Commit ce1dc7db authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- New tags_ajax file mentioned previously. (helps to actually add the file)

parent 48a976c2
<?php
/* phpTodo - Web based todo lists *}
{* Copyright (C) 2005-12 Jason Frisvold <friz@godshell.com> *}
{* *}
{* 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 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
// Define phpTodo (to allow access to files)
define('phpTodo', 1);
// Define usesmarty (to indicate that config needs to load smarty)
define('usesmarty', 1);
// Load the global config
require_once('config.php');
// Connect to the database server
$sqlhdlr = new mysqli($phpTodo_dbHost, $phpTodo_dbUser, $phpTodo_dbPass,
$phpTodo_dbName);
$errorset = 0;
// Make sure we have a connection
if (mysqli_connect_errno()) {
$jsonarray = json_encode(Array('success' => 'false',
'output' => 'Unable to connect to the ' .
'database server at this ' .
'time: ' .
mysqli_connect_error()));
$errorset = 1;
}
// If the user is not authenticated, jump them to the login page
if (! $user_obj = authenticate()) {
$jsonarray = json_encode(Array('success' => 'false',
'output' => 'Unauthenticated User'));
$errorset = 1;
}
// Check the action
if (! $errorset) {
$taglist = Array();
foreach ($_REQUEST['taglist'] as $tag) {
if (ctype_digit($tag)) {
array_push($taglist, $tag);
}
}
if (($_REQUEST['action'] == 'merge') ||
($_REQUEST['action'] == 'split') ||
($_REQUEST['action'] == 'delete')) {
// If we're merging or splitting, add the new tags
if (($_REQUEST['action'] == 'merge') ||
($_REQUEST['action'] == 'split')) {
$query = sprintf('SELECT entry_id FROM tag2entry WHERE user_id = ' .
'%s AND tag_id IN (%s)', $user_obj->user_id(),
implode(',', $taglist));
$result = $sqlhdlr->query($query);
$entry_list = Array();
while ($line = $result->fetch_array()) {
array_push($entry_list, $line[0]);
}
// TODO: We need to create new tags where necessary. Be sure to
// remove existing tags from the taglist to be deleted.
// If we have entries and new tags, create the new links
if ((length($entry_list) > 0) && (length($newtags) > 0)) {
$create_entry = $sqlhdlr->prepare('INSERT INTO tag2entry ' .
'(tag_id, entry_id, ' .
'user_id) VALUES (?, ?, ?)');
foreach ($entry_list AS $entry) {
foreach ($newtags as $tag) {
$create_entry->bind_param("iii", $tag, $entry,
$user_obj->user_id());
$create_entry->execute();
}
}
}
}
// In all three cases, we need to delete the original tags
if (length($taglist) > 0) {
$query = sprintf('DELETE FROM tags WHERE user_id = %d AND id IN ' .
'(%s)', $user_obj->user_id(),
implode(',', $taglist));
$sqlhdlr->query($query);
$query = sprintf('DELETE FROM tag2entry WHERE user_id = %d AND ' .
'tag_id IN (%s)', $user_obj->user_id(),
implode(',', $taglist));
$sqlhdlr->query($query);
}
assign_tags($smarty, $user_obj);
$output = $smarty->fetch('tag_table.tpl');
$jsonarray = json_encode(Array('success' => 'true',
'output' => $output));
}
}
header('Content-type: application/json');
echo $jsonarray;
// Close the MySQL handler
$sqlhdlr->close();
?>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment