Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into cond
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Oct 7, 2016
2 parents 54d441a + fb4add0 commit 44e4627
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 89 deletions.
16 changes: 11 additions & 5 deletions application/controllers/admin/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,15 @@ protected function checkPermission()
* @param bool $showLoader If true, show spinning loader instead of messages (fetch them using ajax)
* @return string HTML
*/
public static function getMenuWidget($surveyId = null, $showLoader = false) {
public static function getMenuWidget($surveyId = null, $showLoader = false)
{
// Make sure database version is high enough.
// This is needed since admin bar is loaded during
// database update procedure.
if (Yii::app()->getConfig('DBVersion') < 259) {
return '';
}

$data = array();
$data['surveyId'] = $surveyId;
$data['showLoader'] = $showLoader;
Expand All @@ -131,14 +139,12 @@ public static function getMenuWidget($surveyId = null, $showLoader = false) {
$data['bellColor'] = $data['nrOfNewNotifications'] == 0 ? 'text-success' : 'text-warning';

// If we have any important notification we might as well load everything
if ($data['nrOfImportantNotifications'] > 0)
{
if ($data['nrOfImportantNotifications'] > 0) {
$data['showLoader'] = false;
}

// Only load all messages when we're not showing spinning loader
if (!$data['showLoader'])
{
if (!$data['showLoader']) {
$data['notifications'] = Notification::getNotifications($surveyId);
}

Expand Down
8 changes: 4 additions & 4 deletions application/controllers/admin/databaseupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public function db($continue = null)

$aData['updatedbaction'] = true;

// TODO: Add admin theme, WITHOUT call _renderWrappedTemplate. We don't want to
// do any database queries when updating the database.
$aData = array_merge($aData, $aViewUrls);
Yii::app()->getController()->renderPartial('databaseupdate/db', $aData);
$this->_renderWrappedTemplate('update', $aViewUrls, $aData);

//$aData = array_merge($aData, $aViewUrls);
//Yii::app()->getController()->renderPartial('databaseupdate/db', $aData);
}
}
25 changes: 20 additions & 5 deletions application/controllers/admin/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,22 @@ public function exportspss()
$data['surveyid'] = $iSurveyID;
$data['display']['menu_bars']['browse'] = gT('Export results');

$surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
$oSurvey = Survey::model()->findByPk($iSurveyID);
$surveyinfo = $oSurvey->surveyinfo;
$data['display']['menu_bars']['browse'] = gT('Browse responses'); // browse is independent of the above
$data["surveyinfo"] = $surveyinfo;
$data['title_bar']['title'] = gT('Browse responses').': '.$surveyinfo['surveyls_title'];
$data['sBaseLanguage'] = $oSurvey->language;

$aLanguages=array();
$aLanguagesCodes=$oSurvey->getAllLanguages();
foreach ($aLanguagesCodes as $sLanguage){
$aLanguages[$sLanguage]=getLanguageNameFromCode($sLanguage,false);
}
$data['aLanguages'] = $aLanguages; // Pass available exports

$data['sidemenu']['state'] = false;

$data['menu']['edition'] = true;
$data['menu']['close'] = true;

Expand All @@ -427,8 +437,13 @@ public function exportspss()
}

// Get Base language:
$language = Survey::model()->findByPk($iSurveyID)->language;
App()->setLanguage($language);
$oSurvey = Survey::model()->findByPk($iSurveyID);
$sLanguage = Yii::app()->request->getParam('exportlang');
$aLanguagesCodes=$oSurvey->getAllLanguages();
if (!in_array($sLanguage,$aLanguagesCodes)){
$sLanguage = $oSurvey->language;
}
App()->setLanguage($sLanguage);

Yii::app()->loadHelper("admin/exportresults");
viewHelper::disableHtmlLogging();
Expand All @@ -446,7 +461,7 @@ public function exportspss()
}

$sNoAnswerValue = (isset($_POST['noanswervalue']) && $_POST['noanswervalue'] != '' )?'\''.$_POST['noanswervalue'].'\'':'';
SPSSExportData($iSurveyID, $iLength, $sNoAnswerValue);
SPSSExportData($iSurveyID, $iLength, $sNoAnswerValue, $sLanguage);

exit;
}
Expand All @@ -459,7 +474,7 @@ public function exportspss()
header("Pragma: public");

