Changeset 89 for img

Show
Ignore:
Timestamp:
05/09/10 15:53:49 (4 months ago)
Author:
daniel
Message:

- Added: edit tag action

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • img/trunk/action.php

    r67 r89  
    5656                } 
    5757                break; 
     58        case 'tags': 
     59                switch (@$_GET['action']) { 
     60                        case 'edit': 
     61                                if (isset($_POST['tags'])) { 
     62                                        $sql = "BEGIN; 
     63UPDATE tags SET count = count - 1 WHERE ROWID IN (SELECT tag FROM imagetags WHERE image = '" . $row['id'] . "'); 
     64DELETE FROM imagetags WHERE image = '" . $row['id'] . "';\n"; 
     65                                         
     66                                        $tags = explode(',', $_POST['tags']); 
     67                                        for ($i = 0; $i < count($tags); $i++) { 
     68                                                $tags[$i] = trim($tags[$i]); 
     69                                        } 
     70                                        $tags = array_unique($tags); 
     71                                        foreach ($tags as $tag) { 
     72                                                if (empty($tag)) continue; 
     73                                                // check if the taga already exists 
     74                                                $row = $db->fetch($db->query("SELECT ROWID as id FROM tags WHERE tag = '" . $db->escape(strtolower($tag)) . "'")); 
     75                                                if (!$row) { 
     76                                                        $db->exec("INSERT INTO tags (tag, text) VALUES ('" . $db->escape(strtolower($tag)) . "', '" . $db->escape($tag) . "');"); 
     77                                                        $row = $db->fetch($db->query("SELECT last_insert_rowid() as id;")); 
     78                                                } 
     79                                                // Save the tag for this image and update tag counter 
     80                                                $sql .= "INSERT INTO imagetags (image, tag) VALUES('" . $id . "', '" . $row['id'] . "');\n"; 
     81                                                $sql .= "UPDATE tags SET count = count + 1 WHERE ROWID = '" . $row['id'] . "';\n"; 
     82                                        } 
     83                                        $sql .= "DELETE FROM tags WHERE count < 1;\n"; 
     84                                        $sql .= "COMMIT;"; 
     85                                        $db->exec($sql); 
     86                                } 
     87                        default: 
     88                                errorMsg('No action set.'); 
     89                                break;   
     90                break; 
    5891        default: 
    5992                errorMsg('No action type set.');