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

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;
        !           138:     %marks=get_bookmarks();
        !           139:     if (exists($marks{"con_lost"})) {
        !           140: 	$page=construct_error("Connection broken with home server. Please contact your system administrator");
        !           141:     } else {
        !           142: 	$marks{'bookmarks'}="$marks{'bookmarks'}\n window.tree.bookmarks.addlink(\"$title\",\"$location\");";
        !           143: 	write_bookmarks(%marks);
        !           144: 	$page="Bookmarks successfully saved";   # UPDATE THIS ONCE DEBUGGED.
        !           145:     }
        !           146: }
        !           147: 
1.16      tyszkabe  148: # ----------------------------------------------------------------Main Handler
1.1       tyszkabe  149: 
                    150: sub handler {
1.6       tyszkabe  151:   my $r=shift;
                    152:   my %marks;
                    153:   my $save_mark;
                    154:   my $page;
                    155:   $r->content_type('text/html');
                    156:   $r->send_http_header;
1.21    ! tyszkabe  157:   if (defined($ENV{'form.addmark_loc'})) {
        !           158:       $page=add_bookmark($ENV{'form.addmark_loc'},$ENV{'form.addmark_title'});
1.6       tyszkabe  159:   } else {
1.21    ! tyszkabe  160:       if (defined($ENV{'form.hiddenbookmarks'})) {
        !           161: 	  $marks{'bookmarks'}=$ENV{'form.hiddenbookmarks'};
        !           162: 	  write_bookmarks($marks{'bookmarks'});
        !           163: 	  if ($marks{'bookmarks'} eq 'recover') {    #if statement is all debug stuff
        !           164: 	      my $recover=defaultmarks();
        !           165: 	      $r->print("BOOKMARK RECOVERY");
        !           166: 	      write_bookmarks($recover);
        !           167: 	  }
        !           168: 	  $page=construct_toolbar();
1.9       tyszkabe  169:       } else {
1.21    ! tyszkabe  170: 	  %marks=get_bookmarks();
        !           171: 	  if (exists($marks{"con_lost"})) {
        !           172: 	      #$page = construct_editor($marks{'bookmarks'});  # Delete this line and uncomment next
        !           173: 	      # in order to re-enable connection detection
        !           174: 	      $page=construct_error("Connection broken with home server. Please contact your system administrator");
        !           175: 	  } else {
        !           176: 	      if ($marks{'bookmarks'} eq "") {
        !           177: 		  $marks{'bookmarks'}=defaultmarks();
        !           178: 	      }
        !           179: 	      $page = construct_editor($marks{'bookmarks'});
1.10      tyszkabe  180: 	  }
1.9       tyszkabe  181:       }
1.6       tyszkabe  182:   }
                    183:   $r->print($page);
                    184:   return OK;
1.1       tyszkabe  185: }
1.9       tyszkabe  186: 
                    187: ####################################
                    188: #
1.16      tyszkabe  189: #            The following was used for debugging when the bookmarks get corrupted
                    190: #                            ben  10/12/2000
                    191: sub recovermarks {
                    192:     return(<<END_MARKS);
                    193: window.tree.bookmarks.addFolder("Default Bookmarks",true);
                    194: window.tree.bookmarks.p[0].addFolder("Michigan State University",true);
                    195: window.tree.bookmarks.p[0].p[0].addLink("Main Website","http://www.msu.edu");
                    196: window.tree.bookmarks.p[0].p[0].addLink("College of Natural Science","http://www.ns.msu.edu");
                    197: window.tree.bookmarks.p[0].p[0].addLink("College of Engineering","http://www.egr.msu.edu");
                    198: window.tree.bookmarks.p[0].p[0].addLink("Dept. of Mathematics","http://www.math.msu.edu");
                    199: window.tree.bookmarks.p[0].p[0].addLink("Lite Lab","http://www.lite.msu.edu");
                    200: window.tree.bookmarks.p[0].p[0].addLink("Physics and Astronomy","http://www.pa.msu.edu");
                    201: window.tree.bookmarks.p[0].addFolder("Lon-Capa",false);
                    202: window.tree.bookmarks.p[0].p[1].addLink("Lon-Capa org","http://lon-capa.org");
                    203: window.tree.bookmarks.p[0].p[1].addLink("Lite Lab","http://www.lite.msu.edu");
1.17      tyszkabe  204: lwindow.tree.bookmarks.p[0].addLink("Redhat","http://redhat.com");
1.16      tyszkabe  205: window.tree.bookmarks.p[0].addLink("Debian","http://debian.org");
                    206: window.tree.bookmarks.addLink("Other Bookmarks","http://kirk.lite.msu.edu");
                    207: END_MARKS
                    208: }
                    209: #
                    210: #
                    211: ##########################################
                    212: 
                    213: ##########################################
                    214: #
                    215: #          Here is a listing of default bookmarks. It may be used to replace 'recover'
                    216: #          eventually, but for now these will load after all bookmarks have been deleted.
1.10      tyszkabe  217: #                ben 10/12/2000
                    218: sub defaultmarks {
                    219:     return(<<END_MARKS);
1.16      tyszkabe  220: window.tree.bookmarks.addFolder("Default Bookmarks",true);
                    221: window.tree.bookmarks.p[0].addFolder("Michigan State University",true);
                    222: window.tree.bookmarks.p[0].p[0].addLink("Main Website","http://www.msu.edu");
                    223: window.tree.bookmarks.p[0].p[0].addLink("College of Natural Science","http://www.ns.msu.edu");
                    224: window.tree.bookmarks.p[0].p[0].addLink("College of Engineering","http://www.egr.msu.edu");
                    225: window.tree.bookmarks.p[0].p[0].addLink("Dept. of Mathematics","http://www.math.msu.edu");
                    226: window.tree.bookmarks.p[0].p[0].addLink("Lite Lab","http://www.lite.msu.edu");
                    227: window.tree.bookmarks.p[0].p[0].addLink("Physics and Astronomy","http://www.pa.msu.edu");
                    228: window.tree.bookmarks.p[0].addFolder("Lon-Capa",false);
                    229: window.tree.bookmarks.p[0].p[1].addLink("Lon-Capa org","http://lon-capa.org");
                    230: window.tree.bookmarks.p[0].p[1].addLink("Lite Lab","http://www.lite.msu.edu");
                    231: window.tree.bookmarks.p[0].addLink("Redhat","http://redhat.com");
                    232: window.tree.bookmarks.p[0].addLink("Debian","http://debian.org");
                    233: window.tree.bookmarks.addLink("Other Bookmarks","http://kirk.lite.msu.edu");
1.10      tyszkabe  234: END_MARKS
                    235: }
1.1       tyszkabe  236: 
                    237: 1;
                    238: __END__
1.8       tyszkabe  239: 
                    240: 
                    241: 
                    242: 
                    243: 

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