<?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);
//====End ==============
define('TITLE','Settings');
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['exportd'])) {
	exportToCSV('Vouch_','vouchers','id,pin,credits,cost,used,validity'," WHERE customer_id = '".$userID."'");
	exit;
}
if(isset($_POST['action'])) {
  if($_POST['action']=='dvouch') {
	foreach($_POST['bulk'] as $inbid) { 
		mysqli_query($server,"DELETE FROM `vouchers` WHERE `id` = '$inbid' AND customer_id = '$userID'") or die(mysqli_error($server));
	}	
	logEvent($userID,'Deleted sms vouchers');
	$_SESSION['message'] = $LANG['The selected SMS Voucher(s) has been deleted'];
	header('location: rsetting?err=0&vouc');
  }
  if($_POST['action']=='delplan') {
	foreach($_POST['bulk'] as $inbid) { 
		mysqli_query($server,"DELETE FROM `sms_plans` WHERE `id` = '$inbid' AND customer_id = '$userID'") or die(mysqli_error($server));
	}	
	logEvent($userID,'Deleted sms plans');
	$_SESSION['message'] = $LANG['The selected SMS Plan(s) has been deleted'];
	header('location: rsetting?err=0&pack');
  }
  
}


if(isset($_REQUEST['dgt'])) {
	$tdelete = mysqli_real_escape_string($server,$_REQUEST['dgt']);
	mysqli_query($server,"DELETE FROM `paymentgateways` WHERE id = '$tdelete' AND customer_id = '$userID'") or die(mysqli_error($server));
	$_SESSION['message'] = $LANG['The selected payment gateway has been deleted'];
	header('location: rsetting?err=0&pay');
 }
 if(isset($_REQUEST['drt'])) {
	$tdelete = mysqli_real_escape_string($server,$_REQUEST['drt']);
	mysqli_query($server,"DELETE FROM `rates` WHERE id = '$tdelete' AND customer_id = '$userID'") or die(mysqli_error($server));
	$_SESSION['message'] = $LANG['The selected custom rate has been deleted'];
	header('location: rsetting?err=0&rate');
 }	
