1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
<?php
// +-----------------------------------------------------------------------+
// | infos_images.php |
// +-----------------------------------------------------------------------+
// | application : PhpWebGallery <http://phpwebgallery.net> |
// | branch : BSF (Best So Far) |
// +-----------------------------------------------------------------------+
// | file : $RCSfile$
// | last update : $Date$
// | last modifier : $Author$
// | revision : $Revision$
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+
if( !defined("PHPWG_ROOT_PATH") )
{
die ("Hacking attempt!");
}
include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
//-------------------------------------------------------------- initialization
$page['nb_image_page'] = 5;
check_cat_id( $_GET['cat_id'] );
$errors = array();
if ( isset( $page['cat'] ) )
{
//--------------------------------------------------- update individual options
if ( isset( $_POST['submit'] ) )
{
if ( isset( $_POST['associate'] ) and $_POST['associate'] != '' )
{
// does the uppercat id exists in the database ?
if ( !is_numeric( $_POST['associate'] ) )
{
array_push( $errors, $lang['cat_unknown_id'] );
}
else
{
$query = 'SELECT id FROM '.CATEGORIES_TABLE;
$query.= ' WHERE id = '.$_POST['associate'];
$query.= ';';
if ( mysql_num_rows( mysql_query( $query ) ) == 0 )
array_push( $errors, $lang['cat_unknown_id'] );
}
}
$associate = false;
$query = 'SELECT id,file FROM '.IMAGES_TABLE;
$query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
$query.= ' WHERE category_id = '.$page['cat'];
$query.= ';';
$result = mysql_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
$name = 'name-'.$row['id'];
$author = 'author-'.$row['id'];
$comment = 'comment-'.$row['id'];
$date_creation = 'date_creation-'.$row['id'];
$keywords = 'keywords-'.$row['id'];
if ( isset( $_POST[$name] ) )
{
$query = 'UPDATE '.IMAGES_TABLE.' SET name = ';
if ( $_POST[$name] == '' )
$query.= 'NULL';
else
$query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'";
$query.= ', author = ';
if ( $_POST[$author] == '' )
$query.= 'NULL';
else
$query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
$query.= ', comment = ';
if ( $_POST[$comment] == '' )
$query.= 'NULL';
else
$query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
$query.= ', date_creation = ';
if ( check_date_format( $_POST[$date_creation] ) )
$query.= "'".date_convert( $_POST[$date_creation] )."'";
else if ( $_POST[$date_creation] == '' )
$query.= 'NULL';
$query.= ', keywords = ';
$keywords_array = get_keywords( $_POST[$keywords] );
if ( count( $keywords_array ) == 0 ) $query.= 'NULL';
else $query.= "'".implode( ',', $keywords_array )."'";
$query.= ' WHERE id = '.$row['id'];
$query.= ';';
mysql_query( $query );
}
// add link to another category
if ( isset( $_POST['check-'.$row['id']] ) and count( $errors ) == 0 )
{
$query = 'INSERT INTO '.IMAGE_CATEGORY_TABLE;
$query.= ' (image_id,category_id) VALUES';
$query.= ' ('.$row['id'].','.$_POST['associate'].')';
$query.= ';';
mysql_query( $query );
$associate = true;
}
}
if ( isset( $_POST['associate'] )) update_category( $_POST['associate'] );
if ( $associate ) synchronize_all_users();
//------------------------------------------------------ update general options
if ( isset( $_POST['use_common_author'] ) )
{
$query = 'SELECT image_id FROM '.IMAGE_CATEGORY_TABLE;
$query.= ' WHERE category_id = '.$page['cat'];
$result = mysql_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
$query = 'UPDATE '.IMAGES_TABLE;
if ( $_POST['author_cat'] == '' )
{
$query.= ' SET author = NULL';
}
else
{
$query.= ' SET author = ';
$query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'";
}
$query.= ' WHERE id = '.$row['image_id'];
$query.= ';';
mysql_query( $query );
}
}
if ( isset( $_POST['use_common_date_creation'] ) )
{
if ( check_date_format( $_POST['date_creation_cat'] ) )
{
$date = date_convert( $_POST['date_creation_cat'] );
$query = 'SELECT image_id FROM '.IMAGE_CATEGORY_TABLE;
$query.= ' WHERE category_id = '.$page['cat'];
$result = mysql_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
$query = 'UPDATE '.IMAGES_TABLE;
if ( $_POST['date_creation_cat'] == '' )
{
$query.= ' SET date_creation = NULL';
}
else
{
$query.= " SET date_creation = '".$date."'";
}
$query.= ' WHERE id = '.$row['image_id'];
$query.= ';';
mysql_query( $query );
}
}
else
{
array_push( $errors, $lang['err_date'] );
}
}
if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '' )
{
$query = 'SELECT id,keywords FROM '.IMAGES_TABLE;
$query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
$query.= ' WHERE category_id = '.$page['cat'];
$query.= ';';
$result = mysql_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
if ( !isset( $row['keywords'] ) ) $specific_keywords = array();
else $specific_keywords = explode( ',', $row['keywords'] );
$common_keywords = get_keywords( $_POST['keywords_cat'] );
// first possiblity : adding the given keywords to all the pictures
if ( $_POST['common_keywords'] == 'add' )
{
$keywords = array_merge( $specific_keywords, $common_keywords );
$keywords = array_unique( $keywords );
}
// second possiblity : removing the given keywords from all pictures
// (without deleting the other specific keywords
if ( $_POST['common_keywords'] == 'remove' )
{
$keywords = array_diff( $specific_keywords, $common_keywords );
}
// cleaning the keywords array, sometimes, an empty value still remain
$keywords = array_remove( $keywords, '' );
// updating the picture with new keywords array
$query = 'UPDATE '.IMAGES_TABLE.' SET keywords = ';
if ( count( $keywords ) == 0 )
{
$query.= 'NULL';
}
else
{
$query.= '"';
$i = 0;
foreach ( $keywords as $keyword ) {
if ( $i++ > 0 ) $query.= ',';
$query.= $keyword;
}
$query.= '"';
}
$query.= ' WHERE id = '.$row['id'];
$query.= ';';
mysql_query( $query );
}
}
}
//--------------------------------------------------------- form initialization
if( !isset( $_GET['start'] )
|| !is_numeric( $_GET['start'] )
|| ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
{
$page['start'] = 0;
}
else
{
$page['start'] = $_GET['start'];
}
if ( isset($_GET['num']) and is_numeric($_GET['num']) and $_GET['num'] >= 0 )
{
$page['start'] =
floor( $_GET['num'] / $page['nb_image_page'] ) * $page['nb_image_page'];
}
// Navigation path
$current_category = get_cat_info($_GET['cat_id']);
$url = PHPWG_ROOT_PATH.'admin.php?page=infos_images&cat_id=';
$category_path = get_cat_display_name($current_category['name'], '->', $url);
$form_action = PHPWG_ROOT_PATH.'admin.php?page=infos_images&cat_id='.$_GET['cat_id'];
if( $page['start'])
{
$form_action.= '&start='.$_GET['start'];
}
$nav_bar = create_navigation_bar(
$form_action, $current_category['nb_images'],$page['start'], $page['nb_image_page'], '' );
//----------------------------------------------------- template initialization
$template->set_filenames( array('infos_images'=>'admin/infos_images.tpl') );
$template->assign_vars(array(
'CATEGORY'=>$category_path,
'NAV_BAR'=>$nav_bar,
'L_INFOS_TITLE'=>$lang['infoimage_general'],
'L_AUTHOR'=>$lang['author'],
'L_INFOS_OVERALL_USE'=>$lang['infoimage_useforall'],
'L_INFOS_CREATION_DATE'=>$lang['infoimage_creation_date'],
'L_KEYWORD'=>$lang['keywords'],
'L_KEYWORD_SEPARATION'=>$lang['infoimage_keyword_separation'],
'L_INFOS_ADDTOALL'=>$lang['infoimage_addtoall'],
'L_INFOS_REMOVEFROMALL'=>$lang['infoimage_removefromall'],
'L_INFOS_DETAIL'=>$lang['infoimage_detailed'],
'L_THUMBNAIL'=>$lang['thumbnail'],
'L_INFOS_IMG'=>$lang['infoimage_title'],
'L_INFOS_COMMENT'=>$lang['comment'],
'L_INFOS_ASSOCIATE'=>$lang['infoimage_associate'],
'L_SUBMIT'=>$lang['submit'],
'F_ACTION'=>add_session_id($form_action)
));
//-------------------------------------------------------------- errors display
if ( sizeof( $errors ) != 0 )
{
$template->assign_block_vars('errors',array());
for ( $i = 0; $i < sizeof( $errors ); $i++ )
{
$template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
}
}
//------------------------------------------------------------------------ form
$array_cat_directories = array();
$infos = array( 'id','file','comment','author','tn_ext','name'
,'date_creation','keywords','storage_category_id'
,'category_id' );
$query = 'SELECT * FROM '.IMAGES_TABLE;
$query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
$query.= ' WHERE category_id = '.$page['cat'];
$query.= $conf['order_by'];
$query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
$query.= ';';
$result = mysql_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
foreach ($infos as $info) { if (!isset($row[$info])) $row[$info] = ''; }
if ( !isset( $array_cat_directories[$row['storage_category_id']] ) )
{
$array_cat_directories[$row['storage_category_id']] =
get_complete_dir( $row['storage_category_id'] );
}
$thumbnail_url = $array_cat_directories[$row['storage_category_id']];
$thumbnail_url.= 'thumbnail/';
$thumbnail_url.= $conf['prefix_thumbnail'].get_filename_wo_extension( $row['file'] ).".".$row['tn_ext'];
$template->assign_block_vars('picture' ,array(
'ID_IMG'=>$row['id'],
'URL_IMG'=>add_session_id( PHPWG_ROOT_PATH.'admin.php?page=picture_modify&image_id='.$row['id'] ),
'TN_URL_IMG'=>$thumbnail_url,
'FILENAME_IMG'=>$row['file'],
'DEFAULTNAME_IMG'=>get_filename_wo_extension( $row['file'] ),
'NAME_IMG'=>$row['name'],
'AUTHOR_IMG'=>$row['author'],
'DATE_IMG'=>date_convert_back( $row['date_creation'] ),
'KEYWORDS_IMG'=>$row['keywords'],
'COMMENT_IMG'=>$row['comment']
));
}
// Virtualy associate a picture to a category
//
// We only show a List Of Values if the number of categories is less than
// $conf['max_LOV_categories']
$query = 'SELECT COUNT(id) AS nb_total_categories';
$query.= ' FROM '.CATEGORIES_TABLE.';';
$row = mysql_fetch_array( mysql_query( $query ) );
if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
{
/*$vtp->addSession( $sub, 'associate_LOV' );
$page['plain_structure'] = get_plain_structure( true );
$structure = create_structure( '', array() );
display_categories( $structure, ' ' );
$vtp->closeSession( $sub, 'associate_LOV' );*/
}
// else, we only display a small text field, we suppose the administrator
// knows the id of its category
else
{
//$vtp->addSession( $sub, 'associate_text' );
//$vtp->closeSession( $sub, 'associate_text' );
}
}
//----------------------------------------------------------- sending html code
$template->assign_var_from_handle('ADMIN_CONTENT', 'infos_images');
?>
|