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

François Jacquet's avatar
François Jacquet committed
3
DrawHeader( ProgramTitle() );
François Jacquet's avatar
François Jacquet committed
4

François Jacquet's avatar
François Jacquet committed
5 6 7
Widgets( 'activity' );
Widgets( 'course' );
Widgets( 'eligibility' );
François Jacquet's avatar
François Jacquet committed
8

François Jacquet's avatar
François Jacquet committed
9
Search( 'student_id', $extra );
François Jacquet's avatar
François Jacquet committed
10

François Jacquet's avatar
François Jacquet committed
11 12 13
if ( $_REQUEST['modfunc'] === 'add'
	&& $_REQUEST['new_activity']
	&& AllowEdit() )
François Jacquet's avatar
François Jacquet committed
14
{
François Jacquet's avatar
François Jacquet committed
15
	// FJ fix bug add the same activity more than once.
16
	$activity_RET = DBGet( "SELECT ACTIVITY_ID
François Jacquet's avatar
François Jacquet committed
17 18 19
		FROM STUDENT_ELIGIBILITY_ACTIVITIES
		WHERE STUDENT_ID='" . UserStudentID() . "'
		AND ACTIVITY_ID='" . $_REQUEST['new_activity'] . "'
20
		AND SYEAR='" . UserSyear() . "'" );
François Jacquet's avatar
François Jacquet committed
21

François Jacquet's avatar
François Jacquet committed
22 23 24 25
	if ( ! empty( $activity_RET ) )
	{
		echo ErrorMessage( array( _( 'The activity you selected is already assigned to this student!' ) ) );
	}
François Jacquet's avatar
François Jacquet committed
26
	else
François Jacquet's avatar
François Jacquet committed
27 28 29
	{
		DBQuery( "INSERT INTO STUDENT_ELIGIBILITY_ACTIVITIES (STUDENT_ID,ACTIVITY_ID,SYEAR) values('" . UserStudentID() . "','" . $_REQUEST['new_activity'] . "','" . UserSyear() . "')" );
	}
François Jacquet's avatar
François Jacquet committed
30 31 32

	// Unset modfunc & new activity & redirect URL.
	RedirectURL( array( 'modfunc', 'new_activity' ) );
François Jacquet's avatar
François Jacquet committed
33 34
}

François Jacquet's avatar
François Jacquet committed
35 36 37
if ( $_REQUEST['modfunc'] === 'remove'
	&& AllowEdit()
	&& UserStudentID() )
François Jacquet's avatar
François Jacquet committed
38
{
39
	if ( DeletePrompt( _( 'Activity' ) ) )
François Jacquet's avatar
François Jacquet committed
40
	{
François Jacquet's avatar
François Jacquet committed
41 42 43 44
		DBQuery( "DELETE FROM STUDENT_ELIGIBILITY_ACTIVITIES
			WHERE STUDENT_ID='" . UserStudentID() . "'
			AND ACTIVITY_ID='" . $_REQUEST['activity_id'] . "'
			AND SYEAR='" . UserSyear() . "'" );
45

François Jacquet's avatar
François Jacquet committed
46 47
		// Unset modfunc & activity ID & redirect URL.
		RedirectURL( array( 'modfunc', 'activity_id' ) );
François Jacquet's avatar
François Jacquet committed
48 49 50
	}
}

François Jacquet's avatar
François Jacquet committed
51 52
if ( UserStudentID()
	&& ! $_REQUEST['modfunc'] )
François Jacquet's avatar
François Jacquet committed
53
{
54 55 56
	// GET ALL THE CONFIG ITEMS FOR ELIGIBILITY
	$eligibility_config = ProgramConfig( 'eligibility' );

57
	foreach ( (array) $eligibility_config as $value )
François Jacquet's avatar
François Jacquet committed
58
	{
59
		${$value[1]['TITLE']} = $value[1]['VALUE'];
François Jacquet's avatar
François Jacquet committed
60
	}
61

62 63
	// Day of the week: 1 (for Monday) through 7 (for Sunday).
	$today = date( 'w' ) ? date( 'w' ) : 7;
64

François Jacquet's avatar
François Jacquet committed
65
	$start = time() - ( $today - $START_DAY ) * 60 * 60 * 24;
66

67
	if ( empty( $_REQUEST['start_date'] ) )
François Jacquet's avatar
François Jacquet committed
68 69
	{
		$start_time = $start;
70

François Jacquet's avatar
François Jacquet committed
71
		$start_date = date( 'Y-m-d', $start_time );
72

François Jacquet's avatar
François Jacquet committed
73
		$end_date = DBDate();
François Jacquet's avatar
François Jacquet committed
74 75 76 77
	}
	else
	{
		$start_time = $_REQUEST['start_date'];
78

François Jacquet's avatar
François Jacquet committed
79
		$start_date = date( 'Y-m-d', $start_time );
80

François Jacquet's avatar
François Jacquet committed
81
		$end_date = date( 'Y-m-d', $start_time + 60 * 60 * 24 * 6 );
François Jacquet's avatar
François Jacquet committed
82 83
	}

84 85 86 87 88
	$begin_year = DBGetOne( "SELECT min(date_part('epoch',SCHOOL_DATE)) AS SCHOOL_DATE
		FROM ATTENDANCE_CALENDAR
		WHERE SCHOOL_ID='" . UserSchool() . "'
		AND SYEAR='" . UserSyear() . "'" );

François Jacquet's avatar
François Jacquet committed
89 90 91 92
	if ( is_null( $begin_year ) )
	{
		ErrorMessage( array( _( 'There are no calendars yet setup.' ) ), 'fatal' );
	}
93

François Jacquet's avatar
François Jacquet committed
94
//FJ display locale with strftime()
François Jacquet's avatar
François Jacquet committed
95 96
	//	$date_select = "<option value=$start>".date('M d, Y',$start).' - '.date('M d, Y',$end).'</option>';
	$date_select = '<option value="' . $start . '">' . ProperDate( date( 'Y-m-d', $start ) ) . ' - ' . ProperDate( DBDate() ) . '</option>';
François Jacquet's avatar
François Jacquet committed
97
	//exit(var_dump($begin_year));
François Jacquet's avatar
François Jacquet committed
98 99

	for ( $i = $start - ( 60 * 60 * 24 * 7 ); $i >= $begin_year; $i -= ( 60 * 60 * 24 * 7 ) )
100
//		$date_select .= "<option value=$i".(($i+86400>=$start_time && $i-86400<=$start_time)?' selected':'').">".date('M d, Y',$i).' - '.date('M d, Y',($i+1+(($END_DAY-$START_DAY))*60*60*24)).'</option>';
François Jacquet's avatar
François Jacquet committed
101 102 103
	{
		$date_select .= '<option value="' . $i . '"' . (  ( $i + 86400 >= $start_time && $i - 86400 <= $start_time ) ? ' selected' : '' ) . ">" . ProperDate( date( 'Y-m-d', $i ) ) . ' - ' . ProperDate( date( 'Y-m-d', ( $i + 1 + (  ( $END_DAY - $START_DAY ) ) * 60 * 60 * 24 ) ) ) . '</option>';
	}
104

François Jacquet's avatar
François Jacquet committed
105 106 107 108 109 110
	$date_select = '<select name="start_date" autocomplete="off">' . $date_select . '</select>';

	echo '<form action="' . PreparePHP_SELF( $_REQUEST, array( 'start_date' ) ) . '" method="GET">';

	DrawHeader( $date_select . ' ' . SubmitButton( _( 'Go' ) ) );

François Jacquet's avatar
François Jacquet committed
111
	echo '</form>';
François Jacquet's avatar
François Jacquet committed
112

113
	$RET = DBGet( "SELECT em.STUDENT_ID,em.ACTIVITY_ID,ea.TITLE,ea.START_DATE,ea.END_DATE
114
	FROM ELIGIBILITY_ACTIVITIES ea,STUDENT_ELIGIBILITY_ACTIVITIES em
François Jacquet's avatar
François Jacquet committed
115 116
	WHERE em.SYEAR='" . UserSyear() . "'
	AND em.STUDENT_ID='" . UserStudentID() . "'
117 118
	AND em.SYEAR=ea.SYEAR
	AND em.ACTIVITY_ID=ea.ID
François Jacquet's avatar
François Jacquet committed
119
	ORDER BY ea.START_DATE", array( 'START_DATE' => 'ProperDate', 'END_DATE' => 'ProperDate' ) );
François Jacquet's avatar
François Jacquet committed
120

François Jacquet's avatar
François Jacquet committed
121 122 123 124
	$activities_RET = DBGet( "SELECT ID,TITLE
		FROM ELIGIBILITY_ACTIVITIES
		WHERE SYEAR='" . UserSyear() . "'
		AND SCHOOL_ID='" . UserSchool() . "'" );
125

François Jacquet's avatar
François Jacquet committed
126
	foreach ( (array) $activities_RET as $value )
François Jacquet's avatar
François Jacquet committed
127
	{
128
		$activities[$value['ID']] = $value['TITLE'];
François Jacquet's avatar
François Jacquet committed
129 130
	}

François Jacquet's avatar
François Jacquet committed
131
	$link['remove']['link'] = 'Modules.php?modname=' . $_REQUEST['modname'] .
132
		'&modfunc=remove&start_date=' . issetVal( $_REQUEST['start_date'], '' );
François Jacquet's avatar
François Jacquet committed
133

François Jacquet's avatar
François Jacquet committed
134
	$link['remove']['variables'] = array( 'activity_id' => 'ACTIVITY_ID' );
François Jacquet's avatar
François Jacquet committed
135
//FJ css WPadmin
François Jacquet's avatar
François Jacquet committed
136 137
	//	$link['add']['html']['TITLE'] = '<table class="cellspacing-0"><tr><td>'.SelectInput('','new_activity','',$activities).'</td><td><input type=submit value="'._('Add').'"></td></tr></table>';
	//	$link['add']['html']['remove'] = button('add');
François Jacquet's avatar
François Jacquet committed
138 139 140 141 142 143 144
	$link['add']['html'] = array(
		'remove' => button( 'add' ),
		'TITLE' => SelectInput( '', 'new_activity', '', $activities ) . SubmitButton( _( 'Add' ) ),
		'START_DATE' => '&nbsp;',
		'END_DATE' => '&nbsp;',
	);

145
	echo '<form action="' . URLEscape( 'Modules.php?modname=' . $_REQUEST['modname'] .
146
		'&modfunc=add&start_date=' . issetVal( $_REQUEST['start_date'], '' ) .
147
		'' ) . '" method="POST">';
François Jacquet's avatar
François Jacquet committed
148 149 150 151 152 153

	$columns = array(
		'TITLE' => _( 'Activity' ),
		'START_DATE' => _( 'Starts' ),
		'END_DATE' => _( 'Ends' ),
	);
François Jacquet's avatar
François Jacquet committed
154

François Jacquet's avatar
François Jacquet committed
155
	ListOutput( $RET, $columns, 'Activity', 'Activities', $link );
François Jacquet's avatar
François Jacquet committed
156

François Jacquet's avatar
François Jacquet committed
157
	echo '</form>';
François Jacquet's avatar
François Jacquet committed
158

159
	$RET = DBGet( "SELECT e.ELIGIBILITY_CODE,c.TITLE as COURSE_TITLE
160
	FROM ELIGIBILITY e,COURSES c,COURSE_PERIODS cp
François Jacquet's avatar
François Jacquet committed
161 162
	WHERE e.STUDENT_ID='" . UserStudentID() . "'
	AND e.SYEAR='" . UserSyear() . "'
163 164
	AND e.COURSE_PERIOD_ID=cp.COURSE_PERIOD_ID
	AND cp.COURSE_ID=c.COURSE_ID
François Jacquet's avatar
François Jacquet committed
165 166 167 168
	AND e.SCHOOL_DATE BETWEEN '" . $start_date . "'
	AND '" . $end_date . "'", array( 'ELIGIBILITY_CODE' => '_makeLower' ) );
	$columns = array( 'COURSE_TITLE' => _( 'Course' ), 'ELIGIBILITY_CODE' => _( 'Grade' ) );
	ListOutput( $RET, $columns, 'Course', 'Courses' );
François Jacquet's avatar
François Jacquet committed
169 170
}

François Jacquet's avatar
François Jacquet committed
171 172 173 174
/**
 * @param $word
 */
function _makeLower( $word )
François Jacquet's avatar
François Jacquet committed
175
{
François Jacquet's avatar
François Jacquet committed
176
	return ucwords( mb_strtolower( $word ) );
François Jacquet's avatar
François Jacquet committed
177
}