[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
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 ('config.php'); 12 require_once ('modules/Users/Users.php'); 13 require_once ('include/utils/UserInfoUtil.php'); 14 require_once ('include/utils/utils.php'); 15 require_once ('include/utils/GetUserGroups.php'); 16 require_once ('include/utils/GetGroupUsers.php'); 17 18 19 /** Creates a file with all the user, user-role,user-profile, user-groups informations 20 * @param $userid -- user id:: Type integer 21 * @returns user_privileges_userid file under the user_privileges directory 22 */ 23 24 function createUserPrivilegesfile($userid) 25 { 26 global $root_directory; 27 $handle=@fopen($root_directory.'user_privileges/user_privileges_'.$userid.'.php',"w+"); 28 29 if($handle) 30 { 31 $newbuf=''; 32 $newbuf .="<?php\n\n"; 33 $newbuf .="\n"; 34 $newbuf .= "//This is the access privilege file\n"; 35 $user_focus= new Users(); 36 $user_focus->retrieve_entity_info($userid,"Users"); 37 $userInfo=Array(); 38 $user_focus->column_fields["id"] = ''; 39 $user_focus->id = $userid; 40 foreach($user_focus->column_fields as $field=>$value_iter) 41 { 42 $userInfo[$field]= $user_focus->$field; 43 } 44 45 if($user_focus->is_admin == 'on') 46 { 47 $newbuf .= "\$is_admin=true;\n"; 48 $newbuf .="\n"; 49 $newbuf .= "\$user_info=".constructSingleStringKeyValueArray($userInfo).";\n"; 50 $newbuf .= "\n"; 51 $newbuf .= "?>"; 52 fputs($handle, $newbuf); 53 fclose($handle); 54 return; 55 } 56 else 57 { 58 $newbuf .= "\$is_admin=false;\n"; 59 $newbuf .= "\n"; 60 61 $globalPermissionArr=getCombinedUserGlobalPermissions($userid); 62 $tabsPermissionArr=getCombinedUserTabsPermissions($userid); 63 //$tabsPermissionArr=getCombinedUserTabsPermissions($userid); 64 $actionPermissionArr=getCombinedUserActionPermissions($userid); 65 $user_role=fetchUserRole($userid); 66 $user_role_info=getRoleInformation($user_role); 67 $user_role_parent=$user_role_info[$user_role][1]; 68 $userGroupFocus=new GetUserGroups(); 69 $userGroupFocus->getAllUserGroups($userid); 70 $subRoles=getRoleSubordinates($user_role); 71 $subRoleAndUsers=getSubordinateRoleAndUsers($user_role); 72 $def_org_share=getDefaultSharingAction(); 73 $parentRoles=getParentRole($user_role); 74 75 76 77 78 $newbuf .= "\$current_user_roles='".$user_role."';\n"; 79 $newbuf .= "\n"; 80 $newbuf .= "\$current_user_parent_role_seq='".$user_role_parent."';\n"; 81 $newbuf .= "\n"; 82 $newbuf .= "\$current_user_profiles=".constructSingleArray(getUserProfile($userid)).";\n"; 83 $newbuf .= "\n"; 84 $newbuf .= "\$profileGlobalPermission=".constructArray($globalPermissionArr).";\n"; 85 $newbuf .="\n"; 86 $newbuf .= "\$profileTabsPermission=".constructArray($tabsPermissionArr).";\n"; 87 $newbuf .="\n"; 88 $newbuf .= "\$profileActionPermission=".constructTwoDimensionalArray($actionPermissionArr).";\n"; 89 $newbuf .="\n"; 90 $newbuf .= "\$current_user_groups=".constructSingleArray($userGroupFocus->user_groups).";\n"; 91 $newbuf .="\n"; 92 $newbuf .= "\$subordinate_roles=".constructSingleCharArray($subRoles).";\n"; 93 $newbuf .="\n"; 94 $newbuf .= "\$parent_roles=".constructSingleCharArray($parentRoles).";\n"; 95 $newbuf .="\n"; 96 $newbuf .= "\$subordinate_roles_users=".constructTwoDimensionalCharIntSingleArray($subRoleAndUsers).";\n"; 97 $newbuf .="\n"; 98 $newbuf .= "\$user_info=".constructSingleStringKeyValueArray($userInfo).";\n"; 99 100 $newbuf .= "?>"; 101 fputs($handle, $newbuf); 102 fclose($handle); 103 } 104 } 105 } 106 107 /** Creates a file with all the organization default sharing permissions and custom sharing permissins specific for the specified user. In this file the information of the other users whose data is shared with the specified user is stored. 108 * @param $userid -- user id:: Type integer 109 * @returns sharing_privileges_userid file under the user_privileges directory 110 */ 111 function createUserSharingPrivilegesfile($userid) 112 { 113 global $adb, $root_directory; 114 checkFileAccessForInclusion('user_privileges/user_privileges_'.$userid.'.php'); 115 require('user_privileges/user_privileges_'.$userid.'.php'); 116 $handle=@fopen($root_directory.'user_privileges/sharing_privileges_'.$userid.'.php',"w+"); 117 118 if($handle) 119 { 120 $newbuf=''; 121 $newbuf .="<?php\n\n"; 122 $newbuf .="\n"; 123 $newbuf .= "//This is the sharing access privilege file\n"; 124 $user_focus= new Users(); 125 $user_focus->retrieve_entity_info($userid,"Users"); 126 if($user_focus->is_admin == 'on') 127 { 128 $newbuf .= "\n"; 129 $newbuf .= "?>"; 130 fputs($handle, $newbuf); 131 fclose($handle); 132 return; 133 } 134 else 135 { 136 //Constructig the Default Org Share Array 137 $def_org_share=getAllDefaultSharingAction(); 138 $newbuf .= "\$defaultOrgSharingPermission=".constructArray($def_org_share).";\n"; 139 $newbuf .= "\n"; 140 141 //Constructing the Related Module Sharing Array 142 $relModSharArr=Array(); 143 $query ="select * from vtiger_datashare_relatedmodules"; 144 $result=$adb->pquery($query, array()); 145 $num_rows = $adb->num_rows($result); 146 for($i=0;$i<$num_rows;$i++) 147 { 148 $parTabId=$adb->query_result($result,$i,'tabid'); 149 $relTabId=$adb->query_result($result,$i,'relatedto_tabid'); 150 if(is_array($relModSharArr[$relTabId])) 151 { 152 $temArr=$relModSharArr[$relTabId]; 153 $temArr[]=$parTabId; 154 } 155 else 156 { 157 $temArr=Array(); 158 $temArr[]=$parTabId; 159 } 160 $relModSharArr[$relTabId]=$temArr; 161 } 162 163 $newbuf .= "\$related_module_share=".constructTwoDimensionalValueArray($relModSharArr).";\n\n"; 164 165 //Constructing Lead Sharing Rules 166 $lead_share_per_array=getUserModuleSharingObjects("Leads",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups); 167 $lead_share_read_per=$lead_share_per_array['read']; 168 $lead_share_write_per=$lead_share_per_array['write']; 169 $lead_sharingrule_members=$lead_share_per_array['sharingrules']; 170 171 $newbuf .= "\$Leads_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($lead_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($lead_share_read_per['GROUP']).");\n\n"; 172 $newbuf .= "\$Leads_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($lead_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($lead_share_write_per['GROUP']).");\n\n"; 173 174 //Constructing the Lead Email Related Module Sharing Array 175 $lead_related_email=getRelatedModuleSharingArray("Leads","Emails",$lead_sharingrule_members,$lead_share_read_per,$lead_share_write_per,$def_org_share); 176 177 $lead_email_share_read_per=$lead_related_email['read']; 178 $lead_email_share_write_per=$lead_related_email['write']; 179 180 $newbuf .= "\$Leads_Emails_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($lead_email_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($lead_email_share_read_per['GROUP']).");\n\n"; 181 $newbuf .= "\$Leads_Emails_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($lead_email_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($lead_email_share_write_per['GROUP']).");\n\n"; 182 183 184 185 //Constructing Account Sharing Rules 186 $account_share_per_array=getUserModuleSharingObjects("Accounts",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups); 187 $account_share_read_per=$account_share_per_array['read']; 188 $account_share_write_per=$account_share_per_array['write']; 189 $account_sharingrule_members=$account_share_per_array['sharingrules']; 190 /*echo '<pre>'; 191 print_r($account_share_read_per['GROUP']); 192 echo '</pre>';*/ 193 $newbuf .= "\$Accounts_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($account_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($account_share_read_per['GROUP']).");\n\n"; 194 $newbuf .= "\$Accounts_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($account_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($account_share_write_per['GROUP']).");\n\n"; 195 196 //Constructing Contact Sharing Rules 197 $newbuf .= "\$Contacts_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($account_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($account_share_read_per['GROUP']).");\n\n"; 198 $newbuf .= "\$Contacts_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($account_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($account_share_write_per['GROUP']).");\n\n"; 199 200 201 202 203 204 //Constructing the Account Potential Related Module Sharing Array 205 $acct_related_pot=getRelatedModuleSharingArray("Accounts","Potentials",$account_sharingrule_members,$account_share_read_per,$account_share_write_per,$def_org_share); 206 207 $acc_pot_share_read_per=$acct_related_pot['read']; 208 $acc_pot_share_write_per=$acct_related_pot['write']; 209 210 $newbuf .= "\$Accounts_Potentials_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($acc_pot_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($acc_pot_share_read_per['GROUP']).");\n\n"; 211 $newbuf .= "\$Accounts_Potentials_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($acc_pot_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($acc_pot_share_write_per['GROUP']).");\n\n"; 212 213 //Constructing the Account Ticket Related Module Sharing Array 214 $acct_related_tkt=getRelatedModuleSharingArray("Accounts","HelpDesk",$account_sharingrule_members,$account_share_read_per,$account_share_write_per,$def_org_share); 215 216 $acc_tkt_share_read_per=$acct_related_tkt['read']; 217 $acc_tkt_share_write_per=$acct_related_tkt['write']; 218 219 $newbuf .= "\$Accounts_HelpDesk_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($acc_tkt_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($acc_tkt_share_read_per['GROUP']).");\n\n"; 220 $newbuf .= "\$Accounts_HelpDesk_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($acc_tkt_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($acc_tkt_share_write_per['GROUP']).");\n\n"; 221 222 //Constructing the Account Email Related Module Sharing Array 223 $acct_related_email=getRelatedModuleSharingArray("Accounts","Emails",$account_sharingrule_members,$account_share_read_per,$account_share_write_per,$def_org_share); 224 225 $acc_email_share_read_per=$acct_related_email['read']; 226 $acc_email_share_write_per=$acct_related_email['write']; 227 228 $newbuf .= "\$Accounts_Emails_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($acc_email_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($acc_email_share_read_per['GROUP']).");\n\n"; 229 $newbuf .= "\$Accounts_Emails_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($acc_email_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($acc_email_share_write_per['GROUP']).");\n\n"; 230 231 //Constructing the Account Quote Related Module Sharing Array 232 $acct_related_qt=getRelatedModuleSharingArray("Accounts","Quotes",$account_sharingrule_members,$account_share_read_per,$account_share_write_per,$def_org_share); 233 234 $acc_qt_share_read_per=$acct_related_qt['read']; 235 $acc_qt_share_write_per=$acct_related_qt['write']; 236 237 $newbuf .= "\$Accounts_Quotes_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($acc_qt_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($acc_qt_share_read_per['GROUP']).");\n\n"; 238 $newbuf .= "\$Accounts_Quotes_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($acc_qt_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($acc_qt_share_write_per['GROUP']).");\n\n"; 239 240 //Constructing the Account SalesOrder Related Module Sharing Array 241 $acct_related_so=getRelatedModuleSharingArray("Accounts","SalesOrder",$account_sharingrule_members,$account_share_read_per,$account_share_write_per,$def_org_share); 242 243 $acc_so_share_read_per=$acct_related_so['read']; 244 $acc_so_share_write_per=$acct_related_so['write']; 245 246 $newbuf .= "\$Accounts_SalesOrder_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($acc_so_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($acc_so_share_read_per['GROUP']).");\n\n"; 247 $newbuf .= "\$Accounts_SalesOrder_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($acc_so_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($acc_so_share_write_per['GROUP']).");\n\n"; 248 249 250 //Constructing the Account Invoice Related Module Sharing Array 251 $acct_related_inv=getRelatedModuleSharingArray("Accounts","Invoice",$account_sharingrule_members,$account_share_read_per,$account_share_write_per,$def_org_share); 252 253 $acc_inv_share_read_per=$acct_related_inv['read']; 254 $acc_inv_share_write_per=$acct_related_inv['write']; 255 256 $newbuf .= "\$Accounts_Invoice_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($acc_inv_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($acc_inv_share_read_per['GROUP']).");\n\n"; 257 $newbuf .= "\$Accounts_Invoice_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($acc_inv_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($acc_inv_share_write_per['GROUP']).");\n\n"; 258 259 260 //Constructing Potential Sharing Rules 261 $pot_share_per_array=getUserModuleSharingObjects("Potentials",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups); 262 $pot_share_read_per=$pot_share_per_array['read']; 263 $pot_share_write_per=$pot_share_per_array['write']; 264 $pot_sharingrule_members=$pot_share_per_array['sharingrules']; 265 $newbuf .= "\$Potentials_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($pot_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($pot_share_read_per['GROUP']).");\n\n"; 266 $newbuf .= "\$Potentials_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($pot_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($pot_share_write_per['GROUP']).");\n\n"; 267 268 //Constructing the Potential Quotes Related Module Sharing Array 269 $pot_related_qt=getRelatedModuleSharingArray("Potentials","Quotes",$pot_sharingrule_members,$pot_share_read_per,$pot_share_write_per,$def_org_share); 270 271 $pot_qt_share_read_per=$pot_related_qt['read']; 272 $pot_qt_share_write_per=$pot_related_qt['write']; 273 274 $newbuf .= "\$Potentials_Quotes_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($pot_qt_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($pot_qt_share_read_per['GROUP']).");\n\n"; 275 $newbuf .= "\$Potentials_Quotes_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($pot_qt_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($pot_qt_share_write_per['GROUP']).");\n\n"; 276 277 //Constructing the Potential SalesOrder Related Module Sharing Array 278 $pot_related_inv=getRelatedModuleSharingArray("Potentials","SalesOrder",$pot_sharingrule_members,$pot_share_read_per,$pot_share_write_per,$def_org_share); 279 280 281 282 $pot_inv_share_read_per=$pot_related_inv['read']; 283 $pot_inv_share_write_per=$pot_related_inv['write']; 284 285 $newbuf .= "\$Potentials_SalesOrder_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($pot_inv_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($pot_inv_share_read_per['GROUP']).");\n\n"; 286 $newbuf .= "\$Potentials_SalesOrder_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($pot_inv_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($pot_inv_share_write_per['GROUP']).");\n\n"; 287 288 289 290 291 //Constructing HelpDesk Sharing Rules 292 $hd_share_per_array=getUserModuleSharingObjects("HelpDesk",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups); 293 $hd_share_read_per=$hd_share_per_array['read']; 294 $hd_share_write_per=$hd_share_per_array['write']; 295 $newbuf .= "\$HelpDesk_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($hd_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($hd_share_read_per['GROUP']).");\n\n"; 296 $newbuf .= "\$HelpDesk_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($hd_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($hd_share_write_per['GROUP']).");\n\n"; 297 298 //Constructing Emails Sharing Rules 299 $email_share_per_array=getUserModuleSharingObjects("Emails",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups); 300 $email_share_read_per=$email_share_per_array['read']; 301 $email_share_write_per=$email_share_per_array['write']; 302 $newbuf .= "\$Emails_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($email_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($email_share_read_per['GROUP']).");\n\n"; 303 $newbuf .= "\$Emails_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($email_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($email_share_write_per['GROUP']).");\n\n"; 304 305 //Constructing Campaigns Sharing Rules 306 $campaign_share_per_array=getUserModuleSharingObjects("Campaigns",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups); 307 $campaign_share_read_per=$campaign_share_per_array['read']; 308 $campaign_share_write_per=$campaign_share_per_array['write']; 309 $newbuf .= "\$Campaigns_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($campaign_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($campaign_share_read_per['GROUP']).");\n\n"; 310 $newbuf .= "\$Campaigns_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($campaign_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($campaign_share_write_per['GROUP']).");\n\n"; 311 312 313 //Constructing Quotes Sharing Rules 314 $quotes_share_per_array=getUserModuleSharingObjects("Quotes",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups); 315 $quotes_share_read_per=$quotes_share_per_array['read']; 316 $quotes_share_write_per=$quotes_share_per_array['write']; 317 $quotes_sharingrule_members=$quotes_share_per_array['sharingrules']; 318 $newbuf .= "\$Quotes_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($quotes_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($quotes_share_read_per['GROUP']).");\n\n"; 319 $newbuf .= "\$Quotes_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($quotes_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($quotes_share_write_per['GROUP']).");\n\n"; 320 321 //Constructing the Quote SalesOrder Related Module Sharing Array 322 $qt_related_so=getRelatedModuleSharingArray("Quotes","SalesOrder",$quotes_sharingrule_members,$quotes_share_read_per,$quotes_share_write_per,$def_org_share); 323 324 $qt_so_share_read_per=$qt_related_so['read']; 325 $qt_so_share_write_per=$qt_related_so['write']; 326 327 $newbuf .= "\$Quotes_SalesOrder_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($qt_so_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($qt_so_share_read_per['GROUP']).");\n\n"; 328 $newbuf .= "\$Quotes_SalesOrder_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($qt_so_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($qt_so_share_write_per['GROUP']).");\n\n"; 329 330 331 332 333 //Constructing Orders Sharing Rules 334 $po_share_per_array=getUserModuleSharingObjects("PurchaseOrder",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups); 335 $po_share_read_per=$po_share_per_array['read']; 336 $po_share_write_per=$po_share_per_array['write']; 337 $newbuf .= "\$PurchaseOrder_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($po_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($po_share_read_per['GROUP']).");\n\n"; 338 $newbuf .= "\$PurchaseOrder_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($po_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($po_share_write_per['GROUP']).");\n\n"; 339 340 //Constructing Sales Order Sharing Rules 341 $so_share_per_array=getUserModuleSharingObjects("SalesOrder",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups); 342 $so_share_read_per=$so_share_per_array['read']; 343 $so_share_write_per=$so_share_per_array['write']; 344 $so_sharingrule_members=$so_share_per_array['sharingrules']; 345 $newbuf .= "\$SalesOrder_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($so_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($so_share_read_per['GROUP']).");\n\n"; 346 $newbuf .= "\$SalesOrder_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($so_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($so_share_write_per['GROUP']).");\n\n"; 347 348 //Constructing the SalesOrder Invoice Related Module Sharing Array 349 $so_related_inv=getRelatedModuleSharingArray("SalesOrder","Invoice",$so_sharingrule_members,$so_share_read_per,$so_share_write_per,$def_org_share); 350 351 $so_inv_share_read_per=$so_related_inv['read']; 352 $so_inv_share_write_per=$so_related_inv['write']; 353 354 $newbuf .= "\$SalesOrder_Invoice_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($so_inv_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($so_inv_share_read_per['GROUP']).");\n\n"; 355 $newbuf .= "\$SalesOrder_Invoice_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($so_inv_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($so_inv_share_write_per['GROUP']).");\n\n"; 356 357 358 359 //Constructing Invoice Sharing Rules 360 $inv_share_per_array=getUserModuleSharingObjects("Invoice",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups); 361 $inv_share_read_per=$inv_share_per_array['read']; 362 $inv_share_write_per=$inv_share_per_array['write']; 363 $newbuf .= "\$Invoice_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($inv_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($inv_share_read_per['GROUP']).");\n\n"; 364 $newbuf .= "\$Invoice_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($inv_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($inv_share_write_per['GROUP']).");\n\n"; 365 366 // Writing Sharing Rules For Custom Modules. 367 // TODO: We are ignoring rules that has already been calculated above, it is good to add GENERIC logic here. 368 $custom_modules = getSharingModuleList( 369 Array('Leads', 'Accounts', 'Contacts', 'Potentials', 'HelpDesk', 370 'Emails', 'Campaigns','Quotes', 'PurchaseOrder', 'SalesOrder', 'Invoice')); 371 372 for($idx = 0; $idx < count($custom_modules); ++$idx) { 373 $module_name = $custom_modules[$idx]; 374 $mod_share_perm_array = getUserModuleSharingObjects($module_name,$userid, 375 $def_org_share,$current_user_roles,$parent_roles,$current_user_groups); 376 377 $mod_share_read_perm = $mod_share_perm_array['read']; 378 $mod_share_write_perm= $mod_share_perm_array['write']; 379 $newbuf .= '$'.$module_name."_share_read_permission=array('ROLE'=>". 380 constructTwoDimensionalCharIntSingleValueArray($mod_share_read_perm['ROLE']).",'GROUP'=>". 381 constructTwoDimensionalArray($mod_share_read_perm['GROUP']).");\n\n"; 382 $newbuf .= '$'.$module_name."_share_write_permission=array('ROLE'=>". 383 constructTwoDimensionalCharIntSingleValueArray($mod_share_write_perm['ROLE']).",'GROUP'=>". 384 constructTwoDimensionalArray($mod_share_write_perm['GROUP']).");\n\n"; 385 } 386 // END 387 388 $newbuf .= "?>"; 389 fputs($handle, $newbuf); 390 fclose($handle); 391 392 //Populating Temp Tables 393 populateSharingtmptables($userid); 394 } 395 } 396 } 397 398 /** Gives an array which contains the information for what all roles, groups and user data is to be shared with the spcified user for the specified module 399 400 * @param $module -- module name:: Type varchar 401 * @param $userid -- user id:: Type integer 402 * @param $def_org_share -- default organization sharing permission array:: Type array 403 * @param $current_user_roles -- roleid:: Type varchar 404 * @param $parent_roles -- parent roles:: Type varchar 405 * @param $current_user_groups -- user id:: Type integer 406 * @returns $mod_share_permission -- array which contains the id of roles,group and users data shared with specifed user for the specified module 407 */ 408 function getUserModuleSharingObjects($module,$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups) 409 { 410 global $adb; 411 412 $mod_tabid=getTabid($module); 413 414 $mod_share_permission; 415 $mod_share_read_permission=Array(); 416 $mod_share_write_permission=Array(); 417 $mod_share_read_permission['ROLE']=Array(); 418 $mod_share_write_permission['ROLE']=Array(); 419 $mod_share_read_permission['GROUP']=Array(); 420 $mod_share_write_permission['GROUP']=Array(); 421 422 $share_id_members=Array(); 423 $share_id_groupmembers=Array(); 424 //If Sharing of leads is Private 425 if($def_org_share[$mod_tabid] == 3 || $def_org_share[$mod_tabid] == 0) 426 { 427 $role_read_per=Array(); 428 $role_write_per=Array(); 429 $rs_read_per=Array(); 430 $rs_write_per=Array(); 431 $grp_read_per=Array(); 432 $grp_write_per=Array(); 433 //Retreiving from vtiger_role to vtiger_role 434 $query="select vtiger_datashare_role2role.* from vtiger_datashare_role2role inner join vtiger_datashare_module_rel on vtiger_datashare_module_rel.shareid=vtiger_datashare_role2role.shareid where vtiger_datashare_module_rel.tabid=? and vtiger_datashare_role2role.to_roleid=?"; 435 $result=$adb->pquery($query, array($mod_tabid, $current_user_roles)); 436 $num_rows=$adb->num_rows($result); 437 for($i=0;$i<$num_rows;$i++) 438 { 439 $share_roleid=$adb->query_result($result,$i,'share_roleid'); 440 441 $shareid=$adb->query_result($result,$i,'shareid'); 442 $share_id_role_members=Array(); 443 $share_id_roles=Array(); 444 $share_id_roles[]=$share_roleid; 445 $share_id_role_members['ROLE']=$share_id_roles; 446 $share_id_members[$shareid]=$share_id_role_members; 447 448 $share_permission=$adb->query_result($result,$i,'permission'); 449 if($share_permission == 1) 450 { 451 if($def_org_share[$mod_tabid] == 3) 452 { 453 if(! array_key_exists($share_roleid,$role_read_per)) 454 { 455 456 $share_role_users=getRoleUserIds($share_roleid); 457 $role_read_per[$share_roleid]=$share_role_users; 458 } 459 } 460 if(! array_key_exists($share_roleid,$role_write_per)) 461 { 462 463 $share_role_users=getRoleUserIds($share_roleid); 464 $role_write_per[$share_roleid]=$share_role_users; 465 } 466 } 467 elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3) 468 { 469 if(! array_key_exists($share_roleid,$role_read_per)) 470 { 471 472 $share_role_users=getRoleUserIds($share_roleid); 473 $role_read_per[$share_roleid]=$share_role_users; 474 } 475 476 } 477 478 } 479 480 481 482 //Retreiving from role to rs 483 $parRoleList = array(); 484 foreach($parent_roles as $par_role_id) 485 { 486 array_push($parRoleList, $par_role_id); 487 } 488 array_push($parRoleList, $current_user_roles); 489 $query="select vtiger_datashare_role2rs.* from vtiger_datashare_role2rs inner join vtiger_datashare_module_rel on vtiger_datashare_module_rel.shareid=vtiger_datashare_role2rs.shareid where vtiger_datashare_module_rel.tabid=? and vtiger_datashare_role2rs.to_roleandsubid in (". generateQuestionMarks($parRoleList) .")"; 490 $result=$adb->pquery($query, array($mod_tabid, $parRoleList)); 491 $num_rows=$adb->num_rows($result); 492 for($i=0;$i<$num_rows;$i++) 493 { 494 $share_roleid=$adb->query_result($result,$i,'share_roleid'); 495 496 $shareid=$adb->query_result($result,$i,'shareid'); 497 $share_id_role_members=Array(); 498 $share_id_roles=Array(); 499 $share_id_roles[]=$share_roleid; 500 $share_id_role_members['ROLE']=$share_id_roles; 501 $share_id_members[$shareid]=$share_id_role_members; 502 503 $share_permission=$adb->query_result($result,$i,'permission'); 504 if($share_permission == 1) 505 { 506 if($def_org_share[$mod_tabid] == 3) 507 { 508 if(! array_key_exists($share_roleid,$role_read_per)) 509 { 510 511 $share_role_users=getRoleUserIds($share_roleid); 512 $role_read_per[$share_roleid]=$share_role_users; 513 } 514 } 515 if(! array_key_exists($share_roleid,$role_write_per)) 516 { 517 518 $share_role_users=getRoleUserIds($share_roleid); 519 $role_write_per[$share_roleid]=$share_role_users; 520 } 521 } 522 elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3) 523 { 524 if(! array_key_exists($share_roleid,$role_read_per)) 525 { 526 527 $share_role_users=getRoleUserIds($share_roleid); 528 $role_read_per[$share_roleid]=$share_role_users; 529 } 530 531 } 532 533 } 534 535 //Get roles from Role2Grp 536 $grpIterator=false; 537 $groupList = $current_user_groups; 538 if (empty($groupList)) $groupList = array(0); 539 540 if (!empty($groupList)) { 541 $query="select vtiger_datashare_role2group.* from vtiger_datashare_role2group inner join vtiger_datashare_module_rel on vtiger_datashare_module_rel.shareid=vtiger_datashare_role2group.shareid where vtiger_datashare_module_rel.tabid=?"; 542 $qparams = array($mod_tabid); 543 544 if (count($groupList) > 0) { 545 $query .= " and vtiger_datashare_role2group.to_groupid in (". generateQuestionMarks($groupList) .")"; 546 array_push($qparams, $groupList); 547 } 548 $result=$adb->pquery($query, $qparams); 549 $num_rows=$adb->num_rows($result); 550 for($i=0;$i<$num_rows;$i++) 551 { 552 $share_roleid=$adb->query_result($result,$i,'share_roleid'); 553 $shareid=$adb->query_result($result,$i,'shareid'); 554 $share_id_role_members=Array(); 555 $share_id_roles=Array(); 556 $share_id_roles[]=$share_roleid; 557 $share_id_role_members['ROLE']=$share_id_roles; 558 $share_id_members[$shareid]=$share_id_role_members; 559 560 $share_permission=$adb->query_result($result,$i,'permission'); 561 if($share_permission == 1) 562 { 563 if($def_org_share[$mod_tabid] == 3) 564 { 565 if(! array_key_exists($share_roleid,$role_read_per)) 566 { 567 568 $share_role_users=getRoleUserIds($share_roleid); 569 $role_read_per[$share_roleid]=$share_role_users; 570 } 571 } 572 if(! array_key_exists($share_roleid,$role_write_per)) 573 { 574 575 $share_role_users=getRoleUserIds($share_roleid); 576 $role_write_per[$share_roleid]=$share_role_users; 577 } 578 } 579 elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3) 580 { 581 if(! array_key_exists($share_roleid,$role_read_per)) 582 { 583 584 $share_role_users=getRoleUserIds($share_roleid); 585 $role_read_per[$share_roleid]=$share_role_users; 586 } 587 588 } 589 590 } 591 } 592 593 594 //Retreiving from rs to vtiger_role 595 $query="select vtiger_datashare_rs2role.* from vtiger_datashare_rs2role inner join vtiger_datashare_module_rel on vtiger_datashare_module_rel.shareid=vtiger_datashare_rs2role.shareid where vtiger_datashare_module_rel.tabid=? and vtiger_datashare_rs2role.to_roleid=?"; 596 $result=$adb->pquery($query, array($mod_tabid, $current_user_roles)); 597 $num_rows=$adb->num_rows($result); 598 for($i=0;$i<$num_rows;$i++) 599 { 600 $share_rsid=$adb->query_result($result,$i,'share_roleandsubid'); 601 $share_roleids=getRoleAndSubordinatesRoleIds($share_rsid); 602 $share_permission=$adb->query_result($result,$i,'permission'); 603 604 $shareid=$adb->query_result($result,$i,'shareid'); 605 $share_id_role_members=Array(); 606 $share_id_roles=Array(); 607 foreach($share_roleids as $share_roleid) 608 { 609 $share_id_roles[]=$share_roleid; 610 611 612 if($share_permission == 1) 613 { 614 if($def_org_share[$mod_tabid] == 3) 615 { 616 if(! array_key_exists($share_roleid,$role_read_per)) 617 { 618 619 $share_role_users=getRoleUserIds($share_roleid); 620 $role_read_per[$share_roleid]=$share_role_users; 621 } 622 } 623 if(! array_key_exists($share_roleid,$role_write_per)) 624 { 625 626 $share_role_users=getRoleUserIds($share_roleid); 627 $role_write_per[$share_roleid]=$share_role_users; 628 } 629 } 630 elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3) 631 { 632 if(! array_key_exists($share_roleid,$role_read_per)) 633 { 634 635 $share_role_users=getRoleUserIds($share_roleid); 636 $role_read_per[$share_roleid]=$share_role_users; 637 } 638 639 } 640 } 641 $share_id_role_members['ROLE']=$share_id_roles; 642 $share_id_members[$shareid]=$share_id_role_members; 643 644 } 645 646 647 //Retreiving from rs to rs 648 $parRoleList = array(); 649 foreach($parent_roles as $par_role_id) 650 { 651 array_push($parRoleList, $par_role_id); 652 } 653 array_push($parRoleList, $current_user_roles); 654 $query="select vtiger_datashare_rs2rs.* from vtiger_datashare_rs2rs inner join vtiger_datashare_module_rel on vtiger_datashare_module_rel.shareid=vtiger_datashare_rs2rs.shareid where vtiger_datashare_module_rel.tabid=? and vtiger_datashare_rs2rs.to_roleandsubid in (". generateQuestionMarks($parRoleList) .")"; 655 $result=$adb->pquery($query, array($mod_tabid, $parRoleList)); 656 $num_rows=$adb->num_rows($result); 657 for($i=0;$i<$num_rows;$i++) 658 { 659 $share_rsid=$adb->query_result($result,$i,'share_roleandsubid'); 660 $share_roleids=getRoleAndSubordinatesRoleIds($share_rsid); 661 $share_permission=$adb->query_result($result,$i,'permission'); 662 663 $shareid=$adb->query_result($result,$i,'shareid'); 664 $share_id_role_members=Array(); 665 $share_id_roles=Array(); 666 foreach($share_roleids as $share_roleid) 667 { 668 669 $share_id_roles[]=$share_roleid; 670 671 if($share_permission == 1) 672 { 673 if($def_org_share[$mod_tabid] == 3) 674 { 675 if(! array_key_exists($share_roleid,$role_read_per)) 676 { 677 678 $share_role_users=getRoleUserIds($share_roleid); 679 $role_read_per[$share_roleid]=$share_role_users; 680 } 681 } 682 if(! array_key_exists($share_roleid,$role_write_per)) 683 { 684 685 $share_role_users=getRoleUserIds($share_roleid); 686 $role_write_per[$share_roleid]=$share_role_users; 687 } 688 } 689 elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3) 690 { 691 if(! array_key_exists($share_roleid,$role_read_per)) 692 { 693 694 $share_role_users=getRoleUserIds($share_roleid); 695 $role_read_per[$share_roleid]=$share_role_users; 696 } 697 698 } 699 } 700 $share_id_role_members['ROLE']=$share_id_roles; 701 $share_id_members[$shareid]=$share_id_role_members; 702 703 } 704 705 //Get roles from Rs2Grp 706 707 $query="select vtiger_datashare_rs2grp.* from vtiger_datashare_rs2grp inner join vtiger_datashare_module_rel on vtiger_datashare_module_rel.shareid=vtiger_datashare_rs2grp.shareid where vtiger_datashare_module_rel.tabid=?"; 708 $qparams = array($mod_tabid); 709 if (count($groupList) > 0) { 710 $query .= " and vtiger_datashare_rs2grp.to_groupid in (". generateQuestionMarks($groupList) .")"; 711 array_push($qparams, $groupList); 712 } 713 $result=$adb->pquery($query, $qparams); 714 $num_rows=$adb->num_rows($result); 715 for($i=0;$i<$num_rows;$i++) 716 { 717 $share_rsid=$adb->query_result($result,$i,'share_roleandsubid'); 718 $share_roleids=getRoleAndSubordinatesRoleIds($share_rsid); 719 $share_permission=$adb->query_result($result,$i,'permission'); 720 721 $shareid=$adb->query_result($result,$i,'shareid'); 722 $share_id_role_members=Array(); 723 $share_id_roles=Array(); 724 725 foreach($share_roleids as $share_roleid) 726 { 727 728 $share_id_roles[]=$share_roleid; 729 730 if($share_permission == 1) 731 { 732 if($def_org_share[$mod_tabid] == 3) 733 { 734 if(! array_key_exists($share_roleid,$role_read_per)) 735 { 736 737 $share_role_users=getRoleUserIds($share_roleid); 738 $role_read_per[$share_roleid]=$share_role_users; 739 } 740 } 741 if(! array_key_exists($share_roleid,$role_write_per)) 742 { 743 744 $share_role_users=getRoleUserIds($share_roleid); 745 $role_write_per[$share_roleid]=$share_role_users; 746 } 747 } 748 elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3) 749 { 750 if(! array_key_exists($share_roleid,$role_read_per)) 751 { 752 753 $share_role_users=getRoleUserIds($share_roleid); 754 $role_read_per[$share_roleid]=$share_role_users; 755 } 756 757 } 758 } 759 $share_id_role_members['ROLE']=$share_id_roles; 760 $share_id_members[$shareid]=$share_id_role_members; 761 762 763 764 } 765 $mod_share_read_permission['ROLE']=$role_read_per; 766 $mod_share_write_permission['ROLE']=$role_write_per; 767 768 //Retreiving from the grp2role sharing 769 $query="select vtiger_datashare_grp2role.* from vtiger_datashare_grp2role inner join vtiger_datashare_module_rel on vtiger_datashare_module_rel.shareid=vtiger_datashare_grp2role.shareid where vtiger_datashare_module_rel.tabid=? and vtiger_datashare_grp2role.to_roleid=?"; 770 $result=$adb->pquery($query, array($mod_tabid, $current_user_roles)); 771 $num_rows=$adb->num_rows($result); 772 for($i=0;$i<$num_rows;$i++) 773 { 774 $share_grpid=$adb->query_result($result,$i,'share_groupid'); 775 $share_permission=$adb->query_result($result,$i,'permission'); 776 777 $shareid=$adb->query_result($result,$i,'shareid'); 778 $share_id_grp_members=Array(); 779 $share_id_grps=Array(); 780 $share_id_grps[]=$share_grpid; 781 782 783 if($share_permission == 1) 784 { 785 if($def_org_share[$mod_tabid] == 3) 786 { 787 if(! array_key_exists($share_grpid,$grp_read_per)) 788 { 789 $focusGrpUsers = new GetGroupUsers(); 790 $focusGrpUsers->getAllUsersInGroup($share_grpid); 791 $share_grp_users=$focusGrpUsers->group_users; 792 $share_grp_subgroups=$focusGrpUsers->group_subgroups; 793 $grp_read_per[$share_grpid]=$share_grp_users; 794 foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers) 795 { 796 if(! array_key_exists($subgrpid,$grp_read_per)) 797 { 798 $grp_read_per[$subgrpid]=$subgrpusers; 799 } 800 if(! in_array($subgrpid,$share_id_grps)) 801 { 802 $share_id_grps[]=$subgrpid; 803 } 804 805 } 806 } 807 } 808 if(! array_key_exists($share_grpid,$grp_write_per)) 809 { 810 $focusGrpUsers = new GetGroupUsers(); 811 $focusGrpUsers->getAllUsersInGroup($share_grpid); 812 $share_grp_users=$focusGrpUsers->group_users; 813 $grp_write_per[$share_grpid]=$share_grp_users; 814 foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers) 815 { 816 if(! array_key_exists($subgrpid,$grp_write_per)) 817 { 818 $grp_write_per[$subgrpid]=$subgrpusers; 819 } 820 if(! in_array($subgrpid,$share_id_grps)) 821 { 822 $share_id_grps[]=$subgrpid; 823 } 824 825 } 826 827 } 828 } 829 elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3) 830 { 831 if(! array_key_exists($share_grpid,$grp_read_per)) 832 { 833 $focusGrpUsers = new GetGroupUsers(); 834 $focusGrpUsers->getAllUsersInGroup($share_grpid); 835 $share_grp_users=$focusGrpUsers->group_users; 836 $grp_read_per[$share_grpid]=$share_grp_users; 837 foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers) 838 { 839 if(! array_key_exists($subgrpid,$grp_read_per)) 840 { 841 $grp_read_per[$subgrpid]=$subgrpusers; 842 } 843 if(! in_array($subgrpid,$share_id_grps)) 844 { 845 $share_id_grps[]=$subgrpid; 846 } 847 848 } 849 } 850 851 } 852 $share_id_grp_members['GROUP']=$share_id_grps; 853 $share_id_members[$shareid]=$share_id_grp_members; 854 855 } 856 857 //Retreiving from the grp2rs sharing 858 859 $query="select vtiger_datashare_grp2rs.* from vtiger_datashare_grp2rs inner join vtiger_datashare_module_rel on vtiger_datashare_module_rel.shareid=vtiger_datashare_grp2rs.shareid where vtiger_datashare_module_rel.tabid=? and vtiger_datashare_grp2rs.to_roleandsubid in (". generateQuestionMarks($parRoleList) .")"; 860 $result=$adb->pquery($query, array($mod_tabid, $parRoleList)); 861 $num_rows=$adb->num_rows($result); 862 for($i=0;$i<$num_rows;$i++) 863 { 864 $share_grpid=$adb->query_result($result,$i,'share_groupid'); 865 $share_permission=$adb->query_result($result,$i,'permission'); 866 867 $shareid=$adb->query_result($result,$i,'shareid'); 868 $share_id_grp_members=Array(); 869 $share_id_grps=Array(); 870 $share_id_grps[]=$share_grpid; 871 872 873 if($share_permission == 1) 874 { 875 if($def_org_share[$mod_tabid] == 3) 876 { 877 if(! array_key_exists($share_grpid,$grp_read_per)) 878 { 879 $focusGrpUsers = new GetGroupUsers(); 880 $focusGrpUsers->getAllUsersInGroup($share_grpid); 881 $share_grp_users=$focusGrpUsers->group_users; 882 $grp_read_per[$share_grpid]=$share_grp_users; 883 884 foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers) 885 { 886 if(! array_key_exists($subgrpid,$grp_read_per)) 887 { 888 $grp_read_per[$subgrpid]=$subgrpusers; 889 } 890 if(! in_array($subgrpid,$share_id_grps)) 891 { 892 $share_id_grps[]=$subgrpid; 893 } 894 895 } 896 } 897 } 898 if(! array_key_exists($share_grpid,$grp_write_per)) 899 { 900 $focusGrpUsers = new GetGroupUsers(); 901 $focusGrpUsers->getAllUsersInGroup($share_grpid); 902 $share_grp_users=$focusGrpUsers->group_users; 903 $grp_write_per[$share_grpid]=$share_grp_users; 904 foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers) 905 { 906 if(! array_key_exists($subgrpid,$grp_write_per)) 907 { 908 $grp_write_per[$subgrpid]=$subgrpusers; 909 } 910 if(! in_array($subgrpid,$share_id_grps)) 911 { 912 $share_id_grps[]=$subgrpid; 913 } 914 915 } 916 917 } 918 } 919 elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3) 920 { 921 if(! array_key_exists($share_grpid,$grp_read_per)) 922 { 923 $focusGrpUsers = new GetGroupUsers(); 924 $focusGrpUsers->getAllUsersInGroup($share_grpid); 925 $share_grp_users=$focusGrpUsers->group_users; 926 $grp_read_per[$share_grpid]=$share_grp_users; 927 foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers) 928 { 929 if(! array_key_exists($subgrpid,$grp_read_per)) 930 { 931 $grp_read_per[$subgrpid]=$subgrpusers; 932 } 933 if(! in_array($subgrpid,$share_id_grps)) 934 { 935 $share_id_grps[]=$subgrpid; 936 } 937 938 } 939 } 940 941 } 942 $share_id_grp_members['GROUP']=$share_id_grps; 943 $share_id_members[$shareid]=$share_id_grp_members; 944 945 } 946 947 //Retreiving from the grp2grp sharing 948 949 $query="select vtiger_datashare_grp2grp.* from vtiger_datashare_grp2grp inner join vtiger_datashare_module_rel on vtiger_datashare_module_rel.shareid=vtiger_datashare_grp2grp.shareid where vtiger_datashare_module_rel.tabid=?"; 950 $qparams = array($mod_tabid); 951 if (count($groupList) > 0) { 952 $query .= " and vtiger_datashare_grp2grp.to_groupid in (". generateQuestionMarks($groupList) .")"; 953 array_push($qparams, $groupList); 954 } 955 $result=$adb->pquery($query, $qparams); 956 $num_rows=$adb->num_rows($result); 957 for($i=0;$i<$num_rows;$i++) 958 { 959 $share_grpid=$adb->query_result($result,$i,'share_groupid'); 960 $share_permission=$adb->query_result($result,$i,'permission'); 961 962 $shareid=$adb->query_result($result,$i,'shareid'); 963 $share_id_grp_members=Array(); 964 $share_id_grps=Array(); 965 $share_id_grps[]=$share_grpid; 966 967 if($share_permission == 1) 968 { 969 if($def_org_share[$mod_tabid] == 3) 970 { 971 if(! array_key_exists($share_grpid,$grp_read_per)) 972 { 973 $focusGrpUsers = new GetGroupUsers(); 974 $focusGrpUsers->getAllUsersInGroup($share_grpid); 975 $share_grp_users=$focusGrpUsers->group_users; 976 $grp_read_per[$share_grpid]=$share_grp_users; 977 foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers) 978 { 979 if(! array_key_exists($subgrpid,$grp_read_per)) 980 { 981 $grp_read_per[$subgrpid]=$subgrpusers; 982 } 983 if(! in_array($subgrpid,$share_id_grps)) 984 { 985 $share_id_grps[]=$subgrpid; 986 } 987 988 989 } 990 } 991 } 992 if(! array_key_exists($share_grpid,$grp_write_per)) 993 { 994 $focusGrpUsers = new GetGroupUsers(); 995 $focusGrpUsers->getAllUsersInGroup($share_grpid); 996 $share_grp_users=$focusGrpUsers->group_users; 997 $grp_write_per[$share_grpid]=$share_grp_users; 998 foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers) 999 { 1000 if(! array_key_exists($subgrpid,$grp_write_per)) 1001 { 1002 $grp_write_per[$subgrpid]=$subgrpusers; 1003 } 1004 if(! in_array($subgrpid,$share_id_grps)) 1005 { 1006 $share_id_grps[]=$subgrpid; 1007 } 1008 1009 } 1010 1011 } 1012 } 1013 elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3) 1014 { 1015 if(! array_key_exists($share_grpid,$grp_read_per)) 1016 { 1017 $focusGrpUsers = new GetGroupUsers(); 1018 $focusGrpUsers->getAllUsersInGroup($share_grpid); 1019 $share_grp_users=$focusGrpUsers->group_users; 1020 $grp_read_per[$share_grpid]=$share_grp_users; 1021 foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers) 1022 { 1023 if(! array_key_exists($subgrpid,$grp_read_per)) 1024 { 1025 $grp_read_per[$subgrpid]=$subgrpusers; 1026 } 1027 if(! in_array($subgrpid,$share_id_grps)) 1028 { 1029 $share_id_grps[]=$subgrpid; 1030 } 1031 1032 } 1033 } 1034 1035 } 1036 $share_id_grp_members['GROUP']=$share_id_grps; 1037 $share_id_members[$shareid]=$share_id_grp_members; 1038 1039 } 1040 $mod_share_read_permission['GROUP']=$grp_read_per; 1041 $mod_share_write_permission['GROUP']=$grp_write_per; 1042 } 1043 $mod_share_permission['read']=$mod_share_read_permission; 1044 $mod_share_permission['write']=$mod_share_write_permission; 1045 $mod_share_permission['sharingrules']=$share_id_members; 1046 return $mod_share_permission; 1047 } 1048 1049 /** Gives an array which contains the information for what all roles, groups and user's related module data that is to be shared for the specified parent module and shared module 1050 1051 * @param $par_mod -- parent module name:: Type varchar 1052 * @param $share_mod -- shared module name:: Type varchar 1053 * @param $userid -- user id:: Type integer 1054 * @param $def_org_share -- default organization sharing permission array:: Type array 1055 * @param $mod_sharingrule_members -- Sharing Rule Members array:: Type array 1056 * @param $$mod_share_read_per -- Sharing Module Read Permission array:: Type array 1057 * @param $$mod_share_write_per -- Sharing Module Write Permission array:: Type array 1058 * @returns $related_mod_sharing_permission; -- array which contains the id of roles,group and users related module data to be shared 1059 */ 1060 function getRelatedModuleSharingArray($par_mod,$share_mod,$mod_sharingrule_members,$mod_share_read_per,$mod_share_write_per,$def_org_share) 1061 { 1062 1063 global $adb; 1064 $related_mod_sharing_permission=Array(); 1065 $mod_share_read_permission=Array(); 1066 $mod_share_write_permission=Array(); 1067 1068 $mod_share_read_permission['ROLE']=Array(); 1069 $mod_share_write_permission['ROLE']=Array(); 1070 $mod_share_read_permission['GROUP']=Array(); 1071 $mod_share_write_permission['GROUP']=Array(); 1072 1073 $par_mod_id=getTabid($par_mod); 1074 $share_mod_id=getTabid($share_mod); 1075 1076 if($def_org_share[$share_mod_id] == 3 || $def_org_share[$share_mod_id] == 0) 1077 { 1078 1079 $role_read_per=Array(); 1080 $role_write_per=Array(); 1081 $grp_read_per=Array(); 1082 $grp_write_per=Array(); 1083 1084 1085 1086 foreach($mod_sharingrule_members as $sharingid => $sharingInfoArr) 1087 { 1088 $query = "select vtiger_datashare_relatedmodule_permission.* from vtiger_datashare_relatedmodule_permission inner join vtiger_datashare_relatedmodules on vtiger_datashare_relatedmodules.datashare_relatedmodule_id=vtiger_datashare_relatedmodule_permission.datashare_relatedmodule_id where vtiger_datashare_relatedmodule_permission.shareid=? and vtiger_datashare_relatedmodules.tabid=? and vtiger_datashare_relatedmodules.relatedto_tabid=?"; 1089 $result=$adb->pquery($query, array($sharingid, $par_mod_id, $share_mod_id)); 1090 $share_permission=$adb->query_result($result,0,'permission'); 1091 1092 foreach($sharingInfoArr as $shareType => $shareEntArr) 1093 { 1094 foreach($shareEntArr as $key=>$shareEntId) 1095 { 1096 if($shareType == 'ROLE') 1097 { 1098 if($share_permission == 1) 1099 { 1100 if($def_org_share[$share_mod_id] == 3) 1101 { 1102 if(! array_key_exists($shareEntId,$role_read_per)) 1103 { 1104 if(array_key_exists($shareEntId,$mod_share_read_per['ROLE'])) 1105 { 1106 $share_role_users=$mod_share_read_per['ROLE'][$shareEntId]; 1107 } 1108 elseif(array_key_exists($shareEntId,$mod_share_write_per['ROLE'])) 1109 { 1110 $share_role_users=$mod_share_write_per['ROLE'][$shareEntId]; 1111 } 1112 else 1113 { 1114 1115 $share_role_users=getRoleUserIds($shareEntId); 1116 } 1117 1118 $role_read_per[$shareEntId]=$share_role_users; 1119 1120 } 1121 } 1122 if(! array_key_exists($shareEntId,$role_write_per)) 1123 { 1124 if(array_key_exists($shareEntId,$mod_share_read_per['ROLE'])) 1125 { 1126 $share_role_users=$mod_share_read_per['ROLE'][$shareEntId]; 1127 } 1128 elseif(array_key_exists($shareEntId,$mod_share_write_per['ROLE'])) 1129 { 1130 $share_role_users=$mod_share_write_per['ROLE'][$shareEntId]; 1131 } 1132 else 1133 { 1134 1135 $share_role_users=getRoleUserIds($shareEntId); 1136 1137 } 1138 1139 $role_write_per[$shareEntId]=$share_role_users; 1140 } 1141 } 1142 elseif($share_permission == 0 && $def_org_share[$share_mod_id] == 3) 1143 { 1144 if(! array_key_exists($shareEntId,$role_read_per)) 1145 { 1146 if(array_key_exists($shareEntId,$mod_share_read_per['ROLE'])) 1147 { 1148 $share_role_users=$mod_share_read_per['ROLE'][$shareEntId]; 1149 } 1150 elseif(array_key_exists($shareEntId,$mod_share_write_per['ROLE'])) 1151 { 1152 $share_role_users=$mod_share_write_per['ROLE'][$shareEntId]; 1153 } 1154 else 1155 { 1156 1157 $share_role_users=getRoleUserIds($shareEntId); 1158 } 1159 1160 $role_read_per[$shareEntId]=$share_role_users; 1161 1162 } 1163 1164 1165 } 1166 1167 } 1168 elseif($shareType == 'GROUP') 1169 { 1170 if($share_permission == 1) 1171 { 1172 if($def_org_share[$share_mod_id] == 3) 1173 { 1174 1175 if(! array_key_exists($shareEntId,$grp_read_per)) 1176 { 1177 if(array_key_exists($shareEntId,$mod_share_read_per['GROUP'])) 1178 { 1179 $share_grp_users=$mod_share_read_per['GROUP'][$shareEntId]; 1180 } 1181 elseif(array_key_exists($shareEntId,$mod_share_write_per['GROUP'])) 1182 { 1183 $share_grp_users=$mod_share_write_per['GROUP'][$shareEntId]; 1184 } 1185 else 1186 { 1187 $focusGrpUsers = new GetGroupUsers(); 1188 $focusGrpUsers->getAllUsersInGroup($shareEntId); 1189 $share_grp_users=$focusGrpUsers->group_users; 1190 1191 foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers) 1192 { 1193 if(! array_key_exists($subgrpid,$grp_read_per)) 1194 { 1195 $grp_read_per[$subgrpid]=$subgrpusers; 1196 } 1197 1198 } 1199 1200 } 1201 1202 $grp_read_per[$shareEntId]=$share_grp_users; 1203 1204 } 1205 } 1206 if(! array_key_exists($shareEntId,$grp_write_per)) 1207 { 1208 if(! array_key_exists($shareEntId,$grp_write_per)) 1209 { 1210 if(array_key_exists($shareEntId,$mod_share_read_per['GROUP'])) 1211 { 1212 $share_grp_users=$mod_share_read_per['GROUP'][$shareEntId]; 1213 } 1214 elseif(array_key_exists($shareEntId,$mod_share_write_per['GROUP'])) 1215 { 1216 $share_grp_users=$mod_share_write_per['GROUP'][$shareEntId]; 1217 } 1218 else 1219 { 1220 $focusGrpUsers = new GetGroupUsers(); 1221 $focusGrpUsers->getAllUsersInGroup($shareEntId); 1222 $share_grp_users=$focusGrpUsers->group_users; 1223 foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers) 1224 { 1225 if(! array_key_exists($subgrpid,$grp_write_per)) 1226 { 1227 $grp_write_per[$subgrpid]=$subgrpusers; 1228 } 1229 1230 } 1231 1232 } 1233 1234 $grp_write_per[$shareEntId]=$share_grp_users; 1235 1236 } 1237 } 1238 } 1239 elseif($share_permission == 0 && $def_org_share[$share_mod_id] == 3) 1240 { 1241 if(! array_key_exists($shareEntId,$grp_read_per)) 1242 { 1243 if(array_key_exists($shareEntId,$mod_share_read_per['GROUP'])) 1244 { 1245 $share_grp_users=$mod_share_read_per['GROUP'][$shareEntId]; 1246 } 1247 elseif(array_key_exists($shareEntId,$mod_share_write_per['GROUP'])) 1248 { 1249 $share_grp_users=$mod_share_write_per['GROUP'][$shareEntId]; 1250 } 1251 else 1252 { 1253 $focusGrpUsers = new GetGroupUsers(); 1254 $focusGrpUsers->getAllUsersInGroup($shareEntId); 1255 $share_grp_users=$focusGrpUsers->group_users; 1256 foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers) 1257 { 1258 if(! array_key_exists($subgrpid,$grp_read_per)) 1259 { 1260 $grp_read_per[$subgrpid]=$subgrpusers; 1261 } 1262 1263 } 1264 1265 } 1266 1267 $grp_read_per[$shareEntId]=$share_grp_users; 1268 1269 } 1270 1271 1272 } 1273 } 1274 } 1275 } 1276 } 1277 $mod_share_read_permission['ROLE']=$role_read_per; 1278 $mod_share_write_permission['ROLE']=$role_write_per; 1279 $mod_share_read_permission['GROUP']=$grp_read_per; 1280 $mod_share_write_permission['GROUP']=$grp_write_per; 1281 } 1282 1283 $related_mod_sharing_permission['read']=$mod_share_read_permission; 1284 $related_mod_sharing_permission['write']=$mod_share_write_permission; 1285 return $related_mod_sharing_permission; 1286 1287 1288 } 1289 1290 1291 /** Converts the input array to a single string to facilitate the writing of the input array in a flat file 1292 1293 * @param $var -- input array:: Type array 1294 * @returns $code -- contains the whole array in a single string:: Type array 1295 */ 1296 function constructArray($var) 1297 { 1298 if (is_array($var)) 1299 { 1300 $code = 'array('; 1301 foreach ($var as $key => $value) 1302 { 1303 $code .= "'".$key."'=>".$value.','; 1304 } 1305 $code .= ')'; 1306 return $code; 1307 } 1308 } 1309 1310 /** Converts the input array to a single string to facilitate the writing of the input array in a flat file 1311 1312 * @param $var -- input array:: Type array 1313 * @returns $code -- contains the whole array in a single string:: Type array 1314 */ 1315 function constructSingleStringValueArray($var) 1316 { 1317 1318 $size = sizeof($var); 1319 $i=1; 1320 if (is_array($var)) 1321 { 1322 $code = 'array('; 1323 foreach ($var as $key => $value) 1324 { 1325 if($i<$size) 1326 { 1327 $code .= $key."=>'".$value."',"; 1328 } 1329 else 1330 { 1331 $code .= $key."=>'".$value."'"; 1332 } 1333 $i++; 1334 } 1335 $code .= ')'; 1336 return $code; 1337 } 1338 } 1339 1340 /** Converts the input array to a single string to facilitate the writing of the input array in a flat file 1341 1342 * @param $var -- input array:: Type array 1343 * @returns $code -- contains the whole array in a single string:: Type array 1344 */ 1345 function constructSingleStringKeyAndValueArray($var) 1346 { 1347 1348 $size = sizeof($var); 1349 $i=1; 1350 if (is_array($var)) 1351 { 1352 $code = 'array('; 1353 foreach ($var as $key => $value) 1354 { 1355 if($i<$size) 1356 { 1357 $code .= "'".$key."'=>".$value.","; 1358 } 1359 else 1360 { 1361 $code .= "'".$key."'=>".$value; 1362 } 1363 $i++; 1364 } 1365 $code .= ')'; 1366 return $code; 1367 } 1368 } 1369 1370 1371 1372 /** Converts the input array to a single string to facilitate the writing of the input array in a flat file 1373 1374 * @param $var -- input array:: Type array 1375 * @returns $code -- contains the whole array in a single string:: Type array 1376 */ 1377 function constructSingleStringKeyValueArray($var) { 1378 global $adb; 1379 $size = sizeof($var); 1380 $i=1; 1381 if (is_array($var)) { 1382 $code = 'array('; 1383 foreach ($var as $key => $value) { 1384 //fix for signatue quote(') issue 1385 $value=$adb->sql_escape_string($value); 1386 if($i<$size) { 1387 $code .= "'".$key."'=>'".$value."',"; 1388 } else { 1389 $code .= "'".$key."'=>'".$value."'"; 1390 } 1391 $i++; 1392 } 1393 $code .= ')'; 1394 return $code; 1395 } 1396 } 1397 1398 1399 /** Converts the input array to a single string to facilitate the writing of the input array in a flat file 1400 1401 * @param $var -- input array:: Type array 1402 * @returns $code -- contains the whole array in a single string:: Type array 1403 */ 1404 function constructSingleArray($var) 1405 { 1406 if (is_array($var)) 1407 { 1408 $code = 'array('; 1409 foreach ($var as $value) 1410 { 1411 $code .= $value.','; 1412 } 1413 $code .= ')'; 1414 return $code; 1415 } 1416 } 1417 1418 /** Converts the input array to a single string to facilitate the writing of the input array in a flat file 1419 1420 * @param $var -- input array:: Type array 1421 * @returns $code -- contains the whole array in a single string:: Type array 1422 */ 1423 function constructSingleCharArray($var) 1424 { 1425 if (is_array($var)) 1426 { 1427 $code = "array("; 1428 foreach ($var as $value) 1429 { 1430 $code .="'".$value."',"; 1431 } 1432 $code .= ")"; 1433 return $code; 1434 } 1435 } 1436 1437 1438 /** Converts the input array to a single string to facilitate the writing of the input array in a flat file 1439 1440 * @param $var -- input array:: Type array 1441 * @returns $code -- contains the whole array in a single string:: Type array 1442 */ 1443 function constructTwoDimensionalArray($var) 1444 { 1445 if (is_array($var)) 1446 { 1447 $code = 'array('; 1448 foreach ($var as $key => $secarr) 1449 { 1450 $code .= $key.'=>array('; 1451 foreach($secarr as $seckey => $secvalue) 1452 { 1453 $code .= $seckey.'=>'.$secvalue.','; 1454 } 1455 $code .= '),'; 1456 } 1457 $code .= ')'; 1458 return $code; 1459 } 1460 } 1461 1462 /** Converts the input array to a single string to facilitate the writing of the input array in a flat file 1463 1464 * @param $var -- input array:: Type array 1465 * @returns $code -- contains the whole array in a single string:: Type array 1466 */ 1467 function constructTwoDimensionalValueArray($var) 1468 { 1469 if (is_array($var)) 1470 { 1471 $code = 'array('; 1472 foreach ($var as $key => $secarr) 1473 { 1474 $code .= $key.'=>array('; 1475 foreach($secarr as $seckey => $secvalue) 1476 { 1477 $code .= $secvalue.','; 1478 } 1479 $code .= '),'; 1480 } 1481 $code .= ')'; 1482 return $code; 1483 } 1484 } 1485 1486 /** Converts the input array to a single string to facilitate the writing of the input array in a flat file 1487 1488 * @param $var -- input array:: Type array 1489 * @returns $code -- contains the whole array in a single string:: Type array 1490 */ 1491 function constructTwoDimensionalCharIntSingleArray($var) 1492 { 1493 if (is_array($var)) 1494 { 1495 $code = "array("; 1496 foreach ($var as $key => $secarr) 1497 { 1498 $code .= "'".$key."'=>array("; 1499 foreach($secarr as $seckey => $secvalue) 1500 { 1501 $code .= $seckey.","; 1502 } 1503 $code .= "),"; 1504 } 1505 $code .= ")"; 1506 return $code; 1507 } 1508 } 1509 1510 /** Converts the input array to a single string to facilitate the writing of the input array in a flat file 1511 1512 * @param $var -- input array:: Type array 1513 * @returns $code -- contains the whole array in a single string:: Type array 1514 */ 1515 function constructTwoDimensionalCharIntSingleValueArray($var) 1516 { 1517 if (is_array($var)) 1518 { 1519 $code = "array("; 1520 foreach ($var as $key => $secarr) 1521 { 1522 $code .= "'".$key."'=>array("; 1523 foreach($secarr as $seckey => $secvalue) 1524 { 1525 $code .= $secvalue.","; 1526 } 1527 $code .= "),"; 1528 } 1529 $code .= ")"; 1530 return $code; 1531 } 1532 } 1533 1534 1535 /** Function to populate the read/wirte Sharing permissions data of user/groups for the specified user into the database 1536 * @param $userid -- user id:: Type integer 1537 */ 1538 1539 function populateSharingtmptables($userid) 1540 { 1541 global $adb; 1542 checkFileAccessForInclusion('user_privileges/sharing_privileges_'.$userid.'.php'); 1543 require('user_privileges/sharing_privileges_'.$userid.'.php'); 1544 //Deleting from the existing vtiger_tables 1545 $table_arr=Array('vtiger_tmp_read_user_sharing_per', 'vtiger_tmp_write_user_sharing_per','vtiger_tmp_read_group_sharing_per','vtiger_tmp_write_group_sharing_per','vtiger_tmp_read_user_rel_sharing_per','vtiger_tmp_write_user_rel_sharing_per','vtiger_tmp_read_group_rel_sharing_per','vtiger_tmp_write_group_rel_sharing_per'); 1546 foreach($table_arr as $tabname) 1547 { 1548 $query = "delete from ".$tabname." where userid=?"; 1549 $adb->pquery($query, array($userid)); 1550 } 1551 1552 // Look up for modules for which sharing access is enabled. 1553 $sharingArray = Array('Emails'); 1554 $otherModules = getSharingModuleList(); 1555 $sharingArray = array_merge($sharingArray, $otherModules); 1556 1557 foreach($sharingArray as $module) 1558 { 1559 $module_sharing_read_permvar = $module.'_share_read_permission'; 1560 $module_sharing_write_permvar = $module.'_share_write_permission'; 1561 1562 populateSharingPrivileges('USER',$userid,$module,'read', $$module_sharing_read_permvar ); 1563 populateSharingPrivileges('USER',$userid,$module,'write', $$module_sharing_write_permvar ); 1564 populateSharingPrivileges('GROUP',$userid,$module,'read', $$module_sharing_read_permvar ); 1565 populateSharingPrivileges('GROUP',$userid,$module,'write', $$module_sharing_write_permvar ); 1566 } 1567 //Populating Values into the temp related sharing tables 1568 foreach($related_module_share as $rel_tab_id => $tabid_arr) 1569 { 1570 $rel_tab_name=getTabname($rel_tab_id); 1571 foreach($tabid_arr as $taid) 1572 { 1573 $tab_name=getTabname($taid); 1574 1575 $relmodule_sharing_read_permvar = $tab_name.'_'.$rel_tab_name.'_share_read_permission'; 1576 $relmodule_sharing_write_permvar = $tab_name.'_'.$rel_tab_name.'_share_write_permission'; 1577 1578 populateRelatedSharingPrivileges('USER',$userid,$tab_name,$rel_tab_name,'read', $$relmodule_sharing_read_permvar); 1579 populateRelatedSharingPrivileges('USER',$userid,$tab_name,$rel_tab_name,'write', $$relmodule_sharing_write_permvar); 1580 populateRelatedSharingPrivileges('GROUP',$userid,$tab_name,$rel_tab_name,'read', $$relmodule_sharing_read_permvar); 1581 populateRelatedSharingPrivileges('GROUP',$userid,$tab_name,$rel_tab_name,'write', $$relmodule_sharing_write_permvar); 1582 } 1583 } 1584 } 1585 1586 /** Function to populate the read/wirte Sharing permissions data for the specified user into the database 1587 * @param $userid -- user id:: Type integer 1588 * @param $enttype -- can have the value of User or Group:: Type varchar 1589 * @param $module -- module name:: Type varchar 1590 * @param $pertype -- can have the value of read or write:: Type varchar 1591 * @param $var_name_arr - Variable to use instead of including the sharing access again 1592 */ 1593 function populateSharingPrivileges($enttype,$userid,$module,$pertype, $var_name_arr=false) 1594 { 1595 global $adb; 1596 $tabid=getTabid($module); 1597 1598 if(!$var_name_arr) { 1599 checkFileAccessForInclusion('user_privileges/sharing_privileges_'.$userid.'.php'); 1600 require('user_privileges/sharing_privileges_'.$userid.'.php'); 1601 } 1602 1603 if($enttype=='USER') 1604 { 1605 if($pertype =='read') 1606 { 1607 $table_name='vtiger_tmp_read_user_sharing_per'; 1608 $var_name=$module.'_share_read_permission'; 1609 } 1610 elseif($pertype == 'write') 1611 { 1612 $table_name='vtiger_tmp_write_user_sharing_per'; 1613 $var_name=$module.'_share_write_permission'; 1614 } 1615 // Lookup for the variable if not set through function argument 1616 if(!$var_name_arr) $var_name_arr=$$var_name; 1617 $user_arr=Array(); 1618 if(sizeof($var_name_arr['ROLE']) > 0) 1619 { 1620 foreach($var_name_arr['ROLE'] as $roleid=>$roleusers) 1621 { 1622 1623 foreach($roleusers as $user_id) 1624 { 1625 if(! in_array($user_id,$user_arr)) 1626 { 1627 $query="insert into ".$table_name." values(?,?,?)"; 1628 $adb->pquery($query, array($userid, $tabid, $user_id)); 1629 $user_arr[]=$user_id; 1630 } 1631 } 1632 } 1633 } 1634 if(sizeof($var_name_arr['GROUP']) > 0) 1635 { 1636 foreach($var_name_arr['GROUP'] as $grpid=>$grpusers) 1637 { 1638 foreach($grpusers as $user_id) 1639 { 1640 if(! in_array($user_id,$user_arr)) 1641 { 1642 $query="insert into ".$table_name." values(?,?,?)"; 1643 $adb->pquery($query, array($userid, $tabid, $user_id)); 1644 $user_arr[]=$user_id; 1645 } 1646 } 1647 } 1648 } 1649 1650 1651 } 1652 elseif($enttype=='GROUP') 1653 { 1654 if($pertype =='read') 1655 { 1656 $table_name='vtiger_tmp_read_group_sharing_per'; 1657 $var_name=$module.'_share_read_permission'; 1658 } 1659 elseif($pertype == 'write') 1660 { 1661 $table_name='vtiger_tmp_write_group_sharing_per'; 1662 $var_name=$module.'_share_write_permission'; 1663 } 1664 // Lookup for the variable if not set through function argument 1665 if(!$var_name_arr) $var_name_arr=$$var_name; 1666 $grp_arr=Array(); 1667 if(sizeof($var_name_arr['GROUP']) > 0) 1668 { 1669 1670 foreach($var_name_arr['GROUP'] as $grpid=>$grpusers) 1671 { 1672 if(! in_array($grpid,$grp_arr)) 1673 { 1674 $query="insert into ".$table_name." values(?,?,?)"; 1675 $adb->pquery($query, array($userid, $tabid, $grpid)); 1676 $grp_arr[]=$grpid; 1677 } 1678 } 1679 } 1680 1681 } 1682 1683 } 1684 1685 1686 /** Function to populate the read/wirte Sharing permissions related module data for the specified user into the database 1687 * @param $userid -- user id:: Type integer 1688 * @param $enttype -- can have the value of User or Group:: Type varchar 1689 * @param $module -- module name:: Type varchar 1690 * @param $relmodule -- related module name:: Type varchar 1691 * @param $pertype -- can have the value of read or write:: Type varchar 1692 * @param $var_name_arr - Variable to use instead of including the sharing access again 1693 */ 1694 1695 function populateRelatedSharingPrivileges($enttype,$userid,$module,$relmodule,$pertype, $var_name_arr=false) 1696 { 1697 global $adb; 1698 $tabid=getTabid($module); 1699 $reltabid=getTabid($relmodule); 1700 1701 if(!$var_name_arr) { 1702 checkFileAccessForInclusion('user_privileges/sharing_privileges_'.$userid.'.php'); 1703 require('user_privileges/sharing_privileges_'.$userid.'.php'); 1704 } 1705 1706 if($enttype=='USER') 1707 { 1708 if($pertype =='read') 1709 { 1710 $table_name='vtiger_tmp_read_user_rel_sharing_per'; 1711 $var_name=$module.'_'.$relmodule.'_share_read_permission'; 1712 } 1713 elseif($pertype == 'write') 1714 { 1715 $table_name='vtiger_tmp_write_user_rel_sharing_per'; 1716 $var_name=$module.'_'.$relmodule.'_share_write_permission'; 1717 } 1718 // Lookup for the variable if not set through function argument 1719 if(!$var_name_arr) $var_name_arr=$$var_name; 1720 $user_arr=Array(); 1721 if(sizeof($var_name_arr['ROLE']) > 0) 1722 { 1723 foreach($var_name_arr['ROLE'] as $roleid=>$roleusers) 1724 { 1725 1726 foreach($roleusers as $user_id) 1727 { 1728 if(! in_array($user_id,$user_arr)) 1729 { 1730 $query="insert into ".$table_name." values(?,?,?,?)"; 1731 $adb->pquery($query, array($userid, $tabid, $reltabid, $user_id)); 1732 $user_arr[]=$user_id; 1733 } 1734 } 1735 } 1736 } 1737 if(sizeof($var_name_arr['GROUP']) > 0) 1738 { 1739 foreach($var_name_arr['GROUP'] as $grpid=>$grpusers) 1740 { 1741 foreach($grpusers as $user_id) 1742 { 1743 if(! in_array($user_id,$user_arr)) 1744 { 1745 $query="insert into ".$table_name." values(?,?,?,?)"; 1746 $adb->pquery($query, array($userid, $tabid, $reltabid, $user_id)); 1747 $user_arr[]=$user_id; 1748 } 1749 } 1750 } 1751 } 1752 1753 1754 } 1755 elseif($enttype=='GROUP') 1756 { 1757 if($pertype =='read') 1758 { 1759 $table_name='vtiger_tmp_read_group_rel_sharing_per'; 1760 $var_name=$module.'_'.$relmodule.'_share_read_permission'; 1761 } 1762 elseif($pertype == 'write') 1763 { 1764 $table_name='vtiger_tmp_write_group_rel_sharing_per'; 1765 $var_name=$module.'_'.$relmodule.'_share_write_permission'; 1766 } 1767 // Lookup for the variable if not set through function argument 1768 if(!$var_name_arr) $var_name_arr=$$var_name; 1769 $grp_arr=Array(); 1770 if(sizeof($var_name_arr['GROUP']) > 0) 1771 { 1772 1773 foreach($var_name_arr['GROUP'] as $grpid=>$grpusers) 1774 { 1775 if(! in_array($grpid,$grp_arr)) 1776 { 1777 $query="insert into ".$table_name." values(?,?,?,?)"; 1778 $adb->pquery($query, array($userid, $tabid, $reltabid, $grpid)); 1779 $grp_arr[]=$grpid; 1780 } 1781 } 1782 } 1783 1784 } 1785 1786 } 1787 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |