/* This PHP script is designed to output an IC Card interaction
* specifier, and write this information to an XML Based Database.
* 04.20.2007
*/
header('Content-Type: text/html; charset=utf-8');
echo ''."\n";
?>
CS2310 IC Card Interaction Tool
IC Card Management System
- IC Card Interaction Tool
if(makeGlobalArrays())
{
$names = $GLOBALS['names'];
$otherIcs = $GLOBALS['otherIcs'];
/*
* The default urls for the scenario
* and IC system are listed below
*/
$icSystem = "http://www.cs.pitt.edu/~chang/231/cinder/ICSystemDesign.htm";
$scenario = "http://www.cs.pitt.edu/~chang/231/cinder/scenario.htm";
$parentId = array();
$scenarioURL = array();
$systemURL = array();
$otherIcId = array();
if(isSet($_POST['submitInteractions']))
{
/* interactions were posted by the form */
$interactions = array();
foreach($_POST as $key => $val)
{
if(strcmp($key,"dbscenario") == 0)
{
if(strcmp($val,"") != 0)
{
$scenario = $val;
}
}
else if (strcmp($key,"dssystem") == 0)
{
if(strcmp($val,"") != 0)
{
$icSystem = $val;
}
}
else
{
if(is_array($val))
{
if(strcmp($key,"parent")==0)
{
foreach($val as $key2 => $val2)
{
$parentId[$key2] = $val2;
}
}
if(strcmp($key,"scenario")==0)
{
foreach($val as $key2 => $val2)
{
$scenarioURL[$key2] = $val2;
}
}
if(strcmp($key,"system")==0)
{
foreach($val as $key2 => $val2)
{
$systemURL[$key2] = $val2;
}
}
}
}
}
foreach($otherIcs as $key => $val)
{
$otherIcId[$key] = -1;
foreach($names as $key2 => $val2)
{
if($val == $val2)
{
$otherIcId[$key] = $key2;
}
}
}
$outputData = ''."\n"
.''
.serializeInteract($names, $parentId, $otherIcId, $systemURL, $scenarioURL, $scenario, $icSystem)."\n";
$fh = fopen('icInteractionDb.xml','w');
echo "";
if($fh)
{
fwrite($fh,$outputData);
fclose($fh);
echo 'XML Database successfully generated.';
}
else
{
echo 'An error occurred. XML Database was not generated.';
}
echo '
';
}
else
{
/* user did not post anything, present form. */
showForm($names, $scenario, $icSystem);
}
}
else
{
echo "';
}
?>
function serializeInteract($names, $parentId, $otherIcId, $systemURL, $scenarioURL, $scenario, $icSystem)
{
include_once('dom4php/XmlParser.php');
include_once('dom4php/Document.php');
include_once('dom4php/DocumentFragment.php');
include_once('dom4php/XmlSerializer.php');
$parser = new XmlParser();
if($dbData == FALSE)
{
// create file from scratch
$dbDoc =& new Document();
$dbNode = $dbDoc->createElement('icInteractions');
$dbNode->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
$dbNode->setAttribute('xsi:noNamespaceSchemaLocation','icCardInteractions.xsd');
$dbNode->setAttribute('scenario', $scenario);
$dbNode->setAttribute('icSystem', $icSystem);
$dbDoc->appendChild($dbNode);
}
$key = 1;
$val = $names[1];
foreach($names as $key => $val)
{
$tmpNode =& $dbDoc->createElement('icCard');
$tmpNode->setAttribute('id',$key);
$tmpNode->setAttribute('icName',$val);
$tmpNode->setAttribute('parentId',$parentId[$key]);
$tmpNode->setAttribute('otherIcId',$otherIcId[$key]);
if(strcmp($scenarioURL[$key],"")!=0)
{
$tmpNode->setAttribute('scenario',$scenarioURL[$key]);
}
if(strcmp($systemURL[$key],"")!=0)
{
$tmpNode->setAttribute('icSystem',$systemURL[$key]);
}
$dbNode->appendChild($tmpNode);
}
$serializer = new XmlSerializer('XML');
return $serializer->serializeNode($dbDoc);
}
function makeGlobalArrays()
{
include_once('dom4php/XmlParser.php');
$parser = new XmlParser();
$dbData = @file_get_contents('icdb.xml');
if($dbData == FALSE)
{
return false;
}
else
{
$names = array();
$otherIcs = array();
$dbDoc = $parser->parse($dbData);
$idNode =& $dbDoc->childNodes[0];
$cardArray =& $idNode->getElementsByTagName('icCardEntry');
foreach(array_keys($cardArray) as $key)
{
$currId = $cardArray[$key]->getAttribute('id');
$tempArray = $cardArray[$key]->getElementsByTagName('icName');
$currName = $tempArray[0]->getAttribute('content');
$tempArray = $cardArray[$key]->getElementsByTagName('icOtherName');
$currOther = $tempArray[0]->getAttribute('content');
$names[$currId] = $currName;
$otherIcs[$currId] = $currOther;
}
}
$GLOBALS['names'] = $names;
$GLOBALS['otherIcs'] = $otherIcs;
return true;
}
function showForm($namesArray, $scenario, $icSystem)
{
echo '';
}
?>