]>
git.wh0rd.org - tt-rss.git/blob - modules/pref-labels.php
2 // We need to accept raw SQL data in label queries, so not everything is escaped
3 // here, this is by design. If you don't like it, disable labels
4 // altogether with GLOBAL_ENABLE_LABELS = false
6 function module_pref_labels ( $link ) {
7 if (! GLOBAL_ENABLE_LABELS
) {
9 print "<p>Sorry, labels have been administratively disabled for this installation. Please contact instance owner or edit configuration file to enable this functionality.</p>" ;
13 $subop = $_GET [ "subop" ];
15 if ( $subop == "edit" ) {
17 $label_id = db_escape_string ( $_GET [ "id" ]);
19 $result = db_query ( $link , "SELECT sql_exp,description FROM ttrss_labels WHERE
20 owner_uid = " . $_SESSION [ "uid" ]. " AND id = ' $label_id ' ORDER by description" );
22 $line = db_fetch_assoc ( $result );
24 $sql_exp = htmlspecialchars ( $line [ "sql_exp" ]);
25 $description = htmlspecialchars ( $line [ "description" ]);
27 print "<div id= \" infoBoxTitle \" >Label editor</div>" ;
28 print "<div class= \" infoBoxContents \" >" ;
30 print "<form id= \" label_edit_form \" onsubmit='return false'>" ;
32 print "<input type= \" hidden \" name= \" op \" value= \" pref-labels \" >" ;
33 print "<input type= \" hidden \" name= \" id \" value= \" $label_id\" >" ;
34 print "<input type= \" hidden \" name= \" subop \" value= \" editSave \" >" ;
36 print "<table width='100%'>" ;
38 print "<tr><td>Caption:</td>
39 <td><input onkeypress= \" return filterCR(event, labelEditSave) \"
40 onkeyup= \" toggleSubmitNotEmpty(this, 'infobox_submit') \"
41 onchange= \" toggleSubmitNotEmpty(this, 'infobox_submit') \"
42 name= \" description \" class= \" iedit \" value= \" $description\" >" ;
46 print "<tr><td colspan= \" 2 \" >
47 <p>SQL Expression:</p>" ;
49 print "<textarea onkeyup= \" toggleSubmitNotEmpty(this, 'infobox_submit') \"
50 rows= \" 4 \" name= \" sql_exp \" class= \" iedit \" > $sql_exp </textarea>" ;
52 print "</td></tr></table>" ;
56 print "<div style= \" display : none \" id= \" label_test_result \" ></div>" ;
58 print "<div align='right'>" ;
60 $is_disabled = ( strpos ( $_SERVER [ 'HTTP_USER_AGENT' ], 'Opera' ) !== FALSE ) ?
"disabled" : "" ;
62 print "<input $is_disabled type= \" submit \" onclick= \" return labelTest() \" value= \" Test \" >
65 print "<input type= \" submit \"
67 class= \" button \" onclick= \" return labelEditSave() \"
70 print "<input class= \" button \"
71 type= \" submit \" onclick= \" return labelEditCancel() \"
79 if ( $subop == "test" ) {
81 // no escaping here on purpose
82 $expr = trim ( $_GET [ "expr" ]);
83 $descr = db_escape_string ( trim ( $_GET [ "descr" ]));
86 print "<div>Error: SQL expression is blank.</div>" ;
95 $result = db_query ( $link ,
96 "SELECT count(ttrss_entries.id) AS num_matches
97 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
99 ttrss_user_entries.ref_id = ttrss_entries.id AND
100 ttrss_user_entries.feed_id = ttrss_feeds.id AND
101 ttrss_user_entries.owner_uid = " . $_SESSION [ "uid" ], false );
103 error_reporting ( DEFAULT_ERROR_LEVEL
);
106 print "<div class= \" labelTestError \" >" . db_last_error ( $link ) . "</div>" ;
111 $num_matches = db_fetch_result ( $result , 0 , "num_matches" );;
113 if ( $num_matches > 0 ) {
115 if ( $num_matches > 10 ) {
116 $showing_msg = ", showing first 10" ;
119 print "<p>Query returned <b> $num_matches </b> matches $showing_msg :</p>" ;
121 $result = db_query ( $link ,
122 "SELECT ttrss_entries.title,
123 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
124 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
126 ttrss_user_entries.ref_id = ttrss_entries.id
127 AND ttrss_user_entries.feed_id = ttrss_feeds.id
128 AND ttrss_user_entries.owner_uid = " . $_SESSION [ "uid" ] . "
129 ORDER BY date_entered LIMIT 10" , false );
131 print "<ul class= \" labelTestResults \" >" ;
135 while ( $line = db_fetch_assoc ( $result )) {
136 $row_class = toggleEvenOdd ( $row_class );
138 print "<li class= \" $row_class\" >" . $line [ "title" ].
139 " <span class= \" insensitive \" >(" . $line [ "feed_title" ]. ")</span></li>" ;
144 print "<p>Query didn't return any matches.</p>" ;
152 if ( $subop == "editSave" ) {
154 $sql_exp = db_escape_string ( trim ( $_GET [ "sql_exp" ]));
155 $descr = db_escape_string ( trim ( $_GET [ "description" ]));
156 $label_id = db_escape_string ( $_GET [ "id" ]);
158 $result = db_query ( $link , "UPDATE ttrss_labels SET
159 sql_exp = ' $sql_exp ',
160 description = ' $descr '
161 WHERE id = ' $label_id '" );
163 if ( db_affected_rows ( $link , $result ) != 0 ) {
164 print_notice ( T_sprintf ( "Saved label <b> %s </b>" , htmlspecialchars ( $descr )));
169 if ( $subop == "remove" ) {
171 if (! WEB_DEMO_MODE
) {
173 $ids = split ( "," , db_escape_string ( $_GET [ "ids" ]));
175 foreach ( $ids as $id ) {
176 db_query ( $link , "DELETE FROM ttrss_labels WHERE id = ' $id '" );
182 if ( $subop == "add" ) {
184 $sql_exp = db_escape_string ( trim ( $_GET [ "sql_exp" ]));
185 $description = db_escape_string ( $_GET [ "description" ]);
187 if (! $sql_exp ||
! $description ) return ;
189 $result = db_query ( $link ,
190 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
191 VALUES (' $sql_exp ', ' $description ', '" . $_SESSION [ "uid" ]. "')" );
193 if ( db_affected_rows ( $link , $result ) != 0 ) {
194 print T_sprintf ( "Created label <b> %s </b>" , htmlspecialchars ( $description ));
200 set_pref ( $link , "_PREFS_ACTIVE_TAB" , "labelConfig" );
202 $sort = db_escape_string ( $_GET [ "sort" ]);
204 if (! $sort ||
$sort == "undefined" ) {
205 $sort = "description" ;
208 print "<a class='helpLinkPic' href= \" javascript:displayHelpInfobox(1) \" >
209 <img src='images/sign_quest.png'></a>" ;
211 print "<div class= \" prefGenericAddBox \" >" ;
213 print "<input type= \" submit \" class= \" button \"
214 id= \" label_create_btn \"
215 onclick= \" return displayDlg('quickAddLabel', false) \"
216 value= \" " . __ ( 'Create label' ). " \" ></div>" ;
218 $result = db_query ( $link , "SELECT
219 id,sql_exp,description
223 owner_uid = " . $_SESSION [ "uid" ]. "
226 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
228 if ( db_num_rows ( $result ) != 0 ) {
230 print "<p><table width= \" 100% \" cellspacing= \" 0 \"
231 class= \" prefLabelList \" id= \" prefLabelList \" >" ;
233 print "<tr><td class= \" selectPrompt \" colspan= \" 8 \" >
235 <a href= \" javascript:selectPrefRows('label', true) \" >" . __ ( 'All' ). "</a>,
236 <a href= \" javascript:selectPrefRows('label', false) \" >" . __ ( 'None' ). "</a>
239 print "<tr class= \" title \" >
240 <td width= \" 5% \" > </td>
241 <td width= \" 30% \" ><a href= \" javascript:updateLabelList('description') \" >" . __ ( 'Caption' ). "</a></td>
242 <td width= \"\" ><a href= \" javascript:updateLabelList('sql_exp') \" >" . __ ( 'SQL Expression' ). "</a>
248 while ( $line = db_fetch_assoc ( $result )) {
250 $class = ( $lnum %
2 ) ?
"even" : "odd" ;
252 $label_id = $line [ "id" ];
253 $edit_label_id = $_GET [ "id" ];
255 if ( $subop == "edit" && $label_id != $edit_label_id ) {
259 $this_row_id = "id= \" LILRR- $label_id\" " ;
262 print "<tr class= \" $class\" $this_row_id >" ;
264 $line [ "sql_exp" ] = htmlspecialchars ( $line [ "sql_exp" ]);
265 $line [ "description" ] = htmlspecialchars ( $line [ "description" ]);
267 if (! $line [ "description" ]) $line [ "description" ] = "[No caption]" ;
269 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \" label \" );'
270 type= \" checkbox \" id= \" LICHK-" . $line [ "id" ]. " \" ></td>" ;
272 print "<td><a href= \" javascript:editLabel( $label_id ); \" >" .
273 $line [ "description" ] . "</td>" ;
275 print "<td><a href= \" javascript:editLabel( $label_id ); \" >" .
276 $line [ "sql_exp" ] . "</td>" ;
284 print "<tr><td colspan= \" 4 \" align= \" center \" >" . __ ( 'No labels defined.' ). "</td></tr>" ;
289 print "<p id= \" labelOpToolbar \" >" ;
291 print "<input type= \" submit \" class= \" button \" disabled= \" true \"
292 onclick= \" javascript:editSelectedLabel() \" value= \" " . __ ( 'Edit' ). " \" >
293 <input type= \" submit \" class= \" button \" disabled= \" true \"
294 onclick= \" javascript:removeSelectedLabels() \" value= \" " . __ ( 'Remove' ). " \" >" ;
297 print "<p>" . __ ( 'No labels defined.' ). "</p>" ;