Skip to content

Commit

Permalink
Dev: saving survey option from editlocalsetting
Browse files Browse the repository at this point in the history
  • Loading branch information
louis committed Sep 22, 2015
1 parent 1c54c20 commit 1f78a2c
Show file tree
Hide file tree
Showing 10 changed files with 507 additions and 272 deletions.
167 changes: 167 additions & 0 deletions application/controllers/admin/database.php
Expand Up @@ -949,6 +949,9 @@ function index($sa = null)
}


/**
* updatesurveylocalesettings
*/
if (($sAction == "updatesurveylocalesettings") && Permission::model()->hasSurveyPermission($iSurveyID,'surveylocale','update'))
{
$languagelist = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
Expand Down Expand Up @@ -995,6 +998,170 @@ function index($sa = null)
}
Yii::app()->session['flashmessage'] = gT("Survey text elements successfully saved.");


////////////////////////////////////////////////////////////////////////////////////
// General settings (copy / paste from surveyadmin::update)

// 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");
}

// We have $oSurvey : update and save it
$oSurvey->admin = Yii::app()->request->getPost('admin');
$oSurvey->expires = $expires;
$oSurvey->startdate = $startdate;
$oSurvey->anonymized = App()->request->getPost('anonymized');
$oSurvey->faxto = App()->request->getPost('faxto');
$oSurvey->format = App()->request->getPost('format');
$oSurvey->savetimings = App()->request->getPost('savetimings');
$oSurvey->template = Yii::app()->request->getPost('template');
$oSurvey->assessments = App()->request->getPost('assessments');
$oSurvey->additional_languages = implode(' ',Yii::app()->request->getPost('additional_languages',array()));
$oSurvey->datestamp = App()->request->getPost('datestamp');
$oSurvey->ipaddr = App()->request->getPost('ipaddr');
$oSurvey->refurl = App()->request->getPost('refurl');
$oSurvey->publicgraphs = App()->request->getPost('publicgraphs');
$oSurvey->usecookie = App()->request->getPost('usecookie');
$oSurvey->allowregister = App()->request->getPost('allowregister');
$oSurvey->allowsave = App()->request->getPost('allowsave');
$oSurvey->navigationdelay = App()->request->getPost('navigationdelay');
$oSurvey->printanswers = App()->request->getPost('printanswers');
$oSurvey->publicstatistics = App()->request->getPost('publicstatistics');
$oSurvey->autoredirect = App()->request->getPost('autoredirect');
$oSurvey->showxquestions = App()->request->getPost('showxquestions');
$oSurvey->showgroupinfo = App()->request->getPost('showgroupinfo');
$oSurvey->showqnumcode = App()->request->getPost('showqnumcode');
$oSurvey->shownoanswer = App()->request->getPost('shownoanswer');
$oSurvey->showwelcome = App()->request->getPost('showwelcome');
$oSurvey->allowprev = App()->request->getPost('allowprev');
$oSurvey->questionindex = App()->request->getPost('questionindex');
$oSurvey->nokeyboard = App()->request->getPost('nokeyboard');
$oSurvey->showprogress = App()->request->getPost('showprogress');
$oSurvey->listpublic = App()->request->getPost('public');
$oSurvey->htmlemail = App()->request->getPost('htmlemail');
$oSurvey->sendconfirmation = App()->request->getPost('sendconfirmation');
$oSurvey->tokenanswerspersistence = App()->request->getPost('tokenanswerspersistence');
$oSurvey->alloweditaftercompletion = App()->request->getPost('alloweditaftercompletion');
$oSurvey->usecaptcha = App()->request->getPost('usecaptcha');
$oSurvey->emailresponseto = App()->request->getPost('emailresponseto');
$oSurvey->emailnotificationto = App()->request->getPost('emailnotificationto');
$oSurvey->googleanalyticsapikey = App()->request->getPost('googleanalyticsapikey');
$oSurvey->googleanalyticsstyle = App()->request->getPost('googleanalyticsstyle');
$oSurvey->tokenlength = App()->request->getPost('tokenlength');
$oSurvey->adminemail = App()->request->getPost('adminemail');
$oSurvey->bounce_email = App()->request->getPost('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 ($sDBOutput != '')
{
echo $sDBOutput;
Expand Down
5 changes: 4 additions & 1 deletion application/controllers/admin/surveyadmin.php
Expand Up @@ -926,6 +926,8 @@ public function editlocalsettings($iSurveyID)

if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read'))
{
$this->_registerScriptFiles();

if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'update'))
{
Yii::app()->session['FileManagerContext'] = "edit:survey:{$iSurveyID}";
Expand Down Expand Up @@ -995,7 +997,8 @@ public function editlocalsettings($iSurveyID)
$surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
$aData['title_bar']['title'] = $surveyinfo['surveyls_title']."(".gT("ID").":".$iSurveyID.")";

$aData['surveybar']['savebutton']['form'] = 'frmeditgroup';
$aData['surveybar']['savebutton']['form'] = 'globalsetting';
$aData['surveybar']['savebutton']['useformid'] = 'true';
$aData['surveybar']['closebutton']['url'] = 'admin/survey/sa/view/surveyid/'.$iSurveyID;

$aViewUrls[] = 'editLocalSettings_main_view';
Expand Down
16 changes: 12 additions & 4 deletions application/views/admin/super/header.php
Expand Up @@ -1275,10 +1275,18 @@
});


