<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
global $configverssion_id; global $configapp_version; global $userID; global $server; global $LANG; $resellerID = getReseller();
//=== List page stuffs =============
$page = 1; $setLimit = 30;
if(isset($_GET["page"])) $page = (int)$_GET["page"];
$pageLimit = ($page * $setLimit) - $setLimit; 
$pageurl=$_SERVER['REQUEST_URI']."?";
if(count($_GET)) { $pageurl = $_SERVER['REQUEST_URI'].'&'; }
$trans = array("s=d_o" => "", "s=d_n" => "", "s=r_h" => "", "s=r_l" => "", "s=s_r" => "", "s=s_u" => "", "s=s_q" => "", "s=s_c" => "", "s=s_f" => "", "s=s_p" => "");
$pageurl = strtr($pageurl,$trans);
$pageurl = str_replace('&&','&',$pageurl);
//====End ==============
define('TITLE','Report');
if(!isAdmin(getUser()) && (userData(getUser(),'phone') == '' || userData(getUser(),'first_name') == '') ) {
	header('location: profile?setting'); exit();
}
if(!isAdmin(getUser()) && userData($userID,'email_verified') != 0) {
	showVerify();
}
if(userRole()==4) {
	//header('location: index.php');	
}

$today = date('Y-m-d'); $time = strtotime($today.'-1 months'); $lastMonth = date("Y-m", $time); $time = strtotime($today.'-1 years'); $lastYear = date("Y", $time);
?>
<?php
	if(isset($_GET['export'])) {
	exportToCSV('Sent_messages_','sentmessages','id,date,type,sender_id,message,to_count,status'," WHERE customer_id = '".getUser()."'");
	exit;
	}
?>
<!-- Quick Navs ::::: You can customize this -->
 <div class="row no-m-t no-m-b">
 	<div class="col s12 m12 l12">
        <div class="card blue">
            <div class="card-content white-text"><?=$LANG['report_tip']?></div>
        </div>
    </div>
 </div>

<?php $from = '1970-01-01 00:00:00'; $to = date('Y-m-d H:i:s');?>
<div class="row no-m-t no-m-b">
 	<div class="col s12 m4 l3">
         <div class="card stats-card purple accent-4" >
             <div class="card-content">
                 <span class="card-title" style="color: white;"><?=$LANG['All Traffics']?></span>
                 <span class="stats-counter" style="color: white;"><span class="counter" style="color: white;"><?=number_format(countAllSMS($from,$to))?></span></span>
             </div>
          </div>
    </div>
    <div class="col s12 m4 l3">
         <div class="card stats-card light-green darken-4" >
             <div class="card-content">
                 <span class="card-title" style="color: white;"><?=$LANG['Successful']?></span>
                 <span class="stats-counter" style="color: white;"><span class="counter" style="color: white;"><?=number_format(countSentSMS($from,$to))?></span></span>
             </div>
          </div>
    </div>
    <div class="col s12 m4 l3">
         <div class="card stats-card red darken-4" >
             <div class="card-content">
                 <span class="card-title" style="color: white;"><?=$LANG['Unsuccessful']?></span>
                 <span class="stats-counter" style="color: white;"><span class="counter" style="color: white;"><?=number_format(countFailedSMS($from,$to) )?></span></span>
             </div>
          </div>
    </div>
    <div class="col s12 m4 l3">
         <div class="card stats-card deep-purple darken-4" >
             <div class="card-content">
                 <span class="card-title" style="color: white;"><?=$LANG['Total Cost']?></span>
                 <span class="stats-counter" style="color: white;"><?=userCurrencySymbol($userID)?><span class="counter" style="color: white;"><?=number_format(creditUsed($userID),2)?></span></span>
             </div>
          </div>
    </div>   
 </div>

	<div class="row no-m-t no-m-b">   
       <div class="col s12 m12 l12">
         <div class="card card-white">
            <div class="card-content">
            	<div class="card-options">
            	<ul>
                    <li><a class='dropdown-button waves-effect waves-teal btn-flat' href='#' data-constrainwidth='false' data-activates='sms_chart_filt'><i class="fa fa-calendar"></i> <?=$LANG['Filter']?></a></li>
                </ul>    
                <ul id='sms_chart_filt' class='dropdown-content'>
                        <li><a href="?day">Today</a></li>
                        <li><a href="?week">Past 7 Days</a></li>
                        <li><a href="?month">This Month</a></li>
                        <li><a href="?months">Past 30 Days</a></li>
                        <li><a href="?quater">Past 3 Months</a></li>
                        <li><a href="?half">Past 6 Months</a></li>
                        <li><a href="?year">This Year</a></li> 
                </ul>
            </div>
                 <div class="row no-m-t no-m-b" >
                     <div class="col s12">
                         <ul class="tabs tab-demo z-depth-1" style="width: 100%;">
                             <li class="tab col s6"><a href="#statu" class=""><?=$LANG['By Status']?></a></li>
                         </ul>
                     </div>
                     <span class="secondary-title black-text" id="sms_chart_desc"></span>
                     <div  class="col s12"><div id="chart1" style="max-height: 290px;"></div></div>
                     <a class="green-text"><i class="fa fa-square"></i> <?=$LANG['Sent SMS']?></a>&nbsp;&nbsp;&nbsp;
                        <a class="red-text"><i class="fa fa-square"></i> <?=$LANG['Failed SMS']?></a>
                 </div>   
                 <div class="row no-m-t no-m-b" >
                     <div class="col s12">
                         <ul class="tabs tab-demo z-depth-1" style="width: 100%;">
                             <li class="tab col s6"><a href="#count" class=""><?=$LANG['By Country']?></a></li>
                         </ul>
                     </div>
                     <span class="secondary-title black-text" id="sms_chart_desc"></span>
                     <div class="col s12"><canvas id="chart2" width="600" height="250"></canvas></div>
                     <a class="green-text"><i class="fa fa-square"></i> <?=$LANG['Sent SMS']?></a>&nbsp;&nbsp;&nbsp;
                        <a class="red-text"><i class="fa fa-square"></i> <?=$LANG['Failed SMS']?></a>
                 </div>   
            </div>  
         </div>

     </div>
  </div>

