コード例 #1
0
 function tutorial2()
 {
     global $appointments;
     //load the file
     if (!class_exists('Pointer_Tutorial')) {
         require_once $appointments->plugin_dir . '/includes/external/pointer-tutorials.php';
     }
     //create our tutorial, with default redirect prefs
     $tutorial = new Pointer_Tutorial('app_tutorial2', true, false);
     //add our textdomain that matches the current plugin
     $tutorial->set_textdomain = 'appointments';
     //add the capability a user must have to view the tutorial
     $tutorial->set_capability = App_Roles::get_capability('manage_options', App_Roles::CTX_TUTORIAL);
     $tutorial->add_icon($appointments->plugin_url . '/images/large-greyscale.png');
     $appointments_page = admin_url('admin.php?page=appointments');
     $tutorial->add_step($appointments_page, 'toplevel_page_appointments', '.info-button', __('Appointment List', 'appointments'), array('content' => '<p>' . esc_js(__('Appointment records are grouped by their statuses. You can see these groupings by clicking the Info icon.', 'appointments')) . '</p>', 'position' => array('edge' => 'right', 'align' => 'center')));
     $tutorial->add_step($appointments_page, 'toplevel_page_appointments', '.add-new-h2', __('Entering a Manual Appointment', 'appointments'), array('content' => '<p>' . esc_js(__('When you received appointments from your clients, they will be added to this page automatically. But you can always add a new appointment manually. Please click ADD NEW link and then click Next.', 'appointments')) . '</p>', 'position' => array('edge' => 'left', 'align' => 'top')));
     $tutorial->add_step($appointments_page, 'toplevel_page_appointments', 'select[name="status"]', __('Entering Data for the New Appointment', 'appointments'), array('content' => '<p>' . esc_js(__('As you can see, you can enter all parameters here. Enter some random values and select status as PENDING, for this example. Then click Next', 'appointments')) . '</p>', 'position' => array('edge' => 'right', 'align' => 'center')));
     $tutorial->add_step($appointments_page, 'toplevel_page_appointments', 'input[name="resend"]', __('Sending Confirmation emails Manually', 'appointments'), array('content' => '<p>' . esc_js(__('If you require payment, confirmation email is automatically sent after a Paypal payment. However if you are confirming appointments manually, you should check this checkbox for a confirmation email to be sent. You can also use this option for resending the confirmation email, e.g. after rescheduling an appointment.', 'appointments')) . '</p>', 'position' => array('edge' => 'right', 'align' => 'center')));
     $tutorial->add_step($appointments_page, 'toplevel_page_appointments', '.save', __('Entering Data for the New Appointment', 'appointments'), array('content' => '<p>' . esc_js(__('Save and then click Next.', 'appointments')) . '</p>', 'position' => array('edge' => 'right', 'align' => 'center')));
     $tutorial->add_step($appointments_page, 'toplevel_page_appointments', '.error', __('Entering Data for the New Appointment', 'appointments'), array('content' => '<p>' . esc_js(__('The result is shown here. Normally you should get a success message. Otherwise it means that you have a javascript problem on admin side.', 'appointments')) . '</p>', 'position' => array('edge' => 'left', 'align' => 'center')));
     $tutorial->add_step($appointments_page, 'toplevel_page_appointments', '.info-button', __('Save New Appointment', 'appointments'), array('content' => '<p>' . esc_js(__('As we added this appointment as "Pending" we will see it under Pending appointments. Click Pending appointments and then click Next.', 'appointments')) . '</p>', 'position' => array('edge' => 'left', 'align' => 'center')));
     $tutorial->add_step($appointments_page . '&type=pending', 'toplevel_page_appointments', '.info-button', __('Editing an Appointment', 'appointments'), array('content' => '<p>' . esc_js(__('You can edit any appointment record. Just hover on the record and then click See Details and Edit', 'appointments')) . '</p>', 'position' => array('edge' => 'left', 'align' => 'center')));
     $tutorial->add_step($appointments_page . '&type=pending', 'toplevel_page_appointments', '.cancel', _x('Cancel', 'Drop current action', 'appointments'), array('content' => '<p>' . esc_js(__('It is always possible to Cancel. Please note that these records are NOT saved until you click the Save button. Thanks for using Appointments+', 'appointments')) . '</p>', 'position' => array('edge' => 'left', 'align' => 'center')));
     if (isset($_GET["tutorial"]) && 'restart2' == $_GET["tutorial"]) {
         $tutorial->restart();
     }
     //start the tutorial
     $tutorial->initialize();
     return $tutorial;
 }
コード例 #2
0
    public function add_script()
    {
        if (!current_user_can(App_Roles::get_capability('manage_options', App_Roles::CTX_PAGE_APPOINTMENTS))) {
            return false;
        }
        $key = esc_js(self::HB_KEY);
        $tpl = json_encode($this->_get_pending_template());
        echo <<<EO_AAPC_JS
<script>
;(function (\$) {

if (typeof(wp) === "undefined") return false;

function update_interface (data) {
\tvar root = \$("#toplevel_page_appointments"),
\t\ttarget = root.find(".wp-menu-name"),
\t\tcount = data.count || 0
\t;
\tif (!target.length) return false;
\ttarget.find(".awaiting-mod").remove();
\tif (count > 0) target.append({$tpl}.replace(/%d/g, count));
}

function set_heartbeat () {
\twp.heartbeat.enqueue('{$key}', {count: "pending"}, false);
}

function init () {
\tset_heartbeat();
\t\$(document).on('heartbeat-tick.{$key}', function (e, data) {
\t\tset_heartbeat();
\t\tif (data && data.hasOwnProperty && data.hasOwnProperty('{$key}')) {
\t\t\tupdate_interface(data['{$key}']);
\t\t}
\t});
}
\$(init);
})(jQuery);
</script>
EO_AAPC_JS;
    }
