<?PHP
/*
* notes.php Insert notes on the index.
* copyright (c)2005 Marco Islas <markuz@islascruz.org>
*/
/*
 *  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 Library 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.
 */

class notes
{
	var $type;
	function notes(){
	}
	
	function default_action(){
		$this->type="user";
		$tpl = new template(CINTILLA_PATH."xhtml");
		$tpl->load("layout","notes.html");
		$tpl->setBlock("user","layout");
		$sql = "select id from notes";
		$ids = $GLOBALS["db"]->fetch_row($sql);
		if (!empty($ids))
			$ids = array_reverse($ids);
		for ($i=0;$i<2;$i++){
			$sql    = "select title,content from notes where ";
			$sql   .= "id='".$ids[$i]."'";
			$data[] = $GLOBALS["db"]->fetch_array($sql);
		}
		if (!empty($data)){
			$tpl->set_variable("t1",$data[0]["title"]);
			$tpl->set_variable("c1",nl2br($data[0]["content"]));
			$tpl->set_variable("t2",$data[1]["title"]);
			$tpl->set_variable("c2",nl2br($data[1]["content"]));
		}
		$tpl->expand("expuser","user");
		return $tpl->export("expuser");
		
	}
	
	function admin($message=""){
		if (empty($message))
			$message = "Insertar una nota";
		$this->type="admin";
		$tpl = new template(CINTILLA_PATH."xhtml");
		$tpl->load("layout","notes.html");
		$tpl->setBlock("admin","layout");
		$tpl->set_variable("message",$message);
		$tpl->expand("expadmin","admin");
		return $tpl->export("expadmin");
	}
	
	function save(){
		$this->type="admin";
		$sql = "insert into notes values ('','".$_REQUEST["title"]."',"
			."'".$_REQUEST["content"]."')";
		$GLOBALS["db"]->query($sql);
		return $this->admin("Nota insertada satisfactoriamente");
	}
}
?>