Annotation of loncom/html/res/adm/pages/bookmarkmenu/admbookmarks.pm, revision 1.38
1.28 albertel 1: # The LearningOnline Network with CAPA
2: # The bookmarks handler
1.1 tyszkabe 3: #
1.38 ! jms 4: # $Id: admbookmarks.pm,v 1.37 2006/04/12 09:45:50 foxr Exp $
1.28 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
1.1 tyszkabe 27: #
1.2 tyszkabe 28: # 08/25/00 Ben Tyszka
1.16 tyszkabe 29: #
1.1 tyszkabe 30: #
1.2 tyszkabe 31: #
32: ##################
1.1 tyszkabe 33:
1.38 ! jms 34: =pod
! 35:
! 36: =head1 NAME
! 37:
! 38: Apache::admbookmarks
! 39:
! 40: =head1 SYNOPSIS
! 41:
! 42: This will take bookmarks and get/write/display
! 43: them for the LON-CAPA user interface.
! 44:
! 45: This is part of the LearningOnline Network with CAPA project
! 46: described at http://www.lon-capa.org.
! 47:
! 48: =head1 OVERVIEW
! 49:
! 50: (empty)
! 51:
! 52:
! 53: =head1 SUBROUTINES
! 54:
! 55: =over write_bookmarks()
! 56:
! 57: =item get_bookmarks()
! 58:
! 59: =item construct_editor()
! 60:
! 61: =item error_message()
! 62:
! 63: =item construct_toolbar()
! 64:
! 65: =item add_bookmark()
! 66:
! 67: =item handler()
! 68:
! 69: =back
! 70:
! 71: =cut
! 72:
! 73:
1.5 tyszkabe 74: package Apache::admbookmarks;
1.1 tyszkabe 75:
76: use strict;
1.2 tyszkabe 77: use Apache::Constants qw(:common);
1.30 albertel 78: use Apache::lonnet;
1.31 albertel 79: use Apache::loncommon();
1.35 albertel 80: use Apache::lonlocal;
1.1 tyszkabe 81:
1.4 tyszkabe 82: # --------------------------------------------------------------Put bookmarks
1.1 tyszkabe 83:
1.4 tyszkabe 84: sub write_bookmarks {
1.32 albertel 85: my ($marks) = @_;
86: &Apache::lonnet::put("bookmarks",{'bookmarks' => $marks});
1.2 tyszkabe 87: return;
1.1 tyszkabe 88: }
89:
1.4 tyszkabe 90: # --------------------------------------------------------------Get bookmarks
1.2 tyszkabe 91:
1.4 tyszkabe 92: sub get_bookmarks {
1.32 albertel 93: my %bookmark=&Apache::lonnet::get('bookmarks',['bookmarks']);
1.26 albertel 94: my ($errormsg) = $bookmark{'bookmarks'};
95: if ($errormsg =~ /^error/) { %bookmark = ('bookmarks' => ''); }
96:
1.5 tyszkabe 97: return %bookmark;
1.2 tyszkabe 98: }
99:
1.4 tyszkabe 100: # ---------------------------------------------------Construct bookmark editor
1.2 tyszkabe 101:
102: sub construct_editor {
1.32 albertel 103: my ($bookmarks) = @_;
1.31 albertel 104: my $js = <<ENDJS;
1.34 albertel 105: <script src="/res/adm/pages/bookmarkmenu/bookmarklib.js" type="text/javascript"></script>
1.16 tyszkabe 106:
1.34 albertel 107: <script type="text/javascript">
1.16 tyszkabe 108: function initialize() {
109: window.tree = new newTree();
1.34 albertel 110: //-----------------------------------------------------------------------------
1.9 tyszkabe 111: // The FOLLOWING data is supplied by the Perl Module
1.34 albertel 112: //-----------------------------------------------------------------------------
1.9 tyszkabe 113: $bookmarks
1.34 albertel 114: //-----------------------------------------------------------------------------
1.9 tyszkabe 115: // The PRECEDING data is supplied by the Perl Module
1.34 albertel 116: //-----------------------------------------------------------------------------
1.16 tyszkabe 117: window.tree.redraw();
1.4 tyszkabe 118: }
1.8 tyszkabe 119: </script>
1.31 albertel 120: ENDJS
121:
1.36 albertel 122: my $start_page =
123: &Apache::loncommon::start_page('Bookmark Tree Viewer/Editor',$js,
124: {'frameset' => 1,
125: 'add_entries' => {
126: 'rows' => "25,*,40,25,1",
127: 'topmargin' => "0",
128: 'leftmargin' => "0",
129: 'marginheight' => "0",
130: 'marginwidth' => "0",
131: 'frameborder' => "0",
132: 'border' => "0",
133: 'framespacing' => "0",
1.37 foxr 134: 'onload' => "javascript:buildBookmarkMenu();initialize();"}});
1.36 albertel 135: my $end_page =
136: &Apache::loncommon::end_page({'frameset' => 1,});
137:
1.31 albertel 138: return(<<END_HTML)
1.36 albertel 139: $start_page
1.34 albertel 140: <frameset cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
1.36 albertel 141: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
142: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
143: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
1.34 albertel 144: </frameset>
145: <frameset cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
1.36 albertel 146: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
1.34 albertel 147: <frame src="/res/adm/pages/bookmarkmenu/blank.html" marginwidth="0"
1.36 albertel 148: marginheight="0" scrolling="yes" />
149: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
1.34 albertel 150: </frameset>
151: <frameset cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
1.36 albertel 152: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
1.34 albertel 153: <frame src="/res/adm/pages/bookmarkmenu/bookmarkmenu_toolbar.html"
1.36 albertel 154: marginwidth="0" marginheight="0" scrolling="no" />
155: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
1.34 albertel 156: </frameset>
157: <frameset cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
1.36 albertel 158: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
159: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
160: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
1.34 albertel 161: </frameset>
1.36 albertel 162: <frame name="closechildren" noresize="noresize" noscroll="noscroll"
163: src="/res/adm/pages/bookmarkmenu/closechildren.html" />
164: $end_page
1.2 tyszkabe 165: END_HTML
1.1 tyszkabe 166: }
167:
1.16 tyszkabe 168: # ---------------------------------------------------------------Construct Error window
1.5 tyszkabe 169:
170: sub construct_error {
1.32 albertel 171: my ($error_message) = @_;
1.31 albertel 172: my $start_page =
173: &Apache::loncommon::start_page('Bookmark Tree Viewer/Editor',undef,
174: {'only_body' => 1,
175: 'bgcolor' => '#BBBBBB',});
176:
177: my $end_page = &Apache::loncommon::end_page();
1.35 albertel 178:
1.36 albertel 179: my $close = &mt('Close Window');
1.31 albertel 180:
1.35 albertel 181: return(<<END_ERROR)
1.31 albertel 182: $start_page
1.5 tyszkabe 183: <table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
184: <td>
185: <i>
186: $error_message
187: </i>
188: </td>
189: </table>
190: <center>
191: <form>
1.35 albertel 192: <input type="button" name="close" value="$close"
193: onclick="javascript:window.close();" />
1.5 tyszkabe 194: </form>
195: </center>
1.31 albertel 196: $end_page
1.5 tyszkabe 197: END_ERROR
198: }
199:
1.16 tyszkabe 200: # --------------------------------------------Construct toolbar (after saving)
1.6 tyszkabe 201:
202: sub construct_toolbar {
1.31 albertel 203: my $start_page =
204: &Apache::loncommon::start_page('Bookmark Tree Viewer/Editor',undef,
205: {'only_body' => 1,
206: 'bgcolor' => '#FFFFFF',});
207:
208: my $end_page = &Apache::loncommon::end_page();
209:
1.35 albertel 210: my $msg = &mt('Bookmarks saved. ([_1]Continue[_2])',
211: '<a href="/res/adm/pages/bookmarkmenu/bookmarkmenu_toolbar.html" target="_self">',
212: '</a>');
213:
1.32 albertel 214: return(<<END_TOOLBAR)
1.31 albertel 215: $start_page
1.7 tyszkabe 216: <div align="bottom">
217: <center>
1.35 albertel 218: $msg
1.7 tyszkabe 219: </center>
220: </div>
1.31 albertel 221: $end_page
1.6 tyszkabe 222: END_TOOLBAR
223: }
224:
1.21 tyszkabe 225: # ---------------------------------------------Add bookmark from remote control
226:
227: sub add_bookmark {
1.32 albertel 228: my ($location, $title, $bookmarks) = @_;
1.33 albertel 229: my $start_page =
230: &Apache::loncommon::start_page('Bookmark Tree Viewer/Editor',undef,
231: {'only_body' => 1,
232: 'bgcolor' => '#FFFFFF',});
233:
234: my $end_page = &Apache::loncommon::end_page();
235:
1.23 harris41 236: $bookmarks .= "window.tree.bookmarks.addLink(\"$title\",\"$location\");\n";
1.22 tyszkabe 237: # $marks{'bookmarks'} += qq/\nwindow.tree.bookmarks.addlink("$title","$location");\n/;
1.32 albertel 238: &write_bookmarks($bookmarks);
1.34 albertel 239: my $page="$start_page $bookmarks<p>Bookmarks successfully saved</p><script type=\"text/javascript\">window.close()</script> $end_page";
1.22 tyszkabe 240: return($page);
1.21 tyszkabe 241: }
242:
1.16 tyszkabe 243: # ----------------------------------------------------------------Main Handler
1.1 tyszkabe 244:
245: sub handler {
1.32 albertel 246: my ($r) = @_;
247: my %marks;
248: my $save_mark;
249: my $page;
1.35 albertel 250: &Apache::loncommon::content_type($r,'text/html');
1.32 albertel 251: $r->send_http_header;
252: if (defined($env{'form.hiddenbookmarks'})) {
253: $marks{'bookmarks'}=$env{'form.hiddenbookmarks'};
254: &write_bookmarks($marks{'bookmarks'});
255: $page=&construct_toolbar();
256: } else {
257: %marks=&get_bookmarks();
258: if (exists($marks{"con_lost"})) {
259: #$page = construct_editor($marks{'bookmarks'}); # Delete this line and uncomment next
260: # in order to re-enable connection detection
1.35 albertel 261: $page=&construct_error(&mt("Connection broken with home server. Please contact your system administrator."));
1.32 albertel 262: } else {
263: if (defined($env{'form.address'})) {
264: $page=&add_bookmark($env{'form.address'},$env{'form.title'},$marks{'bookmarks'});
265: } else {
266: if ($marks{'bookmarks'} eq "") {
267: $marks{'bookmarks'}=&defaultmarks();
268: }
269: $page = &construct_editor($marks{'bookmarks'});
270: }
271: }
272: }
273: $r->print($page);
274: return OK;
1.1 tyszkabe 275: }
1.9 tyszkabe 276:
277: ####################################
278: #
1.16 tyszkabe 279: # The following was used for debugging when the bookmarks get corrupted
280: # ben 10/12/2000
281: sub recovermarks {
282: return(<<END_MARKS);
283: window.tree.bookmarks.addFolder("Default Bookmarks",true);
1.29 www 284: window.tree.bookmarks.p[0].addFolder("LON-CAPA",true);
285: window.tree.bookmarks.p[0].p[0].addLink("Main","http://www.lon-capa.org/");
286: window.tree.bookmarks.p[0].p[0].addLink("Help","http://help.lon-capa.org/");
287: window.tree.bookmarks.p[0].p[0].addLink("Bugs","http://bugs.lon-capa.org/");
1.16 tyszkabe 288: END_MARKS
289: }
290: #
291: #
292: ##########################################
293:
294: ##########################################
295: #
296: # Here is a listing of default bookmarks. It may be used to replace 'recover'
297: # eventually, but for now these will load after all bookmarks have been deleted.
1.10 tyszkabe 298: # ben 10/12/2000
299: sub defaultmarks {
300: return(<<END_MARKS);
1.16 tyszkabe 301: window.tree.bookmarks.addFolder("Default Bookmarks",true);
1.29 www 302: window.tree.bookmarks.p[0].addFolder("LON-CAPA",true);
303: window.tree.bookmarks.p[0].p[0].addLink("Main","http://www.lon-capa.org/");
304: window.tree.bookmarks.p[0].p[0].addLink("Help","http://help.lon-capa.org/");
305: window.tree.bookmarks.p[0].p[0].addLink("Bugs","http://bugs.lon-capa.org/");
1.10 tyszkabe 306: END_MARKS
307: }
1.1 tyszkabe 308:
309: 1;
310: __END__
1.8 tyszkabe 311:
312:
313:
314:
315:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>