Tous les collages #105605 Brut Modifier

Something

public text v1 · immuable
#105605 ·publié 2006-07-29 19:29 UTC
corps du collage affiché
<?PHP
// shoutbox.php
//
// handles the addition of comments in the shoutbox.
// (uses ajax)


include_once("../include/main.php");

//first make sure we do not have blank input OR overflow. if so do not add anything
if($_REQUEST['shout_name'] == "" || $_REQUEST['shout_comment'] == "" || strlen($_REQUEST['shout_name']) > 32 || strlen($_REQUEST['shout_comment']) > 255)
	$_REQUEST['op'] = 'get';
	

switch($_REQUEST['op'])
{
	case 'add':
		//make sure there is no HTML to get in the way
		strip_tags($_REQUEST['shout_comment']);
		
		$sql = "INSERT INTO ".$database['prefix']."shoutbox (name, comment) VALUES ('".$_REQUEST['shout_name']."','". $_REQUEST['shout_comment']."')";
		$recordSet = $db->Execute($sql);
		if ($recordSet === false)
		{
			$error->setError(ERR_DATABASE, $sql);
			return false;
		}
		//don't break, we want to always retreive the updated data
	case 'get':
		$sql = "SELECT * FROM ".$database['prefix']."shoutbox ORDER BY 'timestamp' DESC";
		$recordSet = $db->Execute($sql);
		if ($recordSet === false)
		{
			$error->setError(ERR_DATABASE, $sql);
			return false;
		}

		//now that we have them, format the first 4, or show more depending on user action.
		$return_data = "";	//initialize variable for good measure.
		if(!isset($_REQUEST['sn']) || !is_numeric($_REQUEST['sn']))
			$shout_num = 4;	//4 is default
		else
			$shout_num = $_REQUEST['sn'];
			
		for($i=0; $i < $shout_num; $i++)
		{
			if($recordSet->EOF)
				return;
			$recordSet->fields['comment'] = wordwrap($recordSet->fields['comment'], 36, "\n<br />\n", 1);
      $return_data .= "<p>".$recordSet->fields['comment']."<br />by: <i>".$recordSet->fields['name']."</i></p>\n";		
			$recordSet->MoveNext();
		}
		//build the appropriate link for displaying of more or less shouts
		if($shout_num != 4)
			$return_data .= "<br><a href=\"javascript:getShouts(4);\" onmouseover=\"statusbarMessage('Back to normal shoutbox view');\" onmouseout=\"statusbarMessage('');\">Back to normal view</a>";
		else
			$return_data .= "<br><a href=\"javascript:getShouts(10);\" onmouseover=\"statusbarMessage('Click here to view last 10 shouts');\" onmouseout=\"statusbarMessage('');\">View last 10 shouts</a>";
		
		echo $return_data;
		break;
}
		


/*


if($_REQUEST['shout_name'] != "" || $_REQUEST['shout_comment'] != "")

echo "this is a test to see if the data was retrieved\n\n".$_REQUEST['shout_name']."\n".$_REQUEST['shout_comment'];

*/
?>