// Build array that has to be returned
$fields = SPSSFieldMap($iSurveyID);
$fields = SPSSFieldMap($iSurveyID, 'V', $sLanguage);

//Now get the query string with all fields to export
$query = SPSSGetQuery($iSurveyID, 500, 0); // Sample first 500 responses for adjusting fieldmap
Expand Down
14 changes: 5 additions & 9 deletions application/helpers/SurveyRuntimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,6 @@ function run($surveyid,$args)
// TMSW - could iterate through LEM::currentQset instead

//// To diplay one question, all the questions are processed ?
$qanda=array();
foreach ($_SESSION[$LEMsessid]['fieldarray'] as $key => $ia)
{
++$qnumber;
Expand Down Expand Up @@ -1330,14 +1329,11 @@ function run($surveyid,$args)
echo templatereplace($question_template, $aQuestionReplacement, $redata, false, false, $qa[4]);

}
if (!empty($qanda))
{
if ($surveyMode == 'group') {
echo "<input type='hidden' name='lastgroup' value='$lastgroup' id='lastgroup' />\n"; // for counting the time spent on each group
}
if ($surveyMode == 'question') {
echo "<input type='hidden' name='lastanswer' value='$lastanswer' id='lastanswer' />\n";
}
if ($surveyMode == 'group') {
echo "<input type='hidden' name='lastgroup' value='$lastgroup' id='lastgroup' />\n"; // for counting the time spent on each group
}
if ($surveyMode == 'question') {
echo "<input type='hidden' name='lastanswer' value='$lastanswer' id='lastanswer' />\n";
}

echo "\n\n<!-- END THE GROUP -->\n";
Expand Down
66 changes: 32 additions & 34 deletions application/helpers/export_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ function strSplitUnicode($str, $l = 0) {
* @param sep Quote separator. Use '\'' for SPSS, '"' for R
* @param logical $header If TRUE, adds SQGA code as column headings (used by export to R)
*/
function SPSSExportData ($iSurveyID, $iLength, $na = '', $q='\'', $header=FALSE) {
function SPSSExportData ($iSurveyID, $iLength, $na = '', $q='\'', $header=FALSE, $sLanguage='') {

// Build array that has to be returned
$fields = SPSSFieldMap($iSurveyID);
$fields = SPSSFieldMap($iSurveyID, 'V', $sLanguage);

// Now see if we have parameters for from (offset) & num (limit)
$limit = App()->getRequest()->getParam('limit');
Expand Down Expand Up @@ -326,7 +326,7 @@ function SPSSGetValues ($field = array(), $qidattributes = null, $language ) {
* @param $prefix string prefix for the variable ID
* @return array
*/
function SPSSFieldMap($iSurveyID, $prefix = 'V')
function SPSSFieldMap($iSurveyID, $prefix = 'V', $sLanguage='')
{
$typeMap = array(
'5'=>Array('name'=>'5 Point Choice','size'=>1,'SPSStype'=>'F','Scale'=>3),
Expand Down Expand Up @@ -362,28 +362,26 @@ function SPSSFieldMap($iSurveyID, $prefix = 'V')
'*'=>Array('name'=>'Equation','size'=>1,'SPSStype'=>'A'),
);

$fieldmap = createFieldMap($iSurveyID,'full',false,false,getBaseLanguageFromSurveyID($iSurveyID));
if (empty($sLanguage)){
$sLanguage=getBaseLanguageFromSurveyID($iSurveyID);
}
$fieldmap = createFieldMap($iSurveyID,'full',false,false,$sLanguage);

#See if tokens are being used
$bTokenTableExists = tableExists('tokens_'.$iSurveyID);
// ... and if the survey uses anonymized responses
$sSurveyAnonymized=Survey::model()->findByPk($iSurveyID)->anonymized;

#Lookup the names of the attributes
$query="SELECT sid, anonymized, language FROM {{surveys}} WHERE sid=$iSurveyID";
$aRow=Yii::app()->db->createCommand($query)->queryRow(); //Checked
$surveyprivate=$aRow['anonymized'];
$language=$aRow['language'];

$fieldno=0;

$iFieldNumber=0;
$fields=array();
if ($bTokenTableExists && $surveyprivate == 'N' && Permission::model()->hasSurveyPermission($iSurveyID,'tokens','read')) {
if ($bTokenTableExists && $sSurveyAnonymized == 'N' && Permission::model()->hasSurveyPermission($iSurveyID,'tokens','read')) {
$tokenattributes=getTokenFieldsAndNames($iSurveyID,false);
foreach ($tokenattributes as $attributefield=>$attributedescription)
{
//Drop the token field, since it is in the survey too
if($attributefield!='token') {
$fieldno++;
$fields[] = array('id'=>"$prefix$fieldno",'name'=>mb_substr($attributefield, 0, 8),
$iFieldNumber++;
$fields[] = array('id'=>"{$prefix}{$iFieldNumber}",'name'=>mb_substr($attributefield, 0, 8),
'qid'=>0,'code'=>'','SPSStype'=>'A','LStype'=>'Undef',
'VariableLabel'=>$attributedescription['description'],'sql_name'=>$attributefield,'size'=>'100',
'title'=>$attributefield,'hide'=>0, 'scale'=>'');
Expand Down Expand Up @@ -480,15 +478,15 @@ function SPSSFieldMap($iSurveyID, $prefix = 'V')
}

}
$fieldno++;
$fid = $fieldno - $diff;
$iFieldNumber++;
$fid = $iFieldNumber - $diff;
$lsLong = isset($typeMap[$ftype]["name"])?$typeMap[$ftype]["name"]:$ftype;
$tempArray = array('id'=>"$prefix$fid",'name'=>mb_substr($fieldname, 0, 8),
'qid'=>$qid,'code'=>$code,'SPSStype'=>$fieldtype,'LStype'=>$ftype,"LSlong"=>$lsLong,
'ValueLabels'=>'','VariableLabel'=>$varlabel,"sql_name"=>$fieldname,"size"=>$val_size,
'title'=>$ftitle,'hide'=>$hide,'scale'=>$export_scale, 'scale_id'=>$scale_id);
//Now check if we have to retrieve value labels
$answers = SPSSGetValues($tempArray, $aQuestionAttribs, $language);
$answers = SPSSGetValues($tempArray, $aQuestionAttribs, $sLanguage);
if (is_array($answers)) {
//Ok we have answers
if (isset($answers['size'])) {
Expand Down Expand Up @@ -1274,23 +1272,23 @@ function quexml_export($surveyi, $quexmllan)
$question->appendChild($directive);
}

if (Yii::app()->getConfig('quexmlshowprintablehelp')==true)
{
if (Yii::app()->getConfig('quexmlshowprintablehelp')==true)
{

$RowQ['printable_help']=quexml_get_lengthth($qid,"printable_help","", $quexmllang);
$RowQ['printable_help']=quexml_get_lengthth($qid,"printable_help","", $quexmllang);

if (!empty($RowQ['printable_help']))
{
$directive = $dom->createElement("directive");
$position = $dom->createElement("position","before");
$text = $dom->createElement("text", '['.gT('Only answer the following question if:')." ".QueXMLCleanup($RowQ['printable_help'])."]");
$administration = $dom->createElement("administration","self");
$directive->appendChild($position);
$directive->appendChild($text);
$directive->appendChild($administration);
$question->appendChild($directive);
}
}
if (!empty($RowQ['printable_help']))
{
$directive = $dom->createElement("directive");
$position = $dom->createElement("position","before");
$text = $dom->createElement("text", '['.gT('Only answer the following question if:')." ".QueXMLCleanup($RowQ['printable_help'])."]");
$administration = $dom->createElement("administration","self");
$directive->appendChild($position);
$directive->appendChild($text);
$directive->appendChild($administration);
$question->appendChild($directive);
}
}

$response = $dom->createElement("response");
$sgq = $RowQ['title'];
Expand Down Expand Up @@ -1820,7 +1818,7 @@ function tokensExport($iSurveyID)

if (Yii::app()->request->getPost('tokendeleteexported') && !empty($aExportedTokens))
{
Token::model($iSurveyID)->deleteByPk($aExportedTokens);
Token::model($iSurveyID)->deleteByPk($aExportedTokens);
}
}

Expand Down
1 change: 1 addition & 0 deletions application/helpers/frontend_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ function submittokens($quotaexit=false)

// check how many uses the token has left
$token = Token::model($surveyid)->findByAttributes(array('token' => $clienttoken));
$token->scenario = 'FinalSubmit'; // Do not XSS filter token data

if ($quotaexit==true)
{
Expand Down
41 changes: 12 additions & 29 deletions application/helpers/update/update_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ function CheckForDBUpgrades($subaction = null)
}
else
{
$data = "<p><a href='".Yii::app()->getController()->createUrl("/admin/databaseupdate/sa/db")."'>".gT("Please fix this error in your database and try again")."</a></p></div>";
$msg = '';
foreach(yii::app()->user->getflashes() as $key => $message)
{
$msg .= '<div class="alert alert-danger flash-' . $key . '">' . $message . "</div>\n";
}
$data = $msg . "<p><a href='".Yii::app()->getController()->createUrl("/admin/databaseupdate/sa/db")."'>".gT("Please fix this error in your database and try again")."</a></p></div> ";
}
return $data;
}
Expand All @@ -54,34 +59,12 @@ function CheckForDBUpgrades($subaction = null)
}
}

function ShowDBUpgradeNotice() {
$message ='
<div class="jumbotron message-box">
<h2 class="">'.gT('Database upgrade').'</h2>
<p class="lead">'.gT('Please verify the following information before continuing with the database upgrade:').'</p>
<div class="row">
<div class="col-md-offset-4 col-md-4">
<table class="table table-striped">
<tr><th>'.gT('Database type:') . '</th><td>' . Yii::app()->db->getDriverName() . '</td></tr>
<tr><th>'.gT('Database name:') . '</th><td>' . getDBConnectionStringProperty('dbname') . '</td></tr>
<tr><th>'.gT('Table prefix:') . '</th><td>' . Yii::app()->db->tablePrefix . '</td></tr>
<tr><th>'.gT('Site name:') . '</th><td>' . Yii::app()->getConfig("sitename") . '</td></tr>
<tr><th>'.gT('Root URL:') . '</th><td>' . Yii::app()->getController()->createUrl('') . '</td></tr>
<tr><th>'.gT('Current database version:') . '</th><td>' . GetGlobalSetting('DBVersion') . '</td></tr>
<tr><th>'.gT('Target database version:') . '</th><td>' . Yii::app()->getConfig('dbversionnumber'). '</td></tr>
</table>
</div>
</div>
<p>
<a class="btn btn-lg btn-success" href="'.Yii::app()->getController()->createUrl("admin/databaseupdate/sa/db/continue/yes").'" role="button">
'. gT('Click here to continue') .'
</a>
</p>
</div>
';

/**
* @return string html
*/
function ShowDBUpgradeNotice()
{
$message = Yii::app()->getController()->renderPartial('/admin/databaseupdate/verify', null, true);
return $message;
}

Expand Down
2 changes: 1 addition & 1 deletion application/models/InstallerConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function rules()
array('dbpwd, dbprefix', 'safe', 'on' => 'database'),
array('dbtype', 'in', 'range' => array_keys($this->supported_db_types), 'on' => 'database'),
//Optional
array('adminLoginName, adminLoginPwd, confirmPwd', 'required', 'on' => 'optional', 'message' => gT('Either admin login name or password is empty')),
array('adminLoginName, adminLoginPwd, confirmPwd, adminEmail', 'required', 'on' => 'optional', 'message' => gT('Either admin login name, password or email is empty')),
array('adminLoginName, adminName, siteName, confirmPwd', 'safe', 'on' => 'optional'),
array('adminEmail', 'email', 'on' => 'optional'),
array('surveylang', 'in', 'range' => array_keys(getLanguageData(true, Yii::app()->session['installerLang'])), 'on' => 'optional'),
Expand Down
2 changes: 1 addition & 1 deletion application/models/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function rules()
);
foreach (decodeTokenAttributes($this->survey->attributedescriptions) as $key => $info)
{
$aRules[]=array($key,'LSYii_Validators');
$aRules[]=array($key,'LSYii_Validators','except'=>'FinalSubmit');
}
return $aRules;
}
Expand Down
24 changes: 24 additions & 0 deletions application/views/admin/databaseupdate/verify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="jumbotron message-box">
<h2 class=""><?php eT('Database upgrade'); ?></h2>
<p class="lead"><?php eT('Please verify the following information before continuing with the database upgrade:'); ?></p>
<div class="row">
<div class="col-md-offset-4 col-md-4">
<table class="table table-striped">
<tr><th><?php eT('Database type:'); ?></th><td><?php echo Yii::app()->db->getDriverName(); ?></td></tr>
<tr><th><?php eT('Database name:'); ?></th><td><?php echo getDBConnectionStringProperty('dbname'); ?></td></tr>
<tr><th><?php eT('Table prefix:'); ?></th><td><?php echo Yii::app()->db->tablePrefix; ?></td></tr>
<tr><th><?php eT('Site name:'); ?></th><td><?php echo Yii::app()->getConfig("sitename"); ?></td></tr>
<tr><th><?php eT('Root URL:'); ?></th><td><?php echo Yii::app()->getController()->createUrl('/'); ?></td></tr>
<tr><th><?php eT('Current database version:'); ?></th><td><?php echo GetGlobalSetting('DBVersion'); ?></td></tr>
<tr><th><?php eT('Target database version:'); ?></th><td><?php echo Yii::app()->getConfig('dbversionnumber'); ?></td></tr>
</table>
</div>
</div>

<p>
<a class="btn btn-lg btn-success" href="<?php echo Yii::app()->getController()->createUrl("admin/databaseupdate/sa/db/continue/yes"); ?>" role="button">
<?php eT('Click here to continue'); ?>
</a>
</p>

</div>
13 changes: 13 additions & 0 deletions application/views/admin/export/spss_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
));?>
</div>
</div>
<?php
if (count($aLanguages)>1)
{ ?>
<div class="form-group row">
<label for='exportlang' class='col-sm-2 form-control-label'><?php eT("Language:");?></label>
<div class="col-sm-2">
<?php echo CHtml::dropDownList('exportlang', $sBaseLanguage, $aLanguages, array('class'=>'form-control')); ?>
</div>
</div>
<?php } else { ?>
<?php echo CHtml::hiddenField('exportlang', $sBaseLanguage); ?>

<?php } ?>
<div class="form-group row">
<label for='limit' class='col-sm-2 form-control-label'><?php eT("Limit:");?></label>
<div class="col-sm-1">
Expand Down
2 changes: 1 addition & 1 deletion application/views/installer/optconfig_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="col-md-9">
<h2><?php echo $title; ?></h2>
<legend><?php echo $descp; ?></legend>
<?php if (isset($confirmation)) echo sprintf("<div class='alert alert-success'>%s</div>",$confirmation); ?>
<?php if (isset($confirmation)) echo "<div class='alert alert-success'>".$confirmation."</div>"; ?>
<div style="color:red; font-size:12px;">
<?php echo CHtml::errorSummary($model, null, null, array('class' => 'alert alert-danger')); ?>
</div>
Expand Down

0 comments on commit 44e4627

Please sign in to comment.