-
-
-
-
-
-
+
END
return $output;
}
sub end_pick_box {
+ shift(@row_count);
my $output = <<"END";
-
-
-
- |
-
-
+END
+ return $output;
+}
+
+sub row_headline {
+ my $output = <<"END";
+ |
END
return $output;
}
sub row_title {
- my ($col_width,$tablecolor,$title) = @_;
+ my ($title,$css_title_class,$css_value_class, $css_value_furtherAttributes) = @_;
+ $row_count[0]++;
+ my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
+ $css_title_class ||= 'LC_pick_box_title';
+ $css_title_class = 'class="'.$css_title_class.'"';
+
+ $css_value_class ||= 'LC_pick_box_value';
+
+ if ($title ne '') {
+ $title .= ':';
+ }
my $output = <<"ENDONE";
- |
-
-
+ |
+
+ $title
|
-
-
-
+
ENDONE
return $output;
}
sub row_closure {
+ my ($no_separator) =@_;
my $output = <<"ENDTWO";
- |
-
|
+ENDTWO
+ if (!$no_separator) {
+ $output .= <<"ENDTWO";
-
-
+ |
|
ENDTWO
+ }
return $output;
}
+} # End: row_count block for pick_box
+
sub role_select_row {
- my ($roles,$col_width,$tablecolor,$title) = @_;
+ my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_;
+ my $crstype = 'Course';
+ if ($cdom ne '' && $cnum ne '') {
+ $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
+ }
my $output;
if (defined($title)) {
- $output = &row_title($col_width,$tablecolor,$title);
+ $output = &row_title($title,$css_class);
}
- $output .= qq|
- | \n|;
+ $output .= qq| \n|;
if (defined($title)) {
$output .= &row_closure();
}
@@ -1442,11 +1824,19 @@ sub role_select_row {
}
sub course_select_row {
- my ($col_width,$tablecolor,$title,$formname,$totcodes,$codetitles,$idlist,$idlist_titles) = @_;
- my $output = &row_title($col_width,$tablecolor,$title);
- $output .= " \n";
- $output .= qq|
-
|;
+
+ my ($allcrs,$pickspec);
+ if ($crstype eq 'Community') {
+ $allcrs = &mt('All communities');
+ $pickspec = &mt('Pick specific communities:');
+ } else {
+ $allcrs = &mt('All courses');
+ $pickspec = &mt('Pick specific course(s):');
+ }
+
my $courseform=''.&Apache::loncommon::selectcourse_link
- ($formname,'pickcourse','pickdomain','coursedesc','',1).'';
- $output .= ''.&mt('All courses').' ';
+ ($formname,'pickcourse','pickdomain','coursedesc','',1,$crstype).'';
+ $output .= ''.$allcrs.' ';
if ($totcodes > 0) {
my $numtitles = @$codetitles;
if ($numtitles > 0) {
$output .= ''.&mt('Pick courses by category:').' ';
$output .= ''.$$codetitles[0].' '."\n".
- '[0].
'" onChange="setPick(this.form);courseSet('."'$$codetitles[0]'".')">'."\n".
' Select'."\n";
my @items = ();
@@ -1509,7 +1910,7 @@ sub course_select_row {
$output .= ' | ';
for (my $i=1; $i<$numtitles; $i++) {
$output .= ''.$$codetitles[$i].' '."\n".
- '[$i].
'" onChange="courseSet('."'$$codetitles[$i]'".')">'."\n".
''."\n".
''."\n".
@@ -1518,24 +1919,22 @@ sub course_select_row {
$output .= ' |
';
}
}
- $output .= ''.&mt('Pick specific course(s):').' '.$courseform.' selected.
| '."\n";
- $output .= &row_closure();
+ $output .= ''.$pickspec.' '.$courseform.' selected.
'."\n";
return $output;
}
sub status_select_row {
- my ($types,$col_width,$tablecolor,$title) = @_;
+ my ($types,$title,$css_class) = @_;
my $output;
if (defined($title)) {
- $output = &row_title($col_width,$tablecolor,$title);
+ $output = &row_title($title,$css_class,'LC_pick_box_select');
}
- $output .= qq|
- \n|;
+ $output .= qq|
+ \n|;
foreach my $status_type (sort(keys(%{$types}))) {
$output .= ' ';
}
- $output .= qq|
- | \n|;
+ $output .= qq| \n|;
if (defined($title)) {
$output .= &row_closure();
}
@@ -1543,18 +1942,17 @@ sub status_select_row {
}
sub email_default_row {
- my ($authtypes,$col_width,$tablecolor,$title,$descrip) = @_;
- my $output = &row_title($col_width,$tablecolor,$title);
- my @rowcols = ('#eeeeee','#dddddd');
- $output .= ' '.$descrip;
- $output .= &start_pick_box('');
- $output .= ' |
- '.&mt('Authentication Method').' | '.&mt('Username -> e-mail conversion').' |
-
'."\n";
+ my ($authtypes,$title,$descrip,$css_class) = @_;
+ my $output = &row_title($title,$css_class);
+ $output .= $descrip.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ ''.&mt('Authentication Method').' | '.
+ ''.&mt('Username -> e-mail conversion').' | '."\n".
+ &Apache::loncommon::end_data_table_header_row();
my $rownum = 0;
foreach my $auth (sort(keys(%{$authtypes}))) {
my ($userentry,$size);
- my $rowiter = $rownum%2;
if ($auth =~ /^krb/) {
$userentry = '';
$size = 25;
@@ -1562,32 +1960,95 @@ sub email_default_row {
$userentry = 'username@';
$size = 15;
}
- $output .= ' '.$$authtypes{$auth}.' | '.$userentry.' |
';
- $rownum ++;
+ $output .= &Apache::loncommon::start_data_table_row().
+ ' '.$$authtypes{$auth}.' | '.
+ ''.$userentry.
+ ' | '.
+ &Apache::loncommon::end_data_table_row();
}
- $output .= &end_pick_box();
- $output .= "
\n";
+ $output .= &Apache::loncommon::end_data_table();
$output .= &row_closure();
return $output;
}
sub submit_row {
- my ($col_width,$tablecolor,$title,$cmd,$submit_text) = @_;
- my $output = &row_title($col_width,$tablecolor,$title);
+ my ($title,$cmd,$submit_text,$css_class) = @_;
+ my $output = &row_title($title,$css_class,'LC_pick_box_submit');
$output .= qq|
-
- | \n|;
+ \n|;
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;
+}
+
+
+sub resource_info_box {
+ my ($symb,$onlyfolderflag)=@_;
+ my $return='';
+ if ($symb) {
+ $return=&Apache::loncommon::start_data_table();
+ my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symb);
+ my $folder=&Apache::lonnet::gettitle($map);
+ $return.=&Apache::loncommon::start_data_table_row().
+ ''.&mt('Folder:').' | '.$folder.' | '.
+ &Apache::loncommon::end_data_table_row();
+ unless ($onlyfolderflag) {
+ $return.=&Apache::loncommon::start_data_table_row().
+ ''.&mt('Resource:').' | '.&Apache::lonnet::gettitle($symb).' | '.
+ &Apache::loncommon::end_data_table_row();
+ }
+ $return.=&Apache::loncommon::end_data_table();
+ } else {
+ $return=''.&mt('No context provided.').'
';
+ }
+ return $return;
+
+}
+
+##############################################
+##############################################
+
+# topic_bar
+#
+# Generates a div containing an (optional) number with a white background followed by a
+# title with a background color defined in the corresponding CSS: LC_topic_bar
+# Inputs:
+# 1. number to display.
+# If input for number is empty only the title will be displayed.
+# 2. title text to display.
+# Outputs - a scalar containing html mark-up for the div.
+
+sub topic_bar {
+ my ($num,$title) = @_;
+ my $number = '';
+ if ($num ne '') {
+ $number = ''.$num.'';
+ }
+ return ''.$number.$title.'
';
+}
+
##############################################
##############################################
-
# echo_form_input
#
# Generates html markup to add form elements from the referrer page
@@ -1620,30 +2081,30 @@ sub echo_form_input {
if ($key =~ /^form\.(.+)$/) {
my $name = $1;
my $match = 0;
- if ((!@{$excluded}) || (!grep/^$name$/,@{$excluded})) {
- if (defined($regexps)) {
- if (@{$regexps} > 0) {
- foreach my $regexp (@{$regexps}) {
- if ($name =~ /\Q$regexp\E/) {
- $match = 1;
- last;
- }
+ if (ref($excluded) eq 'ARRAY') {
+ next if (grep(/^\Q$name\E$/,@{$excluded}));
+ }
+ if (ref($regexps) eq 'ARRAY') {
+ if (@{$regexps} > 0) {
+ foreach my $regexp (@{$regexps}) {
+ if ($name =~ /$regexp/) {
+ $match = 1;
+ last;
}
}
}
- if (!$match) {
- if (ref($env{$key})) {
- foreach my $value (@{$env{$key}}) {
- $value = &HTML::Entities::encode($value,'<>&"');
- $output .= ''."\n";
- }
- } else {
- my $value = &HTML::Entities::encode($env{$key},'<>&"');
- $output .= ''."\n";
- }
+ }
+ next if ($match);
+ if (ref($env{$key}) eq 'ARRAY') {
+ foreach my $value (@{$env{$key}}) {
+ $value = &HTML::Entities::encode($value,'<>&"');
+ $output .= ''."\n";
}
+ } else {
+ my $value = &HTML::Entities::encode($env{$key},'<>&"');
+ $output .= ''."\n";
}
}
}
@@ -1652,7 +2113,6 @@ sub echo_form_input {
##############################################
##############################################
-
# set_form_elements
#
# Generates javascript to set form elements to values based on
@@ -1717,72 +2177,74 @@ sub set_form_elements {
$values{$name}[$i] =~ s/([\r\n\f]+)/\\n/g;
$values{$name}[$i] =~ s/"/\\"/g;
}
- if ($$elements{$name} eq 'text') {
+ if (($$elements{$name} eq 'text') || ($$elements{$name} eq 'hidden')) {
my $numvalues = @{$values{$name}};
if ($numvalues > 1) {
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{$key}';\n".
+ " }\n";
+ }
+ }
+ $turninpathtext .= " return '';\n";
+ if (ref($multiples) eq 'HASH') {
+ foreach my $key (sort(keys(%{$multiples}))) {
+ $multtext .= " if (prefix == '$key') {\n".
+ " return '$multiples->{$key}';\n".
+ " }\n";
+ }
+ }
+ $multtext .= " return '';\n";
+
+ $arrayindexofjs = &Apache::loncommon::javascript_array_indexof();
+ return <<"ENDSCRIPT";
+
+
+$arrayindexofjs
+
+ENDSCRIPT
+}
+
+##############################################
+##############################################
+
+# javascript_valid_email
+#
+# Generates javascript to validate an e-mail address.
+# Returns a javascript function which accetps a form field as argumnent, and
+# returns false if field.value does not satisfy two regular expression matches
+# for a valid e-mail address. Backwards compatible with old browsers without
+# support for javascript RegExp (just checks for @ in field.value in this case).
+
+sub javascript_valid_email {
+ my $scripttag .= <<'END';
+function validmail(field) {
+ var str = field.value;
+ if (window.RegExp) {
+ var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
+ var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"
+ var reg1 = new RegExp(reg1str);
+ var reg2 = new RegExp(reg2str);
+ if (!reg1.test(str) && reg2.test(str)) {
+ return true;
+ }
+ return false;
+ }
+ else
+ {
+ if(str.indexOf("@") >= 0) {
+ return true;
+ }
+ return false;
+ }
+}
+END
+ return $scripttag;
+}
+
+
+# USAGE: htmltag(element, content, {attribute => value,...});
+#
+# EXAMPLES:
+# - htmltag('a', 'this is an anchor', {href => 'www.example.com',
+# title => 'this is a title'})
+#
+# - You might want to set up needed tags like:
+#
+# my $h3 = sub { return htmltag( "h3", @_ ) };
+#
+# ... and use them: $h3->("This is a headline")
+#
+# - To set up a couple of tags, see sub inittags
+#
+# NOTES:
+# - Empty elements, such as
are correctly terminated,
+# i.e. htmltag('br') returns
+# - Empty attributes (title="") are filtered out.
+# - The function will not check for deprecated attributes.
+#
+# OUTPUT: content enclosed in xhtml conform tags
+sub htmltag{
+ return
+ qq|<$_[0]|
+ . join( '', map { qq| $_="${$_[2]}{$_}"| if ${$_[2]}{$_} } keys %{ $_[2] } )
+ . ($_[1] ? qq|>$_[1]$_[0]>| : qq|/>|). "\n";
+};
+
+
+# USAGE: inittags(@tags);
+#
+# EXAMPLES:
+# - my ($h1, $h2, $h3) = inittags( qw( h1 h2 h3 ) )
+# $h1->("This is a headline") #Returns: This is a headline
+#
+# NOTES: See sub htmltag for further information.
+#
+# OUTPUT: List of subroutines.
+sub inittags {
+ my @tags = @_;
+ return map { my $tag = $_;
+ sub { return htmltag( $tag, @_ ) }
+ } @tags;
+}
+
+
+# USAGE: scripttag(scriptcode, [start|end|both]);
+#
+# EXAMPLES:
+# - scripttag("alert('Hello World!')", 'both')
+# returns:
+#
+#
+# NOTES:
+# - works currently only for javascripts
+#
+# OUTPUT:
+# Scriptcode properly enclosed in