grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ // ---------------------------------------------------------------------- // Based on the original file: //* Author : Roberto B. * //* E-Mail : roberto.butti@libero.it * //* Version : 1.0.3 * // Purpose of file: // ---------------------------------------------------------------------- if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /// XML class class XML { /// Array of SQL requests to export public $SqlString = ""; /// 1 there is a problem !!! public $IsError = 0; /// If there is an error, this string explains it public $ErrorString = "NO errors ;)"; /// Which format do you want your XML ? public $Type = 1; ///path where the file will be saved. public $FilePath; // HERE I explain $Type /* For Example : 1 (default) each value are in a tag called data value field1 row1 value field2 row1 value field3 row1 value field1 row2 value field2 row2 value field3 row2 2 each value is in a tag called dataN , where N is a position of field value field1 row1 value field2 row1 value field3 row1 value field1 row2 value field2 row2 value field3 row2 3 each value is in a tag called with the name of field value field1 row1 value field2 row1 value field3 row1 value field1 row2 value field2 row2 value field3 row2 4 each value is in a tag with an attributes called fieldname with the name of field value field1 row1 value field1 row1 value field1 row1 value field1 row2 value field1 row2 value field1 row2 */ /** * Do XML export **/ function DoXML() { global $DB; $fp = fopen($this->FilePath,'wb'); fputs($fp, "\n"); fputs($fp, "\n"); foreach ($this->SqlString as $strqry) { if ($strqry == "") { $this->IsError = 1; $this->ErrorString = "Error the query can't be a null string"; return -1; } $result = $DB->query($strqry); if ($result == FALSE) { $this->IsError = 1; $this->ErrorString = "Error in SQL Query: ".$strqry; return -1; } // OK... let's create XML ;) fputs($fp, " \n"); $i = 0; $FieldsVector = array(); while ($i < $DB->num_fields ($result)) { $name = $DB->field_name($result,$i); fputs($fp, " ".$name."\n"); $FieldsVector[] = $name; $i++; } fputs($fp, " \n"); // And NOW the Data ... fputs($fp, " \n"); while ($row = $DB->fetch_row($result)) { fputs($fp, " \n"); for ($j=0 ; $j<$i ; $j++) { $FieldName = ""; // Name of TAG $Attributes = ""; switch ($this->Type) { case 1 : $FieldName = "data"; break; case 2 : $FieldName = "data".$j; break; case 3 : $FieldName = $FieldsVector[$j]; break; case 4 : $FieldName = "data"; $Attributes = " fieldname=\"".$FieldsVector[$j]."\""; } fputs($fp, " <".$FieldName.$Attributes.">". Toolbox::encodeInUtf8(htmlspecialchars($row[$j]))."\n"); } fputs($fp, " \n"); } fputs($fp, " \n"); $DB->free_result($result); } fputs($fp, ""); //OK free ... ;) fclose($fp); } // End Function : DoXML } // Fine Class XML