[ 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 13 /** 14 * Description of ListViewController 15 * 16 * @author MAK 17 */ 18 class ListViewController { 19 /** 20 * 21 * @var QueryGenerator 22 */ 23 private $queryGenerator; 24 /** 25 * 26 * @var PearDatabase 27 */ 28 private $db; 29 private $nameList; 30 private $typeList; 31 private $ownerNameList; 32 private $user; 33 private $picklistValueMap; 34 private $picklistRoleMap; 35 private $headerSortingEnabled; 36 public function __construct($db, $user, $generator) { 37 $this->queryGenerator = $generator; 38 $this->db = $db; 39 $this->user = $user; 40 $this->nameList = array(); 41 $this->typeList = array(); 42 $this->ownerNameList = array(); 43 $this->picklistValueMap = array(); 44 $this->picklistRoleMap = array(); 45 $this->headerSortingEnabled = true; 46 } 47 48 public function isHeaderSortingEnabled() { 49 return $this->headerSortingEnabled; 50 } 51 52 public function setHeaderSorting($enabled) { 53 $this->headerSortingEnabled = $enabled; 54 } 55 56 public function setupAccessiblePicklistValueList($name) { 57 $isRoleBased = vtws_isRoleBasedPicklist($name); 58 $this->picklistRoleMap[$name] = $isRoleBased; 59 if ($this->picklistRoleMap[$name]) { 60 $this->picklistValueMap[$name] = getAssignedPicklistValues($name,$this->user->roleid, $this->db); 61 } 62 } 63 64 public function fetchNameList($field, $result) { 65 $referenceFieldInfoList = $this->queryGenerator->getReferenceFieldInfoList(); 66 $fieldName = $field->getFieldName(); 67 $rowCount = $this->db->num_rows($result); 68 69 $idList = array(); 70 for ($i = 0; $i < $rowCount; $i++) { 71 $id = $this->db->query_result($result, $i, $field->getColumnName()); 72 if (!isset($this->nameList[$fieldName][$id])) { 73 $idList[$id] = $id; 74 } 75 } 76 77 $idList = array_keys($idList); 78 if(count($idList) == 0) { 79 return; 80 } 81 $moduleList = $referenceFieldInfoList[$fieldName]; 82 foreach ($moduleList as $module) { 83 $meta = $this->queryGenerator->getMeta($module); 84 if ($meta->isModuleEntity()) { 85 if($module == 'Users') { 86 $nameList = getOwnerNameList($idList); 87 } else { 88 //TODO handle multiple module names overriding each other. 89 $nameList = getEntityName($module, $idList); 90 } 91 } else { 92 $nameList = vtws_getActorEntityName($module, $idList); 93 } 94 $entityTypeList = array_intersect(array_keys($nameList), $idList); 95 foreach ($entityTypeList as $id) { 96 $this->typeList[$id] = $module; 97 } 98 if(empty($this->nameList[$fieldName])) { 99 $this->nameList[$fieldName] = array(); 100 } 101 foreach ($entityTypeList as $id) { 102 $this->typeList[$id] = $module; 103 $this->nameList[$fieldName][$id] = $nameList[$id]; 104 } 105 } 106 } 107 108 public function getListViewHeaderFields() { 109 $meta = $this->queryGenerator->getMeta($this->queryGenerator->getModule()); 110 $moduleFields = $this->queryGenerator->getModuleFields(); 111 $fields = $this->queryGenerator->getFields(); 112 $headerFields = array(); 113 foreach($fields as $fieldName) { 114 if(array_key_exists($fieldName, $moduleFields)) { 115 $headerFields[$fieldName] = $moduleFields[$fieldName]; 116 } 117 } 118 return $headerFields; 119 } 120 121 function getListViewRecords($focus, $module, $result) { 122 global $listview_max_textlength, $theme, $default_charset; 123 124 require('user_privileges/user_privileges_'.$this->user->id.'.php'); 125 $fields = $this->queryGenerator->getFields(); 126 $meta = $this->queryGenerator->getMeta($this->queryGenerator->getModule()); 127 128 $moduleFields = $this->queryGenerator->getModuleFields(); 129 $accessibleFieldList = array_keys($moduleFields); 130 $listViewFields = array_intersect($fields, $accessibleFieldList); 131 132 $referenceFieldList = $this->queryGenerator->getReferenceFieldList(); 133 foreach ($referenceFieldList as $fieldName) { 134 if (in_array($fieldName, $listViewFields)) { 135 $field = $moduleFields[$fieldName]; 136 $this->fetchNameList($field, $result); 137 } 138 } 139 140 $db = PearDatabase::getInstance(); 141 $rowCount = $db->num_rows($result); 142 $ownerFieldList = $this->queryGenerator->getOwnerFieldList(); 143 foreach ($ownerFieldList as $fieldName) { 144 if (in_array($fieldName, $listViewFields)) { 145 $field = $moduleFields[$fieldName]; 146 $idList = array(); 147 for ($i = 0; $i < $rowCount; $i++) { 148 $id = $this->db->query_result($result, $i, $field->getColumnName()); 149 if (!isset($this->ownerNameList[$fieldName][$id])) { 150 $idList[] = $id; 151 } 152 } 153 if(count($idList) > 0) { 154 if(!is_array($this->ownerNameList[$fieldName])) { 155 $this->ownerNameList[$fieldName] = getOwnerNameList($idList); 156 } else { 157 //array_merge API loses key information so need to merge the arrays 158 // manually. 159 $newOwnerList = getOwnerNameList($idList); 160 foreach ($newOwnerList as $id => $name) { 161 $this->ownerNameList[$fieldName][$id] = $name; 162 } 163 } 164 } 165 } 166 } 167 168 foreach ($listViewFields as $fieldName) { 169 $field = $moduleFields[$fieldName]; 170 if(!$is_admin && ($field->getFieldDataType() == 'picklist' || 171 $field->getFieldDataType() == 'multipicklist')) { 172 $this->setupAccessiblePicklistValueList($fieldName); 173 } 174 } 175 176 $useAsterisk = get_use_asterisk($this->user->id); 177 178 $data = array(); 179 for ($i = 0; $i < $rowCount; ++$i) { 180 //Getting the recordId 181 if($module != 'Users') { 182 $baseTable = $meta->getEntityBaseTable(); 183 $moduleTableIndexList = $meta->getEntityTableIndexList(); 184 $baseTableIndex = $moduleTableIndexList[$baseTable]; 185 186 $recordId = $db->query_result($result,$i,$baseTableIndex); 187 }else { 188 $recordId = $db->query_result($result,$i,"id"); 189 } 190 $row = array(); 191 192 foreach ($listViewFields as $fieldName) { 193 $field = $moduleFields[$fieldName]; 194 $uitype = $field->getUIType(); 195 $rawValue = $this->db->query_result($result, $i, $field->getColumnName()); 196 197 if($uitype != 8){ 198 $value = html_entity_decode($rawValue,ENT_QUOTES,$default_charset); 199 } else { 200 $value = $rawValue; 201 } 202 203 if($module == 'Documents' && $fieldName == 'filename') { 204 $downloadtype = $db->query_result($result,$i,'filelocationtype'); 205 $fileName = $db->query_result($result,$i,'filename'); 206 207 $downloadType = $db->query_result($result,$i,'filelocationtype'); 208 $status = $db->query_result($result,$i,'filestatus'); 209 $fileIdQuery = "select attachmentsid from vtiger_seattachmentsrel where crmid=?"; 210 $fileIdRes = $db->pquery($fileIdQuery,array($recordId)); 211 $fileId = $db->query_result($fileIdRes,0,'attachmentsid'); 212 if($fileName != '' && $status == 1) { 213 if($downloadType == 'I' ) { 214 $value = '<a onclick="Javascript:Documents_Index_Js.updateDownloadCount(\'index.php?module=Documents&action=UpdateDownloadCount&record='.$recordId.'\');"'. 215 ' href="index.php?module=Documents&action=DownloadFile&record='.$recordId.'&fileid='.$fileId.'"'. 216 ' title="'. getTranslatedString('LBL_DOWNLOAD_FILE',$module). 217 '" >'.textlength_check($value). 218 '</a>'; 219 } elseif($downloadType == 'E') { 220 $value = '<a onclick="Javascript:Documents_Index_Js.updateDownloadCount(\'index.php?module=Documents&action=UpdateDownloadCount&record='.$recordId.'\');"'. 221 ' href="'.$fileName.'" target="_blank"'. 222 ' title="'. getTranslatedString('LBL_DOWNLOAD_FILE',$module). 223 '" >'.textlength_check($value). 224 '</a>'; 225 } else { 226 $value = ' --'; 227 } 228 } 229 $value = $fileicon.$value; 230 } elseif($module == 'Documents' && $fieldName == 'filesize') { 231 $downloadType = $db->query_result($result,$i,'filelocationtype'); 232 if($downloadType == 'I') { 233 $filesize = $value; 234 if($filesize < 1024) 235 $value=$filesize.' B'; 236 elseif($filesize > 1024 && $filesize < 1048576) 237 $value=round($filesize/1024,2).' KB'; 238 else if($filesize > 1048576) 239 $value=round($filesize/(1024*1024),2).' MB'; 240 } else { 241 $value = ' --'; 242 } 243 } elseif( $module == 'Documents' && $fieldName == 'filestatus') { 244 if($value == 1) 245 $value=getTranslatedString('yes',$module); 246 elseif($value == 0) 247 $value=getTranslatedString('no',$module); 248 else 249 $value='--'; 250 } elseif( $module == 'Documents' && $fieldName == 'filetype') { 251 $downloadType = $db->query_result($result,$i,'filelocationtype'); 252 if($downloadType == 'E' || $downloadType != 'I') { 253 $value = '--'; 254 } 255 } elseif ($field->getUIType() == '27') { 256 if ($value == 'I') { 257 $value = getTranslatedString('LBL_INTERNAL',$module); 258 }elseif ($value == 'E') { 259 $value = getTranslatedString('LBL_EXTERNAL',$module); 260 }else { 261 $value = ' --'; 262 } 263 }elseif ($field->getFieldDataType() == 'picklist') { 264 //not check for permissions for non admin users for status and activity type field 265 if($module == 'Calendar' && ($fieldName == 'taskstatus' || $fieldName == 'eventstatus' || $fieldName == 'activitytype')) { 266 $value = Vtiger_Language_Handler::getTranslatedString($value,$module); 267 $value = textlength_check($value); 268 } 269 else if ($value != '' && !$is_admin && $this->picklistRoleMap[$fieldName] && 270 !in_array($value, $this->picklistValueMap[$fieldName]) && strtolower($value) != '--none--' && strtolower($value) != 'none' ) { 271 $value = "<font color='red'>". Vtiger_Language_Handler::getTranslatedString('LBL_NOT_ACCESSIBLE', 272 $module)."</font>"; 273 } else { 274 $value = Vtiger_Language_Handler::getTranslatedString($value,$module); 275 $value = textlength_check($value); 276 } 277 }elseif($field->getFieldDataType() == 'date' || $field->getFieldDataType() == 'datetime') { 278 if($value != '' && $value != '0000-00-00') { 279 $fieldDataType = $field->getFieldDataType(); 280 if($module == 'Calendar' &&($fieldName == 'date_start' || $fieldName == 'due_date')) { 281 if($fieldName == 'date_start') { 282 $timeField = 'time_start'; 283 }else if($fieldName == 'due_date') { 284 $timeField = 'time_end'; 285 } 286 $timeFieldValue = $this->db->query_result($result, $i, $timeField); 287 if(!empty($timeFieldValue)){ 288 $value .= ' '. $timeFieldValue; 289 //TO make sure it takes time value as well 290 $fieldDataType = 'datetime'; 291 } 292 } 293 if($fieldDataType == 'datetime') { 294 $value = Vtiger_Datetime_UIType::getDateTimeValue($value); 295 } else if($fieldDataType == 'date') { 296 $date = new DateTimeField($value); 297 $value = $date->getDisplayDate(); 298 } 299 } elseif ($value == '0000-00-00') { 300 $value = ''; 301 } 302 } elseif($field->getFieldDataType() == 'time') { 303 if(!empty($value)){ 304 $userModel = Users_Privileges_Model::getCurrentUserModel(); 305 if($userModel->get('hour_format') == '12'){ 306 $value = Vtiger_Time_UIType::getTimeValueInAMorPM($value); 307 } 308 } 309 } elseif($field->getFieldDataType() == 'currency') { 310 if($value != '') { 311 if($field->getUIType() == 72) { 312 if($fieldName == 'unit_price') { 313 $currencyId = getProductBaseCurrency($recordId,$module); 314 $cursym_convrate = getCurrencySymbolandCRate($currencyId); 315 $currencySymbol = $cursym_convrate['symbol']; 316 } else { 317 $currencyInfo = getInventoryCurrencyInfo($module, $recordId); 318 $currencySymbol = $currencyInfo['currency_symbol']; 319 } 320 $value = CurrencyField::convertToUserFormat($value, null, true); 321 $row['currencySymbol'] = $currencySymbol; 322 // $value = CurrencyField::appendCurrencySymbol($currencyValue, $currencySymbol); 323 } else { 324 if (!empty($value)) { 325 $value = CurrencyField::convertToUserFormat($value); 326 } 327 } 328 } 329 } elseif($field->getFieldDataType() == 'url') { 330 $matchPattern = "^[\w]+:\/\/^"; 331 preg_match($matchPattern, $rawValue, $matches); 332 if(!empty ($matches[0])){ 333 $value = '<a class="urlField cursorPointer" href="'.$rawValue.'" target="_blank">'.textlength_check($value).'</a>'; 334 }else{ 335 $value = '<a class="urlField cursorPointer" href="http://'.$rawValue.'" target="_blank">'.textlength_check($value).'</a>'; 336 } 337 } elseif ($field->getFieldDataType() == 'email') { 338 global $current_user; 339 if($current_user->internal_mailer == 1){ 340 //check added for email link in user detailview 341 $value = "<a class='emailField' onclick=\"Vtiger_Helper_Js.getInternalMailer($recordId,". 342 "'$fieldName','$module');\">".textlength_check($value)."</a>"; 343 } else { 344 $value = '<a class="emailField" href="mailto:'.$rawValue.'">'.textlength_check($value).'</a>'; 345 } 346 } elseif($field->getFieldDataType() == 'boolean') { 347 if ($value === 'on') { 348 $value = 1; 349 } else if ($value == 'off') { 350 $value = 0; 351 } 352 if($value == 1) { 353 $value = getTranslatedString('yes',$module); 354 } elseif($value == 0) { 355 $value = getTranslatedString('no',$module); 356 } else { 357 $value = '--'; 358 } 359 } elseif($field->getUIType() == 98) { 360 $value = '<a href="index.php?module=Roles&parent=Settings&view=Edit&record='.$value.'">'.textlength_check(getRoleName($value)).'</a>'; 361 } elseif($field->getFieldDataType() == 'multipicklist') { 362 $value = ($value != "") ? str_replace(' |##| ',', ',$value) : ""; 363 if(!$is_admin && $value != '') { 364 $valueArray = ($rawValue != "") ? explode(' |##| ',$rawValue) : array(); 365 $notaccess = '<font color="red">'.getTranslatedString('LBL_NOT_ACCESSIBLE', 366 $module)."</font>"; 367 $tmp = ''; 368 $tmpArray = array(); 369 foreach($valueArray as $index => $val) { 370 if(!$listview_max_textlength || 371 !(strlen(preg_replace("/(<\/?)(\w+)([^>]*>)/i","",$tmp)) > 372 $listview_max_textlength)) { 373 if (!$is_admin && $this->picklistRoleMap[$fieldName] && 374 !in_array(trim($val), $this->picklistValueMap[$fieldName])) { 375 $tmpArray[] = $notaccess; 376 $tmp .= ', '.$notaccess; 377 } else { 378 $tmpArray[] = $val; 379 $tmp .= ', '.$val; 380 } 381 } else { 382 $tmpArray[] = '...'; 383 $tmp .= '...'; 384 } 385 } 386 $value = implode(', ', $tmpArray); 387 $value = textlength_check($value); 388 } 389 } elseif ($field->getFieldDataType() == 'skype') { 390 $value = ($value != "") ? "<a href='skype:$value?call'>".textlength_check($value)."</a>" : ""; 391 } elseif ($field->getFieldDataType() == 'phone') { 392 if($useAsterisk == 'true') { 393 $value = "<a href='javascript:;' onclick='startCall("$value", ". 394 ""$recordId")'>".textlength_check($value)."</a>"; 395 } else { 396 $value = textlength_check($value); 397 } 398 } elseif($field->getFieldDataType() == 'reference') { 399 $referenceFieldInfoList = $this->queryGenerator->getReferenceFieldInfoList(); 400 $moduleList = $referenceFieldInfoList[$fieldName]; 401 if(count($moduleList) == 1) { 402 $parentModule = $moduleList[0]; 403 } else { 404 $parentModule = $this->typeList[$value]; 405 } 406 if(!empty($value) && !empty($this->nameList[$fieldName]) && !empty($parentModule)) { 407 $parentMeta = $this->queryGenerator->getMeta($parentModule); 408 $value = textlength_check($this->nameList[$fieldName][$value]); 409 if ($parentMeta->isModuleEntity() && $parentModule != "Users") { 410 $value = "<a href='?module=$parentModule&view=Detail&". 411 "record=$rawValue' title='".getTranslatedString($parentModule, $parentModule)."'>$value</a>"; 412 } 413 } else { 414 $value = '--'; 415 } 416 } elseif($field->getFieldDataType() == 'owner') { 417 $value = textlength_check($this->ownerNameList[$fieldName][$value]); 418 } elseif ($field->getUIType() == 25) { 419 //TODO clean request object reference. 420 $contactId=$_REQUEST['record']; 421 $emailId=$this->db->query_result($result,$i,"activityid"); 422 $result1 = $this->db->pquery("SELECT access_count FROM vtiger_email_track WHERE ". 423 "crmid=? AND mailid=?", array($contactId,$emailId)); 424 $value=$this->db->query_result($result1,0,"access_count"); 425 if(!$value) { 426 $value = 0; 427 } 428 } elseif($field->getUIType() == 8){ 429 if(!empty($value)){ 430 $temp_val = html_entity_decode($value,ENT_QUOTES,$default_charset); 431 $json = new Zend_Json(); 432 $value = vt_suppressHTMLTags(implode(',',$json->decode($temp_val))); 433 } 434 } elseif ( in_array($uitype,array(7,9,90)) ) { 435 $value = "<span align='right'>".textlength_check($value)."</div>"; 436 } else { 437 $value = textlength_check($value); 438 } 439 440 // // vtlib customization: For listview javascript triggers 441 // $value = "$value <span type='vtlib_metainfo' vtrecordid='{$recordId}' vtfieldname=". 442 // "'{$fieldName}' vtmodule='$module' style='display:none;'></span>"; 443 // // END 444 $row[$fieldName] = $value; 445 } 446 $data[$recordId] = $row; 447 } 448 return $data; 449 } 450 } 451 ?>
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 |