';
+ }
+ 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();
+ }
+ if ($stuvcurrent ne '') {
+ $return .= &Apache::loncommon::start_data_table_row().
+ '
'.&mt("Student's current version:").' | '.$stuvcurrent.' | '.
+ &Apache::loncommon::end_data_table_row();
+ }
+ if ($stuvdisp ne '') {
+ $return .= &Apache::loncommon::start_data_table_row().
+ '
'.&mt("Student's version displayed:").' | '.$stuvdisp.' | '.
+ &Apache::loncommon::end_data_table_row();
+ }
+ $return.=&Apache::loncommon::end_data_table();
+ } else {
+ $return='
'.&mt('No context provided.').'
';
+ }
+ if ($stuvcurrent ne '') {
+ $return .= '
';
+ }
+ return $return;
+}
+# display_usage
+#
+# Generates a div containing a block, filled to show percentage of current quota used
+#
+# Quotas available for user portfolios, group portfolios, authoring spaces, and course
+# content stored directly within a course (i.e., excluding published content).
+#
-=item &Update_PrgWin
+sub display_usage {
+ my ($current_disk_usage,$disk_quota) = @_;
+ my $usage = $current_disk_usage/1000;
+ my $quota = $disk_quota/1000;
+ my $percent;
+ if ($disk_quota == 0) {
+ $percent = 100.0;
+ } else {
+ $percent = 100*($current_disk_usage/$disk_quota);
+ }
+ $usage = sprintf("%.2f",$usage);
+ $quota = sprintf("%.2f",$quota);
+ $percent = sprintf("%.0f",$percent);
+ my ($color,$cssclass);
+ if ($percent <= 60) {
+ $color = '#00A000';
+ } elsif ($percent > 60 && $percent < 90) {
+ $color = '#FFD300';
+ $cssclass = 'class="LC_warning"';
+ } elsif( $percent >= 90) {
+ $color = '#FF0000';
+ $cssclass = 'class="LC_error"';
+ }
+ my $prog_width = $percent;
+ if ($prog_width > 100) {
+ $prog_width = 100;
+ }
+ return '
+
+# Outputs - a scalar containing html mark-up for the div.
+
+sub topic_bar {
+ my ($num,$title,$id) = @_;
+ my $number = '';
+ if ($num ne '') {
+ $number = '
'.$num.'';
+ }
+ if ($id ne '') {
+ $id = 'id="'.$id.'"';
+ }
+ return '
'.$number.$title.'
';
+}
-=over 4
+##############################################
+##############################################
+# 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).
-=item $r Apache request
-=item $prog_state Pointer to the data structure returned by &Create_PrgWin
+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;
+}
-=item $displaystring The string to write to the status indicator
+##############################################
+##############################################
+# 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});
+ }
+ }
+ }
+ }
-=back
+ foreach my $key (keys(%env)) {
+ if ($key =~ /^form\.(.+)$/) {
+ my $name = $1;
+ if (exists($$elements{$name})) {
+ @{$values{$name}} = &Apache::loncommon::get_env_multiple($key);
+ }
+ }
+ }
-Returns: none
+ 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";
-Increment the count of items completed for the progress window by 1.
+ $arrayindexofjs = &Apache::loncommon::javascript_array_indexof();
+ return <<"ENDSCRIPT";
+
-=back
+$arrayindexofjs
-Returns: none
+ENDSCRIPT
+}
+##############################################
+##############################################
-=item Close_PrgWin
+sub resize_scrollbox_js {
+ my ($context,$tabidstr,$tid) = @_;
+ my (%names,$paddingwfrac,$offsetwfrac,$offsetv,$minw,$minv);
+ if ($context eq 'docs') {
+ %names = (
+ boxw => 'contenteditor',
+ item => 'contentlist',
+ header => 'uploadfileresult',
+ scroll => 'contentscroll',
+ boxh => 'contenteditor',
+ );
+ $paddingwfrac = 0.09;
+ $offsetwfrac = 0.015;
+ $offsetv = 20;
+ $minw = 250;
+ $minv = 200;
+ } elsif ($context eq 'params') {
+ %names = (
+ boxw => 'parameditor',
+ item => 'mapmenuinner',
+ header => 'parmstep1',
+ scroll => 'mapmenuscroll',
+ boxh => 'parmlevel',
+ );
+ $paddingwfrac = 0.2;
+ $offsetwfrac = 0.015;
+ $offsetv = 80;
+ $minw = 100;
+ $minv = 100;
+ }
+ my $viewport_js = &Apache::loncommon::viewport_geometry_js();
+ my $output = '
+
+window.onresize=callResize;
+
+';
+ if ($context eq 'docs') {
+ if ($env{'form.active'}) {
+ $output .= "\nvar activeTab = '$env{'form.active'}$tid';\n";
+ } else {
+ $output .= "\nvar activeTab = '';\n";
+ }
+ }
+ $output .= <<"FIRST";
-Closes the progress window.
+$viewport_js
-Inputs:
+function resize_scrollbox(scrollboxname,chkw,chkh) {
+ var scrollboxid = 'div_'+scrollboxname;
+ var scrolltableid = 'table_'+scrollboxname;
+ var scrollbox;
+ var scrolltable;
+ var ismobile = '$env{'browser.mobile'}';
-=over 4
+ if (document.getElementById("$names{'boxw'}") == null) {
+ return;
+ }
-=item $r Apache request
+ if (document.getElementById(scrollboxid) == null) {
+ return;
+ } else {
+ scrollbox = document.getElementById(scrollboxid);
+ }
-=item $prog_state Pointer to the data structure returned by Create_PrgWin
-=back
+ if (document.getElementById(scrolltableid) == null) {
+ return;
+ } else {
+ scrolltable = document.getElementById(scrolltableid);
+ }
-Returns: none
+ init_geometry();
+ var vph = Geometry.getViewportHeight();
+ var vpw = Geometry.getViewportWidth();
+
+FIRST
+ if ($context eq 'docs') {
+ $output .= "
+ var alltabs = ['$tabidstr'];
+";
+ } elsif ($context eq 'params') {
+ $output .= "
+ if (document.getElementById('$names{'boxh'}') == null) {
+ return;
+ }
+";
+ }
+ $output .= <<"SECOND";
+ var listwchange;
+ var scrollchange;
+ if (chkw == 1) {
+ var boxw = document.getElementById("$names{'boxw'}").offsetWidth;
+ var itemw;
+ var itemid = document.getElementById("$names{'item'}");
+ if (itemid != null) {
+ itemw = itemid.offsetWidth;
+ }
+ var itemwstart = itemw;
-=back
+ var scrollboxw = scrollbox.offsetWidth;
+ var scrollboxscrollw = scrollbox.scrollWidth;
+ var scrollstart = scrollboxw;
+
+ var offsetw = parseInt(vpw * $offsetwfrac);
+ var paddingw = parseInt(vpw * $paddingwfrac);
+
+ var minscrollboxw = $minw;
+ var maxcolw = 0;
+SECOND
+ if ($context eq 'docs') {
+ $output .= <<"DOCSONE";
+ var actabw = 0;
+ for (var i=0; i maxcolw) {
+ maxcolw = actabw;
+ }
+ } else {
+ if (document.getElementById(alltabs[i]) != null) {
+ var thistab = document.getElementById(alltabs[i]);
+ thistab.style.visibility = 'hidden';
+ thistab.style.display = 'block';
+ var tabw = document.getElementById(alltabs[i]).offsetWidth;
+ thistab.style.display = 'none';
+ thistab.style.visibility = '';
+ if (tabw > maxcolw) {
+ maxcolw = tabw;
+ }
+ }
+ }
+ }
+DOCSONE
+ } elsif ($context eq 'params') {
+ $output .= <<"PARAMSONE";
+ var parmlevelrows = new Array();
+ var mapmenucells = new Array();
+ parmlevelrows = document.getElementById("$names{'boxh'}").rows;
+ var numrows = parmlevelrows.length;
+ if (numrows > 1) {
+ mapmenucells = parmlevelrows[2].getElementsByTagName('td');
+ }
+ maxcolw = mapmenucells[0].offsetWidth;
+PARAMSONE
+ }
+ $output .= <<"THIRD";
+ if (maxcolw > 0) {
+ var newscrollboxw;
+ if (maxcolw+paddingw+scrollboxscrollwprint('");
+ if (itemid.offsetWidth != itemwstart) {
+ listwchange = 1;
+ }
+ }
+ if ((chkh == 1) || (listwchange)) {
+ var itemid = document.getElementById("$names{'item'}");
+ if (itemid != null) {
+ itemh = itemid.offsetHeight;
+ }
+ var primaryheight = document.getElementById('LC_nav_bar').offsetHeight;
+ var secondaryheight;
+ if (document.getElementById('LC_secondary_menu') != null) {
+ secondaryheight = document.getElementById('LC_secondary_menu').offsetHeight;
+ }
+ var crumbsheight = document.getElementById('LC_breadcrumbs').offsetHeight;
+ var dccidheight = 0;
+ if (document.getElementById('dccid') != null) {
+ dccidheight = document.getElementById('dccid').offsetHeight;
+ }
+ var headerheight = 0;
+ if (document.getElementById("$names{'header'}") != null) {
+ headerheight = document.getElementById("$names{'header'}").offsetHeight;
+ }
+ var tabbedheight = document.getElementById("tabbededitor").offsetHeight;
+ var boxheight = document.getElementById("$names{'boxh'}").offsetHeight;
+ var freevspace = vph-(primaryheight+secondaryheight+crumbsheight+dccidheight+headerheight+tabbedheight+boxheight);
+
+ var scrollboxheight = scrollbox.offsetHeight;
+ var scrollboxscrollheight = scrollbox.scrollHeight;
+ var scrollboxh = scrollboxheight;
+
+ var minvscrollbox = $minv;
+ var offsetv = $offsetv;
+ var newscrollboxheight;
+ if (freevspace < 0) {
+ newscrollboxheight = scrollboxheight+freevspace-offsetv;
+ if (newscrollboxheight < minvscrollbox) {
+ newscrollboxheight = minvscrollbox;
+ }
+ scrollbox.style.height = newscrollboxheight + "px";
+ } else {
+ if (scrollboxscrollheight > scrollboxheight) {
+ if (freevspace > offsetv) {
+ newscrollboxheight = scrollboxheight+freevspace-offsetv;
+ if (newscrollboxheight < minvscrollbox) {
+ newscrollboxheight = minvscrollbox;
+ }
+ scrollbox.style.height = newscrollboxheight+"px";
+ }
+ }
+ }
+ scrollboxheight = scrollbox.offsetHeight;
+ var itemh = document.getElementById("$names{'item'}").offsetHeight;
- 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;
+ if (scrollboxscrollheight <= scrollboxheight) {
+ if ((itemh+offsetv)rflush();
- return %prog_state;
+function callResize() {
+ var timer;
+ clearTimeout(timer);
+ timer=setTimeout('resize_scrollbox("$names{'scroll'}","1","1")',500);
}
-# update progress
-sub Update_PrgWin {
- my ($r,$prog_state,$displayString)=@_;
- $r->print('');
- $$prog_state{'laststart'}=&Time::HiRes::time();
- $r->rflush();
+THIRD
+ 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 javascript_jumpto_resource {
+ my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
+ &mt('Switch server?');
+ return (<&');
+ if ($symb) {
+ $cfile .= '&symb='.&HTML::Entities::encode($symb,'"<>&');
+ } elsif ($folderpath) {
+ $cfile .= '&folderpath='.&HTML::Entities::encode($folderpath,'"<>&');
+ }
+ if ($forceedit) {
+ $cfile .= '&forceedit=1';
}
+ if ($forcereg) {
+ $cfile .= '®ister=1';
+ }
+ $jscall = "need_switchserver('".&Apache::loncommon::escape_single($cfile)."');";
}
} else {
- $time_est .= ' seconds';
+ unless ($cfile =~ m{^/priv/}) {
+ if ($symb) {
+ $cfile .= (($cfile=~/\?/)?'&':'?')."symb=$symb";
+ } elsif ($folderpath) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').
+ 'folderpath='.&HTML::Entities::encode(&escape($folderpath),'"<>&');
+ if ($title) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').
+ 'title='.&HTML::Entities::encode(&escape($title),'"<>&');
+ }
+ if ($idx) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').'idx='.$idx;
+ }
+ if ($suppurl) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').
+ 'suppurl='.&HTML::Entities::encode(&escape($suppurl));
+ }
+ }
+ if ($forceedit) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').'forceedit=1';
+ }
+ if ($forcereg) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').'register=1';
+ }
+ if ($todocs) {
+ $cfile .= (($cfile=~/\?/)?'&':'?').'todocs=1';
+ }
+ }
+ $jscall = "go('".&Apache::loncommon::escape_single($cfile)."')";
}
- my $lasttime = &Time::HiRes::time()-$$prog_state{'laststart'};
- if ($lasttime > 9) {
- $lasttime = int($lasttime);
- } elsif ($lasttime < 0.01) {
- $lasttime = 0;
- } else {
- $lasttime = sprintf("%3.2f",$lasttime);
+ return $jscall;
+}
+
+##############################################
+##############################################
+
+# 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;
}
- if ($lasttime == 1) {
- $lasttime = '('.$lasttime.' second for '.$extraInfo.')';
- } else {
- $lasttime = '('.$lasttime.' seconds for '.$extraInfo.')';
+ else
+ {
+ if(str.indexOf("@") >= 0) {
+ return true;
+ }
+ return false;
}
- $r->print('');
- $$prog_state{'laststart'}=&Time::HiRes::time();
- $r->rflush();
+}
+END
+ return $scripttag;
}
-# close Progress Line
-sub Close_PrgWin {
- my ($r,$prog_state)=@_;
- $r->print(''."\n");
- undef(%$prog_state);
- $r->rflush();
+
+# 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