Changeset 157


Ignore:
Timestamp:
08/17/05 13:12:00 (5 years ago)
Author:
anti
Message:

+ implement get_collection_by_name
+ do not allow collections with duplicate names, ticket #60

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/plog-admin-functions.php

    r154 r157  
    184184        }; 
    185185 
     186        // do not allow collections with duplicate names, otherwise mod_rewritten links will start 
     187        // to behave weird. 
     188        $collection_exists = get_collection_by_name($collection_name); 
     189        if ($collection_exists) { 
     190                return array("errors" => 'New collection could not be created, because there already is one named `'.$collection_exists['name'].'`!'); 
     191        } 
     192 
    186193        $collection_folder = strtolower(sanitize_filename($collection_name)); 
    187194        // first try to create the directory, and only if that succeeds, then insert 
     
    221228 
    222229        $errors = $output = ""; 
     230         
     231        $name = trim(SmartStripSlashes($name)); 
     232        if (empty($name)) { 
     233                return array("errors" => "Please enter a valid name for the collection"); 
     234        }; 
    223235 
    224236        $target_name = strtolower(sanitize_filename($name)); 
    225         /* 
    226         if (!is_valid_directory($name)) { 
    227                 $errors .= 'Collection name contains invalid characters!'; 
    228                 return array("errors" => $errors); 
    229         }; 
    230         */ 
     237         
    231238 
    232239        $errors = $output = ""; 
     
    240247        // rename the directory 
    241248        // first, get the collection name of our source collection 
    242         $sql = "SELECT c.path as collection_path 
     249        $sql = "SELECT c.path as collection_path,name 
    243250                        FROM ".$TABLE_PREFIX."collections c 
    244251                        WHERE c.id = '$collection_id'"; 
     
    246253        $result = run_query($sql); 
    247254        $row = mysql_fetch_assoc($result); 
     255         
     256        // do not allow collections with duplicate names, otherwise mod_rewritten links will start 
     257        // to behave weird. 
     258        $collection_exists = get_collection_by_name($name); 
     259        if ($row["name"] != $name && $collection_exists) { 
     260                return array("errors" => 'Collection `' . $row['name'] . '` could not be renamed to `'.$name.'`, because there is another collection with that name'); 
     261        } 
    248262 
    249263        $source_collection_name = $row["collection_path"]; 
  • trunk/plog-functions.php

    r151 r157  
    8484        }; 
    8585        return $picdata; 
     86} 
     87 
     88function get_collection_by_name($name) { 
     89        global $TABLE_PREFIX; 
     90        $name = mysql_real_escape_string($name); 
     91        $sql = "SELECT * FROM `".$TABLE_PREFIX."collections` WHERE name = '$name'"; 
     92        $result = run_query($sql); 
     93        $collection = mysql_fetch_assoc($result); 
     94        return $collection; 
    8695} 
    8796 
Note: See TracChangeset for help on using the changeset viewer.