<?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: bootstrap.inc
 *    Description: Media url and category functions 
 *    $Date: 2010-02-21 23:07:37 +0000 (Sun, 21 Feb 2010) $
 *    $Revision: 10 $
 */
 
include_once 'includes/mysql.inc' ;
include_once 'includes/functions.inc' ;
include_once 'includes/logged.inc' ;
$country = '' ;
global $db;
$sitefolder = getSetting("sitefolder", $db) ;
$sitepath = "http://".$_SERVER['SERVER_NAME'].$sitefolder ;
if (class_exists("mysql")) {
      $db = db_connect() ;
}
//Handle query string
if (isset($_GET['crw'])) {
      define('enc_CAT', url_encode($_GET['crw'])) ;
      define('dec_CAT', url_decode($_GET['crw'], "cat")) ;
}
if (isset($_GET['scrw'])) {
      define('enc_SCAT', url_encode($_GET['scrw'])) ;
      define('dec_SCAT', url_decode($_GET['scrw'], "scat", dec_CAT)) ;
}
if (isset($_GET['sscrw'])) {
      define('enc_SSCAT', url_encode($_GET['sscrw'])) ;
      define('dec_SSCAT', url_decode($_GET['sscrw'], "sscat", dec_SCAT)) ;
}
if (isset($_GET['vrw'])) {
      define('enc_VID', url_encode($_GET['vrw'])) ;
      define('dec_VID', url_decode($_GET['vrw'], "vid")) ;
}
if (isset($_GET['id'])) {
      $_this['id'] = $_GET['id'] ;
}
if (!isset($_GET['id'])) {
      $_GET['id'] = 1 ;
}
if (defined("dec_VID")) {
      $catid = '' ;
      $db->query("SELECT id,ptr FROM `category` WHERE `name` = '".quote_smart(dec_CAT)."'") ;
      $catres = $db->fetch() ;
      if ($catres['ptr'] != 0) {
            $catres['id'] = $catres['ptr'] ;
      }
      $catid = $catres['id'] ;
      if (defined('dec_SCAT')) {
            $db->query("SELECT id, ptr FROM `category` WHERE `name` = '".quote_smart(dec_SCAT)."' AND `parent` = '".$catid."';") ;
            $catres = $db->fetch() ;
            $catid = $catres['id'] ;
      }
      if (defined('dec_SSCAT')) {
            $db->query("SELECT id, ptr FROM `category` WHERE `name` = '".quote_smart(dec_SSCAT)."' AND `parent` = '".$catid."';") ;
            $catres = $db->fetch() ;
            $catid = $catres['id'] ;
      }
      $db->query("SELECT description,tags, thumb FROM `media` WHERE title = '".quote_smart(dec_VID)."' AND `category` = '".$catid."'") ;
      $res = $db->fetch() ;
      $mediaKeywords = $res['tags'] ;
      $mediaDescription = str_replace("\"", "&quot;", $res['description']) ;
      $mediathumb = $res['thumb'] ;
}
?>