1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
---|
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 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | if (!defined("PHPWG_ROOT_PATH")){ |
---|
25 | die("Hacking attempt!"); |
---|
26 | } |
---|
27 | |
---|
28 | global $prefixeTable; |
---|
29 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
30 | load_language('plugin.lang', E_AUTHOR_PATH); |
---|
31 | |
---|
32 | // Check access and exit when user status is not ok |
---|
33 | check_status(ACCESS_ADMINISTRATOR); |
---|
34 | |
---|
35 | // Default is to create an author, if changed to 1, show the edit page |
---|
36 | $edit = 0; |
---|
37 | |
---|
38 | // The values for the form fields |
---|
39 | $EAid = 0; |
---|
40 | $EAname = ''; |
---|
41 | $EAcode = ''; |
---|
42 | $EAurl = ''; |
---|
43 | $EAdescr = ''; |
---|
44 | $EAcopyright_id = ''; // The default should be 0, but this equals 0, doesnt it? |
---|
45 | |
---|
46 | // Fetch all the copyrights and assign them to the template |
---|
47 | $query = sprintf( |
---|
48 | 'SELECT `cr_id`,`name` |
---|
49 | FROM %s |
---|
50 | WHERE `visible`<>0 |
---|
51 | AND cr_id <> -1 |
---|
52 | ORDER BY cr_id ASC |
---|
53 | ;', |
---|
54 | COPYRIGHTS_ADMIN); |
---|
55 | $result = pwg_query($query); |
---|
56 | $EAcopyrights = array(); |
---|
57 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
58 | $EAcopyrights[$row['cr_id']] = $row['name']; |
---|
59 | } |
---|
60 | $template->assign('EAcopyrights', $EAcopyrights); |
---|
61 | |
---|
62 | // Do managing of authors |
---|
63 | if (isset($_GET['tab'])) { |
---|
64 | // Create a new author |
---|
65 | if ($_GET['tab'] == 'create') { |
---|
66 | // Fetch the values from the form |
---|
67 | $name = pwg_db_real_escape_string($_REQUEST['name']); |
---|
68 | $code = pwg_db_real_escape_string($_REQUEST['code']); |
---|
69 | $url = pwg_db_real_escape_string($_REQUEST['url']); |
---|
70 | $descr = pwg_db_real_escape_string($_REQUEST['descr']); |
---|
71 | $copyright = pwg_db_real_escape_string($_REQUEST['copyrightID']); |
---|
72 | |
---|
73 | // Check whether an author with such a name or code exists |
---|
74 | // Therefore count the number of authors with that name or code |
---|
75 | $query = sprintf( |
---|
76 | 'SELECT COUNT(*) |
---|
77 | FROM %s |
---|
78 | WHERE `name` = \'%s\' |
---|
79 | OR `code` = \'%s\' |
---|
80 | ;', |
---|
81 | AUTHORS, $name, $code); |
---|
82 | $result = pwg_query($query); |
---|
83 | $counter = pwg_db_num_rows($result); |
---|
84 | |
---|
85 | if ($counter != 0) { |
---|
86 | // The author exists already |
---|
87 | array_push($page['errors'], l10n('This author already exists.')); |
---|
88 | } else { |
---|
89 | // The author did not yet exist |
---|
90 | // Compose a query to insert the author |
---|
91 | $query = sprintf( |
---|
92 | 'INSERT INTO %s |
---|
93 | (`name`,`code`,`url`,`descr`,`copyright`) VALUES |
---|
94 | ("%s","%s","%s","%s",%d) |
---|
95 | ;', |
---|
96 | AUTHORS, $name, $code, $url, $descr, $copyright); |
---|
97 | pwg_query($query); // Execute the query |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | // Edit an existing author |
---|
102 | if ($_GET['tab'] == 'edit') { |
---|
103 | $edit = 1; // Show the edit page |
---|
104 | $EAid = $_REQUEST['id']; // Fetch the id of the author to be edited |
---|
105 | |
---|
106 | // Fetch the current attributes to the author |
---|
107 | $query = sprintf( |
---|
108 | 'SELECT * |
---|
109 | FROM %s |
---|
110 | WHERE `author_id`=%d |
---|
111 | ;', |
---|
112 | AUTHORS, $EAid); |
---|
113 | $result = pwg_query($query); |
---|
114 | $row = pwg_db_fetch_assoc($result); |
---|
115 | |
---|
116 | // Save the attributes in convenient variables |
---|
117 | $EAname = $row['name']; |
---|
118 | $EAcode = $row['code']; |
---|
119 | $EAurl = $row['url']; |
---|
120 | $EAdescr = $row['descr']; |
---|
121 | $EAcopyright_id = $row['copyright']; |
---|
122 | } |
---|
123 | |
---|
124 | // Update an existing author |
---|
125 | if ($_GET['tab'] == 'update') { |
---|
126 | // Fetch the values from the edit form |
---|
127 | $id = pwg_db_real_escape_string($_REQUEST['id']); |
---|
128 | $name = pwg_db_real_escape_string($_REQUEST['name']); |
---|
129 | $code = pwg_db_real_escape_string($_REQUEST['code']); |
---|
130 | $url = pwg_db_real_escape_string($_REQUEST['url']); |
---|
131 | $descr = pwg_db_real_escape_string($_REQUEST['descr']); |
---|
132 | $copyright = pwg_db_real_escape_string($_REQUEST['copyrightID']); |
---|
133 | |
---|
134 | // Check whether an author with such a name or code exists |
---|
135 | // Therefore count the number of authors with that name or code |
---|
136 | $query = sprintf( |
---|
137 | 'SELECT COUNT(*) |
---|
138 | FROM %s |
---|
139 | WHERE `name` = \'%s\' |
---|
140 | OR `code` = \'%s\' |
---|
141 | ;', |
---|
142 | AUTHORS, $name, $code); |
---|
143 | $result = pwg_query($query); |
---|
144 | $counter = pwg_db_num_rows($result); |
---|
145 | |
---|
146 | if ($counter != 0) { |
---|
147 | // The author exists already |
---|
148 | array_push($page['errors'], l10n('This author already exists.')); |
---|
149 | } else { |
---|
150 | // The author did not yet exist |
---|
151 | // Compose a query to update the author |
---|
152 | $query = sprintf( |
---|
153 | 'UPDATE %s |
---|
154 | SET `name`="%s", `code`="%s", `url`="%s", `descr`="%s", `copyright`=%d |
---|
155 | WHERE `author_id`=%d |
---|
156 | ;', |
---|
157 | AUTHORS, $name, $code, $url, $descr, $copyright, $id); |
---|
158 | pwg_query($query); // Execute the query |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | // Delete an existing author |
---|
163 | if ($_GET['tab'] == 'delete') { |
---|
164 | // Fetch the id of the author to be deleted |
---|
165 | $id = $_REQUEST['id']; |
---|
166 | |
---|
167 | // Get the author's name |
---|
168 | $query = sprintf( |
---|
169 | 'SELECT name |
---|
170 | FROM %s |
---|
171 | WHERE author_id=%d |
---|
172 | ;', |
---|
173 | AUTHORS, $id); |
---|
174 | $result = pwg_query($query); |
---|
175 | $row = pwg_db_fetch_assoc($result); |
---|
176 | $name = $row['name']; |
---|
177 | |
---|
178 | // Delete all his 'default' entries from the copyright table |
---|
179 | delete_default_CR($name); |
---|
180 | |
---|
181 | // Unset the author in the images table |
---|
182 | $query = sprintf( |
---|
183 | 'UPDATE %s |
---|
184 | SET `author`=NULL |
---|
185 | WHERE `author`=\'%s\' |
---|
186 | ;', |
---|
187 | IMAGES, $name); |
---|
188 | pwg_query($query); |
---|
189 | |
---|
190 | // Delete the author |
---|
191 | $query = sprintf( |
---|
192 | 'DELETE FROM %s |
---|
193 | WHERE `author_id`=%d |
---|
194 | ;', |
---|
195 | AUTHORS, $id); |
---|
196 | pwg_query($query); |
---|
197 | } |
---|
198 | } |
---|
199 | |
---|
200 | /* Assign variables to the template */ |
---|
201 | global $template; |
---|
202 | |
---|
203 | // Add the admin.tpl template |
---|
204 | $template->set_filenames( |
---|
205 | array('plugin_admin_content' => dirname(__FILE__).'/admin.tpl') |
---|
206 | ); |
---|
207 | |
---|
208 | // Select the existing authors |
---|
209 | $query = sprintf( |
---|
210 | 'SELECT * |
---|
211 | FROM %s |
---|
212 | ;', |
---|
213 | AUTHORS); |
---|
214 | $result = pwg_query($query); |
---|
215 | |
---|
216 | // Append the authors to the Smarty array |
---|
217 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
218 | $template->append( |
---|
219 | 'EAs', |
---|
220 | array( |
---|
221 | 'author_id' => $row['author_id'], |
---|
222 | 'name' => $row['name'], |
---|
223 | 'code' => $row['code'], |
---|
224 | 'url' => $row['url'], |
---|
225 | 'descr' => $row['descr'], |
---|
226 | 'copyright_id' => $row['copyright'] |
---|
227 | ) |
---|
228 | ); |
---|
229 | } |
---|
230 | |
---|
231 | // Assign the path for URL forming |
---|
232 | $template->assign( |
---|
233 | 'E_AUTHOR_PATH', |
---|
234 | E_AUTHOR_WEB_PATH |
---|
235 | ); |
---|
236 | |
---|
237 | // Assign all the variables we constructed above |
---|
238 | $template->assign('edit', $edit); |
---|
239 | $template->assign('EAid', $EAid); |
---|
240 | $template->assign('EAname', $EAname); |
---|
241 | $template->assign('EAcode', $EAcode); |
---|
242 | $template->assign('EAurl', $EAurl); |
---|
243 | $template->assign('EAdescr', $EAdescr); |
---|
244 | $template->assign('EAcopyright_id', $EAcopyright_id); |
---|
245 | |
---|
246 | // Get it up and running |
---|
247 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
248 | |
---|
249 | ?> |
---|