permissions_functions.inc.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <?php
  2. /**
  3. * This files contains the common functions for the permissions
  4. *
  5. * A list of all the functions (in no particular order)
  6. * ----------------------------------------------------
  7. * store_permissions($content,$id)
  8. * get_permissions($content,$id)
  9. * limited_or_full($current_permissions)
  10. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  11. * @package chamilo.permissions
  12. */
  13. /**
  14. * This function stores the permissions in the correct table.
  15. * Since Checkboxes are used we do not know which ones are unchecked.
  16. * That's why we first delete them all (for the given user/group/role
  17. * and afterwards we store the checked ones only.
  18. * @param $content are we storing rights for a user, a group or a role (the database depends on it)
  19. * @param $id the id of the user, group or role
  20. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  21. * @version 1.0
  22. */
  23. function store_permissions($content, $id)
  24. {
  25. $course_id = api_get_course_int_id();
  26. // Which database are we using (depending on the $content parameter)
  27. if ($content == 'user') {
  28. $table = Database::get_course_table(TABLE_PERMISSION_USER);
  29. $id_field = user_id;
  30. }
  31. if ($content == 'group') {
  32. $table = Database::get_course_table(TABLE_PERMISSION_GROUP);
  33. $id_field = group_id;
  34. }
  35. if ($content == 'role') {
  36. $table = Database::get_course_table(TABLE_ROLE_PERMISSION);
  37. $id_field = role_id;
  38. }
  39. // We first delete all the existing permissions for that user/group/role
  40. $sql = "DELETE FROM $table WHERE c_id = $course_id AND $id_field = '".Database::escape_string($id)."'";
  41. $result = Database::query($sql);
  42. // looping through the post values to find the permission (containing the string permission* )
  43. foreach ($_POST as $key => $value) {
  44. if (strstr($key, "permission*")) {
  45. list($brol, $tool, $action) = explode("*", $key);
  46. $sql = "INSERT INTO $table (c_id, $id_field,tool,action) VALUES ($course_id, '".Database::escape_string($id)."','".Database::escape_string($tool)."','".Database::escape_string($action)."')";
  47. $result = Database::query($sql);
  48. }
  49. }
  50. return get_lang('PermissionsStored');
  51. }
  52. /**
  53. * This function stores one permission in the correct table.
  54. * @param $content are we storing rights for a user, a group or a role (the database depends on it)
  55. * @param $action are we granting or revoking a permission?
  56. * @param $id the id of the user, group or role
  57. * @param $tool the tool
  58. * @param $permission the permission the user, group or role has been granted or revoked
  59. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  60. * @version 1.0
  61. */
  62. function store_one_permission($content, $action, $id, $tool, $permission)
  63. {
  64. global $rights_full;
  65. $course_id = api_get_course_int_id();
  66. // for some reason I don't know, he can't get to the $rights_full array, so commented the following lines out.
  67. // check
  68. //if(!in_array($permission, $rights_full))
  69. //{
  70. // return get_lang('Error');
  71. //}
  72. // Which database are we using (depending on the $content parameter)
  73. if ($content == 'user') {
  74. $table = Database::get_course_table(TABLE_PERMISSION_USER);
  75. $id_field = user_id;
  76. }
  77. if ($content == 'group') {
  78. $table = Database::get_course_table(TABLE_PERMISSION_GROUP);
  79. $id_field = group_id;
  80. }
  81. if ($content == 'role') {
  82. $table = Database::get_course_table(TABLE_ROLE_PERMISSION);
  83. $id_field = role_id;
  84. }
  85. // grating a right
  86. if ($action == 'grant') {
  87. $sql = "INSERT INTO $table (c_id, $id_field,tool,action) VALUES ($course_id, '".Database::escape_string($id)."','".Database::escape_string($tool)."','".Database::escape_string($permission)."')";
  88. $result = Database::query($sql);
  89. if ($result) {
  90. $result_message = get_lang('PermissionGranted');
  91. }
  92. }
  93. if ($action == 'revoke') {
  94. $sql = "DELETE FROM $table WHERE c_id = $course_id AND $id_field = '".Database::escape_string($id)."' AND tool='".Database::escape_string($tool)."' AND action='".Database::escape_string($permission)."'";
  95. $result = Database::query($sql);
  96. if ($result) {
  97. $result_message = get_lang('PermissionRevoked');
  98. }
  99. }
  100. return $result_message;
  101. }
  102. /**
  103. * This function retrieves the existing permissions of a user, group or role.
  104. * @param $content are we retrieving the rights of a user, a group or a role (the database depends on it)
  105. * @param $id the id of the user, group or role
  106. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  107. * @version 1.0
  108. */
  109. function get_permissions($content, $id)
  110. {
  111. $course_id = api_get_course_int_id();
  112. $currentpermissions = array();
  113. // Which database are we using (depending on the $content parameter)
  114. $course_id_condition = " c_id = $course_id AND ";
  115. if ($content == 'user') {
  116. $table = Database::get_course_table(TABLE_PERMISSION_USER);
  117. $id_field = 'user_id';
  118. } elseif ($content == 'group') {
  119. $table = Database::get_course_table(TABLE_PERMISSION_GROUP);
  120. $id_field = 'group_id';
  121. } elseif ($content == 'role') {
  122. $table = Database::get_course_table(TABLE_ROLE_PERMISSION);
  123. $id_field = 'role_id';
  124. } elseif ($content == 'platform_role') {
  125. $table = Database::get_main_table(TABLE_ROLE_PERMISSION);
  126. $id_field = 'role_id';
  127. $course_id_condition = '';
  128. } elseif ($content == 'task') {
  129. $table = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
  130. $id_field = 'task_id';
  131. }
  132. // finding all the permissions. We store this in a multidimensional array
  133. // where the first dimension is the tool.
  134. $sql = "
  135. SELECT * FROM " . $table."
  136. WHERE $course_id_condition ".$id_field."='".Database::escape_string($id)."'";
  137. $result = Database::query($sql);
  138. while ($row = Database::fetch_array($result)) {
  139. $currentpermissions[$row['tool']][] = $row['action'];
  140. }
  141. return $currentpermissions;
  142. }
  143. /**
  144. * the array that contains the current permission a user, group or role has will now be changed depending on
  145. * the Dokeos Config Setting for the permissions (limited [add, edit, delete] or full [view, add, edit, delete, move, visibility]
  146. * @param $content are we retrieving the rights of a user, a group or a role (the database depends on it)
  147. * @param $id the id of the user, group or role
  148. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  149. * @version 1.0
  150. * @todo currently there is a setting user_permissions and group_permissions. We should merge this in one config setting.
  151. */
  152. function limited_or_full($current_permissions)
  153. {
  154. if (api_get_setting('permissions') == 'limited') {
  155. foreach ($current_permissions as $tool => $tool_rights) {
  156. // we loop through the possible permissions of a tool and unset the entry if it is view
  157. // if it is visibility or move we have to grant the edit right
  158. foreach ($tool_rights as $key => $value) {
  159. if ($value == 'View') {
  160. unset($current_permissions[$tool][$key]);
  161. }
  162. if ($value == 'Visibility' OR $value == 'Move') {
  163. if (!in_array('Edit', $current_permissions[$tool])) {
  164. $current_permissions[$tool][] = 'Edit';
  165. }
  166. unset($current_permissions[$tool][$key]);
  167. }
  168. //else
  169. //{
  170. // $current_permissions[$tool][]=$value;
  171. //}
  172. }
  173. }
  174. return $current_permissions;
  175. }
  176. if (api_get_setting('permissions') == 'full') {
  177. return $current_permissions;
  178. }
  179. }
  180. /**
  181. * This function displays a checked or unchecked checkbox. The checkbox will be checked if the
  182. * user, group or role has the permission for the given tool, unchecked if the user, group or role
  183. * does not have the right
  184. * @param $permission_array the array that contains all the permissions of the user, group, role
  185. * @param $tool the tool we want to check a permission for
  186. * @param $permission the permission we want to check for
  187. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  188. * @version 1.0
  189. */
  190. function display_checkbox_matrix($permission_array, $tool, $permission, $inherited_permissions = array())
  191. {
  192. $checked = "";
  193. if (is_array($permission_array[$tool]) AND in_array($permission, $permission_array[$tool]))
  194. {
  195. $checked = "checked";
  196. }
  197. echo "\t\t\t<input type=\"checkbox\" name=\"permission*$tool*$permission\" $checked>\n";
  198. }
  199. /**
  200. * This function displays a checked or unchecked image. The image will be checked if the
  201. * user, group or role has the permission for the given tool, unchecked if the user, group or role
  202. * does not have the right
  203. * @param $permission_array the array that contains all the permissions of the user, group, role
  204. * @param $tool the tool we want to check a permission for
  205. * @param $permission the permission we want to check for
  206. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  207. * @version 1.0
  208. */
  209. function display_image_matrix($permission_array, $tool, $permission, $inherited_permissions = array(), $course_admin = false, $editable = true)
  210. {
  211. if ($course_admin) {
  212. echo "\t\t\t<img src=\"../img/checkbox_on3.gif\" border=\"0\"/ title=\"".get_lang('PermissionGrantedByGroupOrRole')."\">";
  213. } else {
  214. if (in_array($permission, $inherited_permissions[$tool])) {
  215. echo "\t\t\t<img src=\"../img/checkbox_on3.gif\" border=\"0\"/ title=\"".get_lang('PermissionGrantedByGroupOrRole')."\">";
  216. } else {
  217. if (is_array($permission_array[$tool]) AND in_array($permission, $permission_array[$tool])) {
  218. if ($editable) {
  219. $url = api_get_self();
  220. $urlparameters = '';
  221. foreach ($_GET as $key=>$value) {
  222. $parameter[$key] = $value;
  223. }
  224. $parameter['action'] = 'revoke';
  225. $parameter['permission'] = $permission;
  226. $parameter['tool'] = $tool;
  227. foreach ($parameter as $key=>$value) {
  228. $urlparameters .= $key.'='.$value.'&amp;';
  229. }
  230. $url = $url.'?'.$urlparameters;
  231. echo "\t\t\t <a href=\"".$url."\">";
  232. }
  233. echo "<img src=\"../img/checkbox_on2.gif\" border=\"0\"/>";
  234. if ($editable) {
  235. echo "</a>";
  236. }
  237. } else {
  238. if ($editable)
  239. {
  240. $url = api_get_self();
  241. $urlparameters = '';
  242. foreach ($_GET as $key => $value) {
  243. $parameter[$key] = $value;
  244. }
  245. $parameter['action'] = 'grant';
  246. $parameter['permission'] = $permission;
  247. $parameter['tool'] = $tool;
  248. foreach ($parameter as $key => $value) {
  249. $urlparameters .= $key.'='.$value.'&amp;';
  250. }
  251. $url = $url.'?'.$urlparameters;
  252. //echo "\t\t\t <a href=\"".str_replace('&', '&amp;', $_SERVER['REQUEST_URI'])."&amp;action=grant&amp;permission=$permission&amp;tool=$tool\">";
  253. echo "\t\t\t <a href=\"".$url."\">";
  254. }
  255. echo "<img src=\"../img/wrong.gif\" border=\"0\"/>";
  256. if ($editable)
  257. {
  258. echo "</a>";
  259. }
  260. }
  261. }
  262. }
  263. }
  264. /**
  265. * Slightly modified: Toon Keppens
  266. * This function displays a checked or unchecked image. The image will be checked if the
  267. * user, group or role has the permission for the given tool, unchecked if the user, group or role
  268. * does not have the right
  269. * @param $permission_array the array that contains all the permissions of the user, group, role
  270. * @param $tool the tool we want to check a permission for
  271. * @param $permission the permission we want to check for
  272. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  273. * @version 1.0
  274. */
  275. function display_image_matrix_for_blogs($permission_array, $user_id, $tool, $permission, $inherited_permissions = array(), $course_admin = false, $editable = true)
  276. {
  277. if ($course_admin) {
  278. echo "\t\t\t<img src=\"../img/checkbox_on3.gif\" border=\"0\"/ title=\"".get_lang('PermissionGrantedByGroupOrRole')."\">";
  279. } else {
  280. if (!empty($inherited_permissions) and in_array($permission, $inherited_permissions[$tool])) {
  281. echo "\t\t\t<img src=\"../img/checkbox_on3.gif\" border=\"0\"/ title=\"".get_lang('PermissionGrantedByGroupOrRole')."\">";
  282. } else {
  283. if (is_array($permission_array[$tool]) AND in_array($permission, $permission_array[$tool])) {
  284. if ($editable) {
  285. $url = api_get_self();
  286. $urlparameters = '';
  287. foreach ($_GET as $key => $value)
  288. {
  289. $parameter[$key] = $value;
  290. }
  291. $parameter['action'] = 'manage_rights';
  292. $parameter['do'] = 'revoke';
  293. $parameter['permission'] = $permission;
  294. $parameter['tool'] = $tool;
  295. $parameter['user_id'] = $user_id;
  296. foreach ($parameter as $key=>$value)
  297. {
  298. $urlparameters .= $key.'='.$value.'&amp;';
  299. }
  300. $url = $url.'?'.$urlparameters;
  301. echo "\t\t\t <a href=\"".$url."\">";
  302. }
  303. echo "<img src=\"../img/checkbox_on2.gif\" border=\"0\"/ title=\"".get_lang('UserHasPermission')."\">";
  304. if ($editable) {
  305. echo "</a>";
  306. }
  307. } else {
  308. if ($editable) {
  309. $url = api_get_self();
  310. $urlparameters = '';
  311. foreach ($_GET as $key => $value) {
  312. $parameter[$key] = $value;
  313. }
  314. $parameter['action'] = 'manage_rights';
  315. $parameter['do'] = 'grant';
  316. $parameter['permission'] = $permission;
  317. $parameter['tool'] = $tool;
  318. $parameter['user_id'] = $user_id;
  319. foreach ($parameter as $key=>$value) {
  320. $urlparameters .= $key.'='.$value.'&amp;';
  321. }
  322. $url = $url.'?'.$urlparameters;
  323. //echo "\t\t\t <a href=\"".str_replace('&', '&amp;', $_SERVER['REQUEST_URI'])."&amp;action=grant&amp;permission=$permission&amp;tool=$tool\">";
  324. echo "\t\t\t <a href=\"".$url."\">";
  325. }
  326. echo "<img src=\"../img/wrong.gif\" border=\"0\"/ title=\"".get_lang('UserHasPermissionNot')."\">";
  327. if ($editable) {
  328. echo "</a>";
  329. }
  330. }
  331. }
  332. }
  333. }
  334. /**
  335. * This function displays a list off all the roles of the course (and those defined by the platform admin)
  336. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  337. * @version 1.0
  338. */
  339. function display_role_list($current_course_roles, $current_platform_roles)
  340. {
  341. global $setting_visualisation;
  342. $course_id = api_get_course_int_id();
  343. $coures_roles_table = Database::get_course_table(TABLE_ROLE);
  344. // course roles
  345. $sql = "SELECT * FROM $coures_roles_table WHERE c_id = $course_id ";
  346. $result = Database::query($sql);
  347. while ($row = Database::fetch_array($result)) {
  348. if (in_array($row['role_id'], $current_course_roles)) {
  349. $checked = 'checked';
  350. $image = 'checkbox_on2.gif';
  351. $action = 'revoke';
  352. } else {
  353. $checked = '';
  354. $image = 'wrong.gif';
  355. $action = 'grant';
  356. }
  357. if ($setting_visualisation == 'checkbox') {
  358. echo "<input type=\"checkbox\" name=\"role*course*".$row['role_id']."\" $checked>";
  359. }
  360. if ($setting_visualisation == 'image') {
  361. echo "<a href=\"".str_replace('&', '&amp;', $_SERVER['REQUEST_URI'])."&amp;action=$action&amp;role=".$row['role_id']."&amp;scope=course\"><img src=\"../img/".$image."\" border=\"0\"/></a>";
  362. }
  363. echo $row['role_name']." <a href=\"../permissions/roles.php?role_id=".$row['role_id']."&amp;scope=course\"><img src=\"../img/edit.gif\" /></a><br />\n";
  364. echo $row['role_comment']."<br />\n";
  365. }
  366. }
  367. /**
  368. * This function gets all the current roles of the user or group
  369. * @param $content are we finding the roles for a user or a group (the database depends on it)
  370. * @param $id the id of the user or group
  371. * @return array that contains the name of the roles the user has
  372. * @todo consider having a separate table that contains only an id and a name of the role.
  373. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  374. * @version 1.0
  375. */
  376. function get_roles($content, $id, $scope = 'course')
  377. {
  378. $course_id = api_get_course_int_id();
  379. if ($content == 'user') {
  380. $table = Database::get_course_table(TABLE_ROLE_USER);
  381. $id_field = user_id;
  382. }
  383. if ($content == 'group') {
  384. $table = Database::get_course_table(TABLE_ROLE_GROUP);
  385. $id_field = 'group_id';
  386. }
  387. $table_role = Database::get_course_table(TABLE_ROLE);
  388. $current_roles = array();
  389. //$sql="SELECT role.role_id FROM $table role_group_user, $table_role role WHERE role_group_user.$id_field = '$id' AND role_group_user.role_id=role.role_id AND role_group_user.scope='".$scope."'";$sql="SELECT role.role_id FROM $table role_group_user, $table_role role WHERE role_group_user.$id_field = '$id' AND role_group_user.role_id=role.role_id AND role_group_user.scope='".$scope."'";
  390. $sql = "SELECT role_id FROM $table WHERE c_id = $course_id AND $id_field = '$id' AND scope='".$scope."'";
  391. $result = Database::query($sql);
  392. while ($row = Database::fetch_array($result)) {
  393. $current_roles[] = $row['role_id'];
  394. }
  395. return $current_roles;
  396. }
  397. /**
  398. * This function gets all the current roles of the user or group
  399. * @return array that contains the name of the roles the user has
  400. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  401. * @version 1.0
  402. */
  403. function get_all_roles($content = 'course') {
  404. $course_id = api_get_course_int_id();
  405. $course_id_condition = " WHERE c_id = $course_id ";
  406. if ($content == 'course')
  407. {
  408. $table_role = Database::get_course_table(TABLE_ROLE);
  409. }
  410. if ($content == 'platform')
  411. {
  412. $table_role = Database::get_main_table(TABLE_ROLE);
  413. $course_id_condition = '';
  414. }
  415. $current_roles = array();
  416. $sql = "SELECT * FROM $table_role $course_id_condition ";
  417. $result = Database::query($sql);
  418. while ($row = Database::fetch_array($result))
  419. {
  420. $roles[] = $row;
  421. }
  422. return $roles;
  423. }
  424. /**
  425. * This function gets all the roles that are defined
  426. * @param $content are we finding the roles for a user or a group (the database depends on it)
  427. * @param $id the id of the user or group
  428. * @param string Deprecated parameter allowing use of 'platform' scope - the corresponding tables don't exist anymore so the scope is always set to 'course'
  429. * @return array that contains the name of the roles the user has
  430. * @todo consider having a separate table that contains only an id and a name of the role.
  431. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  432. * @version 1.0
  433. */
  434. function get_roles_permissions($content, $id, $scope = 'course')
  435. {
  436. $course_id = api_get_course_int_id();
  437. if ($content == 'user') {
  438. $table = Database::get_course_table(TABLE_ROLE_USER);
  439. $id_field = 'user_id';
  440. }
  441. if ($content == 'group') {
  442. $table = Database::get_course_table(TABLE_ROLE_GROUP);
  443. $id_field = 'group_id';
  444. }
  445. // course roles or platform roles
  446. $scope = 'course';
  447. if ($scope == 'course') {
  448. $table_role = Database::get_course_table(TABLE_ROLE);
  449. $table_role_permissions = Database::get_course_table(TABLE_ROLE_PERMISSION);
  450. $role_condition = " role.c_id = $course_id AND role_permissions.c_id = $course_id AND ";
  451. }
  452. if ($scope == 'platform') {
  453. $table_role = Database::get_main_table(TABLE_ROLE);
  454. $table_role_permissions = Database::get_main_table(TABLE_ROLE_PERMISSION);
  455. $role_condition = '';
  456. }
  457. $sql = "
  458. SELECT *
  459. FROM
  460. " . $table." role_group_user,
  461. " . $table_role." role,
  462. " . $table_role_permissions." role_permissions
  463. WHERE
  464. role_group_user.c_id = $course_id AND
  465. $role_condition
  466. role_group_user.scope = '".$scope."' AND
  467. role_group_user." . $id_field." = '".$id."' AND
  468. role_group_user.role_id = role.role_id AND
  469. role.role_id = role_permissions.role_id";
  470. $result = Database::query($sql);
  471. $current_role_permissions = array();
  472. while ($row = Database::fetch_array($result)) {
  473. $current_role_permissions[$row['tool']][] = $row['action'];
  474. }
  475. return $current_role_permissions;
  476. }
  477. /**
  478. * This function is called when we assign a role to a user or a group
  479. * @param $content are we assigning a role to a group or a user
  480. * @param $action we can grant a role to a group or user or revoke it
  481. * @param $id the user_id of the user or the group_id of the group
  482. * @param $role_id the id of the role we are giving to a user or a group.
  483. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  484. */
  485. function assign_role($content, $action, $id, $role_id, $scope = 'course')
  486. {
  487. $course_id = api_get_course_int_id();
  488. // Which database are we using (depending on the $content parameter)
  489. if ($content == 'user') {
  490. $table = Database::get_course_table(TABLE_ROLE_USER);
  491. $id_field = 'user_id';
  492. } elseif ($content == 'group') {
  493. $table = Database::get_course_table(TABLE_ROLE_GROUP);
  494. $id_field = 'group_id';
  495. } else {
  496. return get_lang('Error');
  497. }
  498. // grating a right
  499. if ($action == 'grant') {
  500. $sql = "INSERT INTO $table (c_id, role_id, scope, $id_field) VALUES ($course_id, '".Database::escape_string($role_id)."','".Database::escape_string($scope)."','".Database::escape_string($id)."')";
  501. $result = Database::query($sql);
  502. if ($result) {
  503. $result_message = get_lang('RoleGranted');
  504. }
  505. }
  506. if ($action == 'revoke') {
  507. $sql = "DELETE FROM $table WHERE c_id = $course_id AND $id_field = '".Database::escape_string($id)."' AND role_id='".Database::escape_string($role_id)."'";
  508. $result = Database::query($sql);
  509. if ($result) {
  510. $result_message = get_lang('RoleRevoked');
  511. }
  512. }
  513. return $result_message;
  514. }
  515. /**
  516. * This function merges permission arrays. Each permission array has the
  517. * following structure
  518. * a permission array has a tool contanst as a key and an array as a value.
  519. * This value array consists of all the permissions that are granted in that tool.
  520. */
  521. function permission_array_merge($array1, $array2)
  522. {
  523. foreach ($array2 as $tool => $permissions) {
  524. foreach ($permissions as $permissionkey => $permissionvalue) {
  525. $array1[$tool][] = $permissionvalue;
  526. }
  527. }
  528. return $array1;
  529. }
  530. function my_print_r($array)
  531. {
  532. echo '<pre>';
  533. print_r($array);
  534. echo '</pre>';
  535. }