';print_r($_SESSION['user']);echo'';exit; $user_dealer_id = (isset($_SESSION['user']['dealer']) ? $_SESSION['user']['dealer'] : 0); $employee_id = $_SESSION['user']['employee_id']; $my_customer_record_id = $_SESSION['user']['id']; $granted_company_ids = $utility->isNotEmpty($_SESSION['user']['company_permissions_implode']) ? $_SESSION['user']['company_permissions_implode'] : '-1' ; // $fields_permissions = $utility->isNotEmpty($_SESSION['user']['fields_permissions']) ? $_SESSION['user']['fields_permissions'] : '-1' ; if(isset($_REQUEST['search'])){ $search = $db -> escape(trim($_REQUEST['search'])); $primary_search = $search_condition = (strlen($search) > 0 ? " AND (ltms.fullname LIKE '%" . $search . "%' OR ltms.cs_number like '%".$search."%' OR ltms.reference like '%".$search."%' )" : ""); }else{ $search=""; } $cs_filter=''; $filter_cs_number=''; if(isset($_REQUEST['cs_number']) && $_REQUEST['cs_number'] >0){ $cs_filter = $_REQUEST['cs_number']; if($cs_filter ==1) { $filter_cs_number = " AND (cs_number IS NOT NULL AND LENGTH(cs_number) > 1)"; } elseif ($cs_filter ==2) { $filter_cs_number = " AND cs_number IS NULL"; } } if(isset($_REQUEST['offset'])){ $offset = $db -> escape(trim($_REQUEST['offset'])); }else{ $offset=""; } if(isset($_REQUEST['my_records'])){ $my_record_bool = filter_var($_REQUEST['my_records'], FILTER_VALIDATE_BOOLEAN); if($my_record_bool){ $my_record=" AND (t1.upload_by='$my_customer_record_id' OR t1.modified_by='$my_customer_record_id') "; }else{ $my_record=""; } }else{ $my_record=""; } $customer_corporation = (isset($_REQUEST['customer_corporation']) && $_REQUEST['customer_corporation']) ? " AND t1.corporation_id = '".$_REQUEST['customer_id']."' " : "" ; if(isset($_REQUEST['limit'])){ $limit = $db -> escape(trim($_REQUEST['limit'])); if(isset($_REQUEST['grid'])){ $page = $_REQUEST['offset']; if($page){ $start = ($page - 1) * $limit; //first item to display on this page $offset = ($page - 1) * $limit; }else{ $start = 0; } } $offset_limit = " LIMIT ". $offset.",".$limit; // echo $offset_limit;exit; } else { $offset_limit = ""; } if(isset($_REQUEST['filter_age']) && $_REQUEST['filter_age'] != '0'){ switch($_REQUEST['filter_age']){ case "below": $age = "AND $where_age <= 30 "; break; case "between": $age = "AND $where_age <= 50 AND $where_age >= 31 "; break; case "above": $age = "AND $where_age >= 51 "; break; } } $customer_actions = "" ; if(isset($_REQUEST['customer_actions']) && $_REQUEST['customer_actions'] != '0'){ switch($_REQUEST['customer_actions']){ case "all": $customer_actions = ""; break; case "new": $customer_actions = " AND t1.date_uploaded > DATE_SUB(NOW(), INTERVAL 1 WEEK) "; break; case "updated": $customer_actions = " AND t1.date_modified > DATE_SUB(NOW(), INTERVAL 1 WEEK) "; break; case "added": $customer_actions = " AND t1.date_uploaded > DATE_SUB(NOW(), INTERVAL 1 DAY) "; break; } } $data_counter = 0; $json_arr['rows'] = array(); // $group_bys =" GROUP BY cua.user_id ORDER BY cua.id" ; // $query ="SELECT %s // FROM customer_upload_ltms as ltms // WHERE active =1 AND status =1 %s %s GROUP BY ltms.fullname ORDER BY ltms.id DESC "; $query ="SELECT %s FROM customer_upload_ltms as ltms WHERE active =1 AND status =1 %s %s GROUP BY ltms.reference ORDER BY ltms.id DESC "; $fields ="ltms.id,ltms.reference,ltms.fullname,ltms.cs_number,ltms.created_at,GROUP_CONCAT(ltms.filename SEPARATOR ',') as files"; $count = " 1 "; // echo (sprintf($query,$fields,$search,$search,$filter_email,$gender,$dms,$age ,$complete_data, $incomplete_data,$mobile_phone_1,$email_1,$address_1,$date_of_birth,$company,$customer_corporation,$customer_actions,$my_record,$type,$group_by)." $offset_limit");exit; $final_query = sprintf($query,$fields,$primary_search,$filter_cs_number)." $offset_limit"; // echo($final_query);exit; $exec_query = $db -> sql_query($final_query); $query_count = $db -> select("SELECT COUNT(*) FROM ( ".sprintf($query,$fields,$primary_search,$filter_cs_number)." ) as total_count"); $json_arr['total'] = $query_count; //total number of result if(isset($_REQUEST['grid'])){ $json_arr['customer_list'] = ""; $json_arr['customer_list_paging'] = ""; $total = intval($query_count);//100;//$json_arr['total']; /* Setup page vars for display. */ if ($page == 0) $page = 1; //if no page var is given, default to 1. $prev = $page - 1; //previous page is current page - 1 $next = $page + 1; //next page is current page + 1 $lastpage = ceil($total/$limit); //lastpage. $lpm1 = $lastpage - 1; //last page minus 1 $counter=0; $adjacents = 1; $lpm1 = $lastpage - 1; //last page minus 1 if($lastpage > 1) { $json_arr['customer_list_paging'] .= ""; if ($page > $counter+1) { $json_arr['customer_list_paging'].= "
  • "; } if ($lastpage < 7 + ($adjacents * 2)){ for ($counter = 1; $counter <= $lastpage; $counter++){ if ($counter == $page) $json_arr['customer_list_paging'].= "
  • $counter
  • "; else $json_arr['customer_list_paging'].= "
  • $counter
  • "; } } elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if($page < 1 + ($adjacents * 2)){ for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $json_arr['customer_list_paging'].= "
  • $counter
  • "; else $json_arr['customer_list_paging'].= "
  • $counter
  • "; } $json_arr['customer_list_paging'].= "
  • ...
  • "; $json_arr['customer_list_paging'].= "
  • $lpm1
  • "; $json_arr['customer_list_paging'].= "
  • $lastpage
  • "; } //in middle; hide some front and some back elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $json_arr['customer_list_paging'].= "
  • 1
  • "; $json_arr['customer_list_paging'].= "
  • 2
  • "; $json_arr['customer_list_paging'].= "
  • ...
  • "; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $json_arr['customer_list_paging'].= "
  • $counter
  • "; else $json_arr['customer_list_paging'].= "
  • $counter
  • "; } $json_arr['customer_list_paging'].= "
  • ...
  • "; $json_arr['customer_list_paging'].= "
  • $lpm1
  • "; $json_arr['customer_list_paging'].= "
  • $lastpage
  • "; } //close to end; only hide early pages else { $json_arr['customer_list_paging'].= "
  • 1
  • "; $json_arr['customer_list_paging'].= "
  • 2
  • "; $json_arr['customer_list_paging'].= "
  • ...
  • "; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $json_arr['customer_list_paging'].= "
  • $counter
  • "; else $json_arr['customer_list_paging'].= "
  • $counter
  • "; } } } //next button if ($page < $counter - 1) $json_arr['customer_list_paging'].= "
  • "; else $json_arr['customer_list_paging'].= ""; } if($total < 1){ $json_arr['customer_list_paging'] = "No Record"; } }else{ $allowed_access_ = ( isset($global_action_permissions['12']['2']) && in_array("1", $global_action_permissions['12']['2']) ? true : false); while($row = $exec_query->fetch_assoc()) { $file_urls = explode(',', $row['files']); // Create an array of image URLs $image_urls = implode(',', array_map(function($file) { return '../../dist/img/customer/ltms-customer-upload/' . $file; }, $file_urls)); // Generate the link to trigger the carousel modal with a count of the total images $file_links = ' (' . count($file_urls) . ') '; $tag_action = ' '; $json_arr['rows'][] = [ 'id' => $row['id'], 'reference_code' => $row['reference'], 'customer_name' => $row['fullname'], 'cs_number' => $row['cs_number'], 'file' => ($allowed_access_ ? $file_links : 'Restricted'), 'date_uploaded' => date('F d, Y', strtotime($row['created_at'])), 'action_tag' => ($allowed_access_ ? $tag_action : 'Restricted') ]; unset($row); } } echo json_encode($json_arr); function isNotEmpty($data){ return preg_match('/\S/', $data); } ?>