Skip to content

Commit

Permalink
merged with dev
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-pranav committed Oct 3, 2024
2 parents 2be5062 + 978d31b commit e3cb05d
Show file tree
Hide file tree
Showing 16 changed files with 229 additions and 93 deletions.
1 change: 1 addition & 0 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3773,6 +3773,7 @@ var import_button;
})
.done(function (results) {
if (results.status) {
jQuery(document).trigger('qsm_after_save_results');
QSMAdmin.displayAlert(qsm_admin_messages.results_page_saved, 'success');
} else {
QSMAdmin.displayAlert( qsm_admin_messages.results_page_save_error + ' ' + qsm_admin_messages.results_page_saved, 'error');
Expand Down
4 changes: 2 additions & 2 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ var qsmTimerInterval = [];
// Calculates starting time.
var timerTotal = parseFloat(qmn_quiz_data[quizID].timer_limit) * 60;
var timerStarted = localStorage.getItem('mlw_started_quiz' + quizID);
var timerConsumed = parseInt(localStorage.getItem('mlw_time_consumed_quiz' + quizID));
var timerConsumed = parseInt(localStorage.getItem('mlw_time_consumed_quiz' + quizID)) || 1;
var timerRemaning = timerTotal - timerConsumed;
if ('yes' == timerStarted && 0 < timerRemaning) {
seconds = parseInt(timerRemaning);
Expand Down Expand Up @@ -357,7 +357,7 @@ var qsmTimerInterval = [];

// Calculates starting time.
let timerStarted = localStorage.getItem('mlw_started_quiz' + quizID);
let timerConsumed = parseInt(localStorage.getItem('mlw_time_consumed_quiz' + quizID));
let timerConsumed = parseInt(localStorage.getItem('mlw_time_consumed_quiz' + quizID)) || 1;
let seconds = parseFloat(qmn_quiz_data[quizID].timer_limit) * 60;
let timerRemaning = seconds - timerConsumed;
if ('yes' == timerStarted && 0 < timerRemaning) {
Expand Down
154 changes: 127 additions & 27 deletions mlw_quizmaster2.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ private function load_dependencies() {
* @return void
*/
private function add_hooks() {
add_action( 'admin_menu', array( $this, 'qsm_add_user_capabilities' ) );
add_action( 'admin_menu', array( $this, 'setup_admin_menu' ) );
add_action( 'admin_head', array( $this, 'admin_head' ), 900 );
add_action( 'init', array( $this, 'register_quiz_post_types' ) );
Expand Down Expand Up @@ -652,6 +653,26 @@ public function register_quiz_post_types() {
'rewrite' => array( 'slug' => $cpt_slug ),
'has_archive' => $has_archive,
'supports' => array( 'title', 'author', 'comments', 'thumbnail' ),
'capability_type' => array( 'qsm_quiz', 'qsm_quizzes' ),
'map_meta_cap' => true,
);
$quiz_args['capabilities'] = array(
'edit_post' => 'edit_qsm_quiz',
'edit_post' => 'duplicate_qsm_quiz',
'read_post' => 'read_qsm_quiz',
'delete_post' => 'delete_qsm_quiz',
'edit_posts' => 'edit_qsm_quizzes',
'edit_others_posts' => 'edit_others_qsm_quizzes',
'publish_posts' => 'publish_qsm_quizzes',
'read_private_posts' => 'read_private_qsm_quizzes',
'delete_posts' => 'delete_qsm_quizzes',
'delete_private_posts' => 'delete_private_qsm_quizzes',
'delete_published_posts' => 'delete_published_qsm_quizzes',
'delete_others_posts' => 'delete_others_qsm_quizzes',
'edit_private_posts' => 'edit_private_qsm_quizzes',
'edit_published_posts' => 'edit_published_qsm_quizzes',
'create_posts' => 'create_qsm_quizzes',
'moderate_comments' => 'view_qsm_quiz_result',
);

// Registers post type.
Expand Down Expand Up @@ -682,10 +703,88 @@ public function register_quiz_post_types() {
'show_in_rest' => true,
'show_tagcloud' => false,
'rewrite' => false,
'capabilities' => array(
'manage_terms' => 'manage_qsm_quiz_categories',
'edit_terms' => 'edit_qsm_quiz_categories',
'delete_terms' => 'delete_qsm_quiz_categories',
'assign_terms' => 'assign_qsm_quiz_categories',
),
);
register_taxonomy( 'qsm_category', array( 'qsm-taxonomy' ), $taxonomy_args );
}

public function qsm_add_user_capabilities() {
$administrator_capabilities = array(
'duplicate_qsm_quiz',
'delete_qsm_quiz',
'edit_others_qsm_quizzes',
'publish_qsm_quizzes',
'read_private_qsm_quizzes',
'delete_qsm_quizzes',
'delete_private_qsm_quizzes',
'delete_published_qsm_quizzes',
'delete_others_qsm_quizzes',
'edit_private_qsm_quizzes',
'edit_published_qsm_quizzes',
'manage_qsm_quiz_categories',
'manage_qsm_quiz_answer_label',
'view_qsm_quiz_result',
'edit_qsm_quiz_categories',
'assign_qsm_quiz_categories',
'delete_qsm_quiz_categories',
);
$editor_capabilities = array(
'publish_qsm_quizzes',
'edit_published_qsm_quizzes',
'edit_others_qsm_quizzes',
'delete_published_qsm_quizzes',
'delete_qsm_quiz',
'delete_qsm_quizzes',
'manage_qsm_quiz_categories',
'manage_qsm_quiz_answer_label',
'view_qsm_quiz_result',
'edit_qsm_quiz_categories',
'assign_qsm_quiz_categories',
);
$author_capabilities = array(
'edit_published_qsm_quizzes',
'publish_qsm_quizzes',
);
$contributor_capabilities = array(
'read_qsm_quiz',
'edit_qsm_quiz',
'edit_qsm_quizzes',
'create_qsm_quizzes',
);

$user = wp_get_current_user();
$roles = (array) $user->roles;
$rolename = $roles[0];

$role = get_role( $rolename );

// Remove all capabilities first.
foreach ( $administrator_capabilities as $cap ) {
if ( $role->has_cap( $cap ) ) {
$role->remove_cap( $cap );
}
}

// Dynamically determine the capabilities to add based on the current user role.
$capabilities_to_add = isset(${$rolename . '_capabilities'}) ? ${$rolename . '_capabilities'} : array();
$capabilities_to_add = apply_filters(
'qsm_default_user_capabilities',
isset(${$rolename . '_capabilities'}) ? array_unique( array_merge( $capabilities_to_add, $contributor_capabilities ) ) : [],
$user
);

if ( isset( $capabilities_to_add ) ) {
foreach ( $capabilities_to_add as $cap ) {
$role->add_cap( $cap );
}
}
}

public function parent_file( $file_name ) {
global $menu, $submenu, $parent_file, $submenu_file;
if ( 'edit-tags.php?taxonomy=qsm_category' === $submenu_file ) {
Expand Down Expand Up @@ -729,44 +828,45 @@ public function setup_admin_menu() {
$enabled = get_option( 'qsm_multiple_category_enabled' );
$menu_position = self::get_free_menu_position(26.1, 0.3);
$settings = (array) get_option( 'qmn-settings' );
if ( ! class_exists('QSM_Ultimate') ) {
$user = wp_get_current_user();
if ( in_array( 'subscriber', (array) $user->roles, true ) ) {
$role_capabilities = get_role( 'subscriber' );
$role_capabilities->remove_cap('edit_posts');
$role_capabilities->remove_cap('moderate_comments');
}
}
else {
apply_filters('qsm_user_role_menu_for_subcriber',true);
}
$qsm_dashboard_page = add_menu_page( 'Quiz And Survey Master', __( 'QSM', 'quiz-master-next' ), 'edit_posts', 'qsm_dashboard', 'qsm_generate_dashboard_page', 'dashicons-feedback', $menu_position );
add_submenu_page( 'qsm_dashboard', __( 'Dashboard', 'quiz-master-next' ), __( 'Dashboard', 'quiz-master-next' ), 'edit_posts', 'qsm_dashboard', 'qsm_generate_dashboard_page', 0 );

apply_filters('qsm_user_role_menu_for_subscriber', true);

$capabilities = array(
'delete_published_qsm_quizzes',
'create_qsm_quizzes',
'delete_others_qsm_quizzes',
'manage_qsm_quiz_categories',
'manage_qsm_quiz_answer_label',
'view_qsm_quiz_result',
);

add_menu_page( 'Quiz And Survey Master', __( 'QSM', 'quiz-master-next' ), $capabilities[1], 'qsm_dashboard', 'qsm_generate_dashboard_page', 'dashicons-feedback', $menu_position );
add_submenu_page( 'qsm_dashboard', __( 'Dashboard', 'quiz-master-next' ), __( 'Dashboard', 'quiz-master-next' ), $capabilities[2], 'qsm_dashboard', 'qsm_generate_dashboard_page', 0 );
if ( $enabled && 'cancelled' !== $enabled ) {
$qsm_taxonomy_menu_hook = add_submenu_page( 'qsm_dashboard', __( 'Question Categories', 'quiz-master-next' ), __( 'Question Categories', 'quiz-master-next' ), 'edit_posts', 'edit-tags.php?taxonomy=qsm_category' );
add_submenu_page( 'qsm_dashboard', __( 'Question Categories', 'quiz-master-next' ), __( 'Question Categories', 'quiz-master-next' ), $capabilities[3], 'edit-tags.php?taxonomy=qsm_category' );
}
if ( ! class_exists( 'QSM_Advanced_Assessment' ) ) {
add_submenu_page( 'qsm_dashboard', __( 'Answer Labels', 'quiz-master-next' ), __( 'Answer Labels', 'quiz-master-next' ), 'manage_options', 'qsm-answer-label', 'qsm_advanced_assessment_quiz_page_content', 3 );
add_submenu_page( 'qsm_dashboard', __( 'Answer Labels', 'quiz-master-next' ), __( 'Answer Labels', 'quiz-master-next' ), $capabilities[4], 'qsm-answer-label', 'qsm_advanced_assessment_quiz_page_content', 3 );
}
add_submenu_page( 'options.php', __( 'Settings', 'quiz-master-next' ), __( 'Settings', 'quiz-master-next' ), 'edit_posts', 'mlw_quiz_options', 'qsm_generate_quiz_options' );
add_submenu_page( 'qsm_dashboard', __( 'Results', 'quiz-master-next' ), __( 'Results', 'quiz-master-next' ), 'moderate_comments', 'mlw_quiz_results', 'qsm_generate_admin_results_page' );
add_submenu_page( 'options.php', __( 'Settings', 'quiz-master-next' ), __( 'Settings', 'quiz-master-next' ), $capabilities[1], 'mlw_quiz_options', 'qsm_generate_quiz_options' );
add_submenu_page( 'qsm_dashboard', __( 'Results', 'quiz-master-next' ), __( 'Results', 'quiz-master-next' ), $capabilities[5], 'mlw_quiz_results', 'qsm_generate_admin_results_page' );

// Failed Submission.
if ( ! empty( $settings['enable_qsm_log'] ) && $settings['enable_qsm_log'] ) {
add_submenu_page( 'qsm_dashboard', __( 'Failed Submission', 'quiz-master-next' ), __( 'Failed Submission', 'quiz-master-next' ), 'moderate_comments', 'qsm-quiz-failed-submission', array( $this, 'admin_failed_submission_page' ) );
add_submenu_page( 'qsm_dashboard', __( 'Failed Submission', 'quiz-master-next' ), __( 'Failed Submission', 'quiz-master-next' ), $capabilities[2], 'qsm-quiz-failed-submission', array( $this, 'admin_failed_submission_page' ) );
}
// Failed DB Query
if ( ! empty( $settings['enable_qsm_log'] ) && $settings['enable_qsm_log'] && $this->get_failed_alter_table_queries() ) {
add_submenu_page( 'qsm_dashboard', __( 'Failed DB Queries', 'quiz-master-next' ), __( 'Failed Database Queries', 'quiz-master-next' ), 'moderate_comments', 'qsm-database-failed-queries', array( $this, 'qsm_database_failed_queries' ) );
add_submenu_page( 'qsm_dashboard', __( 'Failed DB Queries', 'quiz-master-next' ), __( 'Failed Database Queries', 'quiz-master-next' ), $capabilities[2], 'qsm-database-failed-queries', array( $this, 'qsm_database_failed_queries' ) );
}
add_submenu_page( 'options.php', __( 'Result Details', 'quiz-master-next' ), __( 'Result Details', 'quiz-master-next' ), 'moderate_comments', 'qsm_quiz_result_details', 'qsm_generate_result_details' );
add_submenu_page( 'qsm_dashboard', __( 'Settings', 'quiz-master-next' ), __( 'Settings', 'quiz-master-next' ), 'manage_options', 'qmn_global_settings', array( 'QMNGlobalSettingsPage', 'display_page' ) );
add_submenu_page( 'qsm_dashboard', __( 'Tools', 'quiz-master-next' ), __( 'Tools', 'quiz-master-next' ), 'manage_options', 'qsm_quiz_tools', 'qsm_generate_quiz_tools' );
add_submenu_page( 'qsm_dashboard', __( 'Stats', 'quiz-master-next' ), __( 'Stats', 'quiz-master-next' ), 'moderate_comments', 'qmn_stats', 'qmn_generate_stats_page' );
add_submenu_page( 'qsm_dashboard', __( 'About', 'quiz-master-next' ), __( 'About', 'quiz-master-next' ), 'moderate_comments', 'qsm_quiz_about', 'qsm_generate_about_page' );

add_submenu_page( 'qsm_dashboard', __( 'Extensions Settings', 'quiz-master-next' ), '<span style="color:#f39c12;">' . __( 'Extensions', 'quiz-master-next' ) . '</span>', 'moderate_comments', 'qmn_addons', 'qmn_addons_page', 34 );
add_submenu_page( 'qsm_dashboard', __( 'Free Add-ons', 'quiz-master-next' ), '<span style="color:#f39c12;">' . esc_html__( 'Free Add-ons', 'quiz-master-next' ) . '</span>', 'moderate_comments', 'qsm-free-addon', 'qsm_display_optin_page', 90 );
add_submenu_page( 'options.php', __( 'Result Details', 'quiz-master-next' ), __( 'Result Details', 'quiz-master-next' ), $capabilities[5], 'qsm_quiz_result_details', 'qsm_generate_result_details' );
add_submenu_page( 'qsm_dashboard', __( 'Settings', 'quiz-master-next' ), __( 'Settings', 'quiz-master-next' ), $capabilities[2], 'qmn_global_settings', array( 'QMNGlobalSettingsPage', 'display_page' ) );
add_submenu_page( 'qsm_dashboard', __( 'Tools', 'quiz-master-next' ), __( 'Tools', 'quiz-master-next' ), $capabilities[2], 'qsm_quiz_tools', 'qsm_generate_quiz_tools' );
add_submenu_page( 'qsm_dashboard', __( 'Stats', 'quiz-master-next' ), __( 'Stats', 'quiz-master-next' ), $capabilities[2], 'qmn_stats', 'qmn_generate_stats_page' );
add_submenu_page( 'qsm_dashboard', __( 'About', 'quiz-master-next' ), __( 'About', 'quiz-master-next' ), $capabilities[2], 'qsm_quiz_about', 'qsm_generate_about_page' );

add_submenu_page( 'qsm_dashboard', __( 'Extensions Settings', 'quiz-master-next' ), '<span style="color:#f39c12;">' . __( 'Extensions', 'quiz-master-next' ) . '</span>', $capabilities[2], 'qmn_addons', 'qmn_addons_page', 34 );
add_submenu_page( 'qsm_dashboard', __( 'Free Add-ons', 'quiz-master-next' ), '<span style="color:#f39c12;">' . esc_html__( 'Free Add-ons', 'quiz-master-next' ) . '</span>', $capabilities[2], 'qsm-free-addon', 'qsm_display_optin_page', 90 );
// Register screen option for dashboard page
add_action( 'screen_settings', 'qsm_dashboard_screen_options', 10, 2 );
}
Expand Down
8 changes: 7 additions & 1 deletion php/admin/admin-results-details-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @since 4.4.0
*/
function qsm_generate_result_details() {
if ( ! current_user_can( 'moderate_comments' ) ) {
if ( ! current_user_can( 'view_qsm_quiz_result' ) ) {
return;
}
global $mlwQuizMasterNext;
Expand Down Expand Up @@ -69,6 +69,12 @@ function qsm_generate_results_details_tab() {
$quiz_id = intval( $results_data->quiz_id );
$mlwQuizMasterNext->pluginHelper->prepare_quiz( $quiz_id );

$quiz_post_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'quiz_id' AND meta_value = %d", $quiz_id ) );
$post_author = get_post_field( 'post_author', $quiz_post_id, true );
if ( ( ! current_user_can( 'view_qsm_quiz_result' ) || intval($post_author) != get_current_user_id()) && ! current_user_can( 'delete_others_qsm_quizzes' ) ) {
return;
}

//Get the data for comments
$quiz_options = $mlwQuizMasterNext->quiz_settings->get_setting( 'quiz_options');
$comments_enabled = $quiz_options['comment_section'];
Expand Down
17 changes: 15 additions & 2 deletions php/admin/admin-results-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
function qsm_generate_admin_results_page() {

// Makes sure user has the right privledges.
if ( ! current_user_can( 'moderate_comments' ) ) {
if ( ! current_user_can( 'view_qsm_quiz_result' ) ) {
return;
}

Expand Down Expand Up @@ -524,7 +524,20 @@ function qsm_results_overview_tab_content() {
?>
<tr>
<td><input type="checkbox" class="qmn_delete_checkbox" name="delete_results[]" value="<?php echo esc_attr( $quiz_infos[ $x ]->result_id ); ?>" /></td>
<td class="<?php echo apply_filters( 'qsm_results_quiz_name_class','', $quiz_infos[ $x ]->result_id ); ?>"><span style="font-size:16px;"><?php echo esc_html( $quiz_infos[ $x ]->quiz_name ); ?></span><div class="row-actions"><span style="color:green;font-size:16px;"><a href="admin.php?page=qsm_quiz_result_details&result_id=<?php echo esc_attr( $quiz_infos[ $x ]->result_id ); ?>"><?php esc_html_e( 'View Results', 'quiz-master-next' ); ?></a> | <a style="color: red;" class="delete_table_quiz_results_item" data-quiz-id="<?php echo esc_attr( $quiz_infos[ $x ]->result_id ); ?>" data-quiz-name="<?php echo esc_attr( $quiz_infos[ $x ]->quiz_name ); ?>" href='#'><?php esc_html_e( 'Delete', 'quiz-master-next' ); ?></a> | <a class="<?php echo esc_attr( $quiz_infos[ $x ]->proctor_report_class ); ?>" href='<?php echo esc_attr( $quiz_infos[ $x ]->proctor_report_link ); ?>'><?php esc_html_e( 'Proctor Reports', 'quiz-master-next' ); ?></a></span></div></td>
<td class="<?php echo apply_filters( 'qsm_results_quiz_name_class', '', $quiz_infos[ $x ]->result_id ); ?>">
<span style="font-size: 16px;"><?php echo esc_html( $quiz_infos[ $x ]->quiz_name ); ?></span>
<div class="row-actions">
<span style="color: green; font-size: 16px;">
<?php
if ( ( current_user_can( 'view_qsm_quiz_result' ) && $quiz_infos[ $x ]->user == get_current_user_id() ) || current_user_can( 'delete_others_qsm_quizzes' ) ) {
?>
<a href="admin.php?page=qsm_quiz_result_details&result_id=<?php echo esc_attr( $quiz_infos[ $x ]->result_id ); ?>"><?php esc_html_e( 'View Results', 'quiz-master-next' ); ?></a> |
<?php } ?>
<a style="color: red;" class="delete_table_quiz_results_item" data-quiz-id="<?php echo esc_attr( $quiz_infos[ $x ]->result_id ); ?>" data-quiz-name="<?php echo esc_attr( $quiz_infos[ $x ]->quiz_name ); ?>" href='#'><?php esc_html_e( 'Delete', 'quiz-master-next' ); ?></a> |
<a class="<?php echo esc_attr( $quiz_infos[ $x ]->proctor_report_class ); ?>" href='<?php echo esc_attr( $quiz_infos[ $x ]->proctor_report_link ); ?>'><?php esc_html_e( 'Proctor Reports', 'quiz-master-next' ); ?></a>
</span>
</div>
</td>
<?php
foreach ( $values as $k => $v ) {
if ( isset( $v['content'][ $x ] ) ) {
Expand Down
9 changes: 3 additions & 6 deletions php/admin/options-page-contact-tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ function qsm_options_contact_tab_content() {
</tr>
<tr valign="top">
<th scope="row" class="qsm-opt-tr">
<label for="loggedin_user_contact"><?php esc_html_e( 'Show contact form to logged in users', 'quiz-master-next' ); ?></label>
<label for="loggedin_user_contact"><?php esc_html_e( 'Hide contact form to logged in users', 'quiz-master-next' ); ?></label>
<span class="dashicons dashicons-editor-help qsm-tooltips-icon">
<span class="qsm-tooltips"><?php esc_html_e( 'The information will still get saved if this option is disabled', 'quiz-master-next' ); ?></span>
</span>
</th>
<td>
<fieldset class="buttonset buttonset-hide" data-hide="1">
<label for="loggedin_user_contact-0">
<input type="radio" id="loggedin_user_contact-0" name="loggedin_user_contact" value="1" <?php checked( $quiz_options['loggedin_user_contact'], '0', true )?>>
<input type="radio" id="loggedin_user_contact-1" name="loggedin_user_contact" value="1" <?php checked( $quiz_options['loggedin_user_contact'], '1', true )?>>
<?php esc_html_e( 'Yes', 'quiz-master-next' ); ?>
</label>
<label for="loggedin_user_contact-1">
<input type="radio" id="loggedin_user_contact-1" name="loggedin_user_contact" value="0" <?php checked( $quiz_options['loggedin_user_contact'], '1', true )?>>
<input type="radio" id="loggedin_user_contact-0" name="loggedin_user_contact" value="0" <?php checked( $quiz_options['loggedin_user_contact'], '0', true )?>>
<?php esc_html_e( 'No', 'quiz-master-next' ); ?>
</label>
</fieldset>
Expand Down Expand Up @@ -182,9 +182,6 @@ function qsm_contact_form_admin_ajax() {
foreach ( $settings as $key => $val ) {
$quiz_options[ $key ] = $val;
}
if ( isset($settings['loggedin_user_contact']) ) {
$quiz_options['loggedin_user_contact'] = (1 == $settings['loggedin_user_contact']) ? 0 : 1;
}
$mlwQuizMasterNext->pluginHelper->update_quiz_setting( 'quiz_options', $quiz_options );
}

Expand Down
Loading

0 comments on commit e3cb05d

Please sign in to comment.