activities_controller.php
1 year ago
auth_controller.php
1 year ago
booking_form_settings_controller.php
1 year ago
bookings_controller.php
1 year ago
calendars_controller.php
1 year ago
carts_controller.php
1 year ago
controller.php
1 year ago
customer_cabinet_controller.php
1 year ago
customers_controller.php
1 year ago
dashboard_controller.php
1 year ago
default_agent_controller.php
1 year ago
events_controller.php
1 year ago
form_fields_controller.php
1 year ago
integrations_controller.php
1 year ago
invoices_controller.php
1 year ago
manage_booking_by_key_controller.php
1 year ago
manage_order_by_key_controller.php
1 year ago
notifications_controller.php
1 year ago
orders_controller.php
1 year ago
pro_controller.php
1 year ago
process_jobs_controller.php
1 year ago
processes_controller.php
1 year ago
search_controller.php
1 year ago
services_controller.php
1 year ago
settings_controller.php
1 year ago
steps_controller.php
1 year ago
stripe_connect_controller.php
1 year ago
support_topics_controller.php
1 year ago
todos_controller.php
1 year ago
transactions_controller.php
1 year ago
wizard_controller.php
1 year ago
settings_controller.php
314 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) { |
| 3 | exit; // Exit if accessed directly. |
| 4 | } |
| 5 | |
| 6 | |
| 7 | if (!class_exists('OsSettingsController')) : |
| 8 | |
| 9 | |
| 10 | class OsSettingsController extends OsController { |
| 11 | |
| 12 | |
| 13 | function __construct() { |
| 14 | parent::__construct(); |
| 15 | |
| 16 | $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'settings/'; |
| 17 | $this->vars['page_header'] = OsMenuHelper::get_menu_items_by_id('settings'); |
| 18 | $this->vars['pre_page_header'] = OsMenuHelper::get_label_by_id('settings'); |
| 19 | $this->vars['breadcrumbs'][] = array('label' => __('Settings', 'latepoint'), 'link' => OsRouterHelper::build_link(OsRouterHelper::build_route_name('settings', 'general'))); |
| 20 | } |
| 21 | |
| 22 | public function version_5_intro(){ |
| 23 | |
| 24 | $this->set_layout('full_modal'); |
| 25 | $this->format_render(__FUNCTION__); |
| 26 | } |
| 27 | |
| 28 | public function steps_order_modal(){ |
| 29 | $this->vars['steps'] = OsStepsHelper::unflatten_steps(OsStepsHelper::get_step_codes_in_order(true)); |
| 30 | |
| 31 | $this->format_render(__FUNCTION__); |
| 32 | } |
| 33 | |
| 34 | public function update_steps_order(){ |
| 35 | $new_order = explode(',', $this->params['steps_order']); |
| 36 | $errors = []; |
| 37 | |
| 38 | if($new_order){ |
| 39 | $errors = OsStepsHelper::check_steps_for_errors($new_order, OsStepsHelper::get_step_codes_with_rules()); |
| 40 | if(empty($errors)) OsStepsHelper::save_step_codes_in_order($new_order); |
| 41 | } |
| 42 | |
| 43 | if(empty($errors)){ |
| 44 | $status = LATEPOINT_STATUS_SUCCESS; |
| 45 | $message = __('Order of steps has been successfully updated', 'latepoint'); |
| 46 | }else{ |
| 47 | $status = LATEPOINT_STATUS_ERROR; |
| 48 | $message = implode(', ', $errors); |
| 49 | } |
| 50 | |
| 51 | if ($this->get_return_format() == 'json') { |
| 52 | $this->send_json(array('status' => $status, 'message' => $message)); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | |
| 57 | public function set_menu_layout_style() { |
| 58 | $menu_layout_style = (isset($this->params['menu_layout_style']) && in_array($this->params['menu_layout_style'], ['full', 'compact'])) ? $this->params['menu_layout_style'] : 'full'; |
| 59 | OsSettingsHelper::set_menu_layout_style($menu_layout_style); |
| 60 | |
| 61 | if ($this->get_return_format() == 'json') { |
| 62 | $this->send_json(array('status' => LATEPOINT_STATUS_SUCCESS, 'message' => '')); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | public function notifications() { |
| 67 | $this->vars['notification_types'] = OsNotificationsHelper::get_available_notification_types(); |
| 68 | $this->format_render(__FUNCTION__); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | public function pages() { |
| 73 | $this->vars['breadcrumbs'][] = array('label' => __('Pages Setup', 'latepoint'), 'link' => false); |
| 74 | |
| 75 | $pages = get_pages(); |
| 76 | |
| 77 | $this->vars['pages'] = $pages; |
| 78 | |
| 79 | $this->format_render(__FUNCTION__); |
| 80 | } |
| 81 | |
| 82 | public function payments() { |
| 83 | $this->vars['breadcrumbs'][] = array('label' => __('Payment Processing', 'latepoint'), 'link' => false); |
| 84 | |
| 85 | $pages = get_pages(); |
| 86 | |
| 87 | $this->vars['pages'] = $pages; |
| 88 | $this->vars['payment_processors'] = OsPaymentsHelper::get_payment_processors(); |
| 89 | |
| 90 | $this->format_render(__FUNCTION__); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | public function work_periods() { |
| 95 | |
| 96 | $this->vars['breadcrumbs'][] = array('label' => __('Work Schedule Settings', 'latepoint'), 'link' => false); |
| 97 | |
| 98 | $this->format_render(__FUNCTION__); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | public function general() { |
| 103 | |
| 104 | $this->vars['breadcrumbs'][] = array('label' => __('General', 'latepoint'), 'link' => false); |
| 105 | |
| 106 | |
| 107 | $this->format_render(__FUNCTION__); |
| 108 | } |
| 109 | |
| 110 | public function remove_chain_schedule() { |
| 111 | $chain_id = $this->params['chain_id']; |
| 112 | if ($chain_id && OsWorkPeriodsHelper::remove_periods_for_chain_id($chain_id)) { |
| 113 | $response_html = __('Date Range Schedule Removed', 'latepoint'); |
| 114 | $status = LATEPOINT_STATUS_SUCCESS; |
| 115 | } else { |
| 116 | $response_html = __('Invalid Data', 'latepoint'); |
| 117 | $status = LATEPOINT_STATUS_ERROR; |
| 118 | } |
| 119 | |
| 120 | if ($this->get_return_format() == 'json') { |
| 121 | $this->send_json(array('status' => $status, 'message' => $response_html)); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | public function remove_custom_day_schedule() { |
| 126 | $target_date_string = $this->params['date']; |
| 127 | $args = []; |
| 128 | $args['agent_id'] = isset($this->params['agent_id']) ? $this->params['agent_id'] : 0; |
| 129 | $args['service_id'] = isset($this->params['service_id']) ? $this->params['service_id'] : 0; |
| 130 | $args['location_id'] = isset($this->params['location_id']) ? $this->params['location_id'] : 0; |
| 131 | if (OsUtilHelper::is_date_valid($target_date_string) && OsWorkPeriodsHelper::remove_periods_for_date($target_date_string, $args)) { |
| 132 | $response_html = __('Custom Day Schedule Removed', 'latepoint'); |
| 133 | $status = LATEPOINT_STATUS_SUCCESS; |
| 134 | } else { |
| 135 | $response_html = __('Invalid Date', 'latepoint'); |
| 136 | $status = LATEPOINT_STATUS_ERROR; |
| 137 | } |
| 138 | |
| 139 | if ($this->get_return_format() == 'json') { |
| 140 | $this->send_json(array('status' => $status, 'message' => $response_html)); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | |
| 145 | public function save_columns_for_bookings_table() { |
| 146 | $selected_columns = []; |
| 147 | if (isset($this->params['selected_columns']) && $this->params['selected_columns']) { |
| 148 | foreach ($this->params['selected_columns'] as $column_type => $columns) { |
| 149 | foreach ($columns as $column_key => $selected_column) { |
| 150 | if ($selected_column == 'on') { |
| 151 | $selected_columns[$column_type][] = $column_key; |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | OsSettingsHelper::save_setting_by_name('bookings_table_columns', $selected_columns); |
| 157 | if ($this->get_return_format() == 'json') { |
| 158 | $this->send_json(array('status' => LATEPOINT_STATUS_SUCCESS, 'message' => __('Columns Saved', 'latepoint'))); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | public function save_custom_day_schedule() { |
| 163 | $this->check_nonce('save_custom_day_schedule'); |
| 164 | $response_html = __('Work Schedule Updated', 'latepoint'); |
| 165 | $status = LATEPOINT_STATUS_SUCCESS; |
| 166 | $day_date = new OsWpDateTime($this->params['start_custom_date']); |
| 167 | // if end date is provided and is range |
| 168 | $period_type = ($this->params['period_type'] == 'range' && $this->params['end_custom_date']) ? 'range' : 'single'; |
| 169 | |
| 170 | $start_date = new OsWpDateTime($this->params['start_custom_date']); |
| 171 | $end_date = ($period_type == 'range') ? new OsWpDateTime($this->params['end_custom_date']) : $start_date; |
| 172 | $chain_id = (isset($this->params['chain_id'])) ? $this->params['chain_id'] : false; |
| 173 | $existing_work_periods_ids = (isset($this->params['existing_work_periods_ids'])) ? $this->params['existing_work_periods_ids'] : false; |
| 174 | |
| 175 | // remove existing chained periods by chain ID |
| 176 | if ($chain_id) { |
| 177 | $work_periods_to_delete = new OsWorkPeriodModel(); |
| 178 | $work_periods_to_delete->delete_where(['chain_id' => $chain_id]); |
| 179 | if ($period_type == 'single') $chain_id = false; |
| 180 | } else { |
| 181 | $chain_id = ($period_type == 'range') ? uniqid() : false; |
| 182 | } |
| 183 | |
| 184 | // remove existing periods by period ID |
| 185 | if ($existing_work_periods_ids) { |
| 186 | $work_periods_to_delete = new OsWorkPeriodModel(); |
| 187 | $delete_ids = explode(',', $existing_work_periods_ids); |
| 188 | foreach ($delete_ids as $delete_id) { |
| 189 | $work_periods_to_delete->delete_where(['id' => $delete_id]); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | for ($day_date = clone $start_date; $day_date <= $end_date; $day_date->modify('+1 day')) { |
| 194 | $work_periods = $this->params['work_periods']; |
| 195 | foreach ($work_periods as &$work_period) { |
| 196 | $work_period['custom_date'] = $day_date->format('Y-m-d'); |
| 197 | $work_period['week_day'] = $day_date->format('N'); |
| 198 | $work_period['chain_id'] = $chain_id ? $chain_id : null; |
| 199 | } |
| 200 | unset($work_period); |
| 201 | |
| 202 | OsWorkPeriodsHelper::save_work_periods($work_periods, true); |
| 203 | } |
| 204 | |
| 205 | if ($this->get_return_format() == 'json') { |
| 206 | $this->send_json(array('status' => $status, 'message' => $response_html)); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | |
| 211 | public function custom_day_schedule_form() { |
| 212 | $target_date_string = isset($this->params['target_date']) ? $this->params['target_date'] : 'now + 1 month'; |
| 213 | $this->vars['date_is_preselected'] = isset($this->params['target_date']); |
| 214 | $this->vars['target_date'] = new OsWpDateTime($target_date_string); |
| 215 | $this->vars['day_off'] = isset($this->params['day_off']) ? true : false; |
| 216 | $this->vars['agent_id'] = isset($this->params['agent_id']) ? $this->params['agent_id'] : 0; |
| 217 | $this->vars['service_id'] = isset($this->params['service_id']) ? $this->params['service_id'] : 0; |
| 218 | $this->vars['location_id'] = isset($this->params['location_id']) ? $this->params['location_id'] : 0; |
| 219 | $chain_id = isset($this->params['chain_id']) ? $this->params['chain_id'] : false; |
| 220 | $this->vars['chain_id'] = $chain_id; |
| 221 | $this->vars['chain_end_date'] = false; |
| 222 | if ($chain_id) { |
| 223 | $work_period = new OsWorkPeriodModel(); |
| 224 | $chained_work_period = $work_period->where(['chain_id' => $chain_id])->order_by('custom_date desc')->set_limit(1)->get_results_as_models(); |
| 225 | if ($chained_work_period) { |
| 226 | $this->vars['chain_end_date'] = new OsWpDateTime($chained_work_period->custom_date); |
| 227 | } else { |
| 228 | $this->vars['chain_id'] = false; |
| 229 | } |
| 230 | } |
| 231 | $this->format_render(__FUNCTION__); |
| 232 | } |
| 233 | |
| 234 | |
| 235 | public function update_work_periods() { |
| 236 | $this->check_nonce('update_work_periods'); |
| 237 | OsWorkPeriodsHelper::save_work_periods($this->params['work_periods']); |
| 238 | $response_html = __('Work Schedule Updated', 'latepoint'); |
| 239 | $status = LATEPOINT_STATUS_SUCCESS; |
| 240 | |
| 241 | if ($this->get_return_format() == 'json') { |
| 242 | $this->send_json(array('status' => $status, 'message' => $response_html)); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | |
| 247 | public function update() { |
| 248 | $this->check_nonce('update_settings'); |
| 249 | $errors = array(); |
| 250 | |
| 251 | if ($this->params['settings']) { |
| 252 | // make sure thousands and decimal separator are not the same symbol |
| 253 | if (isset($this->params['settings']['thousand_separator']) && isset($this->params['settings']['decimal_separator']) && ($this->params['settings']['thousand_separator'] == $this->params['settings']['decimal_separator'])) { |
| 254 | $this->params['settings']['thousand_separator'] = ''; |
| 255 | } |
| 256 | foreach ($this->params['settings'] as $setting_name => $setting_value) { |
| 257 | $setting = new OsSettingsModel(); |
| 258 | $setting = $setting->load_by_name($setting_name); |
| 259 | $is_new_record = $setting->is_new_record(); |
| 260 | if (!$is_new_record) $old_setting_value = $setting->value; |
| 261 | $setting->name = $setting_name; |
| 262 | $setting->value = OsSettingsHelper::prepare_value($setting_name, $setting_value); |
| 263 | if ($setting->save()) { |
| 264 | if ($is_new_record) { |
| 265 | do_action('latepoint_setting_created', $setting); |
| 266 | } else { |
| 267 | do_action('latepoint_setting_updated', $setting, $old_setting_value); |
| 268 | } |
| 269 | } else { |
| 270 | $errors[] = $setting->get_error_messages(); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | do_action('latepoint_settings_updated', $this->params['settings']); |
| 275 | } |
| 276 | |
| 277 | if (empty($errors)) { |
| 278 | $response_html = esc_html__('Settings Updated', 'latepoint'); |
| 279 | $status = LATEPOINT_STATUS_SUCCESS; |
| 280 | } else { |
| 281 | $response_html = esc_html__('Settings Updated With Errors:', 'latepoint') . implode(', ', $errors); |
| 282 | $status = LATEPOINT_STATUS_ERROR; |
| 283 | } |
| 284 | |
| 285 | if ($this->get_return_format() == 'json') { |
| 286 | $this->send_json(array('status' => $status, 'message' => $response_html)); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | public function load_step_settings() { |
| 291 | |
| 292 | } |
| 293 | |
| 294 | |
| 295 | public function load_work_period_form() { |
| 296 | $args = ['week_day' => 1, 'agent_id' => 0, 'service_id' => 0, 'location_id' => 0]; |
| 297 | |
| 298 | if (isset($this->params['week_day'])) $args['week_day'] = $this->params['week_day']; |
| 299 | if (isset($this->params['agent_id'])) $args['agent_id'] = $this->params['agent_id']; |
| 300 | if (isset($this->params['service_id'])) $args['service_id'] = $this->params['service_id']; |
| 301 | if (isset($this->params['location_id'])) $args['location_id'] = $this->params['location_id']; |
| 302 | |
| 303 | $response_html = OsWorkPeriodsHelper::generate_work_period_form($args); |
| 304 | $status = LATEPOINT_STATUS_SUCCESS; |
| 305 | |
| 306 | if ($this->get_return_format() == 'json') { |
| 307 | $this->send_json(array('status' => $status, 'message' => $response_html)); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | } |
| 312 | |
| 313 | |
| 314 | endif; |