ryxeo-glpi-git / htdocs / mac / contract.php @ e213dd82
Historique | Voir | Annoter | Télécharger (3,54 ko)
1 | 1c14bcc4 | Eric Seigne | <?php
|
---|---|---|---|
2 | /*
|
||
3 | gestion des contrats - affichage et rappel
|
||
4 | e213dd82 | root | http://www.abuledu.net/mac/contract.php/view=toto/mac=08:D8:34:B8:90:CD
|
5 | 1c14bcc4 | Eric Seigne | */
|
6 | |||
7 | $g_http_request = $_SERVER['REQUEST_URI']; |
||
8 | e213dd82 | root | preg_match("/.*mac=(.*)/",$_SERVER['REQUEST_URI'],$regs); |
9 | $mac = addslashes(strtoupper($regs[1])); |
||
10 | |||
11 | preg_match("/.*view=(.*)\/mac=/",$_SERVER['REQUEST_URI'],$regs); |
||
12 | $view = addslashes($regs[1]); |
||
13 | |||
14 | //print "on a $mac et $view";
|
||
15 | |||
16 | 1c14bcc4 | Eric Seigne | //Ou du POST
|
17 | if(trim($mac) == "") { |
||
18 | $mac = addslashes(strtoupper($_POST['mac'])); |
||
19 | e213dd82 | root | } |
20 | 1c14bcc4 | Eric Seigne | |
21 | $_SERVER['REQUEST_URI'] = ""; |
||
22 | $_SERVER['HTTP_REFERER'] = ""; |
||
23 | define('GLPI_ROOT', '..'); |
||
24 | include (GLPI_ROOT . "/inc/includes.php"); |
||
25 | |||
26 | //On recupere l'id du serveur dont la macaddr correspond
|
||
27 | e213dd82 | root | $query = "SELECT FK_computers AS ID FROM glpi_computer_device WHERE specificity ='" . $mac . "'"; |
28 | 1c14bcc4 | Eric Seigne | $result = $DB->query($query); |
29 | $data = $DB->fetch_assoc($result); |
||
30 | //print_r($data);
|
||
31 | |||
32 | if($data['ID']) { |
||
33 | $serverid=$data['ID']; |
||
34 | e213dd82 | root | |
35 | //Quand on a le serverID il faut trouver l'entite dans laquelle il se trouve
|
||
36 | $queryEntity = "SELECT FK_entities AS EntityID FROM glpi_computers WHERE ID='$serverid'"; |
||
37 | $resultEntity = $DB->query($queryEntity); |
||
38 | $dataEntity = $DB->fetch_assoc($resultEntity); |
||
39 | $entityID = $dataEntity['EntityID']; |
||
40 | |||
41 | 1c14bcc4 | Eric Seigne | //Et ensuite on cherche dans les contrats ce qui correspond
|
42 | // -> contrat non supprime
|
||
43 | // -> contrat correspondant a ce serveur
|
||
44 | // -> contrat de type 1 ()
|
||
45 | e213dd82 | root | $query2 = "SELECT UNIX_TIMESTAMP(c.begin_date + INTERVAL c.duration MONTH) as endcontract,c.* FROM glpi_contracts as c WHERE |
46 | 1c14bcc4 | Eric Seigne | c.deleted='0' AND
|
47 | e213dd82 | root | c.FK_entities='$entityID'";
|
48 | |||
49 | 1c14bcc4 | Eric Seigne | //print $query2;
|
50 | $result2 = $DB->query($query2); |
||
51 | $data2 = $DB->fetch_assoc($result2); |
||
52 | |||
53 | //print_r($data2);
|
||
54 | //print mktime() . " -- ";
|
||
55 | $endc = $data2['endcontract']; |
||
56 | if($endc > mktime()) { |
||
57 | e213dd82 | root | if($view == "web") { |
58 | header('Location: http://www.abuledu.net/mac/view/direct.php'); |
||
59 | exit;
|
||
60 | } |
||
61 | else {
|
||
62 | print $endc . ":" . "DIRECT:" . $data2['name'] . ":"; |
||
63 | } |
||
64 | 1c14bcc4 | Eric Seigne | } |
65 | //Reconduction automatique ...
|
||
66 | else if($endc < mktime() && $data2['recursive']=='1') { |
||
67 | e213dd82 | root | if($view == "web") { |
68 | header('Location: http://www.abuledu.net/mac/view/direct.php'); |
||
69 | exit;
|
||
70 | } |
||
71 | else {
|
||
72 | print mktime(0,0,0, date("m",$endc)+$data2['periodicity'], date("d",$endc), date("Y",$endc)) . ":" . "DIRECT:" . $data2['name'] . ":" . "Renouvellement automatique"; |
||
73 | } |
||
74 | 1c14bcc4 | Eric Seigne | } |
75 | else {
|
||
76 | //Le serveur a ete installe par un partenaire qui a un contrat global mais pas encore d'avenant pour ce serveur
|
||
77 | //1 on cherche le partenaire qui a installe ce serveur
|
||
78 | $query3 = "SELECT UNIX_TIMESTAMP(c.begin_date + INTERVAL c.duration MONTH) as endcontract,c.* FROM glpi_plugin_anet_epacks,glpi_contracts as c WHERE FK_serveur='" . $serverid . "' AND c.FK_entities=FK_clientderyxeo"; |
||
79 | //print $query3;
|
||
80 | $result3 = $DB->query($query3); |
||
81 | $data3 = $DB->fetch_assoc($result3); |
||
82 | /*
|
||
83 | print "<pre>";
|
||
84 | print_r($data3);
|
||
85 | print "</pre>";
|
||
86 | */
|
||
87 | $endc = $data3['endcontract']; |
||
88 | if($endc > mktime()) { |
||
89 | e213dd82 | root | if($view == "web") { |
90 | header('Location: http://www.abuledu.net/mac/view/partner.php'); |
||
91 | exit;
|
||
92 | } |
||
93 | else {
|
||
94 | print $endc . ":PARTNER" . ":" . $data3['name'] . ":" . "Avenant pour ce serveur manquant"; |
||
95 | } |
||
96 | 1c14bcc4 | Eric Seigne | } |
97 | else{
|
||
98 | //Le serveur existe dans notre base mais c'est tout
|
||
99 | e213dd82 | root | if($view == "web") { |
100 | header('Location: http://www.abuledu.net/mac/view/waiting.php'); |
||
101 | exit;
|
||
102 | } |
||
103 | else {
|
||
104 | print "000:WAITING:000:"; |
||
105 | } |
||
106 | 1c14bcc4 | Eric Seigne | } |
107 | } |
||
108 | } |
||
109 | else {
|
||
110 | e213dd82 | root | if($view == "web") { |
111 | header('Location: http://www.abuledu.net/mac/view/forbidden.php'); |
||
112 | exit;
|
||
113 | } |
||
114 | else {
|
||
115 | print "000:FORBIDDEN:000:NOT"; |
||
116 | } |
||
117 | 1c14bcc4 | Eric Seigne | } |
118 | |||
119 | ?> |