Skip to content

Commit

Permalink
Merged branch develop into develop_adminpanel
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Jun 28, 2017
2 parents 099326a + 20036bc commit 068201d
Show file tree
Hide file tree
Showing 73 changed files with 10,132 additions and 224 deletions.
1 change: 1 addition & 0 deletions application/config/internal.php
Expand Up @@ -43,6 +43,7 @@
// Third party path
'third_party' => realpath(__DIR__ . '/../../third_party'),
'core' => realpath(__DIR__ . '/../../assets/packages'),
'fonts' => realpath(__DIR__ . '/../../fonts'),

// yiistrap configuration
'bootstrap' => realpath(__DIR__ . '/../extensions/bootstrap'),
Expand Down
4 changes: 2 additions & 2 deletions application/config/packages.php
Expand Up @@ -65,8 +65,8 @@
),

'bootstrap-rtl'=>array( /* Adding boostrap rtl package */
'devBaseUrl' => 'assets/packages/bootstrap-rtl/',
'basePath' => 'core.bootstrap-rtl',
'devBaseUrl' => 'assets/packages/bootstrap/',
'basePath' => 'core.bootstrap',
'css'=> array(
'bootstrap-rtl.css',
),
Expand Down
23 changes: 15 additions & 8 deletions application/config/third_party.php
Expand Up @@ -8,7 +8,7 @@
/* This allow us to use minified version according to debug */
$debug = isset($userConfig['config']['debug']) ? $userConfig['config']['debug'] : 0;
/* To add more easily min version : config > 2 , seems really an core dev issue to fix bootstrap.js ;) */
$minVersion = ($debug>2) ? "":".min";
$minVersion = ($debug>0) ? "":".min";
/* Please : comment the reason, mantis bug link: ajax don't need any package if i don't make error */
/* Ajax must renderPartial (better : always return json) and never render and don't registerScript (IMHO) / Shnoulle on 2016-11-16 */
if(isset($_GET['isAjax'])){
Expand All @@ -19,6 +19,7 @@

// jQuery
'jquery' => array(
'devBaseUrl' => 'third_party/jquery',
'basePath' => 'third_party.jquery',
'js' => array(
'jquery-3.1.1'.$minVersion.'.js',
Expand All @@ -27,16 +28,17 @@
),
// Bootstrap
// This package replace the Yiistrap register() function
// Then instead of using the composer dependency system for templates (will be used for LS3)
// Then instead of using the composer dependency system for templates
// We can use the package dependency system (easier for now)
'bootstrap' => array(
'basePath' => 'bootstrap',
'devBaseUrl' => 'assets/packages/bootstrap/',
'basePath' => 'core.bootstrap',
'css'=> array(
'css/bootstrap.css',/* Admin need it, not public */
'css/yiistrap.css',
'bootstrap'.$minVersion.'.css',/* Admin need it, not public */
'yiistrap'.$minVersion.'.css',
),
'js'=>array(
'js/bootstrap'.$minVersion.'.js'
'bootstrap'.$minVersion.'.js'
),
'depends' => array(
'jquery',
Expand All @@ -59,14 +61,16 @@

'fontawesome' => array(
//'basePath' => 'third_party.bootstrap', // Need fix third_party alias
'basePath' => 'third_party.fontawesome',
'devBaseUrl' => 'fonts/fontawesome/',
'basePath' => 'fonts.fontawesome',
'css'=> array(
'css/font-awesome.min.css',
'css/font-awesome'.$minVersion.'.css',
),
),

// jQuery UI
'jqueryui' => array(
'devBaseUrl' => 'third_party/jquery-ui',
'basePath' => 'third_party.jquery-ui',
'js' => array(
'jquery-ui'.$minVersion.'.js',
Expand Down Expand Up @@ -188,6 +192,7 @@

// Ace
'ace' => array(
'devBaseUrl' => 'third_party/ace',
'basePath' => 'third_party.ace',
'js' => array(
'ace.js'
Expand All @@ -199,6 +204,7 @@

// jQuery Ace
'jquery-ace' => array(
'devBaseUrl' => 'third_party/jquery-ace',
'basePath' => 'third_party.jquery-ace',
'js' => array(
'jquery.ace.js',
Expand Down Expand Up @@ -232,6 +238,7 @@

// Decimal.js calculate in js
'decimal' => array(
'devBaseUrl' => 'third_party/decimal',
'basePath' => 'third_party.decimal',
'js' => array(
'decimal.js'
Expand Down
167 changes: 49 additions & 118 deletions application/controllers/admin/templates.php
Expand Up @@ -26,10 +26,10 @@ class templates extends Survey_Common_Action

public function runWithParams($params)
{
if (!Permission::model()->hasGlobalPermission('templates','read'))
{
if (!Permission::model()->hasGlobalPermission('templates','read')){
die('No permission');
}

parent::runWithParams($params);
}

Expand Down Expand Up @@ -333,8 +333,10 @@ protected function _strip_ext($name)
* @param string $templatename
* @return void
*/
public function index($editfile = 'startpage.pstpl', $screenname = 'welcome', $templatename = '')
public function index($editfile = '', $screenname = 'welcome', $templatename = '')
{


if ($templatename=='') {
$templatename = Yii::app()->getConfig("defaulttemplate");
}
Expand Down Expand Up @@ -602,8 +604,7 @@ public function delete($templatename)
public function templatesavechanges()
{

if (!Permission::model()->hasGlobalPermission('templates','update'))
{
if (!Permission::model()->hasGlobalPermission('templates','update')){
die('No permission');
}

Expand All @@ -617,67 +618,69 @@ public function templatesavechanges()
if (returnGlobal('changes_cp')) {
$changedtext = returnGlobal('changes_cp');
$changedtext = str_replace('<?', '', $changedtext);
if (get_magic_quotes_gpc())
{
if (get_magic_quotes_gpc()){
$changedtext = stripslashes($changedtext);
}
}

$action = returnGlobal('action');
$editfile = returnGlobal('editfile');
$sTemplateName = Template::templateNameFilter(App()->request->getPost('templatename'));
$screenname = returnGlobal('screenname');
$oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName);
$aScreenFiles = $oEditedTemplate->getValidScreenFiles("view");
$cssfiles = $oEditedTemplate->getValidScreenFiles("css");
$jsfiles = $oEditedTemplate->getValidScreenFiles("js");
$action = returnGlobal('action');
$editfile = returnGlobal('editfile');
$relativePathEditfile = returnGlobal('relativePathEditfile');
$sTemplateName = Template::templateNameFilter(App()->request->getPost('templatename'));
$screenname = returnGlobal('screenname');
$oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName);
$aScreenFiles = $oEditedTemplate->getValidScreenFiles("view");
$cssfiles = $oEditedTemplate->getValidScreenFiles("css");
$jsfiles = $oEditedTemplate->getValidScreenFiles("js");


if ($action == "templatesavechanges" && $changedtext){
Yii::app()->loadHelper('admin/template');
$changedtext = str_replace("\r\n", "\n", $changedtext);

if ($editfile)
{

if ($relativePathEditfile){
// Check if someone tries to submit a file other than one of the allowed filenames
if (
in_array($editfile,$aScreenFiles)===false &&
in_array($editfile,$cssfiles)===false &&
in_array($editfile,$jsfiles)===false
)
{
in_array($relativePathEditfile,$aScreenFiles)===false &&
in_array($relativePathEditfile,$cssfiles)===false &&
in_array($relativePathEditfile,$jsfiles)===false
){
Yii::app()->user->setFlash('error',gT('Invalid template name'));
$this->getController()->redirect(array("admin/templates/sa/upload"));
}

$savefilename = gettemplatefilename($sTemplateName, $editfile);

if (is_writable($savefilename))
{
if (!$handle = fopen($savefilename, 'w'))
{
//$savefilename = $oEditedTemplate
if( !file_exists($oEditedTemplate->path.'/'.$relativePathEditfile) && !file_exists($oEditedTemplate->viewPath.$relativePathEditfile) ){
$oEditedTemplate->extendsFile($relativePathEditfile);
}

$savefilename = $oEditedTemplate->extendsFile($relativePathEditfile);

if (is_writable($savefilename)){

if (!$handle = fopen($savefilename, 'w')){
Yii::app()->user->setFlash('error',gT('Could not open file '). $savefilename);
$this->getController()->redirect(array("admin/templates/sa/upload"));
}

if (!fwrite($handle, $changedtext))
{
if (!fwrite($handle, $changedtext)){
Yii::app()->user->setFlash('error',gT('Could not write file '). $savefilename);
$this->getController()->redirect(array("admin/templates/sa/upload"));
}

$oEditedTemplate->actualizeLastUpdate();

fclose($handle);
}
else
{
}else{
Yii::app()->user->setFlash('error',"The file $savefilename is not writable");
$this->getController()->redirect(array("admin/templates/sa/upload"));
}

}
}

$this->getController()->redirect(array('admin/templates/','sa'=>'view','editfile'=>$editfile,'screenname'=>$screenname,'templatename'=>$sTemplateName));
}

Expand Down Expand Up @@ -720,7 +723,7 @@ protected function _templatebar($screenname, $editfile, $screens, $tempdir, $tem
* @param array $myoutput
* @return void
*/
protected function _templatesummary($templatename, $screenname, $editfile, $templates, $files, $cssfiles, $jsfiles, $otherfiles, $myoutput)
protected function _templatesummary($templatename, $screenname, $editfile, $relativePathEditfile, $templates, $files, $cssfiles, $jsfiles, $otherfiles, $myoutput)
{
$tempdir = Yii::app()->getConfig("tempdir");
$tempurl = Yii::app()->getConfig("tempurl");
Expand Down Expand Up @@ -789,6 +792,7 @@ protected function _templatesummary($templatename, $screenname, $editfile, $temp
$filesdir = $oEditedTemplate->filesPath;
$aData['screenname'] = $screenname;
$aData['editfile'] = $editfile;
$aData['relativePathEditfile'] = $relativePathEditfile;
$aData['tempdir'] = $tempdir;
$aData['templatename'] = $templatename;
$aData['templates'] = $templates;
Expand Down Expand Up @@ -853,7 +857,6 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$screens=array();



$screens['welcome'] = gT('Welcome Page','unescaped'); // first page*
$screens['question'] = gT('Question Page','unescaped'); // main
$screens['completed'] = gT('Completed Page','unescaped'); // submit?
Expand All @@ -864,52 +867,6 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$screens['error'] = gT('Error','unescaped');
$screens['assessments'] = gT('Assessments','unescaped');

// TODO: $screens['register'] = gT('Register Page','unescaped'); // still todo?

//TODO: $screens['printanswers'] = gT('Print answers page','unescaped'); // todo?
//TODO: $screens['printablesurvey'] = gT('Printable survey page','unescaped'); // todo ?
/* Twig layout */
/* used for call AND for pstl editable files list */
/* 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('layout_main.twig',);

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

/* Not used */
$Clearall = array('layout_clearall.twig',);

/* Not used */
$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
$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'];
Expand Down Expand Up @@ -1158,7 +1115,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma

$myoutput = Yii::app()->twigRenderer->renderTemplateForTemplateEditor( $sLayoutFile,array('aSurveyInfo'=>$thissurvey), $oEditedTemplate);

$jsfiles = $oEditedTemplate->getValidScreenFiles("js");
$jsfiles = $oEditedTemplate->getValidScreenFiles("js");
$aCssAndJsfiles = array_merge($cssfiles,$jsfiles ) ;

// XML Behaviour: if only one file, then $files is just a string
Expand All @@ -1170,6 +1127,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
// Get list of 'otherfiles'
// We can't use $oTemplate->otherFiles, because of retrocompatibility with 2.06 template and the big mess of it mixing files
$filesdir = ($oEditedTemplate->filesPath!='')?$oEditedTemplate->filesPath:$templatedir . '../files';

$otherfiles = array();
if ( file_exists($filesdir) && $handle = opendir($filesdir))
{
Expand All @@ -1185,50 +1143,22 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
closedir($handle);
}

$editfile = (empty($editfile))?$sLayoutFile:$editfile;
$sEditfile = $oEditedTemplate->getFilePathForEdition($editfile, array_merge($files, $aCssAndJsfiles));


$editfile = $oEditedTemplate->getFilePathForEdition($editfile, array_merge($files, $aCssAndJsfiles));
/*
if (is_array($files))
{
$match = 0;
if (in_array($editfile,$files) || in_array($editfile,$aCssAndJsfiles))
{
$match=1;
}
if ($match == 0)
{
if (count($files) > 0)
{
$editfile = $files[0];
}
else
{
$editfile = "";
}
}
}
*/


$extension = substr(strrchr($editfile, "."), 1);
$highlighter = 'html';
if ($extension == 'css' || $extension == 'js')
{
$highlighter = $extension;
}



$extension = substr(strrchr($sEditfile, "."), 1);
$highlighter = 'html';
if ($extension == 'css' || $extension == 'js'){
$highlighter = $extension;
}

$aData['codelanguage'] = $sLanguageCode;
$aData['highlighter'] = $highlighter;
$aData['screens'] = $screens;
$aData['templatename'] = $templatename;
$aData['templateapiversion'] = $oEditedTemplate->getApiVersion();
$aData['templates'] = $aAllTemplates;
$aData['editfile'] = $editfile;
$aData['editfile'] = $sEditfile;
$aData['screenname'] = $screenname;
$aData['tempdir'] = Yii::app()->getConfig('tempdir');
$aData['usertemplaterootdir'] = Yii::app()->getConfig('usertemplaterootdir');
Expand All @@ -1237,8 +1167,9 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
if ($showsummary)
{
//$aCssfileseditable = (array) $oEditedTemplate->config->files_editable->css->filename;
$aViewUrls = array_merge($aViewUrls, $this->_templatesummary($templatename, $screenname, $editfile, $aAllTemplates, $files, $cssfiles, $jsfiles, $otherfiles, $myoutput));
$aViewUrls = array_merge($aViewUrls, $this->_templatesummary($templatename, $screenname, $sEditfile, $editfile, $aAllTemplates, $files, $cssfiles, $jsfiles, $otherfiles, $myoutput));
}

App()->getClientScript()->registerScriptFile( App()->getConfig('adminscripts') . 'admin_core.js');
return $aViewUrls;
}
Expand Down

0 comments on commit 068201d

Please sign in to comment.