Same thing for trainings
This commit is contained in:
parent
6f1c786efb
commit
f7c54c0dfd
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
require_once 'ui.php';
|
||||
if($tools->validate_form_data('$post-mod', true, "add")) {
|
||||
if($tools->validate_form_data(['$post-data', '$post-name', '$post-start_time', '$post-end_time', '$post-capo', '$post-luogo', '$post-note', '$post-token'])) {
|
||||
if($tools->validate_form_data(['$post-data', '$post-name', '$post-start_time', '$post-end_time', '$post-luogo', '$post-note', '$post-token'])) {
|
||||
if($_POST["token"] == $_SESSION['token']){
|
||||
bdump("adding training");
|
||||
$database->add_training($_POST["data"], $_POST["name"], $_POST["start_time"], $_POST["end_time"], $_POST["capo"], $tools->extract_unique($_POST["personale"]), $_POST["luogo"], $_POST["note"], $tools->extract_unique([$_POST["capo"],$_POST["personale"]]), $user->name());
|
||||
$database->add_training($_POST["data"], $_POST["name"], $_POST["start_time"], $_POST["end_time"], $_POST["capo"][0], $tools->extract_unique($_POST["personale"]), $_POST["luogo"], $_POST["note"], $tools->extract_unique([$_POST["capo"],$_POST["personale"]]), $user->name());
|
||||
$tools->redirect("trainings.php");
|
||||
} else {
|
||||
$tools->redirect("accessdenied.php");
|
||||
|
@ -15,7 +15,7 @@ if($tools->validate_form_data('$post-mod', true, "add")) {
|
|||
if($_POST["token"] == $_SESSION['token']){
|
||||
bdump($_POST);
|
||||
bdump("editing training");
|
||||
$database->change_training($_POST["id"], $_POST["data"], $_POST["name"], $_POST["start_time"], $_POST["end_time"], $_POST["capo"], $tools->extract_unique($_POST["personale"]), $_POST["luogo"], $_POST["note"], $tools->extract_unique([$_POST["capo"],$_POST["personale"]]), $user->name());
|
||||
$database->change_training($_POST["id"], $_POST["data"], $_POST["name"], $_POST["start_time"], $_POST["end_time"], $_POST["capo"][0], $tools->extract_unique($_POST["personale"]), $_POST["luogo"], $_POST["note"], $tools->extract_unique([$_POST["capo"],$_POST["personale"]]), $user->name());
|
||||
$tools->redirect("trainings.php");
|
||||
} else {
|
||||
$tools->redirect("accessdenied.php");
|
||||
|
@ -58,7 +58,7 @@ if($tools->validate_form_data('$post-mod', true, "add")) {
|
|||
if(empty($id)){
|
||||
$tools->redirect("accessdenied.php");
|
||||
} elseif (!$database->exists("trainings", $id)){
|
||||
//$tools->redirect("accessdenied.php");
|
||||
$tools->redirect("accessdenied.php");
|
||||
}
|
||||
}
|
||||
loadtemplate('edit_training.html', ['training' => ['id' => $id, 'token' => $_SESSION['token'], 'modalità' => $modalità, 'personale' => $personale], 'values' => $values, 'increment' => $increment, 'title' => ucfirst($modalità) . ' '.ucfirst(t("training",false))]);
|
||||
|
|
|
@ -472,6 +472,8 @@ INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_ti
|
|||
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES (NULL, 'cron_job_time', :cron_job_time, 1, current_timestamp(), current_timestamp(), '1');
|
||||
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES (NULL, 'service_edit', 1, 1, current_timestamp(), current_timestamp(), '1');
|
||||
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES (NULL, 'service_remove', 1, 1, current_timestamp(), current_timestamp(), '1');
|
||||
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES (NULL, 'training_edit', 1, 1, current_timestamp(), current_timestamp(), '1');
|
||||
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES (NULL, 'training_remove', 1, 1, current_timestamp(), current_timestamp(), '1');
|
||||
$option_check_cf_ip");
|
||||
mt_srand(10);
|
||||
$prep->bindValue(':hidden', ($visible ? 0 : 1), PDO::PARAM_INT);
|
||||
|
|
|
@ -3,49 +3,30 @@ include_once("../../core.php");
|
|||
init_class();
|
||||
$user->requirelogin(false);
|
||||
|
||||
$impostazioni['edit'] = true;
|
||||
$impostazioni['delete'] = true;
|
||||
$risultato = $database->exec("SELECT * FROM `%PREFIX%_trainings` ORDER BY data DESC, inizio desc", true);
|
||||
|
||||
$risultato = $database->exec("SELECT * FROM `%PREFIX%_trainings` ORDER BY data DESC, inizio desc", true); // Pesco i dati della table e li ordino in base alla data
|
||||
?>
|
||||
<div style='margin: 20px 0;' class="mx-auto">
|
||||
<div style='margin: 2px auto' id="new-search-area"></div>
|
||||
<div class="table-responsive">
|
||||
<div style="overflow-x:auto;">
|
||||
<table id="trainings" cellspacing='0' class="display table table-striped table-bordered dt-responsive nowrap" style="width: 90%; text-align:center;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php t("Date"); ?></th>
|
||||
<th><?php t("Name"); ?></th>
|
||||
<th><?php t("Start time"); ?></th>
|
||||
<th><?php t("End time"); ?></th>
|
||||
<th><?php t("Chief"); ?></th>
|
||||
<th><?php t("People"); ?></th>
|
||||
<th><?php t("Place"); ?></th>
|
||||
<th><?php t("Notes"); ?></th>
|
||||
<?php if($impostazioni['edit']) { echo "<th>".t("Edit", false)."</th>"; } ?>
|
||||
<?php if($impostazioni['delete']) { echo "<th>".t("Remove", false)."</th>"; } ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$response = [];
|
||||
foreach($risultato as $row){
|
||||
$chief = $user->nameById($row["capo"]);
|
||||
$others_people = "";
|
||||
foreach(explode(",", $row['personale']) as $key=>$name){
|
||||
$others_people = $others_people.$user->nameById($name).", ";
|
||||
}
|
||||
echo "<tr><td>" . $row['data'] . "</td><td>" . $row['name'] . "</td><td>" . $row['inizio'] . "</td><td>" . $row['fine'] . "</td><td>" . $chief . "</td><td>" . $others_people . "</td><td>" . $row['luogo'] . "</td><td>" . $row['note'] . "</td>";
|
||||
if($impostazioni['edit']) {
|
||||
echo "<td><a href='edit_training.php?edit&id={$row['id']}'><i style='font-size: 40px' class='fa fa-edit'></i></a></td>";
|
||||
}
|
||||
if($impostazioni['delete']) {
|
||||
echo "<td><a href='edit_training.php?delete&id={$row['id']}&increment={$row['increment']}'><i style='font-size: 40px' class='fa fa-trash'></i></a></td></tr>";
|
||||
}
|
||||
$chief = $user->nameById($row["capo"]);
|
||||
|
||||
$others_people_array = explode(",", $row['personale']);
|
||||
foreach($others_people_array as $key=>$name){
|
||||
$others_people_array[$key] = $user->nameById($name);
|
||||
}
|
||||
$others_people = implode(", ", $others_people_array);
|
||||
$response[] = [
|
||||
$row['data'],
|
||||
$row['name'],
|
||||
$row['inizio'],
|
||||
$row['fine'],
|
||||
$chief,
|
||||
$others_people,
|
||||
s($row['luogo'],false,true),
|
||||
s($row['note'],false,true),
|
||||
$database->getOption("training_edit") ? "<a href='edit_service.php?edit&id={$row['id']}'><i style='font-size: 40px' class='fa fa-edit'></i></a>" : null,
|
||||
$database->getOption("training_remove") ? "<a href='edit_service.php?delete&id={$row['id']}&increment={$row['increment']}'><i style='font-size: 40px' class='fa fa-trash'></i></a>" : null
|
||||
];
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
header("Content-type: application/json");
|
||||
print(json_encode($response));
|
||||
?>
|
|
@ -2,147 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<link href="favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pikaday/1.6.1/css/pikaday.min.css" integrity="sha256-QeBQ7yamXxr4+oYQSRzluL3bLLul8ZpZO4Q/AmI+rvM=" crossorigin="anonymous" />
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pikaday/1.6.1/pikaday.min.js" integrity="sha256-nzvGziG948yQHPWFJCynD1AmNPBwYWY2nVZYaDCpq4E=" crossorigin="anonymous"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.5.0.min.js" integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/pikaday@1.7.0/plugins/pikaday.jquery.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js" integrity="sha256-CutOzxCRucUsn6C6TcEYsauvvYilEniTXldPa6/wu0k=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/locale/it.js" integrity="sha256-D8y560ZGsKY1LoAajKkQCG7y0Vkye361MH4yFv2K5kk=" crossorigin="anonymous"></script>
|
||||
<style>
|
||||
/* https://stackoverflow.com/a/44280071 */
|
||||
.checkbox label:after {
|
||||
content: '';
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.checkbox .cr {
|
||||
position: relative;
|
||||
border: 1px solid #a9a9a9;
|
||||
border-radius: .25em;
|
||||
width: 1.3em;
|
||||
height: 1.3em;
|
||||
float: left;
|
||||
margin-right: .5em;
|
||||
}
|
||||
|
||||
.checkbox .cr .cr-icon {
|
||||
position: absolute;
|
||||
font-size: .8em;
|
||||
line-height: 0;
|
||||
top: 50%;
|
||||
left: 15%;
|
||||
}
|
||||
|
||||
.checkbox label input[type="checkbox"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.checkbox label input[type="checkbox"]+.cr>.cr-icon {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.checkbox label input[type="checkbox"]:checked+.cr>.cr-icon {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.checkbox label input[type="checkbox"]:disabled+.cr {
|
||||
opacity: .5;
|
||||
}
|
||||
</style>
|
||||
<style>
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 60px;
|
||||
height: 34px;
|
||||
}
|
||||
|
||||
.switch input {display:none;}
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #ccc;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
}
|
||||
|
||||
.slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 26px;
|
||||
width: 26px;
|
||||
left: 4px;
|
||||
bottom: 4px;
|
||||
background-color: white;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
}
|
||||
|
||||
input:checked + .slider {
|
||||
background-color: #2196F3;
|
||||
}
|
||||
|
||||
input:focus + .slider {
|
||||
box-shadow: 0 0 1px #2196F3;
|
||||
}
|
||||
|
||||
input:checked + .slider:before {
|
||||
-webkit-transform: translateX(26px);
|
||||
-ms-transform: translateX(26px);
|
||||
transform: translateX(26px);
|
||||
}
|
||||
|
||||
/* Rounded sliders */
|
||||
.slider.round {
|
||||
border-radius: 34px;
|
||||
}
|
||||
|
||||
.slider.round:before {
|
||||
border-radius: 50%;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
function zeroes(number, length) {
|
||||
var my_string = '' + number;
|
||||
while (my_string.length < length) {
|
||||
my_string = '0' + my_string;
|
||||
}
|
||||
|
||||
return my_string;
|
||||
}
|
||||
|
||||
// activate datepickers for all elements with a class of `datepicker`
|
||||
$('.datepicker').pikaday({
|
||||
i18n: {
|
||||
months: ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'],
|
||||
weekdays: ['Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato'],
|
||||
weekdaysShort: ['Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab'],
|
||||
today: 'oggi',
|
||||
clear: 'cancella',
|
||||
},
|
||||
firstDay: 1 ,
|
||||
toString(date, format) {
|
||||
// you should do formatting based on the passed format,
|
||||
// but we will just return 'D/M/YYYY' for simplicity
|
||||
var day = zeroes(date.getDate(), 2);
|
||||
var month = zeroes(date.getMonth() + 1, 2);
|
||||
var year = date.getFullYear();
|
||||
var dat = year + '-' + month + '-' + day;
|
||||
return dat;
|
||||
}});
|
||||
|
||||
// chain a few methods for the first datepicker, jQuery style!
|
||||
$('.datepicker').eq(0).pikaday('show');
|
||||
});
|
||||
</script>
|
||||
<script src="resources/dist/main.js"></script>
|
||||
</head>
|
||||
<style>
|
||||
form {
|
||||
|
@ -208,34 +68,38 @@ textarea {
|
|||
<form method="post">
|
||||
<div class="container">
|
||||
<label><b>{{ 'Training day'|t }}</b></label>
|
||||
<input autocomplete="off" class="datepicker" name="data" placeholder="DD/MM/YYY" type="text" value="{{ values.data }}">
|
||||
<div class="input-group">
|
||||
<input placeholder="DD/MM/YYY" autocomplete="off" name="data" data-provide="datepicker" value="{{ values.data }}" type="text" class="form-control">
|
||||
<div class="input-group-addon">
|
||||
<span class="glyphicon glyphicon-th"></span>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
<label><b>{{ 'Name'|t }}</b></label>
|
||||
<input id="name" type="text" name="name" placeholder="1° training" required value="{{ values.name }}">
|
||||
<br>
|
||||
<br>
|
||||
<label><b>{{ 'Start time'|t }}</b></label>
|
||||
<input type="time" name="start_time" required value="{{ values.inizio }}">
|
||||
<label for="timePicker1"><b>{{ 'Start time'|t }}</b></label>
|
||||
<input id="timePicker1" type="time" name="start_time" required value="{{ values.inizio }}">
|
||||
<br>
|
||||
<br>
|
||||
<label><b>{{ 'End time'|t }}</b></label>
|
||||
<input type="time" name="end_time" required value="{{ values.fine }}">
|
||||
<label for="timePicker2"><b>{{ 'End time'|t }}</b></label>
|
||||
<input id="timePicker2" type="time" name="end_time" required value="{{ values.fine }}">
|
||||
<br>
|
||||
<br>
|
||||
<label><b>{{ 'Chief'|t }}</b></label>
|
||||
<br>
|
||||
{% for user in training.personale %}
|
||||
<div {{ user.name == "test" ? "style='display: none'" : "" }} class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name='capo' value='{{ user.id }}'>
|
||||
<span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>
|
||||
{{ user.name }}
|
||||
<div {{ user.name == "test" ? "style='display: none'" : "" }} class="form-check">
|
||||
<input class="form-check-input capo capo-{{ user.id }}" style="transform: scale(1.4); -webkit-transform: scale(1.4);" type="checkbox" name='capo[]' value='{{ user.id }}'>
|
||||
<label class="form-check-label" for="capo-{{ user.id }}">
|
||||
{{ username(user.id) }}
|
||||
</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<script>
|
||||
$('input[name="capo"]').on('change', function() {
|
||||
$('.capo').on('change', function() {
|
||||
$('input[name="' + this.name + '"]').not(this).prop('checked', false);
|
||||
});
|
||||
</script>
|
||||
|
@ -243,11 +107,10 @@ textarea {
|
|||
<label><b>{{ 'Others people'|t }}</b></label>
|
||||
<br>
|
||||
{% for user in training.personale %}
|
||||
<div {{ user.name == "test" ? "style='display: none'" : "" }} class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name='personale[]' value='{{ user.id }}'>
|
||||
<span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>
|
||||
{{ user.name }}
|
||||
<div {{ user.name == "test" ? "style='display: none'" : "" }} class="form-check">
|
||||
<input class="form-check-input personale personale-{{ user.id }}" style="transform: scale(1.4); -webkit-transform: scale(1.4);" type="checkbox" name='personale[]' value='{{ user.id }}'>
|
||||
<label class="form-check-label" for="personale-{{ user.id }}">
|
||||
{{ username(user.id) }}
|
||||
</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
@ -260,14 +123,14 @@ textarea {
|
|||
<textarea name='note'></textarea>
|
||||
<br>
|
||||
<br>
|
||||
<input id="modalità" type="hidden" value="{{ service.modalità }}" name="mod"></input>
|
||||
<input id="modalità" type="hidden" value="{{ training.modalità }}" name="mod"></input>
|
||||
<input id="id" type="hidden" value="{{ training.id }}" name="id"></input>
|
||||
<input id="token" type="hidden" value="{{ training.token }}" name="token"></input>
|
||||
<button type="submit">{{ 'Submit'|t }}</button>
|
||||
</div>
|
||||
</form>
|
||||
<script>
|
||||
//No js Visual Studio Code errors {% if service.modalità == "edit" %}
|
||||
{% if training.modalità == "edit" %}
|
||||
$.each('{{ values.capo|striptags|e("js") }}'.split(','), function( index, value ) {
|
||||
$('.capo-'+value).prop('checked', true);
|
||||
});
|
||||
|
@ -275,7 +138,7 @@ $.each('{{ values.personale|striptags|e("js") }}'.split(','), function( index, v
|
|||
$('.personale-'+value).prop('checked', true);
|
||||
});
|
||||
$('#note').val('{{ values.note|e("js") }}');
|
||||
//{% endif %}
|
||||
{% endif %}
|
||||
</script>
|
||||
{% endif %}
|
||||
{% if training.modalità == "delete" %}
|
||||
|
|
|
@ -61,15 +61,38 @@
|
|||
<a id='add' href="edit_training.php?add">{{ 'Add training'|t }}</a>
|
||||
</p>
|
||||
<br>
|
||||
<div id="list"></div>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$( "#list" ).load("resources/ajax/ajax_trainings.php?"+Math.random());
|
||||
setInterval(function() {
|
||||
$( "#list" ).load("resources/ajax/ajax_trainings.php?"+Math.random());
|
||||
}, 10000);
|
||||
});
|
||||
</script>
|
||||
<div style="overflow-x:auto;">
|
||||
<table style="width: 90%; text-align:center;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ 'Date'|t }}</th>
|
||||
<th>{{ 'Name'|t }}</th>
|
||||
<th>{{ 'Start time'|t }}</th>
|
||||
<th>{{ 'End time'|t }}</th>
|
||||
<th>{{ 'Chief'|t }}</th>
|
||||
<th>{{ 'People'|t }}</th>
|
||||
<th>{{ 'Place'|t }}</th>
|
||||
<th>{{ 'Notes'|t }}</th>
|
||||
{% if option('training_edit') %}
|
||||
<th>{{ 'Edit'|t }}</th>
|
||||
{% endif %}
|
||||
{% if option('training_remove') %}
|
||||
<th>{{ 'Remove'|t }}</th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="table_body">
|
||||
</tbody>
|
||||
</table>
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
window.loadTable("trainings");
|
||||
setInterval(function() {
|
||||
window.loadTable("trainings");
|
||||
}, 10000);
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
Loading…
Reference in New Issue