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