Exemplo n.º 1
0
 function inline_edit()
 {
     $safe_date_format = $this->safe_date_format();
     // Make a locale check to update locale_error flag
     $date_check = $this->to_us(date_i18n($safe_date_format, strtotime('today')));
     global $wpdb;
     $app_id = $_POST["app_id"];
     if ($app_id) {
         $app = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->app_table} WHERE ID=%d", $app_id));
         $start_date_timestamp = date("Y-m-d", strtotime($app->start));
         if ($this->locale_error) {
             $start_date = date($safe_date_format, strtotime($app->start));
         } else {
             $start_date = date_i18n($safe_date_format, strtotime($app->start));
         }
         $start_time = date_i18n($this->time_format, strtotime($app->start));
         $end_datetime = date_i18n($this->datetime_format, strtotime($app->end));
         // Is this a registered user?
         if ($app->user) {
             $name = get_user_meta($app->user, 'app_name', true);
             if ($name) {
                 $app->name = $app->name && !(defined('APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES') && APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES) ? $app->name : $name;
             }
             $email = get_user_meta($app->user, 'app_email', true);
             if ($email) {
                 $app->email = $app->email && !(defined('APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES') && APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES) ? $app->email : $email;
             }
             $phone = get_user_meta($app->user, 'app_phone', true);
             if ($phone) {
                 $app->phone = $app->phone && !(defined('APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES') && APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES) ? $app->phone : $phone;
             }
             $address = get_user_meta($app->user, 'app_address', true);
             if ($address) {
                 $app->address = $app->address && !(defined('APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES') && APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES) ? $app->address : $address;
             }
             $city = get_user_meta($app->user, 'app_city', true);
             if ($city) {
                 $app->city = $app->city && !(defined('APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES') && APP_USE_LEGACY_ADMIN_USERDATA_OVERRIDES) ? $app->city : $city;
             }
         }
     } else {
         $app = new stdClass();
         // This means insert a new app object
         /*
         //DO NOT DO THIS!!!!
         //This is just begging for a race condition issue >.<
         			// Get maximum ID
         			$app_max = $wpdb->get_var( "SELECT MAX(ID) FROM " . $this->app_table . " " );
         			// Check if nothing has saved yet
         			if ( !$app_max )
         				$app_max = 0;
         			$app->ID = $app_max + 1 ; // We want to create a new record
         */
         $app->ID = 0;
         // Set other fields to default so that we don't get notice messages
         $app->user = $app->location = $app->worker = 0;
         $app->created = $app->end = $app->name = $app->email = $app->phone = $app->address = $app->city = $app->status = $app->sent = $app->sent_worker = $app->note = '';
         // Get first service and its price
         $app->service = $this->get_first_service_id();
         $_REQUEST['app_service_id'] = $app->service;
         $_REQUEST['app_provider_id'] = 0;
         $app->price = $this->get_price();
         // Select time as next 1 hour
         $start_time = date_i18n($this->time_format, intval(($this->local_time + 60 * $this->get_min_time()) / 3600) * 3600);
         $start_date_timestamp = date("Y-m-d", $this->local_time + 60 * $this->get_min_time());
         // Set start date as now + 60 minutes.
         if ($this->locale_error) {
             $start_date = date($safe_date_format, $this->local_time + 60 * $this->get_min_time());
         } else {
             $start_date = date_i18n($safe_date_format, $this->local_time + 60 * $this->get_min_time());
         }
     }
     $html = '';
     $html .= '<tr class="inline-edit-row inline-edit-row-post quick-edit-row-post">';
     if (isset($_POST["col_len"])) {
         $html .= '<td colspan="' . $_POST["col_len"] . '" class="colspanchange">';
     } else {
         $html .= '<td colspan="6" class="colspanchange">';
     }
     $html .= '<fieldset class="inline-edit-col-left" style="width:33%">';
     $html .= '<div class="inline-edit-col">';
     $html .= '<h4>' . __('CLIENT', 'appointments') . '</h4>';
     /* user */
     $html .= '<label>';
     $html .= '<span class="title">' . __('User', 'appointments') . '</span>';
     $html .= wp_dropdown_users(array('show_option_all' => __('Not registered user', 'appointments'), 'show' => 'user_login', 'echo' => 0, 'selected' => $app->user, 'name' => 'user'));
     $html .= '</label>';
     /* Client name */
     $html .= '<label>';
     $html .= '<span class="title">' . $this->get_field_name('name') . '</span>';
     $html .= '<span class="input-text-wrap">';
     $html .= '<input type="text" name="cname" class="ptitle" value="' . stripslashes($app->name) . '" />';
     $html .= '</span>';
     $html .= '</label>';
     /* Client email */
     $html .= '<label>';
     $html .= '<span class="title">' . $this->get_field_name('email') . '</span>';
     $html .= '<span class="input-text-wrap">';
     $html .= '<input type="text" name="email" class="ptitle" value="' . $app->email . '" />';
     $html .= '</span>';
     $html .= '</label>';
     /* Client Phone */
     $html .= '<label>';
     $html .= '<span class="title">' . $this->get_field_name('phone') . '</span>';
     $html .= '<span class="input-text-wrap">';
     $html .= '<input type="text" name="phone" class="ptitle" value="' . stripslashes($app->phone) . '" />';
     $html .= '</span>';
     $html .= '</label>';
     /* Client Address */
     $html .= '<label>';
     $html .= '<span class="title">' . $this->get_field_name('address') . '</span>';
     $html .= '<span class="input-text-wrap">';
     $html .= '<input type="text" name="address" class="ptitle" value="' . stripslashes($app->address) . '" />';
     $html .= '</span>';
     $html .= '</label>';
     /* Client City */
     $html .= '<label>';
     $html .= '<span class="title">' . $this->get_field_name('city') . '</span>';
     $html .= '<span class="input-text-wrap">';
     $html .= '<input type="text" name="city" class="ptitle" value="' . stripslashes($app->city) . '" />';
     $html .= '</span>';
     $html .= '</label>';
     $html .= apply_filters('app-appointments_list-edit-client', '', $app);
     $html .= '</div>';
     $html .= '</fieldset>';
     $html .= '<fieldset class="inline-edit-col-center" style="width:28%">';
     $html .= '<div class="inline-edit-col">';
     $html .= '<h4>' . __('SERVICE', 'appointments') . '</h4>';
     /* Services */
     $services = $this->get_services();
     $html .= '<label>';
     $html .= '<span class="title">' . __('Name', 'appointments') . '</span>';
     $html .= '<select name="service">';
     if ($services) {
         foreach ($services as $service) {
             if ($app->service == $service->ID) {
                 $sel = ' selected="selected"';
             } else {
                 $sel = '';
             }
             $html .= '<option value="' . $service->ID . '"' . $sel . '>' . stripslashes($service->name) . '</option>';
         }
     }
     $html .= '</select>';
     $html .= '</label>';
     /* Workers */
     $workers = $wpdb->get_results("SELECT * FROM " . $this->workers_table . " ");
     $html .= '<label>';
     $html .= '<span class="title">' . __('Provider', 'appointments') . '</span>';
     $html .= '<select name="worker">';
     // Always add an "Our staff" field
     $html .= '<option value="0">' . __('No specific provider', 'appointments') . '</option>';
     if ($workers) {
         foreach ($workers as $worker) {
             if ($app->worker == $worker->ID) {
                 $sel = ' selected="selected"';
             } else {
                 $sel = '';
             }
             $html .= '<option value="' . $worker->ID . '"' . $sel . '>' . $this->get_worker_name($worker->ID, false) . '</option>';
         }
     }
     $html .= '</select>';
     $html .= '</label>';
     /* Price */
     $html .= '<label>';
     $html .= '<span class="title">' . __('Price', 'appointments') . '</span>';
     $html .= '<span class="input-text-wrap">';
     $html .= '<input type="text" name="price" style="width:50%" class="ptitle" value="' . $app->price . '" />';
     $html .= '</span>';
     $html .= '</label>';
     $html .= '</label>';
     $html .= apply_filters('app-appointments_list-edit-services', '', $app);
     $html .= '</div>';
     $html .= '</fieldset>';
     $html .= '<fieldset class="inline-edit-col-right" style="width:38%">';
     $html .= '<div class="inline-edit-col">';
     $html .= '<h4>' . __('APPOINTMENT', 'appointments') . '</h4>';
     /* Created - Don't show for a new app */
     if ($app_id) {
         $html .= '<label>';
         $html .= '<span class="title">' . __('Created', 'appointments') . '</span>';
         $html .= '<span class="input-text-wrap" style="height:26px;padding-top:4px;">';
         $html .= date_i18n($this->datetime_format, strtotime($app->created));
         $html .= '</span>';
         $html .= '</label>';
     }
     /* Start */
     $html .= '<label style="float:left;width:65%">';
     $html .= '<span class="title">' . __('Start', 'appointments') . '</span>';
     $html .= '<span class="input-text-wrap" >';
     $html .= '<input type="text" name="date" class="datepicker" size="12" value="' . $start_date . '" data-timestamp="' . esc_attr($start_date_timestamp) . '"  />';
     $html .= '</label>';
     $html .= '<label style="float:left;width:30%; padding-left:5px;">';
     // Check if an admin min time (time base) is set. @since 1.0.2
     if (isset($this->options["admin_min_time"]) && $this->options["admin_min_time"]) {
         $min_time = $this->options["admin_min_time"];
     } else {
         $min_time = $this->get_min_time();
     }
     $min_secs = 60 * apply_filters('app_admin_min_time', $min_time);
     $html .= '<select name="time" >';
     for ($t = 0; $t < 3600 * 24; $t = $t + $min_secs) {
         $dhours = $this->secs2hours($t);
         // Hours in 08:30 format
         if ($dhours == $start_time) {
             $s = " selected='selected'";
         } else {
             $s = '';
         }
         $html .= '<option' . $s . '>';
         $html .= $dhours;
         $html .= '</option>';
     }
     $html .= '</select>';
     $html .= '</span>';
     $html .= '</label>';
     $html .= '<div style="clear:both; height:0"></div>';
     /* End - Don't show for a new app */
     if ($app_id) {
         $html .= '<label style="margin-top:8px">';
         $html .= '<span class="title">' . __('End', 'appointments') . '</span>';
         $html .= '<span class="input-text-wrap" style="height:26px;padding-top:4px;">';
         $html .= $end_datetime;
         $html .= '</span>';
         $html .= '</label>';
     }
     /* Note */
     $html .= '<label>';
     $html .= '<span class="title">' . $this->get_field_name('note') . '</span>';
     $html .= '<textarea cols="22" rows=1">';
     $html .= stripslashes($app->note);
     $html .= '</textarea>';
     $html .= '</label>';
     /* Status */
     //$statuses = $this->get_statuses();
     $statuses = App_Template::get_status_names();
     $html .= '<label>';
     $html .= '<span class="title">' . __('Status', 'appointments') . '</span>';
     $html .= '<span class="input-text-wrap">';
     $html .= '<select name="status">';
     if ($statuses) {
         foreach ($statuses as $status => $status_name) {
             if ($app->status == $status) {
                 $sel = ' selected="selected"';
             } else {
                 $sel = '';
             }
             $html .= '<option value="' . $status . '"' . $sel . '>' . $status_name . '</option>';
         }
     }
     $html .= '</select>';
     $html .= '</span>';
     $html .= '</label>';
     /* Confirmation email */
     // Default is "checked" for a new appointment
     if ($app_id) {
         $c = '';
         $text = __('(Re)send confirmation email', 'appointments');
     } else {
         $c = ' checked="checked"';
         $text = __('Send confirmation email', 'appointments');
     }
     $html .= '<label>';
     $html .= '<span class="title">' . __('Confirm', 'appointments') . '</span>';
     $html .= '<span class="input-text-wrap">';
     $html .= '<input type="checkbox" name="resend" value="1" ' . $c . ' />&nbsp;' . $text;
     $html .= '</span>';
     $html .= '</label>';
     $html .= '</div>';
     $html .= '</fieldset>';
     /* General fields required for save and cancel */
     $html .= '<p class="submit inline-edit-save">';
     $html .= '<a href="javascript:void(0)" title="' . _x('Cancel', 'Drop current action', 'appointments') . '" class="button-secondary cancel alignleft">' . _x('Cancel', 'Drop current action', 'appointments') . '</a>';
     if ('reserved' == $app->status) {
         $js = 'style="display:none"';
         $title = __('GCal reserved appointments cannot be edited here. Edit them in your Google calendar.', 'appointments');
     } else {
         $js = 'href="javascript:void(0)"';
         $title = __('Click to save or update', 'appointments');
     }
     $html .= '<a ' . $js . ' title="' . $title . '" class="button-primary save alignright">' . __('Save / Update', 'appointments') . '</a>';
     $html .= '<img class="waiting" style="display:none;" src="' . admin_url('images/wpspin_light.gif') . '" alt="">';
     $html .= '<input type="hidden" name="app_id" value="' . $app->ID . '">';
     $html .= '<span class="error" style="display:none"></span>';
     $html .= '<br class="clear">';
     $html .= '</p>';
     $html .= '</td>';
     $html .= '</tr>';
     die(json_encode(array('result' => $html)));
 }
    public function process_shortcode($args = array(), $content = '')
    {
        extract(wp_parse_args($args, $this->_defaults_to_args()));
        global $wpdb, $current_user, $bp, $appointments;
        $statuses = explode(',', $status);
        if (!is_array($statuses) || empty($statuses)) {
            return;
        }
        if (!trim($order_by)) {
            $order_by = 'ID';
        }
        $stat = '';
        foreach ($statuses as $s) {
            // Allow only defined stats
            if (array_key_exists(trim($s), App_Template::get_status_names())) {
                $stat .= " status='" . trim($s) . "' OR ";
            }
        }
        $stat = rtrim($stat, "OR ");
        // If this is a client shortcode
        if (!$provider) {
            if (isset($_COOKIE["wpmudev_appointments"])) {
                $apps = unserialize(stripslashes($_COOKIE["wpmudev_appointments"]));
            } else {
                $apps = array();
            }
            if (!is_array($apps)) {
                return;
            }
            $provider_or_client = __('Provider', 'appointments');
            $q = '';
            if ($strict) {
                // Strict matching
                if (is_user_logged_in()) {
                    $q = "user={$current_user->ID}";
                    // If the user is logged in, show just those apps
                } else {
                    // Otherwise, deal with the cookie-cached ones
                    $apps = array_values(array_filter(array_map('intval', $apps)));
                    if (!empty($apps)) {
                        $q = "ID IN(" . join(',', $apps) . ")";
                    }
                }
            } else {
                // Non-strict matching
                foreach ($apps as $app_id) {
                    if (is_numeric($app_id)) {
                        $q .= " ID=" . $app_id . " OR ";
                    }
                }
                $q = rtrim($q, "OR ");
                // But he may as well has appointments added manually (requires being registered user)
                if (is_user_logged_in()) {
                    $q .= " OR user="******" OR");
                }
            }
            if ($q && $stat) {
                $results = $wpdb->get_results("SELECT * FROM " . $appointments->app_table . " WHERE (" . $q . ") AND (" . $stat . ") ORDER BY " . $appointments->sanitize_order_by($order_by));
            } else {
                $results = false;
            }
        } else {
            $provider_or_client = __('Client', 'appointments');
            // If no id is given, get current user
            if (!$provider_id) {
                $provider_id = $current_user->ID;
            }
            // Special case: If this is a single provider website, show staff appointments in his schedule too
            $workers = $appointments->get_workers();
            if (App_Roles::current_user_can('manage_options', App_Roles::CTX_STAFF) && ($workers && count($workers) == 1 || !$workers)) {
                $provider_id .= ' OR worker=0';
            }
            $results = $wpdb->get_results("SELECT * FROM " . $appointments->app_table . " WHERE (worker=" . $provider_id . ") AND (" . $stat . ") ORDER BY " . $order_by . " ");
        }
        // Can worker confirm pending appointments?
        if ($_allow_confirm && $appointments->is_worker($current_user->ID) && isset($appointments->options['allow_worker_confirm']) && 'yes' == $appointments->options['allow_worker_confirm']) {
            $allow_confirm = true;
        } else {
            $allow_confirm = false;
        }
        // Can client cancel appointments?
        if ($allow_cancel && !$provider && isset($appointments->options['allow_cancel']) && 'yes' == $appointments->options['allow_cancel']) {
            $a_cancel = true;
        } else {
            $a_cancel = false;
        }
        $ret = '';
        $ret .= '<div class="appointments-my-appointments">';
        // Make this a form for BP if confirmation is allowed, but not on admin side user profile page
        if ($this->_can_display_editable($allow_confirm)) {
            $ret .= '<form method="post">';
        }
        $ret .= $title;
        $ret = apply_filters('app_my_appointments_before_table', $ret);
        $ret .= '<table class="my-appointments tablesorter"><thead>';
        $ret .= apply_filters('app_my_appointments_column_name', '<th class="my-appointments-service">' . __('Service', 'appointments') . '</th><th class="my-appointments-worker">' . $provider_or_client . '</th><th class="my-appointments-date">' . __('Date/time', 'appointments') . '</th><th class="my-appointments-status">' . __('Status', 'appointments') . '</th>');
        $colspan = 4;
        if ($allow_confirm) {
            $ret .= '<th class="my-appointments-confirm">' . __('Confirm', 'appointments') . '</th>';
            $colspan++;
        }
        if ($a_cancel) {
            $ret .= '<th class="my-appointments-cancel">' . _x('Cancel', 'Discard existing info', 'appointments') . '</th>';
            $colspan++;
        }
        if ($gcal && 'yes' == $appointments->options['gcal']) {
            $ret .= '<th class="my-appointments-gcal">&nbsp;</th>';
            $colspan++;
        }
        $ret .= '</thead><tbody>';
        if ($results) {
            foreach ($results as $r) {
                $ret .= '<tr><td>';
                $ret .= $appointments->get_service_name($r->service) . '</td>';
                $ret .= apply_filters('app-shortcode-my_appointments-after_service', '', $r);
                $ret .= '<td>';
                if (!$provider) {
                    $ret .= $appointments->get_worker_name($r->worker) . '</td>';
                } else {
                    $ret .= $appointments->get_client_name($r->ID) . '</td>';
                }
                $ret .= apply_filters('app-shortcode-my_appointments-after_worker', '', $r);
                $ret .= '<td>';
                $ret .= date_i18n($appointments->datetime_format, strtotime($r->start)) . '</td>';
                $ret .= apply_filters('app-shortcode-my_appointments-after_date', '', $r);
                $ret .= '<td>';
                $ret .= App_Template::get_status_name($r->status);
                $ret .= '</td>';
                $ret .= apply_filters('app-shortcode-my_appointments-after_status', '', $r);
                // If allowed so, a worker can confirm an appointment himself
                if ($allow_confirm) {
                    if ('pending' == $r->status) {
                        $is_readonly = '';
                    } else {
                        $is_readonly = ' readonly="readonly"';
                    }
                    $ret .= '<td><input class="app-my-appointments-confirm" type="checkbox" name="app_confirm[' . $r->ID . ']" ' . $is_readonly . ' /></td>';
                }
                // If allowed so, a client can cancel an appointment
                if ($a_cancel) {
                    // We don't want completed appointments to be cancelled
                    $stat = $r->status;
                    $in_allowed_stat = apply_filters('app_cancel_allowed_status', 'pending' == $stat || 'confirmed' == $stat || 'paid' == $stat, $stat, $r->ID);
                    if ($in_allowed_stat) {
                        $is_readonly = '';
                    } else {
                        $is_readonly = ' readonly="readonly"';
                    }
                    $ret .= '<td><input class="app-my-appointments-cancel" type="checkbox" name="app_cancel[' . $r->ID . ']" ' . $is_readonly . ' /></td>';
                }
                if ($gcal && 'yes' == $appointments->options['gcal']) {
                    if (isset($appointments->options["gcal_same_window"]) && $appointments->options["gcal_same_window"]) {
                        $target = '_self';
                    } else {
                        $target = '_blank';
                    }
                    $ret .= '<td><a title="' . __('Click to submit this appointment to your Google Calendar account', 'appointments') . '" href="' . $appointments->gcal($r->service, strtotime($r->start, $appointments->local_time), strtotime($r->end, $appointments->local_time), true, $r->address, $r->city) . '" target="' . $target . '">' . $appointments->gcal_image . '</a></td>';
                }
                $ret .= apply_filters('app_my_appointments_add_cell', '', $r);
                $ret .= '</tr>';
            }
        } else {
            $ret .= '<tr><td colspan="' . $colspan . '">' . __('No appointments', 'appointments') . '</td></tr>';
        }
        $ret .= '</tbody></table>';
        $ret = apply_filters('app_my_appointments_after_table', $ret, $results);
        if ($this->_can_display_editable($allow_confirm)) {
            $ret .= '<div class="submit">' . '<input type="submit" name="app_bp_settings_submit" value="' . esc_attr(__('Submit Confirm', 'appointments')) . '" class="auto">' . '<input type="hidden" name="app_bp_settings_user" value="' . esc_attr($bp->displayed_user->id) . '">' . wp_nonce_field('app_bp_settings_submit', 'app_bp_settings_submit', true, false) . '</div>';
            $ret .= '</form>';
        }
        $ret .= '</div>';
        $sorter = 'usLongDate';
        $dateformat = 'us';
        // Search for formats where day is at the beginning
        if (stripos(str_replace(array('/', '-'), '', $appointments->date_format), 'dmY') !== false) {
            $sorter = 'shortDate';
            $dateformat = 'uk';
        }
        // Sort table from front end
        if ($_tablesorter && file_exists($appointments->plugin_dir . '/js/jquery.tablesorter.min.js')) {
            $appointments->add2footer('
				$(".my-appointments").tablesorter({
					dateFormat: "' . $dateformat . '",
					headers: {
						2: {
							sorter:"' . $sorter . '"
						}
					}
				});
				$("th.my-appointments-gcal,th.my-appointments-confirm,th.my-appointments-cancel").removeClass("header");

				$(".app-my-appointments-cancel").change( function() {
					if ( $(this).is(":checked") ) {
						var cancel_box = $(this);
						if ( !confirm("' . esc_js(__("Are you sure to cancel the selected appointment?", "appointments")) . '") ) {
							cancel_box.attr("checked", false);
							return false;
						}
						else{
							var cancel_id = $(this).attr("name").replace("app_cancel[","").replace("]","");
							if (cancel_id) {
								var cancel_data = {action: "cancel_app", app_id: cancel_id, cancel_nonce: "' . wp_create_nonce() . '"};
								$.post(_appointments_data.ajax_url, cancel_data, function(response) {
									if (response && response.error ) {
										cancel_box.attr("disabled",true);
										alert(response.error);
									}
									else if (response && response.success) {
										alert("' . esc_js(__("Selected appointment cancelled.", "appointments")) . '");
										cancel_box.closest("tr").css("opacity","0.3");
										cancel_box.attr("disabled",true);
									}
									else {
										cancel_box.attr("disabled",true);
										alert("' . esc_js(__("A connection error occurred.", "appointments")) . '");
									}
								}, "json");
							}
						}
					}

				});');
        }
        return $ret;
    }
    public function process_shortcode($args = array(), $content = '')
    {
        global $wpdb, $appointments;
        extract(wp_parse_args($args, $this->_defaults_to_args()));
        $statuses = explode(',', $status);
        if (!is_array($statuses) || empty($statuses)) {
            return;
        }
        if (!trim($order_by)) {
            $order_by = 'start';
        }
        $stat = '';
        foreach ($statuses as $s) {
            // Allow only defined stats
            if (array_key_exists(trim($s), App_Template::get_status_names())) {
                $stat .= " status='" . trim($s) . "' OR ";
            }
        }
        $stat = rtrim($stat, "OR ");
        $results = $wpdb->get_results("SELECT * FROM " . $appointments->app_table . " WHERE (" . $stat . ") ORDER BY " . $appointments->sanitize_order_by($order_by) . " ");
        $ret = '';
        $ret .= '<div class="appointments-all-appointments">';
        $ret .= $title;
        $ret = apply_filters('app_all_appointments_before_table', $ret);
        $ret .= '<table class="all-appointments tablesorter"><thead>';
        $ret .= apply_filters('app_all_appointments_column_name', '<th class="all-appointments-service">' . __('Service', 'appointments') . '</th><th class="all-appointments-provider">' . __('Provider', 'appointments') . '</th><th class="all-appointments-client">' . __('Client', 'appointments') . '</th><th class="all-appointments-date">' . __('Date/time', 'appointments') . '</th><th class="all-appointments-status">' . __('Status', 'appointments') . '</th>');
        $colspan = 5;
        $ret .= '</thead><tbody>';
        if ($results) {
            foreach ($results as $r) {
                $ret .= '<tr><td>';
                $ret .= $appointments->get_service_name($r->service) . '</td>';
                $ret .= apply_filters('app-shortcode-all_appointments-after_service', '', $r);
                $ret .= '<td>';
                $ret .= $appointments->get_worker_name($r->worker) . '</td>';
                $ret .= apply_filters('app-shortcode-all_appointments-after_provider', '', $r);
                $ret .= '<td>';
                $ret .= $appointments->get_client_name($r->ID) . '</td>';
                $ret .= apply_filters('app-shortcode-all_appointments-after_client', '', $r);
                $ret .= '<td>';
                $ret .= date_i18n($appointments->datetime_format, strtotime($r->start)) . '</td>';
                $ret .= apply_filters('app-shortcode-all_appointments-after_date', '', $r);
                $ret .= '<td>';
                $ret .= App_Template::get_status_name($r->status);
                $ret .= '</td>';
                $ret .= apply_filters('app-shortcode-all_appointments-after_status', '', $r);
                $ret .= apply_filters('app_all_appointments_add_cell', '', $r);
                $ret .= '</tr>';
            }
        } else {
            $ret .= '<tr><td colspan="' . $colspan . '">' . __('No appointments', 'appointments') . '</td></tr>';
        }
        $ret .= '</tbody></table>';
        $ret = apply_filters('app_all_appointments_after_table', $ret, $results);
        $ret .= '</div>';
        $sorter = 'usLongDate';
        $dateformat = 'us';
        // Search for formats where day is at the beginning
        if (stripos(str_replace(array('/', '-'), '', $appointments->date_format), 'dmY') !== false) {
            $sorter = 'shortDate';
            $dateformat = 'uk';
        }
        // Sort table from front end
        if ($_tablesorter && file_exists($appointments->plugin_dir . '/js/jquery.tablesorter.min.js')) {
            $appointments->add2footer('
				$(".all-appointments").tablesorter({
					dateFormat: "' . $dateformat . '",
					headers: {
						2: {
							sorter:"' . $sorter . '"
						}
					}
				});
				$("th.all-appointments-gcal,th.all-appointments-confirm,th.all-appointments-cancel").removeClass("header");');
        }
        return $ret;
    }