File:
[LON-CAPA] /
loncom /
html /
res /
adm /
pages /
bookmarkmenu /
admbookmarks.pm
Revision
1.28:
download - view:
text,
annotated -
select for diffs
Wed Dec 19 17:17:46 2001 UTC (22 years, 9 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_0_99_2,
version_0_99_1,
version_0_99_0,
version_0_6_2,
version_0_6,
version_0_5_1,
version_0_5,
version_0_4,
stable_2002_spring,
stable_2002_july,
stable_2002_april,
conference_2003,
STABLE,
HEAD
- Finished GPLing the code
# The LearningOnline Network with CAPA
# The bookmarks handler
#
# $Id: admbookmarks.pm,v 1.28 2001/12/19 17:17:46 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
# 08/25/00 Ben Tyszka
#
#
#
##################
package Apache::admbookmarks;
use strict;
use Apache::Constants qw(:common);
use Apache::lonnet();
# --------------------------------------------------------------Put bookmarks
sub write_bookmarks {
my $marks=shift;
Apache::lonnet::put("bookmarks",{'bookmarks' => $marks});
return;
}
# --------------------------------------------------------------Get bookmarks
sub get_bookmarks {
my %bookmark=Apache::lonnet::get('bookmarks',['bookmarks']);
my ($errormsg) = $bookmark{'bookmarks'};
if ($errormsg =~ /^error/) { %bookmark = ('bookmarks' => ''); }
return %bookmark;
}
# ---------------------------------------------------Construct bookmark editor
sub construct_editor {
my $bookmarks=shift;
return(<<END_HTML)
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>
Bookmark Tree Viewer/Editor
</title>
<script src="/res/adm/pages/bookmarkmenu/bookmarklib.js" language="JavaScript"></script>
<script LANGUAGE="JavaScript">
function initialize() {
window.tree = new newTree();
//-------------------------------------------------------------------------------
// The FOLLOWING data is supplied by the Perl Module
//-------------------------------------------------------------------------------
$bookmarks
//-------------------------------------------------------------------------------
// The PRECEDING data is supplied by the Perl Module
//-------------------------------------------------------------------------------
window.tree.redraw();
}
</script>
</head>
<FRAMESET rows="25, *, 40, 25, 1" topmargin=0 leftmargin=0 marginheight=0 marginwidth=0 frameborder="0" border="0" framespacing="0" onLoad="Javascript:buildBookmarkMenu();initialize();">
<FRAMESET cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
<FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
<FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
<FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
</FRAMESET>
<FRAMESET cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
<FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
<FRAME src="/res/adm/pages/bookmarkmenu/blank.html" marginwidth="0" marginheight="0" scrolling="yes">
<FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
</FRAMESET>
<FRAMESET cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
<FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
<FRAME src="/res/adm/pages/bookmarkmenu/bookmarkmenu_toolbar.html" marginwidth="0" marginheight="0" scrolling="no">
<FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
</FRAMESET>
<FRAMESET cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
<FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
<FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
<FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
</FRAMESET>
<frame name=closechildren src="/res/adm/pages/bookmarkmenu/closechildren.html" noresize noscroll>
</FRAMESET>
</html>
END_HTML
}
# ---------------------------------------------------------------Construct Error window
sub construct_error {
my $error_message=shift;
return(<<END_ERROR)
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>
Bookmark Tree Viewer/Editor V3
</title>
</head>
<body bgcolor="#BBBBBB">
<table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
<td>
<i>
$error_message
</i>
</td>
</table>
<center>
<form>
<input type=button name="close" value="close window" onClick="javascript:window.close();">
</form>
</center>
</body>
</html>
END_ERROR
}
# --------------------------------------------Construct toolbar (after saving)
sub construct_toolbar {
return(<<END_TOOLBAR)
<html>
<body>
<div align="bottom">
<center>
Bookmarks saved.
[ <a href="/res/adm/pages/bookmarkmenu/bookmarkmenu_toolbar.html" target="_self">Continue</a> ]
</center>
</div>
</body>
</html>
END_TOOLBAR
}
# ---------------------------------------------Add bookmark from remote control
sub add_bookmark {
my $location=shift;
my $title=shift;
my $bookmarks=shift;
my $page='';
$bookmarks .= "window.tree.bookmarks.addLink(\"$title\",\"$location\");\n";
# $marks{'bookmarks'} += qq/\nwindow.tree.bookmarks.addlink("$title","$location");\n/;
write_bookmarks($bookmarks);
$page="<html><body>$bookmarks<p>Bookmarks successfully saved<script language=\"JavaScript\">window.close()</script></body></html>";
return($page);
}
# ----------------------------------------------------------------Main Handler
sub handler {
my $r=shift;
my %marks;
my $save_mark;
my $page;
$r->content_type('text/html');
$r->send_http_header;
if (defined($ENV{'form.hiddenbookmarks'})) {
$marks{'bookmarks'}=$ENV{'form.hiddenbookmarks'};
write_bookmarks($marks{'bookmarks'});
$page=construct_toolbar();
} else {
%marks=get_bookmarks();
if (exists($marks{"con_lost"})) {
#$page = construct_editor($marks{'bookmarks'}); # Delete this line and uncomment next
# in order to re-enable connection detection
$page=construct_error("Connection broken with home server. Please contact your system administrator");
} else {
if (defined($ENV{'form.address'})) {
$page=add_bookmark($ENV{'form.address'},$ENV{'form.title'},$marks{'bookmarks'});
} else {
if ($marks{'bookmarks'} eq "") {
#$marks{'bookmarks'}=defaultmarks();
}
$page = construct_editor($marks{'bookmarks'});
}
}
}
$r->print($page);
return OK;
}
####################################
#
# The following was used for debugging when the bookmarks get corrupted
# ben 10/12/2000
sub recovermarks {
return(<<END_MARKS);
window.tree.bookmarks.addFolder("Default Bookmarks",true);
window.tree.bookmarks.p[0].addFolder("Michigan State University",true);
window.tree.bookmarks.p[0].p[0].addLink("Main Website","http://www.msu.edu");
window.tree.bookmarks.p[0].p[0].addLink("College of Natural Science","http://www.ns.msu.edu");
window.tree.bookmarks.p[0].p[0].addLink("College of Engineering","http://www.egr.msu.edu");
window.tree.bookmarks.p[0].p[0].addLink("Dept. of Mathematics","http://www.math.msu.edu");
window.tree.bookmarks.p[0].p[0].addLink("Lite Lab","http://www.lite.msu.edu");
window.tree.bookmarks.p[0].p[0].addLink("Physics and Astronomy","http://www.pa.msu.edu");
window.tree.bookmarks.p[0].addFolder("Lon-Capa",false);
window.tree.bookmarks.p[0].p[1].addLink("Lon-Capa org","http://lon-capa.org");
window.tree.bookmarks.p[0].p[1].addLink("Lite Lab","http://www.lite.msu.edu");
lwindow.tree.bookmarks.p[0].addLink("Redhat","http://redhat.com");
window.tree.bookmarks.p[0].addLink("Debian","http://debian.org");
window.tree.bookmarks.addLink("Other Bookmarks","http://kirk.lite.msu.edu");
END_MARKS
}
#
#
##########################################
##########################################
#
# Here is a listing of default bookmarks. It may be used to replace 'recover'
# eventually, but for now these will load after all bookmarks have been deleted.
# ben 10/12/2000
sub defaultmarks {
return(<<END_MARKS);
window.tree.bookmarks.addFolder("Default Bookmarks",true);
window.tree.bookmarks.p[0].addFolder("Michigan State University",true);
window.tree.bookmarks.p[0].p[0].addLink("Main Website","http://www.msu.edu");
window.tree.bookmarks.p[0].p[0].addLink("College of Natural Science","http://www.ns.msu.edu");
window.tree.bookmarks.p[0].p[0].addLink("College of Engineering","http://www.egr.msu.edu");
window.tree.bookmarks.p[0].p[0].addLink("Dept. of Mathematics","http://www.math.msu.edu");
window.tree.bookmarks.p[0].p[0].addLink("Lite Lab","http://www.lite.msu.edu");
window.tree.bookmarks.p[0].p[0].addLink("Physics and Astronomy","http://www.pa.msu.edu");
window.tree.bookmarks.p[0].addFolder("Lon-Capa",false);
window.tree.bookmarks.p[0].p[1].addLink("Lon-Capa org","http://lon-capa.org");
window.tree.bookmarks.p[0].p[1].addLink("Lite Lab","http://www.lite.msu.edu");
window.tree.bookmarks.p[0].addLink("Redhat","http://redhat.com");
window.tree.bookmarks.p[0].addLink("Debian","http://debian.org");
window.tree.bookmarks.addLink("Other Bookmarks","http://kirk.lite.msu.edu");
END_MARKS
}
1;
__END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>