source: trunk/admin/site_update.php @ 1122

Last change on this file since 1122 was 1122, checked in by plg, 18 years ago

bug fixed: I had forgotten to re-add storage_category_id in the list of
fields to insert in #images. To avoid future mistakes, I extract
automatically all keys of the first array to insert.

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