Location: PHPKode > projects > Butterfly Organizer > includes/todo.php
Butterfly Organizer
Copyright (C) 2007-2008 Butterfly Media Romania

This file is part of Butterfly Organizer.

Butterfly Organizer 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; version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU 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

include ('settings.php');

// don't allow browsers to cache the contents of this page because it may change
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache'); // for HTTP/1.0
header('Expires: Thu, 01 Jan 1970 00:00:00 GMT');

// request for a new id
if (isset($_GET['getid'])) {
	// insert a new empty note and return its id
	if (mysql_query('INSERT INTO notes (text) VALUES("")')) {
		echo mysql_insert_id();
	else {
		echo 0; // the insert somehow failed (should add more error handling)

// init the list with all current notes
else if (isset($_GET['init'])) {
	// first do a cleanup of the notes list (remove notes which are added but not edited)
	mysql_query('DELETE FROM notes WHERE text = ""');
	$query = 'SELECT id, text FROM notes';
	$result = mysql_query($query);

	header('Content-type: text/javascript');

	while ($row = mysql_fetch_assoc($result)) {
		$text = addslashes($row['text']);

		// we are returning javascript code which will call the addnote function
		echo "addnote({$row['id']}, '$text'); \n";

// delete a note
else if (isset($_GET['del']) && is_numeric($_GET['del'])) {
	mysql_query('DELETE FROM notes WHERE id = '.$_GET['del']);

// update the contents of a note
else if (isset($_POST['id']) && is_numeric($_POST['id'])) {
	// strip the tags from the note text
	$text = strip_tags($_POST['text']);
	$query = 'UPDATE notes SET text = "' . $text . '" WHERE id = '. $_POST['id'];
Return current item: Butterfly Organizer