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

Last change on this file since 25593 was 25593, checked in by plg, 10 years ago

feature 3001: new link "add photos" on album edition page. Patch by msakik

File size: 8.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 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';
147if ('html' == $upload_mode)
148{
149  $upload_file_types.= ', zip';
150}
151$template->assign(
152  array(
153    'upload_file_types' => $upload_file_types,
154    )
155  );
156
157// +-----------------------------------------------------------------------+
158// | Categories                                                            |
159// +-----------------------------------------------------------------------+
160
161// we need to know the category in which the last photo was added
162$selected_category = array();
163
164if (isset($_GET['album']))
165{
166  // set the category from get url or ...
167  check_input_parameter('album', $_GET, false, PATTERN_ID);
168 
169  // test if album really exists
170  $query = '
171SELECT id
172  FROM '.CATEGORIES_TABLE.'
173  WHERE id = '.$_GET['album'].'
174;';
175  $result = pwg_query($query);
176  if (pwg_db_num_rows($result) == 1)
177  {
178    $selected_category = array($_GET['album']);
179   
180    // lets put in the session to persist in case of upload method switch
181    $_SESSION['selected_category'] = $selected_category;
182  }
183  else
184  {
185    fatal_error('[Hacking attempt] the album id = "'.$_GET['album'].'" is not valid');
186  }
187}
188else if (isset($_SESSION['selected_category']))
189{
190  $selected_category = $_SESSION['selected_category'];
191}
192else
193{
194  // we need to know the category in which the last photo was added
195  $query = '
196SELECT category_id
197  FROM '.IMAGES_TABLE.' AS i
198    JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = i.id
199    JOIN '.CATEGORIES_TABLE.' AS c ON category_id = c.id
200  ORDER BY i.id DESC
201  LIMIT 1
202;
203';
204  $result = pwg_query($query);
205  if (pwg_db_num_rows($result) > 0)
206  {
207    $row = pwg_db_fetch_assoc($result);
208    $selected_category = array($row['category_id']);
209  }
210}
211
212// existing album
213$query = '
214SELECT id,name,uppercats,global_rank
215  FROM '.CATEGORIES_TABLE.'
216;';
217
218display_select_cat_wrapper(
219  $query,
220  $selected_category,
221  'category_options'
222  );
223
224
225// image level options
226$selected_level = isset($_POST['level']) ? $_POST['level'] : 0;
227$template->assign(
228    array(
229      'level_options'=> get_privacy_level_options(),
230      'level_options_selected' => array($selected_level)
231    )
232  );
233
234// +-----------------------------------------------------------------------+
235// | Setup errors/warnings                                                 |
236// +-----------------------------------------------------------------------+
237
238// Errors
239$setup_errors = array();
240
241$error_message = ready_for_upload_message();
242if (!empty($error_message))
243{
244  $setup_errors[] = $error_message;
245}
246
247if (!function_exists('gd_info'))
248{
249  $setup_errors[] = l10n('GD library is missing');
250}
251
252$template->assign(
253  array(
254    'setup_errors'=> $setup_errors,
255    )
256  );
257
258// Warnings
259if (isset($_GET['hide_warnings']))
260{
261  $_SESSION['upload_hide_warnings'] = true;
262}
263
264if (!isset($_SESSION['upload_hide_warnings']))
265{
266  $setup_warnings = array();
267 
268  if ($conf['use_exif'] and !function_exists('read_exif_data'))
269  {
270    $setup_warnings[] = l10n('Exif extension not available, admin should disable exif use');
271  }
272
273  if (get_ini_size('upload_max_filesize') > get_ini_size('post_max_size'))
274  {
275    $setup_warnings[] = l10n(
276      'In your php.ini file, the upload_max_filesize (%sB) is bigger than post_max_size (%sB), you should change this setting',
277      get_ini_size('upload_max_filesize', false),
278      get_ini_size('post_max_size', false)
279      );
280  }
281  $template->assign(
282    array(
283      'setup_warnings' => $setup_warnings,
284      'hide_warnings_link' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_mode.'&amp;hide_warnings=1'
285      )
286    );
287}
288
289?>
Note: See TracBrowser for help on using the repository browser.