1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2009 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 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
25 | { |
---|
26 | die ("Hacking attempt!"); |
---|
27 | } |
---|
28 | |
---|
29 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
30 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_waiting.inc.php'); |
---|
31 | |
---|
32 | // +-----------------------------------------------------------------------+ |
---|
33 | // | Check Access and exit when user status is not ok | |
---|
34 | // +-----------------------------------------------------------------------+ |
---|
35 | check_status(ACCESS_ADMINISTRATOR); |
---|
36 | |
---|
37 | //--------------------------------------------------------------------- updates |
---|
38 | |
---|
39 | if (isset($_POST)) |
---|
40 | { |
---|
41 | $to_validate = array(); |
---|
42 | $to_reject = array(); |
---|
43 | |
---|
44 | if (isset($_POST['submit'])) |
---|
45 | { |
---|
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 | } |
---|
66 | elseif (isset($_POST['validate-all']) and !empty($_POST['list'])) |
---|
67 | { |
---|
68 | $to_validate = explode(',', $_POST['list']); |
---|
69 | } |
---|
70 | elseif (isset($_POST['reject-all']) and !empty($_POST['list'])) |
---|
71 | { |
---|
72 | $to_reject = explode(',', $_POST['list']); |
---|
73 | } |
---|
74 | |
---|
75 | if (count($to_validate) > 0) |
---|
76 | { |
---|
77 | $query = ' |
---|
78 | UPDATE '.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 = ' |
---|
98 | SELECT 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)) |
---|
104 | { |
---|
105 | $dir = get_complete_dir($row['storage_category_id']); |
---|
106 | unlink($dir.$row['file']); |
---|
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) ) |
---|
115 | { |
---|
116 | unlink( $tn_path ); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | $query = ' |
---|
121 | DELETE |
---|
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 | ); |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | //----------------------------------------------------- template initialization |
---|
138 | $template->set_filenames(array('upload'=>'upload.tpl')); |
---|
139 | |
---|
140 | // TabSheet initialization |
---|
141 | waiting_tabsheet(); |
---|
142 | |
---|
143 | $template->assign(array( |
---|
144 | 'F_ACTION'=>str_replace( '&', '&', $_SERVER['REQUEST_URI']) |
---|
145 | )); |
---|
146 | |
---|
147 | //---------------------------------------------------------------- form display |
---|
148 | $cat_names = array(); |
---|
149 | $list = array(); |
---|
150 | |
---|
151 | $query = 'SELECT * FROM '.WAITING_TABLE; |
---|
152 | $query.= " WHERE validated = 'false'"; |
---|
153 | $query.= ' ORDER BY storage_category_id'; |
---|
154 | $query.= ';'; |
---|
155 | $result = pwg_query( $query ); |
---|
156 | while ( $row = mysql_fetch_array( $result ) ) |
---|
157 | { |
---|
158 | if ( !isset( $cat_names[$row['storage_category_id']] ) ) |
---|
159 | { |
---|
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'] = |
---|
163 | PHPWG_ROOT_PATH.get_complete_dir( $row['storage_category_id'] ); |
---|
164 | $cat_names[$row['storage_category_id']]['display_name'] = |
---|
165 | get_cat_display_name($cat['upper_names']); |
---|
166 | } |
---|
167 | $preview_url = PHPWG_ROOT_PATH.$cat_names[$row['storage_category_id']]['dir'].$row['file']; |
---|
168 | |
---|
169 | $tpl_var = |
---|
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'], |
---|
178 | 'PREVIEW_URL_IMG'=>$preview_url, |
---|
179 | 'UPLOAD_EMAIL'=>get_email_address_as_display_text($row['mail_address']), |
---|
180 | 'UPLOAD_USERNAME'=>$row['username'] |
---|
181 | ); |
---|
182 | |
---|
183 | // is there an existing associated thumnail ? |
---|
184 | if ( !empty( $row['tn_ext'] )) |
---|
185 | { |
---|
186 | $thumbnail = $conf['prefix_thumbnail']; |
---|
187 | $thumbnail.= get_filename_wo_extension( $row['file'] ); |
---|
188 | $thumbnail.= '.'.$row['tn_ext']; |
---|
189 | $url = $cat_names[$row['storage_category_id']]['dir']; |
---|
190 | $url.= $conf['dir_thumbnail'].'/'.$thumbnail; |
---|
191 | |
---|
192 | $tpl_var['thumbnail'] = |
---|
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 | ); |
---|
200 | } |
---|
201 | $template->append('pictures', $tpl_var); |
---|
202 | array_push($list, $row['id']); |
---|
203 | } |
---|
204 | |
---|
205 | $template->assign('LIST',implode(',', $list) ); |
---|
206 | |
---|
207 | //----------------------------------------------------------- sending html code |
---|
208 | $template->assign_var_from_handle('ADMIN_CONTENT', 'upload'); |
---|
209 | ?> |
---|