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