<script src="https://cdn.ckeditor.com/4.7.1/standard/ckeditor.js"></script>
<section class="content-header">
  <h1>Communicator Message</h1>
  <ol class="breadcrumb">
    <li><a href="<?php echo base_url().'admin';?>"><i class="fa fa-dashboard"></i> Home</a></li>
    <li><a href="<?php echo base_url('admin/message/communicator');?>">Communicator</a></li>
    <li class="active">Send</li>
  </ol>
</section>
<section class="content">
  <div class="row">
    <?php echo $this->utility->showMsg();?>
    <div class="col-md-12">
      <div class="loader" style="display:none;"><img src='<?php echo base_url();?>assets/images/loading.gif' alt='loading' /></div>
      <div class="box box-info">
        <div class="box-header with-border">
          <h3 class="box-title communicator">Communicator 

            <span class="headrAction_btn">
              <label for="messaged" name="messaged">
                Message 
                <input type="radio" id="messages" name="sms_message" value="1" checked>
              </label>
              <label for="sms" name="sms">
                SMS 
                <input type="radio" id="sms"  name="sms_message" value="2">
              </label>
            </span>

            <span class="msgLink">
              <a href="">Incoming Messages</a>
              <a href="<?php echo base_url().'admin/message/communicator'; ?>">Sent</a>
            </span>

          </h3>
        </div>
        <form id="add_cat_add" name="add_cat_add" class="form-horizontal" method="post" action="" enctype="multipart/form-data" onsubmit="return confirm('Are you sure you want to send?')">
           <div class="box-body">
             <div class="row">

               <div class="col-sm-6">
                    <div class="form-group">
                      <label class="col-sm-3 control-label">Select Language</label>
                      <div class="col-sm-9">
                        <ul class="languageWrapper">  
                          <li>
                            <label class="switch"> 
                              <input type="checkbox" name="language_id[]" value="1" class="acc_type" checked> 
                              <span class="slider round"></span>
                            </label>
                            <span class="swtchtext">German</span>
                          </li>
                          <li>
                            <label class="switch"> 
                              <input type="checkbox" name="language_id[]" value="2" class="acc_type"> 
                              <span class="slider round"></span>
                            </label>
                            <span class="swtchtext">English</span>
                          </li>  
                          <li>
                            <label class="switch"> 
                              <input type="checkbox" name="language_id[]" value="3" class="acc_type"> 
                              <span class="slider round"></span>
                            </label>
                            <span class="swtchtext">Spanish</span>
                          </li>
                        </ul>  
                      </div>
                    </div>
                    <div class="form-group">
                      <label class="col-sm-3 control-label">Chose Event</label>
                      <div class="col-sm-9">            
                      <select name="event_id" id="" class="form-control required">
                        <option value="1000000">TEST PARTY</option>
                        <?php if(count($events)>0){ 
                              foreach ($events as $key => $value) {
                        ?>
                          <option value="<?php echo $value['id']; ?>"><?php echo $value['title']; ?></option>
                        <?php }
                            }
                        ?>
                        <?php if(count($past_events)>0){ 
                              foreach ($past_events as $key => $pastvalue) {
                        ?>
                          <option value="<?php echo $pastvalue['id']; ?>"><?php echo $pastvalue['title'].' (PAST)'; ?></option>
                        <?php }
                            }
                        ?>
                      </select>
                      </div>
                    </div>

                    <div class="form-group">
                      <label class="col-sm-3 control-label">Subject</label>
                      <div class="col-sm-9">
                      <input type="text" class="form-control required" name="subject" id="">              
                      <span style="color:#f00; font-weight: bold"></span>
                      </div>
                    </div>

                    <div class="form-group">
                      <label class="col-sm-3 control-label">Message</label>
                      <div class="col-sm-9">
                      <textarea id="message" rows="5" class="form-control required" name="message" ></textarea> 
                      <script>
                        CKEDITOR.replace( 'message',{
                                filebrowserBrowseUrl : '/fileman/index.html',
                                filebrowserImageBrowseUrl : '/fileman/index.html?type=image',
                                removeDialogTabs: 'link:upload;image:upload',
                        });
                      </script> 
                      <span style="color:green; display:none;" id="sms_char"><span id="rchars">160</span> Character(s) Remaining...</span><br/>                     
                      </div>
                    </div>

                    <div class="form-group attach">
                      <label class="col-sm-3 control-label">Attachment</label>
                      <div class="col-sm-9">
                       <label for="uploadFile" class="choosefile">
                         Chooes File
                         <input type="file" name="file" id="uploadFile">
                       </label>
                      </div>
                    </div>
               </div>

               <div class="col-sm-6">
                 <ul class="switchList">
                      <!-- <li> 
                        <label class="switch"> 
                          <input type="checkbox" name="send_to" value="1" class="acc_type"> 
                          <span class="slider round"></span>
                        </label>
                        <span class="swtchtext">Send to paid customer only</span>
                      </li> -->
                      

                      <li> 
                        <label class="switch"> 
                          <input type="checkbox" name="test" value="1" class="acc_type" checked> 
                          <span class="slider round"></span>
                        </label>
                        <span class="swtchtext">TEST</span>
                      </li>
                      <span class="email_thing">
                      <li> 
                        <label class="switch"> 
                          <input type="checkbox" name="priority" value="1" class="acc_type"> 
                          <span class="slider round"></span>
                        </label>
                        <span class="swtchtext">Priority high !!!</span>
                      </li>

                      <li> 
                        <label class="switch"> 
                          <input type="checkbox" name="instant_message" value="1" class="acc_type"> 
                          <span class="slider round"></span>
                        </label>
                        <span class="swtchtext">Instant Message</span>
                      </li>

                      <li> 
                        <label class="switch"> 
                          <input type="checkbox" name="email" value="1" class="acc_type" checked> 
                          <span class="slider round"></span>
                        </label>
                        <span class="swtchtext">Email</span>
                      </li>
                     </span>
                    </ul>
                    <span class="receipant" style="margin-bottom:50px;"></span><br/>
                    <input type="hidden" name="sms_msg" id="sms_msg" value="1">
                    <input type="button" class="btn btn-gold check_receipent" value="Check Receipent" id="" style="background-color:#A9A9A9">
                    <input type="button" class="btn btn-gold" value="Send Message" id="add">
                    
               </div>

             </div>

            


          </div>
          
         
        </form>
      </div>
    </div>
  </div>
