[go: up one dir, main page]

Menu

[2a284d]: / www / courseAdd.php  Maximize  Restore  History

Download this file

139 lines (123 with data), 4.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
$acctTypes = array("professor", "admin");
require_once("loginCheck.php");
$fatal = false;
// Ensure that the security random number is correct
$secure = false;
require_once("securityFunctions.php");
if (isset($_POST['securityRand']) && isset($_POST['securityPage']))
if (checkSecurity($_POST['securityPage'], $_POST['securityRand']) == 1)
$secure = true;
if($secure)
{
// Connect to database
include("connect.php");
// Check course name field for problems
if (!isset($_POST['name']) || $_POST['name'] == "")
{
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "Course name not entered.";
$fatal = true;
}
else if (strlen($_POST['name']) > 255)
{
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "Course name too long, truncating.";
}
// Check course section field for problems
if (!isset($_POST['section']) || $_POST['section'] == "")
{
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "Course section not entered.";
$fatal = true;
}
else if (strlen($_POST['section']) > 20)
{
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "Course section too long, truncating.";
}
// Check course semester field for problems
if (!isset($_POST['semester']) || ($_POST['semester'] != "Fall" && $_POST['semester'] != "Spring" && $_POST['semester'] != "Summer" && $_POST['semester'] != "Winter"))
{
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "Course semester invalid.";
$fatal = true;
}
// Check course year field for problems
if (!isset($_POST['year']) || !is_numeric($_POST['year']))
{
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "Course year invalid.";
$fatal = true;
}
$semester = "{$_POST['semester']} {$_POST['year']}";
// Check if admin and professor is set
if ($_SESSION['acctType'] == "admin")
{
if (!isset($_POST['professor']) || !is_numeric($_POST['professor']))
{
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "Course professor invalid.";
$fatal = true;
}
// Check if id corresponds to a professor
else
{
if (getUserAcctType($_POST['professor']) != "professor")
{
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "Course professor invalid.";
$fatal = true;
}
}
}
// Check course year field for problems
if (!isset($_POST['comment']))
{
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "Course comment not set.";
$fatal = true;
}
// Remove any html codes from posts
$_POST['name'] = strip_tags($_POST['name']);
$_POST['section'] = strip_tags($_POST['section']);
$_POST['comment'] = strip_tags($_POST['comment']);
// Add slashes to all fields if needed
if (!get_magic_quotes_gpc())
{
$_POST['name'] = addslashes($_POST['name']);
$_POST['section'] = addslashes($_POST['section']);
$_POST['comment'] = addslashes($_POST['comment']);
}
// Proceed with course registration if no fatal errors
if (!$fatal)
{
// Insert course into database
$profId = isset($_POST['professor']) ? $_POST['professor'] : $_SESSION['userId'];
if (addNewCourse($profId, $_POST['name'], $_POST['section'], $semester, $_POST['comment'], $_SESSION['schoolId']))
{
$_SESSION['msg']['success'] = "Course successfully added.";
}
else
{
/*
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "MySQL Error: " . mysql_error();
*/
}
}
unset($_SESSION['rand']);
mysql_close();
}
header("Location: courses.php");
?>