+
';
- if (exists $item->{'header'}->[0]->{'col1'} ||
- exists $item->{'header'}->[0]->{'col2'}) {
+ if (exists $item->{'header'}->[2]->{'col1'} ||
+ exists $item->{'header'}->[2]->{'col2'}) {
$output .= '
- '.&mt($item->{'header'}->[0]->{'col1'}).' |
- '.&mt($item->{'header'}->[0]->{'col2'}).' |
+ '.&mt($item->{'header'}->[2]->{'col1'}).' |
+ '.&mt($item->{'header'}->[2]->{'col2'}).' |
';
}
}
} else {
$output .= '
+
+
';
if (exists $item->{'header'}->[0]->{'col1'} ||
exists $item->{'header'}->[0]->{'col2'}) {
$output .= '
- '.&mt($item->{'header'}->[0]->{'col1'}).' |
- '.&mt($item->{'header'}->[0]->{'col2'}).' |
+ '.&mt($item->{'header'}->[0]->{'col1'}).' | ';
+ if (($action eq 'courseinfo') || ($action eq 'localization') ||
+ ($action eq 'print_discussion')) {
+ $output .= '';
+ } else {
+ $output .= ' | ';
+ }
+ $output .= &mt($item->{'header'}->[0]->{'col2'}).' |
';
}
}
$rowtotal ++;
if ($action eq 'courseinfo') {
- $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype);
+ $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
} elsif ($action eq 'localization') {
- $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal);
+ $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
} elsif ($action eq 'feedback') {
- $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal);
+ $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
} elsif ($action eq 'discussion') {
- $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal);
- } elsif ($action eq 'classlists') {
- $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype);
+ $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
+ } elsif (($action eq 'classlists') || ($action eq 'viewableroster')) {
+ $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
} elsif ($action eq 'appearance') {
- $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype);
+ $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
} elsif ($action eq 'grading') {
- $output .= &print_grading($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype);
+ $output .= &print_grading($cdom,$cnum,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
} elsif ($action eq 'printouts') {
- $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype);
+ $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
} elsif ($action eq 'spreadsheet') {
- $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype);
+ $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
} elsif ($action eq 'bridgetasks') {
- $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype);
+ $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
+ } elsif ($action eq 'ltitools') {
+ my $currtools = {};
+ if ((ref($settings) eq 'HASH') && (ref($settings->{'ltitools'}))) {
+ $currtools = $settings->{'ltitools'};
+ }
+ $output .= &print_ltitools($cdom,$cnum,$currtools,\$rowtotal,$crstype,$noedit,'course');
+ } elsif ($action eq 'menuitems') {
+ $output .= &print_menuitems('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
+ } elsif ($action eq 'linkprot') {
+ $output .= &print_linkprotection($cdom,$cnum,$settings,\$rowtotal,$crstype,$noedit,'course');
} elsif ($action eq 'other') {
- $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype);
+ $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype,$noedit);
}
$output .= '
-';
+ |
+
+ ';
return ($output,$rowtotal);
}
sub process_changes {
- my ($cdom,$action,$values,$item,$changes,$allitems,$disallowed,$crstype) = @_;
- my %newvalues;
+ my ($cdom,$cnum,$action,$values,$item,$changes,$allitems,$disallowed,$crstype,$lastactref) = @_;
+ my (%newvalues,$errors);
if (ref($item) eq 'HASH') {
if (ref($changes) eq 'HASH') {
my @ordered;
@@ -647,8 +854,41 @@ sub process_changes {
}
}
}
+ } elsif (($action eq 'linkprot') || ($action eq 'ltitools')) {
+ if (ref($values->{$action}) eq 'HASH') {
+ foreach my $id (keys(%{$values->{$action}})) {
+ if ($id =~ /^\d+$/) {
+ push(@ordered,$id);
+ }
+ }
+ }
+ @ordered = sort { $a <=> $b } @ordered;
+ if (($env{'form.'.$action.'_add'}) && ($env{'form.'.$action.'_maxnum'} =~ /^\d+$/)) {
+ push(@ordered,$env{'form.'.$action.'_maxnum'});
+ }
} elsif (ref($item->{'ordered'}) eq 'ARRAY') {
- @ordered = @{$item->{'ordered'}};
+ if ($action eq 'courseinfo') {
+ my ($can_toggle_cat,$can_categorize) =
+ &can_modify_catsettings($cdom,$crstype);
+ foreach my $entry (@{$item->{'ordered'}}) {
+ next if (($entry eq 'hidefromcat') &&
+ (!$can_toggle_cat));
+ next if (($entry eq 'categories') &&
+ (!$can_categorize));
+ next if (($entry eq 'loncaparev') ||
+ ($entry eq 'owner') ||
+ ($entry eq 'clonedfrom') ||
+ ($entry eq 'syllabus'));
+ push(@ordered,$entry);
+ }
+ } elsif ($action eq 'classlists') {
+ foreach my $entry (@{$item->{'ordered'}}) {
+ next if ($entry eq 'defaultcredits');
+ push(@ordered,$entry);
+ }
+ } else {
+ @ordered = @{$item->{'ordered'}};
+ }
}
if (@ordered > 0) {
if ($action eq 'feedback') {
@@ -688,9 +928,93 @@ sub process_changes {
$changes->{$ext_entry} = $newvalues{$ext_entry};
}
}
+ } elsif ($action eq 'menuitems') {
+ my (%current,@colls);
+ my $next = 1;
+ if ($values->{'menucollections'}) {
+ foreach my $item (split(/;/,$values->{'menucollections'})) {
+ my ($num,$value) = split(/\%/,$item);
+ if ($num =~ /^\d+$/) {
+ unless (grep(/^$num$/,@colls)) {
+ push(@colls,$num);
+ }
+ my @entries = split(/\&/,$value);
+ foreach my $entry (@entries) {
+ my ($name,$fields) = split(/=/,$entry);
+ $current{$num}{$name} = $fields;
+ }
+ }
+ }
+ }
+ if (@colls) {
+ @colls = sort { $a <=> $b } @colls;
+ $next += $colls[-1];
+ }
+ if ($env{'form.menucollections_add'} eq $next) {
+ push(@colls,$next);
+ }
+ my $currdef = $values->{'menudefault'};
+ my $possdef = $env{'form.menudefault'};
+ if (($possdef =~ /^\d+$/) && (grep(/^$possdef$/,@colls))) {
+ if ($currdef ne $possdef) {
+ $changes->{'menudefault'} = $possdef;
+ }
+ } elsif ($currdef) {
+ $changes->{'menudefault'} = '';
+ }
+ my $menucoll;
+ if (@colls) {
+ my ($ordered,$cats) = &menuitems_categories();
+ my %shortcats = &menuitems_abbreviations();
+ foreach my $num (@colls) {
+ my ($entry,%include);
+ map { $include{$_}= 1; } &Apache::loncommon::get_env_multiple('form.menucollections_'.$num);
+ foreach my $item (@{$ordered}) {
+ if ($item eq 'shown') {
+ foreach my $type (@{$cats->{$item}}) {
+ $entry .= $type.'=';
+ if ($include{$type}) {
+ $entry .= 'y';
+ } else {
+ $entry .= 'n';
+ }
+ $entry .= '&';
+ }
+ } else {
+ $entry .= $shortcats{$item}.'=';
+ foreach my $type (@{$cats->{$item}}) {
+ if ($include{$type}) {
+ $entry .= $type.',';
+ }
+ }
+ $entry =~ s/,$//;
+ $entry .= '&';
+ }
+ }
+ $entry =~ s/\&$//;
+ if ($menucoll) {
+ $menucoll .= ';';
+ }
+ $menucoll .= $num.'%'.$entry;
+ }
+ if ($menucoll ne $values->{'menucollections'}) {
+ $changes->{'menucollections'} = $menucoll;
+ }
+ } elsif ($values->{'menucollections'}) {
+ $changes->{'menucollections'} = '';
+ }
+ } elsif ($action eq 'linkprot') {
+ if (ref($values) eq 'HASH') {
+ $errors = &process_linkprot($cdom,$cnum,$values->{$action},$changes,'course',$lastactref);
+ }
+ } elsif ($action eq 'ltitools') {
+ if (ref($values) eq 'HASH') {
+ my $switchserver = &check_switchserver($cdom,$cnum,'course','/adm/courseprefs');
+ $errors = &process_ltitools('',$cdom,$cnum,$values->{$action},$changes,'course',$lastactref,
+ 'ok','','ok');
+ }
} else {
foreach my $entry (@ordered) {
- next if (($entry eq 'loncaparev') || ($entry eq 'owner'));
if ($entry eq 'cloners') {
if ($env{'form.cloners_all'}) {
$newvalues{$entry} = '*';
@@ -698,7 +1022,7 @@ sub process_changes {
my @clonedoms;
if (exists($env{'form.cloners_activate'})) {
my $actnum = $env{'form.cloners_activate'};
- if ($actnum ne '') {
+ if ($actnum ne '-1') {
if ($env{'form.cloners_dom_'.$actnum} ne '') {
my $clonedom = $env{'form.cloners_dom_'.$actnum};
if (&check_clone($clonedom,$disallowed) eq 'ok') {
@@ -716,7 +1040,7 @@ sub process_changes {
my $clonedom = $env{'form.cloners_dom_'.$i};
if (&check_clone($clonedom,$disallowed) eq 'ok') {
if (!grep(/^\*:\Q$clonedom\E$/,@clonedoms)) {
- push (@clonedoms,'*:'.$clonedom);
+ push(@clonedoms,'*:'.$clonedom);
}
}
}
@@ -729,7 +1053,7 @@ sub process_changes {
my $clonedom = $env{'form.cloners_newdom'};
if (&check_clone($clonedom,$disallowed) eq 'ok') {
my $newdom = '*:'.$env{'form.cloners_newdom'};
- if (@clonedoms) {
+ if (@clonedoms) {
if (!grep(/^\Q$newdom\E$/,@clonedoms)) {
$newvalues{$entry} .= ','.$newdom;
}
@@ -762,6 +1086,37 @@ sub process_changes {
}
}
}
+ if (ref($values) eq 'HASH') {
+ my (@code_order,%codedefaults);
+ &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
+ \@code_order);
+ my $clonebycode;
+ if ($env{'form.cloners_instcode'}) {
+ if (@code_order > 0) {
+ my @standardnames = &Apache::loncommon::get_standard_codeitems();
+ my %local_to_standard;
+ for (my $i=0; $i<@code_order; $i++) {
+ $local_to_standard{$code_order[$i]} = $standardnames[$i];
+ }
+ foreach my $item (@code_order) {
+ my $key = $local_to_standard{$item};
+ if ($key ne '') {
+ if ($env{'form.'.$key}) {
+ $clonebycode .= $key.'='.&escape($env{'form.'.$key}).'&';
+ }
+ }
+ }
+ $clonebycode =~ s/\&$//;
+ }
+ }
+ if ($clonebycode) {
+ if ($newvalues{$entry}) {
+ $newvalues{$entry} .= ','.$clonebycode;
+ } else {
+ $newvalues{$entry} = $clonebycode;
+ }
+ }
+ }
}
if (ref($disallowed) eq 'HASH') {
if (ref($disallowed->{'cloners'}) eq 'HASH') {
@@ -787,7 +1142,9 @@ sub process_changes {
$autocoowner = $domconf{'autoenroll'}{'co-owners'};
}
}
- unless ($autocoowner) {
+ if ($autocoowner) {
+ $newvalues{'co-owners'} = $values->{'internal.co-owners'};
+ } else {
my @keepcoowners = &Apache::loncommon::get_env_multiple('form.coowners');
my @pendingcoowners = &Apache::loncommon::get_env_multiple('form.pendingcoowners');
my @invitecoowners = &Apache::loncommon::get_env_multiple('form.invitecoowners');
@@ -811,19 +1168,19 @@ sub process_changes {
my $udom = $env{'user.domain'};
my $pendingcoowners = $values->{'internal.pendingco-owners'};
my @pendingcoown = split(',',$pendingcoowners);
- if ($env{'form.pending_coowoner'}) {
+ if ($env{'form.pending_coowner'}) {
foreach my $item (@pendingcoown) {
unless ($item eq $uname.':'.$udom) {
push(@newpending,$item);
}
}
@newcoown = @currcoown;
- if ($env{'form.pending_coowoner'} eq 'accept') {
+ if ($env{'form.pending_coowner'} eq 'accept') {
unless (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
push(@newcoown,$uname.':'.$udom);
}
}
- } elsif ($env{'form.remove_coowoner'}) {
+ } elsif ($env{'form.remove_coowner'}) {
foreach my $item (@currcoown) {
unless ($item eq $uname.':'.$udom) {
push(@newcoown,$item);
@@ -832,6 +1189,8 @@ sub process_changes {
if ($pendingcoowners ne '') {
@newpending = @pendingcoown;
}
+ } else {
+ @newcoown = @currcoown;
}
$newvalues{'pendingco-owners'} = join(',',sort(@newpending));
$newvalues{'co-owners'} = join(',',sort(@newcoown));
@@ -957,6 +1316,35 @@ sub process_changes {
}
}
$newvalues{$entry} =~ s/,$//;
+ } elsif ($entry eq 'discussion_post_fonts') {
+ my ($classorder,$classtitles) = &discussion_vote_classes();
+ my $fontchange = 0;
+ foreach my $class (@{$classorder}) {
+ my $ext_entry = $entry.'_'.$class;
+ my $size = $env{'form.'.$ext_entry.'_size'};
+ my $unit = $env{'form.'.$ext_entry.'_unit'};
+ my $weight = $env{'form.'.$ext_entry.'_weight'};
+ my $style = $env{'form.'.$ext_entry.'_style'};
+ my $other = $env{'form.'.$ext_entry.'_other'};
+ $size =~ s/,//g;
+ $unit =~ s/,//g;
+ $weight =~ s/,//g;
+ $style =~ s/,//g;
+ $other =~ s/[^\w;:\s\-\%.]//g;
+ $other =~ s/(^\s+|\s+$)//g;
+ $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other));
+ my $current = $values->{$ext_entry};
+ if ($values->{$ext_entry} eq '') {
+ $current = ',,,';
+ }
+ if ($newvalues{$ext_entry} ne $current) {
+ $changes->{$ext_entry} = $newvalues{$ext_entry};
+ $fontchange ++;
+ }
+ }
+ if ($fontchange) {
+ $changes->{$entry} = 1;
+ }
} elsif ($entry eq 'nothideprivileged') {
my @curr_nothide;
my @new_nothide;
@@ -1031,36 +1419,118 @@ sub process_changes {
my $newtext = $maxnum-1;
$newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext};
$newvalues{$entry} = join('',@newhdr);
- } elsif ($entry eq 'languages') {
- my $langstr;
+ } elsif (($entry eq 'languages') ||
+ ($entry eq 'checkforpriv')) {
+ my $settings;
my $total = $env{'form.'.$entry.'_total'};
if ($total) {
my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
for (my $i=0; $i<$total; $i++) {
unless (grep(/^$i$/,@deletes)) {
- $langstr .= $env{'form.'.$entry.'_'.$i}.',';
+ $settings .= $env{'form.'.$entry.'_'.$i}.',';
}
}
} else {
$total = 0;
}
if ($env{'form.'.$entry.'_'.$total} ne '') {
- my $newlang = $env{'form.'.$entry.'_'.$total};
- my %langchoices = &get_lang_choices();
- if ($langchoices{$newlang}) {
- $langstr .= $newlang;
+ my $new = $env{'form.'.$entry.'_'.$total};
+ if ($entry eq 'languages') {
+ my %langchoices = &get_lang_choices();
+ if ($langchoices{$new}) {
+ $settings .= $new;
+ } else {
+ $settings =~ s/,$//;
+ $disallowed->{'localization'}{$entry} = $new;
+ }
} else {
- $langstr =~ s/,$//;
- $disallowed->{'localization'}{$entry} = $newlang;
+ my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
+ if ($domains{$new}) {
+ $settings .= $new;
+ } else {
+ $settings =~ s/,$//;
+ $disallowed->{'classlists'}{$entry} = $new;
+ }
}
} else {
- $langstr =~ s/,$//;
+ $settings =~ s/,$//;
}
- $newvalues{$entry} = $langstr;
+ $newvalues{$entry} = $settings;
+ } elsif ($entry eq 'extresource') {
+ if ($env{'form.'.$entry} =~ /^iframe|tab|window$/) {
+ $newvalues{$entry} = $env{'form.'.$entry};
+ if ($env{'form.'.$entry} ne 'iframe') {
+ if ($env{'form.extwintabreuse'}) {
+ $newvalues{$entry} .= ':1';
+ } else {
+ $newvalues{$entry} .= ':0';
+ }
+ if ($env{'form.'.$entry} eq 'window') {
+ foreach my $dim ('width','height') {
+ $env{'form.extreswin'.$dim} =~ s/^\s+|\s+$//g;
+ if ($env{'form.extreswin'.$dim} =~ /^\d+$/) {
+ $newvalues{$entry} .= ':'.$env{'form.extreswin'.$dim};
+ } else {
+ $newvalues{$entry} .= ':';
+ }
+ }
+ }
+ }
+ }
+ unless (($newvalues{$entry} eq 'iframe') && ($values->{$entry} eq '')) {
+ if ($newvalues{$entry} ne $values->{$entry}) {
+ $changes->{$entry} = $newvalues{$entry};
+ }
+ }
+ } elsif ($entry eq 'timezone') {
+ if ($env{'form.'.$entry}) {
+ $newvalues{$entry} = $env{'form.'.$entry};
+ if ($newvalues{$entry} ne $values->{$entry}) {
+ $changes->{$entry} = $newvalues{$entry};
+ }
+ if ($env{'form.tzover'}) {
+ $newvalues{'tzover'} = $env{'form.tzover'};
+ if ($newvalues{'tzover'} ne $values->{'tzover'}) {
+ $changes->{'tzover'} = $newvalues{'tzover'};
+ }
+ } elsif ($values->{'tzover'}) {
+ $changes->{'tzover'} = '';
+ }
+ } elsif ($values->{$entry}) {
+ $changes->{$entry} = '';
+ }
+ } elsif ($entry eq 'grading') {
+ if ($env{'form.'.$entry} eq 'standard') {
+ if ($env{'form.hidetotals'}) {
+ my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
+ if (keys(%sections)) {
+ my @secs = &Apache::loncommon::get_env_multiple('form.hidetotals_sections');
+ if (grep(/^all$/,@secs)) {
+ $newvalues{'hidetotals'} = 'all';
+ } elsif (@secs) {
+ $newvalues{'hidetotals'} = '';
+ foreach my $sec (sort {$a <=> $b} @secs) {
+ if (exists($sections{$sec})) {
+ $newvalues{'hidetotals'} .= $sec.','
+ }
+ }
+ $newvalues{'hidetotals'} =~ s/,$//;
+ }
+ } else {
+ $newvalues{'hidetotals'} = 'all';
+ }
+ }
+ }
+ if ($newvalues{'hidetotals'} ne $values->{'hidetotals'}) {
+ $changes->{'hidetotals'} = $newvalues{'hidetotals'};
+ $changes->{'grading'} = $env{'form.'.$entry};
+ }
+ $newvalues{$entry} = $env{'form.'.$entry};
} else {
$newvalues{$entry} = $env{'form.'.$entry};
}
- unless ($entry eq 'co-owners') {
+ unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') ||
+ ($entry eq 'extresource') || ($entry eq 'timezone')) {
if ($newvalues{$entry} ne $values->{$entry}) {
$changes->{$entry} = $newvalues{$entry};
}
@@ -1070,7 +1540,887 @@ sub process_changes {
}
}
}
- return;
+ return $errors;
+}
+
+sub process_linkprot {
+ my ($cdom,$cnum,$values,$changes,$context,$lastactref) = @_;
+ my ($dest,$ltiauth,$privnum,$cipher,$errors,%linkprot);
+ if (ref($values) eq 'HASH') {
+ foreach my $id (keys(%{$values})) {
+ if ($id =~ /^\d+$/) {
+ unless (ref($values->{$id}) eq 'HASH') {
+ $linkprot{$id} = '';
+ }
+ }
+ }
+ }
+ ($cipher,$privnum) = &get_credentials($cdom,$cnum,'lti',$context);
+ if ($context eq 'domain') {
+ $dest = '/adm/domainprefs';
+ $ltiauth = 1;
+ } else {
+ $dest = '/adm/courseprefs';
+ if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
+ $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
+ } else {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
+ $ltiauth = $domdefs{'crsltiauth'};
+ }
+ }
+ my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
+ my (@items,%deletions,%itemids,%haschanges);
+ if ($env{'form.linkprot_add'}) {
+ my $name = $env{'form.linkprot_name_add'};
+ $name =~ s/(`)/'/g;
+ my ($newid,$error) = &get_linkprot_id($cdom,$cnum,$name,$context);
+ if ($newid) {
+ $itemids{'add'} = $newid;
+ push(@items,'add');
+ $haschanges{$newid} = 1;
+ } else {
+ $errors .= ''.
+ &mt('Failed to acquire unique ID for link protection').
+ '';
+ }
+ }
+ if (ref($values) eq 'HASH') {
+ my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del');
+ my $maxnum = $env{'form.linkprot_maxnum'};
+ for (my $i=0; $i<$maxnum; $i++) {
+ my $itemid = $env{'form.linkprot_id_'.$i};
+ $itemid =~ s/\D+//g;
+ if ($itemid) {
+ if (ref($values->{$itemid}) eq 'HASH') {
+ push(@items,$i);
+ $itemids{$i} = $itemid;
+ if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
+ $deletions{$itemid} = $values->{$itemid}->{'name'};
+ }
+ }
+ }
+ }
+ }
+ foreach my $idx (@items) {
+ my $itemid = $itemids{$idx};
+ next unless ($itemid);
+ if (exists($deletions{$itemid})) {
+ $linkprot{$itemid} = $deletions{$itemid};
+ $haschanges{$itemid} = 1;
+ next;
+ }
+ my %current;
+ if (ref($values) eq 'HASH') {
+ if (ref($values->{$itemid}) eq 'HASH') {
+ foreach my $key (keys(%{$values->{$itemid}})) {
+ $current{$key} = $values->{$itemid}->{$key};
+ }
+ }
+ }
+ foreach my $inner ('name','lifetime','version') {
+ my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
+ $env{$formitem} =~ s/(`)/'/g;
+ if ($inner eq 'lifetime') {
+ $env{$formitem} =~ s/[^\d.]//g;
+ }
+ unless ($idx eq 'add') {
+ if ($current{$inner} ne $env{$formitem}) {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ if ($env{$formitem} ne '') {
+ $linkprot{$itemid}{$inner} = $env{$formitem};
+ }
+ }
+ my $urlitem = 'form.linkprot_returnurl_'.$idx;
+ my $urlparamname = 'form.linkprot_urlparam_'.$idx;
+ if ($env{$urlitem} == 1) {
+ $env{$urlparamname} =~ s/(`)/'/g;
+ } elsif (exists($env{$urlparamname})) {
+ $env{$urlparamname} = '';
+ }
+ my $passback = 'form.linkprot_passback_'.$idx;
+ my $passbackparamname = 'form.linkprot_passbackformat_'.$idx;
+ if ($env{$passback} == 1) {
+ unless ($env{$passbackparamname} =~ /^1\.(0|1)$/) {
+ $env{$passbackparamname} = '';
+ }
+ } elsif (exists($env{$passbackparamname})) {
+ $env{$passbackparamname} = '';
+ }
+ unless ($idx eq 'add') {
+ if ((!$current{'returnurl'} && ($env{$urlparamname} ne '')) ||
+ ($current{'returnurl'} && ($env{$urlparamname} eq ''))) {
+ $haschanges{$itemid} = 1;
+ }
+ if ((!$current{'passback'} && ($env{$passbackparamname} ne '')) ||
+ ($current{'passback'} && ($env{$passbackparamname} eq ''))) {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ if ($env{$urlparamname} ne '') {
+ $linkprot{$itemid}{'returnurl'} = $env{$urlparamname};
+ }
+ if ($env{$passbackparamname} ne '') {
+ $linkprot{$itemid}{'passback'} = 1;
+ $linkprot{$itemid}{'passbackformat'} = $env{$passbackparamname};
+ }
+ if ($ltiauth) {
+ my $reqitem = 'form.linkprot_requser_'.$idx;
+ $env{$reqitem} =~ s/(`)/'/g;
+ unless ($idx eq 'add') {
+ if ((!$current{'requser'} && $env{$reqitem}) ||
+ ($current{'requser'} && !$env{$reqitem})) {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ if ($env{$reqitem} == 1) {
+ $linkprot{$itemid}{'requser'} = $env{$reqitem};
+ foreach my $inner ('mapuser','notstudent') {
+ my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
+ $env{$formitem} =~ s/(`)/'/g;
+ if ($inner eq 'mapuser') {
+ if ($env{$formitem} eq 'other') {
+ my $mapuser = $env{'form.linkprot_customuser_'.$idx};
+ $mapuser =~ s/(`)/'/g;
+ $mapuser =~ s/^\s+|\s+$//g;
+ if ($mapuser ne '') {
+ $linkprot{$itemid}{$inner} = $mapuser;
+ } else {
+ delete($linkprot{$itemid}{'requser'});
+ last;
+ }
+ } elsif ($env{$formitem} eq 'sourcedid') {
+ $linkprot{$itemid}{$inner} = 'lis_person_sourcedid';
+ } elsif ($env{$formitem} eq 'email') {
+ $linkprot{$itemid}{$inner} = 'lis_person_contact_email_primary';
+ }
+ } else {
+ $linkprot{$itemid}{$inner} = $env{$formitem};
+ }
+ unless ($idx eq 'add') {
+ if ($current{$inner} ne $linkprot{$itemid}{$inner}) {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ }
+ }
+ }
+ unless ($switchserver) {
+ my $keyitem = 'form.linkprot_key_'.$idx;
+ $env{$keyitem} =~ s/(`)/'/g;
+ unless ($idx eq 'add') {
+ if ($current{'key'} ne $env{$keyitem}) {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ if ($env{$keyitem} ne '') {
+ $linkprot{$itemid}{'key'} = $env{$keyitem};
+ }
+ my $secretitem = 'form.linkprot_secret_'.$idx;
+ $env{$secretitem} =~ s/(`)/'/g;
+ if ($current{'usable'}) {
+ if ($env{'form.linkprot_changesecret_'.$idx}) {
+ if ($env{$secretitem} ne '') {
+ if ($privnum && $cipher) {
+ $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
+ $linkprot{$itemid}{'cipher'} = $privnum;
+ } else {
+ $linkprot{$itemid}{'secret'} = $env{$secretitem};
+ }
+ $haschanges{$itemid} = 1;
+ }
+ } else {
+ $linkprot{$itemid}{'secret'} = $current{'secret'};
+ $linkprot{$itemid}{'cipher'} = $current{'cipher'};
+ }
+ } elsif ($env{$secretitem} ne '') {
+ if ($privnum && $cipher) {
+ $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
+ $linkprot{$itemid}{'cipher'} = $privnum;
+ } else {
+ $linkprot{$itemid}{'secret'} = $env{$secretitem};
+ }
+ $haschanges{$itemid} = 1;
+ }
+ }
+ }
+ if (keys(%haschanges)) {
+ foreach my $entry (keys(%haschanges)) {
+ $changes->{$entry} = $linkprot{$entry};
+ }
+ if (ref($lastactref) eq 'HASH') {
+ $lastactref->{'courselti'} = 1;
+ }
+ }
+ return $errors;
+}
+
+sub get_linkprot_id {
+ my ($cdom,$cnum,$name,$context) = @_;
+ # get lock on lti db in course or linkprot db in domain
+ my $lockhash = {
+ lock => $env{'user.name'}.
+ ':'.$env{'user.domain'},
+ };
+ my $tries = 0;
+ my $gotlock;
+ if ($context eq 'domain') {
+ $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
+ } else {
+ $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
+ }
+ my ($id,$error);
+ while (($gotlock ne 'ok') && ($tries<10)) {
+ $tries ++;
+ sleep (0.1);
+ if ($context eq 'domain') {
+ $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
+ } else {
+ $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
+ }
+ }
+ if ($gotlock eq 'ok') {
+ my %currids;
+ if ($context eq 'domain') {
+ %currids = &Apache::lonnet::dump_dom('linkprot',$cdom);
+ } else {
+ %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
+ }
+ if ($currids{'lock'}) {
+ delete($currids{'lock'});
+ if (keys(%currids)) {
+ my @curr = sort { $a <=> $b } keys(%currids);
+ if ($curr[-1] =~ /^\d+$/) {
+ $id = 1 + $curr[-1];
+ } else {
+ $id = 1;
+ }
+ } else {
+ $id = 1;
+ }
+ if ($id) {
+ if ($context eq 'domain') {
+ unless (&Apache::lonnet::newput_dom('linkprot',{ $id => $name },$cdom) eq 'ok') {
+ $error = 'nostore';
+ }
+ } else {
+ unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') {
+ $error = 'nostore';
+ }
+ }
+ } else {
+ $error = 'nonumber';
+ }
+ }
+ my $dellockoutcome;
+ if ($context eq 'domain') {
+ $dellockoutcome = &Apache::lonnet::del_dom('linkprot',['lock'],$cdom);
+ } else {
+ $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum);
+ }
+ } else {
+ $error = 'nolock';
+ }
+ return ($id,$error);
+}
+
+sub get_credentials {
+ my ($cdom,$cnum,$type,$context) = @_;
+ my ($cipher,$privnum,$home);
+ my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
+ my @ids=&Apache::lonnet::current_machine_ids();
+ if ($context eq 'domain') {
+ $home = &Apache::lonnet::domain($cdom,'primary');
+ } else {
+ $home = &Apache::lonnet::homeserver($cnum,$cdom);
+ }
+ my ($hostskey,$domkey,$crskey);
+ if ($type eq 'ltitools') {
+ $hostskey = 'toolprivhosts';
+ $domkey = 'toolenc_dom';
+ $crskey = 'toolenc_crs';
+ } else {
+ $hostskey = 'ltiprivhosts';
+ $domkey = 'linkprotenc_dom';
+ $crskey = 'linkprotenc_crs';
+ }
+ if ((($context eq 'domain') && ($domdefs{$domkey})) ||
+ (($context eq 'course') && ($domdefs{$crskey}))) {
+ unless (($home eq 'no_host') || ($home eq '')) {
+ if (grep(/^\Q$home\E$/,@ids)) {
+ if (ref($domdefs{$hostskey}) eq 'ARRAY') {
+ if (grep(/^\Q$home\E$/,@{$domdefs{$hostskey}})) {
+ my %privhash = &Apache::lonnet::restore_dom($type,'private',$cdom,$home,1);
+ my $privkey = $privhash{'key'};
+ $privnum = $privhash{'version'};
+ if (($privnum) && ($privkey ne '')) {
+ $cipher = Crypt::CBC->new({'key' => $privkey,
+ 'cipher' => 'DES'});
+ }
+ }
+ }
+ }
+ }
+ }
+ return ($cipher,$privnum);
+}
+
+sub process_ltitools {
+ my ($r,$cdom,$cnum,$values,$changes,$context,$lastactref,$configuserok,$lonhost,
+ $author_ok,$confname) = @_;
+ my (%currconfig,$newid,@allpos,%changes,%ltitools,$errors);
+
+ my (%posslti,%possfield);
+ my @courseroles = ('cc','in','ta','ep','st');
+ my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
+ map { $posslti{$_} = 1; } @ltiroles;
+ my @allfields = ('fullname','firstname','lastname','email','user','roles');
+ map { $possfield{$_} = 1; } @allfields;
+
+ my ($dest,$privnum,$cipher);
+
+ ($cipher,$privnum) = &get_credentials($cdom,$cnum,'ltitools',$context);
+ if ($context eq 'domain') {
+ $dest = '/adm/domainprefs';
+ } else {
+ $dest = '/adm/courseprefs';
+ }
+ my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
+
+ my (@allpos,@items,%deletions,%itemids,%haschanges);
+ if ($env{'form.ltitools_add'}) {
+ my $title = $env{'form.ltitools_add_title'};
+ $title =~ s/(`)/'/g;
+ my ($newid,$error) = &Apache::lonnet::get_ltitools_id($context,$cdom,$cnum,$title);
+ if ($newid) {
+ my $position = $env{'form.ltitools_add_pos'};
+ $position =~ s/\D+//g;
+ if ($position ne '') {
+ $allpos[$position] = $newid;
+ }
+ $haschanges{$newid} = 1;
+ foreach my $item ('title','url','lifetime') {
+ $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
+ if ($item eq 'lifetime') {
+ $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
+ }
+ if ($env{'form.ltitools_add_'.$item}) {
+ $ltitools{$newid}{$item} = $env{'form.ltitools_add_'.$item};
+ }
+ }
+ if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
+ $ltitools{$newid}{'version'} = $env{'form.ltitools_add_version'};
+ }
+ if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
+ $ltitools{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
+ }
+ if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
+ $ltitools{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
+ } else {
+ $ltitools{$newid}{'sigmethod'} = 'HMAC-SHA1';
+ }
+ foreach my $item ('width','height','linktext','explanation') {
+ $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
+ $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
+ if (($item eq 'width') || ($item eq 'height')) {
+ if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
+ $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
+ }
+ } else {
+ if ($env{'form.ltitools_add_'.$item} ne '') {
+ $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
+ }
+ }
+ }
+ if ($env{'form.ltitools_add_target'} eq 'window') {
+ $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
+ } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
+ $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
+ } else {
+ $ltitools{$newid}{'display'}{'target'} = 'iframe';
+ }
+ foreach my $item ('passback','roster') {
+ if ($env{'form.ltitools_'.$item.'_add'}) {
+ $ltitools{$newid}{$item} = 1;
+ if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
+ my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
+ $lifetime =~ s/^\s+|\s+$//g;
+ if ($lifetime =~ /^\d+\.?\d*$/) {
+ $ltitools{$newid}{$item.'valid'} = $lifetime;
+ }
+ }
+ }
+ }
+ if ($env{'form.ltitools_add_image.filename'} ne '') {
+ my ($imageurl,$error) =
+ &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_add_image',
+ $newid,$configuserok,$lonhost,$author_ok);
+ if ($imageurl) {
+ $ltitools{$newid}{'image'} = $imageurl;
+ }
+ if ($error) {
+ &Apache::lonnet::logthis($error);
+ $errors .= ''.$error.'';
+ }
+ }
+ my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
+ foreach my $field (@fields) {
+ if ($possfield{$field}) {
+ if ($field eq 'roles') {
+ foreach my $role (@courseroles) {
+ my $choice = $env{'form.ltitools_add_roles_'.$role};
+ if (($choice ne '') && ($posslti{$choice})) {
+ $ltitools{$newid}{'roles'}{$role} = $choice;
+ if ($role eq 'cc') {
+ $ltitools{$newid}{'roles'}{'co'} = $choice;
+ }
+ }
+ }
+ } else {
+ $ltitools{$newid}{'fields'}{$field} = 1;
+ }
+ }
+ }
+ if (ref($ltitools{$newid}{'fields'}) eq 'HASH') {
+ if ($ltitools{$newid}{'fields'}{'user'}) {
+ if ($env{'form.ltitools_add_userincdom'}) {
+ $ltitools{$newid}{'incdom'} = 1;
+ }
+ }
+ }
+ my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_add_courseconfig');
+ foreach my $item (@courseconfig) {
+ $ltitools{$newid}{'crsconf'}{$item} = 1;
+ }
+ if ($env{'form.ltitools_add_custom'}) {
+ my $name = $env{'form.ltitools_add_custom_name'};
+ my $value = $env{'form.ltitools_add_custom_value'};
+ $value =~ s/(`)/'/g;
+ $name =~ s/(`)/'/g;
+ $ltitools{$newid}{'custom'}{$name} = $value;
+ }
+ unless ($switchserver) {
+ my $keyitem = 'form.ltitools_add_key';
+ $env{$keyitem} =~ s/(`)/'/g;
+ if ($env{$keyitem} ne '') {
+ $ltitools{$newid}{'key'} = $env{$keyitem};
+ }
+ my $secretitem = 'form.ltitools_secret_add';
+ $env{$secretitem} =~ s/(`)/'/g;
+ if ($env{$secretitem} ne '') {
+ if ($privnum && $cipher) {
+ $ltitools{$newid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
+ $ltitools{$newid}{'cipher'} = $privnum;
+ } else {
+ $ltitools{$newid}{'secret'} = $env{$secretitem};
+ }
+ }
+ }
+ } else {
+ $errors .= ''.
+ &mt('Failed to acquire unique ID for new external tool').
+ '';
+ }
+ }
+ if (ref($values) eq 'HASH') {
+ my %deletions;
+ my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
+ if (@todelete) {
+ map { $deletions{$_} = 1; } @todelete;
+ }
+ my %customadds;
+ my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
+ if (@newcustom) {
+ map { $customadds{$_} = 1; } @newcustom;
+ }
+ my %imgdeletions;
+ my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
+ if (@todeleteimages) {
+ map { $imgdeletions{$_} = 1; } @todeleteimages;
+ }
+ my $maxnum = $env{'form.ltitools_maxnum'};
+ for (my $i=0; $i<=$maxnum; $i++) {
+ my $itemid = $env{'form.ltitools_id_'.$i};
+ $itemid =~ s/\D+//g;
+ if (ref($values->{$itemid}) eq 'HASH') {
+ if ($deletions{$itemid}) {
+ if ($values->{$itemid}{'image'}) {
+ #FIXME need to obsolete item in RES space
+ }
+ $haschanges{$itemid} = $values->{$itemid}{'title'};
+ next;
+ } else {
+ my $newpos = $env{'form.ltitools_'.$itemid};
+ $newpos =~ s/\D+//g;
+ foreach my $item ('title','url','lifetime') {
+ $ltitools{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
+ if ($values->{$itemid}{$item} ne $ltitools{$itemid}{$item}) {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
+ $ltitools{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
+ }
+ if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
+ $ltitools{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
+ }
+ if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
+ $ltitools{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
+ } else {
+ $ltitools{$itemid}{'sigmethod'} = 'HMAC-SHA1';
+ }
+ if ($values->{$itemid}{'sigmethod'} eq '') {
+ if ($ltitools{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
+ $haschanges{$itemid} = 1;
+ }
+ } elsif ($values->{$itemid}{'sigmethod'} ne $ltitools{$itemid}{'sigmethod'}) {
+ $haschanges{$itemid} = 1;
+ }
+ foreach my $size ('width','height') {
+ $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
+ $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
+ if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
+ $ltitools{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
+ if (ref($values->{$itemid}{'display'}) eq 'HASH') {
+ if ($values->{$itemid}{'display'}{$size} ne $ltitools{$itemid}{'display'}{$size}) {
+ $haschanges{$itemid} = 1;
+ }
+ } else {
+ $haschanges{$itemid} = 1;
+ }
+ } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
+ if ($values->{$itemid}{'display'}{$size} ne '') {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ }
+ foreach my $item ('linktext','explanation') {
+ $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
+ $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
+ if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
+ $ltitools{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
+ if (ref($values->{$itemid}{'display'}) eq 'HASH') {
+ if ($values->{$itemid}{'display'}{$item} ne $ltitools{$itemid}{'display'}{$item}) {
+ $haschanges{$itemid} = 1;
+ }
+ } else {
+ $haschanges{$itemid} = 1;
+ }
+ } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
+ if ($values->{$itemid}{'display'}{$item} ne '') {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ }
+ if ($env{'form.ltitools_target_'.$i} eq 'window') {
+ $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
+ } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
+ $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
+ } else {
+ $ltitools{$itemid}{'display'}{'target'} = 'iframe';
+ }
+ if (ref($values->{$itemid}{'display'}) eq 'HASH') {
+ if ($values->{$itemid}{'display'}{'target'} ne $ltitools{$itemid}{'display'}{'target'}) {
+ $haschanges{$itemid} = 1;
+ }
+ } else {
+ $haschanges{$itemid} = 1;
+ }
+ foreach my $extra ('passback','roster') {
+ if ($env{'form.ltitools_'.$extra.'_'.$i}) {
+ $ltitools{$itemid}{$extra} = 1;
+ if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
+ my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
+ $lifetime =~ s/^\s+|\s+$//g;
+ if ($lifetime =~ /^\d+\.?\d*$/) {
+ $ltitools{$itemid}{$extra.'valid'} = $lifetime;
+ }
+ }
+ }
+ if ($values->{$itemid}{$extra} ne $ltitools{$itemid}{$extra}) {
+ $haschanges{$itemid} = 1;
+ }
+ if ($values->{$itemid}{$extra.'valid'} ne $ltitools{$itemid}{$extra.'valid'}) {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
+ foreach my $item ('label','title','target','linktext','explanation','append') {
+ if (grep(/^\Q$item\E$/,@courseconfig)) {
+ $ltitools{$itemid}{'crsconf'}{$item} = 1;
+ if (ref($values->{$itemid}{'crsconf'}) eq 'HASH') {
+ if ($values->{$itemid}{'crsconf'}{$item} ne $ltitools{$itemid}{'crsconf'}{$item}) {
+ $haschanges{$itemid} = 1;
+ }
+ } else {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ }
+ my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
+ foreach my $field (@fields) {
+ if ($possfield{$field}) {
+ if ($field eq 'roles') {
+ foreach my $role (@courseroles) {
+ my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
+ if (($choice ne '') && ($posslti{$choice})) {
+ $ltitools{$itemid}{'roles'}{$role} = $choice;
+ if ($role eq 'cc') {
+ $ltitools{$itemid}{'roles'}{'co'} = $choice;
+ }
+ }
+ if (ref($values->{$itemid}{'roles'}) eq 'HASH') {
+ if ($values->{$itemid}{'roles'}{$role} ne $ltitools{$itemid}{'roles'}{$role}) {
+ $haschanges{$itemid} = 1;
+ }
+ } elsif ($ltitools{$itemid}{'roles'}{$role}) {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ } else {
+ $ltitools{$itemid}{'fields'}{$field} = 1;
+ if (ref($values->{$itemid}{'fields'}) eq 'HASH') {
+ if ($values->{$itemid}{'fields'}{$field} ne $ltitools{$itemid}{'fields'}{$field}) {
+ $haschanges{$itemid} = 1;
+ }
+ } else {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ }
+ }
+ if (ref($ltitools{$itemid}{'fields'}) eq 'HASH') {
+ if ($ltitools{$itemid}{'fields'}{'user'}) {
+ if ($env{'form.ltitools_userincdom_'.$i}) {
+ $ltitools{$itemid}{'incdom'} = 1;
+ }
+ if ($values->{$itemid}{'incdom'} ne $ltitools{$itemid}{'incdom'}) {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ }
+ $allpos[$newpos] = $itemid;
+ }
+ if ($imgdeletions{$itemid}) {
+ $haschanges{$itemid} = 1;
+ if ($context eq 'course') {
+ my $currimgurl = $values->{$itemid}{'image'};
+ if ($currimgurl =~ m{^(\Q/uploaded/$cdom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
+ my ($path,$imagefile) = ($1,$2);
+ if ($imagefile =~ /^tn\-(.+)$/) {
+ my $origimg = $1;
+ &Apache::lonnet::removeuploadedurl("$path/$origimg");
+ }
+ &Apache::lonnet::removeuploadedurl($currimgurl);
+ }
+ }
+ #FIXME need to obsolete item in RES space
+ } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
+ my $currimgurl = $values->{$itemid}{'image'};
+ my ($imgurl,$error) = &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_image_'.$i,
+ $itemid,$configuserok,$lonhost,$author_ok,$currimgurl);
+ if ($imgurl) {
+ $ltitools{$itemid}{'image'} = $imgurl;
+ $haschanges{$itemid} = 1;
+ }
+ if ($error) {
+ &Apache::lonnet::logthis($error);
+ $errors .= ''.$error.'';
+ }
+ } elsif ($values->{$itemid}{'image'}) {
+ $ltitools{$itemid}{'image'} = $values->{$itemid}{'image'};
+ }
+ if ($customadds{$i}) {
+ my $name = $env{'form.ltitools_custom_name_'.$i};
+ $name =~ s/(`)/'/g;
+ $name =~ s/^\s+//;
+ $name =~ s/\s+$//;
+ my $value = $env{'form.ltitools_custom_value_'.$i};
+ $value =~ s/(`)/'/g;
+ $value =~ s/^\s+//;
+ $value =~ s/\s+$//;
+ if ($name ne '') {
+ $ltitools{$itemid}{'custom'}{$name} = $value;
+ $haschanges{$itemid} = 1;
+ }
+ }
+ my %customdels;
+ my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
+ if (@customdeletions) {
+ $haschanges{$itemid} = 1;
+ }
+ map { $customdels{$_} = 1; } @customdeletions;
+ if (ref($values->{$itemid}{'custom'}) eq 'HASH') {
+ foreach my $key (keys(%{$values->{$itemid}{'custom'}})) {
+ unless ($customdels{$key}) {
+ if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
+ $ltitools{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
+ }
+ if ($values->{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ }
+ }
+ unless ($switchserver) {
+ my $keyitem = 'form.ltitools_key_'.$i;
+ $env{$keyitem} =~ s/(`)/'/g;
+ if ($values->{$itemid}{'key'} ne $env{$keyitem}) {
+ $haschanges{$itemid} = 1;
+ }
+ if ($env{$keyitem} ne '') {
+ $ltitools{$itemid}{'key'} = $env{$keyitem};
+ }
+ my $secretitem = 'form.ltitools_secret_'.$i;
+ $env{$secretitem} =~ s/(`)/'/g;
+ if ($values->{$itemid}{'usable'}) {
+ if ($env{'form.ltitools_changesecret_'.$i}) {
+ if ($env{$secretitem} ne '') {
+ if ($privnum && $cipher) {
+ $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
+ $ltitools{$itemid}{'cipher'} = $privnum;
+ } else {
+ $ltitools{$itemid}{'secret'} = $env{$secretitem};
+ }
+ $haschanges{$itemid} = 1;
+ }
+ } else {
+ $ltitools{$itemid}{'secret'} = $values->{$itemid}{'secret'};
+ $ltitools{$itemid}{'cipher'} = $values->{$itemid}{'cipher'};
+ }
+ } elsif ($env{$secretitem} ne '') {
+ if ($privnum && $cipher) {
+ $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
+ $ltitools{$itemid}{'cipher'} = $privnum;
+ } else {
+ $ltitools{$itemid}{'secret'} = $env{$secretitem};
+ }
+ $haschanges{$itemid} = 1;
+ }
+ }
+ unless ($haschanges{$itemid}) {
+ foreach my $key (keys(%{$values->{$itemid}})) {
+ if (ref($values->{$itemid}{$key}) eq 'HASH') {
+ if (ref($ltitools{$itemid}{$key}) eq 'HASH') {
+ foreach my $innerkey (keys(%{$values->{$itemid}{$key}})) {
+ unless (exists($ltitools{$itemid}{$key}{$innerkey})) {
+ $haschanges{$itemid} = 1;
+ last;
+ }
+ }
+ } elsif (keys(%{$values->{$itemid}{$key}}) > 0) {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ last if ($haschanges{$itemid});
+ }
+ }
+ }
+ }
+ }
+ if (@allpos > 0) {
+ my $idx = 0;
+ foreach my $itemid (@allpos) {
+ if ($itemid ne '') {
+ $ltitools{$itemid}{'order'} = $idx;
+ if (ref($values) eq 'HASH') {
+ if (ref($values->{$itemid}) eq 'HASH') {
+ if ($values->{$itemid}{'order'} ne $idx) {
+ $haschanges{$itemid} = 1;
+ }
+ }
+ }
+ $idx ++;
+ }
+ }
+ }
+ if (keys(%haschanges)) {
+ foreach my $entry (keys(%haschanges)) {
+ $changes->{$entry} = $ltitools{$entry};
+ }
+ if (ref($lastactref) eq 'HASH') {
+ $lastactref->{'courseltitools'} = 1;
+ }
+ }
+ return $errors;
+}
+
+sub process_ltitools_image {
+ my ($r,$context,$dom,$cnum,$confname,$caller,$itemid,$configuserok,$switch,$author_ok,$currimg) = @_;
+ my $filename = $env{'form.'.$caller.'.filename'};
+ my ($error,$url);
+ my ($width,$height) = (21,21);
+ if ($configuserok eq 'ok') {
+ if ($switch) {
+ $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
+ $switch);
+ } elsif ($author_ok eq 'ok') {
+ my ($result,$imageurl,$madethumb);
+ if ($context eq 'domain') {
+ ($result,$imageurl,$madethumb) =
+ &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
+ "ltitools/$itemid/icon",$width,$height);
+ } else {
+ ($result,$imageurl,$madethumb) = &processlogo($dom,$cnum,$caller,$currimg,$itemid,$width,$height);
+ }
+ if ($result eq 'ok') {
+ if ($madethumb) {
+ my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
+ my $imagethumb = "$path/tn-".$imagefile;
+ $url = $imagethumb;
+ } else {
+ $url = $imageurl;
+ }
+ } else {
+ if ($context eq 'domain') {
+ $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
+ } else {
+ $error = &mt("Upload of [_1] failed because an error occurred. Error was: [_2].",$filename,$result);
+ }
+ }
+ } else {
+ $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$filename,$confname,$dom,$author_ok);
+ }
+ } else {
+ $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$filename,$confname,$dom,$configuserok);
+ }
+ return ($url,$error);
+}
+
+sub processlogo {
+ my ($dom,$cnum,$caller,$currimg,$itemid,$width,$height) = @_;
+ my ($result,$imageurl,$madethumb);
+ if ($env{"form.$caller.filename"} ne '') {
+ unless ($caller eq 'ltitools_add_image') {
+ if ($currimg =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
+ my ($path,$imagefile) = ($1,$2);
+ if ($imagefile =~ /^tn\-(.+)$/) {
+ my $origimg = $1;
+ &Apache::lonnet::removeuploadedurl("$path/$origimg");
+ }
+ &Apache::lonnet::removeuploadedurl($currimg);
+ }
+ }
+ $imageurl = &Apache::lonnet::userfileupload($caller,'toollogo',"toollogo/$itemid",
+ '','','',$cnum,$dom,$width,$height);
+ if ($imageurl =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
+ my ($path,$imagefile) = ($1,$2);
+ $result = 'ok';
+ my $thumburl = "$path/tn-".$imagefile;
+ my ($rtncode,$info);
+ my $res = &Apache::lonnet::getuploaded('HEAD',$thumburl,$dom,$cnum,\$info,\$rtncode);
+ if ($res eq 'ok') {
+ $madethumb = 1;
+ }
+ } elsif ($imageurl eq '/adm/notfound.html') {
+ undef($imageurl);
+ $result = 'store failed';
+ } elsif ($imageurl =~ /^error: (.+)$/) {
+ $result = $1;
+ }
+ }
+ return ($result,$imageurl,$madethumb);
}
sub get_sec_str {
@@ -1115,8 +2465,15 @@ sub check_clone {
sub store_changes {
my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_;
my ($chome,$output);
- my (%storehash,@delkeys,@need_env_update,@oldcloner);
+ my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot,%oldltitools);
if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
+ if (ref($values->{'linkprot'}) eq 'HASH') {
+ %oldlinkprot = %{$values->{'linkprot'}};
+ }
+ delete($values->{'linkprot'});
+ if (ref($values->{'ltitools'}) eq 'HASH') {
+ %oldltitools = %{$values->{'ltitools'}};
+ }
%storehash = %{$values};
} else {
if ($crstype eq 'Community') {
@@ -1126,6 +2483,22 @@ sub store_changes {
}
return $output;
}
+ my ($numchanges,$skipstore);
+ if (ref($changes) eq 'HASH') {
+ $numchanges = scalar(keys(%{$changes}));
+ if (($numchanges == 1) && (exists($changes->{'linkprot'}))) {
+ $skipstore = 1;
+ } elsif (($numchanges == 1) && (exists($changes->{'ltitools'}))) {
+ $skipstore = 1;
+ } elsif (!$numchanges) {
+ if ($crstype eq 'Community') {
+ $output = &mt('No changes made to community settings.');
+ } else {
+ $output = &mt('No changes made to course settings.');
+ }
+ return $output;
+ }
+ }
my %yesno = (
hidefromcat => '1',
problem_stream_switch => '1',
@@ -1151,6 +2524,10 @@ sub store_changes {
"'$storehash{$key}'")).'';
}
}
+ } elsif ($item eq 'linkprot') {
+ $output .= &store_linkprot($cdom,$cnum,'course',$changes->{$item},\%oldlinkprot);
+ } elsif ($item eq 'ltitools') {
+ $output .= &store_ltitools($cdom,$cnum,'course',$changes->{$item},\%oldltitools);
} else {
if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
my @settings = @{$prefs->{$item}->{'ordered'}};
@@ -1182,14 +2559,88 @@ sub store_changes {
if ($msg ne '') {
$output .= ''.&Apache::lonhtmlcommon::confirm_success(&mt($displayname)).'';
}
+ } elsif ($key eq 'timezone') {
+ next unless ((exists($changes->{$item}{$key})) || (exists($changes->{$item}{'tzover'})));
+ my ($displayname,$text);
+ $text = $prefs->{$item}->{'itemtext'}{$key};
+ my $displayval;
+ if (exists($changes->{$item}{$key})) {
+ $displayname = &mt($text);
+ $storehash{$key} = $changes->{$item}{$key};
+ if ($changes->{$item}{$key} ne '') {
+ $displayval = ''.$changes->{$item}{$key}.'';
+ } else {
+ push(@delkeys,$key);
+ if (exists($values->{'tzover'})) {
+ push(@delkeys,'tzover');
+ }
+ $output .= ''.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
+ ''.$displayname.'')).'';
+ }
+ }
+ unless (grep(/^\Q$key\E$/,@delkeys)) {
+ if (exists($changes->{$item}{'tzover'})) {
+ $storehash{'tzover'} = $changes->{$item}{'tzover'};
+ my $tzovertext;
+ if ($changes->{$item}{'tzover'} ne '') {
+ $tzovertext = &mt('Course Time Zone overrides individual user preference');
+ } else {
+ push(@delkeys,'tzover');
+ $tzovertext = &mt('Course Time Zone does not override individual user preference');
+ }
+ if ($displayval eq '') {
+ $output .= ''.&Apache::lonhtmlcommon::confirm_success($tzovertext).'';
+ } else {
+ $displayval .= ' '.(' 'x5).$tzovertext;
+ }
+ }
+ if ($displayval ne '') {
+ $output .= ''.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
+ ''.$displayname.'',$displayval)).'';
+ }
+ }
} else {
next if (!exists($changes->{$item}{$key}));
my ($displayname,$text);
$text = $prefs->{$item}->{'itemtext'}{$key};
my $displayval;
- unless ($key eq 'co-owners') {
+ unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) {
$displayval = $changes->{$item}{$key};
}
+ if (($item eq 'grading') && ($key eq 'grading')) {
+ if ($displayval eq 'standard') {
+ my $hidetotals;
+ if (exists($changes->{$item}{'hidetotals'})) {
+ if ($changes->{$item}{'hidetotals'} eq '') {
+ if (exists($values->{'hidetotals'})) {
+ push(@delkeys,'hidetotals');
+ }
+ } else {
+ $hidetotals = $changes->{$item}{'hidetotals'};
+ }
+ } elsif (exists($values->{'hidetotals'})) {
+ $hidetotals = $values->{'hidetotals'};
+ }
+ if ($hidetotals eq '') {
+ $displayval = &mt('standard with "hide course totals" set to "No"');
+ if (exists($values->{'hidetotals'})) {
+ push(@delkeys,'hidetotals');
+ }
+ } elsif ($hidetotals =~ /^([\w,]+)$/) {
+ my $secstr = $1;
+ my @secs = split(/,/,$secstr);
+ if (grep(/^all$/,@secs)) {
+ $displayval = &mt('standard with "hide course totals" set to "Yes" for all users');
+ $hidetotals = 'all';
+ } else {
+ $displayval = &mt('standard with "hide course totals" set to "Yes" for users in section(s): [_1]',join(', ',@secs));
+ }
+ $storehash{'hidetotals'} = $hidetotals;
+ }
+ } elsif (exists($values->{'hidetotals'})) {
+ push(@delkeys,'hidetotals');
+ }
+ }
if ($item eq 'feedback') {
if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
$text = $prefs->{$item}->{'itemtext'}{$1.$2};
@@ -1223,6 +2674,36 @@ sub store_changes {
}
$displayval = join(', ',@longroles);
}
+ } elsif ($key eq 'discussion_post_fonts') {
+ my ($classorder,$classtitles)=&discussion_vote_classes();
+ my ($styleorder,$styleitems)=&discussion_vote_styles();
+ my $count = 1;
+ my $total = scalar(keys(%{$changes->{$item}}));
+ foreach my $class (@{$classorder}) {
+ $count ++;
+ next unless ($changes->{$item}{$key.'_'.$class});
+ my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
+ my $showval = '';
+ for (my $i=0; $i<@{$styleorder}; $i++) {
+ if ($vals[$i] ne '') {
+ $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
+ }
+ }
+ if ($vals[3] ne '') {
+ $showval .= $vals[3];
+ }
+ if ($showval ne '') {
+ $displayval .= $classtitles->{$class}.':{ '.
+ $showval.'}';
+ $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
+ } else {
+ $displayval .= $classtitles->{$class}.': '.&mt('None');
+ push(@delkeys,$key.'_'.$class);
+ }
+ unless ($count == $total) {
+ $displayval .= (' 'x2);
+ }
+ }
}
$displayname = &mt($text);
}
@@ -1237,6 +2718,16 @@ sub store_changes {
}
}
$displayname = &mt($text);
+ } elsif ($item eq 'menuitems') {
+ unless ($changes->{$item}{$key} eq '') {
+ if ($key eq 'menudefault') {
+ $displayname = &mt('Default collection of menu items');
+ $displayval = &mt('Collection: [_1]',
+ $changes->{$item}{$key});
+ } elsif ($key eq 'menucollections') {
+ $displayval = &menucollections_display($changes->{$item}{$key});
+ }
+ }
} else {
$displayname = &mt($text);
}
@@ -1249,12 +2740,44 @@ sub store_changes {
$displayval = &Apache::lonlocal::locallocaltime($displayval);
} elsif ($key eq 'categories') {
$displayval = $env{'form.categories_display'};
- } elsif ($key eq 'canuse_pdfforms') {
+ } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
+ ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
if ($changes->{$item}{$key} eq '1') {
$displayval = &mt('Yes');
} elsif ($changes->{$item}{$key} eq '0') {
$displayval = &mt('No');
}
+ } elsif ($key eq 'extresource') {
+ if ($changes->{$item}{$key} eq 'iframe') {
+ $displayval = &mt('In iframe');
+ } else {
+ my ($selected,$reuse,$width,$height) = split(/:/,$changes->{$item}{$key});
+ if ($selected eq 'tab') {
+ if ($reuse) {
+ $displayval = &mt('[_1]In tab[_2],[_3] and tab re-used for different external resources in course',
+ "'","'",' ');
+ } else {
+ $displayval = &mt('[_1]In tab[_2],[_3] with new tab for each external resource in course',
+ "'","'",' ');
+ }
+ } elsif ($selected eq 'window') {
+ if ($reuse) {
+ $displayval = &mt('[_1]In pop-up window[_2],[_3] and window re-used for different external resources in course',
+ "'","'",' ');
+ } else {
+ $displayval = &mt('[_1]In pop-up window[_2],[_3] with new window for each external resource in course',
+ "'","'",' ');
+ }
+ if (($width ne '') || ($height ne '')) {
+ if ($width ne '') {
+ $displayval .= ' '.&mt('Window width: [_1]px',$width);
+ }
+ if ($height ne '') {
+ $displayval .= ' '.&mt('Window height: [_1]px',$height);
+ }
+ }
+ }
+ }
}
if ($key eq 'co-owners') {
if (ref($changes->{$item}{$key}) eq 'HASH') {
@@ -1281,12 +2804,12 @@ sub store_changes {
}
}
unless (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
- if ($env{'form.pending_coowoner'} eq 'accept') {
+ if ($env{'form.pending_coowner'} eq 'accept') {
$displayval = &mt('on');
- } elsif ($env{'form.pending_coowoner'} eq 'decline') {
+ } elsif ($env{'form.pending_coowner'} eq 'decline') {
$displayval = '';
$output .= ''.&Apache::lonhtmlcommon::confirm_success(&mt('Invitation to be co-owner declined')).'';
- } elsif ($env{'form.remove_coowoner'}) {
+ } elsif ($env{'form.remove_coowner'}) {
$displayval = &mt('off');
}
if ($displayval) {
@@ -1299,12 +2822,25 @@ sub store_changes {
}
} elsif ($changes->{$item}{$key} eq '') {
push(@delkeys,$key);
- $output .= ''.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
- ''.$displayname.'')).'';
+ if ($item eq 'menuitems') {
+ if ($key eq 'menudefault') {
+ $output .= ''.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'';
+ } elsif ($key eq 'menucollections') {
+ $output .= ''.&mt('Specific collections of menus no longer available').'';
+ }
+ } else {
+ $output .= ''.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
+ ''.$displayname.'')).'';
+ }
+ } elsif ($key eq 'menucollections') {
+ $output .= ''.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).' '.
+ $displayval.'';
} else {
+ unless (($key eq 'extresource') && ($changes->{$item}{$key} ne 'iframe')) {
+ $displayval = "'$displayval'";
+ }
$output .= ''.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
- ''.$displayname.'',
- "'$displayval'"));
+ ''.$displayname.'',$displayval));
if ($key eq 'url') {
my $bkuptime=time;
$output .= (' 'x2).&mt('(Previous URL backed up)').': '.
@@ -1322,7 +2858,9 @@ sub store_changes {
}
}
} else {
- $storehash{$key} = $changes->{$item}{$key};
+ unless ($key eq 'discussion_post_fonts') {
+ $storehash{$key} = $changes->{$item}{$key};
+ }
}
}
if ($key eq 'cloners') {
@@ -1346,14 +2884,17 @@ sub store_changes {
$output .= '';
} else {
if ($crstype eq 'Community') {
- $output = &mt('No changes made to community settings.');
+ $output .= &mt('No changes made to community settings.');
} else {
- $output = &mt('No changes made to course settings.');
+ $output .= &mt('No changes made to course settings.');
}
}
}
}
}
+ if ($skipstore) {
+ return $output;
+ }
if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
if (ref($changes) eq 'HASH') {
if (ref($changes->{'courseinfo'}) eq 'HASH') {
@@ -1396,6 +2937,378 @@ sub store_changes {
return $output;
}
+sub store_linkprot {
+ my ($cdom,$cnum,$context,$changes,$oldlinkprot) = @_;
+ my ($ltiauth,$home,$lti_save_error,$output,$error,%ltienc,@deletions);
+ if ($context eq 'domain') {
+ $ltiauth = 1;
+ $home = &Apache::lonnet::domain($cdom,'primary');
+ } else {
+ $home = &Apache::lonnet::homeserver($cnum,$cdom);
+ if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
+ $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
+ } else {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
+ $ltiauth = $domdefs{'crsltiauth'};
+ }
+ }
+ if (ref($changes) eq 'HASH') {
+ foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
+ if (ref($changes->{$id}) eq 'HASH') {
+ if (exists($changes->{$id}->{'key'})) {
+ $ltienc{$id}{'key'} = $changes->{$id}->{'key'};
+ delete($changes->{$id}->{'key'});
+ }
+ if (exists($changes->{$id}->{'secret'})) {
+ $ltienc{$id}{'secret'} = $changes->{$id}->{'secret'};
+ delete($changes->{$id}->{'secret'});
+ } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
+ if (exists($oldlinkprot->{$id}{'usable'})) {
+ $changes->{$id}->{'usable'} = 1;
+ }
+ if (exists($oldlinkprot->{$id}{'cipher'})) {
+ $changes->{$id}->{'cipher'} = $oldlinkprot->{$id}{'cipher'};
+ }
+ }
+ }
+ }
+ }
+ my @ids=&Apache::lonnet::current_machine_ids();
+ if (keys(%ltienc) > 0) {
+ if ($context eq 'domain') {
+ foreach my $id (keys(%ltienc)) {
+ if (exists($ltienc{$id}{'secret'})) {
+ $changes->{$id}->{'usable'} = 1;
+ }
+ }
+ } else {
+ unless (($home eq 'no_host') || ($home eq '')) {
+ my $allowed;
+ foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
+ if ($allowed) {
+ if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') {
+ foreach my $id (keys(%ltienc)) {
+ if (exists($ltienc{$id}{'secret'})) {
+ $changes->{$id}->{'usable'} = 1;
+ }
+ }
+ } else {
+ $lti_save_error = 1;
+ }
+ }
+ }
+ }
+ }
+ unless ($lti_save_error) {
+ if ($context eq 'course') {
+ if (&Apache::lonnet::put('lti',$changes,$cdom,$cnum,1) eq 'ok') {
+ my $hashid=$cdom.'_'.$cnum;
+ &Apache::lonnet::devalidate_cache_new('courselti',$hashid);
+ unless (($home eq 'no_host') || ($home eq '')) {
+ if (grep(/^\Q$home\E$/,@ids)) {
+ &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid);
+ }
+ }
+ } else {
+ $lti_save_error = 1;
+ }
+ }
+ unless ($lti_save_error) {
+ foreach my $id (sort { $a <=> $b } %{$changes}) {
+ if (ref($changes->{$id}) eq 'HASH') {
+ my %values = %{$changes->{$id}};
+ my %desc = &linkprot_names();
+ my $display;
+ foreach my $title ('name','lifetime','version','key','secret','returnurl','passbackformat') {
+ if (($title eq 'key') || ($title eq 'secret')) {
+ if (ref($ltienc{$id}) eq 'HASH') {
+ if (exists($ltienc{$id}{$title})) {
+ if ($title eq 'secret') {
+ my $length = length($ltienc{$id}{$title});
+ $display .= $desc{$title}.': ['.&mt('not shown').'], ';
+ } else {
+ $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', ';
+ }
+ }
+ }
+ } elsif ($title eq 'version') {
+ if ($values{$title} eq 'LTI-1p0') {
+ $display .= $desc{$title}.': 1.1, ';
+ }
+ } elsif ($title eq 'returnurl') {
+ if ($values{$title}) {
+ $display .= &mt('Return URL parameter').': '.$values{$title}.', ';
+ }
+ } elsif ($title eq 'passbackformat') {
+ if ($values{$title} eq '1.0') {
+ $display .= &mt('Can return grades to Launcher with Outcomes Service 1.0 format').', ';
+ } elsif ($values{$title} eq '1.1') {
+ $display .= &mt('Can return grades to Launcher with Outcomes Service 1.1 format').', ';
+ }
+ } else {
+ $display .= $desc{$title}.': '.$values{$title}.', ';
+ }
+ }
+ if ($ltiauth) {
+ if (($values{'requser'}) && ($values{'mapuser'} ne '')) {
+ if ($values{'mapuser'} eq 'lis_person_contact_email_primary') {
+ $display .= &mt('Source of username: Email address [_1]',
+ '(lis_person_contact_email_primary)').', ';
+ } elsif ($values{'mapuser'} eq 'lis_person_sourcedid') {
+ $display .= &mt('Source of username: User ID [_1]',
+ '(lis_person_sourcedid)').', ';
+ } else {
+ $display .= &mt('Source of username: [_1]',$values{'mapuser'}).', ';
+ }
+ if ($values{'notstudent'} eq 'auth') {
+ $display .= &mt('Display LON-CAPA login page if no match').', ';
+ } elsif ($values{'notstudent'} eq 'reject') {
+ $display .= &mt('Discontinue launch if no match').', ';
+ }
+ }
+ }
+ $display =~ s/, $//;
+ $output .= ''.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',''.$id.'',
+ "'$display'")).'';
+ } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
+ my $oldname = $oldlinkprot->{$id}{'name'};
+ $output .= ''.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',''."$id ($oldname)".'')).'';
+ }
+ }
+ } else {
+ $lti_save_error = 1;
+ }
+ }
+ unless ($lti_save_error) {
+ foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
+ unless (ref($changes->{$id}) eq 'HASH') {
+ push(@deletions,$id);
+ }
+ }
+ if (@deletions) {
+ if ($context eq 'course') {
+ &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum);
+ }
+ }
+ }
+ if ($lti_save_error) {
+ $output .= ''.
+ ''.
+ &mt('An error occurred when saving changes to link protection settings, which remain unchanged.').
+ ''.
+ '';
+ }
+ return $output;
+}
+
+sub store_ltitools {
+ my ($cdom,$cnum,$context,$changes,$oldltitools) = @_;
+ my ($home,$ltitools_save_error,$output,$error,%toolsenc,@deletions);
+ my %lt = <itools_names();
+ my @courseroles = ('cc','in','ta','ep','st');
+ my @allfields = ('fullname','firstname','lastname','email','user','roles');
+ if ($context eq 'domain') {
+ $home = &Apache::lonnet::domain($cdom,'primary');
+ } else {
+ $home = &Apache::lonnet::homeserver($cnum,$cdom);
+ }
+ if (ref($changes) eq 'HASH') {
+ foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
+ if (ref($changes->{$id}) eq 'HASH') {
+ if (exists($changes->{$id}->{'key'})) {
+ $toolsenc{$id}{'key'} = $changes->{$id}->{'key'};
+ delete($changes->{$id}->{'key'});
+ }
+ if (exists($changes->{$id}->{'secret'})) {
+ $toolsenc{$id}{'secret'} = $changes->{$id}->{'secret'};
+ delete($changes->{$id}->{'secret'});
+ } elsif (ref($oldltitools->{$id}) eq 'HASH') {
+ if (exists($oldltitools->{$id}{'usable'})) {
+ $changes->{$id}->{'usable'} = 1;
+ }
+ if (exists($oldltitools->{$id}{'cipher'})) {
+ $changes->{$id}->{'cipher'} = $oldltitools->{$id}{'cipher'};
+ }
+ }
+ }
+ }
+ }
+ my @ids=&Apache::lonnet::current_machine_ids();
+ if (keys(%toolsenc) > 0) {
+ unless (($home eq 'no_host') || ($home eq '')) {
+ my $allowed;
+ foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
+ if ($allowed) {
+ if (($context eq 'domain') ||
+ (($context eq 'course') &&
+ (&Apache::lonnet::put('nohist_toolsenc',\%toolsenc,$cdom,$cnum,1) eq 'ok'))) {
+ foreach my $id (keys(%toolsenc)) {
+ if (exists($toolsenc{$id}{'secret'})) {
+ $changes->{$id}->{'usable'} = 1;
+ }
+ }
+ } else {
+ $ltitools_save_error = 1;
+ }
+ }
+ }
+ }
+ unless ($ltitools_save_error) {
+ if ($context eq 'course') {
+ if (&Apache::lonnet::put('ltitools',$changes,$cdom,$cnum,1) eq 'ok') {
+ my $hashid=$cdom.'_'.$cnum;
+ &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
+ unless (($home eq 'no_host') || ($home eq '')) {
+ if (grep(/^\Q$home\E$/,@ids)) {
+ &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
+ }
+ }
+ } else {
+ $ltitools_save_error = 1;
+ }
+ }
+ unless ($ltitools_save_error) {
+ my %bynum;
+ foreach my $itemid (sort(keys(%{$changes}))) {
+ my $position = $changes->{$itemid}{'order'};
+ $bynum{$position} = $itemid;
+ }
+ foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
+ my $itemid = $bynum{$pos};
+ if (ref($changes->{$itemid}) ne 'HASH') {
+ $output .= ''.&mt('Deleted: [_1]',$changes->{$itemid}).'';
+ } else {
+ $output .= ''.$changes->{$itemid}{'title'}.'';
+ if ($changes->{$itemid}{'image'}) {
+ $output .= ' '.
+ '';
+ }
+ $output .= '';
+ my $position = $pos + 1;
+ $output .= '- '.&mt('Order: [_1]',$position).'
';
+ foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
+ if ($changes->{$itemid}{$item} ne '') {
+ $output .= '- '.$lt{$item}.': '.$changes->{$itemid}{$item}.'
';
+ }
+ }
+ if (ref($toolsenc{$itemid}) eq 'HASH') {
+ foreach my $item ('key','secret') {
+ if (exists($toolsenc{$itemid}{$item})) {
+ if ($item eq 'secret') {
+ $output .= '- '.$lt{$item}.': ['.&mt('not shown').']
';
+ } else {
+ $output .= '- '.$lt{$item}.': '.$toolsenc{$itemid}{$item}.'
';
+ }
+ }
+ }
+ }
+ $output .= '- '.&mt('Configurable in course:');
+ my @possconfig = ('label','title','target','linktext','explanation','append');
+ my $numconfig = 0;
+ if (ref($changes->{$itemid}{'crsconf'}) eq 'HASH') {
+ foreach my $item (@possconfig) {
+ if ($changes->{$itemid}{'crsconf'}{$item}) {
+ $numconfig ++;
+ $output .= ' "'.$lt{'crs'.$item}.'"';
+ }
+ }
+ }
+ if (!$numconfig) {
+ $output .= ' '.&mt('None');
+ }
+ $output .= '
';
+ foreach my $item ('passback','roster') {
+ $output .= '- '.$lt{$item}.' ';
+ if ($changes->{$itemid}{$item}) {
+ $output .= &mt('Yes');
+ if ($changes->{$itemid}{$item.'valid'}) {
+ if ($item eq 'passback') {
+ $output .= ' '.&mt('valid for at least [quant,_1,day] after launch',
+ $changes->{$itemid}{$item.'valid'});
+ } else {
+ $output .= ' '.&mt('valid for at least [quant,_1,second] after launch',
+ $changes->{$itemid}{$item.'valid'});
+ }
+ }
+ } else {
+ $output .= &mt('No');
+ }
+ $output .= '
';
+ }
+ if (ref($changes->{$itemid}{'display'}) eq 'HASH') {
+ my $displaylist;
+ if ($changes->{$itemid}{'display'}{'target'}) {
+ $displaylist = &mt('Display target').': '.
+ $changes->{$itemid}{'display'}{'target'}.',';
+ }
+ foreach my $size ('width','height') {
+ if ($changes->{$itemid}{'display'}{$size}) {
+ $displaylist .= (' 'x2).$lt{$size}.': '.
+ $changes->{$itemid}{'display'}{$size}.',';
+ }
+ }
+ if ($displaylist) {
+ $displaylist =~ s/,$//;
+ $output .= '- '.$displaylist.'
';
+ }
+ foreach my $item ('linktext','explanation') {
+ if ($changes->{$itemid}{'display'}{$item}) {
+ $output .= '- '.$lt{$item}.': '.$changes->{$itemid}{'display'}{$item}.'
';
+ }
+ }
+ }
+ if (ref($changes->{$itemid}{'fields'}) eq 'HASH') {
+ my $fieldlist;
+ foreach my $field (@allfields) {
+ if ($changes->{$itemid}{'fields'}{$field}) {
+ $fieldlist .= (' 'x2).$lt{$field}.',';
+ }
+ }
+ if ($fieldlist) {
+ $fieldlist =~ s/,$//;
+ if ($changes->{$itemid}{'fields'}{'user'}) {
+ if ($changes->{$itemid}{'incdom'}) {
+ $fieldlist .= ' ('.&mt('username:domain').')';
+ } else {
+ $fieldlist .= ' ('.&mt('username').')';
+ }
+ }
+ $output .= '- '.&mt('Data sent').':'.$fieldlist.'
';
+ }
+ }
+ if (ref($changes->{$itemid}{'roles'}) eq 'HASH') {
+ my $rolemaps;
+ foreach my $role (@courseroles) {
+ if ($changes->{$itemid}{'roles'}{$role}) {
+ $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
+ $changes->{$itemid}{'roles'}{$role}.',';
+ }
+ }
+ if ($rolemaps) {
+ $rolemaps =~ s/,$//;
+ $output .= '- '.&mt('Role mapping:').$rolemaps.'
';
+ }
+ }
+ if (ref($changes->{$itemid}{'custom'}) eq 'HASH') {
+ my $customlist;
+ if (keys(%{$changes->{$itemid}{'custom'}})) {
+ foreach my $key (sort(keys(%{$changes->{$itemid}{'custom'}}))) {
+ $customlist .= $key.':'.$changes->{$itemid}{'custom'}{$key}.(' 'x2);
+ }
+ }
+ if ($customlist) {
+ $output .= '- '.&mt('Custom items').': '.$customlist.'
';
+ }
+ }
+ $output .= ' ';
+ }
+ }
+ }
+ }
+ return $output;
+}
+
sub update_env {
my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
my $count = 0;
@@ -1519,16 +3432,103 @@ sub get_course {
}
my $cdom=$env{'course.'.$courseid.'.domain'};
my $cnum=$env{'course.'.$courseid.'.num'};
- return ($cnum,$cdom);
+ my $chome=$env{'course.'.$courseid.'.home'};
+ return ($cnum,$cdom,$chome);
}
sub get_jscript {
- my ($cid,$cdom,$phase,$crstype) = @_;
+ my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
- my ($jscript,$categorize_js,$loncaparev_js);
+ my ($jscript,$categorize_js,$loncaparev_js,$instcode_js,$extresource_js,$localization_js);
my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
my $cloners_js = &cloners_javascript($phase);
+ my $currltitools;
+ if (ref($settings) eq 'HASH') {
+ $currltitools = $settings->{'ltitools'};
+ }
+ my $ltitools_js = &Apache::lonconfigsettings::ltitools_javascript($currltitools);
+ my @code_order;
+ if ($crstype ne 'Community') {
+ if (ref($settings) eq 'HASH') {
+ my %codedefaults;
+ &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
+ \@code_order);
+ if (@code_order > 0) {
+ if ($phase eq 'display') {
+ my @actions = &Apache::loncommon::get_env_multiple('form.actions');
+ if (grep(/^courseinfo$/,@actions)) {
+ if ($settings->{'cloners'} ne '') {
+ unless ($settings->{'cloners'} eq '*') {
+ my @cloners = split(/,/,$settings->{'cloners'});
+ my @standardnames = &Apache::loncommon::get_standard_codeitems();
+ my %local_to_standard;
+ for (my $i=0; $i<@code_order; $i++) {
+ $local_to_standard{$code_order[$i]} = $standardnames[$i];
+ }
+ foreach my $cloner (@cloners) {
+ if (($cloner !~ /^\Q*:\E$match_domain$/) &&
+ ($cloner !~ /^$match_username\:$match_domain$/)) {
+ foreach my $item (split(/\&/,$cloner)) {
+ my ($key,$val) = split(/\=/,$item);
+ $val = &unescape($val);
+ foreach my $code (@code_order) {
+ if ($key eq $local_to_standard{$code}) {
+ $env{'form.'.$key} = $val;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ my @codetitles;
+ (undef,$instcode_js) =
+ &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
+ \@codetitles);
+ $instcode_js .= <{'menucollections'} ne '') {
+ my @current;
+ foreach my $item (split(/;/,$settings->{'menucollections'})) {
+ my ($num) = split(/\%/,$item);
+ if ($num =~ /^\d+$/) {
+ push(@current,$num);
+ }
+ }
+ $collections = join("','",sort { $a <=> $b } @current);
+ if ($collections) {
+ $collections = "'$collections'";
+ }
+ $next += $current[-1];
+ }
+ }
+ my $deftext = &mt('Standard (all menus shown)');
+ $menuitems_js = < 0) {
+ var setvis;
+ for (var i=0; i'."\n".
+ '// '."\n".$stubrowse_js."\n";
+ $cloners_js."\n".$instcode_js."\n".$localization_js."\n".
+ $syllabus_js."\n".$menuitems_js."\n".$extresource_js."\n".
+ $grading_js."\n".&linkprot_javascript()."\n".'//]]>'."\n".
+ ''."\n".$stubrowse_js."\n".$ltitools_js."\n";
return $jscript;
}
@@ -1592,7 +3775,7 @@ function update_cloners(caller,num) {
if (document.$formname.cloners_activate[i].value == '0') {
document.$formname.cloners_activate[i].checked = false;
}
- if (document.$formname.cloners_activate[i].value == '') {
+ if (document.$formname.cloners_activate[i].value == '-1') {
document.$formname.cloners_activate[i].checked = true;
}
}
@@ -1643,31 +3826,114 @@ function getIndexByName(item) {
ENDSCRIPT
}
+sub linkprot_javascript {
+ return <<"ENDSCRIPT";
+function toggleLinkProtExtra(form,item,extra,valon,styleon,num) {
+ if (document.getElementById('linkprot_'+extra+'_'+num)) {
+ var extraid = document.getElementById('linkprot_'+extra+'_'+num);
+ var itemname = form.elements['linkprot_'+item+'_'+num];
+ if (itemname) {
+ if (itemname.length > 0) {
+ var setvis;
+ for (var i=0; i{'categories'},$crstype)."\n";
+ $settings->{'categories'},$crstype,$disabled)."\n";
}
}
if (ref($domconf{'autoenroll'}) eq 'HASH') {
$autocoowner = $domconf{'autoenroll'}{'co-owners'};
}
+ my ($currcanclone,@code_order,$cloner_instcode);
+ my %codedefaults;
+ &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
+ \@code_order);
+ if ($settings->{'cloners'}) {
+ unless ($settings->{'cloners'} eq '*') {
+ my @currclone = split(/,/,$settings->{'cloners'});
+ foreach my $item (@currclone) {
+ unless ($item eq '*') {
+ if (($item !~ /\:/) && ($item =~ /=/)) {
+ $cloner_instcode = 1;
+ }
+ }
+ }
+ }
+ }
+ if (ref($domconf{'coursedefaults'}) eq 'HASH') {
+ my $canclone = $domconf{'coursedefaults'}{'canclone'};
+ if (ref($canclone) eq 'HASH') {
+ if (ref($canclone->{'instcode'}) eq 'ARRAY') {
+ if ($settings->{'internal.coursecode'}) {
+ my @posscodes;
+ if (@code_order > 0) {
+ $currcanclone = 'instcode';
+ foreach my $item (@{$canclone->{'instcode'}}) {
+ if (grep(/^\Q$item\E$/,@code_order)) {
+ push(@posscodes,$item);
+ }
+ }
+ my $codestr = join(' + ',@posscodes);
+ $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
+ '"'.$codestr.'"').' ';
+ }
+ }
+ }
+ } elsif ($canclone eq 'domain') {
+ $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
+ ''.$cdom.'').' ';
+ $currcanclone = 'domain';
+ }
+ if ($clonedefaults) {
+ if ($settings->{'cloners'} ne '') {
+ $clonedefaults .= ' '.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','','');
+ } else {
+ $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','','');
+ }
+ $clonedefaults = '
'.$clonedefaults;
+ }
+ }
if (!defined($categoriesform)) {
$categoriesform = &mt('No categories defined in this domain.');
}
-
my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $replace;
if ($crstype eq 'Community') {
@@ -1675,22 +3941,28 @@ sub print_courseinfo {
} else {
$replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
}
+ my ($editmap,$editsyllabus);
+ unless ($noedit) {
+ $editmap = (' 'x2).
+ '".
+ &mt('Select Map').' '.
+ &mt('Modification may make assessment data inaccessible!').
+ '';
+ $editsyllabus = &mt('[_1]Edit[_2]','',
+ '');
+ }
my %items = (
'url' => {
- text => ''.&mt($itemtext->{'url'}).''.(' 'x2).
- '".
- &mt('Select Map').' '.
- &mt('Modification may make assessment data inaccessible!').
- '',
+ text => ''.&mt($itemtext->{'url'}).''.$editmap,
input => 'textbox',
- size => '40',
+ size => '55',
advanced => 1
},
'description' => {
text => ''.&mt($itemtext->{'description'}).'',
input => 'textbox',
- size => '25',
+ size => '55',
},
'owner' => {
text => ''.&mt($itemtext->{'owner'}).'',
@@ -1698,18 +3970,24 @@ sub print_courseinfo {
'co-owners' => {
text => ''.&mt($itemtext->{'co-owners'}).'',
},
+ 'clonedfrom' => {
+ text => ''.&mt($itemtext->{'clonedfrom'}).'',
+ },
'courseid' => {
text => ''.&mt($itemtext->{'courseid'}).' '.'('.
&mt('internal, optional').')',
input => 'textbox',
size => '25',
},
+ 'uniquecode' => {
+ text => ''.&mt($itemtext->{'uniquecode'}).'',
+ },
'cloners' => {
text => ''.&mt($itemtext->{'cloners'}).' '.
- &mt('Owner and Coordinators included automatically'),
+ &mt('Owner and Coordinators included automatically').
+ $clonedefaults,
input => 'textbox',
- size => '40',
- advanced => 1
+ size => '40'
},
'rolenames' => {
text => ''.&mt($itemtext->{'rolenames'}).' '.
@@ -1718,11 +3996,10 @@ sub print_courseinfo {
size => '20',
advanced => 1
},
- 'externalsyllabus' => {
- text => ''.&mt($itemtext->{'externalsyllabus'}).' ('.
- &mt('not using syllabus template)'),
- input => 'textbox',
- size => '40',
+ 'syllabus' => {
+ text => ''.&mt($itemtext->{'syllabus'}).' '.
+ &mt('(Syllabus type in use)').(' ' x2).
+ $editsyllabus,
},
'hidefromcat' => {
text => ''.&mt($itemtext->{'hidefromcat'}).' '.
@@ -1738,27 +4015,37 @@ sub print_courseinfo {
'loncaparev' => {
text => ''.&mt($itemtext->{'loncaparev'}).'',
},
+ 'defaultcredits' => {
+ text => ''.&mt($itemtext->{'defaultcredits'}).'',
+ },
);
my $datatable;
my $count = 0;
foreach my $item (@{$ordered}) {
+ my $colspan;
if ($item eq 'hidefromcat') {
next if (!$can_toggle_cat);
} elsif ($item eq 'categories') {
next if (!$can_categorize);
+ } elsif ($item eq 'uniquecode') {
+ next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'});
+ }
+ unless (($item eq 'cloners') || ($item eq 'rolenames')) {
+ $colspan = 2;
}
$count ++;
if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) {
- $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced");
+ $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced",$colspan);
} else {
- $datatable .= &item_table_row_start($items{$item}{text},$count);
+ $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
}
if ($items{$item}{input} eq 'radio') {
- $datatable .= &yesno_radio($item,$settings);
+ $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
} elsif ($item eq 'cloners') {
my $includeempty = 1;
my $num = 0;
- $datatable .= &Apache::loncommon::start_data_table().
+ $datatable .= ' | '.
+ &Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_row().
' | '.
- (' 'x2).''.&mt('Yes').''.
+ (' 'x2).' | '.
+ "'cloners_all'".');"'.$disabled.' />'.&mt('No').''.
&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table().
- ''.
+ ''.
&Apache::loncommon::start_data_table();
my @cloners;
if ($settings->{$item} eq '') {
- $datatable .= &new_cloners_dom_row($cdom,'0');
+ unless ($noedit) {
+ my $default;
+ if ($currcanclone eq 'domain') {
+ $default = '0';
+ }
+ $datatable .= &new_cloners_dom_row($cdom,'0',$default);
+ }
} elsif ($settings->{$item} ne '*') {
my @entries = split(/,/,$settings->{$item});
if (@entries > 0) {
@@ -1802,7 +4096,7 @@ sub print_courseinfo {
'
'.
''.
&Apache::loncommon::end_data_table_row();
$num ++;
@@ -1825,23 +4119,56 @@ sub print_courseinfo {
''.
$add_domtitle.' '.
&Apache::loncommon::select_dom_form('','cloners_newdom',
- $includeempty).
+ $includeempty,undef,undef,
+ undef,undef,$noedit).
''.
' | '.&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table().
- ''.
+ ''.
&Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_row().
''.
&mt('Specific users').' ('.
&mt('user:domain,user:domain').') '.
&Apache::lonhtmlcommon::textbox($item,$cloners_str,
- $items{$item}{'size'}).
+ $items{$item}{'size'},$disabled).
' | '.&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table();
+ if (@code_order > 0) {
+ my (%cat_items,@codetitles,%cat_titles,%cat_order);
+ my ($jscript,$totcodes,$numtitles,$lasttitle) =
+ &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
+ \%cat_items,\@codetitles,
+ \%cat_titles,\%cat_order);
+ my $showncodes = 'off';
+ my $checkedoff = ' checked="checked"';
+ my $checkedon = '';
+ if ($cloner_instcode) {
+ $checkedon = $checkedoff;
+ $checkedoff = '';
+ $showncodes = 'on';
+ }
+ $datatable .= ''.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_row().
+ ''.
+ &mt('Cloning by official course(s) based on course category').(' 'x2).
+ ''.
+ (' ').
+ ''.
+ &Apache::courseclassifier::build_instcode_selectors($numtitles,
+ $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
+ $showncodes,'LC_cloners_instcodes','LC_cloners_instcode',$noedit).
+ ' | '.&Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table();
+ }
} elsif ($item eq 'rolenames') {
- $datatable .= &Apache::loncommon::start_data_table();
+ $datatable .= ''.
+ &Apache::loncommon::start_data_table();
my @roles;
if ($crstype eq 'Community') {
@roles = ('co');
@@ -1856,12 +4183,17 @@ sub print_courseinfo {
' | '.
&Apache::lonhtmlcommon::textbox('rolenames_'.$role,
$settings->{$role.'.plaintext'},
- $items{$item}{size}).' | '.
+ $items{$item}{size},$disabled).''.
&Apache::loncommon::end_data_table_row();
}
$datatable .= &Apache::loncommon::end_data_table().'';
} elsif ($item eq 'categories') {
- my $launcher = 'onFocus="this.blur();javascript:catsbrowser();";';
+ my $launcher;
+ if ($noedit) {
+ $launcher = $disabled;
+ } else {
+ $launcher = 'onfocus="this.blur();javascript:catsbrowser();"';
+ }
$datatable .= ''.
&Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
$items{$item}{size},$launcher);
@@ -1876,8 +4208,22 @@ sub print_courseinfo {
$owner = &mt('None specified');
}
$datatable .= $owner;
+ } elsif ($item eq 'clonedfrom') {
+ my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
+ my $clonedfrom = &mt('None');
+ if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
+ my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
+ if ($clonesrcinfo{'description'}) {
+ $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
+ }
+ }
+ $datatable .= $clonedfrom;
+ } elsif ($item eq 'uniquecode') {
+ my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'};
+ if ($code) {
+ $datatable .= $code;
+ }
} elsif ($item eq 'co-owners') {
- my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $coowners = $env{'course.'.$env{'request.course.id'}.'.internal.co-owners'};
my @currcoown;
if ($coowners) {
@@ -1887,15 +4233,45 @@ sub print_courseinfo {
if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
$datatable .= &show_autocoowners(@currcoown);
} else {
- $datatable .= &coowner_invitations($cnum,$cdom,@currcoown);
+ $datatable .= &coowner_invitations($cnum,$cdom,\@currcoown,$noedit);
}
} else {
if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
$datatable .= &show_autocoowners(@currcoown);
} else {
- $datatable .= &manage_coownership($cnum,$cdom,@currcoown);
+ $datatable .= &manage_coownership($cnum,$cdom,\@currcoown,$noedit);
}
}
+ } elsif ($item eq 'syllabus') {
+ my $external = $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'};
+ my $uploaded = $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'};
+ my $minimal = $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'};
+ if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
+ if ($minimal =~/\w/) {
+ if ($external =~ m{\Q$minimal\E$}) {
+ undef($external);
+ }
+ } elsif ($uploaded =~/\w/) {
+ if ($external =~ m{\Q$uploaded\E$}) {
+ undef($external);
+ }
+ }
+ } elsif ($external!~/\w/) {
+ undef($external);
+ }
+ if ($external) {
+ $datatable .= &mt('External URL');
+ } elsif ($minimal) {
+ $datatable .= &mt('Minimal template');
+ } elsif ($uploaded) {
+ $datatable .= &mt('Uploaded file');
+ } else {
+ $datatable .= &mt('Standard template');
+ }
+ $datatable .= (' ' x 2).
+ &mt('[_1]View[_2]',
+ '',
+ '');
} elsif ($item eq 'loncaparev') {
my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
my $showreqd;
@@ -1907,7 +4283,7 @@ sub print_courseinfo {
}
$datatable .= $showreqd;
} else {
- $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size});
+ $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size},$disabled);
}
$datatable .= &item_table_row_end();
}
@@ -1916,19 +4292,24 @@ sub print_courseinfo {
}
sub new_cloners_dom_row {
- my ($newdom,$num) = @_;
- my $output;
+ my ($newdom,$num,$default) = @_;
+ my ($output,$checkedon,$checkedoff);
if ($newdom ne '') {
+ if ($num eq $default) {
+ $checkedon = 'checked="checked" ';
+ } else {
+ $checkedoff = 'checked="checked" ';
+ }
$output .= &Apache::loncommon::start_data_table_row().
''.
&mt('Any user in domain:').' '.$newdom.''.
(' 'x2).''.(' 'x2).
'
@@ -2065,6 +4447,7 @@ ENDSCRIPT
sub display_loncaparev_constraints {
my ($r,$navmap,$loncaparev,$crstype) = @_;
+ my ($reqdmajor,$reqdminor);
my $cid = $env{'request.course.id'};
my $cdom = $env{'course.'.$cid.'.domain'};
my $cnum = $env{'course.'.$cid.'.num'};
@@ -2074,25 +4457,45 @@ sub display_loncaparev_constraints {
'section/group' => 'section/group',
'user' => 'user',
);
- my (%checkparms,%checkresponsetypes,%checkcrstypes,%anonsurvey,%randomizetry);
- &Apache::loncommon::build_release_hashes(\%checkparms,\%checkresponsetypes,
- \%checkcrstypes,\%anonsurvey,\%randomizetry);
- if (defined($checkcrstypes{$crstype})) {
+ &Apache::lonrelrequtils::init_global_hashes();
+ if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
+ ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
$output .= ''.&mt('Course type: [_1] requires [_2] or newer',$crstype,
- $checkcrstypes{$crstype}).'';
+ $Apache::lonrelrequtils::checkcrstypes{$crstype}).'';
}
my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
- %byresponsetype,%bysubmission);
+ %byresponsetype,%bysubmission,%fromblocks);
@scopeorder = ('all','section/group','user');
+ my $now = time;
my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
if (ref($resourcedata) eq 'HASH') {
foreach my $key (keys(%{$resourcedata})) {
- foreach my $item (keys(%checkparms)) {
+ foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
if ($key =~ /(\Q$item\E)$/) {
- if (ref($checkparms{$item}) eq 'ARRAY') {
+ if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
my $value = $resourcedata->{$key};
+ if ($item eq 'examcode') {
+ if (&Apache::lonnet::validCODE($value)) {
+ $value = 'valid';
+ } else {
+ $value = '';
+ }
+ } elsif ($item eq 'printstartdate') {
+ if ($value =~ /^\d+$/) {
+ if ($value > $now) {
+ $value = 'future';
+ }
+ }
+ } elsif ($item eq 'printenddate') {
+ if ($value =~ /^\d+$/) {
+ if ($value < $now) {
+ $value = 'past';
+ }
+ }
+
+ }
my ($middle,$scope,$which,$level,$map,$resource);
- if (grep(/^\Q$value\E$/,@{$checkparms{$item}})) {
+ if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
my $stdname = &Apache::lonparmset::standard_parameter_names($item);
my $valname = &get_param_description($stdtype,$value);
@@ -2184,6 +4587,9 @@ sub display_loncaparev_constraints {
' | '.&mt('Extent').' | '.&mt('Setting').' | '.
&Apache::loncommon::end_data_table_header_row();
foreach my $rev (keys(%fromparam)) {
+ my ($major,$minor) = split(/\./,$rev);
+ ($reqdmajor,$reqdminor) =
+ &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
$output .= &Apache::loncommon::start_data_table_row().
''.$rev.' | ';
my $newrow;
@@ -2214,6 +4620,75 @@ sub display_loncaparev_constraints {
}
}
+ my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
+ my $now = time;
+ if (keys(%comm_blocks) > 0) {
+ foreach my $block (keys(%comm_blocks)) {
+ if ($block =~ /^firstaccess____(.+)$/) {
+ my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
+ if (ref($comm_blocks{$block}) eq 'HASH') {
+ push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
+ ' '.&mt('set by [_1]',
+ &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
+ }
+ next;
+ } elsif ($block =~ /^(\d+)____(\d+)$/) {
+ my ($start,$end) = ($1,$2);
+ next if ($end < $now);
+ }
+ if (ref($comm_blocks{$block}) eq 'HASH') {
+ if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
+ if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
+ if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
+ my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
+ push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
+ ' '.
+ &mt('set by [_1]',
+ &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
+ }
+ } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
+ my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
+ push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
+ ' '.
+ &mt('set by [_1]',
+ &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
+
+ }
+ }
+ }
+ }
+ if (keys(%fromblocks)) {
+ my %lt = (
+ docs => 'Content blocking',
+ printout => 'Printout generation',
+ timer => 'Timed quiz trigger',
+ );
+ $output .= ''.&mt('Requirements from exam blocking').'
'.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ ''.&mt('Release').' | '.&mt('Setting').' | '.
+ ''.&mt('Event(s)').' | '.
+ &Apache::loncommon::end_data_table_header_row();
+ foreach my $type ('docs','printout','timer') {
+ if (ref($fromblocks{$type}) eq 'HASH') {
+ foreach my $rev (keys(%{$fromblocks{$type}})) {
+ my ($major,$minor) = split(/\./,$rev);
+ ($reqdmajor,$reqdminor) =
+ &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
+ $output .= &Apache::loncommon::start_data_table_row().
+ ''.$rev.' | '.$lt{$type}.' | ';
+ foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
+ $output .= $event.' ';
+ }
+ $output =~ s{\Q \E$}{};
+ $output .= ' | '.&Apache::loncommon::end_data_table_row();
+ }
+ }
+ }
+ $output .= &Apache::loncommon::end_data_table().'
';
+ }
+ }
+
if (defined($navmap)) {
my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'};
@@ -2223,7 +4698,7 @@ sub display_loncaparev_constraints {
my $stdname=&Apache::lonparmset::standard_parameter_names('type');
my $valanon=&get_param_description($stdtype,'anonsurvey');
my $valrandtry=&get_param_description($stdtype,'randomizetry');
-
+ my %checkedrev;
foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
my @parts = @{$res->parts()};
my $symb = $res->symb();
@@ -2240,6 +4715,13 @@ sub display_loncaparev_constraints {
push(@{$bysubmission{$symb}{$rev}},$what);
}
$allmaps{$enclosing_map} = 1;
+ unless ($checkedrev{'anonsurvey'}) {
+ my ($major,$minor) = split(/\./,$rev);
+ ($reqdmajor,$reqdminor) =
+ &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
+ $reqdmajor,$reqdminor);
+ $checkedrev{'anonsurvey'} = 1;
+ }
}
if (exists($randtrysubms{$symb."\0".$part})) {
my $rev = $rev_randtry;
@@ -2252,12 +4734,27 @@ sub display_loncaparev_constraints {
push(@{$bysubmission{$symb}{$rev}},$what);
}
$allmaps{$enclosing_map} = 1;
+ unless ($checkedrev{'randomizetry'}) {
+ my ($major,$minor) = split(/\./,$rev);
+ ($reqdmajor,$reqdminor) =
+ &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
+ $reqdmajor,$reqdminor);
+ $checkedrev{'randomizetry'} = 1;
+ }
}
}
my %responses = $res->responseTypes();
foreach my $key (keys(%responses)) {
- if (exists($checkresponsetypes{$key})) {
- push(@{$byresponsetype{$symb}{$checkresponsetypes{$key}}},$key);
+ if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
+ my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
+ unless ($checkedrev{$key}) {
+ my ($major,$minor) = split(/\./,$rev);
+ ($reqdmajor,$reqdminor) =
+ &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
+ $reqdmajor,$reqdminor);
+ $checkedrev{$key} = 1;
+ }
+ push(@{$byresponsetype{$symb}{$rev}},$key);
$allmaps{$enclosing_map} = 1;
}
}
@@ -2275,9 +4772,9 @@ sub display_loncaparev_constraints {
}
foreach my $map (keys(%allmaps)) {
my $mapres = $navmap->getResourceByUrl($map);
- my $mapsymb = $mapres->symb();
- $toshow{$mapsymb} = 1;
if (ref($mapres)) {
+ my $mapsymb = $mapres->symb();
+ $toshow{$mapsymb} = 1;
my $pcslist = $mapres->map_hierarchy();
if ($pcslist ne '') {
foreach my $pc (split(/,/,$pcslist)) {
@@ -2318,6 +4815,10 @@ sub display_loncaparev_constraints {
'');
}
$r->print(&Apache::loncommon::end_page());
+ my ($currmajor,$currminor) = split(/\./,$loncaparev);
+ if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
+ return 1;
+ }
return;
}
@@ -2336,7 +4837,7 @@ sub show_contents_view {
''.&mt('Attribute/Setting').' | '.
&Apache::loncommon::end_data_table_header_row().
&Apache::loncommon::start_data_table_row().
- ' '.$icon.' '.&mt('Main Course Documents').' | ');
+ ' '.$icon.' '.&mt('Main Content').' | ');
&releases_by_map($r,$bymap,$topmap,$scopeorder,$lt);
$r->print(&Apache::loncommon::end_data_table_row());
my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
@@ -2376,7 +4877,7 @@ sub show_contents_view {
}
$r->print(&Apache::loncommon::start_data_table_row().
''.$indent.$icon.' '.$title.' | ');
- &releases_by_map($r,$bymap,$url,$scopeorder);
+ &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
$r->print(&Apache::loncommon::end_data_table_row());
} else {
my $rowspan;
@@ -2459,13 +4960,19 @@ sub show_contents_view {
}
$r->print(&Apache::loncommon::end_data_table());
}
+ return;
}
sub releases_by_map {
my ($r,$bymap,$url,$scopeorder,$lt) = @_;
return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY'));
+ my $newrow = 0;
if (ref($bymap->{$url}) eq 'HASH') {
foreach my $rev (sort(keys(%{$bymap->{$url}}))) {
+ if ($newrow) {
+ $r->print(&Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::continue_data_table_row());
+ }
$r->print(''.$rev.' | ');
if (ref($bymap->{$url}{$rev}) eq 'HASH') {
$r->print('');
@@ -2487,6 +4994,7 @@ sub releases_by_map {
$r->print(' ');
}
$r->print(' | ');
+ $newrow = 1;
}
} else {
$r->print(' | ');
@@ -2512,9 +5020,27 @@ sub get_param_description {
return $name;
}
+sub update_releasereq {
+ my $readmap = 1;
+ my $getrelreq = 1;
+ if (ref($modified_courses) eq 'ARRAY') {
+ foreach my $item (@{$modified_courses}) {
+ if (ref($item) eq 'ARRAY') {
+ my ($cdom,$cnum,$chome,$crstype) = @{$item};
+ &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
+ $chome,$crstype,$cdom.'_'.$cnum,
+ $readmap,$getrelreq);
+ }
+ }
+ $modified_courses = [];
+ }
+ undef($registered_cleanup);
+ return;
+}
+
sub show_autocoowners {
my (@currcoown) = @_;
- my $output = ''.&mt('Co-ownership is set automatically when a Course Coordinator role is assigned to official course personnel (from institutional data).').'';
+ my $output = ''.&mt('Co-ownership is set automatically when a Course Coordinator role[_1] is assigned to official course personnel (from institutional data).','
').'';
if (@currcoown > 0) {
$output .= '
'.&mt('Current co-owners are:').' '.
join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
@@ -2525,13 +5051,20 @@ sub show_autocoowners {
}
sub coowner_invitations {
- my ($cnum,$cdom,@currcoown) = @_;
- my ($output,@pendingcoown,@othercoords);
+ my ($cnum,$cdom,$currcoownref,$noedit) = @_;
+ my ($output,@pendingcoown,@othercoords,@currcoown);
my $pendingcoowners =
$env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
if ($pendingcoowners) {
@pendingcoown = split(',',$pendingcoowners);
}
+ if (ref($currcoownref) eq 'ARRAY') {
+ @currcoown = @{$currcoownref};
+ }
+ my $disabled;
+ if ($noedit) {
+ $disabled = ' disabled="disabled"';
+ }
my $ccrole = 'cc';
my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
foreach my $key (sort(keys(%ccroles))) {
@@ -2549,7 +5082,7 @@ sub coowner_invitations {
''.&mt('Current co-owners').' | ';
foreach my $person (@currcoown) {
my ($co_uname,$co_dom) = split(':',$person);
- $output .= ''.(' 'x2).' ';
+ $output .= ''.(' 'x2).' ';
}
$output .= ' | '.
&Apache::loncommon::end_data_table_row();
@@ -2559,7 +5092,7 @@ sub coowner_invitations {
''.&mt('Invited as co-owners [_1](agreement pending)',' ').' | ';
foreach my $person (@pendingcoown) {
my ($co_uname,$co_dom) = split(':',$person);
- $output .= ''.(' 'x2).' ';
+ $output .= ''.(' 'x2).' ';
}
$output .= ' | '.
&Apache::loncommon::end_data_table_row();
@@ -2569,7 +5102,7 @@ sub coowner_invitations {
''.&mt('Invite other Coordinators [_1]to become co-owners',' ').' | ';
foreach my $person (@othercoords) {
my ($co_uname,$co_dom) = split(':',$person);
- $output .= ''.(' 'x2).' ';
+ $output .= ''.(' 'x2).' ';
}
$output .= ' | '.
&Apache::loncommon::end_data_table_row();
@@ -2582,13 +5115,20 @@ sub coowner_invitations {
}
sub manage_coownership {
- my ($cnum,$cdom,@currcoown) = @_;
- my (@pendingcoown);
+ my ($cnum,$cdom,$currcoownref,$noedit) = @_;
+ my (@pendingcoown,@currcoown);
my $pendingcoowners =
$env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
if ($pendingcoowners) {
@pendingcoown = split(',',$pendingcoowners);
}
+ if (ref($currcoownref) eq 'ARRAY') {
+ @currcoown = @{$currcoownref};
+ }
+ my $disabled;
+ if ($noedit) {
+ $disabled = ' disabled="disabled"';
+ }
my ($is_coowner,$is_pending,$output);
my $uname = $env{'user.name'};
my $udom = $env{'user.domain'};
@@ -2618,10 +5158,10 @@ sub manage_coownership {
}
$output .= '';
if ($is_coowner) {
- $output .= &mt('You are currently a co-owner:').' ';
+ $output .= &mt('You are currently a co-owner:').' ';
} else {
- $output .= &mt('The course owner has invited you to become a co-owner:').' '.(' 'x2).
- '';
+ $output .= &mt('The course owner has invited you to become a co-owner:').' '.(' 'x2).
+ '';
}
$output .= '';
if (@currcoown) {
@@ -2635,7 +5175,7 @@ sub manage_coownership {
}
sub print_localization {
- my ($cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
+ my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
return;
}
@@ -2654,17 +5194,38 @@ sub print_localization {
input => 'selectbox',
},
);
- my $datatable;
+ my ($datatable,$disabled);
my $count = 0;
+ if ($noedit) {
+ $disabled = ' disabled="disabled"';
+ }
foreach my $item (@{$ordered}) {
$count ++;
- $datatable .= &item_table_row_start($items{$item}{text},$count);
+ my $colspan;
+ unless ($item eq 'languages') {
+ $colspan = 2;
+ }
+ $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
if ($item eq 'timezone') {
my $includeempty = 1;
my $timezone = &Apache::lonlocal::gettimezone();
+ my $onchange;
+ unless ($noedit) {
+ $onchange = ' onchange="javascript:toggleTimeZone();"';
+ }
+ my $id = ' id="LC_set_timezone"';
$datatable .=
- &Apache::loncommon::select_timezone($item,$timezone,undef,
- $includeempty);
+ &Apache::loncommon::select_timezone($item,$timezone,$onchange,
+ $includeempty,$id,$disabled);
+ my $tzsty = 'none';
+ if ($timezone ne '') {
+ $tzsty = 'block';
+ }
+ $datatable .= ''.
+ ''.
+ &mt('Override individual user preference?').
+ &yesno_radio('tzover',$settings,undef,1,'',$noedit).
+ '
';
} elsif ($item eq 'datelocale') {
my $includeempty = 1;
my $locale_obj = &Apache::lonlocal::getdatelocale();
@@ -2674,15 +5235,18 @@ sub print_localization {
}
$datatable .=
&Apache::loncommon::select_datelocale($item,$currdatelocale,
- undef,$includeempty);
+ undef,$includeempty,$disabled);
} else {
if ($settings->{$item} eq '') {
- $datatable .=
- &Apache::loncommon::select_language('languages_0','',1);
+ unless ($noedit) {
+ $datatable .= ''.
+ &Apache::loncommon::select_language('languages_0','',1);
+ }
} else {
my $num = 0;
my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
- $datatable .= &Apache::loncommon::start_data_table();
+ $datatable .= ' | '.
+ &Apache::loncommon::start_data_table();
if (@languages > 0) {
my %langchoices = &get_lang_choices();
foreach my $lang (@languages) {
@@ -2697,19 +5261,22 @@ sub print_localization {
' '.
' | '.
&Apache::loncommon::end_data_table_row();
$num ++;
}
}
- $datatable .= &Apache::loncommon::start_data_table_row().
+ unless ($noedit) {
+ $datatable .=
+ &Apache::loncommon::start_data_table_row().
''.
&mt('Additional language:'). ' '.
&Apache::loncommon::select_language('languages_'.$num,'',1).
''.
- ' | '.&Apache::loncommon::end_data_table_row().
- &Apache::loncommon::end_data_table();
+ ''.&Apache::loncommon::end_data_table_row();
+ }
+ $datatable .= &Apache::loncommon::end_data_table().'
';
}
}
$datatable .= &item_table_row_end();
@@ -2730,7 +5297,7 @@ sub get_lang_choices {
}
sub print_feedback {
- my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
+ my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
return;
}
@@ -2765,21 +5332,25 @@ sub print_feedback {
del => 'Delete?',
sec => 'Sections:',
);
-
+ my $disabled;
+ if ($noedit) {
+ $disabled = ' disabled="disabled"';
+ }
foreach my $item (@{$ordered}) {
$count ++;
if ($position eq 'top') {
$datatable .= &item_table_row_start($items{$item}{text},$count);
} else {
- $datatable .= &item_table_row_start($items{$item}{text}."
(Custom text)",$count, "advanced");
+ $datatable .= &item_table_row_start($items{$item}{text}."
(Custom text)",$count, "advanced",2);
}
if ($position eq 'top') {
my $includeempty = 0;
- $datatable .= &user_table($cdom,$item,\@sections,
- $settings->{$item},\%lt);
+ $datatable .= ''.
+ &user_table($cdom,$item,\@sections,
+ $settings->{$item},\%lt,$noedit);
} else {
$datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
- $settings->{$item.'.text'},$items{$item}{size});
+ $settings->{$item.'.text'},$items{$item}{size},$disabled);
}
$datatable .= &item_table_row_end();
}
@@ -2788,15 +5359,21 @@ sub print_feedback {
}
sub user_table {
- my ($cdom,$item,$sections,$currvalue,$lt) = @_;
+ my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
my $output;
if ($currvalue eq '') {
- $output .= &select_recipient($item,'0',$cdom,$sections);
+ unless ($noedit) {
+ $output .= &select_recipient($item,'0',$cdom,$sections);
+ }
} else {
my $num = 0;
my @curr = split(/,/,$currvalue);
- $output .= '';
+ $output .= '';
my ($currusers);
+ my $disabled;
+ if ($noedit) {
+ $disabled = ' disabled="disabled"';
+ }
foreach my $val (@curr) {
next if ($val eq '');
my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
@@ -2808,7 +5385,7 @@ sub user_table {
$currusers .= ''.
''.
''.
''.(' 'x2).
@@ -2819,7 +5396,7 @@ sub user_table {
if (@{$sections}) {
$currusers.= (' 'x3).$lt->{'sec'}.' '.
&select_sections($item,$num,$sections,
- \@selsec);
+ \@selsec,$noedit);
}
}
$currusers .= ' | ';
@@ -2837,12 +5414,16 @@ sub user_table {
''.
'';
}
- $output .= ''.
+ unless ($noedit) {
+ $output .=
+ ' '.
''.
$lt->{'add'}.' '.
&select_recipient($item,$num,$cdom,$sections).
''.
- ' | ';
+ '';
+ }
+ $output .= ' ';
}
return $output;
}
@@ -2852,7 +5433,7 @@ sub select_recipient {
my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
my $selectlink =
&Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
- $item.'_udom_'.$num,1);
+ $item.'_udom_'.$num,'only');
my $output =
''.&mt('Username').' '.
' | '.
@@ -2869,29 +5450,40 @@ sub select_recipient {
}
sub select_sections {
- my ($item,$num,$sections,$selected) = @_;
- my ($output,@currsecs,$allsec);
+ my ($item,$num,$sections,$selected,$noedit,$allval) = @_;
+ my ($output,@currsecs,$allsec,$disabled);
if (ref($selected) eq 'ARRAY') {
@currsecs = @{$selected};
}
if (!@currsecs) {
$allsec = ' selected="selected"';
}
+ if ($noedit) {
+ $disabled = ' disabled="disabled"';
+ }
if (ref($sections) eq 'ARRAY') {
if (@{$sections}) {
my $mult;
if (@{$sections} > 1) {
$mult = ' multiple="multiple"';
+ my $size;
if (@{$sections} > 3) {
- $mult .= ' size="4"';
+ $size = 4;
+ } else {
+ $size = 1 + scalar(@{$sections});
}
+ $mult .= ' size="'.$size.'"';
}
- $output = '
|