--- loncom/interface/lonhtmlcommon.pm	2006/07/18 21:55:24	1.144
+++ loncom/interface/lonhtmlcommon.pm	2006/12/05 02:55:53	1.155
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.144 2006/07/18 21:55:24 albertel Exp $
+# $Id: lonhtmlcommon.pm,v 1.155 2006/12/05 02:55:53 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -60,7 +60,6 @@ use Time::Local;
 use Time::HiRes;
 use Apache::lonlocal;
 use Apache::lonnet;
-use lib '/home/httpd/lib/perl/';
 use LONCAPA;
 
 ##############################################
@@ -78,7 +77,7 @@ use LONCAPA;
 sub authorbombs {
     my $url=shift;
     $url=&Apache::lonnet::declutter($url);
-    my ($udom,$uname)=($url=~/^(\w+)\/(\w+)\//);
+    my ($udom,$uname)=($url=~m{^($LONCAPA::domain_re)/($LONCAPA::username_re)/});
     my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
     foreach (keys %bombs) {
 	if ($_=~/^$udom\/$uname\//) {
@@ -689,14 +688,6 @@ sub StatusOptions {
         $status = $env{'form.Status'} if (exists($env{'form.Status'}));
     }
 
-    my $OpSel1 = '';
-    my $OpSel2 = '';
-    my $OpSel3 = '';
-
-    if($status eq 'Any')         { $OpSel3 = ' selected'; }
-    elsif($status eq 'Expired' ) { $OpSel2 = ' selected'; }
-    else                         { $OpSel1 = ' selected'; }
-
     my $Str = '';
     $Str .= '<select name="Status"';
     if(defined($formName) && $formName ne '' && ! defined($onchange)) {
@@ -707,12 +698,18 @@ sub StatusOptions {
     }
     $Str .= ' size="'.$size.'" ';
     $Str .= '>'."\n";
-    $Str .= '<option value="Active" '.$OpSel1.'>'.
-        &mt('Currently Enrolled').'</option>'."\n";
-    $Str .= '<option value="Expired" '.$OpSel2.'>'.
-        &mt('Previously Enrolled').'</option>'."\n";
-    $Str .= '<option value="Any" '.$OpSel3.'>'.
-        &mt('Any Enrollment Status').'</option>'."\n";
+    foreach my $type (['Active',  &mt('Currently Has Access')],
+		      ['Future',  &mt('Will Have Future Access')],
+		      ['Expired', &mt('Previously Had Access')],
+		      ['Any',     &mt('Any Access Status')]) {
+	my ($name,$label) = @$type;
+	$Str .= '<option value="'.$name.'" ';
+	if ($status eq $name) {
+	    $Str .= 'selected="selected" ';
+	}
+	$Str .= '>'.$label.'</option>'."\n";
+    }
+
     $Str .= '</select>'."\n";
 }
 
@@ -1014,9 +1011,12 @@ sub crumbs {
 	    $output.=qq{<a href="$linkpath" $target>$dir</a>/};
 	}
     } else {
-	$output.=$uri;
+	foreach my $dir (split('/',$uri)) {
+            if (! $dir) { next; }
+	    $output.=$dir.'/';
+	}
     }
-    unless ($uri=~/\/$/) { $output=~s/\/$//; }
+    if ($uri !~ m|/$|) { $output=~s|/$||; }
     return $output.'</font>'.($noformat?'':'</b></tt><br />');
 }
 
@@ -1045,7 +1045,7 @@ var checkwin;
 function spellcheckerwindow(string) {
     var esc_string = string.replace(/\"/g,'&quot;');
     checkwin=window.open($nothing,'spellcheckwin','height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
-    checkwin.document.writeln('$start_page<form name="spellcheckform" action="/adm/spellcheck" method="post"><input type="hidden" name="text" value="'+esc_string+'" /><\/form>$end_page');
+    checkwin.document.writeln('$start_page<form name="spellcheckform" action="/adm/spellcheck" method="post"><input type="hidden" name="text" value="'+esc_string+'" /><\\/form>$end_page');
     checkwin.document.close();
 }
 // END LON-CAPA Internal -->
@@ -1094,6 +1094,7 @@ _editor_url='/htmlarea/';
 _editor_lang='$lang';
 </script>
 <script type="text/javascript" src="/htmlarea/htmlarea.js"></script>
+<link rel="stylesheet" type="text/css" href="/htmlarea/htmlarea.css" />
 ENDHEADERS
 }
 
@@ -1264,9 +1265,9 @@ returns: nothing
         $bug = $last->{'bug'} if (exists($last->{'bug'}));
         $help = $last->{'help'} if (exists($last->{'help'}));
         $component_help=($component_help?$component_help:$help);
-        if ($faq ne '') {
-            $icons .= &Apache::loncommon::help_open_faq($faq);
-        }
+#        if ($faq ne '') {
+#            $icons .= &Apache::loncommon::help_open_faq($faq);
+#        }
 #        if ($bug ne '') {
 #            $icons .= &Apache::loncommon::help_open_bug($bug);
 #        }
@@ -1417,7 +1418,7 @@ ENDTWO
 }
 
 sub role_select_row {
-    my ($roles,$title,$css_class) = @_;
+    my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_;
     my $output;
     if (defined($title)) {
         $output = &row_title($title,$css_class);
@@ -1428,10 +1429,25 @@ sub role_select_row {
         my $plrole;
         if ($role eq 'ow') {
             $plrole = &mt('Course Owner');
+        } elsif ($role eq 'cr') {
+            if ($show_separate_custom) {
+                if ($cdom ne '' && $cnum ne '') {
+                    my %course_customroles = &course_custom_roles($cdom,$cnum);
+                    foreach my $crrole (sort(keys(%course_customroles))) {
+                        my ($plcrrole) = ($crrole =~ m|^cr/[^/]+/[^/]+/(.+)$|);
+                        $output .= '  <option value="'.$crrole.'">'.$plcrrole.
+                                   '</option>';
+                    }
+                }
+            } else {
+                $plrole = &mt('Custom Role');
+            }
         } else {
             $plrole=&Apache::lonnet::plaintext($role);
         }
-        $output .= '  <option value="'.$role.'">'.$plrole.'</option>';
+        if (($role ne 'cr') || (!$show_separate_custom)) {
+            $output .= '  <option value="'.$role.'">'.$plrole.'</option>';
+        }
     }
     $output .= qq|                </select>\n|;
     if (defined($title)) {
@@ -1584,6 +1600,24 @@ sub submit_row {
     return $output;
 }
 
+sub course_custom_roles {
+    my ($cdom,$cnum) = @_;
+    my %returnhash=();
+    my %coursepersonnel=&Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
+    foreach my $person (sort(keys(%coursepersonnel))) {
+        my ($role) = ($person =~ /^([^:]+):/);
+        my ($end,$start) = split(/:/,$coursepersonnel{$person});
+        if ($end == -1 && $start == -1) {
+            next;
+        }
+        if ($role =~ m|^cr/[^/]+/[^/]+/[^/]|) {
+            $returnhash{$role} ++;
+        }
+    }
+    return %returnhash;
+}
+
+
 ##############################################
 ##############################################
                                                                              
@@ -1722,66 +1756,66 @@ sub set_form_elements {
                 my $valuestring = join('","',@{$values{$name}});
                 $output .= qq|
   var textvalues = new Array ("$valuestring");
-  var total = courseForm.$name.length;
+  var total = courseForm.elements['$name'].length;
   if (total > $numvalues) {
       total = $numvalues;
   }    
   for (var i=0; i<total; i++) {
-      courseForm.$name\[i].value = textvalues[i];
+      courseForm.elements['$name']\[i].value = textvalues[i];
   }
 |;
             } else {
                 $output .= qq|
-  courseForm.$name.value = "$values{$name}[0]";
+  courseForm.elements['$name'].value = "$values{$name}[0]";
 |;
             }
         } else {
             $output .=  qq|
-  var elementLength = courseForm.$name.length;
+  var elementLength = courseForm.elements['$name'].length;
   if (elementLength==undefined) {
 |;
             foreach my $value (@{$values{$name}}) {
                 if ($$elements{$name} eq 'selectbox') {
                     $output .=  qq|
-      if (courseForm.$name.options[0].value == "$value") {
-          courseForm.$name.options[0].selected = true;
+      if (courseForm.elements['$name'].options[0].value == "$value") {
+          courseForm.elements['$name'].options[0].selected = true;
       }|;
                 } elsif (($$elements{$name} eq 'radio') ||
                          ($$elements{$name} eq 'checkbox')) {
                     $output .= qq|
-      if (courseForm.$name.value == "$value") {
-          courseForm.$name.checked = true;
+      if (courseForm.elements['$name'].value == "$value") {
+          courseForm.elements['$name'].checked = true;
       }|;
                 }
             }
             $output .= qq|
   }
   else {
-      for (var i=0; i<courseForm.$name.length; i++) {
+      for (var i=0; i<courseForm.elements['$name'].length; i++) {
 |;
             if ($$elements{$name} eq 'selectbox') {
                 $output .=  qq|
-          courseForm.$name.options[i].selected = false;|;
+          courseForm.elements['$name'].options[i].selected = false;|;
             } elsif (($$elements{$name} eq 'radio') || 
                      ($$elements{$name} eq 'checkbox')) {
                 $output .= qq|
-          courseForm.$name\[i].checked = false;|; 
+          courseForm.elements['$name']\[i].checked = false;|; 
             }
             $output .= qq|
       }
-      for (var j=0; j<courseForm.$name.length; j++) {
+      for (var j=0; j<courseForm.elements['$name'].length; j++) {
 |;
             foreach my $value (@{$values{$name}}) {
                 if ($$elements{$name} eq 'selectbox') {
                     $output .=  qq|
-          if (courseForm.$name.options[j].value == "$value") {
-              courseForm.$name.options[j].selected = true;
+          if (courseForm.elements['$name'].options[j].value == "$value") {
+              courseForm.elements['$name'].options[j].selected = true;
           }|;
                 } elsif (($$elements{$name} eq 'radio') ||
                          ($$elements{$name} eq 'checkbox')) { 
                       $output .= qq|
-          if (courseForm.$name\[j].value == "$value") {
-              courseForm.$name\[j].checked = true;
+          if (courseForm.elements['$name']\[j].value == "$value") {
+              courseForm.elements['$name']\[j].checked = true;
           }|;
                 }
             }