<?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>Slider</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">Slider</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">
                <h4>View All Blog</h4>
                
              </div>
                <div class="card-body">
                  <table id="example" class="table table-bordered table-striped">
                    <thead>
                    <tr>
                      <th>id</th>
                      <th>Title</th>
                      <th>Image</th>
                      <th>Category</th>
                      <th></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $i=1; foreach ($get_all_blog as $key => $blog):
                    $category = $this->blog_model->get_all_category_by_blog_id($blog->category);
                    ?>
                    <tr>
                      <td><?php echo $i ?></td>
                      <td><?php echo $blog->title ?></td>
                      <td><img src="<?php echo base_url() ?><?php echo $blog->thumb ?>" width="100px"></td>
                      <td><?php echo $category->category_name ?></td>
                      <td><a href="" class="btn btn-info btn-sm" data-toggle="modal" data-target="#update-blog<?php echo $blog->id ?>"><i class="fa fa-edit" aria-hidden="true"></i></a>
                        <a class="btn btn-danger btn-sm" onclick="return confirm('Are you sure?')" href="<?php echo base_url() ?>admin/blog/delete_blog/<?php echo $blog->id ?>"><i class="fa fa-trash" aria-hidden="true"></i></a></td>
                    </tr>
                    <?php $i++; ?>
                    <?php endforeach; ?>
                    </tbody>
                    
                  </table>
                </div>
              </div>
            </div>
          </div>
      </div>
    </section>
    <!-- /.content -->
  </div>
  
<?php $i=1; foreach ($get_all_blog as $key => $blog):
$category = $this->blog_model->get_all_category_by_blog_id($blog->category);
?>
<div class="modal fade" id="update-blog<?php echo $blog->id ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Update Blog</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <?php echo form_open_multipart(base_url().'admin/blog/update_blog'); ?>
          
          <div class="col-md-12">
                <div class="form-group">
                  <label>Blog Title <span class="required">*</span></label>
                  <input type="text" name="title" class="form-control" placeholder="Enter Blog Title" required="" value="<?php echo $blog->title ?>">
                </div>
              </div>
              <div class="col-md-12">
                <div class="form-group">
                  <label>Blog Short Description <span class="required">*</span></label>
                  <textarea type="text" name="short_description" class="form-control" placeholder="Enter Blog Short Description" required=""><?php echo $blog->short_description ?></textarea>
                </div>
              </div>

              <div class="col-md-12">
                <div class="form-group">
                  <label>Blog SEO Title</label>
                  <input type="text" name="seo_title" class="form-control" placeholder="Enter Blog Keywords" value="<?php echo $blog->seo_title ?>">
                </div>
              </div>
              <div class="col-md-12">
                <div class="form-group">
                  <label>Blog SEO Keywords</label>
                  <textarea type="text" name="keywords" class="form-control" placeholder="Enter Blog Keywords"><?php echo $blog->keywords ?></textarea>
                </div>
              </div>
              <div class="col-md-12">
                <div class="form-group">
                  <label>Blog SEO Description</label>
                  <textarea type="text" name="seo_description" class="form-control" placeholder="Enter Blog Description"><?php echo $blog->seo_description ?></textarea>
                </div>
              </div>
              <div class="col-md-12">
                <div class="form-group">
                  <label>Blog SEO Schema</label>
                  <textarea type="text" name="schema" class="form-control" placeholder="Enter Blog Schema"><?php echo $blog->schema ?></textarea>
                </div>
              </div>
              <div class="col-md-12">
                <div class="row">
                  <div class="col-sm-4">
                    <div class="">
                      <label for="radioDanger3">
                        Featured
                      </label>
                    </div>
                  </div>
                  <div class="col-sm-4">
                    <div class="form-group clearfix">
                      <div class="icheck-danger d-inline">
                        <input type="radio" name="breaking" checked="" id="breaking-off" value="0" <?php if($blog->breaking == 0){echo 'checked';} ?>>
                        <label for="breaking-off">
                        </label>
                      </div>
                      <div class="icheck-success d-inline">
                        <input type="radio" name="breaking" id="breaking-on" value="1" <?php if($blog->breaking == 1){echo 'checked';} ?>>
                        <label for="breaking-on">
                        </label>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              
              <div class="col-md-12">
                <div class="form-group">
                  <label>Tags</label>
                  <textarea type="text" name="tag" class="form-control" placeholder="Enter Blog Tag" ><?php echo $blog->tag ?></textarea>
                </div>
              </div>
              <div class="col-md-12">
                <div class="form-group">
                  <label>Blog Content</label>
                  <textarea type="text" name="content" class="text-editor" placeholder="Enter Blog content"><?php echo $blog->content ?></textarea>
                </div>
              </div>

              <div class="col-md-12 ">
               <div class="row">
                  <div class="col-md-12">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Blog Image</label>
                        <input type="file" name="image" class="form-control name_list image" />
                     </div>
                  </div>
               </div>
            </div> 
            <div class="col-md-12 ">
               <div class="row">
                  <div class="col-md-12">
                     <div class="form-group">
                        <label for="inputEmail" class="col-sm-12 col-form-label">Preview Blog Image</label>
                        <div>
                          <img src="<?php echo base_url() ?><?php echo $blog->thumb ?>" width="150px;">
                        </div>
                     </div>
                  </div>
               </div>
            </div>   
            <div class="col-md-12">
                <div class="form-group">
                  <label>Blog Category</label>
                  <select  name="category" class="form-control">
                    <option value="">Select Category</option>
                    <?php foreach ($blog_category as $key => $category):?>
                      <option <?php if($blog->category == $category->id){echo 'selected';} ?> value="<?php echo $category->id ?>"><?php echo $category->category_name ?></option>
                    <?php endforeach; ?>
                  </select>
                </div>
              </div>
          <input type="hidden" name="id" class="form-control" value="<?php echo $blog->id ?>">
          
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Update</button>
      </div>
      <?php echo form_close(); ?>
    </div>
  </div>
</div>
<?php endforeach; ?>