"; $thanks = $_POST['thanks']; //thanks page $quizid = $_POST['id']; //id of the poll submitted $title = $_POST['title']; //title of poll submitted $config; if ($thanks[0] != '/') { $thanks = '/'.$thanks; } if (file_exists('quizresults.xml')) { $xmlmain = simplexml_load_file('quizresults.xml'); } else { $xmlmain = new SimpleXMLElement($xmlstr); } if(file_exists("quiz-config.xml")) { $config = simplexml_load_file("quiz-config.xml"); } else { die("Could not find quiz-config.xml"); } $fullpath = $config->cmsdirectory."/quiz-results"; $user = $config->username; $pass = $config->password; //supplies WSDL $client = new SoapClient($config->CMSURL . "/ws/services/AssetOperationService?wsdl", array('trace' => 1)); //Grabs the questions and their types and places them in arrays $questions = explode(",",$_POST['inputnames']); $types = explode(",",$_POST['inputvalues']); $answers = explode(",",$_POST['inputanswers']); //Grab IP and timestamp for validation $IP = $_SERVER['REMOTE_ADDR']; $timestamp = $_SERVER['REQUEST_TIME']; $questiontypes = array(); $questionanswer = array(); //build associative array for each question and its type (multiple choice or text) and each question with its answer for($i = 0; $i < count($questions); $i++) { $questiontypes[$questions[$i]] = $types[$i]; $questionanswer[$questions[$i]] = $answers[$i]; } //If the poll exists, we'll add to it. If not, create it. $quizexists; if(isset($xmlmain->quiz)) { foreach($xmlmain->quiz as $quiz) { if($quiz['id'] == $quizid) { $xml = $quiz; $quizexists = TRUE; break; } } if(!$quizexists) { $quiz = $xmlmain->addChild('quiz'); $quiz->addAttribute('id',$quizid); $quiz->addAttribute('title',$title); $xml = $quiz; } } else { $quiz = $xmlmain->addChild('quiz'); $quiz->addAttribute('id',$quizid); $quiz->addAttribute('title',$title); $xml = $quiz; } if (entryExists() == False) { //create new response element and provide its basics $response = $xml->addChild('response'); $response->addChild('IP',$IP); $response->addChild('timestamp',$timestamp); addXML($response); file_put_contents("quizresults.xml",$xmlmain->asXML()); outputToCMS($xmlmain); } echo ""; //check if user submitted within last 24 hrs....if he/she did, do nothing function entryExists() { global $xml; global $IP; global $timestamp; if (isset($xml->response)) { foreach($xml->response as $key) { if ($key->IP == $IP && ($timestamp - $key->timestamp < 86400)) { return True; } } } return False; } //buildquiz data into results XML function addXML($response) { global $xml; global $questiontypes; global $questionanswer; foreach($_POST as $key => $value) { //ignore the thanks page, question names, and question types if ($key != 'thanks' && $key != 'inputnames' && $key != 'inputvalues' && $key != 'id' && $key != 'title' && $key != 'inputanswers') { if (!isset($response->answers)) $response->addChild('answers'); $answer = $response->answers->addChild($key,$value); $answer->addAttribute('answer',$questionanswer[$key]); } } } //Sets up parameters and then writes to CMS function outputToCMS($output) { global $config; global $client; global $fullpath; global $user; global $pass; $data = $output->asXML(); //build params $edit_params = array ( 'authentication' => array( 'password' => $pass . "", 'username' => $user . "" ), 'asset' => array( 'xmlBlock' => array( 'name' => basename($fullpath), 'parentFolderPath' => dirname($fullpath), 'path' => $fullpath, 'metadataSetPath' => "/Default", 'xml' => $data ))); try { //first, attempt to edit the block $client->edit($edit_params); //if edit fails, then block did not exist, so create from scratch if (substr_count($client->__getLastResponse(), "false") > 0) { $edit_params['asset']['xmlBlock']['path'] = ""; $client->create($edit_params); } } catch (Exception $e) { print("Block creation/edit request failed to conform to the WSDL.\n"); print($client->__getLastResponse()); } } ?>