]> projects.mako.cc - scuttle/blob - edit.php
Added span's for the modified/original date fields so they can be styled
[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 $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
33 if (!($row = $bookmarkservice->getBookmark(intval($bookmark), true))) {
34     $tplVars['error'] = sprintf(T_('Bookmark with id %s was not found'), $bookmark);
35     $templateservice->loadTemplate('error.404.tpl', $tplVars);
36     exit();
37 } else {
38     if (!$bookmarkservice->editAllowed($row)) {
39         $tplVars['error'] = T_('You are not allowed to edit this bookmark');
40         $templateservice->loadTemplate('error.500.tpl', $tplVars);
41         exit();
42     } else if ($_POST['submitted']) {
43         if (!$_POST['title'] || !$_POST['address']) {
44             $tplVars['error'] = T_('Your bookmark must have a title and an address');
45         } else {
46             // Update bookmark
47             $bId = intval($bookmark);
48             $address = trim($_POST['address']);
49             $title = trim($_POST['title']);
50             $description = trim($_POST['description']);
51             $status = intval($_POST['status']);
52             $tags = trim($_POST['tags']);
53             $logged_on_user = $userservice->getCurrentUser();
54             if (!$bookmarkservice->updateBookmark($bId, $address, $title, $description, $status, $tags)) {
55                 $tplvars['error'] = T_('Error while saving your bookmark');
56             } else {
57                 if (isset($_POST['popup'])) {
58                     $tplVars['msg'] = (isset($_POST['popup'])) ? '<script type="text/javascript">window.close();</script>' : T_('Bookmark saved');
59                 } elseif (isset($_POST['referrer'])) {
60                     header('Location: '. $_POST['referrer']);
61                 } else {
62                     header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
63                 }
64             }
65         }
66     } else {
67         if ($_POST['delete']) {
68             // Delete bookmark
69             if ($bookmarkservice->deleteBookmark($bookmark)) {
70                 $logged_on_user = $userservice->getCurrentUser();
71                 if (isset($_POST['referrer'])) {
72                     header('Location: '. $_POST['referrer']);
73                 } else {
74                     header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
75                 }
76                 exit();
77             } else {
78                 $tplVars['error'] = T_('Failed to delete the bookmark');
79                 $templateservice->loadTemplate('error.500.tpl', $tplVars);
80                 exit();
81             }
82         }
83     }
84
85     $tplVars['popup'] = (isset($_GET['popup'])) ? $_GET['popup'] : null;
86     $tplVars['row'] =& $row;
87     $tplVars['formaction']  = createURL('edit', $bookmark);
88     $tplVars['btnsubmit'] = T_('Save Changes');
89     $tplVars['showdelete'] = true;
90     $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
91     $templateservice->loadTemplate('editbookmark.tpl', $tplVars);
92 }

Benjamin Mako Hill || Want to submit a patch?