コード例 #3
0
 /**
  *	Admin pages init stuff, save settings
  *
  */
 function admin_init()
 {
     if (!session_id()) {
         @session_start();
     }
     $page = add_menu_page('Appointments', __('Appointments', 'appointments'), App_Roles::get_capability('manage_options', App_Roles::CTX_PAGE_APPOINTMENTS), 'appointments', array(&$this, 'appointment_list'), 'div');
     add_submenu_page('appointments', __('Transactions', 'appointments'), __('Transactions', 'appointments'), App_Roles::get_capability('manage_options', App_Roles::CTX_PAGE_TRANSACTIONS), "app_transactions", array(&$this, 'transactions'));
     add_submenu_page('appointments', __('Settings', 'appointments'), __('Settings', 'appointments'), App_Roles::get_capability('manage_options', App_Roles::CTX_PAGE_SETTINGS), "app_settings", array(&$this, 'settings'));
     add_submenu_page('appointments', __('Shortcodes', 'appointments'), __('Shortcodes', 'appointments'), App_Roles::get_capability('manage_options', App_Roles::CTX_PAGE_SHORTCODES), "app_shortcodes", array(&$this, 'shortcodes_page'));
     add_submenu_page('appointments', __('FAQ', 'appointments'), __('FAQ', 'appointments'), App_Roles::get_capability('manage_options', App_Roles::CTX_PAGE_FAQ), "app_faq", array(&$this, 'faq_page'));
     // Add datepicker to appointments page
     add_action("admin_print_scripts-{$page}", array(&$this, 'admin_scripts'));
     do_action('app-admin-admin_pages_added', $page);
     if (isset($_POST["action_app"]) && !wp_verify_nonce($_POST['app_nonce'], 'update_app_settings')) {
         add_action('admin_notices', array(&$this, 'warning'));
         return;
     }
     // Read Location, Service, Worker
     $this->get_lsw();
     global $wpdb;
     if (isset($_POST["action_app"]) && 'save_general' == $_POST["action_app"]) {
         $this->options["min_time"] = $_POST["min_time"];
         $this->options["additional_min_time"] = trim($_POST["additional_min_time"]);
         $this->options["admin_min_time"] = $_POST["admin_min_time"];
         $this->options["app_lower_limit"] = trim($_POST["app_lower_limit"]);
         $this->options["app_limit"] = trim($_POST["app_limit"]);
         $this->options["clear_time"] = trim($_POST["clear_time"]);
         $this->options["spam_time"] = trim($_POST["spam_time"]);
         $this->options["auto_confirm"] = $_POST["auto_confirm"];
         $this->options["allow_worker_wh"] = $_POST["allow_worker_wh"];
         $this->options["allow_worker_confirm"] = $_POST["allow_worker_confirm"];
         $this->options["allow_overwork"] = $_POST["allow_overwork"];
         $this->options["allow_overwork_break"] = $_POST["allow_overwork_break"];
         $this->options["dummy_assigned_to"] = !$this->is_dummy(@$_POST["dummy_assigned_to"]) ? @$_POST["dummy_assigned_to"] : 0;
         $this->options["login_required"] = $_POST["login_required"];
         $this->options["accept_api_logins"] = isset($_POST["accept_api_logins"]);
         $this->options["facebook-no_init"] = isset($_POST["facebook-no_init"]);
         $this->options['facebook-app_id'] = trim($_POST['facebook-app_id']);
         $this->options['twitter-app_id'] = trim($_POST['twitter-app_id']);
         $this->options['twitter-app_secret'] = trim($_POST['twitter-app_secret']);
         $this->options['google-client_id'] = trim($_POST['google-client_id']);
         $this->options["app_page_type"] = $_POST["app_page_type"];
         $this->options["show_legend"] = $_POST["show_legend"];
         $this->options["color_set"] = $_POST["color_set"];
         foreach ($this->get_classes() as $class => $name) {
             $this->options[$class . "_color"] = $_POST[$class . "_color"];
         }
         $this->options["ask_name"] = isset($_POST["ask_name"]);
         $this->options["ask_email"] = isset($_POST["ask_email"]);
         $this->options["ask_phone"] = isset($_POST["ask_phone"]);
         $this->options["ask_phone"] = isset($_POST["ask_phone"]);
         $this->options["ask_address"] = isset($_POST["ask_address"]);
         $this->options["ask_city"] = isset($_POST["ask_city"]);
         $this->options["ask_note"] = isset($_POST["ask_note"]);
         $this->options["additional_css"] = trim(stripslashes_deep($_POST["additional_css"]));
         $this->options["payment_required"] = $_POST["payment_required"];
         $this->options["percent_deposit"] = trim(str_replace('%', '', $_POST["percent_deposit"]));
         $this->options["fixed_deposit"] = trim(str_replace($this->options["currency"], '', $_POST["fixed_deposit"]));
         /*
          * Membership plugin is replaced by Membership2. Old options are
          * only saved when the depreacted Membership plugin is still active.
          */
         if (class_exists('M_Membership')) {
             $this->options['members_no_payment'] = isset($_POST['members_no_payment']);
             // not used??
             $this->options['members_discount'] = trim(str_replace('%', '', $_POST['members_discount']));
             $this->options['members'] = maybe_serialize(@$_POST["members"]);
         }
         $this->options['currency'] = $_POST['currency'];
         $this->options['mode'] = $_POST['mode'];
         $this->options['merchant_email'] = trim($_POST['merchant_email']);
         $this->options['return'] = $_POST['return'];
         $this->options['allow_free_autoconfirm'] = !empty($_POST['allow_free_autoconfirm']);
         $this->options["send_confirmation"] = $_POST["send_confirmation"];
         $this->options["send_notification"] = @$_POST["send_notification"];
         $this->options["confirmation_subject"] = stripslashes_deep($_POST["confirmation_subject"]);
         $this->options["confirmation_message"] = stripslashes_deep($_POST["confirmation_message"]);
         $this->options["send_reminder"] = $_POST["send_reminder"];
         $this->options["reminder_time"] = str_replace(" ", "", $_POST["reminder_time"]);
         $this->options["send_reminder_worker"] = $_POST["send_reminder_worker"];
         $this->options["reminder_time_worker"] = str_replace(" ", "", $_POST["reminder_time_worker"]);
         $this->options["reminder_subject"] = stripslashes_deep($_POST["reminder_subject"]);
         $this->options["reminder_message"] = stripslashes_deep($_POST["reminder_message"]);
         $this->options["send_removal_notification"] = $_POST["send_removal_notification"];
         $this->options["removal_notification_subject"] = stripslashes_deep($_POST["removal_notification_subject"]);
         $this->options["removal_notification_message"] = stripslashes_deep($_POST["removal_notification_message"]);
         $this->options["log_emails"] = $_POST["log_emails"];
         $this->options['use_cache'] = $_POST['use_cache'];
         $this->options['disable_js_check_admin'] = isset($_POST['disable_js_check_admin']);
         $this->options['disable_js_check_frontend'] = isset($_POST['disable_js_check_frontend']);
         $this->options['use_mp'] = isset($_POST['use_mp']);
         $this->options["app_page_type_mp"] = @$_POST["app_page_type_mp"];
         $this->options['allow_cancel'] = @$_POST['allow_cancel'];
         $this->options['cancel_page'] = @$_POST['cancel_page'];
         $this->options["records_per_page"] = (int) trim(@$_POST["records_per_page"]);
         $this->options = apply_filters('app-options-before_save', $this->options);
         $saved = false;
         if (update_option('appointments_options', $this->options)) {
             $saved = true;
             if ('yes' == $this->options['use_cache']) {
                 add_action('admin_notices', array(&$this, 'saved_cleared'));
             } else {
                 add_action('admin_notices', array(&$this, 'saved'));
             }
         }
         // Flush cache
         if (isset($_POST["force_flush"]) || $saved) {
             $this->flush_cache();
             if (isset($_POST["force_flush"])) {
                 add_action('admin_notices', array(&$this, 'cleared'));
             }
         }
         if (isset($_POST['make_an_appointment']) || isset($_POST['make_an_appointment_product'])) {
             $this->_create_pages();
         }
         // Redirecting when saving options
         if ($saved) {
             wp_redirect(add_query_arg('saved', 1));
             die;
         }
     }
     $result = $updated = $inserted = false;
     // Save Working Hours
     if (isset($_POST["action_app"]) && 'save_working_hours' == $_POST["action_app"]) {
         $location = (int) $_POST['location'];
         foreach (array('closed', 'open') as $stat) {
             $query = $this->db->prepare("SELECT COUNT(*) FROM {$this->wh_table} WHERE location=%d AND worker=%d AND status=%s", $location, $this->worker, $stat);
             $count = $wpdb->get_var($query);
             if ($count > 0) {
                 $r = $wpdb->update($this->wh_table, array('hours' => serialize($_POST[$stat]), 'status' => $stat), array('location' => $location, 'worker' => $this->worker, 'status' => $stat), array('%s', '%s'), array('%d', '%d', '%s'));
                 if ($r) {
                     $result = true;
                 }
             } else {
                 $r = $wpdb->insert($this->wh_table, array('location' => $location, 'worker' => $this->worker, 'hours' => serialize($_POST[$stat]), 'status' => $stat), array('%d', '%d', '%s', '%s'));
                 if ($r) {
                     $result = true;
                 }
             }
             if ($result) {
                 add_action('admin_notices', array(&$this, 'saved'));
             }
         }
     }
     // Save Exceptions
     if (isset($_POST["action_app"]) && 'save_exceptions' == $_POST["action_app"]) {
         $location = (int) $_POST['location'];
         foreach (array('closed', 'open') as $stat) {
             $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$this->exceptions_table} WHERE location=%d AND worker=%d AND status=%s", $location, $this->worker, $stat));
             if ($count > 0) {
                 $r = $wpdb->update($this->exceptions_table, array('days' => $this->_sort($_POST[$stat]["exceptional_days"]), 'status' => $stat), array('location' => $location, 'worker' => $this->worker, 'status' => $stat), array('%s', '%s'), array('%d', '%d', '%s'));
                 if ($r) {
                     $result = true;
                 }
             } else {
                 $r = $wpdb->insert($this->exceptions_table, array('location' => $location, 'worker' => $this->worker, 'days' => $this->_sort($_POST[$stat]["exceptional_days"]), 'status' => $stat), array('%d', '%d', '%s', '%s'));
                 if ($r) {
                     $result = true;
                 }
             }
             if ($result) {
                 add_action('admin_notices', array(&$this, 'saved'));
             }
         }
     }
     // Save Services
     if (isset($_POST["action_app"]) && 'save_services' == $_POST["action_app"] && is_array($_POST["services"])) {
         do_action('app-services-before_save');
         foreach ($_POST["services"] as $ID => $service) {
             if ('' != trim($service["name"])) {
                 // Update or insert?
                 $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM {$this->services_table} WHERE ID=%d", $ID));
                 if ($count) {
                     $r = $wpdb->update($this->services_table, array('name' => $service["name"], 'capacity' => (int) $service["capacity"], 'duration' => $service["duration"], 'price' => preg_replace("/[^0-9,.]/", "", $service["price"]), 'page' => $service["page"]), array('ID' => $ID), array('%s', '%d', '%d', '%s', '%d'));
                     if ($r) {
                         $result = true;
                     }
                 } else {
                     //if ((int)$this->db->get_var("SELECT COUNT(ID) FROM {$this->services_table}") >= 2) { /* ... */ }
                     $r = $wpdb->insert($this->services_table, array('ID' => $ID, 'name' => $service["name"], 'capacity' => (int) $service["capacity"], 'duration' => $service["duration"], 'price' => preg_replace("/[^0-9,.]/", "", $service["price"]), 'page' => $service["page"]), array('%d', '%s', '%d', '%d', '%s', '%d'));
                     if ($r) {
                         $result = true;
                     }
                 }
                 do_action('app-services-service-updated', $ID);
             } else {
                 // Entering an empty name means deleting of a service
                 $r = $wpdb->query($wpdb->prepare("DELETE FROM {$this->services_table} WHERE ID=%d LIMIT 1", $ID));
                 // Remove deleted service also from workers table
                 $r1 = $wpdb->query($wpdb->prepare("UPDATE {$this->workers_table} SET services_provided = REPLACE(services_provided,':%d:','') ", $ID));
                 if ($r || $r1) {
                     $result = true;
                 }
             }
         }
         if ($result) {
             add_action('admin_notices', array(&$this, 'saved'));
         }
     }
     // Save Workers
     if (isset($_POST["action_app"]) && 'save_workers' == $_POST["action_app"] && is_array($_POST["workers"])) {
         foreach ($_POST["workers"] as $worker) {
             $ID = $worker["user"];
             if ($ID && !empty($worker["services_provided"])) {
                 $inserted = false;
                 // Does the worker have already a record?
                 $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$this->workers_table} WHERE ID=%d", $ID));
                 if ($count) {
                     if (!$this->db_version) {
                         $r = $wpdb->update($this->workers_table, array('price' => preg_replace("/[^0-9,.]/", "", $worker["price"]), 'services_provided' => $this->_implode($worker["services_provided"]), 'page' => $worker["page"]), array('ID' => $worker["user"]), array('%s', '%s', '%d'));
                     } else {
                         $r = $wpdb->update($this->workers_table, array('price' => preg_replace("/[^0-9,.]/", "", $worker["price"]), 'services_provided' => $this->_implode($worker["services_provided"]), 'page' => $worker["page"], 'dummy' => isset($worker["dummy"])), array('ID' => $worker["user"]), array('%s', '%s', '%d', '%s'));
                     }
                     if ($r) {
                         $updated = true;
                     }
                 } else {
                     if (!$this->db_version) {
                         $r = $wpdb->insert($this->workers_table, array('ID' => $worker["user"], 'price' => preg_replace("/[^0-9,.]/", "", $worker["price"]), 'services_provided' => $this->_implode($worker["services_provided"]), 'page' => $worker["page"]), array('%d', '%s', '%s', '%d'));
                     } else {
                         $r = $wpdb->insert($this->workers_table, array('ID' => $worker["user"], 'price' => preg_replace("/[^0-9,.]/", "", $worker["price"]), 'services_provided' => $this->_implode($worker["services_provided"]), 'page' => $worker["page"], 'dummy' => isset($worker["dummy"])), array('%d', '%s', '%s', '%d', '%s'));
                     }
                     if ($r) {
                         // Insert the default working hours to the worker's working hours
                         foreach (array('open', 'closed') as $stat) {
                             $result_wh = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->wh_table} WHERE location=0 AND service=0 AND status=%s", $stat), ARRAY_A);
                             if ($result_wh != null) {
                                 $result_wh["ID"] = 'NULL';
                                 $result_wh["worker"] = $ID;
                                 $wpdb->insert($this->wh_table, $result_wh);
                             }
                         }
                         // Insert the default holidays to the worker's holidays
                         foreach (array('open', 'closed') as $stat) {
                             $result_wh = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->exceptions_table} WHERE location=0 AND service=0 AND status=%s", $stat), ARRAY_A);
                             if ($result_wh != null) {
                                 $result_wh["ID"] = 'NULL';
                                 $result_wh["worker"] = $ID;
                                 $wpdb->insert($this->exceptions_table, $result_wh);
                             }
                         }
                         $inserted = true;
                     }
                 }
                 do_action('app-workers-worker-updated', $ID);
             } else {
                 if ($ID) {
                     //$r = $wpdb->query( "DELETE FROM " . $this->workers_table . " WHERE ID=".$ID." LIMIT 1 " );
                     //$r1 = $wpdb->query( "DELETE FROM " . $this->wh_table . " WHERE worker=".$ID." " );
                     //$r2 = $wpdb->query( "DELETE FROM " . $this->exceptions_table . " WHERE worker=".$ID." " );
                     $r = $wpdb->query($wpdb->prepare("DELETE FROM {$this->workers_table} WHERE ID=%d LIMIT 1", $ID));
                     $r1 = $wpdb->query($wpdb->prepare("DELETE FROM {$this->wh_table} WHERE worker=%d", $ID));
                     $r2 = $wpdb->query($wpdb->prepare("DELETE FROM {$this->exceptions_table} WHERE worker=%d", $ID));
                     if ($r || $r1 || $r2) {
                         $result = true;
                     }
                 }
             }
         }
         if ($result || $updated || $inserted) {
             add_action('admin_notices', array(&$this, 'saved'));
         }
     }
     // Delete removed app records
     if (isset($_POST["delete_removed"]) && 'delete_removed' == $_POST["delete_removed"] && isset($_POST["app"]) && is_array($_POST["app"])) {
         $q = '';
         foreach ($_POST["app"] as $app_id) {
             $q .= " ID=" . (int) $app_id . " OR";
         }
         $q = rtrim($q, " OR");
         $result = $wpdb->query("DELETE FROM " . $this->app_table . " WHERE " . $q . " ");
         if ($result) {
             global $current_user;
             $userdata = get_userdata($current_user->ID);
             add_action('admin_notices', array(&$this, 'deleted'));
             do_action('app_deleted', $_POST["app"]);
             $this->log(sprintf(__('Appointment(s) with id(s):%s deleted by user:%s', 'appointments'), implode(', ', $_POST["app"]), $userdata->user_login));
         }
     }
     // Bulk status change
     if (isset($_POST["app_status_change"]) && $_POST["app_new_status"] && isset($_POST["app"]) && is_array($_POST["app"])) {
         $q = '';
         foreach ($_POST["app"] as $app_id) {
             $q .= " ID=" . (int) $app_id . " OR";
         }
         $q = rtrim($q, " OR");
         // Make a new status re-check here - It should be in status map
         $new_status = esc_sql($_POST["app_new_status"]);
         if (array_key_exists($new_status, $this->get_statuses())) {
             $result = $wpdb->query("UPDATE " . $this->app_table . " SET status='" . $new_status . "' WHERE " . $q . " ");
             if ($result) {
                 global $current_user;
                 $userdata = get_userdata($current_user->ID);
                 add_action('admin_notices', array(&$this, 'updated'));
                 do_action('app_bulk_status_change', $_POST["app"]);
                 $this->log(sprintf(__('Status of Appointment(s) with id(s):%s changed to %s by user:%s', 'appointments'), implode(', ', $_POST["app"]), $new_status, $userdata->user_login));
                 if (is_object($this->gcal_api)) {
                     // If deleted, remove these from GCal too
                     if ('removed' == $new_status) {
                         foreach ($_POST["app"] as $app_id) {
                             $this->gcal_api->delete($app_id);
                             $this->send_removal_notification($app_id);
                         }
                     } else {
                         if (is_object($this->gcal_api) && $this->gcal_api->is_syncable_status($new_status)) {
                             foreach ($_POST["app"] as $app_id) {
                                 $this->gcal_api->update($app_id);
                                 // Also send out an email
                                 if (!empty($this->options["send_confirmation"]) && 'yes' == $this->options["send_confirmation"]) {
                                     $this->send_confirmation($app_id);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Determine if we shall flush cache
     if (isset($_POST["action_app"]) && ($result || $updated || $inserted) || isset($_POST["delete_removed"]) && 'delete_removed' == $_POST["delete_removed"] || isset($_POST["app_status_change"]) && $_POST["app_new_status"]) {
         // As it means any setting is saved, lets clear cache
         $this->flush_cache();
     }
 }
コード例 #4
0
 /**
  *	Admin pages init stuff, save settings
  *
  */
 function admin_init()
 {
     global $appointments;
     if (!session_id()) {
         @session_start();
     }
     $page = add_menu_page('Appointments', __('Appointments', 'appointments'), App_Roles::get_capability('manage_options', App_Roles::CTX_PAGE_APPOINTMENTS), 'appointments', array(&$this, 'appointment_list'), 'dashicons-clock');
     add_submenu_page('appointments', __('Transactions', 'appointments'), __('Transactions', 'appointments'), App_Roles::get_capability('manage_options', App_Roles::CTX_PAGE_TRANSACTIONS), "app_transactions", array(&$this, 'transactions'));
     add_submenu_page('appointments', __('Settings', 'appointments'), __('Settings', 'appointments'), App_Roles::get_capability('manage_options', App_Roles::CTX_PAGE_SETTINGS), "app_settings", array(&$this, 'settings'));
     add_submenu_page('appointments', __('Shortcodes', 'appointments'), __('Shortcodes', 'appointments'), App_Roles::get_capability('manage_options', App_Roles::CTX_PAGE_SHORTCODES), "app_shortcodes", array(&$this, 'shortcodes_page'));
     add_submenu_page('appointments', __('FAQ', 'appointments'), __('FAQ', 'appointments'), App_Roles::get_capability('manage_options', App_Roles::CTX_PAGE_FAQ), "app_faq", array(&$this, 'faq_page'));
     // Add datepicker to appointments page
     add_action("admin_print_scripts-{$page}", array(&$this, 'admin_scripts'));
     do_action('app-admin-admin_pages_added', $page);
     if (isset($_POST["action_app"]) && !wp_verify_nonce($_POST['app_nonce'], 'update_app_settings')) {
         add_action('admin_notices', array(&$this, 'warning'));
         return;
     }
     // Read Location, Service, Worker
     $appointments->get_lsw();
     global $wpdb;
     if (isset($_POST["action_app"]) && 'save_general' == $_POST["action_app"]) {
         $appointments->options["min_time"] = $_POST["min_time"];
         $appointments->options["additional_min_time"] = trim($_POST["additional_min_time"]);
         $appointments->options["admin_min_time"] = $_POST["admin_min_time"];
         $appointments->options["app_lower_limit"] = trim($_POST["app_lower_limit"]);
         $appointments->options["app_limit"] = trim($_POST["app_limit"]);
         $appointments->options["clear_time"] = trim($_POST["clear_time"]);
         $appointments->options["spam_time"] = trim($_POST["spam_time"]);
         $appointments->options["auto_confirm"] = $_POST["auto_confirm"];
         $appointments->options["allow_worker_wh"] = $_POST["allow_worker_wh"];
         $appointments->options["allow_worker_confirm"] = $_POST["allow_worker_confirm"];
         $appointments->options["allow_overwork"] = $_POST["allow_overwork"];
         $appointments->options["allow_overwork_break"] = $_POST["allow_overwork_break"];
         $appointments->options["dummy_assigned_to"] = !$appointments->is_dummy(@$_POST["dummy_assigned_to"]) ? @$_POST["dummy_assigned_to"] : 0;
         $appointments->options["login_required"] = $_POST["login_required"];
         $appointments->options["accept_api_logins"] = isset($_POST["accept_api_logins"]);
         $appointments->options["facebook-no_init"] = isset($_POST["facebook-no_init"]);
         $appointments->options['facebook-app_id'] = trim($_POST['facebook-app_id']);
         $appointments->options['twitter-app_id'] = trim($_POST['twitter-app_id']);
         $appointments->options['twitter-app_secret'] = trim($_POST['twitter-app_secret']);
         $appointments->options['google-client_id'] = trim($_POST['google-client_id']);
         $appointments->options["app_page_type"] = $_POST["app_page_type"];
         $appointments->options["show_legend"] = $_POST["show_legend"];
         $appointments->options["color_set"] = $_POST["color_set"];
         foreach ($appointments->get_classes() as $class => $name) {
             $appointments->options[$class . "_color"] = $_POST[$class . "_color"];
         }
         $appointments->options["ask_name"] = isset($_POST["ask_name"]);
         $appointments->options["ask_email"] = isset($_POST["ask_email"]);
         $appointments->options["ask_phone"] = isset($_POST["ask_phone"]);
         $appointments->options["ask_phone"] = isset($_POST["ask_phone"]);
         $appointments->options["ask_address"] = isset($_POST["ask_address"]);
         $appointments->options["ask_city"] = isset($_POST["ask_city"]);
         $appointments->options["ask_note"] = isset($_POST["ask_note"]);
         $appointments->options["additional_css"] = trim(stripslashes_deep($_POST["additional_css"]));
         $appointments->options["payment_required"] = $_POST["payment_required"];
         $appointments->options["percent_deposit"] = trim(str_replace('%', '', $_POST["percent_deposit"]));
         $appointments->options["fixed_deposit"] = trim(str_replace($appointments->options["currency"], '', $_POST["fixed_deposit"]));
         /*
          * Membership plugin is replaced by Membership2. Old options are
          * only saved when the depreacted Membership plugin is still active.
          */
         if (class_exists('M_Membership')) {
             $appointments->options['members_no_payment'] = isset($_POST['members_no_payment']);
             // not used??
             $appointments->options['members_discount'] = trim(str_replace('%', '', $_POST['members_discount']));
             $appointments->options['members'] = maybe_serialize(@$_POST["members"]);
         }
         $appointments->options['currency'] = $_POST['currency'];
         $appointments->options['mode'] = $_POST['mode'];
         $appointments->options['merchant_email'] = trim($_POST['merchant_email']);
         $appointments->options['return'] = $_POST['return'];
         $appointments->options['allow_free_autoconfirm'] = !empty($_POST['allow_free_autoconfirm']);
         $appointments->options["send_confirmation"] = $_POST["send_confirmation"];
         $appointments->options["send_notification"] = @$_POST["send_notification"];
         $appointments->options["confirmation_subject"] = stripslashes_deep($_POST["confirmation_subject"]);
         $appointments->options["confirmation_message"] = stripslashes_deep($_POST["confirmation_message"]);
         $appointments->options["send_reminder"] = $_POST["send_reminder"];
         $appointments->options["reminder_time"] = str_replace(" ", "", $_POST["reminder_time"]);
         $appointments->options["send_reminder_worker"] = $_POST["send_reminder_worker"];
         $appointments->options["reminder_time_worker"] = str_replace(" ", "", $_POST["reminder_time_worker"]);
         $appointments->options["reminder_subject"] = stripslashes_deep($_POST["reminder_subject"]);
         $appointments->options["reminder_message"] = stripslashes_deep($_POST["reminder_message"]);
         $appointments->options["send_removal_notification"] = $_POST["send_removal_notification"];
         $appointments->options["removal_notification_subject"] = stripslashes_deep($_POST["removal_notification_subject"]);
         $appointments->options["removal_notification_message"] = stripslashes_deep($_POST["removal_notification_message"]);
         $appointments->options["log_emails"] = $_POST["log_emails"];
         $appointments->options['use_cache'] = $_POST['use_cache'];
         $appointments->options['disable_js_check_admin'] = isset($_POST['disable_js_check_admin']);
         $appointments->options['disable_js_check_frontend'] = isset($_POST['disable_js_check_frontend']);
         $appointments->options['use_mp'] = isset($_POST['use_mp']);
         $appointments->options["app_page_type_mp"] = @$_POST["app_page_type_mp"];
         $appointments->options['allow_cancel'] = @$_POST['allow_cancel'];
         $appointments->options['cancel_page'] = @$_POST['cancel_page'];
         $appointments->options["records_per_page"] = (int) trim(@$_POST["records_per_page"]);
         $appointments->options = apply_filters('app-options-before_save', $appointments->options);
         $saved = false;
         if (update_option('appointments_options', $appointments->options)) {
             $saved = true;
             if ('yes' == $appointments->options['use_cache']) {
                 add_action('admin_notices', array(&$appointments, 'saved_cleared'));
             } else {
                 add_action('admin_notices', array(&$appointments, 'saved'));
             }
         }
         // Flush cache
         if (isset($_POST["force_flush"]) || $saved) {
             $appointments->flush_cache();
             appointments_delete_timetables_cache();
             if (isset($_POST["force_flush"])) {
                 add_action('admin_notices', array(&$appointments, 'cleared'));
             }
         }
         if (isset($_POST['make_an_appointment']) || isset($_POST['make_an_appointment_product'])) {
             $this->_create_pages();
         }
         // Redirecting when saving options
         if ($saved) {
             wp_redirect(add_query_arg('saved', 1));
             die;
         }
     }
     $result = $updated = $inserted = false;
     // Save Working Hours
     if (isset($_POST["action_app"]) && 'save_working_hours' == $_POST["action_app"]) {
         $location = (int) $_POST['location'];
         foreach (array('closed', 'open') as $stat) {
             $query = $wpdb->prepare("SELECT COUNT(*) FROM {$appointments->wh_table} WHERE location=%d AND worker=%d AND status=%s", $location, $appointments->worker, $stat);
             $count = $wpdb->get_var($query);
             if ($count > 0) {
                 $r = $wpdb->update($appointments->wh_table, array('hours' => serialize($_POST[$stat]), 'status' => $stat), array('location' => $location, 'worker' => $appointments->worker, 'status' => $stat), array('%s', '%s'), array('%d', '%d', '%s'));
                 if ($r) {
                     $result = true;
                 }
             } else {
                 $r = $wpdb->insert($appointments->wh_table, array('location' => $location, 'worker' => $appointments->worker, 'hours' => serialize($_POST[$stat]), 'status' => $stat), array('%d', '%d', '%s', '%s'));
                 if ($r) {
                     $result = true;
                 }
             }
             if ($result) {
                 add_action('admin_notices', array(&$appointments, 'saved'));
             }
             appointments_delete_work_breaks_cache($location, $appointments->worker);
             appointments_delete_timetables_cache();
         }
     }
     // Save Exceptions
     if (isset($_POST["action_app"]) && 'save_exceptions' == $_POST["action_app"]) {
         $location = (int) $_POST['location'];
         foreach (array('closed', 'open') as $stat) {
             $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$appointments->exceptions_table} WHERE location=%d AND worker=%d AND status=%s", $location, $appointments->worker, $stat));
             if ($count > 0) {
                 $r = $wpdb->update($appointments->exceptions_table, array('days' => $this->_sort($_POST[$stat]["exceptional_days"]), 'status' => $stat), array('location' => $location, 'worker' => $appointments->worker, 'status' => $stat), array('%s', '%s'), array('%d', '%d', '%s'));
                 if ($r) {
                     $result = true;
                 }
             } else {
                 $r = $wpdb->insert($appointments->exceptions_table, array('location' => $location, 'worker' => $appointments->worker, 'days' => $this->_sort($_POST[$stat]["exceptional_days"]), 'status' => $stat), array('%d', '%d', '%s', '%s'));
                 if ($r) {
                     $result = true;
                 }
             }
             if ($result) {
                 add_action('admin_notices', array(&$appointments, 'saved'));
             }
             appointments_delete_exceptions_cache($location, $appointments->worker);
         }
     }
     // Save Services
     if (isset($_POST["action_app"]) && 'save_services' == $_POST["action_app"] && is_array($_POST["services"])) {
         do_action('app-services-before_save');
         foreach ($_POST["services"] as $ID => $service) {
             if ('' != trim($service["name"])) {
                 // Update or insert?
                 $_service = appointments_get_service($ID);
                 if ($_service) {
                     $args = array('name' => $service["name"], 'capacity' => (int) $service["capacity"], 'duration' => $service["duration"], 'price' => $service["price"], 'page' => $service["page"]);
                     $result = appointments_update_service($ID, $args);
                 } else {
                     $args = array('ID' => $ID, 'name' => $service["name"], 'capacity' => (int) $service["capacity"], 'duration' => $service["duration"], 'price' => $service["price"], 'page' => $service["page"]);
                     $result = appointments_insert_service($args);
                 }
                 do_action('app-services-service-updated', $ID);
             } else {
                 // Entering an empty name means deleting of a service
                 $r = appointments_delete_service($ID);
                 if ($r) {
                     $result = true;
                 }
             }
         }
         if ($result) {
             add_action('admin_notices', array(&$appointments, 'saved'));
         }
     }
     // Save Workers
     if (isset($_POST["action_app"]) && 'save_workers' == $_POST["action_app"] && is_array($_POST["workers"])) {
         foreach ($_POST["workers"] as $worker_id => $worker) {
             $new_worker_id = absint($worker["user"]);
             $worker_id = absint($worker_id);
             $inserted = false;
             $updated = false;
             $result = false;
             $worker_exists = appointments_get_worker($worker_id);
             if ($worker_exists) {
                 // Update
                 if ($new_worker_id != $worker_id && !empty($worker["services_provided"])) {
                     // We are trying to chage the user ID
                     $count = appointments_get_worker($new_worker_id);
                     // If the new ID already exist, do nothing
                     if (!$count) {
                         // Otherwise, change the ID
                         $args = array('ID' => $new_worker_id, 'price' => $worker["price"], 'services_provided' => $worker["services_provided"], 'dummy' => isset($worker["dummy"]), 'page' => $worker['page']);
                         $updated = appointments_update_worker($worker_id, $args);
                     }
                 } elseif ($new_worker_id == $worker_id && !empty($worker["services_provided"])) {
                     // Do not change user ID but update
                     $args = array('price' => $worker["price"], 'services_provided' => $worker["services_provided"], 'dummy' => isset($worker["dummy"]), 'page' => $worker['page']);
                     $updated = appointments_update_worker($worker_id, $args);
                 } elseif (empty($worker["services_provided"])) {
                     $r = appointments_delete_worker($worker_id);
                     if ($r) {
                         $result = true;
                     }
                 }
             } elseif (!$worker_exists && !empty($worker["services_provided"])) {
                 // Insert
                 $args = array('ID' => $worker["user"], 'price' => $worker["price"], 'services_provided' => $worker["services_provided"], 'page' => $worker["page"], 'dummy' => isset($worker["dummy"]));
                 $inserted = appointments_insert_worker($args);
                 if ($inserted) {
                     do_action('app-workers-worker-updated', $worker_id);
                 }
             }
         }
         if ($result || $updated || $inserted) {
             add_action('admin_notices', array(&$appointments, 'saved'));
         }
     }
     // Delete removed app records
     if (isset($_POST["delete_removed"]) && 'delete_removed' == $_POST["delete_removed"] && isset($_POST["app"]) && is_array($_POST["app"])) {
         $result = 0;
         foreach ($_POST["app"] as $app_id) {
             $result = $result + appointments_delete_appointment($app_id);
         }
         if ($result) {
             global $current_user;
             $userdata = get_userdata($current_user->ID);
             add_action('admin_notices', array(&$appointments, 'deleted'));
             do_action('app_deleted', $_POST["app"]);
             $appointments->log(sprintf(__('Appointment(s) with id(s):%s deleted by user:%s', 'appointments'), implode(', ', $_POST["app"]), $userdata->user_login));
         }
     }
     // Bulk status change
     if (isset($_POST["app_status_change"]) && $_POST["app_new_status"] && isset($_POST["app"]) && is_array($_POST["app"])) {
         $result = 0;
         $new_status = $_POST["app_new_status"];
         foreach ($_POST["app"] as $app_id) {
             $result = $result + (int) appointments_update_appointment_status(absint($app_id), $new_status);
         }
         if ($result) {
             $userdata = get_userdata(get_current_user_id());
             add_action('admin_notices', array(&$appointments, 'updated'));
             do_action('app_bulk_status_change', $_POST["app"]);
             $appointments->log(sprintf(__('Status of Appointment(s) with id(s):%s changed to %s by user:%s', 'appointments'), implode(', ', $_POST["app"]), $new_status, $userdata->user_login));
             if (is_object($appointments->gcal_api)) {
                 // If deleted, remove these from GCal too
                 if ('removed' == $new_status) {
                     foreach ($_POST["app"] as $app_id) {
                         $appointments->gcal_api->delete($app_id);
                         $appointments->send_removal_notification($app_id);
                     }
                 } else {
                     if (is_object($appointments->gcal_api) && $appointments->gcal_api->is_syncable_status($new_status)) {
                         foreach ($_POST["app"] as $app_id) {
                             $appointments->gcal_api->update($app_id);
                             // Also send out an email
                             if (!empty($appointments->options["send_confirmation"]) && 'yes' == $appointments->options["send_confirmation"]) {
                                 appointments_send_confirmation($app_id);
                             }
                         }
                     }
                 }
             }
         }
     }
     // Determine if we shall flush cache
     if (isset($_POST["action_app"]) && ($result || $updated || $inserted) || isset($_POST["delete_removed"]) && 'delete_removed' == $_POST["delete_removed"] || isset($_POST["app_status_change"]) && $_POST["app_new_status"]) {
         // As it means any setting is saved, lets clear cache
         $appointments->flush_cache();
     }
 }