private static function create_index($set_size, $page_size, $name = 'null') { require_once __DIR__ . '/Helpers.php'; // set get_name param if displaying by name if ($name !== 'null') { $get_name = 'true'; } else { $get_name = 'false'; } // set up div echo '<div class="zws-contacts-database-index">'; // echo the page numbers with their links for ($i = 1; $i <= self::$number_of_pages; $i++) { $page_url_query_string = \ZwsContactsDatabase\Helpers::set_url_query_cleared(array('show_all' => 'true', 'contacts_page' => $i, 'postback' => 'false', 'getname' => $get_name, 'lastname' => $name)); echo ' <a class="zws-contacts-database-display-index" style="' . Zelp::getCss('page_index') . '" href="' . $page_url_query_string . '">' . $i . '</a>'; } // end div echo '</div>'; return true; }
public static function display_nearest($target_postcode) { // check params have been passed if (!isset($target_postcode)) { return false; } require_once __DIR__ . '/DistanceCalculator.php'; require_once __DIR__ . '/Helpers.php'; $options = get_site_option(self::OPTIONS_LABEL); $success = false; $how_many_contacts = 5; $contacts_array = \ZwsContactsDatabase\DistanceCalculator::nearestContacts($how_many_contacts, $target_postcode); if ($contacts_array !== false) { $contacts_array_safe = []; // display the elements echo '<div class="contact-list"><h2>' . $how_many_contacts . ' Closest Contacts</h2>'; echo '<small><a href="' . \ZwsContactsDatabase\Helpers::set_url_query_cleared(array('postback' => 'false')) . '">Back to administration dashboard</a></small>'; // set variabe for earliest_time field corresponding to 'today' $days_of_week = array(1 => 'mondays', 2 => 'tuesdays', 3 => 'wednesdays', 4 => 'thursdays', 5 => 'fridays', 6 => 'saturdays', 7 => 'sundays'); $earliest_time_today = 'earliest_time_' . $days_of_week[current_time(date('N', time()))]; $latest_time_today = 'latest_time_' . $days_of_week[current_time(date('N', time()))]; foreach ($contacts_array as $key => $value) { // ensure variables from database are safe to output and add them to the contacts array. Only include contacts within their specified radius from target ... // ... only those who are available TODAY are returned from the DistanceCalculator::nearestContacts method, above. // ... ALL of TODAY's results (up to max results) are displayed, with the available times also printed. $contacts_array_safe[$key]['id'] = sanitize_text_field($value['id']); $contacts_array_safe[$key]['distance'] = apply_filters('zws_filter_enforce_numeric', $value['distance']); $contacts_array_safe[$key]['postcode'] = apply_filters('zws_filter_basic_sanitize', $value['postcode']); $contacts_array_safe[$key]['lat'] = apply_filters('zws_filter_basic_sanitize', $value['lat']); $contacts_array_safe[$key]['lng'] = apply_filters('zws_filter_basic_sanitize', $value['lng']); $contacts_array_safe[$key]['first_name'] = apply_filters('zws_filter_basic_sanitize', $value['first_name']); $contacts_array_safe[$key]['last_name'] = apply_filters('zws_filter_basic_sanitize', $value['last_name']); $contacts_array_safe[$key]['phone'] = apply_filters('zws_filter_enforce_numeric', $value['phone']); $contacts_array_safe[$key]['email'] = sanitize_email($value['email']); $contacts_array_safe[$key][$earliest_time_today] = apply_filters('zws_filter_basic_sanitize', $value[$earliest_time_today]); $contacts_array_safe[$key][$latest_time_today] = apply_filters('zws_filter_basic_sanitize', $value[$latest_time_today]); $contacts_array_safe[$key]['max_radius'] = apply_filters('zws_filter_enforce_numeric', $value['max_radius']); $contacts_array_safe[$key]['extra_info'] = nl2br(stripslashes(apply_filters('zws_filter_text_with_linebreak', $value['extra_info']))); } // add contacts array to map config $map_config['contacts_array_safe'] = $contacts_array_safe; // set up additional map config $map_config['target_postcode'] = $target_postcode; $map_config['contact_icon_url'] = apply_filters('zws_filter_basic_sanitize', $options['zws_contacts_database_plugin_map_contact_icon_url']); $map_config['target_icon_url'] = apply_filters('zws_filter_basic_sanitize', $options['zws_contacts_database_plugin_map_target_icon_url']); $map_config['base_icon_url'] = apply_filters('zws_filter_basic_sanitize', $options['zws_contacts_database_plugin_map_base_icon_url']); $map_config['base_postcode'] = apply_filters('zws_filter_sanitize_postcode', $options['zws_contacts_database_plugin_base_postcode']); $map_config['base_name'] = apply_filters('zws_filter_basic_sanitize', $options['zws_contacts_database_plugin_base_name']); $map_config['base_coordinates'] = $options['zws_contacts_database_plugin_base_coordinates']; $map_config['users_id'] = get_current_user_id(); $map_config['zoom'] = apply_filters('zws_filter_validate_integer', $options['zws_contacts_database_plugin_google_map_zoom']); // display the map if (self::display_map($map_config)) { $success = true; } echo '<ol class="contact-info-list">'; $c = 0; // counter to give each entry's available times fields a unique class name for jQuery foreach ($contacts_array_safe as $key => $value) { // display textual elements echo '<li style="margin-bottom:1em;">'; echo '<ul class="contact-info-list-inner">'; echo '<li>Distance from target: ' . $value['distance'] . ' miles</li>'; echo '<li>Name of contact: ' . stripslashes($value['first_name']) . ' ' . stripslashes($value['last_name']) . '</li>'; echo '<li>Postcode of contact: ' . $value['postcode'] . '</li>'; echo '<li>Phone of contact: <a href="tel:' . $value['phone'] . '">' . $value['phone'] . '</a></li>'; echo '<li>Email of contact: <a href="mailto:' . $value['email'] . '">' . $value['email'] . '</a></li>'; echo '<li>Extra notes: ' . $value['extra_info'] . '</li>'; echo '<li><button class="modal_opener_' . $c . '">View time that ' . $value['first_name'] . ' is available</button><div class="zws-contacts-db-times-available">' . '<ul class="contact-info-list-inner_' . $c . '">'; echo '<li>Earliest: ' . $value[$earliest_time_today] . '</li>'; echo '<li style="border-bottom:1px solid silver;">Latest: ' . $value[$latest_time_today] . '</li>'; echo '</ul></div></li>'; echo '</ul>'; echo '</li>'; $c++; } echo '</ol><div>'; } // return true if map has successfully displayed, otherwise false. return true ? $success : false; }