[21] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[5196] | 5 | // | Copyright(C) 2008-2010 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 | // +-----------------------------------------------------------------------+ |
---|
[815] | 23 | |
---|
[623] | 24 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
| 25 | { |
---|
[815] | 26 | die ("Hacking attempt!"); |
---|
[623] | 27 | } |
---|
| 28 | |
---|
[1072] | 29 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 30 | |
---|
[815] | 31 | // +-----------------------------------------------------------------------+ |
---|
[1072] | 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['delete']) or isset($_GET['toggle_is_default'])) |
---|
| 37 | { |
---|
| 38 | check_pwg_token(); |
---|
| 39 | } |
---|
| 40 | |
---|
[1072] | 41 | // +-----------------------------------------------------------------------+ |
---|
[815] | 42 | // | delete a group | |
---|
| 43 | // +-----------------------------------------------------------------------+ |
---|
| 44 | |
---|
[1591] | 45 | if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser()) |
---|
[21] | 46 | { |
---|
[631] | 47 | // destruction of the access linked to the group |
---|
[815] | 48 | $query = ' |
---|
| 49 | DELETE |
---|
| 50 | FROM '.GROUP_ACCESS_TABLE.' |
---|
| 51 | WHERE group_id = '.$_GET['delete'].' |
---|
| 52 | ;'; |
---|
| 53 | pwg_query($query); |
---|
| 54 | |
---|
| 55 | // destruction of the users links for this group |
---|
| 56 | $query = ' |
---|
| 57 | DELETE |
---|
| 58 | FROM '.USER_GROUP_TABLE.' |
---|
| 59 | WHERE group_id = '.$_GET['delete'].' |
---|
| 60 | ;'; |
---|
| 61 | pwg_query($query); |
---|
| 62 | |
---|
| 63 | $query = ' |
---|
| 64 | SELECT name |
---|
| 65 | FROM '.GROUPS_TABLE.' |
---|
| 66 | WHERE id = '.$_GET['delete'].' |
---|
| 67 | ;'; |
---|
[4325] | 68 | list($groupname) = pwg_db_fetch_row(pwg_query($query)); |
---|
[815] | 69 | |
---|
| 70 | // destruction of the group |
---|
| 71 | $query = ' |
---|
| 72 | DELETE |
---|
| 73 | FROM '.GROUPS_TABLE.' |
---|
| 74 | WHERE id = '.$_GET['delete'].' |
---|
| 75 | ;'; |
---|
| 76 | pwg_query($query); |
---|
| 77 | |
---|
| 78 | array_push( |
---|
| 79 | $page['infos'], |
---|
[5036] | 80 | sprintf(l10n('group "%s" deleted'), $groupname) |
---|
[815] | 81 | ); |
---|
[21] | 82 | } |
---|
[815] | 83 | |
---|
| 84 | // +-----------------------------------------------------------------------+ |
---|
| 85 | // | add a group | |
---|
| 86 | // +-----------------------------------------------------------------------+ |
---|
| 87 | |
---|
[1591] | 88 | if (isset($_POST['submit_add']) and !is_adviser()) |
---|
[21] | 89 | { |
---|
[815] | 90 | if (empty($_POST['groupname'])) |
---|
[21] | 91 | { |
---|
[5036] | 92 | array_push($page['errors'], l10n('The name of a group must not contain " or \' or be empty.')); |
---|
[21] | 93 | } |
---|
[815] | 94 | if (count($page['errors']) == 0) |
---|
[21] | 95 | { |
---|
| 96 | // is the group not already existing ? |
---|
[815] | 97 | $query = ' |
---|
| 98 | SELECT COUNT(*) |
---|
| 99 | FROM '.GROUPS_TABLE.' |
---|
| 100 | WHERE name = \''.$_POST['groupname'].'\' |
---|
| 101 | ;'; |
---|
[4325] | 102 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
[815] | 103 | if ($count != 0) |
---|
[21] | 104 | { |
---|
[5021] | 105 | array_push($page['errors'], l10n('This name is already used by another group.')); |
---|
[21] | 106 | } |
---|
| 107 | } |
---|
[815] | 108 | if (count($page['errors']) == 0) |
---|
[21] | 109 | { |
---|
| 110 | // creating the group |
---|
[704] | 111 | $query = ' |
---|
[815] | 112 | INSERT INTO '.GROUPS_TABLE.' |
---|
| 113 | (name) |
---|
[704] | 114 | VALUES |
---|
[4325] | 115 | (\''.pwg_db_real_escape_string($_POST['groupname']).'\') |
---|
[704] | 116 | ;'; |
---|
| 117 | pwg_query($query); |
---|
[815] | 118 | |
---|
| 119 | array_push( |
---|
| 120 | $page['infos'], |
---|
[5036] | 121 | sprintf(l10n('group "%s" added'), $_POST['groupname']) |
---|
[815] | 122 | ); |
---|
[704] | 123 | } |
---|
[623] | 124 | } |
---|
[21] | 125 | |
---|
[815] | 126 | // +-----------------------------------------------------------------------+ |
---|
[1583] | 127 | // | toggle is default group property | |
---|
| 128 | // +-----------------------------------------------------------------------+ |
---|
| 129 | |
---|
[1591] | 130 | if (isset($_GET['toggle_is_default']) and is_numeric($_GET['toggle_is_default']) and !is_adviser()) |
---|
[1583] | 131 | { |
---|
| 132 | $query = ' |
---|
| 133 | SELECT name, is_default |
---|
| 134 | FROM '.GROUPS_TABLE.' |
---|
| 135 | WHERE id = '.$_GET['toggle_is_default'].' |
---|
| 136 | ;'; |
---|
[4325] | 137 | list($groupname, $is_default) = pwg_db_fetch_row(pwg_query($query)); |
---|
[1583] | 138 | |
---|
| 139 | // update of the group |
---|
| 140 | $query = ' |
---|
| 141 | UPDATE '.GROUPS_TABLE.' |
---|
| 142 | SET is_default = \''.boolean_to_string(!get_boolean($is_default)).'\' |
---|
| 143 | WHERE id = '.$_GET['toggle_is_default'].' |
---|
| 144 | ;'; |
---|
| 145 | pwg_query($query); |
---|
| 146 | |
---|
| 147 | array_push( |
---|
| 148 | $page['infos'], |
---|
[5036] | 149 | sprintf(l10n('group "%s" updated'), $groupname) |
---|
[1583] | 150 | ); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | // +-----------------------------------------------------------------------+ |
---|
[815] | 154 | // | template init | |
---|
| 155 | // +-----------------------------------------------------------------------+ |
---|
[21] | 156 | |
---|
[2530] | 157 | $template->set_filenames(array('group_list' => 'group_list.tpl')); |
---|
[623] | 158 | |
---|
[2273] | 159 | $template->assign( |
---|
[815] | 160 | array( |
---|
[2273] | 161 | 'F_ADD_ACTION' => get_root_url().'admin.php?page=group_list', |
---|
| 162 | 'U_HELP' => get_root_url().'popuphelp.php?page=group_list', |
---|
[5195] | 163 | 'PWG_TOKEN' => get_pwg_token(), |
---|
[815] | 164 | ) |
---|
| 165 | ); |
---|
[623] | 166 | |
---|
[815] | 167 | // +-----------------------------------------------------------------------+ |
---|
| 168 | // | group list | |
---|
| 169 | // +-----------------------------------------------------------------------+ |
---|
| 170 | |
---|
| 171 | $query = ' |
---|
[1583] | 172 | SELECT id, name, is_default |
---|
[815] | 173 | FROM '.GROUPS_TABLE.' |
---|
[1960] | 174 | ORDER BY name ASC |
---|
[815] | 175 | ;'; |
---|
| 176 | $result = pwg_query($query); |
---|
| 177 | |
---|
[2273] | 178 | $admin_url = get_root_url().'admin.php?page='; |
---|
[815] | 179 | $perm_url = $admin_url.'group_perm&group_id='; |
---|
| 180 | $del_url = $admin_url.'group_list&delete='; |
---|
| 181 | $members_url = $admin_url.'user_list&group='; |
---|
[1583] | 182 | $toggle_is_default_url = $admin_url.'group_list&toggle_is_default='; |
---|
[815] | 183 | |
---|
[4325] | 184 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[623] | 185 | { |
---|
[815] | 186 | $query = ' |
---|
| 187 | SELECT COUNT(*) |
---|
| 188 | FROM '.USER_GROUP_TABLE.' |
---|
| 189 | WHERE group_id = '.$row['id'].' |
---|
| 190 | ;'; |
---|
[4325] | 191 | list($counter) = pwg_db_fetch_row(pwg_query($query)); |
---|
[815] | 192 | |
---|
[2273] | 193 | $template->append( |
---|
| 194 | 'groups', |
---|
[815] | 195 | array( |
---|
| 196 | 'NAME' => $row['name'], |
---|
[5021] | 197 | 'IS_DEFAULT' => (get_boolean($row['is_default']) ? ' ['.l10n('default').']' : ''), |
---|
[1932] | 198 | 'MEMBERS' => l10n_dec('%d member', '%d members', $counter), |
---|
[815] | 199 | 'U_MEMBERS' => $members_url.$row['id'], |
---|
[5195] | 200 | 'U_DELETE' => $del_url.$row['id'].'&pwg_token='.get_pwg_token(), |
---|
[1583] | 201 | 'U_PERM' => $perm_url.$row['id'], |
---|
[5195] | 202 | 'U_ISDEFAULT' => $toggle_is_default_url.$row['id'].'&pwg_token='.get_pwg_token(), |
---|
[815] | 203 | ) |
---|
| 204 | ); |
---|
[623] | 205 | } |
---|
| 206 | |
---|
[815] | 207 | // +-----------------------------------------------------------------------+ |
---|
| 208 | // | sending html code | |
---|
| 209 | // +-----------------------------------------------------------------------+ |
---|
| 210 | |
---|
| 211 | $template->assign_var_from_handle('ADMIN_CONTENT', 'group_list'); |
---|
| 212 | |
---|
[362] | 213 | ?> |
---|