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

Merge branch 'master' of ssh://git.code.sf.net/p/phptodo/code

parents e918cda4 3701cf35
......@@ -44,7 +44,7 @@ tr.even { border: thin solid; color: black; }
#t_subject { width: 65%; }
#t_duedate { width: 10%; }
#t_action { width: 5%; }
#tags td { text-align: left; }
#tagManagement td { text-align: left; }
/* Division elements */
div.centered { text-align: center; }
......
......@@ -114,12 +114,21 @@
// Get the feed_id to return to the web page
$feed_id = $feed->feed_id();
// Set the link to return to the web page
$feed_link = 'feed.php?user_id=' . $user_obj->user_id() . '&secret=' .
$feed->secret() . '&feed_id=' . $feed->feed_id();
// Get the icon for the feed
$feed_icon = $feed->icon();
// Force the object to go out of scope
unset($feed);
$jsonarray = json_encode(Array('success' => 'true',
'feed_id' => $feed_id));
$jsonarray = json_encode(Array('success' => 'true',
'feed_id' => $feed_id,
'feed_link' => $feed_link,
'feed_icon' => $feed_icon));
}
}
......
......@@ -69,12 +69,47 @@
$( '#tagList tbody input' ).each(function() {
if ($( this ).is(':checked') == true) {
taglist.push($( this ).attr('name').substr(4));
taglist.push( $( this ).next('span').text() );
}
})
if (action == 'merge') {
// display input box with callback to tagManageSubmit
if ((action == 'merge') || (action == 'split')) {
// Cover the screen in a blanket and show the popup
$('<div id="blanket"></div>' +
'<div id="popup"></div>').appendTo('#formdiv');
// Set the size of the popup
var lLeft = ($(window).width() / 4) + "px";
var lTop = ($(window).height() / 4) + "px";
$('#popup').css('top', lTop)
.css('left', lLeft)
.css('width', $(window).width() / 2 + 'px')
.css('height', $(window).height() / 2 + 'px');
$.ajax({
url: 'tags_ajax.php',
dataType: 'json',
type: 'POST',
data: { action: 'popup',
taglist: taglist},
success: function(data) {
if (data.success == 'true') {
$( '#popup' ).append(data.output);
//$( '#tags' ).val( taglist.join(',') );
$( '#okbutton' ).bind('click', function() {
newtags = $( '#tags' ).val().split(',');
tagManageSubmit(action, taglist, newtags);
$( '#popup' ).remove();
$( '#blanket' ).remove();
});
} else {
ajax_error(data.output);
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
ajax_error(errorThrown);
}
});
} else if (action == 'delete') {
tagManageSubmit(action, taglist, newtags);
}
......@@ -239,9 +274,18 @@
feed_order: feed_order,
feed_max: feed_max,
feed_show: feed_show},
ajaxRow: curRow,
success: function(data) {
if (data.success == 'true') {
// TODO : Update RSS Link
curRow = this.ajaxRow;
// Update Feed Link
curRow.find('a').attr('href', data.feed_link);
// Update the Feed Icon
feed_icon = 'images/' + data.feed_icon;
console.log(feed_icon);
curRow.find('a img').attr('src', feed_icon);
// Update feed_id
curRow.find('input[name="feed_id"]').val(data.feed_id);
......@@ -337,7 +381,14 @@
$( '#tagList' ).remove();
$( '#tagTable' ).append(data.output);
// Bind a click function to toggle checkboxes for tags
$( '#tag_management_list span' ).each( function() {
$( this ).bind('click', function() {
checkbox = $( this ).prev('input');
checkbox.attr('checked', !checkbox.attr('checked'));
});
});
} else {
ajax_error(data.output);
}
......
......@@ -92,9 +92,12 @@ class phpTodoFeed {
$this->feed_id = $feed_id;
// Create the necessary sql statement
$query = sprintf('SELECT f.secret, f.name, f.priority_min, f.priority_max, ' .
'f.status_id, f.tag_filter, f.order_by, o.field_name, f.max_limit, ' .
'f.show_completed, f.version, v.template, v.icon FROM feeds AS f, order_by AS o, feed_version AS v WHERE v.id = f.version AND o.id = f.order_by AND ' .
$query = sprintf('SELECT f.secret, f.name, f.priority_min, ' .
'f.priority_max, f.status_id, f.tag_filter, ' .
'f.order_by, o.field_name, f.max_limit, ' .
'f.show_completed, f.version, v.template, v.icon ' .
'FROM feeds AS f, order_by AS o, feed_version AS v ' .
'WHERE v.id = f.version AND o.id = f.order_by AND ' .
'f.id = %d AND f.user_id = %d', $this->feed_id,
$this->user_id);
......@@ -410,7 +413,7 @@ class phpTodoFeed {
$this->version = $version;
// Mark as dirty
$this->pwd_dirty_flag = true;
$this->dirty_flag = true;
}
return $this->version;
......@@ -420,6 +423,10 @@ class phpTodoFeed {
* Return the template filename representing the feed's version
*/
public function template() {
if ($this->dirty_flag == true) {
$this->_get_feed_version();
}
return $this->template;
}
......@@ -427,6 +434,10 @@ class phpTodoFeed {
* Return the icon filename representing the feed's version
*/
public function icon() {
if ($this->dirty_flag == true) {
$this->_get_feed_version();
}
return $this->icon;
}
......@@ -453,6 +464,25 @@ class phpTodoFeed {
}
}
/**
* Retrieve the template and icon corresponding to the feed version
*/
private function _get_feed_version() {
$query = sprintf('SELECT template, icon FROM feed_version WHERE id = %d',
$this->version);
if ($result = $this->sqlhdlr->query($query)) {
$line = $result->fetch_array(MYSQLI_NUM);
$this->template = $line[0];
$this->icon = $line[1];
$result->close();
} else {
die( 'Error: ' . $this->sqlhdlr->error );
}
}
/**
* Serialize the Feed object
*/
......
......@@ -50,13 +50,34 @@
// Check the action
if (! $errorset) {
$phpTodo_nameRegex = '/^[a-zA-Z0-9_\-]{1,15}\z/';
$get_tag = $sqlhdlr->prepare('SELECT id FROM tags WHERE name = ? ' .
'AND user_id = ?');
$taglist = Array();
$popuplist = Array();
$tcount = 0;
foreach ($_REQUEST['taglist'] as $tag) {
if (ctype_digit($tag)) {
array_push($taglist, $tag);
if (preg_match($phpTodo_nameRegex, $tag)) {
$tag_id = 0;
$get_tag->bind_param("si", $tag, $user_obj->user_id());
$get_tag->execute();
$get_tag->bind_result($tag_id);
$get_tag->fetch();
if (isset($tag_id) && is_int($tag_id) && ($tag_id != 0)) {
$popuplist[$tcount]['id'] = $tag_id;
$popuplist[$tcount]['tag'] = $tag;
$popuplist[$tcount]['first'] = strtoupper(substr($tag, 0, 1));
$tcount++;
array_push($taglist, $tag_id);
}
}
}
$get_tag->close();
if (($_REQUEST['action'] == 'merge') ||
($_REQUEST['action'] == 'split') ||
($_REQUEST['action'] == 'delete')) {
......@@ -64,35 +85,83 @@
// If we're merging or splitting, add the new tags
if (($_REQUEST['action'] == 'merge') ||
($_REQUEST['action'] == 'split')) {
// First we need a list of all of the entries using these tags
$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()) {
error_log('Got entry - ' . $line[0]);
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.
// Next, validate the new tags
$newtags = Array();
$phpTodo_nameRegex = '/^[a-zA-Z0-9_\-]{1,15}\z/';
foreach ($_REQUEST['newtags'] as $tag) {
if (preg_match($phpTodo_nameRegex, $tag)) {
array_push($newtags, $tag);
}
}
// Now, check if the tag exists already and add it if not
$create_tag = $sqlhdlr->prepare('INSERT INTO tags (id, name, ' .
'user_id) VALUES (NULL, ?, ?)');
$get_tag = $sqlhdlr->prepare('SELECT id FROM tags WHERE name = ? ' .
'AND user_id = ?');
$newtaglist = Array();
foreach ($newtags as $tag) {
$tag_id = 0;
$get_tag->bind_param("si", $tag, $user_obj->user_id());
$get_tag->execute();
$get_tag->bind_result($tag_id);
$get_tag->fetch();
if (isset($tag_id) && is_int($tag_id) && ($tag_id != 0)) {
array_push($newtaglist, $tag_id);
$index = array_search($tag_id, $taglist);
if (is_int($index)) {
error_log('index defined');
unset($taglist[$index]);
$taglist = array_values($taglist);
}
} else {
$create_tag->bind_param("si", $tag, $user_obj->user_id());
$create_tag->execute();
array_push($newtaglist, $create_tag->insert_id);
}
}
$get_tag->close();
$create_tag->close();
// If we have entries and new tags, create the new links
if ((count($entry_list) > 0) && (count($newtags) > 0)) {
if ((count($entry_list) > 0) && (count($newtaglist) > 0)) {
$query = sprintf('DELETE FROM tag2entry WHERE user_id = %d ' .
'AND tag_id IN (%s)', $user_obj->user_id(),
implode(',', $newtaglist));
$sqlhdlr->query($query);
$create_entry = $sqlhdlr->prepare('INSERT INTO tag2entry ' .
'(tag_id, entry_id, ' .
'user_id) VALUES (?, ?, ?)');
foreach ($entry_list AS $entry) {
foreach ($newtags as $tag) {
foreach ($newtaglist as $tag) {
$create_entry->bind_param("iii", $tag, $entry,
$user_obj->user_id());
$create_entry->execute();
$create_entry->execute() or error_log('error - ' . $sqlhdlr->error);
}
}
}
}
// In all three cases, we need to delete the original tags
// In all three cases, we need to delete the original tags that are not
// being used anymore
if (count($taglist) > 0) {
$query = sprintf('DELETE FROM tags WHERE user_id = %d AND id IN ' .
'(%s)', $user_obj->user_id(),
......@@ -109,12 +178,17 @@
$output = $smarty->fetch('tag_table.tpl');
$jsonarray = json_encode(Array('success' => 'true',
'output' => $output));
} elseif ($_REQUEST['action'] == 'popup' ) {
$smarty->assign('taglist', $popuplist);
$output = $smarty->fetch('tag_edit.tpl');
$jsonarray = json_encode(Array('success' => 'true',
'output' => $output));
}
}
header('Content-type: application/json');
echo $jsonarray;
......
......@@ -76,7 +76,7 @@
<hr class='onethird' />
<div id='tag_management_list'>
<h3>Tag Management</h3>
<form id='tags'>
<form id='tagManagement' method='post' action='prefs.php'>
<div class='centered'>
<div id='tagTable'>
{include file='tag_table.tpl'}
......
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