<?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','Account');
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

	$did = getUser();	
	$query="SELECT * FROM users WHERE id = '$did'"; 
	$result = mysqli_query($server,$query) or die(mysqli_error($server));  
	$profile = mysqli_fetch_assoc($result); 
	if($profile['id'] > 0) {
		$id = $profile['id'];	
		$type = 'Customer';
		if($profile['role_id']==3) $type = 'Reseller';
		$status = '<span class="green-text">'.$LANG['Active'].'</span';
		if($profile['status']==0) $status = '<span class="red-text">'.$LANG['Suspended'].'</span';
		$e_very = '<span class="green-text">'.$LANG['Verified'].'</span';
		if($profile['email_verified']!=0) $e_very = '<span class="red-text">'.$LANG['Unverified'].'</span';
		$p_very = '<span class="green-text">'.$LANG['Verified'].'</span';
		if($profile['phone_verified']!=0) $p_very = '<span class="red-text">'.$LANG['Unverified'].'</span';
	} else {
		header('location: rcustomer');	
	}
	
?>

  <div class="row">
     <div class="col s12 m12 l12"><h5><?=$LANG['My Account']?></h5> </div>
   </div>  
   
 <div class="row no-m-t no-m-b">
 	<div class="col s12 m4 l3">
         <div class="card stats-card blue-grey darken-4" >
             <div class="card-content">
                 <span class="card-title" style="color: white;"><?=$LANG['Current Balance']?></span>
                 <span class="stats-counter" style="color: white;"><?=userCurrencySymbol($profile['id'])?><span class="counter" style="color: white;"><?=number_format(userWalletBalance($profile['id']),4)?></span></span>
             </div>
          </div>
    </div>
    <div class="col s12 m4 l3">
         <div class="card stats-card blue-grey darken-4" >
             <div class="card-content">
                 <span class="card-title" style="color: white;"><?=$LANG['Last Recharge']?></span>
                 <span class="stats-counter" style="color: white;"><?=userCurrencySymbol($profile['id'])?><span class="counter" style="color: white;"><?=number_format(userLastRecharge($profile['id']),4)?></span></span>
             </div>
          </div>
    </div>
    <div class="col s12 m4 l3">
         <div class="card stats-card blue-grey darken-4" >
             <div class="card-content">
                 <span class="card-title" style="color: white;"><?=$LANG['Total Credit Recharged']?></span>
                 <span class="stats-counter" style="color: white;"><?=userCurrencySymbol($profile['id'])?><span class="counter" style="color: white;"><?=number_format(userAllRecharge($profile['id']),4)?></span></span>
             </div>
          </div>
    </div>
    <div class="col s12 m4 l3">
         <div class="card stats-card blue-grey 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($profile['id'])?><span class="counter" style="color: white;"><?=number_format(creditUsed($profile['id'])+(-userCreditShared($profile['id'])),4)?></span></span>
             </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">
            	 <div class="card-title"><i class="material-icons">info</i> <?=$LANG['Account Information']?></div>
                  <div class="card-content center-align">
                     <img src="files/temp/<?=userData($profile['id'],'photo')?>" class="circle" alt="" style="max-width: 150px;">
                     <p class="m-t-lg flow-text"><?=ucfirst($profile['first_name'].' '.$profile['last_name'])?></p>
                      <a class="btn waves-effect waves-light indigo darken-4" href="#" onclick="addPB();"><i class="fa fa-pencil"></i> <?=$LANG['Update Profile']?></a> 
                </div>
            	<table class="highlight responsive2-table">
                	<tbody>
                        <tr class="">
                            <td><b><?=$LANG['Account Type']?></b></td>
                            <td><?=$LANG[$type]?></td>
                        </tr>
                        <tr class="">
                            <td><b><?=$LANG['Account Status']?></b></td>
                            <td><?=$status?></td>
                        </tr>
                        <tr class="">
                            <td><b><?=$LANG['Member Since']?></b></td>
                            <td><?=date('F j Y',strtotime($profile['date']))?></td>
                        </tr>
                        <tr class="">
                            <td><b><?=$LANG['Last Login']?></b></td>
                            <td><?=date('F j Y h:iA',$profile['last_login'])?></td>
                        </tr>
                        <tr class="">
                            <td><b><?=$LANG['Last IP']?></b></td>
                            <td><a target="_blank" href="http://www.geoiptool.com/en/?IP=<?=$profile['last_ip']?>"><?=$profile['last_ip']?></a></td>
                        </tr>
                        <?php $from = '1970-01-01 00:00:00'; $to = date('Y-m-d H:i:s');?>
                    </tbody>
                </table>
            </div>
         </div> 
         
     </div>           

    <div class="col s12 m6 l7">
        <div class="card card-white">   
            <div class="card-content">
            	 <div class="card-title"><i class="material-icons">contact_phone</i> <?=$LANG['Contact Information']?></div>
            	<table class="highlight responsive2-table">
                	<tbody>
                    	<tr class="">
                			<td><b><?=$LANG['Email Address']?></b></td>
                            <td><?=$profile['email'].' &nbsp;&nbsp;'.$e_very?></td>        	
                        </tr>
                        <tr class="">
                			<td><b><?=$LANG['Phone']?></b></td>
                            <td><?=$profile['phone'].' &nbsp;&nbsp;'.$p_very?></td>        	
                        </tr>
                        <tr class="">
                            <td><b><?=$LANG['Address']?></b></td>
                            <td><?=$profile['address']?></td>
                        </tr>
                        <tr class="">
                            <td><b><?=$LANG['City']?></b></td>
                            <td><?=$profile['city']?></td>
                        </tr>
                        <tr class="">
                            <td><b><?=$LANG['State']?></b></td>
                            <td><?=$profile['state']?></td>
                        </tr>
                        <tr class="">
                            <td><b><?=$LANG['Country']?></b></td>
                            <td><?=countryName($profile['country_id'])?></td>
                        </tr>
                    </tbody>
                </table>
            </div>
         </div> 
         
