/*
phpGuestsFunc.inc
Functions for phpGuests
######################################################################
# You can use and modify this software, provided that #
# this header appear on all copies of the software. You may not #
# sell this software to anyone or distribute it in any way #
######################################################################
######################################################################
# This software is provided "AS IS," without a warranty of any kind. #
# Ray L. Cuzzart II or Cuzzart's Web Design DON'T TAKE ANY #
# RESPONSABILITY FOR ANY DAMAGES SUFFERED AS A RESULT OF USING, #
# MODIFYING OR DISTRIBUTING THE SOFTWARE. IN NO EVENT WILL #
# Ray L. Cuzzart II OR Cuzzart's Web design BE LIABLE FOR ANY LOST #
# REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, #
# CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED #
# AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE #
# USE OF OR INABILITY TO USE SOFTWARE, EVEN IF #
# Cuzzart's Web Design and / or Ray L. Cuzzart II HAS BEEN ADVISED #
# OF THE POSSIBILITY OF SUCH DAMAGES. #
######################################################################
*/
// First we need to require the file that
// has our variables in it.
require "phpGuestsConfig.php";
// Now we can start setting up the functions
function addentry ($cat_id, $guest_name, $guest_location, $guest_email, $guest_url, $guest_message, $guest_ip, $guest_icq) {
// We need to set the globals for later use.
global $db,$dbuser,$dbpass,$dbgtbl,$dbhost;
$guest_name = htmlspecialchars($guest_name);
$guest_location = htmlspecialchars($guest_location);
$guest_email = htmlspecialchars($guest_email);
$guest_url = htmlspecialchars($guest_url);
$guest_message = htmlspecialchars($guest_message);
$guest_message = nl2br($guest_message);
$guest_icq = htmlspecialchars($guest_icq);
$post_date = date("Y-m-d g:i:s");
$entry = "INSERT INTO $dbgtbl(cat_id,guest_name,guest_location,guest_email,guest_url,guest_message,guest_ip,guest_icq,post_date)
VALUES('$cat_id', '$guest_name', '$guest_location', '$guest_email', '$guest_url', '$guest_message', '$guest_ip', '$guest_icq', '$post_date')";
// Lets connect to the mysql database
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to $db");
// Lets change to the database we want to use
mysql_select_db($db) or die("Unable to select $db");
// Lets process the insert into the database
$insert = mysql_query($entry) or die("Unable to add entry to $dbgtbl");
mysql_close($connect);
// Let check to see if the entry was added.
// If it was then we send back an ok if not
// then we send back a not ok.
if ($insert){
return (1);
}else{
return (0);
}
}
function showcats () {
global $dbhost,$dbuser,$dbpass,$db,$dbctbl;
$connect = mysql_connect ($dbhost,$dbuser,$dbpass) or die("Unable to connect to $db");
// Lets change to the database we want to use
mysql_select_db ($db) or die("Unable to select $db");
// Lets process the insert into the database
$query = mysql_query ("SELECT * FROM $dbctbl") or die("Unable to select from $dbctbl");
mysql_close($connect);
}
function totals($catid) {
global $dbhost,$dbuser,$dbpass,$db,$dbgtbl,$totals;
$connect = mysql_connect ($dbhost,$dbuser,$dbpass) or die("Unable to connect to $db");
// Lets change to the database we want to use
mysql_select_db ($db) or die("Unable to select $db");
// Lets process the insert into the database
$query = mysql_query ("SELECT * FROM $dbgtbl WHERE cat_id = '$catid'") or die("Unable to select from $dbctbl");
$totals = 0;
// loop through the database
while ($row = mysql_fetch_array($query)) {
$totals++;
}
mysql_close($connect);
return $totals;
}
function adminlogin ($admin_user, $admin_pass){
// setup the global variables
global $db,$dbuser,$dbpass,$dbatbl,$dbhost,$username,$password;
// First we need to connect to the DB
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to $db");
// Now we need to change to the db we want to use
mysql_select_db($db) or die("Unable to select $db");
// Now lets query the db to get the users info
$users = mysql_query("SELECT * FROM $dbatbl WHERE admin_user LIKE '$admin_user' AND
admin_pass LIKE PASSWORD('$admin_pass')") or die("Unable to select from $dbatbl");
// Now we need to test if this is the admin or not
if ($data = mysql_fetch_array($users)) {
$username = $data["admin_user"];
$password = $data["admin_pass"];
mysql_close($connect) or die ("Unable to close $db");
return (1);
}else{
mysql_close($connect) or die ("Unable to close $db");
return (0);
}
}
function checkadmin ($admin_user, $admin_pass) {
// setup the global variables
global $db,$dbuser,$dbpass,$dbatbl,$dbhost,$username,$password;
// First we need to connect to the DB
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to $db");
// Now we need to change to the db we want to use
mysql_select_db($db) or die("Unable to select $db");
// Now lets query the db to get the users info
$users = mysql_query("SELECT * FROM $dbatbl WHERE admin_user LIKE '$admin_user' AND
admin_pass LIKE '$admin_pass'") or die("Unable to select from $dbatbl");
// Now we need to test if this is the admin or not
if ($data = mysql_fetch_array($users)) {
$username = $data["admin_user"];
$password = $data["admin_pass"];
mysql_close($connect) or die ("Unable to close $db");
return (1);
}else{
mysql_close($connect);
return (0);
}
}
function deletepost ($post_id){
// setup the global variables
global $db,$dbuser,$dbpass,$dbgtbl,$dbhost;
// Lets connect to the database
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to mySQL database.
Please click here to go back.");
// Now that we have connected lets make sure
// we are using the proper database
mysql_select_db($db) or die("Unalbe to select from $db database.
Please click here to go back.");
$posted = mysql_query("SELECT * FROM $dbgtbl WHERE post_id LIKE '$post_id'")
or die("
Unable to select from $db database. Please forward this error to the webmaster.
Please click here to go back.");
if ($row = mysql_fetch_array($posted)){
mysql_query("DELETE FROM $dbgtbl WHERE post_id = '$post_id'") or die("Unable to connect to delete $dbgtbl.
Please click here to go back.");
mysql_close($connect);
return (1);
}else{
mysql_close($connect);
return (0);
}
}
// Add a new catagory
function addcat ($cat_name, $cat_desc) {
// We need to set the globals for later use.
global $db,$dbuser,$dbpass,$dbctbl,$dbhost;
$post_date = date("Y-m-d g:i:s");
$entry = "INSERT INTO $dbctbl(cat_name,cat_desc) VALUES('$cat_name', '$cat_desc')";
// Lets connect to the mysql database
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to $db");
// Lets change to the database we want to use
mysql_select_db($db) or die("Unable to select $db");
// Lets process the insert into the database
$insert = mysql_query($entry) or die("Unable to add entry to $dbctbl");
mysql_close($connect);
// Let check to see if the entry was added.
// If it was then we send back an ok if not
// then we send back a not ok.
if ($insert){
return (1);
}else{
return (0);
}
}
// Delete catagory
function deletecat ($cat_id){
// setup the global variables
global $db,$dbuser,$dbpass,$dbctbl,$dbhost;
// Lets connect to the database
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to mySQL database.
Please click here to go back.");
// Now that we have connected lets make sure
// we are using the proper database
mysql_select_db($db) or die("Unalbe to select from $db database.
Please click here to go back.");
$posted = mysql_query("SELECT * FROM $dbctbl WHERE cat_id LIKE '$cat_id'")
or die("
Unable to select from $db database. Please forward this error to the webmaster.
Please click here to go back.");
if ($row = mysql_fetch_array($posted)){
mysql_query("DELETE FROM $dbctbl WHERE cat_id = '$cat_id'") or die("Unable to connect to delete $dbgtbl.
Please click here to go back.");
mysql_close($connect);
return (1);
}else{
mysql_close($connect);
return (0);
}
}
?>