-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddUser.php
43 lines (41 loc) · 1.65 KB
/
addUser.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
<!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);
$user = $entityManager->find('User',$_GET['id_administrator']);
$event = $entityManager->find('Event',$_GET['id_event']);
if( !is_null($user) && !is_null($event) ) {
$event->getIdUser()->add($user);
try {
$entityManager->getConnection()->beginTransaction(); // Suspende o auto-commit
$entityManager->persist($event);
$entityManager->flush();
$entityManager->getConnection()->commit();
$array_return['message'] = "Usuário adicionado com sucesso";
} catch (Exception $e) {
$pdo_error = array();
$pdo_error = $e->getPrevious()->errorInfo;
$array_return['success'] = 0;
$array_return['message'] = "Falha ao adicionar usuário.";
$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>