[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: 2006-05-15 20:53:08 +0000 (Mon, 15 May 2006) $ |
---|
| 10 | // | last modifier : $Author: plg $ |
---|
| 11 | // | revision : $Revision: 1308 $ |
---|
| 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. |
---|
[1092] | 31 | * |
---|
[755] | 32 | */ |
---|
[1092] | 33 | |
---|
[755] | 34 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 35 | { |
---|
| 36 | die('Hacking attempt!'); |
---|
| 37 | } |
---|
| 38 | |
---|
[1072] | 39 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 40 | |
---|
[755] | 41 | // +-----------------------------------------------------------------------+ |
---|
[1072] | 42 | // | Check Access and exit when user status is not ok | |
---|
| 43 | // +-----------------------------------------------------------------------+ |
---|
| 44 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 45 | |
---|
| 46 | // +-----------------------------------------------------------------------+ |
---|
[755] | 47 | // | global mode form submission | |
---|
| 48 | // +-----------------------------------------------------------------------+ |
---|
| 49 | |
---|
| 50 | if (isset($_POST['submit'])) |
---|
| 51 | { |
---|
| 52 | $collection = array(); |
---|
[1092] | 53 | |
---|
[755] | 54 | // echo '<pre>'; |
---|
[762] | 55 | // print_r($_POST); |
---|
[755] | 56 | // echo '</pre>'; |
---|
| 57 | // exit(); |
---|
| 58 | |
---|
| 59 | switch ($_POST['target']) |
---|
| 60 | { |
---|
| 61 | case 'all' : |
---|
| 62 | { |
---|
[764] | 63 | $collection = $page['cat_elements_id']; |
---|
[755] | 64 | break; |
---|
| 65 | } |
---|
| 66 | case 'selection' : |
---|
| 67 | { |
---|
[875] | 68 | if (!isset($_POST['selection']) or count($_POST['selection']) == 0) |
---|
| 69 | { |
---|
| 70 | array_push($page['errors'], l10n('Select at least one picture')); |
---|
| 71 | } |
---|
| 72 | else |
---|
| 73 | { |
---|
| 74 | $collection = $_POST['selection']; |
---|
| 75 | } |
---|
[755] | 76 | break; |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | |
---|
[1119] | 80 | if (isset($_POST['add_tags']) and count($collection) > 0) |
---|
| 81 | { |
---|
| 82 | add_tags($_POST['add_tags'], $collection); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | if (isset($_POST['del_tags']) and count($collection) > 0) |
---|
| 86 | { |
---|
| 87 | $query = ' |
---|
| 88 | DELETE |
---|
| 89 | FROM '.IMAGE_TAG_TABLE.' |
---|
| 90 | WHERE image_id IN ('.implode(',', $collection).') |
---|
| 91 | AND tag_id IN ('.implode(',', $_POST['del_tags']).') |
---|
| 92 | ;'; |
---|
| 93 | pwg_query($query); |
---|
| 94 | } |
---|
[1120] | 95 | |
---|
[875] | 96 | if ($_POST['associate'] != 0 and count($collection) > 0) |
---|
[755] | 97 | { |
---|
[1121] | 98 | associate_images_to_categories( |
---|
| 99 | $collection, |
---|
| 100 | array($_POST['associate']) |
---|
| 101 | ); |
---|
[755] | 102 | } |
---|
| 103 | |
---|
[875] | 104 | if ($_POST['dissociate'] != 0 and count($collection) > 0) |
---|
[755] | 105 | { |
---|
[1121] | 106 | // physical links must not be broken, so we must first retrieve image_id |
---|
| 107 | // which create virtual links with the category to "dissociate from". |
---|
[755] | 108 | $query = ' |
---|
[1121] | 109 | SELECT id |
---|
[1065] | 110 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
[1121] | 111 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
[755] | 112 | WHERE category_id = '.$_POST['dissociate'].' |
---|
[1121] | 113 | AND id IN ('.implode(',', $collection).') |
---|
| 114 | AND category_id != storage_category_id |
---|
[755] | 115 | ;'; |
---|
[1121] | 116 | $dissociables = array_from_query($query, 'id'); |
---|
[755] | 117 | |
---|
| 118 | $query = ' |
---|
[1065] | 119 | DELETE |
---|
| 120 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
[1121] | 121 | WHERE category_id = '.$_POST['dissociate'].' |
---|
| 122 | AND image_id IN ('.implode(',', $dissociables).') |
---|
[755] | 123 | '; |
---|
| 124 | pwg_query($query); |
---|
[1121] | 125 | |
---|
| 126 | update_category($_POST['dissociate']); |
---|
[755] | 127 | } |
---|
[762] | 128 | |
---|
| 129 | $datas = array(); |
---|
| 130 | $dbfields = array('primary' => array('id'), 'update' => array()); |
---|
| 131 | |
---|
| 132 | $formfields = array('author', 'name', 'date_creation'); |
---|
| 133 | foreach ($formfields as $formfield) |
---|
| 134 | { |
---|
| 135 | if ($_POST[$formfield.'_action'] != 'leave') |
---|
| 136 | { |
---|
| 137 | array_push($dbfields['update'], $formfield); |
---|
| 138 | } |
---|
| 139 | } |
---|
[1092] | 140 | |
---|
[762] | 141 | // updating elements is useful only if needed... |
---|
[875] | 142 | if (count($dbfields['update']) > 0 and count($collection) > 0) |
---|
[762] | 143 | { |
---|
| 144 | $query = ' |
---|
[1119] | 145 | SELECT id |
---|
[762] | 146 | FROM '.IMAGES_TABLE.' |
---|
| 147 | WHERE id IN ('.implode(',', $collection).') |
---|
| 148 | ;'; |
---|
| 149 | $result = pwg_query($query); |
---|
| 150 | |
---|
| 151 | while ($row = mysql_fetch_array($result)) |
---|
| 152 | { |
---|
| 153 | $data = array(); |
---|
| 154 | $data['id'] = $row['id']; |
---|
[1092] | 155 | |
---|
[762] | 156 | if ('set' == $_POST['author_action']) |
---|
| 157 | { |
---|
| 158 | $data['author'] = $_POST['author']; |
---|
| 159 | |
---|
| 160 | if ('' == $data['author']) |
---|
| 161 | { |
---|
| 162 | unset($data['author']); |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | if ('set' == $_POST['name_action']) |
---|
| 167 | { |
---|
| 168 | $data['name'] = $_POST['name']; |
---|
| 169 | |
---|
| 170 | if ('' == $data['name']) |
---|
| 171 | { |
---|
| 172 | unset($data['name']); |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | if ('set' == $_POST['date_creation_action']) |
---|
| 177 | { |
---|
| 178 | $data['date_creation'] = |
---|
| 179 | $_POST['date_creation_year'] |
---|
| 180 | .'-'.$_POST['date_creation_month'] |
---|
| 181 | .'-'.$_POST['date_creation_day'] |
---|
| 182 | ; |
---|
| 183 | } |
---|
[1092] | 184 | |
---|
[762] | 185 | array_push($datas, $data); |
---|
| 186 | } |
---|
[763] | 187 | // echo '<pre>'; print_r($datas); echo '</pre>'; |
---|
[762] | 188 | mass_updates(IMAGES_TABLE, $dbfields, $datas); |
---|
| 189 | } |
---|
[755] | 190 | } |
---|
| 191 | |
---|
| 192 | // +-----------------------------------------------------------------------+ |
---|
| 193 | // | template init | |
---|
| 194 | // +-----------------------------------------------------------------------+ |
---|
| 195 | $template->set_filenames( |
---|
| 196 | array('element_set_global' => 'admin/element_set_global.tpl')); |
---|
| 197 | |
---|
[762] | 198 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
[755] | 199 | |
---|
[762] | 200 | // $form_action = $base_url.'?page=element_set_global'; |
---|
| 201 | |
---|
[755] | 202 | $template->assign_vars( |
---|
| 203 | array( |
---|
[834] | 204 | 'CATEGORIES_NAV'=>$page['title'], |
---|
[1092] | 205 | |
---|
[755] | 206 | 'L_SUBMIT'=>$lang['submit'], |
---|
| 207 | |
---|
[764] | 208 | 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), |
---|
[1092] | 209 | |
---|
[764] | 210 | 'U_UNIT_MODE' |
---|
| 211 | => |
---|
| 212 | $base_url |
---|
| 213 | .get_query_string_diff(array('mode','display')) |
---|
| 214 | .'&mode=unit', |
---|
[1092] | 215 | |
---|
[762] | 216 | 'F_ACTION'=>$base_url.get_query_string_diff(array()), |
---|
[755] | 217 | ) |
---|
| 218 | ); |
---|
[764] | 219 | |
---|
[755] | 220 | // +-----------------------------------------------------------------------+ |
---|
[764] | 221 | // | caddie options | |
---|
| 222 | // +-----------------------------------------------------------------------+ |
---|
| 223 | |
---|
| 224 | if ('caddie' == $_GET['cat']) |
---|
| 225 | { |
---|
| 226 | $template->assign_block_vars('in_caddie', array()); |
---|
| 227 | } |
---|
| 228 | else |
---|
| 229 | { |
---|
| 230 | $template->assign_block_vars('not_in_caddie', array()); |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | // +-----------------------------------------------------------------------+ |
---|
[755] | 234 | // | global mode form | |
---|
| 235 | // +-----------------------------------------------------------------------+ |
---|
| 236 | |
---|
| 237 | // Virtualy associate a picture to a category |
---|
| 238 | $blockname = 'associate_option'; |
---|
| 239 | |
---|
| 240 | $template->assign_block_vars( |
---|
| 241 | $blockname, |
---|
| 242 | array('SELECTED' => '', |
---|
| 243 | 'VALUE'=> 0, |
---|
| 244 | 'OPTION' => '------------' |
---|
| 245 | )); |
---|
| 246 | |
---|
| 247 | $query = ' |
---|
| 248 | SELECT id,name,uppercats,global_rank |
---|
| 249 | FROM '.CATEGORIES_TABLE.' |
---|
| 250 | ;'; |
---|
| 251 | display_select_cat_wrapper($query, array(), $blockname, true); |
---|
| 252 | |
---|
| 253 | // Dissociate from a category : categories listed for dissociation can |
---|
| 254 | // only represent virtual links. Links to physical categories can't be |
---|
| 255 | // broken |
---|
| 256 | $blockname = 'dissociate_option'; |
---|
| 257 | |
---|
| 258 | $template->assign_block_vars( |
---|
| 259 | $blockname, |
---|
| 260 | array('SELECTED' => '', |
---|
| 261 | 'VALUE'=> 0, |
---|
| 262 | 'OPTION' => '------------' |
---|
| 263 | )); |
---|
| 264 | |
---|
[764] | 265 | if (count($page['cat_elements_id']) > 0) |
---|
| 266 | { |
---|
| 267 | $query = ' |
---|
[755] | 268 | SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank |
---|
| 269 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic, |
---|
| 270 | '.CATEGORIES_TABLE.' AS c, |
---|
| 271 | '.IMAGES_TABLE.' AS i |
---|
[764] | 272 | WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).') |
---|
[755] | 273 | AND ic.category_id = c.id |
---|
| 274 | AND ic.image_id = i.id |
---|
[1121] | 275 | AND ic.category_id != i.storage_category_id |
---|
[755] | 276 | ;'; |
---|
[764] | 277 | display_select_cat_wrapper($query, array(), $blockname, true); |
---|
| 278 | } |
---|
[755] | 279 | |
---|
[1119] | 280 | // add tags |
---|
| 281 | $template->assign_vars( |
---|
| 282 | array( |
---|
| 283 | 'ADD_TAG_SELECTION' => get_html_tag_selection(get_all_tags(), 'add_tags'), |
---|
| 284 | ) |
---|
| 285 | ); |
---|
[762] | 286 | |
---|
[1120] | 287 | if (count($page['cat_elements_id']) > 0) |
---|
[762] | 288 | { |
---|
[1120] | 289 | // remove tags |
---|
| 290 | $query = ' |
---|
| 291 | SELECT tag_id, name, url_name, count(*) counter |
---|
| 292 | FROM '.IMAGE_TAG_TABLE.' |
---|
| 293 | INNER JOIN '.TAGS_TABLE.' ON tag_id = id |
---|
| 294 | WHERE image_id IN ('.implode(',', $page['cat_elements_id']).') |
---|
| 295 | GROUP BY tag_id |
---|
| 296 | ORDER BY name ASC |
---|
| 297 | ;'; |
---|
| 298 | $result = pwg_query($query); |
---|
[762] | 299 | |
---|
[1120] | 300 | $tags = array(); |
---|
| 301 | while($row = mysql_fetch_array($result)) |
---|
| 302 | { |
---|
| 303 | array_push($tags, $row); |
---|
| 304 | } |
---|
[1119] | 305 | |
---|
[1120] | 306 | $template->assign_vars( |
---|
| 307 | array( |
---|
| 308 | 'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'), |
---|
| 309 | ) |
---|
| 310 | ); |
---|
| 311 | } |
---|
[762] | 312 | // creation date |
---|
| 313 | $day = |
---|
| 314 | empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day']; |
---|
| 315 | get_day_list('date_creation_day', $day); |
---|
| 316 | |
---|
| 317 | if (!empty($_POST['date_creation_month'])) |
---|
| 318 | { |
---|
| 319 | $month = $_POST['date_creation_month']; |
---|
| 320 | } |
---|
| 321 | else |
---|
| 322 | { |
---|
| 323 | $month = date('n'); |
---|
| 324 | } |
---|
| 325 | get_month_list('date_creation_month', $month); |
---|
| 326 | |
---|
| 327 | if (!empty($_POST['date_creation_year'])) |
---|
| 328 | { |
---|
| 329 | $year = $_POST['date_creation_year']; |
---|
| 330 | } |
---|
| 331 | else |
---|
| 332 | { |
---|
| 333 | $year = date('Y'); |
---|
| 334 | } |
---|
| 335 | $template->assign_vars(array('DATE_CREATION_YEAR_VALUE'=>$year)); |
---|
| 336 | |
---|
[755] | 337 | // +-----------------------------------------------------------------------+ |
---|
| 338 | // | global mode thumbnails | |
---|
| 339 | // +-----------------------------------------------------------------------+ |
---|
| 340 | |
---|
[875] | 341 | // how many items to display on this page |
---|
| 342 | if (!empty($_GET['display'])) |
---|
| 343 | { |
---|
| 344 | if ('all' == $_GET['display']) |
---|
| 345 | { |
---|
| 346 | $page['nb_images'] = count($page['cat_elements_id']); |
---|
| 347 | } |
---|
| 348 | else |
---|
| 349 | { |
---|
| 350 | $page['nb_images'] = intval($_GET['display']); |
---|
| 351 | } |
---|
| 352 | } |
---|
| 353 | else |
---|
| 354 | { |
---|
| 355 | $page['nb_images'] = 20; |
---|
| 356 | } |
---|
| 357 | |
---|
[764] | 358 | if (count($page['cat_elements_id']) > 0) |
---|
| 359 | { |
---|
| 360 | $nav_bar = create_navigation_bar( |
---|
| 361 | $base_url.get_query_string_diff(array('start')), |
---|
| 362 | count($page['cat_elements_id']), |
---|
| 363 | $page['start'], |
---|
[1084] | 364 | $page['nb_images'] |
---|
| 365 | ); |
---|
[764] | 366 | $template->assign_vars(array('NAV_BAR' => $nav_bar)); |
---|
| 367 | |
---|
| 368 | $query = ' |
---|
| 369 | SELECT id,path,tn_ext |
---|
| 370 | FROM '.IMAGES_TABLE.' |
---|
| 371 | WHERE id IN ('.implode(',', $page['cat_elements_id']).') |
---|
[755] | 372 | '.$conf['order_by'].' |
---|
[764] | 373 | LIMIT '.$page['start'].', '.$page['nb_images'].' |
---|
[755] | 374 | ;'; |
---|
[764] | 375 | //echo '<pre>'.$query.'</pre>'; |
---|
| 376 | $result = pwg_query($query); |
---|
[755] | 377 | |
---|
[764] | 378 | // template thumbnail initialization |
---|
| 379 | if (mysql_num_rows($result) > 0) |
---|
| 380 | { |
---|
| 381 | $template->assign_block_vars('thumbnails', array()); |
---|
| 382 | } |
---|
[755] | 383 | |
---|
[764] | 384 | while ($row = mysql_fetch_array($result)) |
---|
[755] | 385 | { |
---|
[764] | 386 | $src = get_thumbnail_src($row['path'], @$row['tn_ext']); |
---|
[1092] | 387 | |
---|
[764] | 388 | $template->assign_block_vars( |
---|
[1308] | 389 | 'thumbnails.thumbnail', |
---|
[764] | 390 | array( |
---|
| 391 | 'ID' => $row['id'], |
---|
| 392 | 'SRC' => $src, |
---|
| 393 | 'ALT' => 'TODO', |
---|
| 394 | 'TITLE' => 'TODO' |
---|
| 395 | ) |
---|
| 396 | ); |
---|
[755] | 397 | } |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | //----------------------------------------------------------- sending html code |
---|
| 401 | $template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global'); |
---|
| 402 | ?> |
---|