]> git.wh0rd.org Git - tt-rss.git/commitdiff
new function: label_create
authorAndrew Dolgov <fox@bah.spb.su>
Fri, 23 Jan 2009 06:42:37 +0000 (07:42 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Fri, 23 Jan 2009 06:42:37 +0000 (07:42 +0100)
functions.php
modules/pref-labels.php

index 0fb1fc287dd0906184c68ac555f928cfa49f0084..af3dfe809b26493df7e551c93db8a6da1a90e87e 100644 (file)
                db_query($link, "COMMIT");
        }
 
+       function label_create($link, $caption) {
+
+               db_query($link, "BEGIN");
+
+               $result = false;
+
+               $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"]."')");
+
+                       $result = db_affected_rows($link, $result) != 0;
+               }
+
+               db_query($link, "COMMIT");
+
+               return $result;
+       }
+
        function print_labels_headlines_dropdown($link, $feed_id) {
                print "<li onclick=\"javascript:addLabel()\">
                        &nbsp;&nbsp;".__("Create label...")."</li>";
index c645b12a1e0853d9cfc47aff5b1994162fa20899..b09a16cf56568ff21592dc47dd5341416543c506 100644 (file)
 
                        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;