<?php

/*
 * @name ICT Delta Congres Planner
 * @author Martijn Polak
 * @since 2008-01-18
 *
 */

// Includes
require_once 'class.stdModule.php';
require_once 'class.date.php';

// Class
class congressPlanner extends stdModule {


	// Construct
	function congressPlanner() {

		// Init
		$this->stdModule('cicp0100');
		$this->_settings->assignTemplateFunction	= '$this->assignGlobals();';

		// Templates
		$this->_settings->templates->planner		= 'planner.tpl';

	}

	// -- General Functions -------------------------------------------------------------------------------------------------------------------

	function getCongress($id = null) {

		$rst = $this->_db->Query("
			select
				con_id as id,
				con_name as name,
				unix_timestamp(con_date_signup) as date_signup,
				unix_timestamp(con_date_start) as date_start,
				unix_timestamp(con_date_end) as date_end
			from
				icp_congress
			where
				".(is_numeric($id) ? "id = ".$id : "con_date_end >= now()")."
			order by
				con_date_start desc
		", 0, 1);

		$return = $rst->Row();
		//$return['date_signup'] = date('d-m-Y', $return['date_signup']);
		//$return['date_start'] = date('d-m-Y', $return['date_start']);
		//$return['date_end'] = date('d-m-Y', $return['date_end']);
		$rst->Close();

		return $return;

	}
	/*
	 * Assign global template variables
	 */
	function assignGlobals() {
	}

	function showPlanner() {
	}

	function register($user, $congress, $preregistered = false, $code = null) {

		if (is_numeric($user) && is_numeric($congress))
			return $this->_db->Execute("replace into icp_signups set sig_usr_id = ".$user.", sig_con_id = ".$congress.", sig_preregistered = ".($preregistered ? 1 : 0).($code ? ", sig_code = '".$code."'" : ""));

		return false;

	}

}

?>