tt-rss/modules/pref-labels.php

308 lines
7.9 KiB
PHP
Raw Normal View History

<?php
function module_pref_labels($link) {
$subop = $_GET["subop"];
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"]);
}
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"]);
}
2009-01-26 12:30:13 +01:00
}
2009-01-18 09:28:42 +01:00
if ($subop == "save") {
2009-01-18 09:28:42 +01:00
$id = db_escape_string($_REQUEST["id"]);
$caption = db_escape_string(trim($_REQUEST["value"]));
2009-01-18 09:28:42 +01:00
db_query($link, "BEGIN");
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"]);
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"]);
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"]);
2009-01-18 09:28:42 +01:00
/* Update filters that reference label being renamed */
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"]);
print $_REQUEST["value"];
} else {
print $old_caption;
2009-01-18 09:28:42 +01:00
}
} else {
print $old_caption;
}
}
2009-01-18 09:28:42 +01:00
db_query($link, "COMMIT");
return;
}
if ($subop == "remove") {
2009-01-18 09:28:42 +01:00
$ids = split(",", db_escape_string($_GET["ids"]));
foreach ($ids as $id) {
label_remove($link, $id, $_SESSION["uid"]);
}
}
if ($subop == "add") {
2009-01-18 09:28:42 +01:00
$caption = db_escape_string($_GET["caption"]);
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)) {
print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
2009-01-18 09:28:42 +01:00
}
2009-01-23 07:42:37 +01:00
}
return;
}
2007-05-04 05:26:20 +02:00
set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig");
$sort = db_escape_string($_GET["sort"]);
if (!$sort || $sort == "undefined") {
2009-01-18 09:28:42 +01:00
$sort = "caption";
}
2008-05-17 05:07:39 +02:00
$label_search = db_escape_string($_GET["search"]);
if (array_key_exists("search", $_GET)) {
$_SESSION["prefs_label_search"] = $label_search;
} else {
$label_search = $_SESSION["prefs_label_search"];
}
print "<div class=\"feedEditSearch\">
<input id=\"label_search\" size=\"20\" type=\"search\"
onfocus=\"javascript:disableHotkeys();\"
onblur=\"javascript:enableHotkeys();\"
2008-05-17 05:07:39 +02:00
onchange=\"javascript:updateLabelList()\" value=\"$label_search\">
<input type=\"submit\" class=\"button\"
onclick=\"javascript:updateLabelList()\" value=\"".__('Search')."\">
</div>";
print "<div class=\"prefGenericAddBox\">";
print"<input type=\"submit\" class=\"button\"
id=\"label_create_btn\"
2009-01-18 09:28:42 +01:00
onclick=\"return addLabel()\"
2007-03-05 12:02:18 +01:00
value=\"".__('Create label')."\"></div>";
2008-05-17 05:07:39 +02:00
if ($label_search) {
2009-01-18 09:28:42 +01:00
$label_search_query = "caption LIKE '%$label_search%' AND";
2008-05-17 05:07:39 +02:00
} else {
$label_search_query = "";
}
$result = db_query($link, "SELECT
2009-01-26 11:07:53 +01:00
*
FROM
2009-01-18 09:28:42 +01:00
ttrss_labels2
WHERE
2008-05-17 05:07:39 +02:00
$label_search_query
owner_uid = ".$_SESSION["uid"]."
ORDER BY $sort");
// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
if (db_num_rows($result) != 0) {
print "<p><table width=\"100%\" cellspacing=\"0\"
class=\"prefLabelList\" id=\"prefLabelList\">";
print "<tr><td class=\"selectPrompt\" colspan=\"8\">
".__('Select:')."
<a href=\"javascript:selectPrefRows('label', true)\">".__('All')."</a>,
<a href=\"javascript:selectPrefRows('label', false)\">".__('None')."</a>
</td</tr>";
2009-01-18 11:17:17 +01:00
/* print "<tr class=\"title\">
<td width=\"5%\">&nbsp;</td>
2009-01-18 11:17:17 +01:00
<td width=\"95%\"><a href=\"javascript:updateLabelList('caption')\">".__('Caption')."</a></td>
</td>
2009-01-18 11:17:17 +01:00
</tr>"; */
$lnum = 0;
while ($line = db_fetch_assoc($result)) {
$class = ($lnum % 2) ? "even" : "odd";
$label_id = $line["id"];
2009-01-18 09:28:42 +01:00
$this_row_id = "id=\"LILRR-$label_id\"";
print "<tr class=\"$class\" $this_row_id>";
2009-01-18 09:28:42 +01:00
$line["caption"] = htmlspecialchars($line["caption"]);
2009-01-26 11:07:53 +01:00
$fg_color = $line["fg_color"];
$bg_color = $line["bg_color"];
2009-01-26 17:01:46 +01:00
if (!$fg_color) $fg_color = "";
if (!$bg_color) $bg_color = "";
2009-01-26 11:07:53 +01:00
2009-01-18 11:17:17 +01:00
print "<td width='5%' align='center'><input
2009-01-18 09:28:42 +01:00
onclick='toggleSelectPrefRow(this, \"label\");'
type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2009-01-26 12:05:06 +01:00
$id = $line['id'];
2009-01-26 11:54:47 +01:00
2009-01-26 17:01:46 +01:00
print "<td>";
print "<div class='labelColorIndicator' id='LICID-$id'
2009-01-26 11:07:53 +01:00
style='color : $fg_color; background-color : $bg_color'
title='".__('Click to change color')."'
2009-01-26 17:46:23 +01:00
onclick=\"colorPicker('$id', '$fg_color', '$bg_color')\">&alpha;";
print_color_picker($id);
print "</div>";
2009-01-26 11:54:47 +01:00
2009-01-26 17:01:46 +01:00
print "<span class='prefsLabelEntry'
2009-01-26 11:07:53 +01:00
id=\"LILT-".$line["id"]."\">" . $line["caption"] .
2009-01-26 11:54:47 +01:00
"</span>";
2009-01-26 12:05:06 +01:00
print "</td>";
print "</tr>";
++$lnum;
}
print "</table>";
print "<p id=\"labelOpToolbar\">";
2009-01-26 12:08:05 +01:00
2009-01-26 12:30:13 +01:00
print "<input type=\"submit\" class=\"button\" disabled=\"true\"
onclick=\"javascript:removeSelectedLabels()\" value=\"".__('Remove')."\">";
2009-01-26 17:46:23 +01:00
print "&nbsp;";
/* print "&nbsp;<input type=\"submit\" class=\"button\" disabled=\"true\"
2009-01-26 12:30:13 +01:00
onclick=\"labelColorSet('fg')\" value=\"".__('Fg')."\">&nbsp;";
2009-01-26 12:08:05 +01:00
print "<input type=\"submit\" class=\"button\" disabled=\"true\"
2009-01-26 17:46:23 +01:00
onclick=\"labelColorSet('bg')\" value=\"".__('Bg')."\">&nbsp;"; */
2009-01-26 12:08:05 +01:00
print "<input type=\"submit\" class=\"button\" disabled=\"true\"
2009-01-26 17:46:23 +01:00
onclick=\"labelColorReset()\" value=\"".__('Clear colors')."\">";
2009-01-26 12:08:05 +01:00
2009-01-18 09:28:42 +01:00
print "</p>";
} else {
print "<p>";
if (!$label_search) {
print __('No labels defined.');
} else {
print __('No matching labels found.');
}
print "</p>";
}
}
2009-01-27 06:28:35 +01: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')\">&alpha;</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>";
}
?>