

<?php $__env->startSection('title'); ?>
New Sms 
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumb'); ?>
<ol class="breadcrumb pull-right">
        <li><a href="<?php echo e(route('home')); ?>"><i class="fa fa-dashboard"></i> Home</a></li>

        <li class="active">New SMS</li>
      </ol>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('css'); ?>
<link href="<?php echo e(asset('css/jquery-confirm.css')); ?>" rel="stylesheet">
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

  <div class="container-fluid">
                <!-- /row -->
                <div class="row">
                    <div id="status" style="text-align: center;color:green;display: none"></div>
                    <div class="col-sm-12">
                        <div class="white-box">
                            <h3 class="box-title">Select Customers</h3>
                            <div class="table-responsive">
                                <table id="myTable" class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>Sr #</th>
                                            <th><input type="checkbox" name="select_all" value="1" class="select_all"></th>
                                            <th>Name</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $count =1;?>
                                        <?php $__currentLoopData = $clients; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td><?php echo e($count++); ?></td>
                                             <td><input type="checkbox" name="check_list" value="<?php echo e($c->id); ?>"></td>
                                            <td><?php echo e($c->name); ?></td>
                                           
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                    </tbody>
                                </table>
                            </div>
                            <hr>
                            <h3>Message Box</h3>
                            <textarea class="form-control" id='msg' rows='7' name="message"></textarea>
                            <br>
                            <button class="btn btn-success" onclick="checkSelectedCheckbox()" style="float: right">
                                Send Sms
                            </button>
                        </div>
                    </div>
                </div>
                <!-- /.row -->
              </div>
            <!-- /.container-fluid -->


<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
<script type="text/javascript" src="<?php echo e(URL :: asset('js/jquery-confirm.js')); ?>"></script>
<script>
   function sendSms(check_ids,message) {

    $.confirm({
        title: 'Are You Sure!..',
        content: "You won't be able to revert this!",
        buttons: {
            confirm: function () {
                var data = { 'ids': check_ids,'message':message };
                $.get('/sendMessage', data, function (data) {
                    if(data == 1) {
                        document.getElementById('status').style.display = 'block';
                        document.getElementById('status').style.color = 'green';
                        document.getElementById('status').innerHTML = '<strong><h3>Message Sent Successfully.</h3></strong>';
                        $('#status').delay(9000).fadeOut();
                        location.reload();
                    }
                    else {
                        document.getElementById('status').style.display = 'block';
                        document.getElementById('status').style.color = 'red';
                        document.getElementById('status').innerHTML = '<strong><h3>Error in query!</h3></strong>';
                        $('#status').delay(2000).fadeOut();
                    }
                });
            },
            cancel: function (val) {

            }
        }
    });
}

     
    $(".select_all").click(function(){
        $('input:checkbox').not(this).prop('checked', this.checked);
    });

    function checkSelectedCheckbox()
    {
        var message = $('#msg').val();
        if(!message) {
            document.getElementById('status').style.display = 'block';
            document.getElementById('status').style.color = 'red';
            document.getElementById('status').innerHTML = '<strong><h3>Message box is empty!</h3></strong>';
            $('#status').delay(3000).fadeOut();
            return;
        }

        var check_ids = [];
        
        $.each($("input[name='check_list']:checked"), function(){
                check_ids.push($(this).val());
            });

        // $.each($("input[name='check_list']:checked"), function(){
        //         check_ids.push($(this).val());
        //     });
        if(check_ids.length==0)
        {
            document.getElementById('status').style.display = 'block';
            document.getElementById('status').style.color = 'red';
            document.getElementById('status').innerHTML = '<strong><h3>please select any client!</h3></strong>';
            $('#status').delay(3000).fadeOut();
        }
        else {
          sendSms(check_ids,message); }
           //alert("selected IDS :"+check_ids.length);


    }


</script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/proje372/akram-city.projecterp.net/resources/views/customer/new-sms.blade.php ENDPATH**/ ?>