Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

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