AddActivity.php 2.89 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
if (isset($note))
34 35 36
	echo ErrorMessage($note, 'note');
if (isset($error))
	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 40 41 42 43
{
	echo '<FORM action="Modules.php?modname='.$_REQUEST['modname'].'&modfunc=save" method="POST">';
	DrawHeader('',SubmitButton(_('Add Activity to Selected Students')));
	echo '<BR />';

François Jacquet's avatar
François Jacquet committed
44
//FJ css WPadmin
45
	echo '<TABLE class="postbox center col1-align-right"><TR><TD>'._('Activity').'</TD>';
François Jacquet's avatar
François Jacquet committed
46 47 48
	echo '<TD>';
	$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>';
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 53 54 55 56 57 58
			echo '<OPTION value="'.$activity['ID'].'">'.$activity['TITLE'].'</OPTION>';
	}
	echo '</SELECT>';
	echo '</TD>';
	echo '</TR></TABLE><BR />';

}
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 63
	$extra['functions'] = array('CHECKBOX' => '_makeChooseCheckbox');
	$extra['columns_before'] = array('CHECKBOX' => '</A><INPUT type="checkbox" value="Y" name="controller" onclick="checkAll(this.form,this.form.controller.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')
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;

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