pref-labels.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. function module_pref_labels($link) {
  3. $method = $_REQUEST["method"];
  4. if ($method == "edit") {
  5. $label_id = db_escape_string($_REQUEST['id']);
  6. $result = db_query($link, "SELECT * FROM ttrss_labels2 WHERE
  7. id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
  8. $line = db_fetch_assoc($result);
  9. # print "<form id=\"label_edit_form\" name=\"label_edit_form\"
  10. # onsubmit=\"return false;\">";
  11. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$label_id\">";
  12. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-labels\">";
  13. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">";
  14. print "<div class=\"dlgSec\">".__("Caption")."</div>";
  15. print "<div class=\"dlgSecCont\">";
  16. $fg_color = $line['fg_color'];
  17. $bg_color = $line['bg_color'];
  18. print "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-bottom : 4px; margin-right : 4px'>&alpha;</span>";
  19. print "<input style=\"font-size : 16px\" name=\"caption\"
  20. dojoType=\"dijit.form.ValidationTextBox\"
  21. required=\"true\"
  22. value=\"".htmlspecialchars($line['caption'])."\">";
  23. print "</div>";
  24. print "<div class=\"dlgSec\">" . __("Colors") . "</div>";
  25. print "<div class=\"dlgSecCont\">";
  26. print "<table cellspacing=\"0\">";
  27. print "<tr><td>".__("Foreground:")."</td><td>".__("Background:").
  28. "</td></tr>";
  29. print "<tr><td style='padding-right : 10px'>";
  30. print "<input dojoType=\"dijit.form.TextBox\"
  31. style=\"display : none\" id=\"labelEdit_fgColor\"
  32. name=\"fg_color\" value=\"$fg_color\">";
  33. print "<input dojoType=\"dijit.form.TextBox\"
  34. style=\"display : none\" id=\"labelEdit_bgColor\"
  35. name=\"bg_color\" value=\"$bg_color\">";
  36. print "<div dojoType=\"dijit.ColorPalette\">
  37. <script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\">
  38. dijit.byId(\"labelEdit_fgColor\").attr('value', fg_color);
  39. $('label-editor-indicator').setStyle({color: fg_color});
  40. </script>
  41. </div>";
  42. print "</div>";
  43. print "</td><td>";
  44. print "<div dojoType=\"dijit.ColorPalette\">
  45. <script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\">
  46. dijit.byId(\"labelEdit_bgColor\").attr('value', bg_color);
  47. $('label-editor-indicator').setStyle({backgroundColor: bg_color});
  48. </script>
  49. </div>";
  50. print "</div>";
  51. print "</td></tr></table>";
  52. print "</div>";
  53. # print "</form>";
  54. print "<div class=\"dlgButtons\">";
  55. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').execute()\">".
  56. __('Save')."</button>";
  57. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').hide()\">".
  58. __('Cancel')."</button>";
  59. print "</div>";
  60. return;
  61. }
  62. if ($method == "getlabeltree") {
  63. $root = array();
  64. $root['id'] = 'root';
  65. $root['name'] = __('Labels');
  66. $root['items'] = array();
  67. $result = db_query($link, "SELECT *
  68. FROM ttrss_labels2
  69. WHERE owner_uid = ".$_SESSION["uid"]."
  70. ORDER BY caption");
  71. while ($line = db_fetch_assoc($result)) {
  72. $label = array();
  73. $label['id'] = 'LABEL:' . $line['id'];
  74. $label['bare_id'] = $line['id'];
  75. $label['name'] = $line['caption'];
  76. $label['fg_color'] = $line['fg_color'];
  77. $label['bg_color'] = $line['bg_color'];
  78. $label['type'] = 'label';
  79. $label['checkbox'] = false;
  80. array_push($root['items'], $label);
  81. }
  82. $fl = array();
  83. $fl['identifier'] = 'id';
  84. $fl['label'] = 'name';
  85. $fl['items'] = array($root);
  86. print json_encode($fl);
  87. return;
  88. }
  89. if ($method == "color-set") {
  90. $kind = db_escape_string($_REQUEST["kind"]);
  91. $ids = split(',', db_escape_string($_REQUEST["ids"]));
  92. $color = db_escape_string($_REQUEST["color"]);
  93. $fg = db_escape_string($_REQUEST["fg"]);
  94. $bg = db_escape_string($_REQUEST["bg"]);
  95. foreach ($ids as $id) {
  96. if ($kind == "fg" || $kind == "bg") {
  97. db_query($link, "UPDATE ttrss_labels2 SET
  98. ${kind}_color = '$color' WHERE id = '$id'
  99. AND owner_uid = " . $_SESSION["uid"]);
  100. } else {
  101. db_query($link, "UPDATE ttrss_labels2 SET
  102. fg_color = '$fg', bg_color = '$bg' WHERE id = '$id'
  103. AND owner_uid = " . $_SESSION["uid"]);
  104. }
  105. $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
  106. /* Remove cached data */
  107. db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
  108. WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
  109. }
  110. return;
  111. }
  112. if ($method == "color-reset") {
  113. $ids = split(',', db_escape_string($_REQUEST["ids"]));
  114. foreach ($ids as $id) {
  115. db_query($link, "UPDATE ttrss_labels2 SET
  116. fg_color = '', bg_color = '' WHERE id = '$id'
  117. AND owner_uid = " . $_SESSION["uid"]);
  118. $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
  119. /* Remove cached data */
  120. db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
  121. WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
  122. }
  123. }
  124. if ($method == "save") {
  125. $id = db_escape_string($_REQUEST["id"]);
  126. $caption = db_escape_string(trim($_REQUEST["caption"]));
  127. db_query($link, "BEGIN");
  128. $result = db_query($link, "SELECT caption FROM ttrss_labels2
  129. WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
  130. if (db_num_rows($result) != 0) {
  131. $old_caption = db_fetch_result($result, 0, "caption");
  132. $result = db_query($link, "SELECT id FROM ttrss_labels2
  133. WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
  134. if (db_num_rows($result) == 0) {
  135. if ($caption) {
  136. $result = db_query($link, "UPDATE ttrss_labels2 SET
  137. caption = '$caption' WHERE id = '$id' AND
  138. owner_uid = " . $_SESSION["uid"]);
  139. /* Update filters that reference label being renamed */
  140. $old_caption = db_escape_string($old_caption);
  141. db_query($link, "UPDATE ttrss_filters SET
  142. action_param = '$caption' WHERE action_param = '$old_caption'
  143. AND action_id = 7
  144. AND owner_uid = " . $_SESSION["uid"]);
  145. print $_REQUEST["value"];
  146. } else {
  147. print $old_caption;
  148. }
  149. } else {
  150. print $old_caption;
  151. }
  152. }
  153. db_query($link, "COMMIT");
  154. return;
  155. }
  156. if ($method == "remove") {
  157. $ids = split(",", db_escape_string($_REQUEST["ids"]));
  158. foreach ($ids as $id) {
  159. label_remove($link, $id, $_SESSION["uid"]);
  160. }
  161. }
  162. if ($method == "add") {
  163. $caption = db_escape_string($_REQUEST["caption"]);
  164. $output = db_escape_string($_REQUEST["output"]);
  165. if ($caption) {
  166. if (label_create($link, $caption)) {
  167. if (!$output) {
  168. print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
  169. }
  170. }
  171. if ($output == "select") {
  172. header("Content-Type: text/xml");
  173. print "<rpc-reply><payload>";
  174. print_label_select($link, "select_label",
  175. $caption, "");
  176. print "</payload></rpc-reply>";
  177. }
  178. }
  179. return;
  180. }
  181. $sort = db_escape_string($_REQUEST["sort"]);
  182. if (!$sort || $sort == "undefined") {
  183. $sort = "caption";
  184. }
  185. $label_search = db_escape_string($_REQUEST["search"]);
  186. if (array_key_exists("search", $_REQUEST)) {
  187. $_SESSION["prefs_label_search"] = $label_search;
  188. } else {
  189. $label_search = $_SESSION["prefs_label_search"];
  190. }
  191. print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
  192. print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
  193. print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">";
  194. print "<div dojoType=\"dijit.form.DropDownButton\">".
  195. "<span>" . __('Select')."</span>";
  196. print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
  197. print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\"
  198. dojoType=\"dijit.MenuItem\">".__('All')."</div>";
  199. print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\"
  200. dojoType=\"dijit.MenuItem\">".__('None')."</div>";
  201. print "</div></div>";
  202. print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">".
  203. __('Create label')."</button dojoType=\"dijit.form.Button\"> ";
  204. print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">".
  205. __('Remove')."</button dojoType=\"dijit.form.Button\"> ";
  206. print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">".
  207. __('Clear colors')."</button dojoType=\"dijit.form.Button\">";
  208. print "</div>"; #toolbar
  209. print "</div>"; #pane
  210. print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
  211. print "<div id=\"labellistLoading\">
  212. <img src='images/indicator_tiny.gif'>".
  213. __("Loading, please wait...")."</div>";
  214. print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\"
  215. url=\"backend.php?op=pref-labels&method=getlabeltree\">
  216. </div>
  217. <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\"
  218. query=\"{id:'root'}\" rootId=\"root\"
  219. childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
  220. </div>
  221. <div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\"
  222. model=\"labelModel\" openOnClick=\"true\">
  223. <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
  224. Element.hide(\"labellistLoading\");
  225. </script>
  226. <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
  227. var id = String(item.id);
  228. var bare_id = id.substr(id.indexOf(':')+1);
  229. if (id.match('LABEL:')) {
  230. editLabel(bare_id);
  231. }
  232. </script>
  233. </div>";
  234. print "</div>"; #pane
  235. print "</div>"; #container
  236. }
  237. ?>