<?php echo $this->load->view("common/header"); ?>
<!-- end: HEAD -->

<!-- start: CSS REQUIRED FOR THIS PAGE ONLY -->
<!--<link rel="stylesheet" type="text/css" href="<?php echo asset_url(); ?>plugins/select2/select2.css" />
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/DataTables/media/css/DT_bootstrap.css" />
<link href="<?php echo asset_url(); ?>plugins/bootstrap-modal/css/bootstrap-modal-bs3patch.css" rel="stylesheet" type="text/css"/>
<link href="<?php echo asset_url(); ?>plugins/bootstrap-modal/css/bootstrap-modal.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-fileupload/bootstrap-fileupload.min.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/select2/select2.css">-->


<!--<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/select2/select2.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/datepicker/css/datepicker.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-timepicker/css/bootstrap-timepicker.min.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-daterangepicker/daterangepicker-bs3.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-colorpicker/css/bootstrap-colorpicker.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/jQuery-Tags-Input/jquery.tagsinput.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-fileupload/bootstrap-fileupload.min.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/summernote/build/summernote.css">-->

<style type="text/css">
    .table > thead:first-child > tr:first-child > th, .table > thead:first-child > tr:first-child > td, .table-striped thead tr.primary:nth-child(2n+1) th {
        background-color: #428bca;
        border-color: #357ebd;
        border-top: 1px solid #357ebd;
        color: white;
        text-align: center;
    }

</style>
<!-- end: CSS REQUIRED FOR THIS PAGE ONLY -->
<!-- end: HEAD -->
<!-- start: BODY -->

<body>
    <!-- start: HEADER -->
    <div class="navbar navbar-inverse navbar-fixed-top">
        <!-- start: TOP NAVIGATION CONTAINER -->
        <div class="container">
            <div class="navbar-header">
                <!-- start: RESPONSIVE MENU TOGGLER -->
                <button data-target=".navbar-collapse" data-toggle="collapse" class="navbar-toggle" type="button">
                    <span class="clip-list-2"></span>
                </button>
                <!-- end: RESPONSIVE MENU TOGGLER -->
                <!-- start: LOGO -->
                <?php $this->load->view("common/logo"); ?>
                <!-- end: LOGO -->
            </div>
            <div class="navbar-tools">
                <!-- start: TOP NAVIGATION MENU -->
                <?php $this->load->view("common/notifications.php"); ?>
                <!-- end: TOP NAVIGATION MENU -->
            </div>
        </div>
        <!-- end: TOP NAVIGATION CONTAINER -->
    </div>
    <!-- end: HEADER -->
    <!-- start: MAIN CONTAINER -->
    <div class="main-container">
        <div class="navbar-content">
            <!-- start: SIDEBAR -->
            <?php $this->load->view("common/navigation"); ?>
            <!-- end: SIDEBAR -->
        </div>
        <!-- start: PAGE -->
        <div class="main-content">
            <!-- end: SPANEL CONFIGURATION MODAL FORM -->
            <div class="container">
                <!-- start: PAGE HEADER -->
                <div class="row">
                    <div class="col-sm-12">
                        <!-- start: PAGE TITLE & BREADCRUMB -->
                        <ol class="breadcrumb">
                            <li>
                                <a href="<?php echo base_url('dashboard'); ?>">
                                    Dashboard 
                                </a>
                            </li>
                            <li>
                                <a href="#">
                                    SMS
                                </a>
                            </li>

                            <li class="active">
                                Send SMS 
                            </li>
                            <li class="search-box">
                                <form class="sidebar-search">
                                    <div class="form-group">
                                        <input type="text" placeholder="Start Searching...">
                                        <button class="submit">
                                            <i class="clip-search-3"></i>
                                        </button>
                                    </div>
                                </form>
                            </li>
                        </ol>
                        <div class="page-header">
                            <h1>Send SMS </h1>
                        </div>

                        <p>Please use the table below to navigate or filter the results. </p>
                    </div>
                </div>
                <!-- end: PAGE HEADER -->
                <!-- start: PAGE CONTENT 
                <!-- start grid -->
                <div class="row">
                    <div class="col-md-12">
                    
    <!--start search box-->  
    <div class="panel panel-default">
								<div class="panel-heading">
									 <i class="fa fa-external-link-square"></i>
									Search
									<div class="panel-tools">
										<a class="btn btn-xs btn-link panel-collapse collapses" href="#">
										</a>
										
										<a class="btn btn-xs btn-link panel-refresh" href="#">
											<i class="fa fa-refresh"></i>
										</a>
										<a class="btn btn-xs btn-link panel-expand" href="#">
											<i class="fa fa-resize-full"></i>
										</a>
										<a class="btn btn-xs btn-link panel-close" href="#">
											<i class="fa fa-times"></i>
										</a>
									</div>
								</div>
								<div class="panel-body">
									
                           <!--start search-->                       
