<!-- begin:: Subheader -->
<div class="kt-subheader   kt-grid__item" id="kt_subheader">
<div class="kt-container  kt-container--fluid ">
    <div class="kt-subheader__main">
        <div class="kt-subheader__breadcrumbs">
            <a class="kt-subheader__breadcrumbs-link">
                Leads </a>
            <span class="kt-subheader__breadcrumbs-separator"></span>
            <a class="kt-subheader__breadcrumbs-link">
                All Leads List </a>
            <span class="kt-subheader__breadcrumbs-separator"></span>
            
        </div>
    </div>
    <div class="kt-subheader__toolbar">        
        <a href="<?=base_url();?>scripts/exportLeadData?<?=(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] !=''? $_SERVER['QUERY_STRING']:'');?>" class="btn btn-label-brand btn-bold">
            <i class="flaticon-download"></i> Export to Excel</a>
    </div>                                        
</div>
</div>
<!-- end:: Subheader -->
<!-- begin:: Content -->
<div class="kt-container  kt-container--fluid  kt-grid__item kt-grid__item--fluid form-bg">
   <div class="kt-portlet">
      <div class="kt-portlet__body kt-portlet__body--fit">
        <div class="kt-portlet__body">        
        <form name="filter" method="get">          
            <div class="row justify-content-between">
                <div class="col-sm-3" style="margin-bottom: 10px;">
                    <input type="text" name="mobile" value="<?=(isset($_GET['mobile']) && $_GET['mobile']!='' ? $_GET['mobile']:'');?>" class="form-control" placeholder="Mobile No." aria-controls="kt_table_1" style="width: 100%;">
                </div>
                <div class="col-sm-3" style="margin-bottom: 10px;">
                    <input type="text" name="email" value="<?=(isset($_GET['email']) && $_GET['email']!='' ? $_GET['email']:'');?>" class="form-control" placeholder="Email Id" aria-controls="kt_table_1" style="width: 100%;">
                </div>
                <div class="col-sm-3" style="margin-bottom: 10px;">
                    <select name="course_id" id="course_id" class="form-control input-height">
                        <option value="">Choose Course</option>
                         <?php $courses = get_courses();?>  
                        <?php foreach($courses as $value){ ?>
                            <option value="<?=$value['id'];?>" <?=(isset($_GET['course_id']) && $_GET['course_id']==$value['id'] ?'selected':'');?>><?=$value['name'];?></option>
                        <?php } ?>                                  
                    </select>
                </div>
                <div class="col-sm-3" style="margin-bottom: 10px;">
                    <select name="user_id" id="user_id" class="custom-select">
                        <option value="">Choose Owner</option>
                        <?php $users = get_user_name_list(); ?>  
                        <?php foreach($users as $value){ ?>
                            <option value="<?=$value['uid'];?>" <?=(isset($_GET['user_id']) && $_GET['user_id']==$value['uid'] ?'selected':'');?>><?=ucfirst($value['user_name']);?></option>
                        <?php } ?>                                   
                    </select>
                </div>
                <div class="col-sm-3" style="margin-bottom: 10px;">
                    <input type="text" name="cdate_from" class="form-control" placeholder="Assigned Date From" aria-controls="kt_table_1" id="datepicker" value="<?=(isset($_GET['cdate_from']) && $_GET['cdate_from']!='' ? $_GET['cdate_from']:'');?>"autocomplete="off" >
                </div>
                <div class="col-sm-3" style="margin-bottom: 10px;">
                    <input type="text" name="cdate_to" class="form-control" placeholder="Assigned Date To" aria-controls="kt_table_1" id="datepicker1" value="<?=(isset($_GET['cdate_to']) && $_GET['cdate_to']!='' ? $_GET['cdate_to']:'');?>" autocomplete="off">
                </div>
                <div class="col-sm-3" style="margin-bottom: 10px;">
                    <select name="page" aria-controls="kt_table_1" class="custom-select form-control form-control-sm">
                        <option value="">Show Entries</option>
                        <option value="10" <?=(isset($_GET['page']) && $_GET['page']=='10' ?'selected':'');?>>10</option>
                        <option value="25" <?=(isset($_GET['page']) && $_GET['page']=='25' ?'selected':'');?>>25</option>
                        <option value="50" <?=(isset($_GET['page']) && $_GET['page']=='50' ?'selected':'');?>>50</option>
                        <option value="100" <?=(isset($_GET['page']) && $_GET['page']=='100' ?'selected':'');?>>100</option>
                    </select>
                </div>
                <div class="col-sm-3" style="margin-bottom: 10px;">
                    <button type="submit" class="btn btn-info" style="width: 100%;">Apply</button>
                </div>
            </div>
        </form>
            <div class="row">
                <div class="col-sm-12">
                <table class="table table-striped- table-bordered table-hover table-checkable" id="">
                        <thead>
                            <?php $user_type = session()->get('user_type'); ?>
                            <tr>                                                    
                                <th>Lead No.</th>
                                <th>Name</th>
                                <th>Mobile No</th>
                                <th>Email ID</th>                                
                                <th>City</th>                                
                                <th>State</th>                                                               
                                <?php if ($user_type == 1 || $user_type == 2) { ?>  
                                     <th>Lead Source</th>  
                                <?php }  ?> 
                                <th>Assigned Date</th>                               
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>                        
        				<?php 
                         if(empty($lead_details)==FALSE){
                        $i=1; foreach ($lead_details as $key):?>        				
                            <tr>
                                <td><?=ucfirst($key->id);?></td>                                       
                                <td><?=ucfirst($key->name);?></td>
                                <td><?=ucfirst($key->phone);?></td>
                                <td><?=$key->email;?></td>                       
                                <td><?=$key->city;?></td>                       
                                <td><?=$key->state;?></td>  
                                <?php if ($user_type == 1 || $user_type == 2) { ?>  
                                     <td><?=$key->lead_source;?></td>
                                <?php }  ?>                     
                                <td><?=date('d-m-Y',strtotime($key->created_at));?></td>                       
                                <td>
                                	<a href="<?=base_url();?>leads/lead_details/<?=$key->id; ?>" class="kt-badge kt-badge--brand kt-badge--inline kt-badge--pill">View
        							</a>                             
        							<?php
        							if ($user_type == 1 || $user_type == 2) {
        							?>	
                                    <a href="<?=base_url();?>leads/edit_lead/<?=$key->id; ?>" class="kt-badge  kt-badge--info kt-badge--inline kt-badge--pill">Edit</a>			
        							<a href="javascript:confirmDelete('<?=base_url();?>leads/delete_lead/<?=$key->id; ?>')" class="kt-badge  kt-badge--danger kt-badge--inline kt-badge--pill">Delete</a>
        							<?php }else{ ?>
                                    <?php if($key->form !='1'){ ?>
                                    <a href="<?=base_url();?>leads/edit_lead/<?=$key->id; ?>" class="kt-badge  kt-badge--info kt-badge--inline kt-badge--pill">Edit</a>
                                <?php }} ?>
                                </td>
                            </tr>
                            <?php $i++; endforeach ?>
                        <?php } else{ ?>
                            <tr class="odd"><td valign="top" colspan="13" style="color: #595d6e;text-align: center;">No matching records found.</td></tr>
                        <?php } ?>
                         </tbody>
                    </table>
                </div>               
            </div>
           <div class="row">
               <div class="col-sm-12 col-md-5">
                  <div class="dataTables_info" id="kt_table_1_info" role="status" aria-live="polite">
                    <?=$showing_result;?>

                  </div>
               </div>
               <div class="col-sm-12 col-md-7">
                  <div class="dataTables_paginate paging_full_numbers" id="kt_table_1_paginate">
                     <?=$paging;?>
                  </div>
               </div>
            </div>
        </div>
      </div>
   </div>
</div>
