<?php require_once('Connections/ml_db.php'); ?>
<?php
// Load the XML classes
require_once('includes/XMLExport/XMLExport.php');
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_ml_db, $ml_db);
$query_Recordset1 = "SELECT * FROM ml_products";
$Recordset1 = mysql_query($query_Recordset1, $ml_db) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
// Begin XMLExport Recordset1
$xmlExportObj = new XMLExport();
$xmlExportObj->setRecordset($Recordset1);
$xmlExportObj->addColumn("id", "id");
$xmlExportObj->addColumn("name", "name");
$xmlExportObj->addColumn("type", "type");
$xmlExportObj->addColumn("subtype", "subtype");
$xmlExportObj->addColumn("img_url", "img");
$xmlExportObj->addColumn("description_small", "description_small");
$xmlExportObj->addColumn("description_detail1", "description_detail1");
$xmlExportObj->addColumn("description_detail2", "description_detail2");
$xmlExportObj->addColumn("price", "price");
$xmlExportObj->addColumn("promo", "promo");
$xmlExportObj->addColumn("order", "order");
$xmlExportObj->setMaxRecords("ALL");
$xmlExportObj->setDBEncoding("UTF-8");
$xmlExportObj->setXMLEncoding("UTF-8");
$xmlExportObj->setXMLFormat("NODES");
$xmlExportObj->Execute();
// End XMLExport Recordset1
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
XMLExport.php
<?php
/*
* ADOBE SYSTEMS INCORPORATED
* Copyright 2007 Adobe Systems Incorporated
* All Rights Reserved
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
* terms of the Adobe license agreement accompanying it. If you have received this file from a
* source other than Adobe, then your use, modification, or distribution of it requires the prior
* written permission of Adobe.
*/
/*
Copyright (c) InterAKT Online 2000-2006. All rights reserved.
*/
$KT_XMLExport_uploadErrorMsg = '<strong>XMLExport Error.</strong><br/>File not found: %s. Please upload the includes/ folder to the testing server.';
$KT_XMLExport_uploadFileList = array('XMLExport.class.php');
for ($KT_XMLExport_i=0;$KT_XMLExport_i<sizeof($KT_XMLExport_uploadFileList);$KT_XMLExport_i++) {
$KT_XMLExport_uploadFileName = dirname(realpath(__FILE__)). '/' . $KT_XMLExport_uploadFileList[$KT_XMLExport_i];
if (file_exists($KT_XMLExport_uploadFileName)) {
require_once($KT_XMLExport_uploadFileName);
} else {
die(sprintf($KT_XMLExport_uploadErrorMsg,$KT_XMLExport_uploadFileList[$KT_XMLExport_i]));
}
}
?>
XMLExport.class.php
<?php
/*
* ADOBE SYSTEMS INCORPORATED
* Copyright 2007 Adobe Systems Incorporated
* All Rights Reserved
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
* terms of the Adobe license agreement accompanying it. If you have received this file from a
* source other than Adobe, then your use, modification, or distribution of it requires the prior
* written permission of Adobe.
*/
/*
Copyright (c) InterAKT Online 2000-2006. All rights reserved.
*/
/**
* This is the class responsable for generating and exporting the XML file.
*/
class XMLExport {
/**
* Internal array for storing the column that will be exported.
*/
var $columns;
/**
* The recordset from where the data will be exported.
*/
var $recordset;
/**
* The maximum number of records to be exported. It can be either the string 'ALL' or the actual number of records.
*/
var $maxRecords;
/**
* The encoding in which the data is stored in the database.
*/
var $dbEncoding;
/**
* The encoding which will be set for the exported XML file.
*/
var $xmlEncoding;
/**
* The XML format. It can export the fields as either NODES or ATTRIBUTES.
*/
var $xmlFormat;
/**
* The name of the root element in the exported XML
*/
var $rootNodeName;
/**
* The name of the row element in the exported XML
*/
var $rowNodeName;
/**
* Class constructor. Member variables are initialized to their default values.
*/
function XMLExport() {
$this->maxRecords = 'ALL';
$this->xmlFormat = 'NODES';
$this->columns = array();
$this->rootNodeName = 'export';
$this->rowNodeName = 'row';
}
/**
* This is the setter for the recordset member variable.
*
* @param recordset The recordset from where to retrieve the data for the export.
*/
function setRecordset(&$recordset) {
$this->recordset = $recordset;
}
/**
* This is the setter for the maxRecords member variable specifying how may records should be exported.
*
* @param maxRecords The string 'ALL' or the number of records.
*/
function setMaxRecords($maxRecords) {
$this->maxRecords = trim($maxRecords);
}
/**
* This is the setter for the dbEncoding member variable.
*
* @param dbEncoding The encoding in which the data is stored in the database.
*/
function setDBEncoding($dbEncoding) {
$this->dbEncoding = trim($dbEncoding);
}
/**
* This is the setter for the xmlEncoding member variable.
*
* @param xmlEncoding The encoding that will be set for the XML.
*/
function setXMLEncoding($xmlEncoding) {
$this->xmlEncoding = trim($xmlEncoding);
}
/**
* This is the setter for the xmlFormat member variable.
*
* @param xmlFormat The format in which the XML file should export the data: "NODES" or "ATTRIBUTES".
*/
function setXMLFormat($xmlFormat) {
$this->xmlFormat = strtoupper(trim($xmlFormat));
if ($this->xmlFormat != 'ATTRIBUTES') {
$this->xmlFormat == 'NODES';
}
}
/**
* This is the setter for the rootNodeName member variable.
*
* @param rootNodeName The name of the root element in the resulting XML.
*/
function setRootNode($rootNodeName) {
$this->rootNodeName = trim($rootNodeName);
}
/**
* This is the setter for the rowNodeName member variable.
*
* @param rowNodeName The name of the row element in the resulting XML.
*/
function setRowNode($rowNodeName) {
$this->rowNodeName = trim($rowNodeName);
}
/**
* This method adds a column to the member variable columns which holds the columns that the XML file will have.
*
* @param column The name of the column as it appears in the recordset.
* @param label The label that will be used in the exported XML file to identify this field.
*/
function addColumn($column, $label = '') {
$this->columns[trim($column)] = array('label' => trim($label));
}
/**
* This method is the one that generates and exports the XML file.
*/
function Execute() {
if ( !isset($this->recordset) || !is_resource($this->recordset) ) {
die('<strong>XMLExport Error.</strong><br/>Passed argument is not a valid recordset.');
return;
}
if (count($this->columns) < 1) {
die('<strong>XMLExport Error.</strong><br/>No columns defined!');
return;
}
$document = '';
$document .= '<'.'?xml version="1.0" encoding="' . $this->xmlEncoding . '"?'.'>';
$document .= "\r\n";
$document .= '<' . $this->rootNodeName . '>';
$document .= "\r\n";
$numRow = 1;
if(mysql_num_rows($this->recordset) > 0) {
mysql_data_seek($this->recordset, 0);
}
while($row_recordset = mysql_fetch_assoc($this->recordset)) {
if ($this->maxRecords != 'ALL' && $this->maxRecords < $numRow) {
break;
}
$row = "\t";
$row .= '<' . $this->rowNodeName;
if ($this->xmlFormat != 'ATTRIBUTES') {
$row .= '>' . "\r\n";
}
foreach ($this->columns as $column => $details) {
$colName = $column;
if ($details['label'] != '') {
$colName = $details['label'];
}
$value = $row_recordset[$column];
if ($this->xmlEncoding != $this->dbEncoding) {
if (!function_exists('mb_convert_encoding')) {
die('<strong>XMLExport Error.</strong><br/>Could not perform characters conversion. Function <strong>mb_convert_encoding</strong> is not available! Please enable the <strong>mbstring</strong> extension!');
}
$value = mb_convert_encoding($value, $this->xmlEncoding, $this->dbEncoding);
}
$value = str_replace(array('&', '>', '<', '"'), array('&', '>', '<', '"'), $value);
if ($this->xmlFormat == 'ATTRIBUTES') {
$row .= ' ' . $colName . '="';
$row .= $value;
$row .= '"';
} else {
$row .= "\t\t";
$row .= '<' . $colName . '>';
$row .= $value;
$row .= '</' . $colName . '>';
$row .= "\r\n";
}
}
if ($this->xmlFormat == 'ATTRIBUTES') {
$row .= ' />';
} else {
$row .= "\t" . '</' . $this->rowNodeName . '>';
}
$document .= $row;
$document .= "\r\n";
$numRow++;
}
$document .= '</' . $this->rootNodeName . '>';
$size = strlen($document);
$this->sendHeaders($size);
echo $document;
exit;
}
/**
* This method is used to send the appropriate headers.
*
* @param size The size of the XML being exported.
*/
function sendHeaders($size) {
if (headers_sent()) {
die('<strong>XMLExport Error.</strong><br/>Headers already sent! The XML cannot be exported');
}
header('Content-type: text/xml; charset=' . $this->xmlEncoding);
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');
header('Content-Length: ' . $size);
}
}
?>