The Third Reminders email bug fix - contributed by arnabnaha
[openemr.git] / interface / usergroup / adminacl.php
bloba0f0e312a728255142008c6b039c3c5e647515df
1 <?php
2 // Copyright (C) 2007 Brady Miller <brady@sparmy.com>
3 //
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.
8 //
9 //
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') . ")";
20 exit;
22 //ensure phpgacl is installed
23 if (!isset($phpgacl_location)) {
24 echo "(" . xl('PHP-gacl is not installed') . ")";
25 exit;
29 <html>
30 <head>
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();
39 membership_show();
40 //Show membership section by default
42 $("a.link_submit").livequery("click", function(){
43 generic_click(this);
44 return false;
45 });
47 $("input.button_submit").livequery("click", function(){
48 generic_click(this);
49 return false;
50 });
52 $("#membership_show").livequery("click", function(){
53 membership_show();
54 return;
55 });
57 $("#acl_show").livequery("click", function(){
58 acl_show();
59 return;
60 });
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();
67 return;
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();
76 return;
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();
83 $.ajax({
84 type: "POST",
85 url: "../../library/ajax/adminacl_ajax.php",
86 dataType: "xml",
87 data: {
88 control: "acl",
89 action: "add",
90 title: title,
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();
99 acl_show();
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();
116 error: function(){
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();
124 return false;
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();
132 return;
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();
141 return;
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'); ?>");
148 return false;
150 //Delete and confirmed, so send ajax request
151 temparray = $("#acl_field").val().split("-");
152 title = temparray[0];
153 return_value = temparray[1];
154 $.ajax({
155 type: "POST",
156 url: "../../library/ajax/adminacl_ajax.php",
157 dataType: "xml",
158 data: {
159 control: "acl",
160 action: "remove",
161 title: title,
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();
168 acl_show();
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();
185 error: function(){
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();
193 return false;
196 function membership_show() {
197 if (!$("#membership_show").attr("checked")) {
198 $("#membership_error").empty();
199 $("#membership").hide("slow");
200 return;
202 //Send ajax request
203 $.ajax({
204 type: "POST",
205 url: "../../library/ajax/adminacl_ajax.php",
206 dataType: "xml",
207 data: {
208 control: "username",
209 action: "list"
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;'>&nbsp;&nbsp;<?php xl('This user is not a member of any group','e'); ?>!!!</span><span class='loading' style='display: none;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?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();
229 error: function(){
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();
237 return;
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");
248 return;
250 //Send ajax request
251 $.ajax({
252 type: "POST",
253 url: "../../library/ajax/adminacl_ajax.php",
254 dataType: "xml",
255 data: {
256 control: "acl",
257 action: "list"
259 success: function(xml){
260 $("#acl_error").empty();
261 $("#acl").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;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?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();
281 error:function(){
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();
289 return;
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;
303 linkPointerPost ="";
304 errorPointer = "#error_" + identity;
306 if (control == "acl" || control == "aco") {
307 contentPointer = "#acl_" + identity + "_" + return_value;
308 linkPointer = "#acl_link_" + identity + "_" + return_value;
309 linkPointerPost ="";
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();
332 return;
335 //If clicked Add with ACO or membership, then collect selections
336 if (action == "add" && !(control == "acl")) {
337 var selected = [];
338 selected = $(contentPointer + " select:last").val();
341 //If clicked Remove with ACO or membership, then collect selections
342 if (action == "remove" && !(control == "acl")) {
343 var selected = [];
344 selected = $(contentPointer + " select:first").val();
347 //Send ajax request
348 $.ajax({
349 type: "POST",
350 url: "../../library/ajax/adminacl_ajax.php",
351 dataType: "xml",
352 data: {
353 name: identityFormatted,
354 control: control,
355 action: action,
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();
379 return;
382 if (control == "membership") {
383 //Remove, then re-populate, then set size of selection boxes
384 $(contentPointer + " select").empty();
385 counterActive = 0;
386 counterInactive = 0;
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;
394 });
395 $(contentPointer + " option").removeAttr('selected');
396 if (counterActive > counterInactive) {
397 size = counterActive;
399 else {
400 size = counterInactive;
402 if (size > 10) {
403 size = 10;
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();
414 counterActive = 0;
415 counterInactive = 0;
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;
431 });
432 $(contentPointer + " select:last").append("</optgroup>");
433 });
434 $(contentPointer + " option").removeAttr('selected');
435 if (counterActive > counterInactive) {
436 size = counterActive;
438 else {
439 size = counterInactive;
441 if (size > 15) {
442 size = 15;
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();
470 error: function(){
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();
478 return;
481 </script>
483 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
484 <style type="text/css">
485 body {
486 padding: 5pt 15pt 5pt 5pt;
487 margin: 0pt;
489 .loading {
490 font-family: sans-serif;
491 text-decoration: blink;
492 font-size: 10pt;
493 color: red;
494 font-weight: bold;
496 .alert {
497 font-family: sans-serif;
498 font-size: 10pt;
499 color: red;
500 font-weight: bold;
502 .section {
503 border: solid;
504 border-width: 1px;
505 border-color: #0000ff;
506 margin: 0 0 10pt 10pt;
507 padding: 5pt;
509 </style>
510 </head>
512 <body class="body_top">
513 <span class='title'><?php xl('Access Control List Administration','e'); ?></span>&nbsp;
514 <?php if ($phpgacl_location) {
515 echo "<a href='../../gacl/admin/acl_admin.php' onclick='top.restoreSession()'><span class='back'>(" . xl('Advanced') . ")</span></a>";
516 } ?>
517 <br><br>
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;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php xl('LOADING','e'); ?>...</span>
521 <div id='membership_error'>
522 </div>
523 <div class=section id='membership' style='display: none;'>
524 </div>
525 </div>
526 <div id='acl_edit'>
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;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php xl('LOADING','e'); ?>...</span>
531 <div id='acl_error'>
532 </div>
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;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php xl('LOADING','e'); ?>...</span>
536 <table>
537 <tr>
538 <td>
539 <span class='text'><?php xl('Title','e'); ?>:</span>
540 </td>
541 <td>
542 <input type="text" id="title_field"><td><span class="alert" id="title_error"></span></td>
543 </td>
544 </tr>
545 <tr>
546 <td>
547 <span class='text'><?php xl('Identifier(one word)','e'); ?>:</span>
548 </td>
549 <td>
550 <input type="text" id="id_field"><td><span class="alert" id="identifier_error"></span></td>
551 </td>
552 </tr>
553 <tr>
554 <td>
555 <span class='text'><?php xl('Return Value','e'); ?>:</span>
556 </td>
557 <td>
558 <select id="return_field"></select><td><span class="alert" id="return_error"></span></td>
559 </td>
560 </tr>
561 <tr>
562 <td>
563 <span class='text'><?php xl('Description','e'); ?>:</span>
564 </td>
565 <td>
566 <input type="text" id="desc_field"><td><span class="alert" id="description_error"></span></td>
567 </td>
568 </tr>
569 </table>
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','\'','\''); ?>>
573 </form>
574 </div>
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;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php xl('LOADING','e'); ?>...</span>
578 <table>
579 <tr>
580 <td align="right">
581 <span class='text'><?php xl('Group','e'); ?>:</span>
582 </td>
583 <td>
584 <select id="acl_field"></select><td><span class="alert" id="aclTitle_error"></span></td>
585 </td>
586 </tr>
587 <tr>
588 <td>
589 <span class='text'><?php xl('Do you really want to delete this group','e'); ?>?</span>
590 </td>
591 <td>
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>
595 </td>
596 </tr>
597 </table>
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','\'','\''); ?>>
600 </form>
601 </div>
602 <div class=section id='acl' style='display: none;'>
603 </div>
604 </div>
605 </body>
606 </html>