plugins/gallery/upload.php
author Dan Fuhry <dan@enanocms.org>
Sat, 21 Aug 2010 23:32:06 -0400
changeset 42 7c6e2e97aa08
parent 40 2607b83e986d
child 43 7df4993be0b0
permissions -rw-r--r--
Added AJAX file upload support.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     1
<?php
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     2
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     3
/*
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     4
 * Snapr
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     5
 * Version 0.1 beta 1
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     6
 * Copyright (C) 2007 Dan Fuhry
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     7
 *
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    10
 *
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    13
 */
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    14
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    15
##
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    16
## UPLOAD INTERFACE
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    17
##
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    18
40
2607b83e986d ...And a conversion to ucwords.
Dan Fuhry <dan@enanocms.org>
parents: 32
diff changeset
    19
$plugins->attachHook('session_started', 'register_special_page("GalleryUpload", "Image gallery upload");');
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    20
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    21
function page_Special_GalleryUpload()
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
    22
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    23
	global $db, $session, $paths, $template, $plugins; // Common objects
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    24
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    25
	if ( $session->user_level < USER_LEVEL_ADMIN )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    26
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    27
		die_friendly('Access denied', '<p>You need to have administrative rights to use the gallery\'s upload features.</p>');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    28
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    29
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    30
	$zip_support = ( class_exists('ZipArchive') || ( file_exists('/usr/bin/unzip') && is_executable('/usr/bin/unzip') ) );
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    31
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    32
	$errors = array();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    33
	$template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/gallery/dropdown.css" />');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    34
	$template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/gallery/gallery-bits.js"></script>');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    35
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    36
	$max_size_field = get_max_size_field();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    37
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    38
	//
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    39
	// EDIT IMAGES
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    40
	//  
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    41
	if ( isset($_GET['edit_img']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    42
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    43
		$edit_parms = $_GET['edit_img'];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    44
		$regex = '/^((([0-9]+),)*)?([0-9]+?)$/';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    45
		if ( !preg_match($regex, $edit_parms) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    46
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    47
			die_friendly('Bad request', '<p>$_GET[\'edit_img\'] must be a comma-separated list of image IDs.</p>');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    48
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    49
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    50
		// process any uploaded images
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    51
		// FIXME is this a bad place for this?
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    52
		$limit = isset($_GET['ajax']) ? '' : "LIMIT 5";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    53
		$q = $db->sql_query('SELECT img_id FROM ' . table_prefix . "gallery WHERE is_folder = 0 AND processed = 0 $limit;");
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    54
		if ( !$q )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    55
			$db->_die();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    56
		if ( $db->numrows() > 0 )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    57
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    58
			while ( $row = $db->fetchrow($q) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    59
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    60
				snapr_process_image($row['img_id']);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    61
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    62
			$q = $db->sql_query('SELECT COUNT(img_id) FROM ' . table_prefix . "gallery WHERE is_folder = 0 AND processed = 0;");
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    63
			if ( !$q )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    64
				$db->_die();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    65
			list($count) = $db->fetchrow_num();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    66
			$db->free_result();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    67
			if ( intval($count) > 0 )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    68
			redirect(makeUrlNS('Special', 'GalleryUpload', "edit_img={$_GET['edit_img']}"), "Processing images", "Processing images... $count remaining", 1);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    69
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    70
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    71
		if ( !isset($_GET['ajax']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    72
			$template->header();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    73
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    74
		snapr_editform($edit_parms);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    75
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    76
		if ( !isset($_GET['ajax']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    77
			$template->footer();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    78
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    79
		return;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    80
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    81
	//
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    82
	// REMOVE IMAGES
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    83
	// 
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    84
	else if ( isset($_GET['rm']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    85
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    86
		$warnings = array();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    87
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    88
		if ( !preg_match('/^[0-9]+$/', $_GET['rm']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    89
			die_friendly('Bad Request', '<p>$_GET[rm] needs to be an integer.</p>');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    90
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    91
		$rm_id = intval($_GET['rm']);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    92
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    93
		if ( isset($_POST['confirmed']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    94
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    95
			// The user confirmed the request. Start plowing through data to decide what to delete.
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    96
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    97
			// Array of images and folder rows to delete
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    98
			$del_imgs = array($rm_id);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
    99
			// Array of files to delete
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   100
			$del_files = array();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   101
			// Array of comment entries to delete
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   102
			$del_comments = array();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   103
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   104
			$all_children = gal_fetch_all_children($rm_id);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   105
			$del_imgs = array_merge($del_imgs, $all_children);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   106
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   107
			$imglist = 'img_id=' . implode(' OR img_id=', $del_imgs);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   108
			$sql = "SELECT img_id, img_filename FROM ".table_prefix."gallery WHERE ( $imglist ) AND is_folder!=1;";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   109
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   110
			if ( !$db->sql_query($sql) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   111
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   112
				$db->_die();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   113
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   114
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   115
			while ( $row = $db->fetchrow() )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   116
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   117
				$files = array(
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   118
						ENANO_ROOT . '/files/' . $row['img_filename'],
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   119
						ENANO_ROOT . '/cache/' . $row['img_filename'] . '-thumb.jpg',
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   120
						ENANO_ROOT . '/cache/' . $row['img_filename'] . '-preview.jpg'
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   121
					);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   122
				$del_files = array_merge($del_files, $files);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   123
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   124
				$del_comments[] = intval($row['img_id']);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   125
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   126
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   127
			$commentlist = 'page_id=\'' . implode('\' OR page_id=\'', $del_imgs) . '\'';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   128
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   129
			// Main deletion cycle
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   130
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   131
			foreach ( $del_files as $file )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   132
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   133
				@unlink($file) or $warnings[] = 'Could not delete file ' . $file;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   134
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   135
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   136
			if ( !$db->sql_query('DELETE FROM '.table_prefix.'gallery WHERE ' . $imglist . ';') )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   137
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   138
				$warnings[] = 'Main delete query failed: ' . $db->get_error();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   139
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   140
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   141
			if ( !$db->sql_query('DELETE FROM '.table_prefix.'comments WHERE ( ' . $commentlist . ' ) AND namespace=\'Gallery\';') )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   142
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   143
				$warnings[] = 'Comment delete query failed: ' . $db->get_error();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   144
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   145
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   146
			if ( count($warnings) > 0 )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   147
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   148
				$template->header();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   149
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   150
				echo '<h3>Error during deletion process</h3>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   151
				echo '<p>The deletion process generated some warnings which are shown below.</p>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   152
				echo '<ul><li>' . implode('</li><li>', $warnings) . '</li></ul>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   153
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   154
				$template->footer();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   155
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   156
			else
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   157
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   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);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   159
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   160
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   161
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   162
		else
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   163
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   164
			// Removal form
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   165
			$template->header();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   166
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   167
			echo '<form action="' . makeUrlNS('Special', 'GalleryUpload', 'rm=' . $rm_id, true) . '" method="post" enctype="multipart/form-data">';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   168
			echo $max_size_field;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   169
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   170
			echo '<h3>Are you sure you want to delete this item?</h3>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   171
			echo '<p>If you continue, this item will be permanently deleted from the gallery &ndash; no rollbacks.</p>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   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>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   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>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   174
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   175
			echo '<p><input type="submit" name="confirmed" value="Continue with delete" /></p>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   176
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   177
			echo '</form>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   178
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   179
			$template->footer();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   180
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   181
		return;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   182
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   183
	else if ( isset($_GET['ajax_proc_status']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   184
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   185
		$q = $db->sql_query("SELECT COUNT(img_id) FROM " . table_prefix . "gallery WHERE processed = 0;");
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   186
		if ( !$q )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   187
			$db->_die();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   188
		list($count) = $db->fetchrow_num();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   189
		echo $count;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   190
		return;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   191
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   192
	else
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   193
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   194
		if ( isset($_POST['do_upload']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   195
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   196
			$files =& $_FILES['files'];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   197
			$numfiles = count($files['name']);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   198
			$idlist = array();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   199
			$destfolder = intval($_POST['targetfolder']);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   200
			if ( $destfolder < 1 )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   201
				$destfolder = NULL;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   202
			for ( $i = 0; $i < $numfiles; $i++ )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   203
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   204
				$ext = get_file_extension($files['name'][$i]);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   205
				if ( snapr_extension_allowed($ext) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   206
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   207
					// normal image
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   208
					$result = snapr_insert_image($files['tmp_name'][$i], $destfolder);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   209
					if ( $result !== false )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   210
						$idlist[] = $result;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   211
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   212
				else if ( strtolower($ext) == 'zip' )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   213
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   214
					// zip file
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   215
					$zipidlist = snapr_process_zip($files['tmp_name'][$i], $destfolder);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   216
					if ( $zipidlist )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   217
						$idlist = array_merge($idlist, $zipidlist);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   218
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   219
				else
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   220
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   221
					// FIXME handle unsupported files... maybe?
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   222
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   223
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   224
			$idlist = implode(',', $idlist);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   225
			echo '<div class="idlist">[' . $idlist . ']</div>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   226
			//snapr_editform($idlist);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   227
			return;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   228
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   229
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   230
		// Oh yes, the image uploader!
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   231
		$template->preload_js(array('jquery', 'jquery-ui', 'upload'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   232
		$template->header();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   233
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   234
		?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   235
		<form action="" method="post" enctype="multipart/form-data" id="snaprupload">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   236
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   237
		<script type="text/javascript">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   238
		//<![CDATA[
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   239
		addOnloadHook(function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   240
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   241
				attachHook('snaprupload_ajaxupload_init', 'snapr_upload_init(ajaxupload);');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   242
			});
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   243
		function snapr_upload_init(au)
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   244
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   245
			au.upload_start = function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   246
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   247
				$(this.form).hide();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   248
				$(this.statusbox).html('<h2 class="uploadgoing">Uploading pictures...</h2><div class="progress" style="margin: 15px 0;"></div><p class="uploadstatus">&nbsp;</p>');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   249
				$('div.progress', this.statusbox).progressbar({value: 0});
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   250
			};
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   251
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   252
			au.status = function(state)
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   253
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   254
				if ( !state.done && !state.cancel_upload )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   255
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   256
					var rawpct = state.bytes_processed / state.content_length;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   257
					var pct = (Math.round((rawpct) * 1000)) / 10;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   258
					var elapsed = state.current_time - state.start_time;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   259
					var rawbps = state.bytes_processed / elapsed;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   260
					var kbps = Math.round((rawbps) / 1024);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   261
					var remain_bytes = state.content_length - state.bytes_processed;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   262
					var remain_time = Math.round(remain_bytes / rawbps);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   263
					
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   264
					$('p.uploadstatus', this.statusbox).html(pct + '% complete / ' + kbps + ' KB/s / ' + humanize_time(elapsed) + ' elapsed / ' + humanize_time(remain_time) + ' remaining');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   265
					$('div.progress', this.statusbox).progressbar('value', pct);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   266
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   267
			};
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   268
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   269
			au.upload_success = function(childbody)
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   270
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   271
				$(this.statusbox).html('<div class="info-box"></div>' + childbody.innerHTML);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   272
				var idlist = parseJSON($('div.idlist', this.statusbox).text());
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   273
				$('div.idlist', this.statusbox).remove();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   274
				var s = idlist.length == 1 ? '' : 's';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   275
				$('div.info-box', this.statusbox).html(idlist.length + ' image'+s+' were uploaded successfully. Please wait while they are processed...');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   276
				$(this.statusbox).append('<div class="progress" style="margin: 15px 0;"></div><p class="uploadstatus">&nbsp;</p>');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   277
				$('div.progress', this.statusbox).progressbar({value: 0});
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   278
				var au = this;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   279
				ajaxGet(makeUrlNS('Special', 'GalleryUpload', 'edit_img=' + implode(',', idlist) + '&ajax=true'), function(ajax)
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   280
					{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   281
						if ( ajax.readyState == 4 )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   282
						{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   283
							window.clearTimeout(snapr_refresh_timer);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   284
							$(au.statusbox).html(ajax.responseText);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   285
						}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   286
					});
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   287
				snapr_refresh_proc(au, idlist);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   288
			};
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   289
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   290
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   291
		window.snapr_refresh_timer = false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   292
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   293
		function snapr_refresh_proc(au, idlist)
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   294
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   295
			void(au);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   296
			void(idlist);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   297
			ajaxGet(makeUrlNS('Special', 'GalleryUpload', 'ajax_proc_status'), function(ajax)
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   298
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   299
					if ( ajax.readyState == 4 )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   300
					{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   301
						var n = idlist.length - Number(ajax.responseText);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   302
						var pct = (n / idlist.length) * 100;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   303
						$('div.progress', au.statusbox).progressbar('value', pct);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   304
						$('p.uploadstatus', au.statusbox).html(n + " of " + idlist.length + " images processed");
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   305
						if ( pct < 100 )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   306
							window.snapr_refresh_timer = setTimeout(function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   307
								{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   308
									snapr_refresh_proc(au, idlist);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   309
								}, 1000);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   310
					}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   311
				});
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   312
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   313
		//]]>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   314
		</script>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   315
		<?php ajax_upload_js('snaprupload'); ?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   316
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   317
		<div class="tblholder">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   318
			<table border="0" cellspacing="1" cellpadding="4">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   319
				<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   320
					<th colspan="2">Upload files to the gallery</th>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   321
				</tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   322
				<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   323
					<td class="row1">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   324
						Select files:
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   325
					</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   326
					<td class="row1">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   327
						<input type="hidden" name="do_upload" value="yes" />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   328
						<input type="file" size="50" name="files[]" />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   329
						<input type="button" class="addanother" value="+" />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   330
					</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   331
				</tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   332
				<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   333
					<td class="row2">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   334
						Upload into folder:
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   335
					</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   336
					<td class="row2">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   337
					<?php echo gallery_hier_formfield('targetfolder', true); ?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   338
					</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   339
				</tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   340
				<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   341
					<td class="row3" colspan="2" style="text-align: center; line-height: 24px;">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   342
						<strong>Supported formats:</strong>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   343
						<br />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   344
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   345
						<img alt="Checkmark" src="<?php echo cdnPath; ?>/images/check.png" style="vertical-align: middle;" /> JPEG images &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   346
						<img alt="Checkmark" src="<?php echo cdnPath; ?>/images/check.png" style="vertical-align: middle;" /> PNG images &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   347
						<img alt="Checkmark" src="<?php echo cdnPath; ?>/images/check.png" style="vertical-align: middle;" /> GIF images &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   348
						<?php if ( $zip_support ): ?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   349
						<img alt="Checkmark" src="<?php echo cdnPath; ?>/images/check.png" style="vertical-align: middle;" /> Zip archives
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   350
						<?php else: ?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   351
						<img alt="X mark" src="<?php echo cdnPath; ?>/images/checkbad.png" style="vertical-align: middle;" /> Zip archives
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   352
						<?php endif; ?><br />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   353
						<small>Maximum file size: <strong><?php echo ini_get('upload_max_filesize'); ?></strong></small>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   354
						<?php echo $max_size_field; ?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   355
					</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   356
				</tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   357
				<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   358
					<th colspan="2" class="subhead">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   359
						<input type="submit" value="Upload" />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   360
					</th>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   361
				</tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   362
			</table>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   363
		</div>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   364
		</form>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   365
		<script type="text/javascript">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   366
		// <![CDATA[
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   367
		addOnloadHook(function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   368
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   369
				$('input.addanother').click(function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   370
					{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   371
						$(this).before('<br />');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   372
						var inp = document.createElement('input');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   373
						$(inp).attr('type', 'file').attr('size', '50').attr('name', 'files[]');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   374
						this.parentNode.insertBefore(inp, this);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   375
						$(this).before(' ');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   376
						return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   377
					});
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   378
			});
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   379
		// ]]>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   380
		</script>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   381
		<?php
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   382
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   383
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   384
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   385
	$template->footer();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   386
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   387
}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   388
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   389
function snapr_editform($edit_parms)
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   390
{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   391
	global $db, $session, $paths, $template, $plugins; // Common objects
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   392
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   393
	$max_size_field = get_max_size_field();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   394
	$errors = array();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   395
	$idlist = explode(',', $edit_parms);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   396
	$num_edit = count($idlist);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   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) . ';';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   398
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   399
	if ( !$e = $db->sql_query($idlist) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   400
		$db->_die();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   401
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   402
	if ( isset($_POST['edit_do_save']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   403
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   404
		@set_time_limit(0);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   405
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   406
		$arr_img_data = array();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   407
		while ( $row = $db->fetchrow($e) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   408
			$arr_img_data[$row['img_id']] = $row;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   409
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   410
		// Allow breaking out
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   411
		switch(true):case true:
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   412
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   413
			if ( !is_array($_POST['img']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   414
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   415
				$errors[] = 'No images passed to processor.';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   416
				break;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   417
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   418
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   419
			// Main updater loop
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   420
			foreach ( $_POST['img'] as $img_id => $img_data )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   421
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   422
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   423
				if ( !preg_match('/^[0-9]+$/', $img_id) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   424
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   425
					$errors[] = 'SQL injection attempted!';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   426
					break 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   427
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   428
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   429
				// Array of columns to update
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   430
				$to_update = array();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   431
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   432
				$key = 'reupload_' . $img_data['id'];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   433
				if ( isset($_FILES[$key]) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   434
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   435
					$file =& $_FILES[ $key ];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   436
					if ( $file['tmp_name'] != '' )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   437
					{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   438
						// Reupload
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   439
						$filename = ENANO_ROOT . '/files/' . $arr_img_data[ $img_data['id'] ]['img_filename'];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   440
						if ( !unlink($filename) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   441
						{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   442
							$errors[] = "Could not delete $filename";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   443
							break 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   444
						}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   445
						if ( !@move_uploaded_file($file['tmp_name'], $filename) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   446
						{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   447
							$errors[] = "Could not move uploaded file to $filename";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   448
							break 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   449
						}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   450
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   451
						//
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   452
						// Create scaled images
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   453
						//
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   454
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   455
						// Create thumbnail image
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   456
						$thumb_filename = ENANO_ROOT . '/cache/' . $arr_img_data[ $img_data['id'] ]['img_filename'] . '-thumb.jpg';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   457
						if ( !unlink($thumb_filename) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   458
						{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   459
							$errors[] = "Could not delete $thumb_filename";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   460
							break 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   461
						}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   462
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   463
						if ( !scale_image($filename, $thumb_filename, 80, 80) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   464
						{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   465
							$errors[] = 'Couldn\'t scale image '.$i.': ImageMagick failed us';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   466
							break 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   467
						}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   468
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   469
						// Create preview image
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   470
						$preview_filename = ENANO_ROOT . '/cache/' . $arr_img_data[ $img_data['id'] ]['img_filename'] . '-preview.jpg';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   471
						if ( !unlink($preview_filename) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   472
						{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   473
							$errors[] = "Could not delete $preview_filename";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   474
							break 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   475
						}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   476
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   477
						if ( !scale_image($filename, $preview_filename, 640, 480) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   478
						{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   479
							$errors[] = 'Couldn\'t scale image '.$i.': ImageMagick failed us';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   480
							break 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   481
						}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   482
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   483
						$to_update['img_time_mod'] = strval(time());
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   484
					}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   485
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   486
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   487
				$vars = array(
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   488
					'year' => date('Y'),
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   489
					'month' => date('F'),
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   490
					'day' => date('d'),
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   491
					'time12' => date('g:i A'),
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   492
					'time24' => date('G:i')
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   493
				);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   494
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   495
				// Image name/title
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   496
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   497
				$title = $template->makeParserText($img_data['title']);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   498
				$title->assign_vars($vars);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   499
				$executed = $title->run();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   500
				if ( $executed == '_id' )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   501
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   502
					$errors[] = 'You cannot name an image or folder "_id", this name is reserved for internal functions.';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   503
					break 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   504
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   505
				if ( $executed == '' )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   506
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   507
					$errors[] = 'Please enter a name for the item with unique ID ' . $img_data['id'] . '. <pre>' . print_r($_POST,true) . '</pre>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   508
					break 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   509
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   510
				$to_update['img_title'] = $executed;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   511
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   512
				// Image description
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   513
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   514
				if ( isset($img_data['desc']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   515
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   516
					$desc = $template->makeParserText($img_data['desc']);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   517
					$desc->assign_vars($vars);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   518
					$executed = $desc->run();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   519
					$executed = RenderMan::preprocess_text($executed, false, false);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   520
					$to_update['img_desc'] = $executed;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   521
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   522
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   523
				// Folder
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   524
				$target_folder = false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   525
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   526
				if ( !empty($_POST['override_folder']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   527
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   528
					if ( $_POST['override_folder'] == 'NULL' || preg_match('/^[0-9]+$/', $_POST['override_folder']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   529
					{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   530
						$target_folder = $_POST['override_folder'];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   531
					}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   532
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   533
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   534
				if ( !empty($img_data['folder']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   535
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   536
					if ( $img_data['folder'] == 'NULL' || preg_match('/^[0-9]+$/', $img_data['folder']) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   537
					{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   538
						$target_folder = $img_data['folder'];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   539
					}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   540
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   541
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   542
				if ( $target_folder )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   543
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   544
					// Make sure we're not trying to move a folder to itself or a subdirectory of itself
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   545
					
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   546
					$children = gal_fetch_all_children(intval($img_data['id']));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   547
					if ( $img_data['id'] == $target_folder || in_array($target_folder, $children) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   548
					{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   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.';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   550
						break 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   551
					}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   552
					
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   553
					$to_update['folder_parent'] = $target_folder;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   554
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   555
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   556
				if ( count($to_update) > 0 )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   557
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   558
					$up_keys = array_keys($to_update);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   559
					$up_vals = array_values($to_update);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   560
					
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   561
					$bin_cols = array('folder_parent');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   562
					
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   563
					$sql = 'UPDATE ' . table_prefix.'gallery SET ';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   564
					
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   565
					foreach ( $up_keys as $i => $key )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   566
					{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   567
						if ( in_array($key, $bin_cols) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   568
						{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   569
							$sql .= $key . '=' . $up_vals[$i] . ',';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   570
						}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   571
						else
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   572
						{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   573
							$sql .= $key . '=\'' . $db->escape($up_vals[$i]) . '\',';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   574
						}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   575
					}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   576
					
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   577
					$sql = preg_replace('/,$/i', '', $sql) . ' WHERE img_id=' . $img_data['id'] . ';';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   578
					
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   579
					if ( !$db->sql_query($sql) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   580
					{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   581
						$db->_die();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   582
					}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   583
					
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   584
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   585
				
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   586
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   587
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   588
			echo '<div class="info-box" style="margin-left: 0;">Your changes have been saved.</div>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   589
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   590
		endswitch;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   591
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   592
		// Rerun select query to make sure information in PHP memory is up-to-date
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   593
		if ( !$e = $db->sql_query($idlist) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   594
			$db->_die();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   595
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   596
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   597
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   598
	if ( count($errors) > 0 )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   599
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   600
		echo '<div class="error-box" style="margin-left: 0;">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   601
						<b>The following errors were encountered while updating the image data:</b><br />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   602
						<ul>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   603
							<li>' . implode("</li>\n        <li>", $errors) . '</li>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   604
						</ul>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   605
					</div>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   606
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   607
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   608
	echo '<form action="' . makeUrlNS('Special', 'GalleryUpload', 'edit_img=' . $edit_parms, true) . '" method="post" enctype="multipart/form-data">';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   609
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   610
	echo $max_size_field;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   611
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   612
	if ( $row = $db->fetchrow($e) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   613
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   614
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   615
		echo '<div class="tblholder">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   616
						<table border="0" cellspacing="1" cellpadding="4">';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   617
		echo '    <tr><th class="subhead">Information</th></tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   618
		echo '    <tr><td class="row3">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   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>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   620
		?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   621
				<ul>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   622
					<li>{year}: The current year (<?php echo date('Y'); ?>)</li>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   623
					<li>{month}: The current month (<?php echo date('F'); ?>)</li>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   624
					<li>{day}: The day of the month (<?php echo date('d'); ?>)</li>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   625
					<li>{time12}: 12-hour time (<?php echo date('g:i A'); ?>)</li>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   626
					<li>{time24}: 24-hour time (<?php echo date('G:i'); ?>)</li>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   627
				</ul>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   628
		<?php
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   629
		echo '        </td></tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   630
		echo '  </table>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   631
					</div>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   632
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   633
		$i = 0;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   634
		do
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   635
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   636
			$thumb_url = makeUrlNS('Special', 'GalleryFetcher/thumb/' . $row['img_id'], false, true);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   637
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   638
			# Type: folder
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   639
			if ( $row['is_folder'] == 1 ):
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   640
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   641
			// Image ID tracker
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   642
			echo '<input type="hidden" name="img[' . $i . '][id]" value="' . $row['img_id'] . '" />';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   643
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   644
			//
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   645
			// Editor table
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   646
			//
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   647
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   648
			$folders = gallery_imgid_to_folder(intval($row['img_id']));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   649
			foreach ( $folders as $j => $xxx )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   650
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   651
				$folder =& $folders[$j];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   652
				$folder = sanitize_page_id($folder);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   653
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   654
			$folders = array_reverse($folders);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   655
			$gal_href = implode('/', $folders) . ( count($folders) > 0 ? '/' : '' ) . sanitize_page_id($row['img_title']);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   656
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   657
			echo '<div class="tblholder">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   658
							<table border="0" cellspacing="1" cellpadding="4">';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   659
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   660
			echo '<tr><th colspan="2">Folder: ' . htmlspecialchars($row['img_title']) . '</th></tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   661
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   662
			// Primary key
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   663
			echo '<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   664
							<td class="row2">Unique ID:</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   665
							<td class="row1">' . $row['img_id'] . ' (<a href="' . makeUrlNS('Special', 'Gallery/' . $gal_href) . '">view folder contents</a>)</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   666
						</tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   667
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   668
			// Path info
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   669
			echo '<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   670
							<td class="row2">Parent folders:</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   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>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   672
						</tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   673
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   674
			// Image name
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   675
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   676
			echo '<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   677
							<td class="row2">Folder name:</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   678
							<td class="row1"><input type="text" style="width: 98%;" name="img[' . $i . '][title]" value="' . htmlspecialchars($row['img_title']) . '" size="43" /></td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   679
						</tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   680
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   681
			// Mover widget
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   682
			?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   683
			<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   684
				<td class="row2">Move to folder:</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   685
				<td class="row1">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   686
					<div class="toggle">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   687
						<div class="head" onclick="gal_toggle( ( IE ? this.nextSibling : this.nextSibling.nextSibling ), this.childNodes[1]);">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   688
							<img alt="&gt;&gt;" src="<?php echo scriptPath; ?>/plugins/gallery/toggle-closed.png" class="toggler" />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   689
							Select folder
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   690
						</div>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   691
						<div class="body">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   692
							<?php
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   693
								echo gallery_hier_formfield('img[' . $i . '][folder]', false);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   694
							?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   695
							<br />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   696
							<a href="#" onclick="gal_unset_radios('img[<?php echo $i; ?>][folder]'); return false;">Unselect field</a>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   697
						</div>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   698
					</div>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   699
				</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   700
			</tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   701
			<?php
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   702
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   703
			// Finish table
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   704
			echo '</table>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   705
			echo '</div>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   706
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   707
			# Type: image
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   708
			else:
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   709
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   710
			// Image ID tracker
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   711
			echo '<input type="hidden" name="img[' . $i . '][id]" value="' . $row['img_id'] . '" />';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   712
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   713
			//
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   714
			// Editor table
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   715
			//
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   716
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   717
			echo '<div class="tblholder">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   718
							<table border="0" cellspacing="1" cellpadding="4">';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   719
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   720
			echo '<tr><th colspan="2">Image: ' . htmlspecialchars($row['img_title']) . '</th></tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   721
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   722
			// Primary key
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   723
			echo '<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   724
							<td class="row2">Unique ID:</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   725
							<td class="row1">' . $row['img_id'] . ' (<a href="' . makeUrlNS('Gallery', $row['img_id']) . '">view image\'s page</a>)</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   726
						</tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   727
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   728
			// Thumbnail
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   729
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   730
			echo '<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   731
							<td class="row2">Thumbnail:</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   732
							<td class="row1"><img alt="Thumbnail image" src="' . $thumb_url . '" /></td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   733
						</tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   734
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   735
			// Image name
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   736
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   737
			echo '<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   738
							<td class="row2">Image title:</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   739
							<td class="row1"><input type="text" style="width: 98%;" name="img[' . $i . '][title]" value="' . htmlspecialchars($row['img_title']) . '" size="43" /></td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   740
						</tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   741
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   742
			// Image description
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   743
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   744
			echo '<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   745
							<td class="row2">Image description:</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   746
							<td class="row1"><textarea rows="10" cols="40" style="width: 98%;" name="img[' . $i . '][desc]">' . htmlspecialchars($row['img_desc']) . '</textarea></td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   747
						</tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   748
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   749
			// ACL editor trigger
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   750
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   751
			echo '<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   752
							<td class="row2">Permissions:</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   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>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   754
						</tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   755
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   756
			// Mover widget
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   757
			?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   758
			<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   759
				<td class="row2">Move to folder:</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   760
				<td class="row1">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   761
					<div class="toggle">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   762
						<div class="head" onclick="gal_toggle( ( IE ? this.nextSibling : this.nextSibling.nextSibling ), this.childNodes[1]);">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   763
							<img alt="&gt;&gt;" src="<?php echo scriptPath; ?>/plugins/gallery/toggle-closed.png" class="toggler" />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   764
							Select folder
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   765
						</div>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   766
						<div class="body">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   767
							<?php
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   768
								echo gallery_hier_formfield('img[' . $i . '][folder]', false);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   769
							?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   770
							<br />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   771
							<a href="#" onclick="gal_unset_radios('img[<?php echo $i; ?>][folder]'); return false;">Unselect field</a>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   772
						</div>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   773
					</div>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   774
				</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   775
			</tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   776
			<?php
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   777
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   778
			// File replacer
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   779
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   780
			echo '<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   781
							<td class="row2">Upload new version:</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   782
							<td class="row1"><input type="file" name="reupload_' . $row['img_id'] . '" size="30" style="width: 98%;" /></td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   783
						</tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   784
						
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   785
			// Finish table
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   786
			echo '</table>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   787
			echo '</div>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   788
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   789
			endif;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   790
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   791
			$i++;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   792
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   793
		while ( $row = $db->fetchrow($e) );
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   794
		$db->free_result();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   795
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   796
		echo '<div class="tblholder">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   797
						<table border="0" cellspacing="1" cellpadding="4">';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   798
		// Mover widget
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   799
		if ( $num_edit > 1 ):
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   800
		?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   801
		<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   802
			<td class="row2">Move all to folder:<br /><small>Other folder fields on this page can override this for individual images.</small></td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   803
			<td class="row1" style="width: 70%;">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   804
				<div class="toggle">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   805
					<div class="head" onclick="gal_toggle( ( IE ? this.nextSibling : this.nextSibling.nextSibling ), this.childNodes[1]);">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   806
						<img alt="&gt;&gt;" src="<?php echo scriptPath; ?>/plugins/gallery/toggle-closed.png" class="toggler" />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   807
						Select folder
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   808
					</div>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   809
					<div class="body">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   810
						<?php
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   811
							echo gallery_hier_formfield('override_folder', false);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   812
						?>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   813
						<br />
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   814
						<a href="#" onclick="gal_unset_radios('override_folder'); return false;">Unselect field</a>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   815
					</div>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   816
				</div>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   817
			</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   818
		</tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   819
		<?php
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   820
		endif;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   821
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   822
		echo '    <tr><th class="subhead" colspan="2"><input type="submit" name="edit_do_save" value="Save changes" /></th></tr>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   823
		echo '  </table>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   824
					</div>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   825
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   826
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   827
	else
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   828
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   829
		echo '<p>No images that matched the ID list could be found.</p>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   830
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   831
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   832
	echo '</form>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   833
}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   834
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   835
function get_max_size_field()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   836
{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   837
	$max_size = @ini_get('upload_max_filesize');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   838
	$max_size_field = '';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   839
	if ( $max_size )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   840
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   841
		if ( preg_match('/M$/i', $max_size) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   842
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   843
			$max_size = intval($max_size) * 1048576;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   844
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   845
		else if ( preg_match('/K$/i', $max_size) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   846
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   847
			$max_size = intval($max_size) * 1024;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   848
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   849
		else if ( preg_match('/G$/i', $max_size) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   850
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   851
			$max_size = intval($max_size) * 1048576 * 1024;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   852
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   853
		$max_size = intval($max_size);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   854
		$max_size_field = "\n" . '<input type="hidden" name="MAX_FILE_SIZE" value="' . $max_size . '" />' . "\n";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   855
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 40
diff changeset
   856
	return $max_size_field;
0
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   857
}
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   858
7caf561c50ee Initial population; browser, viewer, uploader, and security are working
Dan
parents:
diff changeset
   859
?>