if(isset($_GET['set'])) {
?>
<div class="row no-m-t no-m-b">
 	<div class="col s12 m12 l12">
        <div class="card red">
            <div class="card-content white-text"><?=$LANG['You have not completed initial setup yet!']?></div>
        </div>
    </div>
 </div>
<?php } ?> 

 
<div class="row no-m-t no-m-b">
	<div class="col s12 m12 l12 responsive-tabs">
            
      <h5><?=$LANG['General']?></h5>
      <div class="card card-white <?php if(isset($_GET['gen'])) echo ' responsive-tabs__panel--active'?>">
            <div class="card-content">
                <form action="" method="post" id=",ain-sett" onSubmit="return false;">
                	<div class="row no-m-t no-m-b">   
	                     <div class="col s12 m6 l6">
    	                     <h5><?=$LANG['Branding']?></h5>
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="businessName" type="text" required class="validate" value="<?=getSetting('businessName',$userID)?>">
                                       <label for="businessName"><?=$LANG['Business Name']?></label>
                                 </div>
                             </div>	 
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="companyAddress" type="text" required class="validate" value="<?=getSetting('companyAddress',$userID)?>">
                                       <label for="companyAddress"><?=$LANG['Business Address']?></label>
                                 </div>
                             </div>	 
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="companyEmail" type="email" required class="validate" value="<?=getSetting('companyEmail',$userID)?>">
                                       <label for="companyEmail"><?=$LANG['Support Email']?></label>
                                 </div>
                             </div>	 
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="companyPhone" type="text" required class="validate" value="<?=getSetting('companyPhone',$userID)?>">
                                       <label for="companyPhone"><?=$LANG['Support Phone']?></label>
                                 </div>
                             </div>	
                            <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="companyWebsite" type="url" class="validate" value="<?=getSetting('companyWebsite',$userID)?>">
                                       <label for="companyWebsite"><?=$LANG['Website']?></label>
                                 </div>
                             </div>	
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="smsSender" type="text" class="validate" required value="<?=getSetting('smsSender',$userID)?>">
                                       <label for="smsSender"><?=$LANG['Default Sender ID']?></label>
                                 </div>
                             </div>	 
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="resellerDomain" type="text" required class="validate" value="<?=getSetting('resellerDomain',$userID)?>">
                                 <h6 class="m-t-md red-text darken-4" style="margin-top: -10px;"><strong><?=$LANG['reseller_domain_note'].gethostbyname($_SERVER['SERVER_NAME'])?></strong></h6>
                                       <label for="resellerDomain"><?=$LANG['Your Reseller Domain']?> (example.com)</label>
                                 </div>
                             </div>	 
                             <div class="row no-m-t no-m-b">
                                <div class="file-field input-field col s12">
                                    <div class="btn light-blue darken-4">
                                        <span><?=$LANG['Signature']?></span>
                                        <input id="files_sign" type="file" name="files_sign" accept="image/*">
                                    </div>
                                    <div class="file-path-wrapper">
                                        <input class="file-path validate" type="text" placeholder="<?=$LANG['Upload Invoice Signature']?>">
                                        <input type="hidden" id="invoiceSignature" value="<?=getSetting('invoiceSignature',$userID)?>">
                                    </div>
                                </div> 
							 </div>	
							<!--------------------------------- -->
                             <br>
                             <h5><?=$LANG['Appearance']?></h5>
                             <div class="row no-m-t no-m-b">
                                <div class="file-field input-field col s12">
                                    <div class="btn light-blue darken-4">
                                        <span><?=$LANG['Background']?></span>
                                        <input id="files_back" type="file" name="files_back" accept="image/*">
                                    </div>
                                    <div class="file-path-wrapper">
                                        <input class="file-path validate" type="text" placeholder="<?=$LANG['Upload Background Image']?>">
                                        <input type="hidden" id="siteBackground" value="<?=getSetting('siteBackground',$userID)?>">
                                    </div>
                                </div> 
							 </div>	
                             
                             <div class="row no-m-t no-m-b">
                                <div class="file-field input-field col s12">
                                    <div class="btn light-blue darken-4">
                                        <span><?=$LANG['Logo']?></span>
                                        <input id="files_logo" type="file" name="files_logo" accept="image/*">
                                    </div>
                                    <div class="file-path-wrapper">
                                        <input class="file-path validate" type="text" placeholder="<?=$LANG['Upload Your Logo']?>">
                                        <input type="hidden" id="siteLogo" value="<?=getSetting('siteLogo',$userID)?>">
                                    </div>
                                </div> 
							 </div>	
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s6"><?=$LANG['Background Color']?></div>
                                 <div class="input-field col s6">
                                       <input id="backgroundColor" type="color" pattern="#[a-f0-9]{6}" value="<?=getSetting('backgroundColor',$userID)?>">
                                 </div>
                             </div>	
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s6"><?=$LANG['Header Color']?></div>
                                 <div class="input-field col s6">
                                       <input id="headerColor" type="color" pattern="#[a-f0-9]{6}" value="<?=getSetting('headerColor',$userID)?>">
                                 </div>
                             </div>	                                       
                            <br>
                             <!-- end of settings -->
                          </div>
                          
                          <div class="col s12 m6 l6">
    	                      <h5><?=$LANG['Other Settings']?></h5> 
                              <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <select id="redirectToSite" required class="validate">
                                            <option value="1" <?php if(getSetting('redirectToSite',$userID)=='1') echo 'selected';?>><?=$LANG['Yes']?></option>
                                            <option value="0" <?php if(getSetting('redirectToSite',$userID)=='0') echo 'selected';?>><?=$LANG['No']?></option>
                                       </select>
                                       <label><?=$LANG['Send customers to website after logout']?></label>
                                 </div>
                              </div>
                              <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="taxAmount" type="text" class="validate" value="<?=getSetting('taxAmount',$userID)?>" placeholder="<?=$LANG['Leave empty or set to Zero to disable']?>">
                                       <label for="taxAmount"><?=$LANG['Invoice Tax (%)']?></label>
                                 </div>
                             </div>
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="vatAmount" type="text" class="validate" value="<?=getSetting('vatAmount',$userID)?>" placeholder="<?=$LANG['Leave empty or set to Zero to disable']?>">
                                       <label for="vatAmount"><?=$LANG['Invoice VAT (%)']?></label>
                                 </div>
                             </div>
                             <br>
                             <h5><?=$LANG['Outgoing Email Settings']?></h5> 
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="smtpServer" type="text" class="validate" value="<?=getSetting('smtpServer',$userID)?>">
                                       <label for="smtpServer"><?=$LANG['SMTP Server']?></label>
                                 </div>
                             </div>
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="smtpUsername" type="text" class="validate" value="<?=getSetting('smtpUsername',$userID)?>">
                                       <label for="smtpUsername"><?=$LANG['SMTP Username']?></label>
                                 </div>
                             </div>
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="smtpPassword" type="text" class="validate" value="<?=getSetting('smtpPassword',$userID)?>">
                                       <label for="smtpPassword"><?=$LANG['SMTP Password']?></label>
                                 </div>
                             </div>
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="smtpPort" type="text" class="validate" value="<?=getSetting('smtpPort',$userID)?>">
                                       <label for="smtpPort"><?=$LANG['SMTP Port']?></label>
                                 </div>
                             </div>
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <select id="smtpSecurity" required class="validate">
                                            <option value="ssl" <?php if(getSetting('smtpSecurity',$userID)=='ssl') echo 'selected';?>>SSL</option>
                                            <option value="tls" <?php if(getSetting('smtpSecurity',$userID)=='tls') echo 'selected';?>>TLS</option>
                                       </select>
                                       <label><?=$LANG['SMTP Security']?></label>
                                 </div>
                             </div>
                          </div>
                          
                    </div>
                <br>
                <div class="card-action">
                       <button id="cus-button" class="btn green darken-4" type="submit"><i class="fa fa-save"></i> <?=$LANG['Save Settings']?> </button>
                       <span id="cus-spin" class="btn-flat" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
                 </div>          
                </form>
            </div>
      </div>     
      
      <h5><?=$LANG['SMS/Email Notifications']?></h5>
      <div class="card card-white <?php if(isset($_GET['notic'])) echo ' responsive-tabs__panel--active'?>">
           <div class="card-content">
 <div class="row no-m-t no-m-b">
 	<div class="col s12 m12 l12">
        <div class="card blue-grey">
            <div class="card-content white-text"><?=$LANG['notification_shortcodes']?></div>
        </div>
    </div>
 </div>           
           		<form>
           		<div class="row no-m-t no-m-b">   
                	 <div class="col s12 m6 l6">
    	                    <h5><?=$LANG['Email Notifications']?></h5>
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="newAccountEmailSubject" type="text" class="validate" value="<?=getSetting('newAccountEmailSubject',$userID)?>">
                                       <label for="newAccountEmailSubject"><?=$LANG['New Account Welcome Email']?> <?=$LANG['Subject']?></label>
                                 </div>
                             </div>
                             <div class="row no-m-t no-m-b">
                                <div class="input-field col s12">
                                      <textarea id="newAccountEmail" placeholder="<?=$LANG['New Account Welcome Email']?>" class="materialize-textarea"><?=getSetting('newAccountEmail',$userID)?></textarea>
                                </div>
                             </div>
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="newPasswordEmailSubject" type="text" class="validate" value="<?=getSetting('newPasswordEmailSubject',$userID)?>">
                                       <label for="newPasswordEmailSubject"><?=$LANG['Password Reset Email']?> <?=$LANG['Subject']?></label>
                                 </div>
                             </div>
                             <div class="row no-m-t no-m-b">
                                <div class="input-field col s12">
                                      <textarea id="newPasswordEmail" placeholder="<?=$LANG['Password Reset Email']?>" class="materialize-textarea"><?=getSetting('newPasswordEmail',$userID)?></textarea>
                                </div>
                             </div>
                             
                             <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="orderApproveEmailSubject" type="text" class="validate" value="<?=getSetting('orderApproveEmailSubject',$userID)?>">
                                       <label for="orderApproveEmailSubject"><?=$LANG['Order Confirmation Email']?> <?=$LANG['Subject']?></label>
                                 </div>
                             </div>
                             <div class="row no-m-t no-m-b">
                                <div class="input-field col s12">
                                      <textarea id="orderApproveEmail" placeholder="<?=$LANG['Order Confirmation Email']?>" class="materialize-textarea"><?=getSetting('orderApproveEmail',$userID)?></textarea>
                                </div>
                             </div>
                            
                      </div>
                      
                      <div class="col s12 m6 l6">
    	                    <h5><?=$LANG['SMS Notifications']?></h5>
                      		<div class="row no-m-t no-m-b">
                                <div class="input-field col s12">
                                      <textarea id="newAccountSMS" class="materialize-textarea" length="960"><?=getSetting('newAccountSMS',$userID)?></textarea>
                                      <label for="newAccountSMS"><?=$LANG['New Account Welcome SMS']?></label>
                                </div>
                             </div>
                             
                             <div class="row no-m-t no-m-b">
                                <div class="input-field col s12">
                                      <textarea id="newPasswordSMS" class="materialize-textarea" length="960"><?=getSetting('newPasswordSMS',$userID)?></textarea>
                                      <label for="newPasswordSMS"><?=$LANG['Password Reset SMS']?></label>
                                </div>
                             </div>
                             
                             <div class="row no-m-t no-m-b">
                                <div class="input-field col s12">
                                      <textarea id="orderApproveSMS" class="materialize-textarea" length="960"><?=getSetting('orderApproveSMS',$userID)?></textarea>
                                      <label for="orderApproveSMS"><?=$LANG['Order Confirmation SMS']?></label>
                                </div>
                             </div>
                      </div>       
                </div>
                <br>
                <div class="card-action">
                    <button id="not-button" class="btn green darken-4" type="submit"><i class="fa fa-save"></i> <?=$LANG['Save Settings']?> </button>
                    <span id="not-spin" class="btn-flat" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
                </div> 
                </form>             
            </div>
       </div>
                
      <h5><?=$LANG['SMS Rates']?></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 m6 l7">
                          <h5><?=$LANG['SMS Rates']?></h5> 
                     <?php
                    $query="SELECT * FROM rates WHERE reseller_id = '$userID' 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['You have not created any SMS rates']?></h5>
                                </div>
                            </div>
                        </div>
                       </table> 
                      <?php } else { ?>  
                      <table class="responsive-table bordered">
                          <thead>
                            <tr>
                                <th data-field="ref"><?=$LANG['Type']?></th>
                                <th data-field="date"><?=$LANG['Country']?></th>
                                <th data-field="credit"><?=$LANG['Operator Prefix']?></th>
                                <th data-field="status"><?=$LANG['Rate']?></th>
                                <th data-field="act"></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><?=strtoupper($rows['type'])?></td>
                                 <td><?=$country?> </td>
                                 <td><?=$operator?></td>
                                 <td><?=userCurrencySymbol($userID).number_format(toUserCurrency($rows['rate'],$userID,getSetting('defaultCurrency')),4)?></td>
                                  <td><a class="hoverable red-text" onclick="return confirm('<?=$LANG['delete_confirm']?>');" href="rsetting?drt=<?=$rows['id']?>"><?=$LANG['Delete']?></a></td>
                             </tr>
                       <?php } ?>   
                          </tbody>
                      </table>
                      <?php } ?>
                      <br><br>
                     </div>
                
                     <div class="col s12 m6 l5 yellow lighten-5" style="border:1px solid black">
                          <form action="" method="post" id="credit-form" onSubmit="return false;">
                          	<h5><?=$LANG['Add New SMS Rate']?></h5> 
                            <div class="col s12 m12 l12">
                                <div class="card blue lighten-5">
                                    <div class="card-content"><?=$LANG['rate_tip']?></div>
                                </div>
                            </div>
                          	<div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <select id="type" required class="validate">
                                        <option value="sms"><?=$LANG['Text Message']?></option>
                                        <?php if(getSetting('unicodeEnabled',0)>0){?>
                                        <option value="unicode" ><?=$LANG['Unicode Message']?></option>
                                        <?php }?>
                                        <?php if(getSetting('voiceEnabled',0)>0){?>
                                        <option value="voice" ><?=$LANG['Voice Message']?></option>
                                        <?php } ?>
                                        <?php if(getSetting('watsappEnabled',0)>0){?>
                                        <option value="whatsapp" ><?=$LANG['WhatsApp Message']?></option>
                                        <?php } ?>
                                        <?php if(getSetting('mmsEnabled',0)>0){?>
                                        <option value="mms" ><?=$LANG['Multimedia Message']?></option>
                                        <?php } ?>
                                        <?php if(getSetting('flashEnabled',0)>0){?>
                                        <option value="flash" ><?=$LANG['Flash Message']?></option>
                                        <?php } ?>
                                   </select>
                                   <label><?=$LANG['Rate for']?></label>
                             </div>
                           </div>                      
                           <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <select id="country_code" required class="js-states browser-default"  style="width: 100%" >
                                       		<option value="0" ><?=$LANG['All Countries']?></option>
                                            <?=getCountryList('') ?>                            
                                       </select>
                                       <label class="active"><?=$LANG['Country']?></label>
                                 </div>
                             </div>
                           <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="operator_code" type="number" class="validate" value="" placeholder="Eg. 803 for MTN Nigeria, 82 for Vodaconn South-Africa" >
                                       <label for="operator_code"><?=$LANG['Operator Prefix']?></label>
                                 </div>
                            </div>
                            <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="rate" type="text" class="validate" required value="">
                                       <label for="rate"><?=$LANG['Rate']?> (<?=userCurrencyCode($userID)?>)</label>
                                 </div>
                            </div>
                           <div class="card-action">
                                <input id="customer_id2" value="0" type="hidden" >
                                <input id="gateway" value="0" type="hidden" >
                                <button id="rate-button" class="btn green darken-4" type="submit"><i class="fa fa-save"></i> <?=$LANG['Save Rate']?> </button>
                                <span id="rate-spin" class="btn-flat" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
                           </div>
                        </form>
                     </div>
                     
				</div>                
            </div>
      </div>  
      
      <h5><?=$LANG['Payment Gateways']?></h5>
      <div class="card card-white <?php if(isset($_GET['pay'])) echo ' responsive-tabs__panel--active'?>">
            <div class="card-content">
            	<span class="card-title"><?=$LANG['Payment Gateways']?></span>
                
                 <div class="row no-m-t no-m-b right"> 
                	<a class='waves-effect waves-light btn teal accent-4 white-text' href="#" onclick="$('#add_gateway_pop').show('slow');"><i class="fa fa-plus-circle"></i> <?=$LANG['Create New Gateway']?></a>
                </div>             	
                <div class="row no-m-t no-m-b">   
                     <div class="col s12 m12 l12">
                    <?php
                    $query="SELECT * FROM paymentgateways WHERE customer_id = '$userID' ORDER BY id DESC limit $pageLimit,$setLimit";
					$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 created any payment gateways! Customers will not be able to make payments untill you do so']?></h5>
                                </div>
                            </div>
                        </div>

                       </table> 
                      <?php } else { ?>  
                      <table class="responsive-table bordered">
                          <thead>
                            <tr>
                                <th data-field="ref"><?=$LANG['ID']?></th>
                                <th data-field="date"><?=$LANG['Title']?></th>
                                <th data-field="credit"><?=$LANG['Type']?></th>
                                <th data-field="valid"><?=$LANG['Status']?></th>
                                <th data-field="act"></th>
                             </tr>
                          </thead>
                          <tbody>
                       <?php
                        while ($rows = mysqli_fetch_assoc($result)) { 
						$status = $LANG['Enabled'];
						if($rows['enabled'] < 1)	$status =$LANG['Disabled'];
						$charge_type = 'fixed';
						if($rows['charges_perc'] > 0) $charge_type = 'percent';
						$params = "'$rows[type]','$rows[title]','$rows[param1]','$rows[param2]','$rows[param3]','$rows[minimum_order]','$charge_type','$rows[charges_perc]','$rows[charges_fix]','".str_replace("\n", '\n',$rows['text'])."','$rows[enabled]','$rows[id]'";
						?>
                             <tr>
                               	 <td><?=$rows['id']?></td>
                                 <td><?=$rows['title']?></td>
                                 <td><?=ucfirst($rows['type'])?></td>
                                 <td><?=$status?> </td>
                                 <td><a class="hoverable" href="#" onclick="editPayG(<?=$params?>);"><i class="fa fa-pencil"></i> <?=$LANG['Edit']?></a> &nbsp;
                                 <a class="hoverable red-text" onclick="return confirm('<?=$LANG['delete_confirm']?>');" href="rsetting?dgt=<?=$rows['id']?>"><i class="fa fa-trash"></i> <?=$LANG['Delete']?></a></td>
                             </tr>
                       <?php } ?>   
                       		</form>
                          </tbody>
                      </table>
                      <?php } ?>
                      <div class="col s12 m12 l12" style="margin-top: 5px;">
                          <?php displayPagination($setLimit,$page,$query,'vouc');  ?>
                      </div>
                   </div>
                </div>   
            </div>
      </div> 
      
      <?php if(getSetting('useSMSPackage',0)>0) { ?>
      <h5><?=$LANG['SMS Plans']?></h5>
      <div class="card card-white <?php if(isset($_GET['pack'])) echo ' responsive-tabs__panel--active'?>">
           <div class="card-content">
            	<div class="card-title">
                 <div class="row no-m-t no-m-b">
                 	<div class="input-field col s12 m12 l12" >
                 	  <div class="switch m-b-md">
                    	 <label id="sch_swit" class="black-text"><?=$LANG['Disable SMS Plans']?> <input <?php if(getSetting('useSMSPackage',$userID)>0) { echo 'checked';} ?> type="checkbox" id="useSMSPackage"><span class="lever"></span><?=$LANG['Enable SMS Plans']?></label>
                   	  </div>
                    </div>
                 </div>
                </div>
                        
                <div class="row no-m-t no-m-b right"> 
                	<a class='waves-effect waves-light btn teal accent-4 white-text' href="#" onclick="$('#add_plan_pop').show('slow');"><i class="fa fa-plus-circle"></i> <?=$LANG['Create New Plan']?></a>
                    <a class='waves-effect waves-light btn red white-text'  href="#" onclick="bulkaction2('delplan','inbox-form2','<?=$LANG['delete_confirm']?>');"> <i class="fa fa-trash"></i> <?=$LANG['Delete Selected']?></a>
                </div>             	
                <div class="row no-m-t no-m-b">   
                     <div class="col s12 m12 l12">
                          <h5><?=$LANG['SMS Plans']?></h5> 
                    <?php
                    $query="SELECT * FROM sms_plans WHERE customer_id = '$userID' ORDER BY id DESC limit $pageLimit2,$setLimit";
					$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 created any SMS plans']?></h5>
                                </div>
                            </div>
                        </div>

                       </table> 
                      <?php } else { ?>  
                      <table class="responsive-table bordered">
                          <thead>
                            <tr>
                            	<th><input type="checkbox" class="filled-in" id="selectall2" /><label for="selectall2"></label></th>
                                <th data-field="ref"><?=$LANG['Plan']?></th>
                                <th data-field="date"><?=$LANG['Credits']?></th>
                                <th data-field="credit"><?=$LANG['Price']?></th>
                                <th data-field="valid"><?=$LANG['Validity']?></th>
                             </tr>
                          </thead>
                          <tbody>
                          <form action="rsetting?pack" method="post" id="inbox-form2">
                    	<input type="hidden" id="bulkaction2" name="action" value=""/>
                          <?php
                        while ($rows = mysqli_fetch_assoc($result)) { 
						$validity = $LANG['Life-time'];
						if($rows['validity'] > 0)	$validity = $rows['validity'].' '.$LANG['Day(s)'];
						?>
                             <tr>
                                 <td><input type="checkbox" class="filled-in bulk2" id="bulk<?=$rows['id']?>" value="<?=$rows['id']?>" name="bulk[<?=$rows['id']?>]"/> <label for="bulk<?=$rows['id']?>"></label></td> 

                               	 <td><?=$rows['title']?></td>
                                 <td><?=userCurrencySymbol($userID).number_format(toUserCurrency($rows['credits'],$userID,getSetting('defaultCurrency')),4)?></td>
                                 <td><?=userCurrencySymbol($userID).number_format(toUserCurrency($rows['price'],$userID,getSetting('defaultCurrency')),4)?></td>
                                 <td><?=$validity?> </td>
                             </tr>
                       <?php } ?>   
                       		</form>
                          </tbody>
                      </table>
                      <?php } ?>
                      <div class="col s12 m12 l12" style="margin-top: 5px;">
                          <?php displayPagination2($setLimit,$pag,$query,'pack');  ?>
                      </div>
                     </div>
                     
				</div>
            </div>
      </div>  
      <?php } ?>
      
      <?php if(getSetting('useSMSVoucher',0)>0) { ?>
      <h5><?=$LANG['SMS Vouchers']?></h5>
      <div class="card card-white <?php if(isset($_GET['vouc'])) echo ' responsive-tabs__panel--active'?>">
           <div class="card-content">
            	<div class="card-title">
                 <div class="row no-m-t no-m-b">
                 	<div class="input-field col s12 m12 l12" >
                 	  <div class="switch m-b-md">
                    	 <label id="sch_swit2" class="black-text"><?=$LANG['Disable SMS Vouchers']?> <input <?php if(getSetting('useSMSVoucher',$userID)>0) { echo 'checked';} ?> type="checkbox" id="useSMSVoucher"><span class="lever"></span><?=$LANG['Enable SMS Vouchers']?></label>
                   	  </div>
                    </div>
                 </div>
                </div>
                <div class="row no-m-t no-m-b right"> 
                	<a class='waves-effect waves-light btn teal accent-4 white-text' href="#" onclick="$('#add_vouc_pop').show('slow');"><i class="fa fa-plus-circle"></i> <?=$LANG['Generate Vouchers']?></a>
                    <a class='waves-effect waves-light btn red white-text'  href="#" onclick="bulkaction('dvouch','inbox-form','<?=$LANG['delete_confirm']?>');"> <i class="fa fa-trash"></i> <?=$LANG['Delete Selected']?></a>
                    <a class='waves-effect waves-light btn green white-text' href='rsetting?exportd&vouc'><i class="fa fa-file-excel-o"></i> Export</a>
                </div>
             	
                <div class="row no-m-t no-m-b">   
                     <div class="col s12 m12 l12">
                          <h5><?=$LANG['SMS Vouchers']?></h5> 
                      <?php
                    $query="SELECT * FROM vouchers WHERE customer_id = '$userID' ORDER BY id DESC limit $pageLimit,$setLimit";
					$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 created any Vouchers yet']?></h5>
                                </div>
                            </div>
                        </div>
                       </table> 
                      <?php } else { ?>  
                      <table class="responsive-table bordered">
                          <thead>
                            <tr>
                            	<th><input type="checkbox" class="filled-in" id="selectall" /><label for="selectall"></label></th>
                                <th data-field="ref"><?=$LANG['PIN']?></th>
                                <th data-field="date"><?=$LANG['Credits']?></th>
                                <th data-field="credit"><?=$LANG['Price']?></th>
                                <th data-field="valid"><?=$LANG['Validity']?></th>
                                <th data-field="status"><?=$LANG['Status']?></th>
                             </tr>
                          </thead>
                          <tbody>
                          <form action="rsetting?vouc" method="post" id="inbox-form">
                    	<input type="hidden" id="bulkaction" name="action" value=""/>
                          <?php
                        while ($rows = mysqli_fetch_assoc($result)) { 
						$validity = $LANG['Life-time'];
						$status = $LANG['Unused'];
						if($rows['validity'] > 0)	$validity = $rows['validity'].' '.$LANG['Day(s)'];
						if($rows['used'] > 0)	$status = $LANG['Used'];
						?>
                             <tr>
                                 <td><input type="checkbox" class="filled-in bulk" id="bulk<?=$rows['id']?>" value="<?=$rows['id']?>" name="bulk[<?=$rows['id']?>]"/> <label for="bulk<?=$rows['id']?>"></label></td> 

                               	 <td><!--<?=substr($rows['pin'],0,-12) . '*****'?>-->
                                 <?=$rows['pin']?></td>
                                 <td><?=userCurrencySymbol($userID).number_format(toUserCurrency($rows['credits'],$userID,getSetting('defaultCurrency')),4)?></td>
                                 <td><?=userCurrencySymbol($userID).number_format(toUserCurrency($rows['cost'],$userID,getSetting('defaultCurrency')),4)?></td>
                                 <td><?=$validity?> </td>
                                 <td><?=$status?></td>
                             </tr>
                       <?php } ?>   
                       		</form>
                          </tbody>
                      </table>
                      <?php } ?>
                      <div class="col s12 m12 l12" style="margin-top: 5px;">
                          <?php displayPagination($setLimit,$page,$query,'vouc');  ?>
                      </div>
                         
                     </div>
				</div>
                
            </div>
      </div>  
     <?php } ?>    	
	</div>
