summaryrefslogtreecommitdiff
path: root/modules/pref-labels.php
blob: c645b12a1e0853d9cfc47aff5b1994162fa20899 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
	function module_pref_labels($link) {

		$subop = $_GET["subop"];

		if ($subop == "save") {

			$id = db_escape_string($_REQUEST["id"]);
			$caption = db_escape_string(trim($_REQUEST["value"]));

			db_query($link, "BEGIN");

			$result = db_query($link, "SELECT caption FROM ttrss_labels2
				WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);

			if (db_num_rows($result) != 0) {
				$old_caption = db_fetch_result($result, 0, "caption");

				$result = db_query($link, "SELECT id FROM ttrss_labels2
					WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);

				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"]);

						/* Update filters that reference label being renamed */

						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;
					}
				} else {
					print $old_caption;
				}
			}

			db_query($link, "COMMIT");

			return;
		}

		if ($subop == "remove") {

			$ids = split(",", db_escape_string($_GET["ids"]));

			foreach ($ids as $id) {
				label_remove($link, $id, $_SESSION["uid"]);
			}

		}

		if ($subop == "add") {

			$caption = db_escape_string($_GET["caption"]);

			if ($caption) {

				$result = db_query($link, "SELECT id FROM ttrss_labels2
					WHERE caption = '$caption' AND owner_uid =  ". $_SESSION["uid"]);

				if (db_num_rows($result) == 0) {

					$result = db_query($link,
						"INSERT INTO ttrss_labels2 (caption,owner_uid) 
						VALUES ('$caption', '".$_SESSION["uid"]."')");

					if (db_affected_rows($link, $result) != 0) {
						print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
					}
				}
			}

			return;
		}

		set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig");

		$sort = db_escape_string($_GET["sort"]);

		if (!$sort || $sort == "undefined") {
			$sort = "caption";
		}

		$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();\"
				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\"
			onclick=\"return addLabel()\" 
			value=\"".__('Create label')."\"></div>";

		if ($label_search) {
			$label_search_query = "caption LIKE '%$label_search%' AND";
		} else {
			$label_search_query = "";
		}

		$result = db_query($link, "SELECT 
				id,caption
			FROM 
				ttrss_labels2
			WHERE 
				$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>";

/*			print "<tr class=\"title\">
						<td width=\"5%\">&nbsp;</td>
						<td width=\"95%\"><a href=\"javascript:updateLabelList('caption')\">".__('Caption')."</a></td>
						</td>
						</tr>"; */
			
			$lnum = 0;
			
			while ($line = db_fetch_assoc($result)) {
	
				$class = ($lnum % 2) ? "even" : "odd";
	
				$label_id = $line["id"];
				$this_row_id = "id=\"LILRR-$label_id\"";

				print "<tr class=\"$class\" $this_row_id>";
	
				$line["caption"] = htmlspecialchars($line["caption"]);
	
				print "<td width='5%' align='center'><input 
					onclick='toggleSelectPrefRow(this, \"label\");' 
					type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
	
				print "<td><span id=\"LILT-".$line["id"]."\">" . $line["caption"] . 
					"</span></td>";

				print "</tr>";
	
				++$lnum;
			}

			print "</table>";
	
			print "<p id=\"labelOpToolbar\">";
			print "<input type=\"submit\" class=\"button\" disabled=\"true\"
				onclick=\"javascript:removeSelectedLabels()\" value=\"".__('Remove')."\">";
			print "</p>";

		} else {
			print "<p>";
			if (!$label_search) {
				print __('No labels defined.');
			} else {
				print __('No matching labels found.');
			}
			print "</p>";

		}
	}
?>