[go: up one dir, main page]

Menu

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

Download this file

257 lines (221 with data), 8.1 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
// IMPORTANT: If you allow editing of an existing doclet, you must make sure
// that any assignments that used the default values are updated so that they
// still use the previous default value. This involves inserting rows into
// the database for each assignment.
$acctTypes = "admin";
require_once("loginCheck.php");
// Connect to database
require_once("connect.php");
require_once("mysqlFunctions.php");
if (!empty($_POST))
{
$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)
{
// Check for errors
$error = array();
// Check name field for problems
if (!isset($_POST['name']) || $_POST['name'] == "")
{
$error[] = "Doclet name not entered.";
$fatal = true;
}
else if (strlen($_POST['name']) > 255)
{
$error[] = "Doclet name too long, truncating.";
$_POST['name'] = substr($_POST['name'], 0, 255);
}
// Check description field for problems
if (!isset($_POST['desc']) || $_POST['desc'] == "")
{
$error[] = "Doclet description not entered.";
$fatal = true;
}
else if (strlen($_POST['desc']) > 255)
{
$error[] = "Doclet description too long, truncating.";
$_POST['desc'] = substr($_POST['desc'], 0, 255);
}
// Check javaName field for problems
if (!isset($_POST['javaName']) || $_POST['javaName'] == "")
{
$error[] = "Java class name not entered.";
$fatal = true;
}
else if (strlen($_POST['javaName']) > 255)
{
$error[] = "Java class name too long";
$fatal = true;
}
// Remove any html codes from posts
$_POST['name'] = strip_tags($_POST['name']);
$_POST['desc'] = strip_tags($_POST['desc']);
$_POST['javaName'] = strip_tags($_POST['javaName']);
// Add slashes to all fields if needed
if (!get_magic_quotes_gpc())
{
$_POST['name'] = addslashes($_POST['name']);
$_POST['desc'] = addslashes($_POST['desc']);
$_POST['javaName'] = addslashes($_POST['javaName']);
}
// Assign errors
if (!empty($error))
$_SESSION['msg']['error'] = implode('<br/>', $error);
else
$_SESSION['msg']['error'] = "";
// Proceed if no fatal errors
if (!$fatal)
{
// Insert doclet into database
switch (addDoclet($_POST['name'], $_POST['desc'], $_POST['javaName'], $docletId))
{
case 0:
$_SESSION['msg']['success'] = 'Doclet successfully added.';
break;
default:
$_SESSION['msg']['error'] .= 'There was an error adding the doclet.';
break;
}
// Add grading options
if (is_numeric($docletId))
{
// Add each section grade
if (isset($_POST['sectionName']) && isset($_POST['sectionDesc']) && isset($_POST['sectionDefault']))
{
$error = "";
if (count($_POST['sectionName']) != count($_POST['sectionDesc']) || count($_POST['sectionName']) != count($_POST['sectionDefault']))
$error = "Error adding sections.<br/>";
else
{
foreach ($_POST['sectionName'] as $idx=>$name)
{
// Last one will be blank
$valid = true;
if ($idx != count($_POST['sectionName']))
{
if (empty($name) || empty($_POST['sectionDesc'][$idx]) || $_POST['sectionDefault'][$idx] === null)
{
// Ignore completely blank rows
if (!empty($name) || !empty($_POST['sectionDesc'][$idx]) || !empty($_POST['sectionDefault'][$idx]))
$error = "Failed to add section(s). Section details must be filled in.<br/>";
$valid = false;
}
}
else
$valid = false;
if ($valid && !addDocletSection($docletId, $name, $_POST['sectionDesc'][$idx], $_POST['sectionDefault'][$idx]))
$error = "Failed to add section(s).<br/>";
}
}
if (!empty($error))
$_SESSION['msg']['error'] .= $error;
}
// Add each param grade
if (isset($_POST['paramName']) && isset($_POST['paramDesc']) && isset($_POST['paramValue']))
{
$error = "";
if (count($_POST['paramName']) != count($_POST['paramDesc']) || count($_POST['paramName']) != count($_POST['paramValue']))
$error = "Error adding params.<br/>";
else
{
foreach ($_POST['paramName'] as $idx=>$name)
{
// Last one will be blank
$valid = true;
if ($idx != count($_POST['paramName']))
{
if (empty($name) || empty($_POST['paramDesc'][$idx]) || $_POST['paramValue'][$idx] === null)
{
// Ignore completely blank rows
if (!empty($name) || !empty($_POST['paramDesc'][$idx]) || !empty($_POST['paramValue'][$idx]))
$error = "Failed to add param(s). Param details must be filled in.<br/>";
$valid = false;
}
}
else
$valid = false;
if ($valid && !addDocletParam($docletId, $name, $_POST['paramDesc'][$idx], $_POST['paramValue'][$idx]))
$error = "Failed to add param(s).<br/>";
}
}
if (!empty($error))
$_SESSION['msg']['error'] .= $error;
}
}
}
// Remove the error message if empty
if ($_SESSION['msg']['error'] == "")
unset($_SESSION['msg']['error']);
}
// Security information incorrect
else
$_SESSION['msg']['error'] = 'Security Error.';
header("Location: index.php");
exit;
}
require_once("smarty/Smarty.class.php");
$tpl = new Smarty();
require_once("header1.php");
// Assign information if editing
$tpl->assign('editing', $editing);
if ($editing)
{
$tpl->assign('name', $assignment['name']);
// Open and close times
$tpl->assign('openTime', $assignment['openTime']);
$tpl->assign('closeTime', $assignment['closeTime']);
// Get and assign current reporting options
if ($options = getAssignmentOptions($assignmentId))
$tpl->assign('assignmentOptions', $options);
$submissions = numAssignmentSubmissions($_GET['assignment_id']);
$tpl->assign("gradeInputsEnabled", ($submissions == 0));
}
// Get report types (doclets) from database
$params = array(
'GetGradeSections'=>true,
'GetGradingParams'=>true,
);
// Get security fields
require_once("securityFunctions.php");
$tpl->assign(securityFormInputs());
// Assign breadcrumbs
$breadcrumbs = array();
$breadcrumbs[] = array('text' => 'COMTOR', 'href' => 'index.php');
$breadcrumbs[] = array('text' => 'Add Doclet', 'href' => 'doclet_add.php');
$tpl->assign('breadcrumbs', $breadcrumbs);
// Register function to determine input values
$tpl->register_function('gradeSectionInputValue', 'gradeSectionInputValue');
$tpl->register_function('gradeParameterInputValue', 'gradeParameterInputValue');
// Fetch template
$tpldata = $tpl->fetch('doclet_add.tpl');
$tpl->assign('tpldata', $tpldata);
// Display template
$tpl->display("htmlmain.tpl");
function gradeSectionInputValue($params, &$tpl)
{
if(empty($params['docletGradeSectionId']))
return "";
else
{
global $gradeSections;
return $gradeSections[$params['docletGradeSectionId']];
}
}
function gradeParameterInputValue($params, &$tpl)
{
if(empty($params['docletGradeParameterId']))
return "";
else
{
global $gradingParams;
return $gradingParams[$params['docletGradeParameterId']];
}
}
?>