Initial import of Din Beste Hjelper site
CodeIgniter 3 app for dinbestehjelper.no. Excludes vendor/, local backup folders (new/, archive/, archived/) and DB dumps (*.sql) via .gitignore. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P16ttGUge8zj91dm6WrmEb
This commit is contained in:
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
class Group_model extends CI_Model {
|
||||
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function createGroup($groupArray){
|
||||
$this->load->database();
|
||||
$query = $this->db->query("INSERT INTO workgroups(
|
||||
group_name,
|
||||
group_info,
|
||||
skills,
|
||||
group_notes,
|
||||
is_active
|
||||
) VALUES(
|
||||
'".$groupArray['group_name']."',
|
||||
'".$groupArray['group_info']."',
|
||||
'".$groupArray['skills']."',
|
||||
'".$groupArray['group_notes']."',
|
||||
'".$groupArray['is_active']."'
|
||||
);");
|
||||
}
|
||||
|
||||
public function getAllGroups(){
|
||||
$this->load->database();
|
||||
$this->load->model('Group_model');
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$query = $this->db->query('SELECT * FROM workgroups ORDER BY group_name DESC;');
|
||||
|
||||
if($query->num_rows() > 0){
|
||||
$resultArray = array();
|
||||
foreach($query->result() as $resultItem){
|
||||
$resultItemTmp = (array)$resultItem;
|
||||
|
||||
if($resultItem->skills != ''){
|
||||
$serviceArray = array();
|
||||
$serviceIds = unserialize($resultItem->skills);
|
||||
foreach($serviceIds as $serviceItem){
|
||||
$serviceArray[] = $this->Service_model->getServiceById($serviceItem);
|
||||
}
|
||||
$resultItemTmp['skillList'] = $serviceArray;
|
||||
}
|
||||
$resultArray[] = (object)$resultItemTmp;
|
||||
}
|
||||
return $resultArray;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllActiveGroups(){
|
||||
$this->load->database();
|
||||
$this->load->model('Group_model');
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$query = $this->db->query('SELECT * FROM workgroups WHERE is_active = "1" && is_deleted != "1" ORDER BY group_id ASC;');
|
||||
|
||||
if($query->num_rows() > 0){
|
||||
$resultArray = array();
|
||||
foreach($query->result() as $resultItem){
|
||||
$resultItemTmp = (array)$resultItem;
|
||||
|
||||
if($resultItem->skills != ''){
|
||||
$serviceArray = array();
|
||||
$serviceIds = unserialize($resultItem->skills);
|
||||
foreach($serviceIds as $serviceItem){
|
||||
$serviceArray[] = $this->Service_model->getServiceById($serviceItem);
|
||||
}
|
||||
$resultItemTmp['skillList'] = $serviceArray;
|
||||
}
|
||||
$resultArray[] = (object)$resultItemTmp;
|
||||
}
|
||||
return $resultArray;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getGroupById($group_id){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM workgroups WHERE group_id = "'.$group_id.'" LIMIT 1;');
|
||||
|
||||
if($query->num_rows() == 1){
|
||||
return $query->result()[0];
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function updateGroup($group_id, $groupArray){
|
||||
$this->load->database();
|
||||
|
||||
foreach($groupArray as $propertyKey => $propertyValue){
|
||||
$query = $this->db->query("UPDATE workgroups SET ".$propertyKey." = '".$propertyValue."' WHERE group_id = '".$group_id."';");
|
||||
}
|
||||
}
|
||||
|
||||
public function availableGroupsByServiceId($serviceCategory){
|
||||
$this->load->database();
|
||||
$this->load->model('Group_model');
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$groupArray = array();
|
||||
|
||||
$activeGroups = $this->Group_model->getAllActiveGroups();
|
||||
$selectedServiceCategory = 0;
|
||||
|
||||
if(is_array($activeGroups)){
|
||||
foreach($activeGroups as $activeGroupItem){
|
||||
$serviceIds = unserialize($activeGroupItem->skills);
|
||||
foreach($serviceIds as $serviceIdItem){
|
||||
$selectedService = $this->Service_model->getServiceById($serviceIdItem);
|
||||
$selectedServiceCategory = $selectedService->service_group;
|
||||
if($selectedServiceCategory == $serviceCategory){
|
||||
$groupArray[] = $activeGroupItem->group_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $groupArray;
|
||||
}
|
||||
|
||||
|
||||
public function getAvailableGroup($bookingDate, $serviceCategory){
|
||||
$this->load->database();
|
||||
$this->load->model('Group_model');
|
||||
|
||||
$activeServiceGroupArray = $this->Group_model->availableGroupsByServiceId($serviceCategory);
|
||||
|
||||
$activeServiceGroupString = '';
|
||||
if(!empty($activeServiceGroupArray)){
|
||||
$arrayIndex = 1;
|
||||
$collectedServiceGroupArrayTmp = array();
|
||||
foreach($activeServiceGroupArray as $activeServiceGroupArrayItem){
|
||||
if($arrayIndex != sizeof($activeServiceGroupArray)){
|
||||
if(!in_array($activeServiceGroupArrayItem, $collectedServiceGroupArrayTmp)){
|
||||
$collectedServiceGroupArrayTmp[] = $activeServiceGroupArrayItem;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(!in_array($activeServiceGroupArrayItem, $collectedServiceGroupArrayTmp)){
|
||||
$collectedServiceGroupArrayTmp[] = $activeServiceGroupArrayItem;
|
||||
}
|
||||
}
|
||||
$arrayIndex++;
|
||||
}
|
||||
|
||||
}
|
||||
$activeServiceGroupString .= implode(', ', $collectedServiceGroupArrayTmp);
|
||||
|
||||
$query = $this->db->query('
|
||||
SELECT * FROM
|
||||
(SELECT
|
||||
results.group_id,
|
||||
SEC_TO_TIME( SUM( TIME_TO_SEC( TIME(results.difference) ) ) ) AS diff FROM
|
||||
(SELECT
|
||||
booking_id,
|
||||
guest_name,
|
||||
guest_email,
|
||||
guest_phone,
|
||||
bookings.group_id,
|
||||
booking_date,
|
||||
booking_start_time,
|
||||
booking_finish_time,
|
||||
service_ids,
|
||||
guest_confirmed,
|
||||
guest_confirm_code,
|
||||
group_name,
|
||||
group_info,
|
||||
group_profile_img,
|
||||
skills,
|
||||
group_notes,
|
||||
is_active,
|
||||
is_deleted,
|
||||
TIMEDIFF(booking_finish_time, booking_start_time) AS difference
|
||||
FROM bookings JOIN workgroups ON bookings.group_id = workgroups.group_id
|
||||
WHERE is_active = 1 AND is_deleted = 0
|
||||
AND booking_date = "'.$bookingDate.'"
|
||||
AND bookings.group_id IN ('.$activeServiceGroupString.')
|
||||
) as results
|
||||
GROUP BY results.group_id
|
||||
ORDER BY SEC_TO_TIME( SUM( TIME_TO_SEC( TIME(results.difference) ) ) ) DESC
|
||||
) AS groupedResults
|
||||
JOIN workgroups ON groupedResults.group_id = workgroups.group_id
|
||||
;');
|
||||
if($query->num_rows() > 0){
|
||||
return $query->result()[0];
|
||||
}
|
||||
else{
|
||||
$activeGroups = $this->Group_model->getAllActiveGroups();
|
||||
$firstGroup = $activeGroups[0];
|
||||
return $firstGroup;
|
||||
}
|
||||
|
||||
return $isServiceActive;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
class Log_model extends CI_Model {
|
||||
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function addLog($eventType, $eventContent, $username=""){
|
||||
$this->load->database();
|
||||
$query = $this->db->query("INSERT INTO system_log(event_type, event_content, username) VALUES('".$eventType."','".$eventContent."','".$username."');");
|
||||
}
|
||||
|
||||
public function getAllLoginfo(){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM system_log ORDER BY event_datetime DESC;');
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
class Module_model extends CI_Model {
|
||||
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getAllModule(){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM modules ORDER BY module_name ASC');
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function getModuleById($module_id){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM modules WHERE module_id = "'.$module_id.'" LIMIT 1;');
|
||||
return $query->result()[0];
|
||||
}
|
||||
|
||||
public function getModuleBySlug($module_slug){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM modules WHERE module_slug = "'.$module_slug.'" LIMIT 1;');
|
||||
return $query->result()[0];
|
||||
}
|
||||
|
||||
public function getUserModules($userId){
|
||||
$this->load->database();
|
||||
$this->load->model('User_model');
|
||||
|
||||
$currentUser = $this->User_model->getUserById($userId);
|
||||
|
||||
$query = $this->db->query('SELECT * FROM modules');
|
||||
$all_module = $query->result();
|
||||
$activeModules = array();
|
||||
$activeModuleIds = array();
|
||||
|
||||
foreach($all_module as $moduleItem){
|
||||
|
||||
//check groupmodules
|
||||
$moduleGroupIds = unserialize($moduleItem->permission_group_ids);
|
||||
$moduleUserIds = unserialize($moduleItem->permission_ids);
|
||||
|
||||
if(!empty($moduleItem->permission_ids)){
|
||||
}
|
||||
|
||||
//check group ids
|
||||
if(is_array($moduleGroupIds)){
|
||||
if(in_array($currentUser->permission_id, $moduleGroupIds)){
|
||||
if(!in_array($moduleItem->module_id, $activeModuleIds)){
|
||||
|
||||
$activeModules[] = $moduleItem;
|
||||
$activeModuleIds[] = $moduleItem->module_id;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//check user_ids
|
||||
|
||||
if(is_array($moduleUserIds)){
|
||||
if(in_array($currentUser->user_id, $moduleUserIds)){
|
||||
|
||||
if(!in_array($moduleItem->module_id, $activeModuleIds)){
|
||||
$activeModules[] = $moduleItem;
|
||||
$activeModuleIds[] = $moduleItem->module_id;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return $activeModules;
|
||||
}
|
||||
|
||||
|
||||
public function is_module_available($module_id, $userId){
|
||||
$this->load->database();
|
||||
$this->load->model('User_model');
|
||||
|
||||
$currentModule = $this->getModuleById($module_id);
|
||||
$currentUser = $this->User_model->getUserById($userId);
|
||||
$moduleGroupIds = unserialize($currentModule->permission_group_ids);
|
||||
$moduleUserIds = unserialize($currentModule->permission_ids);
|
||||
$moduleIsOk = 0;
|
||||
|
||||
//if($currentUser->permission_slug == 'admin' && $module_id != '5'){
|
||||
if($currentUser->permission_slug == 'admin'){
|
||||
$moduleIsOk = 1;
|
||||
}
|
||||
|
||||
//check groupmodules
|
||||
if(is_array($moduleGroupIds)){
|
||||
if(in_array($currentUser->permission_id, $moduleGroupIds)){
|
||||
$moduleIsOk = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//check user_ids
|
||||
if(is_array($moduleUserIds)){
|
||||
if(in_array($currentUser->user_id, $moduleUserIds)){
|
||||
$moduleIsOk = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if($moduleIsOk){
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function is_userId_available_in_module($module_id, $userId){
|
||||
$this->load->database();
|
||||
$this->load->model('User_model');
|
||||
|
||||
$currentModule = $this->getModuleById($module_id);
|
||||
$userIds = unserialize($currentModule->permission_ids);
|
||||
|
||||
|
||||
if(is_array($userIds)){
|
||||
if(in_array($userId, $userIds)){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function is_groupId_available_in_module($module_id, $groupId){
|
||||
$this->load->database();
|
||||
$this->load->model('User_model');
|
||||
|
||||
$currentModule = $this->getModuleById($module_id);
|
||||
$moduleGroupIds = unserialize($currentModule->permission_group_ids);
|
||||
|
||||
if(is_array($moduleGroupIds)){
|
||||
if(in_array($groupId, $moduleGroupIds)){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function updateModule($fieldName, $module_id, $moduleUserArray){
|
||||
$this->load->database();
|
||||
|
||||
if(!empty($moduleUserArray)){
|
||||
$query = $this->db->query("UPDATE modules SET ".$fieldName." ='".serialize($moduleUserArray)."' WHERE module_id = '".$module_id."';");
|
||||
}
|
||||
else{
|
||||
$query = $this->db->query("UPDATE modules SET ".$fieldName." ='' WHERE module_id = '".$module_id."';");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getModulesByPermissionSlug($permissionSlug){
|
||||
$this->load->database();
|
||||
$this->load->model('Module_model');
|
||||
$selectedPermission = $this->Module_model->getPermissionBySlug($permissionSlug);
|
||||
|
||||
$query = $this->db->query('SELECT * FROM modules;');
|
||||
$results = $query->result();
|
||||
$resultArray = array();
|
||||
foreach($results as $resultItem){
|
||||
$permissionIdsArray = explode(',', $resultItem->permission_ids);
|
||||
if(in_array($selectedPermission->permission_id, $permissionIdsArray)){
|
||||
$resultArray[] = $resultItem;
|
||||
}
|
||||
}
|
||||
return $resultArray;
|
||||
}
|
||||
|
||||
public function getPermissionBySlug($permissionSlug){
|
||||
$this->load->database();
|
||||
|
||||
$query = $this->db->query('SELECT * FROM permissions WHERE permission_slug = "'.$permissionSlug.'";');
|
||||
if($query->num_rows() == 1){
|
||||
return $query->result()[0];
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function user_can_access_this_module($moduleSlug, $userId){
|
||||
$this->load->database();
|
||||
$this->load->model('User_model');
|
||||
$selectedUser = $this->User_model->getUserById($userId);
|
||||
|
||||
$query = $this->db->query('SELECT * FROM modules WHERE module_slug = "'.$moduleSlug.'" LIMIT 1;');
|
||||
|
||||
if($query->num_rows() == 1){
|
||||
$result = $query->result()[0];
|
||||
$permissionArray = explode(',', $result->permission_ids);
|
||||
if(in_array($selectedUser->permission_id, $permissionArray)){
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,660 @@
|
||||
<?php
|
||||
class Service_model extends CI_Model {
|
||||
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function createService($serviceArray){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('INSERT INTO services (
|
||||
main_category,
|
||||
main_category_description,
|
||||
service_category,
|
||||
service_name,
|
||||
service_description,
|
||||
service_price,
|
||||
service_time,
|
||||
is_enabled
|
||||
) VALUES(
|
||||
"'.$serviceArray['main_category'].'",
|
||||
"'.$serviceArray['main_category_description'].'",
|
||||
"'.$serviceArray['service_category'].'",
|
||||
"'.$serviceArray['service_name'].'",
|
||||
"'.$serviceArray['service_description'].'",
|
||||
"'.$serviceArray['service_price'].'",
|
||||
"'.$serviceArray['service_time'].'",
|
||||
"'.$serviceArray['is_enabled'].'"
|
||||
);');
|
||||
}
|
||||
|
||||
public function updateService($service_id, $serviceArray){
|
||||
$this->load->database();
|
||||
|
||||
foreach($serviceArray as $propertyKey => $propertyValue){
|
||||
$query = $this->db->query('UPDATE services SET '.$propertyKey.' = "'.$propertyValue.'" WHERE service_id = "'.$service_id.'";');
|
||||
}
|
||||
}
|
||||
|
||||
public function updateBooking($booking_id, $bookingArray){
|
||||
$this->load->database();
|
||||
|
||||
foreach($bookingArray as $propertyKey => $propertyValue){
|
||||
$query = $this->db->query("UPDATE bookings SET ".$propertyKey." = '".$propertyValue."' WHERE booking_id = '".$booking_id."';");
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllServiceByServiceType(){
|
||||
$this->load->database();
|
||||
$this->load->model('Group_model');
|
||||
|
||||
$query = $this->db->query('SELECT * FROM services WHERE is_public = "1" AND is_deleted != "1" ORDER BY list_order_nr ASC;');
|
||||
$serviceArray = array();
|
||||
if($query->num_rows() > 0){
|
||||
foreach($query->result() as $resultItem){
|
||||
|
||||
$isServiceAvailable = $this->Service_model->iServiceAvailable($resultItem->service_id);
|
||||
|
||||
$resultItemTmp = array(
|
||||
'service_id' => $resultItem->service_id,
|
||||
'main_category' => $resultItem->main_category,
|
||||
'main_category_description' => $resultItem->main_category_description,
|
||||
'service_category' => $resultItem->service_category,
|
||||
'service_name' => $resultItem->service_name,
|
||||
'service_description' => $resultItem->service_description,
|
||||
'service_group' => $resultItem->service_group,
|
||||
'service_price' => $resultItem->service_price,
|
||||
'service_time' => $resultItem->service_time,
|
||||
'is_enabled' => $resultItem->is_enabled,
|
||||
'is_public' => $resultItem->is_public,
|
||||
'is_service_available' => $isServiceAvailable,
|
||||
'target_url' => $resultItem->target_url
|
||||
);
|
||||
|
||||
$serviceArray[] = (object)$resultItemTmp;
|
||||
}
|
||||
}
|
||||
return $serviceArray;
|
||||
}
|
||||
|
||||
public function getServiceById($service_id){
|
||||
$this->load->database();
|
||||
$this->load->model('Group_model');
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$query = $this->db->query('SELECT * FROM services WHERE service_id = "'.$service_id.'" LIMIT 1;');
|
||||
if($query->num_rows() > 0){
|
||||
$resultItem = $query->result()[0];
|
||||
|
||||
return $resultItem;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllServices(){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM services WHERE is_deleted != "1" ORDER BY service_name ASC;');
|
||||
|
||||
if($query->num_rows() > 0){
|
||||
foreach($query->result() as $resultItem){
|
||||
|
||||
$isServiceAvailable = $this->Service_model->iServiceAvailable($resultItem->service_id);
|
||||
|
||||
$resultItemTmp = array(
|
||||
'service_id' => $resultItem->service_id,
|
||||
'main_category' => $resultItem->main_category,
|
||||
'main_category_description' => $resultItem->main_category_description,
|
||||
'service_category' => $resultItem->service_category,
|
||||
'service_name' => $resultItem->service_name,
|
||||
'service_description' => $resultItem->service_description,
|
||||
'service_price' => $resultItem->service_price,
|
||||
'service_time' => $resultItem->service_time,
|
||||
'is_enabled' => $resultItem->is_enabled,
|
||||
'is_public' => $resultItem->is_public,
|
||||
'is_service_available' => $isServiceAvailable,
|
||||
'target_url' => $resultItem->target_url
|
||||
);
|
||||
|
||||
$serviceArray[] = (object)$resultItemTmp;
|
||||
}
|
||||
return $serviceArray;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAvailableServices(){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM services WHERE is_enabled = "1" AND is_deleted != "1" ORDER BY service_name ASC;');
|
||||
|
||||
if($query->num_rows() > 0){
|
||||
|
||||
$serviceArray = array();
|
||||
foreach($query->result() as $resultItem){
|
||||
$serviceTmp = array(
|
||||
'service_name' => $resultItem->service_name,
|
||||
'service_id' => $resultItem->service_id,
|
||||
'service_group' => $resultItem->service_group
|
||||
);
|
||||
|
||||
$serviceArray[] = (object)$serviceTmp;
|
||||
}
|
||||
return $serviceArray;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllServiceByGroups($serviceGroupArray){
|
||||
$this->load->database();
|
||||
$serviceGroupArrayString = implode(',', $serviceGroupArray);
|
||||
$query = $this->db->query('SELECT * FROM services
|
||||
WHERE
|
||||
is_deleted != "1" AND
|
||||
is_public = "1" AND
|
||||
service_group IN ('.$serviceGroupArrayString.')
|
||||
ORDER BY service_id ASC;');
|
||||
|
||||
$serviceArray = array();
|
||||
|
||||
if($query->num_rows() > 0){
|
||||
foreach($query->result() as $resultItem){
|
||||
|
||||
$isServiceAvailable = $this->Service_model->iServiceAvailable($resultItem->service_id);
|
||||
|
||||
$resultItemTmp = array(
|
||||
'service_id' => $resultItem->service_id,
|
||||
'main_category' => $resultItem->main_category,
|
||||
'main_category_description' => $resultItem->main_category_description,
|
||||
'service_category' => $resultItem->service_category,
|
||||
'service_name' => $resultItem->service_name,
|
||||
'service_description' => $resultItem->service_description,
|
||||
'service_group' => $resultItem->service_group,
|
||||
'is_extra' => $resultItem->is_extra,
|
||||
'is_car' => $resultItem->is_car,
|
||||
'service_price' => $resultItem->service_price,
|
||||
'service_time' => $resultItem->service_time,
|
||||
'is_enabled' => $resultItem->is_enabled,
|
||||
'is_public' => $resultItem->is_public,
|
||||
'is_service_available' => $isServiceAvailable,
|
||||
'target_url' => $resultItem->target_url
|
||||
);
|
||||
|
||||
$serviceArray[] = (object)$resultItemTmp;
|
||||
}
|
||||
}
|
||||
return $serviceArray;
|
||||
}
|
||||
|
||||
public function deleteBooking($booking_id){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('DELETE FROM bookings WHERE booking_id = "'.$booking_id.'";');
|
||||
}
|
||||
|
||||
public function getAllBookings(){
|
||||
$this->load->database();
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$query = $this->db->query('SELECT * FROM bookings ORDER BY booking_date DESC, booking_start_time ASC;');
|
||||
|
||||
if($query->num_rows() > 0){
|
||||
$resultsArray = array();
|
||||
foreach($query->result() as $resultItem){
|
||||
$resultTmp = (array)$resultItem;
|
||||
$groupObjectsArray = array();
|
||||
|
||||
if($resultTmp['group_ids'] != ''){
|
||||
$selectedGroups = explode(',', $resultTmp['group_ids']);
|
||||
if(is_array($selectedGroups)){
|
||||
foreach($selectedGroups as $selectedGroupItem){
|
||||
$selectedGroup = $this->Group_model->getGroupById($selectedGroupItem);
|
||||
$groupObjectsArray[] = $selectedGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
$resultTmp['workgroups'] = $groupObjectsArray;
|
||||
|
||||
if($resultTmp['service_ids'] != ''){
|
||||
$servicesArray = unserialize($resultTmp['service_ids']);
|
||||
if(is_array($servicesArray)){
|
||||
$services = array();
|
||||
foreach($servicesArray as $servicesArrayItem){
|
||||
$selectedService = $this->Service_model->getServiceById($servicesArrayItem);
|
||||
$services[] = (object)array(
|
||||
'service_name' => $selectedService->service_name,
|
||||
'service_price' => $selectedService->service_price,
|
||||
'service_time' => $selectedService->service_time
|
||||
);
|
||||
}
|
||||
$resultTmp['services'] = $services;
|
||||
}
|
||||
else{
|
||||
$resultTmp['services'] = array();
|
||||
}
|
||||
}
|
||||
else{
|
||||
$resultTmp['services'] = array();
|
||||
|
||||
}
|
||||
$resultsArray[] = (object)$resultTmp;
|
||||
}
|
||||
|
||||
|
||||
return $resultsArray;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getActualBookings(){
|
||||
$this->load->database();
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$query = $this->db->query('SELECT * FROM bookings JOIN workgroups ON bookings.group_id = workgroups.group_id WHERE booking_date >= CURDATE() ORDER BY booking_date DESC, booking_start_time ASC;');
|
||||
|
||||
if($query->num_rows() > 0){
|
||||
$resultsArray = array();
|
||||
foreach($query->result() as $resultItem){
|
||||
$resultTmp = (array)$resultItem;
|
||||
if($resultTmp['service_ids'] != ''){
|
||||
$servicesArray = unserialize($resultTmp['service_ids']);
|
||||
if(is_array($servicesArray)){
|
||||
$services = array();
|
||||
foreach($servicesArray as $servicesArrayItem){
|
||||
|
||||
$selectedService = $this->Service_model->getServiceById($servicesArrayItem['service_id']);
|
||||
$services[] = (object)array(
|
||||
'service_name' => $selectedService->service_name,
|
||||
'service_price' => $selectedService->service_price,
|
||||
'service_time' => $selectedService->service_time,
|
||||
'quantity' => $servicesArrayItem['quantity']
|
||||
);
|
||||
}
|
||||
$resultTmp['services'] = $services;
|
||||
}
|
||||
else{
|
||||
$resultTmp['services'] = array();
|
||||
}
|
||||
}
|
||||
else{
|
||||
$resultTmp['services'] = array();
|
||||
|
||||
}
|
||||
$resultsArray[] = (object)$resultTmp;
|
||||
}
|
||||
|
||||
|
||||
return $resultsArray;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getBookingById($booking_id){
|
||||
$this->load->database();
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$query = $this->db->query('SELECT * FROM bookings WHERE booking_id = "'.$booking_id.'" LIMIT 1;');
|
||||
if($query->num_rows() > 0){
|
||||
$resultTmp = (array)$resultItem;
|
||||
if($resultTmp['service_ids'] != ''){
|
||||
$servicesArray = unserialize($resultTmp['service_ids']);
|
||||
if(is_array($servicesArray)){
|
||||
$services = array();
|
||||
foreach($servicesArray as $servicesArrayItem){
|
||||
$selectedService = $this->Service_model->getServiceById($servicesArrayItem['service_id']);
|
||||
$services[] = (object)array(
|
||||
'service_name' => $selectedService->service_name,
|
||||
'service_price' => $selectedService->service_price,
|
||||
'service_time' => $selectedService->service_time,
|
||||
'quantity' => $servicesArrayItem['quantity']
|
||||
);
|
||||
}
|
||||
$resultTmp['services'] = $services;
|
||||
}
|
||||
else{
|
||||
$resultTmp['services'] = array();
|
||||
}
|
||||
}
|
||||
else{
|
||||
$resultTmp['services'] = array();
|
||||
|
||||
}
|
||||
$resultsArray = (object)$resultTmp;
|
||||
return $resultsArray;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getWorkgroupById($group_id){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM workgroups WHERE group_id = "'.$group_id.'" LIMIT 1;');
|
||||
if($query->num_rows() > 0){
|
||||
return $query->result()[0];
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAvailableTimes($group_id, $selectedDate, $servicelength){
|
||||
$this->load->database();
|
||||
$serviceLengthDateTime = new DateTime($selectedDate.' '.$servicelength);
|
||||
$service_length_time = strtotime($servicelength);
|
||||
$availableTimeArray = array();
|
||||
$selectedDayName = date('D', strtotime($selectedDate));
|
||||
$dayStartTime = new DateTime($selectedDate.' 09:00');
|
||||
$finishTime = new DateTime($selectedDate.' 18:01');
|
||||
if($selectedDayName == 'Sun'){
|
||||
return array();
|
||||
}
|
||||
elseif($selectedDayName == 'Sat'){
|
||||
$finishTime = new DateTime($selectedDate.' 16:01');
|
||||
}
|
||||
else{
|
||||
//finish time - selected service length
|
||||
$finishTime = new DateTime($selectedDate.' 18:01');
|
||||
|
||||
}
|
||||
|
||||
$today=date_create(date('Y-m-d'));
|
||||
$selectedDay=date_create($selectedDate);
|
||||
$dateDiff=date_diff($today,$selectedDay);
|
||||
|
||||
$tmpDateStart = date_create(date('2024-02-29'));
|
||||
$tmpDateEnd = date_create(date('2024-03-07'));
|
||||
|
||||
$datelength = new DateTime($servicelength);
|
||||
$diff = $datelength->diff($finishTime);
|
||||
|
||||
//max time for start
|
||||
$maxTime = $diff->h.':'.$diff->i.':00';
|
||||
$hours = (intval($diff->h)-9)*4+1;
|
||||
$mins = floor(intval($diff->i) / 15);
|
||||
$loopSteps = intval($hours) + intval($mins);
|
||||
|
||||
for($periodIndex = 1; $periodIndex <= $loopSteps; $periodIndex++){
|
||||
$minutes_to_add_start = $periodIndex*15;
|
||||
$minutes_to_add_end = ($periodIndex+1)*15;
|
||||
$startTime = new DateTime($selectedDate.' 08:45');
|
||||
$endTime = new DateTime($selectedDate.' 08:45');
|
||||
$startTime->add(new DateInterval('PT' . $minutes_to_add_start . 'M'));
|
||||
$endTime->add(new DateInterval('PT' . $minutes_to_add_end . 'M'));
|
||||
$maxTimeObject = new DateTime($maxTime);
|
||||
|
||||
$tz = new DateTimeZone('Europe/Budapest');
|
||||
$addStartTimeAndLength = new DateTime($selectedDate.' '.$startTime->format('H:i:00'), $tz);
|
||||
$addStartTimeAndLength->add(new DateInterval('PT' . intval($serviceLengthDateTime->format('H')) . 'H'));
|
||||
$addStartTimeAndLength->add(new DateInterval('PT' . intval($serviceLengthDateTime->format('i')) . 'M'));
|
||||
|
||||
$currentStartTime = $startTime->format('H:i:00');
|
||||
$currentEndTime = $endTime->format('H:i:00');
|
||||
|
||||
|
||||
|
||||
/*
|
||||
echo '<< ';
|
||||
print_r($serviceLengthDateTime->format('H:i:00'));
|
||||
echo ' / ';
|
||||
print_r($currentStartTime);
|
||||
echo ' / ';
|
||||
print_r($addStartTimeAndLength->format('H:i:00'));
|
||||
echo ' >>';
|
||||
*/
|
||||
|
||||
$query = $this->db->query('SELECT * FROM bookings WHERE booking_date = "'.$selectedDate.'" AND group_id = "'.$group_id.'" AND (
|
||||
|
||||
(TIME(booking_start_time) >= CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) <= CAST("'.$currentEndTime.'" AS TIME)) OR
|
||||
|
||||
|
||||
(TIME(booking_start_time) <= CAST("'.$addStartTimeAndLength->format('H:i:00').'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME)) OR
|
||||
|
||||
|
||||
(TIME(booking_start_time) >= CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_start_time) <= CAST("'.$currentEndTime.'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME)) OR
|
||||
|
||||
|
||||
(TIME(booking_start_time) <= CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME)
|
||||
AND TIME(booking_start_time) <= CAST("'.$currentStartTime.'" AS TIME)) OR
|
||||
|
||||
|
||||
(TIME(booking_start_time) <= CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) <= CAST("'.$currentEndTime.'" AS TIME)
|
||||
AND TIME(booking_finish_time) >= CAST("'.$currentStartTime.'" AS TIME)) OR
|
||||
|
||||
|
||||
(TIME(booking_start_time) <= CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME))
|
||||
);
|
||||
');
|
||||
/*
|
||||
$query = $this->db->query('SELECT * FROM bookings WHERE booking_date = "'.$selectedDate.'" AND group_id = "'.$group_id.'" AND (
|
||||
(TIME(booking_start_time) > CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) < CAST("'.$currentEndTime.'" AS TIME)) OR
|
||||
|
||||
(TIME(booking_start_time) < CAST("'.$addStartTimeAndLength->format('H:i:00').'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME)) OR
|
||||
|
||||
(TIME(booking_start_time) > CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_start_time) < CAST("'.$currentEndTime.'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME)) OR
|
||||
|
||||
(TIME(booking_start_time) < CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME)
|
||||
AND TIME(booking_start_time) < CAST("'.$currentStartTime.'" AS TIME)) OR
|
||||
|
||||
(TIME(booking_start_time) < CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) < CAST("'.$currentEndTime.'" AS TIME)
|
||||
AND TIME(booking_finish_time) > CAST("'.$currentStartTime.'" AS TIME)) OR
|
||||
|
||||
(TIME(booking_start_time) < CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME))
|
||||
);
|
||||
');
|
||||
*/
|
||||
$now = strtotime(date('H:i:s')) + 60*60;
|
||||
$timezone = 'Europe/Budapest';
|
||||
$todayStartTime = strtotime($currentStartTime.' '.$timezone);
|
||||
$minDiff = ($todayStartTime - $now) / 60;
|
||||
|
||||
|
||||
if($dateDiff->format("%R%a") == 0 && $minDiff > 0){
|
||||
if($query->num_rows() == 0){
|
||||
$availableTimeArray[] = $currentStartTime;
|
||||
}
|
||||
}
|
||||
|
||||
elseif($dateDiff->format("%R%a") >= 0 && ($selectedDay < $tmpDateStart || $selectedDay > $tmpDateEnd) && $dateDiff->format("%R%a") != 0){
|
||||
if($query->num_rows() == 0){
|
||||
$availableTimeArray[] = $currentStartTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $availableTimeArray;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function createBooking($bookingArray){
|
||||
$this->load->database();
|
||||
$query = $this->db->query("INSERT INTO bookings (
|
||||
guest_name,
|
||||
guest_email,
|
||||
guest_phone,
|
||||
guest_addresse,
|
||||
guest_car_reg_number,
|
||||
guest_car_type,
|
||||
group_id,
|
||||
booking_date,
|
||||
booking_start_time,
|
||||
booking_finish_time,
|
||||
service_ids,
|
||||
guest_confirmed,
|
||||
guest_confirm_code
|
||||
) VALUES(
|
||||
'".$bookingArray['guest_name']."',
|
||||
'".$bookingArray['guest_email']."',
|
||||
'".$bookingArray['guest_phone']."',
|
||||
'".$bookingArray['guest_addresse']."',
|
||||
'".$bookingArray['guest_car_reg_number']."',
|
||||
'".$bookingArray['guest_car_type']."',
|
||||
'".$bookingArray['group_id']."',
|
||||
'".$bookingArray['booking_date']."',
|
||||
'".$bookingArray['booking_start_time']."',
|
||||
'".$bookingArray['booking_finish_time']."',
|
||||
'".$bookingArray['service_ids']."',
|
||||
'".$bookingArray['guest_confirmed']."',
|
||||
'".$bookingArray['guest_confirm_code']."'
|
||||
);");
|
||||
}
|
||||
|
||||
|
||||
public function iServiceAvailable($service_id){
|
||||
$this->load->database();
|
||||
$this->load->model('Group_model');
|
||||
|
||||
$isServiceActive = 0;
|
||||
$selectedService = $this->Service_model->getServiceById($service_id);
|
||||
$activeGroups = $this->Group_model->getAllActiveGroups();
|
||||
|
||||
if(is_array($activeGroups)){
|
||||
foreach($activeGroups as $activeGroupItem){
|
||||
$serviceIds = unserialize($activeGroupItem->skills);
|
||||
if(in_array($service_id, $serviceIds) && $selectedService->is_enabled){
|
||||
$isServiceActive = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $isServiceActive;
|
||||
}
|
||||
|
||||
|
||||
public function getServiceGroups(){
|
||||
$this->load->database();
|
||||
$this->load->model('Group_model');
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$services = $this->Service_model->getAvailableServices();
|
||||
$serviceArray = array();
|
||||
|
||||
if(is_array($services)){
|
||||
foreach($services as $serviceItem){
|
||||
if(!in_array($serviceItem->service_group, $serviceArray)){
|
||||
$serviceArray[] = $serviceItem->service_group;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $serviceArray;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,668 @@
|
||||
<?php
|
||||
class Service_model extends CI_Model {
|
||||
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function createService($serviceArray){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('INSERT INTO services (
|
||||
main_category,
|
||||
main_category_description,
|
||||
service_category,
|
||||
service_name,
|
||||
service_description,
|
||||
service_price,
|
||||
service_time,
|
||||
is_enabled
|
||||
) VALUES(
|
||||
"'.$serviceArray['main_category'].'",
|
||||
"'.$serviceArray['main_category_description'].'",
|
||||
"'.$serviceArray['service_category'].'",
|
||||
"'.$serviceArray['service_name'].'",
|
||||
"'.$serviceArray['service_description'].'",
|
||||
"'.$serviceArray['service_price'].'",
|
||||
"'.$serviceArray['service_time'].'",
|
||||
"'.$serviceArray['is_enabled'].'"
|
||||
);');
|
||||
}
|
||||
|
||||
public function updateService($service_id, $serviceArray){
|
||||
$this->load->database();
|
||||
|
||||
foreach($serviceArray as $propertyKey => $propertyValue){
|
||||
$query = $this->db->query('UPDATE services SET '.$propertyKey.' = "'.$propertyValue.'" WHERE service_id = "'.$service_id.'";');
|
||||
}
|
||||
}
|
||||
|
||||
public function updateBooking($booking_id, $bookingArray){
|
||||
$this->load->database();
|
||||
|
||||
foreach($bookingArray as $propertyKey => $propertyValue){
|
||||
$query = $this->db->query("UPDATE bookings SET ".$propertyKey." = '".$propertyValue."' WHERE booking_id = '".$booking_id."';");
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllServiceByServiceType(){
|
||||
$this->load->database();
|
||||
$this->load->model('Group_model');
|
||||
|
||||
$query = $this->db->query('SELECT * FROM services WHERE is_public = "1" AND is_deleted != "1" ORDER BY list_order_nr ASC;');
|
||||
$serviceArray = array();
|
||||
if($query->num_rows() > 0){
|
||||
foreach($query->result() as $resultItem){
|
||||
|
||||
$isServiceAvailable = $this->Service_model->iServiceAvailable($resultItem->service_id);
|
||||
|
||||
$resultItemTmp = array(
|
||||
'service_id' => $resultItem->service_id,
|
||||
'main_category' => $resultItem->main_category,
|
||||
'main_category_description' => $resultItem->main_category_description,
|
||||
'service_category' => $resultItem->service_category,
|
||||
'service_name' => $resultItem->service_name,
|
||||
'service_description' => $resultItem->service_description,
|
||||
'service_group' => $resultItem->service_group,
|
||||
'service_price' => $resultItem->service_price,
|
||||
'service_time' => $resultItem->service_time,
|
||||
'is_enabled' => $resultItem->is_enabled,
|
||||
'is_public' => $resultItem->is_public,
|
||||
'is_service_available' => $isServiceAvailable,
|
||||
'target_url' => $resultItem->target_url
|
||||
);
|
||||
|
||||
$serviceArray[] = (object)$resultItemTmp;
|
||||
}
|
||||
}
|
||||
return $serviceArray;
|
||||
}
|
||||
|
||||
public function getServiceById($service_id){
|
||||
$this->load->database();
|
||||
$this->load->model('Group_model');
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$query = $this->db->query('SELECT * FROM services WHERE service_id = "'.$service_id.'" LIMIT 1;');
|
||||
if($query->num_rows() > 0){
|
||||
$resultItem = $query->result()[0];
|
||||
|
||||
return $resultItem;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllServices(){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM services WHERE is_deleted != "1" ORDER BY service_name ASC;');
|
||||
|
||||
if($query->num_rows() > 0){
|
||||
foreach($query->result() as $resultItem){
|
||||
|
||||
$isServiceAvailable = $this->Service_model->iServiceAvailable($resultItem->service_id);
|
||||
|
||||
$resultItemTmp = array(
|
||||
'service_id' => $resultItem->service_id,
|
||||
'main_category' => $resultItem->main_category,
|
||||
'main_category_description' => $resultItem->main_category_description,
|
||||
'service_category' => $resultItem->service_category,
|
||||
'service_name' => $resultItem->service_name,
|
||||
'service_description' => $resultItem->service_description,
|
||||
'service_price' => $resultItem->service_price,
|
||||
'service_time' => $resultItem->service_time,
|
||||
'is_enabled' => $resultItem->is_enabled,
|
||||
'is_public' => $resultItem->is_public,
|
||||
'is_service_available' => $isServiceAvailable,
|
||||
'target_url' => $resultItem->target_url
|
||||
);
|
||||
|
||||
$serviceArray[] = (object)$resultItemTmp;
|
||||
}
|
||||
return $serviceArray;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAvailableServices(){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM services WHERE is_enabled = "1" AND is_deleted != "1" ORDER BY service_name ASC;');
|
||||
|
||||
if($query->num_rows() > 0){
|
||||
|
||||
$serviceArray = array();
|
||||
foreach($query->result() as $resultItem){
|
||||
$serviceTmp = array(
|
||||
'service_name' => $resultItem->service_name,
|
||||
'service_id' => $resultItem->service_id,
|
||||
'service_group' => $resultItem->service_group
|
||||
);
|
||||
|
||||
$serviceArray[] = (object)$serviceTmp;
|
||||
}
|
||||
return $serviceArray;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllServiceByGroups($serviceGroupArray){
|
||||
$this->load->database();
|
||||
$serviceGroupArrayString = implode(',', $serviceGroupArray);
|
||||
$query = $this->db->query('SELECT * FROM services
|
||||
WHERE
|
||||
is_deleted != "1" AND
|
||||
is_public = "1" AND
|
||||
service_group IN ('.$serviceGroupArrayString.')
|
||||
ORDER BY service_id ASC;');
|
||||
|
||||
$serviceArray = array();
|
||||
|
||||
if($query->num_rows() > 0){
|
||||
foreach($query->result() as $resultItem){
|
||||
|
||||
$isServiceAvailable = $this->Service_model->iServiceAvailable($resultItem->service_id);
|
||||
|
||||
$resultItemTmp = array(
|
||||
'service_id' => $resultItem->service_id,
|
||||
'main_category' => $resultItem->main_category,
|
||||
'main_category_description' => $resultItem->main_category_description,
|
||||
'service_category' => $resultItem->service_category,
|
||||
'service_name' => $resultItem->service_name,
|
||||
'service_description' => $resultItem->service_description,
|
||||
'service_group' => $resultItem->service_group,
|
||||
'is_extra' => $resultItem->is_extra,
|
||||
'is_car' => $resultItem->is_car,
|
||||
'service_price' => $resultItem->service_price,
|
||||
'service_time' => $resultItem->service_time,
|
||||
'is_enabled' => $resultItem->is_enabled,
|
||||
'is_public' => $resultItem->is_public,
|
||||
'is_service_available' => $isServiceAvailable,
|
||||
'target_url' => $resultItem->target_url
|
||||
);
|
||||
|
||||
$serviceArray[] = (object)$resultItemTmp;
|
||||
}
|
||||
}
|
||||
return $serviceArray;
|
||||
}
|
||||
|
||||
public function deleteBooking($booking_id){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('DELETE FROM bookings WHERE booking_id = "'.$booking_id.'";');
|
||||
}
|
||||
|
||||
public function getAllBookings(){
|
||||
$this->load->database();
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$query = $this->db->query('SELECT * FROM bookings ORDER BY booking_date DESC, booking_start_time ASC;');
|
||||
|
||||
if($query->num_rows() > 0){
|
||||
$resultsArray = array();
|
||||
foreach($query->result() as $resultItem){
|
||||
$resultTmp = (array)$resultItem;
|
||||
$groupObjectsArray = array();
|
||||
|
||||
if($resultTmp['group_ids'] != ''){
|
||||
$selectedGroups = explode(',', $resultTmp['group_ids']);
|
||||
if(is_array($selectedGroups)){
|
||||
foreach($selectedGroups as $selectedGroupItem){
|
||||
$selectedGroup = $this->Group_model->getGroupById($selectedGroupItem);
|
||||
$groupObjectsArray[] = $selectedGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
$resultTmp['workgroups'] = $groupObjectsArray;
|
||||
|
||||
if($resultTmp['service_ids'] != ''){
|
||||
$servicesArray = unserialize($resultTmp['service_ids']);
|
||||
if(is_array($servicesArray)){
|
||||
$services = array();
|
||||
foreach($servicesArray as $servicesArrayItem){
|
||||
$selectedService = $this->Service_model->getServiceById($servicesArrayItem);
|
||||
$services[] = (object)array(
|
||||
'service_name' => $selectedService->service_name,
|
||||
'service_price' => $selectedService->service_price,
|
||||
'service_time' => $selectedService->service_time
|
||||
);
|
||||
}
|
||||
$resultTmp['services'] = $services;
|
||||
}
|
||||
else{
|
||||
$resultTmp['services'] = array();
|
||||
}
|
||||
}
|
||||
else{
|
||||
$resultTmp['services'] = array();
|
||||
|
||||
}
|
||||
$resultsArray[] = (object)$resultTmp;
|
||||
}
|
||||
|
||||
|
||||
return $resultsArray;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getActualBookings(){
|
||||
$this->load->database();
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$query = $this->db->query('SELECT * FROM bookings JOIN workgroups ON bookings.group_id = workgroups.group_id WHERE booking_date >= CURDATE() ORDER BY booking_date DESC, booking_start_time ASC;');
|
||||
|
||||
if($query->num_rows() > 0){
|
||||
$resultsArray = array();
|
||||
foreach($query->result() as $resultItem){
|
||||
$resultTmp = (array)$resultItem;
|
||||
if($resultTmp['service_ids'] != ''){
|
||||
$servicesArray = unserialize($resultTmp['service_ids']);
|
||||
if(is_array($servicesArray)){
|
||||
$services = array();
|
||||
foreach($servicesArray as $servicesArrayItem){
|
||||
|
||||
$selectedService = $this->Service_model->getServiceById($servicesArrayItem['service_id']);
|
||||
$services[] = (object)array(
|
||||
'service_name' => $selectedService->service_name,
|
||||
'service_price' => $selectedService->service_price,
|
||||
'service_time' => $selectedService->service_time,
|
||||
'quantity' => $servicesArrayItem['quantity']
|
||||
);
|
||||
}
|
||||
$resultTmp['services'] = $services;
|
||||
}
|
||||
else{
|
||||
$resultTmp['services'] = array();
|
||||
}
|
||||
}
|
||||
else{
|
||||
$resultTmp['services'] = array();
|
||||
|
||||
}
|
||||
$resultsArray[] = (object)$resultTmp;
|
||||
}
|
||||
|
||||
|
||||
return $resultsArray;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getBookingById($booking_id){
|
||||
$this->load->database();
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$query = $this->db->query('SELECT * FROM bookings WHERE booking_id = "'.$booking_id.'" LIMIT 1;');
|
||||
if($query->num_rows() > 0){
|
||||
$resultTmp = (array)$resultItem;
|
||||
if($resultTmp['service_ids'] != ''){
|
||||
$servicesArray = unserialize($resultTmp['service_ids']);
|
||||
if(is_array($servicesArray)){
|
||||
$services = array();
|
||||
foreach($servicesArray as $servicesArrayItem){
|
||||
$selectedService = $this->Service_model->getServiceById($servicesArrayItem['service_id']);
|
||||
$services[] = (object)array(
|
||||
'service_name' => $selectedService->service_name,
|
||||
'service_price' => $selectedService->service_price,
|
||||
'service_time' => $selectedService->service_time,
|
||||
'quantity' => $servicesArrayItem['quantity']
|
||||
);
|
||||
}
|
||||
$resultTmp['services'] = $services;
|
||||
}
|
||||
else{
|
||||
$resultTmp['services'] = array();
|
||||
}
|
||||
}
|
||||
else{
|
||||
$resultTmp['services'] = array();
|
||||
|
||||
}
|
||||
$resultsArray = (object)$resultTmp;
|
||||
return $resultsArray;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getWorkgroupById($group_id){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM workgroups WHERE group_id = "'.$group_id.'" LIMIT 1;');
|
||||
if($query->num_rows() > 0){
|
||||
return $query->result()[0];
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAvailableTimes($group_id, $selectedDate, $servicelength){
|
||||
$this->load->database();
|
||||
$serviceLengthDateTime = new DateTime($selectedDate.' '.$servicelength);
|
||||
$service_length_time = strtotime($servicelength);
|
||||
$availableTimeArray = array();
|
||||
$selectedDayName = date('D', strtotime($selectedDate));
|
||||
$dayStartTime = new DateTime($selectedDate.' 09:00');
|
||||
$finishTime = new DateTime($selectedDate.' 18:01');
|
||||
if($selectedDayName == 'Sun'){
|
||||
return array();
|
||||
}
|
||||
elseif($selectedDayName == 'Sat'){
|
||||
$finishTime = new DateTime($selectedDate.' 18:01');
|
||||
}
|
||||
else{
|
||||
//finish time - selected service length
|
||||
$finishTime = new DateTime($selectedDate.' 18:01');
|
||||
|
||||
}
|
||||
|
||||
$today=date_create(date('Y-m-d'));
|
||||
$selectedDay=date_create($selectedDate);
|
||||
$dateDiff=date_diff($today,$selectedDay);
|
||||
|
||||
$tmpDateStart = date_create(date('2024-02-29'));
|
||||
$tmpDateEnd = date_create(date('2024-03-07'));
|
||||
|
||||
$datelength = new DateTime($servicelength);
|
||||
$diff = $datelength->diff($finishTime);
|
||||
|
||||
//max time for start
|
||||
$maxTime = $diff->h.':'.$diff->i.':00';
|
||||
$hours = (intval($diff->h)-9)*4+1;
|
||||
$mins = floor(intval($diff->i) / 15);
|
||||
$loopSteps = intval($hours) + intval($mins);
|
||||
|
||||
for($periodIndex = 1; $periodIndex <= $loopSteps; $periodIndex++){
|
||||
$minutes_to_add_start = $periodIndex*15;
|
||||
$minutes_to_add_end = ($periodIndex+1)*15;
|
||||
$startTime = new DateTime($selectedDate.' 08:45');
|
||||
$endTime = new DateTime($selectedDate.' 08:45');
|
||||
$startTime->add(new DateInterval('PT' . $minutes_to_add_start . 'M'));
|
||||
$endTime->add(new DateInterval('PT' . $minutes_to_add_end . 'M'));
|
||||
$maxTimeObject = new DateTime($maxTime);
|
||||
|
||||
$tz = new DateTimeZone('Europe/Budapest');
|
||||
$addStartTimeAndLength = new DateTime($selectedDate.' '.$startTime->format('H:i:00'), $tz);
|
||||
$addStartTimeAndLength->add(new DateInterval('PT' . intval($serviceLengthDateTime->format('H')) . 'H'));
|
||||
$addStartTimeAndLength->add(new DateInterval('PT' . intval($serviceLengthDateTime->format('i')) . 'M'));
|
||||
|
||||
$currentStartTime = $startTime->format('H:i:00');
|
||||
$currentEndTime = $endTime->format('H:i:00');
|
||||
|
||||
|
||||
|
||||
/*
|
||||
echo '<< ';
|
||||
print_r($serviceLengthDateTime->format('H:i:00'));
|
||||
echo ' / ';
|
||||
print_r($currentStartTime);
|
||||
echo ' / ';
|
||||
print_r($addStartTimeAndLength->format('H:i:00'));
|
||||
echo ' >>';
|
||||
*/
|
||||
/*
|
||||
$query = $this->db->query('SELECT * FROM bookings WHERE booking_date = "'.$selectedDate.'" AND group_id = "'.$group_id.'" AND (
|
||||
|
||||
(TIME(booking_start_time) >= CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) <= CAST("'.$currentEndTime.'" AS TIME)) OR
|
||||
|
||||
|
||||
(TIME(booking_start_time) <= CAST("'.$addStartTimeAndLength->format('H:i:00').'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME)) OR
|
||||
|
||||
|
||||
(TIME(booking_start_time) >= CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_start_time) <= CAST("'.$currentEndTime.'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME)) OR
|
||||
|
||||
|
||||
(TIME(booking_start_time) <= CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME)
|
||||
AND TIME(booking_start_time) <= CAST("'.$currentStartTime.'" AS TIME)) OR
|
||||
|
||||
|
||||
(TIME(booking_start_time) <= CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) <= CAST("'.$currentEndTime.'" AS TIME)
|
||||
AND TIME(booking_finish_time) >= CAST("'.$currentStartTime.'" AS TIME)) OR
|
||||
|
||||
|
||||
(TIME(booking_start_time) <= CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME))
|
||||
);
|
||||
');
|
||||
*/
|
||||
|
||||
|
||||
$query = $this->db->query('SELECT * FROM bookings WHERE booking_date = "'.$selectedDate.'" AND group_id = "'.$group_id.'" AND (
|
||||
/*start later and finish before*/
|
||||
(TIME(booking_start_time) > CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) < CAST("'.$currentEndTime.'" AS TIME)) OR
|
||||
|
||||
/*check if not end service until next booking*/
|
||||
(TIME(booking_start_time) < CAST("'.$addStartTimeAndLength->format('H:i:00').'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME)) OR
|
||||
|
||||
/*start later and finish later*/
|
||||
(TIME(booking_start_time) > CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_start_time) < CAST("'.$currentEndTime.'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME)) OR
|
||||
|
||||
/*start before and finish before*/
|
||||
(TIME(booking_start_time) < CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME)
|
||||
AND TIME(booking_start_time) < CAST("'.$currentStartTime.'" AS TIME)) OR
|
||||
|
||||
/**/
|
||||
(TIME(booking_start_time) < CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) < CAST("'.$currentEndTime.'" AS TIME)
|
||||
AND TIME(booking_finish_time) > CAST("'.$currentStartTime.'" AS TIME)) OR
|
||||
|
||||
/**/
|
||||
(TIME(booking_start_time) < CAST("'.$currentStartTime.'" AS TIME) AND TIME(booking_finish_time) >= CAST("'.$currentEndTime.'" AS TIME))
|
||||
);
|
||||
');
|
||||
|
||||
$now = strtotime(date('H:i:s')) + 60*60;
|
||||
$timezone = 'Europe/Budapest';
|
||||
$todayStartTime = strtotime($currentStartTime.' '.$timezone);
|
||||
$minDiff = ($todayStartTime - $now) / 60;
|
||||
|
||||
|
||||
if($dateDiff->format("%R%a") == 0 && $minDiff > 0){
|
||||
if($query->num_rows() == 0){
|
||||
$availableTimeArray[] = $currentStartTime;
|
||||
}
|
||||
}
|
||||
|
||||
elseif($dateDiff->format("%R%a") >= 0 && ($selectedDay < $tmpDateStart || $selectedDay > $tmpDateEnd) && $dateDiff->format("%R%a") != 0){
|
||||
if($query->num_rows() == 0){
|
||||
$availableTimeArray[] = $currentStartTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $availableTimeArray;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function createBooking($bookingArray){
|
||||
$this->load->database();
|
||||
$query = $this->db->query("INSERT INTO bookings (
|
||||
guest_name,
|
||||
guest_email,
|
||||
guest_phone,
|
||||
guest_addresse,
|
||||
guest_car_reg_number,
|
||||
guest_car_type,
|
||||
group_id,
|
||||
booking_date,
|
||||
booking_start_time,
|
||||
booking_finish_time,
|
||||
service_ids,
|
||||
guest_confirmed,
|
||||
guest_confirm_code
|
||||
) VALUES(
|
||||
'".$bookingArray['guest_name']."',
|
||||
'".$bookingArray['guest_email']."',
|
||||
'".$bookingArray['guest_phone']."',
|
||||
'".$bookingArray['guest_addresse']."',
|
||||
'".$bookingArray['guest_car_reg_number']."',
|
||||
'".$bookingArray['guest_car_type']."',
|
||||
'".$bookingArray['group_id']."',
|
||||
'".$bookingArray['booking_date']."',
|
||||
'".$bookingArray['booking_start_time']."',
|
||||
'".$bookingArray['booking_finish_time']."',
|
||||
'".$bookingArray['service_ids']."',
|
||||
'".$bookingArray['guest_confirmed']."',
|
||||
'".$bookingArray['guest_confirm_code']."'
|
||||
);");
|
||||
}
|
||||
|
||||
|
||||
public function iServiceAvailable($service_id){
|
||||
$this->load->database();
|
||||
$this->load->model('Group_model');
|
||||
|
||||
$isServiceActive = 0;
|
||||
$selectedService = $this->Service_model->getServiceById($service_id);
|
||||
$activeGroups = $this->Group_model->getAllActiveGroups();
|
||||
|
||||
if(is_array($activeGroups)){
|
||||
foreach($activeGroups as $activeGroupItem){
|
||||
$serviceIds = unserialize($activeGroupItem->skills);
|
||||
if(in_array($service_id, $serviceIds) && $selectedService->is_enabled){
|
||||
$isServiceActive = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $isServiceActive;
|
||||
}
|
||||
|
||||
|
||||
public function getServiceGroups(){
|
||||
$this->load->database();
|
||||
$this->load->model('Group_model');
|
||||
$this->load->model('Service_model');
|
||||
|
||||
$services = $this->Service_model->getAvailableServices();
|
||||
$serviceArray = array();
|
||||
|
||||
if(is_array($services)){
|
||||
foreach($services as $serviceItem){
|
||||
if(!in_array($serviceItem->service_group, $serviceArray)){
|
||||
$serviceArray[] = $serviceItem->service_group;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $serviceArray;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
require getcwd().'/vendor/autoload.php';
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
|
||||
class User_model extends CI_Model {
|
||||
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function userCanLogin($username, $password){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM users WHERE username = "'.$username.'" AND password = "'.hash('sha256', $password).'" AND is_enabled = 1 LIMIT 1');
|
||||
|
||||
if($query->num_rows() == 1){
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllUser(){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM users JOIN permissions ON users.permission_slug = permissions.permission_slug ORDER BY fullname ASC');
|
||||
$userResults = $query->result();
|
||||
|
||||
foreach($userResults as $userResultItem){
|
||||
if($userResultItem->profile_img_url == ''){
|
||||
$userResultItem->profile_img_url = base_url().'img/default_profile.jpg';
|
||||
}
|
||||
}
|
||||
return $userResults;
|
||||
}
|
||||
|
||||
public function getUserByUsername($username){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM users JOIN permissions ON users.permission_slug = permissions.permission_slug WHERE username = "'.$username.'" LIMIT 1');
|
||||
if($query->num_rows() == 1){
|
||||
|
||||
if($query->result()[0]->profile_img_url == ''){
|
||||
$query->result()[0]->profile_img_url = base_url().'img/default_profile.jpg';
|
||||
}
|
||||
return $query->result()[0];
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllUserPermission(){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM permissions;');
|
||||
if($query->num_rows() > 0){
|
||||
return $query->result();
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public function getUserById($userId){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM users JOIN permissions ON users.permission_slug = permissions.permission_slug WHERE user_id = "'.$userId.'" LIMIT 1');
|
||||
if($query->num_rows() == 1){
|
||||
if($query->result()[0]->profile_img_url == ''){
|
||||
$query->result()[0]->profile_img_url = base_url().'img/default_profile.jpg';
|
||||
}
|
||||
return $query->result()[0];
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteUser($userId){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('DELETE FROM users WHERE user_id = "'.$userId.'";');
|
||||
}
|
||||
|
||||
public function isUsernameAvailable($username){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM users WHERE username = "'.$username.'";');
|
||||
if($query->num_rows() == 1){
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public function updateUser($userId, $userArray){
|
||||
$this->load->database();
|
||||
|
||||
foreach($userArray as $propertyKey => $propertyValue){
|
||||
$query = $this->db->query('UPDATE users SET '.$propertyKey.' = "'.$propertyValue.'" WHERE user_id = "'.$userId.'";');
|
||||
}
|
||||
}
|
||||
|
||||
public function addNewUser($userArray){
|
||||
$this->load->database();
|
||||
|
||||
if(!is_object($this->getUserByUsername($userArray['username']))){
|
||||
$query = $this->db->query('INSERT INTO users (username, password, fullname, permission_slug, is_enabled, user_notes) VALUES("'.$userArray['username'].'", "'.hash('sha256', $userArray['password']).'", "'.$userArray['fullname'].'", "'.$userArray['permission_slug'].'", "'.$userArray['is_enabled'].'", "'.$userArray['user_notes'].'");');
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getAllUserGroup(){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM permissions ORDER BY permission_name ASC;');
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function getPermissionById($groupId){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM permissions WHERE permission_id = "'.$groupId.'" LIMIT 1;');
|
||||
return $query->result()[0];
|
||||
}
|
||||
|
||||
public function getPermissionBySlug($permission_slug){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM permissions WHERE permission_slug = "'.$permission_slug.'" LIMIT 1;');
|
||||
return $query->result()[0];
|
||||
}
|
||||
|
||||
public function sendEmail($addressList){
|
||||
// Import PHPMailer classes into the global namespace
|
||||
// These must be at the top of your script, not inside a function
|
||||
if(!empty($addressList)){
|
||||
foreach($addressList as $addressListItem){
|
||||
// Instantiation and passing `true` enables exceptions
|
||||
$mail = new PHPMailer(false);
|
||||
$mail->SMTPDebug = false;
|
||||
$mail->do_debug = 1;
|
||||
try {
|
||||
//Server settings
|
||||
$mail->CharSet = 'UTF-8';
|
||||
//$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
|
||||
$mail->isSMTP(); //Send using SMTP
|
||||
$mail->Host = 'mail.absolutesolution.hu'; //Set the SMTP server to send through
|
||||
$mail->SMTPAuth = true; //Enable SMTP authentication
|
||||
$mail->Username = 'timebestilling@dinbestehjelper.no'; //SMTP username
|
||||
$mail->Password = 'sudvym-1jydZe-wewtic'; //SMTP password
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
|
||||
$mail->Port = 465; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
|
||||
|
||||
//Recipients
|
||||
$mail->setFrom('timebestilling@dinbestehjelper.no', '[dinbestehjelper]');
|
||||
$mail->addAddress($addressListItem['addressee_email'], $addressListItem['addressee_name']); // Add a recipient
|
||||
//$mail->addAddress('ellen@example.com'); // Name is optional
|
||||
//$mail->addReplyTo('info@example.com', 'Information');
|
||||
$mail->addCC('timebestilling@dinbestehjelper.no');
|
||||
//$mail->addBCC('bcc@example.com');
|
||||
|
||||
// Attachments
|
||||
if(is_array($addressListItem['attachments'])){
|
||||
$attachments = $addressListItem['attachments'];
|
||||
foreach($attachments as $attachmentsItem){
|
||||
$mail->addAttachment(getcwd().'/documents/'.$attachmentsItem); // Add attachments
|
||||
}
|
||||
}
|
||||
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
|
||||
|
||||
// Content
|
||||
$mail->isHTML(true); // Set email format to HTML
|
||||
$mail->Subject = $addressListItem['subject'];
|
||||
ob_start();
|
||||
$body = ob_get_clean();
|
||||
$body .= $addressListItem['content'];
|
||||
|
||||
$mail->Body = $body;
|
||||
//$mail->AltBody = strip_tags($answer_message);
|
||||
|
||||
$mail->send();
|
||||
echo 'Üzenet elküldve';
|
||||
//header('location:'.base_url().'quotation-finished/');
|
||||
|
||||
} catch (Exception $e) {
|
||||
//header('location:'.base_url().'manage-applicants/?email-sent=false&error='.$mail->ErrorInfo);
|
||||
echo "Üzenetküldési hiba. Mailer Error: {$mail->ErrorInfo}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function is_user_admin($username){
|
||||
$this->load->database();
|
||||
$query = $this->db->query('SELECT * FROM users JOIN permissions ON users.permission_slug = permissions.permission_slug WHERE username = "'.$username.'" LIMIT 1');
|
||||
if($query->num_rows() == 1){
|
||||
if($query->result()[0]->permission_slug == 'admin'){
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user