From de95f90b2829714328ee583af073ef1b59ca58f5 Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Fri, 10 Apr 2015 16:00:50 +0200 Subject: [PATCH] Fixed issue #08028: File upload dialogue window can't be styled Dev: except the table in "question" part all is done by css Dev: fix some HTML and javascript --- .../controllers/UploaderController.php | 33 ++- application/helpers/qanda_helper.php | 42 ++-- scripts/modaldialog.js | 77 ++++--- scripts/uploader.js | 208 ++++++++++-------- .../img/upload-delete.png | Bin .../img/upload-edit.png | Bin .../img/upload-error.png | Bin .../img/upload-placeholder.png | Bin .../img/upload-success.png | Bin styles-public/uploader-files.css | 44 ++++ styles-public/uploader.css | 76 +++++-- 11 files changed, 297 insertions(+), 183 deletions(-) rename images/delete.png => styles-public/img/upload-delete.png (100%) rename images/edit.png => styles-public/img/upload-edit.png (100%) rename images/error_notice.png => styles-public/img/upload-error.png (100%) rename images/placeholder.png => styles-public/img/upload-placeholder.png (100%) rename images/success_notice.png => styles-public/img/upload-success.png (100%) create mode 100644 styles-public/uploader-files.css diff --git a/application/controllers/UploaderController.php b/application/controllers/UploaderController.php index a455d56081e..ec35d0d63ce 100644 --- a/application/controllers/UploaderController.php +++ b/application/controllers/UploaderController.php @@ -15,23 +15,14 @@ class UploaderController extends SurveyController { function run($actionID) { - if(isset($_SESSION['LEMsid']) && $oSurvey=Survey::model()->findByPk($_SESSION['LEMsid'])){ - $surveyid= $_SESSION['LEMsid']; - }else{ + $surveyid=Yii::app()->session['LEMsid']; + $oSurvey=Survey::model()->findByPk($surveyid); + if(!$oSurvey) throw new CHttpException(400);// See for debug > 1 - } - if (isset($_SESSION['survey_'.$surveyid]['s_lang'])) - { - $sLanguage = $_SESSION['survey_'.$surveyid]['s_lang']; - } - else - { - $sLanguage=''; - } + $sLanguage=isset(Yii::app()->session['survey_'.$surveyid]['s_lang']) ? Yii::app()->session['survey_'.$surveyid]['s_lang']: ""; $uploaddir = Yii::app()->getConfig("uploaddir"); $tempdir = Yii::app()->getConfig("tempdir"); - Yii::app()->loadHelper("database"); // Fill needed var @@ -45,8 +36,8 @@ function run($actionID) // Validate and filter and throw error if problems // Using 'futmp_'.randomChars(15).'_'.$pathinfo['extension'] for filename, then remove all other characters - $sFileGetContentFiltered=preg_replace('/[^a-z0-9_]/', '', $sFileGetContent); - $sFileNameFiltered = preg_replace('/[^a-z0-9_]/', '',$sFileName); + $sFileGetContentFiltered=preg_replace('/[^a-zA-Z0-9_]/', '', $sFileGetContent); + $sFileNameFiltered = preg_replace('/[^a-zA-Z0-9_]/', '',$sFileName); $sFieldNameFiltered=preg_replace('/[^X0-9]/', '', $sFieldName); if($sFileGetContent!=$sFileGetContentFiltered || $sFileName!=$sFileNameFiltered || $sFieldName!=$sFieldNameFiltered) {// If one seems to be a hack: Bad request @@ -149,13 +140,13 @@ function run($actionID) $valid_extensions_array = array_map('trim',$valid_extensions_array); $pathinfo = pathinfo($_FILES['uploadfile']['name']); - $ext = $pathinfo['extension']; + $ext = strtolower($pathinfo['extension']); $randfilename = 'futmp_'.randomChars(15).'_'.$pathinfo['extension']; $randfileloc = $sTempUploadDir . $randfilename; // check to see that this file type is allowed // it is also checked at the client side, but jst double checking - if (!in_array(strtolower($ext), $valid_extensions_array)) + if (!in_array($ext, $valid_extensions_array)) { $return = array( "success" => false, @@ -291,7 +282,7 @@ function run($actionID) showpopups="'.Yii::app()->getConfig("showpopups").'"; '; $sLangScriptVar=" - translt = { + uploadLang = { titleFld: '" . gT('Title','js') . "', commentFld: '" . gT('Comment','js') . "', errorNoMoreFiles: '" . gT('Sorry, no more files can be uploaded!','js') . "', @@ -302,7 +293,9 @@ function run($actionID) errorMoreAllowed: '" . gT('If you wish, you may upload %s more file(s); else you may return back to survey.','js') . "', errorMaxReached: '" . gT('The maximum number of files has been uploaded. You may return back to survey.','js') . "', errorTooMuch: '" . gT('The maximum number of files has been uploaded. You may return back to survey.','js') . "', - errorNeedMoreConfirm: '" . gT("You need to upload %s more files for this question.\nAre you sure you want to exit?",'js') . "' + errorNeedMoreConfirm: '" . gT("You need to upload %s more files for this question.\nAre you sure you want to exit?",'js') . "', + deleteFile : '".gt('Delete','js') . "', + editFile : '".gt('Edit','js') . "', }; "; $aSurveyInfo=getSurveyInfo($surveyid, $sLanguage); @@ -321,6 +314,8 @@ function run($actionID) App()->getClientScript()->registerScriptFile(Yii::app()->getConfig("generalscripts").'uploader.js'); App()->getClientScript()->registerScriptFile("{$sTemplateUrl}template.js"); App()->clientScript->registerCssFile(Yii::app()->getConfig("publicstyleurl")."uploader.css"); + App()->getClientScript()->registerCssFile(Yii::app()->getConfig('publicstyleurl') . "uploader-files.css"); + if (file_exists($sTemplateDir .DIRECTORY_SEPARATOR.'jquery-ui-custom.css')) { Yii::app()->getClientScript()->registerCssFile("{$sTemplateUrl}jquery-ui-custom.css"); diff --git a/application/helpers/qanda_helper.php b/application/helpers/qanda_helper.php index c969a14498d..a3d0301404c 100644 --- a/application/helpers/qanda_helper.php +++ b/application/helpers/qanda_helper.php @@ -2734,8 +2734,6 @@ function do_file_upload($ia) { global $thissurvey; - - $checkconditionFunction = "checkconditions"; $aQuestionAttributes=getQuestionAttributeValues($ia[0]); @@ -2743,52 +2741,53 @@ function do_file_upload($ia) // Fetch question attributes $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['fieldname'] = $ia[1]; - $currentdir = getcwd(); - $pos = stripos($currentdir, "admin"); $scriptloc = Yii::app()->getController()->createUrl('uploader/index'); + $bPreview=Yii::app()->request->getParam('action')=="previewgroup" || Yii::app()->request->getParam('action')=="previewquestion" || $thissurvey['active'] != "Y"; - if ($pos) + if ($bPreview) { $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['preview'] = 1 ; $questgrppreview = 1; // Preview is launched from Question or group level } - else if ($thissurvey['active'] != "Y") - { - $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['preview'] = 1; - $questgrppreview = 0; - } - else - { - $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['preview'] = 0; - $questgrppreview = 0; + elseif ($thissurvey['active'] != "Y") + { + $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['preview'] = 1; + $questgrppreview = 0; + } + else + { + $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['preview'] = 0; + $questgrppreview = 0; } - $uploadbutton = "