<div class="col-md-12">
<div class="col-sm-3" style="display:none">
<div class="form-group">
<label>Warehouse </label>
<select id="srh_warehouse_id" class="form-control" name="srh_warehouse_id">

<?php 
$ss_warehouse_id=$this->session->userdata('ss_warehouse_id'); 
foreach ($warehouse_list as $row)
{
$sel='';
if($ss_warehouse_id==$row->id)
{
$sel=' selected="selected"';
}
?>  

<option value="<?php echo $row->id; ?>" <?php echo $sel; ?>>
<?php echo $row->name; ?>
</option>
<?php }?>

</select>                                          
</div>
</div>

<div class="col-sm-3">
<div class="form-group">
                                      
</div>
</div>

 

<div class="col-sm-3">

                                                      	<div class="form-group">

															<label for="s2id_autogen1">From Date </label>

                                                            <!--<input id="srh_from_date" name="srh_from_date" type='text' class="form-control date-picker" value="<?php echo date('m/d/Y'); ?>" data-bv-field="date"/>-->
                                                            
                   <input id="srh_from_date" name="srh_from_date" type='text' class="form-control date" value="" data-bv-field="date"/>                                         
                                                            

                                                            

														</div>

													</div>
                                                        <div class="col-sm-3">

                                                      	<div class="form-group">

															<label for="s2id_autogen1">To Date </label>

                                                             <input id="srh_to_date" name="srh_to_date" type='text' class="form-control date" value="" data-bv-field="date"/>                                         
                   

                                                            

														</div>

													</div>
                                                    
                                                    <div class="col-md-3" style="margin-top:21px;">
                  <input class="btn btn-primary" value="Search" name="search" id="search" type="submit" onClick="search_by_custum_value()"> 
                  <input name="add_category" value="Reset" class="btn btn-danger" onClick="location.reload()" type="submit">
                  </div> 
                  
                 
</div> 
<!--end search-->           
                                    
								</div>
							</div>
    
    <!--end search box-->  
    
  
  
  
  
  <!--start send sms-->  
    <div class="panel panel-default">
								<div class="panel-heading">
									 <i class="fa fa-external-link-square"></i>
									Send SMS
									<div class="panel-tools">
										<a class="btn btn-xs btn-link panel-collapse collapses" href="#">
										</a>
										
										<a class="btn btn-xs btn-link panel-refresh" href="#">
											<i class="fa fa-refresh"></i>
										</a>
										<a class="btn btn-xs btn-link panel-expand" href="#">
											<i class="fa fa-resize-full"></i>
										</a>
										<a class="btn btn-xs btn-link panel-close" href="#">
											<i class="fa fa-times"></i>
										</a>
									</div>
								</div>
								<div class="panel-body">
									
                                       
<div class="col-md-12">





<div class="col-sm-9">
<div class="form-group">
   Message<br>
<textarea class="form-control" id="message" name="message_txt" rows="2" cols="50"></textarea>   
<div id="charNum" class="label label-success">Character Count: 0</div>                                
</div>
</div>

 


                                                    
                                                    <div class="col-md-3" style="margin-top:21px;">
                  <input type="submit" value="Send Message" class="btn btn-primary" onClick="send_sms();">
                  </div> 
                  
 <div class="col-sm-12">
  <div id="printableArea">
 <div class="panel-heading">
	Send SMS Details (<?php echo date("Y-m-d H:i:s"); ?>)
