<?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 =============
$pag = $page = 1; $setLimit = 20;
if(isset($_GET["page"])) $page = (int)$_GET["page"];
$pageLimit = ($page * $setLimit) - $setLimit; 
if(isset($_GET["pag"])) $pag = (int)$_GET["pag"];
$pageLimit2 = ($pag * $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);
define('TITLE','Pricing');
//====End ==============

$today = date('Y-m-d'); $time = strtotime($today.'-1 months'); $lastMonth = date("Y-m", $time); $time = strtotime($today.'-1 years'); $lastYear = date("Y", $time);
?>
<div class="row no-m-t no-m-b">
	<div class="col s12 m12 l12 responsive-tabs">
                
      <h5><?=$LANG['Standard SMS Prices']?></h5>
      <div class="card invoices-card <?php if(isset($_GET['rate'])) echo ' responsive-tabs__panel--active'?>">
            <div class="card-content">
            	<div class="row no-m-t no-m-b">   
                
                     <div class="col s12 ">
                     <?php
                    $query="SELECT * FROM rates WHERE reseller_id = '".userData($userID,'reseller')."' AND customer_id = 0 ORDER BY id DESC";
					$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['No rates information found']?></h5>
                                </div>
                            </div>
                        </div>
                       </table> 
                      <?php } else { ?>  
                      <table class="responsive-table bordered">
                          <thead>
                            <tr>
                                <th data-field="date"><?=$LANG['Country']?></th>
                                <th data-field="credit"><?=$LANG['Operator Prefix']?></th>
                                <th data-field="ref"><?=$LANG['Type']?></th>
                                <th data-field="status"><?=$LANG['Rate']?></th>
                             </tr>
                          </thead>
                          <tbody>
                          <?php
                        while ($rows = mysqli_fetch_assoc($result)) { 
						$link = '';
						$gateway = '';
						$operator = $rows['operator_code'];
						$country = countryName(getCountryByCode($rows['country_code']));
						if($rows['gateway_id'] < 1)	$gateway = $LANG['All'];
						if($rows['operator_code'] < 1)	$operator = $LANG['Any Operator'];
						if($rows['country_code'] < 1)	$country = $LANG['All'];
						if($rows['type']=='sms') $rows['type'] = 'text'
						?>
                             <tr>
                                 <td><?=$country?> </td>
                                 <td><?=$operator?></td>
                               	 <td><?=strtoupper($rows['type'])?></td>
                                 <td><?=userCurrencySymbol($userID).number_format(toUserCurrency($rows['rate'],userData($userID,'reseller'),$userID),userCurrencyZero($userID))?></td>
                             </tr>
                       <?php } ?>   
                          </tbody>
                      </table>
                      <?php } ?>
                      <br><br>
                     </div>

				</div>                
            </div>
      </div>  
	
       <h5><?=$LANG['My Custom SMS Prices']?></h5>
      <div class="card invoices-card ">
            <div class="card-content">
            	<div class="row no-m-t no-m-b">   
                     <div class="col s12">
                     <?php
                    $query="SELECT * FROM rates WHERE customer_id = '$userID' ORDER BY id DESC";
					$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 been assigned any custom SMS rates']?></h5>
                                </div>
                            </div>
                        </div>
                       </table> 
                      <?php } else { ?>  
                      <table class="responsive-table bordered">
                          <thead>
                            <tr>
                                <th data-field="date"><?=$LANG['Country']?></th>
                                <th data-field="credit"><?=$LANG['Operator Prefix']?></th>
                                <th data-field="ref"><?=$LANG['Type']?></th>
                                <th data-field="status"><?=$LANG['Rate']?></th>
                             </tr>
                          </thead>
                          <tbody>
                          <?php
                        while ($rows = mysqli_fetch_assoc($result)) { 
						$link = '';
						$gateway = '';
						$operator = $rows['operator_code'];
						$country = countryName(getCountryByCode($rows['country_code']));
						if($rows['gateway_id'] < 1)	$gateway = $LANG['All'];
						if($rows['operator_code'] < 1)	$operator = $LANG['Any Operator'];
						if($rows['country_code'] < 1)	$country = $LANG['All'];
						if($rows['type']=='sms') $rows['type'] = 'text'
						?>
                             <tr>
                                 <td><?=$country?> </td>
                                 <td><?=$operator?></td>
                               	 <td><?=strtoupper($rows['type'])?></td>
                                 <td><?=userCurrencySymbol($userID).number_format(toUserCurrency($rows['rate'],userData($userID,'reseller'),$userID),userCurrencyZero($userID))?></td>
                             </tr>
                       <?php } ?>   
                          </tbody>
                      </table>
                      <?php } ?>
                      <br><br>
                     </div>

				</div>                
            </div>
      </div>  
      <!-- -->
	</div>
</div>
