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

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

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