2006-10-01 10:05:20 +00:00
|
|
|
<?php
|
|
|
|
function module_pref_labels($link) {
|
|
|
|
|
2009-12-29 15:49:27 +00:00
|
|
|
$subop = $_REQUEST["subop"];
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2009-01-26 11:30:13 +00:00
|
|
|
if ($subop == "color-set") {
|
|
|
|
$kind = db_escape_string($_REQUEST["kind"]);
|
|
|
|
$ids = split(',', db_escape_string($_REQUEST["ids"]));
|
|
|
|
$color = db_escape_string($_REQUEST["color"]);
|
2009-01-26 16:46:23 +00:00
|
|
|
$fg = db_escape_string($_REQUEST["fg"]);
|
|
|
|
$bg = db_escape_string($_REQUEST["bg"]);
|
2009-01-26 11:30:13 +00:00
|
|
|
|
|
|
|
foreach ($ids as $id) {
|
2009-01-26 16:46:23 +00:00
|
|
|
|
|
|
|
if ($kind == "fg" || $kind == "bg") {
|
|
|
|
db_query($link, "UPDATE ttrss_labels2 SET
|
|
|
|
${kind}_color = '$color' WHERE id = '$id'
|
|
|
|
AND owner_uid = " . $_SESSION["uid"]);
|
|
|
|
} else {
|
|
|
|
db_query($link, "UPDATE ttrss_labels2 SET
|
|
|
|
fg_color = '$fg', bg_color = '$bg' WHERE id = '$id'
|
|
|
|
AND owner_uid = " . $_SESSION["uid"]);
|
|
|
|
}
|
2010-11-10 15:50:51 +00:00
|
|
|
|
|
|
|
$caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
|
|
|
|
|
|
|
|
/* Remove cached data */
|
|
|
|
|
|
|
|
db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
|
|
|
|
WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
|
|
|
|
|
2009-01-26 11:30:13 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 16:01:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($subop == "color-reset") {
|
|
|
|
$ids = split(',', db_escape_string($_REQUEST["ids"]));
|
|
|
|
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
db_query($link, "UPDATE ttrss_labels2 SET
|
|
|
|
fg_color = '', bg_color = '' WHERE id = '$id'
|
|
|
|
AND owner_uid = " . $_SESSION["uid"]);
|
2010-11-10 15:50:51 +00:00
|
|
|
|
|
|
|
$caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
|
|
|
|
|
|
|
|
/* Remove cached data */
|
|
|
|
|
|
|
|
db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
|
|
|
|
WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
|
2009-01-26 16:01:46 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 11:30:13 +00:00
|
|
|
}
|
|
|
|
|
2009-01-18 08:28:42 +00:00
|
|
|
if ($subop == "save") {
|
2008-08-07 08:06:12 +00:00
|
|
|
|
2009-01-18 08:28:42 +00:00
|
|
|
$id = db_escape_string($_REQUEST["id"]);
|
2009-01-18 09:54:11 +00:00
|
|
|
$caption = db_escape_string(trim($_REQUEST["value"]));
|
2008-08-07 08:06:12 +00:00
|
|
|
|
2009-01-18 08:28:42 +00:00
|
|
|
db_query($link, "BEGIN");
|
2008-08-06 06:47:56 +00:00
|
|
|
|
2009-01-18 08:28:42 +00:00
|
|
|
$result = db_query($link, "SELECT caption FROM ttrss_labels2
|
|
|
|
WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2009-01-18 08:28:42 +00:00
|
|
|
if (db_num_rows($result) != 0) {
|
|
|
|
$old_caption = db_fetch_result($result, 0, "caption");
|
2007-05-14 08:16:48 +00:00
|
|
|
|
2009-01-18 08:28:42 +00:00
|
|
|
$result = db_query($link, "SELECT id FROM ttrss_labels2
|
|
|
|
WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2009-01-18 08:28:42 +00:00
|
|
|
if (db_num_rows($result) == 0) {
|
|
|
|
if ($caption) {
|
|
|
|
$result = db_query($link, "UPDATE ttrss_labels2 SET
|
|
|
|
caption = '$caption' WHERE id = '$id' AND
|
|
|
|
owner_uid = " . $_SESSION["uid"]);
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2009-01-18 08:28:42 +00:00
|
|
|
/* Update filters that reference label being renamed */
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2009-10-19 19:29:45 +00:00
|
|
|
$old_caption = db_escape_string($old_caption);
|
|
|
|
|
2009-01-18 08:28:42 +00:00
|
|
|
db_query($link, "UPDATE ttrss_filters SET
|
|
|
|
action_param = '$caption' WHERE action_param = '$old_caption'
|
|
|
|
AND action_id = 7
|
|
|
|
AND owner_uid = " . $_SESSION["uid"]);
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2009-01-18 09:54:11 +00:00
|
|
|
print $_REQUEST["value"];
|
2009-01-18 10:16:02 +00:00
|
|
|
} else {
|
|
|
|
print $old_caption;
|
2009-01-18 08:28:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print $old_caption;
|
2006-10-01 10:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-18 08:28:42 +00:00
|
|
|
db_query($link, "COMMIT");
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($subop == "remove") {
|
|
|
|
|
2009-12-29 15:49:27 +00:00
|
|
|
$ids = split(",", db_escape_string($_REQUEST["ids"]));
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2009-01-18 10:11:55 +00:00
|
|
|
foreach ($ids as $id) {
|
2009-01-18 14:36:50 +00:00
|
|
|
label_remove($link, $id, $_SESSION["uid"]);
|
2006-10-01 10:05:20 +00:00
|
|
|
}
|
2009-01-18 10:11:55 +00:00
|
|
|
|
2006-10-01 10:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($subop == "add") {
|
2009-12-29 15:49:27 +00:00
|
|
|
$caption = db_escape_string($_REQUEST["caption"]);
|
2010-11-08 22:04:00 +00:00
|
|
|
$output = db_escape_string($_REQUEST["output"]);
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2009-01-18 08:28:42 +00:00
|
|
|
if ($caption) {
|
2008-05-17 03:03:03 +00:00
|
|
|
|
2009-01-23 06:42:37 +00:00
|
|
|
if (label_create($link, $caption)) {
|
2010-11-08 22:04:00 +00:00
|
|
|
if (!$output) {
|
2010-11-17 18:39:51 +00:00
|
|
|
print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
|
2010-11-08 22:04:00 +00:00
|
|
|
}
|
2009-01-18 08:28:42 +00:00
|
|
|
}
|
2009-01-23 06:42:37 +00:00
|
|
|
|
2010-11-08 22:04:00 +00:00
|
|
|
if ($output == "select") {
|
|
|
|
header("Content-Type: text/xml");
|
|
|
|
|
2010-11-09 10:14:59 +00:00
|
|
|
print "<rpc-reply><payload>";
|
2010-11-08 22:04:00 +00:00
|
|
|
|
|
|
|
print_label_select($link, "select_label",
|
|
|
|
$caption, "");
|
|
|
|
|
2010-11-09 10:14:59 +00:00
|
|
|
print "</payload></rpc-reply>";
|
2010-11-08 22:04:00 +00:00
|
|
|
}
|
2007-03-05 13:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2006-10-01 10:05:20 +00:00
|
|
|
}
|
|
|
|
|
2007-05-04 03:26:20 +00:00
|
|
|
set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig");
|
|
|
|
|
2009-12-29 15:49:27 +00:00
|
|
|
$sort = db_escape_string($_REQUEST["sort"]);
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
if (!$sort || $sort == "undefined") {
|
2009-01-18 08:28:42 +00:00
|
|
|
$sort = "caption";
|
2006-10-01 10:05:20 +00:00
|
|
|
}
|
|
|
|
|
2009-12-29 15:49:27 +00:00
|
|
|
$label_search = db_escape_string($_REQUEST["search"]);
|
2008-05-17 03:07:39 +00:00
|
|
|
|
2009-12-29 15:49:27 +00:00
|
|
|
if (array_key_exists("search", $_REQUEST)) {
|
2008-05-17 03:07:39 +00:00
|
|
|
$_SESSION["prefs_label_search"] = $label_search;
|
|
|
|
} else {
|
|
|
|
$label_search = $_SESSION["prefs_label_search"];
|
|
|
|
}
|
|
|
|
|
2010-11-17 11:49:06 +00:00
|
|
|
print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
|
|
|
|
print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
|
|
|
|
print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">";
|
|
|
|
|
|
|
|
print "<div style='float : right; padding-right : 4px'>
|
2008-05-17 03:07:39 +00:00
|
|
|
<input id=\"label_search\" size=\"20\" type=\"search\"
|
2010-11-17 18:13:41 +00:00
|
|
|
dojoType=\"dijit.form.TextBox\"
|
2008-05-17 03:11:51 +00:00
|
|
|
onfocus=\"javascript:disableHotkeys();\"
|
|
|
|
onblur=\"javascript:enableHotkeys();\"
|
2008-05-17 03:07:39 +00:00
|
|
|
onchange=\"javascript:updateLabelList()\" value=\"$label_search\">
|
2010-11-17 18:13:41 +00:00
|
|
|
<button dojoType=\"dijit.form.Button\" onclick=\"javascript:updateLabelList()\">".__('Search')."</button>
|
2008-05-17 03:07:39 +00:00
|
|
|
</div>";
|
2007-03-02 19:16:45 +00:00
|
|
|
|
2010-11-17 18:39:51 +00:00
|
|
|
print "<div dojoType=\"dijit.form.DropDownButton\">".
|
|
|
|
"<span>" . __('Select')."</span>";
|
|
|
|
print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
|
|
|
|
print "<div onclick=\"selectTableRows('prefLabelList', 'all')\"
|
|
|
|
dojoType=\"dijit.MenuItem\">".__('All')."</div>";
|
|
|
|
print "<div onclick=\"selectTableRows('prefLabelList', 'none')\"
|
|
|
|
dojoType=\"dijit.MenuItem\">".__('None')."</div>";
|
|
|
|
print "</div></div>";
|
|
|
|
|
2010-11-17 18:13:41 +00:00
|
|
|
print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">".
|
|
|
|
__('Create label')."</button dojoType=\"dijit.form.Button\"> ";
|
2010-01-11 15:43:53 +00:00
|
|
|
|
2010-11-17 18:13:41 +00:00
|
|
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">".
|
|
|
|
__('Remove')."</button dojoType=\"dijit.form.Button\"> ";
|
2010-01-11 15:43:53 +00:00
|
|
|
|
2010-11-17 18:13:41 +00:00
|
|
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">".
|
|
|
|
__('Clear colors')."</button dojoType=\"dijit.form.Button\">";
|
2010-01-11 15:43:53 +00:00
|
|
|
|
|
|
|
|
2010-11-17 11:49:06 +00:00
|
|
|
print "</div>"; #toolbar
|
|
|
|
print "</div>"; #pane
|
|
|
|
print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
2008-05-17 03:07:39 +00:00
|
|
|
if ($label_search) {
|
2009-10-07 11:12:21 +00:00
|
|
|
|
|
|
|
$label_search = split(" ", $label_search);
|
|
|
|
$tokens = array();
|
|
|
|
|
|
|
|
foreach ($label_search as $token) {
|
|
|
|
|
|
|
|
$token = trim($token);
|
|
|
|
array_push($tokens, "(UPPER(caption) LIKE UPPER('%$token%'))");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$label_search_query = "(" . join($tokens, " AND ") . ") AND ";
|
|
|
|
|
2008-05-17 03:07:39 +00:00
|
|
|
} else {
|
|
|
|
$label_search_query = "";
|
|
|
|
}
|
|
|
|
|
2006-10-01 10:05:20 +00:00
|
|
|
$result = db_query($link, "SELECT
|
2009-01-26 10:07:53 +00:00
|
|
|
*
|
2006-10-01 10:05:20 +00:00
|
|
|
FROM
|
2009-01-18 08:28:42 +00:00
|
|
|
ttrss_labels2
|
2006-10-01 10:05:20 +00:00
|
|
|
WHERE
|
2008-05-17 03:07:39 +00:00
|
|
|
$label_search_query
|
2006-10-01 10:05:20 +00:00
|
|
|
owner_uid = ".$_SESSION["uid"]."
|
|
|
|
ORDER BY $sort");
|
|
|
|
|
|
|
|
if (db_num_rows($result) != 0) {
|
|
|
|
|
|
|
|
print "<p><table width=\"100%\" cellspacing=\"0\"
|
|
|
|
class=\"prefLabelList\" id=\"prefLabelList\">";
|
|
|
|
|
|
|
|
$lnum = 0;
|
|
|
|
|
|
|
|
while ($line = db_fetch_assoc($result)) {
|
|
|
|
|
|
|
|
$class = ($lnum % 2) ? "even" : "odd";
|
|
|
|
|
|
|
|
$label_id = $line["id"];
|
2009-01-18 08:28:42 +00:00
|
|
|
$this_row_id = "id=\"LILRR-$label_id\"";
|
|
|
|
|
2006-10-01 10:05:20 +00:00
|
|
|
print "<tr class=\"$class\" $this_row_id>";
|
|
|
|
|
2009-01-18 08:28:42 +00:00
|
|
|
$line["caption"] = htmlspecialchars($line["caption"]);
|
2009-01-26 10:07:53 +00:00
|
|
|
|
|
|
|
$fg_color = $line["fg_color"];
|
|
|
|
$bg_color = $line["bg_color"];
|
|
|
|
|
2009-01-26 16:01:46 +00:00
|
|
|
if (!$fg_color) $fg_color = "";
|
|
|
|
if (!$bg_color) $bg_color = "";
|
2009-01-26 10:07:53 +00:00
|
|
|
|
2009-01-18 10:17:17 +00:00
|
|
|
print "<td width='5%' align='center'><input
|
2010-11-11 15:59:21 +00:00
|
|
|
onclick='toggleSelectRow(this);'
|
2006-10-01 10:05:20 +00:00
|
|
|
type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
|
|
|
|
|
2009-01-26 11:05:06 +00:00
|
|
|
$id = $line['id'];
|
2009-01-26 10:54:47 +00:00
|
|
|
|
2009-01-26 16:01:46 +00:00
|
|
|
print "<td>";
|
|
|
|
|
|
|
|
print "<div class='labelColorIndicator' id='LICID-$id'
|
2009-01-26 10:07:53 +00:00
|
|
|
style='color : $fg_color; background-color : $bg_color'
|
2009-01-26 16:52:38 +00:00
|
|
|
title='".__('Click to change color')."'
|
2009-01-26 16:46:23 +00:00
|
|
|
onclick=\"colorPicker('$id', '$fg_color', '$bg_color')\">α";
|
|
|
|
print_color_picker($id);
|
|
|
|
print "</div>";
|
2009-01-26 10:54:47 +00:00
|
|
|
|
|
|
|
|
2009-01-26 16:01:46 +00:00
|
|
|
print "<span class='prefsLabelEntry'
|
2009-01-26 10:07:53 +00:00
|
|
|
id=\"LILT-".$line["id"]."\">" . $line["caption"] .
|
2009-01-26 10:54:47 +00:00
|
|
|
"</span>";
|
|
|
|
|
2009-01-26 11:05:06 +00:00
|
|
|
print "</td>";
|
2006-10-01 10:05:20 +00:00
|
|
|
|
|
|
|
print "</tr>";
|
|
|
|
|
|
|
|
++$lnum;
|
|
|
|
}
|
2008-05-17 03:32:36 +00:00
|
|
|
|
2006-10-01 10:05:20 +00:00
|
|
|
print "</table>";
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
2008-05-17 03:32:36 +00:00
|
|
|
print "<p>";
|
|
|
|
if (!$label_search) {
|
2009-10-06 09:37:24 +00:00
|
|
|
print_warning(__('No labels defined.'));
|
2008-05-17 03:32:36 +00:00
|
|
|
} else {
|
2009-10-06 09:37:24 +00:00
|
|
|
print_warning(__('No matching labels found.'));
|
2008-05-17 03:32:36 +00:00
|
|
|
}
|
|
|
|
print "</p>";
|
|
|
|
|
2006-10-01 10:05:20 +00:00
|
|
|
}
|
2010-11-17 11:49:06 +00:00
|
|
|
|
|
|
|
print "</div>"; #pane
|
|
|
|
print "</div>"; #container
|
2006-10-01 10:05:20 +00:00
|
|
|
}
|
2009-01-27 05:28:35 +00:00
|
|
|
|
|
|
|
function print_color_picker($id) {
|
|
|
|
|
|
|
|
print "<div id=\"colorPicker-$id\"
|
|
|
|
onmouseover=\"colorPickerActive(true)\"
|
|
|
|
onmouseout=\"colorPickerActive(false)\"
|
|
|
|
class=\"colorPicker\" style='display : none'>";
|
|
|
|
|
|
|
|
$color_picker_pairs = array(
|
|
|
|
array('#ff0000', '#ffffff'),
|
|
|
|
array('#009000', '#ffffff'),
|
|
|
|
array('#0000ff', '#ffffff'),
|
|
|
|
array('#ff00ff', '#ffffff'),
|
|
|
|
array('#009090', '#ffffff'),
|
|
|
|
|
|
|
|
array('#ffffff', '#ff0000'),
|
|
|
|
array('#000000', '#00ff00'),
|
|
|
|
array('#ffffff', '#0000ff'),
|
|
|
|
array('#ffffff', '#ff00ff'),
|
|
|
|
array('#000000', '#00ffff'),
|
|
|
|
|
|
|
|
array('#7b07e1', '#ffffff'),
|
|
|
|
array('#0091b4', '#ffffff'),
|
|
|
|
array('#00aa71', '#ffffff'),
|
|
|
|
array('#7d9e01', '#ffffff'),
|
|
|
|
array('#e14a00', '#ffffff'),
|
|
|
|
|
|
|
|
array('#ffffff', '#7b07e1'),
|
|
|
|
array('#ffffff', '#00b5e1'),
|
|
|
|
array('#ffffff', '#00e196'),
|
|
|
|
array('#ffffff', '#b3e100'),
|
|
|
|
array('#ffffff', '#e14a00'),
|
|
|
|
|
|
|
|
array('#000000', '#ffffff'),
|
|
|
|
array('#ffffff', '#000000'),
|
|
|
|
array('#ffffff', '#909000'),
|
|
|
|
array('#063064', '#fff7d5'),
|
|
|
|
array('#ffffff', '#4E4E90'),
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($color_picker_pairs as $c) {
|
|
|
|
$fg_color = $c[0];
|
|
|
|
$bg_color = $c[1];
|
|
|
|
|
|
|
|
print "<div class='colorPickerEntry'
|
|
|
|
style='color : $fg_color; background-color : $bg_color;'
|
|
|
|
onclick=\"colorPickerDo('$id', '$fg_color', '$bg_color')\">α</div>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
print "<br clear='both'>";
|
|
|
|
|
|
|
|
print "<br/><b>".__('custom color:')."</b>";
|
|
|
|
print "<div class=\"ccPrompt\" onclick=\"labelColorAsk('$id', 'fg')\">".__("foreground")."</div>";
|
|
|
|
print "<div class=\"ccPrompt\" onclick=\"labelColorAsk('$id', 'bg')\">".__("background")."</div>";
|
|
|
|
|
|
|
|
print "</div>";
|
|
|
|
}
|
|
|
|
|
2006-10-01 10:05:20 +00:00
|
|
|
?>
|