</div>

<!--  //Popups  ---->
 <!--add rates -->
<div id="add_vouc_pop" style="display: none; overflow-x: hidden; width: 99.99%; height: 99.99%; z-index: 1000; position: fixed; top: 0; left: 0; background: rgba(0,0,0,0.7);">
   	 <div class="row"><br><br>
       	<div class="col s1 m2 l3"> </div>
        <div class="col s10 m8 l6 white"> 
             <h5><?=$LANG['Generate Vouchers']?> <span class="right"><a href="#" class="red-text" onclick="$('#add_vouc_form')[0].reset();$('#add_vouc_pop').hide('slow');"><i class="fa fa-times"></i></a></span></h5>
             <div class="card ">
                 <div class="card-content">
                 	<form action="" method="post" id="add_vouc_form" onSubmit="return false;">
                         <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <select id="quantity" required class="validate">
                                        <option value="1">1 <?=$LANG['Voucher']?></option>
                                        <option value="5">5 <?=$LANG['Vouchers']?></option>
                                        <option value="10">10 <?=$LANG['Vouchers']?></option>
                                        <option value="20">20 <?=$LANG['Vouchers']?></option>
                                        <option value="50">50 <?=$LANG['Vouchers']?></option>
                                        <option value="75">75 <?=$LANG['Vouchers']?></option>
                                        <option value="100">100 <?=$LANG['Vouchers']?></option>
                                   </select>
                                   <label><?=$LANG['Quantity']?></label>
                             </div>
                           </div>                      
                           
                           <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="credit" type="text" class="validate" required value="" >
                                       <label for="credit"><?=$LANG['Credits']?> (<?=userCurrencyCode($userID)?>)</label>
                                 </div>
                            </div>
                            <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="cost" type="text" class="validate" required value="">
                                       <label for="cost"><?=$LANG['Cost']?> (<?=userCurrencyCode($userID)?>)</label>
                                 </div>
                            </div>
                            <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="validity" type="number" class="validate" required value="" placeholder="<?=$LANG['validity_tip']?>" >
                                       <label for="validity"><?=$LANG['Validity in Days']?></label>
                                 </div>
                            </div>
                           <div class="card-action">
                                <button id="vouch-button" class="btn green darken-4" type="submit"><i class="fa fa-save"></i> <?=$LANG['Save Rate']?> </button>
                                <span id="vouch-spin" class="btn-flat" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
                            <a class="btn waves-effect waves-light red" href="#" onclick="$('#add_vouc_form')[0].reset();$('#add_vouc_pop').hide('slow');"><i class="fa fa-times"></i> <?=$LANG['Cancel']?></a>
                           </div>
                        </form>
                 </div>
              </div>
        </div>      
        <div class="col s1 m2 l3"> </div>  
     </div>
