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

$mgs = ucwords(remove_junk(escape($_POST['sms'])));



$sql="SELECT * FROM tbl_customer";
$result = mysqli_query($con,$result);

    
    
//SMS Code Start
$sql="SELECT * FROM tbl_sms WHERE id=1 LIMIT 1";
$smsde = mysqli_query($con,$sql);
$sms=mysqli_fetch_array($smsde);

if($sms['status']==1){
$lang=$sms['language'];
$appkey=$sms['appkey'];
$senderid=$sms['senderid'];
$type=$sms['type'];
$url=$sms['url'];

while ($row=mysqli_fetch_array($result)){
$cmobile=$row['cmobile'];
if($lang==1){
    $url = "$url";
    $data = [
      "api_key" => "$appkey",
      "type" => "$type",
      "contacts" => "$cmobile",
      "senderid" => "$senderid",
      "msg" => "$mgs",
    ];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $response = curl_exec($ch);
    curl_close($ch);
}else{
  $url = "$url";
  $data = [
    "api_key" => "$appkey",
    "type" => "$type",
    "contacts" => "$cmobile",
    "senderid" => "$senderid",
    "msg" => "$mgs",
  ];
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  $response = curl_exec($ch);
  curl_close($ch);

}

}

}

//SMS Code End




    if($efid>0){ 
    write_activity($aid,'SSM','SMS Successfully Send','Sended');
    save_msg('s','SMS Successfully Send!');    
    }else{
    save_msg('w','Data Fail to Send!');    
    }
    echo "<script>window.location='main_customersms.php'</script>";  
 
}
?>
<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">
    
<div class="row">
<div class="col-md-9">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">Send SMS</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>    
<form action="main_customersms.php" onsubmit="return validate()" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<div class="col-md-12 popup_details_div">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="col-md-12">
   
<div class="row">
<div class="col-md-12"> 
<div class="form-group">    
<label>SMS</label>
<textarea class="form-control" name="sms" id="sms" maxlength="200" rows="4" placeholder="SMS" required></textarea>    
</div>
</div>        
</div>   
</div>    
</div>    
<div class="col-md-1"></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="submit" name="send_sms" onsubmit="send_sms('sm_1')" id="submit" class="btn btn-flat bg-purple btn-sm" value="Send"/> <a href="main_cutomerlist.php" class="btn btn-flat bg-gray  ">Close</a>
</div> 
</div>     
</form>    
</div>
</div>
</div>
<div class="col-md-3">
<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,'SSM','A');}else{echo read_activity($aid,'SSM','U');}?>
</div>
</div>
</div>
</div>
</div>
</div>

<?php include('../layout/quick.php');?>     
</section>
<!-- /.main content -->    
</div>

<?php 
include('../layout/footer.php');
?>
<!-- page script -->
<script type="text/javascript">
$(document).ready(function () {
var name = new LiveValidation('name');
name.add(Validate.Presence);  
var cnumber = new LiveValidation('cnumber');
cnumber.add(Validate.Presence);
var address = new LiveValidation('address');
address.add(Validate.Presence);
var climit = new LiveValidation('climit');
climit.add(Validate.Presence);     
climit.add(Validate.Numericality, { minimum: 0, onlyInteger: true });
var rank = new LiveValidation('rank');
rank.add(Validate.Presence);     
rank.add(Validate.Numericality, { minimum: 0, onlyInteger: true });    
});

function send_sms(id) {
bootbox.confirm({
title: "Confirm",
message: "Are you sure to delete ?",
buttons: {
confirm: {
label: 'Yes',
className: 'btn-flat bg-purple'
},
cancel: {
label: 'Cancel',
className: 'btn-flat bg-gray'
}
},
callback: function (result) {
if (result == true) {
document.getElementById(id).submit();
}
}
});
}
    
function getAllSubgroup(id){
$.ajax({
url: 'axe_getsub.php',
type: 'post',
data: {zone : id},
success:function(data) {
$('#zid').html(data);
}
});
};    
</script>    
<!-- /page script -->
</html>