DuplicateAttendance.php 10.9 KB
Newer Older
François Jacquet's avatar
François Jacquet committed
1 2
<?php

3 4
DrawHeader( ProgramTitle() );

François Jacquet's avatar
François Jacquet committed
5 6
$_REQUEST['delete'] = issetVal( $_REQUEST['delete'], '' );

François Jacquet's avatar
François Jacquet committed
7
if ( ! empty( $_REQUEST['mp_arr'] ) )
François Jacquet's avatar
François Jacquet committed
8
{
9 10
	foreach ( (array) $_REQUEST['mp_arr'] as $mp )
	{
François Jacquet's avatar
François Jacquet committed
11
		$mp_list .= ",'" . $mp . "'";
12 13
	}

François Jacquet's avatar
François Jacquet committed
14
	$mp_list = mb_substr( $mp_list, 1 );
15
	$last_mp = $mp;
François Jacquet's avatar
François Jacquet committed
16 17 18 19 20 21 22
}

//Widgets('course');
//Widgets('gpa');
//Widgets('class_rank');
//Widgets('letter_grade');

François Jacquet's avatar
François Jacquet committed
23
if ( $_REQUEST['delete'] === 'true' )
François Jacquet's avatar
François Jacquet committed
24
{
25
	//DeletePrompt(_('Duplicate Attendance Record'));
François Jacquet's avatar
François Jacquet committed
26 27

	if ( ! empty( $_REQUEST['deletecheck'] ) )
28
	{
François Jacquet's avatar
François Jacquet committed
29
		if ( DeletePrompt( _( 'Duplicate Attendance Record' ) ) )
30
		{
François Jacquet's avatar
François Jacquet committed
31
			set_time_limit( 0 );
32 33 34 35

			$i = 0;
			$ii = 0;
			$iii = 0;
36 37 38 39
			$sid = issetVal( $_REQUEST['studentidx'] );
			$cnt = issetVal( $_REQUEST['deletecheck'] );
			$pid = issetVal( $_REQUEST['periodidx'] );
			$sdt = issetVal( $_REQUEST['schooldatex'] );
40

François Jacquet's avatar
François Jacquet committed
41
			foreach ( (array) $cnt as $a => $val_dchck )
42
			{
43
				$val1 = $val_dchck;
François Jacquet's avatar
François Jacquet committed
44 45

				if ( $val1 >= 0 )
46 47
				{
					//echo "$val1 |";
François Jacquet's avatar
François Jacquet committed
48 49

					foreach ( (array) $sid as $b => $val_sid )
50 51
					{
						$val2 = $val_sid;
François Jacquet's avatar
François Jacquet committed
52 53

						if ( $val1 == $i )
54 55
						{
							//echo "$val2 - $i||| ";
François Jacquet's avatar
François Jacquet committed
56 57

							foreach ( (array) $pid as $c => $val_pid )
58 59
							{
								$val3 = $val_pid;
François Jacquet's avatar
François Jacquet committed
60 61

								if ( $val1 == $ii )
62 63
								{
									//echo "$val1 - $val2 - $val3 ||| ";
François Jacquet's avatar
François Jacquet committed
64 65

									foreach ( (array) $sdt as $d => $val_sdt )
66 67
									{
										$val4 = $val_sdt;
François Jacquet's avatar
François Jacquet committed
68 69

										if ( $val1 == $iii )
70 71
										{
											//echo "$val1 - $val2 - $val3 - $val4 ||| ";
François Jacquet's avatar
François Jacquet committed
72
											DBQuery( "DELETE FROM ATTENDANCE_PERIOD WHERE STUDENT_ID='" . $val2 . "' AND SCHOOL_DATE='" . $val4 . "' AND COURSE_PERIOD_ID='" . $val3 . "'" );
73
										}
François Jacquet's avatar
François Jacquet committed
74

75 76
										$iii++;
									}
François Jacquet's avatar
François Jacquet committed
77

78 79
									$iii = 0;
								}
François Jacquet's avatar
François Jacquet committed
80

81
								$ii++;
82
							}
François Jacquet's avatar
François Jacquet committed
83

84 85
							$ii = 0;
						}
François Jacquet's avatar
François Jacquet committed
86

87
						$i++;
88
					}
François Jacquet's avatar
François Jacquet committed
89

90 91 92
					$i = 0;
				}
			}
François Jacquet's avatar
François Jacquet committed
93

94
			//foreach ( (array) $sid as $b => $val_sid){
95 96 97
			//        $val2 = $val_sid;
			//        echo "$val2| ";
			//}
François Jacquet's avatar
François Jacquet committed
98

François Jacquet's avatar
François Jacquet committed
99
			$note[] = button( 'check' ) . '&nbsp;' . _( 'The duplicate records have been deleted.' );
100
		}
101 102
	}
	else
François Jacquet's avatar
François Jacquet committed
103 104 105
	{
		$error[] = _( 'You must choose at least one student.' );
	}
106

107 108 109
	if ( $note
		|| $error )
	{
François Jacquet's avatar
François Jacquet committed
110 111
		// Unset delete & redirect URL.
		RedirectURL( 'delete' );
112
	}
François Jacquet's avatar
François Jacquet committed
113 114
}

