3 function bookmark_add($zid, $uid)
5 $query = sprintf("INSERT INTO bookmarks (uid,zeitung) VALUES (%d,%d)",
8 # Ignore potentially existing bookmark
12 function bookmark_delete($zid, $uid)
14 $query = sprintf("DELETE FROM bookmarks " .
15 "WHERE uid = %d AND zeitung = %d",
18 # Ignore potentially non-existing bookmark
22 function bookmark_up($zid, $uid)
24 $query = sprintf("UPDATE bookmarks SET priority = priority - 1 " .
25 "WHERE uid = %d AND zeitung = %d",
28 # Ignore potentially non-existing bookmark
32 function bookmark_down($zid, $uid)
34 $query = sprintf("UPDATE bookmarks SET priority = priority + 1 " .
35 "WHERE uid = %d AND zeitung = %d",
38 # Ignore potentially non-existing bookmark
42 function format_bookmarks()
44 if (!isset($_SESSION['uid']))
47 $query = sprintf("SELECT zeitung,name,priority FROM bookmarks " .
48 "JOIN zeitungen ON zeitungen.id = zeitung " .
50 "ORDER BY priority,name LIMIT 20",
53 $sth = db_query($query);
55 if ($sth === false || pg_num_rows ($sth) == 0)
60 <a %s><img src="up.png" width="16" height="16" alt="up" title="Nach oben schieben" border="0"></a>
62 <a %s><img src="down.png" width="16" height="16" alt="up" title="Nach unten schieben" border="0"></a>
63 <a %s><img src="delete.gif" width="16" height="16" alt="delete" title="Lesezeichen löschen" border="0"></a>
66 <a href="zeitung/%d.html">%s</a></td>
69 $ret .= '<table class="bookmarks" width="100%" alt="">';
70 for ($n=0; $n < pg_num_rows ($sth); $n++) {
71 $row = pg_fetch_array ($sth, $n);
73 if (javascript_ok()) {
74 $link_up = sprintf('href="bookmark.html" onclick="return bookmark_action(\'up\',%d);"', $row['zeitung']);
75 $link_down = sprintf('href="bookmark.html" onclick="return bookmark_action(\'down\',%d);"', $row['zeitung']);
76 $link_del = sprintf('href="bookmark.html" onclick="return bookmark_action(\'del\',%d);"', $row['zeitung']);
78 $link_up = sprintf('href="bookmark.html?zeitung=%d&action=up"', $row['zeitung']);
79 $link_down = sprintf('href="bookmark.html?zeitung=%d&action=down"', $row['zeitung']);
80 $link_del = sprintf('href="bookmark.html?zeitung=%d&action=delete"', $row['zeitung']);
83 $ret .= sprintf($rowf,
84 $link_up, $row['priority'], $link_down, $link_del,
85 $row['zeitung'], $row['name']);
93 function bookmarks_manage()
95 if (!isset($_SESSION['uid']))
98 $ret = '<h3>Verwaltung der persönlichen Lesezeichen</h3>';
100 $ret .= '<div id="bookmarks">';
101 $ret .= load_javascript('bookmarks.js');
102 $ret .= format_bookmarks();
108 function process_bookmark()
113 if (!isset($_SESSION['uid']))
116 if (empty($_SERVER['QUERY_STRING'])) {
117 return bookmarks_manage();
118 } elseif (!isset($_GET['zeitung']) || !is_numeric($_GET['zeitung'])) {
119 if (isset($_SERVER['HTTP_REFERER']))
120 $zlist['redirect'] = substr($_SERVER['HTTP_REFERER'], strlen($zlist['home']));
121 return warning('Keine Zeitung oder Magazin gefunden.');
122 } elseif (isset($_GET['action'])) {
123 if ($_GET['action'] == 'up')
124 bookmark_up($_GET['zeitung'], $_SESSION['uid']);
125 elseif ($_GET['action'] == 'down')
126 bookmark_down($_GET['zeitung'], $_SESSION['uid']);
127 elseif ($_GET['action'] == 'delete')
128 bookmark_delete($_GET['zeitung'], $_SESSION['uid']);
131 header('Location: ' . $cfg['home'] . 'bookmark.html');
134 bookmark_add($_GET['zeitung'], $_SESSION['uid']);
135 if (isset($_SERVER['HTTP_REFERER'])) {
136 header('Location: ' . $_SERVER['HTTP_REFERER']);
139 return information('Ihr Lesezeichen wurde hinzugefügt');
143 function ajax_bookmark_check()
145 if (!isset($_POST['zeitung']) || !is_numeric($_POST['zeitung']) ||
146 !isset($_SESSION['uid']))
152 function ajax_bookmark_up()
154 if (!ajax_bookmark_check())
157 bookmark_up($_POST['zeitung'], $_SESSION['uid']);
159 return format_bookmarks();
162 function ajax_bookmark_down()
164 if (!ajax_bookmark_check())
167 bookmark_down($_POST['zeitung'], $_SESSION['uid']);
169 return format_bookmarks();
172 function ajax_bookmark_del()
174 if (!ajax_bookmark_check())
177 bookmark_delete($_POST['zeitung'], $_SESSION['uid']);
179 return format_bookmarks();
182 function ajax_bookmark_add()
184 if (!ajax_bookmark_check())
187 bookmark_add($_POST['zeitung'], $_SESSION['uid']);
189 return format_info_bookmarks();