permissions_functions.inc.php 23 KB

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