</div>  

 <!--add rates -->
<div id="add_plan_pop" style="display: none; overflow-x: hidden; width: 99.99%; height: 99.99%; z-index: 1000; position: fixed; top: 0; left: 0; background: rgba(0,0,0,0.7);">
   	 <div class="row"><br><br>
       	<div class="col s1 m2 l3"> </div>
        <div class="col s10 m8 l6 white"> 
             <h5><?=$LANG['Add New SMS Plan']?> <span class="right"><a href="#" class="red-text" onclick="$('#add_plan_form')[0].reset();$('#add_plan_pop').hide('slow');"><i class="fa fa-times"></i></a></span></h5>
            
             <div class="card ">
                 <div class="card-content">
                 	<form action="" method="post" id="add_plan_form" onSubmit="return false;">
                        	<div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="name" type="text" class="validate" required value="" >
                                       <label for="name"><?=$LANG['Title']?></label>
                                 </div>
                            </div>                    
                           
                           <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="credit2" type="text" class="validate" required value="" >
                                       <label for="credit2"><?=$LANG['Credits']?> (<?=userCurrencyCode($userID)?>)</label>
                                 </div>
                            </div>
                            <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="cost2" type="text" class="validate" required value="">
                                       <label for="cost2"><?=$LANG['Price']?> (<?=userCurrencyCode($userID)?>)</label>
                                 </div>
                            </div>
                            <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="validity2" type="number" class="validate" required value="" placeholder="<?=$LANG['validity_tip']?>" >
                                       <label for="validity2"><?=$LANG['Validity in Days']?></label>
                                 </div>
                            </div>
                            
                           <div class="card-action">
                                <button id="plan-button" class="btn green darken-4" type="submit"><i class="fa fa-save"></i> <?=$LANG['Save Rate']?> </button>
                                <span id="plan-spin" class="btn-flat" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
                            <a class="btn waves-effect waves-light red" href="#" onclick="$('#add_plan_form')[0].reset();$('#add_plan_pop').hide('slow');"><i class="fa fa-times"></i> <?=$LANG['Cancel']?></a>
                           </div>
                        </form>
                 </div>
              </div>
        </div>      
        <div class="col s1 m2 l3"> </div>
     </div>
