Location: PHPKode > projects > SOS Webpages > includes/queries.php
<?php
// +----------------------------------------------------------------------+
// SOS Webpages is an easy-to-manage website management system
// Copyright (C) 2007 - 2010 HandsomeWeb
//
// This program 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.
//
// This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
// Contact the author of this software at http://www.handsomeweb.com.
// +----------------------------------------------------------------------+

/*	includes/queries.php queries most of the data that is common site-wide. It also gets information about the page
	that is being build so that the correct module and correct template will be used. dbconnection.php is created
	at installation and contains database connection information. $dbprefix is the prefix on table names. */

// Define some variables
$i=0;
$pages_id="";
$pages_uri="";
$admin="";

Require "dbconnection.php";

$dbh=mysql_connect($dbhhost,$dbhuser,$dbhpassword) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db($dbhdatabasename);

// Query Admin Data
$query = "SELECT * FROM " . $dbprefix . "hw_admin WHERE admin_id=1";
$result=mysql_query($query);
$num=mysql_num_rows($result);
$admin_email=mysql_result($result,$i,"admin_email");
$admin_user=mysql_result($result,$i,"admin_user");

// Query Site Data
$query = "SELECT * FROM " . $dbprefix . "hw_site WHERE site_id=1";
$result=mysql_query($query);
$num=mysql_num_rows($result);
$site_name=mysql_result($result,$i,"site_name");
$site_uri=mysql_result($result,$i,"site_uri");
$site_banner_image="uploads/" . mysql_result($result,$i,"site_banner_image");
$site_logo="uploads/" . mysql_result($result,$i,"site_logo");
$site_tagline=mysql_result($result,$i,"site_tagline");
$site_templates_id=mysql_result($result,$i,"site_templates_id");
$site_default_pages_id=mysql_result($result,$i,"site_default_pages_id");
$site_long_description=mysql_result($result,$i,"site_long_description");
$site_language_file="languages/" . mysql_result($result,$i,"site_language_file");

Require $site_language_file;

// Query Template Data
$query = "SELECT * FROM " . $dbprefix . "hw_templates WHERE templates_id='$site_templates_id'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
$templates_id=mysql_result($result,$i,"templates_id");
$templates_name=mysql_result($result,$i,"templates_name");
$templates_folder=mysql_result($result,$i,"templates_folder");

// Query Page Data using $pages_id (integer or default page loads to determine
// page $pages_uri is just in there to put keywords in URI for search engines

if (isset($_GET['pages_id'])) {
	$pages_id = trim(mysql_real_escape_string(stripslashes($_GET['pages_id'])));
	if (isset($_GET['pages_uri'])) {
		$pages_uri = trim(mysql_real_escape_string(stripslashes($_GET['pages_uri'])));
		}
	}
if ($pages_id=="" OR !preg_match( "/^([0-9])+$/", $pages_id)) $pages_id=$site_default_pages_id;
   
//Query the page
$query = "SELECT * FROM " . $dbprefix . "hw_pages WHERE pages_id='" . $pages_id . "'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
//If page does not exist re-query for default page
if ($num==0) {
	$query = "SELECT * FROM " . $dbprefix . "hw_pages WHERE pages_id='" . $site_default_pages_id . "'";
	$result=mysql_query($query);
	$num=mysql_num_rows($result);
	}
$num=mysql_num_rows($result);
$pages_id=mysql_result($result,$i,"pages_id");
$pages_title=mysql_result($result,$i,"pages_title");
$pages_uri=mysql_result($result,$i,"pages_uri");
$pages_modules_id=mysql_result($result,$i,"pages_modules_id");
$pages_parent_id=mysql_result($result,$i,"pages_parent_id");
$pages_description=mysql_result($result,$i,"pages_description");
$pages_keywords=mysql_result($result,$i,"pages_keywords");

//Query Modules Data
$query = "SELECT * FROM " . $dbprefix . "hw_modules WHERE modules_id='$pages_modules_id'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
$modules_id=mysql_result($result,$i,"modules_id");
$modules_name=mysql_result($result,$i,"modules_name");
$modules_filename=mysql_result($result,$i,"modules_filename");

// Add an Edit link if the site administrator is logged in.
if (isset($_COOKIE["admin"])) {
	$admin = trim(mysql_real_escape_string(stripslashes($_COOKIE["admin"])));
	if ($admin=="admin") $site_long_description .= "<br/><br/><a class='admincontent' href='admin/admin_site_info.php?sitelink=true'>". EDIT_LONG_DESCRIPTION . "</a>";
	}
mysql_close();
?>
Return current item: SOS Webpages