/** Function to get the Sharing rule Info * @param $shareId -- Sharing Rule Id * @returns Sharing Rule Information Array in the following format: * $shareRuleInfoArr=Array($shareId, $tabid, $type, $share_ent_type, $to_ent_type, $share_entity_id, $to_entity_id,$permission); */ function getSharingRuleInfo($shareId) { global $log; $log->debug("Entering getSharingRuleInfo(" . $shareId . ") method ..."); global $adb; $shareRuleInfoArr = array(); $query = "select * from vtiger_datashare_module_rel where shareid=?"; $result = $adb->pquery($query, array($shareId)); //Retreving the Sharing Tabid $tabid = $adb->query_result($result, 0, 'tabid'); $type = $adb->query_result($result, 0, 'relationtype'); //Retreiving the Sharing Table Name $tableName = getDSTableNameForType($type); //Retreiving the Sharing Col Names $dsTableColArr = getDSTableColumns($tableName); $share_ent_col = $dsTableColArr[0]; $to_ent_col = $dsTableColArr[1]; //Retreiving the Sharing Entity Col Types $share_ent_type = getEntityTypeFromCol($share_ent_col); $to_ent_type = getEntityTypeFromCol($to_ent_col); //Retreiving the Value from Table $query1 = "select * from {$tableName} where shareid=?"; $result1 = $adb->pquery($query1, array($shareId)); $share_id = $adb->query_result($result1, 0, $share_ent_col); $to_id = $adb->query_result($result1, 0, $to_ent_col); $permission = $adb->query_result($result1, 0, 'permission'); //Constructing the Array $shareRuleInfoArr[] = $shareId; $shareRuleInfoArr[] = $tabid; $shareRuleInfoArr[] = $type; $shareRuleInfoArr[] = $share_ent_type; $shareRuleInfoArr[] = $to_ent_type; $shareRuleInfoArr[] = $share_id; $shareRuleInfoArr[] = $to_id; $shareRuleInfoArr[] = $permission; $log->debug("Exiting getSharingRuleInfo method ..."); return $shareRuleInfoArr; }
/** returns the list of sharing rules for the specified module * @param $module -- Module Name:: Type varchar * @returns $access_permission -- sharing rules list info array:: Type array * */ function getSharingRuleList($module) { global $adb, $mod_strings; $tabid = getTabid($module); $dataShareTableArray = getDataShareTableandColumnArray(); $i = 1; $access_permission = array(); foreach ($dataShareTableArray as $table_name => $colName) { $colNameArr = explode("::", $colName); $query = "select " . $table_name . ".* from " . $table_name . " inner join vtiger_datashare_module_rel on " . $table_name . ".shareid=vtiger_datashare_module_rel.shareid where vtiger_datashare_module_rel.tabid=?"; $result = $adb->pquery($query, array($tabid)); $num_rows = $adb->num_rows($result); $share_colName = $colNameArr[0]; $share_modType = getEntityTypeFromCol($share_colName); $to_colName = $colNameArr[1]; $to_modType = getEntityTypeFromCol($to_colName); for ($j = 0; $j < $num_rows; $j++) { $shareid = $adb->query_result($result, $j, "shareid"); $share_id = $adb->query_result($result, $j, $share_colName); $to_id = $adb->query_result($result, $j, $to_colName); $permission = $adb->query_result($result, $j, 'permission'); $share_ent_disp = getEntityDisplayLink($share_modType, $share_id); $to_ent_disp = getEntityDisplayLink($to_modType, $to_id); if ($permission == 0) { $perr_out = $mod_strings['Read Only ']; } elseif ($permission == 1) { $perr_out = $mod_strings['Read/Write']; } $access_permission[] = $shareid; $access_permission[] = $share_ent_disp; $access_permission[] = $to_ent_disp; $access_permission[] = $perr_out; $i++; } } if (is_array($access_permission)) { $access_permission = array_chunk($access_permission, 4); } return $access_permission; }