aboutsummaryrefslogtreecommitdiffstats
path: root/admin/remote_site.php
blob: fb778084fbe81586b1e4475367036d7a2aa92f43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery                           |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch        : BSF (Best So Far)
// | file          : $RCSfile$
// | last update   : $Date$
// | last modifier : $Author$
// | revision      : $Revision$
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify  |
// | it under the terms of the GNU General Public License as published by  |
// | the Free Software Foundation                                          |
// |                                                                       |
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+

if (!defined('PHPWG_ROOT_PATH'))
{
  die ("Hacking attempt!");
}
include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');

list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
define('CURRENT_DATE', $dbnow);
// +-----------------------------------------------------------------------+
// |                               functions                               |
// +-----------------------------------------------------------------------+

/**
 * requests the given $url (a remote create_listing_file.php) and fills a
 * list of lines corresponding to request output
 *
 * @param string $url
 * @return void
 */
function remote_output($url)
{
  global $template, $page, $lang;
  
  if($lines = @file($url))
  {
    $template->assign_block_vars('remote_output', array());
    // cleaning lines from HTML tags
    foreach ($lines as $line)
    {
      $line = trim(strip_tags($line));
      if (preg_match('/^PWG-([A-Z]+)-/', $line, $matches))
      {
        $template->assign_block_vars(
          'remote_output.remote_line',
          array(
            'CLASS' => 'remote'.ucfirst(strtolower($matches[1])),
            'CONTENT' => $line
           )
         );
      }
    }
  }
  else
  {
    array_push($page['errors'], $lang['remote_site_file_not_found']);
  }
}

/**
 * returns an array where are linked the sub-categories id and there
 * directories corresponding to the given uppercat id
 *
 * @param int site_id
 * @param mixed id_uppercat
 * @return array
 */
function database_subdirs($site_id, $id_uppercat)
{
  $database_dirs = array();
  
  $query = '
SELECT id,dir
  FROM '.CATEGORIES_TABLE.'
  WHERE site_id = '.$site_id;
  if (!is_numeric($id_uppercat))
  {
    $query.= '
    AND id_uppercat IS NULL';
  }
  else
  {
    $query.= '
    AND id_uppercat = '.$id_uppercat;
  }
  // virtual categories not taken
  $query.= '
    AND dir IS NOT NULL
;';
  $result = pwg_query($query);
  while ($row = mysql_fetch_array($result))
  {
    $database_dirs[$row['id']] = $row['dir'];
  }

  return $database_dirs;
}

/**
 * read $listing_file and update a remote site according to its id
 *
 * @param string listing_file
 * @param int site_id
 * @return void
 */
function update_remote_site($listing_file, $site_id)
{
  global $lang, $counts, $template, $removes, $page;
  
  if (@fopen($listing_file, 'r'))
  {
    $counts = array(
      'new_elements' => 0,
      'new_categories' => 0,
      'del_elements' => 0,
      'del_categories' => 0
      );
    $removes = array();
        
    $xml_content = getXmlCode($listing_file);
    insert_remote_category($xml_content, $site_id, 'NULL', 0);
    update_category();
    ordering();
    update_global_rank();
        
    $template->assign_block_vars(
      'update',
      array(
        'NB_NEW_CATEGORIES'=>$counts['new_categories'],
        'NB_DEL_CATEGORIES'=>$counts['del_categories'],
        'NB_NEW_ELEMENTS'=>$counts['new_elements'],
        'NB_DEL_ELEMENTS'=>$counts['del_elements']
        ));
        
    if (count($removes) > 0)
    {
      $template->assign_block_vars('update.removes', array());
    }
    foreach ($removes as $remove)
    {
      $template->assign_block_vars('update.removes.remote_remove',
                                   array('NAME'=>$remove));
    }
  }
  else
  {
    array_push($page['errors'], $lang['remote_site_listing_not_found']);
  }
}

/**
 * searchs the "dir" node of the xml_dir given and insert the contained
 * categories if the are not in the database yet. The function also deletes
 * the categories that are in the database and not in the xml_file.
 *
 * @param string xml_content
 * @param int site_id
 * @param mixed id_uppercat
 * @param int level
 * @return void
 */
