Diff for /loncom/interface/domainprefs.pm between versions 1.304 and 1.305

version 1.304, 2017/07/27 13:42:35 version 1.305, 2017/08/03 16:22:08
Line 281  sub handler { Line 281  sub handler {
                                  {col1 => 'Internal Authentication',                                   {col1 => 'Internal Authentication',
                                   col2 => 'Value'},                                    col2 => 'Value'},
                                  {col1 => 'Institutional user types',                                   {col1 => 'Institutional user types',
                                   col2 => 'Assignable to non-institutional users'}],                                    col2 => 'Name displayed'}],
                       print => \&print_defaults,                        print => \&print_defaults,
                       modify => \&modify_defaults,                        modify => \&modify_defaults,
                     },                      },
Line 598  $javascript_validations Line 598  $javascript_validations
 $coursebrowserjs  $coursebrowserjs
 END  END
         }          }
           if (grep(/^selfcreation$/,@actions)) {
               $js .= &selfcreate_javascript();
           }
         if (grep(/^contacts$/,@actions)) {          if (grep(/^contacts$/,@actions)) {
             $js .= &contacts_javascript();              $js .= &contacts_javascript();
         }          }
Line 694  sub process_changes { Line 697  sub process_changes {
     } elsif ($action eq 'usercreation') {      } elsif ($action eq 'usercreation') {
         $output = &modify_usercreation($dom,%domconfig);          $output = &modify_usercreation($dom,%domconfig);
     } elsif ($action eq 'selfcreation') {      } elsif ($action eq 'selfcreation') {
         $output = &modify_selfcreation($dom,%domconfig);          $output = &modify_selfcreation($dom,$lastactref,%domconfig);
     } elsif ($action eq 'usermodification') {      } elsif ($action eq 'usermodification') {
         $output = &modify_usermodification($dom,%domconfig);          $output = &modify_usermodification($dom,%domconfig);
     } elsif ($action eq 'contacts') {      } elsif ($action eq 'contacts') {
Line 2279  sub print_quotas { Line 2282  sub print_quotas {
 }  }
   
 sub print_requestmail {  sub print_requestmail {
     my ($dom,$action,$settings,$rowtotal) = @_;      my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
     my ($now,$datatable,%currapp);      my ($now,$datatable,%currapp);
     $now = time;      $now = time;
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
Line 2291  sub print_requestmail { Line 2294  sub print_requestmail {
     }      }
     my $numinrow = 2;      my $numinrow = 2;
     my $css_class;      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;      my $text;
     if ($action eq 'requestcourses') {      if ($action eq 'requestcourses') {
         $text = &mt('Receive notification of course requests requiring approval');          $text = &mt('Receive notification of course requests requiring approval');
Line 2764  sub print_autoupdate { Line 2779  sub print_autoupdate {
         my $locknamesettings;          my $locknamesettings;
         $datatable .= &insttypes_row($settings,$types,$usertypes,          $datatable .= &insttypes_row($settings,$types,$usertypes,
                                      $dom,$numinrow,$othertitle,                                       $dom,$numinrow,$othertitle,
                                     'lockablenames');                                      'lockablenames',$rowtotal);
         $$rowtotal ++;          $$rowtotal ++;
     } else {      } else {
         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);          my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
Line 2907  sub print_directorysrch { Line 2922  sub print_directorysrch {
         if (ref($usertypes) eq 'HASH') {          if (ref($usertypes) eq 'HASH') {
             if (keys(%{$usertypes}) > 0) {              if (keys(%{$usertypes}) > 0) {
                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,                  $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                                              $numinrow,$othertitle,'cansearch');                                               $numinrow,$othertitle,'cansearch',
                                                $rowtotal);
                 $cansrchrow = 1;                  $cansrchrow = 1;
             }              }
         }          }
Line 5752  sub print_usercreation { Line 5768  sub print_usercreation {
   
 sub print_selfcreation {  sub print_selfcreation {
     my ($position,$dom,$settings,$rowtotal) = @_;      my ($position,$dom,$settings,$rowtotal) = @_;
     my (@selfcreate,$createsettings,$processing,$emailverified,$emaildomain,$datatable);      my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
           $emaildomain,$datatable);
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
         if (ref($settings->{'cancreate'}) eq 'HASH') {          if (ref($settings->{'cancreate'}) eq 'HASH') {
             $createsettings = $settings->{'cancreate'};              $createsettings = $settings->{'cancreate'};
Line 5769  sub print_selfcreation { Line 5786  sub print_selfcreation {
                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {                  if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                     $processing = $createsettings->{'selfcreateprocessing'};                      $processing = $createsettings->{'selfcreateprocessing'};
                 }                  }
                   if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
                       $emailoptions = $createsettings->{'emailoptions'};
                   }
                 if (ref($createsettings->{'emailverified'}) eq 'HASH') {                  if (ref($createsettings->{'emailverified'}) eq 'HASH') {
                     $emailverified = $createsettings->{'emailverified'};                      $emailverified = $createsettings->{'emailverified'};
                 }                  }
Line 5801  sub print_selfcreation { Line 5821  sub print_selfcreation {
             if (keys(%{$usertypes}) > 0) {              if (keys(%{$usertypes}) > 0) {
                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,                  $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                                              $dom,$numinrow,$othertitle,                                               $dom,$numinrow,$othertitle,
                                              'statustocreate',$$rowtotal);                                               'statustocreate',$rowtotal);
                 $$rowtotal ++;                  $$rowtotal ++;
             }              }
         }          }
Line 5865  sub print_selfcreation { Line 5885  sub print_selfcreation {
         }          }
     } else {      } else {
         my %choices = &Apache::lonlocal::texthash (          my %choices = &Apache::lonlocal::texthash (
                                                       cancreate_email => 'Non-institutional username (e-mail verification)',                            'cancreate_email' => 'Non-institutional username (via e-mail verification)',
                                                   );                                                    );
         my @toggles = sort(keys(%choices));          my @toggles = sort(keys(%choices));
         my %defaultchecked = (          my %defaultchecked = (
                                'cancreate_email' => 'off',                                 '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 $display = 'none';
           my $rowstyle = 'display:none';
         if (grep(/^\Qemail\E$/,@selfcreate)) {          if (grep(/^\Qemail\E$/,@selfcreate)) {
             $display = 'block';              $display = 'block';
               $rowstyle = 'display:table-row';
         }          }
         my $onclick = "toggleDisplay(this.form,'emailoptions');";          my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
         my $additional = '<div id="emailoptions" style="display: '.$display.'">';          ($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 %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
         my $order;          my ($emailrules,$emailruleorder) =
         if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {              &Apache::lonnet::inst_userrules($dom,'email');
             $order = $domdefaults{'inststatusguest'};          my $primary_id = &Apache::lonnet::domain($dom,'primary');
         }          my $intdom = &Apache::lonnet::internet_dom($primary_id);
         my (@ordered,%usertypeshash);          if (ref($types) eq 'ARRAY') {
         if (ref($order) eq 'ARRAY') {              @posstypes = @{$types};
             @ordered = @{$order};          }
         }          if (@posstypes) {
         if (@ordered) {              unless (grep(/^default$/,@posstypes)) {
             unless (grep(/^default$/,@ordered)) {                  push(@posstypes,'default');
                 push(@ordered,'default');  
             }              }
             if (ref($usertypes) eq 'HASH') {              if (ref($usertypes) eq 'HASH') {
                 %usertypeshash = %{$usertypes};                  %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;              $usertypeshash{'default'} = $othertitle;
             $additional .= '<table><tr>';              foreach my $status (@posstypes) {
             foreach my $status (@ordered) {                  my $css_class;
                 $additional .= '<th align="center">'.$usertypeshash{$status}.'</th>';                  if ($$rowtotal%2) {
             }                      $css_class = 'LC_odd_row ';
             $additional .= '</tr><tr>';                  }
             foreach my $status (@ordered) {                  $css_class .= $customclass;
                 $additional .= '<td align="left" valign="top">'.&validate_by_email($rowtotal,$processing,$status).'</td>';                  my $rowid = $optionsprefix.$status;
             }                  my $hidden = 1;
             $additional .= '</tr></table><br />'.                  my $currstyle = 'display:none';
                            '<table><tr>';                  if (grep(/^\Q$status\E$/,@ordered)) {
             foreach my $status (@ordered) {                      $currstyle = $rowstyle;
                 $additional .= '<th align="center">'.$usertypeshash{$status}.'</th>';                      $hidden = 0; 
             }                  }
             $additional .= '</tr><tr>';                  $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
             foreach my $status (@ordered) {                                               $emailrules,$emailruleorder,$settings,$status,$rowid,
                 $additional .= '<td align="left" valign="top">'.&email_as_username($rowtotal,$emailverified,$emaildomain,$status).'</td>';                                               $usertypeshash{$status},$css_class,$currstyle,$intdom);
                   unless ($hidden) {
                       $$rowtotal ++;
                   }
             }              }
             $additional .= '</tr></table>';  
     
         } else {          } else {
               my $css_class;
               if ($$rowtotal%2) {
                   $css_class = 'LC_odd_row ';
               }
               $css_class .= $customclass;
             $usertypeshash{'default'} = $othertitle;              $usertypeshash{'default'} = $othertitle;
             $additional .= &mt('Approval:').' '.&validate_by_email($rowtotal,$processing).'<br />'.              $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                            &mt('Username:').' '.&email_as_username($rowtotal,$emailverified,$emaildomain);                                           $emailrules,$emailruleorder,$settings,'default','',
                                            $othertitle,$css_class,$rowstyle,$intdom);
               $$rowtotal ++;
         }          }
         $additional .= '</div>'."\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();          my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
         $numinrow = 1;          $numinrow = 1;
         foreach my $status (@ordered) {          if (@posstypes) {
             $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,              foreach my $status (@posstypes) {
                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,$infotitles);                  my $rowid = $classprefix.$status;
             $$rowtotal ++;                  my $datarowstyle = 'display:none';
         }                  if (grep(/^\Q$status\E$/,@ordered)) { 
         my ($emailrules,$emailruleorder) =                      $datarowstyle = $rowstyle; 
             &Apache::lonnet::inst_userrules($dom,'email');                  }
         if (ref($emailrules) eq 'HASH') {                  $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
             if (keys(%{$emailrules}) > 0) {                                                         $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                 $datatable .= &user_formats_row('email',$settings,$emailrules,                                                         $infotitles,$rowid,$customclass,$datarowstyle);
                                                 $emailruleorder,$numinrow,$$rowtotal);                  unless ($datarowstyle eq 'display:none') {
                 $$rowtotal ++;                      $$rowtotal ++;
                   }
             }              }
           } else {
               $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
                                                      $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                                                      $infotitles,'',$customclass,$rowstyle);
         }          }
         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);  
     }      }
     return $datatable;      return $datatable;
 }  }
   
 sub validate_by_email {  sub selfcreate_javascript {
     my ($rowtotal,$processing,$type) = @_;      return <<"ENDSCRIPT";
     my %choices =  
         &Apache::lonlocal::texthash (  <script type="text/javascript">
                                       automatic => 'Automatic approval',  // <![CDATA[
                                       approval  => 'Queued for approval',  
                                       notinuse  => 'Unavailable',  function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
                                     );      var x = document.getElementsByClassName(target);
     my $output;      var insttypes = 0;
     my @options = ('automatic','approval');      var insttypeRegExp = new RegExp(prefix);
     unless ($type eq '') {      if ((x.length != undefined) && (x.length > 0)) {
         push(@options,'notinuse');          if (form.elements[radio].length != undefined) {
     }              for (var i=0; i<form.elements[radio].length; i++) {
     foreach my $option (@options) {                  if (form.elements[radio][i].checked) {
         my $checked;                      if (form.elements[radio][i].value == 1) {
         if (ref($processing) eq 'HASH') {                          for (var j=0; j<x.length; j++) {
             if ($type eq '') {                                 if (x[j].id == 'undefined') {
                 if (!exists($processing->{'default'})) {                                  x[j].style.display = 'table-row';
                     if ($option eq 'automatic') {                              } else if (insttypeRegExp.test(x[j].id)) {
                         $checked = ' checked="checked"';                                  insttypes ++;
                     }                              } else {
                 } else {                                  x[j].style.display = 'table-row';
                     if ($processing->{'default'} eq $option) {                              }
                         $checked = ' checked="checked"';                          }
                       } else {
                           for (var j=0; j<x.length; j++) {
                               x[j].style.display = 'none';
                           }
                     }                      }
                       break;
                 }                  }
             } else {              }
                 if (!exists($processing->{$type})) {              if (insttypes > 0) {
                     if ($option eq 'automatic') {                  toggleDataRow(form,checkbox,target,altprefix);
                         $checked = ' checked="checked"';                  toggleDataRow(form,checkbox,target,prefix,1);
               }
           }
       }
       return;
   }
   
   function toggleDataRow(form,checkbox,target,prefix,docount) {
       if (form.elements[checkbox].length != undefined) {
           var count = 0;
           if (docount) {
               for (var i=0; i<form.elements[checkbox].length; i++) {
                   if (form.elements[checkbox][i].checked) {
                       count ++;
                   }
               }
           }
           for (var i=0; i<form.elements[checkbox].length; i++) {
               var type = form.elements[checkbox][i].value;
               if (document.getElementById(prefix+type)) {
                   if (form.elements[checkbox][i].checked) {
                       document.getElementById(prefix+type).style.display = 'table-row';
                       if (count % 2 == 1) {
                           document.getElementById(prefix+type).className = target+' LC_odd_row';
                       } else {
                           document.getElementById(prefix+type).className = target;
                     }                      }
                       count ++;
                 } else {                  } else {
                     if ($processing->{$type} eq $option) {                      document.getElementById(prefix+type).style.display = 'none';
                         $checked = ' checked="checked"';  
                     }  
                 }                  }
             }              }
         } elsif ($option eq 'automatic') {  
             $checked = ' checked="checked"';   
         }  
         my $name = 'cancreate_emailprocess';  
         if (($type ne '') && ($type ne 'default')) {  
             $name .= '_'.$type;  
         }  
         $output .= '<span class="LC_nobreak"><label>'.  
                    '<input type="radio" name="'.$name.'"'.  
                    $checked.' value="'.$option.'" />'.  
                    $choices{$option}.'</label></span>';  
         if ($type eq '') {  
             $output .= '&nbsp;';  
         } else {  
             $output .= '<br />';  
         }          }
     }      }
     $$rowtotal ++;      return;
     return $output;  
 }  }
   
 sub email_as_username {  function toggleEmailOptions(form,radio,prefix,altprefix,status) {
     my ($rowtotal,$emailverified,$emaildomain,$type) = @_;      var caller = radio+'_'+status;
     my %choices =      if (form.elements[caller].length != undefined) {
         &Apache::lonlocal::texthash (          for (var i=0; i<form.elements[caller].length; i++) {
                                       email => 'Username is e-mail',              if (form.elements[caller][i].checked) {
                                       other => 'Username is chosen',                  if (document.getElementById(altprefix+'_inst_'+status)) {
                                     );                      var curr = form.elements[caller][i].value;
     my $name = 'cancreate_emailverified';                      if (prefix) {
     my $condition = 'cancreate_emaildomain';                          document.getElementById(prefix+'_'+status).style.display = 'none';
     if (($type ne '') && ($type ne 'default')) {                      }
         $name .= '_'.$type;                      document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
         $condition .= '_'.$type;                      document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
                       if (curr == 'custom') {
                           if (prefix) { 
                               document.getElementById(prefix+'_'+status).style.display = 'inline';
                           }
                       } else if (curr == 'inst') {
                           document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
                       } else if (curr == 'noninst') {
                           document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
                       }
                       break;
                   }
               }
           }
     }      }
     my $display = 'none';  }
     my $onclick = "toggleDisplay(this.form,'$name');";  
   
     my $output;  // ]]>
     foreach my $option ('email','other') {  </script>
         my ($checked,$domain);  
         if (ref($emailverified) eq 'HASH') {  ENDSCRIPT
             if ($type eq '') {  }
                 if (!exists($emailverified->{'default'})) {  
                     if ($option eq 'email') {  sub noninst_users {
                         $checked = ' checked="checked"';      my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
                     }          $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_; 
                 } else {      my $class = 'LC_left_item';
                     if ($emailverified->{'default'} eq $option) {      if ($css_class) {
                         $checked = ' checked="checked"';          $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 = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                 "<td>$description</td>\n".           
                 '<td class="'.$class.'" colspan="2">'.
                 '<table><tr>';
       my %headers = &Apache::lonlocal::texthash( 
                 approve  => 'Processing',
                 email    => 'E-mail',
                 username => 'Username',
       );
       foreach my $item ('approve','email','username') {
           $output .= '<th>'.$headers{$item}.'</th>';
       }
       $output .= '</tr><tr>';
       foreach my $item ('approve','email','username') {
           $output .= '<td valign="top">';
           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 ++;
                                       }
                                   }
                               }
                           }
                     }                      }
                 }                  }
             } else {              }
                 if (!exists($emailverified->{$type})) {              $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
                     if ($option eq 'email') {                                                       "'cancreate_emaildomain','$type'".');"';
                         $checked = ' checked="checked"';              $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 {                  } else {
                     if ($emailverified->{$type} eq $option) {                      if (!exists($hashref->{$type})) {
                         $checked = ' checked="checked"';                          if ($option eq $defoption) {
                         if ($option eq 'other') {                              $checked = ' checked="checked"';
                             $display = 'inline';                          }
                       } 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"';
             }              }
         } elsif ($option eq 'email') {              $output .= '<span class="LC_nobreak"><label>'.
             $checked = ' checked="checked"';                         '<input type="radio" name="'.$name.'"'.
         }                         $checked.' value="'.$option.'"'.$onclick.' />'.
         $output .= '<span class="LC_nobreak"><label>'.                         $choices{$option}.'</label></span><br />';
                    '<input type="radio" name="'.$name.'"'.              if ($item eq 'email') {
                    $checked.' value="'.$option.'" onclick="'.$onclick.'" />'.                  if ($option eq 'custom') {
                    $choices{$option}.'</label></span>';                      my $id = 'cancreate_emailrule_'.$type;
         if ($type eq '') {                      my $display = 'none';
             $output .= '&nbsp;';                      if ($checked) {
         } else {                          $display = 'inline';
             $output .= '<br />';                      }
         }                      my $numinrow = 2;
     }                      $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
     my $domain;                                 '<legend>'.&mt('Disallow').'</legend><table>'.
     if (ref($emaildomain) eq 'HASH') {                                 &user_formats_row('email',$settings,$emailrules,
         if ($type eq '') {                                                   $emailruleorder,$numinrow,'',$type);
             if (exists($emaildomain->{'default'})) {                                '</table></fieldset>';
                 $domain = $emaildomain->{'default'};                  } elsif (($option eq 'inst') || ($option eq 'noninst')) {
             }                      my %text = &Apache::lonlocal::texthash (
         } else {                                                               inst    => 'must end:',
             if (exists($emaildomain->{$type})) {                                                               noninst => 'cannot end:',
                 $domain = $emaildomain->{$type};                                                             );
                       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 .= '<div id="'.$condition.'" style="display:'.$display.';">'.
                                  '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
                                  '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
                                  '</div>';
                   }
             }              }
         }          }
           $output .= '</td>'."\n";
     }      }
     $output .= '<div id="'.$name.'" style="display: '.$display.';">'.      $output .= "</tr></table></td></tr>\n";
                '<span class="LC_domprefs_email">'.&mt('E-mail domain').'</span> '.  
                '<input type="text" name="'.$condition.'" value="'.$domain.'" size="10" />'.  
                '</div>';  
     $$rowtotal ++;  
     return $output;      return $output;
 }  }
   
 sub captcha_choice {  sub captcha_choice {
     my ($context,$settings,$itemcount) = @_;      my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,      my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
         $vertext,$currver);          $vertext,$currver);
     my %lt = &captcha_phrases();      my %lt = &captcha_phrases();
Line 6116  sub captcha_choice { Line 6310  sub captcha_choice {
     } else {      } else {
         $checked{'original'} = ' checked="checked"';          $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 = '<tr'.$css_class.'>'.      my $output = '<tr'.$css_class.'>'.
                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".                   '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
                  '<table><tr><td>'."\n";                   '<table><tr><td>'."\n";
Line 6135  sub captcha_choice { Line 6342  sub captcha_choice {
 # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.  # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
 #  #
     $output .= '</td></tr>'."\n".      $output .= '</td></tr>'."\n".
                '<tr><td>'."\n".                 '<tr><td class="LC_zero_height">'."\n".
                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".                 '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.                 '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                $currpub.'" size="40" /></span><br />'."\n".                 $currpub.'" size="40" /></span><br />'."\n".
Line 6151  sub captcha_choice { Line 6358  sub captcha_choice {
 }  }
   
 sub user_formats_row {  sub user_formats_row {
     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;      my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
     my $output;      my $output;
     my %text = (      my %text = (
                    'username' => 'new usernames',                     'username' => 'new usernames',
                    'id'       => 'IDs',                     'id'       => 'IDs',
                    'email'    => 'self-created accounts (e-mail)',  
                );                 );
     my $css_class = $rowcount%2?' class="LC_odd_row"':'';      unless ($type eq 'email') {
     $output = '<tr '.$css_class.'>'.          my $css_class = $rowcount%2?' class="LC_odd_row"':'';
               '<td><span class="LC_nobreak">';          $output = '<tr '.$css_class.'>'.
     if ($type eq 'email') {                    '<td><span class="LC_nobreak">'.
         $output .= &mt("Formats disallowed for $text{$type}: ");                    &mt("Format rules to check for $text{$type}: ").
     } else {                    '</td><td class="LC_left_item" colspan="2"><table>';
         $output .= &mt("Format rules to check for $text{$type}: ");  
     }      }
     $output .= '</span></td>'.  
                '<td class="LC_left_item" colspan="2"><table>';  
     my $rem;      my $rem;
     if (ref($ruleorder) eq 'ARRAY') {      if (ref($ruleorder) eq 'ARRAY') {
         for (my $i=0; $i<@{$ruleorder}; $i++) {          for (my $i=0; $i<@{$ruleorder}; $i++) {
Line 6185  sub user_formats_row { Line 6388  sub user_formats_row {
                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {                          if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                             $check = ' checked="checked" ';                              $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 .= '<td class="LC_left_item">'.                  $output .= '<td class="LC_left_item">'.
                            '<span class="LC_nobreak"><label>'.                             '<span class="LC_nobreak"><label>'.
                            '<input type="checkbox" name="'.$type.'_rule" '.                             '<input type="checkbox" name="'.$name.'"'.
                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.                             'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';                             $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
             }              }
         }          }
         $rem = @{$ruleorder}%($numinrow);          $rem = @{$ruleorder}%($numinrow);
     }      }
     my $colsleft = $numinrow - $rem;      my $colsleft;
       if ($rem) {
           $colsleft = $numinrow - $rem;
       }
     if ($colsleft > 1 ) {      if ($colsleft > 1 ) {
         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.          $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                    '&nbsp;</td>';                     '&nbsp;</td>';
     } elsif ($colsleft == 1) {      } elsif ($colsleft == 1) {
         $output .= '<td class="LC_left_item">&nbsp;</td>';          $output .= '<td class="LC_left_item">&nbsp;</td>';
     }      }
     $output .= '</tr></table></td></tr>';      $output .= '</tr></table>';
       unless ($type eq 'email') {
           $output .= '</td></tr>';
       }
     return $output;      return $output;
 }  }
   
Line 6425  sub print_defaults { Line 6644  sub print_defaults {
     } else {      } else {
         my %defaults;          my %defaults;
         if (ref($settings) eq 'HASH') {          if (ref($settings) eq 'HASH') {
             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&              if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                 (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {  
                 my $maxnum = @{$settings->{'inststatusorder'}};                  my $maxnum = @{$settings->{'inststatusorder'}};
                 for (my $i=0; $i<$maxnum; $i++) {                  for (my $i=0; $i<$maxnum; $i++) {
                     $css_class = $rownum%2?' class="LC_odd_row"':'';                      $css_class = $rownum%2?' class="LC_odd_row"':'';
                     my $item = $settings->{'inststatusorder'}->[$i];                      my $item = $settings->{'inststatusorder'}->[$i];
                     my $title = $settings->{'inststatustypes'}->{$item};                      my $title = $settings->{'inststatustypes'}->{$item};
                     my $guestok;  
                     if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {  
                         $guestok = 1;  
                     }  
                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';                      my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                     $datatable .= '<tr'.$css_class.'>'.                      $datatable .= '<tr'.$css_class.'>'.
                                   '<td><span class="LC_nobreak">'.                                    '<td><span class="LC_nobreak">'.
Line 6448  sub print_defaults { Line 6662  sub print_defaults {
                         }                          }
                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';                          $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                     }                      }
                     my ($checkedon,$checkedoff);  
                     $checkedoff = ' checked="checked"';  
                     if ($guestok) {  
                         $checkedon = $checkedoff;  
                         $checkedoff = '';   
                     }  
                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.                      $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.                                    '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                                   &mt('delete').'</span></td>'.                                    &mt('delete').'</span></td>'.
                                   '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').                                    '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.                                    '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                                   '</span></td>'.                                    '</span></td></tr>';
                                   '<td class="LC_right_item"><span class="LC_nobreak">'.  
                                   '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.  
                                   &mt('Yes').'</label>'.('&nbsp;'x2).  
                                   '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.  
                                   &mt('No').'</label></span></td></tr>';  
                 }                  }
                 $css_class = $rownum%2?' class="LC_odd_row"':'';                  $css_class = $rownum%2?' class="LC_odd_row"':'';
                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';                  my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
Line 6481  sub print_defaults { Line 6684  sub print_defaults {
                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').                  $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
                               '<input type="text" size="10" name="addinststatus" value="" />'.                                '<input type="text" size="10" name="addinststatus" value="" />'.
                               '&nbsp;'.&mt('(new)').                                '&nbsp;'.&mt('(new)').
                               '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.                                '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
                               &mt('Name displayed:').                                &mt('Name displayed:').
                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.                                '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                               '<td class="LC_right_item"><span class="LC_nobreak">'.  
                               '<label><input type="radio" value="1" name="addinststatus_guest" />'.  
                               &mt('Yes').'</label>'.('&nbsp;'x2).  
                               '<label><input type="radio" value="0" name="addinststatus_guest" />'.  
                               &mt('No').'</label></span></td></tr>';  
                               '</tr>'."\n";                                '</tr>'."\n";
                 $rownum ++;                  $rownum ++;
             }              }
Line 7386  sub build_category_rows { Line 7584  sub build_category_rows {
 }  }
   
 sub modifiable_userdata_row {  sub modifiable_userdata_row {
     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;      my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
           $rowid,$customcss,$rowstyle) = @_;
     my ($role,$rolename,$statustype);      my ($role,$rolename,$statustype);
     $role = $item;      $role = $item;
     if ($context eq 'cancreate') {      if ($context eq 'cancreate') {
         if ($item =~ /^emailusername_(.+)$/) {          if ($item =~ /^(emailusername)_(.+)$/) {
             $statustype = $1;              $role = $1;
             $role = 'emailusername';              $statustype = $2;
             if (ref($usertypes) eq 'HASH') {              if (ref($usertypes) eq 'HASH') {
                 if ($usertypes->{$statustype}) {                  if ($usertypes->{$statustype}) {
                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});                      $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
Line 7427  sub modifiable_userdata_row { Line 7626  sub modifiable_userdata_row {
         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();          %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
     }      }
     my $output;      my $output;
     my $css_class = $rowcount%2?' class="LC_odd_row"':'';      my $css_class;
     $output = '<tr '.$css_class.'>'.      if ($rowcount%2) {
           $css_class = 'LC_odd_row';
       }
       if ($customcss) {
           $css_class .= " $customcss";
       }
       $css_class =~ s/^\s+//;
       if ($css_class) {
           $css_class = ' class="'.$css_class.'"';
       }
       if ($rowstyle) {
           $css_class .= ' style="'.$rowstyle.'"';
       }
       if ($rowid) {
           $rowid = ' id="'.$rowid.'"';
       }
       
       $output = '<tr '.$css_class.$rowid.'>'.
               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.                '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
               '<td class="LC_left_item" colspan="2"><table>';                '<td class="LC_left_item" colspan="2"><table>';
     my $rem;      my $rem;
Line 7462  sub modifiable_userdata_row { Line 7678  sub modifiable_userdata_row {
             }              }
         }          }
     }      }
         
     for (my $i=0; $i<@fields; $i++) {      my $total = scalar(@fields);
         my $rem = $i%($numinrow);      for (my $i=0; $i<$total; $i++) {
           $rem = $i%($numinrow);
         if ($rem == 0) {          if ($rem == 0) {
             if ($i > 0) {              if ($i > 0) {
                 $output .= '</tr>';                  $output .= '</tr>';
Line 7506  sub modifiable_userdata_row { Line 7723  sub modifiable_userdata_row {
                        '</label>';                         '</label>';
         }          }
         $output .= '</span></td>';          $output .= '</span></td>';
         $rem = @fields%($numinrow);  
     }      }
     my $colsleft = $numinrow - $rem;      $rem = $total%$numinrow;
     if ($colsleft > 1 ) {      my $colsleft;
       if ($rem) {
           $colsleft = $numinrow - $rem;
       }
       if ($colsleft > 1) {
         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.          $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                    '&nbsp;</td>';                     '&nbsp;</td>';
     } elsif ($colsleft == 1) {      } elsif ($colsleft == 1) {
Line 7520  sub modifiable_userdata_row { Line 7740  sub modifiable_userdata_row {
 }  }
   
 sub insttypes_row {  sub insttypes_row {
     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;      my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
           $customcss,$rowstyle) = @_;
     my %lt = &Apache::lonlocal::texthash (      my %lt = &Apache::lonlocal::texthash (
                       cansearch => 'Users allowed to search',                        cansearch => 'Users allowed to search',
                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',                        statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
                       lockablenames => 'User preference to lock name',                        lockablenames => 'User preference to lock name',
                         selfassign    => 'Self-reportable affiliations',
              );               );
     my $showdom;      my $showdom;
     if ($context eq 'cansearch') {      if ($context eq 'cansearch') {
Line 7534  sub insttypes_row { Line 7756  sub insttypes_row {
     if ($context eq 'statustocreate') {      if ($context eq 'statustocreate') {
         $class = 'LC_right_item';          $class = 'LC_right_item';
     }      }
     my $css_class = ' class="LC_odd_row"';      my $css_class;
     if ($rownum ne '') {       if ($$rowtotal%2) {
         $css_class = ($rownum%2? ' class="LC_odd_row"':'');          $css_class = 'LC_odd_row';
       }
       if ($customcss) {
           $css_class .= ' '.$customcss;
       }
       $css_class =~ s/^\s+//;
       if ($css_class) {
           $css_class = ' class="'.$css_class.'"';
       }
       if ($rowstyle) {
           $css_class .= ' style="'.$rowstyle.'"';
       }
       if ($onclick) {
           $onclick = 'onclick="'.$onclick.'" ';
     }      }
     my $output = '<tr'.$css_class.'>'.      my $output = '<tr'.$css_class.'>'.
                  '<td>'.$lt{$context}.$showdom.                   '<td>'.$lt{$context}.$showdom.
Line 7565  sub insttypes_row { Line 7800  sub insttypes_row {
                 $output .= '<td class="LC_left_item">'.                  $output .= '<td class="LC_left_item">'.
                            '<span class="LC_nobreak"><label>'.                             '<span class="LC_nobreak"><label>'.
                            '<input type="checkbox" name="'.$context.'" '.                             '<input type="checkbox" name="'.$context.'" '.
                            'value="'.$types->[$i].'"'.$check.'/>'.                             'value="'.$types->[$i].'"'.$check.$onclick.' />'.
                            $usertypes->{$types->[$i]}.'</label></span></td>';                             $usertypes->{$types->[$i]}.'</label></span></td>';
             }              }
         }          }
Line 7592  sub insttypes_row { Line 7827  sub insttypes_row {
     }      }
     $output .= '<span class="LC_nobreak"><label>'.      $output .= '<span class="LC_nobreak"><label>'.
                '<input type="checkbox" name="'.$context.'" '.                 '<input type="checkbox" name="'.$context.'" '.
                'value="default"'.$defcheck.'/>'.                 'value="default"'.$defcheck.$onclick.' />'.
                $othertitle.'</label></span></td>'.                 $othertitle.'</label></span></td>'.
                '</tr></table></td></tr>';                 '</tr></table></td></tr>';
     return $output;      return $output;
Line 11264  sub modify_usercreation { Line 11499  sub modify_usercreation {
 }  }
   
 sub modify_selfcreation {  sub modify_selfcreation {
     my ($dom,%domconfig) = @_;      my ($dom,$lastactref,%domconfig) = @_;
     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);      my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
     my (%save_usercreate,%save_usermodify,@types,%usertypes);      my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
       my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
     my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);      my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
     if (ref($typesref) eq 'ARRAY') {      if (ref($typesref) eq 'ARRAY') {
         @types = @{$typesref};          @types = @{$typesref};
     }      }
     unless (grep(/^default$/,@types)) {  
         push(@types,'default');  
     }  
     if (ref($usertypesref) eq 'HASH') {      if (ref($usertypesref) eq 'HASH') {
         %usertypes = %{$usertypesref};          %usertypes = %{$usertypesref};
     }      }
Line 11291  sub modify_selfcreation { Line 11524  sub modify_selfcreation {
                             ($item eq 'recaptchaversion') || ($item eq 'notify') ||                              ($item eq 'recaptchaversion') || ($item eq 'notify') ||
                             ($item eq 'emailusername') || ($item eq 'shibenv') ||                              ($item eq 'emailusername') || ($item eq 'shibenv') ||
                             ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||                              ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
                             ($item eq 'emaildomain')) {                              ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};                              $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                         } else {                          } else {
                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};                              $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
Line 11317  sub modify_selfcreation { Line 11550  sub modify_selfcreation {
             }              }
         }          }
     }      }
   #
   # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
   #
       if (ref($domconfig{'inststatus'}) eq 'HASH') {
           foreach my $key (keys(%{$domconfig{'inststatus'}})) {
               if ($key eq 'inststatusguest') {
                   $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
               } else {
                   $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
               }
           }
       }
   
     my @contexts = ('selfcreate');      my @contexts = ('selfcreate');
     @{$cancreate{'selfcreate'}} = ();      @{$cancreate{'selfcreate'}} = ();
     %{$cancreate{'emailusername'}} = ();      %{$cancreate{'emailusername'}} = ();
     @{$cancreate{'statustocreate'}} = ();      if (@types) {
           @{$cancreate{'statustocreate'}} = ();
       }
     %{$cancreate{'selfcreateprocessing'}} = ();      %{$cancreate{'selfcreateprocessing'}} = ();
     %{$cancreate{'shibenv'}} = ();      %{$cancreate{'shibenv'}} = ();
     %{$cancreate{'emailverified'}} = ();      %{$cancreate{'emailverified'}} = ();
       %{$cancreate{'emailoptions'}} = ();
     %{$cancreate{'emaildomain'}} = ();      %{$cancreate{'emaildomain'}} = ();
     my %selfcreatetypes = (      my %selfcreatetypes = (
                              sso   => 'users authenticated by institutional single sign on',                               sso   => 'users authenticated by institutional single sign on',
Line 11335  sub modify_selfcreation { Line 11583  sub modify_selfcreation {
 # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts  # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
 # is permitted.  # is permitted.
 #  #
       my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
   
     my @statuses;      my (@statuses,%email_rule);
     if (ref($domconfig{'inststatus'}) eq 'HASH') {  
         if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {  
             @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};  
         }  
     }  
     push(@statuses,'default');  
   
     foreach my $item ('login','sso','email') {      foreach my $item ('login','sso','email') {
         if ($item eq 'email') {          if ($item eq 'email') {
             if ($env{'form.cancreate_email'}) {              if ($env{'form.cancreate_email'}) {
                 push(@{$cancreate{'selfcreate'}},'email');                  if (@types) {
                 push(@contexts,('selfcreateprocessing','emailverified','emaildomain'));                      my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
                 foreach my $type (@statuses) {                      foreach my $status (@poss_statuses) {
                     if ($type eq 'default') {                          if (grep(/^\Q$status\E$/,(@types,'default'))) {
                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};                              push(@statuses,$status);
                         unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {                          }
                             $cancreate{'emailverified'}{$type} = $env{'form.cancreate_emailverified'};                      }
                             if ($cancreate{'emailverified'}{$type} eq 'other') {                      $save_inststatus{'inststatusguest'} = \@statuses;
                                 $cancreate{'emaildomain'}{$type} =$env{'form.cancreate_emaildomain'};                  } else {
                             }                      push(@statuses,'default');
                         }                  }
                     } else {                   if (@statuses) {
                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};                      my %curr_rule;
                         $cancreate{'emailverified'}{$type} = $env{'form.cancreate_emailverified_'.$type};                      if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                         if ($cancreate{'emailverified'}{$type} eq 'other') {                          foreach my $type (@statuses) {
                             $cancreate{'emaildomain'}{$type} =$env{'form.cancreate_emaildomain_'.$type};                              $curr_rule{$type} = $curr_usercreation{'email_rule'};
                         }                          }
                       } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
                           foreach my $type (@statuses) {
                               $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
                           }
                       }
                       push(@{$cancreate{'selfcreate'}},'email');
                       push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
                       my %curremaildom;
                       if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
                           %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
                       }
                       foreach my $type (@statuses) {
                           if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
                               $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                           }
                           if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
                               $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
                           }
                           if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
   #
   # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
   #
                               my $chosen = $1;
                               if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
                                   my $emaildom;
                                   if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
                                       $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type}; 
                                       $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
                                       if (ref($curremaildom{$type}) eq 'HASH') {
                                           if (exists($curremaildom{$type}{$chosen})) {
                                               if ($curremaildom{$type}{$chosen} ne $emaildom) {
                                                   push(@{$changes{'cancreate'}},'emaildomain');
                                               }
                                           } elsif ($emaildom ne '') {
                                               push(@{$changes{'cancreate'}},'emaildomain');
                                           }
                                       } elsif ($emaildom ne '') {
                                           push(@{$changes{'cancreate'}},'emaildomain');
                                       } 
                                   }
                                   $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                               } elsif ($chosen eq 'custom') {
                                   my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
                                   $email_rule{$type} = [];
                                   if (ref($emailrules) eq 'HASH') {
                                       foreach my $rule (@possemail_rules) {
                                           if (exists($emailrules->{$rule})) {
                                               push(@{$email_rule{$type}},$rule);
                                           }
                                       }
                                   }
                                   if (@{$email_rule{$type}}) {
                                       $cancreate{'emailoptions'}{$type} = 'custom';
                                       if (ref($curr_rule{$type}) eq 'ARRAY') {
                                           if (@{$curr_rule{$type}} > 0) {
                                               foreach my $rule (@{$curr_rule{$type}}) {
                                                   if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
                                                       push(@{$changes{'email_rule'}},$type);
                                                   }
                                               }
                                           }
                                           foreach my $type (@{$email_rule{$type}}) {
                                               if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
                                                   push(@{$changes{'email_rule'}},$type);
                                               }
                                           }
                                       } else {
                                           push(@{$changes{'email_rule'}},$type);
                                       }
                                   }
                               } else {
                                   $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                               }
                           }
                       }
                       if (@types) {
                           if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                               my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
                               if (@changed) {
                                   push(@{$changes{'inststatus'}},'inststatusguest');
                               }
                           } else {
                               push(@{$changes{'inststatus'}},'inststatusguest');
                           }
                       }
                   } else {
                       delete($env{'form.cancreate_email'});
                       if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                           if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                               push(@{$changes{'inststatus'}},'inststatusguest');
                           }
                       }
                   }
               } else {
                   $save_inststatus{'inststatusguest'} = [];
                   if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                       if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                           push(@{$changes{'inststatus'}},'inststatusguest');
                     }                      }
                 }                  }
             }              }
Line 11373  sub modify_selfcreation { Line 11713  sub modify_selfcreation {
             }              }
         }          }
     }      }
     my (@email_rule,%userinfo,%savecaptcha);      my (%userinfo,%savecaptcha);
     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();      my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
 #  #
 # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data  # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
Line 11382  sub modify_selfcreation { Line 11722  sub modify_selfcreation {
   
     if ($env{'form.cancreate_email'}) {      if ($env{'form.cancreate_email'}) {
         push(@contexts,'emailusername');          push(@contexts,'emailusername');
         if (@types) {          if (@statuses) {
             foreach my $type (@types) {              foreach my $type (@statuses) {
                 if (ref($infofields) eq 'ARRAY') {                  if (ref($infofields) eq 'ARRAY') {
                     foreach my $field (@{$infofields}) {                      foreach my $field (@{$infofields}) {
                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {                          if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
Line 11415  sub modify_selfcreation { Line 11755  sub modify_selfcreation {
             push(@{$changes{'cancreate'}},'notify');              push(@{$changes{'cancreate'}},'notify');
         }          }
   
 #  
 # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.  
 #  
         @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');  
         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});          &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
         if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {  
             if (@{$curr_usercreation{'email_rule'}} > 0) {  
                 foreach my $type (@{$curr_usercreation{'email_rule'}}) {  
                     if (!grep(/^\Q$type\E$/,@email_rule)) {  
                         push(@{$changes{'email_rule'}},$type);  
                     }  
                 }  
             }  
             if (@email_rule > 0) {  
                 foreach my $type (@email_rule) {  
                     if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {  
                         push(@{$changes{'email_rule'}},$type);  
                     }  
                 }  
             }  
         } elsif (@email_rule > 0) {  
             push(@{$changes{'email_rule'}},@email_rule);  
         }  
     }      }
 #    #  
 # Check if domain default is set appropriately, if self-creation of accounts is to be available for  # Check if domain default is set appropriately, if self-creation of accounts is to be available for
 # institutional log-in.  # institutional log-in.
 #  #
     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {      if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);  
         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||           if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                ($domdefaults{'auth_def'} eq 'localauth'))) {                 ($domdefaults{'auth_def'} eq 'localauth'))) {
             $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.              $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.
Line 11464  sub modify_selfcreation { Line 11781  sub modify_selfcreation {
 #  #
     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {      if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
         if (@types) {          if (@types) {
             if (@types > 1) {              @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                 @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');              push(@contexts,'statustocreate');
                 push(@contexts,'statustocreate');  
             } else {  
                 undef($cancreate{'statustocreate'});  
             }   
             foreach my $type (@types) {              foreach my $type (@types) {
                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);                  my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                 foreach my $field (@fields) {                  foreach my $field (@fields) {
Line 11542  sub modify_selfcreation { Line 11855  sub modify_selfcreation {
             }              }
         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {          } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
             if (ref($cancreate{$item}) eq 'HASH') {              if (ref($cancreate{$item}) eq 'HASH') {
                 foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {                  foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
                     if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {                      if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {                          foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
                             unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {                              unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {                                  if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                     push(@{$changes{'cancreate'}},$item);                                      push(@{$changes{'cancreate'}},$item);
                                 }                                  }
                             }                              }
                         }                          }
                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emaildomain')) {                      } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                         if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {                          if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                                 push(@{$changes{'cancreate'}},$item);  
                             }  
                         }  
                     } else {  
                         if (!$cancreate{$item}{$curr}) {  
                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {                              if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                 push(@{$changes{'cancreate'}},$item);                                  push(@{$changes{'cancreate'}},$item);
                             }                              }
                         }                          }
                     }                      }
                 }                  }
                 foreach my $field (keys(%{$cancreate{$item}})) {                  foreach my $type (keys(%{$cancreate{$item}})) {
                     if (ref($cancreate{$item}{$field}) eq 'HASH') {                      if (ref($cancreate{$item}{$type}) eq 'HASH') {
                         foreach my $inner (keys(%{$cancreate{$item}{$field}})) {                          foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                             if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {                              if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                                 unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {                                  unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {                                      if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                         push(@{$changes{'cancreate'}},$item);                                          push(@{$changes{'cancreate'}},$item);
                                     }                                      }
Line 11580  sub modify_selfcreation { Line 11887  sub modify_selfcreation {
                                 }                                  }
                             }                              }
                         }                          }
                     } elsif ($item eq 'selfcreateprocessing') {                      } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                         if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {                          if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                                 push(@{$changes{'cancreate'}},$item);  
                             }  
                         }  
                     } else {  
                         if (!$curr_usercreation{'cancreate'}{$item}{$field}) {  
                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {                              if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                 push(@{$changes{'cancreate'}},$item);                                  push(@{$changes{'cancreate'}},$item);
                             }                              }
Line 11602  sub modify_selfcreation { Line 11903  sub modify_selfcreation {
                         push(@{$changes{'cancreate'}},$item);                          push(@{$changes{'cancreate'}},$item);
                     }                      }
                 }                  }
             } elsif (ref($cancreate{$item}) eq 'HASH') {              }
                 if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {          } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {              if (ref($cancreate{$item}) eq 'HASH') {
                         push(@{$changes{'cancreate'}},$item);                  if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                     }                      push(@{$changes{'cancreate'}},$item);
                 }                  }
             }              }
         } elsif ($item eq 'emailusername') {          } elsif ($item eq 'emailusername') {
Line 11642  sub modify_selfcreation { Line 11943  sub modify_selfcreation {
     if (ref($cancreate{'emailverified'}) eq 'HASH') {      if (ref($cancreate{'emailverified'}) eq 'HASH') {
         $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};          $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
     }      }
       if (ref($cancreate{'emailoptions'}) eq 'HASH') {
           $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
       }
     if (ref($cancreate{'emaildomain'}) eq 'HASH') {      if (ref($cancreate{'emaildomain'}) eq 'HASH') {
         $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};          $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
     }      }
Line 11652  sub modify_selfcreation { Line 11956  sub modify_selfcreation {
         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};          $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
     }      }
     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};      $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
     $save_usercreate{'emailrule'} = \@email_rule;      $save_usercreate{'email_rule'} = \%email_rule;
   
     my %userconfig_hash = (      my %userconfig_hash = (
             usercreation     => \%save_usercreate,              usercreation     => \%save_usercreate,
             usermodification => \%save_usermodify,              usermodification => \%save_usermodify,
               inststatus       => \%save_inststatus,
     );      );
   
     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,      my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                                              $dom);                                               $dom);
 #  #
 # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext  # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
 #  #
     if ($putresult eq 'ok') {      if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {          if (keys(%changes) > 0) {
Line 11691  sub modify_selfcreation { Line 11997  sub modify_selfcreation {
                                     }                                      }
                                 }                                  }
                                 if (grep(/^email$/,@{$cancreate{$type}})) {                                  if (grep(/^email$/,@{$cancreate{$type}})) {
                                     if (@statuses > 1) {                                      if (!@statuses) {
                                         my $numtypes = 0;                                          $chgtext .= '<span class="LC_warning">'.
                                         foreach my $type (@statuses) {                                                      &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").
                                             unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {                                                      '</span><br />';
                                                 $numtypes ++;  
                                             }  
                                         }  
                                         if (!$numtypes) {  
                                             $chgtext .= '<span class="LC_warning">'.  
                                                         &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").  
                                                         '</span><br />';  
   
                                         }  
                                     }                                      }
                                 }                                  }
                             }                              }
Line 11770  sub modify_selfcreation { Line 12068  sub modify_selfcreation {
                         my %choices = &Apache::lonlocal::texthash (                          my %choices = &Apache::lonlocal::texthash (
                                                                     automatic => 'Automatic approval',                                                                      automatic => 'Automatic approval',
                                                                     approval  => 'Queued for approval',                                                                      approval  => 'Queued for approval',
                                                                     notinuse  => 'Unavailable',  
                                                                   );                                                                    );
                         if (@statuses > 1) {                          if (@types) {
                             my $numtypes = 0;                              if (@statuses) {
                             foreach my $type (@statuses) {  
                                 unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {  
                                     $numtypes ++;  
                                 }  
                             }  
                             if ($numtypes) {  
                                 $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').                                   $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:'). 
                                             '<ul>';                                                  '<ul>';
                                 foreach my $type (@statuses) {                                  foreach my $status (@statuses) {
                                     if ($type eq 'default') {                                      if ($status eq 'default') {
                                         $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';                                          $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
                                     } else {                                      } else {
                                         $chgtext .= '<li>'.$usertypes{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';                                          $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
                                     }                                      }
                                 }                                  }
                                 $chgtext .= '</ul>';                                  $chgtext .= '</ul>';
Line 11797  sub modify_selfcreation { Line 12088  sub modify_selfcreation {
                         }                          }
                     } elsif ($type eq 'emailverified') {                      } elsif ($type eq 'emailverified') {
                         my %options = &Apache::lonlocal::texthash (                          my %options = &Apache::lonlocal::texthash (
                                                                     email => 'Username is e-mail',                                                                      all   => 'Same as e-mail',
                                                                     other => 'Username is chosen',                                                                      first => 'Omit @domain',
                                                                       free  => 'Free to choose',
                                                                   );                                                                    );
                         if (@statuses > 1) {                          if (@types) {
                             my $numtypes = 0;                              if (@statuses) {
                             foreach my $type (@statuses) {  
                                 unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {  
                                     $numtypes ++;  
                                 }  
                             }  
                             if ($numtypes) {  
                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').                                  $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                                             '<ul>';                                              '<ul>';
                                 foreach my $type (@statuses) {                                  foreach my $status (@statuses) {
                                     next if ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse');   
                                     if ($type eq 'default') {                                      if ($type eq 'default') {
                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$type}}.'</li>';                                          $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
                                     } else {                                      } else {
                                         $chgtext .= '<li>'.$usertypes{$type}.' -- '.$options{$cancreate{'emailverified'}{$type}}.'</li>';                                          $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
                                     }                                      }
                                 }                                  }
                                 $chgtext .= '</ul>';                                  $chgtext .= '</ul>';
                             }                              }
                         } else {                          } else {
                             $chgtext .= &mt('For self-created accounts verified by e-mail address: "[_1]"',                              $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
                                             $options{$cancreate{'emailverified'}{'default'}});                                              $options{$cancreate{'emailverified'}{'default'}});
                         }                          }
                     } elsif ($type eq 'emaildomain') {                      } elsif ($type eq 'emailoptions') {
                         if (@statuses > 1) {                          my %options = &Apache::lonlocal::texthash (
                             my $numtypes = 0;                                                                      any     => 'Any e-mail',
                             foreach my $type (@statuses) {                                                                      inst    => 'Institutional only',
                                 unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {                                                                      noninst => 'Non-institutional only',
                                     if ($cancreate{'emailverified'}{$type} eq 'other') {                                                                      custom  => 'Custom restrictions',
                                         $numtypes ++;                                                                    );
                                     }                          if (@types) {
                                 }                              if (@statuses) {
                             }                                  $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
                             if ($numtypes) {                       
                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, with username chosen by user ...').  
                                             '<ul>';                                              '<ul>';
                                 foreach my $type (@statuses) {                                  foreach my $status (@statuses) {
                                     next if (($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') ||  
                                              ($cancreate{'emailverified'}{$type} eq 'email'));  
                                     if ($type eq 'default') {                                      if ($type eq 'default') {
                                         if ($cancreate{'emaildomain'}{$type} eq '') {                                          $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                                             $chgtext .= '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';  
                                         } else {  
                                             $chgtext .= '<li>'.$othertitle.' -- '.&mt("User's e-mail domain needs to be: [_1]",  
                                                                                       $cancreate{'emaildomain'}{$type}).'</li>';  
                                         }  
                                     } else {                                      } else {
                                         if ($cancreate{'emaildomain'}{$type} eq '') {                                          $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                                             $chgtext .= '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';  
                                         } else {  
                                             $chgtext .= '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail domain needs to be: [_1]",  
                                                                                             $cancreate{'emaildomain'}{$type}).'</li>';   
                                         }  
                                     }                                      }
                                 }                                  }
                                 $chgtext .= '</ul>';                                  $chgtext .= '</ul>';
                             }                              }
                         } else {                          } else {
                             if ($cancreate{'emailverified'}{'default'} eq 'other') {                              if ($cancreate{'emailoptions'}{'default'} eq 'any') {
                                 if ($cancreate{'emaildomain'}{'default'} eq '') {                                  $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
                                     $chgtext .= &mt('No restriction on e-mail domain for self-created accounts verified by e-mail address, where username is chosen by user.');                              } else {
                                 } else {                                  $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
                                     $chgtext .= &mt('For self-created accounts verified by e-mail address, where username is chosen by user, e-mail domain needs to be: [_1]',                                                  $options{$cancreate{'emailoptions'}{'default'}});
                                                     $cancreate{'selfcreateprocessing'}{'default'});                              }
                           }
                       } elsif ($type eq 'emaildomain') {
                           my $output;
                           if (@statuses) {
                               foreach my $type (@statuses) {
                                   if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
                                       if ($cancreate{'emailoptions'}{$type} eq 'inst') {
                                           if ($type eq 'default') {
                                               if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                                                   ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                                                   $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                                               } else {
                                                   $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
                                                                                           $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                                               }
                                           } else {
                                               if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                                                   ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                                                   $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                                               } else {
                                                   $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
                                                                                                 $cancreate{'emaildomain'}{$type}{'inst'}).'</li>'; 
                                               }
                                           }
                                       } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
                                           if ($type eq 'default') {
                                               if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                                                   ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                                                   $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                                               } else {
                                                   $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
                                                                                           $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                                               }
                                           } else {
                                               if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                                                   ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                                                   $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                                               } else {
                                                   $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
                                                                                                   $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';   
                                               }
                                           }
                                       }
                                 }                                  }
                             }                              }
                         }                          }
                           if ($output ne '') {
                               $chgtext .= &mt('For self-created accounts verified by e-mail address:').
                                           '<ul>'.$output.'</ul>';
                           }
                     } elsif ($type eq 'captcha') {                      } elsif ($type eq 'captcha') {
                         if ($savecaptcha{$type} eq 'notused') {                          if ($savecaptcha{$type} eq 'notused') {
                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');                              $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
Line 11903  sub modify_selfcreation { Line 12221  sub modify_selfcreation {
                         }                          }
                     } elsif ($type eq 'emailusername') {                      } elsif ($type eq 'emailusername') {
                         if (ref($cancreate{'emailusername'}) eq 'HASH') {                          if (ref($cancreate{'emailusername'}) eq 'HASH') {
                             if (@types) {                              if (@statuses) {
                                 foreach my $type (@types) {                                  foreach my $type (@statuses) {
                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {                                      if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {                                          if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
                                             $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").                                              $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
Line 11943  sub modify_selfcreation { Line 12261  sub modify_selfcreation {
                     }                      }
                 }                  }
             }              }
             if (ref($changes{'email_rule'}) eq 'ARRAY') {              if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
                 my ($emailrules,$emailruleorder) =                  my ($emailrules,$emailruleorder) =
                     &Apache::lonnet::inst_userrules($dom,'email');                      &Apache::lonnet::inst_userrules($dom,'email');
                 my $chgtext = '<ul>';                  foreach my $type (@{$changes{'email_rule'}}) {
                 foreach my $type (@email_rule) {                      if (ref($email_rule{$type}) eq 'ARRAY') {
                     if (ref($emailrules->{$type}) eq 'HASH') {                          my $chgtext = '<ul>';
                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';                          foreach my $rule (@{$email_rule{$type}}) {
                               if (ref($emailrules->{$rule}) eq 'HASH') {
                                   $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
                               }
                           }
                           $chgtext .= '</ul>';
                           if (@types) {
                               my $typename;
                               if ($type eq 'default') {
                                   $typename = $othertitle;
                               } else {
                                   $typename = $usertypes{$type};
                               } 
                               $chgtext .= &mt('(Affiliation: [_1])',$typename);
                           }
                           if (@{$email_rule{$type}} > 0) {
                               $resulttext .= '<li>'.
                                              &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
                                                  $usertypes{$type}).
                                              $chgtext.
                                              '</li>';
                           } else {
                               $resulttext .= '<li>'.
                                              &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.',
                                                   $usertypes{$type}).
                                              '</li>'.
                                              &mt('(Affiliation: [_1])',$type);
                           }
                     }                      }
                 }                  }
                 $chgtext .= '</ul>';              }
                 if (@email_rule > 0) {              if (ref($changes{'inststatus'}) eq 'ARRAY') {
                     $resulttext .= '<li>'.                  if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
                                    &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ').                      if (@{$save_inststatus{'inststatusguest'}} > 0) {
                                        $chgtext.                          my $chgtext = '<ul>';
                                    '</li>';                          foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
                 } else {                              $chgtext .= '<li>'.$usertypes{$type}.'</li>';
                     $resulttext .= '<li>'.                          }
                                    &mt('There are now no restrictions on e-mail addresses which may be used for verification when self-enrolling.').                          $chgtext .= '</ul>';
                                    '</li>';                          $resulttext .= '<li>'.
                                          &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
                                             $chgtext.
                                          '</li>';
                       } else {
                           $resulttext .= '<li>'.
                                          &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
                                          '</li>';
                       }
                 }                  }
             }              }
             if (ref($changes{'selfcreate'}) eq 'ARRAY') {              if (ref($changes{'selfcreate'}) eq 'ARRAY') {
Line 11994  sub modify_selfcreation { Line 12347  sub modify_selfcreation {
                 $resulttext .= '</ul></li>';                  $resulttext .= '</ul></li>';
             }              }
             $resulttext .= '</ul>';              $resulttext .= '</ul>';
               my $cachetime = 24*60*60;
               $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
               &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
               if (ref($lastactref) eq 'HASH') {
                   $lastactref->{'domdefaults'} = 1;
               }
         } else {          } else {
             $resulttext = &mt('No changes made to self-creation settings');              $resulttext = &mt('No changes made to self-creation settings');
         }          }
