Last active
August 29, 2015 14:10
-
-
Save seanmcn/da227bc832efa3d9638e to your computer and use it in GitHub Desktop.
Edusessions wordpress pluigin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Education Session Plugin | |
Plugin URI: http://coder.ie/ | |
Description: Custom Plugin for IFAN | |
Version: 1.0 | |
Author: Sean McNamara | |
Author URI: http://seanmcn.com/ | |
*/ | |
register_activation_hook(__FILE__,'edusession_plugin_install'); | |
register_deactivation_hook(__FILE__,'edusession_plugin_uninstall'); | |
add_action( 'admin_menu', 'my_plugin_menu' ); | |
function my_plugin_menu() { | |
add_menu_page( 'My Plugin Options', 'Education Sessions', 'manage_options', 'eduSessions', 'edusessionBackend' ); | |
} | |
//Install Function | |
function edusession_plugin_install() { | |
global $wpdb; | |
$table_name = $wpdb->prefix . "eduSessions"; | |
$sql = "CREATE TABLE $table_name ( | |
id mediumint(9) NOT NULL AUTO_INCREMENT, | |
date date NOT NULL, | |
location text NOT NULL, | |
availability int NOT NULL, | |
UNIQUE KEY id (id) | |
);"; | |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); | |
dbDelta( $sql ); | |
} | |
function edusessionFrontend() { | |
global $wpdb; | |
$table_name = $wpdb->prefix . "eduSessions"; | |
$sessions = $wpdb->get_results( "SELECT * FROM $table_name WHERE availability=0" ); | |
if($_POST['eduSession_register'] == 'Y' && trim($_POST["users_name"]) === "") { | |
echo "<div class=\"error\">Error: Name is Required</div>"; | |
} | |
elseif($_POST['eduSession_register'] == 'Y' && trim($_POST["membership_number"]) === "") { | |
echo "<div class=\"error\">Membership Number Required</div>"; | |
} | |
elseif($_POST['eduSession_register'] == 'Y' && trim($_POST["email"]) === "") { | |
echo "<div class=\"error\">Email is Required</div>"; | |
} | |
elseif($_POST['eduSession_register'] == 'Y' && trim($_POST["telephone"]) === "") { | |
echo "<div class=\"error\">Telephone Number Required</div>"; | |
} | |
elseif($_POST['eduSession_register'] == 'Y' && trim($_POST["work_address"]) === "") { | |
echo "<div class=\"error\">Work Address Required</div>"; | |
} | |
elseif($_POST['eduSession_register'] == 'Y' && trim($_POST["choice_one"]) === "") { | |
echo "<div class=\"error\">Choice One is Required</div>"; | |
} | |
elseif($_POST['eduSession_register'] == 'Y' && trim($_POST["choice_two"]) === "") { | |
echo "<div class=\"error\">Choice Two is Required</div>"; | |
} | |
elseif($_POST['eduSession_register'] == 'Y' && trim($_POST["choice_two"]) != "" && trim($_POST["choice_one"]) != "" && trim($_POST["work_address"]) != "" && trim($_POST["telephone"]) != "" && trim($_POST["email"]) != "" && trim($_POST["membership_number"]) != "" && trim($_POST["users_name"]) != "") { | |
$choice_one_id = $_POST["choice_one"]; | |
$choice_two_id = $_POST["choice_two"]; | |
$choice_one = $wpdb->get_row("SELECT * FROM $table_name WHERE id=$choice_one_id"); | |
$choice_two = $wpdb->get_row("SELECT * FROM $table_name WHERE id=$choice_two_id"); | |
$message = "Name : ".$_POST["users_name"]."\n". | |
"Membership Number: ".$_POST["membership_number"]."\n". | |
"I am a: ".$_POST["i_am_a"]."\n". | |
"Work Base: ".$_POST["workBase"]."\n". | |
"Email: ".$_POST["email"]."\n". | |
"Telephone: ".$_POST["telephone"]."\n". | |
"Work Address: ".$_POST["work_address"]."\n". | |
"Choice One: ".date("d-m-Y", strtotime($choice_one->date))." - ".$choice_one->location."\n". | |
"Choice Two: ".date("d-m-Y",strtotime($choice_two->date))." - ".$choice_two->location."\n". | |
"Contact by email: ".$_POST["do_not_contact"]; | |
//var_dump($message); | |
$headers = 'From: IFAN Website <[email protected]>' . "\r\n"; | |
wp_mail( "[email protected]", "IFAN Registration", $message, $headers); | |
$headers2 = 'From: IFAN Website <[email protected]>' . "\r\n"; | |
$message2 = "Thank you for contacting IFAN and for registering for free CME supported education in Paediatric Food Allergy \n \n". | |
"There's a maximum capacity at each venue. In the interest of fairness and funding, IFAN will strive to ensure a broad representation from across all disciplines at each session. It may be possible to attend more than one session. \n \n". | |
"Your registration request is being processed. Attendance is not automatically guaranteed. If successful, you will receive a separate confirmation email a minimum of 4 weeks in advance of the date you requested."; | |
wp_mail($_POST["email"], "Irish Food Allergy Network", $message2, $headers2); | |
?> | |
<div class="success">Thank you for registering, you will recieve confirmation of availability for your selected dates shortly. </div> | |
<?php | |
} | |
?> | |
<div class="educationSessionForm"> | |
<span style="font-weight: bold; color: #ff9933;">*All sections are mandatory</span> | |
<form method="POST" action="<?php echo the_permalink(); ?>"> | |
<strong>Name:</strong><br /><input type="text" name="users_name"/> <br /><br /> | |
<strong>Professional membership number:</strong><br /><input type="text" name="membership_number"/><br /><br /> | |
<strong>I am a: </strong><br /> | |
<select name="i_am_a"> | |
<option name="GP">GP</option> | |
<option name="PracticeNurse">Practice nurse</option> | |
<option name="PublicHealthNurse">Public Health Nurse</option> | |
<option name="Dietitian">Dietitian</option> | |
<option name="MedicalScientist">Medical Scientist</option> | |
<option name="Parent">Parent</option> | |
<option name="Paediatrician">Paediatrician</option> | |
<option name="NCHD">NCHD</option> | |
<option name="MedicalOfficer">Medical Officer</option> | |
<option name="HospitalDoctor">Hospital Doctor</option> | |
<option name="PatientRepresentative">Patient representative</option> | |
<option name="Other">Other (Please State:)</option> | |
</select><br /><br /> | |
<strong>My main work base is in:</strong><br /> | |
<select name="workBase"> | |
<option name="community">The Community</option> | |
<option name="hospital">A Hospital</option> | |
</select><br /><br /> | |
<strong>Contact Email: </strong><br /><input type="text" name="email"/><br /><br /> | |
<strong>Contact Telephone: </strong><br /><input type="text" name="telephone"/><br /><br /> | |
<strong>Work Address:</strong> <br /><input type="text" name="work_address"/><br /><br /> | |
<br /><strong>I would like to attend:</strong> <br /><br /> | |
<strong>Choice One: </strong><br /><br /> | |
<?php foreach($sessions as $session) { ?> | |
<input type="radio" name="choice_one" value="<?php echo $session->id; ?>"/> <?php echo $session->date;?> - <?php echo $session->location;?><br /><br /> | |
<?php } ?> | |
<br /><strong>Choice Two: </strong><br /><br /> | |
<?php foreach($sessions as $session) { ?> | |
<input type="radio" name="choice_two" value="<?php echo $session->id;?>"/> <?php echo $session->date;?> - <?php echo $session->location;?><br /><br /> | |
<?php } ?><br /> | |
The information you provide will remain confidential and will not be used for any reason other than for registration and confirmation purposes associated with this meeting. IFAN reserves the right to cap the maximum attendance at each venue. IFAN will contact all attendees some months after the event to assess any change(s) in knowledge and practice. | |
<br /><br /> | |
If you do not wish to be contacted by IFAN regarding future events please tick here <input type="checkbox" name="do_not_contact" value="false"> <br /> | |
<input type="hidden" name="eduSession_register" value="Y"> <br /> | |
<input type="submit" value="Register"/> | |
</form> | |
</div> | |
</div> | |
</div> | |
<?php | |
} | |
function edusessionBackend() { | |
global $wpdb; | |
$table_name = $wpdb->prefix . "eduSessions"; | |
if($_POST['eduSession_hidden'] == 'Y') { | |
$date = date("Y-m-d",strtotime($_POST["date"])); | |
$data = array ( | |
"date" => $date, | |
"location" => $_POST["location"] | |
); | |
$wpdb->insert( $table_name, $data); | |
} else { | |
//Normal page display | |
} | |
if($_POST["eduSession_make_unavailable"] == 'Y') { | |
$data = array( | |
"availability" => 1 | |
); | |
$id = $_POST['id']; | |
$where= array("id" => $id); | |
$wpdb->update($table_name, $data, $where); | |
} | |
if($_POST["eduSession_make_available"] == 'Y') { | |
$data = array( | |
"availability" => 0 | |
); | |
$id = $_POST['id']; | |
$where= array("id" => $id); | |
$wpdb->update($table_name, $data, $where); | |
} | |
$sessions = $wpdb->get_results( "SELECT * FROM $table_name" ); | |
?> | |
<h1>Add Session</h1> | |
<p> | |
<form method="POST" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>"> | |
<input type="hidden" name="eduSession_hidden" value="Y"> | |
Date: <input type="text" name="date"/> | |
Location: <input type="text" name="location"/> | |
<input type="submit" value="Add Session"/> | |
</form> | |
</p> | |
<h1>Sessions</h1> | |
<table width="100%"> | |
<thead> | |
<tr style="font-weight:bold;"><td>Date</td><td>Location</td><td>Availability</td></tr> | |
</thead> | |
<tbody> | |
<?php | |
foreach($sessions as $session) { ?> | |
<tr> | |
<td><?php echo date("d-m-Y", strtotime($session->date)); ?></td><td><?php echo $session->location; ?></td><td> | |
<?php if($session->availability != 1) { ?> | |
<form method="POST" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>"> | |
<input type="hidden" name="id" value="<?php echo $session->id; ?>"> | |
<input type="hidden" name="eduSession_make_unavailable" value="Y"> | |
<input type="submit" value="Make Unavailable"/> | |
</form> | |
<?php } else { ?> | |
<form method="POST" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>"> | |
<input type="hidden" name="id" value="<?php echo $session->id; ?>"> | |
<input type="hidden" name="eduSession_make_available" value="Y"> | |
<input type="submit" value="Make Available"/> | |
</form> | |
<?php } ?></td> | |
</tr> | |
<?php | |
} | |
?> | |
</tbody> | |
</table> | |
<?php } | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment