[1058] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[12922] | 5 | // | Copyright(C) 2008-2012 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 | |
---|
| 24 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 25 | { |
---|
| 26 | die ("Hacking attempt!"); |
---|
| 27 | } |
---|
| 28 | |
---|
[1072] | 29 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 30 | |
---|
| 31 | // +-----------------------------------------------------------------------+ |
---|
| 32 | // | Check Access and exit when user status is not ok | |
---|
| 33 | // +-----------------------------------------------------------------------+ |
---|
| 34 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 35 | |
---|
[5195] | 36 | if (!empty($_POST) or isset($_GET['action'])) |
---|
| 37 | { |
---|
| 38 | check_pwg_token(); |
---|
| 39 | } |
---|
| 40 | |
---|
[1058] | 41 | // +-----------------------------------------------------------------------+ |
---|
| 42 | // | template init | |
---|
| 43 | // +-----------------------------------------------------------------------+ |
---|
[2530] | 44 | $template->set_filenames(array('site_manager'=>'site_manager.tpl')); |
---|
[1058] | 45 | |
---|
| 46 | // +-----------------------------------------------------------------------+ |
---|
| 47 | // | new site creation form | |
---|
| 48 | // +-----------------------------------------------------------------------+ |
---|
[8126] | 49 | if (isset($_POST['submit']) and !empty($_POST['galleries_url'])) |
---|
[1058] | 50 | { |
---|
| 51 | $is_remote = url_is_remote( $_POST['galleries_url'] ); |
---|
[13488] | 52 | if ($is_remote) |
---|
| 53 | { |
---|
| 54 | fatal_error('remote sites not supported'); |
---|
| 55 | } |
---|
[1058] | 56 | $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']); |
---|
| 57 | $url.= '/'; |
---|
[13488] | 58 | if ( ! (strpos($url, '.') === 0 ) ) |
---|
[1058] | 59 | { |
---|
[13488] | 60 | $url = './' . $url; |
---|
[1058] | 61 | } |
---|
| 62 | |
---|
| 63 | // site must not exists |
---|
| 64 | $query = ' |
---|
| 65 | SELECT COUNT(id) AS count |
---|
| 66 | FROM '.SITES_TABLE.' |
---|
| 67 | WHERE galleries_url = \''.$url.'\' |
---|
| 68 | ;'; |
---|
[4325] | 69 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[1058] | 70 | if ($row['count'] > 0) |
---|
| 71 | { |
---|
| 72 | array_push($page['errors'], |
---|
[5021] | 73 | l10n('This site already exists').' ['.$url.']'); |
---|
[1058] | 74 | } |
---|
| 75 | if (count($page['errors']) == 0) |
---|
| 76 | { |
---|
[13488] | 77 | if ( ! file_exists($url) ) |
---|
[1058] | 78 | { |
---|
[13488] | 79 | array_push($page['errors'], |
---|
| 80 | l10n('Directory does not exist').' ['.$url.']'); |
---|
[1058] | 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | if (count($page['errors']) == 0) |
---|
| 85 | { |
---|
| 86 | $query = ' |
---|
| 87 | INSERT INTO '.SITES_TABLE.' |
---|
| 88 | (galleries_url) |
---|
| 89 | VALUES |
---|
| 90 | (\''.$url.'\') |
---|
| 91 | ;'; |
---|
| 92 | pwg_query($query); |
---|
| 93 | array_push($page['infos'], |
---|
[5021] | 94 | $url.' '.l10n('created')); |
---|
[1058] | 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | // +-----------------------------------------------------------------------+ |
---|
| 99 | // | actions on site | |
---|
| 100 | // +-----------------------------------------------------------------------+ |
---|
| 101 | if (isset($_GET['site']) and is_numeric($_GET['site'])) |
---|
| 102 | { |
---|
| 103 | $page['site'] = $_GET['site']; |
---|
| 104 | } |
---|
[8126] | 105 | if (isset($_GET['action']) and isset($page['site'])) |
---|
[1058] | 106 | { |
---|
| 107 | $query = ' |
---|
| 108 | SELECT galleries_url |
---|
| 109 | FROM '.SITES_TABLE.' |
---|
| 110 | WHERE id = '.$page['site'].' |
---|
| 111 | ;'; |
---|
[4325] | 112 | list($galleries_url) = pwg_db_fetch_row(pwg_query($query)); |
---|
[1058] | 113 | switch($_GET['action']) |
---|
| 114 | { |
---|
| 115 | case 'delete' : |
---|
| 116 | { |
---|
| 117 | delete_site($page['site']); |
---|
| 118 | array_push($page['infos'], |
---|
[5021] | 119 | $galleries_url.' '.l10n('deleted')); |
---|
[1058] | 120 | break; |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
[5195] | 125 | $template->assign( |
---|
| 126 | array( |
---|
| 127 | 'F_ACTION' => get_root_url().'admin.php'.get_query_string_diff(array('action','site','pwg_token')), |
---|
| 128 | 'PWG_TOKEN' => get_pwg_token(), |
---|
| 129 | ) |
---|
| 130 | ); |
---|
[1058] | 131 | |
---|
| 132 | $query = ' |
---|
[2324] | 133 | SELECT c.site_id, COUNT(DISTINCT c.id) AS nb_categories, COUNT(i.id) AS nb_images |
---|
| 134 | FROM '.CATEGORIES_TABLE.' AS c LEFT JOIN '.IMAGES_TABLE.' AS i |
---|
| 135 | ON c.id=i.storage_category_id |
---|
| 136 | WHERE c.site_id IS NOT NULL |
---|
| 137 | GROUP BY c.site_id |
---|
| 138 | ;'; |
---|
| 139 | $sites_detail = hash_from_query($query, 'site_id'); |
---|
| 140 | |
---|
| 141 | $query = ' |
---|
| 142 | SELECT * |
---|
| 143 | FROM '.SITES_TABLE.' |
---|
| 144 | ;'; |
---|
[1058] | 145 | $result = pwg_query($query); |
---|
| 146 | |
---|
[4325] | 147 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[1058] | 148 | { |
---|
| 149 | $is_remote = url_is_remote($row['galleries_url']); |
---|
| 150 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
| 151 | $base_url.= '?page=site_manager'; |
---|
| 152 | $base_url.= '&site='.$row['id']; |
---|
[5195] | 153 | $base_url.= '&pwg_token='.get_pwg_token(); |
---|
[1058] | 154 | $base_url.= '&action='; |
---|
| 155 | |
---|
| 156 | $update_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
| 157 | $update_url.= '?page=site_update'; |
---|
| 158 | $update_url.= '&site='.$row['id']; |
---|
[2273] | 159 | |
---|
| 160 | $tpl_var = |
---|
[1058] | 161 | array( |
---|
| 162 | 'NAME' => $row['galleries_url'], |
---|
[5036] | 163 | 'TYPE' => l10n( $is_remote ? 'Remote' : 'Local' ), |
---|
[2324] | 164 | 'CATEGORIES' => (int)@$sites_detail[$row['id']]['nb_categories'], |
---|
| 165 | 'IMAGES' => (int)@$sites_detail[$row['id']]['nb_images'], |
---|
[1058] | 166 | 'U_SYNCHRONIZE' => $update_url |
---|
[2273] | 167 | ); |
---|
| 168 | |
---|
[1107] | 169 | if ($row['id'] != 1) |
---|
| 170 | { |
---|
[2273] | 171 | $tpl_var['U_DELETE'] = $base_url.'delete'; |
---|
[1107] | 172 | } |
---|
| 173 | |
---|
[2273] | 174 | $plugin_links = array(); |
---|
| 175 | //$plugin_links is array of array composed of U_HREF, U_HINT & U_CAPTION |
---|
| 176 | $plugin_links = |
---|
| 177 | trigger_event('get_admins_site_links', |
---|
| 178 | $plugin_links, $row['id'], $is_remote); |
---|
| 179 | $tpl_var['plugin_links'] = $plugin_links; |
---|
| 180 | |
---|
| 181 | $template->append('sites', $tpl_var); |
---|
[1058] | 182 | } |
---|
| 183 | |
---|
| 184 | $template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager'); |
---|
[1775] | 185 | ?> |
---|