<?php 
/*    
 *    Copyright (c) 2010 VidiScript
 *
 *    This file is part of VidiScript.
 *
 *    VidiScript is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    VidiScript is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with VidiScript.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    File Name: index.php
 *    Description: Main index page - all site content is displayed through this page
 *    $Date: 2010-02-24 18:16:25 +0000 (Wed, 24 Feb 2010) $
 *    $Revision: 22 $
 */
session_start() ;
ini_set("magic_quotes_gpc", "0") ;
include_once 'includes/bootstrap.inc' ;
include_once 'includes/common.inc' ;
include_once 'includes/content.inc' ;
include_once 'includes/news.inc' ;
global $sitepath,$hidethumbnails,$hidemedia ;
$site_template = getSetting("sitetemplate", $db) ;
if (!file_exists("templates/".$site_template."/style.css")) {
	$site_template = "main" ;
	echo $site_template." not found using default" ;
}
//Get page title if it exists
if (isset($c_header)) {
	$s_header = str_replace("<strong>", "", $c_header) ;
	$s_header = str_replace("</strong>", "", $s_header) ;
	$s_header .= " - " ;
}
else {
	$s_header = "" ;
}
//Get installation folder from db
$sitefolder = getSetting("sitefolder", $db) ;
$langy = getSetting("language", $db) ;
$refer = $_SERVER['HTTP_REFERER'] ;
$refer = str_replace('http://', '', $refer) ;
$domain = explode("/", $refer) ;
$domainK = $domain[0] ;
$sql = "SELECT * FROM `ips` WHERE `ip` = CONVERT(_utf8 '".$_SERVER["REMOTE_ADDR"]."' USING latin1) COLLATE latin1_swedish_ci" ;
$check = $db->query($sql) or die("bad") ;
$check_ip = $db->numRows() ;
$sql = "SELECT * FROM `traffic` WHERE `Url` = CONVERT(_utf8 '".$domainK."' USING latin1) COLLATE latin1_swedish_ci" ;
$check2 = $db->query($sql) or die("bad2") ;
$check_refer = $db->numRows() ;
if (($check_ip == 0) && ($check_refer == 1)) //If the Query shows 0 results
 {
	$db->query("INSERT INTO ips (ip) VALUES ('".$_SERVER['REMOTE_ADDR']."')") ;
$db->query("UPDATE `traffic` SET `In` = `In` + 1 WHERE Url = '".$domainK."'") ;
}
//Path to the script
$path = "http://".$_SERVER['SERVER_NAME'].$sitefolder ;
?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
        <script type="text/javascript" src="<?php echo $sitepath?>js/swfobject.js">
        </script>
        <script>
            <!--
            function doBlink(){
                var blink = document.all.tags("blink")
                for (var i = 0; i < blink.length; i++) 
                    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : ""
            }
            function startBlink(){
                if (document.all) 
                    setInterval("doBlink()", 1500)
            }
            window.onload = startBlink;
            // -->
        </script>
		<script type="text/javascript" src="<?php echo $sitepath?>js/flowplayer-3.1.4.min.js"></script>
        <script src="<?php echo $path;?>js/Animated.js" language="javascript">
        </script>

        <meta name="description" content="<?php echo isset($mediaDescription)?$mediaDescription:"YOUR DESCRIPTION"; ?>">
        <meta name="keywords" content="<?php echo isset($mediaKeywords)?$mediaKeywords:"YOUR KEYWORDS"; ?>">
        <title><?php echo $s_header?><?php echo getSetting("sitename", $db)?>&nbsp;-&nbsp;
            <?php echo getSetting("sitetitle", $db)?>
        </title>
        <?php 
        if ($_GET['id'] >= 100) {
        ?>
        <link href="<?php echo $path;?>templates/default/admin.css" rel="stylesheet" type="text/css" />
        <?php 
        }
        ?>
        <link href="<?php echo $path;?>templates/<?php echo $site_template?>/style.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript">
            <!--
            //--><![CDATA[//><!--
            try {
                document.execCommand("BackgroundImageCache", false, true);
            } 
            catch (err) {
            }//--><!]]>
        </script>
        
    </head>
    <body>
        <div id="header">
            <div class="wrapper">
                <?php echo $headerad?>
                <a id="logo" href="#" title="Logo text here">Logo text here</a>
                <ul id="tab-menu" class="no-format">
                    <li<?php if ($_GET['id'] == 1) { echo " class=\"crt\"" ; } ?>>
                        <span><a href="<?php echo $path;?>">Home</a></span>
                    </li>
                    <li<?php if ($_GET['id'] == 2) { echo " class=\"crt\"" ; } ?>>
                        <span><a href="<?php echo $path;?>top_rated">Top Rated</a></span>
                    </li>
                    <li<?php if ($_GET['id'] == 3) { echo " class=\"crt\"" ; } ?>>
                        <span><a href="<?php echo $path;?>most_viewed">Popular</a></span>
                    </li>
                    <li<?php if ($_GET['id'] == 88) { echo " class=\"crt\"" ; } ?>>
                        <span><a href="<?php echo $path;?>members">Members</a></span>
                    </li>
                    <li<?php if ($_GET['id'] == 19) { echo " class=\"crt\"" ; } ?>>
                        <span><a href="<?php echo $path;?>groups">Groups</a></span>
                    </li>
                    <?php 
                    if ($loggedIn) {
                    ?>
                    <li>
                        <span><a href="<?php echo $path;?>logout">Log Out</a></span>
                    </li>
                    <?php 
                    }
                    else {
                    ?>
                    <li<?php if ($_GET['id'] == 6) { echo " class=\"crt\"" ; } ?>>
                        <span><a href="<?php echo $path;?>register">Register</a></span>
                    </li>
                    <?php 
                    }
                    ?>
                    <li<?php if ($_GET['id'] == 5) { echo " class=\"crt\"" ; } ?>>
                        <span><a href="<?php echo $path;?>upload">Upload</a></span>
                    </li>
                </ul>
            </div>
        </div>
        <?php 
        if (!checkBan($_SERVER['REMOTE_ADDR']) > 0) {
        ?>
        <div id="sub-bar">
            <div class="wrapper">
                <div id="top-search">
                    <?php echo searchBox()?>
                </div>
            </div>
        </div>
        <div id="content-area">
            <div id="main-col">
                <?php include_once ("templates/".$site_template."/modules/content.module")?>
            </div>
            <div id="right-col">
                <div class="inner">
                    <?php 
                    if (($loggedIn) && (($_SESSION['username']) != '')) {
                    	if ((!$accountManagementPage) || (getSetting("accountpageon", $db) == 0)) {                    		
                    ?>
                    <div id="right-top-wrap">
                        <div id="login-box">
                            <h2>Menu</h2>
                            Logged in as <?php echo $_SESSION['username'] ; ?>
                            <ul>
                                <li>
                                    <a href="<?php echo $sitepath?>account"><b>Account Management</b></a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/inbox">Inbox : <?php echo $numMessages?>
                                    </a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/outbox">Outbox : <?php echo $numSentMessages?>
                                    </a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/myfriends">My Friends : <?php echo $approvedFriends?>
                                    </a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/myreceivedrequests">Received Requests : <?php echo $receivedRequests?>
                                    </a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/mysentrequests">Sent Requests : <?php echo $sentRequests?>
                                    </a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/blocked">Blocked Members : <?php echo $numBlocked?>
                                    </a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/subscriptions">Subscriptions : <?php echo $numSubs?>
                                    </a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/favorites">Favorites : <?php echo $numFavorites?>
                                    </a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/media">My Media : <?php echo $numMedia?>
                                    </a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/managegroups">My Groups : <?php echo $numGroups?>
                                    </a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/profile?>">My Profile</a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/history">History</a>
                                </li>
                                <li>
                                    <a href="<?php echo $sitepath?>usermenu/profilehistory">Profile Views</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <?php 
                    }
          }
          else {          	
                    ?>
                    <div id="right-top-wrap">
                        <form method="post" action="<?php echo $sitepath?>includes/login.php">
                            <div id="login-box">
                                <h2>log in</h2>
                   <?php 
                   if (isset($_SESSION['loginerr'])) {
						echo "<h4>".$_SESSION['loginerr']."</h4><br>" ;
						unset($_SESSION['loginerr']) ;
	               }
                   ?>
                                <h4>username</h4>
                                <div class="login-field">
                                    <input tabindex="1" value="" name="user" type="text" class="field" />
                                </div><h4>password</h4>
                                <div class="login-field">
                                    <input tabindex="1" name="pass" type="password" class="field" />
                                </div>
                                <div id="lost-passw">
                                    <a href="<?php echo $sitepath?>forgot" title="Click here to recover your password">
                                        <u>
                                            Lost Password ?
                                        </u>
                                    </a>
                                    <input value="log in" name="" type="submit" id="login-btn" />
                                </div>
                                <p>
                                    No account yet ? <a href="<?php echo $sitepath?>register" title="Click here to create new account">
                                        <u>
                                            Register
                                        </u>
                                    </a>
                                </p>
                                <label>
                                    <input name="" type="checkbox" value="" />Remember me
                                </label>
                            </div>
                        </form>
                    </div><?php } ?><? eval(menuBlocks()) ; ?>
                    <div id="right-col-content">
                        <div class="spacing">
                            <a href="<?=$sitepath?>news/"><h2><img border=0 src="<?=templateimagepath()?>icn_categories.jpg" alt="" />News </h2></a>
                            <br/>
                            <br/>
                            <? 
                            $toEcho = ReturnSideBarNews() ;
                            echo $toEcho ;
                            ?>
                        </div>
                        <? include_once "templates/".$site_template."/modules/tags.module" ; ?><? include_once "templates/".$site_template."/modules/showfriendsbar.module" ; ?><?= $adblock1?>
                    </div>
                </div>
            </div>
            <?php 
            }
            else {     	
            ?>
            <div id="sub-bar">
                <div class="wrapper">
                </div>
            </div>
            <div id="content-area">
                <div id="main-col" align=center>
                    <h1><b>You have been banned by admin</b></h1>
                </div>
            </div>
            <?php 
            }
            ?>
            <div id="copyright-bar">
                <div class="wrapper">
 <h4><a href="http://www.vidiscript.co.uk">Free Open Source Video Sharing Script</a>&nbsp;<b>Powered By</b>&nbsp;<a href="http://www.vidiscript.co.uk">VidiScript 1.0.3a</a></h4> |    <b>
                    <a href="<?=$sitepath."rss.php"?>"> Rss Feed</a>
                    </span>
                </div>
            </div>
            <div id="footer">
            </div>
            </body>
        </html>