<script src="https://cdn.ckeditor.com/4.7.1/standard/ckeditor.js"></script>
<section class="content-header">
  <h1>Advertisement</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/advertisement');?>">Advertisement</a></li>
    <li class="active">Add</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">Add </h3>
        </div>
        <form id="add_frm" name="add_frm" class="form-horizontal" method="post" action="" enctype="multipart/form-data" onsubmit="return formValidate();">
           
        <?php if(!empty($language)){ 
                  foreach ($language as $lang) { ?>
          <div class="box-body">
            <div class="form-group">
              <label class="col-sm-2 control-label">Title [<?php echo $lang['name']; ?>]</label>
              <div class="col-sm-6">
              <?php $title = getValue('adverts_lang_values',array('lang_id'=>$lang['id'],'adverts_id'=>$advertDetails['id']));?>
              <input type="text" class="form-control required" required id="title_<?php echo $lang['id']; ?>" name="title_<?php echo $lang['id']; ?>" value="<?php if(!empty($title['title'])){ echo $title['title']; }?>" placeholder="Please enter title">
              </div>
            </div>
          </div>
      <?php } } ?>
      <?php if(!empty($language)){ 
                  foreach ($language as $lang) { ?>
          <div class="box-body">
            <div class="form-group">
              <label class="col-sm-2 control-label">Sub Title [<?php echo $lang['name']; ?>]</label>
              <div class="col-sm-6">
              <?php $title = getValue('adverts_lang_values',array('lang_id'=>$lang['id'],'adverts_id'=>$advertDetails['id']));?>
              <input type="text" class="form-control required" required id="sub_title_<?php echo $lang['id']; ?>" name="sub_title_<?php echo $lang['id']; ?>" value="<?php if(!empty($title['sub_title'])){ echo $title['sub_title']; } ?>" placeholder="Please enter sub title">
              </div>
            </div>
          </div>
      <?php } } ?>
          <?php if(!empty($language)){ 
                  foreach ($language as $lang) { ?> 
          <div class="box-body">
            <div class="form-group">
              <label class="col-sm-2 control-label">Intro Text [<?php echo $lang['name']; ?>]</label>
              <div class="col-sm-6">
              <?php $title = getValue('adverts_lang_values',array('lang_id'=>$lang['id'],'adverts_id'=>$advertDetails['id']));?>
              <textarea name="intro_text_<?php echo $lang['id']; ?>" id="intro_text_<?php echo $lang['id']; ?>" class="form-control required" required style="width:680px;height:175px;"><?php if(!empty($title['intro_text'])){ echo $title['intro_text']; }?></textarea>
              </div>
            </div>
          </div>
          <?php } } ?>
          <div class="box-body">
            <div class="form-group">
              <label class="col-sm-2 control-label">Type</label>
              <div class="col-sm-6">
                <select name="type" id="type" class="form-control">
                  <option value="1" <?php if($advertDetails['type']==1){ echo 'selected';}?>>Event</option>
                  <option value="2" <?php if($advertDetails['type']==2){ echo 'selected';}?>>Article</option>
                </select>
              </div>
            </div>
          </div>
          <div class="box-body">
            <div class="form-group">
              <label class="col-sm-2 control-label">Link</label>
              <div class="col-sm-6">
                <input type="text" class="form-control" id="link" name="link" value="<?php if($advertDetails['link']!=''){ echo $advertDetails['link'];} ?>">
              </div>
            </div>
          </div>
          <div class="box-body">
            <div class="form-group">
              <label class="col-sm-2 control-label">Countdown Date</label>
              <div class="col-sm-6">
                <input type="text" class="form-control" id="date" name="date" value="<?php if($advertDetails['date']>0){ echo date('Y/m/d H:i:d',strtotime($advertDetails['date']));} ?>">
              </div>
            </div>
          </div>
          
        <div class="box-body">
            <div class="form-group">
              <label class="col-sm-2 control-label">Logo</label>
              <div class="col-sm-6">
              <img src="<?php echo $advertDetails['image']; ?>">
                <input type="file" class="form-control" id="logofile" name="logofile" value="">
              </div>
            </div>
          </div>
          <div class="box-footer">
            <button type="button" onclick="return_back()"class="btn btn-default  margin-left  " >Cancel</button>
            <input type="submit" class="btn btn-info " value="Add" id="add">
          </div>
        </form>
      </div>
    </div>
  </div>
</section>
 <script type='text/javascript'>
  $("#add_frm").validate({
        rules: {
          <?php if(!empty($languages)){ 
                  foreach ($languages as $lang) { ?>
          'title_<?php echo $lang['id']; ?>': {
            required: true,
          },
          <?php } } ?>
          <?php if(!empty($languages)){ 
                  foreach ($languages as $lang) { ?>
          'sub_title_<?php echo $lang['id']; ?>': {
            required: true,
          },
          <?php } } ?>
          <?php if(!empty($languages)){ 
                  foreach ($languages as $lang) { ?>
          'intro_text_<?php echo $lang['id']; ?>': {
            required: true,
          },
          <?php } } ?>
          link:{
            required:true
          }
        }
      });
      $(function(){
        $("#date").datetimepicker();
      });
</script>
 <script type="text/javascript">
  function return_back(){
    var back_url='<?php echo base_url()?>admin/adverts';
    window.location=back_url;
  }
 </script>