Skip to content

Commit

Permalink
Merge branch '2.06' of github.com:LimeSurvey/LimeSurvey into 2.06temp
Browse files Browse the repository at this point in the history
Conflicts:
	application/core/db/SmartColumnTypeTrait.php
  • Loading branch information
SamMousa committed Jan 13, 2015
2 parents c7eb2c3 + 1db7223 commit feedf7e
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 185 deletions.
4 changes: 2 additions & 2 deletions application/controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ public function getTokenId($iSurveyId)

$aFieldValue=$this->getFieldValue($iSurveyId);
// Now construct the text returned
$oToken=Token::model($iSurveyId)->findByAttributes([
$oToken=Token::model($iSurveyId)->findByAttributes(array(
'email' => $aFieldValue['sEmail']
]);
));
if ($oToken)
{
if($oToken->usesleft<1 && $aSurveyInfo['alloweditaftercompletion']!='Y')
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/assessments.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private function _collectGroupData($iSurveyID)
private function _collectEditData(array $aData)
{
$assessments = Assessment::model()->findAllByAttributes(array(
'id' => sanitize_int($_POST['id'])
'id' => sanitize_int($_POST['id']),
'language' => App()->language
));

Expand Down
64 changes: 4 additions & 60 deletions application/controllers/admin/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1049,66 +1049,10 @@ function index($sa = null)
$param->save();
}
}
$updatearray= array('admin'=> Yii::app()->request->getPost('admin'),
'expires'=>$expires,
'startdate'=>$startdate,
'anonymized'=> Yii::app()->request->getPost('anonymized'),
'faxto'=> Yii::app()->request->getPost('faxto'),
'format'=> Yii::app()->request->getPost('format'),
'savetimings'=> Yii::app()->request->getPost('savetimings'),
'template'=>$template,
'assessments'=> Yii::app()->request->getPost('assessments'),
'language'=> Yii::app()->request->getPost('language'),
'additional_languages'=> Yii::app()->request->getPost('languageids'),
'datestamp'=> Yii::app()->request->getPost('datestamp'),
'ipaddr'=> Yii::app()->request->getPost('ipaddr'),
'refurl'=> Yii::app()->request->getPost('refurl'),
'publicgraphs'=> Yii::app()->request->getPost('publicgraphs'),
'usecookie'=> Yii::app()->request->getPost('usecookie'),
'allowregister'=> Yii::app()->request->getPost('allowregister'),
'allowsave'=> Yii::app()->request->getPost('allowsave'),
'navigationdelay'=> Yii::app()->request->getPost('navigationdelay'),
'printanswers'=> Yii::app()->request->getPost('printanswers'),
'publicstatistics'=> Yii::app()->request->getPost('publicstatistics'),
'autoredirect'=> Yii::app()->request->getPost('autoredirect'),
'showxquestions'=> Yii::app()->request->getPost('showxquestions'),
'showgroupinfo'=> Yii::app()->request->getPost('showgroupinfo'),
'showqnumcode'=> Yii::app()->request->getPost('showqnumcode'),
'shownoanswer'=> Yii::app()->request->getPost('shownoanswer'),
'showwelcome'=> Yii::app()->request->getPost('showwelcome'),
'allowprev'=> Yii::app()->request->getPost('allowprev'),
'questionindex'=> Yii::app()->request->getPost('questionindex'),
'nokeyboard'=> Yii::app()->request->getPost('nokeyboard'),
'showprogress'=> Yii::app()->request->getPost('showprogress'),
'listpublic'=> Yii::app()->request->getPost('public'),
'htmlemail'=> Yii::app()->request->getPost('htmlemail'),
'sendconfirmation'=> Yii::app()->request->getPost('sendconfirmation'),
'tokenanswerspersistence'=> Yii::app()->request->getPost('tokenanswerspersistence'),
'alloweditaftercompletion'=> Yii::app()->request->getPost('alloweditaftercompletion'),
'usecaptcha'=> Yii::app()->request->getPost('usecaptcha'),
'emailresponseto'=>trim(Yii::app()->request->getPost('emailresponseto')),
'emailnotificationto'=>trim(Yii::app()->request->getPost('emailnotificationto')),
'googleanalyticsapikey'=>trim(Yii::app()->request->getPost('googleanalyticsapikey')),
'googleanalyticsstyle'=>trim(Yii::app()->request->getPost('googleanalyticsstyle')),
'tokenlength'=>$tokenlength
);


