Annotation of loncom/html/res/adm/pages/bookmarkmenu/admbookmarks.pm, revision 1.37
1.28 albertel 1: # The LearningOnline Network with CAPA
2: # The bookmarks handler
1.1 tyszkabe 3: #
1.37 ! foxr 4: # $Id: admbookmarks.pm,v 1.36 2006/04/11 18:50:10 albertel 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.5 tyszkabe 34: package Apache::admbookmarks;
1.1 tyszkabe 35:
36: use strict;
1.2 tyszkabe 37: use Apache::Constants qw(:common);
1.30 albertel 38: use Apache::lonnet;
1.31 albertel 39: use Apache::loncommon();
1.35 albertel 40: use Apache::lonlocal;
1.1 tyszkabe 41:
1.4 tyszkabe 42: # --------------------------------------------------------------Put bookmarks
1.1 tyszkabe 43:
1.4 tyszkabe 44: sub write_bookmarks {
1.32 albertel 45: my ($marks) = @_;
46: &Apache::lonnet::put("bookmarks",{'bookmarks' => $marks});
1.2 tyszkabe 47: return;
1.1 tyszkabe 48: }
49:
1.4 tyszkabe 50: # --------------------------------------------------------------Get bookmarks
1.2 tyszkabe 51:
1.4 tyszkabe 52: sub get_bookmarks {
1.32 albertel 53: my %bookmark=&Apache::lonnet::get('bookmarks',['bookmarks']);
1.26 albertel 54: my ($errormsg) = $bookmark{'bookmarks'};
55: if ($errormsg =~ /^error/) { %bookmark = ('bookmarks' => ''); }
56:
1.5 tyszkabe 57: return %bookmark;
1.2 tyszkabe 58: }
59:
1.4 tyszkabe 60: # ---------------------------------------------------Construct bookmark editor
1.2 tyszkabe 61:
62: sub construct_editor {
1.32 albertel 63: my ($bookmarks) = @_;
1.31 albertel 64: my $js = <<ENDJS;
1.34 albertel 65: <script src="/res/adm/pages/bookmarkmenu/bookmarklib.js" type="text/javascript"></script>
1.16 tyszkabe 66:
1.34 albertel 67: <script type="text/javascript">
1.16 tyszkabe 68: function initialize() {
69: window.tree = new newTree();
1.34 albertel 70: //-----------------------------------------------------------------------------
1.9 tyszkabe 71: // The FOLLOWING data is supplied by the Perl Module
1.34 albertel 72: //-----------------------------------------------------------------------------
1.9 tyszkabe 73: $bookmarks
1.34 albertel 74: //-----------------------------------------------------------------------------
1.9 tyszkabe 75: // The PRECEDING data is supplied by the Perl Module
1.34 albertel 76: //-----------------------------------------------------------------------------
1.16 tyszkabe 77: window.tree.redraw();
1.4 tyszkabe 78: }
1.8 tyszkabe 79: </script>
1.31 albertel 80: ENDJS
81:
1.36 albertel 82: my $start_page =
83: &Apache::loncommon::start_page('Bookmark Tree Viewer/Editor',$js,
84: {'frameset' => 1,
85: 'add_entries' => {
86: 'rows' => "25,*,40,25,1",
87: 'topmargin' => "0",
88: 'leftmargin' => "0",
89: 'marginheight' => "0",
90: 'marginwidth' => "0",
91: 'frameborder' => "0",
92: 'border' => "0",
93: 'framespacing' => "0",
1.37 ! foxr 94: 'onload' => "javascript:buildBookmarkMenu();initialize();"}});
1.36 albertel 95: my $end_page =
96: &Apache::loncommon::end_page({'frameset' => 1,});
97:
1.31 albertel 98: return(<<END_HTML)
1.36 albertel 99: $start_page
1.34 albertel 100: <frameset cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
1.36 albertel 101: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
102: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
103: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
1.34 albertel 104: </frameset>
105: <frameset cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
1.36 albertel 106: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
1.34 albertel 107: <frame src="/res/adm/pages/bookmarkmenu/blank.html" marginwidth="0"
1.36 albertel 108: marginheight="0" scrolling="yes" />
109: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
1.34 albertel 110: </frameset>
111: <frameset cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
1.36 albertel 112: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
1.34 albertel 113: <frame src="/res/adm/pages/bookmarkmenu/bookmarkmenu_toolbar.html"
1.36 albertel 114: marginwidth="0" marginheight="0" scrolling="no" />
115: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
1.34 albertel 116: </frameset>
117: <frameset cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
1.36 albertel 118: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
119: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
120: <frame marginwidth="0" marginheight="0" scrolling="no" src="javascript:''" />
1.34 albertel 121: </frameset>
1.36 albertel 122: <frame name="closechildren" noresize="noresize" noscroll="noscroll"
123: src="/res/adm/pages/bookmarkmenu/closechildren.html" />
124: $end_page
1.2 tyszkabe 125: END_HTML
1.1 tyszkabe 126: }
127:
1.16 tyszkabe 128: # ---------------------------------------------------------------Construct Error window
1.5 tyszkabe 129:
130: sub construct_error {
1.32 albertel 131: my ($error_message) = @_;
1.31 albertel 132: my $start_page =
133: &Apache::loncommon::start_page('Bookmark Tree Viewer/Editor',undef,
134: {'only_body' => 1,
135: 'bgcolor' => '#BBBBBB',});
136:
137: my $end_page = &Apache::loncommon::end_page();
1.35 albertel 138:
1.36 albertel 139: my $close = &mt('Close Window');
1.31 albertel 140:
1.35 albertel 141: return(<<END_ERROR)
1.31 albertel 142: $start_page
1.5 tyszkabe 143: <table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
144: <td>
145: <i>
146: $error_message
147: </i>
148: </td>
149: </table>
150: <center>
151: <form>
1.35 albertel 152: <input type="button" name="close" value="$close"
153: onclick="javascript:window.close();" />
1.5 tyszkabe 154: </form>
155: </center>
1.31 albertel 156: $end_page
1.5 tyszkabe 157: END_ERROR
158: }
159:
1.16 tyszkabe 160: # --------------------------------------------Construct toolbar (after saving)
1.6 tyszkabe 161:
162: sub construct_toolbar {
1.31 albertel 163: my $start_page =
164: &Apache::loncommon::start_page('Bookmark Tree Viewer/Editor',undef,
165: {'only_body' => 1,
166: 'bgcolor' => '#FFFFFF',});
167:
168: my $end_page = &Apache::loncommon::end_page();
169:
1.35 albertel 170: my $msg = &mt('Bookmarks saved. ([_1]Continue[_2])',
171: '<a href="/res/adm/pages/bookmarkmenu/bookmarkmenu_toolbar.html" target="_self">',
172: '</a>');
173:
1.32 albertel 174: return(<<END_TOOLBAR)
1.31 albertel 175: $start_page
1.7 tyszkabe 176: <div align="bottom">
177: <center>
1.35 albertel 178: $msg
1.7 tyszkabe 179: </center>
180: </div>
1.31 albertel 181: $end_page
1.6 tyszkabe 182: END_TOOLBAR
183: }
184:
1.21 tyszkabe 185: # ---------------------------------------------Add bookmark from remote control
186:
187: sub add_bookmark {
1.32 albertel 188: my ($location, $title, $bookmarks) = @_;
1.33 albertel 189: my $start_page =
190: &Apache::loncommon::start_page('Bookmark Tree Viewer/Editor',undef,
191: {'only_body' => 1,
192: 'bgcolor' => '#FFFFFF',});
193:
194: my $end_page = &Apache::loncommon::end_page();
195:
1.23 harris41 196: $bookmarks .= "window.tree.bookmarks.addLink(\"$title\",\"$location\");\n";
1.22 tyszkabe 197: # $marks{'bookmarks'} += qq/\nwindow.tree.bookmarks.addlink("$title","$location");\n/;
1.32 albertel 198: &write_bookmarks($bookmarks);
1.34 albertel 199: my $page="$start_page $bookmarks<p>Bookmarks successfully saved</p><script type=\"text/javascript\">window.close()</script> $end_page";
1.22 tyszkabe 200: return($page);
1.21 tyszkabe 201: }
202:
1.16 tyszkabe 203: # ----------------------------------------------------------------Main Handler
1.1 tyszkabe 204:
205: sub handler {
1.32 albertel 206: my ($r) = @_;
207: my %marks;
208: my $save_mark;
209: my $page;
1.35 albertel 210: &Apache::loncommon::content_type($r,'text/html');
1.32 albertel 211: $r->send_http_header;
212: if (defined($env{'form.hiddenbookmarks'})) {
213: $marks{'bookmarks'}=$env{'form.hiddenbookmarks'};
214: &write_bookmarks($marks{'bookmarks'});
215: $page=&construct_toolbar();
216: } else {
217: %marks=&get_bookmarks();
218: if (exists($marks{"con_lost"})) {
219: #$page = construct_editor($marks{'bookmarks'}); # Delete this line and uncomment next
220: # in order to re-enable connection detection
1.35 albertel 221: $page=&construct_error(&mt("Connection broken with home server. Please contact your system administrator."));
1.32 albertel 222: } else {
223: if (defined($env{'form.address'})) {
224: $page=&add_bookmark($env{'form.address'},$env{'form.title'},$marks{'bookmarks'});
225: } else {
226: if ($marks{'bookmarks'} eq "") {
227: $marks{'bookmarks'}=&defaultmarks();
228: }
229: $page = &construct_editor($marks{'bookmarks'});
230: }
231: }
232: }
233: $r->print($page);
234: return OK;
1.1 tyszkabe 235: }
1.9 tyszkabe 236:
237: ####################################
238: #
1.16 tyszkabe 239: # The following was used for debugging when the bookmarks get corrupted
240: # ben 10/12/2000
241: sub recovermarks {
242: return(<<END_MARKS);
243: window.tree.bookmarks.addFolder("Default Bookmarks",true);
1.29 www 244: window.tree.bookmarks.p[0].addFolder("LON-CAPA",true);
245: window.tree.bookmarks.p[0].p[0].addLink("Main","http://www.lon-capa.org/");
246: window.tree.bookmarks.p[0].p[0].addLink("Help","http://help.lon-capa.org/");
247: window.tree.bookmarks.p[0].p[0].addLink("Bugs","http://bugs.lon-capa.org/");
1.16 tyszkabe 248: END_MARKS
249: }
250: #
251: #
252: ##########################################
253:
254: ##########################################
255: #
256: # Here is a listing of default bookmarks. It may be used to replace 'recover'
257: # eventually, but for now these will load after all bookmarks have been deleted.
1.10 tyszkabe 258: # ben 10/12/2000
259: sub defaultmarks {
260: return(<<END_MARKS);
1.16 tyszkabe 261: window.tree.bookmarks.addFolder("Default Bookmarks",true);
1.29 www 262: window.tree.bookmarks.p[0].addFolder("LON-CAPA",true);
263: window.tree.bookmarks.p[0].p[0].addLink("Main","http://www.lon-capa.org/");
264: window.tree.bookmarks.p[0].p[0].addLink("Help","http://help.lon-capa.org/");
265: window.tree.bookmarks.p[0].p[0].addLink("Bugs","http://bugs.lon-capa.org/");
1.10 tyszkabe 266: END_MARKS
267: }
1.1 tyszkabe 268:
269: 1;
270: __END__
1.8 tyszkabe 271:
272:
273:
274:
275:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>