<?php
/*=====================================================================*\
|| ###################################################################
|| # Kalens [#]version[#]
|| # Copyright ©2002-[#]year[#] Iris Studios, Inc.
|| #
|| # This program is free software; you can redistribute it and/or modify
|| # it under the terms of the GNU General Public License as published by
|| # the Free Software Foundation; version [#]gpl[#] of the License.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|| # more details.
|| #
|| # You should have received a copy of the GNU General Public License along
|| # with this program; if not, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/

// ######################### REQUIRE BACKEND #########################
define('SVN', '$Id$');

$apptemplates = array('index', 'index_list_bits');

require_once('./global.php');

// ######################## START MAIN SCRIPT ########################
if (empty($_REQUEST['do']))
{
	// Show the user a list of calendars
	if ($kalens->userinfo['userid'])
	{
		$where[] = "userid = " . $kalens->userinfo['userid'];
	}
	if ($kalens->options['guestcanview'] OR $kalens->userinfo['userid'])
	{
		$where[] = "OR ispublic = 1";
	}

	if (count($where) > 0)
	{
		$get_calendars = $db->query("SELECT * FROM " . TABLE_PREFIX . "calendar WHERE " . implode(' ', $where));
		while ($calendar = $db->fetch_array($get_calendars))
		{
			$count++;
			eval('$calendarbits .= "' . $template->fetch('index_list_bits') . '";');
		}
	}

	if ($kalens->options['redirforonecal'])
	{
		if ($count == 1)
		{
			header("Location: showcalendar.php?id=$calendar[calendarid]");
		}
	}

	if (!$calendarbits)
	{
		$calendarbits = sprintf($lang->string('%1$s, there are no calendars.'), ($kalens->userinfo['username'] ? $kalens->userinfo['username'] : $lang->string('Guest')));
	}

	if ($kalens->userinfo['userid'] OR ($kalens->options['guestcanedit'] AND $kalens->options['guestcanview']))
	{
		$show['newlink'] = true;
	}

	$navbits = construct_navbar(array($lang->string('Index')));
	eval('$navbar = "' . $template->fetch('navbar') . '";');
	eval('$template->flush("' . $template->fetch('index') . '");');
}

/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>