| 1 | <?php |
|---|
| 2 | /*
|
|---|
| 3 |
|
|---|
| 4 | This file is part of omCollab.
|
|---|
| 5 |
|
|---|
| 6 | Copyright (c) 2008 omCollab (Openmethodology Project)
|
|---|
| 7 | http://www.openmethodology.org
|
|---|
| 8 | http://mike2.openmethodology.org/wiki/OmCollab
|
|---|
| 9 |
|
|---|
| 10 | And parts copyright of Scuttle project
|
|---|
| 11 | (http://sourceforge.net/projects/scuttle/, http://scuttle.org/)
|
|---|
| 12 |
|
|---|
| 13 | omCollab is free software: you can redistribute it and/or modify
|
|---|
| 14 | it under the terms of the GNU General Public License as published by
|
|---|
| 15 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 16 | (at your option) any later version.
|
|---|
| 17 |
|
|---|
| 18 | omCollab is distributed in the hope that it will be useful,
|
|---|
| 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 21 | GNU General Public License for more details.
|
|---|
| 22 |
|
|---|
| 23 | */
|
|---|
| 24 |
|
|---|
| 25 | require_once('header.inc.php'); |
|---|
| 26 | |
|---|
| 27 | $bookmarkservice = & ServiceFactory :: getServiceInstance('BookmarkService'); |
|---|
| 28 | $templateservice = & ServiceFactory :: getServiceInstance('TemplateService'); |
|---|
| 29 | $userservice = & ServiceFactory :: getServiceInstance('UserService'); |
|---|
| 30 | |
|---|
| 31 | // Header variables |
|---|
| 32 | $tplVars['subtitle'] = T_('Edit Bookmark'); |
|---|
| 33 | $tplVars['loadjs'] = true; |
|---|
| 34 | |
|---|
| 35 | list ($url, $bookmark) = explode('/', $_SERVER['PATH_INFO']);
|
|---|
| 36 | $tplVars['sidebar_blocks'] = array( 'profile' ); |
|---|
| 37 | if (!($row = $bookmarkservice->getBookmark(intval($bookmark), true))) { |
|---|
| 38 | $tplVars['error'] = sprintf(T_('Bookmark with id %s not was not found'), $bookmark); |
|---|
| 39 | $templateservice->loadTemplate('error.404.tpl', $tplVars); |
|---|
| 40 | exit(); |
|---|
| 41 | } else { |
|---|
| 42 | if (!$bookmarkservice->editAllowed($row)) { |
|---|
| 43 | $tplVars['error'] = T_('You are not allowed to edit this bookmark'); |
|---|
| 44 | $templateservice->loadTemplate('error.500.tpl', $tplVars); |
|---|
| 45 | exit(); |
|---|
| 46 | } else if ($_POST['submitted']) { |
|---|
| 47 | if (!$_POST['title'] || !$_POST['address']) { |
|---|
| 48 | $tplVars['error'] = T_('Your bookmark must have a title and an address'); |
|---|
| 49 | } else { |
|---|
| 50 | // Update bookmark |
|---|
| 51 | $bId = intval($bookmark); |
|---|
| 52 | $address = trim($_POST['address']); |
|---|
| 53 | $title = trim($_POST['title']); |
|---|
| 54 | $description = trim($_POST['description']); |
|---|
| 55 | $status = intval($_POST['status']); |
|---|
| 56 | $tags = trim($_POST['tags']); |
|---|
| 57 | $logged_on_user = $userservice->getCurrentUser(); |
|---|
| 58 | if (!$bookmarkservice->updateBookmark($bId, $address, $title, $description, $status, $tags)) { |
|---|
| 59 | $tplvars['error'] = T_('Error while saving your bookmark'); |
|---|
| 60 | } else { |
|---|
| 61 | if (isset($_POST['popup'])) { |
|---|
| 62 | $tplVars['msg'] = (isset($_POST['popup'])) ? '<script type="text/javascript">window.close();</script>' : T_('Bookmark saved'); |
|---|
| 63 | } elseif (isset($_POST['referrer'])) { |
|---|
| 64 | header('Location: '. $_POST['referrer']); |
|---|
| 65 | } else { |
|---|
| 66 | header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')])); |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | } else { |
|---|
| 71 | if ($_POST['delete']) { |
|---|
| 72 | // Delete bookmark |
|---|
| 73 | if ($bookmarkservice->deleteBookmark($bookmark)) { |
|---|
| 74 | $logged_on_user = $userservice->getCurrentUser(); |
|---|
| 75 | if (isset($_POST['referrer'])) { |
|---|
| 76 | header('Location: '. $_POST['referrer']); |
|---|
| 77 | } else { |
|---|
| 78 | header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')])); |
|---|
| 79 | } |
|---|
| 80 | exit(); |
|---|
| 81 | } else { |
|---|
| 82 | $tplVars['error'] = T_('Failed to delete the bookmark'); |
|---|
| 83 | $templateservice->loadTemplate('error.500.tpl', $tplVars); |
|---|
| 84 | exit(); |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | $tplVars['popup'] = (isset($_GET['popup'])) ? $_GET['popup'] : null; |
|---|
| 90 | $tplVars['row'] =& $row; |
|---|
| 91 | $tplVars['formaction'] = createURL('edit', $bookmark); |
|---|
| 92 | $tplVars['btnsubmit'] = T_('Save Changes'); |
|---|
| 93 | $tplVars['showdelete'] = true; |
|---|
| 94 | $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
|
|---|
| 95 | $templateservice->loadTemplate('editbookmark.tpl', $tplVars); |
|---|
| 96 | } |
|---|
| 97 | ?> |
|---|