<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
global $configverssion_id; global $configapp_version; global $userID; global $server; global $LANG; global $resellerID;
define('TITLE','Dashboard');
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) {
	if(getSetting('businessName',$userID)=='' || getSetting('companyEmail',$userID)=='' ) {
		header('location: rsetting?set'); exit();
	}
	if(countPayGates(0)< 1) {
		header('location: rsetting?set&pay'); exit();
	}
}

$today = date('Y-m-d'); $time = strtotime($today.'-1 months'); $lastMonth = date("Y-m", $time); $time = strtotime($today.'-1 years'); $lastYear = date("Y", $time);
?>
<!-- Quick Navs ::::: You can customize this -->
 <div class="row no-m-t no-m-b">
	    <a href="compose">
        <div class="col l2 m2 s4">
        	<div class="card white center-align hoverable featmenu">
            <p><i class="material-icons small">send</i>
            <br><?=$LANG['Send Message']?></p>
            </div>
        </div></a>       
        <a href="report">
        <div class="col l2 m2 s4">
        	<div class="card white center-align hoverable featmenu">
            <p><i class="material-icons small ">show_chart</i>
            <br><?=$LANG['SMS Reports']?></p>
            </div>
        </div></a>
        <a href="phonebook">
        <div class="col l2 m2 s4">
        	<div class="card white center-align hoverable featmenu">
            <p><i class="material-icons small ">contact_phone</i>
            <br><?=$LANG['Address Book']?></p>
            </div>
        </div></a>
        <a href="profile">
        <div class="col l2 m2 s4">
        	<div class="card white center-align hoverable featmenu">
            <p><i class="material-icons small ">account_circle</i>
            <br><?=$LANG['My Profile']?></p>
            </div>
        </div></a>
        <a href="apis">
        <div class="col l2 m2 s4">
        	<div class="card white center-align hoverable featmenu">
            <p><i class="material-icons small ">code</i>
            <br><?=$LANG['HTTP API']?></p>
            </div>
        </div></a>                
        <?php if(isset($_SESSION['manageUser']) && $_SESSION['manageUser']>0) {?>
            <a href="index.php?exituser">
        <?php } else {?>
            <a href="index.php?logout">
        <?php }?>
        <div class="col l2 m2 s4">
        	<div class="card white center-align hoverable featmenu">
            <p><i class="material-icons small ">power_settings_new</i>
            <?php if(isset($_SESSION['manageUser']) && $_SESSION['manageUser']>0) {?>
                <br><?=$LANG['Exit']?></p>
            <?php } else {?>
                <br><?=$LANG['Logout']?></p>
            <?php }?>
            </div>
        </div></a>       
 </div>

<!-- Important Facts ::::: You can customize this --> 
 <div class="row no-m-t no-m-b">
 	<div class="col s12 m4 l3">
         <div class="card stats-card green accent-4" >
             <div class="card-content">
                 <span class="card-title" style="color: white;"><?=$LANG['Current Balance']?></span>
                 <span class="stats-counter" style="color: white;"><?=userCurrencySymbol($userID)?><span class="counter" style="color: white;"><?=number_format(userWalletBalance($userID),userCurrencyZero($userID))?></span></span>
             </div>
          </div>
    </div>
    <div class="col s12 m4 l3">
         <div class="card stats-card teal darken-1" >
             <div class="card-content">
                 <span class="card-title" style="color: white;"><?=$LANG['Last Recharge']?></span>
                 <span class="stats-counter" style="color: white;"><?=userCurrencySymbol($userID)?><span class="counter" style="color: white;"><?=number_format(userLastRecharge($userID),userCurrencyZero($userID))?></span></span>
             </div>
          </div>
    </div>
    <div class="col s12 m4 l3">
         <div class="card stats-card light-green darken-3" >
             <div class="card-content">
                 <span class="card-title" style="color: white;"><?=$LANG['Total Credit Recharged']?></span>
                 <span class="stats-counter" style="color: white;"><?=userCurrencySymbol($userID)?><span class="counter" style="color: white;"><?=number_format(userAllRecharge($userID),userCurrencyZero($userID))?></span></span>
             </div>
          </div>
    </div>
    <div class="col s12 m4 l3">
         <div class="card stats-card orange darken-4" >
             <div class="card-content">
                 <span class="card-title" style="color: white;"><?=$LANG['Total Credits Used']?></span>
                 <span class="stats-counter" style="color: white;"><?=userCurrencySymbol($userID)?><span class="counter" style="color: white;"><?=number_format(creditUsed($userID)-userCreditShared($userID),userCurrencyZero($userID))?></span></span>
             </div>
          </div>
    </div>   
 </div>
 
 <!-- SMS Trafic Chat -->
