--- loncom/interface/domainprefs.pm 2017/06/05 21:21:51 1.160.6.84
+++ loncom/interface/domainprefs.pm 2017/10/17 12:58:53 1.160.6.84.2.5
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.160.6.84 2017/06/05 21:21:51 raeburn Exp $
+# $Id: domainprefs.pm,v 1.160.6.84.2.5 2017/10/17 12:58:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -27,7 +27,7 @@
#
#
###############################################################
-##############################################################
+###############################################################
=pod
@@ -216,13 +216,27 @@ sub handler {
'contacts','defaults','scantron','coursecategories',
'serverstatuses','requestcourses','helpsettings',
'coursedefaults','usersessions','loadbalancing',
- 'requestauthor','selfenrollment','inststatus'],$dom);
+ 'requestauthor','selfenrollment','inststatus',
+ 'ltitools'],$dom);
+ if (ref($domconfig{'ltitools'}) eq 'HASH') {
+ my %encconfig =
+ &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
+ if (ref($encconfig{'ltitools'}) eq 'HASH') {
+ foreach my $id (keys(%{$domconfig{'ltitools'}})) {
+ if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
+ foreach my $item ('key','secret') {
+ $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
+ }
+ }
+ }
+ }
+ }
my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
'autoupdate','autocreate','directorysrch','contacts',
'usercreation','selfcreation','usermodification','scantron',
'requestcourses','requestauthor','coursecategories',
'serverstatuses','helpsettings','coursedefaults',
- 'selfenrollment','usersessions');
+ 'ltitools','selfenrollment','usersessions');
my %existing;
if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
%existing = %{$domconfig{'loadbalancing'}};
@@ -475,6 +489,14 @@ sub handler {
print => \&print_loadbalancing,
modify => \&modify_loadbalancing,
},
+ 'ltitools' =>
+ {text => 'External Tools (LTI)',
+ help => 'Domain_Configuration_LTI_Tools',
+ header => [{col1 => 'Setting',
+ col2 => 'Value',}],
+ print => \&print_ltitools,
+ modify => \&modify_ltitools,
+ },
);
if (keys(%servers) > 1) {
$prefs{'login'} = { text => 'Log-in page options',
@@ -651,6 +673,8 @@ sub process_changes {
$output = &modify_usersessions($dom,$lastactref,%domconfig);
} elsif ($action eq 'loadbalancing') {
$output = &modify_loadbalancing($dom,%domconfig);
+ } elsif ($action eq 'ltitools') {
+ $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
}
return $output;
}
@@ -930,7 +954,8 @@ sub print_config_box {
if ($action eq 'quotas') {
$output .= &print_quotas($dom,$settings,\$rowtotal,$action);
} elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
- ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
+ ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
+ ($action eq 'ltitools')) {
$output .= $item->{'print'}->($dom,$settings,\$rowtotal);
} elsif ($action eq 'scantron') {
$output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
@@ -2437,6 +2462,74 @@ $jstext{'templates'};
ENDSCRIPT
}
+sub ltitools_javascript {
+ my ($settings) = @_;
+ return unless(ref($settings) eq 'HASH');
+ my (%ordered,$total,%jstext);
+ $total = 0;
+ foreach my $item (keys(%{$settings})) {
+ if (ref($settings->{$item}) eq 'HASH') {
+ my $num = $settings->{$item}{'order'};
+ $ordered{$num} = $item;
+ }
+ }
+ $total = scalar(keys(%{$settings}));
+ my @jsarray = ();
+ foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
+ push(@jsarray,$ordered{$item});
+ }
+ my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
+ return <<"ENDSCRIPT";
+
+
+ENDSCRIPT
+}
+
sub print_autoenroll {
my ($dom,$settings,$rowtotal) = @_;
my $autorun = &Apache::lonnet::auto_run(undef,$dom),
@@ -2565,7 +2658,7 @@ sub print_autoupdate {
my $locknamesettings;
$datatable .= &insttypes_row($settings,$types,$usertypes,
$dom,$numinrow,$othertitle,
- 'lockablenames');
+ 'lockablenames',$rowtotal);
$$rowtotal ++;
} else {
my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
@@ -2708,7 +2801,8 @@ sub print_directorysrch {
if (ref($usertypes) eq 'HASH') {
if (keys(%{$usertypes}) > 0) {
$datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
- $numinrow,$othertitle,'cansearch');
+ $numinrow,$othertitle,'cansearch',
+ $rowtotal);
$cansrchrow = 1;
}
}
@@ -2909,7 +3003,54 @@ sub print_contacts {
$to{$item}.'" />';
$rownum ++;
}
- } else {
+ } elsif ($position eq 'bottom') {
+ $css_class = $rownum%2?' class="LC_odd_row"':'';
+ $datatable .= '
'.
+ ''.&mt('Extra helpdesk form fields:').' '.
+ &mt('(e-mail, subject, and description always shown)').
+ ' ';
+ if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
+ (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
+ $datatable .= '';
+ }
+ $datatable .= ' '."\n";
+ $rownum ++;
+ }
+ unless ($position eq 'top') {
foreach my $type (@mailings) {
$css_class = $rownum%2?' class="LC_odd_row"':'';
$datatable .= ''.
@@ -2969,56 +3110,138 @@ sub print_contacts {
\%choices,$rownum);
$datatable .= $reports;
} elsif ($position eq 'bottom') {
- $css_class = $rownum%2?' class="LC_odd_row"':'';
- $datatable .= ' '.
- ''.&mt('Extra helpdesk form fields:').' '.
- &mt('(e-mail, subject, and description always shown)').
- ' ';
- if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
- (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
- $datatable .= ''.&mt('Field').' '.&mt('Status').' ';
- foreach my $field (@{$fields}) {
- $datatable .= ''.$fieldtitles->{$field};
- if (($field eq 'screenshot') || ($field eq 'cc')) {
- $datatable .= ' '.&mt('(logged-in users)');
- }
- $datatable .=' ';
- my $clickaction;
- if ($field eq 'screenshot') {
- $clickaction = ' onclick="screenshotSize(this);"';
- }
- if (ref($possoptions->{$field}) eq 'ARRAY') {
- foreach my $option (@{$possoptions->{$field}}) {
- my $checked;
- if ($currfield{$field} eq $option) {
- $checked = ' checked="checked"';
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
+ my (@posstypes,%usertypeshash);
+ if (ref($types) eq 'ARRAY') {
+ @posstypes = @{$types};
+ }
+ if (@posstypes) {
+ if (ref($usertypes) eq 'HASH') {
+ %usertypeshash = %{$usertypes};
+ }
+ my @overridden;
+ my $numinrow = 4;
+ if (ref($settings) eq 'HASH') {
+ if (ref($settings->{'overrides'}) eq 'HASH') {
+ foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
+ if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
+ push(@overridden,$key);
+ foreach my $item (@contacts) {
+ if ($settings->{'overrides'}{$key}{$item}) {
+ $checked{'override_'.$key}{$item} = ' checked="checked" ';
+ }
+ }
+ $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
+ $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
+ $includeloc{'override_'.$key} = '';
+ $includestr{'override_'.$key} = '';
+ if ($settings->{'overrides'}{$key}{'include'} ne '') {
+ ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
+ split(/:/,$settings->{'overrides'}{$key}{'include'},2);
+ $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
+ }
}
- $datatable .= ''.
- ' '.$fieldoptions->{$option}.
- ' '.(' 'x2);
}
}
- if ($field eq 'screenshot') {
- my $display;
- if ($currfield{$field} eq 'no') {
- $display = ' style="display:none"';
- }
- $datatable .= ' '.
- ''.&mt('Maximum size for upload (MB)').' '.
- ' ';
+ }
+ my $customclass = 'LC_helpdesk_override';
+ my $optionsprefix = 'LC_options_helpdesk_';
+
+ my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
+
+ $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
+ $numinrow,$othertitle,'overrides',
+ \$rownum,$onclicktypes,$customclass);
+ $rownum ++;
+ $usertypeshash{'default'} = $othertitle;
+ foreach my $status (@posstypes) {
+ my $css_class;
+ if ($rownum%2) {
+ $css_class = 'LC_odd_row ';
+ }
+ $css_class .= $customclass;
+ my $rowid = $optionsprefix.$status;
+ my $hidden = 1;
+ my $currstyle = 'display:none';
+ if (grep(/^\Q$status\E$/,@overridden)) {
+ $currstyle = 'display:table-row';
+ $hidden = 0;
+ }
+ my $key = 'override_'.$status;
+ $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
+ $includeloc{$key},$includestr{$key},$status,$rowid,
+ $usertypeshash{$status},$css_class,$currstyle,
+ \@contacts,$short_titles);
+ unless ($hidden) {
+ $rownum ++;
}
- $datatable .= ' ';
}
- $datatable .= '
';
}
- $datatable .= ' '."\n";
- $rownum ++;
}
$$rowtotal += $rownum;
return $datatable;
}
+sub overridden_helpdesk {
+ my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
+ $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
+ my $class = 'LC_left_item';
+ if ($css_class) {
+ $css_class = ' class="'.$css_class.'"';
+ }
+ if ($rowid) {
+ $rowid = ' id="'.$rowid.'"';
+ }
+ if ($rowstyle) {
+ $rowstyle = ' style="'.$rowstyle.'"';
+ }
+ my ($output,$description);
+ $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"$typetitle ");
+ $output = ''.
+ "$description \n".
+ ''.
+ ''.&mt('E-mail recipient(s)').' '.
+ '';
+ if (ref($contacts) eq 'ARRAY') {
+ foreach my $item (@{$contacts}) {
+ my $check;
+ if (ref($checked) eq 'HASH') {
+ $check = $checked->{$item};
+ }
+ my $title;
+ if (ref($short_titles) eq 'HASH') {
+ $title = $short_titles->{$item};
+ }
+ $output .= ''.
+ ' '.$title.' ';
+ }
+ }
+ $output .= ' '.&mt('Others').': '.
+ ' ';
+ my %locchecked;
+ foreach my $loc ('s','b') {
+ if ($includeloc eq $loc) {
+ $locchecked{$loc} = ' checked="checked"';
+ last;
+ }
+ }
+ $output .= ' '.&mt('Bcc:').(' 'x6).
+ ' '.
+ ''.&mt('Optional added text').' '.
+ &mt('Text automatically added to e-mail:').' '.
+ ' '.
+ ''.&mt('Location:').' '.
+ ' '.&mt('in subject').' '.
+ (' 'x2).
+ ' '.&mt('in body').' '.
+ ' '.
+ ' '."\n";
+ return $output;
+}
+
sub contacts_javascript {
return <<"ENDSCRIPT";
@@ -3036,6 +3259,37 @@ function screenshotSize(field) {
return;
}
+function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
+ if (form.elements[checkbox].length != undefined) {
+ var count = 0;
+ if (docount) {
+ for (var i=0; i
@@ -3481,6 +3735,373 @@ sub radiobutton_prefs {
return ($datatable,$itemcount);
}
+sub print_ltitools {
+ my ($dom,$settings,$rowtotal) = @_;
+ my $rownum = 0;
+ my $css_class;
+ my $itemcount = 1;
+ my $maxnum = 0;
+ my %ordered;
+ if (ref($settings) eq 'HASH') {
+ foreach my $item (keys(%{$settings})) {
+ if (ref($settings->{$item}) eq 'HASH') {
+ my $num = $settings->{$item}{'order'};
+ $ordered{$num} = $item;
+ }
+ }
+ }
+ my $confname = $dom.'-domainconfig';
+ my $switchserver = &check_switchserver($dom,$confname);
+ my $maxnum = scalar(keys(%ordered));
+ my $datatable = <itools_javascript($settings);
+ my %lt = <itools_names();
+ my @courseroles = ('cc','in','ta','ep','st');
+ my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
+ my @fields = ('fullname','firstname','lastname','email','user','roles');
+ if (keys(%ordered)) {
+ my @items = sort { $a <=> $b } keys(%ordered);
+ for (my $i=0; $i<@items; $i++) {
+ $css_class = $itemcount%2?' class="LC_odd_row"':'';
+ my $item = $ordered{$items[$i]};
+ my ($title,$key,$secret,$url,$imgsrc,$version);
+ if (ref($settings->{$item}) eq 'HASH') {
+ $title = $settings->{$item}->{'title'};
+ $url = $settings->{$item}->{'url'};
+ $key = $settings->{$item}->{'key'};
+ $secret = $settings->{$item}->{'secret'};
+ my $image = $settings->{$item}->{'image'};
+ if ($image ne '') {
+ $imgsrc = ' ';
+ }
+ }
+ my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
+ $datatable .= ''
+ .'';
+ for (my $k=0; $k<=$maxnum; $k++) {
+ my $vpos = $k+1;
+ my $selstr;
+ if ($k == $i) {
+ $selstr = ' selected="selected" ';
+ }
+ $datatable .= ''.$vpos.' ';
+ }
+ $datatable .= ' '.(' 'x2).
+ ' '.
+ &mt('Delete?').' '.
+ ''.
+ ''.&mt('Required settings').' '.
+ ''.$lt{'title'}.': '.
+ (' 'x2).
+ ''.$lt{'version'}.':'.
+ '1.1 '.
+ (' 'x2).
+ ''.$lt{'msgtype'}.':'.
+ 'Launch '.
+ ' '.
+ ''.$lt{'url'}.': '.
+ (' 'x2).
+ ''.$lt{'key'}.
+ ' '.
+ (' 'x2).
+ ''.$lt{'secret'}.':'.
+ ' '.
+ ' '.&mt('Visible input').' '.
+ ' '.
+ ' '.
+ ''.&mt('Optional settings').' '.
+ ''.&mt('Display target:');
+ my %currdisp;
+ if (ref($settings->{$item}->{'display'}) eq 'HASH') {
+ if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
+ $currdisp{'window'} = ' checked="checked"';
+ } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
+ $currdisp{'tab'} = ' checked="checked"';
+ } else {
+ $currdisp{'iframe'} = ' checked="checked"';
+ }
+ if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
+ $currdisp{'width'} = $1;
+ }
+ if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
+ $currdisp{'height'} = $1;
+ }
+ $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
+ $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
+ } else {
+ $currdisp{'iframe'} = ' checked="checked"';
+ }
+ foreach my $disp ('iframe','tab','window') {
+ $datatable .= ' '.
+ $lt{$disp}.' '.(' 'x2);
+ }
+ $datatable .= (' 'x4);
+ foreach my $dimen ('width','height') {
+ $datatable .= ''.$lt{$dimen}.' '.
+ ' '.
+ (' 'x2);
+ }
+ $datatable .= ' '.
+ ''.$lt{'linktext'}.' '.
+ '
'.
+ ''.$lt{'explanation'}.' '.
+ '
';
+ $datatable .= ' ';
+ foreach my $extra ('passback','roster') {
+ my $checkedon = '';
+ my $checkedoff = ' checked="checked"';
+ if ($settings->{$item}->{$extra}) {
+ $checkedon = $checkedoff;
+ $checkedoff = '';
+ }
+ $datatable .= $lt{$extra}.' '.
+ ' '.
+ &mt('Yes').' '.(' 'x2).
+ ' '.
+ &mt('No').' '.(' 'x4);
+ }
+ $datatable .= ''.$lt{'icon'}.': ';
+ if ($imgsrc) {
+ $datatable .= $imgsrc.
+ ' '.&mt('Delete?').' '.
+ ' '.&mt('Replace:').' ';
+ } else {
+ $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
+ }
+ if ($switchserver) {
+ $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+ } else {
+ $datatable .= ' ';
+ }
+ $datatable .= ' ';
+ my (%checkedfields,%rolemaps);
+ if (ref($settings->{$item}) eq 'HASH') {
+ if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
+ %checkedfields = %{$settings->{$item}->{'fields'}};
+ }
+ if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
+ %rolemaps = %{$settings->{$item}->{'roles'}};
+ $checkedfields{'roles'} = 1;
+ }
+ }
+ $datatable .= ''.&mt('User data sent on launch').' '.
+ '';
+ foreach my $field (@fields) {
+ my $checked;
+ if ($checkedfields{$field}) {
+ $checked = ' checked="checked"';
+ }
+ $datatable .= ''.
+ ' '.
+ $lt{$field}.' '.(' ' x2);
+ }
+ $datatable .= ' '.
+ ''.&mt('Role mapping').' ';
+ foreach my $role (@courseroles) {
+ my ($selected,$selectnone);
+ if (!$rolemaps{$role}) {
+ $selectnone = ' selected="selected"';
+ }
+ $datatable .= ''.
+ &Apache::lonnet::plaintext($role,'Course').' '.
+ ''.
+ ''.&mt('Select').' ';
+ foreach my $ltirole (@ltiroles) {
+ unless ($selectnone) {
+ if ($rolemaps{$role} eq $ltirole) {
+ $selected = ' selected="selected"';
+ } else {
+ $selected = '';
+ }
+ }
+ $datatable .= ''.$ltirole.' ';
+ }
+ $datatable .= ' ';
+ }
+ $datatable .= '
';
+ my %courseconfig;
+ if (ref($settings->{$item}) eq 'HASH') {
+ if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
+ %courseconfig = %{$settings->{$item}->{'crsconf'}};
+ }
+ }
+ $datatable .= ''.&mt('Configurable in course').' ';
+ foreach my $item ('label','title','target','linktext','explanation') {
+ my $checked;
+ if ($courseconfig{$item}) {
+ $checked = ' checked="checked"';
+ }
+ $datatable .= ''.
+ ' '.
+ $lt{'crs'.$item}.' '.(' ' x2)."\n";
+ }
+ $datatable .= ' '.
+ ''.&mt('Custom items sent on launch').' '.
+ ' '."\n";
+ $itemcount ++;
+ }
+ }
+ $css_class = $itemcount%2?' class="LC_odd_row"':'';
+ my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
+ $datatable .= ''."\n".
+ ' '."\n".
+ '';
+ for (my $k=0; $k<$maxnum+1; $k++) {
+ my $vpos = $k+1;
+ my $selstr;
+ if ($k == $maxnum) {
+ $selstr = ' selected="selected" ';
+ }
+ $datatable .= ''.$vpos.' ';
+ }
+ $datatable .= ' '."\n".
+ ' '.&mt('Add').' '."\n".
+ ''.
+ ''.&mt('Required settings').' '.
+ ''.$lt{'title'}.': '."\n".
+ (' 'x2).
+ ''.$lt{'version'}.':'.
+ '1.1 '."\n".
+ (' 'x2).
+ ''.$lt{'msgtype'}.':'.
+ 'Launch '.
+ ' '.
+ ''.$lt{'url'}.': '."\n".
+ (' 'x2).
+ ''.$lt{'key'}.': '."\n".
+ (' 'x2).
+ ''.$lt{'secret'}.': '.
+ ' '.&mt('Visible input').' '."\n".
+ ' '.
+ ''.&mt('Optional settings').' '.
+ ''.&mt('Display target:');
+ my %defaultdisp;
+ $defaultdisp{'iframe'} = ' checked="checked"';
+ foreach my $disp ('iframe','tab','window') {
+ $datatable .= ' '.
+ $lt{$disp}.' '.(' 'x2);
+ }
+ $datatable .= (' 'x4);
+ foreach my $dimen ('width','height') {
+ $datatable .= ''.$lt{$dimen}.' '.
+ ' '.
+ (' 'x2);
+ }
+ $datatable .= ' '.
+ ''.$lt{'linktext'}.' '.
+ '
'.
+ ''.$lt{'explanation'}.' '.
+ ''.
+ '
';
+ foreach my $extra ('passback','roster') {
+ $datatable .= $lt{$extra}.' '.
+ ' '.
+ &mt('Yes').' '.(' 'x2).
+ ' '.
+ &mt('No').' '.(' 'x4);
+ }
+ $datatable .= ''.$lt{'icon'}.': '.
+ '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
+ if ($switchserver) {
+ $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+ } else {
+ $datatable .= ' ';
+ }
+ $datatable .= ' '.
+ ''.&mt('User data sent on launch').' '.
+ '';
+ foreach my $field (@fields) {
+ $datatable .= ''.
+ ' '.
+ $lt{$field}.' '.(' ' x2);
+ }
+ $datatable .= ' '.
+ ''.&mt('Role mapping').' ';
+ foreach my $role (@courseroles) {
+ my ($checked,$checkednone);
+ $datatable .= ''.
+ &Apache::lonnet::plaintext($role,'Course').' '.
+ ''.
+ ''.&mt('Select').' ';
+ foreach my $ltirole (@ltiroles) {
+ $datatable .= ''.$ltirole.' ';
+ }
+ $datatable .= ' ';
+ }
+ $datatable .= '
'.
+ ''.&mt('Configurable in course').' ';
+ foreach my $item ('label','title','target','linktext','explanation') {
+ $datatable .= ''.
+ ' '.
+ $lt{'crs'.$item}.' '.(' ' x2)."\n";
+ }
+ $datatable .= ' '.
+ ''.&mt('Custom items sent on launch').' '.
+ ' '."\n".
+ ''."\n".
+ ''."\n";
+ $itemcount ++;
+ return $datatable;
+}
+
+sub ltitools_names {
+ my %lt = &Apache::lonlocal::texthash(
+ 'title' => 'Title',
+ 'version' => 'Version',
+ 'msgtype' => 'Message Type',
+ 'url' => 'URL',
+ 'key' => 'Key',
+ 'secret' => 'Secret',
+ 'icon' => 'Icon',
+ 'user' => 'Username:domain',
+ 'fullname' => 'Full Name',
+ 'firstname' => 'First Name',
+ 'lastname' => 'Last Name',
+ 'email' => 'E-mail',
+ 'roles' => 'Role',
+ 'window' => 'Window',
+ 'tab' => 'Tab',
+ 'iframe' => 'iFrame',
+ 'height' => 'Height',
+ 'width' => 'Width',
+ 'linktext' => 'Default Link Text',
+ 'explanation' => 'Default Explanation',
+ 'passback' => 'Tool can return grades:',
+ 'roster' => 'Tool can retrieve roster:',
+ 'crstarget' => 'Display target',
+ 'crslabel' => 'Course label',
+ 'crstitle' => 'Course title',
+ 'crslinktext' => 'Link Text',
+ 'crsexplanation' => 'Explanation',
+ );
+
+ return %lt;
+}
+
sub print_coursedefaults {
my ($position,$dom,$settings,$rowtotal) = @_;
my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
@@ -4630,9 +5251,14 @@ sub loadbalancing_titles {
'_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
);
my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
+ my @available;
if (ref($types) eq 'ARRAY') {
- unshift(@alltypes,@{$types},'default');
+ @available = @{$types};
+ }
+ unless (grep(/^default$/,@available)) {
+ push(@available,'default');
}
+ unshift(@alltypes,@available);
my %titles;
foreach my $type (@alltypes) {
if ($type =~ /^_LC_/) {
@@ -4759,8 +5385,8 @@ sub contact_titles {
'adminemail' => 'Default Server Admin E-mail address',
'errormail' => 'Error reports to be e-mailed to',
'packagesmail' => 'Package update alerts to be e-mailed to',
- 'helpdeskmail' => "Helpdesk requests for this domain's users",
- 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
+ 'helpdeskmail' => "Helpdesk requests from all users in this domain",
+ 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
'requestsmail' => 'E-mail from course requests requiring approval',
'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
@@ -5008,6 +5634,7 @@ sub print_selfcreation {
my %radiohash;
my $numinrow = 4;
map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
if ($position eq 'top') {
my %choices = &Apache::lonlocal::texthash (
cancreate_login => 'Institutional Login',
@@ -5023,13 +5650,11 @@ sub print_selfcreation {
\%choices,$itemcount,$onclick);
$$rowtotal += $itemcount;
- my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
-
if (ref($usertypes) eq 'HASH') {
if (keys(%{$usertypes}) > 0) {
$datatable .= &insttypes_row($createsettings,$types,$usertypes,
$dom,$numinrow,$othertitle,
- 'statustocreate',$$rowtotal);
+ 'statustocreate',$rowtotal);
$$rowtotal ++;
}
}
@@ -5074,16 +5699,22 @@ sub print_selfcreation {
$$rowtotal ++;
} elsif ($position eq 'middle') {
my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
- my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
- $usertypes->{'default'} = $othertitle;
+ my @posstypes;
if (ref($types) eq 'ARRAY') {
- push(@{$types},'default');
- $usertypes->{'default'} = $othertitle;
- foreach my $status (@{$types}) {
- $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
- $numinrow,$$rowtotal,$usertypes);
- $$rowtotal ++;
- }
+ @posstypes = @{$types};
+ }
+ unless (grep(/^default$/,@posstypes)) {
+ push(@posstypes,'default');
+ }
+ my %usertypeshash;
+ if (ref($usertypes) eq 'HASH') {
+ %usertypeshash = %{$usertypes};
+ }
+ $usertypeshash{'default'} = $othertitle;
+ foreach my $status (@posstypes) {
+ $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
+ $numinrow,$$rowtotal,\%usertypeshash);
+ $$rowtotal ++;
}
} else {
my %choices = &Apache::lonlocal::texthash (
@@ -5101,29 +5732,33 @@ sub print_selfcreation {
my $onclick = "toggleDisplay(this.form,'emailoptions');";
my $additional = '';
my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
- my $usertypes = {};
- my $order = [];
- if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
- $usertypes = $domdefaults{'inststatustypes'};
+ if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
$order = $domdefaults{'inststatusguest'};
}
+ my (@ordered,%usertypeshash);
if (ref($order) eq 'ARRAY') {
- push(@{$order},'default');
- if (@{$order} > 1) {
- $usertypes->{'default'} = &mt('Other users');
- $additional .= '
';
- foreach my $status (@{$order}) {
- $additional .= ''.$usertypes->{$status}.' ';
- }
- $additional .= ' ';
- foreach my $status (@{$order}) {
- $additional .= ''.&email_as_username($rowtotal,$processing,$status).' ';
- }
- $additional .= '
';
- } else {
- $usertypes->{'default'} = &mt('All users');
- $additional .= &email_as_username($rowtotal,$processing);
+ @ordered = @{$order};
+ }
+ if (@ordered) {
+ unless (grep(/^default$/,@ordered)) {
+ push(@ordered,'default');
+ }
+ if (ref($usertypes) eq 'HASH') {
+ %usertypeshash = %{$usertypes};
+ }
+ $usertypeshash{'default'} = $othertitle;
+ $additional .= '
';
+ foreach my $status (@ordered) {
+ $additional .= ''.$usertypeshash{$status}.' ';
}
+ $additional .= ' ';
+ foreach my $status (@ordered) {
+ $additional .= ''.&email_as_username($rowtotal,$processing,$status).' ';
+ }
+ $additional .= '
';
+ } else {
+ $usertypeshash{'default'} = $othertitle;
+ $additional .= &email_as_username($rowtotal,$processing);
}
$additional .= '
'."\n";
@@ -5134,12 +5769,10 @@ sub print_selfcreation {
$$rowtotal ++;
my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
$numinrow = 1;
- if (ref($order) eq 'ARRAY') {
- foreach my $status (@{$order}) {
- $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
- $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
- $$rowtotal ++;
- }
+ foreach my $status (@ordered) {
+ $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
+ $numinrow,$$rowtotal,\%usertypeshash,$infofields,$infotitles);
+ $$rowtotal ++;
}
my ($emailrules,$emailruleorder) =
&Apache::lonnet::inst_userrules($dom,'email');
@@ -6607,11 +7240,13 @@ sub modifiable_userdata_row {
}
sub insttypes_row {
- my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
+ my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
+ $customcss,$rowstyle) = @_;
my %lt = &Apache::lonlocal::texthash (
cansearch => 'Users allowed to search',
statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
lockablenames => 'User preference to lock name',
+ overrides => "Override domain's helpdesk settings based on requester's affiliation",
);
my $showdom;
if ($context eq 'cansearch') {
@@ -6621,9 +7256,22 @@ sub insttypes_row {
if ($context eq 'statustocreate') {
$class = 'LC_right_item';
}
- my $css_class = ' class="LC_odd_row"';
- if ($rownum ne '') {
- $css_class = ($rownum%2? ' class="LC_odd_row"':'');
+ my $css_class;
+ if ($$rowtotal%2) {
+ $css_class = 'LC_odd_row';
+ }
+ if ($customcss) {
+ $css_class .= ' '.$customcss;
+ }
+ $css_class =~ s/^\s+//;
+ if ($css_class) {
+ $css_class = ' class="'.$css_class.'"';
+ }
+ if ($rowstyle) {
+ $css_class .= ' style="'.$rowstyle.'"';
+ }
+ if ($onclick) {
+ $onclick = 'onclick="'.$onclick.'" ';
}
my $output = ''.
''.$lt{$context}.$showdom.
@@ -6645,6 +7293,10 @@ sub insttypes_row {
if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
$check = ' checked="checked" ';
}
+ } elsif (ref($settings->{$context}) eq 'HASH') {
+ if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
+ $check = ' checked="checked" ';
+ }
} elsif ($context eq 'statustocreate') {
$check = ' checked="checked" ';
}
@@ -6659,29 +7311,38 @@ sub insttypes_row {
$rem = @{$types}%($numinrow);
}
my $colsleft = $numinrow - $rem;
- if (($rem == 0) && (@{$types} > 0)) {
- $output .= ' ';
- }
- if ($colsleft > 1) {
- $output .= '';
+ if ($context eq 'overrides') {
+ if ($colsleft > 1) {
+ $output .= ' ';
+ } else {
+ $output .= ' ';
+ }
+ $output .= ' ';
} else {
- $output .= ' ';
- }
- my $defcheck = ' ';
- if (ref($settings) eq 'HASH') {
- if (ref($settings->{$context}) eq 'ARRAY') {
- if (grep(/^default$/,@{$settings->{$context}})) {
+ if (($rem == 0) && (@{$types} > 0)) {
+ $output .= ' ';
+ }
+ if ($colsleft > 1) {
+ $output .= '';
+ } else {
+ $output .= ' ';
+ }
+ my $defcheck = ' ';
+ if (ref($settings) eq 'HASH') {
+ if (ref($settings->{$context}) eq 'ARRAY') {
+ if (grep(/^default$/,@{$settings->{$context}})) {
+ $defcheck = ' checked="checked" ';
+ }
+ } elsif ($context eq 'statustocreate') {
$defcheck = ' checked="checked" ';
}
- } elsif ($context eq 'statustocreate') {
- $defcheck = ' checked="checked" ';
}
+ $output .= ''.
+ ' '.
+ $othertitle.' ';
}
- $output .= ''.
- ' '.
- $othertitle.' '.
- ' ';
+ $output .= '';
return $output;
}
@@ -8679,6 +9340,589 @@ sub process_textbook_image {
return ($url,$error);
}
+sub modify_ltitools {
+ my ($r,$dom,$action,$lastactref,%domconfig) = @_;
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
+ my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
+ my $confname = $dom.'-domainconfig';
+ my $servadm = $r->dir_config('lonAdmEMail');
+ my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
+ 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 %lt = <itools_names();
+ if ($env{'form.ltitools_add'}) {
+ my $title = $env{'form.ltitools_add_title'};
+ $title =~ s/(`)/'/g;
+ ($newid,my $error) = &get_ltitools_id($dom,$title);
+ if ($newid) {
+ my $position = $env{'form.ltitools_add_pos'};
+ $position =~ s/\D+//g;
+ if ($position ne '') {
+ $allpos[$position] = $newid;
+ }
+ $changes{$newid} = 1;
+ foreach my $item ('title','url','key','secret') {
+ $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
+ if ($env{'form.ltitools_add_'.$item}) {
+ if (($item eq 'key') || ($item eq 'secret')) {
+ $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
+ } else {
+ $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
+ }
+ }
+ }
+ if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
+ $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
+ }
+ if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
+ $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
+ }
+ 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+$/) {
+ $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
+ }
+ } else {
+ if ($env{'form.ltitools_add_'.$item} ne '') {
+ $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
+ }
+ }
+ }
+ if ($env{'form.ltitools_add_target'} eq 'window') {
+ $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
+ } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
+ $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
+ } else {
+ $confhash{$newid}{'display'}{'target'} = 'iframe';
+ }
+ foreach my $item ('passback','roster') {
+ if ($env{'form.ltitools_add_'.$item}) {
+ $confhash{$newid}{$item} = 1;
+ }
+ }
+ if ($env{'form.ltitools_add_image.filename'} ne '') {
+ my ($imageurl,$error) =
+ &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
+ $configuserok,$switchserver,$author_ok);
+ if ($imageurl) {
+ $confhash{$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})) {
+ $confhash{$newid}{'roles'}{$role} = $choice;
+ if ($role eq 'cc') {
+ $confhash{$newid}{'roles'}{'co'} = $choice;
+ }
+ }
+ }
+ } else {
+ $confhash{$newid}{'fields'}{$field} = 1;
+ }
+ }
+ }
+ my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
+ foreach my $item (@courseconfig) {
+ $confhash{$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;
+ $confhash{$newid}{'custom'}{$name} = $value;
+ }
+ } else {
+ my $error = &mt('Failed to acquire unique ID for new external tool');
+ $errors .= ''.$error.' ';
+ }
+ }
+ if (ref($domconfig{$action}) 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};
+ if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
+ if ($deletions{$itemid}) {
+ if ($domconfig{$action}{$itemid}{'image'}) {
+ #FIXME need to obsolete item in RES space
+ }
+ $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
+ next;
+ } else {
+ my $newpos = $env{'form.ltitools_'.$itemid};
+ $newpos =~ s/\D+//g;
+ foreach my $item ('title','url') {
+ $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
+ if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
+ $changes{$itemid} = 1;
+ }
+ }
+ foreach my $item ('key','secret') {
+ $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
+ if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
+ $changes{$itemid} = 1;
+ }
+ }
+ if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
+ $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
+ }
+ if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
+ $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
+ }
+ 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+$/) {
+ $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
+ if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
+ if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
+ $changes{$itemid} = 1;
+ }
+ } else {
+ $changes{$itemid} = 1;
+ }
+ } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
+ if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
+ $changes{$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 '') {
+ $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
+ if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
+ if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
+ $changes{$itemid} = 1;
+ }
+ } else {
+ $changes{$itemid} = 1;
+ }
+ } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
+ if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
+ $changes{$itemid} = 1;
+ }
+ }
+ }
+ if ($env{'form.ltitools_target_'.$i} eq 'window') {
+ $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
+ } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
+ $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
+ } else {
+ $confhash{$itemid}{'display'}{'target'} = 'iframe';
+ }
+ if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
+ if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
+ $changes{$itemid} = 1;
+ }
+ } else {
+ $changes{$itemid} = 1;
+ }
+ foreach my $extra ('passback','roster') {
+ if ($env{'form.ltitools_'.$extra.'_'.$i}) {
+ $confhash{$itemid}{$extra} = 1;
+ }
+ if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
+ $changes{$itemid} = 1;
+ }
+ }
+ my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
+ foreach my $item ('label','title','target','linktext','explanation') {
+ if (grep(/^\Q$item\E$/,@courseconfig)) {
+ $confhash{$itemid}{'crsconf'}{$item} = 1;
+ if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
+ if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
+ $changes{$itemid} = 1;
+ }
+ } else {
+ $changes{$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})) {
+ $confhash{$itemid}{'roles'}{$role} = $choice;
+ if ($role eq 'cc') {
+ $confhash{$itemid}{'roles'}{'co'} = $choice;
+ }
+ }
+ if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
+ if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
+ $changes{$itemid} = 1;
+ }
+ } elsif ($confhash{$itemid}{'roles'}{$role}) {
+ $changes{$itemid} = 1;
+ }
+ }
+ } else {
+ $confhash{$itemid}{'fields'}{$field} = 1;
+ if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
+ if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
+ $changes{$itemid} = 1;
+ }
+ } else {
+ $changes{$itemid} = 1;
+ }
+ }
+ }
+ }
+ $allpos[$newpos] = $itemid;
+ }
+ if ($imgdeletions{$itemid}) {
+ $changes{$itemid} = 1;
+ #FIXME need to obsolete item in RES space
+ } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
+ my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
+ $itemid,$configuserok,$switchserver,
+ $author_ok);
+ if ($imgurl) {
+ $confhash{$itemid}{'image'} = $imgurl;
+ $changes{$itemid} = 1;
+ }
+ if ($error) {
+ &Apache::lonnet::logthis($error);
+ $errors .= ''.$error.' ';
+ }
+ } elsif ($domconfig{$action}{$itemid}{'image'}) {
+ $confhash{$itemid}{'image'} =
+ $domconfig{$action}{$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 '') {
+ $confhash{$itemid}{'custom'}{$name} = $value;
+ $changes{$itemid} = 1;
+ }
+ }
+ my %customdels;
+ my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
+ if (@customdeletions) {
+ $changes{$itemid} = 1;
+ }
+ map { $customdels{$_} = 1; } @customdeletions;
+ if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
+ foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
+ unless ($customdels{$key}) {
+ if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
+ $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
+ }
+ if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
+ $changes{$itemid} = 1;
+ }
+ }
+ }
+ }
+ unless ($changes{$itemid}) {
+ foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
+ if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
+ if (ref($confhash{$itemid}{$key}) eq 'HASH') {
+ foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
+ unless (exists($confhash{$itemid}{$key}{$innerkey})) {
+ $changes{$itemid} = 1;
+ last;
+ }
+ }
+ } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
+ $changes{$itemid} = 1;
+ }
+ }
+ last if ($changes{$itemid});
+ }
+ }
+ }
+ }
+ }
+ if (@allpos > 0) {
+ my $idx = 0;
+ foreach my $itemid (@allpos) {
+ if ($itemid ne '') {
+ $confhash{$itemid}{'order'} = $idx;
+ if (ref($domconfig{$action}) eq 'HASH') {
+ if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
+ if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
+ $changes{$itemid} = 1;
+ }
+ }
+ }
+ $idx ++;
+ }
+ }
+ }
+ my %ltitoolshash = (
+ $action => { %confhash }
+ );
+ my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
+ $dom);
+ if ($putresult eq 'ok') {
+ my %ltienchash = (
+ $action => { %encconfig }
+ );
+ &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
+ if (keys(%changes) > 0) {
+ my $cachetime = 24*60*60;
+ my %ltiall = %confhash;
+ foreach my $id (keys(%ltiall)) {
+ if (ref($encconfig{$id}) eq 'HASH') {
+ foreach my $item ('key','secret') {
+ $ltiall{$id}{$item} = $encconfig{$id}{$item};
+ }
+ }
+ }
+ &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
+ if (ref($lastactref) eq 'HASH') {
+ $lastactref->{'ltitools'} = 1;
+ }
+ $resulttext = &mt('Changes made:').'';
+ my %bynum;
+ foreach my $itemid (sort(keys(%changes))) {
+ my $position = $confhash{$itemid}{'order'};
+ $bynum{$position} = $itemid;
+ }
+ foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
+ my $itemid = $bynum{$pos};
+ if (ref($confhash{$itemid}) ne 'HASH') {
+ $resulttext .= ''.&mt('Deleted: [_1]',$changes{$itemid}).' ';
+ } else {
+ $resulttext .= ''.$confhash{$itemid}{'title'}.' ';
+ if ($confhash{$itemid}{'image'}) {
+ $resulttext .= ' '.
+ ' ';
+ }
+ $resulttext .= '';
+ my $position = $pos + 1;
+ $resulttext .= ''.&mt('Order: [_1]',$position).' ';
+ foreach my $item ('version','msgtype','url') {
+ if ($confhash{$itemid}{$item} ne '') {
+ $resulttext .= ''.$lt{$item}.': '.$confhash{$itemid}{$item}.' ';
+ }
+ }
+ if ($encconfig{$itemid}{'key'} ne '') {
+ $resulttext .= ''.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.' ';
+ }
+ if ($encconfig{$itemid}{'secret'} ne '') {
+ $resulttext .= ''.$lt{'secret'}.': ';
+ my $num = length($encconfig{$itemid}{'secret'});
+ $resulttext .= ('*'x$num).' ';
+ }
+ $resulttext .= ''.&mt('Configurable in course:');
+ my @possconfig = ('label','title','target','linktext','explanation');
+ my $numconfig = 0;
+ if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
+ foreach my $item (@possconfig) {
+ if ($confhash{$itemid}{'crsconf'}{$item}) {
+ $numconfig ++;
+ $resulttext .= ' "'.$lt{'crs'.$item}.'"';
+ }
+ }
+ }
+ if (!$numconfig) {
+ $resulttext .= &mt('None');
+ }
+ $resulttext .= ' ';
+ foreach my $item ('passback','roster') {
+ $resulttext .= ''.$lt{$item}.' ';
+ if ($confhash{$itemid}{$item}) {
+ $resulttext .= &mt('Yes');
+ } else {
+ $resulttext .= &mt('No');
+ }
+ $resulttext .= ' ';
+ }
+ if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
+ my $displaylist;
+ if ($confhash{$itemid}{'display'}{'target'}) {
+ $displaylist = &mt('Display target').': '.
+ $confhash{$itemid}{'display'}{'target'}.',';
+ }
+ foreach my $size ('width','height') {
+ if ($confhash{$itemid}{'display'}{$size}) {
+ $displaylist .= (' 'x2).$lt{$size}.': '.
+ $confhash{$itemid}{'display'}{$size}.',';
+ }
+ }
+ if ($displaylist) {
+ $displaylist =~ s/,$//;
+ $resulttext .= ''.$displaylist.' ';
+ }
+ foreach my $item ('linktext','explanation') {
+ if ($confhash{$itemid}{'display'}{$item}) {
+ $resulttext .= ''.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.' ';
+ }
+ }
+ }
+ if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
+ my $fieldlist;
+ foreach my $field (@allfields) {
+ if ($confhash{$itemid}{'fields'}{$field}) {
+ $fieldlist .= (' 'x2).$lt{$field}.',';
+ }
+ }
+ if ($fieldlist) {
+ $fieldlist =~ s/,$//;
+ $resulttext .= ''.&mt('Data sent').':'.$fieldlist.' ';
+ }
+ }
+ if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
+ my $rolemaps;
+ foreach my $role (@courseroles) {
+ if ($confhash{$itemid}{'roles'}{$role}) {
+ $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
+ $confhash{$itemid}{'roles'}{$role}.',';
+ }
+ }
+ if ($rolemaps) {
+ $rolemaps =~ s/,$//;
+ $resulttext .= ''.&mt('Role mapping:').$rolemaps.' ';
+ }
+ }
+ if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
+ my $customlist;
+ if (keys(%{$confhash{$itemid}{'custom'}})) {
+ foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
+ $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
+ }
+ }
+ if ($customlist) {
+ $resulttext .= ''.&mt('Custom items').':'.$customlist.' ';
+ }
+ }
+ $resulttext .= ' ';
+ }
+ }
+ $resulttext .= ' ';
+ } else {
+ $resulttext = &mt('No changes made.');
+ }
+ } else {
+ $errors .= ''.&mt('Failed to save changes').' ';
+ }
+ if ($errors) {
+ $resulttext .= &mt('The following errors occurred: ').'';
+ }
+ return $resulttext;
+}
+
+sub process_ltitools_image {
+ my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
+ my $filename = $env{'form.'.$caller.'.filename'};
+ my ($error,$url);
+ my ($width,$height) = (21,21);
+ if ($configuserok eq 'ok') {
+ if ($switchserver) {
+ $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
+ $switchserver);
+ } elsif ($author_ok eq 'ok') {
+ my ($result,$imageurl,$madethumb) =
+ &publishlogo($r,'upload',$caller,$dom,$confname,
+ "ltitools/$itemid/icon",$width,$height);
+ if ($result eq 'ok') {
+ if ($madethumb) {
+ my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
+ my $imagethumb = "$path/tn-".$imagefile;
+ $url = $imagethumb;
+ } else {
+ $url = $imageurl;
+ }
+ } else {
+ $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 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 get_ltitools_id {
+ my ($cdom,$title) = @_;
+ # get lock on ltitools db
+ my $lockhash = {
+ lock => $env{'user.name'}.
+ ':'.$env{'user.domain'},
+ };
+ my $tries = 0;
+ my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
+ my ($id,$error);
+
+ while (($gotlock ne 'ok') && ($tries<10)) {
+ $tries ++;
+ sleep (0.1);
+ $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
+ }
+ if ($gotlock eq 'ok') {
+ my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
+ 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;
+ }
+ if ($id) {
+ unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
+ $error = 'nostore';
+ }
+ } else {
+ $error = 'nonumber';
+ }
+ }
+ my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
+ } else {
+ $error = 'nolock';
+ }
+ return ($id,$error);
+}
+
sub modify_autoenroll {
my ($dom,$lastactref,%domconfig) = @_;
my ($resulttext,%changes);
@@ -9304,17 +10548,57 @@ sub modify_contacts {
my $value = $env{'form.helpform_'.$field};
$value =~ s/^\s+|\s+$//g;
if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
- $contacts_hash{contacts}{'helpform'}{$field} = $value;
+ $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
if ($field eq 'screenshot') {
$env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
- $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
+ $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
}
}
}
}
}
}
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
+ my (@statuses,%usertypeshash,@overrides);
+ if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
+ @statuses = @{$types};
+ if (ref($usertypes) eq 'HASH') {
+ %usertypeshash = %{$usertypes};
+ }
+ }
+ if (@statuses) {
+ my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
+ foreach my $type (@possoverrides) {
+ if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
+ push(@overrides,$type);
+ }
+ }
+ if (@overrides) {
+ foreach my $type (@overrides) {
+ my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
+ foreach my $item (@contacts) {
+ if (grep(/^\Q$item\E$/,@standard)) {
+ $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
+ $newsetting{'override_'.$type}{$item} = 1;
+ } else {
+ $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
+ $newsetting{'override_'.$type}{$item} = 0;
+ }
+ }
+ $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
+ $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
+ $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
+ $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
+ if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
+ $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
+ $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
+ $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
+ $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
+ }
+ }
+ }
+ }
if (keys(%currsetting) > 0) {
foreach my $item (@contacts) {
if ($to{$item} ne $currsetting{$item}) {
@@ -9369,6 +10653,33 @@ sub modify_contacts {
}
}
}
+ if (@statuses) {
+ if (ref($currsetting{'overrides'}) eq 'HASH') {
+ foreach my $key (keys(%{$currsetting{'overrides'}})) {
+ if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
+ if (ref($newsetting{'override_'.$key}) eq 'HASH') {
+ foreach my $item (@contacts,'bcc','others','include') {
+ if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
+ push(@{$changes{'overrides'}},$key);
+ last;
+ }
+ }
+ } else {
+ push(@{$changes{'overrides'}},$key);
+ }
+ }
+ }
+ foreach my $key (@overrides) {
+ unless (exists($currsetting{'overrides'}{$key})) {
+ push(@{$changes{'overrides'}},$key);
+ }
+ }
+ } else {
+ foreach my $key (@overrides) {
+ push(@{$changes{'overrides'}},$key);
+ }
+ }
+ }
} else {
my %default;
$default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
@@ -9483,6 +10794,60 @@ sub modify_contacts {
$resulttext .= '';
}
}
+ if (ref($changes{'overrides'}) eq 'ARRAY') {
+ my @deletions;
+ foreach my $type (@{$changes{'overrides'}}) {
+ if ($usertypeshash{$type}) {
+ if (grep(/^\Q$type\E/,@overrides)) {
+ $resulttext .= ''.&mt("Overrides based on requester's affiliation set for [_1]",
+ $usertypeshash{$type}).'';
+ if (ref($newsetting{'override_'.$type}) eq 'HASH') {
+ my @text;
+ foreach my $item (@contacts) {
+ if ($newsetting{'override_'.$type}{$item}) {
+ push(@text,$short_titles->{$item});
+ }
+ }
+ if ($newsetting{'override_'.$type}{'others'} ne '') {
+ push(@text,$newsetting{'override_'.$type}{'others'});
+ }
+
+ if (@text) {
+ $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
+ ''.join(', ',@text).' ');
+ }
+ if ($newsetting{'override_'.$type}{'bcc'} ne '') {
+ my $bcctext;
+ if (@text) {
+ $bcctext = ' '.&mt('with Bcc to');
+ } else {
+ $bcctext = '(Bcc)';
+ }
+ $resulttext .= $bcctext.': '.$newsetting{'override_'.$type}{'bcc'}.' ';
+ } elsif (!@text) {
+ $resulttext .= &mt('Helpdesk e-mail sent to no one');
+ }
+ $resulttext .= ' ';
+ if ($newsetting{'override_'.$type}{'include'} ne '') {
+ my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
+ if ($loc eq 'b') {
+ $resulttext .= ''.&mt('Text automatically added to e-mail body:').' '.&unescape($str).' ';
+ } elsif ($loc eq 's') {
+ $resulttext .= ''.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).' ';
+ }
+ }
+ }
+ $resulttext .= ' ';
+ } else {
+ push(@deletions,$usertypeshash{$type});
+ }
+ }
+ }
+ if (@deletions) {
+ $resulttext .= ''.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
+ join(', ',@deletions)).' ';
+ }
+ }
my @offon = ('off','on');
if ($changes{'reporterrors'}) {
$resulttext .= ''.
@@ -9538,7 +10903,6 @@ sub modify_contacts {
&mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
$contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
' ';
-
}
}
$resulttext .= '';
@@ -10132,7 +11496,7 @@ sub modify_selfcreation {
$save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
}
$save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
- $save_usercreate{'emailrule'} = \@email_rule;
+ $save_usercreate{'email_rule'} = \@email_rule;
my %userconfig_hash = (
usercreation => \%save_usercreate,
@@ -13568,7 +14932,7 @@ sub devalidate_remote_domconfs {
my %servers = &Apache::lonnet::internet_dom_servers($dom);
my %thismachine;
map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
- my @posscached = ('domainconfig','domdefaults','usersessions','directorysrch');
+ my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
if (keys(%servers)) {
foreach my $server (keys(%servers)) {
next if ($thismachine{$server});