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
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2023-12-31 21:46:27 +03:00
|
|
|
|
* IFLRandevu - İzmir Fen Lisesi Randevu Portalı
|
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
|
|
|
|
*/
|
2023-11-29 12:24:09 +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
|
|
|
|
{
|
2023-11-29 12:24:09 +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');
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!empty($occurrences)) {
|
2022-03-25 14:44:05 +03:00
|
|
|
|
$last_consent = $occurrences[0];
|
|
|
|
|
|
|
|
|
|
$last_consent_create_datetime_instance = new DateTime($last_consent['create_datetime']);
|
|
|
|
|
|
|
|
|
|
$threshold_datetime_instance = new DateTime('-24 hours');
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if ($last_consent_create_datetime_instance > $threshold_datetime_instance) {
|
2022-03-25 14:44:05 +03:00
|
|
|
|
// Do not create a new consent.
|
|
|
|
|
|
|
|
|
|
json_response([
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'success' => true,
|
2022-03-25 14:44:05 +03:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
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([
|
2023-11-29 12:24:09 +03:00
|
|
|
|
'success' => true,
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'id' => $consent['id'],
|
2021-10-28 15:01:17 +03:00
|
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
} catch (Throwable $e) {
|
2021-10-28 15:01:17 +03:00
|
|
|
|
json_exception($e);
|
2018-06-24 18:27:16 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|