[21] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[675] | 5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[362] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[362] | 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2005-08-16 15:19:40 +0000 (Tue, 16 Aug 2005) $ |
---|
| 10 | // | last modifier : $Author: plg $ |
---|
| 11 | // | revision : $Revision: 815 $ |
---|
| 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 | // +-----------------------------------------------------------------------+ |
---|
[815] | 27 | |
---|
[623] | 28 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
| 29 | { |
---|
[815] | 30 | die ("Hacking attempt!"); |
---|
[623] | 31 | } |
---|
| 32 | include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' ); |
---|
| 33 | |
---|
[815] | 34 | // +-----------------------------------------------------------------------+ |
---|
| 35 | // | delete a group | |
---|
| 36 | // +-----------------------------------------------------------------------+ |
---|
| 37 | |
---|
| 38 | if (isset($_GET['delete']) and is_numeric($_GET['delete'])) |
---|
[21] | 39 | { |
---|
[631] | 40 | // destruction of the access linked to the group |
---|
[815] | 41 | $query = ' |
---|
| 42 | DELETE |
---|
| 43 | FROM '.GROUP_ACCESS_TABLE.' |
---|
| 44 | WHERE group_id = '.$_GET['delete'].' |
---|
| 45 | ;'; |
---|
| 46 | pwg_query($query); |
---|
| 47 | |
---|
| 48 | // destruction of the users links for this group |
---|
| 49 | $query = ' |
---|
| 50 | DELETE |
---|
| 51 | FROM '.USER_GROUP_TABLE.' |
---|
| 52 | WHERE group_id = '.$_GET['delete'].' |
---|
| 53 | ;'; |
---|
| 54 | pwg_query($query); |
---|
| 55 | |
---|
| 56 | $query = ' |
---|
| 57 | SELECT name |
---|
| 58 | FROM '.GROUPS_TABLE.' |
---|
| 59 | WHERE id = '.$_GET['delete'].' |
---|
| 60 | ;'; |
---|
| 61 | list($groupname) = mysql_fetch_row(pwg_query($query)); |
---|
| 62 | |
---|
| 63 | // destruction of the group |
---|
| 64 | $query = ' |
---|
| 65 | DELETE |
---|
| 66 | FROM '.GROUPS_TABLE.' |
---|
| 67 | WHERE id = '.$_GET['delete'].' |
---|
| 68 | ;'; |
---|
| 69 | pwg_query($query); |
---|
| 70 | |
---|
| 71 | array_push( |
---|
| 72 | $page['infos'], |
---|
| 73 | sprintf(l10n('group "%s" deleted'), $groupname) |
---|
| 74 | ); |
---|
[21] | 75 | } |
---|
[815] | 76 | |
---|
| 77 | // +-----------------------------------------------------------------------+ |
---|
| 78 | // | add a group | |
---|
| 79 | // +-----------------------------------------------------------------------+ |
---|
| 80 | |
---|
| 81 | if (isset($_POST['submit_add'])) |
---|
[21] | 82 | { |
---|
[815] | 83 | if (empty($_POST['groupname'])) |
---|
[21] | 84 | { |
---|
[815] | 85 | array_push($page['errors'], $lang['group_add_error1']); |
---|
[21] | 86 | } |
---|
[815] | 87 | if (count($page['errors']) == 0) |
---|
[21] | 88 | { |
---|
| 89 | // is the group not already existing ? |
---|
[815] | 90 | $query = ' |
---|
| 91 | SELECT COUNT(*) |
---|
| 92 | FROM '.GROUPS_TABLE.' |
---|
| 93 | WHERE name = \''.$_POST['groupname'].'\' |
---|
| 94 | ;'; |
---|
| 95 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
| 96 | if ($count != 0) |
---|
[21] | 97 | { |
---|
[815] | 98 | array_push($page['errors'], $lang['group_add_error2']); |
---|
[21] | 99 | } |
---|
| 100 | } |
---|
[815] | 101 | if (count($page['errors']) == 0) |
---|
[21] | 102 | { |
---|
| 103 | // creating the group |
---|
[704] | 104 | $query = ' |
---|
[815] | 105 | INSERT INTO '.GROUPS_TABLE.' |
---|
| 106 | (name) |
---|
[704] | 107 | VALUES |
---|
[815] | 108 | (\''.mysql_escape_string($_POST['groupname']).'\') |
---|
[704] | 109 | ;'; |
---|
| 110 | pwg_query($query); |
---|
[815] | 111 | |
---|
| 112 | array_push( |
---|
| 113 | $page['infos'], |
---|
| 114 | sprintf(l10n('group "%s" added'), $_POST['groupname']) |
---|
| 115 | ); |
---|
[704] | 116 | } |
---|
[623] | 117 | } |
---|
[21] | 118 | |
---|
[815] | 119 | // +-----------------------------------------------------------------------+ |
---|
| 120 | // | template init | |
---|
| 121 | // +-----------------------------------------------------------------------+ |
---|
[21] | 122 | |
---|
[815] | 123 | $template->set_filenames(array('group_list' => 'admin/group_list.tpl')); |
---|
[623] | 124 | |
---|
[815] | 125 | $template->assign_vars( |
---|
| 126 | array( |
---|
| 127 | 'F_ADD_ACTION' => |
---|
| 128 | add_session_id(PHPWG_ROOT_PATH.'admin.php?page=group_list') |
---|
| 129 | ) |
---|
| 130 | ); |
---|
[623] | 131 | |
---|
[815] | 132 | // +-----------------------------------------------------------------------+ |
---|
| 133 | // | group list | |
---|
| 134 | // +-----------------------------------------------------------------------+ |
---|
| 135 | |
---|
| 136 | $query = ' |
---|
| 137 | SELECT id, name |
---|
| 138 | FROM '.GROUPS_TABLE.' |
---|
| 139 | ORDER BY id ASC |
---|
| 140 | ;'; |
---|
| 141 | $result = pwg_query($query); |
---|
| 142 | |
---|
| 143 | $admin_url = PHPWG_ROOT_PATH.'admin.php?page='; |
---|
| 144 | $perm_url = $admin_url.'group_perm&group_id='; |
---|
| 145 | $del_url = $admin_url.'group_list&delete='; |
---|
| 146 | $members_url = $admin_url.'user_list&group='; |
---|
| 147 | |
---|
| 148 | $num = 0; |
---|
| 149 | while ($row = mysql_fetch_array($result)) |
---|
[623] | 150 | { |
---|
[815] | 151 | $query = ' |
---|
| 152 | SELECT COUNT(*) |
---|
| 153 | FROM '.USER_GROUP_TABLE.' |
---|
| 154 | WHERE group_id = '.$row['id'].' |
---|
| 155 | ;'; |
---|
| 156 | list($counter) = mysql_fetch_row(pwg_query($query)); |
---|
| 157 | |
---|
| 158 | $template->assign_block_vars( |
---|
| 159 | 'group', |
---|
| 160 | array( |
---|
| 161 | 'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1', |
---|
| 162 | 'NAME' => $row['name'], |
---|
| 163 | 'MEMBERS' => sprintf(l10n('%d members'), $counter), |
---|
| 164 | 'U_MEMBERS' => $members_url.$row['id'], |
---|
| 165 | 'U_DELETE' => $del_url.$row['id'], |
---|
| 166 | 'U_PERM' => $perm_url.$row['id'] |
---|
| 167 | ) |
---|
| 168 | ); |
---|
[623] | 169 | } |
---|
| 170 | |
---|
[815] | 171 | // +-----------------------------------------------------------------------+ |
---|
| 172 | // | sending html code | |
---|
| 173 | // +-----------------------------------------------------------------------+ |
---|
| 174 | |
---|
| 175 | $template->assign_var_from_handle('ADMIN_CONTENT', 'group_list'); |
---|
| 176 | |
---|
[362] | 177 | ?> |
---|