PageRenderTime 60ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/include/utils/UserInfoUtil.php

https://bitbucket.org/thomashii/vtigercrm-6-for-postgresql
PHP | 2255 lines | 1657 code | 279 blank | 319 comment | 249 complexity | 64d0524487b78044cce7f9a9a7ef0a7a MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.1, GPL-2.0, GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*********************************************************************************
  3. ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
  4. * ("License"); You may not use this file except in compliance with the License
  5. * The Original Code is: vtiger CRM Open Source
  6. * The Initial Developer of the Original Code is vtiger.
  7. * Portions created by vtiger are Copyright (C) vtiger.
  8. * All Rights Reserved.
  9. *
  10. ********************************************************************************/
  11. require_once('include/database/PearDatabase.php');
  12. require_once('include/database/Postgres8.php');
  13. require_once('include/utils/utils.php');
  14. require_once('include/utils/GetUserGroups.php');
  15. include_once('config.php');
  16. require_once("include/events/include.inc");
  17. require_once 'includes/runtime/Cache.php';
  18. global $log;
  19. /** To retreive the mail server info resultset for the specified user
  20. * @param $user -- The user object:: Type Object
  21. * @returns the mail server info resultset
  22. */
  23. function getMailServerInfo($user)
  24. {
  25. global $log;
  26. $log->debug("Entering getMailServerInfo(".$user->user_name.") method ...");
  27. global $adb;
  28. $sql = "select * from vtiger_mail_accounts where status=1 and user_id=?";
  29. $result = $adb->pquery($sql, array($user->id));
  30. $log->debug("Exiting getMailServerInfo method ...");
  31. return $result;
  32. }
  33. /** To get the Role of the specified user
  34. * @param $userid -- The user Id:: Type integer
  35. * @returns vtiger_roleid :: Type String
  36. */
  37. function fetchUserRole($userid)
  38. {
  39. global $log;
  40. $log->debug("Entering fetchUserRole(".$userid.") method ...");
  41. global $adb;
  42. $sql = "select roleid from vtiger_user2role where userid=?";
  43. $result = $adb->pquery($sql, array($userid));
  44. $roleid= $adb->query_result($result,0,"roleid");
  45. $log->debug("Exiting fetchUserRole method ...");
  46. return $roleid;
  47. }
  48. /** Function to get the lists of groupids releated with an user
  49. * This function accepts the user id as arguments and
  50. * returns the groupids related with the user id
  51. * as a comma seperated string
  52. */
  53. function fetchUserGroupids($userid)
  54. {
  55. global $log;
  56. $log->debug("Entering fetchUserGroupids(".$userid.") method ...");
  57. global $adb;
  58. $focus = new GetUserGroups();
  59. $focus->getAllUserGroups($userid);
  60. //Asha: Remove implode if not required and if so, also remove explode functions used at the recieving end of this function
  61. $groupidlists = implode(",",$focus->user_groups);
  62. $log->debug("Exiting fetchUserGroupids method ...");
  63. return $groupidlists;
  64. }
  65. /** Function to get all the vtiger_tab utility action permission for the specified vtiger_profile
  66. * @param $profileid -- Profile Id:: Type integer
  67. * @returns Tab Utility Action Permission Array in the following format:
  68. * $tabPermission = Array($tabid1=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission),
  69. * $tabid2=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission),
  70. * |
  71. * $tabidn=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission))
  72. *
  73. */
  74. function getTabsUtilityActionPermission($profileid)
  75. {
  76. global $log;
  77. $log->debug("Entering getTabsUtilityActionPermission(".$profileid.") method ...");
  78. global $adb;
  79. $check = Array();
  80. $temp_tabid = Array();
  81. $sql1 = "select * from vtiger_profile2utility where profileid=? order by(tabid)";
  82. $result1 = $adb->pquery($sql1, array($profileid));
  83. $num_rows1 = $adb->num_rows($result1);
  84. for($i=0; $i<$num_rows1; $i++)
  85. {
  86. $tab_id = $adb->query_result($result1,$i,'tabid');
  87. if(! in_array($tab_id,$temp_tabid))
  88. {
  89. $temp_tabid[] = $tab_id;
  90. $access = Array();
  91. }
  92. $action_id = $adb->query_result($result1,$i,'activityid');
  93. $per_id = $adb->query_result($result1,$i,'permission');
  94. $access[$action_id] = $per_id;
  95. $check[$tab_id] = $access;
  96. }
  97. $log->debug("Exiting getTabsUtilityActionPermission method ...");
  98. return $check;
  99. }
  100. /**This Function returns the Default Organisation Sharing Action Array for all modules whose sharing actions are editable
  101. * The result array will be in the following format:
  102. * Arr=(tabid1=>Sharing Action Id,
  103. * tabid2=>SharingAction Id,
  104. * |
  105. * |
  106. * |
  107. * tabid3=>SharingAcion Id)
  108. */
  109. function getDefaultSharingEditAction()
  110. {
  111. global $log;
  112. $log->debug("Entering getDefaultSharingEditAction() method ...");
  113. global $adb;
  114. //retreiving the standard permissions
  115. $sql= "select * from vtiger_def_org_share where editstatus=0";
  116. $result = $adb->pquery($sql, array());
  117. $permissionRow=$adb->fetch_array($result);
  118. do
  119. {
  120. for($j=0;$j<count($permissionRow);$j++)
  121. {
  122. $copy[$permissionRow[1]]=$permissionRow[2];
  123. }
  124. }while($permissionRow=$adb->fetch_array($result));
  125. $log->debug("Exiting getDefaultSharingEditAction method ...");
  126. return $copy;
  127. }
  128. /**This Function returns the Default Organisation Sharing Action Array for modules with edit status in (0,1)
  129. * The result array will be in the following format:
  130. * Arr=(tabid1=>Sharing Action Id,
  131. * tabid2=>SharingAction Id,
  132. * |
  133. * |
  134. * |
  135. * tabid3=>SharingAcion Id)
  136. */
  137. function getDefaultSharingAction()
  138. {
  139. global $log;
  140. $log->debug("Entering getDefaultSharingAction() method ...");
  141. global $adb;
  142. //retreivin the standard permissions
  143. $sql= "select * from vtiger_def_org_share where editstatus in(0,1)";
  144. $result = $adb->pquery($sql, array());
  145. $permissionRow=$adb->fetch_array($result);
  146. do
  147. {
  148. for($j=0;$j<count($permissionRow);$j++)
  149. {
  150. $copy[$permissionRow[1]]=$permissionRow[2];
  151. }
  152. }while($permissionRow=$adb->fetch_array($result));
  153. $log->debug("Exiting getDefaultSharingAction method ...");
  154. return $copy;
  155. }
  156. /**This Function returns the Default Organisation Sharing Action Array for all modules
  157. * The result array will be in the following format:
  158. * Arr=(tabid1=>Sharing Action Id,
  159. * tabid2=>SharingAction Id,
  160. * |
  161. * |
  162. * |
  163. * tabid3=>SharingAcion Id)
  164. */
  165. function getAllDefaultSharingAction()
  166. {
  167. global $log;
  168. $log->debug("Entering getAllDefaultSharingAction() method ...");
  169. global $adb;
  170. $copy=Array();
  171. //retreiving the standard permissions
  172. $sql= "select * from vtiger_def_org_share";
  173. $result = $adb->pquery($sql, array());
  174. $num_rows=$adb->num_rows($result);
  175. for($i=0;$i<$num_rows;$i++)
  176. {
  177. $tabid=$adb->query_result($result,$i,'tabid');
  178. $permission=$adb->query_result($result,$i,'permission');
  179. $copy[$tabid]=$permission;
  180. }
  181. $log->debug("Exiting getAllDefaultSharingAction method ...");
  182. return $copy;
  183. }
  184. /** Function to update user to vtiger_role mapping based on the userid
  185. * @param $roleid -- Role Id:: Type varchar
  186. * @param $userid User Id:: Type integer
  187. *
  188. */
  189. function updateUser2RoleMapping($roleid,$userid)
  190. {
  191. global $log;
  192. $log->debug("Entering updateUser2RoleMapping(".$roleid.",".$userid.") method ...");
  193. global $adb;
  194. //Check if row already exists
  195. $sqlcheck = "select * from vtiger_user2role where userid=?";
  196. $resultcheck = $adb->pquery($sqlcheck, array($userid));
  197. if($adb->num_rows($resultcheck) == 1)
  198. {
  199. $sqldelete = "delete from vtiger_user2role where userid=?";
  200. $delparams = array($userid);
  201. $result_delete = $adb->pquery($sqldelete, $delparams);
  202. }
  203. $sql = "insert into vtiger_user2role(userid,roleid) values(?,?)";
  204. $params = array($userid, $roleid);
  205. $result = $adb->pquery($sql, $params);
  206. $log->debug("Exiting updateUser2RoleMapping method ...");
  207. }
  208. /** Function to get the vtiger_role name from the vtiger_roleid
  209. * @param $roleid -- Role Id:: Type varchar
  210. * @returns $rolename -- Role Name:: Type varchar
  211. *
  212. */
  213. function getRoleName($roleid)
  214. {
  215. global $log;
  216. $log->debug("Entering getRoleName(".$roleid.") method ...");
  217. global $adb;
  218. $sql1 = "select * from vtiger_role where roleid=?";
  219. $result = $adb->pquery($sql1, array($roleid));
  220. $rolename = $adb->query_result($result,0,"rolename");
  221. $log->debug("Exiting getRoleName method ...");
  222. return $rolename;
  223. }
  224. /** Function to check if the currently logged in user is permitted to perform the specified action
  225. * @param $module -- Module Name:: Type varchar
  226. * @param $actionname -- Action Name:: Type varchar
  227. * @param $recordid -- Record Id:: Type integer
  228. * @returns yes or no. If Yes means this action is allowed for the currently logged in user. If no means this action is not allowed for the currently logged in user
  229. *
  230. */
  231. function isPermitted($module,$actionname,$record_id='')
  232. {
  233. global $log;
  234. $log->debug("Entering isPermitted(".$module.",".$actionname.",".$record_id.") method ...");
  235. global $adb;
  236. global $current_user;
  237. global $seclog;
  238. require('user_privileges/user_privileges_'.$current_user->id.'.php');
  239. require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
  240. $permission = "no";
  241. if(($module == 'Users' || $module == 'Home' || $module == 'uploads') && $_REQUEST['parenttab'] != 'Settings')
  242. {
  243. //These modules dont have security right now
  244. $permission = "yes";
  245. $log->debug("Exiting isPermitted method ...");
  246. return $permission;
  247. }
  248. //Checking the Access for the Settings Module
  249. if($module == 'Settings' || $module == 'Administration' || $module == 'System' || $_REQUEST['parenttab'] == 'Settings')
  250. {
  251. if(! $is_admin)
  252. {
  253. $permission = "no";
  254. }
  255. else
  256. {
  257. $permission = "yes";
  258. }
  259. $log->debug("Exiting isPermitted method ...");
  260. return $permission;
  261. }
  262. //Checking whether the user is admin
  263. if($is_admin)
  264. {
  265. $permission ="yes";
  266. $log->debug("Exiting isPermitted method ...");
  267. return $permission;
  268. }
  269. //Retreiving the Tabid and Action Id
  270. $tabid = getTabid($module);
  271. $actionid=getActionid($actionname);
  272. //If no actionid, then allow action is vtiger_tab permission is available
  273. if($actionid === '')
  274. {
  275. if($profileTabsPermission[$tabid] ==0)
  276. {
  277. $permission = "yes";
  278. $log->debug("Exiting isPermitted method ...");
  279. }
  280. else
  281. {
  282. $permission ="no";
  283. }
  284. return $permission;
  285. }
  286. $action = getActionname($actionid);
  287. //Checking for view all permission
  288. if($profileGlobalPermission[1] ==0 || $profileGlobalPermission[2] ==0)
  289. {
  290. if($actionid == 3 || $actionid == 4)
  291. {
  292. $permission = "yes";
  293. $log->debug("Exiting isPermitted method ...");
  294. return $permission;
  295. }
  296. }
  297. //Checking for edit all permission
  298. if($profileGlobalPermission[2] ==0)
  299. {
  300. if($actionid == 3 || $actionid == 4 || $actionid ==0 || $actionid ==1)
  301. {
  302. $permission = "yes";
  303. $log->debug("Exiting isPermitted method ...");
  304. return $permission;
  305. }
  306. }
  307. //Checking for vtiger_tab permission
  308. if($profileTabsPermission[$tabid] !=0)
  309. {
  310. $permission = "no";
  311. $log->debug("Exiting isPermitted method ...");
  312. return $permission;
  313. }
  314. //Checking for Action Permission
  315. if(strlen($profileActionPermission[$tabid][$actionid]) < 1 && $profileActionPermission[$tabid][$actionid] == '')
  316. {
  317. $permission = "yes";
  318. $log->debug("Exiting isPermitted method ...");
  319. return $permission;
  320. }
  321. if($profileActionPermission[$tabid][$actionid] != 0 && $profileActionPermission[$tabid][$actionid] != '')
  322. {
  323. $permission = "no";
  324. $log->debug("Exiting isPermitted method ...");
  325. return $permission;
  326. }
  327. //Checking and returning true if recorid is null
  328. if($record_id == '')
  329. {
  330. $permission = "yes";
  331. $log->debug("Exiting isPermitted method ...");
  332. return $permission;
  333. }
  334. //If modules is Products,Vendors,Faq,PriceBook then no sharing
  335. if($record_id != '')
  336. {
  337. if(getTabOwnedBy($module) == 1)
  338. {
  339. $permission = "yes";
  340. $log->debug("Exiting isPermitted method ...");
  341. return $permission;
  342. }
  343. }
  344. //Retreiving the RecordOwnerId
  345. $recOwnType='';
  346. $recOwnId='';
  347. $recordOwnerArr=getRecordOwnerId($record_id);
  348. foreach($recordOwnerArr as $type=>$id)
  349. {
  350. $recOwnType=$type;
  351. $recOwnId=$id;
  352. }
  353. //Retreiving the default Organisation sharing Access
  354. $others_permission_id = $defaultOrgSharingPermission[$tabid];
  355. if($recOwnType == 'Users')
  356. {
  357. //Checking if the Record Owner is the current User
  358. if($current_user->id == $recOwnId)
  359. {
  360. $permission = "yes";
  361. $log->debug("Exiting isPermitted method ...");
  362. return $permission;
  363. }
  364. //Checking if the Record Owner is the Subordinate User
  365. foreach($subordinate_roles_users as $roleid=>$userids)
  366. {
  367. if(in_array($recOwnId,$userids))
  368. {
  369. $permission='yes';
  370. $log->debug("Exiting isPermitted method ...");
  371. return $permission;
  372. }
  373. }
  374. }
  375. elseif($recOwnType == 'Groups')
  376. {
  377. //Checking if the record owner is the current user's group
  378. if(in_array($recOwnId,$current_user_groups))
  379. {
  380. $permission='yes';
  381. $log->debug("Exiting isPermitted method ...");
  382. return $permission;
  383. }
  384. }
  385. //Checking for Default Org Sharing permission
  386. if($others_permission_id == 0)
  387. {
  388. if($actionid == 1 || $actionid == 0)
  389. {
  390. if($module == 'Calendar')
  391. {
  392. if($recOwnType == 'Users')
  393. {
  394. $permission = isCalendarPermittedBySharing($record_id);
  395. }
  396. else
  397. {
  398. $permission='no';
  399. }
  400. }
  401. else
  402. {
  403. $permission = isReadWritePermittedBySharing($module,$tabid,$actionid,$record_id);
  404. }
  405. $log->debug("Exiting isPermitted method ...");
  406. return $permission;
  407. }
  408. elseif($actionid == 2)
  409. {
  410. $permission = "no";
  411. $log->debug("Exiting isPermitted method ...");
  412. return $permission;
  413. }
  414. else
  415. {
  416. $permission = "yes";
  417. $log->debug("Exiting isPermitted method ...");
  418. return $permission;
  419. }
  420. }
  421. elseif($others_permission_id == 1)
  422. {
  423. if($actionid == 2)
  424. {
  425. $permission = "no";
  426. $log->debug("Exiting isPermitted method ...");
  427. return $permission;
  428. }
  429. else
  430. {
  431. $permission = "yes";
  432. $log->debug("Exiting isPermitted method ...");
  433. return $permission;
  434. }
  435. }
  436. elseif($others_permission_id == 2)
  437. {
  438. $permission = "yes";
  439. $log->debug("Exiting isPermitted method ...");
  440. return $permission;
  441. }
  442. elseif($others_permission_id == 3)
  443. {
  444. if($actionid == 3 || $actionid == 4)
  445. {
  446. if($module == 'Calendar')
  447. {
  448. if($recOwnType == 'Users')
  449. {
  450. $permission = isCalendarPermittedBySharing($record_id);
  451. }
  452. else
  453. {
  454. $permission='no';
  455. }
  456. }
  457. else
  458. {
  459. $permission = isReadPermittedBySharing($module,$tabid,$actionid,$record_id);
  460. }
  461. $log->debug("Exiting isPermitted method ...");
  462. return $permission;
  463. }
  464. elseif($actionid ==0 || $actionid ==1)
  465. {
  466. if($module == 'Calendar')
  467. {
  468. $permission='no';
  469. }
  470. else
  471. {
  472. $permission = isReadWritePermittedBySharing($module,$tabid,$actionid,$record_id);
  473. }
  474. $log->debug("Exiting isPermitted method ...");
  475. return $permission;
  476. }
  477. elseif($actionid ==2)
  478. {
  479. $permission ="no";
  480. return $permission;
  481. }
  482. else
  483. {
  484. $permission = "yes";
  485. $log->debug("Exiting isPermitted method ...");
  486. return $permission;
  487. }
  488. }
  489. else
  490. {
  491. $permission = "yes";
  492. }
  493. $log->debug("Exiting isPermitted method ...");
  494. return $permission;
  495. }
  496. /** Function to check if the currently logged in user has Read Access due to Sharing for the specified record
  497. * @param $module -- Module Name:: Type varchar
  498. * @param $actionid -- Action Id:: Type integer
  499. * @param $recordid -- Record Id:: Type integer
  500. * @param $tabid -- Tab Id:: Type integer
  501. * @returns yes or no. If Yes means this action is allowed for the currently logged in user. If no means this action is not allowed for the currently logged in user
  502. */
  503. function isReadPermittedBySharing($module,$tabid,$actionid,$record_id)
  504. {
  505. global $log;
  506. $log->debug("Entering isReadPermittedBySharing(".$module.",".$tabid.",".$actionid.",".$record_id.") method ...");
  507. global $adb;
  508. global $current_user;
  509. require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
  510. $ownertype='';
  511. $ownerid='';
  512. $sharePer='no';
  513. $sharingModuleList=getSharingModuleList();
  514. if(! in_array($module,$sharingModuleList))
  515. {
  516. $sharePer='no';
  517. return $sharePer;
  518. }
  519. $recordOwnerArr=getRecordOwnerId($record_id);
  520. foreach($recordOwnerArr as $type=>$id)
  521. {
  522. $ownertype=$type;
  523. $ownerid=$id;
  524. }
  525. $varname=$module."_share_read_permission";
  526. $read_per_arr=$$varname;
  527. if($ownertype == 'Users')
  528. {
  529. //Checking the Read Sharing Permission Array in Role Users
  530. $read_role_per=$read_per_arr['ROLE'];
  531. foreach($read_role_per as $roleid=>$userids)
  532. {
  533. if(in_array($ownerid,$userids))
  534. {
  535. $sharePer='yes';
  536. $log->debug("Exiting isReadPermittedBySharing method ...");
  537. return $sharePer;
  538. }
  539. }
  540. //Checking the Read Sharing Permission Array in Groups Users
  541. $read_grp_per=$read_per_arr['GROUP'];
  542. foreach($read_grp_per as $grpid=>$userids)
  543. {
  544. if(in_array($ownerid,$userids))
  545. {
  546. $sharePer='yes';
  547. $log->debug("Exiting isReadPermittedBySharing method ...");
  548. return $sharePer;
  549. }
  550. }
  551. }
  552. elseif($ownertype == 'Groups')
  553. {
  554. $read_grp_per=$read_per_arr['GROUP'];
  555. if(array_key_exists($ownerid,$read_grp_per))
  556. {
  557. $sharePer='yes';
  558. $log->debug("Exiting isReadPermittedBySharing method ...");
  559. return $sharePer;
  560. }
  561. }
  562. //Checking for the Related Sharing Permission
  563. $relatedModuleArray=$related_module_share[$tabid];
  564. if(is_array($relatedModuleArray))
  565. {
  566. foreach($relatedModuleArray as $parModId)
  567. {
  568. $parRecordOwner=getParentRecordOwner($tabid,$parModId,$record_id);
  569. if(sizeof($parRecordOwner) > 0)
  570. {
  571. $parModName=getTabname($parModId);
  572. $rel_var=$parModName."_".$module."_share_read_permission";
  573. $read_related_per_arr=$$rel_var;
  574. $rel_owner_type='';
  575. $rel_owner_id='';
  576. foreach($parRecordOwner as $rel_type=>$rel_id)
  577. {
  578. $rel_owner_type=$rel_type;
  579. $rel_owner_id=$rel_id;
  580. }
  581. if($rel_owner_type=='Users')
  582. {
  583. //Checking in Role Users
  584. $read_related_role_per=$read_related_per_arr['ROLE'];
  585. foreach($read_related_role_per as $roleid=>$userids)
  586. {
  587. if(in_array($rel_owner_id,$userids))
  588. {
  589. $sharePer='yes';
  590. $log->debug("Exiting isReadPermittedBySharing method ...");
  591. return $sharePer;
  592. }
  593. }
  594. //Checking in Group Users
  595. $read_related_grp_per=$read_related_per_arr['GROUP'];
  596. foreach($read_related_grp_per as $grpid=>$userids)
  597. {
  598. if(in_array($rel_owner_id,$userids))
  599. {
  600. $sharePer='yes';
  601. $log->debug("Exiting isReadPermittedBySharing method ...");
  602. return $sharePer;
  603. }
  604. }
  605. }
  606. elseif($rel_owner_type=='Groups')
  607. {
  608. $read_related_grp_per=$read_related_per_arr['GROUP'];
  609. if(array_key_exists($rel_owner_id,$read_related_grp_per))
  610. {
  611. $sharePer='yes';
  612. $log->debug("Exiting isReadPermittedBySharing method ...");
  613. return $sharePer;
  614. }
  615. }
  616. }
  617. }
  618. }
  619. $log->debug("Exiting isReadPermittedBySharing method ...");
  620. return $sharePer;
  621. }
  622. /** Function to check if the currently logged in user has Write Access due to Sharing for the specified record
  623. * @param $module -- Module Name:: Type varchar
  624. * @param $actionid -- Action Id:: Type integer
  625. * @param $recordid -- Record Id:: Type integer
  626. * @param $tabid -- Tab Id:: Type integer
  627. * @returns yes or no. If Yes means this action is allowed for the currently logged in user. If no means this action is not allowed for the currently logged in user
  628. */
  629. function isReadWritePermittedBySharing($module,$tabid,$actionid,$record_id)
  630. {
  631. global $log;
  632. $log->debug("Entering isReadWritePermittedBySharing(".$module.",".$tabid.",".$actionid.",".$record_id.") method ...");
  633. global $adb;
  634. global $current_user;
  635. require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
  636. $ownertype='';
  637. $ownerid='';
  638. $sharePer='no';
  639. $sharingModuleList=getSharingModuleList();
  640. if(! in_array($module,$sharingModuleList))
  641. {
  642. $sharePer='no';
  643. return $sharePer;
  644. }
  645. $recordOwnerArr=getRecordOwnerId($record_id);
  646. foreach($recordOwnerArr as $type=>$id)
  647. {
  648. $ownertype=$type;
  649. $ownerid=$id;
  650. }
  651. $varname=$module."_share_write_permission";
  652. $write_per_arr=$$varname;
  653. if($ownertype == 'Users')
  654. {
  655. //Checking the Write Sharing Permission Array in Role Users
  656. $write_role_per=$write_per_arr['ROLE'];
  657. foreach($write_role_per as $roleid=>$userids)
  658. {
  659. if(in_array($ownerid,$userids))
  660. {
  661. $sharePer='yes';
  662. $log->debug("Exiting isReadWritePermittedBySharing method ...");
  663. return $sharePer;
  664. }
  665. }
  666. //Checking the Write Sharing Permission Array in Groups Users
  667. $write_grp_per=$write_per_arr['GROUP'];
  668. foreach($write_grp_per as $grpid=>$userids)
  669. {
  670. if(in_array($ownerid,$userids))
  671. {
  672. $sharePer='yes';
  673. $log->debug("Exiting isReadWritePermittedBySharing method ...");
  674. return $sharePer;
  675. }
  676. }
  677. }
  678. elseif($ownertype == 'Groups')
  679. {
  680. $write_grp_per=$write_per_arr['GROUP'];
  681. if(array_key_exists($ownerid,$write_grp_per))
  682. {
  683. $sharePer='yes';
  684. $log->debug("Exiting isReadWritePermittedBySharing method ...");
  685. return $sharePer;
  686. }
  687. }
  688. //Checking for the Related Sharing Permission
  689. $relatedModuleArray=$related_module_share[$tabid];
  690. if(is_array($relatedModuleArray))
  691. {
  692. foreach($relatedModuleArray as $parModId)
  693. {
  694. $parRecordOwner=getParentRecordOwner($tabid,$parModId,$record_id);
  695. if(sizeof($parRecordOwner) > 0)
  696. {
  697. $parModName=getTabname($parModId);
  698. $rel_var=$parModName."_".$module."_share_write_permission";
  699. $write_related_per_arr=$$rel_var;
  700. $rel_owner_type='';
  701. $rel_owner_id='';
  702. foreach($parRecordOwner as $rel_type=>$rel_id)
  703. {
  704. $rel_owner_type=$rel_type;
  705. $rel_owner_id=$rel_id;
  706. }
  707. if($rel_owner_type=='Users')
  708. {
  709. //Checking in Role Users
  710. $write_related_role_per=$write_related_per_arr['ROLE'];
  711. foreach($write_related_role_per as $roleid=>$userids)
  712. {
  713. if(in_array($rel_owner_id,$userids))
  714. {
  715. $sharePer='yes';
  716. $log->debug("Exiting isReadWritePermittedBySharing method ...");
  717. return $sharePer;
  718. }
  719. }
  720. //Checking in Group Users
  721. $write_related_grp_per=$write_related_per_arr['GROUP'];
  722. foreach($write_related_grp_per as $grpid=>$userids)
  723. {
  724. if(in_array($rel_owner_id,$userids))
  725. {
  726. $sharePer='yes';
  727. $log->debug("Exiting isReadWritePermittedBySharing method ...");
  728. return $sharePer;
  729. }
  730. }
  731. }
  732. elseif($rel_owner_type=='Groups')
  733. {
  734. $write_related_grp_per=$write_related_per_arr['GROUP'];
  735. if(array_key_exists($rel_owner_id,$write_related_grp_per))
  736. {
  737. $sharePer='yes';
  738. $log->debug("Exiting isReadWritePermittedBySharing method ...");
  739. return $sharePer;
  740. }
  741. }
  742. }
  743. }
  744. }
  745. $log->debug("Exiting isReadWritePermittedBySharing method ...");
  746. return $sharePer;
  747. }
  748. /** Function to get the Profile Global Information for the specified vtiger_profileid
  749. * @param $profileid -- Profile Id:: Type integer
  750. * @returns Profile Gloabal Permission Array in the following format:
  751. * $profileGloblaPermisson=Array($viewall_actionid=>permission, $editall_actionid=>permission)
  752. */
  753. function getProfileGlobalPermission($profileid)
  754. {
  755. global $log;
  756. $log->debug("Entering getProfileGlobalPermission(".$profileid.") method ...");
  757. global $adb;
  758. $sql = "select * from vtiger_profile2globalpermissions where profileid=?" ;
  759. $result = $adb->pquery($sql, array($profileid));
  760. $num_rows = $adb->num_rows($result);
  761. for($i=0; $i<$num_rows; $i++)
  762. {
  763. $act_id = $adb->query_result($result,$i,"globalactionid");
  764. $per_id = $adb->query_result($result,$i,"globalactionpermission");
  765. $copy[$act_id] = $per_id;
  766. }
  767. $log->debug("Exiting getProfileGlobalPermission method ...");
  768. return $copy;
  769. }
  770. /** Function to get the Profile Tab Permissions for the specified vtiger_profileid
  771. * @param $profileid -- Profile Id:: Type integer
  772. * @returns Profile Tabs Permission Array in the following format:
  773. * $profileTabPermisson=Array($tabid1=>permission, $tabid2=>permission,........., $tabidn=>permission)
  774. */
  775. function getProfileTabsPermission($profileid)
  776. {
  777. global $log;
  778. $log->debug("Entering getProfileTabsPermission(".$profileid.") method ...");
  779. global $adb;
  780. $sql = "select * from vtiger_profile2tab where profileid=?" ;
  781. $result = $adb->pquery($sql, array($profileid));
  782. $num_rows = $adb->num_rows($result);
  783. for($i=0; $i<$num_rows; $i++)
  784. {
  785. $tab_id = $adb->query_result($result,$i,"tabid");
  786. $per_id = $adb->query_result($result,$i,"permissions");
  787. $copy[$tab_id] = $per_id;
  788. }
  789. // TODO This is temporarily required, till we provide a hook/entry point for Emails module.
  790. // Once that is done, Webmails need to be removed permanently.
  791. $emailsTabId = getTabid('Emails');
  792. $webmailsTabid = getTabid('Webmails');
  793. if(array_key_exists($emailsTabId, $copy)) {
  794. $copy[$webmailsTabid] = $copy[$emailsTabId];
  795. }
  796. $log->debug("Exiting getProfileTabsPermission method ...");
  797. return $copy;
  798. }
  799. /** Function to get the Profile Action Permissions for the specified vtiger_profileid
  800. * @param $profileid -- Profile Id:: Type integer
  801. * @returns Profile Tabs Action Permission Array in the following format:
  802. * $tabActionPermission = Array($tabid1=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission),
  803. * $tabid2=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission),
  804. * |
  805. * $tabidn=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission))
  806. */
  807. function getProfileActionPermission($profileid)
  808. {
  809. global $log;
  810. $log->debug("Entering getProfileActionPermission(".$profileid.") method ...");
  811. global $adb;
  812. $check = Array();
  813. $temp_tabid = Array();
  814. $sql1 = "select * from vtiger_profile2standardpermissions where profileid=?";
  815. $result1 = $adb->pquery($sql1, array($profileid));
  816. $num_rows1 = $adb->num_rows($result1);
  817. for($i=0; $i<$num_rows1; $i++)
  818. {
  819. $tab_id = $adb->query_result($result1,$i,'tabid');
  820. if(! in_array($tab_id,$temp_tabid))
  821. {
  822. $temp_tabid[] = $tab_id;
  823. $access = Array();
  824. }
  825. $action_id = $adb->query_result($result1,$i,'operation');
  826. $per_id = $adb->query_result($result1,$i,'permissions');
  827. $access[$action_id] = $per_id;
  828. $check[$tab_id] = $access;
  829. }
  830. $log->debug("Exiting getProfileActionPermission method ...");
  831. return $check;
  832. }
  833. /** Function to get the Standard and Utility Profile Action Permissions for the specified vtiger_profileid
  834. * @param $profileid -- Profile Id:: Type integer
  835. * @returns Profile Tabs Action Permission Array in the following format:
  836. * $tabActionPermission = Array($tabid1=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission),
  837. * $tabid2=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission),
  838. * |
  839. * $tabidn=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission))
  840. */
  841. function getProfileAllActionPermission($profileid)
  842. {
  843. global $log;
  844. $log->debug("Entering getProfileAllActionPermission(".$profileid.") method ...");
  845. global $adb;
  846. $actionArr=getProfileActionPermission($profileid);
  847. $utilArr=getTabsUtilityActionPermission($profileid);
  848. foreach($utilArr as $tabid=>$act_arr)
  849. {
  850. $act_tab_arr=$actionArr[$tabid];
  851. foreach($act_arr as $utilid=>$util_perr)
  852. {
  853. $act_tab_arr[$utilid]=$util_perr;
  854. }
  855. $actionArr[$tabid]=$act_tab_arr;
  856. }
  857. $log->debug("Exiting getProfileAllActionPermission method ...");
  858. return $actionArr;
  859. }
  860. /** Function to get all the vtiger_role information
  861. * @returns $allRoleDetailArray-- Array will contain the details of all the vtiger_roles. RoleId will be the key:: Type array
  862. */
  863. function getAllRoleDetails()
  864. {
  865. global $log;
  866. $log->debug("Entering getAllRoleDetails() method ...");
  867. global $adb;
  868. $role_det = Array();
  869. $query = "select * from vtiger_role";
  870. $result = $adb->pquery($query, array());
  871. $num_rows=$adb->num_rows($result);
  872. for($i=0; $i<$num_rows;$i++)
  873. {
  874. $each_role_det = Array();
  875. $roleid=$adb->query_result($result,$i,'roleid');
  876. $rolename=$adb->query_result($result,$i,'rolename');
  877. $roledepth=$adb->query_result($result,$i,'depth');
  878. $sub_roledepth=$roledepth + 1;
  879. $parentrole=$adb->query_result($result,$i,'parentrole');
  880. $sub_role='';
  881. //getting the immediate subordinates
  882. $query1="select * from vtiger_role where parentrole like ? and depth=?";
  883. $res1 = $adb->pquery($query1, array($parentrole."::%", $sub_roledepth));
  884. $num_roles = $adb->num_rows($res1);
  885. if($num_roles > 0)
  886. {
  887. for($j=0; $j<$num_roles; $j++)
  888. {
  889. if($j == 0)
  890. {
  891. $sub_role .= $adb->query_result($res1,$j,'roleid');
  892. }
  893. else
  894. {
  895. $sub_role .= ','.$adb->query_result($res1,$j,'roleid');
  896. }
  897. }
  898. }
  899. $each_role_det[]=$rolename;
  900. $each_role_det[]=$roledepth;
  901. $each_role_det[]=$sub_role;
  902. $role_det[$roleid]=$each_role_det;
  903. }
  904. $log->debug("Exiting getAllRoleDetails method ...");
  905. return $role_det;
  906. }
  907. /** Function to get the vtiger_role information of the specified vtiger_role
  908. * @param $roleid -- RoleId :: Type varchar
  909. * @returns $roleInfoArray-- RoleInfoArray in the following format:
  910. * $roleInfo=Array($roleId=>Array($rolename,$parentrole,$roledepth,$immediateParent));
  911. */
  912. function getRoleInformation($roleid)
  913. {
  914. global $log;
  915. $log->debug("Entering getRoleInformation(".$roleid.") method ...");
  916. global $adb;
  917. $query = "select * from vtiger_role where roleid=?";
  918. $result = $adb->pquery($query, array($roleid));
  919. $rolename=$adb->query_result($result,0,'rolename');
  920. $parentrole=$adb->query_result($result,0,'parentrole');
  921. $roledepth=$adb->query_result($result,0,'depth');
  922. $parentRoleArr=explode('::',$parentrole);
  923. $immediateParent=$parentRoleArr[sizeof($parentRoleArr)-2];
  924. $roleDet=Array();
  925. $roleDet[]=$rolename;
  926. $roleDet[]=$parentrole;
  927. $roleDet[]=$roledepth;
  928. $roleDet[]=$immediateParent;
  929. $roleInfo=Array();
  930. $roleInfo[$roleid]=$roleDet;
  931. $log->debug("Exiting getRoleInformation method ...");
  932. return $roleInfo;
  933. }
  934. /** Function to get the vtiger_role related vtiger_users
  935. * @param $roleid -- RoleId :: Type varchar
  936. * @returns $roleUsers-- Role Related User Array in the following format:
  937. * $roleUsers=Array($userId1=>$userName,$userId2=>$userName,........,$userIdn=>$userName));
  938. */
  939. function getRoleUsers($roleId)
  940. {
  941. global $log;
  942. $log->debug("Entering getRoleUsers(".$roleId.") method ...");
  943. global $adb;
  944. $query = "select vtiger_user2role.*,vtiger_users.* from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid where roleid=?";
  945. $result = $adb->pquery($query, array($roleId));
  946. $num_rows=$adb->num_rows($result);
  947. $roleRelatedUsers=Array();
  948. for($i=0; $i<$num_rows; $i++)
  949. {
  950. $roleRelatedUsers[$adb->query_result($result,$i,'userid')]=getFullNameFromQResult($result, $i, 'Users');
  951. }
  952. $log->debug("Exiting getRoleUsers method ...");
  953. return $roleRelatedUsers;
  954. }
  955. /** Function to get the vtiger_role related user ids
  956. * @param $roleid -- RoleId :: Type varchar
  957. * @returns $roleUserIds-- Role Related User Array in the following format:
  958. * $roleUserIds=Array($userId1,$userId2,........,$userIdn);
  959. */
  960. function getRoleUserIds($roleId)
  961. {
  962. global $log;
  963. $log->debug("Entering getRoleUserIds(".$roleId.") method ...");
  964. global $adb;
  965. $query = "select vtiger_user2role.*,vtiger_users.user_name from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid where roleid=?";
  966. $result = $adb->pquery($query, array($roleId));
  967. $num_rows=$adb->num_rows($result);
  968. $roleRelatedUsers=Array();
  969. for($i=0; $i<$num_rows; $i++)
  970. {
  971. $roleRelatedUsers[]=$adb->query_result($result,$i,'userid');
  972. }
  973. $log->debug("Exiting getRoleUserIds method ...");
  974. return $roleRelatedUsers;
  975. }
  976. /** Function to get the vtiger_role and subordinate vtiger_users
  977. * @param $roleid -- RoleId :: Type varchar
  978. * @returns $roleSubUsers-- Role and Subordinates Related Users Array in the following format:
  979. * $roleSubUsers=Array($userId1=>$userName,$userId2=>$userName,........,$userIdn=>$userName));
  980. */
  981. function getRoleAndSubordinateUsers($roleId)
  982. {
  983. global $log;
  984. $log->debug("Entering getRoleAndSubordinateUsers(".$roleId.") method ...");
  985. global $adb;
  986. $roleInfoArr=getRoleInformation($roleId);
  987. $parentRole=$roleInfoArr[$roleId][1];
  988. $query = "select vtiger_user2role.*,vtiger_users.user_name from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like ?";
  989. $result = $adb->pquery($query, array($parentRole."%"));
  990. $num_rows=$adb->num_rows($result);
  991. $roleRelatedUsers=Array();
  992. for($i=0; $i<$num_rows; $i++)
  993. {
  994. $roleRelatedUsers[$adb->query_result($result,$i,'userid')]=$adb->query_result($result,$i,'user_name');
  995. }
  996. $log->debug("Exiting getRoleAndSubordinateUsers method ...");
  997. return $roleRelatedUsers;
  998. }
  999. /** Function to get the vtiger_role and subordinate Information for the specified vtiger_roleId
  1000. * @param $roleid -- RoleId :: Type varchar
  1001. * @returns $roleSubInfo-- Role and Subordinates Information array in the following format:
  1002. * $roleSubInfo=Array($roleId1=>Array($rolename,$parentrole,$roledepth,$immediateParent), $roleId2=>Array($rolename,$parentrole,$roledepth,$immediateParent),.....);
  1003. */
  1004. function getRoleAndSubordinatesInformation($roleId)
  1005. {
  1006. global $log;
  1007. $log->debug("Entering getRoleAndSubordinatesInformation(".$roleId.") method ...");
  1008. global $adb;
  1009. static $roleInfoCache = array();
  1010. if(!empty($roleInfoCache[$roleId])) {
  1011. return $roleInfoCache[$roleId];
  1012. }
  1013. $roleDetails=getRoleInformation($roleId);
  1014. $roleInfo=$roleDetails[$roleId];
  1015. $roleParentSeq=$roleInfo[1];
  1016. $query="select * from vtiger_role where parentrole like ? order by parentrole asc";
  1017. $result=$adb->pquery($query, array($roleParentSeq."%"));
  1018. $num_rows=$adb->num_rows($result);
  1019. $roleInfo=Array();
  1020. for($i=0;$i<$num_rows;$i++)
  1021. {
  1022. $roleid=$adb->query_result($result,$i,'roleid');
  1023. $rolename=$adb->query_result($result,$i,'rolename');
  1024. $roledepth=$adb->query_result($result,$i,'depth');
  1025. $parentrole=$adb->query_result($result,$i,'parentrole');
  1026. $roleDet=Array();
  1027. $roleDet[]=$rolename;
  1028. $roleDet[]=$parentrole;
  1029. $roleDet[]=$roledepth;
  1030. $roleInfo[$roleid]=$roleDet;
  1031. }
  1032. $roleInfoCache[$roleId] = $roleInfo;
  1033. $log->debug("Exiting getRoleAndSubordinatesInformation method ...");
  1034. return $roleInfo;
  1035. }
  1036. /** Function to get the vtiger_role and subordinate vtiger_role ids
  1037. * @param $roleid -- RoleId :: Type varchar
  1038. * @returns $roleSubRoleIds-- Role and Subordinates RoleIds in an Array in the following format:
  1039. * $roleSubRoleIds=Array($roleId1,$roleId2,........,$roleIdn);
  1040. */
  1041. function getRoleAndSubordinatesRoleIds($roleId)
  1042. {
  1043. global $log;
  1044. $log->debug("Entering getRoleAndSubordinatesRoleIds(".$roleId.") method ...");
  1045. global $adb;
  1046. $roleDetails=getRoleInformation($roleId);
  1047. $roleInfo=$roleDetails[$roleId];
  1048. $roleParentSeq=$roleInfo[1];
  1049. $query="select * from vtiger_role where parentrole like ? order by parentrole asc";
  1050. $result=$adb->pquery($query, array($roleParentSeq."%"));
  1051. $num_rows=$adb->num_rows($result);
  1052. $roleInfo=Array();
  1053. for($i=0;$i<$num_rows;$i++)
  1054. {
  1055. $roleid=$adb->query_result($result,$i,'roleid');
  1056. $roleInfo[]=$roleid;
  1057. }
  1058. $log->debug("Exiting getRoleAndSubordinatesRoleIds method ...");
  1059. return $roleInfo;
  1060. }
  1061. /** Function to delete the vtiger_role related sharing rules
  1062. * @param $roleid -- RoleId :: Type varchar
  1063. */
  1064. function deleteRoleRelatedSharingRules($roleId)
  1065. {
  1066. global $log;
  1067. $log->debug("Entering deleteRoleRelatedSharingRules(".$roleId.") method ...");
  1068. global $adb;
  1069. $dataShareTableColArr=Array('vtiger_datashare_grp2role'=>'to_roleid',
  1070. 'vtiger_datashare_grp2rs'=>'to_roleandsubid',
  1071. 'vtiger_datashare_role2group'=>'share_roleid',
  1072. 'vtiger_datashare_role2role'=>'share_roleid::to_roleid',
  1073. 'vtiger_datashare_role2rs'=>'share_roleid::to_roleandsubid',
  1074. 'vtiger_datashare_rs2grp'=>'share_roleandsubid',
  1075. 'vtiger_datashare_rs2role'=>'share_roleandsubid::to_roleid',
  1076. 'vtiger_datashare_rs2rs'=>'share_roleandsubid::to_roleandsubid');
  1077. foreach($dataShareTableColArr as $tablename=>$colname)
  1078. {
  1079. $colNameArr=explode('::',$colname);
  1080. $query="select shareid from ".$tablename." where ".$colNameArr[0]."=?";
  1081. $params = array($roleId);
  1082. if(sizeof($colNameArr) >1)
  1083. {
  1084. $query .=" or ".$colNameArr[1]."=?";
  1085. array_push($params, $roleId);
  1086. }
  1087. $result=$adb->pquery($query, $params);
  1088. $num_rows=$adb->num_rows($result);
  1089. for($i=0;$i<$num_rows;$i++)
  1090. {
  1091. $shareid=$adb->query_result($result,$i,'shareid');
  1092. deleteSharingRule($shareid);
  1093. }
  1094. }
  1095. $log->debug("Exiting deleteRoleRelatedSharingRules method ...");
  1096. }
  1097. /** Function to delete the group related sharing rules
  1098. * @param $roleid -- RoleId :: Type varchar
  1099. */
  1100. function deleteGroupRelatedSharingRules($grpId)
  1101. {
  1102. global $log;
  1103. $log->debug("Entering deleteGroupRelatedSharingRules(".$grpId.") method ...");
  1104. global $adb;
  1105. $dataShareTableColArr=Array('vtiger_datashare_grp2grp'=>'share_groupid::to_groupid',
  1106. 'vtiger_datashare_grp2role'=>'share_groupid',
  1107. 'vtiger_datashare_grp2rs'=>'share_groupid',
  1108. 'vtiger_datashare_role2group'=>'to_groupid',
  1109. 'vtiger_datashare_rs2grp'=>'to_groupid');
  1110. foreach($dataShareTableColArr as $tablename=>$colname)
  1111. {
  1112. $colNameArr=explode('::',$colname);
  1113. $query="select shareid from ".$tablename." where ".$colNameArr[0]."=?";
  1114. $params = array($grpId);
  1115. if(sizeof($colNameArr) >1)
  1116. {
  1117. $query .=" or ".$colNameArr[1]."=?";
  1118. array_push($params, $grpId);
  1119. }
  1120. $result=$adb->pquery($query, $params);
  1121. $num_rows=$adb->num_rows($result);
  1122. for($i=0;$i<$num_rows;$i++)
  1123. {
  1124. $shareid=$adb->query_result($result,$i,'shareid');
  1125. deleteSharingRule($shareid);
  1126. }
  1127. }
  1128. $log->debug("Exiting deleteGroupRelatedSharingRules method ...");
  1129. }
  1130. /** Function to get userid and username of all vtiger_users
  1131. * @returns $userArray -- User Array in the following format:
  1132. * $userArray=Array($userid1=>$username, $userid2=>$username,............,$useridn=>$username);
  1133. */
  1134. function getAllUserName()
  1135. {
  1136. global $log;
  1137. $log->debug("Entering getAllUserName() method ...");
  1138. global $adb;
  1139. $query="select * from vtiger_users where deleted=0";
  1140. $result = $adb->pquery($query, array());
  1141. $num_rows=$adb->num_rows($result);
  1142. $user_details=Array();
  1143. for($i=0;$i<$num_rows;$i++)
  1144. {
  1145. $userid=$adb->query_result($result,$i,'id');
  1146. $username=getFullNameFromQResult($result, $i, 'Users');
  1147. $user_details[$userid]=$username;
  1148. }
  1149. $log->debug("Exiting getAllUserName method ...");
  1150. return $user_details;
  1151. }
  1152. /** Function to get groupid and groupname of all vtiger_groups
  1153. * @returns $grpArray -- Group Array in the following format:
  1154. * $grpArray=Array($grpid1=>$grpname, $grpid2=>$grpname,............,$grpidn=>$grpname);
  1155. */
  1156. function getAllGroupName()
  1157. {
  1158. global $log;
  1159. $log->debug("Entering getAllGroupName() method ...");
  1160. global $adb;
  1161. $query="select * from vtiger_groups";
  1162. $result = $adb->pquery($query, array());
  1163. $num_rows=$adb->num_rows($result);
  1164. $group_details=Array();
  1165. for($i=0;$i<$num_rows;$i++)
  1166. {
  1167. $grpid=$adb->query_result($result,$i,'groupid');
  1168. $grpname=$adb->query_result($result,$i,'groupname');
  1169. $group_details[$grpid]=$grpname;
  1170. }
  1171. $log->debug("Exiting getAllGroupName method ...");
  1172. return $group_details;
  1173. }
  1174. /** This function is to delete the organisation level sharing rule
  1175. * It takes the following input parameters:
  1176. * $shareid -- Id of the Sharing Rule to be updated
  1177. */
  1178. function deleteSharingRule($shareid)
  1179. {
  1180. global $log;
  1181. $log->debug("Entering deleteSharingRule(".$shareid.") method ...");
  1182. global $adb;
  1183. $query2="select * from vtiger_datashare_module_rel where shareid=?";
  1184. $res=$adb->pquery($query2, array($shareid));
  1185. $typestr=$adb->query_result($res,0,'relationtype');
  1186. $tabname=getDSTableNameForType($typestr);
  1187. $query3="delete from $tabname where shareid=?";
  1188. $adb->pquery($query3, array($shareid));
  1189. $query4="delete from vtiger_datashare_module_rel where shareid=?";
  1190. $adb->pquery($query4, array($shareid));
  1191. //deleting the releated module sharing permission
  1192. $query5="delete from vtiger_datashare_relatedmodule_permission where shareid=?";
  1193. $adb->pquery($query5, array($shareid));
  1194. $log->debug("Exiting deleteSharingRule method ...");
  1195. }
  1196. /** Function get the Data Share Table Names
  1197. * @returns the following Date Share Table Name Array:
  1198. * $dataShareTableColArr=Array('GRP::GRP'=>'datashare_grp2grp',
  1199. * 'GRP::ROLE'=>'datashare_grp2role',
  1200. * 'GRP::RS'=>'datashare_grp2rs',
  1201. * 'ROLE::GRP'=>'datashare_role2group',
  1202. * 'ROLE::ROLE'=>'datashare_role2role',
  1203. * 'ROLE::RS'=>'datashare_role2rs',
  1204. * 'RS::GRP'=>'datashare_rs2grp',
  1205. * 'RS::ROLE'=>'datashare_rs2role',
  1206. * 'RS::RS'=>'datashare_rs2rs');
  1207. */
  1208. function getDataShareTableName()
  1209. {
  1210. global $log;
  1211. $log->debug("Entering getDataShareTableName() method ...");
  1212. $dataShareTableColArr=Array('GRP::GRP'=>'vtiger_datashare_grp2grp',
  1213. 'GRP::ROLE'=>'vtiger_datashare_grp2role',
  1214. 'GRP::RS'=>'vtiger_datashare_grp2rs',
  1215. 'ROLE::GRP'=>'vtiger_datashare_role2group',
  1216. 'ROLE::ROLE'=>'vtiger_datashare_role2role',
  1217. 'ROLE::RS'=>'vtiger_datashare_role2rs',
  1218. 'RS::GRP'=>'vtiger_datashare_rs2grp',
  1219. 'RS::ROLE'=>'vtiger_datashare_rs2role',
  1220. 'RS::RS'=>'vtiger_datashare_rs2rs');
  1221. $log->debug("Exiting getDataShareTableName method ...");
  1222. return $dataShareTableColArr;
  1223. }
  1224. /** Function to get the Data Share Table Name from the speciified type string
  1225. * @param $typeString -- Datashare Type Sting :: Type Varchar
  1226. * @returns Table Name -- Type Varchar
  1227. *
  1228. */
  1229. function getDSTableNameForType($typeString)
  1230. {
  1231. global $log;
  1232. $log->debug("Entering getDSTableNameForType(".$typeString.") method ...");
  1233. $dataShareTableColArr=getDataShareTableName();
  1234. $tableName=$dataShareTableColArr[$typeString];
  1235. $log->debug("Exiting getDSTableNameForType method ...");
  1236. return $tableName;
  1237. }
  1238. /** This function is to retreive the vtiger_profiles associated with the the specified user
  1239. * It takes the following input parameters:
  1240. * $userid -- The User Id:: Type Integer
  1241. *This function will return the vtiger_profiles associated to the specified vtiger_users in an Array in the following format:
  1242. * $userProfileArray=(profileid1,profileid2,profileid3,...,profileidn);
  1243. */
  1244. function getUserProfile($userId)
  1245. {
  1246. global $log;
  1247. $log->debug("Entering getUserProfile(".$userId.") method ...");
  1248. global $adb;
  1249. $roleId=fetchUserRole($userId);
  1250. $profArr=Array();
  1251. $sql1 = "select profileid from vtiger_role2profile where roleid=?";
  1252. $result1 = $adb->pquery($sql1, array($roleId));
  1253. $num_rows=$adb->num_rows($result1);
  1254. for($i=0;$i<$num_rows;$i++)
  1255. {
  1256. $profileid= $adb->query_result($result1,$i,"profileid");
  1257. $profArr[]=$profileid;
  1258. }
  1259. $log->debug("Exiting getUserProfile method ...");
  1260. return $profArr;
  1261. }
  1262. /** To retreive the global permission of the specifed user from the various vtiger_profiles associated with the user
  1263. * @param $userid -- The User Id:: Type Integer
  1264. * @returns user global permission array in the following format:
  1265. * $gloabalPerrArray=(view all action id=>permission,
  1266. edit all action id=>permission) );
  1267. */
  1268. function getCombinedUserGlobalPermissions($userId)
  1269. {
  1270. global $log;
  1271. $log->debug("Entering getCombinedUserGlobalPermissions(".$userId.") method ...");
  1272. global $adb;
  1273. $profArr=getUserProfile($userId);
  1274. $no_of_profiles=sizeof($profArr);
  1275. $userGlobalPerrArr=Array();
  1276. $userGlobalPerrArr=getProfileGlobalPermission($profArr[0]);
  1277. if($no_of_profiles != 1)
  1278. {
  1279. for($i=1;$i<$no_of_profiles;$i++)
  1280. {
  1281. $tempUserGlobalPerrArr=getProfileGlobalPermission($profArr[$i]);
  1282. foreach($userGlobalPerrArr as $globalActionId=>$globalActionPermission)
  1283. {
  1284. if($globalActionPermission == 1)
  1285. {
  1286. $now_permission = $tempUserGlobalPerrArr[$globalActionId];
  1287. if($now_permission == 0)
  1288. {
  1289. $userGlobalPerrArr[$globalActionId]=$now_permission;
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }
  1295. $log->debug("Exiting getCombinedUserGlobalPermissions method ...");
  1296. return $userGlobalPerrArr;
  1297. }
  1298. /** To retreive the vtiger_tab permissions of the specifed user from the various vtiger_profiles associated with the user
  1299. * @param $userid -- The User Id:: Type Integer
  1300. * @returns user global permission array in the following format:
  1301. * $tabPerrArray=(tabid1=>permission,
  1302. * tabid2=>permission) );
  1303. */
  1304. function getCombinedUserTabsPermissions($userId)
  1305. {
  1306. global $log;
  1307. $log->debug("Entering getCombinedUserTabsPermissions(".$userId.") method ...");
  1308. global $adb;
  1309. $profArr=getUserProfile($userId);
  1310. $no_of_profiles=sizeof($profArr);
  1311. $userTabPerrArr=Array();
  1312. $userTabPerrArr=getProfileTabsPermission($profArr[0]);
  1313. if($no_of_profiles != 1)
  1314. {
  1315. for($i=1;$i<$no_of_profiles;$i++)
  1316. {
  1317. $tempUserTabPerrArr=getProfileTabsPermission($profArr[$i]);
  1318. foreach($userTabPerrArr as $tabId=>$tabPermission)
  1319. {
  1320. if($tabPermission == 1)
  1321. {
  1322. $now_permission = $tempUserTabPerrArr[$tabId];
  1323. if($now_permission == 0)
  1324. {
  1325. $userTabPerrArr[$tabId]=$now_permission;
  1326. }
  1327. }
  1328. }
  1329. }
  1330. }
  1331. $homeTabid = getTabid('Home');
  1332. if(!array_key_exists($homeTabid, $userTabPerrArr)) {
  1333. $userTabPerrArr[$homeTabid] = 0;
  1334. }
  1335. $log->debug("Exiting getCombinedUserTabsPermissions method ...");
  1336. return $userTabPerrArr;
  1337. }
  1338. /** To retreive the vtiger_tab acion permissions of the specifed user from the various vtiger_profiles associated with the user
  1339. * @param $userid -- The User Id:: Type Integer
  1340. * @returns user global permission array in the following format:
  1341. * $actionPerrArray=(tabid1=>permission,
  1342. * tabid2=>permission);
  1343. */
  1344. function getCombinedUserActionPermissions($userId)
  1345. {
  1346. global $log;
  1347. $log->debug("Entering getCombinedUserActionPermissions(".$userId.") method ...");
  1348. global $adb;
  1349. $profArr=getUserProfile($userId);
  1350. $no_of_profiles=sizeof($profArr);
  1351. $actionPerrArr=Array();
  1352. $actionPerrArr=getProfileAllActionPermission($profArr[0]);
  1353. if($no_of_profiles != 1)
  1354. {
  1355. for($i=1;$i<$no_of_profiles;$i++)
  1356. {
  1357. $tempActionPerrArr=getProfileAllActionPermission($profArr[$i]);
  1358. foreach($actionPerrArr as $tabId=>$perArr)
  1359. {
  1360. foreach($perArr as $actionid=>$per)
  1361. {
  1362. if($per == 1)
  1363. {
  1364. $now_permission = $tempActionPerrArr[$tabId][$actionid];
  1365. if($now_permission == 0)
  1366. {
  1367. $actionPerrArr[$tabId][$actionid]=$now_permission;
  1368. }
  1369. }
  1370. }
  1371. }
  1372. }
  1373. }
  1374. $log->debug("Exiting getCombinedUserActionPermissions method ...");
  1375. return $actionPerrArr;
  1376. }
  1377. /** To retreive the parent vtiger_role of the specified vtiger_role
  1378. * @param $roleid -- The Role Id:: Type varchar
  1379. * @returns parent vtiger_role array in the following format:
  1380. * $parentRoleArray=(roleid1,roleid2,.......,roleidn);
  1381. */
  1382. function getParentRole($roleId)
  1383. {
  1384. global $log;
  1385. $log->debug("Entering getParentRole(".$roleId.") method ...");
  1386. $roleInfo=getRoleInformation($roleId);
  1387. $parentRole=$roleInfo[$roleId][1];
  1388. $tempParentRoleArr=explode('::',$parentRole);
  1389. $parentRoleArr=Array();
  1390. foreach($tempParentRoleArr as $role_id)
  1391. {
  1392. if($role_id != $roleId)
  1393. {
  1394. $parentRoleArr[]=$role_id;
  1395. }
  1396. }
  1397. $log->debug("Exiting getParentRole method ...");
  1398. return $parentRoleArr;
  1399. }
  1400. /** To retreive the subordinate vtiger_roles of the specified parent vtiger_role
  1401. * @param $roleid -- The Role Id:: Type varchar
  1402. * @returns subordinate vtiger_role array in the following format:
  1403. * $subordinateRoleArray=(roleid1,roleid2,.......,roleidn);
  1404. */
  1405. function getRoleSubordinates($roleId)
  1406. {
  1407. global $log;
  1408. $log->debug("Entering getRoleSubordinates(".$roleId.") method ...");
  1409. // Look at cache first for information
  1410. $roleSubordinates = VTCacheUtils::lookupRoleSubordinates($roleId);
  1411. if($roleSubordinates === false) {
  1412. global $adb;
  1413. $roleDetails=getRoleInformation($roleId);
  1414. $roleInfo=$roleDetails[$roleId];
  1415. $roleParentSeq=$roleInfo[1];
  1416. $query="select * from vtiger_role where parentrole like ? order by parentrole asc";
  1417. $result=$adb->pquery($query, array($roleParentSeq."::%"));
  1418. $num_rows=$adb->num_rows($result);
  1419. $roleSubordinates=Array();
  1420. for($i=0;$i<$num_rows;$i++)
  1421. {
  1422. $roleid=$adb->query_result($result,$i,'roleid');
  1423. $roleSubordinates[]=$roleid;
  1424. }
  1425. // Update cache for re-use
  1426. VTCacheUtils::updateRoleSubordinates($roleId, $roleSubordinates);
  1427. }
  1428. $log->debug("Exiting getRoleSubordinates method ...");
  1429. return $roleSubordinates;
  1430. }
  1431. /** To retreive the subordinate vtiger_roles and vtiger_users of the specified parent vtiger_role
  1432. * @param $roleid -- The Role Id:: Type varchar
  1433. * @returns subordinate vtiger_role array in the following format:
  1434. * $subordinateRoleUserArray=(roleid1=>Array(userid1,userid2,userid3),
  1435. vtiger_roleid2=>Array(userid1,userid2,userid3)
  1436. |
  1437. |
  1438. vtiger_roleidn=>Array(userid1,userid2,userid3));
  1439. */
  1440. function getSubordinateRoleAndUsers($roleId)
  1441. {
  1442. global $log;
  1443. $log->debug("Entering getSubordinateRoleAndUsers(".$roleId.") method ...");
  1444. global $adb;
  1445. $subRoleAndUsers=Array();
  1446. $subordinateRoles=getRoleSubordinates($roleId);
  1447. foreach($subordinateRoles as $subRoleId)
  1448. {
  1449. $userArray=getRoleUsers($subRoleId);
  1450. $subRoleAndUsers[$subRoleId]=$userArray;
  1451. }
  1452. $log->debug(

Large files files are truncated, but you can click here to view the full file