function insert_remote_category($xml_content, $site_id, $id_uppercat, $level)
{
  global $counts, $removes, $conf;
  
  $uppercats = '';
  // 0. retrieving informations on the category to display
		
  if (is_numeric($id_uppercat))
  {
    $query = '
SELECT id,name,uppercats,dir,status,visible
  FROM '.CATEGORIES_TABLE.'
  WHERE id = '.$id_uppercat.'
;';
    $row = mysql_fetch_array(pwg_query($query));
    $parent = array('id' => $row['id'],
                    'name' => $row['name'],
                    'dir' => $row['dir'],
                    'uppercats' => $row['uppercats'],
                    'visible' => $row['visible'],
                    'status' => $row['status']);
    
    insert_remote_element($xml_content, $id_uppercat);
  }

  // $xml_dirs contains dir names contained in the xml file for this
  // id_uppercat
  $xml_dirs = array();
  $temp_dirs = getChildren($xml_content, 'dir'.$level);
  foreach ($temp_dirs as $temp_dir)
  {
    array_push($xml_dirs, getAttribute($temp_dir, 'name'));
  }

  // $database_dirs contains dir names contained in the database for this
  // id_uppercat and site_id
  $database_dirs = database_subdirs($site_id, $id_uppercat);
  
  // 3. we have to remove the categories of the database not present anymore
  $to_delete = array();
  foreach ($database_dirs as $id => $dir)
  {
    if (!in_array($dir, $xml_dirs))
    {
      array_push($to_delete, $id);
      array_push($removes, get_complete_dir($id));
    }
  }
  delete_categories($to_delete);

  // array of new categories to insert
  $inserts = array();
  
  // calculate default value at category creation
  $create_values = array();
  if (isset($parent))
  {
    // at creation, must a category be visible or not ? Warning : if
    // the parent category is invisible, the category is automatically
    // create invisible. (invisible = locked)
    if ('false' == $parent['visible'])
    {
      $create_values{'visible'} = 'false';
    }
    else
    {
      $create_values{'visible'} = $conf['newcat_default_visible'];
    }
    // at creation, must a category be public or private ? Warning :
    // if the parent category is private, the category is
    // automatically create private.
    if ('private' == $parent['status'])
    {
      $create_values{'status'} = 'private';
    }
    else
    {
      $create_values{'status'} = $conf['newcat_default_status'];
    }
  }
  else
  {
    $create_values{'visible'} = $conf['newcat_default_visible'];
    $create_values{'status'} = $conf['newcat_default_status'];
  }

  foreach ($xml_dirs as $xml_dir)
  {
    // 5. Is the category already existing ? we create a subcat if not
    //    existing
    $category_id = array_search($xml_dir, $database_dirs);
    if (!is_numeric($category_id))
    {
      $name = str_replace('_', ' ', $xml_dir);

      $insert = array();

      $insert{'dir'} = $xml_dir;
      $insert{'name'} = $name;
      $insert{'site_id'} = $site_id;
      $insert{'uppercats'} = 'undef';
      $insert{'commentable'} = $conf['newcat_default_commentable'];
      $insert{'uploadable'} = 'false';
      $insert{'status'} = $create_values{'status'};
      $insert{'visible'} = $create_values{'visible'};
      if (isset($parent))
      {
        $insert{'id_uppercat'} = $parent['id'];
      }
      array_push($inserts, $insert);
    }
  }

  // we have to create the category
  if (count($inserts) > 0)
  {
    // inserts all found categories
    $dbfields = array('dir','name','site_id','uppercats','id_uppercat',
                      'commentable','uploadable','status','visible');
    mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts);
    $counts{'new_categories'}+= count($inserts);
    
    // updating uppercats field
    $query = '
UPDATE '.CATEGORIES_TABLE;
    if (isset($parent))
    {
      $query.= "
  SET uppercats = CONCAT('".$parent['uppercats']."',',',id)
  WHERE id_uppercat = ".$id_uppercat;
    }
    else
    {
      $query.= '
  SET uppercats = id
  WHERE id_uppercat IS NULL';
    }
    $query.= '
;';
    pwg_query($query);
  }

  // Recursive call on the sub-categories (not virtual ones)
  $database_dirs = database_subdirs($site_id, $id_uppercat);
  
  foreach ($temp_dirs as $temp_dir)
  {
    $dir = getAttribute($temp_dir, 'name');
    $id_uppercat = array_search($dir, $database_dirs);
    insert_remote_category($temp_dir, $site_id, $id_uppercat, $level+1);
  }
}

