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');
 }
Beispiel #2
0
 /**
  * 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 testDeletingRemovesHiddenInstances()
 {
     $this->auth();
     $xml = file_get_contents(PROJECT_PATH . "/test/data/xml/test1-questionnaire-definition.xml");
     QuestionnaireModel::importXML($xml);
     $questionnaire = new QuestionnaireModel(array('questionnaireName' => 'Test1 Questionnaire', 'questionnaireVersion' => '3.00', 'revision' => 1, 'depth' => 'instance'));
     $instanceID = $questionnaire->getDefaultInstance()->instanceID;
     $questionnaire->delete();
     QFrame_Db_Table::resetAll();
     try {
         new InstanceModel(array('instanceID' => $instanceID));
     } catch (Exception $e) {
         $this->assertTrue(preg_match('/^Instance not found/', $e->getMessage()) > 0);
         return;
     }
     $this->fail('Fetching hidden instance after questionnaire deletion should throw an exception');
 }
Beispiel #4
0
 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'));
 }
 /**
  * Action for importing an questionnaire
  */
 public function importQuestionnaireAction()
 {
     $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.');
     $decryptID = $this->_hasParam('decryptID') ? $this->_getParam('decryptID') : null;
     $errorCode = $_FILES['questionnaireFile']['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['questionnaireFile']['tmp_name'];
     $filename = $_FILES['questionnaireFile']['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));
             $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 . ']');
     }
     QuestionnaireModel::importXML($import);
     $this->flash('notice', 'Import Complete');
     $this->_redirector->gotoRoute(array('action' => 'index'));
 }
Beispiel #7
0
include implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', 'core', 'utility.php'));
$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);