Enable prettier for php and reformat the entire application directory

This commit is contained in:
Alex Tselegidis 2023-11-29 10:24:09 +01:00
parent df1f111a0e
commit c8a9e2c24b
679 changed files with 16132 additions and 14651 deletions

View file

@ -1,9 +1,10 @@
.idea
application
.github
.run
build
docker
docs
node_modules
storage
system
tests
vendor

View file

@ -5,5 +5,8 @@
"bracketSpacing": false,
"bracketSameLine": false,
"quoteProps": "preserve",
"trailingComma": "none"
"trailingComma": "none",
"trailingCommaPHP": false,
"phpVersion": "8.0",
"plugins": ["@prettier/plugin-php"]
}

View file

@ -11,7 +11,7 @@
$config['version'] = '1.5.0-dev.4'; // This must be changed manually.
$config['url'] = Config::BASE_URL;
$config['url'] = Config::BASE_URL;
$config['debug'] = Config::DEBUG_MODE;

View file

@ -40,7 +40,6 @@
$autoload['packages'] = [];
/*
| -------------------------------------------------------------------
| Auto-load Libraries
@ -55,7 +54,6 @@ $autoload['packages'] = [];
$autoload['libraries'] = ['database', 'session'];
/*
| -------------------------------------------------------------------
| Auto-load Helper Files
@ -89,7 +87,6 @@ $autoload['helper'] = [
'validation'
];
/*
| -------------------------------------------------------------------
| Auto-load Config files
@ -103,12 +100,7 @@ $autoload['helper'] = [
|
*/
$autoload['config'] = [
'app',
'google',
'email'
];
$autoload['config'] = ['app', 'google', 'email'];
/*
| -------------------------------------------------------------------
@ -125,7 +117,6 @@ $autoload['config'] = [
$autoload['language'] = [];
/*
| -------------------------------------------------------------------
| Auto-load Models
@ -138,6 +129,5 @@ $autoload['language'] = [];
$autoload['model'] = [];
/* End of file autoload.php */
/* Location: ./application/config/autoload.php */

View file