"; + $uploadbutton .=">" .gT('Upload files'). ""; $answer = "\n"; Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."modaldialog.js"); - + Yii::app()->getClientScript()->registerCssFile(Yii::app()->getConfig('publicstyleurl') . "uploader-files.css"); // Modal dialog $answer .= $uploadbutton; @@ -2821,8 +2820,7 @@ function upload_$ia[1]() { var json = $("#"+fieldname).val(); var show_title = "'.$aQuestionAttributes["show_title"].'"; var show_comment = "'.$aQuestionAttributes["show_comment"].'"; - var pos = "'.($pos ? 1 : 0).'"; - displayUploadedFiles(json, filecount, fieldname, show_title, show_comment, pos); + displayUploadedFiles(json, filecount, fieldname, show_title, show_comment); }); '; diff --git a/scripts/modaldialog.js b/scripts/modaldialog.js index 6235cb212e6..be0ab49f3a4 100644 --- a/scripts/modaldialog.js +++ b/scripts/modaldialog.js @@ -1,35 +1,38 @@ $(function() { openUploadModalDialog(); }); - function openUploadModalDialog(){ + $(document).on('click','.upload-edit',function(){ + var fieldname=$(this).data('fieldname'); + $('#upload_'+fieldname).click(); + }); + $('.upload').click(function(e) { e.preventDefault(); var $this = $(this); - var show_title = getQueryVariable('show_title', this.href); var show_comment = getQueryVariable('show_comment', this.href); var pos = getQueryVariable('pos', this.href); var fieldname = getQueryVariable('fieldname', this.href); var buttonsOpts = {}; - buttonsOpts[translt.returnTxt] = function() { + buttonsOpts[uploadLang.returnTxt] = function() { $(this).dialog("close"); }; - // Get the dialogheigth and width from windows (with some maximum: same than old behaviour (why 440 ?) var windowwidth = $(window).width()-30; - var windowheight = $(window).height()-30; var dialogwidth= Math.min(windowwidth, 940); - var dialogheight= Math.min(windowheight, 440); $('#uploader').dialog('destroy').remove(); // destroy the old modal dialog $('