source: trunk/admin/upload.php @ 2713

Last change on this file since 2713 was 2530, checked in by vdigital, 16 years ago

Wigo becomes "goto".
Admin tpl files are moved.

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