Initial ui support

This commit is contained in:
Matteo Gheza 2021-04-04 01:11:46 +02:00
parent 6600361315
commit 994cc57fe7
6 changed files with 116 additions and 7 deletions

View File

@ -11,7 +11,8 @@
"ezyang/htmlpurifier": "^4.13",
"brick/phonenumber": "^0.2.2",
"sentry/sdk": "^3.1",
"maximebf/debugbar": "^1.16"
"maximebf/debugbar": "^1.16",
"azuyalabs/yasumi": "^2.3"
},
"license": "GPL-3.0-or-later",
"authors": [

72
server/composer.lock generated
View File

@ -4,8 +4,78 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "70f094e636bc55d808d812581dddc0b3",
"content-hash": "6ed99ceb745c54c207e4366b68ef0637",
"packages": [
{
"name": "azuyalabs/yasumi",
"version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/azuyalabs/yasumi.git",
"reference": "e2f37e6de3b15642b83275a24bbfe101cd5c7791"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/azuyalabs/yasumi/zipball/e2f37e6de3b15642b83275a24bbfe101cd5c7791",
"reference": "e2f37e6de3b15642b83275a24bbfe101cd5c7791",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": ">=7.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"fzaninotto/faker": "^1.9",
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^8.5"
},
"suggest": {
"ext-calendar": "For calculating the date of Easter"
},
"type": "library",
"autoload": {
"psr-4": {
"Yasumi\\": "src/Yasumi/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Sacha Telgenhof",
"email": "me@sachatelgenhof.com",
"role": "Maintainer"
}
],
"description": "The easy PHP Library for calculating holidays.",
"homepage": "https://www.yasumi.dev",
"keywords": [
"Bank",
"calculation",
"calendar",
"celebration",
"date",
"holiday",
"holidays",
"national",
"time"
],
"support": {
"docs": "https://www.yasumi.dev",
"issues": "https://github.com/azuyalabs/yasumi/issues",
"source": "https://github.com/azuyalabs/yasumi"
},
"funding": [
{
"url": "https://www.buymeacoffee.com/sachatelgenhof",
"type": "other"
}
],
"time": "2020-06-22T12:46:20+00:00"
},
{
"name": "brick/phonenumber",
"version": "0.2.2",

View File

@ -347,6 +347,7 @@ class user
private $profile_names = null;
public $auth = null;
public $authenticated = false;
public $holidays = null;
public function __construct($database, $tools)
{
@ -376,6 +377,7 @@ class user
$this->authenticated = $this->auth->isLoggedIn();
$this->profile_names = $this->database->exec("SELECT `id`, `name` FROM `%PREFIX%_profiles`;", true);
$this->user_names = $this->database->exec("SELECT `id`, `username` FROM `%PREFIX%_users`;", true);
$this->holidays = Yasumi\Yasumi::create($this->database->get_option("holidays_provider") ?: "USA", date("Y"), $this->database->get_option("holidays_language") ?: "en_US");
}
public function authenticated()

View File

@ -424,6 +424,7 @@ CREATE TABLE `".$prefix."_schedules` (
`user` INT NOT NULL,
`profile_name` VARCHAR(500) NOT NULL DEFAULT 'default',
`schedules` VARCHAR(10000) NULL DEFAULT NULL,
`holidays` VARCHAR(10000) NULL DEFAULT NULL,
`last_exec` VARCHAR(7) NULL DEFAULT NULL,
`last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
@ -499,7 +500,9 @@ function initOptions($name, $visible, $developer, $password, $report_email, $own
'training_remove' => 1,
'use_location_picker' => 1,
'force_language' => 0,
'force_remember_cookie' => 0
'force_remember_cookie' => 0,
'holidays_provider' => 'USA',
'holidays_language' => 'en_US'
];
$query = "";
foreach ($options as $key => $value) {

View File

@ -52,8 +52,10 @@ if(!empty($result)){
$hour = $hour[0] == "0" ? substr($hour,1) : $hour;
$old_schedules[$schedule[0]][$hour] = true;
}
$old_holidays = json_decode($result[0]["holidays"]);
} else {
$old_schedules = [];
$old_holidays = [];
}
?>
<style>
@ -127,6 +129,33 @@ endif;
</tbody>
</table>
<br>
<?php
//TODO: translate strings
echo(<<<EOL
<div class="form-group">
<label>Vuoi escudere giorni festivi dalla programmazione degli orari?</label>
<a onclick="$('.holiday_check').prop('checked', true);" class="text-primary">Seleziona tutti</a> / <a onclick="$('.holiday_check').prop('checked', false);" class="text-primary">Rimuovi selezioni</a>
EOL);
$i = 0;
foreach ($user->holidays as $holiday) {
$i++;
$holiday_name = $holiday->getName();
$holiday_shortname = $holiday->shortName;
$is_holiday_selected = in_array($holiday_shortname, $old_holidays) ? "checked" : "";
echo(<<<EOT
<div class="form-check">
<input class="form-check-input holiday_check" name="holiday_check" type="checkbox" value="{$holiday_shortname}" id="holidayCheckbox{$i}" {$is_holiday_selected}>
<label class="form-check-label" for="holidayCheckbox{$i}">
{$holiday_name} ({$holiday})
</label>
</div>
EOT);
}
echo("</div>");
?>
<script>
function init_modal() {
<?php if($orienation == "landscape"){ ?>$(".modal-dialog").css("max-width", "99%");<?php } ?>
@ -218,11 +247,13 @@ function extractSelections(){
function submit_changes(){
let hours = extractSelections();
let holidays = $.map($('input[name="holiday_check"]:checked'), function(c){return c.value; });
$.ajax({
url: "resources/ajax/ajax_availability_schedule.php",
method: "POST",
data: {
hours: hours
hours: hours,
holidays: holidays
},
success: function (data) {
console.log(data);

View File

@ -7,15 +7,17 @@ $user_id = $user->auth->getUserId();
$result = $database->exec("SELECT * FROM `%PREFIX%_schedules` WHERE `user`={$user_id};", true);
if(!empty($result)){
$result[0]["schedules"] = json_decode($result[0]["schedules"]);
$result[0]["holidays"] = json_decode($result[0]["holidays"]);
}
if(isset($_POST["hours"])){
$hours = (string) json_encode($_POST["hours"]);
echo($hours);
$holidays = (string) json_encode($_POST["holidays"]);
echo($hours."-".$holidays);
if(!empty($result)){
$database->exec("UPDATE `%PREFIX%_schedules` SET `schedules` = :schedules WHERE `id` = :id;", false, [":id" => $result[0]["id"], ":schedules" => $hours]);
$database->exec("UPDATE `%PREFIX%_schedules` SET schedules = :schedules, holidays = :holidays WHERE `id` = :id;", false, [":id" => $result[0]["id"], ":schedules" => $hours, ":holidays" => $holidays]);
} else {
$database->exec("INSERT INTO `%PREFIX%_schedules` (`user`, `schedules`) VALUES (:user, :schedules);", false, [":user" => $user_id, ":schedules" => $hours]);
$database->exec("INSERT INTO `%PREFIX%_schedules` (`user`, `schedules`, `holidays`) VALUES (:user, :schedules, :holidays);", false, [":user" => $user_id, ":schedules" => $hours, ":holidays" => $holidays]);
}
} else {
echo(json_encode(empty($result) ? [] : $result[0]));