-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatusChange.php
76 lines (56 loc) · 2.01 KB
/
statusChange.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
<?php
require_once('class.authentification.php');
require_once('class.util.php');
require_once('class.demande.php');
require_once('class.database.php');
$auth = authentification::instance();
if(!$auth->estIdentifie() || !$auth->isUserAdmin())
{
header("Location: index.php");
exit(0);
}
$status = util::getParam($_GET, 'status');
$matricules = util::getParam($_GET, 'matricules');
$details = util::getParam($_GET, 'details');
$includeDetails = util::getParam($_GET, 'includeDetailsInMail') == 'true';
$sendMail = util::getParam($_GET, 'sendMail') == 'true';
$errorIconPath = 'images/error_icon.png';
$successIconPath = 'images/success_icon.png';
$response->statusChangeIndicatorImagePath = $successIconPath;
$response->statusChangeMessage = "";
$response->hasError = false;
if(!isset($status) || !isset($matricules))
{
$response->statusChangeIndicatorImagePath = $errorIconPath;
$response->statusChangeMessage = "Argument manquant";
$response->hasError = true;
print json_encode($response);
return;
}
$response->selectedDemands = json_decode($matricules);
try
{
//$matricules = json_decode($matricules);
$database = database::instance();
$database->beginTransaction();
$matricules = json_decode($matricules);
foreach ($matricules as $matricule) {
$demand = new demande($matricule);
$sendSuccesful = $demand->getStatus()->changeStatusTo($status,$details,$sendMail,$includeDetails);
if(!$sendSuccesful)
throw new Exception("Erreur d'envoi du message");
$demand->refreshStatus();
$response->newStatus = util::cleanUTF8($demand->getStatus()->getName());
}
$database->commitTransaction();
print json_encode($response);
}
catch(Exception $e)
{
$response->statusChangeIndicatorImagePath = $errorIconPath;
$response->statusChangeMessage = $e->getMessage();
$response->hasError = true;
$database->abortTransaction();
print json_encode($response);
}
?>