Advertisement
Guest User

staffhighcharts

a guest
Dec 20th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.10 KB | None | 0 0
  1. <?php
  2. /*********************************************************************
  3.     stats.php
  4.  
  5.     Stats board - Get some stats!
  6.  
  7.     Jorge Ferreira
  8.     TCA
  9.  
  10. **********************************************************************/
  11. require('staff.inc.php');
  12. $nav->setTabActive('statistics');
  13. $ost->addExtraHeader('<meta name="tip-namespace" content="dashboard.dashboard" />',
  14.     "$('#content').data('tipNamespace', 'dashboard.dashboard');");
  15. require(STAFFINC_DIR.'header.inc.php');
  16. ?>
  17. <h2><?php echo __('');
  18. ?></h2>
  19.  
  20.  
  21. <!-- QUERIES -->
  22. <?php
  23. // created queries
  24. //
  25.     $arrmonth = array();
  26.     for($i=1; $i<13; $i++){
  27.         $query = 'select count(*) as value
  28.         from ost_ticket
  29.         where MONTH(created)='.$i;
  30.        
  31.         $exquery = db_query($query);
  32.         $arrmonth[$i] = db_result($exquery,0,"value");
  33.         if($arrmonth[$i]==0){
  34.             $arrmonth[$i]=null;
  35.         }
  36.    
  37.     }
  38.     $jan = $arrmonth[1];
  39.     $fev = $arrmonth[2];
  40.     $mar = $arrmonth[3];
  41.     $may = $arrmonth[4];
  42.     $apr = $arrmonth[5];
  43.     $jun = $arrmonth[6];
  44.     $jul = $arrmonth[7];
  45.     $aug = $arrmonth[8];
  46.     $set = $arrmonth[9];
  47.     $oct = $arrmonth[10];
  48.     $nov = $arrmonth[11];
  49.     $dez = $arrmonth[12];
  50.    
  51.     $arrmonthclo = array();
  52.     for($j=1; $j<13; $j++){
  53.         $cloquery = 'select count(*) as value
  54.         from ost_ticket
  55.         where status_id = 3 and MONTH(created)='.$j;
  56.        
  57.         $cloexquery = db_query($cloquery);
  58.         $arrmonthclo[$j] = db_result($cloexquery,0,"value");
  59.         if($arrmonthclo[$j]==0){
  60.             $arrmonthclo[$j]=null;
  61.         }
  62.    
  63.     }
  64.     $janclo = $arrmonthclo[1];
  65.     $fevclo = $arrmonthclo[2];
  66.     $marclo = $arrmonthclo[3];
  67.     $mayclo = $arrmonthclo[4];
  68.     $aprclo = $arrmonthclo[5];
  69.     $junclo = $arrmonthclo[6];
  70.     $julclo = $arrmonthclo[7];
  71.     $augclo = $arrmonthclo[8];
  72.     $setclo = $arrmonthclo[9];
  73.     $octclo = $arrmonthclo[10];
  74.     $novclo = $arrmonthclo[11];
  75.     $dezclo = $arrmonthclo[12];
  76.  
  77.    
  78.    
  79.     $curmonthq = 'select month(curdate()) as value';
  80.        
  81.     $curmonthquery = db_query($curmonthq);
  82.     $curmonth = db_result($curmonthquery,0,"value");
  83.    
  84.     $arrmonthove = array();
  85.     for($k=1; $k<$curmonth+1; $k++){
  86.         $ovequery = 'select count(*) as value
  87.         from ost_ticket
  88.         where MONTH(created)='.$k.' and isoverdue = 1';
  89.        
  90.         $oveexquery = db_query($ovequery);
  91.         $arrmonthove[$k] = db_result($oveexquery,0,"value");
  92.         if($arrmonthove[$k]==0){
  93.             $arrmonthove[$k]=null;
  94.         }
  95.    
  96.     }
  97.     $janove = $arrmonthove[1];
  98.     $fevove = $arrmonthove[2];
  99.     $marove = $arrmonthove[3];
  100.     $mayove = $arrmonthove[4];
  101.     $aprove = $arrmonthove[5];
  102.     $junove = $arrmonthove[6];
  103.     $julove = $arrmonthove[7];
  104.     $augove = $arrmonthove[8];
  105.     $setove = $arrmonthove[9];
  106.     $octove = $arrmonthove[10];
  107.     $novove = $arrmonthove[11];
  108.     $dezove = $arrmonthove[12];
  109.    
  110. ?>
  111. <?php
  112. // Queries to fill table below
  113.  
  114. //created by
  115.     $arrstaff = array();
  116.     for($l=1; $l<13; $l++){
  117.         $query = 'select count(*) as value
  118.         from ost_ticket
  119.         where staff_id='.$l;
  120.        
  121.         $exquery = db_query($query);
  122.         $arrstaff[$l] = db_result($exquery,0,"value");
  123.        
  124.     }
  125.     $jorge = $arrstaff[1];
  126.     $tiago = $arrstaff[2];
  127.     $antonio = $arrstaff[3];
  128.     $humberto = $arrstaff[4];
  129.     $duarte = $arrstaff[5];
  130.     $joao = $arrstaff[6];
  131.     $dina = $arrstaff[12];
  132.    
  133. //opened    
  134.     $arrstaffopened = array();
  135.     for($l=1; $l<13; $l++){
  136.         $query = 'select count(*) as value
  137.         from ost_ticket
  138.         where staff_id='.$l.' and closed is null';
  139.        
  140.         $exquery = db_query($query);
  141.         $arrstaffopened[$l] = db_result($exquery,0,"value");
  142.        
  143.     }
  144.     $jorgeopened = $arrstaffopened[1];
  145.     $tiagoopened = $arrstaffopened[2];
  146.     $antonioopened = $arrstaffopened[3];
  147.     $humbertoopened = $arrstaffopened[4];
  148.     $duarteopened = $arrstaffopened[5];
  149.     $joaoopened = $arrstaffopened[6];
  150.     $dinaopened = $arrstaffopened[12];
  151.    
  152.    
  153. //closed by
  154.     $arrstaffclosed = array();
  155.     for($l=1; $l<13; $l++){
  156.         $query = 'select count(*) as value
  157.         from ost_ticket
  158.         where staff_id='.$l.' and closed is not null';
  159.        
  160.         $exquery = db_query($query);
  161.         $arrstaffclosed[$l] = db_result($exquery,0,"value");
  162.        
  163.     }
  164.     $jorgeclosed = $arrstaffclosed[1];
  165.     $tiagoclosed = $arrstaffclosed[2];
  166.     $antonioclosed = $arrstaffclosed[3];
  167.     $humbertoclosed = $arrstaffclosed[4];
  168.     $duarteclosed = $arrstaffclosed[5];
  169.     $joaoclosed = $arrstaffclosed[6];
  170.     $dinaclosed = $arrstaffclosed[12];
  171.        
  172. ?>
  173. <?php
  174.     $sqlqry = 'select distinct(o.name) as val, count(*) as nts
  175.             from ost_ticket t, ost_user u, ost_organization o
  176.             where t.user_id =u.id and u.org_id=o.id
  177.             group by org_id
  178.             order by count(*) desc
  179.             limit 21';
  180.     $sqlresult = db_query($sqlqry);
  181.     $arrnameorg= array();
  182.     $arrtksorg= array();
  183.     $ctr=2;
  184.     if ($sqlresult->num_rows > 0) {
  185.      // output data of each row
  186.      while($row = $sqlresult->fetch_assoc()) {
  187.         $arrnameorg[$ctr]=$row["val"];
  188.         $arrtksorg[$ctr]=$row["nts"];
  189.         $ctr++;
  190.      }
  191.     }
  192.    
  193.    
  194. ?>
  195. <!-- END OF QUERIES -->
  196.  
  197.  
  198. <!-- SCRIPTS -->
  199.    
  200. <script src="https://code.highcharts.com/highcharts.js"></script>
  201. <script src="https://code.highcharts.com/modules/data.js"></script>
  202. <script src="https://code.highcharts.com/modules/exporting.js"></script>
  203.  
  204.  
  205. <script type="text/javascript">
  206. $( function () {
  207.     Highcharts.chart('rotatedbars', {
  208.         chart: {
  209.             type: 'column'
  210.         },
  211.         title: {
  212.             text: 'Tickets by Company'
  213.         },
  214.         subtitle: {
  215.             text: ''
  216.         },
  217.         xAxis: {
  218.             type: 'category',
  219.             labels: {
  220.                 rotation: -45,
  221.                 style: {
  222.                     fontSize: '13px',
  223.                     fontFamily: 'Verdana, sans-serif'
  224.                 }
  225.             }
  226.         },
  227.         yAxis: {
  228.             min: 0,
  229.             title: {
  230.                 text: 'Tickets'
  231.             }
  232.         },
  233.         legend: {
  234.             enabled: false
  235.         },
  236.         tooltip: {
  237.             pointFormat: 'Tickets: <b>{point.y:.0f}</b>'
  238.         },
  239.         series: [{
  240.             name: 'Number',
  241.             data: [
  242.                
  243.                 ['<?php echo $arrnameorg[2]?>',<?php echo $arrtksorg[2]?>],
  244.                 ['<?php echo $arrnameorg[3]?>',<?php echo $arrtksorg[3]?>],
  245.                 ['<?php echo $arrnameorg[4]?>',<?php echo $arrtksorg[4]?>],
  246.                 ['<?php echo $arrnameorg[5]?>',<?php echo $arrtksorg[5]?>],
  247.                 ['<?php echo $arrnameorg[6]?>',<?php echo $arrtksorg[6]?>],
  248.                 ['<?php echo $arrnameorg[7]?>',<?php echo $arrtksorg[7]?>],
  249.                 ['<?php echo $arrnameorg[8]?>',<?php echo $arrtksorg[8]?>],
  250.                 ['<?php echo $arrnameorg[9]?>',<?php echo $arrtksorg[9]?>],
  251.                 ['<?php echo $arrnameorg[10]?>',<?php echo $arrtksorg[10]?>],
  252.                 ['<?php echo $arrnameorg[11]?>',<?php echo $arrtksorg[11]?>],
  253.                 ['<?php echo $arrnameorg[12]?>',<?php echo $arrtksorg[12]?>],
  254.                 ['<?php echo $arrnameorg[13]?>',<?php echo $arrtksorg[13]?>],
  255.                 ['<?php echo $arrnameorg[14]?>',<?php echo $arrtksorg[14]?>],
  256.                 ['<?php echo $arrnameorg[15]?>',<?php echo $arrtksorg[15]?>],
  257.                 ['<?php echo $arrnameorg[16]?>',<?php echo $arrtksorg[16]?>],
  258.                 ['<?php echo $arrnameorg[17]?>',<?php echo $arrtksorg[17]?>],
  259.                 ['<?php echo $arrnameorg[18]?>',<?php echo $arrtksorg[18]?>],
  260.                 ['<?php echo $arrnameorg[19]?>',<?php echo $arrtksorg[19]?>],
  261.                 ['<?php echo $arrnameorg[20]?>',<?php echo $arrtksorg[20]?>],
  262.             ],
  263.             dataLabels: {
  264.                 enabled: true,
  265.                 rotation: -90,
  266.                 color: '#FFFFFF',
  267.                 align: 'right',
  268.                 format: '{point.y:.0f}', // one decimal
  269.                 y: 10, // 10 pixels down from the top
  270.                 style: {
  271.                     fontSize: '13px',
  272.                     fontFamily: 'Verdana, sans-serif'
  273.                 }
  274.             }
  275.         }]
  276.     });
  277. });
  278. </script>
  279. <script>
  280. //bar graph
  281. $( function () {
  282.     Highcharts.chart('bargraph', {
  283.         data: {
  284.             table: 'datatable'
  285.         },
  286.         chart: {
  287.             type: 'column'
  288.         },
  289.         title: {
  290.             text: 'Ticket Stats by user'
  291.         },
  292.         yAxis: {
  293.             allowDecimals: false,
  294.             title: {
  295.                 text: 'Units'
  296.             }
  297.         },
  298.         tooltip: {
  299.             formatter: function () {
  300.                 return '<b>' + this.series.name + '</b><br/>' +
  301.                     this.point.y + ' ' + this.point.name.toLowerCase();
  302.             }
  303.         }
  304.     });
  305. });
  306. </script>
  307. <script>
  308. //line graph
  309. $( function () {
  310.    
  311.     $('#linegraph').highcharts({
  312.         title: {
  313.             text: 'Monthly Ticket Report',
  314.             x: -20 //center
  315.         },
  316.         xAxis: {
  317.             categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  318.                 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  319.         },
  320.         yAxis: {
  321.             title: {
  322.                 text: '# Tickets'
  323.             },
  324.             plotLines: [{
  325.                 value: 0,
  326.                 width: 1,
  327.                 color: '#808080'
  328.             }]
  329.         },
  330.         tooltip: {
  331.             valueSuffix: ''
  332.         },
  333.         legend: {
  334.             layout: 'vertical',
  335.             align: 'right',
  336.             verticalAlign: 'middle',
  337.             borderWidth: 0
  338.         },
  339.         series: [{
  340.             name: 'Created',
  341.             data: [<?php echo $jan ?>,<?php echo $fev ?>,<?php echo $mar ?>,<?php echo $may ?>,<?php echo $apr ?>,<?php echo $jun ?>,
  342.                    <?php echo $jul ?>,<?php echo $aug ?>,<?php echo $set ?>,<?php echo $oct ?>,<?php echo $nov ?>,<?php echo $dez ?>]
  343.         }, {
  344.             name: 'Closed',
  345.             data: [<?php echo $janclo ?>,<?php echo $fevclo ?>,<?php echo $marclo ?>,<?php echo $mayclo ?>,<?php echo $aprclo ?>,<?php echo $junclo ?>,
  346.                    <?php echo $julclo ?>,<?php echo $augclo ?>,<?php echo $setclo ?>,<?php echo $octclo ?>,<?php echo $novclo ?>,<?php echo $dezclo ?>]
  347.         }, {
  348.             name: 'Overdue',
  349.             data: [<?php echo $janove ?>,<?php echo $fevove ?>,<?php echo $marove ?>,<?php echo $mayove ?>,<?php echo $aprove ?>,<?php echo $junove ?>,
  350.                    <?php echo $julove ?>,<?php echo $augove ?>,<?php echo $setove ?>,<?php echo $octove ?>,<?php echo $novove ?>,<?php echo $dezove ?>]
  351.         }]
  352.     });
  353. });
  354. </script>
  355.  
  356. <!-- END OF SCRIPTS -->
  357.  
  358. <!-- GRAPHS -->
  359. <div id="linegraph" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
  360. <div id="bargraph" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
  361. <div id="rotatedbars" style="min-width: 300px; height: 400px; margin: 0 auto"></div>
  362.  
  363.  
  364.  
  365. <!-- END OF GRAPHS -->
  366.  
  367. <!-- ADDITIONAL DATA -->
  368. <div>
  369.     <table>
  370.         <tr>
  371.            
  372.             <td>
  373.                 <table id="datatable" border="0">
  374.                 <thead>
  375.                     <tr>
  376.                         <th width="40"></th>
  377.                         <th width="60">António</th>
  378.                         <th width="60">Tiago</th>
  379.                         <th width="60">Humberto</th>
  380.                         <th width="60">Dina</th>
  381.                         <th width="60">João</th>
  382.                         <th width="60">Duarte</th>
  383.                         <th width="60">Jorge</th>
  384.                     </tr>
  385.                 </thead>
  386.                 <tbody>
  387.                     <tr>
  388.                         <th>Created</th>
  389.                         <td align="center"><?php echo $antonio; ?></td>
  390.                         <td align="center"><?php echo $tiago; ?></td>
  391.                         <td align="center"><?php echo $humberto; ?></td>
  392.                         <td align="center"><?php echo $dina; ?></td>
  393.                         <td align="center"><?php echo $joao; ?></td>
  394.                         <td align="center"><?php echo $duarte; ?></td>
  395.                         <td align="center"><?php echo $jorge; ?></td>
  396.                     </tr>
  397.                     <tr>
  398.                         <th>Closed</th>
  399.                         <td align="center"><?php echo $antonioclosed; ?></td>
  400.                         <td align="center"><?php echo $tiagoclosed; ?></td>
  401.                         <td align="center"><?php echo $humbertoclosed; ?></td>
  402.                         <td align="center"><?php echo $dinaclosed; ?></td>
  403.                         <td align="center"><?php echo $joaoclosed; ?></td>
  404.                         <td align="center"><?php echo $duarteclosed; ?></td>
  405.                         <td align="center"><?php echo $jorgeclosed; ?></td>
  406.                     </tr>
  407.                     <tr>
  408.                         <th>Open</th>
  409.                         <td align="center"><?php echo $antonioopened; ?></td>
  410.                         <td align="center"><?php echo $tiagoopened; ?></td>
  411.                         <td align="center"><?php echo $humbertoopened; ?></td>
  412.                         <td align="center"><?php echo $dinaopened; ?></td>
  413.                         <td align="center"><?php echo $joaoopened; ?></td>
  414.                         <td align="center"><?php echo $duarteopened; ?></td>
  415.                         <td align="center"><?php echo $jorgeopened; ?></td>    
  416.                     </tr>
  417.                     </tbody>
  418.                 </table>
  419.             </td>
  420.  
  421.         </tr>
  422.     </table>
  423. </div>
  424.  
  425. <!-- END OF ADDITIONAL DATA -->
  426.    
  427. <?php
  428. include(STAFFINC_DIR.'footer.inc.php');
  429. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement