<?php
include_once($staticpath.'classes/InputButton.php');
$submitButton = new InputButton;
DisplayHeader(".:".ProgramTitle().":.");
if($_REQUEST['btn_block'])
{
    if(!$_REQUEST['student'])$_REQUEST['student'] = array();
    if(count($_REQUEST['student']))
    {
        $count = 0;
        foreach($_REQUEST['student'] as $student_id=>$Y)
        {
            db_execute("UPDATE STUDENTS SET PASSWORD = NULL WHERE STUDENT_ID = '". $student_id ."'");
            $count++;
        }
        DisplayBlock(_('Notise'), $count.' '.(($_REQUEST['servicemod']=='mod_apply/AppBlockAccess.php')?_('Applicants'):_('Students'))._(' be blocked'));
        $_REQUEST['search_servicefunction'] = 'search';
        $_REQUEST['COMPLITE'] = true;
    }
    else
    {
        DisplayBlock(_('Notise'), _("No selected").(($_REQUEST['servicemod']=='mod_apply/AppBlockAccess.php')?_('Applicants'):_('Students')));
        unset($_REQUEST['btn_block']);
        $_REQUEST['search_servicefunction'] = 'list';
    }
}
if(!$_REQUEST['btn_block'] || $_REQUEST['btn_block'] && $_REQUEST['COMPLITE'] == true || !$_REQUEST['servicefunction'])
{
    $addition['link'] = array('FULL_NAME'=>false);
    if(Preferences('NAME_FORMAT')=='WCM')
        $full_name = "s.LAST_NAME".CCAT."', '".CCAT."s.FIRST_NAME".CCAT."' '".CCAT."COALESCE(s.MIDDLE_NAME,' ')";
    else
        $full_name = "s.LAST_NAME".CCAT."' '".CCAT."s.FIRST_NAME".CCAT."' '".CCAT."COALESCE(s.MIDDLE_NAME,' ')";
    if($_REQUEST['_search_all_schools']=='Y')
        $school_sql = " ,ssm.SCHOOL_ID AS LIST_SCHOOL_ID ";
    $addition['SELECT_ONLY'] = "CAST (NULL AS CHAR(1)) AS CHECKBOX $school_sql ,$full_name AS FULL_NAME,s.LAST_NAME,s.FIRST_NAME,s.MIDDLE_NAME,s.STUDENT_ID,ssm.START_DATE,ssm.ENROLLMENT_CODE,ssm.END_DATE,ssm.DROP_CODE,ssm.SCHOOL_YEAR";
    $addition['functions'] = array('CHECKBOX'=>'_makeChooseCheckbox','ENROLLMENT_CODE'=>'get_enr_code','DROP_CODE'=>'get_enr_code');
    $addition['columns_before'] = array('CHECKBOX'=>'</A><INPUT type=checkbox value=Y name=controller onclick="checkAll(this.form,this.form.controller.checked,\'student\');CheckAll_hilite(this.form,this.form.controller.checked,\'student\')"><A>');
    $addition['WHERE'] = " AND ssm.SCHOOL_YEAR = '".get_school_year()."' AND ssm.END_DATE IS NOT NULL AND (ssm.NEXT_SCHOOL = '0' OR ssm.NEXT_SCHOOL = '-1') ";//AND ssm.SCHOOL_ID = '".get_school_id()."'
    $addition['columns_after']['START_DATE'] = ($_REQUEST['servicemod']=='mod_apply/AppBlockAccess.php')?_('Admission date'):_('Enrollment Date');

    $addition['columns_after']['ENROLLMENT_CODE'] = _('Enrollment Code');
    $addition['columns_after']['DROP_CODE'] = _('Drop Code');
    $addition['columns_after']['END_DATE'] = _('End Date');
    $addition['options']['onclick']="check_clicked(this);";
    if(get_school_id() && $_REQUEST['_search_all_schools']!='Y')
            $addition['WHERE'] .= " AND ssm.SCHOOL_ID='".get_school_id()."' ";
    else
    {
            /*$schools = substr(str_replace(",","','",get_user('SCHOOLS')),2,-2);
            if($schools)
                    $addition['WHERE'] .= " AND ssm.SCHOOL_ID IN ($schools) ";*/
            $addition['columns_after']['LIST_SCHOOL_ID'] = _('School');
            $functions['LIST_SCHOOL_ID'] = 'get_school';
    }
    Widgets('all');
    unset($_SESSION['student_id']);
    unset($_REQUEST['student_id']);
    unset($_REQUEST['STUDENT_ID']);
    if(!isset($_GET['search_servicefunction']))
        $_REQUEST['search_servicefunction'] = 'search';
    echo '<FORM ID="block_access" ACTION="modloader.php?servicemod='.$_REQUEST['servicemod'].'&DrawAlign=CENTER&next_servicemod='.$_REQUEST['next_servicemod'].'&search_servicefunction=list" METHOD="POST">';
    if($_REQUEST['search_servicefunction'] == 'list')
        DisplayHeader('', $submitButton->createSButton(_('Block'), 'btn_block', $options, 'submit', $javacode),'','',true,false,false,false,false);
    Search('student_id',$addition);
    if($_REQUEST['search_servicefunction'] == 'list')
        DisplayHeader('', $submitButton->createSButton(_('Block'), 'btn_block', $options, 'submit', $javacode),'','',true,false,false,false,false);
    echo '</FORM>';
}
function _makeChooseCheckbox($value,$title)
{	global $THIS_array;
	return "<INPUT onchange='hl_cb(this)' type=checkbox name=student[".$THIS_array['STUDENT_ID']."] value=Y>";
}
function get_enr_code($value,$title)
{
        global $THIS_array,$enr_array;
        if(!$enr_array)
            $enr_array = db_request (db_execute ("SELECT ID,TITLE FROM STUDENT_REGISTRATION_SETTINGS WHERE SCHOOL_YEAR = '".get_school_year()."'"),array(),array('ID'));
        return ($enr_array[$value][1]['TITLE']<>'')?$enr_array[$value][1]['TITLE']:'<FONT COLOR="#FF0000">'.$value.'</FONT>';

}
?>
