<?php $this->load->view('admin/header_list'); ?>
<div class="wrapper">
<?php $this->load->view('admin/top'); ?>
<?php $this->load->view('admin/side'); ?>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        <?php echo $page_title; ?>
      </h1>
    </section>

    <!-- Main content -->
    <section class="content">

      <!-- Default box -->
      <div class="box">
		<?php echo form_open('studio/delete_selected_news', array('class'=>'form-horizontal','name'=>'bulk_action_form','onsubmit'=>'return deleteConfirm();'));?>
        <div class="box-header with-border">
          <h3 class="box-title"><?php echo $page_title; ?></h3>

          <div class="box-tools pull-right">
            <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
              <i class="fa fa-minus"></i></button>
            <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
              <i class="fa fa-times"></i></button>
          </div>
        </div>
		<div class="box-header with-border">
          <a href="<?php echo base_url(); ?>studio/add_news" class="btn btn-primary">Add News</a>
		  <button type="submit" class="btn" name="bulk_delete_submit">Delete Seleted News</button><br><br>
		  <div id="message"><?php echo $message;?></div>
        </div>
        <div class="box-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
				  <th><input type="checkbox" id="select_all" onclick='select_all_check()'></th>
                  <th>S.No</th>
                  <th>News</th>
                  <th>Options</th>
                </tr>
                </thead>
                <tbody>
				<?php 
					$this->db->select('*');
					$this->db->from('news');
					$this->db->where('status','yes');
					$star_list = $this->db->get();
						if($star_list->num_rows()>0){
							$i=1;
							foreach($star_list->result() as $row){
								echo "<tr>
									    <td style='width:10px;'><input type='checkbox' name='checked_id[]' class='checkbox' value='".$row->news_id."'/></td> 
										<td style='width:50px;'>".$i."</td>
										<td>".$row->news."</td>
										<td style='width:225px;'>
										<a href='".base_url()."studio/news_view/".$row->news_id."' class='label label-success'><i class='fa fa-tv'></i> View</a>
										<a href='".base_url()."studio/edit_news/".$row->news_id."' class='label label-warning'><i class='fa fa-edit'></i> Edit</a>
										<a href='#' title='Delete' onclick='delete_record(".$row->news_id.")' class='label label-danger'><i class='fa fa-ban'></i> Delete</a></td>
									  </tr>";
								$i++;
							}
							
						}
						?>
                </tbody>
                <tfoot>
                <tr>
				  <th></th>
                  <th>S.No</th>
                  <th>News</th>
                  <th>Options</th>
                </tr>
                </tfoot>
              </table>
            </div>
        <!-- /.box-body -->
        <div class="box-footer">
        </div>
		<?php echo form_close();?>
        <!-- /.box-footer-->
      </div>
      <!-- /.box -->

    </section>
    <!-- /.content -->
  </div>
  <script type="text/javascript">
		function delete_record(id)
		{
			$.msgBox({
				title: "Confirm !",
				content: "Are you sure you want to delete this?",
				type: "confirm",
				buttons: [{ value: "Confirm" }, { value: "Cancel"}],
				success: function (result) {
					if (result == "Confirm") {
						var form_data = {
							news_id : id,					
							ajax : '1'
						};
						$.ajax({
							url: '<?php echo base_url(); ?>studio/delete_news',
							type: 'POST',
							async : false,
							data: form_data,
							success: function(msg) {
								setTimeout(function () {
								   window.location.href = "<?php echo base_url();?>studio/news_list"; //will redirect to your blog page (an ex: blog.html)
								}, 2000);
								$('#message').html(msg);
							}
						});
						return false;
					}
				}
			});
		}
	</script>
	<script type="text/javascript">
	function deleteConfirm(){
		var result = confirm("Are you sure to delete users?");
		if(result){
			return true;
		}else{
			return false;
		}
		/*$.msgBox({
				title: "Confirm !",
				content: "Are you sure you want to delete this?",
				type: "confirm",
				buttons: [{ value: "Confirm" }, { value: "Cancel"}],
				success: function (result) {
					if (result == "Confirm") {
						return true;
					}else{
						return false;
					}
				}
			});*/
	}
	
	function select_all_check(){
		$("#select_all").change(function () {
			$("input:checkbox").prop('checked', $(this).prop("checked"));
		});
	}
	</script>
 <?php $this->load->view('admin/footer_list'); ?>