Line 12277  sub modify_defaults { Line 12636  sub modify_defaults {
     }      }
     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');      my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
     my @allpos;      my @allpos;
     my %guests;  
     my %alltypes;      my %alltypes;
     my ($currtitles,$currguests,$currorder);      my @inststatusguest;
       if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
           foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
               unless (grep(/^\Q$type\E$/,@todelete)) {
                   push(@inststatusguest,$type);
               }
           }
       }
       my ($currtitles,$currorder);
     if (ref($currinststatus) eq 'HASH') {      if (ref($currinststatus) eq 'HASH') {
         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {          if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {              foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
Line 12294  sub modify_defaults { Line 12660  sub modify_defaults {
                     $allpos[$position] = $type;                      $allpos[$position] = $type;
                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};                      $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                     $alltypes{$type} =~ s/`//g;                      $alltypes{$type} =~ s/`//g;
                     if ($env{'form.inststatus_guest_'.$type}) {  
                         $guests{$type} = 1;  
                     }  
                 }                  }
             }              }
             if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {  
                 $currguests = join(',',@{$currinststatus->{'inststatusguest'}});  
             }  
             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});              $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
             $currtitles =~ s/,$//;              $currtitles =~ s/,$//;
         }          }
Line 12310  sub modify_defaults { Line 12670  sub modify_defaults {
         my $newtype = $env{'form.addinststatus'};          my $newtype = $env{'form.addinststatus'};
         $newtype =~ s/\W//g;          $newtype =~ s/\W//g;
         unless (exists($alltypes{$newtype})) {          unless (exists($alltypes{$newtype})) {
             if ($env{'form.addinststatus_guest'}) {  
                 $guests{$newtype} = 1;  
             }  
             $alltypes{$newtype} = $env{'form.addinststatus_title'};              $alltypes{$newtype} = $env{'form.addinststatus_title'};
             $alltypes{$newtype} =~ s/`//g;               $alltypes{$newtype} =~ s/`//g; 
             my $position = $env{'form.addinststatus_pos'};              my $position = $env{'form.addinststatus_pos'};
Line 12322  sub modify_defaults { Line 12679  sub modify_defaults {
             }              }
         }          }
     }      }
     my (@orderedstatus,@orderedguests);      my @orderedstatus;
     foreach my $type (@allpos) {      foreach my $type (@allpos) {
         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {          unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
             push(@orderedstatus,$type);              push(@orderedstatus,$type);
             if ($guests{$type}) {  
                 push(@orderedguests,$type);  
             }  
         }          }
     }      }
     foreach my $type (keys(%alltypes)) {      foreach my $type (keys(%alltypes)) {
Line 12339  sub modify_defaults { Line 12693  sub modify_defaults {
     $defaults_hash{'inststatus'} = {      $defaults_hash{'inststatus'} = {
                                      inststatustypes => \%alltypes,                                       inststatustypes => \%alltypes,
                                      inststatusorder => \@orderedstatus,                                       inststatusorder => \@orderedstatus,
                                      inststatusguest => \@orderedguests,                                       inststatusguest => \@inststatusguest,
                                    };                                     };
     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {      if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {          foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
Line 12349  sub modify_defaults { Line 12703  sub modify_defaults {
     if ($currorder ne join(',',@orderedstatus)) {      if ($currorder ne join(',',@orderedstatus)) {
         $changes{'inststatus'}{'inststatusorder'} = 1;          $changes{'inststatus'}{'inststatusorder'} = 1;
     }      }
     if ($currguests ne join(',',@orderedguests)) {  
         $changes{'inststatus'}{'inststatusguest'} = 1;  
     }  
     my $newtitles;      my $newtitles;
     foreach my $item (@orderedstatus) {      foreach my $item (@orderedstatus) {
         $newtitles .= $alltypes{$item}.',';          $newtitles .= $alltypes{$item}.',';
Line 12370  sub modify_defaults { Line 12721  sub modify_defaults {
             foreach my $item (sort(keys(%changes))) {              foreach my $item (sort(keys(%changes))) {
                 if ($item eq 'inststatus') {                  if ($item eq 'inststatus') {
                     if (ref($changes{'inststatus'}) eq 'HASH') {                      if (ref($changes{'inststatus'}) eq 'HASH') {
                         if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {                          if (@orderedstatus) {
                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';                              $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                             foreach my $type (@orderedstatus) {                               foreach my $type (@orderedstatus) { 
                                 $resulttext .= $alltypes{$type}.', ';                                  $resulttext .= $alltypes{$type}.', ';
                             }                              }
                             $resulttext =~ s/, $//;                              $resulttext =~ s/, $//;
                             $resulttext .= '</li>';                              $resulttext .= '</li>';
                         }                          } else {
                         if ($changes{'inststatus'}{'inststatusguest'}) {                              $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>'; 
                             $resulttext .= '<li>';   
                             if (@orderedguests) {  
                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';  
                                 foreach my $type (@orderedguests) {  
                                     $resulttext .= $alltypes{$type}.', ';  
                                 }  
                                 $resulttext =~ s/, $//;  
                             } else {  
                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');  
                             }  
                             $resulttext .= '</li>';  
                         }                          }
                     }                      }
                 } else {                  } else {
Line 13893  sub modify_selfenrollment { Line 14233  sub modify_selfenrollment {
                         $resulttext .= '</ul></li>';                           $resulttext .= '</ul></li>'; 
                     }                      }
                 }                  }
                 if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {              }
                     my $cachetime = 24*60*60;              if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                     &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);                  my $cachetime = 24*60*60;
                     if (ref($lastactref) eq 'HASH') {                  &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                         $lastactref->{'domdefaults'} = 1;                  if (ref($lastactref) eq 'HASH') {
                     }                      $lastactref->{'domdefaults'} = 1;
                 }                  }
             }              }
             $resulttext .= '</ul>';              $resulttext .= '</ul>';

Removed from v.1.304  
changed lines
  Added in v.1.305


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>