All pastes #73650 Raw Edit

Anonymous

public text v1 · immutable
#73650 ·published 2006-06-28 02:48 UTC
rendered paste body
<?php
    error_reporting(E_ALL);
    include("./includes/db.inc");
	include('./includes/functions.php');
	include("./includes/header.inc");
	
    if(isset($_GET['home']) || empty($_GET))
    {
		echo "<h3>Home</h3>";
        $getQuotes = mysql_query("SELECT * FROM quotes ORDER BY id DESC LIMIT 10") or die(mysql_error()); 

        while($quotes = mysql_fetch_array($getQuotes))
        {
            echo "<pre>\n";
            echo htmlspecialchars($quotes['content'])."\n";
            echo "</pre>\n";
            
			echo "<span class=\"info\">";
			echo "#{$quotes['id']} | {$quotes['date']} | <a href=\"/?vote=up&id={$quotes['id']}\" title=\"Vote Up\">+</a> [5] <a href=\"/?vote=down&id={$quotes['id']}\" title=\"Vote Up\">-</a> | <a href=\"{$quotes['proof']}\" title=\"Proof of Comment\">POC</a>";
			echo "</span>";
        }
    }
	
	 elseif(isset($_GET['add']))
    {
		echo "<h3>Add Comment</h3>";
        if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['proof']) && isset($_POST['comment']))
		{
			$message = $_POST['name']."<br />";
			$message .= $_POST['email']."<br />";
			$message .= $_POST['proof']."<br /><br />";
			$message .= $_POST['comment'];
			$headers  = 'MIME-Version: 1.0' . "\r\n";
			$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
			$mail = mail('nicosaan@gmail.com', 'Code Bash [Submission]', stripslashes($message), $headers);
			if($mail)
			{
				echo "<script language=\"Javascript\">window.location=\"http://www.codebash.com\";</script>";
			}
		}
		else
		{
			echo '<form method="POST" action="/?add"><p>
						Enter your name:<br>
							<input NAME="name" size = 40><br>
						Enter your email address:<br>
							<input NAME="email" size=40><br>
						Enter your POC:<br>
							<input NAME="proof" size=40><br>	
						Enter your code comment:<br>
							<textarea NAME="comment" rows=10 cols=40></textarea><br />
						<input type="submit" value="Submit your question"></p>
					</form>';
		}
    }
	
	elseif(isset($_GET['latest']))
	{
		echo "<h3>Latest 50</h3>";
		$getQuotes = mysql_query("SELECT * FROM quotes ORDER BY id DESC LIMIT 50") or die(mysql_error()); 

        while($quotes = mysql_fetch_array($getQuotes))
        {
            echo "<pre>\n";
            echo htmlspecialchars($quotes['content'])."\n";
            echo "</pre>\n";
            
			echo "<span class=\"info\">";
            echo "#{$quotes['id']} | {$quotes['date']} | <a href=\"/?vote=up&id={$quotes['id']}\" title=\"Vote Up\">+</a> [5] <a href=\"/?vote=down&id={$quotes['id']}\" title=\"Vote Up\">-</a> | <a href=\"{$quotes['proof']}\" title=\"Proof of Comment\">POC</a>";
			echo "</span>";
        }
    }
	
	elseif(isset($_GET['random']))
	{
		echo "<h3>Random 10</h3>";
		$getQuotes = mysql_query("SELECT * FROM quotes ORDER BY rand() DESC LIMIT 10") or die(mysql_error()); 

        while($quotes = mysql_fetch_array($getQuotes))
        {
            echo "<pre>\n";
            echo htmlspecialchars($quotes['content'])."\n";
            echo "</pre>\n";
            
			echo "<span class=\"info\">";
            echo "#{$quotes['id']} | {$quotes['date']} | <a href=\"/?vote=up&id={$quotes['id']}\" title=\"Vote Up\">+</a> [5] <a href=\"/?vote=down&id={$quotes['id']}\" title=\"Vote Up\">-</a> | <a href=\"{$quotes['proof']}\" title=\"Proof of Comment\">POC</a>";
			echo "</span>";
        }
    }
	
	elseif(isset($_GET['vote']))
	{
		function castVote($quote_id, $vote) {
			$ip_address = $_SERVER['REMOTE_ADDR'];
			$result = mysql_query("SELECT `id` FROM `ratings` WHERE quote_id = $quote_id AND `ip_address` = '$ip_address'");
			
			if ($result) {
				echo 'Sorry, you\'ve already voted';
				return;
			}
			
			$result = mysql_query("SELECT `id` FROM `ratings` WHERE quote_id = $quote_id");
	
			if ($result) {
				if ($vote == 'up') {
					mysql_query("UPDATE `ratings` SET `current_rating` = `current_rating` + 1 WHERE quote_id = $quote_id");
				} else {
					mysql_query("UPDATE `ratings` SET `current_rating` = `current_rating` - 1 WHERE quote_id = $quote_id");
				}
			} else {
				mysql_query("INSERT INTO `ratings` VALUES(null, $query_id, 5, '$ip_address')");
			}
			if(isset($_GET['id']))
			{
				castVote($_GET['id'], $_GET['vote']);
				echo"<h3>Thanks for voting</h3>";
			}
		}
	}
		
	elseif(isset($_GET['top']))
	{
		echo "<h3>Top 100</h3>";
		$getQuotes = mysql_query("SELECT quotes.*, ratings.current_rating, ratings.quote_id FROM quotes LEFT JOIN ratings ON ratings.quote_id = quotes.id ORDER BY ratings.current_rating DESC LIMIT 100") or die(mysql_error()); 

        while($quotes = mysql_fetch_array($getQuotes))
        {
            echo "<pre>\n";
            echo htmlspecialchars($quotes['content'])."\n";
            echo "</pre>\n";
            
			echo "<span class=\"info\">";
            echo "#{$quotes['id']} | {$quotes['date']} | <a href=\"/?vote=up&id={$quotes['id']}\" title=\"Vote Up\">+</a> [5] <a href=\"/?vote=down&id={$quotes['id']}\" title=\"Vote Up\">-</a> | <a href=\"{$quotes['proof']}\" title=\"Proof of Comment\">POC</a>";
			echo "</span>";
        }
    }
    
	include("./includes/footer.inc");
?>