</div>
 
 <div id="add_new" 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['Update Information']?> <span class="right"><a href="#" class="red-text" onclick="$('#add_contact')[0].reset();$('#add_new').hide('slow');"><i class="fa fa-times"></i></a></span></h5>
            
             <div class="card ">
                 <form action="profile?v=<?=$profile['id']?>" method="post" id="add_contact"  onSubmit="return false;">
                 <div class="card-content">
                    <div class="row">
                      <div class="col s12">
                          <ul class="tabs tab-demo z-depth-1" style="width: 100%;">
                             <li class="tab col s6"><a id="sc5" href="#accd" class=""><?=$LANG['Account Details']?></a></li>
                             <li id="bulk_cont" class="tab col s6"><a href="#paaw"><?=$LANG['Login Details']?></a></li>
                          </ul>
                      </div>
                      <div id="accd">
                         <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['Profile Photo']?></span>
                                        <input id="files" type="file" name="files" accept="image/*">
                                    </div>
                                    <div class="file-path-wrapper">
                                        <input class="file-path validate" type="text" placeholder="<?=$LANG['Upload Image']?>">
                                        <input type="hidden" id="photo" value="<?=$profile['photo']?>">
                                    </div>
                                </div> 
							 </div>	
                        <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="fname" type="text" required class="validate"  value="<?=$profile['first_name']?>">
                                   <label for="fname"><?=$LANG['First Name']?></label>
                             </div>
                       	</div>
                         <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="lname" type="text" required class="validate"  value="<?=$profile['last_name']?>">
                                   <label for="lname"><?=$LANG['Last Name']?></label>
                             </div>
                       	</div>
                        <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="phone" type="text" class="validate" required value="<?=$profile['phone']?>">
                                   <label for="phone"><?=$LANG['Phone']?></label>
                             </div>
                       	</div>
                         <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="default_sender_ID" type="text" class="validate" required value="<?=$profile['default_sender_ID']?>">
                                   <label for="default_sender_ID"><?=$LANG['Default Sender ID']?></label>
                             </div>
                       	</div>
                        
                        <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="address" type="text" class="validate" required value="<?=$profile['address']?>">
                                   <label for="address"><?=$LANG['Address']?></label>
                             </div>
                       	</div>
                        <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="city" type="text" class="validate" required value="<?=$profile['city']?>">
                                   <label for="city"><?=$LANG['City']?></label>
                             </div>
                       	</div>
                        <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="state" type="text" class="validate" required value="<?=$profile['state']?>">
                                   <label for="state"><?=$LANG['State']?></label>
                             </div>
                       	</div>
                         <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <select id="country" required class="js-states browser-default"  style="width: 100%" >
                                        <?=getCountryList($profile['country_id']) ?>                            
                                   </select>
                                   <label class="active"><?=$LANG['Country']?></label>
                             </div>
                         </div>
                          <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <select id="currency" required class="js-states browser-default"  style="width: 100%" >
                                        <?=getCurrencyList($profile['currency_id']) ?>                            
                                   </select>
                                   <label class="active"><?=$LANG['Currency']?></label>
                             </div>
                         </div>
                         
                      </div>
                      
                      <div id="paaw">
                      	<div class="row no-m-t no-m-b">
                            <div class="col s12 m12 l12">
                                <div class="card blue lighten-5 ">
                                    <div class="card-content black-text"><?=$LANG['prof_paa_tip']?><br>
                                </div>
                            </div>
                         </div>	
                          <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="email" type="email" required readonly class="validate" value="<?=$profile['email']?>">
                                   <label for="email"><?=$LANG['Email']?></label>
                             </div>
                       	  </div>
                          <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="password" type="text" class="validate"  value="">
                                   <label for="password"><?=$LANG['New Passowrd']?></label>
                             </div>
                       	  </div>
                      </div>  
                    </div>  
                 </div>   
                 <div class="card-action">
                     <input id="customer_id" value="<?=$profile['id']?>" type="hidden" >
                     <input id="role_id" value="<?=$profile['role_id']?>" type="hidden" >
                     <button id="cus-button" class="btn green darken-4" type="submit"><?=$LANG['Save Profile']?> </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>
                             <span id="upload-spin" class="btn-flat" style="display: none;"><i class="fa fa-spinner fa-spin"></i> <strong><?=$LANG['Uploading your files']?> <span id="progress-wrp">0%</span>...</strong></span>
                     <a class="btn waves-effect waves-light red" href="#" onclick="$('#add_contact')[0].reset();$('#add_new').hide('slow');"><?=$LANG['Cancel']?></a>
                 </div>
                 </form>
             </div>
           </div>
       <div class="col s1 m2 l3"> </div>
	 </div>
 </div>          
 </div>
