source: tags/release-1_7_0RC1/admin/waiting.php @ 6883

Last change on this file since 6883 was 1754, checked in by rvelices, 17 years ago

some more language cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2007-01-25 02:56:51 +0000 (Thu, 25 Jan 2007) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1754 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27if( !defined("PHPWG_ROOT_PATH") )
28{
29  die ("Hacking attempt!");
30}
31
32include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
33
34// +-----------------------------------------------------------------------+
35// | Check Access and exit when user status is not ok                      |
36// +-----------------------------------------------------------------------+
37check_status(ACCESS_ADMINISTRATOR);
38
39//--------------------------------------------------------------------- updates
40
41if (isset($_POST))
42{
43  $to_validate = array();
44  $to_reject = array();
45
46  if (isset($_POST['submit']))
47  {
48    foreach (explode(',', $_POST['list']) as $waiting_id)
49    {
50      if (isset($_POST['action-'.$waiting_id]))
51      {
52        switch ($_POST['action-'.$waiting_id])
53        {
54          case 'reject' :
55          {
56            array_push($to_reject, $waiting_id);
57            break;
58          }
59          case 'validate' :
60          {
61            array_push($to_validate, $waiting_id);
62            break;
63          }
64        }
65      }
66    }
67  }
68  elseif (isset($_POST['validate-all']) and !empty($_POST['list']))
69  {
70    $to_validate = explode(',', $_POST['list']);
71  }
72  elseif (isset($_POST['reject-all']) and !empty($_POST['list']))
73  {
74    $to_reject = explode(',', $_POST['list']);
75  }
76
77  if (count($to_validate) > 0)
78  {
79    $query = '
80UPDATE '.WAITING_TABLE.'
81  SET validated = \'true\'
82  WHERE id IN ('.implode(',', $to_validate).')
83;';
84    pwg_query($query);
85
86    array_push(
87      $page['infos'],
88      sprintf(
89        l10n('%d waiting pictures validated'),
90        count($to_validate)
91        )
92      );
93  }
94
95  if (count($to_reject) > 0)
96  {
97    // The uploaded element was refused, we have to delete its reference in
98    // the database and to delete the element as well.
99    $query = '
100SELECT id, storage_category_id, file, tn_ext
101  FROM '.WAITING_TABLE.'
102  WHERE id IN ('.implode(',', $to_reject).')
103;';
104    $result = pwg_query($query);
105    while($row = mysql_fetch_array($result))
106    {
107      $dir = get_complete_dir($row['storage_category_id']);
108      unlink($dir.$row['file']);
109      $element_info = array(
110        'path' => $dir.$row['file'],
111        'tn_ext' =>
112          (isset($row['tn_ext']) and $row['tn_ext']!='') ? $row['tn_ext']:'jpg'
113        );
114      $tn_path = get_thumbnail_path( $element_info );
115
116      if ( @is_file($tn_path) )
117      {
118        unlink( $tn_path );
119      }
120    }
121
122    $query = '
123DELETE
124  FROM '.WAITING_TABLE.'
125  WHERE id IN ('.implode(',', $to_reject).')
126;';
127    pwg_query($query);
128
129    array_push(
130      $page['infos'],
131      sprintf(
132        l10n('%d waiting pictures rejected'),
133        count($to_reject)
134        )
135      );
136  }
137}
138
139//----------------------------------------------------- template initialization
140$template->set_filenames(array('waiting'=>'admin/waiting.tpl'));
141$template->assign_vars(array(
142  'F_ACTION'=>str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'])
143  ));
144
145//---------------------------------------------------------------- form display
146$cat_names = array();
147$list = array();
148
149$query = 'SELECT * FROM '.WAITING_TABLE;
150$query.= " WHERE validated = 'false'";
151$query.= ' ORDER BY storage_category_id';
152$query.= ';';
153$result = pwg_query( $query );
154$i = 0;
155while ( $row = mysql_fetch_array( $result ) )
156{
157  if ( !isset( $cat_names[$row['storage_category_id']] ) )
158  {
159    $cat = get_cat_info( $row['storage_category_id'] );
160    $cat_names[$row['storage_category_id']] = array();
161    $cat_names[$row['storage_category_id']]['dir'] =
162      PHPWG_ROOT_PATH.get_complete_dir( $row['storage_category_id'] );
163    $cat_names[$row['storage_category_id']]['display_name'] =
164      get_cat_display_name($cat['name']);
165  }
166  $preview_url = PHPWG_ROOT_PATH.$cat_names[$row['storage_category_id']]['dir'].$row['file'];
167  $class='row1';
168  if ( $i++ % 2== 0 ) $class='row2';
169
170  $template->assign_block_vars(
171    'picture',
172    array(
173      'WAITING_CLASS'=>$class,
174      'CATEGORY_IMG'=>$cat_names[$row['storage_category_id']]['display_name'],
175      'ID_IMG'=>$row['id'],
176      'DATE_IMG' => date('Y-m-d H:i:s', $row['date']),
177      'FILE_TITLE'=>$row['file'],
178      'FILE_IMG' =>
179        (strlen($row['file']) > 10) ?
180          (substr($row['file'], 0, 10)).'...' : $row['file'],
181      'PREVIEW_URL_IMG'=>$preview_url,
182      'UPLOAD_EMAIL'=>get_email_address_as_display_text($row['mail_address']),
183      'UPLOAD_USERNAME'=>$row['username']
184      )
185    );
186
187  // is there an existing associated thumnail ?
188  if ( !empty( $row['tn_ext'] ))
189  {
190    $thumbnail = $conf['prefix_thumbnail'];
191    $thumbnail.= get_filename_wo_extension( $row['file'] );
192    $thumbnail.= '.'.$row['tn_ext'];
193        $url = $cat_names[$row['storage_category_id']]['dir'];
194    $url.= 'thumbnail/'.$thumbnail;
195
196    $template->assign_block_vars(
197      'picture.thumbnail',
198      array(
199        'PREVIEW_URL_TN_IMG' => $url,
200        'FILE_TN_IMG' =>
201          (strlen($thumbnail) > 10) ?
202            (substr($thumbnail, 0, 10)).'...' : $thumbnail,
203        'FILE_TN_TITLE' => $thumbnail
204        )
205      );
206  }
207
208  array_push($list, $row['id']);
209}
210
211$template->assign_vars(
212  array(
213    'LIST' => implode(',', $list)
214    )
215  );
216
217//----------------------------------------------------------- sending html code
218$template->assign_var_from_handle('ADMIN_CONTENT', 'waiting');
219?>
Note: See TracBrowser for help on using the repository browser.