permissions_functions.inc.php 20 KB

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