/**
 * searchs the "root" node of $xml_dir (xml string), inserts elements in the
 * database if new
 *
 * @param string xml_dir
 * @param int category_id
 * @return void
 */
function insert_remote_element($xml_dir, $category_id)
{
  global $counts, $lang, $removes;

  $output = '';
  $root = getChild($xml_dir, 'root');

  $xml_files = array();
  $xml_elements = getChildren($root, 'element');
  foreach ($xml_elements as $xml_element)
  {
    array_push($xml_files, getAttribute($xml_element,'file'));
  }
  
  // we have to delete all the images from the database that are not in the
  // directory anymore (not in the XML anymore)
  $query = '
SELECT id,file
  FROM '.IMAGES_TABLE.'
  WHERE storage_category_id = '.$category_id.'
;';
  $result = pwg_query($query);
  $to_delete = array();
  while ($row = mysql_fetch_array($result))
  {
    if (!in_array($row['file'], $xml_files))
    {
      // local_dir is cached
      if (!isset($local_dir))
      {
        $local_dir = get_local_dir($category_id);
      }
      array_push($removes, $local_dir.$row['file']);
      array_push($to_delete, $row['id']);
    }
  }
  delete_elements($to_delete);

  $database_elements = array();
  $query = '
SELECT file
  FROM '.IMAGES_TABLE.'
  WHERE storage_category_id = '.$category_id.'
;';
  $result = pwg_query($query);
  while ($row = mysql_fetch_array($result))
  {
    array_push($database_elements, $row['file']);
  }

  $inserts = array();
  foreach ($xml_elements as $xml_element)
  {
    // minimal tag : <element file="albatros.jpg"/>
    $file = getAttribute($xml_element, 'file');

    // is the picture already existing in the database ?
    if (!in_array($file, $database_elements))
    {
      $insert = array();
      $insert{'file'} = $file;
      $insert{'storage_category_id'} = $category_id;
      $insert{'date_available'} = CURRENT_DATE;
      $optional_atts = array('tn_ext',
                             'representative_ext',
                             'filesize',
                             'width',
                             'height',
                             'date_creation',
                             'author',
                             'keywords',
                             'name',
                             'comment',
                             'path');
      foreach ($optional_atts as $att)
      {
        if (getAttribute($xml_element, $att) != '')
        {
          $insert{$att} = getAttribute($xml_element, $att);
        }
      }
      array_push($inserts, $insert);
    }
  }

  if (count($inserts) > 0)
  {
    $dbfields = array('file','storage_category_id','date_available','tn_ext',
                      'filesize','width','height','date_creation','author',
                      'keywords','name','comment','path');
    mass_inserts(IMAGES_TABLE, $dbfields, $inserts);
    $counts{'new_elements'}+= count($inserts);

    // what are the ids of the pictures in the $category_id ?
    $ids = array();

    $query = '
SELECT id
  FROM '.IMAGES_TABLE.'
  WHERE storage_category_id = '.$category_id.'
;';
    $result = pwg_query($query);
    while ($row = mysql_fetch_array($result))
    {
      array_push($ids, $row['id']);
    }

    // recreation of the links between this storage category pictures and
    // its storage category
    $query = '
DELETE FROM '.IMAGE_CATEGORY_TABLE.'
  WHERE category_id = '.$category_id.'
    AND image_id IN ('.implode(',', $ids).')
;';
    pwg_query($query);

    $query = '
INSERT INTO '.IMAGE_CATEGORY_TABLE.'
  (category_id,image_id)
  VALUES';
    foreach ($ids as $num => $image_id)
    {
      $query.= '
  ';
      if ($num > 0)
      {
        $query.= ',';
      }
      $query.= '('.$category_id.','.$image_id.')';
    }
    $query.= '
;';
    pwg_query($query);
    // set a new representative element for this category
    $query = '
SELECT image_id
  FROM '.IMAGE_CATEGORY_TABLE.'
  WHERE category_id = '.$category_id.'
  ORDER BY RAND()
  LIMIT 0,1
;';
    list($representative) = mysql_fetch_array(pwg_query($query));
    $query = '
UPDATE '.CATEGORIES_TABLE.'
  SET representative_picture_id = '.$representative.'
  WHERE id = '.$category_id.'
;';
    pwg_query($query);
  }
}
// +-----------------------------------------------------------------------+
// |                             template init                             |
// +-----------------------------------------------------------------------+
$template->set_filenames(array('remote_site'=>'admin/remote_site.tpl'));

