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

1.28      albertel    1: # The LearningOnline Network with CAPA
                      2: # The bookmarks handler
1.1       tyszkabe    3: #
1.31    ! albertel    4: # $Id: admbookmarks.pm,v 1.30 2005/04/07 06:56:22 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.3       tyszkabe   44:     my $marks=shift;
1.27      albertel   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.26      albertel   52:     my %bookmark=Apache::lonnet::get('bookmarks',['bookmarks']);
                     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.9       tyszkabe   62:     my $bookmarks=shift;
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.31    ! albertel  117:     my $error_message=shift;
        !           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.6       tyszkabe  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 {
                    168:     my $location=shift;
                    169:     my $title=shift;
1.22      tyszkabe  170:     my $bookmarks=shift;
                    171:     my $page='';
1.23      harris41  172:     $bookmarks .= "window.tree.bookmarks.addLink(\"$title\",\"$location\");\n";
1.22      tyszkabe  173: #	$marks{'bookmarks'} += qq/\nwindow.tree.bookmarks.addlink("$title","$location");\n/;
1.23      harris41  174:     write_bookmarks($bookmarks);
1.24      harris41  175:     $page="<html><body>$bookmarks<p>Bookmarks successfully saved<script language=\"JavaScript\">window.close()</script></body></html>";
1.22      tyszkabe  176:     return($page);
1.21      tyszkabe  177: }
                    178: 
1.16      tyszkabe  179: # ----------------------------------------------------------------Main Handler
1.1       tyszkabe  180: 
                    181: sub handler {
1.6       tyszkabe  182:   my $r=shift;
                    183:   my %marks;
                    184:   my $save_mark;
                    185:   my $page;
                    186:   $r->content_type('text/html');
                    187:   $r->send_http_header;
1.30      albertel  188:   if (defined($env{'form.hiddenbookmarks'})) {
                    189:       $marks{'bookmarks'}=$env{'form.hiddenbookmarks'};
1.22      tyszkabe  190:       write_bookmarks($marks{'bookmarks'});
                    191:       $page=construct_toolbar();
1.6       tyszkabe  192:   } else {
1.22      tyszkabe  193:       %marks=get_bookmarks();
                    194:       if (exists($marks{"con_lost"})) {
                    195: 	  #$page = construct_editor($marks{'bookmarks'});  # Delete this line and uncomment next
                    196: 	  # in order to re-enable connection detection
                    197: 	  $page=construct_error("Connection broken with home server. Please contact your system administrator");
1.9       tyszkabe  198:       } else {
1.30      albertel  199: 	  if (defined($env{'form.address'})) {
                    200: 	      $page=add_bookmark($env{'form.address'},$env{'form.title'},$marks{'bookmarks'});
1.21      tyszkabe  201: 	  } else {
                    202: 	      if ($marks{'bookmarks'} eq "") {
1.29      www       203: 		  $marks{'bookmarks'}=defaultmarks();
1.21      tyszkabe  204: 	      }
                    205: 	      $page = construct_editor($marks{'bookmarks'});
1.10      tyszkabe  206: 	  }
1.9       tyszkabe  207:       }
1.6       tyszkabe  208:   }
                    209:   $r->print($page);
                    210:   return OK;
1.1       tyszkabe  211: }
1.9       tyszkabe  212: 
                    213: ####################################
                    214: #
1.16      tyszkabe  215: #            The following was used for debugging when the bookmarks get corrupted
                    216: #                            ben  10/12/2000
                    217: sub recovermarks {
                    218:     return(<<END_MARKS);
                    219: window.tree.bookmarks.addFolder("Default Bookmarks",true);
1.29      www       220: window.tree.bookmarks.p[0].addFolder("LON-CAPA",true);
                    221: window.tree.bookmarks.p[0].p[0].addLink("Main","http://www.lon-capa.org/");
                    222: window.tree.bookmarks.p[0].p[0].addLink("Help","http://help.lon-capa.org/");
                    223: window.tree.bookmarks.p[0].p[0].addLink("Bugs","http://bugs.lon-capa.org/");
1.16      tyszkabe  224: END_MARKS
                    225: }
                    226: #
                    227: #
                    228: ##########################################
                    229: 
                    230: ##########################################
                    231: #
                    232: #          Here is a listing of default bookmarks. It may be used to replace 'recover'
                    233: #          eventually, but for now these will load after all bookmarks have been deleted.
1.10      tyszkabe  234: #                ben 10/12/2000
                    235: sub defaultmarks {
                    236:     return(<<END_MARKS);
1.16      tyszkabe  237: window.tree.bookmarks.addFolder("Default Bookmarks",true);
1.29      www       238: window.tree.bookmarks.p[0].addFolder("LON-CAPA",true);
                    239: window.tree.bookmarks.p[0].p[0].addLink("Main","http://www.lon-capa.org/");
                    240: window.tree.bookmarks.p[0].p[0].addLink("Help","http://help.lon-capa.org/");
                    241: window.tree.bookmarks.p[0].p[0].addLink("Bugs","http://bugs.lon-capa.org/");
1.10      tyszkabe  242: END_MARKS
                    243: }
1.1       tyszkabe  244: 
                    245: 1;
                    246: __END__
1.8       tyszkabe  247: 
                    248: 
                    249: 
                    250: 
                    251: 

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