ERROR! Please fill out the following fields: ";
$msgEmailFormat = " | ERROR! The following problems occured: ";
$msgCustExist = " |
ERROR! This Personnel already exists in the system. Please add another entry! |
";
$msgTaskComplete = "| TASK COMPLETE! |
";
// Initialise all sessions
$XMLFileChk = (isset($_FILES['xmlfile']) && is_uploaded_file($_FILES['xmlfile']['tmp_name'])) ? true : false;
// Arrays - of required HTML field names and correspond error messages for each field name
$htmlfields = array($XMLFileChk);
$errfields = array('XML File');
// this is the total number of required fields
$numFields = count($htmlfields);
//initiate value for first check
//the first check is to ensure user fills in all required fields.
$errorFound01=false;
$msg01 = $msgStandard;
for($i=0; $i<$numFields; $i++)
{
if ((!strlen($htmlfields[$i]) > 0) || ($htmlfields[$i] == ""))
{
$msg01 = $msg01 . $errfields[$i] . "
";
$errorFound01 = true;
}
}
if($errorFound01)
{
$_SESSION["errorMsg"] = $msg01 . "";
header("Location: $back");
}
// Initiate second check
else
{
//initiate value for second check
$errorFound02=false;
$msg02 = $msgEmailFormat;
/*
arrayChkFields = array();
$numChkFields = count($arrayChkFields);
for($j=0; $j<$numChkFields; $j++)
{
if(!ereg($arrayChkFields[$j][1], $arrayChkFields[$j][0]))
{
$errorFound02 = true;
$msg02 .= $arrayChkFields[$j][2];
}
}
*/
if($errorFound02)
{
$_SESSION['errorMsg'] = $msg02 . "";
header("Location: $back");
}
else
{
// do stuff here
$xmlfile_data = '';
$xml_data = '';
$current_tag = '';
$listing = array();
$index = 0;
$fh = fopen($_FILES['xmlfile']['tmp_name'], "r") or die("Unable to open XML file");
/* Read data from file into a string buffer */
// while (!feof($fh)) {
// $xmlfile_data .= fread($fh, 4096);
// }
$parser = xml_parser_create();
/* Disable XML tag capitalisation (Case Folding) */
xml_parser_set_option ($parser, XML_OPTION_CASE_FOLDING, FALSE);
// xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING, 'US-ASCII');
// xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
/* Define Callback functions for XML Parsing */
//xml_set_object($this->parser, &$this);
xml_set_element_handler ($parser, "xml_element_start", "xml_element_end");
xml_set_character_data_handler ($parser, "xml_data");
// read data from input and parse
while ($data = fread($fh, 4096)) {
if (!xml_parse($parser, $data, feof($fh))) {
die('Whoops');
}
}
/* Parse the XML response */
// xml_parse($parser, $xmlfile_data, TRUE);
/* Clean up after ourselves */
xml_parser_free ($parser);
fclose ($fh);
echo "Debug: ";
print_r($listing);
echo "
\n";
//unset();
$_SESSION['errorMsg'] = $msgTaskComplete;
header("Location: $continue");
}
}
/* Call back Functions for the XML Parser */
function xml_element_start ($parser, $tag, $attributes) {
global $current_tag;
global $in_listing, $listing, $index;
$tmp_array = array();
$current_tag = $tag;
switch(strtolower($tag)) {
case 'propertylist':
echo "Debug: Found propertyList start tag
\n";
break;
case 'residential':
echo "Debug: Found residential listing start tag
\n";
$in_listing = true;
$listing[$index] = array();
$listing[$index]['Classification'] = 'Property';
break;
case 'land':
echo "Debug: Found land listing start tag
\n";
$in_listing = true;
$listing[$index] = array();
$listing[$index]['Classification'] = 'Land';
break;
case 'images':
echo "Debug: Found image list
\n";
$listing[$index]['images'] = $tmp_array;
$listing[$index]['images'][0] = '';
echo "Debug: isset(\$listing[\$index]['images']) [".(isset($listing[$index]['images']) ? 'true' : 'false')."] is_array(\$listing[\$index]['images']) [".(is_array($listing[$index]['images']) ? 'true' : 'false')."]
\n";
echo "Debug: ";
print_r($listing);
echo "
\n";
break;
case 'img':
echo "Debug: Found image - ";
print_r($attributes);
echo "
\n";
echo "Debug: ";
print_r($listing);
echo "
\n";
echo "Debug: isset(\$listing[\$index]['images']) [".(isset($listing[$index]['images']) ? 'true' : 'false')."] is_array(\$listing[\$index]['images']) [".(is_array($listing[$index]['images']) ? 'true' : 'false')."]
\n";
$listing[$index]['images'][] = '';
break;
default:
echo "Setting \$listing[\$index][\$current_tag] to null (index is $index - current_tag is $current_tag)
\n";
$listing[$index][$current_tag] = '';
break;
}
}
function xml_element_end ($parser, $tag) {
global $current_tag;
global $in_listing, $listing, $index;
switch(strtolower($tag)) {
case 'propertylist':
echo "Debug: Found propertyList end tag
\n";
break;
case 'residential':
echo "Debug: Found residential listing end tag
\n";
$in_listing = false;
$index++;
break;
case 'land':
echo "Debug: Found land listing end tag
\n";
$in_listing = false;
$index++;
break;
default:
break;
}
$current_tag = "";
}
function xml_data ($parser, $cdata) {
global $xml_data, $current_tag;
global $in_listing, $listing, $index;
// we're only interested in data thats inside a property listing
if($in_listing) {
if($current_tag)
$listing[$index][$current_tag] .= $cdata;
/*
else
echo "Debug: (In listing) - current tag is null
\n";
*/
}
}
?>