-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduleCloner.php
419 lines (290 loc) · 12.6 KB
/
scheduleCloner.php
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<?php
DrawHeader( ProgramTitle() );
if( User( 'PROFILE' ) === 'admin'){
$canRun = true;
$warning = '';
//See if it time to save anything and Generate the new schedules
//echo('</pre>' . print_r($_REQUEST) . '</pre>');
if($_REQUEST['Generate'] == 'Generate'){
//echo('</pre>' . print_r($_REQUEST) . '</pre>');
//The last table is where any output from this click is going to write to. outputGenerate
//echo( 'from year ' . $_REQUEST['fromYear']);
testGenerateStatus($canRun,$warning);
}else{
$canRun = false;
}
//echo('<pre>' . print_r($_REQUEST) . '</pre>');
$info = 'This routine clones a current or past student SCHEDULE to current Active Student(s).</br>
The schedule shown for Clone Source Student will have both the original schedule Period names (if in the past) and the current Period names for identification purposes.</br></br>
<b> Make a system database backup prior to running the utility in the advent you make a mistake </b></br>
This module is not going to validate the number of students in the class or for conflicts of period.</br></br>
Step 1 : Chose filters to reduce the number of possible students as clone source.</br>
Step 2 : Click the class periods of the Clone Source or Select All</br>
Step 3 : Filter for Target Clone Students</br>
Step 4 : Click Target Students</br>
Step 5 : Process Schedules.(Generate Schedule) Last Step</br></br>';
$instructions = '<div class="table-responsive"><table style=width:80%;align:center><tr><td>' . $info . '</td></tr></table></div>';
echo $instructions;
/* Get the school name */
$schoolName = DBGET("SELECT TITLE
FROM SCHOOLS
WHERE ID = '" . UserSchool() . "'
AND SYEAR = '" . UserSYear() . "'");
// ================= Queries that can be run in advance ===============
$schoolYears = DBGET("SELECT SYEAR
FROM SCHOOLS
WHERE ID = '" . UserSchool() . "'");
$studentGrades = DBGET("SELECT ID, TITLE FROM
school_gradelevels
WHERE SCHOOL_ID = '" . UserSchool() . "'
ORDER BY TITLE ASC");
// =================== Mock Up Screen =============================================
echo '<form action="'. URLEscape( 'Modules.php?modname=' . $_REQUEST['modname'] . '&modfunc=submit') . '" method="POST">';
$actionBar = '<button type="submit" name="Generate" value="Generate">Generate Schedules</button></br></br>';
//echo($actionBar);
$actionBar = '<div class="table-responsive"><table style=width:80%;align:center><tr><td>' . $actionBar . '</td></tr></table></div>';
echo($actionBar);
//The source from which data will come
$createFromYear = '<select id="fromYear" name="fromYear" style="width:400px;")">';
$createFromYear .= '<option value="NO" selected> --- Select Clone Year Required --- </option>';
$createFromYear .= makeOptionSelects($schoolYears,'SYEAR');
$createFromYear .= '</select></br>';
$createFromGrade = '<select id="fromGrade" name="fromGrade" style="width:400px;")">';
$createFromGrade .= '<option value="NO" selected> --- Grade At Time of Schedule --- </option>';
$createFromGrade .= makeOptionSelects($studentGrades,'ID','TITLE');
$createFromGrade .= '</select></br>';
//Change this to a text box and use a LIKE
//Change this to a text box and use a LIKE
$createFromLastName = '<input type="text" id="fromLastName" name="fromLastName" placeholder="Last Name"<br>';
$createFromGoButton = '<button type="button" value="Sources" onclick="getStudents(this.value,' . UserSchool() .',null)">Populate Possible Sources</button></br></br>';
// === From sources is the creation of a possible list of students
$createFromSources = '<select id="fromSources" name="fromSources" style="width:400px;" onchange="myName(this.value,' . UserSyear() . ',' . UserSchool(). ')">';
$createFromSources .= '<option value="NO" selected> --- Possible Students --- </option>';
$createFromSources .= '</select></br>';
//=============================== Data Target =====================================
$createToGrade = '<select id="ToGrade" name="ToGrade" style="width:400px;">';
$createToGrade .= '<option value="NO" selected> --- Current Grade --- </option>';
$createToGrade .= makeOptionSelects($studentGrades,'ID','TITLE');
$createToGrade .= '</select></br>';
$createToLastName = '<input type="text" id="ToLastName" name="ToLastName" placeholder="Last Name"<br>';
$createToGoButton = '<button type="button" value="Targets" onclick="getStudents(this.value,' . UserSchool() . "," . UserSyear() . ')">List Targets</button>';
$cloneFromTable = '<table style="width:65%"><tr><td>' . $createFromYear . $createFromGrade . $createFromLastName . $createFromGoButton . $createFromSources . '</td></tr></table>';
$cloneToTable = '<table style="width:35%"><tr><td>' . $createToYear . $createToGrade . $createToLastName . $createToGoButton . '</td></tr></table>';
$headerTable = '<table border="1" style="width:80%"><tr><td>' . $cloneFromTable . '</td><td>' . $cloneToTable . '</td></tr>';
$headerTable .= '<tr><td valign=top><div id="fromClasses"><div></td>';
$headerTable .= '<td valign=top><div id="ToStudents"></div></td></tr></table>';
echo $headerTable;
echo('</form>');
// ============================== Generation Output ==================================
?>
<table>
<tr><td><div id="outputGenerate">
<?php echo( $warning);
if($canRun){
foreach($_REQUEST['targetStudents'] as $targetStudent){
echo(' have a number ' . $targetStudent);
foreach($_REQUEST['scheduleCourses'] as $course){
/* sets breaks down into
0 = OLDPERIOD
1 = NEWPERIOD
2 = OLDCOURSE
3 = NEWCOURSE
*/
$sets = explode('::',$course);
$oldPeriod = explode('==>',$sets[0]);
$newPeriod = explode('==>',$sets[1]);
$oldCourse = explode('==>',$sets[2]);
$newCourse = explode('==>',$sets[3]);
echo(' have a course ' . $sets[0]);
//Get the OLD Record to act as a template that will be modified
$oldRecord = DBGET("Select *
From schedule
Where course_period_id = '" . $oldPeriod[1] . "'
AND course_id = '" . $oldCourse[1] . "'
AND STUDENT_ID = '" . $_REQUEST['fromSources'] . "'"
);
//echo('<pre>' . print_r($oldRecord,true) . '</pre>');
//Validate that a new record does not exist
$newRecord = DBGET("Select *
From schedule
Where course_period_id = '" . $newPeriod[1] . "'
AND course_id = '" . $newCourse[1] . "'
AND STUDENT_ID = '" . $targetStudent . "'"
);
//echo('<pre>' . print_r($newRecord,true) . '</pre>');
if(empty($newRecord)){
/*Update the oldrecord fields to make them into what we need for this new year,
new record, new student
Fields we want to update are
SYEAR
STUDENT_ID
START_DATE == YYYY-MM-DD
COURSE_ID
COURSE_PERIOD_ID
*/
echo('</br></br>Scheduling Student ID: ' . $targetStudent . '</br>');
echo(" CLASS ID: " . $newPeriod[1] . '</br>');
$oldRecord[1]['SYEAR'] = UserSyear();
$oldRecord[1]['STUDENT_ID'] = $targetStudent;
$oldRecord[1]['COURSE_ID'] = $newCourse[1];
$oldRecord[1]['COURSE_PERIOD_ID'] = $newPeriod[1];
$oldRecord[1]['START_DATE'] = '2021-08-30';
$oldRecord[1]['CREATED_AT'] = NULL;
//echo('<pre>' . print_r($oldRecord,true) . '</pre>');
//Time to run an insert QUERY
DBQuery("INSERT INTO SCHEDULE
(SYEAR,SCHOOL_ID,STUDENT_ID,START_DATE,COURSE_ID,COURSE_PERIOD_ID,MP,MARKING_PERIOD_ID)
VALUES(" . $oldRecord[1]['SYEAR'] . "," .
$oldRecord[1]['SCHOOL_ID'] . "," .
$oldRecord[1]['STUDENT_ID'] . ",'" .
$oldRecord[1]['START_DATE'] . "'," .
$oldRecord[1]['COURSE_ID'] . "," .
$oldRecord[1]['COURSE_PERIOD_ID'] . ",'" .
$oldRecord[1]['MP'] . "','12')"
);
}//checking and updating oldRecord with new
}//Looking at each course cycling by each target student
}//Looking at each target student
}// canRun is true and we process this
?>
</div></td></tr>
</table>
<?php
}else{ //your not an admin so go away.
$info = 'This is an administrative function only</br></br>';
$instructions = '<div class="table-responsive"><table style=width:80%;align:center><tr><td>' . $info . '</td></tr></table></div>';
echo $instructions;
}
//Test to see if we can do anything after Generate is hit.. Check all the input and output error messages.
function testGenerateStatus(&$canRun,&$warning){
//This needs to become a function of all possible warnings.
if($_REQUEST['fromYear'] == 'NO'){
$warning .= 'No Source Year Selected</br>';
$canRun = false;
}
if($_REQUEST['fromGrade'] == 'NO'){
$warning .= 'No Source Grade Selected</br>';
$canRun = false;
}
if($_REQUEST['fromSources'] == 'NO'){
$warning .= 'No Source Student Selected</br>';
$canRun = false;
}
if($_REQUEST['ToGrade'] == 'NO'){
$warning .= 'No Target Grade Selected</br>';
$canRun = false;
}
if(empty($_REQUEST['fromSources']) || ! isset($_REQUEST['fromSources'])){
$warning .= 'No Source Courses Selected</br>';
$canRun = false;
}
if(empty($_REQUEST['targetStudents'])){
$warning .= 'No Target Students Selected</br>';
$canRun = false;
}
}
function makeOptionSelects($singleArray,$values, $words = NULL){
$Select = '';
if($words == NULL){
$words = $values;
}
foreach($singleArray as $record){
$Select .= '<option value="' .
$record[$values] .'">' . $record[$words] . '</option>';
}
return $Select;
}
?>
<script type="text/javascript">
function getStudents(sourceOrTarget,schoolid,currentyear){
//alert(sourceOrTarget);
if(sourceOrTarget == "Sources"){
var elem = 'from';
var selectYear = $('#' + elem + 'Year').val(); // en
var type = 'selectOption';
}else{
var elem = 'To';
var selectYear = currentyear;
var type = 'checkbox';
}
//alert(elem + ' ' + selectYear);
//var selectYear = $('#' + elem + 'Year').val(); // en
var selectGrade = $('#' + elem + 'Grade').val(); // en
var textLastName = $('#' + elem + 'LastName').val(); // English
$.ajax({
url: 'modules/Utilities/getStudents.fnc.php',
type: 'POST',
//dataType: 'JSON',
data:{year: selectYear,
grade: selectGrade,
lastname: textLastName,
school_id: schoolid,
returnType: type},
success: function(response){
//Log the data to the console so that
//you can get a better view of what the script is returning.
//console.log(response);
if(sourceOrTarget == "Sources"){
$('#' + elem +'Sources').html(response);
}else{
//alert(response);
var studentList =
$('#ToStudents').html(response);
}
},
error:function(x,e) {
if (x.status==0) {
alert('You are offline!!\n Please Check Your Network.');
} else if(x.status==404) {
alert('Requested URL not found.');
} else if(x.status==500) {
alert('Internel Server Error.');
} else if(e=='parsererror') {
alert('Error.\nParsing JSON Request failed.');
} else if(e=='timeout'){
alert('Request Time out.');
} else {
alert('Unknow Error.\n'+x.responseText);
}
}
});
//alert(selectYear + selectGrade);
}
function myName(val,syear,schoolid) {
// body...
//alert(val);
var sourceYear = $('#fromYear').val(); // en
//alert(sourceYear + ' ' + syear + ' ' + schoolid + ' ' + val);
$.ajax({
url: 'modules/Utilities/getClasses.fnc.php',
type: 'POST',
//dataType: 'JSON',
data:{year: syear,
source_year: sourceYear,
studentid: val,
school_id: schoolid},
success: function(response){
//Log the data to the console so that
//you can get a better view of what the script is returning.
//console.log(response);
$('#fromClasses').html(response);
},
error:function(x,e) {
if (x.status==0) {
alert('You are offline!!\n Please Check Your Network.');
} else if(x.status==404) {
alert('Requested URL not found.');
} else if(x.status==500) {
alert('Internel Server Error.');
} else if(e=='parsererror') {
alert('Error.\nParsing JSON Request failed.');
} else if(e=='timeout'){
alert('Request Time out.');
} else {
alert('Unknow Error.\n'+x.responseText);
}
}
});
//alert(selectYear + selectGrade);
}
</script>