Skip to content

Commit

Permalink
Dev: Use three bootstrap switches instead of one select for captcha s…
Browse files Browse the repository at this point in the history
…ettings
  • Loading branch information
olleharstedt committed Feb 17, 2016
1 parent eedc59b commit e3f9e4b
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 70 deletions.
54 changes: 53 additions & 1 deletion application/controllers/admin/database.php
Expand Up @@ -1217,7 +1217,7 @@ function index($sa = null)
$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->usecaptcha = $this->transcribeCaptchaOptions();
$oSurvey->emailresponseto = App()->request->getPost('emailresponseto');
$oSurvey->emailnotificationto = App()->request->getPost('emailnotificationto');
$oSurvey->googleanalyticsapikey = App()->request->getPost('googleanalyticsapikey');
Expand Down Expand Up @@ -1350,4 +1350,56 @@ function _updateDefaultValues($qid,$sqid,$scale_id,$specialtype,$language,$defau
}
}
}

/**
* Transcribe from 3 checkboxes to 1 char for captcha usages
*
* 'A' = All three captcha enabled
* 'B' = All but save and load
* 'C' = All but registration
* 'D' = All but survey access
* 'X' = Only survey access
* 'R' = Only registration
* 'S' = Only save and load
* 'N' = None
*
* @return string One character that corresponds to captcha usage
* @todo Should really be saved as three fields in the database!
*/
private function transcribeCaptchaOptions() {
$surveyaccess = App()->request->getPost('usecaptcha_surveyaccess');
$registration = App()->request->getPost('usecaptcha_registration');
$saveandload = App()->request->getPost('usecaptcha_saveandload');

if ($surveyaccess && $registration && $saveandload)
{
return 'A';
}
elseif ($surveyaccess && $registration)
{
return 'B';
}
elseif ($surveyaccess && $saveandload)
{
return 'C';
}
elseif ($registration && $saveandload)
{
return 'D';
}
elseif ($surveyaccess)
{
return 'X';
}
elseif ($registration)
{
return 'R';
}
elseif ($saveandload)
{
return 'S';
}

return 'N';
}
}
39 changes: 17 additions & 22 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -1003,31 +1003,24 @@ public function editlocalsettings($iSurveyID)
$aData['aTabContents'] = $aTabContents;
$aData['aTabTitles'] = $aTabTitles;

$esrow = array();
$esrow = self::_fetchSurveyInfo('editsurvey', $iSurveyID);
$aData['esrow'] = $esrow;

$aData = array_merge($aData, $this->_generalTabEditSurvey($iSurveyID, $esrow));
$aData = array_merge($aData, $this->_tabPresentationNavigation($esrow));
$aData = array_merge($aData, $this->_tabPublicationAccess($esrow));
$aData = array_merge($aData, $this->_tabNotificationDataManagement($esrow));
$aData = array_merge($aData, $this->_tabTokens($esrow));
$aData = array_merge($aData, $this->_tabPanelIntegration($esrow));
$aData = array_merge($aData, $this->_tabResourceManagement($iSurveyID));

$esrow = array();
$esrow = self::_fetchSurveyInfo('editsurvey', $iSurveyID);
$aData['esrow'] = $esrow;

$aData = array_merge($aData, $this->_generalTabEditSurvey($iSurveyID, $esrow));
$aData = array_merge($aData, $this->_tabPresentationNavigation($esrow));
$aData = array_merge($aData, $this->_tabPublicationAccess($esrow));
$aData = array_merge($aData, $this->_tabNotificationDataManagement($esrow));
$aData = array_merge($aData, $this->_tabTokens($esrow));
$aData = array_merge($aData, $this->_tabPanelIntegration($esrow));
$aData = array_merge($aData, $this->_tabResourceManagement($iSurveyID));


$oResult = Question::model()->getQuestionsWithSubQuestions($iSurveyID, $esrow['language'], "({{questions}}.type = 'T' OR {{questions}}.type = 'Q' OR {{questions}}.type = 'T' OR {{questions}}.type = 'S')");

$aData['questions'] = $oResult;
$aData['display']['menu_bars']['surveysummary'] = "editsurveysettings";
$tempData = $aData;
$aData['settings_data'] = $tempData;



$oResult = Question::model()->getQuestionsWithSubQuestions($iSurveyID, $esrow['language'], "({{questions}}.type = 'T' OR {{questions}}.type = 'Q' OR {{questions}}.type = 'T' OR {{questions}}.type = 'S')");

