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

1.16      tyszkabe    1: #!/usr/bin/perl -T
1.1       tyszkabe    2: #
1.2       tyszkabe    3: # This will take annotations and then plug them into a page.
1.1       tyszkabe    4: #
1.2       tyszkabe    5: # 08/25/00 Ben Tyszka
1.16      tyszkabe    6: #
1.1       tyszkabe    7: #
1.2       tyszkabe    8: #
                      9: ##################
1.1       tyszkabe   10: 
1.5       tyszkabe   11: package Apache::admbookmarks;
1.1       tyszkabe   12: 
                     13: use strict;
1.2       tyszkabe   14: use Apache::Constants qw(:common);
1.8       tyszkabe   15: use Apache::lonnet();
1.1       tyszkabe   16: 
1.4       tyszkabe   17: # --------------------------------------------------------------Put bookmarks
1.1       tyszkabe   18: 
1.4       tyszkabe   19: sub write_bookmarks {
1.3       tyszkabe   20:     my $marks=shift;
1.16      tyszkabe   21:     Apache::lonnet::put("bookmarks",('bookmarks' => $marks));
1.2       tyszkabe   22:     return;
1.1       tyszkabe   23: }
                     24: 
1.4       tyszkabe   25: # --------------------------------------------------------------Get bookmarks
1.2       tyszkabe   26: 
1.4       tyszkabe   27: sub get_bookmarks {
1.16      tyszkabe   28:     my %bookmark=Apache::lonnet::get('bookmarks',('bookmarks'));
1.5       tyszkabe   29:     return %bookmark;
1.2       tyszkabe   30: }
                     31: 
1.4       tyszkabe   32: # ---------------------------------------------------Construct bookmark editor
1.2       tyszkabe   33: 
                     34: sub construct_editor {
1.9       tyszkabe   35:     my $bookmarks=shift;
1.2       tyszkabe   36:     return(<<END_HTML) 
1.4       tyszkabe   37: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
                     38: <html>
                     39: <head>
                     40: <title>
1.8       tyszkabe   41: Bookmark Tree Viewer/Editor
1.4       tyszkabe   42: </title>
1.16      tyszkabe   43: 
1.18      tyszkabe   44: <script src="/res/adm/pages/bookmarkmenu/bookmarklib.js" language="JavaScript"></script>
1.16      tyszkabe   45: 
1.4       tyszkabe   46: <script LANGUAGE="JavaScript">
1.16      tyszkabe   47: function initialize() {
                     48: window.tree = new newTree();
                     49: //-------------------------------------------------------------------------------
1.9       tyszkabe   50: //                         The FOLLOWING data is supplied by the Perl Module
1.16      tyszkabe   51: //-------------------------------------------------------------------------------
1.9       tyszkabe   52: $bookmarks
1.16      tyszkabe   53: //-------------------------------------------------------------------------------
1.9       tyszkabe   54: //                         The PRECEDING data is supplied by the Perl Module
1.16      tyszkabe   55: //-------------------------------------------------------------------------------
                     56: window.tree.redraw();
1.4       tyszkabe   57: }
1.8       tyszkabe   58: </script>
1.4       tyszkabe   59: </head>
1.16      tyszkabe   60: <FRAMESET rows="25, *, 40, 25" topmargin=0 leftmargin=0 marginheight=0 marginwidth=0 frameborder="0" border="0" framespacing="0" onLoad="Javascript:buildBookmarkMenu();initialize();">
1.4       tyszkabe   61:  <FRAMESET cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
1.16      tyszkabe   62:   <FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
                     63:   <FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
                     64:   <FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
1.4       tyszkabe   65:  </FRAMESET>
1.16      tyszkabe   66:  <FRAMESET cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
                     67:   <FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
1.18      tyszkabe   68:   <FRAME src="/res/adm/pages/bookmarkmenu/blank.html" marginwidth="0" marginheight="0" scrolling="yes">
1.16      tyszkabe   69:   <FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
1.4       tyszkabe   70:  </FRAMESET>
                     71:  <FRAMESET cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
1.16      tyszkabe   72:   <FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
1.18      tyszkabe   73:   <FRAME src="/res/adm/pages/bookmarkmenu/bookmarkmenu_toolbar.html" marginwidth="0" marginheight="0" scrolling="no">
1.16      tyszkabe   74:   <FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
1.4       tyszkabe   75:  </FRAMESET>
                     76:  <FRAMESET cols="25, *, 25" frameborder="0" borders="0" framespacing="0">
1.16      tyszkabe   77:   <FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
                     78:   <FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
                     79:   <FRAME marginwidth="0" marginheight="0" scrolling="no" src="javascript:''">
1.4       tyszkabe   80:  </FRAMESET>
                     81: </FRAMESET>
                     82: </html>
1.2       tyszkabe   83: END_HTML
1.1       tyszkabe   84: }
                     85: 
