Newer
Older
<?php
/*********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*
********************************************************************************/
require_once('include/database/PearDatabase.php');
require_once('include/database/Postgres8.php');
require_once('include/utils/utils.php');
require_once('include/utils/GetUserGroups.php');
include_once('config.php');
require_once("include/events/include.inc");
require_once 'includes/runtime/Cache.php';
global $log;
/** To retreive the mail server info resultset for the specified user
* @param $user -- The user object:: Type Object
* @returns the mail server info resultset
*/
function getMailServerInfo($user)
{
global $log;
$log->debug("Entering getMailServerInfo(".$user->user_name.") method ...");
global $adb;
$sql = "select * from vtiger_mail_accounts where status=1 and user_id=?";
$result = $adb->pquery($sql, array($user->id));
$log->debug("Exiting getMailServerInfo method ...");
return $result;
}
/** To get the Role of the specified user
* @param $userid -- The user Id:: Type integer
* @returns vtiger_roleid :: Type String
*/
function fetchUserRole($userid)
{
global $log;
$log->debug("Entering fetchUserRole(".$userid.") method ...");
global $adb;
$sql = "select roleid from vtiger_user2role where userid=?";
$roleid= $adb->query_result($result,0,"roleid");
$log->debug("Exiting fetchUserRole method ...");
return $roleid;
}
/** Function to get the lists of groupids releated with an user
* This function accepts the user id as arguments and
* returns the groupids related with the user id
* as a comma seperated string
*/
function fetchUserGroupids($userid)
{
global $log;
$log->debug("Entering fetchUserGroupids(".$userid.") method ...");
global $adb;
$focus = new GetUserGroups();
$focus->getAllUserGroups($userid);
//Asha: Remove implode if not required and if so, also remove explode functions used at the recieving end of this function
}
/** Function to get all the vtiger_tab utility action permission for the specified vtiger_profile
* @param $profileid -- Profile Id:: Type integer
* @returns Tab Utility Action Permission Array in the following format:
* $tabPermission = Array($tabid1=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission),
* $tabid2=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission),
* |
* $tabidn=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission))
*
*/
function getTabsUtilityActionPermission($profileid)
{
global $log;
$log->debug("Entering getTabsUtilityActionPermission(".$profileid.") method ...");
global $adb;
$check = Array();
$temp_tabid = Array();
$sql1 = "select * from vtiger_profile2utility where profileid=? order by(tabid)";
$result1 = $adb->pquery($sql1, array($profileid));
$num_rows1 = $adb->num_rows($result1);
for($i=0; $i<$num_rows1; $i++)
{
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
$tab_id = $adb->query_result($result1,$i,'tabid');
if(! in_array($tab_id,$temp_tabid))
{
$temp_tabid[] = $tab_id;
$access = Array();
}
$action_id = $adb->query_result($result1,$i,'activityid');
$per_id = $adb->query_result($result1,$i,'permission');
$access[$action_id] = $per_id;
$check[$tab_id] = $access;
}
$log->debug("Exiting getTabsUtilityActionPermission method ...");
return $check;
}
/**This Function returns the Default Organisation Sharing Action Array for all modules whose sharing actions are editable
* The result array will be in the following format:
* Arr=(tabid1=>Sharing Action Id,
* tabid2=>SharingAction Id,
* |
* |
* |
* tabid3=>SharingAcion Id)
*/
function getDefaultSharingEditAction()
{
global $log;
$log->debug("Entering getDefaultSharingEditAction() method ...");
global $adb;
//retreiving the standard permissions
$sql= "select * from vtiger_def_org_share where editstatus=0";
$result = $adb->pquery($sql, array());
$permissionRow=$adb->fetch_array($result);
do
{
for($j=0;$j<php7_count($permissionRow);$j++)
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
{
$copy[$permissionRow[1]]=$permissionRow[2];
}
}while($permissionRow=$adb->fetch_array($result));
$log->debug("Exiting getDefaultSharingEditAction method ...");
return $copy;
}
/**This Function returns the Default Organisation Sharing Action Array for modules with edit status in (0,1)
* The result array will be in the following format:
* Arr=(tabid1=>Sharing Action Id,
* tabid2=>SharingAction Id,
* |
* |
* |
* tabid3=>SharingAcion Id)
*/
function getDefaultSharingAction()
{
global $log;
$log->debug("Entering getDefaultSharingAction() method ...");
global $adb;
//retreivin the standard permissions
$sql= "select * from vtiger_def_org_share where editstatus in(0,1)";
$result = $adb->pquery($sql, array());
$permissionRow=$adb->fetch_array($result);
do
{
for($j=0;$j<php7_count($permissionRow);$j++)
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
{
$copy[$permissionRow[1]]=$permissionRow[2];
}
}while($permissionRow=$adb->fetch_array($result));
$log->debug("Exiting getDefaultSharingAction method ...");
return $copy;
}
/**This Function returns the Default Organisation Sharing Action Array for all modules
* The result array will be in the following format:
* Arr=(tabid1=>Sharing Action Id,
* tabid2=>SharingAction Id,
* |
* |
* |
* tabid3=>SharingAcion Id)
*/
function getAllDefaultSharingAction()
{
global $log;
$log->debug("Entering getAllDefaultSharingAction() method ...");
global $adb;
$copy=Array();
//retreiving the standard permissions
$sql= "select * from vtiger_def_org_share";
$result = $adb->pquery($sql, array());
$num_rows=$adb->num_rows($result);
for($i=0;$i<$num_rows;$i++)
{
$tabid=$adb->query_result($result,$i,'tabid');
$permission=$adb->query_result($result,$i,'permission');
$copy[$tabid]=$permission;
}
$log->debug("Exiting getAllDefaultSharingAction method ...");
return $copy;
}
/** Function to update user to vtiger_role mapping based on the userid
* @param $roleid -- Role Id:: Type varchar
* @param $userid User Id:: Type integer
*
*/
function updateUser2RoleMapping($roleid,$userid)
{
global $log;
$log->debug("Entering updateUser2RoleMapping(".$roleid.",".$userid.") method ...");
global $adb;
//Check if row already exists
$sqlcheck = "select * from vtiger_user2role where userid=?";
$resultcheck = $adb->pquery($sqlcheck, array($userid));
if($adb->num_rows($resultcheck) == 1)
{
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
}
$sql = "insert into vtiger_user2role(userid,roleid) values(?,?)";
$params = array($userid, $roleid);
$result = $adb->pquery($sql, $params);
$log->debug("Exiting updateUser2RoleMapping method ...");
}
/** Function to get the vtiger_role name from the vtiger_roleid
* @param $roleid -- Role Id:: Type varchar
* @returns $rolename -- Role Name:: Type varchar
*
*/
function getRoleName($roleid)
{
global $log;
$log->debug("Entering getRoleName(".$roleid.") method ...");
global $adb;
$sql1 = "select * from vtiger_role where roleid=?";
$result = $adb->pquery($sql1, array($roleid));
$rolename = $adb->query_result($result,0,"rolename");
$log->debug("Exiting getRoleName method ...");
return $rolename;
}
/** Function to check if the currently logged in user is permitted to perform the specified action
* @param $module -- Module Name:: Type varchar
* @param $actionname -- Action Name:: Type varchar
* @param $recordid -- Record Id:: Type integer
* @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
*
*/
function isPermitted($module,$actionname,$record_id='')
{
global $log;
$log->debug("Entering isPermitted(".$module.",".$actionname.",".$record_id.") method ...");
global $adb;
global $current_user;
global $seclog;
require('user_privileges/user_privileges_'.$current_user->id.'.php');
require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
$permission = "no";
$parenttab = isset($_REQUEST['parenttab']) ? $_REQUEST['parenttab'] : null;
if(($module == 'Users' || $module == 'Home' || $module == 'uploads') && $parenttab != 'Settings')
{
//These modules dont have security right now
$permission = "yes";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
//Checking the Access for the Settings Module
if($module == 'Settings' || $module == 'Administration' || $module == 'System' || $parenttab == 'Settings')
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
{
if(! $is_admin)
{
$permission = "no";
}
else
{
$permission = "yes";
}
$log->debug("Exiting isPermitted method ...");
return $permission;
}
//Retreiving the Tabid and Action Id
$tabid = getTabid($module);
$actionid=getActionid($actionname);
$checkModule = $module;
if($checkModule == 'Events'){
$checkModule = 'Calendar';
}
if(vtlib_isModuleActive($checkModule)){
//Checking whether the user is admin
if($is_admin)
{
$permission ="yes";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
//If no actionid, then allow action is vtiger_tab permission is available
if($actionid === '')
{
if($profileTabsPermission[$tabid] ==0)
{
$permission = "yes";
$log->debug("Exiting isPermitted method ...");
}
else
{
$permission ="no";
}
return $permission;
}
$action = getActionname($actionid);
//Checking for view all permission
if($profileGlobalPermission[1] ==0 || $profileGlobalPermission[2] ==0)
{
if($actionid == 3 || $actionid == 4)
{
$permission = "yes";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
}
//Checking for edit all permission
if($profileGlobalPermission[2] ==0)
{
if($actionid == 3 || $actionid == 4 || $actionid ==0 || $actionid ==1)
{
$permission = "yes";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
}
//Checking for vtiger_tab permission
if(isset($profileTabsPermission[$tabid]) && $profileTabsPermission[$tabid] !=0)
{
$permission = "no";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
//Checking for Action Permission
if(isset($profileActionPermission[$tabid][$actionid]) && strlen($profileActionPermission[$tabid][$actionid]) < 1 && $profileActionPermission[$tabid][$actionid] == '')
{
$permission = "yes";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
if(isset($profileActionPermission[$tabid][$actionid]) && $profileActionPermission[$tabid][$actionid] != 0 && $profileActionPermission[$tabid][$actionid] != '')
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
{
$permission = "no";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
//Checking and returning true if recorid is null
if($record_id == '')
{
$permission = "yes";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
//If modules is Products,Vendors,Faq,PriceBook then no sharing
if($record_id != '')
{
if(getTabOwnedBy($module) == 1)
{
$permission = "yes";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
}
//Retreiving the RecordOwnerId
$recOwnType='';
$recOwnId='';
$recordOwnerArr=getRecordOwnerId($record_id);
if(empty($recordOwnerArr)){
$groupId = getRecordGroupId($record_id);
$recordOwnerArr['Groups'] = $groupId;
}
foreach($recordOwnerArr as $type=>$id)
{
$recOwnType=$type;
$recOwnId=$id;
}
//Retreiving the default Organisation sharing Access
$others_permission_id = $defaultOrgSharingPermission[$tabid];
if($recOwnType == 'Users')
{
//Checking if the Record Owner is the current User
if($current_user->id == $recOwnId)
{
$permission = "yes";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
//Checking if the Record Owner is the Subordinate User
foreach($subordinate_roles_users as $roleid=>$userids)
{
if(in_array($recOwnId,$userids))
{
$permission='yes';
if($module == 'Calendar') {
$activityType = vtws_getCalendarEntityType($record_id);
if($activityType == 'Events') {
$permission = isCalendarPermittedBySharing($record_id);
} else {
$permission = isToDoPermittedBySharing($record_id);
}
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
}
$log->debug("Exiting isPermitted method ...");
return $permission;
}
}
}
elseif($recOwnType == 'Groups')
{
//Checking if the record owner is the current user's group
if(in_array($recOwnId,$current_user_groups))
{
$permission='yes';
$log->debug("Exiting isPermitted method ...");
return $permission;
}
}
//Checking for Default Org Sharing permission
if($others_permission_id == 0)
{
if($actionid == 1 || $actionid == 0)
{
if($module == 'Calendar')
{
if($recOwnType == 'Users')
{
$permission = isCalendarPermittedBySharing($record_id);
}
else
{
$permission='no';
}
}
else
{
$permission = isReadWritePermittedBySharing($module,$tabid,$actionid,$record_id);
}
$log->debug("Exiting isPermitted method ...");
return $permission;
}
elseif($actionid == 2)
{
$permission = "no";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
else
{
$permission = "yes";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
}
elseif($others_permission_id == 1)
{
if($actionid == 2)
{
$permission = "no";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
else
{
$permission = "yes";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
}
elseif($others_permission_id == 2)
{
$permission = "yes";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
elseif($others_permission_id == 3)
{
if($actionid == 3 || $actionid == 4)
{
if($module == 'Calendar')
{
if($recOwnType == 'Users')
{
$activityType = vtws_getCalendarEntityType($record_id);
if($activityType == 'Events') {
$permission = isCalendarPermittedBySharing($record_id);
} else {
$permission = isToDoPermittedBySharing($record_id);
}
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
}
else
{
$permission='no';
}
}
else
{
$permission = isReadPermittedBySharing($module,$tabid,$actionid,$record_id);
}
$log->debug("Exiting isPermitted method ...");
return $permission;
}
elseif($actionid ==0 || $actionid ==1)
{
if($module == 'Calendar')
{
$permission='no';
}
else
{
$permission = isReadWritePermittedBySharing($module,$tabid,$actionid,$record_id);
}
$log->debug("Exiting isPermitted method ...");
return $permission;
}
elseif($actionid ==2)
{
$permission ="no";
return $permission;
}
else
{
$permission = "yes";
$log->debug("Exiting isPermitted method ...");
return $permission;
}
}
else
{
$permission = "yes";
}
}else {
$permission = "no";
}
$log->debug("Exiting isPermitted method ...");
return $permission;
}
/** Function to check if the currently logged in user has Read Access due to Sharing for the specified record
* @param $module -- Module Name:: Type varchar
* @param $actionid -- Action Id:: Type integer
* @param $recordid -- Record Id:: Type integer
* @param $tabid -- Tab Id:: Type integer
* @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
*/
function isReadPermittedBySharing($module,$tabid,$actionid,$record_id)
{
global $log;
$log->debug("Entering isReadPermittedBySharing(".$module.",".$tabid.",".$actionid.",".$record_id.") method ...");
global $adb;
global $current_user;
require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
$ownertype='';
$ownerid='';
$sharePer='no';
$sharingModuleList=getSharingModuleList();
if(! in_array($module,$sharingModuleList))
{
$sharePer='no';
return $sharePer;
}
$recordOwnerArr=getRecordOwnerId($record_id);
foreach($recordOwnerArr as $type=>$id)
{
$ownertype=$type;
$ownerid=$id;
}
$varname=$module."_share_read_permission";
$read_per_arr=$$varname;
if($ownertype == 'Users')
{
//Checking the Read Sharing Permission Array in Role Users
$read_role_per=$read_per_arr['ROLE'];
foreach($read_role_per as $roleid=>$userids)
{
if(in_array($ownerid,$userids))
{
$sharePer='yes';
$log->debug("Exiting isReadPermittedBySharing method ...");
return $sharePer;
}
}
//Checking the Read Sharing Permission Array in Groups Users
$read_grp_per=$read_per_arr['GROUP'];
foreach($read_grp_per as $grpid=>$userids)
{
if(in_array($ownerid,$userids))
{
$sharePer='yes';
$log->debug("Exiting isReadPermittedBySharing method ...");
return $sharePer;
}
}
}
elseif($ownertype == 'Groups')
{
$read_grp_per=$read_per_arr['GROUP'];
if(array_key_exists($ownerid,$read_grp_per))
{
$sharePer='yes';
$log->debug("Exiting isReadPermittedBySharing method ...");
return $sharePer;
}
}
//Checking for the Related Sharing Permission
$relatedModuleArray=$related_module_share[$tabid];
if(is_array($relatedModuleArray))
{
foreach($relatedModuleArray as $parModId)
{
$parRecordOwner=getParentRecordOwner($tabid,$parModId,$record_id);
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
{
$parModName=getTabname($parModId);
$rel_var=$parModName."_".$module."_share_read_permission";
$read_related_per_arr=$$rel_var;
$rel_owner_type='';
$rel_owner_id='';
foreach($parRecordOwner as $rel_type=>$rel_id)
{
$rel_owner_type=$rel_type;
$rel_owner_id=$rel_id;
}
if($rel_owner_type=='Users')
{
//Checking in Role Users
$read_related_role_per=$read_related_per_arr['ROLE'];
foreach($read_related_role_per as $roleid=>$userids)
{
if(in_array($rel_owner_id,$userids))
{
$sharePer='yes';
$log->debug("Exiting isReadPermittedBySharing method ...");
return $sharePer;
}
}
//Checking in Group Users
$read_related_grp_per=$read_related_per_arr['GROUP'];
foreach($read_related_grp_per as $grpid=>$userids)
{
if(in_array($rel_owner_id,$userids))
{
$sharePer='yes';
$log->debug("Exiting isReadPermittedBySharing method ...");
return $sharePer;
}
}
}
elseif($rel_owner_type=='Groups')
{
$read_related_grp_per=$read_related_per_arr['GROUP'];
if(array_key_exists($rel_owner_id,$read_related_grp_per))
{
$sharePer='yes';
$log->debug("Exiting isReadPermittedBySharing method ...");
return $sharePer;
}
}
}
}
}
$log->debug("Exiting isReadPermittedBySharing method ...");
return $sharePer;
}
/** Function to check if the currently logged in user has Write Access due to Sharing for the specified record
* @param $module -- Module Name:: Type varchar
* @param $actionid -- Action Id:: Type integer
* @param $recordid -- Record Id:: Type integer
* @param $tabid -- Tab Id:: Type integer
* @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
*/
function isReadWritePermittedBySharing($module,$tabid,$actionid,$record_id)
{
global $log;
$log->debug("Entering isReadWritePermittedBySharing(".$module.",".$tabid.",".$actionid.",".$record_id.") method ...");
global $adb;
global $current_user;
require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
$ownertype='';
$ownerid='';
$sharePer='no';
$sharingModuleList=getSharingModuleList();
if(! in_array($module,$sharingModuleList))
{
$sharePer='no';
return $sharePer;
}
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
$recordOwnerArr=getRecordOwnerId($record_id);
foreach($recordOwnerArr as $type=>$id)
{
$ownertype=$type;
$ownerid=$id;
}
$varname=$module."_share_write_permission";
$write_per_arr=$$varname;
if($ownertype == 'Users')
{
//Checking the Write Sharing Permission Array in Role Users
$write_role_per=$write_per_arr['ROLE'];
foreach($write_role_per as $roleid=>$userids)
{
if(in_array($ownerid,$userids))
{
$sharePer='yes';
$log->debug("Exiting isReadWritePermittedBySharing method ...");
return $sharePer;
}
}
//Checking the Write Sharing Permission Array in Groups Users
$write_grp_per=$write_per_arr['GROUP'];
foreach($write_grp_per as $grpid=>$userids)
{
if(in_array($ownerid,$userids))
{
$sharePer='yes';
$log->debug("Exiting isReadWritePermittedBySharing method ...");
return $sharePer;
}
}
}
elseif($ownertype == 'Groups')
{
$write_grp_per=$write_per_arr['GROUP'];
if(array_key_exists($ownerid,$write_grp_per))
{
$sharePer='yes';
$log->debug("Exiting isReadWritePermittedBySharing method ...");
return $sharePer;
}
}
//Checking for the Related Sharing Permission
$relatedModuleArray=$related_module_share[$tabid];
if(is_array($relatedModuleArray))
{
foreach($relatedModuleArray as $parModId)
{
$parRecordOwner=getParentRecordOwner($tabid,$parModId,$record_id);
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
{
$parModName=getTabname($parModId);
$rel_var=$parModName."_".$module."_share_write_permission";
$write_related_per_arr=$$rel_var;
$rel_owner_type='';
$rel_owner_id='';
foreach($parRecordOwner as $rel_type=>$rel_id)
{
$rel_owner_type=$rel_type;
$rel_owner_id=$rel_id;
}
if($rel_owner_type=='Users')
{
//Checking in Role Users
$write_related_role_per=$write_related_per_arr['ROLE'];
foreach($write_related_role_per as $roleid=>$userids)
{
if(in_array($rel_owner_id,$userids))
{
$sharePer='yes';
$log->debug("Exiting isReadWritePermittedBySharing method ...");
return $sharePer;
}
}
//Checking in Group Users
$write_related_grp_per=$write_related_per_arr['GROUP'];
foreach($write_related_grp_per as $grpid=>$userids)
{
if(in_array($rel_owner_id,$userids))
{
$sharePer='yes';
$log->debug("Exiting isReadWritePermittedBySharing method ...");
return $sharePer;
}
}
}
elseif($rel_owner_type=='Groups')
{
$write_related_grp_per=$write_related_per_arr['GROUP'];
if(array_key_exists($rel_owner_id,$write_related_grp_per))
{
$sharePer='yes';
$log->debug("Exiting isReadWritePermittedBySharing method ...");
return $sharePer;
}
}
}
}
}
$log->debug("Exiting isReadWritePermittedBySharing method ...");
return $sharePer;
}
/** Function to get the Profile Global Information for the specified vtiger_profileid
* @param $profileid -- Profile Id:: Type integer
* @returns Profile Gloabal Permission Array in the following format:
* $profileGloblaPermisson=Array($viewall_actionid=>permission, $editall_actionid=>permission)
*/
function getProfileGlobalPermission($profileid)
{
global $log;
$log->debug("Entering getProfileGlobalPermission(".$profileid.") method ...");
global $adb;
$sql = "select * from vtiger_profile2globalpermissions where profileid=?" ;
$result = $adb->pquery($sql, array($profileid));
$num_rows = $adb->num_rows($result);
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
for($i=0; $i<$num_rows; $i++)
{
$act_id = $adb->query_result($result,$i,"globalactionid");
$per_id = $adb->query_result($result,$i,"globalactionpermission");
$copy[$act_id] = $per_id;
}
$log->debug("Exiting getProfileGlobalPermission method ...");
return $copy;
}
/** Function to get the Profile Tab Permissions for the specified vtiger_profileid
* @param $profileid -- Profile Id:: Type integer
* @returns Profile Tabs Permission Array in the following format:
* $profileTabPermisson=Array($tabid1=>permission, $tabid2=>permission,........., $tabidn=>permission)
*/
function getProfileTabsPermission($profileid)
{
global $log;
$log->debug("Entering getProfileTabsPermission(".$profileid.") method ...");
global $adb;
$sql = "select * from vtiger_profile2tab where profileid=?" ;
$result = $adb->pquery($sql, array($profileid));
$num_rows = $adb->num_rows($result);
$copy = array();
for($i=0; $i<$num_rows; $i++)
{
$tab_id = $adb->query_result($result,$i,"tabid");
$per_id = $adb->query_result($result,$i,"permissions");
$copy[$tab_id] = $per_id;
}
// TODO This is temporarily required, till we provide a hook/entry point for Emails module.
// Once that is done, Webmails need to be removed permanently.
$emailsTabId = getTabid('Emails');
$webmailsTabid = getTabid('Webmails');
if(array_key_exists($emailsTabId, $copy)) {
$copy[$webmailsTabid] = $copy[$emailsTabId];
}
$log->debug("Exiting getProfileTabsPermission method ...");
return $copy;
}
/** Function to get the Profile Action Permissions for the specified vtiger_profileid
* @param $profileid -- Profile Id:: Type integer
* @returns Profile Tabs Action Permission Array in the following format:
* $tabActionPermission = Array($tabid1=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission),
* $tabid2=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission),
* |
* $tabidn=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission))
*/
function getProfileActionPermission($profileid)
{
global $log;
$log->debug("Entering getProfileActionPermission(".$profileid.") method ...");
global $adb;
$check = Array();
$temp_tabid = Array();
$sql1 = "select * from vtiger_profile2standardpermissions where profileid=?";
$result1 = $adb->pquery($sql1, array($profileid));
$num_rows1 = $adb->num_rows($result1);
for($i=0; $i<$num_rows1; $i++)
{
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
$tab_id = $adb->query_result($result1,$i,'tabid');
if(! in_array($tab_id,$temp_tabid))
{
$temp_tabid[] = $tab_id;
$access = Array();
}
$action_id = $adb->query_result($result1,$i,'operation');
$per_id = $adb->query_result($result1,$i,'permissions');
$access[$action_id] = $per_id;
$check[$tab_id] = $access;
}
$log->debug("Exiting getProfileActionPermission method ...");
return $check;
}
/** Function to get the Standard and Utility Profile Action Permissions for the specified vtiger_profileid
* @param $profileid -- Profile Id:: Type integer
* @returns Profile Tabs Action Permission Array in the following format:
* $tabActionPermission = Array($tabid1=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission),
* $tabid2=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission),
* |
* $tabidn=>Array(actionid1=>permission, actionid2=>permission,...,actionidn=>permission))
*/
function getProfileAllActionPermission($profileid)
{
global $log;
$log->debug("Entering getProfileAllActionPermission(".$profileid.") method ...");
global $adb;
$actionArr=getProfileActionPermission($profileid);
$utilArr=getTabsUtilityActionPermission($profileid);
foreach($utilArr as $tabid=>$act_arr)
{
$act_tab_arr=$actionArr[$tabid];
foreach($act_arr as $utilid=>$util_perr)
{
$act_tab_arr[$utilid]=$util_perr;
}
$actionArr[$tabid]=$act_tab_arr;
}
$log->debug("Exiting getProfileAllActionPermission method ...");
return $actionArr;
}
/** Function to get all the vtiger_role information
* @returns $allRoleDetailArray-- Array will contain the details of all the vtiger_roles. RoleId will be the key:: Type array
*/
function getAllRoleDetails()
{
global $log;
$log->debug("Entering getAllRoleDetails() method ...");
global $adb;
$role_det = Array();
$query = "select * from vtiger_role";
$result = $adb->pquery($query, array());