</div>
 <button onClick="printDiv('printableArea')" class="btn btn-blue dropdown-toggle pull-right" data-toggle="dropdown">
<i class="fa fa-print"></i>
</button>
<br>

 <table width="100%" border="0" id="total_product_qty_table">
  <tr class="table table-condensed table-hover table-striped dataTable">
   <td width="5%"><strong>#</strong></td>
    <td width="20%"><strong>Name</strong></td>
    <td width="10%"><strong>Phone</strong></td>
    <td><strong>Note</strong></td>
  </tr>
</table>
</div>

 </div>               
</div> 
<!--end search-->           
                                    
								</div>
							</div>
    
    <!--end send sms-->    
    
    <!--start list table-->  
    <div class="panel panel-default">
								<div class="panel-heading">
									<i class="fa fa-search"></i>
									Send SMS List
									<div class="panel-tools">
										<a class="btn btn-xs btn-link panel-collapse collapses" href="#">
										</a>
										
										<a class="btn btn-xs btn-link panel-refresh" href="#">
											<i class="fa fa-refresh"></i>
										</a>
										<a class="btn btn-xs btn-link panel-expand" href="#">
											<i class="fa fa-resize-full"></i>
										</a>
										<a class="btn btn-xs btn-link panel-close" href="#">
											<i class="fa fa-times"></i>
										</a>
									</div>
                                    
                                    <div class="panel-tools" style="top:2px;">
                                    <button class="btn btn-blue dropdown-toggle" data-toggle="dropdown">
                                        <i class="clip-list-5"></i> Add New
                                    </button>
                                    <ul class="dropdown-menu dropdown-light pull-right">
                                        <li>
                                            <a id="modal_ajax_salary_btn" data-toggle="modal" href="#">
                                                <i class="fa fa-plus"></i> Add Salary
                                            </a>
                                        </li>

                                    </ul>
                                </div>
								</div>
								<div class="panel-body">
									
                          <table width="100%" class="table table-bordered table-condensed table-hover table-striped dataTable" id="warehouse_table">
									  <thead>
							              <tr>
                                          <th class="hidden-xs"><input type="checkbox" name="select-all" id="select-all" /></th>
                                    			<th style="width:10%">Code</th>
												<th style="width:30%">Name</th>
												<th style="width:100px">Phone</th>
                                                <th>Address</th>
										</tr>
							          </thead>
							          <tfoot>
											   <tr>
                                               <th class="hidden-xs"></th>
                                               <th>Code</th>
                                				<th>Name</th>
												<th>Phone</th>
                                                <th>Address</th>
										</tr>
								     </tfoot>       
						          </table>
                         
                         
                           
                        </div>
							</div>   
      <!--end list table-->                                    
                    
                        <!-- start: DYNAMIC TABLE PANEL -->
                        
                       
                    </div>
                    <!-- end: DYNAMIC TABLE PANEL -->
                </div>
            </div>

            <!-- end grid -->


        </div>
        <!-- end: PAGE -->
    </div>
    <!-- end: MAIN CONTAINER -->
    <!-- start: FOOTER -->
    <div class="footer clearfix">
        <div class="footer-inner">
            
        </div>
        <div class="footer-items">
            <span class="go-top"><i class="clip-chevron-up"></i></span>
        </div>
    </div>
    <!-- end: FOOTER -->

    <!-- start ajax model -->
    <div id="ajax-modal" class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" style="display: none;"></div>
    <!-- end ajax model -->

    <!-- start: MAIN JAVASCRIPTS -->
    <?php $this->load->view("common/footer"); ?>
    <!-- end: MAIN JAVASCRIPTS -->
   
  
