[10874] | 1 | <?php |
---|
[10931] | 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[12192] | 5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
---|
[10931] | 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 | // +-----------------------------------------------------------------------+ |
---|
[10874] | 23 | |
---|
| 24 | if (!defined("PHPWG_ROOT_PATH")){ |
---|
| 25 | die("Hacking attempt!"); |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
[11268] | 29 | load_language('plugin.lang', COPYRIGHTS_PATH); |
---|
[10874] | 30 | |
---|
| 31 | // Check access and exit when user status is not ok |
---|
| 32 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 33 | |
---|
[11656] | 34 | // Default is to create a copyright, if changed to 1, show the edit page |
---|
[10874] | 35 | $edit = 0; |
---|
| 36 | |
---|
| 37 | // The values for the form fields |
---|
| 38 | $CRid = 0; |
---|
| 39 | $CRname = ''; |
---|
| 40 | $CRurl = ''; |
---|
[11084] | 41 | $CRdescr = ''; |
---|
[10874] | 42 | $CRvisible = 0; |
---|
| 43 | |
---|
| 44 | // Do managing of copyrights |
---|
| 45 | if (isset($_GET['tab'])) { |
---|
[11656] | 46 | // Create a new copyright |
---|
[10874] | 47 | if ($_GET['tab'] == 'create') { |
---|
[11656] | 48 | // Fetch the values from the form |
---|
[10931] | 49 | $name = pwg_db_real_escape_string($_REQUEST['name']); |
---|
| 50 | $url = pwg_db_real_escape_string($_REQUEST['url']); |
---|
[11084] | 51 | $descr = pwg_db_real_escape_string($_REQUEST['descr']); |
---|
[10874] | 52 | $visible = (isset($_REQUEST['visible']) ? 1 : 0); |
---|
[11656] | 53 | |
---|
| 54 | // Check whether a copyright with such a name exists |
---|
| 55 | // Therefore count the number of copyrights with that name |
---|
[10931] | 56 | $query = sprintf( |
---|
[11625] | 57 | 'SELECT COUNT(*) |
---|
| 58 | FROM %s |
---|
[11635] | 59 | WHERE `name` = \'%s\' |
---|
[10931] | 60 | ;', |
---|
[11625] | 61 | COPYRIGHTS_ADMIN, $name); |
---|
| 62 | list($counter) = pwg_db_fetch_row(pwg_query($query)); |
---|
[11656] | 63 | |
---|
| 64 | if ($counter != 0) { // The copyright exists already |
---|
[11675] | 65 | array_push($page['errors'], l10n('This copyright already exists.')); |
---|
[11656] | 66 | } else { // The copyright did not yet exist |
---|
| 67 | // Compose a query to insert the copyright |
---|
[11625] | 68 | $query = sprintf( |
---|
| 69 | 'INSERT INTO %s |
---|
| 70 | (`name`,`url`,`descr`,`visible`) VALUES |
---|
| 71 | ("%s","%s","%s",%d) |
---|
| 72 | ;', |
---|
| 73 | COPYRIGHTS_ADMIN, $name, $url, $descr, $visible); |
---|
[11656] | 74 | pwg_query($query); // Execute the query |
---|
[11625] | 75 | } |
---|
[10874] | 76 | } |
---|
| 77 | |
---|
[11656] | 78 | // Edit an existing copyright |
---|
[10874] | 79 | if ($_GET['tab'] == 'edit') { |
---|
[11656] | 80 | $edit = 1; // Show the edit page |
---|
| 81 | $CRid = $_REQUEST['id']; // Fetch the id of the copyright to be edited |
---|
| 82 | |
---|
| 83 | // Fetch the current attributes to the copyright |
---|
[10931] | 84 | $query = sprintf( |
---|
| 85 | 'SELECT * |
---|
| 86 | FROM %s |
---|
| 87 | WHERE `cr_id`=%d |
---|
| 88 | ;', |
---|
| 89 | COPYRIGHTS_ADMIN, $CRid); |
---|
[10874] | 90 | $result = pwg_query($query); |
---|
| 91 | $row = pwg_db_fetch_assoc($result); |
---|
[11656] | 92 | |
---|
| 93 | // Save the attributes in convenient variables |
---|
[10874] | 94 | $CRname = $row['name']; |
---|
| 95 | $CRurl = $row['url']; |
---|
[11084] | 96 | $CRdescr = $row['descr']; |
---|
[10874] | 97 | $CRvisible = $row['visible']; |
---|
| 98 | } |
---|
| 99 | |
---|
[11656] | 100 | // Update an existing copyright |
---|
[10874] | 101 | if ($_GET['tab'] == 'update') { |
---|
[11656] | 102 | // Fetch the values from the edit form |
---|
[10931] | 103 | $id = pwg_db_real_escape_string($_REQUEST['id']); |
---|
| 104 | $name = pwg_db_real_escape_string($_REQUEST['name']); |
---|
| 105 | $url = pwg_db_real_escape_string($_REQUEST['url']); |
---|
[11084] | 106 | $descr= pwg_db_real_escape_string($_REQUEST['descr']); |
---|
[10874] | 107 | $visible = (isset($_REQUEST['visible']) ? 1 : 0); |
---|
[11656] | 108 | |
---|
| 109 | // Compose a query to update the copyright |
---|
[10931] | 110 | $query = sprintf( |
---|
| 111 | 'UPDATE %s |
---|
[11084] | 112 | SET `name`="%s", `url`="%s", `descr`="%s", `visible`=%d |
---|
[10931] | 113 | WHERE `cr_id`=%d |
---|
| 114 | ;', |
---|
[11084] | 115 | COPYRIGHTS_ADMIN, $name, $url, $descr, $visible, $id); |
---|
[11656] | 116 | pwg_query($query); // Execute the query |
---|
[10874] | 117 | } |
---|
[11656] | 118 | |
---|
| 119 | // Delete an existing copyright |
---|
[10874] | 120 | if ($_GET['tab'] == 'delete') { |
---|
[11656] | 121 | $id = $_REQUEST['id']; // Fetch the id of the copyright to be deleted |
---|
| 122 | |
---|
| 123 | // Compose a query to delete the copyright |
---|
[10931] | 124 | $query = sprintf( |
---|
| 125 | 'DELETE FROM %s |
---|
| 126 | WHERE `cr_id`=%d |
---|
| 127 | ;', |
---|
| 128 | COPYRIGHTS_ADMIN, $id); |
---|
[11656] | 129 | pwg_query($query); // Execute the query |
---|
[10874] | 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
[11656] | 133 | /* Assign variables to the template */ |
---|
[10874] | 134 | global $template; |
---|
| 135 | |
---|
[11656] | 136 | // Add the admin.tpl template |
---|
[10874] | 137 | $template->set_filenames( |
---|
| 138 | array( |
---|
| 139 | 'plugin_admin_content' => dirname(__FILE__).'/admin.tpl' |
---|
| 140 | ) |
---|
| 141 | ); |
---|
| 142 | |
---|
[11656] | 143 | // Select the existing copyrights |
---|
[10931] | 144 | $query = sprintf( |
---|
| 145 | 'SELECT * |
---|
| 146 | FROM %s |
---|
[11794] | 147 | WHERE cr_id <> -1 |
---|
| 148 | ORDER BY cr_id ASC |
---|
[10931] | 149 | ;', |
---|
[11084] | 150 | COPYRIGHTS_ADMIN); |
---|
[10874] | 151 | $result = pwg_query($query); |
---|
| 152 | |
---|
[11656] | 153 | // Append the copyrights to the Smarty array |
---|
[10874] | 154 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
| 155 | $template->append( |
---|
| 156 | 'CRs', |
---|
| 157 | array( |
---|
| 158 | 'cr_id' => $row['cr_id'], |
---|
| 159 | 'name' => $row['name'], |
---|
| 160 | 'url' => $row['url'], |
---|
[11084] | 161 | 'descr' => $row['descr'], |
---|
[10874] | 162 | 'visible' => $row['visible'] |
---|
| 163 | ) |
---|
| 164 | ); |
---|
| 165 | } |
---|
| 166 | |
---|
[11656] | 167 | // Assign the path for URL forming |
---|
[10874] | 168 | $template->assign( |
---|
| 169 | 'COPYRIGHTS_PATH', |
---|
| 170 | COPYRIGHTS_WEB_PATH |
---|
| 171 | ); |
---|
| 172 | |
---|
[11656] | 173 | // Assign all the variables we constructed above |
---|
[10874] | 174 | $template->assign('edit', $edit); |
---|
| 175 | $template->assign('CRid', $CRid); |
---|
| 176 | $template->assign('CRname', $CRname); |
---|
| 177 | $template->assign('CRurl', $CRurl); |
---|
[11084] | 178 | $template->assign('CRdescr', $CRdescr); |
---|
[10874] | 179 | $template->assign('CRvisible', $CRvisible); |
---|
| 180 | |
---|
[11656] | 181 | // Get it up and running |
---|
[10874] | 182 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 183 | |
---|
| 184 | ?> |
---|