source: extensions/photo_update/admin.php @ 26023

Last change on this file since 26023 was 24624, checked in by plg, 11 years ago

bug fixed: load language at the right time so that the tab is always translated

File size: 6.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 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
24if( !defined("PHPWG_ROOT_PATH") )
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
31
32define('COMMUNITY_BASE_URL', get_root_url().'admin.php?page=plugin-community');
33
34// +-----------------------------------------------------------------------+
35// | Check Access and exit when user status is not ok                      |
36// +-----------------------------------------------------------------------+
37
38check_status(ACCESS_ADMINISTRATOR);
39
40// +-----------------------------------------------------------------------+
41// | Basic checks                                                          |
42// +-----------------------------------------------------------------------+
43
44$_GET['image_id'] = $_GET['tab'];
45
46check_input_parameter('image_id', $_GET, false, PATTERN_ID);
47
48$admin_photo_base_url = get_root_url().'admin.php?page=photo-'.$_GET['image_id'];
49
50// +-----------------------------------------------------------------------+
51// | Process form                                                          |
52// +-----------------------------------------------------------------------+
53
54if (isset($_FILES['photo_update']))
55{
56  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
57 
58  if ($_FILES['photo_update']['error'] !== UPLOAD_ERR_OK)
59  {
60    $error_message = file_upload_error_message($_FILES['photo_update']['error']);
61
62    array_push(
63      $page['errors'],
64      $error_message
65      );
66  }
67  else
68  {
69    $file_to_update = 'main';
70    if (isset($_POST['file_to_update']) and in_array($_POST['file_to_update'], array('main', 'representative')))
71    {
72      $file_to_update = $_POST['file_to_update'];
73    }
74
75    $image_id = $_GET['image_id'];
76     
77    $query = '
78SELECT
79    id, path, representative_ext
80  FROM '.IMAGES_TABLE.'
81  WHERE id = '.$image_id.'
82;';
83    $result = pwg_query($query);
84    $row = pwg_db_fetch_assoc($result);
85
86    if ('main' == $file_to_update)
87    {
88      add_uploaded_file(
89        $_FILES['photo_update']['tmp_name'],
90        $_FILES['photo_update']['name'],
91        null,
92        null,
93        $_GET['image_id']
94        );
95     
96      array_push(
97        $page['infos'],
98        l10n('The photo was updated')
99        );
100    }
101   
102    if ('representative' == $file_to_update)
103    {
104      $file_path = $row['path'];
105
106      // move the uploaded file to pwg_representative sub-directory
107      $representative_file_path = dirname($file_path).'/pwg_representative/';     
108      $representative_file_path.= get_filename_wo_extension(basename($file_path)).'.';
109
110      $old_representative_file_path = $representative_file_path.$row['representative_ext'];
111
112      $representative_ext = get_extension($_FILES['photo_update']['name']);
113
114      // in case we replace a *.jpg by *.png we have to safely remove the
115      // *.jpg becase move_uploaded_file won't remove it
116      if ($representative_ext != $row['representative_ext'])
117      {
118        @unlink($representative_file_path.$row['representative_ext']);
119      }
120     
121      $representative_file_path.= $representative_ext;
122
123      prepare_directory(dirname($representative_file_path));
124
125      move_uploaded_file($_FILES['photo_update']['tmp_name'], $representative_file_path);
126
127      $file_infos = pwg_image_infos($representative_file_path);
128     
129      single_update(
130        IMAGES_TABLE,
131        array(
132          'representative_ext' => $representative_ext,
133          'width' => $file_infos['width'],
134          'height' => $file_infos['height'],
135          ),
136        array('id' => $image_id)
137        );
138     
139      array_push(
140        $page['infos'],
141        l10n('The representative picture was updated')
142        );
143    }
144
145    // force refresh of multiple sizes
146    delete_element_derivatives($row);
147  }
148}
149
150// +-----------------------------------------------------------------------+
151// | Tabs                                                                  |
152// +-----------------------------------------------------------------------+
153
154include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
155
156$page['tab'] = 'update';
157
158$tabsheet = new tabsheet();
159$tabsheet->set_id('photo');
160$tabsheet->select('update');
161$tabsheet->assign();
162
163// +-----------------------------------------------------------------------+
164// |                             template init                             |
165// +-----------------------------------------------------------------------+
166
167$template->set_filenames(
168  array(
169    'plugin_admin_content' => dirname(__FILE__).'/admin.tpl'
170    )
171  );
172
173// retrieving direct information about picture
174$query = '
175SELECT *
176  FROM '.IMAGES_TABLE.'
177  WHERE id = '.$_GET['image_id'].'
178;';
179$row = pwg_db_fetch_assoc(pwg_query($query));
180
181if (!in_array(get_extension($row['path']), $conf['picture_ext']) or !empty($row['representative_ext']))
182{
183  $template->assign('show_file_to_update', true);
184}
185
186$template->assign(
187  array(
188    'TN_SRC' => DerivativeImage::thumb_url($row),
189    'original_filename' => $row['file'],
190    'TITLE' => render_element_name($row),
191    )
192  );
193
194// +-----------------------------------------------------------------------+
195// | sending html code                                                     |
196// +-----------------------------------------------------------------------+
197
198$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
199?>
Note: See TracBrowser for help on using the repository browser.