--- loncom/interface/loncommon.pm 2013/07/12 00:15:40 1.1139
+++ loncom/interface/loncommon.pm 2017/08/07 20:22:13 1.1287
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1139 2013/07/12 00:15:40 raeburn Exp $
+# $Id: loncommon.pm,v 1.1287 2017/08/07 20:22:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -69,12 +69,21 @@ use Apache::lontexconvert();
use Apache::lonclonecourse();
use Apache::lonuserutils();
use Apache::lonuserstate();
+use Apache::courseclassifier();
use LONCAPA qw(:DEFAULT :match);
+use LONCAPA::LWPReq;
use DateTime::TimeZone;
-use DateTime::Locale::Catalog;
+use DateTime::Locale;
+use Encode();
use Text::Aspell;
use Authen::Captcha;
use Captcha::reCAPTCHA;
+use JSON::DWIW;
+use LWP::UserAgent;
+use Crypt::DES;
+use DynaLoader; # for Crypt::DES version
+use MIME::Lite;
+use MIME::Types;
# ---------------------------------------------- Designs
use vars qw(%defaultdesign);
@@ -259,7 +268,7 @@ BEGIN {
next if ($line =~ /^\#/);
chomp($line);
my ($extension,$category)=(split(/\s+/,$line,2));
- push @{$category_extensions{lc($category)}},$extension;
+ push(@{$category_extensions{lc($category)}},$extension);
}
close($fh);
}
@@ -532,7 +541,7 @@ ENDAUTHORBRW
sub coursebrowser_javascript {
my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
- $credits_element) = @_;
+ $credits_element,$instcode) = @_;
my $wintitle = 'Course_Browser';
if ($crstype eq 'Community') {
$wintitle = 'Community_Browser';
@@ -583,6 +592,12 @@ sub coursebrowser_javascript {
var ownername = document.forms[formid].ccuname.value;
var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
url += '&cloner='+ownername+':'+ownerdom;
+ if (type == 'Course') {
+ url += '&crscode='+document.forms[formid].crscode.value;
+ }
+ }
+ if (formname == 'requestcrs') {
+ url += '&crsdom=$domainfilter&crscode=$instcode';
}
if (multflag !=null && multflag != '') {
url += '&multiple='+multflag;
@@ -867,6 +882,8 @@ sub selectcourse_link {
my $linktext = &mt('Select Course');
if ($selecttype eq 'Community') {
$linktext = &mt('Select Community');
+ } elsif ($selecttype eq 'Placement') {
+ $linktext = &mt('Select Placement Test');
} elsif ($selecttype eq 'Course/Community') {
$linktext = &mt('Select Course/Community');
$type = '';
@@ -927,8 +944,8 @@ ENDSCRT
}
sub select_timezone {
- my ($name,$selected,$onchange,$includeempty)=@_;
- my $output=''."\n";
+ my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
+ my $output=''."\n";
if ($includeempty) {
$output .= ''."\n";
+ my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
+ my $output=''."\n";
if ($includeempty) {
$output .= '{'id'};
- if ($id ne '') {
- my $en_terr = $locale->{'en_territory'};
- my $native_terr = $locale->{'native_territory'};
- my @languages = &Apache::lonlocal::preferred_languages();
+ my @locales = DateTime::Locale->ids();
+ foreach my $id (@locales) {
+ if ($id ne '') {
+ my ($en_terr,$native_terr);
+ my $loc = DateTime::Locale->load($id);
+ if (ref($loc)) {
+ $en_terr = $loc->name();
+ $native_terr = $loc->native_name();
if (grep(/^en$/,@languages) || !@languages) {
if ($en_terr ne '') {
$locale_names{$id} = '('.$en_terr.')';
@@ -980,8 +998,9 @@ sub select_datelocale {
$locale_names{$id} = '('.$en_terr.')';
}
}
- push (@possibles,$id);
- }
+ $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
+ push(@possibles,$id);
+ }
}
}
foreach my $item (sort(@possibles)) {
@@ -991,7 +1010,7 @@ sub select_datelocale {
}
$output.=">$item";
if ($locale_names{$item} ne '') {
- $output.=" $locale_names{$item} \n";
+ $output.=' '.$locale_names{$item};
}
$output.=" \n";
}
@@ -1000,7 +1019,7 @@ sub select_datelocale {
}
sub select_language {
- my ($name,$selected,$includeempty) = @_;
+ my ($name,$selected,$includeempty,$noedit) = @_;
my %langchoices;
if ($includeempty) {
%langchoices = ('' => 'No language preference');
@@ -1012,7 +1031,7 @@ sub select_language {
}
}
%langchoices = &Apache::lonlocal::texthash(%langchoices);
- return &select_form($selected,$name,\%langchoices);
+ return &select_form($selected,$name,\%langchoices,undef,$noedit);
}
=pod
@@ -1036,7 +1055,7 @@ sub list_languages {
if ($code) {
my $selector = $supported_codes{$id};
my $description = &plainlanguagedescription($id);
- push (@lang_choices, [$selector, $description]);
+ push(@lang_choices, [$selector, $description]);
}
}
return \@lang_choices;
@@ -1076,6 +1095,9 @@ linked_select_forms takes the following
=item * $onchangesecond, additional javascript call to execute for an onchange
event for the second tag
+=item * $suffix, to differentiate separate uses of select2data javascript
+ objects in a page.
+
=back
Below is an example of such a hash. Only the 'text', 'default', and
@@ -1130,7 +1152,8 @@ sub linked_select_forms {
$hashref,
$menuorder,
$onchangefirst,
- $onchangesecond
+ $onchangesecond,
+ $suffix
) = @_;
my $second = "document.$formname.$secondselectname";
my $first = "document.$formname.$firstselectname";
@@ -1138,42 +1161,40 @@ sub linked_select_forms {
my $result = '';
$result.='
END
# output the initial values for the selection lists
- $result .= "\n";
+ $result .= "\n";
my @order = sort(keys(%{$hashref}));
if (ref($menuorder) eq 'ARRAY') {
@order = @{$menuorder};
@@ -1313,8 +1334,10 @@ sub helpLatexCheatsheet {
.&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
.'';
unless ($not_author) {
- $out .= ' '
- .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
+ $out .= ''
+ .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
+ .' '
+ .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
.' ';
}
$out .= ' '; # End cheatsheet
@@ -1380,32 +1403,38 @@ sub top_nav_help {
$text = &mt($text);
my $stay_on_page = 1;
- my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
- : "javascript:helpMenu('open')";
- my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
-
+ my ($link,$banner_link);
+ unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
+ $link = ($stay_on_page) ? "javascript:helpMenu('display')"
+ : "javascript:helpMenu('open')";
+ $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
+ }
my $title = &mt('Get help');
-
- return <<"END";
+ if ($link) {
+ return <<"END";
$banner_link
- $text
+$text
END
+ } else {
+ return ' '.$text.' ';
+ }
}
sub help_menu_js {
- my ($text) = @_;
+ my ($httphost) = @_;
my $stayOnPage = 1;
my $width = 620;
my $height = 600;
my $helptopic=&general_help();
- my $details_link = '/adm/help/'.$helptopic.'.hlp';
+ my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
my $start_page =
&Apache::loncommon::start_page('Help Menu', undef,
{'frameset' => 1,
'js_ready' => 1,
+ 'use_absolute' => $httphost,
'add_entries' => {
- 'border' => '0',
+ 'border' => '0',
'rows' => "110,*",},});
my $end_page =
&Apache::loncommon::end_page({'frameset' => 1,
@@ -1435,9 +1464,10 @@ function helpMenu(target) {
return;
}
function writeHelp(caller) {
- caller.document.writeln('$start_page\\n \\n \\n$end_page')
- caller.document.close()
- caller.focus()
+ caller.document.writeln('$start_page\\n \\n');
+ caller.document.writeln(' \\n$end_page');
+ caller.document.close();
+ caller.focus();
}
// END LON-CAPA Internal -->
// ]]>
@@ -1745,12 +1775,525 @@ RESIZE
}
+sub colorfuleditor_js {
+ my $browse_or_search;
+ my $respath;
+ my ($cnum,$cdom) = &crsauthor_url();
+ if ($cnum) {
+ $respath = "/res/$cdom/$cnum/";
+ my %js_lt = &Apache::lonlocal::texthash(
+ sunm => 'Sub-directory name',
+ save => 'Save page to make this permanent',
+ );
+ &js_escape(\%js_lt);
+ $browse_or_search = <<"END";
+
+ function toggleChooser(form,element,titleid,only,search) {
+ var disp = 'none';
+ if (document.getElementById('chooser_'+element)) {
+ var curr = document.getElementById('chooser_'+element).style.display;
+ if (curr == 'none') {
+ disp='inline';
+ if (form.elements['chooser_'+element].length) {
+ for (var i=0; i 1) {
+ window['select1'+element+'_changed']();
+ }
+ }
+ }
+ document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
+
+ }
+ if (document.getElementById('chooser_'+element+'_upload')) {
+ document.getElementById('chooser_'+element+'_upload').style.display = 'none';
+ if (document.getElementById('uploadcrsres_'+element)) {
+ document.getElementById('uploadcrsres_'+element).value = '';
+ }
+ }
+ return;
+ }
+
+ function toggleCrsUpload(form,element,numcrsdirs) {
+ if (document.getElementById('chooser_'+element+'_crsres')) {
+ document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
+ }
+ if (document.getElementById('chooser_'+element+'_upload')) {
+ var curr = document.getElementById('chooser_'+element+'_upload').style.display;
+ if (curr == 'none') {
+ if (numcrsdirs) {
+ form.elements['crsauthorpath_'+element].selectedIndex = 0;
+ form.elements['newsubdir_'+element][0].checked = true;
+ toggleNewsubdir(form,element);
+ }
+ }
+ document.getElementById('chooser_'+element+'_upload').style.display = 'block';
+ }
+ return;
+ }
+
+ function toggleResImport(form,element) {
+ var choices = new Array('crsres','upload');
+ for (var i=0; i $js_lt{sunm}';
+ }
+ } else {
+ document.getElementById('newsubdirname_'+element).type = "hidden";
+ document.getElementById('newsubdirname_'+element).value = "";
+ document.getElementById('newsubdir_'+element).innerHTML = "";
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ function updateCrsFile(form,element) {
+ var directory = form.elements['coursepath_'+element];
+ var filename = form.elements['coursefile_'+element];
+ var path = directory.options[directory.selectedIndex].value;
+ var file = filename.options[filename.selectedIndex].value;
+ form.elements[element].value = '$respath';
+ if (path == '/') {
+ form.elements[element].value += file;
+ } else {
+ form.elements[element].value += path+'/'+file;
+ }
+ unClean();
+ if (document.getElementById('previewimg_'+element)) {
+ document.getElementById('previewimg_'+element).src = form.elements[element].value;
+ var newsrc = document.getElementById('previewimg_'+element).src;
+ }
+ if (document.getElementById('showimg_'+element)) {
+ document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
+ }
+ toggleChooser(form,element);
+ return;
+ }
+
+ function uploadDone(suffix,name) {
+ if (name) {
+ document.forms["lonhomework"].elements[suffix].value = name;
+ unClean();
+ toggleChooser(document.forms["lonhomework"],suffix);
+ }
+ }
+
+\$(document).ready(function(){
+
+ \$(document).delegate('form :submit', 'click', function( event ) {
+ if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
+ var buttonId = this.id;
+ var suffix = buttonId.toString();
+ suffix = suffix.replace(/^crsupload_/,'');
+ event.preventDefault();
+ document.lonhomework.target = 'crsupload_target_'+suffix;
+ document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
+ \$(this.form).submit();
+ document.lonhomework.target = '';
+ if (document.getElementById('crsuploadto_'+suffix)) {
+ document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
+ }
+ return false;
+ }
+ });
+});
+END
+ }
+ return <<"COLORFULEDIT"
+
+COLORFULEDIT
+}
+
+sub xmleditor_js {
+ return <
+
+XMLEDIT
+}
+
+sub insert_folding_button {
+ my $curDepth = $Apache::lonxml::curdepth;
+ my $lastresource = $env{'request.ambiguous'};
+
+ return " ";
+}
+
+sub crsauthor_url {
+ my ($url) = @_;
+ if ($url eq '') {
+ $url = $ENV{'REQUEST_URI'};
+ }
+ my ($cnum,$cdom);
+ if ($env{'request.course.id'}) {
+ my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
+ if ($audom ne '' && $auname ne '') {
+ if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
+ ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
+ $cnum = $auname;
+ $cdom = $audom;
+ }
+ }
+ }
+ return ($cnum,$cdom);
+}
+
+sub import_crsauthor_form {
+ my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
+ return (0) unless ($env{'request.course.id'});
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
+ return (0) unless (($cnum ne '') && ($cdom ne ''));
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ my @ids=&Apache::lonnet::current_machine_ids();
+ my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
+
+ if (grep(/^\Q$crshome\E$/,@ids)) {
+ $is_home = 1;
+ }
+ $relpath = "/priv/$cdom/$cnum";
+ &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
+ my %lt = &Apache::lonlocal::texthash (
+ fnam => 'Filename',
+ dire => 'Directory',
+ );
+ my $numdirs = scalar(keys(%files));
+ my (%possexts,$singledir,@singledirfiles);
+ if ($only) {
+ map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
+ }
+ my (%nonemptydirs,$possdirs);
+ if ($numdirs > 1) {
+ my @order;
+ foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
+ if (ref($files{$key}) eq 'HASH') {
+ my $shown = $key;
+ if ($key eq '') {
+ $shown = '/';
+ }
+ my @ordered = ();
+ foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
+ if ($only) {
+ my ($ext) = ($file =~ /\.([^.]+)$/);
+ unless ($possexts{lc($ext)}) {
+ next;
+ }
+ }
+ $selimport_menus{$key}->{'select2'}->{$file} = $file;
+ push(@ordered,$file);
+ }
+ if (@ordered) {
+ push(@order,$key);
+ $nonemptydirs{$key} = 1;
+ $selimport_menus{$key}->{'text'} = $shown;
+ $selimport_menus{$key}->{'default'} = '';
+ $selimport_menus{$key}->{'select2'}->{''} = '';
+ $selimport_menus{$key}->{'order'} = \@ordered;
+ }
+ }
+ }
+ $possdirs = scalar(keys(%nonemptydirs));
+ if ($possdirs > 1) {
+ my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
+ $output = $lt{'dire'}.
+ &linked_select_forms($form,' '.
+ $lt{'fnam'},'',
+ $firstselectname,$secondselectname,
+ \%selimport_menus,\@order,
+ $onchangefirst,'',$suffix).' ';
+ } elsif ($possdirs == 1) {
+ $singledir = (keys(%nonemptydirs))[0];
+ if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
+ @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
+ }
+ delete($selimport_menus{$singledir});
+ }
+ } elsif ($numdirs == 1) {
+ $singledir = (keys(%files))[0];
+ foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
+ if ($only) {
+ my ($ext) = ($file =~ /\.([^.]+)$/);
+ unless ($possexts{lc($ext)}) {
+ next;
+ }
+ }
+ push(@singledirfiles,$file);
+ }
+ if (@singledirfiles) {
+ $possdirs == 1;
+ }
+ }
+ if (($possdirs == 1) && (@singledirfiles)) {
+ my $showdir = $singledir;
+ if ($singledir eq '') {
+ $showdir = '/';
+ }
+ $output = $lt{'dire'}.
+ ''.
+ ''.$showdir.' '."\n".
+ ' '.
+ $lt{'fnam'}.''."\n".
+ ''.$lt{'se'}.' '."\n";
+ foreach my $file (@singledirfiles) {
+ $output .= ''.$file.' '."\n";
+ }
+ $output .= ' '."\n";
+ }
+ return ($possdirs,$output);
+}
+
=pod
=head1 Excel and CSV file utility routines
-=over 4
-
=cut
###############################################################
@@ -1758,6 +2301,8 @@ RESIZE
=pod
+=over 4
+
=item * &csv_translate($text)
Translate $text to allow it to be output as a 'comma separated values'
@@ -2004,12 +2549,15 @@ sub multiple_select_form {
=pod
-=item * &select_form($defdom,$name,$hashref,$onchange)
+=item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
Returns a string containing a form to
allow a user to select options from a ref to a hash containing:
option_name => displayed text. An optional $onchange can include
-a javascript onchange item, e.g., onchange="this.form.submit();"
+a javascript onchange item, e.g., onchange="this.form.submit();".
+An optional arg -- $readonly -- if true will cause the select form
+to be disabled, e.g., for the case where an instructor has a section-
+specific role, and is viewing/modifying parameters.
See lonrights.pm for an example invocation and use.
@@ -2017,12 +2565,16 @@ See lonrights.pm for an example invocati
#-------------------------------------------
sub select_form {
- my ($def,$name,$hashref,$onchange) = @_;
+ my ($def,$name,$hashref,$onchange,$readonly) = @_;
return unless (ref($hashref) eq 'HASH');
if ($onchange) {
$onchange = ' onchange="'.$onchange.'"';
}
- my $selectform = "\n";
+ my $disabled;
+ if ($readonly) {
+ $disabled = ' disabled="disabled"';
+ }
+ my $selectform = "\n";
my @keys;
if (exists($hashref->{'select_form_order'})) {
@keys=@{$hashref->{'select_form_order'}};
@@ -2191,7 +2743,7 @@ sub select_level_form {
=pod
-=item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
+=item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
Returns a string containing a form to
allow a user to select the domain to preform an operation in.
@@ -2208,14 +2760,19 @@ The optional $incdoms is a reference to
The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
+The optional $disabled argument, if true, adds the disabled attribute to the select tag.
+
=cut
#-------------------------------------------
sub select_dom_form {
- my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
+ my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
if ($onchange) {
$onchange = ' onchange="'.$onchange.'"';
}
+ if ($disabled) {
+ $disabled = ' disabled="disabled"';
+ }
my (@domains,%exclude);
if (ref($incdoms) eq 'ARRAY') {
@domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
@@ -2226,7 +2783,7 @@ sub select_dom_form {
if (ref($excdoms) eq 'ARRAY') {
map { $exclude{$_} = 1; } @{$excdoms};
}
- my $selectdomain = "\n";
+ my $selectdomain = "\n";
foreach my $dom (@domains) {
next if ($exclude{$dom});
$selectdomain.=" ';
+ $authtype = ' ';
}
}
}
@@ -2645,7 +3222,7 @@ sub authform_kerberos {
if ($authtype eq '') {
$authtype = ' ';
+ $krbcheck.$disabled.' />';
}
if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
($can_assign{'krb4'} && !$can_assign{'krb5'} &&
@@ -2658,9 +3235,9 @@ sub authform_kerberos {
''.$authtype,
' ',
- ' ',
- ' ',
+ 'onchange="'.$jscall.'"'.$disabled.' />',
+ ' ',
+ ' ',
' ');
} elsif ($can_assign{'krb4'}) {
$result .= &mt
@@ -2669,7 +3246,7 @@ sub authform_kerberos {
''.$authtype,
' ',
+ 'onchange="'.$jscall.'"'.$disabled.' />',
' ',
' ');
} elsif ($can_assign{'krb5'}) {
@@ -2679,7 +3256,7 @@ sub authform_kerberos {
''.$authtype,
' ',
+ 'onchange="'.$jscall.'"'.$disabled.' />',
' ',
' ');
}
@@ -2692,8 +3269,11 @@ sub authform_internal {
kerb_def_dom => 'MSU.EDU',
@_,
);
- my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
+ my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
+ if ($in{'readonly'}) {
+ $disabled = ' disabled="disabled"';
+ }
if (defined($in{'curr_authtype'})) {
if ($in{'curr_authtype'} eq 'int') {
if ($can_assign{'int'}) {
@@ -2722,7 +3302,7 @@ sub authform_internal {
if (defined($in{'mode'})) {
if ($in{'mode'} eq 'modifycourse') {
if ($authnum == 1) {
- $authtype = ' ';
+ $authtype = ' ';
}
}
}
@@ -2730,14 +3310,14 @@ sub authform_internal {
$jscall = "javascript:changed_radio('int',$in{'formname'});";
if ($authtype eq '') {
$authtype = ' ';
+ ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
}
$autharg = ' ';
+ $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
$result = &mt
('[_1] Internally authenticated (with initial password [_2])',
''.$authtype,' '.$autharg);
- $result.=" ".&mt('Visible input').' ';
+ $result.=' '.&mt('Visible input').' ';
return $result;
}
@@ -2747,8 +3327,11 @@ sub authform_local {
kerb_def_dom => 'MSU.EDU',
@_,
);
- my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
+ my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
+ if ($in{'readonly'}) {
+ $disabled = ' disabled="disabled"';
+ }
if (defined($in{'curr_authtype'})) {
if ($in{'curr_authtype'} eq 'loc') {
if ($can_assign{'loc'}) {
@@ -2777,7 +3360,7 @@ sub authform_local {
if (defined($in{'mode'})) {
if ($in{'mode'} eq 'modifycourse') {
if ($authnum == 1) {
- $authtype = ' ';
+ $authtype = ' ';
}
}
}
@@ -2786,10 +3369,10 @@ sub authform_local {
if ($authtype eq '') {
$authtype = ' ';
+ $jscall.'"'.$disabled.' />';
}
$autharg = ' ';
+ $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
$result = &mt('[_1] Local Authentication with argument [_2]',
''.$authtype,' '.$autharg);
return $result;
@@ -2801,8 +3384,11 @@ sub authform_filesystem {
kerb_def_dom => 'MSU.EDU',
@_,
);
- my ($fsyscheck,$result,$authtype,$autharg,$jscall);
+ my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
+ if ($in{'readonly'}) {
+ $disabled = ' disabled="disabled"';
+ }
if (defined($in{'curr_authtype'})) {
if ($in{'curr_authtype'} eq 'fsys') {
if ($can_assign{'fsys'}) {
@@ -2815,7 +3401,7 @@ sub authform_filesystem {
} else {
$result = &mt('Currently Filesystem Authenticated.');
return $result;
- }
+ }
}
} else {
if ($authnum == 1) {
@@ -2828,7 +3414,7 @@ sub authform_filesystem {
if (defined($in{'mode'})) {
if ($in{'mode'} eq 'modifycourse') {
if ($authnum == 1) {
- $authtype = ' ';
+ $authtype = ' ';
}
}
}
@@ -2837,16 +3423,16 @@ sub authform_filesystem {
if ($authtype eq '') {
$authtype = ' ';
+ $jscall.'"'.$disabled.' />';
}
$autharg = ' ';
+ ' onchange="'.$jscall.'"'.$disabled.' />';
$result = &mt
('[_1] Filesystem Authenticated (with initial password [_2])',
' ',
+ $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
' ');
+ 'onchange="'.$jscall.'"'.$disabled.' />');
return $result;
}
@@ -2868,7 +3454,7 @@ sub get_assignable_auth {
my $context;
if ($env{'request.role'} =~ /^au/) {
$context = 'author';
- } elsif ($env{'request.role'} =~ /^dc/) {
+ } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
$context = 'domain';
} elsif ($env{'request.course.id'}) {
$context = 'course';
@@ -3066,6 +3652,8 @@ sub get_related_words {
=pod
+=back
+
=head1 Spell checking
=over 4
@@ -3099,12 +3687,6 @@ Note: This sub assumes that aspell is in
=cut
-=pod
-
-=back
-
-=cut
-
sub check_spelling {
my ($wordlist, $language) = @_;
my @misspellings;
@@ -3320,7 +3902,7 @@ sub screenname {
# ------------------------------------------------------------- Confirm Wrapper
=pod
-=item confirmwrapper
+=item * &confirmwrapper($message)
Wrap messages about completion of operation in box
@@ -3593,7 +4175,11 @@ category
sub filecategorytypes {
my ($cat) = @_;
- return @{$category_extensions{lc($cat)}};
+ if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
+ return @{$category_extensions{lc($cat)}};
+ } else {
+ return ();
+ }
}
=pod
@@ -3736,7 +4322,7 @@ sub user_lang {
=over 4
=item * &get_previous_attempt($symb, $username, $domain, $course,
- $getattempt, $regexp, $gradesub)
+ $getattempt, $regexp, $gradesub, $usec, $identifier)
Return string with previous attempt on problem. Arguments:
@@ -3758,6 +4344,11 @@ Return string with previous attempt on p
=item * $gradesub: routine that processes the string if it matches $regexp
+=item * $usec: section of the desired student
+
+=item * $identifier: counter for student (multiple students one problem) or
+ problem (one student; whole sequence).
+
=back
The output string is a table containing all desired attempts, if any.
@@ -3765,7 +4356,7 @@ The output string is a table containing
=cut
sub get_previous_attempt {
- my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
+ my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
my $prevattempts='';
no strict 'refs';
if ($symb) {
@@ -3775,13 +4366,18 @@ sub get_previous_attempt {
my %lasthash=();
my $version;
for ($version=1;$version<=$returnhash{'version'};$version++) {
- foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
- $lasthash{$key}=$returnhash{$version.':'.$key};
+ foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
+ if ($key =~ /\.rawrndseed$/) {
+ my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
+ $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
+ } else {
+ $lasthash{$key}=$returnhash{$version.':'.$key};
+ }
}
}
$prevattempts=&start_data_table().&start_data_table_header_row();
$prevattempts.=''.&mt('History').' ';
- my (%typeparts,%lasthidden);
+ my (%typeparts,%lasthidden,%regraded,%hidestatus);
my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
foreach my $key (sort(keys(%lasthash))) {
my ($ign,@parts) = split(/\./,$key);
@@ -3798,6 +4394,18 @@ sub get_previous_attempt {
$lasthidden{$ign.'.'.$id} = 1;
}
}
+ if ($identifier ne '') {
+ my $id = join(',',@parts);
+ if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
+ $domain,$username,$usec,undef,$course) =~ /^no/) {
+ $hidestatus{$ign.'.'.$id} = 1;
+ }
+ }
+ } elsif ($data eq 'regrader') {
+ if (($identifier ne '') && (@parts)) {
+ my $id = join(',',@parts);
+ $regraded{$ign.'.'.$id} = 1;
+ }
}
} else {
if ($#parts == 0) {
@@ -3809,17 +4417,60 @@ sub get_previous_attempt {
}
$prevattempts.=&end_data_table_header_row();
if ($getattempt eq '') {
+ my (%solved,%resets,%probstatus);
+ if (($identifier ne '') && (keys(%regraded) > 0)) {
+ for ($version=1;$version<=$returnhash{'version'};$version++) {
+ foreach my $id (keys(%regraded)) {
+ if (($returnhash{$version.':'.$id.'.regrader'}) &&
+ ($returnhash{$version.':'.$id.'.tries'} eq '') &&
+ ($returnhash{$version.':'.$id.'.award'} eq '')) {
+ push(@{$resets{$id}},$version);
+ }
+ }
+ }
+ }
for ($version=1;$version<=$returnhash{'version'};$version++) {
- my @hidden;
+ my (@hidden,@unsolved);
if (%typeparts) {
foreach my $id (keys(%typeparts)) {
- if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
+ if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
+ ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
push(@hidden,$id);
+ } elsif ($identifier ne '') {
+ unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
+ ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
+ ($hidestatus{$id})) {
+ next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
+ if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
+ push(@{$solved{$id}},$version);
+ } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
+ (ref($solved{$id}) eq 'ARRAY')) {
+ my $skip;
+ if (ref($resets{$id}) eq 'ARRAY') {
+ foreach my $reset (@{$resets{$id}}) {
+ if ($reset > $solved{$id}[-1]) {
+ $skip=1;
+ last;
+ }
+ }
+ }
+ unless ($skip) {
+ my ($ign,$partslist) = split(/\./,$id,2);
+ push(@unsolved,$partslist);
+ }
+ }
+ }
}
}
}
$prevattempts.=&start_data_table_row().
- ''.&mt('Transaction [_1]',$version).' ';
+ ''.&mt('Transaction [_1]',$version);
+ if (@unsolved) {
+ $prevattempts .= ''.
+ ' '.
+ &mt('Hide').' ';
+ }
+ $prevattempts .= ' ';
if (@hidden) {
foreach my $key (sort(keys(%lasthash))) {
next if ($key =~ /\.foilorder$/);
@@ -3841,9 +4492,15 @@ sub get_previous_attempt {
}
} else {
if ($key =~ /\./) {
- my $value = &format_previous_attempt_value($key,
- $returnhash{$version.':'.$key});
- $prevattempts.=''.$value.' ';
+ my $value = $returnhash{$version.':'.$key};
+ if ($key =~ /\.rndseed$/) {
+ my ($id) = ($key =~ /^(.+)\.[^.]+$/);
+ if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
+ $value = $returnhash{$version.':'.$id.'.rawrndseed'};
+ }
+ }
+ $prevattempts.=''.&format_previous_attempt_value($key,$value).
+ ' ';
} else {
$prevattempts.=' ';
}
@@ -3852,9 +4509,15 @@ sub get_previous_attempt {
} else {
foreach my $key (sort(keys(%lasthash))) {
next if ($key =~ /\.foilorder$/);
- my $value = &format_previous_attempt_value($key,
- $returnhash{$version.':'.$key});
- $prevattempts.=''.$value.' ';
+ my $value = $returnhash{$version.':'.$key};
+ if ($key =~ /\.rndseed$/) {
+ my ($id) = ($key =~ /^(.+)\.[^.]+$/);
+ if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
+ $value = $returnhash{$version.':'.$id.'.rawrndseed'};
+ }
+ }
+ $prevattempts.=''.&format_previous_attempt_value($key,$value).
+ ' ';
}
}
$prevattempts.=&end_data_table_row();
@@ -3879,7 +4542,7 @@ sub get_previous_attempt {
if ($key =~/$regexp$/ && (defined &$gradesub)) {
$value = &$gradesub($value);
}
- $prevattempts.=''.$value.' ';
+ $prevattempts.=''. $value.' ';
} else {
$prevattempts.=' ';
}
@@ -3895,7 +4558,7 @@ sub get_previous_attempt {
if ($key =~/$regexp$/ && (defined &$gradesub)) {
$value = &$gradesub($value);
}
- $prevattempts.=''.$value.' ';
+ $prevattempts.=''.$value.' ';
}
}
$prevattempts.= &end_data_table_row().&end_data_table();
@@ -3916,11 +4579,13 @@ sub get_previous_attempt {
sub format_previous_attempt_value {
my ($key,$value) = @_;
if (($key =~ /timestamp/) || ($key=~/duedate/)) {
- $value = &Apache::lonlocal::locallocaltime($value);
+ $value = &Apache::lonlocal::locallocaltime($value);
} elsif (ref($value) eq 'ARRAY') {
- $value = '('.join(', ', @{ $value }).')';
+ $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
} elsif ($key =~ /answerstring$/) {
my %answers = &Apache::lonnet::str2hash($value);
+ my @answer = %answers;
+ %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
my @anskeys = sort(keys(%answers));
if (@anskeys == 1) {
my $answer = $answers{$anskeys[0]};
@@ -3943,7 +4608,7 @@ sub format_previous_attempt_value {
}
}
} else {
- $value = &unescape($value);
+ $value = &HTML::Entities::encode(&unescape($value), '"<>&');
}
return $value;
}
@@ -4304,23 +4969,20 @@ sub findallcourses {
###############################################
sub blockcheck {
- my ($setters,$activity,$uname,$udom,$url) = @_;
+ my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
- if (!defined($udom)) {
+ if (defined($udom) && defined($uname)) {
+ # If uname and udom are for a course, check for blocks in the course.
+ if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
+ my ($startblock,$endblock,$triggerblock) =
+ &get_blocks($setters,$activity,$udom,$uname,$url);
+ return ($startblock,$endblock,$triggerblock);
+ }
+ } else {
$udom = $env{'user.domain'};
- }
- if (!defined($uname)) {
$uname = $env{'user.name'};
}
- # If uname and udom are for a course, check for blocks in the course.
-
- if (&Apache::lonnet::is_course($udom,$uname)) {
- my ($startblock,$endblock,$triggerblock) =
- &get_blocks($setters,$activity,$udom,$uname,$url);
- return ($startblock,$endblock,$triggerblock);
- }
-
my $startblock = 0;
my $endblock = 0;
my $triggerblock = '';
@@ -4330,7 +4992,9 @@ sub blockcheck {
# boards, chat or groups, check for blocking in current course only.
if (($activity eq 'boards' || $activity eq 'chat' ||
- $activity eq 'groups') && ($env{'request.course.id'})) {
+ $activity eq 'groups' || $activity eq 'printout' ||
+ $activity eq 'reinit' || $activity eq 'alert') &&
+ ($env{'request.course.id'})) {
foreach my $key (keys(%live_courses)) {
if ($key ne $env{'request.course.id'}) {
delete($live_courses{$key});
@@ -4413,7 +5077,7 @@ sub blockcheck {
$tdom,$spec,$trest,$area);
}
}
- my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
+ my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
if ($1) {
$no_userblock = 1;
@@ -4437,7 +5101,7 @@ sub blockcheck {
# Retrieve blocking times and identity of locker for course
# of specified user, unless user has 'evb' privilege.
-
+
my ($start,$end,$trigger) =
&get_blocks($setters,$activity,$cdom,$cnum,$url);
if (($start != 0) &&
@@ -4524,13 +5188,19 @@ sub get_blocks {
my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
if ($start && $end) {
if (($start <= time) && ($end >= time)) {
- unless (grep(/^\Q$block\E$/,@blockers)) {
- push(@blockers,$block);
- $triggered{$block} = {
- start => $start,
- end => $end,
- type => $type,
- };
+ if (ref($commblocks{$block}) eq 'HASH') {
+ if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
+ if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
+ unless(grep(/^\Q$block\E$/,@blockers)) {
+ push(@blockers,$block);
+ $triggered{$block} = {
+ start => $start,
+ end => $end,
+ type => $type,
+ };
+ }
+ }
+ }
}
}
}
@@ -4594,12 +5264,12 @@ sub parse_block_record {
}
sub blocking_status {
- my ($activity,$uname,$udom,$url) = @_;
+ my ($activity,$uname,$udom,$url,$is_course) = @_;
my %setters;
# check for active blocking
my ($startblock,$endblock,$triggerblock) =
- &blockcheck(\%setters,$activity,$uname,$udom,$url);
+ &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
my $blocked = 0;
if ($startblock && $endblock) {
$blocked = 1;
@@ -4611,9 +5281,9 @@ sub blocking_status {
# build a link to a popup window containing the details
my $querystring = "?activity=$activity";
# $uname and $udom decide whose portfolio the user is trying to look at
- if ($activity eq 'port') {
- $querystring .= "&udom=$udom" if $udom;
- $querystring .= "&uname=$uname" if $uname;
+ if (($activity eq 'port') || ($activity eq 'passwd')) {
+ $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
+ $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
} elsif ($activity eq 'docs') {
$querystring .= '&url='.&HTML::Entities::encode($url,'&"');
}
@@ -4632,13 +5302,21 @@ END_MYBLOCK
my $popupUrl = "/adm/blockingstatus/$querystring";
my $text = &mt('Communication Blocked');
+ my $class = 'LC_comblock';
if ($activity eq 'docs') {
$text = &mt('Content Access Blocked');
+ $class = '';
} elsif ($activity eq 'printout') {
$text = &mt('Printing Blocked');
+ } elsif ($activity eq 'passwd') {
+ $text = &mt('Password Changing Blocked');
+ } elsif ($activity eq 'alert') {
+ $text = &mt('Checking Critical Messages Blocked');
+ } elsif ($activity eq 'reinit') {
+ $text = &mt('Checking Course Update Blocked');
}
$output .= <<"END_BLOCK";
-
+
@@ -4654,22 +5332,44 @@ END_BLOCK
###############################################
sub check_ip_acc {
- my ($acc)=@_;
+ my ($acc,$clientip)=@_;
&Apache::lonxml::debug("acc is $acc");
if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
return 1;
}
- my $allowed=0;
- my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
+ my $allowed;
+ my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
my $name;
- foreach my $pattern (split(',',$acc)) {
- $pattern =~ s/^\s*//;
- $pattern =~ s/\s*$//;
+ my %access = (
+ allowfrom => 1,
+ denyfrom => 0,
+ );
+ my @allows;
+ my @denies;
+ foreach my $item (split(',',$acc)) {
+ $item =~ s/^\s*//;
+ $item =~ s/\s*$//;
+ my $pattern;
+ if ($item =~ /^\!(.+)$/) {
+ push(@denies,$1);
+ } else {
+ push(@allows,$item);
+ }
+ }
+ my $numdenies = scalar(@denies);
+ my $numallows = scalar(@allows);
+ my $count = 0;
+ foreach my $pattern (@denies,@allows) {
+ $count ++;
+ my $acctype = 'allowfrom';
+ if ($count <= $numdenies) {
+ $acctype = 'denyfrom';
+ }
if ($pattern =~ /\*$/) {
#35.8.*
$pattern=~s/\*//;
- if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
+ if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
} elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
#35.8.3.[34-56]
my $low=$2;
@@ -4677,7 +5377,7 @@ sub check_ip_acc {
$pattern=$1;
if ($ip =~ /^\Q$pattern\E/) {
my $last=(split(/\./,$ip))[3];
- if ($last <=$high && $last >=$low) { $allowed=1; }
+ if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
}
} elsif ($pattern =~ /^\*/) {
#*.msu.edu
@@ -4687,10 +5387,10 @@ sub check_ip_acc {
my $netaddr=inet_aton($ip);
($name)=gethostbyaddr($netaddr,AF_INET);
}
- if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
+ if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
} elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
#127.0.0.1
- if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
+ if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
} else {
#some.name.com
if (!defined($name)) {
@@ -4698,9 +5398,16 @@ sub check_ip_acc {
my $netaddr=inet_aton($ip);
($name)=gethostbyaddr($netaddr,AF_INET);
}
- if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
+ if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
+ }
+ if ($allowed =~ /^(0|1)$/) { last; }
+ }
+ if ($allowed eq '') {
+ if ($numdenies && !$numallows) {
+ $allowed = 1;
+ } else {
+ $allowed = 0;
}
- if ($allowed) { last; }
}
return $allowed;
}
@@ -4756,23 +5463,29 @@ sub get_domainconf {
if (keys(%{$domconfig{'login'}})) {
foreach my $key (keys(%{$domconfig{'login'}})) {
if (ref($domconfig{'login'}{$key}) eq 'HASH') {
- if ($key eq 'loginvia') {
- if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
- foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
- if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
- if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
- my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
- $designhash{$udom.'.login.loginvia'} = $server;
- if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
-
- $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
- } else {
- $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
+ if (($key eq 'loginvia') || ($key eq 'headtag')) {
+ if (ref($domconfig{'login'}{$key}) eq 'HASH') {
+ foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
+ if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
+ if ($key eq 'loginvia') {
+ if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
+ my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
+ $designhash{$udom.'.login.loginvia'} = $server;
+ if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
+
+ $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
+ } else {
+ $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
+ }
}
- if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
- $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
+ } elsif ($key eq 'headtag') {
+ if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
+ $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
}
}
+ if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
+ $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
+ }
}
}
}
@@ -5029,10 +5742,20 @@ sub CSTR_pageheader {
$lastitem = $thisdisfn;
}
+ my ($crsauthor,$title);
+ if (($env{'request.course.id'}) &&
+ ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
+ ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
+ $crsauthor = 1;
+ $title = &mt('Course Authoring Space');
+ } else {
+ $title = &mt('Authoring Space');
+ }
+
my $output =
'
'
.&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
- .''.&mt('Authoring Space:').' '
+ .''.$title.' '
.''
- .&Apache::lonmenu::constspaceform()
- .'
';
+
+ if ($crsauthor) {
+ $output .= ''.&Apache::lonmenu::constspaceform();
+ } else {
+ $output .=
+ '
'
+ #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."
"
+ .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
+ .''
+ .&Apache::lonmenu::constspaceform();
+ }
+ $output .= '
';
return $output;
}
@@ -5093,9 +5821,10 @@ Inputs:
=item * $args, optional argument valid values are
no_auto_mt_title -> prevents &mt()ing the title arg
- inherit_jsmath -> when creating popup window in a page,
- should it have jsmath forced on by the
- current page
+ use_absolute -> for external resource or syllabus, this will
+ contain https://
if server uses
+ https (as per hosts.tab), but request is for http
+ hostname -> hostname, from $r->hostname().
=item * $advtoolsref, optional argument, ref to an array containing
inlineremote items to be added in "Functions" menu below
@@ -5120,6 +5849,8 @@ sub bodytag {
$public = 1;
}
if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
+ my $httphost = $args->{'use_absolute'};
+ my $hostname = $args->{'hostname'};
$function = &get_users_function() if (!$function);
my $img = &designparm($function.'.img',$domain);
@@ -5135,7 +5866,10 @@ sub bodytag {
@design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
# role and realm
- my ($role,$realm) = split(/\./,$env{'request.role'},2);
+ my ($role,$realm) = split(m{\./},$env{'request.role'},2);
+ if ($realm) {
+ $realm = '/'.$realm;
+ }
if ($role eq 'ca') {
my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
$realm = &plainname($rname,$rdom);
@@ -5144,6 +5878,14 @@ sub bodytag {
if ($env{'request.course.id'}) {
if ($env{'request.role'} !~ /^cr/) {
$role = &Apache::lonnet::plaintext($role,&course_type());
+ } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
+ if ($env{'request.role.desc'}) {
+ $role = $env{'request.role.desc'};
+ } else {
+ $role = &mt('Helpdesk[_1]',' '.$2);
+ }
+ } else {
+ $role = (split(/\//,$role,4))[-1];
}
if ($env{'request.course.sec'}) {
$role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
@@ -5159,7 +5901,7 @@ sub bodytag {
# construct main body tag
my $bodytag = "".
- &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
+ &Apache::lontexconvert::init_math_support();
&get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
@@ -5183,7 +5925,17 @@ sub bodytag {
$dc_info =~ s/\s+$//;
}
- $role = '('.$role.') ' if $role;
+ my $crstype;
+ if ($env{'request.course.id'}) {
+ $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
+ } elsif ($args->{'crstype'}) {
+ $crstype = $args->{'crstype'};
+ }
+ if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
+ undef($role);
+ } else {
+ $role = '('.$role.') ' if ($role && !$env{'browser.mobile'});
+ }
if ($env{'request.state'} eq 'construct') { $forcereg=1; }
@@ -5192,9 +5944,9 @@ sub bodytag {
# }
$bodytag .= Apache::lonhtmlcommon::scripttag(
- Apache::lonmenu::utilityfunctions(), 'start');
+ Apache::lonmenu::utilityfunctions($httphost), 'start');
- my ($left,$right) = Apache::lonmenu::primary_menu();
+ my ($left,$right) = Apache::lonmenu::primary_menu($crstype);
if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
if ($dc_info) {
@@ -5216,23 +5968,29 @@ sub bodytag {
}
$bodytag .= qq|$realm $dc_info
|;
+ #if directed to not display the secondary menu, don't.
+ if ($args->{'no_secondary_menu'}) {
+ return $bodytag;
+ }
#don't show menus for public users
if (!$public){
- $bodytag .= Apache::lonmenu::secondary_menu();
+ $bodytag .= Apache::lonmenu::secondary_menu($httphost);
$bodytag .= Apache::lonmenu::serverform();
$bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
if ($env{'request.state'} eq 'construct') {
$bodytag .= &Apache::lonmenu::innerregister($forcereg,
- $args->{'bread_crumbs'});
+ $args->{'bread_crumbs'},'','',$hostname);
} elsif ($forcereg) {
$bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
- $args->{'group'});
+ $args->{'group'},
+ $args->{'hide_buttons'},
+ $hostname);
} else {
$bodytag .=
&Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
$forcereg,$args->{'group'},
$args->{'bread_crumbs'},
- $advtoolsref);
+ $advtoolsref,'',$hostname);
}
}else{
# this is to seperate menu from content when there's no secondary
@@ -5278,7 +6036,7 @@ sub make_attr_string {
}
my $attr_string;
- foreach my $attr (keys(%$attr_ref)) {
+ foreach my $attr (sort(keys(%$attr_ref))) {
$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
}
return $attr_string;
@@ -5308,7 +6066,6 @@ sub endbodytag {
unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
$endbodytag='';
}
- $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
if ( exists( $env{'internal.head.redirect'} ) ) {
if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
$endbodytag=
@@ -5483,6 +6240,17 @@ div.LC_confirm_box .LC_success img {
vertical-align: middle;
}
+.LC_maxwidth {
+ max-width: 100%;
+ height: auto;
+}
+
+.LC_textsize_mobile {
+ \@media only screen and (max-device-width: 480px) {
+ -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
+ }
+}
+
.LC_icon {
border: none;
vertical-align: middle;
@@ -5588,6 +6356,12 @@ ul.LC_breadcrumb_tools_outerlist li {
float: right;
}
+.LC_placement_prog {
+ padding-right: 20px;
+ font-weight: bold;
+ font-size: 90%;
+}
+
table#LC_title_bar td {
background: $tabbg;
}
@@ -5604,6 +6378,10 @@ table#LC_menubuttons img {
vertical-align: middle;
}
+.LC_breadcrumbs_hoverable {
+ background: $sidebg;
+}
+
td.LC_table_cell_checkbox {
text-align: center;
}
@@ -5674,6 +6452,11 @@ td.LC_menubuttons_text {
background: $tabbg;
}
+td.LC_zero_height {
+ line-height: 0;
+ cellpadding: 0;
+}
+
table.LC_data_table {
border: 1px solid #000000;
border-collapse: separate;
@@ -5995,6 +6778,12 @@ td.LC_parm_overview_restrictions {
border-collapse: collapse;
}
+span.LC_parm_recursive,
+td.LC_parm_recursive {
+ font-weight: bold;
+ font-size: smaller;
+}
+
table.LC_parm_overview_restrictions td {
border-width: 1px 4px 1px 4px;
border-style: solid;
@@ -6346,6 +7135,12 @@ table.LC_data_table tr > td.LC_docs_entr
color: #990000;
}
+.LC_docs_alias {
+ color: #440055;
+}
+
+.LC_domprefs_email,
+.LC_docs_alias_name,
.LC_docs_reinit_warn,
.LC_docs_ext_edit {
font-size: x-small;
@@ -6461,7 +7256,7 @@ div.LC_edit_problem_footer,
div.LC_edit_problem_footer div,
div.LC_edit_problem_editxml_header,
div.LC_edit_problem_editxml_header div {
- margin-top: 5px;
+ z-index: 100;
}
div.LC_edit_problem_header_title {
@@ -6477,14 +7272,17 @@ table.LC_edit_problem_header_title {
background: $tabbg;
}
-div.LC_edit_problem_discards {
- float: left;
- padding-bottom: 5px;
+div.LC_edit_actionbar {
+ background-color: $sidebg;
+ margin: 0;
+ padding: 0;
+ line-height: 200%;
}
-div.LC_edit_problem_saves {
- float: right;
- padding-bottom: 5px;
+div.LC_edit_actionbar div{
+ padding: 0;
+ margin: 0;
+ display: inline-block;
}
.LC_edit_opt {
@@ -6492,6 +7290,18 @@ div.LC_edit_problem_saves {
white-space: nowrap;
}
+.LC_edit_problem_latexhelper{
+ text-align: right;
+}
+
+#LC_edit_problem_colorful div{
+ margin-left: 40px;
+}
+
+#LC_edit_problem_codemirror div{
+ margin-left: 0px;
+}
+
img.stift {
border-width: 0;
vertical-align: middle;
@@ -6579,6 +7389,10 @@ fieldset {
/* overflow: hidden; */
}
+article.geogebraweb div {
+ margin: 0;
+}
+
fieldset > legend {
font-weight: bold;
padding: 0 5px 0 5px;
@@ -6606,7 +7420,6 @@ fieldset > legend {
ol.LC_primary_menu {
margin: 0;
padding: 0;
- background-color: $pgbg_or_bgcolor;
}
ol#LC_PathBreadcrumbs {
@@ -6618,23 +7431,48 @@ ol.LC_primary_menu li {
vertical-align: middle;
text-align: left;
list-style: none;
+ position: relative;
float: left;
+ z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
+ line-height: 1.5em;
}
-ol.LC_primary_menu li a {
+ol.LC_primary_menu li a,
+ol.LC_primary_menu li p {
display: block;
margin: 0;
padding: 0 5px 0 10px;
text-decoration: none;
}
-ol.LC_primary_menu li ul {
+ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
+ display: inline-block;
+ width: 95%;
+ text-align: left;
+}
+
+ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
+ display: inline-block;
+ width: 5%;
+ float: right;
+ text-align: right;
+ font-size: 70%;
+}
+
+ol.LC_primary_menu ul {
display: none;
- width: 10em;
+ width: 15em;
background-color: $data_table_light;
+ position: absolute;
+ top: 100%;
}
-ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
+ol.LC_primary_menu ul ul {
+ left: 100%;
+ top: 0;
+}
+
+ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
display: block;
position: absolute;
margin: 0;
@@ -6643,15 +7481,21 @@ ol.LC_primary_menu li:hover ul, ol.LC_pr
}
ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
+/* First Submenu -> size should be smaller than the menu title of the whole menu */
font-size: 90%;
vertical-align: top;
float: none;
border-left: 1px solid black;
border-right: 1px solid black;
+/* A dark bottom border to visualize different menu options;
+overwritten in the create_submenu routine for the last border-bottom of the menu */
+ border-bottom: 1px solid $data_table_dark;
}
-ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
- background-color:$data_table_light;
+ol.LC_primary_menu li li p:hover {
+ color:$button_hover;
+ text-decoration:none;
+ background-color:$data_table_dark;
}
ol.LC_primary_menu li li a:hover {
@@ -6659,6 +7503,11 @@ ol.LC_primary_menu li li a:hover {
background-color:$data_table_dark;
}
+/* Font-size equal to the size of the predecessors*/
+ol.LC_primary_menu li:hover li li {
+ font-size: 100%;
+}
+
ol.LC_primary_menu li img {
vertical-align: bottom;
height: 1.1em;
@@ -7201,6 +8050,16 @@ ul.LC_funclist li {
}
/*
+ styles used for response display
+*/
+div.LC_radiofoil, div.LC_rankfoil {
+ margin: .5em 0em .5em 0em;
+}
+table.LC_itemgroup {
+ margin-top: 1em;
+}
+
+/*
styles used by TTH when "Default set of options to pass to tth/m
when converting TeX" in course settings has been set
@@ -7221,6 +8080,120 @@ span.roman {font-family: serif; font-sty
span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
+/*
+ sections with roles, for content only
+*/
+section[class^="role-"] {
+ padding-left: 10px;
+ padding-right: 5px;
+ margin-top: 8px;
+ margin-bottom: 8px;
+ border: 1px solid #2A4;
+ border-radius: 5px;
+ box-shadow: 0px 1px 1px #BBB;
+}
+section[class^="role-"]>h1 {
+ position: relative;
+ margin: 0px;
+ padding-top: 10px;
+ padding-left: 40px;
+}
+section[class^="role-"]>h1:before {
+ position: absolute;
+ left: -5px;
+ top: 5px;
+}
+section.role-activity>h1:before {
+ content:url('/adm/daxe/images/section_icons/activity.png');
+}
+section.role-advice>h1:before {
+ content:url('/adm/daxe/images/section_icons/advice.png');
+}
+section.role-bibliography>h1:before {
+ content:url('/adm/daxe/images/section_icons/bibliography.png');
+}
+section.role-citation>h1:before {
+ content:url('/adm/daxe/images/section_icons/citation.png');
+}
+section.role-conclusion>h1:before {
+ content:url('/adm/daxe/images/section_icons/conclusion.png');
+}
+section.role-definition>h1:before {
+ content:url('/adm/daxe/images/section_icons/definition.png');
+}
+section.role-demonstration>h1:before {
+ content:url('/adm/daxe/images/section_icons/demonstration.png');
+}
+section.role-example>h1:before {
+ content:url('/adm/daxe/images/section_icons/example.png');
+}
+section.role-explanation>h1:before {
+ content:url('/adm/daxe/images/section_icons/explanation.png');
+}
+section.role-introduction>h1:before {
+ content:url('/adm/daxe/images/section_icons/introduction.png');
+}
+section.role-method>h1:before {
+ content:url('/adm/daxe/images/section_icons/method.png');
+}
+section.role-more_information>h1:before {
+ content:url('/adm/daxe/images/section_icons/more_information.png');
+}
+section.role-objectives>h1:before {
+ content:url('/adm/daxe/images/section_icons/objectives.png');
+}
+section.role-prerequisites>h1:before {
+ content:url('/adm/daxe/images/section_icons/prerequisites.png');
+}
+section.role-remark>h1:before {
+ content:url('/adm/daxe/images/section_icons/remark.png');
+}
+section.role-reminder>h1:before {
+ content:url('/adm/daxe/images/section_icons/reminder.png');
+}
+section.role-summary>h1:before {
+ content:url('/adm/daxe/images/section_icons/summary.png');
+}
+section.role-syntax>h1:before {
+ content:url('/adm/daxe/images/section_icons/syntax.png');
+}
+section.role-warning>h1:before {
+ content:url('/adm/daxe/images/section_icons/warning.png');
+}
+
+#LC_minitab_header {
+ float:left;
+ width:100%;
+ background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
+ font-size:93%;
+ line-height:normal;
+ margin: 0.5em 0 0.5em 0;
+}
+#LC_minitab_header ul {
+ margin:0;
+ padding:10px 10px 0;
+ list-style:none;
+}
+#LC_minitab_header li {
+ float:left;
+ background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
+ margin:0;
+ padding:0 0 0 9px;
+}
+#LC_minitab_header a {
+ display:block;
+ background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
+ padding:5px 15px 4px 6px;
+}
+#LC_minitab_header #LC_current_minitab {
+ background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
+}
+#LC_minitab_header #LC_current_minitab a {
+ background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
+ padding-bottom:5px;
+}
+
+
END
}
@@ -7257,6 +8230,7 @@ sub headtag {
my $function = $args->{'function'} || &get_users_function();
my $domain = $args->{'domain'} || &determinedomain();
my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
+ my $httphost = $args->{'use_absolute'};
my $url = join(':',$env{'user.name'},$env{'user.domain'},
$Apache::lonnet::perlvar{'lonVersion'},
#time(),
@@ -7267,9 +8241,12 @@ sub headtag {
my $result =
''.
- &font_settings();
+ &font_settings($args);
- my $inhibitprint = &print_suppression();
+ my $inhibitprint;
+ if ($args->{'print_suppress'}) {
+ $inhibitprint = &print_suppression();
+ }
if (!$args->{'frameset'}) {
$result .= &Apache::lonhtmlcommon::htmlareaheaders();
@@ -7280,7 +8257,7 @@ sub headtag {
if (!$args->{'no_nav_bar'}
&& !$args->{'only_body'}
&& !$args->{'frameset'}) {
- $result .= &help_menu_js();
+ $result .= &help_menu_js($httphost);
$result.=&modal_window();
$result.=&togglebox_script();
$result.=&wishlist_window();
@@ -7309,20 +8286,107 @@ sub headtag {
ADDMETA
+ } else {
+ unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
+ my $requrl = $env{'request.uri'};
+ if ($requrl eq '') {
+ $requrl = $ENV{'REQUEST_URI'};
+ $requrl =~ s/\?.+$//;
+ }
+ unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
+ (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
+ ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
+ my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
+ unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
+ if (ref($domdefs{'offloadnow'}) eq 'HASH') {
+ my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
+ if ($domdefs{'offloadnow'}{$lonhost}) {
+ my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
+ if (($newserver) && ($newserver ne $lonhost)) {
+ my $numsec = 5;
+ my $timeout = $numsec * 1000;
+ my ($newurl,$locknum,%locks,$msg);
+ if ($env{'request.role.adv'}) {
+ ($locknum,%locks) = &Apache::lonnet::get_locks();
+ }
+ my $disable_submit = 0;
+ if ($requrl =~ /$LONCAPA::assess_re/) {
+ $disable_submit = 1;
+ }
+ if ($locknum) {
+ my @lockinfo = sort(values(%locks));
+ $msg = &mt('Once the following tasks are complete: ')."\\n".
+ join(", ",sort(values(%locks)))."\\n".
+ &mt('your session will be transferred to a different server, after you click "Roles".');
+ } else {
+ if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
+ $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
+ }
+ $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
+ $newurl = '/adm/switchserver?otherserver='.$newserver;
+ if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
+ $newurl .= '&role='.$env{'request.role'};
+ }
+ if ($env{'request.symb'}) {
+ $newurl .= '&symb='.$env{'request.symb'};
+ } else {
+ $newurl .= '&origurl='.$requrl;
+ }
+ }
+ &js_escape(\$msg);
+ $result.=<
+
+OFFLOAD
+ }
+ }
+ }
+ }
+ }
+ }
}
if (!defined($title)) {
$title = 'The LearningOnline Network with CAPA';
}
if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
$result .= ' LON-CAPA '.$title.' '
- .' '
+ .' {'frameset'}) {
+ $result .= ' /';
+ }
+ $result .= '>'
.$inhibitprint
.$head_extra;
- if ($env{'browser.mobile'}) {
+ my $clientmobile;
+ if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
+ (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
+ } else {
+ $clientmobile = $env{'browser.mobile'};
+ }
+ if ($clientmobile) {
$result .= '
';
}
+ $result .= ' '."\n";
return $result.'';
}
@@ -7332,15 +8396,21 @@ ADDMETA
Returns neccessary to set the proper encoding
-Inputs: none
+Inputs: optional reference to HASH -- $args passed to &headtag()
=cut
sub font_settings {
+ my ($args) = @_;
my $headerstring='';
- if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
- $headerstring.=
- ' ';
+ if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
+ ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
+ $headerstring.=
+ ' {'frameset'}) {
+ $headerstring.= ' /';
+ }
+ $headerstring .= '>'."\n";
}
return $headerstring;
}
@@ -7385,7 +8455,7 @@ sub print_suppression {
}
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- my $blocked = &blocking_status('printout',$cnum,$cdom);
+ my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
if ($blocked) {
my $checkrole = "cm./$cdom/$cnum";
if ($env{'request.course.sec'} ne '') {
@@ -7432,6 +8502,7 @@ Inputs: none
=cut
sub xml_begin {
+ my ($is_frameset) = @_;
my $output='';
if ($env{'browser.mathml'}) {
@@ -7443,9 +8514,12 @@ sub xml_begin {
.''
.'';
+ } elsif ($is_frameset) {
+ $output=''."\n".
+ ''."\n";
} else {
- $output=''
- .'';
+ $output=''."\n".
+ ''."\n";
}
return $output;
}
@@ -7490,13 +8564,16 @@ $args - additional optional args support
head -> skip the generation
body -> skip all generation
no_auto_mt_title -> prevent &mt()ing the title arg
- inherit_jsmath -> when creating popup window in a page,
- should it have jsmath forced on by the
- current page
bread_crumbs -> Array containing breadcrumbs
bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
+ bread_crumbs_nomenu -> if true will pass false as the value of $menulink
+ to lonhtmlcommon::breadcrumbs
group -> includes the current group, if page is for a
- specific group
+ specific group
+ use_absolute -> for request for external resource or syllabus, this
+ will contain https:// if server uses
+ https (as per hosts.tab), but request is for http
+ hostname -> hostname, originally from $r->hostname(), (optional).
=back
@@ -7512,7 +8589,7 @@ sub start_page {
my ($result,@advtools);
if (! exists($args->{'skip_phases'}{'head'}) ) {
- $result .= &xml_begin() . &headtag($title, $head_extra, $args);
+ $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
}
if (! exists($args->{'skip_phases'}{'body'}) ) {
@@ -7560,12 +8637,21 @@ sub start_page {
if (@advtools > 0) {
&Apache::lonmenu::advtools_crumbs(@advtools);
}
-
+ my $menulink;
+ # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
+ if ((exists($args->{'bread_crumbs_nomenu'})) ||
+ ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
+ ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
+ (!$env{'request.role.adv'}))) {
+ $menulink = 0;
+ } else {
+ undef($menulink);
+ }
#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
if(exists($args->{'bread_crumbs_component'})){
- $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
- }else{
- $result .= &Apache::lonhtmlcommon::breadcrumbs();
+ $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
+ } else {
+ $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
}
}
return $result;
@@ -7613,9 +8699,13 @@ function set_wishlistlink(title, path) {
title = document.title;
title = title.replace(/^LON-CAPA /,'');
}
+ title = encodeURIComponent(title);
+ title = title.replace("'","\\\'");
if (!path) {
path = location.pathname;
}
+ path = encodeURIComponent(path);
+ path = path.replace("'","\\\'");
Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
'wishlistNewLink','width=560,height=350,scrollbars=0');
}
@@ -7656,14 +8746,15 @@ var modalWindow = {
$(".LCmodal-overlay").click(function(){modalWindow.close();});
}
};
- var openMyModal = function(source,width,height,scrolling)
+ var openMyModal = function(source,width,height,scrolling,transparency,style)
{
+ source = source.replace(/'/g,"'");
modalWindow.windowId = "myModal";
modalWindow.width = width;
modalWindow.height = height;
- modalWindow.content = " ';
}
+sub nicescroll_javascript {
+ my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
+ my %options;
+ if (ref($cursor) eq 'HASH') {
+ %options = %{$cursor};
+ }
+ unless ($options{'railalign'} =~ /^left|right$/) {
+ $options{'railalign'} = 'left';
+ }
+ unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
+ my $function = &get_users_function();
+ $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
+ unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
+ $options{'cursorcolor'} = '#00F';
+ }
+ }
+ if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
+ unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
+ $options{'cursoropacity'}='1.0';
+ }
+ } else {
+ $options{'cursoropacity'}='1.0';
+ }
+ if ($options{'cursorfixedheight'} eq 'none') {
+ delete($options{'cursorfixedheight'});
+ } else {
+ unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
+ }
+ unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
+ delete($options{'railoffset'});
+ }
+ my @niceoptions;
+ while (my($key,$value) = each(%options)) {
+ if ($value =~ /^\{.+\}$/) {
+ push(@niceoptions,$key.':'.$value);
+ } else {
+ push(@niceoptions,$key.':"'.$value.'"');
+ }
+ }
+ my $nicescroll_js = '
+$(document).ready(
+ function() {
+ $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
+ }
+);
+';
+ if ($framecheck) {
+ $nicescroll_js .= '
+function expand_div(caller) {
+ if (top === self) {
+ document.getElementById("'.$id.'").style.width = "auto";
+ document.getElementById("'.$id.'").style.height = "auto";
+ } else {
+ try {
+ if (parent.frames) {
+ if (parent.frames.length > 1) {
+ var framesrc = parent.frames[1].location.href;
+ var currsrc = framesrc.replace(/\#.*$/,"");
+ if ((caller == "search") || (currsrc == "'.$location.'")) {
+ document.getElementById("'.$id.'").style.width = "auto";
+ document.getElementById("'.$id.'").style.height = "auto";
+ }
+ }
+ }
+ } catch (e) {
+ return;
+ }
+ }
+ return;
+}
+';
+ }
+ if ($needjsready) {
+ $nicescroll_js = '
+\n";
+ } else {
+ $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
+ }
+ return $nicescroll_js;
+}
+
sub simple_error_page {
- my ($r,$title,$msg) = @_;
+ my ($r,$title,$msg,$args) = @_;
+ if (ref($args) eq 'HASH') {
+ if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
+ } else {
+ $msg = &mt($msg);
+ }
+
my $page =
&Apache::loncommon::start_page($title).
- ''.&mt($msg).'
'.
+ ''.$msg.'
'.
&Apache::loncommon::end_page();
if (ref($r)) {
$r->print($page);
@@ -8225,7 +9356,7 @@ role status: active, previous or future.
sub check_user_status {
my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
- my @uroles = keys %userinfo;
+ my @uroles = keys(%userinfo);
my $srchstr;
my $active_chk = 'none';
my $now = time;
@@ -8636,11 +9767,11 @@ Incoming parameters:
2. user's domain
3. quota name - portfolio, author, or course
(if no quota name provided, defaults to portfolio).
-4. crstype - official, unofficial or community, if quota name is
- course
+4. crstype - official, unofficial, textbook, placement or community,
+ if quota name is course
Returns:
-1. Disk quota (in Mb) assigned to student.
+1. Disk quota (in MB) assigned to student.
2. (Optional) Type of setting: custom or default
(individually assigned or default for user's
institutional status).
@@ -8710,7 +9841,9 @@ sub get_user_quota {
if ($quota eq '' || wantarray) {
if ($quotaname eq 'course') {
my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
- if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'community')) {
+ if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
+ ($crstype eq 'community') || ($crstype eq 'textbook') ||
+ ($crstype eq 'placement')) {
$defquota = $domdefs{$crstype.'quota'};
}
if ($defquota eq '') {
@@ -8744,6 +9877,7 @@ Retrieves default quota assigned for sto
given an (optional) user's institutional status.
Incoming parameters:
+
1. domain
2. (Optional) institutional status(es). This is a : separated list of
status types (e.g., faculty, staff, student etc.)
@@ -8754,21 +9888,20 @@ Incoming parameters:
(if no quota name provided, defaults to portfolio).
Returns:
-1. Default disk quota (in Mb) for user portfolios in the domain.
+
+1. Default disk quota (in MB) for user portfolios in the domain.
2. (Optional) institutional type which determined the value of the
default quota.
If a value has been stored in the domain's configuration db,
it will return that, otherwise it returns 20 (for backwards
compatibility with domains which have not set up a configuration
-db file; the original statically defined portfolio quota was 20 Mb).
+db file; the original statically defined portfolio quota was 20 MB).
If the user's status includes multiple types (e.g., staff and student),
the largest default quota which applies to the user determines the
default quota returned.
-=back
-
=cut
###############################################
@@ -8846,28 +9979,31 @@ sub default_quota {
Returns warning message if upload of file to authoring space, or copying
of existing file within authoring space will cause quota for the authoring
-space to be exceeded,
+space to be exceeded.
Same, if upload of a file directly to a course/community via Course Editor
will cause quota for uploaded content for the course to be exceeded.
-Inputs: 6
+Inputs: 7
1. username or coursenum
2. domain
3. context ('author' or 'course')
4. filename of file for which action is being requested
5. filesize (kB) of file
6. action being taken: copy or upload.
+7. quotatype (in course context -- official, unofficial, textbook, placement or community).
Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
- otherwise return null.
+ otherwise return null.
+
+=back
=cut
sub excess_filesize_warning {
- my ($uname,$udom,$context,$filename,$filesize,$action) = @_;
+ my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
my $current_disk_usage = 0;
- my $disk_quota = &get_user_quota($uname,$udom,$context); #expressed in MB
+ my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
if ($context eq 'author') {
my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
$current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
@@ -8878,10 +10014,10 @@ sub excess_filesize_warning {
}
$disk_quota = int($disk_quota * 1000);
if (($current_disk_usage + $filesize) > $disk_quota) {
- return ''.
+ return ''.
&mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
- ''.$filename.' ',$filesize).'
'.
- ' '.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
+ ''.$filename.' ',$filesize).'
'.
+ ''.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
$disk_quota,$current_disk_usage).
'
';
}
@@ -8931,8 +10067,24 @@ sub get_secgrprole_info {
}
sub user_picker {
- my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
+ my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
my $currdom = $dom;
+ my @alldoms = &Apache::lonnet::all_domains();
+ if (@alldoms == 1) {
+ my %domsrch = &Apache::lonnet::get_dom('configuration',
+ ['directorysrch'],$alldoms[0]);
+ my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
+ my $showdom = $domdesc;
+ if ($showdom eq '') {
+ $showdom = $dom;
+ }
+ if (ref($domsrch{'directorysrch'}) eq 'HASH') {
+ if ((!$domsrch{'directorysrch'}{'available'}) &&
+ ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
+ return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
+ }
+ }
+ }
my %curr_selected = (
srchin => 'dom',
srchby => 'lastname',
@@ -8953,7 +10105,7 @@ sub user_picker {
}
$srchterm = $srch->{'srchterm'};
}
- my %lt=&Apache::lonlocal::texthash(
+ my %html_lt=&Apache::lonlocal::texthash(
'usr' => 'Search criteria',
'doma' => 'Domain/institution to search',
'uname' => 'username',
@@ -8966,6 +10118,8 @@ sub user_picker {
'exact' => 'is',
'contains' => 'contains',
'begins' => 'begins with',
+ );
+ my %js_lt=&Apache::lonlocal::texthash(
'youm' => "You must include some text to search for.",
'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
@@ -8975,7 +10129,25 @@ sub user_picker {
'whse' => "When searching by last,first you must include at least one character in the first name.",
'thfo' => "The following need to be corrected before the search can be run:",
);
- my $domform = &select_dom_form($currdom,'srchdomain',1,1);
+ &html_escape(\%html_lt);
+ &js_escape(\%js_lt);
+ my $domform;
+ my $allow_blank = 1;
+ if ($fixeddom) {
+ $allow_blank = 0;
+ $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
+ } else {
+ my $defdom = $env{'request.role.domain'};
+ my ($trustedref,$untrustedref);
+ if (($context eq 'requestcrs') || ($context eq 'course')) {
+ ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('enroll',$defdom);
+ } elsif ($context eq 'author') {
+ ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
+ } elsif ($context eq 'domain') {
+ ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('domroles',$defdom);
+ }
+ $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trustedref,$untrustedref);
+ }
my $srchinsel = ' ';
my @srchins = ('crs','dom','alc','instd');
@@ -8987,12 +10159,13 @@ sub user_picker {
next if ($option eq 'alc');
next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
next if ($option eq 'crs' && !$env{'request.course.id'});
+ next if (($option eq 'instd') && ($noinstd));
if ($curr_selected{'srchin'} eq $option) {
$srchinsel .= '
- '.$lt{$option}.' ';
+ '.$html_lt{$option}.' ';
} else {
$srchinsel .= '
- '.$lt{$option}.' ';
+ '.$html_lt{$option}.' ';
}
}
$srchinsel .= "\n \n";
@@ -9001,10 +10174,10 @@ sub user_picker {
foreach my $option ('lastname','lastfirst','uname') {
if ($curr_selected{'srchby'} eq $option) {
$srchbysel .= '
- '.$lt{$option}.' ';
+ '.$html_lt{$option}.' ';
} else {
$srchbysel .= '
- '.$lt{$option}.' ';
+ '.$html_lt{$option}.' ';
}
}
$srchbysel .= "\n \n";
@@ -9013,10 +10186,10 @@ sub user_picker {
foreach my $option ('begins','contains','exact') {
if ($curr_selected{'srchtype'} eq $option) {
$srchtypesel .= '
- '.$lt{$option}.' ';
+ '.$html_lt{$option}.' ';
} else {
$srchtypesel .= '
- '.$lt{$option}.' ';
+ '.$html_lt{$option}.' ';
}
}
$srchtypesel .= "\n \n";
@@ -9101,46 +10274,46 @@ function validateEntry(callingForm) {
if (srchterm == "") {
checkok = 0;
- msg += "$lt{'youm'}\\n";
+ msg += "$js_lt{'youm'}\\n";
}
if (srchtype== 'begins') {
if (srchterm.length < 2) {
checkok = 0;
- msg += "$lt{'thte'}\\n";
+ msg += "$js_lt{'thte'}\\n";
}
}
if (srchtype== 'contains') {
if (srchterm.length < 3) {
checkok = 0;
- msg += "$lt{'thet'}\\n";
+ msg += "$js_lt{'thet'}\\n";
}
}
if (srchin == 'instd') {
if (srchdomain == '') {
checkok = 0;
- msg += "$lt{'yomc'}\\n";
+ msg += "$js_lt{'yomc'}\\n";
}
}
if (srchin == 'dom') {
if (srchdomain == '') {
checkok = 0;
- msg += "$lt{'ymcd'}\\n";
+ msg += "$js_lt{'ymcd'}\\n";
}
}
if (srchby == 'lastfirst') {
if (srchterm.indexOf(",") == -1) {
checkok = 0;
- msg += "$lt{'whus'}\\n";
+ msg += "$js_lt{'whus'}\\n";
}
if (srchterm.indexOf(",") == srchterm.length -1) {
checkok = 0;
- msg += "$lt{'whse'}\\n";
+ msg += "$js_lt{'whse'}\\n";
}
}
if (checkok == 0) {
- alert("$lt{'thfo'}\\n"+msg);
+ alert("$js_lt{'thfo'}\\n"+msg);
return;
}
if (checkok == 1) {
@@ -9158,10 +10331,10 @@ $new_user_create
END_BLOCK
$output .= &Apache::lonhtmlcommon::start_pick_box().
- &Apache::lonhtmlcommon::row_title($lt{'doma'}).
+ &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
$domform.
&Apache::lonhtmlcommon::row_closure().
- &Apache::lonhtmlcommon::row_title($lt{'usr'}).
+ &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
$srchbysel.
$srchtypesel.
' '.
@@ -9169,61 +10342,165 @@ END_BLOCK
&Apache::lonhtmlcommon::row_closure(1).
&Apache::lonhtmlcommon::end_pick_box().
' ';
- return $output;
+ return ($output,1);
}
sub user_rule_check {
my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
- my $response;
+ my ($response,%inst_response);
if (ref($usershash) eq 'HASH') {
- foreach my $user (keys(%{$usershash})) {
- my ($uname,$udom) = split(/:/,$user);
- next if ($udom eq '' || $uname eq '');
- my ($id,$newuser);
- if (ref($usershash->{$user}) eq 'HASH') {
- $newuser = $usershash->{$user}->{'newuser'};
- $id = $usershash->{$user}->{'id'};
- }
- my $inst_response;
+ if (keys(%{$usershash}) > 1) {
+ my (%by_username,%by_id,%userdoms);
+ my $checkid;
if (ref($checks) eq 'HASH') {
- if (defined($checks->{'username'})) {
- ($inst_response,%{$inst_results->{$user}}) =
- &Apache::lonnet::get_instuser($udom,$uname);
- } elsif (defined($checks->{'id'})) {
- ($inst_response,%{$inst_results->{$user}}) =
- &Apache::lonnet::get_instuser($udom,undef,$id);
+ if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
+ $checkid = 1;
+ }
+ }
+ foreach my $user (keys(%{$usershash})) {
+ my ($uname,$udom) = split(/:/,$user);
+ if ($checkid) {
+ if (ref($usershash->{$user}) eq 'HASH') {
+ if ($usershash->{$user}->{'id'} ne '') {
+ $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
+ $userdoms{$udom} = 1;
+ if (ref($inst_results) eq 'HASH') {
+ $inst_results->{$uname.':'.$udom} = {};
+ }
+ }
+ }
+ } else {
+ $by_username{$udom}{$uname} = 1;
+ $userdoms{$udom} = 1;
+ if (ref($inst_results) eq 'HASH') {
+ $inst_results->{$uname.':'.$udom} = {};
+ }
+ }
+ }
+ foreach my $udom (keys(%userdoms)) {
+ if (!$got_rules->{$udom}) {
+ my %domconfig = &Apache::lonnet::get_dom('configuration',
+ ['usercreation'],$udom);
+ if (ref($domconfig{'usercreation'}) eq 'HASH') {
+ foreach my $item ('username','id') {
+ if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
+ $$curr_rules{$udom}{$item} =
+ $domconfig{'usercreation'}{$item.'_rule'};
+ }
+ }
+ }
+ $got_rules->{$udom} = 1;
+ }
+ }
+ if ($checkid) {
+ foreach my $udom (keys(%by_id)) {
+ my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
+ if ($outcome eq 'ok') {
+ foreach my $id (keys(%{$by_id{$udom}})) {
+ my $uname = $by_id{$udom}{$id};
+ $inst_response{$uname.':'.$udom} = $outcome;
+ }
+ if (ref($results) eq 'HASH') {
+ foreach my $uname (keys(%{$results})) {
+ if (exists($inst_response{$uname.':'.$udom})) {
+ $inst_response{$uname.':'.$udom} = $outcome;
+ $inst_results->{$uname.':'.$udom} = $results->{$uname};
+ }
+ }
+ }
+ }
}
} else {
- ($inst_response,%{$inst_results->{$user}}) =
- &Apache::lonnet::get_instuser($udom,$uname);
- return;
+ foreach my $udom (keys(%by_username)) {
+ my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
+ if ($outcome eq 'ok') {
+ foreach my $uname (keys(%{$by_username{$udom}})) {
+ $inst_response{$uname.':'.$udom} = $outcome;
+ }
+ if (ref($results) eq 'HASH') {
+ foreach my $uname (keys(%{$results})) {
+ $inst_results->{$uname.':'.$udom} = $results->{$uname};
+ }
+ }
+ }
+ }
}
- if (!$got_rules->{$udom}) {
- my %domconfig = &Apache::lonnet::get_dom('configuration',
- ['usercreation'],$udom);
- if (ref($domconfig{'usercreation'}) eq 'HASH') {
- foreach my $item ('username','id') {
- if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
- $$curr_rules{$udom}{$item} =
- $domconfig{'usercreation'}{$item.'_rule'};
+ } elsif (keys(%{$usershash}) == 1) {
+ my $user = (keys(%{$usershash}))[0];
+ my ($uname,$udom) = split(/:/,$user);
+ if (($udom ne '') && ($uname ne '')) {
+ if (ref($usershash->{$user}) eq 'HASH') {
+ if (ref($checks) eq 'HASH') {
+ if (defined($checks->{'username'})) {
+ ($inst_response{$user},%{$inst_results->{$user}}) =
+ &Apache::lonnet::get_instuser($udom,$uname);
+ } elsif (defined($checks->{'id'})) {
+ if ($usershash->{$user}->{'id'} ne '') {
+ ($inst_response{$user},%{$inst_results->{$user}}) =
+ &Apache::lonnet::get_instuser($udom,undef,
+ $usershash->{$user}->{'id'});
+ } else {
+ ($inst_response{$user},%{$inst_results->{$user}}) =
+ &Apache::lonnet::get_instuser($udom,$uname);
+ }
}
+ } else {
+ ($inst_response{$user},%{$inst_results->{$user}}) =
+ &Apache::lonnet::get_instuser($udom,$uname);
+ return;
+ }
+ if (!$got_rules->{$udom}) {
+ my %domconfig = &Apache::lonnet::get_dom('configuration',
+ ['usercreation'],$udom);
+ if (ref($domconfig{'usercreation'}) eq 'HASH') {
+ foreach my $item ('username','id') {
+ if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
+ $$curr_rules{$udom}{$item} =
+ $domconfig{'usercreation'}{$item.'_rule'};
+ }
+ }
+ }
+ $got_rules->{$udom} = 1;
}
}
- $got_rules->{$udom} = 1;
+ } else {
+ return;
+ }
+ } else {
+ return;
+ }
+ foreach my $user (keys(%{$usershash})) {
+ my ($uname,$udom) = split(/:/,$user);
+ next if (($udom eq '') || ($uname eq ''));
+ my $id;
+ if (ref($inst_results) eq 'HASH') {
+ if (ref($inst_results->{$user}) eq 'HASH') {
+ $id = $inst_results->{$user}->{'id'};
+ }
+ }
+ if ($id eq '') {
+ if (ref($usershash->{$user})) {
+ $id = $usershash->{$user}->{'id'};
+ }
}
foreach my $item (keys(%{$checks})) {
if (ref($$curr_rules{$udom}) eq 'HASH') {
if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
if (@{$$curr_rules{$udom}{$item}} > 0) {
- my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
+ my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
+ $$curr_rules{$udom}{$item});
foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
if ($rule_check{$rule}) {
$$rulematch{$user}{$item} = $rule;
- if ($inst_response eq 'ok') {
+ if ($inst_response{$user} eq 'ok') {
if (ref($inst_results) eq 'HASH') {
if (ref($inst_results->{$user}) eq 'HASH') {
if (keys(%{$inst_results->{$user}}) == 0) {
$$alerts{$item}{$udom}{$uname} = 1;
+ } elsif ($item eq 'id') {
+ if ($inst_results->{$user}->{'id'} eq '') {
+ $$alerts{$item}{$udom}{$uname} = 1;
+ }
}
}
}
@@ -9334,7 +10611,14 @@ sub personal_data_fieldtitles {
sub sorted_inst_types {
my ($dom) = @_;
- my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
+ my ($usertypes,$order);
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+ if (ref($domdefaults{'inststatus'}) eq 'HASH') {
+ $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
+ $order = $domdefaults{'inststatus'}{'inststatusorder'};
+ } else {
+ ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
+ }
my $othertitle = &mt('All users');
if ($env{'request.course.id'}) {
$othertitle = &mt('Any users');
@@ -9373,7 +10657,7 @@ sub get_institutional_codes {
foreach (@currxlists) {
if (m/^([^:]+):(\w*)$/) {
unless (grep/^$1$/,@{$allcourses}) {
- push @{$allcourses},$1;
+ push(@{$allcourses},$1);
$$LC_code{$1} = $2;
}
}
@@ -9386,7 +10670,7 @@ sub get_institutional_codes {
my $sec = $coursecode.$1;
my $lc_sec = $2;
unless (grep/^$sec$/,@{$allcourses}) {
- push @{$allcourses},$sec;
+ push(@{$allcourses},$sec);
$$LC_code{$sec} = $lc_sec;
}
}
@@ -9484,7 +10768,9 @@ reservable_now - ref to hash of student_
Keys in inner hash are:
(a) symb: either blank or symb to which slot use is restricted.
- (b) endreserve: end date of reservation period.
+ (b) endreserve: end date of reservation period.
+ (c) uniqueperiod: start,end dates when slot is to be uniquely
+ selected.
sorted_future - ref to array of student_schedulable slots reservable in
the future, ordered by start date of reservation period.
@@ -9494,7 +10780,9 @@ future_reservable - ref to hash of stude
Keys in inner hash are:
(a) symb: either blank or symb to which slot use is restricted.
- (b) startreserve: start date of reservation period.
+ (b) startreserve: start date of reservation period.
+ (c) uniqueperiod: start,end dates when slot is to be uniquely
+ selected.
=back
@@ -9502,13 +10790,35 @@ future_reservable - ref to hash of stude
sub get_future_slots {
my ($cnum,$cdom,$now,$symb) = @_;
+ my $map;
+ if ($symb) {
+ ($map) = &Apache::lonnet::decode_symb($symb);
+ }
my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
foreach my $slot (keys(%slots)) {
next unless($slots{$slot}->{'type'} eq 'schedulable_student');
if ($symb) {
- next if (($slots{$slot}->{'symb'} ne '') &&
- ($slots{$slot}->{'symb'} ne $symb));
+ if ($slots{$slot}->{'symb'} ne '') {
+ my $canuse;
+ my %oksymbs;
+ my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
+ map { $oksymbs{$_} = 1; } @slotsymbs;
+ if ($oksymbs{$symb}) {
+ $canuse = 1;
+ } else {
+ foreach my $item (@slotsymbs) {
+ if ($item =~ /\.(page|sequence)$/) {
+ (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
+ if (($map ne '') && ($map eq $sloturl)) {
+ $canuse = 1;
+ last;
+ }
+ }
+ }
+ }
+ next unless ($canuse);
+ }
}
if (($slots{$slot}->{'starttime'} > $now) &&
($slots{$slot}->{'endtime'} > $now)) {
@@ -9548,6 +10858,10 @@ sub get_future_slots {
my $startreserve = $slots{$slot}->{'startreserve'};
my $endreserve = $slots{$slot}->{'endreserve'};
my $symb = $slots{$slot}->{'symb'};
+ my $uniqueperiod;
+ if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
+ $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
+ }
if (($startreserve < $now) &&
(!$endreserve || $endreserve > $now)) {
my $lastres = $endreserve;
@@ -9556,13 +10870,15 @@ sub get_future_slots {
}
$reservable_now{$slot} = {
symb => $symb,
- endreserve => $lastres
+ endreserve => $lastres,
+ uniqueperiod => $uniqueperiod,
};
} elsif (($startreserve > $now) &&
(!$endreserve || $endreserve > $startreserve)) {
$future_reservable{$slot} = {
symb => $symb,
- startreserve => $startreserve
+ startreserve => $startreserve,
+ uniqueperiod => $uniqueperiod,
};
}
}
@@ -9720,7 +11036,23 @@ sub get_env_multiple {
return(@values);
}
+# Looks at given dependencies, and returns something depending on the context.
+# For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
+# For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
+# For all other contexts, returns ($output, $counter, $numpathchg).
+# $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
+# $counter: integer with the number of existing dependencies when no HTML output is returned, and the number of missing dependencies when an HTML output is returned.
+# $numpathchg: integer with the number of cleaned up dependency paths.
+# \%existing: hash reference clean path -> 1 only for existing dependencies.
+# \%mapping: hash reference clean path -> original path for all dependencies.
+# @param {string} actionurl - The path to the handler, indicative of the context.
+# @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
+# @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
+# @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
+# @param {hash reference} args - More parameters ! Possible keys: error_on_invalid_names (boolean), ignore_remote_references (boolean), current_path (string), docs_url (string), docs_title (string), context (string)
+# @return {Array} - array depending on the context (not a reference)
sub ask_for_embedded_content {
+ # NOTE: documentation was added afterwards, it could be wrong
my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
%currsubfile,%unused,$rem);
@@ -9732,11 +11064,13 @@ sub ask_for_embedded_content {
my $numexisting = 0;
my $numunused = 0;
my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
- $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
+ $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
my $heading = &mt('Upload embedded files');
my $buttontext = &mt('Upload');
- my ($navmap,$cdom,$cnum);
+ # fills these variables based on the context:
+ # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
+ # $path, $fileloc, $title, $rem, $filename
if ($env{'request.course.id'}) {
if ($actionurl eq '/adm/dependencies') {
$navmap = Apache::lonnavmaps::navmap->new();
@@ -9798,7 +11132,15 @@ sub ask_for_embedded_content {
($path) =
($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
}
- $fileloc = &Apache::lonnet::filelocation('',$toplevel);
+ if ($toplevel=~/^\/*(uploaded|editupload)/) {
+ $fileloc = $toplevel;
+ $fileloc=~ s/^\s*(\S+)\s*$/$1/;
+ my ($udom,$uname,$fname) =
+ ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
+ $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
+ } else {
+ $fileloc = &Apache::lonnet::filelocation('',$toplevel);
+ }
$fileloc =~ s{^/}{};
($filename) = ($fileloc =~ m{.+/([^/]+)$});
$heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
@@ -9813,6 +11155,16 @@ sub ask_for_embedded_content {
$fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
$fileloc =~ s{^/}{};
}
+
+ # parses the dependency paths to get some info
+ # fills $newfiles, $mapping, $subdependencies, $dependencies
+ # $newfiles: hash URL -> 1 for new files or external URLs
+ # (will be completed later)
+ # $mapping:
+ # for external URLs: external URL -> external URL
+ # for relative paths: clean path -> original path
+ # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
+ # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
foreach my $file (keys(%{$allfiles})) {
my $embed_file;
if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
@@ -9820,17 +11172,18 @@ sub ask_for_embedded_content {
} else {
$embed_file = $file;
}
- my $absolutepath;
+ my ($absolutepath,$cleaned_file);
if ($embed_file =~ m{^\w+://}) {
- $newfiles{$embed_file} = 1;
- $mapping{$embed_file} = $embed_file;
+ $cleaned_file = $embed_file;
+ $newfiles{$cleaned_file} = 1;
+ $mapping{$cleaned_file} = $embed_file;
} else {
+ $cleaned_file = &clean_path($embed_file);
if ($embed_file =~ m{^/}) {
$absolutepath = $embed_file;
- $embed_file =~ s{^(/+)}{};
}
- if ($embed_file =~ m{/}) {
- my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
+ if ($cleaned_file =~ m{/}) {
+ my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
$path = &check_for_traversal($path,$url,$toplevel);
my $item = $fname;
if ($path ne '') {
@@ -9847,13 +11200,26 @@ sub ask_for_embedded_content {
} else {
$dependencies{$embed_file} = 1;
if ($absolutepath) {
- $mapping{$embed_file} = $absolutepath;
+ $mapping{$cleaned_file} = $absolutepath;
} else {
- $mapping{$embed_file} = $embed_file;
+ $mapping{$cleaned_file} = $embed_file;
}
}
}
}
+
+ # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
+ # and lists
+ # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
+ # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
+ # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
+ # the path had to be cleaned up
+ # $existing: hash clean path -> 1 if the file exists
+ # $numexisting: number of keys in $existing
+ # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
+ # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
+ # dependency subdirectories that are
+ # not listed as dependencies, with some exceptions using $rem
my $dirptr = 16384;
foreach my $path (keys(%subdependencies)) {
$currsubfile{$path} = {};
@@ -9929,6 +11295,9 @@ sub ask_for_embedded_content {
}
}
}
+
+ # fills $currfile, hash file name -> 1 or [$size,$mtime]
+ # for files in $url or $fileloc (target directory) in some contexts
my %currfile;
if (($actionurl eq '/adm/portfolio') ||
($actionurl eq '/adm/coursegrp_portfolio')) {
@@ -9967,6 +11336,8 @@ sub ask_for_embedded_content {
}
}
}
+ # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
+ # are not in subdirectories, using $currfile
foreach my $file (keys(%dependencies)) {
if (exists($currfile{$file})) {
unless ($mapping{$file} eq $file) {
@@ -9995,6 +11366,8 @@ sub ask_for_embedded_content {
$unused{$file} = 1;
}
}
+
+ # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
($args->{'context'} eq 'paste')) {
$counter = scalar(keys(%existing));
@@ -10006,6 +11379,12 @@ sub ask_for_embedded_content {
$numpathchg = scalar(keys(%pathchanges));
return ($output,$counter,$numpathchg,\%existing,\%mapping);
}
+
+ # returns HTML otherwise, with dependency results and to ask for more uploads
+
+ # $upload_output: missing dependencies (with upload form)
+ # $modify_output: uploaded dependencies (in use)
+ # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
if ($actionurl eq '/adm/dependencies') {
next if ($embed_file =~ m{^\w+://});
@@ -10223,6 +11602,46 @@ sub ask_for_embedded_content {
return ($output,$counter,$numpathchg);
}
+=pod
+
+=item * clean_path($name)
+
+Performs clean-up of directories, subdirectories and filename in an
+embedded object, referenced in an HTML file which is being uploaded
+to a course or portfolio, where
+"Upload embedded images/multimedia files if HTML file" checkbox was
+checked.
+
+Clean-up is similar to replacements in lonnet::clean_filename()
+except each / between sub-directory and next level is preserved.
+
+=cut
+
+sub clean_path {
+ my ($embed_file) = @_;
+ $embed_file =~s{^/+}{};
+ my @contents;
+ if ($embed_file =~ m{/}) {
+ @contents = split(/\//,$embed_file);
+ } else {
+ @contents = ($embed_file);
+ }
+ my $lastidx = scalar(@contents)-1;
+ for (my $i=0; $i<=$lastidx; $i++) {
+ $contents[$i]=~s{\\}{/}g;
+ $contents[$i]=~s/\s+/\_/g;
+ $contents[$i]=~s{[^/\w\.\-]}{}g;
+ if ($i == $lastidx) {
+ $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
+ }
+ }
+ if ($lastidx > 0) {
+ return join('/',@contents);
+ } else {
+ return $contents[0];
+ }
+}
+
sub embedded_file_element {
my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
@@ -10347,7 +11766,8 @@ sub upload_embedded {
# Check if extension is valid
if (($fname =~ /\.(\w+)$/) &&
(&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
- $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1).' ';
+ $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
+ .' '.&mt('Rename the file with a different extension and re-upload.').' ';
next;
} elsif (($fname =~ /\.(\w+)$/) &&
(!defined(&Apache::loncommon::fileembstyle($1)))) {
@@ -10611,6 +12031,7 @@ sub modify_html_refs {
my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
$count += $numchg;
$allfiles{$newname} = $allfiles{$ref};
+ delete($allfiles{$ref});
}
if ($env{'form.embedded_codebase_'.$i} ne '') {
$codebase = &unescape($env{'form.embedded_codebase_'.$i});
@@ -10786,11 +12207,11 @@ sub check_for_upload {
if ($currsize < $filesize) {
my $extra = $filesize - $currsize;
if (($current_disk_usage + $extra) > $disk_quota) {
- my $msg = ''.
+ my $msg = ''.
&mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
- ''.$fname.' ',$filesize,$currsize).'
'.
- ' '.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
- $disk_quota,$current_disk_usage);
+ ''.$fname.' ',$filesize,$currsize).'
'.
+ ''.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
+ $disk_quota,$current_disk_usage).'
';
return ('will_exceed_quota',$msg);
}
}
@@ -10799,21 +12220,21 @@ sub check_for_upload {
}
}
if (($current_disk_usage + $filesize) > $disk_quota){
- my $msg = ''.
- &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.',''.$fname.' ',$filesize).' '.
- ' '.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
+ my $msg = ''.
+ &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.',''.$fname.' ',$filesize).'
'.
+ ''.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'
';
return ('will_exceed_quota',$msg);
} elsif ($found_file) {
if ($locked_file) {
- my $msg = '';
+ my $msg = '';
$msg .= &mt('Unable to upload [_1]. A locked file by that name was found in [_2].',''.$fname.' ',''.$port_path.$env{'form.currentpath'}.' ');
- $msg .= '
';
+ $msg .= '';
$msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.',''.$fname.' ');
return ('file_locked',$msg);
} else {
- my $msg = '';
+ my $msg = '';
$msg .= &mt(' A file by that name: [_1] was found in [_2].',''.$fname.' ',$port_path.$env{'form.currentpath'});
- $msg .= '
';
+ $msg .= '';
return ('existingfile',$msg);
}
}
@@ -10904,16 +12325,66 @@ sub decompress_form {
}
}
if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
- my @camtasia = ("$topdir/","$topdir/index.html",
+ my @camtasia6 = ("$topdir/","$topdir/index.html",
"$topdir/media/",
"$topdir/media/$topdir.mp4",
"$topdir/media/FirstFrame.png",
"$topdir/media/player.swf",
"$topdir/media/swfobject.js",
"$topdir/media/expressInstall.swf");
- my @diffs = &compare_arrays(\@paths,\@camtasia);
+ my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
+ "$topdir/$topdir.mp4",
+ "$topdir/$topdir\_config.xml",
+ "$topdir/$topdir\_controller.swf",
+ "$topdir/$topdir\_embed.css",
+ "$topdir/$topdir\_First_Frame.png",
+ "$topdir/$topdir\_player.html",
+ "$topdir/$topdir\_Thumbnails.png",
+ "$topdir/playerProductInstall.swf",
+ "$topdir/scripts/",
+ "$topdir/scripts/config_xml.js",
+ "$topdir/scripts/handlebars.js",
+ "$topdir/scripts/jquery-1.7.1.min.js",
+ "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
+ "$topdir/scripts/modernizr.js",
+ "$topdir/scripts/player-min.js",
+ "$topdir/scripts/swfobject.js",
+ "$topdir/skins/",
+ "$topdir/skins/configuration_express.xml",
+ "$topdir/skins/express_show/",
+ "$topdir/skins/express_show/player-min.css",
+ "$topdir/skins/express_show/spritesheet.png");
+ my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
+ "$topdir/$topdir.mp4",
+ "$topdir/$topdir\_config.xml",
+ "$topdir/$topdir\_controller.swf",
+ "$topdir/$topdir\_embed.css",
+ "$topdir/$topdir\_First_Frame.png",
+ "$topdir/$topdir\_player.html",
+ "$topdir/$topdir\_Thumbnails.png",
+ "$topdir/playerProductInstall.swf",
+ "$topdir/scripts/",
+ "$topdir/scripts/config_xml.js",
+ "$topdir/scripts/techsmith-smart-player.min.js",
+ "$topdir/skins/",
+ "$topdir/skins/configuration_express.xml",
+ "$topdir/skins/express_show/",
+ "$topdir/skins/express_show/spritesheet.min.css",
+ "$topdir/skins/express_show/spritesheet.png",
+ "$topdir/skins/express_show/techsmith-smart-player.min.css");
+ my @diffs = &compare_arrays(\@paths,\@camtasia6);
if (@diffs == 0) {
- $is_camtasia = 1;
+ $is_camtasia = 6;
+ } else {
+ @diffs = &compare_arrays(\@paths,\@camtasia8_1);
+ if (@diffs == 0) {
+ $is_camtasia = 8;
+ } else {
+ @diffs = &compare_arrays(\@paths,\@camtasia8_4);
+ if (@diffs == 0) {
+ $is_camtasia = 8;
+ }
+ }
}
}
my $output;
@@ -10925,8 +12396,7 @@ sub decompress_form {
function camtasiaToggle() {
for (var i=0; i '.
''.$lt{'proa'}.''.
- ' '.
+ ' '.
$lt{'yes'}.' '.
' '.
$lt{'no'}.' '.
@@ -11111,7 +12581,7 @@ sub decompress_uploaded_file {
sub process_decompression {
my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
my ($dir,$error,$warning,$output);
- if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
+ if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
$error = &mt('Filename not a supported archive file type.').
' '.&mt('Filename should end with one of: [_1].',
'.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
@@ -11221,6 +12691,7 @@ sub process_decompression {
\%titles,\%children);
}
if ($env{'form.autoextract_camtasia'}) {
+ my $version = $env{'form.autoextract_camtasia'};
my %displayed;
my $total = 1;
$env{'form.archive_directory'} = [];
@@ -11239,12 +12710,15 @@ sub process_decompression {
$env{'form.archive_'.$i} = 'display';
$env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
$displayed{'folder'} = $i;
- } elsif ($item eq "$contents[0]/index.html") {
+ } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
+ (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
$env{'form.archive_'.$i} = 'display';
$env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
$displayed{'web'} = $i;
} else {
- if ($item eq "$contents[0]/media") {
+ if ((($item eq "$contents[0]/media") && ($version == 6)) ||
+ ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
+ ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
push(@{$env{'form.archive_directory'}},$i);
}
$env{'form.archive_'.$i} = 'dependency';
@@ -11971,7 +13445,7 @@ sub cleanup_empty_dirs {
=pod
-=item &get_folder_hierarchy()
+=item * &get_folder_hierarchy()
Provides hierarchy of names of folders/sub-folders containing the current
item,
@@ -12081,6 +13555,9 @@ sub get_turnedin_filepath {
my $title = $res->compTitle();
$title =~ s/\W+/_/g;
if ($title ne '') {
+ if (($pc > 1) && (length($title) > 12)) {
+ $title = substr($title,0,12);
+ }
push(@pathitems,$title);
}
}
@@ -12089,6 +13566,9 @@ sub get_turnedin_filepath {
my $maptitle = $mapres->compTitle();
$maptitle =~ s/\W+/_/g;
if ($maptitle ne '') {
+ if (length($maptitle) > 12) {
+ $maptitle = substr($maptitle,0,12);
+ }
push(@pathitems,$maptitle);
}
unless ($env{'request.state'} eq 'construct') {
@@ -12129,6 +13609,9 @@ sub get_turnedin_filepath {
$restitle = time;
}
}
+ if (length($restitle) > 12) {
+ $restitle = substr($restitle,0,12);
+ }
push(@pathitems,$restitle);
$path .= join('/',@pathitems);
}
@@ -12635,7 +14118,7 @@ sub DrawBarGraph {
@Labels = @$labels;
} else {
for (my $i=0;$i<@{$Values[0]};$i++) {
- push (@Labels,$i+1);
+ push(@Labels,$i+1);
}
}
#
@@ -13066,16 +14549,20 @@ sub restore_settings {
=item * &build_recipient_list()
-Build recipient lists for five types of e-mail:
+Build recipient lists for following types of e-mail:
(a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
-(d) Help requests, (e) Course requests needing approval, generated by
-lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
-loncoursequeueadmin.pm respectively.
+(d) Help requests, (e) Course requests needing approval, (f) loncapa
+module change checking, student/employee ID conflict checks, as
+generated by lonerrorhandler.pm, CHECKRPMS, loncron,
+lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
Inputs:
defmail (scalar - email address of default recipient),
-mailing type (scalar - errormail, packagesmail, or helpdeskmail),
+mailing type (scalar: errormail, packagesmail, helpdeskmail,
+requestsmail, updatesmail, or idconflictsmail).
+
defdom (domain for which to retrieve configuration settings),
+
origmail (scalar - email address of recipient from loncapa.conf,
i.e., predates configuration by DC via domainprefs.pm
@@ -13090,9 +14577,9 @@ Returns: comma separated list of address
sub build_recipient_list {
my ($defmail,$mailing,$defdom,$origmail) = @_;
my @recipients;
- my $otheremails;
+ my ($otheremails,$lastresort,$allbcc,$addtext);
my %domconfig =
- &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
+ &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
if (ref($domconfig{'contacts'}) eq 'HASH') {
if (exists($domconfig{'contacts'}{$mailing})) {
if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
@@ -13104,14 +14591,96 @@ sub build_recipient_list {
push(@recipients,$addr);
}
}
- $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
+ }
+ $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
+ if ($mailing eq 'helpdeskmail') {
+ if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
+ my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
+ my @ok_bccs;
+ foreach my $bcc (@bccs) {
+ $bcc =~ s/^\s+//g;
+ $bcc =~ s/\s+$//g;
+ if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
+ if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
+ push(@ok_bccs,$bcc);
+ }
+ }
+ }
+ if (@ok_bccs > 0) {
+ $allbcc = join(', ',@ok_bccs);
+ }
+ }
+ $addtext = $domconfig{'contacts'}{$mailing}{'include'};
}
}
} elsif ($origmail ne '') {
- push(@recipients,$origmail);
+ $lastresort = $origmail;
}
} elsif ($origmail ne '') {
- push(@recipients,$origmail);
+ $lastresort = $origmail;
+ }
+
+ if (($mailing eq 'helpdesk') && ($lastresort ne '')) {
+ unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
+ my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
+ my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
+ my %what = (
+ perlvar => 1,
+ );
+ my $primary = &Apache::lonnet::domain($defdom,'primary');
+ if ($primary) {
+ my $gotaddr;
+ my ($result,$returnhash) =
+ &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
+ if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
+ if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
+ $lastresort = $returnhash->{'lonSupportEMail'};
+ $gotaddr = 1;
+ }
+ }
+ unless ($gotaddr) {
+ my $uintdom = &Apache::lonnet::internet_dom($primary);
+ my $intdom = &Apache::lonnet::internet_dom($lonhost);
+ unless ($uintdom eq $intdom) {
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
+ if (ref($domconfig{'contacts'}) eq 'HASH') {
+ if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
+ my @contacts = ('adminemail','supportemail');
+ foreach my $item (@contacts) {
+ if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
+ my $addr = $domconfig{'contacts'}{$item};
+ if (!grep(/^\Q$addr\E$/,@recipients)) {
+ push(@recipients,$addr);
+ }
+ }
+ }
+ if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
+ $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
+ }
+ if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
+ my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
+ my @ok_bccs;
+ foreach my $bcc (@bccs) {
+ $bcc =~ s/^\s+//g;
+ $bcc =~ s/\s+$//g;
+ if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
+ if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
+ push(@ok_bccs,$bcc);
+ }
+ }
+ }
+ if (@ok_bccs > 0) {
+ $allbcc = join(', ',@ok_bccs);
+ }
+ }
+ $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
+ }
+ }
+ }
+ }
+ }
+ }
}
if (defined($defmail)) {
if ($defmail ne '') {
@@ -13131,8 +14700,102 @@ sub build_recipient_list {
}
}
}
- my $recipientlist = join(',',@recipients);
- return $recipientlist;
+ if ($mailing eq 'helpdesk') {
+ if ((!@recipients) && ($lastresort ne '')) {
+ push(@recipients,$lastresort);
+ }
+ } elsif ($lastresort ne '') {
+ if (!grep(/^\Q$lastresort\E$/,@recipients)) {
+ push(@recipients,$lastresort);
+ }
+ }
+ my $recipientlist = join(',',@recipients);
+ if (wantarray) {
+ return ($recipientlist,$allbcc,$addtext);
+ } else {
+ return $recipientlist;
+ }
+}
+
+############################################################
+############################################################
+
+=pod
+
+=over 4
+
+=item * &mime_email()
+
+Sends an email with a possible attachment
+
+Inputs:
+
+=over 4
+
+from - Sender's email address
+
+to - Email address of recipient
+
+subject - Subject of email
+
+body - Body of email
+
+cc_string - Carbon copy email address
+
+bcc - Blind carbon copy email address
+
+type - File type of attachment
+
+attachment_path - Path of file to be attached
+
+file_name - Name of file to be attached
+
+attachment_text - The body of an attachment of type "TEXT"
+
+=back
+
+=back
+
+=cut
+
+############################################################
+############################################################
+
+sub mime_email {
+ my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
+ $file_name, $attachment_text) = @_;
+ my $msg = MIME::Lite->new(
+ From => $from,
+ To => $to,
+ Subject => $subject,
+ Type =>'TEXT',
+ Data => $body,
+ );
+ if ($cc_string ne '') {
+ $msg->add("Cc" => $cc_string);
+ }
+ if ($bcc ne '') {
+ $msg->add("Bcc" => $bcc);
+ }
+ $msg->attr("content-type" => "text/plain");
+ $msg->attr("content-type.charset" => "UTF-8");
+ # Attach file if given
+ if ($attachment_path) {
+ unless ($file_name) {
+ if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
+ }
+ my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
+ $msg->attach(Type => $type,
+ Path => $attachment_path,
+ Filename => $file_name
+ );
+ # Otherwise attach text if given
+ } elsif ($attachment_text) {
+ $msg->attach(Type => 'TEXT',
+ Data => $attachment_text);
+ }
+ # Send it
+ $msg->send('sendmail');
}
############################################################
@@ -13242,6 +14905,8 @@ sub extract_categories {
$trailstr = &mt('Official courses (with institutional codes)');
} elsif ($name eq 'communities') {
$trailstr = &mt('Communities');
+ } elsif ($name eq 'placement') {
+ $trailstr = &mt('Placement Tests');
} else {
$trailstr = $name;
}
@@ -13271,7 +14936,7 @@ sub extract_categories {
=pod
-=item *&recurse_categories()
+=item * &recurse_categories()
Recursively used to generate breadcrumb trails for course categories.
@@ -13342,7 +15007,7 @@ sub recurse_categories {
=pod
-=item *&assign_categories_table()
+=item * &assign_categories_table()
Create a datatable for display of hierarchical categories in a domain,
with checkboxes to allow a course to be categorized.
@@ -13356,12 +15021,15 @@ currcat - scalar with an & separated lis
type - scalar contains course type (Course or Community).
+disabled - scalar (optional) contains disabled="disabled" if input elements are
+ to be readonly (e.g., Domain Helpdesk role viewing course settings).
+
Returns: $output (markup to be displayed)
=cut
sub assign_categories_table {
- my ($cathash,$currcat,$type) = @_;
+ my ($cathash,$currcat,$type,$disabled) = @_;
my $output;
if (ref($cathash) eq 'HASH') {
my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
@@ -13380,8 +15048,10 @@ sub assign_categories_table {
next if ($parent eq 'instcode');
if ($type eq 'Community') {
next unless ($parent eq 'communities');
+ } elsif ($type eq 'Placement') {
+ next unless ($parent eq 'placement');
} else {
- next if ($parent eq 'communities');
+ next if (($parent eq 'communities') || ($parent eq 'placement'));
}
my $css_class = $itemcount%2?' class="LC_odd_row"':'';
my $item = &escape($parent).'::0';
@@ -13394,14 +15064,16 @@ sub assign_categories_table {
my $parent_title = $parent;
if ($parent eq 'communities') {
$parent_title = &mt('Communities');
+ } elsif ($parent eq 'placement') {
+ $parent_title = &mt('Placement Tests');
}
$table .= ''.
' '.$parent_title.' '.
+ $item.'"'.$checked.$disabled.' />'.$parent_title.''.
' ';
my $depth = 1;
push(@path,$parent);
- $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
+ $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
pop(@path);
$table .= ' ';
$itemcount ++;
@@ -13419,7 +15091,7 @@ sub assign_categories_table {
=pod
-=item *&assign_category_rows()
+=item * &assign_category_rows()
Create a datatable row for display of nested categories in a domain,
with checkboxes to allow a course to be categorized,called recursively.
@@ -13440,12 +15112,15 @@ path - Array containing all categories b
currcategories - reference to array of current categories assigned to the course
+disabled - scalar (optional) contains disabled="disabled" if input elements are
+ to be readonly (e.g., Domain Helpdesk role viewing course settings).
+
Returns: $output (markup to be displayed).
=cut
sub assign_category_rows {
- my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
+ my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
my ($text,$name,$item,$chgstr);
if (ref($cats) eq 'ARRAY') {
my $maxdepth = scalar(@{$cats});
@@ -13453,7 +15128,7 @@ sub assign_category_rows {
if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
my $numchildren = @{$cats->[$depth]{$parent}};
my $css_class = $itemcount%2?' class="LC_odd_row"':'';
- $text .= '';
+ $text .= '';
for (my $j=0; $j<$numchildren; $j++) {
$name = $cats->[$depth]{$parent}[$j];
$item = &escape($name).':'.&escape($parent).':'.$depth;
@@ -13468,12 +15143,12 @@ sub assign_category_rows {
}
$text .= ''.
' '.$name.' '.
+ $item.'"'.$checked.$disabled.' />'.$name.''.
' '.
'';
if (ref($path) eq 'ARRAY') {
push(@{$path},$name);
- $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
+ $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
pop(@{$path});
}
$text .= ' ';
@@ -13485,6 +15160,12 @@ sub assign_category_rows {
return $text;
}
+=pod
+
+=back
+
+=cut
+
############################################################
############################################################
@@ -13694,42 +15375,100 @@ sub check_clone {
my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
if ($args->{'crstype'} eq 'Community') {
if ($clonedesc{'type'} ne 'Community') {
- $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
+ $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
return ($can_clone, $clonemsg, $cloneid, $clonehome);
}
}
- if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
+ if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
(&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
$can_clone = 1;
} else {
- my %clonehash = &Apache::lonnet::get('environment',['cloners'],
+ my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
$args->{'clonedomain'},$args->{'clonecourse'});
- my @cloners = split(/,/,$clonehash{'cloners'});
- if (grep(/^\*$/,@cloners)) {
- $can_clone = 1;
- } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
- $can_clone = 1;
+ if ($clonehash{'cloners'} eq '') {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
+ if ($domdefs{'canclone'}) {
+ unless ($domdefs{'canclone'} eq 'none') {
+ if ($domdefs{'canclone'} eq 'domain') {
+ if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
+ $can_clone = 1;
+ }
+ } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
+ ($args->{'clonedomain'} eq $args->{'course_domain'})) {
+ if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
+ $clonehash{'internal.coursecode'},$args->{'crscode'})) {
+ $can_clone = 1;
+ }
+ }
+ }
+ }
} else {
+ my @cloners = split(/,/,$clonehash{'cloners'});
+ if (grep(/^\*$/,@cloners)) {
+ $can_clone = 1;
+ } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
+ $can_clone = 1;
+ } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
+ $can_clone = 1;
+ }
+ unless ($can_clone) {
+ if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
+ ($args->{'clonedomain'} eq $args->{'course_domain'})) {
+ my (%gotdomdefaults,%gotcodedefaults);
+ foreach my $cloner (@cloners) {
+ if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
+ ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
+ my (%codedefaults,@code_order);
+ if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
+ if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
+ %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
+ }
+ if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
+ @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
+ }
+ } else {
+ &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
+ \%codedefaults,
+ \@code_order);
+ $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
+ $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
+ }
+ if (@code_order > 0) {
+ if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
+ $cloner,$clonehash{'internal.coursecode'},
+ $args->{'crscode'})) {
+ $can_clone = 1;
+ last;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ unless ($can_clone) {
my $ccrole = 'cc';
if ($args->{'crstype'} eq 'Community') {
$ccrole = 'co';
}
my %roleshash =
&Apache::lonnet::get_my_roles($args->{'ccuname'},
- $args->{'ccdomain'},
- 'userroles',['active'],[$ccrole],
- [$args->{'clonedomain'}]);
- if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
+ $args->{'ccdomain'},
+ 'userroles',['active'],[$ccrole],
+ [$args->{'clonedomain'}]);
+ if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
$can_clone = 1;
- } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
+ } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
+ $args->{'ccuname'},$args->{'ccdomain'})) {
$can_clone = 1;
+ }
+ }
+ unless ($can_clone) {
+ if ($args->{'crstype'} eq 'Community') {
+ $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
} else {
- if ($args->{'crstype'} eq 'Community') {
- $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
- } else {
- $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
- }
- }
+ $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
+ }
}
}
}
@@ -13737,7 +15476,8 @@ sub check_clone {
}
sub construct_course {
- my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
+ my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
+ $cnum,$category,$coderef) = @_;
my $outcome;
my $linefeed = ' '."\n";
if ($context eq 'auto') {
@@ -13765,7 +15505,12 @@ sub construct_course {
#
# Open course
#
- my $crstype = lc($args->{'crstype'});
+ my $showncrstype;
+ if ($args->{'crstype'} eq 'Placement') {
+ $showncrstype = 'placement test';
+ } else {
+ $showncrstype = lc($args->{'crstype'});
+ }
my %cenv=();
$$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
$args->{'cdescr'},
@@ -13782,7 +15527,7 @@ sub construct_course {
# Utils::Course. This needs to at least be output as a comment
# if anyone ever decides to not show this, and Utils::Course::new
# will need to be suitably modified.
- $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
+ $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
if ($$courseid =~ /^error:/) {
return (0,$outcome);
}
@@ -13802,7 +15547,7 @@ sub construct_course {
# Do the cloning
#
if ($can_clone && $cloneid) {
- $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
+ $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
if ($context ne 'auto') {
$clonemsg = ''.$clonemsg.' ';
}
@@ -13834,8 +15579,12 @@ sub construct_course {
'plc.users.denied',
'hidefromcat',
'checkforpriv',
- 'categories'],
+ 'categories',
+ 'internal.uniquecode'],
$$crsudom,$$crsunum);
+ if ($args->{'textbook'}) {
+ $cenv{'internal.textbook'} = $args->{'textbook'};
+ }
}
#
@@ -13881,7 +15630,7 @@ sub construct_course {
my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
$cenv{'internal.sectionnums'} .= $item.',';
unless ($addcheck eq 'ok') {
- push @badclasses, $class;
+ push(@badclasses,$class);
}
}
$cenv{'internal.sectionnums'} =~ s/,$//;
@@ -13909,7 +15658,7 @@ sub construct_course {
my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
$cenv{'internal.crosslistings'} .= $item.',';
unless ($addcheck eq 'ok') {
- push @badclasses, $xl;
+ push(@badclasses,$xl);
}
}
$cenv{'internal.crosslistings'} =~ s/,$//;
@@ -13944,27 +15693,28 @@ sub construct_course {
}
if (@badclasses > 0) {
my %lt=&Apache::lonlocal::texthash(
- 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course',
- 'dnhr' => 'does not have rights to access enrollment in these classes',
- 'adby' => 'as determined by the policies of your institution on access to official classlists'
+ 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
+ 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
+ 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
);
- my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
- ' ('.$lt{'adby'}.')';
+ my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
+ &mt('That is because the user identified as the course owner ([_1]) does not have rights to access enrollment in these classes, as determined by the policies of your institution on access to official classlists',$cenv{'internal.courseowner'}).$linefeed.$lt{'itis'};
if ($context eq 'auto') {
$outcome .= $badclass_msg.$linefeed;
+ } else {
$outcome .= ''.$badclass_msg.$linefeed.'
'."\n";
- foreach my $item (@badclasses) {
- if ($context eq 'auto') {
- $outcome .= " - $item\n";
- } else {
- $outcome .= "$item \n";
- }
- }
+ }
+ foreach my $item (@badclasses) {
if ($context eq 'auto') {
- $outcome .= $linefeed;
+ $outcome .= " - $item\n";
} else {
- $outcome .= " \n";
+ $outcome .= "$item \n";
}
+ }
+ if ($context eq 'auto') {
+ $outcome .= $linefeed;
+ } else {
+ $outcome .= " \n";
}
}
if ($args->{'no_end_date'}) {
@@ -13997,6 +15747,9 @@ sub construct_course {
if ($args->{'setcontent'}) {
$cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
}
+ if ($args->{'setcomment'}) {
+ $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
+ }
}
if ($args->{'reshome'}) {
$cenv{'reshome'}=$args->{'reshome'}.'/';
@@ -14019,6 +15772,25 @@ sub construct_course {
}
}
+#
+# generate and store uniquecode (available to course requester), if course should have one.
+#
+ if ($args->{'uniquecode'}) {
+ my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
+ if ($code) {
+ $cenv{'internal.uniquecode'} = $code;
+ my %crsinfo =
+ &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
+ if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
+ $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
+ my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
+ }
+ if (ref($coderef)) {
+ $$coderef = $code;
+ }
+ }
+ }
+
if ($args->{'disresdis'}) {
$cenv{'pch.roles.denied'}='st';
}
@@ -14084,14 +15856,91 @@ sub construct_course {
$outcome .= ($fatal?$errtext:'write ok').$linefeed;
}
+#
+# Set params for Placement Tests
+#
+ if ($args->{'crstype'} eq 'Placement') {
+ my %storecontent;
+ my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
+ my %defaults = (
+ buttonshide => { value => 'yes',
+ type => 'string_yesno',},
+ type => { value => 'randomizetry',
+ type => 'string_questiontype',},
+ maxtries => { value => 1,
+ type => 'int_pos',},
+ problemstatus => { value => 'no',
+ type => 'string_problemstatus',},
+ );
+ foreach my $key (keys(%defaults)) {
+ $storecontent{$prefix.$key} = $defaults{$key}{'value'};
+ $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
+ }
+ &Apache::lonnet::cput
+ ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
+ }
+
return (1,$outcome);
}
+sub make_unique_code {
+ my ($cdom,$cnum) = @_;
+ # get lock on uniquecodes db
+ my $lockhash = {
+ $cnum."\0".'uniquecodes' => $env{'user.name'}.
+ ':'.$env{'user.domain'},
+ };
+ my $tries = 0;
+ my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
+ my ($code,$error);
+
+ while (($gotlock ne 'ok') && ($tries<3)) {
+ $tries ++;
+ sleep 1;
+ $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
+ }
+ if ($gotlock eq 'ok') {
+ my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
+ my $gotcode;
+ my $attempts = 0;
+ while ((!$gotcode) && ($attempts < 100)) {
+ $code = &generate_code();
+ if (!exists($currcodes{$code})) {
+ $gotcode = 1;
+ unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
+ $error = 'nostore';
+ }
+ }
+ $attempts ++;
+ }
+ my @del_lock = ($cnum."\0".'uniquecodes');
+ my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
+ } else {
+ $error = 'nolock';
+ }
+ return ($code,$error);
+}
+
+sub generate_code {
+ my $code;
+ my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
+ for (my $i=0; $i<6; $i++) {
+ my $lettnum = int (rand 2);
+ my $item = '';
+ if ($lettnum) {
+ $item = $letts[int( rand(18) )];
+ } else {
+ $item = 1+int( rand(8) );
+ }
+ $code .= $item;
+ }
+ return $code;
+}
+
############################################################
############################################################
-#SD
-# only Community and Course, or anything else?
+# Community, Course and Placement Test
sub course_type {
my ($cid) = @_;
if (!defined($cid)) {
@@ -14109,16 +15958,19 @@ sub group_term {
my %names = (
'Course' => 'group',
'Community' => 'group',
+ 'Placement' => 'group',
);
return $names{$crstype};
}
sub course_types {
- my @types = ('official','unofficial','community');
+ my @types = ('official','unofficial','community','textbook','placement');
my %typename = (
official => 'Official course',
unofficial => 'Unofficial course',
community => 'Community',
+ textbook => 'Textbook course',
+ placement => 'Placement test',
);
return (\@types,\%typename);
}
@@ -14179,7 +16031,7 @@ sub escape_url {
my ($url) = @_;
my @urlslices = split(/\//, $url,-1);
my $lastitem = &escape(pop(@urlslices));
- return join('/',@urlslices).'/'.$lastitem;
+ return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
}
sub compare_arrays {
@@ -14205,8 +16057,6 @@ sub init_user_environment {
my $public=($username eq 'public' && $domain eq 'public');
-# See if old ID present, if so, remove
-
my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
my $now=time;
@@ -14228,7 +16078,8 @@ sub init_user_environment {
}
if (!$cookie) { $cookie="publicuser_$oldest"; }
} else {
- # if this isn't a robot, kill any existing non-robot sessions
+ # See if old ID present, if so, remove if this isn't a robot,
+ # killing any existing non-robot sessions
if (!$args->{'robot'}) {
opendir(DIR,$lonids);
while ($filename=readdir(DIR)) {
@@ -14237,6 +16088,17 @@ sub init_user_environment {
}
}
closedir(DIR);
+# If there is a undeleted lockfile for the user's paste buffer remove it.
+ my $namespace = 'nohist_courseeditor';
+ my $lockingkey = 'paste'."\0".'locked_num';
+ my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
+ $domain,$username);
+ if (exists($lockhash{$lockingkey})) {
+ my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
+ unless ($delresult eq 'ok') {
+ &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
+ }
+ }
}
# Give them a new cookie
my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
@@ -14250,15 +16112,14 @@ sub init_user_environment {
}
# ------------------------------------ Check browser type and MathML capability
- my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
- $clientunicode,$clientos,$clientmobile) = &decode_user_agent($r);
+ my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
+ $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
# ------------------------------------------------------------- Get environment
my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
my ($tmp) = keys(%userenv);
- if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
- } else {
+ if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
undef(%userenv);
}
if (($userenv{'interface'}) && (!$form->{'interface'})) {
@@ -14283,6 +16144,8 @@ sub init_user_environment {
"browser.unicode" => $clientunicode,
"browser.os" => $clientos,
"browser.mobile" => $clientmobile,
+ "browser.info" => $clientinfo,
+ "browser.osversion" => $clientosversion,
"server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
"request.course.fn" => '',
"request.course.uri" => '',
@@ -14302,39 +16165,81 @@ sub init_user_environment {
$env{'browser.interface'}=$form->{'interface'};
}
- my %is_adv = ( is_adv => $env{'user.adv'} );
- my %domdef;
- unless ($domain eq 'public') {
- %domdef = &Apache::lonnet::get_domain_defaults($domain);
+ if ($form->{'iptoken'}) {
+ my $lonhost = $r->dir_config('lonHostID');
+ $initial_env{"user.noloadbalance"} = $lonhost;
+ $env{'user.noloadbalance'} = $lonhost;
}
- foreach my $tool ('aboutme','blog','webdav','portfolio') {
- $userenv{'availabletools.'.$tool} =
- &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
- undef,\%userenv,\%domdef,\%is_adv);
+ if ($form->{'noloadbalance'}) {
+ my @hosts = &Apache::lonnet::current_machine_ids();
+ my $hosthere = $form->{'noloadbalance'};
+ if (grep(/^\Q$hosthere\E$/,@hosts)) {
+ $initial_env{"user.noloadbalance"} = $hosthere;
+ $env{'user.noloadbalance'} = $hosthere;
+ }
}
- foreach my $crstype ('official','unofficial','community') {
- $userenv{'canrequest.'.$crstype} =
- &Apache::lonnet::usertools_access($username,$domain,$crstype,
- 'reload','requestcourses',
- \%userenv,\%domdef,\%is_adv);
- }
+ unless ($domain eq 'public') {
+ my %is_adv = ( is_adv => $env{'user.adv'} );
+ my %domdef = &Apache::lonnet::get_domain_defaults($domain);
- $userenv{'canrequest.author'} =
- &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
- 'reload','requestauthor',
- \%userenv,\%domdef,\%is_adv);
- my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
- $domain,$username);
- my $reqstatus = $reqauthor{'author_status'};
- if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
- if (ref($reqauthor{'author'}) eq 'HASH') {
- $userenv{'requestauthorqueued'} = $reqstatus.':'.
- $reqauthor{'author'}{'timestamp'};
+ foreach my $tool ('aboutme','blog','webdav','portfolio') {
+ $userenv{'availabletools.'.$tool} =
+ &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
+ undef,\%userenv,\%domdef,\%is_adv);
}
- }
+ foreach my $crstype ('official','unofficial','community','textbook','placement') {
+ $userenv{'canrequest.'.$crstype} =
+ &Apache::lonnet::usertools_access($username,$domain,$crstype,
+ 'reload','requestcourses',
+ \%userenv,\%domdef,\%is_adv);
+ }
+
+ $userenv{'canrequest.author'} =
+ &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
+ 'reload','requestauthor',
+ \%userenv,\%domdef,\%is_adv);
+ my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
+ $domain,$username);
+ my $reqstatus = $reqauthor{'author_status'};
+ if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
+ if (ref($reqauthor{'author'}) eq 'HASH') {
+ $userenv{'requestauthorqueued'} = $reqstatus.':'.
+ $reqauthor{'author'}{'timestamp'};
+ }
+ }
+ my ($types,$typename) = &course_types();
+ if (ref($types) eq 'ARRAY') {
+ my @options = ('approval','validate','autolimit');
+ my $optregex = join('|',@options);
+ my (%willtrust,%trustchecked);
+ foreach my $type (@{$types}) {
+ my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
+ if ($dom_str ne '') {
+ my $updatedstr = '';
+ my @possdomains = split(',',$dom_str);
+ foreach my $entry (@possdomains) {
+ my ($extdom,$extopt) = split(':',$entry);
+ unless ($trustchecked{$extdom}) {
+ $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
+ $trustchecked{$extdom} = 1;
+ }
+ if ($willtrust{$extdom}) {
+ $updatedstr .= $entry.',';
+ }
+ }
+ $updatedstr =~ s/,$//;
+ if ($updatedstr) {
+ $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
+ } else {
+ delete($userenv{'reqcrsotherdom.'.$type});
+ }
+ }
+ }
+ }
+ }
$env{'user.environment'} = "$lonids/$cookie.id";
if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
@@ -14419,36 +16324,761 @@ sub clean_symb {
return ($symb,$enc);
}
-sub build_release_hashes {
- my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
- return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
- (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
- (ref($randomizetry) eq 'HASH'));
- foreach my $key (keys(%Apache::lonnet::needsrelease)) {
- my ($item,$name,$value) = split(/:/,$key);
- if ($item eq 'parameter') {
- if (ref($checkparms->{$name}) eq 'ARRAY') {
- unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
- push(@{$checkparms->{$name}},$value);
- }
+############################################################
+############################################################
+
+=pod
+
+=head1 Routines for building display used to search for courses
+
+
+=over 4
+
+=item * &build_filters()
+
+Create markup for a table used to set filters to use when selecting
+courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
+and quotacheck.pl
+
+
+Inputs:
+
+filterlist - anonymous array of fields to include as potential filters
+
+crstype - course type
+
+roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
+ to pop-open a course selector (will contain "extra element").
+
+multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
+
+filter - anonymous hash of criteria and their values
+
+action - form action
+
+numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
+
+caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
+
+cloneruname - username of owner of new course who wants to clone
+
+clonerudom - domain of owner of new course who wants to clone
+
+typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
+
+codetitlesref - reference to array of titles of components in institutional codes (official courses)
+
+codedom - domain
+
+formname - value of form element named "form".
+
+fixeddom - domain, if fixed.
+
+prevphase - value to assign to form element named "phase" when going back to the previous screen
+
+cnameelement - name of form element in form on opener page which will receive title of selected course
+
+cnumelement - name of form element in form on opener page which will receive courseID of selected course
+
+cdomelement - name of form element in form on opener page which will receive domain of selected course
+
+setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
+
+clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
+
+clonewarning - warning message about missing information for intended course owner when DC creates a course
+
+
+Returns: $output - HTML for display of search criteria, and hidden form elements.
+
+
+Side Effects: None
+
+=cut
+
+# ---------------------------------------------- search for courses based on last activity etc.
+
+sub build_filters {
+ my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
+ $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
+ $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
+ $cnameelement,$cnumelement,$cdomelement,$setroles,
+ $clonetext,$clonewarning) = @_;
+ my ($list,$jscript);
+ my $onchange = 'javascript:updateFilters(this)';
+ my ($domainselectform,$sincefilterform,$createdfilterform,
+ $ownerdomselectform,$persondomselectform,$instcodeform,
+ $typeselectform,$instcodetitle);
+ if ($formname eq '') {
+ $formname = $caller;
+ }
+ foreach my $item (@{$filterlist}) {
+ unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
+ ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
+ if ($item eq 'domainfilter') {
+ $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
+ } elsif ($item eq 'coursefilter') {
+ $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
+ } elsif ($item eq 'ownerfilter') {
+ $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
+ } elsif ($item eq 'ownerdomfilter') {
+ $filter->{'ownerdomfilter'} =
+ &LONCAPA::clean_domain($filter->{$item});
+ $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
+ 'ownerdomfilter',1);
+ } elsif ($item eq 'personfilter') {
+ $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
+ } elsif ($item eq 'persondomfilter') {
+ $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
+ 'persondomfilter',1);
} else {
- push(@{$checkparms->{$name}},$value);
+ $filter->{$item} =~ s/\W//g;
}
- } elsif ($item eq 'resourcetag') {
- if ($name eq 'responsetype') {
- $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
+ if (!$filter->{$item}) {
+ $filter->{$item} = '';
+ }
+ }
+ if ($item eq 'domainfilter') {
+ my $allow_blank = 1;
+ if ($formname eq 'portform') {
+ $allow_blank=0;
+ } elsif ($formname eq 'studentform') {
+ $allow_blank=0;
+ }
+ if ($fixeddom) {
+ $domainselectform = ' '.
+ &Apache::lonnet::domain($codedom,'description');
+ } else {
+ $domainselectform = &select_dom_form($filter->{$item},
+ 'domainfilter',
+ $allow_blank,'',$onchange);
+ }
+ } else {
+ $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
+ }
+ }
+
+ # last course activity filter and selection
+ $sincefilterform = &timebased_select_form('sincefilter',$filter);
+
+ # course created filter and selection
+ if (exists($filter->{'createdfilter'})) {
+ $createdfilterform = &timebased_select_form('createdfilter',$filter);
+ }
+
+ my $prefix = $crstype;
+ if ($crstype eq 'Placement') {
+ $prefix = 'Placement Test'
+ }
+ my %lt = &Apache::lonlocal::texthash(
+ 'cac' => "$prefix Activity",
+ 'ccr' => "$prefix Created",
+ 'cde' => "$prefix Title",
+ 'cdo' => "$prefix Domain",
+ 'ins' => 'Institutional Code',
+ 'inc' => 'Institutional Categorization',
+ 'cow' => "$prefix Owner/Co-owner",
+ 'cop' => "$prefix Personnel Includes",
+ 'cog' => 'Type',
+ );
+
+ if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
+ my $typeval = 'Course';
+ if ($crstype eq 'Community') {
+ $typeval = 'Community';
+ } elsif ($crstype eq 'Placement') {
+ $typeval = 'Placement';
+ }
+ $typeselectform = ' ';
+ } else {
+ $typeselectform = '".$shown."\n";
+ }
+ $typeselectform.=" ";
+ }
+
+ my ($cloneableonlyform,$cloneabletitle);
+ if (exists($filter->{'cloneableonly'})) {
+ my $cloneableon = '';
+ my $cloneableoff = ' checked="checked"';
+ if ($filter->{'cloneableonly'}) {
+ $cloneableon = $cloneableoff;
+ $cloneableoff = '';
+ }
+ $cloneableonlyform = ' '.&mt('Required').' '.(' 'x3).' '.&mt('No restriction').' ';
+ if ($formname eq 'ccrs') {
+ $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
+ } else {
+ $cloneabletitle = &mt('Cloneable by you');
+ }
+ }
+ my $officialjs;
+ if ($crstype eq 'Course') {
+ if (exists($filter->{'instcodefilter'})) {
+# if (($fixeddom) || ($formname eq 'requestcrs') ||
+# ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
+ if ($codedom) {
+ $officialjs = 1;
+ ($instcodeform,$jscript,$$numtitlesref) =
+ &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
+ $officialjs,$codetitlesref);
+ if ($jscript) {
+ $jscript = ''."\n";
+ }
+ }
+ if ($instcodeform eq '') {
+ $instcodeform =
+ ' ';
+ $instcodetitle = $lt{'ins'};
+ } else {
+ $instcodetitle = $lt{'inc'};
}
- } elsif ($item eq 'course') {
- if ($name eq 'crstype') {
- $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
+ if ($fixeddom) {
+ $instcodetitle .= ' ('.$codedom.')';
}
}
}
- ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
- ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
+ my $output = qq|
+'."\n".' '."\n";
+ return $jscript.$clonewarning.$output;
+}
+
+=pod
+
+=item * &timebased_select_form()
+
+Create markup for a dropdown list used to select a time-based
+filter e.g., Course Activity, Course Created, when searching for courses
+or communities
+
+Inputs:
+
+item - name of form element (sincefilter or createdfilter)
+
+filter - anonymous hash of criteria and their values
+
+Returns: HTML for a select box contained a blank, then six time selections,
+ with value set in incoming form variables currently selected.
+
+Side Effects: None
+
+=cut
+
+sub timebased_select_form {
+ my ($item,$filter) = @_;
+ if (ref($filter) eq 'HASH') {
+ $filter->{$item} =~ s/[^\d-]//g;
+ if (!$filter->{$item}) { $filter->{$item}=-1; }
+ return &select_form(
+ $filter->{$item},
+ $item,
+ { '-1' => '',
+ '86400' => &mt('today'),
+ '604800' => &mt('last week'),
+ '2592000' => &mt('last month'),
+ '7776000' => &mt('last three months'),
+ '15552000' => &mt('last six months'),
+ '31104000' => &mt('last year'),
+ 'select_form_order' =>
+ ['-1','86400','604800','2592000','7776000',
+ '15552000','31104000']});
+ }
+}
+
+=pod
+
+=item * &js_changer()
+
+Create script tag containing Javascript used to submit course search form
+when course type or domain is changed, and also to hide 'Searching ...' on
+page load completion for page showing search result.
+
+Inputs: None
+
+Returns: markup containing updateFilters() and hideSearching() javascript functions.
+
+Side Effects: None
+
+=cut
+
+sub js_changer {
+ return <
+//
+
+
+ENDJS
+}
+
+=pod
+
+=item * &search_courses()
+
+Process selected filters form course search form and pass to lonnet::courseiddump
+to retrieve a hash for which keys are courseIDs which match the selected filters.
+
+Inputs:
+
+dom - domain being searched
+
+type - course type ('Course' or 'Community' or '.' if any).
+
+filter - anonymous hash of criteria and their values
+
+numtitles - for institutional codes - number of categories
+
+cloneruname - optional username of new course owner
+
+clonerudom - optional domain of new course owner
+
+domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
+ (used when DC is using course creation form)
+
+codetitles - reference to array of titles of components in institutional codes (official courses).
+
+cc_clone - escaped comma separated list of courses for which course cloner has active CC role
+ (and so can clone automatically)
+
+reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
+
+reqinstcode - institutional code of new course, where search_courses is used to identify potential
+ courses to clone
+
+Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
+
+
+Side Effects: None
+
+=cut
+
+
+sub search_courses {
+ my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
+ $cc_clone,$reqcrsdom,$reqinstcode) = @_;
+ my (%courses,%showcourses,$cloner);
+ if (($filter->{'ownerfilter'} ne '') ||
+ ($filter->{'ownerdomfilter'} ne '')) {
+ $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
+ $filter->{'ownerdomfilter'};
+ }
+ foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
+ if (!$filter->{$item}) {
+ $filter->{$item}='.';
+ }
+ }
+ my $now = time;
+ my $timefilter =
+ ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
+ my ($createdbefore,$createdafter);
+ if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
+ $createdbefore = $now;
+ $createdafter = $now-$filter->{'createdfilter'};
+ }
+ my ($instcodefilter,$regexpok);
+ if ($numtitles) {
+ if ($env{'form.official'} eq 'on') {
+ $instcodefilter =
+ &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
+ $regexpok = 1;
+ } elsif ($env{'form.official'} eq 'off') {
+ $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
+ unless ($instcodefilter eq '') {
+ $regexpok = -1;
+ }
+ }
+ } else {
+ $instcodefilter = $filter->{'instcodefilter'};
+ }
+ if ($instcodefilter eq '') { $instcodefilter = '.'; }
+ if ($type eq '') { $type = '.'; }
+
+ if (($clonerudom ne '') && ($cloneruname ne '')) {
+ $cloner = $cloneruname.':'.$clonerudom;
+ }
+ %courses = &Apache::lonnet::courseiddump($dom,
+ $filter->{'descriptfilter'},
+ $timefilter,
+ $instcodefilter,
+ $filter->{'combownerfilter'},
+ $filter->{'coursefilter'},
+ undef,undef,$type,$regexpok,undef,undef,
+ undef,undef,$cloner,$cc_clone,
+ $filter->{'cloneableonly'},
+ $createdbefore,$createdafter,undef,
+ $domcloner,undef,$reqcrsdom,$reqinstcode);
+ if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
+ my $ccrole;
+ if ($type eq 'Community') {
+ $ccrole = 'co';
+ } else {
+ $ccrole = 'cc';
+ }
+ my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
+ $filter->{'persondomfilter'},
+ 'userroles',undef,
+ [$ccrole,'in','ad','ep','ta','cr'],
+ $dom);
+ foreach my $role (keys(%rolehash)) {
+ my ($cnum,$cdom,$courserole) = split(':',$role);
+ my $cid = $cdom.'_'.$cnum;
+ if (exists($courses{$cid})) {
+ if (ref($courses{$cid}) eq 'HASH') {
+ if (ref($courses{$cid}{roles}) eq 'ARRAY') {
+ if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
+ push(@{$courses{$cid}{roles}},$courserole);
+ }
+ } else {
+ $courses{$cid}{roles} = [$courserole];
+ }
+ $showcourses{$cid} = $courses{$cid};
+ }
+ }
+ }
+ %courses = %showcourses;
+ }
+ return %courses;
+}
+
+=pod
+
+=back
+
+=head1 Routines for version requirements for current course.
+
+=over 4
+
+=item * &check_release_required()
+
+Compares required LON-CAPA version with version on server, and
+if required version is newer looks for a server with the required version.
+
+Looks first at servers in user's owen domain; if none suitable, looks at
+servers in course's domain are permitted to host sessions for user's domain.
+
+Inputs:
+
+$loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
+
+$courseid - Course ID of current course
+
+$rolecode - User's current role in course (for switchserver query string).
+
+$required - LON-CAPA version needed by course (format: Major.Minor).
+
+
+Returns:
+
+$switchserver - query string tp append to /adm/switchserver call (if
+ current server's LON-CAPA version is too old.
+
+$warning - Message is displayed if no suitable server could be found.
+
+=cut
+
+sub check_release_required {
+ my ($loncaparev,$courseid,$rolecode,$required) = @_;
+ my ($switchserver,$warning);
+ if ($required ne '') {
+ my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
+ my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
+ if ($reqdmajor ne '' && $reqdminor ne '') {
+ my $otherserver;
+ if (($major eq '' && $minor eq '') ||
+ (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
+ my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
+ my $switchlcrev =
+ &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
+ $userdomserver);
+ my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
+ if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
+ (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
+ my $cdom = $env{'course.'.$courseid.'.domain'};
+ if ($cdom ne $env{'user.domain'}) {
+ my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
+ my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
+ my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
+ my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
+ my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
+ my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
+ my $canhost =
+ &Apache::lonnet::can_host_session($env{'user.domain'},
+ $coursedomserver,
+ $remoterev,
+ $udomdefaults{'remotesessions'},
+ $defdomdefaults{'hostedsessions'});
+
+ if ($canhost) {
+ $otherserver = $coursedomserver;
+ } else {
+ $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).' '. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
+ }
+ } else {
+ $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).' '.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
+ }
+ } else {
+ $otherserver = $userdomserver;
+ }
+ }
+ if ($otherserver ne '') {
+ $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
+ }
+ }
+ }
+ return ($switchserver,$warning);
+}
+
+=pod
+
+=item * &check_release_result()
+
+Inputs:
+
+$switchwarning - Warning message if no suitable server found to host session.
+
+$switchserver - query string to append to /adm/switchserver containing lonHostID
+ and current role.
+
+Returns: HTML to display with information about requirement to switch server.
+ Either displaying warning with link to Roles/Courses screen or
+ display link to switchserver.
+
+=cut
+
+sub check_release_result {
+ my ($switchwarning,$switchserver) = @_;
+ my $output = &start_page('Selected course unavailable on this server').
+ '';
+ if ($switchwarning) {
+ $output .= $switchwarning.'';
+ if (&show_course()) {
+ $output .= &mt('Display courses');
+ } else {
+ $output .= &mt('Display roles');
+ }
+ $output .= ' ';
+ } elsif ($switchserver) {
+ $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
+ ' '.
+ ''.
+ &mt('Switch Server').
+ ' ';
+ }
+ $output .= '
'.&end_page();
+ return $output;
+}
+
+=pod
+
+=item * &needs_coursereinit()
+
+Determine if course contents stored for user's session needs to be
+refreshed, because content has changed since "Big Hash" last tied.
+
+Check for change is made if time last checked is more than 10 minutes ago
+(by default).
+
+Inputs:
+
+$loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
+
+$interval (optional) - Time which may elapse (in s) between last check for content
+ change in current course. (default: 600 s).
+
+Returns: an array; first element is:
+
+=over 4
+
+'switch' - if content updates mean user's session
+ needs to be switched to a server running a newer LON-CAPA version
+
+'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
+ on current server hosting user's session
+
+'' - if no action required.
+
+=back
+
+If first item element is 'switch':
+
+second item is $switchwarning - Warning message if no suitable server found to host session.
+
+third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
+ and current role.
+
+otherwise: no other elements returned.
+
+=back
+
+=cut
+
+sub needs_coursereinit {
+ my ($loncaparev,$interval) = @_;
+ return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $now = time;
+ if ($interval eq '') {
+ $interval = 600;
+ }
+ if (($now-$env{'request.course.timechecked'})>$interval) {
+ &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
+ my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
+ if ($blocked) {
+ return ();
+ }
+ my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
+ if ($lastchange > $env{'request.course.tied'}) {
+ my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
+ if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
+ my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
+ if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
+ &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
+ $curr_reqd_hash{'internal.releaserequired'}});
+ my ($switchserver,$switchwarning) =
+ &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
+ $curr_reqd_hash{'internal.releaserequired'});
+ if ($switchwarning ne '' || $switchserver ne '') {
+ return ('switch',$switchwarning,$switchserver);
+ }
+ }
+ }
+ return ('update');
+ }
+ }
+ return ();
+}
+
sub update_content_constraints {
my ($cdom,$cnum,$chome,$cid) = @_;
my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
@@ -14535,9 +17165,33 @@ sub parse_supplemental_title {
return $title;
}
+sub recurse_supplemental {
+ my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
+ if ($suppmap) {
+ my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
+ if ($fatal) {
+ $errors ++;
+ } else {
+ if ($#LONCAPA::map::resources > 0) {
+ foreach my $res (@LONCAPA::map::resources) {
+ my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
+ if (($src ne '') && ($status eq 'res')) {
+ if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
+ ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
+ } else {
+ $numfiles ++;
+ }
+ }
+ }
+ }
+ }
+ }
+ return ($numfiles,$errors);
+}
+
sub symb_to_docspath {
- my ($symb) = @_;
- return unless ($symb);
+ my ($symb,$navmapref) = @_;
+ return unless ($symb && ref($navmapref));
my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
if ($resurl=~/\.(sequence|page)$/) {
$mapurl=$resurl;
@@ -14545,9 +17199,11 @@ sub symb_to_docspath {
$mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
}
my $mapresobj;
- my $navmap = Apache::lonnavmaps::navmap->new();
- if (ref($navmap)) {
- $mapresobj = $navmap->getResourceByUrl($mapurl);
+ unless (ref($$navmapref)) {
+ $$navmapref = Apache::lonnavmaps::navmap->new();
+ }
+ if (ref($$navmapref)) {
+ $mapresobj = $$navmapref->getResourceByUrl($mapurl);
}
$mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
my $type=$2;
@@ -14557,14 +17213,14 @@ sub symb_to_docspath {
if ($pcslist ne '') {
foreach my $pc (split(/,/,$pcslist)) {
next if ($pc <= 1);
- my $res = $navmap->getByMapPc($pc);
+ my $res = $$navmapref->getByMapPc($pc);
if (ref($res)) {
my $thisurl = $res->src();
$thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
my $thistitle = $res->title();
$path .= '&'.
&Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
- &Apache::lonhtmlcommon::entity_encode($thistitle).
+ &escape($thistitle).
':'.$res->randompick().
':'.$res->randomout().
':'.$res->encrypted().
@@ -14580,7 +17236,7 @@ sub symb_to_docspath {
}
$path .= (($path ne '')? '&' : '').
&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
- &Apache::lonhtmlcommon::entity_encode($maptitle).
+ &escape($maptitle).
':'.$mapresobj->randompick().
':'.$mapresobj->randomout().
':'.$mapresobj->encrypted().
@@ -14593,11 +17249,11 @@ sub symb_to_docspath {
$maptitle = 'Main Content';
}
$path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
- &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage;
+ &escape($maptitle).':::::'.$ispage;
}
unless ($mapurl eq 'default') {
$path = 'default&'.
- &Apache::lonhtmlcommon::entity_encode('Main Content').
+ &escape('Main Content').
':::::&'.$path;
}
return $path;
@@ -14606,29 +17262,30 @@ sub symb_to_docspath {
sub captcha_display {
my ($context,$lonhost) = @_;
my ($output,$error);
- my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
+ my ($captcha,$pubkey,$privkey,$version) =
+ &get_captcha_config($context,$lonhost);
if ($captcha eq 'original') {
$output = &create_captcha();
unless ($output) {
- $error = 'captcha';
+ $error = 'captcha';
}
} elsif ($captcha eq 'recaptcha') {
- $output = &create_recaptcha($pubkey);
+ $output = &create_recaptcha($pubkey,$version);
unless ($output) {
- $error = 'recaptcha';
+ $error = 'recaptcha';
}
}
- return ($output,$error);
+ return ($output,$error,$captcha,$version);
}
sub captcha_response {
my ($context,$lonhost) = @_;
my ($captcha_chk,$captcha_error);
- my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
+ my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
if ($captcha eq 'original') {
($captcha_chk,$captcha_error) = &check_captcha();
} elsif ($captcha eq 'recaptcha') {
- $captcha_chk = &check_recaptcha($privkey);
+ $captcha_chk = &check_recaptcha($privkey,$version);
} else {
$captcha_chk = 1;
}
@@ -14637,7 +17294,7 @@ sub captcha_response {
sub get_captcha_config {
my ($context,$lonhost) = @_;
- my ($captcha,$pubkey,$privkey,$hashtocheck);
+ my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
my $hostname = &Apache::lonnet::hostname($lonhost);
my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
@@ -14653,6 +17310,10 @@ sub get_captcha_config {
}
if ($privkey && $pubkey) {
$captcha = 'recaptcha';
+ $version = $hashtocheck->{'recaptchaversion'};
+ if ($version ne '2') {
+ $version = 1;
+ }
} else {
$captcha = 'original';
}
@@ -14670,6 +17331,10 @@ sub get_captcha_config {
$privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
if ($privkey && $pubkey) {
$captcha = 'recaptcha';
+ $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
+ if ($version ne '2') {
+ $version = 1;
+ }
} else {
$captcha = 'original';
}
@@ -14677,7 +17342,7 @@ sub get_captcha_config {
$captcha = 'original';
}
}
- return ($captcha,$pubkey,$privkey);
+ return ($captcha,$pubkey,$privkey,$version);
}
sub create_captcha {
@@ -14694,8 +17359,9 @@ sub create_captcha {
if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
$output = ' '."\n".
&mt('Type in the letters/numbers shown below').' '.
- ' '.
- ' ';
+ ' '.
+ ' '.
+ ' ';
last;
}
}
@@ -14735,37 +17401,185 @@ sub check_captcha {
}
sub create_recaptcha {
- my ($pubkey) = @_;
- my $captcha = Captcha::reCAPTCHA->new;
- return $captcha->get_options_setter({theme => 'white'})."\n".
- $captcha->get_html($pubkey).
- &mt('If either word is hard to read, [_1] will replace them.',
- ' ').
- ' ';
+ my ($pubkey,$version) = @_;
+ if ($version >= 2) {
+ return '
';
+ } else {
+ my $use_ssl;
+ if ($ENV{'SERVER_PORT'} == 443) {
+ $use_ssl = 1;
+ }
+ my $captcha = Captcha::reCAPTCHA->new;
+ return $captcha->get_options_setter({theme => 'white'})."\n".
+ $captcha->get_html($pubkey,undef,$use_ssl).
+ &mt('If the text is hard to read, [_1] will replace them.',
+ ' ').
+ ' ';
+ }
}
sub check_recaptcha {
- my ($privkey) = @_;
+ my ($privkey,$version) = @_;
my $captcha_chk;
- my $captcha = Captcha::reCAPTCHA->new;
- my $captcha_result =
- $captcha->check_answer(
- $privkey,
- $ENV{'REMOTE_ADDR'},
- $env{'form.recaptcha_challenge_field'},
- $env{'form.recaptcha_response_field'},
- );
- if ($captcha_result->{is_valid}) {
- $captcha_chk = 1;
+ if ($version >= 2) {
+ my %info = (
+ secret => $privkey,
+ response => $env{'form.g-recaptcha-response'},
+ remoteip => $ENV{'REMOTE_ADDR'},
+ );
+ my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
+ $request->content(join('&',map {
+ my $name = escape($_);
+ "$name=" . ( ref($info{$_}) eq 'ARRAY'
+ ? join("&$name=", map {escape($_) } @{$info{$_}})
+ : &escape($info{$_}) );
+ } keys(%info)));
+ my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
+ if ($response->is_success) {
+ my $data = JSON::DWIW->from_json($response->decoded_content);
+ if (ref($data) eq 'HASH') {
+ if ($data->{'success'}) {
+ $captcha_chk = 1;
+ }
+ }
+ }
+ } else {
+ my $captcha = Captcha::reCAPTCHA->new;
+ my $captcha_result =
+ $captcha->check_answer(
+ $privkey,
+ $ENV{'REMOTE_ADDR'},
+ $env{'form.recaptcha_challenge_field'},
+ $env{'form.recaptcha_response_field'},
+ );
+ if ($captcha_result->{is_valid}) {
+ $captcha_chk = 1;
+ }
}
return $captcha_chk;
}
-=pod
+sub emailusername_info {
+ my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
+ my %titles = &Apache::lonlocal::texthash (
+ lastname => 'Last Name',
+ firstname => 'First Name',
+ institution => 'School/college/university',
+ location => "School's city, state/province, country",
+ web => "School's web address",
+ officialemail => 'E-mail address at institution (if different)',
+ id => 'Student/Employee ID',
+ );
+ return (\@fields,\%titles);
+}
-=back
+sub cleanup_html {
+ my ($incoming) = @_;
+ my $outgoing;
+ if ($incoming ne '') {
+ $outgoing = $incoming;
+ $outgoing =~ s/;/;/g;
+ $outgoing =~ s/\#/#/g;
+ $outgoing =~ s/\&/&/g;
+ $outgoing =~ s/</g;
+ $outgoing =~ s/>/>/g;
+ $outgoing =~ s/\(/(/g;
+ $outgoing =~ s/\)/)/g;
+ $outgoing =~ s/"/"/g;
+ $outgoing =~ s/'/'/g;
+ $outgoing =~ s/\$/$/g;
+ $outgoing =~ s{/}{/}g;
+ $outgoing =~ s/=/=/g;
+ $outgoing =~ s/\\/\/g
+ }
+ return $outgoing;
+}
+
+# Checks for critical messages and returns a redirect url if one exists.
+# $interval indicates how often to check for messages.
+# $context is the calling context -- roles, grades, contents, menu or flip.
+sub critical_redirect {
+ my ($interval,$context) = @_;
+ if ((time-$env{'user.criticalcheck.time'})>$interval) {
+ if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
+ if ($blocked) {
+ my $checkrole = "cm./$cdom/$cnum";
+ if ($env{'request.course.sec'} ne '') {
+ $checkrole .= "/$env{'request.course.sec'}";
+ }
+ unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
+ ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
+ return;
+ }
+ }
+ }
+ my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
+ $env{'user.name'});
+ &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
+ my $redirecturl;
+ if ($what[0]) {
+ if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
+ $redirecturl='/adm/email?critical=display';
+ my $url=&Apache::lonnet::absolute_url().$redirecturl;
+ return (1, $url);
+ }
+ }
+ }
+ return ();
+}
-=cut
+# Use:
+# my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
+#
+##################################################
+# password associated functions #
+##################################################
+sub des_keys {
+ # Make a new key for DES encryption.
+ # Each key has two parts which are returned separately.
+ # Please note: Each key must be passed through the &hex function
+ # before it is output to the web browser. The hex versions cannot
+ # be used to decrypt.
+ my @hexstr=('0','1','2','3','4','5','6','7',
+ '8','9','a','b','c','d','e','f');
+ my $lkey='';
+ for (0..7) {
+ $lkey.=$hexstr[rand(15)];
+ }
+ my $ukey='';
+ for (0..7) {
+ $ukey.=$hexstr[rand(15)];
+ }
+ return ($lkey,$ukey);
+}
+
+sub des_decrypt {
+ my ($key,$cyphertext) = @_;
+ my $keybin=pack("H16",$key);
+ my $cypher;
+ if ($Crypt::DES::VERSION>=2.03) {
+ $cypher=new Crypt::DES $keybin;
+ } else {
+ $cypher=new DES $keybin;
+ }
+ my $plaintext='';
+ my $cypherlength = length($cyphertext);
+ my $numchunks = int($cypherlength/32);
+ for (my $j=0; $j<$numchunks; $j++) {
+ my $start = $j*32;
+ my $cypherblock = substr($cyphertext,$start,32);
+ my $chunk =
+ $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
+ $chunk .=
+ $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
+ $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
+ $plaintext .= $chunk;
+ }
+ return $plaintext;
+}
1;
__END__;