// if $category ne 'advtools';
+ }
-Increment the count of items completed for the progress window by 1.
+ push @{$tools{$category}}, @html;
+ }
-Inputs:
+=item clear_breadcrumb_tools()
-=over 4
+Clears the breadcrumb toolbar container.
-=item $r Apache request
+returns: nothing
-=item $prog_state Pointer to the data structure returned by Create_PrgWin
+=cut
-=item $extraInfo A description of the items being iterated over. Typically
-'student'.
+ sub clear_breadcrumb_tools {
+ undef(%tools);
+ }
-=back
+=item render_tools(\$breadcrumbs)
-Returns: none
+Creates html for breadcrumb tools (categories navigation and tools) and inserts
+\$breadcrumbs at the correct position.
+input: \$breadcrumbs - a reference to the string containing prepared
+breadcrumbs.
-=item Close_PrgWin
+returns: nothing
+=cut
-Closes the progress window.
+#TODO might split this in separate functions for each category
+ sub render_tools {
+ my ($breadcrumbs) = @_;
+ return unless (keys(%tools));
-Inputs:
+ my $navigation = list_from_array($tools{navigation},
+ { listattr => { class=>"LC_breadcrumb_tools_navigation" } });
+ my $tools = list_from_array($tools{tools},
+ { listattr => { class=>"LC_breadcrumb_tools_tools" } });
+ $$breadcrumbs = list_from_array([$navigation, $tools, $$breadcrumbs],
+ { listattr => { class=>'LC_breadcrumb_tools_outerlist' } });
+ }
-=over 4
+=item render_advtools(\$breadcrumbs)
-=item $r Apache request
+Creates html for advanced tools (category advtools) and inserts \$breadcrumbs
+at the correct position.
-=item $prog_state Pointer to the data structure returned by Create_PrgWin
+input: \$breadcrumbs - a reference to the string containing prepared
+breadcrumbs (after render_tools call).
-=back
+returns: nothing
+=cut
-Returns: none
+ sub render_advtools {
+ my ($breadcrumbs) = @_;
+ return unless (defined $tools{'advtools'})
+ and (scalar(@{$tools{'advtools'}}) > 0);
-=back
+ $$breadcrumbs .= Apache::loncommon::head_subbox(
+ funclist_from_array($tools{'advtools'}) );
+ }
-=cut
+} # End of scope for @Crumbs
-########################################################
-########################################################
+############################################################
+############################################################
-# Create progress
-sub Create_PrgWin {
- my ($r, $title, $heading, $number_to_do)=@_;
- $r->print('");
+# Nested table routines.
+#
+# Routines to display form items in a multi-row table with 2 columns.
+# Uses nested tables to divide form elements into segments.
+# For examples of use see loncom/interface/lonnotify.pm
+#
+# Can be used in following order: ...
+# &start_pick_box()
+# row1
+# row2
+# row3 ... etc.
+# &submit_row()
+# &end_pick_box()
+#
+# where row1, row 2 etc. are chosen from &role_select_row,&course_select_row,
+# &status_select_row and &email_default_row
+#
+# Can also be used in following order:
+#
+# &start_pick_box()
+# &row_title()
+# &row_closure()
+# &row_title()
+# &row_closure() ... etc.
+# &submit_row()
+# &end_pick_box()
+#
+# In general a &submit_row() call should proceed the call to &end_pick_box(),
+# as this routine adds a button for form submission.
+# &submit_row() does not require a &row_closure after it.
+#
+# &start_pick_box() creates a bounding table with 1-pixel wide black border.
+# rows should be placed between calls to &start_pick_box() and &end_pick_box.
+#
+# &row_title() adds a title in the left column for each segment.
+# &row_closure() closes a row with a 1-pixel wide black line.
+#
+# &role_select_row() provides a select box from which to choose 1 or more roles
+# &course_select_row provides ways of picking groups of courses
+# radio buttons: all, by category or by picking from a course picker pop-up
+# note: by category option is only displayed if a domain has implemented
+# selection by year, semester, department, number etc.
+#
+# &status_select_row() provides a select box from which to choose 1 or more
+# access types (current access, prior access, and future access)
+#
+# &email_default_row() provides text boxes for default e-mail suffixes for
+# different authentication types in a domain.
+#
+# &row_title() and &row_closure() are called internally by the &*_select_row
+# routines, but can also be called directly to start and end rows which have
+# needs that are not accommodated by the *_select_row() routines.
+
+{ # Start: row_count block for pick_box
+my @row_count;
+
+sub start_pick_box {
+ my ($css_class) = @_;
+ if (defined($css_class)) {
+ $css_class = 'class="'.$css_class.'"';
+ } else {
+ $css_class= 'class="LC_pick_box"';
+ }
+ unshift(@row_count,0);
+ my $output = <<"END";
+
+END
+ return $output;
+}
- my %prog_state;
- $prog_state{'done'}=0;
- $prog_state{'firststart'}=&Time::HiRes::time();
- $prog_state{'laststart'}=&Time::HiRes::time();
- $prog_state{'max'}=$number_to_do;
+sub end_pick_box {
+ shift(@row_count);
+ my $output = <<"END";
+
+END
+ return $output;
+}
- $r->rflush();
- return %prog_state;
+sub row_headline {
+ my $output = <<"END";
+
+END
+ return $output;
}
-# update progress
-sub Update_PrgWin {
- my ($r,$prog_state,$displayString)=@_;
- $r->print('');
- $$prog_state{'laststart'}=&Time::HiRes::time();
- $r->rflush();
+sub row_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;
}
-# increment progress state
-sub Increment_PrgWin {
- my ($r,$prog_state,$extraInfo)=@_;
- $$prog_state{'done'}++;
- my $time_est= (&Time::HiRes::time() - $$prog_state{'firststart'})/
- $$prog_state{'done'} *
- ($$prog_state{'max'}-$$prog_state{'done'});
- $time_est = int($time_est);
- if (int ($time_est/60) > 0) {
- my $min = int($time_est/60);
- my $sec = $time_est % 60;
- $time_est = $min.' minutes';
- if ($min < 10) {
- if ($sec > 1) {
- $time_est.= ', '.$sec.' seconds';
- } elsif ($sec > 0) {
- $time_est.= ', '.$sec.' second';
+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,$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($title,$css_class);
+ }
+ $output .= qq|
+ \n|;
+ if (defined($title)) {
+ $output .= &row_closure();
+ }
+ return $output;
+}
+
+sub course_select_row {
+ my ($title,$formname,$totcodes,$codetitles,$idlist,$idlist_titles,
+ $css_class,$crstype,$standardnames) = @_;
+ my $output = &row_title($title,$css_class);
+ $output .= &course_selection($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames);
+ $output .= &row_closure();
+ return $output;
+}
+
+sub course_selection {
+ my ($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames) = @_;
+ my $output = qq|
+
+ |;
+
+ my ($allcrs,$pickspec);
+ if ($crstype eq 'Community') {
+ $allcrs = &mt('All communities');
+ $pickspec = &mt('Pick specific communities:');
} else {
- $time_est .= ' seconds';
+ $allcrs = &mt('All courses');
+ $pickspec = &mt('Pick specific course(s):');
}
- my $lasttime = &Time::HiRes::time()-$$prog_state{'laststart'};
- if ($lasttime > 9) {
- $lasttime = int($lasttime);
- } elsif ($lasttime < 0.01) {
- $lasttime = 0;
+
+ my $courseform=''.&Apache::loncommon::selectcourse_link
+ ($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".
+ ' | ';
+ for (my $i=1; $i<$numtitles; $i++) {
+ $output .= ''.$$codetitles[$i].' '."\n".
+ ''."\n".
+ ' | ';
+ }
+ $output .= '
';
+ }
+ }
+ $output .= ''.$pickspec.' '.$courseform.' selected.
'."\n";
+ return $output;
+}
+
+sub status_select_row {
+ my ($types,$title,$css_class) = @_;
+ my $output;
+ if (defined($title)) {
+ $output = &row_title($title,$css_class,'LC_pick_box_select');
+ }
+ $output .= qq|
+ \n|;
+ if (defined($title)) {
+ $output .= &row_closure();
+ }
+ return $output;
+}
+
+sub email_default_row {
+ 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);
+ if ($auth =~ /^krb/) {
+ $userentry = '';
+ $size = 25;
+ } else {
+ $userentry = 'username@';
+ $size = 15;
+ }
+ $output .= &Apache::loncommon::start_data_table_row().
+ ' '.$$authtypes{$auth}.' | '.
+ ''.$userentry.
+ ' | '.
+ &Apache::loncommon::end_data_table_row();
+ }
+ $output .= &Apache::loncommon::end_data_table();
+ $output .= &row_closure();
+ return $output;
+}
+
+
+sub submit_row {
+ my ($title,$cmd,$submit_text,$css_class) = @_;
+ my $output = &row_title($title,$css_class,'LC_pick_box_submit');
+ $output .= qq|
+
+
+
+
+ \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 {
- $lasttime = sprintf("%3.2f",$lasttime);
+ $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
+# as hidden form elements (values encoded) in the new page.
+#
+# Intended to support two types of use
+# (a) to allow backing up to earlier pages in a multi-page
+# form submission process using a breadcrumb trail.
+#
+# (b) to allow the current page to be reloaded with form elements
+# set on previous page to remain unchanged. An example would
+# be where the a page containing a dynamically-built table of data is
+# is to be redisplayed, with only the sort order of the data changed.
+#
+# Inputs:
+# 1. Reference to array of form elements in the submitted form on
+# the referrer page which are to be excluded from the echoed elements.
+#
+# 2. Reference to array of regular expressions, which if matched in the
+# name of the form element n the referrer page will be omitted from echo.
+#
+# Outputs: A scalar containing the html markup for the echoed form
+# elements (all as hidden elements, with values encoded).
+
+
+sub echo_form_input {
+ my ($excluded,$regexps) = @_;
+ my $output = '';
+ foreach my $key (keys(%env)) {
+ if ($key =~ /^form\.(.+)$/) {
+ my $name = $1;
+ my $match = 0;
+ 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;
+ }
+ }
+ }
+ }
+ 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";
+ }
+ }
+ }
+ return $output;
+}
+
+##############################################
+##############################################
+# set_form_elements
+#
+# Generates javascript to set form elements to values based on
+# corresponding values for the same form elements when the page was
+# previously submitted.
+#
+# Last submission values are read from hidden form elements in referring
+# page which have the same name, i.e., generated by &echo_form_input().
+#
+# Intended to be called by onload event.
+#
+# Inputs:
+# (a) Reference to hash of echoed form elements to be set.
+#
+# In the hash, keys are the form element names, and the values are the
+# element type (selectbox, radio, checkbox or text -for textbox, textarea or
+# hidden).
+#
+# (b) Optional reference to hash of stored elements to be set.
+#
+# If the page being displayed is a page which permits modification of
+# previously stored data, e.g., the first page in a multi-page submission,
+# then if stored is supplied, form elements will be set to the last stored
+# values. If user supplied values are also available for the same elements
+# these will replace the stored values.
+#
+# Output:
+#
+# javascript function - set_form_elements() which sets form elements,
+# expects an argument: formname - the name of the form according to
+# the DOM, e.g., document.compose
+
+sub set_form_elements {
+ my ($elements,$stored) = @_;
+ my %values;
+ my $output .= 'function setFormElements(courseForm) {
+';
+ if (defined($stored)) {
+ foreach my $name (keys(%{$stored})) {
+ if (exists($$elements{$name})) {
+ if (ref($$stored{$name}) eq 'ARRAY') {
+ $values{$name} = $$stored{$name};
+ } else {
+ @{$values{$name}} = ($$stored{$name});
+ }
+ }
+ }
+ }
+
+ foreach my $key (keys(%env)) {
+ if ($key =~ /^form\.(.+)$/) {
+ my $name = $1;
+ if (exists($$elements{$name})) {
+ @{$values{$name}} = &Apache::loncommon::get_env_multiple($key);
+ }
+ }
}
- if ($lasttime == 1) {
- $lasttime = '('.$lasttime.' second for '.$extraInfo.')';
+
+ foreach my $name (keys(%values)) {
+ for (my $i=0; $i<@{$values{$name}}; $i++) {
+ $values{$name}[$i] = &HTML::Entities::decode($values{$name}[$i],'<>&"');
+ $values{$name}[$i] =~ s/([\r\n\f]+)/\\n/g;
+ $values{$name}[$i] =~ s/"/\\"/g;
+ }
+ 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.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";
+ return <<"ENDSCRIPT";
+');
- $$prog_state{'laststart'}=&Time::HiRes::time();
- $r->rflush();
+ if (alloverwrites.length > 0) {
+ if (!confirm("$overwritewarn")) {
+ for (var n=0; n 0) {
+ if (!confirm("$delfilewarn")) {
+ for (var p=0; pprint(''."\n");
- undef(%$prog_state);
- $r->rflush();
+function getIndexByName(formname,item) {
+ for (var i=0;i 0) {
+ if ((formname.elements[alluploads[j]].value != undefined) &&
+ (formname.elements[alluploads[j]].value != '')) {
+ var filepath = formname.elements[alluploads[j]].value;
+ var newfilename = fnametrim.exec(filepath);
+ if (newfilename != null) {
+ var filename = String(newfilename);
+ var nospaces = filename.replace(/\\s+/g,'_');
+ var nospecials = nospaces.replace(/[^\\/\\w\\.\\-]/g,'');
+ var cleanfilename = nospecials.replace(/\\.(\\d+\\.)/g,"_\$1");
+ if (cleanfilename != '') {
+ var fullpath = path+"/"+cleanfilename;
+ if (multiresp == 1) {
+ var partid = String(alluploads[i]);
+ var subdir = partid.replace(/^\\d*.?\\d*_?HWFILE/,'');
+ if (subdir != "" && subdir != undefined) {
+ fullpath = path+"/"+subdir+"/"+cleanfilename;
+ }
+ }
+ for (var m=0; m 0) {
+ if (allskipdel.length > 0) {
+ for (var n=0; n
+
+
+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