<script type="text/javascript" src="<?php echo asset_url(); ?>js/jquery.dataTables.min.js"></script>
          <script type="text/javascript" src="<?php echo asset_url(); ?>js/accounting.js"></script>
          <script type="text/javascript" src="<?php echo asset_url(); ?>js/accounting.min.js"></script>          
           <script type="text/javascript" src="<?php echo asset_url(); ?>js/jquery.dataTables.min.js"></script>
          <script type="text/javascript" src="<?php echo asset_url(); ?>js/dataTables.bootstrap.min.js"></script>
           <script type="text/javascript" src="<?php echo base_url('thems/js/bootbox.min.js'); ?>"></script>
    <script src="<?php echo asset_url(); ?>js/jquery-ui.js" ></script>		
	<script src="<?php echo asset_url(); ?>js/moment-with-locales.js"></script>
	<script type="text/javascript" src="<?php echo asset_url(); ?>js/bootstrap-datetimepicker.js"></script>         
    <script>

$("#message").keyup(function(){
    el = $(this);
    if(el.val().length >= 500){
        el.val( el.val().substr(0, 500) );
    } else {
       // $("#charNum").text('Character Count: '+(500-el.val().length));
    }
	 $("#charNum").text('Character Count: '+(el.val().length));
});

function send_sms(){
	

var values = new Array();
var count=0;
$.each($("input[name='sel_cus[]']:checked"), function() {
  //values.push($(this).val());
  //alert($(this).val());
  var cus_id=$(this).val();
  
  var message=$("#message").val();
  
  if(message==''){
	  alert("Please type message");
	  return false;
  }else{
 // alert(message);
   count++;
    $.ajax({
		type:'POST',
		url:'<?php echo base_url('sms/send_message_to_customer');?>',     
		   async: true, 
		data:{
			cus_id:cus_id,
			count:count,
			message:message,
			},
		success: function(data){
			var obj = jQuery.parseJSON(data);
			
			
			
			if(obj.row){
				$('#total_product_qty_table >tbody:last').append(obj.row);
			}
			

			
			
		/*
			t.row.add( ["","","","",
            		
                     ] ).draw( false );
					 
			*/	 
                             },
        });	
  }
  // or you can do something to the actual checked checkboxes by working directly with  'this'
  // something like $(this).hide() (only something useful, probably) :P
});				
}


function search_by_custum_value(){
	loadGrid();
}

$('#srh_from_date').datetimepicker({
        format: 'YYYY-MM-DD',

         <?php
//if (isset($salary_byid['sl_date']))
 {
    $d = date("Y, m-2, d", strtotime(date("Y-m-d"))); //(1985,01,01)
    ?>
            defaultDate: new Date (<?php echo $d ?>)
<?php }
// else
 { ?>
           // defaultDate: new Date()
<?php } ?>

        });
		
		 $('#srh_to_date').datetimepicker({
        format: 'YYYY-MM-DD',

            defaultDate: new Date()


        });
					
			jQuery(document).ready(function() {
				loadGrid();
				$("#route_id").select2();
				

				
				
				
				
				
				
				});		

			function loadGrid() 
			{
			var route_id=$('#route_id').val();
			$('#warehouse_table').DataTable({
			dom: 'Blfrtip',
			"ajax": "<?php echo base_url('sms/list_customer?route_id=') ?>"+route_id,
			"bDestroy": true,
			"iDisplayLength": 10,
			"lengthMenu": [[10,30,40,50 ,-1], [10,30,40, 50, "All"]],
			"order": [[ 0, "desc" ]]
			});
			}
			
			
			
			
			
			//customer  select lis UPDATE FUNCTION
			$('#select_customer_form').submit(function(e){
    		e.preventDefault(); 
         	$.ajax({
             url:'<?php echo base_url('sms/send_sms_process');?>',
             type:"post",
             data:new FormData(this),
             processData:false,
             contentType:false,
             cache:false,
             async:false,
             success: function(data){
			 obj=JSON.parse(data)
			 } });
			 
			 }); 
			//customer  select lis UPDATE FUNCTIONEND 
			$('#select-all').click(function(event) {
 			 if (this.checked) {
    		$(':checkbox').prop('checked', true);
  			} else {
  		  $(':checkbox').prop('checked', false);
 			 }
			});
					
	
function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}

		</script>

</body>