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: upload.php 1915 2007-03-16 18:49:19Z rub $ |
---|
8 | // | last update : $Date: 2007-03-16 18:49:19 +0000 (Fri, 16 Mar 2007) $ |
---|
9 | // | last modifier : $Author: rub $ |
---|
10 | // | revision : $Revision: 1915 $ |
---|
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 | // +-----------------------------------------------------------------------+ |
---|
26 | |
---|
27 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
28 | { |
---|
29 | die ("Hacking attempt!"); |
---|
30 | } |
---|
31 | |
---|
32 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
33 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_waiting.inc.php'); |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | Check Access and exit when user status is not ok | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | check_status(ACCESS_ADMINISTRATOR); |
---|
39 | |
---|
40 | //--------------------------------------------------------------------- updates |
---|
41 | |
---|
42 | if (isset($_POST)) |
---|
43 | { |
---|
44 | $to_validate = array(); |
---|
45 | $to_reject = array(); |
---|
46 | |
---|
47 | if (isset($_POST['submit'])) |
---|
48 | { |
---|
49 | foreach (explode(',', $_POST['list']) as $waiting_id) |
---|
50 | { |
---|
51 | if (isset($_POST['action-'.$waiting_id])) |
---|
52 | { |
---|
53 | switch ($_POST['action-'.$waiting_id]) |
---|
54 | { |
---|
55 | case 'reject' : |
---|
56 | { |
---|
57 | array_push($to_reject, $waiting_id); |
---|
58 | break; |
---|
59 | } |
---|
60 | case 'validate' : |
---|
61 | { |
---|
62 | array_push($to_validate, $waiting_id); |
---|
63 | break; |
---|
64 | } |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
68 | } |
---|
69 | elseif (isset($_POST['validate-all']) and !empty($_POST['list'])) |
---|
70 | { |
---|
71 | $to_validate = explode(',', $_POST['list']); |
---|
72 | } |
---|
73 | elseif (isset($_POST['reject-all']) and !empty($_POST['list'])) |
---|
74 | { |
---|
75 | $to_reject = explode(',', $_POST['list']); |
---|
76 | } |
---|
77 | |
---|
78 | if (count($to_validate) > 0) |
---|
79 | { |
---|
80 | $query = ' |
---|
81 | UPDATE '.WAITING_TABLE.' |
---|
82 | SET validated = \'true\' |
---|
83 | WHERE id IN ('.implode(',', $to_validate).') |
---|
84 | ;'; |
---|
85 | pwg_query($query); |
---|
86 | |
---|
87 | array_push( |
---|
88 | $page['infos'], |
---|
89 | sprintf( |
---|
90 | l10n('%d waiting pictures validated'), |
---|
91 | count($to_validate) |
---|
92 | ) |
---|
93 | ); |
---|
94 | } |
---|
95 | |
---|
96 | if (count($to_reject) > 0) |
---|
97 | { |
---|
98 | // The uploaded element was refused, we have to delete its reference in |
---|
99 | // the database and to delete the element as well. |
---|
100 | $query = ' |
---|
101 | SELECT id, storage_category_id, file, tn_ext |
---|
102 | FROM '.WAITING_TABLE.' |
---|
103 | WHERE id IN ('.implode(',', $to_reject).') |
---|
104 | ;'; |
---|
105 | $result = pwg_query($query); |
---|
106 | while($row = mysql_fetch_array($result)) |
---|
107 | { |
---|
108 | $dir = get_complete_dir($row['storage_category_id']); |
---|
109 | unlink($dir.$row['file']); |
---|
110 | $element_info = array( |
---|
111 | 'path' => $dir.$row['file'], |
---|
112 | 'tn_ext' => |
---|
113 | (isset($row['tn_ext']) and $row['tn_ext']!='') ? $row['tn_ext']:'jpg' |
---|
114 | ); |
---|
115 | $tn_path = get_thumbnail_path( $element_info ); |
---|
116 | |
---|
117 | if ( @is_file($tn_path) ) |
---|
118 | { |
---|
119 | unlink( $tn_path ); |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | $query = ' |
---|
124 | DELETE |
---|
125 | FROM '.WAITING_TABLE.' |
---|
126 | WHERE id IN ('.implode(',', $to_reject).') |
---|
127 | ;'; |
---|
128 | pwg_query($query); |
---|
129 | |
---|
130 | array_push( |
---|
131 | $page['infos'], |
---|
132 | sprintf( |
---|
133 | l10n('%d waiting pictures rejected'), |
---|
134 | count($to_reject) |
---|
135 | ) |
---|
136 | ); |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | //----------------------------------------------------- template initialization |
---|
141 | $template->set_filenames(array('upload'=>'admin/upload.tpl')); |
---|
142 | |
---|
143 | // TabSheet initialization |
---|
144 | waiting_tabsheet(); |
---|
145 | |
---|
146 | $template->assign_vars(array( |
---|
147 | 'F_ACTION'=>str_replace( '&', '&', $_SERVER['REQUEST_URI']) |
---|
148 | )); |
---|
149 | |
---|
150 | //---------------------------------------------------------------- form display |
---|
151 | $cat_names = array(); |
---|
152 | $list = array(); |
---|
153 | |
---|
154 | $query = 'SELECT * FROM '.WAITING_TABLE; |
---|
155 | $query.= " WHERE validated = 'false'"; |
---|
156 | $query.= ' ORDER BY storage_category_id'; |
---|
157 | $query.= ';'; |
---|
158 | $result = pwg_query( $query ); |
---|
159 | $i = 0; |
---|
160 | while ( $row = mysql_fetch_array( $result ) ) |
---|
161 | { |
---|
162 | if ( !isset( $cat_names[$row['storage_category_id']] ) ) |
---|
163 | { |
---|
164 | $cat = get_cat_info( $row['storage_category_id'] ); |
---|
165 | $cat_names[$row['storage_category_id']] = array(); |
---|
166 | $cat_names[$row['storage_category_id']]['dir'] = |
---|
167 | PHPWG_ROOT_PATH.get_complete_dir( $row['storage_category_id'] ); |
---|
168 | $cat_names[$row['storage_category_id']]['display_name'] = |
---|
169 | get_cat_display_name($cat['upper_names']); |
---|
170 | } |
---|
171 | $preview_url = PHPWG_ROOT_PATH.$cat_names[$row['storage_category_id']]['dir'].$row['file']; |
---|
172 | $class='row1'; |
---|
173 | if ( $i++ % 2== 0 ) $class='row2'; |
---|
174 | |
---|
175 | $template->assign_block_vars( |
---|
176 | 'picture', |
---|
177 | array( |
---|
178 | 'WAITING_CLASS'=>$class, |
---|
179 | 'CATEGORY_IMG'=>$cat_names[$row['storage_category_id']]['display_name'], |
---|
180 | 'ID_IMG'=>$row['id'], |
---|
181 | 'DATE_IMG' => date('Y-m-d H:i:s', $row['date']), |
---|
182 | 'FILE_TITLE'=>$row['file'], |
---|
183 | 'FILE_IMG' => |
---|
184 | (strlen($row['file']) > 10) ? |
---|
185 | (substr($row['file'], 0, 10)).'...' : $row['file'], |
---|
186 | 'PREVIEW_URL_IMG'=>$preview_url, |
---|
187 | 'UPLOAD_EMAIL'=>get_email_address_as_display_text($row['mail_address']), |
---|
188 | 'UPLOAD_USERNAME'=>$row['username'] |
---|
189 | ) |
---|
190 | ); |
---|
191 | |
---|
192 | // is there an existing associated thumnail ? |
---|
193 | if ( !empty( $row['tn_ext'] )) |
---|
194 | { |
---|
195 | $thumbnail = $conf['prefix_thumbnail']; |
---|
196 | $thumbnail.= get_filename_wo_extension( $row['file'] ); |
---|
197 | $thumbnail.= '.'.$row['tn_ext']; |
---|
198 | $url = $cat_names[$row['storage_category_id']]['dir']; |
---|
199 | $url.= 'thumbnail/'.$thumbnail; |
---|
200 | |
---|
201 | $template->assign_block_vars( |
---|
202 | 'picture.thumbnail', |
---|
203 | array( |
---|
204 | 'PREVIEW_URL_TN_IMG' => $url, |
---|
205 | 'FILE_TN_IMG' => |
---|
206 | (strlen($thumbnail) > 10) ? |
---|
207 | (substr($thumbnail, 0, 10)).'...' : $thumbnail, |
---|
208 | 'FILE_TN_TITLE' => $thumbnail |
---|
209 | ) |
---|
210 | ); |
---|
211 | } |
---|
212 | |
---|
213 | array_push($list, $row['id']); |
---|
214 | } |
---|
215 | |
---|
216 | $template->assign_vars( |
---|
217 | array( |
---|
218 | 'LIST' => implode(',', $list) |
---|
219 | ) |
---|
220 | ); |
---|
221 | |
---|
222 | //----------------------------------------------------------- sending html code |
---|
223 | $template->assign_var_from_handle('ADMIN_CONTENT', 'upload'); |
---|
224 | ?> |
---|