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