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

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

bug 1786 fixed: ability to prefilter the synchronize screen with a specific
album by clicking on the new "Synchronize" icon on album admin page or album
admin list.

This is not the solution proposed by Gotcha (ie a treeview to select the album
on the synchronize screen) but it solves the same problem.

  • Property svn:eol-style set to LF
File size: 25.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
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// +-----------------------------------------------------------------------+
23
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die('Hacking attempt!');
27}
28
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
36if (!is_numeric($_GET['site']))
37{
38  die ('site param missing or invalid');
39}
40$site_id = $_GET['site'];
41
42$query='
43SELECT galleries_url
44  FROM '.SITES_TABLE.'
45  WHERE id = '.$site_id;
46list($site_url) = pwg_db_fetch_row(pwg_query($query));
47if (!isset($site_url))
48{
49  die('site '.$site_id.' does not exist');
50}
51$site_is_remote = url_is_remote($site_url);
52
53list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
54define('CURRENT_DATE', $dbnow);
55
56$error_labels = array(
57  'PWG-UPDATE-1' => array(
58    l10n('wrong filename'),
59    l10n('The name of directories and files must be composed of letters, numbers, "-", "_" or "."')
60    ),
61  'PWG-UPDATE-2' => array(
62    l10n('missing thumbnail'),
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'])
64    ),
65  'PWG-ERROR-NO-FS' => array(
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)')
68    ),
69  'PWG-ERROR-VERSION' => array(
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')
72    ),
73  'PWG-ERROR-NOLISTING' => array(
74    l10n('listing.xml file was not found'),
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')
76    )
77  );
78$errors = array();
79$infos = array();
80
81if ($site_is_remote)
82{
83  include_once(PHPWG_ROOT_PATH.'admin/site_reader_remote.php');
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);
91}
92else
93{
94  include_once( PHPWG_ROOT_PATH.'admin/site_reader_local.php');
95  $site_reader = new LocalSiteReader($site_url);
96}
97
98$general_failure = true;
99if (isset($_POST['submit']))
100{
101  if (!isset($conf['flip_picture_ext']))
102  {
103    $conf['flip_picture_ext'] = array_flip($conf['picture_ext']);
104  }
105  if ($site_reader->open())
106  {
107    $general_failure = false;
108  }
109
110  // shall we simulate only
111  if (isset($_POST['simulate']) and $_POST['simulate'] == 1)
112  {
113    $simulate = true;
114  }
115  else
116  {
117    $simulate = false;
118  }
119}
120
121// +-----------------------------------------------------------------------+
122// |                      directories / categories                         |
123// +-----------------------------------------------------------------------+
124if (isset($_POST['submit'])
125    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files'))
126{
127  $counts['new_categories'] = 0;
128  $counts['del_categories'] = 0;
129  $counts['del_elements'] = 0;
130  $counts['new_elements'] = 0;
131  $counts['upd_elements'] = 0;
132}
133
134
135if (isset($_POST['submit'])
136    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')
137    and !$general_failure)
138{
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.= '
151    AND uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.$_POST['cat'].'(,|$)\'
152';
153    }
154    else
155    {
156      $query.= '
157    AND id = '.$_POST['cat'].'
158';
159    }
160  }
161  $db_categories = hash_from_query($query, 'id');
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
186  FROM '.CATEGORIES_TABLE;
187  $result = pwg_query($query);
188  while ($row = pwg_db_fetch_assoc($result))
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.'
197  GROUP BY id_uppercat';
198  $result = pwg_query($query);
199  while ($row = pwg_db_fetch_assoc($result))
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
210  $next_id = pwg_db_nextval('id', CATEGORIES_TABLE);
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  }
221  // If $_POST['subcats-included'] != 1 ("Search in sub-albums" is unchecked)
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  }
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    {
236      $insert = array(
237        'id'          => $next_id++,
238        'dir'         => $dir,
239        'name'        => str_replace('_', ' ', $dir),
240        'site_id'     => $site_id,
241        'commentable' =>
242          boolean_to_string($conf['newcat_default_commentable']),
243        'status'      => $conf['newcat_default_status'],
244        'visible'     => boolean_to_string($conf['newcat_default_visible']),
245        );
246
247      if (isset($db_fulldirs[dirname($fulldir)]))
248      {
249        $parent = $db_fulldirs[dirname($fulldir)];
250
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'];
257        if ('private' == $db_categories[$parent]['status'])
258        {
259          $insert['status'] = 'private';
260        }
261        if ('false' == $db_categories[$parent]['visible'])
262        {
263          $insert['visible'] = 'false';
264        }
265      }
266      else
267      {
268        $insert['uppercats'] = $insert['id'];
269        $insert{'rank'} = $next_rank['NULL']++;
270        $insert['global_rank'] = $insert['rank'];
271      }
272
273      array_push($inserts, $insert);
274      array_push(
275        $infos,
276        array(
277          'path' => $fulldir,
278          'info' => l10n('added')
279          )
280        );
281
282      // add the new category to $db_categories and $db_fulldirs array
283      $db_categories[$insert{'id'}] =
284        array(
285          'id' => $insert['id'],
286          'status' => $insert['status'],
287          'visible' => $insert['visible'],
288          'uppercats' => $insert['uppercats'],
289          'global_rank' => $insert['global_rank']
290          );
291      $db_fulldirs[$fulldir] = $insert['id'];
292      $next_rank[$insert{'id'}] = 1;
293    }
294    else
295    {
296      array_push(
297        $errors,
298        array(
299          'path' => $fulldir,
300          'type' => 'PWG-UPDATE-1'
301          )
302        );
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',
312        'visible','status','rank','global_rank'
313        );
314      mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts);
315    }
316
317    $counts['new_categories'] = count($inserts);
318  }
319
320  // to delete categories
321  $to_delete = array();
322  foreach (array_diff(array_keys($db_fulldirs), $fs_fulldirs) as $fulldir)
323  {
324    array_push($to_delete, $db_fulldirs[$fulldir]);
325    unset($db_fulldirs[$fulldir]);
326    array_push($infos, array('path' => $fulldir,
327                             'info' => l10n('deleted')));
328  }
329  if (count($to_delete) > 0)
330  {
331    if (!$simulate)
332    {
333      delete_categories($to_delete);
334    }
335    $counts['del_categories'] = count($to_delete);
336  }
337
338  $template->append('footer_elements', '<!-- scanning dirs : '
339    . get_elapsed_time($start, get_moment())
340    . ' -->' );
341}
342// +-----------------------------------------------------------------------+
343// |                           files / elements                            |
344// +-----------------------------------------------------------------------+
345if (isset($_POST['submit']) and $_POST['sync'] == 'files'
346      and !$general_failure)
347{
348  $start_files = get_moment();
349  $start= $start_files;
350
351  $fs = $site_reader->get_elements($basedir);
352  $template->append('footer_elements', '<!-- get_elements: '
353    . get_elapsed_time($start, get_moment())
354    . ' -->' );
355
356  $cat_ids = array_diff(array_keys($db_categories), $to_delete);
357
358  $db_elements = array();
359
360  if (count($cat_ids) > 0)
361  {
362    $query = '
363SELECT id, path
364  FROM '.IMAGES_TABLE.'
365  WHERE storage_category_id IN ('
366      .wordwrap(
367        implode(', ', $cat_ids),
368        80,
369        "\n"
370        ).')';
371    $db_elements = simple_hash_from_query($query, 'id', 'path');
372  }
373
374  // next element id available
375  $next_element_id = pwg_db_nextval('id', IMAGES_TABLE);
376
377  $start = get_moment();
378
379  $inserts = array();
380  $insert_links = array();
381
382  foreach (array_diff(array_keys($fs), $db_elements) as $path)
383  {
384    $insert = array();
385    // storage category must exist
386    $dirname = dirname($path);
387    if (!isset($db_fulldirs[$dirname]))
388    {
389      continue;
390    }
391    $filename = basename($path);
392    if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename))
393    {
394      array_push(
395        $errors,
396        array(
397          'path' => $path,
398          'type' => 'PWG-UPDATE-1'
399          )
400        );
401
402      continue;
403    }
404
405    if ( isset( $conf['flip_picture_ext'][get_extension($filename)] )
406          and !isset($fs[$path]['tn_ext']) )
407    { // For a picture thumbnail is mandatory and for non picture element,
408      // thumbnail and representative are optionnal
409      array_push(
410        $errors,
411        array(
412          'path' => $path,
413          'type' => 'PWG-UPDATE-2'
414          )
415        );
416    }
417    else
418    {
419      $insert = array(
420        'id'             => $next_element_id++,
421        'file'           => $filename,
422        'date_available' => CURRENT_DATE,
423        'path'           => $path,
424        'tn_ext'         => isset($fs[$path]['tn_ext'])
425          ? $fs[$path]['tn_ext']
426          : null,
427        'storage_category_id' => $db_fulldirs[$dirname],
428        'added_by' => $user['id'],
429        );
430
431      if ( $_POST['privacy_level']!=0 )
432      {
433        $insert['level'] = $_POST['privacy_level'];
434      }
435
436      array_push(
437        $inserts,
438        $insert
439        );
440
441      array_push(
442        $insert_links,
443        array(
444          'image_id'    => $insert['id'],
445          'category_id' => $insert['storage_category_id'],
446          )
447        );
448
449      array_push(
450        $infos,
451        array(
452          'path' => $insert['path'],
453          'info' => l10n('added')
454          )
455        );
456
457      $caddiables[] = $insert['id'];
458    }
459  }
460
461  if (count($inserts) > 0)
462  {
463    if (!$simulate)
464    {
465      // inserts all new elements
466      mass_inserts(
467        IMAGES_TABLE,
468        array_keys($inserts[0]),
469        $inserts
470        );
471
472      // inserts all links between new elements and their storage category
473      mass_inserts(
474        IMAGE_CATEGORY_TABLE,
475        array_keys($insert_links[0]),
476        $insert_links
477        );
478
479      // add new photos to caddie
480      if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1)
481      {
482        fill_caddie($caddiables);
483      }
484    }
485    $counts['new_elements'] = count($inserts);
486  }
487
488  // delete elements that are in database but not in the filesystem
489  $to_delete_elements = array();
490  foreach (array_diff($db_elements, array_keys($fs)) as $path)
491  {
492    array_push($to_delete_elements, array_search($path, $db_elements));
493    array_push($infos, array('path' => $path,
494                             'info' => l10n('deleted')));
495  }
496  if (count($to_delete_elements) > 0)
497  {
498    if (!$simulate)
499    {
500      delete_elements($to_delete_elements);
501    }
502    $counts['del_elements'] = count($to_delete_elements);
503  }
504
505  $template->append('footer_elements', '<!-- scanning files : '
506    . get_elapsed_time($start_files, get_moment())
507    . ' -->' );
508}
509
510// +-----------------------------------------------------------------------+
511// |                          synchronize files                            |
512// +-----------------------------------------------------------------------+
513if (isset($_POST['submit'])
514    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')
515    and !$general_failure )
516{
517  if (!$simulate)
518  {
519    $start = get_moment();
520    update_category('all');
521    $template->append('footer_elements', '<!-- update_category(all) : '
522      . get_elapsed_time($start,get_moment())
523      . ' -->' );
524    $start = get_moment();
525    update_global_rank();
526    $template->append('footer_elements', '<!-- ordering categories : '
527      . get_elapsed_time($start, get_moment())
528      . ' -->');
529  }
530
531  if ($_POST['sync'] == 'files')
532  {
533    $start = get_moment();
534    $opts['category_id'] = '';
535    $opts['recursive'] = true;
536    if (isset($_POST['cat']))
537    {
538      $opts['category_id'] = $_POST['cat'];
539      if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
540      {
541        $opts['recursive'] = false;
542      }
543    }
544    $files = get_filelist($opts['category_id'], $site_id,
545                          $opts['recursive'],
546                          false);
547    $template->append('footer_elements', '<!-- get_filelist : '
548      . get_elapsed_time($start, get_moment())
549      . ' -->');
550    $start = get_moment();
551
552    $datas = array();
553    foreach ( $files as $id=>$file )
554    {
555      $data = $site_reader->get_element_update_attributes($file);
556      if ( !is_array($data) )
557      {
558        continue;
559      }
560      $extension = get_extension($file);
561      if ( isset($conf['flip_picture_ext'][$extension]) )
562      {
563        if ( !isset($data['tn_ext']) )
564        {
565          array_push(
566            $errors,
567            array(
568              'path' => $file,
569              'type' => 'PWG-UPDATE-2'
570              )
571            );
572          continue;
573        }
574      }
575
576      $data['id']=$id;
577      array_push($datas, $data);
578    } // end foreach file
579
580    $counts['upd_elements'] = count($datas);
581    if (!$simulate and count($datas)>0 )
582    {
583      mass_updates(
584        IMAGES_TABLE,
585        // fields
586        array(
587          'primary' => array('id'),
588          'update'  => $site_reader->get_update_attributes(),
589          ),
590        $datas
591        );
592    }
593    $template->append('footer_elements', '<!-- update files : '
594      . get_elapsed_time($start,get_moment())
595      . ' -->');
596  }// end if sync files
597}
598
599// +-----------------------------------------------------------------------+
600// |                          synchronize files                            |
601// +-----------------------------------------------------------------------+
602if (isset($_POST['submit'])
603    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files'))
604{
605  $template->assign(
606    'update_result',
607    array(
608      'NB_NEW_CATEGORIES'=>$counts['new_categories'],
609      'NB_DEL_CATEGORIES'=>$counts['del_categories'],
610      'NB_NEW_ELEMENTS'=>$counts['new_elements'],
611      'NB_DEL_ELEMENTS'=>$counts['del_elements'],
612      'NB_UPD_ELEMENTS'=>$counts['upd_elements'],
613      'NB_ERRORS'=>count($errors),
614      ));
615}
616
617// +-----------------------------------------------------------------------+
618// |                          synchronize metadata                         |
619// +-----------------------------------------------------------------------+
620if (isset($_POST['submit']) and isset($_POST['sync_meta'])
621         and !$general_failure)
622{
623  // sync only never synchronized files ?
624  $opts['only_new'] = isset($_POST['meta_all']) ? false : true;
625  $opts['category_id'] = '';
626  $opts['recursive'] = true;
627
628  if (isset($_POST['cat']))
629  {
630    $opts['category_id'] = $_POST['cat'];
631    // recursive ?
632    if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
633    {
634      $opts['recursive'] = false;
635    }
636  }
637  $start = get_moment();
638  $files = get_filelist($opts['category_id'], $site_id,
639                        $opts['recursive'],
640                        $opts['only_new']);
641
642  $template->append('footer_elements', '<!-- get_filelist : '
643    . get_elapsed_time($start, get_moment())
644    . ' -->');
645
646  $start = get_moment();
647  $datas = array();
648  $tags_of = array();
649
650  $has_high_images = array();
651
652  $image_ids = array();
653  foreach ($files as $id => $file)
654  {
655    array_push($image_ids, $id);
656  }
657
658  if (count($image_ids) > 0)
659  {
660    $query = '
661SELECT id
662  FROM '.IMAGES_TABLE.'
663  WHERE has_high = \'true\'
664    AND id IN (
665'.wordwrap(implode(', ', $image_ids), 80, "\n").'
666)';
667    $has_high_images = array_from_query($query, 'id' );
668  }
669
670  foreach ( $files as $id=>$file )
671  {
672    $data = $site_reader->get_element_metadata(
673      $file,
674      in_array($id, $has_high_images)
675      );
676
677    if ( is_array($data) )
678    {
679      $data['date_metadata_update'] = CURRENT_DATE;
680      $data['id']=$id;
681      array_push($datas, $data);
682
683      foreach (array('keywords', 'tags') as $key)
684      {
685        if (isset($data[$key]))
686        {
687          if (!isset($tags_of[$id]))
688          {
689            $tags_of[$id] = array();
690          }
691
692          foreach (explode(',', $data[$key]) as $tag_name)
693          {
694            array_push(
695              $tags_of[$id],
696              tag_id_from_tag_name($tag_name)
697              );
698          }
699        }
700      }
701    }
702    else
703    {
704      array_push($errors, array('path' => $file, 'type' => 'PWG-ERROR-NO-FS'));
705    }
706  }
707
708  if (!$simulate)
709  {
710    if (count($datas) > 0)
711    {
712      mass_updates(
713        IMAGES_TABLE,
714        // fields
715        array(
716          'primary' => array('id'),
717          'update'  => array_unique(
718            array_merge(
719              array_diff(
720                $site_reader->get_metadata_attributes(),
721                // keywords and tags fields are managed separately
722                array('keywords', 'tags')
723                ),
724              array('date_metadata_update'))
725            )
726          ),
727        $datas,
728        isset($_POST['meta_empty_overrides']) ? 0 : MASS_UPDATES_SKIP_EMPTY
729        );
730    }
731    set_tags_of($tags_of);
732  }
733
734  $template->append('footer_elements', '<!-- metadata update : '
735    . get_elapsed_time($start, get_moment())
736    . ' -->');
737
738  $template->assign(
739    'metadata_result',
740    array(
741      'NB_ELEMENTS_DONE' => count($datas),
742      'NB_ELEMENTS_CANDIDATES' => count($files),
743      'NB_ERRORS' => count($errors),
744      ));
745}
746
747// +-----------------------------------------------------------------------+
748// |                        template initialization                        |
749// +-----------------------------------------------------------------------+
750$template->set_filenames(array('update'=>'site_update.tpl'));
751$result_title = '';
752if (isset($simulate) and $simulate)
753{
754  $result_title.= l10n('[Simulation]').' ';
755}
756
757// used_metadata string is displayed to inform admin which metadata will be
758// used from files for synchronization
759$used_metadata = implode( ', ', $site_reader->get_metadata_attributes());
760if ($site_is_remote and !isset($_POST['submit']) )
761{
762  $used_metadata.= ' + ...';
763}
764
765$template->assign(
766  array(
767    'SITE_URL'=>$site_url,
768    'U_SITE_MANAGER'=> get_root_url().'admin.php?page=site_manager',
769    'L_RESULT_UPDATE'=>$result_title.l10n('Search for new images in the directories'),
770    'L_RESULT_METADATA'=>$result_title.l10n('Metadata synchronization results'),
771    'METADATA_LIST' => $used_metadata,
772    'U_HELP' => get_root_url().'admin/popuphelp.php?page=synchronize',
773    ));
774
775// +-----------------------------------------------------------------------+
776// |                        introduction : choices                         |
777// +-----------------------------------------------------------------------+
778if (isset($_POST['submit']))
779{
780  $tpl_introduction = array(
781      'sync'  => $_POST['sync'],
782      'sync_meta'  => isset($_POST['sync_meta']) ? true : false,
783      'display_info' => isset($_POST['display_info']) and $_POST['display_info']==1,
784      'add_to_caddie' => isset($_POST['add_to_caddie']) and $_POST['add_to_caddie']==1,
785      'subcats_included' => isset($_POST['subcats-included']) and $_POST['subcats-included']==1,
786      'privacy_level_selected' => (int)@$_POST['privacy_level'],
787      'meta_all'  => isset($_POST['meta_all']) ? true : false,
788      'meta_empty_overrides'  => isset($_POST['meta_empty_overrides']) ? true : false,
789    );
790
791  if (isset($_POST['cat']) and is_numeric($_POST['cat']))
792  {
793    $cat_selected = array($_POST['cat']);
794  }
795  else
796  {
797    $cat_selected = array();
798  }
799}
800else
801{
802  $tpl_introduction = array(
803      'sync'  => 'dirs',
804      'sync_meta'  => true,
805      'display_info' => false,
806      'add_to_caddie' => false,
807      'subcats_included' => true,
808      'privacy_level_selected' => 0,
809      'meta_all'  => false,
810      'meta_empty_overrides'  => false,
811    );
812 
813  $cat_selected = array();
814
815  if (isset($_GET['cat_id']))
816  {
817    check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
818
819    $cat_selected = array($_GET['cat_id']);
820    $tpl_introduction['sync'] = 'files';
821  }
822}
823
824$tpl_introduction['privacy_level_options'] = get_privacy_level_options();
825
826$template->assign('introduction', $tpl_introduction);
827
828$query = '
829SELECT id,name,uppercats,global_rank
830  FROM '.CATEGORIES_TABLE.'
831  WHERE site_id = '.$site_id;
832display_select_cat_wrapper($query,
833                           $cat_selected,
834                           'category_options',
835                           false);
836
837
838if (count($errors) > 0)
839{
840  foreach ($errors as $error)
841  {
842    $template->append(
843      'sync_errors',
844      array(
845        'ELEMENT' => $error['path'],
846        'LABEL' => $error['type'].' ('.$error_labels[$error['type']][0].')'
847        ));
848  }
849
850  foreach ($error_labels as $error_type=>$error_description)
851  {
852    $template->append(
853      'sync_error_captions',
854      array(
855        'TYPE' => $error_type,
856        'LABEL' => $error_description[1]
857        ));
858  }
859}
860
861if (count($infos) > 0
862    and isset($_POST['display_info'])
863    and $_POST['display_info'] == 1)
864{
865  foreach ($infos as $info)
866  {
867    $template->append(
868      'sync_infos',
869      array(
870        'ELEMENT' => $info['path'],
871        'LABEL' => $info['info']
872        ));
873  }
874}
875
876// +-----------------------------------------------------------------------+
877// |                          sending html code                            |
878// +-----------------------------------------------------------------------+
879$template->assign_var_from_handle('ADMIN_CONTENT', 'update');
880?>
Note: See TracBrowser for help on using the repository browser.