// // http://www.chezgreg.net/coppermine/ // // ------------------------------------------------------------------------- // // Based on PHPhotoalbum by Henning Střverud // // http://www.stoverud.com/PHPhotoalbum/ // // ------------------------------------------------------------------------- // // This program is free software; you can redistribute it and/or modify // // it under the terms of the GNU General Public License as published by // // the Free Software Foundation; either version 2 of the License, or // // (at your option) any later version. // // ------------------------------------------------------------------------- // include("include/init.inc.php"); /************************************************************************** * Local functions definition **************************************************************************/ $header_printed = false; $need_caption = false; function output_table_header() { global $header_printed, $need_caption; $header_printed = true; $need_caption = true; ?> Picture F N T C D   Caption
F : full size image   : successfully deleted
N : normal size image   : can't be deleted
T : thumbnail
C : comment
D : image in album

"; $red = "
"; $query = "SELECT * FROM $CONFIG[TABLE_PICTURES] WHERE pid='$pid'"; $result = mysql_query($query); $pic = mysql_fetch_array($result); $aid = $pic['aid']; $dir=$CONFIG['fullpath'].$pic['filepath']; $file=$pic['filename']; if (!is_writable($dir)) echo " Directory '$dir' is not writable, pictures can't be deleted \n"; echo " $file"; $files=array($dir.$file, $dir.$CONFIG['normal_pfx'].$file, $dir.$CONFIG['thumb_pfx'].$file); foreach ($files as $currFile){ echo " "; if ($CONFIG['admin_username'] == 'admin' && $CONFIG['admin_password'] == 'admin') echo $red; // Demo mode elseif (is_file($currFile)){ if(@unlink($currFile)) echo $green; else echo $red; } else echo " "; echo ""; } $query = "DELETE FROM $CONFIG[TABLE_COMMENTS] WHERE pid='$pid'"; $result = mysql_query($query); echo " "; if(mysql_affected_rows() > 0) echo $green; else echo " "; echo ""; $query = "DELETE FROM $CONFIG[TABLE_PICTURES] WHERE pid='$pid' LIMIT 1"; $result = mysql_query($query); echo " "; if(mysql_affected_rows() > 0) echo $green; else echo $red; echo ""; echo "\n"; return $aid; } function delete_album($aid) { global $CONFIG; $query = "SELECT * FROM $CONFIG[TABLE_PICTURES] WHERE aid='$aid'"; $result = mysql_query($query); // Delete all files while($pic = mysql_fetch_array($result)) { delete_picture($pic['pid']); } // Delete album $query = "DELETE from $CONFIG[TABLE_ALBUMS] WHERE aid='$aid'"; $result = mysql_query($query); if(mysql_affected_rows() > 0) echo " Album $aid: Deleted \n"; } /************************************************************************** * Album manager functions **************************************************************************/ function parse_select_option($value) { if (!preg_match("/.+?no=(\d+),album_nm='(.+?)',album_sort=(\d+),action=(\d)/", $value, $matches)) return false; return array( 'album_no' => $matches[1], 'album_nm' => $matches[2], 'album_sort' => $matches[3], 'action' => $matches[4] ); } function parse_orig_sort_order($value) { if (!preg_match("/(\d+)@(\d+)/", $value, $matches)) return false; return array( 'aid' => $matches[1], 'pos' => $matches[2], ); } function parse_list($value) { return preg_split("/,/", $value, -1, PREG_SPLIT_NO_EMPTY); } function index_to_date($index) { $hours = floor($index/3600); $index -= $hours * 3600; $min = floor($index/60); $index -= $min * 60; $sec = $index; return sprintf("%02d:%02d:%02d",$hours,$min,$sec); } /************************************************************************** * Main code starts here **************************************************************************/ switch ($what){ // // Album manager (don't necessarily delete something ;-) // case 'albmgr': auth_needed(); pageheader("Album Manager"); starttable("100%"); echo "

Album Manager

\n"; $orig_sort_order = parse_list($HTTP_POST_VARS['sort_order']); foreach ($orig_sort_order as $album){ $op = parse_orig_sort_order($album); if (count ($op) == 2){ $date_by_pos="2002-01-01 ".index_to_date($op['pos']); $query = "UPDATE $CONFIG[TABLE_ALBUMS] SET date='$date_by_pos' WHERE aid='{$op['aid']}' LIMIT 1"; db_query($query); } else { die ("Invalid data received"); } } $to_delete = parse_list($HTTP_POST_VARS['delete_album']); foreach ($to_delete as $album_id){ delete_album($album_id); } if (isset($HTTP_POST_VARS['to'])) foreach ($HTTP_POST_VARS['to'] as $option_value){ $op = parse_select_option(stripslashes($option_value)); switch ($op['action']){ case '0': break; case '1': echo " Creating album '{$op['album_nm']}' \n"; $date_by_pos="2002-01-01 ".index_to_date($op['album_sort']); $query = "INSERT INTO $CONFIG[TABLE_ALBUMS] (title, uploads, date) VALUES ('".addslashes(htmlspecialchars($op['album_nm']))."', 'NO', '$date_by_pos')"; db_query($query); break; case '2': echo " Updating album '{$op['album_no']}' with title '{$op['album_nm']}' and index '{$op['album_sort']}' \n"; $date_by_pos="2002-01-01 ".index_to_date($op['album_sort']); $query = "UPDATE $CONFIG[TABLE_ALBUMS] SET title='".addslashes(htmlspecialchars($op['album_nm']))."', date='$date_by_pos' WHERE aid='{$op['album_no']}' LIMIT 1"; db_query($query); break; default: die ("Invalid data received"); } } if ($need_caption) output_caption(); echo "

\n"; echo "
\n"; echo "
BACK
\n"; echo "
\n
\n "; break; // // Comment // case 'comment': if ($AUTHORIZED){ $query = "DELETE FROM {$CONFIG['TABLE_COMMENTS']} WHERE msg_id='$HTTP_GET_VARS[id]'"; } else { $query = "DELETE FROM {$CONFIG['TABLE_COMMENTS']} WHERE msg_id='$HTTP_GET_VARS[id]' and author_id='{$USER['ID']}'"; } $result = mysql_query($query); $count = mysql_affected_rows(); if($count > 0){ header("Location: ".$HTTP_SERVER_VARS['HTTP_REFERER']); exit; } else { pageheader("Delete $what"); $msg = "No changes were made..."; msg_box("Deleting comment...", $msg, "BACK", "javascript:history.back()"); } break; // // Picture // case 'picture': auth_needed(); pageheader("Delete $what"); starttable("100%"); echo "

Deleting $what

"; output_table_header(); $aid = delete_picture($HTTP_GET_VARS[id]); output_caption(); echo "

\n"; echo "
\n"; echo "
BACK
\n"; echo "
\n
\n"; break; // // Album // case 'album': auth_needed(); pageheader("Delete $what"); starttable("100%"); echo "

Deleting $what

"; delete_album($HTTP_GET_VARS['id']); if ($need_caption) output_caption(); echo "

\n"; echo "
\n"; echo "
BACK
\n"; echo "
\n
\n "; break; } ?>