]> projects.mako.cc - scuttle/blob - edit.php
Merge branch 'php8'
[scuttle] / edit.php
1 <?php
2 /***************************************************************************
3 Copyright (c) 2004 - 2010 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 $sf = new ServiceFactory();
24 $bookmarkservice =& $sf->getServiceInstance('BookmarkService');
25 $templateservice =& $sf->getServiceInstance('TemplateService');
26 $userservice     =& $sf->getServiceInstance('UserService');
27
28 // Header variables
29 $tplVars['subtitle'] = T_('Edit Bookmark');
30 $tplVars['loadjs']   = TRUE;
31
32 list ($url, $bookmark) = explode('/', $_SERVER['PATH_INFO']);
33
34 if (!($row = $bookmarkservice->getBookmark(intval($bookmark), true))) {
35     $tplVars['error'] = sprintf(T_('Bookmark with id %s was not found'), $bookmark);
36     $templateservice->loadTemplate('error.404.tpl', $tplVars);
37     exit();
38 } else {
39     if (!$bookmarkservice->editAllowed($row)) {
40         $tplVars['error'] = T_('You are not allowed to edit this bookmark');
41         $templateservice->loadTemplate('error.500.tpl', $tplVars);
42         exit();
43     } else if ($_POST['submitted']) {
44         if (!$_POST['title'] || !$_POST['address']) {
45             $tplVars['error'] = T_('Your bookmark must have a title and an address');
46         } else {
47             // Update bookmark
48             $bId = intval($bookmark);
49             $address = trim($_POST['address']);
50             $title = trim($_POST['title']);
51             $description = trim($_POST['description']);
52             $status = intval($_POST['status']);
53             $tags = trim($_POST['tags']);
54             $logged_on_user = $userservice->getCurrentUser();
55             if (!$bookmarkservice->updateBookmark($bId, $address, $title, $description, $status, $tags)) {
56                 $tplvars['error'] = T_('Error while saving your bookmark');
57             } else {
58                 if (isset($_POST['popup'])) {
59                     $tplVars['msg'] = (isset($_POST['popup'])) ? '<script type="text/javascript">window.close();</script>' : T_('Bookmark saved');
60                 } elseif (isset($_POST['referrer'])) {
61                     header('Location: '. $_POST['referrer']);
62                 } else {
63                     header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
64                 }
65             }
66         }
67     } else {
68         if ($_POST['delete']) {
69             // Delete bookmark
70             if ($bookmarkservice->deleteBookmark($bookmark)) {
71                 $logged_on_user = $userservice->getCurrentUser();
72                 if (isset($_POST['referrer'])) {
73                     header('Location: '. $_POST['referrer']);
74                 } else {
75                     header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
76                 }
77                 exit();
78             } else {
79                 $tplVars['error'] = T_('Failed to delete the bookmark');
80                 $templateservice->loadTemplate('error.500.tpl', $tplVars);
81                 exit();
82             }
83         }
84     }
85
86     $tplVars['popup'] = (isset($_GET['popup'])) ? $_GET['popup'] : null;
87     $tplVars['row'] =& $row;
88     $tplVars['formaction']  = createURL('edit', $bookmark);
89     $tplVars['btnsubmit'] = T_('Save Changes');
90     $tplVars['showdelete'] = true;
91     $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
92     $templateservice->loadTemplate('editbookmark.tpl', $tplVars);
93 }

Benjamin Mako Hill || Want to submit a patch?