function dt_pay_commission($teacher_id = '') { if ($teacher_id == '') { $teacher_id = $_REQUEST['teacher_id']; } $payment_settings = get_option('dt_settings'); $paycommission_settings = isset($payment_settings['pay-commission']) ? $payment_settings['pay-commission'] : array(); $setcommission_settings = isset($payment_settings['set-commission']) ? $payment_settings['set-commission'] : array(); $all_ccaps = dt_get_all_capabilities_id(); $out = ''; $out .= '<table border="0" cellpadding="0" cellspacing="20"> <thead> <tr> <th scope="col">' . __('#', 'dt_themes') . '</th> <th scope="col">' . __('Course', 'dt_themes') . '</th> <th scope="col">' . __('Purchases', 'dt_themes') . '</th> <th scope="col">' . __('Price', 'dt_themes') . '</th> <th scope="col">' . __('Commission (%)', 'dt_themes') . '</th> <th scope="col">' . sprintf(__('To Pay (%s)', 'dt_themes'), dttheme_wp_kses(dttheme_option('dt_course', 'currency'))) . '</th> <th scope="col">' . __('Mark As Paid', 'dt_themes') . '</th> </tr> </thead> <tbody>'; $course_args = array('post_type' => 'dt_courses', 'posts_per_page' => -1, 'author' => $teacher_id); $courses = get_posts($course_args); $pay_commission = array(); $i = 1; foreach ($courses as $course) { $course_id = $course->ID; $teacher_id = $course->post_author; $x = $i - 1; $starting_price = dttheme_wp_kses(get_post_meta($course_id, 'starting-price', true)); if (dttheme_option('dt_course', 'currency-position') == 'after-price') { $price = $starting_price . dttheme_wp_kses(dttheme_option('dt_course', 'currency')); } else { $price = dttheme_wp_kses(dttheme_option('dt_course', 'currency')) . $starting_price; } $purchases = dt_count_value($all_ccaps, $course_id); $commission = isset($setcommission_settings['commission'][$teacher_id]['course'][$course_id]) ? $setcommission_settings['commission'][$teacher_id]['course'][$course_id] : 0; $topay = $purchases * $starting_price * $commission / 100; $students_id = dt_get_course_capabilities_id($course_id); $pay_commission[$x]['course_id'] = $course_id; $pay_commission[$x]['teacher_id'] = $teacher_id; $pay_commission[$x]['students_id'] = $students_id; $pay_commission[$x]['starting_price'] = $starting_price; $pay_commission[$x]['purchases'] = $purchases; $pay_commission[$x]['commission'] = $commission; $pay_commission[$x]['topay'] = $topay; $out .= '<tr> <td>' . $i . '</td> <td>' . $course->post_title . '</td> <td>' . $purchases . '</td> <td>' . $price . '</td> <td>' . $commission . '</td> <td>' . $topay . '</td> <td>'; if ($topay != 0) { $out .= '<div data-for="item-' . $x . '" class="dt-paycom-checkbox-switch checkbox-switch-off"></div>'; $out .= '<input id="item-' . $x . '" class="hidden" type="checkbox" name="item[' . $x . ']" value="true" />'; $out .= '<input type="hidden" name="hid_topay" id="hid-topay-' . $x . '" value="' . $topay . '" />'; } $out .= '</td> </tr>'; $i++; } $out .= '</tbody></table>'; $out .= '<input type="hidden" name="item_data_all" value="' . dt_encode_array($pay_commission) . '" />'; $out .= '<div class="dt-amount-container">'; $out .= '<label><strong>' . sprintf(__('Total (%s)', 'dt_themes'), dttheme_wp_kses(dttheme_option('dt_course', 'currency'))) . '</strong></label><input type="text" name="total_amount" id="total-amount" value="0" readonly="readonly" />'; $out .= '</div>'; $out .= wp_nonce_field('dt_payment_settings', '_wpnonce'); $out .= '<input type="submit" name="dt_save" value="' . __('Save Settings', 'dt_themes') . '" class="dt-statistics-button" />'; echo $out; die; }
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'; } }