2 /***************************************************************************
3 Copyright (c) 2004 - 2006 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 $bookmarkservice = & ServiceFactory::getServiceInstance('BookmarkService');
24 $templateservice = & ServiceFactory::getServiceInstance('TemplateService');
25 $userservice = & ServiceFactory::getServiceInstance('UserService');
28 $tplVars['subtitle'] = T_('Edit Bookmark');
29 $tplVars['loadjs'] = true;
31 list ($url, $bookmark) = explode('/', $_SERVER['PATH_INFO']);
32 if (!($row = $bookmarkservice->getBookmark(intval($bookmark), true))) {
33 $tplVars['error'] = sprintf(T_('Bookmark with id %s not was not found'), $bookmark);
34 $templateservice->loadTemplate('error.404.tpl', $tplVars);
37 if (!$bookmarkservice->editAllowed($row)) {
38 $tplVars['error'] = T_('You are not allowed to edit this bookmark');
39 $templateservice->loadTemplate('error.500.tpl', $tplVars);
41 } else if ($_POST['submitted']) {
42 if (!$_POST['title'] || !$_POST['address']) {
43 $tplVars['error'] = T_('Your bookmark must have a title and an address');
46 $bId = intval($bookmark);
47 $address = trim($_POST['address']);
48 $title = trim($_POST['title']);
49 $description = trim($_POST['description']);
50 $status = intval($_POST['status']);
51 $tags = trim($_POST['tags']);
52 $logged_on_user = $userservice->getCurrentUser();
53 if (!$bookmarkservice->updateBookmark($bId, $address, $title, $description, $status, $tags)) {
54 $tplvars['error'] = T_('Error while saving your bookmark');
56 if (isset($_POST['popup'])) {
57 $tplVars['msg'] = (isset($_POST['popup'])) ? '<script type="text/javascript">window.close();</script>' : T_('Bookmark saved');
58 } elseif (isset($_POST['referrer'])) {
59 header('Location: '. $_POST['referrer']);
61 header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
66 if ($_POST['delete']) {
68 if ($bookmarkservice->deleteBookmark($bookmark)) {
69 $logged_on_user = $userservice->getCurrentUser();
70 if (isset($_POST['referrer'])) {
71 header('Location: '. $_POST['referrer']);
73 header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
77 $tplVars['error'] = T_('Failed to delete the bookmark');
78 $templateservice->loadTemplate('error.500.tpl', $tplVars);
84 $tplVars['popup'] = (isset($_GET['popup'])) ? $_GET['popup'] : null;
85 $tplVars['row'] =& $row;
86 $tplVars['formaction'] = createURL('edit', $bookmark);
87 $tplVars['btnsubmit'] = T_('Save Changes');
88 $tplVars['showdelete'] = true;
89 $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
90 $templateservice->loadTemplate('editbookmark.tpl', $tplVars);