028e8bae52eb1edd926f64e71c8196df323eac4f
[scuttle] / edit.php
1 <?php
2 /***************************************************************************
3 Copyright (C) 2004 - 2006 Scuttle project
4 http://sourceforge.net/projects/scuttle/
5 http://scuttle.org/
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 ***************************************************************************/
21
22 require_once('header.inc.php');
23
24 $bookmarkservice = & ServiceFactory :: getServiceInstance('BookmarkService');
25 $templateservice = & ServiceFactory :: getServiceInstance('TemplateService');
26 $userservice = & ServiceFactory :: 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 if (!($row = $bookmarkservice->getBookmark(intval($bookmark), true))) {
34     $tplVars['error'] = sprintf(T_('Bookmark with id %s not 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 }
93 ?>

Benjamin Mako Hill || Want to submit a patch?