AddActivity.php 2.82 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['activity_id']))
François Jacquet's avatar
François Jacquet committed
6 7 8
	{
		if (count($_REQUEST['student']))
		{
François Jacquet's avatar
François Jacquet committed
9
	//FJ fix bug add the same activity more than once
François Jacquet's avatar
François Jacquet committed
10 11
	//		$current_RET = DBGet(DBQuery("SELECT STUDENT_ID FROM STUDENT_ELIGIBILITY_ACTIVITIES WHERE ACTIVITY_ID='".$_SESSION['activity_id']."' AND SYEAR='".UserSyear()."'"),array(),array('STUDENT_ID'));
			$current_RET = DBGet(DBQuery("SELECT STUDENT_ID FROM STUDENT_ELIGIBILITY_ACTIVITIES WHERE ACTIVITY_ID='".$_REQUEST['activity_id']."' AND SYEAR='".UserSyear()."'"),array(),array('STUDENT_ID'));
12
			foreach ( (array) $_REQUEST['student'] as $student_id => $yes)
François Jacquet's avatar
François Jacquet committed
13
			{
14
				if ( ! $current_RET[ $student_id ])
François Jacquet's avatar
François Jacquet committed
15 16 17 18 19 20
				{
					$sql = "INSERT INTO STUDENT_ELIGIBILITY_ACTIVITIES (SYEAR,STUDENT_ID,ACTIVITY_ID)
								values('".UserSyear()."','".$student_id."','".$_REQUEST['activity_id']."')";
					DBQuery($sql);
				}
			}
21
			$note[] = button('check') .'&nbsp;'._('This activity has been added to the selected students.');
François Jacquet's avatar
François Jacquet committed
22 23
		}
		else
24
			$error[] = _('You must choose at least one student.');
François Jacquet's avatar
François Jacquet committed
25 26
	}
	else
27
		$error[] = _('You must choose an activity.');
28 29
	$_SESSION['_REQUEST_vars']['modfunc'] = false;
	$_REQUEST['modfunc'] = false;
François Jacquet's avatar
François Jacquet committed
30 31 32 33
}

DrawHeader(ProgramTitle());

34 35 36
echo ErrorMessage( $note, 'note' );

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

38
if ( $_REQUEST['search_modfunc']=='list')
François Jacquet's avatar
François Jacquet committed
39
{
François Jacquet's avatar
François Jacquet committed
40
	echo '<form action="Modules.php?modname='.$_REQUEST['modname'].'&modfunc=save" method="POST">';
François Jacquet's avatar
François Jacquet committed
41
	DrawHeader('',SubmitButton(_('Add Activity to Selected Students')));
François Jacquet's avatar
François Jacquet committed
42
	echo '<br />';
François Jacquet's avatar
François Jacquet committed
43

François Jacquet's avatar
François Jacquet committed
44
//FJ css WPadmin
François Jacquet's avatar
François Jacquet committed
45 46
	echo '<table class="postbox center col1-align-right"><tr><td>'._('Activity').'</td>';
	echo '<td>';
François Jacquet's avatar
François Jacquet committed
47
	$activities_RET = DBGet(DBQuery("SELECT ID,TITLE FROM ELIGIBILITY_ACTIVITIES WHERE SYEAR='".UserSyear()."' AND SCHOOL_ID='".UserSchool()."'"));
François Jacquet's avatar
François Jacquet committed
48
	echo '<select name="activity_id"><option value="">'._('N/A').'</option>';
49
	if (count($activities_RET))
François Jacquet's avatar
François Jacquet committed
50
	{
51
		foreach ( (array) $activities_RET as $activity)
François Jacquet's avatar
François Jacquet committed
52
			echo '<option value="'.$activity['ID'].'">'.$activity['TITLE'].'</option>';
François Jacquet's avatar
François Jacquet committed
53
	}
François Jacquet's avatar
François Jacquet committed
54 55 56
	echo '</select>';
	echo '</td>';
	echo '</tr></table><br />';
François Jacquet's avatar
François Jacquet committed
57 58

}
François Jacquet's avatar
François Jacquet committed
59
//FJ fix bug no Search when student already selected
François Jacquet's avatar
François Jacquet committed
60 61
	$extra['link'] = array('FULL_NAME'=>false);
	$extra['SELECT'] = ",CAST (NULL AS CHAR(1)) AS CHECKBOX";
62
	$extra['functions'] = array('CHECKBOX' => '_makeChooseCheckbox');
63
	$extra['columns_before'] = array('CHECKBOX' => '</a><input type="checkbox" value="Y" name="controller" onclick="checkAll(this.form,this.checked,\'student\');"><A>');
François Jacquet's avatar
François Jacquet committed
64 65 66 67 68
	$extra['new'] = true;
	Widgets('activity');
	Widgets('course');

Search('student_id',$extra);
69
if ( $_REQUEST['search_modfunc']=='list')
François Jacquet's avatar
François Jacquet committed
70
	echo '<br /><div class="center">' . SubmitButton(_('Add Activity to Selected Students')) . '</div></form>';
François Jacquet's avatar
François Jacquet committed
71 72 73 74

function _makeChooseCheckbox($value,$title)
{	global $THIS_RET;

François Jacquet's avatar
François Jacquet committed
75
	return '<input type="checkbox" name="student['.$THIS_RET['STUDENT_ID'].']" value="Y">';
François Jacquet's avatar
François Jacquet committed
76
}