1.16      tyszkabe   86: # ---------------------------------------------------------------Construct Error window
1.5       tyszkabe   87: 
                     88: sub construct_error {
                     89:   my $error_message=shift;
                     90:   return(<<END_ERROR)
                     91: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
                     92: <html>
                     93:  <head>
                     94:   <title>
                     95:    Bookmark Tree Viewer/Editor  V3
                     96:   </title>
                     97:  </head>
                     98:  <body bgcolor="#BBBBBB">
                     99:   <table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
                    100:    <td>
                    101:     <i>
                    102:      $error_message
                    103:     </i>
                    104:    </td>
                    105:   </table>
                    106:   <center>
                    107:    <form>
                    108:     <input type=button name="close" value="close window" onClick="javascript:window.close();">
                    109:    </form>
                    110:   </center>
                    111:  </body>
                    112: </html>
                    113: END_ERROR
                    114: }
                    115: 
1.16      tyszkabe  116: # --------------------------------------------Construct toolbar (after saving)
1.6       tyszkabe  117: 
                    118: sub construct_toolbar {
                    119:   return(<<END_TOOLBAR)
                    120: <html>
                    121: <body>
1.7       tyszkabe  122: <div align="bottom">
                    123: <center>
                    124: Bookmarks saved. 
1.20      tyszkabe  125: [ <a href="/res/adm/pages/bookmarkmenu/bookmarkmenu_toolbar.html" target="_self">Continue</a> ]
1.7       tyszkabe  126: </center>
                    127: </div>
1.6       tyszkabe  128: </body>
                    129: </html>
                    130: END_TOOLBAR
                    131: }
                    132: 
1.21      tyszkabe  133: # ---------------------------------------------Add bookmark from remote control
                    134: 
                    135: sub add_bookmark {
                    136:     my $location=shift;
                    137:     my $title=shift;
1.22      tyszkabe  138:     my $bookmarks=shift;
                    139:     my $page='';
1.23      harris41  140:     $bookmarks .= "window.tree.bookmarks.addLink(\"$title\",\"$location\");\n";
1.22      tyszkabe  141: #	$marks{'bookmarks'} += qq/\nwindow.tree.bookmarks.addlink("$title","$location");\n/;
1.23      harris41  142:     write_bookmarks($bookmarks);
1.24    ! harris41  143:     $page="<html><body>$bookmarks<p>Bookmarks successfully saved<script language=\"JavaScript\">window.close()</script></body></html>";
1.22      tyszkabe  144:     return($page);
1.21      tyszkabe  145: }
                    146: 
1.16      tyszkabe  147: # ----------------------------------------------------------------Main Handler
1.1       tyszkabe  148: 
                    149: sub handler {
1.6       tyszkabe  150:   my $r=shift;
                    151:   my %marks;
                    152:   my $save_mark;
                    153:   my $page;
                    154:   $r->content_type('text/html');
                    155:   $r->send_http_header;
1.22      tyszkabe  156:   if (defined($ENV{'form.hiddenbookmarks'})) {
                    157:       $marks{'bookmarks'}=$ENV{'form.hiddenbookmarks'};
                    158:       write_bookmarks($marks{'bookmarks'});
                    159:       $page=construct_toolbar();
1.6       tyszkabe  160:   } else {
1.22      tyszkabe  161:       %marks=get_bookmarks();
                    162:       if (exists($marks{"con_lost"})) {
                    163: 	  #$page = construct_editor($marks{'bookmarks'});  # Delete this line and uncomment next
                    164: 	  # in order to re-enable connection detection
                    165: 	  $page=construct_error("Connection broken with home server. Please contact your system administrator");
1.9       tyszkabe  166:       } else {
1.22      tyszkabe  167: 	  if (defined($ENV{'form.address'})) {
                    168: 	      $page=add_bookmark($ENV{'form.address'},$ENV{'form.title'},$marks{'bookmarks'});
1.21      tyszkabe  169: 	  } else {
                    170: 	      if ($marks{'bookmarks'} eq "") {
                    171: 		  $marks{'bookmarks'}=defaultmarks();
                    172: 	      }
                    173: 	      $page = construct_editor($marks{'bookmarks'});
1.10      tyszkabe  174: 	  }
1.9       tyszkabe  175:       }
1.6       tyszkabe  176:   }
                    177:   $r->print($page);
                    178:   return OK;
1.1       tyszkabe  179: }
1.9       tyszkabe  180: 
                    181: ####################################
                    182: #
