[go: up one dir, main page]

Menu

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

Download this file

169 lines (149 with data), 5.2 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?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 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;
}
}
}
$profId = isset($_POST['professor']) ? $_POST['professor'] : $_SESSION['userId'];
// Check course id hidden field for problems
if (isset($_POST['courseId']) && is_numeric($_POST['courseId']))
{
if (!courseExists($_POST['courseId']))
{
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] = "Invalid course specified.";
$fatal = true;
}
// Check if user is a professor and this is his/her course
$courseInfo = getCourseInfo($_POST['courseId']);
if ($courseInfo && $_SESSION['acctType'] == "professor" && $profId != $courseInfo['profId'])
{
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "You cannot edit any course other than you own.";
$fatal = true;
}
}
else
{
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "Course to be edited was not specifed.";
$fatal = true;
}
// 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 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)
{
// Update course
if (updateCourseInfo($_POST['courseId'], $profId, $_POST['name'], $_POST['section'], $semester, $_POST['comment'], $_SESSION['schoolId']))
{
$_SESSION['msg']['success'] = "Course changes successfully applied.";
}
else
{
/*
if (!isset($_SESSION['msg']['error']))
$_SESSION['msg']['error'] = "";
$_SESSION['msg']['error'] .= "MySQL Error: " . mysql_error();
*/
}
}
mysql_close();
}
header("Location: courses.php");
?>