[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-06-11 14:10:04 +0000 (Sat, 11 Jun 2005) $ |
---|
| 10 | // | last modifier : $Author: plg $ |
---|
| 11 | // | revision : $Revision: 792 $ |
---|
| 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 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 35 | { |
---|
| 36 | die('Hacking attempt!'); |
---|
| 37 | } |
---|
| 38 | include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); |
---|
| 39 | |
---|
| 40 | // +-----------------------------------------------------------------------+ |
---|
[762] | 41 | // | functions | |
---|
[755] | 42 | // +-----------------------------------------------------------------------+ |
---|
[762] | 43 | |
---|
| 44 | /** |
---|
| 45 | * returns the list of uniq keywords among given elements |
---|
| 46 | * |
---|
| 47 | * @param array element_ids |
---|
| 48 | */ |
---|
| 49 | function get_elements_keywords($element_ids) |
---|
[755] | 50 | { |
---|
[762] | 51 | if (0 == count($element_ids)) |
---|
| 52 | { |
---|
| 53 | return array(); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | $keywords = array(); |
---|
| 57 | |
---|
[755] | 58 | $query = ' |
---|
[762] | 59 | SELECT 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 | // +-----------------------------------------------------------------------+ |
---|
[755] | 75 | // | global mode form submission | |
---|
| 76 | // +-----------------------------------------------------------------------+ |
---|
| 77 | |
---|
| 78 | if (isset($_POST['submit'])) |
---|
| 79 | { |
---|
| 80 | $collection = array(); |
---|
| 81 | |
---|
| 82 | // echo '<pre>'; |
---|
[762] | 83 | // print_r($_POST); |
---|
[755] | 84 | // echo '</pre>'; |
---|
| 85 | // exit(); |
---|
| 86 | |
---|
| 87 | switch ($_POST['target']) |
---|
| 88 | { |
---|
| 89 | case 'all' : |
---|
| 90 | { |
---|
[764] | 91 | $collection = $page['cat_elements_id']; |
---|
[755] | 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(); |
---|
[760] | 104 | |
---|
| 105 | $query = ' |
---|
| 106 | SELECT image_id |
---|
| 107 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 108 | WHERE category_id = '.$_POST['associate'].' |
---|
| 109 | ;'; |
---|
| 110 | $associated = array_from_query($query, 'image_id'); |
---|
| 111 | |
---|
[762] | 112 | // TODO : if $associable array is empty, no further actions |
---|
[760] | 113 | $associable = array_diff($collection, $associated); |
---|
[755] | 114 | |
---|
[760] | 115 | foreach ($associable as $item) |
---|
[755] | 116 | { |
---|
| 117 | array_push($datas, |
---|
| 118 | array('category_id'=>$_POST['associate'], |
---|
| 119 | 'image_id'=>$item)); |
---|
| 120 | } |
---|
| 121 | |
---|
[760] | 122 | mass_inserts(IMAGE_CATEGORY_TABLE, |
---|
| 123 | array('image_id', 'category_id'), |
---|
| 124 | $datas); |
---|
[755] | 125 | update_category(array($_POST['associate'])); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | if ($_POST['dissociate'] != 0) |
---|
| 129 | { |
---|
[764] | 130 | // physical links must not be broken, so we must first retrieve image_id |
---|
[755] | 131 | // which create virtual links with the category to "dissociate from". |
---|
| 132 | $query = ' |
---|
| 133 | SELECT 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 = ' |
---|
| 142 | DELETE 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 | } |
---|
[762] | 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 = ' |
---|
| 172 | SELECT 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 | } |
---|
[763] | 252 | // echo '<pre>'; print_r($datas); echo '</pre>'; |
---|
[762] | 253 | mass_updates(IMAGES_TABLE, $dbfields, $datas); |
---|
| 254 | } |
---|
[755] | 255 | } |
---|
| 256 | |
---|
| 257 | // +-----------------------------------------------------------------------+ |
---|
| 258 | // | template init | |
---|
| 259 | // +-----------------------------------------------------------------------+ |
---|
| 260 | $template->set_filenames( |
---|
| 261 | array('element_set_global' => 'admin/element_set_global.tpl')); |
---|
| 262 | |
---|
[762] | 263 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
[755] | 264 | |
---|
[762] | 265 | // $form_action = $base_url.'?page=element_set_global'; |
---|
| 266 | |
---|
[755] | 267 | $template->assign_vars( |
---|
| 268 | array( |
---|
[764] | 269 | 'CATEGORY_TITLE'=>$page['title'], |
---|
| 270 | |
---|
[755] | 271 | 'L_SUBMIT'=>$lang['submit'], |
---|
| 272 | |
---|
[764] | 273 | 'U_COLS'=>$base_url.get_query_string_diff(array('cols')), |
---|
| 274 | 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), |
---|
[755] | 275 | |
---|
[764] | 276 | 'U_UNIT_MODE' |
---|
| 277 | => |
---|
| 278 | $base_url |
---|
| 279 | .get_query_string_diff(array('mode','display')) |
---|
| 280 | .'&mode=unit', |
---|
| 281 | |
---|
[762] | 282 | 'F_ACTION'=>$base_url.get_query_string_diff(array()), |
---|
[755] | 283 | ) |
---|
| 284 | ); |
---|
[764] | 285 | |
---|
[755] | 286 | // +-----------------------------------------------------------------------+ |
---|
[764] | 287 | // | caddie options | |
---|
| 288 | // +-----------------------------------------------------------------------+ |
---|
| 289 | |
---|
| 290 | if ('caddie' == $_GET['cat']) |
---|
| 291 | { |
---|
| 292 | $template->assign_block_vars('in_caddie', array()); |
---|
| 293 | } |
---|
| 294 | else |
---|
| 295 | { |
---|
| 296 | $template->assign_block_vars('not_in_caddie', array()); |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | // +-----------------------------------------------------------------------+ |
---|
[755] | 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 = ' |
---|
| 314 | SELECT id,name,uppercats,global_rank |
---|
| 315 | FROM '.CATEGORIES_TABLE.' |
---|
| 316 | ;'; |
---|
| 317 | display_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 | |
---|
[764] | 331 | if (count($page['cat_elements_id']) > 0) |
---|
| 332 | { |
---|
| 333 | $query = ' |
---|
[755] | 334 | SELECT 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 |
---|
[764] | 338 | WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).') |
---|
[755] | 339 | AND ic.category_id = c.id |
---|
| 340 | AND ic.image_id = i.id |
---|
| 341 | AND ic.category_id != i.storage_category_id |
---|
| 342 | ;'; |
---|
[764] | 343 | display_select_cat_wrapper($query, array(), $blockname, true); |
---|
| 344 | } |
---|
[755] | 345 | |
---|
[762] | 346 | $blockname = 'remove_keyword_option'; |
---|
| 347 | |
---|
| 348 | $template->assign_block_vars( |
---|
| 349 | $blockname, |
---|
| 350 | array('VALUE'=> 0, |
---|
| 351 | 'OPTION' => '------------' |
---|
| 352 | )); |
---|
| 353 | |
---|
[764] | 354 | $keywords = get_elements_keywords($page['cat_elements_id']); |
---|
[762] | 355 | |
---|
| 356 | foreach ($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 = |
---|
| 367 | empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day']; |
---|
| 368 | get_day_list('date_creation_day', $day); |
---|
| 369 | |
---|
| 370 | if (!empty($_POST['date_creation_month'])) |
---|
| 371 | { |
---|
| 372 | $month = $_POST['date_creation_month']; |
---|
| 373 | } |
---|
| 374 | else |
---|
| 375 | { |
---|
| 376 | $month = date('n'); |
---|
| 377 | } |
---|
| 378 | get_month_list('date_creation_month', $month); |
---|
| 379 | |
---|
| 380 | if (!empty($_POST['date_creation_year'])) |
---|
| 381 | { |
---|
| 382 | $year = $_POST['date_creation_year']; |
---|
| 383 | } |
---|
| 384 | else |
---|
| 385 | { |
---|
| 386 | $year = date('Y'); |
---|
| 387 | } |
---|
| 388 | $template->assign_vars(array('DATE_CREATION_YEAR_VALUE'=>$year)); |
---|
| 389 | |
---|
[755] | 390 | // +-----------------------------------------------------------------------+ |
---|
| 391 | // | global mode thumbnails | |
---|
| 392 | // +-----------------------------------------------------------------------+ |
---|
| 393 | |
---|
[764] | 394 | $page['cols'] = !empty($_GET['cols']) ? intval($_GET['cols']) : 5; |
---|
| 395 | $page['nb_images'] = !empty($_GET['display']) ? intval($_GET['display']) : 20; |
---|
[762] | 396 | |
---|
[764] | 397 | if (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 = ' |
---|
| 408 | SELECT id,path,tn_ext |
---|
| 409 | FROM '.IMAGES_TABLE.' |
---|
| 410 | WHERE id IN ('.implode(',', $page['cat_elements_id']).') |
---|
[755] | 411 | '.$conf['order_by'].' |
---|
[764] | 412 | LIMIT '.$page['start'].', '.$page['nb_images'].' |
---|
[755] | 413 | ;'; |
---|
[764] | 414 | //echo '<pre>'.$query.'</pre>'; |
---|
| 415 | $result = pwg_query($query); |
---|
[755] | 416 | |
---|
[764] | 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 | } |
---|
[755] | 426 | |
---|
[764] | 427 | while ($row = mysql_fetch_array($result)) |
---|
[755] | 428 | { |
---|
[764] | 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 | { |
---|
[755] | 444 | $template->assign_block_vars('thumbnails.line', array()); |
---|
| 445 | $row_number = 0; |
---|
[764] | 446 | } |
---|
[755] | 447 | } |
---|
| 448 | } |
---|
| 449 | |
---|
| 450 | //----------------------------------------------------------- sending html code |
---|
| 451 | $template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global'); |
---|
| 452 | ?> |
---|