<?php
set_time_limit(0);
//die('jj');
include_once($staticpath."/classes/Button.php");
$button = new Button();
include_once($staticpath.'classes/InputButton.php');
$submitButton = new InputButton;
echo GetBaseJavaFunc();
include_once($staticpath.'classes/HTMLElements.php');
$HTMLElem = new HTMLGetElements;
if($_REQUEST['servicefunction']!='backup')
	DisplayHeader(".:".ProgramTitle().":.");

if(!$_REQUEST['system_tab'])
	$_REQUEST['system_tab'] = 'system';
if($_REQUEST['servicefunction']=='delete' && AllowEdit())
{
    $sql = array();
    if($_REQUEST['edu_cat_id']<>'' && $_REQUEST['field_cat_id']<>'')
    {
        $table = _('Field Category ');
        $sql[] = "DELETE FROM STUDENT_FIELD_CATEGORIES_IN_EDU WHERE FIELD_CATEGORY_ID = '$_REQUEST[field_cat_id]' AND EDU_CATEGORY_ID = '$_REQUEST[edu_cat_id]' AND SCHOOL_YEAR = '".get_school_year()."';";
        $sql[] = "DELETE FROM ONLINE_FIELDS WHERE CATEGORY_ID = '$_REQUEST[field_cat_id]' AND EDU_CAT_ID = '$_REQUEST[edu_cat_id]'";
        $id_var = 'field_cat_id';
    }
    elseif($_REQUEST['edu_cat_id']<>'' && $_REQUEST['field_cat_id']=='')
    {
        $table = _('Education Category');
        $sql[] = "DELETE FROM APP_EDU_CATEGORIES WHERE ID = '$_REQUEST[edu_cat_id]' AND SCHOOL_YEAR = '".get_school_year()."';";
        $sql[] = "DELETE FROM STUDENT_FIELD_CATEGORIES_IN_EDU WHERE EDU_CATEGORY_ID = '$_REQUEST[edu_cat_id]' AND SCHOOL_YEAR = '".get_school_year()."';";
        $sql[] = "DELETE FROM ONLINE_FIELDS WHERE CATEGORY_ID = '$_REQUEST[edu_cat_id]'";
        $id_var = 'edu_cat_id';
    }
    if(DeletePrompt($table))
    {
        foreach($sql as $query)
            db_execute($query);
        unset($_REQUEST['servicefunction']);
        unset($_REQUEST[$id_var]);
    }
}
//die('kk');
if($_REQUEST['servicefunction'] == 'remove' && $_REQUEST['table'] == 'SYSTEM_CONFIG' && AllowEdit())
{
	db_execute("DELETE FROM SYSTEM_CONFIG WHERE VALUE='".$_REQUEST['id']."'");
	unset($_REQUEST['servicefunction']);
}
if(($_REQUEST['values'] && $_POST['values']) || ($_REQUEST['override'] && $_POST['override']))
{
//die('kk');
if($_REQUEST['system_tab']=='school_prefs')


	{

//print_r($_REQUEST['system_tab']);
		$current_array = db_request(db_execute("SELECT DISTINCT TITLE,VALUE,SCHOOL_ID FROM SYSTEM_CONFIG WHERE PROGRAM='system' AND SCHOOL_ID='".get_school_id()."'"),array(),array('TITLE'));
//print_r($current_array);
        $request_vars_to_check = array('NAME_FORMAT', 'WEIGHTS', 'FINAL_EXAMS', 'FY_EXAMS', 'QTR_EXAMS', 'OVERRIDE_SCORE_BREAKOFFS',
        'OVERRIDE_SEMESTER_GRADE_WEIGHTS', 'BUS_ADDRESSES', 'MAILING_ADDRESSES', 'GUARDIANS', 'WEIGHTED_GPA', 'AUTO_STUDENT_USERNAMES',
        'VARIABLE_PERIOD_LENGTH', 'STUDENTS_CAN_SCHEDULE', 'STUDENTS_CAN_REQUEST', 'EDIT_ATTENDANCE_AFTER_SAVE',
        'SHORT_COMMENTS_PER_COURSE', 'ONE_LONGER_COMMENT_PER_COURSE', 'ONE_LONGER_COMMENT_PER_STUDENT',
        'CALC_GPA_AUTOMATICALLY', 'COMMENTS_CONDUCT', 'USE_PREFIX', 'USE_SUFFIX', 'USE_CREDITS','USE_REQUESTS','USE_BLOCKS','ODD_EVEN_WEEKS','DISPLAY_GPA',
        'USE_KLADR','APPLY_MODE');

        foreach($request_vars_to_check as $var)
        {
            if($_REQUEST['values']['system'][$var]!='Y')
				$_REQUEST['values']['system'][$var] = 'N';
        }
        $school = get_school_id();
//die('hhh');

	foreach($_REQUEST['values'] as $program=>$values)
	{
		foreach($values as $name=>$value)
		{
    		        $value = !isset($_REQUEST['override'][$program][$name]) ? $value : 'use_system';

			if((!$current_array[$name] && $value!=''))
	                {
				db_execute("INSERT INTO SYSTEM_CONFIG (PROGRAM,TITLE,VALUE,SCHOOL_ID) values('$program','$name','$value','$school')");
	                }
			elseif($value!='')
	                {
	                        
				db_execute("UPDATE SYSTEM_CONFIG SET VALUE='$value' WHERE PROGRAM='$program' AND TITLE='$name' AND SCHOOL_ID='$school'");
	                }
			else
    		        {
				db_execute("DELETE FROM SYSTEM_CONFIG WHERE PROGRAM='$program' AND TITLE='$name' AND SCHOOL_ID='$school'");
            		}
		}
	}

        foreach($_REQUEST['override'] as $program=>$values)
        {
            foreach($values as $name=>$value)
            {
                $value = 'use_system';

                if(!$current_array[$name])
                {
                	db_execute("INSERT INTO SYSTEM_CONFIG (PROGRAM,TITLE,VALUE,SCHOOL_ID) values('$program','$name','$value','$school')");
                }
                else
                {
            	        db_execute("UPDATE SYSTEM_CONFIG SET VALUE='$value' WHERE PROGRAM='$program' AND TITLE='$name' AND SCHOOL_ID='$school'");
                }
            }
        }

	// So SystemPreferences() will get the new values
	unset($_SYSTEM['SystemPreferences']);
        unset($current_array);
	}
	elseif($_REQUEST['system_tab']=='system')
	{
		$current_array = db_request(db_execute("SELECT TITLE,VALUE FROM SYSTEM_CONFIG WHERE PROGRAM='".$_REQUEST['system_tab']."' AND (SCHOOL_ID IS NULL)"),array(),array('TITLE'));

    		$request_vars_to_check = array('NAME_FORMAT', 'WEIGHTS', 'FINAL_EXAMS', 'FY_EXAMS', 'QTR_EXAMS', 'OVERRIDE_SCORE_BREAKOFFS',
	        'OVERRIDE_SEMESTER_GRADE_WEIGHTS', 'BUS_ADDRESSES', 'MAILING_ADDRESSES', 'GUARDIANS', 'WEIGHTED_GPA', 'AUTO_STUDENT_USERNAMES',
    	        'VARIABLE_PERIOD_LENGTH', 'STUDENTS_CAN_SCHEDULE', 'STUDENTS_CAN_REQUEST', 'EDIT_ATTENDANCE_AFTER_SAVE',
    	        'SHORT_COMMENTS_PER_COURSE', 'ONE_LONGER_COMMENT_PER_COURSE', 'ONE_LONGER_COMMENT_PER_STUDENT',
        	'CALC_GPA_AUTOMATICALLY', 'COMMENTS_CONDUCT','USE_BLOCKS','USE_CREDITS','USE_REQUESTS', 'USE_PREFIX','USE_SUFFIX','ODD_EVEN_WEEKS','DISPLAY_GPA',
        	'USE_KLADR','APPLY_MODE');

	        foreach($request_vars_to_check as $var)
	        {
	    	        if($_REQUEST['values'][$_REQUEST['system_tab']][$var]!='Y')
				$_REQUEST['values'][$_REQUEST['system_tab']][$var] = 'N';
	        }
		foreach($_REQUEST['values'] as $program=>$values)
		{
			foreach($values as $name=>$value)
			{
				if(!$current_array[$name] && $value!='')
		                {
					db_execute("INSERT INTO SYSTEM_CONFIG (PROGRAM,TITLE,VALUE,SCHOOL_ID) values('$program','$name','$value', NULL)");
		                }
				elseif($value!='')
		                {
					db_execute("UPDATE SYSTEM_CONFIG SET VALUE='$value' WHERE PROGRAM='$program' AND TITLE='$name' AND (SCHOOL_ID IS NULL)");
		                }
				else
					db_execute("DELETE FROM SYSTEM_CONFIG WHERE PROGRAM='$program' AND TITLE='$name' AND (SCHOOL_ID IS NULL)");
			}
		}

		// So SystemPreferences() will get the new values
		unset($_SYSTEM['SystemPreferences']);
	}
//die('gg');
	elseif($_REQUEST['system_tab']=='default_user')
	{
		if(true)
		{
			$current_array = db_request(db_execute("SELECT TITLE,VALUE,PROGRAM FROM SYSTEM_CONFIG WHERE PROGRAM IN ('Preferences','StudentFieldsSearch','StudentFieldsView','Gradebook') "),array(),array('PROGRAM','TITLE'));
		
			if($_REQUEST['tab']=='student_listing' && $_REQUEST['values']['Preferences']['SEARCH']!='Y')
				$_REQUEST['values']['Preferences']['SEARCH'] = 'N';
			if($_REQUEST['tab']=='student_listing' && $_REQUEST['values']['Preferences']['DEFAULT_CUSTOMIZED_LIST']!='Y' && (get_user('PROFILE')=='teacher' || get_user('PROFILE')=='admin'))
				$_REQUEST['values']['Preferences']['DEFAULT_CUSTOMIZED_LIST'] = 'N';
			if($_REQUEST['tab']=='student_listing' && $_REQUEST['values']['Preferences']['DEFAULT_ALL_SCHOOLS']!='Y')
				$_REQUEST['values']['Preferences']['DEFAULT_ALL_SCHOOLS'] = 'N';
			if($_REQUEST['tab']=='display_options' && $_REQUEST['values']['Preferences']['CALENDAR']!='Sun')
	                        $_REQUEST['values']['Preferences']['CALENDAR'] = 'Mon';
                        if($_REQUEST['tab']=='display_options' && $_REQUEST['values']['Preferences']['CURRENCY_SL']!='Left')
                                $_REQUEST['values']['Preferences']['CURRENCY_SL'] = 'Right';
			if($_REQUEST['tab']=='student_listing' && $_REQUEST['values']['Preferences']['NAME_FORMAT']!='WCM')
				$_REQUEST['values']['Preferences']['NAME_FORMAT'] = 'WOCM';
			if($_REQUEST['tab']=='student_listing' && $_REQUEST['values']['Preferences']['DISPLAY_STUDENT_ID']!='Y')
				$_REQUEST['values']['Preferences']['DISPLAY_STUDENT_ID'] = 'N';
			if($_REQUEST['tab']=='student_listing' && $_REQUEST['values']['Preferences']['DISPLAY_CLASSLEVEL']!='Y')
				$_REQUEST['values']['Preferences']['DISPLAY_CLASSLEVEL'] = 'N';
			if($_REQUEST['tab']=='student_listing' && $_REQUEST['values']['Preferences']['DISPLAY_GROUP']!='Y')
				$_REQUEST['values']['Preferences']['DISPLAY_GROUP'] = 'N';
	
			if($_REQUEST['tab']=='display_options' && $_REQUEST['values']['Preferences']['HIDDEN']!='Y')
				$_REQUEST['values']['Preferences']['HIDDEN'] = 'N';
		
			if($_REQUEST['tab']=='student_fields')
			{
				db_execute("DELETE FROM SYSTEM_CONFIG WHERE PROGRAM IN ('StudentFieldsSearch','StudentFieldsView')");
	
				foreach($_REQUEST['values'] as $program=>$values)
				{
					foreach($values as $name=>$value)
					{
						if(isset($value))
							db_execute("INSERT INTO SYSTEM_CONFIG (PROGRAM,TITLE,VALUE) values('$program','$name','$value')");
					}
				}
			}
			else
			{
				if($_REQUEST['tab']=='gradebook_configuration')
				{
					// COPIED FROM GRADEBOOK CONFIGURATION
					if($_REQUEST['values']['Gradebook']['WEIGHT']!='Y')
						$_REQUEST['values']['Gradebook']['WEIGHT'] = 'N';
					if($_REQUEST['values']['Gradebook']['APPLY_ALL_DEFAULT']!='Y')
						$_REQUEST['values']['Gradebook']['APPLY_ALL_DEFAULT'] = 'N';		
					if($_REQUEST['values']['Gradebook']['PERCENT_MODE']!='Y')
						$_REQUEST['values']['Gradebook']['PERCENT_MODE'] = 'N';		
				}

				foreach($_REQUEST['values'] as $program=>$values)
				{
					foreach($values as $name=>$value)
					{
						if(!$current_array[$program][$name] && $value!='')
							db_execute("INSERT INTO SYSTEM_CONFIG (PROGRAM,TITLE,VALUE) values('$program','$name','$value')");
						elseif($value!='')
							db_execute("UPDATE SYSTEM_CONFIG SET VALUE='$value' WHERE PROGRAM='$program' AND TITLE='$name'");
						else
							db_execute("DELETE FROM SYSTEM_CONFIG WHERE PROGRAM='$program' AND TITLE='$name'");
					}
				}
			}
	
			// So Preferences() will get the new values
			unset($_SYSTEM['Preferences']);
		}
	}
        elseif($_REQUEST['system_tab']=='applicants')
        {
            if($_REQUEST['apply_all_school'])
            {
                $tmp_REQUEST['apply_all_school'] = $_REQUEST['apply_all_school'];
                if(Prompt(_('Confirm preferences sharing'), _("Do you want overwite Applicantion Prefernces for all schools which are in admission mode with preferences from this school?"), _('All previous preferences will be overwritten!'), false, _('OK'), false, "Are you really sure?",'post'))
                {
                    $app_school = get_apply_school_array();
                    unset($app_school[get_school_id()]);

                    db_execute("DELETE FROM SYSTEM_CONFIG WHERE PROGRAM='".$_REQUEST['system_tab']."' AND SCHOOL_ID IN ('".implode("','",$app_school)."')");
                    db_execute("DELETE FROM APP_IDGEN WHERE SCHOOL_ID IN ('".implode("','",$app_school)."')");
                    foreach($app_school as $id=>$school)
                    {
                        db_execute("INSERT INTO SYSTEM_CONFIG (program,school_id,school_year,title,value) (SELECT program, '".$school."' as school_id,school_year,title,value FROM SYSTEM_CONFIG WHERE PROGRAM='".$_REQUEST['system_tab']."' AND SCHOOL_ID = '".get_school_id()."')");
                        db_execute("INSERT INTO APP_IDGEN (SCHOOL_ID,ELEMENT_ID,SORT_ORDER,IDMASK) (SELECT '".$school."' AS SCHOOL_ID,ELEMENT_ID,SORT_ORDER,IDMASK FROM APP_IDGEN WHERE SCHOOL_ID='".get_school_id()."')");
                    }
                    unset($tmp_REQUEST['apply_all_school']);
                    
                }
                else
                {
                    die();
                }
            }
            else
            {
                $current_array = db_request(db_execute("SELECT TITLE,VALUE FROM SYSTEM_CONFIG WHERE PROGRAM='".$_REQUEST['system_tab']."' AND SCHOOL_ID = '".get_school_id()."'"),array(),array('TITLE'));
                if($_REQUEST['tab']=='mod_apply')
                        $request_vars_to_check = array('BLOCKGROUP','BLOCKUSERNAME','AUTOGENPASS','CHANGESRSCHOOL');
                if(!$request_vars_to_check) $request_vars_to_check = array();
                if($_REQUEST['values']['applicants']['EXFIELD']=='')
                    $_REQUEST['values']['applicants']['EXSHORTFIELD']=='';
                elseif($_REQUEST['values']['applicants']['EXFIELD']<>$current_array['EXFIELD'] && $_REQUEST['values']['applicants']['EXSHORTFIELD']=='' || $_REQUEST['values']['applicants']['EXSHORTFIELD']==$current_array['EXSHORTFIELD'])
                    $_REQUEST['values']['applicants']['EXSHORTFIELD']=='';


                foreach($request_vars_to_check as $var)
                {

                    if($_REQUEST['values']['applicants'][$var]!='Y')
                        $_REQUEST['values']['applicants'][$var] = 'N';
                }
                foreach($_REQUEST['values'] as $program=>$values)
                {
                    foreach($values as $name=>$value)
                    {
                        if(!$current_array[$name] && $value!='')
                        {
    //                    echo "INS:".$program.'-'.$name.'='.$value;
                                db_execute("INSERT INTO SYSTEM_CONFIG (PROGRAM,TITLE,VALUE,SCHOOL_ID) values('$program','$name','$value', '".get_school_id()."')");
    //                    	    echo "INSERT INTO SYSTEM_CONFIG (PROGRAM,TITLE,VALUE,SCHOOL_ID) values('$program','$name','$value', NULL)";
                        }
                        elseif($value!='')
                        {
    //                    echo "UPD:".$program.'-'.$name.'='.$value;
                                db_execute("UPDATE SYSTEM_CONFIG SET VALUE='$value' WHERE PROGRAM='$program' AND TITLE='$name' AND SCHOOL_ID = '".get_school_id()."'");
    //                    	    echo "UPDATE SYSTEM_CONFIG SET VALUE='$value' WHERE PROGRAM='$program' AND TITLE='$name' AND SCHOOL_ID = '".get_school_id()."'";
                        }
                        else
                                db_execute("DELETE FROM SYSTEM_CONFIG WHERE PROGRAM='$program' AND TITLE='$name' AND SCHOOL_ID = '".get_school_id()."'");
                    }
                }
                // So SystemPreferences() will get the new values
                unset($_SYSTEM['SystemPreferences']);
            }
        }
	unset($_SYSTEM['SystemPreferences']);
	unset($_REQUEST['values']);
	unset($_SESSION['_REQUEST_vars']['values']);
}

