<?php
    $errors = $this->session->userdata('errors');
    if (isset($errors)) {
        ?>
        <script>
            swal ( "Oops" ,  "<?php echo $errors ?>" ,  "error" )
        </script>
        <?php echo $errors ?>
        <?php
        $this->session->unset_userdata('errors');
    }
    $error = $this->session->userdata('error');
    if (isset($error)) {
        ?>
         <script>
            swal ( "Oops" ,  "<?php echo $error ?>" ,  "error" )
        </script>
        <?php
        $this->session->unset_userdata('error');
    }
    $success = $this->session->userdata('success');
    if (isset($success)) {
        ?>
         <script>
            swal({
          title: "Done!",
          text: "<?php echo $success ?>",
          icon: "success",
        });
        </script>
        <?php
        $this->session->unset_userdata('success');
    }
    ?>
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Section 15</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?php echo admin_url() ?>admin">Home</a></li>
              <li class="breadcrumb-item active">Section 15</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-sm-12">
            <div class="card card-default">
              <div class="card-header">
                <h3 class="card-title">Select A Class</h3>
                
              </div>
              <!-- /.card-header -->
              <form method="GET">
                <div class="card-body">
                  <div class="row">
                    <div class="col-md-12">
                      <div class="form-group">
                        <label>Select A Page<span class="required">*</span></label>
                        <select type="text" name="class_id" class="form-control" placeholder="Enter Content" required="">
                          <option  value="">Select</option>
                          <?php foreach ($all_pages as $page):?>
                            <option value="<?php echo $page->id ?>"><?php echo $page->title ?></option>
                          <?php endforeach; ?>
                        </select>
                      </div>
                    </div>
                    
                    <div class="col-md-12">
                      <div class="form-group">
                        <button class="btn btn-info" type="submit" style="float: right">Add</button>
                      </div>
                    </div>
                    <?php echo form_close(); ?>
                  </div>
              </div>
            </div>
          </div>
      </div>
    </section>
    <?php if(isset($_GET['class_id'])):
      $this->db->where('section_15_class_id', $_GET['class_id']);
      $section = $this->db->get('event_section_15')->row();

      ?>
      <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-sm-12">
            <div class="card card-default">
              <div class="card-header">
                <h3 class="card-title">Add or Update Section</h3>
              </div>
              <!-- /.card-header -->
              <?php echo form_open_multipart(base_url().'admin/event/add_or_update_section_15'); ?>
              <div class="card-body">
                <div class="row">
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Title<span class="required">*</span></label>
                      <input type="text" name="section_15_title" class="form-control" placeholder="Enter Title" required="" value="<?php echo $section->section_15_title; ?>">
                      <input type="hidden" name="class_id" class="form-control" placeholder="Enter Title" required="" value="<?php echo $_GET['class_id']; ?>">
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Description<span class="required">*</span></label>
                      <textarea type="text" name="section_15_description" class="form-control" placeholder="Enter Description" required=""><?php echo $section->section_15_description; ?></textarea>
                    </div>
                  </div>

                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Image<span class="required">*</span></label>
                      <input type="file" name="section_15_image" class="form-control" placeholder="Enter  Content 2" >
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                      <label>Image<span class="required">*</span></label>
                      <img src="<?php echo base_url()?><?php echo $section->section_15_image; ?>" width="100px">
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                      <label for="inputEmail" class="col-sm-12 col-form-label">Add Content</label>
                      <div class="table-responsive">
                         <div id = "requirement_area">
                            <?php if (count(json_decode($section->section_15_content)) > 0): ?>
                                  <?php
                                  $counter = 0;
                                  foreach (json_decode($section->section_15_content) as $requirement):?>
                                  <?php if ($counter == 0):
                                      $counter++; ?>
                                      <div class="d-flex mt-2">
                                          <div class="flex-grow-1 px-3">
                                              <div class="form-group">
                                                  <input required type="text" class="form-control" name="section_15_content[]" placeholder="Enter Content" value="<?php echo $requirement; ?>">
                                              </div>
                                          </div>
                                          <div class="">
                                              <button type="button" class="btn btn-success btn-sm" style="" name="button" onclick="appendRequirement()"> <i class="fa fa-plus"></i> </button>
                                          </div>
                                      </div>
                                  <?php else: ?>
                                      <div class="d-flex mt-2">
                                          <div class="flex-grow-1 px-3">
                                              <div class="form-group">
                                                  <input required type="text" class="form-control" name="section_15_content[]" placeholder="Enter Content" value="<?php echo $requirement; ?>">
                                              </div>
                                          </div>
                                          <div class="">
                                              <button type="button" class="btn btn-danger btn-sm" style="margin-top: 0px;" name="button" onclick="removeRequirement(this)"> <i class="fa fa-minus"></i> </button>
                                          </div>
                                      </div>
                                  <?php endif; ?>
                              <?php endforeach; ?>
                            <?php else: ?>
                              <div class="d-flex mt-2">
                                  <div class="flex-grow-1 px-3">
                                      <div class="form-group">
                                          <input type="text" class="form-control" name="section_15_content[]" placeholder="Enter Content" required>
                                      </div>
                                  </div>
                                  <div class="">
                                      <button type="button" class="btn btn-success btn-sm" style="" name="button" onclick="appendRequirement()"> <i class="fa fa-plus"></i> </button>
                                  </div>
                              </div>
                            <?php endif; ?>
                          </div>
                      </div>
                   </div>
                  </div>
                  
                  
                  <div class="col-md-12">
                    <div class="form-group">
                      <button class="btn btn-info" type="submit" style="float: right">Update</button>
                    </div>
                  </div>
                  <?php echo form_close(); ?>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
    <div id = "blank_requirement_field">
      <div class="d-flex mt-2">
          <div class="flex-grow-1 px-3">
              <div class="form-group">
                  <input type="text" class="form-control" name="section_15_content[]"  placeholder="Enter Content">
              </div>
          </div>
          <div class="">
              <button type="button" class="btn btn-danger btn-sm" style="margin-top: 0px;" name="button" onclick="removeRequirement(this)"> <i class="fa fa-minus"></i> </button>
          </div>
      </div>
  </div>
    <script type="text/javascript">
      jQuery(document).ready(function() {
        jQuery('#blank_requirement_field').hide();
      });
      var blank_requirement = jQuery('#blank_requirement_field').html();
      function appendRequirement() {
        jQuery('#requirement_area').append(blank_requirement);
      }
      function removeRequirement(requirementElem) {
        jQuery(requirementElem).parent().parent().remove();
      }
    </script>
    <?php endif;?>
  </div>
