Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / inc / xml.class.php @ b67d8923

Historique | Voir | Annoter | Télécharger (5,28 ko)

1
<?php
2

    
3
/*
4
 * @version $Id: xml.class.php 7763 2009-01-06 18:44:50Z moyo $
5
 -------------------------------------------------------------------------
6
 GLPI - Gestionnaire Libre de Parc Informatique
7
 Copyright (C) 2003-2009 by the INDEPNET Development Team.
8

9
 http://indepnet.net/   http://glpi-project.org
10
 -------------------------------------------------------------------------
11

12
 LICENSE
13

14
 This file is part of GLPI.
15

16
 GLPI is free software; you can redistribute it and/or modify
17
 it under the terms of the GNU General Public License as published by
18
 the Free Software Foundation; either version 2 of the License, or
19
 (at your option) any later version.
20

21
 GLPI is distributed in the hope that it will be useful,
22
 but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 GNU General Public License for more details.
25

26
 You should have received a copy of the GNU General Public License
27
 along with GLPI; if not, write to the Free Software
28
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
 --------------------------------------------------------------------------
30
 */
31

    
32
// ----------------------------------------------------------------------
33
// Based on the original file:
34
//* Author        : Roberto B.               *
35
//* E-Mail        : roberto.butti@libero.it  *
36
//* Version        : 1.0.3                    *
37
// Purpose of file:
38
// ----------------------------------------------------------------------
39

    
40
if (!defined('GLPI_ROOT')){
41
        die("Sorry. You can't access directly to this file");
42
        }
43

    
44

    
45
/// XML class
46
class XML {
47
        /// Array of SQL requests to export
48
        var $SqlString;
49
        /// 1 there is a problem !!!
50
        var $IsError;
51
        /// If there is an error, this string explains it
52
        var $ErrorString;
53
        /// Which format do you want your XML ?
54
        var $Type;
55
        ///path where the file will be saved.        
56
        var $FilePath;  
57

    
58
        // HERE I explain $Type
59

    
60
        /* For Example :
61
           1 (default) each value are in a tag called data
62
           <dataxml>
63
           <row>
64
           <data>value field1 row1</data>
65
           <data>value field2 row1</data>
66
           <data>value field3 row1</data>
67
           </row>
68
           <row>
69
           <data>value field1 row2</data>
70
           <data>value field2 row2</data>
71
           <data>value field3 row2</data>
72
           </row>
73
           </dataxml>
74

75
           2 each value is in a tag called dataN , where N is a position of field
76
           <dataxml>
77
           <row>
78
           <data1>value field1 row1</data1>
79
           <data2>value field2 row1</data2>
80
           <data3>value field3 row1</data3>
81
           </row>
82
           <row>
83
           <data1>value field1 row2</data1>
84
           <data2>value field2 row2</data2>
85
           <data3>value field3 row2</data3>
86
           </row>
87
           </dataxml>
88

89
           3 each value is in a tag called with the name of field
90
           <dataxml>
91
           <row>
92
           <fieldname1>value field1 row1</fieldname1>
93
           <fieldname2>value field2 row1</fieldname2>
94
           <fieldname3>value field3 row1</fieldname3>
95
           </row>
96
           <row>
97
           <fieldname1>value field1 row2</fieldname1>
98
           <fieldname2>value field2 row2</fieldname2>
99
           <fieldname3>value field3 row2</fieldname3>
100
           </row>
101
           </dataxml>
102

103
           4 each value is in a tag with an attributes called fieldname with the name of field
104
           <dataxml>
105
           <row>
106
           <data fieldname="fieldname1">value field1 row1</data>
107
           <data fieldname="fieldname2">value field1 row1</data>
108
           <data fieldname="fieldname3">value field1 row1</data>
109
           </row>
110
           <row>
111
           <data fieldname="fieldname1">value field1 row2</data>
112
           <data fieldname="fieldname2">value field1 row2</data>
113
           <data fieldname="fieldname3">value field1 row2</data>
114
           </row>
115
           </dataxml>
116

117

118
         */
119
        /**
120
         * Constructor
121
        **/
122
        function XML()
123
        {
124
                // Initialize the values with DEFAULT value
125
                $this->IsError=0;
126
                $this->Type=1;
127
                $this->ErrorString="NO errors ;)";
128
                $this->SqlString="";
129
        }
130

    
131

    
132
        /**
133
         * Do XML export
134
        **/
135
        function DoXML(){
136
                global $DB;
137
                $fp = fopen($this->FilePath,'wb');
138
                fputs($fp, "<?xml version=\"1.0\"?>\n");
139
                fputs($fp, "<dataxml>\n");
140

    
141
                foreach($this->SqlString as $strqry){
142
                        if ($strqry==""){
143
                                $this->IsError=1;
144
                                $this->ErrorString="Error the query can't be a null string";
145
                                return -1;
146
                        }
147
                        $result = $DB->query($strqry);
148

    
149
                        if ($result==FALSE){
150
                                $this->IsError=1;
151
                                $this->ErrorString="Error in SQL Query : ".$strqry;
152
                                return -1;
153
                        }
154
                        // OK... let's create XML ;)
155
                        fputs($fp, "        <fields>\n");
156
                        $i = 0;
157
                        $FieldsVector=array();
158
                        while ($i < $DB->num_fields ($result)){
159
                                $name = $DB->field_name($result,$i);
160
                                fputs($fp, "                <field>".$name."</field>\n");
161
                                $FieldsVector[]=$name;
162
                                $i++;
163
                        }
164

    
165
                        fputs($fp, "        </fields>\n");
166
                        // And NOW the Data ...
167
                        fputs($fp, "        <rows>\n");
168
                        while ($row = $DB->fetch_array ($result)){
169
                                fputs($fp, "                <row>\n");
170
                                for ($j=0; $j<$i; $j++){
171
                                        $FieldName="";                        // Name of TAG
172
                                        $Attributes="";
173
                                        switch ($this->Type){
174
                                                case 1:
175
                                                        $FieldName="data";
176
                                                        break;
177
                                                case 2:
178
                                                        $FieldName="data".$j;
179
                                                        break;
180
                                                case 3:
181
                                                        $FieldName=$FieldsVector[$j];
182
                                                        break;
183
                                                case 4:
184
                                                        $FieldName="data";
185
                                                        $Attributes=" fieldname=\"".$FieldsVector[$j]."\"";
186
                                        }
187
                                        fputs($fp, "                        <".$FieldName.$Attributes.">".utf8_encode(htmlspecialchars($row[$j]))."</".$FieldName.">\n");
188
                                }
189
                                fputs($fp, "                </row>\n");
190
                        }
191
                        fputs($fp, "        </rows>\n");
192

    
193
                        $DB->free_result($result);
194
                }
195
                fputs($fp, "</dataxml>");
196
                //OK free ...  ;)
197
                fclose($fp);
198

    
199
        } // End  Function : DoXML
200
} // Fine Class XML
201

    
202

    
203
?>
Redmine Appliance - Powered by TurnKey Linux