2006-10-01 12:05:20 +02:00
|
|
|
<?php
|
|
|
|
function module_pref_labels($link) {
|
|
|
|
|
2009-12-29 16:49:27 +01:00
|
|
|
$subop = $_REQUEST["subop"];
|
2006-10-01 12:05:20 +02:00
|
|
|
|
2010-11-18 18:04:57 +01:00
|
|
|
if ($subop == "edit") {
|
|
|
|
$label_id = db_escape_string($_REQUEST['id']);
|
|
|
|
|
|
|
|
header("Content-Type: text/xml");
|
|
|
|
print "<dlg id=\"$subop\">";
|
|
|
|
print "<title>" . __("Label Editor") . "</title>";
|
|
|
|
print "<content><![CDATA[";
|
|
|
|
|
|
|
|
$result = db_query($link, "SELECT * FROM ttrss_labels2 WHERE
|
|
|
|
id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
|
|
|
|
|
|
|
|
$line = db_fetch_assoc($result);
|
|
|
|
|
|
|
|
print "<div class=\"dlgSec\">".__("Caption")."</div>";
|
|
|
|
|
|
|
|
print "<div class=\"dlgSecCont\">";
|
|
|
|
|
|
|
|
print "<span dojoType=\"dijit.InlineEditBox\" style=\"font-size : 18px;\"
|
|
|
|
width=\"150px\" autoSave=\"false\"
|
|
|
|
label-id=\"$label_id\">" . $line["caption"] .
|
|
|
|
"<script type=\"dojo/method\" event=\"onChange\" args=\"item\">
|
|
|
|
var elem = this;
|
|
|
|
dojo.xhrPost({
|
|
|
|
url: 'backend.php',
|
|
|
|
content: {op: 'pref-labels', subop: 'save',
|
|
|
|
value: this.value,
|
|
|
|
id: this.srcNodeRef.getAttribute('label-id')},
|
|
|
|
load: function(response) {
|
|
|
|
elem.attr('value', response);
|
|
|
|
dijit.byId('labelTree').setNameById($label_id, response);
|
|
|
|
updateFilterList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</span>";
|
|
|
|
|
|
|
|
print "</div>";
|
|
|
|
print "<div class=\"dlgSec\">" . __("Change colors") . "</div>";
|
|
|
|
print "<div class=\"dlgSecCont\">";
|
|
|
|
|
|
|
|
print "<table cellspacing=\"5\"><th>";
|
|
|
|
|
|
|
|
print "<tr><td>".__("Foreground color:")."</td><td>".__("Background color:").
|
|
|
|
"</td></tr>";
|
|
|
|
|
|
|
|
print "</th><tr><td>";
|
|
|
|
|
|
|
|
print "<div dojoType=\"dijit.ColorPalette\">
|
|
|
|
<script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\">
|
|
|
|
setLabelColor('$label_id', fg_color, null);
|
|
|
|
</script>
|
|
|
|
</div>";
|
|
|
|
print "</div>";
|
|
|
|
|
|
|
|
print "</td><td>";
|
|
|
|
|
|
|
|
print "<div dojoType=\"dijit.ColorPalette\">
|
|
|
|
<script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\">
|
|
|
|
setLabelColor('$label_id', null, bg_color);
|
|
|
|
</script>
|
|
|
|
</div>";
|
|
|
|
print "</div>";
|
|
|
|
|
|
|
|
print "</td></tr></table>";
|
|
|
|
print "</div>";
|
|
|
|
|
|
|
|
print "<div class=\"dlgButtons\" style=\"text-align : center\">";
|
|
|
|
print "<button onclick=\"return closeInfoBox()\">".
|
|
|
|
__('Close this window')."</button>";
|
|
|
|
print "</div>";
|
|
|
|
|
|
|
|
print "]]></content></dlg>";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($subop == "getlabeltree") {
|
|
|
|
$root = array();
|
|
|
|
$root['id'] = 'root';
|
|
|
|
$root['name'] = __('Labels');
|
|
|
|
$root['items'] = array();
|
|
|
|
|
|
|
|
$result = db_query($link, "SELECT *
|
|
|
|
FROM ttrss_labels2
|
|
|
|
WHERE owner_uid = ".$_SESSION["uid"]."
|
|
|
|
ORDER BY caption");
|
|
|
|
|
|
|
|
while ($line = db_fetch_assoc($result)) {
|
|
|
|
$label = array();
|
|
|
|
$label['id'] = 'LABEL:' . $line['id'];
|
|
|
|
$label['bare_id'] = $line['id'];
|
|
|
|
$label['name'] = $line['caption'];
|
|
|
|
$label['fg_color'] = $line['fg_color'];
|
|
|
|
$label['bg_color'] = $line['bg_color'];
|
|
|
|
$label['type'] = 'label';
|
|
|
|
$label['checkbox'] = false;
|
|
|
|
|
|
|
|
array_push($root['items'], $label);
|
|
|
|
}
|
|
|
|
|
|
|
|
$fl = array();
|
|
|
|
$fl['identifier'] = 'id';
|
|
|
|
$fl['label'] = 'name';
|
|
|
|
$fl['items'] = array($root);
|
|
|
|
|
|
|
|
print json_encode($fl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-26 12:30:13 +01: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 17:46:23 +01:00
|
|
|
$fg = db_escape_string($_REQUEST["fg"]);
|
|
|
|
$bg = db_escape_string($_REQUEST["bg"]);
|
2009-01-26 12:30:13 +01:00
|
|
|
|
|
|
|
foreach ($ids as $id) {
|
2009-01-26 17:46:23 +01: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 16:50:51 +01: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 12:30:13 +01:00
|
|
|
}
|
|
|
|
|
2009-01-26 17:01:46 +01: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 16:50:51 +01: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 17:01:46 +01:00
|
|
|
}
|
|
|
|
|
2009-01-26 12:30:13 +01:00
|
|
|
}
|
|
|
|
|
2009-01-18 09:28:42 +01:00
|
|
|
if ($subop == "save") {
|
2008-08-07 10:06:12 +02:00
|
|
|
|
2009-01-18 09:28:42 +01:00
|
|
|
$id = db_escape_string($_REQUEST["id"]);
|
2009-01-18 10:54:11 +01:00
|
|
|
$caption = db_escape_string(trim($_REQUEST["value"]));
|
2008-08-07 10:06:12 +02:00
|
|
|
|
2009-01-18 09:28:42 +01:00
|
|
|
db_query($link, "BEGIN");
|
2008-08-06 08:47:56 +02:00
|
|
|
|
2009-01-18 09:28:42 +01:00
|
|
|
$result = db_query($link, "SELECT caption FROM ttrss_labels2
|
|
|
|
WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
|
2006-10-01 12:05:20 +02:00
|
|
|
|
2009-01-18 09:28:42 +01:00
|
|
|
if (db_num_rows($result) != 0) {
|
|
|
|
$old_caption = db_fetch_result($result, 0, "caption");
|
2007-05-14 10:16:48 +02:00
|
|
|
|
2009-01-18 09:28:42 +01:00
|
|
|
$result = db_query($link, "SELECT id FROM ttrss_labels2
|
|
|
|
WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
|
2006-10-01 12:05:20 +02:00
|
|
|
|
2009-01-18 09:28:42 +01: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 12:05:20 +02:00
|
|
|
|
2009-01-18 09:28:42 +01:00
|
|
|
/* Update filters that reference label being renamed */
|
2006-10-01 12:05:20 +02:00
|
|
|
|
2009-10-19 21:29:45 +02:00
|
|
|
$old_caption = db_escape_string($old_caption);
|
|
|
|
|
2009-01-18 09:28:42 +01: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 12:05:20 +02:00
|
|
|
|
2009-01-18 10:54:11 +01:00
|
|
|
print $_REQUEST["value"];
|
2009-01-18 11:16:02 +01:00
|
|
|
} else {
|
|
|
|
print $old_caption;
|
2009-01-18 09:28:42 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print $old_caption;
|
2006-10-01 12:05:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-18 09:28:42 +01:00
|
|
|
db_query($link, "COMMIT");
|
2006-10-01 12:05:20 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($subop == "remove") {
|
|
|
|
|
2009-12-29 16:49:27 +01:00
|
|
|
$ids = split(",", db_escape_string($_REQUEST["ids"]));
|
2006-10-01 12:05:20 +02:00
|
|
|
|
2009-01-18 11:11:55 +01:00
|
|
|
foreach ($ids as $id) {
|
2009-01-18 15:36:50 +01:00
|
|
|
label_remove($link, $id, $_SESSION["uid"]);
|
2006-10-01 12:05:20 +02:00
|
|
|
}
|
2009-01-18 11:11:55 +01:00
|
|
|
|
2006-10-01 12:05:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($subop == "add") {
|
2009-12-29 16:49:27 +01:00
|
|
|
$caption = db_escape_string($_REQUEST["caption"]);
|
2010-11-08 23:04:00 +01:00
|
|
|
$output = db_escape_string($_REQUEST["output"]);
|
2006-10-01 12:05:20 +02:00
|
|
|
|
2009-01-18 09:28:42 +01:00
|
|
|
if ($caption) {
|
2008-05-17 05:03:03 +02:00
|
|
|
|
2009-01-23 07:42:37 +01:00
|
|
|
if (label_create($link, $caption)) {
|
2010-11-08 23:04:00 +01:00
|
|
|
if (!$output) {
|
2010-11-17 19:39:51 +01:00
|
|
|
print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
|
2010-11-08 23:04:00 +01:00
|
|
|
}
|
2009-01-18 09:28:42 +01:00
|
|
|
}
|
2009-01-23 07:42:37 +01:00
|
|
|
|
2010-11-08 23:04:00 +01:00
|
|
|
if ($output == "select") {
|
|
|
|
header("Content-Type: text/xml");
|
|
|
|
|
2010-11-09 11:14:59 +01:00
|
|
|
print "<rpc-reply><payload>";
|
2010-11-08 23:04:00 +01:00
|
|
|
|
|
|
|
print_label_select($link, "select_label",
|
|
|
|
$caption, "");
|
|
|
|
|
2010-11-09 11:14:59 +01:00
|
|
|
print "</payload></rpc-reply>";
|
2010-11-08 23:04:00 +01:00
|
|
|
}
|
2007-03-05 14:45:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2006-10-01 12:05:20 +02:00
|
|
|
}
|
|
|
|
|
2009-12-29 16:49:27 +01:00
|
|
|
$sort = db_escape_string($_REQUEST["sort"]);
|
2006-10-01 12:05:20 +02:00
|
|
|
|
|
|
|
if (!$sort || $sort == "undefined") {
|
2009-01-18 09:28:42 +01:00
|
|
|
$sort = "caption";
|
2006-10-01 12:05:20 +02:00
|
|
|
}
|
|
|
|
|
2009-12-29 16:49:27 +01:00
|
|
|
$label_search = db_escape_string($_REQUEST["search"]);
|
2008-05-17 05:07:39 +02:00
|
|
|
|
2009-12-29 16:49:27 +01:00
|
|
|
if (array_key_exists("search", $_REQUEST)) {
|
2008-05-17 05:07:39 +02:00
|
|
|
$_SESSION["prefs_label_search"] = $label_search;
|
|
|
|
} else {
|
|
|
|
$label_search = $_SESSION["prefs_label_search"];
|
|
|
|
}
|
|
|
|
|
2010-11-17 12:49:06 +01: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\">";
|
|
|
|
|
2010-11-17 19:39:51 +01:00
|
|
|
print "<div dojoType=\"dijit.form.DropDownButton\">".
|
|
|
|
"<span>" . __('Select')."</span>";
|
|
|
|
print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
|
2010-11-18 18:04:57 +01:00
|
|
|
print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\"
|
2010-11-17 19:39:51 +01:00
|
|
|
dojoType=\"dijit.MenuItem\">".__('All')."</div>";
|
2010-11-18 18:04:57 +01:00
|
|
|
print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\"
|
2010-11-17 19:39:51 +01:00
|
|
|
dojoType=\"dijit.MenuItem\">".__('None')."</div>";
|
|
|
|
print "</div></div>";
|
|
|
|
|
2010-11-17 19:13:41 +01:00
|
|
|
print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">".
|
|
|
|
__('Create label')."</button dojoType=\"dijit.form.Button\"> ";
|
2010-01-11 16:43:53 +01:00
|
|
|
|
2010-11-17 19:13:41 +01:00
|
|
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">".
|
|
|
|
__('Remove')."</button dojoType=\"dijit.form.Button\"> ";
|
2010-01-11 16:43:53 +01:00
|
|
|
|
2010-11-17 19:13:41 +01:00
|
|
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">".
|
|
|
|
__('Clear colors')."</button dojoType=\"dijit.form.Button\">";
|
2010-01-11 16:43:53 +01:00
|
|
|
|
|
|
|
|
2010-11-17 12:49:06 +01:00
|
|
|
print "</div>"; #toolbar
|
|
|
|
print "</div>"; #pane
|
|
|
|
print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
|
2006-10-01 12:05:20 +02:00
|
|
|
|
2010-11-18 18:04:57 +01:00
|
|
|
print "<div id=\"labellistLoading\">
|
|
|
|
<img src='images/indicator_tiny.gif'>".
|
|
|
|
__("Loading, please wait...")."</div>";
|
|
|
|
|
|
|
|
print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\"
|
|
|
|
url=\"backend.php?op=pref-labels&subop=getlabeltree\">
|
|
|
|
</div>
|
|
|
|
<div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\"
|
|
|
|
query=\"{id:'root'}\" rootId=\"root\"
|
|
|
|
childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
|
|
|
|
</div>
|
|
|
|
<div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\"
|
|
|
|
model=\"labelModel\" openOnClick=\"true\">
|
|
|
|
<script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
|
|
|
|
Element.hide(\"labellistLoading\");
|
|
|
|
</script>
|
|
|
|
</div>";
|
2010-11-17 12:49:06 +01:00
|
|
|
|
|
|
|
print "</div>"; #pane
|
|
|
|
print "</div>"; #container
|
2006-10-01 12:05:20 +02:00
|
|
|
}
|
2009-01-27 06:28:35 +01:00
|
|
|
|
2006-10-01 12:05:20 +02:00
|
|
|
?>
|