2 // Copyright (C) 2007 Brady Miller <brady@sparmy.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
10 // Allows acl(php-gacl) administration. Heavily ajax and
11 // javascript/jquery dependent. All ajax functions are called
12 // from adminacl_ajax.php
14 include_once("../globals.php");
15 include_once("$srcdir/acl.inc");
17 //ensure user has proper access
18 if (!acl_check('admin', 'acl')) {
19 echo "(" . xl('ACL Administration Not Authorized') . ")";
22 //ensure phpgacl is installed
23 if (!isset($phpgacl_location)) {
24 echo "(" . xl('PHP-gacl is not installed') . ")";
31 <script type
="text/JavaScript" src
="../../library/js/jquery121.js"></script
>
32 <script type
="text/JavaScript" src
="../../library/js/jquery.livequery101.js"></script
>
33 <script type
="text/JavaScript">
35 $
(document
).ready(function(){
37 //Show membership section by default
38 $
("#membership_show").click();
40 //Show membership section by default
42 $
("a.link_submit").livequery("click", function(){
47 $
("input.button_submit").livequery("click", function(){
52 $
("#membership_show").livequery("click", function(){
57 $
("#acl_show").livequery("click", function(){
62 $
("input.button_acl_add").livequery("click", function(){
63 //if Clear, then reset form
64 if (this
.id
== "button_acl_add_clear") {
65 $
("#acl_error").empty();
66 $
("#div_acl_add_form span.alert").empty();
69 //if Cancel, then reset/hide form and show create/remove acl links
70 if (this
.id
== "button_acl_add_cancel") {
71 $
("#div_acl_add_form").hide("slow");
72 $
("#acl_error").empty();
73 $
("#div_acl_add_form span.alert").empty();
74 $
("#none_acl_returns").show();
75 $
("#none_acl_list").show();
78 //Submit selected, so send ajax request
79 title
= $
("#title_field").val();
80 identifier
= $
("#id_field").val();
81 return_value
= $
("#return_field").val();
82 description
= $
("#desc_field").val();
85 url
: "../../library/ajax/adminacl_ajax.php",
91 identifier
: identifier
,
92 return_value
: return_value
,
93 description
: description
95 success
: function(xml
){
96 //if successful, then show new group
97 if ($
(xml
).find("success").text() == "SUCCESS") {
98 $
("#button_acl_add_cancel").click();
101 //Remove Loading indicator and old errors, then display new errors
102 $
("#div_acl_add_form span.loading").hide();
103 $
("#acl_error").empty();
104 $
("#div_acl_add_form span.alert").empty();
105 $
(xml
).find("error").each(function(){
106 temparray
= $
(this
).text().split("_");
107 $
("#" + temparray
[0] +
"_error").append(temparray
[1]);
109 $
("#acl_error").show();
110 $
("#div_acl_add_form span.alert").show();
112 beforeSend
: function(){
113 //Show Loading indicator
114 $
("#div_acl_add_form span.loading").show();
117 //Remove Loading indicator and show errors
118 $
("#div_acl_add_form span.loading").hide();
119 $
("#acl_error").empty();
120 $
("#acl_error").append("<span class='alert'><?php xl('ERROR, unable to collect data from server','e'); ?><br></span>");
121 $
("#acl_error").show();
127 $
("input.button_acl_remove").livequery("click", function(){
128 //if Clear, then reset form
129 if (this
.id
== "button_acl_remove_clear") {
130 $
("#acl_error").empty();
131 $
("#div_acl_remove_form span.alert").empty();
134 //if Cancel, then reset/hide form and show create/remove acl links
135 if (this
.id
== "button_acl_remove_cancel") {
136 $
("#div_acl_remove_form").hide("slow");
137 $
("#acl_error").empty();
138 $
("#div_acl_remove_form span.alert").empty();
139 $
("#none_acl_returns").show();
140 $
("#none_acl_list").show();
143 //Ensure confirmed before deleting group
144 confirmDelete
= $
("input[@name=acl_remove_confirm]:checked").val();
145 if (confirmDelete
== "no") { //send confirm alert and exit
146 $
("#remove_confirm_error").empty();
147 $
("#remove_confirm_error").append("<?php xl('Select Yes to confirm group deletion','e'); ?>");
150 //Delete and confirmed, so send ajax request
151 temparray
= $
("#acl_field").val().split("-");
152 title
= temparray
[0];
153 return_value
= temparray
[1];
156 url
: "../../library/ajax/adminacl_ajax.php",
162 return_value
: return_value
164 success
: function(xml
){
165 //if successful, then show new group
166 if ($
(xml
).find("success").text() == "SUCCESS") {
167 $
("#button_acl_remove_cancel").click();
170 //Remove Loading indicator and old errors, then display new errors
171 $
("#div_acl_remove_form span.loading").hide();
172 $
("#acl_error").empty();
173 $
("#div_acl_remove_form span.alert").empty();
174 $
(xml
).find("error").each(function(){
175 temparray
= $
(this
).text().split("_");
176 $
("#" + temparray
[0] +
"_error").append(temparray
[1]);
178 $
("#acl_error").show();
179 $
("#div_acl_remove_form span.alert").show();
181 beforeSend
: function(){
182 //Show Loading indicator
183 $
("#div_acl_remove_form span.loading").show();
186 //Remove Loading indicator and show errors
187 $
("#div_acl_remove_form span.loading").hide();
188 $
("#acl_error").empty();
189 $
("#acl_error").append("<span class='alert'><?php xl('ERROR, unable to collect data from server','e'); ?><br></span>");
190 $
("#acl_error").show();
196 function membership_show() {
197 if (!$
("#membership_show").attr("checked")) {
198 $
("#membership_error").empty();
199 $
("#membership").hide("slow");
205 url
: "../../library/ajax/adminacl_ajax.php",
211 success
: function(xml
){
212 $
("#membership_error").empty();
213 $
("#membership").empty();
214 $
(xml
).find("user").each(function(){
215 username
= $
(this
).find("username").text();
216 $
("#membership").append("<div id='link_" + username +
"'><span class='text'>" + username +
"</span><a class='link_submit' href='no_javascript' id='" + username +
"_membership_list' title='<?php xl('Edit','e'); ?> " + username +
"'>(<?php xl('Edit','e'); ?>)</a></span><a class='link_submit' href='no_javascript' id='" + username +
"_membership_hide' style='display: none' title='<?php xl('Hide','e'); ?> " + username +
"'>(<?php xl('Hide','e'); ?>)</a><span class='alert' style='display: none;'> <?php xl('This user is not a member of any group','e'); ?>!!!</span><span class='loading' style='display: none;'> <?php xl('LOADING','e'); ?>...</span></div><div id='error_" + username +
"'></div><div id='" + username +
"' style='display: none'><table class='lists' border='1' bgcolor='white' cellpadding='3' cellspacing='2'><tr><td align='center'><span class='bold'><?php xl('Active','e'); ?></span></td><td align='center'><span class='bold'><?php xl('Inactive','e'); ?></span></td></tr><tr><td align='center'><select name='active[]' multiple></select><br /><p align='center'><input class='button_submit' type='button' title='<?php xl('Remove','e'); ?>' id='" + username +
"_membership_remove' value=' >> '></p></td><td align='center'><select name='inactive[]' multiple></select><br /><p align='center'><input class='button_submit' type='button' title='<?php xl('Add','e'); ?>' id='" + username +
"_membership_add' value=' << ' ></p></td></tr></table></div>");
217 if ($
(this
).find("alert").text() == "no membership") {
218 $
("#link_" + username +
" span.alert").show();
221 //Show the username list and remove loading indicator
222 $
("#membership").show("slow");
223 $
("#membership_edit span.loading:first").hide();
225 beforeSend
: function(){
226 //Show Loading indicator
227 $
("#membership_edit span.loading:first").show();
230 //Remove Loading indicator and previous error, if any, then show error
231 $
("#membership_edit span.loading:first").hide();
232 $
("#membership_error").empty();
233 $
("#membership_error").append("<span class='alert'><?php xl('ERROR, unable to collect data from server','e'); ?><br><br></span>");
234 $
("#membership_error").show();
240 function acl_show() {
241 if (!$
("#acl_show").attr("checked")) {
242 $
("#acl_error").empty();
243 $
("#none_acl_returns").hide();
244 $
("#none_acl_list").hide();
245 $
("#acl").hide("slow");
246 $
("#div_acl_add_form").hide("slow");
247 $
("#div_acl_remove_form").hide("slow");
253 url
: "../../library/ajax/adminacl_ajax.php",
259 success
: function(xml
){
260 $
("#acl_error").empty();
262 $
(xml
).find("acl").each(function(){
263 value_acl
= $
(this
).find("value").text();
264 title
= $
(this
).find("title").text();
265 titleDash
= value_acl
.replace(" ","-");
266 return_value
= $
(this
).find("returnid").text();
267 return_title
= $
(this
).find("returntitle").text();
268 note
= $
(this
).find("note").text();
269 $
("#acl").append("<div id='acl_link_" + titleDash +
"_" + return_value +
"'><span class='text' title='" + note +
"'>" + title +
"-" + return_title +
"</span><a class='link_submit' href='no_javascript' id='" + titleDash +
"_aco_list_" + return_value +
"' title='<?php xl('Edit','e'); ?> " + title +
"-" + return_title +
"'>(<?php xl('Edit','e'); ?>)</a></span><a class='link_submit' href='no_javascript' id='" + titleDash +
"_acl_hide_" + return_value +
"' style='display: none' title='<?php xl('Hide','e'); ?> " + title +
"-" + return_title +
"'>(<?php xl('Hide','e'); ?>)</a><span class='loading' style='display: none;'> <?php xl('LOADING','e'); ?>...</span></div><div id='acl_error_" + titleDash +
"_" + return_value +
"'></div><div id='acl_" + titleDash +
"_" + return_value +
"' style='display: none'><table border='1' bgcolor='white' cellpadding='3' cellspacing='2'><tr><td align='center'><span class='bold'><?php xl('Active','e'); ?></span></td><td align='center'><span class='bold'><?php xl('Inactive','e'); ?></span></td></tr><tr><td align='center'><select name='active[]' size='6' multiple></select><br /><p align='center'><input class='button_submit' type='button' title='<?php xl('Remove','e'); ?>' id='" + titleDash +
"_aco_remove_" + return_value +
"' value=' >> '></p></td><td align='center'><select name='inactive[]' size='6' multiple></select><br /><p align='center'><input class='button_submit' type='button' title='<?php xl('Add','e'); ?>' id='" + titleDash +
"_aco_add_" + return_value +
"' value=' << ' ></p></td></tr></table></div>");
271 //Show the acl list and add link. Remove loading indicator.
272 $
("#acl").show("slow");
273 $
("#acl_edit span.loading:first").hide();
274 $
("#none_acl_returns").show();
275 $
("#none_acl_list").show();
277 beforeSend
: function(){
278 //Show Loading indicator
279 $
("#acl_edit span.loading:first").show();
282 //Remove Loading indicator and previous error, if any, then show error
283 $
("#acl_edit span.loading:first").hide();
284 $
("#acl_error").empty();
285 $
("#acl_error").append("<span class='alert'><?php xl('ERROR, unable to collect data from server','e'); ?><br><br></span>");
286 $
("#acl_error").show();
292 function generic_click(cthis
) {
293 //set up variables and html page pointers
294 temparray
= cthis
.id
.split("_");
295 identity
= temparray
[0];
296 identityFormatted
= identity
.replace("-"," ");
297 control
= temparray
[1];
298 action
= temparray
[2];
299 return_value
= temparray
[3];
300 if (control
== "membership") {
301 contentPointer
= "#" + identity
;
302 linkPointer
= "#link_" + identity
;
304 errorPointer
= "#error_" + identity
;
306 if (control
== "acl" || control
== "aco") {
307 contentPointer
= "#acl_" + identity +
"_" + return_value
;
308 linkPointer
= "#acl_link_" + identity +
"_" + return_value
;
310 errorPointer
= "#acl_error_" + identity +
"_" + return_value
;
312 //special cases, show add/remove acl forms
313 if (identity
== "none" && control
== "acl") { //action == "returns"
314 if (action
== "returns") {
315 contentPointer
= "#div_acl_add_form";
317 else if (action
== "list") {
318 contentPointer
= "#div_acl_remove_form";
320 linkPointer
= "#acl_edit";
321 linkPointerPost
=":first";
322 errorPointer
= "#acl_error";
325 //If clicked Hide link
326 if (action
== "hide") {
327 //Remove stuff and show Edit link
328 $
(contentPointer
).hide("slow");
329 $
(errorPointer
).hide();
330 $
(linkPointer +
" a.link_submit:last").hide();
331 $
(linkPointer +
" a.link_submit:first").show();
335 //If clicked Add with ACO or membership, then collect selections
336 if (action
== "add" && !(control
== "acl")) {
338 selected
= $
(contentPointer +
" select:last").val();
341 //If clicked Remove with ACO or membership, then collect selections
342 if (action
== "remove" && !(control
== "acl")) {
344 selected
= $
(contentPointer +
" select:first").val();
350 url
: "../../library/ajax/adminacl_ajax.php",
353 name
: identityFormatted
,
356 'selection[]': selected
,
357 return_value
: return_value
359 success
: function(xml
){
361 //SPECIAL CASES to show the add/remove acl form, then exit
362 if (identity
== "none" && control
== "acl") {
363 $
(contentPointer +
" select").empty();
364 if (action
== "returns") {
365 $
(xml
).find("return").each(function(){
366 $
(contentPointer +
" select").append("<option value='" + $
(this
).find("returnid").text() +
"'>" + $
(this
).find("returntitle").text() +
"</option>");
369 else if (action
== "list") {
370 $
(xml
).find("acl").each(function(){
371 $
(contentPointer +
" select").append("<option value='" + $
(this
).find("value").text() +
"-" + $
(this
).find("returnid").text() +
"'>" + $
(this
).find("title").text() +
"-" + $
(this
).find("returntitle").text() +
"</option>");
374 $
(contentPointer +
" option").removeAttr('selected');
375 $
(contentPointer
).show("slow");
376 $
("#none_acl_returns").hide();
377 $
("#none_acl_list").hide();
378 $
(linkPointer +
" span.loading" + linkPointerPost
).hide();
382 if (control
== "membership") {
383 //Remove, then re-populate, then set size of selection boxes
384 $
(contentPointer +
" select").empty();
387 $
(xml
).find("active").find("group").each(function(){
388 $
(contentPointer +
" select:first").append("<option value='" + $
(this
).find("value").text() +
"'>" + $
(this
).find("label").text() +
"</option>");
389 counterActive
= counterActive +
1;
391 $
(xml
).find("inactive").find("group").each(function(){
392 $
(contentPointer +
" select:last").append("<option value='" + $
(this
).find("value").text() +
"'>" + $
(this
).find("label").text() +
"</option>");
393 counterInactive
= counterInactive +
1;
395 $
(contentPointer +
" option").removeAttr('selected');
396 if (counterActive
> counterInactive
) {
397 size
= counterActive
;
400 size
= counterInactive
;
405 if (counterActive
> 0) {
406 //ensure remove the no active group alert
407 $
(linkPointer +
" span.alert").hide();
411 if (control
== "acl" || control
== "aco") {
412 //Remove, then re-populate, then set size of selection boxes
413 $
(contentPointer +
" select").empty();
416 $
(xml
).find("active").find("section").each(function(){
417 $
(contentPointer +
" select:first").append("<optgroup label='" + $
(this
).find("name").text() +
"'>");
418 counterActive
= counterActive +
1;
419 $
(this
).find("aco").each(function(){
420 $
(contentPointer +
" select:first").append("<option value='" + $
(this
).find("id").text() +
"'>" + $
(this
).find("title").text() +
"</option>");
421 counterActive
= counterActive +
1;
423 $
(contentPointer +
" select:first").append("</optgroup>");
425 $
(xml
).find("inactive").find("section").each(function(){
426 $
(contentPointer +
" select:last").append("<optgroup label='" + $
(this
).find("name").text() +
"'>");
427 counterInactive
= counterInactive +
1;
428 $
(this
).find("aco").each(function(){
429 $
(contentPointer +
" select:last").append("<option value='" + $
(this
).find("id").text() +
"'>" + $
(this
).find("title").text() +
"</option>");
430 counterInactive
= counterInactive +
1;
432 $
(contentPointer +
" select:last").append("</optgroup>");
434 $
(contentPointer +
" option").removeAttr('selected');
435 if (counterActive
> counterInactive
) {
436 size
= counterActive
;
439 size
= counterInactive
;
446 //display the selection boxes
447 $
(contentPointer +
" select").attr('size', size
);
448 $
(contentPointer
).show("slow");
450 if (action
== "list") {
451 //Remove Edit link and show Hide link
452 $
(linkPointer +
" a.link_submit:first").hide();
453 $
(linkPointer +
" a.link_submit:last").show();
456 //Remove Loading indicator
457 $
(linkPointer +
" span.loading" + linkPointerPost
).hide();
459 //Remove old errors, then display any new errors to user
460 $
(errorPointer
).empty();
461 $
(xml
).find("error").each(function(){
462 $
(errorPointer
).append("<span class='alert'>" + $
(this
).text() +
"<br></span>");
463 $
(errorPointer
).show();
466 beforeSend
: function(){
467 //Show Loading indicator
468 $
(linkPointer +
" span.loading" + linkPointerPost
).show();
471 //Remove Loading indicator and show errors
472 $
(linkPointer +
" span.loading" + linkPointerPost
).hide();
473 $
(errorPointer
).empty();
474 $
(errorPointer
).append("<span class='alert'><?php xl('ERROR, unable to collect data from server','e'); ?><br></span>");
475 $
(errorPointer
).show();
483 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
484 <style type
="text/css">
486 padding
: 5pt
15pt
5pt
5pt
;
490 font
-family
: sans
-serif
;
491 text
-decoration
: blink
;
497 font
-family
: sans
-serif
;
505 border
-color
: #0000ff;
506 margin
: 0 0 10pt
10pt
;
512 <body
class="body_top">
513 <span
class='title'><?php
xl('Access Control List Administration','e'); ?
></span
> 
;
514 <?php
if ($phpgacl_location) {
515 echo "<a href='../../gacl/admin/acl_admin.php' onclick='top.restoreSession()'><span class='back'>(" . xl('Advanced') . ")</span></a>";
518 <div id
='membership_edit'>
519 <span
class=bold
><input type
='checkbox' id
='membership_show'><?php
xl('User Memberships','e'); ?
></span
>
520 <span
class='loading' style
='display: none;'> 
; 
; 
; 
; 
;<?php
xl('LOADING','e'); ?
>...</span
>
521 <div id
='membership_error'>
523 <div
class=section id
='membership' style
='display: none;'>
527 <span
class=bold
><input type
='checkbox' id
='acl_show'><?php
xl('Groups and Access Controls','e'); ?
></span
>
528 <a
class='link_submit' href
='no_javascript' id
='none_acl_returns' title
=<?php
xl('Add New Group','e','\'','\''); ?
> style
='display: none;'>(<?php
xl('Add New Group','e'); ?
>)</a
>
529 <a
class='link_submit' href
='no_javascript' id
='none_acl_list' title
=<?php
xl('Remove Group','e','\'','\''); ?
> style
='display: none;'>(<?php
xl('Remove Group','e'); ?
>)</a
>
530 <span
class='loading' style
='display: none;'> 
; 
; 
; 
; 
;<?php
xl('LOADING','e'); ?
>...</span
>
533 <div id
='div_acl_add_form' style
='display: none;'>
534 <form
class="section" id
="acl_add_form" action
="no_javascript" method
="post">
535 <span
class='bold'><?php
xl('New Group Information','e'); ?
></span
><span
class='loading' style
='display: none;'> 
; 
; 
; 
; 
;<?php
xl('LOADING','e'); ?
>...</span
>
539 <span
class='text'><?php
xl('Title','e'); ?
>:</span
>
542 <input type
="text" id
="title_field"><td
><span
class="alert" id
="title_error"></span
></td
>
547 <span
class='text'><?php
xl('Identifier(one word)','e'); ?
>:</span
>
550 <input type
="text" id
="id_field"><td
><span
class="alert" id
="identifier_error"></span
></td
>
555 <span
class='text'><?php
xl('Return Value','e'); ?
>:</span
>
558 <select id
="return_field"></select
><td
><span
class="alert" id
="return_error"></span
></td
>
563 <span
class='text'><?php
xl('Description','e'); ?
>:</span
>
566 <input type
="text" id
="desc_field"><td
><span
class="alert" id
="description_error"></span
></td
>
570 <input type
="submit" class="button_acl_add" id
="button_acl_add_submit" title
=<?php
xl('Submit','e','\'','\''); ?
> value
=<?php
xl('Submit','e','\'','\''); ?
>>
571 <input type
="reset" class="button_acl_add" id
="button_acl_add_clear" title
=<?php
xl('Clear','e','\'','\''); ?
> value
=<?php
xl('Clear','e','\'','\''); ?
>>
572 <input type
="reset" class="button_acl_add" id
="button_acl_add_cancel" title
=<?php
xl('Cancel','e','\'','\''); ?
> value
=<?php
xl('Cancel','e','\'','\''); ?
>>
575 <div id
='div_acl_remove_form' style
='display: none;'>
576 <form
class="section" id
="acl_remove_form" action
="no_javascript" method
="post">
577 <span
class='bold'><?php
xl('Remove Group Form','e'); ?
></span
><span
class='loading' style
='display: none;'> 
; 
; 
; 
; 
;<?php
xl('LOADING','e'); ?
>...</span
>
581 <span
class='text'><?php
xl('Group','e'); ?
>:</span
>
584 <select id
="acl_field"></select
><td
><span
class="alert" id
="aclTitle_error"></span
></td
>
589 <span
class='text'><?php
xl('Do you really want to delete this group','e'); ?
>?
</span
>
592 <input type
="radio" name
="acl_remove_confirm" value
= "yes"><span
class='text'><?php
xl('Yes','e'); ?
></span
>
593 <input type
="radio" name
="acl_remove_confirm" value
= "no" checked
><span
class='text'><?php
xl('No','e'); ?
></span
>
594 <td
><span
class="alert" id
="remove_confirm_error"></span
></td
>
598 <input type
="submit" class="button_acl_remove" id
="button_acl_remove_delete" title
=<?php
xl('Delete','e','\'','\''); ?
> value
=<?php
xl('Delete','e','\'','\''); ?
>>
599 <input type
="reset" class="button_acl_remove" id
="button_acl_remove_cancel" title
=<?php
xl('Cancel','e','\'','\''); ?
> value
=<?php
xl('Cancel','e','\'','\''); ?
>>
602 <div
class=section id
='acl' style
='display: none;'>