<?php

function _get_absence_summary($student_id, $start_date, $end_date, $using_default_end_date)
{
    $result = '';

    if(!$codes_array)
        $codes_array = db_request(db_execute("SELECT ID,TITLE,STATE_CODE,SHORT_NAME FROM ATTENDANCE_CODES_SETTINGS WHERE SCHOOL_YEAR='".get_school_year()."' AND SCHOOL_ID='".get_school_id()."' AND TABLE_NAME='0' AND (DEFAULT_CODE!='Y' OR DEFAULT_CODE IS NULL OR STATE_CODE='A') ORDER BY SORT_ORDER"));

    if($_REQUEST['CREATEPDF']=='true')
        $result .= '<B style="padding:4px;">'._('Attendance Report Timeframe ').': </B>'.PrepareDate($start_date,'_start').
        ' - '.PrepareDate($end_date,'_end');

    $name_array = db_request(db_execute("SELECT FIRST_NAME".CCAT."' '".CCAT."COALESCE(MIDDLE_NAME,' ')".CCAT."' '".CCAT."LAST_NAME AS FULL_NAME FROM STUDENTS WHERE STUDENT_ID='".$student_id."'"));
	if(AllowUse('mod_attendance/AttdMark.php') && !isset($_REQUEST['CREATEPDF']))
//		$add_link = button('add',_('Add Absence'),"modloader.php?servicemod=mod_attendance/AttdMark.php&search_servicefunction=list&stuid=".get_student_id());
		echo '<CENTER>'.button('add',_('Add Absence'),"modloader.php?servicemod=mod_attendance/AttdMark.php&search_servicefunction=list&stuid=".get_student_id()).'</CENTER><BR>';

	// by default, we see attendance for the full-year .. including future attendance.  But, the student hasn't actually attended that many days of school yet, so let's not count future attendance if we're looking at the default timeframe
	if($using_default_end_date)
		$attended_end_date = get_db_date();
	else
		$attended_end_date = $end_date;

    $total_missed_array = db_request(db_execute("SELECT COALESCE((SUM((STATE_VALUE-1))),0.0) AS TOTAL FROM STUDENT_ATTENDANCE_DAYS ad,STUDENT_REGISTRATION ssm,SCHOOL_CALENDAR_DAYS ac WHERE ac.SCHOOL_DATE=ad.SCHOOL_DATE AND ac.CALENDAR_ID=ssm.CALENDAR_ID AND ad.STUDENT_ID=ssm.STUDENT_ID AND ssm.SCHOOL_YEAR='".get_school_year()."' AND ssm.SCHOOL_ID='".get_school_id()."' AND ad.STUDENT_ID='".$student_id."' AND ad.SCHOOL_DATE BETWEEN '$start_date' AND '$attended_end_date'
						AND (ad.SCHOOL_DATE BETWEEN ssm.START_DATE AND ssm.END_DATE OR (ssm.END_DATE IS NULL AND ad.SCHOOL_DATE>=ssm.START_DATE))
	"));
	$total_possible_array = db_request(db_execute("SELECT COUNT(*) AS TOTAL FROM SCHOOL_CALENDAR_DAYS ac,STUDENT_REGISTRATION ssm WHERE ssm.STUDENT_ID='".$student_id."' AND ssm.SCHOOL_YEAR='".get_school_year()."' AND ssm.SCHOOL_ID='".get_school_id()."' AND ac.SCHOOL_DATE BETWEEN '$start_date' AND '$attended_end_date'
					AND (ac.SCHOOL_DATE BETWEEN ssm.START_DATE AND ssm.END_DATE OR (ssm.END_DATE IS NULL AND ac.SCHOOL_DATE>=ssm.START_DATE)) AND ac.CALENDAR_ID=ssm.CALENDAR_ID
	"));

	$total_array[1]['TOTAL'] = $total_possible_array[1]['TOTAL'] + $total_missed_array[1]['TOTAL'];

	// THIS SHOULD BE JOINED TO STUDENT_REGISTRATION & STUDENT_SCHEDULE
	$absences_array = db_request(db_execute("SELECT ac.SCHOOL_ID,ap.STUDENT_ID,ap.SCHOOL_PERIOD_ID,".db_to_char('ap.SCHOOL_DATE','YYYY-MM-DD')." as SCHOOL_DATE,ac.SHORT_NAME,ac.STATE_CODE,ad.STATE_VALUE,ad.DAILY_CODE,ad.COMMENT
		FROM STUDENT_ATTENDANCE_PERIODS ap,STUDENT_ATTENDANCE_DAYS ad,ATTENDANCE_CODES_SETTINGS ac,STUDENT_REGISTRATION se,SCHOOL_CALENDAR_DAYS cal,STUDENT_SCHEDULE sched
		WHERE
			se.STUDENT_ID=ad.STUDENT_ID AND (ad.SCHOOL_DATE BETWEEN se.START_DATE AND se.END_DATE OR (se.END_DATE IS NULL AND ad.SCHOOL_DATE>=se.START_DATE))
			AND sched.STUDENT_ID=se.STUDENT_ID  AND sched.COURSE_SECTION_ID=ap.COURSE_SECTION_ID
			AND (ad.SCHOOL_DATE BETWEEN sched.START_DATE AND sched.END_DATE OR (sched.END_DATE IS NULL AND ad.SCHOOL_DATE>=sched.START_DATE))
			AND cal.SCHOOL_DATE=ad.SCHOOL_DATE AND cal.CALENDAR_ID=se.CALENDAR_ID
			AND ap.STUDENT_ID=ad.STUDENT_ID AND ap.SCHOOL_DATE=ad.SCHOOL_DATE AND ap.ATTENDANCE_CODE=ac.ID AND (ac.DEFAULT_CODE!='Y' OR ac.DEFAULT_CODE IS NULL or ac.STATE_CODE='A')
			AND ap.STUDENT_ID='".$student_id."' AND ap.SCHOOL_DATE BETWEEN '$start_date' AND '$end_date' ORDER BY ap.SCHOOL_DATE DESC"),
	array(),array('SCHOOL_DATE','SCHOOL_PERIOD_ID'));

/*echo
"SELECT ac.SCHOOL_ID,ap.STUDENT_ID,ap.SCHOOL_PERIOD_ID,".db_to_char('ap.SCHOOL_DATE','YYYY-MM-DD')." as SCHOOL_DATE,ac.SHORT_NAME,ac.STATE_CODE,ad.STATE_VALUE,ad.DAILY_CODE,ad.COMMENT
		FROM STUDENT_ATTENDANCE_PERIODS ap,STUDENT_ATTENDANCE_DAYS ad,ATTENDANCE_CODES_SETTINGS ac,STUDENT_REGISTRATION se,SCHOOL_CALENDAR_DAYS cal,STUDENT_SCHEDULE sched
		WHERE
			se.STUDENT_ID=ad.STUDENT_ID AND (ad.SCHOOL_DATE BETWEEN se.START_DATE AND se.END_DATE OR (se.END_DATE IS NULL AND ad.SCHOOL_DATE>=se.START_DATE))
			AND sched.STUDENT_ID=se.STUDENT_ID  AND sched.COURSE_SECTION_ID=ap.COURSE_SECTION_ID
			AND (ad.SCHOOL_DATE BETWEEN sched.START_DATE AND sched.END_DATE OR (sched.END_DATE IS NULL AND ad.SCHOOL_DATE>=sched.START_DATE))
			AND cal.SCHOOL_DATE=ad.SCHOOL_DATE AND cal.CALENDAR_ID=se.CALENDAR_ID
			AND ap.STUDENT_ID=ad.STUDENT_ID AND ap.SCHOOL_DATE=ad.SCHOOL_DATE AND ap.ATTENDANCE_CODE=ac.ID AND (ac.DEFAULT_CODE!='Y' OR ac.DEFAULT_CODE IS NULL or ac.STATE_CODE='A')
			AND ap.STUDENT_ID='".$student_id."' AND ap.SCHOOL_DATE BETWEEN '$start_date' AND '$end_date' ORDER BY ap.SCHOOL_DATE DESC";
			*/
//	$enrollment_DATE = db_request(db_limit("SELECT START_DATE,END_DATE FROM STUDENT_REGISTRATION WHERE STUDENT_ID='".get_student_id()."' ORDER BY START_DATE DESC",1));
	if(get_student_id())
		$enrollment_DATE = db_request(db_execute("SELECT START_DATE,END_DATE FROM STUDENT_REGISTRATION WHERE STUDENT_ID='".get_student_id()."' ORDER BY START_DATE DESC",array(),array()));
	else
		$enrollment_DATE = db_request(db_execute("SELECT START_DATE,END_DATE FROM STUDENT_REGISTRATION WHERE STUDENT_ID='".$student_id."' ORDER BY START_DATE DESC",array(),array()));

	$state_absence_counts['A'] = $state_absence_counts['H'] = $state_absence_counts['P'] = 0;
	foreach($absences_array as $date=>$periods)
	{
		foreach($periods as $period=>$absence)
		{
			$absence = $absence[1];
			$absence_counts[$absence['SHORT_NAME']]++;
			$state_absence_counts[$absence['STATE_CODE']]++;
			$state_day_count[$absence['STATE_CODE']][$date] = true;
		}
	}
	
//	if ($state_absence_counts['A']
//	$absent_content = '<B>'._('Amount of periods when student was absent').':</B> '.$state_absence_counts['A'].' '._('').' ('._('during').' '.(count($state_day_count['A'])).' '._('days').')<UL>';
//	$absent_content = $state_absence_counts['A'].' ('._('during').' '.(count($state_day_count['A'])).' '._('days').')<OL>';
//	$absent_content = '<B>'._('Absent').':</B> '.$state_absence_counts['A'].' '._('periods').' ('._('during').' '.(count($state_day_count['A'])).' '._('days').')<UL>';
//	$present_content = '<B>'._('Amount of periods that have other marks').':</B> '.($state_absence_counts['P']+$state_absence_counts['H']).' '._('').' ('._('during').' '.(count($state_day_count['T'])+count($state_day_count['P'])).' '._('days').')<UL>';
	$present_content = '<TABLE width=100%>';
//	$present_content = ($state_absence_counts['P']+$state_absence_counts['H']).' ('._('during').' '.(count($state_day_count['T'])+count($state_day_count['P'])).' '._('days').')<OL>';


if($_REQUEST['CREATEPDF'])
       {

   	$content = '<TABLE border=0 cellpadding=0 cellspacing=0 width=100%>';
	$absent_content = '<Table width=100%>';
	$present_content = '<Table width=100%>';

	foreach($codes_array as $code)
	{
		if($code['STATE_CODE']=='A')
			$absent_content .= '<TR><TD width=15 bgcolor=FF0000 align=center><font color="#ffffff"><b>'.$code['SHORT_NAME'].'</b></font></TD><TD style="border-width:1px;border-style:none none groove none;" width=200 align=left>'.$code['TITLE'].': </TD><TD align=right>'.($absence_counts[$code['SHORT_NAME']]?$absence_counts[$code['SHORT_NAME']]:0).' '._('periods');
		elseif($code['STATE_CODE']=='H')
			$present_content .= '<TR><TD width=15 bgcolor=FFCC00 align=center><b>'.$code['SHORT_NAME'].'</b></TD><TD style="border-width:1px;border-style:none none groove none;" width=200>'.$code['TITLE'].': </TD><TD align=right>'.($absence_counts[$code['SHORT_NAME']]?$absence_counts[$code['SHORT_NAME']]:0).' '._('periods');
		elseif($code['STATE_CODE']=='P')
			$present_content .= '<TR><TD width=15 bgcolor=00ff00 align=center><B>'.$code['SHORT_NAME'].'</B></TD><TD style="border-width:1px;border-style:none none groove none;" width=200>'.$code['TITLE'].': </TD><TD align=right>'.($absence_counts[$code['SHORT_NAME']]?$absence_counts[$code['SHORT_NAME']]:0).' '._('periods');
	}
	//$present_content .= '<LI><SPAN style="background-color:#00FF00">-</SPAN>'._('No class scheduled this period');
	$absent_content .= '</TD></TR></table>';
	$present_content .= '</TD></TR></table>';



	$content .= '<TR><TD colspan=2><HR></TD></TR><TR><TD alin=left width=50%>'._('Amount of periods when student was absent').': &nbsp; '.$state_absence_counts['A'].'</TD><TD align="right"> '.$absent_content.'</TD></TR><TR><TD colspan=2><HR></TD></TR><TR><TD><bR>'._('Amount of periods that have other marks').': &nbsp;'.($state_absence_counts['P']+$state_absence_counts['H']).'</TD><TD>'.$present_content.'</TD></TR> ';
	$content .= '<TR><TD colspan=2><HR></TD></TR><TR><TD valign=middle><B>'._('Total Amount').':</B></TD><TD><TABLE>';

    }
 else
    {

   	$content = '<TABLE border=0 cellpadding=0 cellspacing=0>';
	$absent_content = '<Table width=100%>';
	$present_content = '<Table width=100%>';

	foreach($codes_array as $code)
	{
		if($code['STATE_CODE']=='A')
			$absent_content .= '<TR><TD width=15 bgcolor=FF0000 align=center><font color="#ffffff"><b>'.$code['SHORT_NAME'].'</b></font></TD><TD style="border-width:1px;border-style:none none groove none;">'.$code['TITLE'].': </TD><TD>'.($absence_counts[$code['SHORT_NAME']]?$absence_counts[$code['SHORT_NAME']]:0).' '._('periods');
		elseif($code['STATE_CODE']=='H')
			$present_content .= '<TR><TD width=15 bgcolor=FFCC00 align=center><b>'.$code['SHORT_NAME'].'</b></TD><TD style="border-width:1px;border-style:none none groove none;">'.$code['TITLE'].': </TD><TD>'.($absence_counts[$code['SHORT_NAME']]?$absence_counts[$code['SHORT_NAME']]:0).' '._('periods');
		elseif($code['STATE_CODE']=='P')
			$present_content .= '<TR><TD width=15 bgcolor=00ff00 align=center><B>'.$code['SHORT_NAME'].'</B></TD><TD style="border-width:1px;border-style:none none groove none;">'.$code['TITLE'].': </TD><TD>'.($absence_counts[$code['SHORT_NAME']]?$absence_counts[$code['SHORT_NAME']]:0).' '._('periods');
	}
	//$present_content .= '<LI><SPAN style="background-color:#00FF00">-</SPAN>'._('No class scheduled this period');
	$absent_content .= '</TD></TR></table>';
	$present_content .= '</TD></TR></table>';

	$content .= '<TR><TD valign=top><fieldset style="border:1px solid gray;"><legend><B>'._('Amount of periods when student was absent').': &nbsp;'.$state_absence_counts['A'].'</B> </legend>'.$absent_content.'</fieldset></TD><TD valign=top><fieldset style="border:1px solid gray;"><legend><B>'._('Amount of periods that have other marks').': &nbsp;'.($state_absence_counts['P']+$state_absence_counts['H']).'</B> </legend>'.$present_content.'</fieldset></TD> ';
	$content .= '<TD valign=top><fieldset style="border:1px solid gray;"><legend><B>'._('Total Amount').':</B> </legend><TABLE width=100%>';
    }

	$content .= $days_content;
//	$content .= '<B>'._('Total Amount:').'</B><BR>';
	$content .= '<TR><TD  style="border-width:1px;border-style:none none groove none;"><B>'._('Full Days Possible').':</B></TD><TD> '.$total_possible_array[1]['TOTAL'].'</TD><TR>';

	if ($total_array[1]['TOTAL'] > 0) {
		$ttl1 = $total_array[1]['TOTAL'];
	}
	else{
		$ttl1 = 100;	
	}

	if ($total_possible_array[1]['TOTAL'] > 0) {
		$ttl2 = $total_possible_array[1]['TOTAL'];
	}
	else{
		$ttl2 = 100;
	}

	$content .= '<TR><TD  style="border-width:1px;border-style:none none groove none;"><B>'._('Full Days Present').':</B></TD><TD>  '.$total_array[1]['TOTAL'].' ('.Percent($ttl1/$ttl2,2).')</TD><TR>';
	$content .= '<TR><TD  style="border-width:1px;border-style:none none groove none;"><B>'._('Full Days Absent').':</B></TD><TD>  '.($total_missed_array[1]['TOTAL']*-1).' ('.Percent((($ttl1*-1)/$ttl2),2).')</TD><TR>';
	if (!empty($enrollment_DATE))
	{
		$content .= '<TR><TD  style="border-width:1px;border-style:none none groove none;"><B>'._('Student registration timeframe').':</B></TD><TD>'.ProperDate($enrollment_DATE[1]['START_DATE'],'attendance').' - '.(!is_null($enrollment_DATE[1]['END_DATE'])? ProperDate($enrollment_DATE[1]['END_DATE']) : _('still studying')).'</TD><TR>';
	}
	else
	{
		$content .= '<TR><TD  style="border-width:1px;border-style:none none groove none;"><B>'._('Student registration timeframe').':</B></TD><TD>' . _('Not Available').'</TD><TR>';
	}
	
	$content .= '</TABLE></fieldset></TD>';
	$content .= '</TABLE>';

	$result .= DisplayHeaderBuffered($content,$add_link,null,'');
	$PHP_tmp_SELF = SetRequestOptions();

	foreach($absences_array as $school_date=>$absences)
	{
		$this_school_id = $absences[key($absences)][1]['SCHOOL_ID'];

		if(!$index[$this_school_id])
			$index[$this_school_id] = 0;
		$index[$this_school_id] = $index[$this_school_id]+1;

	        $days_array[$this_school_id][$index[$this_school_id]]['DB_SCHOOL_DATE'] = $school_date;
		$days_array[$this_school_id][$index[$this_school_id]]['SCHOOL_DATE'] = ProperDate($school_date);
		$days_array[$this_school_id][$index[$this_school_id]]['DAILY'] = _makeStateValue($absences[key($absences)][1]['STATE_VALUE'],null);
		$days_array[$this_school_id][$index[$this_school_id]]['COMMENT'] = $absences[key($absences)][1]['COMMENT'];
		foreach($absences as $school_period_id=>$absence)
		{
//		echo "123"._makeColor($absence);
			$days_array[$this_school_id][$index[$this_school_id]][$school_period_id] = _makeColor($absence);
			$state_code = $absence[1]['STATE_CODE'];

			if($state_code=='P')
				$totals[$school_period_id]['P']++;
			elseif($state_code=='A')
				$totals[$school_period_id]['A']++;
			elseif($state_code=='H')
				$totals[$school_period_id]['A']+=.5;
		}
	}
//var_dump($days_array);
	if(is_countable($days_array))
	{
		foreach($days_array as $school_id=>$days_R)
		{
			$columns = array();
			$link = array();
			$periods_array = db_request(db_execute("SELECT SCHOOL_PERIOD_ID,SHORT_NAME FROM SCHOOL_PERIODS WHERE SCHOOL_ID='".$school_id."' AND SCHOOL_YEAR='".get_school_year()."' AND ATTENDANCE='Y' ORDER BY SORT_ORDER"));
			$columns['SCHOOL_DATE'] = _('Date');
			$columns['DAILY'] = _('Attendance State');
			$columns['COMMENT'] = _('Comment');
			$link['add']['html']['SCHOOL_DATE'] = '<b>'._('Total Absences').'<BR>'._('Total Tardies').'</b>';

			foreach($periods_array as $period)
			{
				if(!$totals[$period['SCHOOL_PERIOD_ID']]['A'])
					$totals[$period['SCHOOL_PERIOD_ID']]['A'] = 0;
				if(!$totals[$period['SCHOOL_PERIOD_ID']]['P'])
					$totals[$period['SCHOOL_PERIOD_ID']]['P'] = 0;
				$columns[$period['SCHOOL_PERIOD_ID']] = $period['SHORT_NAME'];
				$link['add']['html'][$period['SCHOOL_PERIOD_ID']] = '<b>'.$totals[$period['SCHOOL_PERIOD_ID']]['A'].'<BR>'.$totals[$period['SCHOOL_PERIOD_ID']]['P'].'</b>';
    			        //fill empty cell with add new absence
//		                echo "school=$school_id";
		                foreach($days_array[$school_id] as $k=>&$v)
		                {
		//	                echo "==".$period['SCHOOL_PERIOD_ID']." - $k -- ".print_r($v)."<br>";
		                        if(!array_key_exists($period['SCHOOL_PERIOD_ID'], $v))
		                        {
			                        $v[$period['SCHOOL_PERIOD_ID']] = _makeEmptyColor($school_id,$student_id,$period['SCHOOL_PERIOD_ID'],$v['DB_SCHOOL_DATE']);
		                        }
		                }
			}
			$result .= '<BR>';
			if(count($days_array)>1 || $school_id!=get_school_id())
			{
				$singular = _('Day at ').get_school($school_id);
				$plural = _('Days at ').get_school($school_id);
			}
			else
			{
				$singular = _('Days');
				$plural = _('Amount of Days');
			}
			$result .= GridoutputBuffered($days_array[$school_id],$columns,$singular,$plural,$link);
		}
	}
	else
	{
		$result .= '<BR>';
		$content = $name_array[1]['FULL_NAME']._(' has no absences in this time period.').'  ';
		if(get_user('PROFILE')=='admin' && $_REQUEST['CREATEPDF']!='true')
			$content .= '<BR><BR>'._('If you want to search other students, click ').'<IMG SRC="images/back.png">';
		$result .= $_REQUEST['CREATEPDF']!='true' ? DisplayBlock(_('Note '),$content,'333366','FFFFFF',true) : $content;
	}

    return $result;
} //function

function _makeStateValue($value,$daily_code)
{	global $THIS_array,$date,$codes_shortname_array;

	if($value=='0.0')
	{
		if($daily_code)
			return $codes_shortname_array[$daily_code][1]['TITLE'];
		else
			return _('None');
	}
	elseif($value=='.5')
		return _('Half-Day');
	else
		return _('Full-Day');
}

function _makeAbs($value, $column)
{
    global $THIS_array, $_SYSTEM;

    return $_SYSTEM['array_'.$column][$THIS_array['STUDENT_ID']][1][$column];
}

function _makeColor($absence)
{	global $codes_shortname_array, $THIS_array;

    $value = $absence[1]["SHORT_NAME"];
    $state_code = $absence[1]["STATE_CODE"];
    $school_id = $absence[1]["SCHOOL_ID"];
    $student_id = $absence[1]["STUDENT_ID"];
    $school_period_id = $absence[1]["SCHOOL_PERIOD_ID"];
    $school_date = $absence[1]["SCHOOL_DATE"];
//echo "|$school_id - $student_id - $school_period_id - $school_date|";
	if($state_code=='P')
		$color = '00FF00';
	elseif($state_code=='A')
		$color = 'FF0000';
	elseif($state_code=='H')
		$color = 'FFCC00';

    $options = array();
    if(!$codes_shortname_array) $codes_shortname_array = array();    
    foreach($codes_shortname_array as $key=>$val)
    {
        $options[$val[1]["ID"]] = $key;
    }

    $id = $codes_shortname_array[$value][1]['ID'];
//echo "-->".$codes_shortname_array[$value][1]['TITLE'];
    if(!isset($_REQUEST['CREATEPDF']))
    {
        if(AllowEdit())
            $value = SelectInput($id, "values[$school_id][$student_id][$school_period_id][$school_date]", false, $options, false);
        else
            $value = '<DIV onMouseOver=\'stm(["","'.$codes_shortname_array[$value][1]['TITLE'].'"],["white","#333366","","","",,"black","#e8e8ff","","","",,50,,2,"#333366",2,,,,,"",,,,]);\' onMouseOut=\'htm()\'>'.$value.'</DIV>';
    }
	return '<TABLE cellspacing=0 WIDTH="100%" bgcolor="#'.$color.'" class=GridOutput_fieldint><TR><TD bgcolor="#'.$color.'">'.$value.'</TD></TR></TABLE>';
}

function _makeEmptyColor($school_id,$student_id,$school_period_id,$school_date)
{	global $codes_shortname_array;

    $options = array();
    $options[-1] = "";

    foreach($codes_shortname_array as $key=>$val)
    {
        $options[$val[1]["ID"]] = $key;
    }

	if(!isset($_REQUEST['CREATEPDF']))
    {
//    echo "|$school_id - $student_id - $school_period_id - $school_date|";
        $course_section_id = _get_course_section_id($school_id,$student_id,$school_period_id,$school_date);
//        echo "==>".$course_section_id;
        if(AllowEdit() && $course_section_id)
            $value = SelectInput(-1, "newvalues[$school_id][$student_id][$school_period_id][$school_date]", false, $options, false);
        else
            $value = '<DIV onMouseOver=\'stm(["","'.$codes_shortname_array[$value][1]['TITLE'].'"],["white","#333366","","","",,"black","#e8e8ff","","","",,50,,2,"#333366",2,,,,,"",,,,]);\' onMouseOut=\'htm()\'>'.$value.'</DIV>';
    }
#$color = "FFFFFF";
//	return '<TABLE cellspacing=0 bgcolor="#'.$color.'" class=GridOutput_fieldint><TR><TD bgcolor="#'.$color.'">'.$value.'</TD></TR></TABLE>';
	return '<TABLE cellspacing=0 class=GridOutput_fieldint><TR><TD>'.$value.'</TD></TR></TABLE>';
}

function _makeCount($value,$column)
{	global $THIS_array,$_SYSTEM;

	if($value==0 || !$THIS_array['SCHED_ALL'])
		return '<!-- 0 -->0';
		//return '0';
	else
	{
		_total($value,$column);
		return '<!-- '.$value.' -->'.$value.' - '.Percent($value/$THIS_array['SCHED_ALL']);
//		return ''.$value.' - '.Percent($value/$THIS_array['SCHED_ALL']);
	}
}

function _total($value,$column)
{	global $sums;

	$sums[$column] += $value;
	return $value;
}

function _makeStateAbs($value,$column)
{	global $THIS_array,$sums;
	$sums['STATE_ABS'] += $THIS_array['TOTAL_POSSIBLE'] + $value;
	// adding value since it is negative.
	return $THIS_array['TOTAL_POSSIBLE'] + $value;

}

function _makeTotal($col)
{	global $sums;

	if($col=='FULL_NAME')
		return '<b>'._('Total').'</b>';

	if($sums[$col] && $col!='SCHED_ALL' && $col!='ABS_ALL' && $col!='STATE_ABS' && $sums['SCHED_ALL'])
		return '<B>'.$sums[$col].' - '.Percent($sums[$col]/$sums['SCHED_ALL']).'</B>';
	elseif($sums[$col])
		return '<B>'.$sums[$col].'</B>';
	else
		return '<B>0</B>';
}
?>