]> git.quilime.com - clmpr.git/commitdiff
Implemented ability to delete tags
authorGabriel Dunne <gdunne@quilime.com>
Sun, 18 Dec 2011 19:25:32 +0000 (11:25 -0800)
committerGabriel Dunne <gdunne@quilime.com>
Sun, 18 Dec 2011 19:25:32 +0000 (11:25 -0800)
clmpr.sql
data.php
delete.php
get.php
put.php

index 6a9a88a2d16fca4a627d97c5aa45ac633fcdd3d3..85697439cb8902f45f46f154654679bdc277b11f 100644 (file)
--- a/clmpr.sql
+++ b/clmpr.sql
@@ -29,4 +29,3 @@ CREATE TABLE `users` (
   PRIMARY KEY (`id`),
   UNIQUE KEY `user` (`user`)
 ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-
index f071328d176d569d2d8db2d3098eac28193964a4..fb59b3dd75b4a3e35f9531e8917c5fb785e3e3ed 100644 (file)
--- a/data.php
+++ b/data.php
@@ -37,4 +37,4 @@ function get_users(&$dbh, $args)
     }
 
     return false;
-}
\ No newline at end of file
+}
index f5324f27768c76a699e63349f47d1cfdf90519b1..f37b26f29e545e52ff1ce25caa565f7464da3ea4 100644 (file)
@@ -1,30 +1,56 @@
 <?php
 
-    include 'init.php';
-
-    $params = array();
-    $params['clump_id'] = isset($_POST['clump_id']) ? $_POST['clump_id'] : null;
-
-    try {
-
-        $dbh = get_db_connection();
-        $dbh->beginTransaction();
-
-        if ($user = get_user()) {
-            $sql = "DELETE FROM clmpr.clumps WHERE id = ? AND user_id = ?";
-            $q = $dbh->prepare($sql);
-            $count = $q->execute( array( $params['clump_id'], $user['id'] ));
-            $dbh = null;
-            echo json_encode(array('deleted' => true));
-            exit;
-        } else {
-            echo json_encode(array('mssg' => 'must be logged in'));
-        }
-        exit;
-    }
-    catch(PDOException $e)
-    {
-        echo $e->getMessage();
+include 'init.php';
+
+$params = array();
+$params['clump_id'] = isset($_POST['clump_id']) ? $_POST['clump_id'] : null;
+
+try {
+
+    $dbh = get_db_connection();
+    $dbh->beginTransaction();
+    $user = get_user();
+
+    if ($user && $params['clump_id']) {
+
+        # get current clump
+        $q = $dbh->prepare("SELECT * 
+                            FROM clumps
+                            JOIN users ON users.id = clumps.user_id 
+                            WHERE user_id = ? AND clumps.id = ? 
+                            LIMIT 1");
+        $q->execute( array( $user['id'], $params['clump_id'] ));
+        $row = $q->fetch();
+
+        # decrement tag count in DB
+        # note: leaves tags in database with count of '0' if not used
+        $tags = explode(" ", $row['tags']);
+        if (count($tags) > 0) {
+            foreach($tags as $key => $tag) {
+                $sql = "UPDATE tags
+                        SET count = count - 1
+                        WHERE tag = ? AND count > 0";
+                $q = $dbh->prepare($sql);
+                $q->execute( array( $tag ));
+            }
+        }            
+
+        # delete clump
+        $sql = "DELETE FROM clumps WHERE id = ? AND user_id = ?";
+        $q = $dbh->prepare($sql);
+        $count = $q->execute( array( $params['clump_id'], $user['id'] ));
+        echo json_encode(array('deleted' => true));        
+    } else {
+        echo json_encode(array('mssg' => 'must be logged in'));
     }
 
-    exit;
\ No newline at end of file
+    $dbh = null;
+    $q = null;    
+    
+}
+catch(PDOException $e)
+{
+    echo $e->getMessage();
+}
+
+exit;
diff --git a/get.php b/get.php
index d51cac8ddf5cdb343b306965c3b5fe137f46bf54..a004ff85370b7f51467e15b25d7f90daa16742bf 100644 (file)
--- a/get.php
+++ b/get.php
@@ -81,7 +81,6 @@ case 'xml' :
         <?php else : ?>
         &nbsp; 
         <?php endif; ?>
-
             
         <span class="url">
             <a href="<?php echo $row['url'] ?>">
diff --git a/put.php b/put.php
index a78631ba7604660160aa045db2a0c35c96fb7123..b874a95de5d997405624637bde3718e188a9a081 100644 (file)
--- a/put.php
+++ b/put.php
@@ -33,22 +33,19 @@ try {
 
         # insert clump
         $sql = "INSERT INTO `clmpr`.`clumps` ( `user_id`, `title` , `url` , `tags`, `description`, `date` )
-                VALUES ( ?, ?, ?, ?, ?, NOW() ) ";
+                VALUES ( ?, ?, ?, ?, ?, NOW() ) ";  
         $q = $dbh->prepare($sql);
         $insert = $q->execute( array( $user['id'], $params['title'], $params['url'], implode(" ", $tags), htmlentities($params['description']) ));
 
-
-        $dbh = null;
-
         echo "clumped.<br/><br/>";
         echo '<a href="javascript:window.close();">ok</a>';
         echo '<script>window.close();</script>';
 
+        $dbh = null;
+        $q = null;    
 
     } else {
-
         include 'signin.php';
-
     }
 }
 catch(PDOException $e)