Просмотр файла guestbook/post.php

Размер файла: 6.08Kb
<?php 
/*
 * $RCSfile: post.php,v1 $
 *
 * Wap-GuestBook - a wap based guestbook
 * Copyright (C) 2004-2005 Chinmay N. Muranjan
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

header("Content-type: text/vnd.wap.wml"); 
echo "<?xml version=\"1.0\"?>"; 
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"" 
   . " \"http://www.wapforum.org/DTD/wml_1.1.xml\">"; 
?> 

<?php
include('inc/config.inc.php');
include('inc/func.inc.php');

$db = mysql_connect($host,$user,$pass);
mysql_select_db($database,$db) or die ("Query 1 failed");

if (isset($_GET['type']) == "post")
{

$name3 = $_POST['name'];
$email3 = $_POST['email'];
$comments3 = $_POST['comments'];
$url = $_POST['url'];
$show_url = $_POST['show_url'];
$rate = $_POST['rate'];
$show_email = $_POST['show_email'];

	if ($name3 == "" OR $email3 == "" OR $comments3 == "")
	{
		if (($name3=="" AND $email3=="") OR ($name3=="" AND $comments3=="") OR ($email3=="" AND $comments3==""))
		{
			if ($name3 == "" AND $email3 == "" AND $comments3 == "")
			{
				$continue = "Name,_Email_and_Comments";
				$flag = 1;
			}
			else
			{ 
				if ($name3 == "" AND $email3 == ""):
					$continue = "Name_and_Email";
					$flag = 1;
				endif;

				if ($name3 == "" AND $comments3 == ""):
					$continue = "Name_and_Comments";
					$flag = 1;
				endif;

				if ($email3 == "" AND $comments3 == ""):
					$continue = "Email_and_Comments";
					$flag = 1;
				endif;
			}
		}
		else
		{
			if ($name3 == ""):
				$continue = "Name";
				$flag = 1;
			endif;

			if ($email3 == ""):
				$continue = "Email";
				$flag = 1;
			endif;

			if ($comments3 == ""):
				$continue = "Comments";
				$flag = 1;
			endif;
		}
	}

	else
	{
		$numresults = mysql_query("SELECT comments FROM $table WHERE comments = '$comments3'") or die ("Query 2 failed");
		$numrows = mysql_num_rows($numresults);

		if ($numrows > 0)
		{
			$flag = 2;
			$continue = "comments";
		}
		else
		{
			$str2 = $email3;
			$str3 = $url;

			if(validateEmail($str2))
			{
				$chk1 = 1;
			}
			else
			{
				$chk1 = 0;
			}

			if($url == "http://" OR $url == "")
			{
				$chk2 = 1;
			}
			else
			{
				if(validateUrl($str3))
				{
					$chk2 = 1;
				}
				else
				{
					$chk2 = 0;
				}
			}

			if ($chk1 == "1" AND $chk2 == "1")
			{
				$flag = 4;

				$datetime = gmdate("Y-m-d H:i:s", time() + 3600*($timezone));
 
				if ($url == "http://" OR $url == ""):
					$show_url = 0;
				endif;

				$sql="INSERT INTO $table (name, email, rate, comments, show_email, datetime, url, show_url) VALUES ('$name3', '$email3', '$rate', '$comments3','$show_email', '$datetime', '$url', '$show_url')";

				mysql_query($sql, $db) or die ("Query 3 failed");

				$continue = htmlentities(urlencode($name3));

			}
			else
			{
				if ($chk1 == "0" AND $chk2 == "0")
				{
					$flag = 3;
					$continue = "Email_and_URL";
				}
				else
				{
					if ($chk1 == "0")
					{
						$flag = 3;
						$continue = "Email";
					}
					else
					{
						$flag = 3;
						$continue = "URL";
					}
				}
			}
		}
	}
?>
<wml>
<head><meta http-equiv="Cache-control" content="no-cache"/></head>
<card title="POST" id="card1" ontimer="post.php?flag=<? print "$flag"; ?>&amp;continue=<? print "$continue"; ?>">
<timer value="10"/>
<p><a href="<? print $post; ?>?flag=<? print "$flag"; ?>&amp;continue=<? print"$continue"; ?>">Processing...</a>
</p>
</card>
</wml>
<?
}

else
{
?>

<wml>
<head><meta http-equiv="Cache-control" content="no-cache"/></head>
<card title="POST" id="card2">

<?
$flag = $_GET['flag'];
$continue = $_GET['continue'];

switch ($flag)
{
	case 1:
		print "<p>Please enter your&nbsp;<b><i>$continue</i></b>&nbsp;!<br/>";
		print "<a href=\"$show\">view guestbook</a></p>";
		break;

	case 2:
		print "<p>Sorry ! You either enter same&nbsp;<b><i>Comments</i></b>&nbsp;";
		print "OR this page refreshes accidently !!<br/>";
		print "<a href=\"$show\">view guestbook</a></p>";
		break;

	case 3:
		print "<p>Sorry ! Please enter your valid&nbsp;<b><i>$continue</i></b>&nbsp;address.<br/>";
		print "<a href=\"$show\">view guestbook</a></p>";
		break;

	case 4:
		$continue = htmlentities(urldecode($continue));
		print "<p>Thank you&nbsp;<b>".$continue."</b>&nbsp;for signing in my guestbook !<br/>";
		print "<a href=\"$show\">view guestbook</a><br/></p>";
		break;

	default:
		print "<p>Illegal syntax ! Please try again !!<br/>";
		print "<a href=\"$show\">view guestbook</a></p>";
		break;
}

print "<p><br/>Back To:<br/>";
print "<a href=\"$sign\">Sign Guestbook</a>";
print "<br/>";
print "<a href=\"$home\">HOME</a>";
print "<br/></p>";
?>

<!-- END MAIN CONTENT AREA -->
<p><br/><small>
Comments are the property of their posters.<br/>
        [ <a href="info.php?type=6">License</a>
        &nbsp;|&nbsp;
        <a href="info.php?type=3">Change Log</a>
        &nbsp;|&nbsp;
        <a href="info.php?type=5">To Do List</a>
        &nbsp;|&nbsp;
        <a href="info.php?type=4">Bugs</a> ]
      <br/>
      Powered by <a href="info.php?type=1">Wap_GuestBook v2.0</a>&nbsp;and&nbsp;<a href="info.php?type=2">PHP</a>. Copyright © 2004-2005 <a href="info.php?type=1">Chinmay N. Muranjan</a>, All Rights Reserved.<br/></small>
      <!-- YOU MAY NOT REMOVE THIS COPYRIGHT NOTICE WITHOUT PERMISSION FROM THE Wap_GuestBook AUTHOR --></p>
</card>
</wml>
<?
exit;
}
?>