source: trunk/admin/site_update.php @ 23430

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

bug:2855
check "Apply to sub" checkbox if $conf inheritance_by_default is true
add admins to the users granted
optimizations

  • Property svn:eol-style set to LF
File size: 27.0 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 (!isset($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        }
337        $query = '
338          SELECT *
339          FROM '.USER_ACCESS_TABLE.'
340          WHERE cat_id IN ('.$category_up.')
341        ;';
342        $result = pwg_query($query);
343        if (!empty($result))
344        {
345          $granted_users = array();
346          while ($row = pwg_db_fetch_assoc($result))
347          {
348            if (!isset($granted_users[$row['cat_id']]))
349            {
350              $granted_users[$row['cat_id']]=array();
351            }
352            array_push(
353              $granted_users,
354              array(
355                $row['cat_id'] => array_push($granted_users[$row['cat_id']],$row['user_id'])
356              )
357            );
358          }
359        }
360        $insert_granted_users=array();
361        $insert_granted_grps=array();
362        foreach ($category_ids as $ids)
363        {
364          $parent_id=$db_categories[$ids]['parent'];
365          while (in_array($parent_id, $category_ids))
366          {
367            $parent_id= $db_categories[$parent_id]['parent'];
368          }
369          if ($db_categories[$ids]['status']=='private' and !is_null($parent_id))
370          {
371            if (isset($granted_grps[$parent_id]))
372            {
373              foreach ($granted_grps[$parent_id] as $granted_grp)
374              {
375                array_push(
376                  $insert_granted_grps,
377                  array(
378                    'group_id' => $granted_grp,
379                    'cat_id' => $ids
380                  )
381                );
382              }
383            }
384            if (isset($granted_users[$parent_id]))
385            {
386              foreach ($granted_users[$parent_id] as $granted_user)
387              {
388                array_push(
389                  $insert_granted_users,
390                  array(
391                    'user_id' => $granted_user,
392                    'cat_id' => $ids
393                  )
394                );
395              }
396            }
397            foreach (get_admins() as $granted_user)
398            {
399              array_push(
400                $insert_granted_users,
401                array(
402                  'user_id' => $granted_user,
403                  'cat_id' => $ids
404                )
405              );
406            }
407          }
408        }
409        mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $insert_granted_grps);
410        $insert_granted_users=array_unique($insert_granted_users, SORT_REGULAR);
411        mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $insert_granted_users);
412      }
413      else
414      {
415        add_permission_on_category($category_ids, get_admins());
416      }
417    }
418
419    $counts['new_categories'] = count($inserts);
420  }
421
422  // to delete categories
423  $to_delete = array(); $to_delete_derivative_dirs = array();
424  foreach (array_diff(array_keys($db_fulldirs), $fs_fulldirs) as $fulldir)
425  {
426    array_push($to_delete, $db_fulldirs[$fulldir]);
427    unset($db_fulldirs[$fulldir]);
428    array_push($infos, array('path' => $fulldir,
429                             'info' => l10n('deleted')));
430    if (substr_compare($fulldir, '../', 0, 3)==0)
431    {
432      $fulldir = substr($fulldir, 3);
433    }
434    $to_delete_derivative_dirs[] = PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$fulldir;
435  }
436  if (count($to_delete) > 0)
437  {
438    if (!$simulate)
439    {
440      delete_categories($to_delete);
441      foreach($to_delete_derivative_dirs as $to_delete_dir)
442      {
443        if (is_dir($to_delete_dir))
444        {
445          clear_derivative_cache_rec($to_delete_dir, '#.+#');
446        }
447      }
448    }
449    $counts['del_categories'] = count($to_delete);
450  }
451
452  $template->append('footer_elements', '<!-- scanning dirs : '
453    . get_elapsed_time($start, get_moment())
454    . ' -->' );
455}
456// +-----------------------------------------------------------------------+
457// |                           files / elements                            |
458// +-----------------------------------------------------------------------+
459if (isset($_POST['submit']) and $_POST['sync'] == 'files'
460      and !$general_failure)
461{
462  $start_files = get_moment();
463  $start= $start_files;
464
465  $fs = $site_reader->get_elements($basedir);
466  $template->append('footer_elements', '<!-- get_elements: '
467    . get_elapsed_time($start, get_moment())
468    . ' -->' );
469
470  $cat_ids = array_diff(array_keys($db_categories), $to_delete);
471
472  $db_elements = array();
473
474  if (count($cat_ids) > 0)
475  {
476    $query = '
477SELECT id, path
478  FROM '.IMAGES_TABLE.'
479  WHERE storage_category_id IN ('
480      .wordwrap(
481        implode(', ', $cat_ids),
482        160,
483        "\n"
484        ).')';
485    $db_elements = simple_hash_from_query($query, 'id', 'path');
486  }
487
488  // next element id available
489  $next_element_id = pwg_db_nextval('id', IMAGES_TABLE);
490
491  $start = get_moment();
492
493  $inserts = array();
494  $insert_links = array();
495
496  foreach (array_diff(array_keys($fs), $db_elements) as $path)
497  {
498    $insert = array();
499    // storage category must exist
500    $dirname = dirname($path);
501    if (!isset($db_fulldirs[$dirname]))
502    {
503      continue;
504    }
505    $filename = basename($path);
506    if (!preg_match($conf['sync_chars_regex'], $filename))
507    {
508      array_push(
509        $errors,
510        array(
511          'path' => $path,
512          'type' => 'PWG-UPDATE-1'
513          )
514        );
515
516      continue;
517    }
518
519    $insert = array(
520      'id'             => $next_element_id++,
521      'file'           => $filename,
522      'name'           => get_name_from_file($filename),
523      'date_available' => CURRENT_DATE,
524      'path'           => $path,
525      'representative_ext'  => $fs[$path]['representative_ext'],
526      'storage_category_id' => $db_fulldirs[$dirname],
527      'added_by'       => $user['id'],
528      );
529
530    if ( $_POST['privacy_level']!=0 )
531    {
532      $insert['level'] = $_POST['privacy_level'];
533    }
534
535    array_push(
536      $inserts,
537      $insert
538      );
539
540    array_push(
541      $insert_links,
542      array(
543        'image_id'    => $insert['id'],
544        'category_id' => $insert['storage_category_id'],
545        )
546      );
547
548    array_push(
549      $infos,
550      array(
551        'path' => $insert['path'],
552        'info' => l10n('added')
553        )
554      );
555
556    $caddiables[] = $insert['id'];
557  }
558
559  if (count($inserts) > 0)
560  {
561    if (!$simulate)
562    {
563      // inserts all new elements
564      mass_inserts(
565        IMAGES_TABLE,
566        array_keys($inserts[0]),
567        $inserts
568        );
569
570      // inserts all links between new elements and their storage category
571      mass_inserts(
572        IMAGE_CATEGORY_TABLE,
573        array_keys($insert_links[0]),
574        $insert_links
575        );
576
577      // add new photos to caddie
578      if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1)
579      {
580        fill_caddie($caddiables);
581      }
582    }
583    $counts['new_elements'] = count($inserts);
584  }
585
586  // delete elements that are in database but not in the filesystem
587  $to_delete_elements = array();
588  foreach (array_diff($db_elements, array_keys($fs)) as $path)
589  {
590    array_push($to_delete_elements, array_search($path, $db_elements));
591    array_push($infos, array('path' => $path,
592                             'info' => l10n('deleted')));
593  }
594  if (count($to_delete_elements) > 0)
595  {
596    if (!$simulate)
597    {
598      delete_elements($to_delete_elements);
599    }
600    $counts['del_elements'] = count($to_delete_elements);
601  }
602
603  $template->append('footer_elements', '<!-- scanning files : '
604    . get_elapsed_time($start_files, get_moment())
605    . ' -->' );
606}
607
608// +-----------------------------------------------------------------------+
609// |                          synchronize files                            |
610// +-----------------------------------------------------------------------+
611if (isset($_POST['submit'])
612    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')
613    and !$general_failure )
614{
615  if (!$simulate)
616  {
617    $start = get_moment();
618    update_category('all');
619    $template->append('footer_elements', '<!-- update_category(all) : '
620      . get_elapsed_time($start,get_moment())
621      . ' -->' );
622    $start = get_moment();
623    update_global_rank();
624    $template->append('footer_elements', '<!-- ordering categories : '
625      . get_elapsed_time($start, get_moment())
626      . ' -->');
627  }
628
629  if ($_POST['sync'] == 'files')
630  {
631    $start = get_moment();
632    $opts['category_id'] = '';
633    $opts['recursive'] = true;
634    if (isset($_POST['cat']))
635    {
636      $opts['category_id'] = $_POST['cat'];
637      if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
638      {
639        $opts['recursive'] = false;
640      }
641    }
642    $files = get_filelist($opts['category_id'], $site_id,
643                          $opts['recursive'],
644                          false);
645    $template->append('footer_elements', '<!-- get_filelist : '
646      . get_elapsed_time($start, get_moment())
647      . ' -->');
648    $start = get_moment();
649
650    $datas = array();
651    foreach ( $files as $id=>$file )
652    {
653      $file = $file['path'];
654      $data = $site_reader->get_element_update_attributes($file);
655      if ( !is_array($data) )
656      {
657        continue;
658      }
659
660      $data['id']=$id;
661      array_push($datas, $data);
662    } // end foreach file
663
664    $counts['upd_elements'] = count($datas);
665    if (!$simulate and count($datas)>0 )
666    {
667      mass_updates(
668        IMAGES_TABLE,
669        // fields
670        array(
671          'primary' => array('id'),
672          'update'  => $site_reader->get_update_attributes(),
673          ),
674        $datas
675        );
676    }
677    $template->append('footer_elements', '<!-- update files : '
678      . get_elapsed_time($start,get_moment())
679      . ' -->');
680  }// end if sync files
681}
682
683// +-----------------------------------------------------------------------+
684// |                          synchronize files                            |
685// +-----------------------------------------------------------------------+
686if (isset($_POST['submit'])
687    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files'))
688{
689  $template->assign(
690    'update_result',
691    array(
692      'NB_NEW_CATEGORIES'=>$counts['new_categories'],
693      'NB_DEL_CATEGORIES'=>$counts['del_categories'],
694      'NB_NEW_ELEMENTS'=>$counts['new_elements'],
695      'NB_DEL_ELEMENTS'=>$counts['del_elements'],
696      'NB_UPD_ELEMENTS'=>$counts['upd_elements'],
697      'NB_ERRORS'=>count($errors),
698      ));
699}
700
701// +-----------------------------------------------------------------------+
702// |                          synchronize metadata                         |
703// +-----------------------------------------------------------------------+
704if (isset($_POST['submit']) and isset($_POST['sync_meta'])
705         and !$general_failure)
706{
707  // sync only never synchronized files ?
708  $opts['only_new'] = isset($_POST['meta_all']) ? false : true;
709  $opts['category_id'] = '';
710  $opts['recursive'] = true;
711
712  if (isset($_POST['cat']))
713  {
714    $opts['category_id'] = $_POST['cat'];
715    // recursive ?
716    if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
717    {
718      $opts['recursive'] = false;
719    }
720  }
721  $start = get_moment();
722  $files = get_filelist($opts['category_id'], $site_id,
723                        $opts['recursive'],
724                        $opts['only_new']);
725
726  $template->append('footer_elements', '<!-- get_filelist : '
727    . get_elapsed_time($start, get_moment())
728    . ' -->');
729
730  $start = get_moment();
731  $datas = array();
732  $tags_of = array();
733
734  foreach ( $files as $id => $element_infos )
735  {
736    $data = $site_reader->get_element_metadata($element_infos);
737
738    if ( is_array($data) )
739    {
740      $data['date_metadata_update'] = CURRENT_DATE;
741      $data['id']=$id;
742      array_push($datas, $data);
743
744      foreach (array('keywords', 'tags') as $key)
745      {
746        if (isset($data[$key]))
747        {
748          if (!isset($tags_of[$id]))
749          {
750            $tags_of[$id] = array();
751          }
752
753          foreach (explode(',', $data[$key]) as $tag_name)
754          {
755            array_push(
756              $tags_of[$id],
757              tag_id_from_tag_name($tag_name)
758              );
759          }
760        }
761      }
762    }
763    else
764    {
765      array_push($errors, array('path' => $element_infos['path'], 'type' => 'PWG-ERROR-NO-FS'));
766    }
767  }
768
769  if (!$simulate)
770  {
771    if (count($datas) > 0)
772    {
773      mass_updates(
774        IMAGES_TABLE,
775        // fields
776        array(
777          'primary' => array('id'),
778          'update'  => array_unique(
779            array_merge(
780              array_diff(
781                $site_reader->get_metadata_attributes(),
782                // keywords and tags fields are managed separately
783                array('keywords', 'tags')
784                ),
785              array('date_metadata_update'))
786            )
787          ),
788        $datas,
789        isset($_POST['meta_empty_overrides']) ? 0 : MASS_UPDATES_SKIP_EMPTY
790        );
791    }
792    set_tags_of($tags_of);
793  }
794
795  $template->append('footer_elements', '<!-- metadata update : '
796    . get_elapsed_time($start, get_moment())
797    . ' -->');
798
799  $template->assign(
800    'metadata_result',
801    array(
802      'NB_ELEMENTS_DONE' => count($datas),
803      'NB_ELEMENTS_CANDIDATES' => count($files),
804      'NB_ERRORS' => count($errors),
805      ));
806}
807
808// +-----------------------------------------------------------------------+
809// |                        template initialization                        |
810// +-----------------------------------------------------------------------+
811$template->set_filenames(array('update'=>'site_update.tpl'));
812$result_title = '';
813if (isset($simulate) and $simulate)
814{
815  $result_title.= '['.l10n('Simulation').'] ';
816}
817
818// used_metadata string is displayed to inform admin which metadata will be
819// used from files for synchronization
820$used_metadata = implode( ', ', $site_reader->get_metadata_attributes());
821if ($site_is_remote and !isset($_POST['submit']) )
822{
823  $used_metadata.= ' + ...';
824}
825
826$template->assign(
827  array(
828    'SITE_URL'=>$site_url,
829    'U_SITE_MANAGER'=> get_root_url().'admin.php?page=site_manager',
830    'L_RESULT_UPDATE'=>$result_title.l10n('Search for new images in the directories'),
831    'L_RESULT_METADATA'=>$result_title.l10n('Metadata synchronization results'),
832    'METADATA_LIST' => $used_metadata,
833    'U_HELP' => get_root_url().'admin/popuphelp.php?page=synchronize',
834    ));
835
836// +-----------------------------------------------------------------------+
837// |                        introduction : choices                         |
838// +-----------------------------------------------------------------------+
839if (isset($_POST['submit']))
840{
841  $tpl_introduction = array(
842      'sync'  => $_POST['sync'],
843      'sync_meta'  => isset($_POST['sync_meta']) ? true : false,
844      'display_info' => isset($_POST['display_info']) and $_POST['display_info']==1,
845      'add_to_caddie' => isset($_POST['add_to_caddie']) and $_POST['add_to_caddie']==1,
846      'subcats_included' => isset($_POST['subcats-included']) and $_POST['subcats-included']==1,
847      'privacy_level_selected' => (int)@$_POST['privacy_level'],
848      'meta_all'  => isset($_POST['meta_all']) ? true : false,
849      'meta_empty_overrides'  => isset($_POST['meta_empty_overrides']) ? true : false,
850    );
851
852  if (isset($_POST['cat']) and is_numeric($_POST['cat']))
853  {
854    $cat_selected = array($_POST['cat']);
855  }
856  else
857  {
858    $cat_selected = array();
859  }
860}
861else
862{
863  $tpl_introduction = array(
864      'sync'  => 'dirs',
865      'sync_meta'  => true,
866      'display_info' => false,
867      'add_to_caddie' => false,
868      'subcats_included' => true,
869      'privacy_level_selected' => 0,
870      'meta_all'  => false,
871      'meta_empty_overrides'  => false,
872    );
873
874  $cat_selected = array();
875
876  if (isset($_GET['cat_id']))
877  {
878    check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
879
880    $cat_selected = array($_GET['cat_id']);
881    $tpl_introduction['sync'] = 'files';
882  }
883}
884
885$tpl_introduction['privacy_level_options'] = get_privacy_level_options();
886
887$template->assign('introduction', $tpl_introduction);
888
889$query = '
890SELECT id,name,uppercats,global_rank
891  FROM '.CATEGORIES_TABLE.'
892  WHERE site_id = '.$site_id;
893display_select_cat_wrapper($query,
894                           $cat_selected,
895                           'category_options',
896                           false);
897
898
899if (count($errors) > 0)
900{
901  foreach ($errors as $error)
902  {
903    $template->append(
904      'sync_errors',
905      array(
906        'ELEMENT' => $error['path'],
907        'LABEL' => $error['type'].' ('.$error_labels[$error['type']][0].')'
908        ));
909  }
910
911  foreach ($error_labels as $error_type=>$error_description)
912  {
913    $template->append(
914      'sync_error_captions',
915      array(
916        'TYPE' => $error_type,
917        'LABEL' => $error_description[1]
918        ));
919  }
920}
921
922if (count($infos) > 0
923    and isset($_POST['display_info'])
924    and $_POST['display_info'] == 1)
925{
926  foreach ($infos as $info)
927  {
928    $template->append(
929      'sync_infos',
930      array(
931        'ELEMENT' => $info['path'],
932        'LABEL' => $info['info']
933        ));
934  }
935}
936
937// +-----------------------------------------------------------------------+
938// |                          sending html code                            |
939// +-----------------------------------------------------------------------+
940$template->assign_var_from_handle('ADMIN_CONTENT', 'update');
941?>
Note: See TracBrowser for help on using the repository browser.