François Jacquet's avatar
François Jacquet committed
115 116 117
if ( isset( $_REQUEST['search_modfunc'] )
	&& $_REQUEST['search_modfunc'] === 'list'
	&& $_REQUEST['delete'] !== 'true' )
François Jacquet's avatar
François Jacquet committed
118
{
François Jacquet's avatar
François Jacquet committed
119
	$RET = GetStuList( $extra );
François Jacquet's avatar
François Jacquet committed
120

François Jacquet's avatar
François Jacquet committed
121
	if ( isset( $_REQUEST['page'] ) )
122
	{
François Jacquet's avatar
François Jacquet committed
123
		$urlpage = $_REQUEST['page'];
124 125 126
	}
	else
	{
François Jacquet's avatar
François Jacquet committed
127 128 129 130 131 132 133 134
		$urlpage = 1;
	}

	$firstrow = 1;
	$rows_per_page = 25;
	$endrow = $urlpage * $rows_per_page;
	$startrow = $endrow - $rows_per_page;

François Jacquet's avatar
François Jacquet committed
135
	//echo "Startrow: $startrow  Endrow: $endrow <br />";
François Jacquet's avatar
François Jacquet committed
136

François Jacquet's avatar
François Jacquet committed
137 138 139
	if ( ! empty( $RET ) )
	{
		unset( $extra );
François Jacquet's avatar
François Jacquet committed
140 141

		$extra['SELECT_ONLY'] = "ap.COURSE_PERIOD_ID,s.STUDENT_ID," . DisplayNameSQL( 's' ) . " AS FULL_NAME,
142
		ap.SCHOOL_DATE,cp.TITLE,ap.PERIOD_ID,sc.START_DATE,sc.END_DATE ";
François Jacquet's avatar
François Jacquet committed
143 144 145

		$extra['FROM'] = " ,ATTENDANCE_PERIOD ap,COURSE_PERIODS cp,SCHEDULE sc ";

146 147
		//$extra['WHERE'] .= " AND ssm.student_id=s.student_id AND ap.STUDENT_ID=s.STUDENT_ID AND ap.COURSE_PERIOD_ID = cp.COURSE_PERIOD_ID AND ('".DBDate()."' BETWEEN ssm.START_DATE AND ssm.END_DATE OR ssm.END_DATE IS NULL) ";
		//$extra['WHERE'] .= " AND ssm.student_id=s.student_id AND ap.STUDENT_ID=s.STUDENT_ID AND ap.COURSE_PERIOD_ID = cp.COURSE_PERIOD_ID ";
François Jacquet's avatar
François Jacquet committed
148 149 150 151 152 153 154 155

		$extra['WHERE'] = " AND ap.STUDENT_ID=s.STUDENT_ID
			AND sc.STUDENT_ID=s.STUDENT_ID
			AND ap.COURSE_PERIOD_ID=cp.COURSE_PERIOD_ID
			AND ap.COURSE_PERIOD_ID=sc.COURSE_PERIOD_ID
			AND sc.END_DATE>'1999-01-01' ";

		$extra['ORDER_BY'] = ' STUDENT_ID,COURSE_PERIOD_ID,SCHOOL_DATE';
156

François Jacquet's avatar
François Jacquet committed
157 158 159 160
		Widgets( 'course' );
		Widgets( 'gpa' );
		Widgets( 'class_rank' );
		Widgets( 'letter_grade' );
161

François Jacquet's avatar
François Jacquet committed
162
		$pageresult1 = GetStuList( $extra );
163 164

		$totalrows = 0;
François Jacquet's avatar
François Jacquet committed
165 166

		foreach ( (array) $pageresult1 as $rr )
167
		{
François Jacquet's avatar
François Jacquet committed
168 169 170 171 172
			$afterr = "N";

			$studentidr = $rr['STUDENT_ID'];
			$courseidr = $rr['COURSE_PERIOD_ID'];
			$periodidr = $rr['PERIOD_ID'];
173
			$full_namer = $rr['FULL_NAME'];
François Jacquet's avatar
François Jacquet committed
174 175 176 177 178
			$schooldater = $rr['SCHOOL_DATE'];
			$titler = $rr['TITLE'];
			$startr = $rr['START_DATE'];
			$endr = $rr['END_DATE'];

François Jacquet's avatar
François Jacquet committed
179
			if ( $schooldater > $endr )
180 181
			{
				$afterr = "Y";
François Jacquet's avatar
François Jacquet committed
182 183
			}

François Jacquet's avatar
François Jacquet committed
184
			if (  ( $studentidr == $studentid2 ) && ( $courseidr == $courseid2 ) && ( $schooldater == $schooldate2 ) && ( $startr == $start2 ) )
185 186 187
			{
				$totalrows++;
			}
François Jacquet's avatar
François Jacquet committed
188
			elseif (  ( $schooldater > $endr ) && ( $endr != NULL ) && ( $startr == $start2 ) )
189 190 191 192 193
			{
				$totalrows++;
			}
			else
			{
François Jacquet's avatar
François Jacquet committed
194
				//Do nothing
195
			}
François Jacquet's avatar
François Jacquet committed
196

197 198 199 200
			$studentid2 = $studentidr;
			$courseid2 = $courseidr;
			$periodid2 = $periodidr;
			$schooldate2 = $schooldater;
201
			$full_name2 = $full_namer;
202 203 204 205
			$title2 = $titler;
			$start2 = $startr;
			$end2 = $endr;
		}
François Jacquet's avatar
François Jacquet committed
206

207 208
		//echo "$totalrows";

François Jacquet's avatar
François Jacquet committed
209
		unset( $extra );
François Jacquet's avatar
François Jacquet committed
210 211

		$extra['SELECT_ONLY'] = "ap.COURSE_PERIOD_ID,s.STUDENT_ID," . DisplayNameSQL( 's' ) . " AS FULL_NAME,
212
		ap.SCHOOL_DATE,cp.TITLE,cp.SHORT_NAME,ap.PERIOD_ID,sc.START_DATE,sc.END_DATE ";
François Jacquet's avatar
François Jacquet committed
213 214 215

		$extra['FROM'] = ",ATTENDANCE_PERIOD ap,COURSE_PERIODS cp,SCHEDULE sc ";

216 217
		//$extra['WHERE'] .= " AND ssm.student_id=s.student_id AND ap.STUDENT_ID=s.STUDENT_ID AND ap.COURSE_PERIOD_ID = cp.COURSE_PERIOD_ID AND ('".DBDate()."' BETWEEN ssm.START_DATE AND ssm.END_DATE OR ssm.END_DATE IS NULL) ";
		//$extra['WHERE'] .= " AND ssm.student_id=s.student_id AND ap.STUDENT_ID=s.STUDENT_ID AND ap.COURSE_PERIOD_ID = cp.COURSE_PERIOD_ID ";
François Jacquet's avatar
François Jacquet committed
218 219 220 221 222 223 224 225

		$extra['WHERE'] = " AND ap.STUDENT_ID=s.STUDENT_ID
			AND sc.STUDENT_ID=s.STUDENT_ID
			AND ap.COURSE_PERIOD_ID=cp.COURSE_PERIOD_ID
			AND ap.COURSE_PERIOD_ID=sc.COURSE_PERIOD_ID
			AND sc.END_DATE>'1999-01-01' ";

		$extra['ORDER_BY'] = ' STUDENT_ID,COURSE_PERIOD_ID,SCHOOL_DATE';
226

François Jacquet's avatar
François Jacquet committed
227 228 229 230
		Widgets( 'course' );
		Widgets( 'gpa' );
		Widgets( 'class_rank' );
		Widgets( 'letter_grade' );
231

François Jacquet's avatar
François Jacquet committed
232
		$result1 = GetStuList( $extra );
233

234
		echo ErrorMessage( $error );
François Jacquet's avatar
François Jacquet committed
235

236
		echo ErrorMessage( $note, 'note' );
François Jacquet's avatar
François Jacquet committed
237

238
		echo '<form action="' . URLEscape( 'Modules.php?modname=Attendance/DuplicateAttendance.php&modfunc=&search_modfunc=list&next_modname=Attendance/DuplicateAttendance.php&delete=true' ) . '" method="POST">';
François Jacquet's avatar
François Jacquet committed
239

240
		DrawHeader( '', SubmitButton( _( 'Delete' ) ) );
François Jacquet's avatar
François Jacquet committed
241

242 243
		$num_rows = $totalrows;

François Jacquet's avatar
François Jacquet committed
244
		if ( $num_rows > $rows_per_page )
245
		{
François Jacquet's avatar
François Jacquet committed
246 247
			$totalpages = $num_rows / $rows_per_page;
			$totalpages = ceil( $totalpages );
François Jacquet's avatar
François Jacquet committed
248

François Jacquet's avatar
François Jacquet committed
249
			echo '<br />';
François Jacquet's avatar
François Jacquet committed
250
			echo '<div class="center">' . _( 'Page' ) . ': ';
François Jacquet's avatar
François Jacquet committed
251 252 253
			$first = 0;
			$ii = 1;

François Jacquet's avatar
François Jacquet committed
254 255 256
			for ( $i = 0; $i < $totalpages; $i++ )
			{
				if ( $urlpage == $ii )
257
				{
François Jacquet's avatar
François Jacquet committed
258
					echo '<b>' . $ii . '</b> &nbsp;';
259 260 261
				}
				else
				{
François Jacquet's avatar
François Jacquet committed
262
					echo '<a href="Modules.php?modname=Attendance/DuplicateAttendance.php&modfunc=&search_modfunc=list&next_modname=Attendance/DuplicateAttendance.php&delete=false&page=' . $ii . '">' . $ii . '</a> &nbsp;';
François Jacquet's avatar
François Jacquet committed
263
				}
François Jacquet's avatar
François Jacquet committed
264

François Jacquet's avatar
François Jacquet committed
265 266 267
				$first = $first + $rows_per_page;
				$ii++;
			}
268

François Jacquet's avatar
François Jacquet committed
269
			echo sprintf( _( 'of %d pages.' ), $totalpages );
François Jacquet's avatar
François Jacquet committed
270
			echo '</div>';
François Jacquet's avatar
François Jacquet committed
271 272
		}

François Jacquet's avatar
François Jacquet committed
273
		echo '<br /><table class="widefat rt center">';
274
		echo '<thead><tr><th class="column_heading"><input type="checkbox" value="Y" name="controller" onclick="checkAll(this.form,this.checked,\'deletecheck\');" /> &nbsp</th>';
François Jacquet's avatar
François Jacquet committed
275

François Jacquet's avatar
François Jacquet committed
276 277 278 279 280
		echo '<th>' . _( 'Student' ) . ' (' . sprintf( _( '%s ID' ), Config( 'NAME' ) ) . ')</th>
			<th>' . _( 'Course' ) . ' (' . _( 'Course Period ID' ) . ')</th>
			<th>' . _( 'Course Start Date' ) . '</th>
			<th>' . _( 'Course End Date' ) . '</th>
			<th>' . _( 'Attendance Date' ) . '</th></tr></thead><tbody>';
François Jacquet's avatar
François Jacquet committed
281 282 283 284 285 286

		$URIcount = 0;
		$count = 0;
		$yellow = 1;
		$after = "N";

François Jacquet's avatar
François Jacquet committed
287
		foreach ( (array) $result1 as $r )
288
		{
François Jacquet's avatar
François Jacquet committed
289 290 291 292 293
			$after = "N";

			$studentid = $r['STUDENT_ID'];
			$courseid = $r['COURSE_PERIOD_ID'];
			$periodid = $r['PERIOD_ID'];
294
			$full_name = $r['FULL_NAME'];
François Jacquet's avatar
François Jacquet committed
295 296 297 298 299 300
			$schooldate = $r['SCHOOL_DATE'];
			$title = $r['TITLE'];
			$short_name = $r['SHORT_NAME'];
			$start = $r['START_DATE'];
			$end = $r['END_DATE'];

François Jacquet's avatar
François Jacquet committed
301
			if ( $schooldate > $end )
302 303
			{
				$after = "Y";
François Jacquet's avatar
François Jacquet committed
304 305
			}

François Jacquet's avatar
François Jacquet committed
306
			if (  ( $studentid == $studentid2 ) && ( $courseid == $courseid2 ) && ( $schooldate == $schooldate2 ) && ( $start == $start2 ) )
307
			{
François Jacquet's avatar
François Jacquet committed
308 309 310
				$URIcount++;
				//echo "$URIcount | ";

François Jacquet's avatar
François Jacquet committed
311 312
				if ( $URIcount > $startrow && $URIcount < $endrow )
				{
François Jacquet's avatar
François Jacquet committed
313 314 315 316
					echo '<input type="hidden" name="delete" value="true">
						<input type="hidden" name="studentidx[' . $count . ']" value="' . $studentid . '">
						<input type="hidden" name="periodidx[' . $count . ']" value="' . $courseid . '">
						<input type="hidden" name="schooldatex[' . $count . ']" value="' . $schooldate . '">';
François Jacquet's avatar
François Jacquet committed
317

François Jacquet's avatar
François Jacquet committed
318
					if ( $yellow == 0 )
319
					{
François Jacquet's avatar
François Jacquet committed
320 321
						$color = 'F8F8F9';
						$yellow++;
322 323 324
					}
					else
					{
François Jacquet's avatar
François Jacquet committed
325 326
						$color = Preferences( 'COLOR' );
						$yellow = 0;
François Jacquet's avatar
François Jacquet committed
327
					}
328

François Jacquet's avatar
François Jacquet committed
329 330
					echo '<tr>
						<td><input type="checkbox" name="deletecheck[' . $count . ']" value="' . $count . '"></td>
331
						<td>' . $full_name . ' (' . $studentid . ')</td>
François Jacquet's avatar
François Jacquet committed
332
						<td>' . $short_name . ' (' . $courseid . ')</td>
François Jacquet's avatar
François Jacquet committed
333 334 335 336
						<td>' . ProperDate( $start ) . '</td>
						<td>' . ProperDate( $end ) . '</td>
						<td>' . ProperDate( $schooldate ) . '</td>
					</tr>';
François Jacquet's avatar
François Jacquet committed
337

François Jacquet's avatar
François Jacquet committed
338
					$count++;
François Jacquet's avatar
François Jacquet committed
339
				}
340
			}
François Jacquet's avatar
François Jacquet committed
341
			elseif (  ( $schooldate > $end ) && ( $end != NULL ) && ( $start == $start2 ) )
342
			{
François Jacquet's avatar
François Jacquet committed
343 344 345
				$URIcount++;
				//echo "$URIcount | ";

François Jacquet's avatar
François Jacquet committed
346 347
				if ( $URIcount > $startrow && $URIcount < $endrow )
				{
François Jacquet's avatar
François Jacquet committed
348 349 350 351
					echo '<input type="hidden" name="delete" value="true">
						<input type="hidden" name="studentidx[' . $count . ']" value="' . $studentid . '">
						<input type="hidden" name="periodidx[' . $count . ']" value="' . $courseid . '">
						<input type="hidden" name="schooldatex[' . $count . ']" value="' . $schooldate . '">';
François Jacquet's avatar
François Jacquet committed
352

François Jacquet's avatar
François Jacquet committed
353
					if ( $yellow == 0 )
354
					{
François Jacquet's avatar
François Jacquet committed
355 356
						$color = 'F8F8F9';
						$yellow++;
357 358 359
					}
					else
					{
François Jacquet's avatar
François Jacquet committed
360 361
						$color = Preferences( 'COLOR' );
						$yellow = 0;
François Jacquet's avatar
François Jacquet committed
362
					}
363

François Jacquet's avatar
François Jacquet committed
364 365
					echo '<tr>
						<td><input type="checkbox" name="deletecheck[' . $count . ']" value="' . $count . '"></td>
366
						<td>' . $full_name . ' (' . $studentid . ')</td>
François Jacquet's avatar
François Jacquet committed
367 368 369 370 371
						<td>' . $short_name . ' (' . $courseid . ')</td>
						<td>' . ProperDate( $start ) . '</td>
						<td>' . ProperDate( $end ) . '</td>
						<td>' . ProperDate( $schooldate ) . '</td>
					</tr>';
François Jacquet's avatar
François Jacquet committed
372 373 374

					$count++;
				}
375 376 377
			}
			else
			{
François Jacquet's avatar
François Jacquet committed
378 379
				//echo "<tr><td>$studentid</td><td>$courseid</td></tr>";
				$duplicate = 0;
François Jacquet's avatar
François Jacquet committed
380 381
			}

François Jacquet's avatar
François Jacquet committed
382 383 384 385
			$studentid2 = $studentid;
			$courseid2 = $courseid;
			$periodid2 = $periodid;
			$schooldate2 = $schooldate;
386
			$full_name2 = $full_name;
François Jacquet's avatar
François Jacquet committed
387 388 389 390 391 392
			$title2 = $title;
			$start2 = $start;
			$end2 = $end;
			//echo "<tr><td>$studentid</td><td>$courseid</td></tr>";
			//echo "$studentid | $courseid";
		}
393

394 395 396
		if ( $count == 0 )
		{
			echo '<tr><td colspan="6"><b>' . _( 'No Duplicates Found' ) . '</b></td></tr>';
François Jacquet's avatar
François Jacquet committed
397
			echo '</tbody></table>';
398 399 400
		}
		else
		{
François Jacquet's avatar
François Jacquet committed
401
			echo '</tbody></table>';
402
			echo '<br /><div class="center">' . SubmitButton( _( 'Delete' ) ) . '</div>';
François Jacquet's avatar
François Jacquet committed
403 404 405 406 407 408 409
		}

		echo '</form>';
		$RET = " ";
	}
	else
	{
François Jacquet's avatar
François Jacquet committed
410 411 412 413
		// Unset search modfunc & redirect URL.
		RedirectURL( 'search_modfunc' );

		$error[] = _( 'No Students were found.' );
François Jacquet's avatar
François Jacquet committed
414 415
	}
}
416

François Jacquet's avatar
François Jacquet committed
417 418
if ( ! $_REQUEST['search_modfunc']
	&& $_REQUEST['delete'] !== 'true' )
François Jacquet's avatar
François Jacquet committed
419
{
420
	echo ErrorMessage( $error );
421

422
	$extra['new'] = true;
François Jacquet's avatar
François Jacquet committed
423
	Search( 'student_id', $extra );
François Jacquet's avatar
François Jacquet committed
424 425
}

François Jacquet's avatar
François Jacquet committed
426 427 428 429 430
/**
 * @param $teacher
 * @param $column
 */
function _makeTeacher( $teacher, $column )
François Jacquet's avatar
François Jacquet committed
431
{
François Jacquet's avatar
François Jacquet committed
432
	return mb_substr( $teacher, mb_strrpos( str_replace( ' - ', ' ^ ', $teacher ), '^' ) + 2 );
François Jacquet's avatar
François Jacquet committed
433
}