--- loncom/interface/domainprefs.pm 2015/03/30 20:47:13 1.160.6.60 +++ loncom/interface/domainprefs.pm 2019/08/17 19:24:29 1.160.6.97 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.160.6.60 2015/03/30 20:47:13 raeburn Exp $ +# $Id: domainprefs.pm,v 1.160.6.97 2019/08/17 19:24:29 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -19,7 +19,8 @@ # # You should have received a copy of the GNU General Public License # along with LON-CAPA; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA# +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ @@ -213,15 +214,15 @@ sub handler { 'quotas','autoenroll','autoupdate','autocreate', 'directorysrch','usercreation','usermodification', 'contacts','defaults','scantron','coursecategories', - 'serverstatuses','requestcourses','coursedefaults', - 'usersessions','loadbalancing','requestauthor', - 'selfenrollment','inststatus'],$dom); + 'serverstatuses','requestcourses','helpsettings', + 'coursedefaults','usersessions','loadbalancing', + 'requestauthor','selfenrollment','inststatus'],$dom); my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll', 'autoupdate','autocreate','directorysrch','contacts', 'usercreation','selfcreation','usermodification','scantron', 'requestcourses','requestauthor','coursecategories', - 'serverstatuses','coursedefaults','selfenrollment', - 'usersessions'); + 'serverstatuses','helpsettings','coursedefaults', + 'selfenrollment','usersessions'); my %existing; if (ref($domconfig{'loadbalancing'}) eq 'HASH') { %existing = %{$domconfig{'loadbalancing'}}; @@ -261,8 +262,10 @@ sub handler { help => 'Domain_Configuration_LangTZAuth', header => [{col1 => 'Setting', col2 => 'Value'}, + {col1 => 'Internal Authentication', + col2 => 'Value'}, {col1 => 'Institutional user types', - col2 => 'Assignable to e-mail usernames'}], + col2 => 'Name displayed'}], print => \&print_defaults, modify => \&modify_defaults, }, @@ -304,18 +307,24 @@ sub handler { modify => \&modify_autocreate, }, 'directorysrch' => - { text => 'Institutional directory searches', + { text => 'Directory searches', help => 'Domain_Configuration_InstDirectory_Search', - header => [{col1 => 'Setting', + header => [{col1 => 'Institutional Directory Setting', + col2 => 'Value',}, + {col1 => 'LON-CAPA Directory Setting', col2 => 'Value',}], print => \&print_directorysrch, modify => \&modify_directorysrch, }, 'contacts' => - { text => 'Contact Information', + { text => 'E-mail addresses and helpform', help => 'Domain_Configuration_Contact_Info', - header => [{col1 => 'Setting', - col2 => 'Value',}], + header => [{col1 => 'Default e-mail addresses', + col2 => 'Value',}, + {col1 => 'Recipient(s) for notifications', + col2 => 'Value',}, + {col1 => 'Ask helpdesk form settings', + col2 => 'Value',},], print => \&print_contacts, modify => \&modify_contacts, }, @@ -338,7 +347,7 @@ sub handler { col2 => 'Enabled?'}, {col1 => 'Institutional user type (login/SSO self-creation)', col2 => 'Information user can enter'}, - {col1 => 'Self-creation with e-mail as username', + {col1 => 'Self-creation with e-mail verification', col2 => 'Settings'}], print => \&print_selfcreation, modify => \&modify_selfcreation, @@ -354,11 +363,12 @@ sub handler { modify => \&modify_usermodification, }, 'scantron' => - { text => 'Bubblesheet format file', + { text => 'Bubblesheet format', help => 'Domain_Configuration_Scantron_Format', - header => [ {col1 => 'Item', - col2 => '', - }], + header => [ {col1 => 'Bubblesheet format file', + col2 => ''}, + {col1 => 'Bubblesheet data upload formats', + col2 => 'Settings'}], print => \&print_scantron, modify => \&modify_scantron, }, @@ -411,6 +421,16 @@ sub handler { print => \&print_serverstatuses, modify => \&modify_serverstatuses, }, + 'helpsettings' => + {text => 'Support settings', + help => 'Domain_Configuration_Help_Settings', + header => [{col1 => 'Help Page Settings (logged-in users)', + col2 => 'Value'}, + {col1 => 'Helpdesk Roles', + col2 => 'Settings'},], + print => \&print_helpsettings, + modify => \&modify_helpsettings, + }, 'coursedefaults' => {text => 'Course/Community defaults', help => 'Domain_Configuration_Course_Defaults', @@ -445,7 +465,7 @@ sub handler { print => \&print_usersessions, modify => \&modify_usersessions, }, - 'loadbalancing' => + 'loadbalancing' => {text => 'Dedicated Load Balancer(s)', help => 'Domain_Configuration_Load_Balancing', header => [{col1 => 'Balancers', @@ -509,6 +529,15 @@ $javascript_validations $coursebrowserjs END } + if (grep(/^selfcreation$/,@actions)) { + $js .= &selfcreate_javascript(); + } + if (grep(/^contacts$/,@actions)) { + $js .= &contacts_javascript(); + } + if (grep(/^scantron$/,@actions)) { + $js .= &scantron_javascript(); + } &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js); } else { # check if domconfig user exists for the domain. @@ -598,11 +627,11 @@ sub process_changes { } elsif ($action eq 'autocreate') { $output = &modify_autocreate($dom,%domconfig); } elsif ($action eq 'directorysrch') { - $output = &modify_directorysrch($dom,%domconfig); + $output = &modify_directorysrch($dom,$lastactref,%domconfig); } elsif ($action eq 'usercreation') { $output = &modify_usercreation($dom,%domconfig); } elsif ($action eq 'selfcreation') { - $output = &modify_selfcreation($dom,%domconfig); + $output = &modify_selfcreation($dom,$lastactref,%domconfig); } elsif ($action eq 'usermodification') { $output = &modify_usermodification($dom,%domconfig); } elsif ($action eq 'contacts') { @@ -619,6 +648,8 @@ sub process_changes { $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig); } elsif ($action eq 'requestauthor') { $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig); + } elsif ($action eq 'helpsettings') { + $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig); } elsif ($action eq 'coursedefaults') { $output = &modify_coursedefaults($dom,$lastactref,%domconfig); } elsif ($action eq 'selfenrollment') { @@ -639,6 +670,22 @@ sub print_config_box { $output = &coursecategories_javascript($settings); } elsif ($action eq 'defaults') { $output = &defaults_javascript($settings); + } elsif ($action eq 'helpsettings') { + my (%privs,%levelscurrent); + my %full=(); + my %levels=( + course => {}, + domain => {}, + system => {}, + ); + my $context = 'domain'; + my $crstype = 'Course'; + my $formname = 'display'; + &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent); + my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype); + $output = + &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full, + \@templateroles); } $output .= ' @@ -656,6 +703,7 @@ sub print_config_box { my $colspan = ''; my $rightcolspan = ''; if (($action eq 'rolecolors') || ($action eq 'defaults') || + ($action eq 'directorysrch') || (($action eq 'login') && ($numheaders < 4))) { $colspan = ' colspan="2"'; } @@ -673,10 +721,13 @@ sub print_config_box { $rowtotal ++; if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') || ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') || - ($action eq 'selfenrollment') || ($action eq 'usersessions')) { + ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') || + ($action eq 'helpsettings') || ($action eq 'contacts')) { $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal); } elsif ($action eq 'coursecategories') { $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal); + } elsif ($action eq 'scantron') { + $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal); } elsif ($action eq 'login') { if ($numheaders == 4) { $colspan = ' colspan="2"'; @@ -703,7 +754,8 @@ sub print_config_box { $rowtotal ++; if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') || ($action eq 'selfenrollment') || - ($action eq 'usersessions') || ($action eq 'coursecategories')) { + ($action eq 'usersessions') || ($action eq 'coursecategories') || + ($action eq 'contacts') || ($action eq 'defaults')) { if ($action eq 'coursecategories') { $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal); $colspan = ' colspan="2"'; @@ -728,8 +780,11 @@ sub print_config_box { } $rowtotal ++; } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') || - ($action eq 'defaults')) { + ($action eq 'defaults') || ($action eq 'directorysrch') || + ($action eq 'helpsettings')) { $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal); + } elsif ($action eq 'scantron') { + $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal); } elsif ($action eq 'login') { if ($numheaders == 4) { $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).' @@ -841,7 +896,7 @@ sub print_config_box { '; } @@ -1396,7 +1447,7 @@ sub display_color_options { my $datatable = ''. ''; if (!$is_custom->{'font'}) { - $datatable .= ''; + $datatable .= ''; } else { $datatable .= ''; } @@ -1405,12 +1456,12 @@ sub display_color_options { $datatable .= ''; + ' '; unless ($role eq 'login') { $datatable .= ''. ''; if (!$is_custom->{'fontmenu'}) { - $datatable .= ''; + $datatable .= ''; } else { $datatable .= ''; } @@ -1420,7 +1471,7 @@ sub display_color_options { ' '. - ' '; + ' '; } my $switchserver = &check_switchserver($dom,$confname); foreach my $img (@{$images}) { @@ -1479,7 +1530,8 @@ sub display_color_options { if ($fullwidth ne '' && $fullheight ne '') { if ($fullwidth > $width && $fullheight > $height) { my $size = $width.'x'.$height; - system("convert -sample $size $input $output"); + my @args = ('convert','-sample',$size,$input,$output); + system({$args[0]} @args); $showfile = "/$imgdir/tn-".$filename; } } @@ -1537,7 +1589,7 @@ sub display_color_options { my $bgs_def; foreach my $item (@{$bgs}) { if (!$is_custom->{$item}) { - $bgs_def .= ''; + $bgs_def .= ''; } } if ($bgs_def) { @@ -1565,7 +1617,7 @@ sub display_color_options { my $links_def; foreach my $item (@{$links}) { if (!$is_custom->{$item}) { - $links_def .= ''; + $links_def .= ''; } } if ($links_def) { @@ -1651,17 +1703,15 @@ sub image_changes { my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_; my $output; if ($img eq 'login') { - # suppress image for Log-in header + $output = ''."\n". + ''.&mt('Add').''."\n". ''."\n". ''."\n"; $itemcount ++; @@ -2398,7 +2460,7 @@ ENDSCRIPT sub print_autoenroll { my ($dom,$settings,$rowtotal) = @_; my $autorun = &Apache::lonnet::auto_run(undef,$dom), - my ($defdom,$runon,$runoff,$coownerson,$coownersoff); + my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe); if (ref($settings) eq 'HASH') { if (exists($settings->{'run'})) { if ($settings->{'run'} eq '0') { @@ -2432,6 +2494,9 @@ sub print_autoenroll { if (exists($settings->{'sender_domain'})) { $defdom = $settings->{'sender_domain'}; } + if (exists($settings->{'autofailsafe'})) { + $failsafe = $settings->{'autofailsafe'}; + } } else { if ($autorun) { $runon = ' checked="checked" '; @@ -2467,8 +2532,12 @@ sub print_autoenroll { $coownerson.' value="1" />'.&mt('Yes').' '. ''. - ''; - $$rowtotal += 3; + ''. + ''. + ''; + $$rowtotal += 4; return $datatable; } @@ -2516,7 +2585,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); @@ -2597,233 +2666,789 @@ sub print_autocreate { } sub print_directorysrch { - my ($dom,$settings,$rowtotal) = @_; - my $srchon = ' '; - my $srchoff = ' checked="checked" '; - my ($exacton,$containson,$beginson); - 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 (ref($settings->{'searchtypes'}) eq 'ARRAY') { - foreach my $type (@{$settings->{'searchtypes'}}) { - if ($type eq 'exact') { + my ($position,$dom,$settings,$rowtotal) = @_; + my $datatable; + if ($position eq 'top') { + my $instsrchon = ' '; + my $instsrchoff = ' checked="checked" '; + my ($exacton,$containson,$beginson); + my $instlocalon = ' '; + my $instlocaloff = ' checked="checked" '; + if (ref($settings) eq 'HASH') { + if ($settings->{'available'} eq '1') { + $instsrchon = $instsrchoff; + $instsrchoff = ' '; + } + if ($settings->{'localonly'} eq '1') { + $instlocalon = $instlocaloff; + $instlocaloff = ' '; + } + if (ref($settings->{'searchtypes'}) eq 'ARRAY') { + foreach my $type (@{$settings->{'searchtypes'}}) { + if ($type eq 'exact') { + $exacton = ' checked="checked" '; + } elsif ($type eq 'contains') { + $containson = ' checked="checked" '; + } elsif ($type eq 'begins') { + $beginson = ' checked="checked" '; + } + } + } else { + if ($settings->{'searchtypes'} eq 'exact') { + $exacton = ' checked="checked" '; + } elsif ($settings->{'searchtypes'} eq 'contains') { + $containson = ' checked="checked" '; + } elsif ($settings->{'searchtypes'} eq 'specify') { $exacton = ' checked="checked" '; - } elsif ($type eq 'contains') { $containson = ' checked="checked" '; - } elsif ($type eq 'begins') { - $beginson = ' checked="checked" '; } } - } else { - if ($settings->{'searchtypes'} eq 'exact') { - $exacton = ' checked="checked" '; - } elsif ($settings->{'searchtypes'} eq 'contains') { - $containson = ' checked="checked" '; - } elsif ($settings->{'searchtypes'} eq 'specify') { - $exacton = ' checked="checked" '; - $containson = ' checked="checked" '; - } } - } - my ($searchtitles,$titleorder) = &sorted_searchtitles(); - my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); + my ($searchtitles,$titleorder) = &sorted_searchtitles(); + my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); - my $numinrow = 4; - my $cansrchrow = 0; - my $datatable=''. - ''. - ''. - ''. - ''. - ''. - ''; - $$rowtotal += 2; - if (ref($usertypes) eq 'HASH') { - if (keys(%{$usertypes}) > 0) { - $datatable .= &insttypes_row($settings,$types,$usertypes,$dom, - $numinrow,$othertitle,'cansearch'); - $cansrchrow = 1; + my $numinrow = 4; + my $cansrchrow = 0; + $datatable=''. + ''. + ''. + ''. + ''. + ''. + ''; + $$rowtotal += 2; + if (ref($usertypes) eq 'HASH') { + if (keys(%{$usertypes}) > 0) { + $datatable .= &insttypes_row($settings,$types,$usertypes,$dom, + $numinrow,$othertitle,'cansearch', + $rowtotal); + $cansrchrow = 1; + } } - } - if ($cansrchrow) { - $$rowtotal ++; - $datatable .= ''; - } else { - $datatable .= ''; - } - $datatable .= ''; + $$rowtotal ++; + if ($cansrchrow) { + $datatable .= ''; + } else { + $datatable .= ''; + } + $datatable .= ''. + ''; + $$rowtotal ++; } else { - $datatable .= ''; + my $domsrchon = ' checked="checked" '; + my $domsrchoff = ' '; + my $domlocalon = ' '; + my $domlocaloff = ' checked="checked" '; + if (ref($settings) eq 'HASH') { + if ($settings->{'lclocalonly'} eq '1') { + $domlocalon = $domlocaloff; + $domlocaloff = ' '; + } + if ($settings->{'lcavailable'} eq '0') { + $domsrchoff = $domsrchon; + $domsrchon = ' '; + } + } + $datatable=''. + ''. + ''. + ''. + ''. + ''. + ''; + $$rowtotal += 2; } - $datatable .= ''. - ''; - $$rowtotal ++; return $datatable; } sub print_contacts { - my ($dom,$settings,$rowtotal) = @_; + my ($position,$dom,$settings,$rowtotal) = @_; my $datatable; my @contacts = ('adminemail','supportemail'); - my (%checked,%to,%otheremails,%bccemails); - my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail', - 'requestsmail','updatesmail','idconflictsmail'); - foreach my $type (@mailings) { - $otheremails{$type} = ''; - } - $bccemails{'helpdeskmail'} = ''; - if (ref($settings) eq 'HASH') { - foreach my $item (@contacts) { - if (exists($settings->{$item})) { - $to{$item} = $settings->{$item}; + my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield, + $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings); + if ($position eq 'top') { + if (ref($settings) eq 'HASH') { + foreach my $item (@contacts) { + if (exists($settings->{$item})) { + $to{$item} = $settings->{$item}; + } } } + } elsif ($position eq 'middle') { + @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail', + 'updatesmail','idconflictsmail','hostipmail'); foreach my $type (@mailings) { - if (exists($settings->{$type})) { - if (ref($settings->{$type}) eq 'HASH') { - foreach my $item (@contacts) { - if ($settings->{$type}{$item}) { - $checked{$type}{$item} = ' checked="checked" '; + $otheremails{$type} = ''; + } + } else { + @mailings = ('helpdeskmail','otherdomsmail'); + foreach my $type (@mailings) { + $otheremails{$type} = ''; + } + $bccemails{'helpdeskmail'} = ''; + $bccemails{'otherdomsmail'} = ''; + $includestr{'helpdeskmail'} = ''; + $includestr{'otherdomsmail'} = ''; + ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields(); + } + if (ref($settings) eq 'HASH') { + unless ($position eq 'top') { + foreach my $type (@mailings) { + if (exists($settings->{$type})) { + if (ref($settings->{$type}) eq 'HASH') { + foreach my $item (@contacts) { + if ($settings->{$type}{$item}) { + $checked{$type}{$item} = ' checked="checked" '; + } } + $otheremails{$type} = $settings->{$type}{'others'}; + if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) { + $bccemails{$type} = $settings->{$type}{'bcc'}; + if ($settings->{$type}{'include'} ne '') { + ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2); + $includestr{$type} = &unescape($includestr{$type}); + } + } + } + } elsif ($type eq 'lonstatusmail') { + $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; + } + } + } + if ($position eq 'bottom') { + foreach my $type (@mailings) { + $bccemails{$type} = $settings->{$type}{'bcc'}; + if ($settings->{$type}{'include'} ne '') { + ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2); + $includestr{$type} = &unescape($includestr{$type}); + } + } + if (ref($settings->{'helpform'}) eq 'HASH') { + if (ref($fields) eq 'ARRAY') { + foreach my $field (@{$fields}) { + $currfield{$field} = $settings->{'helpform'}{$field}; } - $otheremails{$type} = $settings->{$type}{'others'}; - if ($type eq 'helpdeskmail') { - $bccemails{$type} = $settings->{$type}{'bcc'}; + } + if (exists($settings->{'helpform'}{'maxsize'})) { + $maxsize = $settings->{'helpform'}{'maxsize'}; + } else { + $maxsize = '1.0'; + } + } else { + if (ref($fields) eq 'ARRAY') { + foreach my $field (@{$fields}) { + $currfield{$field} = 'yes'; } } - } elsif ($type eq 'lonstatusmail') { - $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; + $maxsize = '1.0'; } } } else { - $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'}; - $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'}; - $checked{'errormail'}{'adminemail'} = ' checked="checked" '; - $checked{'packagesmail'}{'adminemail'} = ' checked="checked" '; - $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" '; - $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; - $checked{'requestsmail'}{'adminemail'} = ' checked="checked" '; - $checked{'updatesmail'}{'adminemail'} = ' checked="checked" '; - $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" '; + if ($position eq 'top') { + $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'}; + $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'}; + $checked{'errormail'}{'adminemail'} = ' checked="checked" '; + $checked{'packagesmail'}{'adminemail'} = ' checked="checked" '; + $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; + $checked{'requestsmail'}{'adminemail'} = ' checked="checked" '; + $checked{'updatesmail'}{'adminemail'} = ' checked="checked" '; + $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" '; + $checked{'hostipmail'}{'adminemail'} = ' checked="checked" '; + } elsif ($position eq 'bottom') { + $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" '; + $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" '; + if (ref($fields) eq 'ARRAY') { + foreach my $field (@{$fields}) { + $currfield{$field} = 'yes'; + } + } + $maxsize = '1.0'; + } } my ($titles,$short_titles) = &contact_titles(); my $rownum = 0; my $css_class; - foreach my $item (@contacts) { - $css_class = $rownum%2?' class="LC_odd_row"':''; - $datatable .= ''. - ''; - $rownum ++; + if ($position eq 'top') { + foreach my $item (@contacts) { + $css_class = $rownum%2?' class="LC_odd_row"':''; + $datatable .= ''. + ''; + $rownum ++; + } + } else { + foreach my $type (@mailings) { + $css_class = $rownum%2?' class="LC_odd_row"':''; + $datatable .= ''. + ''. + ''."\n"; + $rownum ++; + } } - foreach my $type (@mailings) { + if ($position eq 'middle') { + my %choices; + $choices{'reporterrors'} = &mt('E-mail error reports to [_1]', + &Apache::loncommon::modal_link('http://loncapa.org/core.html', + &mt('LON-CAPA core group - MSU'),600,500)); + $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]', + &Apache::loncommon::modal_link('http://loncapa.org/core.html', + &mt('LON-CAPA core group - MSU'),600,500)); + my @toggles = ('reporterrors','reportupdates'); + my %defaultchecked = ('reporterrors' => 'on', + 'reportupdates' => 'on'); + (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked, + \%choices,$rownum); + $datatable .= $reports; + } elsif ($position eq 'bottom') { $css_class = $rownum%2?' class="LC_odd_row"':''; $datatable .= ''. - ''. - ''."\n"; $rownum ++; } - my %choices; - $choices{'reporterrors'} = &mt('E-mail error reports to [_1]', - &Apache::loncommon::modal_link('http://loncapa.org/core.html', - &mt('LON-CAPA core group - MSU'),600,500)); - $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]', - &Apache::loncommon::modal_link('http://loncapa.org/core.html', - &mt('LON-CAPA core group - MSU'),600,500)); - my @toggles = ('reporterrors','reportupdates'); - my %defaultchecked = ('reporterrors' => 'on', - 'reportupdates' => 'on'); - (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked, - \%choices,$rownum); - $datatable .= $reports; $$rowtotal += $rownum; return $datatable; } +sub contacts_javascript { + return <<"ENDSCRIPT"; + + + +ENDSCRIPT +} + sub print_helpsettings { - my ($dom,$confname,$settings,$rowtotal) = @_; + my ($position,$dom,$settings,$rowtotal) = @_; + my $confname = $dom.'-domainconfig'; + my $formname = 'display'; my ($datatable,$itemcount); - $itemcount = 1; - my (%choices,%defaultchecked,@toggles); - $choices{'submitbugs'} = &mt('Display link to: [_1]?', - &Apache::loncommon::modal_link('http://bugs.loncapa.org', - &mt('LON-CAPA bug tracker'),600,500)); - %defaultchecked = ('submitbugs' => 'on'); - @toggles = ('submitbugs',); - - ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked, - \%choices,$itemcount); + if ($position eq 'top') { + $itemcount = 1; + my (%choices,%defaultchecked,@toggles); + $choices{'submitbugs'} = &mt('Display link to: [_1]?', + &Apache::loncommon::modal_link('http://bugs.loncapa.org', + &mt('LON-CAPA bug tracker'),600,500)); + %defaultchecked = ('submitbugs' => 'on'); + @toggles = ('submitbugs'); + ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked, + \%choices,$itemcount); + $$rowtotal ++; + } else { + my $css_class; + my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_'); + my (%customroles,%ordered,%current); + if (ref($settings) eq 'HASH') { + if (ref($settings->{'adhoc'}) eq 'HASH') { + %current = %{$settings->{'adhoc'}}; + } + } + my $count = 0; + foreach my $key (sort(keys(%existing))) { + if ($key=~/^rolesdef\_(\w+)$/) { + my $rolename = $1; + my (%privs,$order); + ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key}); + $customroles{$rolename} = \%privs; + if (ref($current{$rolename}) eq 'HASH') { + $order = $current{$rolename}{'order'}; + } + if ($order eq '') { + $order = $count; + } + $ordered{$order} = $rolename; + $count++; + } + } + my $maxnum = scalar(keys(%ordered)); + my @roles_by_num = (); + foreach my $item (sort {$a <=> $b } (keys(%ordered))) { + push(@roles_by_num,$item); + } + my $context = 'domprefs'; + my $crstype = 'Course'; + my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); + my @accesstypes = ('all','dh','da','none'); + my ($numstatustypes,@jsarray); + if (ref($types) eq 'ARRAY') { + if (@{$types} > 0) { + $numstatustypes = scalar(@{$types}); + push(@accesstypes,'status'); + @jsarray = ('bystatus'); + } + } + my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']); + if (keys(%domhelpdesk)) { + push(@accesstypes,('inc','exc')); + push(@jsarray,('notinc','notexc')); + } + my $hiddenstr = join("','",@jsarray); + $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname); + my $context = 'domprefs'; + my $crstype = 'Course'; + my $prefix = 'helproles_'; + my $add_class = 'LC_hidden'; + foreach my $num (@roles_by_num) { + my $role = $ordered{$num}; + my ($desc,$access,@statuses); + if (ref($current{$role}) eq 'HASH') { + $desc = $current{$role}{'desc'}; + $access = $current{$role}{'access'}; + if (ref($current{$role}{'insttypes'}) eq 'ARRAY') { + @statuses = @{$current{$role}{'insttypes'}}; + } + } + if ($desc eq '') { + $desc = $role; + } + my $identifier = 'custhelp'.$num; + my %full=(); + my %levels= ( + course => {}, + domain => {}, + system => {}, + ); + my %levelscurrent=( + course => {}, + domain => {}, + system => {}, + ); + &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent); + my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype); + $css_class = $itemcount%2?' class="LC_odd_row"':''; + my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"'; + $datatable .= ''. + ''; + $itemcount ++; + } + $css_class = $itemcount%2?' class="LC_odd_row"':''; + my $newcust = 'custhelp'.$count; + my (%privs,%levelscurrent); + my %full=(); + my %levels= ( + course => {}, + domain => {}, + system => {}, + ); + &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent); + my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype); + my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"'; + $datatable .= ''. + ''; + $count ++; + $$rowtotal += $count; + } return $datatable; } +sub adhocbutton { + my ($prefix,$num,$field,$visibility) = @_; + my %lt = &Apache::lonlocal::texthash( + show => 'Show details', + hide => 'Hide details', + ); + return ''.(' 'x10). + ''.(' 'x2).''.(' 'x2); +} + +sub helpsettings_javascript { + my ($roles_by_num,$total,$hiddenstr,$formname) = @_; + return unless(ref($roles_by_num) eq 'ARRAY'); + my %html_js_lt = &Apache::lonlocal::texthash( + show => 'Show details', + hide => 'Hide details', + ); + &html_escape(\%html_js_lt); + my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n"; + return <<"ENDSCRIPT"; + + +ENDSCRIPT +} + +sub helpdeskroles_access { + my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle, + $usertypes,$types,$domhelpdesk) = @_; + return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH')); + my %lt = &Apache::lonlocal::texthash( + 'rou' => 'Role usage', + 'whi' => 'Which helpdesk personnel may use this role?', + 'all' => 'All with domain helpdesk or helpdesk assistant role', + 'dh' => 'All with domain helpdesk role', + 'da' => 'All with domain helpdesk assistant role', + 'none' => 'None', + 'status' => 'Determined based on institutional status', + 'inc' => 'Include all, but exclude specific personnel', + 'exc' => 'Exclude all, but include specific personnel', + ); + my %usecheck = ( + all => ' checked="checked"', + ); + my %displaydiv = ( + status => 'none', + inc => 'none', + exc => 'none', + priv => 'block', + ); + my $output; + if (ref($current) eq 'HASH') { + if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) { + if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) { + $usecheck{$current->{access}} = $usecheck{'all'}; + delete($usecheck{'all'}); + if ($current->{access} =~ /^(status|inc|exc)$/) { + my $access = $1; + $displaydiv{$access} = 'inline'; + } elsif ($current->{access} eq 'none') { + $displaydiv{'priv'} = 'none'; + } + } + } + } + $output = '
'.$lt{'rou'}.''. + '