<div class="row no-m-t no-m-b">
    <div class="col s12 m12 l12">
        <div class="card visitors-card">
            <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="<?=thisURL()?>#day">Today</a></li>
                        <li><a href="<?=thisURL()?>#week">Past 7 Days</a></li>
                        <li><a href="<?=thisURL()?>#month">This Month</a></li>
                        <li><a href="<?=thisURL()?>#months">Past 30 Days</a></li>
                        <li><a href="<?=thisURL()?>#quater">Past 3 Months</a></li>
                        <li><a href="<?=thisURL()?>#half">Past 6 Months</a></li>
                        <li><a href="<?=thisURL()?>#year">This Year</a></li> 
                    </ul>
                </div>
    	        <span class="card-title"><?=$LANG['SMS Traffic By Status']?>
                	<span class="secondary-title" id="sms_chart_desc"></span>
                    <span class="secondary-title right">
                    	<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>
                    </span>
            	</span>
               	<div id="chart1"></div>
            </div>    
        </div>
    </div>
</div>
<div class="row no-m-t no-m-b">
	<div class="col s12 m6 l5">
       <div class="card visitors-card">
           <div class="card-content">
               <span class="card-title"><?=$LANG['SMS Traffic By Country']?><small></small></span>
       		   <div id="flot1"></div>
           </div>
      </div>
    </div>

    <!-- Recent mesages -->
    <div class="col s12 m6 l7">
        <div class="card invoices-card">
             <div class="card-content">
                 <div class="card-options">
                      <a href="sent" class="waves-effect waves-light btn"><?=$LANG['History']?></a>
                  </div>
                  <span class="card-title"><?=$LANG['My Recent Traffic']?></span>
               <?php
			    $query="SELECT * FROM sentmessages WHERE customer_id = '$userID' ORDER BY id DESC LIMIT 5";
				$result = mysqli_query($server,$query) or die(mysqli_error($server));
				$x = mysqli_num_rows($result);
				if($x < 1) {
				?><table>	   
                  <div class="col s12 m12 l12">
                        <div class="card blue lighten-5">
                            <div class="card-content">
            	                 <h3 class="center-align"><i class="fa fa-exclamation-circle"></i></h3>
			                     <h5 class="center-align"><?=$LANG['You have not sent any messages yet']?></h5>
                            </div>
                        </div>
                    </div>
                   </table> 
                  <?php } else { ?>  
                  <table class="responsive-table bordered">
                      <thead>
                        <tr>
                            <th data-field="message"><?=$LANG['Message']?></th>
                            <th data-field="date"><?=$LANG['Date']?></th>
                            <th data-field="progress"><?=$LANG['Progress']?></th>
                            <th data-field="credits"><?=$LANG['Credits']?></th>
                         </tr>
                      </thead>
                      <tbody>
                      <?php
					while ($rows = mysqli_fetch_assoc($result)) { ?>
                         <tr>
                           <td><?=shorten($rows['message'],60)?></td>
                           <td><?=timeElapsed($rows['date'])?></td>
                           <td><a class="tooltipped" data-position="left" data-delay="50" data-tooltip="<?=messageProgress($rows['id'])?> <?=$LANG['messages processed']?>"><span class="pie"><?=messageProgress($rows['id'])?></span></a></td>
                           <td><?=userCurrencySymbol($userID)?><?=number_format(messageCost($rows['id']),userCurrencyZero($userID))?></td>
                         </tr>
                   <?php } ?>   
                      </tbody>
                  </table>
                  <?php } ?>
             </div>
        </div>
    </div>                         
</div>