forked from stwebcode/register
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
155 lines (152 loc) · 5.27 KB
/
index.php
File metadata and controls
155 lines (152 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
require_once 'config.php';
if(!isset($_SESSION['user']['id'])):
header('Location: login.php');
else: ?>
<?php include_once "header.php"; ?>
<div id="evoCalendar"></div>
<?php if($_SESSION['user']['roleID'] == 2): ?>
<button id="show-event-form">+ Jauns ieraksts</button>
<div id="new-event" class="shadowbox">
<div class="two-column-form">
<br><span><button id="close-event-form">X</button></span>
<label for="type">Tips</label>
<div>
<input id="type" list="types" type="text" name="type" autocomplete="off" required>
<datalist id="types">
<option>Svētki</option>
<option>Atceres diena</option>
<option>Ekskursija</option>
<option>Eksāmens</option>
</datalist>
<p id="type-error"></p>
</div>
<label for="name">Nosaukums</label>
<div>
<input id="name" type="text" name="name" required>
<p id="name-error"></p>
</div>
<label for="date">Datums</label>
<div>
<input id="date" type="date" name="date" required>
<p id="date-error"></p>
</div>
<label for="time">Laiks</label>
<div>
<input id="time" type="time" name="time" required>
<p id="time-error"></p>
</div>
<br>
<label for="everyYear">Ikgadējs <input id="everyYear" type="checkbox" name="everyYear"></label>
<label for="description">Apraksts</label>
<textarea id="description" name="description" rows="8" cols="30"></textarea>
<button id="submit-new-event">iesniegt</button>
</div>
</div>
<?php endif; ?>
<script src="calendar/evo-calendar.js"></script>
<script>
$( document ).ready(function() {
$("#new-event").hide();
getEvents();
$("#show-event-form").click(function(){$("#new-event").show()});
$("#close-event-form").click(function(){$("#new-event").hide()});
$("#submit-new-event").click(function(){
if(validateEventForm()){
submitNewEvent();
}
});
$(document.body).on("click",".shadowbox", function(){
$(".shadowbox").hide();
});
$(document.body).on("click",".shadowbox > *", function(event){
event.stopPropagation();
});
});
function getEvents(){
$.ajax({
url: 'server.php',
method: 'post',
dataType: 'json',
data: {
action: 'get_events'
},
success: function(data){
$('#evoCalendar').evoCalendar({
theme: 'Midnight Blue',
language: 'lv',
format: 'mm/dd/yyyy',
titleFormat: 'MM yyyy',
eventHeaderFormat: 'd. MM, yyyy',
firstDayOfWeek: 1, // Monday
todayHighlight: true,
calendarEvents: data
});
$("#show-event-form").appendTo('.calendar-months');
}
});
}
function validateEventForm(){
$("#name-error").text("");
$("#date-error").text("");
$("#type-error").text("");
$("#time-error").text("");
const name = $("#name").val();
const date = $("#date").val();
const type = $("#type").val();
const time = $("#time").val();
// const description = $("#description").val();
if(type == ""){
$("#type-error").text("Šis lauks ir obligāts.");
return false;
}
if(name.length == 0){
$("#name-error").text("Šis lauks ir obligāts.");
return false;
}
if(date == ""){
$("#date-error").text("Šis lauks ir obligāts.");
return false;
}
if(time == ""){
$("#time-error").text("Šis lauks ir obligāts.");
return false;
}
return true;
}
//nosūta form info serverim
function submitNewEvent(){
let eventDataToServer = {
name: $("#name").val(),
date: $("#date").val(),
type: $("#type").val(),
everyYear: $("#everyYear").is(":checked") ? 1 : 0,
time: $("#time").val(),
description: $("#description").val()
}
$.ajax({
url: 'server.php',
method: 'post',
dataType: 'json',
data: {
action: 'insert_event',
eventData: eventDataToServer
},
success: function(data){
// console.log(data);
insertCalendarEvent(data);
$("#new-event").hide();
},
error: function(data){
console.log(data);
}
});
}
// ievieto event no servera response
function insertCalendarEvent(eventData){
$("#evoCalendar").evoCalendar('addCalendarEvent', [eventData]);
}
// https://www.jqueryscript.net/time-clock/event-calendar-evo.html
</script>
<?php include_once "footer.php"; ?>
<?php endif; ?>