--- loncom/interface/domainprefs.pm 2007/04/05 21:36:15 1.8 +++ loncom/interface/domainprefs.pm 2007/07/28 21:23:53 1.24 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.8 2007/04/05 21:36:15 raeburn Exp $ +# $Id: domainprefs.pm,v 1.24 2007/07/28 21:23:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -38,6 +38,7 @@ use Apache::lonhtmlcommon(); use Apache::lonlocal; use LONCAPA(); use LONCAPA::Enrollment; +use File::Copy; sub handler { my $r=shift; @@ -66,7 +67,7 @@ sub handler { } my %domconfig = &Apache::lonnet::get_dom('configuration',['login','rolecolors', - 'quotas','autoenroll','autoupdate'],$dom); + 'quotas','autoenroll','autoupdate','directorysrch'],$dom); my @prefs = ( { text => 'Default color schemes', help => 'Default_Color_Schemes', @@ -105,12 +106,19 @@ sub handler { col2 => 'Value',}, {col1 => 'User Population', col2 => 'Updataeable user data'}], - }, + }, + { text => 'Institutional directory searches', + help => 'Domain_Directory_Search', + action => 'directorysrch', + header => [{col1 => 'Setting', + col2 => 'Value',}], + }, ); my @roles = ('student','coordinator','author','admin'); &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:changePage(document.$phase,'display')", text=>"Domain Configuration"}); + my $confname = $dom.'-domainconfig'; if ($phase eq 'process') { &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:changePage(document.$phase,'$phase')", @@ -118,7 +126,8 @@ sub handler { &print_header($r,$phase); foreach my $item (@prefs) { $r->print('

'.&mt($item->{'text'}).'

'. - &process_changes($r,$dom,$item->{'action'},\@roles,%domconfig)); + &process_changes($r,$dom,$confname, + $item->{'action'},\@roles,%domconfig)); } $r->print('

'); &print_footer($r,$phase,'display','Back to actions menu'); @@ -130,48 +139,79 @@ sub handler { my %helphash; my $numprefs = @prefs; &print_header($r,$phase); + if (keys(%domconfig) == 0) { + my $primarylibserv = &Apache::lonnet::domain($dom,'primary'); + my $perlvarref = &LONCAPA::Configuration::read_conf('loncapa.conf'); + my $hostid = $perlvarref->{'lonHostID'}; + if ($hostid ne $primarylibserv) { + my %designhash = &Apache::loncommon::get_domainconf($dom); + my @loginimages = ('img','logo','domlogo'); + my $custom_img_count = 0; + foreach my $img (@loginimages) { + if ($designhash{$dom.'.login.'.$img} ne '') { + $custom_img_count ++; + } + } + foreach my $role (@roles) { + if ($designhash{$dom.'.'.$role.'.img'} ne '') { + $custom_img_count ++; + } + } + if ($custom_img_count > 0) { + my $switch_server = &check_switchserver($dom,$confname); + $r->print(&mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'
'.&mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'

'.&mt("Thereafter, you will be able to update settings from this screen when logged in to any server in the LON-CAPA network (with a DC role selected in the domain), although you will still need to switch to the domain's primary library server to upload new images or logos.").'

