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

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

5
if ( $_REQUEST['modfunc'] === 'save' )
François Jacquet's avatar
François Jacquet committed
6
{
7
	if ( ! empty( $_REQUEST['activity_id'] ) )
François Jacquet's avatar
François Jacquet committed
8
	{
9
		if ( ! empty( $_REQUEST['student'] ) )
François Jacquet's avatar
François Jacquet committed
10
		{
François Jacquet's avatar
François Jacquet committed
11
			// Fix bug add the same activity more than once.
12
			// $current_RET = DBGet( "SELECT STUDENT_ID FROM STUDENT_ELIGIBILITY_ACTIVITIES WHERE ACTIVITY_ID='".$_SESSION['activity_id']."' AND SYEAR='".UserSyear()."'",array(),array('STUDENT_ID'));
13 14 15 16
			$current_RET = DBGet( "SELECT STUDENT_ID
				FROM STUDENT_ELIGIBILITY_ACTIVITIES
				WHERE ACTIVITY_ID='" . $_REQUEST['activity_id'] . "'
				AND SYEAR='" . UserSyear() . "'", array(), array( 'STUDENT_ID' ) );
17 18 19 20 21

			// Group SQL inserts.
			$sql = '';

			foreach ( (array) $_REQUEST['student'] as $student_id )
François Jacquet's avatar
François Jacquet committed
22
			{
François Jacquet's avatar
François Jacquet committed
23
				if ( empty( $current_RET[$student_id] ) )
François Jacquet's avatar
François Jacquet committed
24
				{
25
					$sql .= "INSERT INTO STUDENT_ELIGIBILITY_ACTIVITIES (SYEAR,STUDENT_ID,ACTIVITY_ID)
François Jacquet's avatar
François Jacquet committed
26
						VALUES('" . UserSyear() . "','" . $student_id . "','" . $_REQUEST['activity_id'] . "');";
François Jacquet's avatar
François Jacquet committed
27 28
				}
			}
29 30 31 32 33 34 35

			if ( $sql )
			{
				DBQuery( $sql );

				$note[] = button( 'check' ) . '&nbsp;' . _( 'This activity has been added to the selected students.' );
			}
François Jacquet's avatar
François Jacquet committed
36 37
		}
		else
38 39 40
		{
			$error[] = _( 'You must choose at least one student.' );
		}
François Jacquet's avatar
François Jacquet committed
41 42
	}
	else
43 44 45
	{
		$error[] = _( 'You must choose an activity.' );
	}
François Jacquet's avatar
François Jacquet committed
46

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

51 52 53
echo ErrorMessage( $note, 'note' );

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

François Jacquet's avatar
François Jacquet committed
55
if ( $_REQUEST['search_modfunc'] === 'list' )
François Jacquet's avatar
François Jacquet committed
56
{
57
	echo '<form action="Modules.php?modname=' . $_REQUEST['modname'] . '&modfunc=save" method="POST">';
58
	DrawHeader( '', SubmitButton( _( 'Add Activity to Selected Students' ) ) );
François Jacquet's avatar
François Jacquet committed
59
	echo '<br />';
François Jacquet's avatar
François Jacquet committed
60

François Jacquet's avatar
François Jacquet committed
61
//FJ css WPadmin
62
	echo '<table class="postbox center col1-align-right"><tr><td>' . _( 'Activity' ) . '</td>';
François Jacquet's avatar
François Jacquet committed
63
	echo '<td>';
64 65 66 67
	$activities_RET = DBGet( "SELECT ID,TITLE
		FROM ELIGIBILITY_ACTIVITIES
		WHERE SYEAR='" . UserSyear() . "'
		AND SCHOOL_ID='" . UserSchool() . "'" );
68 69
	echo '<select name="activity_id"><option value="">' . _( 'N/A' ) . '</option>';

70
	foreach ( (array) $activities_RET as $activity )
François Jacquet's avatar
François Jacquet committed
71
	{
72
		echo '<option value="' . $activity['ID'] . '">' . $activity['TITLE'] . '</option>';
François Jacquet's avatar
François Jacquet committed
73
	}
74

François Jacquet's avatar
François Jacquet committed
75 76 77
	echo '</select>';
	echo '</td>';
	echo '</tr></table><br />';
François Jacquet's avatar
François Jacquet committed
78
}
79

François Jacquet's avatar
François Jacquet committed
80
//FJ fix bug no Search when student already selected
81 82 83 84 85 86 87 88 89
$extra['link'] = array( 'FULL_NAME' => false );
$extra['SELECT'] = ",CAST (NULL AS CHAR(1)) AS CHECKBOX";
$extra['functions'] = array( 'CHECKBOX' => 'MakeChooseCheckbox' );
$extra['columns_before'] = array( 'CHECKBOX' => MakeChooseCheckbox( '', 'STUDENT_ID', 'student' ) );
$extra['new'] = true;
Widgets( 'activity' );
Widgets( 'course' );

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

François Jacquet's avatar
François Jacquet committed
91
if ( $_REQUEST['search_modfunc'] === 'list' )
92 93 94
{
	echo '<br /><div class="center">' . SubmitButton( _( 'Add Activity to Selected Students' ) ) . '</div></form>';
}