Commit 2fce5e19 authored by François Jacquet's avatar François Jacquet
Browse files

Group SQL inserts & deletes

Format code
parent 9af2087c
......@@ -24,6 +24,7 @@ Changes in 4.3
- CSS add .teacher-programs-wrapper class in TeacherPrograms.php, stylesheet.css, zresponsive.css & colors.css
- Fix GetMailingLabelsFormHTML AllowUse check in StudentLabels.fnc.php
- Add Help texts & translations for Create Parent Users program in Help_en.php & help.po
- Group SQL inserts & deletes in AddActivity.php, MassDrops.php, MassAssignFees.php & MassAssignPayments.php
Changes in 4.2
--------------
......
......@@ -4,29 +4,42 @@ DrawHeader( ProgramTitle() );
if ( $_REQUEST['modfunc'] === 'save' )
{
if ( !empty($_REQUEST['activity_id']))
if ( ! empty( $_REQUEST['activity_id'] ) )
{
if (count($_REQUEST['student']))
if ( count( $_REQUEST['student'] ) )
{
// 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'));
$current_RET = DBGet(DBQuery("SELECT STUDENT_ID FROM STUDENT_ELIGIBILITY_ACTIVITIES WHERE ACTIVITY_ID='".$_REQUEST['activity_id']."' AND SYEAR='".UserSyear()."'"),array(),array('STUDENT_ID'));
foreach ( (array) $_REQUEST['student'] as $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' ) );
// Group SQL inserts.
$sql = '';
foreach ( (array) $_REQUEST['student'] as $student_id )
{
if ( ! $current_RET[ $student_id ])
if ( ! $current_RET[$student_id] )
{
$sql = "INSERT INTO STUDENT_ELIGIBILITY_ACTIVITIES (SYEAR,STUDENT_ID,ACTIVITY_ID)
values('".UserSyear()."','".$student_id."','".$_REQUEST['activity_id']."')";
DBQuery($sql);
$sql .= "INSERT INTO STUDENT_ELIGIBILITY_ACTIVITIES (SYEAR,STUDENT_ID,ACTIVITY_ID)
values('" . UserSyear() . "','" . $student_id . "','" . $_REQUEST['activity_id'] . "');";
}
}
$note[] = button('check') .' '._('This activity has been added to the selected students.');
if ( $sql )
{
DBQuery( $sql );
$note[] = button( 'check' ) . ' ' . _( 'This activity has been added to the selected students.' );
}
}
else
$error[] = _('You must choose at least one student.');
{
$error[] = _( 'You must choose at least one student.' );
}
}
else
$error[] = _('You must choose an activity.');
{
$error[] = _( 'You must choose an activity.' );
}
// Unset modfunc & redirect URL.
RedirectURL( 'modfunc' );
......@@ -36,37 +49,43 @@ echo ErrorMessage( $note, 'note' );
echo ErrorMessage( $error );
if ( $_REQUEST['search_modfunc']=='list')
if ( $_REQUEST['search_modfunc'] == 'list' )
{
echo '<form action="Modules.php?modname='.$_REQUEST['modname'].'&modfunc=save" method="POST">';
echo '<form action="Modules.php?modname=' . $_REQUEST['modname'] . '&modfunc=save" method="POST">';
DrawHeader( '', SubmitButton( _( 'Add Activity to Selected Students' ) ) );
echo '<br />';
//FJ css WPadmin
echo '<table class="postbox center col1-align-right"><tr><td>'._('Activity').'</td>';
echo '<table class="postbox center col1-align-right"><tr><td>' . _( 'Activity' ) . '</td>';
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>';
if (count($activities_RET))
$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 ) )
{
foreach ( (array) $activities_RET as $activity)
echo '<option value="'.$activity['ID'].'">'.$activity['TITLE'].'</option>';
foreach ( (array) $activities_RET as $activity )
{
echo '<option value="' . $activity['ID'] . '">' . $activity['TITLE'] . '</option>';
}
}
echo '</select>';
echo '</td>';
echo '</tr></table><br />';
}
//FJ fix bug no Search when student already selected
$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);
if ( $_REQUEST['search_modfunc']=='list')
echo '<br /><div class="center">' . SubmitButton( _( 'Add Activity to Selected Students' ) ) . '</div></form>';
$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 );
if ( $_REQUEST['search_modfunc'] == 'list' )
{
echo '<br /><div class="center">' . SubmitButton( _( 'Add Activity to Selected Students' ) ) . '</div></form>';
}
......@@ -23,70 +23,121 @@ if ( $_REQUEST['modfunc'] === 'save' )
if ( $drop_date )
{
$course_mp = DBGet(DBQuery("SELECT MARKING_PERIOD_ID FROM COURSE_PERIODS WHERE COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."'"));
$course_mp = DBGet( DBQuery( "SELECT MARKING_PERIOD_ID
FROM COURSE_PERIODS
WHERE COURSE_PERIOD_ID='" . $_SESSION['MassDrops.php']['course_period_id'] . "'" ) );
$course_mp = $course_mp[1]['MARKING_PERIOD_ID'];
$course_mp_table = GetMP($course_mp,'MP');
$course_mp_table = GetMP( $course_mp, 'MP' );
if ( $course_mp_table=='FY' || $course_mp==$_REQUEST['marking_period_id'] || mb_strpos(GetChildrenMP($course_mp_table,$course_mp),"'".$_REQUEST['marking_period_id']."'")!==false)
if ( $course_mp_table == 'FY' || $course_mp == $_REQUEST['marking_period_id'] || mb_strpos( GetChildrenMP( $course_mp_table, $course_mp ), "'" . $_REQUEST['marking_period_id'] . "'" ) !== false )
{
$mp_table = GetMP($_REQUEST['marking_period_id'],'MP');
$mp_table = GetMP( $_REQUEST['marking_period_id'], 'MP' );
//$current_RET = DBGet(DBQuery("SELECT STUDENT_ID FROM SCHEDULE WHERE COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."' AND SYEAR='".UserSyear()."' AND (('".$start_date."' BETWEEN START_DATE AND END_DATE OR END_DATE IS NULL) AND '".$start_date."'>=START_DATE)"),array(),array('STUDENT_ID'));
$current_RET = DBGet(DBQuery("SELECT STUDENT_ID FROM SCHEDULE WHERE COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."' "));
$current_RET = DBGet( DBQuery( "SELECT STUDENT_ID
FROM SCHEDULE
WHERE COURSE_PERIOD_ID='" . $_SESSION['MassDrops.php']['course_period_id'] . "' " ) );
foreach ( (array) $_REQUEST['student'] as $student_id )
{
if ( $current_RET[ $student_id ]
&& empty( $schedule_deletion_pending ) )
if ( $current_RET[$student_id]
&& empty( $schedule_deletion_pending ) )
{
DBQuery("UPDATE SCHEDULE SET END_DATE='".$drop_date."' WHERE STUDENT_ID='".$student_id."' AND COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."'");
DBQuery( "UPDATE SCHEDULE
SET END_DATE='" . $drop_date . "'
WHERE STUDENT_ID='" . $student_id . "'
AND COURSE_PERIOD_ID='" . $_SESSION['MassDrops.php']['course_period_id'] . "'" );
//$start_end_RET = DBGet(DBQuery("SELECT START_DATE,END_DATE FROM SCHEDULE WHERE STUDENT_ID='".UserStudentID()."' AND COURSE_PERIOD_ID='".$course_period_id."' AND END_DATE<START_DATE"));
$start_end_RET = DBGet(DBQuery("SELECT START_DATE,END_DATE FROM SCHEDULE WHERE STUDENT_ID='".$student_id."' AND COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."' AND END_DATE<START_DATE"));
$start_end_RET = DBGet( DBQuery( "SELECT START_DATE,END_DATE
FROM SCHEDULE
WHERE STUDENT_ID='" . $student_id . "'
AND COURSE_PERIOD_ID='" . $_SESSION['MassDrops.php']['course_period_id'] . "'
AND END_DATE<START_DATE" ) );
//User is asked if he wants absences and grades to be deleted
if (count($start_end_RET))
if ( count( $start_end_RET ) )
{
//if user clicked Cancel or OK or Display Prompt
if ( isset( $_REQUEST['delete_ok'] )
|| DeletePrompt(_('Students\' Absences and Grades'), 'Delete', false))
|| DeletePrompt( _( 'Students\' Absences and Grades' ), 'Delete', false ) )
{
// Group SQL deletes.
$delete_sql = '';
//if user clicked OK
if ( ! isset( $_REQUEST['delete_cancel'] ) )
{
DBQuery("DELETE FROM GRADEBOOK_GRADES WHERE STUDENT_ID='".$student_id."' AND COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."'");
DBQuery("DELETE FROM STUDENT_REPORT_CARD_GRADES WHERE STUDENT_ID='".$student_id."' AND COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."'");
DBQuery("DELETE FROM STUDENT_REPORT_CARD_COMMENTS WHERE STUDENT_ID='".$student_id."' AND COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."'");
DBQuery("DELETE FROM ATTENDANCE_PERIOD WHERE STUDENT_ID='".$student_id."' AND COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."'");
$delete_sql .= "DELETE FROM GRADEBOOK_GRADES
WHERE STUDENT_ID='" . $student_id . "'
AND COURSE_PERIOD_ID='" . $_SESSION['MassDrops.php']['course_period_id'] . "';";
$delete_sql .= "DELETE FROM STUDENT_REPORT_CARD_GRADES
WHERE STUDENT_ID='" . $student_id . "'
AND COURSE_PERIOD_ID='" . $_SESSION['MassDrops.php']['course_period_id'] . "';";
$delete_sql .= "DELETE FROM STUDENT_REPORT_CARD_COMMENTS
WHERE STUDENT_ID='" . $student_id . "'
AND COURSE_PERIOD_ID='" . $_SESSION['MassDrops.php']['course_period_id'] . "';";
$delete_sql .= "DELETE FROM ATTENDANCE_PERIOD
WHERE STUDENT_ID='" . $student_id . "'
AND COURSE_PERIOD_ID='" . $_SESSION['MassDrops.php']['course_period_id'] . "';";
}
//else simply delete schedule entry
DBQuery("DELETE FROM SCHEDULE WHERE STUDENT_ID='".$student_id."' AND COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."'");
$delete_sql .= "DELETE FROM SCHEDULE
WHERE STUDENT_ID='" . $student_id . "'
AND COURSE_PERIOD_ID='" . $_SESSION['MassDrops.php']['course_period_id'] . "';";
DBQuery( $delete_sql );
//hook
do_action('Scheduling/MassDrops.php|drop_student');
do_action( 'Scheduling/MassDrops.php|drop_student' );
}
else
{
$schedule_deletion_pending = true;
}
}
else
DBQuery("DELETE FROM ATTENDANCE_PERIOD WHERE STUDENT_ID='".$student_id."' AND COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."' AND SCHOOL_DATE>'".$drop_date."'");
{
DBQuery( "DELETE FROM ATTENDANCE_PERIOD
WHERE STUDENT_ID='" . $student_id . "'
AND COURSE_PERIOD_ID='" . $_SESSION['MassDrops.php']['course_period_id'] . "'
AND SCHOOL_DATE>'" . $drop_date . "'" );
}
}
}
if (empty($schedule_deletion_pending))
$note[] = button('check') .'&nbsp;'._('This course has been dropped for the selected students\' schedules.');
if ( empty( $schedule_deletion_pending ) )
{
$note[] = button( 'check' ) . '&nbsp;' . _( 'This course has been dropped for the selected students\' schedules.' );
}
}
else
$error[] = _('You cannot schedule a student into that course during this marking period.').' '.sprintf(_('This course meets on %s.'),GetMP($course_mp));
{
$error[] = _( 'You cannot schedule a student into that course during this marking period.' ) . ' ' . sprintf( _( 'This course meets on %s.' ), GetMP( $course_mp ) );
}
}
else
$error[] = _('The date you entered is not valid');
{
$error[] = _( 'The date you entered is not valid' );
}
}
else
$error[] = _('You must choose at least one student.');
{
$error[] = _( 'You must choose at least one student.' );
}
}
else
$error[] = _('You must choose a course.');
{
$error[] = _( 'You must choose a course.' );
}
if ( empty( $schedule_deletion_pending ) )
{
......@@ -97,32 +148,38 @@ if ( $_REQUEST['modfunc'] === 'save' )
}
}
echo ErrorMessage( $error );
echo ErrorMessage( $note, 'note' );
if ( $_REQUEST['modfunc']!='choose_course')
if ( $_REQUEST['modfunc'] != 'choose_course' )
{
if ( $_REQUEST['search_modfunc']=='list')
if ( $_REQUEST['search_modfunc'] == 'list' )
{
echo '<form action="Modules.php?modname='.$_REQUEST['modname'].'&modfunc=save" method="POST">';
echo '<form action="Modules.php?modname=' . $_REQUEST['modname'] . '&modfunc=save" method="POST">';
DrawHeader( '', SubmitButton( _( 'Drop Course for Selected Students' ) ) );
echo '<br />';
PopTable('header', _('Course to Drop'));
PopTable( 'header', _( 'Course to Drop' ) );
echo '<table><tr><td colspan="2"><div id=course_div>';
if ( $_SESSION['MassDrops.php'])
if ( $_SESSION['MassDrops.php'] )
{
$course_title = DBGet(DBQuery("SELECT TITLE FROM COURSES WHERE COURSE_ID='".$_SESSION['MassDrops.php']['course_id']."'"));
$course_title = DBGet( DBQuery( "SELECT TITLE
FROM COURSES
WHERE COURSE_ID='" . $_SESSION['MassDrops.php']['course_id'] . "'" ) );
$course_title = $course_title[1]['TITLE'];
$period_title = DBGet(DBQuery("SELECT TITLE FROM COURSE_PERIODS WHERE COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."'"));
$period_title = DBGet( DBQuery( "SELECT TITLE
FROM COURSE_PERIODS
WHERE COURSE_PERIOD_ID='" . $_SESSION['MassDrops.php']['course_period_id'] . "'" ) );
$period_title = $period_title[1]['TITLE'];
echo $course_title.'<br />'.$period_title;
echo $course_title . '<br />' . $period_title;
}
echo '</div>' . '<a href="#" onclick=\'popups.open(
......@@ -132,59 +189,81 @@ if ( $_REQUEST['modfunc']!='choose_course')
echo '<tr class="st"><td>' . _( 'Drop Date' ) . '</td>
<td>' . DateInput( DBDate(), 'drop', '', false, false ) . '</td></tr>';
echo '<tr class="st"><td>'._('Marking Period').'</td><td>';
echo '<tr class="st"><td>' . _( 'Marking Period' ) . '</td><td>';
echo '<select name=marking_period_id>';
$mp_RET = DBGet(DBQuery("SELECT MARKING_PERIOD_ID,TITLE,".db_case(array('MP',"'FY'","'0'","'SEM'","'1'","'QTR'","'2'"))." AS TBL FROM SCHOOL_MARKING_PERIODS WHERE (MP='FY' OR MP='SEM' OR MP='QTR') AND SCHOOL_ID='".UserSchool()."' AND SYEAR='".UserSyear()."' ORDER BY TBL,SORT_ORDER"));
foreach ( (array) $mp_RET as $mp)
echo '<option value="'.$mp['MARKING_PERIOD_ID'].'">'.$mp['TITLE'].'</option>';
$mp_RET = DBGet( DBQuery( "SELECT MARKING_PERIOD_ID,TITLE," .
db_case( array( 'MP', "'FY'", "'0'", "'SEM'", "'1'", "'QTR'", "'2'" ) ) . " AS TBL
FROM SCHOOL_MARKING_PERIODS
WHERE (MP='FY' OR MP='SEM' OR MP='QTR')
AND SCHOOL_ID='" . UserSchool() . "'
AND SYEAR='" . UserSyear() . "'
ORDER BY TBL,SORT_ORDER" ) );
foreach ( (array) $mp_RET as $mp )
{
echo '<option value="' . $mp['MARKING_PERIOD_ID'] . '">' . $mp['TITLE'] . '</option>';
}
echo '</select>';
echo '</td></tr></table>';
PopTable('footer');
PopTable( 'footer' );
echo '<br />';
}
}
if ( ! $_REQUEST['modfunc'] )
{
if ( $_REQUEST['search_modfunc']!='list')
unset($_SESSION['MassDrops.php']);
$extra['link'] = array('FULL_NAME'=>false);
if ( $_REQUEST['search_modfunc'] !== 'list' )
{
unset( $_SESSION['MassDrops.php'] );
}
$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['functions'] = array( 'CHECKBOX' => 'MakeChooseCheckbox' );
$extra['columns_before'] = array( 'CHECKBOX' => MakeChooseCheckbox( '', 'STUDENT_ID', 'student' ) );
$extra['new'] = true;
Widgets('course');
Widgets('request');
Widgets('activity');
Widgets( 'course' );
Widgets( 'request' );
Widgets( 'activity' );
Search( 'student_id', $extra );
Search('student_id',$extra);
if ( $_REQUEST['search_modfunc']=='list')
if ( $_REQUEST['search_modfunc'] == 'list' )
{
echo '<br /><div class="center">' . SubmitButton( _( 'Drop Course for Selected Students' ) ) . '</div>';
echo '</form>';
}
}
if ( $_REQUEST['modfunc']=='choose_course')
if ( $_REQUEST['modfunc'] === 'choose_course' )
{
if ( empty( $_REQUEST['course_period_id'] ) )
{
include 'modules/Scheduling/Courses.php';
}
else
{
$_SESSION['MassDrops.php']['subject_id'] = isset( $_REQUEST['subject_id'] ) ? $_REQUEST['subject_id'] : null;
$_SESSION['MassDrops.php']['course_id'] = isset( $_REQUEST['course_id'] ) ? $_REQUEST['course_id'] : null;
$_SESSION['MassDrops.php']['course_period_id'] = isset( $_REQUEST['course_period_id'] ) ? $_REQUEST['course_period_id'] : null;
$course_title = DBGet(DBQuery("SELECT TITLE FROM COURSES WHERE COURSE_ID='".$_SESSION['MassDrops.php']['course_id']."'"));
$course_title = DBGet( DBQuery( "SELECT TITLE
FROM COURSES
WHERE COURSE_ID='" . $_SESSION['MassDrops.php']['course_id'] . "'" ) );
$course_title = $course_title[1]['TITLE'];
$period_title = DBGet(DBQuery("SELECT TITLE FROM COURSE_PERIODS WHERE COURSE_PERIOD_ID='".$_SESSION['MassDrops.php']['course_period_id']."'"));
$period_title = DBGet( DBQuery( "SELECT TITLE
FROM COURSE_PERIODS
WHERE COURSE_PERIOD_ID='" . $_SESSION['MassDrops.php']['course_period_id'] . "'" ) );
$period_title = $period_title[1]['TITLE'];
echo '<script>opener.document.getElementById("course_div").innerHTML = '.json_encode($course_title.'<br />'.$period_title).'; window.close();</script>';
echo '<script>opener.document.getElementById("course_div").innerHTML = ' . json_encode( $course_title . '<br />' . $period_title ) . '; window.close();</script>';
}
}
......@@ -6,7 +6,8 @@ if ( $_REQUEST['modfunc'] === 'save' )
&& AllowEdit() )
{
//FJ fix SQL bug invalid amount
if (is_numeric($_REQUEST['amount']))
if ( is_numeric( $_REQUEST['amount'] ) )
{
$due_date = RequestedDate(
$_REQUEST['year_due'],
......@@ -16,30 +17,45 @@ if ( $_REQUEST['modfunc'] === 'save' )
if ( $due_date )
{
// Group SQL inserts.
$sql = '';
foreach ( (array) $_REQUEST['student'] as $student_id )
{
$sql = "INSERT INTO BILLING_FEES (STUDENT_ID,ID,TITLE,AMOUNT,SYEAR,SCHOOL_ID,ASSIGNED_DATE,DUE_DATE,COMMENTS)
values('".$student_id."',".db_seq_nextval('BILLING_FEES_SEQ').",'".$_REQUEST['title']."','".preg_replace('/[^0-9.-]/','',$_REQUEST['amount'])."','".UserSyear()."','".UserSchool()."','".DBDate()."','".$due_date."','".$_REQUEST['comments']."')";
DBQuery($sql);
$sql .= "INSERT INTO BILLING_FEES (STUDENT_ID,ID,TITLE,AMOUNT,SYEAR,SCHOOL_ID,ASSIGNED_DATE,DUE_DATE,COMMENTS)
VALUES('" . $student_id . "'," . db_seq_nextval( 'BILLING_FEES_SEQ' ) . ",
'" . $_REQUEST['title'] . "','" . preg_replace( '/[^0-9.-]/', '', $_REQUEST['amount'] ) . "',
'" . UserSyear() . "','" . UserSchool() . "','" . DBDate() . "','" . $due_date . "',
'" . $_REQUEST['comments'] . "');";
}
if ( $sql )
{
DBQuery( $sql );
$note[] = button( 'check' ) . '&nbsp;' . _( 'That fee has been added to the selected students.' );
}
$note[] = button('check') .'&nbsp;'._('That fee has been added to the selected students.');
}
else
$error[] = _('The date you entered is not valid');
{
$error[] = _( 'The date you entered is not valid' );
}
}
else
$error[] = _('Please enter a valid Amount.');
{
$error[] = _( 'Please enter a valid Amount.' );
}
}
else
$error[] = _('You must choose at least one student.');
{
$error[] = _( 'You must choose at least one student.' );
}
// Unset modfunc & redirect URL.
RedirectURL( 'modfunc' );
}
if ( ! $_REQUEST['modfunc'] )
{
DrawHeader( ProgramTitle() );
......@@ -47,29 +63,29 @@ if ( ! $_REQUEST['modfunc'] )
echo ErrorMessage( $note, 'note' );
if ( $_REQUEST['search_modfunc']=='list')
if ( $_REQUEST['search_modfunc'] == 'list' )
{
echo '<form action="Modules.php?modname='.$_REQUEST['modname'].'&modfunc=save" method="POST">';
echo '<form action="Modules.php?modname=' . $_REQUEST['modname'] . '&modfunc=save" method="POST">';
DrawHeader( '', SubmitButton( _( 'Add Fee to Selected Students' ) ) );
echo '<br />';
PopTable('header', _('Fee'));
PopTable( 'header', _( 'Fee' ) );
echo '<table class="col1-align-right">';
echo '<tr><td>'._('Title').'</td><td><input type="text" name="title" required /></td></tr>';
echo '<tr><td>' . _( 'Title' ) . '</td><td><input type="text" name="title" required /></td></tr>';
echo '<tr><td>'._('Amount').'</td><td><input type="text" name="amount" size="5" maxlength="10" required /></td></tr>';
echo '<tr><td>' . _( 'Amount' ) . '</td><td><input type="text" name="amount" size="5" maxlength="10" required /></td></tr>';
echo '<tr><td>' . _( 'Due Date' ) . '</td>
<td>' . DateInput( DBDate(), 'due', '', false, false ) . '</td></tr>';
echo '<tr><td>'._('Comment').'</td><td><input type="text" name="comments" /></td></tr>';
echo '<tr><td>' . _( 'Comment' ) . '</td><td><input type="text" name="comments" /></td></tr>';
echo '</table>';
PopTable('footer');
PopTable( 'footer' );
echo '<br />';
}
......@@ -80,10 +96,9 @@ if ( ! $_REQUEST['modfunc'] )
$extra['link'] = array( 'FULL_NAME' => false );
$extra['SELECT'] = ",NULL AS CHECKBOX";
$extra['functions'] = array( 'CHECKBOX' => 'MakeChooseCheckbox' );
$extra['columns_before'] = array( 'CHECKBOX' => MakeChooseCheckbox( '', 'STUDENT_ID', 'student' ) );
$extra['columns_before'] = array( 'CHECKBOX' => MakeChooseCheckbox( '', 'STUDENT_ID', 'student' ) );
$extra['new'] = true;
Search( 'student_id', $extra );
if ( $_REQUEST['search_modfunc'] === 'list' )
......
......@@ -2,7 +2,7 @@
if ( $_REQUEST['modfunc'] === 'save' )
{
if (count($_REQUEST['student']) && AllowEdit())
if ( count( $_REQUEST['student'] ) && AllowEdit() )
{
$date = RequestedDate(
$_REQUEST['year_date'],
......@@ -11,34 +11,50 @@ if ( $_REQUEST['modfunc'] === 'save' )
);
// FJ fix SQL bug invalid amount.
if ( is_numeric( $_REQUEST['amount'] ) )
{
if ( $date )
{
// Group SQL inserts.
$sql = '';
foreach ( (array) $_REQUEST['student'] as $student_id )
{
$sql = "INSERT INTO BILLING_PAYMENTS (ID,SYEAR,SCHOOL_ID,STUDENT_ID,PAYMENT_DATE,AMOUNT,COMMENTS)
values(" . db_seq_nextval( 'BILLING_PAYMENTS_SEQ' ) . ",'" . UserSyear() . "','" . UserSchool() . "','" . $student_id . "','" . $date . "','" . preg_replace( '/[^0-9.-]/', '', $_REQUEST['amount'] ) . "','" . $_REQUEST['comments'] . "')";
DBQuery($sql);
$sql .= "INSERT INTO BILLING_PAYMENTS (ID,SYEAR,SCHOOL_ID,STUDENT_ID,PAYMENT_DATE,AMOUNT,COMMENTS)
VALUES(" . db_seq_nextval( 'BILLING_PAYMENTS_SEQ' ) . ",'" . UserSyear() . "',
'" . UserSchool() . "','" . $student_id . "','" . $date . "',
'" . preg_replace( '/[^0-9.-]/', '', $_REQUEST['amount'] ) . "',
'" . $_REQUEST['comments'] . "');";
}
$note[] = button('check') .'&nbsp;'._('That payment has been added to the selected students.');
if ( $sql )
{
DBQuery( $sql );
$note[] = button( 'check' ) . '&nbsp;' . _( 'That payment has been added to the selected students.' );
}
}
else
{
$error[] = _( 'The date you entered is not valid' );
}
}
else
{