* @param sql : a sql query (as a string) * @desc return one result from a sql query (1 single result) */ function getOneResult($sql) { $query = Database::query($sql); if ($query !== false) { $res = @Database::fetch_array($query, 'NUM'); } else { $res = array(); } return $res[0]; } /** * @author Sebastien Piraux * @param sql : a sql query (as a string) * @desc Return many results of a query in a 1 column tab */ 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; } /** * @author Sebastien Piraux * @param sql : a sql query (as a string) * @desc Return many results of a query */ 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; } /** * @author Sebastien Piraux * @param sql : a sql query (as a string) * @desc Return many results of a query in a 3 column tab in $resu[$i][0], $resu[$i][1],$resu[$i][2] */ 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; } /** * @author Sebastien Piraux * @param sql : a sql query (as a string) * @desc Return many results of a query in a X column tab in $resu[$i][0], $resu[$i][1],$resu[$i][2],... this function is more 'standard' but use a little more ressources So I encourage to use the dedicated for 1, 2 or 3 columns of results */ 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; } /** * @author Sebastien Piraux * @param sql : a sql query (as a string) * @return hours_array * @desc Return an assoc array. Keys are the hours, values are the number of time this hours was found. key 'total' return the sum of all number of time hours appear */ function hoursTab($sql) { $hours_array = array('total' => 0); $res = Database::query($sql); if ($res !== false) { $last_hours = -1; 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; } /** * @author Sebastien Piraux * @param sql : a sql query (as a string) * @return days_array * @desc Return an assoc array. Keys are the days, values are the number of time this hours was found. key "total" return the sum of all number of time days appear */ function daysTab($sql) { $MonthsShort = api_get_months_short(); $days_array = array('total' => 0); $res = Database::query($sql); if ($res !== false) { $last_day = -1; 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; } /** * @author Sebastien Piraux * @param sql : a sql query (as a string) * @return month_array * @desc Return an assoc array. Keys are the days, values are the number of time this hours was found. key "total" return the sum of all number of time days appear */ function monthTab($sql) { $MonthsLong = api_get_months_long(); $month_array = array('total' => 0); $res = Database::query($sql); if ($res !== false) { // init tab with all months 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; } /** * @author Sebastien Piraux * @param period_array : an array provided by hoursTab($sql) or daysTab($sql) * @param periodTitle : title of the first column, type of period * @param linkOnPeriod : * @desc Display a 4 column array Columns are : hour of day, graph, number of hits and % First line are titles next are informations Last is total number of hits */ function makeHitsTable($period_array, $periodTitle, $linkOnPeriod = '???') { echo ""; // titles echo " "; $factor = 4; $maxSize = $factor * 100; //pixels while (list($periodPiece, $cpt) = each($period_array)) { if ($periodPiece != 'total') { $pourcent = round(100 * $cpt / $period_array['total']); $barwidth = $factor * $pourcent ; echo " "; } } echo " "; echo "
$periodTitle   ".get_lang('Hits')." %
"; echo $periodPiece; echo " " // display hitbar ."$periodPiece : $cpt hits – $pourcent %"; if($pourcent != 0) echo "$periodPiece : $cpt hits – $pourcent %"; // display 100% bar if($pourcent != 100 && $pourcent != 0) echo "$periodPiece : $cpt hits – $pourcent %"; if($pourcent != 100) echo "$periodPiece : $cpt hits – $pourcent %"; echo "$periodPiece : $cpt hits – $pourcent % $cpt $pourcent %
".get_lang('Total')."   ".$period_array['total']."  
"; } /** * @author Sebastien Piraux * @param array_of_results : a 2 columns array * @param title1 : string, title of the first column * @param title2 : string, title of the ... second column * @desc display a 2 column tab from an array titles of columns are title1 and title2 */ function buildTab2col($array_of_results, $title1, $title2) { echo "\n"; echo "\n"; if (is_array($array_of_results)) { for ($j = 0 ; $j < count($array_of_results) ; $j++) { echo ''; echo ''; echo ''; echo "\n"; } } else { echo ''; echo ''; echo "\n"; } echo "
$title1 $title2
'.$array_of_results[$j][0].''.$array_of_results[$j][1].'
'.get_lang('NoResult').'
\n"; } /** * @author Sebastien Piraux * @param array_of_results : a 2 columns array * @desc display a 2 column tab from an array this tab has no title */ function buildTab2ColNoTitle($array_of_results) { echo "\n"; if (is_array($array_of_results)) { for ($j = 0 ; $j < count($array_of_results) ; $j++) { echo ''; echo ''; echo ''; echo "\n"; } } else { echo ''; echo ''; echo "\n"; } echo "
'.$array_of_results[$j][0].'  '.$array_of_results[$j][1].'
'.get_lang('NoResult').'
\n"; } /** * @author Sebastien Piraux * @param array_of_results : a 2 columns array * @desc this function is used to display integrity errors in the platform if array_of_results is not an array there is no error, else errors are displayed */ function buildTabDefcon($array_of_results) { echo "\n"; if (is_array($array_of_results)) { // there are some strange cases... echo ''; echo ''; echo "\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 ''; echo ''; echo ''; echo "\n"; } } else { // all right echo ''; echo ''; echo "\n"; } echo "
'.get_lang('Defcon').'
'.$key.''.$array_of_results[$j][1].'
'.get_lang('AllRight').'
\n"; }