query($sql); $navSections = array(); while ($row = mysql_fetch_array($result)) { $navSections[$row['id']]['id'] = $row['id']; $navSections[$row['id']]['name'] = $row['name']; } //$navSections["resources"]['name'] = "Resources"; //////////////////////////////////////////////////////////////////////////////// // work out if we are in a category - if we are, display the sub-category links // and pages in the immediate category if ( isset($_GET['section'])) { // we are displaying a specific section // get all sub-sections of this section $sql = sprintf("SELECT * FROM sections WHERE parent = '%s'", makeSafe($_GET['section']) ); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $insideSections[$row['id']]['id'] = $row['id']; $insideSections[$row['id']]['name'] = $row['name']; } } // get all pages in this section $sql = sprintf("SELECT * FROM pages WHERE section = '%s' AND status = 'Publish'", makeSafe($_GET['section']) ); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $sectionPages[$row['id']]['id'] = $row['id']; $sectionPages[$row['id']]['title'] = $row['title']; } } // get the default page for this section $sql = sprintf("SELECT default_page FROM sections WHERE id = '%s'", makeSafe($_GET['section']) ); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { if (mysql_result($result, 0, "default_page") != "") { // a page exists! $sql = "SELECT * FROM pages WHERE id = '" . mysql_result($result, 0, "default_page") . "'"; $result = $mysql->query($sql); if (mysql_num_rows($result)) { $pageTitle = mysql_result($result, 0, "title"); $pageContent = mysql_result($result, 0, "content"); } } else { // no default page exists, so try to get ANY page $sql = sprintf("SELECT * FROM pages WHERE section = '%s' AND status='Publish'", makeSafe($_GET['section']) ); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { // pages exist in this section, so choose the first page $pageTitle = mysql_result($result, 0, "title"); $pageContent = mysql_result($result, 0, "content"); $pageID = mysql_result($result, 0, "id"); } else { // no pages exist in this section! header("Location: index.php"); } } } // get the parent sections of this section, if we're not in the top level $sql = sprintf("SELECT parent FROM sections WHERE id = %s", makeSafe($_GET['section'])); $result = $mysql->query($sql); if ($result) { $parent = mysql_result($result, 0, "parent"); } if ($_GET['section'] != "ROOT" && $parent != "ROOT") { $sql = sprintf("SELECT * FROM sections WHERE parent = %s", makeSafe($parent)); $result = $mysql->query($sql); while ($row = mysql_fetch_array($result)) { $aboveSections[$row['id']]['id'] = $row['id']; $aboveSections[$row['id']]['name'] = $row['name']; } } // work out our path, backwards to ROOT $cookieTrail[$_GET['section']]["link"] = "page.php?section=" . $_GET['section']; $cookieTrail[$_GET['section']]["title"] = $pageTitle; $cookieParent = sprintf("SELECT parent FROM sections WHERE id = %s", makeSafe($_GET['section'])); $result = $mysql->query($cookieParent); $section_id = mysql_result($result, 0, "parent"); // $cookieTrail[$_GET['section']]["link"] = "page.php?section=" . $_GET['section']; // $sql = sprintf("SELECT name FROM sections WHERE id = %s", // makeSafe($_GET['section'])); // $result = $mysql->query($sql); // $cookieTrail[$pageSection]["title"] = mysql_result($result, 0, "name"); while ($section_id != "ROOT") { $sql = sprintf("SELECT name FROM sections WHERE id = %s", makeSafe($section_id)); $result = $mysql->query($sql); $section_name = mysql_result($result, 0, "name"); $cookieTrail[$cookieParent]["link"] = "page.php?section=" . $section_id; $cookieTrail[$cookieParent]["title"] = $section_name; $sql = sprintf("SELECT parent FROM sections WHERE id = %s", makeSafe($section_id)); $result = $mysql->query($sql); $section_id = mysql_result($result, 0, "parent"); } $cookieTrail[SITE_URL]["link"] = "index.php"; $cookieTrail[SITE_URL]["title"] = "EUCU"; } else if ( isset($_GET['page']) ) { // we are displaying a specific page $pageID = $_GET['page']; // work out the section this page is in $sql = sprintf("SELECT * FROM pages WHERE id = '%s'", makeSafe($_GET['page'])); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { $pageSection = mysql_result($result, 0, "section"); $pageTitle = mysql_result($result, 0, "title"); $pageContent = mysql_result($result, 0, "content"); // get all sub-sections of this section $sql = sprintf("SELECT * FROM sections WHERE parent = '%s'", makeSafe($pageSection) ); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $insideSections[$row['id']]['id'] = $row['id']; $insideSections[$row['id']]['name'] = $row['name']; } } // get all pages in this section $sql = sprintf("SELECT * FROM pages WHERE section = '%s' AND status = 'Publish'", makeSafe($pageSection) ); $result = $mysql->query($sql); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $sectionPages[$row['id']]['id'] = $row['id']; $sectionPages[$row['id']]['title'] = $row['title']; } } // get the parent sections of this section, if we're not in the top level $sql = sprintf("SELECT parent FROM sections WHERE id = %s", makeSafe($pageSection)); $result = $mysql->query($sql); if ($result) { $parent = mysql_result($result, 0, "parent"); } if ($pageSection != "ROOT" && $parent != "ROOT") { $sql = sprintf("SELECT * FROM sections WHERE parent = %s", makeSafe($parent)); $result = $mysql->query($sql); while ($row = mysql_fetch_array($result)) { $aboveSections[$row['id']]['id'] = $row['id']; $aboveSections[$row['id']]['name'] = $row['name']; } } } else { // page doesn't exit $pageContent = "You have specified an invalid page."; $pageTitle = "Error 404 - Page Not Found"; } // work out our path, backwards to ROOT $cookieTrail[$_GET['page']]["link"] = "page.php?page=" . $_GET['page']; $cookieTrail[$_GET['page']]["title"] = $pageTitle; $cookieTrail[$pageSection]["link"] = "page.php?section=" . $pageSection; $sql = sprintf("SELECT name FROM sections WHERE id = %s", makeSafe($pageSection)); $result = $mysql->query($sql); $cookieTrail[$pageSection]["title"] = mysql_result($result, 0, "name"); $cookieParent = sprintf("SELECT parent FROM sections WHERE id = %s", makeSafe($pageSection)); $result = $mysql->query($cookieParent); $section_id = mysql_result($result, 0, "parent"); while ($section_id != "ROOT") { $sql = sprintf("SELECT name FROM sections WHERE id = %s", makeSafe($section_id)); $result = $mysql->query($sql); $section_name = mysql_result($result, 0, "name"); $cookieTrail[$cookieParent]["link"] = "page.php?section=" . $section_id; $cookieTrail[$cookieParent]["title"] = $section_name; $sql = sprintf("SELECT parent FROM sections WHERE id = %s", makeSafe($section_id)); $result = $mysql->query($sql); $section_id = mysql_result($result, 0, "parent"); } $cookieTrail[SITE_URL]["link"] = "index.php"; $cookieTrail[SITE_URL]["title"] = "EUCU"; } else { // we are not in a page or section - display the homepage header("Location: index.php"); } // remove the page that is being displayed from the sectionsPage array if (array_key_exists($pageID, $sectionPages)) { unset($sectionPages[$pageID]); } // remove the page that is being displayed from the sectionsPage array /* if (array_key_exists($pageID, $insideSections)) { unset($insideSections[$pageID]); }*/ //////////////////////////////////////////////////////////////////////////////// // Assign contents to variables for the template $smarty->assign('title', $pageTitle); // This is the page title, as displayed in the title bar $smarty->assign('content', $pageContent); // This is the page content! $smarty->assign('navSections', $navSections); // This is the links for the navigation bar $smarty->assign('insideSections', $insideSections); // This is for the sub-sections of this section $smarty->assign('sectionPages', $sectionPages); // This is for all the pages which belong to this category $smarty->assign('aboveSections', $aboveSections); // This is the sections in the parent of this section $smarty->assign('cookieTrail', array_reverse($cookieTrail)); //////////////////////////////////////////////////////////////////////////////// $smarty->display('page.tpl'); ?>