<!-- 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/exportStudentData?center_name=0&year=<?=(isset($_GET['year']) && $_GET['year'] !=''? $_GET['year']:'C-20');?>" 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;">
                    <select name="lstage" id="lstage" class="form-control input-height">
                        <option value="">Choose Lead Stage</option>
                         <?php $dispos = get_disposition('action'); ?>  
                        <?php foreach($dispos 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="lsource" id="lsource" class="form-control input-height">
                        <option value="">Choose Lead Source</option>
                         <?php $lead_source = get_lead_source_list();?>  
                        <?php foreach($lead_source as $value){ ?>
                            <option value="<?=$value['name'];?>" <?=(isset($_GET['lsource']) && $_GET['lsource']==$value['name'] ?'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;">
                    <select name="drange" id="drange" class="form-control input-height">
                        <option value="">Choose Date Range</option>
                         <option value="la" <?=(isset($_GET['drange']) && $_GET['drange']=='lastactivity' ?'selected':'');?>>Last Activity</option>
                         <option value="cd" <?=(isset($_GET['drange']) && $_GET['drange']=='cd' ?'selected':'');?>>Created Date</option>                                 
                    </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 id="countBox" class="row" style="display:none;margin: 10px 0px 10px 0px;">
                    <span id="selectedCountLabel">0 selected</span>	
                     <div class="col-sm-3">
                        <select name="assigned_to" id="assigned_to" 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"><button type="submit" id="assignBtn" class="btn btn-info">Submit</button></div>
            </div>
            <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><input id="checkAllLead" type="checkbox" aria-label="Select all leads"></th>
                                <th>Name</th>
                                <th>Lead Stage</th>
                                <th>Owner</th>                                
                                <th>Lead Source</th>                            
                                <th>Course</th> 
                                <th>City</th> 
                                <th>Created Date</th>
                                <th>Updated Date</th>                                
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>                        
        				<?php 
                         if(empty($lead_details)==FALSE){
                        $i=1; foreach ($lead_details as $key):?>        				
                            <tr data-id="<?=ucfirst($key->id);?>">
                                <td><input class="row-checkbox" type="checkbox" value="<?=ucfirst($key->id);?>"></td>                                       
                                <td><?=ucfirst($key->name);?></td>
                                <td><?='Open';?></td>                       
                                <td><?php $center_details    = get_center_by_id($key->user_id); 
                                ?>
                                    <?= ucfirst($center_details[0]['user_name'] ?? ''); ?>
                                </td>                      
                                <?php if ($user_type == 1 || $user_type == 2) { ?>  
                                     <td><?=$key->lead_source;?></td>
                                <?php }  ?>
                                <td><?=$key->course;?></td>                     
                                <td><?=$key->city;?></td>                     
                                <td><?=date('d-m-Y',strtotime($key->created_at));?></td>                       
                                <td><?=date('d-m-Y',strtotime($key->updated_at));?></td>                       
                                <td>
                                	<a href="<?=base_url();?>leads/lead_details/<?=$key->id; ?>" class="kt-badge kt-badge--brand kt-badge--inline kt-badge--pill" target="_blank">View
        							</a> 
                                </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>
