Commit 4500e81f authored by François Jacquet's avatar François Jacquet
Browse files

Format long SQL statements for readability

parent 6215d6c7
......@@ -136,13 +136,33 @@ function _makeAutoSelectInput($column,$name,$request)
{
// add values found in current and previous year
if($request=='values[ADDRESS]')
$options_RET = DBGet(DBQuery("SELECT DISTINCT a.CUSTOM_$field[ID],upper(a.CUSTOM_$field[ID]) AS SORT_KEY FROM ADDRESS a,STUDENTS_JOIN_ADDRESS sja,STUDENTS s,STUDENT_ENROLLMENT sse WHERE a.ADDRESS_ID=sja.ADDRESS_ID AND s.STUDENT_ID=sja.STUDENT_ID AND sse.STUDENT_ID=s.STUDENT_ID AND (sse.SYEAR='".UserSyear()."' OR sse.SYEAR='".(UserSyear()-1)."') AND a.CUSTOM_$field[ID] IS NOT NULL ORDER BY SORT_KEY"));
$options_RET = DBGet(DBQuery("SELECT DISTINCT a.CUSTOM_".$field['ID'].",upper(a.CUSTOM_".$field['ID'].") AS SORT_KEY
FROM ADDRESS a,STUDENTS_JOIN_ADDRESS sja,STUDENTS s,STUDENT_ENROLLMENT sse
WHERE a.ADDRESS_ID=sja.ADDRESS_ID
AND s.STUDENT_ID=sja.STUDENT_ID
AND sse.STUDENT_ID=s.STUDENT_ID
AND (sse.SYEAR='".UserSyear()."' OR sse.SYEAR='".(UserSyear()-1)."')
AND a.CUSTOM_".$field['ID']." IS NOT NULL
ORDER BY SORT_KEY"));
elseif($request=='values[PEOPLE]')
$options_RET = DBGet(DBQuery("SELECT DISTINCT p.CUSTOM_$field[ID],upper(p.CUSTOM_$field[ID]) AS SORT_KEY FROM PEOPLE p,STUDENTS_JOIN_PEOPLE sjp,STUDENTS s,STUDENT_ENROLLMENT sse WHERE p.PERSON_ID=sjp.PERSON_ID AND s.STUDENT_ID=sjp.STUDENT_ID AND sse.STUDENT_ID=s.STUDENT_ID AND (sse.SYEAR='".UserSyear()."' OR sse.SYEAR='".(UserSyear()-1)."') AND p.CUSTOM_$field[ID] IS NOT NULL ORDER BY SORT_KEY"));
$options_RET = DBGet(DBQuery("SELECT DISTINCT p.CUSTOM_".$field['ID'].",upper(p.CUSTOM_".$field['ID'].") AS SORT_KEY
FROM PEOPLE p,STUDENTS_JOIN_PEOPLE sjp,STUDENTS s,STUDENT_ENROLLMENT sse
WHERE p.PERSON_ID=sjp.PERSON_ID
AND s.STUDENT_ID=sjp.STUDENT_ID
AND sse.STUDENT_ID=s.STUDENT_ID
AND (sse.SYEAR='".UserSyear()."' OR sse.SYEAR='".(UserSyear()-1)."')
AND p.CUSTOM_".$field['ID']." IS NOT NULL
ORDER BY SORT_KEY"));
elseif($request=='students')
$options_RET = DBGet(DBQuery("SELECT DISTINCT s.CUSTOM_$field[ID],upper(s.CUSTOM_$field[ID]) AS SORT_KEY FROM STUDENTS s,STUDENT_ENROLLMENT sse WHERE sse.STUDENT_ID=s.STUDENT_ID AND (sse.SYEAR='".UserSyear()."' OR sse.SYEAR='".(UserSyear()-1)."') AND s.CUSTOM_$field[ID] IS NOT NULL ORDER BY SORT_KEY"));
$options_RET = DBGet(DBQuery("SELECT DISTINCT s.CUSTOM_".$field['ID'].",upper(s.CUSTOM_".$field['ID'].") AS SORT_KEY
FROM STUDENTS s,STUDENT_ENROLLMENT sse
WHERE sse.STUDENT_ID=s.STUDENT_ID
AND (sse.SYEAR='".UserSyear()."' OR sse.SYEAR='".(UserSyear()-1)."')
AND s.CUSTOM_".$field['ID']." IS NOT NULL
ORDER BY SORT_KEY"));
elseif($request=='staff')
$options_RET = DBGet(DBQuery("SELECT DISTINCT s.CUSTOM_$field[ID],upper(s.CUSTOM_$field[ID]) AS KEY FROM STAFF s WHERE (s.SYEAR='".UserSyear()."' OR s.SYEAR='".(UserSyear()-1)."') AND s.CUSTOM_$field[ID] IS NOT NULL ORDER BY KEY"));
$options_RET = DBGet(DBQuery("SELECT DISTINCT s.CUSTOM_".$field['ID'].",upper(s.CUSTOM_".$field['ID'].") AS KEY FROM STAFF s WHERE (s.SYEAR='".UserSyear()."' OR s.SYEAR='".(UserSyear()-1)."') AND s.CUSTOM_".$field['ID']." IS NOT NULL ORDER BY KEY"));
if(count($options_RET))
{
foreach($options_RET as $option)
......
......@@ -121,7 +121,13 @@ if(User('PROFILE')=='admin' || User('PROFILE')=='teacher')
if(User('PROFILE')=='parent')
{
$RET = DBGet(DBQuery("SELECT sju.STUDENT_ID,s.LAST_NAME||', '||s.FIRST_NAME AS FULL_NAME,se.SCHOOL_ID FROM STUDENTS s,STUDENTS_JOIN_USERS sju, STUDENT_ENROLLMENT se WHERE s.STUDENT_ID=sju.STUDENT_ID AND sju.STAFF_ID='".User('STAFF_ID')."' AND se.SYEAR='".UserSyear()."' AND se.STUDENT_ID=sju.STUDENT_ID AND ('".DBDate()."'>=se.START_DATE AND ('".DBDate()."'<=se.END_DATE OR se.END_DATE IS NULL))"));
$RET = DBGet(DBQuery("SELECT sju.STUDENT_ID,s.LAST_NAME||', '||s.FIRST_NAME AS FULL_NAME,se.SCHOOL_ID
FROM STUDENTS s,STUDENTS_JOIN_USERS sju,STUDENT_ENROLLMENT se
WHERE s.STUDENT_ID=sju.STUDENT_ID
AND sju.STAFF_ID='".User('STAFF_ID')."'
AND se.SYEAR='".UserSyear()."'
AND se.STUDENT_ID=sju.STUDENT_ID
AND ('".DBDate()."'>=se.START_DATE AND ('".DBDate()."'<=se.END_DATE OR se.END_DATE IS NULL))"));
if(!UserStudentID())
$_SESSION['student_id'] = $RET[1]['STUDENT_ID'];
......@@ -184,7 +190,17 @@ if(User('PROFILE')=='teacher')
{
//modif Francois: multiple school periods for a course period
//$QI = DBQuery("SELECT cp.PERIOD_ID,cp.COURSE_PERIOD_ID,sp.TITLE,sp.SHORT_NAME,cp.MARKING_PERIOD_ID,cp.DAYS,c.TITLE AS COURSE_TITLE FROM COURSE_PERIODS cp, SCHOOL_PERIODS sp,COURSES c WHERE c.COURSE_ID=cp.COURSE_ID AND cp.PERIOD_ID=sp.PERIOD_ID AND cp.SYEAR='".UserSyear()."' AND cp.SCHOOL_ID='".UserSchool()."' AND cp.TEACHER_ID='".User('STAFF_ID')."' AND cp.MARKING_PERIOD_ID IN (".GetAllMP('QTR',UserMP()).") ORDER BY sp.SORT_ORDER");
$QI = DBQuery("SELECT cpsp.PERIOD_ID,cp.COURSE_PERIOD_ID,cpsp.COURSE_PERIOD_SCHOOL_PERIODS_ID,sp.TITLE,sp.SHORT_NAME,cp.MARKING_PERIOD_ID,cpsp.DAYS,c.TITLE AS COURSE_TITLE, cp.SHORT_NAME AS CP_SHORT_NAME FROM COURSE_PERIODS cp,SCHOOL_PERIODS sp,COURSES c, COURSE_PERIOD_SCHOOL_PERIODS cpsp WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID AND c.COURSE_ID=cp.COURSE_ID AND cpsp.PERIOD_ID=sp.PERIOD_ID AND cp.SYEAR='".UserSyear()."' AND cp.SCHOOL_ID='".UserSchool()."' AND cp.TEACHER_ID='".User('STAFF_ID')."' AND cp.MARKING_PERIOD_ID IN (".GetAllMP('QTR',UserMP()).") ORDER BY cp.SHORT_NAME, sp.SORT_ORDER");
$QI = DBQuery("SELECT cpsp.PERIOD_ID,cp.COURSE_PERIOD_ID,cpsp.COURSE_PERIOD_SCHOOL_PERIODS_ID,sp.TITLE,sp.SHORT_NAME,cp.MARKING_PERIOD_ID,cpsp.DAYS,c.TITLE AS COURSE_TITLE, cp.SHORT_NAME AS CP_SHORT_NAME
FROM COURSE_PERIODS cp,SCHOOL_PERIODS sp,COURSES c,COURSE_PERIOD_SCHOOL_PERIODS cpsp
WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID
AND c.COURSE_ID=cp.COURSE_ID
AND cpsp.PERIOD_ID=sp.PERIOD_ID
AND cp.SYEAR='".UserSyear()."'
AND cp.SCHOOL_ID='".UserSchool()."'
AND cp.TEACHER_ID='".User('STAFF_ID')."'
AND cp.MARKING_PERIOD_ID IN (".GetAllMP('QTR',UserMP()).")
ORDER BY cp.SHORT_NAME, sp.SORT_ORDER");
//modif Francois: add subject areas
$RET = DBGet($QI, array('COURSE_TITLE'=>'CourseTitle'));
// get the fy marking period id, there should be exactly one fy marking period per school
......
......@@ -69,7 +69,10 @@ function GetAllMP($mp,$marking_period_id='0')
foreach($value as $qtr)
$_ROSARIO['GetAllMP'][$mp][$marking_period_id] .= ",'".$qtr['MARKING_PERIOD_ID']."'";
}
$RET = DBGet(DBQuery("SELECT MARKING_PERIOD_ID FROM SCHOOL_MARKING_PERIODS s WHERE MP='SEM' AND NOT EXISTS (SELECT '' FROM SCHOOL_MARKING_PERIODS q WHERE q.MP='QTR' AND q.PARENT_ID=s.MARKING_PERIOD_ID) AND SYEAR='".UserSyear()."' AND SCHOOL_ID='".UserSchool()."'"));
$RET = DBGet(DBQuery("SELECT MARKING_PERIOD_ID
FROM SCHOOL_MARKING_PERIODS s
WHERE MP='SEM' AND NOT EXISTS (SELECT '' FROM SCHOOL_MARKING_PERIODS q WHERE q.MP='QTR' AND q.PARENT_ID=s.MARKING_PERIOD_ID)
AND SYEAR='".UserSyear()."' AND SCHOOL_ID='".UserSchool()."'"));
foreach($RET as $value)
$_ROSARIO['GetAllMP'][$mp][$marking_period_id] .= ",'".$value['MARKING_PERIOD_ID']."'";
break;
......
......@@ -10,7 +10,9 @@ function GetMP($mp,$column='TITLE')
if(!isset($_ROSARIO['GetMP']))
{
$_ROSARIO['GetMP'] = DBGet(DBQuery("SELECT MARKING_PERIOD_ID,TITLE,POST_START_DATE,POST_END_DATE,MP,SORT_ORDER,SHORT_NAME,START_DATE,END_DATE,DOES_GRADES,DOES_COMMENTS FROM SCHOOL_MARKING_PERIODS WHERE SYEAR='".UserSyear()."' AND SCHOOL_ID='".UserSchool()."'"),array(),array('MARKING_PERIOD_ID'));
$_ROSARIO['GetMP'] = DBGet(DBQuery("SELECT MARKING_PERIOD_ID,TITLE,POST_START_DATE,POST_END_DATE,MP,SORT_ORDER,SHORT_NAME,START_DATE,END_DATE,DOES_GRADES,DOES_COMMENTS
FROM SCHOOL_MARKING_PERIODS
WHERE SYEAR='".UserSyear()."' AND SCHOOL_ID='".UserSchool()."'"),array(),array('MARKING_PERIOD_ID'));
}
$suffix = '';
......
......@@ -19,7 +19,10 @@ function GetStaffList(& $extra)
$extra['columns_after']['FAILED_LOGIN'] = _('Failed Login');
$functions['FAILED_LOGIN'] = 'makeLogin';
$view_fields_RET = DBGet(DBQuery("SELECT cf.ID,cf.TYPE,cf.TITLE FROM STAFF_FIELDS cf WHERE ((SELECT VALUE FROM PROGRAM_USER_CONFIG WHERE TITLE=cast(cf.ID AS TEXT) AND PROGRAM='StaffFieldsView' AND USER_ID='".User('STAFF_ID')."')='Y'".($extra['staff_fields']['view']?" OR cf.ID IN (".$extra['staff_fields']['view'].")":'').") ORDER BY cf.SORT_ORDER,cf.TITLE"));
$view_fields_RET = DBGet(DBQuery("SELECT cf.ID,cf.TYPE,cf.TITLE
FROM STAFF_FIELDS cf
WHERE ((SELECT VALUE FROM PROGRAM_USER_CONFIG WHERE TITLE=cast(cf.ID AS TEXT) AND PROGRAM='StaffFieldsView' AND USER_ID='".User('STAFF_ID')."')='Y'".($extra['staff_fields']['view']?" OR cf.ID IN (".$extra['staff_fields']['view'].")":'').")
ORDER BY cf.SORT_ORDER,cf.TITLE"));
foreach($view_fields_RET as $field)
{
......
......@@ -28,7 +28,10 @@ function GetStuList(&$extra=array())
if(!$extra['columns_after'])
$extra['columns_after'] = array();
$view_fields_RET = DBGet(DBQuery("SELECT cf.ID,cf.TYPE,cf.TITLE FROM CUSTOM_FIELDS cf WHERE ((SELECT VALUE FROM PROGRAM_USER_CONFIG WHERE TITLE=cast(cf.ID AS TEXT) AND PROGRAM='StudentFieldsView' AND USER_ID='".User('STAFF_ID')."')='Y'".($extra['student_fields']['view']?" OR cf.ID IN (".$extra['student_fields']['view'].")":'').") ORDER BY cf.SORT_ORDER,cf.TITLE"));
$view_fields_RET = DBGet(DBQuery("SELECT cf.ID,cf.TYPE,cf.TITLE
FROM CUSTOM_FIELDS cf
WHERE ((SELECT VALUE FROM PROGRAM_USER_CONFIG WHERE TITLE=cast(cf.ID AS TEXT) AND PROGRAM='StudentFieldsView' AND USER_ID='".User('STAFF_ID')."')='Y'".($extra['student_fields']['view']?" OR cf.ID IN (".$extra['student_fields']['view'].")":'').")
ORDER BY cf.SORT_ORDER,cf.TITLE"));
$view_address_RET = DBGet(DBQuery("SELECT VALUE FROM PROGRAM_USER_CONFIG WHERE PROGRAM='StudentFieldsView' AND TITLE='ADDRESS' AND USER_ID='".User('STAFF_ID')."'"));
$view_address_RET = $view_address_RET[1]['VALUE'];
$view_other_RET = DBGet(DBQuery("SELECT TITLE,VALUE FROM PROGRAM_USER_CONFIG WHERE PROGRAM='StudentFieldsView' AND TITLE IN ('CONTACT_INFO','HOME_PHONE','GUARDIANS','ALL_CONTACTS') AND USER_ID='".User('STAFF_ID')."'"),array(),array('TITLE'));
......@@ -363,7 +366,10 @@ function makeParents($student_id,$column)
else
$constraint .= " AND sjp.CUSTODY='Y'";
$people_RET = DBGet(DBQuery("SELECT p.PERSON_ID,p.FIRST_NAME,p.LAST_NAME,sjp.CUSTODY,sjp.EMERGENCY FROM STUDENTS_JOIN_PEOPLE sjp,PEOPLE p WHERE sjp.PERSON_ID=p.PERSON_ID AND sjp.STUDENT_ID='".$student_id."' AND sjp.ADDRESS_ID='".$THIS_RET['ADDRESS_ID']."'$constraint ORDER BY sjp.CUSTODY,sjp.STUDENT_RELATION,p.LAST_NAME,p.FIRST_NAME"));
$people_RET = DBGet(DBQuery("SELECT p.PERSON_ID,p.FIRST_NAME,p.LAST_NAME,sjp.CUSTODY,sjp.EMERGENCY
FROM STUDENTS_JOIN_PEOPLE sjp,PEOPLE p
WHERE sjp.PERSON_ID=p.PERSON_ID AND sjp.STUDENT_ID='".$student_id."' AND sjp.ADDRESS_ID='".$THIS_RET['ADDRESS_ID']."'$constraint
ORDER BY sjp.CUSTODY,sjp.STUDENT_RELATION,p.LAST_NAME,p.FIRST_NAME"));
if(count($people_RET))
{
$THIS_RET['PARENTS'] .= '<TABLE class="cellpadding-0 cellspacing-0">';
......
......@@ -5,7 +5,10 @@ function GetTeacher($teacher_id,$title='',$column='FULL_NAME',$schools=true)
if(!$_ROSARIO['GetTeacher'])
{
$QI=DBQuery("SELECT STAFF_ID,LAST_NAME||', '||FIRST_NAME AS FULL_NAME,USERNAME,PROFILE FROM STAFF WHERE SYEAR='".UserSyear()."'".($schools?" AND (SCHOOLS IS NULL OR SCHOOLS LIKE '%,".UserSchool().",%')":''));
$QI=DBQuery("SELECT STAFF_ID,LAST_NAME||', '||FIRST_NAME AS FULL_NAME,USERNAME,PROFILE
FROM STAFF
WHERE SYEAR='".UserSyear()."'".
($schools?" AND (SCHOOLS IS NULL OR SCHOOLS LIKE '%,".UserSchool().",%')":''));
$_ROSARIO['GetTeacher'] = DBGet($QI,array(),array('STAFF_ID'));
}
......
......@@ -105,13 +105,34 @@ function Search($type,$extra=null)
case 'student_fields':
case 'student_fields_all':
if($type=='staff_fields_all')
$categories_RET = ParseMLArray(DBGet(DBQuery("SELECT sfc.ID,sfc.TITLE AS CATEGORY_TITLE,'CUSTOM_'||cf.ID AS COLUMN_NAME,cf.TYPE,cf.TITLE,SELECT_OPTIONS FROM STAFF_FIELD_CATEGORIES sfc,STAFF_FIELDS cf WHERE (SELECT CAN_USE FROM ".(User('PROFILE_ID')?"PROFILE_EXCEPTIONS WHERE PROFILE_ID='".User('PROFILE_ID')."'":"STAFF_EXCEPTIONS WHERE USER_ID='".User('STAFF_ID')."'")." AND MODNAME='Users/User.php&category_id='||sfc.ID)='Y' AND cf.CATEGORY_ID=sfc.ID AND NOT exists(SELECT '' FROM PROGRAM_USER_CONFIG WHERE PROGRAM='StaffFieldsSearch' AND TITLE=cast(cf.ID AS TEXT) AND USER_ID='".User('STAFF_ID')."' AND VALUE='Y') ORDER BY sfc.SORT_ORDER,sfc.TITLE,cf.SORT_ORDER,cf.TITLE"),array(),array('ID','TYPE')),array('CATEGORY_TITLE','TITLE'));
$categories_RET = ParseMLArray(DBGet(DBQuery("SELECT sfc.ID,sfc.TITLE AS CATEGORY_TITLE,'CUSTOM_'||cf.ID AS COLUMN_NAME,cf.TYPE,cf.TITLE,SELECT_OPTIONS
FROM STAFF_FIELD_CATEGORIES sfc,STAFF_FIELDS cf
WHERE
(SELECT CAN_USE FROM ".(User('PROFILE_ID')?"PROFILE_EXCEPTIONS WHERE PROFILE_ID='".User('PROFILE_ID')."'":"STAFF_EXCEPTIONS WHERE USER_ID='".User('STAFF_ID')."'")." AND MODNAME='Users/User.php&category_id='||sfc.ID)='Y'
AND cf.CATEGORY_ID=sfc.ID
AND NOT exists(SELECT '' FROM PROGRAM_USER_CONFIG WHERE PROGRAM='StaffFieldsSearch' AND TITLE=cast(cf.ID AS TEXT) AND USER_ID='".User('STAFF_ID')."' AND VALUE='Y')
ORDER BY sfc.SORT_ORDER,sfc.TITLE,cf.SORT_ORDER,cf.TITLE"),array(),array('ID','TYPE')),array('CATEGORY_TITLE','TITLE'));
elseif($type=='staff_fields')
$categories_RET = ParseMLArray(DBGet(DBQuery("SELECT '0' AS ID,'' AS CATEGORY_TITLE,'CUSTOM_'||cf.ID AS COLUMN_NAME,cf.TYPE,cf.TITLE,cf.SELECT_OPTIONS FROM STAFF_FIELDS cf WHERE (SELECT CAN_USE FROM ".(User('PROFILE_ID')?"PROFILE_EXCEPTIONS WHERE PROFILE_ID='".User('PROFILE_ID')."'":"STAFF_EXCEPTIONS WHERE USER_ID='".User('STAFF_ID')."'")." AND MODNAME='Users/User.php&category_id='||cf.CATEGORY_ID)='Y' AND ((SELECT VALUE FROM PROGRAM_USER_CONFIG WHERE TITLE=cast(cf.ID AS TEXT) AND PROGRAM='StaffFieldsSearch' AND USER_ID='".User('STAFF_ID')."')='Y') ORDER BY cf.SORT_ORDER,cf.TITLE"),array(),array('ID','TYPE')),array('CATEGORY_TITLE','TITLE'));
$categories_RET = ParseMLArray(DBGet(DBQuery("SELECT '0' AS ID,'' AS CATEGORY_TITLE,'CUSTOM_'||cf.ID AS COLUMN_NAME,cf.TYPE,cf.TITLE,cf.SELECT_OPTIONS
FROM STAFF_FIELDS cf
WHERE (SELECT CAN_USE FROM ".(User('PROFILE_ID')?"PROFILE_EXCEPTIONS WHERE PROFILE_ID='".User('PROFILE_ID')."'":"STAFF_EXCEPTIONS WHERE USER_ID='".User('STAFF_ID')."'")." AND MODNAME='Users/User.php&category_id='||cf.CATEGORY_ID)='Y'
AND ((SELECT VALUE FROM PROGRAM_USER_CONFIG WHERE TITLE=cast(cf.ID AS TEXT)
AND PROGRAM='StaffFieldsSearch'
AND USER_ID='".User('STAFF_ID')."')='Y')
ORDER BY cf.SORT_ORDER,cf.TITLE"),array(),array('ID','TYPE')),array('CATEGORY_TITLE','TITLE'));
elseif($type=='student_fields_all')
$categories_RET = ParseMLArray(DBGet(DBQuery("SELECT sfc.ID,sfc.TITLE AS CATEGORY_TITLE,'CUSTOM_'||cf.ID AS COLUMN_NAME,cf.TYPE,cf.TITLE,SELECT_OPTIONS FROM STUDENT_FIELD_CATEGORIES sfc,CUSTOM_FIELDS cf WHERE (SELECT CAN_USE FROM ".(User('PROFILE_ID')?"PROFILE_EXCEPTIONS WHERE PROFILE_ID='".User('PROFILE_ID')."'":"STAFF_EXCEPTIONS WHERE USER_ID='".User('STAFF_ID')."'")." AND MODNAME='Students/Student.php&category_id='||sfc.ID)='Y' AND cf.CATEGORY_ID=sfc.ID AND NOT exists(SELECT '' FROM PROGRAM_USER_CONFIG WHERE PROGRAM='StudentFieldsSearch' AND TITLE=cast(cf.ID AS TEXT) AND USER_ID='".User('STAFF_ID')."' AND VALUE='Y') ORDER BY sfc.SORT_ORDER,sfc.TITLE,cf.SORT_ORDER,cf.TITLE"),array(),array('ID','TYPE')),array('CATEGORY_TITLE','TITLE'));
$categories_RET = ParseMLArray(DBGet(DBQuery("SELECT sfc.ID,sfc.TITLE AS CATEGORY_TITLE,'CUSTOM_'||cf.ID AS COLUMN_NAME,cf.TYPE,cf.TITLE,SELECT_OPTIONS
FROM STUDENT_FIELD_CATEGORIES sfc,CUSTOM_FIELDS cf
WHERE (SELECT CAN_USE FROM ".(User('PROFILE_ID')?"PROFILE_EXCEPTIONS WHERE PROFILE_ID='".User('PROFILE_ID')."'":"STAFF_EXCEPTIONS WHERE USER_ID='".User('STAFF_ID')."'")." AND MODNAME='Students/Student.php&category_id='||sfc.ID)='Y'
AND cf.CATEGORY_ID=sfc.ID
AND NOT exists(SELECT '' FROM PROGRAM_USER_CONFIG WHERE PROGRAM='StudentFieldsSearch' AND TITLE=cast(cf.ID AS TEXT) AND USER_ID='".User('STAFF_ID')."' AND VALUE='Y')
ORDER BY sfc.SORT_ORDER,sfc.TITLE,cf.SORT_ORDER,cf.TITLE"),array(),array('ID','TYPE')),array('CATEGORY_TITLE','TITLE'));
else
$categories_RET = ParseMLArray(DBGet(DBQuery("SELECT '0' AS ID,'' AS CATEGORY_TITLE,'CUSTOM_'||cf.ID AS COLUMN_NAME,cf.TYPE,cf.TITLE,cf.SELECT_OPTIONS FROM CUSTOM_FIELDS cf WHERE (SELECT CAN_USE FROM ".(User('PROFILE_ID')?"PROFILE_EXCEPTIONS WHERE PROFILE_ID='".User('PROFILE_ID')."'":"STAFF_EXCEPTIONS WHERE USER_ID='".User('STAFF_ID')."'")." AND MODNAME='Students/Student.php&category_id='||cf.CATEGORY_ID)='Y' AND ((SELECT VALUE FROM PROGRAM_USER_CONFIG WHERE TITLE=cast(cf.ID AS TEXT) AND PROGRAM='StudentFieldsSearch' AND USER_ID='".User('STAFF_ID')."')='Y') ORDER BY cf.SORT_ORDER,cf.TITLE"),array(),array('ID','TYPE')),array('CATEGORY_TITLE','TITLE'));
$categories_RET = ParseMLArray(DBGet(DBQuery("SELECT '0' AS ID,'' AS CATEGORY_TITLE,'CUSTOM_'||cf.ID AS COLUMN_NAME,cf.TYPE,cf.TITLE,cf.SELECT_OPTIONS
FROM CUSTOM_FIELDS cf
WHERE (SELECT CAN_USE FROM ".(User('PROFILE_ID')?"PROFILE_EXCEPTIONS WHERE PROFILE_ID='".User('PROFILE_ID')."'":"STAFF_EXCEPTIONS WHERE USER_ID='".User('STAFF_ID')."'")." AND MODNAME='Students/Student.php&category_id='||cf.CATEGORY_ID)='Y'
AND ((SELECT VALUE FROM PROGRAM_USER_CONFIG WHERE TITLE=cast(cf.ID AS TEXT) AND PROGRAM='StudentFieldsSearch' AND USER_ID='".User('STAFF_ID')."')='Y')
ORDER BY cf.SORT_ORDER,cf.TITLE"),array(),array('ID','TYPE')),array('CATEGORY_TITLE','TITLE'));
foreach($categories_RET as $search_fields_RET)
{
......@@ -209,7 +230,11 @@ function Search($type,$extra=null)
echo '<OPTION value="---">-'. _('Edit') .'-</OPTION>';
$options['---'] = true;
// add values found in current and previous year
$options_RET = DBGet(DBQuery("SELECT DISTINCT s.$column[COLUMN_NAME],upper(s.$column[COLUMN_NAME]) AS KEY FROM STUDENTS s,STUDENT_ENROLLMENT sse WHERE sse.STUDENT_ID=s.STUDENT_ID AND (sse.SYEAR='".UserSyear()."' OR sse.SYEAR='".(UserSyear()-1)."') AND $column[COLUMN_NAME] IS NOT NULL ORDER BY KEY"));
$options_RET = DBGet(DBQuery("SELECT DISTINCT s.".$column['COLUMN_NAME'].",upper(s.".$column['COLUMN_NAME'].") AS KEY
FROM STUDENTS s,STUDENT_ENROLLMENT sse
WHERE sse.STUDENT_ID=s.STUDENT_ID
AND (sse.SYEAR='".UserSyear()."' OR sse.SYEAR='".(UserSyear()-1)."')
AND ".$column['COLUMN_NAME']." IS NOT NULL ORDER BY KEY"));
foreach($options_RET as $option)
if($option[$column['COLUMN_NAME']]!='' && !$options[$option[$column['COLUMN_NAME']]])
{
......
......@@ -10,12 +10,20 @@ function User($item)
{
if(!empty($_SESSION['STAFF_ID']))
{
$sql = "SELECT STAFF_ID,USERNAME,FIRST_NAME||' '||LAST_NAME AS NAME,PROFILE,PROFILE_ID,SCHOOLS,CURRENT_SCHOOL_ID,EMAIL,SYEAR,LAST_LOGIN FROM STAFF WHERE SYEAR='".$_SESSION['UserSyear']."' AND USERNAME=(SELECT USERNAME FROM STAFF WHERE SYEAR='".Config('SYEAR')."' AND STAFF_ID='".$_SESSION['STAFF_ID']."')";
$sql = "SELECT STAFF_ID,USERNAME,FIRST_NAME||' '||LAST_NAME AS NAME,PROFILE,PROFILE_ID,SCHOOLS,CURRENT_SCHOOL_ID,EMAIL,SYEAR,LAST_LOGIN
FROM STAFF
WHERE SYEAR='".$_SESSION['UserSyear']."'
AND USERNAME=(SELECT USERNAME FROM STAFF WHERE SYEAR='".Config('SYEAR')."' AND STAFF_ID='".$_SESSION['STAFF_ID']."')";
$_ROSARIO['User'] = DBGet(DBQuery($sql));
}
elseif(!empty($_SESSION['STUDENT_ID']))
{
$sql = "SELECT '0' AS STAFF_ID,s.USERNAME,s.FIRST_NAME||' '||s.LAST_NAME AS NAME,'student' AS PROFILE,'0' AS PROFILE_ID,','||se.SCHOOL_ID||',' AS SCHOOLS,se.SYEAR,se.SCHOOL_ID FROM STUDENTS s,STUDENT_ENROLLMENT se WHERE s.STUDENT_ID='".$_SESSION['STUDENT_ID']."' AND se.SYEAR='".$_SESSION['UserSyear']."' AND se.STUDENT_ID=s.STUDENT_ID ORDER BY se.END_DATE DESC LIMIT 1";
$sql = "SELECT '0' AS STAFF_ID,s.USERNAME,s.FIRST_NAME||' '||s.LAST_NAME AS NAME,'student' AS PROFILE,'0' AS PROFILE_ID,','||se.SCHOOL_ID||',' AS SCHOOLS,se.SYEAR,se.SCHOOL_ID
FROM STUDENTS s,STUDENT_ENROLLMENT se
WHERE s.STUDENT_ID='".$_SESSION['STUDENT_ID']."'
AND se.SYEAR='".$_SESSION['UserSyear']."'
AND se.STUDENT_ID=s.STUDENT_ID
ORDER BY se.END_DATE DESC LIMIT 1";
$_ROSARIO['User'] = DBGet(DBQuery($sql));
$_SESSION['UserSchool'] = $_ROSARIO['User'][1]['SCHOOL_ID'];
}
......
......@@ -289,7 +289,13 @@ function Widgets($item,&$myextra=null)
//modif Francois: fix error Invalid argument supplied for foreach()
if($_REQUEST['search_modfunc']=='search_fnc' || !$_REQUEST['search_modfunc'])
{
$letter_grades_RET = DBGet(DBQuery("SELECT rg.ID,rg.TITLE,rg.GRADE_SCALE_ID FROM REPORT_CARD_GRADES rg,REPORT_CARD_GRADE_SCALES rs WHERE rg.SCHOOL_ID='".UserSchool()."' AND rg.SYEAR='".UserSyear()."' AND rs.ID=rg.GRADE_SCALE_ID".(User('PROFILE')=='teacher'?' AND rg.GRADE_SCALE_ID=(SELECT GRADE_SCALE_ID FROM COURSE_PERIODS WHERE COURSE_PERIOD_ID=\''.UserCoursePeriod().'\')':'')." ORDER BY rs.SORT_ORDER,rs.ID,rg.BREAK_OFF IS NOT NULL DESC,rg.BREAK_OFF DESC,rg.SORT_ORDER"),array(),array('GRADE_SCALE_ID'));
$letter_grades_RET = DBGet(DBQuery("SELECT rg.ID,rg.TITLE,rg.GRADE_SCALE_ID
FROM REPORT_CARD_GRADES rg,REPORT_CARD_GRADE_SCALES rs
WHERE rg.SCHOOL_ID='".UserSchool()."'
AND rg.SYEAR='".UserSyear()."'
AND rs.ID=rg.GRADE_SCALE_ID".(User('PROFILE')=='teacher'?'
AND rg.GRADE_SCALE_ID=(SELECT GRADE_SCALE_ID FROM COURSE_PERIODS WHERE COURSE_PERIOD_ID=\''.UserCoursePeriod().'\')':'')."
ORDER BY rs.SORT_ORDER,rs.ID,rg.BREAK_OFF IS NOT NULL DESC,rg.BREAK_OFF DESC,rg.SORT_ORDER"),array(),array('GRADE_SCALE_ID'));
foreach($letter_grades_RET as $grades)
{
$i = 0;
......@@ -456,7 +462,12 @@ function Widgets($item,&$myextra=null)
$extra['WHERE'] .= ' AND dr.STUDENT_ID=ssm.STUDENT_ID AND dr.SYEAR=ssm.SYEAR AND dr.SCHOOL_ID=ssm.SCHOOL_ID ';
$extra['FROM'] .= ',DISCIPLINE_REFERRALS dr ';
}
$users_RET = DBGet(DBQuery("SELECT STAFF_ID,FIRST_NAME,LAST_NAME,MIDDLE_NAME FROM STAFF WHERE SYEAR='".UserSyear()."' AND (SCHOOLS IS NULL OR SCHOOLS LIKE '%,".UserSchool().",%') AND (PROFILE='admin' OR PROFILE='teacher') ORDER BY LAST_NAME,FIRST_NAME,MIDDLE_NAME"),array(),array('STAFF_ID'));
$users_RET = DBGet(DBQuery("SELECT STAFF_ID,FIRST_NAME,LAST_NAME,MIDDLE_NAME
FROM STAFF
WHERE SYEAR='".UserSyear()."'
AND (SCHOOLS IS NULL OR SCHOOLS LIKE '%,".UserSchool().",%')
AND (PROFILE='admin' OR PROFILE='teacher')
ORDER BY LAST_NAME,FIRST_NAME,MIDDLE_NAME"),array(),array('STAFF_ID'));
if($_REQUEST['discipline_reporter'])
{
$extra['WHERE'] .= " AND dr.STAFF_ID='".$_REQUEST['discipline_reporter']."' ";
......
......@@ -25,19 +25,25 @@ elseif($_REQUEST['modfunc']=='create_account')
if($_REQUEST['USERNAME'] && $_REQUEST['PASSWORD'])
{
$_REQUEST['USERNAME'] = DBEscapeString($_REQUEST['USERNAME']);
//$_REQUEST['PASSWORD'] = DBEscapeString($_REQUEST['PASSWORD']);
//modif Francois: add password encryption
// $login_RET = DBGet(DBQuery("SELECT USERNAME,PROFILE,STAFF_ID,LAST_LOGIN,FAILED_LOGIN FROM STAFF WHERE SYEAR='".$DefaultSyear."' AND UPPER(USERNAME)=UPPER('".$_REQUEST['USERNAME']."') AND UPPER(PASSWORD)=UPPER('".$_REQUEST['PASSWORD']."')"));
//modif Francois: add WHERE PROFILE<>'admin' to restrict admin login to $RosarioAdmins list
$login_RET = DBGet(DBQuery("SELECT USERNAME,PROFILE,STAFF_ID,LAST_LOGIN,FAILED_LOGIN,PASSWORD FROM STAFF WHERE PROFILE<>'admin' AND SYEAR='".Config('SYEAR')."' AND UPPER(USERNAME)=UPPER('".$_REQUEST['USERNAME']."')"));
$login_RET = DBGet(DBQuery("SELECT USERNAME,PROFILE,STAFF_ID,LAST_LOGIN,FAILED_LOGIN,PASSWORD
FROM STAFF
WHERE PROFILE<>'admin'
AND SYEAR='".Config('SYEAR')."'
AND UPPER(USERNAME)=UPPER('".$_REQUEST['USERNAME']."')"));
if ($login_RET && match_password($login_RET[1]['PASSWORD'], $_REQUEST['PASSWORD']))
$_REQUEST['PASSWORD'] = '';
else
$login_RET = false;
if(!$login_RET)
{
// $student_RET = DBGet(DBQuery("SELECT s.USERNAME,s.STUDENT_ID,s.LAST_LOGIN,s.FAILED_LOGIN FROM STUDENTS s,STUDENT_ENROLLMENT se WHERE UPPER(s.USERNAME)=UPPER('".$_REQUEST['USERNAME']."') AND UPPER(s.PASSWORD)=UPPER('".$_REQUEST['PASSWORD']."') AND se.STUDENT_ID=s.STUDENT_ID AND se.SYEAR='".$DefaultSyear."' AND CURRENT_DATE>=se.START_DATE AND (CURRENT_DATE<=se.END_DATE OR se.END_DATE IS NULL)"));
$student_RET = DBGet(DBQuery("SELECT s.USERNAME,s.STUDENT_ID,s.LAST_LOGIN,s.FAILED_LOGIN,s.PASSWORD FROM STUDENTS s,STUDENT_ENROLLMENT se WHERE UPPER(s.USERNAME)=UPPER('".$_REQUEST['USERNAME']."') AND se.STUDENT_ID=s.STUDENT_ID AND se.SYEAR='".Config('SYEAR')."' AND CURRENT_DATE>=se.START_DATE AND (CURRENT_DATE<=se.END_DATE OR se.END_DATE IS NULL)"));
$student_RET = DBGet(DBQuery("SELECT s.USERNAME,s.STUDENT_ID,s.LAST_LOGIN,s.FAILED_LOGIN,s.PASSWORD
FROM STUDENTS s,STUDENT_ENROLLMENT se
WHERE UPPER(s.USERNAME)=UPPER('".$_REQUEST['USERNAME']."')
AND se.STUDENT_ID=s.STUDENT_ID
AND se.SYEAR='".Config('SYEAR')."'
AND CURRENT_DATE>=se.START_DATE
AND (CURRENT_DATE<=se.END_DATE OR se.END_DATE IS NULL)"));
if ($student_RET && match_password($student_RET[1]['PASSWORD'], $_REQUEST['PASSWORD']))
$_REQUEST['PASSWORD'] = '';
else
......@@ -45,8 +51,12 @@ if($_REQUEST['USERNAME'] && $_REQUEST['PASSWORD'])
}
if(!$login_RET && !$student_RET && $RosarioAdmins)
{
// $admin_RET = DBGet(DBQuery("SELECT STAFF_ID FROM STAFF WHERE PROFILE='admin' AND SYEAR='".$DefaultSyear."' AND STAFF_ID IN ($RosarioAdmins) AND UPPER(PASSWORD)=UPPER('".$_REQUEST['PASSWORD']."')"));
$admin_RET = DBGet(DBQuery("SELECT STAFF_ID,PASSWORD FROM STAFF WHERE PROFILE='admin' AND SYEAR='".Config('SYEAR')."' AND STAFF_ID IN ($RosarioAdmins) AND UPPER(USERNAME)=UPPER('".$_REQUEST['USERNAME']."')"));
$admin_RET = DBGet(DBQuery("SELECT STAFF_ID,PASSWORD
FROM STAFF WHERE
PROFILE='admin'
AND SYEAR='".Config('SYEAR')."'
AND STAFF_ID IN (".$RosarioAdmins.")
AND UPPER(USERNAME)=UPPER('".$_REQUEST['USERNAME']."')"));
if ($admin_RET && match_password($admin_RET[1]['PASSWORD'], $_REQUEST['PASSWORD']))
{
$_REQUEST['PASSWORD'] = '';
......
......@@ -45,9 +45,20 @@ if(!isset($_REQUEST['accounting']) || $_REQUEST['accounting']=='true')
if(isset($_REQUEST['staff_payroll']) || isset($_REQUEST['student_billing']))
$name_col_sql = "'' AS FULL_NAME,";
$RET = DBGet(DBQuery("SELECT ".$name_col_sql."f.AMOUNT AS CREDIT,'' AS DEBIT,f.TITLE||' '||COALESCE(f.COMMENTS,' ') AS EXPLANATION,f.ASSIGNED_DATE AS DATE,f.ID AS ID FROM ACCOUNTING_INCOMES f WHERE f.SYEAR='".UserSyear()."' AND f.SCHOOL_ID='".UserSchool()."' AND f.ASSIGNED_DATE BETWEEN '".$start_date."' AND '".$end_date."'"),$extra['functions']);
$payments_SQL = "SELECT ".$name_col_sql."'' AS CREDIT,p.AMOUNT AS DEBIT,COALESCE(p.COMMENTS,' ') AS EXPLANATION,p.PAYMENT_DATE AS DATE,p.ID AS ID FROM ACCOUNTING_PAYMENTS p WHERE p.SYEAR='".UserSyear()."' AND p.SCHOOL_ID='".UserSchool()."' AND p.PAYMENT_DATE BETWEEN '".$start_date."' AND '".$end_date."' AND STAFF_ID IS NULL";
$RET = DBGet(DBQuery("SELECT ".$name_col_sql."f.AMOUNT AS CREDIT,'' AS DEBIT,f.TITLE||' '||COALESCE(f.COMMENTS,' ') AS EXPLANATION,f.ASSIGNED_DATE AS DATE,f.ID AS ID
FROM ACCOUNTING_INCOMES f
WHERE f.SYEAR='".UserSyear()."'
AND f.SCHOOL_ID='".UserSchool()."'
AND f.ASSIGNED_DATE BETWEEN '".$start_date."'
AND '".$end_date."'"),$extra['functions']);
$payments_SQL = "SELECT ".$name_col_sql."'' AS CREDIT,p.AMOUNT AS DEBIT,COALESCE(p.COMMENTS,' ') AS EXPLANATION,p.PAYMENT_DATE AS DATE,p.ID AS ID
FROM ACCOUNTING_PAYMENTS p
WHERE p.SYEAR='".UserSyear()."'
AND p.SCHOOL_ID='".UserSchool()."'
AND p.PAYMENT_DATE BETWEEN '".$start_date."'
AND '".$end_date."'
AND STAFF_ID IS NULL";
$payments_RET = DBGet(DBQuery($payments_SQL),$extra['functions']);
......
......@@ -20,7 +20,12 @@ if(isset($_REQUEST['modfunc']) && $_REQUEST['modfunc']=='save')
$students_list .= ",'".$student_id."'";
$students_list = '('.mb_substr($students_list,1).')';
$current_RET = DBGet(DBQuery("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'));
$current_RET = DBGet(DBQuery("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'));
$state_code = DBGet(DBQuery("SELECT STATE_CODE FROM ATTENDANCE_CODES WHERE ID='".$_REQUEST['absence_code']."'"));
$state_code = $state_code[1]['STATE_CODE'];
foreach($_REQUEST['student'] as $student_id=>$yes)
......@@ -33,7 +38,27 @@ if(isset($_REQUEST['modfunc']) && $_REQUEST['modfunc']=='save')
//modif Francois: multiple school periods for a course period
if (SchoolInfo('NUMBER_DAYS_ROTATION') !== null)
{
$course_periods_RET = DBGet(DBQuery("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 AND ac.SCHOOL_DATE='".$date."' AND ac.CALENDAR_ID=cp.CALENDAR_ID AND (ac.BLOCK=sp.BLOCK OR sp.BLOCK IS NULL) AND s.COURSE_PERIOD_ID=cp.COURSE_PERIOD_ID AND s.STUDENT_ID='".$student_id."' 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('MTWHFSU' FROM cast((SELECT CASE COUNT(school_date)% ".SchoolInfo('NUMBER_DAYS_ROTATION')." WHEN 0 THEN ".SchoolInfo('NUMBER_DAYS_ROTATION')." ELSE COUNT(school_date)% ".SchoolInfo('NUMBER_DAYS_ROTATION')." END AS day_number FROM attendance_calendar WHERE school_date>=(SELECT start_date FROM school_marking_periods WHERE start_date<=ac.SCHOOL_DATE AND end_date>=ac.SCHOOL_DATE AND mp='QTR' AND SCHOOL_ID=ac.SCHOOL_ID) AND school_date<=ac.SCHOOL_DATE 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'));
$course_periods_RET = DBGet(DBQuery("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
AND ac.SCHOOL_DATE='".$date."'
AND ac.CALENDAR_ID=cp.CALENDAR_ID
AND (ac.BLOCK=sp.BLOCK OR sp.BLOCK IS NULL)
AND s.COURSE_PERIOD_ID=cp.COURSE_PERIOD_ID
AND s.STUDENT_ID='".$student_id."'
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('MTWHFSU' FROM cast(
(SELECT CASE COUNT(school_date)% ".SchoolInfo('NUMBER_DAYS_ROTATION')." WHEN 0 THEN ".SchoolInfo('NUMBER_DAYS_ROTATION')." ELSE COUNT(school_date)% ".SchoolInfo('NUMBER_DAYS_ROTATION')." END AS day_number
FROM attendance_calendar
WHERE school_date>=(SELECT start_date FROM school_marking_periods WHERE start_date<=ac.SCHOOL_DATE AND end_date>=ac.SCHOOL_DATE AND mp='QTR' AND SCHOOL_ID=ac.SCHOOL_ID)
AND school_date<=ac.SCHOOL_DATE
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'));
} else {
$course_periods_RET = DBGet(DBQuery("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."' AND ac.CALENDAR_ID=cp.CALENDAR_ID AND (ac.BLOCK=sp.BLOCK OR sp.BLOCK IS NULL) AND s.COURSE_PERIOD_ID=cp.COURSE_PERIOD_ID AND s.STUDENT_ID='".$student_id."' 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'));
}
......@@ -92,11 +117,15 @@ if(empty($_REQUEST['modfunc']))
//modif Francois: css WPadmin
echo '<TABLE class="postbox cellpadding-4" style="margin:0 auto;"><TR><TD style="text-align:right">'._('Add Absence to Periods').'</TD>';
echo '<TD><TABLE><TR>';
//$periods_RET = DBGet(DBQuery("SELECT SHORT_NAME,PERIOD_ID FROM SCHOOL_PERIODS WHERE SYEAR='".UserSyear()."' AND SCHOOL_ID='".UserSchool()."' ORDER BY SORT_ORDER"));
//modif Francois: 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 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"));
$periods_RET = DBGet(DBQuery("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"));
foreach($periods_RET as $period)
//modif Francois: add <label> on checkbox
echo '<TD><label><INPUT type="CHECKBOX" value="Y" name="period['.$period['PERIOD_ID'].']"> '.$period['SHORT_NAME'].'</label></TD>';
......
......@@ -52,9 +52,37 @@ $current_Q = "SELECT ATTENDANCE_TEACHER_CODE,ATTENDANCE_CODE,ATTENDANCE_REASON,C
//modif Francois: multiple school periods for a course period
if (SchoolInfo('NUMBER_DAYS_ROTATION') !== null)
{
$current_schedule_Q = "SELECT cpsp.PERIOD_ID,cp.COURSE_PERIOD_ID,cp.HALF_DAY FROM SCHEDULE s,COURSE_PERIODS cp, COURSE_PERIOD_SCHOOL_PERIODS cpsp WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID AND s.STUDENT_ID='__student_id__' AND s.SYEAR='".UserSyear()."' AND s.SCHOOL_ID='".UserSchool()."' AND cp.COURSE_PERIOD_ID = s.COURSE_PERIOD_ID AND position(',$_REQUEST[table],' IN cp.DOES_ATTENDANCE)>0 AND ('".$date."' BETWEEN s.START_DATE AND s.END_DATE OR (s.END_DATE IS NULL AND '".$date."'>=s.START_DATE)) AND position(substring('MTWHFSU' FROM cast((SELECT CASE COUNT(school_date)% ".SchoolInfo('NUMBER_DAYS_ROTATION')." WHEN 0 THEN ".SchoolInfo('NUMBER_DAYS_ROTATION')." ELSE COUNT(school_date)% ".SchoolInfo('NUMBER_DAYS_ROTATION')." END AS day_number FROM attendance_calendar WHERE school_date>=(SELECT start_date FROM school_marking_periods WHERE start_date<='".$date."' AND end_date>='".$date."' AND mp='QTR' AND SCHOOL_ID=s.SCHOOL_ID) AND school_date<='".$date."' AND SCHOOL_ID=s.SCHOOL_ID) AS INT) FOR 1) IN cpsp.DAYS)>0 AND s.MARKING_PERIOD_ID IN ($all_mp) ORDER BY s.START_DATE ASC";
$current_schedule_Q = "SELECT cpsp.PERIOD_ID,cp.COURSE_PERIOD_ID,cp.HALF_DAY
FROM SCHEDULE s,COURSE_PERIODS cp, COURSE_PERIOD_SCHOOL_PERIODS cpsp
WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID
AND s.STUDENT_ID='__student_id__'
AND s.SYEAR='".UserSyear()."'
AND s.SCHOOL_ID='".UserSchool()."'
AND cp.COURSE_PERIOD_ID = s.COURSE_PERIOD_ID
AND position(',".$_REQUEST['table'].",' IN cp.DOES_ATTENDANCE)>0
AND ('".$date."' BETWEEN s.START_DATE AND s.END_DATE OR (s.END_DATE IS NULL AND '".$date."'>=s.START_DATE))
AND position(substring('MTWHFSU' FROM cast(
(SELECT CASE COUNT(school_date)% ".SchoolInfo('NUMBER_DAYS_ROTATION')." WHEN 0 THEN ".SchoolInfo('NUMBER_DAYS_ROTATION')." ELSE COUNT(school_date)% ".SchoolInfo('NUMBER_DAYS_ROTATION')." END AS day_number
FROM attendance_calendar
WHERE school_date>=(SELECT start_date FROM school_marking_periods WHERE start_date<='".$date."' AND end_date>='".$date."' AND mp='QTR' AND SCHOOL_ID=s.SCHOOL_ID)
AND school_date<='".$date."'
AND SCHOOL_ID=s.SCHOOL_ID)
AS INT) FOR 1) IN cpsp.DAYS)>0
AND s.MARKING_PERIOD_ID IN (".$all_mp.")
ORDER BY s.START_DATE ASC";
} else {
$current_schedule_Q = "SELECT cpsp.PERIOD_ID,cp.COURSE_PERIOD_ID,cp.HALF_DAY FROM SCHEDULE s,COURSE_PERIODS cp, COURSE_PERIOD_SCHOOL_PERIODS cpsp WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID AND s.STUDENT_ID='__student_id__' AND s.SYEAR='".UserSyear()."' AND s.SCHOOL_ID='".UserSchool()."' AND cp.COURSE_PERIOD_ID = s.COURSE_PERIOD_ID AND position(',$_REQUEST[table],' IN cp.DOES_ATTENDANCE)>0 AND ('".$date."' BETWEEN s.START_DATE AND s.END_DATE OR (s.END_DATE IS NULL AND '".$date."'>=s.START_DATE)) AND position(substring('UMTWHFS' FROM cast(extract(DOW FROM cast('".$date."' AS DATE)) AS INT)+1 FOR 1) IN cpsp.DAYS)>0 AND s.MARKING_PERIOD_ID IN ($all_mp) ORDER BY s.START_DATE ASC";
$current_schedule_Q = "SELECT cpsp.PERIOD_ID,cp.COURSE_PERIOD_ID,cp.HALF_DAY
FROM SCHEDULE s,COURSE_PERIODS cp, COURSE_PERIOD_SCHOOL_PERIODS cpsp
WHERE cp.COURSE_PERIOD_ID=cpsp.COURSE_PERIOD_ID
AND s.STUDENT_ID='__student_id__'
AND s.SYEAR='".UserSyear()."'
AND s.SCHOOL_ID='".UserSchool()."'
AND cp.COURSE_PERIOD_ID = s.COURSE_PERIOD_ID
AND position(',".$_REQUEST['table'].",' IN cp.DOES_ATTENDANCE)>0
AND ('".$date."' BETWEEN s.START_DATE AND s.END_DATE OR (s.END_DATE IS NULL AND '".$date."'>=s.START_DATE))
AND position(substring('UMTWHFS' FROM cast(extract(DOW FROM cast('".$date."' AS DATE)) AS INT)+1 FOR 1) IN cpsp.DAYS)>0
AND s.MARKING_PERIOD_ID IN (".$all_mp.")
ORDER BY s.START_DATE ASC";
}
$current_RET = DBGet(DBQuery($current_Q),array(),array('STUDENT_ID','PERIOD_ID'));
if($_REQUEST['attendance'] && $_POST['attendance'] && AllowEdit())
......@@ -124,7 +152,12 @@ if(count($_REQUEST['attendance_day']))
}
$codes_RET = DBGet(DBQuery("SELECT ID,SHORT_NAME,TITLE,STATE_CODE FROM ATTENDANCE_CODES WHERE SCHOOL_ID='".UserSchool()."' AND SYEAR='".UserSyear()."' AND TABLE_NAME='".$_REQUEST['table']."'"));
$periods_RET = DBGet(DBQuery("SELECT PERIOD_ID,SHORT_NAME,TITLE FROM SCHOOL_PERIODS WHERE SCHOOL_ID='".UserSchool()."' AND SYEAR='".UserSyear()."' AND EXISTS (SELECT '' FROM COURSE_PERIODS WHERE PERIOD_ID=SCHOOL_PERIODS.PERIOD_ID AND position(',$_REQUEST[table],' IN DOES_ATTENDANCE)>0) ORDER BY SORT_ORDER"));
$periods_RET = DBGet(DBQuery("SELECT PERIOD_ID,SHORT_NAME,TITLE
FROM SCHOOL_PERIODS
WHERE SCHOOL_ID='".UserSchool()."'
AND SYEAR='".UserSyear()."'
AND EXISTS (SELECT '' FROM COURSE_PERIODS WHERE PERIOD_ID=SCHOOL_PERIODS.PERIOD_ID AND position(',".$_REQUEST['table'].",' IN DOES_ATTENDANCE)>0)
ORDER BY SORT_ORDER"));
$categories_RET = DBGet(DBQuery("SELECT ID,TITLE FROM ATTENDANCE_CODE_CATEGORIES WHERE SYEAR='".UserSyear()."' AND SCHOOL_ID='".UserSchool()."'"));
if(count($categories_RET))
......
......@@ -167,7 +167,15 @@ function _makeCodePulldown($value,$title)
if(!is_array($current_schedule_RET[$THIS_RET['STUDENT_ID']]))
{
$current_schedule_RET[$THIS_RET['STUDENT_ID']] = DBGet(DBQuery("SELECT cp.PERIOD_ID,cp.COURSE_PERIOD_ID FROM SCHEDULE s,COURSE_PERIODS cp WHERE s.STUDENT_ID='".$THIS_RET['STUDENT_ID']."' AND s.SYEAR='".UserSyear()."' AND s.SCHOOL_ID='".UserSchool()."' AND cp.COURSE_PERIOD_ID = s.COURSE_PERIOD_ID AND cp.DOES_ATTENDANCE='Y' AND s.MARKING_PERIOD_ID IN (".GetAllMP('QTR',GetCurrentMP('QTR',$date)).") AND ('".$date."' BETWEEN s.START_DATE AND s.END_DATE OR s.END_DATE IS NULL)"),array(),array('PERIOD_ID'));
$current_schedule_RET[$THIS_RET['STUDENT_ID']] = DBGet(DBQuery("SELECT cp.PERIOD_ID,cp.COURSE_PERIOD_ID
FROM SCHEDULE s,COURSE_PERIODS cp
WHERE s.STUDENT_ID='".$THIS_RET['STUDENT_ID']."'
AND s.SYEAR='".UserSyear()."'
AND s.SCHOOL_ID='".UserSchool()."'
AND cp.COURSE_PERIOD_ID = s.COURSE_PERIOD_ID
AND cp.DOES_ATTENDANCE='Y'
AND s.MARKING_PERIOD_ID IN (".GetAllMP('QTR',GetCurrentMP('QTR',$date)).")
AND ('".$date."' BETWEEN s.START_DATE AND s.END_DATE OR s.END_DATE IS NULL)"),array(),array('PERIOD_ID'));
if(!$current_schedule_RET[$THIS_RET['STUDENT_ID']])
$current_schedule_RET[$THIS_RET['STUDENT_ID']] = array();
}
......
......@@ -50,7 +50,12 @@ if($_REQUEST['search_modfunc'] || $_REQUEST['student_id'] || User('PROFILE')=='p
{
//modif Francois: 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 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"));
$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 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"));
foreach($periods_RET as $period)
$period_select .= '<OPTION value="'.$period['PERIOD_ID'].'"'.(($_REQUEST['period_id']==$period['PERIOD_ID'])?' SELECTED="SELECTED"':'').'>'.$period['TITLE'].'</OPTION>';
}
......@@ -58,7 +63,12 @@ if($_REQUEST['search_modfunc'] || $_REQUEST['student_id'] || User('PROFILE')=='p
{
//modif Francois: 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 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()."'"));
$periods_RET = DBGet(DBQuery("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()."'"));
if($periods_RET)
{
//$period_select .= '<OPTION value="'.$periods_RET[1]['PERIOD_ID'].'"'.(($_REQUEST['period_id']==$periods_RET[1]['PERIOD_ID'] || !isset($_REQUEST['period_id']))?' SELECTED="SELECTED"':'').">".$periods_RET[1]['TITLE'].'</OPTION>';
......@@ -157,11 +167,23 @@ else
// in 2.11 this was switched to incremental query in the _makeColor function
if(!$_REQUEST['period_id'])
{
$att_sql = "SELECT ad.STATE_VALUE,SCHOOL_DATE,'_'||to_char(ad.SCHOOL_DATE,'yyyymmdd') AS SHORT_DATE FROM ATTENDANCE_DAY ad,STUDENT_ENROLLMENT ssm WHERE ad.STUDENT_ID=ssm.STUDENT_ID AND (('".DBDate()."' BETWEEN ssm.START_DATE AND ssm.END_DATE OR ssm.END_DATE IS NULL) AND '".DBDate()."'>=ssm.START_DATE) AND ssm.SCHOOL_ID='".UserSchool()."' AND ad.SCHOOL_DATE BETWEEN '".$start_date."' AND '".$end_date."' AND ad.STUDENT_ID=";
$att_sql = "SELECT ad.STATE_VALUE,SCHOOL_DATE,'_'||to_char(ad.SCHOOL_DATE,'yyyymmdd') AS SHORT_DATE
FROM ATTENDANCE_DAY ad,STUDENT_ENROLLMENT ssm
WHERE ad.STUDENT_ID=ssm.STUDENT_ID
AND (('".DBDate()."' BETWEEN ssm.START_DATE AND ssm.END_DATE OR ssm.END_DATE IS NULL) AND '".DBDate()."'>=ssm.START_DATE)
AND ssm.SCHOOL_ID='".UserSchool()."'
AND ad.SCHOOL_DATE BETWEEN '".$start_date."'
AND '".$end_date."'
AND ad.STUDENT_ID=";
}
else
{
$att_sql = "SELECT ap.ATTENDANCE_CODE,ap.SCHOOL_DATE,'_'||to_char(ap.SCHOOL_DATE,'yyyymmdd') AS SHORT_DATE FROM ATTENDANCE_PERIOD ap,STUDENT_ENROLLMENT ssm WHERE ap.STUDENT_ID=ssm.STUDENT_ID AND ap.SCHOOL_DATE BETWEEN '".$start_date."' AND '".$end_date."' AND ap.STUDENT_ID=";
$att_sql = "SELECT ap.ATTENDANCE_CODE,ap.SCHOOL_DATE,'_'||to_char(ap.SCHOOL_DATE,'yyyymmdd') AS SHORT_DATE
FROM ATTENDANCE_PERIOD ap,STUDENT_ENROLLMENT ssm
WHERE ap.STUDENT_ID=ssm.STUDENT_ID
AND ap.SCHOOL_DATE BETWEEN '".$start_date."'
AND '".$end_date."'
AND ap.STUDENT_ID=";
}
if(count($cal_RET))
......
......@@ -109,10 +109,31 @@ if(empty($_REQUEST['modfunc']))
{
$cal_days = 1;
$student_days_absent = DBGet(DBQuery("SELECT ad.SCHOOL_DATE,ssm.GRADE_ID,COALESCE(sum(ad.STATE_VALUE-1)*-1,0) AS STATE_VALUE FROM ATTENDANCE_DAY ad,STUDENT_ENROLLMENT ssm,STUDENTS s".$extra['FROM']." WHERE s.STUDENT_ID=ssm.STUDENT_ID AND ad.STUDENT_ID=ssm.STUDENT_ID AND ssm.SYEAR='".UserSyear()."' AND ad.SYEAR=ssm.SYEAR AND ad.SCHOOL_DATE BETWEEN '".$start_date."' AND '".$end_date."' AND (ad.SCHOOL_DATE BETWEEN ssm.START_DATE AND ssm.END_DATE OR (ssm.END_DATE IS NULL AND ssm.START_DATE <= ad.SCHOOL_DATE)) ".$extra['WHERE']." GROUP BY ad.SCHOOL_DATE,ssm.GRADE_ID"),array(''),array('SCHOOL_DATE','GRADE_ID'));
$student_days_absent = DBGet(DBQuery("SELECT ad.SCHOOL_DATE,ssm.GRADE_ID,COALESCE(sum(ad.STATE_VALUE-1)*-1,0) AS STATE_VALUE
FROM ATTENDANCE_DAY ad,STUDENT_ENROLLMENT ssm,STUDENTS s".$extra['FROM']."
WHERE s.STUDENT_ID=ssm.STUDENT_ID
AND ad.STUDENT_ID=ssm.STUDENT_ID
AND ssm.SYEAR='".UserSyear()."'
AND ad.SYEAR=ssm.SYEAR
AND ad.SCHOOL_DATE BETWEEN '".$start_date."' AND '".$end_date."'
AND (ad.SCHOOL_DATE BETWEEN ssm.START_DATE AND ssm.END_DATE OR (ssm.END_DATE IS NULL AND ssm.START_DATE <= ad.SCHOOL_DATE))
".$extra['WHERE']."
GROUP BY ad.SCHOOL_DATE,ssm.GRADE_ID"),array(''),array('SCHOOL_DATE','GRADE_ID'));
//modif Francois: ORDER BY Date
// $student_days_possible = DBGet(DBQuery("SELECT ac.SCHOOL_DATE,ssm.GRADE_ID,'' AS DAYS_POSSIBLE,count(*) AS ATTENDANCE_POSSIBLE,count(*) AS STUDENTS,'' AS PRESENT,'' AS ABSENT,'' AS ADA,'' AS AVERAGE_ATTENDANCE,'' AS AVERAGE_ABSENT FROM STUDENT_ENROLLMENT ssm,ATTENDANCE_CALENDAR ac,STUDENTS s".$extra['FROM']." WHERE s.STUDENT_ID=ssm.STUDENT_ID AND ssm.SYEAR='".UserSyear()."' AND ac.SYEAR=ssm.SYEAR AND ssm.SCHOOL_ID='".UserSchool()."' AND ssm.SCHOOL_ID=ac.SCHOOL_ID AND (ac.SCHOOL_DATE BETWEEN ssm.START_DATE AND ssm.END_DATE OR (ssm.END_DATE IS NULL AND ssm.START_DATE <= ac.SCHOOL_DATE)) AND ac.SCHOOL_DATE BETWEEN '".$start_date."' AND '".$end_date."' ".$extra['WHERE']." GROUP BY ac.SCHOOL_DATE,ssm.GRADE_ID"),array('SCHOOL_DATE'=>'ProperDate','GRADE_ID'=>'GetGrade','STUDENTS'=>'_makeByDay','PRESENT'=>'_makeByDay','ABSENT'=>'_makeByDay','ADA'=>'_makeByDay','AVERAGE_ATTENDANCE'=>'_makeByDay','AVERAGE_ABSENT'=>'_makeByDay','DAYS_POSSIBLE'=>'_makeByDay'));
$student_days_possible = DBGet(DBQuery("SELECT ac.SCHOOL_DATE,ssm.GRADE_ID,'' AS DAYS_POSSIBLE,count(*) AS ATTENDANCE_POSSIBLE,count(*) AS STUDENTS,'' AS PRESENT,'' AS ABSENT,'' AS ADA,'' AS AVERAGE_ATTENDANCE,'' AS AVERAGE_ABSENT FROM STUDENT_ENROLLMENT ssm,ATTENDANCE_CALENDAR ac,STUDENTS s".$extra['FROM']." WHERE s.STUDENT_ID=ssm.STUDENT_ID AND ssm.SYEAR='".UserSyear()."' AND ac.SYEAR=ssm.SYEAR AND ssm.SCHOOL_ID='".UserSchool()."' AND ssm.SCHOOL_ID=ac.SCHOOL_ID AND (ac.SCHOOL_DATE BETWEEN ssm.START_DATE AND ssm.END_DATE OR (ssm.END_DATE IS NULL AND ssm.START_DATE <= ac.SCHOOL_DATE)) AND ac.SCHOOL_DATE BETWEEN '".$start_date."' AND '"