</section>
 <script type='text/javascript'>
  //$("#add_cat_add").validate();
  $('input[name="sms_message"]').click(function(){
    if($('input[name="sms_message"]:checked').val()==2)
    {
      $('.attach').hide();
      $('.email_thing').hide();
      $('#sms_msg').val(2);
    }
    else
    {
      $('.attach').show();
      $('.email_thing').show();
      $('#sms_msg').val(1);
    }
  })
  $('.check_receipent').click(function(){
      $.ajax({
        url:'<?php echo base_url();?>admin/message/check_receipent',
        data:$('#add_cat_add').serialize(),
        type: 'POST',
        success:function(res)
        {
          if(res)
          {
            $('.receipant').html(res);
          }
          else
          {
            alert('Something wrong....');
          }
        }
      })
    })
  $('#add').click(function(e){
    e.preventDefault();
    if($('input[name="sms_message"]:checked').val()==1)
    {
      if($('input[name="subject"]').val()=='')
      {
        $('input[name="subject"]').next().html('This field is required');
        return false;
      }
      else{
        $('input[name="subject"]').next().html('');
        $('#add_cat_add').submit();
      }
    }
    else{
      $('input[name="subject"]').next().html('');
      $('#add_cat_add').submit();
    }
  })
  var maxLength = 160;
  CKEDITOR.instances['message'].on('key', function(e) {
    if($('input[name="sms_message"]:checked').val()==2)
    {
      var self = this;
      var textlen = maxLength - self.getData().length;
      $('#rchars').text(textlen);
      if (textlen <= 0) {
          self.setData((self.getData()).substring(0, 160));
          $('#rchars').text(0);
          return false;
      }
    }
  });
  CKEDITOR.instances['message'].on('focus', function(e) {
    if($('input[name="sms_message"]:checked').val()==2)
    {
      var self = this;
      var textlen = maxLength - self.getData().length;
      $('#rchars').text(textlen);
      if (textlen <= 0) {
          self.setData((self.getData()).substring(0, 160));
          $('#rchars').text(0);
          return false;
      }
    }
  });
  $('input[name="sms_message"]').click(function(){
    if($('input[name="sms_message"]:checked').val()==2)
    {
      $('#sms_char').show();
    }
    else
    {
      $('#sms_char').hide();
    }
  })
</script>
 <script type="text/javascript">
  function return_back(){
    var back_url='<?php echo base_url()?>admin/shop';
    window.location=back_url;
  }
 </script>