@ -16,17 +16,17 @@
*/
$protocol =
(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')
|| (isset($_SERVER['SERVER_PORT']) && (int)$_SERVER['SERVER_PORT'] === 443)
|| (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
? 'https://' : 'http://';
(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ||
(isset($_SERVER['SERVER_PORT']) && (int) $_SERVER['SERVER_PORT'] === 443) ||
(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
? 'https://'
: 'http://';
$domain = $_SERVER['HTTP_HOST'] ?? 'localhost';
$request_uri = dirname($_SERVER['SCRIPT_NAME']);
if ($request_uri === '.')
{
if ($request_uri === '.') {
$request_uri = '';
}
@ -117,7 +117,7 @@ $languages = [
'sk' => 'slovak',
'es' => 'spanish',
'sv' => 'swedish',
'tr' => 'turkish',
'tr' => 'turkish'
];
$config['language_codes'] = $languages;
@ -195,8 +195,7 @@ $config['charset'] = 'UTF-8';
| setting this variable to TRUE (boolean). See the user guide for details.
|
*/
$config['enable_hooks'] = TRUE;
$config['enable_hooks'] = true;
/*
|--------------------------------------------------------------------------
@ -212,7 +211,6 @@ $config['enable_hooks'] = TRUE;
*/
$config['subclass_prefix'] = 'EA_';
/*
|--------------------------------------------------------------------------
| Allowed URL Characters
@ -232,7 +230,6 @@ $config['subclass_prefix'] = 'EA_';
*/
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
/*
|--------------------------------------------------------------------------
| Enable Query Strings
@ -258,8 +255,8 @@ $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
| use segment based URLs.
|
*/
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;
$config['allow_get_array'] = true;
$config['enable_query_strings'] = false;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd'; // experimental not currently in use
@ -352,9 +349,9 @@ $config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ea_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = __DIR__ . '/../../storage/sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_ip'] = false;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['sess_regenerate_destroy'] = false;
/*
|--------------------------------------------------------------------------
@ -370,7 +367,7 @@ $config['sess_regenerate_destroy'] = FALSE;
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = strpos($config['base_url'], 'https') !== FALSE;
$config['cookie_secure'] = strpos($config['base_url'], 'https') !== false;
/*
|--------------------------------------------------------------------------
@ -384,16 +381,11 @@ $config['cookie_secure'] = strpos($config['base_url'], 'https') !== FALSE;
| 'csrf_cookie_name' = The cookie name
| 'csrf_expire' = The number in seconds the token should expire.
*/
$config['csrf_protection'] = TRUE;
$config['csrf_protection'] = true;
$config['csrf_token_name'] = 'csrf_token';
$config['csrf_cookie_name'] = 'csrf_cookie';
$config['csrf_expire'] = 7200;
$config['csrf_exclude_uris'] = [
'api/v1/.*',
'booking/.*',
'booking_cancellation/.*',
'booking_confirmation/.*'
];
$config['csrf_exclude_uris'] = ['api/v1/.*', 'booking/.*', 'booking_cancellation/.*', 'booking_confirmation/.*'];
/*
|--------------------------------------------------------------------------
@ -412,7 +404,7 @@ $config['csrf_exclude_uris'] = [
| by the output class. Do not 'echo' any values with compression enabled.
|
*/
$config['compress_output'] = FALSE;
$config['compress_output'] = false;
/*
|--------------------------------------------------------------------------
@ -427,7 +419,6 @@ $config['compress_output'] = FALSE;
*/
$config['time_reference'] = 'local';
/*
|--------------------------------------------------------------------------
| Rewrite PHP Short Tags
@ -438,8 +429,7 @@ $config['time_reference'] = 'local';
| in your view files. Options are TRUE or FALSE (boolean)
|
*/
$config['rewrite_short_tags'] = FALSE;
$config['rewrite_short_tags'] = false;
/*
|--------------------------------------------------------------------------
@ -463,8 +453,7 @@ $config['proxy_ips'] = '';
| will control the number of requests a client can sent to the app.
|
*/
$config['rate_limiting'] = TRUE;
$config['rate_limiting'] = true;
/* End of file config.php */
/* Location: ./application/config/config.php */

View file

@ -36,7 +36,6 @@ const FOPEN_READ_WRITE_CREATE = 'a+b';
const FOPEN_WRITE_CREATE_STRICT = 'xb';
const FOPEN_READ_WRITE_CREATE_STRICT = 'x+b';
/*
|--------------------------------------------------------------------------
| Application Data

View file

@ -47,7 +47,7 @@
*/
$active_group = 'default';
$query_builder = TRUE;
$query_builder = true;
$db['default']['hostname'] = Config::DB_HOST;
$db['default']['username'] = Config::DB_USERNAME;
@ -55,16 +55,15 @@ $db['default']['password'] = Config::DB_PASSWORD;
$db['default']['database'] = Config::DB_NAME;
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = 'ea_';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['pconnect'] = true;
$db['default']['db_debug'] = true;
$db['default']['cache_on'] = false;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8mb4';
$db['default']['dbcollat'] = 'utf8mb4_unicode_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['autoinit'] = true;
$db['default']['stricton'] = false;
/* End of file database.php */
/* Location: ./application/config/database.php */

View file

@ -15,4 +15,3 @@ $config['google_sync_feature'] = Config::GOOGLE_SYNC_FEATURE;
$config['google_client_id'] = Config::GOOGLE_CLIENT_ID;
$config['google_client_secret'] = Config::GOOGLE_CLIENT_SECRET;

View file

@ -9,7 +9,7 @@
| whenever you intend to do a schema migration.
|
*/
$config['migration_enabled'] = TRUE;
$config['migration_enabled'] = true;
/*
|--------------------------------------------------------------------------
@ -23,7 +23,6 @@ $config['migration_enabled'] = TRUE;
*/
$config['migration_version'] = 0;
/*
|--------------------------------------------------------------------------
| Migrations Path
@ -36,6 +35,5 @@ $config['migration_version'] = 0;
*/
$config['migration_path'] = APPPATH . 'migrations/';
/* End of file migration.php */
/* Location: ./application/config/migration.php */

View file

@ -10,10 +10,33 @@ defined('BASEPATH') or exit('No direct script access allowed');
|
*/
return [
'hqx' => ['application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'],
'hqx' => [
'application/mac-binhex40',
'application/mac-binhex',
'application/x-binhex40',
'application/x-mac-binhex40'
],
'cpt' => 'application/mac-compactpro',
'csv' => ['text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'],
'bin' => ['application/macbinary', 'application/mac-binary', 'application/octet-stream', 'application/x-binary', 'application/x-macbinary'],
'csv' => [
'text/x-comma-separated-values',
'text/comma-separated-values',
'application/octet-stream',
'application/vnd.ms-excel',
'application/x-csv',
'text/x-csv',
'text/csv',
'application/csv',
'application/excel',
'application/vnd.msexcel',
'text/plain'
],
'bin' => [
'application/macbinary',
'application/mac-binary',
'application/octet-stream',
'application/x-binary',
'application/x-macbinary'
],
'dms' => 'application/octet-stream',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
@ -31,9 +54,31 @@ return [
'smi' => 'application/smil',
'smil' => 'application/smil',
'mif' => 'application/vnd.mif',
'xls' => ['application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'],
'ppt' => ['application/powerpoint', 'application/vnd.ms-powerpoint', 'application/vnd.ms-office', 'application/msword'],
'pptx' => ['application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/x-zip', 'application/zip'],
'xls' => [
'application/vnd.ms-excel',
'application/msexcel',
'application/x-msexcel',
'application/x-ms-excel',
'application/x-excel',
'application/x-dos_ms_excel',
'application/xls',
'application/x-xls',
'application/excel',
'application/download',
'application/vnd.ms-office',
'application/msword'
],
'ppt' => [
'application/powerpoint',
'application/vnd.ms-powerpoint',
'application/vnd.ms-office',
'application/msword'
],
'pptx' => [
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/x-zip',
'application/zip'
],
'wbxml' => 'application/wbxml',
'wmlc' => 'application/wmlc',
'dcr' => 'application/x-director',
@ -43,7 +88,14 @@ return [
'gtar' => 'application/x-gtar',
'gz' => 'application/x-gzip',
'gzip' => 'application/x-gzip',
'php' => ['application/x-httpd-php', 'application/php', 'application/x-php', 'text/php', 'text/x-php', 'application/x-httpd-php-source'],
'php' => [
'application/x-httpd-php',
'application/php',
'application/x-php',
'text/php',
'text/x-php',
'application/x-httpd-php-source'
],
'php4' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
'phtml' => 'application/x-httpd-php',
@ -56,7 +108,13 @@ return [
'z' => 'application/x-compress',
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => ['application/x-zip', 'application/zip', 'application/x-zip-compressed', 'application/s-compressed', 'multipart/x-zip'],
'zip' => [
'application/x-zip',
'application/zip',
'application/x-zip-compressed',
'application/s-compressed',
'multipart/x-zip'
],
'rar' => ['application/x-rar', 'application/rar', 'application/x-rar-compressed'],
'mid' => 'audio/midi',
'midi' => 'audio/midi',
@ -72,7 +130,19 @@ return [
'ra' => 'audio/x-realaudio',
'rv' => 'video/vnd.rn-realvideo',
'wav' => ['audio/x-wav', 'audio/wave', 'audio/wav'],
'bmp' => ['image/bmp', 'image/x-bmp', 'image/x-bitmap', 'image/x-xbitmap', 'image/x-win-bitmap', 'image/x-windows-bmp', 'image/ms-bmp', 'image/x-ms-bmp', 'application/bmp', 'application/x-bmp', 'application/x-win-bitmap'],
'bmp' => [
'image/bmp',
'image/x-bmp',
'image/x-bitmap',
'image/x-xbitmap',
'image/x-win-bitmap',
'image/x-windows-bmp',
'image/ms-bmp',
'image/x-ms-bmp',
'application/bmp',
'application/x-bmp',
'application/x-win-bitmap'
],
'gif' => 'image/gif',
'jpeg' => ['image/jpeg', 'image/pjpeg'],
'jpg' => ['image/jpeg', 'image/pjpeg'],
@ -107,10 +177,25 @@ return [
'avi' => ['video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'],
'movie' => 'video/x-sgi-movie',
'doc' => ['application/msword', 'application/vnd.ms-office'],
'docx' => ['application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip'],
'docx' => [
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/zip',
'application/msword',
'application/x-zip'
],
'dot' => ['application/msword', 'application/vnd.ms-office'],
'dotx' => ['application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'],
'xlsx' => ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'],
'dotx' => [
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/zip',
'application/msword'
],
'xlsx' => [
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/zip',
'application/vnd.ms-excel',
'application/msword',
'application/x-zip'
],
'word' => ['application/msword', 'application/octet-stream'],
'xl' => 'application/excel',
'eml' => 'message/rfc822',
@ -155,11 +240,36 @@ return [
'ics' => 'text/calendar',
'ical' => 'text/calendar',
'zsh' => 'text/x-scriptzsh',
'7z' => ['application/x-7z-compressed', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'],
'7zip' => ['application/x-7z-compressed', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'],
'cdr' => ['application/cdr', 'application/coreldraw', 'application/x-cdr', 'application/x-coreldraw', 'image/cdr', 'image/x-cdr', 'zz-application/zz-winassoc-cdr'],
'7z' => [
'application/x-7z-compressed',
'application/x-compressed',
'application/x-zip-compressed',
'application/zip',
'multipart/x-zip'
],
'7zip' => [
'application/x-7z-compressed',
'application/x-compressed',
'application/x-zip-compressed',
'application/zip',
'multipart/x-zip'
],
'cdr' => [
'application/cdr',
'application/coreldraw',
'application/x-cdr',
'application/x-coreldraw',
'image/cdr',
'image/x-cdr',
'zz-application/zz-winassoc-cdr'
],
'wma' => ['audio/x-ms-wma', 'video/x-ms-asf'],
'jar' => ['application/java-archive', 'application/x-java-application', 'application/x-jar', 'application/x-compressed'],
'jar' => [
'application/java-archive',
'application/x-java-application',
'application/x-jar',
'application/x-compressed'
],
'svg' => ['image/svg+xml', 'application/xml', 'text/xml'],
'vcf' => 'text/x-vcard',
'srt' => ['text/srt', 'text/plain'],

View file

@ -12,6 +12,5 @@
|
*/
/* End of file profiler.php */
/* Location: ./application/config/profiler.php */

View file

@ -55,7 +55,7 @@ $route['default_controller'] = 'booking';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['translate_uri_dashes'] = false;
/*
| -------------------------------------------------------------------------
@ -86,19 +86,16 @@ header('Access-Control-Allow-Origin: ' . ($_SERVER['HTTP_ORIGIN'] ?? '*')); // N
header('Access-Control-Allow-Credentials: "true"');
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
{
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
// May also be using PUT, PATCH, HEAD etc
header('Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD');
}
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
{
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
header('Access-Control-Allow-Headers: ' . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
}
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'OPTIONS')
{
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
exit(0);
}

View file

@ -13,8 +13,7 @@
$route['default_controller'] = 'test/index';
$route['404_override'] = 'test/index'; // when in doubt, use the hammer
$route['translate_uri_dashes'] = FALSE;
$route['translate_uri_dashes'] = false;
/* End of file routes.php */
/* Location: ./application/config/testing/routes.php */

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class About extends EA_Controller {
class About extends EA_Controller
{
/**
* About constructor.
*/
@ -48,11 +49,9 @@ class About extends EA_Controller {
session(['dest_url' => site_url('about')]);
$user_id = session('user_id');
if (cannot('view', PRIV_USER_SETTINGS))
{
if ($user_id)
{
if (cannot('view', PRIV_USER_SETTINGS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -65,14 +64,14 @@ class About extends EA_Controller {
script_vars([
'user_id' => $user_id,
'role_slug' => $role_slug,
'role_slug' => $role_slug
]);
html_vars([
'page_title' => lang('settings'),
'active_menu' => PRIV_SYSTEM_SETTINGS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug)
]);
$this->load->view('pages/about');

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Account extends EA_Controller {
class Account extends EA_Controller
{
/**
* Account constructor.
*/
@ -49,10 +50,8 @@ class Account extends EA_Controller {
$user_id = session('user_id');
if (cannot('view', PRIV_USER_SETTINGS))
{
if ($user_id)
{
if (cannot('view', PRIV_USER_SETTINGS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -64,14 +63,14 @@ class Account extends EA_Controller {
$account = $this->users_model->find($user_id);
script_vars([
'account' => $account,
'account' => $account
]);
html_vars([
'page_title' => lang('settings'),
'active_menu' => PRIV_SYSTEM_SETTINGS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'grouped_timezones' => $this->timezones->to_grouped_array(),
'grouped_timezones' => $this->timezones->to_grouped_array()
]);
$this->load->view('pages/account');
@ -82,10 +81,8 @@ class Account extends EA_Controller {
*/
public function save()
{
try
{
if (cannot('edit', PRIV_USER_SETTINGS))
{
try {
if (cannot('edit', PRIV_USER_SETTINGS)) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
@ -110,15 +107,9 @@ class Account extends EA_Controller {
'settings'
]);
$this->users_model->only($account['settings'], [
'username',
'password',
'notifications',
'calendar_view'
]);
$this->users_model->only($account['settings'], ['username', 'password', 'notifications', 'calendar_view']);
if (empty($account['password']))
{
if (empty($account['password'])) {
unset($account['password']);
}
@ -128,13 +119,11 @@ class Account extends EA_Controller {
'user_email' => $account['email'],
'username' => $account['settings']['username'],
'timezone' => $account['timezone'],
'language' => $account['language'],
'language' => $account['language']
]);
response();
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -144,8 +133,7 @@ class Account extends EA_Controller {
*/
public function validate_username()
{
try
{
try {
$username = request('username');
$user_id = request('user_id');
@ -153,11 +141,9 @@ class Account extends EA_Controller {
$is_valid = $this->users_model->validate_username($username, $user_id);
json_response([
'is_valid' => $is_valid,
'is_valid' => $is_valid
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Admins extends EA_Controller {
class Admins extends EA_Controller
{
/**
* Admins constructor.
*/
@ -46,10 +47,8 @@ class Admins extends EA_Controller {
$user_id = session('user_id');
if (cannot('view', PRIV_USERS))
{
if ($user_id)
{
if (cannot('view', PRIV_USERS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -64,15 +63,15 @@ class Admins extends EA_Controller {
'user_id' => $user_id,
'role_slug' => $role_slug,
'timezones' => $this->timezones->to_array(),
'min_password_length' => MIN_PASSWORD_LENGTH,
'min_password_length' => MIN_PASSWORD_LENGTH
]);
html_vars([
'page_title' => lang('admins'),
'active_menu' => PRIV_USERS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'grouped_timezones' => $this->timezones->to_grouped_array(),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug)
]);
$this->load->view('pages/admins');
@ -83,11 +82,9 @@ class Admins extends EA_Controller {
*/
public function search()
{
try
{
if (cannot('view', PRIV_USERS))
{
abort(403,'Forbidden');
try {
if (cannot('view', PRIV_USERS)) {
abort(403, 'Forbidden');
}
$keyword = request('keyword', '');
@ -101,9 +98,7 @@ class Admins extends EA_Controller {
$admins = $this->admins_model->search($keyword, $limit, $offset, $order_by);
json_response($admins);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -113,13 +108,11 @@ class Admins extends EA_Controller {
*/
public function store()
{
try
{
if (cannot('add', PRIV_USERS))
{
try {
if (cannot('add', PRIV_USERS)) {
abort(403, 'Forbidden');
}
$admin = request('admin');
$this->admins_model->only($admin, [
@ -138,26 +131,39 @@ class Admins extends EA_Controller {
'settings'
]);
$this->admins_model->only($admin['settings'], [
'username',
'password',
'notifications',
'calendar_view'
]);
$this->admins_model->only($admin['settings'], ['username', 'password', 'notifications', 'calendar_view']);
$admin_id = $this->admins_model->save($admin);
$admin = $this->admins_model->find($admin_id);
$this->webhooks_client->trigger(WEBHOOK_ADMIN_SAVE, $admin);
$admin = $this->admins_model->find($admin_id);
$this->webhooks_client->trigger(WEBHOOK_ADMIN_SAVE, $admin);
json_response([
'success' => TRUE,
'success' => true,
'id' => $admin_id
]);
} catch (Throwable $e) {
json_exception($e);
}
catch (Throwable $e)
{
}
/**
* Find an admin.
*/
public function find()
{
try {
if (cannot('view', PRIV_USERS)) {
abort(403, 'Forbidden');
}
$admin_id = request('admin_id');
$admin = $this->admins_model->find($admin_id);
json_response($admin);
} catch (Throwable $e) {
json_exception($e);
}
}
@ -167,10 +173,8 @@ class Admins extends EA_Controller {
*/
public function update()
{
try
{
if (cannot('edit', PRIV_USERS))
{
try {
if (cannot('edit', PRIV_USERS)) {
abort(403, 'Forbidden');
}
@ -193,12 +197,7 @@ class Admins extends EA_Controller {
'settings'
]);
$this->admins_model->only($admin['settings'], [
'username',
'password',
'notifications',
'calendar_view'
]);
$this->admins_model->only($admin['settings'], ['username', 'password', 'notifications', 'calendar_view']);
$admin_id = $this->admins_model->save($admin);
@ -207,12 +206,10 @@ class Admins extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_ADMIN_SAVE, $admin);
json_response([
'success' => TRUE,
'success' => true,
'id' => $admin_id
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -222,10 +219,8 @@ class Admins extends EA_Controller {
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_USERS))
{
try {
if (cannot('delete', PRIV_USERS)) {
abort(403, 'Forbidden');
}
@ -238,35 +233,9 @@ class Admins extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_ADMIN_DELETE, $admin);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Find an admin.
*/
public function find()
{
try
{
if (cannot('view', PRIV_USERS))
{
abort(403, 'Forbidden');
}
$admin_id = request('admin_id');
$admin = $this->admins_model->find($admin_id);
json_response($admin);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Api_settings extends EA_Controller {
class Api_settings extends EA_Controller
{
/**
* Api_settings constructor.
*/
@ -40,10 +41,8 @@ class Api_settings extends EA_Controller {
$user_id = session('user_id');
if (cannot('view', PRIV_SYSTEM_SETTINGS))
{
if ($user_id)
{
if (cannot('view', PRIV_SYSTEM_SETTINGS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -57,13 +56,13 @@ class Api_settings extends EA_Controller {
script_vars([
'user_id' => $user_id,
'role_slug' => $role_slug,
'api_settings' => $this->settings_model->get('name like "api_%"'),
'api_settings' => $this->settings_model->get('name like "api_%"')
]);
html_vars([
'page_title' => lang('api'),
'active_menu' => PRIV_SYSTEM_SETTINGS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'user_display_name' => $this->accounts->get_user_display_name($user_id)
]);
$this->load->view('pages/api_settings');
@ -74,21 +73,21 @@ class Api_settings extends EA_Controller {
*/
public function save()
{
try
{
if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{
try {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
$settings = request('api_settings', []);
foreach ($settings as $setting)
{
$existing_setting = $this->settings_model->query()->where('name', $setting['name'])->get()->row_array();
foreach ($settings as $setting) {
$existing_setting = $this->settings_model
->query()
->where('name', $setting['name'])
->get()
->row_array();
if ( ! empty($existing_setting))
{
if (!empty($existing_setting)) {
$setting['id'] = $existing_setting['id'];
}
@ -96,9 +95,7 @@ class Api_settings extends EA_Controller {
}
response();
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -21,7 +21,8 @@
*
* @package Controllers
*/
class Appointments extends EA_Controller {
class Appointments extends EA_Controller
{
/**
* Appointments constructor.
*/
@ -54,10 +55,8 @@ class Appointments extends EA_Controller {
*/
public function search()
{
try
{
if (cannot('view', PRIV_APPOINTMENTS))
{
try {
if (cannot('view', PRIV_APPOINTMENTS)) {
abort(403, 'Forbidden');
}
@ -72,9 +71,7 @@ class Appointments extends EA_Controller {
$appointments = $this->appointments_model->search($keyword, $limit, $offset, $order_by);
json_response($appointments);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -84,25 +81,23 @@ class Appointments extends EA_Controller {
*/
public function store()
{
try
{
if (cannot('add', PRIV_APPOINTMENTS))
{
try {
if (cannot('add', PRIV_APPOINTMENTS)) {
abort(403, 'Forbidden');
}
$appointment = json_decode(request('appointment'), TRUE);
$appointment = json_decode(request('appointment'), true);
$this->appointments_model->only($appointment, [
'start_datetime',
'end_datetime',
'location',
'notes',
'color',
'is_unavailability',
'id_users_provider',
'id_users_customer',
'id_services',
'start_datetime',
'end_datetime',
'location',
'notes',
'color',
'is_unavailability',
'id_users_provider',
'id_users_customer',
'id_services'
]);
$appointment_id = $this->appointments_model->save($appointment);
@ -112,12 +107,30 @@ class Appointments extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_APPOINTMENT_SAVE, $appointment);
json_response([
'success' => TRUE,
'success' => true,
'id' => $appointment_id
]);
} catch (Throwable $e) {
json_exception($e);
}
catch (Throwable $e)
{
}
/**
* Find an appointment.
*/
public function find()
{
try {
if (cannot('view', PRIV_APPOINTMENTS)) {
abort(403, 'Forbidden');
}
$appointment_id = request('appointment_id');
$appointment = $this->appointments_model->find($appointment_id);
json_response($appointment);
} catch (Throwable $e) {
json_exception($e);
}
}
@ -127,14 +140,12 @@ class Appointments extends EA_Controller {
*/
public function update()
{
try
{
if (cannot('edit', PRIV_APPOINTMENTS))
{
try {
if (cannot('edit', PRIV_APPOINTMENTS)) {
abort(403, 'Forbidden');
}
$appointment = json_decode(request('appointment'), TRUE);
$appointment = json_decode(request('appointment'), true);
$this->appointments_model->only($appointment, [
'id',
@ -146,18 +157,16 @@ class Appointments extends EA_Controller {
'is_unavailability',
'id_users_provider',
'id_users_customer',
'id_services',
'id_services'
]);
$appointment_id = $this->appointments_model->save($appointment);
json_response([
'success' => TRUE,
'success' => true,
'id' => $appointment_id
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -167,40 +176,8 @@ class Appointments extends EA_Controller {
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_APPOINTMENTS))
{
abort(403, 'Forbidden');
}
$appointment_id = request('appointment_id');
$appointment = $this->appointments_model->find($appointment_id);
$this->appointments_model->delete($appointment_id);
$this->webhooks_client->trigger(WEBHOOK_APPOINTMENT_DELETE, $appointment);
json_response([
'success' => TRUE,
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Find an appointment.
*/
public function find()
{
try
{
if (cannot('view', PRIV_APPOINTMENTS))
{
try {
if (cannot('delete', PRIV_APPOINTMENTS)) {
abort(403, 'Forbidden');
}
@ -208,10 +185,14 @@ class Appointments extends EA_Controller {
$appointment = $this->appointments_model->find($appointment_id);
json_response($appointment);
}
catch (Throwable $e)
{
$this->appointments_model->delete($appointment_id);
$this->webhooks_client->trigger(WEBHOOK_APPOINTMENT_DELETE, $appointment);
json_response([
'success' => true
]);
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -36,10 +36,11 @@
* Handles the backend related operations.
*
* @package Controllers
*
*
* @deprecated Since 1.5
*/
class Backend extends EA_Controller {
class Backend extends EA_Controller
{
/**
* Display the calendar page.
*
@ -47,12 +48,9 @@ class Backend extends EA_Controller {
*/
public function index(string $appointment_hash = '')
{
if (empty($appointment_hash))
{
if (empty($appointment_hash)) {
redirect('calendar');
}
else
{
} else {
redirect('calendar/reschedule/' . $appointment_hash);
}
}

View file

@ -36,10 +36,11 @@
* Handles the backend API related operations.
*
* @package Controllers
*
*
* @deprecated Since 1.5
*/
class Backend_api extends EA_Controller {
class Backend_api extends EA_Controller
{
/**
* Get Calendar Events
*/

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Blocked_periods extends EA_Controller {
class Blocked_periods extends EA_Controller
{
/**
* Blocked_periods constructor.
*/
@ -46,10 +47,8 @@ class Blocked_periods extends EA_Controller {
$user_id = session('user_id');
if (cannot('view', PRIV_BLOCKED_PERIODS))
{
if ($user_id)
{
if (cannot('view', PRIV_BLOCKED_PERIODS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -65,7 +64,7 @@ class Blocked_periods extends EA_Controller {
'role_slug' => $role_slug,
'date_format' => setting('date_format'),
'time_format' => setting('time_format'),
'first_weekday' => setting('first_weekday'),
'first_weekday' => setting('first_weekday')
]);
html_vars([
@ -73,7 +72,7 @@ class Blocked_periods extends EA_Controller {
'active_menu' => PRIV_BLOCKED_PERIODS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'timezones' => $this->timezones->to_array(),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug)
]);
$this->load->view('pages/blocked_periods');
@ -84,10 +83,8 @@ class Blocked_periods extends EA_Controller {
*/
public function search()
{
try
{
if (cannot('view', PRIV_BLOCKED_PERIODS))
{
try {
if (cannot('view', PRIV_BLOCKED_PERIODS)) {
abort(403, 'Forbidden');
}
@ -102,9 +99,7 @@ class Blocked_periods extends EA_Controller {
$blocked_periods = $this->blocked_periods_model->search($keyword, $limit, $offset, $order_by);
json_response($blocked_periods);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -114,21 +109,14 @@ class Blocked_periods extends EA_Controller {
*/
public function store()
{
try
{
if (cannot('add', PRIV_BLOCKED_PERIODS))
{
try {
if (cannot('add', PRIV_BLOCKED_PERIODS)) {
abort(403, 'Forbidden');
}
$blocked_period = request('blocked_period');
$this->blocked_periods_model->only($blocked_period, [
'name',
'start_datetime',
'end_datetime',
'notes'
]);
$this->blocked_periods_model->only($blocked_period, ['name', 'start_datetime', 'end_datetime', 'notes']);
$blocked_period_id = $this->blocked_periods_model->save($blocked_period);
@ -137,12 +125,30 @@ class Blocked_periods extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_BLOCKED_PERIOD_SAVE, $blocked_period);
json_response([
'success' => TRUE,
'success' => true,
'id' => $blocked_period_id
]);
} catch (Throwable $e) {
json_exception($e);
}
catch (Throwable $e)
{
}
/**
* Find a service-category.
*/
public function find()
{
try {
if (cannot('view', PRIV_BLOCKED_PERIODS)) {
abort(403, 'Forbidden');
}
$blocked_period_id = request('blocked_period_id');
$blocked_period = $this->blocked_periods_model->find($blocked_period_id);
json_response($blocked_period);
} catch (Throwable $e) {
json_exception($e);
}
}
@ -152,10 +158,8 @@ class Blocked_periods extends EA_Controller {
*/
public function update()
{
try
{
if (cannot('edit', PRIV_BLOCKED_PERIODS))
{
try {
if (cannot('edit', PRIV_BLOCKED_PERIODS)) {
abort(403, 'Forbidden');
}
@ -176,12 +180,10 @@ class Blocked_periods extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_BLOCKED_PERIOD_SAVE, $blocked_period);
json_response([
'success' => TRUE,
'success' => true,
'id' => $blocked_period_id
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -191,10 +193,8 @@ class Blocked_periods extends EA_Controller {
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_BLOCKED_PERIODS))
{
try {
if (cannot('delete', PRIV_BLOCKED_PERIODS)) {
abort(403, 'Forbidden');
}
@ -207,35 +207,9 @@ class Blocked_periods extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_BLOCKED_PERIOD_DELETE, $blocked_period);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Find a service-category.
*/
public function find()
{
try
{
if (cannot('view', PRIV_BLOCKED_PERIODS))
{
abort(403, 'Forbidden');
}
$blocked_period_id = request('blocked_period_id');
$blocked_period = $this->blocked_periods_model->find($blocked_period_id);
json_response($blocked_period);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -21,7 +21,8 @@
*
* @package Controllers
*/
class Booking extends EA_Controller {
class Booking extends EA_Controller
{
/**
* Booking constructor.
*/
@ -46,6 +47,20 @@ class Booking extends EA_Controller {
$this->load->library('webhooks_client');
}
/**
* Render the booking page and display the selected appointment.
*
* This method will call the "index" callback to handle the page rendering.
*
* @param string $appointment_hash
*/
public function reschedule(string $appointment_hash)
{
html_vars(['appointment_hash' => $appointment_hash]);
$this->index();
}
/**
* Render the booking page.
*
@ -53,8 +68,7 @@ class Booking extends EA_Controller {
*/
public function index()
{
if ( ! is_app_installed())
{
if (!is_app_installed()) {
redirect('installation');
return;
@ -67,12 +81,11 @@ class Booking extends EA_Controller {
$google_analytics_code = setting('google_analytics_code');
$matomo_analytics_url = setting('matomo_analytics_url');
if ($disable_booking)
{
if ($disable_booking) {
$disable_booking_message = setting('disable_booking_message');
html_vars([
'show_message' => TRUE,
'show_message' => true,
'page_title' => lang('page_title') . ' ' . $company_name,
'message_title' => lang('booking_is_disabled'),
'message_text' => $disable_booking_message,
@ -86,11 +99,10 @@ class Booking extends EA_Controller {
return;
}
$available_services = $this->services_model->get_available_services(TRUE);
$available_providers = $this->providers_model->get_available_providers(TRUE);
$available_services = $this->services_model->get_available_services(true);
$available_providers = $this->providers_model->get_available_providers(true);
foreach ($available_providers as &$available_provider)
{
foreach ($available_providers as &$available_provider) {
// Only expose the required provider data.
$this->providers_model->only($available_provider, [
@ -133,8 +145,7 @@ class Booking extends EA_Controller {
$book_advance_timeout = setting('book_advance_timeout');
$theme = request('theme', setting('theme', 'default'));
if (empty($theme) || ! file_exists(__DIR__ . '/../../assets/css/themes/' . $theme . '.min.css'))
{
if (empty($theme) || !file_exists(__DIR__ . '/../../assets/css/themes/' . $theme . '.min.css')) {
$theme = 'default';
}
@ -143,18 +154,16 @@ class Booking extends EA_Controller {
$appointment_hash = html_vars('appointment_hash');
if ( ! empty($appointment_hash))
{
if (!empty($appointment_hash)) {
// Load the appointments data and enable the manage mode of the booking page.
$manage_mode = TRUE;
$manage_mode = true;
$results = $this->appointments_model->get(['hash' => $appointment_hash]);
if (empty($results))
{
if (empty($results)) {
html_vars([
'show_message' => TRUE,
'show_message' => true,
'page_title' => lang('page_title') . ' ' . $company_name,
'message_title' => lang('appointment_not_found'),
'message_text' => lang('appointment_does_not_exist_in_db'),
@ -174,14 +183,13 @@ class Booking extends EA_Controller {
$limit = strtotime('+' . $book_advance_timeout . ' minutes', strtotime('now'));
if ($start_datetime < $limit)
{
if ($start_datetime < $limit) {
$hours = floor($book_advance_timeout / 60);
$minutes = ($book_advance_timeout % 60);
$minutes = $book_advance_timeout % 60;
html_vars([
'show_message' => TRUE,
'show_message' => true,
'page_title' => lang('page_title') . ' ' . $company_name,
'message_title' => lang('appointment_locked'),
'message_text' => strtr(lang('appointment_locked_message'), [
@ -200,18 +208,16 @@ class Booking extends EA_Controller {
$appointment = $results[0];
$provider = $this->providers_model->find($appointment['id_users_provider']);
$customer = $this->customers_model->find($appointment['id_users_customer']);
$customer_token = md5(uniqid(mt_rand(), TRUE));
$customer_token = md5(uniqid(mt_rand(), true));
// Cache the token for 10 minutes.
$this->cache->save('customer-token-' . $customer_token, $customer['id'], 600);
}
else
{
$manage_mode = FALSE;
$customer_token = FALSE;
$appointment = NULL;
$provider = NULL;
$customer = NULL;
} else {
$manage_mode = false;
$customer_token = false;
$appointment = null;
$provider = null;
$customer = null;
}
script_vars([
@ -226,7 +232,7 @@ class Booking extends EA_Controller {
'future_booking_limit' => setting('future_booking_limit'),
'appointment_data' => $appointment,
'provider_data' => $provider,
'customer_data' => $customer,
'customer_data' => $customer
]);
html_vars([
@ -272,187 +278,48 @@ class Booking extends EA_Controller {
'customer_token' => $customer_token,
'appointment_data' => $appointment,
'provider_data' => $provider,
'customer_data' => $customer,
'customer_data' => $customer
]);
$this->load->view('pages/booking');
}
/**
* Render the booking page and display the selected appointment.
*
* This method will call the "index" callback to handle the page rendering.
*
* @param string $appointment_hash
*/
public function reschedule(string $appointment_hash)
{
html_vars(['appointment_hash' => $appointment_hash]);
$this->index();
}
/**
* Get the available appointment hours for the selected date.
*
* This method answers to an AJAX request. It calculates the available hours for the given service, provider and
* date.
*/
public function get_available_hours()
{
try
{
$provider_id = request('provider_id');
$service_id = request('service_id');
$selected_date = request('selected_date');
// Do not continue if there was no provider selected (more likely there is no provider in the system).
if (empty($provider_id))
{
json_response();
return;
}
// If manage mode is TRUE then the following we should not consider the selected appointment when
// calculating the available time periods of the provider.
$exclude_appointment_id = request('manage_mode') ? request('appointment_id') : NULL;
// If the user has selected the "any-provider" option then we will need to search for an available provider
// that will provide the requested service.
$service = $this->services_model->find($service_id);
if ($provider_id === ANY_PROVIDER)
{
$providers = $this->providers_model->get();
$available_hours = [];
foreach ($providers as $provider)
{
if ( ! in_array($service_id, $provider['services']))
{
continue;
}
$provider_available_hours = $this->availability->get_available_hours($selected_date, $service, $provider, $exclude_appointment_id);
$available_hours = array_merge($available_hours, $provider_available_hours);
}
$available_hours = array_unique(array_values($available_hours));
sort($available_hours);
$response = $available_hours;
}
else
{
$provider = $this->providers_model->find($provider_id);
$response = $this->availability->get_available_hours($selected_date, $service, $provider, $exclude_appointment_id);
}
json_response($response);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Search for any provider that can handle the requested service.
*
* This method will return the database ID of the provider with the most available periods.
*
* @param int $service_id Service ID
* @param string $date Selected date (Y-m-d).
* @param string|null $hour Selected hour (H:i).
*
* @return int|null Returns the ID of the provider that can provide the service at the selected date.
*
* @throws Exception
*/
protected function search_any_provider(int $service_id, string $date, string $hour = NULL): ?int
{
$available_providers = $this->providers_model->get_available_providers(TRUE);
$service = $this->services_model->find($service_id);
$provider_id = NULL;
$max_hours_count = 0;
foreach ($available_providers as $provider)
{
foreach ($provider['services'] as $provider_service_id)
{
if ($provider_service_id == $service_id)
{
// Check if the provider is available for the requested date.
$available_hours = $this->availability->get_available_hours($date, $service, $provider);
if (count($available_hours) > $max_hours_count && (empty($hour) || in_array($hour, $available_hours)))
{
$provider_id = $provider['id'];
$max_hours_count = count($available_hours);
}
}
}
}
return $provider_id;
}
/**
* Register the appointment to the database.
*/
public function register()
{
try
{
try {
$post_data = request('post_data');
$captcha = request('captcha');
$appointment = $post_data['appointment'];
$customer = $post_data['customer'];
$manage_mode = filter_var($post_data['manage_mode'], FILTER_VALIDATE_BOOLEAN);
if ( ! array_key_exists('address', $customer))
{
if (!array_key_exists('address', $customer)) {
$customer['address'] = '';
}
if ( ! array_key_exists('city', $customer))
{
if (!array_key_exists('city', $customer)) {
$customer['city'] = '';
}
if ( ! array_key_exists('zip_code', $customer))
{
if (!array_key_exists('zip_code', $customer)) {
$customer['zip_code'] = '';
}
if ( ! array_key_exists('notes', $customer))
{
if (!array_key_exists('notes', $customer)) {
$customer['notes'] = '';
}
if ( ! array_key_exists('phone_number', $customer))
{
if (!array_key_exists('phone_number', $customer)) {
$customer['address'] = '';
}
// Check appointment availability before registering it to the database.
$appointment['id_users_provider'] = $this->check_datetime_availability();
if ( ! $appointment['id_users_provider'])
{
if (!$appointment['id_users_provider']) {
throw new RuntimeException(lang('requested_hour_is_unavailable'));
}
@ -460,23 +327,21 @@ class Booking extends EA_Controller {
$service = $this->services_model->find($appointment['id_services']);
$require_captcha = (bool)setting('require_captcha');
$require_captcha = (bool) setting('require_captcha');
$captcha_phrase = session('captcha_phrase');
// Validate the CAPTCHA string.
if ($require_captcha && strtoupper($captcha_phrase) !== strtoupper($captcha))
{
if ($require_captcha && strtoupper($captcha_phrase) !== strtoupper($captcha)) {
json_response([
'captcha_verification' => FALSE
'captcha_verification' => false
]);
return;
}
if ($this->customers_model->exists($customer))
{
if ($this->customers_model->exists($customer)) {
$customer['id'] = $this->customers_model->find_record_id($customer);
$existing_appointments = $this->appointments_model->get([
@ -485,19 +350,16 @@ class Booking extends EA_Controller {
'end_datetime >=' => $appointment['end_datetime']
]);
if (count($existing_appointments))
{
if (count($existing_appointments)) {
throw new RuntimeException(lang('customer_is_already_booked'));
}
}
if (empty($appointment['location']) && ! empty($service['location']))
{
if (empty($appointment['location']) && !empty($service['location'])) {
$appointment['location'] = $service['location'];
}
if (empty($appointment['color']) && ! empty($service['color']))
{
if (empty($appointment['color']) && !empty($service['color'])) {
$appointment['color'] = $service['color'];
}
@ -508,18 +370,16 @@ class Booking extends EA_Controller {
'first_name' => $customer['first_name'] ?? '-',
'last_name' => $customer['last_name'] ?? '-',
'email' => $customer['email'] ?? '-',
'ip' => $customer_ip,
'ip' => $customer_ip
];
if (setting('display_terms_and_conditions'))
{
if (setting('display_terms_and_conditions')) {
$consent['type'] = 'terms-and-conditions';
$this->consents_model->save($consent);
}
if (setting('display_privacy_policy'))
{
if (setting('display_privacy_policy')) {
$consent['type'] = 'privacy-policy';
$this->consents_model->save($consent);
@ -539,19 +399,19 @@ class Booking extends EA_Controller {
'state',
'zip_code',
'timezone',
'language',
'language'
]);
$customer_id = $this->customers_model->save($customer);
$customer = $this->customers_model->find($customer_id);
$appointment['id_users_customer'] = $customer_id;
$appointment['is_unavailability'] = FALSE;
$appointment['is_unavailability'] = false;
$appointment['color'] = $service['color'];
$appointment_status_options_json = setting('appointment_status_options', '[]');
$appointment_status_options = json_decode($appointment_status_options_json, TRUE) ?? [];
$appointment['status'] = $appointment_status_options[0] ?? NULL;
$appointment_status_options = json_decode($appointment_status_options_json, true) ?? [];
$appointment['status'] = $appointment_status_options[0] ?? null;
$this->appointments_model->only($appointment, [
'id',
@ -564,7 +424,7 @@ class Booking extends EA_Controller {
'is_unavailability',
'id_users_provider',
'id_users_customer',
'id_services',
'id_services'
]);
$appointment_id = $this->appointments_model->save($appointment);
@ -580,7 +440,14 @@ class Booking extends EA_Controller {
$this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings);
$this->notifications->notify_appointment_saved($appointment, $service, $provider, $customer, $settings, $manage_mode);
$this->notifications->notify_appointment_saved(
$appointment,
$service,
$provider,
$customer,
$settings,
$manage_mode
);
$this->webhooks_client->trigger(WEBHOOK_APPOINTMENT_SAVE, $appointment);
@ -590,9 +457,7 @@ class Booking extends EA_Controller {
];
json_response($response);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -623,8 +488,7 @@ class Booking extends EA_Controller {
$hour = $appointment_start->format('H:i');
if ($appointment['id_users_provider'] === ANY_PROVIDER)
{
if ($appointment['id_users_provider'] === ANY_PROVIDER) {
$appointment['id_users_provider'] = $this->search_any_provider($appointment['id_services'], $date, $hour);
return $appointment['id_users_provider'];
@ -632,26 +496,146 @@ class Booking extends EA_Controller {
$service = $this->services_model->find($appointment['id_services']);
$exclude_appointment_id = $appointment['id'] ?? NULL;
$exclude_appointment_id = $appointment['id'] ?? null;
$provider = $this->providers_model->find($appointment['id_users_provider']);
$available_hours = $this->availability->get_available_hours($date, $service, $provider, $exclude_appointment_id);
$available_hours = $this->availability->get_available_hours(
$date,
$service,
$provider,
$exclude_appointment_id
);
$is_still_available = FALSE;
$is_still_available = false;
$appointment_hour = date('H:i', strtotime($appointment['start_datetime']));
foreach ($available_hours as $available_hour)
{
if ($appointment_hour === $available_hour)
{
$is_still_available = TRUE;
foreach ($available_hours as $available_hour) {
if ($appointment_hour === $available_hour) {
$is_still_available = true;
break;
}
}
return $is_still_available ? $appointment['id_users_provider'] : NULL;
return $is_still_available ? $appointment['id_users_provider'] : null;
}
/**
* Search for any provider that can handle the requested service.
*
* This method will return the database ID of the provider with the most available periods.
*
* @param int $service_id Service ID
* @param string $date Selected date (Y-m-d).
* @param string|null $hour Selected hour (H:i).
*
* @return int|null Returns the ID of the provider that can provide the service at the selected date.
*
* @throws Exception
*/
protected function search_any_provider(int $service_id, string $date, string $hour = null): ?int
{
$available_providers = $this->providers_model->get_available_providers(true);
$service = $this->services_model->find($service_id);
$provider_id = null;
$max_hours_count = 0;
foreach ($available_providers as $provider) {
foreach ($provider['services'] as $provider_service_id) {
if ($provider_service_id == $service_id) {
// Check if the provider is available for the requested date.
$available_hours = $this->availability->get_available_hours($date, $service, $provider);
if (
count($available_hours) > $max_hours_count &&
(empty($hour) || in_array($hour, $available_hours))
) {
$provider_id = $provider['id'];
$max_hours_count = count($available_hours);
}
}
}
}
return $provider_id;
}
/**
* Get the available appointment hours for the selected date.
*
* This method answers to an AJAX request. It calculates the available hours for the given service, provider and
* date.
*/
public function get_available_hours()
{
try {
$provider_id = request('provider_id');
$service_id = request('service_id');
$selected_date = request('selected_date');
// Do not continue if there was no provider selected (more likely there is no provider in the system).
if (empty($provider_id)) {
json_response();
return;
}
// If manage mode is TRUE then the following we should not consider the selected appointment when
// calculating the available time periods of the provider.
$exclude_appointment_id = request('manage_mode') ? request('appointment_id') : null;
// If the user has selected the "any-provider" option then we will need to search for an available provider
// that will provide the requested service.
$service = $this->services_model->find($service_id);
if ($provider_id === ANY_PROVIDER) {
$providers = $this->providers_model->get();
$available_hours = [];
foreach ($providers as $provider) {
if (!in_array($service_id, $provider['services'])) {
continue;
}
$provider_available_hours = $this->availability->get_available_hours(
$selected_date,
$service,
$provider,
$exclude_appointment_id
);
$available_hours = array_merge($available_hours, $provider_available_hours);
}
$available_hours = array_unique(array_values($available_hours));
sort($available_hours);
$response = $available_hours;
} else {
$provider = $this->providers_model->find($provider_id);
$response = $this->availability->get_available_hours(
$selected_date,
$service,
$provider,
$exclude_appointment_id
);
}
json_response($response);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
@ -665,40 +649,35 @@ class Booking extends EA_Controller {
*/
public function get_unavailable_dates()
{
try
{
try {
$provider_id = request('provider_id');
$service_id = request('service_id');
$appointment_id = request('appointment_id');
$manage_mode = filter_var(request('manage_mode'), FILTER_VALIDATE_BOOLEAN);
$selected_date_string = request('selected_date');
$selected_date = new DateTime($selected_date_string);
$number_of_days_in_month = (int)$selected_date->format('t');
$number_of_days_in_month = (int) $selected_date->format('t');
$unavailable_dates = [];
$provider_ids = $provider_id === ANY_PROVIDER
? $this->search_providers_by_service($service_id)
: [$provider_id];
$provider_ids =
$provider_id === ANY_PROVIDER ? $this->search_providers_by_service($service_id) : [$provider_id];
$exclude_appointment_id = $manage_mode ? $appointment_id : NULL;
$exclude_appointment_id = $manage_mode ? $appointment_id : null;
// Get the service record.
$service = $this->services_model->find($service_id);
for ($i = 1; $i <= $number_of_days_in_month; $i++)
{
for ($i = 1; $i <= $number_of_days_in_month; $i++) {
$current_date = new DateTime($selected_date->format('Y-m') . '-' . $i);
if ($current_date < new DateTime(date('Y-m-d 00:00:00')))
{
if ($current_date < new DateTime(date('Y-m-d 00:00:00'))) {
// Past dates become immediately unavailability.
$unavailable_dates[] = $current_date->format('Y-m-d');
continue;
}
// Finding at least one slot of availability.
foreach ($provider_ids as $current_provider_id)
{
foreach ($provider_ids as $current_provider_id) {
$provider = $this->providers_model->find($current_provider_id);
$available_hours = $this->availability->get_available_hours(
@ -708,32 +687,27 @@ class Booking extends EA_Controller {
$exclude_appointment_id
);
if ( ! empty($available_hours))
{
if (!empty($available_hours)) {
break;
}
}
// No availability amongst all the provider.
if (empty($available_hours))
{
if (empty($available_hours)) {
$unavailable_dates[] = $current_date->format('Y-m-d');
}
}
if (count($unavailable_dates) === $number_of_days_in_month)
{
if (count($unavailable_dates) === $number_of_days_in_month) {
json_response([
'is_month_unavailable' => TRUE,
'is_month_unavailable' => true
]);
return;
}
json_response($unavailable_dates);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -749,15 +723,12 @@ class Booking extends EA_Controller {
*/
protected function search_providers_by_service(int $service_id): array
{
$available_providers = $this->providers_model->get_available_providers(TRUE);
$available_providers = $this->providers_model->get_available_providers(true);
$provider_list = [];
foreach ($available_providers as $provider)
{
foreach ($provider['services'] as $provider_service_id)
{
if ($provider_service_id === $service_id)
{
foreach ($available_providers as $provider) {
foreach ($provider['services'] as $provider_service_id) {
if ($provider_service_id === $service_id) {
// Check if the provider is affected to the selected service.
$provider_list[] = $provider['id'];
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Booking_cancellation extends EA_Controller {
class Booking_cancellation extends EA_Controller
{
/**
* Booking_cancellation constructor.
*/
@ -47,19 +48,16 @@ class Booking_cancellation extends EA_Controller {
*/
public function of(string $appointment_hash)
{
try
{
try {
$cancellation_reason = request('cancellation_reason');
if ($this->input->method() !== 'post' || empty($cancellation_reason))
{
if ($this->input->method() !== 'post' || empty($cancellation_reason)) {
abort(403, 'Forbidden');
}
$occurrences = $this->appointments_model->get(['hash' => $appointment_hash]);
if (empty($occurrences))
{
if (empty($occurrences)) {
html_vars([
'page_title' => lang('appointment_not_found'),
'company_color' => setting('company_color'),
@ -67,7 +65,7 @@ class Booking_cancellation extends EA_Controller {
'message_text' => lang('appointment_does_not_exist_in_db'),
'message_icon' => base_url('assets/img/error.png'),
'google_analytics_code' => setting('google_analytics_code'),
'matomo_analytics_url' => setting('matomo_analytics_url'),
'matomo_analytics_url' => setting('matomo_analytics_url')
]);
$this->load->view('pages/booking_message');
@ -95,13 +93,17 @@ class Booking_cancellation extends EA_Controller {
$this->synchronization->sync_appointment_deleted($appointment, $provider);
$this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings, $cancellation_reason);
$this->notifications->notify_appointment_deleted(
$appointment,
$service,
$provider,
$customer,
$settings,
$cancellation_reason
);
$this->webhooks_client->trigger(WEBHOOK_APPOINTMENT_DELETE, $appointment);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
log_message('error', 'Booking Cancellation Exception: ' . $e->getMessage());
}
@ -109,7 +111,7 @@ class Booking_cancellation extends EA_Controller {
'page_title' => lang('appointment_cancelled_title'),
'company_color' => setting('company_color'),
'google_analytics_code' => setting('google_analytics_code'),
'matomo_analytics_url' => setting('matomo_analytics_url'),
'matomo_analytics_url' => setting('matomo_analytics_url')
]);
$this->load->view('pages/booking_cancellation');

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Booking_confirmation extends EA_Controller {
class Booking_confirmation extends EA_Controller
{
/**
* Booking_confirmation constructor.
*/
@ -30,13 +31,13 @@ class Booking_confirmation extends EA_Controller {
$this->load->model('providers_model');
$this->load->model('services_model');
$this->load->model('customers_model');
$this->load->library('google_sync');
}
/**
* Display the appointment registration success page.
*
*
* @throws Exception
*/
public function of()
@ -45,8 +46,7 @@ class Booking_confirmation extends EA_Controller {
$occurrences = $this->appointments_model->get(['hash' => $appointment_hash]);
if (empty($occurrences))
{
if (empty($occurrences)) {
redirect('appointments'); // The appointment does not exist.
return;
@ -54,14 +54,14 @@ class Booking_confirmation extends EA_Controller {
$appointment = $occurrences[0];
$add_to_google_url = $this->google_sync->get_add_to_google_url($appointment['id']);
$add_to_google_url = $this->google_sync->get_add_to_google_url($appointment['id']);
html_vars([
'page_title' => lang('success'),
'company_color' => setting('company_color'),
'google_analytics_code' => setting('google_analytics_code'),
'matomo_analytics_url' => setting('matomo_analytics_url'),
'add_to_google_url' => $add_to_google_url,
'add_to_google_url' => $add_to_google_url
]);
$this->load->view('pages/booking_confirmation');

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Booking_settings extends EA_Controller {
class Booking_settings extends EA_Controller
{
/**
* Booking_settings constructor.
*/
@ -48,11 +49,9 @@ class Booking_settings extends EA_Controller {
session(['dest_url' => site_url('booking_settings')]);
$user_id = session('user_id');
if (cannot('view', PRIV_SYSTEM_SETTINGS))
{
if ($user_id)
{
if (cannot('view', PRIV_SYSTEM_SETTINGS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -72,7 +71,7 @@ class Booking_settings extends EA_Controller {
html_vars([
'page_title' => lang('settings'),
'active_menu' => PRIV_SYSTEM_SETTINGS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'user_display_name' => $this->accounts->get_user_display_name($user_id)
]);
$this->load->view('pages/booking_settings');
@ -83,37 +82,31 @@ class Booking_settings extends EA_Controller {
*/
public function save()
{
try
{
if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{
try {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
$settings = request('booking_settings', []);
foreach ($settings as $setting)
{
$existing_setting = $this->settings_model->query()->where('name', $setting['name'])->get()->row_array();
foreach ($settings as $setting) {
$existing_setting = $this->settings_model
->query()
->where('name', $setting['name'])
->get()
->row_array();
if ( ! empty($existing_setting))
{
if (!empty($existing_setting)) {
$setting['id'] = $existing_setting['id'];
}
$this->settings_model->only($setting, [
'id',
'name',
'value'
]);
$this->settings_model->only($setting, ['id', 'name', 'value']);
$this->settings_model->save($setting);
}
response();
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Business_settings extends EA_Controller {
class Business_settings extends EA_Controller
{
/**
* Business_logic constructor.
*/
@ -48,11 +49,9 @@ class Business_settings extends EA_Controller {
session(['dest_url' => site_url('business_settings')]);
$user_id = session('user_id');
if (cannot('view', PRIV_SYSTEM_SETTINGS))
{
if ($user_id)
{
if (cannot('view', PRIV_SYSTEM_SETTINGS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -68,13 +67,13 @@ class Business_settings extends EA_Controller {
'role_slug' => $role_slug,
'business_settings' => $this->settings_model->get(),
'first_weekday' => setting('first_weekday'),
'time_format' => setting('time_format'),
'time_format' => setting('time_format')
]);
html_vars([
'page_title' => lang('settings'),
'active_menu' => PRIV_SYSTEM_SETTINGS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'user_display_name' => $this->accounts->get_user_display_name($user_id)
]);
$this->load->view('pages/business_settings');
@ -85,37 +84,31 @@ class Business_settings extends EA_Controller {
*/
public function save()
{
try
{
if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{
try {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
$settings = request('business_settings', []);
foreach ($settings as $setting)
{
$existing_setting = $this->settings_model->query()->where('name', $setting['name'])->get()->row_array();
foreach ($settings as $setting) {
$existing_setting = $this->settings_model
->query()
->where('name', $setting['name'])
->get()
->row_array();
if ( ! empty($existing_setting))
{
if (!empty($existing_setting)) {
$setting['id'] = $existing_setting['id'];
}
$this->settings_model->only($setting, [
'id',
'name',
'value'
]);
$this->settings_model->only($setting, ['id', 'name', 'value']);
$this->settings_model->save($setting);
}
response();
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -125,10 +118,8 @@ class Business_settings extends EA_Controller {
*/
public function apply_global_working_plan()
{
try
{
if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{
try {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
@ -136,15 +127,12 @@ class Business_settings extends EA_Controller {
$providers = $this->providers_model->get();
foreach ($providers as $provider)
{
foreach ($providers as $provider) {
$this->providers_model->set_setting($provider['id'], 'working_plan', $working_plan);
}
response();
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Calendar extends EA_Controller {
class Calendar extends EA_Controller
{
/**
* Calendar constructor.
*/
@ -42,6 +43,18 @@ class Calendar extends EA_Controller {
$this->load->library('webhooks_client');
}
/**
* Render the calendar page and display the selected appointment.
*
* This method will call the "index" callback to handle the page rendering.
*
* @param string $appointment_hash Appointment hash.
*/
public function reschedule(string $appointment_hash)
{
$this->index($appointment_hash);
}
/**
* Display the main backend page.
*
@ -53,14 +66,12 @@ class Calendar extends EA_Controller {
*/
public function index(string $appointment_hash = '')
{
session(['dest_url' => site_url('backend/index' . (! empty($appointment_hash) ? '/' . $appointment_hash : ''))]);
session(['dest_url' => site_url('backend/index' . (!empty($appointment_hash) ? '/' . $appointment_hash : ''))]);
$user_id = session('user_id');
if (cannot('view', PRIV_APPOINTMENTS))
{
if ($user_id)
{
if (cannot('view', PRIV_APPOINTMENTS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -75,21 +86,18 @@ class Calendar extends EA_Controller {
$secretary_providers = [];
if ($role_slug === DB_SLUG_SECRETARY)
{
if ($role_slug === DB_SLUG_SECRETARY) {
$secretary = $this->secretaries_model->find(session('user_id'));
$secretary_providers = $secretary['providers'];
}
$edit_appointment = NULL;
$edit_appointment = null;
if ( ! empty($appointment_hash))
{
if (!empty($appointment_hash)) {
$occurrences = $this->appointments_model->get(['hash' => $appointment_hash]);
if ($appointment_hash !== '' && ! empty($occurrences))
{
if ($appointment_hash !== '' && !empty($occurrences)) {
$edit_appointment = $occurrences[0];
$this->appointments_model->load($edit_appointment, ['customer']);
@ -100,18 +108,20 @@ class Calendar extends EA_Controller {
$available_providers = $this->providers_model->get_available_providers();
if ($role_slug === DB_SLUG_PROVIDER)
{
$available_providers = array_values(array_filter($available_providers, function ($available_provider) use ($user_id) {
return (int)$available_provider['id'] === (int)$user_id;
}));
if ($role_slug === DB_SLUG_PROVIDER) {
$available_providers = array_values(
array_filter($available_providers, function ($available_provider) use ($user_id) {
return (int) $available_provider['id'] === (int) $user_id;
})
);
}
if ($role_slug === DB_SLUG_SECRETARY)
{
$available_providers = array_values(array_filter($available_providers, function ($available_provider) use ($secretary_providers) {
return in_array($available_provider['id'], $secretary_providers);
}));
if ($role_slug === DB_SLUG_SECRETARY) {
$available_providers = array_values(
array_filter($available_providers, function ($available_provider) use ($secretary_providers) {
return in_array($available_provider['id'], $secretary_providers);
})
);
}
$available_services = $this->services_model->get_available_services();
@ -134,7 +144,7 @@ class Calendar extends EA_Controller {
'available_services' => $available_services,
'secretary_providers' => $secretary_providers,
'edit_appointment' => $edit_appointment,
'customers' => $this->customers_model->get(NULL, 50, NULL, 'update_datetime DESC'),
'customers' => $this->customers_model->get(null, 50, null, 'update_datetime DESC')
]);
html_vars([
@ -149,7 +159,7 @@ class Calendar extends EA_Controller {
'available_providers' => $available_providers,
'available_services' => $available_services,
'secretary_providers' => $secretary_providers,
'appointment_status_options' => json_decode($appointment_status_options, TRUE) ?? [],
'appointment_status_options' => json_decode($appointment_status_options, true) ?? [],
'require_first_name' => setting('require_first_name'),
'require_last_name' => setting('require_last_name'),
'require_email' => setting('require_email'),
@ -157,47 +167,32 @@ class Calendar extends EA_Controller {
'require_address' => setting('require_address'),
'require_city' => setting('require_city'),
'require_zip_code' => setting('require_zip_code'),
'require_notes' => setting('require_notes'),
'require_notes' => setting('require_notes')
]);
$this->load->view('pages/calendar');
}
/**
* Render the calendar page and display the selected appointment.
*
* This method will call the "index" callback to handle the page rendering.
*
* @param string $appointment_hash Appointment hash.
*/
public function reschedule(string $appointment_hash)
{
$this->index($appointment_hash);
}
/**
* Save appointment changes that are made from the backend calendar page.
*/
public function save_appointment()
{
try
{
try {
$customer_data = request('customer_data');
$appointment_data = request('appointment_data');
$this->check_event_permissions((int)$appointment_data['id_users_provider']);
$this->check_event_permissions((int) $appointment_data['id_users_provider']);
// Save customer changes to the database.
if ($customer_data)
{
if ($customer_data) {
$customer = $customer_data;
$required_permissions = ! empty($customer['id'])
$required_permissions = !empty($customer['id'])
? can('add', PRIV_CUSTOMERS)
: can('edit', PRIV_CUSTOMERS);
if ( ! $required_permissions)
{
if (!$required_permissions) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
@ -213,37 +208,33 @@ class Calendar extends EA_Controller {
'zip_code',
'timezone',
'language',
'notes',
'notes'
]);
$customer['id'] = $this->customers_model->save($customer);
}
// Save appointment changes to the database.
$manage_mode = ! empty($appointment_data['id']);
$manage_mode = !empty($appointment_data['id']);
if ($appointment_data)
{
if ($appointment_data) {
$appointment = $appointment_data;
$required_permissions = ! empty($appointment['id'])
$required_permissions = !empty($appointment['id'])
? can('add', PRIV_APPOINTMENTS)
: can('edit', PRIV_APPOINTMENTS);
if ( ! $required_permissions)
{
if (!$required_permissions) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
// If the appointment does not contain the customer record id, then it means that is going to be
// inserted.
if ( ! isset($appointment['id_users_customer']))
{
if (!isset($appointment['id_users_customer'])) {
$appointment['id_users_customer'] = $customer['id'] ?? $customer_data['id'];
}
if ($manage_mode && ! empty($appointment['id']))
{
if ($manage_mode && !empty($appointment['id'])) {
$this->synchronization->remove_appointment_on_provider_change($appointment['id']);
}
@ -259,21 +250,20 @@ class Calendar extends EA_Controller {
'is_unavailability',
'id_users_provider',
'id_users_customer',
'id_services',
'id_services'
]);
$appointment['id'] = $this->appointments_model->save($appointment);
}
if (empty($appointment['id']))
{
if (empty($appointment['id'])) {
throw new RuntimeException('The appointment ID is not available.');
}
$appointment = $this->appointments_model->find($appointment['id']);
$provider = $this->providers_model->find($appointment['id_users_provider'], TRUE);
$customer = $this->customers_model->find($appointment['id_users_customer'], TRUE);
$service = $this->services_model->find($appointment['id_services'], TRUE);
$provider = $this->providers_model->find($appointment['id_users_provider'], true);
$customer = $this->customers_model->find($appointment['id_users_customer'], true);
$service = $this->services_model->find($appointment['id_services'], true);
$settings = [
'company_name' => setting('company_name'),
@ -285,20 +275,42 @@ class Calendar extends EA_Controller {
$this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings);
$this->notifications->notify_appointment_saved($appointment, $service, $provider, $customer, $settings, $manage_mode);
$this->notifications->notify_appointment_saved(
$appointment,
$service,
$provider,
$customer,
$settings,
$manage_mode
);
$this->webhooks_client->trigger(WEBHOOK_APPOINTMENT_SAVE, $appointment);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
private function check_event_permissions(int $provider_id): void
{
$user_id = (int) session('user_id');
$role_slug = session('role_slug');
if (
$role_slug === DB_SLUG_SECRETARY &&
!$this->secretaries_model->is_provider_supported($user_id, $provider_id)
) {
abort(403);
}
if ($role_slug === DB_SLUG_PROVIDER && $user_id !== $provider_id) {
abort(403);
}
}
/**
* Delete appointment from the database.
*
@ -308,29 +320,26 @@ class Calendar extends EA_Controller {
*/
public function delete_appointment()
{
try
{
if (cannot('delete', 'appointments'))
{
try {
if (cannot('delete', 'appointments')) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
$appointment_id = request('appointment_id');
$cancellation_reason = (string)request('cancellation_reason');
$cancellation_reason = (string) request('cancellation_reason');
if (empty($appointment_id))
{
if (empty($appointment_id)) {
throw new InvalidArgumentException('No appointment id provided.');
}
// Store appointment data for later use in this method.
$appointment = $this->appointments_model->find($appointment_id);
$this->check_event_permissions((int)$appointment['id_users_provider']);
$this->check_event_permissions((int) $appointment['id_users_provider']);
$provider = $this->providers_model->find($appointment['id_users_provider'], TRUE);
$customer = $this->customers_model->find($appointment['id_users_customer'], TRUE);
$service = $this->services_model->find($appointment['id_services'], TRUE);
$provider = $this->providers_model->find($appointment['id_users_provider'], true);
$customer = $this->customers_model->find($appointment['id_users_customer'], true);
$service = $this->services_model->find($appointment['id_services'], true);
$settings = [
'company_name' => setting('company_name'),
@ -343,18 +352,23 @@ class Calendar extends EA_Controller {
// Delete appointment record from the database.
$this->appointments_model->delete($appointment_id);
$this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings, $cancellation_reason);
$this->notifications->notify_appointment_deleted(
$appointment,
$service,
$provider,
$customer,
$settings,
$cancellation_reason
);
$this->synchronization->sync_appointment_deleted($appointment, $provider);
$this->webhooks_client->trigger(WEBHOOK_APPOINTMENT_DELETE, $appointment);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -364,21 +378,19 @@ class Calendar extends EA_Controller {
*/
public function save_unavailability()
{
try
{
try {
// Check privileges
$unavailability = request('unavailability');
$required_permissions = ( ! isset($unavailability['id']))
$required_permissions = !isset($unavailability['id'])
? can('add', PRIV_APPOINTMENTS)
: can('edit', PRIV_APPOINTMENTS);
if ( ! $required_permissions)
{
if (!$required_permissions) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
$provider_id = (int)$unavailability['id_users_provider'];
$provider_id = (int) $unavailability['id_users_provider'];
$this->check_event_permissions($provider_id);
@ -393,12 +405,10 @@ class Calendar extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_UNAVAILABILITY_SAVE, $unavailability);
json_response([
'success' => TRUE,
'success' => true,
'warnings' => $warnings ?? []
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -408,10 +418,8 @@ class Calendar extends EA_Controller {
*/
public function delete_unavailability()
{
try
{
if (cannot('delete', PRIV_APPOINTMENTS))
{
try {
if (cannot('delete', PRIV_APPOINTMENTS)) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
@ -419,7 +427,7 @@ class Calendar extends EA_Controller {
$unavailability = $this->unavailabilities_model->find($unavailability_id);
$this->check_event_permissions((int)$unavailability['id_users_provider']);
$this->check_event_permissions((int) $unavailability['id_users_provider']);
$provider = $this->providers_model->find($unavailability['id_users_provider']);
@ -430,11 +438,9 @@ class Calendar extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_UNAVAILABILITY_DELETE, $unavailability);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -444,10 +450,8 @@ class Calendar extends EA_Controller {
*/
public function save_working_plan_exception()
{
try
{
if (cannot('edit', PRIV_USERS))
{
try {
if (cannot('edit', PRIV_USERS)) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
@ -455,9 +459,8 @@ class Calendar extends EA_Controller {
$working_plan_exception = request('working_plan_exception');
if ( ! $working_plan_exception)
{
$working_plan_exception = NULL;
if (!$working_plan_exception) {
$working_plan_exception = null;
}
$provider_id = request('provider_id');
@ -465,11 +468,9 @@ class Calendar extends EA_Controller {
$this->providers_model->save_working_plan_exception($provider_id, $date, $working_plan_exception);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -479,12 +480,10 @@ class Calendar extends EA_Controller {
*/
public function delete_working_plan_exception()
{
try
{
try {
$required_permissions = can('edit', PRIV_CUSTOMERS);
if ( ! $required_permissions)
{
if (!$required_permissions) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
@ -495,11 +494,9 @@ class Calendar extends EA_Controller {
$this->providers_model->delete_working_plan_exception($provider_id, $date);
json_response([
'success' => TRUE
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -511,12 +508,10 @@ class Calendar extends EA_Controller {
*/
public function get_calendar_appointments_for_table_view()
{
try
{
try {
$required_permissions = can('view', PRIV_APPOINTMENTS);
if ( ! $required_permissions)
{
if (!$required_permissions) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
@ -535,11 +530,10 @@ class Calendar extends EA_Controller {
])
];
foreach ($response['appointments'] as &$appointment)
{
$appointment['provider'] = $this->providers_model->find($appointment['id_users_provider'], TRUE);
$appointment['service'] = $this->services_model->find($appointment['id_services'], TRUE);
$appointment['customer'] = $this->customers_model->find($appointment['id_users_customer'], TRUE);
foreach ($response['appointments'] as &$appointment) {
$appointment['provider'] = $this->providers_model->find($appointment['id_users_provider'], true);
$appointment['service'] = $this->services_model->find($appointment['id_services'], true);
$appointment['customer'] = $this->customers_model->find($appointment['id_users_customer'], true);
}
unset($appointment);
@ -549,22 +543,17 @@ class Calendar extends EA_Controller {
$role_slug = session('role_slug');
// If the current user is a provider he must only see his own appointments.
if ($role_slug === DB_SLUG_PROVIDER)
{
foreach ($response['appointments'] as $index => $appointment)
{
if ((int)$appointment['id_users_provider'] !== (int)$user_id)
{
if ($role_slug === DB_SLUG_PROVIDER) {
foreach ($response['appointments'] as $index => $appointment) {
if ((int) $appointment['id_users_provider'] !== (int) $user_id) {
unset($response['appointments'][$index]);
}
}
$response['appointments'] = array_values($response['appointments']);
foreach ($response['unavailabilities'] as $index => $unavailability)
{
if ((int)$unavailability['id_users_provider'] !== (int)$user_id)
{
foreach ($response['unavailabilities'] as $index => $unavailability) {
if ((int) $unavailability['id_users_provider'] !== (int) $user_id) {
unset($response['unavailabilities'][$index]);
}
}
@ -573,24 +562,19 @@ class Calendar extends EA_Controller {
}
// If the current user is a secretary he must only see the appointments of his providers.
if ($role_slug === DB_SLUG_SECRETARY)
{
if ($role_slug === DB_SLUG_SECRETARY) {
$providers = $this->secretaries_model->find($user_id)['providers'];
foreach ($response['appointments'] as $index => $appointment)
{
if ( ! in_array((int)$appointment['id_users_provider'], $providers))
{
foreach ($response['appointments'] as $index => $appointment) {
if (!in_array((int) $appointment['id_users_provider'], $providers)) {
unset($response['appointments'][$index]);
}
}
$response['appointments'] = array_values($response['appointments']);
foreach ($response['unavailabilities'] as $index => $unavailability)
{
if ( ! in_array((int)$unavailability['id_users_provider'], $providers))
{
foreach ($response['unavailabilities'] as $index => $unavailability) {
if (!in_array((int) $unavailability['id_users_provider'], $providers)) {
unset($response['unavailabilities'][$index]);
}
}
@ -598,15 +582,13 @@ class Calendar extends EA_Controller {
$response['unavailabilities'] = array_values($response['unavailabilities']);
}
// Add blocked periods to the response.
// Add blocked periods to the response.
$start_date = request('start_date');
$end_date = request('end_date');
$response['blocked_periods'] = $this->blocked_periods_model->get_for_period($start_date, $end_date);
json_response($response);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -619,10 +601,8 @@ class Calendar extends EA_Controller {
*/
public function get_calendar_appointments()
{
try
{
if (cannot('view', PRIV_APPOINTMENTS))
{
try {
if (cannot('view', PRIV_APPOINTMENTS)) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
@ -630,8 +610,7 @@ class Calendar extends EA_Controller {
$filter_type = request('filter_type');
if ( ! $filter_type && $record_id !== FILTER_TYPE_ALL)
{
if (!$filter_type && $record_id !== FILTER_TYPE_ALL) {
json_response([
'appointments' => [],
'unavailabilities' => []
@ -642,16 +621,11 @@ class Calendar extends EA_Controller {
$record_id = $this->db->escape($record_id);
if ($filter_type == FILTER_TYPE_PROVIDER)
{
if ($filter_type == FILTER_TYPE_PROVIDER) {
$where_id = 'id_users_provider';
}
elseif ($filter_type === FILTER_TYPE_SERVICE)
{
} elseif ($filter_type === FILTER_TYPE_SERVICE) {
$where_id = 'id_services';
}
else
{
} else {
$where_id = $record_id;
}
@ -659,39 +633,68 @@ class Calendar extends EA_Controller {
$start_date = $this->db->escape(request('start_date'));
$end_date = $this->db->escape(date('Y-m-d', strtotime(request('end_date') . ' +1 day')));
$where_clause = $where_id . ' = ' . $record_id . '
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
$where_clause =
$where_id .
' = ' .
$record_id .
'
AND ((start_datetime > ' .
$start_date .
' AND start_datetime < ' .
$end_date .
')
or (end_datetime > ' .
$start_date .
' AND end_datetime < ' .
$end_date .
')
or (start_datetime <= ' .
$start_date .
' AND end_datetime >= ' .
$end_date .
'))
AND is_unavailability = 0
';
$response['appointments'] = $this->appointments_model->get($where_clause);
foreach ($response['appointments'] as &$appointment)
{
$appointment['provider'] = $this->providers_model->find($appointment['id_users_provider'], TRUE);
$appointment['service'] = $this->services_model->find($appointment['id_services'], TRUE);
$appointment['customer'] = $this->customers_model->find($appointment['id_users_customer'], TRUE);
foreach ($response['appointments'] as &$appointment) {
$appointment['provider'] = $this->providers_model->find($appointment['id_users_provider'], true);
$appointment['service'] = $this->services_model->find($appointment['id_services'], true);
$appointment['customer'] = $this->customers_model->find($appointment['id_users_customer'], true);
}
// Get unavailability periods (only for provider).
$response['unavailabilities'] = [];
if ($filter_type == FILTER_TYPE_PROVIDER)
{
$where_clause = $where_id . ' = ' . $record_id . '
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
if ($filter_type == FILTER_TYPE_PROVIDER) {
$where_clause =
$where_id .
' = ' .
$record_id .
'
AND ((start_datetime > ' .
$start_date .
' AND start_datetime < ' .
$end_date .
')
or (end_datetime > ' .
$start_date .
' AND end_datetime < ' .
$end_date .
')
or (start_datetime <= ' .
$start_date .
' AND end_datetime >= ' .
$end_date .
'))
AND is_unavailability = 1
';
$response['unavailabilities'] = $this->unavailabilities_model->get($where_clause);
}
foreach ($response['unavailabilities'] as &$unavailability)
{
foreach ($response['unavailabilities'] as &$unavailability) {
$unavailability['provider'] = $this->providers_model->find($unavailability['id_users_provider']);
}
@ -702,22 +705,17 @@ class Calendar extends EA_Controller {
$role_slug = session('role_slug');
// If the current user is a provider he must only see his own appointments.
if ($role_slug === DB_SLUG_PROVIDER)
{
foreach ($response['appointments'] as $index => $appointment)
{
if ((int)$appointment['id_users_provider'] !== (int)$user_id)
{
if ($role_slug === DB_SLUG_PROVIDER) {
foreach ($response['appointments'] as $index => $appointment) {
if ((int) $appointment['id_users_provider'] !== (int) $user_id) {
unset($response['appointments'][$index]);
}
}
$response['appointments'] = array_values($response['appointments']);
foreach ($response['unavailabilities'] as $index => $unavailability)
{
if ((int)$unavailability['id_users_provider'] !== (int)$user_id)
{
foreach ($response['unavailabilities'] as $index => $unavailability) {
if ((int) $unavailability['id_users_provider'] !== (int) $user_id) {
unset($response['unavailabilities'][$index]);
}
}
@ -726,57 +724,34 @@ class Calendar extends EA_Controller {
}
// If the current user is a secretary he must only see the appointments of his providers.
if ($role_slug === DB_SLUG_SECRETARY)
{
if ($role_slug === DB_SLUG_SECRETARY) {
$providers = $this->secretaries_model->find($user_id)['providers'];
foreach ($response['appointments'] as $index => $appointment)
{
if ( ! in_array((int)$appointment['id_users_provider'], $providers))
{
foreach ($response['appointments'] as $index => $appointment) {
if (!in_array((int) $appointment['id_users_provider'], $providers)) {
unset($response['appointments'][$index]);
}
}
$response['appointments'] = array_values($response['appointments']);
foreach ($response['unavailabilities'] as $index => $unavailability)
{
if ( ! in_array((int)$unavailability['id_users_provider'], $providers))
{
foreach ($response['unavailabilities'] as $index => $unavailability) {
if (!in_array((int) $unavailability['id_users_provider'], $providers)) {
unset($response['unavailabilities'][$index]);
}
}
$response['unavailabilities'] = array_values($response['unavailabilities']);
}
// Add blocked periods to the response.
$start_date = request('start_date');
$end_date = request('end_date');
$response['blocked_periods'] = $this->blocked_periods_model->get_for_period($start_date, $end_date);
// Add blocked periods to the response.
$start_date = request('start_date');
$end_date = request('end_date');
$response['blocked_periods'] = $this->blocked_periods_model->get_for_period($start_date, $end_date);
json_response($response);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
private function check_event_permissions(int $provider_id): void
{
$user_id = (int)session('user_id');
$role_slug = session('role_slug');
if ($role_slug === DB_SLUG_SECRETARY && ! $this->secretaries_model->is_provider_supported($user_id, $provider_id))
{
abort(403);
}
if ($role_slug === DB_SLUG_PROVIDER && $user_id !== $provider_id)
{
abort(403);
}
}
}

View file

@ -11,16 +11,15 @@
* @since v1.0.0
* ---------------------------------------------------------------------------- */
use Gregwar\Captcha\CaptchaBuilder;
/**
* Captcha controller.
*
*
* Handles the captcha operations.
*
* @package Controllers
*/
class Captcha extends EA_Controller {
class Captcha extends EA_Controller
{
/**
* Class Constructor
*/
@ -39,7 +38,7 @@ class Captcha extends EA_Controller {
$this->captcha_builder->setDistortion(true);
$this->captcha_builder->setMaxBehindLines(1);
$this->captcha_builder->setMaxFrontLines(1);
$this->captcha_builder->setBackgroundColor(255,255,255);
$this->captcha_builder->setBackgroundColor(255, 255, 255);
$this->captcha_builder->build();
session(['captcha_phrase' => $this->captcha_builder->getPhrase()]);
header('Content-type: image/jpeg');

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Consents extends EA_Controller {
class Consents extends EA_Controller
{
/**
* Consents constructor.
*/
@ -34,28 +35,25 @@ class Consents extends EA_Controller {
*/
public function save()
{
try
{
try {
$consent = request('consent');
$consent['ip'] = $this->input->ip_address();
$occurrences = $this->consents_model->get(['ip' => $consent['ip']], 1, 0, 'create_datetime DESC');
if ( ! empty($occurrences))
{
if (!empty($occurrences)) {
$last_consent = $occurrences[0];
$last_consent_create_datetime_instance = new DateTime($last_consent['create_datetime']);
$threshold_datetime_instance = new DateTime('-24 hours');
if ($last_consent_create_datetime_instance > $threshold_datetime_instance)
{
if ($last_consent_create_datetime_instance > $threshold_datetime_instance) {
// Do not create a new consent.
json_response([
'success' => TRUE,
'success' => true
]);
return;
@ -65,12 +63,10 @@ class Consents extends EA_Controller {
$consent['id'] = $this->consents_model->save($consent);
json_response([
'success' => TRUE,
'success' => true,
'id' => $consent['id']
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,14 +18,14 @@ require_once __DIR__ . '/Google.php';
*
* Handles all the Console related operations.
*/
class Console extends EA_Controller {
class Console extends EA_Controller
{
/**
* Console constructor.
*/
public function __construct()
{
if ( ! is_cli())
{
if (!is_cli()) {
exit('No direct script access allowed');
}
@ -57,7 +57,9 @@ class Console extends EA_Controller {
$password = $this->instance->seed();
response(PHP_EOL . '⇾ Installation completed, login with "administrator" / "' . $password . '".' . PHP_EOL . PHP_EOL);
response(
PHP_EOL . '⇾ Installation completed, login with "administrator" / "' . $password . '".' . PHP_EOL . PHP_EOL
);
}
/**
@ -112,7 +114,7 @@ class Console extends EA_Controller {
*/
public function backup()
{
$this->instance->backup($GLOBALS['argv'][3] ?? NULL);
$this->instance->backup($GLOBALS['argv'][3] ?? null);
}
/**
@ -132,18 +134,15 @@ class Console extends EA_Controller {
{
$providers = $this->providers_model->get();
foreach ($providers as $provider)
{
if ( ! filter_var($provider['settings']['google_sync'], FILTER_VALIDATE_BOOLEAN))
{
foreach ($providers as $provider) {
if (!filter_var($provider['settings']['google_sync'], FILTER_VALIDATE_BOOLEAN)) {
continue;
}
Google::sync((string)$provider['id']);
Google::sync((string) $provider['id']);
}
}
/**
* Show help information about the console capabilities.
*
@ -174,7 +173,7 @@ class Console extends EA_Controller {
'⇾ php index.php console backup',
'⇾ php index.php console sync',
'',
'',
''
];
response(implode(PHP_EOL, $help));

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class General_settings extends EA_Controller {
class General_settings extends EA_Controller
{
/**
* Calendar constructor.
*/
@ -39,11 +40,9 @@ class General_settings extends EA_Controller {
session(['dest_url' => site_url('general_settings')]);
$user_id = session('user_id');
if (cannot('view', PRIV_SYSTEM_SETTINGS))
{
if ($user_id)
{
if (cannot('view', PRIV_SYSTEM_SETTINGS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -51,26 +50,26 @@ class General_settings extends EA_Controller {
return;
}
$role_slug = session('role_slug');
$available_theme_files = glob(__DIR__ . '/../../assets/css/themes/*.min.css');
$available_themes = array_map(function ($available_theme_file) {
return str_replace('.min.css', '', basename($available_theme_file));
}, $available_theme_files);
return str_replace('.min.css', '', basename($available_theme_file));
}, $available_theme_files);
script_vars([
'user_id' => $user_id,
'role_slug' => $role_slug,
'general_settings' => $this->settings_model->get(),
'general_settings' => $this->settings_model->get()
]);
html_vars([
'page_title' => lang('settings'),
'active_menu' => PRIV_SYSTEM_SETTINGS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'available_themes' => $available_themes,
'available_themes' => $available_themes
]);
$this->load->view('pages/general_settings');
@ -81,21 +80,21 @@ class General_settings extends EA_Controller {
*/
public function save()
{
try
{
if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{
try {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
$settings = request('general_settings', []);
foreach ($settings as $setting)
{
$existing_setting = $this->settings_model->query()->where('name', $setting['name'])->get()->row_array();
foreach ($settings as $setting) {
$existing_setting = $this->settings_model
->query()
->where('name', $setting['name'])
->get()
->row_array();
if ( ! empty($existing_setting))
{
if (!empty($existing_setting)) {
$setting['id'] = $existing_setting['id'];
}
@ -103,9 +102,7 @@ class General_settings extends EA_Controller {
}
response();
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Google extends EA_Controller {
class Google extends EA_Controller
{
/**
* Google constructor.
*/
@ -40,10 +41,9 @@ class Google extends EA_Controller {
* needs to be relatively small, because a lot of API calls might be necessary and this will lead to consuming the
* Google limit for the Calendar API usage.
*/
public static function sync(string $provider_id = NULL): void
public static function sync(string $provider_id = null): void
{
try
{
try {
/** @var EA_Controller $CI */
$CI = get_instance();
@ -60,13 +60,11 @@ class Google extends EA_Controller {
$user_id = session('user_id');
if ( ! $user_id && ! is_cli())
{
if (!$user_id && !is_cli()) {
return;
}
if ( ! $provider_id)
{
if (!$provider_id) {
throw new InvalidArgumentException('No provider ID provided.');
}
@ -75,12 +73,11 @@ class Google extends EA_Controller {
// Check whether the selected provider has the Google Sync enabled.
$google_sync = $CI->providers_model->get_setting($provider['id'], 'google_sync');
if ( ! $google_sync)
{
if (!$google_sync) {
return; // The selected provider does not have the Google Syncing enabled.
}
$google_token = json_decode($provider['settings']['google_token'], TRUE);
$google_token = json_decode($provider['settings']['google_token'], true);
$CI->google_sync->refresh_token($google_token['refresh_token']);
@ -114,25 +111,26 @@ class Google extends EA_Controller {
$provider_timezone = new DateTimeZone($provider['timezone']);
// Sync each appointment with Google Calendar by following the project's sync protocol (see documentation).
foreach ($local_events as $local_event)
{
if ( ! $local_event['is_unavailability'])
{
foreach ($local_events as $local_event) {
if (!$local_event['is_unavailability']) {
$service = $CI->services_model->find($local_event['id_services']);
$customer = $CI->customers_model->find($local_event['id_users_customer']);
$events_model = $CI->appointments_model;
}
else
{
$service = NULL;
$customer = NULL;
} else {
$service = null;
$customer = null;
$events_model = $CI->unavailabilities_model;
}
// If current appointment not synced yet, add to Google Calendar.
if ( ! $local_event['id_google_calendar'])
{
$google_event = $CI->google_sync->add_appointment($local_event, $provider, $service, $customer, $settings);
if (!$local_event['id_google_calendar']) {
$google_event = $CI->google_sync->add_appointment(
$local_event,
$provider,
$service,
$customer,
$settings
);
$local_event['id_google_calendar'] = $google_event->getId();
@ -141,85 +139,75 @@ class Google extends EA_Controller {
continue;
}
// Appointment is synced with Google Calendar.
try
{
try {
$google_event = $CI->google_sync->get_event($provider, $local_event['id_google_calendar']);
if ($google_event->getStatus() == 'cancelled')
{
if ($google_event->getStatus() == 'cancelled') {
throw new Exception('Event is cancelled, remove the record from Easy!Appointments.');
}
// If Google Calendar event is different from Easy!Appointments appointment then update Easy!Appointments record.
$local_event_start = strtotime($local_event['start_datetime']);
$local_event_end = strtotime($local_event['end_datetime']);
$google_event_start = new DateTime($google_event->getStart()->getDateTime() ?? $google_event->getEnd()->getDate());
$google_event_start = new DateTime(
$google_event->getStart()->getDateTime() ?? $google_event->getEnd()->getDate()
);
$google_event_start->setTimezone($provider_timezone);
$google_event_end = new DateTime($google_event->getEnd()->getDateTime() ?? $google_event->getEnd()->getDate());
$google_event_end = new DateTime(
$google_event->getEnd()->getDateTime() ?? $google_event->getEnd()->getDate()
);
$google_event_end->setTimezone($provider_timezone);
$google_event_notes = $local_event['is_unavailability'] ? $google_event->getSummary() . ' ' . $google_event->getDescription() : $google_event->getDescription();
$google_event_notes = $local_event['is_unavailability']
? $google_event->getSummary() . ' ' . $google_event->getDescription()
: $google_event->getDescription();
$is_different = $local_event_start !== $google_event_start->getTimestamp()
|| $local_event_end !== $google_event_end->getTimestamp()
|| $local_event['notes'] !== $google_event_notes;
$is_different =
$local_event_start !== $google_event_start->getTimestamp() ||
$local_event_end !== $google_event_end->getTimestamp() ||
$local_event['notes'] !== $google_event_notes;
if ($is_different)
{
if ($is_different) {
$local_event['start_datetime'] = $google_event_start->format('Y-m-d H:i:s');
$local_event['end_datetime'] = $google_event_end->format('Y-m-d H:i:s');
$local_event['notes'] = $google_event_notes;
$events_model->save($local_event);
}
}
catch (Throwable)
{
} catch (Throwable) {
// Appointment not found on Google Calendar, delete from Easy!Appointments.
$events_model->delete($local_event['id']);
$local_event['id_google_calendar'] = NULL;
$local_event['id_google_calendar'] = null;
}
}
// Add Google Calendar events that do not exist in Easy!Appointments.
$google_calendar = $provider['settings']['google_calendar'];
try
{
try {
$google_events = $CI->google_sync->get_sync_events($google_calendar, $start, $end);
}
catch (Throwable $e)
{
if ($e->getCode() === 404)
{
} catch (Throwable $e) {
if ($e->getCode() === 404) {
log_message('error', 'Google - Remote Calendar not found for provider ID: ' . $provider_id);
return; // The remote calendar was not found.
}
else
{
} else {
throw $e;
}
}
foreach ($google_events->getItems() as $google_event)
{
if ($google_event->getStatus() === 'cancelled')
{
foreach ($google_events->getItems() as $google_event) {
if ($google_event->getStatus() === 'cancelled') {
continue;
}
if ($google_event->getStart() === NULL || $google_event->getEnd() === NULL)
{
if ($google_event->getStart() === null || $google_event->getEnd() === null) {
continue;
}
if ($google_event->getStart()->getDateTime() === $google_event->getEnd()->getDateTime())
{
if ($google_event->getStart()->getDateTime() === $google_event->getEnd()->getDateTime()) {
continue;
}
@ -230,15 +218,15 @@ class Google extends EA_Controller {
$appointment_results = $CI->appointments_model->get(['id_google_calendar' => $google_event->getId()]);
if ( ! empty($appointment_results))
{
if (!empty($appointment_results)) {
continue;
}
$unavailability_results = $CI->unavailabilities_model->get(['id_google_calendar' => $google_event->getId()]);
$unavailability_results = $CI->unavailabilities_model->get([
'id_google_calendar' => $google_event->getId()
]);
if ( ! empty($unavailability_results))
{
if (!empty($unavailability_results)) {
continue;
}
@ -246,25 +234,26 @@ class Google extends EA_Controller {
$local_event = [
'start_datetime' => $google_event_start->format('Y-m-d H:i:s'),
'end_datetime' => $google_event_end->format('Y-m-d H:i:s'),
'is_unavailability' => TRUE,
'is_unavailability' => true,
'location' => $google_event->getLocation(),
'notes' => $google_event->getSummary() . ' ' . $google_event->getDescription(),
'id_users_provider' => $provider_id,
'id_google_calendar' => $google_event->getId(),
'id_users_customer' => NULL,
'id_services' => NULL,
'id_users_customer' => null,
'id_services' => null
];
$CI->unavailabilities_model->save($local_event);
}
json_response([
'success' => TRUE
'success' => true
]);
}
catch (Throwable $e)
{
log_message('error', 'Google - Sync completed with an error (provider ID "' . $provider_id . '"): ' . $e->getMessage());
} catch (Throwable $e) {
log_message(
'error',
'Google - Sync completed with an error (provider ID "' . $provider_id . '"): ' . $e->getMessage()
);
json_exception($e);
}
@ -280,8 +269,7 @@ class Google extends EA_Controller {
*/
public function oauth(string $provider_id): void
{
if ( ! $this->session->userdata('user_id'))
{
if (!$this->session->userdata('user_id')) {
show_error('Forbidden', 403);
}
@ -308,15 +296,13 @@ class Google extends EA_Controller {
*/
public function oauth_callback(): void
{
if ( ! session('user_id'))
{
if (!session('user_id')) {
abort(403, 'Forbidden');
}
$code = request('code');
if (empty($code))
{
if (empty($code)) {
response('Code authorization failed.');
return;
@ -324,8 +310,7 @@ class Google extends EA_Controller {
$token = $this->google_sync->authenticate($code);
if (empty($token))
{
if (empty($token)) {
response('Token authorization failed.');
return;
@ -334,14 +319,11 @@ class Google extends EA_Controller {
// Store the token into the database for future reference.
$oauth_provider_id = session('oauth_provider_id');
if ($oauth_provider_id)
{
$this->providers_model->set_setting($oauth_provider_id, 'google_sync', TRUE);
if ($oauth_provider_id) {
$this->providers_model->set_setting($oauth_provider_id, 'google_sync', true);
$this->providers_model->set_setting($oauth_provider_id, 'google_token', json_encode($token));
$this->providers_model->set_setting($oauth_provider_id, 'google_calendar', 'primary');
}
else
{
} else {
response('Sync provider id not specified.');
}
}
@ -354,37 +336,32 @@ class Google extends EA_Controller {
*/
public function get_google_calendars(): void
{
try
{
$provider_id = (int)request('provider_id');
try {
$provider_id = (int) request('provider_id');
if (empty($provider_id))
{
if (empty($provider_id)) {
throw new Exception('Provider id is required in order to fetch the google calendars.');
}
// Check if selected provider has sync enabled.
$google_sync = $this->providers_model->get_setting($provider_id, 'google_sync');
if ( ! $google_sync)
{
if (!$google_sync) {
json_response([
'success' => FALSE
'success' => false
]);
return;
}
$google_token = json_decode($this->providers_model->get_setting($provider_id, 'google_token'), TRUE);
$google_token = json_decode($this->providers_model->get_setting($provider_id, 'google_token'), true);
$this->google_sync->refresh_token($google_token['refresh_token']);
$calendars = $this->google_sync->get_google_calendars();
json_response($calendars);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -396,14 +373,12 @@ class Google extends EA_Controller {
*/
public function select_google_calendar(): void
{
try
{
try {
$provider_id = request('provider_id');
$user_id = session('user_id');
if (cannot('edit', PRIV_USERS) && (int)$user_id !== (int)$provider_id)
{
if (cannot('edit', PRIV_USERS) && (int) $user_id !== (int) $provider_id) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
@ -412,11 +387,9 @@ class Google extends EA_Controller {
$this->providers_model->set_setting($provider_id, 'google_calendar', $calendar_id);
json_response([
'success' => TRUE
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -430,36 +403,29 @@ class Google extends EA_Controller {
*/
public function disable_provider_sync(): void
{
try
{
try {
$provider_id = request('provider_id');
if ( ! $provider_id)
{
if (!$provider_id) {
throw new Exception('Provider id not specified.');
}
$user_id = session('user_id');
if (
cannot('edit', PRIV_USERS)
&& (int)$user_id !== (int)$provider_id)
{
if (cannot('edit', PRIV_USERS) && (int) $user_id !== (int) $provider_id) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
$this->providers_model->set_setting($provider_id, 'google_sync', FALSE);
$this->providers_model->set_setting($provider_id, 'google_sync', false);
$this->providers_model->set_setting($provider_id, 'google_token');
$this->appointments_model->clear_google_sync_ids($provider_id);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Google_analytics_settings extends EA_Controller {
class Google_analytics_settings extends EA_Controller
{
/**
* Google_analytics_settings constructor.
*/
@ -40,10 +41,8 @@ class Google_analytics_settings extends EA_Controller {
$user_id = session('user_id');
if (cannot('view', PRIV_SYSTEM_SETTINGS))
{
if ($user_id)
{
if (cannot('view', PRIV_SYSTEM_SETTINGS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -57,13 +56,13 @@ class Google_analytics_settings extends EA_Controller {
script_vars([
'user_id' => $user_id,
'role_slug' => $role_slug,
'google_analytics_settings' => $this->settings_model->get('name like "google_analytics_%"'),
'google_analytics_settings' => $this->settings_model->get('name like "google_analytics_%"')
]);
html_vars([
'page_title' => lang('google_analytics'),
'active_menu' => PRIV_SYSTEM_SETTINGS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'user_display_name' => $this->accounts->get_user_display_name($user_id)
]);
$this->load->view('pages/google_analytics_settings');
@ -74,21 +73,21 @@ class Google_analytics_settings extends EA_Controller {
*/
public function save()
{
try
{
if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{
try {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
$settings = request('google_analytics_settings', []);
foreach ($settings as $setting)
{
$existing_setting = $this->settings_model->query()->where('name', $setting['name'])->get()->row_array();
foreach ($settings as $setting) {
$existing_setting = $this->settings_model
->query()
->where('name', $setting['name'])
->get()
->row_array();
if ( ! empty($existing_setting))
{
if (!empty($existing_setting)) {
$setting['id'] = $existing_setting['id'];
}
@ -96,9 +95,7 @@ class Google_analytics_settings extends EA_Controller {
}
response();
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,20 +18,21 @@
*
* @package Controllers
*/
class Installation extends EA_Controller {
class Installation extends EA_Controller
{
/**
* Installation constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->model('admins_model');
$this->load->model('settings_model');
$this->load->model('services_model');
$this->load->model('providers_model');
$this->load->model('customers_model');
$this->load->library('instance');
}
@ -40,8 +41,7 @@ class Installation extends EA_Controller {
*/
public function index()
{
if (is_app_installed())
{
if (is_app_installed()) {
redirect();
return;
}
@ -56,23 +56,21 @@ class Installation extends EA_Controller {
*/
public function perform()
{
try
{
if (is_app_installed())
{
try {
if (is_app_installed()) {
return;
}
$admin = request('admin');
$company = request('company');
$this->instance->migrate();
$this->instance->migrate();
// Insert admin
$admin['timezone'] = 'UTC';
$admin['settings']['username'] = $admin['username'];
$admin['settings']['password'] = $admin['password'];
$admin['settings']['notifications'] = TRUE;
$admin['settings']['notifications'] = true;
$admin['settings']['calendar_view'] = CALENDAR_VIEW_DEFAULT;
unset($admin['username'], $admin['password']);
$admin['id'] = $this->admins_model->save($admin);
@ -82,14 +80,14 @@ class Installation extends EA_Controller {
'user_email' => $admin['email'],
'role_slug' => DB_SLUG_ADMIN,
'timezone' => $admin['timezone'],
'username' => $admin['settings']['username']
'username' => $admin['settings']['username']
]);
// Save company settings
setting([
'company_name' => $company['company_name'],
'company_email' => $company['company_email'],
'company_link' => $company['company_link'],
'company_link' => $company['company_link']
]);
// Service
@ -108,19 +106,17 @@ class Installation extends EA_Controller {
'last_name' => 'Doe',
'email' => 'jane@example.org',
'phone_number' => '+1 (000) 000-0000',
'services' => [
$service_id
],
'services' => [$service_id],
'settings' => [
'username' => 'janedoe',
'password' => random_string(),
'working_plan' => setting('company_working_plan'),
'notifications' => TRUE,
'google_sync' => FALSE,
'notifications' => true,
'google_sync' => false,
'sync_past_days' => 30,
'sync_future_days' => 90,
'calendar_view' => CALENDAR_VIEW_DEFAULT
],
]
]);
// Customer
@ -128,15 +124,13 @@ class Installation extends EA_Controller {
'first_name' => 'James',
'last_name' => 'Doe',
'email' => 'james@example.org',
'phone_number' => '+1 (000) 000-0000',
'phone_number' => '+1 (000) 000-0000'
]);
json_response([
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Integrations extends EA_Controller {
class Integrations extends EA_Controller
{
/**
* Integrations constructor.
*/
@ -49,10 +50,8 @@ class Integrations extends EA_Controller {
$user_id = session('user_id');
if (cannot('view', PRIV_SYSTEM_SETTINGS))
{
if ($user_id)
{
if (cannot('view', PRIV_SYSTEM_SETTINGS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -67,7 +66,7 @@ class Integrations extends EA_Controller {
'page_title' => lang('integrations'),
'active_menu' => PRIV_SYSTEM_SETTINGS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug)
]);
$this->load->view('pages/integrations');

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Legal_settings extends EA_Controller {
class Legal_settings extends EA_Controller
{
/**
* Legal_contents constructor.
*/
@ -39,11 +40,9 @@ class Legal_settings extends EA_Controller {
session(['dest_url' => site_url('legal_settings')]);
$user_id = session('user_id');
if (cannot('view', PRIV_SYSTEM_SETTINGS))
{
if ($user_id)
{
if (cannot('view', PRIV_SYSTEM_SETTINGS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -51,19 +50,19 @@ class Legal_settings extends EA_Controller {
return;
}
$role_slug = session('role_slug');
script_vars([
'user_id' => $user_id,
'role_slug' => $role_slug,
'legal_settings' => $this->settings_model->get(),
'legal_settings' => $this->settings_model->get()
]);
html_vars([
'page_title' => lang('settings'),
'active_menu' => PRIV_SYSTEM_SETTINGS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'user_display_name' => $this->accounts->get_user_display_name($user_id)
]);
$this->load->view('pages/legal_settings');
@ -74,21 +73,21 @@ class Legal_settings extends EA_Controller {
*/
public function save()
{
try
{
if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{
try {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
$settings = request('legal_settings', []);
foreach ($settings as $setting)
{
$existing_setting = $this->settings_model->query()->where('name', $setting['name'])->get()->row_array();
foreach ($settings as $setting) {
$existing_setting = $this->settings_model
->query()
->where('name', $setting['name'])
->get()
->row_array();
if ( ! empty($existing_setting))
{
if (!empty($existing_setting)) {
$setting['id'] = $existing_setting['id'];
}
@ -96,9 +95,7 @@ class Legal_settings extends EA_Controller {
}
response();
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Localization extends EA_Controller {
class Localization extends EA_Controller
{
/**
* Change system language for current user.
*
@ -28,14 +29,14 @@ class Localization extends EA_Controller {
*/
public function change_language()
{
try
{
try {
// Check if language exists in the available languages.
$language = request('language');
if ( ! in_array($language, config('available_languages')))
{
throw new RuntimeException('Translations for the given language does not exist (' . request('language') . ').');
if (!in_array($language, config('available_languages'))) {
throw new RuntimeException(
'Translations for the given language does not exist (' . request('language') . ').'
);
}
$language = request('language');
@ -45,11 +46,9 @@ class Localization extends EA_Controller {
config(['language' => $language]);
json_response([
'success' => TRUE
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -14,11 +14,12 @@
/**
* Login controller.
*
* Handles the login page functionality.
* Handles the login page functionality.
*
* @package Controllers
*/
class Login extends EA_Controller {
class Login extends EA_Controller
{
/**
* Login constructor.
*/
@ -30,12 +31,12 @@ class Login extends EA_Controller {
$this->load->library('email_messages');
script_vars([
'dest_url' => session('dest_url', site_url('calendar')),
'dest_url' => session('dest_url', site_url('calendar'))
]);
}
/**
* Render the login page.
* Render the login page.
*/
public function index()
{
@ -45,48 +46,42 @@ class Login extends EA_Controller {
'dest_url' => session('dest_url', site_url('calendar')),
'company_name' => setting('company_name')
]);
$this->load->view('pages/login');
}
/**
* Validate the provided credentials and start a new session if the validation was successful.
* Validate the provided credentials and start a new session if the validation was successful.
*/
public function validate()
{
try
{
try {
$username = request('username');
if (empty($username))
{
if (empty($username)) {
throw new InvalidArgumentException('No username value provided.');
}
$password = request('password');
if (empty($password))
{
if (empty($password)) {
throw new InvalidArgumentException('No password value provided.');
}
$user_data = $this->accounts->check_login($username, $password);
if (empty($user_data))
{
if (empty($user_data)) {
throw new InvalidArgumentException('Invalid credentials provided, please try again.');
}
$this->session->sess_regenerate();
session($user_data); // Save data in the session.
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,16 +18,17 @@
*
* @package Controllers
*/
class Logout extends EA_Controller {
class Logout extends EA_Controller
{
/**
* Render the logout page.
* Render the logout page.
*/
public function index()
{
$this->session->sess_destroy();
$company_name = setting('company_name');
$company_name = setting('company_name');
html_vars([
'page_title' => lang('log_out'),
'company_name' => $company_name

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Matomo_analytics_settings extends EA_Controller {
class Matomo_analytics_settings extends EA_Controller
{
/**
* Matomo_analytics_settings constructor.
*/
@ -40,10 +41,8 @@ class Matomo_analytics_settings extends EA_Controller {
$user_id = session('user_id');
if (cannot('view', PRIV_SYSTEM_SETTINGS))
{
if ($user_id)
{
if (cannot('view', PRIV_SYSTEM_SETTINGS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -57,13 +56,13 @@ class Matomo_analytics_settings extends EA_Controller {
script_vars([
'user_id' => $user_id,
'role_slug' => $role_slug,
'matomo_analytics_settings' => $this->settings_model->get('name like "matomo_analytics_%"'),
'matomo_analytics_settings' => $this->settings_model->get('name like "matomo_analytics_%"')
]);
html_vars([
'page_title' => lang('matomo_analytics'),
'active_menu' => PRIV_SYSTEM_SETTINGS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'user_display_name' => $this->accounts->get_user_display_name($user_id)
]);
$this->load->view('pages/matomo_analytics_settings');
@ -74,21 +73,21 @@ class Matomo_analytics_settings extends EA_Controller {
*/
public function save()
{
try
{
if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{
try {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) {
throw new RuntimeException('You do not have the required permissions for this task.');
}
$settings = request('matomo_analytics_settings', []);
foreach ($settings as $setting)
{
$existing_setting = $this->settings_model->query()->where('name', $setting['name'])->get()->row_array();
foreach ($settings as $setting) {
$existing_setting = $this->settings_model
->query()
->where('name', $setting['name'])
->get()
->row_array();
if ( ! empty($existing_setting))
{
if (!empty($existing_setting)) {
$setting['id'] = $existing_setting['id'];
}
@ -96,9 +95,7 @@ class Matomo_analytics_settings extends EA_Controller {
}
response();
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Privacy extends EA_Controller {
class Privacy extends EA_Controller
{
/**
* Privacy constructor.
*/
@ -36,38 +37,33 @@ class Privacy extends EA_Controller {
*/
public function delete_personal_information()
{
try
{
try {
$display_delete_personal_information = setting('display_delete_personal_information');
if ( ! $display_delete_personal_information)
{
if (!$display_delete_personal_information) {
abort(403, 'Forbidden');
}
$customer_token = request('customer_token');
if (empty($customer_token))
{
if (empty($customer_token)) {
throw new InvalidArgumentException('Invalid customer token value provided.');
}
$customer_id = $this->cache->get('customer-token-' . $customer_token);
if (empty($customer_id))
{
throw new InvalidArgumentException('Customer ID does not exist, please reload the page '
. 'and try again.');
if (empty($customer_id)) {
throw new InvalidArgumentException(
'Customer ID does not exist, please reload the page ' . 'and try again.'
);
}
$this->customers_model->delete($customer_id);
json_response([
'success' => TRUE
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Providers extends EA_Controller {
class Providers extends EA_Controller
{
/**
* Providers constructor.
*/
@ -47,10 +48,8 @@ class Providers extends EA_Controller {
$user_id = session('user_id');
if (cannot('view', PRIV_USERS))
{
if ($user_id)
{
if (cannot('view', PRIV_USERS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -63,8 +62,7 @@ class Providers extends EA_Controller {
$services = $this->services_model->get();
foreach ($services as &$service)
{
foreach ($services as &$service) {
$this->services_model->only($service, ['id', 'name']);
}
@ -77,7 +75,7 @@ class Providers extends EA_Controller {
'first_weekday' => setting('first_weekday'),
'min_password_length' => MIN_PASSWORD_LENGTH,
'timezones' => $this->timezones->to_array(),
'services' => $services,
'services' => $services
]);
html_vars([
@ -86,7 +84,7 @@ class Providers extends EA_Controller {
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'grouped_timezones' => $this->timezones->to_grouped_array(),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
'services' => $this->services_model->get(),
'services' => $this->services_model->get()
]);
$this->load->view('pages/providers');
@ -97,10 +95,8 @@ class Providers extends EA_Controller {
*/
public function search()
{
try
{
if (cannot('view', PRIV_USERS))
{
try {
if (cannot('view', PRIV_USERS)) {
abort(403, 'Forbidden');
}
@ -115,9 +111,7 @@ class Providers extends EA_Controller {
$providers = $this->providers_model->search($keyword, $limit, $offset, $order_by);
json_response($providers);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -127,10 +121,8 @@ class Providers extends EA_Controller {
*/
public function store()
{
try
{
if (cannot('add', PRIV_USERS))
{
try {
if (cannot('add', PRIV_USERS)) {
abort(403, 'Forbidden');
}
@ -152,7 +144,7 @@ class Providers extends EA_Controller {
'is_private',
'id_roles',
'settings',
'services',
'services'
]);
$this->providers_model->only($provider['settings'], [
@ -165,7 +157,7 @@ class Providers extends EA_Controller {
]);
$this->providers_model->optional($provider, [
'services' => [],
'services' => []
]);
$provider_id = $this->providers_model->save($provider);
@ -175,12 +167,30 @@ class Providers extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_PROVIDER_SAVE, $provider);
json_response([
'success' => TRUE,
'success' => true,
'id' => $provider_id
]);
} catch (Throwable $e) {
json_exception($e);
}
catch (Throwable $e)
{
}
/**
* Find a provider.
*/
public function find()
{
try {
if (cannot('view', PRIV_USERS)) {
abort(403, 'Forbidden');
}
$provider_id = request('provider_id');
$provider = $this->providers_model->find($provider_id);
json_response($provider);
} catch (Throwable $e) {
json_exception($e);
}
}
@ -190,10 +200,8 @@ class Providers extends EA_Controller {
*/
public function update()
{
try
{
if (cannot('edit', PRIV_USERS))
{
try {
if (cannot('edit', PRIV_USERS)) {
abort(403, 'Forbidden');
}
@ -216,7 +224,7 @@ class Providers extends EA_Controller {
'is_private',
'id_roles',
'settings',
'services',
'services'
]);
$this->providers_model->only($provider['settings'], [
@ -229,7 +237,7 @@ class Providers extends EA_Controller {
]);
$this->providers_model->optional($provider, [
'services' => [],
'services' => []
]);
$provider_id = $this->providers_model->save($provider);
@ -239,12 +247,10 @@ class Providers extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_PROVIDER_SAVE, $provider);
json_response([
'success' => TRUE,
'success' => true,
'id' => $provider_id
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -254,10 +260,8 @@ class Providers extends EA_Controller {
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_USERS))
{
try {
if (cannot('delete', PRIV_USERS)) {
abort(403, 'Forbidden');
}
@ -270,35 +274,9 @@ class Providers extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_PROVIDER_DELETE, $provider);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Find a provider.
*/
public function find()
{
try
{
if (cannot('view', PRIV_USERS))
{
abort(403, 'Forbidden');
}
$provider_id = request('provider_id');
$provider = $this->providers_model->find($provider_id);
json_response($provider);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Recovery extends EA_Controller {
class Recovery extends EA_Controller
{
/**
* User constructor.
*/
@ -35,45 +36,38 @@ class Recovery extends EA_Controller {
*/
public function index()
{
$company_name = setting('company_name');
$company_name = setting('company_name');
html_vars([
'page_title' => lang('forgot_your_password'),
'dest_url' => session('dest_url', site_url('backend')),
'company_name' => $company_name
]);
]);
$this->load->view('pages/recovery');
}
/**
* Recover the user password and notify the user via email.
*/
public function perform()
{
try
{
try {
$username = request('username');
if (empty($username))
{
if (empty($username)) {
throw new InvalidArgumentException('No username value provided.');
}
$email = request('email');
if (empty($email))
{
if (empty($email)) {
throw new InvalidArgumentException('No email value provided.');
}
$new_password = $this->accounts->regenerate_password(
$username,
$email
);
$new_password = $this->accounts->regenerate_password($username, $email);
if ($new_password)
{
if ($new_password) {
$settings = [
'company_name' => setting('company_name'),
'company_link' => setting('company_link'),
@ -84,11 +78,9 @@ class Recovery extends EA_Controller {
}
json_response([
'success' => TRUE
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Secretaries extends EA_Controller {
class Secretaries extends EA_Controller
{
/**
* Secretaries constructor.
*/
@ -46,11 +47,9 @@ class Secretaries extends EA_Controller {
session(['dest_url' => site_url('secretaries')]);
$user_id = session('user_id');
if (cannot('view', PRIV_USERS))
{
if ($user_id)
{
if (cannot('view', PRIV_USERS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -63,13 +62,8 @@ class Secretaries extends EA_Controller {
$providers = $this->providers_model->get();
foreach ($providers as &$provider)
{
$this->providers_model->only($provider, [
'id',
'first_name',
'last_name'
]);
foreach ($providers as &$provider) {
$this->providers_model->only($provider, ['id', 'first_name', 'last_name']);
}
script_vars([
@ -77,7 +71,7 @@ class Secretaries extends EA_Controller {
'role_slug' => $role_slug,
'timezones' => $this->timezones->to_array(),
'min_password_length' => MIN_PASSWORD_LENGTH,
'providers' => $providers,
'providers' => $providers
]);
html_vars([
@ -86,7 +80,7 @@ class Secretaries extends EA_Controller {
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'grouped_timezones' => $this->timezones->to_grouped_array(),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
'providers' => $this->providers_model->get(),
'providers' => $this->providers_model->get()
]);
$this->load->view('pages/secretaries');
@ -97,10 +91,8 @@ class Secretaries extends EA_Controller {
*/
public function search()
{
try
{
if (cannot('view', PRIV_USERS))
{
try {
if (cannot('view', PRIV_USERS)) {
abort(403, 'Forbidden');
}
@ -115,9 +107,7 @@ class Secretaries extends EA_Controller {
$secretaries = $this->secretaries_model->search($keyword, $limit, $offset, $order_by);
json_response($secretaries);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -127,10 +117,8 @@ class Secretaries extends EA_Controller {
*/
public function store()
{
try
{
if (cannot('add', PRIV_USERS))
{
try {
if (cannot('add', PRIV_USERS)) {
abort(403, 'Forbidden');
}
@ -152,7 +140,7 @@ class Secretaries extends EA_Controller {
'is_private',
'id_roles',
'settings',
'providers',
'providers'
]);
$this->secretaries_model->only($secretary['settings'], [
@ -163,7 +151,7 @@ class Secretaries extends EA_Controller {
]);
$this->secretaries_model->optional($secretary, [
'providers' => [],
'providers' => []
]);
$secretary_id = $this->secretaries_model->save($secretary);
@ -173,12 +161,30 @@ class Secretaries extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_SECRETARY_SAVE, $secretary);
json_response([
'success' => TRUE,
'success' => true,
'id' => $secretary_id
]);
} catch (Throwable $e) {
json_exception($e);
}
catch (Throwable $e)
{
}
/**
* Find a secretary.
*/
public function find()
{
try {
if (cannot('view', PRIV_USERS)) {
abort(403, 'Forbidden');
}
$secretary_id = request('secretary_id');
$secretary = $this->secretaries_model->find($secretary_id);
json_response($secretary);
} catch (Throwable $e) {
json_exception($e);
}
}
@ -188,15 +194,13 @@ class Secretaries extends EA_Controller {
*/
public function update()
{
try
{
if (cannot('edit', PRIV_USERS))
{
try {
if (cannot('edit', PRIV_USERS)) {
abort(403, 'Forbidden');
}
$secretary = request('secretary');
$this->secretaries_model->only($secretary, [
'id',
'first_name',
@ -214,7 +218,7 @@ class Secretaries extends EA_Controller {
'is_private',
'id_roles',
'settings',
'providers',
'providers'
]);
$this->secretaries_model->only($secretary['settings'], [
@ -225,10 +229,9 @@ class Secretaries extends EA_Controller {
]);
$this->secretaries_model->optional($secretary, [
'providers' => [],
'providers' => []
]);
$secretary_id = $this->secretaries_model->save($secretary);
$secretary = $this->secretaries_model->find($secretary_id);
@ -236,12 +239,10 @@ class Secretaries extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_SECRETARY_SAVE, $secretary);
json_response([
'success' => TRUE,
'success' => true,
'id' => $secretary_id
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -251,10 +252,8 @@ class Secretaries extends EA_Controller {
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_USERS))
{
try {
if (cannot('delete', PRIV_USERS)) {
abort(403, 'Forbidden');
}
@ -267,35 +266,9 @@ class Secretaries extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_SECRETARY_DELETE, $secretary);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Find a secretary.
*/
public function find()
{
try
{
if (cannot('view', PRIV_USERS))
{
abort(403, 'Forbidden');
}
$secretary_id = request('secretary_id');
$secretary = $this->secretaries_model->find($secretary_id);
json_response($secretary);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Service_categories extends EA_Controller {
class Service_categories extends EA_Controller
{
/**
* Service-categories constructor.
*/
@ -46,10 +47,8 @@ class Service_categories extends EA_Controller {
$user_id = session('user_id');
if (cannot('view', PRIV_SERVICES))
{
if ($user_id)
{
if (cannot('view', PRIV_SERVICES)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -62,7 +61,7 @@ class Service_categories extends EA_Controller {
script_vars([
'user_id' => $user_id,
'role_slug' => $role_slug,
'role_slug' => $role_slug
]);
html_vars([
@ -70,7 +69,7 @@ class Service_categories extends EA_Controller {
'active_menu' => PRIV_SERVICES,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'timezones' => $this->timezones->to_array(),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug)
]);
$this->load->view('pages/service_categories');
@ -81,10 +80,8 @@ class Service_categories extends EA_Controller {
*/
public function search()
{
try
{
if (cannot('view', PRIV_SERVICES))
{
try {
if (cannot('view', PRIV_SERVICES)) {
abort(403, 'Forbidden');
}
@ -99,9 +96,7 @@ class Service_categories extends EA_Controller {
$service_categories = $this->service_categories_model->search($keyword, $limit, $offset, $order_by);
json_response($service_categories);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -111,19 +106,14 @@ class Service_categories extends EA_Controller {
*/
public function store()
{
try
{
if (cannot('add', PRIV_SERVICES))
{
try {
if (cannot('add', PRIV_SERVICES)) {
abort(403, 'Forbidden');
}
$service_category = request('service_category');
$this->service_categories_model->only($service_category, [
'name',
'description'
]);
$this->service_categories_model->only($service_category, ['name', 'description']);
$service_category_id = $this->service_categories_model->save($service_category);
@ -132,12 +122,30 @@ class Service_categories extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_SAVE, $service_category);
json_response([
'success' => TRUE,
'success' => true,
'id' => $service_category_id
]);
} catch (Throwable $e) {
json_exception($e);
}
catch (Throwable $e)
{
}
/**
* Find a service-category.
*/
public function find()
{
try {
if (cannot('view', PRIV_SERVICES)) {
abort(403, 'Forbidden');
}
$service_category_id = request('service_category_id');
$service_category = $this->service_categories_model->find($service_category_id);
json_response($service_category);
} catch (Throwable $e) {
json_exception($e);
}
}
@ -147,20 +155,14 @@ class Service_categories extends EA_Controller {
*/
public function update()
{
try
{
if (cannot('edit', PRIV_SERVICES))
{
try {
if (cannot('edit', PRIV_SERVICES)) {
abort(403, 'Forbidden');
}
$service_category = request('service_category');
$this->service_categories_model->only($service_category, [
'id',
'name',
'description'
]);
$this->service_categories_model->only($service_category, ['id', 'name', 'description']);
$service_category_id = $this->service_categories_model->save($service_category);
@ -169,12 +171,10 @@ class Service_categories extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_SAVE, $service_category);
json_response([
'success' => TRUE,
'success' => true,
'id' => $service_category_id
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -184,10 +184,8 @@ class Service_categories extends EA_Controller {
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_SERVICES))
{
try {
if (cannot('delete', PRIV_SERVICES)) {
abort(403, 'Forbidden');
}
@ -200,35 +198,9 @@ class Service_categories extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_DELETE, $service_category);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Find a service-category.
*/
public function find()
{
try
{
if (cannot('view', PRIV_SERVICES))
{
abort(403, 'Forbidden');
}
$service_category_id = request('service_category_id');
$service_category = $this->service_categories_model->find($service_category_id);
json_response($service_category);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Services extends EA_Controller {
class Services extends EA_Controller
{
/**
* Services constructor.
*/
@ -46,10 +47,8 @@ class Services extends EA_Controller {
$user_id = session('user_id');
if (cannot('view', PRIV_SERVICES))
{
if ($user_id)
{
if (cannot('view', PRIV_SERVICES)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -63,7 +62,7 @@ class Services extends EA_Controller {
script_vars([
'user_id' => $user_id,
'role_slug' => $role_slug,
'event_minimum_duration' => EVENT_MINIMUM_DURATION,
'event_minimum_duration' => EVENT_MINIMUM_DURATION
]);
html_vars([
@ -71,7 +70,7 @@ class Services extends EA_Controller {
'active_menu' => PRIV_SERVICES,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'timezones' => $this->timezones->to_array(),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug)
]);
$this->load->view('pages/services');
@ -82,10 +81,8 @@ class Services extends EA_Controller {
*/
public function search()
{
try
{
if (cannot('view', PRIV_SERVICES))
{
try {
if (cannot('view', PRIV_SERVICES)) {
abort(403, 'Forbidden');
}
@ -100,9 +97,7 @@ class Services extends EA_Controller {
$services = $this->services_model->search($keyword, $limit, $offset, $order_by);
json_response($services);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -112,10 +107,8 @@ class Services extends EA_Controller {
*/
public function store()
{
try
{
if (cannot('add', PRIV_SERVICES))
{
try {
if (cannot('add', PRIV_SERVICES)) {
abort(403, 'Forbidden');
}
@ -132,11 +125,11 @@ class Services extends EA_Controller {
'availabilities_type',
'attendants_number',
'is_private',
'id_service_categories',
'id_service_categories'
]);
$this->services_model->optional($service, [
'id_service_categories' => NULL
'id_service_categories' => null
]);
$service_id = $this->services_model->save($service);
@ -146,12 +139,30 @@ class Services extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_SERVICE_SAVE, $service);
json_response([
'success' => TRUE,
'success' => true,
'id' => $service_id
]);
} catch (Throwable $e) {
json_exception($e);
}
catch (Throwable $e)
{
}
/**
* Find a service.
*/
public function find()
{
try {
if (cannot('delete', PRIV_SERVICES)) {
abort(403, 'Forbidden');
}
$service_id = request('service_id');
$service = $this->services_model->find($service_id);
json_response($service);
} catch (Throwable $e) {
json_exception($e);
}
}
@ -161,10 +172,8 @@ class Services extends EA_Controller {
*/
public function update()
{
try
{
if (cannot('edit', PRIV_SERVICES))
{
try {
if (cannot('edit', PRIV_SERVICES)) {
abort(403, 'Forbidden');
}
@ -182,11 +191,11 @@ class Services extends EA_Controller {
'availabilities_type',
'attendants_number',
'is_private',
'id_service_categories',
'id_service_categories'
]);
$this->services_model->optional($service, [
'id_service_categories' => NULL
'id_service_categories' => null
]);
$service_id = $this->services_model->save($service);
@ -196,12 +205,10 @@ class Services extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_SERVICE_SAVE, $service);
json_response([
'success' => TRUE,
'success' => true,
'id' => $service_id
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -211,10 +218,8 @@ class Services extends EA_Controller {
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_SERVICES))
{
try {
if (cannot('delete', PRIV_SERVICES)) {
abort(403, 'Forbidden');
}
@ -227,35 +232,9 @@ class Services extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_SERVICE_DELETE, $service);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Find a service.
*/
public function find()
{
try
{
if (cannot('delete', PRIV_SERVICES))
{
abort(403, 'Forbidden');
}
$service_id = request('service_id');
$service = $this->services_model->find($service_id);
json_response($service);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -15,8 +15,7 @@
* This file can only be used in a testing environment and only from the termninal.
*/
if (ENVIRONMENT !== 'testing' || ! is_cli())
{
if (ENVIRONMENT !== 'testing' || !is_cli()) {
show_404();
}
@ -26,7 +25,8 @@ if (ENVIRONMENT !== 'testing' || ! is_cli())
* This controller does not have or need any logic, it is just used so that CI can be loaded properly during the test
* execution.
*/
class Test extends EA_Controller {
class Test extends EA_Controller
{
/**
* Placeholder callback.
*

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Unavailabilities extends EA_Controller {
class Unavailabilities extends EA_Controller
{
/**
* Unavailabilities constructor.
*/
@ -39,10 +40,8 @@ class Unavailabilities extends EA_Controller {
*/
public function search()
{
try
{
if (cannot('view', PRIV_APPOINTMENTS))
{
try {
if (cannot('view', PRIV_APPOINTMENTS)) {
abort(403, 'Forbidden');
}
@ -57,9 +56,7 @@ class Unavailabilities extends EA_Controller {
$unavailabilities = $this->unavailabilities_model->search($keyword, $limit, $offset, $order_by);
json_response($unavailabilities);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -69,10 +66,8 @@ class Unavailabilities extends EA_Controller {
*/
public function store()
{
try
{
if (cannot('add', PRIV_APPOINTMENTS))
{
try {
if (cannot('add', PRIV_APPOINTMENTS)) {
abort(403, 'Forbidden');
}
@ -89,7 +84,7 @@ class Unavailabilities extends EA_Controller {
'zip_code',
'notes',
'timezone',
'language',
'language'
]);
$unavailability_id = $this->unavailabilities_model->save($unavailability);
@ -103,12 +98,30 @@ class Unavailabilities extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_UNAVAILABILITY_SAVE, $unavailability);
json_response([
'success' => TRUE,
'success' => true,
'id' => $unavailability_id
]);
} catch (Throwable $e) {
json_exception($e);
}
catch (Throwable $e)
{
}
/**
* Find an unavailability.
*/
public function find()
{
try {
if (cannot('view', PRIV_APPOINTMENTS)) {
abort(403, 'Forbidden');
}
$unavailability_id = request('unavailability_id');
$unavailability = $this->unavailabilities_model->find($unavailability_id);
json_response($unavailability);
} catch (Throwable $e) {
json_exception($e);
}
}
@ -118,10 +131,8 @@ class Unavailabilities extends EA_Controller {
*/
public function update()
{
try
{
if (cannot('edit', PRIV_APPOINTMENTS))
{
try {
if (cannot('edit', PRIV_APPOINTMENTS)) {
abort(403, 'Forbidden');
}
@ -138,12 +149,10 @@ class Unavailabilities extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_UNAVAILABILITY_SAVE, $unavailability);
json_response([
'success' => TRUE,
'success' => true,
'id' => $unavailability_id
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -153,10 +162,8 @@ class Unavailabilities extends EA_Controller {
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_APPOINTMENTS))
{
try {
if (cannot('delete', PRIV_APPOINTMENTS)) {
abort(403, 'Forbidden');
}
@ -169,35 +176,9 @@ class Unavailabilities extends EA_Controller {
$this->webhooks_client->trigger(WEBHOOK_UNAVAILABILITY_DELETE, $unavailability);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Find an unavailability.
*/
public function find()
{
try
{
if (cannot('view', PRIV_APPOINTMENTS))
{
abort(403, 'Forbidden');
}
$unavailability_id = request('unavailability_id');
$unavailability = $this->unavailabilities_model->find($unavailability_id);
json_response($unavailability);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -18,20 +18,21 @@
*
* @package Controllers
*/
class Update extends EA_Controller {
class Update extends EA_Controller
{
/**
* Update constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->model('admins_model');
$this->load->model('settings_model');
$this->load->model('services_model');
$this->load->model('providers_model');
$this->load->model('customers_model');
$this->load->library('instance');
}
@ -46,14 +47,11 @@ class Update extends EA_Controller {
*/
public function index()
{
try
{
try {
$user_id = session('user_id');
if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{
if ($user_id)
{
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -64,11 +62,9 @@ class Update extends EA_Controller {
$this->instance->migrate();
$view = ['success' => TRUE];
}
catch (Throwable $e)
{
$view = ['success' => FALSE, 'exception' => $e->getMessage()];
$view = ['success' => true];
} catch (Throwable $e) {
$view = ['success' => false, 'exception' => $e->getMessage()];
}
html_vars($view);

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class User extends EA_Controller {
class User extends EA_Controller
{
/**
* User constructor.
*/
@ -40,7 +41,7 @@ class User extends EA_Controller {
/**
* Display the login page.
*
*
* @deprecated Since 1.5 Use the Login controller instead.
*/
public function login()
@ -50,17 +51,17 @@ class User extends EA_Controller {
/**
* Display the logout page.
*
*
* @deprecated Since 1.5 Use the Logout controller instead.
*/
public function logout()
{
redirect('logout');
redirect('logout');
}
/**
* Display the password recovery page.
*
*
* @deprecated Since 1.5 Use the Logout controller instead.
*/
public function forgot_password()

View file

@ -18,7 +18,8 @@
*
* @package Controllers
*/
class Webhooks extends EA_Controller {
class Webhooks extends EA_Controller
{
/**
* Webhooks constructor.
*/
@ -45,10 +46,8 @@ class Webhooks extends EA_Controller {
$user_id = session('user_id');
if (cannot('view', PRIV_WEBHOOKS))
{
if ($user_id)
{
if (cannot('view', PRIV_WEBHOOKS)) {
if ($user_id) {
abort(403, 'Forbidden');
}
@ -61,7 +60,7 @@ class Webhooks extends EA_Controller {
script_vars([
'user_id' => $user_id,
'role_slug' => $role_slug,
'role_slug' => $role_slug
]);
html_vars([
@ -100,10 +99,8 @@ class Webhooks extends EA_Controller {
*/
public function search()
{
try
{
if (cannot('view', PRIV_WEBHOOKS))
{
try {
if (cannot('view', PRIV_WEBHOOKS)) {
abort(403, 'Forbidden');
}
@ -118,9 +115,7 @@ class Webhooks extends EA_Controller {
$webhooks = $this->webhooks_model->search($keyword, $limit, $offset, $order_by);
json_response($webhooks);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -130,10 +125,8 @@ class Webhooks extends EA_Controller {
*/
public function store()
{
try
{
if (cannot('add', PRIV_WEBHOOKS))
{
try {
if (cannot('add', PRIV_WEBHOOKS)) {
abort(403, 'Forbidden');
}
@ -145,18 +138,16 @@ class Webhooks extends EA_Controller {
'actions',
'secret_token',
'is_ssl_verified',
'notes',
'notes'
]);
$webhook_id = $this->webhooks_model->save($webhook);
json_response([
'success' => TRUE,
'success' => true,
'id' => $webhook_id
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -166,10 +157,8 @@ class Webhooks extends EA_Controller {
*/
public function update()
{
try
{
if (cannot('edit', PRIV_WEBHOOKS))
{
try {
if (cannot('edit', PRIV_WEBHOOKS)) {
abort(403, 'Forbidden');
}
@ -182,18 +171,16 @@ class Webhooks extends EA_Controller {
'actions',
'secret_token',
'is_ssl_verified',
'notes',
'notes'
]);
$webhook_id = $this->webhooks_model->save($webhook);
json_response([
'success' => TRUE,
'success' => true,
'id' => $webhook_id
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -203,10 +190,8 @@ class Webhooks extends EA_Controller {
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_WEBHOOKS))
{
try {
if (cannot('delete', PRIV_WEBHOOKS)) {
abort(403, 'Forbidden');
}
@ -215,11 +200,9 @@ class Webhooks extends EA_Controller {
$this->webhooks_model->delete($webhook_id);
json_response([
'success' => TRUE,
'success' => true
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -229,10 +212,8 @@ class Webhooks extends EA_Controller {
*/
public function find()
{
try
{
if (cannot('view', PRIV_WEBHOOKS))
{
try {
if (cannot('view', PRIV_WEBHOOKS)) {
abort(403, 'Forbidden');
}
@ -241,9 +222,7 @@ class Webhooks extends EA_Controller {
$webhook = $this->webhooks_model->find($webhook_id);
json_response($webhook);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -16,7 +16,8 @@
*
* @package Controllers
*/
class Admins_api_v1 extends EA_Controller {
class Admins_api_v1 extends EA_Controller
{
/**
* Admins_api_v1 constructor.
*/
@ -38,8 +39,7 @@ class Admins_api_v1 extends EA_Controller {
*/
public function index()
{
try
{
try {
$keyword = $this->api->request_keyword();
$limit = $this->api->request_limit();
@ -53,28 +53,23 @@ class Admins_api_v1 extends EA_Controller {
$with = $this->api->request_with();
$admins = empty($keyword)
? $this->admins_model->get(NULL, $limit, $offset, $order_by)
? $this->admins_model->get(null, $limit, $offset, $order_by)
: $this->admins_model->search($keyword, $limit, $offset, $order_by);
foreach ($admins as &$admin)
{
foreach ($admins as &$admin) {
$this->admins_model->api_encode($admin);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->admins_model->only($admin, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->admins_model->load($admin, $with);
}
}
json_response($admins);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -84,10 +79,9 @@ class Admins_api_v1 extends EA_Controller {
*
* @param int|null $id Admin ID.
*/
public function show(int $id = NULL)
public function show(int $id = null)
{
try
{
try {
$fields = $this->api->request_fields();
$with = $this->api->request_with();
@ -96,27 +90,22 @@ class Admins_api_v1 extends EA_Controller {
$this->admins_model->api_encode($admin);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->admins_model->only($admin, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->admins_model->load($admin, $with);
}
if ( ! $admin)
{
if (!$admin) {
response('', 404);
return;
}
json_response($admin);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -126,19 +115,16 @@ class Admins_api_v1 extends EA_Controller {
*/
public function store()
{
try
{
try {
$admin = request();
$this->admins_model->api_decode($admin);
if (array_key_exists('id', $admin))
{
if (array_key_exists('id', $admin)) {
unset($admin['id']);
}
if ( ! array_key_exists('settings', $admin))
{
if (!array_key_exists('settings', $admin)) {
throw new InvalidArgumentException('No settings property provided.');
}
@ -149,9 +135,7 @@ class Admins_api_v1 extends EA_Controller {
$this->admins_model->api_encode($created_admin);
json_response($created_admin, 201);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -163,12 +147,10 @@ class Admins_api_v1 extends EA_Controller {
*/
public function update(int $id)
{
try
{
try {
$occurrences = $this->admins_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -187,9 +169,7 @@ class Admins_api_v1 extends EA_Controller {
$this->admins_model->api_encode($updated_admin);
json_response($updated_admin);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -201,12 +181,10 @@ class Admins_api_v1 extends EA_Controller {
*/
public function destroy(int $id)
{
try
{
try {
$occurrences = $this->admins_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -215,9 +193,7 @@ class Admins_api_v1 extends EA_Controller {
$this->admins_model->delete($id);
response('', 204);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -16,7 +16,8 @@
*
* @package Controllers
*/
class Appointments_api_v1 extends EA_Controller {
class Appointments_api_v1 extends EA_Controller
{
/**
* Appointments_api_v1 constructor.
*/
@ -44,8 +45,7 @@ class Appointments_api_v1 extends EA_Controller {
*/
public function index()
{
try
{
try {
$keyword = $this->api->request_keyword();
$limit = $this->api->request_limit();
@ -58,14 +58,13 @@ class Appointments_api_v1 extends EA_Controller {
$with = $this->api->request_with();
$where = NULL;
$where = null;
// Date query param.
$date = request('date');
if ( ! empty($date))
{
if (!empty($date)) {
$where['DATE(start_datetime)'] = (new DateTime($date))->format('Y-m-d');
}
@ -73,8 +72,7 @@ class Appointments_api_v1 extends EA_Controller {
$from = request('from');
if ( ! empty($from))
{
if (!empty($from)) {
$where['DATE(start_datetime) >='] = (new DateTime($from))->format('Y-m-d');
}
@ -82,8 +80,7 @@ class Appointments_api_v1 extends EA_Controller {
$till = request('till');
if ( ! empty($till))
{
if (!empty($till)) {
$where['DATE(end_datetime) <='] = (new DateTime($till))->format('Y-m-d');
}
@ -91,8 +88,7 @@ class Appointments_api_v1 extends EA_Controller {
$service_id = request('serviceId');
if ( ! empty($service_id))
{
if (!empty($service_id)) {
$where['id_services'] = $service_id;
}
@ -100,8 +96,7 @@ class Appointments_api_v1 extends EA_Controller {
$provider_id = request('providerId');
if ( ! empty($provider_id))
{
if (!empty($provider_id)) {
$where['id_users_provider'] = $provider_id;
}
@ -109,8 +104,7 @@ class Appointments_api_v1 extends EA_Controller {
$customer_id = request('customerId');
if ( ! empty($customer_id))
{
if (!empty($customer_id)) {
$where['id_users_customer'] = $customer_id;
}
@ -118,40 +112,68 @@ class Appointments_api_v1 extends EA_Controller {
? $this->appointments_model->get($where, $limit, $offset, $order_by)
: $this->appointments_model->search($keyword, $limit, $offset, $order_by);
foreach ($appointments as &$appointment)
{
foreach ($appointments as &$appointment) {
$this->appointments_model->api_encode($appointment);
$this->aggregates($appointment);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->appointments_model->only($appointment, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->appointments_model->load($appointment, $with);
}
}
json_response($appointments);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Load the relations of the current appointment if the "aggregates" query parameter is present.
*
* This is a compatibility addition to the appointment resource which was the only one to support it.
*
* Use the "attach" query parameter instead as this one will be removed.
*
* @param array $appointment Appointment data.
*
* @deprecated Since 1.5
*/
private function aggregates(array &$appointment)
{
$aggregates = request('aggregates') !== null;
if ($aggregates) {
$appointment['service'] = $this->services_model->find(
$appointment['id_services'] ?? ($appointment['serviceId'] ?? null),
true
);
$appointment['provider'] = $this->providers_model->find(
$appointment['id_users_provider'] ?? ($appointment['providerId'] ?? null),
true
);
$appointment['customer'] = $this->customers_model->find(
$appointment['id_users_customer'] ?? ($appointment['customerId'] ?? null),
true
);
$this->services_model->api_encode($appointment['service']);
$this->providers_model->api_encode($appointment['provider']);
$this->customers_model->api_encode($appointment['customer']);
}
}
/**
* Get a single appointment.
*
* @param int|null $id Appointment ID.
*/
public function show(int $id = NULL)
public function show(int $id = null)
{
try
{
try {
$fields = $this->api->request_fields();
$with = $this->api->request_with();
@ -160,27 +182,22 @@ class Appointments_api_v1 extends EA_Controller {
$this->appointments_model->api_encode($appointment);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->appointments_model->only($appointment, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->appointments_model->load($appointment, $with);
}
if ( ! $appointment)
{
if (!$appointment) {
response('Not Found', 404);
return;
}
json_response($appointment);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -190,19 +207,16 @@ class Appointments_api_v1 extends EA_Controller {
*/
public function store()
{
try
{
try {
$appointment = request();
$this->appointments_model->api_decode($appointment);
if (array_key_exists('id', $appointment))
{
if (array_key_exists('id', $appointment)) {
unset($appointment['id']);
}
if ( ! array_key_exists('end_datetime', $appointment))
{
if (!array_key_exists('end_datetime', $appointment)) {
$appointment['end_datetime'] = $this->calculate_end_datetime($appointment);
}
@ -215,130 +229,11 @@ class Appointments_api_v1 extends EA_Controller {
$this->appointments_model->api_encode($created_appointment);
json_response($created_appointment, 201);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Update an appointment.
*
* @param int $id Appointment ID.
*/
public function update(int $id)
{
try
{
$occurrences = $this->appointments_model->get(['id' => $id]);
if (empty($occurrences))
{
response('', 404);
return;
}
$original_appointment = $occurrences[0];
$appointment = request();
$this->appointments_model->api_decode($appointment, $original_appointment);
$appointment_id = $this->appointments_model->save($appointment);
$updated_appointment = $this->appointments_model->find($appointment_id);
$this->notify_and_sync_appointment($updated_appointment, 'update');
$this->appointments_model->api_encode($updated_appointment);
json_response($updated_appointment);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Delete an appointment.
*
* @param int $id Appointment ID.
*/
public function destroy(int $id)
{
try
{
$occurrences = $this->appointments_model->get(['id' => $id]);
if (empty($occurrences))
{
response('', 404);
return;
}
$deleted_appointment = $occurrences[0];
$service = $this->services_model->find($deleted_appointment['id_services'], TRUE);
$provider = $this->providers_model->find($deleted_appointment['id_users_provider'], TRUE);
$customer = $this->customers_model->find($deleted_appointment['id_users_customer'], TRUE);
$settings = [
'company_name' => setting('company_name'),
'company_email' => setting('company_email'),
'company_link' => setting('company_link'),
'date_format' => setting('date_format'),
'time_format' => setting('time_format')
];
$this->appointments_model->delete($id);
$this->synchronization->sync_appointment_deleted($deleted_appointment, $provider);
$this->notifications->notify_appointment_deleted($deleted_appointment, $service, $provider, $customer, $settings);
response('', 204);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Send the required notifications and trigger syncing after saving an appointment.
*
* @param array $appointment Appointment data.
* @param string $action Performed action ("store" or "update").
*/
private function notify_and_sync_appointment(array $appointment, string $action = 'store')
{
$manage_mode = $action === 'update';
$service = $this->services_model->find($appointment['id_services'], TRUE);
$provider = $this->providers_model->find($appointment['id_users_provider'], TRUE);
$customer = $this->customers_model->find($appointment['id_users_customer'], TRUE);
$settings = [
'company_name' => setting('company_name'),
'company_email' => setting('company_email'),
'company_link' => setting('company_link'),
'date_format' => setting('date_format'),
'time_format' => setting('time_format')
];
$this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings);
$this->notifications->notify_appointment_saved($appointment, $service, $provider, $customer, $settings, $manage_mode);
}
/**
* Calculate the end date time of an appointment based on the selected service.
*
@ -360,28 +255,124 @@ class Appointments_api_v1 extends EA_Controller {
}
/**
* Load the relations of the current appointment if the "aggregates" query parameter is present.
*
* This is a compatibility addition to the appointment resource which was the only one to support it.
*
* Use the "attach" query parameter instead as this one will be removed.
* Send the required notifications and trigger syncing after saving an appointment.
*
* @param array $appointment Appointment data.
*
* @deprecated Since 1.5
* @param string $action Performed action ("store" or "update").
*/
private function aggregates(array &$appointment)
private function notify_and_sync_appointment(array $appointment, string $action = 'store')
{
$aggregates = request('aggregates') !== NULL;
$manage_mode = $action === 'update';
if ($aggregates)
{
$appointment['service'] = $this->services_model->find($appointment['id_services'] ?? $appointment['serviceId'] ?? NULL, TRUE);
$appointment['provider'] = $this->providers_model->find($appointment['id_users_provider'] ?? $appointment['providerId'] ?? NULL, TRUE);
$appointment['customer'] = $this->customers_model->find($appointment['id_users_customer'] ?? $appointment['customerId'] ?? NULL, TRUE);
$this->services_model->api_encode($appointment['service']);
$this->providers_model->api_encode($appointment['provider']);
$this->customers_model->api_encode($appointment['customer']);
$service = $this->services_model->find($appointment['id_services'], true);
$provider = $this->providers_model->find($appointment['id_users_provider'], true);
$customer = $this->customers_model->find($appointment['id_users_customer'], true);
$settings = [
'company_name' => setting('company_name'),
'company_email' => setting('company_email'),
'company_link' => setting('company_link'),
'date_format' => setting('date_format'),
'time_format' => setting('time_format')
];
$this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings);
$this->notifications->notify_appointment_saved(
$appointment,
$service,
$provider,
$customer,
$settings,
$manage_mode
);
}
/**
* Update an appointment.
*
* @param int $id Appointment ID.
*/
public function update(int $id)
{
try {
$occurrences = $this->appointments_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$original_appointment = $occurrences[0];
$appointment = request();
$this->appointments_model->api_decode($appointment, $original_appointment);
$appointment_id = $this->appointments_model->save($appointment);
$updated_appointment = $this->appointments_model->find($appointment_id);
$this->notify_and_sync_appointment($updated_appointment, 'update');
$this->appointments_model->api_encode($updated_appointment);
json_response($updated_appointment);
} catch (Throwable $e) {
json_exception($e);
}
}
/**
* Delete an appointment.
*
* @param int $id Appointment ID.
*/
public function destroy(int $id)
{
try {
$occurrences = $this->appointments_model->get(['id' => $id]);
if (empty($occurrences)) {
response('', 404);
return;
}
$deleted_appointment = $occurrences[0];
$service = $this->services_model->find($deleted_appointment['id_services'], true);
$provider = $this->providers_model->find($deleted_appointment['id_users_provider'], true);
$customer = $this->customers_model->find($deleted_appointment['id_users_customer'], true);
$settings = [
'company_name' => setting('company_name'),
'company_email' => setting('company_email'),
'company_link' => setting('company_link'),
'date_format' => setting('date_format'),
'time_format' => setting('time_format')
];
$this->appointments_model->delete($id);
$this->synchronization->sync_appointment_deleted($deleted_appointment, $provider);
$this->notifications->notify_appointment_deleted(
$deleted_appointment,
$service,
$provider,
$customer,
$settings
);
response('', 204);
} catch (Throwable $e) {
json_exception($e);
}
}
}

View file

@ -16,7 +16,8 @@
*
* @package Controllers
*/
class Availabilities_api_v1 extends EA_Controller {
class Availabilities_api_v1 extends EA_Controller
{
/**
* Availabilities_api_v1 constructor.
*/
@ -27,7 +28,7 @@ class Availabilities_api_v1 extends EA_Controller {
$this->load->library('api');
$this->api->auth();
$this->load->model('appointments_model');
$this->load->model('providers_model');
$this->load->model('services_model');
@ -55,16 +56,14 @@ class Availabilities_api_v1 extends EA_Controller {
*/
public function get()
{
try
{
try {
$provider_id = request('providerId');
$service_id = request('serviceId');
$date = request('date');
if ( ! $date)
{
if (!$date) {
$date = date('Y-m-d');
}
@ -75,9 +74,7 @@ class Availabilities_api_v1 extends EA_Controller {
$available_hours = $this->availability->get_available_hours($date, $service, $provider);
json_response($available_hours);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -16,7 +16,8 @@
*
* @package Controllers
*/
class Customers_api_v1 extends EA_Controller {
class Customers_api_v1 extends EA_Controller
{
/**
* Customers_api_v1 constructor.
*/
@ -36,8 +37,7 @@ class Customers_api_v1 extends EA_Controller {
*/
public function index()
{
try
{
try {
$keyword = $this->api->request_keyword();
$limit = $this->api->request_limit();
@ -51,28 +51,23 @@ class Customers_api_v1 extends EA_Controller {
$with = $this->api->request_with();
$customers = empty($keyword)
? $this->customers_model->get(NULL, $limit, $offset, $order_by)
? $this->customers_model->get(null, $limit, $offset, $order_by)
: $this->customers_model->search($keyword, $limit, $offset, $order_by);
foreach ($customers as &$customer)
{
foreach ($customers as &$customer) {
$this->customers_model->api_encode($customer);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->customers_model->only($customer, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->customers_model->load($customer, $with);
}
}
json_response($customers);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -82,32 +77,27 @@ class Customers_api_v1 extends EA_Controller {
*
* @param int|null $id Customer ID.
*/
public function show(int $id = NULL)
public function show(int $id = null)
{
try
{
try {
$fields = $this->api->request_fields();
$customer = $this->customers_model->find($id);
$this->customers_model->api_encode($customer);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->customers_model->only($customer, $fields);
}
if ( ! $customer)
{
if (!$customer) {
response('', 404);
return;
}
json_response($customer);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -117,14 +107,12 @@ class Customers_api_v1 extends EA_Controller {
*/
public function store()
{
try
{
try {
$customer = request();
$this->customers_model->api_decode($customer);
if (array_key_exists('id', $customer))
{
if (array_key_exists('id', $customer)) {
unset($customer['id']);
}
@ -135,9 +123,7 @@ class Customers_api_v1 extends EA_Controller {
$this->customers_model->api_encode($created_customer);
json_response($created_customer, 201);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -149,12 +135,10 @@ class Customers_api_v1 extends EA_Controller {
*/
public function update(int $id)
{
try
{
try {
$occurrences = $this->customers_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -173,9 +157,7 @@ class Customers_api_v1 extends EA_Controller {
$this->customers_model->api_encode($updated_customer);
json_response($updated_customer);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -187,12 +169,10 @@ class Customers_api_v1 extends EA_Controller {
*/
public function destroy(int $id)
{
try
{
try {
$occurrences = $this->customers_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -201,9 +181,7 @@ class Customers_api_v1 extends EA_Controller {
$this->customers_model->delete($id);
response('', 204);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -16,7 +16,8 @@
*
* @package Controllers
*/
class Providers_api_v1 extends EA_Controller {
class Providers_api_v1 extends EA_Controller
{
/**
* Providers_api_v1 constructor.
*/
@ -36,8 +37,7 @@ class Providers_api_v1 extends EA_Controller {
*/
public function index()
{
try
{
try {
$keyword = $this->api->request_keyword();
$limit = $this->api->request_limit();
@ -47,32 +47,27 @@ class Providers_api_v1 extends EA_Controller {
$order_by = $this->api->request_order_by();
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$providers = empty($keyword)
? $this->providers_model->get(NULL, $limit, $offset, $order_by)
? $this->providers_model->get(null, $limit, $offset, $order_by)
: $this->providers_model->search($keyword, $limit, $offset, $order_by);
foreach ($providers as &$provider)
{
foreach ($providers as &$provider) {
$this->providers_model->api_encode($provider);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->providers_model->only($provider, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->providers_model->load($provider, $with);
}
}
json_response($providers);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -82,39 +77,33 @@ class Providers_api_v1 extends EA_Controller {
*
* @param int|null $id Provider ID.
*/
public function show(int $id = NULL)
public function show(int $id = null)
{
try
{
try {
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$provider = $this->providers_model->find($id);
$this->providers_model->api_encode($provider);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->providers_model->only($provider, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->providers_model->load($provider, $with);
}
if ( ! $provider)
{
if (!$provider) {
response('', 404);
return;
}
json_response($provider);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -124,29 +113,24 @@ class Providers_api_v1 extends EA_Controller {
*/
public function store()
{
try
{
try {
$provider = request();
$this->providers_model->api_decode($provider);
if (array_key_exists('id', $provider))
{
if (array_key_exists('id', $provider)) {
unset($provider['id']);
}
if ( ! array_key_exists('services', $provider))
{
if (!array_key_exists('services', $provider)) {
throw new InvalidArgumentException('No services property provided.');
}
if ( ! array_key_exists('settings', $provider))
{
if (!array_key_exists('settings', $provider)) {
throw new InvalidArgumentException('No settings property provided.');
}
if ( ! array_key_exists('working_plan', $provider['settings']))
{
if (!array_key_exists('working_plan', $provider['settings'])) {
$provider['settings']['working_plan'] = setting('company_working_plan');
}
@ -157,9 +141,7 @@ class Providers_api_v1 extends EA_Controller {
$this->providers_model->api_encode($created_provider);
json_response($created_provider, 201);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -171,12 +153,10 @@ class Providers_api_v1 extends EA_Controller {
*/
public function update(int $id)
{
try
{
try {
$occurrences = $this->providers_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -195,9 +175,7 @@ class Providers_api_v1 extends EA_Controller {
$this->providers_model->api_encode($updated_provider);
json_response($updated_provider);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -209,12 +187,10 @@ class Providers_api_v1 extends EA_Controller {
*/
public function destroy(int $id)
{
try
{
try {
$occurrences = $this->providers_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -223,9 +199,7 @@ class Providers_api_v1 extends EA_Controller {
$this->providers_model->delete($id);
response('', 204);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -16,7 +16,8 @@
*
* @package Controllers
*/
class Secretaries_api_v1 extends EA_Controller {
class Secretaries_api_v1 extends EA_Controller
{
/**
* Secretaries_api_v1 constructor.
*/
@ -36,8 +37,7 @@ class Secretaries_api_v1 extends EA_Controller {
*/
public function index()
{
try
{
try {
$keyword = $this->api->request_keyword();
$limit = $this->api->request_limit();
@ -51,28 +51,23 @@ class Secretaries_api_v1 extends EA_Controller {
$with = $this->api->request_with();
$secretaries = empty($keyword)
? $this->secretaries_model->get(NULL, $limit, $offset, $order_by)
? $this->secretaries_model->get(null, $limit, $offset, $order_by)
: $this->secretaries_model->search($keyword, $limit, $offset, $order_by);
foreach ($secretaries as &$secretary)
{
foreach ($secretaries as &$secretary) {
$this->secretaries_model->api_encode($secretary);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->secretaries_model->only($secretary, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->secretaries_model->load($secretary, $with);
}
}
json_response($secretaries);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -82,32 +77,27 @@ class Secretaries_api_v1 extends EA_Controller {
*
* @param int|null $id Secretary ID.
*/
public function show(int $id = NULL)
public function show(int $id = null)
{
try
{
try {
$fields = $this->api->request_fields();
$secretary = $this->secretaries_model->find($id);
$this->secretaries_model->api_encode($secretary);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->secretaries_model->only($secretary, $fields);
}
if ( ! $secretary)
{
if (!$secretary) {
response('', 404);
return;
}
json_response($secretary);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -117,24 +107,20 @@ class Secretaries_api_v1 extends EA_Controller {
*/
public function store()
{
try
{
try {
$secretary = request();
$this->secretaries_model->api_decode($secretary);
if (array_key_exists('id', $secretary))
{
if (array_key_exists('id', $secretary)) {
unset($secretary['id']);
}
if ( ! array_key_exists('providers', $secretary))
{
if (!array_key_exists('providers', $secretary)) {
throw new InvalidArgumentException('No providers property provided.');
}
if ( ! array_key_exists('settings', $secretary))
{
if (!array_key_exists('settings', $secretary)) {
throw new InvalidArgumentException('No settings property provided.');
}
@ -145,9 +131,7 @@ class Secretaries_api_v1 extends EA_Controller {
$this->secretaries_model->api_encode($created_secretary);
json_response($created_secretary, 201);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -159,12 +143,10 @@ class Secretaries_api_v1 extends EA_Controller {
*/
public function update(int $id)
{
try
{
try {
$occurrences = $this->secretaries_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -183,9 +165,7 @@ class Secretaries_api_v1 extends EA_Controller {
$this->secretaries_model->api_encode($updated_secretary);
json_response($updated_secretary);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -197,12 +177,10 @@ class Secretaries_api_v1 extends EA_Controller {
*/
public function destroy(int $id)
{
try
{
try {
$occurrences = $this->secretaries_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -211,9 +189,7 @@ class Secretaries_api_v1 extends EA_Controller {
$this->secretaries_model->delete($id);
response('', 204);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -16,7 +16,8 @@
*
* @package Controllers
*/
class Service_categories_api_v1 extends EA_Controller {
class Service_categories_api_v1 extends EA_Controller
{
/**
* Service_categories_api_v1 constructor.
*/
@ -36,8 +37,7 @@ class Service_categories_api_v1 extends EA_Controller {
*/
public function index()
{
try
{
try {
$keyword = $this->api->request_keyword();
$limit = $this->api->request_limit();
@ -47,32 +47,27 @@ class Service_categories_api_v1 extends EA_Controller {
$order_by = $this->api->request_order_by();
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$service_categories = empty($keyword)
? $this->service_categories_model->get(NULL, $limit, $offset, $order_by)
? $this->service_categories_model->get(null, $limit, $offset, $order_by)
: $this->service_categories_model->search($keyword, $limit, $offset, $order_by);
foreach ($service_categories as &$service_category)
{
foreach ($service_categories as &$service_category) {
$this->service_categories_model->api_encode($service_category);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->service_categories_model->only($service_category, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->service_categories_model->load($service_category, $with);
}
}
json_response($service_categories);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -82,39 +77,33 @@ class Service_categories_api_v1 extends EA_Controller {
*
* @param int|null $id Service-category ID.
*/
public function show(int $id = NULL)
public function show(int $id = null)
{
try
{
try {
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$service_category = $this->service_categories_model->find($id);
$this->service_categories_model->api_encode($service_category);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->service_categories_model->only($service_category, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->service_categories_model->load($service_category, $with);
}
if ( ! $service_category)
{
if (!$service_category) {
response('', 404);
return;
}
json_response($service_category);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -124,14 +113,12 @@ class Service_categories_api_v1 extends EA_Controller {
*/
public function store()
{
try
{
try {
$service_category = request();
$this->service_categories_model->api_decode($service_category);
if (array_key_exists('id', $service_category))
{
if (array_key_exists('id', $service_category)) {
unset($service_category['id']);
}
@ -142,9 +129,7 @@ class Service_categories_api_v1 extends EA_Controller {
$this->service_categories_model->api_encode($created_service_category);
json_response($created_service_category, 201);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -156,12 +141,10 @@ class Service_categories_api_v1 extends EA_Controller {
*/
public function update(int $id)
{
try
{
try {
$occurrences = $this->service_categories_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -180,9 +163,7 @@ class Service_categories_api_v1 extends EA_Controller {
$this->service_categories_model->api_encode($updated_service_category);
json_response($updated_service_category);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -194,12 +175,10 @@ class Service_categories_api_v1 extends EA_Controller {
*/
public function destroy(int $id)
{
try
{
try {
$occurrences = $this->service_categories_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -208,9 +187,7 @@ class Service_categories_api_v1 extends EA_Controller {
$this->service_categories_model->delete($id);
response('', 204);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -16,7 +16,8 @@
*
* @package Controllers
*/
class Services_api_v1 extends EA_Controller {
class Services_api_v1 extends EA_Controller
{
/**
* Services_api_v1 constructor.
*/
@ -36,8 +37,7 @@ class Services_api_v1 extends EA_Controller {
*/
public function index()
{
try
{
try {
$keyword = $this->api->request_keyword();
$limit = $this->api->request_limit();
@ -47,32 +47,27 @@ class Services_api_v1 extends EA_Controller {
$order_by = $this->api->request_order_by();
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$services = empty($keyword)
? $this->services_model->get(NULL, $limit, $offset, $order_by)
? $this->services_model->get(null, $limit, $offset, $order_by)
: $this->services_model->search($keyword, $limit, $offset, $order_by);
foreach ($services as &$service)
{
foreach ($services as &$service) {
$this->services_model->api_encode($service);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->services_model->only($service, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->services_model->load($service, $with);
}
}
json_response($services);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -82,39 +77,33 @@ class Services_api_v1 extends EA_Controller {
*
* @param int|null $id Service ID.
*/
public function show(int $id = NULL)
public function show(int $id = null)
{
try
{
try {
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$service = $this->services_model->find($id);
$this->services_model->api_encode($service);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->services_model->only($service, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->services_model->load($service, $with);
}
if ( ! $service)
{
if (!$service) {
response('', 404);
return;
}
json_response($service);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -124,14 +113,12 @@ class Services_api_v1 extends EA_Controller {
*/
public function store()
{
try
{
try {
$service = request();
$this->services_model->api_decode($service);
if (array_key_exists('id', $service))
{
if (array_key_exists('id', $service)) {
unset($service['id']);
}
@ -142,9 +129,7 @@ class Services_api_v1 extends EA_Controller {
$this->services_model->api_encode($created_service);
json_response($created_service, 201);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -156,12 +141,10 @@ class Services_api_v1 extends EA_Controller {
*/
public function update(int $id)
{
try
{
try {
$occurrences = $this->services_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -180,9 +163,7 @@ class Services_api_v1 extends EA_Controller {
$this->services_model->api_encode($updated_service);
json_response($updated_service);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -194,12 +175,10 @@ class Services_api_v1 extends EA_Controller {
*/
public function destroy(int $id)
{
try
{
try {
$occurrences = $this->services_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -208,9 +187,7 @@ class Services_api_v1 extends EA_Controller {
$this->services_model->delete($id);
response('', 204);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -16,7 +16,8 @@
*
* @package Controllers
*/
class Settings_api_v1 extends EA_Controller {
class Settings_api_v1 extends EA_Controller
{
/**
* Settings_api_v1 constructor.
*/
@ -36,8 +37,7 @@ class Settings_api_v1 extends EA_Controller {
*/
public function index()
{
try
{
try {
$keyword = $this->api->request_keyword();
$limit = $this->api->request_limit();
@ -49,23 +49,19 @@ class Settings_api_v1 extends EA_Controller {
$fields = $this->api->request_fields();
$settings = empty($keyword)
? $this->settings_model->get(NULL, $limit, $offset, $order_by)
? $this->settings_model->get(null, $limit, $offset, $order_by)
: $this->settings_model->search($keyword, $limit, $offset, $order_by);
foreach ($settings as &$setting)
{
foreach ($settings as &$setting) {
$this->settings_model->api_encode($setting);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->settings_model->only($setting, $fields);
}
}
json_response($settings);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -77,17 +73,14 @@ class Settings_api_v1 extends EA_Controller {
*/
public function show(string $name)
{
try
{
try {
$value = setting($name);
json_response([
'name' => $name,
'value' => $value,
'value' => $value
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -99,19 +92,16 @@ class Settings_api_v1 extends EA_Controller {
*/
public function update(string $name)
{
try
{
try {
$value = request('value');
setting([$name => $value]);
json_response([
'name' => $name,
'value' => $value,
'value' => $value
]);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -16,7 +16,8 @@
*
* @package Controllers
*/
class Unavailabilities_api_v1 extends EA_Controller {
class Unavailabilities_api_v1 extends EA_Controller
{
/**
* Unavailabilities_api_v1 constructor.
*/
@ -36,8 +37,7 @@ class Unavailabilities_api_v1 extends EA_Controller {
*/
public function index()
{
try
{
try {
$keyword = $this->api->request_keyword();
$limit = $this->api->request_limit();
@ -51,28 +51,23 @@ class Unavailabilities_api_v1 extends EA_Controller {
$with = $this->api->request_with();
$unavailabilities = empty($keyword)
? $this->unavailabilities_model->get(NULL, $limit, $offset, $order_by)
? $this->unavailabilities_model->get(null, $limit, $offset, $order_by)
: $this->unavailabilities_model->search($keyword, $limit, $offset, $order_by);
foreach ($unavailabilities as &$unavailability)
{
foreach ($unavailabilities as &$unavailability) {
$this->unavailabilities_model->api_encode($unavailability);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->unavailabilities_model->only($unavailability, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->unavailabilities_model->load($unavailability, $with);
}
}
json_response($unavailabilities);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -82,10 +77,9 @@ class Unavailabilities_api_v1 extends EA_Controller {
*
* @param int|null $id Unavailability ID.
*/
public function show(int $id = NULL)
public function show(int $id = null)
{
try
{
try {
$fields = $this->api->request_fields();
$with = $this->api->request_with();
@ -94,27 +88,22 @@ class Unavailabilities_api_v1 extends EA_Controller {
$this->unavailabilities_model->api_encode($unavailability);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->unavailabilities_model->only($unavailability, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->unavailabilities_model->load($unavailability, $with);
}
if ( ! $unavailability)
{
if (!$unavailability) {
response('', 404);
return;
}
json_response($unavailability);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -124,14 +113,12 @@ class Unavailabilities_api_v1 extends EA_Controller {
*/
public function store()
{
try
{
try {
$unavailability = request();
$this->unavailabilities_model->api_decode($unavailability);
if (array_key_exists('id', $unavailability))
{
if (array_key_exists('id', $unavailability)) {
unset($unavailability['id']);
}
@ -142,9 +129,7 @@ class Unavailabilities_api_v1 extends EA_Controller {
$this->unavailabilities_model->api_encode($created_unavailability);
json_response($created_unavailability, 201);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -156,12 +141,10 @@ class Unavailabilities_api_v1 extends EA_Controller {
*/
public function update(int $id)
{
try
{
try {
$occurrences = $this->unavailabilities_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -180,9 +163,7 @@ class Unavailabilities_api_v1 extends EA_Controller {
$this->unavailabilities_model->api_encode($updated_unavailability);
json_response($updated_unavailability);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -194,12 +175,10 @@ class Unavailabilities_api_v1 extends EA_Controller {
*/
public function destroy(int $id)
{
try
{
try {
$occurrences = $this->unavailabilities_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -208,9 +187,7 @@ class Unavailabilities_api_v1 extends EA_Controller {
$this->unavailabilities_model->delete($id);
response('', 204);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -16,7 +16,8 @@
*
* @package Controllers
*/
class Webhooks_api_v1 extends EA_Controller {
class Webhooks_api_v1 extends EA_Controller
{
/**
* Webhooks_api_v1 constructor.
*/
@ -36,8 +37,7 @@ class Webhooks_api_v1 extends EA_Controller {
*/
public function index()
{
try
{
try {
$keyword = $this->api->request_keyword();
$limit = $this->api->request_limit();
@ -47,32 +47,27 @@ class Webhooks_api_v1 extends EA_Controller {
$order_by = $this->api->request_order_by();
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$webhooks = empty($keyword)
? $this->webhooks_model->get(NULL, $limit, $offset, $order_by)
? $this->webhooks_model->get(null, $limit, $offset, $order_by)
: $this->webhooks_model->search($keyword, $limit, $offset, $order_by);
foreach ($webhooks as &$webhook)
{
foreach ($webhooks as &$webhook) {
$this->webhooks_model->api_encode($webhook);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->webhooks_model->only($webhook, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->webhooks_model->load($webhook, $with);
}
}
json_response($webhooks);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -82,39 +77,33 @@ class Webhooks_api_v1 extends EA_Controller {
*
* @param int|null $id Webhook ID.
*/
public function show(int $id = NULL)
public function show(int $id = null)
{
try
{
try {
$fields = $this->api->request_fields();
$with = $this->api->request_with();
$webhook = $this->webhooks_model->find($id);
$this->webhooks_model->api_encode($webhook);
if ( ! empty($fields))
{
if (!empty($fields)) {
$this->webhooks_model->only($webhook, $fields);
}
if ( ! empty($with))
{
if (!empty($with)) {
$this->webhooks_model->load($webhook, $with);
}
if ( ! $webhook)
{
if (!$webhook) {
response('', 404);
return;
}
json_response($webhook);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -124,14 +113,12 @@ class Webhooks_api_v1 extends EA_Controller {
*/
public function store()
{
try
{
try {
$webhook = request();
$this->webhooks_model->api_decode($webhook);
if (array_key_exists('id', $webhook))
{
if (array_key_exists('id', $webhook)) {
unset($webhook['id']);
}
@ -142,9 +129,7 @@ class Webhooks_api_v1 extends EA_Controller {
$this->webhooks_model->api_encode($created_webhook);
json_response($created_webhook, 201);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -156,12 +141,10 @@ class Webhooks_api_v1 extends EA_Controller {
*/
public function update(int $id)
{
try
{
try {
$occurrences = $this->webhooks_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -180,9 +163,7 @@ class Webhooks_api_v1 extends EA_Controller {
$this->webhooks_model->api_encode($updated_webhook);
json_response($updated_webhook);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}
@ -194,12 +175,10 @@ class Webhooks_api_v1 extends EA_Controller {
*/
public function destroy(int $id)
{
try
{
try {
$occurrences = $this->webhooks_model->get(['id' => $id]);
if (empty($occurrences))
{
if (empty($occurrences)) {
response('', 404);
return;
@ -208,9 +187,7 @@ class Webhooks_api_v1 extends EA_Controller {
$this->webhooks_model->delete($id);
response('', 204);
}
catch (Throwable $e)
{
} catch (Throwable $e) {
json_exception($e);
}
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Benchmark extends CI_Benchmark {
//
class EA_Benchmark extends CI_Benchmark
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Cache extends CI_Cache {
//
class EA_Cache extends CI_Cache
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Calendar extends CI_Calendar {
//
class EA_Calendar extends CI_Calendar
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Config extends CI_Config {
//
class EA_Config extends CI_Config
{
//
}

View file

@ -68,7 +68,8 @@
* @property Timezones $timezones
* @property Webhooks_client $webhooks_client
*/
class EA_Controller extends CI_Controller {
class EA_Controller extends CI_Controller
{
/**
* EA_Controller constructor.
*/
@ -89,6 +90,21 @@ class EA_Controller extends CI_Controller {
rate_limit($this->input->ip_address());
}
private function ensure_user_exists()
{
$user_id = session('user_id');
if (!$user_id) {
return;
}
if (!$this->accounts->does_account_exist($user_id)) {
session_destroy();
abort(403, 'Forbidden');
}
}
/**
* Configure the language.
*/
@ -96,10 +112,9 @@ class EA_Controller extends CI_Controller {
{
$session_language = session('language');
if ($session_language)
{
$language_codes = config('language_codes');
if ($session_language) {
$language_codes = config('language_codes');
config([
'language' => $session_language,
'language_code' => array_search($session_language, $language_codes) ?: 'en'
@ -119,7 +134,7 @@ class EA_Controller extends CI_Controller {
'index_page' => config('index_page'),
'available_languages' => config('available_languages'),
'language' => $this->lang->language,
'csrf_token' => $this->security->get_csrf_hash(),
'csrf_token' => $this->security->get_csrf_hash()
]);
}
@ -134,24 +149,7 @@ class EA_Controller extends CI_Controller {
'available_languages' => config('available_languages'),
'csrf_token' => $this->security->get_csrf_hash(),
'language' => config('language'),
'language_code' => config('language_code'),
'language_code' => config('language_code')
]);
}
private function ensure_user_exists()
{
$user_id = session('user_id');
if ( ! $user_id)
{
return;
}
if ( ! $this->accounts->does_account_exist($user_id))
{
session_destroy();
abort(403, 'Forbidden');
}
}
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_DB_forge extends CI_DB_forge {
//
class EA_DB_forge extends CI_DB_forge
{
//
}

View file

@ -38,9 +38,10 @@
* @property EA_Session $session
* @property EA_Upload $upload
* @property EA_URI $uri
*
*
* @method int insert_id()
*/
class EA_DB_query_builder extends CI_DB_query_builder {
//
class EA_DB_query_builder extends CI_DB_query_builder
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_DB_utility extends CI_DB_utility {
//
class EA_DB_utility extends CI_DB_utility
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Email extends CI_Email {
//
class EA_Email extends CI_Email
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Encrypt extends CI_Encrypt {
//
class EA_Encrypt extends CI_Encrypt
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Encryption extends CI_Encryption {
//
class EA_Encryption extends CI_Encryption
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Exceptions extends CI_Exceptions {
//
class EA_Exceptions extends CI_Exceptions
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Hooks extends CI_Hooks {
//
class EA_Hooks extends CI_Hooks
{
//
}

View file

@ -41,7 +41,8 @@
*
* @property string $raw_input_stream
*/
class EA_Input extends CI_Input {
class EA_Input extends CI_Input
{
/**
* Fetch an item from JSON data.
*
@ -50,38 +51,33 @@ class EA_Input extends CI_Input {
*
* @return mixed
*/
public function json(string $index = NULL, bool $xss_clean = FALSE)
public function json(string $index = null, bool $xss_clean = false)
{
/** @var EA_Controller $CI */
$CI = &get_instance();
if (strpos((string)$CI->input->get_request_header('Content-Type'), 'application/json') === false)
{
return NULL;
if (strpos((string) $CI->input->get_request_header('Content-Type'), 'application/json') === false) {
return null;
}
$input_stream = $CI->input->raw_input_stream;
if (empty($input_stream))
{
if (empty($input_stream)) {
throw new RuntimeException('Cannot get JSON attribute from an empty input stream.');
}
$payload = json_decode($input_stream, TRUE);
$payload = json_decode($input_stream, true);
if ($xss_clean)
{
foreach ($payload as $name => $value)
{
if ($xss_clean) {
foreach ($payload as $name => $value) {
$payload[$name] = $CI->security->xss_clean($value);
}
}
if (empty($index))
{
if (empty($index)) {
return $payload;
}
return $payload[$index] ?? NULL;
return $payload[$index] ?? null;
}
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Lang extends CI_Lang {
//
class EA_Lang extends CI_Lang
{
//
}

View file

@ -39,7 +39,8 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Loader extends CI_Loader {
class EA_Loader extends CI_Loader
{
/**
* Override the original view loader method so that layouts are also supported.
*
@ -49,19 +50,26 @@ class EA_Loader extends CI_Loader {
*
* @return object|string
*/
public function view($view, $vars = [], $return = FALSE)
public function view($view, $vars = [], $return = false)
{
$layout = config('layout');
$is_layout_page = empty($layout); // This is a layout page if "layout" was undefined before the page got rendered.
$result = $this->_ci_load(['_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return]);
$result = $this->_ci_load([
'_ci_view' => $view,
'_ci_vars' => $this->_ci_prepare_view_vars($vars),
'_ci_return' => $return
]);
$layout = config('layout');
if ($layout && $is_layout_page)
{
$result = $this->_ci_load(['_ci_view' => $layout['filename'], '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return]);
if ($layout && $is_layout_page) {
$result = $this->_ci_load([
'_ci_view' => $layout['filename'],
'_ci_vars' => $this->_ci_prepare_view_vars($vars),
'_ci_return' => $return
]);
}
return $result;

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Log extends CI_Log {
//
class EA_Log extends CI_Log
{
//
}

View file

@ -41,7 +41,8 @@ require_once __DIR__ . '/../../system/libraries/Migration.php';
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Migration extends CI_Migration {
class EA_Migration extends CI_Migration
{
/**
* Get the current migration version.
*

View file

@ -39,7 +39,8 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Model extends CI_Model {
class EA_Model extends CI_Model
{
/**
* @var array
*/
@ -67,8 +68,7 @@ class EA_Model extends CI_Model {
*/
public function get_value(string $field, int $record_id): string
{
if (method_exists($this, 'value'))
{
if (method_exists($this, 'value')) {
return $this->value($field, $record_id);
}
@ -88,8 +88,7 @@ class EA_Model extends CI_Model {
*/
public function get_row(int $record_id): array
{
if (method_exists($this, 'find'))
{
if (method_exists($this, 'find')) {
return $this->find($record_id);
}
@ -106,7 +105,7 @@ class EA_Model extends CI_Model {
*
* @return array Returns an array of records.
*/
public function get_batch($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
public function get_batch($where = null, int $limit = null, int $offset = null, string $order_by = null): array
{
return $this->get($where, $limit, $offset, $order_by);
}
@ -135,29 +134,26 @@ class EA_Model extends CI_Model {
*/
public function cast(array &$record)
{
foreach ($this->casts as $attribute => $cast)
{
if ( ! isset($record[$attribute]))
{
foreach ($this->casts as $attribute => $cast) {
if (!isset($record[$attribute])) {
continue;
}
switch ($cast)
{
switch ($cast) {
case 'integer':
$record[$attribute] = (int)$record[$attribute];
$record[$attribute] = (int) $record[$attribute];
break;
case 'float':
$record[$attribute] = (float)$record[$attribute];
$record[$attribute] = (float) $record[$attribute];
break;
case 'boolean':
$record[$attribute] = (bool)$record[$attribute];
$record[$attribute] = (bool) $record[$attribute];
break;
case 'string':
$record[$attribute] = (string)$record[$attribute];
$record[$attribute] = (string) $record[$attribute];
break;
default:
@ -174,14 +170,10 @@ class EA_Model extends CI_Model {
*/
public function only(array &$record, array $fields)
{
if (is_assoc($record))
{
if (is_assoc($record)) {
$record = array_fields($record, $fields);
}
else
{
foreach ($record as &$record_item)
{
} else {
foreach ($record as &$record_item) {
$record_item = array_fields($record_item, $fields);
}
}
@ -195,19 +187,13 @@ class EA_Model extends CI_Model {
*/
public function optional(array &$record, array $fields)
{
if (is_assoc($record))
{
foreach ($fields as $field => $default)
{
if (is_assoc($record)) {
foreach ($fields as $field => $default) {
$record[$field] = $record[$field] ?? $default;
}
}
else
{
foreach ($record as &$record_item)
{
foreach ($fields as $field => $default)
{
} else {
foreach ($record as &$record_item) {
foreach ($fields as $field => $default) {
$record_item[$field] = $record_item[$field] ?? $default;
}
}
@ -223,6 +209,6 @@ class EA_Model extends CI_Model {
*/
public function db_field(string $api_field): ?string
{
return $this->api_resource[$api_field] ?? NULL;
return $this->api_resource[$api_field] ?? null;
}
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Output extends CI_Output {
//
class EA_Output extends CI_Output
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Profiler extends CI_Profiler {
//
class EA_Profiler extends CI_Profiler
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Router extends CI_Router {
//
class EA_Router extends CI_Router
{
//
}

View file

@ -39,7 +39,8 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Security extends CI_Security {
class EA_Security extends CI_Security
{
/**
* CSRF Verify
*
@ -48,47 +49,43 @@ class EA_Security extends CI_Security {
public function csrf_verify()
{
// If it's not a POST request we will set the CSRF cookie
if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST')
{
if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST') {
return $this->csrf_set_cookie();
}
// Check if URI has been whitelisted from CSRF checks
if ($exclude_uris = config_item('csrf_exclude_uris'))
{
if ($exclude_uris = config_item('csrf_exclude_uris')) {
$uri = load_class('URI', 'core');
foreach ($exclude_uris as $excluded)
{
if (preg_match('#^' . $excluded . '$#i' . (UTF8_ENABLED ? 'u' : ''), $uri->uri_string()))
{
foreach ($exclude_uris as $excluded) {
if (preg_match('#^' . $excluded . '$#i' . (UTF8_ENABLED ? 'u' : ''), $uri->uri_string())) {
return $this;
}
}
}
// Check CSRF token validity, but don't error on mismatch just yet - we'll want to regenerate
$csrf_token = $_POST[$this->_csrf_token_name] ?? $_SERVER['HTTP_X_CSRF'] ?? NULL;
$csrf_token = $_POST[$this->_csrf_token_name] ?? ($_SERVER['HTTP_X_CSRF'] ?? null);
$valid = isset($csrf_token, $_COOKIE[$this->_csrf_cookie_name])
&& is_string($csrf_token) && is_string($_COOKIE[$this->_csrf_cookie_name])
&& hash_equals($csrf_token, $_COOKIE[$this->_csrf_cookie_name]);
$valid =
isset($csrf_token, $_COOKIE[$this->_csrf_cookie_name]) &&
is_string($csrf_token) &&
is_string($_COOKIE[$this->_csrf_cookie_name]) &&
hash_equals($csrf_token, $_COOKIE[$this->_csrf_cookie_name]);
// We kill this since we're done and we don't want to pollute the _POST array
unset($_POST[$this->_csrf_token_name]);
// Regenerate on every submission?
if (config_item('csrf_regenerate'))
{
if (config_item('csrf_regenerate')) {
// Nothing should last forever
unset($_COOKIE[$this->_csrf_cookie_name]);
$this->_csrf_hash = NULL;
$this->_csrf_hash = null;
}
$this->_csrf_set_hash();
$this->csrf_set_cookie();
if ($valid !== TRUE)
{
if ($valid !== true) {
$this->csrf_show_error();
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Session extends CI_Session {
//
class EA_Session extends CI_Session
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_URI extends CI_URI {
//
class EA_URI extends CI_URI
{
//
}

View file

@ -39,6 +39,7 @@
* @property EA_Upload $upload
* @property EA_URI $uri
*/
class EA_Upload extends CI_Upload {
//
class EA_Upload extends CI_Upload
{
//
}

View file

@ -11,8 +11,7 @@
* @since v1.4.0
* ---------------------------------------------------------------------------- */
if ( ! function_exists('is_assoc'))
{
if (!function_exists('is_assoc')) {
/**
* Check if an array is an associative array.
*
@ -22,17 +21,15 @@ if ( ! function_exists('is_assoc'))
*/
function is_assoc(array $array): bool
{
if (empty($array))
{
return FALSE;
if (empty($array)) {
return false;
}
return array_keys($array) !== range(0, count($array) - 1);
}
}
if ( ! function_exists('array_find'))
{
if (!function_exists('array_find')) {
/**
* Find the first array element based on the provided function.
*
@ -43,23 +40,19 @@ if ( ! function_exists('array_find'))
*/
function array_find(array $array, callable $callback): mixed
{
if (empty($array))
{
return NULL;
if (empty($array)) {
return null;
}
if ( ! is_callable($callback))
{
if (!is_callable($callback)) {
throw new InvalidArgumentException('No filter function provided.');
}
return array_filter($array, $callback)[0] ?? NULL;
return array_filter($array, $callback)[0] ?? null;
}
}
if ( ! function_exists('array_fields'))
{
if (!function_exists('array_fields')) {
/**
* Keep only the provided fields of an array.
*
@ -70,9 +63,12 @@ if ( ! function_exists('array_fields'))
*/
function array_fields(array $array, array $fields): array
{
return array_filter($array, function ($field) use ($fields) {
return in_array($field, $fields);
}, ARRAY_FILTER_USE_KEY);
return array_filter(
$array,
function ($field) use ($fields) {
return in_array($field, $fields);
},
ARRAY_FILTER_USE_KEY
);
}
}

View file

@ -22,19 +22,17 @@
*
* @return string Returns the final asset URL.
*/
function asset_url(string $uri = '', string $protocol = NULL): string
function asset_url(string $uri = '', string $protocol = null): string
{
$debug = config('debug');
$cache_busting_token = ! $debug ? '?' . config('cache_busting_token') : '';
$cache_busting_token = !$debug ? '?' . config('cache_busting_token') : '';
if (str_contains(basename($uri), '.js') && ! str_contains(basename($uri), '.min.js') && ! $debug)
{
if (str_contains(basename($uri), '.js') && !str_contains(basename($uri), '.min.js') && !$debug) {
$uri = str_replace('.js', '.min.js', $uri);
}
if (str_contains(basename($uri), '.css') && ! str_contains(basename($uri), '.min.css') && ! $debug)
{
if (str_contains(basename($uri), '.css') && !str_contains(basename($uri), '.min.css') && !$debug) {
$uri = str_replace('.css', '.min.css', $uri);
}

View file

@ -31,24 +31,21 @@
*
* @throws InvalidArgumentException
*/
function config(array|string $key, mixed $default = NULL): mixed
function config(array|string $key, mixed $default = null): mixed
{
/** @var EA_Controller $CI */
$CI = &get_instance();
if (empty($key))
{
if (empty($key)) {
throw new InvalidArgumentException('The $key argument cannot be empty.');
}
if (is_array($key))
{
foreach ($key as $item => $value)
{
if (is_array($key)) {
foreach ($key as $item => $value) {
$CI->config->set_item($item, $value);
}
return NULL;
return null;
}
$value = $CI->config->item($key);
@ -56,8 +53,7 @@ function config(array|string $key, mixed $default = NULL): mixed
return $value ?? $default;
}
if ( ! function_exists('script_vars'))
{
if (!function_exists('script_vars')) {
/**
* Get / set the specified JS config value.
*
@ -78,35 +74,31 @@ if ( ! function_exists('script_vars'))
*
* @throws InvalidArgumentException
*/
function script_vars(array|string $key = NULL, mixed $default = NULL): mixed
function script_vars(array|string $key = null, mixed $default = null): mixed
{
$script_vars = config('script_vars', []);
if (empty($key))
{
if (empty($key)) {
return $script_vars;
}
if (is_array($key))
{
foreach ($key as $item => $value)
{
if (is_array($key)) {
foreach ($key as $item => $value) {
$script_vars[$item] = $value;
}
config(['script_vars' => $script_vars]);
return NULL;
return null;
}
$value = $script_vars[$key] ?? NULL;
$value = $script_vars[$key] ?? null;
return $value ?? $default;
}
}
if ( ! function_exists('html_vars'))
{
if (!function_exists('html_vars')) {
/**
* Get / set the specified HTML variable.
*
@ -127,35 +119,31 @@ if ( ! function_exists('html_vars'))
*
* @throws InvalidArgumentException
*/
function html_vars(array|string $key = NULL, mixed $default = NULL): mixed
function html_vars(array|string $key = null, mixed $default = null): mixed
{
$html_vars = config('html_vars', []);
if (empty($key))
{
if (empty($key)) {
return $html_vars;
}
if (is_array($key))
{
foreach ($key as $item => $value)
{
if (is_array($key)) {
foreach ($key as $item => $value) {
$html_vars[$item] = $value;
}
config(['html_vars' => $html_vars]);
return NULL;
return null;
}
$value = $html_vars[$key] ?? NULL;
$value = $html_vars[$key] ?? null;
return $value ?? $default;
}
}
if ( ! function_exists('vars'))
{
if (!function_exists('vars')) {
/**
* Get / set the specified HTML & JS config value.
*
@ -176,8 +164,8 @@ if ( ! function_exists('vars'))
*
* @throws InvalidArgumentException
*/
function vars(array|string $key = NULL, mixed $default = NULL): mixed
function vars(array|string $key = null, mixed $default = null): mixed
{
return html_vars($key) ?? script_vars($key) ?? $default;
return html_vars($key) ?? (script_vars($key) ?? $default);
}
}

View file

@ -11,8 +11,7 @@
* @since v1.4.0
* ---------------------------------------------------------------------------- */
if ( ! function_exists('get_date_format'))
{
if (!function_exists('get_date_format')) {
/**
* Get the date format based on the current settings.
*
@ -22,18 +21,16 @@ if ( ! function_exists('get_date_format'))
{
$date_format = setting('date_format');
return match ($date_format)
{
return match ($date_format) {
'DMY' => 'd/m/Y',
'MDY' => 'm/d/Y',
'YMD' => 'Y/m/d',
default => throw new RuntimeException('Invalid date format value: ' . $date_format),
default => throw new RuntimeException('Invalid date format value: ' . $date_format)
};
}
}
if ( ! function_exists('get_time_format'))
{
if (!function_exists('get_time_format')) {
/**
* Get the time format based on the current settings.
*
@ -43,17 +40,15 @@ if ( ! function_exists('get_time_format'))
{
$time_format = setting('time_format');
return match ($time_format)
{
return match ($time_format) {
'military' => 'H:i',
'regular' => 'g:i a',
default => throw new RuntimeException('Invalid time format value: ' . $time_format),
default => throw new RuntimeException('Invalid time format value: ' . $time_format)
};
}
}
if ( ! function_exists('get_date_time_format'))
{
if (!function_exists('get_date_time_format')) {
/**
* Get the date-time format based on the current settings.
*
@ -65,9 +60,7 @@ if ( ! function_exists('get_date_time_format'))
}
}
if ( ! function_exists('format_date'))
{
if (!function_exists('format_date')) {
/**
* Format a date string based on the current app settings.
*
@ -79,19 +72,15 @@ if ( ! function_exists('format_date'))
*/
function format_date(DateTimeInterface|string $value): string
{
try
{
try {
$value_date_time = $value;
if (is_string($value_date_time))
{
if (is_string($value_date_time)) {
$value_date_time = new DateTime($value);
}
return $value_date_time->format(get_date_format());
}
catch (Exception $e)
{
} catch (Exception $e) {
log_message('error', 'Invalid date provided to the "format_date" helper function: ' . $e->getMessage());
return 'Invalid Date';
@ -99,8 +88,7 @@ if ( ! function_exists('format_date'))
}
}
if ( ! function_exists('format_time'))
{
if (!function_exists('format_time')) {
/**
* Format a time string based on the current app settings.
*
@ -112,19 +100,15 @@ if ( ! function_exists('format_time'))
*/
function format_time(DateTimeInterface|string $value): string
{
try
{
try {
$value_date_time = $value;
if (is_string($value_date_time))
{
if (is_string($value_date_time)) {
$value_date_time = new DateTime($value);
}
return $value_date_time->format(get_time_format());
}
catch (Exception $e)
{
} catch (Exception $e) {
log_message('error', 'Invalid date provided to the format_time helper function: ' . $e->getMessage());
return 'Invalid Time';
@ -132,8 +116,7 @@ if ( ! function_exists('format_time'))
}
}
if ( ! function_exists('format_date_time'))
{
if (!function_exists('format_date_time')) {
/**
* Format a time string based on the current app settings.
*
@ -143,20 +126,15 @@ if ( ! function_exists('format_date_time'))
*/
function format_date_time(DateTimeInterface|string $value): string
{
try
{
try {
$value_date_time = $value;
if (is_string($value_date_time))
{
if (is_string($value_date_time)) {
$value_date_time = new DateTime($value);
}
return $value_date_time->format(get_date_time_format());
}
catch (Exception $e)
{
} catch (Exception $e) {
log_message('error', 'Invalid date provided to the format_date_time helper function: ' . $e->getMessage());
return 'Invalid Date-Time';
@ -164,8 +142,7 @@ if ( ! function_exists('format_date_time'))
}
}
if ( ! function_exists('format_timezone'))
{
if (!function_exists('format_timezone')) {
/**
* Format a timezone string based on the current app settings.
*
@ -176,12 +153,10 @@ if ( ! function_exists('format_timezone'))
function format_timezone(string $value): string
{
/** @var EA_Controller $CI */
$CI =& get_instance();
$CI = &get_instance();
$CI->load->library('timezones');
return $CI->timezones->get_timezone_name($value);
}
}

View file

@ -13,18 +13,18 @@ defined('BASEPATH') or exit('No direct script access allowed');
* @since v1.5.0
* ---------------------------------------------------------------------------- */
if ( ! function_exists('dd'))
{
if (!function_exists('dd')) {
/**
* Output the provided variables with "var_dump" and stop the execution.
*
*
* Example:
*
* dd($appointment, $service, $provider, $customer);
*
* dd($appointment, $service, $provider, $customer);
*
* @param mixed ...$vars
*/
#[NoReturn] function dd(...$vars): void
#[NoReturn]
function dd(...$vars): void
{
var_dump($vars);

View file

@ -11,8 +11,7 @@
* @since v1.5.0
* ---------------------------------------------------------------------------- */
if ( ! function_exists('env'))
{
if (!function_exists('env')) {
/**
* Gets the value of an environment variable.
*
@ -20,17 +19,16 @@ if ( ! function_exists('env'))
*
* $debug = env('debug', FALSE);
*
* @param string $key Environment key.
* @param string $key Environment key.
* @param mixed|null $default Default value in case the requested variable has no value.
*
* @return mixed
*
* @throws InvalidArgumentException
*/
function env(string $key, mixed $default = NULL): mixed
function env(string $key, mixed $default = null): mixed
{
if (empty($key))
{
if (empty($key)) {
throw new InvalidArgumentException('The $key argument cannot be empty.');
}

View file

@ -11,8 +11,7 @@
* @since v1.4.0
* ---------------------------------------------------------------------------- */
if ( ! function_exists('e'))
{
if (!function_exists('e')) {
/**
* HTML escape function for templates.
*
@ -26,12 +25,11 @@ if ( ! function_exists('e'))
*/
function e(mixed $string): string
{
return htmlspecialchars((string)$string, ENT_QUOTES, 'UTF-8');
return htmlspecialchars((string) $string, ENT_QUOTES, 'UTF-8');
}
}
if ( ! function_exists('component'))
{
if (!function_exists('component')) {
/**
* Render a component from the "views/components/*.php" directory.
*
@ -50,7 +48,7 @@ if ( ! function_exists('component'))
*
* @return string|object Return the HTML if the $return argument is TRUE or NULL.
*/
function component(string $component, array $vars = [], bool $return = FALSE): string|object
function component(string $component, array $vars = [], bool $return = false): string|object
{
/** @var EA_Controller $CI */
$CI = get_instance();
@ -59,8 +57,7 @@ if ( ! function_exists('component'))
}
}
if ( ! function_exists('extend'))
{
if (!function_exists('extend')) {
/**
* Use this function at the top of view files to mark the layout you are extending from.
*
@ -72,14 +69,13 @@ if ( ! function_exists('extend'))
'layout' => [
'filename' => $layout,
'sections' => [],
'tmp' => [],
'tmp' => []
]
]);
}
}
if ( ! function_exists('section'))
{
if (!function_exists('section')) {
/**
* Use this function in view files to mark the beginning and/or end of a layout section.
*
@ -103,8 +99,7 @@ if ( ! function_exists('section'))
{
$layout = config('layout');
if (array_key_exists($name, $layout['tmp']))
{
if (array_key_exists($name, $layout['tmp'])) {
$layout['sections'][$name][] = ob_get_clean();
unset($layout['tmp'][$name]);
@ -114,8 +109,7 @@ if ( ! function_exists('section'))
return;
}
if (empty($layout['sections'][$name]))
{
if (empty($layout['sections'][$name])) {
$layout['sections'][$name] = [];
}
@ -127,8 +121,7 @@ if ( ! function_exists('section'))
}
}
if ( ! function_exists('end_section'))
{
if (!function_exists('end_section')) {
/**
* Use this function in view files to mark the end of a layout section.
*
@ -152,8 +145,7 @@ if ( ! function_exists('end_section'))
{
$layout = config('layout');
if (array_key_exists($name, $layout['tmp']))
{
if (array_key_exists($name, $layout['tmp'])) {
$layout['sections'][$name][] = ob_get_clean();
unset($layout['tmp'][$name]);
@ -163,8 +155,7 @@ if ( ! function_exists('end_section'))
}
}
if ( ! function_exists('slot'))
{
if (!function_exists('slot')) {
/**
* Use this function in view files to mark a slot that sections can populate from within child templates.
*
@ -174,15 +165,13 @@ if ( ! function_exists('slot'))
{
$layout = config('layout');
$section = $layout['sections'][$name] ?? NULL;
$section = $layout['sections'][$name] ?? null;
if ( ! $section)
{
if (!$section) {
return;
}
foreach ($section as $content)
{
foreach ($section as $content) {
echo $content;
}
}

View file

@ -11,8 +11,7 @@
* @since v1.5.0
* ---------------------------------------------------------------------------- */
if ( ! function_exists('request'))
{
if (!function_exists('request')) {
/**
* Gets the value of a request variable.
*
@ -27,29 +26,26 @@ if ( ! function_exists('request'))
*
* @throws InvalidArgumentException
*/
function request(string $key = NULL, $default = NULL)
function request(string $key = null, $default = null)
{
/** @var EA_Controller $CI */
$CI = &get_instance();
if (empty($key))
{
if (empty($key)) {
$payload = $CI->input->post_get($key);
if (empty($payload))
{
if (empty($payload)) {
$payload = $CI->input->json($key);
}
return $payload;
}
return $CI->input->post_get($key) ?? $CI->input->json($key) ?? $default;
return $CI->input->post_get($key) ?? ($CI->input->json($key) ?? $default);
}
}
if ( ! function_exists('response'))
{
if (!function_exists('response')) {
/**
* Return a new response from the application.
*
@ -66,20 +62,15 @@ if ( ! function_exists('response'))
/** @var EA_Controller $CI */
$CI = &get_instance();
foreach ($headers as $header)
{
foreach ($headers as $header) {
$CI->output->set_header($header);
}
$CI
->output
->set_status_header($status)
->set_output($content);
$CI->output->set_status_header($status)->set_output($content);
}
}
if ( ! function_exists('response'))
{
if (!function_exists('response')) {
/**
* Return a new response from the application.
*
@ -92,20 +83,15 @@ if ( ! function_exists('response'))
/** @var EA_Controller $CI */
$CI = &get_instance();
foreach ($headers as $header)
{
foreach ($headers as $header) {
$CI->output->set_header($header);
}
$CI
->output
->set_status_header($status)
->set_output($content);
$CI->output->set_status_header($status)->set_output($content);
}
}
if ( ! function_exists('json_response'))
{
if (!function_exists('json_response')) {
/**
* Return a new response from the application.
*
@ -124,21 +110,18 @@ if ( ! function_exists('json_response'))
/** @var EA_Controller $CI */
$CI = &get_instance();
foreach ($headers as $header)
{
foreach ($headers as $header) {
$CI->output->set_header($header);
}
$CI
->output
$CI->output
->set_status_header($status)
->set_content_type('application/json')
->set_output(json_encode($content));
}
}
if ( ! function_exists('json_exception'))
{
if (!function_exists('json_exception')) {
/**
* Return a new json exception from the application.
*
@ -150,17 +133,18 @@ if ( ! function_exists('json_exception'))
*/
function json_exception(Throwable $e)
{
json_response([
'success' => FALSE,
'message' => $e->getMessage(),
'trace' => config('debug') ? $e->getTrace() : []
], 500);
json_response(
[
'success' => false,
'message' => $e->getMessage(),
'trace' => config('debug') ? $e->getTrace() : []
],
500
);
}
}
if ( ! function_exists('abort'))
{
if (!function_exists('abort')) {
/**
* Throw an HttpException with the given data.
*
@ -179,8 +163,7 @@ if ( ! function_exists('abort'))
/** @var EA_Controller $CI */
$CI = &get_instance();
foreach ($headers as $header)
{
foreach ($headers as $header) {
$CI->output->set_header($header);
}

View file

@ -23,7 +23,7 @@
*/
function is_app_installed(): bool
{
$CI =& get_instance();
$CI = &get_instance();
return $CI->db->table_exists('users');
}

View file

@ -11,9 +11,7 @@
* @since v1.1.0
* ---------------------------------------------------------------------------- */
if ( ! function_exists('lang'))
{
if (!function_exists('lang')) {
/**
* Lang
*
@ -32,8 +30,7 @@ if ( ! function_exists('lang'))
$result = $CI->lang->line($line);
if ($for !== '')
{
if ($for !== '') {
$result = '<label for="' . $for . '"' . _stringify_attributes($attributes) . '>' . $result . '</label>';
}

View file

@ -27,17 +27,15 @@
*/
function hash_password(string $salt, string $password): string
{
if (strlen($password) > MAX_PASSWORD_LENGTH)
{
if (strlen($password) > MAX_PASSWORD_LENGTH) {
throw new InvalidArgumentException('The provided password is too long, please use a shorter value.');
}
$half = (int)(strlen($salt) / 2);
$half = (int) (strlen($salt) / 2);
$hash = hash('sha256', substr($salt, 0, $half) . $password . substr($salt, $half));
for ($i = 0; $i < 100000; $i++)
{
for ($i = 0; $i < 100000; $i++) {
$hash = hash('sha256', $hash);
}
@ -56,7 +54,7 @@ function generate_salt(): string
{
$max_length = 100;
$salt = hash('sha256', (uniqid(rand(), TRUE)));
$salt = hash('sha256', uniqid(rand(), true));
return substr($salt, 0, $max_length);
}

View file

@ -11,8 +11,7 @@
* @since v1.5.0
* ---------------------------------------------------------------------------- */
if ( ! function_exists('storage_path'))
{
if (!function_exists('storage_path')) {
/**
* Get the path to the storage folder.
*
@ -30,8 +29,7 @@ if ( ! function_exists('storage_path'))
}
}
if ( ! function_exists('base_path'))
{
if (!function_exists('base_path')) {
/**
* Get the path to the base of the current installation.
*
@ -46,4 +44,3 @@ if ( ! function_exists('base_path'))
return FCPATH . trim($path);
}
}

Some files were not shown because too many files have changed in this diff Show more