Exemple #1
0
function dt_payment_save_settings($current)
{
    if (!empty($_POST) && check_admin_referer('dt_payment_settings', '_wpnonce')) {
        $payment_settings = array();
        $payment_settings = get_option('dt_settings');
        unset($_POST['_wpnonce']);
        unset($_POST['_wp_http_referer']);
        unset($_POST['dt_save']);
        switch ($current) {
            case 'dt_set_commission':
                $payment_settings['set-commission']['commission'][$_POST['dt-setcom-teacher']] = $_POST;
                break;
            case 'dt_pay_commission':
                $teacher_info = get_userdata($_POST['dt-paycom-teacher']);
                $teacher_name = $teacher_info->display_name;
                $title = __('Commissions / ' . $teacher_name . ' / ' . date('Y-m-d'), 'dt_themes');
                $items_all = dt_decode_array($_POST['item_data_all']);
                $selected_items = isset($_POST['item']) ? $_POST['item'] : '';
                $new_items = array();
                if ($selected_items != '') {
                    $j = 0;
                    foreach ($items_all as $key => $item) {
                        if (isset($selected_items[$j]) && $selected_items[$j] == 'true') {
                            $students = array_merge(get_users(array('role' => 's2member_level1')), get_users(array('role' => 's2member_level2')), get_users(array('role' => 's2member_level3')), get_users(array('role' => 's2member_level4')));
                            foreach ($students as $student) {
                                $new_ccaps = '';
                                $student_level = get_user_field("s2member_access_role", $student->data->ID);
                                if ($student_level == 's2member_level2' || $student_level == 's2member_level3' || $student_level == 's2member_level4') {
                                    $all_ccaps = dt_get_all_paid_courses();
                                } else {
                                    $student_cap = get_user_field("s2member_access_ccaps", $student->data->ID);
                                    $all_ccaps = dt_remove_cid($student_cap);
                                }
                                if (in_array($item['course_id'], $all_ccaps)) {
                                    $prev_ccaps = get_user_meta($student->data->ID, 'commission_ccaps', true);
                                    $prev_ccaps = isset($prev_ccaps) ? $prev_ccaps : '';
                                    if ($prev_ccaps != '') {
                                        $new_ccaps = $prev_ccaps . ',' . $item['course_id'];
                                    } else {
                                        $new_ccaps = $item['course_id'];
                                    }
                                    update_user_meta($student->data->ID, 'commission_ccaps', $new_ccaps);
                                }
                            }
                            $new_items[] = $item;
                        }
                        $j++;
                    }
                    $payment_post = array('post_title' => $title, 'post_status' => 'publish', 'post_type' => 'dt_payments');
                    $payment_post_id = wp_insert_post($payment_post);
                    update_post_meta($payment_post_id, 'payment-data', $new_items);
                }
                break;
        }
        update_option('dt_settings', $payment_settings);
    }
}
        </ul>
    </div>
	<div class="column dt-sc-four-fifth dt-sc-user-dashboard-details">
    	
    	<?php 
