ryxeo-glpi-git / inc / export.function.php @ b67d8923
Historique | Voir | Annoter | Télécharger (10,5 ko)
1 | b67d8923 | Eric Seigne | <?php
|
---|---|---|---|
2 | /*
|
||
3 | * @version $Id: export.function.php 7870 2009-01-20 20:24:42Z moyo $
|
||
4 | -------------------------------------------------------------------------
|
||
5 | GLPI - Gestionnaire Libre de Parc Informatique
|
||
6 | Copyright (C) 2003-2009 by the INDEPNET Development Team.
|
||
7 | |||
8 | http://indepnet.net/ http://glpi-project.org
|
||
9 | -------------------------------------------------------------------------
|
||
10 | |||
11 | LICENSE
|
||
12 | |||
13 | This file is part of GLPI.
|
||
14 | |||
15 | GLPI is free software; you can redistribute it and/or modify
|
||
16 | it under the terms of the GNU General Public License as published by
|
||
17 | the Free Software Foundation; either version 2 of the License, or
|
||
18 | (at your option) any later version.
|
||
19 | |||
20 | GLPI is distributed in the hope that it will be useful,
|
||
21 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
23 | GNU General Public License for more details.
|
||
24 | |||
25 | You should have received a copy of the GNU General Public License
|
||
26 | along with GLPI; if not, write to the Free Software
|
||
27 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
28 | --------------------------------------------------------------------------
|
||
29 | */
|
||
30 | |||
31 | if (!defined('GLPI_ROOT')){ |
||
32 | die("Sorry. You can't access directly to this file"); |
||
33 | } |
||
34 | |||
35 | /**
|
||
36 | * Print generic Header Column
|
||
37 | *
|
||
38 | *
|
||
39 | *@param $type display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
|
||
40 | *@param $value value to display
|
||
41 | *@param $num column number
|
||
42 | *@param $linkto link display element (HTML specific)
|
||
43 | *@param $issort is the sort column ?
|
||
44 | *@param $order order type ASC or DESC
|
||
45 | *
|
||
46 | *@return string to display
|
||
47 | *
|
||
48 | **/
|
||
49 | function displaySearchHeaderItem($type,$value,&$num,$linkto="",$issort=0,$order=""){ |
||
50 | global $CFG_GLPI; |
||
51 | $out=""; |
||
52 | switch ($type){ |
||
53 | case PDF_OUTPUT_LANDSCAPE : //pdf |
||
54 | case PDF_OUTPUT_PORTRAIT : |
||
55 | global $PDF_HEADER; |
||
56 | $PDF_HEADER[$num]=utf8_decode(html_clean($value)); |
||
57 | break;
|
||
58 | case SYLK_OUTPUT : //sylk |
||
59 | global $SYLK_HEADER,$SYLK_SIZE; |
||
60 | $SYLK_HEADER[$num]=sylk_clean($value); |
||
61 | $SYLK_SIZE[$num]=strlen($SYLK_HEADER[$num]); |
||
62 | |||
63 | // $out="F;SDM4;FG0C;".($num == 1 ? "Y1;" : "")."X$num\n";
|
||
64 | // $out.= "C;N;K\"".sylk_clean($value)."\"\n";
|
||
65 | break;
|
||
66 | case CSV_OUTPUT : //CSV |
||
67 | $out="\"".csv_clean($value)."\";"; |
||
68 | break;
|
||
69 | default :
|
||
70 | |||
71 | $out="<th>"; |
||
72 | if ($issort) { |
||
73 | if ($order=="DESC") $out.="<img src=\"".$CFG_GLPI["root_doc"]."/pics/puce-down.png\" alt='' title=''>"; |
||
74 | else $out.="<img src=\"".$CFG_GLPI["root_doc"]."/pics/puce-up.png\" alt='' title=''>"; |
||
75 | } |
||
76 | |||
77 | if (!empty($linkto)) |
||
78 | $out.= "<a href=\"$linkto\">"; |
||
79 | |||
80 | $out.= $value; |
||
81 | |||
82 | if (!empty($linkto)) |
||
83 | $out.="</a>"; |
||
84 | |||
85 | $out.="</th>\n"; |
||
86 | break;
|
||
87 | } |
||
88 | $num++;
|
||
89 | return $out; |
||
90 | |||
91 | } |
||
92 | |||
93 | |||
94 | /**
|
||
95 | * Print generic normal Item Cell
|
||
96 | *
|
||
97 | *
|
||
98 | *@param $type display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
|
||
99 | *@param $value value to display
|
||
100 | *@param $num column number
|
||
101 | *@param $row row number
|
||
102 | *@param $extraparam extra parameters for display
|
||
103 | *
|
||
104 | *@return string to display
|
||
105 | *
|
||
106 | **/
|
||
107 | function displaySearchItem($type,$value,&$num,$row,$extraparam=''){ |
||
108 | $out=""; |
||
109 | switch ($type){ |
||
110 | case PDF_OUTPUT_LANDSCAPE : //pdf |
||
111 | case PDF_OUTPUT_PORTRAIT : |
||
112 | global $PDF_ARRAY,$PDF_HEADER; |
||
113 | $PDF_ARRAY[$row][$num]=utf8_decode(html_clean($value)); |
||
114 | break;
|
||
115 | case SYLK_OUTPUT : //sylk |
||
116 | global $SYLK_ARRAY,$SYLK_HEADER,$SYLK_SIZE; |
||
117 | $SYLK_ARRAY[$row][$num]=sylk_clean($value); |
||
118 | $SYLK_SIZE[$num]=max($SYLK_SIZE[$num],strlen($SYLK_ARRAY[$row][$num])); |
||
119 | |||
120 | // $out="F;P3;FG0L;".($num == 1 ? "Y".$row.";" : "")."X$num\n";
|
||
121 | // $out.= "C;N;K\"".sylk_clean($value)."\"\n";
|
||
122 | break;
|
||
123 | case CSV_OUTPUT : //csv |
||
124 | $out="\"".csv_clean($value)."\";"; |
||
125 | break;
|
||
126 | default :
|
||
127 | $out="<td $extraparam>".$value."</td>\n"; |
||
128 | break;
|
||
129 | } |
||
130 | $num++;
|
||
131 | return $out; |
||
132 | |||
133 | } |
||
134 | |||
135 | /**
|
||
136 | * Print generic error
|
||
137 | *
|
||
138 | *
|
||
139 | *@param $type display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
|
||
140 | *
|
||
141 | *@return string to display
|
||
142 | *
|
||
143 | **/
|
||
144 | function displaySearchError($type){ |
||
145 | global $LANG; |
||
146 | $out=""; |
||
147 | switch ($type){ |
||
148 | case PDF_OUTPUT_LANDSCAPE : //pdf |
||
149 | case PDF_OUTPUT_PORTRAIT : |
||
150 | break;
|
||
151 | case SYLK_OUTPUT : //sylk |
||
152 | break;
|
||
153 | case CSV_OUTPUT : //csv |
||
154 | break;
|
||
155 | default :
|
||
156 | $out= "<div class='center'><strong>".$LANG["search"][15]."</strong></div>\n"; |
||
157 | break;
|
||
158 | } |
||
159 | return $out; |
||
160 | |||
161 | } |
||
162 | /**
|
||
163 | * Print generic footer
|
||
164 | *
|
||
165 | *
|
||
166 | *@param $type display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
|
||
167 | *@param $title title of file : used for PDF
|
||
168 | *
|
||
169 | *@return string to display
|
||
170 | *
|
||
171 | **/
|
||
172 | function displaySearchFooter($type,$title=""){ |
||
173 | global $LANG; |
||
174 | $out=""; |
||
175 | switch ($type){ |
||
176 | case PDF_OUTPUT_LANDSCAPE : //pdf |
||
177 | global $PDF_HEADER,$PDF_ARRAY; |
||
178 | $pdf= new Cezpdf('a4','landscape'); |
||
179 | $pdf->selectFont(GLPI_ROOT."/lib/ezpdf/fonts/Helvetica.afm"); |
||
180 | $pdf->ezStartPageNumbers(750,10,10,'left',"GLPI PDF export - ".convDate(date("Y-m-d"))." - ".count($PDF_ARRAY)." ".utf8_decode($LANG["pager"][5])."- {PAGENUM}/{TOTALPAGENUM}"); |
||
181 | $options=array('fontSize'=>8,'colGap'=>2,'maxWidth'=>800,'titleFontSize'=>8,); |
||
182 | $pdf->ezTable($PDF_ARRAY,$PDF_HEADER,utf8_decode($title),$options); |
||
183 | $pdf->ezStream();
|
||
184 | |||
185 | break;
|
||
186 | case PDF_OUTPUT_PORTRAIT : //pdf |
||
187 | global $PDF_HEADER,$PDF_ARRAY; |
||
188 | $pdf= new Cezpdf('a4','portrait'); |
||
189 | $pdf->selectFont(GLPI_ROOT."/lib/ezpdf/fonts/Helvetica.afm"); |
||
190 | $pdf->ezStartPageNumbers(550,10,10,'left',"GLPI PDF export - ".convDate(date("Y-m-d"))." - ".count($PDF_ARRAY)." ".utf8_decode($LANG["pager"][5])."- {PAGENUM}/{TOTALPAGENUM}"); |
||
191 | $options=array('fontSize'=>8,'colGap'=>2,'maxWidth'=>565,'titleFontSize'=>8,); |
||
192 | $pdf->ezTable($PDF_ARRAY,$PDF_HEADER,utf8_decode($title),$options); |
||
193 | $pdf->ezStream();
|
||
194 | |||
195 | break;
|
||
196 | case SYLK_OUTPUT : //sylk |
||
197 | |||
198 | global $SYLK_HEADER,$SYLK_ARRAY,$SYLK_SIZE; |
||
199 | // largeurs des colonnes
|
||
200 | foreach ($SYLK_SIZE as $num => $val) { |
||
201 | $out.= "F;W".$num." ".$num." ".min(50,$val)."\n"; |
||
202 | } |
||
203 | $out.="\n"; |
||
204 | // Header
|
||
205 | foreach ($SYLK_HEADER as $num => $val){ |
||
206 | $out.="F;SDM4;FG0C;".($num == 1 ? "Y1;" : "")."X$num\n"; |
||
207 | $out.= "C;N;K\"".sylk_clean($val)."\"\n"; |
||
208 | $out.="\n"; |
||
209 | } |
||
210 | // Datas
|
||
211 | foreach ($SYLK_ARRAY as $row => $tab){ |
||
212 | foreach ($tab as $num => $val){ |
||
213 | $out.="F;P3;FG0L;".($num == 1 ? "Y".$row.";" : "")."X$num\n"; |
||
214 | $out.= "C;N;K\"".sylk_clean($val)."\"\n"; |
||
215 | } |
||
216 | } |
||
217 | |||
218 | $out.= "E\n"; |
||
219 | break;
|
||
220 | case CSV_OUTPUT : //csv |
||
221 | break;
|
||
222 | default :
|
||
223 | $out= "</table></div>\n"; |
||
224 | break;
|
||
225 | } |
||
226 | return $out; |
||
227 | |||
228 | } |
||
229 | /**
|
||
230 | * Print generic footer
|
||
231 | *
|
||
232 | *
|
||
233 | *@param $type display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
|
||
234 | *@param $cols number of columns
|
||
235 | *@param $rows number of rows
|
||
236 | *@param $fixed used tab_cadre_fixe table for HTML export ?
|
||
237 | *
|
||
238 | *@return string to display
|
||
239 | *
|
||
240 | **/
|
||
241 | function displaySearchHeader($type,$rows,$cols,$fixed=0){ |
||
242 | $out=""; |
||
243 | switch ($type){ |
||
244 | case PDF_OUTPUT_LANDSCAPE : //pdf |
||
245 | case PDF_OUTPUT_PORTRAIT : |
||
246 | global $PDF_ARRAY,$PDF_HEADER; |
||
247 | $PDF_ARRAY=array(); |
||
248 | $PDF_HEADER=array(); |
||
249 | break;
|
||
250 | case SYLK_OUTPUT : // Sylk |
||
251 | global $SYLK_ARRAY,$SYLK_HEADER,$SYLK_SIZE; |
||
252 | $SYLK_ARRAY=array(); |
||
253 | $SYLK_HEADER=array(); |
||
254 | $SYLK_SIZE=array(); |
||
255 | |||
256 | // define("FORMAT_REEL", 1); // #,##0.00
|
||
257 | // define("FORMAT_ENTIER", 2); // #,##0
|
||
258 | // define("FORMAT_TEXTE", 3); // @
|
||
259 | |||
260 | // $cfg_formats[FORMAT_ENTIER] = "FF0";
|
||
261 | // $cfg_formats[FORMAT_REEL] = "FF2";
|
||
262 | // $cfg_formats[FORMAT_TEXTE] = "FG0";
|
||
263 | |||
264 | // entetes HTTP
|
||
265 | // --------------------------------------------------------------------
|
||
266 | header("Expires: Mon, 26 Nov 1962 00:00:00 GMT"); |
||
267 | header('Pragma: private'); /// IE BUG + SSL |
||
268 | //header('Pragma: no-cache');
|
||
269 | header('Cache-control: private, must-revalidate'); /// IE BUG + SSL |
||
270 | header("Content-disposition: filename=glpi.slk"); |
||
271 | header('Content-type: application/octetstream'); |
||
272 | |||
273 | |||
274 | // entete du fichier
|
||
275 | // --------------------------------------------------------------------
|
||
276 | echo "ID;PGLPI_EXPORT\n"; // ID;Pappli |
||
277 | echo "\n"; |
||
278 | // formats
|
||
279 | echo "P;PGeneral\n"; |
||
280 | echo "P;P#,##0.00\n"; // P;Pformat_1 (reels) |
||
281 | echo "P;P#,##0\n"; // P;Pformat_2 (entiers) |
||
282 | echo "P;P@\n"; // P;Pformat_3 (textes) |
||
283 | echo "\n"; |
||
284 | // polices
|
||
285 | echo "P;EArial;M200\n"; |
||
286 | echo "P;EArial;M200\n"; |
||
287 | echo "P;EArial;M200\n"; |
||
288 | echo "P;FArial;M200;SB\n"; |
||
289 | echo "\n"; |
||
290 | // nb lignes * nb colonnes
|
||
291 | echo "B;Y".$rows; |
||
292 | echo ";X".$cols."\n"; // B;Yligmax;Xcolmax |
||
293 | echo "\n"; |
||
294 | |||
295 | break;
|
||
296 | case CSV_OUTPUT : // csv |
||
297 | header("Expires: Mon, 26 Nov 1962 00:00:00 GMT"); |
||
298 | header('Pragma: private'); /// IE BUG + SSL |
||
299 | header('Cache-control: private, must-revalidate'); /// IE BUG + SSL |
||
300 | header("Content-disposition: filename=glpi.csv"); |
||
301 | header('Content-type: application/octetstream'); |
||
302 | break;
|
||
303 | default :
|
||
304 | if ($fixed){ |
||
305 | $out="<div class='center'><table border='0' class='tab_cadre_fixehov'>\n"; |
||
306 | } else {
|
||
307 | $out="<div class='center'><table border='0' class='tab_cadrehov'>\n"; |
||
308 | } |
||
309 | break;
|
||
310 | } |
||
311 | return $out; |
||
312 | |||
313 | } |
||
314 | |||
315 | /**
|
||
316 | * Print generic new line
|
||
317 | *
|
||
318 | *
|
||
319 | *@param $type display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
|
||
320 | *@param $odd is it a new odd line ?
|
||
321 | *
|
||
322 | *@return string to display
|
||
323 | *
|
||
324 | **/
|
||
325 | function displaySearchNewLine($type,$odd=false){ |
||
326 | $out=""; |
||
327 | switch ($type){ |
||
328 | case PDF_OUTPUT_LANDSCAPE : //pdf |
||
329 | case PDF_OUTPUT_PORTRAIT : |
||
330 | break;
|
||
331 | case SYLK_OUTPUT : //sylk |
||
332 | // $out="\n";
|
||
333 | break;
|
||
334 | case CSV_OUTPUT : //csv |
||
335 | break;
|
||
336 | default :
|
||
337 | $class=" class='tab_bg_2' "; |
||
338 | if ($odd){ |
||
339 | $class=" class='tab_bg_1' "; |
||
340 | } |
||
341 | $out="<tr $class>"; |
||
342 | break;
|
||
343 | } |
||
344 | return $out; |
||
345 | } |
||
346 | /**
|
||
347 | * Print generic end line
|
||
348 | *
|
||
349 | *
|
||
350 | *@param $type display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
|
||
351 | *
|
||
352 | *@return string to display
|
||
353 | *
|
||
354 | **/
|
||
355 | function displaySearchEndLine($type){ |
||
356 | $out=""; |
||
357 | switch ($type){ |
||
358 | case PDF_OUTPUT_LANDSCAPE : //pdf |
||
359 | case PDF_OUTPUT_PORTRAIT : |
||
360 | break;
|
||
361 | case SYLK_OUTPUT : //sylk |
||
362 | break;
|
||
363 | case CSV_OUTPUT : //csv |
||
364 | $out="\n"; |
||
365 | break;
|
||
366 | default :
|
||
367 | $out="</tr>"; |
||
368 | break;
|
||
369 | } |
||
370 | return $out; |
||
371 | } |
||
372 | |||
373 | /**
|
||
374 | * Clean display value for csv export
|
||
375 | *
|
||
376 | *
|
||
377 | *@param $value string value
|
||
378 | *
|
||
379 | *@return clean value
|
||
380 | *
|
||
381 | **/
|
||
382 | function csv_clean($value){ |
||
383 | |||
384 | // $value=utf8_decode($value);
|
||
385 | if (get_magic_quotes_runtime()) $value=stripslashes($value); |
||
386 | // $value=preg_replace('/\x0A/',' ',$value);
|
||
387 | // $value=preg_replace('/\x0D/',NULL,$value);
|
||
388 | $value=ereg_replace("\"","''",$value); |
||
389 | // $value=str_replace(';', ',', $value);
|
||
390 | $value=html_clean($value); |
||
391 | |||
392 | return $value; |
||
393 | } |
||
394 | |||
395 | /**
|
||
396 | * Clean display value for sylk export
|
||
397 | *
|
||
398 | *
|
||
399 | *@param $value string value
|
||
400 | *
|
||
401 | *@return clean value
|
||
402 | *
|
||
403 | **/
|
||
404 | function sylk_clean($value){ |
||
405 | |||
406 | // $value=utf8_decode($value);
|
||
407 | if (get_magic_quotes_runtime()) $value=stripslashes($value); |
||
408 | $value=preg_replace('/\x0A/',' ',$value); |
||
409 | $value=preg_replace('/\x0D/',NULL,$value); |
||
410 | $value=ereg_replace("\"","''",$value); |
||
411 | $value=str_replace(';', ';;', $value); |
||
412 | $value=html_clean($value); |
||
413 | |||
414 | return $value; |
||
415 | } |
||
416 | |||
417 | ?> |