<?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','Customers');
if(userRole()>2 && userRole() != 11) {
	header('location: index.php');	
}
hasModulePermission('view customer');
$today = date('Y-m-d'); $time = strtotime($today.'-1 months'); $lastMonth = date("Y-m", $time); $time = strtotime($today.'-1 years'); $lastYear = date("Y", $time);
if(isset($_REQUEST['v'])&& $_REQUEST['v']>0) {	
	$did = mysqli_real_escape_string($server,$_REQUEST['v']);	
	$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) {
		if(userRole()>2 && $profile['account_manager'] != getUser()) {
			header('location: index.php');	
		}
		$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';
		
		$customer = '<a href="acustomer?v='.$profile['reseller'].'">'.userData($profile['reseller'],'first_name').' '.userData($profile['reseller'],'last_name').'</a>';
		if($profile['reseller']==0) $customer = 'Administrator';
	} else {
		header('location: acustomer');	
	}
	
	//suspende customer
	 if(isset($_REQUEST['sus'])) {
		 if(DEMO_MODE) {
			$_SESSION['message'] = $LANG['This operation can not be performed on Demo Mode!'];
			header('location: acustomer?err=1&v='.$did); exit;
		}
		mysqli_query($server,"UPDATE `users` SET `status` = '0' WHERE id = '$did'") or die(mysqli_error($server));
		logEvent($userID,'Suspended customer ID '.$did.'');
		$_SESSION['message'] = $LANG['The selected account has been successfully suspended'];
		header('location: acustomer?err=0&v='.$did);
	  }	
	  if(isset($_REQUEST['drt'])) {
			$tdelete = mysqli_real_escape_string($server,$_REQUEST['drt']);
			$did = mysqli_real_escape_string($server,$_REQUEST['v']);
			mysqli_query($server,"DELETE FROM `routes` WHERE id = '$tdelete'") or die(mysqli_error($server));
			$_SESSION['message'] = $LANG['The selected routing rule has been deleted'];
			header('location: acustomer?err=0&v='.$did);
  	  }	
	  //activate customer
	 if(isset($_REQUEST['act'])) {
		 if(DEMO_MODE) {
			$_SESSION['message'] = $LANG['This operation can not be performed on Demo Mode!'];
			header('location: acustomer?err=1&v='.$did); exit;
		}
		mysqli_query($server,"UPDATE `users` SET `status` = '1' WHERE id = '$did'") or die(mysqli_error($server));
		logEvent($userID,'Re-activated customer ID '.$did.'');
		$_SESSION['message'] = $LANG['The selected account has been successfully re-activated'];
		header('location: acustomer?err=0&v='.$did);
	  }	
	
	if(isset($_REQUEST['rt'])) {
		$tdelete = mysqli_real_escape_string($server,$_REQUEST['rt']);
		mysqli_query($server,"DELETE FROM `rates` WHERE id = '$tdelete'") or die(mysqli_error($server));
		logEvent($userID,'removed a custom rate for customer ID '.$did.'');
		$_SESSION['message'] = $LANG['The selected custom rate has been deleted'];
		header('location: acustomer?err=0&v='.$did);
	 }	
	  if(isset($_GET['login'])) {
		  hasModulePermission('login customer');
		  	logEvent($userID,'Logged into customer ID '.$did.' account');
			$_SESSION['manageUser'] =   $did;
			header('location: index.php');
			exit;
	  }
$billingModel = checkBillingModel($profile['id']);
if($billingModel == 'unit') { }