$warning = '';
// make sure we only update admin email if it is valid
if (Yii::app()->request->getPost('adminemail', '') == ''
|| validateEmailAddress(Yii::app()->request->getPost('adminemail'))) {
$updatearray['adminemail'] = Yii::app()->request->getPost('adminemail');
} else {
$warning .= gT("Warning! Notification email was not updated because it was not valid.").'<br/>';
}
// make sure we only update bounce email if it is valid
if (Yii::app()->request->getPost('bounce_email', '') == ''
|| validateEmailAddress(Yii::app()->request->getPost('bounce_email'))) {
$updatearray['bounce_email'] = Yii::app()->request->getPost('bounce_email');
} else {
$warning .= gT("Warning! Bounce email was not updated because it was not valid.").'<br/>';
}





// use model

Expand Down
212 changes: 209 additions & 3 deletions application/controllers/admin/surveyadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,11 @@ function fakebrowser()
function editsurveysettings($iSurveyID)
{
$iSurveyID = (int) $iSurveyID;
if (is_null($iSurveyID) || !$iSurveyID)
$this->getController()->error('Invalid survey id');

if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read') && !Permission::model()->hasGlobalPermission('surveys','read'))
$this->getController()->error('No permission');

if(Yii::app()->request->isPostRequest)
$this->update($iSurveyID);
$this->_registerScriptFiles();

//Yii::app()->loadHelper('text');
Expand Down Expand Up @@ -1419,6 +1418,213 @@ private function _registerScriptFiles($files = array())
}
}

