Web Analytics Made Easy -
StatCounter how to add a delete option - CodingForum

Announcement

Collapse
No announcement yet.

how to add a delete option

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to add a delete option

    Greetings

    I'm using 'plogger', an image gallery software. Their support forum hardly get responses, so I thought I ask here.
    There is a file named import.php, where admin can review images uploaded by users and decide which album to send them to. The problem is that there is no 'delete' option, to use in cases where there are unwated pics.
    Can someone please help me? I dont know how to add a delete option to that script:
    Code:
    <?php
    
    // Code by Mike Johnson -- [email protected] October 23rd, 2004.
    // This is the main administrative interface code.  To change the look of the interface, change ../css/admin.css.
    
    
    // The initial tab is UPLOAD function.
    
    require("plog-globals.php");
    require_once("../plog-load_config.php");
    require_once("../plog-functions.php");
    include("plog-admin-functions.php");
    
    global $inHead;
    global $TABLE_PREFIX;
    
    $inHead = '<script type="text/javascript" src="js/plogger.js"></script>';
    
    function generate_albums_menu($albums,$type = "multiple", $preselect) {
    	$output = '';
    	
    	if ($type == "multiple")
    		 $output .=  "<select name=\"destinations[]\">";
    	else
    		$output .=  "<select name=\"destination\">";
    		
    	foreach($albums as $album_id => $album_data) {
    	    if ($preselect == $album_id) 
    			$selected = " selected"; else $selected = "";
    						
    		$output .= "<option value=\"".$album_id."\"$selected>".$album_data['collection_name']." : ".$album_data['album_name']."" ;
            $output .= "</option>";
            }
    	
    	$output .=  "</select>";
    	
    	return $output;
    }
    
    
    function generate_collections_menu() {
    	$collections = get_collections();
        $output = "<select name=\"collections_menu\">";
        foreach($collections as $collection) {
            $output .= "<option value=\"".$collection['id']."\">".$collection['name']."" ;
            $output .=  "</option>";
        }
    	
    	$output .= "</select>";
    	
    	return $output;
    }
    
    function get_files($directory) {
       // Try to open the directory
       if($dir = opendir($directory)) {
           // Create an array for all files found
           $tmp = Array();
    
           // Add the files
           while($file = readdir($dir)) {
               // Make sure the file exists
               if($file != "." && $file != ".." && $file[0] != '.') {
                   // If it's a directiry, list all files within it
                   if(is_dir($directory . "/" . $file)) {
                       $tmp2 = get_files($directory . "/" . $file);
                       if(is_array($tmp2)) {
                           $tmp = array_merge($tmp, $tmp2);
                       }
                   } else {
                       $filename = basename(stripslashes($file));
    			
    				   $filename_parts = explode(".",$filename,2);
    				   $filename_ext = strtolower($filename_parts[1]);
    					
    				   if($filename_ext == "jpg" || $filename_ext == "gif" || $filename_ext == "bmp" || $filename_ext == "png")
                       		array_push($tmp, $directory . "/" . $file);
                   }
               }
           }
    
           // Finish off the function
           closedir($dir);
           return $tmp;
       }
    }
    
    $output = '';
    
    
    // Check if update has been clicked, handle erroneous conditions, or upload
    if (isset($_POST["upload"])){
    
    	$destinations = $_POST["destinations"];
    	$captions = $_POST["captions"];
    	$files = $_POST["files"];
    	$selected = $_POST["Selected"];
    
    	
    	$counter = $imported = 0;
    
    	global $config;
      	
    	$files = get_files($config['basedir'] . 'uploads');
    
    	if ($_POST["destination_radio"] == "new" && $_POST["new_album_name"] == ""){
                $output .= '<p class="errors">New album name not specified!</p>';
            }
    	else {
    		
    		if ($_POST["destination_radio"] == "new"){
    			// Create the new album
    			$result = add_album($_POST["new_album_name"], NULL, $_POST["collections_menu"]);
    			$album_id = $result["id"];
    		}
    		else
    		{
    			$album_id = $_POST["destination"];
    		}
    
    		if ($album_id) {
    			foreach($files as $file) {
    				$file_key = md5($file);
    				if (in_array($file_key,$selected)) {
    				
    					$file_name = SmartStripSlashes($file);
    					// fully qualified file name
    					//$fqfn = $config["basedir"] . "uploads/".$file_name;
    					$fqfn = $file;
    
    					// attempt to chmod the pictures directory before moving them
    					@chmod(dirname($fqfn), 0777);
    					
    					if (is_file($fqfn)) {
    						$result = add_picture($album_id,$fqfn,basename($file_name),$captions[$file_key]);
    						if ($result["picture_id"] != false) {
    							$imported++;
    							// delete thumbnail file if it exists
    							$thumbpath = $config['basedir'] . 'thumbs/import-' . basename($file_name);
    							if (is_file($thumbpath) && is_readable($thumbpath))
    							{
    								unlink($thumbpath);
    							};
    						};
    					}
    						
    					$counter++;
    				};
    			
    			}
    			
    			// get album name for display
    			$sql = "SELECT name FROM ".$TABLE_PREFIX."albums WHERE id = $album_id";
    			$result = run_query($sql);
    			
    			$row = mysql_fetch_assoc($result);
    			 
    			$output .= '<p class="actions">'.$imported.' picture(s) were successfully imported to album <b>'.$row['name'].'</b></p>';
    		
    			if ($imported == 0)
    				$output .= '<p class="errors">Make sure to CHMOD 777 your newly created folders within the uploads directory or else Plogger cannot access them.  Plogger cannot CHMOD the directory for you while PHP is in safe mode.</p>';
    		}
    		else
    			$output .= '<p class="errors">'.$result['output'].'</p>';
    
    	}
    
    	// read the list again, so any newly created directories show up
    	$files = get_files($config['basedir'] . 'uploads');
      	
      	// build a list of unique directories from the filenames
      	$directories = array();
      	
      	foreach ($files as $file) {
      		 
      		 $dirname = dirname($file);
      		 
      		 if (!in_array($dirname, $directories))
      		 	$directories[md5($dirname)] = $dirname;
      	}  		 
      		
      	// here we will check which group of pictures we are editing, grouped by directory
      	if (count($directories) > 0) {
      		$output .= '<div class="actions">Would you like to import anything else?';
      		
      		$output .= '<ul>';			
      		
      		foreach ($directories as $dirkey => $group) {
      				 $output .= '<li><a class="folder" href="'.$_SERVER['PHP_SELF']."?directory=$dirkey".'">'.basename($group).'</a></li>';
      		}
    		
      		$dirkey = md5($upload_directory);
    		  $output .= '<li><a class="folder" href="'.$_SERVER['PHP_SELF']."?directory=$dirkey".'">All Pictures</a></li>';
      
      		$output .= '</ul></div>';
      		
      	}
    	
    }
      else {
      $output .= '
      	<h1>Import Photos</h1>';
      	
    
      	$upload_directory = $config['basedir'] . 'uploads';
      	if (!is_writable($upload_directory))
      		$output .= '<p class="errors">Your "Uploads" directory is NOT WRITABLE!  Use your FTP client to CHMOD the directory with the
      		proper permissions or your import may fail!</p>';
      
      	$files = get_files($upload_directory);
      	
      	// build a list of unique directories from the filenames
      	$directories = array();
    
      	foreach ($files as $file) {
      		 
      		 $dirname = dirname($file);
    
    		 $dirkey = md5($dirname);
      		 
    		// using md5 hashes for directory names allows for easier validation of given directory name
    		// and also allows us to work with international characters in directory names
      		 if (!in_array($dirname, $directories))
      		 		$directories[md5($dirname)] = $dirname;
      	}
    
      	if (count($files) == 0) {
      		 $output .= '<div class="actions">No images found in the <b>/uploads/</b> directory.  
      		 To mass import pictures into your gallery, simply:<ul>
      		 <li><b>Open an FTP connection</b> to your website</li>
    			 <li>Transfer photos you wish to publish to the <b>/uploads/</b> directory</li>  		 
    			 <li>Optionally, you can create folders within that directory to import in groups</li></ul></div>';
      	}
    
      	// here we will check which group of pictures we are editing, grouped by directory
      	if (!isset($_GET["directory"]) && count($directories) > 0) {
      		$output .= '<div class="actions">Choose a directory you wish to import from:';
      		
      		$output .= '<ul>';			
      		
      		foreach ($directories as $dirkey => $group) {
      			$output .= '<li><a class="folder" href="'.$_SERVER['PHP_SELF']."?directory=$dirkey".'">'.basename($group).'</a></li>';
      		}
      
      		$dirkey = md5($upload_directory);
      		// $output .= '<li><a class="folder" href="'.$_SERVER['PHP_SELF'].'?directory='.$dirkey.'">All pictures</a></li>';
      		$output .= '</ul></div>';
      		
      	}
      	else {
    		// real_directory is the full path
    		// show_directory is what the user sees, it's relative so the directory structure of the server
    		// is not exposed
    		$show_directory = "uploads";
      		if (isset($_GET["directory"]) && isset($directories[$_GET["directory"]])) {
    			$real_directory = $directories[$_GET["directory"]];
    			$show_directory .= substr($real_directory,strlen($upload_directory));
    		}
      		else {
    			$real_directory = $upload_directory;
      		}
      		
    		$files = get_files($real_directory);
      		
      		if (count($files) > 0) 
    			$output .= '<p class="actions">You are currently looking at <b>'.count($files).'</b> image(s) within the <b>
    			  				   	   '.$show_directory.'</b> directory';
    
      	
      		// check to make sure album is writable and readable, and issue warning
      		if (!is_writable($real_directory) || !is_readable($real_directory))
      			$output .= '<p class="actions">Warning: this directory does not have the proper permissions settings!  You must
      						CHMOD 777 on this directory using your FTP software or import may fail.';	
      		
      		
    		$albums = get_albums();
    	    for($i=0; $i<count($files); $i++)  
    	    {  
    	    		$file_key = md5($files[$i]);
    			$relative_name = substr($files[$i],strlen($upload_directory)+1);
    	  		if ($i == 0)
    	  		$output.= '<form id="uploadForm" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">
    	  							<table><tr class="header"><td></td><td>Thumbnail</td><td>Filename</td><td>Caption</td></tr>';
    	  						
    	  		// For each file within upload directory, list checkmark, thumbnail, caption box, album box
    	  		if ($counter%2 == 0) $table_row_color = "color-1";
    	  		else $table_row_color = "color-2";
    	  		
    	  		// start a new table row (alternating colors)
    	  		$output .= "<tr class=\"$table_row_color\">";
    	
    			$thumbpath = generate_thumb($config['basedir'].'uploads/'.$relative_name,"import",'small');
    	
    	  			// generate XHTML with thumbnail and link to picture view.
    	  			$imgtag = '<td><img class="photos" src="'.$thumbpath.'" /></td>';
    	  			$output .= '<td width="15"><input type="CHECKBOX" name="Selected[]" VALUE="'.$file_key.'" checked></td>';
    	  			$output .= $imgtag;
    	  			//$output .= '<input name="files[]" type="hidden" value="'.$file_key.'">'
    				$output .= '</td>';
    	  			$output .= '<td>'.basename($files[$i]).'</td>';
    	  			$output .= '<td><input size="100%" name="captions[' . $file_key . ']"></input></td>';
    	  			$counter++;  
    	    }  
    	  
    		if (count($files) != 0) {
    		  	$output .= '</table><a href="#" onclick="checkAll(document.getElementById(\'uploadForm\')); return false; ">Invert Checkbox Selection</a>'; 
    		    
    		    // here we can preselect some default options based on the structure of the import directory
    		    // if pictures are within one directory, simply place the name of the album within the
    		    // create new album selector and allow user to pick collection.
    		    // if two levels deep, preselect appropriate existing album and collection
    		    // or place album name in new box
    		    
    		    // break up directory name into parts
    		    $directory_parts = explode("/", $show_directory);
    		    
    		    // check if album exists
    		    $collection_name = $directory_parts[2];
    		    $album_name = $directory_parts[3];
    	
    		    
    		    if (is_null($album_name)) // file is only one level deep, assume folder name is album name
    		    	$sql = "SELECT id FROM ".$TABLE_PREFIX."albums WHERE name = '".$collection_name."'";
    			else 
    		    	$sql = "SELECT id FROM ".$TABLE_PREFIX."albums WHERE name = '".$album_name."'";
    		    
    		    
    		    $result = run_query($sql);
    			$row = mysql_fetch_assoc($result);
    			
    			if(!isset($row['id'])) { // album doesn't exist, place in new album box
    				$existing = "";
    				$new_album = "CHECKED";
    				if (is_null($album_name))
    					$new_album_name = $collection_name;
    				else
    					$new_album_name = $album_name;
    			}
    			else {
    				$existing = "CHECKED";
    				$new_album = "";
    			}
    		    
    		    $output .=  '
    		      <h1>Destination:</h1>
    		      <table>
    		      <tr><td>
    		      <table><tr valign="middle"><td width="20"><input type="radio" name="destination_radio" 
    		      value="existing" '.$existing.'></td><td>Existing Album</td></tr></table>
    			  '.generate_albums_menu($albums,"single", $row['id']).'
    			  <td><h3>OR</h3></td>
    		      <td><table><tr valign="middle"><td width="20"><input onClick="var k=document.getElementsByName(\'new_album_name\');k[0].focus()" 
    		      type="radio" name="destination_radio" 
    		      value="new" '.$new_album.'></td><td>Create a New Album</td></table><table>
    		      <tr valign="middle"><td width="120">New Album Name: </td><td width="160"><input type="text" 
    		      name="new_album_name" value="'.$new_album_name.'"> 
    		      <td width="90">In collection:</td><td>
    				'.generate_collections_menu().'</td></tr></table></td><tr>
    		      <td><br><input class="submit" type="submit" name="upload" value="Import" /></td></tr>
    		      </table></div>';
    		
    		    $output .= '</form>';
    		}
    	}
    }
    
    
    $output_error = '<h1>Import</h1><p class="actions">Before you can begin importing photos to your gallery, you must
    create at least <b>one collection</b> AND <b>one album</b> within that collection.  Move over to 
    the <a href="plog-manage.php">"Manage"</a> tab to begin creating your organizational structure</p>';
    
    $num_albums = count_albums();
    
    if ($num_albums > 0)
    	 display($output, "import");
    else
    	 display($output_error, "import");
    	 
    ?>

  • #2
    If its any help, here is another plogger file that has the delete option:
    Code:
    <?php
    
    require("plog-globals.php");
    require_once("../plog-load_config.php"); 					// load configuration variables from database
    require_once("plog-admin-functions.php");
    error_reporting(E_ERROR);
    global $inHead;
    
    $inHead = '<script type="text/javascript" src="js/plogger.js"></script>';
    
    function generate_pagination_view_menu() {
    	
    	$java = 'document.location.href = \''.$_SERVER["PHP_SELF"].'?level='.$_REQUEST["level"].
    	'&amp;id='.$_REQUEST["id"].'&amp;entries_per_page=\'+this.options[this.selectedIndex].value';
    	
    	$possible_values = array("5"=>5, "10"=>10, "20"=>20, "50"=>50);
    	$output.= 'Entries per page <select onchange="'.$java.'" name="entries_per_page">';
    	
    	foreach ($possible_values as $key => $value)
    		if ($_SESSION['entries_per_page'] == $key)
    			$output .= "<option value=\"$value\" selected>$key</option>";
    		else
    			$output .= "<option value=\"$value\">$key</option>";
    			
    	$output.= '</select>';
    	
    	return $output;				
    
    }
    
    function generate_move_menu($level) {
    	global $TABLE_PREFIX;
    	if ($level != "collections" and $level != "comments"){
      	
    		if ($level == "albums") $parent = "collections";
    		if ($level == "pictures") $parent = "albums";
    		$output .=  '<input class="submit" type="submit" name="action" value="Move Checked To"/>';
      	
    		if ($level == "pictures") {
    			$albums = get_albums();
    			$output .= generate_albums_menu($albums);
    		} else {
    			$output .=  '<select name="group_id">';
    			$collections = get_collections();
    			foreach($collections as $collection) {
    				$output .= '<option value="'.$collection["id"].'">'.$collection["name"];
    				$output .=  '</option>';
    			}
    			$output .=  '</select>';
    		}
    			
    		return $output;
    	}
    }
    
    function generate_albums_menu($albums) {
    	$output .=  '<select name="group_id">';
    	foreach($albums as $album_id => $album) {
    		
                if ($_REQUEST["albums_menu"] == $album_id || $_REQUEST["new_album_name"] == $album['album_name']) 
    						$selected = " selected"; else $selected = "";
    						
    						$output .= "<option value=\"".$album_id."\"$selected>".$album['collection_name']." : ".$album['album_name']."" ;
                $output .= "</option>";
            }
    	
    	$output .=  "</select>";
    	
    	return $output;
    }
    
    function generate_breadcrumb_admin($level, $id){
    	global $TABLE_PREFIX;
    	switch ($level){
    		case 'collections':
    		  $breadcrumbs = '<b>Collections</b>';
    			
    			break;
    		case 'albums':
    			$query = "SELECT * FROM `".$TABLE_PREFIX."collections` WHERE `id`='".$id."'";
    			$result = run_query($query);
    			$row = mysql_fetch_assoc($result);
    			
    			$collection_name = $row["name"];
    			
    			$breadcrumbs = '<a href="'.$_SERVER["PHP_SELF"].'">Collections</a> &raquo; ' . "<b>$collection_name</b>";
    			
    			break;
    		case 'pictures':
    			
    			$query = "SELECT * FROM `".$TABLE_PREFIX."albums` WHERE `id`='".$id."'";
    			$result = run_query($query);
    			$row = mysql_fetch_assoc($result);
    			
    			$album_link = $row["name"];
    			
    			$query = "SELECT * FROM `".$TABLE_PREFIX."collections` WHERE `id`='".$row["parent_id"]."'";
    			$result = run_query($query);
    			$row = mysql_fetch_assoc($result);
    			
    			$collection_link = '<a href="'.$_SERVER["PHP_SELF"].'?level=albums&amp;id='.$row["id"].'">'.$row["name"].'</a>';
    			
    			$breadcrumbs = '<a href="'.$_SERVER["PHP_SELF"].'">Collections</a> &raquo; ' . $collection_link . ' &raquo; ' . '<b>'.						$album_link.'</b>';
    			
    			break;
    		case 'comments':
    			
    			$query = "SELECT * FROM `".$TABLE_PREFIX."pictures` WHERE `id`='".$id."'";
    			$result = run_query($query);
    			$row = mysql_fetch_assoc($result);
    			
    			$picture_link = '<b>'.$row["path"].'</b>';
    			$album_id = $row["parent_album"];
    			$collection_id = $row["parent_collection"];
    			
    			$query = "SELECT * FROM `".$TABLE_PREFIX."albums` WHERE `id`='".$album_id."'";
    			$result = run_query($query);
    			$row = mysql_fetch_assoc($result);
    			
    			$album_link = '<a href="'.$_SERVER["PHP_SELF"].'?level=pictures&amp;id='.$album_id.'">'.$row["name"].'</a>';
    			
    			$query = "SELECT * FROM `".$TABLE_PREFIX."collections` WHERE `id`='".$collection_id."'";
    			$result = run_query($query);
    			$row = mysql_fetch_assoc($result);
    			
    			$collection_link = '<a href="'.$_SERVER["PHP_SELF"].'?level=albums&amp;id='.$collection_id.'">'.$row									["name"].'</a>';
    			
    			$breadcrumbs = '<a href="'.$_SERVER["PHP_SELF"].'">Collections</a> &raquo; ' . $collection_link . ' &raquo; '
    			.$album_link. ' &raquo; '.$picture_link . ' &raquo;' . " Comments";
    			
    			break;
    		default:
    			$breadcrumbs = '<b>Collections</b>';
    	}
    	
    	return '<div id="breadcrumb_links">'.$breadcrumbs.'</div>';
    }
    
    if (!isset($_REQUEST["level"]) or $_REQUEST["level"] == '') $level = "collections";	 
    else $level = $_REQUEST['level'];
    
    $output = '<h1>Manage Content</h1>';
    
    global $config;
    
    
    // here we will determine if we need to perform a move or delete action.
    if (isset($_REQUEST["action"])) {
    	$num_items = 0;
    
    	$action_result = array();
    
    	if ($_REQUEST["action"]== "Delete Checked") {
    		// perform the delete function on the selected items
    		
    		if (isset($_REQUEST["Selected"])) {
    			foreach($_REQUEST["Selected"] as $del_id) {
    				// lets build the query string
    				if ($level == "pictures") {
    					$rv = delete_picture($del_id);
    				}
    				if ($level == "collections") {
    					$rv = delete_collection($del_id);
    				}
    				if ($level == "albums") {
    					$rv = delete_album($del_id);
    				}
    
    				if (isset($rv['errors'])) {
    					$output .= '<p class="errors">' . $rv['errors'] . '</p>';
    				} else {
    					$num_items++;
    				};
    			}
    			
    			$output .= "<p class=\"actions\">You have deleted $num_items entry(s) successfully.</p>";
    		}
    		else{
    			$output .= "<p class=\"errors\">Nothing selected to delete!</p>";
    		}
    	}
    	else if ($_REQUEST["action"] == "Move Checked To") {
    		if ($level == "albums") $parent = "parent_id";
    		if ($level == "pictures") $parent = "parent_album";
    		
    		// perform the move function on the selected items
    		$pid = intval($_REQUEST["group_id"]);
    		
    		if (isset($_REQUEST["Selected"])) {
    			foreach($_REQUEST["Selected"] as $mov_id) {
    				
    				// if we are using pictures we need to update the parent_collection as well
    				if ($level == "pictures") {
    					 // lets build the query string
    					 $mov_id = intval($mov_id);
    					$query = "UPDATE ".$TABLE_PREFIX."$level SET `$parent` = '$pid' WHERE `id`='$mov_id'";
    					$result = run_query($query);
    					$num_items++;
    				
    					 // we need the parent_id from the album we're changing to
    					 $query = "SELECT * FROM ".$TABLE_PREFIX."albums WHERE `id` = '$pid'";
    					 $result = run_query($query);
    					 $row = mysql_fetch_assoc($result);
    					 $new_collection = $row['parent_id'];
    					 
    					 // set the new parent id
    					 $query = "UPDATE ".$TABLE_PREFIX."$level SET `parent_collection` = '$new_collection' WHERE `id`='$mov_id'";
    					 $result = run_query($query);
    					 
    					 // move picture to new location
    					 // we need to query to get collection names and album names to find new directory path
    					 
    					 $sql = "SELECT p.path as path, c.path as collection_path, a.path as album_path
    							FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."pictures p, ".$TABLE_PREFIX."collections c 
    							WHERE p.parent_album = a.id AND p.parent_collection = c.id AND p.id = '$mov_id'";
    					
    					 $result = run_query($sql);
    					 $row = mysql_fetch_assoc($result);
    					 
    					 $filename = basename($row['path']);
    					 $directory = $row['collection_path']."/".$row['album_path']."/";
    					 $new_path = $directory.$filename;
    					 
    					 if (!rename($config['basedir']."images/".$row['path'], $config['basedir']."images/".$new_path))
    						$output .= "<p class=\"errors\">Error moving file! ($row[path] to $new_path)</p>";
    						
    					$new_path = mysql_real_escape_string($new_path);
    					// update database
    					$sql = "UPDATE ".$TABLE_PREFIX."pictures SET path = '$new_path' WHERE id = '$mov_id'";
    					mysql_query($sql) or ($output .= "<p class=\"errors\">".mysql_error()."</p>");
    				}
    				else if ($level == "albums") {
    					// if we are moving entire albums then we need to rename the folder
    					// $pid is our target collection id, $mov_id is our source album
    					
    					// rename the directory
    					// first, get the album name and collection name of our source album
    					$sql = "SELECT c.path as collection_path, a.path as album_path
    							FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."collections c 
    							WHERE c.id = a.parent_id AND a.id = '$mov_id'";
    					
    					$result = run_query($sql);
    					$row = mysql_fetch_assoc($result);
    					
    					$source_album_name = SmartStripSlashes($row["album_path"]);
    					$source_collection_name = SmartStripSlashes($row["collection_path"]);
    					
    					// next, get the collection name of our destination collection
    					$sql = "SELECT c.path as collection_path
    							FROM ".$TABLE_PREFIX."collections c 
    							WHERE c.id = '$pid'";
    					
    					$result = run_query($sql);
    					$row = mysql_fetch_assoc($result);
    					
    					$target_collection_name = SmartStripSlashes($row["collection_path"]);
    					
    					$source_path = $config['basedir']."images/".$source_collection_name."/".$source_album_name;
    					$target_path = $config['basedir']."images/".$target_collection_name."/".$source_album_name;
    					
    					// attempt to make new album directory in target collection
    					@mkdir($target_path, 0775);
    					
    					//if (!rename($source_path, $target_path))
    					//	$output .= '<p class="errors">Could not rename directory!</p>';
    					
    					// now we need to update the database paths of all pictures within source album
    					$sql = "SELECT p.path as path, c.name as collection_name, a.name as album_name
    							FROM ".$TABLE_PREFIX."albums a, ".$TABLE_PREFIX."pictures p, ".$TABLE_PREFIX."collections c 
    							WHERE p.parent_album = a.id AND p.parent_collection = c.id AND p.parent_album = '$mov_id'";
    					
    					$result = run_query($sql);
    					
    					while($row = mysql_fetch_assoc($result)) {
    					 
    						$filename = basename($row['path']);
    						
    						$old_path = $source_path."/".$filename;
    						$new_path = $target_path."/".$filename;
    						 
    						if (!rename($old_path, $new_path))
    							$output .= "<p class=\"errors\">Error moving file! ($old_path to $new_path)</p>";
    						
    						// $output .= "<p class=\"actions\">Updating database: $row[path] -> $new_path</p>";	
    						// update database
    						$row['path'] = mysql_real_escape_string($row['path']);
    						
    						$sql = "UPDATE ".$TABLE_PREFIX."pictures SET parent_collection = '$pid' WHERE path = '$row[path]'";
    						mysql_query($sql) or ($output .= "<p class=\"errors\">".mysql_error()."</p>");
    						
    						$path_insert = mysql_real_escape_string($target_collection_name."/".$source_album_name."/".$filename);
    						$sql = "UPDATE ".$TABLE_PREFIX."pictures SET path = '$path_insert' WHERE path = '$row[path]'";
    						mysql_query($sql) or ($output .= "<p class=\"errors\">".mysql_error()."</p>");
    						
    						
    					}
    					
    					// update the parent id of the moved album
    					$query = "UPDATE ".$TABLE_PREFIX."albums SET `parent_id` = '$pid' WHERE `id`='$mov_id'";
    					$result = run_query($query);
    					$num_items++;
    
    					
    				
    				}
    					  
    			}
    			
    			$output .= "<p class=\"actions\">You have moved $num_items entry(s) successfully.</p>";
    		}
    		else{
    			$output .= "<p class=\"errors\">Nothing selected to move!</p>";
    		}
    	}
    	else if ($_REQUEST["action"] == "edit-picture") {
    		// show the edit form
    		$pid = intval($_REQUEST["pid"]);
    		$sql = "SELECT * FROM ".$TABLE_PREFIX."pictures p WHERE p.id = '" . $pid . "'";
    		$result = run_query($sql);
    		$photo = mysql_fetch_assoc($result);
    		if ($photo['allow_comments'] == 1) $state = "checked"; else $state = "";
    		
    		$output .= '<form class="edit" action="'.$_SERVER["PHP_SELF"].'" method="post">';
    		
    		
    		$output .= 'Caption:<br/><input size="80" name="caption" id="caption" value="'.$photo['caption'].'">
    				    Allow Comments? <input type="checkbox" id="allow_comments" name="allow_comments" value="1"'." $state>";
    					
    		$output .= '<input type="hidden" name="level" value="'.$level.'"><input type="hidden" 
    					name="id" value="'.$photo['parent_album'].'"><input type="hidden" 
    					name="pid" value="'.$photo['id'].'"><input type="hidden" 
    					name="action" value="update-picture"><button class="submit" type="submit">Update</button>';
    		
    		$output .= '</form>';
    		
    	}
    	else if ($_REQUEST["action"] == "edit-album") {
    		// show the edit form
    		
    		$output .= '<form class="edit" action="'.$_SERVER["PHP_SELF"].'" method="post">';
    		$pid = intval($_REQUEST["pid"]);
    		
    		$sql = "SELECT * FROM ".$TABLE_PREFIX."albums a WHERE a.id = '" . $pid . "'";
    		$result = run_query($sql);
    		$album = mysql_fetch_assoc($result);
    					
    		$sql = "SELECT id,caption,path FROM ".$TABLE_PREFIX."pictures p
    			WHERE p.parent_album = '" . $pid . "'";
    				
    		$images = "<option value='0'>automatic</option>";
    		$result = run_query($sql);
    		while($row = mysql_fetch_assoc($result)) {
    			$selected = ($row["id"] == $album["thumbnail_id"]) ? " selected" : "";
    			$images .= "<option value='" . $row["id"] . "'" . $selected . ">";
    			$images .= !empty($row["caption"]) ? $row["caption"] : basename($row["path"]);
    			$images .= "</option>\n";
    		};
    		
    
    		$output .= 'Name:<br/><input size="30" name="name" id="name" value="'.$album['name'].'"><br/>
    				    Description:<br/><input size="80" name="description" id="description" value="'.$album['description'].'"><br/>
    				    Thumbnail:<br/><select name="thumbnail_id" id="thumbnail_id">' . $images . '</select>';
    					
    		$output .= '<input type="hidden" name="level" value="'.$level.'"><input type="hidden" 
    					name="pid" value="'.$pid.'"><input type="hidden" 
    					name="id" value="'.$id.'"><input type="hidden" 
    					name="action" value="update-album"><tr><td><button class="submit" type="submit">Update</button>';
    		
    		$output .= '</form>';
    		
    	}
    	else if ($_REQUEST["action"] == "edit-collection") {
    		// show the edit form
    		$output .= '<form class="edit" action="'.$_SERVER["PHP_SELF"].'" method="post">';
    		$pid = intval($_REQUEST["pid"]);
    		
    		$sql = "SELECT * FROM ".$TABLE_PREFIX."collections c WHERE c.id = '" . $pid . "'";
    		$result = run_query($sql);
    		$collection = mysql_fetch_assoc($result);
    		
    		$sql = "SELECT p.id AS id,caption,p.path AS path,a.name AS album_name FROM ".$TABLE_PREFIX."pictures p
    			LEFT JOIN " . $TABLE_PREFIX . "albums AS a ON p.parent_album = a.id
    			WHERE p.parent_collection = '" . $pid . "' ORDER BY a.name,p.date_submitted";
    				
    		$images = "<option value='0'>automatic</option>";
    		$result = run_query($sql);
    		while($row = mysql_fetch_assoc($result)) {
    			$selected = ($row["id"] == $collection["thumbnail_id"]) ? " selected" : "";
    			$images .= "<option value='" . $row["id"] . "'" . $selected . ">";
    			$images .= $row["album_name"] . " : ";
    			$images .= !empty($row["caption"]) ? $row["caption"] : basename($row["path"]);
    			$images .= "</option>\n";
    		};
    
    
    		$output .= 'Name:<br/><input size="30" name="name" id="name" value="'.$collection['name'].'"><br/>
    				    Description:<br/><input size="80" name="description" id="description" value="'.$collection['description'].'"><br/>
    				    Thumbnail:<br/><select name="thumbnail_id" id="thumbnail_id">' . $images . "</select>";
    					
    		$output .= '<input type="hidden" name="level" value="'.$level.'"><input type="hidden" 
    					name="pid" value="'.$pid.'"><input type="hidden" 
    					name="id" value="'.$id.'"><input type="hidden" 
    					name="action" value="update-collection"><button class="submit" type="submit">Update</button>';
    		
    		$output .= '</form>';
    		
    	}
    	else if ($_REQUEST["action"] == "edit-comment") {
    		// show the edit form
    		$comment_id = intval($_GET["pid"]);
    		$sql = "SELECT * FROM ".$TABLE_PREFIX."comments c WHERE c.id = '$comment_id'";
    		$result = run_query($sql);
    		$comment = mysql_fetch_assoc($result);
    		$output .= '<form class="edit" action="'.$_SERVER["PHP_SELF"].'" method="post"><table>';
    
    		$output .= '<tr><td>Author:<br/><input size="30" name="author" id="author" value="'.SmartStripSlashes($comment['author']).'"></td>
    				    <td>Email:<br/><input size="30" name="email" id="email" value="'.SmartStripSlashes($comment['email']).'"></td>
    					<td>Website:<br/><input size="30" name="url" id="url" value="'.SmartStripSlashes($comment['url']).'"></td></tr>
    					<tr><td colspan="3">Comment:<br/> <textarea cols="70" rows="4" name="comment" id="comment">'.
    					SmartStripSlashes($comment['comment']).'</textarea></td></tr></table>';
    					
    		$output .= '<input type="hidden" name="level" value="'.$level.'"><input type="hidden" 
    					name="pid" value="'.$comment['id'].'"><input type="hidden" 
    					name="id" value="'.$id.'"><input type="hidden" 
    					name="action" value="update-comment"><button class="submit" type="submit">Update</button>';
    		
    		$output .= '</form>';
    		
    	}
    	else if ($_POST['action'] == 'update-picture') {
    		$action_result = update_picture($_POST['pid'],$_POST['caption'],$_POST['allow_comments']);
    	}
    	else if ($_POST['action'] == 'update-album') {
    		$action_result = update_album($_POST['pid'],$_POST['name'],$_POST['description'],$_POST['thumbnail_id']);
    	}
    	else if ($_POST["action"] == "update-collection") {
    		$action_result = update_collection($_POST["pid"],$_POST["name"],$_POST["description"],$_POST["thumbnail_id"]);
    	}
    	else if ($_POST["action"] == "update-comment") {
    		$action_result = update_comment($_POST["pid"],$_POST["author"],$_POST["email"],$_POST["url"],$_POST["comment"]);
    	}
    	else if ($_POST["action"] == "add-collection") {
    		$action_result = add_collection($_POST["name"],$_POST["description"]);
    	}
    	else if ($_POST["action"] == "add-album") {
    		$action_result = add_album($_POST["name"],$_POST["description"],$_POST["id"]);
    	}
    
    	if (!empty($action_result['errors'])) {
    		$output .= '<p class="errors">' . $action_result['errors'] . '</p>';
    	} elseif (!empty($action_result['output'])) {
    		$output .= '<p class="actions">' . $action_result['output'] . '</p>';
    	};
    }
    
    $output .= '<form id="contentList" action="'.$_SERVER["PHP_SELF"].'" method="post">';
    
    // here we will generate a "add collection/album" header
    if ($level == "collections") {
    	 $output .= '<div class="box-3"><h2 class="add">Create a Collection: </h2><label for="name">Name </label><br/><input name="name" id="name">
    	 <br/><label for="description">Description </label><br/><input name="description" id="description" size="50">
    	 <input name="action" type="hidden" value="add-collection">
    	 <input class="submit" type="submit" value="Add Collection">
    	 </div>';
    	 }
    else if ($level == "albums") {
    	$output .= '<div class="box-3"><h2 class="add">Create an Album: </h2><label for="name">Name </label><br/><input name="name" id="name">
    	 <br/><label for="description">Description </label><br/><input name="description" id="description" size="50">
    	 <input name="action" type="hidden" value="add-album">
    	 <input class="submit" type="submit" value="Add Album"></div>';
    	 }
    continued next post >

    Comment


    • #3
      Code:
      // this is our defined list of allowed fields for each table
      $allowedPictureKeys = array("path", "caption", "allow_comments");
      $allowedAlbumKeys = array("name", "description");
      $allowedCollectionKeys = array("name", "description");
      $allowedCommentKeys = array("date", "author", "email", "url", "comment");
      
      
      // lets iterate through all the content and build a table
      // set the default level if nothing is specified
      
      // handle pagination
      // lets determine the limit filter based on current page and number of results per page
      
      $page = 1;
      $id = intval($_REQUEST['id']);
      $REQUEST['id'] = $id;
      if (isset($_REQUEST["page"]) && is_numeric($_REQUEST["page"])) {
      	$page = $_REQUEST["page"];
      }
      
      if (isset($_REQUEST['entries_per_page']) && is_numeric($_REQUEST['entries_per_page'])) 
      	$_SESSION['entries_per_page'] = $_REQUEST['entries_per_page'];
      else
      	$_SESSION['entries_per_page'] = 20;
      
      
      // determine the filtering conditional based on the level and id number
      if ($level == "albums" or $level == "comments"){
      	$cond = "WHERE `parent_id` = '$_REQUEST[id]'";
      }
      else if ($level == "pictures"){
      	$cond = "WHERE `parent_album` = '$_REQUEST[id]'";
      }
      
      $url = "?entries_per_page=$_SESSION[entries_per_page]&amp;level=$level&amp;id=$_REQUEST[id]";
      
      $first_item = ($page - 1) * $_SESSION['entries_per_page'];
      $limit = "LIMIT $first_item, $_SESSION[entries_per_page]";
      
      // lets generate the pagination menu as well
      $recordCount = "SELECT COUNT(*) AS num_items FROM ".$TABLE_PREFIX."$level $cond";
      $totalRowsResult = mysql_query($recordCount);
      $totalRows = mysql_result($totalRowsResult,'num_items');
      
      $pagination_menu = generate_pagination('plog-manage.php'.$url,$page,$totalRows,$_SESSION['entries_per_page']);
      
      $query = "SELECT * FROM ".$TABLE_PREFIX."$level $cond $limit";
      $result = run_query($query);
      
      if ($result) {
      	if (mysql_num_rows($result) == 0) {
         $output .= generate_breadcrumb_admin($level, $id);
      	 $output.= '<p class="actions">This table is empty.</p>';
      	}
      	while($row = mysql_fetch_assoc($result)) {
      		// if we're on our first iteration, dump the header
      		if ($counter == 0) {
      			$output .= '<table><tr><td>'
      			.generate_breadcrumb_admin($level, $id).'</td>';
      			
      			// output view entries pagination control
      			$output .= '<td align="right">'.generate_pagination_view_menu().'</td></tr></table>';
      			
      			if ($level == "pictures"){
      				$output .= '<table cellpadding="4"><tr class="header"><td></td><td width="65">Thumb</td>';
      			}
      			else{
      				$output .= '<table cellpadding="4"><tr class="header"><td></td>';
      			}
      			
      			foreach ($row as $name => $value) {
      				// check to see if this is allowed
      				$value = SmartStripSlashes($value);
      				if (($level == "albums" && in_array($name, $allowedAlbumKeys)) ||
      					  ($level == "pictures" && in_array($name, $allowedPictureKeys)) ||
      						($level == "collections" && in_array($name, $allowedCollectionKeys)) ||
      							($level == "comments" && in_array($name, $allowedCommentKeys))) {
      										if ($level == "pictures" && $name == 'path') $name = 'filename'; 
      										$output .= "<td>".ucfirst($name)."</td>";
      							}
      			}
      			
      			$output .= '<td>Actions</td></tr>';
      		}
      		
      		if ($counter%2 == 0) $table_row_color = "color-1";
      		else $table_row_color = "color-2";
      		
      		// start a new table row (alternating colors)
      		$output .= "<tr class=\"$table_row_color\">";
      		
      		// give the row a checkbox
      		$output .= '<td width="15"><input type="CHECKBOX" name="Selected[]" VALUE="'.$row["id"].'"></td>';
      		
      		//give the row a thumbnail if we're in pictures view
      		if ($level == "pictures") {
      		
      			$thumbpath = generate_thumb($row["path"],$row["id"],'small');
      			
      			// generate XHTML with thumbnail and link to picture view.
      			$imgtag = '<img class="photos" src="'.$thumbpath.'" title="'.$row["caption"].'" alt="'.$row["caption"].'" />';
      			$target = 'plog-thumbpopup.php?src='.$row["id"];
      			$java = "javascript:this.ThumbPreviewPopup('$target')";
      			
      			$output .= '<td><a href="'.$java.'">'.$imgtag.'</a></td>';
      		}
      		
      		foreach($row as $key => $value) {
      			$value = htmlspecialchars($value);
      			if ($key == "name" || ($key == "path" && $level == "pictures")) {  // $output .= a link to the next level
      				if ($level == "collections") {
      					$num = count_albums($row['id']);
      					$output .= "<td><a class=\"folder\" href=\"$_SERVER[PHP_SELF]?level=albums&amp;id=$row[id]\">
      					<b>$value </b></a> — contains $num album(s)</td>";
      				}
      				else if ($level == "albums") {
      					$num = count_pictures($row['id']);
      					$output .= "<td><a class=\"folder\" href=\"$_SERVER[PHP_SELF]?level=pictures&amp;id=$row[id]\">
      					<b>$value</b></a> — contains $num picture(s)</td>";
      					
      				}
      				else if ($level == "pictures") {
      					$output .= "<td><a class=\"folder\" href=\"$_SERVER[PHP_SELF]?level=comments&amp;id=$row[id]\">
      					<b>".basename($value)."</b></a></td>";
      					
      				}
      				else
      					$output .= "<td>$value</td>";
      			}
      			else if ($key == "email") {
      				$output .= "<td><a href=\"mailto:$value\">$value</a></td>";
      			}
      			else if ($key == "allow_comments") {
      				if ($value) $output .= "<td>Yes</td>";
      				else $output .= "<td>No</td>";
      			}
      			else {
      				if (($level == "albums" && in_array($key, $allowedAlbumKeys)) ||
      					  ($level == "pictures" && in_array($key, $allowedPictureKeys)) ||
      						($level == "collections" && in_array($key, $allowedCollectionKeys)) ||
      							($level == "comments" && in_array($key, $allowedCommentKeys)))
      										$output .= "<td>".SmartStripSlashes($value)."</td>";
      			}
      		}
      		
      		// $output .= our actions panel
      		if ($level == "pictures") $query = "?action=edit-picture&amp;pid=$row[id]&amp;level=pictures&amp;id=$id";
      		else if ($level == "collections") $query = "?action=edit-collection&amp;pid=$row[id]&amp;
      			level=collections&amp;id=$id";
      		else if ($level == "albums") $query = "?action=edit-album&amp;pid=$row[id]&amp;
      			&amp;level=albums&amp;id=$id";
      		else if ($level == "comments") $query = "?action=edit-comment&amp;pid=$row[id]&amp;level=$level&amp;id=$id";
      
      		
      		$output .= '<td width="50"><a href="'.$_SERVER["PHP_SELF"]."$query&amp;entries_per_page=$_SESSION[entries_per_page]".
      		'"><img style="display:inline" src="../graphics/edit.gif" alt="Edit" title="Edit"></a><a href="'.$_SERVER["PHP_SELF"]."?action=Delete+Checked&amp;Selected[]=$row[id]&amp;level=$level&amp;id=$id".'" 
      		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>';
      
      		
      		$output .= "</tr>";
      		$counter++;
      	}
      	
      	$output .= '<tr class="header"><td colspan="7"></td></tr></table>';
      }
      
      $output .= '
      	<table><tr><td><a href="#" onclick="checkAll(document.getElementById(\'contentList\')); return false; ">Invert Checkbox Selection</a></td><td align="right">'.$pagination_menu.'</td></tr></table>'.
      	'<input type="hidden" name="level" value="'.$level.'" />
      	<input type="hidden" name="id" value="'.$id.'" />
      	<input class="submit" type="submit" name="action" onClick="return confirm(\'Are you sure you want to delete selected items?\');" 
      	value="Delete Checked">
      	'.generate_move_menu($level).'</form>';
      
      display($output, "manage");
      ?>
      Many thanks in advance.

      Comment


      • #4
        anyone please?

        Comment


        • #5
          here you go

          replace 'admin/plog_import.php' with this script
          PHP Code:
          <?php

          // Code by Mike Johnson -- [email protected] October 23rd, 2004.
          // This is the main administrative interface code.  To change the look of the interface, change ../css/admin.css.


          // The initial tab is UPLOAD function.

          require("plog-globals.php");
          require_once(
          "../plog-load_config.php");
          require_once(
          "../plog-functions.php");
          include(
          "plog-admin-functions.php");

          global 
          $inHead;
          global 
          $TABLE_PREFIX;

          $inHead '<script type="text/javascript" src="js/plogger.js"></script>';

          function 
          generate_albums_menu($albums,$type "multiple"$preselect) {
              
          $output '';
              
              if (
          $type == "multiple")
                   
          $output .=  "<select name=\"destinations[]\">";
              else
                  
          $output .=  "<select name=\"destination\">";
                  
              foreach(
          $albums as $album_id => $album_data) {
                  if (
          $preselect == $album_id
                      
          $selected " selected"; else $selected "";
                                  
                  
          $output .= "<option value=\"".$album_id."\"$selected>".$album_data['collection_name']." : ".$album_data['album_name']."" ;
                  
          $output .= "</option>";
                  }
              
              
          $output .=  "</select>";
              
              return 
          $output;
          }


          function 
          generate_collections_menu() {
              
          $collections get_collections();
              
          $output "<select name=\"collections_menu\">";
              foreach(
          $collections as $collection) {
                  
          $output .= "<option value=\"".$collection['id']."\">".$collection['name']."" ;
                  
          $output .=  "</option>";
              }
              
              
          $output .= "</select>";
              
              return 
          $output;
          }

          function 
          get_files($directory) {
             
          // Try to open the directory
             
          if($dir opendir($directory)) {
                 
          // Create an array for all files found
                 
          $tmp = Array();

                 
          // Add the files
                 
          while($file readdir($dir)) {
                     
          // Make sure the file exists
                     
          if($file != "." && $file != ".." && $file[0] != '.') {
                         
          // If it's a directiry, list all files within it
                         
          if(is_dir($directory "/" $file)) {
                             
          $tmp2 get_files($directory "/" $file);
                             if(
          is_array($tmp2)) {
                                 
          $tmp array_merge($tmp$tmp2);
                             }
                         } else {
                             
          $filename basename(stripslashes($file));
                      
                             
          $filename_parts explode(".",$filename,2);
                             
          $filename_ext strtolower($filename_parts[1]);
                              
                             if(
          $filename_ext == "jpg" || $filename_ext == "gif" || $filename_ext == "bmp" || $filename_ext == "png")
                                     
          array_push($tmp$directory "/" $file);
                         }
                     }
                 }

                 
          // Finish off the function
                 
          closedir($dir);
                 return 
          $tmp;
             }
          }

          $output '';


          // Check if update has been clicked, handle erroneous conditions, or upload
          if (isset($_POST["upload"])){

              
          $destinations $_POST["destinations"];
              
          $captions $_POST["captions"];
              
          $files $_POST["files"];
              
          $selected $_POST["Selected"];

              
              
          $counter $imported 0;

              global 
          $config;
                
              
          $files get_files($config['basedir'] . 'uploads');

              if (
          $_POST["destination_radio"] == "new" && $_POST["new_album_name"] == ""){
                      
          $output .= '<p class="errors">New album name not specified!</p>';
                  }
              else {
                  
                  if (
          $_POST["destination_radio"] == "new"){
                      
          // Create the new album
                      
          $result add_album($_POST["new_album_name"], NULL$_POST["collections_menu"]);
                      
          $album_id $result["id"];
                  }
                  else
                  {
                      
          $album_id $_POST["destination"];
                  }

                  if (
          $album_id) {
                      foreach(
          $files as $file) {
                          
          $file_key md5($file);
                          if (
          in_array($file_key,$selected)) {
                          
                              
          $file_name SmartStripSlashes($file);
                              
          // fully qualified file name
                              //$fqfn = $config["basedir"] . "uploads/".$file_name;
                              
          $fqfn $file;

                              
          // attempt to chmod the pictures directory before moving them
                              
          @chmod(dirname($fqfn), 0777);
                              
                              if (
          is_file($fqfn)) {
                                  
          $result add_picture($album_id,$fqfn,basename($file_name),$captions[$file_key]);
                                  if (
          $result["picture_id"] != false) {
                                      
          $imported++;
                                      
          // delete thumbnail file if it exists
                                      
          $thumbpath $config['basedir'] . 'thumbs/import-' basename($file_name);
                                      if (
          is_file($thumbpath) && is_readable($thumbpath))
                                      {
                                          
          unlink($thumbpath);
                                      };
                                  };
                              }
                                  
                              
          $counter++;
                          };
                      
                      }
                      
                      
          // get album name for display
                      
          $sql "SELECT name FROM ".$TABLE_PREFIX."albums WHERE id = $album_id";
                      
          $result run_query($sql);
                      
                      
          $row mysql_fetch_assoc($result);
                       
                      
          $output .= '<p class="actions">'.$imported.' picture(s) were successfully imported to album <b>'.$row['name'].'</b></p>';
                  
                      if (
          $imported == 0)
                          
          $output .= '<p class="errors">Make sure to CHMOD 777 your newly created folders within the uploads directory or else Plogger cannot access them.  Plogger cannot CHMOD the directory for you while PHP is in safe mode.</p>';
                  }
                  else
                      
          $output .= '<p class="errors">'.$result['output'].'</p>';

              }

              
          // read the list again, so any newly created directories show up
              
          $files get_files($config['basedir'] . 'uploads');
                
                
          // build a list of unique directories from the filenames
                
          $directories = array();
                
                foreach (
          $files as $file) {
                     
                     
          $dirname dirname($file);
                     
                     if (!
          in_array($dirname$directories))
                         
          $directories[md5($dirname)] = $dirname;
                }           
                    
                
          // here we will check which group of pictures we are editing, grouped by directory
                
          if (count($directories) > 0) {
                    
          $output .= '<div class="actions">Would you like to import anything else?';
                    
                    
          $output .= '<ul>';            
                    
                    foreach (
          $directories as $dirkey => $group) {
                             
          $output .= '<li><a class="folder" href="'.$_SERVER['PHP_SELF']."?directory=$dirkey".'">'.basename($group).'</a></li>';
                    }
                  
                    
          $dirkey md5($upload_directory);
                    
          $output .= '<li><a class="folder" href="'.$_SERVER['PHP_SELF']."?directory=$dirkey".'">All Pictures</a></li>';
            
                    
          $output .= '</ul></div>';
                    
                }
              
          }
            else {
            
          $output .= '
                <h1>Import Photos</h1>'
          ;
                

                
          $upload_directory $config['basedir'] . 'uploads';
                if (!
          is_writable($upload_directory))
                    
          $output .= '<p class="errors">Your "Uploads" directory is NOT WRITABLE!  Use your FTP client to CHMOD the directory with the
                    proper permissions or your import may fail!</p>'
          ;
            
                
          $files get_files($upload_directory);
                
                
          // build a list of unique directories from the filenames
                
          $directories = array();

                foreach (
          $files as $file) {
                     
                     
          $dirname dirname($file);

                   
          $dirkey md5($dirname);
                     
                  
          // using md5 hashes for directory names allows for easier validation of given directory name
                  // and also allows us to work with international characters in directory names
                     
          if (!in_array($dirname$directories))
                             
          $directories[md5($dirname)] = $dirname;
                }

                if (
          count($files) == 0) {
                     
          $output .= '<div class="actions">No images found in the <b>/uploads/</b> directory.  
                     To mass import pictures into your gallery, simply:<ul>
                     <li><b>Open an FTP connection</b> to your website</li>
                       <li>Transfer photos you wish to publish to the <b>/uploads/</b> directory</li>           
                       <li>Optionally, you can create folders within that directory to import in groups</li></ul></div>'
          ;
                }

                
          // here we will check which group of pictures we are editing, grouped by directory
                
          if (!isset($_GET["directory"]) && count($directories) > 0) {
                    
          $output .= '<div class="actions">Choose a directory you wish to import from:';
                    
                    
          $output .= '<ul>';            
                    
                    foreach (
          $directories as $dirkey => $group) {
                        
          $output .= '<li><a class="folder" href="'.$_SERVER['PHP_SELF']."?directory=$dirkey".'">'.basename($group).'</a></li>';
                    }
            
                    
          $dirkey md5($upload_directory);
                    
          // $output .= '<li><a class="folder" href="'.$_SERVER['PHP_SELF'].'?directory='.$dirkey.'">All pictures</a></li>';
                    
          $output .= '</ul></div>';
                    
                }
                else {
                  
          // real_directory is the full path
                  // show_directory is what the user sees, it's relative so the directory structure of the server
                  // is not exposed
                  
          $show_directory "uploads";
                    if (isset(
          $_GET["directory"]) && isset($directories[$_GET["directory"]])) {
                      
          $real_directory $directories[$_GET["directory"]];
                      
          $show_directory .= substr($real_directory,strlen($upload_directory));
                  }
                    else {
                      
          $real_directory $upload_directory;
                    }
                    
                  
          $files get_files($real_directory);
                    
                    if (
          count($files) > 0
                      
          $output .= '<p class="actions">You are currently looking at <b>'.count($files).'</b> image(s) within the <b>
                                                  '
          .$show_directory.'</b> directory';

                
                    
          // check to make sure album is writable and readable, and issue warning
                    
          if (!is_writable($real_directory) || !is_readable($real_directory))
                        
          $output .= '<p class="actions">Warning: this directory does not have the proper permissions settings!  You must
                                    CHMOD 777 on this directory using your FTP software or import may fail.'
          ;    
                    
                    
                  
          $albums get_albums();
                  for(
          $i=0$i<count($files); $i++)  
                  {  
                          
          $file_key md5($files[$i]);
                      
          $relative_name substr($files[$i],strlen($upload_directory)+1);
                        if (
          $i == 0)
                        
          $output.= '<form id="uploadForm" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">
                                            <table><tr class="header"><td></td><td>Thumbnail</td><td>Filename</td><td>Caption</td></tr>'
          ;
                                        
                        
          // For each file within upload directory, list checkmark, thumbnail, caption box, album box
                        
          if ($counter%== 0$table_row_color "color-1";
                        else 
          $table_row_color "color-2";
                        
                        
          // start a new table row (alternating colors)
                        
          $output .= "<tr class=\"$table_row_color\">";
              
                      
          $thumbpath generate_thumb($config['basedir'].'uploads/'.$relative_name,"import",'small');
              
                            
          // generate XHTML with thumbnail and link to picture view.
                            
          $imgtag '<td><img class="photos" src="'.$thumbpath.'" /></td>';
                            
          $output .= '<td width="15"><input type="CHECKBOX" name="Selected[]" VALUE="'.$file_key.'" checked></td>';
                            
          $output .= $imgtag;
                            
          //$output .= '<input name="files[]" type="hidden" value="'.$file_key.'">'
                          
          $output .= '</td>';
                            
          $output .= '<td>'.basename($files[$i]).'</td>';
                            
          $output .= '<td><input size="100%" name="captions[' $file_key ']"></input></td>';
                          
          $output .= '<td><a href="delete.php?filename='.urlencode(basename($files[$i])).'&from_dir='.$_GET['directory'].'"><img src="delete.gif" border="0"></a></td>';
                            
          $counter++;
                  }  
                
                  if (
          count($files) != 0) {
                        
          $output .= '</table><a href="#" onclick="checkAll(document.getElementById(\'uploadForm\')); return false; ">Invert Checkbox Selection</a>'
                      
                      
          // here we can preselect some default options based on the structure of the import directory
                      // if pictures are within one directory, simply place the name of the album within the
                      // create new album selector and allow user to pick collection.
                      // if two levels deep, preselect appropriate existing album and collection
                      // or place album name in new box
                      
                      // break up directory name into parts
                      
          $directory_parts explode("/"$show_directory);
                      
                      
          // check if album exists
                      
          $collection_name $directory_parts[2];
                      
          $album_name $directory_parts[3];
              
                      
                      if (
          is_null($album_name)) // file is only one level deep, assume folder name is album name
                          
          $sql "SELECT id FROM ".$TABLE_PREFIX."albums WHERE name = '".$collection_name."'";
                      else 
                          
          $sql "SELECT id FROM ".$TABLE_PREFIX."albums WHERE name = '".$album_name."'";
                      
                      
                      
          $result run_query($sql);
                      
          $row mysql_fetch_assoc($result);
                      
                      if(!isset(
          $row['id'])) { // album doesn't exist, place in new album box
                          
          $existing "";
                          
          $new_album "CHECKED";
                          if (
          is_null($album_name))
                              
          $new_album_name $collection_name;
                          else
                              
          $new_album_name $album_name;
                      }
                      else {
                          
          $existing "CHECKED";
                          
          $new_album "";
                      }
                      
                      
          $output .=  '
                        <h1>Destination:</h1>
                        <table>
                        <tr><td>
                        <table><tr valign="middle"><td width="20"><input type="radio" name="destination_radio" 
                        value="existing" '
          .$existing.'></td><td>Existing Album</td></tr></table>
                        '
          .generate_albums_menu($albums,"single"$row['id']).'
                        <td><h3>OR</h3></td>
                        <td><table><tr valign="middle"><td width="20"><input onClick="var k=document.getElementsByName(\'new_album_name\');k[0].focus()" 
                        type="radio" name="destination_radio" 
                        value="new" '
          .$new_album.'></td><td>Create a New Album</td></table><table>
                        <tr valign="middle"><td width="120">New Album Name: </td><td width="160"><input type="text" 
                        name="new_album_name" value="'
          .$new_album_name.'"> 
                        <td width="90">In collection:</td><td>
                          '
          .generate_collections_menu().'</td></tr></table></td><tr>
                        <td><br><input class="submit" type="submit" name="upload" value="Import" /></td></tr>
                        </table></div>'
          ;
                  
                      
          $output .= '</form>';
                  }
              }
          }


          $output_error '<h1>Import</h1><p class="actions">Before you can begin importing photos to your gallery, you must
          create at least <b>one collection</b> AND <b>one album</b> within that collection.  Move over to 
          the <a href="plog-manage.php">"Manage"</a> tab to begin creating your organizational structure</p>'
          ;

          $num_albums count_albums();

          if (
          $num_albums 0)
               
          display($output"import");
          else
               
          display($output_error"import");
               
          ?>
          Create a file in /admin/ called "delete.php" and put the following code in it
          PHP Code:
          <?php
          require("plog-globals.php");
          require_once(
          "../plog-load_config.php");
          require_once(
          "../plog-functions.php");
          include(
          "plog-admin-functions.php");
          global 
          $config;
          $dir $config['basedir'] . 'uploads';
          if(
          unlink($dir."/".urldecode($_GET['filename']))){ 
          echo 
          "<font face=verdana size=3 color=green><b>Successfully Deleted <em>".urldecode($_GET['filename'])."</em></b><br /><a href='plog-import.php?directory=".$_GET['from_dir']."'>Back</a></font>"
          }else{ 
          echo 
          "<font face=verdana size=3 color=red><b>ERROR: Could not remove file <em>".urldecode($_GET['filename'])."</em></b><br /><a href='plog-import.php?directory=".$_GET['from_dir']."'>Back</a></font>"

          ?>
          save this GIF as "delete.gif" and upload it to your /admin/ directory as well.



          This will add a "Delete" button for each image to the rightmost column on the page that displays the imported files.
          Last edited by boeing747fp; Oct 8, 2006, 08:57 PM.

          Comment


          • #6
            boeing747fp, thank you so much! it worked like a charm.
            Can't find enough words to thank you.

            Comment

            Working...
            X