ryxeo-glpi-git / htdocs / epack / recette.php @ 7c12ea40
Historique | Voir | Annoter | Télécharger (8,27 ko)
1 | 1c14bcc4 | Eric Seigne | <?php
|
---|---|---|---|
2 | $debug=0; |
||
3 | |||
4 | //Permet de trier le tableau des postes
|
||
5 | function localsort_name($a,$b) { |
||
6 | if ($a == $b) { |
||
7 | return 0; |
||
8 | } |
||
9 | return ($a['host'] < $b['host']) ? -1 : 1; |
||
10 | } |
||
11 | |||
12 | if($debug) { |
||
13 | ob_start(); |
||
14 | error_reporting(E_ALL); |
||
15 | } |
||
16 | else
|
||
17 | error_reporting(E_NONE); |
||
18 | |||
19 | define('GLPI_ROOT', '..'); |
||
20 | include (GLPI_ROOT . "/inc/includes.php"); |
||
21 | include ("ryxeo.php"); |
||
22 | |||
23 | $object = array('message' => '', |
||
24 | 'header1' => '', |
||
25 | 'header2' => ''); |
||
26 | $send_mail = 0; //flag pour savoir s'il faut envoyer un mail (en bref a toute insertion ou update de base) |
||
27 | |||
28 | $code = $_POST['code']; |
||
29 | $pass = $_POST['pass']; |
||
30 | $anetlogin = $_POST['anetlogin']; |
||
31 | $anetpassword = $_POST['anetpassword']; |
||
32 | 5c3812b2 | root | $version = $_POST['version']; |
33 | 1c14bcc4 | Eric Seigne | $tab_postes = unserialize(base64_decode($_POST['tab_postes'])); |
34 | $tab_server = unserialize(base64_decode($_POST['tab_server'])); |
||
35 | $tab_hdd = unserialize(base64_decode($_POST['tab_hdd'])); |
||
36 | $tab_wifi = unserialize(base64_decode($_POST['tab_wifi'])); |
||
37 | $tab_rvd = unserialize(base64_decode($_POST['tab_rvd'])); |
||
38 | $tab_client = unserialize(base64_decode($_POST['tab_client'])); |
||
39 | |||
40 | usort($tab_postes,localsort_name); |
||
41 | |||
42 | //debug
|
||
43 | if($debug) { |
||
44 | $object['message'] .= "<p>Mode debug</p>"; |
||
45 | $object['message'] .= implode(",",$tab_client); |
||
46 | $object['message'] .= "<p>DEBUG:: " . ob_get_clean() . "</p>"; |
||
47 | ob_end_clean(); |
||
48 | } |
||
49 | |||
50 | //profil 5 -> ce sont les revendeurs, 3 et 4 c'est admin et super admin
|
||
51 | $query = "SELECT gu.*,ge.address,ge.postcode,ge.town FROM glpi_users as gu |
||
52 | LEFT JOIN glpi_users_profiles AS gup ON gup.FK_users=gu.ID
|
||
53 | LEFT JOIN glpi_entities_data AS ge ON ge.FK_entities=gu.FK_entities
|
||
54 | WHERE gu.email='" . $anetlogin . "' AND password_md5=MD5('" . $anetpassword . "') AND (gup.FK_profiles='5' OR gup.FK_profiles='4' OR gup.FK_profiles='3') |
||
55 | GROUP BY gu.email;";
|
||
56 | |||
57 | if($debug) |
||
58 | $object['message'] .= "<p>query: $query</p>"; |
||
59 | $result = $DB->query($query); |
||
60 | if(($DB->numrows($result)>0) || $debug) { |
||
61 | $data = $DB->fetch_assoc($result); |
||
62 | |||
63 | $tab_rvd['RVD_ADDRESS'] = trim($data['address']); |
||
64 | $tab_rvd['RVD_CP'] = trim($data['postcode']); |
||
65 | $tab_rvd['RVD_CITY'] = trim($data['town']); |
||
66 | |||
67 | if((trim($pass) != "" && trim($code) != "") || $debug) { |
||
68 | $query2 = "SELECT * FROM glpi_plugin_anet_epacks |
||
69 | LEFT JOIN glpi_entities AS g ON FK_client=g.ID
|
||
70 | WHERE code='$code' AND password='$pass'";
|
||
71 | if($debug) { |
||
72 | $object['message'] .= "<p>query2: $query2</p>"; |
||
73 | } |
||
74 | $result2 = $DB->query($query2); |
||
75 | if(($DB->numrows($result2)>0) || $debug) { |
||
76 | //print serialize($object);
|
||
77 | //print_r($_SERVER);
|
||
78 | require_once('lib/odf.php'); |
||
79 | 5c3812b2 | root | if($version == "1108") |
80 | $odf = new odf("abuledu-recette-1108.odt"); |
||
81 | else
|
||
82 | $odf = new odf("abuledu-recette.odt"); |
||
83 | 1c14bcc4 | Eric Seigne | |
84 | //1ere page
|
||
85 | setlocale(LC_TIME, "fr_FR.UTF-8"); |
||
86 | $odf->setVars('date', strftime("%A %e %B %Y")); |
||
87 | 7c12ea40 | root | $odf->setVars('annee', date("Y")); |
88 | 1c14bcc4 | Eric Seigne | $odf->setVars('datecourte', date("d/m/Y")); |
89 | |||
90 | //L'installateur
|
||
91 | 0a369d2d | Eric Seigne | $odf->setVars('installateursociete', $tab_rvd['RVD_CODE'], true, 'UTF-8'); |
92 | $odf->setVars('installateuradresse', $tab_rvd['RVD_ADDRESS'], true, 'UTF-8'); |
||
93 | $odf->setVars('installateurcp', $tab_rvd['RVD_CO'], true, 'UTF-8'); |
||
94 | $odf->setVars('installateurville', $tab_rvd['RVD_CITY'], true, 'UTF-8'); |
||
95 | $odf->setVars('installateuremail', $tab_rvd['RVD_EMAIL'], true, 'UTF-8'); |
||
96 | $odf->setVars('installateurtel', $tab_rvd['RVD_PHONE'], true, 'UTF-8'); |
||
97 | 1c14bcc4 | Eric Seigne | |
98 | //Le client
|
||
99 | 0a369d2d | Eric Seigne | $odf->setVars('client', $tab_client["installation_name"], true, 'UTF-8'); |
100 | $odf->setVars('clientadresse', $tab_client["installation_address0"], true, 'UTF-8'); |
||
101 | $odf->setVars('clientcp', $tab_client["installation_postalcode"], true, 'UTF-8'); |
||
102 | $odf->setVars('clientville', $tab_client["installation_city"], true, 'UTF-8'); |
||
103 | $odf->setVars('clienttel', $tab_client["installation_phone"], true, 'UTF-8'); |
||
104 | $odf->setVars('clientmail', $tab_client["installation_email"], true, 'UTF-8'); |
||
105 | 1c14bcc4 | Eric Seigne | |
106 | //abuledu.net
|
||
107 | $odf->setVars('anetdip', "TODO"); |
||
108 | $odf->setVars('anetdyn', "a venir"); |
||
109 | |||
110 | //Internet
|
||
111 | 0a369d2d | Eric Seigne | $odf->setVars('internetip', $tab_server["externalip"], true, 'UTF-8'); |
112 | $odf->setVars('internetfai', $tab_server["fai"], true, 'UTF-8'); |
||
113 | 1c14bcc4 | Eric Seigne | |
114 | //wifi
|
||
115 | 0a369d2d | Eric Seigne | $odf->setVars('wifimarque', $tab_wifi["wifimarque"], true, 'UTF-8'); |
116 | $odf->setVars('wifimodele', $tab_wifi["wifimodele"], true, 'UTF-8'); |
||
117 | $odf->setVars('wifiwpa', $tab_wifi["wifiwpa"], true, 'UTF-8'); |
||
118 | 1c14bcc4 | Eric Seigne | |
119 | //serveur
|
||
120 | 0a369d2d | Eric Seigne | $odf->setVars('serveurmarque', $tab_server["vendor"], true, 'UTF-8'); |
121 | $odf->setVars('serveurmodele', $tab_server["product"], true, 'UTF-8'); |
||
122 | 1c14bcc4 | Eric Seigne | if(trim($tab_server["serial"] != "")) |
123 | 0a369d2d | Eric Seigne | $odf->setVars('serveurserial', "(SERIAL #" . $tab_server["serial"] . ")", true, 'UTF-8'); |
124 | 1c14bcc4 | Eric Seigne | |
125 | //abuladmin
|
||
126 | 0a369d2d | Eric Seigne | $odf->setVars('abuladminpass', "TODO", true, 'UTF-8'); |
127 | 1c14bcc4 | Eric Seigne | |
128 | //disque dur
|
||
129 | // $odf->setVars('srvhddcount', count($tab_hdd));
|
||
130 | $p = $odf->setSegment('srvhdd'); |
||
131 | $nb=1; |
||
132 | foreach($tab_hdd AS $element) { |
||
133 | $p->srvhddnum($nb); |
||
134 | $p->srvhddsize($element["size"]); |
||
135 | $p->srvhddvendor($element["vendor"]); |
||
136 | $p->srvhddproduct($element["product"]); |
||
137 | $p->srvhddserial($element["serial"]); |
||
138 | $p->merge();
|
||
139 | $nb++;
|
||
140 | } |
||
141 | $odf->mergeSegment($p); |
||
142 | |||
143 | //epack
|
||
144 | $odf->setVars('epackcode', $code); |
||
145 | $odf->setVars('epackpassword', $pass); |
||
146 | |||
147 | // $odf->setVars('', "");
|
||
148 | |||
149 | //Les postes + imprimante + wifi (partiels)
|
||
150 | $p = $odf->setSegment('postes'); |
||
151 | $nb=1; |
||
152 | foreach($tab_postes AS $element) { |
||
153 | if(ereg("^wifi-",$element['host'])) { |
||
154 | $odf->setVars('wifiip', $element['ip']); |
||
155 | $odf->setVars('wifimac', $element['mac']); |
||
156 | } |
||
157 | else if(ereg("^imprimante-",$element['host'])){ |
||
158 | $odf->setVars('imprimanteip', $element['ip']); |
||
159 | $odf->setVars('imprimantemac', $element['mac']); |
||
160 | //nothing
|
||
161 | } |
||
162 | else {
|
||
163 | $p->postenum($nb); |
||
164 | $p->postenom($element['host']); |
||
165 | $p->postemodele("modele"); |
||
166 | $p->posteip($element['ip']); |
||
167 | $p->postemac($element['mac']); |
||
168 | $p->posteadmin("TODO"); |
||
169 | $p->merge();
|
||
170 | $nb++;
|
||
171 | } |
||
172 | } |
||
173 | $odf->mergeSegment($p); |
||
174 | |||
175 | //On créé un fichier local pour archive ...
|
||
176 | $fichier="archives/" . date("Y-m-d") . "-recette-" . $code . ".odt"; |
||
177 | $odf->saveToDisk($fichier); |
||
178 | |||
179 | //On génère le fichier
|
||
180 | if(! $debug) { |
||
181 | $object['header1'] = 'Content-type: application/vnd.oasis.opendocument.text'; |
||
182 | $object['header2'] = 'Content-Disposition: attachment; filename="abuledu-recette.odt"'; |
||
183 | $object['message'] = @file_get_contents($fichier,FILE_BINARY); |
||
184 | } |
||
185 | |||
186 | |||
187 | |||
188 | $mail_content = " |
||
189 | Bonjour,
|
||
190 | le pack $code :: $pass vient d'être utilisé par $anetlogin pour créer un cahier de recettes
|
||
191 |
|
||
192 | Informations brutes récoltées:
|
||
193 |
|
||
194 | ";
|
||
195 | |||
196 | foreach ($tab_rvd as $key => $value) { |
||
197 | $mail_content .= "$key -> $value\n"; |
||
198 | } |
||
199 | $mail_content .= "\n\n"; |
||
200 | |||
201 | foreach ($tab_client as $key => $value) { |
||
202 | $mail_content .= "$key -> $value\n"; |
||
203 | } |
||
204 | $mail_content .= "\n\n"; |
||
205 | |||
206 | foreach ($tab_postes as $key => $value) { |
||
207 | $mail_content .= "$key -> " . implode(",",$value) . "\n"; |
||
208 | } |
||
209 | $mail_content .= "\n\n"; |
||
210 | |||
211 | foreach ($tab_server as $key => $value) { |
||
212 | $mail_content .= "$key -> $value\n"; |
||
213 | } |
||
214 | $mail_content .= "\n\n"; |
||
215 | |||
216 | foreach ($tab_hdd as $key => $value) { |
||
217 | $mail_content .= "$key -> " . implode(",",$value) . "\n"; |
||
218 | } |
||
219 | $mail_content .= "\n\n"; |
||
220 | |||
221 | foreach ($tab_wifi as $key => $value) { |
||
222 | $mail_content .= "$key -> $value\n"; |
||
223 | } |
||
224 | $mail_content .= "\n\n"; |
||
225 | |||
226 | $mail_content .= " |
||
227 |
|
||
228 | --
|
||
229 | abuledu.net est un service de RyXéo SARL, société éditrice d'AbulÉdu
|
||
230 |
|
||
231 | ";
|
||
232 | ryxeo_mail("anet@ryxeo.com",$mail_content,"contact@ryxeo.com","$code : Cahier de recettes - " . $tab_client["installation_name"] . " " . $tab_client["installation_city"]); |
||
233 | |||
234 | } |
||
235 | else {
|
||
236 | $object['message'] .= "<p>Erreur d'ePack 1 ...</p>"; |
||
237 | //print "<p>Erreur d'ePack ...</p>";
|
||
238 | } |
||
239 | } |
||
240 | else {
|
||
241 | $object['message'] .= "<p>Erreur d'ePack 2 ...</p>"; |
||
242 | //print "<p>Erreur d'ePack ...</p>";
|
||
243 | } |
||
244 | } |
||
245 | else {
|
||
246 | //print "<p>Erreur d'identifiant ou de mot de passe ...</p>";
|
||
247 | $object['message'] .= "<p>Erreur d'identifiant ou de mot de passe ...</p>"; |
||
248 | } |
||
249 | |||
250 | if($debug) { |
||
251 | print $object['message']; |
||
252 | $object['message'] .= "<p>DEBUG:: " . ob_get_clean() . "</p>"; |
||
253 | ob_end_clean(); |
||
254 | print $object['message']; |
||
255 | } |
||
256 | |||
257 | print serialize($object); |
||
258 | |||
259 | ?> |