Example #1
0
function auth_redirect()
{
    if ($user_id = validate_login_cookie()) {
        return;
    }
    $redirect = current_url();
    $login_url = get_option('siteurl') . '/login.php?redirect_to=' . urlencode($redirect);
    cm_redirect($login_url);
}
switch ($action) {
    case 'delete':
        delete_lh($lh);
        cm_redirect(admin_url("lecture-edit.php"));
        break;
    case 'edit':
        $editing = true;
        $lh = get_lh_to_edit($lh);
        setup_lhdata($lh);
        $title = __("Chỉnh sửa giảng đường - ") . get_lh_name();
        require_once 'template-loader.php';
        break;
    case 'update':
        $new_lh_data['name'] = strip_all_tags($_POST['lh_name']);
        $new_lh_data['address'] = strip_all_tags($_POST['lh_address']);
        $redirect = admin_url("lecture-hall.php?action=edit&lh={$lh}");
        $cmdb->update($cmdb->lecture_hall, $new_lh_data, array("lh_id" => $lh));
        cm_redirect($redirect);
        break;
    case 'new':
        //$lh=0;
        $new_lh_data['name'] = strip_all_tags($_POST['lh_name']);
        $new_lh_data['address'] = strip_all_tags($_POST['lh_address']);
        $cmdb->insert($cmdb->lecture_hall, $new_lh_data);
        if ($redirect_to) {
            $redirect = urldecode($redirect_to);
        } else {
            $redirect = admin_url("lecture-edit.php");
        }
        cm_redirect($redirect);
}
        $all_students = _get_course_students($course, $offset, $limit);
        $all_teachers = _get_course_teachers($course);
        break;
    case 'edit':
        $editing = true;
        $course_teachers = _get_course_teachers($course);
        $course_teacher = $course_teachers[0];
        $course = get_course_to_edit($course);
        setup_coursedata($course);
        break;
    case 'update':
        $new_course_data = $new_course = $_POST;
        $new_teacher['user_id'] = $new_course_data['course_teacher'];
        strip_course_data($new_course_data);
        $cmdb->update($cmdb->courses, $new_course_data, array('ID' => $course));
        if (!$cmdb->update($cmdb->users_join, $new_teacher, array('course_id' => $course))) {
            $cmdb->insert($cmdb->users_join, array('user_id' => $new_course['course_teacher'], 'course_id' => $course));
        }
        cm_redirect(admin_url("course.php?action=edit&course=" . $course));
    case 'new':
        $new_course_data = $_POST;
        $course_teacher['user_id'] = $new_course_data['course_teacher'];
        strip_course_data($new_course_data);
        $cmdb->insert($cmdb->courses, $new_course_data);
        $course_id = $cmdb->get_var("select ID from {$cmdb->courses} order by ID DESC limit 1");
        $course_teacher['course_id'] = $course_id;
        $cmdb->insert($cmdb->users_join, $course_teacher);
        cm_redirect(admin_url("course-edit.php"));
        break;
}
require_once 'template-loader.php';
Example #4
0
function cm()
{
    if (is_administrator()) {
        cm_redirect(admin_url());
    }
}
auth_redirect();
$student = get_username();
$selected_courses = get_selected_courses();
if ($course = $_GET['select']) {
    if (!in_array($course, $selected_courses)) {
        $selected_courses[] = $course;
    }
    update_option($student . "_selected_courses", $selected_courses);
} elseif ($course = $_GET['unselect']) {
    foreach ($selected_courses as $k => $v) {
        if ($course == $v) {
            unset($selected_courses[$k]);
        }
    }
    update_option($student . "_selected_courses", $selected_courses);
}
if ($_POST['join-course']) {
    $course_ids = $_POST['courses'];
    if (is_array($course_ids)) {
        foreach ($course_ids as $course_id) {
            cm_join(get_user_id(), $course_id);
        }
        update_option($student . "_selected_courses", '');
        //clear
        $message = "Các khóa học bạn chọn đã được đăng ký thành công";
    } else {
        $message = "Chưa có khóa học nào được chọn";
    }
}
cm_redirect(site_url() . "/?cm=courses-list&message=" . urlencode($message));
    $remember = $_POST['cm-remember'];
}
if (isset($_GET['logout'])) {
    cm_logout();
    cm_redirect(site_url('login.php'));
}
if (is_user_logged_in()) {
    if (is_administrator()) {
        cm_redirect(admin_url());
    } else {
        cm_redirect(site_url());
    }
}
$logged_in = cm_logon($username, $password, $remember);
if ($logged_in) {
    cm_redirect($redirect_to);
}
if ($username) {
    if (!$password) {
        $mess = "Xin hãy nhập mật khẩu";
    } else {
        $mess = "Tên đăng nhập hoặc mật khẩu không đúng";
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML dir=ltr lang=vi xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>CCM › Đăng nhập</TITLE>
<META content="text/html; charset=UTF-8" http-equiv=Content-Type>
<style>
* {
	PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px
<?php

require 'cm-load.php';
auth_redirect();
$new_user_data = $_POST;
$user_new_pass = $new_user_data['newpass'];
$user_new_pass_retype = $new_user_data['newpass_retype'];
$user_current_password = $new_user_data['password'];
_fill_user($new_user_data);
unset($new_user_data['password']);
if (cm_check_password($user_current_password)) {
    if (!empty($user_new_pass)) {
        if ($user_new_pass == $user_new_pass_retype) {
            $new_user_data['password'] = md5($user_new_pass);
        } else {
            $message = "Mật khẩu mới ở hai ô phải giống nhau";
        }
    }
    $cmdb->update($cmdb->users, $new_user_data, array("ID" => get_user_id(), "type" => "student"));
    $message = "Thông tin của bạn đã được thay đổi thành công";
} else {
    $message = "Mật khẩu hiện tại không đúng";
}
cm_redirect(site_url() . "/?cm=profile&action=edit&message=" . urlencode($message));