# The LearningOnline Network with CAPA # The bookmarks handler # # $Id: admbookmarks.pm,v 1.30 2005/04/07 06:56:22 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(< Bookmark Tree Viewer/Editor END_HTML } # ---------------------------------------------------------------Construct Error window sub construct_error { my $error_message=shift; return(< Bookmark Tree Viewer/Editor V3
$error_message
END_ERROR } # --------------------------------------------Construct toolbar (after saving) sub construct_toolbar { return(<
Bookmarks saved. [ Continue ]
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="$bookmarks

Bookmarks successfully saved"; 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(<