[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/modules/Users/ -> CreateUserPrivilegeFile.php (source)

   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  
  12  require_once ('config.php');
  13  require_once ('modules/Users/Users.php');
  14  require_once ('include/utils/UserInfoUtil.php');
  15  require_once ('include/utils/utils.php');
  16  require_once ('include/utils/GetUserGroups.php');
  17  require_once ('include/utils/GetGroupUsers.php');
  18  
  19  
  20  /** Creates a file with all the user, user-role,user-profile, user-groups informations 
  21    * @param $userid -- user id:: Type integer
  22    * @returns user_privileges_userid file under the user_privileges directory
  23   */
  24  
  25  function createUserPrivilegesfile($userid)
  26  {
  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;
 114      require('user_privileges/user_privileges_'.$userid.'.php');
 115      $handle=@fopen($root_directory.'user_privileges/sharing_privileges_'.$userid.'.php',"w+");
 116  
 117      if($handle)
 118      {
 119          $newbuf='';
 120          $newbuf .="<?php\n\n";
 121          $newbuf .="\n";        
 122          $newbuf .= "//This is the sharing access privilege file\n";
 123          $user_focus= new Users();
 124          $user_focus->retrieve_entity_info($userid,"Users");
 125          if($user_focus->is_admin == 'on')
 126          {
 127              $newbuf .= "\n";
 128              $newbuf .= "?>";
 129              fputs($handle, $newbuf);
 130              fclose($handle);
 131              return;    
 132          }
 133          else
 134          {
 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->query($query);
 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 Invoice Related Module Sharing Array
 278              $pot_related_inv=getRelatedModuleSharingArray("Potentials","Invoice",$pot_sharingrule_members,$pot_share_read_per,$pot_share_write_per,$def_org_share);
 279  
 280              $pot_inv_share_read_per=$pot_related_inv['read'];
 281              $pot_inv_share_write_per=$pot_related_inv['write'];
 282  
 283              $newbuf .= "\$Potentials_Invoice_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($pot_inv_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($pot_inv_share_read_per['GROUP']).");\n\n";    
 284              $newbuf .= "\$Potentials_Invoice_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($pot_inv_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($pot_inv_share_write_per['GROUP']).");\n\n";
 285  
 286  
 287  
 288  
 289              //Constructing HelpDesk Sharing Rules
 290              $hd_share_per_array=getUserModuleSharingObjects("HelpDesk",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups);
 291              $hd_share_read_per=$hd_share_per_array['read'];
 292              $hd_share_write_per=$hd_share_per_array['write'];
 293              $newbuf .= "\$HelpDesk_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($hd_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($hd_share_read_per['GROUP']).");\n\n";    
 294              $newbuf .= "\$HelpDesk_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($hd_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($hd_share_write_per['GROUP']).");\n\n";
 295      
 296  
 297              //Constructing Emails Sharing Rules
 298              $email_share_per_array=getUserModuleSharingObjects("Emails",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups);
 299              $email_share_read_per=$email_share_per_array['read'];
 300              $email_share_write_per=$email_share_per_array['write'];
 301              $newbuf .= "\$Emails_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($email_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($email_share_read_per['GROUP']).");\n\n";    
 302              $newbuf .= "\$Emails_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($email_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($email_share_write_per['GROUP']).");\n\n";
 303  
 304              //Constructing Campaigns Sharing Rules
 305              $campaign_share_per_array=getUserModuleSharingObjects("Campaigns",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups);
 306              $campaign_share_read_per=$campaign_share_per_array['read'];
 307              $campaign_share_write_per=$campaign_share_per_array['write'];
 308              $newbuf .= "\$Campaigns_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($campaign_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($campaign_share_read_per['GROUP']).");\n\n";    
 309              $newbuf .= "\$Campaigns_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($campaign_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($campaign_share_write_per['GROUP']).");\n\n";
 310      
 311  
 312              //Constructing Quotes Sharing Rules
 313              $quotes_share_per_array=getUserModuleSharingObjects("Quotes",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups);
 314              $quotes_share_read_per=$quotes_share_per_array['read'];
 315              $quotes_share_write_per=$quotes_share_per_array['write'];
 316              $quotes_sharingrule_members=$quotes_share_per_array['sharingrules'];
 317              $newbuf .= "\$Quotes_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($quotes_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($quotes_share_read_per['GROUP']).");\n\n";    
 318              $newbuf .= "\$Quotes_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($quotes_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($quotes_share_write_per['GROUP']).");\n\n";
 319  
 320              //Constructing the Quote SalesOrder Related Module Sharing Array
 321              $qt_related_so=getRelatedModuleSharingArray("Quotes","SalesOrder",$quotes_sharingrule_members,$quotes_share_read_per,$quotes_share_write_per,$def_org_share);
 322  
 323              $qt_so_share_read_per=$qt_related_so['read'];
 324              $qt_so_share_write_per=$qt_related_so['write'];
 325  
 326              $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";    
 327              $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";
 328  
 329  
 330  
 331  
 332              //Constructing Orders Sharing Rules
 333              $po_share_per_array=getUserModuleSharingObjects("PurchaseOrder",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups);
 334              $po_share_read_per=$po_share_per_array['read'];
 335              $po_share_write_per=$po_share_per_array['write'];
 336              $newbuf .= "\$PurchaseOrder_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($po_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($po_share_read_per['GROUP']).");\n\n";    
 337              $newbuf .= "\$PurchaseOrder_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($po_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($po_share_write_per['GROUP']).");\n\n";
 338      
 339              //Constructing Sales Order Sharing Rules
 340              $so_share_per_array=getUserModuleSharingObjects("SalesOrder",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups);
 341              $so_share_read_per=$so_share_per_array['read'];
 342              $so_share_write_per=$so_share_per_array['write'];
 343              $so_sharingrule_members=$so_share_per_array['sharingrules'];
 344              $newbuf .= "\$SalesOrder_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($so_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($so_share_read_per['GROUP']).");\n\n";    
 345              $newbuf .= "\$SalesOrder_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($so_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalValueArray($so_share_write_per['GROUP']).");\n\n";
 346  
 347              //Constructing the SalesOrder Invoice Related Module Sharing Array
 348              $so_related_inv=getRelatedModuleSharingArray("SalesOrder","Invoice",$so_sharingrule_members,$so_share_read_per,$so_share_write_per,$def_org_share);
 349  
 350              $so_inv_share_read_per=$so_related_inv['read'];
 351              $so_inv_share_write_per=$so_related_inv['write'];
 352  
 353              $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";    
 354              $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";
 355  
 356  
 357      
 358              //Constructing Invoice Sharing Rules
 359              $inv_share_per_array=getUserModuleSharingObjects("Invoice",$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups);
 360              $inv_share_read_per=$inv_share_per_array['read'];
 361              $inv_share_write_per=$inv_share_per_array['write'];
 362              $newbuf .= "\$Invoice_share_read_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($inv_share_read_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($inv_share_read_per['GROUP']).");\n\n";    
 363              $newbuf .= "\$Invoice_share_write_permission=array('ROLE'=>".constructTwoDimensionalCharIntSingleValueArray($inv_share_write_per['ROLE']).",'GROUP'=>".constructTwoDimensionalArray($inv_share_write_per['GROUP']).");\n\n";
 364      
 365  
 366              $newbuf .= "?>";
 367              fputs($handle, $newbuf);
 368              fclose($handle);
 369  
 370              //Populating Temp Tables
 371              populateSharingtmptables($userid);
 372          }
 373      }
 374  }
 375  
 376  
 377  /** 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 
 378  
 379    * @param $module -- module name:: Type varchar
 380    * @param $userid -- user id:: Type integer
 381    * @param $def_org_share -- default organization sharing permission array:: Type array
 382    * @param $current_user_roles -- roleid:: Type varchar
 383    * @param $parent_roles -- parent roles:: Type varchar
 384    * @param $current_user_groups -- user id:: Type integer
 385    * @returns $mod_share_permission -- array which contains the id of roles,group and users data shared with specifed user for the specified module
 386   */
 387  function getUserModuleSharingObjects($module,$userid,$def_org_share,$current_user_roles,$parent_roles,$current_user_groups)
 388  {
 389      global $adb;
 390  
 391      $mod_tabid=getTabid($module);
 392  
 393      $mod_share_permission;
 394      $mod_share_read_permission=Array();
 395      $mod_share_write_permission=Array();
 396      $mod_share_read_permission['ROLE']=Array();
 397          $mod_share_write_permission['ROLE']=Array();
 398          $mod_share_read_permission['GROUP']=Array();
 399          $mod_share_write_permission['GROUP']=Array();
 400  
 401      $share_id_members=Array();
 402      $share_id_groupmembers=Array();
 403      //If Sharing of leads is Private
 404      if($def_org_share[$mod_tabid] == 3 || $def_org_share[$mod_tabid] == 1)
 405      {
 406          $role_read_per=Array();
 407          $role_write_per=Array();
 408          $rs_read_per=Array();
 409          $rs_write_per=Array();
 410          $grp_read_per=Array();
 411          $grp_write_per=Array();
 412          //Retreiving from vtiger_role to vtiger_role
 413          $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=".$mod_tabid." and vtiger_datashare_role2role.to_roleid='".$current_user_roles."'";
 414          $result=$adb->query($query);
 415          $num_rows=$adb->num_rows($result);
 416          for($i=0;$i<$num_rows;$i++)
 417          {
 418              $share_roleid=$adb->query_result($result,$i,'share_roleid');
 419              
 420              $shareid=$adb->query_result($result,$i,'shareid');
 421              $share_id_role_members=Array();
 422              $share_id_roles=Array();
 423              $share_id_roles[]=$share_roleid;
 424              $share_id_role_members['ROLE']=$share_id_roles;
 425              $share_id_members[$shareid]=$share_id_role_members;
 426      
 427              $share_permission=$adb->query_result($result,$i,'permission');
 428              if($share_permission == 1)
 429              {
 430                  if($def_org_share[$mod_tabid] == 3)
 431                  {    
 432                      if(! array_key_exists($share_roleid,$role_read_per))
 433                      {
 434  
 435                          $share_role_users=getRoleUserIds($share_roleid);
 436                          $role_read_per[$share_roleid]=$share_role_users;
 437                      }
 438                  }
 439                  if(! array_key_exists($share_roleid,$role_write_per))
 440                  {
 441  
 442                      $share_role_users=getRoleUserIds($share_roleid);
 443                      $role_write_per[$share_roleid]=$share_role_users;
 444                  }
 445              }
 446              elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3)
 447              {
 448                  if(! array_key_exists($share_roleid,$role_read_per))
 449                  {
 450  
 451                      $share_role_users=getRoleUserIds($share_roleid);
 452                      $role_read_per[$share_roleid]=$share_role_users;
 453                  }
 454  
 455              }
 456  
 457          }
 458  
 459  
 460  
 461          //Retreiving from role to rs
 462          $parRoleList = "(";
 463          foreach($parent_roles as $par_role_id)
 464          {
 465              $parRoleList .= "'".$par_role_id."',";        
 466          }
 467          $parRoleList .= "'".$current_user_roles."')";
 468          $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=".$mod_tabid." and vtiger_datashare_role2rs.to_roleandsubid in ".$parRoleList;
 469          $result=$adb->query($query);
 470          $num_rows=$adb->num_rows($result);
 471          for($i=0;$i<$num_rows;$i++)
 472          {
 473              $share_roleid=$adb->query_result($result,$i,'share_roleid');
 474  
 475              $shareid=$adb->query_result($result,$i,'shareid');
 476              $share_id_role_members=Array();
 477              $share_id_roles=Array();
 478              $share_id_roles[]=$share_roleid;
 479              $share_id_role_members['ROLE']=$share_id_roles;
 480              $share_id_members[$shareid]=$share_id_role_members;
 481  
 482              $share_permission=$adb->query_result($result,$i,'permission');
 483              if($share_permission == 1)
 484              {
 485                  if($def_org_share[$mod_tabid] == 3)
 486                  {    
 487                      if(! array_key_exists($share_roleid,$role_read_per))
 488                      {
 489  
 490                          $share_role_users=getRoleUserIds($share_roleid);
 491                          $role_read_per[$share_roleid]=$share_role_users;
 492                      }
 493                  }
 494                  if(! array_key_exists($share_roleid,$role_write_per))
 495                  {
 496  
 497                      $share_role_users=getRoleUserIds($share_roleid);
 498                      $role_write_per[$share_roleid]=$share_role_users;
 499                  }
 500              }
 501              elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3)
 502              {
 503                  if(! array_key_exists($share_roleid,$role_read_per))
 504                  {
 505  
 506                      $share_role_users=getRoleUserIds($share_roleid);
 507                      $role_read_per[$share_roleid]=$share_role_users;
 508                  }
 509  
 510              }
 511  
 512          }
 513  
 514  
 515          //Get roles from Role2Grp
 516          $grpIterator=false;
 517          $groupList = "(";
 518          foreach($current_user_groups as $grp_id)
 519          {
 520              if($grpIterator)
 521              {
 522                  $groupList .= ",";
 523              }
 524              $groupList .= "'".$grp_id."'";
 525              $grpIterator=true;        
 526          }
 527          $groupList .= ")";
 528  
 529          $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=".$mod_tabid." and vtiger_datashare_role2group.to_groupid in ".$groupList;
 530          $result=$adb->query($query);
 531          $num_rows=$adb->num_rows($result);
 532          for($i=0;$i<$num_rows;$i++)
 533          {
 534              $share_roleid=$adb->query_result($result,$i,'share_roleid');
 535              $shareid=$adb->query_result($result,$i,'shareid');
 536              $share_id_role_members=Array();
 537              $share_id_roles=Array();
 538              $share_id_roles[]=$share_roleid;
 539              $share_id_role_members['ROLE']=$share_id_roles;
 540              $share_id_members[$shareid]=$share_id_role_members;    
 541  
 542              $share_permission=$adb->query_result($result,$i,'permission');
 543              if($share_permission == 1)
 544              {
 545                  if($def_org_share[$mod_tabid] == 3)
 546                  {    
 547                      if(! array_key_exists($share_roleid,$role_read_per))
 548                      {
 549  
 550                          $share_role_users=getRoleUserIds($share_roleid);
 551                          $role_read_per[$share_roleid]=$share_role_users;
 552                      }
 553                  }
 554                  if(! array_key_exists($share_roleid,$role_write_per))
 555                  {
 556  
 557                      $share_role_users=getRoleUserIds($share_roleid);
 558                      $role_write_per[$share_roleid]=$share_role_users;
 559                  }
 560              }
 561              elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3)
 562              {
 563                  if(! array_key_exists($share_roleid,$role_read_per))
 564                  {
 565  
 566                      $share_role_users=getRoleUserIds($share_roleid);
 567                      $role_read_per[$share_roleid]=$share_role_users;
 568                  }
 569  
 570              }
 571  
 572          }
 573  
 574  
 575  
 576          //Retreiving from rs to vtiger_role
 577          $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=".$mod_tabid." and vtiger_datashare_rs2role.to_roleid='".$current_user_roles."'";
 578          $result=$adb->query($query);
 579          $num_rows=$adb->num_rows($result);
 580          for($i=0;$i<$num_rows;$i++)
 581          {
 582              $share_rsid=$adb->query_result($result,$i,'share_roleandsubid');
 583              $share_roleids=getRoleAndSubordinatesRoleIds($share_rsid);
 584              $share_permission=$adb->query_result($result,$i,'permission');
 585  
 586              $shareid=$adb->query_result($result,$i,'shareid');
 587              $share_id_role_members=Array();
 588              $share_id_roles=Array();
 589              foreach($share_roleids as $share_roleid)
 590              {
 591                  $share_id_roles[]=$share_roleid;
 592                  
 593  
 594                  if($share_permission == 1)
 595                  {
 596                      if($def_org_share[$mod_tabid] == 3)
 597                      {    
 598                          if(! array_key_exists($share_roleid,$role_read_per))
 599                          {
 600  
 601                              $share_role_users=getRoleUserIds($share_roleid);
 602                              $role_read_per[$share_roleid]=$share_role_users;
 603                          }
 604                      }
 605                      if(! array_key_exists($share_roleid,$role_write_per))
 606                      {
 607  
 608                          $share_role_users=getRoleUserIds($share_roleid);
 609                          $role_write_per[$share_roleid]=$share_role_users;
 610                      }
 611                  }
 612                  elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3)
 613                  {
 614                      if(! array_key_exists($share_roleid,$role_read_per))
 615                      {
 616  
 617                          $share_role_users=getRoleUserIds($share_roleid);
 618                          $role_read_per[$share_roleid]=$share_role_users;
 619                      }
 620  
 621                  }
 622              }
 623              $share_id_role_members['ROLE']=$share_id_roles;
 624              $share_id_members[$shareid]=$share_id_role_members;
 625  
 626          }
 627  
 628  
 629          //Retreiving from rs to rs
 630          $parRoleList = "(";
 631          foreach($parent_roles as $par_role_id)
 632          {
 633              $parRoleList .= "'".$par_role_id."',";        
 634          }
 635          $parRoleList .= "'".$current_user_roles."')";
 636          $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=".$mod_tabid." and vtiger_datashare_rs2rs.to_roleandsubid in ".$parRoleList;
 637          $result=$adb->query($query);
 638          $num_rows=$adb->num_rows($result);
 639          for($i=0;$i<$num_rows;$i++)
 640          {
 641              $share_rsid=$adb->query_result($result,$i,'share_roleandsubid');
 642              $share_roleids=getRoleAndSubordinatesRoleIds($share_rsid);
 643              $share_permission=$adb->query_result($result,$i,'permission');
 644          
 645              $shareid=$adb->query_result($result,$i,'shareid');
 646              $share_id_role_members=Array();
 647              $share_id_roles=Array();
 648              foreach($share_roleids as $share_roleid)
 649              {
 650  
 651                  $share_id_roles[]=$share_roleid;
 652  
 653                  if($share_permission == 1)
 654                  {
 655                      if($def_org_share[$mod_tabid] == 3)
 656                      {    
 657                          if(! array_key_exists($share_roleid,$role_read_per))
 658                          {
 659  
 660                              $share_role_users=getRoleUserIds($share_roleid);
 661                              $role_read_per[$share_roleid]=$share_role_users;
 662                          }
 663                      }
 664                      if(! array_key_exists($share_roleid,$role_write_per))
 665                      {
 666  
 667                          $share_role_users=getRoleUserIds($share_roleid);
 668                          $role_write_per[$share_roleid]=$share_role_users;
 669                      }
 670                  }
 671                  elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3)
 672                  {
 673                      if(! array_key_exists($share_roleid,$role_read_per))
 674                      {
 675  
 676                          $share_role_users=getRoleUserIds($share_roleid);
 677                          $role_read_per[$share_roleid]=$share_role_users;
 678                      }
 679  
 680                  }
 681              }
 682              $share_id_role_members['ROLE']=$share_id_roles;
 683              $share_id_members[$shareid]=$share_id_role_members;    
 684  
 685          }
 686  
 687  
 688          //Get roles from Rs2Grp
 689  
 690  
 691          $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=".$mod_tabid." and vtiger_datashare_rs2grp.to_groupid in ".$groupList;
 692          $result=$adb->query($query);
 693          $num_rows=$adb->num_rows($result);
 694          for($i=0;$i<$num_rows;$i++)
 695          {
 696              $share_rsid=$adb->query_result($result,$i,'share_roleandsubid');
 697              $share_roleids=getRoleAndSubordinatesRoleIds($share_rsid);
 698              $share_permission=$adb->query_result($result,$i,'permission');
 699  
 700              $shareid=$adb->query_result($result,$i,'shareid');
 701              $share_id_role_members=Array();
 702              $share_id_roles=Array();
 703  
 704              foreach($share_roleids as $share_roleid)
 705              {
 706                  
 707                  $share_id_roles[]=$share_roleid;
 708              
 709                  if($share_permission == 1)
 710                  {
 711                      if($def_org_share[$mod_tabid] == 3)
 712                      {    
 713                          if(! array_key_exists($share_roleid,$role_read_per))
 714                          {
 715  
 716                              $share_role_users=getRoleUserIds($share_roleid);
 717                              $role_read_per[$share_roleid]=$share_role_users;
 718                          }
 719                      }
 720                      if(! array_key_exists($share_roleid,$role_write_per))
 721                      {
 722  
 723                          $share_role_users=getRoleUserIds($share_roleid);
 724                          $role_write_per[$share_roleid]=$share_role_users;
 725                      }
 726                  }
 727                  elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3)
 728                  {
 729                      if(! array_key_exists($share_roleid,$role_read_per))
 730                      {
 731  
 732                          $share_role_users=getRoleUserIds($share_roleid);
 733                          $role_read_per[$share_roleid]=$share_role_users;
 734                      }
 735  
 736                  }
 737              }
 738              $share_id_role_members['ROLE']=$share_id_roles;
 739              $share_id_members[$shareid]=$share_id_role_members;
 740  
 741  
 742  
 743          }
 744          $mod_share_read_permission['ROLE']=$role_read_per;
 745          $mod_share_write_permission['ROLE']=$role_write_per;
 746          
 747          //Retreiving from the grp2role sharing
 748          $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=".$mod_tabid." and vtiger_datashare_grp2role.to_roleid='".$current_user_roles."'";
 749          $result=$adb->query($query);
 750          $num_rows=$adb->num_rows($result);
 751          for($i=0;$i<$num_rows;$i++)
 752          {
 753              $share_grpid=$adb->query_result($result,$i,'share_groupid');
 754              $share_permission=$adb->query_result($result,$i,'permission');
 755  
 756              $shareid=$adb->query_result($result,$i,'shareid');
 757              $share_id_grp_members=Array();
 758              $share_id_grps=Array();
 759              $share_id_grps[]=$share_grpid;
 760              
 761  
 762              if($share_permission == 1)
 763              {
 764                  if($def_org_share[$mod_tabid] == 3)
 765                  {    
 766                      if(! array_key_exists($share_grpid,$grp_read_per))
 767                      {
 768                          $focusGrpUsers = new GetGroupUsers();
 769                          $focusGrpUsers->getAllUsersInGroup($share_grpid);
 770                          $share_grp_users=$focusGrpUsers->group_users;
 771                          $share_grp_subgroups=$focusGrpUsers->group_subgroups;
 772                          $grp_read_per[$share_grpid]=$share_grp_users;
 773                          foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers)
 774                          {
 775                              if(! array_key_exists($subgrpid,$grp_read_per))
 776                              {
 777                                  $grp_read_per[$subgrpid]=$subgrpusers;    
 778                              }
 779                              if(! in_array($subgrpid,$share_id_grps))
 780                              {
 781                                  $share_id_grps[]=$subgrpid;
 782                              }
 783                              
 784                          }    
 785                      }
 786                  }
 787                  if(! array_key_exists($share_grpid,$grp_write_per))
 788                  {
 789                      $focusGrpUsers = new GetGroupUsers();
 790                      $focusGrpUsers->getAllUsersInGroup($share_grpid);
 791                      $share_grp_users=$focusGrpUsers->group_users;
 792                      $grp_write_per[$share_grpid]=$share_grp_users;
 793                      foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers)
 794                      {
 795                          if(! array_key_exists($subgrpid,$grp_write_per))
 796                          {
 797                              $grp_write_per[$subgrpid]=$subgrpusers;    
 798                          }
 799                          if(! in_array($subgrpid,$share_id_grps))
 800                          {
 801                              $share_id_grps[]=$subgrpid;
 802                          }    
 803  
 804                      }    
 805  
 806                  }
 807              }
 808              elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3)
 809              {
 810                  if(! array_key_exists($share_grpid,$grp_read_per))
 811                  {
 812                      $focusGrpUsers = new GetGroupUsers();
 813                      $focusGrpUsers->getAllUsersInGroup($share_grpid);
 814                      $share_grp_users=$focusGrpUsers->group_users;
 815                      $grp_read_per[$share_grpid]=$share_grp_users;
 816                      foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers)
 817                      {
 818                          if(! array_key_exists($subgrpid,$grp_read_per))
 819                          {
 820                              $grp_read_per[$subgrpid]=$subgrpusers;    
 821                          }
 822                          if(! in_array($subgrpid,$share_id_grps))
 823                          {
 824                              $share_id_grps[]=$subgrpid;
 825                          }    
 826  
 827                      }
 828                  }
 829  
 830              }
 831              $share_id_grp_members['GROUP']=$share_id_grps;
 832              $share_id_members[$shareid]=$share_id_grp_members;
 833  
 834          }
 835  
 836          //Retreiving from the grp2rs sharing
 837  
 838  
 839          $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=".$mod_tabid." and vtiger_datashare_grp2rs.to_roleandsubid in ".$parRoleList;
 840          $result=$adb->query($query);
 841          $num_rows=$adb->num_rows($result);
 842          for($i=0;$i<$num_rows;$i++)
 843          {
 844              $share_grpid=$adb->query_result($result,$i,'share_groupid');
 845              $share_permission=$adb->query_result($result,$i,'permission');
 846  
 847              $shareid=$adb->query_result($result,$i,'shareid');
 848              $share_id_grp_members=Array();
 849              $share_id_grps=Array();
 850              $share_id_grps[]=$share_grpid;
 851              
 852  
 853              if($share_permission == 1)
 854              {
 855                  if($def_org_share[$mod_tabid] == 3)
 856                  {    
 857                      if(! array_key_exists($share_grpid,$grp_read_per))
 858                      {
 859                          $focusGrpUsers = new GetGroupUsers();
 860                          $focusGrpUsers->getAllUsersInGroup($share_grpid);
 861                          $share_grp_users=$focusGrpUsers->group_users;
 862                          $grp_read_per[$share_grpid]=$share_grp_users;
 863  
 864                          foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers)
 865                          {
 866                              if(! array_key_exists($subgrpid,$grp_read_per))
 867                              {
 868                                  $grp_read_per[$subgrpid]=$subgrpusers;    
 869                              }
 870                              if(! in_array($subgrpid,$share_id_grps))
 871                              {
 872                                  $share_id_grps[]=$subgrpid;
 873                              }
 874                              
 875                          }    
 876                      }
 877                  }
 878                  if(! array_key_exists($share_grpid,$grp_write_per))
 879                  {
 880                      $focusGrpUsers = new GetGroupUsers();
 881                      $focusGrpUsers->getAllUsersInGroup($share_grpid);
 882                      $share_grp_users=$focusGrpUsers->group_users;
 883                      $grp_write_per[$share_grpid]=$share_grp_users;
 884                      foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers)
 885                      {
 886                          if(! array_key_exists($subgrpid,$grp_write_per))
 887                          {
 888                                  $grp_write_per[$subgrpid]=$subgrpusers;    
 889                          }
 890                          if(! in_array($subgrpid,$share_id_grps))
 891                          {
 892                              $share_id_grps[]=$subgrpid;
 893                          }
 894                      
 895                      }
 896  
 897                  }
 898              }
 899              elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3)
 900              {
 901                  if(! array_key_exists($share_grpid,$grp_read_per))
 902                  {
 903                      $focusGrpUsers = new GetGroupUsers();
 904                      $focusGrpUsers->getAllUsersInGroup($share_grpid);
 905                      $share_grp_users=$focusGrpUsers->group_users;
 906                      $grp_read_per[$share_grpid]=$share_grp_users;
 907                      foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers)
 908                      {
 909                          if(! array_key_exists($subgrpid,$grp_read_per))
 910                          {
 911                                  $grp_read_per[$subgrpid]=$subgrpusers;    
 912                          }
 913                          if(! in_array($subgrpid,$share_id_grps))
 914                          {
 915                              $share_id_grps[]=$subgrpid;
 916                          }
 917                      
 918                      }
 919                  }
 920  
 921              }
 922              $share_id_grp_members['GROUP']=$share_id_grps;
 923              $share_id_members[$shareid]=$share_id_grp_members;
 924  
 925          }
 926  
 927          //Retreiving from the grp2grp sharing
 928  
 929          $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=".$mod_tabid." and vtiger_datashare_grp2grp.to_groupid in ".$groupList;
 930          $result=$adb->query($query);
 931          $num_rows=$adb->num_rows($result);
 932          for($i=0;$i<$num_rows;$i++)
 933          {
 934              $share_grpid=$adb->query_result($result,$i,'share_groupid');
 935              $share_permission=$adb->query_result($result,$i,'permission');
 936          
 937              $shareid=$adb->query_result($result,$i,'shareid');
 938              $share_id_grp_members=Array();
 939              $share_id_grps=Array();
 940              $share_id_grps[]=$share_grpid;
 941  
 942              if($share_permission == 1)
 943              {
 944                  if($def_org_share[$mod_tabid] == 3)
 945                  {    
 946                      if(! array_key_exists($share_grpid,$grp_read_per))
 947                      {
 948                          $focusGrpUsers = new GetGroupUsers();
 949                          $focusGrpUsers->getAllUsersInGroup($share_grpid);
 950                          $share_grp_users=$focusGrpUsers->group_users;
 951                          $grp_read_per[$share_grpid]=$share_grp_users;
 952                          foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers)
 953                          {
 954                              if(! array_key_exists($subgrpid,$grp_read_per))
 955                              {
 956                                  $grp_read_per[$subgrpid]=$subgrpusers;    
 957                              }
 958                              if(! in_array($subgrpid,$share_id_grps))
 959                              {
 960                                  $share_id_grps[]=$subgrpid;
 961                              }
 962                              
 963                              
 964                          }
 965                      }
 966                  }
 967                  if(! array_key_exists($share_grpid,$grp_write_per))
 968                  {
 969                      $focusGrpUsers = new GetGroupUsers();
 970                      $focusGrpUsers->getAllUsersInGroup($share_grpid);
 971                      $share_grp_users=$focusGrpUsers->group_users;
 972                      $grp_write_per[$share_grpid]=$share_grp_users;
 973                      foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers)
 974                      {
 975                          if(! array_key_exists($subgrpid,$grp_write_per))
 976                          {
 977                              $grp_write_per[$subgrpid]=$subgrpusers;    
 978                          }
 979                          if(! in_array($subgrpid,$share_id_grps))
 980                          {
 981                              $share_id_grps[]=$subgrpid;
 982                          }
 983                              
 984                      }
 985  
 986                  }
 987              }
 988              elseif($share_permission == 0 && $def_org_share[$mod_tabid] == 3)
 989              {
 990                  if(! array_key_exists($share_grpid,$grp_read_per))
 991                  {
 992                      $focusGrpUsers = new GetGroupUsers();
 993                      $focusGrpUsers->getAllUsersInGroup($share_grpid);
 994                      $share_grp_users=$focusGrpUsers->group_users;
 995                      $grp_read_per[$share_grpid]=$share_grp_users;
 996                      foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers)
 997                      {
 998                          if(! array_key_exists($subgrpid,$grp_read_per))
 999                          {
1000                              $grp_read_per[$subgrpid]=$subgrpusers;    
1001                          }
1002                          if(! in_array($subgrpid,$share_id_grps))
1003                          {
1004                              $share_id_grps[]=$subgrpid;
1005                          }
1006  
1007                      }
1008                  }
1009  
1010              }
1011              $share_id_grp_members['GROUP']=$share_id_grps;
1012              $share_id_members[$shareid]=$share_id_grp_members;
1013  
1014          }
1015          $mod_share_read_permission['GROUP']=$grp_read_per;
1016          $mod_share_write_permission['GROUP']=$grp_write_per;    
1017      }
1018      $mod_share_permission['read']=$mod_share_read_permission;
1019      $mod_share_permission['write']=$mod_share_write_permission;
1020      $mod_share_permission['sharingrules']=$share_id_members;    
1021      return $mod_share_permission;
1022  }
1023  
1024  /** 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 
1025  
1026    * @param $par_mod -- parent module name:: Type varchar
1027    * @param $share_mod -- shared module name:: Type varchar
1028    * @param $userid -- user id:: Type integer
1029    * @param $def_org_share -- default organization sharing permission array:: Type array
1030    * @param $mod_sharingrule_members -- Sharing Rule Members array:: Type array
1031    * @param $$mod_share_read_per -- Sharing Module Read Permission array:: Type array
1032    * @param $$mod_share_write_per -- Sharing Module Write Permission array:: Type array
1033    * @returns $related_mod_sharing_permission; -- array which contains the id of roles,group and users related module data to be shared 
1034   */
1035  function getRelatedModuleSharingArray($par_mod,$share_mod,$mod_sharingrule_members,$mod_share_read_per,$mod_share_write_per,$def_org_share)
1036  {
1037  
1038      global $adb;
1039      $related_mod_sharing_permission=Array();
1040      $mod_share_read_permission=Array();
1041      $mod_share_write_permission=Array();
1042  
1043      $mod_share_read_permission['ROLE']=Array();
1044          $mod_share_write_permission['ROLE']=Array();
1045          $mod_share_read_permission['GROUP']=Array();
1046          $mod_share_write_permission['GROUP']=Array();
1047  
1048      $par_mod_id=getTabid($par_mod);
1049      $share_mod_id=getTabid($share_mod);
1050  
1051      if($def_org_share[$share_mod_id] == 3 || $def_org_share[$share_mod_id] == 1)
1052      {
1053  
1054          $role_read_per=Array();
1055          $role_write_per=Array();
1056          $grp_read_per=Array();
1057          $grp_write_per=Array();    
1058  
1059  
1060  
1061          foreach($mod_sharingrule_members as $sharingid => $sharingInfoArr)
1062          {
1063              $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=".$sharingid." and vtiger_datashare_relatedmodules.tabid=".$par_mod_id." and vtiger_datashare_relatedmodules.relatedto_tabid=".$share_mod_id;
1064              $result = $adb->query($query);
1065              $share_permission=$adb->query_result($result,0,'permission');    
1066  
1067              foreach($sharingInfoArr as $shareType => $shareEntArr)
1068              {
1069                  foreach($shareEntArr as $key=>$shareEntId)
1070                  {
1071                      if($shareType == 'ROLE')
1072                      {
1073                          if($share_permission == 1)
1074                          {
1075                              if($def_org_share[$share_mod_id] == 3)
1076                              {    
1077                                  if(! array_key_exists($shareEntId,$role_read_per))
1078                                  {
1079                                      if(array_key_exists($shareEntId,$mod_share_read_per['ROLE']))
1080                                      {
1081                                          $share_role_users=$mod_share_read_per['ROLE'][$shareEntId];
1082                                      }
1083                                      elseif(array_key_exists($shareEntId,$mod_share_write_per['ROLE']))
1084                                      {
1085                                          $share_role_users=$mod_share_write_per['ROLE'][$shareEntId];
1086                                      }
1087                                      else
1088                                      {    
1089  
1090                                          $share_role_users=getRoleUserIds($shareEntId);
1091                                      }
1092  
1093                                      $role_read_per[$shareEntId]=$share_role_users;
1094  
1095                                  }
1096                              }
1097                              if(! array_key_exists($shareEntId,$role_write_per))
1098                              {
1099                                  if(array_key_exists($shareEntId,$mod_share_read_per['ROLE']))
1100                                  {
1101                                      $share_role_users=$mod_share_read_per['ROLE'][$shareEntId];
1102                                  }
1103                                  elseif(array_key_exists($shareEntId,$mod_share_write_per['ROLE']))
1104                                  {
1105                                      $share_role_users=$mod_share_write_per['ROLE'][$shareEntId];
1106                                  }
1107                                  else
1108                                  {    
1109  
1110                                      $share_role_users=getRoleUserIds($shareEntId);
1111  
1112                                  }
1113  
1114                                  $role_write_per[$shareEntId]=$share_role_users;
1115                              }
1116                          }
1117                          elseif($share_permission == 0 && $def_org_share[$share_mod_id] == 3)
1118                          {
1119                              if(! array_key_exists($shareEntId,$role_read_per))
1120                              {
1121                                  if(array_key_exists($shareEntId,$mod_share_read_per['ROLE']))
1122                                  {
1123                                      $share_role_users=$mod_share_read_per['ROLE'][$shareEntId];
1124                                  }
1125                                  elseif(array_key_exists($shareEntId,$mod_share_write_per['ROLE']))
1126                                  {
1127                                      $share_role_users=$mod_share_write_per['ROLE'][$shareEntId];
1128                                  }
1129                                  else
1130                                  {    
1131  
1132                                      $share_role_users=getRoleUserIds($shareEntId);
1133                                  }
1134  
1135                                  $role_read_per[$shareEntId]=$share_role_users;
1136  
1137                              }
1138  
1139  
1140                          }
1141  
1142                      }
1143                      elseif($shareType == 'GROUP')
1144                      {
1145                          if($share_permission == 1)
1146                          {
1147                              if($def_org_share[$share_mod_id] == 3)
1148                              {
1149                                      
1150                                  if(! array_key_exists($shareEntId,$grp_read_per))
1151                                  {
1152                                      if(array_key_exists($shareEntId,$mod_share_read_per['GROUP']))
1153                                      {
1154                                          $share_grp_users=$mod_share_read_per['GROUP'][$shareEntId];
1155                                      }
1156                                      elseif(array_key_exists($shareEntId,$mod_share_write_per['GROUP']))
1157                                      {
1158                                          $share_grp_users=$mod_share_write_per['GROUP'][$shareEntId];
1159                                      }
1160                                      else
1161                                      {
1162                                          $focusGrpUsers = new GetGroupUsers();
1163                                          $focusGrpUsers->getAllUsersInGroup($shareEntId);
1164                                          $share_grp_users=$focusGrpUsers->group_users;
1165                                          
1166                                          foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers)
1167                                          {
1168                                              if(! array_key_exists($subgrpid,$grp_read_per))
1169                                              {
1170                                                  $grp_read_per[$subgrpid]=$subgrpusers;    
1171                                              }
1172  
1173                                          }
1174  
1175                                      }
1176  
1177                                      $grp_read_per[$shareEntId]=$share_grp_users;    
1178  
1179                                  }
1180                              }
1181                              if(! array_key_exists($shareEntId,$grp_write_per))
1182                              {
1183                                  if(! array_key_exists($shareEntId,$grp_write_per))
1184                                  {
1185                                      if(array_key_exists($shareEntId,$mod_share_read_per['GROUP']))
1186                                      {
1187                                          $share_grp_users=$mod_share_read_per['GROUP'][$shareEntId];
1188                                      }
1189                                      elseif(array_key_exists($shareEntId,$mod_share_write_per['GROUP']))
1190                                      {
1191                                          $share_grp_users=$mod_share_write_per['GROUP'][$shareEntId];
1192                                      }
1193                                      else
1194                                      {
1195                                          $focusGrpUsers = new GetGroupUsers();
1196                                          $focusGrpUsers->getAllUsersInGroup($shareEntId);
1197                                          $share_grp_users=$focusGrpUsers->group_users;
1198                                          foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers)
1199                                          {
1200                                              if(! array_key_exists($subgrpid,$grp_write_per))
1201                                              {
1202                                                  $grp_write_per[$subgrpid]=$subgrpusers;    
1203                                              }
1204  
1205                                          }
1206  
1207                                      }
1208  
1209                                      $grp_write_per[$shareEntId]=$share_grp_users;    
1210  
1211                                  }
1212                              }
1213                          }
1214                          elseif($share_permission == 0 && $def_org_share[$share_mod_id] == 3)
1215                          {
1216                              if(! array_key_exists($shareEntId,$grp_read_per))
1217                              {
1218                                  if(array_key_exists($shareEntId,$mod_share_read_per['GROUP']))
1219                                  {
1220                                      $share_grp_users=$mod_share_read_per['GROUP'][$shareEntId];
1221                                  }
1222                                  elseif(array_key_exists($shareEntId,$mod_share_write_per['GROUP']))
1223                                  {
1224                                      $share_grp_users=$mod_share_write_per['GROUP'][$shareEntId];
1225                                  }
1226                                  else
1227                                  {
1228                                      $focusGrpUsers = new GetGroupUsers();
1229                                      $focusGrpUsers->getAllUsersInGroup($shareEntId);
1230                                      $share_grp_users=$focusGrpUsers->group_users;
1231                                      foreach($focusGrpUsers->group_subgroups as $subgrpid=>$subgrpusers)
1232                                      {
1233                                          if(! array_key_exists($subgrpid,$grp_read_per))
1234                                          {
1235                                              $grp_read_per[$subgrpid]=$subgrpusers;    
1236                                          }
1237  
1238                                      }
1239  
1240                                  }
1241  
1242                                  $grp_read_per[$shareEntId]=$share_grp_users;    
1243  
1244                              }
1245  
1246  
1247                          }
1248                      }    
1249                  }
1250              }            
1251          }
1252          $mod_share_read_permission['ROLE']=$role_read_per;
1253          $mod_share_write_permission['ROLE']=$role_write_per;
1254          $mod_share_read_permission['GROUP']=$grp_read_per;
1255          $mod_share_write_permission['GROUP']=$grp_write_per;
1256      }
1257  
1258      $related_mod_sharing_permission['read']=$mod_share_read_permission;
1259      $related_mod_sharing_permission['write']=$mod_share_write_permission;
1260      return $related_mod_sharing_permission;    
1261  
1262  
1263  }
1264  
1265  
1266  /** Converts the input array  to a single string to facilitate the writing of the input array in a flat file 
1267  
1268    * @param $var -- input array:: Type array
1269    * @returns $code -- contains the whole array in a single string:: Type array 
1270   */
1271  function constructArray($var)
1272  {
1273      if (is_array($var))
1274      {
1275                 $code = 'array(';
1276                 foreach ($var as $key => $value)
1277          {
1278                     $code .= "'".$key."'=>".$value.',';
1279                 }
1280                 $code .= ')';
1281                 return $code;
1282         }
1283  }
1284  
1285  /** Converts the input array  to a single string to facilitate the writing of the input array in a flat file 
1286  
1287    * @param $var -- input array:: Type array
1288    * @returns $code -- contains the whole array in a single string:: Type array 
1289   */
1290  function constructSingleStringValueArray($var)
1291  {
1292  
1293          $size = sizeof($var);
1294          $i=1;
1295          if (is_array($var))
1296          {
1297                  $code = 'array(';
1298                  foreach ($var as $key => $value)
1299                  {
1300                          if($i<$size)
1301                          {
1302                                  $code .= $key."=>'".$value."',";
1303                          }
1304                          else
1305                          {
1306                                  $code .= $key."=>'".$value."'";
1307                          }
1308                          $i++;
1309                  }
1310                  $code .= ')';
1311                  return $code;
1312          }
1313  }
1314  
1315  /** Converts the input array  to a single string to facilitate the writing of the input array in a flat file 
1316  
1317    * @param $var -- input array:: Type array
1318    * @returns $code -- contains the whole array in a single string:: Type array 
1319   */
1320  function constructSingleStringKeyAndValueArray($var)
1321  {
1322  
1323          $size = sizeof($var);
1324          $i=1;
1325          if (is_array($var))
1326          {
1327                  $code = 'array(';
1328                  foreach ($var as $key => $value)
1329                  {
1330                          if($i<$size)
1331                          {
1332                                  $code .= "'".$key."'=>".$value.",";
1333                          }
1334                          else
1335                          {
1336                                  $code .= "'".$key."'=>".$value;
1337                          }
1338                          $i++;
1339                  }
1340                  $code .= ')';
1341                  return $code;
1342          }
1343  }
1344  
1345  
1346  
1347  /** Converts the input array  to a single string to facilitate the writing of the input array in a flat file 
1348  
1349    * @param $var -- input array:: Type array
1350    * @returns $code -- contains the whole array in a single string:: Type array 
1351   */
1352  function constructSingleStringKeyValueArray($var)
1353  {
1354  
1355          $size = sizeof($var);
1356          $i=1;
1357          if (is_array($var))
1358          {
1359                  $code = 'array(';
1360                  foreach ($var as $key => $value)
1361                  {
1362                          if($i<$size)
1363                          {
1364                                  $code .= "'".$key."'=>'".$value."',";
1365                          }
1366                          else
1367                          {
1368                                  $code .= "'".$key."'=>'".$value."'";
1369                          }
1370                          $i++;
1371                  }
1372                  $code .= ')';
1373                  return $code;
1374          }
1375  }
1376  
1377  
1378  /** Converts the input array  to a single string to facilitate the writing of the input array in a flat file 
1379  
1380    * @param $var -- input array:: Type array
1381    * @returns $code -- contains the whole array in a single string:: Type array 
1382   */
1383  function constructSingleArray($var)
1384  {
1385      if (is_array($var))
1386      {
1387                 $code = 'array(';
1388                 foreach ($var as $value)
1389          {
1390                     $code .= $value.',';
1391                 }
1392                 $code .= ')';
1393                 return $code;
1394         }
1395  }
1396  
1397  /** Converts the input array  to a single string to facilitate the writing of the input array in a flat file 
1398  
1399    * @param $var -- input array:: Type array
1400    * @returns $code -- contains the whole array in a single string:: Type array 
1401   */
1402  function constructSingleCharArray($var)
1403  {
1404      if (is_array($var))
1405      {
1406                 $code = "array(";
1407                 foreach ($var as $value)
1408          {
1409                     $code .="'".$value."',";
1410                 }
1411                 $code .= ")";
1412                 return $code;
1413         }
1414  }
1415  
1416  
1417  /** Converts the input array  to a single string to facilitate the writing of the input array in a flat file 
1418  
1419    * @param $var -- input array:: Type array
1420    * @returns $code -- contains the whole array in a single string:: Type array 
1421   */
1422  function constructTwoDimensionalArray($var)
1423  {
1424      if (is_array($var))
1425      {
1426                 $code = 'array(';
1427                 foreach ($var as $key => $secarr)
1428          {
1429                     $code .= $key.'=>array(';
1430              foreach($secarr as $seckey => $secvalue)
1431              {
1432                  $code .= $seckey.'=>'.$secvalue.',';
1433              }
1434              $code .= '),';
1435                 }
1436                 $code .= ')';
1437                 return $code;
1438         }
1439  }
1440  
1441  /** Converts the input array  to a single string to facilitate the writing of the input array in a flat file 
1442  
1443    * @param $var -- input array:: Type array
1444    * @returns $code -- contains the whole array in a single string:: Type array 
1445   */
1446  function constructTwoDimensionalValueArray($var)
1447  {
1448      if (is_array($var))
1449      {
1450                 $code = 'array(';
1451                 foreach ($var as $key => $secarr)
1452          {
1453                     $code .= $key.'=>array(';
1454              foreach($secarr as $seckey => $secvalue)
1455              {
1456                  $code .= $secvalue.',';
1457              }
1458              $code .= '),';
1459                 }
1460                 $code .= ')';
1461                 return $code;
1462         }
1463  }
1464  
1465  /** Converts the input array  to a single string to facilitate the writing of the input array in a flat file 
1466  
1467    * @param $var -- input array:: Type array
1468    * @returns $code -- contains the whole array in a single string:: Type array 
1469   */
1470  function constructTwoDimensionalCharIntSingleArray($var)
1471  {
1472      if (is_array($var))
1473      {
1474                 $code = "array(";
1475                 foreach ($var as $key => $secarr)
1476          {
1477                     $code .= "'".$key."'=>array(";
1478              foreach($secarr as $seckey => $secvalue)
1479              {
1480                  $code .= $seckey.",";
1481              }
1482              $code .= "),";
1483                 }
1484                 $code .= ")";
1485                 return $code;
1486         }
1487  }
1488  
1489  /** Converts the input array  to a single string to facilitate the writing of the input array in a flat file 
1490  
1491    * @param $var -- input array:: Type array
1492    * @returns $code -- contains the whole array in a single string:: Type array 
1493   */
1494  function constructTwoDimensionalCharIntSingleValueArray($var)
1495  {
1496      if (is_array($var))
1497      {
1498                 $code = "array(";
1499                 foreach ($var as $key => $secarr)
1500          {
1501                     $code .= "'".$key."'=>array(";
1502              foreach($secarr as $seckey => $secvalue)
1503              {
1504                  $code .= $secvalue.",";
1505              }
1506              $code .= "),";
1507                 }
1508                 $code .= ")";
1509                 return $code;
1510         }
1511  }
1512  
1513  
1514  /** Function to populate the read/wirte Sharing permissions data of user/groups for the specified user into the database 
1515    * @param $userid -- user id:: Type integer
1516   */
1517  
1518  function populateSharingtmptables($userid)
1519  {
1520      global $adb;
1521      require('user_privileges/sharing_privileges_'.$userid.'.php');
1522      //Deleting from the existing vtiger_tables
1523      $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');
1524      foreach($table_arr as $tabname)
1525      {
1526          $query = "delete from ".$tabname." where userid=".$userid;
1527          $adb->query($query);
1528      }
1529  
1530      //Populating Values into the tmp sharing tables
1531      $sharingArray=Array('Leads','Accounts','Contacts','Potentials','HelpDesk','Emails','Campaigns','Quotes','PurchaseOrder','SalesOrder','Invoice');
1532      foreach($sharingArray as $module)
1533      {
1534          populateSharingPrivileges('USER',$userid,$module,'read');
1535          populateSharingPrivileges('USER',$userid,$module,'write');
1536          populateSharingPrivileges('GROUP',$userid,$module,'read');
1537          populateSharingPrivileges('GROUP',$userid,$module,'write');
1538      }
1539      //Populating Values into the temp related sharing tables
1540      foreach($related_module_share as $rel_tab_id => $tabid_arr)
1541      {
1542          $rel_tab_name=getTabname($rel_tab_id);
1543          foreach($tabid_arr as $taid)
1544          {
1545              $tab_name=getTabname($taid);
1546              populateRelatedSharingPrivileges('USER',$userid,$tab_name,$rel_tab_name,'read');
1547                      populateRelatedSharingPrivileges('USER',$userid,$tab_name,$rel_tab_name,'write');
1548                      populateRelatedSharingPrivileges('GROUP',$userid,$tab_name,$rel_tab_name,'read');
1549                      populateRelatedSharingPrivileges('GROUP',$userid,$tab_name,$rel_tab_name,'write');
1550              
1551          }    
1552      }             
1553  }
1554  
1555  /** Function to populate the read/wirte Sharing permissions data for the specified user into the database 
1556    * @param $userid -- user id:: Type integer
1557    * @param $enttype -- can have the value of User or Group:: Type varchar
1558    * @param $module -- module name:: Type varchar
1559    * @param $pertype -- can have the value of read or write:: Type varchar
1560   */
1561  function populateSharingPrivileges($enttype,$userid,$module,$pertype)
1562  {
1563      global $adb;    
1564      require('user_privileges/sharing_privileges_'.$userid.'.php');
1565      $tabid=getTabid($module);
1566      if($enttype=='USER')
1567      {
1568          if($pertype =='read')
1569          {
1570              $table_name='vtiger_tmp_read_user_sharing_per';
1571              $var_name=$module.'_share_read_permission';
1572          }
1573          elseif($pertype == 'write')
1574          {
1575              $table_name='vtiger_tmp_write_user_sharing_per';
1576              $var_name=$module.'_share_write_permission';
1577          }
1578          $var_name_arr=$$var_name;    
1579          $user_arr=Array();
1580          if(sizeof($var_name_arr['ROLE']) > 0)
1581          {
1582              foreach($var_name_arr['ROLE'] as $roleid=>$roleusers)
1583              {
1584                  
1585                  foreach($roleusers as $user_id)
1586                  {
1587                      if(! in_array($user_id,$user_arr))
1588                      {
1589                          $query="insert into ".$table_name." values(".$userid.",".$tabid.",".$user_id.")";
1590                          $adb->query($query);
1591                          $user_arr[]=$user_id;
1592                      }
1593                  }
1594              }
1595          }
1596          if(sizeof($var_name_arr['GROUP']) > 0)
1597          {
1598              foreach($var_name_arr['GROUP'] as $grpid=>$grpusers)
1599              {
1600                  foreach($grpusers as $user_id)
1601                  {
1602                      if(! in_array($user_id,$user_arr))
1603                      {
1604                          $query="insert into ".$table_name." values(".$userid.",".$tabid.",".$user_id.")";
1605                          $adb->query($query);
1606                          $user_arr[]=$user_id;
1607                      }
1608                  }
1609              }
1610          }
1611  
1612  
1613      }
1614      elseif($enttype=='GROUP')
1615      {
1616          if($pertype =='read')
1617          {
1618              $table_name='vtiger_tmp_read_group_sharing_per';
1619              $var_name=$module.'_share_read_permission';
1620          }
1621          elseif($pertype == 'write')
1622          {
1623              $table_name='vtiger_tmp_write_group_sharing_per';
1624              $var_name=$module.'_share_write_permission';
1625          }
1626          $var_name_arr=$$var_name;
1627          $grp_arr=Array();
1628          if(sizeof($var_name_arr['GROUP']) > 0)
1629          {
1630  
1631              foreach($var_name_arr['GROUP'] as $grpid=>$grpusers)
1632              {
1633                  if(! in_array($grpid,$grp_arr))
1634                  {
1635                      $query="insert into ".$table_name." values(".$userid.",".$tabid.",".$grpid.")";
1636                      $adb->query($query);
1637                      $grp_arr[]=$grpid;
1638                  }
1639              }
1640          }
1641  
1642      }
1643  
1644  }
1645  
1646  
1647  /** Function to populate the read/wirte Sharing permissions related module data for the specified user into the database 
1648    * @param $userid -- user id:: Type integer
1649    * @param $enttype -- can have the value of User or Group:: Type varchar
1650    * @param $module -- module name:: Type varchar
1651    * @param $relmodule -- related module name:: Type varchar
1652    * @param $pertype -- can have the value of read or write:: Type varchar
1653   */
1654  
1655  function populateRelatedSharingPrivileges($enttype,$userid,$module,$relmodule,$pertype)
1656  {
1657      global $adb;    
1658      require('user_privileges/sharing_privileges_'.$userid.'.php');
1659      $tabid=getTabid($module);
1660      $reltabid=getTabid($relmodule);
1661      //echo $module.'               '.$enttype.'                '.$pertype.'<BR>';                       
1662      if($enttype=='USER')
1663      {
1664          if($pertype =='read')
1665          {
1666              $table_name='vtiger_tmp_read_user_rel_sharing_per';
1667              $var_name=$module.'_'.$relmodule.'_share_read_permission';
1668          }
1669          elseif($pertype == 'write')
1670          {
1671              $table_name='vtiger_tmp_write_user_rel_sharing_per';
1672              $var_name=$module.'_'.$relmodule.'_share_write_permission';
1673          }
1674          $var_name_arr=$$var_name;    
1675          $user_arr=Array();
1676          if(sizeof($var_name_arr['ROLE']) > 0)
1677          {
1678              foreach($var_name_arr['ROLE'] as $roleid=>$roleusers)
1679              {
1680                  
1681                  foreach($roleusers as $user_id)
1682                  {
1683                      if(! in_array($user_id,$user_arr))
1684                      {
1685                          $query="insert into ".$table_name." values(".$userid.",".$tabid.",".$reltabid.",".$user_id.")";
1686                          $adb->query($query);
1687                          $user_arr[]=$user_id;
1688                      }
1689                  }
1690              }
1691          }
1692          if(sizeof($var_name_arr['GROUP']) > 0)
1693          {
1694              foreach($var_name_arr['GROUP'] as $grpid=>$grpusers)
1695              {
1696                  foreach($grpusers as $user_id)
1697                  {
1698                      if(! in_array($user_id,$user_arr))
1699                      {
1700                          $query="insert into ".$table_name." values(".$userid.",".$tabid.",".$reltabid.",".$user_id.")";
1701                          $adb->query($query);
1702                          $user_arr[]=$user_id;
1703                      }
1704                  }
1705              }
1706          }
1707  
1708  
1709      }
1710      elseif($enttype=='GROUP')
1711      {
1712          if($pertype =='read')
1713          {
1714              $table_name='vtiger_tmp_read_group_rel_sharing_per';
1715              $var_name=$module.'_'.$relmodule.'_share_read_permission';
1716          }
1717          elseif($pertype == 'write')
1718          {
1719              $table_name='vtiger_tmp_write_group_rel_sharing_per';
1720              $var_name=$module.'_'.$relmodule.'_share_write_permission';
1721          }
1722          $var_name_arr=$$var_name;
1723          $grp_arr=Array();
1724          if(sizeof($var_name_arr['GROUP']) > 0)
1725          {
1726  
1727              foreach($var_name_arr['GROUP'] as $grpid=>$grpusers)
1728              {
1729                  if(! in_array($grpid,$grp_arr))
1730                  {
1731                      $query="insert into ".$table_name." values(".$userid.",".$tabid.",".$reltabid.",".$grpid.")";
1732                      $adb->query($query);
1733                      $grp_arr[]=$grpid;
1734                  }
1735              }
1736          }
1737  
1738      }
1739  
1740  }
1741  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7