-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateEvent.php
More file actions
51 lines (48 loc) · 2.05 KB
/
Copy pathcreateEvent.php
File metadata and controls
51 lines (48 loc) · 2.05 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Criar Evento</title>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
if ($_GET) {
require_once 'bootstrap.php';
$array_return = array('success' => 1);
$administrator = $entityManager->find('User',$_GET['id_administrator']);
if( !is_null($administrator) ) {
$event = new Event();
$event->setName($_GET['name'])
->setDescription($_GET['description'])
->setStartTime(new DateTime($_GET['start_time']))
->setAndTime(new DateTime($_GET['end_time']));
$event->setIdAdministratorUser($administrator);
$event->getIdUser()->add($administrator);
try {
$entityManager->getConnection()->beginTransaction(); // Suspende o auto-commit
$entityManager->persist($event);
$entityManager->flush();
$entityManager->getConnection()->commit();
$array_return['id_event'] = $event->getIdEvent();
$array_return['message'] = "Evento cadastrado com sucesso";
} catch (Exception $e) {
$pdo_error = array();
$pdo_error = $e->getPrevious()->errorInfo;
$array_return['success'] = 0;
$array_return['id_event'] = null;
$array_return['message'] = "Falha ao cadastrar evento.";
$array_return['mysql_error_message'] = $pdo_error[2];
}
} else {
$array_return['success'] = 0;
$array_return['id_event'] = null;
$array_return['message'] = "Especifique um administrador para o evento.";
}
echo json_encode($array_return);
}
?>
<!-- <a href="formCreate.php">Adicionar um novo usuário</a> -->
</body>
</html>