Annotation of loncom/html/res/adm/pages/bookmarkmenu/admbookmarks.pm, revision 1.35

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>