<?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','Transfer');
if(!isAdmin(getUser()) && (userData(getUser(),'phone') == '' || userData(getUser(),'first_name') == '') ) {
	header('location: profile?setting'); exit();
}
if(!isAdmin(getUser()) && userData($userID,'email_verified') != 0) {
	showVerify();
}
$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($_REQUEST['exportc'])) { 
		exportToCSV('TransferLog_','transactions','id,date,receiver,credits,transaction_reference'," WHERE customer_id = '".getUser()."' AND is_shared = 1");
		exit;
	}		
?>
<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['transf_intro']?></div>
        </div>
    </div>
 </div>

 <div class="row no-m-t no-m-b">
     <div class="col s12 m6 l5">  
         <div class="card card-white">
 
             <div class="card-content">  
                    <span class="card-title"><?=$LANG['Transfer Credit']?></span>
                <form action="share" method="post" id="share_ph"  onSubmit="return false;">
                	<div class="row no-m-t no-m-b">
                     <div class="input-field col s12">
                           <input id="member" type="text" class="validate" required value="">
                           <label for="member"><?=$LANG['Receiver\'s Email']?></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 to Transfer']?></label>
                     </div>
                   </div>
                    <div class="row no-m-t no-m-b">
                     <div class="input-field col s12">
                           <input id="pass" type="password" class="validate" required value="">
                           <label for="pass"><?=$LANG['Your Password']?></label>
                     </div>
                   </div>
                   <div class="card-action">
                        <button id="share-button" class="btn ight-blue darken-4" type="submit"><i class="fa fa-share"></i> <?=$LANG['Transfer']?> </button>
                        <span id="share-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>           

<?php
	$added  = '';
	if(isset($_GET['s'])) {

	} else {
		$added .= " order by id DESC ";	
	}

    $query="SELECT * FROM transactions WHERE customer_id = '$userID' AND is_shared = 1 $added limit $pageLimit,$setLimit";
	$result = mysqli_query($server,$query) or die(mysqli_error($server));
	$x = mysqli_num_rows($result);
?>     
     <div class="col s12 m6 l7">
         <div class="card card-white">
            <div class="card-content">
             	<span class="card-title"><?=$LANG['Transfer History']?></span>
            </div>    
            <div class="card-content">
            	<div class="card-options">
                      <a class='waves-effect waves-light btn green white-text' href='share?exportc=1'>Export</a>
                </div>
                <table class="highlight responsive-table">
                <?php if($x>0) { ?>
                <thead>
                	<tr>
                        <th data-field="date"><?=$LANG['Date']?></th>
                        <th data-field="to"><?=$LANG['Recipient']?></th>
                        <th data-field="message"><?=$LANG['Credits']?></th>
                        <th data-field="ref"><?=$LANG['Reference']?></th>
                    </tr>
                 </thead>
                 <?php } ?>
                 <tbody>
<?php $xf=0; while ($rows = mysqli_fetch_assoc($result)) { $xf+=1;
?>
						<tr class="">
                             <td><?=date('M j, Y',strtotime($rows['date']))?></td>
                             <td><?=userData($rows['receiver'],'email')?></td>
                             <td><?=number_format($rows['credits'],4)?></td>
                             <td><?=$rows['transaction_reference']?></td>
                        </tr>
<?php } ?>
<?php if($xf<1) echo '<tr class="orange lighten-5"><td colspan=10><h5 class="center-align">'.$LANG['No records found!'].'</h5></td></tr>' ?>	
					</form>
                 </tbody>
            </table>          
     	</div>
  	</div>
    <div class="row">
        <div class="col s12 m12 l12" style="margin-top: 5px;">
            <?php displayPagination($setLimit,$page,$query);  ?>
        </div>
    </div>                       
 </div>     
