[ 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 require_once ('include/database/PearDatabase.php'); 12 require_once ('data/CRMEntity.php'); 13 require_once ('include/utils/UserInfoUtil.php'); 14 global $calpath; 15 global $app_strings,$mod_strings; 16 global $app_list_strings; 17 global $modules; 18 global $blocks; 19 global $adv_filter_options; 20 global $log; 21 22 global $report_modules; 23 global $related_modules; 24 25 $adv_filter_options = array("e"=>"equals", 26 "n"=>"not equal to", 27 "s"=>"starts with", 28 "c"=>"contains", 29 "k"=>"does not contain", 30 "l"=>"less than", 31 "g"=>"greater than", 32 "m"=>"less or equal", 33 "h"=>"greater or equal" 34 ); 35 36 $report_modules = Array('Leads','Accounts','Contacts','Potentials','Products', 37 'HelpDesk','Quotes','PurchaseOrder','Invoice','Calendar','SalesOrder','Campaigns' 38 ); 39 40 $related_modules = Array('Leads'=>Array(), 41 'Accounts'=>Array('Potentials','Contacts','Products','Quotes','Invoice'), 42 'Contacts'=>Array('Accounts','Potentials','Quotes','PurchaseOrder'), 43 'Potentials'=>Array('Accounts','Contacts','Quotes'), 44 'Calendar'=>Array('Contacts'), 45 'Products'=>Array('Accounts','Contacts'), 46 'HelpDesk'=>Array('Products'), 47 'Quotes'=>Array('Accounts','Contacts','Potentials'), 48 'PurchaseOrder'=>Array('Contacts'), 49 'SalesOrder'=>Array(), 50 'Invoice'=>Array('Accounts'), 51 'Campaigns'=>Array('Products') 52 ); 53 54 foreach($report_modules as $values) 55 { 56 $modules[] = $values."_"; 57 } 58 $modules[] = "_"; 59 60 class Reports extends CRMEntity{ 61 62 63 64 /** 65 * This class has the informations for Reports and inherits class CRMEntity and 66 * has the variables required to generate,save,restore vtiger_reports 67 * and also the required functions for the same 68 * Contributor(s): ______________________________________.. 69 */ 70 71 72 var $srptfldridjs; 73 74 var $column_fields = Array(); 75 76 var $sort_fields = Array(); 77 var $sort_values = Array(); 78 79 var $id; 80 var $mode; 81 var $mcount; 82 83 var $startdate; 84 var $enddate; 85 86 var $ascdescorder; 87 88 var $stdselectedfilter; 89 var $stdselectedcolumn; 90 91 var $primodule; 92 var $secmodule; 93 var $columnssummary; 94 95 var $reporttype; 96 var $reportname; 97 var $reportdescription; 98 var $folderid; 99 var $module_blocks; 100 101 var $pri_module_columnslist; 102 var $sec_module_columnslist; 103 104 var $advft_column; 105 var $advft_option; 106 var $advft_value; 107 108 var $module_list = Array( 109 "Leads"=>Array("Information"=>13,"Address"=>15,"Description"=>16,"Custom Information"=>14), 110 "Contacts"=>Array("Information"=>4,"- Portal Information"=>6,"Address"=>7,"Description"=>8,"Custom Information"=>5), 111 "Accounts"=>Array("Information"=>9,"Address"=>11,"Description"=>12,"Custom Information"=>10), 112 "Potentials"=>Array("Information"=>1,"Description"=>3,"Custom Information"=>2), 113 "Calendar"=>Array("Information"=>19,"Description"=>20), 114 "Campaigns"=>Array("Information"=>76,"Expectations"=>78,"Description"=>82,"Custom Information"=>77), 115 "Products"=>Array("Information"=>31,"Description"=>36,"Pricing Information"=>32,"Stock Information"=>33,"Custom Information"=>34), 116 "Notes"=>Array("Information"=>17,"Description"=>18), 117 "Emails"=>Array("Information"=>21,"Description"=>24), 118 "HelpDesk"=>Array("Information"=>'25,26',"Custom Information"=>27,"Description"=>28,"Solution"=>29),//patch2 119 "Quotes"=>Array("Information"=>51,"Address"=>53,"Description"=>56,"Terms and Conditions"=>55,"Custom Information"=>52), 120 "PurchaseOrder"=>Array("Information"=>57,"Address"=>59,"Description"=>62,"Terms and Conditions"=>61,"Custom Information"=>58), 121 "SalesOrder"=>Array("Information"=>63,"Address"=>65,"Description"=>68,"Terms and Conditions"=>67,"Custom Information"=>64), 122 "Invoice"=>Array("Information"=>69,"Address"=>71,"Description"=>74,"Terms and Conditions"=>73,"Custom Information"=>70) 123 ); 124 125 /** Function to set primodule,secmodule,reporttype,reportname,reportdescription,folderid for given vtiger_reportid 126 * This function accepts the vtiger_reportid as argument 127 * It sets primodule,secmodule,reporttype,reportname,reportdescription,folderid for the given vtiger_reportid 128 */ 129 130 function Reports($reportid="") 131 { 132 global $adb; 133 134 if($reportid != "") 135 { 136 $ssql = "select vtiger_reportmodules.*,vtiger_report.* from vtiger_report inner join vtiger_reportmodules on vtiger_report.reportid = vtiger_reportmodules.reportmodulesid"; 137 $ssql .= " where vtiger_report.reportid =".$reportid; 138 $result = $adb->query($ssql); 139 $reportmodulesrow = $adb->fetch_array($result); 140 if($reportmodulesrow) 141 { 142 $this->primodule = $reportmodulesrow["primarymodule"]; 143 $this->secmodule = $reportmodulesrow["secondarymodules"]; 144 $this->reporttype = $reportmodulesrow["reporttype"]; 145 $this->reportname = $reportmodulesrow["reportname"]; 146 $this->reportdescription = $reportmodulesrow["description"]; 147 $this->folderid = $reportmodulesrow["folderid"]; 148 } 149 } 150 } 151 152 153 /** Function to get the Listview of Reports 154 * This function accepts no argument 155 * This generate the Reports view page and returns a string 156 * contains HTML 157 */ 158 159 function sgetRptFldr($mode='') 160 { 161 162 global $adb; 163 global $log; 164 $returndata = Array(); 165 $sql = "select * from vtiger_reportfolder order by folderid"; 166 $result = $adb->query($sql); 167 $reportfldrow = $adb->fetch_array($result); 168 if($mode != '') 169 { 170 do 171 { 172 if($reportfldrow["state"] == $mode) 173 { 174 $details = Array(); 175 $details['state'] = $reportfldrow["state"]; 176 $details['id'] = $reportfldrow["folderid"]; 177 $details['name'] = $reportfldrow["foldername"]; 178 $details['description'] = $reportfldrow["description"]; 179 $details['details'] = $this->sgetRptsforFldr($reportfldrow["folderid"]); 180 $returndata[] = $details; 181 } 182 }while($reportfldrow = $adb->fetch_array($result)); 183 }else 184 { 185 do 186 { 187 $details = Array(); 188 $details['state'] = $reportfldrow["state"]; 189 $details['id'] = $reportfldrow["folderid"]; 190 $details['name'] = $reportfldrow["foldername"]; 191 $details['description'] = $reportfldrow["description"]; 192 $returndata[] = $details; 193 }while($reportfldrow = $adb->fetch_array($result)); 194 } 195 196 $log->info("Reports :: ListView->Successfully returned vtiger_report folder HTML"); 197 return $returndata; 198 } 199 200 /** Function to get the Reports inside each modules 201 * This function accepts the folderid 202 * This Generates the Reports under each Reports module 203 * This Returns a HTML sring 204 */ 205 206 function sgetRptsforFldr($rpt_fldr_id) 207 { 208 $srptdetails=""; 209 global $adb; 210 global $log; 211 global $mod_strings; 212 $returndata = Array(); 213 214 require_once ('include/utils/UserInfoUtil.php'); 215 216 $sql = "select vtiger_report.*, vtiger_reportmodules.* from vtiger_report inner join vtiger_reportfolder on vtiger_reportfolder.folderid = vtiger_report.folderid"; 217 $sql .= " inner join vtiger_reportmodules on vtiger_reportmodules.reportmodulesid = vtiger_report.reportid where vtiger_reportfolder.folderid=".$rpt_fldr_id; 218 $result = $adb->query($sql); 219 $report = $adb->fetch_array($result); 220 if(count($report)>0) 221 { 222 do 223 { 224 $report_details = Array(); 225 $report_details ['customizable'] = $report["customizable"]; 226 $report_details ['reportid'] = $report["reportid"]; 227 $report_details ['primarymodule'] = $report["primarymodule"]; 228 $report_details ['secondarymodules'] = $report["secondarymodules"]; 229 $report_details ['state'] = $report["state"]; 230 $report_details ['description'] = $report["description"]; 231 $report_details ['reportname'] = $report["reportname"]; 232 233 $returndata []=$report_details; 234 }while($report = $adb->fetch_array($result)); 235 } 236 237 $log->info("Reports :: ListView->Successfully returned vtiger_report details HTML"); 238 return $returndata; 239 } 240 241 /** Function to get the array of ids 242 * This function forms the array for the ExpandCollapse 243 * Javascript 244 * It returns the array of ids 245 * Array('1RptFldr','2RptFldr',........,'9RptFldr','10RptFldr') 246 */ 247 248 function sgetJsRptFldr() 249 { 250 $srptfldr_js = "var ReportListArray=new Array(".$this->srptfldridjs.") 251 setExpandCollapse()"; 252 return $srptfldr_js; 253 } 254 255 /** Function to set the Primary module vtiger_fields for the given Report 256 * This function sets the primary module columns for the given Report 257 * It accepts the Primary module as the argument and set the vtiger_fields of the module 258 * to the varialbe pri_module_columnslist and returns true if sucess 259 */ 260 261 function getPriModuleColumnsList($module) 262 { 263 foreach($this->module_list[$module] as $key=>$value) 264 { 265 $ret_module_list[$module][$key] = $this->getColumnsListbyBlock($module,$value); 266 } 267 $this->pri_module_columnslist = $ret_module_list; 268 return true; 269 } 270 271 /** Function to set the Secondary module fileds for the given Report 272 * This function sets the secondary module columns for the given module 273 * It accepts the module as the argument and set the vtiger_fields of the module 274 * to the varialbe sec_module_columnslist and returns true if sucess 275 */ 276 277 function getSecModuleColumnsList($module) 278 { 279 if($module != "") 280 { 281 $secmodule = explode(":",$module); 282 for($i=0;$i < count($secmodule) ;$i++) 283 { 284 foreach($this->module_list[$secmodule[$i]] as $key=>$value) 285 { 286 $ret_module_list[$secmodule[$i]][$key] = $this->getColumnsListbyBlock($secmodule[$i],$value); 287 } 288 } 289 $this->sec_module_columnslist = $ret_module_list; 290 } 291 return true; 292 } 293 294 /** Function to get vtiger_fields for the given module and block 295 * This function gets the vtiger_fields for the given module 296 * It accepts the module and the block as arguments and 297 * returns the array column lists 298 * Array module_columnlist[ vtiger_fieldtablename:fieldcolname:module_fieldlabel1:fieldname:fieldtypeofdata]=fieldlabel 299 */ 300 301 function getColumnsListbyBlock($module,$block) 302 { 303 global $adb; 304 global $log; 305 global $current_user; 306 307 308 $tabid = getTabid($module); 309 310 311 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 312 //Security Check 313 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] ==0) 314 { 315 $sql = "select * from vtiger_field where vtiger_field.uitype != 50 and vtiger_field.tabid=".$tabid." and vtiger_field.block in (".$block .") and vtiger_field.displaytype in (1,2) order by sequence"; 316 } 317 else 318 { 319 320 $profileList = getCurrentUserProfileList(); 321 $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 where vtiger_field.uitype != 50 and vtiger_field.tabid=".$tabid." and vtiger_field.block in (".$block .") and vtiger_field.displaytype in (1,2) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_profile2field.profileid in ".$profileList." group by vtiger_field.fieldid order by sequence"; 322 } 323 $result = $adb->query($sql); 324 $noofrows = $adb->num_rows($result); 325 for($i=0; $i<$noofrows; $i++) 326 { 327 $fieldtablename = $adb->query_result($result,$i,"tablename"); 328 $fieldcolname = $adb->query_result($result,$i,"columnname"); 329 $fieldname = $adb->query_result($result,$i,"fieldname"); 330 $fieldtype = $adb->query_result($result,$i,"typeofdata"); 331 $fieldtype = explode("~",$fieldtype); 332 $fieldtypeofdata = $fieldtype[0]; 333 if($fieldtablename == "vtiger_crmentity") 334 { 335 $fieldtablename = $fieldtablename.$module; 336 } 337 if($fieldname == "assigned_user_id") 338 { 339 $fieldtablename = "vtiger_users".$module; 340 $fieldcolname = "user_name"; 341 } 342 if($fieldname == "account_id") 343 { 344 $fieldtablename = "vtiger_account".$module; 345 $fieldcolname = "accountname"; 346 } 347 if($fieldname == "contact_id") 348 { 349 $fieldtablename = "vtiger_contactdetails".$module; 350 $fieldcolname = "lastname"; 351 } 352 if($fieldname == "parent_id") 353 { 354 $fieldtablename = "vtiger_crmentityRel".$module; 355 $fieldcolname = "setype"; 356 } 357 if($fieldname == "vendor_id") 358 { 359 $fieldtablename = "vtiger_vendorRel"; 360 $fieldcolname = "vendorname"; 361 } 362 if($fieldname == "potential_id") 363 { 364 $fieldtablename = "vtiger_potentialRel"; 365 $fieldcolname = "potentialname"; 366 } 367 if($fieldname == "assigned_user_id1") 368 { 369 $fieldtablename = "vtiger_usersRel1"; 370 $fieldcolname = "user_name"; 371 } 372 if($fieldname == 'quote_id') 373 { 374 $fieldtablename = "vtiger_quotes".$module; 375 $fieldcolname = "subject"; 376 } 377 if($fieldname == 'product_id' && $fieldtablename == 'vtiger_troubletickets') 378 { 379 $fieldtablename = "vtiger_productsRel"; 380 $fieldcolname = "productname"; 381 } 382 383 $fieldlabel = $adb->query_result($result,$i,"fieldlabel"); 384 $fieldlabel1 = str_replace(" ","_",$fieldlabel); 385 $optionvalue = $fieldtablename.":".$fieldcolname.":".$module."_".$fieldlabel1.":".$fieldname.":".$fieldtypeofdata; 386 //added to escape attachments fields in Reports as we have multiple attachments 387 if($module != 'HelpDesk' || $fieldname !='filename') 388 $module_columnlist[$optionvalue] = $fieldlabel; 389 } 390 $log->info("Reports :: FieldColumns->Successfully returned ColumnslistbyBlock".$module.$block); 391 return $module_columnlist; 392 } 393 394 /** Function to set the standard filter vtiger_fields for the given vtiger_report 395 * This function gets the standard filter vtiger_fields for the given vtiger_report 396 * and set the values to the corresponding variables 397 * It accepts the repordid as argument 398 */ 399 400 function getSelectedStandardCriteria($reportid) 401 { 402 global $adb; 403 $sSQL = "select vtiger_reportdatefilter.* from vtiger_reportdatefilter inner join vtiger_report on vtiger_report.reportid = vtiger_reportdatefilter.datefilterid where vtiger_report.reportid=".$reportid; 404 405 $result = $adb->query($sSQL); 406 $selectedstdfilter = $adb->fetch_array($result); 407 408 $this->stdselectedcolumn = $selectedstdfilter["datecolumnname"]; 409 $this->stdselectedfilter = $selectedstdfilter["datefilter"]; 410 411 if($selectedstdfilter["datefilter"] == "custom") 412 { 413 if($selectedstdfilter["startdate"] != "0000-00-00") 414 { 415 $this->startdate = $selectedstdfilter["startdate"]; 416 } 417 if($selectedstdfilter["enddate"] != "0000-00-00") 418 { 419 $this->enddate = $selectedstdfilter["enddate"]; 420 } 421 } 422 } 423 424 /** Function to get the combo values for the standard filter 425 * This function get the combo values for the standard filter for the given vtiger_report 426 * and return a HTML string 427 */ 428 429 function getSelectedStdFilterCriteria($selecteddatefilter = "") 430 { 431 global $mod_strings; 432 433 $datefiltervalue = Array("custom","prevfy","thisfy","nextfy","prevfq","thisfq","nextfq", 434 "yesterday","today","tomorrow","lastweek","thisweek","nextweek","lastmonth","thismonth", 435 "nextmonth","last7days","last30days", "last60days","last90days","last120days", 436 "next30days","next60days","next90days","next120days" 437 ); 438 439 $datefilterdisplay = Array("Custom","Previous FY", "Current FY","Next FY","Previous FQ","Current FQ","Next FQ","Yesterday", 440 "Today","Tomorrow","Last Week","Current Week","Next Week","Last Month","Current Month", 441 "Next Month","Last 7 Days","Last 30 Days","Last 60 Days","Last 90 Days","Last 120 Days", 442 "Next 7 Days","Next 30 Days","Next 60 Days","Next 90 Days","Next 120 Days" 443 ); 444 445 for($i=0;$i<count($datefiltervalue);$i++) 446 { 447 if($selecteddatefilter == $datefiltervalue[$i]) 448 { 449 $sshtml .= "<option selected value='".$datefiltervalue[$i]."'>".$mod_strings[$datefilterdisplay[$i]]."</option>"; 450 }else 451 { 452 $sshtml .= "<option value='".$datefiltervalue[$i]."'>".$mod_strings[$datefilterdisplay[$i]]."</option>"; 453 } 454 } 455 456 return $sshtml; 457 } 458 459 /** Function to get the selected standard filter columns 460 * This function returns the selected standard filter criteria 461 * which is selected for vtiger_reports as an array 462 * Array stdcriteria_list[fieldtablename:fieldcolname:module_fieldlabel1]=fieldlabel 463 */ 464 465 function getStdCriteriaByModule($module) 466 { 467 global $adb; 468 global $log; 469 global $current_user; 470 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 471 472 $tabid = getTabid($module); 473 foreach($this->module_list[$module] as $key=>$blockid) 474 { 475 $blockids[] = $blockid; 476 } 477 $blockids = implode(",",$blockids); 478 479 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) 480 { 481 $sql = "select * from vtiger_field where vtiger_field.tabid=".$tabid." and (vtiger_field.uitype =5 or vtiger_field.displaytype=2) and vtiger_field.block in (".$blockids.") order by vtiger_field.sequence"; 482 } 483 else 484 { 485 486 $profileList = getCurrentUserProfileList(); 487 $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 where vtiger_field.tabid=".$tabid." and (vtiger_field.uitype =5 or vtiger_field.displaytype=2) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.block in (".$blockids.") and vtiger_profile2field.profileid in ".$profileList." order by vtiger_field.sequence"; 488 489 } 490 491 $result = $adb->query($sql); 492 493 while($criteriatyperow = $adb->fetch_array($result)) 494 { 495 $fieldtablename = $criteriatyperow["tablename"]; 496 $fieldcolname = $criteriatyperow["columnname"]; 497 $fieldlabel = $criteriatyperow["fieldlabel"]; 498 499 if($fieldtablename == "vtiger_crmentity") 500 { 501 $fieldtablename = $fieldtablename.$module; 502 } 503 $fieldlabel1 = str_replace(" ","_",$fieldlabel); 504 $optionvalue = $fieldtablename.":".$fieldcolname.":".$module."_".$fieldlabel1; 505 $stdcriteria_list[$optionvalue] = $fieldlabel; 506 } 507 508 $log->info("Reports :: StdfilterColumns->Successfully returned Stdfilter for".$module); 509 return $stdcriteria_list; 510 511 } 512 513 /** Function to form a javascript to determine the start date and end date for a standard filter 514 * This function is to form a javascript to determine 515 * the start date and End date from the value selected in the combo lists 516 */ 517 518 function getCriteriaJS() 519 { 520 $today = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d"), date("Y"))); 521 $tomorrow = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+1, date("Y"))); 522 $yesterday = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-1, date("Y"))); 523 524 $currentmonth0 = date("Y-m-d",mktime(0, 0, 0, date("m"), "01", date("Y"))); 525 $currentmonth1 = date("Y-m-t"); 526 $lastmonth0 = date("Y-m-d",mktime(0, 0, 0, date("m")-1, "01", date("Y"))); 527 $lastmonth1 = date("Y-m-t", strtotime("-1 Month")); 528 $nextmonth0 = date("Y-m-d",mktime(0, 0, 0, date("m")+1, "01", date("Y"))); 529 $nextmonth1 = date("Y-m-t", strtotime("+1 Month")); 530 531 $lastweek0 = date("Y-m-d",strtotime("-2 week Sunday")); 532 $lastweek1 = date("Y-m-d",strtotime("-1 week Saturday")); 533 534 $thisweek0 = date("Y-m-d",strtotime("-1 week Sunday")); 535 $thisweek1 = date("Y-m-d",strtotime("this Saturday")); 536 537 $nextweek0 = date("Y-m-d",strtotime("this Sunday")); 538 $nextweek1 = date("Y-m-d",strtotime("+1 week Saturday")); 539 540 $next7days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+6, date("Y"))); 541 $next30days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+29, date("Y"))); 542 $next60days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+59, date("Y"))); 543 $next90days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+89, date("Y"))); 544 $next120days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+119, date("Y"))); 545 546 $last7days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-6, date("Y"))); 547 $last30days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-29, date("Y"))); 548 $last60days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-59, date("Y"))); 549 $last90days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-89, date("Y"))); 550 $last120days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-119, date("Y"))); 551 552 $currentFY0 = date("Y-m-d",mktime(0, 0, 0, "01", "01", date("Y"))); 553 $currentFY1 = date("Y-m-t",mktime(0, 0, 0, "12", date("d"), date("Y"))); 554 $lastFY0 = date("Y-m-d",mktime(0, 0, 0, "01", "01", date("Y")-1)); 555 $lastFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y")-1)); 556 $nextFY0 = date("Y-m-d",mktime(0, 0, 0, "01", "01", date("Y")+1)); 557 $nextFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y")+1)); 558 559 560 $sjsStr = '<script language="JavaScript" type="text/javaScript"> 561 function showDateRange( type ) 562 { 563 if (type!="custom") 564 { 565 document.NewReport.startdate.readOnly=true 566 document.NewReport.enddate.readOnly=true 567 getObj("jscal_trigger_date_start").style.visibility="hidden" 568 getObj("jscal_trigger_date_end").style.visibility="hidden" 569 } 570 else 571 { 572 document.NewReport.startdate.readOnly=false 573 document.NewReport.enddate.readOnly=false 574 getObj("jscal_trigger_date_start").style.visibility="visible" 575 getObj("jscal_trigger_date_end").style.visibility="visible" 576 } 577 if( type == "today" ) 578 { 579 580 document.NewReport.startdate.value = "'.$today.'"; 581 document.NewReport.enddate.value = "'.$today.'"; 582 } 583 else if( type == "yesterday" ) 584 { 585 586 document.NewReport.startdate.value = "'.$yesterday.'"; 587 document.NewReport.enddate.value = "'.$yesterday.'"; 588 } 589 else if( type == "tomorrow" ) 590 { 591 592 document.NewReport.startdate.value = "'.$tomorrow.'"; 593 document.NewReport.enddate.value = "'.$tomorrow.'"; 594 } 595 else if( type == "thisweek" ) 596 { 597 598 document.NewReport.startdate.value = "'.$thisweek0.'"; 599 document.NewReport.enddate.value = "'.$thisweek1.'"; 600 } 601 else if( type == "lastweek" ) 602 { 603 604 document.NewReport.startdate.value = "'.$lastweek0.'"; 605 document.NewReport.enddate.value = "'.$lastweek1.'"; 606 } 607 else if( type == "nextweek" ) 608 { 609 610 document.NewReport.startdate.value = "'.$nextweek0.'"; 611 document.NewReport.enddate.value = "'.$nextweek1.'"; 612 } 613 614 else if( type == "thismonth" ) 615 { 616 617 document.NewReport.startdate.value = "'.$currentmonth0.'"; 618 document.NewReport.enddate.value = "'.$currentmonth1.'"; 619 } 620 621 else if( type == "lastmonth" ) 622 { 623 624 document.NewReport.startdate.value = "'.$lastmonth0.'"; 625 document.NewReport.enddate.value = "'.$lastmonth1.'"; 626 } 627 else if( type == "nextmonth" ) 628 { 629 630 document.NewReport.startdate.value = "'.$nextmonth0.'"; 631 document.NewReport.enddate.value = "'.$nextmonth1.'"; 632 } 633 else if( type == "next7days" ) 634 { 635 636 document.NewReport.startdate.value = "'.$today.'"; 637 document.NewReport.enddate.value = "'.$next7days.'"; 638 } 639 else if( type == "next30days" ) 640 { 641 642 document.NewReport.startdate.value = "'.$today.'"; 643 document.NewReport.enddate.value = "'.$next30days.'"; 644 } 645 else if( type == "next60days" ) 646 { 647 648 document.NewReport.startdate.value = "'.$today.'"; 649 document.NewReport.enddate.value = "'.$next60days.'"; 650 } 651 else if( type == "next90days" ) 652 { 653 654 document.NewReport.startdate.value = "'.$today.'"; 655 document.NewReport.enddate.value = "'.$next90days.'"; 656 } 657 else if( type == "next120days" ) 658 { 659 660 document.NewReport.startdate.value = "'.$today.'"; 661 document.NewReport.enddate.value = "'.$next120days.'"; 662 } 663 else if( type == "last7days" ) 664 { 665 666 document.NewReport.startdate.value = "'.$last7days.'"; 667 document.NewReport.enddate.value = "'.$today.'"; 668 } 669 else if( type == "last30days" ) 670 { 671 672 document.NewReport.startdate.value = "'.$last30days.'"; 673 document.NewReport.enddate.value = "'.$today.'"; 674 } 675 else if( type == "last60days" ) 676 { 677 678 document.NewReport.startdate.value = "'.$last60days.'"; 679 document.NewReport.enddate.value = "'.$today.'"; 680 } 681 else if( type == "last90days" ) 682 { 683 684 document.NewReport.startdate.value = "'.$last90days.'"; 685 document.NewReport.enddate.value = "'.$today.'"; 686 } 687 else if( type == "last120days" ) 688 { 689 690 document.NewReport.startdate.value = "'.$last120days.'"; 691 document.NewReport.enddate.value = "'.$today.'"; 692 } 693 else if( type == "thisfy" ) 694 { 695 696 document.NewReport.startdate.value = "'.$currentFY0.'"; 697 document.NewReport.enddate.value = "'.$currentFY1.'"; 698 } 699 else if( type == "prevfy" ) 700 { 701 702 document.NewReport.startdate.value = "'.$lastFY0.'"; 703 document.NewReport.enddate.value = "'.$lastFY1.'"; 704 } 705 else if( type == "nextfy" ) 706 { 707 708 document.NewReport.startdate.value = "'.$nextFY0.'"; 709 document.NewReport.enddate.value = "'.$nextFY1.'"; 710 } 711 else if( type == "nextfq" ) 712 { 713 714 document.NewReport.startdate.value = "2005-07-01"; 715 document.NewReport.enddate.value = "2005-09-30"; 716 } 717 else if( type == "prevfq" ) 718 { 719 720 document.NewReport.startdate.value = "2005-01-01"; 721 document.NewReport.enddate.value = "2005-03-31"; 722 } 723 else if( type == "thisfq" ) 724 { 725 document.NewReport.startdate.value = "2005-04-01"; 726 document.NewReport.enddate.value = "2005-06-30"; 727 } 728 else 729 { 730 document.NewReport.startdate.value = ""; 731 document.NewReport.enddate.value = ""; 732 } 733 } 734 </script>'; 735 736 return $sjsStr; 737 } 738 739 /** Function to set the order of grouping and to find the columns responsible 740 * to the grouping 741 * This function accepts the vtiger_reportid as variable,sets the variable ascdescorder[] to the sort order and 742 * returns the array array_list which has the column responsible for the grouping 743 * Array array_list[0]=columnname 744 */ 745 746 747 function getSelctedSortingColumns($reportid) 748 { 749 750 global $adb; 751 global $log; 752 753 $sreportsortsql = "select vtiger_reportsortcol.* from vtiger_report"; 754 $sreportsortsql .= " inner join vtiger_reportsortcol on vtiger_report.reportid = vtiger_reportsortcol.reportid"; 755 $sreportsortsql .= " where vtiger_report.reportid =".$reportid." order by vtiger_reportsortcol.sortcolid"; 756 757 $result = $adb->query($sreportsortsql); 758 $noofrows = $adb->num_rows($result); 759 760 for($i=0; $i<$noofrows; $i++) 761 { 762 $fieldcolname = $adb->query_result($result,$i,"columnname"); 763 $sort_values = $adb->query_result($result,$i,"sortorder"); 764 $this->ascdescorder[] = $sort_values; 765 $array_list[] = $fieldcolname; 766 } 767 768 $log->info("Reports :: Successfully returned getSelctedSortingColumns"); 769 return $array_list; 770 } 771 772 /** Function to get the selected columns list for a selected vtiger_report 773 * This function accepts the vtiger_reportid as the argument and get the selected columns 774 * for the given vtiger_reportid and it forms a combo lists and returns 775 * HTML of the combo values 776 */ 777 778 function getSelectedColumnsList($reportid) 779 { 780 781 global $adb; 782 global $modules; 783 global $log; 784 785 $ssql = "select vtiger_selectcolumn.* from vtiger_report inner join vtiger_selectquery on vtiger_selectquery.queryid = vtiger_report.queryid"; 786 $ssql .= " left join vtiger_selectcolumn on vtiger_selectcolumn.queryid = vtiger_selectquery.queryid where vtiger_report.reportid =".$reportid; 787 $ssql .= " order by vtiger_selectcolumn.columnindex"; 788 789 $result = $adb->query($ssql); 790 $noofrows = $adb->num_rows($result); 791 792 for($i=0; $i<$noofrows; $i++) 793 { 794 $fieldcolname = $adb->query_result($result,$i,"columnname"); 795 $fieldlist = explode(":",$fieldcolname); 796 797 //Fix for multilanguage support - code contribution by Ding jianting 798 $fieldlabel_array = explode("_",$fieldlist[2]); 799 $mod_strings = return_module_language($current_language,$fieldlabel_array[0]); 800 if($fieldcolname != "") 801 { 802 $fieldlabel = trim(str_replace($modules," ",$fieldlist[2])); 803 if(isset($mod_strings[$fieldlabel])) { 804 $shtml .= "<option value=\"".$fieldcolname."\">".$mod_strings[$fieldlabel]."</option>"; 805 } else { 806 $shtml .= "<option value=\"".$fieldcolname."\">".$fieldlabel."</option>"; 807 } 808 } 809 //Code contribution ends 810 } 811 812 $log->info("Reports :: Successfully returned getSelectedColumnsList"); 813 return $shtml; 814 } 815 816 /** Function to Set the selected columns for the advanced filter for the vtiger_report 817 * This function accepts the vtiger_reportid as the argument and get the selected columns 818 * in the advanced filter and sets the values 819 * $this->advft_column[] = The column name 820 * $this->advft_option[] = The filter option 821 * $this->advft_value[] = The value to be compared 822 * and returns true in sucess 823 */ 824 825 //<<<<<<<<advanced filter>>>>>>>>>>>>>> 826 function getAdvancedFilterList($reportid) 827 { 828 global $adb; 829 global $modules; 830 global $log; 831 $ssql = 'select vtiger_relcriteria.* from vtiger_report inner join vtiger_relcriteria on vtiger_relcriteria.queryid = vtiger_report.queryid left join vtiger_selectquery on vtiger_relcriteria.queryid = vtiger_selectquery.queryid'; 832 $ssql.= " where vtiger_report.reportid =".$reportid." order by vtiger_relcriteria.columnindex"; 833 834 $result = $adb->query($ssql); 835 836 while($relcriteriarow = $adb->fetch_array($result)) 837 { 838 $this->advft_column[] = $relcriteriarow["columnname"]; 839 $this->advft_option[] = $relcriteriarow["comparator"]; 840 $this->advft_value[] = $relcriteriarow["value"]; 841 } 842 843 $log->info("Reports :: Successfully returned getAdvancedFilterList"); 844 return true; 845 } 846 //<<<<<<<<advanced filter>>>>>>>>>>>>>> 847 848 /** Function to get the list of vtiger_report folders when Save and run the vtiger_report 849 * This function gets the vtiger_report folders from database and form 850 * a combo values of the folders and return 851 * HTML of the combo values 852 */ 853 854 function sgetRptFldrSaveReport() 855 { 856 global $adb; 857 global $log; 858 859 $sql = "select * from vtiger_reportfolder order by folderid"; 860 $result = $adb->query($sql); 861 $reportfldrow = $adb->fetch_array($result); 862 $x = 0; 863 do 864 { 865 $shtml .= "<option value='".$reportfldrow['folderid']."'>".$reportfldrow['foldername']."</option>"; 866 }while($reportfldrow = $adb->fetch_array($result)); 867 868 $log->info("Reports :: Successfully returned sgetRptFldrSaveReport"); 869 return $shtml; 870 } 871 872 /** Function to get the column to total vtiger_fields in Reports 873 * This function gets columns to total vtiger_field 874 * and generated the html for that vtiger_fields 875 * It returns the HTML of the vtiger_fields along with the check boxes 876 */ 877 878 function sgetColumntoTotal($primarymodule,$secondarymodule) 879 { 880 $options = Array(); 881 $options []= $this->sgetColumnstoTotalHTML($primarymodule,0); 882 if($secondarymodule != "") 883 { 884 $secondarymodule = explode(":",$secondarymodule); 885 for($i=0;$i < count($secondarymodule) ;$i++) 886 { 887 $options []= $this->sgetColumnstoTotalHTML($secondarymodule[$i],($i+1)); 888 } 889 } 890 return $options; 891 } 892 893 /** Function to get the selected columns of total vtiger_fields in Reports 894 * This function gets selected columns of total vtiger_field 895 * and generated the html for that vtiger_fields 896 * It returns the HTML of the vtiger_fields along with the check boxes 897 */ 898 899 900 function sgetColumntoTotalSelected($primarymodule,$secondarymodule,$reportid) 901 { 902 global $adb; 903 global $log; 904 $options = Array(); 905 if($reportid != "") 906 { 907 $ssql = "select vtiger_reportsummary.* from vtiger_reportsummary inner join vtiger_report on vtiger_report.reportid = vtiger_reportsummary.reportsummaryid where vtiger_report.reportid=".$reportid; 908 $result = $adb->query($ssql); 909 if($result) 910 { 911 $reportsummaryrow = $adb->fetch_array($result); 912 913 do 914 { 915 $this->columnssummary[] = $reportsummaryrow["columnname"]; 916 917 }while($reportsummaryrow = $adb->fetch_array($result)); 918 } 919 } 920 $options []= $this->sgetColumnstoTotalHTML($primarymodule,0); 921 if($secondarymodule != "") 922 { 923 $secondarymodule = explode(":",$secondarymodule); 924 for($i=0;$i < count($secondarymodule) ;$i++) 925 { 926 $options []= $this->sgetColumnstoTotalHTML($secondarymodule[$i],($i+1)); 927 } 928 } 929 930 $log->info("Reports :: Successfully returned sgetColumntoTotalSelected"); 931 return $options; 932 } 933 934 935 /** Function to form the HTML for columns to total 936 * This function formulates the HTML format of the 937 * vtiger_fields along with four checkboxes 938 * It returns the HTML of the vtiger_fields along with the check boxes 939 */ 940 941 942 function sgetColumnstoTotalHTML($module) 943 { 944 //retreive the vtiger_tabid 945 global $adb; 946 global $log; 947 global $current_user; 948 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 949 $tabid = getTabid($module); 950 $escapedchars = Array('_SUM','_AVG','_MIN','_MAX'); 951 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] ==0) 952 { 953 $ssql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid where vtiger_field.uitype != 50 and vtiger_field.tabid=".$tabid." and vtiger_field.displaytype = 1 order by sequence"; 954 } 955 else 956 { 957 $profileList = getCurrentUserProfileList(); 958 $ssql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid where vtiger_field.uitype != 50 and vtiger_field.tabid=".$tabid." and vtiger_field.displaytype = 1 and vtiger_def_org_field.visible=0 and vtiger_profile2field.visible=0 and vtiger_profile2field.profileid in ".$profileList." order by sequence"; 959 } 960 $result = $adb->query($ssql); 961 $columntototalrow = $adb->fetch_array($result); 962 $options_list = Array(); 963 do 964 { 965 $typeofdata = explode("~",$columntototalrow["typeofdata"]); 966 967 if($typeofdata[0] == "N" || $typeofdata[0] == "I") 968 { 969 $options = Array(); 970 if(isset($this->columnssummary)) 971 { 972 $selectedcolumn = ""; 973 $selectedcolumn1 = ""; 974 975 for($i=0;$i < count($this->columnssummary) ;$i++) 976 { 977 $selectedcolumnarray = explode(":",$this->columnssummary[$i]); 978 $selectedcolumn = $selectedcolumnarray[1].":".$selectedcolumnarray[2].":". 979 str_replace($escapedchars,"",$selectedcolumnarray[3]); 980 981 if ($selectedcolumn != $columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.str_replace(" ","_",$columntototalrow['fieldlabel'])) 982 { 983 $selectedcolumn = ""; 984 }else 985 { 986 $selectedcolumn1[$selectedcolumnarray[4]] = $this->columnssummary[$i]; 987 } 988 989 } 990 991 $columntototalrow['fieldlabel'] = str_replace(" ","_",$columntototalrow['fieldlabel']); 992 $options []= $columntototalrow['tablabel'].' - '.$columntototalrow['fieldlabel']; 993 if($selectedcolumn1[2] == "cb:".$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel']."_SUM:2") 994 { 995 $options []= '<input checked name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_SUM:2" type="checkbox" value="">'; 996 }else 997 { 998 $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_SUM:2" type="checkbox" value="">'; 999 } 1000 if($selectedcolumn1[3] == "cb:".$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel']."_AVG:3") 1001 { 1002 $options []= '<input checked name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_AVG:3" type="checkbox" value="">'; 1003 }else 1004 { 1005 $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_AVG:3" type="checkbox" value="">'; 1006 } 1007 1008 if($selectedcolumn1[4] == "cb:".$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel']."_MIN:4") 1009 { 1010 $options []= '<input checked name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_MIN:4" type="checkbox" value="">'; 1011 }else 1012 { 1013 $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_MIN:4" type="checkbox" value="">'; 1014 } 1015 1016 if($selectedcolumn1[5] == "cb:".$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel']."_MAX:5") 1017 { 1018 $options []= '<input checked name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_MAX:5" type="checkbox" value="">'; 1019 }else 1020 { 1021 $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_MAX:5" type="checkbox" value="">'; 1022 } 1023 }else 1024 { 1025 $options []= $columntototalrow['tablabel'].' - '.$columntototalrow['fieldlabel']; 1026 $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_SUM:2" type="checkbox" value="">'; 1027 $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_AVG:3" type="checkbox" value="" >'; 1028 $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_MIN:4"type="checkbox" value="" >'; 1029 $options [] ='<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_MAX:5" type="checkbox" value="" >'; 1030 } 1031 $options_list [] = $options; 1032 } 1033 }while($columntototalrow = $adb->fetch_array($result)); 1034 1035 $log->info("Reports :: Successfully returned sgetColumnstoTotalHTML"); 1036 return $options_list; 1037 } 1038 } 1039 1040 /** Function to get the primary module list in vtiger_reports 1041 * This function generates the list of primary modules in vtiger_reports 1042 * and returns an array of permitted modules 1043 */ 1044 1045 function getReportsModuleList() 1046 { 1047 global $adb; 1048 global $app_list_strings; 1049 global $report_modules; 1050 global $mod_strings; 1051 $modules = Array(); 1052 foreach($app_list_strings['moduleList'] as $key=>$value) 1053 { 1054 for($i=0;$i<count($report_modules);$i++) 1055 { 1056 if($key == $report_modules[$i]) 1057 { 1058 if(isPermitted($key,'index') == "yes") 1059 { 1060 $count_flag = 1; 1061 $modules [$key] = $value; 1062 } 1063 } 1064 } 1065 1066 } 1067 return $modules; 1068 } 1069 /** Function to get the Related module list in vtiger_reports 1070 * This function generates the list of secondary modules in vtiger_reports 1071 * and returns the related module as an Array 1072 */ 1073 1074 function getReportRelatedModules($module) 1075 { 1076 global $app_list_strings; 1077 global $related_modules; 1078 global $mod_strings; 1079 $optionhtml = Array(); 1080 foreach($related_modules[$module] as $rel_modules) 1081 { 1082 if(isPermitted($rel_modules,'index') == "yes") 1083 { 1084 $optionhtml []= $rel_modules; 1085 } 1086 } 1087 return $optionhtml; 1088 } 1089 ?>
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 |