'.$lt{'whi'}.'

'; + foreach my $access (@{$accesstypes}) { + $output .= '

'; + if ($access eq 'status') { + $output .= '

'. + &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access}, + $othertitle,$usertypes,$types). + '
'; + } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) { + $output .= '
'. + &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk). + '
'; + } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) { + $output .= '
'. + &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk). + '
'; + } + $output .= '

'; + } + $output .= '
'; + return $output; +} + sub radiobutton_prefs { my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick, $additional,$align) = @_; @@ -2890,24 +3515,128 @@ sub print_coursedefaults { coursecredits => 'Credits can be specified for courses', uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)', usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)', + texengine => 'Default method to display mathematics', postsubmit => 'Disable submit button/keypress following student submission', + canclone => "People who may clone a course (besides course's owner and coordinators)", + mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver', ); my %staticdefaults = ( anonsurvey_threshold => 10, uploadquota => 500, postsubmit => 60, + mysqltables => 172800, ); if ($position eq 'top') { %defaultchecked = ( 'uselcmath' => 'on', 'usejsme' => 'on', + 'canclone' => 'none', ); @toggles = ('uselcmath','usejsme'); + my $deftex = $Apache::lonnet::deftex; + if (ref($settings) eq 'HASH') { + if ($settings->{'texengine'}) { + if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) { + $deftex = $settings->{'texengine'}; + } + } + } + $css_class = $itemcount%2?' class="LC_odd_row"':''; + my $mathdisp = ''."\n"; + $itemcount ++; ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked, \%choices,$itemcount); + $datatable = $mathdisp.$datatable; + $css_class = $itemcount%2?' class="LC_odd_row"':''; + $datatable .= + ''. + ''; + $itemcount ++; } else { $css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; - my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout); + my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql); my $currusecredits = 0; my $postsubmitclient = 1; my @types = ('official','unofficial','community','textbook'); @@ -2951,6 +3680,15 @@ sub print_coursedefaults { $deftimeout{$type} = $staticdefaults{'postsubmit'}; } } + if (ref($settings->{'mysqltables'}) eq 'HASH') { + foreach my $type (keys(%{$settings->{'mysqltables'}})) { + $currmysql{$type} = $settings->{'mysqltables'}{$type}; + } + } else { + foreach my $type (@types) { + $currmysql{$type} = $staticdefaults{'mysqltables'}; + } + } } else { foreach my $type (@types) { $deftimeout{$type} = $staticdefaults{'postsubmit'}; @@ -3028,13 +3766,27 @@ sub print_coursedefaults { $additional .= '
'; - if (($action eq 'login') || ($action eq 'directorysrch')) { + if ($action eq 'login') { $output .= ' '; } elsif ($action eq 'serverstatuses') { @@ -885,13 +940,9 @@ sub print_config_box { $rowtotal ++; if ($action eq 'quotas') { $output .= &print_quotas($dom,$settings,\$rowtotal,$action); - } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') || - ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) { + } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || + ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) { $output .= $item->{'print'}->($dom,$settings,\$rowtotal); - } elsif ($action eq 'scantron') { - $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal); - } elsif ($action eq 'helpsettings') { - $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal); } } $output .= ' @@ -1236,7 +1287,7 @@ sub print_login { } else { $datatable .= ''; } - $datatable .= ''; + $datatable .= ''; } $datatable .= '
'.&mt($item->{'header'}->[0]->{'col1'}).'
'.$choices->{'font'}.''.&mt('Default in use:').' '.$defaults->{'font'}.''.&mt('Default in use:').' '.$defaults->{'font'}.' '. ' '. - ' 
'.$choices->{'fontmenu'}.''.&mt('Default in use:').' '.$defaults->{'fontmenu'}.''.&mt('Default in use:').' '.$defaults->{'fontmenu'}.' 
'.$choices->{$item}.'    
'.$defaults->{'bgs'}{$item}.'
'.$choices->{$item}.'    
'.$defaults->{'bgs'}{$item}.'
'.$choices->{$item}.'
'.$defaults->{'links'}{$item}.'
'.$choices->{$item}.'
'.$defaults->{'links'}{$item}.'
'.$logincolors; # suppress image for Log-in header } elsif (!$is_custom) { if ($img ne 'domlogo') { - $output .= &mt('Default image:').'
'; + $output = &mt('Default image:').'
'; } else { - $output .= &mt('Default in use:').'
'; + $output = &mt('Default in use:').'
'; } } - if ($img eq 'login') { # suppress image for Log-in header - $output .= '
'.$logincolors; - } else { + if ($img ne 'login') { if ($img_import) { $output .= ''; } @@ -2105,7 +2155,7 @@ sub print_quotas { } sub print_requestmail { - my ($dom,$action,$settings,$rowtotal) = @_; + my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_; my ($now,$datatable,%currapp); $now = time; if (ref($settings) eq 'HASH') { @@ -2117,7 +2167,19 @@ sub print_requestmail { } my $numinrow = 2; my $css_class; - $css_class = ($$rowtotal%2? ' class="LC_odd_row"':''); + 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.'"'; + } my $text; if ($action eq 'requestcourses') { $text = &mt('Receive notification of course requests requiring approval'); @@ -2272,7 +2334,7 @@ sub print_textbookcourses { $datatable .= ''; } $datatable .= ' '."\n". - ''.&mt('Add').''. ''.&mt('Subject:').' '."\n". (' 'x2). @@ -2289,13 +2351,13 @@ sub print_textbookcourses { } else { $datatable .= ''; } + $datatable .= ''."\n"; } - $datatable .= ''."\n". - ''.&mt('LON-CAPA course:').' '. + $datatable .= ''.&mt('LON-CAPA course:').' '. &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom'). ''. &Apache::loncommon::selectcourse_link - ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course'); + ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course'). '
'.&mt('Failsafe for no drops when institutional data missing').''. + '
'.&mt('Directory search available?').' '. - '
'.&mt('Other domains can search?').' '. - '
'.&mt('Institutional directory search available?').' '. + '
'.&mt('Other domains can search institution?').' '. + '
'.&mt('Supported search methods'). - ''; - foreach my $title (@{$titleorder}) { - if (defined($searchtitles->{$title})) { - my $check = ' '; - if (ref($settings) eq 'HASH') { - if (ref($settings->{'searchby'}) eq 'ARRAY') { - if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) { - $check = ' checked="checked" '; + if ($cansrchrow) { + $$rowtotal ++; + $datatable .= ''; + } else { + $datatable .= ''; + } + $datatable .= ''; - $$rowtotal ++; - if ($cansrchrow) { - $datatable .= ''; + $datatable .= '
'.&mt('Supported search methods'). + ''; + foreach my $title (@{$titleorder}) { + if (defined($searchtitles->{$title})) { + my $check = ' '; + if (ref($settings) eq 'HASH') { + if (ref($settings->{'searchby'}) eq 'ARRAY') { + if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) { + $check = ' checked="checked" '; + } } } + $datatable .= ''; } - $datatable .= ''; } - } - $datatable .= '
'. + ''. - '
'.&mt('Search latitude').''. + ' '. + ' '. + '
'.&mt('LON-CAPA directory search available?').' '. + '
'.&mt('Other domains can search LON-CAPA domain?').' '. + '
'.&mt('Search latitude').''. - ' '. - ' '. - '
'.$titles->{$item}. - ''. - '
'.$titles->{$item}. + ''. + '
'. + $titles->{$type}.': '; + if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) { + $datatable .= '
'.&mt('E-mail recipient(s)').''; + } + $datatable .= ''; + foreach my $item (@contacts) { + $datatable .= ' '; + } + $datatable .= '
'.&mt('Others').':  '. + ''; + my %locchecked; + if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) { + foreach my $loc ('s','b') { + if ($includeloc{$type} eq $loc) { + $locchecked{$loc} = ' checked="checked"'; + last; + } + } + $datatable .= '
'.&mt('Bcc:').(' 'x6). + '
'. + '
'.&mt('Optional added text').''. + &mt('Text automatically added to e-mail:').' '. + '
'. + ''.&mt('Location:').' '. + ''. + (' 'x2). + ''. + '
'; + } + $datatable .= '
'. - $titles->{$type}.': '. - ''; - foreach my $item (@contacts) { - $datatable .= ' '; - } - $datatable .= '
'.&mt('Others').':  '. - ''; - if ($type eq 'helpdeskmail') { - $datatable .= '
'.&mt('Bcc:').(' 'x6). - ''; + '
'.&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 .= ''; + foreach my $field (@{$fields}) { + $datatable .= ''. + ''; + } + $datatable .= '
'.&mt('Field').''.&mt('Status').'
'.$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"'; + } + $datatable .= ''.(' 'x2); + } + } + if ($field eq 'screenshot') { + my $display; + if ($currfield{$field} eq 'no') { + $display = ' style="display:none"'; + } + $datatable .= '
'.&mt('Maximum size for upload (MB)').''. + ''; + } + $datatable .= '
'; } $datatable .= '
'.$role.'
'. + ''.(' 'x2). + ''. + '
'.&mt('Role name').''. + &mt('Name shown to users:'). + ''. + '
'. + &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes, + $othertitle,$usertypes,$types,\%domhelpdesk). + '
'. + ''.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').''. + &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels, + \%levelscurrent,$identifier, + 'LC_hidden',$prefix.$num.'_privs'). + '
'.&mt('Role name').''. + ''. + &mt('Internal name:'). + ''. + ''.(' 'x4). + ''. + &mt('Name shown to users:'). + ''. + '
'. + &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle, + $usertypes,$types,\%domhelpdesk). + '
'.&mt('Role privileges').''. + &Apache::lonuserutils::custom_role_header($context,$crstype, + \@templateroles,$newcust). + &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels, + \%levelscurrent,$newcust). + '
'. + &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname). + '
'. + ''.$choices{'texengine'}. + ''. + '
'. + ''.$choices{'canclone'}. + ''; + my $currcanclone = 'none'; + my $onclick; + my @cloneoptions = ('none','domain'); + my %clonetitles = ( + none => 'No additional course requesters', + domain => "Any course requester in course's domain", + instcode => 'Course requests for official courses ...', + ); + my (%codedefaults,@code_order,@posscodes); + if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults, + \@code_order) eq 'ok') { + if (@code_order > 0) { + push(@cloneoptions,'instcode'); + $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"'; + } + } + if (ref($settings) eq 'HASH') { + if ($settings->{'canclone'}) { + if (ref($settings->{'canclone'}) eq 'HASH') { + if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') { + if (@code_order > 0) { + $currcanclone = 'instcode'; + @posscodes = @{$settings->{'canclone'}{'instcode'}}; + } + } + } elsif ($settings->{'canclone'} eq 'domain') { + $currcanclone = $settings->{'canclone'}; + } + } + } + foreach my $option (@cloneoptions) { + my ($checked,$additional); + if ($currcanclone eq $option) { + $checked = ' checked="checked"'; + } + if ($option eq 'instcode') { + if (@code_order) { + my $show = 'none'; + if ($checked) { + $show = 'block'; + } + $additional = '
'. + &mt('Institutional codes for new and cloned course have identical:'). + '
'; + foreach my $item (@code_order) { + my $codechk; + if ($checked) { + if (grep(/^\Q$item\E$/,@posscodes)) { + $codechk = ' checked="checked"'; + } + } + $additional .= ''; + } + $additional .= (' 'x2).'('.&mt('check as many as needed').')
'; + } + } + $datatable .= + ' '.$additional.'
'; + } + $datatable .= '
'."\n"; %defaultchecked = ('postsubmit' => 'on'); @toggles = ('postsubmit'); - my $current = { - 'postsubmit' => $postsubmitclient, - }; + $current = { + 'postsubmit' => $postsubmitclient, + }; ($table,$itemcount) = &radiobutton_prefs($current,\@toggles,\%defaultchecked, \%choices,$itemcount,$onclick,$additional,'left'); $datatable .= $table; + $css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; + $datatable .= ''. + $choices{'mysqltables'}. + ''. + ''. + ''; + foreach my $type (@types) { + $datatable .= ''; + } + $datatable .= '
'.&mt($type).'
'. + '
'."\n"; + $itemcount ++; + } $$rowtotal += $itemcount; return $datatable; @@ -3228,7 +3980,7 @@ sub print_validation_rows { ' '; } } elsif ($item eq 'markup') { - $datatable .= ''; } @@ -3250,7 +4002,7 @@ sub print_validation_rows { my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio', 'validationdc',%currhash); my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; - $datatable .= ''; + $datatable .= ''; if ($numdc > 1) { $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)'); } else { @@ -3279,7 +4031,13 @@ sub print_usersessions { if ($position eq 'top') { if (keys(%serverhomes) > 1) { my %spareid = ¤t_offloads_to($dom,$settings,\%servers); - $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal); + my $curroffloadnow; + if (ref($settings) eq 'HASH') { + if (ref($settings->{'offloadnow'}) eq 'HASH') { + $curroffloadnow = $settings->{'offloadnow'}; + } + } + $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal); } else { $datatable .= ''. &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.'); @@ -3529,7 +4287,7 @@ sub current_offloads_to { } sub spares_row { - my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_; + my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_; my $css_class; my $numinrow = 4; my $itemcount = 1; @@ -3549,12 +4307,21 @@ sub spares_row { } } next unless (ref($spareid->{$server}) eq 'HASH'); + my $checkednow; + if (ref($curroffloadnow) eq 'HASH') { + if ($curroffloadnow->{$server}) { + $checkednow = ' checked="checked"'; + } + } $css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; $datatable .= ' '. &mt('[_1] when busy, offloads to:' - ,''.$server.''). + ,''.$server.'').'
'. + ''."\n". + ''. "\n"; my (%current,%canselect); my @choices = @@ -3679,13 +4446,13 @@ sub print_loadbalancing { my $numinrow = 1; my $datatable; my %servers = &Apache::lonnet::internet_dom_servers($dom); - my (%currbalancer,%currtargets,%currrules,%existing); + my (%currbalancer,%currtargets,%currrules,%existing,%currcookies); if (ref($settings) eq 'HASH') { %existing = %{$settings}; } if ((keys(%servers) > 1) || (keys(%existing) > 0)) { &get_loadbalancers_config(\%servers,\%existing,\%currbalancer, - \%currtargets,\%currrules); + \%currtargets,\%currrules,\%currcookies); } else { return; } @@ -3759,6 +4526,12 @@ sub print_loadbalancing { my ($numspares,@spares) = &count_servers($lonhost,%servers); my @sparestypes = ('primary','default'); my %typetitles = &sparestype_titles(); + my %hostherechecked = ( + no => ' checked="checked"', + ); + my %balcookiechecked = ( + no => ' checked="checked"', + ); foreach my $sparetype (@sparestypes) { my $targettable; for (my $i=0; $i<$numspares; $i++) { @@ -3804,8 +4577,35 @@ sub print_loadbalancing { $datatable .= ''.$typetitles{$sparetype}.'
'. ''.$targettable.'

