-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
146 lines (133 loc) · 4.43 KB
/
index.php
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
<?php require_once("config.inc.php"); ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Calendario</title>
<meta http-equiv="PRAGMA" content="NO-CACHE">
<meta http-equiv="EXPIRES" content="-1">
<link type="text/css" rel="stylesheet" media="all" href="estilos.css">
</head>
<body>
<div class="calendario_ajax">
<div class="cal"></div><div id="mask"></div>
</div>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/localization/messages_es.js "></script>
<script>
function generar_calendario(mes,anio)
{
var agenda=$(".cal");
agenda.html("<img src='images/loading.gif'>");
$.ajax({
type: "GET",
url: "ajax_calendario.php",
cache: false,
data: { mes:mes,anio:anio,accion:"generar_calendario" }
}).done(function( respuesta )
{
agenda.html(respuesta);
});
}
function formatDate (input) {
var datePart = input.match(/\d+/g),
year = datePart[0].substring(2),
month = datePart[1], day = datePart[2];
return day+'-'+month+'-'+year;
}
$(document).ready(function()
{
/* GENERATE CALENDAR WITH DATE OF TODAY */
generar_calendario("<?php if (isset($_GET["mes"])) echo $_GET["mes"]; ?>","<?php if (isset($_GET["anio"])) echo $_GET["anio"]; ?>");
/* ADD AN EVENT */
$(document).on("click",'a.add',function(e)
{
e.preventDefault();
var id = $(this).data('evento');
var fecha = $(this).attr('rel');
$('#mask').fadeIn(1000).html("<div id='nuevo_evento' class='window' rel='"+fecha+"'>Agregar un evento el "+formatDate(fecha)+"</h2><a href='#' class='close' rel='"+fecha+"'> </a><div id='respuesta_form'></div><form class='formeventos'><input type='text' name='evento_titulo' id='evento_titulo' class='required'><input type='button' name='Enviar' value='Guardar' class='enviar'><input type='hidden' name='evento_fecha' id='evento_fecha' value='"+fecha+"'></form></div>");
});
/* LIST EVENTS OF DAY */
$(document).on("click",'a.modal',function(e)
{
e.preventDefault();
var fecha = $(this).attr('rel');
$('#mask').fadeIn(1000).html("<div id='nuevo_evento' class='window' rel='"+fecha+"'>Eventos del "+formatDate(fecha)+"</h2><a href='#' class='close' rel='"+fecha+"'> </a><div id='respuesta'></div><div id='respuesta_form'></div></div>");
$.ajax({
type: "GET",
url: "ajax_calendario.php",
cache: false,
data: { fecha:fecha,accion:"listar_evento" }
}).done(function( respuesta )
{
$("#respuesta_form").html(respuesta);
});
});
$(document).on("click",'.close',function (e)
{
e.preventDefault();
$('#mask').fadeOut();
setTimeout(function()
{
var fecha=$(".window").attr("rel");
var fechacal=fecha.split("-");
generar_calendario(fechacal[1],fechacal[0]);
}, 500);
});
//guardar evento
$(document).on("click",'.enviar',function (e)
{
e.preventDefault();
if ($("#evento_titulo").valid()==true)
{
$("#respuesta_form").html("<img src='images/loading.gif'>");
var evento=$("#evento_titulo").val();
var fecha=$("#evento_fecha").val();
$.ajax({
type: "GET",
url: "ajax_calendario.php",
cache: false,
data: { evento:evento,fecha:fecha,accion:"guardar_evento" }
}).done(function( respuesta2 )
{
$("#respuesta_form").html(respuesta2);
$(".formeventos,.close").hide();
setTimeout(function()
{
$('#mask').fadeOut('fast');
var fechacal=fecha.split("-");
generar_calendario(fechacal[1],fechacal[0]);
}, 3000);
});
}
});
/* DELETE EVENT */
$(document).on("click",'.eliminar_evento',function (e)
{
e.preventDefault();
var current_p=$(this);
$("#respuesta").html("<img src='images/loading.gif'>");
var id=$(this).attr("rel");
$.ajax({
type: "GET",
url: "ajax_calendario.php",
cache: false,
data: { id:id,accion:"borrar_evento" }
}).done(function( respuesta2 )
{
$("#respuesta").html(respuesta2);
current_p.parent("p").fadeOut();
});
});
$(document).on("click",".anterior,.siguiente",function(e)
{
e.preventDefault();
var datos=$(this).attr("rel");
var nueva_fecha=datos.split("-");
generar_calendario(nueva_fecha[1],nueva_fecha[0]);
});
});
</script>
</body>
</html>