source: trunk/admin/site_update.php @ 1204

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

merge r1203 from branch-1_6 into trunk

bug 335: tn_ext, has_high and representative_ext are updated during file
synchronization and not metadata synchronization

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.0 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-18 23:46:53 +0000 (Tue, 18 Apr 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1204 $
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 (!isset($conf['flip_picture_ext']))
107  {
108    $conf['flip_picture_ext'] = array_flip($conf['picture_ext']);
109  }
110  if ($site_reader->open())
111  {
112    $general_failure = false;
113  }
114  // shall we simulate only
115  if (isset($_POST['simulate']) and $_POST['simulate'] == 1)
116  {
117    $simulate = true;
118  }
119  else
120  {
121    $simulate = false;
122  }
123}
124
125// +-----------------------------------------------------------------------+
126// |                      directories / categories                         |
127// +-----------------------------------------------------------------------+
128if (isset($_POST['submit'])
129    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')
130    and !$general_failure)
131{
132  $counts['new_categories'] = 0;
133  $counts['del_categories'] = 0;
134  $counts['del_elements'] = 0;
135  $counts['new_elements'] = 0;
136  $counts['upd_elements'] = 0;
137
138  $start = get_moment();
139  // which categories to update ?
140  $cat_ids = array();
141
142  $query = '
143SELECT id, uppercats, global_rank, status, visible
144  FROM '.CATEGORIES_TABLE.'
145  WHERE dir IS NOT NULL
146    AND site_id = '.$site_id;
147  if (isset($_POST['cat']) and is_numeric($_POST['cat']))
148  {
149    if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1)
150    {
151      $query.= '
152    AND uppercats REGEXP \'(^|,)'.$_POST['cat'].'(,|$)\'
153';
154    }
155    else
156    {
157      $query.= '
158    AND id = '.$_POST['cat'].'
159';
160    }
161  }
162  $query.= '
163;';
164  $result = pwg_query($query);
165
166  $db_categories = array();
167  while ($row = mysql_fetch_array($result))
168  {
169    $db_categories[$row['id']] = $row;
170  }
171
172  // get categort full directories in an array for comparison with file
173  // system directory tree
174  $db_fulldirs = get_fulldirs(array_keys($db_categories));
175
176  // what is the base directory to search file system sub-directories ?
177  if (isset($_POST['cat']) and is_numeric($_POST['cat']))
178  {
179    $basedir = $db_fulldirs[$_POST['cat']];
180  }
181  else
182  {
183    $basedir = preg_replace('#/*$#', '', $site_url);
184  }
185
186  // we need to have fulldirs as keys to make efficient comparison
187  $db_fulldirs = array_flip($db_fulldirs);
188
189  // finding next rank for each id_uppercat. By default, each category id
190  // has 1 for next rank on its sub-categories to create
191  $next_rank['NULL'] = 1;
192
193  $query = '
194SELECT id
195  FROM '.CATEGORIES_TABLE.'
196;';
197  $result = pwg_query($query);
198  while ($row = mysql_fetch_array($result))
199  {
200    $next_rank[$row['id']] = 1;
201  }
202
203  // let's see if some categories already have some sub-categories...
204  $query = '
205SELECT id_uppercat, MAX(rank)+1 AS next_rank
206  FROM '.CATEGORIES_TABLE.'
207  GROUP BY id_uppercat
208;';
209  $result = pwg_query($query);
210  while ($row = mysql_fetch_array($result))
211  {
212    // for the id_uppercat NULL, we write 'NULL' and not the empty string
213    if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '')
214    {
215      $row['id_uppercat'] = 'NULL';
216    }
217    $next_rank[$row['id_uppercat']] = $row['next_rank'];
218  }
219
220  // next category id available
221  $query = '
222SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id
223  FROM '.CATEGORIES_TABLE.'
224;';
225  list($next_id) = mysql_fetch_array(pwg_query($query));
226
227  // retrieve sub-directories fulldirs from the site reader
228  $fs_fulldirs = $site_reader->get_full_directories($basedir);
229  //print_r( $fs_fulldirs ); echo "<br>";
230
231  // get_full_directories doesn't include the base directory, so if it's a
232  // category directory, we need to include it in our array
233  if (isset($_POST['cat']))
234  {
235    array_push($fs_fulldirs, $basedir);
236  }
237
238  $inserts = array();
239  // new categories are the directories not present yet in the database
240  foreach (array_diff($fs_fulldirs, array_keys($db_fulldirs)) as $fulldir)
241  {
242    $dir = basename($fulldir);
243    if (preg_match('/^[a-zA-Z0-9-_.]+$/', $dir))
244    {
245      $insert = array(
246        'id'          => $next_id++,
247        'dir'         => $dir,
248        'name'        => str_replace('_', ' ', $dir),
249        'site_id'     => $site_id,
250        'commentable' => $conf['newcat_default_commentable'],
251        'uploadable'  => $site_is_remote
252          ? false
253          : $conf['newcat_default_uploadable'],
254        'status'      => $conf{'newcat_default_status'},
255        'visible'     => $conf{'newcat_default_visible'},
256        );
257
258      if (isset($db_fulldirs[dirname($fulldir)]))
259      {
260        $parent = $db_fulldirs[dirname($fulldir)];
261
262        $insert{'id_uppercat'} = $parent;
263        $insert{'uppercats'} =
264          $db_categories[$parent]['uppercats'].','.$insert{'id'};
265        $insert{'rank'} = $next_rank[$parent]++;
266        $insert{'global_rank'} =
267          $db_categories[$parent]['global_rank'].'.'.$insert{'rank'};
268        if ('private' == $db_categories[$parent]['status'])
269        {
270          $insert{'status'} = 'private';
271        }
272        if ('false' == $db_categories[$parent]['visible'])
273        {
274          $insert{'visible'} = 'false';
275        }
276      }
277      else
278      {
279        $insert{'uppercats'} = $insert{'id'};
280        $insert{'rank'} = $next_rank['NULL']++;
281        $insert{'global_rank'} = $insert{'rank'};
282      }
283
284      array_push($inserts, $insert);
285      array_push(
286        $infos,
287        array(
288          'path' => $fulldir,
289          'info' => l10n('update_research_added')
290          )
291        );
292
293      // add the new category to $db_categories and $db_fulldirs array
294      $db_categories[$insert{'id'}] =
295        array(
296          'id' => $insert{'id'},
297          'status' => $insert{'status'},
298          'visible' => $insert{'visible'},
299          'uppercats' => $insert{'uppercats'},
300          'global_rank' => $insert{'global_rank'}
301          );
302      $db_fulldirs[$fulldir] = $insert{'id'};
303      $next_rank[$insert{'id'}] = 1;
304    }
305    else
306    {
307      array_push(
308        $errors,
309        array(
310          'path' => $fulldir,
311          'type' => 'PWG-UPDATE-1'
312          )
313        );
314    }
315  }
316
317  if (count($inserts) > 0)
318  {
319    if (!$simulate)
320    {
321      $dbfields = array(
322        'id','dir','name','site_id','id_uppercat','uppercats','commentable',
323        'uploadable','visible','status','rank','global_rank'
324        );
325      mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts);
326    }
327
328    $counts['new_categories'] = count($inserts);
329  }
330
331  // to delete categories
332  $to_delete = array();
333  foreach (array_diff(array_keys($db_fulldirs), $fs_fulldirs) as $fulldir)
334  {
335    array_push($to_delete, $db_fulldirs[$fulldir]);
336    unset($db_fulldirs[$fulldir]);
337    array_push($infos, array('path' => $fulldir,
338                             'info' => l10n('update_research_deleted')));
339  }
340  if (count($to_delete) > 0)
341  {
342    if (!$simulate)
343    {
344      delete_categories($to_delete);
345    }
346    $counts['del_categories'] = count($to_delete);
347  }
348
349  echo '<!-- scanning dirs : ';
350  echo get_elapsed_time($start, get_moment());
351  echo ' -->'."\n";
352}
353// +-----------------------------------------------------------------------+
354// |                           files / elements                            |
355// +-----------------------------------------------------------------------+
356if (isset($_POST['submit']) and $_POST['sync'] == 'files'
357      and !$general_failure)
358{
359  $start_files = get_moment();
360  $start= $start_files;
361
362  $fs = $site_reader->get_elements($basedir);
363  //print_r($fs); echo "<br>";
364  echo '<!-- get_elements: '.get_elapsed_time($start, get_moment())." -->\n";
365
366  $cat_ids = array_diff(array_keys($db_categories), $to_delete);
367
368  $db_elements = array();
369  $db_unvalidated = array();
370
371  if (count($cat_ids) > 0)
372  {
373    $query = '
374SELECT id, path
375  FROM '.IMAGES_TABLE.'
376  WHERE storage_category_id IN ('
377      .wordwrap(
378        implode(', ', $cat_ids),
379        80,
380        "\n"
381        ).')
382;';
383    $result = pwg_query($query);
384    while ($row = mysql_fetch_array($result))
385    {
386      $db_elements[$row['id']] = $row['path'];
387    }
388
389    // searching the unvalidated waiting elements (they must not be taken into
390    // account)
391    $query = '
392SELECT file,storage_category_id
393  FROM '.WAITING_TABLE.'
394  WHERE storage_category_id IN (
395'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
396    AND validated = \'false\'
397;';
398    $result = pwg_query($query);
399    while ($row = mysql_fetch_array($result))
400    {
401      array_push(
402        $db_unvalidated,
403        array_search(
404          $row['storage_category_id'],
405          $db_fulldirs)
406        .'/'.$row['file']
407        );
408    }
409  }
410
411  // next element id available
412  $query = '
413SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
414  FROM '.IMAGES_TABLE.'
415;';
416  list($next_element_id) = mysql_fetch_array(pwg_query($query));
417
418  $start = get_moment();
419
420  $inserts = array();
421  $insert_links = array();
422
423  foreach (array_diff(array_keys($fs), $db_elements, $db_unvalidated) as $path)
424  {
425    $insert = array();
426    // storage category must exist
427    $dirname = dirname($path);
428    if (!isset($db_fulldirs[$dirname]))
429    {
430      continue;
431    }
432    $filename = basename($path);
433    if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename))
434    {
435      array_push(
436        $errors,
437        array(
438          'path' => $path,
439          'type' => 'PWG-UPDATE-1'
440          )
441        );
442
443      continue;
444    }
445
446    // 2 cases : the element is a picture or not. Indeed, for a picture
447    // thumbnail is mandatory and for non picture element, thumbnail and
448    // representative are optionnal
449    if ( isset( $conf['flip_picture_ext'][get_extension($filename)] ) )
450    {
451      // if we found a thumnbnail corresponding to our picture...
452      if (isset($fs[$path]['tn_ext']))
453      {
454        $insert = array(
455          'id'             => $next_element_id++,
456          'file'           => $filename,
457          'date_available' => CURRENT_DATE,
458          'tn_ext'         => $fs[$path]['tn_ext'],
459          'path'           => $path,
460          'storage_category_id' => $db_fulldirs[$dirname],
461          );
462
463        array_push(
464          $inserts,
465          $insert
466          );
467
468        array_push(
469          $insert_links,
470          array(
471            'image_id'    => $insert{'id'},
472            'category_id' => $insert['storage_category_id'],
473            )
474          );
475        array_push(
476          $infos,
477          array(
478            'path' => $insert{'path'},
479            'info' => l10n('update_research_added')
480            )
481          );
482      }
483      else
484      {
485        array_push(
486          $errors,
487          array(
488            'path' => $path,
489            'type' => 'PWG-UPDATE-2'
490            )
491          );
492      }
493    }
494    else
495    {
496      $insert = array(
497        'id'             => $next_element_id++,
498        'file'           => $filename,
499        'date_available' => CURRENT_DATE,
500        'path'           => $path,
501        'tn_ext'         => isset($fs[$path]['tn_ext'])
502          ? $fs[$path]['tn_ext']
503          : null,
504        'storage_category_id' => $db_fulldirs[$dirname],
505        );
506
507      array_push(
508        $inserts,
509        $insert
510        );
511
512      array_push(
513        $insert_links,
514        array(
515          'image_id'    => $insert{'id'},
516          'category_id' => $insert['storage_category_id'],
517          )
518        );
519
520      array_push(
521        $infos,
522        array(
523          'path' => $insert{'path'},
524          'info' => l10n('update_research_added')
525          )
526        );
527    }
528  }
529
530  if (count($inserts) > 0)
531  {
532    if (!$simulate)
533    {
534      // inserts all new elements
535      mass_inserts(
536        IMAGES_TABLE,
537        array_keys($inserts[0]),
538        $inserts
539        );
540
541      // inserts all links between new elements and their storage category
542      mass_inserts(
543        IMAGE_CATEGORY_TABLE,
544        array_keys($insert_links[0]),
545        $insert_links
546        );
547    }
548    $counts['new_elements'] = count($inserts);
549  }
550
551  // delete elements that are in database but not in the filesystem
552  $to_delete_elements = array();
553  foreach (array_diff($db_elements, array_keys($fs)) as $path)
554  {
555    array_push($to_delete_elements, array_search($path, $db_elements));
556    array_push($infos, array('path' => $path,
557                             'info' => l10n('update_research_deleted')));
558  }
559  if (count($to_delete_elements) > 0)
560  {
561    if (!$simulate)
562    {
563      delete_elements($to_delete_elements);
564    }
565    $counts['del_elements'] = count($to_delete_elements);
566  }
567
568  echo '<!-- scanning files : ';
569  echo get_elapsed_time($start_files, get_moment());
570  echo ' -->'."\n";
571
572  // retrieving informations given by uploaders
573  if (!$simulate and count($cat_ids) > 0)
574  {
575    $query = '
576SELECT id,file,storage_category_id,infos
577  FROM '.WAITING_TABLE.'
578  WHERE storage_category_id IN (
579'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
580    AND validated = \'true\'
581;';
582    $result = pwg_query($query);
583
584    $datas = array();
585    $fields =
586      array(
587        'primary' => array('id'),
588        'update'  => array('date_creation', 'author', 'name', 'comment')
589        );
590
591    $waiting_to_delete = array();
592
593    while ($row = mysql_fetch_array($result))
594    {
595      $data = array();
596
597      $query = '
598SELECT id
599  FROM '.IMAGES_TABLE.'
600  WHERE storage_category_id = '.$row['storage_category_id'].'
601    AND file = \''.$row['file'].'\'
602;';
603      list($data['id']) = mysql_fetch_array(pwg_query($query));
604
605      foreach ($fields['update'] as $field)
606      {
607        $data[$field] = addslashes( getAttribute($row['infos'], $field) );
608      }
609
610      array_push($datas, $data);
611      array_push($waiting_to_delete, $row['id']);
612    }
613
614    if (count($datas) > 0)
615    {
616      mass_updates(IMAGES_TABLE, $fields, $datas);
617
618      // delete now useless waiting elements
619      $query = '
620DELETE
621  FROM '.WAITING_TABLE.'
622  WHERE id IN ('.implode(',', $waiting_to_delete).')
623;';
624      pwg_query($query);
625    }
626  }
627}
628
629// +-----------------------------------------------------------------------+
630// |                          synchronize files                            |
631// +-----------------------------------------------------------------------+
632if (isset($_POST['submit'])
633    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')
634    and !$general_failure )
635{
636  if (!$simulate)
637  {
638    $start = get_moment();
639    update_category('all');
640    echo '<!-- update_category(all) : ';
641    echo get_elapsed_time($start,get_moment());
642    echo ' -->'."\n";
643    $start = get_moment();
644    ordering();
645    update_global_rank();
646    echo '<!-- ordering categories : ';
647    echo get_elapsed_time($start, get_moment());
648    echo ' -->'."\n";
649  }
650
651  if ($_POST['sync'] == 'files')
652  {
653    $start = get_moment();
654    $opts['category_id'] = '';
655    $opts['recursive'] = true;
656    if (isset($_POST['cat']))
657    {
658      $opts['category_id'] = $_POST['cat'];
659      if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
660      {
661        $opts['recursive'] = false;
662      }
663    }
664    $files = get_filelist($opts['category_id'], $site_id,
665                          $opts['recursive'],
666                          false);
667    echo '<!-- get_filelist : ';
668    echo get_elapsed_time($start, get_moment());
669    echo ' -->'."\n";
670    $start = get_moment();
671
672    $datas = array();
673    foreach ( $files as $id=>$file )
674    {
675      $data = $site_reader->get_element_update_attributes($file);
676      if ( !is_array($data) )
677      {
678        continue;
679      }
680      $extension = get_extension($file);
681      if ( isset($conf['flip_picture_ext'][$extension]) )
682      {
683        if ( !isset($data['tn_ext']) )
684        {
685          array_push(
686            $errors,
687            array(
688              'path' => $file,
689              'type' => 'PWG-UPDATE-2'
690              )
691            );
692          continue;
693        }
694      }
695
696      $data['id']=$id;
697      array_push($datas, $data);
698    } // end foreach file
699
700    $counts['upd_elements'] = count($datas);
701    if (!$simulate and count($datas)>0 )
702    {
703      mass_updates(
704        IMAGES_TABLE,
705        // fields
706        array(
707          'primary' => array('id'),
708          'update'  => $site_reader->get_update_attributes(),
709          ),
710        $datas
711        );
712    }
713    echo '<!-- update files : ';
714    echo get_elapsed_time($start,get_moment());
715    echo ' -->'."\n";
716  }// end if sync files
717}
718
719// +-----------------------------------------------------------------------+
720// |                          synchronize files                            |
721// +-----------------------------------------------------------------------+
722if (isset($_POST['submit'])
723    and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files'))
724{
725  $template->assign_block_vars(
726    'update_result',
727    array(
728      'NB_NEW_CATEGORIES'=>$counts['new_categories'],
729      'NB_DEL_CATEGORIES'=>$counts['del_categories'],
730      'NB_NEW_ELEMENTS'=>$counts['new_elements'],
731      'NB_DEL_ELEMENTS'=>$counts['del_elements'],
732      'NB_UPD_ELEMENTS'=>$counts['upd_elements'],
733      'NB_ERRORS'=>count($errors),
734      ));
735}
736
737// +-----------------------------------------------------------------------+
738// |                          synchronize metadata                         |
739// +-----------------------------------------------------------------------+
740if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync'])
741         and !$general_failure)
742{
743  // sync only never synchronized files ?
744  if ($_POST['sync'] == 'metadata_new')
745  {
746    $opts['only_new'] = true;
747  }
748  else
749  {
750    $opts['only_new'] = false;
751  }
752  $opts['category_id'] = '';
753  $opts['recursive'] = true;
754
755  if (isset($_POST['cat']))
756  {
757    $opts['category_id'] = $_POST['cat'];
758    // recursive ?
759    if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
760    {
761      $opts['recursive'] = false;
762    }
763  }
764  $start = get_moment();
765  $files = get_filelist($opts['category_id'], $site_id,
766                        $opts['recursive'],
767                        $opts['only_new']);
768
769  echo '<!-- get_filelist : ';
770  echo get_elapsed_time($start, get_moment());
771  echo ' -->'."\n";
772
773  $start = get_moment();
774  $datas = array();
775  $tags_of = array();
776  foreach ( $files as $id=>$file )
777  {
778    $data = $site_reader->get_element_metadata($file);
779    if ( is_array($data) )
780    {
781      $data['date_metadata_update'] = CURRENT_DATE;
782      $data['id']=$id;
783      array_push($datas, $data);
784
785      foreach (array('keywords', 'tags') as $key)
786      {
787        if (isset($data[$key]))
788        {
789          if (!isset($tags_of[$id]))
790          {
791            $tags_of[$id] = array();
792          }
793
794          foreach (explode(',', $data[$key]) as $tag_name)
795          {
796            array_push(
797              $tags_of[$id],
798              tag_id_from_tag_name($tag_name)
799              );
800          }
801        }
802      }
803    }
804    else
805    {
806      array_push($errors, array('path' => $file, 'type' => 'PWG-ERROR-NO-FS'));
807    }
808  }
809
810  if (!$simulate)
811  {
812    if (count($datas) > 0)
813    {
814      mass_updates(
815        IMAGES_TABLE,
816        // fields
817        array(
818          'primary' => array('id'),
819          'update'  => array_unique(
820            array_merge(
821              array_diff(
822                $site_reader->get_metadata_attributes(),
823                // keywords and tags fields are managed separately
824                array('keywords', 'tags')
825                ),
826              array('date_metadata_update'))
827            )
828          ),
829        $datas
830        );
831    }
832    set_tags_of($tags_of);
833  }
834
835  echo '<!-- metadata update : ';
836  echo get_elapsed_time($start, get_moment());
837  echo ' -->'."\n";
838
839  $template->assign_block_vars(
840    'metadata_result',
841    array(
842      'NB_ELEMENTS_DONE' => count($datas),
843      'NB_ELEMENTS_CANDIDATES' => count($files),
844      'NB_ERRORS' => count($errors),
845      ));
846}
847
848// +-----------------------------------------------------------------------+
849// |                        template initialization                        |
850// +-----------------------------------------------------------------------+
851$template->set_filenames(array('update'=>'admin/site_update.tpl'));
852$result_title = '';
853if (isset($simulate) and $simulate)
854{
855  $result_title.= l10n('update_simulation_title').' ';
856}
857
858// used_metadata string is displayed to inform admin which metadata will be
859// used from files for synchronization
860$used_metadata = implode( ', ', $site_reader->get_metadata_attributes());
861if ($site_is_remote and !isset($_POST['submit']) )
862{
863  $used_metadata.= ' + ...';
864}
865
866$template->assign_vars(
867  array(
868    'SITE_URL'=>$site_url,
869    'U_SITE_MANAGER'=> PHPWG_ROOT_PATH.'admin.php?page=site_manager',
870    'L_RESULT_UPDATE'=>$result_title.l10n('update_part_research'),
871    'L_RESULT_METADATA'=>$result_title.l10n('update_result_metadata'),
872    'METADATA_LIST' => $used_metadata
873    ));
874
875$template->assign_vars(
876  array(
877    'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=synchronize'
878    )
879  );
880// +-----------------------------------------------------------------------+
881// |                        introduction : choices                         |
882// +-----------------------------------------------------------------------+
883if (!isset($_POST['submit']) or (isset($simulate) and $simulate))
884{
885  $template->assign_block_vars('introduction', array());
886
887  if (isset($simulate) and $simulate)
888  {
889    switch ($_POST['sync'])
890    {
891      case 'dirs' :
892      {
893        $template->assign_vars(
894          array('SYNC_DIRS_CHECKED'=>'checked="checked"'));
895        break;
896      }
897      case 'files' :
898      {
899        $template->assign_vars(
900          array('SYNC_ALL_CHECKED'=>'checked="checked"'));
901        break;
902      }
903      case 'metadata_new' :
904      {
905        $template->assign_vars(
906          array('SYNC_META_NEW_CHECKED'=>'checked="checked"'));
907        break;
908      }
909      case 'metadata_all' :
910      {
911        $template->assign_vars(
912          array('SYNC_META_ALL_CHECKED'=>'checked="checked"'));
913        break;
914      }
915    }
916
917    if (isset($_POST['display_info']) and $_POST['display_info'] == 1)
918    {
919      $template->assign_vars(
920        array('DISPLAY_INFO_CHECKED'=>'checked="checked"'));
921    }
922
923    if (isset($_POST['subcats-included']) and $_POST['subcats-included'] == 1)
924    {
925      $template->assign_vars(
926        array('SUBCATS_INCLUDED_CHECKED'=>'checked="checked"'));
927    }
928
929    if (isset($_POST['cat']) and is_numeric($_POST['cat']))
930    {
931      $cat_selected = array($_POST['cat']);
932    }
933    else
934    {
935      $cat_selected = array();
936    }
937  }
938  else
939  {
940    $template->assign_vars(
941      array('SYNC_DIRS_CHECKED' => 'checked="checked"',
942            'SUBCATS_INCLUDED_CHECKED'=>'checked="checked"'));
943
944    $cat_selected = array();
945  }
946
947  $query = '
948SELECT id,name,uppercats,global_rank
949  FROM '.CATEGORIES_TABLE.'
950  WHERE site_id = '.$site_id.'
951;';
952  display_select_cat_wrapper($query,
953                             $cat_selected,
954                             'introduction.category_option',
955                             false);
956}
957
958if (count($errors) > 0)
959{
960  $template->assign_block_vars('sync_errors', array());
961  foreach ($errors as $error)
962  {
963    $template->assign_block_vars(
964      'sync_errors.error',
965      array(
966        'ELEMENT' => $error['path'],
967        'LABEL' => $error['type'].' ('.$error_labels[$error['type']][0].')'
968        ));
969  }
970
971  foreach ($error_labels as $error_type=>$error_description)
972  {
973    $template->assign_block_vars(
974      'sync_errors.error_caption',
975      array(
976        'TYPE' => $error_type,
977        'LABEL' => $error_description[1]
978        ));
979  }
980
981}
982if (count($infos) > 0
983    and isset($_POST['display_info'])
984    and $_POST['display_info'] == 1)
985{
986  $template->assign_block_vars('sync_infos', array());
987  foreach ($infos as $info)
988  {
989    $template->assign_block_vars(
990      'sync_infos.info',
991      array(
992        'ELEMENT' => $info['path'],
993        'LABEL' => $info['info']
994        ));
995  }
996}
997
998// +-----------------------------------------------------------------------+
999// |                          sending html code                            |
1000// +-----------------------------------------------------------------------+
1001$template->assign_var_from_handle('ADMIN_CONTENT', 'update');
1002?>
Note: See TracBrowser for help on using the repository browser.