--- loncom/interface/domainprefs.pm 2014/04/28 01:48:04 1.238 +++ loncom/interface/domainprefs.pm 2015/06/09 21:22:55 1.265 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.238 2014/04/28 01:48:04 raeburn Exp $ +# $Id: domainprefs.pm,v 1.265 2015/06/09 21:22:55 damieng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -250,6 +250,8 @@ sub handler { header => [{col1 => 'Log-in Page Items', col2 => '',}, {col1 => 'Log-in Help', + col2 => 'Value'}, + {col1 => 'Custom HTML in document head', col2 => 'Value'}], print => \&print_login, modify => \&modify_login, @@ -369,6 +371,8 @@ sub handler { col2 => 'Value'}, {col1 => 'Available textbooks', col2 => ''}, + {col1 => 'Available templates', + col2 => ''}, {col1 => 'Validation (not official courses)', col2 => 'Value'},], print => \&print_quotas, @@ -477,6 +481,8 @@ sub handler { {col1 => 'Log-in Page Items', col2 => ''}, {col1 => 'Log-in Help', + col2 => 'Value'}, + {col1 => 'Custom HTML in document head', col2 => 'Value'}], print => \&print_login, modify => \&modify_login, @@ -622,7 +628,7 @@ sub process_changes { } elsif ($action eq 'scantron') { $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig); } elsif ($action eq 'coursecategories') { - $output = &modify_coursecategories($dom,%domconfig); + $output = &modify_coursecategories($dom,$lastactref,%domconfig); } elsif ($action eq 'serverstatuses') { $output = &modify_serverstatuses($dom,%domconfig); } elsif ($action eq 'requestcourses') { @@ -668,7 +674,7 @@ sub print_config_box { my $colspan = ''; my $rightcolspan = ''; if (($action eq 'rolecolors') || ($action eq 'defaults') || - (($action eq 'login') && ($numheaders < 3))) { + (($action eq 'login') && ($numheaders < 4))) { $colspan = ' colspan="2"'; } if ($action eq 'usersessions') { @@ -690,7 +696,7 @@ sub print_config_box { } elsif ($action eq 'coursecategories') { $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal); } elsif ($action eq 'login') { - if ($numheaders == 3) { + if ($numheaders == 4) { $colspan = ' colspan="2"'; $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal); } else { @@ -743,7 +749,7 @@ sub print_config_box { ($action eq 'defaults')) { $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal); } elsif ($action eq 'login') { - if ($numheaders == 3) { + if ($numheaders == 4) { $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).' @@ -759,9 +765,31 @@ sub print_config_box { } else { $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal); } + $output .= ' + + + + + + + '; + if ($numheaders == 4) { + $output .= ' + + + '; + } else { + $output .= ' + + + '; + } + $rowtotal ++; + $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal); } elsif ($action eq 'requestcourses') { - $output .= &print_requestmail($dom,$action,$settings,\$rowtotal). - &print_studentcode($settings,\$rowtotal).' + $output .= &print_requestmail($dom,$action,$settings,\$rowtotal); + $rowtotal ++; + $output .= &print_studentcode($settings,\$rowtotal).'
'.&mt($item->{'header'}->[3]->{'col1'}).''.&mt($item->{'header'}->[3]->{'col2'}).'
'.&mt($item->{'header'}->[2]->{'col1'}).''.&mt($item->{'header'}->[2]->{'col2'}).'
@@ -771,7 +799,18 @@ sub print_config_box { '.&mt($item->{'header'}->[2]->{'col1'}).' '.&mt($item->{'header'}->[2]->{'col2'}).' '. - &print_textbookcourses($dom,$settings,\$rowtotal).' + &textbookcourses_javascript($settings). + &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).' + + + + + + + + + '. + &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
'.&mt($item->{'header'}->[3]->{'col1'}).''.&mt($item->{'header'}->[3]->{'col2'}).'
@@ -779,12 +818,13 @@ sub print_config_box { - - + + '. &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal); } elsif ($action eq 'requestauthor') { $output .= &print_requestmail($dom,$action,$settings,\$rowtotal); + $rowtotal ++; } elsif ($action eq 'rolecolors') { $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
'.&mt($item->{'header'}->[3]->{'col1'}).''.&mt($item->{'header'}->[3]->{'col2'}).''.&mt($item->{'header'}->[4]->{'col1'}).''.&mt($item->{'header'}->[4]->{'col2'}).'
@@ -1166,6 +1206,57 @@ sub print_login { $itemcount ++; } $datatable .= &captcha_choice('login',$settings,$itemcount); + } elsif ($caller eq 'headtag') { + my %domservers = &Apache::lonnet::get_servers($dom); + my $choice = $choices{'headtag'}; + $css_class = ' class="LC_odd_row"'; + $datatable .= ''.$choice.''. + ''. + ''. + ''. + ''."\n"; + my (%currurls,%currexempt); + if (ref($settings) eq 'HASH') { + if (ref($settings->{'headtag'}) eq 'HASH') { + foreach my $lonhost (keys(%{$settings->{'headtag'}})) { + if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') { + $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'}; + $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'}; + } + } + } + } + my %lt = &Apache::lonlocal::texthash( + del => 'Delete?', + rep => 'Replace:', + upl => 'Upload:', + curr => 'View contents', + none => 'None', + ); + my $switchserver = &check_switchserver($dom,$confname); + foreach my $lonhost (sort(keys(%domservers))) { + my $exempt = &check_exempt_addresses($currexempt{$lonhost}); + $datatable .= ''; + if ($currurls{$lonhost}) { + $datatable .= ''. + ''; + } + $datatable .= '
'.$choices{'hostid'}.''.$choices{'current'}.''.$choices{'action'}.''.$choices{'exempt'}.'
'.$domservers{$lonhost}.''.$lt{'curr'}.' '.$lt{'rep'}.''; + } else { + $datatable .= ''.$lt{'none'}.''.$lt{'upl'}; + } + $datatable .='
'; + if ($switchserver) { + $datatable .= &mt('Upload to library server: [_1]',$switchserver); + } else { + $datatable .= ''; + } + $datatable .= '
'; } return $datatable; } @@ -1199,6 +1290,9 @@ sub login_choices { link => "Link", alink => "Active link", vlink => "Visited link", + headtag => "Custom markup", + action => "Action", + current => "Current", ); return %choices; } @@ -2061,7 +2155,6 @@ sub print_requestmail { $datatable .= &mt('There are no active Domain Coordinators'); } $datatable .=''; - $$rowtotal += $rows; return $datatable; } @@ -2070,9 +2163,11 @@ sub print_studentcode { my $rownum = 0; my ($output,%current); my @crstypes = ('official','unofficial','community','textbook'); - if (ref($settings->{'uniquecode'}) eq 'HASH') { - foreach my $type (@crstypes) { - $current{$type} = $settings->{'uniquecode'}{$type}; + if (ref($settings) eq 'HASH') { + if (ref($settings->{'uniquecode'}) eq 'HASH') { + foreach my $type (@crstypes) { + $current{$type} = $settings->{'uniquecode'}{$type}; + } } } $output .= ''. @@ -2093,14 +2188,14 @@ sub print_studentcode { } 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') { @@ -2113,8 +2208,8 @@ sub print_textbookcourses { } 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++) { @@ -2122,21 +2217,24 @@ sub print_textbookcourses { my $key = $ordered{$items[$i]}; my %coursehash=&Apache::lonnet::coursedescription($key); my $coursetitle = $coursehash{'description'}; - my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum); + my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum); 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 = ''.&mt('Textbook image').''; + if ($type eq 'textbooks') { + $publisher = $bookshash->{$key}->{'publisher'}; + $author = $bookshash->{$key}->{'author'}; + $image = $bookshash->{$key}->{'image'}; + if ($image ne '') { + my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$}); + my $imagethumb = "$path/tn-".$imagefile; + $imgsrc = ''.&mt('Textbook image').''; + } } } - my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"'; + my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"'; $datatable .= '' - .''; for (my $k=0; $k<=$maxnum; $k++) { my $vpos = $k+1; my $selstr; @@ -2146,39 +2244,43 @@ sub print_textbookcourses { $datatable .= ''; } $datatable .= ''.(' 'x2). - ''. ''. - ''.&mt('Subject:').' '. - (' 'x2). - ''.&mt('Title:').' '. - (' 'x2). - ''.&mt('Author(s):').' '. + ''.&mt('Subject:').' '. (' 'x2). - ''.&mt('Thumbnail:'); - if ($image) { - $datatable .= ''. - $imgsrc. - ' '. - ' '.&mt('Replace:').' '; - } - if ($switchserver) { - $datatable .= &mt('Upload to library server: [_1]',$switchserver); - } else { - $datatable .= ''; + ''.&mt('Title:').' '; + if ($type eq 'textbooks') { + $datatable .= (' 'x2). + ''.&mt('Publisher:').' '. + (' 'x2). + ''.&mt('Author(s):').' '. + (' 'x2). + ''.&mt('Thumbnail:'); + if ($image) { + $datatable .= ''. + $imgsrc. + ' '. + ' '.&mt('Replace:').' '; + } + if ($switchserver) { + $datatable .= &mt('Upload to library server: [_1]',$switchserver); + } else { + $datatable .= ''; + } } - $datatable .= ' '. + $datatable .= ' '. ''.&mt('LON-CAPA course:').' '. $coursetitle.''."\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 .= ''."\n". - ''."\n". - ''."\n". + ' '."\n". - ''.&mt('Add').''."\n". + ''.&mt('Add').''."\n". ''. - ''.&mt('Subject:').' '."\n". - (' 'x2). - ''.&mt('Title:').' '."\n". - (' 'x2). - ''.&mt('Author(s):').' '."\n". + ''.&mt('Subject:').' '."\n". (' 'x2). - ''.&mt('Image:').' '; - if ($switchserver) { - $datatable .= &mt('Upload to library server: [_1]',$switchserver); - } else { - $datatable .= ''; + ''.&mt('Title:').' '."\n". + (' 'x2); + if ($type eq 'textbooks') { + $datatable .= ''.&mt('Publisher:').' '."\n". + (' 'x2). + ''.&mt('Author(s):').' '."\n". + (' 'x2). + ''.&mt('Image:').' '; + if ($switchserver) { + $datatable .= &mt('Upload to library server: [_1]',$switchserver); + } else { + $datatable .= ''; + } } $datatable .= ''."\n". ''.&mt('LON-CAPA course:').' '. - &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom'). - ''. + &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom'). + ''. &Apache::loncommon::selectcourse_link - ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course'); + ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course'); ''."\n". ''."\n"; $itemcount ++; @@ -2215,23 +2321,43 @@ sub print_textbookcourses { } 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("','",@jsarray)."'".');'."\n"; } - my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n"; return <<"ENDSCRIPT";