source: trunk/admin/site_update.php @ 23428

Last change on this file since 23428 was 23428, checked in by flop25, 11 years ago

bug:2855
take care if no parent album, and propagate the permissions
ToDo: check "Apply to sub" checkbox if $conf inheritance_by_default is true, optimizations

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