</div>           

 <!--add payment gateway -->
<div id="add_gateway_pop" style="display: none; overflow-x: hidden; width: 99.99%; height: 99.99%; z-index: 1000; position: fixed; top: 0; left: 0; background: rgba(0,0,0,0.7);">
   	 <div class="row"><br><br>
       	<div class="col s1 m2 l3"> </div>
        <div class="col s10 m8 l6 white"> 
             <h5><?=$LANG['Add New Payment Gateway']?> <span class="right"><a href="#" class="red-text" onclick="$('#add_gateway_form')[0].reset();$('#add_gateway_pop').hide('slow');"><i class="fa fa-times"></i></a></span></h5>
            
             <div class="card ">
                 <div class="card-content">
                 	<form action="" method="post" id="add_gateway_form" onSubmit="return false;">
	                    	<div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                   <select id="gtype" required class="validate">
                                        <option value="" disabled selected><?=$LANG['Select a gateway template']?></option>
                                        <?php $query="SELECT * FROM paymentgateway_templates WHERE status = 1";
                                        $result = mysqli_query($server,$query) or die(mysqli_error($server));
                                        while ($rows = mysqli_fetch_assoc($result)) { 
                                            echo '<option value="'.$rows['alias'].'">'.$rows['title'].'</option>';
                                        }
                                       ?> 
                                    </select>
                                    <label><?=$LANG['Gateway Type']?></label>
                                </div>
                            </div>
                        	<div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="gtitle" type="text" class="validate" required value="" >
                                       <label for="gtitle"><?=$LANG['Display Name']?></label>
                                 </div>
                            </div>                    
                           <div class="row no-m-t no-m-b" id="show_p1" style="display:none;">
                                 <div class="input-field col s12">
                                       <input id="param1" type="text" class="validate" value="" >
                                       <label for="param1" id="label_p1"></label>
                                 </div>
                            </div>
                           <div class="row no-m-t no-m-b" id="show_p2" style="display:none;">
                                 <div class="input-field col s12">
                                       <input id="param2" type="text" class="validate" value="" >
                                       <label for="param2" id="label_p2"></label>
                                 </div>
                            </div>
                            <div class="row no-m-t no-m-b" id="show_p3" style="display:none;">
                                 <div class="input-field col s12">
                                       <input id="param3" type="text" class="validate" value="" >
                                       <label for="param3" id="label_p3"></label>
                                 </div>
                            </div>                           
                           <div class="row no-m-t no-m-b">
                                 <div class="input-field col s12">
                                       <input id="minimum_order" type="text" class="validate" value="0.00" >
                                       <label for="minimum_order"><?=$LANG['Minimum Order']?> (<?=userCurrencyCode($userID)?>)</label>
                                 </div>
                            </div>
                           <div class="row no-m-t no-m-b">
                           	  <div class="input-field col s12">
                                   <select id="charge_type" required class="validate">
                                        <option value="0"><?=$LANG['None']?></option>
                                        <option value="fixed"><?=$LANG['Fixed Amount']?></option>
                                        <option value="percent"><?=$LANG['Percentage of Order Total']?></option>
                                   </select>
                                   <label><?=$LANG['Gateway Fee Type']?></label>
                           	  </div>
                            </div>
                            <div class="row no-m-t no-m-b" id="hide_fix" style="display: none;">
                                 <div class="input-field col s12">
                                       <input id="charges_perc" type="text" class="validate" value="0.00">
                                       <label for="charges_perc"><?=$LANG['Gateway Fee Percentage']?> (%)</label>
                                 </div>
                            </div>
                            <div class="row no-m-t no-m-b"  id="hide_pec" style="display: none;">
                                 <div class="input-field col s12">
                                       <input id="charges_fix" type="text" class="validate" value="0.00">
                                       <label for="charges_fix"><?=$LANG['Gateway Fee Ammount']?> (<?=userCurrencyCode($userID)?>)</label>
                                 </div>
                            </div>

                            <div class="row no-m-t no-m-b">
                                <div class="input-field col s12">
                                      <textarea id="text" class="materialize-textarea" length="960"></textarea>
                                      <label for="text"><?=$LANG['Gateway Notice']?></label>
                                </div>
                           </div>
                          <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <select id="genabled" required class="validate">
                                        <option value="1"><?=$LANG['Yes']?></option>
                                        <option value="0"><?=$LANG['No']?></option>
                                   </select>
                                   <label><?=$LANG['Enable Gateway']?></label>
                             </div>
                           </div>  
                            
                           <div class="card-action">
                           		<input type="hidden" id="gateway_id" value="0">
                                <button id="gate-button" class="btn green darken-4" type="submit"><i class="fa fa-save"></i> <?=$LANG['Save Gateway']?> </button>
                                <span id="gate-spin" class="btn-flat" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Please wait']?>...</strong></span>
                            <a class="btn waves-effect waves-light red" href="#" onclick="$('#add_gateway_form')[0].reset();$('#add_gateway_pop').hide('slow');"><i class="fa fa-times"></i> <?=$LANG['Cancel']?></a>
                           </div>
                        </form>
                 </div>
              </div>
        </div>      
        <div class="col s1 m2 l3"> </div>
     </div>
</div>   
