2 /***************************************************************************
3 Copyright (c) 2004 - 2006 Scuttle project
4 http://sourceforge.net/projects/scuttle/
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.
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.
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 ***************************************************************************/
22 require_once('header.inc.php');
24 $bookmarkservice = & ServiceFactory :: getServiceInstance('BookmarkService');
25 $templateservice = & ServiceFactory :: getServiceInstance('TemplateService');
26 $userservice = & ServiceFactory :: getServiceInstance('UserService');
29 $tplVars['subtitle'] = T_('Edit Bookmark');
30 $tplVars['loadjs'] = true;
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);
38 if (!$bookmarkservice->editAllowed($row)) {
39 $tplVars['error'] = T_('You are not allowed to edit this bookmark');
40 $templateservice->loadTemplate('error.500.tpl', $tplVars);
42 } else if ($_POST['submitted']) {
43 if (!$_POST['title'] || !$_POST['address']) {
44 $tplVars['error'] = T_('Your bookmark must have a title and an address');
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');
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']);
62 header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
67 if ($_POST['delete']) {
69 if ($bookmarkservice->deleteBookmark($bookmark)) {
70 $logged_on_user = $userservice->getCurrentUser();
71 if (isset($_POST['referrer'])) {
72 header('Location: '. $_POST['referrer']);
74 header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
78 $tplVars['error'] = T_('Failed to delete the bookmark');
79 $templateservice->loadTemplate('error.500.tpl', $tplVars);
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);