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

3
if ( $_REQUEST['modfunc'] === 'save' )
François Jacquet's avatar
François Jacquet committed
4
{
5
	if ( empty( $_REQUEST['st_arr'] ) )
François Jacquet's avatar
François Jacquet committed
6
	{
7 8
		BackPrompt( _( 'You must choose at least one student.' ) );
	}
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
	$st_list = "'" . implode( "','", $_REQUEST['st_arr'] ) . "'";

	$extra['WHERE'] = " AND s.STUDENT_ID IN (" . $st_list . ")";

	$months = array(
		1 => _( 'January' ),
		2 => _( 'February' ),
		3 => _( 'March' ),
		4 => _( 'April' ),
		5 => _( 'May' ),
		6 => _( 'June' ),
		7 => _( 'July' ),
		8 => _( 'August' ),
		9 => _( 'September' ),
		10 => _( 'October' ),
		11 => _( 'November' ),
		12 => _( 'December' ),
	);

	// Check Social Security + Gender fields exists before adding them to SELECT.
	$custom_RET = DBGet( "SELECT TITLE,ID
		FROM CUSTOM_FIELDS
		WHERE ID IN ('200000000','200000003')", array(), array( 'ID' ) );

	$extra['SELECT'] = ",ssm.CALENDAR_ID,ssm.START_DATE,ssm.END_DATE";

	foreach ( (array) $custom_RET as $id => $custom )
	{
		$extra['SELECT'] .= ",CUSTOM_" . $id;
	}
40

41 42 43
	// ACTIVE logic taken from GetStuList().
	$active = "'" . DBEscapeString( _( 'Active' ) ) . "'";
	$inactive = "'" . DBEscapeString( _( 'Inactive' ) ) . "'";
44

45 46 47 48 49 50
	$extra['SELECT'] .= ',' . db_case( array(
		"(ssm.SYEAR='" . UserSyear() . "' AND ('" . DBDate() . "'>=ssm.START_DATE AND ('" . DBDate() . "'<=ssm.END_DATE OR ssm.END_DATE IS NULL)))",
		'TRUE',
		$active,
		$inactive,
	) ) . ' AS STATUS';
François Jacquet's avatar
François Jacquet committed
51

52
	$RET = GetStuList( $extra );
53

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
	if ( empty( $RET ) )
	{
		BackPrompt( _( 'No Students were found.' ) );
	}

	// Change orientation to landscape.
	$_SESSION['orientation'] = 'landscape';

	$handle = PDFStart();

	?>
	<style>
		body {
			font-size: larger;
		}
	</style>
	<?php
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
	foreach ( (array) $RET as $student )
	{
		$calendar_RET = DBGet( "SELECT CASE WHEN
			MINUTES>=" . Config( 'ATTENDANCE_FULL_DAY_MINUTES' ) .
					" THEN '1.0' ELSE '0.5' END AS POS,
			trim(leading '0' from to_char(SCHOOL_DATE,'MM')) AS MON,
			trim(leading '0' from to_char(SCHOOL_DATE,'DD')) AS DAY
			FROM ATTENDANCE_CALENDAR
			WHERE CALENDAR_ID='" . $student['CALENDAR_ID'] . "'
			AND SCHOOL_DATE>='" . $student['START_DATE'] . "'" .
			( $student['END_DATE'] ? " AND SCHOOL_DATE<='" . $student['END_DATE'] . "'" : '' ),
			array(),
			array( 'MON', 'DAY' ) );

		$attendance_RET = DBGet( "SELECT
			trim(leading '0' from to_char(ad.SCHOOL_DATE,'MM')) AS MON,
			trim(leading '0' from to_char(ad.SCHOOL_DATE,'DD')) AS DAY,
			ad.STATE_VALUE
			FROM ATTENDANCE_DAY ad
			WHERE ad.STUDENT_ID='" . $student['STUDENT_ID'] . "'
			AND ad.SYEAR='" . UserSyear() . "'", array(), array( 'MON', 'DAY' ) );
		//echo '<pre>'; var_dump($calendar_RET); echo '</pre>';

		echo '<h2 class="center">' . $student['FULL_NAME'] . '</h2>';

		echo '<table class="width-100p">
		<tr><td>' . NoInput(
			$student['FULL_NAME'],
			_( 'Student Name' )
		) . '</td><td>' . NoInput(
			$student['STUDENT_ID'],
			sprintf( _( '%s ID' ), Config( 'NAME' ) )
		) . '</td><td>' . NoInput(
			( SchoolInfo( 'SCHOOL_NUMBER' ) ? SchoolInfo( 'SCHOOL_NUMBER' ) : SchoolInfo( 'TITLE' ) ) .
				' &mdash; ' . FormatSyear( UserSyear(), Config( 'SCHOOL_SYEAR_OVER_2_YEARS' ) ),
			_( 'School' ) . ' &mdash; ' . _( 'Year' )
		) . '</td></tr>';

		echo '<tr><td colspan="3"><hr /><h3>' . _( 'Demographics' ) . '</h3></td></tr><tr>';
François Jacquet's avatar
François Jacquet committed
111

112
		foreach ( (array) $custom_RET as $id => $custom )
113
		{
114 115 116 117 118
			echo '<td>' . NoInput(
				$student['CUSTOM_' . $id],
				ParseMLField( $custom_RET[$id][1]['TITLE'] )
			) . '</td>';
		}
119

120 121 122 123 124 125 126 127
		echo '</tr><tr>
		<td>' . NoInput(
			$student['STATUS'],
			_( 'Status' )
		) . '</td><td>' . NoInput(
			$student['GRADE_ID'],
			_( 'Grade Level' )
		) . '</td></tr>';
128

129 130
		echo '<tr><td colspan="3"><hr /><h3>' . _( 'Attendance' ) . '</h3>
		<table class="width-100p cellspacing-0 center">';
131

132
		echo '<tr class="center"><td><b>' . _( 'Month' ) . '</b></td>';
François Jacquet's avatar
François Jacquet committed
133

134 135 136 137 138
		for ( $day = 1; $day <= 31; $day++ )
		{
			echo '<td><b>' . ( $day < 10 ? '&nbsp;' : '' ) . $day .
				( $day < 10 ? '&nbsp;' : '' ) . '</b></td>';
		}
139

140 141
		echo '<td><b>' . _( 'Absences' ) . '</b></td>
		<td><b>' . _( 'Possible' ) . '</b></td></tr>';
142

143
		$abs_tot = $pos_tot = 0;
François Jacquet's avatar
François Jacquet committed
144

145 146 147 148 149
		$FY_dates = DBGet( "SELECT START_DATE,END_DATE
		FROM SCHOOL_MARKING_PERIODS
		WHERE MP='FY'
		AND SYEAR='" . UserSyear() . "'
		AND SCHOOL_ID='" . UserSchool() . "'" );
150

151 152
		$first_month = explode( '-', $FY_dates[1]['START_DATE'] );
		$first_month = (int) $first_month[1];
153

154 155
		$last_month = explode( '-', $FY_dates[1]['END_DATE'] );
		$last_month = (int) $last_month[1];
156

157
		//foreach ( array(7,8,9,10,11,12,1,2,3,4,5,6) as $month)
158

159 160 161 162 163 164 165 166
		if ( $last_month > $first_month )
		{
			$last_month_tmp = $last_month;
		}
		else
		{
			$last_month_tmp = 12;
		}
167

168 169 170 171 172 173 174 175 176 177
		$attendance_codes_locale = array(
			// Attendance codes.
			'P' => _( 'Present' ),
			'A' => _( 'Absent' ),
			'H' => _( 'Half Day' ),
			// Daily attendance.
			'1.0' => _( 'Present' ),
			'0.0' => _( 'Absent' ),
			'0.5' => _( 'Half Day' ),
		);
178

179 180 181 182 183 184 185 186 187 188
		$attendance_code_classes = array(
			// Attendance codes.
			'P' => 'present',
			'A' => 'absent',
			'H' => 'half-day',
			// Daily attendance.
			'1.0' => 'present',
			'0.0' => 'absent',
			'0.5' => 'half-day',
		);
François Jacquet's avatar
François Jacquet committed
189

190 191 192 193 194 195
		for ( $month = $first_month; $month <= $last_month_tmp; $month++ )
		{
			if ( ! empty( $calendar_RET[$month] )
				|| ! empty( $attendance_RET[$month] ) )
			{
				echo '<tr class="center"><td>' . $months[$month] . '</td>';
196

197
				$abs = $pos = 0;
198

199
				for ( $day = 1; $day <= 31; $day++ )
200
				{
201
					if ( ! empty( $calendar_RET[$month][$day] ) )
François Jacquet's avatar
François Jacquet committed
202
					{
203 204 205 206 207
						$calendar = $calendar_RET[$month][$day][1];

						if ( ! empty( $attendance_RET[$month][$day] ) )
						{
							$attendance = $attendance_RET[$month][$day][1];
208

209 210 211 212
							echo '<td class="attendance-code ' .
								$attendance_code_classes[ $attendance['STATE_VALUE'] ] . '"
								style="display: table-cell; padding: 0;">' .
								mb_substr( $attendance_codes_locale[ $attendance['STATE_VALUE'] ], 0, 1 ) . '</td>';
213

214 215 216 217 218 219 220
							$abs += ( $attendance['STATE_VALUE'] == '0.0' ?
								$calendar['POS'] :
								( $attendance['STATE_VALUE'] == '0.5' ? $calendar['POS'] / 2 : 0 )
							);
						}
						else
						//green box
221
						{
222
							echo '<td style="background-color:#dfd;">&nbsp;</td>';
François Jacquet's avatar
François Jacquet committed
223
						}
224

225
						$pos += $calendar['POS'];
226
					}
227
					else
228
					{
229
						// Attendance record before attendance start date!
François Jacquet's avatar
François Jacquet committed
230

231 232 233
						if ( ! empty( $attendance_RET[$month][$day] ) )
						{
							$attendance = $attendance_RET[$month][$day][1];
François Jacquet's avatar
François Jacquet committed
234

235 236 237 238 239 240 241 242 243 244 245 246 247
							//red box
							echo '<td class="attendance-code ' .
								$attendance_code_classes[ $attendance['STATE_VALUE'] ] . '"
								style="display: table-cell; padding: 0;">' .
								$attendance_codes_locale[ $attendance['STATE_VALUE'] ] . '</td>';
						}
						else
						//pink box
						{
							echo '<td style="background-color:#fdd;">&nbsp;</td>';
						}
					}
				}
François Jacquet's avatar
François Jacquet committed
248

249 250
				echo '<td>' . (float) number_format( $abs, 1 ) . '</td>
				<td>' . (float) number_format( $pos, 1 ) . '</td></tr>';
François Jacquet's avatar
François Jacquet committed
251

252 253
				$abs_tot += $abs;
				$pos_tot += $pos;
254
			}
255

256 257 258 259 260 261
			if ( $month == 12 && $last_month != 12 )
			{
				// School year over 2 calendar years, reset month to January.
				$month = 0;
				$last_month_tmp = $last_month;
			}
262
		}
263 264 265 266 267 268 269 270 271 272

		echo '<tr class="center"><td colspan="32" class="align-right"><b>' .
			_( 'Year to Date Totals' ) . '</b></td>';

		echo '<td>' . (float) number_format( $abs_tot, 1 ) . '</td>
		<td>' . (float) number_format( $pos_tot, 1 ) . '</td></tr>';

		echo '</table></td></tr></table>';

		echo '<div style="page-break-after: always;"></div>';
François Jacquet's avatar
François Jacquet committed
273
	}
274 275

	PDFStop( $handle );
François Jacquet's avatar
François Jacquet committed
276 277
}

278
if ( ! $_REQUEST['modfunc'] )
François Jacquet's avatar
François Jacquet committed
279
{
280
	DrawHeader( ProgramTitle() );
François Jacquet's avatar
François Jacquet committed
281

282
	if ( $_REQUEST['search_modfunc'] === 'list' )
François Jacquet's avatar
François Jacquet committed
283
	{
284
		echo '<form action="' . URLEscape( 'Modules.php?modname=' . $_REQUEST['modname'] .
285
			'&modfunc=save&include_inactive=' . issetVal( $_REQUEST['include_inactive'], '' ) .
286
			'&_ROSARIO_PDF=true' ) . '" method="POST">';
François Jacquet's avatar
François Jacquet committed
287

288
		$extra['header_right'] = SubmitButton( _( 'Create Attendance Report for Selected Students' ) );
François Jacquet's avatar
François Jacquet committed
289 290
	}

291 292
	$extra['link'] = array( 'FULL_NAME' => false );

François Jacquet's avatar
François Jacquet committed
293
	$extra['SELECT'] = ",s.STUDENT_ID AS CHECKBOX";
294

295
	$extra['functions'] = array( 'CHECKBOX' => 'MakeChooseCheckbox' );
296

297
	$extra['columns_before'] = array( 'CHECKBOX' => MakeChooseCheckbox( 'Y', '', 'st_arr' ) );
298

François Jacquet's avatar
François Jacquet committed
299
	$extra['options']['search'] = false;
300

François Jacquet's avatar
François Jacquet committed
301 302
	$extra['new'] = true;

303
	Widgets( 'course' );
François Jacquet's avatar
François Jacquet committed
304 305 306 307
	//Widgets('gpa');
	//Widgets('class_rank');
	//Widgets('letter_grade');

308
	Search( 'student_id', $extra );
309

310
	if ( $_REQUEST['search_modfunc'] === 'list' )
François Jacquet's avatar
François Jacquet committed
311
	{
312
		echo '<br /><div class="center">' . SubmitButton( _( 'Create Attendance Report for Selected Students' ) ) . '</div>';
François Jacquet's avatar
François Jacquet committed
313
		echo '</form>';
François Jacquet's avatar
François Jacquet committed
314 315
	}
}