[ 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 require_once ('data/CRMEntity.php'); 12 require_once ('include/utils/utils.php'); 13 require_once 'include/Webservices/Utils.php'; 14 15 global $adv_filter_options; 16 17 $adv_filter_options = array("e" => "" . $mod_strings['equals'] . "", 18 "n" => "" . $mod_strings['not equal to'] . "", 19 "s" => "" . $mod_strings['starts with'] . "", 20 "ew" => "" . $mod_strings['ends with'] . "", 21 "c" => "" . $mod_strings['contains'] . "", 22 "k" => "" . $mod_strings['does not contain'] . "", 23 "l" => "" . $mod_strings['less than'] . "", 24 "g" => "" . $mod_strings['greater than'] . "", 25 "m" => "" . $mod_strings['less or equal'] . "", 26 "h" => "" . $mod_strings['greater or equal'] . "", 27 "b" => "" . $mod_strings['before'] . "", 28 "a" => "" . $mod_strings['after'] . "", 29 "bw" => "" . $mod_strings['between'] . "", 30 ); 31 32 class CustomView extends CRMEntity { 33 34 var $module_list = Array(); 35 var $customviewmodule; 36 var $list_fields; 37 var $list_fields_name; 38 var $setdefaultviewid; 39 var $escapemodule; 40 var $mandatoryvalues; 41 var $showvalues; 42 var $data_type; 43 // Information as defined for this instance in the database table. 44 protected $_status = false; 45 protected $_userid = false; 46 protected $meta; 47 protected $moduleMetaInfo; 48 49 /** This function sets the currentuser id to the class variable smownerid, 50 * modulename to the class variable customviewmodule 51 * @param $module -- The module Name:: Type String(optional) 52 * @returns nothing 53 */ 54 function CustomView($module = "") { 55 global $current_user, $adb; 56 $this->customviewmodule = $module; 57 $this->escapemodule[] = $module . "_"; 58 $this->escapemodule[] = "_"; 59 $this->smownerid = $current_user->id; 60 $this->moduleMetaInfo = array(); 61 if ($module != "" && $module != 'Calendar') { 62 $this->meta = $this->getMeta($module, $current_user); 63 } 64 } 65 66 /** 67 * 68 * @param String:ModuleName $module 69 * @return EntityMeta 70 */ 71 public function getMeta($module, $user) { 72 $db = PearDatabase::getInstance(); 73 if (empty($this->moduleMetaInfo[$module])) { 74 $handler = vtws_getModuleHandlerFromName($module, $user); 75 $meta = $handler->getMeta(); 76 $this->moduleMetaInfo[$module] = $meta; 77 } 78 return $this->moduleMetaInfo[$module]; 79 } 80 81 /** To get the customViewId of the specified module 82 * @param $module -- The module Name:: Type String 83 * @returns customViewId :: Type Integer 84 */ 85 function getViewId($module) { 86 global $adb, $current_user; 87 $now_action = vtlib_purify($_REQUEST['action']); 88 if (empty($_REQUEST['viewname'])) { 89 if (isset($_SESSION['lvs'][$module]["viewname"]) && $_SESSION['lvs'][$module]["viewname"] != '') { 90 $viewid = $_SESSION['lvs'][$module]["viewname"]; 91 } elseif ($this->setdefaultviewid != "") { 92 $viewid = $this->setdefaultviewid; 93 } else { 94 $defcv_result = $adb->pquery("select default_cvid from vtiger_user_module_preferences where userid = ? and tabid =?", array($current_user->id, getTabid($module))); 95 if ($adb->num_rows($defcv_result) > 0) { 96 $viewid = $adb->query_result($defcv_result, 0, 'default_cvid'); 97 } else { 98 $query = "select cvid from vtiger_customview where setdefault=1 and entitytype=?"; 99 $cvresult = $adb->pquery($query, array($module)); 100 if ($adb->num_rows($cvresult) > 0) { 101 $viewid = $adb->query_result($cvresult, 0, 'cvid'); 102 } else 103 $viewid = ''; 104 } 105 } 106 107 if ($viewid == '' || $viewid == 0 || $this->isPermittedCustomView($viewid, $now_action, $module) != 'yes') { 108 $query = "select cvid from vtiger_customview where viewname='All' and entitytype=?"; 109 $cvresult = $adb->pquery($query, array($module)); 110 $viewid = $adb->query_result($cvresult, 0, 'cvid'); 111 } 112 } else { 113 $viewname = vtlib_purify($_REQUEST['viewname']); 114 if (!is_numeric($viewname)) { 115 if (strtolower($viewname) == 'all' || $viewname == 0) { 116 $viewid = $this->getViewIdByName('All', $module); 117 } else { 118 $viewid = $this->getViewIdByName($viewname, $module); 119 } 120 } else { 121 $viewid = $viewname; 122 } 123 if ($this->isPermittedCustomView($viewid, $now_action, $this->customviewmodule) != 'yes') 124 $viewid = 0; 125 } 126 $_SESSION['lvs'][$module]["viewname"] = $viewid; 127 return $viewid; 128 } 129 130 function getViewIdByName($viewname, $module) { 131 global $adb; 132 if (isset($viewname)) { 133 $query = "select cvid from vtiger_customview where viewname=? and entitytype=?"; 134 $cvresult = $adb->pquery($query, array($viewname, $module)); 135 $viewid = $adb->query_result($cvresult, 0, 'cvid'); 136 ; 137 return $viewid; 138 } else { 139 return 0; 140 } 141 } 142 143 // return type array 144 /** to get the details of a customview 145 * @param $cvid :: Type Integer 146 * @returns $customviewlist Array in the following format 147 * $customviewlist = Array('viewname'=>value, 148 * 'setdefault'=>defaultchk, 149 * 'setmetrics'=>setmetricschk) 150 */ 151 function getCustomViewByCvid($cvid) { 152 global $adb, $current_user; 153 $tabid = getTabid($this->customviewmodule); 154 155 require('user_privileges/user_privileges_' . $current_user->id . '.php'); 156 157 $ssql = "select vtiger_customview.* from vtiger_customview inner join vtiger_tab on vtiger_tab.name = vtiger_customview.entitytype"; 158 $ssql .= " where vtiger_customview.cvid=?"; 159 $sparams = array($cvid); 160 161 if ($is_admin == false) { 162 $ssql .= " and (vtiger_customview.status=0 or vtiger_customview.userid = ? or vtiger_customview.status = 3 or vtiger_customview.userid in(select vtiger_user2role.userid from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '" . $current_user_parent_role_seq . "::%'))"; 163 array_push($sparams, $current_user->id); 164 } 165 $result = $adb->pquery($ssql, $sparams); 166 167 $usercv_result = $adb->pquery("select default_cvid from vtiger_user_module_preferences where userid = ? and tabid = ?", array($current_user->id, $tabid)); 168 $def_cvid = $adb->query_result($usercv_result, 0, 'default_cvid'); 169 170 while ($cvrow = $adb->fetch_array($result)) { 171 $customviewlist["viewname"] = $cvrow["viewname"]; 172 if ((isset($def_cvid) || $def_cvid != '') && $def_cvid == $cvid) { 173 $customviewlist["setdefault"] = 1; 174 } else { 175 $customviewlist["setdefault"] = $cvrow["setdefault"]; 176 } 177 $customviewlist["setmetrics"] = $cvrow["setmetrics"]; 178 $customviewlist["userid"] = $cvrow["userid"]; 179 $customviewlist["status"] = $cvrow["status"]; 180 } 181 return $customviewlist; 182 } 183 184 /** to get the customviewCombo for the class variable customviewmodule 185 * @param $viewid :: Type Integer 186 * $viewid will make the corresponding selected 187 * @returns $customviewCombo :: Type String 188 */ 189 function getCustomViewCombo($viewid = '', $markselected = true) { 190 global $adb, $current_user; 191 global $app_strings; 192 $tabid = getTabid($this->customviewmodule); 193 194 require('user_privileges/user_privileges_' . $current_user->id . '.php'); 195 196 $shtml_user = ''; 197 $shtml_pending = ''; 198 $shtml_public = ''; 199 $shtml_others = ''; 200 201 $selected = 'selected'; 202 if ($markselected == false) 203 $selected = ''; 204 205 $ssql = "select vtiger_customview.*, vtiger_users.first_name,vtiger_users.last_name from vtiger_customview inner join vtiger_tab on vtiger_tab.name = vtiger_customview.entitytype 206 left join vtiger_users on vtiger_customview.userid = vtiger_users.id "; 207 $ssql .= " where vtiger_tab.tabid=?"; 208 $sparams = array($tabid); 209 210 if ($is_admin == false) { 211 $ssql .= " and (vtiger_customview.status=0 or vtiger_customview.userid = ? or vtiger_customview.status = 3 or vtiger_customview.userid in(select vtiger_user2role.userid from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '" . $current_user_parent_role_seq . "::%'))"; 212 array_push($sparams, $current_user->id); 213 } 214 $ssql .= " ORDER BY viewname"; 215 $result = $adb->pquery($ssql, $sparams); 216 while ($cvrow = $adb->fetch_array($result)) { 217 if ($cvrow['viewname'] == 'All') { 218 $cvrow['viewname'] = $app_strings['COMBO_ALL']; 219 } 220 221 $option = ''; 222 $viewname = $cvrow['viewname']; 223 if ($cvrow['status'] == CV_STATUS_DEFAULT || $cvrow['userid'] == $current_user->id) { 224 $disp_viewname = $viewname; 225 } else { 226 $userName = getFullNameFromArray('Users', $cvrow); 227 $disp_viewname = $viewname . " [" . $userName . "] "; 228 } 229 230 231 if ($cvrow['setdefault'] == 1 && $viewid == '') { 232 $option = "<option $selected value=\"" . $cvrow['cvid'] . "\">" . $disp_viewname . "</option>"; 233 $this->setdefaultviewid = $cvrow['cvid']; 234 } elseif ($cvrow['cvid'] == $viewid) { 235 $option = "<option $selected value=\"" . $cvrow['cvid'] . "\">" . $disp_viewname . "</option>"; 236 $this->setdefaultviewid = $cvrow['cvid']; 237 } else { 238 $option = "<option value=\"" . $cvrow['cvid'] . "\">" . $disp_viewname . "</option>"; 239 } 240 241 // Add the option to combo box at appropriate section 242 if ($option != '') { 243 if ($cvrow['status'] == CV_STATUS_DEFAULT || $cvrow['userid'] == $current_user->id) { 244 $shtml_user .= $option; 245 } elseif ($cvrow['status'] == CV_STATUS_PUBLIC) { 246 if ($shtml_public == '') 247 $shtml_public = "<option disabled>--- " . $app_strings['LBL_PUBLIC'] . " ---</option>"; 248 $shtml_public .= $option; 249 } elseif ($cvrow['status'] == CV_STATUS_PENDING) { 250 if ($shtml_pending == '') 251 $shtml_pending = "<option disabled>--- " . $app_strings['LBL_PENDING'] . " ---</option>"; 252 $shtml_pending .= $option; 253 } else { 254 if ($shtml_others == '') 255 $shtml_others = "<option disabled>--- " . $app_strings['LBL_OTHERS'] . " ---</option>"; 256 $shtml_others .= $option; 257 } 258 } 259 } 260 $shtml = $shtml_user; 261 if ($is_admin == true) 262 $shtml .= $shtml_pending; 263 $shtml = $shtml . $shtml_public . $shtml_others; 264 return $shtml; 265 } 266 267 /** to get the getColumnsListbyBlock for the given module and Block 268 * @param $module :: Type String 269 * @param $block :: Type Integer 270 * @returns $columnlist Array in the format 271 * $columnlist = Array ($fieldlabel =>'$fieldtablename:$fieldcolname:$fieldname:$module_$fieldlabel1:$fieldtypeofdata', 272 $fieldlabel1 =>'$fieldtablename1:$fieldcolname1:$fieldname1:$module_$fieldlabel11:$fieldtypeofdata1', 273 | 274 $fieldlabeln =>'$fieldtablenamen:$fieldcolnamen:$fieldnamen:$module_$fieldlabel1n:$fieldtypeofdatan') 275 */ 276 function getColumnsListbyBlock($module, $block) { 277 global $adb, $mod_strings, $app_strings; 278 $block_ids = explode(",", $block); 279 $tabid = getTabid($module); 280 global $current_user; 281 require('user_privileges/user_privileges_' . $current_user->id . '.php'); 282 if (empty($this->meta) && $module != 'Calendar') { 283 $this->meta = $this->getMeta($module, $current_user); 284 } 285 if ($tabid == 9) 286 $tabid = "9,16"; 287 $display_type = " vtiger_field.displaytype in (1,2,3)"; 288 289 if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) { 290 $tab_ids = explode(",", $tabid); 291 $sql = "select * from vtiger_field "; 292 $sql.= " where vtiger_field.tabid in (" . generateQuestionMarks($tab_ids) . ") and vtiger_field.block in (" . generateQuestionMarks($block_ids) . ") and vtiger_field.presence in (0,2) and"; 293 $sql.= $display_type; 294 if ($tabid == 9 || $tabid == 16) { 295 $sql.= " and vtiger_field.fieldname not in('notime','duration_minutes','duration_hours')"; 296 } 297 $sql.= " order by sequence"; 298 $params = array($tab_ids, $block_ids); 299 } else { 300 $tab_ids = explode(",", $tabid); 301 $profileList = getCurrentUserProfileList(); 302 $sql = "select * from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid "; 303 $sql.= " where vtiger_field.tabid in (" . generateQuestionMarks($tab_ids) . ") and vtiger_field.block in (" . generateQuestionMarks($block_ids) . ") and"; 304 $sql.= "$display_type and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)"; 305 306 $params = array($tab_ids, $block_ids); 307 308 if (count($profileList) > 0) { 309 $sql.= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")"; 310 array_push($params, $profileList); 311 } 312 if ($tabid == 9 || $tabid == 16) { 313 $sql.= " and vtiger_field.fieldname not in('notime','duration_minutes','duration_hours')"; 314 } 315 316 $sql.= " group by columnname order by sequence"; 317 } 318 if ($tabid == '9,16') 319 $tabid = "9"; 320 $result = $adb->pquery($sql, $params); 321 $noofrows = $adb->num_rows($result); 322 //Added on 14-10-2005 -- added ticket id in list 323 if ($module == 'HelpDesk' && $block == 25) { 324 $module_columnlist['vtiger_crmentity:crmid::HelpDesk_Ticket_ID:I'] = 'Ticket ID'; 325 } 326 //Added to include vtiger_activity type in vtiger_activity vtiger_customview list 327 if ($module == 'Calendar' && $block == 19) { 328 $module_columnlist['vtiger_activity:activitytype:activitytype:Calendar_Activity_Type:V'] = 'Activity Type'; 329 } 330 331 if ($module == 'SalesOrder' && $block == 63) 332 $module_columnlist['vtiger_crmentity:crmid::SalesOrder_Order_No:I'] = $app_strings['Order No']; 333 334 if ($module == 'PurchaseOrder' && $block == 57) 335 $module_columnlist['vtiger_crmentity:crmid::PurchaseOrder_Order_No:I'] = $app_strings['Order No']; 336 337 if ($module == 'Quotes' && $block == 51) 338 $module_columnlist['vtiger_crmentity:crmid::Quotes_Quote_No:I'] = $app_strings['Quote No']; 339 if ($module != 'Calendar') { 340 $moduleFieldList = $this->meta->getModuleFields(); 341 } 342 for ($i = 0; $i < $noofrows; $i++) { 343 $fieldtablename = $adb->query_result($result, $i, "tablename"); 344 $fieldcolname = $adb->query_result($result, $i, "columnname"); 345 $fieldname = $adb->query_result($result, $i, "fieldname"); 346 $fieldtype = $adb->query_result($result, $i, "typeofdata"); 347 $fieldtype = explode("~", $fieldtype); 348 $fieldtypeofdata = $fieldtype[0]; 349 $fieldlabel = $adb->query_result($result, $i, "fieldlabel"); 350 $field = $moduleFieldList[$fieldname]; 351 if (!empty($field) && $field->getFieldDataType() == 'reference') { 352 $fieldtypeofdata = 'V'; 353 } else { 354 //Here we Changing the displaytype of the field. So that its criteria will be 355 //displayed Correctly in Custom view Advance Filter. 356 $fieldtypeofdata = ChangeTypeOfData_Filter($fieldtablename, $fieldcolname, $fieldtypeofdata); 357 } 358 if ($fieldlabel == "Start Date & Time") { 359 $fieldlabel = "Start Date"; 360 } 361 $fieldlabel1 = str_replace(" ", "_", $fieldlabel); 362 $optionvalue = $fieldtablename . ":" . $fieldcolname . ":" . $fieldname . ":" . $module . "_" . 363 $fieldlabel1 . ":" . $fieldtypeofdata; 364 //added to escape attachments fields in customview as we have multiple attachments 365 $fieldlabel = getTranslatedString($fieldlabel); //added to support i18n issue 366 if ($module != 'HelpDesk' || $fieldname != 'filename') 367 $module_columnlist[$optionvalue] = $fieldlabel; 368 if ($fieldtype[1] == "M") { 369 $this->mandatoryvalues[] = "'" . $optionvalue . "'"; 370 $this->showvalues[] = $fieldlabel; 371 $this->data_type[$fieldlabel] = $fieldtype[1]; 372 } 373 } 374 return $module_columnlist; 375 } 376 377 /** to get the getModuleColumnsList for the given module 378 * @param $module :: Type String 379 * @returns $ret_module_list Array in the following format 380 * $ret_module_list = 381 Array ('module' => 382 Array('BlockLabel1' => 383 Array('$fieldtablename:$fieldcolname:$fieldname:$module_$fieldlabel1:$fieldtypeofdata'=>$fieldlabel, 384 Array('$fieldtablename1:$fieldcolname1:$fieldname1:$module_$fieldlabel11:$fieldtypeofdata1'=>$fieldlabel1, 385 Array('BlockLabel2' => 386 Array('$fieldtablename:$fieldcolname:$fieldname:$module_$fieldlabel1:$fieldtypeofdata'=>$fieldlabel, 387 Array('$fieldtablename1:$fieldcolname1:$fieldname1:$module_$fieldlabel11:$fieldtypeofdata1'=>$fieldlabel1, 388 | 389 Array('BlockLabeln' => 390 Array('$fieldtablename:$fieldcolname:$fieldname:$module_$fieldlabel1:$fieldtypeofdata'=>$fieldlabel, 391 Array('$fieldtablename1:$fieldcolname1:$fieldname1:$module_$fieldlabel11:$fieldtypeofdata1'=>$fieldlabel1, 392 393 394 */ 395 function getModuleColumnsList($module) { 396 397 $module_info = $this->getCustomViewModuleInfo($module); 398 foreach ($this->module_list[$module] as $key => $value) { 399 $columnlist = $this->getColumnsListbyBlock($module, $value); 400 401 if (isset($columnlist)) { 402 $ret_module_list[$module][$key] = $columnlist; 403 } 404 } 405 return $ret_module_list; 406 } 407 408 /** to get the getModuleColumnsList for the given customview 409 * @param $cvid :: Type Integer 410 * @returns $columnlist Array in the following format 411 * $columnlist = Array( $columnindex => $columnname, 412 * $columnindex1 => $columnname1, 413 * | 414 * $columnindexn => $columnnamen) 415 */ 416 function getColumnsListByCvid($cvid) { 417 global $adb; 418 419 $sSQL = "select vtiger_cvcolumnlist.* from vtiger_cvcolumnlist"; 420 $sSQL .= " inner join vtiger_customview on vtiger_customview.cvid = vtiger_cvcolumnlist.cvid"; 421 $sSQL .= " where vtiger_customview.cvid =? order by vtiger_cvcolumnlist.columnindex"; 422 $result = $adb->pquery($sSQL, array($cvid)); 423 while ($columnrow = $adb->fetch_array($result)) { 424 $columnlist[$columnrow['columnindex']] = $columnrow['columnname']; 425 } 426 return $columnlist; 427 } 428 429 /** to get the standard filter fields or the given module 430 * @param $module :: Type String 431 * @returns $stdcriteria_list Array in the following format 432 * $stdcriteria_list = Array( $tablename:$columnname:$fieldname:$module_$fieldlabel => $fieldlabel, 433 * $tablename1:$columnname1:$fieldname1:$module_$fieldlabel1 => $fieldlabel1, 434 * | 435 * $tablenamen:$columnnamen:$fieldnamen:$module_$fieldlabeln => $fieldlabeln) 436 */ 437 function getStdCriteriaByModule($module) { 438 global $adb; 439 $tabid = getTabid($module); 440 441 global $current_user; 442 require('user_privileges/user_privileges_' . $current_user->id . '.php'); 443 444 $module_info = $this->getCustomViewModuleInfo($module); 445 foreach ($this->module_list[$module] as $key => $blockid) { 446 $blockids[] = $blockid; 447 } 448 449 if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) { 450 $sql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid "; 451 $sql.= " where vtiger_field.tabid=? and vtiger_field.block in (" . generateQuestionMarks($blockids) . ") 452 and vtiger_field.uitype in (5,6,23,70)"; 453 $sql.= " and vtiger_field.presence in (0,2) order by vtiger_field.sequence"; 454 $params = array($tabid, $blockids); 455 } else { 456 $profileList = getCurrentUserProfileList(); 457 $sql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid "; 458 $sql.= " where vtiger_field.tabid=? and vtiger_field.block in (" . generateQuestionMarks($blockids) . ") and vtiger_field.uitype in (5,6,23,70)"; 459 $sql.= " and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)"; 460 461 $params = array($tabid, $blockids); 462 463 if (count($profileList) > 0) { 464 $sql.= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")"; 465 array_push($params, $profileList); 466 } 467 468 $sql.= " order by vtiger_field.sequence"; 469 } 470 471 $result = $adb->pquery($sql, $params); 472 473 while ($criteriatyperow = $adb->fetch_array($result)) { 474 $fieldtablename = $criteriatyperow["tablename"]; 475 $fieldcolname = $criteriatyperow["columnname"]; 476 $fieldlabel = $criteriatyperow["fieldlabel"]; 477 $fieldname = $criteriatyperow["fieldname"]; 478 $fieldlabel1 = str_replace(" ", "_", $fieldlabel); 479 $optionvalue = $fieldtablename . ":" . $fieldcolname . ":" . $fieldname . ":" . $module . "_" . $fieldlabel1; 480 $stdcriteria_list[$optionvalue] = $fieldlabel; 481 } 482 483 return $stdcriteria_list; 484 } 485 486 /** 487 * Function which will give condition list for date fields 488 * @return array of std filter conditions 489 */ 490 function getStdFilterConditions() { 491 return Array("custom","prevfy" ,"thisfy" ,"nextfy","prevfq", 492 "thisfq","nextfq","yesterday","today","tomorrow", 493 "lastweek","thisweek","nextweek","lastmonth","thismonth", 494 "nextmonth","last7days","last30days","last60days","last90days", 495 "last120days","next30days","next60days","next90days","next120days", 496 ); 497 } 498 499 /** to get the standard filter criteria 500 * @param $selcriteria :: Type String (optional) 501 * @returns $filter Array in the following format 502 * $filter = Array( 0 => array('value'=>$filterkey,'text'=>$mod_strings[$filterkey],'selected'=>$selected) 503 * 1 => array('value'=>$filterkey1,'text'=>$mod_strings[$filterkey1],'selected'=>$selected) 504 * | 505 * n => array('value'=>$filterkeyn,'text'=>$mod_strings[$filterkeyn],'selected'=>$selected) 506 */ 507 function getStdFilterCriteria($selcriteria = "") { 508 global $mod_strings; 509 $filter = array(); 510 511 $stdfilter = Array("custom" => "" . $mod_strings['Custom'] . "", 512 "prevfy" => "" . $mod_strings['Previous FY'] . "", 513 "thisfy" => "" . $mod_strings['Current FY'] . "", 514 "nextfy" => "" . $mod_strings['Next FY'] . "", 515 "prevfq" => "" . $mod_strings['Previous FQ'] . "", 516 "thisfq" => "" . $mod_strings['Current FQ'] . "", 517 "nextfq" => "" . $mod_strings['Next FQ'] . "", 518 "yesterday" => "" . $mod_strings['Yesterday'] . "", 519 "today" => "" . $mod_strings['Today'] . "", 520 "tomorrow" => "" . $mod_strings['Tomorrow'] . "", 521 "lastweek" => "" . $mod_strings['Last Week'] . "", 522 "thisweek" => "" . $mod_strings['Current Week'] . "", 523 "nextweek" => "" . $mod_strings['Next Week'] . "", 524 "lastmonth" => "" . $mod_strings['Last Month'] . "", 525 "thismonth" => "" . $mod_strings['Current Month'] . "", 526 "nextmonth" => "" . $mod_strings['Next Month'] . "", 527 "last7days" => "" . $mod_strings['Last 7 Days'] . "", 528 "last30days" => "" . $mod_strings['Last 30 Days'] . "", 529 "last60days" => "" . $mod_strings['Last 60 Days'] . "", 530 "last90days" => "" . $mod_strings['Last 90 Days'] . "", 531 "last120days" => "" . $mod_strings['Last 120 Days'] . "", 532 "next30days" => "" . $mod_strings['Next 30 Days'] . "", 533 "next60days" => "" . $mod_strings['Next 60 Days'] . "", 534 "next90days" => "" . $mod_strings['Next 90 Days'] . "", 535 "next120days" => "" . $mod_strings['Next 120 Days'] . "", 536 ); 537 538 foreach ($stdfilter as $FilterKey => $FilterValue) { 539 if ($FilterKey == $selcriteria) { 540 $shtml['value'] = $FilterKey; 541 $shtml['text'] = $FilterValue; 542 $shtml['selected'] = "selected"; 543 } else { 544 $shtml['value'] = $FilterKey; 545 $shtml['text'] = $FilterValue; 546 $shtml['selected'] = ""; 547 } 548 $filter[] = $shtml; 549 } 550 return $filter; 551 } 552 553 /** to get the standard filter criteria scripts 554 * @returns $jsStr : Type String 555 * This function will return the script to set the start data and end date 556 * for the standard selection criteria 557 */ 558 function getCriteriaJS() { 559 560 $todayDateTime = new DateTimeField(date('Y-m-d H:i:s')); 561 562 $tomorrow = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))); 563 $tomorrowDateTime = new DateTimeField($tomorrow . ' ' . date('H:i:s')); 564 565 $yesterday = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 1, date("Y"))); 566 $yesterdayDateTime = new DateTimeField($yesterday . ' ' . date('H:i:s')); 567 568 $currentmonth0 = date("Y-m-d", mktime(0, 0, 0, date("m"), "01", date("Y"))); 569 $currentMonthStartDateTime = new DateTimeField($currentmonth0 . ' ' . date('H:i:s')); 570 $currentmonth1 = date("Y-m-t"); 571 $currentMonthEndDateTime = new DateTimeField($currentmonth1 . ' ' . date('H:i:s')); 572 573 $lastmonth0 = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, "01", date("Y"))); 574 $lastMonthStartDateTime = new DateTimeField($lastmonth0 . ' ' . date('H:i:s')); 575 $lastmonth1 = date("Y-m-t", strtotime("last day of previous month")); 576 $lastMonthEndDateTime = new DateTimeField($lastmonth1 . ' ' . date('H:i:s')); 577 578 $nextmonth0 = date("Y-m-d", mktime(0, 0, 0, date("m") + 1, "01", date("Y"))); 579 $nextMonthStartDateTime = new DateTimeField($nextmonth0 . ' ' . date('H:i:s')); 580 $nextmonth1 = date("Y-m-t", strtotime("last day of next month")); 581 $nextMonthEndDateTime = new DateTimeField($nextmonth1 . ' ' . date('H:i:s')); 582 583 $lastweek0 = date("Y-m-d", strtotime("-2 week Sunday")); 584 $lastWeekStartDateTime = new DateTimeField($lastweek0 . ' ' . date('H:i:s')); 585 $lastweek1 = date("Y-m-d", strtotime("-1 week Saturday")); 586 $lastWeekEndDateTime = new DateTimeField($lastweek1 . ' ' . date('H:i:s')); 587 588 $thisweek0 = date("Y-m-d", strtotime("-1 week Sunday")); 589 $thisWeekStartDateTime = new DateTimeField($thisweek0 . ' ' . date('H:i:s')); 590 $thisweek1 = date("Y-m-d", strtotime("this Saturday")); 591 $thisWeekEndDateTime = new DateTimeField($thisweek1 . ' ' . date('H:i:s')); 592 593 $nextweek0 = date("Y-m-d", strtotime("this Sunday")); 594 $nextWeekStartDateTime = new DateTimeField($nextweek0 . ' ' . date('H:i:s')); 595 $nextweek1 = date("Y-m-d", strtotime("+1 week Saturday")); 596 $nextWeekEndDateTime = new DateTimeField($nextweek1 . ' ' . date('H:i:s')); 597 598 $next7days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 6, date("Y"))); 599 $next7DaysDateTime = new DateTimeField($next7days . ' ' . date('H:i:s')); 600 601 $next30days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 29, date("Y"))); 602 $next30DaysDateTime = new DateTimeField($next30days . ' ' . date('H:i:s')); 603 604 $next60days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 59, date("Y"))); 605 $next60DaysDateTime = new DateTimeField($next60days . ' ' . date('H:i:s')); 606 607 $next90days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 89, date("Y"))); 608 $next90DaysDateTime = new DateTimeField($next90days . ' ' . date('H:i:s')); 609 610 $next120days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 119, date("Y"))); 611 $next120DaysDateTime = new DateTimeField($next120days . ' ' . date('H:i:s')); 612 613 $last7days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 6, date("Y"))); 614 $last7DaysDateTime = new DateTimeField($last7days . ' ' . date('H:i:s')); 615 616 $last30days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 29, date("Y"))); 617 $last30DaysDateTime = new DateTimeField($last30days . ' ' . date('H:i:s')); 618 619 $last60days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 59, date("Y"))); 620 $last60DaysDateTime = new DateTimeField($last60days . ' ' . date('H:i:s')); 621 622 $last90days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 89, date("Y"))); 623 $last90DaysDateTime = new DateTimeField($last90days . ' ' . date('H:i:s')); 624 625 $last120days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 119, date("Y"))); 626 $last120DaysDateTime = new DateTimeField($last120days . ' ' . date('H:i:s')); 627 628 $currentFY0 = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y"))); 629 $currentFYStartDateTime = new DateTimeField($currentFY0 . ' ' . date('H:i:s')); 630 $currentFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y"))); 631 $currentFYEndDateTime = new DateTimeField($currentFY1 . ' ' . date('H:i:s')); 632 633 $lastFY0 = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y") - 1)); 634 $lastFYStartDateTime = new DateTimeField($lastFY0 . ' ' . date('H:i:s')); 635 $lastFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y") - 1)); 636 $lastFYEndDateTime = new DateTimeField($lastFY1 . ' ' . date('H:i:s')); 637 638 $nextFY0 = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y") + 1)); 639 $nextFYStartDateTime = new DateTimeField($nextFY0 . ' ' . date('H:i:s')); 640 $nextFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y") + 1)); 641 $nextFYEndDateTime = new DateTimeField($nextFY1 . ' ' . date('H:i:s')); 642 643 if (date("m") <= 3) { 644 $cFq = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y"))); 645 $cFqStartDateTime = new DateTimeField($cFq . ' ' . date('H:i:s')); 646 $cFq1 = date("Y-m-d", mktime(0, 0, 0, "03", "31", date("Y"))); 647 $cFqEndDateTime = new DateTimeField($cFq1 . ' ' . date('H:i:s')); 648 649 $nFq = date("Y-m-d", mktime(0, 0, 0, "04", "01", date("Y"))); 650 $nFqStartDateTime = new DateTimeField($nFq . ' ' . date('H:i:s')); 651 $nFq1 = date("Y-m-d", mktime(0, 0, 0, "06", "30", date("Y"))); 652 $nFqEndDateTime = new DateTimeField($nFq1 . ' ' . date('H:i:s')); 653 654 $pFq = date("Y-m-d", mktime(0, 0, 0, "10", "01", date("Y") - 1)); 655 $pFqStartDateTime = new DateTimeField($pFq . ' ' . date('H:i:s')); 656 $pFq1 = date("Y-m-d", mktime(0, 0, 0, "12", "31", date("Y") - 1)); 657 $pFqEndDateTime = new DateTimeField($pFq1 . ' ' . date('H:i:s')); 658 } else if (date("m") > 3 and date("m") <= 6) { 659 660 $pFq = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y"))); 661 $pFqStartDateTime = new DateTimeField($pFq . ' ' . date('H:i:s')); 662 $pFq1 = date("Y-m-d", mktime(0, 0, 0, "03", "31", date("Y"))); 663 $pFqEndDateTime = new DateTimeField($pFq1 . ' ' . date('H:i:s')); 664 665 $cFq = date("Y-m-d", mktime(0, 0, 0, "04", "01", date("Y"))); 666 $cFqStartDateTime = new DateTimeField($cFq . ' ' . date('H:i:s')); 667 $cFq1 = date("Y-m-d", mktime(0, 0, 0, "06", "30", date("Y"))); 668 $cFqEndDateTime = new DateTimeField($cFq1 . ' ' . date('H:i:s')); 669 670 $nFq = date("Y-m-d", mktime(0, 0, 0, "07", "01", date("Y"))); 671 $nFqStartDateTime = new DateTimeField($nFq . ' ' . date('H:i:s')); 672 $nFq1 = date("Y-m-d", mktime(0, 0, 0, "09", "30", date("Y"))); 673 $nFqEndDateTime = new DateTimeField($nFq1 . ' ' . date('H:i:s')); 674 } else if (date("m") > 6 and date("m") <= 9) { 675 676 $nFq = date("Y-m-d", mktime(0, 0, 0, "10", "01", date("Y"))); 677 $nFqStartDateTime = new DateTimeField($nFq . ' ' . date('H:i:s')); 678 $nFq1 = date("Y-m-d", mktime(0, 0, 0, "12", "31", date("Y"))); 679 $nFqEndDateTime = new DateTimeField($nFq1 . ' ' . date('H:i:s')); 680 681 $pFq = date("Y-m-d", mktime(0, 0, 0, "04", "01", date("Y"))); 682 $pFqStartDateTime = new DateTimeField($pFq . ' ' . date('H:i:s')); 683 $pFq1 = date("Y-m-d", mktime(0, 0, 0, "06", "30", date("Y"))); 684 $pFqEndDateTime = new DateTimeField($pFq1 . ' ' . date('H:i:s')); 685 686 $cFq = date("Y-m-d", mktime(0, 0, 0, "07", "01", date("Y"))); 687 $cFqStartDateTime = new DateTimeField($cFq . ' ' . date('H:i:s')); 688 $cFq1 = date("Y-m-d", mktime(0, 0, 0, "09", "30", date("Y"))); 689 $cFqEndDateTime = new DateTimeField($cFq1 . ' ' . date('H:i:s')); 690 } else if (date("m") > 9 and date("m") <= 12) { 691 $nFq = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y") + 1)); 692 $nFqStartDateTime = new DateTimeField($nFq . ' ' . date('H:i:s')); 693 $nFq1 = date("Y-m-d", mktime(0, 0, 0, "03", "31", date("Y") + 1)); 694 $nFqEndDateTime = new DateTimeField($nFq1 . ' ' . date('H:i:s')); 695 696 $pFq = date("Y-m-d", mktime(0, 0, 0, "07", "01", date("Y"))); 697 $pFqStartDateTime = new DateTimeField($pFq . ' ' . date('H:i:s')); 698 $pFq1 = date("Y-m-d", mktime(0, 0, 0, "09", "30", date("Y"))); 699 $pFqEndDateTime = new DateTimeField($pFq1 . ' ' . date('H:i:s')); 700 701 $cFq = date("Y-m-d", mktime(0, 0, 0, "10", "01", date("Y"))); 702 $cFqStartDateTime = new DateTimeField($cFq . ' ' . date('H:i:s')); 703 $cFq1 = date("Y-m-d", mktime(0, 0, 0, "12", "31", date("Y"))); 704 $cFqEndDateTime = new DateTimeField($cFq1 . ' ' . date('H:i:s')); 705 } 706 707 $sjsStr = '<script language="JavaScript" type="text/javaScript"> 708 function showDateRange( type ) { 709 if (type!="custom") { 710 document.CustomView.startdate.readOnly=true 711 document.CustomView.enddate.readOnly=true 712 getObj("jscal_trigger_date_start").style.visibility="hidden" 713 getObj("jscal_trigger_date_end").style.visibility="hidden" 714 } else { 715 document.CustomView.startdate.readOnly=false 716 document.CustomView.enddate.readOnly=false 717 getObj("jscal_trigger_date_start").style.visibility="visible" 718 getObj("jscal_trigger_date_end").style.visibility="visible" 719 } 720 if( type == "today" ) { 721 document.CustomView.startdate.value = "' . $todayDateTime->getDisplayDate() . '"; 722 document.CustomView.enddate.value = "' . $todayDateTime->getDisplayDate() . '"; 723 724 } else if( type == "yesterday" ) { 725 document.CustomView.startdate.value = "' . $yesterdayDateTime->getDisplayDate() . '"; 726 document.CustomView.enddate.value = "' . $yesterdayDateTime->getDisplayDate() . '"; 727 728 } else if( type == "tomorrow" ) { 729 document.CustomView.startdate.value = "' . $tomorrowDateTime->getDisplayDate() . '"; 730 document.CustomView.enddate.value = "' . $tomorrowDateTime->getDisplayDate() . '"; 731 732 } else if( type == "thisweek" ) { 733 document.CustomView.startdate.value = "' . $thisWeekStartDateTime->getDisplayDate() . '"; 734 document.CustomView.enddate.value = "' . $thisWeekEndDateTime->getDisplayDate() . '"; 735 736 } else if( type == "lastweek" ) { 737 document.CustomView.startdate.value = "' . $lastWeekStartDateTime->getDisplayDate() . '"; 738 document.CustomView.enddate.value = "' . $lastWeekEndDateTime->getDisplayDate() . '"; 739 740 } else if( type == "nextweek" ) { 741 document.CustomView.startdate.value = "' . $nextWeekStartDateTime->getDisplayDate() . '"; 742 document.CustomView.enddate.value = "' . $nextWeekEndDateTime->getDisplayDate() . '"; 743 744 } else if( type == "thismonth" ) { 745 document.CustomView.startdate.value = "' . $currentMonthStartDateTime->getDisplayDate() . '"; 746 document.CustomView.enddate.value = "' . $currentMonthEndDateTime->getDisplayDate() . '"; 747 748 } else if( type == "lastmonth" ) { 749 document.CustomView.startdate.value = "' . $lastMonthStartDateTime->getDisplayDate() . '"; 750 document.CustomView.enddate.value = "' . $lastMonthEndDateTime->getDisplayDate() . '"; 751 752 } else if( type == "nextmonth" ) { 753 document.CustomView.startdate.value = "' . $nextMonthStartDateTime->getDisplayDate() . '"; 754 document.CustomView.enddate.value = "' . $nextMonthEndDateTime->getDisplayDate() . '"; 755 756 } else if( type == "next7days" ) { 757 document.CustomView.startdate.value = "' . $todayDateTime->getDisplayDate() . '"; 758 document.CustomView.enddate.value = "' . $next7DaysDateTime->getDisplayDate() . '"; 759 760 } else if( type == "next30days" ) { 761 document.CustomView.startdate.value = "' . $todayDateTime->getDisplayDate() . '"; 762 document.CustomView.enddate.value = "' . $next30DaysDateTime->getDisplayDate() . '"; 763 764 } else if( type == "next60days" ) { 765 document.CustomView.startdate.value = "' . $todayDateTime->getDisplayDate() . '"; 766 document.CustomView.enddate.value = "' . $next60DaysDateTime->getDisplayDate() . '"; 767 768 } else if( type == "next90days" ) { 769 document.CustomView.startdate.value = "' . $todayDateTime->getDisplayDate() . '"; 770 document.CustomView.enddate.value = "' . $next90DaysDateTime->getDisplayDate() . '"; 771 772 } else if( type == "next120days" ) { 773 document.CustomView.startdate.value = "' . $todayDateTime->getDisplayDate() . '"; 774 document.CustomView.enddate.value = "' . $next120DaysDateTime->getDisplayDate() . '"; 775 776 } else if( type == "last7days" ) { 777 document.CustomView.startdate.value = "' . $last7DaysDateTime->getDisplayDate() . '"; 778 document.CustomView.enddate.value = "' . $todayDateTime->getDisplayDate() . '"; 779 780 } else if( type == "last30days" ) { 781 document.CustomView.startdate.value = "' . $last30DaysDateTime->getDisplayDate() . '"; 782 document.CustomView.enddate.value = "' . $todayDateTime->getDisplayDate() . '"; 783 784 } else if( type == "last60days" ) { 785 document.CustomView.startdate.value = "' . $last60DaysDateTime->getDisplayDate() . '"; 786 document.CustomView.enddate.value = "' . $todayDateTime->getDisplayDate() . '"; 787 788 } else if( type == "last90days" ) { 789 document.CustomView.startdate.value = "' . $last90DaysDateTime->getDisplayDate() . '"; 790 document.CustomView.enddate.value = "' . $todayDateTime->getDisplayDate() . '"; 791 792 } else if( type == "last120days" ) { 793 document.CustomView.startdate.value = "' . $last120DaysDateTime->getDisplayDate() . '"; 794 document.CustomView.enddate.value = "' . $todayDateTime->getDisplayDate() . '"; 795 796 } else if( type == "thisfy" ) { 797 document.CustomView.startdate.value = "' . $currentFYStartDateTime->getDisplayDate() . '"; 798 document.CustomView.enddate.value = "' . $currentFYEndDateTime->getDisplayDate() . '"; 799 800 } else if( type == "prevfy" ) { 801 document.CustomView.startdate.value = "' . $lastFYStartDateTime->getDisplayDate() . '"; 802 document.CustomView.enddate.value = "' . $lastFYEndDateTime->getDisplayDate() . '"; 803 804 } else if( type == "nextfy" ) { 805 document.CustomView.startdate.value = "' . $nextFYStartDateTime->getDisplayDate() . '"; 806 document.CustomView.enddate.value = "' . $nextFYEndDateTime->getDisplayDate() . '"; 807 808 } else if( type == "nextfq" ) { 809 document.CustomView.startdate.value = "' . $nFqStartDateTime->getDisplayDate() . '"; 810 document.CustomView.enddate.value = "' . $nFqEndDateTime->getDisplayDate() . '"; 811 812 } else if( type == "prevfq" ) { 813 document.CustomView.startdate.value = "' . $pFqStartDateTime->getDisplayDate() . '"; 814 document.CustomView.enddate.value = "' . $pFqEndDateTime->getDisplayDate() . '"; 815 816 } else if( type == "thisfq" ) { 817 document.CustomView.startdate.value = "' . $cFqStartDateTime->getDisplayDate() . '"; 818 document.CustomView.enddate.value = "' . $cFqEndDateTime->getDisplayDate() . '"; 819 820 } else { 821 document.CustomView.startdate.value = ""; 822 document.CustomView.enddate.value = ""; 823 } 824 } 825 </script>'; 826 827 return $sjsStr; 828 } 829 830 /** to get the standard filter for the given customview Id 831 * @param $cvid :: Type Integer 832 * @returns $stdfilterlist Array in the following format 833 * $stdfilterlist = Array( 'columnname' => $tablename:$columnname:$fieldname:$module_$fieldlabel,'stdfilter'=>$stdfilter,'startdate'=>$startdate,'enddate'=>$enddate) 834 */ 835 function getStdFilterByCvid($cvid) { 836 global $adb; 837 838 $sSQL = "select vtiger_cvstdfilter.* from vtiger_cvstdfilter inner join vtiger_customview on vtiger_customview.cvid = vtiger_cvstdfilter.cvid"; 839 $sSQL .= " where vtiger_cvstdfilter.cvid=?"; 840 841 $result = $adb->pquery($sSQL, array($cvid)); 842 $stdfilterrow = $adb->fetch_array($result); 843 return $this->resolveDateFilterValue($stdfilterrow); 844 } 845 846 function resolveDateFilterValue ($dateFilterRow) { 847 $stdfilterlist = array(); 848 $stdfilterlist["columnname"] = $dateFilterRow["columnname"]; 849 $stdfilterlist["stdfilter"] = $dateFilterRow["stdfilter"]; 850 851 if ($dateFilterRow["stdfilter"] == "custom" || $dateFilterRow["stdfilter"] == "" || $dateFilterRow["stdfilter"] == "e" || $dateFilterRow["stdfilter"] == "n") { 852 if ($dateFilterRow["startdate"] != "0000-00-00" && $dateFilterRow["startdate"] != "") { 853 $startDateTime = new DateTimeField($dateFilterRow["startdate"] . ' ' . date('H:i:s')); 854 $stdfilterlist["startdate"] = $startDateTime->getDisplayDate(); 855 } 856 if ($dateFilterRow["enddate"] != "0000-00-00" && $dateFilterRow["enddate"] != "") { 857 $endDateTime = new DateTimeField($dateFilterRow["enddate"] . ' ' . date('H:i:s')); 858 $stdfilterlist["enddate"] = $endDateTime->getDisplayDate(); 859 } 860 } else { //if it is not custom get the date according to the selected duration 861 $datefilter = $this->getDateforStdFilterBytype($dateFilterRow["stdfilter"]); 862 $startDateTime = new DateTimeField($datefilter[0] . ' ' . date('H:i:s')); 863 $stdfilterlist["startdate"] = $startDateTime->getDisplayDate(); 864 $endDateTime = new DateTimeField($datefilter[1] . ' ' . date('H:i:s')); 865 $stdfilterlist["enddate"] = $endDateTime->getDisplayDate(); 866 } 867 return $stdfilterlist; 868 } 869 870 /** to get the Advanced filter for the given customview Id 871 * @param $cvid :: Type Integer 872 * @returns $advfilterlist Array 873 */ 874 function getAdvFilterByCvid($cvid) { 875 876 global $adb, $log, $default_charset; 877 878 $advft_criteria = array(); 879 880 $sql = 'SELECT * FROM vtiger_cvadvfilter_grouping WHERE cvid = ? ORDER BY groupid'; 881 $groupsresult = $adb->pquery($sql, array($cvid)); 882 883 $i = 1; 884 $j = 0; 885 while ($relcriteriagroup = $adb->fetch_array($groupsresult)) { 886 $groupId = $relcriteriagroup["groupid"]; 887 $groupCondition = $relcriteriagroup["group_condition"]; 888 889 $ssql = 'select vtiger_cvadvfilter.* from vtiger_customview 890 inner join vtiger_cvadvfilter on vtiger_cvadvfilter.cvid = vtiger_customview.cvid 891 left join vtiger_cvadvfilter_grouping on vtiger_cvadvfilter.cvid = vtiger_cvadvfilter_grouping.cvid 892 and vtiger_cvadvfilter.groupid = vtiger_cvadvfilter_grouping.groupid'; 893 $ssql.= " where vtiger_customview.cvid = ? AND vtiger_cvadvfilter.groupid = ? order by vtiger_cvadvfilter.columnindex"; 894 895 $result = $adb->pquery($ssql, array($cvid, $groupId)); 896 $noOfColumns = $adb->num_rows($result); 897 if ($noOfColumns <= 0) 898 continue; 899 900 while ($relcriteriarow = $adb->fetch_array($result)) { 901 $columnIndex = $relcriteriarow["columnindex"]; 902 $criteria = array(); 903 $criteria['columnname'] = html_entity_decode($relcriteriarow["columnname"], ENT_QUOTES, $default_charset); 904 $criteria['comparator'] = $relcriteriarow["comparator"]; 905 $advfilterval = html_entity_decode($relcriteriarow["value"], ENT_QUOTES, $default_charset); 906 $col = explode(":", $relcriteriarow["columnname"]); 907 $temp_val = explode(",", $relcriteriarow["value"]); 908 if ($col[4] == 'D' || ($col[4] == 'T' && $col[1] != 'time_start' && $col[1] != 'time_end') || ($col[4] == 'DT')) { 909 $val = Array(); 910 for ($x = 0; $x < count($temp_val); $x++) { 911 if ($col[4] == 'D') { 912 /** while inserting in db for due_date it was taking date and time values also as it is 913 * date time field. We only need to take date from that value 914 */ 915 if($col[0] == "vtiger_activity" && $col[1] == "due_date" ){ 916 $values = explode(' ', $temp_val[$x]); 917 $temp_val[$x] = $values[0]; 918 } 919 $date = new DateTimeField(trim($temp_val[$x])); 920 $val[$x] = $date->getDisplayDate(); 921 } elseif ($col[4] == 'DT') { 922 $comparator = array('e','n','b','a'); 923 if(in_array($criteria['comparator'], $comparator)) { 924 $originalValue = $temp_val[$x]; 925 $dateTime = explode(' ',$originalValue); 926 $temp_val[$x] = $dateTime[0]; 927 } 928 $date = new DateTimeField(trim($temp_val[$x])); 929 $val[$x] = $date->getDisplayDateTimeValue(); 930 } else { 931 $date = new DateTimeField(trim($temp_val[$x])); 932 $val[$x] = $date->getDisplayTime(); 933 } 934 } 935 $advfilterval = implode(",", $val); 936 } 937 $criteria['value'] = $advfilterval; 938 $criteria['column_condition'] = $relcriteriarow["column_condition"]; 939 940 $advft_criteria[$i]['columns'][$j] = $criteria; 941 $advft_criteria[$i]['condition'] = $groupCondition; 942 $j++; 943 } 944 if (!empty($advft_criteria[$i]['columns'][$j - 1]['column_condition'])) { 945 $advft_criteria[$i]['columns'][$j - 1]['column_condition'] = ''; 946 } 947 $i++; 948 } 949 // Clear the condition (and/or) for last group, if any. 950 if (!empty($advft_criteria[$i - 1]['condition'])) 951 $advft_criteria[$i - 1]['condition'] = ''; 952 return $advft_criteria; 953 } 954 955 /** 956 * Cache information to perform re-lookups 957 * 958 * @var String 959 */ 960 protected $_fieldby_tblcol_cache = array(); 961 962 /** 963 * Function to check if field is present based on 964 * 965 * @param String $columnname 966 * @param String $tablename 967 */ 968 function isFieldPresent_ByColumnTable($columnname, $tablename) { 969 global $adb; 970 971 if (!isset($this->_fieldby_tblcol_cache[$tablename])) { 972 $query = 'SELECT columnname FROM vtiger_field WHERE tablename = ? and presence in (0,2)'; 973 974 $result = $adb->pquery($query, array($tablename)); 975 $numrows = $adb->num_rows($result); 976 977 if ($numrows) { 978 $this->_fieldby_tblcol_cache[$tablename] = array(); 979 for ($index = 0; $index < $numrows; ++$index) { 980 $this->_fieldby_tblcol_cache[$tablename][] = $adb->query_result($result, $index, 'columnname'); 981 } 982 } 983 } 984 // If still the field was not found (might be disabled or deleted?) 985 if (!isset($this->_fieldby_tblcol_cache[$tablename])) { 986 return false; 987 } 988 return in_array($columnname, $this->_fieldby_tblcol_cache[$tablename]); 989 } 990 991 /** to get the customview Columnlist Query for the given customview Id 992 * @param $cvid :: Type Integer 993 * @returns $getCvColumnList as a string 994 * This function will return the columns for the given customfield in comma seperated values in the format 995 * $tablename.$columnname,$tablename1.$columnname1, ------ $tablenamen.$columnnamen 996 * 997 */ 998 function getCvColumnListSQL($cvid) { 999 global $adb; 1000 $columnslist = $this->getColumnsListByCvid($cvid); 1001 if (isset($columnslist)) { 1002 foreach ($columnslist as $columnname => $value) { 1003 $tablefield = ""; 1004 if ($value != "") { 1005 $list = explode(":", $value); 1006 1007 //Added For getting status for Activities -Jaguar 1008 $sqllist_column = $list[0] . "." . $list[1]; 1009 if ($this->customviewmodule == "Calendar") { 1010 if ($list[1] == "status" || $list[1] == "eventstatus") { 1011 $sqllist_column = "case when (vtiger_activity.status not like '') then vtiger_activity.status else vtiger_activity.eventstatus end as activitystatus"; 1012 } 1013 } 1014 //Added for assigned to sorting 1015 if ($list[1] == "smownerid") { 1016 $userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 1017 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); 1018 $sqllist_column = "case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name"; 1019 } 1020 if ($list[0] == "vtiger_contactdetails" && $list[1] == "lastname") 1021 $sqllist_column = "vtiger_contactdetails.lastname,vtiger_contactdetails.firstname"; 1022 $sqllist[] = $sqllist_column; 1023 //Ends 1024 1025 $tablefield[$list[0]] = $list[1]; 1026 1027 //Changed as the replace of module name may replace the string if the fieldname has module name in it -- Jeri 1028 $fieldinfo = explode('_', $list[3], 2); 1029 $fieldlabel = $fieldinfo[1]; 1030 $fieldlabel = str_replace("_", " ", $fieldlabel); 1031 1032 if ($this->isFieldPresent_ByColumnTable($list[1], $list[0])) { 1033 1034 $this->list_fields[$fieldlabel] = $tablefield; 1035 $this->list_fields_name[$fieldlabel] = $list[2]; 1036 } 1037 } 1038 } 1039 $returnsql = implode(",", $sqllist); 1040 } 1041 return $returnsql; 1042 } 1043 1044 /** to get the customview stdFilter Query for the given customview Id 1045 * @param $cvid :: Type Integer 1046 * @returns $stdfiltersql as a string 1047 * This function will return the standard filter criteria for the given customfield 1048 * 1049 */ 1050 function getCVStdFilterSQL($cvid) { 1051 global $adb; 1052 1053 $stdfiltersql = ''; 1054 $stdfilterlist = array(); 1055 1056 $sSQL = "select vtiger_cvstdfilter.* from vtiger_cvstdfilter inner join vtiger_customview on vtiger_customview.cvid = vtiger_cvstdfilter.cvid"; 1057 $sSQL .= " where vtiger_cvstdfilter.cvid=?"; 1058 1059 $result = $adb->pquery($sSQL, array($cvid)); 1060 $stdfilterrow = $adb->fetch_array($result); 1061 1062 $stdfilterlist = array(); 1063 $stdfilterlist["columnname"] = $stdfilterrow["columnname"]; 1064 $stdfilterlist["stdfilter"] = $stdfilterrow["stdfilter"]; 1065 1066 if ($stdfilterrow["stdfilter"] == "custom" || $stdfilterrow["stdfilter"] == "") { 1067 if ($stdfilterrow["startdate"] != "0000-00-00" && $stdfilterrow["startdate"] != "") { 1068 $stdfilterlist["startdate"] = $stdfilterrow["startdate"]; 1069 } 1070 if ($stdfilterrow["enddate"] != "0000-00-00" && $stdfilterrow["enddate"] != "") { 1071 $stdfilterlist["enddate"] = $stdfilterrow["enddate"]; 1072 } 1073 } else { //if it is not custom get the date according to the selected duration 1074 $datefilter = $this->getDateforStdFilterBytype($stdfilterrow["stdfilter"]); 1075 $stdfilterlist["startdate"] = $datefilter[0]; 1076 $stdfilterlist["enddate"] = $datefilter[1]; 1077 } 1078 1079 if (isset($stdfilterlist)) { 1080 1081 foreach ($stdfilterlist as $columnname => $value) { 1082 1083 if ($columnname == "columnname") { 1084 $filtercolumn = $value; 1085 } elseif ($columnname == "stdfilter") { 1086 $filtertype = $value; 1087 } elseif ($columnname == "startdate") { 1088 $startDateTime = new DateTimeField($value . ' ' . date('H:i:s')); 1089 $userStartDate = $startDateTime->getDisplayDate(); 1090 $userStartDateTime = new DateTimeField($userStartDate . ' 00:00:00'); 1091 $startDateTime = $userStartDateTime->getDBInsertDateTimeValue(); 1092 } elseif ($columnname == "enddate") { 1093 $endDateTime = new DateTimeField($value . ' ' . date('H:i:s')); 1094 $userEndDate = $endDateTime->getDisplayDate(); 1095 $userEndDateTime = new DateTimeField($userEndDate . ' 23:59:00'); 1096 $endDateTime = $userEndDateTime->getDBInsertDateTimeValue(); 1097 } 1098 if ($startDateTime != "" && $endDateTime != "") { 1099 $columns = explode(":", $filtercolumn); 1100 // Fix for http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/5423 1101 if ($columns[1] == 'birthday') { 1102 $tableColumnSql = "DATE_FORMAT(" . $columns[0] . "." . $columns[1] . ", '%m%d')"; 1103 $startDateTime = "DATE_FORMAT('$startDate', '%m%d')"; 1104 $endDateTime = "DATE_FORMAT('$endDate', '%m%d')"; 1105 $stdfiltersql = $tableColumnSql . " BETWEEN " . $startDateTime . " and " . $endDateTime; 1106 } else { 1107 if ($this->customviewmodule == 'Calendar' && ($columns[1] == 'date_start' || $columns[1] == 'due_date')) { 1108 $tableColumnSql = ''; 1109 if ($columns[1] == 'date_start') { 1110 $tableColumnSql = "CAST((CONCAT(date_start,' ',time_start)) AS DATETIME)"; 1111 } else { 1112 $tableColumnSql = "CAST((CONCAT(due_date,' ',time_end)) AS DATETIME)"; 1113 } 1114 } else { 1115 $tableColumnSql = $columns[0] . "." . $columns[1]; 1116 } 1117 $stdfiltersql = $tableColumnSql . " BETWEEN '" . $startDateTime . "' and '" . $endDateTime . "'"; 1118 } 1119 } 1120 } 1121 } 1122 return $stdfiltersql; 1123 } 1124 1125 /** to get the customview AdvancedFilter Query for the given customview Id 1126 * @param $cvid :: Type Integer 1127 * @returns $advfiltersql as a string 1128 * This function will return the advanced filter criteria for the given customfield 1129 * 1130 */ 1131 // Needs to be modified according to the new advanced filter (support for grouping). 1132 // Not modified as of now, as this function is not used for now (Instead Query Generator is used for better performance). 1133 function getCVAdvFilterSQL($cvid) { 1134 global $current_user; 1135 1136 $advfilter = $this->getAdvFilterByCvid($cvid); 1137 1138 $advcvsql = ""; 1139 1140 foreach ($advfilter as $groupid => $groupinfo) { 1141 1142 $groupcolumns = $groupinfo["columns"]; 1143 $groupcondition = $groupinfo["condition"]; 1144 $advfiltergroupsql = ""; 1145 1146 foreach ($groupcolumns as $columnindex => $columninfo) { 1147 $columnname = $columninfo['columnname']; 1148 $comparator = $columninfo['comparator']; 1149 $value = $columninfo['value']; 1150 $columncondition = $columninfo['column_condition']; 1151 1152 $columns = explode(":", $columnname); 1153 $datatype = (isset($columns[4])) ? $columns[4] : ""; 1154 1155 if ($columnname != "" && $comparator != "") { 1156 $valuearray = explode(",", trim($value)); 1157 1158 if (isset($valuearray) && count($valuearray) > 1 && $comparator != 'bw') { 1159 $advorsql = ""; 1160 for ($n = 0; $n < count($valuearray); $n++) { 1161 $advorsql[] = $this->getRealValues($columns[0], $columns[1], $comparator, trim($valuearray[$n]), $datatype); 1162 } 1163 //If negative logic filter ('not equal to', 'does not contain') is used, 'and' condition should be applied instead of 'or' 1164 if ($comparator == 'n' || $comparator == 'k') 1165 $advorsqls = implode(" and ", $advorsql); 1166 else 1167 $advorsqls = implode(" or ", $advorsql); 1168 $advfiltersql = " (" . $advorsqls . ") "; 1169 } 1170 elseif ($comparator == 'bw' && count($valuearray) == 2) { 1171 $advfiltersql = "(" . $columns[0] . "." . $columns[1] . " between '" . getValidDBInsertDateTimeValue(trim($valuearray[0]), $datatype) . "' and '" . getValidDBInsertDateTimeValue(trim($valuearray[1]), $datatype) . "')"; 1172 } 1173 elseif ($comparator == 'y') { 1174 $advfiltersql = sprintf("(%s.%s IS NULL OR %s.%s = '')", $columns[0], $columns[1], $columns[0], $columns[1]); 1175 } else { 1176 //Added for getting vtiger_activity Status -Jaguar 1177 if ($this->customviewmodule == "Calendar" && ($columns[1] == "status" || $columns[1] == "eventstatus")) { 1178 if (getFieldVisibilityPermission("Calendar", $current_user->id, 'taskstatus') == '0') { 1179 $advfiltersql = "case when (vtiger_activity.status not like '') then vtiger_activity.status else vtiger_activity.eventstatus end" . $this->getAdvComparator($comparator, trim($value), $datatype); 1180 } 1181 else 1182 $advfiltersql = "vtiger_activity.eventstatus" . $this->getAdvComparator($comparator, trim($value), $datatype); 1183 } 1184 elseif ($this->customviewmodule == "Documents" && $columns[1] == 'folderid') { 1185 $advfiltersql = "vtiger_attachmentsfolder.foldername" . $this->getAdvComparator($comparator, trim($value), $datatype); 1186 } elseif ($this->customviewmodule == "Assets") { 1187 if ($columns[1] == 'account') { 1188 $advfiltersql = "vtiger_account.accountname" . $this->getAdvComparator($comparator, trim($value), $datatype); 1189 } 1190 if ($columns[1] == 'product') { 1191 $advfiltersql = "vtiger_products.productname" . $this->getAdvComparator($comparator, trim($value), $datatype); 1192 } 1193 if ($columns[1] == 'invoiceid') { 1194 $advfiltersql = "vtiger_invoice.subject" . $this->getAdvComparator($comparator, trim($value), $datatype); 1195 } 1196 } else { 1197 $advfiltersql = $this->getRealValues($columns[0], $columns[1], $comparator, trim($value), $datatype); 1198 } 1199 } 1200 1201 $advfiltergroupsql .= $advfiltersql; 1202 if ($columncondition != NULL && $columncondition != '' && count($groupcolumns) > $columnindex) { 1203 $advfiltergroupsql .= ' ' . $columncondition . ' '; 1204 } 1205 } 1206 } 1207 1208 if (trim($advfiltergroupsql) != "") { 1209 $advfiltergroupsql = "( $advfiltergroupsql ) "; 1210 if ($groupcondition != NULL && $groupcondition != '' && $advfilter > $groupid) { 1211 $advfiltergroupsql .= ' ' . $groupcondition . ' '; 1212 } 1213 1214 $advcvsql .= $advfiltergroupsql; 1215 } 1216 } 1217 if (trim($advcvsql) != "") 1218 $advcvsql = '(' . $advcvsql . ')'; 1219 return $advcvsql; 1220 } 1221 1222 /** to get the realvalues for the given value 1223 * @param $tablename :: type string 1224 * @param $fieldname :: type string 1225 * @param $comparator :: type string 1226 * @param $value :: type string 1227 * @returns $value as a string in the following format 1228 * $tablename.$fieldname comparator 1229 */ 1230 function getRealValues($tablename, $fieldname, $comparator, $value, $datatype) { 1231 //we have to add the fieldname/tablename.fieldname and the corresponding value (which we want) we can add here. So that when these LHS field comes then RHS value will be replaced for LHS in the where condition of the query 1232 global $adb, $mod_strings, $currentModule, $current_user; 1233 //Added for proper check of contact name in advance filter 1234 if ($tablename == "vtiger_contactdetails" && $fieldname == "lastname") 1235 $fieldname = "contactid"; 1236 1237 $contactid = "vtiger_contactdetails.lastname"; 1238 if ($currentModule != "Contacts" && $currentModule != "Leads" && $currentModule != 'Campaigns') { 1239 $contactid = getSqlForNameInDisplayFormat(array('lastname' => 'vtiger_contactdetails.lastname', 'firstname' => 'vtiger_contactdetails.firstname'), 'Contacts'); 1240 } 1241 $change_table_field = Array( 1242 "product_id" => "vtiger_products.productname", 1243 "contactid" => 'trim(' . $contactid . ')', 1244 "contact_id" => 'trim(' . $contactid . ')', 1245 "accountid" => "", //in cvadvfilter accountname is stored for Contact, Potential, Quotes, SO, Invoice 1246 "account_id" => "", //Same like accountid. No need to change 1247 "vendorid" => "vtiger_vendor.vendorname", 1248 "vendor_id" => "vtiger_vendor.vendorname", 1249 "potentialid" => "vtiger_potential.potentialname", 1250 "vtiger_account.parentid" => "vtiger_account2.accountname", 1251 "quoteid" => "vtiger_quotes.subject", 1252 "salesorderid" => "vtiger_salesorder.subject", 1253 "campaignid" => "vtiger_campaign.campaignname", 1254 "vtiger_contactdetails.reportsto" => getSqlForNameInDisplayFormat(array('lastname' => 'vtiger_contactdetails2.lastname', 'firstname' => 'vtiger_contactdetails2.firstname'), 'Contacts'), 1255 "vtiger_pricebook.currency_id" => "vtiger_currency_info.currency_name", 1256 ); 1257 1258 if ($fieldname == "smownerid" || $fieldname == 'modifiedby') { 1259 if($fieldname == "smownerid") { 1260 $tableNameSuffix = ''; 1261 } elseif($fieldname == "modifiedby") { 1262 $tableNameSuffix = '2'; 1263 } 1264 $userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 1265 'vtiger_users'.$tableNameSuffix.'.first_name', 'last_name' => 'vtiger_users'.$tableNameSuffix.'.last_name'), 'Users'); 1266 $temp_value = '( trim(' . $userNameSql . ')' . $this->getAdvComparator($comparator, $value, $datatype); 1267 $temp_value.= " OR vtiger_groups$tableNameSuffix.groupname" . $this->getAdvComparator($comparator, $value, $datatype) . ')'; 1268 $value = $temp_value; // Hot fix: removed unbalanced closing bracket ")"; 1269 } elseif ($fieldname == "inventorymanager") { 1270 $value = $tablename . "." . $fieldname . $this->getAdvComparator($comparator, getUserId_Ol($value), $datatype); 1271 } elseif ($change_table_field[$fieldname] != '') {//Added to handle special cases 1272 $value = $change_table_field[$fieldname] . $this->getAdvComparator($comparator, $value, $datatype); 1273 } elseif ($change_table_field[$tablename . "." . $fieldname] != '') {//Added to handle special cases 1274 $tmp_value = ''; 1275 if ((($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($value) == '') || (($comparator == 'n' || $comparator == 'k') && trim($value) != '')) { 1276 $tmp_value = $change_table_field[$tablename . "." . $fieldname] . ' IS NULL or '; 1277 } 1278 $value = $tmp_value . $change_table_field[$tablename . "." . $fieldname] . $this->getAdvComparator($comparator, $value, $datatype); 1279 } elseif (($fieldname == "crmid" && $tablename != 'vtiger_crmentity') || $fieldname == "parent_id" || $fieldname == 'parentid') { 1280 //For crmentity.crmid the control should not come here. This is only to get the related to modules 1281 $value = $this->getSalesRelatedName($comparator, $value, $datatype, $tablename, $fieldname); 1282 } else { 1283 //For checkbox type values, we have to convert yes/no as 1/0 to get the values 1284 $field_uitype = getUItype($this->customviewmodule, $fieldname); 1285 if ($field_uitype == 56) { 1286 if (strtolower($value) == 'yes') 1287 $value = 1; 1288 elseif (strtolower($value) == 'no') 1289 $value = 0; 1290 } else if (is_uitype($field_uitype, '_picklist_')) { /* Fix for tickets 4465 and 4629 */ 1291 // Get all the keys for the for the Picklist value 1292 $mod_keys = array_keys($mod_strings, $value); 1293 1294 // Iterate on the keys, to get the first key which doesn't start with LBL_ (assuming it is not used in PickList) 1295 foreach ($mod_keys as $mod_idx => $mod_key) { 1296 $stridx = strpos($mod_key, 'LBL_'); 1297 // Use strict type comparision, refer strpos for more details 1298 if ($stridx !== 0) { 1299 $value = $mod_key; 1300 break; 1301 } 1302 } 1303 } 1304 //added to fix the ticket 1305 if ($this->customviewmodule == "Calendar" && ($fieldname == "status" || $fieldname == "taskstatus" || $fieldname == "eventstatus")) { 1306 if (getFieldVisibilityPermission("Calendar", $current_user->id, 'taskstatus') == '0') { 1307 $value = " (case when (vtiger_activity.status not like '') then vtiger_activity.status else vtiger_activity.eventstatus end)" . $this->getAdvComparator($comparator, $value, $datatype); 1308 } 1309 else 1310 $value = " vtiger_activity.eventstatus " . $this->getAdvComparator($comparator, $value, $datatype); 1311 } elseif ($comparator == 'e' && (trim($value) == "NULL" || trim($value) == '')) { 1312 $value = '(' . $tablename . "." . $fieldname . ' IS NULL OR ' . $tablename . "." . $fieldname . ' = \'\')'; 1313 } else { 1314 $value = $tablename . "." . $fieldname . $this->getAdvComparator($comparator, $value, $datatype); 1315 } 1316 //end 1317 } 1318 return $value; 1319 } 1320 1321 /** to get the related name for the given module 1322 * @param $comparator :: type string, 1323 * @param $value :: type string, 1324 * @param $datatype :: type string, 1325 * @returns $value :: string 1326 */ 1327 function getSalesRelatedName($comparator, $value, $datatype, $tablename, $fieldname) { 1328 global $log; 1329 $log->info("in getSalesRelatedName " . $comparator . "==" . $value . "==" . $datatype . "==" . $tablename . "==" . $fieldname); 1330 global $adb; 1331 1332 $adv_chk_value = $value; 1333 $value = '('; 1334 $sql = "select distinct(setype) from vtiger_crmentity c INNER JOIN " . $adb->sql_escape_string($tablename) . " t ON t." . $adb->sql_escape_string($fieldname) . " = c.crmid"; 1335 $res = $adb->pquery($sql, array()); 1336 for ($s = 0; $s < $adb->num_rows($res); $s++) { 1337 $modulename = $adb->query_result($res, $s, "setype"); 1338 if ($modulename == 'Vendors') { 1339 continue; 1340 } 1341 if ($s != 0) 1342 $value .= ' or '; 1343 if ($modulename == 'Accounts') { 1344 //By Pavani : Related to problem in calender, Ticket: 4284 and 4675 1345 if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($adv_chk_value) == '') { 1346 if ($tablename == 'vtiger_seactivityrel' && $fieldname == 'crmid') { 1347 $value .= 'vtiger_account2.accountname IS NULL or '; 1348 } else { 1349 $value .= 'vtiger_account.accountname IS NULL or '; 1350 } 1351 } 1352 if ($tablename == 'vtiger_seactivityrel' && $fieldname == 'crmid') { 1353 $value .= 'vtiger_account2.accountname'; 1354 } else { 1355 $value .= 'vtiger_account.accountname'; 1356 } 1357 } 1358 if ($modulename == 'Leads') { 1359 $concatSql = getSqlForNameInDisplayFormat(array('lastname' => 'vtiger_leaddetails.lastname', 'firstname' => 'vtiger_leaddetails.firstname'), 'Leads'); 1360 if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($adv_chk_value) == '') { 1361 $value .= " $concatSql IS NULL or "; 1362 } 1363 $value .= " $concatSql"; 1364 } 1365 if ($modulename == 'Potentials') { 1366 if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($adv_chk_value) == '') { 1367 1368 $value .= ' vtiger_potential.potentialname IS NULL or '; 1369 } 1370 $value .= ' vtiger_potential.potentialname'; 1371 } 1372 if ($modulename == 'Products') { 1373 if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($adv_chk_value) == '') { 1374 $value .= ' vtiger_products.productname IS NULL or '; 1375 } 1376 $value .= ' vtiger_products.productname'; 1377 } 1378 if ($modulename == 'Invoice') { 1379 if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($adv_chk_value) == '') { 1380 $value .= ' vtiger_invoice.subject IS NULL or '; 1381 } 1382 $value .= ' vtiger_invoice.subject'; 1383 } 1384 if ($modulename == 'PurchaseOrder') { 1385 if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($adv_chk_value) == '') { 1386 $value .= ' vtiger_purchaseorder.subject IS NULL or '; 1387 } 1388 $value .= ' vtiger_purchaseorder.subject'; 1389 } 1390 if ($modulename == 'SalesOrder') { 1391 if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($adv_chk_value) == '') { 1392 $value .= ' vtiger_salesorder.subject IS NULL or '; 1393 } 1394 $value .= ' vtiger_salesorder.subject'; 1395 } 1396 if ($modulename == 'Quotes') { 1397 1398 if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($adv_chk_value) == '') { 1399 $value .= ' vtiger_quotes.subject IS NULL or '; 1400 } 1401 $value .= ' vtiger_quotes.subject'; 1402 } 1403 if ($modulename == 'Contacts') { 1404 $concatSql = getSqlForNameInDisplayFormat(array('lastname' => 'vtiger_contactdetails.lastname', 'firstname' => 'vtiger_contactdetails.firstname'), 'Contacts'); 1405 if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($adv_chk_value) == '') { 1406 $value .= " $concatSql IS NULL or "; 1407 } 1408 $value .= " $concatSql"; 1409 } 1410 if ($modulename == 'HelpDesk') { 1411 if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($adv_chk_value) == '') { 1412 $value .= ' vtiger_troubletickets.title IS NULL or '; 1413 } 1414 $value .= ' vtiger_troubletickets.title'; 1415 } 1416 if ($modulename == 'Campaigns') { 1417 if (($comparator == 'e' || $comparator == 's' || $comparator == 'c') && trim($adv_chk_value) == '') { 1418 $value .= ' vtiger_campaign.campaignname IS NULL or '; 1419 } 1420 $value .= ' vtiger_campaign.campaignname'; 1421 } 1422 1423 $value .= $this->getAdvComparator($comparator, $adv_chk_value, $datatype); 1424 } 1425 $value .= ")"; 1426 $log->info("in getSalesRelatedName " . $comparator . "==" . $value . "==" . $datatype . "==" . $tablename . "==" . $fieldname); 1427 return $value; 1428 } 1429 1430 /** to get the comparator value for the given comparator and value 1431 * @param $comparator :: type string 1432 * @param $value :: type string 1433 * @returns $rtvalue in the format $comparator $value 1434 */ 1435 function getAdvComparator($comparator, $value, $datatype = '') { 1436 1437 global $adb, $default_charset; 1438 $value = html_entity_decode(trim($value), ENT_QUOTES, $default_charset); 1439 $value = $adb->sql_escape_string($value); 1440 1441 if ($comparator == "e") { 1442 if (trim($value) == "NULL") { 1443 $rtvalue = " is NULL"; 1444 } elseif (trim($value) != "") { 1445 $rtvalue = " = " . $adb->quote($value); 1446 } elseif (trim($value) == "" && ($datatype == "V" || $datatype == "E")) { 1447 $rtvalue = " = " . $adb->quote($value); 1448 } else { 1449 $rtvalue = " is NULL"; 1450 } 1451 } 1452 if ($comparator == "n") { 1453 if (trim($value) == "NULL") { 1454 $rtvalue = " is NOT NULL"; 1455 } elseif (trim($value) != "") { 1456 $rtvalue = " <> " . $adb->quote($value); 1457 } elseif (trim($value) == "" && $datatype == "V") { 1458 $rtvalue = " <> " . $adb->quote($value); 1459 } elseif (trim($value) == "" && $datatype == "E") { 1460 $rtvalue = " <> " . $adb->quote($value); 1461 } else { 1462 $rtvalue = " is NOT NULL"; 1463 } 1464 } 1465 if ($comparator == "s") { 1466 if (trim($value) == "" && ($datatype == "V" || $datatype == "E")) { 1467 $rtvalue = " like '" . formatForSqlLike($value, 3) . "'"; 1468 } else { 1469 $rtvalue = " like '" . formatForSqlLike($value, 2) . "'"; 1470 } 1471 } 1472 if ($comparator == "ew") { 1473 if (trim($value) == "" && ($datatype == "V" || $datatype == "E")) { 1474 $rtvalue = " like '" . formatForSqlLike($value, 3) . "'"; 1475 } else { 1476 $rtvalue = " like '" . formatForSqlLike($value, 1) . "'"; 1477 } 1478 } 1479 if ($comparator == "c") { 1480 if (trim($value) == "" && ($datatype == "V" || $datatype == "E")) { 1481 $rtvalue = " like '" . formatForSqlLike($value, 3) . "'"; 1482 } else { 1483 $rtvalue = " like '" . formatForSqlLike($value) . "'"; 1484 } 1485 } 1486 if ($comparator == "k") { 1487 if (trim($value) == "" && ($datatype == "V" || $datatype == "E")) { 1488 $rtvalue = " not like ''"; 1489 } else { 1490 $rtvalue = " not like '" . formatForSqlLike($value) . "'"; 1491 } 1492 } 1493 if ($comparator == "l") { 1494 $rtvalue = " < " . $adb->quote($value); 1495 } 1496 if ($comparator == "g") { 1497 $rtvalue = " > " . $adb->quote($value); 1498 } 1499 if ($comparator == "m") { 1500 $rtvalue = " <= " . $adb->quote($value); 1501 } 1502 if ($comparator == "h") { 1503 $rtvalue = " >= " . $adb->quote($value); 1504 } 1505 if ($comparator == "b") { 1506 $rtvalue = " < " . $adb->quote($value); 1507 } 1508 if ($comparator == "a") { 1509 $rtvalue = " > " . $adb->quote($value); 1510 } 1511 1512 return $rtvalue; 1513 } 1514 1515 /** to get the date value for the given type 1516 * @param $type :: type string 1517 * @returns $datevalue array in the following format 1518 * $datevalue = Array(0=>$startdate,1=>$enddate) 1519 */ 1520 function getDateforStdFilterBytype($type) { 1521 $thisyear = date("Y"); 1522 $today = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d"), date("Y"))); 1523 $todayName = date('l', strtotime( $today)); 1524 1525 $tomorrow = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))); 1526 $yesterday = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 1, date("Y"))); 1527 1528 $currentmonth0 = date("Y-m-d", mktime(0, 0, 0, date("m"), "01", date("Y"))); 1529 $currentmonth1 = date("Y-m-t"); 1530 $lastmonth0 = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, "01", date("Y"))); 1531 $lastmonth1 = date("Y-m-t", strtotime("last day of previous month")); 1532 $nextmonth0 = date("Y-m-d", mktime(0, 0, 0, date("m") + 1, "01", date("Y"))); 1533 $nextmonth1 = date("Y-m-t", strtotime("last day of next month")); 1534 1535 // (Last Week) If Today is "Sunday" then "-2 week Sunday" will give before last week Sunday date 1536 if($todayName == "Sunday") 1537 $lastweek0 = date("Y-m-d",strtotime("-1 week Sunday")); 1538 else 1539 $lastweek0 = date("Y-m-d", strtotime("-2 week Sunday")); 1540 $lastweek1 = date("Y-m-d", strtotime("-1 week Saturday")); 1541 1542 // (This Week) If Today is "Sunday" then "-1 week Sunday" will give last week Sunday date 1543 if($todayName == "Sunday") 1544 $thisweek0 = date("Y-m-d",strtotime("-0 week Sunday")); 1545 else 1546 $thisweek0 = date("Y-m-d", strtotime("-1 week Sunday")); 1547 $thisweek1 = date("Y-m-d", strtotime("this Saturday")); 1548 1549 // (Next Week) If Today is "Sunday" then "this Sunday" will give Today's date 1550 if($todayName == "Sunday") 1551 $nextweek0 = date("Y-m-d",strtotime("+1 week Sunday")); 1552 else 1553 $nextweek0 = date("Y-m-d", strtotime("this Sunday")); 1554 $nextweek1 = date("Y-m-d", strtotime("+1 week Saturday")); 1555 1556 $next7days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 6, date("Y"))); 1557 $next30days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 29, date("Y"))); 1558 $next60days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 59, date("Y"))); 1559 $next90days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 89, date("Y"))); 1560 $next120days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 119, date("Y"))); 1561 1562 $last7days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 6, date("Y"))); 1563 $last30days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 29, date("Y"))); 1564 $last60days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 59, date("Y"))); 1565 $last90days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 89, date("Y"))); 1566 $last120days = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 119, date("Y"))); 1567 1568 $currentFY0 = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y"))); 1569 $currentFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y"))); 1570 $lastFY0 = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y") - 1)); 1571 $lastFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y") - 1)); 1572 $nextFY0 = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y") + 1)); 1573 $nextFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y") + 1)); 1574 1575 if (date("m") <= 4) { 1576 $cFq = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y"))); 1577 $cFq1 = date("Y-m-d", mktime(0, 0, 0, "04", "30", date("Y"))); 1578 $nFq = date("Y-m-d", mktime(0, 0, 0, "05", "01", date("Y"))); 1579 $nFq1 = date("Y-m-d", mktime(0, 0, 0, "08", "31", date("Y"))); 1580 $pFq = date("Y-m-d", mktime(0, 0, 0, "09", "01", date("Y") - 1)); 1581 $pFq1 = date("Y-m-d", mktime(0, 0, 0, "12", "31", date("Y") - 1)); 1582 } else if (date("m") > 4 and date("m") <= 8) { 1583 $pFq = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y"))); 1584 $pFq1 = date("Y-m-d", mktime(0, 0, 0, "04", "30", date("Y"))); 1585 $cFq = date("Y-m-d", mktime(0, 0, 0, "05", "01", date("Y"))); 1586 $cFq1 = date("Y-m-d", mktime(0, 0, 0, "08", "31", date("Y"))); 1587 $nFq = date("Y-m-d", mktime(0, 0, 0, "09", "01", date("Y"))); 1588 $nFq1 = date("Y-m-d", mktime(0, 0, 0, "12", "31", date("Y"))); 1589 } else { 1590 $nFq = date("Y-m-d", mktime(0, 0, 0, "01", "01", date("Y") + 1)); 1591 $nFq1 = date("Y-m-d", mktime(0, 0, 0, "04", "30", date("Y") + 1)); 1592 $pFq = date("Y-m-d", mktime(0, 0, 0, "05", "01", date("Y"))); 1593 $pFq1 = date("Y-m-d", mktime(0, 0, 0, "08", "31", date("Y"))); 1594 $cFq = date("Y-m-d", mktime(0, 0, 0, "09", "01", date("Y"))); 1595 $cFq1 = date("Y-m-d", mktime(0, 0, 0, "12", "31", date("Y"))); 1596 } 1597 1598 if ($type == "today") { 1599 1600 $datevalue[0] = $today; 1601 $datevalue[1] = $today; 1602 } elseif ($type == "yesterday") { 1603 1604 $datevalue[0] = $yesterday; 1605 $datevalue[1] = $yesterday; 1606 } elseif ($type == "tomorrow") { 1607 1608 $datevalue[0] = $tomorrow; 1609 $datevalue[1] = $tomorrow; 1610 } elseif ($type == "thisweek") { 1611 1612 $datevalue[0] = $thisweek0; 1613 $datevalue[1] = $thisweek1; 1614 } elseif ($type == "lastweek") { 1615 1616 $datevalue[0] = $lastweek0; 1617 $datevalue[1] = $lastweek1; 1618 } elseif ($type == "nextweek") { 1619 1620 $datevalue[0] = $nextweek0; 1621 $datevalue[1] = $nextweek1; 1622 } elseif ($type == "thismonth") { 1623 1624 $datevalue[0] = $currentmonth0; 1625 $datevalue[1] = $currentmonth1; 1626 } elseif ($type == "lastmonth") { 1627 1628 $datevalue[0] = $lastmonth0; 1629 $datevalue[1] = $lastmonth1; 1630 } elseif ($type == "nextmonth") { 1631 1632 $datevalue[0] = $nextmonth0; 1633 $datevalue[1] = $nextmonth1; 1634 } elseif ($type == "next7days") { 1635 1636 $datevalue[0] = $today; 1637 $datevalue[1] = $next7days; 1638 } elseif ($type == "next30days") { 1639 1640 $datevalue[0] = $today; 1641 $datevalue[1] = $next30days; 1642 } elseif ($type == "next60days") { 1643 1644 $datevalue[0] = $today; 1645 $datevalue[1] = $next60days; 1646 } elseif ($type == "next90days") { 1647 1648 $datevalue[0] = $today; 1649 $datevalue[1] = $next90days; 1650 } elseif ($type == "next120days") { 1651 1652 $datevalue[0] = $today; 1653 $datevalue[1] = $next120days; 1654 } elseif ($type == "last7days") { 1655 1656 $datevalue[0] = $last7days; 1657 $datevalue[1] = $today; 1658 } elseif ($type == "last30days") { 1659 1660 $datevalue[0] = $last30days; 1661 $datevalue[1] = $today; 1662 } elseif ($type == "last60days") { 1663 1664 $datevalue[0] = $last60days; 1665 $datevalue[1] = $today; 1666 } else if ($type == "last90days") { 1667 1668 $datevalue[0] = $last90days; 1669 $datevalue[1] = $today; 1670 } elseif ($type == "last120days") { 1671 1672 $datevalue[0] = $last120days; 1673 $datevalue[1] = $today; 1674 } elseif ($type == "thisfy") { 1675 1676 $datevalue[0] = $currentFY0; 1677 $datevalue[1] = $currentFY1; 1678 } elseif ($type == "prevfy") { 1679 1680 $datevalue[0] = $lastFY0; 1681 $datevalue[1] = $lastFY1; 1682 } elseif ($type == "nextfy") { 1683 1684 $datevalue[0] = $nextFY0; 1685 $datevalue[1] = $nextFY1; 1686 } elseif ($type == "nextfq") { 1687 1688 $datevalue[0] = $nFq; 1689 $datevalue[1] = $nFq1; 1690 } elseif ($type == "prevfq") { 1691 1692 $datevalue[0] = $pFq; 1693 $datevalue[1] = $pFq1; 1694 } elseif ($type == "thisfq") { 1695 $datevalue[0] = $cFq; 1696 $datevalue[1] = $cFq1; 1697 } else { 1698 $datevalue[0] = ""; 1699 $datevalue[1] = ""; 1700 } 1701 1702 return $datevalue; 1703 } 1704 1705 /** to get the customview query for the given customview 1706 * @param $viewid (custom view id):: type Integer 1707 * @param $listquery (List View Query):: type string 1708 * @param $module (Module Name):: type string 1709 * @returns $query 1710 */ 1711 //CHANGE : TO IMPROVE PERFORMANCE 1712 function getModifiedCvListQuery($viewid, $listquery, $module) { 1713 if ($viewid != "" && $listquery != "") { 1714 1715 $listviewquery = substr($listquery, strpos($listquery, 'FROM'), strlen($listquery)); 1716 if ($module == "Calendar" || $module == "Emails") { 1717 $query = "select " . $this->getCvColumnListSQL($viewid) . ", vtiger_activity.activityid, vtiger_activity.activitytype as type, vtiger_activity.priority, case when (vtiger_activity.status not like '') then vtiger_activity.status else vtiger_activity.eventstatus end as status, vtiger_crmentity.crmid,vtiger_contactdetails.contactid " . $listviewquery; 1718 if ($module == "Calendar") 1719 $query = str_replace('vtiger_seactivityrel.crmid,', '', $query); 1720 }else if ($module == "Documents") { 1721 $query = "select " . $this->getCvColumnListSQL($viewid) . " ,vtiger_crmentity.crmid,vtiger_notes.* " . $listviewquery; 1722 } else if ($module == "Products") { 1723 $query = "select " . $this->getCvColumnListSQL($viewid) . " ,vtiger_crmentity.crmid,vtiger_products.* " . $listviewquery; 1724 } else if ($module == "Vendors") { 1725 $query = "select " . $this->getCvColumnListSQL($viewid) . " ,vtiger_crmentity.crmid " . $listviewquery; 1726 } else if ($module == "PriceBooks") { 1727 $query = "select " . $this->getCvColumnListSQL($viewid) . " ,vtiger_crmentity.crmid " . $listviewquery; 1728 } else if ($module == "Faq") { 1729 $query = "select " . $this->getCvColumnListSQL($viewid) . " ,vtiger_crmentity.crmid " . $listviewquery; 1730 } else if ($module == "Potentials" || $module == "Contacts") { 1731 $query = "select " . $this->getCvColumnListSQL($viewid) . " ,vtiger_crmentity.crmid,vtiger_account.accountid " . $listviewquery; 1732 } else if ($module == "Invoice" || $module == "SalesOrder" || $module == "Quotes") { 1733 $query = "select " . $this->getCvColumnListSQL($viewid) . " ,vtiger_crmentity.crmid,vtiger_contactdetails.contactid,vtiger_account.accountid " . $listviewquery; 1734 } else if ($module == "PurchaseOrder") { 1735 $query = "select " . $this->getCvColumnListSQL($viewid) . " ,vtiger_crmentity.crmid,vtiger_contactdetails.contactid " . $listviewquery; 1736 } else { 1737 $query = "select " . $this->getCvColumnListSQL($viewid) . " ,vtiger_crmentity.crmid " . $listviewquery; 1738 } 1739 $stdfiltersql = $this->getCVStdFilterSQL($viewid); 1740 $advfiltersql = $this->getCVAdvFilterSQL($viewid); 1741 if (isset($stdfiltersql) && $stdfiltersql != '') { 1742 $query .= ' and ' . $stdfiltersql; 1743 } 1744 if (isset($advfiltersql) && $advfiltersql != '') { 1745 $query .= ' and ' . $advfiltersql; 1746 } 1747 } 1748 return $query; 1749 } 1750 1751 /** to get the Key Metrics for the home page query for the given customview to find the no of records 1752 * @param $viewid (custom view id):: type Integer 1753 * @param $listquery (List View Query):: type string 1754 * @param $module (Module Name):: type string 1755 * @returns $query 1756 */ 1757 function getMetricsCvListQuery($viewid, $listquery, $module) { 1758 if ($viewid != "" && $listquery != "") { 1759 $listviewquery = substr($listquery, strpos($listquery, 'FROM'), strlen($listquery)); 1760 1761 $query = "select count(*) AS count " . $listviewquery; 1762 1763 $stdfiltersql = $this->getCVStdFilterSQL($viewid); 1764 $advfiltersql = $this->getCVAdvFilterSQL($viewid); 1765 if (isset($stdfiltersql) && $stdfiltersql != '') { 1766 $query .= ' and ' . $stdfiltersql; 1767 } 1768 if (isset($advfiltersql) && $advfiltersql != '') { 1769 $query .= ' and ' . $advfiltersql; 1770 } 1771 } 1772 1773 return $query; 1774 } 1775 1776 /** to get the custom action details for the given customview 1777 * @param $viewid (custom view id):: type Integer 1778 * @returns $calist array in the following format 1779 * $calist = Array ('subject'=>$subject, 1780 'module'=>$module, 1781 'content'=>$content, 1782 'cvid'=>$custom view id) 1783 */ 1784 function getCustomActionDetails($cvid) { 1785 global $adb; 1786 1787 $sSQL = "select vtiger_customaction.* from vtiger_customaction inner join vtiger_customview on vtiger_customaction.cvid = vtiger_customview.cvid"; 1788 $sSQL .= " where vtiger_customaction.cvid=?"; 1789 $result = $adb->pquery($sSQL, array($cvid)); 1790 1791 while ($carow = $adb->fetch_array($result)) { 1792 $calist["subject"] = $carow["subject"]; 1793 $calist["module"] = $carow["module"]; 1794 $calist["content"] = $carow["content"]; 1795 $calist["cvid"] = $carow["cvid"]; 1796 } 1797 return $calist; 1798 } 1799 1800 /* This function sets the block information for the given module to the class variable module_list 1801 * and return the array 1802 */ 1803 1804 function getCustomViewModuleInfo($module) { 1805 global $adb; 1806 global $current_language; 1807 $current_mod_strings = return_specified_module_language($current_language, $module); 1808 $block_info = Array(); 1809 $modules_list = explode(",", $module); 1810 if ($module == "Calendar") { 1811 $module = "Calendar','Events"; 1812 $modules_list = array('Calendar', 'Events'); 1813 } 1814 1815 // Tabid mapped to the list of block labels to be skipped for that tab. 1816 $skipBlocksList = array( 1817 getTabid('HelpDesk') => array('LBL_COMMENTS'), 1818 getTabid('Faq') => array('LBL_COMMENT_INFORMATION'), 1819 getTabid('Quotes') => array('LBL_RELATED_PRODUCTS'), 1820 getTabid('PurchaseOrder') => array('LBL_RELATED_PRODUCTS'), 1821 getTabid('SalesOrder') => array('LBL_RELATED_PRODUCTS'), 1822 getTabid('Invoice') => array('LBL_RELATED_PRODUCTS') 1823 ); 1824 1825 $Sql = "select distinct block,vtiger_field.tabid,name,blocklabel from vtiger_field inner join vtiger_blocks on vtiger_blocks.blockid=vtiger_field.block inner join vtiger_tab on vtiger_tab.tabid=vtiger_field.tabid where displaytype != 3 and vtiger_tab.name in (" . generateQuestionMarks($modules_list) . ") and vtiger_field.presence in (0,2) order by block"; 1826 $result = $adb->pquery($Sql, array($modules_list)); 1827 if ($module == "Calendar','Events") 1828 $module = "Calendar"; 1829 1830 $pre_block_label = ''; 1831 while ($block_result = $adb->fetch_array($result)) { 1832 $block_label = $block_result['blocklabel']; 1833 $tabid = $block_result['tabid']; 1834 // Skip certain blocks of certain modules 1835 if (array_key_exists($tabid, $skipBlocksList) && in_array($block_label, $skipBlocksList[$tabid])) 1836 continue; 1837 1838 if (trim($block_label) == '') { 1839 $block_info[$pre_block_label] = $block_info[$pre_block_label] . "," . $block_result['block']; 1840 } else { 1841 $lan_block_label = $current_mod_strings[$block_label]; 1842 if (isset($block_info[$lan_block_label]) && $block_info[$lan_block_label] != '') { 1843 $block_info[$lan_block_label] = $block_info[$lan_block_label] . "," . $block_result['block']; 1844 } else { 1845 $block_info[$lan_block_label] = $block_result['block']; 1846 } 1847 } 1848 $pre_block_label = $lan_block_label; 1849 } 1850 $this->module_list[$module] = $block_info; 1851 return $this->module_list; 1852 } 1853 1854 /** 1855 * Get the userid, status information of this custom view. 1856 * 1857 * @param Integer $viewid 1858 * @return Array 1859 */ 1860 function getStatusAndUserid($viewid) { 1861 global $adb; 1862 1863 if ($this->_status === false || $this->_userid === false) { 1864 $query = "SELECT status, userid FROM vtiger_customview WHERE cvid=?"; 1865 $result = $adb->pquery($query, array($viewid)); 1866 if ($result && $adb->num_rows($result)) { 1867 $this->_status = $adb->query_result($result, 0, 'status'); 1868 $this->_userid = $adb->query_result($result, 0, 'userid'); 1869 } else { 1870 return false; 1871 } 1872 } 1873 return array('status' => $this->_status, 'userid' => $this->_userid); 1874 } 1875 1876 //Function to check if the current user is able to see the customView 1877 function isPermittedCustomView($record_id, $action, $module) { 1878 global $log, $adb; 1879 global $current_user; 1880 $log->debug("Entering isPermittedCustomView($record_id,$action,$module) method...."); 1881 1882 require('user_privileges/user_privileges_' . $current_user->id . '.php'); 1883 $permission = "yes"; 1884 1885 if ($record_id != '') { 1886 $status_userid_info = $this->getStatusAndUserid($record_id); 1887 1888 if ($status_userid_info) { 1889 $status = $status_userid_info['status']; 1890 $userid = $status_userid_info['userid']; 1891 1892 if ($status == CV_STATUS_DEFAULT) { 1893 $log->debug("Entering when status=0"); 1894 if ($action == 'ListView' || $action == $module . "Ajax" || $action == 'index' || $action == 'DetailView') { 1895 $permission = "yes"; 1896 } 1897 else 1898 $permission = "no"; 1899 } 1900 elseif ($is_admin) { 1901 $permission = 'yes'; 1902 } elseif ($action != 'ChangeStatus') { 1903 if ($userid == $current_user->id) { 1904 $log->debug("Entering when $userid=$current_user->id"); 1905 $permission = "yes"; 1906 } elseif ($status == CV_STATUS_PUBLIC) { 1907 $log->debug("Entering when status=3"); 1908 if ($action == 'ListView' || $action == $module . "Ajax" || $action == 'index' || $action == 'DetailView') { 1909 $permission = "yes"; 1910 } 1911 else 1912 $permission = "no"; 1913 } 1914 elseif ($status == CV_STATUS_PRIVATE || $status == CV_STATUS_PENDING) { 1915 $log->debug("Entering when status=1 or 2"); 1916 if ($userid == $current_user->id) 1917 $permission = "yes"; 1918 else { 1919 /* if($action == 'ListView' || $action == $module."Ajax" || $action == 'index') 1920 { */ 1921 $log->debug("Entering when status=1 or status=2 & action = ListView or $module.Ajax or index"); 1922 $sql = "select vtiger_users.id from vtiger_customview inner join vtiger_users where vtiger_customview.cvid = ? and vtiger_customview.userid in (select vtiger_user2role.userid from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '%" . $current_user_parent_role_seq . "::%')"; 1923 $result = $adb->pquery($sql, array($record_id)); 1924 1925 while ($row = $adb->fetchByAssoc($result)) { 1926 $temp_result[] = $row['id']; 1927 } 1928 $user_array = $temp_result; 1929 if (sizeof($user_array) > 0) { 1930 if (!in_array($current_user->id, $user_array)) 1931 $permission = "no"; 1932 else 1933 $permission = "yes"; 1934 } 1935 else 1936 $permission = "no"; 1937 /* } 1938 else 1939 { 1940 $log->debug("Entering when status=1 or 2 & action = Editview or Customview"); 1941 $permission = "no"; 1942 } */ 1943 } 1944 } 1945 else 1946 $permission = "yes"; 1947 } 1948 else { 1949 $log->debug("Entering else condition............"); 1950 $permission = "no"; 1951 } 1952 } else { 1953 $log->debug("Enters when count =0"); 1954 $permission = 'no'; 1955 } 1956 } 1957 $log->debug("Permission @@@@@@@@@@@@@@@@@@@@@@@@@@@ : $permission"); 1958 $log->debug("Exiting isPermittedCustomView($record_id,$action,$module) method...."); 1959 return $permission; 1960 } 1961 1962 function isPermittedChangeStatus($status) { 1963 global $current_user, $log; 1964 global $current_language; 1965 $custom_strings = return_module_language($current_language, "CustomView"); 1966 1967 $log->debug("Entering isPermittedChangeStatus($status) method.............."); 1968 require('user_privileges/user_privileges_' . $current_user->id . '.php'); 1969 $status_details = Array(); 1970 if ($is_admin) { 1971 if ($status == CV_STATUS_PENDING) { 1972 $changed_status = CV_STATUS_PUBLIC; 1973 $status_label = $custom_strings['LBL_STATUS_PUBLIC_APPROVE']; 1974 } elseif ($status == CV_STATUS_PUBLIC) { 1975 $changed_status = CV_STATUS_PENDING; 1976 $status_label = $custom_strings['LBL_STATUS_PUBLIC_DENY']; 1977 } 1978 $status_details = Array('Status' => $status, 'ChangedStatus' => $changed_status, 'Label' => $status_label); 1979 } 1980 $log->debug("Exiting isPermittedChangeStatus($status) method.............."); 1981 return $status_details; 1982 } 1983 1984 } 1985 1986 ?>
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 |