source: trunk/admin/site_update.php @ 19066

Last change on this file since 19066 was 17650, checked in by rvelices, 12 years ago

bug 2730: multi size not deleted when physical directory deleted

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