permissions_functions.inc.php 20 KB

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