function result_screen($mode = 'reg') { global $month_names; $page_title = "Statistic Center Results"; $page_detail = " "; // ----------------------------------------- if (!checkdate($_POST['to_month'], $_POST['to_day'], $_POST['to_year'])) { die("The 'Date To:' time is incorrect, please check the input and try again"); } if (!checkdate($_POST['from_month'], $_POST['from_day'], $_POST['from_year'])) { die("The 'Date From:' time is incorrect, please check the input and try again"); } // ----------------------------------------- $to_time = mktime(12, 0, 0, $_POST['to_month'], $_POST['to_day'], $_POST['to_year']); $from_time = mktime(12, 0, 0, $_POST['from_month'], $_POST['from_day'], $_POST['from_year']); // $sql_date_to = date("Y-m-d",$to_time); // $sql_date_from = date("Y-m-d",$from_time); $human_to_date = getdate($to_time); $human_from_date = getdate($from_time); // ----------------------------------------- if ($mode == 'reg') { $table = 'Registration Statistics'; $sql_table = 'users'; $sql_field = 'added'; $page_detail = "Showing the number of users registered. (Note: All times based on GMT)"; } else { if ($mode == 'rate') { $table = 'Rating Statistics'; $sql_table = 'ratings'; $sql_field = 'added'; $page_detail = "Showing the number of ratings. (Note: All times based on GMT)"; } else { if ($mode == 'post') { $table = 'Post Statistics'; $sql_table = 'posts'; $sql_field = 'added'; $page_detail = "Showing the number of posts. (Note: All times based on GMT)"; } else { if ($mode == 'msg') { $table = 'PM Sent Statistics'; $sql_table = 'messages'; $sql_field = 'added'; $page_detail = "Showing the number of sent messages. (Note: All times based on GMT)"; } else { if ($mode == 'torr') { $table = 'Torrent Statistics'; $sql_table = 'torrents'; $sql_field = 'added'; $page_detail = "Showing the number of Torrents. (Note: All times based on GMT)"; } else { if ($mode == 'bans') { $table = 'Ban Statistics'; $sql_table = 'bans'; $sql_field = 'added'; $page_detail = "Showing the number of Bans. (Note: All times based on GMT)"; } else { if ($mode == 'comm') { $table = 'Comment Statistics'; $sql_table = 'comments'; $sql_field = 'added'; $page_detail = "Showing the number of torrent Comments. (Note: All times based on GMT)"; } else { if ($mode == 'new') { $table = 'News Statistics'; $sql_table = 'news'; $sql_field = 'added'; $page_detail = "Showing the number of News Items added. (Note: All times based on GMT)"; } else { if ($mode == 'poll') { $table = 'Poll Statistics'; $sql_table = 'polls'; $sql_field = 'added'; $page_detail = "Showing the number of Polls added. (Note: All times based on GMT)"; } else { if ($mode == 'rqst') { $table = 'Request Statistics'; $sql_table = 'requests'; $sql_field = 'added'; $page_detail = "Showing the number of Requests made. (Note: All times based on GMT)"; } } } } } } } } } } switch ($_POST['timescale']) { case 'daily': $sql_date = "%w %U %m %Y"; $php_date = "F jS - Y"; // $sql_scale = "DAY"; break; case 'monthly': $sql_date = "%m %Y"; $php_date = "F Y"; // $sql_scale = "MONTH"; break; default: // weekly $sql_date = "%U %Y"; $php_date = " [F Y]"; // $sql_scale = "WEEK"; break; } $sortby = isset($_POST['sortby']) ? mysql_real_escape_string($_POST['sortby']) : ""; // $sortby = sqlesc($sortby); $sqlq = "SELECT UNIX_TIMESTAMP(MAX({$sql_field})) as result_maxdate,\n\t\t\t\t COUNT(*) as result_count,\n\t\t\t\t DATE_FORMAT({$sql_field},'{$sql_date}') AS result_time\n\t\t\t\t FROM {$sql_table}\n\t\t\t\t WHERE UNIX_TIMESTAMP({$sql_field}) > '{$from_time}'\n\t\t\t\t AND UNIX_TIMESTAMP({$sql_field}) < '{$to_time}'\n\t\t\t\t GROUP BY result_time\n\t\t\t\t ORDER BY {$sql_field} {$sortby}"; $res = @mysql_query($sqlq); $running_total = 0; $max_result = 0; $results = array(); if (mysql_num_rows($res)) { while ($row = mysql_fetch_assoc($res)) { if ($row['result_count'] > $max_result) { $max_result = $row['result_count']; } $running_total += $row['result_count']; $results[] = array('result_maxdate' => $row['result_maxdate'], 'result_count' => $row['result_count'], 'result_time' => $row['result_time']); } include 'chart/php-ofc-library/open-flash-chart.php'; foreach ($results as $pOOp => $data) { $counts[] = (int) $data['result_count']; if ($_POST['timescale'] == 'weekly') { $labes[] = "Week #" . strftime("%W", $data['result_maxdate']) . "\n" . date($php_date, $data['result_maxdate']); } else { $labes[] = date($php_date, $data['result_maxdate']); } } $title = new title($page_title . "\n" . ucfirst($_POST['timescale']) . " " . $table . " " . $human_from_date['mday'] . " " . $month_names[$human_from_date['mon']] . " " . $human_from_date['year'] . " to " . $human_to_date['mday'] . " " . $month_names[$human_to_date['mon']] . " " . $human_to_date['year']); $chart = new open_flash_chart(); $chart->set_title($title); $line_1 = new line_hollow(); $line_1->set_values($counts); $line_1->set_key($table . " | Total: " . $running_total, 12); $line_1->set_halo_size(1); $line_1->set_width(2); $line_1->set_colour('#0099FF'); $line_1->set_dot_size(5); $chart->add_element($line_1); $x_labels = new x_axis_labels(); $x_labels->set_steps(2); $x_labels->set_vertical(); $x_labels->set_colour('#000000'); $x_labels->set_size(12); $x_labels->set_labels($labes); $x = new x_axis(); $x->set_colours('#A2ACBA', '#ECFFAF'); $x->set_steps(2); $x->set_labels($x_labels); $chart->set_x_axis($x); $y = new y_axis(); $y->set_steps(2); $y->set_colour('#A2ACBA'); $y->set_range(0, max($counts) + 5, 50); $chart->add_y_axis($y); $cont = $chart->toPrettyString(); // toFile($_SERVER["DOCUMENT_ROOT"]."/chart/","chart.json",$cont,false); // unset($cont); $html = "<script type=\"text/javascript\" src=\"chart/js/json/json2.js\"></script>"; $html .= "<script type=\"text/javascript\" src=\"chart/js/swfobject.js\"></script>"; $html .= "<script type=\"text/javascript\">\n\n\t\t\t\tfunction open_flash_chart_data()\n\t\t\t\t{\n\t\t\t\treturn JSON.stringify(data);\n\t\t\t\t}\n\n\t\t\t\tfunction findSWF(movieName) {\n\t\t\t\t if (navigator.appName.indexOf(\"Microsoft\")!= -1) {\n\t\t\t\t\treturn window[movieName];\n\t\t\t\t } else {\n\t\t\t\t\treturn document[movieName];\n\t\t\t\t }\n\t\t\t\t}\n\n\t\t\t\tvar data = " . $cont . ";\n\n\t\t\t\t\t swfobject.embedSWF(\"chart/open-flash-chart.swf\", \"my_chart\", \"800\", \"" . (max($counts) * 5 < 200 ? "250" : (max($counts) * 5 > 400 ? "400" : max($counts) * 5)) . "\", \"9.0.0\", \"expressInstall.swf\", {\"loading\":\"Please wait while the stats are loaded!\"} );\n\t\t\t\t\t </script>"; $html .= "<div id=\"my_chart\"></div>"; } else { $html .= "No results found\n"; } print $html . "<br />"; }
private static function make_bandwidth_chart($values, $options = array()) { if (!$values || !count($values)) { return false; } $title = !empty($options['title']) ? $options['title'] : 'Chart'; //array_check_value($options, 'title', 'BI Chart'); $step = !empty($options['step']) ? $options['step'] : 0.75; //array_check_value($options, 'step', 0.75); $max = !empty($options['max']) ? $options['max'] : 0; //array_check_value($options, 'max', 0); $value_mod = !empty($options['value_modifier']) ? $options['value_modifier'] : 1; //array_check_value($options, 'value_modifier', 1); $input_title = !empty($options['input_title']) ? $options['input_title'] : 'Downloads for :key: #val#'; //array_check_value($options, 'input_title', 'Downloads for :key: #val#'); $output_title = !empty($options['output_title']) ? $options['output_title'] : 'Uploads for :key: #val#'; //array_check_value($options, 'output_title', 'Uploads for :key: #val#'); $total_title = !empty($options['total_title']) ? $options['total_title'] : 'Total for :key: #val#'; //array_check_value($options, 'total_title', 'Total for :key: #val#'); $on_click = !empty($options['on_click']) ? $options['on_click'] : false; //array_check_value($options, 'on_click', false); $x_labels = !empty($options['x_labels']) ? $options['x_labels'] : array_keys($values); //array_check_value($options, 'x_labels', array_keys($values)); include_once APP_FOLDER . '/libraries/php-ofc-library/ofc_title.php'; include_once APP_FOLDER . '/libraries/php-ofc-library/open-flash-chart.php'; //include(APP_FOLDER . '/libraries/php-ofc-library/ofc_bar_glass_value.php'); include_once APP_FOLDER . '/libraries/php-ofc-library/ofc_line_dot.php'; include_once APP_FOLDER . '/libraries/php-ofc-library/ofc_line_base.php'; include_once APP_FOLDER . '/libraries/php-ofc-library/ofc_x_axis.php'; $title = new title($title); $chart = new open_flash_chart(); $chart->set_title($title); $input = array(); $ouput = array(); $total = array(); $clicks = array(); foreach ($values as $key => $value) { $this_value = (double) number_format($value['input'] / $value_mod, 2, '.', ''); $tmp = new bar_glass_value($this_value); $tmp->set_tooltip(preg_replace('/:key/', $key, $input_title)); $input[] = $tmp; $this_value = (double) number_format($value['output'] / $value_mod, 2, '.', ''); $tmp = new bar_glass_value($this_value); $tmp->set_tooltip(preg_replace('/:key/', $key, $output_title)); $output[] = $tmp; $this_value = (double) number_format(($value['input'] + $value['output']) / $value_mod, 2, '.', ''); $tmp = new dot_value($this_value, '#000066'); $tmp->set_tooltip(preg_replace('/:key/', $key, $total_title)); $total[] = $tmp; if ($on_click) { $tmp = (double) number_format(($value['input'] + $value['output']) / $value_mod, 2, '.', ''); $clicks[] = $tmp; } $max = ceil(max(($value['input'] + $value['output']) / $value_mod, $max)); } $x_axis = new x_axis(); $x_axis->set_labels_from_array($x_labels); $x_axis->set_3d(5); $x_axis->colour = '#909090'; if ($max > 0) { //Don't know why we sometimes get a division by zero error @($max = $max + ($step - $max % $step)); } if ($max / $step > 5) { $step = floor($max / 5); } else { if ($max / $step <= 1) { $step = floor($max / 2); } } $y_axis = new y_axis(); $y_axis->set_range(0, $max, $step); $input_bar = new bar_glass(); $input_bar->set_values($input); $input_bar->colour = '#D54C78'; $output_bar = new bar_glass(); $output_bar->set_values($output); $output_bar->colour = '#78D54C'; $total_graph = new line_hollow(); $total_graph->set_colour('#9999FF'); $total_graph->set_values($total); if ($on_click) { $click_graph = new line(); $click_graph->set_values($clicks); $click_graph->set_on_click($on_click); $chart->add_element($click_graph); } $chart->set_x_axis($x_axis); $chart->set_y_axis($y_axis); $chart->add_element($input_bar); $chart->add_element($output_bar); $chart->add_element($total_graph); //$decoded = json_decode($chart->toString()); return $chart->toString(); }