'.$switch_server.' '.&mt('to primary library server for domain: [_1]',$dom)); + return OK; + } + } + } $r->print('
'); foreach my $item (@prefs) { if ($item->{'action'} eq 'login') { $r->print(' '); } - &print_config_box($r,$dom,$phase,$item->{'action'}, + &print_config_box($r,$dom,$confname,$phase,$item->{'action'}, $item,$domconfig{$item->{'action'}}); } $r->print('
'); - &print_footer($r,$phase,'process','Store changes'); + &print_footer($r,$phase,'process','Save changes'); } return OK; } sub process_changes { - my ($r,$dom,$action,$roles,%domconfig) = @_; + my ($r,$dom,$confname,$action,$roles,%domconfig) = @_; my $output; if ($action eq 'login') { - $output = &modify_login($r,$dom,%domconfig); + $output = &modify_login($r,$dom,$confname,%domconfig); } elsif ($action eq 'rolecolors') { - $output = &modify_rolecolors($r,$dom,$roles,%domconfig); + $output = &modify_rolecolors($r,$dom,$confname,$roles, + %domconfig); } elsif ($action eq 'quotas') { $output = &modify_quotas($dom,%domconfig); } elsif ($action eq 'autoenroll') { $output = &modify_autoenroll($dom,%domconfig); } elsif ($action eq 'autoupdate') { $output = &modify_autoupdate($dom,%domconfig); + } elsif ($action eq 'directorysrch') { + $output = &modify_directorysrch($dom,%domconfig); } return $output; } sub print_config_box { - my ($r,$dom,$phase,$action,$item,$settings) = @_; + my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_; $r->print(' - - '); + '); +# +# FIXME - put the help link back in when the help files exist +# +# '); if (($action eq 'autoupdate') || ($action eq 'rolecolors')) { my $colspan = ($action eq 'rolecolors')?' colspan="2"':''; $r->print(' @@ -185,7 +225,7 @@ sub print_config_box { if ($action eq 'autoupdate') { $r->print(&print_autoupdate('top',$dom,$settings)); } else { - $r->print(&print_rolecolors($phase,'student',$dom,$settings)); + $r->print(&print_rolecolors($phase,'student',$dom,$confname,$settings)); } $r->print('
'.&mt($item->{text}).' '. - &Apache::loncommon::help_open_topic($item->{'help'}).'
'.&mt($item->{text}).' 
'.&mt($item->{text}).' '. +# &Apache::loncommon::help_open_topic($item->{'help'}).'
@@ -201,7 +241,7 @@ sub print_config_box { if ($action eq 'autoupdate') { $r->print(&print_autoupdate('bottom',$dom,$settings)); } else { - $r->print(&print_rolecolors($phase,'coordinator',$dom,$settings).' + $r->print(&print_rolecolors($phase,'coordinator',$dom,$confname,$settings).' @@ -212,7 +252,7 @@ sub print_config_box { '.$item->{'header'}->[2]->{'col1'}.' '.$item->{'header'}->[2]->{'col2'}.' '. - &print_rolecolors($phase,'author',$dom,$settings).' + &print_rolecolors($phase,'author',$dom,$confname,$settings).' @@ -223,7 +263,7 @@ sub print_config_box { '.$item->{'header'}->[3]->{'col1'}.' '.$item->{'header'}->[3]->{'col2'}.' '. - &print_rolecolors($phase,'admin',$dom,$settings)); + &print_rolecolors($phase,'admin',$dom,$confname,$settings)); } } else { $r->print(' @@ -231,7 +271,7 @@ sub print_config_box { '); - if ($action eq 'login') { + if (($action eq 'login') || ($action eq 'directorysrch')) { $r->print(' '); } else { @@ -242,11 +282,13 @@ sub print_config_box { '); if ($action eq 'login') { - $r->print(&print_login($dom,$phase,$settings)); + $r->print(&print_login($dom,$confname,$phase,$settings)); } elsif ($action eq 'quotas') { $r->print(&print_quotas($dom,$settings)); } elsif ($action eq 'autoenroll') { $r->print(&print_autoenroll($dom,$settings)); + } elsif ($action eq 'directorysrch') { + $r->print(&print_directorysrch($dom,$settings)); } } $r->print(' @@ -301,7 +343,7 @@ sub print_footer { } sub print_login { - my ($dom,$phase,$settings) = @_; + my ($dom,$confname,$phase,$settings) = @_; my %choices = &login_choices(); my ($catalogon,$catalogoff,$adminmailon,$adminmailoff); $catalogon = ' checked="checked" '; @@ -402,7 +444,7 @@ sub print_login { ''; $itemcount ++; - $datatable .= &display_color_options($dom,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text); + $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text); $datatable .= '
'.$item->{'header'}->[0]->{'col1'}.''.$item->{'header'}->[0]->{'col2'}.'
'; return $datatable; } @@ -429,7 +471,7 @@ sub login_choices { } sub print_rolecolors { - my ($phase,$role,$dom,$settings) = @_; + my ($phase,$role,$dom,$confname,$settings) = @_; my %choices = &color_font_choices(); my @bgs = ('pgbg','tabbg','sidebg'); my @links = ('link','alink','vlink'); @@ -495,15 +537,14 @@ sub print_rolecolors { } } my $itemcount = 1; - my $datatable = &display_color_options($dom,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text); + my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text); $datatable .= ''; return $datatable; } sub display_color_options { - my ($dom,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs, + my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs, $images,$bgs,$links,$alt_text) = @_; - my $configuname = $dom.'-domainconfig'; my $css_class = $itemcount%2?' class="LC_odd_row"':''; my $datatable = ''. ''.$choices->{'font'}.''; @@ -517,20 +558,22 @@ sub display_color_options { ' '.$fontlink. ''; + my $switchserver = &check_switchserver($dom,$confname); foreach my $img (@{$images}) { - $itemcount ++; + $itemcount ++; $css_class = $itemcount%2?' class="LC_odd_row"':''; $datatable .= ''. ''.$choices->{$img}.''; - my $imgfile; + my ($imgfile, $img_import); if ($designs->{$img} ne '') { $imgfile = $designs->{$img}; + $img_import = ($imgfile =~ m{^/adm/}); } else { $imgfile = $defaults->{$img}; } if ($imgfile) { - my $showfile; - if ($imgfile =~ m-^(/uploaded/\Q$dom\E/\Q$configuname\E/portfolio.*)/([^/]+)$-) { + my ($showfile,$fullsize); + if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) { my $urldir = $1; my $filename = $2; my @info = &Apache::lonnet::stat_file($designs->{$img}); @@ -546,6 +589,7 @@ sub display_color_options { $showfile = ''; } } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) { + $showfile = $imgfile; my $imgdir = $1; my $filename = $2; if (-e "/home/httpd/html/$imgdir/tn-".$filename) { @@ -554,18 +598,31 @@ sub display_color_options { my $input = "/home/httpd/html".$imgfile; my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename; if (!-e $output) { - system("convert -sample 200x50 $input $output"); + my ($width,$height) = &thumb_dimensions(); + my ($fullwidth,$fullheight) = &check_dimensions($input); + if ($fullwidth ne '' && $fullheight ne '') { + if ($fullwidth > $width && $fullheight > $height) { + my $size = $width.'x'.$height; + system("convert -sample $size $input $output"); + $showfile = '/'.$imgdir.'/tn-'.$filename; + } + } } - $showfile = '/'.$imgdir.'/tn-'.$filename; } - } + } if ($showfile) { + $showfile = &Apache::loncommon::lonhttpdurl($showfile); + $fullsize = &Apache::loncommon::lonhttpdurl($imgfile); $datatable.= ''; if (!$is_custom->{$img}) { $datatable .= &mt('Default in use:').'
'; } - $datatable.= ''.
-                             $alt_text->{$img}.''; + if ($img_import) { + $datatable.= ''; + } + $datatable.= ''.$alt_text->{$img}.
+                             ''; if ($is_custom->{$img}) { $datatable.=''; } } - $othertitle = "Other users"; } my $defaultquota = '20'; if (ref($settings) eq 'HASH') { @@ -719,16 +770,15 @@ sub print_quotas { $datatable .= ''. ''.&mt($othertitle).''. ''. - ' Mb'; return $datatable; } sub print_autoenroll { my ($dom,$settings) = @_; - my $defdom = $dom; my $autorun = &Apache::lonnet::auto_run(undef,$dom), - my ($runon,$runoff); + my ($defdom,$runon,$runoff); if (ref($settings) eq 'HASH') { if (exists($settings->{'run'})) { if ($settings->{'run'} eq '0') { @@ -750,6 +800,14 @@ sub print_autoenroll { if (exists($settings->{'sender_domain'})) { $defdom = $settings->{'sender_domain'}; } + } else { + if ($autorun) { + $runon = ' checked="checked" '; + $runoff = ' '; + } else { + $runoff = ' checked="checked" '; + $runon = ' '; + } } my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1); my $datatable=''. @@ -758,7 +816,7 @@ sub print_autoenroll { ''.&mt('Yes').' '. ''. + $runoff.' value="0" />'.&mt('No').''. ''. ''.&mt('Notification messages - sender'). ''. @@ -808,34 +866,22 @@ sub print_autoupdate { $classlistsoff.'value="0" />'.&mt('No').''. ''; } else { - my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom); - my @types; - if (ref($order) eq 'ARRAY') { - @types = @{$order}; - } - if (@types == 0) { - if (ref($usertypes) eq 'HASH') { - @types = sort(keys(%{$usertypes})); - } - } - my $othertitle = &mt('All users'); - if (keys(%{$usertypes}) > 0) { - $othertitle = &mt('Other users'); - } - my @fields = ('lastname','firstname','middlename','gen','email','id'); + my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom); + my @fields = ('lastname','firstname','middlename','gen', + 'permanentemail','id'); my %fieldtitles = &Apache::lonlocal::texthash ( id => 'Student/Employee ID', - email => 'E-mail address', + permanentemail => 'E-mail address', lastname => 'Last Name', firstname => 'First Name', middlename => 'Middle Name', gen => 'Generation', ); my $numrows = 0; - if (@types > 0) { + if (@{$types} > 0) { $datatable = &usertype_update_row($settings,$usertypes,\%fieldtitles, - \@fields,\@types,\$numrows); + \@fields,$types,\$numrows); } $datatable .= &usertype_update_row($settings,{'default' => $othertitle}, @@ -845,6 +891,157 @@ sub print_autoupdate { return $datatable; } +sub print_directorysrch { + my ($dom,$settings) = @_; + my $srchon = ' '; + my $srchoff = ' checked="checked" '; + my $exacton = ''; + my $containson = ' checked="checked" '; + my $specifyon = ''; + my $localon = ' '; + my $localoff = ' checked="checked" '; + if (ref($settings) eq 'HASH') { + if ($settings->{'available'} eq '1') { + $srchon = $srchoff; + $srchoff = ' '; + } + if ($settings->{'localonly'} eq '1') { + $localon = $localoff; + $localoff = ' '; + } + if ($settings->{'searchtypes'} eq 'exact') { + $exacton = $containson; + $containson = ' '; + } + if ($settings->{'searchtypes'} eq 'specify') { + $specifyon = $containson; + $containson = ' '; + } + } + my ($searchtitles,$titleorder) = &sorted_searchtitles(); + my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom); + + my $numinrow = 4; + my $datatable=''. + ''.&mt('Directory search available?').''. + ' '. + ''. + ''. + ''.&mt('Search latitude').''. + ' '. + ''. + ' '. + ''. + ''.&mt('Other domains can search').''. + ' '. + ''. + ''. + ''.&mt('Users allowed to search').' ('.$dom.')'. + ''; + for (my $i=0; $i<@{$types}; $i++) { + if (defined($usertypes->{$types->[$i]})) { + my $rem = $i%($numinrow); + if ($rem == 0) { + if ($i > 0) { + $datatable .= ''; + } + $datatable .= ''; + } + my $check = ' '; + if (ref($settings->{'cansearch'}) eq 'ARRAY') { + if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) { + $check = ' checked="checked" '; + } + } + $datatable .= ''; + } + } + + my $rem = @{$types}%($numinrow); + my $colsleft = $numinrow - $rem; + if ($colsleft > 1) { + $datatable .= ''. + '
'. + ''; + } else { + $datatable .= ''; + } + my $defcheck = ' '; + if (ref($settings->{'cansearch'}) eq 'ARRAY') { + if (grep(/^default$/,@{$settings->{'cansearch'}})) { + $defcheck = ' checked="checked" '; + } + } + $datatable .= '
'; + + $datatable .= ''. + ''.&mt('Supported search methods'). + ''; + foreach my $title (@{$titleorder}) { + if (defined($searchtitles->{$title})) { + my $check = ' '; + if (ref($settings->{'searchby'}) eq 'ARRAY') { + if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) { + $check = ' checked="checked" '; + } + } + $datatable .= ''; + } + } + $datatable .= '
'. + '
'; + return $datatable; +} + +sub sorted_inst_types { + my ($dom) = @_; + my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom); + my $othertitle = "All users"; + my @types; + if (ref($order) eq 'ARRAY') { + @types = @{$order}; + } + if (@types == 0) { + if (ref($usertypes) eq 'HASH') { + @types = sort(keys(%{$usertypes})); + } + } + if (keys(%{$usertypes}) > 0) { + $othertitle = &mt('Other users'); + } + return ($othertitle,$usertypes,\@types); +} + +sub sorted_searchtitles { + my %searchtitles = &Apache::lonlocal::texthash( + 'uname' => 'username', + 'lastname' => 'last name', + 'lastfirst' => 'last name, first name', + ); + my @titleorder = ('uname','lastname','lastfirst'); + return (\%searchtitles,\@titleorder); +} + sub usertype_update_row { my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_; my $datatable; @@ -894,14 +1091,14 @@ sub usertype_update_row { } sub modify_login { - my ($r,$dom,%domconfig) = @_; + my ($r,$dom,$confname,%domconfig) = @_; my ($resulttext,$errors,$colchgtext,%changes,%colchanges); my %title = ( coursecatalog => 'Display course catalog', adminmail => 'Display administrator E-mail address'); my @offon = ('off','on'); my %loginhash; - ($errors,%colchanges) = &modify_colors($r,$dom,['login'],\%domconfig, - \%loginhash); + ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'], + \%domconfig,\%loginhash); $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'}; $loginhash{login}{adminmail} = $env{'form.adminmail'}; if (ref($colchanges{'login'}) eq 'HASH') { @@ -937,10 +1134,11 @@ sub modify_login { $resulttext = &mt('No changes made to log-in page settings'); } } else { - $resulttext = &mt('An error occurred: [_1]',$putresult); + $resulttext = ''. + &mt('An error occurred: [_1]',$putresult).''; } if ($errors) { - $resulttext .= &mt('The following errors occurred: ').'