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

DrawHeader(ProgramTitle());

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

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

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

François Jacquet's avatar
François Jacquet committed
43
//FJ css WPadmin
François Jacquet's avatar
François Jacquet committed
44 45
	echo '<table class="postbox center col1-align-right"><tr><td>'._('Activity').'</td>';
	echo '<td>';
François Jacquet's avatar
François Jacquet committed
46
	$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
47
	echo '<select name="activity_id"><option value="">'._('N/A').'</option>';
48
	if (count($activities_RET))
François Jacquet's avatar
François Jacquet committed
49
	{
50
		foreach ( (array) $activities_RET as $activity)
François Jacquet's avatar
François Jacquet committed
51
			echo '<option value="'.$activity['ID'].'">'.$activity['TITLE'].'</option>';
François Jacquet's avatar
François Jacquet committed
52
	}
François Jacquet's avatar
François Jacquet committed
53 54 55
	echo '</select>';
	echo '</td>';
	echo '</tr></table><br />';
François Jacquet's avatar
François Jacquet committed
56 57

}
François Jacquet's avatar
François Jacquet committed
58
//FJ fix bug no Search when student already selected
François Jacquet's avatar
François Jacquet committed
59 60
	$extra['link'] = array('FULL_NAME'=>false);
	$extra['SELECT'] = ",CAST (NULL AS CHAR(1)) AS CHECKBOX";
61
	$extra['functions'] = array('CHECKBOX' => '_makeChooseCheckbox');
62
	$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
63 64 65 66 67
	$extra['new'] = true;
	Widgets('activity');
	Widgets('course');

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

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

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