<?php
require_once "HTML/Template/IT.php";
require "inc/cms.inc";
define( "menuLine", " <li CLASS><a href=\"sam.php?page=PAGE\"><em>DISPLAY_NAME</em></a></li>\n");
define( "menuNotLoggedIn", "<fieldset>\n <legend>Login hier !</legend>\n <form method=\"post\" action=\"login.php\">\n <fieldset>\n <p><label for=\"username\">Naam :</label><br /><input name=\"fname\" id=\"username\" value=\"voornaam\" type=\"text\" onfocus=\"value=''\" /><br /><input name=\"lname\" value=\"familienaam\" type=\"text\" onfocus=\"value=''\" /></p>\n <p><label for=\"paswoord\">Paswoord :</label><br /><input name=\"pass\" id=\"paswoord\" type=\"password\" /></p>\n <input value=\"Aanmelden\" name=\"submit\" type=\"submit\" />\n </fieldset>\n </form>\n </fieldset>\n");
define( "menuLoggedIn", "<fieldset>\n <legend>Welkom !</legend>\n <form method=\"post\" action=\"logout.php\"><fieldset>\n <p>U bent ingelogd als<br />FNAME LNAME</p>\n <input value=\"Uitloggen\" name=\"submit\" type=\"submit\" /></fieldset></form> <a href=\"sam.php?page=personal\"> Mijn pagina </a> </fieldset>\n");
define( "contextMenu", "<fieldset>\n <div id=\"contextmenu\">\n <h1>PAGE</h1><br/>\nCONTEXT_LINE </div>\n </fieldset>\n");
header("Vary: Accept");
if (stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")):
header("Content-Type: application/xhtml+xml; charset=utf-8");
else:
header("Content-Type: text/html; charset=utf-8");
endif;
function setVars ($scope, $ITtemplate)
{
while ($row = mysql_fetch_array($scope))
{ $ITtemplate->setVariable(strtoupper($row["name"]), $row["code"]); }
return $ITtemplate;
}
/* initialisations */
if (!$page = $_GET['page']): $page = "news"; endif;
$connection = connectCMS();
$template = new HTML_Template_IT("./templates");
$template->loadTemplatefile("default.tpl", true, true);
$template->setCurrentBlock("GENERAL");
session_start();
$loggedIn = FALSE;
/* logged in ? */
if ($sessionID = session_id()) { // Assign the current session's ID to $sessionID
//if ($sessionID = $_COOKIE["samConn"])
//{
// $content = mysql_query ("SELECT u.lname,u.fname,u.classID,u.usertype from connections c,users u WHERE c.ID=$sessionID AND c.userID=u.autoID AND c.lname=u.lname", $connection) or die(mysql_error());
$content = mysql_query ("SELECT u.lname,u.fname,u.classID,u.usertype from loggedInUsers l,users u WHERE l.sessionID=\"$sessionID\" AND l.userID=u.autoID AND l.lname=u.lname", $connection) or die(mysql_error());
if ($row = mysql_fetch_array($content)): $loggedIn = TRUE; endif;
$lname = $row["lname"]; $fname = $row["fname"]; $loggedInUsertype = $row["usertype"];
};
/* fill in the location
This happens first, I am retrieving data for further in the page too*/
$tmpPage = $page;
$EOList = FALSE;
while (!$EOList) {
$content = mysql_query ('SELECT name,display_name,parentID,orderID FROM pages WHERE name="'. $tmpPage .'"', $connection) or die(mysql_error());
$row = mysql_fetch_array($content);
if ($row["name"] == $page): $pageDisplayName = $row["display_name"]; endif; /* this will be needed further on */
$tmpLocation = '<a href="sam.php?page='. $row["name"] .'">'. $row["display_name"] .'</a>' .$tmpLocation;
if (!$tmpPage = $row["parentID"]):
$EOList = TRUE;
else:
$tmpLocation = ' / ' .$tmpLocation;
if ($tmpPage != "/"): $parentPage = $tmpPage; endif;
endif;
}
$template->setVariable("LOCATION", $tmpLocation);
/* fill in the info all pages have in common */
$content = mysql_query ('SELECT name,code FROM content WHERE page="all"', $connection) or die(mysql_error());
$template = setVars ($content, $template);
/* fill in the page specific info */
$content = mysql_query ('SELECT name,code FROM content WHERE page="'. $parentPage .'" AND NOT (name="'. $page .'") UNION ALL SELECT name,code FROM content WHERE page="'. $page .'"', $connection) or die(mysql_error());
$template = setVars ($content, $template);
/* create the menu */
$contentMenu = mysql_query ('SELECT name,display_name,orderID FROM pages WHERE parentID="/" ORDER BY orderID', $connection) or die(mysql_error());
while ($row = mysql_fetch_array($contentMenu)) {
$tmpMenuLine = menuLine;
$tmpMenuLine = str_replace("PAGE", $row["name"], $tmpMenuLine);
$tmpMenuLine = str_replace("DISPLAY_NAME", $row["display_name"], $tmpMenuLine);
if ($row["name"] == $page): $tmpMenuLine = str_replace("CLASS",'class="active"',$tmpMenuLine); else: $tmpMenuLine = str_replace("CLASS","",$tmpMenuLine); endif;
$menu .= $tmpMenuLine;
}
$template->setVariable("MENU", $menu);
/* show the correct LOGIN or LOGOUT window */
if ($loggedIn)
{
$tmpMenuLoggedIn = str_replace("FNAME",$fname,menuLoggedIn);
$tmpMenuLoggedIn = str_replace("LNAME",$lname,$tmpMenuLoggedIn);
$template->setVariable("RIGHT_LOGIN", $tmpMenuLoggedIn);
}
else { $template->setVariable("RIGHT_LOGIN", menuNotLoggedIn); }
/* assemble the context menu if needed */
#$context = mysql_query ("SELECT name,display_name FROM pages WHERE parentID=\"$page\" OR parentID=\"admin\" ORDER BY parentID,orderID", $connection) or die(mysql_error());
$context = mysql_query ("SELECT name,display_name FROM pages WHERE parentID=\"$page\" ORDER BY orderID", $connection) or die(mysql_error());
while ($row = mysql_fetch_array($context)) {
$contextLine .= " <a href=\"sam.php?page=". $row["name"] ."\">". $row["display_name"] ."</a><br />\n";
}
if ($contextLine)
{
$tmpContextMenu = contextMenu;
$tmpContextMenu = str_replace( "PAGE", $pageDisplayName, $tmpContextMenu );
$tmpContextMenu = str_replace( "CONTEXT_LINE", $contextLine, $tmpContextMenu);
}
/* assemble the ADMIN contextmenu */
if (($loggedIn) && ($loggedInUsertype <= 1))
{
$contextLine = "";
$context = mysql_query ("SELECT name,display_name FROM pages WHERE parentID=\"admin\" ORDER BY orderID", $connection) or die(mysql_error());
while ($row = mysql_fetch_array($context)) {
if ($row["name"] == "cms")
{
$contextLine .= " <a href=\"admin/cmsadmin.php\">". $row["display_name"] ."</a><br />\n";
} else
{
$contextLine .= " <a href=\"sam.php?page=". $row["name"] ."\">". $row["display_name"] ."</a><br />\n";
};
}
$tmpContextMenu .= contextMenu;
$tmpContextMenu = str_replace( "PAGE", "Admin", $tmpContextMenu );
$tmpContextMenu = str_replace( "CONTEXT_LINE", $contextLine, $tmpContextMenu);
}
$tmpLeftContext .= " <div class=\"shadow\"><img src=\"gallery/$album/thumbs/small/".$row["image"]."\" /></div>\n";
$tmpLeftContext .= " <ul><li class=\"gallery_title\">".$row["name"]."</li><li class=\"gallery_desc\">".$albumDesc."</li></ul>\n";
if ($contextLine): $template->setVariable("RIGHT_CONTEXT", $tmpContextMenu); endif;
/* assemble the LEFT context menu if needed */
if (substr($page,0,7)=="gallery") {
$tmpLeftContext = "";
$contentLeftContext = mysql_query ('SELECT * FROM galleries ORDER BY uploaded_on', $connection) or die(mysql_error());
$tmpLeftContext .= "Kies je album hier: \n";
$tmpLeftContext .= "<div class=\"galleries\">\n";
while ($row = mysql_fetch_array($contentLeftContext)) {
# if ($i==1): $tmpLeftContext .= "<ul>\n<li><a href=\"#nogo\">$i\n<!--[if IE 7]><!-->\n</a>\n<!--<![endif]-->"; endif;
$album = str_replace (" ", "", $row["name"]);
$albumDesc = $row["description"];
if (strlen($albumDesc)>15): $albumDesc = substr($albumDesc,0,11)." ..."; endif;
$tmpLeftContext .= " <div class=\"galleryElem\">\n <a href=\"sam.php?page=gallery_$album\">\n";
$tmpLeftContext .= " </a>\n </div>\n";
# if ($i==1): $tmpLeftContext .= "<!--[if lte IE 6]>\n</a>\n<![endif]-->\n</li>"; endif;
# if ($i==1): $tmpLeftContext .= " </a>\n</li>\n"; endif;
};
$tmpLeftContext .= "</div>\n";
$template->setVariable("LEFT_CONTEXT", $tmpLeftContext);
};
//
//
//
//
/* finish up */
$template->parseCurrentBlock();
$template->show();
?>