Skip to content

Commit

Permalink
Dev: Remove redundant controller showquexmlsurvey
Browse files Browse the repository at this point in the history
Dev: Add method and view for clearing queXML default settings
  • Loading branch information
adamzammit committed Jul 22, 2015
1 parent 3a2a523 commit cad4901
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 81 deletions.
118 changes: 37 additions & 81 deletions application/controllers/admin/export.php
Expand Up @@ -760,77 +760,6 @@ public function vvexport()
}
}

/**
* quexml survey export
*/
public function showquexmlsurvey()
{
$iSurveyID = sanitize_int(Yii::app()->request->getParam('surveyid'));
$lang = ( isset($_GET['lang']) ) ? Yii::app()->request->getParam('lang') : NULL;
$tempdir = Yii::app()->getConfig("tempdir");

// Set the language of the survey, either from GET parameter of session var
if ( $lang != NULL )
{
$lang = preg_replace("/[^a-zA-Z0-9-]/", "", $lang);
if ( $lang ) $surveyprintlang = $lang;
}
else
{
$surveyprintlang=Survey::model()->findByPk($iSurveyID)->language;
}

// Setting the selected language for printout
App()->setLanguage($surveyprintlang);

Yii::import("application.libraries.admin.quexmlpdf", TRUE);
$quexmlpdf = new quexmlpdf($this->getController());

$quexmlpdf->setLanguage($surveyprintlang);

set_time_limit(120);

$noheader = TRUE;

$quexml = quexml_export($iSurveyID, $surveyprintlang);

$quexmlpdf->create($quexmlpdf->createqueXML($quexml));

//NEED TO GET QID from $quexmlpdf
$qid = intval($quexmlpdf->getQuestionnaireId());

$zipdir= $this->_tempdir($tempdir);

$f1 = "$zipdir/quexf_banding_{$qid}_{$surveyprintlang}.xml";
$f2 = "$zipdir/quexmlpdf_{$qid}_{$surveyprintlang}.pdf";
$f3 = "$zipdir/quexml_{$qid}_{$surveyprintlang}.xml";
$f4 = "$zipdir/readme.txt";

file_put_contents($f1, $quexmlpdf->getLayout());
file_put_contents($f2, $quexmlpdf->Output("quexml_$qid.pdf", 'S'));
file_put_contents($f3, $quexml);
file_put_contents($f4, gT('This archive contains a PDF file of the survey, the queXML file of the survey and a queXF banding XML file which can be used with queXF: http://quexf.sourceforge.net/ for processing scanned surveys.'));

Yii::app()->loadLibrary('admin.pclzip');
$zipfile="$tempdir/quexmlpdf_{$qid}_{$surveyprintlang}.zip";
$z = new PclZip($zipfile);
$z->create($zipdir, PCLZIP_OPT_REMOVE_PATH, $zipdir);

unlink($f1);
unlink($f2);
unlink($f3);
unlink($f4);
rmdir($zipdir);

$fn = "quexmlpdf_{$qid}_{$surveyprintlang}.zip";
$this->_addHeaders($fn, "application/zip", 0);
header('Content-Transfer-Encoding: binary');

// load the file to send:
readfile($zipfile);
unlink($zipfile);
}

public function resources()
{
switch ( Yii::app()->request->getParam('export') )
Expand Down Expand Up @@ -1058,19 +987,16 @@ private function _surveyexport($action, $iSurveyID)
$this->_exportarchive($iSurveyID);
}
}

/**
* Generate a queXML PDF document with provided styles/settings
* Return a list of queXML settings
*
* @access public
* @param int $iSurveyID
* @return void
*/
public function quexml($iSurveyID)
* @access private
* @return array queXML settings
*/
private function _quexmlsettings()
{
$iSurveyID = (int) $iSurveyID;

$queXMLSettings = array('queXMLBackgroundColourQuestion',
return array('queXMLBackgroundColourQuestion',
'queXMLPageFormat',
'queXMLPageOrientation',
'queXMLEdgeDetectionFormat',
Expand All @@ -1087,7 +1013,37 @@ public function quexml($iSurveyID)
'queXMLAllowSplittingMatrixText',
'queXMLAllowSplittingSingleChoiceVertical',
'queXMLAllowSplittingSingleChoiceHorizontal');
}

/**
* Clear queXML settings from settings table
*
* @access public
* @param int $iSurveyID
* @return void
*/
public function quexmlclear($iSurveyID)
{
$queXMLSettings = $this->_quexmlsettings();
foreach ($queXMLSettings as $s)
{
setGlobalSetting($s,'');
}
$this->getController()->redirect($this->getController()->createUrl("/admin/export/quexml/surveyid/{$iSurveyID}"));
}

/**
* Generate a queXML PDF document with provided styles/settings
*
* @access public
* @param int $iSurveyID
* @return void
*/
public function quexml($iSurveyID)
{
$iSurveyID = (int) $iSurveyID;

$queXMLSettings = $this->_quexmlsettings();
$aData = array();
$aData['surveyid'] = $iSurveyID;
$aData['slangs'] = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
Expand Down
3 changes: 3 additions & 0 deletions application/views/admin/survey/queXMLSurvey_view.php
Expand Up @@ -182,5 +182,8 @@

<input type='hidden' name='ok' value='Y' />
<input type='submit' value="<?php eT("queXML PDF export"); ?>" />
</form>
<?php echo CHtml::form(array("admin/export/sa/quexmlclear/surveyid/{$surveyid}/"), 'post', array('class'=>'form44'));
echo CHtml::htmlButton(gT('Reset to default settings'),array('type'=>'submit'));?>
</form>
</div><br />&nbsp;

0 comments on commit cad4901

Please sign in to comment.