<?php include 'include/header.php';?>

    <body class="fixed-left">
        
        <!-- Begin page -->
        <div id="wrapper">
        
       <?php include 'include/side_menu.php';
$this->db->order_by("id", "asc");

$userList = $this->admin_common_model->get_all('coupons');

?>

      
            <div class="content-page">
                <!-- Start content -->
                <div class="content">
                    <div class="container">

                        <!-- Page-Title -->
                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="pull-left page-title">Welcome !</h4>&nbsp;	&nbsp;	

                                <ol class="breadcrumb pull-right">
  <li><a href="<?=base_url('admin/view_page/dashboard');?>"><?php $fetch_app_name = $this->admin_common_model->get_where('admin',['id'=>'1']);
                                echo $fetch_app_name[0]['app_name']; ?></a></li>   
                                    <li class="active">Offer List</li>
                                </ol>
                            </div>
                        </div>

                        <!-- Start Widget -->
                
<div class="row">
                            <div class="col-md-12">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <h3 class="panel-title">Offer List</h3>
                                    </div>
                                    <div class="panel-body">
                                        <div class="row">
                                            <div class="col-md-12 col-sm-12 col-xs-12">
                                                <table id="datatable" class="table table-striped table-bordered">
                                                    <thead>
                                                        <tr>
                                                            <th>ID</th>
<!--                                                            <th>Username</th>
-->                                                            <th>Code</th>
                                                            <th>Percentage</th>
                                                            <th>End Date</th>
                                                            <th>Description</th>
                                                            <th>Description (In Arabic)</th>
                                                            <th>Image</th>
                                                            <th>Action</th>
                                                        </tr>
                                                    </thead>

                                             
                                                   <tbody>

                                              <?php $i=1; foreach($userList as $row){ 
                                                  
                                               //   $user = $this->admin_common_model->get_where('users',['id'=>$row['user_id']]);
                                                  
                                               ///   $ins = $this->admin_common_model->get_where('insentive_amount',['noti_id'=>$row['id']]);

                                              
                                              ?>

                                                        <tr>
                                                           
                                
                                
                                                            
                                                            <td><?= $i; ?></td>
                                                            
                                        <!--                     <td>
<?php 

 $ans= $row['user_id']; 

 $ans= explode(",",$ans);

foreach($ans as $row1){

                 $emp = $this->admin_common_model->get_where('users',['id'=>$row1]);


?>
                <?= "<span class='label label-primary'>".$emp[0]['first_name']."</span>"; ?>
<?php } ?>

</td>-->
                                                            <td><?= $row['code']; ?></td>
                                                            <td><?= $row['percentage']; ?></td>
                                                            <td><?= $row['end_date']; ?></td>
                                                            <td><?= $row['description']; ?></td>
                                                            <td><?= $row['description_ar']; ?></td>
                                                            <td><div class="col-sm-2">
                                                               <?php
                                                                if ($row['image'] == ''){
                                                                  $img_url = base_url('uploads/images/user.jpg');
                                                                }else{
                                                                  $img_url = base_url('uploads/images/'.$row['image']);
                                                                }
                                                              ?>
                                                              <img src="<?=$img_url;?>" alt="" width="50"> 
                                                            </div></td>
                                                            

 <td class="text-center"><a href="<?=base_url('admin/view_page/addCoupon/'.$row['id']);?>"><button class="btn view-t"><i class="fa  fa-edit"></i></a> </button>  <!--<a href="<?=base_url('admin/view_page/view_user/'.$row['id']);?>"><button class="btn view-t"><i class="fa  fa-eye"></i></a> </button> --><button class="btn delete-t"><i class="fa   fa-trash-o" onclick="deleteUsers('<?=$row["id"];?>')"></i></button></td>

  

                                                        </tr>
<?php $i++; } ?>

                                                    </tbody>
                                                </table>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                        </div> <!-- End Row -->

                    </div> <!-- container -->
                               
                </div> <!-- content -->

                <footer class="footer text-right">
                    2020 © Edamah.
                </footer>

            </div>
          
        </div>
        <!-- END wrapper -->
<script>
// delete function
function deleteUsers(id)
{
  swal({
  title: "Are you sure?",
  text: "You want to permanently remove this item!",
  type: "warning",
  showCancelButton: true,
  confirmButtonColor: "#DD6B55",
  confirmButtonText: "Yes, delete it!",
  closeOnConfirm: false
},
function(){



        $.ajax({
          url: "<?=base_url('admin/delete_data');?>",
          data: {'table': 'coupons', 'id': id}, // change this to send js object
          type: "POST",
          success: function(result){
            //alert(result);
            swal("Deleted!", "Your selected item has been deleted.", "success");
  
            $('.confirm').click(function(){
               location.reload();
            });
             

          }
        });

  

});

} 
// end delete function
// end delete function

</script>


 <?php include 'include/footer.php';?>
