source: extensions/Copyrights/admin.php @ 28805

Last change on this file since 28805 was 12192, checked in by Mattias, 13 years ago

Fixed a small bug with single quotes in the copyright name
and some very small things

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