Location: PHPKode > projects > Guestbook and Comment Box > gb_admin/guestbook/functions/gb_functions.php
<?

/************************************

Script : Free Guest Book and comment box
Website : http://www.agrizlive.com

Script is provided Under GPU Non-Commercial License
Agrizlive.com doesn't provide any WARRANTY for this script
**************************************/
	
function getGuestBooksBackEnd($limit)
{
	$query = "SELECT * FROM ".TABLE_PREFIX."gb_guestbook ORDER BY guestbook_id DESC LIMIT $limit,".GUESTBOOK_ADMIN_DISPLAY."";
	$result = mysql_query($query);
	
	return $result;
}

function getTotalGuestBooks()
{
	$query = "SELECT * FROM ".TABLE_PREFIX."gb_guestbook";
	$result = mysql_query($query);
	
	return mysql_num_rows($result);
}

function addNewSmiley($title,$short_cut,$image_name,$image_tmp)
{
	if($image_name != ""){
		if(move_uploaded_file($image_tmp,"smiley/".$image_name))
		{
			$query = "INSERT INTO ".TABLE_PREFIX."gb_smiley(smiley_name, short_cut,smiley_image) VALUES('".$title."','".$short_cut."','".$image_name."')";
			$result = mysql_query($query);
			if($result){
				return " - Added successfully";
			}
			else
			{
				return " - New smiley added failed.";
			}
		}
		else
		{
			return " - Image Uploading failed";
		}
	}
	else
	{
		return " - You must upload an image";
	}
}

function getSmileys($limit)
{
	$query = "SELECT * FROM ".TABLE_PREFIX."gb_smiley ORDER BY smiley_id DESC LIMIT $limit,".GUESTBOOK_ADMIN_DISPLAY."";
	$result = mysql_query($query);
	
	return $result;
}

function getTotalSmileys()
{
	$query = "SELECT * FROM ".TABLE_PREFIX."gb_smiley";
	$result = mysql_query($query);
	
	return mysql_num_rows($result);
}

function getSmileyDetails($id)
{
	$query = "SELECT * FROM ".TABLE_PREFIX."gb_smiley WHERE smiley_id = ".addslashes($id)."";
	$result = mysql_query($query);
	
	return mysql_fetch_array($result);
}


function editSmiley($title,$short_cut,$image_name,$image_tmp,$id)
{
	$query = "UPDATE ".TABLE_PREFIX."gb_smiley SET smiley_name = '".$title."', short_cut = '".$short_cut."' WHERE smiley_id = $id";
	$result = mysql_query($query);
	if($image_name != ""){
		$value_smiley = getSmileyDetails($id);
		unlink("smiley/".$value_smiley['smiley_image']);
		
		if(move_uploaded_file($image_tmp,"smiley/".$image_name))
		{
			$query = "UPDATE ".TABLE_PREFIX."gb_smiley SET smiley_image = '".$image_name."' WHERE smiley_id = $id";
			$result = mysql_query($query);
			if($result){
				return " - Editted successfully";
			}
			else
			{
				return " - Edit Failed";
			}
		}
		else
		{
			return " - Image Uploading failed";
		}
	}	
}

function deleteSmiley($id)
{
	$query = "DELETE FROM ".TABLE_PREFIX."gb_smiley WHERE smiley_id = ".addslashes($id)."";
	$result = mysql_query($query);
	
	if($result){
		return "Delete is success";
	}
	else{
		return "Smiley is not deleted";
	}
}


function addGBComment($name,$email,$website,$comment,$unique_id)
{
	if(AUTO_APPROVE){
		$status = 'approved';
	}
	else{
		$status = "pending";
	}
	$ip = $_SERVER['REMOTE_ADDR'];
	$query = "INSERT INTO ".TABLE_PREFIX."gb_guestbook(user_name,user_email,user_website,guestbook_message,date,ip,status,page_name) VALUES('".addslashes($name)."','".addslashes($email)."','".addslashes($website)."','".addslashes($comment)."',NOW(),'$ip','$status','$unique_id')";
	$result = mysql_query($query);
	
	if($result){
		if(AUTO_APPROVE){
			return AUTO_APPROVE_MESSAGE;
		}
		else{
			return PENDING_MESSAGE;
		}
	}
	else{
		return COMMENT_FAILED_MESSAGE;
	}
}

function editGuestBook($name,$email,$website,$comment,$status,$id)
{
	$query = "UPDATE ".TABLE_PREFIX."gb_guestbook SET user_name = '".addslashes($name)."', user_email = '".addslashes($email)."', user_website = '".addslashes($website)."', guestbook_message = '".addslashes($comment)."', status = '$status' WHERE guestbook_id = $id";
	$result = mysql_query($query);
	
	if($result){
		return "Editted Successfully";
	}
	else{
		return "There is a problem in editting. Try later";
	}
}

function getComments($unique_id)
{
	$query = "SELECT * FROM ".TABLE_PREFIX."gb_guestbook WHERE page_name = '$unique_id' and status = 'approved' ORDER BY guestbook_id ASC";
	$result = mysql_query($query);
	
	return $result;
}

function getSmileysFE()
{
	$query = "SELECT * FROM ".TABLE_PREFIX."gb_smiley ORDER BY smiley_id DESC";
	$result = mysql_query($query);
	
	return $result;
}


function getGuestBookID($id)
{
	$query = "SELECT * FROM ".TABLE_PREFIX."gb_guestbook WHERE guestbook_id = $id";
	$result = mysql_query($query);
	
	return mysql_fetch_array($result);
}

function deleteGB($id)
{
	$query = "DELETE FROM ".TABLE_PREFIX."gb_guestbook WHERE guestbook_id = ".addslashes($id)."";
	$result = mysql_query($query);
	
	if($result){
		return "Delete is success";
	}
	else{
		return "Guestbook is not deleted";
	}
}
?>

Return current item: Guestbook and Comment Box