. * --------------------------------------------------------------------- */ 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 = []; while ($i < $DB->numFields ($result)) { $name = $DB->fieldName($result, $i); fputs($fp, " ".$name."\n"); $FieldsVector[] = $name; $i++; } fputs($fp, " \n"); // And NOW the Data ... fputs($fp, " \n"); while ($row = $DB->fetchRow($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->freeResult($result); } fputs($fp, ""); //OK free ...;) fclose($fp); } // End Function : DoXML } // Fine Class XML