示例#1
0
} else {
    $invite_emails = "";
}
if (!empty($invite_emails)) {
    global $post;
    $class = new SPClass($post->ID);
    $invites = $class->addInvites($invite_emails);
    //return array(worked?, emails)
    //check for errors
    if (is_array($invites)) {
        //errror
        $invite_emails = implode("\n", $invites);
        sp_showMessage("There was an error adding the inviting the following emails: " . implode(", ", $invites), "error");
    } else {
        $invite_emails = "";
        sp_showMessage("Invites sent. <a href=\"" . get_permalink($post->ID) . "\">Return to Class</a>", "success");
    }
}
//form
?>
<form class="form" action="" method="post">
	<input type="hidden" name="invite" value="1" />
	<p class="pmpro_message pmpro_alert">Enter one email address per line to invite students to your class.</p>
	<div class="form-group">	
		<textarea class="form-control" rows="3" name="invite_emails" rows="5" cols="50"><?php 
echo esc_textarea($invite_emails);
?>
</textarea>
	</div>
	<div class="form-group">
		<input class="btn btn-info" type="submit" value="Send Invites" />
示例#2
0
function sp_edit_class_shortcode($atts, $content = null, $code = "")
{
    //get values
    if (!empty($_POST['edit'])) {
        $edit = intval($_POST['edit']);
        $class_name = stripslashes($_REQUEST['class_name']);
        $class_description = stripslashes($_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 = "";
        }
    } elseif (!empty($_REQUEST['edit']) && intval($_REQUEST['edit']) > 0) {
        $edit = intval($_REQUEST['edit']);
        $class = new SPClass(intval($_REQUEST['edit']));
        if (!empty($class)) {
            $class_name = $class->name;
            $class_description = $class->description;
            $class_department = $class->department_id;
            $class_semester = $class->semester_id;
            $class_enrollment = $class->enrollment;
        } else {
            $class_name = "";
            $class_description = "";
            $class_department = "";
            $class_semester = "";
            $class_enrollment = "";
        }
    } else {
        $edit = -1;
        $class_name = "";
        $class_description = "";
        $class_department = "";
        $class_semester = "";
        $class_enrollment = "";
    }
    ob_start();
    ?>
		<?php 
    sp_showMessage();
    ?>
		<form class="form form-horizontal" method="post">
			<div class="form-group">
				<label for="class_name" class="col-sm-2 control-label">Class Name</label>
				<div class="col-sm-10">
					<input type="text" class="form-control" id="class_name" name="class_name" value="<?php 
    echo esc_attr($class_name);
    ?>
">
				</div>
			</div>
			<div class="form-group">
				<label for="class_description" class="col-sm-2 control-label">Description</label>
				<div class="col-sm-10">
					<textarea class="form-control" id="class_description" name="class_description"><?php 
    echo esc_textarea($class_description);
    ?>
</textarea>
				</div>
			</div>
			<div class="form-group">
				<label for="class_department" class="col-sm-2 control-label">Department</label>
				<div class="col-sm-10">
					<select class="form-control" id="class_department" name="class_department">
					<?php 
    $terms = get_terms("department", array('hide_empty' => 0));
    if (!empty($terms) && !is_wp_error($terms)) {
        foreach ($terms as $term) {
            echo "<option " . selected($class_department, $term->term_id) . " value='" . intval($term->term_id) . "' >" . $term->name . "</option>";
        }
    }
    ?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="class_semester" class="col-sm-2 control-label">Semester</label>
				<div class="col-sm-10">
					<select class="form-control" id="class_semester" name="class_semester">
					<?php 
    $terms = get_terms("semester", array('hide_empty' => 0, 'orderby' => 'ID', 'order' => 'DESC'));
    if (!empty($terms) && !is_wp_error($terms)) {
        foreach ($terms as $term) {
            echo "<option " . selected($class_semester, $term->term_id) . " value='" . intval($term->term_id) . "' >" . $term->name . "</option>";
        }
    }
    ?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-10 col-sm-offset-2">
					<label for="class_enrollment">
						<input type="checkbox" id="class_enrollment" name="class_enrollment" value="1" <?php 
    checked($class_enrollment, 1);
    ?>
 /> Allow any student to join this class. (Leave unchecked for invite-only.)
					</label>
				</div>
			</div>
			<p class="text-center">
				<input type="hidden" name="edit" value="<?php 
    echo $edit;
    ?>
" />
				<button type="submit" class="pmpro_btn">Submit</button>
				
				<?php 
    //delete or cancel
    if (!empty($class)) {
        ?>
					<a class="btn btn-link" href="javascript:askfirst('Are you sure you want to delete this class?', '<?php 
        echo home_url('/start-a-class/?delete=' . $class->id);
        ?>
');">Delete</a>
					<?php 
    }
    ?>
					<a class="btn btn-link" href="<?php 
    echo home_url();
    ?>
">Cancel</a>
					<?php 
    ?>
			</p>
		</form>
		<?php 
    $temp_content = ob_get_contents();
    ob_end_clean();
    return $temp_content;
}
function sp_edit_assignment_shortcode($atts, $content = null, $code = "")
{
    //get values
    if (!empty($_POST['edit'])) {
        $edit = intval($_POST['edit']);
        $assignment_title = stripslashes($_REQUEST['assignment_title']);
        $assignment_description = stripslashes($_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 = "";
        }
    } elseif (!empty($_REQUEST['edit']) && intval($_REQUEST['edit']) > 0) {
        $edit = intval($_REQUEST['edit']);
        $assignment = new SPAssignment(intval($_REQUEST['edit']));
        if (!empty($assignment)) {
            $assignment_title = $assignment->title;
            $assignment_description = $assignment->description;
            $assignment_due_date = $assignment->due_date;
            $assignment_required = $assignment->required;
        } else {
            $assignment_title = "";
            $assignment_description = "";
            $assignment_due_date = "";
            $assignment_required = "";
        }
    } else {
        $edit = -1;
        $assignment_title = "";
        $assignment_description = "";
        $assignment_due_date = "";
        $assignment_required = "";
    }
    //get class
    if (!empty($assignment) && !empty($assignment->class_id)) {
        $class = $assignment->getClass();
    } elseif (!empty($_REQUEST['class_id'])) {
        $class = new SPClass(intval($_REQUEST['class_id']));
    } else {
        die("ERROR: Could not figure out which class you wanted to add/edit assignments for.");
    }
    ob_start();
    ?>
		<?php 
    sp_showMessage();
    ?>
		<form class="form form-horizontal" method="post">
			<div class="form-group">
				<label for="assignment_title" class="col-sm-2 control-label">Assignment Title</label>
				<div class="col-sm-10">
					<input type="text" class="form-control" id="assignment_title" name="assignment_title" value="<?php 
    echo esc_attr($assignment_title);
    ?>
">
				</div>
			</div>			
			<div class="form-group">
				<label for="assignment_due_date" class="col-sm-2 control-label">Due Date</label>
				<div class="col-sm-10">
					<?php 
    //split assignment due date into parts
    if (empty($assignment_due_date)) {
        $assignment_due_date = date("Y-m-d", current_time("timestamp"));
    }
    $current_year = date("Y", current_time("timestamp"));
    $due_date_parts = explode("-", $assignment_due_date);
    $selected_due_year = $due_date_parts[0];
    $selected_due_month = $due_date_parts[1];
    $selected_due_day = $due_date_parts[2];
    ?>
					<select name="due_month">
						<?php 
    for ($i = 1; $i < 13; $i++) {
        ?>
							<option value="<?php 
        echo $i;
        ?>
" <?php 
        if ($i == $selected_due_month) {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        echo date("M", strtotime($i . "/1/" . $current_year, current_time("timestamp")));
        ?>
</option>
							<?php 
    }
    ?>
					</select>
					<input name="due_day" type="text" size="2" value="<?php 
    echo esc_attr($selected_due_day);
    ?>
" />
					<input name="due_year" type="text" size="4" value="<?php 
    echo esc_attr($selected_due_year);
    ?>
" />
					
					<input type="hidden" class="form-control datepicker" id="assignment_due_date" name="assignment_due_date" value="<?php 
    echo esc_attr($assignment_due_date);
    ?>
">
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-10 col-sm-offset-2">
					<label for="assignment_required">
						<input type="checkbox" id="assignment_required" name="assignment_required" value="1" <?php 
    checked($assignment_required, 1);
    ?>
 /> Required?
					</label>
				</div>
			</div>
			<div class="form-group">
				<label for="assignment_description" class="col-sm-2 control-label">Description</label>
				<div class="col-sm-10">					
					<textarea class="form-control" id="assignment_description" name="assignment_description"><?php 
    echo esc_textarea($assignment_description);
    ?>
</textarea>
				</div>
			</div>
						
			<p class="text-center">
				<input type="hidden" name="edit" value="<?php 
    echo $edit;
    ?>
" />
				<input type="hidden" name="class_id" value="<?php 
    echo $class->id;
    ?>
" />
				<button type="submit" class="pmpro_btn">Submit</button>
				
				<?php 
    //delete or cancel
    if (!empty($assignment->id)) {
        ?>
					<a class="btn btn-link" href="javascript:askfirst('Are you sure you want to delete this assignment?', '<?php 
        echo home_url('/edit-assignment/?delete=' . $assignment->id);
        ?>
');">Delete</a>
					<?php 
    }
    ?>
					<a class="btn btn-link" href="<?php 
    echo get_permalink($class->id);
    ?>
">Cancel</a>
					<?php 
    ?>
			</p>
		</form>
		<?php 
    $temp_content = ob_get_contents();
    ob_end_clean();
    return $temp_content;
}