| <?php |
| |
| $columns = array( |
| "project_id", |
| "stats_date", |
| "liveness", |
| "bugs_total", |
| "bugs_7_delta", |
| "bugs_7_percentage", |
| "bugs_7_gainloss", |
| "bugs_30_delta", |
| "bugs_30_percentage", |
| "bugs_30_gainloss", |
| "bugs_180_delta", |
| "bugs_180_percentage", |
| "bugs_180_gainloss", |
| "news_7_answer_average_time", |
| "news_7_unanswered_number", |
| "news_7_insider_posts", |
| "news_7_number_posts", |
| "news_7_average_posts", |
| "news_30_answer_average_time", |
| "news_30_unanswered_number", |
| "news_30_insider_posts", |
| "news_30_number_posts", |
| "news_30_average_posts", |
| "mail_7_number_posts", |
| "mail_7_average_posts", |
| "mail_7_average_subscribers", |
| "mail_30_number_posts", |
| "mail_30_average_posts", |
| "mail_30_average_subscribers", |
| "mail_180_number_posts", |
| "mail_180_average_posts", |
| "mail_180_average_subscribers", |
| ); |
| |
| require_once "/home/data/httpd/eclipse-php-classes/system/dbconnection_dashboard_rw.class.php"; |
| require_once $_SERVER['DOCUMENT_ROOT'] . "/projects/stats/hostname.php"; |
| |
| $dbc_cache = new DBConnectionDashboard(); |
| $db_handle = $dbc_cache->connect(); |
| |
| function download_csv_dashboard($db_handle,$project){ |
| global $columns; |
| $csv_file = ""; |
| $count = count($columns); |
| for ($i = 0; $i < $count; $i++) { |
| $csv_file .= $columns[$i] . ","; |
| } |
| $csv_file .= "\r\n"; |
| |
| if ($project == ""){ |
| // Get last available date |
| $query = "SELECT stats_date FROM ".stats_table()." ORDER BY stats_date DESC LIMIT 1"; |
| $result = mysql_query($query,$db_handle); |
| $row = mysql_fetch_assoc($result); |
| $last_date = $row['stats_date']; |
| |
| // Main query to select all stats from dashboard |
| $query = "SELECT * FROM ".stats_table()." WHERE stats_date = \"".$last_date."\""; |
| }else{ |
| $query = "SELECT * FROM ".stats_table()." WHERE project_id = \"".$project."\" ORDER BY stats_date DESC"; |
| } |
| $result = mysql_query($query,$db_handle); |
| while($row = mysql_fetch_assoc($result)){ |
| for ($i = 0; $i < $count; $i++) { |
| $value = $row[$columns[$i]]; |
| if( $columns[$i] == "stats_date" ) { |
| $pos1 = strpos($value,"-"); |
| $pos2 = strpos($value,"-",$pos1+1); |
| $month = substr($value, $pos1+1, $pos2-$pos1-1); |
| $day = substr($value, $pos2+1); |
| $year = substr($value, 0, $pos1); |
| $value = $month . "/" . $day . "/" . $year; |
| } |
| $csv_file .= $value . ","; |
| } |
| $csv_file .= "\r\n"; |
| } |
| |
| return $csv_file; |
| } |
| |
| @ob_start(); |
| |
| if (isset($_GET['project'])){ |
| $project = ereg_replace("[^a-zA-Z0-9 ]","",$_GET['project']); |
| $csv_file = download_csv_dashboard($db_handle,$project); |
| $output_file = $project.'_statistics.csv'; |
| }else{ |
| $project = ""; |
| $csv_file = download_csv_dashboard($db_handle,$project); |
| $output_file = 'dashboard_statistics.csv'; |
| } |
| |
| @ob_end_clean(); |
| @ini_set('zlib.output_compression', 'Off'); |
| header('Pragma: public'); |
| header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); |
| header('Cache-Control: no-store, no-cache, must-revalidate'); |
| header('Cache-Control: pre-check=0, post-check=0, max-age=0'); |
| header('Content-Transfer-Encoding: none'); |
| // This should work for IE & Opera |
| header('Content-Type: application/octetstream; name="' . $output_file . '"'); |
| // This should work for the rest |
| header('Content-Type: application/octet-stream; name="' . $output_file . '"'); |
| header('Content-Disposition: inline; filename="' . $output_file . '"'); |
| echo $csv_file; |
| |
| $output_file = null; |
| $csv_file = null; |
| $query = null; |
| $result = null; |
| $db_handle = null; |
| $dbc_cache = null; |
| |
| exit(); |
| ?> |