Major refactoring and improvements to the application API code.

This commit is contained in:
Alex Tselegidis 2020-04-22 21:48:56 +02:00
parent d67b622d65
commit 39956c6b37
85 changed files with 3623 additions and 2707 deletions

View file

@ -81,7 +81,7 @@ $autoload['helper'] = ['custom_exceptions', 'url', 'file', 'language', 'asset',
|
*/
$autoload['config'] = [];
$autoload['config'] = ['google', 'email'];
/*

View file

@ -10,7 +10,7 @@
*/
$config['version'] = '1.4.0'; // This must be changed manually.
$config['release_label'] = 'Dev'; // Leave empty for no title or add Alpha, Beta etc ...
$config['google_sync_feature'] = Config::GOOGLE_SYNC_FEATURE;
$config['debug'] = Config::DEBUG_MODE;
/*
|--------------------------------------------------------------------------

View file

@ -0,0 +1,17 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Google Calendar - Internal Configuration
|--------------------------------------------------------------------------
|
| Declare some of the global config values of the Google Calendar
| synchronization feature.
|
*/
$config['google_sync_feature'] = Config::GOOGLE_SYNC_FEATURE;
$config['google_product_name'] = Config::GOOGLE_PRODUCT_NAME;
$config['google_client_id'] = Config::GOOGLE_CLIENT_ID;
$config['google_client_secret'] = Config::GOOGLE_CLIENT_SECRET;
$config['google_api_key'] = Config::GOOGLE_API_KEY;

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,6 +14,28 @@
/**
* Backend Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
*/
class Backend extends CI_Controller {
@ -25,15 +47,16 @@ class Backend extends CI_Controller {
parent::__construct();
$this->load->library('session');
// Set user's selected language.
if ($this->session->userdata('language'))
{
// Set user's selected language.
$this->config->set_item('language', $this->session->userdata('language'));
$this->lang->load('translations', $this->session->userdata('language'));
}
else
{
$this->lang->load('translations', $this->config->item('language')); // default
// Set the default language.
$this->lang->load('translations', $this->config->item('language'));
}
}
@ -45,12 +68,14 @@ class Backend extends CI_Controller {
* menus at the top of the page.
*
* @param string $appointment_hash Appointment edit dialog will appear when the page loads (default '').
*
* @throws Exception
*/
public function index($appointment_hash = '')
{
$this->session->set_userdata('dest_url', site_url('backend'));
if ( ! $this->_has_privileges(PRIV_APPOINTMENTS))
if ( ! $this->has_privileges(PRIV_APPOINTMENTS))
{
return;
}
@ -76,7 +101,7 @@ class Backend extends CI_Controller {
$view['available_providers'] = $this->providers_model->get_available_providers();
$view['available_services'] = $this->services_model->get_available_services();
$view['customers'] = $this->customers_model->get_batch();
$user = $this->user_model->get_settings($this->session->userdata('user_id'));
$user = $this->user_model->get_user($this->session->userdata('user_id'));
$view['calendar_view'] = $user['settings']['calendar_view'];
$view['timezones'] = $this->timezones_model->to_array();
$this->set_user_data($view);
@ -109,6 +134,72 @@ class Backend extends CI_Controller {
$this->load->view('backend/footer', $view);
}
/**
* Check whether current user is logged in and has the required privileges to view a page.
*
* The backend page requires different privileges from the users to display pages. Not all pages are available to
* all users. For example secretaries should not be able to edit the system users.
*
* @param string $page This argument must match the roles field names of each section (eg "appointments", "users"
* ...).
* @param bool $redirect If the user has not the required privileges (either not logged in or insufficient role
* privileges) then the user will be redirected to another page. Set this argument to FALSE when using ajax (default
* true).
*
* @return bool Returns whether the user has the required privileges to view the page or not. If the user is not
* logged in then he will be prompted to log in. If he hasn't the required privileges then an info message will be
* displayed.
*/
protected function has_privileges($page, $redirect = TRUE)
{
// Check if user is logged in.
$user_id = $this->session->userdata('user_id');
if ($user_id == FALSE)
{
// User not logged in, display the login view.
if ($redirect)
{
header('Location: ' . site_url('user/login'));
}
return FALSE;
}
// Check if the user has the required privileges for viewing the selected page.
$role_slug = $this->session->userdata('role_slug');
$role_privileges = $this->db->get_where('ea_roles', ['slug' => $role_slug])->row_array();
if ($role_privileges[$page] < PRIV_VIEW)
{
// User does not have the permission to view the page.
if ($redirect)
{
header('Location: ' . site_url('user/no_privileges'));
}
return FALSE;
}
return TRUE;
}
/**
* Set the user data in order to be available at the view and js code.
*
* @param array $view Contains the view data.
*/
protected function set_user_data(&$view)
{
$this->load->model('roles_model');
// Get privileges
$view['user_id'] = $this->session->userdata('user_id');
$view['user_email'] = $this->session->userdata('user_email');
$view['timezone'] = $this->session->userdata('timezone');
$view['role_slug'] = $this->session->userdata('role_slug');
$view['privileges'] = $this->roles_model->get_privileges($this->session->userdata('role_slug'));
}
/**
* Display the backend customers page.
*
@ -118,7 +209,7 @@ class Backend extends CI_Controller {
{
$this->session->set_userdata('dest_url', site_url('backend/customers'));
if ( ! $this->_has_privileges(PRIV_CUSTOMERS))
if ( ! $this->has_privileges(PRIV_CUSTOMERS))
{
return;
}
@ -173,7 +264,7 @@ class Backend extends CI_Controller {
{
$this->session->set_userdata('dest_url', site_url('backend/services'));
if ( ! $this->_has_privileges(PRIV_SERVICES))
if ( ! $this->has_privileges(PRIV_SERVICES))
{
return;
}
@ -211,7 +302,7 @@ class Backend extends CI_Controller {
{
$this->session->set_userdata('dest_url', site_url('backend/users'));
if ( ! $this->_has_privileges(PRIV_USERS))
if ( ! $this->has_privileges(PRIV_USERS))
{
return;
}
@ -255,8 +346,8 @@ class Backend extends CI_Controller {
public function settings()
{
$this->session->set_userdata('dest_url', site_url('backend/settings'));
if ( ! $this->_has_privileges(PRIV_SYSTEM_SETTINGS, FALSE)
&& ! $this->_has_privileges(PRIV_USER_SETTINGS))
if ( ! $this->has_privileges(PRIV_SYSTEM_SETTINGS, FALSE)
&& ! $this->has_privileges(PRIV_USER_SETTINGS))
{
return;
}
@ -277,7 +368,7 @@ class Backend extends CI_Controller {
$view['time_format'] = $this->settings_model->get_setting('time_format');
$view['role_slug'] = $this->session->userdata('role_slug');
$view['system_settings'] = $this->settings_model->get_settings();
$view['user_settings'] = $this->user_model->get_settings($user_id);
$view['user_settings'] = $this->user_model->get_user($user_id);
$view['timezones'] = $this->timezones_model->to_array();
$this->set_user_data($view);
@ -286,52 +377,6 @@ class Backend extends CI_Controller {
$this->load->view('backend/footer', $view);
}
/**
* Check whether current user is logged in and has the required privileges to view a page.
*
* The backend page requires different privileges from the users to display pages. Not all pages are available to
* all users. For example secretaries should not be able to edit the system users.
*
* @see Constant definition in application/config/constants.php.
*
* @param string $page This argument must match the roles field names of each section (eg "appointments", "users"
* ...).
* @param bool $redirect If the user has not the required privileges (either not logged in or insufficient role
* privileges) then the user will be redirected to another page. Set this argument to FALSE when using ajax (default
* true).
*
* @return bool Returns whether the user has the required privileges to view the page or not. If the user is not
* logged in then he will be prompted to log in. If he hasn't the required privileges then an info message will be
* displayed.
*/
protected function _has_privileges($page, $redirect = TRUE)
{
// Check if user is logged in.
$user_id = $this->session->userdata('user_id');
if ($user_id == FALSE)
{ // User not logged in, display the login view.
if ($redirect)
{
header('Location: ' . site_url('user/login'));
}
return FALSE;
}
// Check if the user has the required privileges for viewing the selected page.
$role_slug = $this->session->userdata('role_slug');
$role_priv = $this->db->get_where('ea_roles', ['slug' => $role_slug])->row_array();
if ($role_priv[$page] < PRIV_VIEW)
{ // User does not have the permission to view the page.
if ($redirect)
{
header('Location: ' . site_url('user/no_privileges'));
}
return FALSE;
}
return TRUE;
}
/**
* This method will update the installation to the latest available version in the server.
*
@ -345,7 +390,7 @@ class Backend extends CI_Controller {
{
try
{
if ( ! $this->_has_privileges(PRIV_SYSTEM_SETTINGS, TRUE))
if ( ! $this->has_privileges(PRIV_SYSTEM_SETTINGS, TRUE))
{
throw new Exception('You do not have the required privileges for this task!');
}
@ -359,28 +404,11 @@ class Backend extends CI_Controller {
$view = ['success' => TRUE];
}
catch (Exception $exc)
catch (Exception $exception)
{
$view = ['success' => FALSE, 'exception' => $exc->getMessage()];
$view = ['success' => FALSE, 'exception' => $exception->getMessage()];
}
$this->load->view('general/update', $view);
}
/**
* Set the user data in order to be available at the view and js code.
*
* @param array $view Contains the view data.
*/
protected function set_user_data(&$view)
{
$this->load->model('roles_model');
// Get privileges
$view['user_id'] = $this->session->userdata('user_id');
$view['user_email'] = $this->session->userdata('user_email');
$view['timezone'] = $this->session->userdata('timezone');
$view['role_slug'] = $this->session->userdata('role_slug');
$view['privileges'] = $this->roles_model->get_privileges($this->session->userdata('role_slug'));
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,6 +14,28 @@
/**
* Captcha Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
*/
class Captcha extends CI_Controller {

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -15,6 +15,31 @@
* Class Consent
*
* Handles user consent related operations.
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Consents_Model consents_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
*/
class Consents extends CI_Controller {
/**
@ -24,28 +49,31 @@ class Consents extends CI_Controller {
{
try
{
$consent = $this->input->post('consent');
$this->load->model('consents_model');
$consent = $this->input->post('consent');
$consent['ip'] = $this->input->ip_address();
$consent['id'] = $this->consents_model->add($consent);
$this->output
->set_content_type('application/json')
->set_output(json_encode([
'success' => TRUE,
'id' => $consent['id']
]));
$response = [
'success' => TRUE,
'id' => $consent['id']
];
}
catch (Exception $exc)
catch (Exception $exception)
{
$this->output
->set_content_type('application/json')
->set_output(json_encode([
'exceptions' => [exceptionToJavaScript($exc)]
]));
$this->output->set_status_header(500);
$response = [
'message' => $exception->getMessage(),
'trace' => config('debug') ? $exception->getTrace() : []
];
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($response));
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,6 +14,28 @@
/**
* Errors Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
*/
class Errors extends CI_Controller {
@ -26,15 +48,16 @@ class Errors extends CI_Controller {
$this->load->library('session');
// Set user's selected language.
if ($this->session->userdata('language'))
{
// Set user's selected language.
$this->config->set_item('language', $this->session->userdata('language'));
$this->lang->load('translations', $this->session->userdata('language'));
}
else
{
$this->lang->load('translations', $this->config->item('language')); // default
// Set the default language.
$this->lang->load('translations', $this->config->item('language'));
}
}
@ -43,7 +66,7 @@ class Errors extends CI_Controller {
*/
public function index()
{
$this->e404();
$this->error404();
}
/**
@ -53,7 +76,9 @@ class Errors extends CI_Controller {
{
$this->load->helper('google_analytics');
$this->load->model('settings_model');
$view['company_name'] = $this->settings_model->get_setting('company_name');
$this->load->view('general/error404', $view);
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -16,6 +16,28 @@
*
* This controller handles the Google Calendar synchronization operations.
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
*/
class Google extends CI_Controller {
@ -39,10 +61,10 @@ class Google extends CI_Controller {
public function oauth($provider_id)
{
// Store the provider id for use on the callback function.
$_SESSION['oauth_provider_id'] = $provider_id;
$this->session->set_userdata('oauth_provider_id', $provider_id);
// Redirect browser to google user content page.
$this->load->library('Google_sync');
$this->load->library('google_sync');
header('Location: ' . $this->google_sync->get_auth_url());
}
@ -55,7 +77,7 @@ class Google extends CI_Controller {
*
* IMPORTANT: Because it is necessary to authorize the application using the web server flow (see official
* documentation of OAuth), every Easy!Appointments installation should use its own calendar api key. So in every
* api console account, the "http://path-to-e!a/google/oauth_callback" should be included in an allowed redirect URL.
* api console account, the "http://path-to-Easy!Appointments/google/oauth_callback" should be included in an allowed redirect URL.
*/
public function oauth_callback()
{
@ -65,12 +87,14 @@ class Google extends CI_Controller {
$token = $this->google_sync->authenticate($this->input->get('code'));
// Store the token into the database for future reference.
if (isset($_SESSION['oauth_provider_id']))
$oauth_provider_id = $this->session->userdata('oauth_provider_id');
if ($oauth_provider_id)
{
$this->load->model('providers_model');
$this->providers_model->set_setting('google_sync', TRUE, $_SESSION['oauth_provider_id']);
$this->providers_model->set_setting('google_token', $token, $_SESSION['oauth_provider_id']);
$this->providers_model->set_setting('google_calendar', 'primary', $_SESSION['oauth_provider_id']);
$this->providers_model->set_setting('google_sync', TRUE, $oauth_provider_id);
$this->providers_model->set_setting('google_token', $token, $oauth_provider_id);
$this->providers_model->set_setting('google_calendar', 'primary', $oauth_provider_id);
}
else
{
@ -149,7 +173,7 @@ class Google extends CI_Controller {
'company_email' => $this->settings_model->get_setting('company_email')
];
$provider_timezone = new \DateTimeZone($provider['timezone']);
$provider_timezone = new DateTimeZone($provider['timezone']);
// Sync each appointment with Google Calendar by following the project's sync protocol (see documentation).
foreach ($appointments as $appointment)
@ -165,13 +189,13 @@ class Google extends CI_Controller {
$customer = NULL;
}
// If current appointment not synced yet, add to gcal.
// If current appointment not synced yet, add to Google Calendar.
if ($appointment['id_google_calendar'] == NULL)
{
$google_event = $this->google_sync->add_appointment($appointment, $provider,
$service, $customer, $company_settings);
$appointment['id_google_calendar'] = $google_event->id;
$this->appointments_model->add($appointment); // Save gcal id
$this->appointments_model->add($appointment); // Save the Google Calendar ID.
}
else
{
@ -185,13 +209,14 @@ class Google extends CI_Controller {
throw new Exception('Event is cancelled, remove the record from Easy!Appointments.');
}
// If gcal event is different from e!a appointment then update e!a record.
// If Google Calendar event is different from Easy!Appointments appointment then update
// Easy!Appointments record.
$is_different = FALSE;
$appt_start = strtotime($appointment['start_datetime']);
$appt_end = strtotime($appointment['end_datetime']);
$event_start = new \DateTime($google_event->getStart()->getDateTime());
$event_start = new DateTime($google_event->getStart()->getDateTime());
$event_start->setTimezone($provider_timezone);
$event_end = new \DateTime($google_event->getEnd()->getDateTime());
$event_end = new DateTime($google_event->getEnd()->getDateTime());
$event_end->setTimezone($provider_timezone);
@ -210,49 +235,52 @@ class Google extends CI_Controller {
}
}
catch (Exception $exc)
catch (Exception $exception)
{
// Appointment not found on gcal, delete from e!a.
// Appointment not found on Google Calendar, delete from Easy!Appoinmtents.
$this->appointments_model->delete($appointment['id']);
$appointment['id_google_calendar'] = NULL;
}
}
}
// :: ADD GCAL EVENTS THAT ARE NOT PRESENT ON E!A
// Add Google Calendar events that do not exist in Easy!Appointments.
$google_calendar = $provider['settings']['google_calendar'];
$events = $this->google_sync->get_sync_events($google_calendar, $start, $end);
$google_events = $this->google_sync->get_sync_events($google_calendar, $start, $end);
foreach ($events->getItems() as $event)
foreach ($google_events->getItems() as $google_event)
{
if ($event->getStatus() === 'cancelled') {
if ($google_event->getStatus() === 'cancelled')
{
continue;
}
if ($event->getStart() === null || $event->getEnd() === null) {
if ($google_event->getStart() === NULL || $google_event->getEnd() === NULL)
{
continue;
}
$results = $this->appointments_model->get_batch(['id_google_calendar' => $event->getId()]);
$results = $this->appointments_model->get_batch(['id_google_calendar' => $google_event->getId()]);
if (!empty($results)) {
if ( ! empty($results))
{
continue;
}
$event_start = new \DateTime($event->getStart()->getDateTime());
$event_start = new DateTime($google_event->getStart()->getDateTime());
$event_start->setTimezone($provider_timezone);
$event_end = new \DateTime($event->getEnd()->getDateTime());
$event_end = new DateTime($google_event->getEnd()->getDateTime());
$event_end->setTimezone($provider_timezone);
// Record doesn't exist in E!A, so add the event now.
// Record doesn't exist in the Easy!Appointments, so add the event now.
$appointment = [
'start_datetime' => $event_start->format('Y-m-d H:i:s'),
'end_datetime' => $event_end->format('Y-m-d H:i:s'),
'is_unavailable' => TRUE,
'location' => $event->getLocation(),
'notes' => $event->getSummary() . ' ' . $event->getDescription(),
'location' => $google_event->getLocation(),
'notes' => $google_event->getSummary() . ' ' . $google_event->getDescription(),
'id_users_provider' => $provider_id,
'id_google_calendar' => $event->getId(),
'id_google_calendar' => $google_event->getId(),
'id_users_customer' => NULL,
'id_services' => NULL,
];
@ -260,15 +288,20 @@ class Google extends CI_Controller {
$this->appointments_model->add($appointment);
}
$this->output
->set_content_type('application/json')
->set_output(json_encode(AJAX_SUCCESS));
$response = AJAX_SUCCESS;
}
catch (Exception $exc)
catch (Exception $exception)
{
$this->output
->set_content_type('application/json')
->set_output(json_encode(['exceptions' => [exceptionToJavaScript($exc)]]));
$this->output->set_status_header(500);
$response = [
'message' => $exception->getMessage(),
'trace' => config('debug') ? $exception->getTrace() : []
];
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($response));
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,7 +14,29 @@
/**
* Installation Controller
*
* This controller will handle the installation procedure of Easy!Appointments
* This controller will handle the installation procedure of Easy!Appointments.
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
*/
@ -25,18 +47,20 @@ class Installation extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('installation');
$this->load->library('session');
// Set user's selected language.
if ($this->session->userdata('language'))
{
// Set user's selected language.
$this->config->set_item('language', $this->session->userdata('language'));
$this->lang->load('translations', $this->session->userdata('language'));
}
else
{
$this->lang->load('translations', $this->config->item('language')); // default
// Set the default language.
$this->lang->load('translations', $this->config->item('language'));
}
}
@ -58,11 +82,6 @@ class Installation extends CI_Controller {
/**
* [AJAX] Installs Easy!Appointments on the server.
*
* Required POST Parameters
*
* - array $_POST['admin'] Contains the initial admin user data. The App needs at least one admin user to work.
* - array $_POST['company'] Contains the basic company data.
*/
public function ajax_install()
{
@ -73,7 +92,17 @@ class Installation extends CI_Controller {
return;
}
// Create E!A database structure.
$this->load->model('admins_model');
$this->load->model('settings_model');
$this->load->model('services_model');
$this->load->model('providers_model');
$this->load->library('session');
$admin = $this->input->post('admin');
$company = $this->input->post('company');
// Create the Easy!Appointments database structure.
$file_contents = file_get_contents(__DIR__ . '/../../assets/sql/structure.sql');
$sql_queries = explode(';', $file_contents);
array_pop($sql_queries);
@ -82,7 +111,7 @@ class Installation extends CI_Controller {
$this->db->query($query);
}
// Insert default E!A entries into the database.
// Insert default Easy!Appointments entries into the database.
$file_contents = file_get_contents(__DIR__ . '/../../assets/sql/data.sql');
$sql_queries = explode(';', $file_contents);
array_pop($sql_queries);
@ -92,47 +121,43 @@ class Installation extends CI_Controller {
}
// Insert admin
$this->load->model('admins_model');
$admin = $this->input->post('admin');
$admin['settings']['username'] = $admin['username'];
$admin['settings']['password'] = $admin['password'];
$admin['settings']['calendar_view'] = CALENDAR_VIEW_DEFAULT;
unset($admin['username'], $admin['password']);
$admin['id'] = $this->admins_model->add($admin);
$this->load->library('session');
$this->session->set_userdata('user_id', $admin['id']);
$this->session->set_userdata('user_email', $admin['email']);
$this->session->set_userdata('role_slug', DB_SLUG_ADMIN);
$this->session->set_userdata('username', $admin['settings']['username']);
// Save company settings
$this->load->model('settings_model');
$company = $this->input->post('company');
$this->settings_model->set_setting('company_name', $company['company_name']);
$this->settings_model->set_setting('company_email', $company['company_email']);
$this->settings_model->set_setting('company_link', $company['company_link']);
// Create sample records.
$this->load->model('services_model');
$this->load->model('providers_model');
$sample_service = get_sample_service();
$sample_service['id'] = $this->services_model->add($sample_service);
$sample_provider = get_sample_provider();
$sample_provider['services'][] = $sample_service['id'];
$this->providers_model->add($sample_provider);
$this->output
->set_content_type('application/json')
->set_output(json_encode(AJAX_SUCCESS));
$response = AJAX_SUCCESS;
}
catch (Exception $exc)
catch (Exception $exception)
{
$this->output
->set_content_type('application/json')
->set_output(json_encode(['exceptions' => [exceptionToJavaScript($exc)]]));
$this->output->set_status_header(500);
$response = [
'message' => $exception->getMessage(),
'trace' => config('debug') ? $exception->getTrace() : []
];
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($response));
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,6 +14,28 @@
/**
* Class Privacy
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
*/
class Privacy extends CI_Controller {
@ -37,26 +59,30 @@ class Privacy extends CI_Controller {
if (empty($customer_id))
{
throw new InvalidArgumentException('Customer ID could not be found, please reload the page and try again.');
throw new InvalidArgumentException('Customer ID could not be found, please reload the page '
. 'and try again.');
}
$this->load->model('customers_model');
$this->customers_model->delete($customer_id);
$this->output
->set_content_type('application/json')
->set_output(json_encode([
'success' => TRUE
]));
$response = [
'success' => TRUE
];
}
catch (Exception $exc)
catch (Exception $exception)
{
$this->output
->set_content_type('application/json')
->set_output(json_encode([
'exceptions' => [exceptionToJavaScript($exc)]
]));
$this->output->set_status_header(500);
$response = [
'message' => $exception->getMessage(),
'trace' => config('debug') ? $exception->getTrace() : []
];
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($response));
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,12 +11,35 @@
* @since v1.0.0
* ---------------------------------------------------------------------------- */
use \EA\Engine\Types\NonEmptyText;
use \EA\Engine\Types\Email;
use EA\Engine\Notifications\Email as EmailClient;
use EA\Engine\Types\Email;
use EA\Engine\Types\NonEmptyText;
/**
* User Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
*/
class User extends CI_Controller {
@ -26,16 +49,18 @@ class User extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('session');
// Set user's selected language.
if ($this->session->userdata('language'))
{
// Set user's selected language.
$this->config->set_item('language', $this->session->userdata('language'));
$this->lang->load('translations', $this->session->userdata('language'));
}
else
{
// Set the default language.
$this->lang->load('translations', $this->config->item('language')); // default
}
}
@ -52,6 +77,8 @@ class User extends CI_Controller {
/**
* Display the login page.
*
* @throws Exception
*/
public function login()
{
@ -66,6 +93,7 @@ class User extends CI_Controller {
}
$view['company_name'] = $this->settings_model->get_setting('company_name');
$this->load->view('user/login', $view);
}
@ -89,6 +117,7 @@ class User extends CI_Controller {
/**
* Display the "forgot password" page.
* @throws Exception
*/
public function forgot_password()
{
@ -100,6 +129,7 @@ class User extends CI_Controller {
/**
* Display the "not authorized" page.
* @throws Exception
*/
public function no_privileges()
{
@ -128,29 +158,33 @@ class User extends CI_Controller {
}
$this->load->model('user_model');
$user_data = $this->user_model->check_login($this->input->post('username'), $this->input->post('password'));
if ($user_data)
{
$this->session->set_userdata($user_data); // Save data on user's session.
$this->output
->set_content_type('application/json')
->set_output(json_encode(AJAX_SUCCESS));
$response = AJAX_SUCCESS;
}
else
{
$this->output
->set_content_type('application/json')
->set_output(json_encode(AJAX_FAILURE));
$response = AJAX_FAILURE;
}
}
catch (Exception $exc)
catch (Exception $exception)
{
$this->output
->set_content_type('application/json')
->set_output(json_encode(['exceptions' => [exceptionToJavaScript($exc)]]));
$this->output->set_status_header(500);
$response = [
'message' => $exception->getMessage(),
'trace' => config('debug') ? $exception->getTrace() : []
];
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($response));
}
/**
@ -175,13 +209,17 @@ class User extends CI_Controller {
$this->load->model('user_model');
$this->load->model('settings_model');
$new_password = $this->user_model->regenerate_password($this->input->post('username'),
$this->input->post('email'));
$new_password = $this->user_model->regenerate_password(
$this->input->post('username'),
$this->input->post('email')
);
if ($new_password != FALSE)
{
$this->config->load('email');
$email = new \EA\Engine\Notifications\Email($this, $this->config->config);
$email = new EmailClient($this, $this->config->config);
$company_settings = [
'company_name' => $this->settings_model->get_setting('company_name'),
'company_link' => $this->settings_model->get_setting('company_link'),
@ -192,15 +230,20 @@ class User extends CI_Controller {
$company_settings);
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($new_password != FALSE ? AJAX_SUCCESS : AJAX_FAILURE));
$response = $new_password != FALSE ? AJAX_SUCCESS : AJAX_FAILURE;
}
catch (Exception $exc)
catch (Exception $exception)
{
$this->output
->set_content_type('application/json')
->set_output(json_encode(['exceptions' => [exceptionToJavaScript($exc)]]));
$this->output->set_status_header(500);
$response = [
'message' => $exception->getMessage(),
'trace' => config('debug') ? $exception->getTrace() : []
];
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($response));
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,6 +11,7 @@
* @since v1.2.0
* ---------------------------------------------------------------------------- */
use EA\Engine\Api\V1\Authorization;
use EA\Engine\Types\NonEmptyText;
/**
@ -43,7 +44,7 @@ class API_V1_Controller extends CI_Controller {
$api_token = $this->settings_model->get_setting('api_token');
$authorization = new \EA\Engine\Api\V1\Authorization($this);
$authorization = new Authorization($this);
if ( ! empty($api_token) && $api_token === $this->_getBearerToken())
{
@ -59,7 +60,8 @@ class API_V1_Controller extends CI_Controller {
$username = new NonEmptyText($_SERVER['PHP_AUTH_USER']);
$password = new NonEmptyText($_SERVER['PHP_AUTH_PW']);
$authorization->basic($username, $password);
} catch (\Exception $exception)
}
catch (Exception $exception)
{
exit($this->_handleException($exception));
}
@ -96,13 +98,15 @@ class API_V1_Controller extends CI_Controller {
if (isset($_SERVER['Authorization']))
{
$headers = trim($_SERVER['Authorization']);
} else
}
else
{
if (isset($_SERVER['HTTP_AUTHORIZATION']))
{
//Nginx or fast CGI
$headers = trim($_SERVER['HTTP_AUTHORIZATION']);
} elseif (function_exists('apache_request_headers'))
}
elseif (function_exists('apache_request_headers'))
{
$requestHeaders = apache_request_headers();
// Server-side fix for bug in old Android versions (a nice side-effect of this fix means we don't care about capitalization for Authorization)
@ -132,9 +136,9 @@ class API_V1_Controller extends CI_Controller {
*
* Call this method from catch blocks of child controller callbacks.
*
* @param \Exception $exception Thrown exception to be outputted.
* @param Exception $exception Thrown exception to be outputted.
*/
protected function _handleException(\Exception $exception)
protected function _handleException(Exception $exception)
{
$error = [
'code' => $exception->getCode() ?: 500,

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -13,13 +13,35 @@
require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyText;
use EA\Engine\Api\V1\Request;
use EA\Engine\Api\V1\Response;
use EA\Engine\Types\NonEmptyText;
/**
* Admins Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
* @subpackage API
*/
@ -69,7 +91,7 @@ class Admins extends API_V1_Controller {
->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -82,7 +104,7 @@ class Admins extends API_V1_Controller {
{
try
{
// Insert the admin to the database.
// Insert the admin to the database.
$request = new Request();
$admin = $request->getBody();
$this->parser->decode($admin);
@ -100,7 +122,7 @@ class Admins extends API_V1_Controller {
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -115,7 +137,7 @@ class Admins extends API_V1_Controller {
{
try
{
// Update the admin record.
// Update the admin record.
$batch = $this->admins_model->get_batch('id = ' . $id);
if ($id !== NULL && count($batch) === 0)
@ -135,7 +157,7 @@ class Admins extends API_V1_Controller {
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -159,7 +181,7 @@ class Admins extends API_V1_Controller {
$response->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -13,13 +13,35 @@
require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyText;
use EA\Engine\Api\V1\Request;
use EA\Engine\Api\V1\Response;
use EA\Engine\Types\NonEmptyText;
/**
* Appointments Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
* @subpackage API
*/
@ -77,7 +99,7 @@ class Appointments extends API_V1_Controller {
->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
exit($this->_handleException($exception));
}
@ -108,7 +130,7 @@ class Appointments extends API_V1_Controller {
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (\Exception $exception)
catch (Exception $exception)
{
exit($this->_handleException($exception));
}
@ -143,7 +165,7 @@ class Appointments extends API_V1_Controller {
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
exit($this->_handleException($exception));
}
@ -167,7 +189,7 @@ class Appointments extends API_V1_Controller {
$response->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
exit($this->_handleException($exception));
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,11 +14,33 @@
require_once __DIR__ . '/API_V1_Controller.php';
require_once __DIR__ . '/../../Appointments.php';
use \EA\Engine\Types\UnsignedInteger;
use EA\Engine\Types\UnsignedInteger;
/**
* Availabilities Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
* @subpackage API
*/
@ -97,7 +119,7 @@ class Availabilities extends API_V1_Controller {
->set_content_type('application/json')
->set_output(json_encode($availableHours));
}
catch (\Exception $exception)
catch (Exception $exception)
{
exit($this->_handleException($exception));
}
@ -122,7 +144,8 @@ class Availabilities extends API_V1_Controller {
$provider_id,
$selected_date,
$exclude_appointments = []
) {
)
{
$this->load->model('appointments_model');
$this->load->model('providers_model');
@ -318,7 +341,8 @@ class Availabilities extends API_V1_Controller {
$service_duration,
$manage_mode = FALSE,
$availabilities_type = 'flexible'
) {
)
{
$this->load->model('settings_model');
$available_hours = [];
@ -358,7 +382,8 @@ class Availabilities extends API_V1_Controller {
$selected_date,
$service,
$provider
) {
)
{
$this->load->model('appointments_model');
$this->load->model('services_model');
$this->load->model('providers_model');

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -13,13 +13,35 @@
require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyText;
use EA\Engine\Api\V1\Request;
use EA\Engine\Api\V1\Response;
use EA\Engine\Types\NonEmptyText;
/**
* Categories Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
* @subpackage API
*/
@ -69,7 +91,7 @@ class Categories extends API_V1_Controller {
->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -82,7 +104,7 @@ class Categories extends API_V1_Controller {
{
try
{
// Insert the category to the database.
// Insert the category to the database.
$request = new Request();
$category = $request->getBody();
$this->parser->decode($category);
@ -100,7 +122,7 @@ class Categories extends API_V1_Controller {
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -115,7 +137,7 @@ class Categories extends API_V1_Controller {
{
try
{
// Update the category record.
// Update the category record.
$batch = $this->services_model->get_all_categories('id = ' . $id);
if ($id !== NULL && count($batch) === 0)
@ -135,7 +157,7 @@ class Categories extends API_V1_Controller {
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -159,7 +181,7 @@ class Categories extends API_V1_Controller {
$response->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -13,13 +13,35 @@
require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyText;
use EA\Engine\Api\V1\Request;
use EA\Engine\Api\V1\Response;
use EA\Engine\Types\NonEmptyText;
/**
* Customers Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
* @subpackage API
*/
@ -69,7 +91,7 @@ class Customers extends API_V1_Controller {
->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -82,7 +104,7 @@ class Customers extends API_V1_Controller {
{
try
{
// Insert the customer to the database.
// Insert the customer to the database.
$request = new Request();
$customer = $request->getBody();
$this->parser->decode($customer);
@ -100,7 +122,7 @@ class Customers extends API_V1_Controller {
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -115,7 +137,7 @@ class Customers extends API_V1_Controller {
{
try
{
// Update the customer record.
// Update the customer record.
$batch = $this->customers_model->get_batch('id = ' . $id);
if ($id !== NULL && count($batch) === 0)
@ -135,7 +157,7 @@ class Customers extends API_V1_Controller {
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -159,7 +181,7 @@ class Customers extends API_V1_Controller {
$response->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -13,13 +13,35 @@
require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyText;
use EA\Engine\Api\V1\Request;
use EA\Engine\Api\V1\Response;
use EA\Engine\Types\NonEmptyText;
/**
* Providers Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
* @subpackage API
*/
@ -69,7 +91,7 @@ class Providers extends API_V1_Controller {
->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -100,7 +122,7 @@ class Providers extends API_V1_Controller {
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -135,7 +157,7 @@ class Providers extends API_V1_Controller {
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -159,7 +181,7 @@ class Providers extends API_V1_Controller {
$response->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -13,13 +13,35 @@
require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyText;
use EA\Engine\Api\V1\Request;
use EA\Engine\Api\V1\Response;
use EA\Engine\Types\NonEmptyText;
/**
* Secretaries Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
* @subpackage API
*/
@ -69,7 +91,7 @@ class Secretaries extends API_V1_Controller {
->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -82,7 +104,7 @@ class Secretaries extends API_V1_Controller {
{
try
{
// Insert the secretary to the database.
// Insert the secretary to the database.
$request = new Request();
$secretary = $request->getBody();
$this->parser->decode($secretary);
@ -100,7 +122,7 @@ class Secretaries extends API_V1_Controller {
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -115,7 +137,7 @@ class Secretaries extends API_V1_Controller {
{
try
{
// Update the secretary record.
// Update the secretary record.
$batch = $this->secretaries_model->get_batch('id = ' . $id);
if ($id !== NULL && count($batch) === 0)
@ -135,7 +157,7 @@ class Secretaries extends API_V1_Controller {
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -159,7 +181,7 @@ class Secretaries extends API_V1_Controller {
$response->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -13,13 +13,35 @@
require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyText;
use EA\Engine\Api\V1\Request;
use EA\Engine\Api\V1\Response;
use EA\Engine\Types\NonEmptyText;
/**
* Services Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
* @subpackage API
*/
@ -69,7 +91,7 @@ class Services extends API_V1_Controller {
->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -82,7 +104,7 @@ class Services extends API_V1_Controller {
{
try
{
// Insert the service to the database.
// Insert the service to the database.
$request = new Request();
$service = $request->getBody();
$this->parser->decode($service);
@ -100,7 +122,7 @@ class Services extends API_V1_Controller {
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -115,7 +137,7 @@ class Services extends API_V1_Controller {
{
try
{
// Update the service record.
// Update the service record.
$batch = $this->services_model->get_batch('id = ' . $id);
if ($id !== NULL && count($batch) === 0)
@ -135,7 +157,7 @@ class Services extends API_V1_Controller {
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}
@ -159,7 +181,7 @@ class Services extends API_V1_Controller {
$response->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
$this->_handleException($exception);
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -13,12 +13,34 @@
require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use EA\Engine\Api\V1\Request;
use EA\Engine\Api\V1\Response;
/**
* Settings Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
* @subpackage API
*/
@ -87,7 +109,7 @@ class Settings extends API_V1_Controller {
->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
exit($this->_handleException($exception));
}
@ -115,7 +137,7 @@ class Settings extends API_V1_Controller {
]);
$response->encode($this->parser)->singleEntry($name)->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
exit($this->_handleException($exception));
}
@ -139,7 +161,7 @@ class Settings extends API_V1_Controller {
$response->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
exit($this->_handleException($exception));
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -13,13 +13,35 @@
require_once __DIR__ . '/API_V1_Controller.php';
use \EA\Engine\Api\V1\Response;
use \EA\Engine\Api\V1\Request;
use \EA\Engine\Types\NonEmptyText;
use EA\Engine\Api\V1\Request;
use EA\Engine\Api\V1\Response;
use EA\Engine\Types\NonEmptyText;
/**
* Unavailabilities Controller
*
* @property CI_Session session
* @property CI_Loader load
* @property CI_Input input
* @property CI_Output output
* @property CI_Config config
* @property CI_Lang lang
* @property CI_Cache cache
* @property CI_DB_query_builder db
* @property CI_Security security
* @property Google_Sync google_sync
* @property Ics_file ics_file
* @property Appointments_Model appointments_model
* @property Providers_Model providers_model
* @property Services_Model services_model
* @property Customers_Model customers_model
* @property Settings_Model settings_model
* @property Timezones_Model timezones_model
* @property Roles_Model roles_model
* @property Secretaries_Model secretaries_model
* @property Admins_Model admins_model
* @property User_Model user_model
*
* @package Controllers
* @subpackage API
*/
@ -69,7 +91,7 @@ class Unavailabilities extends API_V1_Controller {
->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
exit($this->_handleException($exception));
}
@ -82,7 +104,7 @@ class Unavailabilities extends API_V1_Controller {
{
try
{
// Insert the appointment to the database.
// Insert the appointment to the database.
$request = new Request();
$unavailability = $request->getBody();
$this->parser->decode($unavailability);
@ -100,7 +122,7 @@ class Unavailabilities extends API_V1_Controller {
$status = new NonEmptyText('201 Created');
$response->encode($this->parser)->singleEntry(TRUE)->output($status);
}
catch (\Exception $exception)
catch (Exception $exception)
{
exit($this->_handleException($exception));
}
@ -115,7 +137,7 @@ class Unavailabilities extends API_V1_Controller {
{
try
{
// Update the appointment record.
// Update the appointment record.
$batch = $this->appointments_model->get_batch('id = ' . $id);
if ($id !== NULL && count($batch) === 0)
@ -135,7 +157,7 @@ class Unavailabilities extends API_V1_Controller {
$response = new Response($batch);
$response->encode($this->parser)->singleEntry($id)->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
exit($this->_handleException($exception));
}
@ -159,7 +181,7 @@ class Unavailabilities extends API_V1_Controller {
$response->output();
}
catch (\Exception $exception)
catch (Exception $exception)
{
exit($this->_handleException($exception));
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -24,16 +24,18 @@
*/
function asset_url($uri = '', $protocol = NULL)
{
$ci =& get_instance();
$framework =& get_instance();
$cache_busting_token = ! Config::DEBUG_MODE ? '?' . $ci->config->item('cache_busting_token') : '';
$debug = $framework->config->item('debug');
if (strpos(basename($uri), '.js') !== FALSE && strpos(basename($uri), '.min.js') === FALSE && ! Config::DEBUG_MODE)
$cache_busting_token = ! $debug ? '?' . $framework->config->item('cache_busting_token') : '';
if (strpos(basename($uri), '.js') !== FALSE && strpos(basename($uri), '.min.js') === FALSE && ! $debug)
{
$uri = str_replace('.js', '.min.js', $uri);
}
if (strpos(basename($uri), '.css') !== FALSE && strpos(basename($uri), '.min.css') === FALSE && ! Config::DEBUG_MODE)
if (strpos(basename($uri), '.css') !== FALSE && strpos(basename($uri), '.min.css') === FALSE && ! $debug)
{
$uri = str_replace('.css', '.min.css', $uri);
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,30 +11,6 @@
* @since v1.0.0
* ---------------------------------------------------------------------------- */
/**
* Database Exception Class
*/
class DatabaseException extends Exception {
}
/**
* Validation Exception Class
*/
class ValidationException extends Exception {
}
/**
* Notification Exception Class
*/
class NotificationException extends Exception {
}
/**
* Sync Exception Class
*/
class SyncException extends Exception {
}
/**
* Print an exception to an HTML text.
*
@ -44,10 +20,10 @@ class SyncException extends Exception {
* We display only one exceptions at a time because the user needs to be able
* to display the details of each exception seperately. (In contrast with js).
*
* @param Exception $exc The exception to be displayed.
* @param Exception $exception The exception to be displayed.
* @return string Returns the html markup of the exception.
*/
function exceptionToHtml($exc)
function exceptionToHtml($exception)
{
return
'<div class="accordion" id="error-accordion">
@ -55,35 +31,14 @@ function exceptionToHtml($exc)
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse"
data-parent="#error-accordion" href="#error-technical">' .
$exc->getMessage() . '
$exception->getMessage() . '
</a>
</div>
<div id="error-technical" class="accordion-body collapse">
<div class="accordion-inner">
<pre>' . $exc->getTraceAsString() . '</pre>
<pre>' . $exception->getTraceAsString() . '</pre>
</div>
</div>
</div>
</div>';
}
/**
* Get a javascript object of a given exception.
*
* This method is pretty useful whenever we need to pass an exception object
* to javascript during ajax calls.
*
* @param Exception $exception The given exception object.
* @return string Returns the json encoded object of the exception.
*/
function exceptionToJavaScript($exception)
{
return json_encode([
'code' => $exception->getCode(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'message' => $exception->getMessage(),
'previous' => $exception->getPrevious(),
'trace' => $exception->getTraceAsString()
]);
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -23,5 +23,6 @@
function validate_mysql_datetime($datetime)
{
$dt = DateTime::createFromFormat('Y-m-d H:i:s', $datetime);
return ($dt) ? TRUE : FALSE;
return $dt ? TRUE : FALSE;
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -13,17 +13,19 @@
/**
* Get date in RFC3339
*
* For example used in XML/Atom
*
* @link http://stackoverflow.com/questions/5671433/php-time-to-google-calendar-dates-time-format
*
* @param integer $timestamp
*
* @return string date in RFC3339
*
* @author Boris Korobkov
*/
function date3339($timestamp = 0)
{
if ( ! $timestamp)
{
$timestamp = time();
@ -45,12 +47,13 @@ function date3339($timestamp = 0)
/**
* Generate a hash of password string.
*
* For user security, all system passwords are stored in hash string into the database. Use
* this method to produce the hashed password.
* For user security, all system passwords are stored in hash string into the database. Use this method to produce the
* hashed password.
*
* @param string $salt Salt value for current user. This value is stored on the database and
* is used when generating the password hash.
* @param string $salt Salt value for current user. This value is stored on the database and is used when generating
* the password hash.
* @param string $password Given string password.
*
* @return string Returns the hash string of the given password.
*/
function hash_password($salt, $password)
@ -84,9 +87,11 @@ function generate_salt()
/**
* This method generates a random string.
*
* @param int $length (OPTIONAL = 10) The length of the generated string.
* @return string Returns the randomly generated string.
* @link http://stackoverflow.com/a/4356295/1718162
*
* @param int $length (OPTIONAL = 10) The length of the generated string.
*
* @return string Returns the randomly generated string.
*/
function generate_random_string($length = 10)
{

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,17 +14,17 @@
/**
* Print Google Analytics script.
*
* This helper function should be used in view files in order to output the Google Analytics
* script. It will check whether the code is set in the database and print it, otherwise nothing
* will be outputted. This eliminates the need for extra checking before outputting.
* This helper function should be used in view files in order to output the Google Analytics script. It will check
* whether the code is set in the database and print it, otherwise nothing will be outputted. This eliminates the need
* for extra checking before outputting.
*/
function google_analytics_script()
{
$ci =& get_instance();
$framework =& get_instance();
$ci->load->model('settings_model');
$framework->load->model('settings_model');
$google_analytics_code = $ci->settings_model->get_setting('google_analytics_code');
$google_analytics_code = $framework->settings_model->get_setting('google_analytics_code');
if ($google_analytics_code !== '')
{

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,19 +14,18 @@
/**
* Check if Easy!Appointments is installed.
*
* This function will check some factors to determine if Easy!Appointments is
* installed or not. It is possible that the installation is properly configure
* without being recognized by this method.
* This function will check some factors to determine if Easy!Appointments is installed or not. It is possible that the
* installation is properly configure without being recognized by this method.
*
* Notice: You can add more checks into this file in order to further check the
* installation state of the application.
* Notice: You can add more checks into this file in order to further check the installation state of the application.
*
* @return bool Returns whether E!A is installed or not.
*/
function is_ea_installed()
{
$ci =& get_instance();
return $ci->db->table_exists('ea_users');
$framework =& get_instance();
return $framework->db->table_exists('ea_users');
}
/**

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -28,9 +28,9 @@ class Google_Sync {
/**
* CodeIgniter Instance
*
* @var CodeIgniter
* @var CI_Controller
*/
protected $CI;
protected $framework;
/**
* Google API Client
@ -54,18 +54,18 @@ class Google_Sync {
*/
public function __construct()
{
$this->CI =& get_instance();
$this->framework =& get_instance();
$this->CI->load->library('session');
$this->framework->load->library('session');
// Initialize google client and calendar service.
$this->client = new Google_Client();
$this->client->setUseObjects(TRUE);
$this->client->setApplicationName(Config::GOOGLE_PRODUCT_NAME);
$this->client->setClientId(Config::GOOGLE_CLIENT_ID);
$this->client->setClientSecret(Config::GOOGLE_CLIENT_SECRET);
$this->client->setDeveloperKey(Config::GOOGLE_API_KEY);
$this->client->setApplicationName($this->framework->config->item('google_application_name'));
$this->client->setClientId($this->framework->config->item('google_client_id'));
$this->client->setClientSecret($this->framework->config->item('google_client_secret'));
$this->client->setDeveloperKey($this->framework->config->item('google_api_key'));
$this->client->setRedirectUri(site_url('google/oauth_callback'));
$this->service = new Google_CalendarService($this->client);
@ -121,29 +121,26 @@ class Google_Sync {
/**
* Add an appointment record to its providers Google Calendar account.
*
* This method checks whether the appointment's provider has enabled the Google
* Sync utility of Easy!Appointments and the stored access token is still valid.
* If yes, the selected appointment record is going to be added to the Google
* Calendar account.
* This method checks whether the appointment's provider has enabled the Google Sync utility of Easy!Appointments
* and the stored access token is still valid. If yes, the selected appointment record is going to be added to the
* Google Calendar account.
*
* @param array $appointment Contains the appointment record data.
* @param array $provider Contains the provider record data.
* @param array $service Contains the service record data.
* @param array $customer Contains the customer recod data.
* @parma array $company_settings Contains some company settings that are used
* by this method. By the time the following values must be in the array:
* 'company_name'.
* @param array $settings Contains some company settings that are used by this method.
*
* @return Google_Event Returns the Google_Event class object.
*/
public function add_appointment($appointment, $provider, $service, $customer, $company_settings)
public function add_appointment($appointment, $provider, $service, $customer, $settings)
{
$this->CI->load->helper('general');
$this->framework->load->helper('general');
$event = new Google_Event();
$event->setSummary(($service != NULL) ? $service['name'] : 'Unavailable');
$event->setDescription($appointment['notes']);
$event->setLocation(isset($appointment['location']) ? $appointment['location'] : $company_settings['company_name']);
$event->setLocation(isset($appointment['location']) ? $appointment['location'] : $settings['company_name']);
$start = new Google_EventDateTime();
$start->setDateTime(date3339(strtotime($appointment['start_datetime'])));
@ -186,22 +183,20 @@ class Google_Sync {
* @param array $provider Contains the provider record data.
* @param array $service Contains the service record data.
* @param array $customer Contains the customer recod data.
* @parma array $company_settings Contains some company settings that are used
* by this method. By the time the following values must be in the array:
* 'company_name'.
* @parma array $company_settings Contains some company settings that are used by this method.
*
* @return Google_Event Returns the Google_Event class object.
*/
public function update_appointment($appointment, $provider, $service, $customer, $company_settings)
public function update_appointment($appointment, $provider, $service, $customer, $settings)
{
$this->CI->load->helper('general');
$this->framework->load->helper('general');
$event = $this->service->events->get($provider['settings']['google_calendar'],
$appointment['id_google_calendar']);
$event->setSummary($service['name']);
$event->setDescription($appointment['notes']);
$event->setLocation(isset($appointment['location']) ? $appointment['location'] : $company_settings['company_name']);
$event->setLocation(isset($appointment['location']) ? $appointment['location'] : $settings['company_name']);
$start = new Google_EventDateTime();
$start->setDateTime(date3339(strtotime($appointment['start_datetime'])));
@ -263,7 +258,7 @@ class Google_Sync {
*/
public function add_unavailable($provider, $unavailable)
{
$this->CI->load->helper('general');
$this->framework->load->helper('general');
$event = new Google_Event();
$event->setSummary('Unavailable');
@ -294,7 +289,7 @@ class Google_Sync {
*/
public function update_unavailable($provider, $unavailable)
{
$this->CI->load->helper('general');
$this->framework->load->helper('general');
$event = $this->service->events->get($provider['settings']['google_calendar'],
$unavailable['id_google_calendar']);
@ -349,20 +344,20 @@ class Google_Sync {
* Get all the events between the sync period.
*
* @param string $google_calendar The name of the google calendar to be used.
* @param date $start The start date of sync period.
* @param date $end The end date of sync period.
* @param string $start The start date of sync period.
* @param string $end The end date of sync period.
*
* @return object Returns an array with Google_Event objects that belong on the given
* sync period (start, end).
*/
public function get_sync_events($google_calendar, $start, $end)
{
$this->CI->load->helper('general');
$this->framework->load->helper('general');
$params = [
'timeMin' => date3339($start),
'timeMax' => date3339($end),
'singleEvents' => true,
'singleEvents' => TRUE,
];
return $this->service->events->listEvents($google_calendar, $params);

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,13 +11,14 @@
* @since v1.3.0
* ---------------------------------------------------------------------------- */
use Jsvrcek\ICS\CalendarExport;
use Jsvrcek\ICS\CalendarStream;
use Jsvrcek\ICS\Exception\CalendarEventException;
use Jsvrcek\ICS\Model\Calendar;
use Jsvrcek\ICS\Model\CalendarEvent;
use Jsvrcek\ICS\Model\Relationship\Attendee;
use Jsvrcek\ICS\Model\Relationship\Organizer;
use Jsvrcek\ICS\Utility\Formatter;
use Jsvrcek\ICS\CalendarStream;
use Jsvrcek\ICS\CalendarExport;
/**
* Class Ics_file
@ -37,6 +38,9 @@ class Ics_file {
* @param array $customer Customer.
*
* @return string Returns the contents of the ICS file.
*
* @throws CalendarEventException
* @throws Exception
*/
public function get_stream($appointment, $service, $provider, $customer)
{

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,8 +11,16 @@
* @since v1.0.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Specific_calendar_sync
*
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
*/
class Migration_Specific_calendar_sync extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
if ( ! $this->db->field_exists('google_calendar', 'ea_user_settings'))
@ -28,6 +36,9 @@ class Migration_Specific_calendar_sync extends CI_Migration {
}
}
/**
* Downgrade method.
*/
public function down()
{
if ($this->db->field_exists('google_calendar', 'ea_user_settings'))

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,11 +11,34 @@
* @since v1.1.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_google_analytics_setting
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_google_analytics_setting extends CI_Migration {
/**
* Migration_Add_google_analytics_setting constructor.
*
* @param array $config
*/
public function __construct($config = [])
{
parent::__construct($config);
$this->load->model('settings_model');
}
/**
* Upgrade method.
*
* @throws Exception
*/
public function up()
{
$this->load->model('settings_model');
try
{
$this->settings_model->get_setting('google_analytics_code');
@ -26,10 +49,13 @@ class Migration_Add_google_analytics_setting extends CI_Migration {
}
}
/**
* Downgrade method.
*
* @throws Exception
*/
public function down()
{
$this->load->model('settings_model');
$this->settings_model->remove_setting('google_analytics_code');
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,11 +11,33 @@
* @since v1.1.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_customer_notifications_setting
*
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_customer_notifications_setting extends CI_Migration {
/**
* Migration_Add_customer_notifications_setting constructor.
*
* @param array $config
*/
public function __construct($config = [])
{
parent::__construct($config);
$this->load->model('settings_model');
}
/**
* Upgrade method.
*
* @throws Exception
*/
public function up()
{
$this->load->model('settings_model');
try
{
$this->settings_model->get_setting('customer_notifications');
@ -26,10 +48,13 @@ class Migration_Add_customer_notifications_setting extends CI_Migration {
}
}
/**
* Downgrade method.
*
* @throws Exception
*/
public function down()
{
$this->load->model('settings_model');
$this->settings_model->remove_setting('customer_notifications');
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,11 +11,35 @@
* @since v1.1.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_date_format_setting
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_date_format_setting extends CI_Migration {
/**
* Migration_Add_date_format_setting constructor.
*
* @param array $config
*/
public function __construct($config = [])
{
parent::__construct($config);
$this->load->model('settings_model');
}
/**
* Upgrade method.
*
* @throws Exception
*/
public function up()
{
$this->load->model('settings_model');
try
{
$this->settings_model->get_setting('date_format');
@ -26,10 +50,13 @@ class Migration_Add_date_format_setting extends CI_Migration {
}
}
/**
* Downgrade method.
*
* @throws Exception
*/
public function down()
{
$this->load->model('settings_model');
$this->settings_model->remove_setting('date_format');
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,11 +11,34 @@
* @since v1.1.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_require_captcha_setting
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_require_captcha_setting extends CI_Migration {
/**
* Migration_Add_require_captcha_setting constructor.
*
* @param array $config
*/
public function __construct($config = [])
{
parent::__construct($config);
$this->load->model('settings_model');
}
/**
* Upgrade method.
*
* @throws Exception
*/
public function up()
{
$this->load->model('settings_model');
try
{
$this->settings_model->get_setting('require_captcha');
@ -26,10 +49,13 @@ class Migration_Add_require_captcha_setting extends CI_Migration {
}
}
/**
* Downgrade method.
*
* @throws Exception
*/
public function down()
{
$this->load->model('settings_model');
$this->settings_model->remove_setting('require_captcha');
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,7 +11,18 @@
* @since v1.2.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_calendar_view_setting
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_calendar_view_setting extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
if ( ! $this->db->field_exists('calendar_view', 'ea_user_settings'))
@ -30,6 +41,9 @@ class Migration_Add_calendar_view_setting extends CI_Migration {
}
}
/**
* Downgrade method.
*/
public function down()
{
if ($this->db->field_exists('calendar_view', 'ea_user_settings'))

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,7 +11,18 @@
* @since v1.2.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_service_availabilities_type
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_service_availabilities_type extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
if ( ! $this->db->field_exists('availabilities_type', 'ea_services'))
@ -31,6 +42,9 @@ class Migration_Add_service_availabilities_type extends CI_Migration {
}
}
/**
* Downgrade method.
*/
public function down()
{
if ($this->db->field_exists('availabilities_type', 'ea_services'))

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,7 +11,18 @@
* @since v1.2.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_service_attendants_number
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_service_attendants_number extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
if ( ! $this->db->field_exists('attendants_number', 'ea_services'))
@ -31,6 +42,9 @@ class Migration_Add_service_attendants_number extends CI_Migration {
}
}
/**
* Downgrade method.
*/
public function down()
{
if ($this->db->field_exists('attendants_number', 'ea_services'))

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,7 +11,18 @@
* @since v1.3.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Change_column_types
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Change_column_types extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
// Drop table constraints.
@ -223,6 +234,9 @@ class Migration_Change_column_types extends CI_Migration {
$this->db->query('ALTER TABLE ea_secretaries_providers CONVERT TO CHARACTER SET utf8');
}
/**
* Downgrade method.
*/
public function down()
{
// Drop table constraints.

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,11 +11,32 @@
* @since v1.3.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_time_format_setting
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_time_format_setting extends CI_Migration {
/**
* Migration_Add_time_format_setting constructor.
*
* @param array $config
*/
public function __construct($config = [])
{
parent::__construct($config);
$this->load->model('settings_model');
}
/**
* Upgrade method.
*/
public function up()
{
$this->load->model('settings_model');
try
{
$this->settings_model->get_setting('time_format');
@ -26,10 +47,11 @@ class Migration_Add_time_format_setting extends CI_Migration {
}
}
/**
* Downgrade method.
*/
public function down()
{
$this->load->model('settings_model');
$this->settings_model->remove_setting('time_format');
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,7 +11,18 @@
* @since v1.3.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Remove_prefix_from_fkey_constraints
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Remove_prefix_from_fkey_constraints extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
// Drop table constraints.
@ -70,6 +81,9 @@ class Migration_Remove_prefix_from_fkey_constraints extends CI_Migration {
ON UPDATE CASCADE');
}
/**
* Downgrade method.
*/
public function down()
{
// Drop table constraints.

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,7 +11,18 @@
* @since v1.3.2
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Legal_contents
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Legal_contents extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
$this->db->insert('ea_settings', ['name' => 'display_cookie_notice', 'value' => '0']);
@ -40,6 +51,9 @@ class Migration_Legal_contents extends CI_Migration {
');
}
/**
* Downgrade method.
*/
public function down()
{
$this->db->delete('ea_settings', ['name' => 'display_cookie_notice']);

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,11 +11,32 @@
* @since v1.3.2
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_weekday_start_setting
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_weekday_start_setting extends CI_Migration {
/**
* Migration_Add_weekday_start_setting constructor.
*
* @param array $config
*/
public function __construct($config = [])
{
parent::__construct($config);
$this->load->model('settings_model');
}
/**
* Upgrade method.
*/
public function up()
{
$this->load->model('settings_model');
try
{
$this->settings_model->get_setting('first_weekday');
@ -26,10 +47,11 @@ class Migration_Add_weekday_start_setting extends CI_Migration {
}
}
/**
* Downgrade method.
*/
public function down()
{
$this->load->model('settings_model');
$this->settings_model->remove_setting('first_weekday');
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,7 +11,18 @@
* @since v1.4.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_add_appointment_location_column
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_add_appointment_location_column extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
$this->db->query('
@ -25,6 +36,9 @@ class Migration_add_appointment_location_column extends CI_Migration {
');
}
/**
* Downgrade method.
*/
public function down()
{
$this->db->query('

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,10 +11,22 @@
* @since v1.2.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_user_extra_working_plan
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_user_extra_working_plan extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
if (!$this->db->field_exists('extra_working_plan', 'ea_user_settings')) {
if ( ! $this->db->field_exists('extra_working_plan', 'ea_user_settings'))
{
$fields = [
'extra_working_plan' => [
'type' => 'TEXT',
@ -28,9 +40,13 @@ class Migration_Add_user_extra_working_plan extends CI_Migration {
}
}
/**
* Downgrade method.
*/
public function down()
{
if (!$this->db->field_exists('extra_working_plan', 'ea_user_settings')) {
if ( ! $this->db->field_exists('extra_working_plan', 'ea_user_settings'))
{
$this->dbforge->drop_column('ea_user_settings', 'extra_working_plan');
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,11 +11,32 @@
* @since v1.4.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_require_phone_number_setting
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_require_phone_number_setting extends CI_Migration {
/**
* Migration_Add_require_phone_number_setting constructor.
*
* @param array $config
*/
public function __construct($config = [])
{
parent::__construct($config);
$this->load->model('settings_model');
}
/**
* Upgrade method.
*/
public function up()
{
$this->load->model('settings_model');
try
{
$this->settings_model->get_setting('require_phone_number');
@ -26,10 +47,11 @@ class Migration_Add_require_phone_number_setting extends CI_Migration {
}
}
/**
* Downgrade method.
*/
public function down()
{
$this->load->model('settings_model');
$this->settings_model->remove_setting('require_phone_number');
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,11 +11,34 @@
* @since v1.4.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_api_token_setting
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_api_token_setting extends CI_Migration {
/**
* Migration_Add_api_token_setting constructor.
*
* @param array $config
*/
public function __construct($config = [])
{
parent::__construct($config);
$this->load->model('settings_model');
}
/**
* Upgrade method.
*
* @throws Exception
*/
public function up()
{
$this->load->model('settings_model');
try
{
$this->settings_model->get_setting('api_token');
@ -26,10 +49,13 @@ class Migration_Add_api_token_setting extends CI_Migration {
}
}
/**
* Downgrade method.
*
* @throws Exception
*/
public function down()
{
$this->load->model('settings_model');
$this->settings_model->remove_setting('api_token');
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,7 +11,18 @@
* @since v1.4.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_timezone_columns
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_timezone_columns extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
$this->db->query('
@ -20,6 +31,9 @@ class Migration_Add_timezone_columns extends CI_Migration {
');
}
/**
* Downgrade method.
*/
public function down()
{
$this->db->query('

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -11,7 +11,18 @@
* @since v1.4.0
* ---------------------------------------------------------------------------- */
/**
* Class Migration_Add_display_any_provider_setting
*
* @property CI_Loader load
* @property CI_DB_query_builder db
* @property CI_DB_forge dbforge
* @property Settings_Model settings_model
*/
class Migration_Add_display_any_provider_setting extends CI_Migration {
/**
* Upgrade method.
*/
public function up()
{
$this->db->insert('ea_settings', [
@ -20,6 +31,9 @@ class Migration_Add_display_any_provider_setting extends CI_Migration {
]);
}
/**
* Downgrade method.
*/
public function down()
{
$this->db->delete('ea_settings', [

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -30,6 +30,9 @@
* 'id_roles'
* 'settings' >>> array that contains user settings (username, password etc)
*
* @property CI_DB_query_builder db
* @property CI_Loader load
*
* @package Models
*/
class Admins_Model extends CI_Model {
@ -63,145 +66,6 @@ class Admins_Model extends CI_Model {
return (int)$admin['id'];
}
/**
* Check whether a particular admin record exists in the database.
*
* @param array $admin Contains the admin data. The 'email' value is required to be present at the moment.
*
* @return bool Returns whether the record exists or not.
*
* @throws Exception When the 'email' value is not present on the $admin argument.
*/
public function exists($admin)
{
if ( ! isset($admin['email']))
{
throw new Exception('Admin email is not provided: ' . print_r($admin, TRUE));
}
// This method shouldn't depend on another method of this class.
$num_rows = $this->db
->select('*')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $admin['email'])
->where('ea_roles.slug', DB_SLUG_ADMIN)
->get()->num_rows();
return ($num_rows > 0) ? TRUE : FALSE;
}
/**
* Insert a new admin record into the database.
*
* @param array $admin Contains the admin data.
*
* @return int Returns the new record id.
*
* @throws Exception When the insert operation fails.
*/
protected function _insert($admin)
{
$this->load->helper('general');
$admin['id_roles'] = $this->get_admin_role_id();
$settings = $admin['settings'];
unset($admin['settings']);
$this->db->trans_begin();
if ( ! $this->db->insert('ea_users', $admin))
{
throw new Exception('Could not insert admin into the database.');
}
$admin['id'] = (int)$this->db->insert_id();
$settings['id_users'] = $admin['id'];
$settings['salt'] = generate_salt();
$settings['password'] = hash_password($settings['salt'], $settings['password']);
// Insert admin settings.
if ( ! $this->db->insert('ea_user_settings', $settings))
{
$this->db->trans_rollback();
throw new Exception('Could not insert admin settings into the database.');
}
$this->db->trans_complete();
return $admin['id'];
}
/**
* Update an existing admin record in the database.
*
* @param array $admin Contains the admin record data.
*
* @return int Returns the record id.
*
* @throws Exception When the update operation fails.
*/
protected function _update($admin)
{
$this->load->helper('general');
$settings = $admin['settings'];
unset($admin['settings']);
$settings['id_users'] = $admin['id'];
if (isset($settings['password']))
{
$salt = $this->db->get_where('ea_user_settings', ['id_users' => $admin['id']])->row()->salt;
$settings['password'] = hash_password($salt, $settings['password']);
}
$this->db->where('id', $admin['id']);
if ( ! $this->db->update('ea_users', $admin))
{
throw new Exception('Could not update admin record.');
}
$this->db->where('id_users', $settings['id_users']);
if ( ! $this->db->update('ea_user_settings', $settings))
{
throw new Exception('Could not update admin settings.');
}
return (int)$admin['id'];
}
/**
* Find the database record id of an admin user.
*
* @param array $admin Contains the admin data. The 'email' value is required in order to find the record id.
*
* @return int Returns the record id
*
* @throws Exception When the 'email' value is not present on the $admin array.
*/
public function find_record_id($admin)
{
if ( ! isset($admin['email']))
{
throw new Exception('Admin email was not provided: ' . print_r($admin, TRUE));
}
$result = $this->db
->select('ea_users.id')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $admin['email'])
->where('ea_roles.slug', DB_SLUG_ADMIN)
->get();
if ($result->num_rows() == 0)
{
throw new Exception('Could not find admin record id.');
}
return (int)$result->row()->id;
}
/**
* Validate admin user data before add() operation is executed.
*
@ -291,6 +155,170 @@ class Admins_Model extends CI_Model {
return TRUE; // Operation completed successfully.
}
/**
* Validate Records Username
*
* @param string $username The provider records username.
* @param int $user_id The user record id.
*
* @return bool Returns the validation result.
*/
public function validate_username($username, $user_id)
{
$num_rows = $this->db->get_where('ea_user_settings',
['username' => $username, 'id_users <> ' => $user_id])->num_rows();
return ($num_rows > 0) ? FALSE : TRUE;
}
/**
* Check whether a particular admin record exists in the database.
*
* @param array $admin Contains the admin data. The 'email' value is required to be present at the moment.
*
* @return bool Returns whether the record exists or not.
*
* @throws Exception When the 'email' value is not present on the $admin argument.
*/
public function exists($admin)
{
if ( ! isset($admin['email']))
{
throw new Exception('Admin email is not provided: ' . print_r($admin, TRUE));
}
// This method shouldn't depend on another method of this class.
$num_rows = $this->db
->select('*')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $admin['email'])
->where('ea_roles.slug', DB_SLUG_ADMIN)
->get()->num_rows();
return $num_rows > 0;
}
/**
* Find the database record id of an admin user.
*
* @param array $admin Contains the admin data. The 'email' value is required in order to find the record id.
*
* @return int Returns the record id
*
* @throws Exception When the 'email' value is not present on the $admin array.
*/
public function find_record_id($admin)
{
if ( ! isset($admin['email']))
{
throw new Exception('Admin email was not provided: ' . print_r($admin, TRUE));
}
$result = $this->db
->select('ea_users.id')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $admin['email'])
->where('ea_roles.slug', DB_SLUG_ADMIN)
->get();
if ($result->num_rows() == 0)
{
throw new Exception('Could not find admin record id.');
}
return (int)$result->row()->id;
}
/**
* Insert a new admin record into the database.
*
* @param array $admin Contains the admin data.
*
* @return int Returns the new record id.
*
* @throws Exception When the insert operation fails.
*/
protected function _insert($admin)
{
$this->load->helper('general');
$admin['id_roles'] = $this->get_admin_role_id();
$settings = $admin['settings'];
unset($admin['settings']);
$this->db->trans_begin();
if ( ! $this->db->insert('ea_users', $admin))
{
throw new Exception('Could not insert admin into the database.');
}
$admin['id'] = (int)$this->db->insert_id();
$settings['id_users'] = $admin['id'];
$settings['salt'] = generate_salt();
$settings['password'] = hash_password($settings['salt'], $settings['password']);
// Insert admin settings.
if ( ! $this->db->insert('ea_user_settings', $settings))
{
$this->db->trans_rollback();
throw new Exception('Could not insert admin settings into the database.');
}
$this->db->trans_complete();
return $admin['id'];
}
/**
* Get the admin users role id.
*
* @return int Returns the role record id.
*/
public function get_admin_role_id()
{
return (int)$this->db->get_where('ea_roles', ['slug' => DB_SLUG_ADMIN])->row()->id;
}
/**
* Update an existing admin record in the database.
*
* @param array $admin Contains the admin record data.
*
* @return int Returns the record id.
*
* @throws Exception When the update operation fails.
*/
protected function _update($admin)
{
$this->load->helper('general');
$settings = $admin['settings'];
unset($admin['settings']);
$settings['id_users'] = $admin['id'];
if (isset($settings['password']))
{
$salt = $this->db->get_where('ea_user_settings', ['id_users' => $admin['id']])->row()->salt;
$settings['password'] = hash_password($salt, $settings['password']);
}
$this->db->where('id', $admin['id']);
if ( ! $this->db->update('ea_users', $admin))
{
throw new Exception('Could not update admin record.');
}
$this->db->where('id_users', $settings['id_users']);
if ( ! $this->db->update('ea_user_settings', $settings))
{
throw new Exception('Could not update admin settings.');
}
return (int)$admin['id'];
}
/**
* Delete an existing admin record from the database.
*
@ -439,29 +467,4 @@ class Admins_Model extends CI_Model {
return $batch;
}
/**
* Get the admin users role id.
*
* @return int Returns the role record id.
*/
public function get_admin_role_id()
{
return (int)$this->db->get_where('ea_roles', ['slug' => DB_SLUG_ADMIN])->row()->id;
}
/**
* Validate Records Username
*
* @param string $username The provider records username.
* @param int $user_id The user record id.
*
* @return bool Returns the validation result.
*/
public function validate_username($username, $user_id)
{
$num_rows = $this->db->get_where('ea_user_settings',
['username' => $username, 'id_users <> ' => $user_id])->num_rows();
return ($num_rows > 0) ? FALSE : TRUE;
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,6 +14,9 @@
/**
* Appointments Model
*
* @property CI_DB_query_builder db
* @property CI_Loader load
*
* @package Models
*/
class Appointments_Model extends CI_Model {
@ -27,6 +30,7 @@ class Appointments_Model extends CI_Model {
* database fields.
*
* @return int Returns the appointments id.
* @throws Exception
*/
public function add($appointment)
{
@ -46,121 +50,6 @@ class Appointments_Model extends CI_Model {
return $appointment['id'];
}
/**
* Check if a particular appointment record already exists.
*
* This method checks whether the given appointment already exists in the database. It doesn't search with the id,
* but by using the following fields: "start_datetime", "end_datetime", "id_users_provider", "id_users_customer",
* "id_services".
*
* @param array $appointment Associative array with the appointment's data. Each key has the same name with the
* database fields.
*
* @return bool Returns whether the record exists or not.
*
* @throws Exception If appointment fields are missing.
*/
public function exists($appointment)
{
if ( ! isset($appointment['start_datetime'])
|| ! isset($appointment['end_datetime'])
|| ! isset($appointment['id_users_provider'])
|| ! isset($appointment['id_users_customer'])
|| ! isset($appointment['id_services']))
{
throw new Exception('Not all appointment field values are provided: '
. print_r($appointment, TRUE));
}
$num_rows = $this->db->get_where('ea_appointments', [
'start_datetime' => $appointment['start_datetime'],
'end_datetime' => $appointment['end_datetime'],
'id_users_provider' => $appointment['id_users_provider'],
'id_users_customer' => $appointment['id_users_customer'],
'id_services' => $appointment['id_services'],
])
->num_rows();
return ($num_rows > 0) ? TRUE : FALSE;
}
/**
* Insert a new appointment record to the database.
*
* @param array $appointment Associative array with the appointment's data. Each key has the same name with the
* database fields.
*
* @return int Returns the id of the new record.
*
* @throws Exception If appointment record could not be inserted.
*/
protected function _insert($appointment)
{
$appointment['book_datetime'] = date('Y-m-d H:i:s');
$appointment['hash'] = $this->generate_hash();
if ( ! $this->db->insert('ea_appointments', $appointment))
{
throw new Exception('Could not insert appointment record.');
}
return (int)$this->db->insert_id();
}
/**
* Update an existing appointment record in the database.
*
* The appointment data argument should already include the record ID in order to process the update operation.
*
* @param array $appointment Associative array with the appointment's data. Each key has the same name with the
* database fields.
*
* @throws Exception If appointment record could not be updated.
*/
protected function _update($appointment)
{
$this->db->where('id', $appointment['id']);
if ( ! $this->db->update('ea_appointments', $appointment))
{
throw new Exception('Could not update appointment record.');
}
}
/**
* Find the database id of an appointment record.
*
* The appointment data should include the following fields in order to get the unique id from the database:
* "start_datetime", "end_datetime", "id_users_provider", "id_users_customer", "id_services".
*
* IMPORTANT: The record must already exists in the database, otherwise an exception is raised.
*
* @param array $appointment Array with the appointment data. The keys of the array should have the same names as
* the db fields.
*
* @return int Returns the db id of the record that matches the appointment data.
*
* @throws Exception If appointment could not be found.
*/
public function find_record_id($appointment)
{
$this->db->where([
'start_datetime' => $appointment['start_datetime'],
'end_datetime' => $appointment['end_datetime'],
'id_users_provider' => $appointment['id_users_provider'],
'id_users_customer' => $appointment['id_users_customer'],
'id_services' => $appointment['id_services']
]);
$result = $this->db->get('ea_appointments');
if ($result->num_rows() == 0)
{
throw new Exception('Could not find appointment record id.');
}
return $result->row()->id;
}
/**
* Validate appointment data before the insert or update operations are executed.
*
@ -237,6 +126,135 @@ class Appointments_Model extends CI_Model {
return TRUE;
}
/**
* Insert a new appointment record to the database.
*
* @param array $appointment Associative array with the appointment's data. Each key has the same name with the
* database fields.
*
* @return int Returns the id of the new record.
*
* @throws Exception If appointment record could not be inserted.
*/
protected function _insert($appointment)
{
$appointment['book_datetime'] = date('Y-m-d H:i:s');
$appointment['hash'] = $this->generate_hash();
if ( ! $this->db->insert('ea_appointments', $appointment))
{
throw new Exception('Could not insert appointment record.');
}
return (int)$this->db->insert_id();
}
/**
* Generate a unique hash for the given appointment data.
*
* This method uses the current date-time to generate a unique hash string that is later used to identify this
* appointment. Hash is needed when the email is send to the user with an edit link.
*
* @return string Returns the unique appointment hash.
*/
public function generate_hash()
{
$current_date = new DateTime();
return md5($current_date->getTimestamp());
}
/**
* Update an existing appointment record in the database.
*
* The appointment data argument should already include the record ID in order to process the update operation.
*
* @param array $appointment Associative array with the appointment's data. Each key has the same name with the
* database fields.
*
* @throws Exception If appointment record could not be updated.
*/
protected function _update($appointment)
{
$this->db->where('id', $appointment['id']);
if ( ! $this->db->update('ea_appointments', $appointment))
{
throw new Exception('Could not update appointment record.');
}
}
/**
* Check if a particular appointment record already exists.
*
* This method checks whether the given appointment already exists in the database. It doesn't search with the id,
* but by using the following fields: "start_datetime", "end_datetime", "id_users_provider", "id_users_customer",
* "id_services".
*
* @param array $appointment Associative array with the appointment's data. Each key has the same name with the
* database fields.
*
* @return bool Returns whether the record exists or not.
*
* @throws Exception If appointment fields are missing.
*/
public function exists($appointment)
{
if ( ! isset($appointment['start_datetime'])
|| ! isset($appointment['end_datetime'])
|| ! isset($appointment['id_users_provider'])
|| ! isset($appointment['id_users_customer'])
|| ! isset($appointment['id_services']))
{
throw new Exception('Not all appointment field values are provided: '
. print_r($appointment, TRUE));
}
$num_rows = $this->db->get_where('ea_appointments', [
'start_datetime' => $appointment['start_datetime'],
'end_datetime' => $appointment['end_datetime'],
'id_users_provider' => $appointment['id_users_provider'],
'id_users_customer' => $appointment['id_users_customer'],
'id_services' => $appointment['id_services'],
])
->num_rows();
return ($num_rows > 0) ? TRUE : FALSE;
}
/**
* Find the database id of an appointment record.
*
* The appointment data should include the following fields in order to get the unique id from the database:
* "start_datetime", "end_datetime", "id_users_provider", "id_users_customer", "id_services".
*
* IMPORTANT: The record must already exists in the database, otherwise an exception is raised.
*
* @param array $appointment Array with the appointment data. The keys of the array should have the same names as
* the db fields.
*
* @return int Returns the db id of the record that matches the appointment data.
*
* @throws Exception If appointment could not be found.
*/
public function find_record_id($appointment)
{
$this->db->where([
'start_datetime' => $appointment['start_datetime'],
'end_datetime' => $appointment['end_datetime'],
'id_users_provider' => $appointment['id_users_provider'],
'id_users_customer' => $appointment['id_users_customer'],
'id_services' => $appointment['id_services']
]);
$result = $this->db->get('ea_appointments');
if ($result->num_rows() == 0)
{
throw new Exception('Could not find appointment record id.');
}
return $result->row()->id;
}
/**
* Delete an existing appointment record from the database.
*
@ -383,17 +401,21 @@ class Appointments_Model extends CI_Model {
}
/**
* Generate a unique hash for the given appointment data.
* Get the aggregates of an appointment.
*
* This method uses the current date-time to generate a unique hash string that is later used to identify this
* appointment. Hash is needed when the email is send to the user with an edit link.
* @param array $appointment Appointment data.
*
* @return string Returns the unique appointment hash.
* @return array Returns the appointment with the aggregates.
*/
public function generate_hash()
private function get_aggregates(array $appointment)
{
$current_date = new DateTime();
return md5($current_date->getTimestamp());
$appointment['service'] = $this->db->get_where('ea_services',
['id' => $appointment['id_services']])->row_array();
$appointment['provider'] = $this->db->get_where('ea_users',
['id' => $appointment['id_users_provider']])->row_array();
$appointment['customer'] = $this->db->get_where('ea_users',
['id' => $appointment['id_users_customer']])->row_array();
return $appointment;
}
/**
@ -535,22 +557,4 @@ class Appointments_Model extends CI_Model {
->row()
->attendants_number;
}
/**
* Get the aggregates of an appointment.
*
* @param array $appointment Appointment data.
*
* @return array Returns the appointment with the aggregates.
*/
private function get_aggregates(array $appointment)
{
$appointment['service'] = $this->db->get_where('ea_services',
['id' => $appointment['id_services']])->row_array();
$appointment['provider'] = $this->db->get_where('ea_users',
['id' => $appointment['id_users_provider']])->row_array();
$appointment['customer'] = $this->db->get_where('ea_users',
['id' => $appointment['id_users_customer']])->row_array();
return $appointment;
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,6 +14,9 @@
/**
* Class Consents_model
*
* @property CI_DB_query_builder db
* @property CI_Loader load
*
* @package Models
*/
class Consents_model extends CI_Model {

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,6 +14,9 @@
/**
* Customers Model
*
* @property CI_DB_query_builder db
* @property CI_Loader load
*
* @package Models
*/
class Customers_Model extends CI_Model {
@ -53,6 +56,74 @@ class Customers_Model extends CI_Model {
return $customer['id'];
}
/**
* Validate customer data before the insert or update operation is executed.
*
* @param array $customer Contains the customer data.
*
* @return bool Returns the validation result.
*
* @throws Exception If customer validation fails.
*/
public function validate($customer)
{
$this->load->helper('data_validation');
// If a customer id is provided, check whether the record
// exist in the database.
if (isset($customer['id']))
{
$num_rows = $this->db->get_where('ea_users',
['id' => $customer['id']])->num_rows();
if ($num_rows == 0)
{
throw new Exception('Provided customer id does not '
. 'exist in the database.');
}
}
$query = $this->db->get_where('ea_settings', ['name' => 'require_phone_number']);
$phone_number_required = $query->num_rows() > 0 ? $query->row() === '1' : FALSE;
// Validate required fields
if (empty($customer['first_name'])
|| empty($customer['last_name'])
|| empty($customer['email'])
|| (empty($customer['phone_number']) && $phone_number_required))
{
throw new Exception('Not all required fields are provided: '
. print_r($customer, TRUE));
}
// Validate email address
if ( ! filter_var($customer['email'], FILTER_VALIDATE_EMAIL))
{
throw new Exception('Invalid email address provided: '
. $customer['email']);
}
// When inserting a record the email address must be unique.
$customer_id = (isset($customer['id'])) ? $customer['id'] : '';
$num_rows = $this->db
->select('*')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_roles.slug', DB_SLUG_CUSTOMER)
->where('ea_users.email', $customer['email'])
->where('ea_users.id <>', $customer_id)
->get()
->num_rows();
if ($num_rows > 0)
{
throw new Exception('Given email address belongs to another customer record. '
. 'Please use a different email.');
}
return TRUE;
}
/**
* Check if a particular customer record already exists.
*
@ -85,6 +156,45 @@ class Customers_Model extends CI_Model {
return ($num_rows > 0) ? TRUE : FALSE;
}
/**
* Find the database id of a customer record.
*
* The customer data should include the following fields in order to get the unique id from the database: "email"
*
* IMPORTANT: The record must already exists in the database, otherwise an exception is raised.
*
* @param array $customer Array with the customer data. The keys of the array should have the same names as the
* database fields.
*
* @return int Returns the ID.
*
* @throws Exception If customer record does not exist.
*/
public function find_record_id($customer)
{
if (empty($customer['email']))
{
throw new Exception('Customer\'s email was not provided: '
. print_r($customer, TRUE));
}
// Get customer's role id
$result = $this->db
->select('ea_users.id')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $customer['email'])
->where('ea_roles.slug', DB_SLUG_CUSTOMER)
->get();
if ($result->num_rows() == 0)
{
throw new Exception('Could not find customer record id.');
}
return $result->row()->id;
}
/**
* Insert a new customer record to the database.
*
@ -139,113 +249,6 @@ class Customers_Model extends CI_Model {
return (int)$customer['id'];
}
/**
* Find the database id of a customer record.
*
* The customer data should include the following fields in order to get the unique id from the database: "email"
*
* IMPORTANT: The record must already exists in the database, otherwise an exception is raised.
*
* @param array $customer Array with the customer data. The keys of the array should have the same names as the
* database fields.
*
* @return int Returns the ID.
*
* @throws Exception If customer record does not exist.
*/
public function find_record_id($customer)
{
if (empty($customer['email']))
{
throw new Exception('Customer\'s email was not provided: '
. print_r($customer, TRUE));
}
// Get customer's role id
$result = $this->db
->select('ea_users.id')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $customer['email'])
->where('ea_roles.slug', DB_SLUG_CUSTOMER)
->get();
if ($result->num_rows() == 0)
{
throw new Exception('Could not find customer record id.');
}
return $result->row()->id;
}
/**
* Validate customer data before the insert or update operation is executed.
*
* @param array $customer Contains the customer data.
*
* @return bool Returns the validation result.
*
* @throws Exception If customer validation fails.
*/
public function validate($customer)
{
$this->load->helper('data_validation');
// If a customer id is provided, check whether the record
// exist in the database.
if (isset($customer['id']))
{
$num_rows = $this->db->get_where('ea_users',
['id' => $customer['id']])->num_rows();
if ($num_rows == 0)
{
throw new Exception('Provided customer id does not '
. 'exist in the database.');
}
}
$query = $this->db->get_where('ea_settings', ['name' => 'require_phone_number']);
$phone_number_required = $query->num_rows() > 0 ? $query->row() === '1' : false;
// Validate required fields
if ( empty($customer['first_name'])
|| empty($customer['last_name'])
|| empty($customer['email'])
|| (empty($customer['phone_number']) && $phone_number_required))
{
throw new Exception('Not all required fields are provided: '
. print_r($customer, TRUE));
}
// Validate email address
if ( ! filter_var($customer['email'], FILTER_VALIDATE_EMAIL))
{
throw new Exception('Invalid email address provided: '
. $customer['email']);
}
// When inserting a record the email address must be unique.
$customer_id = (isset($customer['id'])) ? $customer['id'] : '';
$num_rows = $this->db
->select('*')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_roles.slug', DB_SLUG_CUSTOMER)
->where('ea_users.email', $customer['email'])
->where('ea_users.id <>', $customer_id)
->get()
->num_rows();
if ($num_rows > 0)
{
throw new Exception('Given email address belongs to another customer record. '
. 'Please use a different email.');
}
return TRUE;
}
/**
* Delete an existing customer record from the database.
*

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -41,6 +41,9 @@
* 'sync_future_days',
* 'calendar_view'
*
* @property CI_DB_query_builder db
* @property CI_Loader load
*
* @package Models
*/
class Providers_Model extends CI_Model {
@ -77,144 +80,6 @@ class Providers_Model extends CI_Model {
return (int)$provider['id'];
}
/**
* Check whether a particular provider record already exists in the database.
*
* @param array $provider Contains the provider data. The 'email' value is required in order to check for a provider.
*
* @return bool Returns whether the provider record exists or not.
*
* @throws Exception When the 'email' value is not provided.
*/
public function exists($provider)
{
if ( ! isset($provider['email']))
{
throw new Exception('Provider email is not provided:' . print_r($provider, TRUE));
}
// This method shouldn't depend on another method of this class.
$num_rows = $this->db
->select('*')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $provider['email'])
->where('ea_roles.slug', DB_SLUG_PROVIDER)
->get()->num_rows();
return ($num_rows > 0) ? TRUE : FALSE;
}
/**
* Insert a new provider record into the database.
*
* @param array $provider Contains the provider data (must be already validated).
*
* @return int Returns the new record id.
*
* @throws Exception When the insert operation fails.
*/
protected function _insert($provider)
{
$this->load->helper('general');
// Get provider role id.
$provider['id_roles'] = $this->get_providers_role_id();
// Store provider settings and services (must not be present on the $provider array).
$services = $provider['services'];
unset($provider['services']);
$settings = $provider['settings'];
unset($provider['settings']);
// Insert provider record and save settings.
if ( ! $this->db->insert('ea_users', $provider))
{
throw new Exception('Could not insert provider into the database');
}
$settings['salt'] = generate_salt();
$settings['password'] = hash_password($settings['salt'], $settings['password']);
$provider['id'] = $this->db->insert_id();
$this->save_settings($settings, $provider['id']);
$this->save_services($services, $provider['id']);
// Return the new record id.
return (int)$provider['id'];
}
/**
* Update an existing provider record in the database.
*
* @param array $provider Contains the provider data.
*
* @return int Returns the record id.
*
* @throws Exception When the update operation fails.
*/
protected function _update($provider)
{
$this->load->helper('general');
// Store service and settings (must not be present on the $provider array).
$services = $provider['services'];
unset($provider['services']);
$settings = $provider['settings'];
unset($provider['settings']);
if (isset($settings['password']))
{
$salt = $this->db->get_where('ea_user_settings', ['id_users' => $provider['id']])->row()->salt;
$settings['password'] = hash_password($salt, $settings['password']);
}
// Update provider record.
$this->db->where('id', $provider['id']);
if ( ! $this->db->update('ea_users', $provider))
{
throw new Exception('Could not update provider record.');
}
$this->save_services($services, $provider['id']);
$this->save_settings($settings, $provider['id']);
// Return record id.
return (int)$provider['id'];
}
/**
* Find the database record id of a provider.
*
* @param array $provider Contains the provider data. The 'email' value is required in order to find the record id.
*
* @return int Returns the record id.
*
* @throws Exception When the provider's email value is not provided.
*/
public function find_record_id($provider)
{
if ( ! isset($provider['email']))
{
throw new Exception('Provider email was not provided:' . print_r($provider, TRUE));
}
$result = $this->db
->select('ea_users.id')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $provider['email'])
->where('ea_roles.slug', DB_SLUG_PROVIDER)
->get();
if ($result->num_rows() == 0)
{
throw new Exception('Could not find provider record id.');
}
return (int)$result->row()->id;
}
/**
* Validate provider data before the insert or update operation is executed.
*
@ -328,6 +193,260 @@ class Providers_Model extends CI_Model {
return TRUE;
}
/**
* Validate Records Username
*
* @param string $username The provider records username.
* @param int $user_id The user record id.
*
* @return bool Returns the validation result.
*/
public function validate_username($username, $user_id)
{
$num_rows = $this->db->get_where('ea_user_settings',
['username' => $username, 'id_users <> ' => $user_id])->num_rows();
return ($num_rows > 0) ? FALSE : TRUE;
}
/**
* Check whether a particular provider record already exists in the database.
*
* @param array $provider Contains the provider data. The 'email' value is required in order to check for a provider.
*
* @return bool Returns whether the provider record exists or not.
*
* @throws Exception When the 'email' value is not provided.
*/
public function exists($provider)
{
if ( ! isset($provider['email']))
{
throw new Exception('Provider email is not provided:' . print_r($provider, TRUE));
}
// This method shouldn't depend on another method of this class.
$num_rows = $this->db
->select('*')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $provider['email'])
->where('ea_roles.slug', DB_SLUG_PROVIDER)
->get()->num_rows();
return ($num_rows > 0) ? TRUE : FALSE;
}
/**
* Find the database record id of a provider.
*
* @param array $provider Contains the provider data. The 'email' value is required in order to find the record id.
*
* @return int Returns the record id.
*
* @throws Exception When the provider's email value is not provided.
*/
public function find_record_id($provider)
{
if ( ! isset($provider['email']))
{
throw new Exception('Provider email was not provided:' . print_r($provider, TRUE));
}
$result = $this->db
->select('ea_users.id')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $provider['email'])
->where('ea_roles.slug', DB_SLUG_PROVIDER)
->get();
if ($result->num_rows() == 0)
{
throw new Exception('Could not find provider record id.');
}
return (int)$result->row()->id;
}
/**
* Insert a new provider record into the database.
*
* @param array $provider Contains the provider data (must be already validated).
*
* @return int Returns the new record id.
*
* @throws Exception When the insert operation fails.
*/
protected function _insert($provider)
{
$this->load->helper('general');
// Get provider role id.
$provider['id_roles'] = $this->get_providers_role_id();
// Store provider settings and services (must not be present on the $provider array).
$services = $provider['services'];
unset($provider['services']);
$settings = $provider['settings'];
unset($provider['settings']);
// Insert provider record and save settings.
if ( ! $this->db->insert('ea_users', $provider))
{
throw new Exception('Could not insert provider into the database');
}
$settings['salt'] = generate_salt();
$settings['password'] = hash_password($settings['salt'], $settings['password']);
$provider['id'] = $this->db->insert_id();
$this->save_settings($settings, $provider['id']);
$this->save_services($services, $provider['id']);
// Return the new record id.
return (int)$provider['id'];
}
/**
* Get the providers role id from the database.
*
* @return int Returns the role id for the provider records.
*/
public function get_providers_role_id()
{
return $this->db->get_where('ea_roles', ['slug' => DB_SLUG_PROVIDER])->row()->id;
}
/**
* Save the provider settings (used from insert or update operation).
*
* @param array $settings Contains the setting values.
* @param int $provider_id Record id of the provider.
*
* @throws Exception If $provider_id argument is invalid.
* @throws Exception If $settings argument is invalid.
*/
protected function save_settings($settings, $provider_id)
{
if ( ! is_numeric($provider_id))
{
throw new Exception('Invalid $provider_id argument given:' . $provider_id);
}
if (count($settings) == 0 || ! is_array($settings))
{
throw new Exception('Invalid $settings argument given:' . print_r($settings, TRUE));
}
// Check if the setting record exists in db.
if ($this->db->get_where('ea_user_settings', ['id_users' => $provider_id])
->num_rows() == 0)
{
$this->db->insert('ea_user_settings', ['id_users' => $provider_id]);
}
foreach ($settings as $name => $value)
{
// Sort in descending order the extra working plan days
if ($name == 'extra_working_plan')
{
$value = json_decode($value, TRUE);
// Sort the array and put in reverse order
krsort($value);
$value = json_encode($value);
}
$this->set_setting($name, $value, $provider_id);
}
}
/**
* Set a provider's setting value in the database.
*
* The provider and settings record must already exist.
*
* @param string $setting_name The setting's name.
* @param string $value The setting's value.
* @param int $provider_id The selected provider id.
*/
public function set_setting($setting_name, $value, $provider_id)
{
$this->db->where(['id_users' => $provider_id]);
return $this->db->update('ea_user_settings', [$setting_name => $value]);
}
/**
* Save the provider services in the database (use on both insert and update operation).
*
* @param array $services Contains the service ids that the selected provider can provide.
* @param int $provider_id The selected provider record id.
*
* @throws Exception When the $services argument type is not array.
* @throws Exception When the $provider_id argument type is not int.
*/
protected function save_services($services, $provider_id)
{
// Validate method arguments.
if ( ! is_array($services))
{
throw new Exception('Invalid argument type $services: ' . $services);
}
if ( ! is_numeric($provider_id))
{
throw new Exception('Invalid argument type $provider_id: ' . $provider_id);
}
// Save provider services in the database (delete old records and add new).
$this->db->delete('ea_services_providers', ['id_users' => $provider_id]);
foreach ($services as $service_id)
{
$service_provider = [
'id_users' => $provider_id,
'id_services' => $service_id
];
$this->db->insert('ea_services_providers', $service_provider);
}
}
/**
* Update an existing provider record in the database.
*
* @param array $provider Contains the provider data.
*
* @return int Returns the record id.
*
* @throws Exception When the update operation fails.
*/
protected function _update($provider)
{
$this->load->helper('general');
// Store service and settings (must not be present on the $provider array).
$services = $provider['services'];
unset($provider['services']);
$settings = $provider['settings'];
unset($provider['settings']);
if (isset($settings['password']))
{
$salt = $this->db->get_where('ea_user_settings', ['id_users' => $provider['id']])->row()->salt;
$settings['password'] = hash_password($salt, $settings['password']);
}
// Update provider record.
$this->db->where('id', $provider['id']);
if ( ! $this->db->update('ea_users', $provider))
{
throw new Exception('Could not update provider record.');
}
$this->save_services($services, $provider['id']);
$this->save_settings($settings, $provider['id']);
// Return record id.
return (int)$provider['id'];
}
/**
* Delete an existing provider record from the database.
*
@ -539,120 +658,6 @@ class Providers_Model extends CI_Model {
return $providers;
}
/**
* Get the providers role id from the database.
*
* @return int Returns the role id for the provider records.
*/
public function get_providers_role_id()
{
return $this->db->get_where('ea_roles', ['slug' => DB_SLUG_PROVIDER])->row()->id;
}
/**
* Get a providers setting from the database.
*
* @param string $setting_name The setting name that is going to be returned.
* @param int $provider_id The selected provider id.
*
* @return string Returns the value of the selected user setting.
*/
public function get_setting($setting_name, $provider_id)
{
$provider_settings = $this->db->get_where('ea_user_settings', ['id_users' => $provider_id])->row_array();
return $provider_settings[$setting_name];
}
/**
* Set a provider's setting value in the database.
*
* The provider and settings record must already exist.
*
* @param string $setting_name The setting's name.
* @param string $value The setting's value.
* @param int $provider_id The selected provider id.
*/
public function set_setting($setting_name, $value, $provider_id)
{
$this->db->where(['id_users' => $provider_id]);
return $this->db->update('ea_user_settings', [$setting_name => $value]);
}
/**
* Save the provider settings (used from insert or update operation).
*
* @param array $settings Contains the setting values.
* @param int $provider_id Record id of the provider.
*
* @throws Exception If $provider_id argument is invalid.
* @throws Exception If $settings argument is invalid.
*/
protected function save_settings($settings, $provider_id)
{
if ( ! is_numeric($provider_id))
{
throw new Exception('Invalid $provider_id argument given:' . $provider_id);
}
if (count($settings) == 0 || ! is_array($settings))
{
throw new Exception('Invalid $settings argument given:' . print_r($settings, TRUE));
}
// Check if the setting record exists in db.
if ($this->db->get_where('ea_user_settings', ['id_users' => $provider_id])
->num_rows() == 0)
{
$this->db->insert('ea_user_settings', ['id_users' => $provider_id]);
}
foreach ($settings as $name => $value)
{
// Sort in descending order the extra working plan days
if ($name == 'extra_working_plan') {
$value = json_decode($value, true);
// Sort the array and put in reverse order
krsort($value);
$value = json_encode($value);
}
$this->set_setting($name, $value, $provider_id);
}
}
/**
* Save the provider services in the database (use on both insert and update operation).
*
* @param array $services Contains the service ids that the selected provider can provide.
* @param int $provider_id The selected provider record id.
*
* @throws Exception When the $services argument type is not array.
* @throws Exception When the $provider_id argument type is not int.
*/
protected function save_services($services, $provider_id)
{
// Validate method arguments.
if ( ! is_array($services))
{
throw new Exception('Invalid argument type $services: ' . $services);
}
if ( ! is_numeric($provider_id))
{
throw new Exception('Invalid argument type $provider_id: ' . $provider_id);
}
// Save provider services in the database (delete old records and add new).
$this->db->delete('ea_services_providers', ['id_users' => $provider_id]);
foreach ($services as $service_id)
{
$service_provider = [
'id_users' => $provider_id,
'id_services' => $service_id
];
$this->db->insert('ea_services_providers', $service_provider);
}
}
/**
* Save the provider extra working plan days.
*
@ -668,8 +673,8 @@ class Providers_Model extends CI_Model {
{
// Validate period
$dateStart = date('Y-m-d', strtotime($extra_period['start_datetime']));
$start = date('H:i',strtotime($extra_period['start_datetime']));
$end = date('H:i',strtotime($extra_period['end_datetime']));
$start = date('H:i', strtotime($extra_period['start_datetime']));
$end = date('H:i', strtotime($extra_period['end_datetime']));
if ($start > $end)
{
throw new Exception('Unavailable period start must be prior to end.');
@ -687,7 +692,7 @@ class Providers_Model extends CI_Model {
}
// Add record to database.
$extra_working_plan = json_decode($this->get_setting('extra_working_plan', $provider_id), true);
$extra_working_plan = json_decode($this->get_setting('extra_working_plan', $provider_id), TRUE);
$extra_working_plan[$dateStart] = [
'start' => $start,
@ -700,6 +705,20 @@ class Providers_Model extends CI_Model {
return $success;
}
/**
* Get a providers setting from the database.
*
* @param string $setting_name The setting name that is going to be returned.
* @param int $provider_id The selected provider id.
*
* @return string Returns the value of the selected user setting.
*/
public function get_setting($setting_name, $provider_id)
{
$provider_settings = $this->db->get_where('ea_user_settings', ['id_users' => $provider_id])->row_array();
return $provider_settings[$setting_name];
}
/**
* Delete a provider extra working plan day.
*
@ -724,7 +743,7 @@ class Providers_Model extends CI_Model {
}
// Add record to database.
$extra_working_plan = json_decode($this->get_setting('extra_working_plan', $provider_id), true);
$extra_working_plan = json_decode($this->get_setting('extra_working_plan', $provider_id), TRUE);
unset($extra_working_plan[$extra_period]);
@ -732,19 +751,4 @@ class Providers_Model extends CI_Model {
return $success;
}
/**
* Validate Records Username
*
* @param string $username The provider records username.
* @param int $user_id The user record id.
*
* @return bool Returns the validation result.
*/
public function validate_username($username, $user_id)
{
$num_rows = $this->db->get_where('ea_user_settings',
['username' => $username, 'id_users <> ' => $user_id])->num_rows();
return ($num_rows > 0) ? FALSE : TRUE;
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,6 +14,9 @@
/**
* Roles Model
*
* @property CI_DB_query_builder db
* @property CI_Loader load
*
* @package Models
*/
class Roles_Model extends CI_Model {

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -32,6 +32,9 @@
* 'providers' >> array with provider ids that the secretary handles
* 'settings' >> array with the secretary settings
*
* @property CI_DB_query_builder db
* @property CI_Loader load
*
* @package Models
*/
class Secretaries_Model extends CI_Model {
@ -56,7 +59,8 @@ class Secretaries_Model extends CI_Model {
if ( ! isset($secretary['id']))
{
$secretary['id'] = $this->_insert($secretary);
} else
}
else
{
$secretary['id'] = $this->_update($secretary);
}
@ -64,137 +68,6 @@ class Secretaries_Model extends CI_Model {
return (int)$secretary['id'];
}
/**
* Check whether a particular secretary record exists in the database.
*
* @param array $secretary Contains the secretary data. The 'email' value is required to be present at the moment.
*
* @return bool Returns whether the record exists or not.
*
* @throws Exception When the 'email' value is not present on the $secretary argument.
*/
public function exists($secretary)
{
if ( ! isset($secretary['email']))
{
throw new Exception('Secretary email is not provided: ' . print_r($secretary, TRUE));
}
// This method shouldn't depend on another method of this class.
$num_rows = $this->db
->select('*')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $secretary['email'])
->where('ea_roles.slug', DB_SLUG_SECRETARY)
->get()->num_rows();
return ($num_rows > 0) ? TRUE : FALSE;
}
/**
* Insert a new secretary record into the database.
*
* @param array $secretary Contains the secretary data.
*
* @return int Returns the new record id.
*
* @throws Exception When the insert operation fails.
*/
protected function _insert($secretary)
{
$this->load->helper('general');
$providers = $secretary['providers'];
unset($secretary['providers']);
$settings = $secretary['settings'];
unset($secretary['settings']);
$secretary['id_roles'] = $this->get_secretary_role_id();
if ( ! $this->db->insert('ea_users', $secretary))
{
throw new Exception('Could not insert secretary into the database.');
}
$secretary['id'] = (int)$this->db->insert_id();
$settings['salt'] = generate_salt();
$settings['password'] = hash_password($settings['salt'], $settings['password']);
$this->save_providers($providers, $secretary['id']);
$this->save_settings($settings, $secretary['id']);
return $secretary['id'];
}
/**
* Update an existing secretary record in the database.
*
* @param array $secretary Contains the secretary record data.
*
* @return int Returns the record id.
*
* @throws Exception When the update operation fails.
*/
protected function _update($secretary)
{
$this->load->helper('general');
$providers = $secretary['providers'];
unset($secretary['providers']);
$settings = $secretary['settings'];
unset($secretary['settings']);
if (isset($settings['password']))
{
$salt = $this->db->get_where('ea_user_settings', ['id_users' => $secretary['id']])->row()->salt;
$settings['password'] = hash_password($salt, $settings['password']);
}
$this->db->where('id', $secretary['id']);
if ( ! $this->db->update('ea_users', $secretary))
{
throw new Exception('Could not update secretary record.');
}
$this->save_providers($providers, $secretary['id']);
$this->save_settings($settings, $secretary['id']);
return (int)$secretary['id'];
}
/**
* Find the database record id of a secretary.
*
* @param array $secretary Contains the secretary data. The 'email' value is required in order to find the record id.
*
* @return int Returns the record id
*
* @throws Exception When the 'email' value is not present on the $secretary array.
*/
public function find_record_id($secretary)
{
if ( ! isset($secretary['email']))
{
throw new Exception('Secretary email was not provided: ' . print_r($secretary, TRUE));
}
$result = $this->db
->select('ea_users.id')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $secretary['email'])
->where('ea_roles.slug', DB_SLUG_SECRETARY)
->get();
if ($result->num_rows() == 0)
{
throw new Exception('Could not find secretary record id.');
}
return (int)$result->row()->id;
}
/**
* Validate secretary user data before add() operation is executed.
*
@ -290,6 +163,242 @@ class Secretaries_Model extends CI_Model {
return TRUE;
}
/**
* Validate Records Username
*
* @param string $username The provider records username.
* @param int $user_id The user record id.
*
* @return bool Returns the validation result.
*/
public function validate_username($username, $user_id)
{
$num_rows = $this->db->get_where('ea_user_settings',
['username' => $username, 'id_users <> ' => $user_id])->num_rows();
return ($num_rows > 0) ? FALSE : TRUE;
}
/**
* Check whether a particular secretary record exists in the database.
*
* @param array $secretary Contains the secretary data. The 'email' value is required to be present at the moment.
*
* @return bool Returns whether the record exists or not.
*
* @throws Exception When the 'email' value is not present on the $secretary argument.
*/
public function exists($secretary)
{
if ( ! isset($secretary['email']))
{
throw new Exception('Secretary email is not provided: ' . print_r($secretary, TRUE));
}
// This method shouldn't depend on another method of this class.
$num_rows = $this->db
->select('*')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $secretary['email'])
->where('ea_roles.slug', DB_SLUG_SECRETARY)
->get()->num_rows();
return ($num_rows > 0) ? TRUE : FALSE;
}
/**
* Find the database record id of a secretary.
*
* @param array $secretary Contains the secretary data. The 'email' value is required in order to find the record id.
*
* @return int Returns the record id
*
* @throws Exception When the 'email' value is not present on the $secretary array.
*/
public function find_record_id($secretary)
{
if ( ! isset($secretary['email']))
{
throw new Exception('Secretary email was not provided: ' . print_r($secretary, TRUE));
}
$result = $this->db
->select('ea_users.id')
->from('ea_users')
->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
->where('ea_users.email', $secretary['email'])
->where('ea_roles.slug', DB_SLUG_SECRETARY)
->get();
if ($result->num_rows() == 0)
{
throw new Exception('Could not find secretary record id.');
}
return (int)$result->row()->id;
}
/**
* Insert a new secretary record into the database.
*
* @param array $secretary Contains the secretary data.
*
* @return int Returns the new record id.
*
* @throws Exception When the insert operation fails.
*/
protected function _insert($secretary)
{
$this->load->helper('general');
$providers = $secretary['providers'];
unset($secretary['providers']);
$settings = $secretary['settings'];
unset($secretary['settings']);
$secretary['id_roles'] = $this->get_secretary_role_id();
if ( ! $this->db->insert('ea_users', $secretary))
{
throw new Exception('Could not insert secretary into the database.');
}
$secretary['id'] = (int)$this->db->insert_id();
$settings['salt'] = generate_salt();
$settings['password'] = hash_password($settings['salt'], $settings['password']);
$this->save_providers($providers, $secretary['id']);
$this->save_settings($settings, $secretary['id']);
return $secretary['id'];
}
/**
* Get the secretary users role id.
*
* @return int Returns the role record id.
*/
public function get_secretary_role_id()
{
return (int)$this->db->get_where('ea_roles', ['slug' => DB_SLUG_SECRETARY])->row()->id;
}
/**
* Save a secretary handling users.
*
* @param array $providers Contains the provider ids that are handled by the secretary.
* @param int $secretary_id The selected secretary record.
*
* @throws Exception If $providers argument is invalid.
*/
protected function save_providers($providers, $secretary_id)
{
if ( ! is_array($providers))
{
throw new Exception('Invalid argument given $providers: ' . print_r($providers, TRUE));
}
// Delete old connections
$this->db->delete('ea_secretaries_providers', ['id_users_secretary' => $secretary_id]);
if (count($providers) > 0)
{
foreach ($providers as $provider_id)
{
$this->db->insert('ea_secretaries_providers', [
'id_users_secretary' => $secretary_id,
'id_users_provider' => $provider_id
]);
}
}
}
/**
* Save the secretary settings (used from insert or update operation).
*
* @param array $settings Contains the setting values.
* @param int $secretary_id Record id of the secretary.
*
* @throws Exception If $secretary_id argument is invalid.
* @throws Exception If $settings argument is invalid.
*/
protected function save_settings($settings, $secretary_id)
{
if ( ! is_numeric($secretary_id))
{
throw new Exception('Invalid $secretary_id argument given:' . $secretary_id);
}
if (count($settings) == 0 || ! is_array($settings))
{
throw new Exception('Invalid $settings argument given:' . print_r($settings, TRUE));
}
// Check if the setting record exists in db.
$num_rows = $this->db->get_where('ea_user_settings',
['id_users' => $secretary_id])->num_rows();
if ($num_rows == 0)
{
$this->db->insert('ea_user_settings', ['id_users' => $secretary_id]);
}
foreach ($settings as $name => $value)
{
$this->set_setting($name, $value, $secretary_id);
}
}
/**
* Set a provider's setting value in the database.
*
* The provider and settings record must already exist.
*
* @param string $setting_name The setting's name.
* @param string $value The setting's value.
* @param int $secretary_id The selected provider id.
*/
public function set_setting($setting_name, $value, $secretary_id)
{
$this->db->where(['id_users' => $secretary_id]);
return $this->db->update('ea_user_settings', [$setting_name => $value]);
}
/**
* Update an existing secretary record in the database.
*
* @param array $secretary Contains the secretary record data.
*
* @return int Returns the record id.
*
* @throws Exception When the update operation fails.
*/
protected function _update($secretary)
{
$this->load->helper('general');
$providers = $secretary['providers'];
unset($secretary['providers']);
$settings = $secretary['settings'];
unset($secretary['settings']);
if (isset($settings['password']))
{
$salt = $this->db->get_where('ea_user_settings', ['id_users' => $secretary['id']])->row()->salt;
$settings['password'] = hash_password($salt, $settings['password']);
}
$this->db->where('id', $secretary['id']);
if ( ! $this->db->update('ea_users', $secretary))
{
throw new Exception('Could not update secretary record.');
}
$this->save_providers($providers, $secretary['id']);
$this->save_settings($settings, $secretary['id']);
return (int)$secretary['id'];
}
/**
* Delete an existing secretary record from the database.
*
@ -445,81 +554,6 @@ class Secretaries_Model extends CI_Model {
return $batch;
}
/**
* Get the secretary users role id.
*
* @return int Returns the role record id.
*/
public function get_secretary_role_id()
{
return (int)$this->db->get_where('ea_roles', ['slug' => DB_SLUG_SECRETARY])->row()->id;
}
/**
* Save a secretary handling users.
*
* @param array $providers Contains the provider ids that are handled by the secretary.
* @param int $secretary_id The selected secretary record.
*
* @throws Exception If $providers argument is invalid.
*/
protected function save_providers($providers, $secretary_id)
{
if ( ! is_array($providers))
{
throw new Exception('Invalid argument given $providers: ' . print_r($providers, TRUE));
}
// Delete old connections
$this->db->delete('ea_secretaries_providers', ['id_users_secretary' => $secretary_id]);
if (count($providers) > 0)
{
foreach ($providers as $provider_id)
{
$this->db->insert('ea_secretaries_providers', [
'id_users_secretary' => $secretary_id,
'id_users_provider' => $provider_id
]);
}
}
}
/**
* Save the secretary settings (used from insert or update operation).
*
* @param array $settings Contains the setting values.
* @param int $secretary_id Record id of the secretary.
*
* @throws Exception If $secretary_id argument is invalid.
* @throws Exception If $settings argument is invalid.
*/
protected function save_settings($settings, $secretary_id)
{
if ( ! is_numeric($secretary_id))
{
throw new Exception('Invalid $secretary_id argument given:' . $secretary_id);
}
if (count($settings) == 0 || ! is_array($settings))
{
throw new Exception('Invalid $settings argument given:' . print_r($settings, TRUE));
}
// Check if the setting record exists in db.
$num_rows = $this->db->get_where('ea_user_settings',
['id_users' => $secretary_id])->num_rows();
if ($num_rows == 0)
{
$this->db->insert('ea_user_settings', ['id_users' => $secretary_id]);
}
foreach ($settings as $name => $value)
{
$this->set_setting($name, $value, $secretary_id);
}
}
/**
* Get a providers setting from the database.
*
@ -534,34 +568,4 @@ class Secretaries_Model extends CI_Model {
['id_users' => $secretary_id])->row_array();
return $provider_settings[$setting_name];
}
/**
* Set a provider's setting value in the database.
*
* The provider and settings record must already exist.
*
* @param string $setting_name The setting's name.
* @param string $value The setting's value.
* @param int $secretary_id The selected provider id.
*/
public function set_setting($setting_name, $value, $secretary_id)
{
$this->db->where(['id_users' => $secretary_id]);
return $this->db->update('ea_user_settings', [$setting_name => $value]);
}
/**
* Validate Records Username
*
* @param string $username The provider records username.
* @param int $user_id The user record id.
*
* @return bool Returns the validation result.
*/
public function validate_username($username, $user_id)
{
$num_rows = $this->db->get_where('ea_user_settings',
['username' => $username, 'id_users <> ' => $user_id])->num_rows();
return ($num_rows > 0) ? FALSE : TRUE;
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,6 +14,9 @@
/**
* Services Model
*
* @property CI_DB_query_builder db
* @property CI_Loader load
*
* @package Models
*/
class Services_Model extends CI_Model {
@ -23,6 +26,7 @@ class Services_Model extends CI_Model {
* @param array $service Contains the service data. If an 'id' value is provided then the record will be updated.
*
* @return int Returns the record id.
* @throws Exception
*/
public function add($service)
{
@ -40,69 +44,6 @@ class Services_Model extends CI_Model {
return (int)$service['id'];
}
/**
* Insert service record into database.
*
* @param array $service Contains the service record data.
*
* @return int Returns the new service record id.
*
* @throws Exception If service record could not be inserted.
*/
protected function _insert($service)
{
if ( ! $this->db->insert('ea_services', $service))
{
throw new Exception('Could not insert service record.');
}
return (int)$this->db->insert_id();
}
/**
* Update service record.
*
* @param array $service Contains the service data. The record id needs to be included in the array.
*
* @throws Exception If service record could not be updated.
*/
protected function _update($service)
{
$this->db->where('id', $service['id']);
if ( ! $this->db->update('ea_services', $service))
{
throw new Exception('Could not update service record');
}
}
/**
* Checks whether an service record already exists in the database.
*
* @param array $service Contains the service data. Name, duration and price values are mandatory in order to
* perform the checks.
*
* @return bool Returns whether the service record exists.
*
* @throws Exception If required fields are missing.
*/
public function exists($service)
{
if ( ! isset($service['name'])
|| ! isset($service['duration'])
|| ! isset($service['price']))
{
throw new Exception('Not all service fields are provided in order to check whether '
. 'a service record already exists: ' . print_r($service, TRUE));
}
$num_rows = $this->db->get_where('ea_services', [
'name' => $service['name'],
'duration' => $service['duration'],
'price' => $service['price']
])->num_rows();
return ($num_rows > 0) ? TRUE : FALSE;
}
/**
* Validate a service record data.
*
@ -181,6 +122,69 @@ class Services_Model extends CI_Model {
return TRUE;
}
/**
* Insert service record into database.
*
* @param array $service Contains the service record data.
*
* @return int Returns the new service record id.
*
* @throws Exception If service record could not be inserted.
*/
protected function _insert($service)
{
if ( ! $this->db->insert('ea_services', $service))
{
throw new Exception('Could not insert service record.');
}
return (int)$this->db->insert_id();
}
/**
* Update service record.
*
* @param array $service Contains the service data. The record id needs to be included in the array.
*
* @throws Exception If service record could not be updated.
*/
protected function _update($service)
{
$this->db->where('id', $service['id']);
if ( ! $this->db->update('ea_services', $service))
{
throw new Exception('Could not update service record');
}
}
/**
* Checks whether an service record already exists in the database.
*
* @param array $service Contains the service data. Name, duration and price values are mandatory in order to
* perform the checks.
*
* @return bool Returns whether the service record exists.
*
* @throws Exception If required fields are missing.
*/
public function exists($service)
{
if ( ! isset($service['name'])
|| ! isset($service['duration'])
|| ! isset($service['price']))
{
throw new Exception('Not all service fields are provided in order to check whether '
. 'a service record already exists: ' . print_r($service, TRUE));
}
$num_rows = $this->db->get_where('ea_services', [
'name' => $service['name'],
'duration' => $service['duration'],
'price' => $service['price']
])->num_rows();
return ($num_rows > 0) ? TRUE : FALSE;
}
/**
* Get the record id of an existing record.
*
@ -304,12 +308,12 @@ class Services_Model extends CI_Model {
/**
* Get all, or specific records from service's table.
*
* @example $this->Model->getBatch('id = ' . $recordId);
*
* @param string $whereClause (OPTIONAL) The WHERE clause of
* the query to be executed. DO NOT INCLUDE 'WHERE' KEYWORD.
*
* @return array Returns the rows from the database.
* @example $this->Model->getBatch('id = ' . $recordId);
*
*/
public function get_batch($where = NULL, $order_by = NULL, $limit = NULL, $offset = NULL)
{
@ -376,6 +380,40 @@ class Services_Model extends CI_Model {
return (int)$category['id'];
}
/**
* Validate a service category record data. This method must be used before adding
* a service category record into database in order to secure the record integrity.
*
* @param array $category Contains the service category data.
*
* @return bool Returns the validation result.
*
* @throws Exception If required fields are missing.
*/
public function validate_category($category)
{
try
{
// Required Fields
if ( ! isset($category['name']))
{
throw new Exception('Not all required fields where provided ');
}
if ($category['name'] == '' || $category['name'] == NULL)
{
throw new Exception('Required fields cannot be empty or null ($category: '
. print_r($category, TRUE) . ')');
}
return TRUE;
}
catch (Exception $exception)
{
return FALSE;
}
}
/**
* Delete a service category record from the database.
*
@ -449,38 +487,4 @@ class Services_Model extends CI_Model {
return $this->db->get('ea_service_categories', $limit, $offset)->result_array();
}
/**
* Validate a service category record data. This method must be used before adding
* a service category record into database in order to secure the record integrity.
*
* @param array $category Contains the service category data.
*
* @return bool Returns the validation result.
*
* @throws Exception If required fields are missing.
*/
public function validate_category($category)
{
try
{
// Required Fields
if ( ! isset($category['name']))
{
throw new Exception('Not all required fields where provided ');
}
if ($category['name'] == '' || $category['name'] == NULL)
{
throw new Exception('Required fields cannot be empty or null ($category: '
. print_r($category, TRUE) . ')');
}
return TRUE;
}
catch (Exception $exc)
{
return FALSE;
}
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,6 +14,9 @@
/**
* Settings Model
*
* @property CI_DB_query_builder db
* @property CI_Loader load
*
* @package Models
*/
class Settings_Model extends CI_Model {

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -14,6 +14,9 @@
/**
* Timezones Model
*
* @property CI_DB_query_builder db
* @property CI_Loader load
*
* @package Models
*/
class Timezones_Model extends CI_Model {
@ -457,16 +460,6 @@ class Timezones_Model extends CI_Model {
],
];
/**
* Get all timezones to a flat array.
*
* @return array
*/
public function to_array()
{
return array_merge(...array_values($this->timezones));
}
/**
* Get all timezones to a grouped array (by continent).
*
@ -477,33 +470,6 @@ class Timezones_Model extends CI_Model {
return $this->timezones;
}
/**
* Convert a date time value to a new timezone.
*
* @param string $value Provide a date time value as a string (format Y-m-d H:i:s).
* @param string $from_timezone From timezone value.
* @param string $to_timezone To timezone value.
* @return string
* @throws Exception
*/
public function convert($value, $from_timezone, $to_timezone)
{
if ( ! $to_timezone)
{
return $value;
}
$from = new \DateTimeZone($from_timezone);
$to = new \DateTimeZone($to_timezone);
$result = new \DateTime($value, $from);
$result->setTimezone($to);
return $result->format('Y-m-d H:i:s');
}
/**
* Convert the dates of an event to the timezone of the user.
*
@ -558,6 +524,43 @@ class Timezones_Model extends CI_Model {
return isset($this->session->timezone) ? $this->session->timezone : $default_timezone;
}
/**
* Get the default timezone value of the current system.
*
* @return string
*/
public function get_default_timezone()
{
return 'UTC';
}
/**
* Convert a date time value to a new timezone.
*
* @param string $value Provide a date time value as a string (format Y-m-d H:i:s).
* @param string $from_timezone From timezone value.
* @param string $to_timezone To timezone value.
* @return string
* @throws Exception
*/
public function convert($value, $from_timezone, $to_timezone)
{
if ( ! $to_timezone)
{
return $value;
}
$from = new DateTimeZone($from_timezone);
$to = new DateTimeZone($to_timezone);
$result = new DateTime($value, $from);
$result->setTimezone($to);
return $result->format('Y-m-d H:i:s');
}
/**
* Get the timezone name for the provided value.
*
@ -571,14 +574,13 @@ class Timezones_Model extends CI_Model {
return isset($timezones[$value]) ? $timezones[$value] : NULL;
}
/**
* Get the default timezone value of the current system.
* Get all timezones to a flat array.
*
* @return string
* @return array
*/
public function get_default_timezone()
public function to_array()
{
return 'UTC';
return array_merge(...array_values($this->timezones));
}
}

View file

@ -1,4 +1,4 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
@ -16,6 +16,9 @@
*
* Contains current user's methods.
*
* @property CI_DB_query_builder db
* @property CI_Loader load
*
* @package Models
*/
class User_Model extends CI_Model {
@ -25,10 +28,8 @@ class User_Model extends CI_Model {
* @param int $user_id User record id.
*
* @return array Returns an array with user data.
*
* @todo Refactor this method as it does not do as it states.
*/
public function get_settings($user_id)
public function get_user($user_id)
{
$user = $this->db->get_where('ea_users', ['id' => $user_id])->row_array();
$user['settings'] = $this->db->get_where('ea_user_settings', ['id_users' => $user_id])->row_array();
@ -42,10 +43,8 @@ class User_Model extends CI_Model {
* @param array $user Contains the current users data.
*
* @return bool Returns the operation result.
*
* @todo Refactor this method as it does not do as it states.
*/
public function save_settings($user)
public function save_user($user)
{
$user_settings = $user['settings'];
$user_settings['id_users'] = $user['id'];
@ -72,19 +71,6 @@ class User_Model extends CI_Model {
return TRUE;
}
/**
* Retrieve user's salt from database.
*
* @param string $username This will be used to find the user record.
*
* @return string Returns the salt db value.
*/
public function get_salt($username)
{
$user = $this->db->get_where('ea_user_settings', ['username' => $username])->row_array();
return ($user) ? $user['salt'] : '';
}
/**
* Performs the check of the given user credentials.
*
@ -96,7 +82,7 @@ class User_Model extends CI_Model {
public function check_login($username, $password)
{
$this->load->helper('general');
$salt = $this->user_model->get_salt($username);
$salt = $this->get_salt($username);
$password = hash_password($salt, $password);
$user_settings = $this->db->get_where('ea_user_settings', [
@ -136,6 +122,19 @@ class User_Model extends CI_Model {
];
}
/**
* Retrieve user's salt from database.
*
* @param string $username This will be used to find the user record.
*
* @return string Returns the salt db value.
*/
public function get_salt($username)
{
$user = $this->db->get_where('ea_user_settings', ['username' => $username])->row_array();
return ($user) ? $user['salt'] : '';
}
/**
* Get the given user's display name (first + last name).
*

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@ -343,7 +343,7 @@
<a href="https://easyappointments.org" target="_blank">Easy!Appointments</a>
|
<span id="select-language" class="label label-success">
<?= ucfirst($this->config->item('language')) ?>
<?= ucfirst(config('language')) ?>
</span>
|
<a href="<?= site_url('backend'); ?>">
@ -385,7 +385,7 @@
};
var EALang = <?= json_encode($this->lang->language) ?>;
var availableLanguages = <?= json_encode($this->config->item('available_languages')) ?>;
var availableLanguages = <?= json_encode(config('available_languages')) ?>;
</script>
<script src="<?= asset_url('assets/js/general_functions.js') ?>"></script>

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@ -37,7 +37,7 @@
</a>
';
if ($this->config->item('google_sync_feature')) {
if (config('google_sync_feature')) {
echo '
<button id="add-to-google-calendar" class="btn btn-primary">
<span class="glyphicon glyphicon-plus"></span>
@ -49,8 +49,8 @@
if (isset($exceptions)) {
echo '<div class="col-xs-12" style="margin:10px">';
echo '<h4>Unexpected Errors</h4>';
foreach($exceptions as $exc) {
echo exceptionToHtml($exc);
foreach($exceptions as $exception) {
echo exceptionToHtml($exception);
}
echo '</div>';
}
@ -72,8 +72,8 @@
'providerData' : <?= json_encode($provider_data) ?>,
'serviceData' : <?= json_encode($service_data) ?>,
'companyName' : <?= json_encode($company_name) ?>,
'googleApiKey' : <?= json_encode(Config::GOOGLE_API_KEY) ?>,
'googleClientId' : <?= json_encode(Config::GOOGLE_CLIENT_ID) ?>,
'googleApiKey' : <?= json_encode(config('google_api_key')) ?>,
'googleClientId' : <?= json_encode(config('google_client_id')) ?>,
'googleApiScope' : 'https://www.googleapis.com/auth/calendar'
};

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@ -41,7 +41,7 @@
<h3><?= $message_title ?></h3>
<p><?= $message_text ?></p>
<?php if (isset($exceptions) && Config::DEBUG_MODE): ?>
<?php if (isset($exceptions) && config('debug')): ?>
<div>
<h4><?= lang('unexpected_issues') ?></h4>
<?php foreach($exceptions as $exception): ?>

View file

@ -53,7 +53,7 @@
<div id="calendar-actions" class="col-xs-12 col-sm-7">
<?php if (($role_slug == DB_SLUG_ADMIN || $role_slug == DB_SLUG_PROVIDER)
&& Config::GOOGLE_SYNC_FEATURE == TRUE): ?>
&& config('google_sync_feature') == TRUE): ?>
<button id="google-sync" class="btn btn-primary"
title="<?= lang('trigger_google_sync_hint') ?>">
<span class="glyphicon glyphicon-refresh"></span>

View file

@ -3,16 +3,16 @@
Powered by
<a href="https://easyappointments.org">Easy!Appointments
<?php
echo 'v' . $this->config->item('version');
echo 'v' . config('version');
$release_title = $this->config->item('release_label');
$release_title = config('release_label');
if ($release_title != '') {
echo ' - ' . $release_title;
}
?></a> |
<?= lang('licensed_under') ?> GPLv3 |
<span id="select-language" class="label label-success">
<?= ucfirst($this->config->item('language')) ?>
<?= ucfirst(config('language')) ?>
</span>
|
<a href="<?= site_url('appointments') ?>">

View file

@ -24,7 +24,7 @@
<script>
// Global JavaScript Variables - Used in all backend pages.
var availableLanguages = <?= json_encode($this->config->item('available_languages')) ?>;
var availableLanguages = <?= json_encode(config('available_languages')) ?>;
var EALang = <?= json_encode($this->lang->language) ?>;
</script>
</head>

View file

@ -502,9 +502,9 @@
<div class="current-version well">
<?= lang('current_version') ?>
<?= $this->config->item('version') ?>
<?php if ($this->config->item('release_label')): ?>
- <?= $this->config->item('release_label') ?>
<?= config('version') ?>
<?php if (config('release_label')): ?>
- <?= config('release_label') ?>
<?php endif ?>
</div>

View file

@ -1,4 +1,4 @@
<html>
<html lang="en">
<head>
<title><?= lang('appointment_details_title') ?></title>
</head>

View file

@ -1,4 +1,4 @@
<html>
<html lang="en">
<head>
<title><?= lang('appointment_cancelled_title') ?></title>
</head>

View file

@ -1,4 +1,4 @@
<html>
<html lang="en">
<head>
<title>New Account Password</title>
</head>

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>403 Forbidden</title>
</head>

View file

@ -1,4 +1,4 @@
<html>
<html lang="en">
<head>
<title>403 Forbidden</title>
</head>
@ -7,4 +7,4 @@
<p>Directory access is forbidden.</p>
</body>
</html>
</html>

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>Easy!Appointments - Installation</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>Easy!Appointments - Update</title>

View file

@ -1,4 +1,4 @@
<html>
<html lang="en">
<head>
<title>403 Forbidden</title>
</head>
@ -7,4 +7,4 @@
<p>Directory access is forbidden.</p>
</body>
</html>
</html>

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@ -53,7 +53,7 @@
};
var EALang = <?= json_encode($this->lang->language) ?>;
var availableLanguages = <?= json_encode($this->config->item('available_languages')) ?>;
var availableLanguages = <?= json_encode(config('available_languages')) ?>;
$(document).ready(function() {
GeneralFunctions.enableLanguageSelection($('#select-language'));
@ -125,7 +125,7 @@
<?= lang('forgot_your_password') ?></a>
|
<span id="select-language" class="label label-success">
<?= ucfirst($this->config->item('language')) ?>
<?= ucfirst(config('language')) ?>
</span>
</form>
</div>

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

View file

@ -203,7 +203,7 @@ window.FrontendBookApi = window.FrontendBookApi || {};
}
window.location.href = GlobalVariables.baseUrl
+ '/index.php/appointments/book_success/' + response.appointment_id;
+ '/index.php/appointments/book_success/' + response.appointment_hash;
})
.fail(function (jqxhr, textStatus, errorThrown) {
$('.captcha-title small').trigger('click');