if($_REQUEST['servicefunction']=='backup' && $_REQUEST['CREATEPDF']!='true')
{
	$str=""; 
	$ctype="application/force-download"; 
	header("Pragma: public"); 
	header("Expires: 0"); 
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
	header("Cache-Control: public"); 
	header("Content-Description: File Transfer"); 
	header("Content-Type: $ctype"); 
	$header="Content-Disposition: attachment; filename=integral_db.sql;"; 
	header($header); 
	header("Content-Transfer-Encoding: binary"); 

	$str = '';
	$res = db_execute("select relname as tablename 
					from pg_class where relkind in ('S')
					and relname not like 'pg_%' and relname not like 'sql_%' order by tablename");
	
	while($row = pg_fetch_row($res))
	{
		$table = $row[0];
		$str .= "\n--\n"; 
		$str .= "-- Structure for sequence: '$table'"; 
		$str .= "\n--\n"; 
		$str .= "\nCREATE SEQUENCE $table INCREMENT 1 START ";

		$res2 = db_request(db_execute("SELECT last_value FROM public.$table"));
		$str .= ($res2[1]['LAST_VALUE']+1).';';
	}
	
	echo $str;
	echo "\n\n";
	$str = '';
	$res = db_execute("select relname as tablename 
					from pg_class where relkind in ('r')
					and relname not like 'pg_%' and relname not like 'sql_%' order by tablename");
	
	while($row = pg_fetch_row($res)) 
	{
		$table = $row[0]; 
		$str .= "\n--\n"; 
		$str .= "-- Structure for table: '$table'"; 
		$str .= "\n--\n"; 
		$str .= "\nCREATE TABLE $table ("; 
		$res2 = db_execute(" 
		SELECT  attnum,attname , typname , atttypmod-4 , attnotnull ,atthasdef ,adsrc AS def 
		FROM pg_attribute, pg_class, pg_type, pg_attrdef WHERE pg_class.oid=attrelid 
		AND pg_type.oid=atttypid AND attnum>0 AND pg_class.oid=adrelid AND adnum=attnum 
		AND atthasdef='t' AND lower(relname)='$table' UNION 
		SELECT attnum,attname , typname , atttypmod-4 , attnotnull , atthasdef ,'' AS def 
		FROM pg_attribute, pg_class, pg_type WHERE pg_class.oid=attrelid 
		AND pg_type.oid=atttypid AND attnum>0 AND atthasdef='f' AND lower(relname)='$table' ");
		$types = array();
		$count = 0;
		while($r = pg_fetch_row($res2)) 
		{ 
			$str .= "\n".'"'.$r[1]. '" ' . $r[2]; 
			if($r[2]=="varchar") 
			{
				$str .= "(".$r[3] .")"; 
			} 
			if($r[4]=="t") 
			{
				$str .= " NOT NULL"; 
			} 
			if($r[5]=="t") 
			{
				$str .= " DEFAULT ".$r[6]; 
			}
			$str .= ",";

			$count++;
			$types[$count] = $r[2];
		}
		$str=rtrim($str, ",");  
		$str .= "\n);\n"; 
		$str .= "\n--\n"; 
		$str .= "-- Creating data for '$table'"; 
		$str .= "\n--\n\n";

		$res3 = db_execute("SELECT * FROM $table");
		$count = 0;
		while($r = pg_fetch_row($res3))
		{
			array_rwalk($r,'DBEscapeString');
			array_rwalk($r,'_replaceSingleQuotes');
			array_rwalk($r,'_replaceDoubleLineBreaks');
			array_rwalk($r,'utf8_decode');
			$sql = "INSERT INTO $table VALUES ('";
			$sql .= str_replace("í","''",str_replace("î",'"',implode("','",$r)));
			$sql .= "');";
			//if(substr($table,0,4)!='mdl_')
				//$sql = ereg_replace("([,\(=])[\r\n\t ]*''",'\\1NULL',$sql);
			$str .= $sql;
			$str .= "\n";
			echo $str;
			$str = '';
		}

		 $res1 = db_execute("SELECT pg_index.indisprimary, 
			pg_catalog.pg_get_indexdef(pg_index.indexrelid) 
		FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, 
			pg_catalog.pg_index AS pg_index 
		WHERE c.relname = '$table' 
			AND c.oid = pg_index.indrelid 
			AND pg_index.indexrelid = c2.oid"); 

		$str .= "\n\n--\n";
		$str .= "-- Creating indices for '$table'";
		$str .= "\n--\n\n";
		while($r = pg_fetch_row($res1))
		{
			$t = str_replace("CREATE UNIQUE INDEX", "", $r[1]);
			$t = str_replace("USING btree", "|", $t);
			// Next Line Can be improved!!!
			$t = str_replace("ON", "|", $t);
			$Temparray = explode("|", $t);
			$str .= "ALTER TABLE ONLY ". $Temparray[1] . " ADD CONSTRAINT " . $Temparray[0];
			if($r[0]=='t' || strpos($r[1], "CREATE UNIQUE INDEX") !== false)
				$str .= " PRIMARY KEY " . $Temparray[2] .";\n";
			else
				$str .= $Temparray[2] .";\n";
		}
		$str .= "\n\n";
	}
	$res = db_execute(" SELECT 
	cl.relname AS tabela,ct.conname, 
	pg_get_constraintdef(ct.oid) 
	FROM pg_catalog.pg_attribute a 
	JOIN pg_catalog.pg_class cl ON (a.attrelid = cl.oid AND cl.relkind = 'r') 
	JOIN pg_catalog.pg_namespace n ON (n.oid = cl.relnamespace) 
	JOIN pg_catalog.pg_constraint ct ON (a.attrelid = ct.conrelid AND 
	ct.confrelid != 0 AND ct.conkey[1] = a.attnum) 
	JOIN pg_catalog.pg_class clf ON (ct.confrelid = clf.oid AND clf.relkind = 'r') 
	JOIN pg_catalog.pg_namespace nf ON (nf.oid = clf.relnamespace) 
	JOIN pg_catalog.pg_attribute af ON (af.attrelid = ct.confrelid AND 
	af.attnum = ct.confkey[1]) order by cl.relname "); 
	
	while($row = pg_fetch_row($res)) 
	{
		$str .= "\n\n--\n"; 
		$str .= "-- Creating relationships for '".$row[0]."'"; 
		$str .= "\n--\n\n"; 
		$str .= "ALTER TABLE ONLY ".$row[0] . " ADD CONSTRAINT " . $row[1] . " " . $row[2] . ";"; 
	}        
	echo $str;

	exit;
}

unset($_REQUEST['search_servicefunction']);
unset($_SESSION['_REQUEST_vars']['search_servicefunction']);
$remove_id = false;
$sdis = false;
if($_REQUEST['servicefunction'] == 'remove_id' && !$_REQUEST['delete_ok'])
{
	unset($_REQUEST['servicefunction']);
	$remove_id = true;
	$sdis = true;
}
elseif($_REQUEST['delete_ok'])
{
	$remove_id = true;
	unset($_REQUEST['servicefunction']);
}

if(!$_REQUEST['servicefunction'])
{
	if($_REQUEST['system_tab'] == 'applicants')
		$current_array = db_request(db_execute("SELECT TITLE,VALUE FROM SYSTEM_CONFIG WHERE PROGRAM='".$_REQUEST['system_tab']."' AND SCHOOL_ID = '".get_school_id()."'"),array(),array('TITLE'));
	else
		$current_array = db_request(db_execute("SELECT TITLE,VALUE FROM SYSTEM_CONFIG WHERE PROGRAM='".$_REQUEST['system_tab']."'"),array(),array('TITLE'));
	
	if($_REQUEST['system_tab']!='database_backup_download' && $sdis === false)
	{
		echo "<FORM name=config_form id=config_form action=modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=$_REQUEST[system_tab]&amp;tab=$_REQUEST[tab]&amp;edu_cat_id=$_REQUEST[edu_cat_id]&amp;field_cat_id=$_REQUEST[field_cat_id] method=POST>";
	
		DisplayHeader('','<INPUT type=submit value='._('Save').'>');
	}
	echo '<BR>';

    $has_school_preferences = db_request(db_execute("SELECT count(*) as CNT FROM SCHOOLS"));
//echo ($has_school_preferences) ;
    $has_school_preferences = $has_school_preferences[1]['CNT']>1;
	
    $tabs = array();

    //$tabs[] = array('title'=>_('Counter Preferences'), 'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=counter");
    if($has_school_preferences)
    
    	    $tabs[] = array('title'=>_('School Preferences'), 'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=school_prefs");
    if(is_apply_school()<>'N')
        $tabs[] = array('title'=>_('Application Preferences'), 'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=applicants");

    if($DBType == 'mssql')
    {
	    if($has_school_preferences)
		    $tabs[] = array('title'=>_('Default School Preferences'),'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=system");
	    else
		    $tabs[] = array('title'=>_('System Preferences'),'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=system");
    	    $tabs[] = array('title'=>_('Default User Preferences'),'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=default_user");
    }
    else
    {
	    if($has_school_preferences)
		    $tabs[] = array('title'=>_('Default School Preferences'),'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=system");
	    else
		    $tabs[] = array('title'=>_('System Preferences'),'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=system");
    	    $tabs[] = array('title'=>_('Default User Preferences'),'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=default_user");
//        $tabs[] = array('title'=>_('Database Download'),'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=database_backup_download");
    }
    //array('title'=>_('Default Gradebook Configuration'),'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=default_gradebook")

	$_SYSTEM['selected_tab'] = "modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=".$_REQUEST['system_tab'];
	PopTable('header',$tabs);

	if($_REQUEST['system_tab']=='default_user')
	    echo '<table width=100%><tr><td style="text-align:center"><font color=red>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>'._('Attention!!! These Default User Preferences will work only for new created users.<br>If you want to change your personal preferences, click').'</font> <A HREF="modloader.php?servicemod=mod_users/UsrPrefnProper.php&system_tab=&tab=display_options">'._('"My Preferences"').'</B></A></td></tr></table>';

        $alternate_row_color = " bgcolor=\"".Preferences('COLOR')."\"";
        $colorline = Preferences('HIGHLIGHT');
        $TDleft = "style='border-bottom:1px inset #".$colorline."' valign=top align=".ALIGN_LEFT."";
        $TDright = 'style="border-bottom:1px inset #'.$colorline.';"';
	if($_REQUEST['system_tab']=='system')
	{
	        echo '<div valign=top align='.'CENTER'.'><h3>'._('Default preferences').'</h3></div>';
		echo '<TABLE class="setuptable" style="border:1px solid #'.Preferences('HIGHLIGHT').';border-radius: 10px;" cellspacing=0 cellpadding=2 width=100%>';
		$options = '';
		for($i=0;$i<=20;$i++)
		{
			if(SystemPreferences('VIEW_PAST_STUDENT_ATTENDANCE_DAYS', 'system', true)==$i)
				$selected = ' SELECTED';
			else
				$selected = '';
			$options .= '<OPTION value='.$i.$selected.'>'.$i.' ';
			if($i==1)
				$options .= _('day');
			else
				$options .= _('days');
		}
		
		echo '<TR '.$alternate_row_color.'><TD '.$TDleft.' valign=top align='.ALIGN_LEFT.'><br><font color=gray>'._('How many the previous days\'<BR>attendance can teachers view').'</TD><TD '.$TDright.'><SELECT name=values[system][VIEW_PAST_STUDENT_ATTENDANCE_DAYS]>'.$options.'</SELECT></TD></TR>';
		
		$options = '';
		for($i=0;$i<=20;$i++)
		{
			if(SystemPreferences('EDIT_PAST_STUDENT_ATTENDANCE_DAYS', 'system', true)==$i)
				$selected = ' SELECTED';
			else
				$selected = '';
			$options .= '<OPTION value='.$i.$selected.'>'.$i.' ';
			if($i==1)
				$options .= _('day');
			else
				$options .= _('days');
		}
		
		echo '<TR><TD '.$TDleft.' width=300><font color=gray>'._('How many the previous days\'<BR>attendance can teachers modify').'</TD><TD '.$TDright.'><SELECT name=values[system][EDIT_PAST_STUDENT_ATTENDANCE_DAYS]>'.$options.'</SELECT></TD></TR>';
		echo '<TR '.$alternate_row_color.'><TD '.$TDleft.'><font color=gray>'._('How many minimum minutes a student<BR>has to attend to count as full-day present').'</TD><TD '.$TDright.'><INPUT type=text name=values[system][MIN_FULLDAY] value="'.SystemPreferences('MIN_FULLDAY', 'system', true).'" maxlength=5 size=3></TD></TR>';

		echo '<TR><TD '.$TDleft.'><font color=gray>'._('How many minimum minutes a student<BR>has to attend to count as half-day present').'</TD><TD '.$TDright.'><INPUT type=text name=values[system][MIN_HALFDAY] value="'.SystemPreferences('MIN_HALFDAY', 'system', true).'" maxlength=5 size=3></TD></TR>';
		echo '<TR '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox id=values[system][EDIT_ATTENDANCE_AFTER_SAVE] name=values[system][EDIT_ATTENDANCE_AFTER_SAVE] value=Y'.((SystemPreferences('EDIT_ATTENDANCE_AFTER_SAVE', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][EDIT_ATTENDANCE_AFTER_SAVE]>'._('Allow teachers to modify attendance after pressing "Save"').'</label></TD></TR>';


		echo '<TR><TD '.$TDleft.'><font color=gray>'._('Report Card. Type of Visibility').'</TD><TD '.$TDright.'><INPUT type=radio name=values[system][REPORT_CARD] id="values[system][REPORT_CARD]1" value="both"'.((SystemPreferences('REPORT_CARD', 'system', true)=='both')?' CHECKED':'').'><label for=values[system][REPORT_CARD]1>'._('Percent & Letter/Digit Grade').'</label><INPUT type=radio name=values[system][REPORT_CARD] id=values[system][REPORT_CARD]2 value=grade'.((SystemPreferences('REPORT_CARD', 'system', true)=='grade')?' CHECKED':'').'><label for=values[system][REPORT_CARD]2>'._('Letter/Digit Grade').'</label><INPUT type=radio name=values[system][REPORT_CARD] id=values[system][REPORT_CARD]3 value=percent'.((SystemPreferences('REPORT_CARD', 'system', true)=='percent')?' CHECKED':'').'><label for=values[system][REPORT_CARD]3>'._('Percent').'</label></TD></TR>';
		echo '<TR '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][FINAL_EXAMS] id=values[system][FINAL_EXAMS] value=Y'.((SystemPreferences('FINAL_EXAMS', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][FINAL_EXAMS]>'._('Use Final Semester Exams').'</label></TD></TR>';

		echo '<TR><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][FY_EXAMS] id=values[system][FY_EXAMS] value=Y'.((SystemPreferences('FY_EXAMS', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][FY_EXAMS]>'._('Use Full Year Exams').'</label></TD></TR>';
		echo '<TR '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][QTR_EXAMS] id=values[system][QTR_EXAMS] value=Y'.((SystemPreferences('QTR_EXAMS', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][QTR_EXAMS]>'._('Use Quarter Exams').'</label></TD></TR>';

		echo '<TR><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][OVERRIDE_SCORE_BREAKOFFS] id=values[system][OVERRIDE_SCORE_BREAKOFFS] value=Y'.((SystemPreferences('OVERRIDE_SCORE_BREAKOFFS', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][OVERRIDE_SCORE_BREAKOFFS]>'._('Allow teachers to change grading scale score breakoffs').'</label></TD></TR>';
		echo '<TR '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][OVERRIDE_SEMESTER_GRADE_WEIGHTS] id=values[system][OVERRIDE_SEMESTER_GRADE_WEIGHTS] value=Y'.((SystemPreferences('OVERRIDE_SEMESTER_GRADE_WEIGHTS', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][OVERRIDE_SEMESTER_GRADE_WEIGHTS]>'._('Allow teachers to change semester grade calculation weights').'</label></TD></TR>';

		echo '<TR><TD '.$TDleft.'><font color=gray>'._('Default Credits').'</TD><TD '.$TDright.'><INPUT type=text name=values[system][DEFAULT_CREDITS] value="'.SystemPreferences('DEFAULT_CREDITS', 'system', true).'" maxlength=10 size=2></TD></TR>';
		echo '<TR  '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][WEIGHTED_GPA] id=values[system][WEIGHTED_GPA] value=Y'.((SystemPreferences('WEIGHTED_GPA', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][WEIGHTED_GPA]>'._('Use Weighted GPA').'</label></TD></TR>';
		
		echo '<TR><TD '.$TDleft.'><font color=gray>'._('Use GPA points or Percent Grade for calculation Class Rating').'</TD><TD '.$TDright.'><INPUT type=radio name=values[system][GPA_POINTS_OR_PERCENT_GRADE] id=values[system][GPA_POINTS_OR_PERCENT_GRADE]1 value="GPA_POINTS"'.((SystemPreferences('GPA_POINTS_OR_PERCENT_GRADE', 'system', true)=='GPA_POINTS')?' CHECKED':'').'><label for=values[system][GPA_POINTS_OR_PERCENT_GRADE]1>'._('GPA points').'</label><INPUT type=radio name=values[system][GPA_POINTS_OR_PERCENT_GRADE] id=values[system][GPA_POINTS_OR_PERCENT_GRADE]2 value="PERCENT_GRADE"'.((SystemPreferences('GPA_POINTS_OR_PERCENT_GRADE', 'system', true)=='PERCENT_GRADE')?' CHECKED':'').'><label for=values[system][GPA_POINTS_OR_PERCENT_GRADE]2>'._('Percent Grade').'</label></TD></TR>';
		
		echo '<TR  '.$alternate_row_color.'><TD '.$TDleft.' valign=top ><font color=gray>'._('How to calculate final grade using gradebook').'</TD><TD '.$TDright.'><INPUT type=radio name=values[system][FORMULA] id=values[system][FORMULA]1 value="WPOINT"'.((SystemPreferences('FORMULA', 'system', true)=='WPOINT')?' CHECKED':'').'><label for=values[system][FORMULA]1>'._('Fg=E(student_points / assignment_points) * category_weight').'</label><BR><INPUT type=radio name=values[system][FORMULA] id=values[system][FORMULA]2 value="WAVGGRD"'.((SystemPreferences('FORMULA', 'system', true)=='WAVGGRD')?' CHECKED':'').'><label for=values[system][FORMULA]2>'._('Fg=E(Ri*Ki)').'</label></TD></TR>';

		echo '<TR><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][USE_CREDITS] id=values[system][USE_CREDITS] value=Y'.((SystemPreferences('USE_CREDITS', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][USE_CREDITS]>'._('Use Credits').'</label></TD></TR>';
		echo '<TR  '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][WEIGHTS] id=values[system][WEIGHTS] value=Y'.((SystemPreferences('WEIGHTS', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][WEIGHTS]>'._('Use Course Weights').'</label></TD></TR>';
				
		echo '<TR><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][USE_BLOCKS] id=values[system][USE_BLOCKS] value=Y'.((SystemPreferences('USE_BLOCKS', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][USE_BLOCKS]>'._('Use Blocks').'</label></TD></TR>';
		echo '<TR  '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][USE_REQUESTS] id=values[system][USE_REQUESTS] value=Y'.((SystemPreferences('USE_REQUESTS', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][USE_REQUESTS]>'._('Use Course Requests').'</label></TD></TR>';		

		echo '<TR><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][DISPLAY_GPA] id=values[system][DISPLAY_GPA] value=Y'.((SystemPreferences('DISPLAY_GPA', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][DISPLAY_GPA]>'._('Display GPA in Final Grades Report').'</label></TD></TR>';

	  /*      echo '<TR  '.$alternate_row_color.'><TD colspan=2  background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 style="border-width:1px;border-color:gray;border-style:none solid none solid;background-repeat:repeat-x;" valign=top align='.CENTER.'><font color=black></TR>';*/
		echo '<SCRIPT LANGUAGE=JAVASCRIPT>
			function change_wstate()
			{

			    if(document.getElementById("values[system][ODD_EVEN_WEEKS]").checked)
				    document.getElementById("wf_input").disabled=false;
			    else
				    document.getElementById("wf_input").disabled=true;
				
			}
		</SCRIPT>
		';
		echo '<TR  '.$alternate_row_color.' ><TD '.$TDleft.' valign=top><font color=gray>'._('School Year Title').'</TD><TD '.$TDright.'><INPUT type=radio name=values[system][SCHOOL_YEAR_TITLE] id=values[system][SCHOOL_YEAR_TITLE]1 value="YYYY-YYYY"'.((SystemPreferences('SCHOOL_YEAR_TITLE', 'system', true)=='YYYY-YYYY')?' CHECKED':'').'><label for=values[system][SCHOOL_YEAR_TITLE]1>'.get_school_year().'-'.(get_school_year()+1).'</label><INPUT type=radio name=values[system][SCHOOL_YEAR_TITLE] id=values[system][SCHOOL_YEAR_TITLE]2 value=YYYY'.((SystemPreferences('SCHOOL_YEAR_TITLE', 'system', true)=='YYYY')?' CHECKED':'').'><label for=values[system][SCHOOL_YEAR_TITLE]2>'.get_school_year().'</label></TD></TR>';
		echo '<TR><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][VARIABLE_PERIOD_LENGTH] id=values[system][VARIABLE_PERIOD_LENGTH] value=Y'.((SystemPreferences('VARIABLE_PERIOD_LENGTH', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][VARIABLE_PERIOD_LENGTH]>'._('Period lengths depends on the day of the week').'</label></TD></TR>';
		//even weeks
		echo '<TR  '.$alternate_row_color.' ><TD '.$TDleft.' valign=top><font color=gray>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][ODD_EVEN_WEEKS] onclick="change_wstate();" id=values[system][ODD_EVEN_WEEKS] value=Y'.((SystemPreferences('ODD_EVEN_WEEKS', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][ODD_EVEN_WEEKS]>'._('Use Even-numbered/odd-numbered weeks').'</label></TD></TR>';
		if(!SystemPreferences('WEEKSFROM', 'system', true))
		{
		    $weeksdate = date("Y")."-01-01";
		}
		else
		    $weeksdate = SystemPreferences('WEEKSFROM', 'system', true);
		    
		    if(SystemPreferences('ODD_EVEN_WEEKS', 'system', true)=='Y')
			    $wdisable = 'ENABLED';
		    else
			    $wdisable = 'DISABLED';
		    
		echo '<TR><TD '.$TDleft.' valign=top><font color=gray>'._('Count weeks from').'</TD><TD '.$TDright.'><INPUT type=text name=values[system][WEEKSFROM] id=wf_input '.$wdisable.' value="'.$weeksdate.'" maxlength=10 size=10></TD></TR>';
		

		echo '<TR  '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][STUDENTS_CAN_SCHEDULE] id=values[system][STUDENTS_CAN_SCHEDULE] value=Y'.((SystemPreferences('STUDENTS_CAN_SCHEDULE', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][STUDENTS_CAN_SCHEDULE]>'._('Allow students to enroll themselves in classes').'</label></TD></TR>';
		echo '<TR><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][STUDENTS_CAN_REQUEST] id=values[system][STUDENTS_CAN_REQUEST] value=Y'.((SystemPreferences('STUDENTS_CAN_REQUEST', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][STUDENTS_CAN_REQUEST]>'._('Allow students to request classes').'</label></TD></TR>';

		echo '<TR  '.$alternate_row_color.'><TD '.$TDleft.' valign=top><font color=gray>'._('Display the list of students by:').'</TD><TD '.$TDright.'><INPUT type=radio name=values[system][SHOW_STUDENTS_BY] id=values[system][SHOW_STUDENTS_BY]1 value="25"'.((SystemPreferences('SHOW_STUDENTS_BY', 'system', true)=='25')?' CHECKED':'').'><label for=values[system][SHOW_STUDENTS_BY]1>'._('25 lines').'</label><INPUT type=radio name=values[system][SHOW_STUDENTS_BY] id=values[system][SHOW_STUDENTS_BY]2 value="50"'.((SystemPreferences('SHOW_STUDENTS_BY', 'system', true)=='50')?' CHECKED':'').'><label for=values[system][SHOW_STUDENTS_BY]2>'._('50 lines').'</label><INPUT type=radio name=values[system][SHOW_STUDENTS_BY] id=values[system][SHOW_STUDENTS_BY]3 value="00"'.((SystemPreferences('SHOW_STUDENTS_BY', 'system', true)=='00')?' CHECKED':'').'><label for=values[system][SHOW_STUDENTS_BY]3>'._('no limit').'</label></TD></TR>';
/*	        echo '<TR><TD colspan=2  background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 style="border-width:1px;border-color:gray;border-style:none solid none solid;background-repeat:repeat-x;" valign=top align='.CENTER.'><font color=black></TR>';*/

		echo '<TR  '.$alternate_row_color.'><TD '.$TDleft.' valign=top><font color=gray>'._('Decimal Point Character').'</TD><TD '.$TDright.'><INPUT type=radio name=values[system][DECIMAL] id=values[system][DECIMAL]1 value="."'.((SystemPreferences('DECIMAL', 'system', true)=='.')?' CHECKED':'').'><label for=values[system][DECIMAL]1>'._('Point (<b>.</b>)').'</label><INPUT type=radio name=values[system][DECIMAL] id=values[system][DECIMAL]2 value=","'.((SystemPreferences('DECIMAL', 'system', true)==',')?' CHECKED':'').'><label for=values[system][DECIMAL]2>'._('Comma (<b>,</b>)').'</label></TD></TR>';
		echo '<TR ><TD valign=top '.$TDleft.'><font color=gray>'._('Currency Symbol').'</TD><TD '.$TDright.'><INPUT type=text name=values[system][CURRENCY] value="'.SystemPreferences('CURRENCY', 'system', true).'" maxlength=1 size=1></TD></TR>';
/*	        echo '<TR  '.$alternate_row_color.'><TD colspan=2  background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 style="border-width:1px;border-color:gray;border-style:none solid none solid;background-repeat:repeat-x;" valign=top align='.CENTER.'><font color=black></TR>';*/

		echo '<TR  '.$alternate_row_color.'><TD '.$TDleft.' valign=top><BR><font color=gray>'._('Default City').'</TD><TD '.$TDright.'><INPUT type=text name=values[system][DEFAULT_CITY] value="'.SystemPreferences('DEFAULT_CITY', 'system', true).'" maxlength=60 size=20></TD></TR>';
		echo '<TR><TD '.$TDleft.' valign=top><font color=gray>'._('Default State/Area').'</TD><TD '.$TDright.'><INPUT type=text name=values[system][DEFAULT_STATE] value="'.SystemPreferences('DEFAULT_STATE', 'system', true).'" maxlength=10 size=2></TD></TR>';

		echo '<TR  '.$alternate_row_color.'><TD '.$TDleft.' valign=top><font color=gray>'._('Default Zipcode').'</TD><TD '.$TDright.'><INPUT type=text name=values[system][DEFAULT_ZIPCODE] value="'.SystemPreferences('DEFAULT_ZIPCODE', 'system', true).'" maxlength=10 size=5></TD></TR>';
		echo '<TR><TD '.$TDleft.' valign=top><font color=gray>'._('Default Area Code').'</TD><TD '.$TDright.'><INPUT type=text name=values[system][DEFAULT_AREACODE] value="'.SystemPreferences('DEFAULT_AREACODE', 'system', true).'" maxlength=10 size=4></TD></TR>';
/*		echo '<TR  '.$alternate_row_color.'><TD colspan=2  background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 style="border-width:1px;border-color:gray;border-style:none solid none solid;background-repeat:repeat-x;" valign=top align='.CENTER.'><font color=black></TR>';*/

		echo '<TR  '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][BUS_ADDRESSES] id=values[system][BUS_ADDRESSES] value=Y'.((SystemPreferences('BUS_ADDRESSES', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][BUS_ADDRESSES]>'._('Use Bus Addresses').'</label></TD></TR>';
		echo '<TR><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][MAILING_ADDRESSES] id=values[system][MAILING_ADDRESSES] value=Y'.((SystemPreferences('MAILING_ADDRESSES', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][MAILING_ADDRESSES]>'._('Use Mailing Addresses').'</label></TD></TR>';
		echo '<TR  '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][USE_KLADR] id=values[system][USE_KLADR] value=Y'.((SystemPreferences('USE_KLADR', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][USE_KLADR]>'._('Use KLADR (Only for Russia)').'</label></TD></TR>';
		echo '<TR><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][GUARDIANS] id=values[system][GUARDIANS] value=Y'.((SystemPreferences('GUARDIANS', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][GUARDIANS]>'._('Use Parents/Guardians/Emergency Contacts').'</label></TD></TR>';
		echo '<TR  '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][AUTO_STUDENT_USERNAMES] id=values[system][AUTO_STUDENT_USERNAMES] value=Y'.((SystemPreferences('AUTO_STUDENT_USERNAMES', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][AUTO_STUDENT_USERNAMES]>'._('Automatically Generate Student Usernames').'</label></TD></TR>';
/*		echo '<TR><TD colspan=2  background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 style="border-width:1px;border-color:gray;border-style:none solid none solid;background-repeat:repeat-x;" valign=top align='.CENTER.'><font color=black></TR>';*/

		echo '<tr><TD '.$TDleft.' valign=top><font color=gray>'._('Comments for the posted grades').'</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][SHORT_COMMENTS_PER_COURSE] id=values[system][SHORT_COMMENTS_PER_COURSE] value=Y'.((SystemPreferences('SHORT_COMMENTS_PER_COURSE', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][SHORT_COMMENTS_PER_COURSE]>'._('Short Comments Per Course').'</label></TD></tr>';

    	echo '<tr  '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][ONE_LONGER_COMMENT_PER_COURSE] id=values[system][ONE_LONGER_COMMENT_PER_COURSE] value=Y'.((SystemPreferences('ONE_LONGER_COMMENT_PER_COURSE', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][ONE_LONGER_COMMENT_PER_COURSE]>'._('Long Comment Per Course').'</label></TD></tr>';
    	echo '<tr><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][ONE_LONGER_COMMENT_PER_STUDENT] id=values[system][ONE_LONGER_COMMENT_PER_STUDENT] value=Y'.((SystemPreferences('ONE_LONGER_COMMENT_PER_STUDENT', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][ONE_LONGER_COMMENT_PER_STUDENT]>'._('Long Comment Per Student').'</label></TD></tr>';

    	echo '<tr  '.$alternate_row_color.'><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][COMMENTS_CONDUCT] id=values[system][COMMENTS_CONDUCT] value=Y'.((SystemPreferences('COMMENTS_CONDUCT', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][COMMENTS_CONDUCT]>'._('Comment on Student\'s Conduct').'</label></TD></tr>';
    	echo '<tr><TD '.$TDleft.'>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][CALC_GPA_AUTOMATICALLY] id=values[system][CALC_GPA_AUTOMATICALLY] value=Y'.((SystemPreferences('CALC_GPA_AUTOMATICALLY', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][CALC_GPA_AUTOMATICALLY]>'._('Calculate GPA Automatically').'</label></TD></tr>';

    	$options = '';
		for($i=0;$i<=10;$i++)
		{
			if(SystemPreferences('ROUND_GPA_POINTS', 'system', true)==$i)
				$selected = ' SELECTED';
			else
				$selected = '';
			$options .= '<OPTION value='.$i.$selected.'>'.$i.'</option>';
		}
        echo '<tr ><TD '.$TDleft.' valign=top><label for=values[system][ROUND_GPA_POINTS]><font color=gray>'._('Round GPA to X Decimal Points').'</font></label></TD><TD '.$TDright.'><SELECT name=values[system][ROUND_GPA_POINTS] id=values[system][ROUND_GPA_POINTS]>'.$options.'</SELECT></TD></tr>';
    	
        $options = '';
		for($i=0;$i<=10;$i++)
		{
			if(SystemPreferences('ROUND_AVERAGE_POINTS', 'system', true)==$i)
				$selected = ' SELECTED';
			else
				$selected = '';
			$options .= '<OPTION value='.$i.$selected.'>'.$i.'</option>';
		}
        
        echo '<tr  '.$alternate_row_color.'><TD '.$TDleft.'><label for=values[system][ROUND_AVERAGE_POINTS]><font color=gray>'._('Round Average to X Decimal Points').'</font></label></TD><TD '.$TDright.'><SELECT name=values[system][ROUND_AVERAGE_POINTS] id=values[system][ROUND_AVERAGE_POINTS]>'.$options.'</SELECT></TD></tr>';
/*	echo '<TR><TD colspan=2 background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 style="border-width:1px;border-color:gray;border-style:none solid none solid;background-repeat:repeat-x;" valign=top align='.CENTER.'><font color=black><b>'._('Prefix & Suffix in Name').'</b></TR>';*/
	
        echo '<tr><TD colspan=2 >';
		if($_REQUEST['tables']['SYSTEM_CONFIG'])
		{
			foreach($_REQUEST['tables']['SYSTEM_CONFIG'] as $suffix_id=>$data)
			{
				if($suffix_id == 'new')	
				{
					$fields = $values = '';
					foreach($data as $key=>$value)
					{
						$go = true;
						if($key && $value)
						{
							if($key!='ID')
								$fields .= $key.",";
							else
								$fields .= "VALUE,";
							$values .= "'".$value."',";
						}else{
							$go = false;
						}
						$sql = "INSERT INTO SYSTEM_CONFIG (SCHOOL_ID,PROGRAM,TITLE,VALUE) values(".get_school_id().",'system','".$key."',".substr($values,0,-1).")";
						if($go)
							db_execute($sql);
					}
				}else{
					$sql = "UPDATE SYSTEM_CONFIG SET ";
					foreach($data as $key=>$value)
					{
						$go = true;
						if($key && $value)
						{
							if($key!='ID')
								$sql .= "VALUE='".str_replace("'","''",$value)."',";
							else
								$sql .= $key."='".str_replace("'","''",$value)."',";
						}else{
							$go = false;
						}
						$sql = substr($sql,0,-1)." WHERE VALUE='".$suffix_id."' AND TITLE='".$key."'";
						if($go)
							db_execute($sql);
					}
				}
			}
		}
        $sql = "SELECT VALUE AS NAME_SUFFIX,VALUE AS ID FROM SYSTEM_CONFIG WHERE PROGRAM='system' AND TITLE='NAME_SUFFIX'";
		$QI = db_execute($sql);
    
		$array = db_request($QI,array('NAME_SUFFIX'=>'_makePrefixInput'));
		$columns = array('NAME_SUFFIX'=>_('Name of Student Suffix'));
		
		$link['add']['html'] = array('NAME_SUFFIX'=>_makePrefixInput('','NAME_SUFFIX'));
		$link['remove']['link'] = "modloader.php?servicemod=$_REQUEST[servicemod]&servicefunction=remove&table=SYSTEM_CONFIG";
		$link['remove']['variables'] = array('id'=>'ID');
		
		Gridoutput($array,$columns,_('Student Suffixes'),_('Amount of Student Suffixes'),$link,array(),array('download'=>false,'search'=>false,'xscroll'=>false));

        $sql = "SELECT VALUE AS NAME_TITLE,VALUE AS ID FROM SYSTEM_CONFIG WHERE PROGRAM='system' AND TITLE='NAME_TITLE'";
		$QI = db_execute($sql);
		$array = db_request($QI,array('NAME_TITLE'=>'_makePrefixInput'));
		$columns = array('NAME_TITLE'=>_('Title of User Prefix'));
		
		$link['add']['html'] = array('NAME_TITLE'=>_makePrefixInput('','NAME_TITLE'));
		$link['remove']['link'] = "modloader.php?servicemod=$_REQUEST[servicemod]&servicefunction=remove&table=SYSTEM_CONFIG";
		$link['remove']['variables'] = array('id'=>'ID');
		
		Gridoutput($array,$columns,_('Prefix Titles'),_('Amount of Prefix Titles'),$link,array(),array('download'=>false,'search'=>false,'xscroll'=>false));
        echo '</TD></TR>';
        echo '<tr><td><INPUT type=checkbox name=values[system][USE_SUFFIX] id=values[system][USE_SUFFIX] value=Y'.((SystemPreferences('USE_SUFFIX', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][USE_SUFFIX]>'._('Use Suffixes for Students').'</label></td><td><INPUT type=checkbox name=values[system][USE_PREFIX] id=values[system][USE_PREFIX] value=Y'.((SystemPreferences('USE_PREFIX', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][USE_PREFIX]>'._('Use Prefixes for Users').'</label></td></tr>';
        echo '<tr><td COLSPAN=2><INPUT type=checkbox name=values[system][APPLY_MODE] id=values[system][APPLY_MODE] value=Y'.((SystemPreferences('APPLY_MODE', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][APPLY_MODE]>'._('Online application mode').'</label></td></tr>';
        //APPLY_MODE

	echo '</TABLE>';
	}
	elseif($_REQUEST['system_tab']=='default_user')
	{
		$old_preferences = $_SYSTEM['Preferences'];
		foreach($_SYSTEM['Preferences']['Preferences'] as $item=>$value)
			$_SYSTEM['Preferences']['Preferences'][$item][1]['VALUE'] = SystemPreferences($item,'Preferences');
		if(!$_SYSTEM['Preferences']['Gradebook']) $_SYSTEM['Preferences']['Gradebook'] = array();
		foreach($_SYSTEM['Preferences']['Gradebook'] as $item=>$value)
			$_SYSTEM['Preferences']['Gradebook'][$item][1]['VALUE'] = SystemPreferences($item,'Gradebook');
		
		include($staticpath.'modules/mod_users/UsrPrefnProper.php');
		$_SYSTEM['Preferences'] = $old_preferences;
	}
	elseif($_REQUEST['system_tab']=='default_gradebook')
	{
		include($staticpath.'modules/mod_grades/GrdBookConfiguration.php');		
	}
	elseif($_REQUEST['system_tab']=='database_backup_download')
	{
		echo '<FORM action=modloader.php?servicemod='.$_REQUEST['servicemod'].'&servicefunction=backup&CREATEPDF=true method=POST>';
		echo _('Download the copy of database to the disk in case of system failure');
		echo '<BR><BR>';
		echo '<CENTER><INPUT type=submit value="'._('Download Database File').'"></CENTER>';
		echo '</FORM>';
	}
	elseif($_REQUEST['system_tab']=='school_prefs')
	{
		echo '<TABLE cellspacing=0 cellpadding=2 width=100%>';
		echo "<tr><td colspan=2><font color=black>"._("Here you can change settings for the current school.  <br>By default, each school has settings from the \"Default School Preferences\" tab.  <br>You can change any Default School Preferences by unchecking the default in the column \"Default Preferences\".")."</font></td><td valign=top></td></tr>";
		echo "<tr><td>&nbsp;</td></tr>";
		$options = '';
		for($i=0;$i<=20;$i++)
		{
			if(SystemPreferences('VIEW_PAST_STUDENT_ATTENDANCE_DAYS')==$i)
				$selected = ' SELECTED';
			else
				$selected = '';
			$options .= '<OPTION value='.$i.$selected.'>'.$i.' ';
			if($i==1)
				$options .= _('day');
			else
				$options .= _('days');
		}
	        $checked = IsSystemDefaultPreference('VIEW_PAST_STUDENT_ATTENDANCE_DAYS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";

/*		echo '<TR><TD colspan=2  style="border-width:1px;border-color:gray;border-style:solid none none solid;background-repeat:repeat-x;" valign=top align='.CENTER.' background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 ><font color=black><b>'._('Current preferences').'</b><td style="border-width:1px;border-color:gray;border-style:solid solid none solid;background-repeat:repeat-x;" valign=top align='.CENTER.' background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 ><font color=black><b>'._('Default preferences').'</b></td></TR>';*/
		echo '<TR '.$alternate_row_color.'><TD style="border-width:1px;border-color:gray;border-style:solid none none solid;" valign=top align='.ALIGN_LEFT.'><br><font color=gray>'._('How many the previous days\'<BR>attendance can teachers view').'</TD><TD style="border-width:1px;border-color:gray;border-style:solid none none none;"><SELECT '.$disabled.' name=values[system][VIEW_PAST_STUDENT_ATTENDANCE_DAYS] id=values[system][VIEW_PAST_STUDENT_ATTENDANCE_DAYS]>'.$options.'</SELECT></TD><td style="border-width:1px;border-color:gray;border-style:solid solid none solid;"><br><input '.$checked.' type=checkbox name=override[system][VIEW_PAST_STUDENT_ATTENDANCE_DAYS] onclick="enable_input(\'values[system][VIEW_PAST_STUDENT_ATTENDANCE_DAYS]\', this)" id=VIEW_PAST_STUDENT_ATTENDANCE_DAYS /><label for="VIEW_PAST_STUDENT_ATTENDANCE_DAYS">'.SystemPreferences('VIEW_PAST_STUDENT_ATTENDANCE_DAYS','system',true).' '._('days').'</label></td></TR>';

		$options = '';
		for($i=0;$i<=20;$i++)
		{
			if(SystemPreferences('EDIT_PAST_STUDENT_ATTENDANCE_DAYS')==$i)
				$selected = ' SELECTED';
			else
				$selected = '';
			$options .= '<OPTION value='.$i.$selected.'>'.$i.' ';
			if($i==1)
				$options .= _('day');
			else
				$options .= _('days');
		}
    	
		$checked = IsSystemDefaultPreference('EDIT_PAST_STUDENT_ATTENDANCE_DAYS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
		echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><font color=gray>'._('How many the previous days\'<BR>attendance can teachers modify').'</TD><TD><SELECT '.$disabled.' name=values[system][EDIT_PAST_STUDENT_ATTENDANCE_DAYS] id=values[system][EDIT_PAST_STUDENT_ATTENDANCE_DAYS]>'.$options.'</SELECT></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][EDIT_PAST_STUDENT_ATTENDANCE_DAYS] onclick="enable_input(\'values[system][EDIT_PAST_STUDENT_ATTENDANCE_DAYS]\', this)" id=EDIT_PAST_STUDENT_ATTENDANCE_DAYS /><label for="EDIT_PAST_STUDENT_ATTENDANCE_DAYS">'.SystemPreferences('EDIT_PAST_STUDENT_ATTENDANCE_DAYS','system',true).' '._('days').'</label></td></TR>';

		$checked = IsSystemDefaultPreference('MIN_FULLDAY') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
		echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><font color=gray>'._('How many minimum minutes a student<BR>has to attend to count as full-day present').'</TD><TD><INPUT '.$disabled.' type=text name=values[system][MIN_FULLDAY] id=values[system][MIN_FULLDAY] value="'.SystemPreferences('MIN_FULLDAY').'" maxlength=5 size=3></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][MIN_FULLDAY] onclick="enable_input(\'values[system][MIN_FULLDAY]\', this)" id=MIN_FULLDAY /><label for="MIN_FULLDAY">'.SystemPreferences('MIN_FULLDAY','system', true).' '._('minutes').'</label></td></TR>';

		$checked = IsSystemDefaultPreference('MIN_HALFDAY') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
		echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><font color=gray>'._('How many minimum minutes a student<BR>has to attend to count as half-day present').'</TD><TD><INPUT '.$disabled.' type=text name=values[system][MIN_HALFDAY] id=values[system][MIN_HALFDAY] value="'.SystemPreferences('MIN_HALFDAY').'" maxlength=5 size=3></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][MIN_HALFDAY] onclick="enable_input(\'values[system][MIN_HALFDAY]\', this)" id=MIN_HALFDAY /><label for="MIN_HALFDAY">'.SystemPreferences('MIN_HALFDAY','system', true).' '._('minutes').'</label></td></TR>';

		$checked = IsSystemDefaultPreference('EDIT_ATTENDANCE_AFTER_SAVE') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR '.$alternate_row_color.'><TD style="border-width:1px;border-color:gray;border-style:none none solid solid;">&nbsp</TD><TD style="border-width:1px;border-color:gray;border-style:none none solid none;"><INPUT '.$disabled.' type=checkbox id=values[system][EDIT_ATTENDANCE_AFTER_SAVE] name=values[system][EDIT_ATTENDANCE_AFTER_SAVE] value=Y'.((SystemPreferences('EDIT_ATTENDANCE_AFTER_SAVE')=='Y')?' CHECKED':'').'><label for=values[system][EDIT_ATTENDANCE_AFTER_SAVE]>'._('Allow teachers to modify attendance after pressing "Save"').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid solid solid;"><input '.$checked.' type=checkbox name=override[system][EDIT_ATTENDANCE_AFTER_SAVE] onclick="enable_input(\'values[system][EDIT_ATTENDANCE_AFTER_SAVE]\', this)" id=EDIT_ATTENDANCE_AFTER_SAVE /><label for="EDIT_ATTENDANCE_AFTER_SAVE">'.(SystemPreferences('EDIT_ATTENDANCE_AFTER_SAVE','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';
		//frame
	    	/*	echo '<TR background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 ><TD colspan=2  style="border-width:1px;border-color:gray;border-style:solid none none solid;" valign=top align='.CENTER.'><font color=black><td style="border-width:1px;border-color:gray;border-style:solid solid none solid;" valign=top align='.CENTER.'><font color=black></td></TR>';*/

		$checked = IsSystemDefaultPreference('REPORT_CARD') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
		echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><BR><font color=gray>'._('Report Card. Type of Visibility').'</TD><TD style="border-width:1px;border-color:gray;border-style:none none none none;"><BR><INPUT '.$disabled.' type=radio name=values[system][REPORT_CARD] id="values[system][REPORT_CARD]1" value="both"'.((SystemPreferences('REPORT_CARD')=='both')?' CHECKED':'').'><label for=values[system][REPORT_CARD]1>'._('Percent & Letter/Digit Grade').'</label><INPUT '.$disabled.' type=radio name=values[system][REPORT_CARD] id=values[system][REPORT_CARD]2 value=grade'.((SystemPreferences('REPORT_CARD')=='grade')?' CHECKED':'').'><label for=values[system][REPORT_CARD]2>'._('Letter/Digit Grade').'</label><INPUT '.$disabled.' type=radio name=values[system][REPORT_CARD] id=values[system][REPORT_CARD]3 value=percent'.((SystemPreferences('REPORT_CARD')=='percent')?' CHECKED':'').'><label for=values[system][REPORT_CARD]3>'._('Percent').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><br><input '.$checked.' type=checkbox name=override[system][REPORT_CARD] onclick="enable_input(\'values[system][REPORT_CARD]1\', this);enable_input(\'values[system][REPORT_CARD]2\',this);enable_input(\'values[system][REPORT_CARD]3\',this)" id=REPORT_CARD /><label for="REPORT_CARD">'.(SystemPreferences('REPORT_CARD','system', true)=='both'?_('Percent &amp; Letter/Digit Grade'): (SystemPreferences('REPORT_CARD','system', true)=='grade'?_("Letter/Digit Grade"):_("Percent"))).'</label></td></TR>';
		$checked = IsSystemDefaultPreference('FINAL_EXAMS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";

	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][FINAL_EXAMS] id=values[system][FINAL_EXAMS] value=Y'.((SystemPreferences('FINAL_EXAMS')=='Y')?' CHECKED':'').'><label for=values[system][FINAL_EXAMS]>'._('Use Final Semester Exams').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][FINAL_EXAMS] onclick="enable_input(\'values[system][FINAL_EXAMS]\', this)" id=FINAL_EXAMS /><label for="FINAL_EXAMS">'.(SystemPreferences('FINAL_EXAMS','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('FY_EXAMS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";

	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][FY_EXAMS] id=values[system][FY_EXAMS] value=Y'.((SystemPreferences('FY_EXAMS')=='Y')?' CHECKED':'').'><label for=values[system][FY_EXAMS]>'._('Use Full Year Exams').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][FY_EXAMS] onclick="enable_input(\'values[system][FY_EXAMS]\', this)" id=FY_EXAMS /><label for="FY_EXAMS">'.(SystemPreferences('FY_EXAMS','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('QTR_EXAMS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][QTR_EXAMS] id=values[system][QTR_EXAMS] value=Y'.((SystemPreferences('QTR_EXAMS')=='Y')?' CHECKED':'').'><label for=values[system][QTR_EXAMS]>'._('Use Quarter Exams').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][QTR_EXAMS] onclick="enable_input(\'values[system][QTR_EXAMS]\', this)" id=QTR_EXAMS /><label for="QTR_EXAMS">'.(SystemPreferences('QTR_EXAMS','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('OVERRIDE_SCORE_BREAKOFFS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][OVERRIDE_SCORE_BREAKOFFS] id=values[system][OVERRIDE_SCORE_BREAKOFFS] value=Y'.((SystemPreferences('OVERRIDE_SCORE_BREAKOFFS')=='Y')?' CHECKED':'').'><label for=values[system][OVERRIDE_SCORE_BREAKOFFS]>'._('Allow teachers to change grading scale score breakoffs').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][OVERRIDE_SCORE_BREAKOFFS] onclick="enable_input(\'values[system][OVERRIDE_SCORE_BREAKOFFS]\', this);" id=OVERRIDE_SCORE_BREAKOFFS /><label for="OVERRIDE_SCORE_BREAKOFFS">'.(SystemPreferences('OVERRIDE_SCORE_BREAKOFFS','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('OVERRIDE_SEMESTER_GRADE_WEIGHTS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][OVERRIDE_SEMESTER_GRADE_WEIGHTS] id=values[system][OVERRIDE_SEMESTER_GRADE_WEIGHTS] value=Y'.((SystemPreferences('OVERRIDE_SEMESTER_GRADE_WEIGHTS')=='Y')?' CHECKED':'').'><label for=values[system][OVERRIDE_SEMESTER_GRADE_WEIGHTS]>'._('Allow teachers to change semester grade calculation weights').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][OVERRIDE_SEMESTER_GRADE_WEIGHTS] onclick="enable_input(\'values[system][OVERRIDE_SEMESTER_GRADE_WEIGHTS]\', this)" id=OVERRIDE_SEMESTER_GRADE_WEIGHTS /><label for="OVERRIDE_SEMESTER_GRADE_WEIGHTS">'.(SystemPreferences('OVERRIDE_SEMESTER_GRADE_WEIGHTS','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('DEFAULT_CREDITS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><font color=gray>'._('Default Credits').'</TD><TD><INPUT '.$disabled.' type=text name=values[system][DEFAULT_CREDITS] id=values[system][DEFAULT_CREDITS] value="'.SystemPreferences('DEFAULT_CREDITS').'" maxlength=10 size=2></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][DEFAULT_CREDITS] onclick="enable_input(\'values[system][DEFAULT_CREDITS]\', this)" id=DEFAULT_CREDITS /><label for="DEFAULT_CREDITS">'.SystemPreferences('DEFAULT_CREDITS','system', true).' '._('credits').'</label></td></TR>';

		$checked = IsSystemDefaultPreference('WEIGHTED_GPA') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD style="border-style:none none none none;border-width:1px;border-color:gray;"><INPUT '.$disabled.' type=checkbox name=values[system][WEIGHTED_GPA] id=values[system][WEIGHTED_GPA] value=Y'.((SystemPreferences('WEIGHTED_GPA')=='Y')?' CHECKED':'').'><label for=values[system][WEIGHTED_GPA]>'._('Use Weighted GPA').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][WEIGHTED_GPA] onclick="enable_input(\'values[system][WEIGHTED_GPA]\', this)" id=WEIGHTED_GPA /><label for="WEIGHTED_GPA">'.(SystemPreferences('WEIGHTED_GPA','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

	        $checked = IsSystemDefaultPreference('GPA_POINTS_OR_PERCENT_GRADE') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=middle align='.ALIGN_LEFT.'><font color=gray>'._('Use GPA points or Percent Grade for calculation Class Rating').'</TD><TD><INPUT '.$disabled.' type=radio name=values[system][GPA_POINTS_OR_PERCENT_GRADE] id=values[system][GPA_POINTS_OR_PERCENT_GRADE]1 value="GPA_POINTS"'.((SystemPreferences('GPA_POINTS_OR_PERCENT_GRADE')=='GPA_POINTS')?' CHECKED':'').'><label for=values[system][GPA_POINTS_OR_PERCENT_GRADE]1>'._('GPA points').'</label><INPUT '.$disabled.' type=radio name=values[system][GPA_POINTS_OR_PERCENT_GRADE] id=values[system][GPA_POINTS_OR_PERCENT_GRADE]2 value="PERCENT_GRADE"'.((SystemPreferences('GPA_POINTS_OR_PERCENT_GRADE')=='PERCENT_GRADE')?' CHECKED':'').'><label for=values[system][GPA_POINTS_OR_PERCENT_GRADE]2>'._('Percent Grade').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][GPA_POINTS_OR_PERCENT_GRADE] onclick="enable_input(\'values[system][GPA_POINTS_OR_PERCENT_GRADE]1\', this);enable_input(\'values[system][GPA_POINTS_OR_PERCENT_GRADE]2\',this);" id=GPA_POINTS_OR_PERCENT_GRADE /><label for="GPA_POINTS_OR_PERCENT_GRADE">'.(SystemPreferences('GPA_POINTS_OR_PERCENT_GRADE','system', true)=='GPA_POINTS'?_("GPA points"):_("Percent Grade")).'</label></td></TR>';

	        $checked = IsSystemDefaultPreference('FORMULA') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=middle align='.ALIGN_LEFT.'><font color=gray>'._('How to calculate final grade using gradebook').'</TD><TD><INPUT '.$disabled.' type=radio name=values[system][FORMULA] id=values[system][FORMULA]1 value="WPOINT"'.((SystemPreferences('FORMULA')=='WPOINT')?' CHECKED':'').'><label for=values[system][FORMULA]1>Fg=E(student_points / assignment_points) * category_weight</label><BR><INPUT '.$disabled.' type=radio name=values[system][FORMULA] id=values[system][FORMULA]2 value="WAVGGRD"'.((SystemPreferences('FORMULA')=='WAVGGRD')?' CHECKED':'').'><label for=values[system][FORMULA]2>Fg=E(Ri*Ki</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][FORMULA] onclick="enable_input(\'values[system][FORMULA]1\', this);enable_input(\'values[system][FORMULA]2\',this);" id=FORMULA /><label for="FORMULA">'.(SystemPreferences('FORMULA','system', true)=='WPOINT'?_("Fg=E(student_points / assignment_points) * category_weight"):_("Fg=E(Ri*Ki)")).'</label></td></TR>';
        
	        $checked = IsSystemDefaultPreference('USE_CREDITS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD style="border-style:none none none none;border-width:1px;border-color:gray;"><INPUT '.$disabled.' type=checkbox name=values[system][USE_CREDITS] id=values[system][USE_CREDITS] value=Y'.((SystemPreferences('USE_CREDITS')=='Y')?' CHECKED':'').'><label for=values[system][USE_CREDITS]>'._('Use Credits').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][USE_CREDITS] onclick="enable_input(\'values[system][USE_CREDITS]\', this)" id=USE_CREDITS /><label for="USE_CREDITS">'.(SystemPreferences('USE_CREDITS','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('WEIGHTS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][WEIGHTS] id=values[system][WEIGHTS] value=Y'.((SystemPreferences('WEIGHTS')=='Y')?' CHECKED':'').'><label for=values[system][WEIGHTS]>'._('Use Course Weights').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][WEIGHTS] onclick="enable_input(\'values[system][WEIGHTS]\', this)" id=WEIGHTS /><label for="WEIGHTS">'.(SystemPreferences('WEIGHTS','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

	        $checked = IsSystemDefaultPreference('USE_REQUESTS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD style="border-style:none none none none;border-width:1px;border-color:gray;"><INPUT '.$disabled.' type=checkbox name=values[system][USE_REQUESTS] id=values[system][USE_REQUESTS] value=Y'.((SystemPreferences('USE_REQUESTS')=='Y')?' CHECKED':'').'><label for=values[system][USE_REQUESTS]>'._('Use Course Requests').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][USE_REQUESTS] onclick="enable_input(\'values[system][USE_REQUESTS]\', this)" id=USE_REQUESTS /><label for="USE_REQUESTS">'.(SystemPreferences('USE_REQUESTS','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';
        
	        $checked = IsSystemDefaultPreference('USE_BLOCKS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD style="border-style:none none none none;border-width:1px;border-color:gray;"><INPUT '.$disabled.' type=checkbox name=values[system][USE_BLOCKS] id=values[system][USE_BLOCKS] value=Y'.((SystemPreferences('USE_BLOCKS')=='Y')?' CHECKED':'').'><label for=values[system][USE_BLOCKS]>'._('Use Blocks').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none none none solid;"><input '.$checked.' type=checkbox name=override[system][USE_BLOCKS] onclick="enable_input(\'values[system][USE_BLOCKS]\', this)" id=USE_BLOCKS /><label for="USE_BLOCKS">'.(SystemPreferences('USE_BLOCKS','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('DISPLAY_GPA') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][DISPLAY_GPA] id=values[system][DISPLAY_GPA] value=Y'.((SystemPreferences('DISPLAY_GPA')=='Y')?' CHECKED':'').'><label for=values[system][DISPLAY_GPA]>'._('Display GPA points in Final Grades Report').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][DISPLAY_GPA] onclick="enable_input(\'values[system][DISPLAY_GPA]\', this)" id=DISPLAY_GPA /><label for="DISPLAY_GPA">'.(SystemPreferences('DISPLAY_GPA','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';
        
		//frame
		/*		echo '<TR background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 ><TD colspan=2  style="border-width:1px;border-color:gray;border-style:solid none none solid;background-repeat:repeat-x;" valign=top align='.CENTER.'><font color=black><td style="border-width:1px;border-color:gray;border-style:solid solid none solid;" valign=top align='.CENTER.'><font color=black></td></TR>';*/
    
	        $checked = IsSystemDefaultPreference('SCHOOL_YEAR_TITLE') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><br><font color=gray>'._('School Year Title').'</TD><TD><br><INPUT '.$disabled.' type=radio name=values[system][SCHOOL_YEAR_TITLE] id=values[system][SCHOOL_YEAR_TITLE]1 value="YYYY-YYYY"'.((SystemPreferences('SCHOOL_YEAR_TITLE')=='YYYY-YYYY')?' CHECKED':'').'><label for=values[system][SCHOOL_YEAR_TITLE]1>'.get_school_year().'-'.(get_school_year()+1).'</label><INPUT '.$disabled.' type=radio name=values[system][SCHOOL_YEAR_TITLE] id=values[system][SCHOOL_YEAR_TITLE]2 value=YYYY'.((SystemPreferences('SCHOOL_YEAR_TITLE')=='YYYY')?' CHECKED':'').'><label for=values[system][SCHOOL_YEAR_TITLE]2>'.get_school_year().'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><br><input '.$checked.' type=checkbox name=override[system][SCHOOL_YEAR_TITLE] onclick="enable_input(\'values[system][SCHOOL_YEAR_TITLE]1\', this);enable_input(\'values[system][SCHOOL_YEAR_TITLE]2\',this);" id=SCHOOL_YEAR_TITLE /><label for="SCHOOL_YEAR_TITLE">'.(SystemPreferences('SCHOOL_YEAR_TITLE','system', true)=='YYYY-YYYY'?get_school_year().'-'.(get_school_year()+1):get_school_year()).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('VARIABLE_PERIOD_LENGTH') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][VARIABLE_PERIOD_LENGTH] id=values[system][VARIABLE_PERIOD_LENGTH] value=Y'.((SystemPreferences('VARIABLE_PERIOD_LENGTH')=='Y')?' CHECKED':'').'><label for=values[system][VARIABLE_PERIOD_LENGTH]>'._('Period lengths depends on the day of the week').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][VARIABLE_PERIOD_LENGTH] onclick="enable_input(\'values[system][VARIABLE_PERIOD_LENGTH]\', this)" id=VARIABLE_PERIOD_LENGTH /><label for="VARIABLE_PERIOD_LENGTH">'.(SystemPreferences('VARIABLE_PERIOD_LENGTH','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		//even weeks
		$checked = IsSystemDefaultPreference('ODD_EVEN_WEEKS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][ODD_EVEN_WEEKS] id=values[system][ODD_EVEN_WEEKS] value=Y'.((SystemPreferences('ODD_EVEN_WEEKS')=='Y')?' CHECKED':'').'><label for=values[system][ODD_EVEN_WEEKS]>'._('Use Even-numbered/odd-numbered weeks').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][ODD_EVEN_WEEKS] onclick="enable_input(\'values[system][ODD_EVEN_WEEKS]\', this)" id=ODD_EVEN_WEEKS /><label for="ODD_EVEN_WEEKS">'.(SystemPreferences('ODD_EVEN_WEEKS','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';
	//	echo '<TR><TD '.$TDleft.' valign=top><font color=gray>&nbsp;</TD><TD '.$TDright.'><INPUT type=checkbox name=values[system][ODD_EVEN_WEEKS] onclick="change_wstate();" id=values[system][ODD_EVEN_WEEKS] value=Y'.((SystemPreferences('ODD_EVEN_WEEKS', 'system', true)=='Y')?' CHECKED':'').'><label for=values[system][ODD_EVEN_WEEKS]>'._('Use Even-numbered/odd-numbered weeks').'</label></TD></TR>';
		if(!SystemPreferences('WEEKSFROM', 'system', true))
		{
		    $weeksdate = date("Y")."-01-01";
		}
		else
		    $weeksdate = SystemPreferences('WEEKSFROM', 'system', true);
/*		    
		    if(SystemPreferences('ODD_EVEN_WEEKS', 'system', true)=='Y')
			    $wdisable = 'ENABLED';
		    else
			    $wdisable = 'DISABLED';
*/		    

	        $checked = IsSystemDefaultPreference('WEEKSFROM') ? "checked" : ""; $disabled = $checked ? " disabled " : "";

	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><font color=gray>'._('Count weeks from').'</TD><TD><INPUT '.$disabled.' type=text name=values[system][WEEKSFROM] id=values[system][WEEKSFROM] value="'.SystemPreferences('WEEKSFROM').'" maxlength=12 size=12></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][WEEKSFROM] onclick="enable_input(\'values[system][WEEKSFROM]\', this)" id=WEEKSFROM /><label for="WEEKSFROM">'.SystemPreferences('WEEKSFROM','system', true).' '.'</label></td></TR>';

		$checked = IsSystemDefaultPreference('STUDENTS_CAN_SCHEDULE') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][STUDENTS_CAN_SCHEDULE] id=values[system][STUDENTS_CAN_SCHEDULE] value=Y'.((SystemPreferences('STUDENTS_CAN_SCHEDULE')=='Y')?' CHECKED':'').'><label for=values[system][STUDENTS_CAN_SCHEDULE]>'._('Allow students to enroll themselves in classes').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][STUDENTS_CAN_SCHEDULE] onclick="enable_input(\'values[system][STUDENTS_CAN_SCHEDULE]\', this)" id=STUDENTS_CAN_SCHEDULE /><label for="STUDENTS_CAN_SCHEDULE">'.(SystemPreferences('STUDENTS_CAN_SCHEDULE','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('STUDENTS_CAN_REQUEST') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][STUDENTS_CAN_REQUEST] id=values[system][STUDENTS_CAN_REQUEST] value=Y'.((SystemPreferences('STUDENTS_CAN_REQUEST')=='Y')?' CHECKED':'').'><label for=values[system][STUDENTS_CAN_REQUEST]>'._('Allow students to request classes').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][STUDENTS_CAN_REQUEST] onclick="enable_input(\'values[system][STUDENTS_CAN_REQUEST]\', this)" id=STUDENTS_CAN_REQUEST /><label for="STUDENTS_CAN_REQUEST">'.(SystemPreferences('STUDENTS_CAN_REQUEST','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('SHOW_STUDENTS_BY') ? "checked" : ""; $disabled = $checked ? " disabled " : "";

		echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none solid solid;" align='.ALIGN_RIGHT.'><font color=gray>'._('Display the list of students by:').'</TD><TD style="border-width:1px;border-color:gray;border-style:none none solid none;"><INPUT '.$disabled.' type=radio name=values[system][SHOW_STUDENTS_BY] id=values[system][SHOW_STUDENTS_BY]1 value="25"'.((SystemPreferences('SHOW_STUDENTS_BY')=='25')?' CHECKED':'').'><label for=values[system][SHOW_STUDENTS_BY]1>'._('25 lines').'</label><INPUT '.$disabled.' type=radio name=values[system][SHOW_STUDENTS_BY] id=values[system][SHOW_STUDENTS_BY]2 value=50'.((SystemPreferences('SHOW_STUDENTS_BY')=='50')?' CHECKED':'').'><label for=values[system][SHOW_STUDENTS_BY]2>'._('50 lines').'</label><INPUT '.$disabled.' type=radio name=values[system][SHOW_STUDENTS_BY] id=values[system][SHOW_STUDENTS_BY]3 value=00'.((SystemPreferences('SHOW_STUDENTS_BY')=='00')?' CHECKED':'').'><label for=values[system][SHOW_STUDENTS_BY]3>'._('no limit').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid solid solid;"><br><input '.$checked.' type=checkbox name=override[system][SHOW_STUDENTS_BY] onclick="enable_input(\'values[system][SHOW_STUDENTS_BY]1\', this);enable_input(\'values[system][SHOW_STUDENTS_BY]2\',this);enable_input(\'values[system][SHOW_STUDENTS_BY]3\',this)" id=SHOW_STUDENTS_BY /><label for="SHOW_STUDENTS_BY">'.(SystemPreferences('SHOW_STUDENTS_BY','system', true)=='25'?_('25 lines'): (SystemPreferences('SHOW_STUDENTS_BY','system', true)=='50'?_("50 lines"):_("no limit"))).'</label></td></TR>';	
		//frame
		/*		echo '<TR background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 ><TD colspan=2  style="border-width:1px;border-color:gray;border-style:solid none none solid;background-repeat:repeat-x;" valign=top align='.CENTER.'><font color=black><td style="border-width:1px;border-color:gray;border-style:solid solid none solid;" valign=top align='.CENTER.'><font color=black></td></TR>';*/

		$checked = IsSystemDefaultPreference('DECIMAL') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><br><font color=gray>'._('Decimal Point Character').'</TD><TD><br><INPUT '.$disabled.' type=radio name=values[system][DECIMAL] id=values[system][DECIMAL]1 value="."'.((SystemPreferences('DECIMAL')=='.')?' CHECKED':'').'><label for=values[system][DECIMAL]1>'._('Point (<b>.</b>)').'</label><INPUT '.$disabled.' type=radio name=values[system][DECIMAL] id=values[system][DECIMAL]2 value=","'.((SystemPreferences('DECIMAL')==',')?' CHECKED':'').'><label for=values[system][DECIMAL]2>'._('Comma (<b>,</b>)').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><br><input '.$checked.' type=checkbox name=override[system][DECIMAL] onclick="enable_input(\'values[system][DECIMAL]1\', this);enable_input(\'values[system][DECIMAL]2\',this);" id=DECIMAL /><label for="DECIMAL">'.(SystemPreferences('DECIMAL','system', true)=='.'?_("Point (<b>.</b>)"):_("Comma (<b>,</b>)")).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('CURRENCY') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none solid solid;" valign=top align='.ALIGN_LEFT.'><font color=gray>'._('Currency Symbol').'</TD><TD style="border-width:1px;border-color:gray;border-style:none none solid none;"><INPUT '.$disabled.' type=text name=values[system][CURRENCY] id=values[system][CURRENCY] value="'.SystemPreferences('CURRENCY').'" maxlength=1 size=1></TD><td style="border-width:1px;border-color:gray;border-style:none solid solid solid;"><input '.$checked.' type=checkbox name=override[system][CURRENCY] onclick="enable_input(\'values[system][CURRENCY]\', this)" id=CURRENCY /><label for="CURRENCY">'.(SystemPreferences('CURRENCY','system', true)?SystemPreferences('CURRENCY','system', true):_("Empty")).'</label></td></TR>';
		//frame
		/*		echo '<TR background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 ><TD colspan=2  style="border-width:1px;border-color:gray;border-style:solid none none solid;" valign=top align='.CENTER.'><font color=black><td style="border-width:1px;border-color:gray;border-style:solid solid none solid;" valign=top align='.CENTER.'><font color=black></td></TR>';*/

		$checked = IsSystemDefaultPreference('DEFAULT_CITY') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><BR><font color=gray>'._('Default City').'</TD><TD><BR><INPUT '.$disabled.' type=text name=values[system][DEFAULT_CITY] id=values[system][DEFAULT_CITY] value="'.SystemPreferences('DEFAULT_CITY').'" maxlength=60 size=20></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><BR><input '.$checked.' type=checkbox name=override[system][DEFAULT_CITY] onclick="enable_input(\'values[system][DEFAULT_CITY]\', this)" id=DEFAULT_CITY /><label for="DEFAULT_CITY">'.(SystemPreferences('DEFAULT_CITY','system', true)?SystemPreferences('DEFAULT_CITY','system', true):_("Empty")).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('DEFAULT_STATE') ? "checked" : "";  $disabled = $checked ? " disabled " : "";
	        echo '<TR  BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><font color=gray>'._('Default State/Area').'</TD><TD><INPUT '.$disabled.' type=text name=values[system][DEFAULT_STATE] id=values[system][DEFAULT_STATE] value="'.SystemPreferences('DEFAULT_STATE').'" maxlength=10 size=2></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][DEFAULT_STATE] onclick="enable_input(\'values[system][DEFAULT_STATE]\', this)" id=DEFAULT_STATE /><label for="DEFAULT_STATE">'.(SystemPreferences('DEFAULT_STATE','system', true)?SystemPreferences('DEFAULT_STATE','system', true):_("Empty")).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('DEFAULT_ZIPCODE') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><font color=gray>'._('Default Zipcode').'</TD><TD><INPUT '.$disabled.' type=text name=values[system][DEFAULT_ZIPCODE] id=values[system][DEFAULT_ZIPCODE] value="'.SystemPreferences('DEFAULT_ZIPCODE').'" maxlength=10 size=5></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][DEFAULT_ZIPCODE] onclick="enable_input(\'values[system][DEFAULT_ZIPCODE]\', this)" id=DEFAULT_ZIPCODE /><label for="DEFAULT_ZIPCODE">'.(SystemPreferences('DEFAULT_ZIPCODE','system', true)?SystemPreferences('DEFAULT_ZIPCODE','system', true):_("Empty")).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('DEFAULT_AREACODE') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><font color=gray>'._('Default Area Code').'</TD><TD><INPUT '.$disabled.' type=text name=values[system][DEFAULT_AREACODE] id=values[system][DEFAULT_AREACODE] value="'.SystemPreferences('DEFAULT_AREACODE').'" maxlength=10 size=4></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][DEFAULT_AREACODE] onclick="enable_input(\'values[system][DEFAULT_AREACODE]\', this)" id=DEFAULT_AREACODE /><label for="DEFAULT_AREACODE">'.(SystemPreferences('DEFAULT_AREACODE','system', true)?SystemPreferences('DEFAULT_AREACODE','system', true):_("Empty")).'</label></td></TR>';
		//frame
		/*		echo '<TR background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 ><TD colspan=2  style="border-width:1px;border-color:gray;border-style:solid none none solid;background-repeat:repeat-x;" valign=top align='.CENTER.'><font color=black><td style="border-width:1px;border-color:gray;border-style:solid solid none solid;" valign=top align='.CENTER.'><font color=black></td></TR>';*/

		$checked = IsSystemDefaultPreference('BUS_ADDRESSES') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][BUS_ADDRESSES] id=values[system][BUS_ADDRESSES] value=Y'.((SystemPreferences('BUS_ADDRESSES')=='Y')?' CHECKED':'').'><label for=values[system][BUS_ADDRESSES]>'._('Use Bus Addresses').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][BUS_ADDRESSES] onclick="enable_input(\'values[system][BUS_ADDRESSES]\', this)" id=BUS_ADDRESSES /><label for="BUS_ADDRESSES">'.(SystemPreferences('BUS_ADDRESSES','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('MAILING_ADDRESSES') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][MAILING_ADDRESSES] id=values[system][MAILING_ADDRESSES] value=Y'.((SystemPreferences('MAILING_ADDRESSES')=='Y')?' CHECKED':'').'><label for=values[system][MAILING_ADDRESSES]>'._('Use Mailing Addresses').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][MAILING_ADDRESSES] onclick="enable_input(\'values[system][MAILING_ADDRESSES]\', this)" id=MAILING_ADDRESSES /><label for="MAILING_ADDRESSES">'.(SystemPreferences('MAILING_ADDRESSES','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('USE_KLADR') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][USE_KLADR] id=values[system][USE_KLADR] value=Y'.((SystemPreferences('USE_KLADR')=='Y')?' CHECKED':'').'><label for=values[system][USE_KLADR]>'._('Use KLADR (Only for Russia)').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][USE_KLADR] onclick="enable_input(\'values[system][USE_KLADR]\', this)" id=USE_KLADR /><label for="USE_KLADR">'.(SystemPreferences('USE_KLADR','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('GUARDIANS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][GUARDIANS] id=values[system][GUARDIANS] value=Y'.((SystemPreferences('GUARDIANS')=='Y')?' CHECKED':'').'><label for=values[system][GUARDIANS]>'._('Use Parents/Guardians/Emergency Contacts').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][GUARDIANS] onclick="enable_input(\'values[system][GUARDIANS]\', this)" id=GUARDIANS /><label for="GUARDIANS">'.(SystemPreferences('GUARDIANS','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';

		$checked = IsSystemDefaultPreference('AUTO_STUDENT_USERNAMES') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<TR><TD style="border-width:1px;border-color:gray;border-style:none none solid solid;">&nbsp</TD><TD style="border-width:1px;border-color:gray;border-style:none none solid none;"><INPUT '.$disabled.' type=checkbox name=values[system][AUTO_STUDENT_USERNAMES] id=values[system][AUTO_STUDENT_USERNAMES] value=Y'.((SystemPreferences('AUTO_STUDENT_USERNAMES')=='Y')?' CHECKED':'').'><label for=values[system][AUTO_STUDENT_USERNAMES]>'._('Automatically Generate Student Usernames').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid solid solid;"><input '.$checked.' type=checkbox name=override[system][AUTO_STUDENT_USERNAMES] onclick="enable_input(\'values[system][AUTO_STUDENT_USERNAMES]\', this)" id=AUTO_STUDENT_USERNAMES /><label for="AUTO_STUDENT_USERNAMES">'.(SystemPreferences('AUTO_STUDENT_USERNAMES','system', true)=='Y'?_('Yes'):_('No')).'</label></td></TR>';
		//frame
		/*		echo '<TR background=themes/'.Preferences('HIGHLIGHT_FRAME').'/bottom_shadow.png height=20 ><TD colspan=2  style="border-width:1px;border-color:gray;border-style:solid none none solid;background-repeat:repeat-x;" valign=top align='.CENTER.'><font color=black><td style="border-width:1px;border-color:gray;border-style:solid solid none solid;" valign=top align='.CENTER.'><font color=black></td></TR>';*/
    
	    	$checked = IsSystemDefaultPreference('SHORT_COMMENTS_PER_COURSE') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<tr><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><br><font color=gray>'._('Comments for the posted grades').'</TD><TD><br><INPUT '.$disabled.' type=checkbox name=values[system][SHORT_COMMENTS_PER_COURSE] id=values[system][SHORT_COMMENTS_PER_COURSE] value=Y'.((SystemPreferences('SHORT_COMMENTS_PER_COURSE')=='Y')?' CHECKED':'').'><label for=values[system][SHORT_COMMENTS_PER_COURSE]>'._('Short Comments Per Course').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><br><input '.$checked.' type=checkbox name=override[system][SHORT_COMMENTS_PER_COURSE] onclick="enable_input(\'values[system][SHORT_COMMENTS_PER_COURSE]\', this)" id=SHORT_COMMENTS_PER_COURSE /><label for="SHORT_COMMENTS_PER_COURSE">'.(SystemPreferences('SHORT_COMMENTS_PER_COURSE','system', true)=='Y'?_('Yes'):_('No')).'</label></td></tr>';

	    	$checked = IsSystemDefaultPreference('ONE_LONGER_COMMENT_PER_COURSE') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<tr BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][ONE_LONGER_COMMENT_PER_COURSE] id=values[system][ONE_LONGER_COMMENT_PER_COURSE] value=Y'.((SystemPreferences('ONE_LONGER_COMMENT_PER_COURSE')=='Y')?' CHECKED':'').'><label for=values[system][ONE_LONGER_COMMENT_PER_COURSE]>'._('Long Comment Per Course').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][ONE_LONGER_COMMENT_PER_COURSE] onclick="enable_input(\'values[system][ONE_LONGER_COMMENT_PER_COURSE]\', this)" id=ONE_LONGER_COMMENT_PER_COURSE /><label for="ONE_LONGER_COMMENT_PER_COURSE">'.(SystemPreferences('ONE_LONGER_COMMENT_PER_COURSE','system', true)=='Y'?_('Yes'):_('No')).'</label></td></tr>';
    		
	    	$checked = IsSystemDefaultPreference('ONE_LONGER_COMMENT_PER_STUDENT') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<tr><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][ONE_LONGER_COMMENT_PER_STUDENT] id=values[system][ONE_LONGER_COMMENT_PER_STUDENT] value=Y'.((SystemPreferences('ONE_LONGER_COMMENT_PER_STUDENT')=='Y')?' CHECKED':'').'><label for=values[system][ONE_LONGER_COMMENT_PER_STUDENT]>'._('Long Comment Per Student').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][ONE_LONGER_COMMENT_PER_STUDENT] onclick="enable_input(\'values[system][ONE_LONGER_COMMENT_PER_STUDENT]\', this)" id=ONE_LONGER_COMMENT_PER_STUDENT /><label for="ONE_LONGER_COMMENT_PER_STUDENT">'.(SystemPreferences('ONE_LONGER_COMMENT_PER_STUDENT','system', true)=='Y'?_('Yes'):_('No')).'</label></td></tr>';

	    	$checked = IsSystemDefaultPreference('COMMENTS_CONDUCT') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<tr BGCOLOR=#'.Preferences('HIGHLIGHT_BACKGROUND').'><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><INPUT '.$disabled.' type=checkbox name=values[system][COMMENTS_CONDUCT] id=values[system][COMMENTS_CONDUCT] value=Y'.((SystemPreferences('COMMENTS_CONDUCT')=='Y')?' CHECKED':'').'><label for=values[system][COMMENTS_CONDUCT]>'._('Comment on Student\'s Conduct').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][COMMENTS_CONDUCT] onclick="enable_input(\'values[system][COMMENTS_CONDUCT]\', this)" id=COMMENTS_CONDUCT /><label for="COMMENTS_CONDUCT">'.(SystemPreferences('COMMENTS_CONDUCT','system', true)=='Y'?_('Yes'):_('No')).'</label></td></tr>';

	    	$checked = IsSystemDefaultPreference('CALC_GPA_AUTOMATICALLY') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<tr><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><br><INPUT '.$disabled.' type=checkbox name=values[system][CALC_GPA_AUTOMATICALLY] id=values[system][CALC_GPA_AUTOMATICALLY] value=Y'.((SystemPreferences('CALC_GPA_AUTOMATICALLY')=='Y')?' CHECKED':'').'><label for=values[system][CALC_GPA_AUTOMATICALLY]>'._('Calculate GPA Automatically').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><br><input '.$checked.' type=checkbox name=override[system][CALC_GPA_AUTOMATICALLY] onclick="enable_input(\'values[system][CALC_GPA_AUTOMATICALLY]\', this)" id=CALC_GPA_AUTOMATICALLY /><label for="CALC_GPA_AUTOMATICALLY">'.(SystemPreferences('CALC_GPA_AUTOMATICALLY','system', true)=='Y'?_('Yes'):_('No')).'</label></td></tr>';
	        $options = '';
		for($i=0;$i<=10;$i++)
		{
			if(SystemPreferences('ROUND_GPA_POINTS')==$i)
				$selected = ' SELECTED';
			else
				$selected = '';
			$options .= '<OPTION value='.$i.$selected.'>'.$i.'</option>';
		}
	        $checked = IsSystemDefaultPreference('ROUND_GPA_POINTS') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<tr ><TD style="border-width:1px;border-color:gray;border-style:none none none solid;" valign=top align='.ALIGN_LEFT.'><label for=values[system][ROUND_GPA_POINTS]><font color=gray>'._('Round GPA to X Decimal Points').'</font></label></TD><TD style="border-width:1px;border-color:gray;border-style:none none none none;"><SELECT '.$disabled.' name=values[system][ROUND_GPA_POINTS] id=values[system][ROUND_GPA_POINTS] >'.$options.'</select></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><input '.$checked.' type=checkbox name=override[system][ROUND_GPA_POINTS] onclick="enable_input(\'values[system][ROUND_GPA_POINTS]\', this)" id=ROUND_GPA_POINTS /><label for="ROUND_GPA_POINTS">'.(SystemPreferences('ROUND_GPA_POINTS','system', true)).'</label></td></tr>';
        
	        $options = '';
		for($i=0;$i<=10;$i++)
		{
			if(SystemPreferences('ROUND_AVERAGE_POINTS')==$i)
				$selected = ' SELECTED';
			else
				$selected = '';
			$options .= '<OPTION value='.$i.$selected.'>'.$i.'</option>';
		}
	        echo '<tr><TD style="border-width:1px;border-color:gray;border-style:none none solid solid;" valign=top align='.ALIGN_LEFT.'><label for=values[system][ROUND_AVERAGE_POINTS]><font color=gray>'._('Round Average to X Decimal Points').'</font></label></TD><TD style="border-width:1px;border-color:gray;border-style:none none solid none;"><SELECT '.$disabled.' name=values[system][ROUND_AVERAGE_POINTS] id=values[system][ROUND_AVERAGE_POINTS] >'.$options.'</select></TD><td style="border-width:1px;border-color:gray;border-style:none solid solid solid;"><input '.$checked.' type=checkbox name=override[system][ROUND_AVERAGE_POINTS] onclick="enable_input(\'values[system][ROUND_AVERAGE_POINTS]\', this)" id=ROUND_AVERAGE_POINTS /><label for="ROUND_AVERAGE_POINTS">'.(SystemPreferences('ROUND_AVERAGE_POINTS','system', true)).'</label></td></tr>';
	        $checked = IsSystemDefaultPreference('APPLY_MODE') ? "checked" : ""; $disabled = $checked ? " disabled " : "";
	        echo '<tr><TD style="border-width:1px;border-color:gray;border-style:none none none solid;">&nbsp</TD><TD><br><INPUT '.$disabled.' type=checkbox name=values[system][APPLY_MODE] id=values[system][APPLY_MODE] value=Y'.((SystemPreferences('APPLY_MODE')=='Y')?' CHECKED':'').'><label for=values[system][APPLY_MODE]>'._('Online application mode').'</label></TD><td style="border-width:1px;border-color:gray;border-style:none solid none solid;"><br><input '.$checked.' type=checkbox name=override[system][APPLY_MODE] onclick="enable_input(\'values[system][APPLY_MODE]\', this)" id=APPLY_MODE /><label for="APPLY_MODE">'.(SystemPreferences('APPLY_MODE','system', true)=='Y'?_('Yes'):_('No')).'</label></td></tr>';
		echo '</TABLE>';
	        //APPLY_MODE
	}
        elseif($_REQUEST['system_tab']=='counter')
        {
            include('includes/counter.php');
        }
	elseif($_REQUEST['system_tab']=='applicants')
        {
                if(!$_REQUEST['tab'])
                        $_REQUEST['tab'] = 'mod_apply';

                if($_REQUEST['return'])
                        echo "<FORM action=modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=$_REQUEST[system_tab]&amp;tab=$_REQUEST[tab]&return=".$_REQUEST['return']."&CREATEPDF=true method=POST>";
                elseif($_REQUEST['servicemod']!='mod_ssetup/SchSysPrefnProper.php')
                        echo "<FORM action=modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=$_REQUEST[system_tab]&amp;tab=$_REQUEST[tab]&amp;edu_cat_id=$_REQUEST[edu_cat_id]&amp;field_cat_id=$_REQUEST[field_cat_id] method=POST>";

                if($_REQUEST['servicemod']!='mod_ssetup/SchSysPrefnProper.php')
                        DisplayHeader('','<INPUT style="width:100px;" type=submit value='._('Save').'>');
                echo '<BR>';

                if($_REQUEST['servicemod']=='mod_ssetup/SchSysPrefnProper.php')
                {
                        if(get_user('PROFILE')=='admin')
                                $tabs = array(array('title'=>_('Global Settings'),'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=$_REQUEST[system_tab]&amp;tab=mod_apply"),
                            		    array('title'=>_('Online Applicants'),'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=$_REQUEST[system_tab]&amp;tab=online_apply"),
	                                    array('title'=>_('AID Generator'),'link'=>"modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=$_REQUEST[system_tab]&amp;tab=AID_generator"));
                }

                $_SYSTEM['selected_tab'] = "modloader.php?servicemod=$_REQUEST[servicemod]&amp;system_tab=$_REQUEST[system_tab]&amp;tab=".$_REQUEST['tab'];
                PopTable('header',$tabs);
                if($_REQUEST['tab']=='mod_apply')
                {
                    include('includes/apply_iface.php');
                }
                if($_REQUEST['tab']=='online_apply')
                {
                    include('includes/apply_online_iface.php');
                }
                if($_REQUEST['tab']=='AID_generator')
                {
            		if($remove_id === true) $_REQUEST['servicefunction'] = 'remove_id';
	                include('includes/id_gen_iface.php');
	                if($remove_id === false) unset ($_REQUEST['servicefunction']);
		}
        if($_REQUEST['servicemod']!='mod_ssetup/SchSysPrefnProper.php' && $remove_id === false)
		echo '<BR><CENTER><INPUT style="width:100px;" type=submit value='._('Save').'></CENTER>';
	//echo '</fieldset>';
	PopTable('footer');
        }

	if($_REQUEST['system_tab']!='database_backup_download' && $remove_id === false)
		echo '<BR><CENTER><INPUT type=submit id=button_submit onclick="javascript: document.config_form.submit();" value='._('Save').'></CENTER>';

	PopTable('footer');

	if($_REQUEST['system_tab']!='database_backup_download')
		echo '</FORM>';
}

function _replaceDoubleLineBreaks($str)
{
	return str_replace("\n","\r",str_replace("\r\n","\r",$str));
}

function _replaceSingleQuotes($str)
{
	return str_replace("'","''",$str);
}

function _makePrefixInput($value,$name)
{	global $THIS_array;
	
	if($THIS_array['ID'])
	{
		$id = $THIS_array['ID'];
		$div = true;
	}
	else
		$id = 'new';
	if($name=='VALUE')
		$addition = 'size=50 maxlength=500';
	else
		$addition = 'size=20 maxlength=150';

	return TextInput(array($value,$value.$suffix),'tables[SYSTEM_CONFIG]['.$id.']['.$name.']','',$addition,$div);
}

?>