Skip to content

Commit

Permalink
Dev: move message error out of alert, just text-danger
Browse files Browse the repository at this point in the history
Dev: 2 error type errorALert (for form) and errorWarning
  • Loading branch information
Shnoulle committed Oct 17, 2016
1 parent b0a7aee commit ecdcf74
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 106 deletions.
11 changes: 6 additions & 5 deletions application/controllers/SurveyController.php
Expand Up @@ -97,8 +97,9 @@ public function actions()
/**
* Show a message and exit
* @param string $sType : type of message
* @param string[] $aMessage : string for the messageconstructed via array of string
* @param array[null : $aUrl : if url can/must be set
* @param string[] $aMessage : array of message line to be shown
* @param string|null : $aUrl : if url can/must be set
* @param string[] $aErrors : array of errors to be shown
* @return void
**/
function renderExitMessage($iSurveyId,$sType,$aMessages=array(),$aUrl=null,$aErrors=null)
Expand All @@ -115,18 +116,18 @@ function renderExitMessage($iSurveyId,$sType,$aMessages=array(),$aUrl=null,$aErr
$url="";
}
if(!empty($aErrors)){
$error=$this->renderPartial("/survey/system/error",array(
$error=$this->renderPartial("/survey/system/errorWarning",array(
'aErrors'=>$aErrors
),true);
}else{
$error="";
}
/* Set the data for templatereplace */
$this->aGlobalData['thissurvey']=getSurveyInfo($iSurveyId); /* Did we need it, or did we just use Yii::app()->getConfig('surveyID'); ? */
$aReplacementData['MESSAGEID']=$sType;
$this->aReplacementData=$aReplacementData['MESSAGEID']=$sType; // Adding this to replacement data : allow to update title (for example)
$aReplacementData['MESSAGE']=$message;
$aReplacementData['URL']=$url;
$aReplacementData['ERROR']=$error;
$this->aReplacementData=$aReplacementData['ERROR']=$error; // Adding this to replacement data : allow to update title (for example) : @see https://bugs.limesurvey.org/view.php?id=9106 (but need more)
$content=templatereplace(file_get_contents($oTemplate->viewPath."message.pstpl"),$aReplacementData,$this->aGlobalData);
$this->render("/survey/system/display",array('content'=>$content));
App()->end();
Expand Down
104 changes: 3 additions & 101 deletions application/controllers/survey/index.php
Expand Up @@ -438,18 +438,6 @@ function action()
} else {
$tokenInstance = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $token));
}

// if (!isset($tokenInstance) && !$previewmode)
// {
// //TOKEN DOESN'T EXIST OR HAS ALREADY BEEN USED. EXPLAIN PROBLEM AND EXIT
// $asMessage = array(
// null,
// gT("This is a controlled survey. You need a valid token to participate."),
// sprintf(gT("For further information please contact %s"), $thissurvey['adminname']." (<a href='mailto:{$thissurvey['adminemail']}'>"."{$thissurvey['adminemail']}</a>)")
// );

// $this->_niceExit($redata, __LINE__, $thistpl, $asMessage, true);
// }
}
if ($tokensexist == 1 && isset($token) && $token!="" && tableExists("{{tokens_".$surveyid."}}") && !$previewmode) //check if token is in a valid time frame
{
Expand Down Expand Up @@ -492,7 +480,6 @@ function action()
null,
array($sError)
);
$this->_niceExit($redata, __LINE__, $thistpl, $asMessage, true);
}
else
{
Expand Down Expand Up @@ -559,26 +546,6 @@ function action()
$this->getController()->layout='survey';
$this->getController()->render("/survey/system/display",array('content'=>$content));
App()->end();
//~ sendCacheHeaders();
//~ doHeader();

//~ $redata = compact(array_keys(get_defined_vars()));
//~ $this->_printTemplateContent($thistpl.'/startpage.pstpl', $redata, __LINE__);
//~ echo "\n\n<!-- JAVASCRIPT FOR CONDITIONAL QUESTIONS -->\n"
//~ ."\t<script type='text/javascript'>\n"
//~ ."\t<!--\n"
//~ ."function checkconditions(value, name, type, evt_type)\n"
//~ ."\t{\n"
//~ ."\t}\n"
//~ ."\t//-->\n"
//~ ."\t</script>\n\n";

//~ //Present the clear all page using clearall.pstpl template
//~ $this->_printTemplateContent($thistpl.'/clearall.pstpl', $redata, __LINE__);

//~ $this->_printTemplateContent($thistpl.'/endpage.pstpl', $redata, __LINE__);
//~ doFooter();
//~ exit;
}


Expand Down Expand Up @@ -760,75 +727,10 @@ function _userHasPreviewAccessSession($iSurveyID){
return (isset($_SESSION['USER_RIGHT_PREVIEW']) && ($_SESSION['USER_RIGHT_PREVIEW'] == $iSurveyID));
}

function _niceExit(&$redata, $iDebugLine, $sTemplateDir = null, $asMessage = array())
{
$oTemplate = Template::model()->getInstance('', $redata['surveyid']);
$asMessage[]="<input type='hidden' class='hidemenubutton'/>";

if(isset($redata['surveyid']) && $redata['surveyid'] && !isset($thisurvey))
{
$thissurvey=getSurveyInfo($redata['surveyid']);
$sTemplateDir= $oTemplate->viewPath;
}
else
{
$sTemplateDir= $oTemplate->viewPath;
}
sendCacheHeaders();

doHeader();

$oTemplate = $this->oTemplate; //$oTemplate->viewPath;

echo "<!-- survey/index/_niceExit -->";
$this->_printTemplateContent($oTemplate->viewPath.'/startpage.pstpl', $redata, $iDebugLine);
$this->_printMessage($asMessage);
$this->_printTemplateContent($oTemplate->viewPath.'/endpage.pstpl', $redata, $iDebugLine);

doFooter();
exit;
}

function _createNewUserSessionAndRedirect($surveyid, &$redata, $iDebugLine, $asMessage = array())
{

killSurveySession($surveyid);
$thissurvey=getSurveyInfo($surveyid);
if($thissurvey)
{
$templatename=$thissurvey['template'];
}
else
{
$templatename=Yii::app()->getConfig('defaulttemplate');;
}
// Let's redirect the client to the same URL after having reset the session
$this->_niceExit($redata, $iDebugLine, $templatename, $asMessage);
}



function _printMessage($asLines)
{
if ( func_num_args() > 1 )
$asLines = func_get_args();

if ( count($asLines) == 0 )
return;

$sError = array_shift($asLines);

echo "\t<div id='wrapper'>\n";
echo "\t<p id='tokenmessage'>\n";
if ( $sError != null )
{
echo "\t<span class='error'>".$sError."</span><br /><br />\n";
}
echo "\t".implode ("<br /><br />\n\t", $asLines)."<br /><br />\n";
echo "\t</p>\n";
echo "\t</div>\n";
}

/**
* @deprecated
*/
function _printTemplateContent($sTemplateFile, &$redata, $iDebugLine = -1)
{
echo templatereplace(file_get_contents($sTemplateFile),array(),$redata,'survey['.$iDebugLine.']');
Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions application/views/survey/system/errorWarning.php
@@ -0,0 +1,17 @@
<?php
/**
* $aErrors string[]
*
*/
?>
<?php if(count($aErrors) > 1) : ?>
<ul class='text-danger list-unstyled' role='alert'>
<?php foreach($aErrors as $key=>$error) : ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p class='text-danger' role='alert'>
<?php echo reset($aErrors); ?>
</p>
<?php endif; ?>

0 comments on commit ecdcf74

Please sign in to comment.