Skip to content

Commit

Permalink
Dev: render welcome screen
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jun 2, 2017
1 parent 6111189 commit ccb8c0e
Showing 1 changed file with 74 additions and 65 deletions.
139 changes: 74 additions & 65 deletions application/controllers/admin/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,19 @@ public function index($editfile = 'startpage.pstpl', $screenname = 'welcome', $t
if ($templatename=='') {
$templatename = Yii::app()->getConfig("defaulttemplate");
}

// This can happen if the global default template is deleted
if (!Template::checkIfTemplateExists($templatename))
{
if (!Template::checkIfTemplateExists($templatename)){
// Redirect to the default template
Yii::app()->setFlashMessage(sprintf(gT('Template %s does not exist.'),htmlspecialchars($templatename,ENT_QUOTES)),'error');
$this->getController()->redirect(array('admin/templates/sa/view/','templatename'=>'default'));
}

/* Keep Bootstrap Package clean after loading template : because template can update boostrap */
$aBootstrapPackage=Yii::app()->clientScript->packages['bootstrap'];

$aViewUrls = $this->_initialise($templatename, $screenname, $editfile, true, true);
//var_dump($aViewUrls); die();

App()->getClientScript()->reset();
Yii::app()->clientScript->packages['bootstrap']=$aBootstrapPackage;
Expand Down Expand Up @@ -704,13 +706,13 @@ protected function _templatesummary($templatename, $screenname, $editfile, $temp
//~ }


$myoutput = implode("\n", $myoutput);
//$myoutput = implode("\n", $myoutput);



App()->getClientScript()->registerScriptFile( App()->getConfig('generalscripts') . 'survey_runtime.js');
/* register template package : PS : use asset :) */
Yii::app()->clientScript->registerPackage( 'survey-template' );
Yii::app()->clientScript->registerPackage( 'survey-template-'.$templatename );
/* some needed utils script from limesurvey-public package */
App()->getClientScript()->registerScript("activateActionLink","activateActionLink();",CClientScript::POS_END);/* show the button if needed */

Expand Down Expand Up @@ -870,7 +872,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
//App()->getClientScript()->reset();
Yii::app()->loadHelper('surveytranslator');
Yii::app()->loadHelper('admin/template');
$files = $this->getValidScreenFiles($templatename);
$files = $this->getValidScreenFiles($templatename);
$cssfiles = $this->_initcssfiles($oEditedTemplate);


Expand All @@ -882,89 +884,82 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
// Standard screens
// Only these may be viewed
$screens=array();
$screens['surveylist'] = gT('Survey List Page','unescaped');
$screens['welcome'] = gT('Welcome Page','unescaped');
$screens['question'] = gT('Question Page','unescaped');
$screens['completed'] = gT('Completed Page','unescaped');
$screens['clearall'] = gT('Clear All Page','unescaped');
$screens['register'] = gT('Register Page','unescaped');
$screens['load'] = gT('Load Page','unescaped');
$screens['save'] = gT('Save Page','unescaped');
$screens['printanswers'] = gT('Print answers page','unescaped');
$screens['printablesurvey'] = gT('Printable survey page','unescaped');

/* pstpl file list */

$screens['clearall'] = gT('Clear All Page','unescaped');
$screens['errors'] = gT('Errors','unescaped');
$screens['welcome'] = gT('Welcome Page','unescaped'); // first page
$screens['load'] = gT('Load Page','unescaped');
$screens['surveylist'] = gT('Survey List Page','unescaped');

$screens['question'] = gT('Question Page','unescaped'); // main
$screens['completed'] = gT('Completed Page','unescaped'); // submit?
$screens['register'] = gT('Register Page','unescaped'); // still todo?
$screens['save'] = gT('Save Page','unescaped');
$screens['printanswers'] = gT('Print answers page','unescaped'); // todo?
$screens['printablesurvey'] = gT('Printable survey page','unescaped'); // todo ?
/* Twig layout */
/* used for call AND for pstl editable files list */
$SurveyList = array('startpage.pstpl',
'surveylist.pstpl',
'endpage.pstpl'
);
$Welcome = array('startpage.pstpl',
'welcome.pstpl',
'privacy.pstpl',
'navigator.pstpl',
'endpage.pstpl'
);
/* should contains datas for inclusion ??? */
$SurveyList = array('layout_survey_list.twig',);

$Welcome = array('layout_first_page.twig',);

/* Not used : data updated during rendering */
$Question = array('startpage.pstpl',
'survey.pstpl',
'startgroup.pstpl',
'groupdescription.pstpl',
'question.pstpl',
'endgroup.pstpl',
'navigator.pstpl',
'endpage.pstpl'
);
$CompletedTemplate = array(
'startpage.pstpl',
'assessment.pstpl',
'completed.pstpl',
'endpage.pstpl'
);
/* Not used */
$Clearall = array('startpage.pstpl',
'clearall.pstpl',
'endpage.pstpl'
);
/* Not used */
$Register = array('startpage.pstpl',
'survey.pstpl',
'register.pstpl',
'endpage.pstpl'
);
$Question = array('layout_main.twig',);

$CompletedTemplate = array('layout_submit.twig',);

/* Not used */
$Save = array('startpage.pstpl',
'save.pstpl',
'endpage.pstpl'
);
$Clearall = array('layout_clearall.twig',);

/* Not used */
$Load = array('startpage.pstpl',
'load.pstpl',
'endpage.pstpl'
);
$Save = array('layout_save.twig',);

/* Not used */
$Load = array('layout_load.twig',);

/** TODO: TWIG
// Not used
$printtemplate = array('startpage.pstpl',
'printanswers.pstpl',
'endpage.pstpl'
);
/* Not used */
// Not used
$printablesurveytemplate = array('print_survey.pstpl',
'print_group.pstpl',
'print_question.pstpl'
);
// Not used
$Register = array('startpage.pstpl',
'survey.pstpl',
'register.pstpl',
'endpage.pstpl'
);
*/

$file_version = "LimeSurvey template editor " . Yii::app()->getConfig('versionnumber');

Yii::app()->session['s_lang'] = Yii::app()->session['adminlang'];

$templatename = sanitize_dirname($templatename);

// Checks if screen name is in the list of allowed screen names
if (!isset($screens[$screenname]))
{
Yii::app()->user->setFlash('error',gT('Invalid screen name'));
$this->getController()->redirect(array("admin/templates/sa/upload"));
}

/** TODO: TWIG
if (is_file(Yii::app()->getConfig('usertemplaterootdir') . DIRECTORY_SEPARATOR . $templatename . DIRECTORY_SEPARATOR.'question_start.pstpl')) {
$files[] = 'question_start.pstpl';
$Question[] = 'question_start.pstpl';
}
**/

/* See if we found the file to be edited inside template */
/* @todo must control if is updatable : in updatable file OR is a view */
Expand All @@ -983,8 +978,9 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
// Make sure file is within the template path
if (strpos($sEditFile,realpath(Yii::app()->getConfig('usertemplaterootdir') . DIRECTORY_SEPARATOR . $templatename))===false)
{
$editfile='startpage.pstpl';
$editfile='layout_first_page.twig';
}

$extension = substr(strrchr($editfile, "."), 1);
$highlighter = 'html';
if ($extension == 'css' || $extension == 'js')
Expand Down Expand Up @@ -1030,7 +1026,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$thissurvey['surveyls_url'] = "http://www.limesurvey.org/";
$thissurvey['surveyls_urldescription'] = gT("Some URL description");
$thissurvey['usecaptcha'] = "A";
$percentcomplete = makegraph(6, 10);
$percentcomplete = 0; //makegraph(6, 10);

$groupname = gT("Group 1: The first lot of questions");
$groupdescription = gT("This group description is fairly vacuous, but quite important.");
Expand All @@ -1056,6 +1052,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$templateurl = getTemplateURL($templatename);

// Save these variables in an array
// TODO: remove the useless datas for twig
$aData['thissurvey'] = $thissurvey;
$aData['percentcomplete'] = $percentcomplete;
$aData['groupname'] = $groupname;
Expand All @@ -1077,7 +1074,9 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$aData['templatename'] = $templatename;
$aData['screenname'] = $screenname;
$aData['editfile'] = $editfile;

/* always here, even if hidden or in navigator , for button : if nopt in navigator : must be hidden by default */
/* TODO : TWIG
$aGlobalReplacements = array(
'SAVE_LINKS' => $this->getController()->renderPartial("/survey/system/actionLink/saveSave",array(
'submit'=>'', // Don't do the action, just for display
Expand All @@ -1101,20 +1100,25 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
'confirmvalue'=>'confirm',
),true),
);
*/
$aGlobalReplacements = array();
$myoutput[] = "";

// TODO: TWIG
switch ($screenname)
{
case 'surveylist':
$aSurveyList = array(
'publicSurveys' => Survey::model()->active()->open()->public()->with('languagesettings')->findAll(),
'futureSurveys' => Survey::model()->active()->registration()->public()->with('languagesettings')->findAll(),
);

$aReplacementSurveyList = array(
"SURVEYCONTACT" => sprintf(gT("Please contact %s ( %s ) for further assistance."), Yii::app()->getConfig("siteadminname"), Yii::app()->getConfig("siteadminemail")),
"SURVEYLISTHEADING" => gT("The following surveys are available:"),
"SURVEYLIST" => $this->getController()->renderPartial('/admin/templates/templateeditor_surveylist_view', $aSurveyList, true),
);

//$aData['surveylist'] = $aSurveyListTexts;
$aData['aReplacements'] = array_merge($aGlobalReplacements,$aReplacementSurveyList);
$myoutput[] = "";
Expand Down Expand Up @@ -1191,6 +1195,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
break;

case 'welcome':
/*
$sMoveNext = App()->getController()->renderPartial("/survey/system/actionButton/moveNext",array('value'=>"movenext",'class'=>"ls-move-btn ls-move-next-btn"),true);
$aData['aReplacements'] = array_merge($aGlobalReplacements,array(
'MOVEPREVBUTTON' => '',
Expand All @@ -1201,6 +1206,9 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
foreach ($files as $qs) {
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/$qs", $aData, $oEditedTemplate));
}
*/
$myoutput = Yii::app()->twigRenderer->renderTemplateFromFile("layout_first_page.twig", array('aSurveyInfo'=>$thissurvey), true);
//var_dump($myoutput); die();
break;

case 'register':
Expand Down Expand Up @@ -1328,7 +1336,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$myoutput[] = "\n";
break;
}
$myoutput[] = "</html>";
//$myoutput[] = "</html>";

$jsfiles = $this->_getEditableJsFiles($oEditedTemplate);
$aCssAndJsfiles = array_merge($cssfiles,$jsfiles ) ;
Expand Down Expand Up @@ -1403,6 +1411,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
*/
protected function _renderWrappedTemplate($sAction = 'templates', $aViewUrls = array(), $aData = array())
{
//var_dump($aViewUrls);
//$aData['display']['menu_bars'] = false;
parent::_renderWrappedTemplate($sAction, $aViewUrls, $aData);
}
Expand Down

0 comments on commit ccb8c0e

Please sign in to comment.