1<?php 2require_once 'conf.php'; 3require_once 'createlu.php'; 4require_once 'HTML/Template/IT.php'; 5 6// Setup template objects 7 8if (!$usr->isLoggedIn()) { 9 $tpl = new HTML_Template_IT('./'); 10 $tpl->loadTemplatefile('login_form.tpl', true, false); 11 $login = $tpl->get(); 12} else { 13 $login = '<p>User: ' . $usr->getProperty('handle') . ' !</p>'; 14 $login .= '<p><a href="admin.php">Go to the admin part</a></p>'; 15 $login .= '<p><a href="?logout=1">Logout</a></p>'; 16} 17 18$tpl = &new HTML_Template_IT('./'); 19$tpl->loadTemplatefile('home.tpl', true, true); 20 21// assign the content to the vars 22$tpl->setVariable('GENERALNEWS', getNews($db, 'general')); 23$tpl->setVariable('LOGIN', $login); 24 25$tpl->show(); 26 27// This function is to fetch news from the MDB2 28function getNews(&$db, $newsCategory) 29{ 30 $query = " 31 SELECT 32 news_id AS id, 33 DATE_FORMAT(news_date, '%D %b %Y at %H:%I:%S') AS date, 34 news_title AS title, 35 news_content AS content 36 FROM 37 news 38 WHERE 39 news_category = '$newsCategory' 40 AND 41 news_id<>0 42 ORDER BY 43 date ASC"; 44 45 $news = $db->queryAll($query, null, MDB2_FETCHMODE_ASSOC, true); 46 47 if (PEAR::isError($news)) { 48 die($news->getMessage() . ' ' . $news->getUserinfo()); 49 } else { 50 $tpl = new HTML_Template_IT('./'); 51 52 $tpl->loadTemplatefile('news.tpl', true, true); 53 54 foreach ($news as $name) { 55 $tpl->setCurrentBlock('row'); 56 $tpl->setVariable('DATE', $name['date']); 57 $tpl->setVariable('TITLE', $name['title']); 58 $tpl->setVariable('CONTENT', $name['content']); 59 $tpl->parseCurrentBlock('row'); 60 } 61 return $tpl->get(); 62 } 63} 64?> 65