[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
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 global $calpath; 12 global $app_strings,$mod_strings; 13 global $app_list_strings; 14 global $theme; 15 $theme_path="themes/".$theme."/"; 16 $image_path=$theme_path."images/"; 17 require_once ('include/database/PearDatabase.php'); 18 require_once ($theme_path."layout_utils.php"); 19 require_once ('data/CRMEntity.php'); 20 require_once ('include/utils/utils.php'); 21 22 global $adv_filter_options; 23 24 $adv_filter_options = array("e"=>"".$mod_strings['equals']."", 25 "n"=>"".$mod_strings['not_equal_to']."", 26 "s"=>"".$mod_strings['starts_with']."", 27 "c"=>"".$mod_strings['contains']."", 28 "k"=>"".$mod_strings['does_not_contain']."", 29 "l"=>"".$mod_strings['less_than']."", 30 "g"=>"".$mod_strings['greater_than']."", 31 "m"=>"".$mod_strings['less_or_equal']."", 32 "h"=>"".$mod_strings['greater_or_equal']."", 33 ); 34 35 class CustomView extends CRMEntity{ 36 37 38 39 var $module_list = Array(); 40 41 var $customviewmodule; 42 43 var $list_fields; 44 45 var $list_fields_name; 46 47 var $setdefaultviewid; 48 49 var $escapemodule; 50 51 var $mandatoryvalues; 52 53 var $showvalues; 54 55 /** This function sets the currentuser id to the class variable smownerid, 56 * modulename to the class variable customviewmodule 57 * @param $module -- The module Name:: Type String(optional) 58 * @returns nothing 59 */ 60 function CustomView($module="") 61 { 62 global $current_user,$adb; 63 $this->customviewmodule = $module; 64 $this->escapemodule[] = $module."_"; 65 $this->escapemodule[] = "_"; 66 $this->smownerid = $current_user->id; 67 } 68 69 70 /** To get the customViewId of the specified module 71 * @param $module -- The module Name:: Type String 72 * @returns customViewId :: Type Integer 73 */ 74 function getViewId($module) 75 { 76 global $adb; 77 if(isset($_REQUEST['viewname']) == false) 78 { 79 if (isset($_SESSION['lvs'][$module]["viewname"]) && $_SESSION['lvs'][$module]["viewname"]!='') 80 { 81 $viewid = $_SESSION['lvs'][$module]["viewname"]; 82 } 83 elseif($this->setdefaultviewid != "") 84 { 85 $viewid = $this->setdefaultviewid; 86 }else 87 { 88 $query="select cvid from vtiger_customview where setdefault=1 and entitytype='".$module."'"; 89 $cvresult=$adb->query($query); 90 if($adb->num_rows($cvresult) == 0) 91 { 92 $query="select cvid from vtiger_customview where viewname='All' and entitytype='".$module."'"; 93 $cvresult=$adb->query($query); 94 } 95 $viewid = $adb->query_result($cvresult,0,'cvid');; 96 } 97 } 98 else 99 { 100 $viewid = $_REQUEST['viewname']; 101 } 102 $_SESSION['lvs'][$module]["viewname"] = $viewid; 103 return $viewid; 104 105 } 106 107 // return type array 108 /** to get the details of a customview 109 * @param $cvid :: Type Integer 110 * @returns $customviewlist Array in the following format 111 * $customviewlist = Array('viewname'=>value, 112 * 'setdefault'=>defaultchk, 113 * 'setmetrics'=>setmetricschk) 114 */ 115 116 function getCustomViewByCvid($cvid) 117 { 118 global $adb; 119 $tabid = getTabid($this->customviewmodule); 120 $ssql = "select vtiger_customview.* from vtiger_customview inner join vtiger_tab on vtiger_tab.name = vtiger_customview.entitytype"; 121 $ssql .= " where vtiger_customview.cvid=".$cvid; 122 123 $result = $adb->query($ssql); 124 125 while($cvrow=$adb->fetch_array($result)) 126 { 127 $customviewlist["viewname"] = $cvrow["viewname"]; 128 $customviewlist["setdefault"] = $cvrow["setdefault"]; 129 $customviewlist["setmetrics"] = $cvrow["setmetrics"]; 130 } 131 return $customviewlist; 132 } 133 134 /** to get the customviewCombo for the class variable customviewmodule 135 * @param $viewid :: Type Integer 136 * $viewid will make the corresponding selected 137 * @returns $customviewCombo :: Type String 138 */ 139 140 function getCustomViewCombo($viewid='') 141 { 142 global $adb; 143 global $app_strings; 144 $tabid = getTabid($this->customviewmodule); 145 $ssql = "select vtiger_customview.* from vtiger_customview inner join vtiger_tab on vtiger_tab.name = vtiger_customview.entitytype"; 146 $ssql .= " where vtiger_tab.tabid=".$tabid; 147 $result = $adb->query($ssql); 148 while($cvrow=$adb->fetch_array($result)) 149 { 150 if($cvrow['viewname'] == 'All') 151 { 152 $cvrow['viewname'] = $app_strings['COMBO_ALL']; 153 } 154 155 if($cvrow['setdefault'] == 1 && $viewid =='') 156 { 157 $shtml .= "<option selected value=\"".$cvrow['cvid']."\">".$cvrow['viewname']."</option>"; 158 $this->setdefaultviewid = $cvrow['cvid']; 159 } 160 elseif($cvrow['cvid'] == $viewid) 161 { 162 $shtml .= "<option selected value=\"".$cvrow['cvid']."\">".$cvrow['viewname']."</option>"; 163 $this->setdefaultviewid = $cvrow['cvid']; 164 } 165 else 166 { 167 $shtml .= "<option value=\"".$cvrow['cvid']."\">".$cvrow['viewname']."</option>"; 168 } 169 } 170 return $shtml; 171 } 172 173 /** to get the getColumnsListbyBlock for the given module and Block 174 * @param $module :: Type String 175 * @param $block :: Type Integer 176 * @returns $columnlist Array in the format 177 * $columnlist = Array ($fieldlabel =>'$fieldtablename:$fieldcolname:$fieldname:$module_$fieldlabel1:$fieldtypeofdata', 178 $fieldlabel1 =>'$fieldtablename1:$fieldcolname1:$fieldname1:$module_$fieldlabel11:$fieldtypeofdata1', 179 | 180 $fieldlabeln =>'$fieldtablenamen:$fieldcolnamen:$fieldnamen:$module_$fieldlabel1n:$fieldtypeofdatan') 181 */ 182 183 function getColumnsListbyBlock($module,$block) 184 { 185 global $adb; 186 $tabid = getTabid($module); 187 global $current_user; 188 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 189 190 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) 191 { 192 $sql = "select * from vtiger_field "; 193 $sql.= " where vtiger_field.tabid=".$tabid." and vtiger_field.block in (".$block.") and"; 194 $sql.= " vtiger_field.displaytype in (1,2)"; 195 $sql.= " order by sequence"; 196 } 197 else 198 { 199 $profileList = getCurrentUserProfileList(); 200 $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 "; 201 $sql.= " where vtiger_field.tabid=".$tabid." and vtiger_field.block in (".$block.") and"; 202 $sql.= " vtiger_field.displaytype in (1,2) and vtiger_profile2field.visible=0"; 203 $sql.= " and vtiger_def_org_field.visible=0 and vtiger_profile2field.profileid in ".$profileList." order by sequence"; 204 } 205 206 207 208 $result = $adb->query($sql); 209 $noofrows = $adb->num_rows($result); 210 //Added on 14-10-2005 -- added ticket id in list 211 if($module == 'HelpDesk' && $block == 25) 212 { 213 $module_columnlist['vtiger_crmentity:crmid::HelpDesk_Ticket_ID:I'] = 'Ticket ID'; 214 } 215 //Added to include vtiger_activity type in vtiger_activity vtiger_customview list 216 if($module == 'Calendar' && $block == 19) 217 { 218 $module_columnlist['vtiger_activity:activitytype:activitytype:Calendar_Activity_Type:C'] = 'Activity Type'; 219 } 220 221 for($i=0; $i<$noofrows; $i++) 222 { 223 $fieldtablename = $adb->query_result($result,$i,"tablename"); 224 $fieldcolname = $adb->query_result($result,$i,"columnname"); 225 $fieldname = $adb->query_result($result,$i,"fieldname"); 226 $fieldtype = $adb->query_result($result,$i,"typeofdata"); 227 $fieldtype = explode("~",$fieldtype); 228 $fieldtypeofdata = $fieldtype[0]; 229 $fieldlabel = $adb->query_result($result,$i,"fieldlabel"); 230 if($fieldlabel == "Related To") 231 { 232 $fieldlabel = "Related to"; 233 } 234 if($fieldlabel == "Start Date & Time") 235 { 236 $fieldlabel = "Start Date"; 237 if($module == 'Calendar' && $block == 19) 238 $module_columnlist['vtiger_activity:time_start::Calendar_Start_Time:I'] = 'Start Time'; 239 240 } 241 $fieldlabel1 = str_replace(" ","_",$fieldlabel); 242 $optionvalue = $fieldtablename.":".$fieldcolname.":".$fieldname.":".$module."_".$fieldlabel1.":".$fieldtypeofdata; 243 //added to escape attachments fields in customview as we have multiple attachments 244 if($module != 'HelpDesk' || $fieldname !='filename') 245 $module_columnlist[$optionvalue] = $fieldlabel; 246 if($fieldtype[1] == "M") 247 { 248 $this->mandatoryvalues[] = "'".$optionvalue."'"; 249 $this->showvalues[] = $fieldlabel; 250 } 251 } 252 return $module_columnlist; 253 } 254 255 /** to get the getModuleColumnsList for the given module 256 * @param $module :: Type String 257 * @returns $ret_module_list Array in the following format 258 * $ret_module_list = 259 Array ('module' => 260 Array('BlockLabel1' => 261 Array('$fieldtablename:$fieldcolname:$fieldname:$module_$fieldlabel1:$fieldtypeofdata'=>$fieldlabel, 262 Array('$fieldtablename1:$fieldcolname1:$fieldname1:$module_$fieldlabel11:$fieldtypeofdata1'=>$fieldlabel1, 263 Array('BlockLabel2' => 264 Array('$fieldtablename:$fieldcolname:$fieldname:$module_$fieldlabel1:$fieldtypeofdata'=>$fieldlabel, 265 Array('$fieldtablename1:$fieldcolname1:$fieldname1:$module_$fieldlabel11:$fieldtypeofdata1'=>$fieldlabel1, 266 | 267 Array('BlockLabeln' => 268 Array('$fieldtablename:$fieldcolname:$fieldname:$module_$fieldlabel1:$fieldtypeofdata'=>$fieldlabel, 269 Array('$fieldtablename1:$fieldcolname1:$fieldname1:$module_$fieldlabel11:$fieldtypeofdata1'=>$fieldlabel1, 270 271 272 */ 273 274 275 function getModuleColumnsList($module) 276 { 277 278 $module_info = $this->getCustomViewModuleInfo($module); 279 foreach($this->module_list[$module] as $key=>$value) 280 { 281 $columnlist = $this->getColumnsListbyBlock($module,$value); 282 if(isset($columnlist)) 283 { 284 $ret_module_list[$module][$key] = $columnlist; 285 } 286 } 287 return $ret_module_list; 288 } 289 290 /** to get the getModuleColumnsList for the given customview 291 * @param $cvid :: Type Integer 292 * @returns $columnlist Array in the following format 293 * $columnlist = Array( $columnindex => $columnname, 294 * $columnindex1 => $columnname1, 295 * | 296 * $columnindexn => $columnnamen) 297 */ 298 function getColumnsListByCvid($cvid) 299 { 300 global $adb; 301 302 $sSQL = "select vtiger_cvcolumnlist.* from vtiger_cvcolumnlist"; 303 $sSQL .= " inner join vtiger_customview on vtiger_customview.cvid = vtiger_cvcolumnlist.cvid"; 304 $sSQL .= " where vtiger_customview.cvid =".$cvid." order by vtiger_cvcolumnlist.columnindex"; 305 $result = $adb->query($sSQL); 306 while($columnrow = $adb->fetch_array($result)) 307 { 308 $columnlist[$columnrow['columnindex']] = $columnrow['columnname']; 309 } 310 return $columnlist; 311 } 312 313 /** to get the standard filter fields or the given module 314 * @param $module :: Type String 315 * @returns $stdcriteria_list Array in the following format 316 * $stdcriteria_list = Array( $tablename:$columnname:$fieldname:$module_$fieldlabel => $fieldlabel, 317 * $tablename1:$columnname1:$fieldname1:$module_$fieldlabel1 => $fieldlabel1, 318 * | 319 * $tablenamen:$columnnamen:$fieldnamen:$module_$fieldlabeln => $fieldlabeln) 320 */ 321 function getStdCriteriaByModule($module) 322 { 323 global $adb; 324 $tabid = getTabid($module); 325 326 global $current_user; 327 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 328 329 $module_info = $this->getCustomViewModuleInfo($module); 330 foreach($this->module_list[$module] as $key=>$blockid) 331 { 332 $blockids[] = $blockid; 333 } 334 $blockids = implode(",",$blockids); 335 336 337 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) 338 { 339 $sql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid "; 340 $sql.= " where vtiger_field.tabid=".$tabid." and vtiger_field.block in (".$blockids.") 341 and (vtiger_field.uitype =5 or vtiger_field.displaytype=2) "; 342 $sql.= " order by vtiger_field.sequence"; 343 } 344 else 345 { 346 $profileList = getCurrentUserProfileList(); 347 $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 "; 348 $sql.= " where vtiger_field.tabid=".$tabid." and vtiger_field.block in (".$blockids.") and (vtiger_field.uitype =5 or vtiger_field.displaytype=2)"; 349 $sql.= " and vtiger_profile2field.visible=0"; 350 $sql.= " and vtiger_def_org_field.visible=0 and vtiger_profile2field.profileid in ".$profileList." order by vtiger_field.sequence"; 351 } 352 353 354 $result = $adb->query($sql); 355 356 while($criteriatyperow = $adb->fetch_array($result)) 357 { 358 $fieldtablename = $criteriatyperow["tablename"]; 359 $fieldcolname = $criteriatyperow["columnname"]; 360 $fieldlabel = $criteriatyperow["fieldlabel"]; 361 $fieldname = $criteriatyperow["fieldname"]; 362 $fieldlabel1 = str_replace(" ","_",$fieldlabel); 363 $optionvalue = $fieldtablename.":".$fieldcolname.":".$fieldname.":".$module."_".$fieldlabel1; 364 $stdcriteria_list[$optionvalue] = $fieldlabel; 365 } 366 367 return $stdcriteria_list; 368 369 } 370 371 /** to get the standard filter criteria 372 * @param $selcriteria :: Type String (optional) 373 * @returns $filter Array in the following format 374 * $filter = Array( 0 => array('value'=>$filterkey,'text'=>$mod_strings[$filterkey],'selected'=>$selected) 375 * 1 => array('value'=>$filterkey1,'text'=>$mod_strings[$filterkey1],'selected'=>$selected) 376 * | 377 * n => array('value'=>$filterkeyn,'text'=>$mod_strings[$filterkeyn],'selected'=>$selected) 378 */ 379 function getStdFilterCriteria($selcriteria = "") 380 { 381 global $mod_strings; 382 $filter = array(); 383 384 $stdfilter = Array("custom"=>"".$mod_strings['Custom']."", 385 "prevfy"=>"".$mod_strings['Previous FY']."", 386 "thisfy"=>"".$mod_strings['Current FY']."", 387 "nextfy"=>"".$mod_strings['Next FY']."", 388 "prevfq"=>"".$mod_strings['Previous FQ']."", 389 "thisfq"=>"".$mod_strings['Current FQ']."", 390 "nextfq"=>"".$mod_strings['Next FQ']."", 391 "yesterday"=>"".$mod_strings['Yesterday']."", 392 "today"=>"".$mod_strings['Today']."", 393 "tomorrow"=>"".$mod_strings['Tomorrow']."", 394 "lastweek"=>"".$mod_strings['Last Week']."", 395 "thisweek"=>"".$mod_strings['Current Week']."", 396 "nextweek"=>"".$mod_strings['Next Week']."", 397 "lastmonth"=>"".$mod_strings['Last Month']."", 398 "thismonth"=>"".$mod_strings['Current Month']."", 399 "nextmonth"=>"".$mod_strings['Next Month']."", 400 "last7days"=>"".$mod_strings['Last 7 Days']."", 401 "last30days"=>"".$mod_strings['Last 30 Days']."", 402 "last60days"=>"".$mod_strings['Last 60 Days']."", 403 "last90days"=>"".$mod_strings['Last 90 Days']."", 404 "last120days"=>"".$mod_strings['Last 120 Days']."", 405 "next30days"=>"".$mod_strings['Next 30 Days']."", 406 "next60days"=>"".$mod_strings['Next 60 Days']."", 407 "next90days"=>"".$mod_strings['Next 90 Days']."", 408 "next120days"=>"".$mod_strings['Next 120 Days']."", 409 ); 410 411 foreach($stdfilter as $FilterKey=>$FilterValue) 412 { 413 if($FilterKey == $selcriteria) 414 { 415 $shtml['value'] = $FilterKey; 416 $shtml['text'] = $FilterValue; 417 $shtml['selected'] = "selected"; 418 }else 419 { 420 $shtml['value'] = $FilterKey; 421 $shtml['text'] = $FilterValue; 422 $shtml['selected'] = ""; 423 } 424 $filter[] = $shtml; 425 } 426 return $filter; 427 428 } 429 430 /** to get the standard filter criteria scripts 431 * @returns $jsStr : Type String 432 * This function will return the script to set the start data and end date 433 * for the standard selection criteria 434 */ 435 function getCriteriaJS() 436 { 437 438 439 $today = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d"), date("Y"))); 440 $tomorrow = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+1, date("Y"))); 441 $yesterday = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-1, date("Y"))); 442 443 $currentmonth0 = date("Y-m-d",mktime(0, 0, 0, date("m"), "01", date("Y"))); 444 $currentmonth1 = date("Y-m-t"); 445 $lastmonth0 = date("Y-m-d",mktime(0, 0, 0, date("m")-1, "01", date("Y"))); 446 $lastmonth1 = date("Y-m-t", strtotime("-1 Month")); 447 $nextmonth0 = date("Y-m-d",mktime(0, 0, 0, date("m")+1, "01", date("Y"))); 448 $nextmonth1 = date("Y-m-t", strtotime("+1 Month")); 449 450 $lastweek0 = date("Y-m-d",strtotime("-2 week Sunday")); 451 $lastweek1 = date("Y-m-d",strtotime("-1 week Saturday")); 452 453 $thisweek0 = date("Y-m-d",strtotime("-1 week Sunday")); 454 $thisweek1 = date("Y-m-d",strtotime("this Saturday")); 455 456 $nextweek0 = date("Y-m-d",strtotime("this Sunday")); 457 $nextweek1 = date("Y-m-d",strtotime("+1 week Saturday")); 458 459 $next7days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+6, date("Y"))); 460 $next30days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+29, date("Y"))); 461 $next60days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+59, date("Y"))); 462 $next90days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+89, date("Y"))); 463 $next120days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+119, date("Y"))); 464 465 $last7days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-6, date("Y"))); 466 $last30days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-29, date("Y"))); 467 $last60days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-59, date("Y"))); 468 $last90days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-89, date("Y"))); 469 $last120days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-119, date("Y"))); 470 471 $currentFY0 = date("Y-m-d",mktime(0, 0, 0, "01", "01", date("Y"))); 472 $currentFY1 = date("Y-m-t",mktime(0, 0, 0, "12", date("d"), date("Y"))); 473 $lastFY0 = date("Y-m-d",mktime(0, 0, 0, "01", "01", date("Y")-1)); 474 $lastFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y")-1)); 475 476 $nextFY0 = date("Y-m-d",mktime(0, 0, 0, "01", "01", date("Y")+1)); 477 $nextFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y")+1)); 478 479 if(date("m") <= 4) 480 { 481 $cFq = date("Y-m-d",mktime(0, 0, 0, "01","01",date("Y"))); 482 $cFq1 = date("Y-m-d",mktime(0, 0, 0, "04","30",date("Y"))); 483 $nFq = date("Y-m-d",mktime(0, 0, 0, "05","01",date("Y"))); 484 $nFq1 = date("Y-m-d",mktime(0, 0, 0, "08","31",date("Y"))); 485 $pFq = date("Y-m-d",mktime(0, 0, 0, "09","01",date("Y")-1)); 486 $pFq1 = date("Y-m-d",mktime(0, 0, 0, "12","31",date("Y")-1)); 487 }else if(date("m") > 4 and date("m") <= 8) 488 { 489 $pFq = date("Y-m-d",mktime(0, 0, 0, "01","01",date("Y"))); 490 $pFq1 = date("Y-m-d",mktime(0, 0, 0, "04","30",date("Y"))); 491 $cFq = date("Y-m-d",mktime(0, 0, 0, "05","01",date("Y"))); 492 $cFq1 = date("Y-m-d",mktime(0, 0, 0, "08","31",date("Y"))); 493 $nFq = date("Y-m-d",mktime(0, 0, 0, "09","01",date("Y"))); 494 $nFq1 = date("Y-m-d",mktime(0, 0, 0, "12","31",date("Y"))); 495 496 }else 497 { 498 $nFq = date("Y-m-d",mktime(0, 0, 0, "01","01",date("Y")+1)); 499 $nFq1 = date("Y-m-d",mktime(0, 0, 0, "04","30",date("Y")+1)); 500 $pFq = date("Y-m-d",mktime(0, 0, 0, "05","01",date("Y"))); 501 $pFq1 = date("Y-m-d",mktime(0, 0, 0, "08","31",date("Y"))); 502 $cFq = date("Y-m-d",mktime(0, 0, 0, "09","01",date("Y"))); 503 $cFq1 = date("Y-m-d",mktime(0, 0, 0, "12","31",date("Y"))); 504 } 505 506 $sjsStr = '<script language="JavaScript" type="text/javaScript"> 507 function showDateRange( type ) 508 { 509 if (type!="custom") 510 { 511 document.CustomView.startdate.readOnly=true 512 document.CustomView.enddate.readOnly=true 513 getObj("jscal_trigger_date_start").style.visibility="hidden" 514 getObj("jscal_trigger_date_end").style.visibility="hidden" 515 } 516 else 517 { 518 document.CustomView.startdate.readOnly=false 519 document.CustomView.enddate.readOnly=false 520 getObj("jscal_trigger_date_start").style.visibility="visible" 521 getObj("jscal_trigger_date_end").style.visibility="visible" 522 } 523 if( type == "today" ) 524 { 525 document.CustomView.startdate.value = "'.$today.'"; 526 document.CustomView.enddate.value = "'.$today.'"; 527 } 528 else if( type == "yesterday" ) 529 { 530 document.CustomView.startdate.value = "'.$yesterday.'"; 531 document.CustomView.enddate.value = "'.$yesterday.'"; 532 } 533 else if( type == "tomorrow" ) 534 { 535 536 document.CustomView.startdate.value = "'.$tomorrow.'"; 537 document.CustomView.enddate.value = "'.$tomorrow.'"; 538 } 539 else if( type == "thisweek" ) 540 { 541 document.CustomView.startdate.value = "'.$thisweek0.'"; 542 document.CustomView.enddate.value = "'.$thisweek1.'"; 543 } 544 else if( type == "lastweek" ) 545 { 546 document.CustomView.startdate.value = "'.$lastweek0.'"; 547 document.CustomView.enddate.value = "'.$lastweek1.'"; 548 } 549 else if( type == "nextweek" ) 550 { 551 document.CustomView.startdate.value = "'.$nextweek0.'"; 552 document.CustomView.enddate.value = "'.$nextweek1.'"; 553 } 554 else if( type == "thismonth" ) 555 { 556 document.CustomView.startdate.value = "'.$currentmonth0.'"; 557 document.CustomView.enddate.value = "'.$currentmonth1.'"; 558 } 559 else if( type == "lastmonth" ) 560 { 561 document.CustomView.startdate.value = "'.$lastmonth0.'"; 562 document.CustomView.enddate.value = "'.$lastmonth1.'"; 563 } 564 else if( type == "nextmonth" ) 565 { 566 document.CustomView.startdate.value = "'.$nextmonth0.'"; 567 document.CustomView.enddate.value = "'.$nextmonth1.'"; 568 } 569 else if( type == "next7days" ) 570 { 571 document.CustomView.startdate.value = "'.$today.'"; 572 document.CustomView.enddate.value = "'.$next7days.'"; 573 } 574 else if( type == "next30days" ) 575 { 576 document.CustomView.startdate.value = "'.$today.'"; 577 document.CustomView.enddate.value = "'.$next30days.'"; 578 } 579 else if( type == "next60days" ) 580 { 581 document.CustomView.startdate.value = "'.$today.'"; 582 document.CustomView.enddate.value = "'.$next60days.'"; 583 } 584 else if( type == "next90days" ) 585 { 586 document.CustomView.startdate.value = "'.$today.'"; 587 document.CustomView.enddate.value = "'.$next90days.'"; 588 } 589 else if( type == "next120days" ) 590 { 591 document.CustomView.startdate.value = "'.$today.'"; 592 document.CustomView.enddate.value = "'.$next120days.'"; 593 } 594 else if( type == "last7days" ) 595 { 596 document.CustomView.startdate.value = "'.$last7days.'"; 597 document.CustomView.enddate.value = "'.$today.'"; 598 } 599 else if( type == "last30days" ) 600 { 601 document.CustomView.startdate.value = "'.$last30days.'"; 602 document.CustomView.enddate.value = "'.$today.'"; 603 } 604 else if( type == "last60days" ) 605 { 606 document.CustomView.startdate.value = "'.$last60days.'"; 607 document.CustomView.enddate.value = "'.$today.'"; 608 } 609 else if( type == "last90days" ) 610 { 611 document.CustomView.startdate.value = "'.$last90days.'"; 612 document.CustomView.enddate.value = "'.$today.'"; 613 } 614 else if( type == "last120days" ) 615 { 616 document.CustomView.startdate.value = "'.$last120days.'"; 617 document.CustomView.enddate.value = "'.$today.'"; 618 } 619 else if( type == "thisfy" ) 620 { 621 document.CustomView.startdate.value = "'.$currentFY0.'"; 622 document.CustomView.enddate.value = "'.$currentFY1.'"; 623 } 624 else if( type == "prevfy" ) 625 { 626 document.CustomView.startdate.value = "'.$lastFY0.'"; 627 document.CustomView.enddate.value = "'.$lastFY1.'"; 628 } 629 else if( type == "nextfy" ) 630 { 631 document.CustomView.startdate.value = "'.$nextFY0.'"; 632 document.CustomView.enddate.value = "'.$nextFY1.'"; 633 } 634 else if( type == "nextfq" ) 635 { 636 document.CustomView.startdate.value = "'.$nFq.'"; 637 document.CustomView.enddate.value = "'.$nFq1.'"; 638 } 639 else if( type == "prevfq" ) 640 { 641 document.CustomView.startdate.value = "'.$pFq.'"; 642 document.CustomView.enddate.value = "'.$pFq1.'"; 643 } 644 else if( type == "thisfq" ) 645 { 646 document.CustomView.startdate.value = "'.$cFq.'"; 647 document.CustomView.enddate.value = "'.$cFq1.'"; 648 } 649 else 650 { 651 document.CustomView.startdate.value = ""; 652 document.CustomView.enddate.value = ""; 653 } 654 } 655 </script>'; 656 657 return $sjsStr; 658 } 659 660 /** to get the standard filter for the given customview Id 661 * @param $cvid :: Type Integer 662 * @returns $stdfilterlist Array in the following format 663 * $stdfilterlist = Array( 'columnname' => $tablename:$columnname:$fieldname:$module_$fieldlabel,'stdfilter'=>$stdfilter,'startdate'=>$startdate,'enddate'=>$enddate) 664 */ 665 666 function getStdFilterByCvid($cvid) 667 { 668 global $adb; 669 670 $sSQL = "select vtiger_cvstdfilter.* from vtiger_cvstdfilter inner join vtiger_customview on vtiger_customview.cvid = vtiger_cvstdfilter.cvid"; 671 $sSQL .= " where vtiger_cvstdfilter.cvid=".$cvid; 672 673 $result = $adb->query($sSQL); 674 $stdfilterrow = $adb->fetch_array($result); 675 676 $stdfilterlist["columnname"] = $stdfilterrow["columnname"]; 677 $stdfilterlist["stdfilter"] = $stdfilterrow["stdfilter"]; 678 679 if($stdfilterrow["stdfilter"] == "custom") 680 { 681 if($stdfilterrow["startdate"] != "0000-00-00") 682 { 683 $stdfilterlist["startdate"] = $stdfilterrow["startdate"]; 684 } 685 if($stdfilterrow["enddate"] != "0000-00-00") 686 { 687 $stdfilterlist["enddate"] = $stdfilterrow["enddate"]; 688 } 689 }else //if it is not custom get the date according to the selected duration 690 { 691 $datefilter = $this->getDateforStdFilterBytype($stdfilterrow["stdfilter"]); 692 $stdfilterlist["startdate"] = $datefilter[0]; 693 $stdfilterlist["enddate"] = $datefilter[1]; 694 } 695 696 return $stdfilterlist; 697 } 698 699 /** to get the Advanced filter for the given customview Id 700 * @param $cvid :: Type Integer 701 * @returns $stdfilterlist Array in the following format 702 * $stdfilterlist = Array( 0=>Array('columnname' => $tablename:$columnname:$fieldname:$module_$fieldlabel,'comparator'=>$comparator,'value'=>$value), 703 * 1=>Array('columnname' => $tablename1:$columnname1:$fieldname1:$module_$fieldlabel1,'comparator'=>$comparator1,'value'=>$value1), 704 * | 705 * 4=>Array('columnname' => $tablename4:$columnname4:$fieldname4:$module_$fieldlabel4,'comparator'=>$comparatorn,'value'=>$valuen), 706 */ 707 function getAdvFilterByCvid($cvid) 708 { 709 global $adb; 710 global $modules; 711 712 $sSQL = "select vtiger_cvadvfilter.* from vtiger_cvadvfilter inner join vtiger_customview on vtiger_cvadvfilter.cvid = vtiger_customview.cvid"; 713 $sSQL .= " where vtiger_cvadvfilter.cvid=".$cvid; 714 $result = $adb->query($sSQL); 715 716 while($advfilterrow = $adb->fetch_array($result)) 717 { 718 $advft["columnname"] = $advfilterrow["columnname"]; 719 $advft["comparator"] = $advfilterrow["comparator"]; 720 $advft["value"] = $advfilterrow["value"]; 721 $advfilterlist[] = $advft; 722 } 723 724 return $advfilterlist; 725 } 726 727 728 /** to get the customview Columnlist Query for the given customview Id 729 * @param $cvid :: Type Integer 730 * @returns $getCvColumnList as a string 731 * This function will return the columns for the given customfield in comma seperated values in the format 732 * $tablename.$columnname,$tablename1.$columnname1, ------ $tablenamen.$columnnamen 733 * 734 */ 735 function getCvColumnListSQL($cvid) 736 { 737 $columnslist = $this->getColumnsListByCvid($cvid); 738 if(isset($columnslist)) 739 { 740 foreach($columnslist as $columnname=>$value) 741 { 742 $tablefield = ""; 743 if($value != "") 744 { 745 $list = explode(":",$value); 746 747 //Added For getting status for Activities -Jaguar 748 $sqllist_column = $list[0].".".$list[1]; 749 if($this->customviewmodule == "Calendar") 750 { 751 if($list[1] == "status") 752 { 753 $sqllist_column = "case when (vtiger_activity.status not like '') then vtiger_activity.status else vtiger_activity.eventstatus end as activitystatus"; 754 } 755 } 756 757 //Added for for assigned to sorting 758 if($list[1] == "smownerid") 759 { 760 $sqllist_column = "case when (vtiger_users.user_name not like '') then vtiger_users.user_name else vtiger_groups.groupname end as user_name"; 761 } 762 763 $sqllist[] = $sqllist_column; 764 //Ends 765 766 $tablefield[$list[0]] = $list[1]; 767 $fieldlabel = trim(str_replace($this->escapemodule," ",$list[3])); 768 $this->list_fields[$fieldlabel] = $tablefield; 769 $this->list_fields_name[$fieldlabel] = $list[2]; 770 } 771 } 772 $returnsql = implode(",",$sqllist); 773 } 774 return $returnsql; 775 776 } 777 778 /** to get the customview stdFilter Query for the given customview Id 779 * @param $cvid :: Type Integer 780 * @returns $stdfiltersql as a string 781 * This function will return the standard filter criteria for the given customfield 782 * 783 */ 784 function getCVStdFilterSQL($cvid) 785 { 786 global $adb; 787 $stdfilterlist = $this->getStdFilterByCvid($cvid); 788 if(isset($stdfilterlist)) 789 { 790 foreach($stdfilterlist as $columnname=>$value) 791 { 792 if($columnname == "columnname") 793 { 794 $filtercolumn = $value; 795 }elseif($columnname == "stdfilter") 796 { 797 $filtertype = $value; 798 }elseif($columnname == "startdate") 799 { 800 $startdate = $value; 801 }elseif($columnname == "enddate") 802 { 803 $enddate = $value; 804 } 805 } 806 if($filtertype != "custom") 807 { 808 $datearray = $this->getDateforStdFilterBytype($filtertype); 809 $startdate = $datearray[0]; 810 $enddate = $datearray[1]; 811 } 812 if($startdate != "" && $enddate != "") 813 { 814 $columns = explode(":",$filtercolumn); 815 $stdfiltersql = $columns[0].".".$columns[1]." between '".$startdate." 00:00:00' and '".$enddate." 23:59:00'"; 816 } 817 } 818 return $stdfiltersql; 819 } 820 /** to get the customview AdvancedFilter Query for the given customview Id 821 * @param $cvid :: Type Integer 822 * @returns $advfiltersql as a string 823 * This function will return the advanced filter criteria for the given customfield 824 * 825 */ 826 function getCVAdvFilterSQL($cvid) 827 { 828 $advfilter = $this->getAdvFilterByCvid($cvid); 829 if(isset($advfilter)) 830 { 831 foreach($advfilter as $key=>$advfltrow) 832 { 833 if(isset($advfltrow)) 834 { 835 $columns = explode(":",$advfltrow["columnname"]); 836 $datatype = (isset($columns[4])) ? $columns[4] : ""; 837 if($advfltrow["columnname"] != "" && $advfltrow["comparator"] != "") 838 { 839 840 $valuearray = explode(",",trim($advfltrow["value"])); 841 if(isset($valuearray) && count($valuearray) > 1) 842 { 843 $advorsql = ""; 844 for($n=0;$n<count($valuearray);$n++) 845 { 846 $advorsql[] = $this->getRealValues($columns[0],$columns[1],$advfltrow["comparator"],trim($valuearray[$n]),$datatype); 847 } 848 $advorsqls = implode(" or ",$advorsql); 849 $advfiltersql[] = " (".$advorsqls.") "; 850 }else 851 { 852 //Added for getting vtiger_activity Status -Jaguar 853 if($this->customviewmodule == "Calendar" && $columns[1] == "status") 854 { 855 $advfiltersql[] = "case when (vtiger_activity.status not like '') then vtiger_activity.status else vtiger_activity.eventstatus end".$this->getAdvComparator($advfltrow["comparator"],trim($advfltrow["value"]),$datatype); 856 } 857 else 858 { 859 $advfiltersql[] = $this->getRealValues($columns[0],$columns[1],$advfltrow["comparator"],trim($advfltrow["value"]),$datatype); 860 } 861 } 862 } 863 } 864 } 865 } 866 if(isset($advfiltersql)) 867 { 868 $advfsql = implode(" and ",$advfiltersql); 869 } 870 return $advfsql; 871 } 872 873 /** to get the realvalues for the given value 874 * @param $tablename :: type string 875 * @param $fieldname :: type string 876 * @param $comparator :: type string 877 * @param $value :: type string 878 * @returns $value as a string in the following format 879 * $tablename.$fieldname comparator 880 */ 881 function getRealValues($tablename,$fieldname,$comparator,$value,$datatype) 882 { 883 if($fieldname == "smownerid" || $fieldname == "inventorymanager") 884 { 885 $value = $tablename.".".$fieldname.$this->getAdvComparator($comparator,getUserId_Ol($value),$datatype); 886 }else if($fieldname == "parentid") 887 { 888 $value = $tablename.".".$fieldname.$this->getAdvComparator($comparator,$this->getAccountId($value),$datatype); 889 }else if($fieldname == "accountid") 890 { 891 $value = $tablename.".".$fieldname.$this->getAdvComparator($comparator,$this->getAccountId($value),$datatype); 892 }else if($fieldname == "contactid") 893 { 894 $value = $tablename.".".$fieldname.$this->getAdvComparator($comparator,$this->getContactId($value),$datatype); 895 }else if($fieldname == "vendor_id" || $fieldname == "vendorid") 896 { 897 $value = $tablename.".".$fieldname.$this->getAdvComparator($comparator,$this->getVendorId($value),$datatype); 898 }else if($fieldname == "potentialid") 899 { 900 $value = $tablename.".".$fieldname.$this->getAdvComparator($comparator,$this->getPotentialId($value),$datatype); 901 }else if($fieldname == "quoteid") 902 { 903 $value = $tablename.".".$fieldname.$this->getAdvComparator($comparator,$this->getQuoteId($value),$datatype); 904 } 905 else if($fieldname == "product_id") 906 { 907 $value = $tablename.".".$fieldname.$this->getAdvComparator($comparator,$this->getProductId($value),$datatype); 908 } 909 else if($fieldname == "salesorderid") 910 { 911 $value = $tablename.".".$fieldname.$this->getAdvComparator($comparator,$this->getSoId($value),$datatype); 912 } 913 else if($fieldname == "crmid" || $fieldname == "parent_id") 914 { 915 //Added on 14-10-2005 -- for HelpDesk 916 if($this->customviewmodule == 'HelpDesk' && $fieldname == "crmid") 917 { 918 $value = $tablename.".".$fieldname.$this->getAdvComparator($comparator,$value,$datatype); 919 } 920 else 921 { 922 $value = $tablename.".".$fieldname." in (".$this->getSalesEntityId($value).") "; 923 } 924 } 925 else 926 { 927 $value = $tablename.".".$fieldname.$this->getAdvComparator($comparator,$value,$datatype); 928 } 929 return $value; 930 } 931 932 /** to get the entityId for the given module 933 * @param $setype :: type string 934 * @returns $parent_id as a string of comma seperated id 935 * $id,$id1,$id2, ---- $idn 936 */ 937 938 function getSalesEntityId($setype) 939 { 940 global $log; 941 $log->info("in getSalesEntityId ".$setype); 942 global $adb; 943 $sql = "select crmid from vtiger_crmentity where setype='".$setype."' and deleted = 0"; 944 $result = $adb->query($sql); 945 while($row = $adb->fetch_array($result)) 946 { 947 $parent_id[] = $row["crmid"]; 948 } 949 if(isset($parent_id)) 950 { 951 $parent_id = implode(",",$parent_id); 952 }else 953 { 954 $parent_id = 0; 955 } 956 return $parent_id; 957 } 958 959 /** to get the salesorder id for the given sales order subject 960 * @param $so_name :: type string 961 * @returns $so_id as a Integer 962 */ 963 964 function getSoId($so_name) 965 { 966 global $log; 967 $log->info("in getSoId ".$so_name); 968 global $adb; 969 if($so_name != '') 970 { 971 $sql = "select salesorderid from vtiger_salesorder where subject='".$so_name."'"; 972 $result = $adb->query($sql); 973 $so_id = $adb->query_result($result,0,"salesorderid"); 974 } 975 return $so_id; 976 } 977 978 /** to get the Product id for the given Product Name 979 * @param $product_name :: type string 980 * @returns $productid as a Integer 981 */ 982 983 function getProductId($product_name) 984 { 985 global $log; 986 $log->info("in getProductId ".$product_name); 987 global $adb; 988 if($product_name != '') 989 { 990 $sql = "select productid from vtiger_products where productname='".$product_name."'"; 991 $result = $adb->query($sql); 992 $productid = $adb->query_result($result,0,"productid"); 993 } 994 return $productid; 995 } 996 997 /** to get the Quote id for the given Quote Name 998 * @param $quote_name :: type string 999 * @returns $quote_id as a Integer 1000 */ 1001 1002 function getQuoteId($quote_name) 1003 { 1004 global $log; 1005 $log->info("in getQuoteId ".$quote_name); 1006 global $adb; 1007 if($quote_name != '') 1008 { 1009 $sql = "select quoteid from vtiger_quotes where subject='".$quote_name."'"; 1010 $result = $adb->query($sql); 1011 $quote_id = $adb->query_result($result,0,"quoteid"); 1012 } 1013 return $quote_id; 1014 } 1015 1016 /** to get the Potential id for the given Potential Name 1017 * @param $pot_name :: type string 1018 * @returns $potentialid as a Integer 1019 */ 1020 1021 function getPotentialId($pot_name) 1022 { 1023 global $log; 1024 $log->info("in getPotentialId ".$pot_name); 1025 global $adb; 1026 if($pot_name != '') 1027 { 1028 $sql = "select potentialid from vtiger_potential where potentialname='".$pot_name."'"; 1029 $result = $adb->query($sql); 1030 $potentialid = $adb->query_result($result,0,"potentialid"); 1031 } 1032 return $potentialid; 1033 } 1034 1035 /** to get the Vendor id for the given Vendor Name 1036 * @param $vendor_name :: type string 1037 * @returns $vendor_id as a Integer 1038 */ 1039 1040 1041 function getVendorId($vendor_name) 1042 { 1043 global $log; 1044 $log->info("in getVendorId ".$vendor_name); 1045 global $adb; 1046 if($vendor_name != '') 1047 { 1048 $sql = "select vendorid from vtiger_vendor where vendorname='".$vendor_name."'"; 1049 $result = $adb->query($sql); 1050 $vendor_id = $adb->query_result($result,0,"vendorid"); 1051 } 1052 return $vendor_id; 1053 } 1054 1055 /** to get the Contact id for the given Contact Name 1056 * @param $contact_name :: type string 1057 * @returns $contact_id as a Integer 1058 */ 1059 1060 1061 function getContactId($contact_name) 1062 { 1063 global $log; 1064 $log->info("in getContactId ".$contact_name); 1065 global $adb; 1066 if($contact_name != '') 1067 { 1068 $sql = "select contactid from vtiger_contactdetails where lastname='".$contact_name."'"; 1069 $result = $adb->query($sql); 1070 $contact_id = $adb->query_result($result,0,"contactid"); 1071 } 1072 return $contact_id; 1073 } 1074 1075 /** to get the Account id for the given Account Name 1076 * @param $account_name :: type string 1077 * @returns $accountid as a Integer 1078 */ 1079 1080 function getAccountId($account_name) 1081 { 1082 global $log; 1083 $log->info("in getAccountId ".$account_name); 1084 global $adb; 1085 if($account_name != '') 1086 { 1087 $sql = "select accountid from vtiger_account where accountname='".$account_name."'"; 1088 $result = $adb->query($sql); 1089 $accountid = $adb->query_result($result,0,"accountid"); 1090 } 1091 return $accountid; 1092 } 1093 1094 /** to get the comparator value for the given comparator and value 1095 * @param $comparator :: type string 1096 * @param $value :: type string 1097 * @returns $rtvalue in the format $comparator $value 1098 */ 1099 1100 function getAdvComparator($comparator,$value,$datatype = '') 1101 { 1102 1103 global $adb; 1104 if($comparator == "e") 1105 { 1106 if(trim($value) == "NULL") 1107 { 1108 $rtvalue = " is NULL"; 1109 }elseif(trim($value) != "") 1110 { 1111 $rtvalue = " = ".$adb->quote($value); 1112 }elseif(trim($value) == "" && $datatype == "V") 1113 { 1114 $rtvalue = " = ".$adb->quote($value); 1115 }else 1116 { 1117 $rtvalue = " is NULL"; 1118 } 1119 } 1120 if($comparator == "n") 1121 { 1122 if(trim($value) == "NULL") 1123 { 1124 $rtvalue = " is NOT NULL"; 1125 }elseif(trim($value) != "") 1126 { 1127 $rtvalue = " <> ".$adb->quote($value); 1128 }elseif(trim($value) == "" && $datatype == "V") 1129 { 1130 $rtvalue = " <> ".$adb->quote($value); 1131 }else 1132 { 1133 $rtvalue = " is NOT NULL"; 1134 } 1135 } 1136 if($comparator == "s") 1137 { 1138 $rtvalue = " like ".$adb->quote($value."%"); 1139 } 1140 if($comparator == "c") 1141 { 1142 $rtvalue = " like ".$adb->quote("%".$value."%"); 1143 } 1144 if($comparator == "k") 1145 { 1146 $rtvalue = " not like ".$adb->quote("%".$value."%"); 1147 } 1148 if($comparator == "l") 1149 { 1150 $rtvalue = " < ".$adb->quote($value); 1151 } 1152 if($comparator == "g") 1153 { 1154 $rtvalue = " > ".$adb->quote($value); 1155 } 1156 if($comparator == "m") 1157 { 1158 $rtvalue = " <= ".$adb->quote($value); 1159 } 1160 if($comparator == "h") 1161 { 1162 $rtvalue = " >= ".$adb->quote($value); 1163 } 1164 1165 return $rtvalue; 1166 } 1167 1168 /** to get the date value for the given type 1169 * @param $type :: type string 1170 * @returns $datevalue array in the following format 1171 * $datevalue = Array(0=>$startdate,1=>$enddate) 1172 */ 1173 1174 function getDateforStdFilterBytype($type) 1175 { 1176 $thisyear = date("Y"); 1177 $today = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d"), date("Y"))); 1178 $tomorrow = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+1, date("Y"))); 1179 $yesterday = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-1, date("Y"))); 1180 1181 $currentmonth0 = date("Y-m-d",mktime(0, 0, 0, date("m"), "01", date("Y"))); 1182 $currentmonth1 = date("Y-m-t"); 1183 $lastmonth0 = date("Y-m-d",mktime(0, 0, 0, date("m")-1, "01", date("Y"))); 1184 $lastmonth1 = date("Y-m-t", strtotime("-1 Month")); 1185 $nextmonth0 = date("Y-m-d",mktime(0, 0, 0, date("m")+1, "01", date("Y"))); 1186 $nextmonth1 = date("Y-m-t", strtotime("+1 Month")); 1187 1188 $lastweek0 = date("Y-m-d",strtotime("-2 week Sunday")); 1189 $lastweek1 = date("Y-m-d",strtotime("-1 week Saturday")); 1190 1191 $thisweek0 = date("Y-m-d",strtotime("-1 week Sunday")); 1192 $thisweek1 = date("Y-m-d",strtotime("this Saturday")); 1193 1194 $nextweek0 = date("Y-m-d",strtotime("this Sunday")); 1195 $nextweek1 = date("Y-m-d",strtotime("+1 week Saturday")); 1196 1197 $next7days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+6, date("Y"))); 1198 $next30days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+29, date("Y"))); 1199 $next60days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+59, date("Y"))); 1200 $next90days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+89, date("Y"))); 1201 $next120days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+119, date("Y"))); 1202 1203 $last7days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-6, date("Y"))); 1204 $last30days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-29, date("Y"))); 1205 $last60days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-59, date("Y"))); 1206 $last90days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-89, date("Y"))); 1207 $last120days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-119, date("Y"))); 1208 1209 $currentFY0 = date("Y-m-d",mktime(0, 0, 0, "01", "01", date("Y"))); 1210 $currentFY1 = date("Y-m-t",mktime(0, 0, 0, "12", date("d"), date("Y"))); 1211 $lastFY0 = date("Y-m-d",mktime(0, 0, 0, "01", "01", date("Y")-1)); 1212 $lastFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y")-1)); 1213 $nextFY0 = date("Y-m-d",mktime(0, 0, 0, "01", "01", date("Y")+1)); 1214 $nextFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y")+1)); 1215 1216 if(date("m") <= 4) 1217 { 1218 $cFq = date("Y-m-d",mktime(0, 0, 0, "01","01",date("Y"))); 1219 $cFq1 = date("Y-m-d",mktime(0, 0, 0, "04","30",date("Y"))); 1220 $nFq = date("Y-m-d",mktime(0, 0, 0, "05","01",date("Y"))); 1221 $nFq1 = date("Y-m-d",mktime(0, 0, 0, "08","31",date("Y"))); 1222 $pFq = date("Y-m-d",mktime(0, 0, 0, "09","01",date("Y")-1)); 1223 $pFq1 = date("Y-m-d",mktime(0, 0, 0, "12","31",date("Y")-1)); 1224 }else if(date("m") > 4 and date("m") <= 8) 1225 { 1226 $pFq = date("Y-m-d",mktime(0, 0, 0, "01","01",date("Y"))); 1227 $pFq1 = date("Y-m-d",mktime(0, 0, 0, "04","30",date("Y"))); 1228 $cFq = date("Y-m-d",mktime(0, 0, 0, "05","01",date("Y"))); 1229 $cFq1 = date("Y-m-d",mktime(0, 0, 0, "08","31",date("Y"))); 1230 $nFq = date("Y-m-d",mktime(0, 0, 0, "09","01",date("Y"))); 1231 $nFq1 = date("Y-m-d",mktime(0, 0, 0, "12","31",date("Y"))); 1232 1233 }else 1234 { 1235 $nFq = date("Y-m-d",mktime(0, 0, 0, "01","01",date("Y")+1)); 1236 $nFq1 = date("Y-m-d",mktime(0, 0, 0, "04","30",date("Y")+1)); 1237 $pFq = date("Y-m-d",mktime(0, 0, 0, "05","01",date("Y"))); 1238 $pFq1 = date("Y-m-d",mktime(0, 0, 0, "08","31",date("Y"))); 1239 $cFq = date("Y-m-d",mktime(0, 0, 0, "09","01",date("Y"))); 1240 $cFq1 = date("Y-m-d",mktime(0, 0, 0, "12","31",date("Y"))); 1241 } 1242 1243 if($type == "today" ) 1244 { 1245 1246 $datevalue[0] = $today; 1247 $datevalue[1] = $today; 1248 } 1249 elseif($type == "yesterday" ) 1250 { 1251 1252 $datevalue[0] = $yesterday; 1253 $datevalue[1] = $yesterday; 1254 } 1255 elseif($type == "tomorrow" ) 1256 { 1257 1258 $datevalue[0] = $tomorrow; 1259 $datevalue[1] = $tomorrow; 1260 } 1261 elseif($type == "thisweek" ) 1262 { 1263 1264 $datevalue[0] = $thisweek0; 1265 $datevalue[1] = $thisweek1; 1266 } 1267 elseif($type == "lastweek" ) 1268 { 1269 1270 $datevalue[0] = $lastweek0; 1271 $datevalue[1] = $lastweek1; 1272 } 1273 elseif($type == "nextweek" ) 1274 { 1275 1276 $datevalue[0] = $nextweek0; 1277 $datevalue[1] = $nextweek1; 1278 } 1279 elseif($type == "thismonth" ) 1280 { 1281 1282 $datevalue[0] =$currentmonth0; 1283 $datevalue[1] = $currentmonth1; 1284 } 1285 1286 elseif($type == "lastmonth" ) 1287 { 1288 1289 $datevalue[0] = $lastmonth0; 1290 $datevalue[1] = $lastmonth1; 1291 } 1292 elseif($type == "nextmonth" ) 1293 { 1294 1295 $datevalue[0] = $nextmonth0; 1296 $datevalue[1] = $nextmonth1; 1297 } 1298 elseif($type == "next7days" ) 1299 { 1300 1301 $datevalue[0] = $today; 1302 $datevalue[1] = $next7days; 1303 } 1304 elseif($type == "next30days" ) 1305 { 1306 1307 $datevalue[0] =$today; 1308 $datevalue[1] =$next30days; 1309 } 1310 elseif($type == "next60days" ) 1311 { 1312 1313 $datevalue[0] = $today; 1314 $datevalue[1] = $next60days; 1315 } 1316 elseif($type == "next90days" ) 1317 { 1318 1319 $datevalue[0] = $today; 1320 $datevalue[1] = $next90days; 1321 } 1322 elseif($type == "next120days" ) 1323 { 1324 1325 $datevalue[0] = $today; 1326 $datevalue[1] = $next120days; 1327 } 1328 elseif($type == "last7days" ) 1329 { 1330 1331 $datevalue[0] = $last7days; 1332 $datevalue[1] = $today; 1333 } 1334 elseif($type == "last30days" ) 1335 { 1336 1337 $datevalue[0] = $last30days; 1338 $datevalue[1] = $today; 1339 } 1340 elseif($type == "last60days" ) 1341 { 1342 1343 $datevalue[0] = $last60days; 1344 $datevalue[1] = $today; 1345 } 1346 else if($type == "last90days" ) 1347 { 1348 1349 $datevalue[0] = $last90days; 1350 $datevalue[1] = $today; 1351 } 1352 elseif($type == "last120days" ) 1353 { 1354 1355 $datevalue[0] = $last120days; 1356 $datevalue[1] = $today; 1357 } 1358 elseif($type == "thisfy" ) 1359 { 1360 1361 $datevalue[0] = $currentFY0; 1362 $datevalue[1] = $currentFY1; 1363 } 1364 elseif($type == "prevfy" ) 1365 { 1366 1367 $datevalue[0] = $lastFY0; 1368 $datevalue[1] = $lastFY1; 1369 } 1370 elseif($type == "nextfy" ) 1371 { 1372 1373 $datevalue[0] = $nextFY0; 1374 $datevalue[1] = $nextFY1; 1375 } 1376 elseif($type == "nextfq" ) 1377 { 1378 1379 $datevalue[0] = $nFq; 1380 $datevalue[1] = $nFq1; 1381 } 1382 elseif($type == "prevfq" ) 1383 { 1384 1385 $datevalue[0] = $pFq; 1386 $datevalue[1] = $pFq1; 1387 } 1388 elseif($type == "thisfq") 1389 { 1390 $datevalue[0] = $cFq; 1391 $datevalue[1] = $cFq1; 1392 } 1393 else 1394 { 1395 $datevalue[0] = ""; 1396 $datevalue[1] = ""; 1397 } 1398 1399 return $datevalue; 1400 } 1401 1402 /** to get the customview query for the given customview 1403 * @param $viewid (custom view id):: type Integer 1404 * @param $listquery (List View Query):: type string 1405 * @param $module (Module Name):: type string 1406 * @returns $query 1407 */ 1408 1409 function getModifiedCvListQuery($viewid,$listquery,$module) 1410 { 1411 if($viewid != "" && $listquery != "") 1412 { 1413 $listviewquery = substr($listquery, strpos($listquery,'FROM'),strlen($listquery)); 1414 if($module == "Calendar" || $module == "Emails") 1415 { 1416 $query = "select ".$this->getCvColumnListSQL($viewid)." ,vtiger_crmentity.crmid,vtiger_activity.* ".$listviewquery; 1417 }else if($module == "Notes") 1418 { 1419 $query = "select ".$this->getCvColumnListSQL($viewid)." ,vtiger_crmentity.crmid,vtiger_notes.* ".$listviewquery; 1420 } 1421 else if($module == "Products") 1422 { 1423 $query = "select ".$this->getCvColumnListSQL($viewid)." ,vtiger_crmentity.crmid,vtiger_products.* ".$listviewquery; 1424 } 1425 else if($module == "Vendors") 1426 { 1427 $query = "select ".$this->getCvColumnListSQL($viewid)." ,vtiger_crmentity.crmid ".$listviewquery; 1428 } 1429 else if($module == "PriceBooks") 1430 { 1431 $query = "select ".$this->getCvColumnListSQL($viewid)." ,vtiger_crmentity.crmid ".$listviewquery; 1432 } 1433 else if($module == "Faq") 1434 { 1435 $query = "select ".$this->getCvColumnListSQL($viewid)." ,vtiger_crmentity.crmid ".$listviewquery; 1436 } 1437 else 1438 { 1439 $query = "select ".$this->getCvColumnListSQL($viewid)." ,vtiger_crmentity.crmid ".$listviewquery; 1440 } 1441 $stdfiltersql = $this->getCVStdFilterSQL($viewid); 1442 $advfiltersql = $this->getCVAdvFilterSQL($viewid); 1443 if(isset($stdfiltersql) && $stdfiltersql != '') 1444 { 1445 $query .= ' and '.$stdfiltersql; 1446 } 1447 if(isset($advfiltersql) && $advfiltersql != '') 1448 { 1449 $query .= ' and '.$advfiltersql; 1450 } 1451 1452 } 1453 return $query; 1454 } 1455 1456 /** to get the Key Metrics for the home page query for the given customview to find the no of records 1457 * @param $viewid (custom view id):: type Integer 1458 * @param $listquery (List View Query):: type string 1459 * @param $module (Module Name):: type string 1460 * @returns $query 1461 */ 1462 function getMetricsCvListQuery($viewid,$listquery,$module) 1463 { 1464 if($viewid != "" && $listquery != "") 1465 { 1466 $listviewquery = substr($listquery, strpos($listquery,'FROM'),strlen($listquery)); 1467 1468 $query = "select count(*) AS count ".$listviewquery; 1469 1470 $stdfiltersql = $this->getCVStdFilterSQL($viewid); 1471 $advfiltersql = $this->getCVAdvFilterSQL($viewid); 1472 if(isset($stdfiltersql) && $stdfiltersql != '') 1473 { 1474 $query .= ' and '.$stdfiltersql; 1475 } 1476 if(isset($advfiltersql) && $advfiltersql != '') 1477 { 1478 $query .= ' and '.$advfiltersql; 1479 } 1480 1481 } 1482 1483 return $query; 1484 } 1485 1486 /** to get the custom action details for the given customview 1487 * @param $viewid (custom view id):: type Integer 1488 * @returns $calist array in the following format 1489 * $calist = Array ('subject'=>$subject, 1490 'module'=>$module, 1491 'content'=>$content, 1492 'cvid'=>$custom view id) 1493 */ 1494 function getCustomActionDetails($cvid) 1495 { 1496 global $adb; 1497 1498 $sSQL = "select vtiger_customaction.* from vtiger_customaction inner join vtiger_customview on vtiger_customaction.cvid = vtiger_customview.cvid"; 1499 $sSQL .= " where vtiger_customaction.cvid=".$cvid; 1500 $result = $adb->query($sSQL); 1501 1502 while($carow = $adb->fetch_array($result)) 1503 { 1504 $calist["subject"] = $carow["subject"]; 1505 $calist["module"] = $carow["module"]; 1506 $calist["content"] = $carow["content"]; 1507 $calist["cvid"] = $carow["cvid"]; 1508 } 1509 return $calist; 1510 } 1511 1512 1513 /* This function sets the block information for the given module to the class variable module_list 1514 * and return the array 1515 */ 1516 1517 function getCustomViewModuleInfo($module) 1518 { 1519 global $adb; 1520 global $current_language; 1521 $current_mod_strings = return_specified_module_language($current_language, $module); 1522 $block_info = Array(); 1523 $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_field.block not in(40,6,75,35,30,54,60,66,72) and vtiger_tab.name='$module' order by block"; 1524 $result = $adb->query($Sql); 1525 while($block_result = $adb->fetch_array($result)) 1526 { 1527 $block_label = $block_result['blocklabel']; 1528 if (trim($block_label) == '') 1529 { 1530 $block_info[$pre_block_label] = $block_info[$pre_block_label].",".$block_result['block']; 1531 }else 1532 { 1533 $lan_block_label = $current_mod_strings[$block_label]; 1534 $block_info[$lan_block_label] = $block_result['block']; 1535 } 1536 $pre_block_label = $lan_block_label; 1537 } 1538 $this->module_list[$module] = $block_info; 1539 return $this->module_list; 1540 } 1541 1542 } 1543 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |