<?	
require_once('control/include/user.php');
require_once('control/include/mysql.php');
require_once('control/include/functions.php');
require_once('control/Rmail/Rmail.php');
require_once('control/include/fb.php');
/* require_once('currency.php'); */

ob_start();
session_start();

// COOKIE SETUP FOR BASKET
$session_id = session_id();
if (isset($_COOKIE['session_id'])) {
    $session_id = $_COOKIE['session_id'];
} else {
    setcookie('session_id', $session_id, time() + (60 * 60 * 24 * 7 * 4 * 3), "/", "", 0);
}

// SETUP MYSQL HANDLERS
$mysqldb1 = new mysql($host, $user, $pswd, $db);
$mysqldb1->connect();
$mysqldb1->select();
$mysqldb2 = new mysql($host, $user, $pswd, $db);
$mysqldb2->connect();
$mysqldb2->select();
$mysqldb3 = new mysql($host, $user, $pswd, $db);
$mysqldb3->connect();
$mysqldb3->select();
$mysqldb4 = new mysql($host, $user, $pswd, $db);
$mysqldb4->connect();
$mysqldb4->select();

// PAGE ENGINE
$_SESSION['page'] = str_replace(" ", "_", strtolower($_GET['page']));

// BRING UP THE HOME PAGE
if ($_SESSION['page'] == '') {
    $query = "SELECT name FROM page WHERE home=1";
    $mysqldb1->query($query);
    $page = $mysqldb1->fetchArray();
    $_SESSION['page'] = $page['name'];
}

$page_url = 'website/include/'.$_SESSION['page'].'.php';
if (!file_exists($page_url)) {
    $page_url = 'website/include/page.php';
}
fb($page_url);
// --PAGE ENGINE