?>

  <div class="row">
     <div class="col s12 m12 l12"><h5><?=$LANG['Managing']?> <?=ucfirst($profile['first_name'].' '.$profile['last_name'])?>'s <?=$LANG['Account']?></h5> <a class="btn waves-effect waves-light light-blue darken-4 right" href="acustomer"><?=$LANG['Back to Customers']?></a></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;"><?=$billingModel=='unit'?'':userCurrencySymbol($profile['id'])?><span class="counter" style="color: white;"><?=number_format(userWalletBalance($profile['id']),userCurrencyZero($profile['id']))?></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;"><?=$billingModel=='unit'?'':userCurrencySymbol($profile['id'])?><span class="counter" style="color: white;"><?=number_format(userLastRecharge($profile['id']),userCurrencyZero($profile['id']))?></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;"><?=$billingModel=='unit'?$LANG['Total Units Recharged']:$LANG['Total Credit Recharged']?></span>
                 <span class="stats-counter" style="color: white;"><?=$billingModel=='unit'?'':userCurrencySymbol($profile['id'])?><span class="counter" style="color: white;"><?=number_format(userAllRecharge($profile['id']),userCurrencyZero($profile['id']))?></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;"><?=$billingModel=='unit'?$LANG['Total Units Used']:$LANG['Total Credits Used']?></span>
                 <span class="stats-counter" style="color: white;"><?=$billingModel=='unit'?'':userCurrencySymbol($profile['id'])?><span class="counter" style="color: white;"><?=number_format(creditUsed($profile['id'])+(-userCreditShared($profile['id'])),userCurrencyZero($profile['id']))?></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['Owner']?></b></td>
                            <td><?=$customer?></td>
                        </tr>
                        <tr class="">
                            <td><b><?=$LANG['Account Manager']?></b></td>
                            <td><?=$profile['account_manager']<1?$LANG['Not Assigned']:userData($profile['account_manager'],'first_name').' '.userData($profile['account_manager'],'last_name')?></td>
                        </tr>
                        <tr class="">
                            <td><b><?=$LANG['Billing Model']?></b></td>
                            <td><?=!empty($profile['billingModel'])?ucfirst($profile['billingModel']):'Credit'?></td>
                        </tr>
                        <tr class="">
                            <td><b><?=$LANG['Birthday']?></b></td>
                            <td><?=!checkIsAValidDate($profile['birthday'])?$LANG['Not Set']:date('F j',strtotime($profile['birthday']))?></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');?>
                        <tr class="">
                        	<td><b><?=$LANG['Total SMS Sent']?></b></td>
                            <td><?=number_format(countAllCustomerSMS($from,$to,$profile['id']))?> <?=$LANG['Message(s)']?></td>
                        </tr>
                    </tbody>
                </table>
            </div>
         </div> 
         
          <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 class="card card-white">   
            <div class="card-content">
            	 <div class="card-title"><i class="material-icons">widgets</i> <?=$LANG['Other Information']?></div>
            	<table class="highlight responsive2-table">
                	<tbody>
                    <?php 
					$sql="SELECT * FROM customfields WHERE customer_id = '0' AND enabled = '1' ORDER BY id DESC";
					$result = mysqli_query($server, $sql);
					while($row3 = mysqli_fetch_assoc($result)){ ?>
                    	<tr class="">
                			<td><b><?=$row3['name']?></b></td>
                            <td><?=customFieldValue($row3['id'],$profile['id'])?></td>        	
                        </tr>
                    <?php } ?>    
                    </tbody>
                </table>
            </div>
         </div> 
         
     </div>           

    <div class="col s12 m6 l7">
    	<div class="row">
        <?php if(userRole()<3) {?>
    	<a class='waves-effect waves-light btn green accent-4 white-text' onclick="addCredit();" href='#'><i class="fa fa-money"></i> <?=$LANG['Add Credits']?></a> 
        <?php } ?>
        <a class='dropdown-button btn light-blue darken-4' href='#' data-activates='messa' data-beloworigin='true' data-constrainwidth='false'><i class="fa fa-envelope"></i> <?=$LANG['Message']?></a> 
        <ul id='messa' class='dropdown-content'>
         <?php if(userRole()<3) {?>   <li><a href="acompose?to=<?=$profile['phone']?>"> <i class="fa fa-mobile"></i> <?=$LANG['Send SMS']?></a></li><?php } ?>
            <li><a href="sendemail?e=<?=$profile['id']?>"> <i class="fa fa-envelope"></i> <?=$LANG['Send Email']?></a></li>
        </ul>
                
        <a class='waves-effect waves-light btn cyan darken-1 white-text' target="_blank" href='rcustomer?v=<?=$profile['id']?>&login'><i class="fa fa-user"></i> <?=$LANG['Login']?></a> 
        <?php if(userRole()<3) {?>
			<?php if($profile['status']==1) { ?>
            <a class='waves-effect waves-light btn orange darken-4 white-text' href='acustomer?v=<?=$profile['id']?>&sus'><i class="fa fa-ban"></i> <?=$LANG['Suspend']?></a>
            <?php } else { ?>
            <a class='waves-effect waves-light btn green darken-4 white-text' href='acustomer?v=<?=$profile['id']?>&act'><i class="fa fa-check"></i> <?=$LANG['Activate']?></a>
            <?php } ?>
        <?php } ?>
        </div>
            <div class="card invoices-card">
                 <div class="card-content">
                      <span class="card-title"><i class="fa fa-list"></i><?=$LANG['Recent Traffic']?> &nbsp;&nbsp;
                      <a class="hoverable" href="asent?customer_id=<?=$profile['id']?>"><?=$LANG['View All']?></a>
                      </span>
                   <?php
                    $query="SELECT * FROM sentmessages WHERE customer_id = '$profile[id]' 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['This customer has 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['Status']?></th>
                                <th data-field="credits"><?=$LANG['Credits']?></th>
                                <th data-field="act"></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']?>"><?=ucfirst($rows['status'])?></a></td>
                               <td><?=$billingModel=='unit'?'':userCurrencySymbol($profile['id'])?><?=number_format(messageCost($rows['id']),userCurrencyZero($profile['id']))?></td>
                                <td><a class="hoverable" href="asent?view=<?=$rows['id']?>"><?=$LANG['Details']?></a></td>
                             </tr>
                       <?php } ?>   
                          </tbody>
                      </table>
                      <?php } ?>
                 </div>
            </div>
            
            <div class="card invoices-card">
                 <div class="card-content">
                      <span class="card-title"><i class="fa fa-money"></i><?=$LANG['Recent Transactions']?> &nbsp;&nbsp;
                      <a class="hoverable" href="atransaction?customer_id=<?=$profile['id']?>"><?=$LANG['View All']?></a>
                      </span>
                   <?php
                     $query="SELECT * FROM transactions WHERE customer_id = '$profile[id]' 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['This customer has not done any transactions yet']?></h5>
                                </div>
                            </div>
                        </div>
                       </table> 
                      <?php } else { ?>  
                      <table class="responsive-table bordered">
                          <thead>
                            <tr>
                                <th data-field="date"><?=$LANG['Date']?></th>
                                <th data-field="credit"><?=$LANG['Credits']?></th>
                                <th data-field="cost"><?=$LANG['Cost']?></th>
                                <th data-field="ref"><?=$LANG['Reference']?></th>
                                <th data-field="status"><?=$LANG['Status']?></th>
                             </tr>
                          </thead>
                          <tbody>
                          <?php
                        while ($rows = mysqli_fetch_assoc($result)) { 
						$link = '';
						if( ($rows['is_earned'] < 1) && ($rows['is_shared'] < 1) && ($rows['credits'] > 0) ) {
						$link = '<a class="hoverable" href="atransaction?view='.$rows['transaction_reference'].'"><i class="fa fa-eye"></i> '.$LANG['Invoice'].'</a>';	
						}
						?>
                             <tr>
                               	 <td><?=date('M j, Y',strtotime($rows['date']))?></td>
                                 <td><?=number_format($rows['credits'],userCurrencyZero($profile['id']))?></td>
                                 <td><?=userCurrencySymbol($profile['id']).number_format($rows['cost'],userCurrencyZero($profile['id']))?></td>
                                 <td><?=$rows['transaction_reference']?></td>
                                 <td><?=ucfirst($rows['status'])?></td>
                               <td><?=$link?></td>
                             </tr>
                       <?php } ?>   
                          </tbody>
                      </table>
                      <?php } ?>
                 </div>
            </div>
            
           <div class="card invoices-card">
                 <div class="card-content">
                      <span class="card-title"><i class="fa fa-cubes"></i><?=$LANG['Custom Rates']?></span>
                      <span class="card-options">
                      	<a class="btn waves-effect waves-light blue darken-4" href="#" onclick="addCusRate();"><i class="fa fa-plus-circle"></i> <?=$LANG['Add Rate']?></a> 
                      </span>
                   <?php
                    $query="SELECT * FROM rates WHERE customer_id = '$profile[id]' 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['No custom rate has been defined for this customer']?></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>
                             </tr>
                          </thead>
                          <?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'
						?>
                          <tbody>
                             <tr>
                               	 <td><?=strtoupper($rows['type'])?></td>
                                 <td><?=$country?> </td>
                                 <td><?=$operator?></td>
                                 <td><?=userCurrencySymbol($profile['id']).number_format(toUserCurrency($rows['rate'],$userID,$profile['id']),userCurrencyZero($profile['id']))?></td>
                               <td><a onclick="return confirm('<?=$LANG['delete_confirm']?>');" href="acustomer?v=<?=$profile['id']?>&rt=<?=$rows['id']?>"><?=$LANG['Delete']?></a></td>
                             </tr>
                          </tbody>
                       <?php } ?>   
                      </table>
                      <?php } ?>
                 </div>
            </div>
            
            <div class="card invoices-card">
                 <div class="card-content">
                      <span class="card-title"><i class="fa fa-database"></i><?=$LANG['Custom Route']?></span>
                      <span class="card-options">
                      	<a class="btn waves-effect waves-light blue darken-4" href="#" onclick="addCusRoute();"><i class="fa fa-plus-circle"></i> <?=$LANG['Add Custom Route']?></a> 
                      </span>
                   <?php
                    $query="SELECT * FROM routes WHERE customer_id = '$profile[id]' 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['No custom routes has been assigned to this customer']?></h5>
                                </div>
                            </div>
                        </div>
                       </table> 
                      <?php } else { ?>  
                      <table class="responsive-table bordered">
                          <thead>
                            <tr>
                                <th data-field="ref"><?=$LANG['Type']?></th>
                                <th data-field="status"><?=$LANG['Destination']?></th>
                                <th data-field="credit"><?=$LANG['Operator Prefix']?></th>
                                <th data-field="date"><?=$LANG['Gateway']?></th>
                                <th data-field="act"></th>
                             </tr>
                          </thead>
                          <?php
                        while ($rows = mysqli_fetch_assoc($result)) { 
						$link = '';
						$operator = $rows['operator_code'];
						$country = countryName(getCountryByCode($rows['country_code']));
						if($rows['customer_id'] < 1)	$customer = $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'
						?>
                          <tbody>
                             <tr>
                               	 <td><?=strtoupper($rows['type'])?></td>
                                 <td><?=$country?> </td>
                                 <td><?=$operator?></td>
                                 <td><?=smsGatewayData($rows['gateway_id'],'title')?></td>
                                  <td><a class="hoverable red-text" onclick="return confirm('<?=$LANG['delete_confirm']?>');" href="acustomer?v=<?=$profile['id']?>&drt=<?=$rows['id']?>"><?=$LANG['Delete']?></a></td>
                             </tr>
                          </tbody>
                       <?php } ?>   
                      </table>
                      <?php } ?>
                 </div>
            </div>
            
      </div>                         
         
