aboutsummaryrefslogtreecommitdiffstats
path: root/admin/picture_modify.php
blob: 5f59007277880ae4928b97a10ef1748c495b3520 (plain)
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
<?php
// +-----------------------------------------------------------------------+
// |                          picture_modify.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' );

//--------------------------------------------------------- update informations
$errors = array();
// first, we verify whether there is a mistake on the given creation date
if ( isset( $_POST['date_creation'] ) and !empty($_POST['date_creation']))
{
  if ( !check_date_format( $_POST['date_creation'] ) )
    array_push( $errors, $lang['err_date'] );
}
if ( isset( $_POST['submit'] ) )
{
  $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.= "'";
    foreach ( $keywords_array as $i => $keyword ) {
      if ( $i > 0 ) $query.= ',';
      $query.= $keyword;
    }
    $query.= "'";
  }

  $query.= ' WHERE id = '.$_GET['image_id'];
  $query.= ';';
  mysql_query( $query );
  // make the picture representative of a category ?
  $query = 'SELECT DISTINCT(category_id) as category_id';
  $query.= ',representative_picture_id';
  $query.= ' FROM '.IMAGE_CATEGORY_TABLE.' AS ic';
  $query.= ', '.CATEGORIES_TABLE.' AS c';
  $query.= ' WHERE c.id = ic.category_id';
  $query.= ' AND image_id = '.$_GET['image_id'];
  $query.= ';';
  $result = mysql_query( $query );
  while ( $row = mysql_fetch_array( $result ) )
  {
    // if the user ask the picture to be the representative picture of its
    // category, the category is updated in the database (without wondering
    // if this picture was already the representative one)
    if ( isset($_POST['representative-'.$row['category_id']]) )
    {
      $query = 'UPDATE '.CATEGORIES_TABLE;
      $query.= ' SET representative_picture_id = '.$_GET['image_id'];
      $query.= ' WHERE id = '.$row['category_id'];
      $query.= ';';
      mysql_query( $query );
    }
    // if the user ask this picture to be not any more the representative,
    // we have to set the representative_picture_id of this category to NULL
    else if ( isset( $row['representative_picture_id'] )
              and $row['representative_picture_id'] == $_GET['image_id'] )
    {
      $query = 'UPDATE '.CATEGORIES_TABLE;
      $query.= ' SET representative_picture_id = NULL';
      $query.= ' WHERE id = '.$row['category_id'];
      $query.= ';';
      mysql_query( $query );
    }
  }
  $associate_or_dissociate = false;
  // associate with a new category ?
  if ( $_POST['associate'] != '-1' 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'] );
    }
  }
  if ( $_POST['associate'] != '-1'
       and $_POST['associate'] != ''
       and count( $errors ) == 0 )
  {
    $query = 'INSERT INTO '.IMAGE_CATEGORY_TABLE;
    $query.= ' (category_id,image_id) VALUES ';
    $query.= '('.$_POST['associate'].','.$_GET['image_id'].')';
    $query.= ';';
    mysql_query( $query);
    $associate_or_dissociate = true;
    update_category( $_POST['associate'] );
  }
  // dissociate any category ?
  // retrieving all the linked categories
  $query = 'SELECT DISTINCT(category_id) as category_id FROM '.IMAGE_CATEGORY_TABLE;
  $query.= ' WHERE image_id = '.$_GET['image_id'];
  $query.= ';';
  $result = mysql_query( $query );
  while ( $row = mysql_fetch_array( $result ) )
  {
    if ( isset($_POST['dissociate-'.$row['category_id']]) )
    {
      $query = 'DELETE FROM '.IMAGE_CATEGORY_TABLE;
      $query.= ' WHERE image_id = '.$_GET['image_id'];
      $query.= ' AND category_id = '.$row['category_id'];
      $query.= ';';
      mysql_query( $query );
      $associate_or_dissociate = true;
      update_category( $row['category_id'] );
    }
  }
  if ( $associate_or_dissociate )
  {
    synchronize_all_users();
  }
}

// retrieving direct information about picture
$query = 'SELECT * FROM '.IMAGES_TABLE;
$query.= ' WHERE id = '.$_GET['image_id'];
$query.= ';';
$row = mysql_fetch_array( mysql_query( $query ) );

$title = empty($row['name'])?str_replace( '_',' ',get_filename_wo_extension($row['file']) ):$row['name'];
// Navigation path
$current_category = get_cat_info($row['storage_category_id']);
$dir_path = get_cat_display_name($current_category['name'], '-&gt;', '');

