';
// @since 4.8 Search Parents by Student Grade Level.
$grade_levels_RET = DBGet( "SELECT ID,TITLE,SHORT_NAME
FROM SCHOOL_GRADELEVELS
WHERE SCHOOL_ID='" . UserSchool() . "'
ORDER BY SORT_ORDER" );
// Do not hide in case first Profile is "Parent".
$maybe_hide = key( $options ) === 'parent' ? '' : ' class="hide"';
echo '
';
// Show Student Grade Level when selected Profile is "Parent".
echo '';
break;
case 'staff_fields':
case 'staff_fields_all':
case 'student_fields':
case 'student_fields_all':
if ( $type === 'staff_fields_all' )
{
$categories_SQL = "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
LIMIT 1)='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')
AND cf.TYPE<>'files'
ORDER BY sfc.SORT_ORDER,sfc.TITLE,cf.SORT_ORDER,cf.TITLE";
}
elseif ( $type === 'staff_fields' )
{
$categories_SQL = "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
LIMIT 1)='Y'
AND (SELECT VALUE
FROM PROGRAM_USER_CONFIG
WHERE TITLE=cast(cf.ID AS TEXT)
AND PROGRAM='StaffFieldsSearch'
AND USER_ID='" . User( 'STAFF_ID' ) . "'
LIMIT 1)='Y'
ORDER BY cf.SORT_ORDER,cf.TITLE";
}
elseif ( $type === 'student_fields_all' )
{
$categories_SQL = "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')
AND cf.TYPE<>'files'
ORDER BY sfc.SORT_ORDER,sfc.TITLE,cf.SORT_ORDER,cf.TITLE";
}
else
{
$categories_SQL = "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";
}
$categories_RET = ParseMLArray(
DBGet(
$categories_SQL,
array(),
array( 'ID', 'TYPE' ) ),
array( 'CATEGORY_TITLE', 'TITLE' )
);
if ( $type === 'student_fields_all' )
{
// Student Fields: search Username.
$general_info_category_title = ParseMLField( DBGetOne( "SELECT sfc.TITLE
FROM STUDENT_FIELD_CATEGORIES sfc
WHERE sfc.ID=1" ) );
$i = empty( $categories_RET[1]['text'] ) ? 1 : count( $categories_RET[1]['text'] );
if ( Preferences( 'USERNAME', 'StudentFieldsSearch' ) !== 'Y' )
{
if ( ! isset( $categories_RET[1] ) )
{
// Empty General Info category.
$categories_RET[1] = array();
}
// Add Username to Staff General Info.
$categories_RET[1]['text'][ $i++ ] = array(
'ID' => '1',
'CATEGORY_TITLE' => $general_info_category_title,
'COLUMN_NAME' => 'USERNAME',
'TYPE' => 'text',
'TITLE' => _( 'Username' ),
'SELECT_OPTIONS' => null,
);
}
}
elseif ( $type === 'student_fields' )
{
$i = isset( $i ) ? $i : 0;
if ( Preferences( 'USERNAME', 'StudentFieldsSearch' ) === 'Y' )
{
// Add USername to Find a User form.
$categories_RET[1]['text'][ $i++ ] = array(
'ID' => '1',
'CATEGORY_TITLE' => '',
'COLUMN_NAME' => 'USERNAME',
'TYPE' => 'text',
'TITLE' => _( 'Username' ),
'SELECT_OPTIONS' => null,
);
}
}
elseif ( $type === 'staff_fields_all' )
{
$i = 1;
}
elseif ( $type === 'staff_fields' )
{
$i = isset( $i ) ? $i : 0;
}
foreach ( (array) $categories_RET as $category )
{
$TR_classes = '';
$category_default = array(
'text' => array(),
'numeric' => array(),
'select' => array(),
'autos' => array(),
'exports' => array(),
'date' => array(),
'radio' => array(),
);
$category = array_replace_recursive( $category_default, (array) $category );
foreach ( $category as $cols )
{
if ( ! empty( $cols[1]['CATEGORY_TITLE'] ) )
{
$category_title = $cols[1]['CATEGORY_TITLE'];
break;
}
}
if ( $type === 'student_fields_all'
|| $type === 'staff_fields_all' )
{
echo '' . $category_title . '