source: trunk/admin/element_set_global.php @ 834

Last change on this file since 834 was 834, checked in by plg, 19 years ago
  • improvement : standardization of categories navigation bar on top of administration screen element_set_(global|unit), cat_modify, cat_list, cat_perm.
  • new : direct link to admin/cat_modify from category.php.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 KB
Line 
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$
9// | last update   : $Date: 2005-08-19 17:00:20 +0000 (Fri, 19 Aug 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 834 $
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/**
29 * Management of elements set. Elements can belong to a category or to the
30 * user caddie.
31 *
32 */
33 
34if (!defined('PHPWG_ROOT_PATH'))
35{
36  die('Hacking attempt!');
37}
38include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
39
40// +-----------------------------------------------------------------------+
41// |                               functions                               |
42// +-----------------------------------------------------------------------+
43
44/**
45 * returns the list of uniq keywords among given elements
46 *
47 * @param array element_ids
48 */
49function get_elements_keywords($element_ids)
50{
51  if (0 == count($element_ids))
52  {
53    return array();
54  }
55 
56  $keywords = array();
57 
58  $query = '
59SELECT keywords
60  FROM '.IMAGES_TABLE.'
61  WHERE id IN ('.implode(',', $element_ids).')
62;';
63  $result = pwg_query($query);
64  while ($row = mysql_fetch_array($result))
65  {
66    if (isset($row['keywords']) and !empty($row['keywords']))
67    {
68      $keywords = array_merge($keywords, explode(',', $row['keywords']));
69    }
70  }
71  return array_unique($keywords);
72}
73
74// +-----------------------------------------------------------------------+
75// |                       global mode form submission                     |
76// +-----------------------------------------------------------------------+
77
78if (isset($_POST['submit']))
79{
80  $collection = array();
81 
82//   echo '<pre>';
83//   print_r($_POST);
84//   echo '</pre>';
85//   exit();
86
87  switch ($_POST['target'])
88  {
89    case 'all' :
90    {
91      $collection = $page['cat_elements_id'];
92      break;
93    }
94    case 'selection' :
95    {
96      $collection = $_POST['selection'];
97      break;
98    }
99  }
100
101  if ($_POST['associate'] != 0)
102  {
103    $datas = array();
104
105    $query = '
106SELECT image_id
107  FROM '.IMAGE_CATEGORY_TABLE.'
108  WHERE category_id = '.$_POST['associate'].'
109;';
110    $associated = array_from_query($query, 'image_id');
111
112    // TODO : if $associable array is empty, no further actions
113    $associable = array_diff($collection, $associated);
114   
115    foreach ($associable as $item)
116    {
117      array_push($datas,
118                 array('category_id'=>$_POST['associate'],
119                       'image_id'=>$item));
120    }
121 
122    mass_inserts(IMAGE_CATEGORY_TABLE,
123                 array('image_id', 'category_id'),
124                 $datas);
125    update_category(array($_POST['associate']));
126  }
127
128  if ($_POST['dissociate'] != 0)
129  {
130    // physical links must not be broken, so we must first retrieve image_id
131    // which create virtual links with the category to "dissociate from".
132    $query = '
133SELECT id
134  FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
135  WHERE category_id = '.$_POST['dissociate'].'
136    AND category_id != storage_category_id
137    AND id IN ('.implode(',', $collection).')
138;';
139    $dissociables = array_from_query($query, 'id');
140
141    $query = '
142DELETE FROM '.IMAGE_CATEGORY_TABLE.'
143  WHERE category_id = '.$_POST['dissociate'].'
144  AND image_id IN ('.implode(',', $dissociables).')
145';
146    pwg_query($query);
147
148    update_category(array($_POST['dissociate']));
149  }
150
151  $datas = array();
152  $dbfields = array('primary' => array('id'), 'update' => array());
153
154  if (!empty($_POST['add_keywords']) or $_POST['remove_keyword'] != '0')
155  {
156    array_push($dbfields['update'], 'keywords');
157  }
158
159  $formfields = array('author', 'name', 'date_creation');
160  foreach ($formfields as $formfield)
161  {
162    if ($_POST[$formfield.'_action'] != 'leave')
163    {
164      array_push($dbfields['update'], $formfield);
165    }
166  }
167 
168  // updating elements is useful only if needed...
169  if (count($dbfields['update']) > 0)
170  {
171    $query = '
172SELECT id, keywords
173  FROM '.IMAGES_TABLE.'
174  WHERE id IN ('.implode(',', $collection).')
175;';
176    $result = pwg_query($query);
177
178    while ($row = mysql_fetch_array($result))
179    {
180      $data = array();
181      $data['id'] = $row['id'];
182     
183      if (!empty($_POST['add_keywords']))
184      {
185        $data['keywords'] =
186          implode(
187            ',',
188            array_unique(
189              array_merge(
190                get_keywords(empty($row['keywords']) ? '' : $row['keywords']),
191                get_keywords($_POST['add_keywords'])
192                )
193              )
194            );
195      }
196
197      if ($_POST['remove_keyword'] != '0')
198      {
199        if (!isset($data['keywords']))
200        {
201          $data['keywords'] = empty($row['keywords']) ? '' : $row['keywords'];
202        }
203       
204        $data['keywords'] =
205          implode(
206            ',',
207            array_unique(
208              array_diff(
209                get_keywords($data['keywords']),
210                array($_POST['remove_keyword'])
211                )
212              )
213            );
214
215        if ($data['keywords'] == '')
216        {
217          unset($data['keywords']);
218        }
219      }
220
221      if ('set' == $_POST['author_action'])
222      {
223        $data['author'] = $_POST['author'];
224
225        if ('' == $data['author'])
226        {
227          unset($data['author']);
228        }
229      }
230
231      if ('set' == $_POST['name_action'])
232      {
233        $data['name'] = $_POST['name'];
234
235        if ('' == $data['name'])
236        {
237          unset($data['name']);
238        }
239      }
240
241      if ('set' == $_POST['date_creation_action'])
242      {
243        $data['date_creation'] =
244          $_POST['date_creation_year']
245          .'-'.$_POST['date_creation_month']
246          .'-'.$_POST['date_creation_day']
247          ;
248      }
249     
250      array_push($datas, $data);
251    }
252    // echo '<pre>'; print_r($datas); echo '</pre>';
253    mass_updates(IMAGES_TABLE, $dbfields, $datas);
254  }
255}
256
257// +-----------------------------------------------------------------------+
258// |                             template init                             |
259// +-----------------------------------------------------------------------+
260$template->set_filenames(
261  array('element_set_global' => 'admin/element_set_global.tpl'));
262
263$base_url = PHPWG_ROOT_PATH.'admin.php';
264
265// $form_action = $base_url.'?page=element_set_global';
266
267$template->assign_vars(
268  array(
269    'CATEGORIES_NAV'=>$page['title'],
270   
271    'L_SUBMIT'=>$lang['submit'],
272
273    'U_COLS'=>$base_url.get_query_string_diff(array('cols')),
274    'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')),
275   
276    'U_UNIT_MODE'
277    =>
278    $base_url
279    .get_query_string_diff(array('mode','display'))
280    .'&amp;mode=unit',
281   
282    'F_ACTION'=>$base_url.get_query_string_diff(array()),
283   )
284 );
285
286// +-----------------------------------------------------------------------+
287// |                            caddie options                             |
288// +-----------------------------------------------------------------------+
289
290if ('caddie' == $_GET['cat'])
291{
292  $template->assign_block_vars('in_caddie', array());
293}
294else
295{
296  $template->assign_block_vars('not_in_caddie', array());
297}
298
299// +-----------------------------------------------------------------------+
300// |                           global mode form                            |
301// +-----------------------------------------------------------------------+
302
303// Virtualy associate a picture to a category
304$blockname = 'associate_option';
305
306$template->assign_block_vars(
307  $blockname,
308  array('SELECTED' => '',
309        'VALUE'=> 0,
310        'OPTION' => '------------'
311    ));
312
313$query = '
314SELECT id,name,uppercats,global_rank
315  FROM '.CATEGORIES_TABLE.'
316;';
317display_select_cat_wrapper($query, array(), $blockname, true);
318
319// Dissociate from a category : categories listed for dissociation can
320// only represent virtual links. Links to physical categories can't be
321// broken
322$blockname = 'dissociate_option';
323
324$template->assign_block_vars(
325  $blockname,
326  array('SELECTED' => '',
327        'VALUE'=> 0,
328        'OPTION' => '------------'
329    ));
330
331if (count($page['cat_elements_id']) > 0)
332{
333  $query = '
334SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank
335  FROM '.IMAGE_CATEGORY_TABLE.' AS ic,
336       '.CATEGORIES_TABLE.' AS c,
337       '.IMAGES_TABLE.' AS i
338  WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).')
339    AND ic.category_id = c.id
340    AND ic.image_id = i.id
341    AND ic.category_id != i.storage_category_id
342;';
343  display_select_cat_wrapper($query, array(), $blockname, true);
344}
345
346$blockname = 'remove_keyword_option';
347
348$template->assign_block_vars(
349  $blockname,
350  array('VALUE'=> 0,
351        'OPTION' => '------------'
352    ));
353
354$keywords = get_elements_keywords($page['cat_elements_id']);
355
356foreach ($keywords as $keyword)
357{
358  $template->assign_block_vars(
359  $blockname,
360  array('VALUE'=> $keyword,
361        'OPTION' => $keyword
362    ));
363}
364
365// creation date
366$day =
367empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day'];
368get_day_list('date_creation_day', $day);
369
370if (!empty($_POST['date_creation_month']))
371{
372  $month = $_POST['date_creation_month'];
373}
374else
375{
376  $month = date('n');
377}
378get_month_list('date_creation_month', $month);
379
380if (!empty($_POST['date_creation_year']))
381{
382  $year = $_POST['date_creation_year'];
383}
384else
385{
386  $year = date('Y');
387}
388$template->assign_vars(array('DATE_CREATION_YEAR_VALUE'=>$year));
389
390// +-----------------------------------------------------------------------+
391// |                        global mode thumbnails                         |
392// +-----------------------------------------------------------------------+
393
394$page['cols'] = !empty($_GET['cols']) ? intval($_GET['cols']) : 5;
395$page['nb_images'] = !empty($_GET['display']) ? intval($_GET['display']) : 20;
396
397if (count($page['cat_elements_id']) > 0)
398{
399  $nav_bar = create_navigation_bar(
400    $base_url.get_query_string_diff(array('start')),
401    count($page['cat_elements_id']),
402    $page['start'],
403    $page['nb_images'],
404    '');
405  $template->assign_vars(array('NAV_BAR' => $nav_bar));
406
407  $query = '
408SELECT id,path,tn_ext
409  FROM '.IMAGES_TABLE.'
410  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
411  '.$conf['order_by'].'
412  LIMIT '.$page['start'].', '.$page['nb_images'].'
413;';
414  //echo '<pre>'.$query.'</pre>';
415  $result = pwg_query($query);
416
417  // template thumbnail initialization
418  if (mysql_num_rows($result) > 0)
419  {
420    $template->assign_block_vars('thumbnails', array());
421    // first line
422    $template->assign_block_vars('thumbnails.line', array());
423    // current row displayed
424    $row_number = 0;
425  }
426
427  while ($row = mysql_fetch_array($result))
428  {
429    $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
430   
431    $template->assign_block_vars(
432      'thumbnails.line.thumbnail',
433      array(
434        'ID' => $row['id'],
435        'SRC' => $src,
436        'ALT' => 'TODO',
437        'TITLE' => 'TODO'
438        )
439      );
440   
441    // create a new line ?
442    if (++$row_number == $page['cols'])
443    {
444    $template->assign_block_vars('thumbnails.line', array());
445    $row_number = 0;
446    }
447  }
448}
449
450//----------------------------------------------------------- sending html code
451$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global');
452?>
Note: See TracBrowser for help on using the repository browser.