[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface domainprefs.pm
raeburn
raeburn at source.lon-capa.org
Fri May 9 11:23:29 EDT 2014
raeburn Fri May 9 15:23:29 2014 EDT
Modified files: (Branch: version_2_11_X)
/loncom/interface domainprefs.pm
Log:
- For 2.11
- Backport 1.242.
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.160.6.45 loncom/interface/domainprefs.pm:1.160.6.46
--- loncom/interface/domainprefs.pm:1.160.6.45 Mon May 5 23:34:42 2014
+++ loncom/interface/domainprefs.pm Fri May 9 15:23:28 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.160.6.45 2014/05/05 23:34:42 raeburn Exp $
+# $Id: domainprefs.pm,v 1.160.6.46 2014/05/09 15:23:28 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -369,6 +369,8 @@
col2 => 'Value'},
{col1 => 'Available textbooks',
col2 => ''},
+ {col1 => 'Available templates',
+ col2 => ''},
{col1 => 'Validation (not official courses)',
col2 => 'Value'},],
print => \&print_quotas,
@@ -753,7 +755,18 @@
<tr class="LC_info_row">
<td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
<td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
- &print_textbookcourses($dom,$settings,\$rowtotal).'
+ &textbookcourses_javascript($settings).
+ &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <table class="LC_nested">
+ <tr class="LC_info_row">
+ <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
+ <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
+ &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
</table>
</td>
</tr>
@@ -761,8 +774,8 @@
<td>
<table class="LC_nested">
<tr class="LC_info_row">
- <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
- <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
+ <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
+ <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
</tr>'.
&print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
} elsif ($action eq 'requestauthor') {
@@ -2075,14 +2088,14 @@
}
sub print_textbookcourses {
- my ($dom,$settings,$rowtotal) = @_;
+ my ($dom,$type,$settings,$rowtotal) = @_;
my $rownum = 0;
my $css_class;
my $itemcount = 1;
my $maxnum = 0;
my $bookshash;
if (ref($settings) eq 'HASH') {
- $bookshash = $settings->{'textbooks'};
+ $bookshash = $settings->{$type};
}
my %ordered;
if (ref($bookshash) eq 'HASH') {
@@ -2095,8 +2108,8 @@
}
my $confname = $dom.'-domainconfig';
my $switchserver = &check_switchserver($dom,$confname);
- $maxnum = scalar(keys(%ordered));
- my $datatable = &textbookcourses_javascript(\%ordered);
+ my $maxnum = scalar(keys(%ordered));
+ my $datatable;
if (keys(%ordered)) {
my @items = sort { $a <=> $b } keys(%ordered);
for (my $i=0; $i<@items; $i++) {
@@ -2108,17 +2121,19 @@
if (ref($bookshash->{$key}) eq 'HASH') {
$subject = $bookshash->{$key}->{'subject'};
$title = $bookshash->{$key}->{'title'};
- $author = $bookshash->{$key}->{'author'};
- $image = $bookshash->{$key}->{'image'};
- if ($image ne '') {
- my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
- my $imagethumb = "$path/tn-".$imagefile;
- $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
+ if ($type eq 'textbooks') {
+ $author = $bookshash->{$key}->{'author'};
+ $image = $bookshash->{$key}->{'image'};
+ if ($image ne '') {
+ my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
+ my $imagethumb = "$path/tn-".$imagefile;
+ $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
+ }
}
}
- my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
+ my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
$datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
- .'<select name="'.$key.'"'.$chgstr.'>';
+ .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
for (my $k=0; $k<=$maxnum; $k++) {
my $vpos = $k+1;
my $selstr;
@@ -2128,39 +2143,41 @@
$datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
}
$datatable .= '</select>'.(' 'x2).
- '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
+ '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
&mt('Delete?').'</label></span></td>'.
'<td colspan="2">'.
- '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
- (' 'x2).
- '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
+ '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
(' 'x2).
- '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
- (' 'x2).
- '<span class="LC_nobreak">'.&mt('Thumbnail:');
- if ($image) {
- $datatable .= '<span class="LC_nobreak">'.
- $imgsrc.
- '<label><input type="checkbox" name="book_image_del"'.
- ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
- '<span class="LC_nobreak"> '.&mt('Replace:').' ';
- }
- if ($switchserver) {
- $datatable .= &mt('Upload to library server: [_1]',$switchserver);
- } else {
- $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
+ '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
+ if ($type eq 'textbooks') {
+ $datatable .= (' 'x2).
+ '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
+ (' 'x2).
+ '<span class="LC_nobreak">'.&mt('Thumbnail:');
+ if ($image) {
+ $datatable .= '<span class="LC_nobreak">'.
+ $imgsrc.
+ '<label><input type="checkbox" name="'.$type.'_image_del"'.
+ ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
+ '<span class="LC_nobreak"> '.&mt('Replace:').' ';
+ }
+ if ($switchserver) {
+ $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+ } else {
+ $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
+ }
}
- $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
+ $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
'<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
$coursetitle.'</span></td></tr>'."\n";
$itemcount ++;
}
}
$css_class = $itemcount%2?' class="LC_odd_row"':'';
- my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
+ my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
$datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
- '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
- '<select name="addbook_pos"'.$chgstr.'>';
+ '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
+ '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
for (my $k=0; $k<$maxnum+1; $k++) {
my $vpos = $k+1;
my $selstr;
@@ -2170,26 +2187,28 @@
$datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
}
$datatable .= '</select> '."\n".
- '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
+ '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
'<td colspan="2">'.
- '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
+ '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
(' 'x2).
- '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
- (' 'x2).
- '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
- (' 'x2).
- '<span class="LC_nobreak">'.&mt('Image:').' ';
- if ($switchserver) {
- $datatable .= &mt('Upload to library server: [_1]',$switchserver);
- } else {
- $datatable .= '<input type="file" name="addbook_image" value="" />';
+ '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
+ (' 'x2);
+ if ($type eq 'textbooks') {
+ $datatable .= '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
+ (' 'x2).
+ '<span class="LC_nobreak">'.&mt('Image:').' ';
+ if ($switchserver) {
+ $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+ } else {
+ $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
+ }
}
$datatable .= '</span>'."\n".
'<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
- &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
- '<input type="text" size="25" name="addbook_cnum" value="" />'.
+ &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
+ '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
&Apache::loncommon::selectcourse_link
- ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
+ ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
'</span></td>'."\n".
'</tr>'."\n";
$itemcount ++;
@@ -2197,23 +2216,43 @@
}
sub textbookcourses_javascript {
- my ($textbooks) = @_;
- return unless(ref($textbooks) eq 'HASH');
- my $num = scalar(keys(%{$textbooks}));
- my @jsarray;
- foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
- push(@jsarray,$textbooks->{$item});
+ my ($settings) = @_;
+ return unless(ref($settings) eq 'HASH');
+ my (%ordered,%total,%jstext);
+ foreach my $type ('textbooks','templates') {
+ $total{$type} = 0;
+ if (ref($settings->{$type}) eq 'HASH') {
+ foreach my $item (keys(%{$settings->{$type}})) {
+ if (ref($settings->{$type}->{$item}) eq 'HASH') {
+ my $num = $settings->{$type}->{$item}{'order'};
+ $ordered{$type}{$num} = $item;
+ }
+ }
+ $total{$type} = scalar(keys(%{$settings->{$type}}));
+ }
+ my @jsarray = ();
+ foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
+ push(@jsarray,$ordered{$type}{$item});
+ }
+ $jstext{$type} = ' var '.$type.' = Array('."'".join("','", at jsarray)."'".');'."\n";
}
- my $jstext = ' var textbooks = Array('."'".join("','", at jsarray)."'".');'."\n";
return <<"ENDSCRIPT";
<script type="text/javascript">
// <![CDATA[
-function reorderBooks(form,item) {
+function reorderBooks(form,item,caller) {
var changedVal;
-$jstext
- var newpos = 'addbook_pos';
+$jstext{'textbooks'};
+$jstext{'templates'};
+ var newpos;
+ var maxh;
+ if (caller == 'textbooks') {
+ newpos = 'textbooks_addbook_pos';
+ maxh = 1 + $total{'textbooks'};
+ } else {
+ newpos = 'templates_addbook_pos';
+ maxh = 1 + $total{'templates'};
+ }
var current = new Array;
- var maxh = 1 + $num;
var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
if (item == newpos) {
changedVal = newitemVal;
@@ -2221,12 +2260,25 @@
changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
current[newitemVal] = newpos;
}
- for (var i=0; i<textbooks.length; i++) {
- var elementName = textbooks[i];
- if (elementName != item) {
- if (form.elements[elementName]) {
- var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
- current[currVal] = elementName;
+ if (caller == 'textbooks') {
+ for (var i=0; i<textbooks.length; i++) {
+ var elementName = 'textbooks_'+textbooks[i];
+ if (elementName != item) {
+ if (form.elements[elementName]) {
+ var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
+ current[currVal] = elementName;
+ }
+ }
+ }
+ }
+ if (caller == 'templates') {
+ for (var i=0; i<templates.length; i++) {
+ var elementName = 'templates_'+templates[i];
+ if (elementName != item) {
+ if (form.elements[elementName]) {
+ var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
+ current[currVal] = elementName;
+ }
}
}
}
@@ -6812,29 +6864,35 @@
$confhash{'uniquecode'}{$type} = 1;
}
}
- my ($newbook, at allpos);
+ my (%newbook,%allpos);
if ($context eq 'requestcourses') {
- if ($env{'form.addbook'}) {
- if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
- ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
- if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
- $env{'form.addbook_cdom'}) eq 'no_host') {
- $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
- '</span></li>';
- } else {
- $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
- my $position = $env{'form.addbook_pos'};
- $position =~ s/\D+//g;
- if ($position ne '') {
- $allpos[$position] = $newbook;
+ foreach my $type ('textbooks','templates') {
+ @{$allpos{$type}} = ();
+ my $invalid;
+ if ($type eq 'textbooks') {
+ $invalid = &mt('Invalid LON-CAPA course for textbook');
+ } else {
+ $invalid = &mt('Invalid LON-CAPA course for template');
+ }
+ if ($env{'form.'.$type.'_addbook'}) {
+ if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
+ ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
+ if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
+ $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
+ $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
+ } else {
+ $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
+ my $position = $env{'form.'.$type.'_addbook_pos'};
+ $position =~ s/\D+//g;
+ if ($position ne '') {
+ $allpos{$type}[$position] = $newbook{$type};
+ }
}
+ } else {
+ $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
}
- } else {
- $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
- '</span></li>';
}
- }
-
+ }
}
if (ref($domconfig{$action}) eq 'HASH') {
if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
@@ -6867,56 +6925,60 @@
$changes{'uniquecode'} = 1;
}
if ($context eq 'requestcourses') {
- if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
- my %deletions;
- my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
- if (@todelete) {
- map { $deletions{$_} = 1; } @todelete;
- }
- my %imgdeletions;
- my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
- if (@todeleteimages) {
- map { $imgdeletions{$_} = 1; } @todeleteimages;
- }
- my $maxnum = $env{'form.book_maxnum'};
- for (my $i=0; $i<=$maxnum; $i++) {
- my $key = $env{'form.book_id_'.$i};
- if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
- if ($deletions{$key}) {
- if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
- #FIXME need to obsolete item in RES space
+ foreach my $type ('textbooks','templates') {
+ if (ref($domconfig{$action}{$type}) eq 'HASH') {
+ my %deletions;
+ my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
+ if (@todelete) {
+ map { $deletions{$_} = 1; } @todelete;
+ }
+ my %imgdeletions;
+ my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
+ if (@todeleteimages) {
+ map { $imgdeletions{$_} = 1; } @todeleteimages;
+ }
+ my $maxnum = $env{'form.'.$type.'_maxnum'};
+ for (my $i=0; $i<=$maxnum; $i++) {
+ my $itemid = $env{'form.'.$type.'_id_'.$i};
+ my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
+ if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
+ if ($deletions{$key}) {
+ if ($domconfig{$action}{$type}{$key}{'image'}) {
+ #FIXME need to obsolete item in RES space
+ }
+ next;
+ } else {
+ my $newpos = $env{'form.'.$itemid};
+ $newpos =~ s/\D+//g;
+ foreach my $item ('subject','title','author') {
+ next if (($item eq 'author') && ($type eq 'templates'));
+ $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
+ if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
+ $changes{$type}{$key} = 1;
+ }
+ }
+ $allpos{$type}[$newpos] = $key;
}
- next;
- } else {
- my $newpos = $env{'form.'.$key};
- $newpos =~ s/\D+//g;
- foreach my $item ('subject','title','author') {
- $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
- if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
- $changes{'textbooks'}{$key} = 1;
+ if ($imgdeletions{$key}) {
+ $changes{$type}{$key} = 1;
+ #FIXME need to obsolete item in RES space
+ } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
+ my ($cdom,$cnum) = split(/_/,$key);
+ my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
+ $cdom,$cnum,$type,$configuserok,
+ $switchserver,$author_ok);
+ if ($imgurl) {
+ $confhash{$type}{$key}{'image'} = $imgurl;
+ $changes{$type}{$key} = 1;
}
+ if ($error) {
+ &Apache::lonnet::logthis($error);
+ $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
+ }
+ } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
+ $confhash{$type}{$key}{'image'} =
+ $domconfig{$action}{$type}{$key}{'image'};
}
- $allpos[$newpos] = $key;
- }
- if ($imgdeletions{$key}) {
- $changes{'textbooks'}{$key} = 1;
- #FIXME need to obsolete item in RES space
- } elsif ($env{'form.book_image_'.$i.'.filename'}) {
- my ($cdom,$cnum) = split(/_/,$key);
- my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
- $cdom,$cnum,$configuserok,
- $switchserver,$author_ok);
- if ($imgurl) {
- $confhash{'textbooks'}{$key}{'image'} = $imgurl;
- $changes{'textbooks'}{$key} = 1;
- }
- if ($error) {
- &Apache::lonnet::logthis($error);
- $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
- }
- } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
- $confhash{'textbooks'}{$key}{'image'} =
- $domconfig{$action}{'textbooks'}{$key}{'image'};
}
}
}
@@ -6931,43 +6993,48 @@
}
}
if ($context eq 'requestcourses') {
- if ($newbook) {
- $changes{'textbooks'}{$newbook} = 1;
- foreach my $item ('subject','title','author') {
- $env{'form.addbook_'.$item} =~ s/(`)/'/g;
- if ($env{'form.addbook_'.$item}) {
- $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
- }
- }
- if ($env{'form.addbook_image.filename'} ne '') {
- my ($cdom,$cnum) = split(/_/,$newbook);
- my ($imageurl,$error) =
- &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
- $switchserver,$author_ok);
- if ($imageurl) {
- $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
- }
- if ($error) {
- &Apache::lonnet::logthis($error);
- $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
+ foreach my $type ('textbooks','templates') {
+ if ($newbook{$type}) {
+ $changes{$type}{$newbook{$type}} = 1;
+ foreach my $item ('subject','title','author') {
+ next if (($item eq 'author') && ($type eq 'template'));
+ $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
+ if ($env{'form.'.$type.'_addbook_'.$item}) {
+ $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
+ }
+ }
+ if ($type eq 'textbooks') {
+ if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
+ my ($cdom,$cnum) = split(/_/,$newbook{$type});
+ my ($imageurl,$error) =
+ &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
+ $configuserok,$switchserver,$author_ok);
+ if ($imageurl) {
+ $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
+ }
+ if ($error) {
+ &Apache::lonnet::logthis($error);
+ $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
+ }
+ }
}
}
- }
- if (@allpos > 0) {
- my $idx = 0;
- foreach my $item (@allpos) {
- if ($item ne '') {
- $confhash{'textbooks'}{$item}{'order'} = $idx;
- if (ref($domconfig{$action}) eq 'HASH') {
- if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
- if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
- if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
- $changes{'textbooks'}{$item} = 1;
+ if (@{$allpos{$type}} > 0) {
+ my $idx = 0;
+ foreach my $item (@{$allpos{$type}}) {
+ if ($item ne '') {
+ $confhash{$type}{$item}{'order'} = $idx;
+ if (ref($domconfig{$action}) eq 'HASH') {
+ if (ref($domconfig{$action}{$type}) eq 'HASH') {
+ if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
+ if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
+ $changes{$type}{$item} = 1;
+ }
}
}
}
+ $idx ++;
}
- $idx ++;
}
}
}
@@ -7184,7 +7251,7 @@
$domdefaults{'requestauthor'} = \%confhash;
} else {
foreach my $key (keys(%confhash)) {
- unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
+ unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
$domdefaults{$key} = $confhash{$key};
}
}
@@ -7336,27 +7403,32 @@
'</li>';
}
}
- if (ref($changes{'textbooks'}) eq 'HASH') {
- $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
- foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
- my %coursehash = &Apache::lonnet::coursedescription($key);
- my $coursetitle = $coursehash{'description'};
- my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
- $resulttext .= '<li>';
- foreach my $item ('subject','title','author') {
- my $name = $item.':';
- $name =~ s/^(\w)/\U$1/;
- $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
- }
- $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
- if ($confhash{'textbooks'}{$key}{'image'}) {
- $resulttext .= ' '.&mt('Image: [_1]',
- '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
- ' alt="Textbook cover" />').'<br />';
+ foreach my $type ('textbooks','templates') {
+ if (ref($changes{$type}) eq 'HASH') {
+ $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
+ foreach my $key (sort(keys(%{$changes{$type}}))) {
+ my %coursehash = &Apache::lonnet::coursedescription($key);
+ my $coursetitle = $coursehash{'description'};
+ my $position = $confhash{$type}{$key}{'order'} + 1;
+ $resulttext .= '<li>';
+ foreach my $item ('subject','title','author') {
+ next if (($item eq 'author') && ($type eq 'templates'));
+ my $name = $item.':';
+ $name =~ s/^(\w)/\U$1/;
+ $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
+ }
+ $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
+ if ($type eq 'textbooks') {
+ if ($confhash{$type}{$key}{'image'}) {
+ $resulttext .= ' '.&mt('Image: [_1]',
+ '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
+ ' alt="Textbook cover" />').'<br />';
+ }
+ }
+ $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
}
- $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
+ $resulttext .= '</ul></li>';
}
- $resulttext .= '</ul></li>';
}
if (ref($changes{'validation'}) eq 'HASH') {
if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
@@ -7404,7 +7476,7 @@
}
sub process_textbook_image {
- my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
+ my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
my $filename = $env{'form.'.$caller.'.filename'};
my ($error,$url);
my ($width,$height) = (50,50);
@@ -7415,7 +7487,7 @@
} elsif ($author_ok eq 'ok') {
my ($result,$imageurl) =
&publishlogo($r,'upload',$caller,$dom,$confname,
- "textbooks/$dom/$cnum/cover",$width,$height);
+ "$type/$dom/$cnum/cover",$width,$height);
if ($result eq 'ok') {
$url = $imageurl;
} else {
More information about the LON-CAPA-cvs
mailing list