All pastes #539204 Raw Edit

Untitled

public text v1 · immutable
·published 2007-06-05 06:36 UTC
rendered paste body
<?php


function __autoload($classname) { require_once('includes/'.$classname.'.class.php'); }

class news {
	function __toString() {
		return '<div id="news_'.$this->id.'">'.$this->show().'</div>';
	}
	function show() {
		$str = '<h1>'.$this->title.'</h1> by <i>'.$this->author.'</i>';
		$str .= '[<a href"#" onclick="updateSection(\'news_id\',\'news.php?news_id='.$this->id.'&edit=1\');">Edit</a>]'
		$str .= '<br />';
		$str .= '<pre>'.$this->body.'</pre>';
		return $str;
	}

	function edit() {
		$str ='<form method="#" onsubmit="postPage(this,\'news.test.php\'); updateSection(\'news_id\',\'news.php?news_id='.$this->id.'\&show=1'); return false">';
		$str .= '<input type="hidden" name="id" value="'.$this->id.'">';
		$str .= '<input type="text" name="title" value="'.$this->title.'" size="60"> by <i>'.$this->author.'</i>';
		$str .= '<br />';
		$str .= '<textarea  rows="12" cols="60" name="body">'.$this->body.'</textarea><br />';
		$str .= '<input type="submit" name="action" value="Edit news">';
		$str .= '</form>';
	}
}

$db = new DB();
if($_POST['submit'] == 'Edit news') {
	$db->execute('UPDATE news SET
		title=\''.filter_input(INPUT_POST,'title',FILTER_SANITIZE_MAGIC_QUOTES).'\',
		body=\''.filter_input(INPUT_POST,'body',FILTER_SANITIZE_MAGIC_QUOTES).'\'
		WHERR `id`='.intval($_POST['news_id']));
		exit;
}
if($_GET['news_id'])
	$news = $db->execute('SELECT * FROM news WHERE news_id='.intval($_POST['news_id']));
else
	$news = $db->execute('SELECT * FROM news');
$news->handler('news');
foreach($news as $post) {
	if($_GET['edit'])
		print $post->edit();
	else if($_GET['show'])
		print $post->show();
	else
		print $post;
}

?>