plugins/gallery/upload.php
changeset 42 7c6e2e97aa08
parent 40 2607b83e986d
child 43 7df4993be0b0
equal deleted inserted replaced
41:0944c9354e9c 42:7c6e2e97aa08
    18 
    18 
    19 $plugins->attachHook('session_started', 'register_special_page("GalleryUpload", "Image gallery upload");');
    19 $plugins->attachHook('session_started', 'register_special_page("GalleryUpload", "Image gallery upload");');
    20 
    20 
    21 function page_Special_GalleryUpload()
    21 function page_Special_GalleryUpload()
    22 {
    22 {
    23   global $db, $session, $paths, $template, $plugins; // Common objects
    23 	global $db, $session, $paths, $template, $plugins; // Common objects
    24   
    24 	
    25   if ( $session->user_level < USER_LEVEL_ADMIN )
    25 	if ( $session->user_level < USER_LEVEL_ADMIN )
    26   {
    26 	{
    27     die_friendly('Access denied', '<p>You need to have administrative rights to use the gallery\'s upload features.</p>');
    27 		die_friendly('Access denied', '<p>You need to have administrative rights to use the gallery\'s upload features.</p>');
    28   }
    28 	}
    29   
    29 	
    30   $zip_support = ( class_exists('ZipArchive') || ( file_exists('/usr/bin/unzip') && is_executable('/usr/bin/unzip') ) );
    30 	$zip_support = ( class_exists('ZipArchive') || ( file_exists('/usr/bin/unzip') && is_executable('/usr/bin/unzip') ) );
    31   
    31 	
    32   $errors = array();
    32 	$errors = array();
    33   $template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/gallery/dropdown.css" />');
    33 	$template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/gallery/dropdown.css" />');
    34   $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/gallery/gallery-bits.js"></script>');
    34 	$template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/gallery/gallery-bits.js"></script>');
    35   
    35 	
    36   $max_size = @ini_get('upload_max_filesize');
    36 	$max_size_field = get_max_size_field();
    37   $max_size_field = '';
    37 	
    38   if ( $max_size )
    38 	//
    39   {
    39 	// EDIT IMAGES
    40     if ( preg_match('/M$/i', $max_size) )
    40 	//  
    41     {
    41 	if ( isset($_GET['edit_img']) )
    42       $max_size = intval($max_size) * 1048576;
    42 	{
    43     }
    43 		$edit_parms = $_GET['edit_img'];
    44     else if ( preg_match('/K$/i', $max_size) )
    44 		$regex = '/^((([0-9]+),)*)?([0-9]+?)$/';
    45     {
    45 		if ( !preg_match($regex, $edit_parms) )
    46       $max_size = intval($max_size) * 1024;
    46 		{
    47     }
    47 			die_friendly('Bad request', '<p>$_GET[\'edit_img\'] must be a comma-separated list of image IDs.</p>');
    48     else if ( preg_match('/G$/i', $max_size) )
    48 		}
    49     {
    49 		
    50       $max_size = intval($max_size) * 1048576 * 1024;
    50 		// process any uploaded images
    51     }
    51 		// FIXME is this a bad place for this?
    52     $max_size = intval($max_size);
    52 		$limit = isset($_GET['ajax']) ? '' : "LIMIT 5";
    53     $max_size_field = "\n" . '<input type="hidden" name="MAX_FILE_SIZE" value="' . $max_size . '" />' . "\n";
    53 		$q = $db->sql_query('SELECT img_id FROM ' . table_prefix . "gallery WHERE is_folder = 0 AND processed = 0 $limit;");
    54   }
    54 		if ( !$q )
    55   
    55 			$db->_die();
    56   if ( isset($_GET['edit_img']) )
    56 		if ( $db->numrows() > 0 )
    57   {
    57 		{
    58     $edit_parms = $_GET['edit_img'];
    58 			while ( $row = $db->fetchrow($q) )
    59     $regex = '/^((([0-9]+),)*)?([0-9]+?)$/';
    59 			{
    60     if ( !preg_match($regex, $edit_parms) )
    60 				snapr_process_image($row['img_id']);
    61     {
    61 			}
    62       die_friendly('Bad request', '<p>$_GET[\'edit_img\'] must be a comma-separated list of image IDs.</p>');
    62 			$q = $db->sql_query('SELECT COUNT(img_id) FROM ' . table_prefix . "gallery WHERE is_folder = 0 AND processed = 0;");
    63     }
    63 			if ( !$q )
    64     
    64 				$db->_die();
    65     $idlist = explode(',', $edit_parms);
    65 			list($count) = $db->fetchrow_num();
    66     $num_edit = count($idlist);
    66 			$db->free_result();
    67     $idlist = "SELECT img_id,img_title,img_desc,img_filename,is_folder FROM ".table_prefix."gallery WHERE img_id=" . implode(' OR img_id=', $idlist) . ';';
    67 			if ( intval($count) > 0 )
    68     
    68 			redirect(makeUrlNS('Special', 'GalleryUpload', "edit_img={$_GET['edit_img']}"), "Processing images", "Processing images... $count remaining", 1);
    69     if ( !$e = $db->sql_query($idlist) )
    69 		}
    70       $db->_die();
    70 		
    71     
    71 		if ( !isset($_GET['ajax']) )
    72     $template->header();
    72 			$template->header();
    73     
    73 		
    74     if ( isset($_POST['edit_do_save']) )
    74 		snapr_editform($edit_parms);
    75     {
    75 		
    76       @set_time_limit(0);
    76 		if ( !isset($_GET['ajax']) )
    77       
    77 			$template->footer();
    78       $arr_img_data = array();
    78 		
    79       while ( $row = $db->fetchrow($e) )
    79 		return;
    80         $arr_img_data[$row['img_id']] = $row;
    80 	}
    81       
    81 	//
    82       // Allow breaking out
    82 	// REMOVE IMAGES
    83       switch(true):case true:
    83 	// 
    84         
    84 	else if ( isset($_GET['rm']) )
    85         if ( !is_array($_POST['img']) )
    85 	{
    86         {
    86 		$warnings = array();
    87           $errors[] = 'No images passed to processor.';
    87 		
    88           break;
    88 		if ( !preg_match('/^[0-9]+$/', $_GET['rm']) )
    89         }
    89 			die_friendly('Bad Request', '<p>$_GET[rm] needs to be an integer.</p>');
    90         
    90 		
    91         // Main updater loop
    91 		$rm_id = intval($_GET['rm']);
    92         foreach ( $_POST['img'] as $img_id => $img_data )
    92 		
    93         {
    93 		if ( isset($_POST['confirmed']) )
    94           
    94 		{
    95           if ( !preg_match('/^[0-9]+$/', $img_id) )
    95 			// The user confirmed the request. Start plowing through data to decide what to delete.
    96           {
    96 			
    97             $errors[] = 'SQL injection attempted!';
    97 			// Array of images and folder rows to delete
    98             break 2;
    98 			$del_imgs = array($rm_id);
    99           }
    99 			// Array of files to delete
   100           
   100 			$del_files = array();
   101           // Array of columns to update
   101 			// Array of comment entries to delete
   102           $to_update = array();
   102 			$del_comments = array();
   103           
   103 			
   104           $key = 'reupload_' . $img_data['id'];
   104 			$all_children = gal_fetch_all_children($rm_id);
   105           if ( isset($_FILES[$key]) )
   105 			$del_imgs = array_merge($del_imgs, $all_children);
   106           {
   106 			
   107             $file =& $_FILES[ $key ];
   107 			$imglist = 'img_id=' . implode(' OR img_id=', $del_imgs);
   108             if ( $file['tmp_name'] != '' )
   108 			$sql = "SELECT img_id, img_filename FROM ".table_prefix."gallery WHERE ( $imglist ) AND is_folder!=1;";
   109             {
   109 			
   110               // Reupload
   110 			if ( !$db->sql_query($sql) )
   111               $filename = ENANO_ROOT . '/files/' . $arr_img_data[ $img_data['id'] ]['img_filename'];
   111 			{
   112               if ( !unlink($filename) )
   112 				$db->_die();
   113               {
   113 			}
   114                 $errors[] = "Could not delete $filename";
   114 			
   115                 break 2;
   115 			while ( $row = $db->fetchrow() )
   116               }
   116 			{
   117               if ( !@move_uploaded_file($file['tmp_name'], $filename) )
   117 				$files = array(
   118               {
   118 						ENANO_ROOT . '/files/' . $row['img_filename'],
   119                 $errors[] = "Could not move uploaded file to $filename";
   119 						ENANO_ROOT . '/cache/' . $row['img_filename'] . '-thumb.jpg',
   120                 break 2;
   120 						ENANO_ROOT . '/cache/' . $row['img_filename'] . '-preview.jpg'
   121               }
   121 					);
   122               
   122 				$del_files = array_merge($del_files, $files);
   123               //
   123 				
   124               // Create scaled images
   124 				$del_comments[] = intval($row['img_id']);
   125               //
   125 			}
   126               
   126 			
   127               // Create thumbnail image
   127 			$commentlist = 'page_id=\'' . implode('\' OR page_id=\'', $del_imgs) . '\'';
   128               $thumb_filename = ENANO_ROOT . '/cache/' . $arr_img_data[ $img_data['id'] ]['img_filename'] . '-thumb.jpg';
   128 			
   129               if ( !unlink($thumb_filename) )
   129 			// Main deletion cycle
   130               {
   130 			
   131                 $errors[] = "Could not delete $thumb_filename";
   131 			foreach ( $del_files as $file )
   132                 break 2;
   132 			{
   133               }
   133 				@unlink($file) or $warnings[] = 'Could not delete file ' . $file;
   134               
   134 			}
   135               if ( !scale_image($filename, $thumb_filename, 80, 80) )
   135 			
   136               {
   136 			if ( !$db->sql_query('DELETE FROM '.table_prefix.'gallery WHERE ' . $imglist . ';') )
   137                 $errors[] = 'Couldn\'t scale image '.$i.': ImageMagick failed us';
   137 			{
   138                 break 2;
   138 				$warnings[] = 'Main delete query failed: ' . $db->get_error();
   139               }
   139 			}
   140               
   140 			
   141               // Create preview image
   141 			if ( !$db->sql_query('DELETE FROM '.table_prefix.'comments WHERE ( ' . $commentlist . ' ) AND namespace=\'Gallery\';') )
   142               $preview_filename = ENANO_ROOT . '/cache/' . $arr_img_data[ $img_data['id'] ]['img_filename'] . '-preview.jpg';
   142 			{
   143               if ( !unlink($preview_filename) )
   143 				$warnings[] = 'Comment delete query failed: ' . $db->get_error();
   144               {
   144 			}
   145                 $errors[] = "Could not delete $preview_filename";
   145 			
   146                 break 2;
   146 			if ( count($warnings) > 0 )
   147               }
   147 			{
   148               
   148 				$template->header();
   149               if ( !scale_image($filename, $preview_filename, 640, 480) )
   149 				
   150               {
   150 				echo '<h3>Error during deletion process</h3>';
   151                 $errors[] = 'Couldn\'t scale image '.$i.': ImageMagick failed us';
   151 				echo '<p>The deletion process generated some warnings which are shown below.</p>';
   152                 break 2;
   152 				echo '<ul><li>' . implode('</li><li>', $warnings) . '</li></ul>';
   153               }
   153 				
   154               
   154 				$template->footer();
   155               $to_update['img_time_mod'] = strval(time());
   155 			}
   156             }
   156 			else
   157           }
   157 			{
   158           
   158 				redirect(makeUrlNS('Special', 'Gallery'), 'Deletion successful', 'The selected item has been deleted from the gallery. You will now be transferred to the gallery index.', 2);
   159           $vars = array(
   159 			}
   160             'year' => date('Y'),
   160 			
   161             'month' => date('F'),
   161 		}
   162             'day' => date('d'),
   162 		else
   163             'time12' => date('g:i A'),
   163 		{
   164             'time24' => date('G:i')
   164 			// Removal form
   165           );
   165 			$template->header();
   166           
   166 			
   167           // Image name/title
   167 			echo '<form action="' . makeUrlNS('Special', 'GalleryUpload', 'rm=' . $rm_id, true) . '" method="post" enctype="multipart/form-data">';
   168           
   168 			echo $max_size_field;
   169           $title = $template->makeParserText($img_data['title']);
   169 			
   170           $title->assign_vars($vars);
   170 			echo '<h3>Are you sure you want to delete this item?</h3>';
   171           $executed = $title->run();
   171 			echo '<p>If you continue, this item will be permanently deleted from the gallery &ndash; no rollbacks.</p>';
   172           if ( $executed == '_id' )
   172 			echo '<p>If this is an image, the image files will be removed from the filesystem, and all comments associated with the image will be deleted, as well as the image\'s title, description, and location.</p>';
   173           {
   173 			echo '<p>If this is a folder, all of its contents will be removed. Any images will be removed from the filesystem and all comments and metadata associated with images in this folder or any folders in it will be permanently deleted.</p>';
   174             $errors[] = 'You cannot name an image or folder "_id", this name is reserved for internal functions.';
   174 			
   175             break 2;
   175 			echo '<p><input type="submit" name="confirmed" value="Continue with delete" /></p>';
   176           }
   176 			
   177           if ( $executed == '' )
   177 			echo '</form>';
   178           {
   178 			
   179             $errors[] = 'Please enter a name for the item with unique ID ' . $img_data['id'] . '. <pre>' . print_r($_POST,true) . '</pre>';
   179 			$template->footer();
   180             break 2;
   180 		}
   181           }
   181 		return;
   182           $to_update['img_title'] = $executed;
   182 	}
   183           
   183 	else if ( isset($_GET['ajax_proc_status']) )
   184           // Image description
   184 	{
   185           
   185 		$q = $db->sql_query("SELECT COUNT(img_id) FROM " . table_prefix . "gallery WHERE processed = 0;");
   186           if ( isset($img_data['desc']) )
   186 		if ( !$q )
   187           {
   187 			$db->_die();
   188             $desc = $template->makeParserText($img_data['desc']);
   188 		list($count) = $db->fetchrow_num();
   189             $desc->assign_vars($vars);
   189 		echo $count;
   190             $executed = $desc->run();
   190 		return;
   191             $executed = RenderMan::preprocess_text($executed, false, false);
   191 	}
   192             $to_update['img_desc'] = $executed;
   192 	else
   193           }
   193 	{
   194           
   194 		if ( isset($_POST['do_upload']) )
   195           // Folder
   195 		{
   196           $target_folder = false;
   196 			$files =& $_FILES['files'];
   197           
   197 			$numfiles = count($files['name']);
   198           if ( !empty($_POST['override_folder']) )
   198 			$idlist = array();
   199           {
   199 			$destfolder = intval($_POST['targetfolder']);
   200             if ( $_POST['override_folder'] == 'NULL' || preg_match('/^[0-9]+$/', $_POST['override_folder']) )
   200 			if ( $destfolder < 1 )
   201             {
   201 				$destfolder = NULL;
   202               $target_folder = $_POST['override_folder'];
   202 			for ( $i = 0; $i < $numfiles; $i++ )
   203             }
   203 			{
   204           }
   204 				$ext = get_file_extension($files['name'][$i]);
   205           
   205 				if ( snapr_extension_allowed($ext) )
   206           if ( !empty($img_data['folder']) )
   206 				{
   207           {
   207 					// normal image
   208             if ( $img_data['folder'] == 'NULL' || preg_match('/^[0-9]+$/', $img_data['folder']) )
   208 					$result = snapr_insert_image($files['tmp_name'][$i], $destfolder);
   209             {
   209 					if ( $result !== false )
   210               $target_folder = $img_data['folder'];
   210 						$idlist[] = $result;
   211             }
   211 				}
   212           }
   212 				else if ( strtolower($ext) == 'zip' )
   213           
   213 				{
   214           if ( $target_folder )
   214 					// zip file
   215           {
   215 					$zipidlist = snapr_process_zip($files['tmp_name'][$i], $destfolder);
   216             // Make sure we're not trying to move a folder to itself or a subdirectory of itself
   216 					if ( $zipidlist )
   217             
   217 						$idlist = array_merge($idlist, $zipidlist);
   218             $children = gal_fetch_all_children(intval($img_data['id']));
   218 				}
   219             if ( $img_data['id'] == $target_folder || in_array($target_folder, $children) )
   219 				else
   220             {
   220 				{
   221               $errors[] = 'You are trying to move a folder to itself, or to a subdirectory of itself, which is not allowed. If done manually (i.e. via an SQL client) this will result in infinite loops in the folder sorting code.';
   221 					// FIXME handle unsupported files... maybe?
   222               break 2;
   222 				}
   223             }
   223 			}
   224             
   224 			$idlist = implode(',', $idlist);
   225             $to_update['folder_parent'] = $target_folder;
   225 			echo '<div class="idlist">[' . $idlist . ']</div>';
   226           }
   226 			//snapr_editform($idlist);
   227           
   227 			return;
   228           if ( count($to_update) > 0 )
   228 		}
   229           {
   229 		
   230             $up_keys = array_keys($to_update);
   230 		// Oh yes, the image uploader!
   231             $up_vals = array_values($to_update);
   231 		$template->preload_js(array('jquery', 'jquery-ui', 'upload'));
   232             
   232 		$template->header();
   233             $bin_cols = array('folder_parent');
   233 		
   234             
   234 		?>
   235             $sql = 'UPDATE ' . table_prefix.'gallery SET ';
   235 		<form action="" method="post" enctype="multipart/form-data" id="snaprupload">
   236             
   236 		
   237             foreach ( $up_keys as $i => $key )
   237 		<script type="text/javascript">
   238             {
   238 		//<![CDATA[
   239               if ( in_array($key, $bin_cols) )
   239 		addOnloadHook(function()
   240               {
   240 			{
   241                 $sql .= $key . '=' . $up_vals[$i] . ',';
   241 				attachHook('snaprupload_ajaxupload_init', 'snapr_upload_init(ajaxupload);');
   242               }
   242 			});
   243               else
   243 		function snapr_upload_init(au)
   244               {
   244 		{
   245                 $sql .= $key . '=\'' . $db->escape($up_vals[$i]) . '\',';
   245 			au.upload_start = function()
   246               }
   246 			{
   247             }
   247 				$(this.form).hide();
   248             
   248 				$(this.statusbox).html('<h2 class="uploadgoing">Uploading pictures...</h2><div class="progress" style="margin: 15px 0;"></div><p class="uploadstatus">&nbsp;</p>');
   249             $sql = preg_replace('/,$/i', '', $sql) . ' WHERE img_id=' . $img_data['id'] . ';';
   249 				$('div.progress', this.statusbox).progressbar({value: 0});
   250             
   250 			};
   251             if ( !$db->sql_query($sql) )
   251 			
   252             {
   252 			au.status = function(state)
   253               $db->_die();
   253 			{
   254             }
   254 				if ( !state.done && !state.cancel_upload )
   255             
   255 				{
   256           }
   256 					var rawpct = state.bytes_processed / state.content_length;
   257           
   257 					var pct = (Math.round((rawpct) * 1000)) / 10;
   258         }
   258 					var elapsed = state.current_time - state.start_time;
   259         
   259 					var rawbps = state.bytes_processed / elapsed;
   260         echo '<div class="info-box" style="margin-left: 0;">Your changes have been saved.</div>';
   260 					var kbps = Math.round((rawbps) / 1024);
   261         
   261 					var remain_bytes = state.content_length - state.bytes_processed;
   262       endswitch;
   262 					var remain_time = Math.round(remain_bytes / rawbps);
   263       
   263 					
   264       // Rerun select query to make sure information in PHP memory is up-to-date
   264 					$('p.uploadstatus', this.statusbox).html(pct + '% complete / ' + kbps + ' KB/s / ' + humanize_time(elapsed) + ' elapsed / ' + humanize_time(remain_time) + ' remaining');
   265       if ( !$e = $db->sql_query($idlist) )
   265 					$('div.progress', this.statusbox).progressbar('value', pct);
   266         $db->_die();
   266 				}
   267       
   267 			};
   268     }
   268 			
   269     
   269 			au.upload_success = function(childbody)
   270     if ( count($errors) > 0 )
   270 			{
   271     {
   271 				$(this.statusbox).html('<div class="info-box"></div>' + childbody.innerHTML);
   272       echo '<div class="error-box" style="margin-left: 0;">
   272 				var idlist = parseJSON($('div.idlist', this.statusbox).text());
   273               <b>The following errors were encountered while updating the image data:</b><br />
   273 				$('div.idlist', this.statusbox).remove();
   274               <ul>
   274 				var s = idlist.length == 1 ? '' : 's';
   275                 <li>' . implode("</li>\n        <li>", $errors) . '</li>
   275 				$('div.info-box', this.statusbox).html(idlist.length + ' image'+s+' were uploaded successfully. Please wait while they are processed...');
   276               </ul>
   276 				$(this.statusbox).append('<div class="progress" style="margin: 15px 0;"></div><p class="uploadstatus">&nbsp;</p>');
   277             </div>';
   277 				$('div.progress', this.statusbox).progressbar({value: 0});
   278     }
   278 				var au = this;
   279     
   279 				ajaxGet(makeUrlNS('Special', 'GalleryUpload', 'edit_img=' + implode(',', idlist) + '&ajax=true'), function(ajax)
   280     ?>
   280 					{
   281     <script type="text/javascript">
   281 						if ( ajax.readyState == 4 )
   282     
   282 						{
   283       function gal_unset_radios(name)
   283 							window.clearTimeout(snapr_refresh_timer);
   284       {
   284 							$(au.statusbox).html(ajax.responseText);
   285         var radios = document.getElementsByTagName('input');
   285 						}
   286         for ( var i = 0; i < radios.length; i++ )
   286 					});
   287         {
   287 				snapr_refresh_proc(au, idlist);
   288           var radio = radios[i];
   288 			};
   289           if ( radio.name == name )
   289 		}
   290           {
   290 		
   291             radio.checked = false;
   291 		window.snapr_refresh_timer = false;
   292           }
   292 		
   293         }
   293 		function snapr_refresh_proc(au, idlist)
   294       }
   294 		{
   295     
   295 			void(au);
   296     </script>
   296 			void(idlist);
   297     <?php
   297 			ajaxGet(makeUrlNS('Special', 'GalleryUpload', 'ajax_proc_status'), function(ajax)
   298     
   298 				{
   299     echo '<form action="' . makeUrlNS('Special', 'GalleryUpload', 'edit_img=' . $edit_parms, true) . '" method="post" enctype="multipart/form-data">';
   299 					if ( ajax.readyState == 4 )
   300     
   300 					{
   301     echo $max_size_field;
   301 						var n = idlist.length - Number(ajax.responseText);
   302     
   302 						var pct = (n / idlist.length) * 100;
   303     if ( $row = $db->fetchrow($e) )
   303 						$('div.progress', au.statusbox).progressbar('value', pct);
   304     {
   304 						$('p.uploadstatus', au.statusbox).html(n + " of " + idlist.length + " images processed");
   305       
   305 						if ( pct < 100 )
   306       echo '<div class="tblholder">
   306 							window.snapr_refresh_timer = setTimeout(function()
   307               <table border="0" cellspacing="1" cellpadding="4">';
   307 								{
   308       echo '    <tr><th class="subhead">Information</th></tr>';
   308 									snapr_refresh_proc(au, idlist);
   309       echo '    <tr><td class="row3">
   309 								}, 1000);
   310                   As with the upload form, the following variables can be used. <b>Note that when editing images, the {id} and {autotitle} variables will be ignored.</b>';
   310 					}
   311       ?>
   311 				});
   312           <ul>
   312 		}
   313             <li>{year}: The current year (<?php echo date('Y'); ?>)</li>
   313 		//]]>
   314             <li>{month}: The current month (<?php echo date('F'); ?>)</li>
   314 		</script>
   315             <li>{day}: The day of the month (<?php echo date('d'); ?>)</li>
   315 		<?php ajax_upload_js('snaprupload'); ?>
   316             <li>{time12}: 12-hour time (<?php echo date('g:i A'); ?>)</li>
   316 		
   317             <li>{time24}: 24-hour time (<?php echo date('G:i'); ?>)</li>
   317 		<div class="tblholder">
   318           </ul>
   318 			<table border="0" cellspacing="1" cellpadding="4">
   319       <?php
   319 				<tr>
   320       echo '        </td></tr>';
   320 					<th colspan="2">Upload files to the gallery</th>
   321       echo '  </table>
   321 				</tr>
   322             </div>';
   322 				<tr>
   323       
   323 					<td class="row1">
   324       $i = 0;
   324 						Select files:
   325       do
   325 					</td>
   326       {
   326 					<td class="row1">
   327         $thumb_url = makeUrlNS('Special', 'GalleryFetcher/thumb/' . $row['img_id'], false, true);
   327 						<input type="hidden" name="do_upload" value="yes" />
   328         
   328 						<input type="file" size="50" name="files[]" />
   329         # Type: folder
   329 						<input type="button" class="addanother" value="+" />
   330         if ( $row['is_folder'] == 1 ):
   330 					</td>
   331         
   331 				</tr>
   332         // Image ID tracker
   332 				<tr>
   333         echo '<input type="hidden" name="img[' . $i . '][id]" value="' . $row['img_id'] . '" />';
   333 					<td class="row2">
   334         
   334 						Upload into folder:
   335         //
   335 					</td>
   336         // Editor table
   336 					<td class="row2">
   337         //
   337 					<?php echo gallery_hier_formfield('targetfolder', true); ?>
   338         
   338 					</td>
   339         $folders = gallery_imgid_to_folder(intval($row['img_id']));
   339 				</tr>
   340         foreach ( $folders as $j => $xxx )
   340 				<tr>
   341         {
   341 					<td class="row3" colspan="2" style="text-align: center; line-height: 24px;">
   342           $folder =& $folders[$j];
   342 						<strong>Supported formats:</strong>
   343           $folder = sanitize_page_id($folder);
   343 						<br />
   344         }
   344 						
   345         $folders = array_reverse($folders);
   345 						<img alt="Checkmark" src="<?php echo cdnPath; ?>/images/check.png" style="vertical-align: middle;" /> JPEG images &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   346         $gal_href = implode('/', $folders) . ( count($folders) > 0 ? '/' : '' ) . sanitize_page_id($row['img_title']);
   346 						<img alt="Checkmark" src="<?php echo cdnPath; ?>/images/check.png" style="vertical-align: middle;" /> PNG images &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   347         
   347 						<img alt="Checkmark" src="<?php echo cdnPath; ?>/images/check.png" style="vertical-align: middle;" /> GIF images &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   348         echo '<div class="tblholder">
   348 						<?php if ( $zip_support ): ?>
   349                 <table border="0" cellspacing="1" cellpadding="4">';
   349 						<img alt="Checkmark" src="<?php echo cdnPath; ?>/images/check.png" style="vertical-align: middle;" /> Zip archives
   350         
   350 						<?php else: ?>
   351         echo '<tr><th colspan="2">Folder: ' . htmlspecialchars($row['img_title']) . '</th></tr>';
   351 						<img alt="X mark" src="<?php echo cdnPath; ?>/images/checkbad.png" style="vertical-align: middle;" /> Zip archives
   352         
   352 						<?php endif; ?><br />
   353         // Primary key
   353 						<small>Maximum file size: <strong><?php echo ini_get('upload_max_filesize'); ?></strong></small>
   354         echo '<tr>
   354 						<?php echo $max_size_field; ?>
   355                 <td class="row2">Unique ID:</td>
   355 					</td>
   356                 <td class="row1">' . $row['img_id'] . ' (<a href="' . makeUrlNS('Special', 'Gallery/' . $gal_href) . '">view folder contents</a>)</td>
   356 				</tr>
   357               </tr>';
   357 				<tr>
   358               
   358 					<th colspan="2" class="subhead">
   359         // Path info
   359 						<input type="submit" value="Upload" />
   360         echo '<tr>
   360 					</th>
   361                 <td class="row2">Parent folders:</td>
   361 				</tr>
   362                 <td class="row1">' . /* Yeah it's dirty, but hey, it gets the job done ;-) */ ( ( $x = str_replace('&amp;raquo;', '&raquo;', htmlspecialchars(str_replace('_', ' ', implode(' &raquo; ', $folders)))) ) ? $x : '&lt;in root&gt;' ) . '</td>
   362 			</table>
   363               </tr>';
   363 		</div>
   364         
   364 		</form>
   365         // Image name
   365 		<script type="text/javascript">
   366         
   366 		// <![CDATA[
   367         echo '<tr>
   367 		addOnloadHook(function()
   368                 <td class="row2">Folder name:</td>
   368 			{
   369                 <td class="row1"><input type="text" style="width: 98%;" name="img[' . $i . '][title]" value="' . htmlspecialchars($row['img_title']) . '" size="43" /></td>
   369 				$('input.addanother').click(function()
   370               </tr>';
   370 					{
   371               
   371 						$(this).before('<br />');
   372         // Mover widget
   372 						var inp = document.createElement('input');
   373         ?>
   373 						$(inp).attr('type', 'file').attr('size', '50').attr('name', 'files[]');
   374         <tr>
   374 						this.parentNode.insertBefore(inp, this);
   375           <td class="row2">Move to folder:</td>
   375 						$(this).before(' ');
   376           <td class="row1">
   376 						return false;
   377             <div class="toggle">
   377 					});
   378               <div class="head" onclick="gal_toggle( ( IE ? this.nextSibling : this.nextSibling.nextSibling ), this.childNodes[1]);">
   378 			});
   379                 <img alt="&gt;&gt;" src="<?php echo scriptPath; ?>/plugins/gallery/toggle-closed.png" class="toggler" />
   379 		// ]]>
   380                 Select folder
   380 		</script>
   381               </div>
   381 		<?php
   382               <div class="body">
   382 	}
   383                 <?php
   383 	
   384                   echo gallery_hier_formfield('img[' . $i . '][folder]', false);
   384 	
   385                 ?>
   385 	$template->footer();
   386                 <br />
   386 	
   387                 <a href="#" onclick="gal_unset_radios('img[<?php echo $i; ?>][folder]'); return false;">Unselect field</a>
   387 }
   388               </div>
   388 
   389             </div>
   389 function snapr_editform($edit_parms)
   390           </td>
   390 {
   391         </tr>
   391 	global $db, $session, $paths, $template, $plugins; // Common objects
   392         <?php
   392 	
   393         
   393 	$max_size_field = get_max_size_field();
   394         // Finish table
   394 	$errors = array();
   395         echo '</table>';
   395 	$idlist = explode(',', $edit_parms);
   396         echo '</div>';
   396 	$num_edit = count($idlist);
   397         
   397 	$idlist = "SELECT img_id,img_title,img_desc,img_filename,is_folder FROM ".table_prefix."gallery WHERE img_id=" . implode(' OR img_id=', $idlist) . ';';
   398         # Type: image
   398 	
   399         else:
   399 	if ( !$e = $db->sql_query($idlist) )
   400         
   400 		$db->_die();
   401         // Image ID tracker
   401 	
   402         echo '<input type="hidden" name="img[' . $i . '][id]" value="' . $row['img_id'] . '" />';
   402 	if ( isset($_POST['edit_do_save']) )
   403         
   403 	{
   404         //
   404 		@set_time_limit(0);
   405         // Editor table
   405 		
   406         //
   406 		$arr_img_data = array();
   407         
   407 		while ( $row = $db->fetchrow($e) )
   408         echo '<div class="tblholder">
   408 			$arr_img_data[$row['img_id']] = $row;
   409                 <table border="0" cellspacing="1" cellpadding="4">';
   409 		
   410         
   410 		// Allow breaking out
   411         echo '<tr><th colspan="2">Image: ' . htmlspecialchars($row['img_title']) . '</th></tr>';
   411 		switch(true):case true:
   412         
   412 			
   413         // Primary key
   413 			if ( !is_array($_POST['img']) )
   414         echo '<tr>
   414 			{
   415                 <td class="row2">Unique ID:</td>
   415 				$errors[] = 'No images passed to processor.';
   416                 <td class="row1">' . $row['img_id'] . ' (<a href="' . makeUrlNS('Gallery', $row['img_id']) . '">view image\'s page</a>)</td>
   416 				break;
   417               </tr>';
   417 			}
   418               
   418 			
   419         // Thumbnail
   419 			// Main updater loop
   420         
   420 			foreach ( $_POST['img'] as $img_id => $img_data )
   421         echo '<tr>
   421 			{
   422                 <td class="row2">Thumbnail:</td>
   422 				
   423                 <td class="row1"><img alt="Thumbnail image" src="' . $thumb_url . '" /></td>
   423 				if ( !preg_match('/^[0-9]+$/', $img_id) )
   424               </tr>';
   424 				{
   425         
   425 					$errors[] = 'SQL injection attempted!';
   426         // Image name
   426 					break 2;
   427         
   427 				}
   428         echo '<tr>
   428 				
   429                 <td class="row2">Image title:</td>
   429 				// Array of columns to update
   430                 <td class="row1"><input type="text" style="width: 98%;" name="img[' . $i . '][title]" value="' . htmlspecialchars($row['img_title']) . '" size="43" /></td>
   430 				$to_update = array();
   431               </tr>';
   431 				
   432               
   432 				$key = 'reupload_' . $img_data['id'];
   433         // Image description
   433 				if ( isset($_FILES[$key]) )
   434         
   434 				{
   435         echo '<tr>
   435 					$file =& $_FILES[ $key ];
   436                 <td class="row2">Image description:</td>
   436 					if ( $file['tmp_name'] != '' )
   437                 <td class="row1"><textarea rows="10" cols="40" style="width: 98%;" name="img[' . $i . '][desc]">' . htmlspecialchars($row['img_desc']) . '</textarea></td>
   437 					{
   438               </tr>';
   438 						// Reupload
   439               
   439 						$filename = ENANO_ROOT . '/files/' . $arr_img_data[ $img_data['id'] ]['img_filename'];
   440         // ACL editor trigger
   440 						if ( !unlink($filename) )
   441         
   441 						{
   442         echo '<tr>
   442 							$errors[] = "Could not delete $filename";
   443                 <td class="row2">Permissions:</td>
   443 							break 2;
   444                 <td class="row1"><input type="button" onclick="ajaxOpenACLManager(\'' . $row['img_id'] . '\', \'Gallery\');" value="Edit permissions" /><br /><small>Only works in Firefox 1.5 or later, Safari 3.x or later, or Opera 9.0 or later.</small></td>
   444 						}
   445               </tr>';
   445 						if ( !@move_uploaded_file($file['tmp_name'], $filename) )
   446               
   446 						{
   447         // Mover widget
   447 							$errors[] = "Could not move uploaded file to $filename";
   448         ?>
   448 							break 2;
   449         <tr>
   449 						}
   450           <td class="row2">Move to folder:</td>
   450 						
   451           <td class="row1">
   451 						//
   452             <div class="toggle">
   452 						// Create scaled images
   453               <div class="head" onclick="gal_toggle( ( IE ? this.nextSibling : this.nextSibling.nextSibling ), this.childNodes[1]);">
   453 						//
   454                 <img alt="&gt;&gt;" src="<?php echo scriptPath; ?>/plugins/gallery/toggle-closed.png" class="toggler" />
   454 						
   455                 Select folder
   455 						// Create thumbnail image
   456               </div>
   456 						$thumb_filename = ENANO_ROOT . '/cache/' . $arr_img_data[ $img_data['id'] ]['img_filename'] . '-thumb.jpg';
   457               <div class="body">
   457 						if ( !unlink($thumb_filename) )
   458                 <?php
   458 						{
   459                   echo gallery_hier_formfield('img[' . $i . '][folder]', false);
   459 							$errors[] = "Could not delete $thumb_filename";
   460                 ?>
   460 							break 2;
   461                 <br />
   461 						}
   462                 <a href="#" onclick="gal_unset_radios('img[<?php echo $i; ?>][folder]'); return false;">Unselect field</a>
   462 						
   463               </div>
   463 						if ( !scale_image($filename, $thumb_filename, 80, 80) )
   464             </div>
   464 						{
   465           </td>
   465 							$errors[] = 'Couldn\'t scale image '.$i.': ImageMagick failed us';
   466         </tr>
   466 							break 2;
   467         <?php
   467 						}
   468               
   468 						
   469         // File replacer
   469 						// Create preview image
   470         
   470 						$preview_filename = ENANO_ROOT . '/cache/' . $arr_img_data[ $img_data['id'] ]['img_filename'] . '-preview.jpg';
   471         echo '<tr>
   471 						if ( !unlink($preview_filename) )
   472                 <td class="row2">Upload new version:</td>
   472 						{
   473                 <td class="row1"><input type="file" name="reupload_' . $row['img_id'] . '" size="30" style="width: 98%;" /></td>
   473 							$errors[] = "Could not delete $preview_filename";
   474               </tr>';
   474 							break 2;
   475               
   475 						}
   476         // Finish table
   476 						
   477         echo '</table>';
   477 						if ( !scale_image($filename, $preview_filename, 640, 480) )
   478         echo '</div>';
   478 						{
   479         
   479 							$errors[] = 'Couldn\'t scale image '.$i.': ImageMagick failed us';
   480         endif;
   480 							break 2;
   481         
   481 						}
   482         $i++;
   482 						
   483       }
   483 						$to_update['img_time_mod'] = strval(time());
   484       while ( $row = $db->fetchrow($e) );
   484 					}
   485       $db->free_result();
   485 				}
   486       
   486 				
   487       echo '<div class="tblholder">
   487 				$vars = array(
   488               <table border="0" cellspacing="1" cellpadding="4">';
   488 					'year' => date('Y'),
   489       // Mover widget
   489 					'month' => date('F'),
   490       if ( $num_edit > 1 ):
   490 					'day' => date('d'),
   491       ?>
   491 					'time12' => date('g:i A'),
   492       <tr>
   492 					'time24' => date('G:i')
   493         <td class="row2">Move all to folder:<br /><small>Other folder fields on this page can override this for individual images.</small></td>
   493 				);
   494         <td class="row1" style="width: 70%;">
   494 				
   495           <div class="toggle">
   495 				// Image name/title
   496             <div class="head" onclick="gal_toggle( ( IE ? this.nextSibling : this.nextSibling.nextSibling ), this.childNodes[1]);">
   496 				
   497               <img alt="&gt;&gt;" src="<?php echo scriptPath; ?>/plugins/gallery/toggle-closed.png" class="toggler" />
   497 				$title = $template->makeParserText($img_data['title']);
   498               Select folder
   498 				$title->assign_vars($vars);
   499             </div>
   499 				$executed = $title->run();
   500             <div class="body">
   500 				if ( $executed == '_id' )
   501               <?php
   501 				{
   502                 echo gallery_hier_formfield('override_folder', false);
   502 					$errors[] = 'You cannot name an image or folder "_id", this name is reserved for internal functions.';
   503               ?>
   503 					break 2;
   504               <br />
   504 				}
   505               <a href="#" onclick="gal_unset_radios('override_folder'); return false;">Unselect field</a>
   505 				if ( $executed == '' )
   506             </div>
   506 				{
   507           </div>
   507 					$errors[] = 'Please enter a name for the item with unique ID ' . $img_data['id'] . '. <pre>' . print_r($_POST,true) . '</pre>';
   508         </td>
   508 					break 2;
   509       </tr>
   509 				}
   510       <?php
   510 				$to_update['img_title'] = $executed;
   511       endif;
   511 				
   512         
   512 				// Image description
   513       echo '    <tr><th class="subhead" colspan="2"><input type="submit" name="edit_do_save" value="Save changes" /></th></tr>';
   513 				
   514       echo '  </table>
   514 				if ( isset($img_data['desc']) )
   515             </div>';
   515 				{
   516       
   516 					$desc = $template->makeParserText($img_data['desc']);
   517     }
   517 					$desc->assign_vars($vars);
   518     else
   518 					$executed = $desc->run();
   519     {
   519 					$executed = RenderMan::preprocess_text($executed, false, false);
   520       echo '<p>No images that matched the ID list could be found.</p>';
   520 					$to_update['img_desc'] = $executed;
   521     }
   521 				}
   522     
   522 				
   523     echo '</form>';
   523 				// Folder
   524     
   524 				$target_folder = false;
   525     $template->footer();
   525 				
   526     return;
   526 				if ( !empty($_POST['override_folder']) )
   527   }
   527 				{
   528   
   528 					if ( $_POST['override_folder'] == 'NULL' || preg_match('/^[0-9]+$/', $_POST['override_folder']) )
   529   if ( isset($_GET['rm']) )
   529 					{
   530   {
   530 						$target_folder = $_POST['override_folder'];
   531     $warnings = array();
   531 					}
   532     
   532 				}
   533     if ( !preg_match('/^[0-9]+$/', $_GET['rm']) )
   533 				
   534       die_friendly('Bad Request', '<p>$_GET[rm] needs to be an integer.</p>');
   534 				if ( !empty($img_data['folder']) )
   535     
   535 				{
   536     $rm_id = intval($_GET['rm']);
   536 					if ( $img_data['folder'] == 'NULL' || preg_match('/^[0-9]+$/', $img_data['folder']) )
   537     
   537 					{
   538     if ( isset($_POST['confirmed']) )
   538 						$target_folder = $img_data['folder'];
   539     {
   539 					}
   540       // The user confirmed the request. Start plowing through data to decide what to delete.
   540 				}
   541       
   541 				
   542       // Array of images and folder rows to delete
   542 				if ( $target_folder )
   543       $del_imgs = array($rm_id);
   543 				{
   544       // Array of files to delete
   544 					// Make sure we're not trying to move a folder to itself or a subdirectory of itself
   545       $del_files = array();
   545 					
   546       // Array of comment entries to delete
   546 					$children = gal_fetch_all_children(intval($img_data['id']));
   547       $del_comments = array();
   547 					if ( $img_data['id'] == $target_folder || in_array($target_folder, $children) )
   548       
   548 					{
   549       $all_children = gal_fetch_all_children($rm_id);
   549 						$errors[] = 'You are trying to move a folder to itself, or to a subdirectory of itself, which is not allowed. If done manually (i.e. via an SQL client) this will result in infinite loops in the folder sorting code.';
   550       $del_imgs = array_merge($del_imgs, $all_children);
   550 						break 2;
   551       
   551 					}
   552       $imglist = 'img_id=' . implode(' OR img_id=', $del_imgs);
   552 					
   553       $sql = "SELECT img_id, img_filename FROM ".table_prefix."gallery WHERE ( $imglist ) AND is_folder!=1;";
   553 					$to_update['folder_parent'] = $target_folder;
   554       
   554 				}
   555       if ( !$db->sql_query($sql) )
   555 				
   556       {
   556 				if ( count($to_update) > 0 )
   557         $db->_die();
   557 				{
   558       }
   558 					$up_keys = array_keys($to_update);
   559       
   559 					$up_vals = array_values($to_update);
   560       while ( $row = $db->fetchrow() )
   560 					
   561       {
   561 					$bin_cols = array('folder_parent');
   562         $files = array(
   562 					
   563             ENANO_ROOT . '/files/' . $row['img_filename'],
   563 					$sql = 'UPDATE ' . table_prefix.'gallery SET ';
   564             ENANO_ROOT . '/cache/' . $row['img_filename'] . '-thumb.jpg',
   564 					
   565             ENANO_ROOT . '/cache/' . $row['img_filename'] . '-preview.jpg'
   565 					foreach ( $up_keys as $i => $key )
   566           );
   566 					{
   567         $del_files = array_merge($del_files, $files);
   567 						if ( in_array($key, $bin_cols) )
   568         
   568 						{
   569         $del_comments[] = intval($row['img_id']);
   569 							$sql .= $key . '=' . $up_vals[$i] . ',';
   570       }
   570 						}
   571       
   571 						else
   572       $commentlist = 'page_id=\'' . implode('\' OR page_id=\'', $del_imgs) . '\'';
   572 						{
   573       
   573 							$sql .= $key . '=\'' . $db->escape($up_vals[$i]) . '\',';
   574       // Main deletion cycle
   574 						}
   575       
   575 					}
   576       foreach ( $del_files as $file )
   576 					
   577       {
   577 					$sql = preg_replace('/,$/i', '', $sql) . ' WHERE img_id=' . $img_data['id'] . ';';
   578         @unlink($file) or $warnings[] = 'Could not delete file ' . $file;
   578 					
   579       }
   579 					if ( !$db->sql_query($sql) )
   580       
   580 					{
   581       if ( !$db->sql_query('DELETE FROM '.table_prefix.'gallery WHERE ' . $imglist . ';') )
   581 						$db->_die();
   582       {
   582 					}
   583         $warnings[] = 'Main delete query failed: ' . $db->get_error();
   583 					
   584       }
   584 				}
   585       
   585 				
   586       if ( !$db->sql_query('DELETE FROM '.table_prefix.'comments WHERE ( ' . $commentlist . ' ) AND namespace=\'Gallery\';') )
   586 			}
   587       {
   587 			
   588         $warnings[] = 'Comment delete query failed: ' . $db->get_error();
   588 			echo '<div class="info-box" style="margin-left: 0;">Your changes have been saved.</div>';
   589       }
   589 			
   590       
   590 		endswitch;
   591       if ( count($warnings) > 0 )
   591 		
   592       {
   592 		// Rerun select query to make sure information in PHP memory is up-to-date
   593         $template->header();
   593 		if ( !$e = $db->sql_query($idlist) )
   594         
   594 			$db->_die();
   595         echo '<h3>Error during deletion process</h3>';
   595 		
   596         echo '<p>The deletion process generated some warnings which are shown below.</p>';
   596 	}
   597         echo '<ul><li>' . implode('</li><li>', $warnings) . '</li></ul>';
   597 	
   598         
   598 	if ( count($errors) > 0 )
   599         $template->footer();
   599 	{
   600       }
   600 		echo '<div class="error-box" style="margin-left: 0;">
   601       else
   601 						<b>The following errors were encountered while updating the image data:</b><br />
   602       {
   602 						<ul>
   603         redirect(makeUrlNS('Special', 'Gallery'), 'Deletion successful', 'The selected item has been deleted from the gallery. You will now be transferred to the gallery index.', 2);
   603 							<li>' . implode("</li>\n        <li>", $errors) . '</li>
   604       }
   604 						</ul>
   605       
   605 					</div>';
   606     }
   606 	}
   607     else
   607 	
   608     {
   608 	echo '<form action="' . makeUrlNS('Special', 'GalleryUpload', 'edit_img=' . $edit_parms, true) . '" method="post" enctype="multipart/form-data">';
   609       // Removal form
   609 	
   610       $template->header();
   610 	echo $max_size_field;
   611       
   611 	
   612       echo '<form action="' . makeUrlNS('Special', 'GalleryUpload', 'rm=' . $rm_id, true) . '" method="post" enctype="multipart/form-data">';
   612 	if ( $row = $db->fetchrow($e) )
   613       echo $max_size_field;
   613 	{
   614       
   614 		
   615       echo '<h3>Are you sure you want to delete this item?</h3>';
   615 		echo '<div class="tblholder">
   616       echo '<p>If you continue, this item will be permanently deleted from the gallery &ndash; no rollbacks.</p>';
   616 						<table border="0" cellspacing="1" cellpadding="4">';
   617       echo '<p>If this is an image, the image files will be removed from the filesystem, and all comments associated with the image will be deleted, as well as the image\'s title, description, and location.</p>';
   617 		echo '    <tr><th class="subhead">Information</th></tr>';
   618       echo '<p>If this is a folder, all of its contents will be removed. Any images will be removed from the filesystem and all comments and metadata associated with images in this folder or any folders in it will be permanently deleted.</p>';
   618 		echo '    <tr><td class="row3">
   619       
   619 								As with the upload form, the following variables can be used. <b>Note that when editing images, the {id} and {autotitle} variables will be ignored.</b>';
   620       echo '<p><input type="submit" name="confirmed" value="Continue with delete" /></p>';
   620 		?>
   621       
   621 				<ul>
   622       echo '</form>';
   622 					<li>{year}: The current year (<?php echo date('Y'); ?>)</li>
   623       
   623 					<li>{month}: The current month (<?php echo date('F'); ?>)</li>
   624       $template->footer();
   624 					<li>{day}: The day of the month (<?php echo date('d'); ?>)</li>
   625     }
   625 					<li>{time12}: 12-hour time (<?php echo date('g:i A'); ?>)</li>
   626     return;
   626 					<li>{time24}: 24-hour time (<?php echo date('G:i'); ?>)</li>
   627   }
   627 				</ul>
   628   
   628 		<?php
   629   if ( isset($_POST['do_stage2']) )
   629 		echo '        </td></tr>';
   630   {
   630 		echo '  </table>
   631     // Allow breaking out of the validation in the case of an error
   631 					</div>';
   632     switch(true):case true:
   632 		
   633       
   633 		$i = 0;
   634       if ( empty($_POST['img_name']) )
   634 		do
   635       {
   635 		{
   636         $errors[] = 'Please enter an image name.';
   636 			$thumb_url = makeUrlNS('Special', 'GalleryFetcher/thumb/' . $row['img_id'], false, true);
   637       }
   637 			
   638       
   638 			# Type: folder
   639       // Validate files
   639 			if ( $row['is_folder'] == 1 ):
   640       $n_files = intval($_POST['img_count']);
   640 			
   641       if ( $n_files < 1 )
   641 			// Image ID tracker
   642       {
   642 			echo '<input type="hidden" name="img[' . $i . '][id]" value="' . $row['img_id'] . '" />';
   643         $errors[] = 'Cannot get image count';
   643 			
   644         break;
   644 			//
   645       }
   645 			// Editor table
   646       
   646 			//
   647       $files = array();
   647 			
   648       
   648 			$folders = gallery_imgid_to_folder(intval($row['img_id']));
   649       for ( $i = 0; $i < $n_files; $i++ )
   649 			foreach ( $folders as $j => $xxx )
   650       {
   650 			{
   651         $key = "img_$i";
   651 				$folder =& $folders[$j];
   652         if ( isset($_FILES[$key]) && !empty($_FILES[$key]['name']) )
   652 				$folder = sanitize_page_id($folder);
   653         {
   653 			}
   654           $files[] =& $_FILES[$key];
   654 			$folders = array_reverse($folders);
   655         }
   655 			$gal_href = implode('/', $folders) . ( count($folders) > 0 ? '/' : '' ) . sanitize_page_id($row['img_title']);
   656       }
   656 			
   657       
   657 			echo '<div class="tblholder">
   658       if ( count($files) < 1 )
   658 							<table border="0" cellspacing="1" cellpadding="4">';
   659       {
   659 			
   660         $errors[] = 'No files specified.';
   660 			echo '<tr><th colspan="2">Folder: ' . htmlspecialchars($row['img_title']) . '</th></tr>';
   661         break;
   661 			
   662       }
   662 			// Primary key
   663       
   663 			echo '<tr>
   664       $allowed = array('png', 'jpg', 'jpeg', 'tiff', 'tif', 'bmp', 'gif');
   664 							<td class="row2">Unique ID:</td>
   665       $is_zip = false;
   665 							<td class="row1">' . $row['img_id'] . ' (<a href="' . makeUrlNS('Special', 'Gallery/' . $gal_href) . '">view folder contents</a>)</td>
   666       foreach ( $files as $i => $file )
   666 						</tr>';
   667       {
   667 						
   668         $ext = substr($file['name'], ( strrpos($file['name'], '.') + 1 ));
   668 			// Path info
   669         $ext = strtolower($ext);
   669 			echo '<tr>
   670         if ( !in_array($ext, $allowed) && ( !$zip_support || ( $ext != 'zip' || $i > 0 ) ) )
   670 							<td class="row2">Parent folders:</td>
   671         {
   671 							<td class="row1">' . /* Yeah it's dirty, but hey, it gets the job done ;-) */ ( ( $x = str_replace('&amp;raquo;', '&raquo;', htmlspecialchars(str_replace('_', ' ', implode(' &raquo; ', $folders)))) ) ? $x : '&lt;in root&gt;' ) . '</td>
   672           $errors[] = htmlspecialchars($file['name']) . ' is an invalid extension (' . htmlspecialchars($ext) . ').';
   672 						</tr>';
   673         }
   673 			
   674         else if ( $ext == 'zip' && $i == 0 && $zip_support )
   674 			// Image name
   675         {
   675 			
   676           $is_zip = true;
   676 			echo '<tr>
   677         }
   677 							<td class="row2">Folder name:</td>
   678       }
   678 							<td class="row1"><input type="text" style="width: 98%;" name="img[' . $i . '][title]" value="' . htmlspecialchars($row['img_title']) . '" size="43" /></td>
   679       
   679 						</tr>';
   680       if ( count($errors) > 0 )
   680 						
   681       {
   681 			// Mover widget
   682         // Send error messages
   682 			?>
   683         break;
   683 			<tr>
   684       }
   684 				<td class="row2">Move to folder:</td>
   685       
   685 				<td class="row1">
   686       // Parent folder
   686 					<div class="toggle">
   687       $folder = $_POST['folder_id'];
   687 						<div class="head" onclick="gal_toggle( ( IE ? this.nextSibling : this.nextSibling.nextSibling ), this.childNodes[1]);">
   688       if ( $folder != 'NULL' && !preg_match('/^[0-9]+$/', $folder) )
   688 							<img alt="&gt;&gt;" src="<?php echo scriptPath; ?>/plugins/gallery/toggle-closed.png" class="toggler" />
   689       {
   689 							Select folder
   690         $folder = 'NULL';
   690 						</div>
   691       }
   691 						<div class="body">
   692       
   692 							<?php
   693       // Format title and description fields
   693 								echo gallery_hier_formfield('img[' . $i . '][folder]', false);
   694       $title = $template->makeParserText($_POST['img_name']);
   694 							?>
   695       $desc  = $template->makeParserText($_POST['img_desc']);
   695 							<br />
   696       
   696 							<a href="#" onclick="gal_unset_radios('img[<?php echo $i; ?>][folder]'); return false;">Unselect field</a>
   697       $vars = array(
   697 						</div>
   698           'year' => date('Y'),
   698 					</div>
   699           'month' => date('F'),
   699 				</td>
   700           'day' => date('d'),
   700 			</tr>
   701           'time12' => date('g:i A'),
   701 			<?php
   702           'time24' => date('G:i')
   702 			
   703         );
   703 			// Finish table
   704       
   704 			echo '</table>';
   705       $title->assign_vars($vars);
   705 			echo '</div>';
   706       $desc->assign_vars($vars);
   706 			
   707       
   707 			# Type: image
   708       $idlist = array();
   708 			else:
   709       
   709 			
   710       // Try to disable the time limit
   710 			// Image ID tracker
   711       @set_time_limit(0);
   711 			echo '<input type="hidden" name="img[' . $i . '][id]" value="' . $row['img_id'] . '" />';
   712       
   712 			
   713       // Move uploaded files to the files/ directory
   713 			//
   714       foreach ( $files as $i => $__trash )
   714 			// Editor table
   715       {
   715 			//
   716         $file =& $files[$i];
   716 			
   717         $ext = substr($file['name'], ( strrpos($file['name'], '.') + 1 ));
   717 			echo '<div class="tblholder">
   718         $ext = strtolower($ext);
   718 							<table border="0" cellspacing="1" cellpadding="4">';
   719         if ( $ext == 'zip' && $is_zip && $zip_support )
   719 			
   720         {
   720 			echo '<tr><th colspan="2">Image: ' . htmlspecialchars($row['img_title']) . '</th></tr>';
   721           //
   721 			
   722           // Time for some unzipping fun.
   722 			// Primary key
   723           //
   723 			echo '<tr>
   724           
   724 							<td class="row2">Unique ID:</td>
   725           error_reporting(E_ALL);
   725 							<td class="row1">' . $row['img_id'] . ' (<a href="' . makeUrlNS('Gallery', $row['img_id']) . '">view image\'s page</a>)</td>
   726           
   726 						</tr>';
   727           mkdir(ENANO_ROOT . '/cache/temp') or $errors[] = 'Could not create temporary directory for extraction.';
   727 						
   728           if ( count($errors) > 0 )
   728 			// Thumbnail
   729             break 2;
   729 			
   730           $temp_dir = tempnam(ENANO_ROOT . '/cache/temp', 'galunz');
   730 			echo '<tr>
   731           if ( file_exists($temp_dir) )
   731 							<td class="row2">Thumbnail:</td>
   732             unlink($temp_dir);
   732 							<td class="row1"><img alt="Thumbnail image" src="' . $thumb_url . '" /></td>
   733           @mkdir($temp_dir);
   733 						</tr>';
   734           
   734 			
   735           // Extract the zip file
   735 			// Image name
   736           if ( class_exists('ZipArchive') )
   736 			
   737           {
   737 			echo '<tr>
   738             $zip = new ZipArchive();
   738 							<td class="row2">Image title:</td>
   739             $op = $zip->open($file['tmp_name']);
   739 							<td class="row1"><input type="text" style="width: 98%;" name="img[' . $i . '][title]" value="' . htmlspecialchars($row['img_title']) . '" size="43" /></td>
   740             if ( !$op )
   740 						</tr>';
   741             {
   741 						
   742               $errors[] = 'Could not open the zip file.';
   742 			// Image description
   743               break 2;
   743 			
   744             }
   744 			echo '<tr>
   745             $op = $zip->extractTo($temp_dir);
   745 							<td class="row2">Image description:</td>
   746             if ( !$op )
   746 							<td class="row1"><textarea rows="10" cols="40" style="width: 98%;" name="img[' . $i . '][desc]">' . htmlspecialchars($row['img_desc']) . '</textarea></td>
   747             {
   747 						</tr>';
   748               $errors[] = 'Could not extract the zip file.';
   748 						
   749               break 2;
   749 			// ACL editor trigger
   750             }
   750 			
   751           }
   751 			echo '<tr>
   752           else if ( file_exists('/usr/bin/unzip') )
   752 							<td class="row2">Permissions:</td>
   753           {
   753 							<td class="row1"><input type="button" onclick="ajaxOpenACLManager(\'' . $row['img_id'] . '\', \'Gallery\');" value="Edit permissions" /><br /><small>Only works in Firefox 1.5 or later, Safari 3.x or later, or Opera 9.0 or later.</small></td>
   754             $cmd = "/usr/bin/unzip -qq -d $temp_dir {$file['tmp_name']}";
   754 						</tr>';
   755             system($cmd);
   755 						
   756           }
   756 			// Mover widget
   757           
   757 			?>
   758           // Any files?
   758 			<tr>
   759           $file_list = gal_dir_recurse($temp_dir, $dirs);
   759 				<td class="row2">Move to folder:</td>
   760           if ( !$file_list )
   760 				<td class="row1">
   761           {
   761 					<div class="toggle">
   762             $errors[] = 'Could not get file list for temp directory.';
   762 						<div class="head" onclick="gal_toggle( ( IE ? this.nextSibling : this.nextSibling.nextSibling ), this.childNodes[1]);">
   763             break 2;
   763 							<img alt="&gt;&gt;" src="<?php echo scriptPath; ?>/plugins/gallery/toggle-closed.png" class="toggler" />
   764           }
   764 							Select folder
   765           if ( count($file_list) < 1 )
   765 						</div>
   766           {
   766 						<div class="body">
   767             $errors[] = 'There weren\'t any files in the uploaded zip file.';
   767 							<?php
   768           }
   768 								echo gallery_hier_formfield('img[' . $i . '][folder]', false);
   769           
   769 							?>
   770           $dirs = array_reverse($dirs);
   770 							<br />
   771           $img_files = array();
   771 							<a href="#" onclick="gal_unset_radios('img[<?php echo $i; ?>][folder]'); return false;">Unselect field</a>
   772           
   772 						</div>
   773           // Loop through and add files
   773 					</div>
   774           foreach ( $file_list as $file )
   774 				</td>
   775           {
   775 			</tr>
   776             $ext = get_file_extension($file);
   776 			<?php
   777             
   777 						
   778             if ( in_array($ext, $allowed) )
   778 			// File replacer
   779             {
   779 			
   780               $img_files[] = $file;
   780 			echo '<tr>
   781             }
   781 							<td class="row2">Upload new version:</td>
   782             else
   782 							<td class="row1"><input type="file" name="reupload_' . $row['img_id'] . '" size="30" style="width: 98%;" /></td>
   783             {
   783 						</tr>';
   784               unlink($file);
   784 						
   785             }
   785 			// Finish table
   786           }
   786 			echo '</table>';
   787           
   787 			echo '</div>';
   788           // Main storage loop
   788 			
   789           $j = 0;
   789 			endif;
   790           foreach ( $img_files as $file )
   790 			
   791           {
   791 			$i++;
   792             $ext = get_file_extension($file);
   792 		}
   793             $stored_name = gallery_make_filename() . ".$ext";
   793 		while ( $row = $db->fetchrow($e) );
   794             $store = ENANO_ROOT . '/files/' . $stored_name;
   794 		$db->free_result();
   795             if ( !rename($file, $store) )
   795 		
   796             {
   796 		echo '<div class="tblholder">
   797               $errors[] = 'Could not move file ' . $file . ' to permanent storage location ' . $store . '.';
   797 						<table border="0" cellspacing="1" cellpadding="4">';
   798               break 3;
   798 		// Mover widget
   799             }
   799 		if ( $num_edit > 1 ):
   800             
   800 		?>
   801             $autotitle = ucwords(basename($file));
   801 		<tr>
   802             $autotitle = substr($autotitle, 0, ( strrpos($autotitle, '.') ));
   802 			<td class="row2">Move all to folder:<br /><small>Other folder fields on this page can override this for individual images.</small></td>
   803             $autotitle = str_replace('_', ' ', $autotitle);
   803 			<td class="row1" style="width: 70%;">
   804             
   804 				<div class="toggle">
   805             $title->assign_vars(array('id' => ( $j + 1 ), 'autotitle' => $autotitle));
   805 					<div class="head" onclick="gal_toggle( ( IE ? this.nextSibling : this.nextSibling.nextSibling ), this.childNodes[1]);">
   806             $desc->assign_vars(array('id' => ( $j + 1 ), 'autotitle' => $autotitle));
   806 						<img alt="&gt;&gt;" src="<?php echo scriptPath; ?>/plugins/gallery/toggle-closed.png" class="toggler" />
   807             
   807 						Select folder
   808             $local_t = $title->run();
   808 					</div>
   809             $local_t = RenderMan::preprocess_text($local_t, true, false);
   809 					<div class="body">
   810             
   810 						<?php
   811             $local_d = $desc->run();
   811 							echo gallery_hier_formfield('override_folder', false);
   812             $local_d = RenderMan::preprocess_text($local_d, true, false);
   812 						?>
   813             
   813 						<br />
   814             $subq = '(\'' . $stored_name . '\', \'' . $db->escape($local_t) . '\', \'' . $db->escape($local_d) . '\',\'a:0:{}\', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), ' . $folder . ', \'[]\')';
   814 						<a href="#" onclick="gal_unset_radios('override_folder'); return false;">Unselect field</a>
   815             $sql = "INSERT INTO ".table_prefix."gallery(img_filename,img_title,img_desc,print_sizes,img_time_upload,img_time_mod,folder_parent,img_tags) VALUES{$subq};";
   815 					</div>
   816             
   816 				</div>
   817             if ( !$db->sql_query($sql) )
   817 			</td>
   818               $db->_die();
   818 		</tr>
   819             
   819 		<?php
   820             $idlist[] = $db->insert_id();
   820 		endif;
   821             
   821 			
   822             //
   822 		echo '    <tr><th class="subhead" colspan="2"><input type="submit" name="edit_do_save" value="Save changes" /></th></tr>';
   823             // Create scaled images
   823 		echo '  </table>
   824             //
   824 					</div>';
   825             
   825 		
   826             // Create thumbnail image
   826 	}
   827             $thumb_filename = ENANO_ROOT . '/cache/' . $stored_name . '-thumb.jpg';
   827 	else
   828             if ( file_exists($thumb_filename) )
   828 	{
   829             {
   829 		echo '<p>No images that matched the ID list could be found.</p>';
   830               if ( !unlink($thumb_filename) )
   830 	}
   831               {
   831 	
   832                 $errors[] = "Could not delete $thumb_filename";
   832 	echo '</form>';
   833                 break 2;
   833 }
   834               }
   834 
   835             }
   835 function get_max_size_field()
   836             
   836 {
   837             if ( !scale_image($store, $thumb_filename, 80, 80) )
   837 	$max_size = @ini_get('upload_max_filesize');
   838             {
   838 	$max_size_field = '';
   839               $errors[] = 'Couldn\'t scale image '.$i.': ImageMagick failed us';
   839 	if ( $max_size )
   840               break 2;
   840 	{
   841             }
   841 		if ( preg_match('/M$/i', $max_size) )
   842             
   842 		{
   843             // Create preview image
   843 			$max_size = intval($max_size) * 1048576;
   844             $preview_filename = ENANO_ROOT . '/cache/' . $stored_name . '-preview.jpg';
   844 		}
   845             if ( file_exists($preview_filename) )
   845 		else if ( preg_match('/K$/i', $max_size) )
   846             {
   846 		{
   847               if ( !unlink($preview_filename) )
   847 			$max_size = intval($max_size) * 1024;
   848               {
   848 		}
   849                 $errors[] = "Could not delete $preview_filename";
   849 		else if ( preg_match('/G$/i', $max_size) )
   850                 break 2;
   850 		{
   851               }
   851 			$max_size = intval($max_size) * 1048576 * 1024;
   852             }
   852 		}
   853             
   853 		$max_size = intval($max_size);
   854             if ( !scale_image($store, $preview_filename, 640, 640) )
   854 		$max_size_field = "\n" . '<input type="hidden" name="MAX_FILE_SIZE" value="' . $max_size . '" />' . "\n";
   855             {
   855 	}
   856               $errors[] = 'Couldn\'t scale image '.$i.': ImageMagick failed us';
   856 	return $max_size_field;
   857               break 2;
       
   858             }
       
   859             
       
   860             $j++;
       
   861           }
       
   862           
       
   863           // clean up
       
   864           foreach ( $dirs as $dir )
       
   865           {
       
   866             rmdir($dir);
       
   867           }
       
   868           
       
   869           rmdir( $temp_dir ) or $errors[] = 'Couldn\'t delete the unzip directory.';
       
   870           rmdir( ENANO_ROOT . '/cache/temp' ) or $errors[] = 'Couldn\'t delete the temp directory.';
       
   871           if ( count($errors) > 0 )
       
   872             break 2;
       
   873           
       
   874           $idlist = implode(',', $idlist);
       
   875           $url = makeUrlNS('Special', 'GalleryUpload', "edit_img=$idlist");
       
   876           
       
   877           redirect($url, 'Upload successful', 'Your images have been uploaded successfully. Please wait while you are transferred...', 2);
       
   878           
       
   879           break 2;
       
   880         }
       
   881         $file['stored_name'] = gallery_make_filename() . '.' . $ext;
       
   882         $store = ENANO_ROOT . '/files/' . $file['stored_name'];
       
   883         if ( !@move_uploaded_file($file['tmp_name'], $store) )
       
   884         {
       
   885           $errors[] = "[Internal] Couldn't move temporary file {$file['tmp_name']} to permanently stored file $store";
       
   886           break 2;
       
   887         }
       
   888         
       
   889         $autotitle = ucwords(basename($file['name']));
       
   890         $autotitle = substr($autotitle, 0, ( strrpos($autotitle, '.') ));
       
   891         $autotitle = str_replace('_', ' ', $autotitle);
       
   892         
       
   893         $title->assign_vars(array('id' => ( $i + 1 ), 'autotitle' => $autotitle));
       
   894         $desc->assign_vars (array('id' => ( $i + 1 ), 'autotitle' => $autotitle));
       
   895         
       
   896         $local_t = $title->run();
       
   897         $local_t = RenderMan::preprocess_text($local_t, true, false);
       
   898         
       
   899         $local_d = $desc->run();
       
   900         $local_d = RenderMan::preprocess_text($local_d, true, false);
       
   901         
       
   902         $subq = '(\'' . $file['stored_name'] . '\', \'' . $db->escape($local_t) . '\', \'' . $db->escape($local_d) . '\',\'a:0:{}\', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), ' . $folder . ', \'[]\')';
       
   903         $sql = "INSERT INTO ".table_prefix."gallery(img_filename,img_title,img_desc,print_sizes,img_time_upload,img_time_mod,folder_parent,img_tags) VALUES{$subq};";
       
   904         
       
   905         if ( !$db->sql_query($sql) )
       
   906           $db->_die();
       
   907         
       
   908         $idlist[] = $db->insert_id();
       
   909         
       
   910         // Create thumbnail image
       
   911         $thumb_filename = ENANO_ROOT . '/cache/' . $file['stored_name'] . '-thumb.jpg';
       
   912         $magick = getConfig('imagemagick_path');
       
   913         $command = "$magick '{$store}' -resize ".'"'."80x80>".'"'." -quality 85 $thumb_filename";
       
   914         
       
   915         @system($command, $stat);
       
   916         
       
   917         if ( !file_exists($thumb_filename) )
       
   918         {
       
   919           $errors[] = 'Couldn\'t scale image '.$i.': ImageMagick failed us';
       
   920           break 2;
       
   921         }
       
   922         
       
   923         // Create preview image
       
   924         $preview_filename = ENANO_ROOT . '/cache/' . $file['stored_name'] . '-preview.jpg';
       
   925         $magick = getConfig('imagemagick_path');
       
   926         $command = "$magick '{$store}' -resize ".'"'."640x640>".'"'." -quality 85 $preview_filename";
       
   927         
       
   928         @system($command, $stat);
       
   929         
       
   930         if ( !file_exists($preview_filename) )
       
   931         {
       
   932           $errors[] = 'Couldn\'t scale image '.$i.': ImageMagick failed us';
       
   933           break 2;
       
   934         }
       
   935         
       
   936       }
       
   937       
       
   938       $idlist = implode(',', $idlist);
       
   939       $url = makeUrlNS('Special', 'GalleryUpload', "edit_img=$idlist");
       
   940       
       
   941       redirect($url, 'Upload successful', 'Your images have been uploaded successfully. Please wait while you are transferred...', 2);
       
   942       
       
   943       return;
       
   944       
       
   945     endswitch;
       
   946   }
       
   947   
       
   948   // Smart batch-upload interface
       
   949   $template->header();
       
   950   
       
   951   ?>
       
   952   <!-- Some Javascript magic :-) -->
       
   953   <script type="text/javascript">
       
   954     function gal_upload_addimg()
       
   955     {
       
   956       var id = 0;
       
   957       var td = document.getElementById('gal_upload_td');
       
   958       for ( var i = 0; i < td.childNodes.length; i++ )
       
   959       {
       
   960         var child = td.childNodes[i];
       
   961         if ( child.tagName == 'INPUT' && child.type == 'hidden' )
       
   962         {
       
   963           var file = document.createElement('input');
       
   964           file.type = 'file';
       
   965           file.size = '43';
       
   966           file.name = 'img_' + id;
       
   967           file.style.marginBottom = '3px';
       
   968           td.insertBefore(file, child);
       
   969           td.insertBefore(document.createElement('br'), child);
       
   970           child.value = String(id);
       
   971           return;
       
   972         }
       
   973         else if ( child.tagName == 'INPUT' && child.type == 'file' )
       
   974         {
       
   975           id++;
       
   976         }
       
   977       }
       
   978     }
       
   979   </script>
       
   980   <?php
       
   981   
       
   982   echo '<form action="' . makeUrlNS('Special', 'GalleryUpload') . '" enctype="multipart/form-data" method="post" onsubmit="if ( window.whiteOutForm ) window.whiteOutForm(this);">';
       
   983   echo $max_size_field;
       
   984   if ( count($errors) > 0 )
       
   985   {
       
   986     echo '<div class="error-box">
       
   987             <b>The following errors were encountered during the upload:</b><br />
       
   988             <ul>
       
   989               <li>' . implode("</li>\n        <li>", $errors) . '</li>
       
   990             </ul>
       
   991           </div>';
       
   992   }
       
   993   ?>
       
   994   <div class="tblholder">
       
   995     <table border="0" cellspacing="1" cellpadding="4">
       
   996       <tr>
       
   997         <th colspan="2">Upload images to gallery</th>
       
   998       </tr>
       
   999       <tr>
       
  1000         <td class="row2">Image name template:</td>
       
  1001         <td class="row1"><input type="text" name="img_name" size="43" style="width: 98%;" /></td>
       
  1002       </tr>
       
  1003       <tr>
       
  1004         <td class="row2">Image description template:</td>
       
  1005         <td class="row1"><textarea rows="10" cols="40" name="img_desc" style="width: 98%;"></textarea></td>
       
  1006       </tr>
       
  1007       <tr>
       
  1008         <td colspan="2" class="row3" style="font-size: smaller;">
       
  1009           <p>The name and description templates can contain the following variables:</p>
       
  1010           <ul>
       
  1011             <li>{id}: The number of the image (different for each image)</li>
       
  1012             <li>{autotitle}: Let the uploader automatically generate a title, based on the filename (david_in_the_barn.jpg will become "David in the barn"). Sometimes this process can be very dumb (mtrooper2k5.jpg will become "Mtrooper2k5").</li>
       
  1013             <li>{year}: The current year (<?php echo date('Y'); ?>)</li>
       
  1014             <li>{month}: The current month (<?php echo date('F'); ?>)</li>
       
  1015             <li>{day}: The day of the month (<?php echo date('d'); ?>)</li>
       
  1016             <li>{time12}: 12-hour time (<?php echo date('g:i A'); ?>)</li>
       
  1017             <li>{time24}: 24-hour time (<?php echo date('G:i'); ?>)</li>
       
  1018           </ul>
       
  1019           <p>Example: <input type="text" readonly="readonly" value="Photo #{id} - uploaded {month} {day}, {year} {time12}" size="50" /></p>
       
  1020         </td>
       
  1021       </tr>
       
  1022       <tr>
       
  1023         <td class="row2">
       
  1024           Image files:
       
  1025           <?php
       
  1026           if ( $zip_support )
       
  1027           {
       
  1028             ?>
       
  1029             <br />
       
  1030             <small><b>Your server has support for zip files.</b>
       
  1031                    Instead of uploading many image files, you can upload a single zip file here. Note that if you send a zip file through,
       
  1032                    it must be the first and only file or it will be ignored. Any files in the zip archive that are not supported image
       
  1033                    files will be ignored.
       
  1034                    <?php
       
  1035                      if ( $sz = ini_get('upload_max_filesize') )
       
  1036                      {
       
  1037                        echo "<b>The maximum file size is <u>{$sz}B</u>.</b>";
       
  1038                      }
       
  1039                    ?>
       
  1040                    </small>
       
  1041             <?php
       
  1042           }
       
  1043           ?>
       
  1044         </td>
       
  1045         <td class="row1" id="gal_upload_td">
       
  1046           <input type="file" name="img_0" size="43" style="margin-bottom: 3px" /><br />
       
  1047           <input type="file" name="img_1" size="43" style="margin-bottom: 3px" /><br />
       
  1048           <input type="file" name="img_2" size="43" style="margin-bottom: 3px" /><br />
       
  1049           <input type="file" name="img_3" size="43" style="margin-bottom: 3px" /><br />
       
  1050           <input type="file" name="img_4" size="43" style="margin-bottom: 3px" /><br />
       
  1051           <input type="hidden" name="img_count" value="4" />
       
  1052           <input type="button" value="+  Add image" onclick="gal_upload_addimg();" title="Add another image field" />
       
  1053         </td>
       
  1054       </tr>
       
  1055       <tr>
       
  1056         <td class="row2">Upload to folder:</td>
       
  1057         <td class="row1">
       
  1058           <div class="toggle">
       
  1059             <div class="head" onclick="gal_toggle( ( IE ? this.nextSibling : this.nextSibling.nextSibling ), this.childNodes[1]);">
       
  1060               <img alt="&gt;&gt;" src="<?php echo scriptPath; ?>/plugins/gallery/toggle-closed.png" class="toggler" />
       
  1061               Select folder
       
  1062             </div>
       
  1063             <div class="body">
       
  1064               <?php
       
  1065                 echo gallery_hier_formfield();
       
  1066               ?>
       
  1067             </div>
       
  1068           </div>
       
  1069         </td>
       
  1070       </tr>
       
  1071     </table>
       
  1072     <table border="0" cellspacing="1" cellpadding="4" style="padding-top: 0;">
       
  1073       <tr>
       
  1074         <th class="subhead" style="text-align: left;">
       
  1075           <small>Please press the Upload button only once! Depending on the size of your image files and the speed of your connection, the upload may take several minutes.</small>
       
  1076         </th>
       
  1077         <th class="subhead" style="text-align: right;">
       
  1078           <input type="submit" name="do_stage2" value="Upload images" /><br />
       
  1079         </th>
       
  1080       </tr>
       
  1081     </table>
       
  1082   </div>
       
  1083   <?php
       
  1084   echo '</form>';
       
  1085   
       
  1086   $template->footer();
       
  1087   
       
  1088 }
   857 }
  1089 
   858 
  1090 ?>
   859 ?>