'."\n"; ?> CS2310 IC Card Adder

IC Card Management System - IC Card Adder

$_POST['icNumberTotal']) { echo '

Validation Errors

    '."\n". '
  1. Card Number(s) are not valid.
  2. '."\n"; $complete = false; } /* These are not valid for adding new cards. */ unset($_POST['submitCard']); unset($_POST['icCardID']); unset($_POST['icCardGroupID']); $cardInfo = array(); foreach($_POST as $key => $val) { if(empty($val)) { if($complete){echo '

    Validation Errors

      '."\n";} echo "\t
    1. Missing Entry: $key
    2. \n"; $complete = false; } else { $cardInfo[$key] = $val; } } if($complete) { if($_POST['icNumberTotal'] > 1) { $_SESSION['icData'] = $cardInfo; showGroupForm(); } else { echo '

      Saving the card. '; $outputData = ''."\n" .'' .serializeCard($cardInfo,-1)."\n"; $fh = fopen('icdb.xml','w'); if($fh) { fwrite($fh,$outputData); fclose($fh); echo 'Succeeded.'; } else { echo 'Failed. Please Notify the Administrator.'; } echo '

      Click' .' here to add another card.

      '; } } else { echo '
    '.showCardForm($_POST); } } else { if(isSet($_POST['submitGroup']) && isSet($_SESSION['icData'])) { $cardInfo = $_SESSION['icData']; echo '

    Saving the card. '; $outputData = ''."\n" .'' .serializeCard($cardInfo,$_POST['icGroup'])."\n"; $fh = fopen('icdb.xml','w'); if($fh) { fwrite($fh,$outputData); fclose($fh); echo 'Succeeded.'; } else { echo 'Failed. Please Notify the Administrator.'; } echo '
    Click here to' .' add another card.

    '; unset($_SESSION['icData']); } else { /* user did not post anything, present form. */ echo showCardForm(NULL); } } ?> createDocumentFragment(); $domNode =& $domDoc->createElement('icCard'); $cardDoc->appendChild($domNode); foreach($cardDataArray as $name => $value) { $tmpNode =& $domDoc->createElement($name); $tmpNode->setAttribute('content',$value); $domNode->appendChild($tmpNode); } return $cardDoc; } function serializeCard($cardData,$groupNum) { include_once('dom4php/XmlParser.php'); include_once('dom4php/Document.php'); include_once('dom4php/DocumentFragment.php'); include_once('dom4php/XmlSerializer.php'); $parser = new XmlParser(); $dbData = @file_get_contents('icdb.xml'); if($dbData == FALSE) { // create file from scratch $dbDoc =& new Document(); $dbNode = $dbDoc->createElement('icCardList'); $dbNode->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $dbNode->setAttribute('xsi:noNamespaceSchemaLocation','icCard.xsd'); $dbDoc->appendChild($dbNode); $nodeNum = 1; } else { $dbDoc = $parser->parse($dbData); $dbNode =& $dbDoc->childNodes[0]; $nodeNum = $dbNode->lastChild->previousSibling->attributes['id']; $nodeNum++; } $tmpNode = $dbDoc->createElement('icCardEntry'); $tmpNode->setAttribute('id',$nodeNum); $tmpNode->setAttribute('groupId',$groupNum); $dbNode->appendChild($tmpNode); $tmpNode->appendChild(generateCardXML($dbDoc,$cardData)); $serializer = new XmlSerializer('XML'); return $serializer->serializeNode($dbDoc); } function showGroupForm() { include_once('dom4php/XmlParser.php'); include_once('dom4php/Document.php'); include_once('dom4php/DocumentFragment.php'); include_once('dom4php/XmlSerializer.php'); $parser = new XmlParser(); $dbData = @file_get_contents('icdb.xml'); $groupArray = array(); if($dbData == FALSE) { $groupNum = 1; } else { $groupNum=0; $dbDoc = $parser->parse($dbData); $entryArray = $dbDoc->getElementsByTagName("icCardEntry"); foreach(array_keys($entryArray) as $key) { $tmpVal = $entryArray[$key]->getAttribute('groupId'); if($tmpVal != -1) { $card = $entryArray[$key]->getElementsByTagName("icName"); $groupArray[$tmpVal] .= $card[0]->attributes['content'].', '; if($tmpVal > $groupNum) { $groupNum = $tmpVal; } } } $groupNum++; } echo '
    '; echo '

    Which IC Card Group would you like to add' .' this card to?

    '; foreach($groupArray as $key => $val) { echo ' '; echo 'Group '.$key.': '.substr($val,0,strlen($val)-2).'
    '; } echo ' Create a New Group (Group '.$groupNum.').' .'

    '; } ?>