<?php

require_once("common.php");

foreach(query_array("			##########################################################
					SELECT	activity,
						date,
						location,
						IF(ISNULL(dates.start)	,activities.start	,dates.start	) AS start,
						IF(ISNULL(dates.end)	,activities.end		,dates.end	) AS end,
#//        addr: null,
#//        city: null,
#//        title: Generalforsamling --DATO--,
#//        linux_in_mail: 2,
#//        other_in_mail: null,
#//        opraab: null,
#//        info: null
						'x'
					FROM	dates
					LEFT JOIN activities USING(activity)
					WHERE	date >= DATE(NOW()) ".
							(isset($_GET["limit"]) &&
									($_GET["limit"] == "month" || $_GET["limit"] == "year")
								? "AND"."\r\n\t\t\t\t\t\t".
									"date <= DATE(".
											"DATE_ADD(".
											"DATE_ADD(".
												"NOW()".
													", INTERVAL 1 WEEK)".
													", INTERVAL 2 ".$_GET["limit"].")".
											")"
								: "") ."
					ORDER BY
						date
					".
						(isset($_GET["limit"]) && is_numeric($_GET["limit"]) ? "LIMIT ".$_GET["limit"] : "" ).
																"
					##########################################################") AS $id => $event) {
	if ($s = iconv("ISO-8859-1","UTF-8",$event->activity)) $event->activity = $s;
	if ($s = iconv("ISO-8859-1","UTF-8",$event->location)) $event->location = $s;
	$events[$event->date] = $event;
}

echo json_encode($events,JSON_PRETTY_PRINT);
