<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
include ('../inc/cartfunctions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
get_pagesecurity('26','creates','R');    
$_SESSION['cuPages']='main_indivisualcustomersms.php';   
$cuPage='main_indivisualcustomersms.php';    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];    
}else{
header('Location:../index.php');
exit;    
}
$mhead='client';
$menuh='Client';
$phead='indicsms';
$page='Indivisual Promotional SMS';
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
$dtnow = date("Y-m-d h:i:s", time());
?>

<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">

<div class="row">
<div class="col-md-8">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">Indivisual Promotional SMS</h3>
</div>
<div class="box-body">
<div class="col-md-12 addpayment">
<div class="row">    
<center>
<h3 class="page-title">Indivisual Promotional SMS</h3>
</center>
</div>  
<div class="row">
<div class="col-md-8">
<div class="form-group" >
<label>Sender </label></label>
<div class="input-group">
<select class="form-control select2" name="did" id="did">
<option value="">-Select-</option>
<optgroup label="Supplier">
<?php
$sql="SELECT * FROM tbl_supplier ORDER BY id ASC";    
$querys=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rows=mysqli_fetch_array($querys)){
?>
<option value="<?php echo 'SU_'.$rows['id'];?>"><?php echo $rows['code'].' - '.$rows['name'].' - '.$rows['cnumber'];?></option>
<?php } ?>
</optgroup>
<optgroup label="Customer">
<?php
$sql="SELECT * FROM tbl_customer ORDER BY id ASC";    
$querys=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rows=mysqli_fetch_array($querys)){
?>
<option value="<?php echo 'CU_'.$rows['id'];?>"><?php echo $rows['code'].' - '.$rows['name'].' - '.$rows['cnumber'];?></option>
<?php } ?>
</optgroup>
<optgroup label="Employee">
<?php
$sql="SELECT * FROM tbl_employe ORDER BY id ASC";    
$querys=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rows=mysqli_fetch_array($querys)){
?>
<option value="<?php echo 'EM_'.$rows['id'];?>"><?php echo $rows['code'].' - '.$rows['name'];?></option>
<?php } ?>
</optgroup>
</select>
<span class="input-group-addon"><a href=""><span class="fa fa-plus"></span></a></span>     
</div>   
</div>
</div>

<div class="col-md-2">
<div class="form-group">
<label>&nbsp;</label>    
<input type="button" id="addpay" class="btn btn-flat bg-red" value="Add"/>    
</div>
</div>    
</div>
<div class="row">
<div class="col-md-12">
<table class="table table-bordered table-striped">
<thead>    
<th style="width:40px; text-align:center">SN</th>
<th>Customer</th>
<th>Number</th>    
<th style="width:40px; text-align:center"><a class="empty" style="cursor: pointer;"><i class="fa fa-trash"></i></a></th>    
</thead>
<tbody id="itemdata">

</tbody>
<tfoot id="itemfoot">

</tfoot>    
</table> 
</div>    
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Message</label>
<textarea class="form-control" name="note" id="note" maxlength="250" rows="3" placeholder="e.g. Note"></textarea>
<input type="hidden" name="save_payment" readonly="">
</div>    
</div>   
</div>    
    
</div>    
    
<div class="clearfix" ></div>
<div class="col-md-12 nopadding widgets_area"></div>    
<div class="row"style="margin-top: 15px" >
<div class="col-md-8"></div>
<div class="col-md-4 text-right" >
<input type="button" id="save_payment" class="btn btn-flat bg-purple btn-sm" value="Send">    
 <a href="home.php" class="btn btn-flat bg-gray  ">Close</a>
</div> 
</div>     
</div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-12">
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">History </h3>
</div>
<!-- /.box-header -->
<div class="box-body" >
<?php if($_SESSION['access']=='1'){echo read_activity($aid,'SMS','A');}else{echo read_activity($aid,'SMS','U');}?>
</div>
</div>
</div>
</div>
</div>
</div>

<?php include('../layout/quick.php');?>    
</section>
<!-- /.main content -->   
<?php include('../layout/rside.php'); ?>
<div id="invdata" style="display: none;"></div>    
</div>

<?php 
include('../layout/footer.php');
?>
<!-- page script -->
<script type="text/javascript">
$(document).ready(function (){ 
var note = new LiveValidation('note');
note.add(Validate.Presence);
});
    
    
ReadData();
function ReadData(){
$.ajax({
url: "main_incussmsview.php",
method: "POST",
data:{ 
body:1
},
success: function(data){
$('#itemdata').html(data);
}
})

$.ajax({
url: "main_incussmsview.php",
method: "POST",
data:{ 
foot:1
},
success: function(data){
$('#itemfoot').html(data);
}
})    
};    

function ReadFoot(){
$.ajax({
url: "main_incussmsview.php",
method: "POST",
data:{ 
foot:1
},
success: function(data){
$('#itemfoot').html(data);
}
})	
}
    
$(document).on('click', '#addpay', function(e) {
sdid = $('#did').val(); 
toastr.options = {'positionClass': 'toast-top-center'};

if(sdid == '-Select-' || sdid == ''){
toastr.info('Please Select Sender!');
return;
};   

edid = sdid.split("_");
dty=edid[0];
did=edid[1];


$.ajax({
url: 'main_incussmscart.php',
type: 'post',
data: {getsms:1,did:did,dty:dty},
success:function(data) {  
$("#did").val("").trigger("change");
ReadData();
}
});    
    
e.preventDefault();     
});
    
    


$(document).on('click','.empty',function() {
$.ajax({
url: 'main_incussmscart.php',
method: "POST",
data:{ 
smsdata: 1
},
success: function(data){
ReadData();    
}
});    
});    

$(document).on('click', '.remove', function () {
var id = $(this).attr('id');
$.ajax({
url: 'main_incussmscart.php',
method: "POST",
data:{ 
smsremove: id
},
success: function(data){
ReadData();
}
});    
});    

$(document).on('click','#payreset',function() {
$.ajax({
url: 'main_incussmscart.php',
method: "POST",
data:{ 
smsclear: 1
},
success: function(data){
$("#note").val("");   
ReadData();    
}
});    
});

   
    


$(document).on('click', '#save_payment', function() {
var pay_data = $('.addpayment input, .addpayment select, .addpayment textarea');    
toastr.options = {'positionClass': 'toast-top-center'};
    
$.ajax({
url: "main_incussmscart.php",
data: pay_data,
type: 'post',
dataType: 'json',    
success: function(data){
if(data.status === "success"){   
$("#note").val("");    
ReadData();    
toastr.success(data.message);    
}else if(data.status === "info"){
toastr.info(data.message);    
}else{
toastr.error(data.message);    
}         
}
})    
});
   
    
</script>    
<!-- /page script -->
</html>    