Location: PHPKode > projects > MyOrgBook > myorgbook/main.php
<?php
/*
Purpose: Main page (desktop)

$Header: /cvsroot/myorgbook/unstable/main.php,v 1.14 2003/10/19 14:24:41 mik3 Exp $
$Log: main.php,v $
Revision 1.14  2003/10/19 14:24:41  mik3
Timezone stuff

Revision 1.13  2003/10/04 19:01:55  mik3
Made timeformat an users choice (24h / am/pm)

Revision 1.12  2003/08/17 19:44:00  mik3
Made little icons which show the priority of a task in the mainscreen

Revision 1.11  2003/08/02 13:44:38  mik3
Layout changes, language changes, theme support changes. Iow version 2.5

Revision 1.10  2003/06/20 22:04:22  mik3
Changed how language works, fixed bugs, made small other enhancements.......

*/

include ('inc/session.inc');
include ('inc/template.inc');
include ('inc/functions.inc');

// Doing some date things that are needed later in the code.
if (!isset($_REQUEST['MyDate'])) {
	$databasedate = date("Y-m-d");
	$MyDate = mktime();
} else {
	$databasedate = date("Y-m-d", $_REQUEST['MyDate']);
	$MyDate = $_REQUEST['MyDate'];
}

$MonthNames = msg('MonthNames');
$month_number = date("n",$MyDate);
$month = $MonthNames[$month_number];
$year = date("Y",$MyDate);
$numberofdays = date("t",$MyDate);
$month_day = date("j",$MyDate);

// Calculating difference between user timezone and GMT
$diff_hours = round($_SESSION["TimeZone"]/100);
$diff_minutes = substr($_SESSION["TimeZone"],0,1) . substr($_SESSION["TimeZone"],3,2);
$diff = ($diff_hours * 3600) + ($diff_minutes * 60);

// Setup the template
$MyPage = New Template("Templates/" . $Theme . "/");
$MyPage->set_file(array("MyHeaderHandle" => "header.tpl",
		"MyFileHandle" => "main.tpl",
		"MyTableElementHandle_high" => "main_table_element_high.tpl",
		"MyTableElementHandle_medium" => "main_table_element_medium.tpl",
		"MyTableElementHandle_low" => "main_table_element_low.tpl"));
// Setting the variables
include ('inc/Templateheader.inc');

// parsing header
$MyPage->parse("header","MyHeaderHandle",true);

// Doing the static part (welcome message etc.)
$MyPage->set_var("Desktop",msg('Desktop'));
$MyPage->set_var("Welcome",msg('Welcome'));
$MyPage->set_var("Tasks",msg('Tasks'));
$MyPage->set_var("Contacts",msg('Contacts'));
$MyPage->set_var("Notes",msg('Notes'));
$MyPage->set_var("Profile",msg('Profile'));
$MyPage->set_var("Logout",msg('Logout'));
$MyPage->set_var("name_email",$_SESSION["First_Name"] . " (" . $_SESSION["Email"] . ")");
$MyPage->set_var("Today's Tasks",msg('Today\'s Tasks'));
$MyPage->set_var("Date", "$month_day $month $year");
$MyPage->set_var("Time:",msg('Time:'));
$MyPage->set_var("Task Title:",msg('Task Title:'));
$MyPage->set_var("Open Tasks",msg('Open Tasks'));
$MyPage->set_var("Date:",msg('Date:'));

// Doing the dynamic part (tasks or no tasks / notes)
if ((isset($_SESSION["IsAdmin"])) && ($_SESSION["IsAdmin"])) {
	$MyPage->set_var("Administrator functions",msg('Administrator functions'));
} else {
	$MyPage->set_var("Administrator functions",'');
}

$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$date1 = strtotime("$databasedate 00:00");
$date2 = strtotime("$databasedate 23:59");
// Today's tasks
$result = $db->Execute("SELECT * FROM myorgbook_tasks WHERE uemail = '" . $_SESSION["Email"] . "' AND date BETWEEN '$date1' AND '$date2' ORDER BY 'date'");
if ($result == false) die(msg('Query Failed'));
$num = $result->RecordCount();
// No task there
if ($num == "0") {
	$MyPage->set_var("time","");
	$MyPage->set_var("task_link","ManageTask.php");
	$MyPage->set_var("task_text",msg('Nothing is scheduled for today.'));
	$MyPage->parse("table_element","MyTableElementHandle_medium",true);
} else {
// Display that day's tasks
	while (!$result->EOF) {
		$r = $result->fields;
		$ttitle = $r["ttitle"];
		$taskid = $r["taskid"];
		$date = $r["date"];
		// Setting to users Timezone
		$date = $date + $diff;

		if ($_SESSION["TimeFormat"] == 0) {
			// am/pm
			$time = date("g:i a",$date);
		} else {
			// 24h
			$time = date("G:i",$date);
		}
		if ($r["taskdone"] == 1) {
			$time = "<s>$time</s>";
			$ttitle = "<s>$ttitle</s>";
		}
		$MyPage->set_var("time",$time);
		$MyPage->set_var("task_link","ManageTask.php?taskid=$taskid&Action=Details");
		$MyPage->set_var("task_text",$ttitle);
		$MyPage->parse("table_element","MyTableElementHandle_" . $r["print"],true);
		$result->MoveNext();
	}
}	
// Open tasks
$result = $db->Execute("SELECT * FROM myorgbook_tasks WHERE uemail = '" . $_SESSION["Email"] . "' AND taskdone = 0 AND date NOT BETWEEN '$date1' AND '$date2' ORDER BY 'date'");
if ($result == false) die(msg('Query Failed'));
$num = $result->RecordCount();
// No task there
if ($num == "0") {
	$MyPage->set_var("time","");
	$MyPage->set_var("task_link","ManageTask.php");
	$MyPage->set_var("task_text",msg('There are no open tasks.'));
	$MyPage->parse("table_element_open","MyTableElementHandle_medium",true);
} else {
// Display that day's tasks
	$TR = $Tpl_Table_Background_main;
	while (!$result->EOF) {
		$r = $result->fields;
		$ttitle = $r["ttitle"];
		$taskid = $r["taskid"];
		$date 	= $r["date"];
		$time = date("j M y",$date);
		if ($r["taskdone"] == 1) {
			$time = "<s>$time</s>";
			$ttitle = "<s>$ttitle</s>";
		}
		$MyPage->set_var("time",$time);
		$MyPage->set_var("task_link","ManageTask.php?taskid=$taskid&Action=Details");
		$MyPage->set_var("task_text",$ttitle);
		$MyPage->parse("table_element_open","MyTableElementHandle_" . $r["print"],true);
		$result->MoveNext();
	}
}
// outputting result
$MyPage->pparse("output","MyFileHandle");
?>
Return current item: MyOrgBook