[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /* +*********************************************************************************** 3 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 * *********************************************************************************** */ 10 vimport('~~/modules/Reports/Reports.php'); 11 12 class Vtiger_Report_Model extends Reports { 13 14 static function getInstance($reportId = "") { 15 $self = new self(); 16 return $self->Reports($reportId); 17 } 18 19 function Reports($reportId = "") { 20 $db = PearDatabase::getInstance(); 21 $currentUser = Users_Record_Model::getCurrentUserModel(); 22 $userId = $currentUser->getId(); 23 24 $this->initListOfModules(); 25 26 if($reportId != "") { 27 // Lookup information in cache first 28 $cachedInfo = VTCacheUtils::lookupReport_Info($userId, $reportId); 29 $subOrdinateUsers = VTCacheUtils::lookupReport_SubordinateUsers($reportId); 30 31 if($cachedInfo === false) { 32 $ssql = "SELECT vtiger_reportmodules.*, vtiger_report.* FROM vtiger_report 33 INNER JOIN vtiger_reportmodules ON vtiger_report.reportid = vtiger_reportmodules.reportmodulesid 34 WHERE vtiger_report.reportid = ?"; 35 $params = array($reportId); 36 37 require_once ('include/utils/GetUserGroups.php'); 38 require('user_privileges/user_privileges_'.$userId.'.php'); 39 40 $userGroups = new GetUserGroups(); 41 $userGroups->getAllUserGroups($userId); 42 $userGroupsList = $userGroups->user_groups; 43 44 if(!empty($userGroupsList) && $currentUser->isAdminUser() == false) { 45 $userGroupsQuery = " (shareid IN (".generateQuestionMarks($userGroupsList).") AND setype='groups') OR"; 46 array_push($params, $userGroupsList); 47 } 48 49 $nonAdminQuery = " vtiger_report.reportid IN (SELECT reportid from vtiger_reportsharing 50 WHERE $userGroupsQuery (shareid=? AND setype='users'))"; 51 if($currentUser->isAdminUser() == false) { 52 $ssql .= " AND (($nonAdminQuery) 53 OR vtiger_report.sharingtype = 'Public' 54 OR vtiger_report.owner = ? OR vtiger_report.owner IN 55 (SELECT vtiger_user2role.userid FROM vtiger_user2role 56 INNER JOIN vtiger_users ON vtiger_users.id = vtiger_user2role.userid 57 INNER JOIN vtiger_role ON vtiger_role.roleid = vtiger_user2role.roleid 58 WHERE vtiger_role.parentrole LIKE '$current_user_parent_role_seq::%') 59 )"; 60 array_push($params, $userId, $userId); 61 } 62 63 $result = $db->pquery($ssql, $params); 64 65 if($result && $db->num_rows($result)) { 66 $reportModulesRow = $db->fetch_array($result); 67 68 // Update information in cache now 69 VTCacheUtils::updateReport_Info( 70 $userId, $reportId, $reportModulesRow["primarymodule"], 71 $reportModulesRow["secondarymodules"], $reportModulesRow["reporttype"], 72 $reportModulesRow["reportname"], $reportModulesRow["description"], 73 $reportModulesRow["folderid"], $reportModulesRow["owner"] 74 ); 75 } 76 77 $subOrdinateUsers = Array(); 78 79 $subResult = $db->pquery("SELECT userid FROM vtiger_user2role 80 INNER JOIN vtiger_users ON vtiger_users.id = vtiger_user2role.userid 81 INNER JOIN vtiger_role ON vtiger_role.roleid = vtiger_user2role.roleid 82 WHERE vtiger_role.parentrole LIKE '$current_user_parent_role_seq::%'", array()); 83 84 $numOfSubRows = $db->num_rows($subResult); 85 86 for($i=0; $i<$numOfSubRows; $i++) { 87 $subOrdinateUsers[] = $db->query_result($subResult, $i,'userid'); 88 } 89 90 // Update subordinate user information for re-use 91 VTCacheUtils::updateReport_SubordinateUsers($reportId, $subOrdinateUsers); 92 93 // Re-look at cache to maintain code-consistency below 94 $cachedInfo = VTCacheUtils::lookupReport_Info($userId, $reportId); 95 } 96 97 if($cachedInfo) { 98 $this->primodule = $cachedInfo["primarymodule"]; 99 $this->secmodule = $cachedInfo["secondarymodules"]; 100 $this->reporttype = $cachedInfo["reporttype"]; 101 $this->reportname = decode_html($cachedInfo["reportname"]); 102 $this->reportdescription = decode_html($cachedInfo["description"]); 103 $this->folderid = $cachedInfo["folderid"]; 104 if($currentUser->isAdminUser() == true || in_array($cachedInfo["owner"], $subOrdinateUsers) || $cachedInfo["owner"]==$userId) { 105 $this->is_editable = true; 106 }else{ 107 $this->is_editable = false; 108 } 109 } 110 } 111 return $this; 112 } 113 114 function isEditable() { 115 return $this->is_editable; 116 } 117 118 function getModulesList() { 119 foreach($this->module_list as $key=>$value) { 120 if(isPermitted($key,'index') == "yes") { 121 $modules [$key] = vtranslate($key, $key); 122 } 123 } 124 asort($modules); 125 return $modules; 126 } 127 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |