<?php
if(Auth::user()->user_type == 'organization')
{
    $layout = 'fcviews.layouts.org';
}
elseif(Auth::user()->user_type == 'organization_user')
{
    $layout = 'fcviews.layouts.user';
}
?>

<?php $__env->startSection('content'); ?>
<style>
.dropdown-menu a:hover{ background:#f27200;color:#fff;}</style>
<style>
.notification1 {
  background-color: #555;
  color: white;
  text-decoration: none;
  padding: 15px 26px;
  position: relative;
  display: inline-block;
  border-radius: 2px;
}

.notification1:hover {
  background: red;
}

.notification1 .badge {
  position: absolute;
  top: -10px;
  right: -10px;
  padding: 5px 10px;
  border-radius: 50%;
  background-color: red;
  color: white;
}



</style>
<div class="main-panel">
    <div class="content">
            <div class="panel-header">
                <div class="page-inner py-5 text-white"  style="background:#313232">
                    <div class="d-flex align-items-left align-items-md-center flex-column flex-md-row">
                        <div><div class="page-header">
                            <h4 class="page-title text-white">Send SMS</h4>
                            <ul class="breadcrumbs">
                                    <li class="nav-home">
                                        <a class="text-white" href="">
                                            <i class="flaticon-home"></i>
                                        </a>
                                    </li>
                                    <li class="separator">
                                        <i class="flaticon-right-arrow"></i>
                                    </li>
                                    <li class="nav-item">
                                        <a class="text-white" href="">SMS Composer</a>
                                    </li>
                                </ul>
                        </div></div>
                        <div class="ml-md-auto py-2 py-md-0">
                            <a href="" class="btn btn-white btn-border btn-round mr-2"><i class="fas fa-arrow-circle-left"></i> Back</a>
           <a href="#" data-target="#recipients" data-toggle="modal" id="show-modal" class="btn btn-white btn-round"><i class="fa fa-plus"></i> Recipients</a>
                        </div>
                    </div>
                </div>
                
            <div id="app">
            <div class="page-category">
                <div class="page-inner mt--5">
                    <div class="row mt--2">
                            <div class="col-md-12">
                                <div class="card full-height">
                                    <div class="card-body">
                                        <div class="card-title">Custom SMS</div>
                                                              <!-- check if exist -->
                                        <?php if($errors->any()): ?>
                                        <div class="alert alert-danger alert-dismissible" role="alert">
                                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                        <strong>Error! </strong>There were some errors with inputs.
                                        <ul>
                                        <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <li><?php echo e($error); ?></li>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </ul>
                                        </div>
                                        
                                        <?php endif; ?>
                                        <?php echo $__env->make('layouts.messages', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                                       <div class="row">
                    						<div class="wizard-container wizard-round col-md-12">
                    							<div class="wizard-header text-center bg-warning text-white">
                    								<h4>To Send Custom SMS use column name in braces e.g. {columnname}. For Example Dear {name} come on {date}. 
                    								Please ensure your names in braces matches column name in excel file. NOTE<span class="text-danger">*</span>: The first column name should be <strong>number</strong>
                    									
                    								</h4>
                    							</div>
                    							<form action="<?php echo e(route('importcustom')); ?>" method="post" enctype="multipart/form-data">
                    							    <?php echo csrf_field(); ?>
                    								<div class="wizard-body">
                    									<div class="row">
                    
                    										<ul class="wizard-menu nav nav-pills nav-primary">
                    											<li class="step" style="width: 50%;">
                    												<a class="nav-link active" href="#custom" data-toggle="tab" aria-expanded="true"><i class="fa fa-user mr-0"></i> Submit Custom Message</a>
                    											</li>
                    											<!--	<li class="step" style="width: 25%;">
                    												<a class="nav-link success" href="#contacts" data-toggle="tab" aria-expanded="true"><i class="fa fa-user mr-0"></i> Uploaded Contacts</a>
                    											</li>-->
                    											
                    											<li class="step" style="width: 50%;">
                    												<a class="nav-link notification1" href="#preview" data-toggle="tab"><i class="fa fa-file mr-2"></i> Custom Message Preview
                    												<?php if(count($mycustomdata)==0): ?> 
                    											          <span></span>
                                                                    <?php elseif(count($mycustomdata)>0): ?>
                                                                    
                                                                    	<span class="badge" style="margin-right:25%"><?php echo e(count($mycustomdatacount)); ?></span>
                                                                    	
                                                                    <?php endif; ?>
                                                                  
                                                               
                    												</a>
                    											</li>
                    										
                    										</ul>
                    									</div>
                    									<div class="tab-content">
                    										<div class="tab-pane active" id="custom">
                    											<div class="row">
                    											
                    												<div class="col-md-6">
                    												
                    													<div class="form-group">
                    														<p class="form-control mb-0">Download <a href="<?php echo e(url('/sample/Sample.xlsx')); ?>">sample file</a></p>
                    													</div>
                    													<div class="form-group">
                    														<label>Import CSV/Excel file ONLY</label>
                    														<input type="file" name="file" class="form-control" />
                    													</div>
                    												
                    												</div>
                    												<div class="col-md-6">
                    												
                    													<div class="form-group">
                    														<label>Message :</label>
                    														<textarea name="message" class="form-control" rows="5" required></textarea>
                    													    
                    													   
                    													</div>
                    													 <div class="form-group">
                    													<input type="reset" class="btn btn-danger btn-fill btn-black" name="cancel" value="Clear">
                    													<input type="submit" class="btn btn-success btn-fill btn-black" name="submit" value="Submit">
                    													</div>
                    												</div>
                    												
                    
                    											</div>
                                							</form>
                    										</div>
                    										
                    										
                    										
                    											<div class="tab-pane" id="contacts">
                    									
                    											<div class="row">
                    								            <?php if(!empty($mycustomdatacontacts)): ?>
                    								            
                    											<?php $__currentLoopData = $mycustomdatacontacts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $contacts): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            									
                        											
                            							
            											
                    							                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    											<?php endif; ?>
                    										       
                    										        
                    										        
                    										        
                    										        
                    										          <div class="card-title">Uploaded Contacts Preview</div>
                                        <!-- check if exist -->
                                
                                        
                                        <div class="table-responsive">
                                        <table  id="table" class="display table table-striped table-hover">
                                            <thead>
                                          <tr>
                                                 <th>ID#</th>
                                                 <th>Contact </th>
                                                 <th>Message </th>
                                            
                                                <th class="text-center">Action</th>
                                                </tr>
                                            </thead>
                                            <tfoot>
                                            <tr>
                                            <th>ID#</th>
                                            <th>Contact </th>
                                            <th>Message </th>
                                            
                                                <th class="text-center">Action</th>
                                                </tr>
                                            </tfoot>
                                            <tbody>
                                                 <?php if(!empty($mycustomdatacontacts)): ?>
                                            <?php $__currentLoopData = $mycustomdatacontacts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $contacts): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <tr>
                                                   <td><?php echo e($contacts->id); ?></td>
                                										             <td><?php echo e($contacts->number); ?></td>
                                            <td><?php echo e($contacts->sms); ?></td>
                                           
                                            <td>
                                            <div class="form-button-action" role="group" aria-label="Actions">
                                      
                                            
                                            </form>
                                            </div>
                                            </td>
                                            </tr>
                                    
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            <?php endif; ?>
                                            </tbody>
                                        </table>
                                         
                          
                                    </div>     
                    										        
                    										</div>
                    									
                    									</div>
                    										
                    									   <!-- Create modal -->
                                    <div class="modal fade" id="recipients" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                                        <div class="modal-dialog modal-dialog-centered" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <h5 class="modal-title" id="exampleModalLongTitle">All Message Recipients </h5>
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                        <span aria-hidden="true">&times;</span>
                                                    </button>
                                                </div>
                                                <div class="modal-body panel-default bg-light">
                                                  <table  id="table" class="display table table-striped table-hover">
                                            <thead>
                                          <tr>
                                                 <th>ID#</th>
                                                 <th>Contact </th>
                                                 <th>Message </th>
                                            
                                            
                                                </tr>
                                            </thead>
                                            <tfoot>
                                            <tr>
                                            <th>ID#</th>
                                            <th>Contact </th>
                                            <th>Message </th>
                                           
                                                </tr>
                                            </tfoot>
                                            <tbody>
                                                 <?php if(!empty($mycustomdatacontacts)): ?>
                                            <?php $__currentLoopData = $mycustomdatacontacts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $contacts): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <tr>
                                                   <td><?php echo e($contacts->id); ?></td>
                                										             <td><?php echo e($contacts->number); ?></td>
                                            <td><?php echo e($contacts->sms); ?></td>
                                           
                                         
                                            </tr>
                                    
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            <?php endif; ?>
                                            </tbody>
                                        </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                <!-- end Create modal -->
                    									<div class="tab-pane" id="preview">
                    											<h4 class="info-text">Custom Message Preview
                    										
                    											</h4>
                    											<div class="row">
                    										  <?php if(count($mycustomdata)>0): ?>
                    											<?php $__currentLoopData = $mycustomdata; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            										<div class="table-responsive">
                            										    <table class="table">
                                										    <thead>
                                										        <tr>
                                										           <th>Recipient Summary: </th>
                                										           <td><?php echo e($allmessages); ?> Messages</td>
                                    										       <th>Rate/Message: </th>
                                										           <td><?php echo e($rates[0]); ?></td>
                                										          </tr>
                                										    </thead>
                                										    <tbody>
                                										        <tr>
                                										           <th>Total Cost: </th>
                                										           <td><?php echo e($totalcost); ?></td>
                                										           <th>Wallet Status: </th>
                                										           <td><?php echo e($checkaccount); ?></td>
                                										        </tr>
                                										        <tr>
                                										            <th>Sample Message to Recipient(s)</th>
                                										            <td colspan="2"><?php echo e($data->sms); ?></td>
                                										                <td ><a href="#" data-target="#recipients" data-toggle="modal" id="show-modal" class="btn btn-white btn-round"><i class="fa fa-eye"></i> View All Recipients</a></td>
                                										                       

                                										        </tr>
                                										        <tr class="table-danger">
                                										            <th>Invalid Phone Number(s)</th>
                                										            <td colspan="3"><?php echo e(str_replace('"','',json_encode($invalid_nos))); ?></td>
                                										        </tr>
                                										    </tbody>
                                										</table>
                                										
                            										</div>
                        											
                            									<form method="post" action="<?php echo e(route('drop-table')); ?>">
                    							                 <?php echo csrf_field(); ?>
                        							                  <div class="form-group">
                        													<input type="submit" class="btn btn-alert btn-fill btn-black" name="cancel" value="Cancel">
                													  </div>
            													</form>
            													<form action="#" method="post">
                    							                 <?php echo csrf_field(); ?>
                        							                 <div class="form-group">
                        													<input type="button" id="submitcustommessage" class="btn btn-success btn-fill btn-black" name="submit" value="Confirm and Send">
                        											  </div>
                    							                </form>
                    							                <?php if($data->reason): ?>
                    							                <div class="table-responsive">
                    										            <h2>Failed Messages </h2>
                        										    <table id="table" class="display table table-striped table-hover">
                            										    <thead>
                            										        <tr>
                            										           <th>Recipient </th>
                            										           <th>Reason</th>
                        										           </tr>
                            										    </thead>
                            										    <tfoot>
                            										        <tr>
                            										           <th>Recipient </th>
                            										           <th>Reason</th>
                        										           </tr>
                            										    </tfoot>
                            										    <?php $__currentLoopData = $mycustomdatacount; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            										    <?php if($data->reason): ?>
                            										    <tbody>
                            										        <tr>
                            										           <td><?php echo e($data->number); ?></td>
                            										           <td><?php echo $data->reason; ?></td>
                            										        </tr>
                        										        </tbody>
                        										        <?php endif; ?>
                        										        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    										        </table>
                										        
                    											</div>
                    							                <?php endif; ?>
                    											<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    											<?php elseif(count($mycustomdata)==0): ?>
                        										  <p>You don't have any custom messages to send.Kindly upload excel data first.</p>
                        										
                        										<?php endif; ?>
                    											
                    										        <hr>
                    										        
                    										</div>
                    									
                    									</div>
                    								</div>
                    
                    							
                    							
                    						</div>
                    					</div>
                                       
                                        
                                </div>
                            </div>
                        </div>
            </div>
            </div>
            </div>
        </div>
    </div>
    

    <script src="<?php echo e(asset('js/jquery.min.js')); ?>"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			$.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
			});
			// 
			            // approve
			$('#submitcustommessage').on('click', function () {
                // e.preventDefault();
                // let input_order_id = $(this).data('id');
                swal({
                        title: 'Sending...',
                        text: 'Please wait...',
                        type: 'success',
                        buttons : {
                          confirm: {
                            className : 'btn btn-success'                 
                          }
                        }             
                      }).then(function(){
                        // window.location.href = '';
                      });
                $.ajax({
					url: '/fc/submitcustommessage',
					dataType: 'json',
					type: "POST",
					data : { 
                            _token: "<?php echo e(csrf_token()); ?>" 
                        },
					success: function (data) {
					    console.log(data);
					    
                        swal({
                        title: 'Success!',
                        text: 'Sent succesfully',
                        type: 'success',
                        buttons : {
                          confirm: {
                            className : 'btn btn-success'                 
                          }
                        }             
                      }).then(function(){
                        window.location.href = '';
                      });
                    //   window.location.href = '/customsms';
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        // console.warn(xhr.responseText)
                        console.log(JSON.stringify(jqXHR));
                        console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
                    }
				// 	window.location.href('/customsms');
                });
            });
			// 
		});
   </script>
        <script src='https://code.jquery.com/jquery-3.2.0.min.js'></script>
    <script src='https://unpkg.com/popper.js@1.11.1'></script>
    <script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js'></script>
    <?php $__env->stopSection(); ?>
<?php echo $__env->make($layout, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/dashmobisky/public_html/Accounts/resources/views/fcviews/customsms/index.blade.php ENDPATH**/ ?>