Beispiel #1
0
function sp_showMessage($msg = NULL, $msgt = NULL)
{
    global $sp_msg, $sp_msgt;
    if (!empty($msg) || !empty($msgt)) {
        sp_setMessage($msg, $msgt);
    }
    if (!empty($sp_msg)) {
        ?>
	<div class="pmpro_message pmpro_<?php 
        echo esc_attr($sp_msgt);
        ?>
"><?php 
        echo $sp_msg;
        ?>
</div>
	<?php 
    }
}
Beispiel #2
0
function sp_edit_class_preheader()
{
    if (!is_admin()) {
        global $post, $current_user;
        if (!empty($post->post_content) && strpos($post->post_content, "[sp_edit_class]") !== false) {
            /*
            	Preheader operations here.
            */
            //make sure user is logged in and a Teacher
            if (!pmpro_hasMembershipLevel(array(2, 3))) {
                wp_redirect('http://schoolpress.me/membership/');
                exit;
            }
            //adding a class?
            if (!empty($_POST['edit'])) {
                $edit = intval($_POST['edit']);
                //get values
                $class_name = $_REQUEST['class_name'];
                $class_description = $_REQUEST['class_description'];
                $class_department = $_REQUEST['class_department'];
                $class_semester = $_REQUEST['class_semester'];
                if (!empty($_REQUEST['class_enrollment'])) {
                    $class_enrollment = $_REQUEST['class_enrollment'];
                } else {
                    $class_enrollment = "";
                }
                //check values
                if (empty($class_name) || empty($class_description) || empty($class_department) || empty($class_semester)) {
                    sp_setMessage("Please complete all fields.", "error");
                } else {
                    //adding or updating?
                    if ($edit == -1) {
                        //woah, let's make sure they are a teacher
                        if (!pmpro_hasMembershipLevel(array(2, 3))) {
                            die("You do not have permission to do this.");
                        }
                        //add class
                        $class = new SPCLass(array('name' => $class_name, 'description' => $class_description, 'department' => $class_department, 'semester' => $class_semester, 'enrollment' => $class_enrollment));
                        if (!empty($class)) {
                            //redirect to the class page
                            wp_redirect(get_permalink($class->id));
                            exit;
                        } else {
                            sp_setMessage("Error adding class.", "error");
                        }
                    } else {
                        //update class
                        $class = new SPClass($edit);
                        //let's make sure they can edit this class
                        if (!$class->isTeacher() && !current_user_can("manage_options")) {
                            die("You do not have permission to do this.");
                        }
                        //okay update
                        if (!empty($class) && $class->editClass($class_name, $class_description, $class_department, $class_semester, $class_enrollment)) {
                            sp_setMessage("Class updated successfully.", "success");
                        } else {
                            sp_setMessage("Error updating class.", "error");
                        }
                    }
                }
            }
            //deleting a class?
            if (!empty($_REQUEST['delete'])) {
                $class_id = intval($_REQUEST['delete']);
                $class = new SPClass($class_id);
                //only teachers and admins can delete classes
                if ($class->isTeacher() || current_user_can("manage_options")) {
                    $r = wp_delete_post($class->post->ID);
                    wp_redirect(home_url("/my-classes/"));
                    exit;
                }
            }
        }
    }
}
function sp_edit_assignment_preheader()
{
    if (!is_admin()) {
        global $post, $current_user;
        if (!empty($post->post_content) && strpos($post->post_content, "[sp_edit_assignment]") !== false) {
            /*
            	Preheader operations here.
            */
            //make sure user is logged in and a Teacher
            if (!pmpro_hasMembershipLevel(array(2, 3))) {
                wp_redirect('http://schoolpress.me/membership/');
                exit;
            }
            //adding an assignment?
            if (!empty($_POST['edit'])) {
                $edit = intval($_POST['edit']);
                //get values
                $assignment_title = $_REQUEST['assignment_title'];
                $assignment_description = $_REQUEST['assignment_description'];
                $due_year = intval($_REQUEST['due_year']);
                $due_month = intval($_REQUEST['due_month']);
                $due_day = intval($_REQUEST['due_day']);
                $assignment_due_date = $due_year . "-" . $due_month . "-" . $due_day;
                if (!empty($_REQUEST['assignment_required'])) {
                    $assignment_required = $_REQUEST['assignment_required'];
                } else {
                    $assignment_required = "";
                }
                $class_id = $_REQUEST['class_id'];
                //must specify a class
                if (empty($class_id)) {
                    die("ERROR: Could not figure out which class you wanted to add/edit assignments for.");
                }
                //check values
                if (empty($assignment_title) || empty($assignment_description) || empty($assignment_due_date)) {
                    sp_setMessage("Please complete all fields.", "error");
                } else {
                    //adding or updating?
                    if ($edit == -1) {
                        //woah, let's make sure they are a teacher
                        if (!pmpro_hasMembershipLevel(array(2, 3))) {
                            die("You do not have permission to do this.");
                        }
                        //add assignment
                        $assignment = new SPAssignment(array("title" => $assignment_title, "due_date" => $assignment_due_date, "required" => $assignment_required, "description" => $assignment_description, 'class_id' => $class_id));
                        if (!empty($assignment)) {
                            //redirect to the class page
                            wp_redirect(get_permalink($class_id));
                            exit;
                        } else {
                            sp_setMessage("Error adding assignment.", "error");
                        }
                    } else {
                        //update assignment
                        $assignment = new SPAssignment($edit);
                        //let's make sure they can edit this assignment
                        if (!$assignment->isTeacher() && !current_user_can("manage_options")) {
                            die("You do not have permission to do this.");
                        }
                        //okay update
                        if (!empty($assignment) && $assignment->editAssignment($assignment_title, $assignment_due_date, $assignment_required, $assignment_description)) {
                            sp_setMessage("Assignment updated successfully.", "success");
                        } else {
                            sp_setMessage("Error updating assignment.", "error");
                        }
                    }
                }
            }
            //deleting an assignment?
            if (!empty($_REQUEST['delete'])) {
                $assignment_id = intval($_REQUEST['delete']);
                $assignment = new SPAssignment($assignment_id);
                //only teachers and admins can delete classes
                if ($assignment->isTeacher() || current_user_can("manage_options")) {
                    $r = wp_delete_post($assignment->post->ID);
                    wp_redirect(get_permalink($assignment->class_id));
                    exit;
                }
            }
        }
    }
}