a123fb2f by Chris Boden

Course section

1 parent 468d4992
...@@ -150,6 +150,26 @@ jQuery(function($) { ...@@ -150,6 +150,26 @@ jQuery(function($) {
150 }; 150 };
151 jQuery('#edit-event-form').ajaxForm(options); 151 jQuery('#edit-event-form').ajaxForm(options);
152 }}); 152 }});
153
154 jQuery('.course-edit').colorbox({onComplete: function() {
155 var cb = this;
156 var options = {
157 beforeSubmit: function() {}
158 , success: function(data) {
159
160 if (data.refresh == "true") {
161 document.location.href = document.location.href;
162 } else {
163 jQuery.colorbox.close();
164 }
165
166 }
167 , data: ({ajax:"yes", action: 'course_registration'})
168 , dataType: 'json'
169 , url: '/wp-admin/admin-ajax.php'
170 };
171 jQuery('#edit-course-form').ajaxForm(options);
172 }});
153 173
154 jQuery('#admin_add_new_cehours').colorbox({onComplete: function() { 174 jQuery('#admin_add_new_cehours').colorbox({onComplete: function() {
155 jQuery('.datepicker').datePicker( 175 jQuery('.datepicker').datePicker(
......
...@@ -19,8 +19,8 @@ use Tz\WordPress\CBV\User; ...@@ -19,8 +19,8 @@ use Tz\WordPress\CBV\User;
19 use Tz\WordPress\CBV\Events; 19 use Tz\WordPress\CBV\Events;
20 use Tz\WordPress\CBV\CEHours; 20 use Tz\WordPress\CBV\CEHours;
21 use Tz\WordPress\CBV\Invoice; 21 use Tz\WordPress\CBV\Invoice;
22 use Tz\WordPress\CBV\Courses;
22 use Exception, StdClass; 23 use Exception, StdClass;
23 use WP_User;
24 24
25 const OPTION_NAME = "user_options"; 25 const OPTION_NAME = "user_options";
26 const CAPABILITY = "manage_cbv_users"; 26 const CAPABILITY = "manage_cbv_users";
...@@ -145,15 +145,11 @@ function get_users($role = null, $pagenum=1, $records_per_page=0, $return_count_ ...@@ -145,15 +145,11 @@ function get_users($role = null, $pagenum=1, $records_per_page=0, $return_count_
145 $limit = ""; 145 $limit = "";
146 } 146 }
147 147
148 $wp_user_search = $wpdb->get_results($query.$limit); 148 $wp_user_search = $wpdb->get_results($query . $limit);
149 149
150 foreach ( $wp_user_search as $user ) { 150 foreach ($wp_user_search as $user ) {
151 $uid = (int) $user->ID; 151 $user = new User\Account((int)$user->ID);
152 $user = new WP_User($uid); 152 $users[] = Array('uid' => $user->ID, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'role' => $user->getRole(), 'user_login' => $user->user_login, 'email' => $user->user_email, 'status' => $user->status, 'member_id' => $user->member_id);
153 reset($user->roles);
154 $role = ucwords(current($user->roles));
155 $member_id = get_user_meta($uid, 'member_id', true);
156 $users[] = array('uid'=>$uid,'first_name'=>$user->first_name,'last_name'=>$user->last_name,'role'=>$role, 'user_login'=>$user->user_login, 'email'=>$user->user_email, 'status'=>$user->status, 'member_id'=>$member_id);
157 } 153 }
158 return $users; 154 return $users;
159 } 155 }
...@@ -411,7 +407,7 @@ class AccountValidation extends Common\Validation { ...@@ -411,7 +407,7 @@ class AccountValidation extends Common\Validation {
411 } 407 }
412 408
413 public function user_role($val) { 409 public function user_role($val) {
414 $user = new WP_User($_POST['uid']); 410 $user = new User\Account($_POST['uid']);
415 try { 411 try {
416 $user->set_role($val); 412 $user->set_role($val);
417 } catch (Exception $e) { 413 } catch (Exception $e) {
...@@ -583,7 +579,7 @@ class Actions { ...@@ -583,7 +579,7 @@ class Actions {
583 try { 579 try {
584 $user_key = Auth\register($username, $email, $password, $user_details); 580 $user_key = Auth\register($username, $email, $password, $user_details);
585 $uid = Auth\activate($user_key, $password); 581 $uid = Auth\activate($user_key, $password);
586 $u = new WP_User($uid); 582 $u = new User\Account($uid);
587 $u->set_role($user_role); 583 $u->set_role($user_role);
588 update_user_meta($uid, 'validated', time()); 584 update_user_meta($uid, 'validated', time());
589 } catch (Exception $e) { 585 } catch (Exception $e) {
...@@ -760,8 +756,16 @@ class Actions { ...@@ -760,8 +756,16 @@ class Actions {
760 die(json_encode($return)); 756 die(json_encode($return));
761 757
762 } 758 }
763 759
764 760 public static function wp_ajax_course_registration() {
761 $user = new User\Account($_POST['user_id']);
762
763 $user->registerForCourse($_POST['course_id'], (boolean)isset($_POST['exam']), $_POST['enrolltype']);
764 $user->approveToCourse($_POST['course_id']);
765
766 die(json_encode(Array('success' => 'true', 'refresh' => 'true')));
767 }
768
765 public static function wp_ajax_update_registration() { 769 public static function wp_ajax_update_registration() {
766 770
767 CBV\load('Events'); 771 CBV\load('Events');
...@@ -855,7 +859,7 @@ class Actions { ...@@ -855,7 +859,7 @@ class Actions {
855 } 859 }
856 860
857 public static function wp_ajax_build_cehour_form() { 861 public static function wp_ajax_build_cehour_form() {
858 $user = new WP_User($_GET['uid']); 862 $user = new User\Account($_GET['uid']);
859 $uid = $user->ID; 863 $uid = $user->ID;
860 864
861 $fname = get_user_meta($user->ID, 'first_name', true); 865 $fname = get_user_meta($user->ID, 'first_name', true);
...@@ -900,13 +904,21 @@ class Actions { ...@@ -900,13 +904,21 @@ class Actions {
900 die($content); 904 die($content);
901 905
902 } 906 }
903 907
908 public static function wp_ajax_build_course_form() {
909 $user = new User\Account($_GET['uid']);
910 $course = new Courses\Course($_GET['course_id']);
911
912 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'partials' . DIRECTORY_SEPARATOR . 'edit_course.php');
913
914 die;
915 }
916
904 public static function wp_ajax_build_event_form() { 917 public static function wp_ajax_build_event_form() {
905 918
906 $user = new WP_User($_GET['uid']); 919 $user = new User\Account($_GET['uid']);
907 $uid = $user->ID; 920 $uid = $user->ID;
908 reset($user->roles); 921 $role = $user->getRole();
909 $role = current($user->roles);
910 922
911 $fname = get_user_meta($user->ID, 'first_name', true); 923 $fname = get_user_meta($user->ID, 'first_name', true);
912 $lname = get_user_meta($user->ID, 'last_name', true); 924 $lname = get_user_meta($user->ID, 'last_name', true);
......
1 <?php 1 <?php
2 namespace Tz\WordPress\Tools\UserManager; 2 namespace Tz\WordPress\Tools\UserManager;
3
4 use Tz, Tz\Common; 3 use Tz, Tz\Common;
4 use Tz\WordPress\Tools;
5 use Tz\WordPress\CBV; 5 use Tz\WordPress\CBV;
6 use Tz\WordPress\CBV\CEHours; 6 use Tz\WordPress\CBV\Courses;
7 use Tz\WordPress\CBV\Events;
8 use Tz\WordPress\CBV\User; 7 use Tz\WordPress\CBV\User;
9 use Tz\WordPress\UAM; 8 use Tz\WordPress\UAM;
9 use WP_Query;
10 10
11 use Tz\WordPress\Tools, Tz\WordPress\Tools\UserDetails as UD; 11 // check to see if user is eligible for course (is member/student)
12 use Tz\WordPress\Tools\Notifications;
13
14 use Exception, StdClass;
15 use WP_User;
16 12
17 CBV\load('Courses'); 13 CBV\load('Courses');
18 $user = new User\Account($_GET['uid']); 14 $user = new User\Account($_GET['uid']);
15 $courses = Courses\getActiveCourses();
16 $lookup = Array();
17 foreach ($courses as $course) {
18 $lookup[$course->getTemplateID()] = $course;
19 }
20
21 $fn_cd = function($tid, $key) use ($courses, $lookup) {
22 if (!isset($lookup[$tid])) {
23 return 'Not Available';
24 }
25
26 return date('Y-m-d', $courses[$lookup[$tid]->getID()]->{$key});
27 };
19 ?> 28 ?>
20 <div style="padding:10px 10px 0px 10px; min-width:760px;"> 29 <div style="padding:10px 10px 0px 10px; min-width:760px;">
30 <!--
21 <h2>Security Question Status</h2> 31 <h2>Security Question Status</h2>
22 <p> 32 <p>
23 33
24 </p> 34 </p>
35 -->
25 36
26 <h2 style="margin-bottom:10px;padding-bottom:0px;">Registered for Courses...</h2> 37 <h2 style="margin-bottom:10px;padding-bottom:0px;">Registered for Courses...</h2>
38
39 <table class="clean-lines widefat post fixed">
40 <thead><tr>
41 <th>Course</th>
42 <th>Type</th>
43 <th>Mark & Pass/Fail</th>
44 <th>Registration Deadline</th>
45 <th>Semester Runs</th>
46 <th>Register</th>
47 </tr></thead>
48 <tbody>
49 <?php
50 $templates = new WP_Query(Array(
51 'post_type' => CBV\PCT_COURSETEMPLATE
52 , 'posts_per_page' => 0
53 ));
54 while ($templates->have_posts()):
55 $templates->the_post();
56 ?>
57 <tr>
58 <td><?php echo get_the_title(); ?></td>
59 <td><?php echo get_post_meta(get_the_ID(), 'course_type', true); ?></td>
60 <td><?php echo $user->getMark(get_the_ID()); ?></td>
61 <td><?php echo $fn_cd(get_the_ID(), 'course_regi_close'); ?>
62 <td><?php echo $fn_cd(get_the_ID(), 'course_start') . ' - ' . $fn_cd(get_the_ID(), 'course_end'); ?></td>
63 <td>
64 <?php if (isset($lookup[get_the_ID()]) && $lookup[get_the_ID()]->registrationOpen()): ?>
65 <?php if ($user->courseApprovalStatus($lookup[get_the_ID()]->getID()) == $user::CAS_APPROVED): ?>
66 Registered
67 <?php else: ?>
68 <a href="/wp-admin/admin-ajax.php?ajax=yes&action=build_course_form&post_action=create&uid=<?php echo $user->ID; ?>&course_id=<?php echo $lookup[get_the_ID()]->getID();?>" class="course-edit" rel="<?php echo get_the_id();?>">Register</a>
69 <?php endif; ?>
70 <?php endif; ?>
71 </td>
72 </tr>
73 <?php
74 endwhile;
75 _reset_postdata();
76 ?>
77 </tbody>
78 </table>
79
80 <?php /*
27 <pre><?php print_r(get_user_meta($_GET['uid'], 'courses_registered', true)); ?></pre> 81 <pre><?php print_r(get_user_meta($_GET['uid'], 'courses_registered', true)); ?></pre>
82 <pre><?php print_r(get_user_meta($_GET['uid'], 'marks', true)); ?></pre>
28 <pre><?php print_r(get_user_meta($_GET['uid'], 'course_4q_approvals', true)); ?></pre> 83 <pre><?php print_r(get_user_meta($_GET['uid'], 'course_4q_approvals', true)); ?></pre>
84 */ ?>
29 </div> 85 </div>
30 <script src="<?php echo Tools\url('../UserManager.js', __FILE__);?>" type="text/javascript"></script> 86 <script src="<?php echo Tools\url('../UserManager.js', __FILE__);?>" type="text/javascript"></script>
...\ No newline at end of file ...\ No newline at end of file
......
1 <?php
2 $enrolments = $course->getEnrolments($user->ID);
3 ?>
4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
7 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
8 <head>
9 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
10
11 <title>Edit Course</title>
12 <style type="text/css">
13
14 html, body { margin:0px; padding:0;}
15 .title-link {
16 color:#f7bd55;
17 font-size: 12px;
18 font-weight: bold;
19 text-align: left;
20 line-height: 1.75em;
21 background: #3b0d32;
22 border: solid 1px #FFF;
23 border-bottom: solid 1px #999;
24 cursor: default;
25 padding: 0em; padding:3px 10px 3px 10px;
26 margin: 0em;
27 }
28
29 form {
30 display: block;
31 margin-right:20px;
32 }
33
34 .dashboard-section-title { font-weight:bold; color:#3b0d32; }
35 </style>
36 </head>
37
38 <body>
39 <form method="post" id="edit-course-form">
40 <input type="hidden" name="course_id" value="<?php echo $course->getID(); ?>" />
41 <input type="hidden" name="user_id" value="<?php echo $user->ID; ?>" />
42
43 <div class="title-link" style="display:block;color:#f7bd55; font-size: 12px;font-weight: bold;text-align: left;line-height: 1.75em; background-color: #3b0d32; border: solid 1px #FFF; border-bottom: solid 1px #999; cursor: default; padding: 0em; padding:3px 10px 3px 10px; margin: 0em;"><?php echo $course->post_title;?></div>
44
45 <div class="dashboard-section" style="margin-left:20px;margin-top:10px;">
46 <div class="dashboard-section-title">REGISTRATION STATUS</div>
47 <div class="dashboard-section-links"></div>
48 <div class="dashboard-section-content small">
49 <select name="status">
50 <option value="paid">Paid</option>
51 <option value="free">Free</option>
52 </select>
53 </div>
54 </div>
55
56 <div class="dashboard-section" style="margin-left:20px;margin-top:10px;">
57 <div class="dashboard-section-title">ENROLMENT TYPE</div>
58 <div class="dashboard-section-links"></div>
59 <div class="dashboard-section-content small">
60 <select name="enrolltype">
61 <?php foreach ($enrolments as $key => $display): ?>
62 <option value="<?php echo $key; ?>"><?php echo $display; ?></option>
63 <?php endforeach; ?>
64 </select>
65 </div>
66 </div>
67
68 <div class="dashboard-section" style="margin-left:20px;margin-top:10px;">
69 <div class="dashboard-section-title"></div>
70 <div class="dashboard-section-links"></div>
71 <div class="dashboard-section-content small">
72 <div><input type="submit" value="Register" /></div>
73 </div>
74 </div>
75
76 </body>
77 </html>
...\ No newline at end of file ...\ No newline at end of file