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