123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- <?php
- function getOneResult($sql) {
- $query = Database::query($sql);
- if ($query !== false) {
- $res = @Database::fetch_array($query, 'NUM');
- } else {
- $res = array();
- }
- return $res[0];
- }
- function getManyResults1Col($sql) {
- $res = Database::query($sql);
- if ($res !== false) {
- $i = 0;
- while ($resA = Database::fetch_array($res, 'NUM')) {
- $resu[$i++] = $resA[0];
- }
- }
- return $resu;
- }
- function getManyResults2Col($sql) {
- $res = Database::query($sql);
- if ($res !== false) {
- $i = 0;
- while ($resA = Database::fetch_array($res, 'NUM')) {
- $resu[$i][0] = $resA[0];
- $resu[$i][1] = $resA[1];
- $i++;
- }
- }
- return $resu;
- }
- function getManyResults3Col($sql) {
- $res = Database::query($sql);
- if ($res !== false) {
- $i = 0;
- while ($resA = Database::fetch_array($res, 'NUM')) {
- $resu[$i][0] = $resA[0];
- $resu[$i][1] = $resA[1];
- $resu[$i][2] = $resA[2];
- $i++;
- }
- }
- return $resu;
- }
- function getManyResultsXCol($sql, $X) {
- $res = Database::query($sql);
- if ($res !== false) {
- $i = 0;
- while ($resA = Database::fetch_array($res, 'NUM')) {
- for ($j = 0; $j < $X ; $j++) {
- $resu[$i][$j] = $resA[$j];
- }
- $i++;
- }
- }
- return $resu;
- }
- function hoursTab($sql) {
- $hours_array = array('total' => 0);
- $res = Database::query($sql);
- if ($res !== false) {
- while ($row = Database::fetch_row($res)) {
- $date_array = getdate($row[0]);
- if ($date_array['hours'] == $last_hours) {
- $hours_array[$date_array['hours']]++;
- } else {
- $hours_array[$date_array['hours']] = 1;
- $last_hours = $date_array['hours'];
- }
- $hours_array['total']++;
- }
- Database::free_result($res);
- }
- return $hours_array;
- }
- function daysTab($sql) {
- $MonthsShort = api_get_months_short();
- $days_array = array('total' => 0);
- $res = Database::query($sql);
- if ($res !== false) {
- while ($row = Database::fetch_row($res)) {
- $date_array = getdate($row[0]);
- $display_date = $date_array['mday'].' '.$MonthsShort[$date_array['mon'] - 1].' '.$date_array['year'];
- if ($date_array['mday'] == $last_day) {
- $days_array[$display_date]++;
- } else {
- $days_array[$display_date] = 1;
- $last_day = $display_date;
- }
- $days_array['total']++;
- }
- Database::free_result($res);
- }
- return $days_array;
- }
- function monthTab($sql) {
- $MonthsLong = api_get_months_long();
- $month_array = array('total' => 0);
- $res = Database::query($sql);
- if ($res !== false) {
-
- for($i = 0; $i < 12; $i++) {
- $month_array[$MonthsLong[$i]] = 0;
- }
- while ($row = Database::fetch_row($res)) {
- $date_array = getdate($row[0]);
- $month_array[$MonthsLong[$date_array['mon'] - 1]]++;
- $month_array['total']++;
- }
- Database::free_result($res);
- }
- return $month_array;
- }
- function makeHitsTable($period_array, $periodTitle, $linkOnPeriod = '???') {
- echo "<table width='100%' cellpadding='0' cellspacing='1' border='0' align=center class='minitext'>";
-
- echo "<tr bgcolor='#E6E6E6' align='center'>
- <td width='15%' >
- <b>$periodTitle</b>
- </td>
- <td width='60%'>
-
- </td>
- <td width='10%'>
- <b>".get_lang('Hits')."</b>
- </td>
- <td width='15%'>
- <b>%</b>
- </td>
- </tr>
- ";
- $factor = 4;
- $maxSize = $factor * 100;
- while (list($periodPiece, $cpt) = each($period_array)) {
- if ($periodPiece != 'total') {
- $pourcent = round(100 * $cpt / $period_array['total']);
- $barwidth = $factor * $pourcent ;
- echo "<tr>
- <td align='center' width='15%'>";
- echo $periodPiece;
- echo "</td>
- <td width='60%' style='padding-top: 3px;' align='center'>"
-
- ."<img src='../img/bar_1.gif' width='1' height='12' alt='$periodPiece : $cpt hits – $pourcent %' />";
- if($pourcent != 0)
- echo "<img src='../img/bar_1u.gif' width='$barwidth' height='12' alt='$periodPiece : $cpt hits – $pourcent %' />";
-
- if($pourcent != 100 && $pourcent != 0)
- echo "<img src='../img/bar_1m.gif' width='1' height='12' alt='$periodPiece : $cpt hits – $pourcent %' />";
- if($pourcent != 100)
- echo "<img src='../img/bar_1r.gif' width='".($maxSize-$barwidth)."' height='12' alt='$periodPiece : $cpt hits – $pourcent %' />";
- echo "<img src='../img/bar_1.gif' width='1' height='12' alt='$periodPiece : $cpt hits – $pourcent %' />
- </td>
- <td align='center' width='10%'>
- $cpt
- </td>
- <td align='center' width='15%'>
- $pourcent %
- </td>
- </tr>
- ";
- }
- }
- echo "<tr bgcolor='#E6E6E6'>
- <td width='15%' align='center'>
- ".get_lang('Total')."
- </td>
- <td align='right' width='60%'>
-
- </td>
- <td align='center' width='10%'>
- ".$period_array['total']."
- </td>
- <td width='15%'>
-
- </td>
- </tr>
- ";
- echo "</table>";
- }
- function buildTab2col($array_of_results, $title1, $title2) {
- echo "<table cellpadding='2' cellspacing='1' border='1' align='center'>\n";
- echo "<tr>
- <td bgcolor='#E6E6E6'>
- $title1
- </td>
- <td bgcolor='#E6E6E6'>
- $title2
- </td>
- </tr>\n";
- if (is_array($array_of_results)) {
- for ($j = 0 ; $j < count($array_of_results) ; $j++) {
- echo '<tr>';
- echo '<td bgcolor="#eeeeee">'.$array_of_results[$j][0].'</td>';
- echo '<td align="right">'.$array_of_results[$j][1].'</td>';
- echo "</tr>\n";
- }
- } else {
- echo '<tr>';
- echo '<td colspan="2" align="center">'.get_lang('NoResult').'</td>';
- echo "</tr>\n";
- }
- echo "</table>\n";
- }
- function buildTab2ColNoTitle($array_of_results) {
- echo "<table cellpadding='3' cellspacing='1' border='0' align='center'>\n";
- if (is_array($array_of_results)) {
- for ($j = 0 ; $j < count($array_of_results) ; $j++) {
- echo '<tr>';
- echo '<td bgcolor="#eeeeee">'.$array_of_results[$j][0].'</td>';
- echo '<td align="right"> '.$array_of_results[$j][1].'</td>';
- echo "</tr>\n";
- }
- } else {
- echo '<tr>';
- echo '<td colspan="2" align="center">'.get_lang('NoResult').'</td>';
- echo "</tr>\n";
- }
- echo "</table>\n";
- }
- function buildTabDefcon($array_of_results) {
- echo "<table width='60%' cellpadding='2' cellspacing='1' border='0' align=center class='minitext'>\n";
- if (is_array($array_of_results)) {
-
- echo '<tr>';
- echo '<td colspan="2" align="center" bgcolor="#eeeeee"><font color="#ff0000">'.get_lang('Defcon').'</font></td>';
- echo "</tr>\n";
- for ($j = 0 ; $j < count($array_of_results) ; $j++) {
- if($array_of_results[$j][0] == "") {
- $key = get_lang('NULLValue');
- } else {
- $key = $array_of_results[$j][0];
- }
- echo '<tr>';
- echo '<td width="70%" class="content">'.$key.'</td>';
- echo '<td width="30%" align="right">'.$array_of_results[$j][1].'</td>';
- echo "</tr>\n";
- }
- } else {
-
- echo '<tr>';
- echo '<td colspan="2" align="center"><font color="#00ff00">'.get_lang('AllRight').'</font></td>';
- echo "</tr>\n";
- }
- echo "</table>\n";
- }
|