$_POST["enddate"] = converttodb($_POST["enddate"]);
    $query = mysql_query("INSERT INTO semesters (termid,title,startdate,midtermdate,enddate,type) VALUES( {$_POST['term']}, '{$_POST['title']}', '{$_POST['startdate']}', '{$_POST['middate']}', '{$_POST['enddate']}', '{$_POST['half']}')") or die("ManageSemesters.php: Unable to insert new semester - " . mysql_error());
}
// Edit the semester if one is being edited //
if ($_POST["editsemester"] == 1 && $_POST['term'] != "" && $_POST["title"] != "" && $_POST["startdate"] != "" && $_POST["middate"] != "" && $_POST["enddate"] != "") {
    $_POST["startdate"] = converttodb($_POST["startdate"]);
    $_POST["middate"] = converttodb($_POST["middate"]);
    $_POST["enddate"] = converttodb($_POST["enddate"]);
    $query = mysql_query("UPDATE `semesters` SET `title`='{$_POST['title']}', `startdate`='{$_POST['startdate']}', `midtermdate`='{$_POST['middate']}', `enddate`='{$_POST['enddate']}', `type`='{$_POST['half']}' WHERE `semesterid`='{$_POST['semesterid']}' LIMIT 1") or die("ManageSemesters.php: Unable to update the semester information - " . mysql_error());
}
// Delete the semesters that the user has requested as well as the classes belonging to those semesters //
if ($_POST["deletesemester"] == 1) {
    require_once "DeleteFunctions.php";
    $delete = $_POST["delete"];
    for ($i = 0; $i < sizeof($delete); $i++) {
        deleteSemester($delete[$i]);
    }
}
print "<script language='JavaScript'>\n\n  // Function to make sure the user wants to delete the semester(s) //\n  function validate()\n  {\n   if( document.semesters.selectsemester.value > 0 )\n   {\n\tvar confirmed = confirm(\"Deleteing a semester will also delete the classes, bulletins, tardies, attendance, assignments, and registrations that occured during that semester. \\n \\nAre you sure?\");\n\n\tif( confirmed == true )\n\t{\n\t document.semesters.submit();\n\t}\n   }\n   else\n   {\n\talert('You must select a semester to delete.');\n   }\n  }\n\n\n  // Function to make sure only one checkbox has been selected //\n  function checkboxes()\n  {\n   if( document.semesters.selectsemester.value == 1 )\n   {\n\tdocument.semesters.submit();\n   }\n   else\n   {\n\tif( document.semesters.selectsemester.value > 1 )\n\t{\n\t alert('You can only edit one semester at a time.');\n\t}\n\telse\n\t{\n\t alert('You must select a semester to edit.');\n\t}\n   }\n  }\n\n\n  // Function to keep track of how many checkboxes are checked //\n  function updateboxes(row)\n  {\n   row = row + 2;\n   if(document.semesters.elements[row].checked)\n   {\n\tdocument.semesters.selectsemester.value = Math.round(document.semesters.selectsemester.value) + 1;\n   }\n   else\n   {\n\tdocument.semesters.selectsemester.value = Math.round(document.semesters.selectsemester.value) - 1;\n   }\n  }\n </script>\n\n <h1>Manage Semesters</h1>\n <br><br>\n <table align='center' width='600' cellspacing='0' cellpadding='0' border='0'>\n <tr>\n <td>\n <form name='semesters' action='./index.php' method='POST'>\n  <input type='button' value='Add' onClick='document.semesters.page2.value=7;document.semesters.submit();'>\n  <input type='button' value='Edit' onClick='document.semesters.page2.value=13;checkboxes();'>\n  <input type='button' value='Delete' onClick='document.semesters.deletesemester.value=1;validate();'>\n  <br><br>\n  <table cellspacing='0' width='600' cellpadding='8' class='dynamiclist'>\n   <tr class='header'>\n\t<td>&nbsp;</td>\n\t<th>Semester Name</th>\n\t<th>Term</th>\n\t<th>Start Date</th>\n\t<th>Midterm Date</th>\n\t<th>End Date</th>\n\t<th>Half</th>\n   </tr>";
// Get the total number of semesters to know how many pages to have //
$query = mysql_query("SELECT COUNT(*) FROM semesters") or die("ManageSemesters.php: Unable to retrieve total number of semesters - " . mysql_error());
$numrows = mysql_result($query, 0);
$numpages = ceil($numrows / 25);
if ($_POST["onpage"] == "") {
    $_POST["onpage"] = 1;
}
// Get and display the semesters //
$query = mysql_query("SELECT semesterid,termid,title,startdate,midtermdate,enddate,type FROM semesters ORDER BY enddate DESC");
$row = 0;
$actualrow = 0;
while ($smstr = mysql_fetch_row($query)) {
     updateSemester($formData['id'], $formData['semester'], $formData['start_Day'], $formData['start_Month'], $formData['start_Year']);
     $smarty->assign("url", "./index.php?page=listSemesters");
     $smarty->display('redirect.tpl');
     break;
 case 'deleteSemester':
     //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
     $formData['id'] = db_clean_int($_POST['id']);
     //Verify form
     if (!secureform_test_pk($verify_key, $verify_action, $formData['id'])) {
         $smarty->assign("url", "./index.php?page=updateSemester&semester=" . $formData['id']);
         $smarty->display('redirectError.tpl');
         exit;
     }
     if (retreiveSemesterChildrenCount($formData['id']) == 0) {
         //Allowed to be deleted...
         deleteSemester($formData['id']);
     }
     $smarty->assign("url", "./index.php?page=listSemesters");
     $smarty->display('redirect.tpl');
     break;
 case 'addMeeting':
     //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
     $formData['Date_Day'] = db_clean_int($_POST['Date_Day']);
     $formData['Date_Month'] = db_clean_int($_POST['Date_Month']);
     $formData['Date_Year'] = db_clean_int($_POST['Date_Year']);
     $formData['meeting_type'] = db_clean_int($_POST['meeting_type']);
     $formData['semester'] = db_clean_int($_POST['semester']);
     $formData['description'] = db_clean_text($_POST['description']);
     //Verify form
     if (!secureform_test($verify_key, $verify_action)) {
         $smarty->assign("url", "./index.php?page=addMeeting&semester=" . $formData['semester']);