activities_controller.php
11 months ago
auth_controller.php
9 months ago
booking_form_settings_controller.php
1 year ago
bookings_controller.php
1 year ago
calendars_controller.php
9 months ago
carts_controller.php
1 year ago
controller.php
9 months ago
customer_cabinet_controller.php
9 months ago
customers_controller.php
9 months ago
dashboard_controller.php
9 months ago
default_agent_controller.php
1 year ago
events_controller.php
1 year ago
form_fields_controller.php
9 months ago
integrations_controller.php
9 months 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
9 months ago
processes_controller.php
1 year ago
search_controller.php
1 year ago
services_controller.php
9 months ago
settings_controller.php
1 year ago
steps_controller.php
9 months ago
stripe_connect_controller.php
9 months 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
default_agent_controller.php
89 lines
| 1 | <?php |
| 2 | /* |
| 3 | * Copyright (c) 2024 LatePoint LLC. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | exit; // Exit if accessed directly. |
| 8 | } |
| 9 | |
| 10 | |
| 11 | if ( ! class_exists( 'OsDefaultAgentController' ) ) : |
| 12 | |
| 13 | |
| 14 | class OsDefaultAgentController extends OsController { |
| 15 | |
| 16 | |
| 17 | |
| 18 | function __construct(){ |
| 19 | parent::__construct(); |
| 20 | |
| 21 | $this->views_folder = plugin_dir_path( __FILE__ ) . '../views/default_agent/'; |
| 22 | $this->vars['page_header'] = OsMenuHelper::get_menu_items_by_id( 'agents' ); |
| 23 | $this->vars['breadcrumbs'][] = array('label' => __('Agent', 'latepoint'), 'link' => OsRouterHelper::build_link(OsRouterHelper::build_route_name('agents', 'index') ) ); |
| 24 | } |
| 25 | |
| 26 | |
| 27 | |
| 28 | /* |
| 29 | Edit agent |
| 30 | */ |
| 31 | |
| 32 | public function edit_form(){ |
| 33 | $agent = OsAgentHelper::get_default_agent(); |
| 34 | |
| 35 | if(!OsAuthHelper::get_current_user()->check_if_allowed_record_id($agent->id, 'agent')) $this->access_not_allowed(); |
| 36 | |
| 37 | $this->vars['page_header'] = __('Agents', 'latepoint'); |
| 38 | $this->vars['breadcrumbs'][] = array('label' => __('Agents', 'latepoint'), 'link' => false ); |
| 39 | |
| 40 | if($agent->id){ |
| 41 | |
| 42 | $this->vars['agent'] = $agent; |
| 43 | |
| 44 | } |
| 45 | |
| 46 | $this->format_render(__FUNCTION__); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | public function update(){ |
| 51 | $is_new_record = (isset($this->params['agent']['id']) && $this->params['agent']['id']) ? false : true; |
| 52 | |
| 53 | $this->check_nonce($is_new_record ? 'new_agent' : 'edit_agent_'. $this->params['agent']['id']); |
| 54 | $agent = new OsAgentModel(); |
| 55 | $agent->set_data($this->params['agent']); |
| 56 | $agent->set_features($this->params['agent']['features']); |
| 57 | $extra_response_vars = array(); |
| 58 | |
| 59 | if($agent->save() && (empty($this->params['agent']['services']) || $agent->save_locations_and_services($this->params['agent']['services']))){ |
| 60 | if($is_new_record){ |
| 61 | $response_html = __('Agent Created. ID:', 'latepoint') . $agent->id; |
| 62 | OsActivitiesHelper::create_activity(array('code' => 'agent_create', 'agent_id' => $agent->id)); |
| 63 | }else{ |
| 64 | $response_html = __('Agent Updated. ID:', 'latepoint') . $agent->id; |
| 65 | OsActivitiesHelper::create_activity(array('code' => 'agent_update', 'agent_id' => $agent->id)); |
| 66 | } |
| 67 | $status = LATEPOINT_STATUS_SUCCESS; |
| 68 | // save schedules |
| 69 | if($this->params['is_custom_schedule'] == 'on'){ |
| 70 | $agent->save_custom_schedule($this->params['work_periods']); |
| 71 | }elseif($this->params['is_custom_schedule'] == 'off'){ |
| 72 | $agent->delete_custom_schedule(); |
| 73 | } |
| 74 | $extra_response_vars['record_id'] = $agent->id; |
| 75 | do_action('latepoint_agent_saved', $agent, $is_new_record, $this->params['agent']); |
| 76 | }else{ |
| 77 | $response_html = $agent->get_error_messages(); |
| 78 | $status = LATEPOINT_STATUS_ERROR; |
| 79 | } |
| 80 | if($this->get_return_format() == 'json'){ |
| 81 | $this->send_json(array('status' => $status, 'message' => $response_html) + $extra_response_vars); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | |
| 86 | } |
| 87 | |
| 88 | |
| 89 | endif; |