source: trunk/admin/site_manager.php @ 1072

Last change on this file since 1072 was 1072, checked in by rub, 18 years ago

Step 2 improvement issue 0000301:

o Add and use Functions Check of status
o Restricted Access for user generic

  • Property svn:eol-style set to native
File size: 8.3 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-01-31 21:46:26 -0500 (Tue, 31 Jan 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1020 $
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
40/**
41 * requests the given $url (a remote create_listing_file.php) and fills a
42 * list of lines corresponding to request output
43 *
44 * @param string $url
45 * @return void
46 */
47function remote_output($url)
48{
49  global $template, $page;
50
51  if($lines = @file($url))
52  {
53    $template->assign_block_vars('remote_output', array());
54    // cleaning lines from HTML tags
55    foreach ($lines as $line)
56    {
57      $line = trim(strip_tags($line));
58      if (preg_match('/^PWG-([A-Z]+)-/', $line, $matches))
59      {
60        $template->assign_block_vars(
61          'remote_output.remote_line',
62          array(
63            'CLASS' => 'remote'.ucfirst(strtolower($matches[1])),
64            'CONTENT' => $line
65           )
66         );
67      }
68    }
69  }
70  else
71  {
72    array_push($page['errors'], l10n('site_err_remote_file_not_found'));
73  }
74}
75
76
77// +-----------------------------------------------------------------------+
78// |                             template init                             |
79// +-----------------------------------------------------------------------+
80$template->set_filenames(array('site_manager'=>'admin/site_manager.tpl'));
81
82// +-----------------------------------------------------------------------+
83// |                        new site creation form                         |
84// +-----------------------------------------------------------------------+
85if (isset($_POST['submit']))
86{
87  $is_remote = url_is_remote( $_POST['galleries_url'] );
88  $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']);
89  $url.= '/';
90  if (! $is_remote)
91  {
92    if ( ! (strpos($url, '.') === 0 ) )
93    {
94      $url = './' . $url;
95    }
96  }
97
98  // site must not exists
99  $query = '
100SELECT COUNT(id) AS count
101  FROM '.SITES_TABLE.'
102  WHERE galleries_url = \''.$url.'\'
103;';
104  $row = mysql_fetch_array(pwg_query($query));
105  if ($row['count'] > 0)
106  {
107    array_push($page['errors'],
108      l10n('site_already_exists').' ['.$url.']');
109  }
110  if (count($page['errors']) == 0)
111  {
112    if ($is_remote)
113    {
114      $clf_url = $url.'create_listing_file.php';
115      $clf_url.= '?action=test';
116      $clf_url.= '&version='.PHPWG_VERSION;
117      if ($lines = @file($clf_url))
118      {
119        $first_line = strip_tags($lines[0]);
120        if (!preg_match('/^PWG-INFO-2:/', $first_line))
121        {
122          array_push($page['errors'],
123                     l10n('site_err').' : '.$first_line);
124        }
125      }
126      else
127      {
128        array_push($page['errors'], l10n('site_err_remote_file_not_found') );
129      }
130    }
131    else
132    { // local directory
133      if ( ! file_exists($url) )
134      {
135        array_push($page['errors'],
136          l10n('Directory does not exist').' ['.$url.']');
137      }
138    }
139  }
140
141  if (count($page['errors']) == 0)
142  {
143    $query = '
144INSERT INTO '.SITES_TABLE.'
145  (galleries_url)
146  VALUES
147  (\''.$url.'\')
148;';
149    pwg_query($query);
150    array_push($page['infos'],
151               $url.' '.l10n('site_created'));
152  }
153}
154
155// +-----------------------------------------------------------------------+
156// |                            actions on site                            |
157// +-----------------------------------------------------------------------+
158if (isset($_GET['site']) and is_numeric($_GET['site']))
159{
160  $page['site'] = $_GET['site'];
161}
162if (isset($_GET['action']) and isset($page['site']) )
163{
164  $query = '
165SELECT galleries_url
166  FROM '.SITES_TABLE.'
167  WHERE id = '.$page['site'].'
168;';
169  list($galleries_url) = mysql_fetch_array(pwg_query($query));
170  switch($_GET['action'])
171  {
172    case 'generate' :
173    {
174      $title = $galleries_url.' : '.l10n('remote_site_generate');
175      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
176      remote_output($galleries_url.'create_listing_file.php?action=generate');
177      break;
178    }
179    case 'test' :
180    {
181      $title = $galleries_url.' : '.l10n('remote_site_test');
182      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
183      remote_output($galleries_url.'create_listing_file.php?action=test&version='.PHPWG_VERSION);
184      break;
185    }
186    case 'clean' :
187    {
188      $title = $galleries_url.' : '.l10n('remote_site_clean');
189      $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title));
190      remote_output($galleries_url.'create_listing_file.php?action=clean');
191      break;
192    }
193    case 'delete' :
194    {
195      delete_site($page['site']);
196      array_push($page['infos'],
197                 $galleries_url.' '.l10n('site_deleted'));
198      break;
199    }
200  }
201}
202
203$template->assign_vars( array(
204  'F_ACTION' => PHPWG_ROOT_PATH.'admin.php'
205                .get_query_string_diff( array('action','site') )
206  ) );
207
208// +-----------------------------------------------------------------------+
209// |                           remote sites list                           |
210// +-----------------------------------------------------------------------+
211
212$query = '
213SELECT s.*, COUNT(c.id) AS nb_categories, SUM(c.nb_images) AS nb_images
214FROM '.SITES_TABLE.' AS s LEFT JOIN '.CATEGORIES_TABLE.' AS c
215ON s.id=c.site_id
216GROUP BY s.id'.
217';';
218$result = pwg_query($query);
219
220if (mysql_num_rows($result) > 0)
221{
222  $template->assign_block_vars('sites', array());
223}
224while ($row = mysql_fetch_array($result))
225{
226  $is_remote = url_is_remote($row['galleries_url']);
227  $base_url = PHPWG_ROOT_PATH.'admin.php';
228  $base_url.= '?page=site_manager';
229  $base_url.= '&amp;site='.$row['id'];
230  $base_url.= '&amp;action=';
231
232  $update_url = PHPWG_ROOT_PATH.'admin.php';
233  $update_url.= '?page=site_update';
234  $update_url.= '&amp;site='.$row['id'];
235  $template->assign_block_vars(
236    'sites.site',
237    array(
238      'NAME' => $row['galleries_url'],
239      'TYPE' => l10n( $is_remote ? 'site_remote' : 'site_local' ),
240      'CATEGORIES' => $row['nb_categories'],
241      'IMAGES' => isset($row['nb_images']) ? $row['nb_images'] : 0,
242      'U_SYNCHRONIZE' => $update_url
243     )
244   );
245   if ($is_remote)
246   {
247     $template->assign_block_vars('sites.site.remote',
248       array(
249         'U_TEST' => $base_url.'test',
250         'U_GENERATE' => $base_url.'generate',
251         'U_CLEAN' => $base_url.'clean'
252         )
253       );
254   }
255
256   if ($row['id'] != 1)
257   {
258     $template->assign_block_vars( 'sites.site.delete',
259       array('U_DELETE' => $base_url.'delete') );
260   }
261}
262
263$template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager');
264?>
Note: See TracBrowser for help on using the repository browser.