cheeseus

Statistics All

May 15th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1. <?php
  2. // statistics.php
  3.  
  4. $client_list = "";
  5.  
  6. $clients = $db->getAll("SELECT * FROM `".CLIENT_TABLE."` ORDER BY ?n DESC", 'clientID');
  7.  
  8. $years = array("2010", "2011", "2012", "2013", "2014");
  9.  
  10. foreach($clients as $row) {
  11.     $clientname = $row->clientname;
  12.     $clientID   = $row->clientID;
  13.     $status     = $row->status;
  14.     if($status == 1) {$status = "tick.gif"; }
  15.     else { $status = "cross.gif"; }
  16.    
  17.     $client_list .= "
  18.     <tr>
  19.         <td>".$clientID."</td>
  20.         <td><img src=\"images/".$status."\" alt=\"".$status."\" /></td>
  21.         <td><a href=\"index.php?page=Project&amp;do=View&amp;sortby=$clientID\">".$clientname."</a></td>";
  22.    
  23.     foreach($years as $year) {
  24.         $client_list .= "<td>";
  25.        
  26.         // collect statistics by project type, e.g. translation, proofreading, interpreting etc.
  27.         $stat_by_type[$year] = $db->getAll("SELECT type,
  28.                         COUNT(projectID) as count
  29.                         FROM `".PROJECT_TABLE."`
  30.                         WHERE clientID = ?i AND duedate LIKE '%$year%'
  31.                         GROUP BY type", $clientID);
  32.            
  33.         foreach($stat_by_type[$year] as $prow) {
  34.             $client_list .= $prow->count." ".$prow->type."<br />";
  35.         }
  36.        
  37.        
  38.         // collect statistics by project units, e.g. words, pages, hours
  39.         $stat_by_units[$year] = $db->getAll("SELECT *,
  40.                         SUM(units) AS units_sum
  41.                         FROM `".PROJECT_TABLE."`
  42.                         WHERE clientID = ?i AND duedate LIKE '%$year%'
  43.                         GROUP BY unit", $clientID);
  44.            
  45.         foreach($stat_by_units[$year] as $urow) {
  46.             $client_list .= $urow->units_sum." ".$urow->unit."<br />";
  47.         }
  48.        
  49.         // collect statistics by income per client
  50.         $stat_by_income[$year] = $db->getAll("SELECT *,
  51.                         SUM(totalprice) AS client_sum
  52.                         FROM `".PROJECT_TABLE."`
  53.                         WHERE clientID = ?i AND duedate LIKE '%$year%'
  54.                         GROUP BY currency", $clientID);
  55.            
  56.         foreach($stat_by_income[$year] as $irow) {
  57.             $client_list .= $irow->client_sum." ".$irow->currency."<br />";
  58.         }
  59.        
  60.         $client_list .= "</td>";
  61.     }
  62.     $client_list .= "</tr>";
  63. }
  64. ?>
  65. <div id="list">
  66. <h3><?php echo $label['projectstats']; ?></h3>
  67. <table>
  68. <tr><td colspan="8" class="subheader"></td></tr>
  69. <tr>
  70.     <th>ID</th>
  71.     <th>Status</th>
  72.     <th>Client</th>
  73.     <th>2010</th>
  74.     <th>2011</th>
  75.     <th>2012</th>
  76.     <th>2013</th>
  77.     <th>2014</th>
  78. </tr>
  79. <?php echo $client_list; ?>
  80. </table>
  81. </div>
Advertisement
Add Comment
Please, Sign In to add comment