]> git.wh0rd.org - tt-rss.git/blobdiff - modules/pref-labels.php
prefs: reorganize toolbar buttons
[tt-rss.git] / modules / pref-labels.php
index 797d2de3f5fcb142d20f891410cd68496b46ceb1..a6324c7a2b70fb6128fb8402319d2c30547154a7 100644 (file)
@@ -1,7 +1,41 @@
 <?php
        function module_pref_labels($link) {
 
-               $subop = $_GET["subop"];
+               $subop = $_REQUEST["subop"];
+
+               if ($subop == "color-set") {
+                       $kind = db_escape_string($_REQUEST["kind"]);
+                       $ids = split(',', db_escape_string($_REQUEST["ids"]));
+                       $color = db_escape_string($_REQUEST["color"]);
+                       $fg = db_escape_string($_REQUEST["fg"]);
+                       $bg = db_escape_string($_REQUEST["bg"]);
+
+                       foreach ($ids as $id) {
+
+                               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"]);                  
+                               }
+                       }
+
+                       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"]);                  
+                       }
+
+               }
 
                if ($subop == "save") {
 
@@ -27,6 +61,8 @@
 
                                                /* Update filters that reference label being renamed */
 
+                                               $old_caption = db_escape_string($old_caption);
+
                                                db_query($link, "UPDATE ttrss_filters SET
                                                        action_param = '$caption' WHERE action_param = '$old_caption'
                                                        AND action_id = 7
 
                if ($subop == "remove") {
 
-                       $ids = split(",", db_escape_string($_GET["ids"]));
-
-                       db_query($link, "BEGIN");
+                       $ids = split(",", db_escape_string($_REQUEST["ids"]));
 
                        foreach ($ids as $id) {
-                               $result = db_query($link, "SELECT caption FROM ttrss_labels2
-                                       WHERE id = '$id'");
-
-                               $caption = db_fetch_result($result, 0, "caption");
-
-                               $result = db_query($link, "DELETE FROM ttrss_labels2 WHERE id = '$id'
-                                       AND owner_uid = " . $_SESSION["uid"]);
-
-                               if (db_affected_rows($link, $result) != 0 && $caption) {
-
-                                               /* Disable filters that reference label being removed */
-
-                                               db_query($link, "UPDATE ttrss_filters SET
-                                                       enabled = false WHERE action_param = '$caption'
-                                                       AND action_id = 7
-                                                       AND owner_uid = " . $_SESSION["uid"]);
-                               }
+                               label_remove($link, $id, $_SESSION["uid"]);
                        }
 
-                       db_query($link, "COMMIT");
-
                }
 
                if ($subop == "add") {
 
-                       $caption = db_escape_string($_GET["caption"]);
+                       $caption = db_escape_string($_REQUEST["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));
-                                       }
+                               if (label_create($link, $caption)) {
+                                       print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
                                }
+
                        }
 
                        return;
 
                set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig");
 
-               $sort = db_escape_string($_GET["sort"]);
+               $sort = db_escape_string($_REQUEST["sort"]);
 
                if (!$sort || $sort == "undefined") {
                        $sort = "caption";
                }
 
-               $label_search = db_escape_string($_GET["search"]);
+               $label_search = db_escape_string($_REQUEST["search"]);
 
-               if (array_key_exists("search", $_GET)) {
+               if (array_key_exists("search", $_REQUEST)) {
                        $_SESSION["prefs_label_search"] = $label_search;
                } else {
                        $label_search = $_SESSION["prefs_label_search"];
                print"<input type=\"submit\" class=\"button\" 
                        id=\"label_create_btn\"
                        onclick=\"return addLabel()\" 
-                       value=\"".__('Create label')."\"></div>";
+                       value=\"".__('Create label')."\"> ";
+
+                       print "<input type=\"submit\" class=\"button\"
+                               onclick=\"javascript:removeSelectedLabels()\" value=\"".__('Remove')."\">";
+
+                       print "&nbsp;";
+/*                     print "&nbsp;<input type=\"submit\" class=\"button\" disabled=\"true\"
+                               onclick=\"labelColorSet('fg')\" value=\"".__('Fg')."\">&nbsp;";
+                       print "<input type=\"submit\" class=\"button\" disabled=\"true\"
+                               onclick=\"labelColorSet('bg')\" value=\"".__('Bg')."\">&nbsp;"; */
+                       print "<input type=\"submit\" class=\"button\"
+                               onclick=\"labelColorReset()\" value=\"".__('Clear colors')."\">";
+
+
+               print "</div>";
 
                if ($label_search) {
-                       $label_search_query = "caption LIKE '%$label_search%' AND";
+
+                       $label_search = split(" ", $label_search);
+                       $tokens = array();
+
+                       foreach ($label_search as $token) {
+
+                               $token = trim($token);
+                               array_push($tokens, "(UPPER(caption) LIKE UPPER('%$token%'))");
+
+                       }
+
+                       $label_search_query = "(" . join($tokens, " AND ") . ") AND ";
+                       
                } else {
                        $label_search_query = "";
                }
 
                $result = db_query($link, "SELECT 
-                               id,caption
+                               *
                        FROM 
                                ttrss_labels2
                        WHERE 
                                print "<tr class=\"$class\" $this_row_id>";
        
                                $line["caption"] = htmlspecialchars($line["caption"]);
-       
+
+                               $fg_color = $line["fg_color"];
+                               $bg_color = $line["bg_color"];
+
+                               if (!$fg_color) $fg_color = "";
+                               if (!$bg_color) $bg_color = "";
+
                                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>";
+                               $id = $line['id'];
+
+                               print "<td>";
+
+                               print "<div class='labelColorIndicator' id='LICID-$id' 
+                                       style='color : $fg_color; background-color : $bg_color'
+                                       title='".__('Click to change color')."'
+                                       onclick=\"colorPicker('$id', '$fg_color', '$bg_color')\">&alpha;";
+                               print_color_picker($id);
+                               print "</div>";
+
+
+                               print "<span class='prefsLabelEntry' 
+                                       id=\"LILT-".$line["id"]."\">" . $line["caption"] . 
+                                       "</span>";
+
+                               print "</td>";
 
                                print "</tr>";
        
 
                        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.');
+                               print_warning(__('No labels defined.'));
                        } else {
-                               print __('No matching labels found.');
+                               print_warning(__('No matching labels found.'));
                        }
                        print "</p>";
 
                }
        }
+
+       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>";
+       }
+
 ?>