source: trunk/admin/element_set_global.php @ 755

Last change on this file since 755 was 755, checked in by plg, 20 years ago
  • new feature : caddie. The purpose is batch management, especially concerning elements to categories associations. This is the very first release, needs many improvements.
  • new function : array_from_query. Firstly used by "caddie" feature, it may be useful in many cases.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
RevLine 
[755]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-03-25 22:10:55 +0000 (Fri, 25 Mar 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 755 $
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
34$user['nb_image_line'] = 6; // temporary
35 
36if (!defined('PHPWG_ROOT_PATH'))
37{
38  die('Hacking attempt!');
39}
40include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
41
42// +-----------------------------------------------------------------------+
43// |                              empty caddie                             |
44// +-----------------------------------------------------------------------+
45if (isset($_GET['empty']))
46{
47  $query = '
48DELETE FROM '.CADDIE_TABLE.'
49  WHERE user_id = '.$user['id'].'
50;';
51  pwg_query($query);
52}
53
54// +-----------------------------------------------------------------------+
55// |                       global mode form submission                     |
56// +-----------------------------------------------------------------------+
57$errors = array();
58
59if (isset($_POST['submit']))
60{
61  $collection = array();
62 
63//   echo '<pre>';
64//   print_r($_POST['selection']);
65//   echo '</pre>';
66//   exit();
67
68  switch ($_POST['target'])
69  {
70    case 'all' :
71    {
72      $query = '
73SELECT element_id
74  FROM '.CADDIE_TABLE.'
75  WHERE user_id = '.$user['id'].'
76;';
77      $result = pwg_query($query);
78      while ($row = mysql_fetch_array($result))
79      {
80        array_push($collection, $row['element_id']);
81      }
82      break;
83    }
84    case 'selection' :
85    {
86      $collection = $_POST['selection'];
87      break;
88    }
89  }
90
91  if ($_POST['associate'] != 0)
92  {
93    $datas = array();
94   
95    foreach ($collection as $item)
96    {
97      array_push($datas,
98                 array('category_id'=>$_POST['associate'],
99                       'image_id'=>$item));
100    }
101 
102    // TODO : inserting an existing PK will fail
103    mass_inserts(IMAGE_CATEGORY_TABLE, array('image_id', 'category_id'), $datas);
104    update_category(array($_POST['associate']));
105  }
106
107  if ($_POST['dissociate'] != 0)
108  {
109    // physical links must be broken, so we must first retrieve image_id
110    // which create virtual links with the category to "dissociate from".
111    $query = '
112SELECT id
113  FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
114  WHERE category_id = '.$_POST['dissociate'].'
115    AND category_id != storage_category_id
116    AND id IN ('.implode(',', $collection).')
117;';
118    $dissociables = array_from_query($query, 'id');
119
120    $query = '
121DELETE FROM '.IMAGE_CATEGORY_TABLE.'
122  WHERE category_id = '.$_POST['dissociate'].'
123  AND image_id IN ('.implode(',', $dissociables).')
124';
125    pwg_query($query);
126
127    update_category(array($_POST['dissociate']));
128  }
129}
130
131// +-----------------------------------------------------------------------+
132// |                             template init                             |
133// +-----------------------------------------------------------------------+
134$template->set_filenames(
135  array('element_set_global' => 'admin/element_set_global.tpl'));
136
137$form_action = PHPWG_ROOT_PATH.'admin.php?page=element_set_global';
138
139$template->assign_vars(
140  array(
141    'L_SUBMIT'=>$lang['submit'],
142
143    'U_EMPTY_CADDIE'=>add_session_id($form_action.'&amp;empty=1'),
144   
145    'F_ACTION'=>add_session_id($form_action)
146   )
147 );
148// +-----------------------------------------------------------------------+
149// |                           global mode form                            |
150// +-----------------------------------------------------------------------+
151
152// Virtualy associate a picture to a category
153$blockname = 'associate_option';
154
155$template->assign_block_vars(
156  $blockname,
157  array('SELECTED' => '',
158        'VALUE'=> 0,
159        'OPTION' => '------------'
160    ));
161
162$query = '
163SELECT id,name,uppercats,global_rank
164  FROM '.CATEGORIES_TABLE.'
165;';
166display_select_cat_wrapper($query, array(), $blockname, true);
167
168// Dissociate from a category : categories listed for dissociation can
169// only represent virtual links. Links to physical categories can't be
170// broken
171$blockname = 'dissociate_option';
172
173$template->assign_block_vars(
174  $blockname,
175  array('SELECTED' => '',
176        'VALUE'=> 0,
177        'OPTION' => '------------'
178    ));
179
180$query = '
181SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank
182  FROM '.IMAGE_CATEGORY_TABLE.' AS ic,
183       '.CADDIE_TABLE.' AS caddie,
184       '.CATEGORIES_TABLE.' AS c,
185       '.IMAGES_TABLE.' AS i
186  WHERE ic.image_id = caddie.element_id
187    AND ic.category_id = c.id
188    AND ic.image_id = i.id
189    AND ic.category_id != i.storage_category_id
190    AND caddie.user_id = '.$user['id'].'
191;';
192display_select_cat_wrapper($query, array(), $blockname, true);
193
194// +-----------------------------------------------------------------------+
195// |                        global mode thumbnails                         |
196// +-----------------------------------------------------------------------+
197
198$query = '
199SELECT element_id,path,tn_ext
200  FROM '.IMAGES_TABLE.' INNER JOIN '.CADDIE_TABLE.' ON id=element_id
201  WHERE user_id = '.$user['id'].'
202  '.$conf['order_by'].'
203;';
204//echo '<pre>'.$query.'</pre>';
205$result = pwg_query($query);
206
207// template thumbnail initialization
208if (mysql_num_rows($result) > 0)
209{
210  $template->assign_block_vars('thumbnails', array());
211  // first line
212  $template->assign_block_vars('thumbnails.line', array());
213  // current row displayed
214  $row_number = 0;
215}
216
217while ($row = mysql_fetch_array($result))
218{
219  $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
220     
221  $template->assign_block_vars(
222    'thumbnails.line.thumbnail',
223    array(
224      'ID' => $row['element_id'],
225      'SRC' => $src,
226      'ALT' => 'TODO',
227      'TITLE' => 'TODO'
228      )
229    );
230 
231  // create a new line ?
232  if (++$row_number == $user['nb_image_line'])
233  {
234    $template->assign_block_vars('thumbnails.line', array());
235    $row_number = 0;
236  }
237}
238
239//----------------------------------------------------------- sending html code
240$template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global');
241?>
Note: See TracBrowser for help on using the repository browser.