From 53bac18dfed9e26603a66188105489e9b3c686d3 Mon Sep 17 00:00:00 2001 From: Vibina Date: Fri, 15 Sep 2023 17:16:01 +0530 Subject: [PATCH] file upload code missing --- css/common.css | 15 +++++++--- js/qsm-quiz.js | 1 + php/classes/class-qmn-quiz-manager.php | 30 +++++++++++++++++-- .../qsm-question-type-file-upload.php | 4 +-- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/css/common.css b/css/common.css index 22b6680c7..0cbe075d3 100644 --- a/css/common.css +++ b/css/common.css @@ -294,12 +294,19 @@ footer.qsm-popup__footer button.qsm-popup-secondary-button:hover { color: red; display: block; } - +.quiz_section .mlw-file-upload-error-msg.mlw-file-upload-success-msg { + color: green; + display: block; +} .quiz_section .remove-uploaded-file { color: red; - border: 1px solid red; - width: 31px; - padding: 5px 5px 0px 5px; + display: inline-block; + cursor: pointer; + margin-top: 5px; +} +.quiz_section .loading-uploaded-file { + width: 20px; + margin-bottom: -5px; } /** diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index 2781a93c7..c916ee201 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -1693,6 +1693,7 @@ jQuery(function () { $this.parent('.quiz_section').find('.mlw_file_upload_hidden_path').val(obj.file_path); $this.parent('.quiz_section').find('.mlw_file_upload_media_id').val(obj.media_id); $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').hide(); + $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').addClass('mlw-file-upload-success-msg').text(obj.message); $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').show(); } else { $this.parent('.quiz_section').find('.mlw-file-upload-error-msg').removeClass('mlw-file-upload-success-msg'); diff --git a/php/classes/class-qmn-quiz-manager.php b/php/classes/class-qmn-quiz-manager.php index 0a5aa6c11..354ffaef7 100644 --- a/php/classes/class-qmn-quiz-manager.php +++ b/php/classes/class-qmn-quiz-manager.php @@ -180,9 +180,33 @@ public function qsm_upload_image_fd_question() { echo wp_json_encode( $json ); } } else { - $json['type'] = 'error'; - $json['message'] = __( 'Incorrect File Type uploaded. Please upload the allowed file type!', 'quiz-master-next' ); - echo wp_json_encode( $json ); + if ( ! empty ($file_upload_type) ) { + $filestype = explode(',', $file_upload_type); + foreach ( $filestype as $file ) { + if ( strpos($file, '/') !== false ) { + $filetypes = explode('/', $file); + if ( ! empty($filetypes[0]) && 'application' == $filetypes[0] ) { + $filetypes_allowed[] = 'pdf'; + } else { + $filetypes_allowed[] = $filetypes[0]; + } + }else { + $filetypes_allowed[] = $file; + } + } + if ( count($filetypes_allowed) > 1 ) { + $files_allowed = implode(',', $filetypes_allowed); + } else { + $files_allowed = $filetypes_allowed[0]; // Just take the single element + } + $json['type'] = 'error'; + $json['message'] = __('File Upload Unsuccessful! (Please upload ', 'quiz-master-next') . $files_allowed . __(' file type)', 'quiz-master-next'); + echo wp_json_encode( $json ); + } else { + $json['type'] = 'error'; + $json['message'] = __( 'File Upload Unsuccessful! (Please select file type)', 'quiz-master-next' ); + echo wp_json_encode( $json ); + } } exit; } diff --git a/php/question-types/qsm-question-type-file-upload.php b/php/question-types/qsm-question-type-file-upload.php index 3c7fc98ba..6dcd9be0c 100644 --- a/php/question-types/qsm-question-type-file-upload.php +++ b/php/question-types/qsm-question-type-file-upload.php @@ -22,8 +22,8 @@ function qmn_file_upload_display( $id, $question, $answers ) { $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' ); qsm_question_title_func( $question, '', $new_question_title, $id ); ?>
- - + +