source: trunk/admin/upload.php @ 6348

Last change on this file since 6348 was 6348, checked in by plg, 14 years ago

merge r6347 from branch 2.1 to trunk

bug 1672: replace the language key where it's used.

File size: 6.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2010 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');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
36//--------------------------------------------------------------------- updates
37
38if (isset($_POST))
39{
40  $to_validate = array();
41  $to_reject = array();
42
43  if (isset($_POST['submit']))
44  {
45    foreach (explode(',', $_POST['list']) as $waiting_id)
46    {
47      if (isset($_POST['action-'.$waiting_id]))
48      {
49        switch ($_POST['action-'.$waiting_id])
50        {
51          case 'reject' :
52          {
53            array_push($to_reject, $waiting_id);
54            break;
55          }
56          case 'validate' :
57          {
58            array_push($to_validate, $waiting_id);
59            break;
60          }
61        }
62      }
63    }
64  }
65  elseif (isset($_POST['validate-all']) and !empty($_POST['list']))
66  {
67    $to_validate = explode(',', $_POST['list']);
68  }
69  elseif (isset($_POST['reject-all']) and !empty($_POST['list']))
70  {
71    $to_reject = explode(',', $_POST['list']);
72  }
73
74  if (count($to_validate) > 0)
75  {
76    $query = '
77UPDATE '.WAITING_TABLE.'
78  SET validated = \'true\'
79  WHERE id IN ('.implode(',', $to_validate).')
80;';
81    pwg_query($query);
82
83    array_push(
84      $page['infos'],
85      sprintf(
86        l10n('%d waiting pictures validated'),
87        count($to_validate)
88        )
89      );
90  }
91
92  if (count($to_reject) > 0)
93  {
94    // The uploaded element was refused, we have to delete its reference in
95    // the database and to delete the element as well.
96    $query = '
97SELECT id, storage_category_id, file, tn_ext
98  FROM '.WAITING_TABLE.'
99  WHERE id IN ('.implode(',', $to_reject).')
100;';
101    $result = pwg_query($query);
102    while($row = pwg_db_fetch_assoc($result))
103    {
104      $dir = get_complete_dir($row['storage_category_id']);
105      unlink($dir.$row['file']);
106      $element_info = array(
107        'path' => $dir.$row['file'],
108        'tn_ext' =>
109          (isset($row['tn_ext']) and $row['tn_ext']!='') ? $row['tn_ext']:'jpg'
110        );
111      $tn_path = get_thumbnail_path( $element_info );
112
113      if ( @is_file($tn_path) )
114      {
115        unlink( $tn_path );
116      }
117    }
118
119    $query = '
120DELETE
121  FROM '.WAITING_TABLE.'
122  WHERE id IN ('.implode(',', $to_reject).')
123;';
124    pwg_query($query);
125
126    array_push(
127      $page['infos'],
128      sprintf(
129        l10n('%d waiting pictures rejected'),
130        count($to_reject)
131        )
132      );
133  }
134}
135
136//----------------------------------------------------- template initialization
137$template->set_filenames(array('upload'=>'upload.tpl'));
138
139$template->assign(array(
140  'F_ACTION'=>str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'])
141  ));
142
143//---------------------------------------------------------------- form display
144$cat_names = array();
145$list = array();
146
147$query = 'SELECT * FROM '.WAITING_TABLE;
148$query.= " WHERE validated = 'false'";
149$query.= ' ORDER BY storage_category_id';
150$query.= ';';
151$result = pwg_query( $query );
152while ( $row = pwg_db_fetch_assoc( $result ) )
153{
154  if ( !isset( $cat_names[$row['storage_category_id']] ) )
155  {
156    $cat = get_cat_info( $row['storage_category_id'] );
157    $cat_names[$row['storage_category_id']] = array();
158    $cat_names[$row['storage_category_id']]['dir'] =
159      PHPWG_ROOT_PATH.get_complete_dir( $row['storage_category_id'] );
160    $cat_names[$row['storage_category_id']]['display_name'] =
161      get_cat_display_name($cat['upper_names']);
162  }
163  $preview_url = PHPWG_ROOT_PATH.$cat_names[$row['storage_category_id']]['dir'].$row['file'];
164
165  $tpl_var =
166    array(
167      'CATEGORY_IMG'=>$cat_names[$row['storage_category_id']]['display_name'],
168      'ID_IMG'=>$row['id'],
169      'DATE_IMG' => date('Y-m-d H:i:s', $row['date']),
170      'FILE_TITLE'=>$row['file'],
171      'FILE_IMG' =>
172        (strlen($row['file']) > 10) ?
173          (substr($row['file'], 0, 10)).'...' : $row['file'],
174      'PREVIEW_URL_IMG'=>$preview_url,
175      'UPLOAD_EMAIL'=>get_email_address_as_display_text($row['mail_address']),
176      'UPLOAD_USERNAME'=>stripslashes($row['username'])
177    );
178
179  // is there an existing associated thumnail ?
180  if ( !empty( $row['tn_ext'] ))
181  {
182    $thumbnail = $conf['prefix_thumbnail'];
183    $thumbnail.= get_filename_wo_extension( $row['file'] );
184    $thumbnail.= '.'.$row['tn_ext'];
185        $url = $cat_names[$row['storage_category_id']]['dir'];
186    $url.= $conf['dir_thumbnail'].'/'.$thumbnail;
187
188    $tpl_var['thumbnail'] =
189      array(
190        'PREVIEW_URL_TN_IMG' => $url,
191        'FILE_TN_IMG' =>
192          (strlen($thumbnail) > 10) ?
193            (substr($thumbnail, 0, 10)).'...' : $thumbnail,
194        'FILE_TN_TITLE' => $thumbnail
195      );
196  }
197  $template->append('pictures', $tpl_var);
198  array_push($list, $row['id']);
199}
200
201$template->assign('LIST',implode(',', $list) );
202
203//----------------------------------------------------------- sending html code
204$template->assign_var_from_handle('ADMIN_CONTENT', 'upload');
205?>
Note: See TracBrowser for help on using the repository browser.