Location: PHPKode > projects > MyOrgBook > myorgbook/ShowNote.php
<?php
/*
Purpose: Show a given note

$Header: /cvsroot/myorgbook/unstable/ShowNote.php,v 1.11 2003/08/17 10:58:32 mik3 Exp $
$Log: ShowNote.php,v $
Revision 1.11  2003/08/17 10:58:32  mik3
Changed the way feedback behaves

Revision 1.10  2003/08/07 18:46:32  mik3
bugfix

Revision 1.9  2003/08/02 13:44:38  mik3
Layout changes, language changes, theme support changes. Iow version 2.5

Revision 1.8  2003/06/21 04:23:22  myorgbook
Changed "update note" to "Update Note".

Revision 1.7  2003/06/20 22:04:22  mik3
Changed how language works, fixed bugs, made small other enhancements.......

*/

include ('inc/session.inc');
include ('inc/template.inc');
include ('inc/functions.inc');

// Getting info and error variables
If (isset($_REQUEST['Info'])) $Info = $_REQUEST['Info'];
If (isset($_REQUEST['Error'])) $Error = $_REQUEST['Error'];

//Defining template
$MyPage = New Template("Templates/$Theme");

// Setting the static variables
$MyPage->set_var("Manage Notes",msg('Manage Notes'));
$MyPage->set_var("Note title",msg('Note title'));
$MyPage->set_var("Note",msg('Note'));
$MyPage->set_var("Notes",msg('Notes'));
$MyPage->set_var("Back",msg('Back'));
$MyPage->set_var("Delete",msg('Delete'));
$MyPage->set_var("Add note",msg('Add note'));
$MyPage->set_var("You forgot to fill in a title!",msg('You forgot to fill in a title!'));
$MyPage->set_var("NegLang",$_SESSION["Language"]);

if ((isset($_REQUEST['delete'])) && ($_REQUEST['delete'] == true)) {
	// Delete the note
	$result = $db->Execute("DELETE from myorgbook_notes where note_id =" . $_REQUEST['noteid']);
	if ($result == false) die(msg('Query Failed'));
	$Info = msg('Note successfully deleted');
}

if ((isset($_REQUEST['action'])) && ($_REQUEST['action'] == "show")){
	// Setting up the right template
	$MyPage->set_file(array("MyHeaderHandle" => "header.tpl",
			"MyFileHandle" => "NoteDetail.tpl"));
	// parse header
	$MyPage->parse("header","MyHeaderHandle",true);
	// executing queries
	$result = $db->Execute("SELECT * FROM myorgbook_notes WHERE note_id =" . $_REQUEST['noteid']);
	if ($result == false) die(msg('Query Failed'));
	$r = $result->fields;
	$note_id = $r["note_id"];
	$note_title = $r["title"];
	$note_body = $r["body"];
	//setting all fields
	$MyPage->set_var("note_id",$note_id);
	$MyPage->set_var("note_title",$note_title);
	$MyPage->set_var("note_body",$note_body);
	$MyPage->set_var("Do_Action",msg('Update Note'));
	$MyPage->set_var("action","update");
	// Process and output
	$MyPage->parse("MyFileOut","MyFileHandle");
	$MyPage->p("MyFileOut");
	exit;
}

if ((isset($_REQUEST['action'])) && ($_REQUEST['action'] == "add")) {
	// Setting up the right template
	$MyPage->set_file(array("MyHeaderHandle" => "header.tpl",
			"MyFileHandle" => "NoteAdd.tpl",
			"MyError" => "error.tpl",
			"MyInfo" => "info.tpl"));
	// Checking for error
	if ($Error != "") {
		$MyPage->set_var("error_text",$Error);
		$MyPage->parse("Error_Element","MyError");
	}
	// Checking for info
	if ($Info != "") {
		$MyPage->set_var("info_text",$Info);
		$MyPage->parse("Info_Element","MyInfo");
	}
	// parse header
	$MyPage->parse("header","MyHeaderHandle",true);
	//setting all fields
	$MyPage->set_var("Do_Action",msg('Add note'));
	$MyPage->set_var("action","commit");
	// Process and output
	$MyPage->parse("MyFileOut","MyFileHandle");
	$MyPage->p("MyFileOut");
	exit;
}

if ((isset($_REQUEST['action'])) && ($_REQUEST['action'] == "commit")) {
	// Checking for title
	if ($_REQUEST['note_title'] != "") {
		$result = $db->Execute("INSERT INTO myorgbook_notes (uemail,title,body) values ('" . $_SESSION['Email'] . "'," . $db->qstr(StripHTML($_REQUEST['note_title']),get_magic_quotes_gpc()) . "," . $db->qstr(StripHTML($_REQUEST['note_body']),get_magic_quotes_gpc()) . ")");
		if ($result == false) die(msg('Query Failed'));
		$Info = msg('Note successfully added');
	} else {
		header("Location: http://".$_SERVER['SERVER_NAME']."/".substr($_SERVER['PHP_SELF'], 1, strrpos($_SERVER['PHP_SELF'],"/")) . "ShowNote.php?action=add&Error=" . msg('The title is a required field!'));
		exit;
	}
}

if ((isset($_REQUEST['action'])) && ($_REQUEST['action'] == "update")) {
	$result = $db->Execute("UPDATE myorgbook_notes set title = " . $db->qstr(StripHTML($_REQUEST['note_title']),get_magic_quotes_gpc()) . ", body = " . $db->qstr(StripHTML($_REQUEST['note_body']),get_magic_quotes_gpc()) . " where note_id =" . $_REQUEST['noteid']);
	if ($result == false) die(msg('Query Failed'));
	$Info = msg('Note successfully updated');
}

// Showing all notes as default action
$MyPage->set_file(array("MyHeaderHandle" => "header.tpl",
			"MyFileHandle" => "note.tpl",
			"MyTableElementHandle" => "note_element.tpl",
			"MyError" => "error.tpl",
			"MyInfo" => "info.tpl"));
// Checking for error
if ($Error != "") {
	$MyPage->set_var("error_text",$Error);
	$MyPage->parse("Error_Element","MyError");
}
// Checking for info
if ($Info != "") {
	$MyPage->set_var("info_text",$Info);
	$MyPage->parse("Info_Element","MyInfo");
}
// parse header
$MyPage->parse("header","MyHeaderHandle",true);
//query
$result = $db->Execute("SELECT note_id, title FROM myorgbook_notes WHERE uemail = '" . $_SESSION["Email"] . "'");
if ($result == false) die(msg('Query Failed'));
$num = $result->RecordCount();
// No notes there
$NoteContent = "";
if ($num == "0") {
	$MyPage->set_var("content",msg('No notes found') . "<BR>");
} else {
	while (!$result->EOF) {
		$r = $result->fields;
		$note_title = $r["title"];
		$MyPage->set_var("note_id",$r["note_id"]);
		$MyPage->set_var("title",$r["title"]);
		$MyPage->parse("content","MyTableElementHandle",true);
		$result->MoveNext();
	}
}
// Process and output
$MyPage->parse("MyFileOut","MyFileHandle");
$MyPage->p("MyFileOut");

?>
Return current item: MyOrgBook