Advertisement
Guest User

Untitled

a guest
Mar 11th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.97 KB | None | 0 0
  1. <?php
  2.  
  3. // $pMySQL-ExecuteSQL() function
  4. public function ExecuteSQL( $sSQLQuery ) {
  5.         $this->sLastQuery = $sSQLQuery;
  6.        
  7.         $this->aResult = mysql_query( $sSQLQuery, $this->pDBLink );
  8.        
  9.         if( $this->aResult ) {
  10.             $this->iRecords = @mysql_num_rows( $this->aResult );
  11.             $this->iAffected = @mysql_affected_rows( $this->pDBLink );
  12.             return true;
  13.         } else {
  14.             $this->sLastError = mysql_error( $this->pDBLink );
  15.             return false;
  16.         }
  17.     }
  18.  
  19. // GetLanguageByLCID()
  20. function GetLanguageByLCID( $nLCID ) {
  21.         global $pMySQL;
  22.  
  23.         if ( !is_int( $nLCID ) )
  24.             return 'Unknown';
  25.  
  26.         if ( $pMySQL->Select( 'Locales', array( 'LCID' => $nLCID ), '', '0,1' ) )
  27.             return $pMySQL->aArrayedResult['DisplayName'];
  28.  
  29.         return 'Unknown';
  30.     }
  31.  
  32. $aLanguageChartData = array();
  33. $nLangTotal = 0;
  34.  
  35. $sSQLQuery = "SELECT s.*, u.* FROM `".$pMySQL->sPrefix."Sessions` AS s, `".$pMySQL->sPrefix."UniqueUsers` AS u ";
  36. $sSQLQuery .= "WHERE s.UniqueUserId = u.UniqueUserId ";
  37. $sSQLQuery .= "AND s.ApplicationId = '".$sAppId."' " . ( ( $sAppVer != "all" ) ? ( "AND s.ApplicationVersion = '".$sAppVer."' " ) : ( "" ) );
  38. $sSQLQuery .= "AND s.StartApp BETWEEN '".$nStartTime."' AND '".$nEndTime."' ";
  39.  
  40. $pMySQL->ExecuteSQL( $sSQLQuery );
  41.  
  42. $aLanguagesTotal = array();
  43.  
  44. if ( $pMySQL->iRecords == 1 )
  45.     $aLanguagesTotal[] = $pMySQL->ArrayResult();
  46. else if ( $pMySQL->iRecords > 1 )
  47.     $aLanguagesTotal = $pMySQL->ArrayResults();
  48.  
  49. foreach ( $aLanguagesTotal as $aLanguageRow ) {
  50.     $nLCID = intval( $aLanguageRow['LangID'] );
  51.    
  52.     if ( !array_key_exists( $nLCID, $aLanguageChartData ) ) {
  53.         $aLanguageChartData[$nLCID] = array(
  54.             'total' => 0,
  55.             'unique' => 0
  56.         );
  57.     }
  58.    
  59.     $aLanguageChartData[$nLCID]['total']++;
  60.     $nLangTotal++;
  61. }
  62.  
  63. $sSQLQuery = "SELECT s.*, u.* FROM `".$pMySQL->sPrefix."Sessions` AS s, `".$pMySQL->sPrefix."UniqueUsers` AS u ";
  64. $sSQLQuery .= "WHERE s.UniqueUserId = u.UniqueUserId ";
  65. $sSQLQuery .= "AND s.ApplicationId = '".$sAppId."' " . ( ( $sAppVer != "all" ) ? ( "AND s.ApplicationVersion = '".$sAppVer."' " ) : ( "" ) );
  66. $sSQLQuery .= "AND s.StartApp BETWEEN '".$nStartTime."' AND '".$nEndTime."' ";
  67. $sSQLQuery .= "GROUP BY s.UniqueUserId";
  68.  
  69. $pMySQL->ExecuteSQL( $sSQLQuery );
  70.  
  71. $aLanguagesUnique = array();
  72.  
  73. if ( $pMySQL->iRecords == 1 )
  74.     $aLanguagesUnique[] = $pMySQL->ArrayResult();
  75. else if ( $pMySQL->iRecords > 1 )
  76.     $aLanguagesUnique = $pMySQL->ArrayResults();
  77.  
  78. foreach ( $aLanguagesUnique as $aLanguageRow ) {
  79.     $nLCID = intval( $aLanguageRow['LangID'] );
  80.    
  81.     $aLanguageChartData[$nLCID]['unique']++;
  82. }
  83. ?>
  84. // How the data is outputted in HTML
  85. <table style="width: 100%" class="datatable">
  86.                 <thead>
  87.                     <tr>
  88.                         <th>Language</th>
  89.                         <th>Executions</th>
  90.                         <th>Unique</th>
  91.                         <th>Percentage of Executions</th>
  92.                     </tr>
  93.                 </thead>
  94.                 <tbody>
  95.                     <?php
  96.                     foreach ( $aLanguageChartData as $nLCID => $aData ) :
  97.                         $sLanguage = GetLanguageByLCID( $nLCID ); // Another SQL Query, see function at top
  98.                         $sPercentTotal = CalculatePercent( $aData['total'], $nLangTotal ) . '%';
  99.                     ?>
  100.                     <tr>
  101.                         <td><?php echo $sLanguage ?></td>
  102.                         <td><?php echo $aData['total'] ?></td>
  103.                         <td><?php echo $aData['unique'] ?></td>
  104.                         <td><div style="width: 85%" class="usagebox left"><div style="width: <?php echo $sPercentTotal ?>" class="lowbar"></div></div><span style="padding: 8px" class="right"><?php echo $sPercentTotal ?></span></td>
  105.                     </tr>
  106.                     <?php endforeach; ?>
  107.                 </tbody>
  108.             </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement