--- loncom/interface/lonmenu.pm	2011/09/27 14:50:12	1.351
+++ loncom/interface/lonmenu.pm	2012/05/14 13:58:04	1.369.2.2
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.351 2011/09/27 14:50:12 raeburn Exp $
+# $Id: lonmenu.pm,v 1.369.2.2 2012/05/14 13:58:04 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -153,9 +153,9 @@ use Apache::lonhtmlcommon();
 use Apache::loncommon();
 use Apache::lonenc();
 use Apache::lonlocal;
+use Apache::lonmsg();
 use LONCAPA qw(:DEFAULT :match);
 use HTML::Entities();
-use Apache::lonwishlist();
 
 use vars qw(@desklines %category_names %category_members %category_positions 
             $readdesk @primary_menu @secondary_menu);
@@ -334,9 +334,8 @@ sub secondary_menu {
             and (   $env{'request.noversionuri'} eq '' 
                  || !defined($env{'request.noversionuri'}))) 
         {
-            ($escurl = $env{'request.filename'}) =~ 
-                s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
-
+            my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+            ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
             $escurl  = &escape($escurl);
         }    
         $menu =~ s/\[url\]/$escurl/g;
@@ -411,7 +410,7 @@ sub innerregister {
 
         my $hwkadd='';
         if ($env{'request.symb'} ne '' &&
-	    $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
+	    $env{'request.filename'}=~/$LONCAPA::assess_re/) {
 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
 		$hwkadd.=&switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
                        "gocmd('/adm/grades','gradingmenu')",
@@ -428,6 +427,12 @@ sub innerregister {
 			     "gocmd('/adm/parmset','set')",
 			     'Content Settings');
 	}
+        if ($env{'request.symb'}=~/^uploaded/ &&
+            &Apache::lonnet::allowed('mdc',$crs)) {
+            $hwkadd.=&switch('','',7,4,'docs.png','Folder/Page Content','parms[_2]',
+                             "gocmd('/adm/coursedocs','direct')",
+                             'Folder/Page Content');
+        }
 # -- End Homework
         ###
         ### Determine whether or not to display the 'cstr' button for this
@@ -447,7 +452,7 @@ sub innerregister {
 #
                 # Set defaults for authors
                 my ($top,$bottom) = ('con-','struct');
-                my $action = "go('/priv/".$env{'user.name'}."');";
+                my $action = "go('/priv/".$env{'user.domain'}.'/'.$env{'user.name'}."');";
                 my $cadom  = $env{'request.role.domain'};
                 my $caname = $env{'user.name'};
                 my $desc = "Enter my construction space";
@@ -455,12 +460,12 @@ sub innerregister {
                 if ($env{'request.role'} =~ /^ca/) { 
                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                     ($top,$bottom) = ('co con-','struct');
-                    $action = "go('/priv/".$caname."');";
+                    $action = "go('/priv/".$cadom.'/'.$caname."');";
                     $desc = "Enter construction space as co-author";
                 } elsif ($env{'request.role'} =~ /^aa/) {
                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                     ($top,$bottom) = ('co con-','struct');
-                    $action = "go('/priv/".$caname."');";
+                    $action = "go('/priv/".$cadom.'/'.$caname."');";
                     $desc = "Enter construction space as assistant co-author";
                 }
                 # Check that we are on the correct machine
@@ -493,9 +498,13 @@ sub innerregister {
                     $uploaded = &is_course_upload($file,$cnum,$cdom);
                 }
                 if (!$uploaded) {
-                    $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
+
+                    $file=~s{^(priv/$match_domain/$match_username)}{/$1};
+                    $file=~s{^($match_domain/$match_username)}{/priv/$1};
+
                     # Check that the user has permission to edit this resource
-                    ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
+                    my $setpriv = 1;
+                    ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$setpriv);
                     if (defined($cfudom)) {
 		        $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
 		        my $allowed=0;
@@ -576,9 +585,11 @@ sub innerregister {
 #
 # We are in construction space
 #
-	    my ($uname,$thisdisfn) =
-		($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
-            my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
+
+            my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+	    my ($udom,$uname,$thisdisfn) =
+		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
+            my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
             if ($currdir =~ m-/$-) {
                 $is_const_dir = 1;
             } else {
@@ -590,10 +601,10 @@ sub innerregister {
 #
                 $menuitems=(<<ENDMENUITEMS);
 s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
-s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
-s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
-s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
-s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
+s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
+s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
+s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
+s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
 ENDMENUITEMS
             }
                 if (ref($bread_crumbs) eq 'ARRAY') {
@@ -616,14 +627,9 @@ c&6&3
 c&8&1
 c&8&2
 s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
+s&9&1&sbkm.png&Bookmark&set[_1]bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
+
 ENDMENUITEMS
-            if (&Apache::lonnet::allowed('bre', $env{'request.course.id'}) eq 'F' && $env{'request.uri'} =~ /^\/res/) {
-                # wishlist is only available for users with access to resource-pool
-                # and links can only be set for resources within the resource-pool
-                $menuitems .= (<<ENDMENUITEMS);
-s&9&1&wishlist-link.png&Wishlist&wishlistlink[_2]&set_wishlistlink()&Set a link for this resource to wishlist&&1
-ENDMENUITEMS
-            }
 
 my $currentURL = &Apache::loncommon::get_symb();
 my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
@@ -653,12 +659,6 @@ ENDREALRES
 	    $menuitems .= (<<ENDMENUITEMS);
 s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
 ENDMENUITEMS
-            if (&Apache::lonnet::allowed('bre', $env{'request.course.id'}) eq 'F') {
-                # wishlist is only available for users with access to resource-pool
-                $menuitems .= (<<ENDMENUITEMS);
-s&9&1&wishlist-link.png&Wishlist&wishlistlink[_2]&set_wishlistlink()&Set a link for this resource to wishlist&&1
-ENDMENUITEMS
-            }
 	}
         my $buttons='';
         foreach (split(/\n/,$menuitems)) {
@@ -703,7 +703,7 @@ ENDMENUITEMS
             
             unless ($env{'request.noversionuri'}=~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
-                    'advtools', @inlineremote[61,71,72,73,92]);
+                    'advtools', @inlineremote[61,71,72,73,74,92]);
             }
         }
     }
@@ -749,6 +749,164 @@ sub edit_course_upload {
     return $cfile;
 }
 
+sub startupremote {
+    my ($lowerurl)=@_;
+    if ($env{'environment.remote'} eq 'off') {
+     return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
+    }
+#
+# The Remote actually gets launched!
+#
+    my $configmenu=&rawconfig();
+    my $esclowerurl=&escape($lowerurl);
+    my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
+    return(<<ENDREMOTESTARTUP);
+<script type="text/javascript">
+// <![CDATA[
+var timestart;
+function wheelswitch() {
+    if (typeof(document.wheel) != 'undefined') {
+        if (typeof(document.wheel.spin) != 'undefined') {
+            var date=new Date();
+            var waited=Math.round(30-((date.getTime()-timestart)/1000));
+            document.wheel.spin.value=$message;
+        }
+    }
+   if (window.status=='|') {
+      window.status='/';
+   } else {
+      if (window.status=='/') {
+         window.status='-';
+      } else {
+         if (window.status=='-') {
+            window.status='\\\\';
+         } else {
+            if (window.status=='\\\\') { window.status='|'; }
+         }
+      }
+   }
+}
+
+// ---------------------------------------------------------- The wait function
+var canceltim;
+function wait() {
+   if ((menuloaded==1) || (tim==1)) {
+      window.status='Done.';
+      if (tim==0) {
+         clearTimeout(canceltim);
+         $configmenu
+         window.location='$lowerurl';
+      } else {
+          window.location='/adm/remote?action=collapse&url=$esclowerurl';
+      }
+   } else {
+      wheelswitch();
+      setTimeout('wait();',200);
+   }
+}
+
+function main() {
+   canceltim=setTimeout('tim=1;',30000);
+   window.status='-';
+   var date=new Date();
+   timestart=date.getTime();
+   wait();
+}
+
+// ]]>
+</script>
+ENDREMOTESTARTUP
+}
+
+sub setflags() {
+    return(<<ENDSETFLAGS);
+<script type="text/javascript">
+// <![CDATA[
+    menuloaded=0;
+    tim=0;
+// ]]>
+</script>
+ENDSETFLAGS
+}
+
+sub maincall() {
+    if ($env{'environment.remote'} eq 'off') { return ''; }
+    return(<<ENDMAINCALL);
+<script type="text/javascript">
+// <![CDATA[
+    main();
+// ]]>
+</script>
+ENDMAINCALL
+}
+
+sub load_remote_msg {
+    my ($lowerurl)=@_;
+
+    if ($env{'environment.remote'} eq 'off') { return ''; }
+
+    my $esclowerurl=&escape($lowerurl);
+    my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
+                ,'<a href="/adm/remote?action=collapse&amp;url='.$esclowerurl.'">'
+                ,'</a>');
+    return(<<ENDREMOTEFORM);
+<p>
+<form name="wheel">
+<input name="spin" type="text" size="60" />
+</form>
+</p>
+<p>$link</p>
+ENDREMOTEFORM
+}
+
+sub get_menu_name {
+    my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
+    $hostid =~ s/\W//g;
+    return 'LCmenu'.$hostid;
+}
+
+
+sub reopenmenu {
+   if ($env{'environment.remote'} eq 'off') { return ''; }
+   my $menuname = &get_menu_name();
+   my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
+   return('window.open('.$nothing.',"'.$menuname.'","",false);');
+}
+
+
+sub open {
+    my $returnval='';
+    if ($env{'environment.remote'} eq 'off') {
+        return
+        '<script type="text/javascript">'."\n"
+       .'// <![CDATA['."\n"
+       .'self.name="loncapaclient";'."\n"
+       .'// ]]>'."\n"
+       .'</script>';
+    }
+    my $menuname = &get_menu_name();
+
+#    unless (shift eq 'unix') {
+# resizing does not work on linux because of virtual desktop sizes
+#       $returnval.=(<<ENDRESIZE);
+#if (window.screen) {
+#    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
+#    self.moveTo(190,15);
+#}
+#ENDRESIZE
+#    }
+    $returnval=(<<ENDOPEN);
+// <![CDATA[
+window.status='Opening LON-CAPA Remote Control';
+var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
+"height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
+self.name='loncapaclient';
+// ]]>
+ENDOPEN
+    return '<script type="text/javascript">'.$returnval.'</script>';
+}
+
+
 # ================================================================== Raw Config
 
 sub clear {
@@ -1001,6 +1159,7 @@ sub rawconfig {
                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                     }                       
                     $act =~ s/\$caname/$caname/g;
+                    $act =~ s/\$cadom/$cadom/g;
                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 		    my $allowed=0;
 		    my @ids=&Apache::lonnet::current_machine_ids();
@@ -1063,6 +1222,28 @@ sub check_for_rcrs {
     return $showreqcrs;
 }
 
+# ======================================================================= Close
+
+sub close {
+    if ($env{'environment.remote'} eq 'off') { return ''; }
+    my $menuname = &get_menu_name();
+    return(<<ENDCLOSE);
+<script type="text/javascript">
+// <![CDATA[
+window.status='Accessing Remote Control';
+menu=window.open("/adm/rat/empty.html","$menuname",
+                 "height=350,width=150,scrollbars=no,menubar=no");
+window.status='Disabling Remote Control';
+menu.active=0;
+menu.autologout=0;
+window.status='Closing Remote Control';
+menu.close();
+window.status='Done.';
+// ]]>
+</script>
+ENDCLOSE
+}
+
 sub dc_popup_js {
     my %lt = &Apache::lonlocal::texthash(
                                           more => '(More ...)',
@@ -1074,13 +1255,13 @@ function showCourseID() {
     document.getElementById('dccid').style.display='block';
     document.getElementById('dccid').style.textAlign='left';
     document.getElementById('dccid').style.textFace='normal';
-    document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();">$lt{'less'}</a>';
+    document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
     return;
 }
 
 function hideCourseID() {
     document.getElementById('dccid').style.display='none';
-    document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()">$lt{'more'}</a>';
+    document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
     return;
 }
 
@@ -1116,15 +1297,26 @@ sub utilityfunctions {
     my $end_page_annotate = 
         &Apache::loncommon::end_page({'js_ready' => 1});
 
+    my $start_page_bookmark =
+        &Apache::loncommon::start_page('Bookmarks',undef,
+                                       {'only_body' => 1,
+                                        'js_ready'  => 1,
+                                        'bgcolor'   => '#BBBBBB',});
+
+    my $end_page_bookmark =
+        &Apache::loncommon::end_page({'js_ready' => 1});
+
     my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
                          &mt('Switch server?');
 
+    my $esc_url=&escape($currenturl);
+    my $esc_symb=&escape($currentsymb);
 
 return (<<ENDUTILITY)
 
-    var currentURL="$currenturl";
-    var reloadURL="$currenturl";
-    var currentSymb="$currentsymb";
+    var currentURL=unescape("$esc_url");
+    var reloadURL=unescape("$esc_url");
+    var currentSymb=unescape("$esc_symb");
 
 $dc_popup_cid
 
@@ -1217,7 +1409,7 @@ function golist(url) {
 
 
 function catalog_info() {
-   loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
+   openMyModal(window.location.pathname+'.meta',500,400,'yes');
 }
 
 function chat_win() {
@@ -1230,6 +1422,13 @@ function group_chat(group) {
    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 }
 
+function edit_bookmarks() {
+   go('');
+   w_BookmarkPal_flag=1;
+   bookmarkpal=window.open("/adm/bookmarks",
+               "BookmarkPal", "width=500,height=505,scrollbars=0");
+}
+
 function annotate() {
    w_Annotator_flag=1;
    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
@@ -1243,29 +1442,26 @@ function annotate() {
    annotator.document.close();
 }
 
-function set_wishlistlink(title, path) {
-    if (!title) {
-        title = document.title;
-        title = title.replace(/^LON-CAPA /,'');
-    }
-    if (!path) {
-        path = location.pathname;
-    }
-    Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
-                      'wishlistNewLink','width=560,height=350,scrollbars=0');
-}
-
-function open_Wishlist_Import(rat) {
-   var newWin;
-   if (rat) {
-       newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
-                            'wishlistImport','scrollbars=1,resizable=1,menubar=0');
-   }
-   else {
-       newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import',
-                            'wishlistImport','scrollbars=1,resizable=1,menubar=0');
-   }
-   newWin.focus();
+function set_bookmark() {
+   go('');
+   clienttitle=document.title;
+   clienthref=location.pathname;
+   w_bmquery_flag=1;
+   bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
+   bmquery.document.write(
+   '$start_page_bookmark'
+   +'<center><form method="post"'
+   +' name="newlink" action="/adm/bookmarks" target="bmquery" '
+   +'> <table width="340" height="150" '
+   +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
+   +'type="text" name="title" size="45" value="'+clienttitle+'" />'
+   +'<br />Address:<br /><input type="text" name="address" size="45" '
+   +'value="'+clienthref+'" /><br /><center><input type="submit" '
+   +'value="Save" /> <input type="button" value="Close" '
+   +'onclick="javascript:window.close();" /></center></td>'
+   +'</tr></table></form></center>'
+   +'$end_page_bookmark' );
+   bmquery.document.close();
 }
 
 ENDUTILITY
@@ -1500,7 +1696,7 @@ sub jump_to_role {
                 orlb => 'Enter a specific section, or leave blank for no section.',
                 avai => 'Available sections are:',
                 youe => 'You entered an invalid section choice:',
-                plst => 'Please try again',
+                plst => 'Please try again.',
                 role => 'The role you selected is not permitted to view the current page.',
                 swit => 'Switch role, but display Main Menu page instead?',
     );
@@ -1655,11 +1851,13 @@ sub required_privs {
              '/adm/populate'     => 'cst',
              '/adm/trackstudent' => 'vsa',
              '/adm/statistics'   => 'vgr',
+             '/adm/setblock'     => 'dcm',
+             '/adm/coursedocs'   => 'mdc',
            };
     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
-        $privs->{'/adm/classcalc'}   => 'vgr',
-        $privs->{'/adm/assesscalc'}  => 'vgr',
-        $privs->{'/adm/studentcalc'} => 'vgr';
+        $privs->{'/adm/classcalc'}   = 'vgr',
+        $privs->{'/adm/assesscalc'}  = 'vgr',
+        $privs->{'/adm/studentcalc'} = 'vgr';
     }
     return $privs;
 }