public function up() { // reset db metadata cache QFrame_Db_Table::scanDb(); QFrame_Db_Table::resetAll(); $this->auth(); $xml = file_get_contents(_path(PROJECT_PATH, 'xml', 'sig-4-0-questionnaire-definition.xml')); QuestionnaireModel::importXML($xml); InstanceModel::importXML($xml, 'Sample SIG Instance'); }
public function up() { // add the column $this->addColumn('instance', 'hidden', 'boolean', array('default' => 0)); // reset db metadata cache QFrame_Db_Table::scanDb(); QFrame_Db_Table::resetAll(); // make sure that existing questionnaires have a default instance (and create one if not) $this->auth(); foreach (QuestionnaireModel::getAllQuestionnaires('instance') as $questionnaire) { $default = $questionnaire->getDefaultInstance(); if ($default === null) { $xml = $questionnaire->fetchQuestionnaireDefinition(); InstanceModel::importXML($xml, '_default_', array('hidden' => 1)); } } }
public function testEncryptedZipArchiveExportCanBeImported() { $this->auth(); $crypto = CryptoModel::importRijndael256Key('testdupe', 'BqPwhnSskTFzxPUlljXG1zgG8cfgTSaGj8UyRWsKanA='); $instance = new InstanceModel(array('instanceID' => 1)); $zip = new ZipArchiveModel($instance, array('new' => '1')); $zip->addInstanceFullResponsesXMLDocument(); $zip->close(); $encrypted = $crypto->encrypt($zip->getZipFileContents()); $zip->deleteZipFile(); $decrypted = $crypto->decrypt($encrypted); $tempfile = tempnam(PROJECT_PATH . DIRECTORY_SEPARATOR . 'tmp', 'zip'); unlink($tempfile); file_put_contents($tempfile, $decrypted); $zip = new ZipArchiveModel(null, array('filename' => $tempfile)); InstanceModel::importXML($zip, 'test encryption import'); $zip->deleteZipFile(); }
/** * Generates a signature for an questionnaire definition * * @param questionnaire definition xml dom object * @return string md5 hash */ public static function generateSignature($dom) { $questionnaireID = QuestionnaireModel::importXML($dom, array('SkipQuestionnaireExistCheck' => 1, 'SkipFileAttachments' => 1)); $instanceID = InstanceModel::importXML($dom, '_generateSignature', array('questionnaireID' => $questionnaireID)); $instance = new InstanceModel(array('instanceID' => $instanceID, 'depth' => 'instance')); $questionnaire = new QuestionnaireModel(array('questionnaireID' => $questionnaireID, 'depth' => 'questionnaire')); $signature = md5($instance->toXML(1)); $instance->delete(); $questionnaire->delete(); return $signature; }
public function testNoResponsesInstanceWithMergedResponsesExportEqualsResponsesInstanceExport() { $this->auth(); $xml = file_get_contents(PROJECT_PATH . "/test/data/xml/responses-questionnaire-definition.xml"); QuestionnaireModel::importXML($xml); InstanceModel::importXML($xml, 'Test1 Resp. Company', array('pageResponses' => array('all' => 1))); $instance1 = new InstanceModel(array('questionnaireName' => 'Test1 Questionnaire', 'questionnaireVersion' => '3.00', 'revision' => 1, 'instanceName' => 'Test1 Resp. Company')); $xml = file_get_contents(PROJECT_PATH . "/test/data/xml/no-responses-questionnaire-definition.xml"); InstanceModel::importXML($xml, 'Test1 Company', array('instanceID' => $instance1->instanceID)); $instance2 = new InstanceModel(array('questionnaireName' => 'Test1 Questionnaire', 'questionnaireVersion' => '3.00', 'revision' => 1, 'instanceName' => 'Test1 Company')); $xml1 = $instance1->toXML(1); $xml2 = $instance2->toXML(1); $xml1 = preg_replace("/Test1 Resp. Company/", "Test1 Company", $xml1); $xml1 = preg_replace("/<csi:responseDate>.+<\\/csi:responseDate>/", "", $xml1); $xml2 = preg_replace("/<csi:responseDate>.+<\\/csi:responseDate>/", "", $xml2); $this->assertEquals($xml1, $xml2); }
/** * Action for importing an instance */ public function importInstanceAction() { $session = new Zend_Session_Namespace('login'); $instanceID = $session->importResponsesInstanceID; $instanceName = $this->_getParam('instanceName'); $importResponses = $this->_getParam('importResponsesRadioButton'); $decryptID = $this->_hasParam('decryptID') ? $this->_getParam('decryptID') : null; if (is_numeric($instanceID)) { $session->importResponsesInstanceID = intVal($instanceID); } elseif (isset($importResponses) && $importResponses === 'importInstanceResponses') { $this->_redirector->gotoRouteAndExit(array('action' => 'index')); } $uploadErrors = array(UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.', UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded.', UPLOAD_ERR_NO_FILE => 'No file was uploaded.', UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder.', UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.', UPLOAD_ERR_EXTENSION => 'File upload stopped by extension.'); $errorCode = $_FILES['instanceFile']['error']; if ($errorCode !== UPLOAD_ERR_OK) { if (isset($uploadErrors[$errorCode])) { throw new Exception($uploadErrors[$errorCode]); } else { throw new Exception("Unknown error uploading file."); } } $file = $_FILES['instanceFile']['tmp_name']; $filename = $_FILES['instanceFile']['name']; if (preg_match('/\\.enc$/i', $filename)) { if (!isset($decryptID) || $decryptID == 0) { throw new Exception('Key not specified for encrypted file'); } $crypto = new CryptoModel(array('cryptoID' => $decryptID)); if (preg_match('/\\.zip\\.enc$/i', $filename)) { $decrypted = $crypto->decrypt(file_get_contents($file), false); $tempfile = tempnam(PROJECT_PATH . DIRECTORY_SEPARATOR . 'tmp', 'zip'); unlink($tempfile); file_put_contents($tempfile, $decrypted); $import = new ZipArchiveModel(null, array('filename' => $tempfile)); } elseif (preg_match('/\\.xml.enc$/i', $filename)) { $decrypted = $crypto->decrypt(file_get_contents($file)); $import = $decrypted; } else { throw new Exception('Unrecognized file extension [' . $filename . ']'); } } elseif (preg_match('/\\.zip$/i', $filename)) { $import = new ZipArchiveModel(null, array('filename' => $file)); } elseif (preg_match('/\\.xml$/i', $filename)) { $import = file_get_contents($file); } else { throw new Exception('Unrecognized file extension [' . $filename . ']'); } // Import the questionnaire definition if it doesn't already exist QuestionnaireModel::importXML($import); if ($importResponses === 'importInstanceResponses') { $importResponsesInstanceID = $this->_getParam('importResponsesInstanceSelect'); InstanceModel::importXML($import, $instanceName, array('instanceID' => $importResponsesInstanceID)); } elseif ($importResponses === 'importXMLResponses') { InstanceModel::importXML($import, $instanceName, array('pageResponses' => array('all' => 1))); } else { InstanceModel::importXML($import, $instanceName); } $this->flash('notice', 'Import Complete'); $this->_redirector->gotoRoute(array('action' => 'index')); }
$core_path = _path(dirname(__FILE__), '..', 'core'); /* * Set up a bunch of path constants that the application will use to refer * to various application directories */ include _path(dirname(__FILE__), '..', 'core', 'paths.php'); /* * Deal with environment stuff including determining the current environment * and loading the configuration stuff for that environment */ include _path(CORE_PATH, 'env.php'); /* * Include file that contains pure configuration (used for testing) * as well as routing. Also include the file that sets up database * "stuff". */ include _path(CORE_PATH, 'database.php'); /* * Set up any dynamic properties (properties that rely on current environment configuration) */ include _path($core_path, 'dynamic.php'); // perform mock authentication $auth_adapter = new QFrame_Auth_Adapter('', '', true); $auth = Zend_Auth::getInstance(); $auth->authenticate($auth_adapter); $content = file_get_contents(_path(PROJECT_PATH, 'xml', 'sig-4-0-questionnaire-definition.xml')); QuestionnaireModel::importXML($content); $options['pageResponses']['all'] = 1; // import all responses InstanceModel::importXML($content, 'Acme Vendor', $options);