Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:LimeSurvey/LimeSurvey into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Jul 22, 2015
2 parents 6794219 + 14152bb commit 7ee3faa
Show file tree
Hide file tree
Showing 7 changed files with 898 additions and 120 deletions.
226 changes: 155 additions & 71 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 @@ -1059,6 +988,161 @@ private function _surveyexport($action, $iSurveyID)
}
}

/**
* Return a list of queXML settings
*
* @access private
* @return array queXML settings
*/
private function _quexmlsettings()
{
return array('queXMLBackgroundColourQuestion',
'queXMLPageFormat',
'queXMLPageOrientation',
'queXMLEdgeDetectionFormat',
'queXMLBackgroundColourSection',
'queXMLSectionHeight',
'queXMLResponseLabelFontSize',
'queXMLResponseLabelFontSizeSmall',
'queXMLResponseTextFontSize',
'queXMLQuestionnaireInfoMargin',
'queXMLSingleResponseHorizontalHeight',
'queXMLSingleResponseAreaHeight',
'queXMLStyle',
'queXMLAllowSplittingVas',
'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;
$aData['baselang'] = Survey::model()->findByPk($iSurveyID)->language;
array_unshift($aData['slangs'],$aData['baselang']);

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

foreach ($queXMLSettings as $s)
{
$aData[$s] = getGlobalSetting($s);

if ($aData[$s] === NULL || trim($aData[$s]) === '')
{
$method = str_replace("queXML","get",$s);
$aData[$s] = $defaultquexmlpdf->$method();
}
}

if (empty($_POST['ok']))
{
$this->_renderWrappedTemplate('survey','queXMLSurvey_view',$aData);
} else
{
$quexmlpdf = new quexmlpdf($this->getController());

//Save settings globally and generate queXML document
foreach ($queXMLSettings as $s)
{
if($s!== 'queXMLStyle'){
setGlobalSetting($s,Yii::app()->request->getPost($s));
}

$method = str_replace("queXML","set",$s);



$quexmlpdf->$method(Yii::app()->request->getPost($s));
}


$lang = Yii::app()->request->getPost('save_language');
$tempdir = Yii::app()->getConfig("tempdir");

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

$quexmlpdf->setLanguage($lang);

set_time_limit(120);

Yii::app()->loadHelper('export');


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

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

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

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

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

file_put_contents($f5,$quexmlpdf->exportStyleXML());
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}_{$lang}.zip";
$z = new PclZip($zipfile);
$z->create($zipdir,PCLZIP_OPT_REMOVE_PATH,$zipdir);

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

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

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

/**
* Generate an TSV (tab-separated value) file for the survey structure
* @param type $surveyid
Expand Down
105 changes: 95 additions & 10 deletions application/helpers/expressions/em_core_helper.php
Expand Up @@ -213,17 +213,17 @@ function __construct()
'strcasecmp' => array('strcasecmp', 'strcasecmp', gT('Binary safe case-insensitive string comparison'), 'int strcasecmp(str1, str2)', 'http://www.php.net/manual/en/function.strcasecmp.php', 2),
'strcmp' => array('strcmp', 'strcmp', gT('Binary safe string comparison'), 'int strcmp(str1, str2)', 'http://www.php.net/manual/en/function.strcmp.php', 2),
'strip_tags' => array('strip_tags', 'strip_tags', gT('Strip HTML and PHP tags from a string'), 'string strip_tags(str, allowable_tags)', 'http://www.php.net/manual/en/function.strip-tags.php', 1,2),
'stripos' => array('stripos', 'stripos', gT('Find position of first occurrence of a case-insensitive string'), 'int stripos(haystack, needle [, offset=0])', 'http://www.php.net/manual/en/function.stripos.php', 2,3),
'stripos' => array('exprmgr_stripos', 'stripos', gT('Find position of first occurrence of a case-insensitive string'), 'int stripos(haystack, needle [, offset=0])', 'http://www.php.net/manual/en/function.stripos.php', 2,3),
'stripslashes' => array('stripslashes', 'stripslashes', gT('Un-quotes a quoted string'), 'string stripslashes(string)', 'http://www.php.net/manual/en/function.stripslashes.php', 1),
'stristr' => array('stristr', 'stristr', gT('Case-insensitive strstr'), 'string stristr(haystack, needle [, before_needle=false])', 'http://www.php.net/manual/en/function.stristr.php', 2,3),
'strlen' => array('strlen', 'LEMstrlen', gT('Get string length'), 'int strlen(string)', 'http://www.php.net/manual/en/function.strlen.php', 1),
'strpos' => array('strpos', 'LEMstrpos', gT('Find position of first occurrence of a string'), 'int strpos(haystack, needle [ offset=0])', 'http://www.php.net/manual/en/function.strpos.php', 2,3),
'stristr' => array('exprmgr_stristr', 'stristr', gT('Case-insensitive strstr'), 'string stristr(haystack, needle [, before_needle=false])', 'http://www.php.net/manual/en/function.stristr.php', 2,3),
'strlen' => array('exprmgr_strlen', 'LEMstrlen', gT('Get string length'), 'int strlen(string)', 'http://www.php.net/manual/en/function.strlen.php', 1),
'strpos' => array('exprmgr_strpos', 'LEMstrpos', gT('Find position of first occurrence of a string'), 'int strpos(haystack, needle [ offset=0])', 'http://www.php.net/manual/en/function.strpos.php', 2,3),
'strrev' => array('strrev', 'strrev', gT('Reverse a string'), 'string strrev(string)', 'http://www.php.net/manual/en/function.strrev.php', 1),
'strstr' => array('strstr', 'strstr', gT('Find first occurrence of a string'), 'string strstr(haystack, needle)', 'http://www.php.net/manual/en/function.strstr.php', 2),
'strtolower' => array('strtolower', 'LEMstrtolower', gT('Make a string lowercase'), 'string strtolower(string)', 'http://www.php.net/manual/en/function.strtolower.php', 1),
'strstr' => array('exprmgr_strstr', 'strstr', gT('Find first occurrence of a string'), 'string strstr(haystack, needle [, before_needle=false])', 'http://www.php.net/manual/en/function.strstr.php', 2,3),
'strtolower' => array('exprmgr_strtolower', 'LEMstrtolower', gT('Make a string lowercase'), 'string strtolower(string)', 'http://www.php.net/manual/en/function.strtolower.php', 1),
'strtotime' => array('strtotime', 'strtotime', gT('Convert a date/time string to unix timestamp'), 'int strtotime(string)', 'http://www.php.net/manual/de/function.strtotime.php', 1),
'strtoupper' => array('strtoupper', 'LEMstrtoupper', gT('Make a string uppercase'), 'string strtoupper(string)', 'http://www.php.net/manual/en/function.strtoupper.php', 1),
'substr' => array('substr', 'substr', gT('Return part of a string'), 'string substr(string, start [, length])', 'http://www.php.net/manual/en/function.substr.php', 2,3),
'strtoupper' => array('exprmgr_strtoupper', 'LEMstrtoupper', gT('Make a string uppercase'), 'string strtoupper(string)', 'http://www.php.net/manual/en/function.strtoupper.php', 1),
'substr' => array('exprmgr_substr', 'substr', gT('Return part of a string'), 'string substr(string, start [, length])', 'http://www.php.net/manual/en/function.substr.php', 2,3),
'sum' => array('array_sum', 'LEMsum', gT('Calculate the sum of values in an array'), 'number sum(arg1, arg2, ... argN)', '', -2),
'sumifop' => array('exprmgr_sumifop', 'LEMsumifop', gT('Sum the values of answered questions in the list which pass the critiera (arg op value)'), 'number sumifop(op, value, arg1, arg2, ... argN)', '', -3),
'tan' => array('tan', 'Math.tan', gT('Tangent'), 'number tan(arg)', 'http://www.php.net/manual/en/function.tan.php', 1),
Expand Down Expand Up @@ -2538,7 +2538,92 @@ function exprmgr_countifop($args)
}
return $j;
}

/**
* Find position of first occurrence of unicode string in a unicode string, case insensitive
* @param string $haystack : checked string
* @param string $needle : string to find
* @param $offset : offset
* @return int|false : position or false if not found
*/
function exprmgr_stripos($haystack , $needle ,$offset=0)
{
if($offset > mb_strlen($haystack))
return false;
return mb_stripos($haystack , $needle ,$offset,'UTF-8');
}
/**
* Finds first occurrence of a unicode string within another, case-insensitive
* @param string $haystack : checked string
* @param string $needle : string to find
* @param boolean $before_needle : portion to return
* @return string|false
*/
function exprmgr_stristr($haystack,$needle,$before_needle=false)
{
return mb_stristr($haystack,$needle,$before_needle,'UTF-8');
}
/**
* Get unicode string length
* @param string $string
* @return int
*/
function exprmgr_strlen($string)
{
return mb_strlen ($string,'UTF-8');
}
/**
* Find position of first occurrence of unicode string in a unicode string
* @param string $haystack : checked string
* @param string $needle : string to find
* @param $offset : offset
* @return int|false : position or false if not found
*/
function exprmgr_strpos($haystack , $needle ,$offset=0)
{
if($offset > mb_strlen($haystack))
return false;
return mb_strpos($haystack , $needle ,$offset,'UTF-8');
}
/**
* Finds first occurrence of a unicode string within another
* @param string $haystack : checked string
* @param string $needle : string to find
* @param boolean $before_needle : portion to return
* @return string|false
*/
function exprmgr_strstr($haystack,$needle,$before_needle=false)
{
return mb_strstr($haystack,$needle,$before_needle,'UTF-8');
}
/**
* Make an unicode string lowercase
* @param string $string
* @return string
*/
function exprmgr_strtolower($string)
{
return mb_strtolower ($string,'UTF-8');
}
/**
* Make an unicode string uppercase
* @param string $string
* @return string
*/
function exprmgr_strtoupper($string)
{
return mb_strtoupper ($string,'UTF-8');
}
/**
* Get part of unicode string
* @param string $string
* @param int $start
* @param int $end
* @return string
*/
function exprmgr_substr($string,$start,$end=null)
{
return mb_substr($string,$start,$end,'UTF-8');
}
/**
* Sum of values of answered questions which meet the criteria (arg op value)
* @param <type> $args
Expand Down Expand Up @@ -2818,10 +2903,10 @@ function exprmgr_fixnum($value)
}
return $value;
}

/**
* Returns true if all non-empty values are unique
* @param type $args
* @return boolean
*/
function exprmgr_unique($args)
{
Expand Down
8 changes: 7 additions & 1 deletion application/helpers/surveytranslator_helper.php
Expand Up @@ -660,7 +660,13 @@ function getLanguageData($bOrderByNative=false,$sLanguageCode='en') {
$supportedLanguages['th']['rtl'] = false;
$supportedLanguages['th']['dateformat'] = 5;
$supportedLanguages['th']['radixpoint'] = 0;


//Ukrainian
$supportedLanguages['uk']['description'] = gT('Ukrainian');
$supportedLanguages['uk']['nativedescription'] = 'ukrayins&#x2B9;kyy';
$supportedLanguages['uk']['rtl'] = false;
$supportedLanguages['uk']['dateformat'] = 1;
$supportedLanguages['uk']['radixpoint'] = 1;

//Urdu
$supportedLanguages['ur']['description'] = gT('Urdu');
Expand Down

0 comments on commit 7ee3faa

Please sign in to comment.