AddActivity.php 2.79 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 ( count( $_REQUEST['student'] ) )
François Jacquet's avatar
François Jacquet committed
10
		{
François Jacquet's avatar
François Jacquet committed
11 12
			// FJ fix bug add the same activity more than once
			// $current_RET = DBGet(DBQuery("SELECT STUDENT_ID FROM STUDENT_ELIGIBILITY_ACTIVITIES WHERE ACTIVITY_ID='".$_SESSION['activity_id']."' AND SYEAR='".UserSyear()."'"),array(),array('STUDENT_ID'));
13 14 15 16 17 18
			$current_RET = DBGet( DBQuery( "SELECT STUDENT_ID FROM STUDENT_ELIGIBILITY_ACTIVITIES WHERE ACTIVITY_ID='" . $_REQUEST['activity_id'] . "' AND SYEAR='" . UserSyear() . "'" ), array(), array( 'STUDENT_ID' ) );

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

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

			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
33 34
		}
		else
35 36 37
		{
			$error[] = _( 'You must choose at least one student.' );
		}
François Jacquet's avatar
François Jacquet committed
38 39
	}
	else
40 41 42
	{
		$error[] = _( 'You must choose an activity.' );
	}
François Jacquet's avatar
François Jacquet committed
43

François Jacquet's avatar
François Jacquet committed
44 45 46
	// Unset modfunc & redirect URL.
	RedirectURL( 'modfunc' );
}
François Jacquet's avatar
François Jacquet committed
47

48 49 50
echo ErrorMessage( $note, 'note' );

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

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

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

	if ( count( $activities_RET ) )
François Jacquet's avatar
François Jacquet committed
65
	{
66 67 68 69
		foreach ( (array) $activities_RET as $activity )
		{
			echo '<option value="' . $activity['ID'] . '">' . $activity['TITLE'] . '</option>';
		}
François Jacquet's avatar
François Jacquet committed
70
	}
71

François Jacquet's avatar
François Jacquet committed
72 73 74
	echo '</select>';
	echo '</td>';
	echo '</tr></table><br />';
François Jacquet's avatar
François Jacquet committed
75
}
76

François Jacquet's avatar
François Jacquet committed
77
//FJ fix bug no Search when student already selected
78 79 80 81 82 83 84 85 86
$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
87

88 89 90 91
if ( $_REQUEST['search_modfunc'] == 'list' )
{
	echo '<br /><div class="center">' . SubmitButton( _( 'Add Activity to Selected Students' ) ) . '</div></form>';
}