if ($user_role == 's2member_level1' || $user_role == 's2member_level2' || $user_role == 's2member_level3' || $user_role == 's2member_level4') {
    $ccaps = array();
    if ($user_role == 's2member_level1') {
        foreach ($user_info->allcaps as $cap => $cap_enabled) {
            if (preg_match("/^access_s2member_ccap_cid_/", $cap)) {
                $ccaps[] = preg_replace("/^access_s2member_ccap_cid_/", "", $cap);
            }
        }
    } else {
        if ($user_role == 's2member_level2' || $user_role == 's2member_level3' || $user_role == 's2member_level4') {
            $ccaps = dt_get_all_paid_courses();
        }
    }
    if ($dt_type == 'home') {
        ?>
            
               <div>
                <div class="dt-sc-hr-invisible-small"></div>
                	
                    <h4 class="border-title"> <?php 
        echo __('Perfil', 'dt_themes');
        ?>
 <span> </span> </h4>
                    <ul class="teachers-details">
                        <li><strong><?php 
        echo __('Usuario : ', 'dt_themes');
Exemple #3
0
function dt_get_user_course_overview($post_per_page, $curr_page)
{
    $user_id = get_current_user_id();
    $user_info = get_userdata($user_id);
    $ccaps = array();
    if (IAMD_USER_ROLE == 's2member_level1') {
        foreach ($user_info->allcaps as $cap => $cap_enabled) {
            if (preg_match("/^access_s2member_ccap_cid_/", $cap)) {
                $ccaps[] = preg_replace("/^access_s2member_ccap_cid_/", "", $cap);
            }
        }
    } else {
        if (IAMD_USER_ROLE == 's2member_level2' || IAMD_USER_ROLE == 's2member_level3' || IAMD_USER_ROLE == 's2member_level4') {
            $ccaps = dt_get_all_paid_courses();
        }
    }
    $dt_start = ($curr_page - 1) * $post_per_page;
    $dt_end = $dt_start + $post_per_page;
    $courses_cnt = count($ccaps);
    $course_ids_arr = dt_get_user_graded_course();
    $free_course = array_diff($course_ids_arr, $ccaps);
    $ccaps = array_merge($ccaps, $free_course);
    if (isset($ccaps) && is_array($ccaps)) {
        echo '<table border="0" cellpadding="0" cellspacing="10" style="width:100%;">
				<thead>
				  <tr>
					<th scope="col">' . __('#', 'dt_themes') . '</th>
					<th scope="col" class="dt-sc-align-left">' . __('Course', 'dt_themes') . '</th>
					<th scope="col" class="dt-sc-align-left">' . __('Lesson', 'dt_themes') . '</th>
					<th scope="col">' . __('Grade', 'dt_themes') . '</th>
					<th scope="col">' . __('Status', 'dt_themes') . '</th>
					<th scope="col">' . __('Option', 'dt_themes') . '</th>
				  </tr>
				</thead>
				<tbody>';
        $i = 0;
        foreach ($ccaps as $course_id) {
            if ($i >= $dt_start && $i < $dt_end) {
                $course_args = array('post_type' => 'dt_courses', 'p' => $course_id);
                $course = get_posts($course_args);
                $course_status = dt_get_users_course_status($course_id, '');
                if ($course_status) {
                    $course_overall_status = '<div class="dt-sc-course-completed"> <span class="fa fa-check-circle"></span>' . __('Completed', 'dt_themes') . '</div>';
                    $course_percent = dt_get_course_percentage($course_id, '') . '%';
                } else {
                    $course_overall_status = '<div class="dt-sc-course-pending"> <span class="fa fa-clock-o fa-rotate-90"></span>' . __('Pending', 'dt_themes') . '</div>';
                    $course_percent = '';
                }
                $starting_price = dttheme_wp_kses(get_post_meta($course_id, 'starting-price', true));
                if (in_array($course_id, $free_course) & $starting_price != '') {
                    $notyet_text = ' <span class="dt-sc-not-purchased">(' . __('Not yet purchased', 'dt_themes') . ')</span>';
                } elseif (in_array($course_id, $free_course) & $starting_price == '') {
                    $notyet_text = ' <span class="dt-sc-not-purchased">(' . __('Free', 'dt_themes') . ')</span>';
                } else {
                    $notyet_text = '';
                }
                echo '<tr>
						<td>' . ($i + 1) . '</td>
						<td class="dt-sc-course-name"><a href="' . get_permalink($course_id) . '">' . $course[0]->post_title . '</a>' . $notyet_text . '</td>
						<td>&nbsp;</td>
						<td>' . $course_percent . '</td>
						<td>' . $course_overall_status . '</td>
						<td>&nbsp;</td>
					</tr>';
                $lesson_args = array('sort_order' => 'ASC', 'sort_column' => 'menu_order', 'post_type' => 'dt_lessons', 'posts_per_page' => -1, 'meta_key' => 'dt_lesson_course', 'meta_value' => $course_id);
                $lessons_array = get_posts($lesson_args);
                foreach ($lessons_array as $lesson) {
                    $user_option = '';
                    $lesson_id = $lesson->ID;
                    $quiz_id = get_post_meta($lesson_id, "lesson-quiz", true);
                    if (!isset($quiz_id) || $quiz_id == '') {
                        $quiz_id = -1;
                    }
                    $dt_gradings = dt_get_user_gradings_array($course_id, $lesson_id, $quiz_id, $user_id);
                    $dt_grade_post = get_posts($dt_gradings);
                    if (isset($dt_grade_post[0])) {
                        $dt_grade_post_id = $dt_grade_post[0]->ID;
                        $graded = get_post_meta($dt_grade_post_id, "graded", true);
                        if (isset($graded) && $graded != '') {
                            $user_status = '<div class="dt-sc-course-completed"> <span class="fa fa-check-circle"></span>' . __('Completed', 'dt_themes') . '</div>';
                            if ($quiz_id != -1 && $quiz_id != '') {
                                $user_option = '<a href="' . get_permalink($quiz_id) . '?dttype=viewquiz" class="dt-sc-button small">' . __('View Quiz', 'dt_themes') . '</a>';
                            }
                            $grade = get_post_meta($dt_grade_post_id, "marks-obtained-percent", true);
                            $grade = $grade . '%';
                        } else {
                            $grade = '';
                            $user_status = '<div class="dt-sc-course-notgraded"> <span class="fa fa-trophy"></span>' . __('Not yet graded', 'dt_themes') . '</div>';
                            if (dt_can_user_retake_quiz($course_id, $lesson_id, $quiz_id, $user_id)) {
                                $user_option = '<a href="' . get_permalink($quiz_id) . '" class="dt-sc-button small">' . __('Retake Quiz', 'dt_themes') . '</a>';
                            }
                        }
                    } else {
                        $grade = '';
                        $user_status = '<div class="dt-sc-course-pending"> <span class="fa fa-clock-o fa-rotate-90"></span>' . __('Pending', 'dt_themes') . '</div>';
                        if (isset($quiz_id) && $quiz_id > 0) {
                            $user_option = '<a href="' . get_permalink($quiz_id) . '" class="dt-sc-button small">' . __('Take Quiz', 'dt_themes') . '</a>';
                        }
                    }
                    echo '<tr>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
							<td class="dt-sc-lesson-name"><a href="' . get_permalink($lesson_id) . '">' . $lesson->post_title . '</a></td>
							<td class="dt-sc-grade-percent">' . $grade . '</td>
							<td>' . $user_status . '</td>
							<td>' . $user_option . '</td>
						</tr>';
                }
                $assignment_args = array('post_type' => 'dt_assignments', 'posts_per_page' => -1, 'meta_query' => array());
                $assignment_args['meta_query'][] = array('key' => 'dt-assignment-course', 'value' => $course_id, 'compare' => '=', 'type' => 'numeric');
                $assignment_array = get_posts($assignment_args);
                foreach ($assignment_array as $assignment) {
                    $assignment_id = $assignment->ID;
                    $dtgradings = array('post_type' => 'dt_gradings', 'meta_query' => array());
                    $dtgradings['meta_query'][] = array('key' => 'dt-user-id', 'value' => $user_id, 'compare' => '=', 'type' => 'numeric');
                    $dtgradings['meta_query'][] = array('key' => 'dt-course-id', 'value' => $course_id, 'compare' => '=', 'type' => 'numeric');
                    $dtgradings['meta_query'][] = array('key' => 'dt-assignment-id', 'value' => $assignment_id, 'compare' => '=', 'type' => 'numeric');
                    $dtgradings['meta_query'][] = array('key' => 'grade-type', 'value' => 'assignment', 'compare' => '=');
                    $dtgradings_post = get_posts($dtgradings);
                    if (isset($dtgradings_post) && !empty($dtgradings_post)) {
                        $dtgradings_id = $dtgradings_post[0]->ID;
                        $marks_obtained_percent = get_post_meta($dtgradings_id, "marks-obtained-percent", true);
                        $graded = get_post_meta($dtgradings_id, "graded", true);
                        if (isset($graded) && $graded != '') {
                            $user_status = '<div class="dt-sc-course-completed"> <span class="fa fa-check-circle"></span>' . __('Completed', 'dt_themes') . '</div>';
                            $grade = $marks_obtained_percent . '%';
                        } else {
                            $user_status = '<div class="dt-sc-course-notgraded"> <span class="fa fa-check-circle"></span>' . __('Not yet graded', 'dt_themes') . '</div>';
                            $grade = '';
                        }
                    } else {
                        $grade = '';
                        $user_status = '<div class="dt-sc-course-pending"> <span class="fa fa-clock-o fa-rotate-90"></span>' . __('Pending', 'dt_themes') . '</div>';
                    }
                    echo '<tr>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
							<td class="dt-sc-assignment-name"><a href="' . get_permalink($assignment_id) . '">' . get_the_title($assignment_id) . '</a></td>
							<td>' . $grade . '</td>
							<td>' . $user_status . '</td>
							<td><a href="' . get_permalink($assignment_id) . '" class="dt-sc-button small">' . __('View Assignment', 'dt_themes') . '</a></td>
						</tr>';
                }
            }
            $i++;
        }
        if ($i == 0) {
            echo '<tr><td colspan="6">' . __('You haven\'t purchased any course!', 'dt_themes') . '</td></tr>';
        }
        echo '</tbody></table>';
        echo dtthemes_ajax_pagination($post_per_page, $curr_page, $courses_cnt, 0);
    }
}
function dt_get_statistics_graph_data($graph_type = 'course', $include_zero_sales = 0, $selectedItems = '')
{
    $graph_title = $graph_data = $graph_data2 = '';
    if ($graph_type == 'course') {
        if (isset($selectedItems) && !empty($selectedItems)) {
            $course_args = array('include' => $selectedItems, 'posts_per_page' => -1, 'post_type' => 'dt_courses', 'orderby' => 'title', 'order' => 'ASC');
        } else {
            $course_args = array('posts_per_page' => -1, 'post_type' => 'dt_courses', 'orderby' => 'title', 'order' => 'ASC');
        }
        $courses = get_posts($course_args);
        if (isset($courses) && !empty($courses)) {
            $course_title = $courses_subscribed = array();
            foreach ($courses as $course) {
                $course_id = $course->ID;
                $student_cap = dt_get_course_capabilities_id($course_id);
                $subscription = count($student_cap);
                if ($include_zero_sales == 1 || $subscription > 0) {
                    $courses_subscribed[] = $subscription;
                    $course_title[] = '"' . $course->post_title . '"';
                }
            }
            $graph_title = implode(',', $course_title);
            $graph_data = implode(',', $courses_subscribed);
            echo '<h3>' . __('Courses Vs Subscriptions (sales)', 'dt_themes') . '</h3>';
            echo '<div class="dt-graph-marker">';
            echo '<div class="dt-graph-marker-box"> <div style="background-color:rgba(14,81,124,1); width:20px; height:20px;"></div></div> - ' . __('Total Subscribtions (Sales)', 'dt_themes');
            echo '</div>';
        }
    } else {
        if ($graph_type == 'teacher') {
            if (isset($selectedItems) && !empty($selectedItems)) {
                $teachers = get_users(array('include' => $selectedItems, 'role' => 'teacher'));
            } else {
                $teachers = get_users(array('role' => 'teacher'));
            }
            if (isset($teachers) && !empty($teachers)) {
                $teacher_names = $total_courses = $total_subscription = array();
                foreach ($teachers as $teacher) {
                    $teacher_id = $teacher->data->ID;
                    $teacher_name = $teacher->data->display_name;
                    $courses_args = array('post_type' => 'dt_courses', 'post_status' => 'publish', 'author' => $teacher_id);
                    $courses = get_posts($courses_args);
                    $total_course = count($courses);
                    if ($include_zero_sales == 1 || $total_course > 0) {
                        $teacher_names[] = '"' . $teacher_name . '"';
                        $total_courses[] = $total_course;
                        $total_course_subscribed = 0;
                        if (isset($courses) && !empty($courses)) {
                            foreach ($courses as $course) {
                                $course_id = $course->ID;
                                $student_cap = dt_get_course_capabilities_id($course_id);
                                $course_subscribed = count($student_cap);
                                $total_course_subscribed = $total_course_subscribed + $course_subscribed;
                            }
                        }
                        $total_subscription[] = $total_course_subscribed;
                    }
                }
                $graph_title = implode(',', $teacher_names);
                $graph_data = implode(',', $total_courses);
                $graph_data2 = implode(',', $total_subscription);
                echo '<h3>' . __('Teachers Vs Courses Submitted and Courses Total Subscriptions', 'dt_themes') . '</h3>';
                echo '<div class="dt-graph-marker">';
                echo '<div class="dt-graph-marker-box"> <div style="background-color:rgba(14,81,124,1); width:20px; height:20px;"></div></div> - ' . __('Total Courses Submitted', 'dt_themes');
                echo '</div>';
                echo '<div class="dt-graph-marker">';
                echo '<div class="dt-graph-marker-box"> <div style="background-color:rgba(51,167,227,1); width:20px; height:20px;"></div></div> - ' . __('Total Subscribtions (Sales)', 'dt_themes');
                echo '</div>';
            }
        } else {
            if ($graph_type == 'student') {
                if (isset($selectedItems) && !empty($selectedItems)) {
                    $students = array_merge(get_users(array('include' => $selectedItems, 'role' => 's2member_level1')), get_users(array('include' => $selectedItems, 'role' => 's2member_level2')), get_users(array('include' => $selectedItems, 'role' => 's2member_level3')), get_users(array('include' => $selectedItems, 'role' => 's2member_level4')));
                } else {
                    $students = array_merge(get_users(array('role' => 's2member_level1')), get_users(array('role' => 's2member_level2')), get_users(array('role' => 's2member_level3')), get_users(array('role' => 's2member_level4')));
                }
                if (isset($students) && !empty($students)) {
                    $student_names = $total_courses = $courses_completed = array();
                    foreach ($students as $student) {
                        $student_id = $student->data->ID;
                        $student_name = $student->data->display_name;
                        $student_level = get_user_field("s2member_access_role", $student_id);
                        if ($student_level == 's2member_level2' || $student_level == 's2member_level3' || $student_level == 's2member_level4') {
                            $student_cap = dt_get_all_paid_courses();
                        } else {
                            $student_cap = get_user_field("s2member_access_ccaps", $student_id);
                        }
                        $total_course = count($student_cap);
                        $course_completed = dt_get_user_completed_course_count($student_id);
                        if ($include_zero_sales == 1 || $total_course > 0) {
                            $student_names[] = '"' . $student_name . '"';
                            $total_courses[] = $total_course;
                            $courses_completed[] = $course_completed;
                        }
                    }
                    $graph_title = implode(',', $student_names);
                    $graph_data = implode(',', $total_courses);
                    $graph_data2 = implode(',', $courses_completed);
                    echo '<h3>' . __('Students Vs Courses Subscribed and Courses Completed', 'dt_themes') . '</h3>';
                    echo '<div class="dt-graph-marker">';
                    echo '<div class="dt-graph-marker-box"> <div style="background-color:rgba(14,81,124,1); width:20px; height:20px;"></div></div> - ' . __('Total Courses Subscribed', 'dt_themes');
                    echo '</div>';
                    echo '<div class="dt-graph-marker">';
                    echo '<div class="dt-graph-marker-box"> <div style="background-color:rgba(51,167,227,1); width:20px; height:20px;"></div></div> - ' . __('Courses Completed', 'dt_themes');
                    echo '</div>';
                }
            }
        }
    }
    if ($graph_title != '') {
        echo '<div style="width: 90%; height:80%" class="dt-chart-container"><canvas id="dt-chart"></canvas></div>';
        echo '<script>
		
				var dtChartData = {
					labels : [' . $graph_title . '],
					datasets : [
						{
							fillColor : "rgba(14,81,124,1)",
							strokeColor : "rgba(1,65,109,1)",
							highlightFill: "rgba(1,65,109,1)",
							highlightStroke: "rgba(1,56,93,1)",
							data : [' . $graph_data . ']
						},';
        if ($graph_data2 != '') {
            echo ' {
							fillColor : "rgba(51,167,227,1)",
							strokeColor : "rgba(43,138,189,1)",
							highlightFill: "rgba(43,138,189,1)",
							highlightStroke: "rgba(40,129,176,1)",
							data : [' . $graph_data2 . ']
						}';
        }
        echo '		]
			
				}

				window.onload = function(){
					var dtChart = document.getElementById("dt-chart").getContext("2d");
					window.dtBar = new Chart(dtChart).Bar(dtChartData, {
							responsive : true,
						});
				}
				
			</script>';
    } else {
        echo 'NoData';
    }
}