// SECTION: SEO
$query = "SELECT * FROM page WHERE name='".$_SESSION['page']."'";
$mysqldb1->query($query);
if ($mysqldb1->affectedRows() == 1) {
    $page = $mysqldb1->fetchArray();

    switch ($_SESSION['page']) {
        case 'news_detail':

            $query = "SELECT * FROM news WHERE link_name='".$_GET['link_name']."'";
            $mysqldb1->query($query);
            $news = $mysqldb1->fetchArray();

            $meta_title = $news['headline'];
            $meta_page = strtolower($meta_title);
            $meta_description = $news['headline'];
            $meta_keywords = strtolower($meta_title);

            break;
        case 'event_detail':

            $query = "SELECT * FROM event WHERE link_name='".$_GET['link_name']."'";
            $mysqldb1->query($query);
            $event = $mysqldb1->fetchArray();

            $meta_title = $event['name'];
            $meta_page = strtolower($meta_title);
            $meta_description = $event['name'];
            $meta_keywords = strtolower($meta_title);

            break;
        case 'article_detail':

            $query = "SELECT * FROM article WHERE link_name='".$_GET['link_name']."'";
            $mysqldb1->query($query);
            $article = $mysqldb1->fetchArray();

            $meta_title = $article['name'];
            $meta_page = strtolower($meta_title);
            $meta_description = $article['name'];
            $meta_keywords = strtolower($meta_title);

            break;
        case 'newsletter_detail':

            $query = "SELECT * FROM newsletter WHERE link_name='".$_GET['link_name']."'";
            $mysqldb1->query($query);
            $newsletter = $mysqldb1->fetchArray();

            $meta_title = $newsletter['heading'];
            $meta_page = strtolower($meta_title);
            $meta_description = $newsletter['heading'];
            $meta_keywords = strtolower($meta_title);

            break;
        default:
            $meta_title = $page['title'];
            $meta_page = strtolower($meta_title);
            $meta_description = $page['title'];
            $meta_keywords = strtolower($meta_title);

            // PATCH: For older sites that might not be using the title field yet
            if ($page['title'] == '') {
                $meta_title = $page['heading'];
                $meta_page = strtolower($meta_title);
                $meta_description = $page['heading'];
                $meta_keywords = strtolower($meta_title);
            }
    }

}
// --SEO
//fb($query);
fb('page: '.$_SESSION['page']);
$webceo_page = $meta_title;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title><? print $meta_title; ?></title>
        <meta name="Description" content="<? print $meta_description; ?>" />
        <meta name="Keywords" content="<? print $meta_keywords; ?>" />
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <meta http-equiv="pragma" content="no-cache" />
        <link type="text/css" rel="stylesheet" href="/control/styles/tinymce.css" />
        <link type="text/css" rel="stylesheet" href="/website/styles/default/website.css" />
        <!--JQUERY-->
        <link type="text/css" rel="stylesheet" href="/control/scripts/shadowbox-3.0.2/shadowbox.css" />
        <link type="text/css" rel="stylesheet" href="/control/styles/smoothness/jquery.ui.css" />
        <script type="text/javascript" src="/control/scripts/jquery.js"></script>
        <script type="text/javascript" src="/control/scripts/shadowbox-3.0.2/shadowbox.js"></script>
        <script type="text/javascript" src="/control/scripts/jquery.ui.js"></script>
        <script type="text/javascript" src="/control/scripts/jquery.cycle.js"></script>
        <script type="text/javascript" src="/control/scripts/jquery.charcounter.js"></script>
        <script type="text/javascript" src="/control/scripts/jquery.tools.min.js"></script>
        <script type="text/javascript" src="/control/scripts/jquery.autogrow.textarea.js"></script>
        <!--/JQUERY-->
        <!--MENU-->
        <link type="text/css" rel="stylesheet" media="screen" href="/website/scripts/superfish/css/superfish.css" />
        <link type="text/css" rel="stylesheet" media="screen" href="/website/scripts/superfish/css/superfish-vertical.css" />
        <script type="text/javascript" src="/website/scripts/superfish/js/hoverIntent.js"></script>
        <script type="text/javascript" src="/website/scripts/superfish/js/superfish.js"></script>
        <script type="text/javascript" src="/website/scripts/superfish/js/supersubs.js"></script>
        <!--/MENU-->
        <!--FORMS-->
        <script type="text/javascript" src="/control/scripts/jquery.validate.js"></script>
        <!--FORMS-->
        <!--CUSTOM-->
        <script type="text/javascript" src="/control/scripts/php.js"></script>
        <script type="text/javascript" src="/control/scripts/md5.js"></script>
        <script type="text/javascript" src="/website/scripts/custom.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                //fetchAdverts('<? print $_SESSION['page']; ?>', 'right', '#right_advert');
                //fetchAdverts('<? print $_SESSION['page']; ?>', 'left', '#left_advert');
            });
            $(document).ready(function() {
                //fetchMenu('left', '#left_menu');
                $("ul.sf-menu").superfish({ dropShadows : false });
                fetchNews(3);
                //fetchEvents(3);
                //fetchCalendar();
                fetchSnippet('news', 3);
                //fetchSnippet('events', 3);
                //fetchSnippet('articles', 3);
                //fetchSlideshow('.slideshow1', 980, 370);
            });
            $(document).ready(function() {
                fetchImages('#news_images', 'news', '<? print $_GET['link_name']; ?>');
                //fetchImages('#event_images', 'event', '<? print $_GET['link_name']; ?>');
                //fetchImages('#article_images', 'article', '<? print $_GET['link_name']; ?>');
                //fetchGallery(<? print $_GET['gallery_id']; ?>);
            });
            $(document).ready(function() {
                if ($('#page_header').html() == '') {
                    $('#page_header').hide();
                }
                $("#signup").validate({
                    submitHandler: function(form) {
                        emailExists('contact', $('#email').val(), form);
                    }
                });
                $("input:submit", ".form").button();
                Shadowbox.setup(".popup");
            });
        </script>
        <!--/CUSTOM-->
    </head>
    <body>
        <div id="page">
            <div id="frame">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td id="header" colspan="3">
                            <div class="meta_top"><? print $meta_page; ?></div>
                            <div id="overlay_logo"></div>
                            <div id="header_slideshow" class="slideshow1"></div>
                        </td>
                    </tr>
                    <tr>
                        <td id="left_border">&nbsp;</td>
                        <td>
                            <div id="top_menu"></div>
                            <div style="float:left; width:980px;">
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td id="left_column">
                                            <div id="left_menu"><? $position = 'left'; require_once('website/include/menu.php'); ?></div>
                                            <div class="module"><? $position = 'left'; require('website/include/module.php'); ?></div>
                                        </td>
                                        <td id="include"><? require_once($page_url); ?></td>
                                        <td id="right_column">
                                            <div id="basket"></div>
                                            <div id="news_images"></div>
                                            <div id="event_images"></div>
                                            <div id="article_images"></div>
                                            <div class="module"><? $position = 'right'; require('website/include/module.php'); ?></div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                        <td id="right_border">&nbsp;</td>
                    </tr>
                </table>
                <div id="footer">&copy; RAM Consulting (PTY) LTD - 2010 | <a href="/sitemap.php" target="_self">Site Map</a> | <a href="/page/links" target="_self">Links</a></div>
                <div class="meta">
                    <p><? print $meta_page; ?></p>
                    <? require_once ('links.php'); ?>
                </div>
            </div>
        </div>
        <?
        if ($webceo_id != '') {
            ?>
        <!--WEBSITECEO:BEGIN:{764EEF2E-BC11-45CF-8627-300CE1BA2219}-->
        <!--
        Do NOT modify this script to avoid traffic misrepresentation!
        Web CEO 4 0300/1
        Code initially inserted into: "/index.php".
        -->
        <script type="text/javascript"><!--
            // hitlens v1.2.7
            function hitlens_embedded() {
                var id = <? print $webceo_id; ?>;
                var pc = 1;
                var PAGENAME = escape('<? print $webceo_page; ?>');
                var CONTENTGROUP = escape('');
                var TRANSACTION = escape('');
                var TRANSACTION_ID = 0;
                var ORDER = escape('');
                return "id="+id+"&pc="+pc+"&p="+PAGENAME+"&gr="+CONTENTGROUP+"&tr="+TRANSACTION+"&trid="+TRANSACTION_ID+"&ord="+ORDER;
            }
            //--></script>
        <script type="text/javascript" src="/webceo.js"></script>
        <!--WEBSITECEO:END:{764EEF2E-BC11-45CF-8627-300CE1BA2219}-->
            <?
        }
        ?>
    </body>
</html>
<?
$mysqldb1->close();
$mysqldb2->close();
$mysqldb3->close();
$mysqldb4->close();
?>