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