-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventos.php
62 lines (55 loc) · 1.62 KB
/
eventos.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
<?php
require_once __DIR__ . '/include/config.php';
header('Content-Type: application/json');
$pdo = new PDO("mysql:host=localhost;dbname=centros_educativos;charset=UTF8","administrador","administrador");
$accion = (isset($_GET['accion']))?$_GET['accion']:'leer';
switch($accion) {
case 'agregar':
$sentenciaSQL = $pdo->prepare("INSERT INTO
eventos(title,descripcion,color,start,end)
VALUES(:title,:descripcion,:color,:start,:end)");
$respuesta = $sentenciaSQL->execute(array(
"title" => $_POST['title'],
"descripcion" => $_POST['descripcion'],
"color" => $_POST['color'],
"start" => $_POST['start'],
"end" => $_POST['end']
));
echo json_encode($respuesta);
break;
case 'eliminar':
$respuesta = false;
if(isset($_POST['id'])) {
$sentenciaSQL = $pdo->prepare("DELETE FROM eventos WHERE ID=:ID");
$respuesta = $sentenciaSQL->execute(array("ID"=>$_POST['id']));
}
echo json_encode($respuesta);
break;
case 'modificar':
$sentenciaSQL = $pdo->prepare("UPDATE eventos SET
title=:title,
descripcion=:descripcion,
color=:color,
start=:start,
end=:end
WHERE ID=:ID
");
$respuesta = $sentenciaSQL->execute(array(
"ID" => $_POST['id'],
"title" => $_POST['title'],
"descripcion" => $_POST['descripcion'],
"color" => $_POST['color'],
"start" => $_POST['start'],
"end" => $_POST['end']
));
echo json_encode($respuesta);
break;
default:
//Seleccionar los eventos del calendario
$sentenciaSQL = $pdo->prepare("SELECT * FROM eventos");
$sentenciaSQL->execute();
$results = $sentenciaSQL->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($results);
break;
}
?>