source: trunk/admin/waiting.php @ 1900

Last change on this file since 1900 was 1900, checked in by rub, 17 years ago

Apply property svn:eol-style Value: LF

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