/**
* Update survey settings with post value
*
* @param $iSurveyId The survey id
*/
function update($iSurveyId)
{
if(!Yii::app()->request->isPostRequest)
throw new CHttpException(500);
if(!Permission::model()->hasSurveyPermission($iSurveyId,'surveysettings','update'))
throw new CHttpException(401,"401 Unauthorized");

// Preload survey
$oSurvey=Survey::model()->findByPk($iSurveyId);

// Save plugin settings.
$pluginSettings = App()->request->getPost('plugin', array());
foreach($pluginSettings as $plugin => $settings)
{
$settingsEvent = new PluginEvent('newSurveySettings');
$settingsEvent->set('settings', $settings);
$settingsEvent->set('survey', $iSurveyId);
App()->getPluginManager()->dispatchEvent($settingsEvent, $plugin);
}

/* Start to fix some param before save (TODO : use models directly ?) */
/* Date management */
Yii::app()->loadHelper('surveytranslator');
$formatdata=getDateFormatData(Yii::app()->session['dateformat']);
Yii::app()->loadLibrary('Date_Time_Converter');
$startdate = App()->request->getPost('startdate');
if (trim($startdate)=="")
{
$startdate=null;
}
else
{
Yii::app()->loadLibrary('Date_Time_Converter');
$datetimeobj = new date_time_converter($startdate,$formatdata['phpdate'].' H:i'); //new Date_Time_Converter($startdate,$formatdata['phpdate'].' H:i');
$startdate=$datetimeobj->convert("Y-m-d H:i:s");
}
$expires = App()->request->getPost('expires');
if (trim($expires)=="")
{
$expires=null;
}
else
{
$datetimeobj = new date_time_converter($expires, $formatdata['phpdate'].' H:i'); //new Date_Time_Converter($expires, $formatdata['phpdate'].' H:i');
$expires=$datetimeobj->convert("Y-m-d H:i:s");
}
/* Token management */
$tokenlength = (int)App()->request->getPost('tokenlength');
//token length has to be at least 5, otherwise set it to default (15) : model
if($tokenlength < 5)
{
$tokenlength = 15;
}
if($tokenlength > 36)
{
$tokenlength = 36;
}

/* Fix email of admin : not in model ? */
if (Yii::app()->request->getPost('adminemail', '') == '' || validateEmailAddress(trim(Yii::app()->request->getPost('adminemail')))) {
$adminemail = trim(Yii::app()->request->getPost('adminemail'));
} else {
$adminemail= $oSurvey->adminemail;
Yii::app()->setFlashMessage(gT("Warning! Notification email was not updated because it was not valid."),'warning'); gT().'<br/>';
}
if (Yii::app()->request->getPost('bounce_email', '') == '' || validateEmailAddress(trim(Yii::app()->request->getPost('adminemail')))) {
$bounce_email = trim(Yii::app()->request->getPost('bounce_email'));
} else {
$bounce_email = $oSurvey->bounce_email;
Yii::app()->setFlashMessage(gT("Warning! Bounce email was not updated because it was not valid."),'warning'); gT().'<br/>';
}

// Validate template : accepted: user have rigth to read template OR template are not updated : else set to the default from config
$template = Yii::app()->request->getPost('template');
if( $template!=$oSurvey->template && !Permission::model()->hasTemplatePermission($template))
{
$template = Yii::app()->getConfig('defaulttemplate');
}

// We have $oSurvey : update and save it
$oSurvey->admin = Yii::app()->request->getPost('admin');
$oSurvey->expires = $expires;
$oSurvey->startdate = $startdate;
$oSurvey->anonymized = Yii::app()->request->getPost('anonymized');
$oSurvey->faxto = Yii::app()->request->getPost('faxto');
$oSurvey->format = Yii::app()->request->getPost('format');
$oSurvey->savetimings = Yii::app()->request->getPost('savetimings');
$oSurvey->template = $template;
$oSurvey->assessments = Yii::app()->request->getPost('assessments');
$oSurvey->language = Yii::app()->request->getPost('language');
$oSurvey->additional_languages = Yii::app()->request->getPost('languageids');
$oSurvey->datestamp = Yii::app()->request->getPost('datestamp');
$oSurvey->ipaddr = Yii::app()->request->getPost('ipaddr');
$oSurvey->refurl = Yii::app()->request->getPost('refurl');
$oSurvey->publicgraphs = Yii::app()->request->getPost('publicgraphs');
$oSurvey->usecookie = Yii::app()->request->getPost('usecookie');
$oSurvey->allowregister = Yii::app()->request->getPost('allowregister');
$oSurvey->allowsave = Yii::app()->request->getPost('allowsave');
$oSurvey->navigationdelay = Yii::app()->request->getPost('navigationdelay');
$oSurvey->printanswers = Yii::app()->request->getPost('printanswers');
$oSurvey->publicstatistics = Yii::app()->request->getPost('publicstatistics');
$oSurvey->autoredirect = Yii::app()->request->getPost('autoredirect');
$oSurvey->showxquestions = Yii::app()->request->getPost('showxquestions');
$oSurvey->showgroupinfo = Yii::app()->request->getPost('showgroupinfo');
$oSurvey->showqnumcode = Yii::app()->request->getPost('showqnumcode');
$oSurvey->shownoanswer = Yii::app()->request->getPost('shownoanswer');
$oSurvey->showwelcome = Yii::app()->request->getPost('showwelcome');
$oSurvey->allowprev = Yii::app()->request->getPost('allowprev');
$oSurvey->questionindex = Yii::app()->request->getPost('questionindex');
$oSurvey->nokeyboard = Yii::app()->request->getPost('nokeyboard');
$oSurvey->showprogress = Yii::app()->request->getPost('showprogress');
$oSurvey->listpublic = Yii::app()->request->getPost('public');
$oSurvey->htmlemail = Yii::app()->request->getPost('htmlemail');
$oSurvey->sendconfirmation = Yii::app()->request->getPost('sendconfirmation');
$oSurvey->tokenanswerspersistence = Yii::app()->request->getPost('tokenanswerspersistence');
$oSurvey->alloweditaftercompletion = Yii::app()->request->getPost('alloweditaftercompletion');
$oSurvey->usecaptcha = Yii::app()->request->getPost('usecaptcha');
$oSurvey->emailresponseto = trim(Yii::app()->request->getPost('emailresponseto'));
$oSurvey->emailnotificationto = trim(Yii::app()->request->getPost('emailnotificationto'));
$oSurvey->googleanalyticsapikey = trim(Yii::app()->request->getPost('googleanalyticsapikey'));
$oSurvey->googleanalyticsstyle = trim(Yii::app()->request->getPost('googleanalyticsstyle'));
$oSurvey->tokenlength = $tokenlength;
$oSurvey->adminemail = $adminemail;
$oSurvey->bounce_email = $bounce_email;
if ($oSurvey->save())
{
Yii::app()->setFlashMessage(gT("Survey settings were successfully saved."));
}
else
{
Yii::app()->setFlashMessage(gT("Survey could not be updated.","error"));
tracevar($oSurvey->getErrors());
}

/* Reload $oSurvey (language are fixed : need it ?) */
$oSurvey=Survey::model()->findByPk($iSurveyId);

/* Delete removed language cleanLanguagesFromSurvey do it already why redo it (cleanLanguagesFromSurvey must be moved to model) ?*/
$aAvailableLanguage=$oSurvey->getAllLanguages();
$oCriteria = new CDbCriteria;
$oCriteria->compare('surveyls_survey_id',$iSurveyId);
$oCriteria->addNotInCondition('surveyls_language',$aAvailableLanguage);
SurveyLanguageSetting::model()->deleteAll($oCriteria);

/* Add new language fixLanguageConsistency do it ?*/
foreach ($oSurvey->additionalLanguages as $sLang)
{
if ($sLang)
{
$oLanguageSettings = SurveyLanguageSetting::model()->find('surveyls_survey_id=:surveyid AND surveyls_language=:langname', array(':surveyid'=>$iSurveyId,':langname'=>$sLang));
if(!$oLanguageSettings)
{
$oLanguageSettings= new SurveyLanguageSetting;
$languagedetails=getLanguageDetails($sLang);
$oLanguageSettings->surveyls_survey_id = $iSurveyId;
$oLanguageSettings->surveyls_language = $sLang;
$oLanguageSettings->surveyls_title = ''; // Not in default model ?
$oLanguageSettings->surveyls_dateformat = $languagedetails['dateformat'];
if(!$oLanguageSettings->save())
{
Yii::app()->setFlashMessage(gT("Survey language could not be created.","error"));
tracevar($oLanguageSettings->getErrors());
}
}
}
}
/* Language fix : remove and add question/group */
cleanLanguagesFromSurvey($iSurveyId,implode(" ",$oSurvey->additionalLanguages));
fixLanguageConsistency($iSurveyId,implode(" ",$oSurvey->additionalLanguages));

// Url params in json
$aURLParams=json_decode(Yii::app()->request->getPost('allurlparams'),true);
SurveyURLParameter::model()->deleteAllByAttributes(array('sid'=>$iSurveyId));
if(isset($aURLParams))
{
foreach($aURLParams as $aURLParam)
{
$aURLParam['parameter']=trim($aURLParam['parameter']);
if ($aURLParam['parameter']=='' || !preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/',$aURLParam['parameter']) || $aURLParam['parameter']=='sid' || $aURLParam['parameter']=='newtest' || $aURLParam['parameter']=='token' || $aURLParam['parameter']=='lang')
{
continue; // this parameter name seems to be invalid - just ignore it
}
unset($aURLParam['act']);
unset($aURLParam['title']);
unset($aURLParam['id']);
if ($aURLParam['targetqid']=='') $aURLParam['targetqid']=NULL;
if ($aURLParam['targetsqid']=='') $aURLParam['targetsqid']=NULL;
$aURLParam['sid']=$iSurveyId;

$param = new SurveyURLParameter;
foreach ($aURLParam as $k => $v)
$param->$k = $v;
$param->save();
}
}

if (Yii::app()->request->getPost('redirect'))
{
$this->getController()->redirect(Yii::app()->request->getPost('redirect'));
App()->end();
}
}
/**
* Saves the new survey after the creation screen is submitted
*
Expand Down
4 changes: 2 additions & 2 deletions application/core/db/DbConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ class DbConnection extends \CDbConnection
{
public function __construct($dsn = '', $username = '', $password = '') {
parent::__construct($dsn, $username, $password);
$this->driverMap = array_merge($this->driverMap, [
$this->driverMap = array_merge($this->driverMap, array(
'mysql' => 'MysqlSchema',
'mysqli' => 'MysqlSchema',
'mssql' => 'MssqlSchema',
'dblib' => 'MssqlSchema',
'sqlsrv' => 'MssqlSchema',
]);
));
}
}
?>
1 change: 1 addition & 0 deletions application/core/db/MssqlSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function getColumnType($type)
* If resulting type doesn't contain NULL then add it.
*/
$result = parent::getColumnType($type);

if (stripos($result, 'NULL') === false) {
$result .= ' NULL';
}
Expand Down
2 changes: 0 additions & 2 deletions application/core/db/MysqlSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
class MysqlSchema extends CMysqlSchema
{
use SmartColumnTypeTrait;

public function __construct($conn) {
parent::__construct($conn);
/**
Expand All @@ -17,5 +16,4 @@ public function createTable($table, $columns, $options = null) {
$result .= ' ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
return $result;
}

}
2 changes: 2 additions & 0 deletions application/core/db/PgsqlSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
class PgsqlSchema extends CPgsqlSchema
{
use SmartColumnTypeTrait;

public function __construct($conn) {
parent::__construct($conn);
/**
* Auto increment.
*/
$this->columnTypes['autoincrement'] = 'serial';
}

}
9 changes: 8 additions & 1 deletion application/helpers/expressions/em_manager_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5209,7 +5209,14 @@ private function _UpdateValuesInDatabase($updatedValues, $finished=false)
}
if ($this->surveyOptions['refurl'] == true)
{
$sdata['refurl'] = getenv("HTTP_REFERER");
if (isset($_SESSION[$this->sessid]['refurl']))
{
$sdata['refurl'] = $_SESSION[$this->sessid]['refurl'];
}
else
{
$sdata['refurl'] = getenv("HTTP_REFERER");
}
}

$sdata = array_filter($sdata);
Expand Down

0 comments on commit feedf7e

Please sign in to comment.