--- loncom/interface/loncommon.pm	2009/10/12 08:01:08	1.896
+++ loncom/interface/loncommon.pm	2009/10/31 16:17:07	1.907
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.896 2009/10/12 08:01:08 amueller Exp $
+# $Id: loncommon.pm,v 1.907 2009/10/31 16:17:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -482,7 +482,7 @@ ENDAUTHORBRW
 }
 
 sub coursebrowser_javascript {
-    my ($domainfilter,$sec_element,$formname)=@_;
+    my ($domainfilter,$sec_element,$formname,$role_element)=@_;
     my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Community - for which you wish to add/modify a user role.');
     my $id_functions = &javascript_index_functions();
     my $output = '
@@ -548,8 +548,8 @@ sub coursebrowser_javascript {
     }
 $id_functions
 ENDSTDBRW
-    if ($sec_element ne '') {
-        $output .= &setsec_javascript($sec_element,$formname);
+    if (($sec_element ne '') || ($role_element ne '')) {
+        $output .= &setsec_javascript($sec_element,$formname,$role_element);
     }
     $output .= '
 // ]]>
@@ -661,7 +661,28 @@ ENDUSERBRW
 }
 
 sub setsec_javascript {
-    my ($sec_element,$formname) = @_;
+    my ($sec_element,$formname,$role_element) = @_;
+    my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
+        $communityrolestr);
+    if ($role_element ne '') {
+        my @allroles = ('st','ta','ep','in','ad');
+        foreach my $crstype ('Course','Community') {
+            if ($crstype eq 'Community') {
+                foreach my $role (@allroles) {
+                    push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
+                }
+                push(@communityrolenames,&Apache::lonnet::plaintext('co'));
+            } else {
+                foreach my $role (@allroles) {
+                    push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
+                }
+                push(@courserolenames,&Apache::lonnet::plaintext('cc'));
+            }
+        }
+        $rolestr = '"'.join('","',@allroles).'"';
+        $courserolestr = '"'.join('","',@courserolenames).'"';
+        $communityrolestr = '"'.join('","',@communityrolenames).'"';
+    }
     my $setsections = qq|
 function setSect(sectionlist) {
     var sectionsArray = new Array();
@@ -695,16 +716,57 @@ function setSect(sectionlist) {
         }
     }
 }
+
+function setRole(crstype) {
 |;
+    if ($role_element eq '') {
+        $setsections .= '    return;
+}
+';
+    } else {
+        $setsections .= qq|
+    var elementLength = document.$formname.$role_element.length;
+    var allroles = Array($rolestr);
+    var courserolenames = Array($courserolestr);
+    var communityrolenames = Array($communityrolestr);
+    if (elementLength != undefined) {
+        if (document.$formname.$role_element.options[5].value == 'cc') {
+            if (crstype == 'Course') {
+                return;
+            } else {
+                allroles[5] = 'co';
+                for (var i=0; i<6; i++) {
+                    document.$formname.$role_element.options[i].value = allroles[i];
+                    document.$formname.$role_element.options[i].text = communityrolenames[i];
+                }
+            }
+        } else {
+            if (crstype == 'Community') {
+                return;
+            } else {
+                allroles[5] = 'cc';
+                for (var i=0; i<6; i++) {
+                    document.$formname.$role_element.options[i].value = allroles[i];
+                    document.$formname.$role_element.options[i].text = courserolenames[i];
+                }
+            }
+        }
+    }
+    return;
+}
+|;
+    }
     return $setsections;
 }
 