$template->assign_vars(
  array(
    'L_SUBMIT'=>$lang['submit'],
    'L_REMOTE_SITE_CREATE'=>$lang['remote_site_create'],
    'L_REMOTE_SITE_GENERATE'=>$lang['remote_site_generate'],
    'L_REMOTE_SITE_GENERATE_HINT'=>$lang['remote_site_generate_hint'],
    'L_REMOTE_SITE_UPDATE'=>$lang['remote_site_update'],
    'L_REMOTE_SITE_UPDATE_HINT'=>$lang['remote_site_update_hint'],
    'L_REMOTE_SITE_CLEAN'=>$lang['remote_site_clean'],
    'L_REMOTE_SITE_CLEAN_HINT'=>$lang['remote_site_clean_hint'],
    'L_REMOTE_SITE_DELETE'=>$lang['remote_site_delete'],
    'L_REMOTE_SITE_DELETE_HINT'=>$lang['remote_site_delete_hint'],
    'L_NB_NEW_ELEMENTS'=>$lang['update_nb_new_elements'],
    'L_NB_NEW_CATEGORIES'=>$lang['update_nb_new_categories'],
    'L_NB_DEL_ELEMENTS'=>$lang['update_nb_del_elements'],
    'L_NB_DEL_CATEGORIES'=>$lang['update_nb_del_categories'],
    'L_REMOTE_SITE_REMOVED_TITLE'=>$lang['remote_site_removed_title'],
    'L_REMOTE_SITE_REMOVED'=>$lang['remote_site_removed'],
    'L_REMOTE_SITE_LOCAL_FOUND'=>$lang['remote_site_local_found'],
    'L_REMOTE_SITE_LOCAL_NEW'=>$lang['remote_site_local_new'],
    'L_REMOTE_SITE_LOCAL_UPDATE'=>$lang['remote_site_local_update'],

    'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=remote_site',
    
    'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=remote_site')
   )
 );
 