$thumbnail_url = get_complete_dir( $row['storage_category_id'] );
$file_wo_ext = get_filename_wo_extension( $row['file'] );
$thumbnail_url.= '/thumbnail/';
$thumbnail_url.= $conf['prefix_thumbnail'].$file_wo_ext.'.'.$row['tn_ext'];
$url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id'];
$url_img .= '&amp;cat='.$row['storage_category_id'];
$date = isset($_POST['date_creation']) && empty($errors)
          ?$_POST['date_creation']:date_convert_back($row['date_creation']);

// retrieving all the linked categories
$query = 'SELECT DISTINCT(category_id) as category_id,status,visible';
$query.= ',representative_picture_id';
$query.= ' FROM '.IMAGE_CATEGORY_TABLE.','.CATEGORIES_TABLE;
$query.= ' WHERE image_id = '.$_GET['image_id'];
$query.= ' AND category_id = id;';
$result = mysql_query( $query );
$categories = '';
while ( $cat_row = mysql_fetch_array( $result ) )
{
  $cat_infos = get_cat_info( $cat_row['category_id'] );
  $cat_name = get_cat_display_name( $cat_infos['name'], ' &gt; ', '' );
  $categories.='<option value="'.$cat_row['category_id'].'">'.$cat_name.'</option>';
}

//----------------------------------------------------- template initialization
$template->set_filenames( array('picture_modify'=>'admin/picture_modify.tpl') );
$template->assign_vars(array(
  'TITLE_IMG'=>$title,
  'DIR_IMG'=>$dir_path,
  'FILE_IMG'=>$row['file'],
  'TN_URL_IMG'=>$thumbnail_url,
  'URL_IMG'=>add_session_id( $url_img ),
  'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:$row['name'],
  'DEFAULT_NAME_IMG'=>str_replace( '_',' ',get_filename_wo_extension($row['file']) ),
  'FILE_IMG'=>$row['file'],
  'SIZE_IMG'=>$row['width'].' * '.$row['height'],
  'FILESIZE_IMG'=>$row['filesize'].' KB',
  'REGISTRATION_DATE_IMG'=> format_date($row['date_available']),
  'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:$row['author'],
  'CREATION_DATE_IMG'=>$date,
  'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:$row['keywords'],
  'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:$row['comment'],
  'ASSOCIATED_CATEGORIES'=>$categories,
  
  'L_UPLOAD_NAME'=>$lang['upload_name'],
  'L_DEFAULT'=>$lang['default'],
  'L_FILE'=>$lang['file'],
  'L_SIZE'=>$lang['size'],
  'L_FILESIZE'=>$lang['filesize'],
  'L_REGISTRATION_DATE'=>$lang['registration_date'],
  'L_AUTHOR'=>$lang['author'],
  'L_CREATION_DATE'=>$lang['creation_date'],
  'L_KEYWORDS'=>$lang['keywords'],
  'L_COMMENT'=>$lang['comment'],
  'L_CATEGORIES'=>$lang['categories'],
  'L_DISSOCIATE'=>$lang['dissociate'],
  'L_INFOIMAGE_ASSOCIATE'=>$lang['infoimage_associate'],
  'L_SUBMIT'=>$lang['submit'],
  
  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING'])
  ));
  
//-------------------------------------------------------------- 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]));
  }
}

// if there are linked category other than the storage category, we show
// propose the dissociate text
if ( mysql_num_rows( $result ) > 0 )
{
  //$vtp->addSession( $sub, 'dissociate' );
  //$vtp->closeSession( $sub, 'dissociate' );
}
// associate to another 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'] )
{
  $template->assign_block_vars('associate_LOV',array());
  $template->assign_block_vars('associate_LOV.associate_cat',array(
	));
  /*$vtp->addSession( $sub, 'associate_LOV' );
  $vtp->addSession( $sub, 'associate_cat' );
  $vtp->setVar( $sub, 'associate_cat.value', '-1' );
  $vtp->setVar( $sub, 'associate_cat.content', '' );
  $vtp->closeSession( $sub, 'associate_cat' );
  $page['plain_structure'] = get_plain_structure( true );
  $structure = create_structure( '', array() );
  display_categories( $structure, '&nbsp;' );
  $vtp->closeSession( $sub, 'associate_LOV' );*/
}

//----------------------------------------------------------- sending html code
$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
?>