source: trunk/admin/include/photos_add_direct_prepare.inc.php @ 28436

Last change on this file since 28436 was 26461, checked in by mistic100, 11 years ago

Update headers to 2014. Happy new year!!

File size: 8.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2014 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24
25// +-----------------------------------------------------------------------+
26// | Uploaded photos                                                       |
27// +-----------------------------------------------------------------------+
28
29if (isset($page['thumbnails']))
30{
31  $template->assign(
32    array(
33      'thumbnails' => $page['thumbnails'],
34      )
35    );
36
37  // only display the batch link if we have more than 1 photo
38  if (count($page['thumbnails']) > 1)
39  {
40    $template->assign(
41      array(
42        'batch_link' => $page['batch_link'],
43        'batch_label' => sprintf(
44          l10n('Manage this set of %d photos'),
45          count($page['thumbnails'])
46          ),
47        )
48      );
49  }
50}
51
52// +-----------------------------------------------------------------------+
53// | Photo selection                                                       |
54// +-----------------------------------------------------------------------+
55
56$uploadify_path = PHPWG_ROOT_PATH.'admin/include/uploadify';
57
58$upload_max_filesize = min(
59  get_ini_size('upload_max_filesize'),
60  get_ini_size('post_max_size')
61  );
62
63if ($upload_max_filesize == get_ini_size('upload_max_filesize'))
64{
65  $upload_max_filesize_shorthand = get_ini_size('upload_max_filesize', false);
66}
67else
68{
69  $upload_max_filesize_shorthand = get_ini_size('post_max_filesize', false);
70}
71
72$template->assign(
73    array(
74      'F_ADD_ACTION'=> PHOTOS_ADD_BASE_URL,
75      'uploadify_path' => $uploadify_path,
76      'upload_max_filesize' => $upload_max_filesize,
77      'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand,
78    )
79  );
80
81// what is the maximum number of pixels permitted by the memory_limit?
82if (pwg_image::get_library() == 'gd')
83{
84  $fudge_factor = 1.7;
85  $available_memory = get_ini_size('memory_limit') - memory_get_usage();
86  $max_upload_width = round(sqrt($available_memory/(2 * $fudge_factor)));
87  $max_upload_height = round(2 * $max_upload_width / 3);
88 
89  // we don't want dimensions like 2995x1992 but 3000x2000
90  $max_upload_width = round($max_upload_width/100)*100;
91  $max_upload_height = round($max_upload_height/100)*100;
92 
93  $max_upload_resolution = floor($max_upload_width * $max_upload_height / (1000000));
94
95  // no need to display a limitation warning if the limitation is huge like 20MP
96  if ($max_upload_resolution < 25)
97  {
98    $template->assign(
99      array(
100        'max_upload_width' => $max_upload_width,
101        'max_upload_height' => $max_upload_height,
102        'max_upload_resolution' => $max_upload_resolution,
103        )
104      );
105  }
106}
107
108//warn the user if the picture will be resized after upload
109if ($conf['original_resize'])
110{
111  $template->assign(
112    array(
113        'original_resize_maxwidth' => $conf['original_resize_maxwidth'],
114        'original_resize_maxheight' => $conf['original_resize_maxheight'],
115      )
116    );
117}
118
119
120$upload_modes = array('html', 'multiple');
121$upload_mode = isset($conf['upload_mode']) ? $conf['upload_mode'] : 'multiple';
122
123if (isset($_GET['upload_mode']) and $upload_mode != $_GET['upload_mode'] and in_array($_GET['upload_mode'], $upload_modes))
124{
125  $upload_mode = $_GET['upload_mode'];
126  conf_update_param('upload_mode', $upload_mode);
127}
128
129// what is the upload switch mode
130$index_of_upload_mode = array_flip($upload_modes);
131$upload_mode_index = $index_of_upload_mode[$upload_mode];
132$upload_switch = $upload_modes[ ($upload_mode_index + 1) % 2 ];
133
134$template->assign(
135    array(
136      'upload_mode' => $upload_mode,
137      'form_action' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_mode.'&amp;processed=1',
138      'switch_url' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_switch,
139      'upload_id' => md5(rand()),
140      'session_id' => session_id(),
141      'pwg_token' => get_pwg_token(),
142      'another_upload_link' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_mode,
143    )
144  );
145
146$upload_file_types = 'jpeg, png, gif';
147
148if (pwg_image::get_library() == 'ext_imagick')
149{
150  $upload_file_types.= ', tiff';
151  $template->assign('tif_enabled', true);
152}
153
154if ('html' == $upload_mode)
155{
156  $upload_file_types.= ', zip';
157}
158$template->assign(
159  array(
160    'upload_file_types' => $upload_file_types,
161    )
162  );
163
164// +-----------------------------------------------------------------------+
165// | Categories                                                            |
166// +-----------------------------------------------------------------------+
167
168// we need to know the category in which the last photo was added
169$selected_category = array();
170
171if (isset($_GET['album']))
172{
173  // set the category from get url or ...
174  check_input_parameter('album', $_GET, false, PATTERN_ID);
175 
176  // test if album really exists
177  $query = '
178SELECT id
179  FROM '.CATEGORIES_TABLE.'
180  WHERE id = '.$_GET['album'].'
181;';
182  $result = pwg_query($query);
183  if (pwg_db_num_rows($result) == 1)
184  {
185    $selected_category = array($_GET['album']);
186   
187    // lets put in the session to persist in case of upload method switch
188    $_SESSION['selected_category'] = $selected_category;
189  }
190  else
191  {
192    fatal_error('[Hacking attempt] the album id = "'.$_GET['album'].'" is not valid');
193  }
194}
195else if (isset($_SESSION['selected_category']))
196{
197  $selected_category = $_SESSION['selected_category'];
198}
199else
200{
201  // we need to know the category in which the last photo was added
202  $query = '
203SELECT category_id
204  FROM '.IMAGES_TABLE.' AS i
205    JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = i.id
206    JOIN '.CATEGORIES_TABLE.' AS c ON category_id = c.id
207  ORDER BY i.id DESC
208  LIMIT 1
209;
210';
211  $result = pwg_query($query);
212  if (pwg_db_num_rows($result) > 0)
213  {
214    $row = pwg_db_fetch_assoc($result);
215    $selected_category = array($row['category_id']);
216  }
217}
218
219// existing album
220$query = '
221SELECT id,name,uppercats,global_rank
222  FROM '.CATEGORIES_TABLE.'
223;';
224
225display_select_cat_wrapper(
226  $query,
227  $selected_category,
228  'category_options'
229  );
230
231
232// image level options
233$selected_level = isset($_POST['level']) ? $_POST['level'] : 0;
234$template->assign(
235    array(
236      'level_options'=> get_privacy_level_options(),
237      'level_options_selected' => array($selected_level)
238    )
239  );
240
241// +-----------------------------------------------------------------------+
242// | Setup errors/warnings                                                 |
243// +-----------------------------------------------------------------------+
244
245// Errors
246$setup_errors = array();
247
248$error_message = ready_for_upload_message();
249if (!empty($error_message))
250{
251  $setup_errors[] = $error_message;
252}
253
254if (!function_exists('gd_info'))
255{
256  $setup_errors[] = l10n('GD library is missing');
257}
258
259$template->assign(
260  array(
261    'setup_errors'=> $setup_errors,
262    )
263  );
264
265// Warnings
266if (isset($_GET['hide_warnings']))
267{
268  $_SESSION['upload_hide_warnings'] = true;
269}
270
271if (!isset($_SESSION['upload_hide_warnings']))
272{
273  $setup_warnings = array();
274 
275  if ($conf['use_exif'] and !function_exists('read_exif_data'))
276  {
277    $setup_warnings[] = l10n('Exif extension not available, admin should disable exif use');
278  }
279
280  if (get_ini_size('upload_max_filesize') > get_ini_size('post_max_size'))
281  {
282    $setup_warnings[] = l10n(
283      'In your php.ini file, the upload_max_filesize (%sB) is bigger than post_max_size (%sB), you should change this setting',
284      get_ini_size('upload_max_filesize', false),
285      get_ini_size('post_max_size', false)
286      );
287  }
288  $template->assign(
289    array(
290      'setup_warnings' => $setup_warnings,
291      'hide_warnings_link' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_mode.'&amp;hide_warnings=1'
292      )
293    );
294}
295
296?>
Note: See TracBrowser for help on using the repository browser.