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

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

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