[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /********************************************************************************* 3 ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 * 10 ********************************************************************************/ 11 12 require_once ('include/logging.php'); 13 require_once ('modules/CustomView/CustomView.php'); 14 15 class ListViewSession { 16 17 var $module = null; 18 var $viewname = null; 19 var $start = null; 20 var $sorder = null; 21 var $sortby = null; 22 var $page_view = null; 23 24 /**initializes ListViewSession 25 * Portions created by vtigerCRM are Copyright (C) vtigerCRM. 26 * All Rights Reserved. 27 */ 28 29 function ListViewSession() 30 { 31 global $log,$currentModule; 32 $log->debug("Entering ListViewSession() method ..."); 33 34 $this->module = $currentModule; 35 $this->sortby = 'ASC'; 36 $this->start =1; 37 } 38 39 function getCurrentPage($currentModule,$viewId){ 40 if(!empty($_SESSION['lvs'][$currentModule][$viewId]['start'])){ 41 return $_SESSION['lvs'][$currentModule][$viewId]['start']; 42 } 43 return 1; 44 } 45 46 function getRequestStartPage(){ 47 $start = $_REQUEST['start']; 48 if(!is_numeric($start)){ 49 $start = 1; 50 } 51 if($start < 1){ 52 $start = 1; 53 } 54 $start = ceil($start); 55 return $start; 56 } 57 58 function getListViewNavigation($currentRecordId){ 59 global $currentModule,$current_user,$adb,$log,$list_max_entries_per_page; 60 Zend_Json::$useBuiltinEncoderDecoder = true; 61 $reUseData = false; 62 $displayBufferRecordCount = 10; 63 $bufferRecordCount = 15; 64 if($currentModule == 'Documents'){ 65 $sql = "select folderid from vtiger_notes where notesid=?"; 66 $params = array($currentRecordId); 67 $result = $adb->pquery($sql,$params); 68 $folderId = $adb->query_result($result,0,'folderid'); 69 } 70 $cv = new CustomView(); 71 $viewId = $cv->getViewId($currentModule); 72 if(!empty($_SESSION[$currentModule.'_DetailView_Navigation'.$viewId])){ 73 $recordNavigationInfo = Zend_Json::decode($_SESSION[$currentModule.'_DetailView_Navigation'.$viewId]); 74 $pageNumber =0; 75 if(count($recordNavigationInfo) == 1){ 76 foreach ($recordNavigationInfo as $recordIdList) { 77 if(in_array($currentRecordId,$recordIdList)){ 78 $reUseData = true; 79 } 80 } 81 }else{ 82 $recordList = array(); 83 $recordPageMapping = array(); 84 foreach ($recordNavigationInfo as $start=>$recordIdList){ 85 foreach ($recordIdList as $index=>$recordId) { 86 $recordList[] = $recordId; 87 $recordPageMapping[$recordId] = $start; 88 if($recordId == $currentRecordId){ 89 $searchKey = count($recordList)-1; 90 $_REQUEST['start'] = $start; 91 } 92 } 93 } 94 if($searchKey > $displayBufferRecordCount -1 && $searchKey < count($recordList)-$displayBufferRecordCount){ 95 $reUseData= true; 96 } 97 } 98 } 99 100 $list_query = $_SESSION[$currentModule.'_listquery']; 101 102 if($reUseData === false && !empty($list_query)){ 103 $recordNavigationInfo = array(); 104 if(!empty($_REQUEST['start'])){ 105 $start = ListViewSession::getRequestStartPage(); 106 }else{ 107 $start = ListViewSession::getCurrentPage($currentModule,$viewId); 108 } 109 $startRecord = (($start - 1) * $list_max_entries_per_page) - $bufferRecordCount; 110 if($startRecord < 0){ 111 $startRecord = 0; 112 } 113 114 $instance = CRMEntity::getInstance($currentModule); 115 $instance->getNonAdminAccessControlQuery($currentModule, $current_user); 116 vtlib_setup_modulevars($currentModule, $instance); 117 if($currentModule=='Documents' && !empty($folderId)){ 118 $list_query = preg_replace("/[\n\r\s]+/"," ",$list_query); 119 $list_query = explode('ORDER BY', $list_query); 120 $default_orderby = $list_query[1]; 121 $list_query = $list_query[0]; 122 $list_query .= " AND vtiger_notes.folderid=$folderId"; 123 $order_by = $instance->getOrderByForFolder($folderId); 124 $sorder = $instance->getSortOrderForFolder($folderId); 125 $tablename = getTableNameForField($currentModule,$order_by); 126 $tablename = (($tablename != '')?($tablename."."):''); 127 if(!empty($order_by)){ 128 $list_query .= ' ORDER BY '.$tablename.$order_by.' '.$sorder; 129 }else{ 130 $list_query .= ' ORDER BY '.$default_orderby.''; 131 } 132 } 133 if($start !=1){ 134 $recordCount = ($list_max_entries_per_page * $start + $bufferRecordCount); 135 }else{ 136 $recordCount = ($list_max_entries_per_page+ $bufferRecordCount); 137 } 138 if( $adb->dbType == "pgsql"){ 139 $list_query .= " OFFSET $startRecord LIMIT $recordCount"; 140 }else{ 141 $list_query .= " LIMIT $startRecord, $recordCount"; 142 } 143 144 $resultAllCRMIDlist_query=$adb->pquery($list_query,array()); 145 $navigationRecordList = array(); 146 while($forAllCRMID = $adb->fetch_array($resultAllCRMIDlist_query)) { 147 $navigationRecordList[] = $forAllCRMID[$instance->table_index]; 148 } 149 150 $pageCount = 0; 151 $current = $start; 152 if($start ==1){ 153 $firstPageRecordCount = $list_max_entries_per_page; 154 }else{ 155 $firstPageRecordCount = $bufferRecordCount; 156 $current -=1; 157 } 158 159 $searchKey = array_search($currentRecordId,$navigationRecordList); 160 $recordNavigationInfo = array(); 161 if($searchKey !== false){ 162 foreach ($navigationRecordList as $index => $recordId) { 163 if(!is_array($recordNavigationInfo[$current])){ 164 $recordNavigationInfo[$current] = array(); 165 } 166 if($index == $firstPageRecordCount || $index == ($firstPageRecordCount+$pageCount * $list_max_entries_per_page)){ 167 $current++; 168 $pageCount++; 169 } 170 $recordNavigationInfo[$current][] = $recordId; 171 } 172 } 173 $_SESSION[$currentModule.'_DetailView_Navigation'.$viewId] = 174 Zend_Json::encode($recordNavigationInfo); 175 } 176 return $recordNavigationInfo; 177 } 178 179 function getRequestCurrentPage($currentModule, $query, $viewid, $queryMode = false) { 180 global $list_max_entries_per_page, $adb; 181 $start = 1; 182 if(isset($_REQUEST['query']) && $_REQUEST['query'] == 'true'&& $_REQUEST['start']!="last"){ 183 return ListViewSession::getRequestStartPage(); 184 } 185 if(!empty($_REQUEST['start'])){ 186 $start = $_REQUEST['start']; 187 if($start == 'last'){ 188 $count_result = $adb->query(Vtiger_Functions::mkCountQuery( $query)); 189 $noofrows = $adb->query_result($count_result,0,"count"); 190 if($noofrows > 0){ 191 $start = ceil($noofrows/$list_max_entries_per_page); 192 } 193 } 194 if(!is_numeric($start)){ 195 $start = 1; 196 }elseif($start < 1){ 197 $start = 1; 198 } 199 $start = ceil($start); 200 }else if(!empty($_SESSION['lvs'][$currentModule][$viewid]['start'])){ 201 $start = $_SESSION['lvs'][$currentModule][$viewid]['start']; 202 } 203 if(!$queryMode) { 204 $_SESSION['lvs'][$currentModule][$viewid]['start'] = intval($start); 205 } 206 return $start; 207 } 208 209 function setSessionQuery($currentModule,$query,$viewid){ 210 if(isset($_SESSION[$currentModule.'_listquery'])){ 211 if($_SESSION[$currentModule.'_listquery'] != $query){ 212 unset($_SESSION[$currentModule.'_DetailView_Navigation'.$viewid]); 213 } 214 } 215 $_SESSION[$currentModule.'_listquery'] = $query; 216 } 217 218 function hasViewChanged($currentModule) { 219 if(empty($_SESSION['lvs'][$currentModule]['viewname'])) return true; 220 if(empty($_REQUEST['viewname'])) return false; 221 if($_REQUEST['viewname'] != $_SESSION['lvs'][$currentModule]['viewname']) return true; 222 return false; 223 } 224 225 /** 226 * Function that sets the module filter in session 227 * @param <String> $module - module name 228 * @param <Integer> $viewId - filter id 229 */ 230 public static function setCurrentView($module, $viewId) { 231 $_SESSION['lvs'][$module]['viewname'] = $viewId; 232 } 233 234 /** 235 * Function that reads current module filter 236 * @param <String> $module - module name 237 * @return <Integer> 238 */ 239 public static function getCurrentView($module) { 240 if(!empty($_SESSION['lvs'][$module]['viewname'])) { 241 return $_SESSION['lvs'][$module]['viewname']; 242 } 243 } 244 } 245 ?>
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 |