Location: PHPKode > projects > SASHA > SASHA/inc/lib/lib.home.php
<?php

/**
 * SASHA :: inc/lib/lib.home.php
 *
 * This contains all of the home functions.
 *
 * @package SASHA
 * @copyright (C) 2006-2010 Gordon P. Hemsley
 * @license docs/LICENSE BSD License
 * @version $Id: lib.home.php 87 2010-02-10 22:27:14Z gphemsley $
 */

/**
 * Home
 *
 * Child class for tasks related to Home
 *
 * @package SASHA
 */
class Home extends Base
{
	/**
	 * Home::display_assignments_list()
	 *
	 * Display list of assignments due in given time range, in optional completion status range.
	 *
	 * @access public
	 * @param string $list_title Title of list, displayed as header
	 * @param int $begin_date UNIX timestamp to use for beginning of range (inclusive)
	 * @param int $end_date UNIX timestamp to use for end of range (not inclusive)
	 * @param bool $with_opacity Gradually hide assignments based on their status (default: FALSE)
	 * @param int $upper_status AT constant to use for upper limit (not inclusive) (default: NULL)
	 * @param int $lower_status AT constant to use for lower limit (inclusive) (default: NULL)
	 * @return void Prints list of assignments
	 */
	public function display_assignments_list( $list_title, $begin_date, $end_date, $with_opacity = FALSE, $upper_status = NULL, $lower_status = NULL )
	{
		global $Database, $User;

		$where_upper_status = $where_lower_status = '';

		if( !is_null( $upper_status ) )
		{
			$where_upper_status = "AND a.status < $upper_status";
		}

		if( !is_null( $lower_status ) )
		{
			$where_lower_status = "AND a.status >= $lower_status";
		}

		$sql = "SELECT a.*, s.*, c.course_title
			FROM assignments a, schedules s
			LEFT JOIN ( institutions i, courses c )
				ON ( i.institution = c.institution
					AND s.institution = c.institution
					AND s.subject = c.subject
					AND s.course = c.course )
			WHERE s.user_id = {$User->user_info['id']}
				AND a.schedule_id = s.schedule_id
				AND a.due_date >= $begin_date
				AND a.due_date < $end_date
				$where_upper_status
				$where_lower_status
			ORDER BY a.due_date ASC, s.start_time ASC, s.end_time ASC, a.assigned_date ASC, a.assignment_name ASC, a.assignment_id ASC";

		$result = $Database->query( $sql );

		if( $Database->has_result( $result ) )
		{
			print "\t<h3>$list_title</h3>\n";
			print "\t<ul>\n";

			while( $row = $Database->fetch_assoc( $result ) )
			{
				$bg_color = ( $row['bg_color'] ) ? 'background-color: #' . $row['bg_color'] . '; ' : '';
				$text_color = ( $row['text_color'] ) ? ' style="color: #' . $row['text_color'] . ';"' : '';
				$opacity = ( $with_opacity ) ? 1 - ( $row['status'] / 100 ) : 1.0;

				print "\t\t" . '<li style="' . $bg_color . 'opacity: ' . $opacity . ';" title="' . htmlentities( $row['description'], ENT_QUOTES, 'UTF-8' ) . '"><span' . $text_color . '><strong>' . date( 'm/d', $row['due_date'] ) . ':</strong> ' . htmlentities( $row['assignment_name'], ENT_QUOTES, 'UTF-8' ) . ' (' . $this->format_course( $row['subject'], $row['course'], $row['institution'], '&nbsp;' ) . '&nbsp;' . $row['section'] . ')</span></li>' . "\n";
			}

			print "\t</ul>\n";
			print "\n";
		}

		$Database->free_result( $result );
	}

	/**
	 * Home::display_tests_list()
	 *
	 * Display list of tests of given type in given time range.
	 *
	 * @access public
	 * @param string $list_title Title of list, displayed as header
	 * @param int $begin_date UNIX timestamp to use for beginning of range (inclusive)
	 * @param int $end_date UNIX timestamp to use for end of range (not inclusive)
	 * @param int $test_type TT constant specifying test type
	 * @return void Prints list of tests
	 */
	public function display_tests_list( $list_title, $begin_date, $end_date, $test_type )
	{
		global $Database, $User;

		$sql = "SELECT t.*, s.*, c.course_title
			FROM tests t, schedules s
			LEFT JOIN ( institutions i, courses c )
				ON ( i.institution = c.institution
					AND s.institution = c.institution
					AND s.subject = c.subject
					AND s.course = c.course )
			WHERE s.user_id = {$User->user_info['id']}
				AND t.schedule_id = s.schedule_id
				AND t.test_type = $test_type
				AND (
					( t.start_date >= $begin_date
						AND t.start_date < $end_date )
					OR ( t.end_date <= $end_date
						AND t.end_date > $begin_date )
				)
				AND (
					t.possible_score = 0
					OR t.possible_score IS NULL
				)
			ORDER BY t.start_date ASC, t.end_date ASC, s.start_time ASC, s.end_time ASC, t.test_name ASC, t.test_id ASC";

		$result = $Database->query( $sql );

		if( $Database->has_result( $result ) )
		{
			print "\t<h3>$list_title</h3>\n";
			print "\t<ul>\n";

			while( $row = $Database->fetch_assoc( $result ) )
			{
				$now = time();
				$test_now = ( ( $row['start_date'] < $now ) && ( $row['end_date'] > $now ) );
				$li_style = $bg_color = $blink = $opacity = '';

				if( $row['bg_color'] || $test_now )
				{
					$li_style .= ' style="';

					if( $row['bg_color'] )
					{
						$bg_color = 'background-color: #' . $row['bg_color'] . ';';
					}

					// If the test is currently ongoing, make sure the user knows!
					if( $test_now )
					{
						$blink = 'text-decoration: blink;';

						$test_length = $row['end_date'] - $row['start_date'];
						$time_elapsed = $now - $row['start_date'];

						$opacity = 'opacity: ' . round( ( 1 - ( $time_elapsed / $test_length ) ), 3 ) . ';';
					}

					$li_style .= trim( implode( array( $bg_color, $blink, $opacity ), ' ' ) );
					$li_style .= '"';
				}

				$text_color = ( $row['text_color'] ) ? ' style="color: #' . $row['text_color'] . ';"' : '';

				print "\t\t" . '<li' . $li_style . ' title="' . htmlentities( $row['description'], ENT_QUOTES, 'UTF-8' ) . '"><span' . $text_color . '><strong title="' . date( 'm/d g:i A', $row['end_date'] ) . '">' . date( 'm/d g:i A', $row['start_date'] ) . ':</strong> ' . htmlentities( $row['test_name'], ENT_QUOTES, 'UTF-8' ) . ' (' . $this->format_course( $row['subject'], $row['course'], $row['institution'], '&nbsp;' ) . '&nbsp;' . $row['section'] . ')</span></li>' . "\n";
			}

			print "\t</ul>\n";
			print "\n";
		}

		$Database->free_result( $result );
	}
}

?>
Return current item: SASHA