-
 sub selectcourse_link {
    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
    my $linktext = &mt('Select Course');
    if ($selecttype eq 'Community') {
        $linktext = &mt('Select Community'); 
+   } elsif ($selecttype eq 'Course/Community') {
+       $linktext = &mt('Select Course/Community');
+       $selecttype = 'Course';
    }
    return '<span class="LC_nobreak">'
          ."<a href='"
@@ -1109,7 +1171,7 @@ sub general_help {
     my $helptopic='Student_Intro';
     if ($env{'request.role'}=~/^(ca|au)/) {
 	$helptopic='Authoring_Intro';
-    } elsif ($env{'request.role'}=~/^cc/) {
+    } elsif ($env{'request.role'}=~/^(cc|co)/) {
 	$helptopic='Course_Coordination_Intro';
     } elsif ($env{'request.role'}=~/^dc/) {
         $helptopic='Domain_Coordination_Intro';
@@ -3670,6 +3732,7 @@ sub findallcourses {
         if (!%roles) {
             %roles = (
                        cc => 1,
+                       co => 1,
                        in => 1,
                        ep => 1,
                        ta => 1,
@@ -4397,6 +4460,9 @@ sub bodytag {
         if ($env{'request.role'} !~ /^cr/) {
             $role = &Apache::lonnet::plaintext($role,&course_type());
         }
+        if ($env{'request.course.sec'}) {
+            $role .= ('&nbsp;'x2).'-&nbsp;'.&mt('section:').'&nbsp;'.$env{'request.course.sec'};
+        }   
 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
     } else {
         $role = &Apache::lonnet::plaintext($role);
@@ -4436,53 +4502,49 @@ sub bodytag {
         $dc_info = '('.$dc_info.')';
     }
 
-    $role = "($role)" if $role;
+    $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
 
     if ($env{'environment.remote'} eq 'off') {
         # No Remote
-        if ($env{'request.state'} eq 'construct') {
-            $forcereg=1;
-        }
+        if ($no_nav_bar) { return $bodytag; } 
 
-    #    if ($env{'request.state'} eq 'construct') {
-    #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
-    #    }
+        if ($env{'request.state'} eq 'construct') { $forcereg=1; }
 
-        my $titletable = '<table id="LC_title_bar">'
-                            ."<tr><td> $titleinfo $dc_info</td>"
-                            .'</tr></table>';
+        #    if ($env{'request.state'} eq 'construct') {
+        #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
+        #    }
 
-        if ($no_nav_bar) {
-            $bodytag .= $titletable;
-        } else {
-            $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
-                <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
+        $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
+            <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
 
-#SD $titletable is obsolete
-#SD            if ($env{'request.state'} eq 'construct') {
-#SD                $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$titletable);
-#SD            } else {
-#SD                $bodytag .= &Apache::lonmenu::menubuttons($forcereg).$titletable;
-#SD            }
-               if (   $env{'form.inhibitmenu'} eq 'yes' 
-                   || $ENV{'REQUEST_URI'} eq '/adm/logout'
-                   || $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
-                   
-                   return $bodytag;
-               }
+        if (   $env{'form.inhibitmenu'} eq 'yes' 
+            || $ENV{'REQUEST_URI'} eq '/adm/logout'
+            || $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
+
+            return $bodytag;
+        }
+
+        $bodytag .= Apache::lonhtmlcommon::scripttag(
+            Apache::lonmenu::utilityfunctions(), 'start');
 
-               $bodytag .= Apache::lonhtmlcommon::scripttag(
-                                Apache::lonmenu::utilityfunctions(),
-                                'start');
-               $bodytag .= Apache::lonmenu::primary_menu();
-               $bodytag .= Apache::lonmenu::secondary_menu();
-               #SD remove next line
-               #$bodytag .= Apache::lonmenu::menubuttons($forcereg);
-               $bodytag .= Apache::lonmenu::serverform();
-               $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
-               $bodytag .= Apache::lonmenu::innerregister($forcereg) if $forcereg;
+        $bodytag .= Apache::lonmenu::primary_menu();
+
+        #don't show menus for public users
+        if($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public'){
+            $bodytag .= Apache::lonmenu::secondary_menu();
+            $bodytag .= Apache::lonmenu::serverform();
+            $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
+            $bodytag .= Apache::lonmenu::innerregister($forcereg) if $forcereg;
+        }else{
+            # this is to seperate menu from content when there's no secondary
+            # menu. Especially needed for public accessible ressources.
+            $bodytag .= '<hr style="clear:both" />';
+            $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
         }
+
+        #SD testing
+        #$bodytag .= Apache::lonmenu::menubuttons($forcereg);
         return $bodytag;
     }
 
@@ -4501,7 +4563,7 @@ sub bodytag {
 	       :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
     $bodytag .= qq|<div id="LC_nav_bar">$name $role
             <em>$realm</em> $dc_info </div>
-            <ol class="LC_smallMenu LC_right">
+            <ol class="LC_primary_menu LC_right">
                 <li>$menu</li>
             </ol>| unless $env{'form.inhibitmenu'};
     #
@@ -4881,7 +4943,10 @@ table#LC_mainmenu td.LC_mainmenu_column
  clear:both;
  background: $sidebg;
  border-bottom: 1px solid $lg_border_color;
- line-height: 32px; 
+ line-height: 2.5em; 
+ /* SD working here
+ height: 2.5em;
+ overflow: hidden; */
  margin: 0;
  padding: 0;
 }
@@ -4990,12 +5055,14 @@ table.LC_data_table tr.LC_odd_row > td,
 table.LC_pick_box tr > td.LC_odd_row {
   background-color: $data_table_light;
   padding: 2px;
+  vertical-align: top;
 }
 
 table.LC_data_table tr.LC_even_row > td,
 table.LC_pick_box tr > td.LC_even_row {
   background-color: $data_table_dark;
   padding: 2px;
+  vertical-align: top;
 }
 
 table.LC_data_table tr.LC_data_table_highlight td {
@@ -5142,7 +5209,7 @@ table.LC_mail_list tr.LC_mail_other:hove
 
 table.LC_data_table tr > td.LC_browser_file,
 table.LC_data_table tr > td.LC_browser_file_published {
-  background: #CCFF88;
+  background: #AAEE77;
 }
 
 table.LC_data_table tr > td.LC_browser_file_locked,
@@ -5151,16 +5218,16 @@ table.LC_data_table tr > td.LC_browser_f
 }
 
 table.LC_data_table tr > td.LC_browser_file_obsolete {
-  background: #AAAAAA;
+  background: #888888;
 }
 
 table.LC_data_table tr > td.LC_browser_file_modified,
 table.LC_data_table tr > td.LC_browser_file_metamodified {
-  background: #FFFF77;
+  background: #F8F866;
 }
 
 table.LC_data_table tr.LC_browser_folder > td {
-  background: #CCCCFF;
+  background: #E0E8FF;
 }
 
 table.LC_data_table tr > td.LC_roles_is {
@@ -5302,7 +5369,7 @@ table.LC_pick_box {
 table.LC_pick_box td.LC_pick_box_title {
   background: $sidebg;
   font-weight: bold;
-  text-align: right;
+  text-align: left;
   vertical-align: top;
   width: 184px;
   padding: 8px;
@@ -5340,40 +5407,6 @@ table.LC_pick_box td.LC_oddrow_value {
   background-color: $data_table_light;
 }
 
-table.LC_helpform_receipt {
-  width: 620px;
-  border-collapse: separate;
-  background: white;
-  border: 1px solid black;
-  border-spacing: 1px;
-}
-
-table.LC_helpform_receipt td.LC_pick_box_title {
-  background: $tabbg;
-  font-weight: bold;
-  text-align: right;
-  width: 184px;
-  padding: 8px;
-}
-
-table.LC_helpform_receipt td.LC_evenrow_value {
-  text-align: left;
-  padding: 8px;
-  background-color: $data_table_light;
-}
-
-table.LC_helpform_receipt td.LC_oddrow_value {
-  text-align: left;
-  padding: 8px;
-  background-color: $data_table_light;
-}
-
-table.LC_helpform_receipt td.LC_pick_box_separator {
-  padding: 0;
-  height: 1px;
-  background: black;
-}
-
 span.LC_helpform_receipt_cat {
   font-weight: bold;
 }
@@ -5830,14 +5863,14 @@ div.LC_createcourse {
 # --------------------------*/
 
 a:hover,
-ol.LC_smallMenu a:hover,
+ol.LC_primary_menu a:hover,
 ol#LC_MenuBreadcrumbs a:hover,
 ol#LC_PathBreadcrumbs a:hover,
-ul#LC_TabMainMenuContent a:hover,
+ul#LC_secondary_menu a:hover,
 .LC_FormSectionClearButton input:hover
 ul.LC_TabContent   li:hover a {
 	color:#BF2317;
-        text-decoration:none;
+    text-decoration:none;
 }
 
 h1 {
@@ -5910,7 +5943,7 @@ fieldset > legend {
     font-style: normal;
 }
 
-ol.LC_smallMenu {
+ol.LC_primary_menu {
     float: right;
     margin: 0.2em 0 0 0;
 }
@@ -5919,23 +5952,23 @@ ol#LC_PathBreadcrumbs {
 	margin: 0;
 }
 
-ol.LC_smallMenu li {
+ol.LC_primary_menu li {
 	display: inline;
 	padding: 5px 5px 0 10px;
 	vertical-align: top;
 }
 
-ol.LC_smallMenu li img {
+ol.LC_primary_menu li img {
 	vertical-align: bottom;
 }
 
-ol.LC_smallMenu a {
+ol.LC_primary_menu a {
 	font-size: 90%;
 	color: RGB(80, 80, 80);
 	text-decoration: none;
 }
 
-ul#LC_TabMainMenuContent {
+ul#LC_secondary_menu {
     clear: both;
     color: $fontmenu;
     background: $tabbg;
@@ -5945,7 +5978,7 @@ ul#LC_TabMainMenuContent {
     width: 100%;
 }
 
-ul#LC_TabMainMenuContent li {
+ul#LC_secondary_menu li {
     font-weight: bold;
     line-height: 1.8em;
     padding: 0 0.8em; 
@@ -5968,7 +6001,7 @@ ul.LC_TabContentBigger li {
 	float:left;
 }
 
-ul#LC_TabMainMenuContent li a {
+ul#LC_secondary_menu li a {
     color: $fontmenu;
 	text-decoration: none;
 }
@@ -6067,6 +6100,8 @@ ol#LC_PathBreadcrumbs {
 	padding-left: 10px;
 	margin: 0;
 	list-style-position: inside;
+    /* SD working here
+    white-space: nowrap; */
 }
 
 ol#LC_MenuBreadcrumbs li, 
@@ -6074,6 +6109,8 @@ ol#LC_PathBreadcrumbs li,
 ul.LC_CourseBreadcrumbs li {
     display: inline;
     white-space: nowrap;
+    /* SD working here
+    white-space: normal; */
 }
 
 ol#LC_MenuBreadcrumbs li a,
@@ -6757,14 +6794,14 @@ sub simple_error_page {
 	my ($add_class) = @_;
 	$row_count[0]++;
 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
-	$css_class = (join(' ',$css_class,$add_class));
+	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
 	return  '<tr class="'.$css_class.'">'."\n";;
     }
     
     sub continue_data_table_row {
 	my ($add_class) = @_;
 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
-	$css_class = (join(' ',$css_class,$add_class));
+	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
 	return  '<tr class="'.$css_class.'">'."\n";;
     }
 
@@ -6863,7 +6900,7 @@ sub get_users_function {
     if ($env{'request.role'}=~/^(st)/) {
         $function='student';
     }
-    if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
+    if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
         $function='coordinator';
     }
     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
@@ -10273,6 +10310,16 @@ sub group_term {
     return $names{$crstype};
 }
 
+sub course_types {
+    my @types = ('official','unofficial','community');
+    my %typename = (
+                         official   => 'Official course',
+                         unofficial => 'Unofficial course',
+                         community  => 'Community',
+                   );
+    return (\@types,\%typename);
+}
+
 sub icon {
     my ($file)=@_;
     my $curfext = lc((split(/\./,$file))[-1]);