Skip to content

Commit

Permalink
Fixed issue: Captcha image does not appear (because GD library is not…
Browse files Browse the repository at this point in the history
… installed)
  • Loading branch information
c-schmitz committed Jan 24, 2018
1 parent 861a22e commit 42933a7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions application/controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function getRegisterErrors($iSurveyId)
$aSurveyInfo = getSurveyInfo($iSurveyId, App()->language);

// Check the security question's answer
if (function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen', $aSurveyInfo['usecaptcha'])) {
if (isCaptchaEnabled('registrationscreen', $aSurveyInfo['usecaptcha'])) {
$sLoadSecurity = Yii::app()->request->getPost('loadsecurity', '');
$captcha = Yii::app()->getController()->createAction("captcha");
$captchaCorrect = $captcha->validate($sLoadSecurity, false);
Expand Down Expand Up @@ -245,7 +245,7 @@ public function getRegisterForm($iSurveyId)
$aData['sEmail'] = $aFieldValue['sEmail'];
$aData['aAttribute'] = $aFieldValue['aAttribute'];
$aData['aExtraAttributes'] = $aRegisterAttributes;
$aData['bCaptcha'] = function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen', $oSurvey->usecaptcha);
$aData['bCaptcha'] = isCaptchaEnabled('registrationscreen', $oSurvey->usecaptcha);
$aData['sRegisterFormUrl'] = App()->createUrl('register/index', array('sid'=>$iSurveyId));

$aData['formAdditions'] = '';
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/survey/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public function action()
// if security question answer is incorrect
// Not called if scid is set in GET params (when using email save/reload reminder URL)
// && Yii::app()->request->isPostRequest ?
if (function_exists("ImageCreate") && isCaptchaEnabled('saveandloadscreen', $thissurvey['usecaptcha']) && is_null(Yii::app()->request->getQuery('scid'))) {
if (isCaptchaEnabled('saveandloadscreen', $thissurvey['usecaptcha']) && is_null(Yii::app()->request->getQuery('scid'))) {
$sLoadSecurity = Yii::app()->request->getPost('loadsecurity');
$captcha = Yii::app()->getController()->createAction('captcha');
$captchaCorrect = $captcha->validate($sLoadSecurity, false);
Expand Down Expand Up @@ -413,7 +413,7 @@ public function action()
/* Construction of the form */
$aLoadForm['aCaptcha']['show'] = false;

if (function_exists("ImageCreate") && isCaptchaEnabled('saveandloadscreen', Survey::model()->findByPk($surveyid)->usecaptcha)) {
if (isCaptchaEnabled('saveandloadscreen', Survey::model()->findByPk($surveyid)->usecaptcha)) {
$aLoadForm['aCaptcha']['show'] = true;
$aLoadForm['aCaptcha']['sImageUrl'] = Yii::app()->getController()->createUrl('/verification/image', array('sid'=>$surveyid));
}
Expand Down
3 changes: 3 additions & 0 deletions application/helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2592,6 +2592,9 @@ function incompleteAnsFilterState()
**/
function isCaptchaEnabled($screen, $captchamode = '')
{
if (!extension_loaded('gd')) {
return false;
}
switch ($screen) {
case 'registrationscreen':
if ($captchamode == 'A' ||
Expand Down
8 changes: 4 additions & 4 deletions application/libraries/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function showsaveform($iSurveyId)
}

/* Construction of the form */
if (function_exists("ImageCreate") && isCaptchaEnabled('saveandloadscreen', Survey::model()->findByPk($iSurveyId)->usecaptcha)) {
if (isCaptchaEnabled('saveandloadscreen', Survey::model()->findByPk($iSurveyId)->usecaptcha)) {
$captcha = Yii::app()->getController()->createUrl('/verification/image', array('sid'=>$iSurveyId));
} else {
$captcha = null;
Expand Down Expand Up @@ -143,7 +143,7 @@ function getSaveFormDatas($iSurveyId)

/* Construction of the form */
$aSaveForm['aCaptcha']['show'] = false;
if (function_exists("ImageCreate") && isCaptchaEnabled('saveandloadscreen', Survey::model()->findByPk($iSurveyId)->usecaptcha)) {
if (isCaptchaEnabled('saveandloadscreen', Survey::model()->findByPk($iSurveyId)->usecaptcha)) {
$aSaveForm['aCaptcha']['show'] = true;
$aSaveForm['aCaptcha']['sImageUrl'] = Yii::app()->getController()->createUrl('/verification/image', array('sid'=>$iSurveyId));
}
Expand Down Expand Up @@ -192,7 +192,7 @@ function savedcontrol()
}

// if security question asnwer is incorrect
if (function_exists("ImageCreate") && isCaptchaEnabled('saveandloadscreen', $thissurvey['usecaptcha'])) {
if (isCaptchaEnabled('saveandloadscreen', $thissurvey['usecaptcha'])) {
if (!Yii::app()->request->getPost('loadsecurity')
|| !isset($_SESSION['survey_'.$surveyid]['secanswer'])
|| Yii::app()->request->getPost('loadsecurity') != $_SESSION['survey_'.$surveyid]['secanswer']) {
Expand Down Expand Up @@ -327,7 +327,7 @@ function saveSurvey()
}

// Check captcha
if (function_exists("ImageCreate") && isCaptchaEnabled('saveandloadscreen', $thissurvey['usecaptcha'])) {
if (isCaptchaEnabled('saveandloadscreen', $thissurvey['usecaptcha'])) {

if (!Yii::app()->request->getPost('loadsecurity')
|| !isset($_SESSION['survey_'.$surveyid]['secanswer'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@
?>
</div>
</div>
<?php if(!extension_loaded('gd')) { ?>
<div class="alert alert-warning " role="alert">
<p><strong><?php eT('Warning!'); ?></strong> <?php eT("The CAPTCHA settings won't have any effect because you don't have the required GD library activated in your PHP configuration."); ?></p>
</div>
<?php }?>
</div>
</div>
</div>

0 comments on commit 42933a7

Please sign in to comment.