/** * Load overview box content. * * @return void * @access public */ public function box() { // prepare box data switch ($this->get["box"]) { case "most_recent": // most recent calls $recent = $this->db->GetAssoc("\n\t\t\t\t\tSELECT uniqueid,calldate,src,dst,SEC_TO_TIME(duration) AS formatted_duration\n\t\t\t\t\tFROM " . DB_TABLE . "\n\t\t\t\t\tORDER BY calldate DESC LIMIT 12;\n\t\t\t\t"); $this->template->cdrs = $recent; break; case "summary_day": // summary for the current day $barchart = new BarChart(date("l jS F Y") . " (minutes)"); $barchart->dimensions = "300x265"; $barchart->x_labels = range(0, 23); $barchart->margins = array(25, 5, 5, 5); $barchart->barwidth = 6; $barchart->palette = CHART_PALETTE; foreach ($barchart->x_labels as $hour) { $from = sprintf(date("Y-m-d") . " %02d:00:00", $hour); $to = sprintf(date("Y-m-d") . " %02d:59:59", $hour); $sql = "SELECT COALESCE(SUM(duration),0) FROM " . DB_TABLE . " WHERE calldate >= '{$from}' AND calldate <= '{$to}'"; $minutes = round($this->db->getOne($sql) / 60); $barchart->values[] = $minutes; } $this->template->chart = $barchart->saveFile(CHART_CACHE); break; case "summary_week": // summary for the current week if (date("l") == "Monday") { $mm = strtotime("today"); } else { $mm = strtotime("last Monday"); } $barchart = new BarChart("W/B " . date("l jS F Y", $mm) . " (minutes)"); $barchart->dimensions = "300x265"; $barchart->x_labels = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); $barchart->margins = array(25, 5, 5, 5); $barchart->barwidth = 25; $barchart->palette = CHART_PALETTE; for ($i = 0; $i <= 6; $i++) { $ts = $mm + 86400 * $i; $from = sprintf(date("Y-m-d", $ts) . " 00:00:00"); $to = sprintf(date("Y-m-d", $ts) . " 23:59:59"); $sql = "SELECT COALESCE(SUM(duration),0) FROM " . DB_TABLE . " WHERE calldate >= '{$from}' AND calldate <= '{$to}'"; $minutes = round($this->db->getOne($sql) / 60); $barchart->values[] = $minutes; } $this->template->chart = $barchart->saveFile(CHART_CACHE); break; case "top_src": // most popular sources $popular = $this->db->GetAssoc("\n\t\t\t\t\tSELECT src, COUNT(*) AS count\n\t\t\t\t\tFROM " . DB_TABLE . "\n\t\t\t\t\tWHERE src IS NOT NULL AND src != ''\n\t\t\t\t\tGROUP BY src\n\t\t\t\t\tORDER BY count DESC LIMIT 12;\n\t\t\t\t"); $this->template->numbers = $popular; break; case "top_dst": // most popular destinations $popular = $this->db->GetAssoc("\n\t\t\t\t\tSELECT dst, COUNT(*) AS count\n\t\t\t\t\tFROM " . DB_TABLE . "\n\t\t\t\t\tWHERE dst IS NOT NULL AND dst != ''\n\t\t\t\t\tGROUP BY dst\n\t\t\t\t\tORDER BY count DESC LIMIT 12;\n\t\t\t\t"); $this->template->numbers = $popular; break; case "top_clid": // most popular caller IDs $popular = $this->db->GetAssoc("\n\t\t\t\t\tSELECT clid, COUNT(*) AS count\n\t\t\t\t\tFROM " . DB_TABLE . "\n\t\t\t\t\tWHERE clid IS NOT NULL AND clid != ''\n\t\t\t\t\tGROUP BY clid\n\t\t\t\t\tORDER BY count DESC LIMIT 12;\n\t\t\t\t"); $this->template->numbers = $popular; break; case "longest_calls": // longest calls $recent = $this->db->GetAssoc("\n\t\t\t\t\tSELECT uniqueid,calldate,src,dst,SEC_TO_TIME(duration) AS formatted_duration\n\t\t\t\t\tFROM " . DB_TABLE . "\n\t\t\t\t\tORDER BY duration DESC LIMIT 12;\n\t\t\t\t"); $this->template->cdrs = $recent; break; } // render box template $this->template->show("box_" . $this->get["box"]); }
/** * Detailed year report. * * @return void * @access public */ public function year() { // which year? if (isset($this->get["year"])) { $year = $this->get["year"]; } else { $year = strftime("%Y", time()); } // list of overview boxes to render (in order). $boxes = array("general_stats", "top_src", "top_dst", "top_clid"); // set list of boxes to render $this->template->boxes = $boxes; $this->template->boxlist = "'" . implode("','", $boxes) . "'"; // set month and year information in template $this->template->year = $year; // array of month names for chart X axis $monthnames = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); // create calls chart $chart_calls = new BarChart("Calls per month ({$year})"); $chart_calls->dimensions = "700x350"; $chart_calls->margins = array(35, 35, 35, 35); $chart_calls->barwidth = 45; $chart_calls->palette = CHART_PALETTE; $chart_calls->x_labels = $monthnames; // create minutes chart $chart_mins = new BarChart("Minutes per month ({$year})"); $chart_mins->dimensions = "700x350"; $chart_mins->margins = array(35, 35, 35, 35); $chart_mins->barwidth = 45; $chart_mins->palette = CHART_PALETTE; $chart_mins->x_labels = $monthnames; // calculate daily statistics foreach (range(1, 12) as $month) { $month = sprintf("%02d", $month); $stat = $this->db->GetRow("\n\t\t\t\tSELECT\tCOUNT(*) AS calls,\n\t\t\t\t\tSUM(duration) AS seconds\n\t\t\t\tFROM " . DB_TABLE . "\n\t\t\t\tWHERE \tcalldate >= '{$year}-{$month}-01 00:00:00'\n\t\t\t\t\tAND calldate < DATE_ADD('{$year}-{$month}-01 00:00:00', INTERVAL 1 MONTH);\n\t\t\t"); $chart_calls->values[] = $stat["calls"]; $chart_mins->values[] = round($stat["seconds"] / 60); } // create time of day breakdown chart $chart_todb = new BarChart("Time of day breakdown (number of calls) ({$year})"); $chart_todb->dimensions = "700x350"; $chart_todb->margins = array(35, 35, 35, 35); $chart_todb->barwidth = 16; $chart_todb->palette = CHART_PALETTE; $chart_todb->x_labels = range(0, 23); // calculate time of day breakdown $hours = array(); foreach (range(0, 23) as $hour) { $stat = $this->db->GetOne(sprintf("\n\t\t\t\tSELECT COUNT(*) AS calls\n\t\t\t\tFROM " . DB_TABLE . "\n\t\t\t\tWHERE\tcalldate LIKE '{$year}%%'\n\t\t\t\t\tAND calldate LIKE '%% %02d:%%'\n\t\t\t", $hour)); $chart_todb->values[] = $stat; } // assign chart URLs to template $this->template->chart_calls = $chart_calls->saveFile(CHART_CACHE); $this->template->chart_mins = $chart_mins->saveFile(CHART_CACHE); $this->template->chart_todb = $chart_todb->saveFile(CHART_CACHE); // render page $this->template->show("year"); }