<?php 

$pageTitle = 'Products';
$buttonAction ='';$buttonName = 'Reset';

if($this->input->get()){
	$buttonName = 'Back To List';
	$backUrl = base_url().'admin/'.$categoryFor;
    $buttonAction = "window.location.href='".$backUrl."'";
}
$PER_PAGE = $GLOBALS['PER_PAGE'];
$page = 20;

if($this->input->cookie('perPage',true)){
  $page = $this->input->cookie('perPage',true);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title><?php echo $pageTitle ?> List - ACP -<?php echo site_name(); ?></title>

<?php $this->load->view('admin/ap_top'); ?>

<script type="text/javascript">

 function doActionFn(action,id){
	 if(action == 'edit' || action == 'view'){
		window.location= '<?php echo base_url('admin/'.$categoryFor.'/manager/'); ?>'+action+'/'+id;
	}
	else if(action == 'mapquestprod'){
		window.location= '<?php echo base_url('admin/'.$categoryFor.'/mapquestprod/'); ?>'+id;
	}
	else{
		 $('#doAction').val(action);	
 		 if(id != 'all' && $('#checked_'+id).length){
			 $('.checkedAll').prop('checked',false); 	
			 $('#checked_'+id).prop('checked',true); 
		  }
		 var checkBox = false;
		$.each($("input[name='p_ids[]']:checked"), function() {
			checkBox =  true;
		});
 		 if(checkBox == false){
			$('#showActionErr').html(' <div class="alert alert-danger alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button> Please select at least one item </div>');	 
 			return false;
		 }
		 if(action == 'delete'){
			if (confirm("Are you sure you want to delete?")) {
				$('#listFrm').submit();
			}	
		} else{
			$('#listFrm').submit();
		}
 	}
  }

</script>

</head>

<body>
    
    <div class="wrapper" >
        <?php $this->load->view('admin/navbar'); ?>
            
		<div class="main-panel main-panel-custom">
		    <div class="content">
				<div class="page-inner">
					<div class="page-header">
						<h4 class="page-title"><?php echo $categoryForPage;?></h4>
						<ul class="breadcrumbs">
							<li class="nav-home">
								<a href="<?php echo base_url('admin/dashboard');?>">
									<i class="flaticon-home"></i>
								</a>
							</li>
							<li class="separator">
								<i class="flaticon-right-arrow"></i>
							</li>
							<li class="nav-item">
								<a href="#"><?php echo $pageTitle; ?> List</a>
							</li>
							
						</ul>
					</div>
                    <div class="row">
						<div class="col-md-12">
							<div class="card">
								
								<div class="card-header">
								    <div class="card-head-row">
									    <h4 class="card-title"><?php echo $pageTitle; ?> List</h4>
									    
									    <div class="card-tools">
											<ul class="nav nav-pills nav-secondary nav-pills-no-bd " role="tablist">
											    <li class="nav-item">
										            <a class="nav-link active" style="background: #28a745;!important"  href="<?php echo base_url('admin/'.$categoryFor.'/manager/') ?>"> <i class="fa fa-plus"></i>&nbsp; Add New Product</a>
									            </li>
									            <!--<li class="nav-item">-->
										           <!-- <a class="nav-link active" style="background: #007bff;!important"  href="app_export.php"> <i class="fas fa-file-export"></i>&nbsp; Export</a>-->
									            <!--</li>-->
									            <!--<li class="nav-item">-->
									                <!--<a class="nav-link active btn-refresh-card" style="background: #007bff;!important">Reload</a>-->
										           <!-- <button id="table-refresh" class="nav-link active btn-refresh-card btn-refresh-card" ><span class="fa fa-sync-alt"></span></button>-->
									            <!--</li>-->
											</ul>
										</div>
									</div>
								</div>
								
								<!--notifiactions-->
    							<div class="container" id="">
                                    <?php 
                             		$errMsg = validation_errors('* ');
                            		if(empty($errMsg)){ $errMsg = $this->session->flashdata('errMsg');  }
                            		$warningMsg = $this->session->flashdata('warningMsg');
                            		$successMsg = $this->session->flashdata('successMsg');
                            		if(isset($errMsg) && !empty($errMsg)){ echo showMessage($errMsg,'error'); }  
                            		if(isset($warningMsg) && !empty($warningMsg)){ echo showMessage($warningMsg,'warning'); }
                            		if(isset($successMsg) && !empty($successMsg)){ echo showMessage($successMsg,'success'); }
                            	?>
                                </div>
                                
                                <div class="container" id="showActionErr"></div>
                                <!--notifiactions-->
								
								<div class="card-body">
								    
								     <div class="row">
                                            <div class="col-md-12 " style="padding: 0rem 1.25rem;">
                                                <!--<div class="text-left">-->
                                                  <!--<h3>Search</h3>-->
                                                <!--</div>-->
                                                <?php     echo form_open( 'admin/'.$categoryFor,array('name' => 'searchFrm', 'id' => 'searchFrm','method' => 'get')); ?>
                                                <div class="row">
                                                  <div class="form-group col-md-2"  >
                                                    <label for="searchKey">Search Key</label>
                                                    <?php   $data = array( 'name' => 'searchKey','value' => set_value('searchKey',$this->input->get('searchKey',true)),  'id' => 'searchKey',  'placeholder'   => '', 'class' => 'form-control required', );
                                     						 echo form_input($data);
                                    					?>
                                                  </div>
                                                  <div class="form-group col-md-3"   >
                                                    <label for="searchBy">Search By</label>
                                                    <?php  
                                    				$arrSearchBy = array(''=>'Select','p_id'=>'Product Id', 'title'=>'Title ','title_slug'=>'Title Slug');
                                    				$js = 'class="form-control" id="searchBy"  '; 
                                    				echo form_dropdown('searchBy', $arrSearchBy,set_value('searchBy',$this->input->get('searchBy',true)), $js); 
                                    		        ?>
                                                  </div>
                                                  
                                                  <div class="form-group col-md-2" >
                                                    <label for="daterange_By">Date Range By</label>
                                                    <div class="input-icon ">
                                                        <?php
                                                        if($this->input->get('daterange_By',true)){
                                                            $set_Date_value=$this->input->get('daterange_By',true);
                                                        }else $set_Date_value='';
                                                        
                                                            $data = array( 'name' => 'daterange_By','autoComplete' => 'off',
                                                            'value' => set_value('daterange_By',$set_Date_value), 
                                                            'id' => 'daterange_By',  'class' => 'form-control', );
                                     						 echo form_input($data);
                                    					?>
                                                        
                                                    </div>
                                                  </div>
                                                  <div class="form-group col-md-2"   >
                                                    <label for="searchStatus">Status</label>
                                                    <?php  
                                        		        $arrSearchBy = array('all'=>'All','Disabled'=>'Disabled','Enabled'=>'Enabled');
                                        		        $js = 'class="form-control" id="searchStatus"  '; 
                                          				 echo form_dropdown('searchStatus', $arrSearchBy,set_value('searchStatus',$this->input->get('searchStatus',true)), $js); 
                                    					?>
                                                  </div>
                                                </div>
                                                <div class="row">
                                                  <div class="form-group col-md-12">
                                                    <?php   $data = array( 'name' => 'myAccountBtn','value' => 'true', 'id' => 'myAccountBtn',  'type' => 'submit','content' => 'Search', 'class' => 'btn btn-success btn-sm',   );
                                     				echo form_button($data);
                                    				$data = array( 'name' => 'resetAgrmtBtn','value' => 'true', 'id' => 'resetAgrmtBtn',  'type' => 'reset','content' => $buttonName, 'class' => 'btn btn-warning btn-sm','onClick' => $buttonAction   );
                                    				echo '&nbsp;';
                                     				echo form_button($data) ;
                                     				?>
                                                  </div>
                                                </div>
                                                <?php echo form_close();?>
                                            </div>
                                      </div>
								   
                        		    <div class="btn-wrapper text-center d-flex justify-content-between">
                        		        <div class="d-flex align-items-center">
                        		            <h4 class="card-title"> <?php echo $pageTitle; ?> List</h4>
                        		        </div>
                        		        <div class="d-flex align-items-center">
                        		             <form action="<?php echo $_SERVER['REQUEST_URI']?>" name="perPageForm" method="post">
                        		                 <input type="hidden" name="listUrl" value="admin/<?php echo $categoryFor ?>">
                                              <?php  
                                				
                                				$js = 'class="form-control" id="perPage" style="width:auto;" onchange="this.form.submit()"  '; 
                                				echo form_dropdown('perPage', $PER_PAGE, set_value('perPage',$page), $js); 
                                			?>
                                            </form>
                        		        </div>
                        		    </div>
                  
                        		        <?php
                        					$listUrl = base_url('admin/'.$categoryFor.'?'); 
                        				  if($this->input->get()){
                        					 $arrGet = $this->input->get(); unset($arrGet['per_page']);
                        					 $listUrl   = base_url('admin/'.$categoryFor).'?'.  http_build_query($arrGet);
                          					}
                         					$GLOBALS['ARR_ACP_PAGIN_CONF']['base_url'] = $listUrl;
                        					$GLOBALS['ARR_ACP_PAGIN_CONF']['per_page'] = $this->admin_product_model->limit;	
                        					$total_rows = $GLOBALS['ARR_ACP_PAGIN_CONF']['total_rows'] = $this->admin_product_model->getProductList('count',$resourceFor);	
                         					$this->pagination->initialize($GLOBALS['ARR_ACP_PAGIN_CONF']);
                                           $arrList = $this->admin_product_model->getProductList('list',$resourceFor);
                                           
                        					$listUrl1 = "";
                        					$sortBy = 'registerDate';$sortOrder = 'desc';
                        					 if($this->input->get('sortBy',true) && $this->input->get('sortOrder',true)){
                        						 $sortBy = $this->input->get('sortBy',true);$sortOrder = $this->input->get('sortOrder',true);
                        					 }
                        					if(isset($arrGet)){
                        						unset($arrGet['sortBy']); unset($arrGet['sortOrder']);
                        						 $listUrl  = base_url('admin/'.$categoryFor).'?'. http_build_query($arrGet);
                        						 $listUrl1  = 'admin/'.$categoryFor.'?'. http_build_query($arrGet);
                        					}
  							            ?>
                        		    <div class="btn-wrapper text-center d-flex justify-content-between">
                        		        <div class="d-flex align-items-center">
                        		            <h4 class="card-title"> Total <?php echo $pageTitle;?> : <?php echo $total_rows;?></h4>
                        		        </div>
                        		        <div class="d-flex align-items-center">
                        		             <div class="form-group col-md-4">
                                                  <div class="">
                                                    <?php  echo $this->pagination->create_links();  ?>
                                                  </div>
                                            </div>
                        		        </div>
                        		    </div>
                        		    
                        		    <?php     
                        		        echo form_open('admin/'.$categoryFor ,array('name' => 'listFrm', 'id' => 'listFrm'));
                            		  	echo form_input(array('name' => 'doAction', 'type'=>'hidden', 'id' =>'doAction'));
                        		    ?>
							        <div class="table-responsive">
										<table id="feedback_list_table" class="display table table-striped table-hover table-bordered " >
										    
											<thead>
 					                            <input type="hidden" name="listUrl" value="<?php echo $listUrl1 ?>">
                                                <tr>
                                                    <th ><?php $data = array( 'name' => 'checkedAll', 'id' => 'checkedAll',  ); echo form_checkbox($data);?>
                                                    </th>
                                                    <th>#</th>
                                                    <th onClick="doSort('p_id','<?php echo $listUrl;?>');">P.ID <i class="fas <?php if($sortBy != 'p_id')echo 'fa-sort';else if($sortOrder == 'desc')echo 'fa-sort-up'; else echo 'fa-sort-down'; ?> " id="sort_p_id" ></i></th>
                                                    <th onClick="doSort('title','<?php echo $listUrl;?>');">Title<i class="fas <?php if($sortBy != 'title')echo 'fa-sort';else if($sortOrder == 'desc')echo 'fa-sort-up'; else echo 'fa-sort-down'; ?> " id="sort_title" ></i></th>
                                                    <th onClick="doSort('title_slug','<?php echo $listUrl;?>');">Title Slug<i class="fas <?php if($sortBy != 'title_slug')echo 'fa-sort';else if($sortOrder == 'desc')echo 'fa-sort-up'; else echo 'fa-sort-down'; ?> " id="sort_title_slug" ></i></th>
                                                    <th>Product link</th>
                                                    <th>Redirect link</th>
                                                    <th>Action</th>
                                                    <th onClick="doSort('created_at','<?php echo $listUrl;?>');">Created <i class="fas  <?php if($sortBy != 'created_at')echo 'fa-sort';else if($sortOrder == 'desc')echo 'fa-sort-up'; else echo 'fa-sort-down'; ?> " id="sort_created_at" ></i></th>
                                                    
                                                    <th>Status</th>
                                                </tr>
											</thead>
										
											<tbody>
									            <?php
                         					    if($arrList){
                        						 
                        						    $sno = (($this->admin_product_model->page) * $this->admin_product_model->limit)+1;
                    						        foreach($arrList as $objRow){
                        							?>
                                                        <tr>
                                                            <td>
                                                                <?php 
                                                                $data = array( 'name' => 'p_ids[]','id' => 'checked_'.$objRow->p_id, 'value' => set_value('p_ids[]',$objRow->p_id),  'class' => 'checkedAll', ); 
                                                                echo form_checkbox($data);
                                                                ?>
                                                            </td>
                                           
                                                            <td><?php echo $sno;?></td> 
                                                            <td><?php echo $objRow->p_id;?></td>
                                                            <td><?php echo $objRow->title;?></td>
                                                            <td><?php echo $objRow->title_slug;?></td>
                                                            
                                                            <td>
                                                                <?php
                                            				        if(isset($objRow->title_slug)&&!empty($objRow->title_slug)){
                                            				            $url = PROMO_SITE_LINK_BASE_URL;
                                                                        $url_Set =  $url.$objRow->title_slug;
                                            				            echo '<a href="'.$url_Set.'" target="_blank"> Open </a>&nbsp;&nbsp;';
                                            				            ?>
                                            				            <!--<div class="s_copy" >-->
                                            				              <button type="button" class="btn btn-primary btn-xs " 
                                            				              data-toggle="tooltip" title="Copy" onClick="copyToClipboard_URL(this)" data-copy_url="<?php echo $url_Set; ?>" >
                                            				                  <i class="fa fa-copy"></i>
                                            				              </button>
                                                                        <!--</div>-->
                                            				            <?php
                                            				        }else{
                                            				            echo '-';
                                            				        }
                                            				    ?>
                                                            </td>
        
                                                            <td style="white-space:normal">
                                                                <?php
                                                                echo $objRow->red_link;
                                                                ?>
                                                            </td>
                                                            <td>
                                                                <?php 
                                									if($objRow->is_active == 1){
                                										$enabled = 'disabled';
                                									} else $enabled = ''; 
                                									
                                									if($objRow->is_active == 0){
                                										$disabled = 'disabled';
                                									} else $disabled = '';
                            									?>
                        									    <div class="form-button-action">
                                            					<button type="button" onClick="doActionFn('view','<?php echo $objRow->p_id;?>');" data-toggle="tooltip" title="View" 
                                            					class="btn btn-link btn-info " style="padding: 0.65rem 1rem;" data-original-title="View">
                                            						<i class="fa fa-info"></i>
                                            					</button>
                                            				    
                                            				    <button type="button" onClick="doActionFn('mapquestprod','<?php echo $objRow->p_id;?>');" data-toggle="tooltip" title="Map Questions" 
                                            					    class="btn btn-link btn-success " style="padding: 0.65rem 1rem;" data-original-title="Map Questions">
                                            						<i class="fas fa-folder fa-lg"></i>
                                            					</button>
                                            					
                                            					<button type="button" onClick="doActionFn('edit','<?php echo $objRow->p_id;?>');" data-toggle="tooltip" title="Edit" 
                                            					class="btn btn-link btn-primary" style="padding: 0.65rem 1rem;" data-original-title="Edit">
                                            						<i class="fas fa-pencil-alt"></i>
                                            					</button>
                                            					
                                            					<button type="button" onClick="doActionFn('delete','<?php echo $objRow->p_id;?>');" data-toggle="tooltip" title="Delete" 
                                            					class="btn btn-link btn-danger delbtn" style="padding: 0.65rem 1rem;" data-original-title="Delete">
                                            						<i class="fas fa-trash"></i>
                                            					</button>
                                            					
                                            					<!--<button type="button" <?php //echo $disabled; ?> onClick="doActionFn('enable','<?php //echo $objRow->p_id;?>');" data-toggle="tooltip" title="Enable" -->
                                            					<!--class="btn btn-sm btn-icon btn-round btn-success " data-original-title="Enable">-->
                                            					<!--	<i class="fa fa-check "></i>-->
                                            					<!--</button>-->
                                            					
                                            					<!--<button type="button" <?php //echo $enabled; ?> onClick="doActionFn('disable','<?php //echo $objRow->p_id;?>');" data-toggle="tooltip" title="Disable" -->
                                            					<!--class="btn btn-sm btn-icon btn-round btn-warning" data-original-title="Disable">-->
                                            					<!--	<i class="fas fa-ban"></i>-->
                                            					<!--</button>-->
                                            				</div>
    									                    </td>
    								                        <td><?php echo date_format(date_create($objRow->created_at),"d-m-Y") ; ?></td>
                								            <td>
                                                                <?php 
                                                                // far fa-check-circle
                                                                if($objRow->is_active == 0)
                                                                {
                                                                    echo '<button type="button" data-toggle="tooltip" data-original-title="Enable" title="Enable" 
                                                                            class="btn btn-xs btn-icon btn-round btn-success">
                                											<i class="fa fa-check"></i>
                                										    </button>';
                                                                }
                                                                else
                                                                {
                                                                    echo '<button type="button" data-toggle="tooltip" data-original-title="Disable" title="Disable" 
                                                                            class="btn btn-xs btn-icon btn-round btn-warning">
                                											<i class="fas fa-ban"></i>
                                										</button>';
                                                                }
                                                                ?>
                                                            </td>
                                                    </tr>
                                                    <?php	
                        							$sno++;
                        						    }	 
					                            }else{
						                        ?>
                                                <tr>
                                                    <td colspan="9" align="center">No records</td>
                                                </tr>
                                                <?php	 
                            					}
			                                    ?>
											</tbody>
										</table>
									</div>
									<?php echo form_close();?>
								</div>
    
                                <div class="card-footer ">
								     <div class="btn-wrapper text-center d-flex justify-content-between">
                        		        <div class="d-flex align-items-center">
                        		            <h4 class="card-title"></h4>
                        		        </div>
                        		        <div class="d-flex align-items-center">
                        		             <div class="form-group col-md-4">
                                                  <div class="">
                                                    <?php  echo $this->pagination->create_links();  ?>
                                                  </div>
                                            </div>
                        		        </div>
                        		    </div>
								    <div class="btn-wrapper text-center d-flex justify-content-between">
								        <div class="d-flex align-items-center">
											<label for="inlineinput" class="col-form-label "> With Selected &nbsp;&nbsp;&nbsp;&nbsp; </label>
											<div class="p-0">
											    <button type="button" class="btn btn-success btn-sm btn-enable"   title="Enable" onClick="doActionFn('enable','all');"> <i class="far fa-check-circle"></i> Enable </button>
											    <button type="button" class="btn btn-warning btn-sm btn-disable"  title="Disable" onClick="doActionFn('disable','all');"> <i class="fas fa-ban"></i> Disable</button>
                                                <button type="button" class="btn btn-danger btn-sm  btn-delete " title="Delete" onClick="doActionFn('delete','all');"> <i class="fas fa-trash"></i> Delete</button>
											</div>
										</div>
										<div class="d-flex align-items-center">
											<form action="<?php echo $_SERVER['REQUEST_URI']?>" name="perPageForm" method="post">
											    <input type="hidden" name="listUrl" value="admin/<?php echo $categoryFor ?>">
                                                <?php
                                    				$js = 'class="form-control" id="perPage" style="width:auto;" onchange="this.form.submit()"  '; 
                                    				echo form_dropdown('perPage', $PER_PAGE,set_value('perPage',$page), $js); 
                                    			?>
                                            </form>
										</div>
                                    </div>
                                </div>
							</div>
						</div>
					</div>
				</div>
			</div>
		    <!--<footer class="footer">-->
			    <?php //footer();?>
			<!--</footer>-->
		</div>
	</div>

</body>


<script>
    function copyToClipboard_URL(event)
    {
        c_url = $(event).data('copy_url');
        
        const input = document.createElement('input')
        
        input.value = c_url;
        document.body.appendChild(input)
        input.select()
        document.execCommand('Copy')
        document.body.removeChild(input)

        // $(".copy_txtc_u").css("font-weight",'900');
        // $(".copy_txtc_u").text("Copied!");
        $(event).attr('title', 'Copied');
        $(event).attr('data-original-title','Copied');
        
        // $(event).tooltip('show');
        // setTimeout(() => { $(".copy_txtc_u").text("Copy URL"); $(".copy_txtc_u").css("font-weight",'400'); }, 1500);
        setTimeout(() => { $(event).attr('title', 'Copy'); $(event).attr('data-original-title','Copy'); }, 4000);
        
    }
</script>

</html>
