a123fb2f by Chris Boden

Course section

1 parent 468d4992
......@@ -150,6 +150,26 @@ jQuery(function($) {
};
jQuery('#edit-event-form').ajaxForm(options);
}});
jQuery('.course-edit').colorbox({onComplete: function() {
var cb = this;
var options = {
beforeSubmit: function() {}
, success: function(data) {
if (data.refresh == "true") {
document.location.href = document.location.href;
} else {
jQuery.colorbox.close();
}
}
, data: ({ajax:"yes", action: 'course_registration'})
, dataType: 'json'
, url: '/wp-admin/admin-ajax.php'
};
jQuery('#edit-course-form').ajaxForm(options);
}});
jQuery('#admin_add_new_cehours').colorbox({onComplete: function() {
jQuery('.datepicker').datePicker(
......
......@@ -19,8 +19,8 @@ use Tz\WordPress\CBV\User;
use Tz\WordPress\CBV\Events;
use Tz\WordPress\CBV\CEHours;
use Tz\WordPress\CBV\Invoice;
use Tz\WordPress\CBV\Courses;
use Exception, StdClass;
use WP_User;
const OPTION_NAME = "user_options";
const CAPABILITY = "manage_cbv_users";
......@@ -145,15 +145,11 @@ function get_users($role = null, $pagenum=1, $records_per_page=0, $return_count_
$limit = "";
}
$wp_user_search = $wpdb->get_results($query.$limit);
$wp_user_search = $wpdb->get_results($query . $limit);
foreach ( $wp_user_search as $user ) {
$uid = (int) $user->ID;
$user = new WP_User($uid);
reset($user->roles);
$role = ucwords(current($user->roles));
$member_id = get_user_meta($uid, 'member_id', true);
$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);
foreach ($wp_user_search as $user ) {
$user = new User\Account((int)$user->ID);
$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);
}
return $users;
}
......@@ -411,7 +407,7 @@ class AccountValidation extends Common\Validation {
}
public function user_role($val) {
$user = new WP_User($_POST['uid']);
$user = new User\Account($_POST['uid']);
try {
$user->set_role($val);
} catch (Exception $e) {
......@@ -583,7 +579,7 @@ class Actions {
try {
$user_key = Auth\register($username, $email, $password, $user_details);
$uid = Auth\activate($user_key, $password);
$u = new WP_User($uid);
$u = new User\Account($uid);
$u->set_role($user_role);
update_user_meta($uid, 'validated', time());
} catch (Exception $e) {
......@@ -760,8 +756,16 @@ class Actions {
die(json_encode($return));
}
public static function wp_ajax_course_registration() {
$user = new User\Account($_POST['user_id']);
$user->registerForCourse($_POST['course_id'], (boolean)isset($_POST['exam']), $_POST['enrolltype']);
$user->approveToCourse($_POST['course_id']);
die(json_encode(Array('success' => 'true', 'refresh' => 'true')));
}
public static function wp_ajax_update_registration() {
CBV\load('Events');
......@@ -855,7 +859,7 @@ class Actions {
}
public static function wp_ajax_build_cehour_form() {
$user = new WP_User($_GET['uid']);
$user = new User\Account($_GET['uid']);
$uid = $user->ID;
$fname = get_user_meta($user->ID, 'first_name', true);
......@@ -900,13 +904,21 @@ class Actions {
die($content);
}
public static function wp_ajax_build_course_form() {
$user = new User\Account($_GET['uid']);
$course = new Courses\Course($_GET['course_id']);
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'partials' . DIRECTORY_SEPARATOR . 'edit_course.php');
die;
}
public static function wp_ajax_build_event_form() {
$user = new WP_User($_GET['uid']);
$user = new User\Account($_GET['uid']);
$uid = $user->ID;
reset($user->roles);
$role = current($user->roles);
$role = $user->getRole();
$fname = get_user_meta($user->ID, 'first_name', true);
$lname = get_user_meta($user->ID, 'last_name', true);
......
<?php
namespace Tz\WordPress\Tools\UserManager;
use Tz, Tz\Common;
use Tz\WordPress\Tools;
use Tz\WordPress\CBV;
use Tz\WordPress\CBV\CEHours;
use Tz\WordPress\CBV\Events;
use Tz\WordPress\CBV\Courses;
use Tz\WordPress\CBV\User;
use Tz\WordPress\UAM;
use WP_Query;
use Tz\WordPress\Tools, Tz\WordPress\Tools\UserDetails as UD;
use Tz\WordPress\Tools\Notifications;
use Exception, StdClass;
use WP_User;
// check to see if user is eligible for course (is member/student)
CBV\load('Courses');
$user = new User\Account($_GET['uid']);
$courses = Courses\getActiveCourses();
$lookup = Array();
foreach ($courses as $course) {
$lookup[$course->getTemplateID()] = $course;
}
$fn_cd = function($tid, $key) use ($courses, $lookup) {
if (!isset($lookup[$tid])) {
return 'Not Available';
}
return date('Y-m-d', $courses[$lookup[$tid]->getID()]->{$key});
};
?>
<div style="padding:10px 10px 0px 10px; min-width:760px;">
<!--
<h2>Security Question Status</h2>
<p>
</p>
-->
<h2 style="margin-bottom:10px;padding-bottom:0px;">Registered for Courses...</h2>
<table class="clean-lines widefat post fixed">
<thead><tr>
<th>Course</th>
<th>Type</th>
<th>Mark & Pass/Fail</th>
<th>Registration Deadline</th>
<th>Semester Runs</th>
<th>Register</th>
</tr></thead>
<tbody>
<?php
$templates = new WP_Query(Array(
'post_type' => CBV\PCT_COURSETEMPLATE
, 'posts_per_page' => 0
));
while ($templates->have_posts()):
$templates->the_post();
?>
<tr>
<td><?php echo get_the_title(); ?></td>
<td><?php echo get_post_meta(get_the_ID(), 'course_type', true); ?></td>
<td><?php echo $user->getMark(get_the_ID()); ?></td>
<td><?php echo $fn_cd(get_the_ID(), 'course_regi_close'); ?>
<td><?php echo $fn_cd(get_the_ID(), 'course_start') . ' - ' . $fn_cd(get_the_ID(), 'course_end'); ?></td>
<td>
<?php if (isset($lookup[get_the_ID()]) && $lookup[get_the_ID()]->registrationOpen()): ?>
<?php if ($user->courseApprovalStatus($lookup[get_the_ID()]->getID()) == $user::CAS_APPROVED): ?>
Registered
<?php else: ?>
<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>
<?php endif; ?>
<?php endif; ?>
</td>
</tr>
<?php
endwhile;
_reset_postdata();
?>
</tbody>
</table>
<?php /*
<pre><?php print_r(get_user_meta($_GET['uid'], 'courses_registered', true)); ?></pre>
<pre><?php print_r(get_user_meta($_GET['uid'], 'marks', true)); ?></pre>
<pre><?php print_r(get_user_meta($_GET['uid'], 'course_4q_approvals', true)); ?></pre>
*/ ?>
</div>
<script src="<?php echo Tools\url('../UserManager.js', __FILE__);?>" type="text/javascript"></script>
\ No newline at end of file
......
<?php
$enrolments = $course->getEnrolments($user->ID);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Edit Course</title>
<style type="text/css">
html, body { margin:0px; padding:0;}
.title-link {
color:#f7bd55;
font-size: 12px;
font-weight: bold;
text-align: left;
line-height: 1.75em;
background: #3b0d32;
border: solid 1px #FFF;
border-bottom: solid 1px #999;
cursor: default;
padding: 0em; padding:3px 10px 3px 10px;
margin: 0em;
}
form {
display: block;
margin-right:20px;
}
.dashboard-section-title { font-weight:bold; color:#3b0d32; }
</style>
</head>
<body>
<form method="post" id="edit-course-form">
<input type="hidden" name="course_id" value="<?php echo $course->getID(); ?>" />
<input type="hidden" name="user_id" value="<?php echo $user->ID; ?>" />
<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>
<div class="dashboard-section" style="margin-left:20px;margin-top:10px;">
<div class="dashboard-section-title">REGISTRATION STATUS</div>
<div class="dashboard-section-links"></div>
<div class="dashboard-section-content small">
<select name="status">
<option value="paid">Paid</option>
<option value="free">Free</option>
</select>
</div>
</div>
<div class="dashboard-section" style="margin-left:20px;margin-top:10px;">
<div class="dashboard-section-title">ENROLMENT TYPE</div>
<div class="dashboard-section-links"></div>
<div class="dashboard-section-content small">
<select name="enrolltype">
<?php foreach ($enrolments as $key => $display): ?>
<option value="<?php echo $key; ?>"><?php echo $display; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="dashboard-section" style="margin-left:20px;margin-top:10px;">
<div class="dashboard-section-title"></div>
<div class="dashboard-section-links"></div>
<div class="dashboard-section-content small">
<div><input type="submit" value="Register" /></div>
</div>
</div>
</body>
</html>
\ No newline at end of file