2020-04-22 22:48:56 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2018-06-24 18:27:16 +03:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2018-06-24 18:27:16 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
2020-11-14 22:36:25 +03:00
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2018-06-24 18:27:16 +03:00
|
|
|
* @since v1.3.2
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2021-11-06 18:21:27 +03:00
|
|
|
* Consents controller.
|
2018-06-24 18:27:16 +03:00
|
|
|
*
|
|
|
|
* Handles user consent related operations.
|
2020-04-22 22:48:56 +03:00
|
|
|
*
|
|
|
|
* @package Controllers
|
2018-06-24 18:27:16 +03:00
|
|
|
*/
|
2020-11-16 11:29:36 +03:00
|
|
|
class Consents extends EA_Controller {
|
2020-12-05 12:55:09 +03:00
|
|
|
/**
|
|
|
|
* Consents constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2020-12-05 12:55:09 +03:00
|
|
|
$this->load->model('consents_model');
|
|
|
|
}
|
|
|
|
|
2018-06-24 18:27:16 +03:00
|
|
|
/**
|
2021-10-28 15:01:17 +03:00
|
|
|
* Save (insert or update) the consent
|
2018-06-24 18:27:16 +03:00
|
|
|
*/
|
2022-03-25 14:44:05 +03:00
|
|
|
public function save()
|
2018-06-24 18:27:16 +03:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$consent = request('consent');
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2018-06-24 18:27:16 +03:00
|
|
|
$consent['ip'] = $this->input->ip_address();
|
|
|
|
|
2022-03-25 14:44:05 +03:00
|
|
|
$occurrences = $this->consents_model->get(['ip' => $consent['ip']], 1, 0, 'create_datetime DESC');
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
// Do not create a new consent.
|
|
|
|
|
|
|
|
json_response([
|
|
|
|
'success' => TRUE,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$consent['id'] = $this->consents_model->save($consent);
|
2018-06-24 18:27:16 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
2020-04-22 22:48:56 +03:00
|
|
|
'success' => TRUE,
|
|
|
|
'id' => $consent['id']
|
2021-10-28 15:01:17 +03:00
|
|
|
]);
|
2018-06-24 18:27:16 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2018-06-24 18:27:16 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2018-06-24 18:27:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|