$('#save-button').on('click', function(){
$form = $('.side-body').find('form');
//alert($form.attr('id'));
$form.submit();
$('#save-button').on('click', function()
{
if($(this).attr('data-use-form-id')==1)
{
formId = '#'+$(this).attr('data-form-to-save');
$(formId).submit();
}
else
{
$form = $('.side-body').find('form');
$form.submit();
}

});

Expand Down
Expand Up @@ -14,7 +14,6 @@
var sEnterValidParam = "<?php eT('You have to enter a valid parameter name.','js');?>";
var sAddParam = "<?php eT('Add URL parameter','js');?>";
var sEditParam = "<?php eT('Edit URL parameter','js');?>";

</script>

<div id='panelintegration' class="tab-pane fade">
Expand Down
31 changes: 21 additions & 10 deletions application/views/admin/survey/editLocalSettings_main_view.php
@@ -1,25 +1,36 @@
<?php
/**
* General container for edit survey action
*/
?>
<?php
extract($settings_data);
$count = 0;
if(isset($scripts))
echo $scripts;
?>
<?php
$data = array('aTabTitles'=>$aTabTitles, 'aTabContents'=>$aTabContents, 'has_permissions'=>$has_permissions, 'surveyid'=>$surveyid,'surveyls_language'=>$surveyls_language);
$data = array('aTabTitles'=>$aTabTitles, 'aTabContents'=>$aTabContents, 'has_permissions'=>$has_permissions, 'surveyid'=>$surveyid,'surveyls_language'=>$surveyls_language);
?>

<div class="side-body" id="edit-survey-text-element">
<div class="row">
<h3 class="pagetitle"><?php echo gT("Edit survey text elements and settings"); ?></h3>

<!-- Edition container -->
<div class="row" style="margin-bottom: 100px">

<!-- Form -->
<?php echo CHtml::form(array("admin/database/index/updatesurveylocalesettings"), 'post', array('id'=>'globalsetting','name'=>'globalsetting','class'=>'form-horizontal form30')); ?>
<div class="col-lg-8 content-right">
<?php $this->renderPartial('/admin/survey/subview/tab_edit_view',$data); ?>
</div>
<div class="col-lg-4">
<?php $this->renderPartial('/admin/survey/subview/accordion/_accordion_container', array('data'=>$settings_data)); ?>
</div>
</form>

<!-- text edition -->
<div class="col-lg-8 content-right">
<?php $this->renderPartial('/admin/survey/subview/tab_edit_view',$data); ?>
</div>

<!-- settings -->
<div class="col-lg-4">
<?php $this->renderPartial('/admin/survey/subview/accordion/_accordion_container', array('data'=>$settings_data)); ?>
</div>
</form>
</div>
</div>
</div>
33 changes: 25 additions & 8 deletions application/views/admin/survey/editLocalSettings_view.php
@@ -1,11 +1,22 @@
<?
/**
* Edit the survey text elements of a survey for one given language
* It is rendered from editLocalSettings_main_view.
*/
?>

<div id="edittxtele-<?php echo $i;?>" class="tab-pane fade in <?php if($i==0){echo "active";}?> col-lg-6 center-box">

<!-- Survey title -->
<div class="input-group">
<span class="input-group-addon" id="question-group-title"><?php eT("Survey title"); ?></span>
<input class="form-control" type='text' size='80' id='short_title_<?php echo $esrow['surveyls_language']; ?>' name='short_title_<?php echo $esrow['surveyls_language']; ?>' value="<?php echo $esrow['surveyls_title']; ?>" />
</div>

<!-- Description -->
<div class="form-group form-group-lg">
<label class="col-sm-2 control-label" for="description_<?php echo $esrow['surveyls_language']; ?>"><?php eT("Description:"); ?></label>
<br/>
<label class="col-sm-3 for="description_<?php echo $esrow['surveyls_language']; ?>"><?php eT("Description:"); ?></label>
<div class="htmleditorboot">
<textarea cols='80' rows='15' id='description_<?php echo $esrow['surveyls_language']; ?>' name='description_<?php echo $esrow['surveyls_language']; ?>'>
<?php echo $esrow['surveyls_description']; ?>
Expand All @@ -15,8 +26,9 @@

</div>

<!--Welcome message -->
<div class="form-group form-group-lg">
<label class="col-sm-2 control-label" for='welcome_<?php echo $esrow['surveyls_language']; ?>'><?php eT("Welcome message:"); ?></label>
<label class="col-sm-4" for='welcome_<?php echo $esrow['surveyls_language']; ?>'><?php eT("Welcome message:"); ?></label>

<div class="htmleditorboot">
<textarea cols='80' rows='15' id='welcome_<?php echo $esrow['surveyls_language']; ?>' name='welcome_<?php echo $esrow['surveyls_language']; ?>'>
Expand All @@ -26,8 +38,9 @@
</div>
</div>

<!-- End message -->
<div class="form-group form-group-lg">
<label class="col-sm-2 control-label" for='endtext_<?php echo $esrow['surveyls_language']; ?>'><?php eT("End message:"); ?></label>
<label class="col-sm-4" for='endtext_<?php echo $esrow['surveyls_language']; ?>'><?php eT("End message:"); ?></label>

<div class="htmleditorboot">
<textarea cols='80' rows='15' id='endtext_<?php echo $esrow['surveyls_language']; ?>' name='endtext_<?php echo $esrow['surveyls_language']; ?>'>
Expand All @@ -37,21 +50,24 @@
</div>
</div>

<div class="col-lg-6">
<!-- End URL -->
<div class="col-lg-12">
<div class="input-group">
<span class="input-group-addon"><?php eT("End URL:"); ?></span>
<input class="form-control" type='text' size='80' maxlength='2000' id='url_<?php echo $esrow['surveyls_language']; ?>' name='url_<?php echo $esrow['surveyls_language']; ?>' value="<?php echo ($esrow['surveyls_url']!="")?$esrow['surveyls_url']:"http://"; ?>" />
</div>
</div>

<div class="col-lg-6">
<!-- URL description -->
<div class="col-lg-12">
<div class="input-group">
<span class="input-group-addon"><?php eT("URL description:"); ?></span>
<input class="form-control" type='text' id='urldescrip_<?php echo $esrow['surveyls_language']; ?>' size='80' name='urldescrip_<?php echo $esrow['surveyls_language']; ?>' value="<?php echo $esrow['surveyls_urldescription']; ?>" />
</div>
</div>

<div class="col-lg-6">

<!-- Date format -->
<div class="col-lg-12">
<div class="input-group">
<span class="input-group-addon"><?php eT("Date format:"); ?></span>

Expand All @@ -69,7 +85,8 @@
</div>
</div>

<div class="col-lg-6">
<!-- Decimal mark -->
<div class="col-lg-12">
<div class="input-group">
<span class="input-group-addon"><?php eT("Decimal mark:"); ?></span>

Expand Down

0 comments on commit 1f78a2c

Please sign in to comment.