source: trunk/admin/site_update.php @ 1058

Last change on this file since 1058 was 1058, checked in by rvelices, 18 years ago

remake of Remote sites and synchronize: final integration and old code cleanup

fix: xml getAttribute always decodes html entities and added encodeAttribute
function

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