$aData['questions'] = $oResult;
$aData['display']['menu_bars']['surveysummary'] = "editsurveysettings";
$tempData = $aData;
$aData['settings_data'] = $tempData;

$aData['sidemenu']['state'] = false;
$surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
Expand All @@ -1042,7 +1035,9 @@ public function editlocalsettings($iSurveyID)
$aViewUrls[] = 'editLocalSettings_main_view';
}
else
{
$this->getController()->error('Access denied');
}

$this->_renderWrappedTemplate('survey', $aViewUrls, $aData);
}
Expand Down
Expand Up @@ -65,57 +65,43 @@
</div>
</div>

<!-- Use CAPTCHA for -->
<!-- Use CAPTCHA for survey access -->
<?php $usecap = $esrow['usecaptcha']; // Just a short-hand ?>
<div class="form-group">
<label class="col-sm-4 control-label" for='usecaptcha'><?php eT("Use CAPTCHA for"); ?>:</label>
<label class="col-sm-4 control-label" for='usecaptcha'><?php eT("Use CAPTCHA for survey access:"); ?></label>
<div class="col-sm-8">
<select name='usecaptcha' id='usecaptcha' class="form-control" >
<option value='A'
<?php if ($esrow['usecaptcha'] == "A") { ?>
selected='selected'
<?php } ?>
><?php eT("Survey Access"); ?> / <?php eT("Registration"); ?> / <?php echo gT("Save & Load"); ?></option>
<option value='B'
<?php if ($esrow['usecaptcha'] == "B") { ?>
selected='selected'
<?php } ?>

><?php eT("Survey Access"); ?> / <?php eT("Registration"); ?> / ---------</option>
<option value='C'
<?php if ($esrow['usecaptcha'] == "C") { ?>
selected='selected'
<?php } ?>

><?php eT("Survey Access"); ?> / ------------ / <?php eT("Save & Load"); ?></option>
<option value='D'
<?php if ($esrow['usecaptcha'] == "D") { ?>
selected='selected'
<?php } ?>

>------------- / <?php eT("Registration"); ?> / <?php eT("Save & Load"); ?></option>
<option value='X'
<?php $this->widget('yiiwheels.widgets.switch.WhSwitch', array(
'name' => 'usecaptcha_surveyaccess',
'value'=> $usecap === 'A' || $usecap === 'B' || $usecap === 'C' || $usecap === 'X',
'onLabel'=>gT('On'),'offLabel'=>gT('Off')));
?>
</div>
</div>

<?php if ($esrow['usecaptcha'] == "X") { ?>
selected='selected'
<?php } ?>
<!-- Use CAPTCHA for registration -->
<div class="form-group">
<label class="col-sm-4 control-label" for='usecaptcha'><?php eT("Use CAPTCHA for registration:"); ?></label>
<div class="col-sm-8">
<?php $this->widget('yiiwheels.widgets.switch.WhSwitch', array(
'name' => 'usecaptcha_registration',
'value'=> $usecap === 'A' || $usecap === 'B' || $usecap === 'D' || $usecap === 'R',
'onLabel'=>gT('On'),
'offLabel'=>gT('Off')));
?>
</div>
</div>

><?php eT("Survey Access"); ?> / ------------ / ---------</option>
<option value='R'
<?php if ($esrow['usecaptcha'] == "R") { ?>
selected='selected'
<?php } ?>
>------------- / <?php eT("Registration"); ?> / ---------</option>
<option value='S'
<?php if ($esrow['usecaptcha'] == "S") { ?>
selected='selected'
<?php } ?>
>------------- / ------------ / <?php eT("Save & Load"); ?></option>
<option value='N'
<?php if ($esrow['usecaptcha'] == "N") { ?>
selected='selected'";
<?php } ?>
>------------- / ------------ / ---------</option>
</select>
<!-- Use CAPTCHA for save and load -->
<div class="form-group">
<label class="col-sm-4 control-label" for='usecaptcha'><?php eT("Use CAPTCHA for save and load:"); ?></label>
<div class="col-sm-8">
<?php $this->widget('yiiwheels.widgets.switch.WhSwitch', array(
'name' => 'usecaptcha_saveandload',
'value'=> $usecap === 'A' || $usecap === 'C' || $usecap === 'D' || $usecap === 'S',
'onLabel'=>gT('On'),
'offLabel'=>gT('Off')));
?>
</div>
</div>

</div>

0 comments on commit e3f9e4b

Please sign in to comment.