Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file upload code missing #2349

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
1 change: 1 addition & 0 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
30 changes: 27 additions & 3 deletions php/classes/class-qmn-quiz-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions php/question-types/qsm-question-type-file-upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
?> <div></div><input type="file" class="mlw_answer_file_upload <?php echo esc_attr( $mlw_require_class ); ?>"/>
<div style="display: none;" class="loading-uploaded-file"><img alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( get_site_url() . '/wp-includes/images/spinner-2x.gif' ); ?>"></div>
<div style="display: none;" class="remove-uploaded-file"><span class="dashicons dashicons-trash"></span></div>
<img style="display: none;" class="loading-uploaded-file" alt="<?php echo esc_attr( $new_question_title ); ?>" src="<?php echo esc_url( get_site_url() . '/wp-includes/images/spinner-2x.gif' ); ?>">
<span style="display: none;" class="dashicons dashicons-trash remove-uploaded-file"></span>
<span style="display: none;" class='mlw-file-upload-error-msg'></span>
<input class="mlw_file_upload_hidden_path" type="hidden" value="" />
<input class="mlw_file_upload_hidden_nonce" type="hidden" value="" />
Expand Down