<?php /** * **************************************************************************************** * Copyright (c) 2013 Christopher W. * Olsen <cwolsen@ubixtechnologies.com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions, the following disclaimer and the list of authors. Redistributions in binary * form must reproduce the above copyright notice, this list of conditions, the following * disclaimer and the list of authors in the documentation and/or other materials provided * with the distribution. Neither the name of the uBix Cube Project nor the names of its * contributors may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $Id: index_json.php 940 2017-09-07 20:12:42Z reddawg $ * * *************************************************************************************** */ /* Main include info */ ini_set ( 'include_path', $_SERVER ['DOCUMENT_ROOT'] . "/include/" ); include ("config.php"); $ubF->session->Validate_JSON ( 'A_V_', 0 ); if ( !isset ( $form_data ['req'] ) ) $form_data ['req'] = -1; $_day = 60 * 60 * 24; $rData ['authenticated'] = $ubF->session->auth_data ['authenticated']; switch ( $form_data ['req'] ) { case 'call_history' : $hDays = (isset ( $form_data ['days'] )) ? $form_data ['days'] : 30; $_time = time () - ($_day * $hDays); $query = "SELECT count(calldate) as total_calls, sum(CASE WHEN dcontext LIKE '%-out' THEN 1 ELSE 0 END) as outbound_calls, sum(CASE WHEN dcontext NOT LIKE '%-out' THEN 1 ELSE 0 END) as inbound_calls, DATE_FORMAT(calldate, '%m-%d-%y') as statDay FROM cdr_master WHERE calldate >= '" . date ( "Y-m-d 00:00:00", $_time ) . "' AND calldate <= '" . date ( "Y-m-d 23:59:59" ) . "' GROUP BY YEAR(calldate), MONTH(calldate), DAY(calldate) ORDER BY calldate ASC"; $res =$ubF->DB['cdr']->query ( $query ); for ( $i = $res->num_rows ; $i > 0 ; $i-- ) { $qData = $res->fetch_row (); $rData ['data'] ['labels'] [] = $qData [3]; $rData ['data'] ['total_calls'] [] = $qData [0]; $rData ['data'] ['outbound_calls'] [] = $qData [1]; $rData ['data'] ['inbound_calls'] [] = $qData [2]; } break; case 'ytd_history' : $query = "SELECT count(calldate) as total_calls, sum(CASE WHEN dcontext LIKE '%-out' THEN 1 ELSE 0 END) as outbound_calls, sum(CASE WHEN dcontext NOT LIKE '%-out' THEN 1 ELSE 0 END) as inbound_calls, DATE_FORMAT(calldate, '%m-%d-%y') as statDay FROM cdr_master WHERE calldate >= '" . date ( "Y-01-01 00:00:00" ) . "' AND calldate <= '" . date ( "Y-12-31 23:59:59" ) . "' GROUP BY WEEK(calldate) ORDER BY calldate ASC"; $res =$ubF->DB['cdr']->query ( $query ); for ( $i = $res->num_rows ; $i > 0 ; $i-- ) { $qData = $res->fetch_row (); $rData ['data'] ['labels'] [] = $qData [3]; $rData ['data'] ['total_calls'] [] = $qData [0]; $rData ['data'] ['outbound_calls'] [] = $qData [1]; $rData ['data'] ['inbound_calls'] [] = $qData [2]; } break; default : $rData ['data'] = Array ( 0 ); break; } print json_encode ( $rData ); ?>