source: branches/2.2/admin/site_update.php @ 11727

Last change on this file since 11727 was 11727, checked in by plg, 13 years ago

feature 2245: when a new private album is added, the creator and admins
automatically get permission on it.

  • Property svn:eol-style set to LF
File size: 25.4 KB
RevLine 
[1058]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[8728]5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
[2297]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
[1058]23
24if (!defined('PHPWG_ROOT_PATH'))
25{
[1064]26  die('Hacking attempt!');
[1058]27}
28
[1072]29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
[1064]36if (!is_numeric($_GET['site']))
[1058]37{
38  die ('site param missing or invalid');
39}
40$site_id = $_GET['site'];
[1064]41
42$query='
43SELECT galleries_url
44  FROM '.SITES_TABLE.'
[2491]45  WHERE id = '.$site_id;
[4325]46list($site_url) = pwg_db_fetch_row(pwg_query($query));
[1064]47if (!isset($site_url))
[1058]48{
[1064]49  die('site '.$site_id.' does not exist');
[1058]50}
51$site_is_remote = url_is_remote($site_url);
52
[4325]53list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
[1058]54define('CURRENT_DATE', $dbnow);
55
56$error_labels = array(
[1064]57  'PWG-UPDATE-1' => array(
[5021]58    l10n('wrong filename'),
[5207]59    l10n('The name of directories and files must be composed of letters, numbers, "-", "_" or "."')
[1064]60    ),
61  'PWG-UPDATE-2' => array(
[5021]62    l10n('missing thumbnail'),
[7024]63    l10n('a picture filetype requires a thumbnail. The thumbnail must be present in the sub-directory "thumbnail" of the album directory. The thumbnail filename must start with the configured thumbnail prefix and the extension must be among the following list :').implode(',', $conf['picture_ext'])
[1064]64    ),
65  'PWG-ERROR-NO-FS' => array(
[5021]66    l10n('File/directory read error'),
67    l10n('The file or directory cannot be accessed (either it does not exist or the access is denied)')
[1064]68    ),
69  'PWG-ERROR-VERSION' => array(
[5021]70    l10n('Piwigo version differs on the remote site'),
71    l10n('Version of create_listing_file.php on the remote site and Piwigo must be the same')
[1064]72    ),
73  'PWG-ERROR-NOLISTING' => array(
[5021]74    l10n('listing.xml file was not found'),
[5207]75    l10n('listing.xml file was not found on the remote site. This file is generated by choosing the "generate listing" command in the Site manager')
[1064]76    )
77  );
[1058]78$errors = array();
79$infos = array();
80
81if ($site_is_remote)
82{
[1064]83  include_once(PHPWG_ROOT_PATH.'admin/site_reader_remote.php');
[1107]84  $local_listing = null;
85  if ( isset($_GET['local_listing'])
86      and $_GET['local_listing'] )
87  {
88    $local_listing = PHPWG_ROOT_PATH.'listing.xml';
89  }
90  $site_reader = new RemoteSiteReader($site_url, $local_listing);
[1058]91}
92else
93{
94  include_once( PHPWG_ROOT_PATH.'admin/site_reader_local.php');
95  $site_reader = new LocalSiteReader($site_url);
96}
97
[1064]98$general_failure = true;
[1058]99if (isset($_POST['submit']))
100{
[1204]101  if (!isset($conf['flip_picture_ext']))
102  {
103    $conf['flip_picture_ext'] = array_flip($conf['picture_ext']);
104  }
[1058]105  if ($site_reader->open())
106  {
107    $general_failure = false;
108  }
[1458]109
[1058]110  // shall we simulate only
[8126]111  if (isset($_POST['simulate']) and $_POST['simulate'] == 1)
[1058]112  {
113    $simulate = true;
114  }
115  else
116  {
117    $simulate = false;
118  }
119}
120
121// +-----------------------------------------------------------------------+
122// |                      directories / categories                         |
123// +-----------------------------------------------------------------------+
124if (isset($_POST['submit'])
[2038]125    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files'))
[1058]126{
127  $counts['new_categories'] = 0;
128  $counts['del_categories'] = 0;
129  $counts['del_elements'] = 0;
130  $counts['new_elements'] = 0;
[1204]131  $counts['upd_elements'] = 0;
[2038]132}
[1058]133
[2038]134
135if (isset($_POST['submit'])
136    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')
137    and !$general_failure)
138{
[1058]139  $start = get_moment();
140  // which categories to update ?
141  $query = '
142SELECT id, uppercats, global_rank, status, visible
143  FROM '.CATEGORIES_TABLE.'
144  WHERE dir IS NOT NULL
145    AND site_id = '.$site_id;
146  if (isset($_POST['cat']) and is_numeric($_POST['cat']))
147  {
148    if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1)
149    {
150      $query.= '
[4367]151    AND uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.$_POST['cat'].'(,|$)\'
[1058]152';
153    }
154    else
155    {
156      $query.= '
157    AND id = '.$_POST['cat'].'
158';
159    }
160  }
[2491]161  $db_categories = hash_from_query($query, 'id');
[1058]162
163  // get categort full directories in an array for comparison with file
164  // system directory tree
165  $db_fulldirs = get_fulldirs(array_keys($db_categories));
166
167  // what is the base directory to search file system sub-directories ?
168  if (isset($_POST['cat']) and is_numeric($_POST['cat']))
169  {
170    $basedir = $db_fulldirs[$_POST['cat']];
171  }
172  else
173  {
174    $basedir = preg_replace('#/*$#', '', $site_url);
175  }
176
177  // we need to have fulldirs as keys to make efficient comparison
178  $db_fulldirs = array_flip($db_fulldirs);
179
180  // finding next rank for each id_uppercat. By default, each category id
181  // has 1 for next rank on its sub-categories to create
182  $next_rank['NULL'] = 1;
183
184  $query = '
185SELECT id
[2491]186  FROM '.CATEGORIES_TABLE;
[1058]187  $result = pwg_query($query);
[4325]188  while ($row = pwg_db_fetch_assoc($result))
[1058]189  {
190    $next_rank[$row['id']] = 1;
191  }
192
193  // let's see if some categories already have some sub-categories...
194  $query = '
195SELECT id_uppercat, MAX(rank)+1 AS next_rank
196  FROM '.CATEGORIES_TABLE.'
[2491]197  GROUP BY id_uppercat';
[1058]198  $result = pwg_query($query);
[4325]199  while ($row = pwg_db_fetch_assoc($result))
[1058]200  {
201    // for the id_uppercat NULL, we write 'NULL' and not the empty string
202    if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '')
203    {
204      $row['id_uppercat'] = 'NULL';
205    }
206    $next_rank[$row['id_uppercat']] = $row['next_rank'];
207  }
208
209  // next category id available
[4367]210  $next_id = pwg_db_nextval('id', CATEGORIES_TABLE);
[1058]211
212  // retrieve sub-directories fulldirs from the site reader
213  $fs_fulldirs = $site_reader->get_full_directories($basedir);
214
215  // get_full_directories doesn't include the base directory, so if it's a
216  // category directory, we need to include it in our array
217  if (isset($_POST['cat']))
218  {
219    array_push($fs_fulldirs, $basedir);
220  }
[6951]221  // If $_POST['subcats-included'] != 1 ("Search in sub-albums" is unchecked)
[2344]222  // $db_fulldirs doesn't include any subdirectories and $fs_fulldirs does
223  // So $fs_fulldirs will be limited to the selected basedir
224  // (if that one is in $fs_fulldirs)
225  if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
226  {
227    $fs_fulldirs = array_intersect($fs_fulldirs, array_keys($db_fulldirs));
228  }
[1058]229  $inserts = array();
230  // new categories are the directories not present yet in the database
231  foreach (array_diff($fs_fulldirs, array_keys($db_fulldirs)) as $fulldir)
232  {
233    $dir = basename($fulldir);
234    if (preg_match('/^[a-zA-Z0-9-_.]+$/', $dir))
235    {
[1064]236      $insert = array(
237        'id'          => $next_id++,
238        'dir'         => $dir,
239        'name'        => str_replace('_', ' ', $dir),
240        'site_id'     => $site_id,
[1278]241        'commentable' =>
242          boolean_to_string($conf['newcat_default_commentable']),
[4325]243        'status'      => $conf['newcat_default_status'],
244        'visible'     => boolean_to_string($conf['newcat_default_visible']),
[1064]245        );
[1058]246
247      if (isset($db_fulldirs[dirname($fulldir)]))
248      {
249        $parent = $db_fulldirs[dirname($fulldir)];
250
[4325]251        $insert['id_uppercat'] = $parent;
252        $insert['uppercats'] =
253          $db_categories[$parent]['uppercats'].','.$insert['id'];
254        $insert['rank'] = $next_rank[$parent]++;
255        $insert['global_rank'] =
256          $db_categories[$parent]['global_rank'].'.'.$insert['rank'];
[1058]257        if ('private' == $db_categories[$parent]['status'])
258        {
[4325]259          $insert['status'] = 'private';
[1058]260        }
261        if ('false' == $db_categories[$parent]['visible'])
262        {
[4325]263          $insert['visible'] = 'false';
[1058]264        }
265      }
266      else
267      {
[4325]268        $insert['uppercats'] = $insert['id'];
[1058]269        $insert{'rank'} = $next_rank['NULL']++;
[4325]270        $insert['global_rank'] = $insert['rank'];
[1058]271      }
272
273      array_push($inserts, $insert);
[1064]274      array_push(
275        $infos,
276        array(
277          'path' => $fulldir,
[5021]278          'info' => l10n('added')
[1064]279          )
280        );
[1058]281
282      // add the new category to $db_categories and $db_fulldirs array
283      $db_categories[$insert{'id'}] =
284        array(
[4325]285          'id' => $insert['id'],
286          'status' => $insert['status'],
287          'visible' => $insert['visible'],
288          'uppercats' => $insert['uppercats'],
289          'global_rank' => $insert['global_rank']
[1058]290          );
[4325]291      $db_fulldirs[$fulldir] = $insert['id'];
[1058]292      $next_rank[$insert{'id'}] = 1;
293    }
294    else
295    {
[1064]296      array_push(
297        $errors,
298        array(
299          'path' => $fulldir,
300          'type' => 'PWG-UPDATE-1'
301          )
302        );
[1058]303    }
304  }
305
306  if (count($inserts) > 0)
307  {
308    if (!$simulate)
309    {
310      $dbfields = array(
311        'id','dir','name','site_id','id_uppercat','uppercats','commentable',
[8651]312        'visible','status','rank','global_rank'
[1058]313        );
314      mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts);
315    }
316
[11727]317    // add default permissions to categories
318    $category_ids = array();
319    foreach ($inserts as $category)
320    {
321      $category_ids[] = $category['id'];
322    }
323    add_permission_on_category($category_ids, get_admins());
324
[1058]325    $counts['new_categories'] = count($inserts);
326  }
327
328  // to delete categories
329  $to_delete = array();
330  foreach (array_diff(array_keys($db_fulldirs), $fs_fulldirs) as $fulldir)
331  {
332    array_push($to_delete, $db_fulldirs[$fulldir]);
333    unset($db_fulldirs[$fulldir]);
334    array_push($infos, array('path' => $fulldir,
[5021]335                             'info' => l10n('deleted')));
[1058]336  }
337  if (count($to_delete) > 0)
338  {
339    if (!$simulate)
340    {
341      delete_categories($to_delete);
342    }
343    $counts['del_categories'] = count($to_delete);
344  }
345
[2276]346  $template->append('footer_elements', '<!-- scanning dirs : '
[2107]347    . get_elapsed_time($start, get_moment())
[2276]348    . ' -->' );
[1058]349}
350// +-----------------------------------------------------------------------+
351// |                           files / elements                            |
352// +-----------------------------------------------------------------------+
353if (isset($_POST['submit']) and $_POST['sync'] == 'files'
354      and !$general_failure)
355{
356  $start_files = get_moment();
357  $start= $start_files;
358
359  $fs = $site_reader->get_elements($basedir);
[2276]360  $template->append('footer_elements', '<!-- get_elements: '
[2107]361    . get_elapsed_time($start, get_moment())
[2276]362    . ' -->' );
[1058]363
364  $cat_ids = array_diff(array_keys($db_categories), $to_delete);
365
366  $db_elements = array();
367
368  if (count($cat_ids) > 0)
369  {
370    $query = '
371SELECT id, path
372  FROM '.IMAGES_TABLE.'
[1121]373  WHERE storage_category_id IN ('
374      .wordwrap(
[1064]375        implode(', ', $cat_ids),
376        80,
377        "\n"
[2491]378        ).')';
379    $db_elements = simple_hash_from_query($query, 'id', 'path');
[1058]380  }
381
382  // next element id available
[4367]383  $next_element_id = pwg_db_nextval('id', IMAGES_TABLE);
[1058]384
385  $start = get_moment();
386
387  $inserts = array();
388  $insert_links = array();
389
[8651]390  foreach (array_diff(array_keys($fs), $db_elements) as $path)
[1058]391  {
392    $insert = array();
393    // storage category must exist
394    $dirname = dirname($path);
395    if (!isset($db_fulldirs[$dirname]))
396    {
397      continue;
398    }
399    $filename = basename($path);
400    if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename))
401    {
[1064]402      array_push(
403        $errors,
404        array(
405          'path' => $path,
406          'type' => 'PWG-UPDATE-1'
407          )
408        );
[1107]409
[1058]410      continue;
411    }
412
[2306]413    if ( isset( $conf['flip_picture_ext'][get_extension($filename)] )
[2292]414          and !isset($fs[$path]['tn_ext']) )
[2306]415    { // For a picture thumbnail is mandatory and for non picture element,
[2292]416      // thumbnail and representative are optionnal
417      array_push(
418        $errors,
419        array(
420          'path' => $path,
421          'type' => 'PWG-UPDATE-2'
422          )
423        );
[1058]424    }
425    else
426    {
[1064]427      $insert = array(
428        'id'             => $next_element_id++,
429        'file'           => $filename,
430        'date_available' => CURRENT_DATE,
431        'path'           => $path,
432        'tn_ext'         => isset($fs[$path]['tn_ext'])
433          ? $fs[$path]['tn_ext']
434          : null,
[1121]435        'storage_category_id' => $db_fulldirs[$dirname],
[8464]436        'added_by' => $user['id'],
[1064]437        );
[2306]438
[2292]439      if ( $_POST['privacy_level']!=0 )
440      {
441        $insert['level'] = $_POST['privacy_level'];
442      }
[1058]443
[1064]444      array_push(
445        $inserts,
446        $insert
447        );
[1058]448
[1064]449      array_push(
450        $insert_links,
451        array(
[4325]452          'image_id'    => $insert['id'],
[1121]453          'category_id' => $insert['storage_category_id'],
[1064]454          )
455        );
456
457      array_push(
458        $infos,
459        array(
[4325]460          'path' => $insert['path'],
[5021]461          'info' => l10n('added')
[1064]462          )
463        );
[2114]464
465      $caddiables[] = $insert['id'];
[1058]466    }
467  }
468
469  if (count($inserts) > 0)
470  {
471    if (!$simulate)
472    {
473      // inserts all new elements
[1064]474      mass_inserts(
475        IMAGES_TABLE,
[1122]476        array_keys($inserts[0]),
[1064]477        $inserts
[1058]478        );
479
[1064]480      // inserts all links between new elements and their storage category
481      mass_inserts(
482        IMAGE_CATEGORY_TABLE,
[1122]483        array_keys($insert_links[0]),
[1064]484        $insert_links
485        );
[2114]486
[8682]487      // add new photos to caddie
[2114]488      if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1)
489      {
490        fill_caddie($caddiables);
491      }
[1058]492    }
493    $counts['new_elements'] = count($inserts);
494  }
495
496  // delete elements that are in database but not in the filesystem
497  $to_delete_elements = array();
498  foreach (array_diff($db_elements, array_keys($fs)) as $path)
499  {
500    array_push($to_delete_elements, array_search($path, $db_elements));
501    array_push($infos, array('path' => $path,
[5021]502                             'info' => l10n('deleted')));
[1058]503  }
504  if (count($to_delete_elements) > 0)
505  {
506    if (!$simulate)
507    {
508      delete_elements($to_delete_elements);
509    }
510    $counts['del_elements'] = count($to_delete_elements);
511  }
512
[2276]513  $template->append('footer_elements', '<!-- scanning files : '
[2107]514    . get_elapsed_time($start_files, get_moment())
[2276]515    . ' -->' );
[1058]516}
517
518// +-----------------------------------------------------------------------+
519// |                          synchronize files                            |
520// +-----------------------------------------------------------------------+
521if (isset($_POST['submit'])
[1204]522    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')
523    and !$general_failure )
[1058]524{
525  if (!$simulate)
526  {
527    $start = get_moment();
528    update_category('all');
[2276]529    $template->append('footer_elements', '<!-- update_category(all) : '
[2107]530      . get_elapsed_time($start,get_moment())
[2276]531      . ' -->' );
[1058]532    $start = get_moment();
533    update_global_rank();
[2276]534    $template->append('footer_elements', '<!-- ordering categories : '
[2107]535      . get_elapsed_time($start, get_moment())
[2276]536      . ' -->');
[1058]537  }
[1204]538
539  if ($_POST['sync'] == 'files')
540  {
541    $start = get_moment();
542    $opts['category_id'] = '';
543    $opts['recursive'] = true;
544    if (isset($_POST['cat']))
545    {
546      $opts['category_id'] = $_POST['cat'];
547      if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
548      {
549        $opts['recursive'] = false;
550      }
551    }
552    $files = get_filelist($opts['category_id'], $site_id,
553                          $opts['recursive'],
554                          false);
[2276]555    $template->append('footer_elements', '<!-- get_filelist : '
[2107]556      . get_elapsed_time($start, get_moment())
[2276]557      . ' -->');
[1204]558    $start = get_moment();
559
560    $datas = array();
561    foreach ( $files as $id=>$file )
562    {
563      $data = $site_reader->get_element_update_attributes($file);
564      if ( !is_array($data) )
565      {
566        continue;
567      }
568      $extension = get_extension($file);
569      if ( isset($conf['flip_picture_ext'][$extension]) )
570      {
571        if ( !isset($data['tn_ext']) )
572        {
573          array_push(
574            $errors,
575            array(
576              'path' => $file,
577              'type' => 'PWG-UPDATE-2'
578              )
579            );
580          continue;
581        }
582      }
583
584      $data['id']=$id;
585      array_push($datas, $data);
586    } // end foreach file
587
588    $counts['upd_elements'] = count($datas);
589    if (!$simulate and count($datas)>0 )
590    {
591      mass_updates(
592        IMAGES_TABLE,
593        // fields
594        array(
595          'primary' => array('id'),
596          'update'  => $site_reader->get_update_attributes(),
597          ),
598        $datas
599        );
600    }
[2276]601    $template->append('footer_elements', '<!-- update files : '
[2107]602      . get_elapsed_time($start,get_moment())
[2276]603      . ' -->');
[1204]604  }// end if sync files
[1058]605}
606
607// +-----------------------------------------------------------------------+
[1204]608// |                          synchronize files                            |
609// +-----------------------------------------------------------------------+
610if (isset($_POST['submit'])
611    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files'))
612{
[2276]613  $template->assign(
[1204]614    'update_result',
615    array(
616      'NB_NEW_CATEGORIES'=>$counts['new_categories'],
617      'NB_DEL_CATEGORIES'=>$counts['del_categories'],
618      'NB_NEW_ELEMENTS'=>$counts['new_elements'],
619      'NB_DEL_ELEMENTS'=>$counts['del_elements'],
620      'NB_UPD_ELEMENTS'=>$counts['upd_elements'],
621      'NB_ERRORS'=>count($errors),
622      ));
623}
624
625// +-----------------------------------------------------------------------+
[1058]626// |                          synchronize metadata                         |
627// +-----------------------------------------------------------------------+
[2491]628if (isset($_POST['submit']) and isset($_POST['sync_meta'])
[1058]629         and !$general_failure)
630{
631  // sync only never synchronized files ?
[2491]632  $opts['only_new'] = isset($_POST['meta_all']) ? false : true;
[1058]633  $opts['category_id'] = '';
634  $opts['recursive'] = true;
635
636  if (isset($_POST['cat']))
637  {
638    $opts['category_id'] = $_POST['cat'];
639    // recursive ?
640    if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
641    {
642      $opts['recursive'] = false;
643    }
644  }
645  $start = get_moment();
646  $files = get_filelist($opts['category_id'], $site_id,
647                        $opts['recursive'],
648                        $opts['only_new']);
649
[2276]650  $template->append('footer_elements', '<!-- get_filelist : '
[2107]651    . get_elapsed_time($start, get_moment())
[2276]652    . ' -->');
[1058]653
654  $start = get_moment();
655  $datas = array();
[1119]656  $tags_of = array();
[1883]657
658  $has_high_images = array();
659
660  $image_ids = array();
661  foreach ($files as $id => $file)
662  {
663    array_push($image_ids, $id);
664  }
665
666  if (count($image_ids) > 0)
667  {
668    $query = '
669SELECT id
670  FROM '.IMAGES_TABLE.'
671  WHERE has_high = \'true\'
672    AND id IN (
673'.wordwrap(implode(', ', $image_ids), 80, "\n").'
[2491]674)';
675    $has_high_images = array_from_query($query, 'id' );
[1883]676  }
[2107]677
[1058]678  foreach ( $files as $id=>$file )
679  {
[1883]680    $data = $site_reader->get_element_metadata(
681      $file,
682      in_array($id, $has_high_images)
683      );
[2107]684
[1058]685    if ( is_array($data) )
686    {
687      $data['date_metadata_update'] = CURRENT_DATE;
688      $data['id']=$id;
689      array_push($datas, $data);
[1119]690
691      foreach (array('keywords', 'tags') as $key)
692      {
693        if (isset($data[$key]))
694        {
695          if (!isset($tags_of[$id]))
696          {
697            $tags_of[$id] = array();
698          }
[1204]699
[1119]700          foreach (explode(',', $data[$key]) as $tag_name)
701          {
702            array_push(
703              $tags_of[$id],
704              tag_id_from_tag_name($tag_name)
705              );
706          }
707        }
708      }
[1058]709    }
710    else
711    {
712      array_push($errors, array('path' => $file, 'type' => 'PWG-ERROR-NO-FS'));
713    }
714  }
[1119]715
716  if (!$simulate)
717  {
718    if (count($datas) > 0)
719    {
720      mass_updates(
721        IMAGES_TABLE,
722        // fields
723        array(
724          'primary' => array('id'),
725          'update'  => array_unique(
726            array_merge(
727              array_diff(
[1204]728                $site_reader->get_metadata_attributes(),
[1119]729                // keywords and tags fields are managed separately
730                array('keywords', 'tags')
731                ),
732              array('date_metadata_update'))
733            )
734          ),
[2491]735        $datas,
736        isset($_POST['meta_empty_overrides']) ? 0 : MASS_UPDATES_SKIP_EMPTY
[1058]737        );
[1119]738    }
739    set_tags_of($tags_of);
[1058]740  }
741
[2276]742  $template->append('footer_elements', '<!-- metadata update : '
[2107]743    . get_elapsed_time($start, get_moment())
[2276]744    . ' -->');
[1058]745
[2276]746  $template->assign(
[1058]747    'metadata_result',
748    array(
749      'NB_ELEMENTS_DONE' => count($datas),
750      'NB_ELEMENTS_CANDIDATES' => count($files),
751      'NB_ERRORS' => count($errors),
752      ));
753}
754
755// +-----------------------------------------------------------------------+
756// |                        template initialization                        |
757// +-----------------------------------------------------------------------+
[2530]758$template->set_filenames(array('update'=>'site_update.tpl'));
[1058]759$result_title = '';
760if (isset($simulate) and $simulate)
761{
[5021]762  $result_title.= l10n('[Simulation]').' ';
[1058]763}
764
765// used_metadata string is displayed to inform admin which metadata will be
766// used from files for synchronization
[1204]767$used_metadata = implode( ', ', $site_reader->get_metadata_attributes());
[1058]768if ($site_is_remote and !isset($_POST['submit']) )
769{
770  $used_metadata.= ' + ...';
771}
772
[2276]773$template->assign(
[1058]774  array(
775    'SITE_URL'=>$site_url,
[2276]776    'U_SITE_MANAGER'=> get_root_url().'admin.php?page=site_manager',
[5021]777    'L_RESULT_UPDATE'=>$result_title.l10n('Search for new images in the directories'),
778    'L_RESULT_METADATA'=>$result_title.l10n('Metadata synchronization results'),
[2276]779    'METADATA_LIST' => $used_metadata,
[5920]780    'U_HELP' => get_root_url().'admin/popuphelp.php?page=synchronize',
[1058]781    ));
782
783// +-----------------------------------------------------------------------+
784// |                        introduction : choices                         |
785// +-----------------------------------------------------------------------+
[2491]786if (isset($_POST['submit']))
[1058]787{
[2491]788  $tpl_introduction = array(
789      'sync'  => $_POST['sync'],
790      'sync_meta'  => isset($_POST['sync_meta']) ? true : false,
791      'display_info' => isset($_POST['display_info']) and $_POST['display_info']==1,
792      'add_to_caddie' => isset($_POST['add_to_caddie']) and $_POST['add_to_caddie']==1,
793      'subcats_included' => isset($_POST['subcats-included']) and $_POST['subcats-included']==1,
794      'privacy_level_selected' => (int)@$_POST['privacy_level'],
795      'meta_all'  => isset($_POST['meta_all']) ? true : false,
796      'meta_empty_overrides'  => isset($_POST['meta_empty_overrides']) ? true : false,
797    );
798
799  if (isset($_POST['cat']) and is_numeric($_POST['cat']))
[1058]800  {
[2491]801    $cat_selected = array($_POST['cat']);
[1058]802  }
803  else
804  {
805    $cat_selected = array();
806  }
[2491]807}
808else
809{
810  $tpl_introduction = array(
811      'sync'  => 'dirs',
812      'sync_meta'  => true,
813      'display_info' => false,
814      'add_to_caddie' => false,
815      'subcats_included' => true,
816      'privacy_level_selected' => 0,
817      'meta_all'  => false,
818      'meta_empty_overrides'  => false,
819    );
[11040]820 
821  $cat_selected = array();
[1058]822
[11040]823  if (isset($_GET['cat_id']))
824  {
825    check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
826
827    $cat_selected = array($_GET['cat_id']);
828    $tpl_introduction['sync'] = 'files';
829  }
[2491]830}
[2292]831
[6025]832$tpl_introduction['privacy_level_options'] = get_privacy_level_options();
[2276]833
[2491]834$template->assign('introduction', $tpl_introduction);
835
836$query = '
[1058]837SELECT id,name,uppercats,global_rank
838  FROM '.CATEGORIES_TABLE.'
[2491]839  WHERE site_id = '.$site_id;
840display_select_cat_wrapper($query,
841                           $cat_selected,
842                           'category_options',
843                           false);
[1058]844
[2491]845
[1058]846if (count($errors) > 0)
847{
848  foreach ($errors as $error)
849  {
[2276]850    $template->append(
851      'sync_errors',
[1058]852      array(
853        'ELEMENT' => $error['path'],
854        'LABEL' => $error['type'].' ('.$error_labels[$error['type']][0].')'
855        ));
856  }
857
858  foreach ($error_labels as $error_type=>$error_description)
859  {
[2276]860    $template->append(
861      'sync_error_captions',
[1058]862      array(
863        'TYPE' => $error_type,
864        'LABEL' => $error_description[1]
865        ));
866  }
[2276]867}
[1058]868
869if (count($infos) > 0
870    and isset($_POST['display_info'])
871    and $_POST['display_info'] == 1)
872{
873  foreach ($infos as $info)
874  {
[2276]875    $template->append(
876      'sync_infos',
[1058]877      array(
878        'ELEMENT' => $info['path'],
879        'LABEL' => $info['info']
880        ));
881  }
882}
883
884// +-----------------------------------------------------------------------+
885// |                          sending html code                            |
886// +-----------------------------------------------------------------------+
887$template->assign_var_from_handle('ADMIN_CONTENT', 'update');
[1903]888?>
Note: See TracBrowser for help on using the repository browser.