[ 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/utils/utils.php'); 12 require_once ('include/database/PearDatabase.php'); 13 require_once ('include/utils/CommonUtils.php'); 14 include ("modules/Dashboard/horizontal_bargraph.php"); 15 include ("modules/Dashboard/vertical_bargraph.php"); 16 include ("modules/Dashboard/pie_graph.php"); 17 18 //To get the vtiger_account names 19 20 /* Function to get the Account name for a given vtiger_account id 21 * Portions created by vtiger are Copyright (C) vtiger. 22 * All Rights Reserved. 23 * Contributor(s): ______________________________________.. 24 */ 25 26 function get_account_name($acc_id) 27 { 28 global $adb; 29 $acc_qry="select accountname from vtiger_account where accountid =".$acc_id; 30 $acc_result=$adb->query($acc_qry); 31 $no_acc_rows=$adb->num_rows($acc_result); 32 33 if($no_acc_rows!=0) 34 { 35 while($acc_row = $adb->fetch_array($acc_result)) 36 { 37 $name_val=$acc_row['accountname']; 38 } 39 $name=$name_val; 40 } 41 else 42 $name=""; 43 return $name; 44 } 45 46 /* Function returns the values to render the graph for a particular type 47 * Portions created by vtiger are Copyright (C) vtiger. 48 * All Rights Reserved. 49 * Contributor(s): ______________________________________.. 50 */ 51 52 // TO get the Values for a particular graph type 53 function module_Chart($user_id,$date_start="2000-01-01",$end_date="2017-01-01",$query,$graph_for,$title,$added_qry="",$module="",$graph_type) 54 { 55 56 global $adb,$current_user; 57 global $days,$date_array,$period_type; 58 59 //$where= " and vtiger_crmentity.smownerid=".$user_id." and vtiger_crmentity.createdtime between '".$date_start."' and '".$end_date."'" ; 60 $query.=$where; 61 if($added_qry!="") 62 $query.=$added_qry; 63 64 $result=$adb->query($query); 65 66 $no_of_rows=$adb->num_rows($result); 67 $mod_count_array=array(); 68 $mod_name_array=array(); 69 $count_by_date[]=array(); 70 $mod_tot_cnt_array=array(); 71 72 $mod_name_val=""; 73 $mod_cnt_crtd_date=""; 74 $target_val=""; 75 $bar_target_val=""; 76 $test_target_val=""; 77 78 if($no_of_rows!=0) 79 { 80 while($row = $adb->fetch_array($result)) 81 { 82 $mod_name= $row[$graph_for]; 83 if($mod_name=="") 84 $mod_name="Un Assigned"; 85 $crtd_time=$row['createdtime']; 86 $crtd_time_array=explode(" ",$crtd_time); 87 $crtd_date=$crtd_time_array[0]; 88 89 if(!isset($mod_tot_cnt_array[$crtd_date])) 90 $mod_tot_cnt_array[$crtd_date]=0; 91 92 $mod_tot_cnt_array[$crtd_date]+=1; 93 94 if (in_array($mod_name,$mod_name_array) == false) 95 { 96 array_push($mod_name_array,$mod_name); // getting all the unique Names into the array 97 } 98 99 //Counting the number of values for a type of graph 100 if($graph_for == "productid") 101 { 102 if($row['qtyinstock'] =='') 103 $mod_count_array[$mod_name] = 0; 104 else 105 $mod_count_array[$mod_name]=$row['qtyinstock']; 106 107 } 108 else 109 { 110 if(!isset($mod_count_array[$mod_name])) 111 $mod_count_array[$mod_name]=0; 112 $mod_count_array[$mod_name]++; 113 } 114 115 //Counting the number of values for a type of graph for a particular date 116 if(!isset($count_by_date[$mod_name][$crtd_date])) 117 $count_by_date[$mod_name][$crtd_date]=0; 118 119 $count_by_date[$mod_name][$crtd_date]+=1; 120 } 121 $mod_by_mod_cnt=count($mod_name_array); 122 123 if($mod_by_mod_cnt!=0) 124 { 125 $url_string=""; 126 127 $mod_cnt_table="<table border=0 cellspacing=1 cellpadding=3><tr> 128 <th> Status </th>"; 129 130 //Assigning the Header values to the vtiger_table and giving the dates as graphformat 131 for($i=0; $i<$days; $i++) 132 { 133 $tdate=$date_array[$i]; 134 $values=Graph_n_table_format($period_type,$tdate); 135 $graph_format=$values[0]; 136 $table_format=$values[1]; 137 $mod_cnt_table.= "<th>$table_format</th>"; 138 139 } 140 $mod_cnt_table .= "<th>Total</th></tr>" ; 141 142 //For all type of the array 143 for ($i=0;$i<count($mod_name_array); $i++) 144 { 145 $name=$mod_name_array[$i]; 146 if($name=="") 147 $name="Un Assigned"; 148 149 if($graph_for =="accountid") 150 { 151 $name_val_table=get_account_name($name); 152 } 153 else 154 { 155 $name_val_table=$name; 156 } 157 158 159 $mod_cnt_table .= "<tr><td>$name_val_table</td>"; 160 $mod_cnt_crtd_date=""; 161 //For all the days 162 for($j=0;$j<$days;$j++) 163 { 164 $tdate=$date_array[$j]; 165 166 if (!isset($count_by_date[$name][$tdate])) 167 { 168 $count_by_date[$name][$tdate]="0"; 169 } 170 $cnt_by_date=$count_by_date[$name][$tdate]; 171 $mod_cnt_table .= "<td>$cnt_by_date </td>"; 172 173 if($i==0) 174 { 175 $values=Graph_n_table_format($period_type,$tdate); 176 $graph_format=$values[0]; 177 $table_format=$values[1]; 178 179 180 //passing the created dates to graph 181 if($mod_graph_date!="") 182 $mod_graph_date="$mod_graph_date,$graph_format"; 183 else 184 $mod_graph_date="$graph_format"; 185 186 } 187 188 //passing the name count by date to graph 189 if($mod_cnt_crtd_date!="") 190 $mod_cnt_crtd_date.=",$cnt_by_date"; 191 else 192 $mod_cnt_crtd_date="$cnt_by_date"; 193 194 } 195 196 $mod_count_val=$mod_count_array[$name]; 197 198 $tot_mod_cnt=array_sum($count_by_date[$name]); 199 $mod_cnt_table .= "<td align=center>$tot_mod_cnt</td></tr>"; 200 201 if($graph_for =="accountid") 202 { 203 $name_val=get_account_name($name); 204 if($name_val!="") 205 $name=$name_val; 206 } 207 if($graph_for =="smownerid") 208 { 209 $name_val=get_assigned_user_name($name); 210 if($name_val!="") 211 $name=$name_val; 212 } 213 if($graph_for =="product_id" || $graph_for =="productid") 214 { 215 $query = "SELECT productname FROM vtiger_products WHERE productid='".$name."'"; 216 $result = $adb->query($query); 217 $name_val = $adb->query_result($result,0,"productname"); 218 if($name_val!="") 219 $name=$name_val; 220 } 221 if($graph_for =="purchaseorderid") 222 { 223 $query = "SELECT subject FROM vtiger_purchaseorder WHERE purchaseorderid='".$name."'"; 224 $result = $adb->query($query); 225 $name_val = $adb->query_result($result,0,"subject"); 226 if($name_val!="") 227 $name=$name_val; 228 } 229 if($graph_for =="quoteid") 230 { 231 $query = "SELECT subject FROM vtiger_quotes WHERE quoteid='".$name."'"; 232 $result = $adb->query($query); 233 $name_val = $adb->query_result($result,0,"subject"); 234 if($name_val!="") 235 $name=$name_val; 236 } 237 if($graph_for =="invoiceid") 238 { 239 $query = "SELECT subject FROM vtiger_invoice WHERE invoiceid='".$name."'"; 240 $result = $adb->query($query); 241 $name_val = $adb->query_result($result,0,"subject"); 242 if($name_val!="") 243 $name=$name_val; 244 } 245 if($graph_for =="campaignid") 246 { 247 //this will return the list of the names of the campaign``:w for the y-axis 248 $query = "SELECT campaignname FROM vtiger_campaign WHERE campaignid='".$name."'"; 249 $result = $adb->query($query); 250 $name_val = $adb->query_result($result,0,"campaignname"); 251 if($name_val!="") 252 $name=$name_val; 253 } 254 if($graph_for =="contactid") 255 { 256 $query = "SELECT lastname FROM vtiger_contactdetails WHERE contactid='".$name."'"; 257 $result = $adb->query($query); 258 $name_val = $adb->query_result($result,0,"lastname"); 259 if($name_val!="") 260 $name=$name_val; 261 } 262 263 //Passing name to graph 264 if($mod_name_val!="") $mod_name_val.="::$name"; 265 else $mod_name_val="$name"; 266 267 268 //Passing count to graph 269 if($mod_cnt_val!="") $mod_cnt_val.="::$mod_count_val"; 270 else $mod_cnt_val="$mod_count_val"; 271 272 if($module!="") 273 { 274 //Check for Ticket Priority 275 if(($graph_type=="ticketsbypriority")) 276 { 277 $graph_for="ticketpriorities"; 278 } 279 280 //added to get valid url in dashbord for tickets by team 281 if($graph_for == "ticketgroupname" || $graph_for == "groupname") $graph_for = "smownerid"; 282 283 if($graph_for == "accountid") $graph_for = "account_id"; 284 if($module == "Home") 285 $link_val="index.php?module=".$name."&action=ListView&from_homepagedb=true&search_field=assigned_user_id&searchtype=BasicSearch&query=true&type=entchar&search_text=".$current_user->user_name; 286 else 287 $link_val="index.php?module=".$module."&action=index&from_dashboard=true&search_text=".$name."&search_field=".$graph_for."&searchtype=BasicSearch&query=true&type=entchar"; 288 289 if($graph_for == "account_id") $graph_for = "accountid"; 290 291 //Adding the links to the graph 292 if($i==0) 293 $bar_target_val .=$link_val; 294 else 295 $bar_target_val .="::".$link_val; 296 } 297 //The data as per given date 298 if($i==0) 299 $urlstring .=$mod_cnt_crtd_date; 300 else 301 $urlstring .="K".$mod_cnt_crtd_date; 302 303 if($i==0) 304 $test_target_val.=$link_val; 305 else 306 $test_target_val.="K".$link_val; 307 } 308 $mod_cnt_table .="</tr><tr><td class=\"$class\">Total</td>"; 309 //For all Days getting the vtiger_table 310 for($k=0; $k<$days;$k++) 311 { 312 $tdate=$date_array[$k]; 313 if(!isset($mod_tot_cnt_array[$tdate])) 314 $mod_tot_cnt_array[$tdate]="0"; 315 $tot= $mod_tot_cnt_array[$tdate]; 316 if($period_type!="yday") 317 $mod_cnt_table.="<td>$tot</td>"; 318 } 319 if($graph_for == "productid") 320 { 321 $cnt_total=array_sum($mod_count_array); 322 } 323 else 324 { 325 $cnt_total=array_sum($mod_tot_cnt_array); 326 } 327 328 $mod_cnt_table.="<td align=\"center\" class=\"$class\">$cnt_total</td></tr></table>"; 329 $mod_cnt_table.="</table>"; 330 $title_of_graph="$title : $cnt_total"; 331 $bar_target_val=urlencode($bar_target_val); 332 $test_target_val=urlencode($test_target_val); 333 334 335 $Prod_mod_val=array($mod_name_val,$mod_cnt_val,$title_of_graph,$bar_target_val,$mod_graph_date,$urlstring,$mod_cnt_table,$test_target_val); 336 return $Prod_mod_val; 337 } 338 else 339 { 340 $data=0; 341 342 } 343 344 } 345 else 346 { 347 $data=0; 348 return "<h3> The data is not available with the specified time period</h3>"; 349 } 350 return $data; 351 } 352 353 354 /** Saving the images of the graph in the /cache/images 355 * otherwise it will render the graph with the given details 356 * Portions created by vtiger are Copyright (C) vtiger. 357 * All Rights Reserved. 358 * Contributor(s): ______________________________________.. 359 */ 360 361 362 function save_image_map($filename,$image_map) 363 { 364 365 366 global $log; 367 368 if (!$handle = fopen($filename, 'w')) { 369 $log->debug(" Cannot open file ($filename)"); 370 return; 371 } 372 373 // Write $somecontent to our opened file. 374 if (fwrite($handle, $image_map) === FALSE) { 375 $log->debug(" Cannot write to file ($filename)"); 376 return false; 377 } 378 379 fclose($handle); 380 return true; 381 } 382 383 function get_graph_by_type($graph_by,$graph_title,$module,$where,$query,$width=900,$height=500) 384 { 385 global $user_id,$date_start,$end_date,$type,$mod_strings; 386 387 //Giving the Cached image name 388 $cache_file_name=abs(crc32($user_id))."_".$type."_".crc32($date_start.$end_date).".png"; 389 $html_imagename=$graph_by; //Html image name for the graph 390 391 $graph_details=module_Chart($user_id,$date_start,$end_date,$query,$graph_by,$graph_title,$where,$module,$type); 392 393 if($graph_details!=0) 394 { 395 $name_val=$graph_details[0]; 396 $cnt_val=$graph_details[1]; 397 $graph_title=$graph_details[2]; 398 $target_val=$graph_details[3]; 399 $graph_date=$graph_details[4]; 400 $urlstring=$graph_details[5]; 401 $cnt_table=$graph_details[6]; 402 $test_target_val=$graph_details[7]; 403 404 if(isset($_REQUEST['display_view']) && $_REQUEST['display_view'] == 'MATRIX') 405 { 406 $width = 350; 407 $height = 250; 408 }else 409 { 410 $width = 850; 411 $height = 500; 412 } 413 414 $top=20; 415 $left=140; 416 $bottom=120; 417 $title=$graph_title; 418 419 return get_graph($cache_file_name,$html_imagename,$cnt_val,$name_val,$width,$height,$left,$right,$top,$bottom,$title,$target_val,$graph_date,$urlstring,$test_target_val,$date_start,$end_date); 420 } 421 else 422 { 423 //echo $mod_strings['LBL_NO_DATA']; 424 sleep(1); 425 echo '<h3>'.$mod_strings['LBL_NO_DATA'].'</h3>'; 426 } 427 428 } 429 430 /** Returns the Horizontal,vertical, pie graphs and Accumulated Graphs 431 for the details 432 * Portions created by vtiger are Copyright (C) vtiger. 433 * All Rights Reserved. 434 * Contributor(s): ______________________________________.. 435 */ 436 437 438 // Function for get graphs 439 function get_graph($cache_file_name,$html_imagename,$cnt_val,$name_val,$width,$height,$left,$right,$top,$bottom,$title,$target_val,$graph_date,$urlstring,$test_target_val,$date_start,$end_date) 440 { 441 442 global $tmp_dir; 443 global $graph_title, $mod_strings; 444 global $theme; 445 $theme_path="themes/".$theme."/"; 446 $image_path=$theme_path."images/"; 447 448 $val=explode(":",$title); 449 $display_title=$val[0]; 450 451 if(isset($_REQUEST['display_view']) && $_REQUEST['display_view'] == 'MATRIX') 452 { 453 $sHTML .="<tr><td width=50%><table width=100% border=0 cellspacing=0 cellpadding=0 align=left>"; 454 } 455 456 $sHTML .= "<tr> 457 <td><a name='1'></a><table width=20% border=0 cellspacing=0 cellpadding=0 align=left> 458 <tr> 459 <td rowspan=2 valign=top><span class=\"dash_count\">1</span></td> 460 <td nowrap><span class=genHeaderSmall>".$graph_title."</span></td> 461 </tr> 462 <tr> 463 <td nowrap><span class=big>".$mod_strings['LBL_HORZ_BAR_CHART']."</span> </td> 464 </tr> 465 </table> 466 </td> 467 <td align='right'>"; 468 if(isset($_REQUEST['display_view']) && $_REQUEST['display_view'] == 'MATRIX') 469 { 470 $sHTML .= " "; 471 472 }else 473 { 474 $sHTML .= "<table cellpadding='0' cellspacing='0' border='0' class='small'> 475 <tr> 476 <td class='small'>".$mod_strings['VIEWCHART']." : </td> 477 <td class='dash_row_sel'>1</td> 478 <td class='dash_row_unsel'><a class='dash_href' href='#2'>2</a></td> 479 <td class='dash_switch'><a href='#top'><img align='absmiddle' src='".$image_path."dash_scroll_up.jpg' border='0'></a></td> 480 </tr> 481 </table>"; 482 } 483 $sHTML .="</td> 484 </tr> 485 <tr> 486 <td colspan='2'>"; 487 488 489 $sHTML .= render_graph($tmp_dir."hor_".$cache_file_name,$html_imagename."_hor",$cnt_val,$name_val,$width,$height,$left,$right,$top,$bottom,$title,$target_val,"horizontal"); 490 //Commented by Minnie -- same content displayed in two graphs 491 /*$sHTML .= "</td> 492 </tr> 493 <tr> 494 <td><hr noshade='noshade' size='1' /></td> 495 </tr>"; 496 497 $sHTML .= "<tr> 498 <td><table width=20% border=0 cellspacing=0 cellpadding=0 align=left> 499 <tr> 500 <td rowspan=2 valign=top><span class=dashSerial>2</span></td> 501 <td nowrap><span class=genHeaderSmall>".$graph_title."</span></td> 502 </tr> 503 <tr> 504 <td><span class=big>Vertical Bar Chart</span> </td> 505 </tr> 506 </table> 507 </td> 508 </tr> 509 <tr> 510 <td height=200>"; 511 512 $sHTML .= render_graph($tmp_dir."vert_".$cache_file_name,$html_imagename."_vert",$cnt_val,$name_val,$width,$height,$left,$right,$top,$bottom,$title,$target_val,"vertical");*/ 513 514 $sHTML .= "</td> 515 </tr>"; 516 517 if(isset($_REQUEST['display_view']) && $_REQUEST['display_view'] == 'MATRIX') 518 { 519 $sHTML .="</table></td><td width=50%><table width=100% border=0 cellspacing=0 cellpadding=0 align=left>"; 520 }else 521 { 522 $sHTML .= "<tr><td colspan='2' class='dash_chart_btm'> </td></tr>"; 523 } 524 525 $sHTML .= "<tr> 526 <td><a name='2'></a><table width=20% border=0 cellspacing=0 cellpadding=0 align=left> 527 <tr> 528 <td rowspan=2 valign=top><span class=\"dash_count\">2</span></td> 529 <td nowrap><span class=genHeaderSmall>".$graph_title."</span></td> 530 </tr> 531 <tr> 532 <td><span class=big>".$mod_strings['LBL_PIE_CHART']."</span> </td> 533 </tr> 534 </table> 535 </td> 536 <td align='right'>"; 537 if(isset($_REQUEST['display_view']) && $_REQUEST['display_view'] == 'MATRIX') 538 { 539 $sHTML .= " "; 540 541 }else 542 { 543 $sHTML .= "<table cellpadding='0' cellspacing='0' border='0' class='small'> 544 <tr> 545 <td class='small'>".$mod_strings['VIEWCHART']." : </td> 546 <td class='dash_row_unsel'><a class='dash_href' href='#1'>1</a></td> 547 <td class='dash_row_sel'>2</td> 548 <td class='dash_switch'><a href='#top'><img align='absmiddle' src='".$image_path."dash_scroll_up.jpg' border='0'></a></td> 549 </tr> 550 </table>"; 551 } 552 $sHTML .="</td> 553 </tr> 554 <tr> 555 <td colspan='2'>"; 556 557 $sHTML .= render_graph($tmp_dir."pie_".$cache_file_name,$html_imagename."_pie",$cnt_val,$name_val,$width,$height,$left,$right,$top,$bottom,$title,$target_val,"pie"); 558 559 $sHTML .= "</td> 560 </tr>"; 561 562 if(isset($_REQUEST['display_view']) && $_REQUEST['display_view'] == 'MATRIX') 563 { 564 $sHTML .="</table></td></tr>"; 565 } 566 $sHTML .= "<tr><td colspan='2' class='dash_chart_btm'> </td></tr>"; 567 568 569 return $sHTML; 570 } 571 572 /** Returns graph, if the cached image is present it'll display that image, 573 otherwise it will render the graph with the given details 574 * Portions created by vtiger are Copyright (C) vtiger. 575 * All Rights Reserved. 576 * Contributor(s): ______________________________________.. 577 */ 578 579 // Function to get the chached image if exists 580 function render_graph($cache_file_name,$html_imagename,$cnt_val,$name_val,$width,$height,$left,$right,$top,$bottom,$title,$target_val,$graph_type) 581 { 582 583 //Checks whether the cached image is present or not 584 if(file_exists($cache_file_name)) 585 { 586 unlink($cache_file_name); 587 } 588 if(file_exists($cache_file_name.'.map')) 589 { 590 unlink($cache_file_name.'.map'); 591 } 592 if (!file_exists($cache_file_name) || !file_exists($cache_file_name.'.map')) 593 { 594 //If the Cached image is not present 595 if($graph_type=="horizontal") 596 { 597 return horizontal_graph($cnt_val,$name_val,$width,$height,$left,$right,$top,$bottom,$title,$target_val,$cache_file_name,$html_imagename); 598 } 599 else if($graph_type=="vertical") 600 { 601 return vertical_graph($cnt_val,$name_val,$width,$height,$left,$right,$top,$bottom,$title,$target_val,$cache_file_name,$html_imagename); 602 } 603 else if($graph_type=="pie") 604 { 605 return pie_chart($cnt_val,$name_val,$width,$height,$left,$right,$top,$bottom,$title,$target_val,$cache_file_name,$html_imagename); 606 607 } 608 } 609 else 610 { 611 //Getting the cached image 612 $imgMap_fp = fopen($cache_file_name.'.map', "rb"); 613 $imgMap = fread($imgMap_fp, filesize($cache_file_name.'.map')); 614 fclose($imgMap_fp); 615 $base_name_cache_file=basename($cache_file_name); 616 $ccc="cache/images/".$base_name_cache_file; 617 $return = "\n$imgMap\n"; 618 $return .= "<img src=$ccc ismap usemap=#$html_imagename border='0'>"; 619 return $return; 620 } 621 } 622 ?>
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 |