'; } + $hostherechecked{$sparetype} = ''; + if (ref($currtargets{$lonhost}) eq 'HASH') { + if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') { + if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) { + $hostherechecked{$sparetype} = ' checked="checked"'; + $hostherechecked{'no'} = ''; + } + } + } } - $datatable .= ''. + if ($currcookies{$lonhost}) { + %balcookiechecked = ( + yes => ' checked="checked"', + ); + } + $datatable .= &mt('Hosting on balancer itself').'
'. + '
'; + foreach my $sparetype (@sparestypes) { + $datatable .= '
'; + } + $datatable .= &mt('Use balancer cookie').'
'. + '
'. + '
'. + ''. &loadbalancing_rules($dom,$intdom,$currrules{$lonhost}, $othertitle,$usertypes,$types,\%servers, \%currbalancer,$lonhost, @@ -3819,10 +4619,11 @@ sub print_loadbalancing { } sub get_loadbalancers_config { - my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_; + my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_; return unless ((ref($servers) eq 'HASH') && (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') && - (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH')); + (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') && + (ref($currcookies) eq 'HASH')); if (keys(%{$existing}) > 0) { my $oldlonhost; foreach my $key (sort(keys(%{$existing}))) { @@ -3841,6 +4642,9 @@ sub get_loadbalancers_config { $currbalancer->{$key} = 1; $currtargets->{$key} = $existing->{$key}{'targets'}; $currrules->{$key} = $existing->{$key}{'rules'}; + if ($existing->{$key}{'cookie'}) { + $currcookies->{$key} = 1; + } } } } else { @@ -3896,9 +4700,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_/) { @@ -4021,15 +4830,17 @@ sub sparestype_titles { sub contact_titles { my %titles = &Apache::lonlocal::texthash ( - 'supportemail' => 'Support E-mail address', - '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 to be e-mailed to', - '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', + 'supportemail' => 'Support E-mail address', + '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', + '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', 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID', + 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes', ); my %short_titles = &Apache::lonlocal::texthash ( adminemail => 'Admin E-mail address', @@ -4038,6 +4849,34 @@ sub contact_titles { return (\%titles,\%short_titles); } +sub helpform_fields { + my %titles = &Apache::lonlocal::texthash ( + 'username' => 'Name', + 'user' => 'Username/domain', + 'phone' => 'Phone', + 'cc' => 'Cc e-mail', + 'course' => 'Course Details', + 'section' => 'Sections', + 'screenshot' => 'File upload', + ); + my @fields = ('username','phone','user','course','section','cc','screenshot'); + my %possoptions = ( + username => ['yes','no','req'], + phone => ['yes','no','req'], + user => ['yes','no'], + cc => ['yes','no'], + course => ['yes','no'], + section => ['yes','no'], + screenshot => ['yes','no'], + ); + my %fieldoptions = &Apache::lonlocal::texthash ( + 'yes' => 'Optional', + 'req' => 'Required', + 'no' => "Not shown", + ); + return (\@fields,\%titles,\%fieldoptions,\%possoptions); +} + sub tool_titles { my %titles = &Apache::lonlocal::texthash ( aboutme => 'Personal web page', @@ -4222,7 +5061,8 @@ sub print_usercreation { sub print_selfcreation { my ($position,$dom,$settings,$rowtotal) = @_; - my (@selfcreate,$createsettings,$processing,$datatable); + my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified, + $emaildomain,$datatable); if (ref($settings) eq 'HASH') { if (ref($settings->{'cancreate'}) eq 'HASH') { $createsettings = $settings->{'cancreate'}; @@ -4239,12 +5079,22 @@ sub print_selfcreation { if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') { $processing = $createsettings->{'selfcreateprocessing'}; } + if (ref($createsettings->{'emailoptions'}) eq 'HASH') { + $emailoptions = $createsettings->{'emailoptions'}; + } + if (ref($createsettings->{'emailverified'}) eq 'HASH') { + $emailverified = $createsettings->{'emailverified'}; + } + if (ref($createsettings->{'emaildomain'}) eq 'HASH') { + $emaildomain = $createsettings->{'emaildomain'}; + } } } } 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', @@ -4259,14 +5109,12 @@ sub print_selfcreation { ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked, \%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 ++; } } @@ -4279,7 +5127,7 @@ sub print_selfcreation { $datatable .= ''. ''.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').''. ''."\n". - '\n". + '\n"; return $output; } sub captcha_choice { - my ($context,$settings,$itemcount) = @_; - my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext); + my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_; + my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext, + $vertext,$currver); my %lt = &captcha_phrases(); $keyentry = 'hidden'; if ($context eq 'cancreate') { @@ -4465,6 +5590,11 @@ sub captcha_choice { $pubtext = $lt{'pub'}; $privtext = $lt{'priv'}; $keyentry = 'text'; + $vertext = $lt{'ver'}; + $currver = $settings->{'recaptchaversion'}; + if ($currver ne '2') { + $currver = 1; + } } if (ref($settings->{'recaptchakeys'}) eq 'HASH') { $currpub = $settings->{'recaptchakeys'}{'public'}; @@ -4473,7 +5603,20 @@ sub captcha_choice { } else { $checked{'original'} = ' checked="checked"'; } - my $css_class = $itemcount%2?' class="LC_odd_row"':''; + my $css_class; + if ($itemcount%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.'"'; + } my $output = ''. '
'."\n"; + ''."\n"; for (my $i=0; $i<@fields; $i++) { $rem = $i%($numperrow); if ($rem == 0) { @@ -4311,143 +5159,420 @@ 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 ( - cancreate_email => 'E-mail address as username', + 'cancreate_email' => 'Non-institutional username (via e-mail verification)', ); my @toggles = sort(keys(%choices)); my %defaultchecked = ( 'cancreate_email' => 'off', ); - my $itemcount = 0; + my $customclass = 'LC_selfcreate_email'; + my $classprefix = 'LC_canmodify_emailusername_'; + my $optionsprefix = 'LC_options_emailusername_'; my $display = 'none'; + my $rowstyle = 'display:none'; if (grep(/^\Qemail\E$/,@selfcreate)) { $display = 'block'; + $rowstyle = 'display:table-row'; } - my $onclick = "toggleDisplay(this.form,'emailoptions');"; - my $additional = '
'; + my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');"; + ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked, + \%choices,$$rowtotal,$onclick); + $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass, + $rowstyle); + $$rowtotal ++; + $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass, + $rowstyle); + $$rowtotal ++; + my (@ordered,@posstypes,%usertypeshash); 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'}; - $order = $domdefaults{'inststatusguest'}; - } - if (ref($order) eq 'ARRAY') { - push(@{$order},'default'); - if (@{$order} > 1) { - $usertypes->{'default'} = &mt('Other users'); - $additional .= '
'; - foreach my $status (@{$order}) { - $additional .= ''; - } - $additional .= ''; - foreach my $status (@{$order}) { - $additional .= ''; + my ($emailrules,$emailruleorder) = + &Apache::lonnet::inst_userrules($dom,'email'); + my $primary_id = &Apache::lonnet::domain($dom,'primary'); + my $intdom = &Apache::lonnet::internet_dom($primary_id); + if (ref($types) eq 'ARRAY') { + @posstypes = @{$types}; + } + if (@posstypes) { + unless (grep(/^default$/,@posstypes)) { + push(@posstypes,'default'); + } + if (ref($usertypes) eq 'HASH') { + %usertypeshash = %{$usertypes}; + } + my $currassign; + if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') { + $currassign = { + selfassign => $domdefaults{'inststatusguest'}, + }; + @ordered = @{$domdefaults{'inststatusguest'}}; + } else { + $currassign = { selfassign => [] }; + } + my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);". + "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);"; + $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom, + $numinrow,$othertitle,'selfassign', + $rowtotal,$onclicktypes,$customclass, + $rowstyle); + $$rowtotal ++; + $usertypeshash{'default'} = $othertitle; + foreach my $status (@posstypes) { + my $css_class; + if ($$rowtotal%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$/,@ordered)) { + $currstyle = $rowstyle; + $hidden = 0; + } + $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain, + $emailrules,$emailruleorder,$settings,$status,$rowid, + $usertypeshash{$status},$css_class,$currstyle,$intdom); + unless ($hidden) { + $$rowtotal ++; } - $additional .= '
'.$usertypes->{$status}.'
'.&email_as_username($rowtotal,$processing,$status).'
'; - } else { - $usertypes->{'default'} = &mt('All users'); - $additional .= &email_as_username($rowtotal,$processing); } + } else { + my $css_class; + if ($$rowtotal%2) { + $css_class = 'LC_odd_row '; + } + $css_class .= $customclass; + $usertypeshash{'default'} = $othertitle; + $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain, + $emailrules,$emailruleorder,$settings,'default','', + $othertitle,$css_class,$rowstyle,$intdom); + $$rowtotal ++; } - $additional .= ''."\n"; - - ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked, - \%choices,$$rowtotal,$onclick,$additional); - $$rowtotal ++; - $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal); - $$rowtotal ++; my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info(); $numinrow = 1; - if (ref($order) eq 'ARRAY') { - foreach my $status (@{$order}) { + if (@posstypes) { + foreach my $status (@posstypes) { + my $rowid = $classprefix.$status; + my $datarowstyle = 'display:none'; + if (grep(/^\Q$status\E$/,@ordered)) { + $datarowstyle = $rowstyle; + } $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings, - $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles); - $$rowtotal ++; + $numinrow,$$rowtotal,\%usertypeshash,$infofields, + $infotitles,$rowid,$customclass,$datarowstyle); + unless ($datarowstyle eq 'display:none') { + $$rowtotal ++; + } } + } else { + $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings, + $numinrow,$$rowtotal,\%usertypeshash,$infofields, + $infotitles,'',$customclass,$rowstyle); } - my ($emailrules,$emailruleorder) = - &Apache::lonnet::inst_userrules($dom,'email'); - if (ref($emailrules) eq 'HASH') { - if (keys(%{$emailrules}) > 0) { - $datatable .= &user_formats_row('email',$settings,$emailrules, - $emailruleorder,$numinrow,$$rowtotal); - $$rowtotal ++; + } + return $datatable; +} + +sub selfcreate_javascript { + return <<"ENDSCRIPT"; + + + +ENDSCRIPT +} + +sub noninst_users { + my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules, + $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_; + 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); + if ($type eq 'default') { + $description = &mt('Requests for: [_1]',$typetitle); + } else { + $description = &mt('Requests for: [_1] (status self-reported)',$typetitle); + } + $output = ''. + "
$description'. + ''; + my %headers = &Apache::lonlocal::texthash( + approve => 'Processing', + email => 'E-mail', + username => 'Username', + ); + foreach my $item ('approve','email','username') { + $output .= ''; + } + $output .= ''; + foreach my $item ('approve','email','username') { + $output .= ''."\n"; } - $$rowtotal ++; + $output .= "
'.$headers{$item}.'
'; + my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom); + if ($item eq 'approve') { + %choices = &Apache::lonlocal::texthash ( + automatic => 'Automatically approved', + approval => 'Queued for approval', + ); + @options = ('automatic','approval'); + $hashref = $processing; + $defoption = 'automatic'; + $name = 'cancreate_emailprocess_'.$type; + } elsif ($item eq 'email') { + %choices = &Apache::lonlocal::texthash ( + any => 'Any e-mail', + inst => 'Institutional only', + noninst => 'Non-institutional only', + custom => 'Custom restrictions', + ); + @options = ('any','inst','noninst'); + my $showcustom; + if (ref($emailrules) eq 'HASH') { + if (keys(%{$emailrules}) > 0) { + push(@options,'custom'); + $showcustom = 'cancreate_emailrule'; + if (ref($settings) eq 'HASH') { + if (ref($settings->{'email_rule'}) eq 'ARRAY') { + foreach my $rule (@{$settings->{'email_rule'}}) { + if (exists($emailrules->{$rule})) { + $hascustom ++; + } + } + } elsif (ref($settings->{'email_rule'}) eq 'HASH') { + if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') { + foreach my $rule (@{$settings->{'email_rule'}{$type}}) { + if (exists($emailrules->{$rule})) { + $hascustom ++; + } + } + } + } + } + } + } + $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',". + "'cancreate_emaildomain','$type'".');"'; + $hashref = $emailoptions; + $defoption = 'any'; + $name = 'cancreate_emailoptions_'.$type; + } elsif ($item eq 'username') { + %choices = &Apache::lonlocal::texthash ( + all => 'Same as e-mail', + first => 'Omit @domain', + free => 'Free to choose', + ); + @options = ('all','first','free'); + $hashref = $emailverified; + $defoption = 'all'; + $name = 'cancreate_usernameoptions_'.$type; + } + foreach my $option (@options) { + my $checked; + if (ref($hashref) eq 'HASH') { + if ($type eq '') { + if (!exists($hashref->{'default'})) { + if ($option eq $defoption) { + $checked = ' checked="checked"'; + } + } else { + if ($hashref->{'default'} eq $option) { + $checked = ' checked="checked"'; + } } } else { - if ($processing->{$type} eq $option) { - $checked = ' checked="checked"'; + if (!exists($hashref->{$type})) { + if ($option eq $defoption) { + $checked = ' checked="checked"'; + } + } else { + if ($hashref->{$type} eq $option) { + $checked = ' checked="checked"'; + } + } + } + } elsif (($item eq 'email') && ($hascustom)) { + if ($option eq 'custom') { + $checked = ' checked="checked"'; + } + } elsif ($option eq $defoption) { + $checked = ' checked="checked"'; + } + $output .= '
'; + if ($item eq 'email') { + if ($option eq 'custom') { + my $id = 'cancreate_emailrule_'.$type; + my $display = 'none'; + if ($checked) { + $display = 'inline'; + } + my $numinrow = 2; + $output .= '
'. + ''.&mt('Disallow').''. + &user_formats_row('email',$settings,$emailrules, + $emailruleorder,$numinrow,'',$type); + '
'; + } elsif (($option eq 'inst') || ($option eq 'noninst')) { + my %text = &Apache::lonlocal::texthash ( + inst => 'must end:', + noninst => 'cannot end:', + ); + my $value; + if (ref($emaildomain) eq 'HASH') { + if (ref($emaildomain->{$type}) eq 'HASH') { + $value = $emaildomain->{$type}->{$option}; + } } + if ($value eq '') { + $value = '@'.$intdom; + } + my $condition = 'cancreate_emaildomain_'.$option.'_'.$type; + my $display = 'none'; + if ($checked) { + $display = 'inline'; + } + $output .= '
'. + ''.$text{$option}.' '. + ''. + '
'; } } - } elsif ($option eq 'automatic') { - $checked = ' checked="checked"'; - } - my $name = 'cancreate_emailprocess'; - if (($type ne '') && ($type ne 'default')) { - $name .= '_'.$type; - } - $output .= ''; - if ($type eq '') { - $output .= ' '; - } else { - $output .= '
'; } + $output .= '
'.$rowname.''."\n". ''."\n". - '
'."\n"; @@ -4492,35 +5635,35 @@ sub captcha_choice { # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain. # $output .= '
'."\n". + '
'."\n". ''.$pubtext.' '."\n". '
'."\n". ''.$privtext.' '."\n". '
'."\n". + $currpriv.'" size="40" />
'. + ''.$vertext.' '."\n". + '
'. + '
'."\n". ''; return $output; } sub user_formats_row { - my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_; + my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_; my $output; my %text = ( 'username' => 'new usernames', 'id' => 'IDs', - 'email' => 'self-created accounts (e-mail)', ); - my $css_class = $rowcount%2?' class="LC_odd_row"':''; - $output = ''. - ''; - if ($type eq 'email') { - $output .= &mt("Formats disallowed for $text{$type}: "); - } else { - $output .= &mt("Format rules to check for $text{$type}: "); + unless ($type eq 'email') { + my $css_class = $rowcount%2?' class="LC_odd_row"':''; + $output = ''. + ''. + &mt("Format rules to check for $text{$type}: "). + ''; } - $output .= ''. - ''; + $output .= '
'; my $rem; if (ref($ruleorder) eq 'ARRAY') { for (my $i=0; $i<@{$ruleorder}; $i++) { @@ -4538,25 +5681,41 @@ sub user_formats_row { if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) { $check = ' checked="checked" '; } + } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) { + if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') { + if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) { + $check = ' checked="checked" '; + } + } } } + my $name = $type.'_rule'; + if ($type eq 'email') { + $name .= '_'.$status; + } $output .= ''; } } $rem = @{$ruleorder}%($numinrow); } - my $colsleft = $numinrow - $rem; + my $colsleft; + if ($rem) { + $colsleft = $numinrow - $rem; + } if ($colsleft > 1 ) { $output .= ''; } elsif ($colsleft == 1) { $output .= ''; } - $output .= '
'. ''. '  
'; + unless ($type eq 'email') { + $output .= ''; + } return $output; } @@ -4633,7 +5792,10 @@ sub print_usermodification { sub print_defaults { my ($position,$dom,$settings,$rowtotal) = @_; my $rownum = 0; - my ($datatable,$css_class); + my ($datatable,$css_class,$titles); + unless ($position eq 'bottom') { + $titles = &defaults_titles($dom); + } if ($position eq 'top') { my @items = ('auth_def','auth_arg_def','lang_def','timezone_def', 'datelocale_def','portal_def'); @@ -4646,7 +5808,6 @@ sub print_defaults { $defaults{$item} = $domdefaults{$item}; } } - my $titles = &defaults_titles($dom); foreach my $item (@items) { if ($rownum%2) { $css_class = ''; @@ -4681,11 +5842,8 @@ sub print_defaults { my $includeempty = 1; $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty); } elsif ($item eq 'lang_def') { - my %langchoices = &get_languages_hash(); - $langchoices{''} = 'No language preference'; - %langchoices = &Apache::lonlocal::texthash(%langchoices); - $datatable .= &Apache::loncommon::select_form($defaults{$item},$item, - \%langchoices); + my $includeempty = 1; + $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty); } else { my $size; if ($item eq 'portal_def') { @@ -4697,20 +5855,94 @@ sub print_defaults { $datatable .= ''; $rownum ++; } + } elsif ($position eq 'middle') { + my @items = ('intauth_cost','intauth_check','intauth_switch'); + my %defaults; + if (ref($settings) eq 'HASH') { + %defaults = %{$settings}; + if ($defaults{'intauth_cost'} !~ /^\d+$/) { + $defaults{'intauth_cost'} = 10; + } + if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) { + $defaults{'intauth_check'} = 0; + } + if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) { + $defaults{'intauth_switch'} = 0; + } + } else { + %defaults = ( + 'intauth_cost' => 10, + 'intauth_check' => 0, + 'intauth_switch' => 0, + ); + } + foreach my $item (@items) { + if ($rownum%2) { + $css_class = ''; + } else { + $css_class = ' class="LC_odd_row" '; + } + $datatable .= ''. + ''.$titles->{$item}. + ''; + if ($item eq 'intauth_switch') { + my @options = (0,1,2); + my %optiondesc = &Apache::lonlocal::texthash ( + 0 => 'No', + 1 => 'Yes', + 2 => 'Yes, and copy existing passwd file to passwd.bak file', + ); + $datatable .= ''; + foreach my $option (@options) { + my $checked = ' '; + if ($defaults{$item} eq $option) { + $checked = ' checked="checked"'; + } + $datatable .= ''; + } + $datatable .= '
'. + '
'; + } elsif ($item eq 'intauth_check') { + my @options = (0,1,2); + my %optiondesc = &Apache::lonlocal::texthash ( + 0 => 'No', + 1 => 'Yes, allow login then update passwd file using default cost (if higher)', + 2 => 'Yes, disallow login if stored cost is less than domain default', + ); + $datatable .= ''; + foreach my $option (@options) { + my $checked = ' '; + my $onclick; + if ($defaults{$item} eq $option) { + $checked = ' checked="checked"'; + } + if ($option == 2) { + $onclick = ' onclick="javascript:warnIntAuth(this);"'; + } + $datatable .= ''; + } + $datatable .= '
'. + '
'; + } else { + $datatable .= ''; + } + $datatable .= ''; + $rownum ++; + } } else { - my (%defaults); + my %defaults; if (ref($settings) eq 'HASH') { - if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') && - (ref($settings->{'inststatusguest'}) eq 'ARRAY')) { + if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) { my $maxnum = @{$settings->{'inststatusorder'}}; for (my $i=0; $i<$maxnum; $i++) { $css_class = $rownum%2?' class="LC_odd_row"':''; my $item = $settings->{'inststatusorder'}->[$i]; my $title = $settings->{'inststatustypes'}->{$item}; - my $guestok; - if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) { - $guestok = 1; - } my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"'; $datatable .= ''. ''. @@ -4723,23 +5955,12 @@ sub print_defaults { } $datatable .= ''; } - my ($checkedon,$checkedoff); - $checkedoff = ' checked="checked"'; - if ($guestok) { - $checkedon = $checkedoff; - $checkedoff = ''; - } $datatable .= ' '.&mt('Internal ID:').' '.$item.' '. ''. &mt('delete').''. ''.&mt('Name displayed:'). ''. - ''. - ''. - ''.(' 'x2). - ''; + '
'; } $css_class = $rownum%2?' class="LC_odd_row"':''; my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"'; @@ -4754,16 +5975,11 @@ sub print_defaults { $datatable .= ''; } $datatable .= ' '.&mt('Internal ID:'). - '
'. + ''. ' '.&mt('(new)'). ''. &mt('Name displayed:'). ''. - ''. - ''.(' 'x2). - ''; ''."\n"; $rownum ++; } @@ -4793,6 +6009,9 @@ sub defaults_titles { 'timezone_def' => 'Default timezone', 'datelocale_def' => 'Default locale for dates', 'portal_def' => 'Portal/Default URL', + 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)', + 'intauth_check' => 'Check bcrypt cost if authenticated', + 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication', ); if ($dom) { my $uprimary_id = &Apache::lonnet::domain($dom,'primary'); @@ -4807,6 +6026,58 @@ sub defaults_titles { return (\%titles); } +sub print_scantron { + my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_; + if ($position eq 'top') { + return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal); + } else { + return &print_scantronconfig($dom,$settings,\$rowtotal); + } +} + +sub scantron_javascript { + return <<"ENDSCRIPT"; + + + +ENDSCRIPT + +} + sub print_scantronformat { my ($r,$dom,$confname,$settings,$rowtotal) = @_; my $itemcount = 1; @@ -4833,8 +6104,8 @@ sub print_scantronformat { if ($configuserok eq 'ok') { if ($author_ok eq 'ok') { my %legacyfile = ( - default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', - custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', + default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', + custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', ); my %md5chk; foreach my $type (keys(%legacyfile)) { @@ -4843,7 +6114,7 @@ sub print_scantronformat { } if ($md5chk{'default'} ne $md5chk{'custom'}) { foreach my $type (keys(%legacyfile)) { - ($scantronurls{$type},my $error) = + ($scantronurls{$type},my $error) = &legacy_scantronformat($r,$dom,$confname, $type,$legacyfile{$type}, $scantronurls{$type}, @@ -4854,13 +6125,13 @@ sub print_scantronformat { } if (keys(%error) == 0) { $is_custom = 1; - $confhash{'scantron'}{'scantronformat'} = + $confhash{'scantron'}{'scantronformat'} = $scantronurls{'custom'}; - my $putresult = + my $putresult = &Apache::lonnet::put_dom('configuration', \%confhash,$dom); if ($putresult ne 'ok') { - $error{'custom'} = + $error{'custom'} = ''. &mt('An error occurred updating the domain configuration: [_1]',$putresult).''; } @@ -4980,6 +6251,129 @@ sub legacy_scantronformat { return ($url,$error); } +sub print_scantronconfig { + my ($dom,$settings,$rowtotal) = @_; + my $itemcount = 2; + my $is_checked = ' checked="checked"'; + my %optionson = ( + hdr => ' checked="checked"', + pad => ' checked="checked"', + rem => ' checked="checked"', + ); + my %optionsoff = ( + hdr => '', + pad => '', + rem => '', + ); + my $currcsvsty = 'none'; + my ($datatable,%csvfields,%checked,%onclick,%csvoptions); + my @fields = &scantroncsv_fields(); + my %titles = &scantronconfig_titles(); + if (ref($settings) eq 'HASH') { + if (ref($settings->{config}) eq 'HASH') { + if ($settings->{config}->{dat}) { + $checked{'dat'} = $is_checked; + } + if (ref($settings->{config}->{csv}) eq 'HASH') { + if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') { + %csvfields = %{$settings->{config}->{csv}->{fields}}; + if (keys(%csvfields) > 0) { + $checked{'csv'} = $is_checked; + $currcsvsty = 'block'; + } + } + if (ref($settings->{config}->{csv}->{options}) eq 'HASH') { + %csvoptions = %{$settings->{config}->{csv}->{options}}; + foreach my $option (keys(%optionson)) { + unless ($csvoptions{$option}) { + $optionsoff{$option} = $optionson{$option}; + $optionson{$option} = ''; + } + } + } + } + } else { + $checked{'dat'} = $is_checked; + } + } else { + $checked{'dat'} = $is_checked; + } + $onclick{'csv'} = ' onclick="toggleScantron(this.form);"'; + my $css_class = $itemcount%2? ' class="LC_odd_row"':''; + $datatable = ''.&mt('Supported formats').''. + ''; + foreach my $item ('dat','csv') { + my $id; + if ($item eq 'csv') { + $id = 'id="scantronconfcsv" '; + } + $datatable .= ''.(' 'x3); + if ($item eq 'csv') { + $datatable .= '
'. + ''.&mt('CSV Column Mapping').''. + ''."\n"; + foreach my $col (@fields) { + my $selnone; + if ($csvfields{$col} eq '') { + $selnone = ' selected="selected"'; + } + $datatable .= ''. + ''; + } + $datatable .= '
'.&mt('Field').''.&mt('Location').'
'.$titles{$col}.'
'. + '
'. + ''.&mt('CSV Options').''; + foreach my $option ('hdr','pad','rem') { + $datatable .= ''.$titles{$option}.':'. + ''.(' 'x2)."\n". + '
'; + } + $datatable .= '
'; + $itemcount ++; + } + } + $datatable .= ''; + $$rowtotal ++; + return $datatable; +} + +sub scantronconfig_titles { + return &Apache::lonlocal::texthash( + dat => 'Standard format (.dat)', + csv => 'Comma separated values (.csv)', + hdr => 'Remove first line in file (contains column titles)', + pad => 'Prepend 0s to PaperID', + rem => 'Remove leading spaces (except Question Response columns)', + CODE => 'CODE', + ID => 'Student ID', + PaperID => 'Paper ID', + FirstName => 'First Name', + LastName => 'Last Name', + FirstQuestion => 'First Question Response', + Section => 'Section', + ); +} + +sub scantroncsv_fields { + return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion'); +} + sub print_coursecategories { my ($position,$dom,$hdritem,$settings,$rowtotal) = @_; my $datatable; @@ -5022,7 +6416,7 @@ sub print_coursecategories { ''.$lt{$type}.' '; } - $datatable .= ''; + $datatable .= '
'; $itemcount ++; } $$rowtotal += $itemcount; @@ -5233,7 +6627,7 @@ sub print_coursecategories { $datatable .= &initialize_categories($itemcount); } } else { - $datatable .= ''.$hdritem->{'header'}->[1]->{'col2'}.'' + $datatable .= ''.$hdritem->{'header'}->[1]->{'col2'}.'' .&initialize_categories($itemcount); } $$rowtotal += $itemcount; @@ -5281,7 +6675,7 @@ sub print_serverstatuses { ''. ''. - ''."\n"; + ''."\n"; } $$rowtotal += $rownum; return $datatable; @@ -5291,12 +6685,40 @@ sub serverstatus_pages { return ('userstatus','lonstatus','loncron','server-status','codeversions', 'checksums','clusterstatus','metadata_keywords','metadata_harvest', 'takeoffline','takeonline','showenv','toggledebug','ping','domconf', - 'uniquecodes','diskusage'); + 'uniquecodes','diskusage','coursecatalog'); } sub defaults_javascript { my ($settings) = @_; - return unless (ref($settings) eq 'HASH'); + my $intauthcheck = &mt('Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.'); + my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.'); + &js_escape(\$intauthcheck); + &js_escape(\$intauthcost); + my $intauthjs = <<"ENDSCRIPT"; + +function warnIntAuth(field) { + if (field.name == 'intauth_check') { + if (field.value == '2') { + alert('$intauthcheck'); + } + } + if (field.name == 'intauth_cost') { + field.value.replace(/\s/g,''); + if (field.value != '') { + var regexdigit=/^\\d+\$/; + if (!regexdigit.test(field.value)) { + alert('$intauthcost'); + } + } + } + return; +} + +ENDSCRIPT + + if (ref($settings) ne 'HASH') { + return &Apache::lonhtmlcommon::scripttag($intauthjs); + } if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) { my $maxnum = scalar(@{$settings->{'inststatusorder'}}); if ($maxnum eq '') { @@ -5350,10 +6772,14 @@ $jstext return; } +$intauthjs + // ]]> ENDSCRIPT + } else { + return &Apache::lonhtmlcommon::scripttag($intauthjs); } } @@ -5381,7 +6807,10 @@ sub coursecategories_javascript { } my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"'); my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"'); - my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.'); + my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); + &js_escape(\$instcode_reserved); + &js_escape(\$communities_reserved); + &js_escape(\$choose_again); $output = <<"ENDSCRIPT";