[10] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
| 5 | // | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[362] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[362] | 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2004-11-06 21:12:59 +0000 (Sat, 06 Nov 2004) $ |
---|
| 10 | // | last modifier : $Author: z0rglub $ |
---|
| 11 | // | revision : $Revision: 593 $ |
---|
| 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 | // +-----------------------------------------------------------------------+ |
---|
[10] | 27 | |
---|
[520] | 28 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
| 29 | { |
---|
[522] | 30 | die ("Hacking attempt!"); |
---|
[520] | 31 | } |
---|
[466] | 32 | include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); |
---|
[486] | 33 | |
---|
| 34 | define('CURRENT_DATE', "'".date('Y-m-d')."'"); |
---|
[589] | 35 | // +-----------------------------------------------------------------------+ |
---|
| 36 | // | functions | |
---|
| 37 | // +-----------------------------------------------------------------------+ |
---|
| 38 | |
---|
[486] | 39 | /** |
---|
| 40 | * order categories (update categories.rank database field) |
---|
| 41 | * |
---|
| 42 | * the purpose of this function is to give a rank for all categories |
---|
| 43 | * (insides its sub-category), even the newer that have none at te |
---|
| 44 | * beginning. For this, ordering function selects all categories ordered by |
---|
| 45 | * rank ASC then name ASC for each uppercat. |
---|
| 46 | * |
---|
| 47 | * @returns void |
---|
| 48 | */ |
---|
| 49 | function ordering() |
---|
[394] | 50 | { |
---|
[486] | 51 | $current_rank = 0; |
---|
| 52 | $current_uppercat = ''; |
---|
[394] | 53 | |
---|
[486] | 54 | $query = ' |
---|
| 55 | SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat |
---|
| 56 | FROM '.CATEGORIES_TABLE.' |
---|
| 57 | ORDER BY id_uppercat,rank,name |
---|
| 58 | ;'; |
---|
[587] | 59 | $result = pwg_query($query); |
---|
[486] | 60 | while ($row = mysql_fetch_array($result)) |
---|
[394] | 61 | { |
---|
[486] | 62 | if ($row['id_uppercat'] != $current_uppercat) |
---|
| 63 | { |
---|
| 64 | $current_rank = 0; |
---|
| 65 | $current_uppercat = $row['id_uppercat']; |
---|
| 66 | } |
---|
| 67 | $query = ' |
---|
| 68 | UPDATE '.CATEGORIES_TABLE.' |
---|
[494] | 69 | SET rank = '.++$current_rank.' |
---|
| 70 | WHERE id = '.$row['id'].' |
---|
[486] | 71 | ;'; |
---|
[587] | 72 | pwg_query($query); |
---|
[394] | 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
[466] | 76 | function insert_local_category($id_uppercat) |
---|
[10] | 77 | { |
---|
[498] | 78 | global $conf, $page, $user, $lang, $counts; |
---|
[345] | 79 | |
---|
| 80 | $uppercats = ''; |
---|
| 81 | $output = ''; |
---|
[228] | 82 | |
---|
[10] | 83 | // 0. retrieving informations on the category to display |
---|
[393] | 84 | $cat_directory = PHPWG_ROOT_PATH.'galleries'; |
---|
[466] | 85 | if (is_numeric($id_uppercat)) |
---|
[345] | 86 | { |
---|
[393] | 87 | $query = 'SELECT name,uppercats,dir FROM '.CATEGORIES_TABLE; |
---|
[345] | 88 | $query.= ' WHERE id = '.$id_uppercat; |
---|
| 89 | $query.= ';'; |
---|
[587] | 90 | $row = mysql_fetch_array( pwg_query( $query)); |
---|
[345] | 91 | $uppercats = $row['uppercats']; |
---|
| 92 | $name = $row['name']; |
---|
| 93 | $dir = $row['dir']; |
---|
[228] | 94 | |
---|
[466] | 95 | $upper_array = explode( ',', $uppercats); |
---|
[345] | 96 | |
---|
| 97 | $local_dir = ''; |
---|
| 98 | |
---|
| 99 | $database_dirs = array(); |
---|
[466] | 100 | $query = ' |
---|
| 101 | SELECT id,dir FROM '.CATEGORIES_TABLE.' |
---|
| 102 | WHERE id IN ('.$uppercats.') |
---|
| 103 | ;'; |
---|
[587] | 104 | $result = pwg_query( $query); |
---|
[466] | 105 | while ($row = mysql_fetch_array($result)) |
---|
[345] | 106 | { |
---|
| 107 | $database_dirs[$row['id']] = $row['dir']; |
---|
| 108 | } |
---|
[466] | 109 | foreach ($upper_array as $id) |
---|
| 110 | { |
---|
[345] | 111 | $local_dir.= $database_dirs[$id].'/'; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | $cat_directory.= '/'.$local_dir; |
---|
| 115 | |
---|
[10] | 116 | // 1. display the category name to update |
---|
[393] | 117 | $output = '<ul class="menu">'; |
---|
| 118 | $output.= '<li><strong>'.$name.'</strong>'; |
---|
[345] | 119 | $output.= ' [ '.$dir.' ]'; |
---|
[393] | 120 | $output.= '</li>'; |
---|
[61] | 121 | |
---|
[10] | 122 | // 2. we search pictures of the category only if the update is for all |
---|
| 123 | // or a cat_id is specified |
---|
[589] | 124 | if ($_POST['sync'] == 'files') |
---|
[10] | 125 | { |
---|
[466] | 126 | $output.= insert_local_element($cat_directory, $id_uppercat); |
---|
[10] | 127 | } |
---|
| 128 | } |
---|
[61] | 129 | |
---|
[486] | 130 | $fs_subdirs = get_category_directories($cat_directory); |
---|
[345] | 131 | |
---|
| 132 | $sub_category_dirs = array(); |
---|
[466] | 133 | $query = ' |
---|
| 134 | SELECT id,dir FROM '.CATEGORIES_TABLE.' |
---|
| 135 | WHERE site_id = 1 |
---|
| 136 | '; |
---|
| 137 | if (!is_numeric($id_uppercat)) |
---|
[10] | 138 | { |
---|
[466] | 139 | $query.= ' AND id_uppercat IS NULL'; |
---|
| 140 | } |
---|
| 141 | else |
---|
| 142 | { |
---|
| 143 | $query.= ' AND id_uppercat = '.$id_uppercat; |
---|
| 144 | } |
---|
| 145 | $query.= ' |
---|
| 146 | AND dir IS NOT NULL'; // virtual categories not taken |
---|
| 147 | $query.= ' |
---|
| 148 | ;'; |
---|
[587] | 149 | $result = pwg_query($query); |
---|
[466] | 150 | while ($row = mysql_fetch_array($result)) |
---|
| 151 | { |
---|
[345] | 152 | $sub_category_dirs[$row['id']] = $row['dir']; |
---|
[10] | 153 | } |
---|
[345] | 154 | |
---|
| 155 | // 3. we have to remove the categories of the database not present anymore |
---|
[486] | 156 | $to_delete_categories = array(); |
---|
[466] | 157 | foreach ($sub_category_dirs as $id => $dir) |
---|
| 158 | { |
---|
[486] | 159 | if (!in_array($dir, $fs_subdirs)) |
---|
[466] | 160 | { |
---|
[486] | 161 | array_push($to_delete_categories,$id); |
---|
[466] | 162 | } |
---|
[345] | 163 | } |
---|
[486] | 164 | if (count($to_delete_categories) > 0) |
---|
| 165 | { |
---|
| 166 | delete_categories($to_delete_categories); |
---|
| 167 | } |
---|
[345] | 168 | |
---|
| 169 | // array of new categories to insert |
---|
| 170 | $inserts = array(); |
---|
| 171 | |
---|
[486] | 172 | foreach ($fs_subdirs as $fs_subdir) |
---|
[466] | 173 | { |
---|
[345] | 174 | // 5. Is the category already existing ? we create a subcat if not |
---|
| 175 | // existing |
---|
[486] | 176 | $category_id = array_search($fs_subdir, $sub_category_dirs); |
---|
[466] | 177 | if (!is_numeric($category_id)) |
---|
[10] | 178 | { |
---|
[486] | 179 | if (preg_match('/^[a-zA-Z0-9-_.]+$/', $fs_subdir)) |
---|
[10] | 180 | { |
---|
[486] | 181 | $name = str_replace('_', ' ', $fs_subdir); |
---|
[345] | 182 | |
---|
[486] | 183 | $value = "('".$fs_subdir."','".$name."',1"; |
---|
[466] | 184 | if (!is_numeric($id_uppercat)) |
---|
| 185 | { |
---|
| 186 | $value.= ',NULL'; |
---|
| 187 | } |
---|
| 188 | else |
---|
| 189 | { |
---|
| 190 | $value.= ','.$id_uppercat; |
---|
| 191 | } |
---|
[345] | 192 | $value.= ",'undef'"; |
---|
| 193 | $value.= ')'; |
---|
[466] | 194 | array_push($inserts, $value); |
---|
[10] | 195 | } |
---|
[345] | 196 | else |
---|
| 197 | { |
---|
[498] | 198 | $output.= '<span class="update_category_error">"'.$fs_subdir.'" : '; |
---|
[345] | 199 | $output.= $lang['update_wrong_dirname'].'</span><br />'; |
---|
| 200 | } |
---|
[10] | 201 | } |
---|
| 202 | } |
---|
[345] | 203 | |
---|
| 204 | // we have to create the category |
---|
[466] | 205 | if (count($inserts) > 0) |
---|
[345] | 206 | { |
---|
[466] | 207 | $query = ' |
---|
| 208 | INSERT INTO '.CATEGORIES_TABLE.' |
---|
| 209 | (dir,name,site_id,id_uppercat,uppercats) VALUES |
---|
| 210 | '; |
---|
| 211 | $query.= implode(',', $inserts); |
---|
| 212 | $query.= ' |
---|
| 213 | ;'; |
---|
[587] | 214 | pwg_query($query); |
---|
[498] | 215 | |
---|
| 216 | $counts['new_categories']+= count($inserts); |
---|
[345] | 217 | // updating uppercats field |
---|
[466] | 218 | $query = ' |
---|
| 219 | UPDATE '.CATEGORIES_TABLE.' |
---|
| 220 | SET uppercats = '; |
---|
| 221 | if ($uppercats != '') |
---|
| 222 | { |
---|
| 223 | $query.= "CONCAT('".$uppercats."',',',id)"; |
---|
| 224 | } |
---|
| 225 | else |
---|
| 226 | { |
---|
| 227 | $query.= 'id'; |
---|
| 228 | } |
---|
| 229 | $query.= ' |
---|
| 230 | WHERE id_uppercat '; |
---|
| 231 | if (!is_numeric($id_uppercat)) |
---|
| 232 | { |
---|
| 233 | $query.= 'IS NULL'; |
---|
| 234 | } |
---|
| 235 | else |
---|
| 236 | { |
---|
| 237 | $query.= '= '.$id_uppercat; |
---|
| 238 | } |
---|
| 239 | $query.= ' |
---|
| 240 | ;'; |
---|
[587] | 241 | pwg_query($query); |
---|
[10] | 242 | } |
---|
[345] | 243 | |
---|
| 244 | // Recursive call on the sub-categories (not virtual ones) |
---|
[589] | 245 | if (!isset($_POST['cat']) |
---|
| 246 | or (isset($_POST['subcats-included']) |
---|
| 247 | and $_POST['subcats-included'] == 1)) |
---|
| 248 | { |
---|
| 249 | $query = ' |
---|
[466] | 250 | SELECT id |
---|
| 251 | FROM '.CATEGORIES_TABLE.' |
---|
| 252 | WHERE site_id = 1 |
---|
| 253 | '; |
---|
[589] | 254 | if (!is_numeric($id_uppercat)) |
---|
| 255 | { |
---|
| 256 | $query.= ' AND id_uppercat IS NULL'; |
---|
| 257 | } |
---|
| 258 | else |
---|
| 259 | { |
---|
| 260 | $query.= ' AND id_uppercat = '.$id_uppercat; |
---|
| 261 | } |
---|
| 262 | $query.= ' |
---|
[466] | 263 | AND dir IS NOT NULL'; // virtual categories not taken |
---|
[589] | 264 | $query.= ' |
---|
[466] | 265 | ;'; |
---|
[589] | 266 | $result = pwg_query($query); |
---|
| 267 | while ($row = mysql_fetch_array($result)) |
---|
| 268 | { |
---|
| 269 | $output.= insert_local_category($row['id']); |
---|
| 270 | } |
---|
[466] | 271 | } |
---|
[345] | 272 | |
---|
[466] | 273 | if (is_numeric($id_uppercat)) |
---|
[345] | 274 | { |
---|
[393] | 275 | $output.= '</ul>'; |
---|
[10] | 276 | } |
---|
| 277 | return $output; |
---|
| 278 | } |
---|
[345] | 279 | |
---|
[466] | 280 | function insert_local_element($dir, $category_id) |
---|
[10] | 281 | { |
---|
[498] | 282 | global $lang,$conf,$counts; |
---|
[10] | 283 | |
---|
| 284 | $output = ''; |
---|
[345] | 285 | |
---|
[466] | 286 | // fs means FileSystem : $fs_files contains files in the filesystem found |
---|
| 287 | // in $dir that can be managed by PhpWebGallery (see get_pwg_files |
---|
| 288 | // function), $fs_thumbnails contains thumbnails, $fs_representatives |
---|
| 289 | // contains potentially representative pictures for non picture files |
---|
| 290 | $fs_files = get_pwg_files($dir); |
---|
| 291 | $fs_thumbnails = get_thumb_files($dir); |
---|
| 292 | $fs_representatives = get_representative_files($dir); |
---|
[345] | 293 | |
---|
[466] | 294 | // element deletion |
---|
| 295 | $to_delete_elements = array(); |
---|
| 296 | // deletion of element if the correspond file doesn't exist anymore |
---|
| 297 | $query = ' |
---|
| 298 | SELECT id,file |
---|
| 299 | FROM '.IMAGES_TABLE.' |
---|
| 300 | WHERE storage_category_id = '.$category_id.' |
---|
| 301 | ;'; |
---|
[587] | 302 | $result = pwg_query($query); |
---|
[466] | 303 | while ($row = mysql_fetch_array($result)) |
---|
[10] | 304 | { |
---|
[466] | 305 | if (!in_array($row['file'], $fs_files)) |
---|
[10] | 306 | { |
---|
[345] | 307 | $output.= $row['file']; |
---|
| 308 | $output.= ' <span style="font-weight:bold;">'; |
---|
| 309 | $output.= $lang['update_disappeared'].'</span><br />'; |
---|
[466] | 310 | array_push($to_delete_elements, $row['id']); |
---|
[10] | 311 | } |
---|
[466] | 312 | } |
---|
| 313 | // in picture case, we also delete the element if the thumbnail doesn't |
---|
| 314 | // existe anymore |
---|
| 315 | $query = ' |
---|
| 316 | SELECT id,file,tn_ext |
---|
| 317 | FROM '.IMAGES_TABLE.' |
---|
| 318 | WHERE storage_category_id = '.$category_id.' |
---|
| 319 | AND ('.implode(' OR ', |
---|
| 320 | array_map( |
---|
| 321 | create_function('$s', 'return "file LIKE \'%".$s."\'";') |
---|
| 322 | , $conf['picture_ext'])).') |
---|
| 323 | ;'; |
---|
[587] | 324 | $result = pwg_query($query); |
---|
[466] | 325 | while ($row = mysql_fetch_array($result)) |
---|
| 326 | { |
---|
[345] | 327 | $thumbnail = $conf['prefix_thumbnail']; |
---|
[466] | 328 | $thumbnail.= get_filename_wo_extension($row['file']); |
---|
[345] | 329 | $thumbnail.= '.'.$row['tn_ext']; |
---|
[466] | 330 | if (!in_array($thumbnail, $fs_thumbnails)) |
---|
[345] | 331 | { |
---|
| 332 | $output.= $row['file']; |
---|
| 333 | $output.= ' : <span style="font-weight:bold;">'; |
---|
| 334 | $output.= $lang['update_disappeared_tn'].'</span><br />'; |
---|
[466] | 335 | array_push($to_delete_elements, $row['id']); |
---|
[345] | 336 | } |
---|
[10] | 337 | } |
---|
[345] | 338 | |
---|
[466] | 339 | $to_delete_elements = array_unique($to_delete_elements); |
---|
[486] | 340 | if (count($to_delete_elements) > 0) |
---|
[10] | 341 | { |
---|
[466] | 342 | delete_elements($to_delete_elements); |
---|
[345] | 343 | } |
---|
[466] | 344 | |
---|
| 345 | $registered_elements = array(); |
---|
| 346 | $query = ' |
---|
| 347 | SELECT file FROM '.IMAGES_TABLE.' |
---|
| 348 | WHERE storage_category_id = '.$category_id.' |
---|
| 349 | ;'; |
---|
[587] | 350 | $result = pwg_query($query); |
---|
[466] | 351 | while ($row = mysql_fetch_array($result)) |
---|
| 352 | { |
---|
| 353 | array_push($registered_elements, $row['file']); |
---|
| 354 | } |
---|
[345] | 355 | |
---|
[486] | 356 | // unvalidated pictures are picture uploaded by users, but not validated |
---|
| 357 | // by an admin (so not registered truly visible yet) |
---|
[345] | 358 | $unvalidated_pictures = array(); |
---|
| 359 | |
---|
[466] | 360 | $query = ' |
---|
[486] | 361 | SELECT file |
---|
[466] | 362 | FROM '.WAITING_TABLE.' |
---|
| 363 | WHERE storage_category_id = '.$category_id.' |
---|
[486] | 364 | AND validated = \'false\' |
---|
[466] | 365 | ;'; |
---|
[587] | 366 | $result = pwg_query($query); |
---|
[466] | 367 | while ($row = mysql_fetch_array($result)) |
---|
[345] | 368 | { |
---|
[486] | 369 | array_push($unvalidated_pictures, $row['file']); |
---|
[345] | 370 | } |
---|
| 371 | |
---|
| 372 | // we only search among the picture present in the filesystem and not |
---|
| 373 | // present in the database yet. If we know that this picture is known as |
---|
| 374 | // an uploaded one but not validated, it's not tested neither |
---|
[466] | 375 | $unregistered_elements = array_diff($fs_files |
---|
| 376 | ,$registered_elements |
---|
| 377 | ,$unvalidated_pictures); |
---|
[345] | 378 | |
---|
| 379 | $inserts = array(); |
---|
| 380 | |
---|
[466] | 381 | foreach ($unregistered_elements as $unregistered_element) |
---|
| 382 | { |
---|
| 383 | if (preg_match('/^[a-zA-Z0-9-_.]+$/', $unregistered_element)) |
---|
[10] | 384 | { |
---|
[466] | 385 | $file_wo_ext = get_filename_wo_extension($unregistered_element); |
---|
[345] | 386 | $tn_ext = ''; |
---|
[466] | 387 | foreach ($conf['picture_ext'] as $ext) |
---|
| 388 | { |
---|
[345] | 389 | $test = $conf['prefix_thumbnail'].$file_wo_ext.'.'.$ext; |
---|
[466] | 390 | if (!in_array($test, $fs_thumbnails)) |
---|
| 391 | { |
---|
| 392 | continue; |
---|
| 393 | } |
---|
| 394 | else |
---|
| 395 | { |
---|
| 396 | $tn_ext = $ext; |
---|
| 397 | break; |
---|
| 398 | } |
---|
[345] | 399 | } |
---|
[466] | 400 | |
---|
| 401 | // 2 cases : the element is a picture or not. Indeed, for a picture |
---|
| 402 | // thumbnail is mandatory and for non picture element, thumbnail and |
---|
| 403 | // representative is optionnal |
---|
| 404 | if (in_array(get_extension($unregistered_element), $conf['picture_ext'])) |
---|
[10] | 405 | { |
---|
[466] | 406 | // if we found a thumnbnail corresponding to our picture... |
---|
| 407 | if ($tn_ext != '') |
---|
[10] | 408 | { |
---|
[486] | 409 | $insert = array(); |
---|
| 410 | $insert['file'] = "'".$unregistered_element."'"; |
---|
| 411 | $insert['storage_category_id'] = $category_id; |
---|
| 412 | $insert['date_available'] = CURRENT_DATE; |
---|
| 413 | $insert['tn_ext'] = "'".$tn_ext."'"; |
---|
[160] | 414 | |
---|
[498] | 415 | $counts['new_elements']++; |
---|
[486] | 416 | array_push($inserts, $insert); |
---|
[10] | 417 | } |
---|
[345] | 418 | else |
---|
| 419 | { |
---|
[498] | 420 | $output.= '<span class="update_error_element">'; |
---|
[466] | 421 | $output.= $lang['update_missing_tn'].' : '.$unregistered_element; |
---|
| 422 | $output.= ' (<span style="font-weight:bold;">'; |
---|
| 423 | $output.= $conf['prefix_thumbnail']; |
---|
| 424 | $output.= get_filename_wo_extension($unregistered_element); |
---|
| 425 | $output.= '.XXX</span>'; |
---|
| 426 | $output.= ', XXX = '; |
---|
| 427 | $output.= implode(', ', $conf['picture_ext']); |
---|
| 428 | $output.= ')</span><br />'; |
---|
[345] | 429 | } |
---|
[466] | 430 | } |
---|
| 431 | else |
---|
| 432 | { |
---|
| 433 | $representative_ext = ''; |
---|
| 434 | foreach ($conf['picture_ext'] as $ext) |
---|
| 435 | { |
---|
[522] | 436 | $candidate = $file_wo_ext.'.'.$ext; |
---|
| 437 | if (!in_array($candidate, $fs_representatives)) |
---|
[466] | 438 | { |
---|
| 439 | continue; |
---|
| 440 | } |
---|
| 441 | else |
---|
| 442 | { |
---|
| 443 | $representative_ext = $ext; |
---|
| 444 | break; |
---|
| 445 | } |
---|
| 446 | } |
---|
| 447 | |
---|
[486] | 448 | $insert = array(); |
---|
| 449 | $insert['file'] = "'".$unregistered_element."'"; |
---|
| 450 | $insert['storage_category_id'] = $category_id; |
---|
| 451 | $insert['date_available'] = CURRENT_DATE; |
---|
[466] | 452 | if ( $tn_ext != '' ) |
---|
| 453 | { |
---|
[486] | 454 | $insert['tn_ext'] = "'".$tn_ext."'"; |
---|
[466] | 455 | } |
---|
| 456 | if ( $representative_ext != '' ) |
---|
| 457 | { |
---|
[486] | 458 | $insert['representative_ext'] = "'".$representative_ext."'"; |
---|
[466] | 459 | } |
---|
| 460 | |
---|
[498] | 461 | $counts['new_elements']++; |
---|
[486] | 462 | array_push($inserts, $insert); |
---|
[10] | 463 | } |
---|
| 464 | } |
---|
[345] | 465 | else |
---|
| 466 | { |
---|
[498] | 467 | $output.= '<span class="update_error_element">"'; |
---|
| 468 | $output.= $unregistered_element.'" : '; |
---|
[345] | 469 | $output.= $lang['update_wrong_dirname'].'</span><br />'; |
---|
| 470 | } |
---|
[10] | 471 | } |
---|
[466] | 472 | |
---|
| 473 | if (count($inserts) > 0) |
---|
[345] | 474 | { |
---|
| 475 | // inserts all found pictures |
---|
[486] | 476 | $dbfields = array( |
---|
| 477 | 'file','storage_category_id','date_available','tn_ext' |
---|
| 478 | ,'representative_ext' |
---|
| 479 | ); |
---|
[466] | 480 | $query = ' |
---|
| 481 | INSERT INTO '.IMAGES_TABLE.' |
---|
[486] | 482 | ('.implode(',', $dbfields).') |
---|
[466] | 483 | VALUES |
---|
[486] | 484 | '; |
---|
| 485 | foreach ($inserts as $insert_id => $insert) |
---|
| 486 | { |
---|
| 487 | $query.= ' |
---|
| 488 | '; |
---|
| 489 | if ($insert_id > 0) |
---|
| 490 | { |
---|
| 491 | $query.= ','; |
---|
| 492 | } |
---|
| 493 | $query.= '('; |
---|
| 494 | foreach ($dbfields as $field_id => $dbfield) |
---|
| 495 | { |
---|
| 496 | if ($field_id > 0) |
---|
| 497 | { |
---|
| 498 | $query.= ','; |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | if (!isset($insert[$dbfield]) or $insert[$dbfield] == '') |
---|
| 502 | { |
---|
| 503 | $query.= 'NULL'; |
---|
| 504 | } |
---|
| 505 | else |
---|
| 506 | { |
---|
| 507 | $query.= $insert[$dbfield]; |
---|
| 508 | } |
---|
| 509 | } |
---|
| 510 | $query.=')'; |
---|
| 511 | } |
---|
| 512 | $query.= ' |
---|
[466] | 513 | ;'; |
---|
[486] | 514 | |
---|
[587] | 515 | pwg_query($query); |
---|
[345] | 516 | |
---|
| 517 | // what are the ids of the pictures in the $category_id ? |
---|
| 518 | $ids = array(); |
---|
| 519 | |
---|
[466] | 520 | $query = ' |
---|
| 521 | SELECT id |
---|
| 522 | FROM '.IMAGES_TABLE.' |
---|
| 523 | WHERE storage_category_id = '.$category_id.' |
---|
| 524 | ;'; |
---|
[587] | 525 | $result = pwg_query($query); |
---|
[466] | 526 | while ($row = mysql_fetch_array($result)) |
---|
[345] | 527 | { |
---|
[466] | 528 | array_push($ids, $row['id']); |
---|
[345] | 529 | } |
---|
| 530 | |
---|
| 531 | // recreation of the links between this storage category pictures and |
---|
| 532 | // its storage category |
---|
[466] | 533 | $query = ' |
---|
| 534 | DELETE FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 535 | WHERE category_id = '.$category_id.' |
---|
| 536 | AND image_id IN ('.implode(',', $ids).') |
---|
| 537 | ;'; |
---|
[587] | 538 | pwg_query($query); |
---|
[345] | 539 | |
---|
[466] | 540 | foreach ($ids as $num => $image_id) |
---|
[345] | 541 | { |
---|
[466] | 542 | $ids[$num] = '('.$category_id.','.$image_id.')'; |
---|
[345] | 543 | } |
---|
[466] | 544 | $query = ' |
---|
| 545 | INSERT INTO '.IMAGE_CATEGORY_TABLE.' |
---|
| 546 | (category_id,image_id) VALUES |
---|
| 547 | '.implode(',', $ids).' |
---|
| 548 | ;'; |
---|
[587] | 549 | pwg_query($query); |
---|
[345] | 550 | } |
---|
[10] | 551 | return $output; |
---|
| 552 | } |
---|
[589] | 553 | // +-----------------------------------------------------------------------+ |
---|
| 554 | // | template initialization | |
---|
| 555 | // +-----------------------------------------------------------------------+ |
---|
[466] | 556 | $template->set_filenames(array('update'=>'admin/update.tpl')); |
---|
[393] | 557 | |
---|
[589] | 558 | $base_url = PHPWG_ROOT_PATH.'admin.php?page=update'; |
---|
| 559 | |
---|
| 560 | $template->assign_vars( |
---|
| 561 | array( |
---|
| 562 | 'L_SUBMIT'=>$lang['submit'], |
---|
| 563 | 'L_UPDATE_TITLE'=>$lang['update_default_title'], |
---|
| 564 | 'L_UPDATE_SYNC_FILES'=>$lang['update_sync_files'], |
---|
| 565 | 'L_UPDATE_SYNC_DIRS'=>$lang['update_sync_dirs'], |
---|
| 566 | 'L_UPDATE_SYNC_ALL'=>$lang['update_sync_all'], |
---|
| 567 | 'L_UPDATE_SYNC_METADATA'=>$lang['update_sync_metadata'], |
---|
| 568 | 'L_UPDATE_SYNC_METADATA_NEW'=>$lang['update_sync_metadata_new'], |
---|
| 569 | 'L_UPDATE_SYNC_METADATA_ALL'=>$lang['update_sync_metadata_all'], |
---|
| 570 | 'L_UPDATE_CATS_SUBSET'=>$lang['update_cats_subset'], |
---|
| 571 | 'L_RESULT_UPDATE'=>$lang['update_part_research'], |
---|
| 572 | 'L_NB_NEW_ELEMENTS'=>$lang['update_nb_new_elements'], |
---|
| 573 | 'L_NB_NEW_CATEGORIES'=>$lang['update_nb_new_categories'], |
---|
| 574 | 'L_NB_DEL_ELEMENTS'=>$lang['update_nb_del_elements'], |
---|
| 575 | 'L_NB_DEL_CATEGORIES'=>$lang['update_nb_del_categories'], |
---|
| 576 | 'L_SEARCH_SUBCATS_INCLUDED'=>$lang['search_subcats_included'], |
---|
| 577 | |
---|
| 578 | 'U_SYNC_DIRS'=>add_session_id($base_url.'&update=dirs'), |
---|
| 579 | 'U_SYNC_ALL'=>add_session_id($base_url.'&update=all'), |
---|
| 580 | 'U_SYNC_METADATA_NEW'=>add_session_id($base_url.'&metadata=all:new'), |
---|
| 581 | 'U_SYNC_METADATA_ALL'=>add_session_id($base_url.'&metadata=all') |
---|
| 582 | )); |
---|
| 583 | // +-----------------------------------------------------------------------+ |
---|
| 584 | // | introduction : choices | |
---|
| 585 | // +-----------------------------------------------------------------------+ |
---|
| 586 | if (!isset($_POST['submit'])) |
---|
[10] | 587 | { |
---|
[589] | 588 | $template->assign_block_vars('introduction', array()); |
---|
| 589 | |
---|
| 590 | $query = ' |
---|
| 591 | SELECT id |
---|
| 592 | FROM '.CATEGORIES_TABLE.' |
---|
| 593 | WHERE site_id != 1 |
---|
| 594 | ;'; |
---|
| 595 | $result = pwg_query($query); |
---|
| 596 | while ($row = mysql_fetch_array($result)) |
---|
| 597 | { |
---|
| 598 | array_push($user['restrictions'], $row['id']); |
---|
| 599 | } |
---|
| 600 | $user['forbidden_categories'] = implode(',', $user['restrictions']); |
---|
| 601 | $user['expand'] = true; |
---|
| 602 | $structure = create_user_structure(''); |
---|
| 603 | display_select_categories($structure, |
---|
| 604 | ' ', |
---|
| 605 | array(), |
---|
| 606 | 'introduction.category_option'); |
---|
[10] | 607 | } |
---|
[589] | 608 | // +-----------------------------------------------------------------------+ |
---|
| 609 | // | synchronize files | |
---|
| 610 | // +-----------------------------------------------------------------------+ |
---|
| 611 | else if (isset($_POST['submit']) |
---|
| 612 | and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')) |
---|
[10] | 613 | { |
---|
[498] | 614 | $counts = array( |
---|
| 615 | 'new_elements' => 0, |
---|
| 616 | 'new_categories' => 0, |
---|
| 617 | 'del_elements' => 0, |
---|
| 618 | 'del_categories' => 0 |
---|
| 619 | ); |
---|
[589] | 620 | |
---|
| 621 | if (isset($_POST['cat'])) |
---|
[10] | 622 | { |
---|
[589] | 623 | $opts['category_id'] = $_POST['cat']; |
---|
[10] | 624 | } |
---|
| 625 | else |
---|
| 626 | { |
---|
[589] | 627 | $opts['category_id'] = 'NULL'; |
---|
[10] | 628 | } |
---|
[589] | 629 | |
---|
| 630 | $start = get_moment(); |
---|
| 631 | $categories = insert_local_category($opts['category_id']); |
---|
[486] | 632 | echo get_elapsed_time($start,get_moment()).' for scanning directories<br />'; |
---|
[589] | 633 | |
---|
[498] | 634 | $template->assign_block_vars( |
---|
| 635 | 'update', |
---|
| 636 | array( |
---|
| 637 | 'CATEGORIES'=>$categories, |
---|
| 638 | 'NB_NEW_CATEGORIES'=>$counts['new_categories'], |
---|
| 639 | 'NB_DEL_CATEGORIES'=>$counts['del_categories'], |
---|
| 640 | 'NB_NEW_ELEMENTS'=>$counts['new_elements'], |
---|
| 641 | 'NB_DEL_ELEMENTS'=>$counts['del_elements'] |
---|
| 642 | )); |
---|
[345] | 643 | $start = get_moment(); |
---|
[466] | 644 | update_category('all'); |
---|
[486] | 645 | echo get_elapsed_time($start,get_moment()).' for update_category(all)<br />'; |
---|
| 646 | $start = get_moment(); |
---|
| 647 | ordering(); |
---|
| 648 | echo get_elapsed_time($start, get_moment()).' for ordering categories<br />'; |
---|
[345] | 649 | } |
---|
[589] | 650 | // +-----------------------------------------------------------------------+ |
---|
| 651 | // | synchronize metadata | |
---|
| 652 | // +-----------------------------------------------------------------------+ |
---|
| 653 | else if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync'])) |
---|
[486] | 654 | { |
---|
[589] | 655 | // sync only never synchronized files ? |
---|
| 656 | if ($_POST['sync'] == 'metadata_new') |
---|
[486] | 657 | { |
---|
[589] | 658 | $opts['only_new'] = true; |
---|
[486] | 659 | } |
---|
[589] | 660 | else |
---|
[486] | 661 | { |
---|
[589] | 662 | $opts['only_new'] = false; |
---|
[486] | 663 | } |
---|
[589] | 664 | $opts['category_id'] = ''; |
---|
| 665 | $opts['recursive'] = true; |
---|
| 666 | |
---|
| 667 | if (isset($_POST['cat'])) |
---|
[486] | 668 | { |
---|
[589] | 669 | $opts['category_id'] = $_POST['cat']; |
---|
| 670 | // recursive ? |
---|
| 671 | if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1) |
---|
| 672 | { |
---|
| 673 | $opts['recursive'] = false; |
---|
| 674 | } |
---|
[486] | 675 | } |
---|
[589] | 676 | $start = get_moment(); |
---|
| 677 | $files = get_filelist($opts['category_id'], |
---|
| 678 | $opts['recursive'], |
---|
| 679 | $opts['only_new']); |
---|
[486] | 680 | echo get_elapsed_time($start, get_moment()).' for get_filelist<br />'; |
---|
| 681 | |
---|
| 682 | $start = get_moment(); |
---|
| 683 | update_metadata($files); |
---|
| 684 | echo get_elapsed_time($start, get_moment()).' for metadata update<br />'; |
---|
| 685 | } |
---|
[589] | 686 | // +-----------------------------------------------------------------------+ |
---|
| 687 | // | sending html code | |
---|
| 688 | // +-----------------------------------------------------------------------+ |
---|
[393] | 689 | $template->assign_var_from_handle('ADMIN_CONTENT', 'update'); |
---|
[486] | 690 | ?> |
---|