Commit 7b947e4e authored by François Jacquet's avatar François Jacquet
Browse files

Omit DBQuery call for DBGet SELECT, bis

parent f31a7916
......@@ -48,7 +48,7 @@ echo '<form action="Modules.php?modname=' . $_REQUEST['modname'] . '&accounting=
$header_checkboxes = '<label><input type="checkbox" value="true" name="accounting" id="accounting" ' .
( ! isset( $_REQUEST['accounting'] )
|| $_REQUEST['accounting'] == 'true' ? 'checked ' : '' ) . '/> ' .
_( 'Expense' ) . ' & ' . _( 'Income' ) . '</label>&nbsp; ';
_( 'Expense' ) . ' & ' . _( 'Income' ) . '</label>&nbsp; ';
$header_checkboxes .= '<label><input type="checkbox" value="true" name="staff_payroll" id="staff_payroll" ' .
( ! empty( $_REQUEST['staff_payroll'] ) ? 'checked ' : '' ) . '/> ' .
......@@ -73,26 +73,26 @@ echo '</form>';
if ( ! isset( $_REQUEST['accounting'] )
|| $_REQUEST['accounting'] == 'true' )
{
$accounting_payments = DBGet( DBQuery( "SELECT sum(AMOUNT) AS AMOUNT
$accounting_payments = DBGet( "SELECT sum(AMOUNT) AS AMOUNT
FROM ACCOUNTING_PAYMENTS
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
AND PAYMENT_DATE BETWEEN '" . $start_date . "'
AND '" . $end_date . "'
AND STAFF_ID IS NULL" ) );
AND STAFF_ID IS NULL" );
$accounting_incomes = DBGet( DBQuery( "SELECT sum(f.AMOUNT) AS AMOUNT
$accounting_incomes = DBGet( "SELECT sum(f.AMOUNT) AS AMOUNT
FROM ACCOUNTING_INCOMES f
WHERE f.SYEAR='" . UserSyear() . "'
AND f.SCHOOL_ID='" . UserSchool() . "'
WHERE f.SYEAR='" . UserSyear() . "'
AND f.SCHOOL_ID='" . UserSchool() . "'
AND f.ASSIGNED_DATE BETWEEN '" . $start_date . "'
AND '" . $end_date . "'" ) );
AND '" . $end_date . "'" );
}
// Staff salaries.
if ( ! empty( $_REQUEST['staff_payroll'] ) )
{
$staffpayroll_payments = DBGet( DBQuery( "SELECT sum(p.AMOUNT) AS AMOUNT
$staffpayroll_payments = DBGet( "SELECT sum(p.AMOUNT) AS AMOUNT
FROM ACCOUNTING_PAYMENTS p, STAFF s
WHERE p.SYEAR='" . UserSyear() . "'
AND s.SYEAR=p.SYEAR
......@@ -100,35 +100,35 @@ if ( ! empty( $_REQUEST['staff_payroll'] ) )
AND p.PAYMENT_DATE BETWEEN '" . $start_date . "'
AND '" . $end_date . "'
AND p.STAFF_ID=s.STAFF_ID
AND p.SYEAR=s.SYEAR" ) );
AND p.SYEAR=s.SYEAR" );
$staffpayroll_incomes = DBGet( DBQuery( "SELECT sum(f.AMOUNT) AS AMOUNT
$staffpayroll_incomes = DBGet( "SELECT sum(f.AMOUNT) AS AMOUNT
FROM ACCOUNTING_SALARIES f, STAFF s
WHERE f.SYEAR='" . UserSyear() . "'
WHERE f.SYEAR='" . UserSyear() . "'
AND s.SYEAR=f.SYEAR
AND f.SCHOOL_ID='" . UserSchool() . "'
AND f.ASSIGNED_DATE BETWEEN '" . $start_date . "'
AND '" . $end_date . "'
AND f.STAFF_ID=s.STAFF_ID
AND f.SYEAR=s.SYEAR" ) );
AND f.SYEAR=s.SYEAR" );
}
// Student Billing.
if ( ! empty( $_REQUEST['student_billing'] )
&& $RosarioModules['Student_Billing'] )
{
$billing_payments = DBGet( DBQuery( "SELECT sum(AMOUNT) AS AMOUNT
$billing_payments = DBGet( "SELECT sum(AMOUNT) AS AMOUNT
FROM BILLING_PAYMENTS
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
AND PAYMENT_DATE BETWEEN '" . $start_date . "'
AND '" . $end_date . "'" ) );
AND '" . $end_date . "'" );
$billing_fees = DBGet( DBQuery( "SELECT sum(f.AMOUNT) AS AMOUNT
$billing_fees = DBGet( "SELECT sum(f.AMOUNT) AS AMOUNT
FROM BILLING_FEES f
WHERE f.SCHOOL_ID='" . UserSchool() . "'
AND f.ASSIGNED_DATE BETWEEN '" . $start_date . "'
AND '" . $end_date . "'" ) );
AND '" . $end_date . "'" );
}
echo '<br />';
......
......@@ -37,7 +37,7 @@ if ( $_REQUEST['values']
elseif ( $columns['AMOUNT'] != ''
&& $columns['PAYMENT_DATE'] )
{
$id = DBGet( DBQuery( "SELECT " . db_seq_nextval( 'ACCOUNTING_PAYMENTS_SEQ' ) . ' AS ID' ) );
$id = DBGet( "SELECT " . db_seq_nextval( 'ACCOUNTING_PAYMENTS_SEQ' ) . ' AS ID' );
$id = $id[1]['ID'];
$sql = "INSERT INTO ACCOUNTING_PAYMENTS ";
......
......@@ -44,41 +44,41 @@ if ( ! function_exists( 'DashboardAccountingAdmin' ) )
{
$general_balance = 0;
$incomes_RET = DBGet( DBQuery( "SELECT TO_CHAR(ASSIGNED_DATE,'YYYY-MM') AS YEAR_MONTH,
$incomes_RET = DBGet( "SELECT TO_CHAR(ASSIGNED_DATE,'YYYY-MM') AS YEAR_MONTH,
SUM(AMOUNT) AS TOTAL_INCOMES
FROM ACCOUNTING_INCOMES
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
GROUP BY YEAR_MONTH
ORDER BY YEAR_MONTH DESC
LIMIT 3" ), array(), array( 'YEAR_MONTH' ) );
LIMIT 3", array(), array( 'YEAR_MONTH' ) );
$expenses_RET = DBGet( DBQuery( "SELECT TO_CHAR(PAYMENT_DATE,'YYYY-MM') AS YEAR_MONTH,
$expenses_RET = DBGet( "SELECT TO_CHAR(PAYMENT_DATE,'YYYY-MM') AS YEAR_MONTH,
SUM(CASE WHEN STAFF_ID IS NULL THEN AMOUNT END) AS TOTAL_EXPENSES
FROM ACCOUNTING_PAYMENTS
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
GROUP BY YEAR_MONTH
ORDER BY YEAR_MONTH DESC
LIMIT 3" ), array(), array( 'YEAR_MONTH' ) );
LIMIT 3", array(), array( 'YEAR_MONTH' ) );
$staff_payments_RET = DBGet( DBQuery( "SELECT TO_CHAR(PAYMENT_DATE,'YYYY-MM') AS YEAR_MONTH,
$staff_payments_RET = DBGet( "SELECT TO_CHAR(PAYMENT_DATE,'YYYY-MM') AS YEAR_MONTH,
SUM(CASE WHEN STAFF_ID IS NOT NULL THEN AMOUNT END) AS TOTAL_STAFF
FROM ACCOUNTING_PAYMENTS
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
GROUP BY YEAR_MONTH
ORDER BY YEAR_MONTH DESC
LIMIT 3" ), array(), array( 'YEAR_MONTH' ) );
LIMIT 3", array(), array( 'YEAR_MONTH' ) );
$student_payments_RET = DBGet( DBQuery( "SELECT TO_CHAR(PAYMENT_DATE,'YYYY-MM') AS YEAR_MONTH,
$student_payments_RET = DBGet( "SELECT TO_CHAR(PAYMENT_DATE,'YYYY-MM') AS YEAR_MONTH,
SUM(AMOUNT) AS TOTAL_STUDENT_PAYMENTS
FROM BILLING_PAYMENTS
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
GROUP BY YEAR_MONTH
ORDER BY YEAR_MONTH DESC
LIMIT 3" ), array(), array( 'YEAR_MONTH' ) );
LIMIT 3", array(), array( 'YEAR_MONTH' ) );
$accounting_RET = array_replace_recursive( $incomes_RET, $expenses_RET, $staff_payments_RET, $student_payments_RET );
......
......@@ -28,16 +28,16 @@ if ( $_REQUEST['modfunc'] === 'save' )
$students_list = "'" . implode( "','", $_REQUEST['student'] ) . "'";
$current_RET = DBGet( DBQuery( "SELECT STUDENT_ID,PERIOD_ID,SCHOOL_DATE
$current_RET = DBGet( "SELECT STUDENT_ID,PERIOD_ID,SCHOOL_DATE
FROM ATTENDANCE_PERIOD
WHERE EXTRACT(MONTH FROM SCHOOL_DATE)='" . ( $_REQUEST['month'] * 1 ) . "'
AND EXTRACT(YEAR FROM SCHOOL_DATE)='" . $_REQUEST['year'] . "'
AND PERIOD_ID IN (" . $periods_list . ")
AND STUDENT_ID IN (" . $students_list . ")" ), array(), array( 'STUDENT_ID', 'SCHOOL_DATE', 'PERIOD_ID' ) );
AND STUDENT_ID IN (" . $students_list . ")", array(), array( 'STUDENT_ID', 'SCHOOL_DATE', 'PERIOD_ID' ) );
$state_code = DBGet( DBQuery( "SELECT STATE_CODE
$state_code = DBGet( "SELECT STATE_CODE
FROM ATTENDANCE_CODES
WHERE ID='" . $_REQUEST['absence_code'] . "'" ) );
WHERE ID='" . $_REQUEST['absence_code'] . "'" );
$state_code = $state_code[1]['STATE_CODE'];
......@@ -52,7 +52,7 @@ if ( $_REQUEST['modfunc'] === 'save' )
if ( SchoolInfo( 'NUMBER_DAYS_ROTATION' ) !== null )
{
$course_periods_RET = DBGet( DBQuery( "SELECT s.COURSE_PERIOD_ID,cpsp.PERIOD_ID,cp.HALF_DAY
$course_periods_RET = DBGet( "SELECT s.COURSE_PERIOD_ID,cpsp.PERIOD_ID,cp.HALF_DAY
FROM SCHEDULE s,COURSE_PERIODS cp,ATTENDANCE_CALENDAR ac,SCHOOL_PERIODS sp,COURSE_PERIOD_SCHOOL_PERIODS cpsp
WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID
AND sp.PERIOD_ID=cpsp.PERIOD_ID
......@@ -72,11 +72,11 @@ if ( $_REQUEST['modfunc'] === 'save' )
AND SCHOOL_ID=ac.SCHOOL_ID)
AS INT) FOR 1) IN cpsp.DAYS)>0
AND s.MARKING_PERIOD_ID IN (" . $all_mp . ")
AND ac.SCHOOL_ID=s.SCHOOL_ID" ), array(), array( 'PERIOD_ID' ) );
AND ac.SCHOOL_ID=s.SCHOOL_ID", array(), array( 'PERIOD_ID' ) );
}
else
{
$course_periods_RET = DBGet( DBQuery( "SELECT s.COURSE_PERIOD_ID,cpsp.PERIOD_ID,cp.HALF_DAY
$course_periods_RET = DBGet( "SELECT s.COURSE_PERIOD_ID,cpsp.PERIOD_ID,cp.HALF_DAY
FROM SCHEDULE s,COURSE_PERIODS cp,ATTENDANCE_CALENDAR ac,SCHOOL_PERIODS sp,COURSE_PERIOD_SCHOOL_PERIODS cpsp
WHERE sp.PERIOD_ID=cpsp.PERIOD_ID
AND ac.SCHOOL_DATE='" . $date . "'
......@@ -87,7 +87,7 @@ if ( $_REQUEST['modfunc'] === 'save' )
AND cpsp.PERIOD_ID IN (" . $periods_list . ")
AND position(',0,' IN cp.DOES_ATTENDANCE)>0
AND (ac.SCHOOL_DATE BETWEEN s.START_DATE AND s.END_DATE OR (s.END_DATE IS NULL AND ac.SCHOOL_DATE>=s.START_DATE))
AND position(substring('UMTWHFS' FROM cast(extract(DOW FROM ac.SCHOOL_DATE) AS INT)+1 FOR 1) IN cpsp.DAYS)>0 AND s.MARKING_PERIOD_ID IN ($all_mp)" ), array(), array( 'PERIOD_ID' ) );
AND position(substring('UMTWHFS' FROM cast(extract(DOW FROM ac.SCHOOL_DATE) AS INT)+1 FOR 1) IN cpsp.DAYS)>0 AND s.MARKING_PERIOD_ID IN ($all_mp)", array(), array( 'PERIOD_ID' ) );
}
//echo '<pre>'; var_dump($course_periods_RET); echo '</pre>';
......@@ -170,12 +170,12 @@ if ( ! $_REQUEST['modfunc'] )
//FJ multiple school periods for a course period
//$periods_RET = DBGet(DBQuery("SELECT SHORT_NAME,PERIOD_ID FROM SCHOOL_PERIODS WHERE SYEAR='".UserSyear()."' AND SCHOOL_ID='".UserSchool()."' AND EXISTS (SELECT '' FROM COURSE_PERIODS WHERE PERIOD_ID=SCHOOL_PERIODS.PERIOD_ID AND position(',0,' IN DOES_ATTENDANCE)>0) ORDER BY SORT_ORDER"));
$periods_RET = DBGet( DBQuery( "SELECT SHORT_NAME,PERIOD_ID
$periods_RET = DBGet( "SELECT SHORT_NAME,PERIOD_ID
FROM SCHOOL_PERIODS
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
AND EXISTS (SELECT '' FROM COURSE_PERIOD_SCHOOL_PERIODS cpsp, COURSE_PERIODS cp WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID AND cpsp.PERIOD_ID=SCHOOL_PERIODS.PERIOD_ID AND position(',0,' IN cp.DOES_ATTENDANCE)>0)
ORDER BY SORT_ORDER" ) );
ORDER BY SORT_ORDER" );
foreach ( (array) $periods_RET as $period )
{
......@@ -186,11 +186,11 @@ if ( ! $_REQUEST['modfunc'] )
echo '<tr><td>' . _( 'Absence Code' ) . '</td><td><select name="absence_code">';
$codes_RET = DBGet( DBQuery( "SELECT TITLE,ID
$codes_RET = DBGet( "SELECT TITLE,ID
FROM ATTENDANCE_CODES
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
AND TABLE_NAME='0'" ) );
AND TABLE_NAME='0'" );
foreach ( (array) $codes_RET as $code )
{
......@@ -237,12 +237,12 @@ if ( ! $_REQUEST['modfunc'] )
'</th><th>' . mb_substr( _( 'Saturday' ), 0, 3 ) .
'</th></tr><tr>';
$calendar_RET = DBGet( DBQuery( "SELECT SCHOOL_DATE
$calendar_RET = DBGet( "SELECT SCHOOL_DATE
FROM ATTENDANCE_CALENDAR
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
AND MINUTES!='0'
AND EXTRACT(MONTH FROM SCHOOL_DATE)='" . ( $_REQUEST['month'] * 1 ) . "'" ), array(), array( 'SCHOOL_DATE' ) );
AND EXTRACT(MONTH FROM SCHOOL_DATE)='" . ( $_REQUEST['month'] * 1 ) . "'", array(), array( 'SCHOOL_DATE' ) );
for ( $i = 1; $i <= $skip; $i++ )
{
......
......@@ -64,10 +64,10 @@ if ( $_REQUEST['attendance']
}
}
$current_RET = DBGet( DBQuery( "SELECT ATTENDANCE_TEACHER_CODE,ATTENDANCE_CODE,
$current_RET = DBGet( "SELECT ATTENDANCE_TEACHER_CODE,ATTENDANCE_CODE,
ATTENDANCE_REASON,STUDENT_ID,ADMIN,COURSE_PERIOD_ID
FROM ATTENDANCE_PERIOD
WHERE SCHOOL_DATE='" . $date . "'" ), array(), array( 'STUDENT_ID', 'COURSE_PERIOD_ID' ) );
WHERE SCHOOL_DATE='" . $date . "'", array(), array( 'STUDENT_ID', 'COURSE_PERIOD_ID' ) );
// Unset attendance & redirect URL.
RedirectURL( 'attendance' );
......@@ -115,12 +115,12 @@ if ( $_REQUEST['search_modfunc'] || $_REQUEST['student_id'] || User('PROFILE')==
{
//FJ multiple school periods for a course period
//$periods_RET = DBGet(DBQuery("SELECT sp.PERIOD_ID,sp.TITLE FROM SCHOOL_PERIODS sp WHERE sp.SYEAR='".UserSyear()."' AND sp.SCHOOL_ID='".UserSchool()."' AND (SELECT count(1) FROM COURSE_PERIODS WHERE position(',0,' IN DOES_ATTENDANCE)>0 AND PERIOD_ID=sp.PERIOD_ID AND SYEAR=sp.SYEAR AND SCHOOL_ID=sp.SCHOOL_ID)>0 ORDER BY sp.SORT_ORDER"));
$periods_RET = DBGet( DBQuery( "SELECT sp.PERIOD_ID,sp.TITLE
$periods_RET = DBGet( "SELECT sp.PERIOD_ID,sp.TITLE
FROM SCHOOL_PERIODS sp
WHERE sp.SYEAR='" . UserSyear() . "'
AND sp.SCHOOL_ID='" . UserSchool() . "'
AND (SELECT count(1) FROM COURSE_PERIODS cp, COURSE_PERIOD_SCHOOL_PERIODS cpsp WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID AND position(',0,' IN cp.DOES_ATTENDANCE)>0 AND cpsp.PERIOD_ID=sp.PERIOD_ID AND cp.SYEAR=sp.SYEAR AND cp.SCHOOL_ID=sp.SCHOOL_ID)>0
ORDER BY sp.SORT_ORDER" ) );
ORDER BY sp.SORT_ORDER" );
foreach ( (array) $periods_RET as $period )
{
......@@ -133,12 +133,12 @@ if ( $_REQUEST['search_modfunc'] || $_REQUEST['student_id'] || User('PROFILE')==
{
//FJ multiple school periods for a course period
//$periods_RET = DBGet(DBQuery("SELECT sp.PERIOD_ID,sp.TITLE FROM SCHOOL_PERIODS sp,COURSE_PERIODS cp WHERE position(',0,' IN cp.DOES_ATTENDANCE)>0 AND sp.PERIOD_ID=cp.PERIOD_ID AND cp.COURSE_PERIOD_ID='".UserCoursePeriod()."'"));
$periods_RET = DBGet( DBQuery( "SELECT sp.PERIOD_ID,sp.TITLE
$periods_RET = DBGet( "SELECT sp.PERIOD_ID,sp.TITLE
FROM SCHOOL_PERIODS sp,COURSE_PERIODS cp, COURSE_PERIOD_SCHOOL_PERIODS cpsp
WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID
AND position(',0,' IN cp.DOES_ATTENDANCE)>0
AND sp.PERIOD_ID=cpsp.PERIOD_ID
AND cpsp.COURSE_PERIOD_SCHOOL_PERIODS_ID='" . UserCoursePeriodSchoolPeriod() . "'" ) );
AND cpsp.COURSE_PERIOD_SCHOOL_PERIODS_ID='" . UserCoursePeriodSchoolPeriod() . "'" );
if ( $periods_RET )
{
......@@ -203,11 +203,11 @@ if ( $_REQUEST['search_modfunc'] || $_REQUEST['student_id'] || User('PROFILE')==
);
}
$cal_RET = DBGet( DBQuery( "SELECT DISTINCT SCHOOL_DATE,'_'||to_char(SCHOOL_DATE,'yyyymmdd') AS SHORT_DATE
$cal_RET = DBGet( "SELECT DISTINCT SCHOOL_DATE,'_'||to_char(SCHOOL_DATE,'yyyymmdd') AS SHORT_DATE
FROM ATTENDANCE_CALENDAR
WHERE SCHOOL_ID='" . UserSchool() . "'
AND SCHOOL_DATE BETWEEN '" . $start_date . "' AND '" . $end_date . "'
ORDER BY SCHOOL_DATE" ) );
ORDER BY SCHOOL_DATE" );
//FJ bugfix bug when Back to Student Search
//if (UserStudentID() || $_REQUEST['student_id'] || User('PROFILE')=='parent')
......@@ -268,12 +268,12 @@ if ( $_REQUEST['student_id'] || User( 'PROFILE' ) === 'parent' )
'PERIOD_ID' => '0',
);
$attendance_RET = DBGet( DBQuery( "SELECT ad.SCHOOL_DATE,'0' AS PERIOD_ID,
$attendance_RET = DBGet( "SELECT ad.SCHOOL_DATE,'0' AS PERIOD_ID,
ad.STATE_VALUE AS STATE_CODE," .
db_case( array( 'ad.STATE_VALUE', "'0.0'", "'A'", "'1.0'", "'P'", "'H'" ) ) . " AS SHORT_NAME
FROM ATTENDANCE_DAY ad
WHERE ad.SCHOOL_DATE BETWEEN '" . $start_date . "' AND '" . $end_date . "'
AND ad.STUDENT_ID='" . UserStudentID() . "'" ), array(), array( 'SCHOOL_DATE', 'PERIOD_ID' ) );
AND ad.STUDENT_ID='" . UserStudentID() . "'", array(), array( 'SCHOOL_DATE', 'PERIOD_ID' ) );
}
$i = 0;
......@@ -416,11 +416,11 @@ function _makeColor( $value, $column )
{
if ( empty( $attendance_codes_RET ) )
{
$attendance_codes_RET = DBGet( DBQuery( "SELECT ID,DEFAULT_CODE,STATE_CODE,SHORT_NAME,TITLE
$attendance_codes_RET = DBGet( "SELECT ID,DEFAULT_CODE,STATE_CODE,SHORT_NAME,TITLE
FROM ATTENDANCE_CODES
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
AND TABLE_NAME='0'" ), array(), array( 'ID' ) );
AND TABLE_NAME='0'", array(), array( 'ID' ) );
}
return MakeAttendanceCode(
......@@ -445,11 +445,11 @@ function makeCodePulldown( $value, $student_id, $date )
if ( empty( $attendance_codes_RET ) )
{
$attendance_codes_RET = DBGet( DBQuery( "SELECT ID,DEFAULT_CODE,STATE_CODE,SHORT_NAME
$attendance_codes_RET = DBGet( "SELECT ID,DEFAULT_CODE,STATE_CODE,SHORT_NAME
FROM ATTENDANCE_CODES
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
AND TABLE_NAME='0'" ), array(), array( 'ID' ) );
AND TABLE_NAME='0'", array(), array( 'ID' ) );
}
if ( empty( $attendance_code_options ) )
......
......@@ -91,19 +91,19 @@ if ( ! empty( $_REQUEST['period_id'] ) )
{
if ( User( 'PROFILE' ) === 'teacher' )
{
$period_ids_RET = DBGet( DBQuery( "SELECT PERIOD_ID
$period_ids_RET = DBGet( "SELECT PERIOD_ID
FROM COURSE_PERIOD_SCHOOL_PERIODS
WHERE COURSE_PERIOD_ID IN (SELECT COURSE_PERIOD_ID
FROM COURSE_PERIOD_SCHOOL_PERIODS
WHERE COURSE_PERIOD_SCHOOL_PERIODS_ID='" . UserCoursePeriodSchoolPeriod() . "')" ) );
WHERE COURSE_PERIOD_SCHOOL_PERIODS_ID='" . UserCoursePeriodSchoolPeriod() . "')" );
}
else
{
$period_ids_RET = DBGet( DBQuery( "SELECT PERIOD_ID
$period_ids_RET = DBGet( "SELECT PERIOD_ID
FROM SCHOOL_PERIODS
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
ORDER BY SORT_ORDER" ) );
ORDER BY SORT_ORDER" );
}
$period_ids_list = array();
......@@ -157,13 +157,13 @@ Search( 'student_id', $extra );
if ( UserStudentID() )
{
$name_RET = DBGet( DBQuery( "SELECT " . DisplayNameSQL() . " AS FULL_NAME
$name_RET = DBGet( "SELECT " . DisplayNameSQL() . " AS FULL_NAME
FROM STUDENTS
WHERE STUDENT_ID='" . UserStudentID() . "'" ) );
WHERE STUDENT_ID='" . UserStudentID() . "'" );
DrawHeader( $name_RET[1]['FULL_NAME'] );
$absences_RET = DBGet( DBQuery( "SELECT ap.STUDENT_ID,ap.PERIOD_ID,ap.SCHOOL_DATE,ac.SHORT_NAME,
$absences_RET = DBGet( "SELECT ap.STUDENT_ID,ap.PERIOD_ID,ap.SCHOOL_DATE,ac.SHORT_NAME,
ac.TITLE,ac.STATE_CODE,ad.STATE_VALUE,ad.COMMENT AS OFFICE_COMMENT,ap.COMMENT AS TEACHER_COMMENT
FROM ATTENDANCE_PERIOD ap,ATTENDANCE_DAY ad,ATTENDANCE_CODES ac
WHERE ap.STUDENT_ID=ad.STUDENT_ID
......@@ -174,7 +174,7 @@ if ( UserStudentID() )
AND ap.SCHOOL_DATE BETWEEN '" . $start_date . "'
AND '" . $end_date . "'
AND ad.SYEAR='" . UserSyear() . "'
ORDER BY ap.SCHOOL_DATE" ), array(), array( 'SCHOOL_DATE', 'PERIOD_ID' ) );
ORDER BY ap.SCHOOL_DATE", array(), array( 'SCHOOL_DATE', 'PERIOD_ID' ) );
foreach ( (array) $absences_RET as $school_date => $absences )
{
......@@ -201,7 +201,7 @@ if ( UserStudentID() )
//FJ multiple school periods for a course period
//$periods_RET = DBGet(DBQuery("SELECT sp.PERIOD_ID,sp.SHORT_NAME FROM SCHOOL_PERIODS sp,SCHEDULE s,COURSE_PERIODS cp WHERE sp.SCHOOL_ID='".UserSchool()."' AND sp.SYEAR='".UserSyear()."' AND s.STUDENT_ID='".UserStudentID()."' AND cp.COURSE_PERIOD_ID=s.COURSE_PERIOD_ID AND cp.PERIOD_ID=sp.PERIOD_ID AND position(',0,' IN cp.DOES_ATTENDANCE)>0 ORDER BY sp.SORT_ORDER"));
$periods_RET = DBGet( DBQuery( "SELECT sp.PERIOD_ID,sp.SHORT_NAME
$periods_RET = DBGet( "SELECT sp.PERIOD_ID,sp.SHORT_NAME
FROM SCHOOL_PERIODS sp,SCHEDULE s,COURSE_PERIODS cp,COURSE_PERIOD_SCHOOL_PERIODS cpsp
WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID
AND sp.SCHOOL_ID='" . UserSchool() . "'
......@@ -210,7 +210,7 @@ if ( UserStudentID() )
AND cp.COURSE_PERIOD_ID=s.COURSE_PERIOD_ID
AND cpsp.PERIOD_ID=sp.PERIOD_ID
AND position(',0,' IN cp.DOES_ATTENDANCE)>0
ORDER BY sp.SORT_ORDER" ) );
ORDER BY sp.SORT_ORDER" );
$columns['SCHOOL_DATE'] = _( 'Date' );
......
......@@ -26,7 +26,7 @@ else
}
//FJ bugfix SQL bug more than one row returned by a subquery
$categories_RET = DBGet( DBQuery( "SELECT '0' AS ID,'" . DBEscapeString( _( 'Attendance' ) ) . "' AS TITLE,0,NULL AS SORT_ORDER
$categories_RET = DBGet( "SELECT '0' AS ID,'" . DBEscapeString( _( 'Attendance' ) ) . "' AS TITLE,0,NULL AS SORT_ORDER
WHERE position(',0,' IN
(SELECT DOES_ATTENDANCE
FROM COURSE_PERIODS
......@@ -41,11 +41,11 @@ $categories_RET = DBGet( DBQuery( "SELECT '0' AS ID,'" . DBEscapeString( _( 'Att
FROM COURSE_PERIODS
WHERE COURSE_PERIOD_ID='" . UserCoursePeriod() . "')
)>0
ORDER BY 3,SORT_ORDER,TITLE" ) );
ORDER BY 3,SORT_ORDER,TITLE" );
$cp_title_RET = DBGet( DBQuery( "SELECT TITLE
$cp_title_RET = DBGet( "SELECT TITLE
FROM COURSE_PERIODS
WHERE COURSE_PERIOD_ID='" . UserCoursePeriod() . "'" ) );
WHERE COURSE_PERIOD_ID='" . UserCoursePeriod() . "'" );
if ( isset( $cp_title_RET[1]['TITLE'] ) )
{
......@@ -82,7 +82,7 @@ else
if ( SchoolInfo( 'NUMBER_DAYS_ROTATION' ) !== null )
{
$course_RET = DBGet( DBQuery( "SELECT cp.HALF_DAY
$course_RET = DBGet( "SELECT cp.HALF_DAY
FROM ATTENDANCE_CALENDAR acc,COURSE_PERIODS cp,SCHOOL_PERIODS sp, COURSE_PERIOD_SCHOOL_PERIODS cpsp
WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID
AND acc.SYEAR='" . UserSyear() . "'
......@@ -102,11 +102,11 @@ if ( SchoolInfo( 'NUMBER_DAYS_ROTATION' ) !== null )
AND school_date<=acc.SCHOOL_DATE
AND SCHOOL_ID=acc.SCHOOL_ID)
AS INT) FOR 1) IN cpsp.DAYS)>0 OR sp.BLOCK IS NOT NULL AND acc.BLOCK IS NOT NULL AND sp.BLOCK=acc.BLOCK)
AND position('," . $_REQUEST['table'] . ",' IN cp.DOES_ATTENDANCE)>0" ) );
AND position('," . $_REQUEST['table'] . ",' IN cp.DOES_ATTENDANCE)>0" );
}
else
{
$course_RET = DBGet( DBQuery( "SELECT cp.HALF_DAY
$course_RET = DBGet( "SELECT cp.HALF_DAY
FROM ATTENDANCE_CALENDAR acc,COURSE_PERIODS cp,SCHOOL_PERIODS sp, COURSE_PERIOD_SCHOOL_PERIODS cpsp
WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID
AND acc.SYEAR='" . UserSyear() . "'
......@@ -118,7 +118,7 @@ else
AND cp.MARKING_PERIOD_ID IN (SELECT MARKING_PERIOD_ID FROM SCHOOL_MARKING_PERIODS WHERE (MP='FY' OR MP='SEM' OR MP='QTR') AND SCHOOL_ID=acc.SCHOOL_ID AND acc.SCHOOL_DATE BETWEEN START_DATE AND END_DATE)
AND sp.PERIOD_ID=cpsp.PERIOD_ID
AND (sp.BLOCK IS NULL AND position(substring('UMTWHFS' FROM cast(extract(DOW FROM acc.SCHOOL_DATE) AS INT)+1 FOR 1) IN cpsp.DAYS)>0 OR sp.BLOCK IS NOT NULL AND acc.BLOCK IS NOT NULL AND sp.BLOCK=acc.BLOCK)
AND position('," . $_REQUEST['table'] . ",' IN cp.DOES_ATTENDANCE)>0" ) );
AND position('," . $_REQUEST['table'] . ",' IN cp.DOES_ATTENDANCE)>0" );
}
// Instead of displaying a fatal error which could confuse user, display a warning and exit.
......@@ -248,12 +248,12 @@ if ( ! empty( $_REQUEST['attendance'] )
}
}
$completed_RET = DBGet( DBQuery( "SELECT 'Y' AS COMPLETED
$completed_RET = DBGet( "SELECT 'Y' AS COMPLETED
FROM ATTENDANCE_COMPLETED
WHERE STAFF_ID='" . User( 'STAFF_ID' ) . "'
AND SCHOOL_DATE='" . $date . "'
AND PERIOD_ID='" . UserPeriod() . "'
AND TABLE_NAME='" . $_REQUEST['table'] . "'" ) );
AND TABLE_NAME='" . $_REQUEST['table'] . "'" );
if ( ! count( $completed_RET ) )
{
......@@ -279,14 +279,14 @@ if ( ! empty( $_REQUEST['attendance'] )
RedirectURL( 'attendance' );
}
$codes_RET = DBGet( DBQuery( "SELECT ID,TITLE,DEFAULT_CODE,STATE_CODE
$codes_RET = DBGet( "SELECT ID,TITLE,DEFAULT_CODE,STATE_CODE
FROM ATTENDANCE_CODES
WHERE SCHOOL_ID='" . UserSchool() . "'
AND SYEAR='" . UserSyear() . "'
AND TYPE='teacher'
AND TABLE_NAME='" . $_REQUEST['table'] . "'" .
( $_REQUEST['table'] == '0' && $course_RET[1]['HALF_DAY'] ? " AND STATE_CODE!='H'" : '' ) .
" ORDER BY SORT_ORDER" ) );
" ORDER BY SORT_ORDER" );
$columns = array();
......@@ -360,12 +360,12 @@ $date_note .= AllowEdit() ? ' <span style="color:green" class="nobr">' .
_( 'You can edit this attendance' ) . '</span>' :
' <span style="color:red" class="nobr">' . _( 'You cannot edit this attendance' ) . '</span>';
$completed_RET = DBGet( DBQuery( "SELECT 'Y' AS COMPLETED
$completed_RET = DBGet( "SELECT 'Y' AS COMPLETED
FROM ATTENDANCE_COMPLETED
WHERE STAFF_ID='" . User( 'STAFF_ID' ) . "'
AND SCHOOL_DATE='" . $date . "'
AND PERIOD_ID='" . UserPeriod() . "'
AND TABLE_NAME='" . $_REQUEST['table'] . "'" ) );
AND TABLE_NAME='" . $_REQUEST['table'] . "'" );
if ( $completed_RET )
{
......
......@@ -108,13 +108,13 @@ function AttendanceCodesTipMessage( $type = '' )
$type_where = " AND TYPE='" . $type . "' ";
}
$attendance_codes_RET = DBGet( DBQuery( "SELECT ID,DEFAULT_CODE,STATE_CODE,SHORT_NAME,TITLE
$attendance_codes_RET = DBGet( "SELECT ID,DEFAULT_CODE,STATE_CODE,SHORT_NAME,TITLE
FROM ATTENDANCE_CODES
WHERE SYEAR='" . UserSyear() . "'
AND SCHOOL_ID='" . UserSchool() . "'
AND TABLE_NAME='0'" .
$type_where .
" ORDER BY TABLE_NAME,SORT_ORDER" ) );
" ORDER BY TABLE_NAME,SORT_ORDER" );
}
foreach ( (array) $attendance_codes_RET as $attendance_code )
......
......@@ -45,7 +45,7 @@ if ( ! function_exists( 'DashboardAttendanceAdmin' ) )
$absences_today = 0;
// Absences by day.
$absences_RET = DBGet( DBQuery( "SELECT SCHOOL_DATE,
$absences_RET = DBGet( "SELECT SCHOOL_DATE,
SUM(CASE WHEN STATE_VALUE='0.0' THEN 1 END) AS ABSENT,
SUM(CASE WHEN STATE_VALUE='0.5' THEN 1 END) AS HALF_DAY
FROM ATTENDANCE_DAY ad,STUDENT_ENROLLMENT ssm
......@@ -57,7 +57,7 @@ if ( ! function_exists( 'DashboardAttendanceAdmin' ) )
AND ssm.END_DATE IS NULL OR SCHOOL_DATE<=ssm.END_DATE
GROUP BY SCHOOL_DATE
ORDER BY SCHOOL_DATE DESC
LIMIT 7" ) );
LIMIT 7" );
if ( ! empty( $absences_RET[1] )
&& $absences_RET[1]['SCHOOL_DATE'] === DBDate() )
......
......@@ -24,7 +24,9 @@ if ( $_REQUEST['modfunc'] === 'save' )
);
// Check Social Security + Gender fields exists before adding them to SELECT.
$custom_RET = DBGet( DBQuery( "SELECT TITLE,ID FROM CUSTOM_FIELDS WHERE ID IN ('200000000','200000003')" ), array(), array( 'ID' ) );
$custom_RET = DBGet( "SELECT TITLE,ID
FROM CUSTOM_FIELDS
WHERE ID IN ('200000000','200000003')", array(), array( 'ID' ) );
$extra['SELECT'] = ",ssm.CALENDAR_ID,ssm.START_DATE,ssm.END_DATE";
......@@ -63,7 +65,7 @@ if ( $_REQUEST['modfunc'] === 'save' )
foreach ( (array) $RET as $student )
{
$calendar_RET = DBGet( DBquery( "SELECT CASE WHEN
$calendar_RET = DBGet( "SELECT CASE WHEN
MINUTES>=" . Config( 'ATTENDANCE_FULL_DAY_MINUTES' ) .
" THEN '1.0' ELSE '0.5' END AS POS,
trim(leading '0' from to_char(SCHOOL_DATE,'MM')) AS MON,
......@@ -71,11 +73,11 @@ if ( $_REQUEST['modfunc'] === 'save' )
FROM ATTENDANCE_CALENDAR
WHERE CALENDAR_ID='" . $student['CALENDAR_ID'] . "'
AND SCHOOL_DATE>='" . $student['START_DATE'] . "'" .
( $student['END_DATE'] ? " AND SCHOOL_DATE<='" . $student['END_DATE'] . "'" : '' ) ),
( $student['END_DATE'] ? " AND SCHOOL_DATE<='" . $student['END_DATE'] . "'" : '' ),
array(),
array( 'MON', 'DAY' ) );
$attendance_RET = DBGet( DBQuery( "SELECT
$attendance_RET = DBGet( "SELECT
trim(leading '0' from to_char(ap.SCHOOL_DATE,'MM')) AS MON,
trim(leading '0' from to_char(ap.SCHOOL_DATE,'DD')) AS DAY,
ac.STATE_CODE,
......@@ -86,7 +88,7 @@ if ( $_REQUEST['modfunc'] === 'save' )
AND sp.SCHOOL_ID='" . UserSchool() . "'
AND sp.SYEAR='" . UserSyear() . "'
AND ac.ID=ap.ATTENDANCE_CODE
AND sp.ATTENDANCE='Y'" ), array(), array( 'MON', 'DAY' ) );
AND sp.ATTENDANCE='Y'", array(), array( 'MON', 'DAY' ) );
//echo '<pre>'; var_dump($calendar_RET); echo '</pre>';
echo '<table class="width-100p"><tr><td class="center">
......@@ -151,11 +153,11 @@ if ( $_REQUEST['modfunc'] === 'save' )
$abs_tot = $pos_tot = 0;
$FY_dates = DBGet( DBQuery( "SELECT START_DATE,END_DATE
$FY_dates = DBGet( "SELECT START_DATE,END_DATE
FROM SCHOOL_MARKING_PERIODS