Internationalization Project: added Amharic language.
[openemr.git] / gacl / admin / assign_group.php
blobfae975dba6258bcb85332703f17b803774db550c
1 <?php
2 //First make sure user has access
3 include_once("../../interface/globals.php");
4 include_once("$srcdir/acl.inc");
5 //ensure user has proper access
6 if (!acl_check('admin', 'acl')) {
7 echo xl('ACL Administration Not Authorized');
8 exit;
10 //ensure php is installed
11 if (!isset($phpgacl_location)) {
12 echo xl('php-GACL access controls are turned off');
13 exit;
16 require_once('gacl_admin.inc.php');
18 //GET takes precedence.
19 if ($_GET['group_type'] != '') {
20 $group_type = $_GET['group_type'];
21 } else {
22 $group_type = $_POST['group_type'];
25 switch(strtolower(trim($group_type))) {
26 case 'axo':
27 $group_type = 'axo';
28 $table = $gacl_api->_db_table_prefix . 'axo';
29 $group_table = $gacl_api->_db_table_prefix . 'axo_groups';
30 $group_sections_table = $gacl_api->_db_table_prefix . 'axo_sections';
31 $group_map_table = $gacl_api->_db_table_prefix . 'groups_axo_map';
32 $object_type = 'Access eXtension Object';
33 break;
34 default:
35 $group_type = 'aro';
36 $table = $gacl_api->_db_table_prefix . 'aro';
37 $group_table = $gacl_api->_db_table_prefix . 'aro_groups';
38 $group_sections_table = $gacl_api->_db_table_prefix . 'aro_sections';
39 $group_map_table = $gacl_api->_db_table_prefix . 'groups_aro_map';
40 $object_type = 'Access Request Object';
41 break;
44 switch ($_POST['action']) {
45 case 'Remove':
46 $gacl_api->debug_text('Delete!!');
48 //Parse the form values
49 //foreach ($_POST['delete_assigned_aro'] as $aro_value) {
50 while (list(,$object_value) = @each($_POST['delete_assigned_object'])) {
51 $split_object_value = explode('^', $object_value);
52 $selected_object_array[$split_object_value[0]][] = $split_object_value[1];
55 //Insert Object -> GROUP mappings
56 while (list($object_section_value,$object_array) = @each($selected_object_array)) {
57 $gacl_api->debug_text('Assign: Object ID: '. $object_section_value .' to Group: '. $_POST['group_id']);
59 foreach ($object_array as $object_value) {
60 $gacl_api->del_group_object($_POST['group_id'], $object_section_value, $object_value, $group_type);
64 //Return page.
65 $gacl_api->return_page($_SERVER['PHP_SELF'] .'?group_type='. $_POST['group_type'] .'&group_id='. $_POST['group_id']);
67 break;
68 case 'Submit':
69 $gacl_api->debug_text('Submit!!');
71 //showarray($_POST['selected_'.$_POST['group_type']]);
72 //Parse the form values
73 //foreach ($_POST['selected_aro'] as $aro_value) {
74 while (list(,$object_value) = @each($_POST['selected_'.$_POST['group_type']])) {
75 $split_object_value = explode('^', $object_value);
76 $selected_object_array[$split_object_value[0]][] = $split_object_value[1];
79 //Insert ARO -> GROUP mappings
80 while (list($object_section_value,$object_array) = @each($selected_object_array)) {
81 $gacl_api->debug_text('Assign: Object ID: '. $object_section_value .' to Group: '. $_POST['group_id']);
83 foreach ($object_array as $object_value) {
84 $gacl_api->add_group_object($_POST['group_id'], $object_section_value, $object_value, $group_type);
88 $gacl_api->return_page($_SERVER['PHP_SELF'] .'?group_type='. $_POST['group_type'] .'&group_id='. $_POST['group_id']);
90 break;
91 default:
93 //Grab all sections for select box
95 $query = 'SELECT value,name FROM '. $group_sections_table .' ORDER BY order_value,name';
96 $rs = $db->Execute($query);
98 $options_sections = array();
100 if (is_object($rs)) {
101 while ($row = $rs->FetchRow()) {
102 $options_sections[$row[0]] = $row[1];
106 //showarray($options_sections);
107 $smarty->assign('options_sections', $options_sections);
108 $smarty->assign('section_value', reset($options_sections));
111 //Grab all objects for select box
113 $query = 'SELECT section_value,value,name FROM '. $table .' ORDER BY section_value,order_value,name';
114 $rs = $db->SelectLimit($query, $gacl_api->_max_select_box_items);
116 $js_array_name = 'options[\''. $group_type .'\']';
117 //Init the main aro js array.
118 $js_array = 'var options = new Array();' . "\n";
119 $js_array .= $js_array_name .' = new Array();' . "\n";
121 unset($tmp_section_value);
123 if (is_object($rs)) {
124 while ($row = $rs->FetchRow()) {
125 //list($section_value, $value, $name) = $row;
127 $section_value = addslashes($row[0]);
128 $value = addslashes($row[1]);
129 $name = addslashes($row[2]);
131 //Prepare javascript code for dynamic select box.
132 //Init the javascript sub-array.
133 if (!isset($tmp_section_value) OR $section_value != $tmp_section_value) {
134 $i = 0;
135 $js_array .= $js_array_name .'[\''. $section_value .'\'] = new Array();' . "\n";
138 //Add each select option for the section
139 $js_array .= $js_array_name .'[\''. $section_value .'\']['. $i .'] = new Array(\''. $value .'\', \''. $name ."');\n";
141 $tmp_section_value = $section_value;
142 $i++;
146 $smarty->assign('js_array', $js_array);
147 $smarty->assign('js_array_name', $group_type);
149 //Grab list of assigned Objects
150 $query = '
151 SELECT b.section_value,b.value,b.name AS b_name,c.name AS c_name
152 FROM '. $group_map_table .' a
153 INNER JOIN '. $table .' b ON b.id=a.'. $group_type .'_id
154 INNER JOIN '. $group_sections_table .' c ON c.value=b.section_value
155 WHERE a.group_id='. $db->qstr($_GET['group_id']) .'
156 ORDER BY c.name, b.name';
157 //$rs = $db->Execute($query);
158 $rs = $db->PageExecute($query, $gacl_api->_items_per_page, $_GET['page']);
160 $object_rows = array();
162 if (is_object($rs)) {
163 while ($row = $rs->FetchRow()) {
164 list($section_value, $value, $name, $section) = $row;
166 $object_rows[] = array(
167 'section_value' => $row[0],
168 'value' => $row[1],
169 'name' => $row[2],
170 'section' => $row[3]
174 $smarty->assign('total_objects', $rs->_maxRecordCount);
176 $smarty->assign('paging_data', $gacl_api->get_paging_data($rs));
178 //showarray($aros);
180 $smarty->assign('rows', $object_rows);
182 //Get group name.
183 $group_data = $gacl_api->get_group_data($_GET['group_id'], $group_type);
184 $smarty->assign('group_name', $group_data[2]);
186 $smarty->assign('group_id', $_GET['group_id']);
188 break;
191 $smarty->assign('group_type', $group_type);
192 $smarty->assign('object_type', $object_type);
193 $smarty->assign('return_page', $_SERVER['REQUEST_URI'] );
195 $smarty->assign('current','assign_group_'. $group_type);
196 $smarty->assign('page_title', 'Assign Group - '. strtoupper($group_type));
198 $smarty->assign('phpgacl_version', $gacl_api->get_version() );
199 $smarty->assign('phpgacl_schema_version', $gacl_api->get_schema_version() );
201 $smarty->display('phpgacl/assign_group.tpl');