- Enforce minimum elapsed time on registration form
[scuttle] / edit.php
1 <?php
2 /***************************************************************************
3 Copyright (c) 2004 - 2006 Marcus Campbell
4 http://scuttle.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 ***************************************************************************/
20
21 require_once 'header.inc.php';
22
23 $bookmarkservice = & ServiceFactory::getServiceInstance('BookmarkService');
24 $templateservice = & ServiceFactory::getServiceInstance('TemplateService');
25 $userservice     = & ServiceFactory::getServiceInstance('UserService');
26
27 // Header variables
28 $tplVars['subtitle'] = T_('Edit Bookmark');
29 $tplVars['loadjs'] = true;
30
31 list ($url, $bookmark) = explode('/', $_SERVER['PATH_INFO']);
32 if (!($row = $bookmarkservice->getBookmark(intval($bookmark), true))) {
33     $tplVars['error'] = sprintf(T_('Bookmark with id %s not was not found'), $bookmark);
34     $templateservice->loadTemplate('error.404.tpl', $tplVars);
35     exit();
36 } else {
37     if (!$bookmarkservice->editAllowed($row)) {
38         $tplVars['error'] = T_('You are not allowed to edit this bookmark');
39         $templateservice->loadTemplate('error.500.tpl', $tplVars);
40         exit();
41     } else if ($_POST['submitted']) {
42         if (!$_POST['title'] || !$_POST['address']) {
43             $tplVars['error'] = T_('Your bookmark must have a title and an address');
44         } else {
45             // Update bookmark
46             $bId = intval($bookmark);
47             $address = trim($_POST['address']);
48             $title = trim($_POST['title']);
49             $description = trim($_POST['description']);
50             $status = intval($_POST['status']);
51             $tags = trim($_POST['tags']);
52             $logged_on_user = $userservice->getCurrentUser();
53             if (!$bookmarkservice->updateBookmark($bId, $address, $title, $description, $status, $tags)) {
54                 $tplvars['error'] = T_('Error while saving your bookmark');
55             } else {
56                 if (isset($_POST['popup'])) {
57                     $tplVars['msg'] = (isset($_POST['popup'])) ? '<script type="text/javascript">window.close();</script>' : T_('Bookmark saved');
58                 } elseif (isset($_POST['referrer'])) {
59                     header('Location: '. $_POST['referrer']);
60                 } else {
61                     header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
62                 }
63             }
64         }
65     } else {
66         if ($_POST['delete']) {
67             // Delete bookmark
68             if ($bookmarkservice->deleteBookmark($bookmark)) {
69                 $logged_on_user = $userservice->getCurrentUser();
70                 if (isset($_POST['referrer'])) {
71                     header('Location: '. $_POST['referrer']);
72                 } else {
73                     header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
74                 }
75                 exit();
76             } else {
77                 $tplVars['error'] = T_('Failed to delete the bookmark');
78                 $templateservice->loadTemplate('error.500.tpl', $tplVars);
79                 exit();
80             }
81         }
82     }
83
84     $tplVars['popup'] = (isset($_GET['popup'])) ? $_GET['popup'] : null;
85     $tplVars['row'] =& $row;
86     $tplVars['formaction']  = createURL('edit', $bookmark);
87     $tplVars['btnsubmit'] = T_('Save Changes');
88     $tplVars['showdelete'] = true;
89     $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
90     $templateservice->loadTemplate('editbookmark.tpl', $tplVars);
91 }
92 ?>

Benjamin Mako Hill || Want to submit a patch?