</div>
<?php
$vars = array( "customer_id"=>$rows['id'] );
	$_SESSION['EventVals'] = $vars;
 global $hooks; $hooks->do_action('OnCiustomerView'); ?>
 
 <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"> <?php hasModulePermission('add customer');?>
             <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="acustomer?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="input-field col s12">
                               <select id="role_id" required class="validate">
                                    <option <?php if($profile['role_id']=='4') echo 'selected';?> value="4" ><?=$LANG['Customer']?></option>
                                    <option <?php if($profile['role_id']=='3') echo 'selected';?> value="3" ><?=$LANG['Reseller']?></option>
                               </select>
                               <label><?=$LANG['Account Type']?></label>
                         </div>
                       </div>
                       
                       <?php if($profile['role_id']=='4') { ?>
                       <div class="row no-m-t no-m-b">
                    	<div class="input-field col s12">
                            <select id="reseller_id" class="js-states browser-default"  style="width: 100%">
                                <option value="0" disabled selected><?=$LANG['Select Reseller']?></option>
                                <option <?php if($profile['reseller']==0) { echo 'selected';}?> value="0">Administrator (Root)</option>
                                <?php $query="SELECT * FROM users WHERE reseller = '0' AND role_id = '3'";
								$result = mysqli_query($server,$query) or die(mysqli_error($server));
								$selected = '';
                                while ($rws = mysqli_fetch_assoc($result)) { 
									if($profile['reseller']==$rws['id']) { $selected = 'selected';}
                                    echo '<option '.$selected.' value="'.$rws['id'].'">'.$rws['first_name'].' '.$rws['last_name'].' ('.$rws['email'].')</option>';
									$selected = '';
                                }
                               ?> 
                            </select>
                            <label class="active"><?=$LANG['Assign Reseller']?></label>
                        </div>
                     </div>   
                       <?php } else {?>
                       	<input id="reseller_id" value="<?=$profile['reseller']?>" type="hidden" >
                       <?php } ?>
                        <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="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">
                                   <input id="birthday" type="date" class="validate" value="<?=$profile['birthday']?>">
                                   <label class="active" for="birthday"><?=$LANG['Date of Birth']?> </label>
                             </div>
                       	</div>
                        <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <select id="account_manager" class="js-states browser-default" style="width: 100%" >
                                   		<option value="0" <?php if($profile['account_manager']=='1') echo 'selected';?>><?=$LANG['Not Assigned']?></option>
                                        <?=getManagerList($profile['account_manager']) ?>                            
                                   </select>
                                   <label class="active"><?=$LANG['Account Manager']?></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">
                                   <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 class="row no-m-t no-m-b">
                            <div class="input-field col s12">
                                <select id="language_id" required class="js-states browser-default"  style="width: 100%">
                                    <option value="0" disabled selected><?=$LANG['Select Language']?></option>
                                    <?php $query="SELECT * FROM language WHERE enabled = '1'";
                                    $result = mysqli_query($server,$query);
                                    $selected = '';
                                    while ($rws = mysqli_fetch_assoc($result)) { 
                                        if($profile['language_id']==$rws['alias']) { $selected = 'selected';}
                                        echo '<option '.$selected.' value="'.$rws['alias'].'">'.$rws['title'].'</option>';
                                        $selected = '';
                                    }
                                   ?> 
                                </select>
                                <label class="active"><?=$LANG['Default Language']?></label>
                            </div>
                         </div>   
                         <div class="row no-m-t no-m-b">
                         <div class="input-field col s12">
                               <select id="no_tat" required class="validate">
                                    <option value="1" <?php if($profile['no_tax']=='1') echo 'selected';?>><?=$LANG['Yes']?></option>
                                    <option value="0" <?php if($profile['no_tax']=='0') echo 'selected';?>><?=$LANG['No']?></option>
                               </select>
                               <label><?=$LANG['Exempt from Taxes']?></label>
                         </div>
                       </div>
                       
                       <div class="row no-m-t no-m-b">
                            <div class="input-field col s12">
                                  <select id="billingModel" required class="validate">
                                       <option value="credit"><?=$LANG['Credit Model']?></option>
                                       <option value="unit" <?php if($profile['billingModel']=='unit') echo 'selected';?>><?=$LANG['Unit Model']?></option>
                                  </select>
                                  <label><?=$LANG['Custom Billing Model']?></label>
                            </div>
                         </div>
                         <!-- advancedUnitPricing -->
                         <div class="row no-m-t no-m-b" style="display:none" id="show_advancedUnitPricing">
                           <h6 class="m-t-md red-text darken-4"><b><?=$LANG['unit_config_tip2']?></b></h6>
                           <div class="input-field col s12">
                                 <textarea id="advancedUnitPricing" class="materialize-textarea"><?=$profile['advancedUnitPricing']?></textarea>
                                 <label for="advancedUnitPricing"><?=$LANG['Unit Pricing']?></label>
                           </div>
                        </div>
                             
                       <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="min_order" type="number" class="validate" required value="<?=round($profile['min_order']*userExchangeRate($userID),2)?>">
                                   <label for="min_order"><?=$LANG['Set Minimum Order']?></label>
                             </div>
                       	</div>
                        
                     <?=loadCustomFields(0,$profile['id'],0,'<div class="row no-m-t no-m-b"><div class="input-field col s12">',' </div></div>','validate','la1')?>   
                      </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['cus_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 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" >
                     <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>
                     <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>
 
 <!--add rates -->
  <div id="add_new2" 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"> <?php hasModulePermission('add customer');?>
             <h5><?=$LANG['Add Rate']?> <span class="right"><a href="#" class="red-text" onclick="$('#add_rate')[0].reset();$('#add_new2').hide('slow');"><i class="fa fa-times"></i></a></span></h5>
            
             <div class="card ">
                 <div class="card-content">
                    <form action="acustomer?v=<?=$profile['id']?>" method="post" id="add_rate" onSubmit="return false;">
                    <div class="row">
                       <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>   
                       <div class="card-action">
                            <input id="customer_id2" value="<?=$profile['id']?>" type="hidden" >
                            <input id="gateway" value="0" type="hidden" >
                            <button id="rate-button" class="btn green darken-4" type="submit"><?=$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>
                            <a class="btn waves-effect waves-light red" href="#" onclick="$('#add_rate')[0].reset();$('#add_new2').hide('slow');"><?=$LANG['Cancel']?></a>
                       </div>
                    </form>
                 </div>
             </div>
           </div>
       <div class="col s1 m2 l3"> </div>
	 </div>
 </div>          


 <!--add route -->
  <div id="add_new2R" 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"> <?php hasModulePermission('add customer');?>
             <h5><?=$LANG['Add Custom Route']?> <span class="right"><a href="#" class="red-text" onclick="$('#add_route')[0].reset();$('#add_new2R').hide('slow');"><i class="fa fa-times"></i></a></span></h5>
            
             <div class="card ">
                 <div class="card-content">
                    <form action="acustomer?v=<?=$profile['id']?>" method="post" id="add_route" onSubmit="return false;">
                    <div class="row">
                       <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                 <select id="country_code2" 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_code2" type="number" class="validate" value="" placeholder="Eg. 803 for MTN Nigeria, 82 for Vodaconn South-Africa" >
                                   <label for="operator_code2"><?=$LANG['Operator Prefix']?></label>
                             </div>
                       	</div>
                        <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <select id="gateway_id" required class="js-states browser-default"  style="width: 100%" >
                                        <option value="" disabled selected><?=$LANG['Assign a gateway']?></option>
                                        <?php $query="SELECT * FROM sms_gateways ";
                                        $result = mysqli_query($server,$query) or die(mysqli_error($server));
                                        while ($rows = mysqli_fetch_assoc($result)) { 
                                            echo '<option value="'.$rows['id'].'">'.$rows['title'].' ('.strtoupper($rows['type']).') </option>';
                                        }
                                       ?> 
                                    </select>
                                    <label class="active"><?=$LANG['Gateway']?></label>
                             </div>
                       	</div>
                    </div>   
                       <div class="card-action">
                       		<input type="hidden" id="group_id" value="1" >
                            <input id="customer_id2R" value="<?=$profile['id']?>" type="hidden" >
                            <button id="route-button" class="btn green darken-4" type="submit"><?=$LANG['Add Rule']?> </button>
                            <span id="route-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_route')[0].reset();$('#add_new2R').hide('slow');"><?=$LANG['Cancel']?></a>
                       </div>
                    </form>
                 </div>
             </div>
           </div>
       <div class="col s1 m2 l3"> </div>
	 </div>
 </div>          

 
 <!--add credit -->
  <div id="add_new3" 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"> <?php hasModulePermission('credit customer');?>
             <h5><?=$LANG['Add Credits To']?> <?=$profile['first_name']?><span class="right"><a href="#" class="red-text" onclick="$('#add_rate2')[0].reset();$('#add_new3').hide('slow');"><i class="fa fa-times"></i></a></span></h5>
            
             <div class="card ">
                 <div class="card-content">
                    <form action="acustomer?v=<?=$profile['id']?>" method="post" id="add_rate2" onSubmit="return false;">
                        <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="credits" type="text" class="validate" required value="">
                                   <label for="credits"><?=$LANG['Credits']?> (<?=userCurrencyCode($profile['id'])?>)</label>
                             </div>
                       	</div>
                        <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="passworda" type="password" class="validate" required value="">
                                   <label for="passworda"><?=$LANG['Your Password']?> </label>
                             </div>
                       	</div>
                       <div class="card-action">
                            <input id="customer_id3" value="<?=$profile['id']?>" type="hidden" >
                            <button id="creditcus-button" class="btn green darken-4" type="submit"><?=$LANG['Add Credits']?> </button>
                            <span id="creditcus-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_rate2')[0].reset();$('#add_new3').hide('slow');"><?=$LANG['Cancel']?></a>
                       </div>
                    </form>
                 </div>
             </div>
           </div>
       <div class="col s1 m2 l3"> </div>
	 </div>
 </div>          

       
<?php	
} else {
if(isset($_POST['bulk'])) { 
  $userID = getUser();
  if($_POST['action']=='delete') {
	  hasModulePermission('delete customer');
	if(userRole()<3) {  
		if(DEMO_MODE) {
			$_SESSION['message'] = $LANG['This operation can not be performed on Demo Mode!'];
			header('location: acustomer?err=1');
		} else {
			foreach($_POST['bulk'] as $inbid) { 
				mysqli_query($server,"DELETE FROM `users` WHERE `id` = '$inbid' AND 1") or die(mysqli_error($server));
				logEvent($userID,'Deleted customer ID '.$inbid.'.');
			}	
			$_SESSION['message'] = $LANG['The selected accounts(s) has been deleted'];
			header('location: acustomer?err=0');
		}
	}
  } elseif($_POST['action']=='suspend') {
	  if(DEMO_MODE) {
		$_SESSION['message'] = $LANG['This operation can not be performed on Demo Mode!'];
		header('location: acustomer?err=1');
	} else {
		foreach($_POST['bulk'] as $inbid) { 
			mysqli_query($server,"UPDATE users SET `status` = '0' WHERE `id` = '$inbid' AND 1") or die(mysqli_error($server));
			logEvent($userID,'Suspended customer ID '.$inbid.'.');
		}	
		$_SESSION['message'] = $LANG['The selected account(s) has been suspended'];
		header('location: acustomer?err=0');
	}
  } elseif($_POST['action']=='activate') {
	foreach($_POST['bulk'] as $inbid) { 
		mysqli_query($server,"UPDATE users SET `status` = '1' WHERE `id` = '$inbid' AND 1") or die(mysqli_error($server));
		logEvent($userID,'Activated customer ID '.$inbid.'.');
	}	
	$_SESSION['message'] = $LANG['The selected account(s) has been activated'];
	header('location: acustomer?err=0');
  } else {
	  header('location: acustomer');
  }
}
	//show list
	$added = '';	
	if(isset($_GET['sc'])) {
		$keywords = mysqli_real_escape_string($server,$_GET['sc']);
		$ser = explode(' ', $keywords);
		$clauses = array();
		foreach($ser as $look){
			$term = trim($look);   
			if (!empty($term)){
				 $clauses[] = "first_name LIKE '%$term%' OR last_name LIKE '%$term%'  OR email LIKE '%$term%' OR phone LIKE '%$term%' OR city LIKE '%$term%'  OR state LIKE '%$term%' ";
			} else {
				 $clauses[] = " id LIKE '%%' ";
			}
		}
		$added .= ' AND ('.implode(' OR ', $clauses).') ';		
	}
	if(isset($_GET['s'])) {
		if($_GET['s']=='res') {
			$added .= ' AND (role_id = 3) ';
		}
	} else {
		$added .= " order by id DESC ";	
	}

    $query="SELECT * FROM users WHERE role_id > 2 $added limit $pageLimit,$setLimit";
	$result = mysqli_query($server,$query) or die(mysqli_error($server));
	$x = mysqli_num_rows($result);
?>
<!-- Quick Navs ::::: You can customize this -->
 <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['acustomer_tip']?></div>
        </div>
    </div>
 </div>

<div class="row no-m-t no-m-b">
 	<div class="col s12 m12 l12">
        <div class="card card-transparent">
            <div class="card-content">
            	<div class="col s12 m5 l5">
                </div>
                <div class="col s12 m7 l7">
                  <div class="col s12 m12 l12">
                    <div class="row no-m-t no-m-b">
                     <form action="acustomer" method="get">
                     <div class="input-field col s12">
                        <i class="material-icons prefix">search</i>
                        <input type="text" name="sc" value="<?=@$_GET['sc']?>" placeholder="<?=$LANG['Search...']?>">
                     </div>
                     </form>  
                    </div>
                  </div> 
                </div>
            </div>
        </div>
    </div>
 </div>

<div class="row no-m-t no-m-b">
 	<div class="col s12 m12 l12">
        <div class="card card-transparent">
            <div class="card-content">
                    <a class="btn waves-effect waves-light light-green darken-4" href="#" onclick="addPB();"><?=$LANG['Create Customer']?></a> &nbsp;
                    <?php if(userRole()<3) {?>
                    <a class="btn waves-effect waves-light green darken-2" href="#" onclick="$('#add_new3').show('slow');"><?=$LANG['Import Customers']?></a>
                    &nbsp; 
                    <a class="btn waves-effect waves-light blue darken-4" href="acompose?cust" ><?=$LANG['SMS Customers']?></a>
                    &nbsp; 
                    <a class="btn waves-effect waves-light deep-purple darken-4" href="sendemail?e=0" ><?=$LANG['Email Customers']?></a>
                    <?php } ?>
                
            </div>
        </div>
    </div>
 </div>

<div class="row no-m-t no-m-b">
 	<div class="col s12 m12 l12">
         <div class="card card-white">   
            <div class="card-content">
            <div class="card-options">
            	<ul>
                </ul>    
                <ul id='bulka' class='dropdown-content'>
                        <li><a href="#" onclick="bulkaction('delete','inbox-form','<?=$LANG['delete_confirm']?>');"> <i class="fa fa-trash"></i> <?=$LANG['Delete']?></a></li>
                         <li><a href="#" onclick="bulkaction('suspend','inbox-form','<?=$LANG['suspend_confirm']?>');"> <i class="fa fa-times"></i> <?=$LANG['Suspend']?></a></li>
                         <li><a href="#" onclick="bulkaction('activate','inbox-form','<?=$LANG['activae_confirm']?>');"> <i class="fa fa-check"></i> <?=$LANG['Activate']?></a></li>
                </ul>                
            </div>
            <span class="card-title">
            <?php if(userRole()<3) {?><a class='dropdown-button btn light-blue darken-4' href='#' data-activates='bulka' data-beloworigin='true' data-constrainwidth='false'><?=$LANG['With Selected']?></a>
            <?php } ?></span>
       		<table class="highlight responsive-table">
            <?php if($x>0) { ?>
                <thead>
                	<tr>
                    	<th><input type="checkbox" class="filled-in" id="selectall" /><label for="selectall"></label></th>
                        <th data-field="id"><?=$LANG['ID']?></th>
                        <th data-field="date"><?=$LANG['First Name']?></th>
                        <th data-field="type"><?=$LANG['Last Name']?></th>
                        <th data-field="message"><?=$LANG['Email']?></th>
                        <th data-field="message"><?=$LANG['Owner']?></th>
                        <th data-field="date"><?=$LANG['Joined On']?></th>
                        <th data-field="date"><?=$LANG['Status']?></th>
                        <th data-field="act"></th>
                    </tr>
                 </thead>
              <?php } ?>   
                 <tbody>
                    <form action="acustomer" method="post" id="inbox-form">
                    	<input type="hidden" id="bulkaction" name="action" value=""/>
<?php $xf=0; while ($rows = mysqli_fetch_assoc($result)) { $xf+=1; $stats = ''; 
$type = 'Customer';
if($rows['role_id']==3) $type = 'Reseller';
$status = '<span class="green-text">'.$LANG['Active'].'</span';
if($rows['status']==0) $status = '<span class="red-text">'.$LANG['Suspended'].'</span';

$customer = '<a href="acustomer?v='.$rows['reseller'].'">'.userData($rows['reseller'],'first_name').' '.userData($rows['reseller'],'last_name').'</a>';
if($rows['reseller']==0) $customer = 'Administrator';
$vars = array( "customer_id"=>$rows['id'] );
	$_SESSION['EventVals'] = $vars;
?>
						<tr class="">
                             <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><?=$rows['id']?></td>
                             <td><?=$rows['first_name']?></td>
                             <td><?=$rows['last_name']?></td>
                             <td><?=$rows['email']?></td>
                             <td><?=$customer?></td>
                             <td><?=date('Y-m-d', strtotime($rows['date']))?></td>
                             <td><?=$status?></td>
                             <td><?php if(userRole()< 3 || (userRole()>2 && $rows['account_manager'] == getUser())) { ?> 
                             <a class="hoverable" href="acustomer?v=<?=$rows['id']?>"><i class="fa fa-eye"></i> <?=$LANG['Manage']?></a><?php } ?>
                             <?php global $hooks; $hooks->do_action('CustoerTableAction'); ?>
                             </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>
  </div>
 <div class="row">
 	<div class="col s12 m12 l12" style="margin-top: 5px;">
        <?php displayPagination($setLimit,$page,$query);  ?>
    </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"> <?php hasModulePermission('add customer');?>
             <h5><?=$LANG['Create Customer']?> <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="acustomer" 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="input-field col s12">
                               <select id="role_id" required class="validate">
                                    <option value="4" ><?=$LANG['Customer']?></option>
                                    <option value="3" ><?=$LANG['Reseller']?></option>
                               </select>
                               <label><?=$LANG['Account Type']?></label>
                         </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="">
                                   <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="">
                                   <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="">
                                   <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="address" type="text" class="validate" required value="">
                                   <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="">
                                   <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="">
                                   <label for="state"><?=$LANG['State']?></label>
                             </div>
                       	</div>
                        <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="birthday" type="date" class="validate" value="">
                                   <label class="active" for="birthday"><?=$LANG['Date of Birth']?></label>
                             </div>
                       	</div>
                        <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <select id="account_manager" class="js-states browser-default" style="width: 100%" >
                                   		<option value="0" ><?=$LANG['Not Assigned']?></option>
                                        <?=getManagerList() ?>                            
                                   </select>
                                   <label class="active"><?=$LANG['Account Manager']?></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="">
                                   <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">
                                   <select id="country" required class="js-states browser-default"  style="width: 100%" >
                                        <?=getCountryList(userData($userID,'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(userData($userID,'currency_id')) ?>                            
                                   </select>
                                   <label class="active"><?=$LANG['Currency']?></label>
                             </div>
                         </div>
                         <div class="row no-m-t no-m-b">
                         <div class="input-field col s12">
                               <select id="no_tat" required class="validate">
                                    <option value="1" ><?=$LANG['Yes']?></option>
                                    <option value="0" ><?=$LANG['No']?></option>
                               </select>
                               <label><?=$LANG['Exempt from Taxes']?></label>
                         </div>
                       </div>
                       <div class="row no-m-t no-m-b">
                            <div class="input-field col s12">
                                  <select id="billingModel" required class="validate">
                                       <option value="credit"><?=$LANG['Credit Model']?></option>
                                       <option value="unit" <?php if(getSetting('billingModel')=='unit') echo 'selected';?>><?=$LANG['Unit Model']?></option>
                                  </select>
                                  <label><?=$LANG['Custom Billing Model']?></label>
                            </div>
                         </div>
                         <!-- advancedUnitPricing -->
                         <div class="row no-m-t no-m-b" style="display:none" id="show_advancedUnitPricing">
                           <h6 class="m-t-md red-text darken-4"><b><?=$LANG['unit_config_tip2']?></b></h6>
                           <div class="input-field col s12">
                                 <textarea id="advancedUnitPricing" class="materialize-textarea"><?=getSetting('advancedUnitPricing')?></textarea>
                                 <label for="advancedUnitPricing"><?=$LANG['Unit Pricing']?></label>
                           </div>
                        </div>
                       <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="min_order" type="number" class="validate" required value="">
                                   <label for="min_order"><?=$LANG['Set Minimum Order']?></label>
                             </div>
                       	</div>
                        
					<?=loadCustomFields(0,0,0,'<div class="row no-m-t no-m-b"><div class="input-field col s12">',' </div></div>','validate','la1')?>
                      </div>
                      
                      <div id="paaw">
                          <div class="row no-m-t no-m-b">
                             <div class="input-field col s12">
                                   <input id="email" type="email" required class="validate" value="">
                                   <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['Passowrd']?></label>
                             </div>
                       	  </div>
                      </div>  

                    </div>  
                 </div>   
                 <div class="card-action">
                     <input id="customer_id" value="0" type="hidden" >
                     <button id="cus-button" class="btn green darken-4" type="submit"><?=$LANG['Save']?> </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>
                     <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>          

 
<!-- /Import customer -->
 <div id="add_new3" 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"> <?php hasModulePermission('add customer');?>
             <h5><?=$LANG['Import Customers']?> <span class="right"><a href="#" class="red-text" onclick="$('#add_csv')[0].reset();$('#add_new3').hide('slow');"><i class="fa fa-times"></i></a></span></h5>
             <div class="card ">
                 <div class="card-content">
                    <form action="acustomer" method="post" id="add_csv"  onSubmit="return false;">
                    <div class="row">
                      	<div class="row no-m-t no-m-b">
                            <div class="col s12 m12 l12">
                                <div class="card grey lighten-5 ">
                                    <div class="card-content black-text"><?=$LANG['upload_customer_tip']?><br>
                                    <a href="files/sample2.xls" class="btn cyan darken-4"><?=$LANG['download_sample']?></a></div>
                                </div>
                            </div>
                         </div>	
                         <div class="file-field input-field col s12">
                            <div class="btn light-blue darken-4">
                                <span><i class="fa fa-cloud-upload"></i></span>
                                <input id="files" type="file" name="files" accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
                            </div>
                            <div class="file-path-wrapper">
                                <input class="file-path validate" type="text" placeholder="<?=$LANG['Upload an Excel or CSV file']?>">
                                <input type="hidden" id="files_holder">
                           </div>
                         </div> 
                      </div>  
                       <div class="card-action">
                            <button id="imp-button" class="btn ight-blue darken-4" type="submit"><?=$LANG['Import Data']?> </button>
                            <span id="imp-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_csv')[0].reset();$('#add_new3').hide('slow');"><?=$LANG['Cancel']?></a>
                       </div>
                    </form>
                 </div>
             </div>
           </div>
       <div class="col s1 m2 l3"> </div>
	 </div>
 </div>          
<?php } ?> 
