From ffdaa7c26b45855fbc1a6d5f4fa5792e3116a3fb Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Wed, 4 May 2016 13:47:27 +0200 Subject: [PATCH] Fixed issue #11001: Selecting a theme in the theme editor does not function properly --- application/controllers/admin/templates.php | 255 +++++++----------- application/helpers/admin/template_helper.php | 31 +-- .../templates/templateeditorbar_view.php | 27 +- .../admin/templates/templatesummary_view.php | 110 ++++---- 4 files changed, 171 insertions(+), 252 deletions(-) diff --git a/application/controllers/admin/templates.php b/application/controllers/admin/templates.php index ae76398af9d..075cb2ad31c 100644 --- a/application/controllers/admin/templates.php +++ b/application/controllers/admin/templates.php @@ -261,8 +261,7 @@ public function uploadfile() } $action = returnGlobal('action'); - $editfileindex = App()->request->getPost('editfileindex'); - $useindex = App()->request->getPost('useindex'); + $templatename = returnGlobal('templatename'); $oEditedTemplate = Template::model()->getTemplateConfiguration($templatename); $templatedir = $oEditedTemplate->viewPath; @@ -285,7 +284,7 @@ public function uploadfile() { $uploadresult = sprintf(gT("The folder %s doesn't exist and can't be created."),$dirfilepath); Yii::app()->setFlashMessage($uploadresult,'error'); - $this->getController()->redirect(array('admin/templates/sa/view/editfile/'.$editfileindex.'/screenname/'.$screenname.'/templatename/'.$templatename.'/useindex/'.$useindex)); + $this->getController()->redirect(array('admin/templates/sa/view/','screenname'=>$screenname,'templatename'=>$templatename)); } } @@ -319,7 +318,7 @@ public function uploadfile() } Yii::app()->setFlashMessage($uploadresult,$status); } - $this->getController()->redirect(array('admin/templates/sa/view/editfile/'.$editfileindex.'/screenname/'.$screenname.'/templatename/'.$templatename.'/useindex/'.$useindex)); + $this->getController()->redirect(array('admin/templates/sa/view/','screenname'=>$screenname,'templatename'=>$templatename)); } /** @@ -365,25 +364,19 @@ protected function _strip_ext($name) * Load default view screen of template controller. * * @access public - * @param string $editfile - * @param string $screenname - * @param string $templatename * @return void */ - public function index($editfile = 'startpage.pstpl', $screenname = 'welcome', $templatename = '', $useindex=false) + public function index() { - if(!$templatename) - { - $templatename = Yii::app()->getConfig("defaulttemplate"); - } - + $templatename = App()->request->getParam('templatename',Yii::app()->getConfig("defaulttemplate")); + $screenname = App()->request->getParam('screenname','welcome'); + $editfile = App()->request->getParam('editfile','pstpl_0'); // This can happen if the global default template is deleted if (!Template::checkIfTemplateExists($templatename)) { $templatename = 'default'; } - - $aViewUrls = $this->_initialise($templatename, $screenname, $editfile, true, $useindex); + $aViewUrls = $this->_initialise($templatename, $screenname, $editfile, true, true); App()->getClientScript()->reset(); $this->registerScriptFile( 'ADMIN_SCRIPT_PATH', 'admin_core.js'); $this->registerScriptFile( 'ADMIN_SCRIPT_PATH', 'templates.js'); @@ -412,13 +405,13 @@ public function index($editfile = 'startpage.pstpl', $screenname = 'welcome', $t * @param string $editfile * @return void */ - public function fileredirect($templatename = '', $screenname = 'welcome', $editfile = 'startpage.pstpl', $useindex=false) + public function fileredirect($templatename = '', $screenname = 'welcome', $editfile = 'startpage.pstpl') { if(!$templatename) { $templatename = Yii::app()->getConfig("defaulttemplate"); } - $this->getController()->redirect(array("admin/templates/sa/view/editfile/" . $editfile . "/screenname/" . $screenname . "/templatename/" . $templatename . '/useindex/' . $useindex)); + $this->getController()->redirect(array("admin/templates/sa/view/","editfile"=>$editfile,"screenname" =>$screenname ,"templatename"=>$templatename )); } /** @@ -438,7 +431,7 @@ public function templatefiledelete() // This is where the temp file is $sFileToDelete=sanitize_filename(returnGlobal('otherfile'),false,false); - $sTemplateName=Template::templateNameFilter(App()->request->getPost('templatename')); + $sTemplateName=Template::templateNameFilter(App()->request->getParam('templatename')); $oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName); $templatedir = $oEditedTemplate->viewPath; $filesdir = $oEditedTemplate->filesPath; @@ -451,9 +444,8 @@ public function templatefiledelete() { Yii::app()->user->setFlash('error',sprintf(gT("File %s couldn't be deleted. Please check the permissions on the /upload/template folder"), htmlspecialchars($sFileToDelete))); } - $editfileindex = App()->request->getPost('editfileindex'); - $useindex = App()->request->getPost('useindex'); - $this->getController()->redirect(array('admin/templates/sa/view/editfile/'.$editfileindex.'/screenname/'.returnGlobal('screenname').'/templatename/'.$sTemplateName.'/useindex/'.$useindex)); + $editfileindex = App()->request->getParam('editfileindex'); + $this->getController()->redirect(array('admin/templates/sa/view/','editfile'=>$editfileindex,'screenname'=>returnGlobal('screenname'),'templatename'=>$sTemplateName)); } } @@ -517,9 +509,9 @@ public function templatecopy() { die('No permission'); } - $newname=sanitize_dirname(Yii::app()->request->getPost("newname")); - $copydir=sanitize_dirname(Yii::app()->request->getPost("copydir")); - $action=Yii::app()->request->getPost("action"); + $newname=sanitize_dirname(Yii::app()->request->getParam("newname")); + $copydir=sanitize_dirname(Yii::app()->request->getParam("copydir")); + $action=Yii::app()->request->getParam("action"); if ($newname && $copydir) { // Copies all the files from one template directory to a new one Yii::app()->loadHelper('admin/template'); @@ -618,20 +610,10 @@ public function templatesavechanges() $changedtext = stripslashes($changedtext); } - if (returnGlobal('changes_cp')) { - $changedtext = returnGlobal('changes_cp'); - $changedtext = str_replace('request->getPost('templatename')); - $editfileindex = App()->request->getPost('editfileindex'); - $useindex = App()->request->getPost('useindex'); + $editfilename = returnGlobal('editfilename'); + $sTemplateName = Template::templateNameFilter(App()->request->getParam('templatename')); $screenname = returnGlobal('screenname'); $oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName); $files = $this->_initfiles($sTemplateName); @@ -643,20 +625,20 @@ public function templatesavechanges() Yii::app()->loadHelper('admin/template'); $changedtext = str_replace("\r\n", "\n", $changedtext); - if ($editfile) + if ($editfilename) { // Check if someone tries to submit a file other than one of the allowed filenames if ( - multiarray_search($files, 'name', $editfile) === false && - multiarray_search($cssfiles, 'name', $editfile) === false && - multiarray_search($jsfiles, 'name', $editfile) === false + multiarray_search($files, 'name', $editfilename) === false && + multiarray_search($cssfiles, 'name', $editfilename) === false && + multiarray_search($jsfiles, 'name', $editfilename) === false ) { - Yii::app()->user->setFlash('error',gT('Invalid template name')); - $this->getController()->redirect(array("admin/templates/sa/upload")); + Yii::app()->user->setFlash('error',gT('Invalid file name')); + $this->getController()->redirect(array("admin/templates")); } - $savefilename = gettemplatefilename(Yii::app()->getConfig('usertemplaterootdir') . "/" . $sTemplateName, $editfile); + $savefilename = gettemplatefilename(Yii::app()->getConfig('usertemplaterootdir') . "/" . $sTemplateName, $editfilename); if (is_writable($savefilename)) { @@ -684,31 +666,7 @@ public function templatesavechanges() } } - $this->getController()->redirect(array('admin/templates/sa/view/editfile/'.$editfileindex.'/screenname/'.$screenname.'/templatename/'.$sTemplateName.'/useindex/'.$useindex)); - } - - /** - * Load menu bar related to a template. - * - * @access protected - * @param string $screenname - * @param string $editfile - * @param string $screens - * @param string $tempdir - * @param string $templatename - * @return void - * @deprecated ? 151005 - */ - protected function _templatebar($screenname, $editfile, $screens, $tempdir, $templatename) - { - $aData['screenname'] = $screenname; - $aData['editfile'] = $editfile; - $aData['screens'] = $screens; - $aData['tempdir'] = $tempdir; - $aData['templatename'] = $templatename; - $aData['usertemplaterootdir'] = Yii::app()->getConfig('usertemplaterootdir'); - - $this->getController()->render("/admin/templates/templatebar_view", $aData); + $this->getController()->redirect(array('admin/templates/sa/view','editfile'=>$editfile,'screenname'=>$screenname,'templatename'=>$sTemplateName)); } /** @@ -911,7 +869,7 @@ protected function _getEditableJsFiles($oEditedTemplate) * @param bool $showsummary * @return */ - protected function _initialise($templatename, $screenname, $editfile, $showsummary = true, $useindex=false) + protected function _initialise($templatename, $screenname, $editfile, $showsummary = true) { // LimeSurvey style $oEditedTemplate = Template::model()->getTemplateConfiguration($templatename); @@ -944,29 +902,20 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma // Standard screens // Only these may be viewed - $screens[] = array('name' => gT('Survey List Page'), 'id' => 'surveylist'); - $screens[] = array('name' => gT('Welcome Page'), 'id' => 'welcome'); - $screens[] = array('name' => gT('Question Page'), 'id' => 'question'); - $screens[] = array('name' => gT('Completed Page'), 'id' => 'completed'); - $screens[] = array('name' => gT('Clear All Page'), 'id' => 'clearall'); - $screens[] = array('name' => gT('Register Page'), 'id' => 'register'); - $screens[] = array('name' => gT('Load Page'), 'id' => 'load'); - $screens[] = array('name' => gT('Save Page'), 'id' => 'save'); - $screens[] = array('name' => gT('Print answers page'), 'id' => 'printanswers'); - $screens[] = array('name' => gT('Printable survey page'), 'id' => 'printablesurvey'); - - // Page display blocks - $SurveyList = array('startpage.pstpl', - 'surveylist.pstpl', - 'endpage.pstpl' - ); - $Welcome = array('startpage.pstpl', + $screens['surveylist'] = array('name' => gT('Survey List Page'), 'files' => array( + 'startpage.pstpl', + 'surveylist.pstpl', + 'endpage.pstpl' + )); + $screens['welcome'] = array('name' => gT('Welcome Page'), 'files' => array( + 'startpage.pstpl', 'welcome.pstpl', 'privacy.pstpl', 'navigator.pstpl', 'endpage.pstpl' - ); - $Question = array('startpage.pstpl', + )); + $screens['question'] = array('name' => gT('Question Page'), 'files' => array( + 'startpage.pstpl', 'survey.pstpl', 'startgroup.pstpl', 'groupdescription.pstpl', @@ -974,102 +923,84 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma 'endgroup.pstpl', 'navigator.pstpl', 'endpage.pstpl' - ); - $CompletedTemplate = array( + )); + $screens['completed'] = array('name' => gT('Completed Page'), 'files' => array( 'startpage.pstpl', 'assessment.pstpl', 'completed.pstpl', 'endpage.pstpl' - ); - $Clearall = array('startpage.pstpl', + )); + $screens['clearall'] = array('name' => gT('Clear All Page'), 'files' => array( + 'startpage.pstpl', 'clearall.pstpl', 'endpage.pstpl' - ); - $Register = array('startpage.pstpl', + )); + $screens['register'] = array('name' => gT('Register Page'), 'files' => array( + 'startpage.pstpl', 'survey.pstpl', 'register.pstpl', 'endpage.pstpl' - ); - $Save = array('startpage.pstpl', - 'save.pstpl', - 'endpage.pstpl' - ); - $Load = array('startpage.pstpl', + )); + $screens['load'] = array('name' => gT('Load Page'), 'files' => array( + 'startpage.pstpl', 'load.pstpl', 'endpage.pstpl' - ); - $printtemplate = array('startpage.pstpl', + )); + $screens['save'] = array('name' => gT('Save Page'), 'files' => array( + 'startpage.pstpl', + 'save.pstpl', + 'endpage.pstpl' + )); + $screens['printanswers'] = array('name' => gT('Print answers page'), 'files' => array( + 'startpage.pstpl', 'printanswers.pstpl', 'endpage.pstpl' - ); - $printablesurveytemplate = array('print_survey.pstpl', + )); + $screens['printablesurvey'] = array('name' => gT('Printable survey page'), 'files' => array( + 'print_survey.pstpl', 'print_group.pstpl', 'print_question.pstpl' - ); + )); $file_version = "LimeSurvey template editor " . Yii::app()->getConfig('versionnumber'); Yii::app()->session['s_lang'] = Yii::app()->session['adminlang']; - $templatename = sanitize_dirname($templatename); - $screenname = autoUnescape($screenname); // Checks if screen name is in the list of allowed screen names - if (multiarray_search($screens, 'id', $screenname) === false) + if (array_key_exists($screenname, $screens) === false) { Yii::app()->user->setFlash('error',gT('Invalid screen name')); $this->getController()->redirect(array("admin/templates/sa/upload")); } - if (!isset($action)) - $action = sanitize_paranoid_string(returnGlobal('action')); - - if (!isset($subaction)) - $subaction = sanitize_paranoid_string(returnGlobal('subaction')); - - if (!isset($newname)) - $newname = sanitize_dirname(returnGlobal('newname')); - - if (!isset($copydir)) - $copydir = sanitize_dirname(returnGlobal('copydir')); - - if (is_file(Yii::app()->getConfig('usertemplaterootdir') . '/' . $templatename . '/question_start.pstpl')) { + if (is_file(Yii::app()->getConfig('usertemplaterootdir') . '/' . $templatename . '/question_start.pstpl') && $screenname=='question') { $files[] = array('name' => 'question_start.pstpl'); - $Question[] = 'question_start.pstpl'; + $screens['question']['files'][] = 'question_start.pstpl'; } - $editfile=sanitize_filename($editfile); // Fixed with editable file after, but put in aData before fix - $availableeditorlanguages = array('bg', 'cs', 'de', 'dk', 'en', 'eo', 'es', 'fi', 'fr', 'hr', 'it', 'ja', 'mk', 'nl', 'pl', 'pt', 'ru', 'sk', 'zh'); - // 2.06 way of doing. - if(!$useindex) - { - $extension = substr(strrchr($editfile, "."), 1); - } - // 2.5 - else - { - // The extension is now set as a prefix separated by a _ - $file_datas = explode("_", $editfile); - $extension = $file_datas[0]; + // The extension is now set as a prefix separated by a _ + $file_datas = explode("_", $editfile); + $extension = $file_datas[0]; - // The file name is now based on the index of the oTemplate files - $file_index = $file_datas[1]; - switch($extension) - { - case 'css': - $aTemplateFiles = (array) $oEditedTemplate->config->files_editable->css->filename; + // The file name is now based on the index of the oTemplate files + $file_index = $file_datas[1]; + switch($extension) + { + case 'css': + $aTemplateFiles = (array) $oEditedTemplate->config->files_editable->css->filename; break; - - case 'js': - $aTemplateFiles = (array) $oEditedTemplate->config->files_editable->js->filename; + case 'js': + $aTemplateFiles = (array) $oEditedTemplate->config->files_editable->js->filename; break; - - default: - $aTemplateFiles = (array) $oEditedTemplate->config->files_editable->css->filename; + case 'pstpl': + $aTemplateFiles = $screens[$screenname]['files']; break; - } - $editfile = $aTemplateFiles[$file_index]; + default: + $aTemplateFiles = (array) $oEditedTemplate->config->files_editable->css->filename; } + $editfile = $aTemplateFiles[$file_index]; + if ($extension == 'css' || $extension == 'js') $highlighter = $extension; @@ -1180,7 +1111,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma $myoutput[] = ""; //$myoutput[] = templatereplace(file_get_contents("$templatedir/startpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); - foreach ($SurveyList as $qs) + foreach ($screens[$screenname]['files'] as $qs) { $files[] = array("name" => $qs); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/$qs", $aData, $oEditedTemplate)); @@ -1189,7 +1120,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma case 'question': unset($files); - foreach ($Question as $qs) + foreach ($screens[$screenname]['files'] as $qs) $files[] = array("name" => $qs); $myoutput[] = $this->getController()->render('/admin/templates/templateeditor_question_meta_view', array(), true); @@ -1242,7 +1173,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma ' @@ -1271,7 +1202,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma 'MOVENEXTBUTTON' => '' ); - foreach ($Welcome as $qs) { + foreach ($screens[$screenname]['files'] as $qs) { $files[] = array("name" => $qs); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/$qs", $aData, $oEditedTemplate)); } @@ -1281,7 +1212,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma case 'register': unset($files); - foreach ($Register as $qs) { + foreach ($screens[$screenname]['files'] as $qs){ $files[] = array("name" => $qs); } @@ -1308,7 +1239,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma case 'save': unset($files); - foreach ($Save as $qs) + foreach ($screens[$screenname]['files'] as $qs) $files[] = array("name" => $qs); $myoutput[] = templatereplace(file_get_contents("$templatedir/startpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); @@ -1319,7 +1250,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma case 'load': unset($files); - foreach ($Load as $qs) + foreach ($screens[$screenname]['files'] as $qs) $files[] = array("name" => $qs); $myoutput[] = templatereplace(file_get_contents("$templatedir/startpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); @@ -1330,7 +1261,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma case 'clearall': unset($files); - foreach ($Clearall as $qs) + foreach ($screens[$screenname]['files'] as $qs) $files[] = array("name" => $qs); $myoutput[] = templatereplace(file_get_contents("$templatedir/startpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate); @@ -1342,7 +1273,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma case 'completed': unset($files); $myoutput[] = ""; - foreach ($CompletedTemplate as $qs) + foreach ($screens[$screenname]['files'] as $qs) { $files[] = array("name" => $qs); $myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/$qs", $aData, $oEditedTemplate)); @@ -1351,7 +1282,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma case 'printablesurvey': unset($files); - foreach ($printablesurveytemplate as $qs) + foreach ($screens[$screenname]['files'] as $qs) { $files[] = array("name" => $qs); } @@ -1396,7 +1327,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma case 'printanswers': unset($files); - foreach ($printtemplate as $qs) + foreach ($screens[$screenname]['files'] as $qs) { $files[] = array("name" => $qs); } @@ -1468,6 +1399,10 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma $aData['codelanguage'] = $codelanguage; $aData['highlighter'] = $highlighter; $aData['screens'] = $screens; + foreach ($screens as $index=>$value) + { + $aData['screenselect'][$index] = $value['name']; + } $aData['templatename'] = $templatename; $aData['templates'] = $templates; $aData['editfile'] = $editfile; diff --git a/application/helpers/admin/template_helper.php b/application/helpers/admin/template_helper.php index 2ca6403b3d7..8023ae110cb 100644 --- a/application/helpers/admin/template_helper.php +++ b/application/helpers/admin/template_helper.php @@ -15,7 +15,7 @@ function doreplacement($file,$data, $oTemplate='') { - //Produce sample page from template file + //Produce sample page from template file $aReplacements=isset($data['aReplacements']) ? $data['aReplacements'] : array(); return (array)templatereplace(file_get_contents($file),$aReplacements,$data, 'Unspecified', false, NULL, array(), false, $oTemplate); } @@ -100,35 +100,12 @@ function makeoptions($array, $value, $text, $selectedvalue) { /** * Index is the file index in the Template configuration file */ -function makeoptionswithindex($array, $value, $text, $selectedvalue, $prefix) +function makeoptionswithindex($array, $prefix) { - - if(isset( $_GET['editfile'])) - { - $editfile = (string) $_GET['editfile']; - $editfile_infos = explode('_',$editfile); - - // If user is editing a file requiring an index, $_GET['editfile'] will have a prefix (like css or js) - // If it's the same prefix than the one asked here, then it means he's editing one of the files of the list - // The edited file will have an index corresponding to the suffix of $_GET['editfile'] - // e.g : admin/templates/sa/view/editfile/css_1/ .... - // Mean user is editing a css file with index 1 in the template's configuration file - if(isset($editfile_infos[0]) && $editfile_infos[0] == $prefix) - $selectedindex = $editfile_infos[1]; - } - $selectedindex = (isset($selectedindex))?$selectedindex:-1; - - $return=''; + $return=array(); foreach ($array as $index => $ar) { - $return .= "