Changeset 402 for branches


Ignore:
Timestamp:
05/23/06 18:47:39 (4 years ago)
Author:
stefan
Message:

merging in changes from trunk that have been made since the branch was created.

Location:
branches/plogger-with-tags
Files:
18 added
1 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • branches/plogger-with-tags/.htaccess

    r373 r402  
    1 # BEGIN Plogger 
    2 # END Plogger 
     1 
  • branches/plogger-with-tags/_install.php

    r401 r402  
    88        if (    @mysql_connect(PLOGGER_DB_HOST,PLOGGER_DB_USER,PLOGGER_DB_PW) && 
    99                @mysql_select_db(PLOGGER_DB_NAME)) { 
    10                 die("Plogger seems to have been already installed!<br/>If this is not the case and you really wish to attempt to create the Plogger database tables, please remove the file 'plog-config.php' from the Plogger installation directory."); 
     10                die("Plogger has already been installed!"); 
    1111        }; 
    1212}; 
  • branches/plogger-with-tags/admin/js/plogger.js

    r373 r402  
    8383         
    8484} 
     85 
     86function toggle(obj) { 
     87        var el = document.getElementById(obj); 
     88        if ( el.style.display != 'none' ) { 
     89                el.style.display = 'none'; 
     90        } 
     91        else { 
     92                el.style.display = ''; 
     93        } 
     94 
     95} 
  • branches/plogger-with-tags/admin/plog-admin-functions.php

    r401 r402  
    66 
    77function get_files($directory) { 
    8    // Try to open the directory 
    9    if($dir = opendir($directory)) { 
    10       // Create an array for all files found 
    11       $tmp = Array(); 
    12       // Add the files 
    13       while($file = readdir($dir)) { 
    14          // Make sure the file exists 
    15          if($file != "." && $file != ".." && $file[0] != '.') { 
    16             // If it's a directiry, list all files within it 
    17             if(is_dir($directory . "/" . $file)) { 
    18                $tmp2 = get_files($directory . "/" . $file); 
    19                if(is_array($tmp2)) { 
    20                   $tmp = array_merge($tmp, $tmp2); 
    21                } 
    22             } else if (is_readable($directory . "/" . $file)) { 
    23                $filename = basename(stripslashes($file)); 
    24                $pi = pathinfo($file); 
    25                if (is_allowed_extension($pi["extension"])) { 
    26                   array_push($tmp, $directory . "/" . $file); 
    27                } 
    28             } 
    29          } 
    30       } 
    31       // Finish off the function 
    32       closedir($dir); 
    33       return $tmp; 
     8        // Try to open the directory 
     9        if($dir = opendir($directory)) { 
     10        // Create an array for all files found 
     11        $tmp = Array(); 
     12 
     13        // Add the files 
     14        while($file = readdir($dir)) { 
     15                // Make sure the file exists 
     16                if($file != "." && $file != ".." && $file[0] != '.') { 
     17                        // If it's a directiry, list all files within it 
     18                        if(is_dir($directory . "/" . $file)) { 
     19                                $tmp2 = get_files($directory . "/" . $file); 
     20                                if(is_array($tmp2)) { 
     21                                        $tmp = array_merge($tmp, $tmp2); 
     22                                } 
     23                        } else if (is_readable($directory . "/" . $file)) { 
     24                                $filename = basename(stripslashes($file)); 
     25                                $pi = pathinfo($file); 
     26                                if (is_allowed_extension($pi["extension"])) { 
     27                                        array_push($tmp, $directory . "/" . $file); 
     28                                } 
     29                        } 
     30           } 
     31       } 
     32       // Finish off the function 
     33       closedir($dir); 
     34       return $tmp; 
    3435   } 
    3536} 
    3637 
    3738function add_picture($album_id,$tmpname,$filename,$caption,$desc) { 
    38    global $TABLE_PREFIX; 
    39    global $config; 
    40  
    41    $filename_parts = explode(".",strrev($filename),2); 
    42    $filename_base = strrev($filename_parts[1]); 
    43    $filename_ext = strrev($filename_parts[0]); 
    44  
    45    $result = array( 
    46       'output' => '', 
    47       'picture_id' => false, 
    48    ); 
    49  
    50    $i = 0; 
    51  
    52    $unique_filename_base = strtolower(sanitize_filename($filename_base)); 
    53  
    54    // now get the name of the collection 
    55  
    56    $sql = "SELECT c.path AS collection_path, c.id AS collection_id, 
    57            a.path AS album_path, a.id AS album_id 
    58            FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."collections c 
    59            WHERE c.id = a.parent_id AND a.id = '$album_id'"; 
    60  
    61    $sql_result = run_query($sql); 
    62    $albumdata = mysql_fetch_assoc($sql_result); 
    63  
    64    // this shouldn't happen in normal cases 
    65    if (empty($albumdata)) { 
    66       $result['errors'] .= 'No such album!'; 
    67       return $result; 
    68    } 
    69  
    70    $dest_album_name = SmartStripSlashes($albumdata["album_path"]); 
    71    $dest_collection_name = SmartStripSlashes($albumdata["collection_path"]); 
    72  
    73    $create_path = $dest_collection_name."/".$dest_album_name; 
    74  
    75    while (is_file('images/'.$create_path."/".$unique_filename_base . "." . $filename_ext)){ 
    76       $unique_filename_base = $filename_base . " (" . ++$i .")"; 
    77    } 
    78  
    79    $final_filename = $unique_filename_base . "." . $filename_ext; 
    80  
    81    // final fully qualified file name 
    82    $final_fqfn = $config["basedir"].'images/'.$create_path.'/'.$final_filename; 
    83  
    84    if (!makeDirs($config['basedir'].'images/'.$create_path, 0777)) { 
    85       $result['errors'] .= 'Could not create directory '.$create_path.'!'; 
    86       return $result; 
    87    }; 
    88  
    89    // cannot use move_uploaded_file here, because plog-import uses the same function and  
    90    // and doesn't deal with uploaded files 
    91    //if (!move_uploaded_file($tmpname,$final_fqfn)) { 
    92  
    93    if (is_uploaded_file($tmpname)) { 
    94       if (!move_uploaded_file($tmpname,$final_fqfn)) { 
    95          $result['errors'] .= 'Could not move uploaded file! ' . $tmpname .' to '.$final_fqfn; 
    96          return $result; 
    97       }  
    98    } 
    99    else 
    100    if (!rename($tmpname,$final_fqfn)) { 
    101       $result['errors'] .= 'Could not move file! ' . $tmpname .' to '.$final_fqfn; 
    102       return $result; 
    103    }; 
    104  
    105    @unlink($tmpname); 
    106    $res = chmod($final_fqfn, 0755); 
    107  
    108    // Get the EXIF data. 
     39        global $TABLE_PREFIX; 
     40        global $config; 
     41 
     42        $filename_parts = explode(".",strrev($filename),2); 
     43        $filename_base = strrev($filename_parts[1]); 
     44        $filename_ext = strrev($filename_parts[0]); 
     45 
     46        $result = array( 
     47                'output' => '', 
     48                'picture_id' => false, 
     49        ); 
     50 
     51        $i = 0; 
     52 
     53        $unique_filename_base = strtolower(sanitize_filename($filename_base)); 
     54 
     55        // now get the name of the collection 
     56 
     57        $sql = "SELECT c.path AS collection_path, c.id AS collection_id, 
     58                        a.path AS album_path, a.id AS album_id 
     59                        FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."collections c 
     60                        WHERE c.id = a.parent_id AND a.id = '$album_id'"; 
     61 
     62        $sql_result = run_query($sql); 
     63        $albumdata = mysql_fetch_assoc($sql_result); 
     64 
     65        // this shouldn't happen in normal cases 
     66        if (empty($albumdata)) { 
     67                $result['errors'] .= 'No such album!'; 
     68                return $result; 
     69        } 
     70 
     71        $dest_album_name = SmartStripSlashes($albumdata["album_path"]); 
     72        $dest_collection_name = SmartStripSlashes($albumdata["collection_path"]); 
     73 
     74        $create_path = $dest_collection_name."/".$dest_album_name; 
     75 
     76        while (is_file('images/'.$create_path."/".$unique_filename_base . "." . $filename_ext)){ 
     77                $unique_filename_base = $filename_base . " (" . ++$i .")"; 
     78        } 
     79 
     80        $final_filename = $unique_filename_base . "." . $filename_ext; 
     81 
     82        // final fully qualified file name 
     83        $final_fqfn = $config["basedir"].'images/'.$create_path.'/'.$final_filename; 
     84 
     85        if (!makeDirs($config['basedir'].'images/'.$create_path, 0777)) { 
     86                $result['errors'] .= 'Could not create directory '.$create_path.'!'; 
     87                return $result; 
     88        }; 
     89 
     90        // cannot use move_uploaded_file here, because plog-import uses the same function and  
     91        // and doesn't deal with uploaded files 
     92        //if (!move_uploaded_file($tmpname,$final_fqfn)) { 
     93 
     94        if (is_uploaded_file($tmpname)) { 
     95                if (!move_uploaded_file($tmpname,$final_fqfn)) { 
     96                        $result['errors'] .= 'Could not move uploaded file! ' . $tmpname .' to '.$final_fqfn; 
     97                        return $result; 
     98                }  
     99        } 
     100        else 
     101        if (!rename($tmpname,$final_fqfn)) { 
     102                $result['errors'] .= 'Could not move file! ' . $tmpname .' to '.$final_fqfn; 
     103                return $result; 
     104        }; 
     105 
     106        @unlink($tmpname); 
     107        $res = chmod($final_fqfn, 0755); 
     108 
     109        // Get the EXIF data. 
    109110   $exif_raw = read_exif_data_raw($final_fqfn,false); 
    110    $exif = array(); 
    111  
    112    $exif["date_taken"] = (isset($exif_raw["IFD0"]["DateTime"])) ? trim($exif_raw["IFD0"]["DateTime"]) : ''; 
    113    $exif["camera"] = (isset($exif_raw["IFD0"]["Make"]) && isset($exif_raw["IFD0"]["Model"])) ? trim($exif_raw["IFD0"]["Make"]) . " " . trim($exif_raw["IFD0"]["Model"]) : ''; 
    114    $exif["shutter_speed"] = (isset($exif_raw["SubIFD"]["ExposureTime"])) ? $exif_raw["SubIFD"]["ExposureTime"] : ''; 
    115    $exif["focal_length"] = (isset($exif_raw["SubIFD"]["FocalLength"])) ? $exif_raw["SubIFD"]["FocalLength"] : ''; 
    116    $exif["flash"] = (isset($exif_raw["SubIFD"]["Flash"])) ? $exif_raw["SubIFD"]["Flash"] : ''; 
    117    $exif["aperture"] = (isset($exif_raw["SubIFD"]["FNumber"])) ? $exif_raw["SubIFD"]["FNumber"] : ''; 
    118  
    119    $picture_path = $create_path . "/" . $final_filename; 
     111        $exif = array(); 
     112 
     113        $exif["date_taken"] = (isset($exif_raw["IFD0"]["DateTime"])) ? trim($exif_raw["IFD0"]["DateTime"]) : ''; 
     114        $exif["camera"] = (isset($exif_raw["IFD0"]["Make"]) && isset($exif_raw["IFD0"]["Model"])) ? trim($exif_raw["IFD0"]["Make"]) . " " . trim($exif_raw["IFD0"]["Model"]) : ''; 
     115        $exif["shutter_speed"] = (isset($exif_raw["SubIFD"]["ExposureTime"])) ? $exif_raw["SubIFD"]["ExposureTime"] : ''; 
     116        $exif["focal_length"] = (isset($exif_raw["SubIFD"]["FocalLength"])) ? $exif_raw["SubIFD"]["FocalLength"] : ''; 
     117        $exif["flash"] = (isset($exif_raw["SubIFD"]["Flash"])) ? $exif_raw["SubIFD"]["Flash"] : ''; 
     118        $exif["aperture"] = (isset($exif_raw["SubIFD"]["FNumber"])) ? $exif_raw["SubIFD"]["FNumber"] : ''; 
     119 
     120        $picture_path = $create_path . "/" . $final_filename; 
    120121 
    121122   $result = insert_picture($albumdata['collection_id'],$albumdata['album_id'],$picture_path,$exif,$caption,$desc,$filename); 
     
    136137   global $TABLE_PREFIX; 
    137138 
    138    $query = "INSERT INTO `".$TABLE_PREFIX."pictures` 
    139       (`parent_collection`, 
    140       `parent_album`, 
    141       `path`, 
    142       `date_modified`, 
    143       `date_submitted`, 
    144       `allow_comments`, 
    145       `EXIF_date_taken`, 
    146       `EXIF_camera`, 
    147       `EXIF_shutterspeed`, 
    148       `EXIF_focallength`, 
    149       `EXIF_flash`, 
    150       `EXIF_aperture`, 
    151       `caption`, 
    152       `description`) 
    153       VALUES 
     139        $query = "INSERT INTO `".$TABLE_PREFIX."pictures` 
     140                (`parent_collection`, 
     141                `parent_album`, 
     142                `path`, 
     143                `date_modified`, 
     144                `date_submitted`, 
     145                `allow_comments`, 
     146                `EXIF_date_taken`, 
     147                `EXIF_camera`, 
     148                `EXIF_shutterspeed`, 
     149                `EXIF_focallength`, 
     150                `EXIF_flash`, 
     151                `EXIF_aperture`, 
     152                `caption`, 
     153                `description`) 
     154                VALUES 
    154155          ('".$collection_id."', 
    155156           '".$album_id."','".mysql_escape_string($picture_path)."', 
     
    165166           '".mysql_escape_string($caption)."', 
    166167           '".mysql_escape_string($desc)."')"; 
    167  
    168    $sql_result = run_query($query); 
    169  
    170    $result['output'] .= 'Your photo ('.$filename.') was uploaded successfully.'; 
    171    $result['picture_id'] = mysql_insert_id(); 
    172    return $result; 
    173 } 
     168            
     169        $sql_result = run_query($query); 
     170 
     171        $result['output'] .= 'Your photo ('.$filename.') was uploaded successfully.'; 
     172        $result['picture_id'] = mysql_insert_id(); 
     173         
     174        // let's generate the thumbnail and the large thumbnail right away. 
     175        // this way, the user won't see any latency from the thumbnail generation 
     176        // when viewing the gallery for the first time 
     177        // this also helps with the image pre-loading problem introduced 
     178        // by a javascript slideshow. 
     179         
     180        $thumbpath = generate_thumb($picture_path, $result['picture_id'],THUMB_SMALL); 
     181        #$thumbpath = generate_thumb($picture_path, $result['picture_id'],THUMB_LARGE); 
     182         
     183        return $result; 
     184}; 
    174185 
    175186function update_picture($id,$caption,$allow_comments,$description) { 
    176    global $TABLE_PREFIX; 
    177    $id = intval($id); 
    178    $caption = mysql_real_escape_string($caption); 
    179    $description = mysql_real_escape_string($description); 
    180    $allow_comments = intval($allow_comments); 
    181    $query = "UPDATE ".$TABLE_PREFIX."pictures SET 
    182          caption = '$caption', 
    183          description = '$description', 
    184          allow_comments = '$allow_comments' 
    185       WHERE id='$id'"; 
    186    $result = mysql_query($query); 
    187    if ($result)  
    188       return array('output' => 'You have successfully modified the selected picture.'); 
    189    else 
    190       return array('errors' => mysql_error()); 
     187        global $TABLE_PREFIX; 
     188        $id = intval($id); 
     189        $caption = mysql_real_escape_string($caption); 
     190        $description = mysql_real_escape_string($description); 
     191        $allow_comments = intval($allow_comments); 
     192        $query = "UPDATE ".$TABLE_PREFIX."pictures SET 
     193                        caption = '$caption', 
     194                        description = '$description', 
     195                        allow_comments = '$allow_comments' 
     196                WHERE id='$id'"; 
     197        $result = mysql_query($query); 
     198        if ($result)  
     199                return array('output' => 'You have successfully modified the selected picture.'); 
     200        else 
     201                return array('errors' => mysql_error()); 
     202} 
     203 
     204function update_picture_description($id, $description) { 
     205        global $TABLE_PREFIX; 
     206        $id = intval($id); 
     207        $description = mysql_real_escape_string($description); 
     208 
     209        $query = "UPDATE ".$TABLE_PREFIX."pictures SET 
     210                        description = '$description' 
     211                WHERE id='$id'"; 
     212        $result = mysql_query($query); 
     213        if ($result)  
     214                return array('output' => 'You have successfully modified the selected picture.'); 
     215        else 
     216                return array('errors' => mysql_error()); 
     217} 
     218 
     219function update_picture_caption($id, $caption) { 
     220        global $TABLE_PREFIX; 
     221        $id = intval($id); 
     222        $caption = mysql_real_escape_string($caption); 
     223 
     224        $query = "UPDATE ".$TABLE_PREFIX."pictures SET 
     225                        caption = '$caption' 
     226                WHERE id='$id'"; 
     227        $result = mysql_query($query); 
     228        if ($result)  
     229                return array('output' => 'You have successfully modified the selected picture.'); 
     230        else 
     231                return array('errors' => mysql_error()); 
    191232} 
    192233 
    193234function move_picture($pic_id,$to_album) { 
    194    global $TABLE_PREFIX; 
    195    global $config; 
    196    // we need the parent_id from the album we're changing to 
    197    $to_album = intval($to_album); 
    198    $pic_id = intval($pic_id); 
    199  
    200    $query = "SELECT * FROM ".$TABLE_PREFIX."albums WHERE `id` = '$to_album'"; 
    201    $result = run_query($query); 
    202    $row = mysql_fetch_assoc($result); 
    203  
    204    if (!is_array($row)) { 
    205       return array('errors' => 'There is no album with id ' . $to_album); 
    206    }; 
    207  
    208    $new_collection = $row['parent_id']; 
    209  
    210    // move picture to new location 
    211    // we need to query to get collection names and album names to find new directory path 
    212  
    213    $picture = get_picture_by_id($pic_id); 
    214    $album = get_album_by_id($to_album); 
    215  
    216    $filename = SmartStripSlashes(basename($picture['path'])); 
    217    $directory = SmartStripSlashes($album['collection_path'])."/".SmartStripSlashes($album['album_path'])."/"; 
    218    $new_path = $directory.$filename; 
    219  
    220    if (!rename($config['basedir']."images/".SmartStripSlashes($picture['path']), $config['basedir']."images/".$new_path)) { 
    221       return array('errors' => "Error moving file! ($picture[path] to $new_path)"); 
    222    }; 
    223  
    224    $new_path = mysql_real_escape_string($new_path); 
    225  
    226    // update database 
    227    $sql = "UPDATE ".$TABLE_PREFIX."pictures SET 
    228          path = '$new_path', 
    229          parent_album = '$to_album', 
    230          parent_collection = '$new_collection' 
    231       WHERE id = '$pic_id'"; 
    232    if (!mysql_query($sql)) { 
    233       return array('errors' => mysql_error()); 
    234    }; 
    235    return array('output' => 'Success'); 
    236 } 
    237  
     235        global $TABLE_PREFIX; 
     236        global $config; 
     237        // we need the parent_id from the album we're changing to 
     238        $to_album = intval($to_album); 
     239        $pic_id = intval($pic_id); 
     240 
     241        $query = "SELECT * FROM ".$TABLE_PREFIX."albums WHERE `id` = '$to_album'"; 
     242        $result = run_query($query); 
     243        $row = mysql_fetch_assoc($result); 
     244 
     245        if (!is_array($row)) { 
     246                return array('errors' => 'There is no album with id ' . $to_album); 
     247        }; 
     248                 
     249        $new_collection = $row['parent_id']; 
     250         
     251        // move picture to new location 
     252        // we need to query to get collection names and album names to find new directory path 
     253 
     254        $picture = get_picture_by_id($pic_id); 
     255        $album = get_album_by_id($to_album); 
     256 
     257        $filename = SmartStripSlashes(basename($picture['path'])); 
     258        $directory = SmartStripSlashes($album['collection_path'])."/".SmartStripSlashes($album['album_path'])."/"; 
     259        $new_path = $directory.$filename; 
     260 
     261        if (!rename($config['basedir']."images/".SmartStripSlashes($picture['path']), $config['basedir']."images/".$new_path)) { 
     262                return array('errors' => "Error moving file! ($picture[path] to $new_path)"); 
     263        }; 
     264 
     265        $new_path = mysql_real_escape_string($new_path); 
     266         
     267        // update database 
     268        $sql = "UPDATE ".$TABLE_PREFIX."pictures SET 
     269                        path = '$new_path', 
     270                        parent_album = '$to_album', 
     271                        parent_collection = '$new_collection' 
     272                WHERE id = '$pic_id'"; 
     273        if (!mysql_query($sql)) { 
     274                return array('errors' => mysql_error()); 
     275        }; 
     276        return array('output' => 'Success'); 
     277} 
     278                 
    238279function delete_picture($del_id) { 
    239    global $TABLE_PREFIX; 
    240    global $config; 
    241    $del_id = intval($del_id); 
    242    global $thumbnail_config; 
    243    $picture = get_picture_by_id($del_id); 
    244    if ($picture) { 
    245       $query = "DELETE FROM ".$TABLE_PREFIX."pictures WHERE `id`= '" . $picture['id'] . "'"; 
    246       run_query($query); 
    247  
    248       // delete all comments for the picture 
    249       $query = "DELETE FROM ".$TABLE_PREFIX."comments WHERE `parent_id`= '" . $picture['id'] . "'"; 
    250       run_query($query); 
    251  
    252       // make sure that the file is actually located inside our images directory 
    253       $full_path = realpath($config['basedir'] . 'images/' . $picture['path']); 
    254       // also check whether this image is in the correct folder 
    255       $relative_path = substr($full_path,0,strlen($config['basedir'])); 
    256       $basename = basename($picture['path']); 
    257       if ($relative_path == $config['basedir']) { 
    258          foreach($thumbnail_config as $tkey => $tval) { 
    259             $thumbpath = $config['basedir'].'thumbs/'.$tval['filename_prefix'].$picture['id'].'-'.$basename; 
    260             if (file_exists($thumbpath) && is_writable($thumbpath)) { 
    261                //print "deleting $thumbpath<br/>"; 
    262                @chmod($thumbpath, 0777); 
    263                unlink($thumbpath); 
    264             }; 
    265          }; 
    266          if (is_file($full_path)) { 
    267             // print "deleting $full_path<br/>"; 
    268             @chmod($full_path, 0777); 
    269  
    270             if (!unlink($full_path)) 
    271                 return array('errors' => 'Could not physically delete file from disk!'); 
    272          }; 
    273       } else { 
    274          return array('errors' => 'Picture has invalid path, ignoring delete request'); 
    275       }; 
    276    } else { 
    277       return array('errors' => 'There is no picture with id ' . $del_id); 
    278    }; 
     280        global $TABLE_PREFIX; 
     281        global $config; 
     282        $del_id = intval($del_id); 
     283        global $thumbnail_config; 
     284        $picture = get_picture_by_id($del_id); 
     285        if ($picture) { 
     286                 
     287                $query = "DELETE FROM ".$TABLE_PREFIX."pictures WHERE `id`= '" . $picture['id'] . "'"; 
     288                run_query($query); 
     289                 
     290                // delete all comments for the picture 
     291                $query = "DELETE FROM ".$TABLE_PREFIX."comments WHERE `parent_id`= '" . $picture['id'] . "'"; 
     292                run_query($query); 
     293 
     294                // make sure that the file is actually located inside our images directory 
     295                $full_path = realpath($config['basedir'] . 'images/' . $picture['path']); 
     296                // also check whether this image is in the correct folder 
     297                $relative_path = substr($full_path,0,strlen($config['basedir'])); 
     298                $basename = basename($picture['path']); 
     299                if ($relative_path == $config['basedir']) { 
     300                        foreach($thumbnail_config as $tkey => $tval) { 
     301                                $thumbpath = $config['basedir'].'thumbs/'.$tval['filename_prefix'].$picture['id'].'-'.$basename; 
     302                                if (file_exists($thumbpath) && is_writable($thumbpath)) { 
     303                                        //print "deleting $thumbpath<br/>"; 
     304                                        @chmod($thumbpath, 0777); 
     305                                        unlink($thumbpath); 
     306                                }; 
     307                        }; 
     308                        if (is_file($full_path)) { 
     309                                // print "deleting $full_path<br/>"; 
     310                                @chmod($full_path, 0777); 
     311                                 
     312                                if (!unlink($full_path)) 
     313                                         return array('errors' => 'Could not physically delete file from disk!'); 
     314                        }; 
     315                } else { 
     316                        return array('errors' => 'Picture has invalid path, ignoring delete request'); 
     317                }; 
     318        } else { 
     319                return array('errors' => 'There is no picture with id ' . $del_id); 
     320        }; 
    279321}; 
    280322 
    281323function add_collection($collection_name, $description) { 
    282    global $config; 
    283    global $TABLE_PREFIX; 
    284    $output = $errors = ""; 
    285    $id = 0; 
    286    $collection_name = trim(SmartStripSlashes($collection_name)); 
    287    if (empty($collection_name)) { 
    288       return array("errors" => "Please enter a valid name for the collection"); 
    289    }; 
    290  
    291    // do not allow collections with duplicate names, otherwise mod_rewritten links will start 
    292    // to behave weird. 
    293    $collection_exists = get_collection_by_name($collection_name); 
    294    if ($collection_exists) { 
    295       return array("errors" => 'New collection could not be created, because there already is one named `'.$collection_exists['name'].'`!'); 
    296    } 
    297  
    298    $collection_folder = strtolower(sanitize_filename($collection_name)); 
    299    // first try to create the directory, and only if that succeeds, then insert 
    300    // a new row into collections table, otherwise the collection will not be usable 
    301    // anyway 
    302    $create_path = $config["basedir"] . "/images/".$collection_folder; 
    303  
    304    // create directory 
    305    if (!makeDirs($create_path, 0777)) { 
    306       $errors .= "Could not create directory $create_path!</p>"; 
    307    } else { 
    308       $sql_name = mysql_real_escape_string($collection_name); 
    309       $description = mysql_real_escape_string($description); 
    310       $collection_folder = mysql_real_escape_string($collection_folder); 
    311       $query = "INSERT INTO ".$TABLE_PREFIX."collections  (`name`,`description`,`path`) VALUES ('$sql_name', '$description', '$collection_folder')"; 
    312       $result = run_query($query); 
    313       $id = mysql_insert_id(); 
    314  
    315       $output .= 'You have successfully created the collection <strong>'.$collection_name.'.</strong>';     
    316    }; 
    317  
    318    // caller can check the value of id, if it is zero, then collection creation failed 
    319    // errors and output are separate, because this way the caller can format the return value 
    320    // as it needs 
    321    $result = array( 
    322       "output" => $output, 
    323       "errors" => $errors, 
    324       "id" => $id, 
    325    ); 
    326    return $result; 
     324        global $config; 
     325        global $TABLE_PREFIX; 
     326        $output = $errors = ""; 
     327        $id = 0; 
     328        $collection_name = trim(SmartStripSlashes($collection_name)); 
     329        if (empty($collection_name)) { 
     330                return array("errors" => "Please enter a valid name for the collection"); 
     331        }; 
     332 
     333        // do not allow collections with duplicate names, otherwise mod_rewritten links will start 
     334        // to behave weird. 
     335        $collection_exists = get_collection_by_name($collection_name); 
     336        if ($collection_exists) { 
     337                return array("errors" => 'New collection could not be created, because there already is one named `'.$collection_exists['name'].'`!'); 
     338        } 
     339 
     340        $collection_folder = strtolower(sanitize_filename($collection_name)); 
     341        // first try to create the directory, and only if that succeeds, then insert 
     342        // a new row into collections table, otherwise the collection will not be usable 
     343        // anyway 
     344        $create_path = $config["basedir"] . "/images/".$collection_folder; 
     345 
     346        // create directory 
     347        if (!makeDirs($create_path, 0777)) { 
     348                $errors .= "Could not create directory $create_path!</p>"; 
     349        } else { 
     350                $sql_name = mysql_real_escape_string($collection_name); 
     351                $description = mysql_real_escape_string($description); 
     352                $collection_folder = mysql_real_escape_string($collection_folder); 
     353                $query = "INSERT INTO ".$TABLE_PREFIX."collections  (`name`,`description`,`path`) VALUES ('$sql_name', '$description', '$collection_folder')"; 
     354                $result = run_query($query); 
     355                $id = mysql_insert_id(); 
     356 
     357                $output .= 'You have successfully created the collection <strong>'.$collection_name.'.</strong>';     
     358        }; 
     359 
     360        // caller can check the value of id, if it is zero, then collection creation failed 
     361        // errors and output are separate, because this way the caller can format the return value 
     362        // as it needs 
     363        $result = array( 
     364                "output" => $output, 
     365                "errors" => $errors, 
     366                "id" => $id, 
     367        ); 
     368        return $result; 
    327369 
    328370} 
    329371 
    330372function update_collection($collection_id,$name,$description,$thumbnail_id = 0) { 
    331    global $TABLE_PREFIX; 
    332    global $config; 
    333  
    334    $errors = $output = ""; 
    335  
    336    $name = trim(SmartStripSlashes($name)); 
    337    if (empty($name)) { 
    338       return array("errors" => "Please enter a valid name for the collection"); 
    339    }; 
    340  
    341    $target_name = strtolower(sanitize_filename($name)); 
    342  
    343    $errors = $output = ""; 
    344  
    345    $collection_id = intval($collection_id); 
    346    $thumbnail_id = intval($thumbnail_id); 
    347  
    348    $name = mysql_real_escape_string($name); 
    349    $description = mysql_real_escape_string($description); 
    350  
    351    // rename the directory 
    352    // first, get the collection name of our source collection 
    353    $sql = "SELECT c.path as collection_path,name 
    354          FROM ".$TABLE_PREFIX."collections c 
    355          WHERE c.id = '$collection_id'"; 
    356  
    357    $result = run_query($sql); 
    358    $row = mysql_fetch_assoc($result); 
    359  
    360    // do not allow collections with duplicate names, otherwise mod_rewritten links will start 
    361    // to behave weird. 
    362    $collection_exists = get_collection_by_name($name); 
    363    if ($row["name"] != $name && $collection_exists) { 
    364       return array("errors" => 'Collection `' . $row['name'] . '` could not be renamed to `'.$name.'`, because there is another collection with that name'); 
    365    } 
    366  
    367    $source_collection_name = SmartStripSlashes($row["collection_path"]); 
    368    $source_path = $config["basedir"] . "images/".$source_collection_name; 
    369    $target_path = $config["basedir"] . "images/".$target_name; 
    370  
    371    // perform the rename on the directory 
    372    if (!rename($source_path, $target_path)) { 
    373       return array("errors" => "Error renaming directory! ($source_path to $target_path)"); 
    374    }; 
    375  
    376    $target_name = mysql_real_escape_string($target_name); 
    377  
    378    $query = "UPDATE ".$TABLE_PREFIX."collections SET name = '$name', path = '$target_name', description = '$description', thumbnail_id = '$thumbnail_id' WHERE id='$collection_id'"; 
    379    $result = mysql_query($query); 
    380    if (!$result) { 
    381       return array("errors" => mysql_error()); 
    382    }; 
    383  
    384  
    385    $output = 'You have successfully modified the selected collection.'; 
    386  
    387    // XXX: Update the path only if a collection was actually renamed 
    388  
    389    // update the path field for all pictures within that collection 
    390    // now we need to update the database paths of all pictures within source album 
    391    $sql = "SELECT p.id AS id,p.path AS path, c.name AS collection_name, a.path AS album_path 
    392       FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."pictures p, ".$TABLE_PREFIX."collections c 
    393       WHERE p.parent_album = a.id AND p.parent_collection = c.id AND p.parent_collection = '$collection_id'"; 
    394  
    395    $result = run_query($sql); 
    396  
    397    while($row = mysql_fetch_assoc($result)) { 
    398  
    399       $filename = basename(SmartStripSlashes($row['path'])); 
    400       $album_path = $row['album_path']; 
    401  
    402       $new_path = mysql_escape_string($target_name."/".$album_path."/".$filename); 
    403  
    404       // update database 
    405       $sql = "UPDATE ".$TABLE_PREFIX."pictures SET path = '$new_path' WHERE id = '$row[id]'"; 
    406       mysql_query($sql) or ($output .= mysql_error()); 
    407    } 
    408  
    409    return array( 
    410       "errors" => $errors, 
    411       "output" => $output, 
    412    ); 
     373        global $TABLE_PREFIX; 
     374        global $config; 
     375 
     376        $errors = $output = ""; 
     377         
     378        $name = trim(SmartStripSlashes($name)); 
     379        if (empty($name)) { 
     380                return array("errors" => "Please enter a valid name for the collection"); 
     381        }; 
     382 
     383        $target_name = strtolower(sanitize_filename($name)); 
     384         
     385        $errors = $output = ""; 
     386 
     387        $collection_id = intval($collection_id); 
     388        $thumbnail_id = intval($thumbnail_id); 
     389 
     390        $name = mysql_real_escape_string($name); 
     391        $description = mysql_real_escape_string($description); 
     392 
     393        // rename the directory 
     394        // first, get the collection name of our source collection 
     395        $sql = "SELECT c.path as collection_path,name 
     396                        FROM ".$TABLE_PREFIX."collections c 
     397                        WHERE c.id = '$collection_id'"; 
     398 
     399        $result = run_query($sql); 
     400        $row = mysql_fetch_assoc($result); 
     401         
     402        // do not allow collections with duplicate names, otherwise mod_rewritten links will start 
     403        // to behave weird. 
     404        $collection_exists = get_collection_by_name($name); 
     405        if ($row["name"] != $name && $collection_exists) { 
     406                return array("errors" => 'Collection `' . $row['name'] . '` could not be renamed to `'.$name.'`, because there is another collection with that name'); 
     407        } 
     408 
     409        $source_collection_name = SmartStripSlashes($row["collection_path"]); 
     410        $source_path = $config["basedir"] . "images/".$source_collection_name; 
     411        $target_path = $config["basedir"] . "images/".$target_name; 
     412         
     413        // perform the rename on the directory 
     414        if (!rename($source_path, $target_path)) { 
     415                return array("errors" => "Error renaming directory! ($source_path to $target_path)"); 
     416        }; 
     417 
     418        $target_name = mysql_real_escape_string($target_name); 
     419 
     420        $query = "UPDATE ".$TABLE_PREFIX."collections SET name = '$name', path = '$target_name', description = '$description', thumbnail_id = '$thumbnail_id' WHERE id='$collection_id'"; 
     421        $result = mysql_query($query); 
     422        if (!$result) { 
     423                return array("errors" => mysql_error()); 
     424        }; 
     425 
     426 
     427        $output = 'You have successfully modified the selected collection.'; 
     428 
     429        // XXX: Update the path only if a collection was actually renamed 
     430 
     431        // update the path field for all pictures within that collection 
     432        // now we need to update the database paths of all pictures within source album 
     433        $sql = "SELECT p.id AS id,p.path AS path, c.name AS collection_name, a.path AS album_path 
     434                FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."pictures p, ".$TABLE_PREFIX."collections c 
     435                WHERE p.parent_album = a.id AND p.parent_collection = c.id AND p.parent_collection = '$collection_id'"; 
     436 
     437        $result = run_query($sql); 
     438 
     439        while($row = mysql_fetch_assoc($result)) { 
     440 
     441                $filename = basename(SmartStripSlashes($row['path'])); 
     442                $album_path = $row['album_path']; 
     443 
     444                $new_path = mysql_escape_string($target_name."/".$album_path."/".$filename); 
     445 
     446                // update database 
     447                $sql = "UPDATE ".$TABLE_PREFIX."pictures SET path = '$new_path' WHERE id = '$row[id]'"; 
     448                mysql_query($sql) or ($output .= mysql_error()); 
     449        } 
     450 
     451        return array( 
     452                "errors" => $errors, 
     453                "output" => $output, 
     454        ); 
     455} 
     456 
     457function update_collection_description($collection_id, $description) { 
     458        global $TABLE_PREFIX; 
     459        global $config; 
     460 
     461        $errors = $output = ""; 
     462         
     463        $collection_id = intval($collection_id); 
     464        $description = mysql_real_escape_string($description); 
     465 
     466        $query = "UPDATE ".$TABLE_PREFIX."collections SET description = '$description' WHERE id='$collection_id'"; 
     467         
     468        $result = mysql_query($query); 
     469        if (!$result) { 
     470                return array("errors" => mysql_error()); 
     471        }; 
     472 
     473        $output = 'You have successfully modified the selected collection.'; 
     474 
     475        return array( 
     476                "errors" => $errors, 
     477                "output" => $output, 
     478        ); 
    413479} 
    414480 
    415481function delete_collection($del_id) { 
    416    global $TABLE_PREFIX; 
    417    global $config; 
    418    $sql = "SELECT c.name AS collection_name, c.path AS collection_path, c.id AS collection_id 
    419       FROM ".$TABLE_PREFIX."collections c 
    420       WHERE c.id = '$del_id'"; 
    421  
    422    $result = run_query($sql); 
    423    $collection = mysql_fetch_assoc($result); 
    424  
    425    if (!$collection) { 
    426       return array('errors' => 'No such collection'); 
    427    }; 
    428  
    429    // first delete all albums registered with this album 
    430    $sql = 'SELECT * FROM '.$TABLE_PREFIX.'albums WHERE parent_id = ' . $collection['collection_id']; 
    431    $result = run_query($sql); 
    432    while ($row = mysql_fetch_assoc($result)) { 
    433       delete_album($row['id']); 
    434    }; 
    435  
    436    // XXX: un-register collection 
    437    $query = "DELETE FROM ".$TABLE_PREFIX."collections WHERE `id`= '" . $collection['collection_id'] . "'"; 
    438    run_query($query); 
    439  
    440    // finally try to delete the directory itself. It will succeed, if there are no files left inside it .. 
    441    // if there are then .. how did they get there? Probably not through plogger and in this case do we  
    442    // really want to delete those? 
    443    $source_collection_name = $collection["collection_path"]; 
    444  
    445    $collection_directory = realpath($config['basedir'] . 'images/'.$source_collection_name); 
    446    $relative_path = substr($collection_directory,0,strlen($config['basedir'])); 
    447    $collection_path = explode('/',substr($collection_directory,strlen($config['basedir']))); 
    448    // it needs to have 2 parts - images and collection name, if it doesn't, then there is something 
    449    // wrong with collection name and it's probably not safe to try to delete the directory 
    450    if ($relative_path == $config['basedir'] && sizeof($collection_path) == 2) { 
    451       @chmod($collection_directory,0777); 
    452       $delete_result = rmdir($collection_directory); 
    453       if (!$delete_result) { 
    454          return array('errors' => 'Collection directory still contains files after all albums have been deleted.'); 
    455       }; 
    456    } else { 
    457       return array('errors' => 'Collection has invalid path, not deleting directory'); 
    458    }; 
    459    return array(); 
     482        global $TABLE_PREFIX; 
     483        global $config; 
     484        $sql = "SELECT c.name AS collection_name, c.path AS collection_path, c.id AS collection_id 
     485                FROM ".$TABLE_PREFIX."collections c 
     486                WHERE c.id = '$del_id'"; 
     487 
     488        $result = run_query($sql); 
     489        $collection = mysql_fetch_assoc($result); 
     490 
     491        if (!$collection) { 
     492                return array('errors' => 'No such collection'); 
     493        }; 
     494 
     495        // first delete all albums registered with this album 
     496        $sql = 'SELECT * FROM '.$TABLE_PREFIX.'albums WHERE parent_id = ' . $collection['collection_id']; 
     497        $result = run_query($sql); 
     498        while ($row = mysql_fetch_assoc($result)) { 
     499                delete_album($row['id']); 
     500        }; 
     501                         
     502        // XXX: un-register collection 
     503        $query = "DELETE FROM ".$TABLE_PREFIX."collections WHERE `id`= '" . $collection['collection_id'] . "'"; 
     504        run_query($query); 
     505 
     506        // finally try to delete the directory itself. It will succeed, if there are no files left inside it .. 
     507        // if there are then .. how did they get there? Probably not through plogger and in this case do we  
     508        // really want to delete those? 
     509        $source_collection_name = $collection["collection_path"]; 
     510 
     511        $collection_directory = realpath($config['basedir'] . 'images/'.$source_collection_name); 
     512        $relative_path = substr($collection_directory,0,strlen($config['basedir'])); 
     513        $collection_path = explode('/',substr($collection_directory,strlen($config['basedir']))); 
     514        // it needs to have 2 parts - images and collection name, if it doesn't, then there is something 
     515        // wrong with collection name and it's probably not safe to try to delete the directory 
     516        if ($relative_path == $config['basedir'] && sizeof($collection_path) == 2) { 
     517                @chmod($collection_directory,0777); 
     518                $delete_result = rmdir($collection_directory); 
     519                if (!$delete_result) { 
     520                        return array('errors' => 'Collection directory still contains files after all albums have been deleted.'); 
     521                }; 
     522        } else { 
     523                return array('errors' => 'Collection has invalid path, not deleting directory'); 
     524        }; 
     525        return array(); 
    460526} 
    461527 
    462528function add_album($album_name, $description, $pid) { 
    463    global $config; 
    464    global $TABLE_PREFIX; 
    465    $output = $errors = ""; 
    466    $id = 0; 
    467    $album_name = trim(SmartStripSlashes($album_name)); 
    468    if (empty($album_name)) { 
    469       return array("errors" => "Please enter a valid name for the album"); 
    470    }; 
    471    // get the parent collection name 
    472    $query = "SELECT c.path as collection_path FROM ". $TABLE_PREFIX."collections c WHERE id = '$pid'"; 
    473  
    474    $result = run_query($query); 
    475    $row = mysql_fetch_assoc($result); 
    476  
    477    // this shouldn't happen 
    478    if (empty($row)) { 
    479       return array("errors" => "No such collection"); 
    480    }; 
    481  
    482    $album_folder = strtolower(sanitize_filename($album_name)); 
    483  
    484    // first try to create the directory to hold the images, if that fails, then the album 
    485    // will be unusable anyway 
    486    $create_path = $config["basedir"] . "/images/".$row["collection_path"]."/".$album_folder; 
    487  
    488    if (!makeDirs($create_path, 0777)) { 
    489       $errors .= "Could not create directory $path!"; 
    490    } else { 
    491       $sql_name = mysql_real_escape_string($album_name); 
    492       $description = mysql_real_escape_string($description); 
    493       $album_folder = mysql_real_escape_string($album_folder); 
    494       $query = "INSERT INTO ".$TABLE_PREFIX."albums (`name`,`description`,`parent_id`,`path`) VALUES ('$sql_name', '$description', '$pid','$album_folder')"; 
    495       $result = run_query($query); 
    496       $id = mysql_insert_id(); 
    497  
    498       $output .= 'You have successfully created the album <strong>'.$album_name.'.</strong>'; 
    499    }; 
    500    // caller can check the value of id, if it is zero, then album creation failed 
    501    // errors and output are separate, because this way the caller can format the return value 
    502    // as it needs 
    503    $result = array( 
    504       "output" => $output, 
    505       "errors" => $errors, 
    506       "id" => $id, 
    507    ); 
    508    return $result; 
     529        global $config; 
     530        global $TABLE_PREFIX; 
     531        $output = $errors = ""; 
     532        $id = 0; 
     533        $album_name = trim(SmartStripSlashes($album_name)); 
     534        if (empty($album_name)) { 
     535                return array("errors" => "Please enter a valid name for the album"); 
     536        }; 
     537        // get the parent collection name 
     538        $query = "SELECT c.path as collection_path FROM ". $TABLE_PREFIX."collections c WHERE id = '$pid'"; 
     539 
     540        $result = run_query($query); 
     541        $row = mysql_fetch_assoc($result); 
     542 
     543        // this shouldn't happen 
     544        if (empty($row)) { 
     545                return array("errors" => "No such collection"); 
     546        }; 
     547 
     548        $album_folder = strtolower(sanitize_filename($album_name)); 
     549 
     550        // first try to create the directory to hold the images, if that fails, then the album 
     551        // will be unusable anyway 
     552        $create_path = $config["basedir"] . "/images/".$row["collection_path"]."/".$album_folder; 
     553 
     554        if (!makeDirs($create_path, 0777)) { 
     555                $errors .= "Could not create directory $path!"; 
     556        } else { 
     557                $sql_name = mysql_real_escape_string($album_name); 
     558                $description = mysql_real_escape_string($description); 
     559                $album_folder = mysql_real_escape_string($album_folder); 
     560                $query = "INSERT INTO ".$TABLE_PREFIX."albums (`name`,`description`,`parent_id`,`path`) VALUES ('$sql_name', '$description', '$pid','$album_folder')"; 
     561                $result = run_query($query); 
     562                $id = mysql_insert_id(); 
     563 
     564                $output .= 'You have successfully created the album <strong>'.$album_name.'.</strong>'; 
     565        }; 
     566        // caller can check the value of id, if it is zero, then album creation failed 
     567        // errors and output are separate, because this way the caller can format the return value 
     568        // as it needs 
     569        $result = array( 
     570                "output" => $output, 
     571                "errors" => $errors, 
     572                "id" => $id, 
     573        ); 
     574        return $result; 
    509575} 
    510576 
    511577function update_album($album_id,$name,$description,$thumbnail_id = 0) { 
    512    global $TABLE_PREFIX; 
    513    global $config; 
    514  
    515    $errors = $output = ""; 
    516  
    517    $target_name = strtolower(sanitize_filename($name)); 
    518  
    519    $album_id = intval($album_id); 
    520    $thumbnail_id = intval($thumbnail_id); 
    521    $name = mysql_real_escape_string(SmartStripSlashes($name)); 
    522    $description = mysql_real_escape_string(SmartStripSlashes($description)); 
    523  
    524     // first, get the album name and collection name of our source album 
    525    $sql = "SELECT c.path AS collection_path, a.path AS album_path 
    526          FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."collections c 
    527          WHERE c.id = a.parent_id AND a.id = '$album_id'"; 
    528  
    529    $result = run_query($sql); 
    530    $row = mysql_fetch_assoc($result); 
    531  
    532    $source_album_name = SmartStripSlashes($row["album_path"]); 
    533    $source_collection_name = SmartStripSlashes($row["collection_path"]);      
    534  
    535  
    536    $source_path = $config['basedir'] . "images/".$source_collection_name."/".$source_album_name; 
    537    $target_path = $config['basedir'] . "images/".$source_collection_name."/".$target_name; 
    538  
    539    // perform the rename on the directory 
    540    if (!rename($source_path, $target_path)) 
    541    { 
    542       return array( 
    543          "errors" => "Error renaming directory! ($source_path to $target_path)", 
    544       ); 
    545    }; 
    546  
    547    $target_name = mysql_real_escape_string($target_name); 
    548  
    549    // proceed only if rename succeeded 
    550    $query = "UPDATE ".$TABLE_PREFIX."albums SET 
    551          name = '$name', 
    552          description = '$description', 
    553          thumbnail_id = '$thumbnail_id', 
    554          path = '$target_name' 
    555        WHERE id='$album_id'"; 
    556  
    557    $result = mysql_query($query); 
    558    if (!$result) { 
    559       return array("errors" => mysql_error()); 
    560    }; 
    561  
    562    $output .= 'You have successfully modified the selected album.'; 
    563  
    564    // update the path field for all pictures within that album 
    565    $sql = "SELECT p.path AS path, p.id AS id,c.name AS collection_name, a.name AS album_name 
    566          FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."pictures p, ".$TABLE_PREFIX."collections c 
    567          WHERE p.parent_album = a.id AND p.parent_collection = c.id AND p.parent_album = '$album_id'"; 
    568  
    569    $result = run_query($sql); 
    570  
    571    while($row = mysql_fetch_assoc($result)) { 
    572  
    573       $filename = basename($row['path']); 
    574       $new_path = $source_collection_name."/".$target_name."/".$filename; 
    575  
    576       // update database 
    577       $sql = "UPDATE ".$TABLE_PREFIX."pictures SET path = '$new_path' WHERE id = '$row[id]'"; 
    578       mysql_query($sql) or ($errors .= mysql_error()); 
    579    } 
    580  
    581    return array( 
    582       "errors" => $errors, 
    583       "output" => $output, 
    584    ); 
     578        global $TABLE_PREFIX; 
     579        global $config; 
     580 
     581        $errors = $output = ""; 
     582 
     583        $target_name = strtolower(sanitize_filename($name)); 
     584 
     585        $album_id = intval($album_id); 
     586        $thumbnail_id = intval($thumbnail_id); 
     587        $name = mysql_real_escape_string(SmartStripSlashes($name)); 
     588        $description = mysql_real_escape_string(SmartStripSlashes($description)); 
     589         
     590         // first, get the album name and collection name of our source album 
     591        $sql = "SELECT c.path AS collection_path, a.path AS album_path 
     592                        FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."collections c 
     593                        WHERE c.id = a.parent_id AND a.id = '$album_id'"; 
     594 
     595        $result = run_query($sql); 
     596        $row = mysql_fetch_assoc($result); 
     597 
     598        $source_album_name = SmartStripSlashes($row["album_path"]); 
     599        $source_collection_name = SmartStripSlashes($row["collection_path"]);      
     600 
     601 
     602        $source_path = $config['basedir'] . "images/".$source_collection_name."/".$source_album_name; 
     603        $target_path = $config['basedir'] . "images/".$source_collection_name."/".$target_name; 
     604 
     605        // perform the rename on the directory 
     606        if (!rename($source_path, $target_path)) 
     607        { 
     608                return array( 
     609                        "errors" => "Error renaming directory! ($source_path to $target_path)", 
     610                ); 
     611        }; 
     612 
     613        $target_name = mysql_real_escape_string($target_name); 
     614 
     615        // proceed only if rename succeeded 
     616        $query = "UPDATE ".$TABLE_PREFIX."albums SET 
     617                        name = '$name', 
     618                        description = '$description', 
     619                        thumbnail_id = '$thumbnail_id', 
     620                        path = '$target_name' 
     621                 WHERE id='$album_id'"; 
     622 
     623        $result = mysql_query($query); 
     624        if (!$result) { 
     625                return array("errors" => mysql_error()); 
     626        }; 
     627 
     628        $output .= 'You have successfully modified the selected album.'; 
     629 
     630        // update the path field for all pictures within that album 
     631        $sql = "SELECT p.path AS path, p.id AS id,c.name AS collection_name, a.name AS album_name 
     632                        FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."pictures p, ".$TABLE_PREFIX."collections c 
     633                        WHERE p.parent_album = a.id AND p.parent_collection = c.id AND p.parent_album = '$album_id'"; 
     634 
     635        $result = run_query($sql); 
     636 
     637        while($row = mysql_fetch_assoc($result)) { 
     638 
     639                $filename = basename($row['path']); 
     640                $new_path = $source_collection_name."/".$target_name."/".$filename; 
     641 
     642                // update database 
     643                $sql = "UPDATE ".$TABLE_PREFIX."pictures SET path = '$new_path' WHERE id = '$row[id]'"; 
     644                mysql_query($sql) or ($errors .= mysql_error()); 
     645        } 
     646 
     647        return array( 
     648                "errors" => $errors, 
     649                "output" => $output, 
     650        ); 
     651} 
     652 
     653function update_album_description($album_id, $description) { 
     654        global $TABLE_PREFIX; 
     655        global $config; 
     656 
     657        $errors = $output = ""; 
     658 
     659        $album_id = intval($album_id); 
     660        $description = mysql_real_escape_string(SmartStripSlashes($description)); 
     661 
     662          
     663        // proceed only if rename succeeded 
     664        $query = "UPDATE ".$TABLE_PREFIX."albums SET 
     665                        description = '$description' 
     666                 WHERE id='$album_id'"; 
     667         
     668        $result = mysql_query($query); 
     669        if (!$result) { 
     670                return array("errors" => mysql_error()); 
     671        }; 
     672 
     673        $output .= 'You have successfully modified the selected album.'; 
     674 
     675        return array( 
     676                "errors" => $errors, 
     677                "output" => $output, 
     678        ); 
    585679} 
    586680 
    587681function move_album($album_id,$to_collection) { 
    588    global $TABLE_PREFIX; 
    589    global $config; 
    590  
    591    $res = array( 
    592       'errors' => '', 
    593       'output' => '', 
    594    ); 
    595  
    596    $album_id = intval($album_id); 
    597    $to_collection = intval($to_collection); 
    598  
    599    $sql = "SELECT c.path as collection_path, a.path as album_path 
    600          FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."collections c 
    601          WHERE c.id = a.parent_id AND a.id = '$album_id'"; 
    602  
    603    $result = run_query($sql); 
    604    $row = mysql_fetch_assoc($result); 
    605  
    606    $source_album_name = SmartStripSlashes($row["album_path"]); 
    607    $source_collection_name = SmartStripSlashes($row["collection_path"]); 
    608  
    609    // next, get the collection name of our destination collection 
    610    $sql = "SELECT c.path as collection_path 
    611          FROM ".$TABLE_PREFIX."collections c 
    612          WHERE c.id = '$to_collection'"; 
    613  
    614    $result = run_query($sql); 
    615    $row = mysql_fetch_assoc($result); 
    616  
    617    $target_collection_name = SmartStripSlashes($row["collection_path"]); 
    618    $source_path = $config['basedir']."images/".$source_collection_name."/".$source_album_name; 
    619    $target_path = $config['basedir']."images/".$target_collection_name."/".$source_album_name; 
    620  
    621    // attempt to make new album directory in target collection 
    622    @mkdir($target_path, 0775); 
    623  
    624    //if (!rename($source_path, $target_path)) 
    625    //  $output .= '<p class="errors">Could not rename directory!</p>'; 
    626  
    627    // now we need to update the database paths of all pictures within source album 
    628    $sql = "SELECT p.path as path, p.id as picture_id, c.name as collection_name, a.name as album_name 
    629       FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."pictures p, ".$TABLE_PREFIX."collections c 
    630       WHERE p.parent_album = a.id AND p.parent_collection = c.id AND p.parent_album = '$album_id'"; 
    631  
    632    $result = run_query($sql); 
    633  
    634    while($row = mysql_fetch_assoc($result)) { 
    635       $filename = basename($row['path']); 
    636  
    637       $old_path = $source_path."/".$filename; 
    638       $new_path = $target_path."/".$filename; 
    639  
    640       if (!rename($old_path, $new_path)) 
    641          $res['errors'] .=  "Error moving file! ($old_path to $new_path)"; 
    642  
    643       $path_insert = mysql_real_escape_string($target_collection_name."/".$source_album_name."/".$filename); 
    644  
    645       $sql = "UPDATE ".$TABLE_PREFIX."pictures SET 
    646             parent_collection = '$to_collection', 
    647             path = '$path_insert' 
    648          WHERE id = '$row[picture_id]'"; 
    649       mysql_query($sql) or ($res['errors'] .= mysql_error()); 
    650    } 
    651  
    652    // update the parent id of the moved album 
    653    $query = "UPDATE ".$TABLE_PREFIX."albums SET `parent_id` = '$to_collection' WHERE `id`='$album_id'"; 
    654    $result = run_query($query); 
    655  
    656    return $res; 
     682        global $TABLE_PREFIX; 
     683        global $config; 
     684 
     685        $res = array( 
     686                'errors' => '', 
     687                'output' => '', 
     688        ); 
     689 
     690        $album_id = intval($album_id); 
     691        $to_collection = intval($to_collection); 
     692 
     693        $sql = "SELECT c.path as collection_path, a.path as album_path 
     694                        FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."collections c 
     695                        WHERE c.id = a.parent_id AND a.id = '$album_id'"; 
     696 
     697        $result = run_query($sql); 
     698        $row = mysql_fetch_assoc($result); 
     699 
     700        $source_album_name = SmartStripSlashes($row["album_path"]); 
     701        $source_collection_name = SmartStripSlashes($row["collection_path"]); 
     702 
     703        // next, get the collection name of our destination collection 
     704        $sql = "SELECT c.path as collection_path 
     705                        FROM ".$TABLE_PREFIX."collections c 
     706                        WHERE c.id = '$to_collection'"; 
     707 
     708        $result = run_query($sql); 
     709        $row = mysql_fetch_assoc($result); 
     710 
     711        $target_collection_name = SmartStripSlashes($row["collection_path"]); 
     712        $source_path = $config['basedir']."images/".$source_collection_name."/".$source_album_name; 
     713        $target_path = $config['basedir']."images/".$target_collection_name."/".$source_album_name; 
     714 
     715        // attempt to make new album directory in target collection 
     716        @mkdir($target_path, 0775); 
     717 
     718        //if (!rename($source_path, $target_path)) 
     719        //  $output .= '<p class="errors">Could not rename directory!</p>'; 
     720 
     721        // now we need to update the database paths of all pictures within source album 
     722        $sql = "SELECT p.path as path, p.id as picture_id, c.name as collection_name, a.name as album_name 
     723                FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."pictures p, ".$TABLE_PREFIX."collections c 
     724                WHERE p.parent_album = a.id AND p.parent_collection = c.id AND p.parent_album = '$album_id'"; 
     725 
     726        $result = run_query($sql); 
     727 
     728        while($row = mysql_fetch_assoc($result)) { 
     729                $filename = basename($row['path']); 
     730 
     731                $old_path = $source_path."/".$filename; 
     732                $new_path = $target_path."/".$filename; 
     733 
     734                if (!rename($old_path, $new_path)) 
     735                        $res['errors'] .=  "Error moving file! ($old_path to $new_path)"; 
     736                 
     737                $path_insert = mysql_real_escape_string($target_collection_name."/".$source_album_name."/".$filename); 
     738 
     739                $sql = "UPDATE ".$TABLE_PREFIX."pictures SET 
     740                                parent_collection = '$to_collection', 
     741                                path = '$path_insert' 
     742                        WHERE id = '$row[picture_id]'"; 
     743                mysql_query($sql) or ($res['errors'] .= mysql_error()); 
     744        } 
     745 
     746        // update the parent id of the moved album 
     747        $query = "UPDATE ".$TABLE_PREFIX."albums SET `parent_id` = '$to_collection' WHERE `id`='$album_id'"; 
     748        $result = run_query($query); 
     749 
     750        return $res; 
    657751} 
    658752 
    659753function delete_album($del_id) { 
    660    global $TABLE_PREFIX; 
    661    global $config; 
    662    $sql = "SELECT c.name AS collection_name, a.name AS album_name, a.id AS album_id, c.path AS collection_path, a.path AS album_path 
    663       FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."collections c 
    664       WHERE c.id = a.parent_id AND a.id = '$del_id'"; 
    665  
    666    $result = run_query($sql); 
    667    $album = mysql_fetch_assoc($result); 
    668  
    669    if (!$album) { 
    670       return array('errors' => 'No such album'); 
    671    }; 
    672  
    673    // first delete all pictures registered with this album 
    674    $sql = 'SELECT * FROM '.$TABLE_PREFIX.'pictures WHERE parent_album = ' . $album['album_id']; 
    675    $result = run_query($sql); 
    676    while ($row = mysql_fetch_assoc($result)) { 
    677       delete_picture($row['id']); 
    678    }; 
    679  
    680    // XXX: un-register album 
    681    $query = "DELETE FROM ".$TABLE_PREFIX."albums WHERE `id`= '" . $album['album_id'] . "'"; 
    682    run_query($query); 
    683  
    684    // finally try to delete the directory itself. It will succeed, if there are no files left inside it .. 
    685    // if there are then .. how did they get there? Probably not through plogger and in this case do we  
    686    // really want to delete those? 
    687    $source_album_name = $album["album_path"]; 
    688    $source_collection_name = $album["collection_path"]; 
    689  
    690    $album_directory = realpath($config['basedir'] . 'images/'.$source_collection_name."/".$source_album_name); 
    691    $relative_path = substr($album_directory,0,strlen($config['basedir'])); 
    692    $album_path = explode('/',substr($album_directory,strlen($config['basedir']))); 
    693    // it needs to have 3 parts - images, collection name and album name, if it doesn't, then there is something 
    694    // wrong with either collectio or album name and it's probably not safe to try to delete the directory 
    695    if ($relative_path == $config['basedir'] && sizeof($album_path) == 3) { 
    696       @chmod($album_directory,0777); 
    697       $delete_result = rmdir($album_directory); 
    698       if (!$delete_result) { 
    699          return array('errors' => 'Album directory still contains files after all pictures have been deleted.'); 
    700       }; 
    701    } else { 
    702       return array('errors' => 'Album has invalid path, not deleting directory'); 
    703    }; 
    704    return array(); 
     754        global $TABLE_PREFIX; 
     755        global $config; 
     756        $sql = "SELECT c.name AS collection_name, a.name AS album_name, a.id AS album_id, c.path AS collection_path, a.path AS album_path 
     757                FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."collections c 
     758                WHERE c.id = a.parent_id AND a.id = '$del_id'"; 
     759 
     760        $result = run_query($sql); 
     761        $album = mysql_fetch_assoc($result); 
     762 
     763        if (!$album) { 
     764                return array('errors' => 'No such album'); 
     765        }; 
     766 
     767        // first delete all pictures registered with this album 
     768        $sql = 'SELECT * FROM '.$TABLE_PREFIX.'pictures WHERE parent_album = ' . $album['album_id']; 
     769        $result = run_query($sql); 
     770        while ($row = mysql_fetch_assoc($result)) { 
     771                delete_picture($row['id']); 
     772        }; 
     773                         
     774        // XXX: un-register album 
     775        $query = "DELETE FROM ".$TABLE_PREFIX."albums WHERE `id`= '" . $album['album_id'] . "'"; 
     776        run_query($query); 
     777 
     778        // finally try to delete the directory itself. It will succeed, if there are no files left inside it .. 
     779        // if there are then .. how did they get there? Probably not through plogger and in this case do we  
     780        // really want to delete those? 
     781        $source_album_name = $album["album_path"]; 
     782        $source_collection_name = $album["collection_path"]; 
     783 
     784        $album_directory = realpath($config['basedir'] . 'images/'.$source_collection_name."/".$source_album_name); 
     785        $relative_path = substr($album_directory,0,strlen($config['basedir'])); 
     786        $album_path = explode('/',substr($album_directory,strlen($config['basedir']))); 
     787        // it needs to have 3 parts - images, collection name and album name, if it doesn't, then there is something 
     788        // wrong with either collectio or album name and it's probably not safe to try to delete the directory 
     789        if ($relative_path == $config['basedir'] && sizeof($album_path) == 3) { 
     790                @chmod($album_directory,0777); 
     791                $delete_result = rmdir($album_directory); 
     792                if (!$delete_result) { 
     793                        return array('errors' => 'Album directory still contains files after all pictures have been deleted.'); 
     794                }; 
     795        } else { 
     796                return array('errors' => 'Album has invalid path, not deleting directory'); 
     797        }; 
     798        return array(); 
    705799} 
    706800 
     
    708802 
    709803function update_comment($id,$author,$email,$url,$comment) { 
    710    global $TABLE_PREFIX; 
    711    $id = intval($id); 
    712    $author = mysql_real_escape_string($author); 
    713    $email = mysql_real_escape_string($email); 
    714    $url = mysql_real_escape_string($url); 
    715    $comment = mysql_real_escape_string($comment); 
    716  
    717    $query = "UPDATE ".$TABLE_PREFIX."comments SET author = '$author', comment = '$comment', 
    718          url = '$url', email = '$email' WHERE id='$id'"; 
    719    $result = mysql_query($query); 
    720    if ($result) 
    721       return array('output' => 'You have successfully modified the selected comment.'); 
    722    else 
    723       return array('errors' => mysql_error()); 
     804        global $TABLE_PREFIX; 
     805        $id = intval($id); 
     806        $author = mysql_real_escape_string($author); 
     807        $email = mysql_real_escape_string($email); 
     808        $url = mysql_real_escape_string($url); 
     809        $comment = mysql_real_escape_string($comment); 
     810 
     811        $query = "UPDATE ".$TABLE_PREFIX."comments SET author = '$author', comment = '$comment', 
     812                        url = '$url', email = '$email' WHERE id='$id'"; 
     813        $result = mysql_query($query); 
     814        if ($result) 
     815                return array('output' => 'You have successfully modified the selected comment.'); 
     816        else 
     817                return array('errors' => mysql_error()); 
     818} 
     819 
     820function update_comment_author($id, $author) { 
     821        global $TABLE_PREFIX; 
     822        $id = intval($id); 
     823        $author = mysql_real_escape_string($author); 
     824 
     825        $query = "UPDATE ".$TABLE_PREFIX."comments SET author = '$author' WHERE id='$id'"; 
     826        $result = mysql_query($query); 
     827        if ($result) 
     828                return array('output' => 'You have successfully modified the selected comment.'); 
     829        else 
     830                return array('errors' => mysql_error()); 
     831} 
     832 
     833function update_comment_email($id, $email) { 
     834        global $TABLE_PREFIX; 
     835        $id = intval($id); 
     836        $email = mysql_real_escape_string($email); 
     837         
     838        $query = "UPDATE ".$TABLE_PREFIX."comments SET email = '$email' WHERE id='$id'"; 
     839        $result = mysql_query($query); 
     840        if ($result) 
     841                return array('output' => 'You have successfully modified the selected comment.'); 
     842        else 
     843                return array('errors' => mysql_error()); 
     844} 
     845 
     846function update_comment_url($id, $url) { 
     847        global $TABLE_PREFIX; 
     848        $id = intval($id); 
     849        $url = mysql_real_escape_string($url); 
     850         
     851        $query = "UPDATE ".$TABLE_PREFIX."comments SET url = '$url' WHERE id='$id'"; 
     852        $result = mysql_query($query); 
     853        if ($result) 
     854                return array('output' => 'You have successfully modified the selected comment.'); 
     855        else 
     856                return array('errors' => mysql_error()); 
     857} 
     858 
     859function update_comment_text($id, $comment) { 
     860        global $TABLE_PREFIX; 
     861        $id = intval($id); 
     862        $comment = mysql_real_escape_string($comment); 
     863 
     864        $query = "UPDATE ".$TABLE_PREFIX."comments SET comment = '$comment' WHERE id='$id'"; 
     865        $result = mysql_query($query); 
     866        if ($result) 
     867                return array('output' => 'You have successfully modified the selected comment.'); 
     868        else 
     869                return array('errors' => mysql_error()); 
    724870} 
    725871 
    726872function count_albums($parent_id = 0) { 
    727    global $TABLE_PREFIX; 
    728    if (!$parent_id) 
    729       $numquery = "SELECT COUNT(*) AS `num_albums` FROM `".$TABLE_PREFIX."albums`"; 
    730    else 
    731       $numquery = "SELECT COUNT(*) AS `num_albums` FROM `".$TABLE_PREFIX."albums` WHERE parent_id = '$parent_id'"; 
    732  
    733    $numresult = run_query($numquery); 
    734    $num_albums = mysql_result($numresult, 'num_albums'); 
    735    return $num_albums; 
     873        global $TABLE_PREFIX; 
     874        if (!$parent_id) 
     875                $numquery = "SELECT COUNT(*) AS `num_albums` FROM `".$TABLE_PREFIX."albums`"; 
     876        else 
     877                $numquery = "SELECT COUNT(*) AS `num_albums` FROM `".$TABLE_PREFIX."albums` WHERE parent_id = '$parent_id'"; 
     878                 
     879        $numresult = run_query($numquery); 
     880        $num_albums = mysql_result($numresult, 'num_albums'); 
     881        return $num_albums; 
    736882} 
    737883 
    738884function count_collections() { 
    739    global $TABLE_PREFIX; 
    740  
    741    $numquery = "SELECT COUNT(*) AS `num_collections` FROM `".$TABLE_PREFIX."collections`"; 
    742  
    743    $numresult = run_query($numquery); 
    744    $num_albums = mysql_result($numresult, 'num_collections'); 
    745    return $num_albums; 
     885        global $TABLE_PREFIX; 
     886         
     887        $numquery = "SELECT COUNT(*) AS `num_collections` FROM `".$TABLE_PREFIX."collections`"; 
     888                 
     889        $numresult = run_query($numquery); 
     890        $num_albums = mysql_result($numresult, 'num_collections'); 
     891        return $num_albums; 
    746892} 
    747893 
    748894function count_pictures($parent_id = 0) { 
    749    global $TABLE_PREFIX; 
    750    if (!$parent_id) 
    751       $numquery = "SELECT COUNT(*) AS `num_pics` FROM `".$TABLE_PREFIX."pictures`"; 
    752    else 
    753       $numquery = "SELECT COUNT(*) AS `num_pics` FROM `".$TABLE_PREFIX."pictures` WHERE parent_album = '$parent_id'"; 
    754  
    755    $numresult = run_query($numquery); 
    756    $num_pics = mysql_result($numresult, 'num_pics'); 
    757    return $num_pics; 
     895        global $TABLE_PREFIX; 
     896        if (!$parent_id) 
     897                $numquery = "SELECT COUNT(*) AS `num_pics` FROM `".$TABLE_PREFIX."pictures`"; 
     898        else 
     899                $numquery = "SELECT COUNT(*) AS `num_pics` FROM `".$TABLE_PREFIX."pictures` WHERE parent_album = '$parent_id'"; 
     900                 
     901        $numresult = run_query($numquery); 
     902        $num_pics = mysql_result($numresult, 'num_pics'); 
     903        return $num_pics; 
    758904} 
    759905 
    760906function count_comments($parent_id = 0) { 
    761    global $TABLE_PREFIX; 
    762    if (!$parent_id) 
    763       $numquery = "SELECT COUNT(*) AS `num_comments` FROM `".$TABLE_PREFIX."comments`"; 
    764    else 
    765       $numquery = "SELECT COUNT(*) AS `num_comments` FROM `".$TABLE_PREFIX."comments` WHERE parent_id = '$parent_id'"; 
    766  
    767    $numresult = run_query($numquery); 
    768    $num_comments = mysql_result($numresult, 'num_comments'); 
    769    return $num_comments; 
     907        global $TABLE_PREFIX; 
     908        if (!$parent_id) 
     909                $numquery = "SELECT COUNT(*) AS `num_comments` FROM `".$TABLE_PREFIX."comments`"; 
     910        else 
     911                $numquery = "SELECT COUNT(*) AS `num_comments` FROM `".$TABLE_PREFIX."comments` WHERE parent_id = '$parent_id'"; 
     912                 
     913        $numresult = run_query($numquery); 
     914        $num_comments = mysql_result($numresult, 'num_comments'); 
     915        return $num_comments; 
    770916} 
    771917 
    772918function edit_comment_form($comment_id) 
    773919{ 
    774    global $TABLE_PREFIX; 
    775    $output = ''; 
    776    $comment_id = intval($comment_id); 
    777    $sql = "SELECT * FROM ".$TABLE_PREFIX."comments c WHERE c.id = '$comment_id'"; 
    778    $result = run_query($sql); 
    779    $comment = mysql_fetch_assoc($result); 
    780    if (!is_array($comment)) 
    781    { 
    782       // XXX: return an error message instead 
    783       return false; 
    784    } 
    785    $output .= '<form class="edit" action="'.$_SERVER["PHP_SELF"].'" method="post"><table>'; 
    786                    $output .= '<tr><td>Author:<br/><input size="30" name="author" id="author" value="'.SmartStripSlashes($comment['author']).'"></td> 
     920        global $TABLE_PREFIX; 
     921        $output = ''; 
     922        $comment_id = intval($comment_id); 
     923        $sql = "SELECT * FROM ".$TABLE_PREFIX."comments c WHERE c.id = '$comment_id'"; 
     924        $result = run_query($sql); 
     925        $comment = mysql_fetch_assoc($result); 
     926        if (!is_array($comment)) 
     927        { 
     928                // XXX: return an error message instead 
     929                return false; 
     930        } 
     931        $output .= '<form class="edit" action="'.$_SERVER["PHP_SELF"].'" method="post"><table>'; 
     932                        $output .= '<tr><td>Author:<br/><input size="30" name="author" id="author" value="'.SmartStripSlashes($comment['author']).'"></td> 
    787933                                    <td>Email:<br/><input size="30" name="email" id="email" value="'.SmartStripSlashes($comment['email']).'"></td> 
    788934                                        <td>Website:<br/><input size="30" name="url" id="url" value="'.SmartStripSlashes($comment['url']).'"></td></tr> 
    789935                                        <tr><td colspan="3">Comment:<br/> <textarea cols="70" rows="4" name="comment" id="comment">'. 
    790936                                        SmartStripSlashes($comment['comment']).'</textarea></td></tr></table>'; 
    791  
     937                                         
    792938                $output .= '<input type="hidden" name="pid" value="'.$comment['id'].'"> 
    793                <input type="hidden" name="action" value="update-comment"> 
    794                <button class="submit" type="submit">Update</button>'; 
    795  
    796       if (isset($_REQUEST["level"])) 
    797       { 
    798          $output .= '<input type="hidden" name="level"  value="'.$_REQUEST['level'].'">'; 
    799       } 
    800  
    801       if (isset($_REQUEST["id"])) 
    802       { 
    803          $output .= '<input type="hidden" name="id"  value="'.$_REQUEST['id'].'">'; 
    804       } 
    805  
    806       $output .= '</form>'; 
    807       return $output; 
     939                                        <input type="hidden" name="action" value="update-comment"> 
     940                                        <button class="submit" type="submit">Update</button>'; 
     941         
     942                if (isset($_REQUEST["level"])) 
     943                { 
     944                        $output .= '<input type="hidden" name="level"  value="'.$_REQUEST['level'].'">'; 
     945                } 
     946                 
     947                if (isset($_REQUEST["id"])) 
     948                { 
     949                        $output .= '<input type="hidden" name="id"  value="'.$_REQUEST['id'].'">'; 
     950                } 
     951                 
     952                $output .= '</form>'; 
     953                return $output; 
    808954} 
    809955 
     
    816962//  
    817963function configure_htaccess_fullpic($allow = false) { 
    818    $cfg = ""; 
    819    $placeholder_start = "# BEGIN Plogger"; 
    820    $placeholder_end = "# END Plogger"; 
    821    $thisfile =  "/admin/" . basename(__FILE__); 
    822    $adm = strpos($_SERVER["PHP_SELF"],"/admin"); 
    823    $rewritebase = substr($_SERVER["PHP_SELF"],0,$adm); 
    824    if (!$allow) { 
    825       $cfg .= "\n"; 
    826       $cfg .= "deny from all"; 
    827    };    
    828    // read the file 
    829    global $config; 
    830    $fpath = $config["basedir"] . "images/.htaccess";  
    831    $htaccess_lines = (is_file($fpath)) ? @file($fpath) : array(); 
    832  
    833    $output = ""; 
    834    $configuration_placed = false; 
    835    $between_placeholders = false; 
    836    foreach($htaccess_lines as $line) { 
    837       $tline = trim($line); 
    838       if ($placeholder_start == $tline) { 
    839          $between_placeholders = true; 
    840          $output .= $line . $cfg; 
    841          $configuration_placed = true; 
    842          continue; 
    843       } 
    844       if ($placeholder_end == $tline) { 
    845          $between_placeholders = false; 
    846          $output .= $line; 
    847          continue; 
    848       } 
    849       if ($between_placeholders) continue; 
    850  
    851       $output .= $line; 
    852    }; 
    853  
    854    // no placeholders? append to the end 
    855    if (!$configuration_placed) { 
    856       $output .= $placeholder_start . "\n" . $cfg . $placeholder_end . "\n"; 
    857     }; 
    858  
    859    $fh = @fopen($fpath,"w"); 
    860    // write changes out if the file can be opened. 
    861    // XXX: perhaps plog-options.php should check whether settings can be written and warn the user if not? 
    862    $success = false; 
    863    if ($fh) { 
    864       $success = true; 
    865       fwrite($fh,$output); 
    866       fclose($fh); 
    867    }; 
    868    return $success; 
     964        $cfg = ""; 
     965        $placeholder_start = "# BEGIN Plogger"; 
     966        $placeholder_end = "# END Plogger"; 
     967        $thisfile =  "/admin/" . basename(__FILE__); 
     968        $adm = strpos($_SERVER["PHP_SELF"],"/admin"); 
     969        $rewritebase = substr($_SERVER["PHP_SELF"],0,$adm); 
     970        if (!$allow) { 
     971                $cfg .= "\n"; 
     972                $cfg .= "deny from all"; 
     973        };       
     974        // read the file 
     975        global $config; 
     976        $fpath = $config["basedir"] . "images/.htaccess";  
     977        $htaccess_lines = (is_file($fpath)) ? @file($fpath) : array(); 
     978 
     979        $output = ""; 
     980        $configuration_placed = false; 
     981        $between_placeholders = false; 
     982        foreach($htaccess_lines as $line) { 
     983                $tline = trim($line); 
     984                if ($placeholder_start == $tline) { 
     985                        $between_placeholders = true; 
     986                        $output .= $line . $cfg; 
     987                        $configuration_placed = true; 
     988                        continue; 
     989                } 
     990                if ($placeholder_end == $tline) { 
     991                        $between_placeholders = false; 
     992                        $output .= $line; 
     993                        continue; 
     994                } 
     995                if ($between_placeholders) continue; 
     996 
     997                $output .= $line; 
     998        }; 
     999 
     1000        // no placeholders? append to the end 
     1001        if (!$configuration_placed) { 
     1002                $output .= $placeholder_start . "\n" . $cfg . $placeholder_end . "\n"; 
     1003        }; 
     1004 
     1005        $fh = @fopen($fpath,"w"); 
     1006        // write changes out if the file can be opened. 
     1007        // XXX: perhaps plog-options.php should check whether settings can be written and warn the user if not? 
     1008        $success = false; 
     1009        if ($fh) { 
     1010                $success = true; 
     1011                fwrite($fh,$output); 
     1012                fclose($fh); 
     1013        }; 
     1014        return $success; 
    8691015} 
    8701016 
    8711017function configure_mod_rewrite($enable = false) { 
    872    $cfg = ""; 
    873    $placeholder_start = "# BEGIN Plogger"; 
    874    $placeholder_end = "# END Plogger"; 
    875    $thisfile =  "/admin/" . basename(__FILE__); 
    876    $adm = strpos($_SERVER["PHP_SELF"],"/admin"); 
    877    $rewritebase = substr($_SERVER["PHP_SELF"],0,$adm); 
    878    if ($enable) { 
    879       $cfg .= "\n"; 
    880       if (empty($rewritebase)) 
    881       { 
    882          $rewritebase = "/"; 
    883       }; 
    884       $cfg .= "<IfModule mod_rewrite.c>\n"; 
    885       $cfg .= "RewriteEngine on\n"; 
    886       $cfg .= "RewriteBase $rewritebase\n"; 
    887       $cfg .= "RewriteCond %{REQUEST_FILENAME} -d [OR]\n"; 
    888       $cfg .= "RewriteCond %{REQUEST_FILENAME} -f\n"; 
    889       $cfg .= "RewriteRule ^.*$ - [S=2]\n"; 
    890       $cfg .= "RewriteRule feed/$ plog-rss.php?path=%{REQUEST_URI} [L]\n"; 
    891       $cfg .= "RewriteRule ^.*$ index.php?path=%{REQUEST_URI} [L]\n"; 
    892       $cfg .= "</IfModule>\n"; 
    893    };    
    894    // read the file 
    895    global $config; 
    896    $fpath = $config["basedir"] . ".htaccess";  
    897    $htaccess_lines = @file($fpath); 
    898  
    899    $output = ""; 
    900    $configuration_placed = false; 
    901    $between_placeholders = false; 
    902    foreach($htaccess_lines as $line) { 
    903       $tline = trim($line); 
    904       if ($placeholder_start == $tline) { 
    905          $between_placeholders = true; 
    906          $output .= $line . $cfg; 
    907          $configuration_placed = true; 
    908          continue; 
    909       } 
    910       if ($placeholder_end == $tline) { 
    911          $between_placeholders = false; 
    912          $output .= $line; 
    913          continue; 
    914       } 
    915       if ($between_placeholders) continue; 
    916  
    917       $output .= $line; 
    918    }; 
    919  
    920    // no placeholders? append to the end 
    921    if (!$configuration_placed) { 
    922       $output .= $placeholder_start . "\n" . $cfg . $placeholder_end . "\n"; 
    923     }; 
    924  
    925    $fh = @fopen($fpath,"w"); 
    926    // write changes out if the file can be opened. 
    927    // XXX: perhaps plog-options.php should check whether settings can be written and warn the user if not? 
    928    $success = false; 
    929    if ($fh) { 
    930       $success = true; 
    931       fwrite($fh,$output); 
    932       fclose($fh); 
    933    }; 
    934    return $success; 
     1018        $cfg = ""; 
     1019        $placeholder_start = "# BEGIN Plogger"; 
     1020        $placeholder_end = "# END Plogger"; 
     1021        $thisfile =  "/admin/" . basename(__FILE__); 
     1022        $adm = strpos($_SERVER["PHP_SELF"],"/admin"); 
     1023        $rewritebase = substr($_SERVER["PHP_SELF"],0,$adm); 
     1024        if ($enable) { 
     1025                $cfg .= "\n"; 
     1026                if (empty($rewritebase)) 
     1027                { 
     1028                        $rewritebase = "/"; 
     1029                }; 
     1030                $cfg .= "<IfModule mod_rewrite.c>\n"; 
     1031                $cfg .= "RewriteEngine on\n"; 
     1032                $cfg .= "RewriteBase $rewritebase\n"; 
     1033                $cfg .= "RewriteCond %{REQUEST_FILENAME} -d [OR]\n"; 
     1034                $cfg .= "RewriteCond %{REQUEST_FILENAME} -f\n"; 
     1035                $cfg .= "RewriteRule ^.*$ - [S=2]\n"; 
     1036                $cfg .= "RewriteRule feed/$ plog-rss.php?path=%{REQUEST_URI} [L]\n"; 
     1037                $cfg .= "RewriteRule ^.*$ index.php?path=%{REQUEST_URI} [L]\n"; 
     1038                $cfg .= "</IfModule>\n"; 
     1039        };       
     1040        // read the file 
     1041        global $config; 
     1042        $fpath = $config["basedir"] . ".htaccess";  
     1043        $htaccess_lines = @file($fpath); 
     1044 
     1045        $output = ""; 
     1046        $configuration_placed = false; 
     1047        $between_placeholders = false; 
     1048        foreach($htaccess_lines as $line) { 
     1049                $tline = trim($line); 
     1050                if ($placeholder_start == $tline) { 
     1051                        $between_placeholders = true; 
     1052                        $output .= $line . $cfg; 
     1053                        $configuration_placed = true; 
     1054                        continue; 
     1055                } 
     1056                if ($placeholder_end == $tline) { 
     1057                        $between_placeholders = false; 
     1058                        $output .= $line; 
     1059                        continue; 
     1060                } 
     1061                if ($between_placeholders) continue; 
     1062 
     1063                $output .= $line; 
     1064        }; 
     1065 
     1066        // no placeholders? append to the end 
     1067        if (!$configuration_placed) { 
     1068                $output .= $placeholder_start . "\n" . $cfg . $placeholder_end . "\n"; 
     1069        }; 
     1070 
     1071        $fh = @fopen($fpath,"w"); 
     1072        // write changes out if the file can be opened. 
     1073        // XXX: perhaps plog-options.php should check whether settings can be written and warn the user if not? 
     1074        $success = false; 
     1075        if ($fh) { 
     1076                $success = true; 
     1077                fwrite($fh,$output); 
     1078                fclose($fh); 
     1079        }; 
     1080        return $success; 
    9351081} 
    9361082 
     
    9391085function is_valid_directory($str)  
    9401086{ 
    941    // allow only alfanumeric characters, hyphen, [, ], dot, apostrophe  and space in collection names 
    942    return !preg_match("/[^\w|\.|'|\-|\[|\] ]/",$str); 
     1087        // allow only alfanumeric characters, hyphen, [, ], dot, apostrophe  and space in collection names 
     1088        return !preg_match("/[^\w|\.|'|\-|\[|\] ]/",$str); 
    9431089} 
    9441090 
     
    9461092// so plugis could add new fields to all those forms. 
    9471093function plog_add_collection_form() { 
    948    $output = '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'; 
    949    $output .= '<div class="cssbox-green" style="width: 385px !important;">   
    950       <div class="cssbox_head-green"><h2>Create a Collection</h2></div>   
    951       <div class="cssbox_body-green"><label accesskey="n" for="name"><em>N</em>ame:</label><br/><input name="name" id="name"> 
    952     <br/><label accesskey="d" for="description"><em>D</em>escription:</label><br/><input name="description" id="description" size="50"> 
    953     <input name="action" type="hidden" value="add-collection"> 
    954     <input class="submit" type="submit" value="Add Collection"> 
    955     </div></div></form>'; 
    956     return $output; 
     1094        $output = '<a href="#" id="show-collection" onclick="toggle(\'create-collection\'); toggle(\'show-collection\')">Create a Collection</a>'; 
     1095        $output .= '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'; 
     1096        $output .= '<div id="create-collection" class="cssbox-green" style="width: 385px !important; display: none;">   
     1097                <div class="cssbox_head-green"><h2>Create a Collection</h2></div>   
     1098                <div class="cssbox_body-green"><label accesskey="n" for="name"><em>N</em>ame:</label><br/><input name="name" id="name"> 
     1099         <br/><label accesskey="d" for="description"><em>D</em>escription:</label><br/><input name="description" id="description" size="50"> 
     1100         <input name="action" type="hidden" value="add-collection"> 
     1101         <input class="submit" type="submit" value="Add Collection"> 
     1102         </div></div></form>'; 
     1103         return $output; 
    9571104} 
    9581105 
    9591106function plog_add_album_form($parent_collection) { 
    960    $parent_collection = intval($parent_collection); 
    961    $output = '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'; 
    962    $output .= '<div class="cssbox-green" style="width: 385px !important;">   
    963       <div class="cssbox_head-green"><h2>Create an Album</h2></div>   
    964       <div class="cssbox_body-green"><label accesskey="n" for="name"><em>N</em>ame:</label><br/><input name="name" id="name"> 
    965     <br/><label accesskey="d" for="description"><em>D</em>escription:</label><br/><input name="description" id="description" size="50"> 
    966     <input name="action" type="hidden" value="add-album"> 
    967     <input type="hidden" name="parent_collection" value="' . $parent_collection . '"/> 
    968     <input class="submit" type="submit" value="Add Album"></div></div></form>'; 
    969     return $output; 
     1107        $parent_collection = intval($parent_collection); 
     1108        $output = '<a href="#" id="show-album" onclick="toggle(\'create-album\'); toggle(\'show-album\')">Create an Album</a>'; 
     1109        $output .= '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'; 
     1110        $output .= '<div id="create-album" class="cssbox-green" style="width: 385px !important; display: none;">   
     1111                <div class="cssbox_head-green"><h2>Create an Album</h2></div>   
     1112                <div class="cssbox_body-green"><label accesskey="n" for="name"><em>N</em>ame:</label><br/><input name="name" id="name"> 
     1113         <br/><label accesskey="d" for="description"><em>D</em>escription:</label><br/><input name="description" id="description" size="50"> 
     1114         <input name="action" type="hidden" value="add-album"> 
     1115         <input type="hidden" name="parent_collection" value="' . $parent_collection . '"/> 
     1116         <input class="submit" type="submit" value="Add Album"></div></div></form>'; 
     1117         return $output; 
    9701118} 
    9711119 
    9721120function plog_edit_collection_form($collection_id) { 
    973    global $thumbnail_config; 
    974    $output = ''; 
    975    $collection_id = intval($collection_id); 
    976    $output .= '<form class="edit" action="'.$_SERVER["PHP_SELF"].'" method="post">'; 
    977    $collection = get_collection_by_id($collection_id); 
    978  
    979    $auto_graphic = "../graphics/auto.gif"; 
    980  
    981    $images = '<option class="thumboption" value="0" style="padding-left: 100px; background-image: url('.$auto_graphic.'); background-repeat: no-repeat;">automatic</option>'; 
    982  
    983    // create a list of all pictures in the collection. Should I create a separate 
    984    // function for this as well? 
    985    $sql = "SELECT p.id AS id,caption,p.path AS path,a.name AS album_name 
    986          FROM ".TABLE_PREFIX."pictures p 
    987          LEFT JOIN " . TABLE_PREFIX . "albums AS a ON p.parent_album = a.id 
    988          WHERE p.parent_collection = '" . $collection_id . "' 
    989          ORDER BY a.name,p.date_submitted"; 
    990  
    991    $result = run_query($sql); 
    992    while($row = mysql_fetch_assoc($result)) { 
    993       $selected = ($row["id"] == $collection["thumbnail_id"]) ? " selected" : ""; 
    994       $style = 'class="thumboption" style="padding-left: '.($thumbnail_config[THUMB_SMALL]["size"] + 5).'px; background-image: url('.generate_thumb(SmartStripSlashes($row["path"]), $row["id"]).'); background-repeat: no-repeat;"'; 
    995  
    996       $images .= "<option $style value='" . $row["id"] . "'" . $selected . ">"; 
    997       $images .= SmartStripSlashes($row["album_name"]) . " : "; 
    998       $images .= !empty($row["caption"]) ? SmartStripSlashes($row["caption"]) : SmartStripSlashes(basename($row["path"])); 
    999       $images .= "</option>\n"; 
    1000    }; 
    1001  
    1002  
    1003    $output .= '<label accesskey="n" for="name"><em>N</em>ame:</label><br/><input size="30" name="name" id="name" value="'.SmartStripSlashes($collection['name']).'"><br/> 
    1004                 <label accesskey="d" for="description"><em>D</em>escription:</label><br/><input size="80" name="description" id="description" value="'.SmartStripSlashes($collection['description']).'"><br/> 
    1005                 Thumbnail:<br/><select name="thumbnail_id" onchange="updateThumbPreview(this)"  
    1006                 class="thumbselect" id="thumbselect">' . $images . '</select> 
    1007                 <script type="text/javascript">updateThumbPreview(document.getElementById(\'thumbselect\'));</script>'; 
    1008  
    1009       $output .= '<input type="hidden" name="pid" value="'.$collection_id.'"> 
    1010                <input type="hidden" name="action" value="update-collection"> 
    1011                <button class="submit" type="submit">Update</button>'; 
    1012  
    1013       $output .= '</form>'; 
    1014       return $output; 
     1121        global $thumbnail_config; 
     1122        $output = ''; 
     1123        $collection_id = intval($collection_id); 
     1124        $output .= '<form class="edit" action="'.$_SERVER["PHP_SELF"].'" method="post">'; 
     1125        $collection = get_collection_by_id($collection_id); 
     1126 
     1127        $auto_graphic = "../graphics/auto.gif"; 
     1128                 
     1129        $images = '<option class="thumboption" value="0" style="padding-left: 100px; background-image: url('.$auto_graphic.'); background-repeat: no-repeat;">automatic</option>'; 
     1130                 
     1131        // create a list of all pictures in the collection. Should I create a separate 
     1132        // function for this as well? 
     1133        $sql = "SELECT p.id AS id,caption,p.path AS path,a.name AS album_name 
     1134                        FROM ".TABLE_PREFIX."pictures p 
     1135                        LEFT JOIN " . TABLE_PREFIX . "albums AS a ON p.parent_album = a.id 
     1136                        WHERE p.parent_collection = '" . $collection_id . "' 
     1137                        ORDER BY a.name,p.date_submitted"; 
     1138                                 
     1139        $result = run_query($sql); 
     1140        while($row = mysql_fetch_assoc($result)) { 
     1141                $selected = ($row["id"] == $collection["thumbnail_id"]) ? " selected" : ""; 
     1142                $style = 'class="thumboption" style="padding-left: '.($thumbnail_config[THUMB_SMALL]["size"] + 5).'px; background-image: url('.generate_thumb(SmartStripSlashes($row["path"]), $row["id"]).'); background-repeat: no-repeat;"'; 
     1143                         
     1144                $images .= "<option $style value='" . $row["id"] . "'" . $selected . ">"; 
     1145                $images .= SmartStripSlashes($row["album_name"]) . " : "; 
     1146                $images .= !empty($row["caption"]) ? SmartStripSlashes($row["caption"]) : SmartStripSlashes(basename($row["path"])); 
     1147                $images .= "</option>\n"; 
     1148        }; 
     1149 
     1150 
     1151        $output .= '<label accesskey="n" for="name"><em>N</em>ame:</label><br/><input size="30" name="name" id="name" value="'.SmartStripSlashes($collection['name']).'"><br/> 
     1152                                    <label accesskey="d" for="description"><em>D</em>escription:</label><br/><input size="80" name="description" id="description" value="'.SmartStripSlashes($collection['description']).'"><br/> 
     1153                                    Thumbnail:<br/><select name="thumbnail_id" onchange="updateThumbPreview(this)"  
     1154                                    class="thumbselect" id="thumbselect">' . $images . '</select> 
     1155                                    <script type="text/javascript">updateThumbPreview(document.getElementById(\'thumbselect\'));</script>'; 
     1156                                         
     1157                $output .= '<input type="hidden" name="pid" value="'.$collection_id.'"> 
     1158                                        <input type="hidden" name="action" value="update-collection"> 
     1159                                        <button class="submit" type="submit">Update</button>'; 
     1160                 
     1161                $output .= '</form>'; 
     1162                return $output; 
    10151163} 
    10161164 
    10171165function plog_edit_album_form($album_id) { 
    1018    global $thumbnail_config; 
    1019    $album_id = intval($album_id); 
    1020    $output .= '<form class="edit" action="'.$_SERVER["PHP_SELF"].'" method="post">'; 
    1021  
    1022    $album = get_album_by_id($album_id); 
    1023  
    1024    $auto_graphic = "../graphics/auto.gif"; 
    1025  
    1026    $images = '<option class="thumboption" value="0" style="padding-left: 100px; background-image: url('.$auto_graphic.');  
    1027       background-repeat: no-repeat;">automatic</option>'; 
    1028  
    1029    // nii, siin tuleks kasutada hoopis ploggeri enda funktsioone selleks et saada 
    1030    // piltide nimekiri. Ja ldse tuleks liidest kuidagi lihtsamaks teha, nii et ei oleks 
    1031    // hel lehel koos liiga palju vorme. Ja kui mul on eraldi funktsiooni vormi nᅵtamiseks, 
    1032    // siis ma saan ju ka mingi ajaxi liidese sellele ehitada. Which is just as good. 
    1033    $sql = "SELECT id,caption,path FROM ".TABLE_PREFIX."pictures p WHERE p.parent_album = '" . $album_id . "'"; 
    1034  
    1035    $result = run_query($sql); 
    1036    while($row = mysql_fetch_assoc($result)) { 
    1037          $selected = ($row["id"] == $album["thumbnail_id"]) ? " selected" : ""; 
    1038          $style = 'class="thumboption" style="padding-left: '.($thumbnail_config[THUMB_SMALL]["size"] + 5).'px; background-image:  
    1039          url('.generate_thumb(SmartStripSlashes($row["path"])).'); background-repeat: no-repeat;"'; 
    1040  
    1041          $images .= "<option $style value='" . $row["id"] . "'" . $selected . ">"; 
    1042          $images .= !empty($row["caption"]) ? SmartStripSlashes($row["caption"]) : SmartStripSlashes(basename($row["path"])); 
    1043          $images .= "</option>\n"; 
    1044       }; 
    1045  
    1046       $output .= '<label for="name" accesskey="n"><em>N</em>ame:</label><br/><input size="30" name="name" id="name" value="'.SmartStripSlashes($album['name']).'"><br/> 
    1047                 <label for="description" accesskey="d"><em>D</em>escription:</label><br/><input size="80" name="description" id="description" value="'.SmartStripSlashes($album['description']).'"><br/> 
    1048                 Thumbnail:<br/><select name="thumbnail_id" class="thumbselect" id="thumbselect"  
    1049                 onchange="updateThumbPreview(this)">' . $images . '</select> 
    1050                 <script type="text/javascript">updateThumbPreview(document.getElementById(\'thumbselect\'));</script>'; 
    1051  
    1052       $output .= '<input type="hidden" name="pid" value="'.$album_id.'"> 
    1053                <input type="hidden" name="action" value="update-album"> 
    1054                <tr><td><button class="submit" type="submit">Update</button>'; 
    1055  
    1056       $output .= '</form>'; 
    1057       return $output; 
     1166        global $thumbnail_config; 
     1167        $album_id = intval($album_id); 
     1168        $output .= '<form class="edit" action="'.$_SERVER["PHP_SELF"].'" method="post">'; 
     1169         
     1170        $album = get_album_by_id($album_id); 
     1171 
     1172        $auto_graphic = "../graphics/auto.gif"; 
     1173                 
     1174        $images = '<option class="thumboption" value="0" style="padding-left: 100px; background-image: url('.$auto_graphic.');  
     1175                background-repeat: no-repeat;">automatic</option>'; 
     1176                                         
     1177        // nii, siin tuleks kasutada hoopis ploggeri enda funktsioone selleks et saada 
     1178        // piltide nimekiri. Ja ldse tuleks liidest kuidagi lihtsamaks teha, nii et ei oleks 
     1179        // hel lehel koos liiga palju vorme. Ja kui mul on eraldi funktsiooni vormi nᅵtamiseks, 
     1180        // siis ma saan ju ka mingi ajaxi liidese sellele ehitada. Which is just as good. 
     1181        $sql = "SELECT id,caption,path FROM ".TABLE_PREFIX."pictures p WHERE p.parent_album = '" . $album_id . "'"; 
     1182                                 
     1183        $result = run_query($sql); 
     1184        while($row = mysql_fetch_assoc($result)) { 
     1185                        $selected = ($row["id"] == $album["thumbnail_id"]) ? " selected" : ""; 
     1186                        $style = 'class="thumboption" style="padding-left: '.($thumbnail_config[THUMB_SMALL]["size"] + 5).'px; background-image:  
     1187                        url('.generate_thumb(SmartStripSlashes($row["path"])).'); background-repeat: no-repeat;"'; 
     1188                         
     1189                        $images .= "<option $style value='" . $row["id"] . "'" . $selected . ">"; 
     1190                        $images .= !empty($row["caption"]) ? SmartStripSlashes($row["caption"]) : SmartStripSlashes(basename($row["path"])); 
     1191                        $images .= "</option>\n"; 
     1192                }; 
     1193                 
     1194                $output .= '<label for="name" accesskey="n"><em>N</em>ame:</label><br/><input size="30" name="name" id="name" value="'.SmartStripSlashes($album['name']).'"><br/> 
     1195                                    <label for="description" accesskey="d"><em>D</em>escription:</label><br/><input size="80" name="description" id="description" value="'.SmartStripSlashes($album['description']).'"><br/> 
     1196                                    Thumbnail:<br/><select name="thumbnail_id" class="thumbselect" id="thumbselect"  
     1197                                    onchange="updateThumbPreview(this)">' . $images . '</select> 
     1198                                    <script type="text/javascript">updateThumbPreview(document.getElementById(\'thumbselect\'));</script>'; 
     1199                                         
     1200                $output .= '<input type="hidden" name="pid" value="'.$album_id.'"> 
     1201                                        <input type="hidden" name="action" value="update-album"> 
     1202                                        <tr><td><button class="submit" type="submit">Update</button>'; 
     1203                 
     1204                $output .= '</form>'; 
     1205                return $output; 
    10581206 
    10591207} 
    10601208 
    10611209function plog_picture_manager($id,$from,$limit) { 
    1062    $output = '<table style="width: 100%" cellpadding="4"> 
    1063       <col style="width: 15px;"/><tr class="header"><td class="table-header-left">&nbsp;</td>'; 
    1064    $output .= '<td width="65" class="table-header-middle">Thumb</td>'; 
    1065    $output .= '<td class="table-header-middle">Filename</td>'; 
    1066    $output .= '<td class="table-header-middle">Caption</td>'; 
    1067    $output .= '<td class="table-header-middle">Allow comments</td>'; 
    1068    $output .= '<td class="table-header-right">Actions</td></tr>'; 
    1069  
    1070  
    1071    plogger_init_pictures(array( 
    1072          'type' => 'album', 
    1073          'value' => $id, 
    1074          'from' => $from, 
    1075          'limit' => $limit, 
    1076    )); 
    1077  
    1078    if (plogger_has_pictures()) { 
    1079       $counter = 0; 
    1080       while(plogger_has_pictures()) { 
    1081          if ($counter%2 == 0) $table_row_color = "color-1"; 
    1082          else $table_row_color = "color-2"; 
    1083          $counter++; 
    1084          plogger_load_picture(); 
    1085          $id = plogger_get_picture_id(); 
    1086          $output .= "<tr class='$table_row_color'>"; 
    1087          $output .= "<td><input type='checkbox' name='selected[]' value='" . $id . "'/></td>"; 
    1088  
    1089          $thumbpath = plogger_get_picture_thumb(); 
    1090  
    1091          $imgtag = '<img class="photos" src="'.$thumbpath.'" title="'.plogger_get_picture_caption().'" alt="'.plogger_get_picture_caption().'" />'; 
    1092          //$target = 'plog-thumbpopup.php?src='.$id; 
    1093          //$java = "javascript:this.ThumbPreviewPopup('$target')"; 
    1094  
    1095          $output .= '<td><a href="'.plogger_get_picture_thumb(THUMB_LARGE).'" rel="lightbox" title="'.plogger_get_picture_caption().'">'.$imgtag.'</a></td>'; 
    1096  
    1097          $output .= "<td><strong><a class='folder' href='?level=comments&amp;id=" . $id . "'>" . basename(plogger_get_source_picture_path()) . "</a></strong></td>"; 
    1098  
    1099          $output .= "<td>" . plogger_get_picture_caption() . "</td>"; 
    1100  
    1101          $allow_comments = (1 == plogger_picture_allows_comments()) ? "Yes" : "No"; 
    1102  
    1103  
    1104          $output .= "<td>" . $allow_comments . "</td>"; 
    1105  
    1106          $output .= '<td><a href="?action=edit-picture&amp;id=' . $id . '"><img style="display:inline" src="../graphics/edit.gif" alt="Edit" title="Edit"></a>'; 
    1107  
    1108          $parent_id = $_REQUEST["id"]; 
    1109          $output .= '<a href="?action=1&selected%5B%5D=' . $id . '&level=pictures&delete_checked=1&id='.$parent_id.'"  
    1110       onClick="return confirm(\'Are you sure you want to delete this item?\');"><img style="display:inline" src="../graphics/x.gif" alt="Delete"                title="Delete"></a></td>'; 
    1111  
    1112          $output .= "</tr>"; 
    1113  
    1114       }; 
    1115       $output .= '<tr class="header"><td colspan="7"></td></tr></table>'; 
    1116       $output .= "</table>"; 
    1117    } else { 
    1118       $output .= "Sadly, there are no pictures yet"; 
    1119    }; 
    1120    return $output; 
     1210 
     1211        plogger_init_pictures(array( 
     1212                        'type' => 'album', 
     1213                        'value' => $id, 
     1214                        'from' => $from, 
     1215                        'limit' => $limit, 
     1216        )); 
     1217 
     1218        // create javascript initiation function for editable elements 
     1219        if (plogger_has_pictures()) { 
     1220                $output .= '<script type="text/javascript">'; 
     1221                $output .= "Event.observe(window, 'load', init, false);"; 
     1222                $output .= "function init() {"; 
     1223                 
     1224                while(plogger_has_pictures()) { 
     1225                        plogger_load_picture(); 
     1226                        $output .= "makeEditable('picture-description-".plogger_get_picture_id()."'); makeEditable('picture-caption-".plogger_get_picture_id()."');"; 
     1227                } 
     1228                $output .= "}"; 
     1229                $output .= '</script>'; 
     1230        } 
     1231         
     1232        // reset the picture array 
     1233                plogger_init_pictures(array( 
     1234                        'type' => 'album', 
     1235                        'value' => $id, 
     1236                        'from' => $from, 
     1237                        'limit' => $limit, 
     1238        )); 
     1239         
     1240        if (plogger_has_pictures()) { 
     1241                $output .= '<table style="width: 100%" cellpadding="4"> 
     1242                           <col style="width: 15px;"/><tr class="header"><td class="table-header-left">&nbsp;</td>'; 
     1243                $output .= '<td width="65" class="table-header-middle">Thumb</td>'; 
     1244                $output .= '<td class="table-header-middle">Filename</td>'; 
     1245                $output .= '<td class="table-header-middle">Caption</td>'; 
     1246                $output .= '<td class="table-header-middle">Description</td>'; 
     1247                $output .= '<td class="table-header-middle">Allow comments</td>'; 
     1248                $output .= '<td class="table-header-right">Actions</td></tr>'; 
     1249                $counter = 0; 
     1250                while(plogger_has_pictures()) { 
     1251                        if ($counter%2 == 0) $table_row_color = "color-1"; 
     1252                        else $table_row_color = "color-2"; 
     1253                        $counter++; 
     1254                        plogger_load_picture(); 
     1255                        $id = plogger_get_picture_id(); 
     1256                        $output .= "<tr class='$table_row_color'>"; 
     1257                        $output .= "<td><input type='checkbox' name='selected[]' value='" . $id . "'/></td>"; 
     1258 
     1259                        $thumbpath = plogger_get_picture_thumb(); 
     1260 
     1261                        $imgtag = '<img class="photos" src="'.$thumbpath.'" title="'.plogger_get_picture_caption().'" alt="'.plogger_get_picture_caption().'" />'; 
     1262                        //$target = 'plog-thumbpopup.php?src='.$id; 
     1263                        //$java = "javascript:this.ThumbPreviewPopup('$target')"; 
     1264                         
     1265                        $output .= '<td><a href="'.plogger_get_picture_thumb(THUMB_LARGE).'" rel="lightbox" title="'.plogger_get_picture_caption().'">'.$imgtag.'</a></td>'; 
     1266 
     1267                        $output .= "<td><strong><a class='folder' href='?level=comments&amp;id=" . $id . "'>" . basename(plogger_get_source_picture_path()) . "</a></strong></td>"; 
     1268 
     1269                        $output .= "<td><p id=\"picture-caption-" . plogger_get_picture_id() ."\">" . plogger_get_picture_caption() . "&nbsp;</p></td>"; 
     1270                        $output .= "<td><p id=\"picture-description-" . plogger_get_picture_id()  ."\">" . plogger_get_picture_description() . "&nbsp;</p></td>"; 
     1271                         
     1272                        $allow_comments = (1 == plogger_picture_allows_comments()) ? "Yes" : "No"; 
     1273 
     1274 
     1275                        $output .= "<td>" . $allow_comments . "</td>"; 
     1276 
     1277                        $output .= '<td><a href="?action=edit-picture&amp;id=' . $id . '"><img style="display:inline" src="../graphics/edit.gif" alt="Edit" title="Edit"></a>'; 
     1278                 
     1279                        $parent_id = $_REQUEST["id"]; 
     1280                        $output .= '<a href="?action=1&selected%5B%5D=' . $id . '&level=pictures&delete_checked=1&id='.$parent_id.'"  
     1281                onClick="return confirm(\'Are you sure you want to delete this item?\');"><img style="display:inline" src="../graphics/x.gif" alt="Delete"                                      title="Delete"></a></td>'; 
     1282 
     1283                        $output .= "</tr>"; 
     1284 
     1285                }; 
     1286                $output .= '<tr class="header"><td colspan="7"></td></tr></table>'; 
     1287                $output .= "</table>"; 
     1288        } else { 
     1289                $output .= '<p class="actions">Sadly, there are no pictures yet.  Why don\'t you <a href="plog-upload.php">upload some?</a></p>'; 
     1290        }; 
     1291        return $output; 
    11211292} 
    11221293 
    11231294function plog_album_manager($id,$from,$limit) { 
    1124       $output = '<table style="width: 100%" cellpadding="4"> 
    1125       <col style="width: 15px;"/><tr class="header"><td class="table-header-left">&nbsp;</td>'; 
    1126    $output .= '<td class="table-header-middle">Name</td>'; 
    1127    $output .= '<td class="table-header-middle">Description</td>'; 
    1128    $output .= '<td class="table-header-right">Actions</td></tr>'; 
    1129    plogger_init_albums(array( 
    1130       'from' => $from, 
    1131       'collection_id' => $id, 
    1132       'limit' => $limit, 
    1133       'all_albums' => 1, 
    1134       'sortby' => 'id', 
    1135       'sortdir' => 'asc' 
    1136    )); 
    1137  
    1138    if (plogger_has_albums()) { 
    1139       $counter = 0; 
    1140       while(plogger_has_albums()) { 
    1141          plogger_load_album(); 
    1142          $id = plogger_get_album_id(); 
    1143          if ($counter%2 == 0) $table_row_color = "color-1"; 
    1144          else $table_row_color = "color-2"; 
    1145          $counter++; 
    1146  
    1147          $output .= "<tr class='$table_row_color'>"; 
    1148          $output .= "<td><input type='checkbox' name='selected[]' value='" . $id . "'/></td>"; 
    1149  
    1150          $output .= "<td><a class='folder' href='?level=pictures&amp;id=" .$id . "'>" . plogger_get_album_name() . "</a> &#8212; contains " . plogger_album_picture_count() . " picture(s)</td>"; 
    1151  
    1152          $output .= "<td>" . plogger_get_album_description() . "</td>"; 
    1153  
    1154          $output .= '<td><a href="?action=edit-album&amp;id=' . $id . '"><img style="display:inline" src="../graphics/edit.gif" alt="Edit" title="Edit"></a>'; 
    1155          $output .= '<a href="?action=1&selected%5B%5D=' . $id . '&level=albums&delete_checked=1&id='.$_REQUEST["id"].'"  
    1156                      onClick="return confirm(\'Are you sure you want to delete this item?\');"><img style="display:inline" src="../graphics/x.gif" alt="Delete"                title="Delete"></a></td>'; 
    1157  
    1158          $output .= "</tr>"; 
    1159       }; 
    1160       $output .= '<tr class="header"><td colspan="7"></td></tr></table>'; 
    1161       $output .= "</table>"; 
    1162    } else { 
    1163       $output .= "There are no albums in this collection yet"; 
    1164    }; 
    1165    return $output; 
     1295         
     1296         
     1297        plogger_init_albums(array( 
     1298                'from' => $from, 
     1299                'collection_id' => $id, 
     1300                'limit' => $limit, 
     1301                'all_albums' => 1, 
     1302                'sortby' => 'id', 
     1303                'sortdir' => 'asc' 
     1304        )); 
     1305         
     1306                // create javascript initiation function for editable elements 
     1307        if (plogger_has_albums()) { 
     1308                $output .= '<script type="text/javascript">'; 
     1309                $output .= "Event.observe(window, 'load', init, false);"; 
     1310                $output .= "function init() {"; 
     1311                 
     1312                while(plogger_has_albums()) { 
     1313                        plogger_load_album(); 
     1314                        // makeEditable('album-name-".plogger_get_album_id()."'); 
     1315                        $output .= "makeEditable('album-description-".plogger_get_album_id()."');"; 
     1316                } 
     1317                $output .= "}"; 
     1318                $output .= '</script>'; 
     1319        } 
     1320         
     1321        plogger_init_albums(array( 
     1322                'from' => $from, 
     1323                'collection_id' => $id, 
     1324                'limit' => $limit, 
     1325                'all_albums' => 1, 
     1326                'sortby' => 'id', 
     1327                'sortdir' => 'asc' 
     1328        )); 
     1329         
     1330        if (plogger_has_albums()) { 
     1331 
     1332                $output .= '<table style="width: 100%" cellpadding="4"> 
     1333                       <col style="width: 15px;"/><tr class="header"><td class="table-header-left">&nbsp;</td>'; 
     1334                $output .= '<td class="table-header-middle">Name</td>'; 
     1335                $output .= '<td class="table-header-middle">Description</td>'; 
     1336                $output .= '<td class="table-header-right">Actions</td></tr>'; 
     1337                $counter = 0; 
     1338 
     1339                while(plogger_has_albums()) { 
     1340                        plogger_load_album(); 
     1341                        $id = plogger_get_album_id(); 
     1342                        if ($counter%2 == 0) $table_row_color = "color-1"; 
     1343                        else $table_row_color = "color-2"; 
     1344                        $counter++; 
     1345 
     1346                        $output .= "<tr class='$table_row_color'>"; 
     1347                        $output .= "<td><input type='checkbox' name='selected[]' value='" . $id . "'/></td>"; 
     1348 
     1349                        $output .= "<td><a class='folder' href='?level=pictures&amp;id=" .$id . "'><span id='album-name-" . plogger_get_album_id(). "'><strong>" . plogger_get_album_name() . "</span></a></strong> &#8212; contains " . plogger_album_picture_count() . " picture(s)</td>"; 
     1350 
     1351                        $output .= "<td><p id='album-description-" . plogger_get_album_id() . "'>" . plogger_get_album_description() . "&nbsp;</p></td>"; 
     1352 
     1353                        $output .= '<td><a href="?action=edit-album&amp;id=' . $id . '"><img style="display:inline" src="../graphics/edit.gif" alt="Edit" title="Edit"></a>'; 
     1354                $output .= '<a href="?action=1&selected%5B%5D=' . $id . '&level=albums&delete_checked=1&id='.$_REQUEST["id"].'"  
     1355                onClick="return confirm(\'Are you sure you want to delete this item?\');"><img style="display:inline" src="../graphics/x.gif" alt="Delete"                                      title="Delete"></a></td>'; 
     1356 
     1357                        $output .= "</tr>"; 
     1358                }; 
     1359                $output .= '<tr class="header"><td colspan="7"></td></tr></table>'; 
     1360                $output .= "</table>"; 
     1361        } else { 
     1362                $output .= "<p class='actions'>There are no albums in this collection yet, why don't you create one?</p>"; 
     1363        }; 
     1364        return $output; 
    11661365 
    11671366 
     
    11691368 
    11701369function plog_collection_manager($from,$limit) { 
    1171    $output = '<table style="width: 100%" cellpadding="4"> 
    1172       <col style="width: 15px;"/><tr class="header"><td class="table-header-left"></td>'; 
    1173    $output .= '<td class="table-header-middle">Name</td>'; 
    1174    $output .= '<td class="table-header-middle">Description</td>'; 
    1175    $output .= '<td class="table-header-right">Actions</td></tr>'; 
    1176  
    1177    plogger_init_collections(array( 
    1178       'from' => $from, 
    1179       'limit' => $limit, 
    1180       'all_collections' => 1, 
    1181       'sortby' => 'id', 
    1182       'sortdir' => 'asc' 
    1183    )); 
    1184  
    1185    if (plogger_has_collections()) { 
    1186       $counter = 0; 
    1187       while(plogger_has_collections()) { 
    1188          plogger_load_collection(); 
    1189          if ($counter%2 == 0) $table_row_color = "color-1"; 
    1190          else $table_row_color = "color-2"; 
    1191          $counter++; 
    1192          $id = plogger_get_collection_id(); 
    1193  
    1194          $output .= "<tr class='$table_row_color'>"; 
    1195          $output .= "<td><input type='checkbox' name='selected[]' value='" . $id . "'/></td>"; 
    1196  
    1197          $output .= "<td><a class='folder' href='?level=albums&amp;id=" .$id . "'>" . plogger_get_collection_name() . "</a> &#8212; contains " . plogger_collection_album_count() . " albums</td>"; 
    1198  
    1199          $output .= "<td>" . plogger_get_collection_description() . "</td>"; 
    1200  
    1201          $output .= '<td><a href="?action=edit-collection&amp;id=' . $id . '"><img style="display:inline" src="../graphics/edit.gif" alt="Edit" title="Edit"></a>'; 
    1202  
    1203          $output .= '<a href="?action=1&selected%5B%5D=' . $id . '&level=collections&delete_checked=1&id='.@$_REQUEST["id"].'"  
    1204          onClick="return confirm(\'Are you sure you want to delete this item?\');"><img style="display:inline" src="../graphics/x.gif" alt="Delete"                title="Delete"></a></td>'; 
    1205  
    1206          $output .= "</tr>"; 
    1207       }; 
    1208       $output .= '<tr class="header"><td colspan="7"></td></tr></table>'; 
    1209       $output .= "</table>"; 
    1210    } else { 
    1211       $output .= "There are no collections yet"; 
    1212    }; 
    1213    return $output; 
     1370 
     1371        plogger_init_collections(array( 
     1372                'from' => $from, 
     1373                'limit' => $limit, 
     1374                'all_collections' => 1, 
     1375                'sortby' => 'id', 
     1376                'sortdir' => 'asc' 
     1377        )); 
     1378         
     1379                        // create javascript initiation function for editable elements 
     1380        if (plogger_has_collections()) { 
     1381                $output .= '<script type="text/javascript">'; 
     1382                $output .= "Event.observe(window, 'load', init, false);"; 
     1383                $output .= "function init() {"; 
     1384                 
     1385                while(plogger_has_collections()) { 
     1386                        plogger_load_collection(); 
     1387                        // makeEditable('collection-name-".plogger_get_collection_id()."'); 
     1388                        $output .= "makeEditable('collection-description-".plogger_get_collection_id()."');"; 
     1389                } 
     1390                $output .= "}"; 
     1391                $output .= '</script>'; 
     1392        } 
     1393         
     1394        plogger_init_collections(array( 
     1395                'from' => $from, 
     1396                'limit' => $limit, 
     1397                'all_collections' => 1, 
     1398                'sortby' => 'id', 
     1399                'sortdir' => 'asc' 
     1400        )); 
     1401 
     1402        if (plogger_has_collections()) { 
     1403                $output .= '<table style="width: 100%" cellpadding="4"> 
     1404                <col style="width: 15px;"/><tr class="header"><td class="table-header-left"></td>'; 
     1405                $output .= '<td class="table-header-middle">Name</td>'; 
     1406                $output .= '<td class="table-header-middle">Description</td>'; 
     1407                $output .= '<td class="table-header-right">Actions</td></tr>'; 
     1408                $counter = 0; 
     1409                while(plogger_has_collections()) { 
     1410                        plogger_load_collection(); 
     1411                        if ($counter%2 == 0) $table_row_color = "color-1"; 
     1412                        else $table_row_color = "color-2"; 
     1413                        $counter++; 
     1414                        $id = plogger_get_collection_id(); 
     1415 
     1416                        $output .= "<tr class='$table_row_color'>"; 
     1417                        $output .= "<td><input type='checkbox' name='selected[]' value='" . $id . "'/></td>"; 
     1418 
     1419                        $output .= "<td><a class='folder' href='?level=albums&amp;id=" .$id . "'><strong><span id='collection-name-" . plogger_get_collection_id() . "'>" . plogger_get_collection_name() . "</span></a></strong> &#8212; contains " . plogger_collection_album_count() . " albums</td>"; 
     1420                         
     1421                        $output .= "<td><p id='collection-description-" . plogger_get_collection_id() . "'>" . plogger_get_collection_description() . "&nbsp;</p></td>"; 
     1422 
     1423                        $output .= '<td><a href="?action=edit-collection&amp;id=' . $id . '"><img style="display:inline" src="../graphics/edit.gif" alt="Edit" title="Edit"></a>'; 
     1424                 
     1425                        $output .= '<a href="?action=1&selected%5B%5D=' . $id . '&level=collections&delete_checked=1&id='.@$_REQUEST["id"].'"  
     1426                        onClick="return confirm(\'Are you sure you want to delete this item?\');"><img style="display:inline" src="../graphics/x.gif" alt="Delete"                                      title="Delete"></a></td>'; 
     1427 
     1428                        $output .= "</tr>"; 
     1429                }; 
     1430                $output .= '<tr class="header"><td colspan="7"></td></tr></table>'; 
     1431                $output .= "</table>"; 
     1432        } else { 
     1433                $output .= "<p class='actions'>There are no collections yet</p>"; 
     1434        }; 
     1435        return $output; 
    12141436} 
    12151437 
    12161438function plog_comment_manager($id,$from,$limit) { 
    1217       $output = '<table style="width: 100%" cellpadding="4"> 
    1218       <col style="width: 15px;"/><tr class="header"><td class="table-header-left">&nbsp;</td>'; 
    1219    $output .= '<td class="table-header-middle">Author</td>'; 
    1220    $output .= '<td class="table-header-middle">E-mail</td>'; 
    1221    $output .= '<td class="table-header-middle">URL</td>'; 
    1222    $output .= '<td class="table-header-middle">Date</td>'; 
    1223    $output .= '<td class="table-header-middle">Comment</td>'; 
    1224    $output .= '<td class="table-header-right">Actions</td></tr>'; 
    1225  
    1226    plogger_init_picture(array( 
    1227          'id' => $id, 
    1228    )); 
    1229  
    1230    if (plogger_picture_has_comments()) { 
    1231       $counter = 0; 
    1232       while(plogger_picture_has_comments()) { 
    1233          plogger_load_comment(); 
    1234          if ($counter%2 == 0) $table_row_color = "color-1"; 
    1235          else $table_row_color = "color-2"; 
    1236  
    1237          $id = plogger_get_comment_id(); 
    1238  
    1239  
    1240  
    1241          $output .= "<tr class='$table_row_color'>"; 
    1242          $output .= "<td><input type='checkbox' name='selected[]' value='" . $id . "'/></td>"; 
    1243          $output .= "<td>" . plogger_get_comment_author() . "</td>"; 
    1244          $email = plogger_get_comment_email(); 
    1245          $output .= "<td><a href='mailto:$email'>" . $email . "</td>"; 
    1246          $output .= "<td>" . plogger_get_comment_url() . "</td>"; 
    1247          $output .= "<td>" . plogger_get_comment_date("n.j.Y H:i:s") . "</td>"; 
    1248          $output .= "<td>" . plogger_get_comment_text() . "</td>"; 
    1249  
    1250          $output .= '<td><a href="?action=edit-comment&amp;id=' . $id . '"><img style="display:inline" src="../graphics/edit.gif" alt="Edit" title="Edit"></a>'; 
    1251       $output .= '<a href="?action=delete-comment&amp;id=' . $id . '"  
    1252       onClick="return confirm(\'Are you sure you want to delete this item?\');"><img style="display:inline" src="../graphics/x.gif" alt="Delete"                title="Delete"></a></td>'; 
    1253  
    1254          $output .= "</tr>"; 
    1255  
    1256  
    1257  
    1258  
    1259    }; 
    1260    $output .= '<tr class="header"><td colspan="7"></td></tr></table>'; 
    1261    $output .= "</table>"; 
    1262  
    1263  
    1264    } else { 
    1265       $output .= "No comments here"; 
    1266    }; 
    1267  
    1268    // tuleb kᅵgepealt pilt initsialiseerida. Ja seejᅵel  
    1269  
    1270  
    1271  
    1272    return $output; 
     1439 
     1440        plogger_init_picture(array( 
     1441                        'id' => $id, 
     1442        )); 
     1443         
     1444        // create javascript initiation function for editable elements 
     1445        if (plogger_picture_has_comments()) { 
     1446                $output .= '<script type="text/javascript">'; 
     1447                $output .= "Event.observe(window, 'load', init, false);"; 
     1448                $output .= "function init() {"; 
     1449                 
     1450                while(plogger_picture_has_comments()) { 
     1451                        plogger_load_comment(); 
     1452                        // makeEditable('collection-name-".plogger_get_collection_id()."'); 
     1453                        $output .= "makeEditable('comment-comment-".plogger_get_comment_id()."'); 
     1454                                                makeEditable('comment-author-".plogger_get_comment_id()."'); 
     1455                                                makeEditable('comment-url-".plogger_get_comment_id()."'); 
     1456                                                makeEditable('comment-email-".plogger_get_comment_id()."');"; 
     1457                } 
     1458                $output .= "}"; 
     1459                $output .= '</script>'; 
     1460        } 
     1461         
     1462        plogger_init_picture(array( 
     1463                        'id' => $id, 
     1464        )); 
     1465         
     1466        if (plogger_picture_has_comments()) { 
     1467                $output .= '<table style="width: 100%" cellpadding="4"> 
     1468                <col style="width: 15px;"/><tr class="header"><td class="table-header-left">&nbsp;</td>'; 
     1469                $output .= '<td class="table-header-middle">Author</td>'; 
     1470                $output .= '<td class="table-header-middle">E-mail</td>'; 
     1471                $output .= '<td class="table-header-middle">URL</td>'; 
     1472                $output .= '<td class="table-header-middle">Date</td>'; 
     1473                $output .= '<td class="table-header-middle">Comment</td>'; 
     1474                $output .= '<td class="table-header-right">Actions</td></tr>'; 
     1475                $counter = 0; 
     1476                while(plogger_picture_has_comments()) { 
     1477                        plogger_load_comment(); 
     1478                        if ($counter%2 == 0) $table_row_color = "color-1"; 
     1479                        else $table_row_color = "color-2"; 
     1480 
     1481                        $id = plogger_get_comment_id(); 
     1482 
     1483 
     1484 
     1485                        $output .= "<tr class='$table_row_color'>"; 
     1486                        $output .= "<td><input type='checkbox' name='selected[]' value='" . $id . "'/></td>"; 
     1487                        $output .= "<td><p id=\"comment-author-" . $id ."\">" . plogger_get_comment_author() . "&nbsp;</p></td>"; 
     1488                        $email = plogger_get_comment_email(); 
     1489                        $output .= "<td><p id=\"comment-email-" . $id ."\">" . $email . "&nbsp;</p></td>"; 
     1490                        $output .= "<td><p id=\"comment-url-" . $id ."\">" . plogger_get_comment_url() . "&nbsp;</p></td>"; 
     1491                        $output .= "<td>" . plogger_get_comment_date("n.j.Y H:i:s") . "</td>"; 
     1492                        $output .= "<td><p id=\"comment-comment-" . $id ."\">" . plogger_get_comment_text() . "&nbsp;</p></td>"; 
     1493 
     1494                        $output .= '<td><a href="?action=edit-comment&amp;id=' . $id . '"><img style="display:inline" src="../graphics/edit.gif" alt="Edit" title="Edit"></a>'; 
     1495                $output .= '<a href="?action=delete-comment&amp;id=' . $id . '"  
     1496                onClick="return confirm(\'Are you sure you want to delete this item?\');"><img style="display:inline" src="../graphics/x.gif" alt="Delete"                                      title="Delete"></a></td>'; 
     1497 
     1498                        $output .= "</tr>"; 
     1499 
     1500 
     1501 
     1502 
     1503        }; 
     1504        $output .= '<tr class="header"><td colspan="7"></td></tr></table>'; 
     1505        $output .= "</table>"; 
     1506 
     1507 
     1508        } else { 
     1509                $output .= "<p class='actions'>This picture has no comments on it.</p>"; 
     1510        }; 
     1511 
     1512        // tuleb kᅵgepealt pilt initsialiseerida. Ja seejᅵel  
     1513 
     1514 
     1515 
     1516        return $output; 
     1517} 
     1518 
     1519function generate_ajax_picture_editing_init() { 
     1520         
     1521        $output = '<script type="text/javascript">'; 
    12731522} 
    12741523?> 
  • branches/plogger-with-tags/admin/plog-admin.php

    r373 r402  
    11<?php 
    2 error_reporting(E_ALL); 
     2 
    33//session_start(); 
    44header("Content-Type: text/html; charset=utf-8"); 
     
    5959                                <link href="../css/admin.css" type="text/css" rel="stylesheet" media="all"/> 
    6060                                <link href="../css/greybox.css" type="text/css" rel="stylesheet" media="all"/> 
     61                                <script type="text/javascript" src="js/prototype.js"></script> 
     62                                <script type="text/javascript" src="js/moo.fx.js"></script> 
     63                                <script type="text/javascript" src="js/plogger.js"></script> 
     64                                <script type="text/javascript" src="js/lightbox.js"></script> 
     65                                <script type="text/javascript" src="js/AmiJS.js"></script> 
     66                                <script type="text/javascript" src="js/greybox.js"></script> 
    6167                                '.$inHead.' 
    62                         <script type="text/javascript" src="js/prototype.js"></script> 
    63                         <script type="text/javascript" src="js/plogger.js"></script> 
    64                         <script type="text/javascript" src="js/lightbox.js"></script> 
    65                         <script type="text/javascript" src="js/AmiJS.js"></script> 
    66                         <script type=