1.16      tyszkabe  183: #            The following was used for debugging when the bookmarks get corrupted
                    184: #                            ben  10/12/2000
                    185: sub recovermarks {
                    186:     return(<<END_MARKS);
                    187: window.tree.bookmarks.addFolder("Default Bookmarks",true);
                    188: window.tree.bookmarks.p[0].addFolder("Michigan State University",true);
                    189: window.tree.bookmarks.p[0].p[0].addLink("Main Website","http://www.msu.edu");
                    190: window.tree.bookmarks.p[0].p[0].addLink("College of Natural Science","http://www.ns.msu.edu");
                    191: window.tree.bookmarks.p[0].p[0].addLink("College of Engineering","http://www.egr.msu.edu");
                    192: window.tree.bookmarks.p[0].p[0].addLink("Dept. of Mathematics","http://www.math.msu.edu");
                    193: window.tree.bookmarks.p[0].p[0].addLink("Lite Lab","http://www.lite.msu.edu");
                    194: window.tree.bookmarks.p[0].p[0].addLink("Physics and Astronomy","http://www.pa.msu.edu");
                    195: window.tree.bookmarks.p[0].addFolder("Lon-Capa",false);
                    196: window.tree.bookmarks.p[0].p[1].addLink("Lon-Capa org","http://lon-capa.org");
                    197: window.tree.bookmarks.p[0].p[1].addLink("Lite Lab","http://www.lite.msu.edu");
1.17      tyszkabe  198: lwindow.tree.bookmarks.p[0].addLink("Redhat","http://redhat.com");
1.16      tyszkabe  199: window.tree.bookmarks.p[0].addLink("Debian","http://debian.org");
                    200: window.tree.bookmarks.addLink("Other Bookmarks","http://kirk.lite.msu.edu");
                    201: END_MARKS
                    202: }
                    203: #
                    204: #
                    205: ##########################################
                    206: 
                    207: ##########################################
                    208: #
                    209: #          Here is a listing of default bookmarks. It may be used to replace 'recover'
                    210: #          eventually, but for now these will load after all bookmarks have been deleted.
1.10      tyszkabe  211: #                ben 10/12/2000
                    212: sub defaultmarks {
                    213:     return(<<END_MARKS);
1.16      tyszkabe  214: window.tree.bookmarks.addFolder("Default Bookmarks",true);
                    215: window.tree.bookmarks.p[0].addFolder("Michigan State University",true);
                    216: window.tree.bookmarks.p[0].p[0].addLink("Main Website","http://www.msu.edu");
                    217: window.tree.bookmarks.p[0].p[0].addLink("College of Natural Science","http://www.ns.msu.edu");
                    218: window.tree.bookmarks.p[0].p[0].addLink("College of Engineering","http://www.egr.msu.edu");
                    219: window.tree.bookmarks.p[0].p[0].addLink("Dept. of Mathematics","http://www.math.msu.edu");
                    220: window.tree.bookmarks.p[0].p[0].addLink("Lite Lab","http://www.lite.msu.edu");
                    221: window.tree.bookmarks.p[0].p[0].addLink("Physics and Astronomy","http://www.pa.msu.edu");
                    222: window.tree.bookmarks.p[0].addFolder("Lon-Capa",false);
                    223: window.tree.bookmarks.p[0].p[1].addLink("Lon-Capa org","http://lon-capa.org");
                    224: window.tree.bookmarks.p[0].p[1].addLink("Lite Lab","http://www.lite.msu.edu");
                    225: window.tree.bookmarks.p[0].addLink("Redhat","http://redhat.com");
                    226: window.tree.bookmarks.p[0].addLink("Debian","http://debian.org");
                    227: window.tree.bookmarks.addLink("Other Bookmarks","http://kirk.lite.msu.edu");
1.10      tyszkabe  228: END_MARKS
                    229: }
1.1       tyszkabe  230: 
                    231: 1;
                    232: __END__
1.8       tyszkabe  233: 
                    234: 
                    235: 
                    236: 
                    237: 

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