2 /***************************************************************************
3 Copyright (c) 2004 - 2010 Marcus Campbell
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.
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.
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 ***************************************************************************/
21 require_once 'header.inc.php';
23 $sf = new ServiceFactory();
24 $bookmarkservice =& $sf->getServiceInstance('BookmarkService');
25 $templateservice =& $sf->getServiceInstance('TemplateService');
26 $userservice =& $sf->getServiceInstance('UserService');
29 $tplVars['subtitle'] = T_('Edit Bookmark');
30 $tplVars['loadjs'] = TRUE;
32 list ($url, $bookmark) = explode('/', $_SERVER['PATH_INFO']);
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);
39 if (!$bookmarkservice->editAllowed($row)) {
40 $tplVars['error'] = T_('You are not allowed to edit this bookmark');
41 $templateservice->loadTemplate('error.500.tpl', $tplVars);
43 } else if ($_POST['submitted']) {
44 if (!$_POST['title'] || !$_POST['address']) {
45 $tplVars['error'] = T_('Your bookmark must have a title and an address');
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');
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']);
63 header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
68 if ($_POST['delete']) {
70 if ($bookmarkservice->deleteBookmark($bookmark)) {
71 $logged_on_user = $userservice->getCurrentUser();
72 if (isset($_POST['referrer'])) {
73 header('Location: '. $_POST['referrer']);
75 header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
79 $tplVars['error'] = T_('Failed to delete the bookmark');
80 $templateservice->loadTemplate('error.500.tpl', $tplVars);
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);