* @license : GPL2 * */ if (defined('ABSPATH') === false) { exit; } global $wpdb; $tableName = $wpdb->prefix.'chaty_contact_form_leads'; $paged = filter_input(INPUT_GET, 'paged'); $current = isset($paged)&&!empty($paged)&&is_numeric($paged)&&$paged > 0 ? $paged : 1; $current = intval($current); $searchFor = "all_time"; $searchList = [ 'today' => esc_html__('Today', 'chaty'), 'yesterday' => esc_html__('Yesterday', 'chaty'), 'last_7_days' => esc_html__('Last 7 Days', 'chaty'), 'last_30_days' => esc_html__('Last 30 Days', 'chaty'), 'this_week' => esc_html__('This Week', 'chaty'), 'this_month' => esc_html__('This Month', 'chaty'), 'all_time' => esc_html__('All Time', 'chaty'), 'custom' => esc_html__('Custom Date', 'chaty') ]; $searchFor = filter_input(INPUT_GET, 'search_for'); if (isset($searchFor) && !empty($searchFor) && isset($searchList[$searchFor])) { $searchFor = esc_attr($searchFor); } else { $searchFor = "all_time"; } $startDate = ""; $endDate = ""; if ($searchFor == "today") { $startDate = gmdate("Y-m-d"); $endDate = gmdate("Y-m-d"); } else if ($searchFor == "yesterday") { $startDate = gmdate("Y-m-d", strtotime("-1 days")); $endDate = gmdate("Y-m-d", strtotime("-1 days")); } else if ($searchFor == "last_7_days") { $startDate = gmdate("Y-m-d", strtotime("-7 days")); $endDate = gmdate("Y-m-d"); } else if ($searchFor == "last_30_days") { $startDate = gmdate("Y-m-d", strtotime("-30 days")); $endDate = gmdate("Y-m-d"); } else if ($searchFor == "this_week") { $startDate = gmdate("Y-m-d", strtotime('monday this week')); $endDate = gmdate("Y-m-d"); } else if ($searchFor == "this_month") { $startDate = gmdate("Y-m-01"); $endDate = gmdate("Y-m-d"); } else if ($searchFor == "custom") { $startDate = filter_input(INPUT_GET, 'start_date'); if (!empty($startDate)) { $startDate = esc_attr($startDate); } else { $startDate = ""; } $endDate = filter_input(INPUT_GET, 'end_date'); if (!empty($endDate)) { $endDate = esc_attr($endDate); } else { $endDate = ""; } }//end if $hasSearch = filter_input(INPUT_GET, 'search'); $hasSearch = isset($hasSearch)&&!empty($hasSearch) ? $hasSearch : false; $query = "SELECT count(id) as total_records FROM ".$tableName; $search = ""; $condition = ""; $conditionArray = []; if ($hasSearch !== false) { $search = $hasSearch; $hasSearch = '%'.esc_sql($hasSearch).'%'; $condition .= " (name LIKE %s OR email LIKE %s OR phone_number LIKE %s OR message LIKE %s)"; $conditionArray[] = $hasSearch; $conditionArray[] = $hasSearch; $conditionArray[] = $hasSearch; $conditionArray[] = $hasSearch; } $startDate = esc_attr($startDate); $endDate = esc_attr($endDate); if (!empty($startDate) && !empty($endDate)) { if (!empty($condition)) { $condition .= " AND "; } $cStartDate = gmdate("Y-m-d 00:00:00", strtotime($startDate)); $cEndDate = gmdate("Y-m-d 23:59:59", strtotime($endDate)); $condition .= " created_on >= %s AND created_on <= %s"; $conditionArray[] = $cStartDate; $conditionArray[] = $cEndDate; } if (!empty($condition)) { $query .= " WHERE ".$condition; } $query .= " ORDER BY ID DESC"; if (!empty($conditionArray)) { $query = $wpdb->prepare($query, $conditionArray); } $totalRecords = $wpdb->get_var($query); $perPage = 15; $totalPages = ceil($totalRecords / $perPage); $query = "SELECT * FROM ".$tableName; if (!empty($condition)) { $query .= " WHERE ".$condition; } if ($current > $totalPages) { $current = 1; } $startFrom = (($current - 1) * $perPage); $query .= " ORDER BY ID DESC"; $query .= " LIMIT $startFrom, $perPage"; if (!empty($conditionArray)) { $query = $wpdb->prepare($query, $conditionArray); } ?>