// +-----------------------------------------------------------------------+
// |                        new site creation form                         |
// +-----------------------------------------------------------------------+
if (isset($_POST['submit']))
{
  // site must start by http:// or https://
  if (!preg_match('/^https?:\/\/[~\/\.\w-]+$/', $_POST['galleries_url']))
  {
    array_push($page['errors'], $lang['remote_site_uncorrect_url']);
  }
  else
  {
    $page['galleries_url'] = preg_replace('/[\/]*$/',
                                          '',
                                          $_POST['galleries_url']);
    $page['galleries_url'].= '/';
    // site must not exists
    $query = '
SELECT COUNT(id) AS count
  FROM '.SITES_TABLE.'
  WHERE galleries_url = \''.$page['galleries_url'].'\'
;';
    $row = mysql_fetch_array(pwg_query($query));
    if ($row['count'] > 0)
    {
      array_push($page['errors'], $lang['remote_site_already_exists']);
    }
  }

  if (count($page['errors']) == 0)
  {
    $url = $page['galleries_url'].'create_listing_file.php';
    $url.= '?action=test';
    $url.= '&version='.PHPWG_VERSION;
    if ($lines = @file($url))
    {
      $first_line = strip_tags($lines[0]);
      if (!preg_match('/^PWG-INFO-2:/', $first_line))
      {
        array_push($page['errors'],
                   $lang['remote_site_error'].' : '.$first_line);
      }
    }
    else
    {
      array_push($page['errors'], $lang['remote_site_file_not_found']);
    }
  }
  
  if (count($page['errors']) == 0)
  {
    $query = '
INSERT INTO '.SITES_TABLE.'
  (galleries_url)
  VALUES
  (\''.$page['galleries_url'].'\')
;';
    pwg_query($query);

    array_push($page['infos'],
               $page['galleries_url'].' '.$lang['remote_site_created']);
  }
}
// +-----------------------------------------------------------------------+
// |                            actions on site                            |
// +-----------------------------------------------------------------------+
if (isset($_GET['site']) and is_numeric($_GET['site']))
{
  $page['site'] = $_GET['site'];
}

if (isset($_GET['action']))
{
  if (isset($page['site']))
  {
    $query = '
SELECT galleries_url
  FROM '.SITES_TABLE.'
  WHERE id = '.$page['site'].'
;';
    list($galleries_url) = mysql_fetch_array(pwg_query($query));
  }

  switch($_GET['action'])
  {
    case 'delete' :
    {
      delete_site($page['site']);
      array_push($page['infos'],
                 $galleries_url.' '.$lang['remote_site_deleted']);
      break;
    }
    case 'generate' :
    {
      $title = $galleries_url.' : '.$lang['remote_site_generate'];
      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
      remote_output($galleries_url.'create_listing_file.php?action=generate');
      break;
    }
    case 'update' :
    {
      $title = $galleries_url.' : '.$lang['remote_site_update'];
      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
      update_remote_site($galleries_url.'listing.xml', $page['site']);
      break;
    }
    case 'clean' :
    {
      $title = $galleries_url.' : '.$lang['remote_site_clean'];
      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
      remote_output($galleries_url.'create_listing_file.php?action=clean');
      break;
    }
    case 'local_update' :
    {
      $local_listing = PHPWG_ROOT_PATH.'listing.xml';
      $xml_content = getXmlCode($local_listing);
      $url = getAttribute(getChild($xml_content, 'informations'), 'url');

      // is the site already existing ?
      $query = '
SELECT id
  FROM '.SITES_TABLE.'
  WHERE galleries_url = \''.addslashes($url).'\'
;';
      $result = pwg_query($query);
      if (mysql_num_rows($result) == 0)
      {
        // we have to register this site in the database
        $query = '
INSERT INTO '.SITES_TABLE.'
  (galleries_url)
  VALUES
  (\''.$url.'\')
;';
        pwg_query($query);
        $site_id = mysql_insert_id();
      }
      else
      {
        // we get the already registered id
        $row = mysql_fetch_array($result);
        $site_id = $row['id'];
      }
      
      $title = $url.' : '.$lang['remote_site_local_update'];
      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
      update_remote_site($local_listing, $site_id);
      break;
    }
  }
}
else
{
  // we search a "local" listing.xml file
  $local_listing = PHPWG_ROOT_PATH.'listing.xml';
  if (is_file($local_listing))
  {
    $xml_content = getXmlCode($local_listing);
    $url = getAttribute(getChild($xml_content, 'informations'), 'url');

    $base_url = PHPWG_ROOT_PATH.'admin.php?page=remote_site&amp;action=';
    
    $template->assign_block_vars(
      'local',
      array(
        'URL' => $url,
        'U_UPDATE' => add_session_id($base_url.'local_update')
        )
      );

    // is the site already existing ?
    $query = '
SELECT COUNT(*)
  FROM '.SITES_TABLE.'
  WHERE galleries_url = \''.addslashes($url).'\'
;';
    list($count) = mysql_fetch_array(pwg_query($query));
    if ($count == 0)
    {
      $template->assign_block_vars('local.new_site', array());
    }
  }
}
// +-----------------------------------------------------------------------+
// |                           remote sites list                           |
// +-----------------------------------------------------------------------+

// site 1 is the local site, should not be taken into account
$query = '
SELECT id, galleries_url
  FROM '.SITES_TABLE.'
  WHERE id != 1
;';
$result = pwg_query($query);

if (mysql_num_rows($result) > 0)
{
  $template->assign_block_vars('sites', array());
}

while ($row = mysql_fetch_array($result))
{
  $base_url = PHPWG_ROOT_PATH.'admin.php';
  $base_url.= '?page=remote_site';
  $base_url.= '&amp;site='.$row['id'];
  $base_url.= '&amp;action=';
  
  $template->assign_block_vars(
    'sites.site',
    array(
      'NAME' => $row['galleries_url'],
      'U_GENERATE' => add_session_id($base_url.'generate'),
      'U_UPDATE' => add_session_id($base_url.'update'),
      'U_CLEAN' => add_session_id($base_url.'clean'),
      'U_DELETE' => add_session_id($base_url.'delete')
     )
   );
}
// +-----------------------------------------------------------------------+
// |                           sending html code                           |
// +-----------------------------------------------------------------------+
$template->assign_var_from_handle('ADMIN_CONTENT', 'remote_site');
?>