source: trunk/admin/waiting.php @ 1565

Last change on this file since 1565 was 1458, checked in by rub, 18 years ago

Resolved Issue ID 0000456, 0000457, 0000459, 0000465:

o Fix bugs adviser mode

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 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: 2006-07-11 20:51:24 +0000 (Tue, 11 Jul 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1458 $
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      if (isset($row['tn_ext']) and $row['tn_ext'] != '')
110      {
111        unlink(
112          get_thumbnail_src(
113            $dir.$row['file'],
114            $row['tn_ext']
115            )
116          );
117      }
118      else if (@is_file(get_thumbnail_src($dir.$row['file'], 'jpg')))
119      {
120        unlink(
121          get_thumbnail_src(
122            $dir.$row['file'],
123            'jpg'
124            )
125          );
126      }
127    }
128   
129    $query = '
130DELETE
131  FROM '.WAITING_TABLE.'
132  WHERE id IN ('.implode(',', $to_reject).')
133;';
134    pwg_query($query);
135
136    array_push(
137      $page['infos'],
138      sprintf(
139        l10n('%d waiting pictures rejected'),
140        count($to_reject)
141        )
142      );
143  }
144}
145
146//----------------------------------------------------- template initialization
147$template->set_filenames(array('waiting'=>'admin/waiting.tpl'));
148$template->assign_vars(array(
149  'L_AUTHOR'=>$lang['author'],
150  'L_THUMBNAIL'=>$lang['thumbnail'],
151  'L_DATE'=>$lang['date'],
152  'L_FILE'=>$lang['file'],
153  'L_CATEGORY'=>$lang['category'],
154  'L_SUBMIT'=>$lang['submit'],
155  'L_RESET'=>$lang['reset'],
156  'L_DELETE'=>$lang['delete'],
157 
158  'F_ACTION'=>str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'])
159  ));
160 
161//---------------------------------------------------------------- form display
162$cat_names = array();
163$list = array();
164
165$query = 'SELECT * FROM '.WAITING_TABLE;
166$query.= " WHERE validated = 'false'";
167$query.= ' ORDER BY storage_category_id';
168$query.= ';';
169$result = pwg_query( $query );
170$i = 0;
171while ( $row = mysql_fetch_array( $result ) )
172{
173  if ( !isset( $cat_names[$row['storage_category_id']] ) )
174  {
175    $cat = get_cat_info( $row['storage_category_id'] );
176    $cat_names[$row['storage_category_id']] = array();
177    $cat_names[$row['storage_category_id']]['dir'] =
178      PHPWG_ROOT_PATH.get_complete_dir( $row['storage_category_id'] );
179    $cat_names[$row['storage_category_id']]['display_name'] =
180      get_cat_display_name($cat['name']);
181  }
182  $preview_url = PHPWG_ROOT_PATH.$cat_names[$row['storage_category_id']]['dir'].$row['file'];
183  $class='row1';
184  if ( $i++ % 2== 0 ) $class='row2';
185 
186  $template->assign_block_vars(
187    'picture',
188    array(
189      'WAITING_CLASS'=>$class,
190      'CATEGORY_IMG'=>$cat_names[$row['storage_category_id']]['display_name'],
191      'ID_IMG'=>$row['id'],
192      'DATE_IMG' => date('Y-m-d H:i:s', $row['date']),
193      'FILE_TITLE'=>$row['file'],
194      'FILE_IMG' =>
195        (strlen($row['file']) > 10) ?
196          (substr($row['file'], 0, 10)).'...' : $row['file'],
197      'PREVIEW_URL_IMG'=>$preview_url, 
198      'UPLOAD_EMAIL'=>get_email_address_as_display_text($row['mail_address']),
199      'UPLOAD_USERNAME'=>$row['username']
200      )
201    );
202
203  // is there an existing associated thumnail ?
204  if ( !empty( $row['tn_ext'] ))
205  {
206    $thumbnail = $conf['prefix_thumbnail'];
207    $thumbnail.= get_filename_wo_extension( $row['file'] );
208    $thumbnail.= '.'.$row['tn_ext'];
209        $url = $cat_names[$row['storage_category_id']]['dir'];
210    $url.= 'thumbnail/'.$thumbnail;
211       
212    $template->assign_block_vars(
213      'picture.thumbnail',
214      array(
215        'PREVIEW_URL_TN_IMG' => $url,
216        'FILE_TN_IMG' =>
217          (strlen($thumbnail) > 10) ?
218            (substr($thumbnail, 0, 10)).'...' : $thumbnail,
219        'FILE_TN_TITLE' => $thumbnail
220        )
221      );
222  }
223
224  array_push($list, $row['id']);
225}
226
227$template->assign_vars(
228  array(
229    'LIST' => implode(',', $list)
230    )
231  );
232 
233//----------------------------------------------------------- sending html code
234$template->assign_var_from_handle('ADMIN_CONTENT', 'waiting');
235?>
Note: See TracBrowser for help on using the repository browser.