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
RevLine 
[2]1<?php
[362]2// +-----------------------------------------------------------------------+
[2297]3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
[5196]5// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[1915]23
[520]24if( !defined("PHPWG_ROOT_PATH") )
25{
[696]26  die ("Hacking attempt!");
[520]27}
[1072]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
[26]36//--------------------------------------------------------------------- updates
[849]37
38if (isset($_POST))
[26]39{
[849]40  $to_validate = array();
41  $to_reject = array();
[1609]42
[849]43  if (isset($_POST['submit']))
[1609]44  {
[849]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  }
[1245]65  elseif (isset($_POST['validate-all']) and !empty($_POST['list']))
[26]66  {
[849]67    $to_validate = explode(',', $_POST['list']);
68  }
[1245]69  elseif (isset($_POST['reject-all']) and !empty($_POST['list']))
[849]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);
[4325]102    while($row = pwg_db_fetch_assoc($result))
[26]103    {
[849]104      $dir = get_complete_dir($row['storage_category_id']);
105      unlink($dir.$row['file']);
[1609]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) )
[26]114      {
[1609]115        unlink( $tn_path );
[26]116      }
117    }
[1609]118
[849]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      );
[26]133  }
134}
[520]135
[26]136//----------------------------------------------------- template initialization
[2530]137$template->set_filenames(array('upload'=>'upload.tpl'));
[1915]138
[2260]139$template->assign(array(
[1004]140  'F_ACTION'=>str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'])
[520]141  ));
[1609]142
[26]143//---------------------------------------------------------------- form display
144$cat_names = array();
[849]145$list = array();
146
[520]147$query = 'SELECT * FROM '.WAITING_TABLE;
[26]148$query.= " WHERE validated = 'false'";
[61]149$query.= ' ORDER BY storage_category_id';
[26]150$query.= ';';
[587]151$result = pwg_query( $query );
[4325]152while ( $row = pwg_db_fetch_assoc( $result ) )
[26]153{
[61]154  if ( !isset( $cat_names[$row['storage_category_id']] ) )
[26]155  {
[61]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'] =
[520]159      PHPWG_ROOT_PATH.get_complete_dir( $row['storage_category_id'] );
[61]160    $cat_names[$row['storage_category_id']]['display_name'] =
[1861]161      get_cat_display_name($cat['upper_names']);
[26]162  }
[520]163  $preview_url = PHPWG_ROOT_PATH.$cat_names[$row['storage_category_id']]['dir'].$row['file'];
[1609]164
[2260]165  $tpl_var =
[849]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'],
[1609]174      'PREVIEW_URL_IMG'=>$preview_url,
[1458]175      'UPLOAD_EMAIL'=>get_email_address_as_display_text($row['mail_address']),
[4304]176      'UPLOAD_USERNAME'=>stripslashes($row['username'])
[849]177    );
[520]178
[26]179  // is there an existing associated thumnail ?
[520]180  if ( !empty( $row['tn_ext'] ))
[26]181  {
182    $thumbnail = $conf['prefix_thumbnail'];
183    $thumbnail.= get_filename_wo_extension( $row['file'] );
184    $thumbnail.= '.'.$row['tn_ext'];
[520]185        $url = $cat_names[$row['storage_category_id']]['dir'];
[3720]186    $url.= $conf['dir_thumbnail'].'/'.$thumbnail;
[1609]187
[2260]188    $tpl_var['thumbnail'] =
[849]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      );
[26]196  }
[2260]197  $template->append('pictures', $tpl_var);
[849]198  array_push($list, $row['id']);
[26]199}
[849]200
[2260]201$template->assign('LIST',implode(',', $list) );
[1609]202
[26]203//----------------------------------------------------------- sending html code
[1915]204$template->assign_var_from_handle('ADMIN_CONTENT', 'upload');
[362]205?>
Note: See TracBrowser for help on using the repository browser.