source: trunk/admin/site_manager.php @ 24663

Last change on this file since 24663 was 22979, checked in by plg, 11 years ago

merge r22978 from branch 2.5 to trunk

bug 2915 fixed: really disable synchronization on synchronization and site (directories) manager screens.

  • Property svn:eol-style set to LF
File size: 6.1 KB
RevLine 
[1058]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[19703]5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
[2297]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
[1058]23
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die ("Hacking attempt!");
27}
28
[1072]29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
[22979]34
35if (!$conf['enable_synchronization'])
36{
37  die('synchronization is disabled');
38}
39
[1072]40check_status(ACCESS_ADMINISTRATOR);
41
[5195]42if (!empty($_POST) or isset($_GET['action']))
43{
44  check_pwg_token();
45}
46
[1058]47// +-----------------------------------------------------------------------+
48// |                             template init                             |
49// +-----------------------------------------------------------------------+
[2530]50$template->set_filenames(array('site_manager'=>'site_manager.tpl'));
[1058]51
52// +-----------------------------------------------------------------------+
53// |                        new site creation form                         |
54// +-----------------------------------------------------------------------+
[8126]55if (isset($_POST['submit']) and !empty($_POST['galleries_url']))
[1058]56{
57  $is_remote = url_is_remote( $_POST['galleries_url'] );
[13488]58  if ($is_remote)
59  {
60    fatal_error('remote sites not supported');
61  }
[1058]62  $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']);
63  $url.= '/';
[13488]64  if ( ! (strpos($url, '.') === 0 ) )
[1058]65  {
[13488]66    $url = './' . $url;
[1058]67  }
68
69  // site must not exists
70  $query = '
71SELECT COUNT(id) AS count
72  FROM '.SITES_TABLE.'
73  WHERE galleries_url = \''.$url.'\'
74;';
[4325]75  $row = pwg_db_fetch_assoc(pwg_query($query));
[1058]76  if ($row['count'] > 0)
77  {
78    array_push($page['errors'],
[5021]79      l10n('This site already exists').' ['.$url.']');
[1058]80  }
81  if (count($page['errors']) == 0)
82  {
[13488]83    if ( ! file_exists($url) )
[1058]84    {
[13488]85      array_push($page['errors'],
86        l10n('Directory does not exist').' ['.$url.']');
[1058]87    }
88  }
89
90  if (count($page['errors']) == 0)
91  {
92    $query = '
93INSERT INTO '.SITES_TABLE.'
94  (galleries_url)
95  VALUES
96  (\''.$url.'\')
97;';
98    pwg_query($query);
99    array_push($page['infos'],
[5021]100               $url.' '.l10n('created'));
[1058]101  }
102}
103
104// +-----------------------------------------------------------------------+
105// |                            actions on site                            |
106// +-----------------------------------------------------------------------+
107if (isset($_GET['site']) and is_numeric($_GET['site']))
108{
109  $page['site'] = $_GET['site'];
110}
[8126]111if (isset($_GET['action']) and isset($page['site']))
[1058]112{
113  $query = '
114SELECT galleries_url
115  FROM '.SITES_TABLE.'
116  WHERE id = '.$page['site'].'
117;';
[4325]118  list($galleries_url) = pwg_db_fetch_row(pwg_query($query));
[1058]119  switch($_GET['action'])
120  {
121    case 'delete' :
122    {
123      delete_site($page['site']);
124      array_push($page['infos'],
[5021]125                 $galleries_url.' '.l10n('deleted'));
[1058]126      break;
127    }
128  }
129}
130
[5195]131$template->assign(
132  array(
133    'F_ACTION'  => get_root_url().'admin.php'.get_query_string_diff(array('action','site','pwg_token')),
134    'PWG_TOKEN' => get_pwg_token(),
135    )
136  );
[1058]137
138$query = '
[2324]139SELECT c.site_id, COUNT(DISTINCT c.id) AS nb_categories, COUNT(i.id) AS nb_images
140  FROM '.CATEGORIES_TABLE.' AS c LEFT JOIN '.IMAGES_TABLE.' AS i
141  ON c.id=i.storage_category_id
142  WHERE c.site_id IS NOT NULL
143  GROUP BY c.site_id
144;';
145$sites_detail = hash_from_query($query, 'site_id'); 
146
147$query = '
148SELECT *
149  FROM '.SITES_TABLE.'
150;';
[1058]151$result = pwg_query($query);
152
[4325]153while ($row = pwg_db_fetch_assoc($result))
[1058]154{
155  $is_remote = url_is_remote($row['galleries_url']);
156  $base_url = PHPWG_ROOT_PATH.'admin.php';
157  $base_url.= '?page=site_manager';
158  $base_url.= '&amp;site='.$row['id'];
[5195]159  $base_url.= '&amp;pwg_token='.get_pwg_token();
[1058]160  $base_url.= '&amp;action=';
161
162  $update_url = PHPWG_ROOT_PATH.'admin.php';
163  $update_url.= '?page=site_update';
164  $update_url.= '&amp;site='.$row['id'];
[2273]165 
166  $tpl_var =
[1058]167    array(
168      'NAME' => $row['galleries_url'],
[5036]169      'TYPE' => l10n( $is_remote ? 'Remote' : 'Local' ),
[2324]170      'CATEGORIES' => (int)@$sites_detail[$row['id']]['nb_categories'],
171      'IMAGES' => (int)@$sites_detail[$row['id']]['nb_images'],
[1058]172      'U_SYNCHRONIZE' => $update_url
[2273]173     );
174     
[1107]175  if ($row['id'] != 1)
176  {
[2273]177    $tpl_var['U_DELETE'] = $base_url.'delete';
[1107]178  }
179
[2273]180  $plugin_links = array();
181  //$plugin_links is array of array composed of U_HREF, U_HINT & U_CAPTION
182  $plugin_links =
183    trigger_event('get_admins_site_links',
184      $plugin_links, $row['id'], $is_remote);
185  $tpl_var['plugin_links'] = $plugin_links;
186
187  $template->append('sites', $tpl_var);
[1058]188}
189
190$template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager');
[1775]191?>
Note: See TracBrowser for help on using the repository browser.