Diff for /loncom/interface/domainprefs.pm between versions 1.160.6.43 and 1.217

version 1.160.6.43, 2014/05/04 22:19:29 version 1.217, 2013/12/24 21:59:36
Line 95  institutional affiliation in the domain Line 95  institutional affiliation in the domain
 but is now also used to manage availability of user tools:   but is now also used to manage availability of user tools: 
 i.e., blogs, aboutme page, and portfolios, and the course request tool,  i.e., blogs, aboutme page, and portfolios, and the course request tool,
 used by course owners to request creation of a course, and to display/store  used by course owners to request creation of a course, and to display/store
 default quota sizes for Authoring Spaces.  default quota sizes for authoring spaces.
   
 Outputs: 1  Outputs: 1
   
Line 164  use Apache::lonhtmlcommon(); Line 164  use Apache::lonhtmlcommon();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonmsg();  use Apache::lonmsg();
 use Apache::lonconfigsettings;  use Apache::lonconfigsettings;
 use Apache::lonuserutils();  
 use Apache::loncoursequeueadmin();  
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
 use LONCAPA::Enrollment;  use LONCAPA::Enrollment;
 use LONCAPA::lonauthcgi();  use LONCAPA::lonauthcgi();
Line 213  sub handler { Line 211  sub handler {
                 'quotas','autoenroll','autoupdate','autocreate',                  'quotas','autoenroll','autoupdate','autocreate',
                 'directorysrch','usercreation','usermodification',                  'directorysrch','usercreation','usermodification',
                 'contacts','defaults','scantron','coursecategories',                  'contacts','defaults','scantron','coursecategories',
                 'serverstatuses','requestcourses','coursedefaults',                  'serverstatuses','requestcourses','helpsettings',
                 'usersessions','loadbalancing','requestauthor',                  'coursedefaults','usersessions','loadbalancing',
                 'selfenrollment','inststatus'],$dom);                  'requestauthor'],$dom);
     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',      my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
                        'autoupdate','autocreate','directorysrch','contacts',                         'autoupdate','autocreate','directorysrch','contacts',
                        'usercreation','selfcreation','usermodification','scantron',                         'usercreation','usermodification','scantron',
                        'requestcourses','requestauthor','coursecategories',                         'requestcourses','requestauthor','coursecategories',
                        'serverstatuses','coursedefaults','selfenrollment',                         'serverstatuses','helpsettings',
                        'usersessions');                         'coursedefaults','usersessions');
     my %existing;      my %existing;
     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {      if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
         %existing = %{$domconfig{'loadbalancing'}};          %existing = %{$domconfig{'loadbalancing'}};
Line 241  sub handler { Line 239  sub handler {
                                  col2 => '',},                                   col2 => '',},
                                 {col1 => 'Administrator Settings',                                  {col1 => 'Administrator Settings',
                                  col2 => '',}],                                   col2 => '',}],
                       print => \&print_rolecolors,  
                       modify => \&modify_rolecolors,  
                     },                      },
         'login' =>          'login' =>
                     { text => 'Log-in page options',                      { text => 'Log-in page options',
Line 251  sub handler { Line 247  sub handler {
                                   col2 => '',},                                    col2 => '',},
                                  {col1 => 'Log-in Help',                                   {col1 => 'Log-in Help',
                                   col2 => 'Value'}],                                    col2 => 'Value'}],
                       print => \&print_login,  
                       modify => \&modify_login,  
                     },                      },
         'defaults' =>           'defaults' => 
                     { text => 'Default authentication/language/timezone/portal/types',                      { text => 'Default authentication/language/timezone/portal',
                       help => 'Domain_Configuration_LangTZAuth',                        help => 'Domain_Configuration_LangTZAuth',
                       header => [{col1 => 'Setting',                        header => [{col1 => 'Setting',
                                   col2 => 'Value'},                                    col2 => 'Value'}],
                                  {col1 => 'Institutional user types',  
                                   col2 => 'Assignable to e-mail usernames'}],  
                       print => \&print_defaults,  
                       modify => \&modify_defaults,  
                     },                      },
         'quotas' =>           'quotas' => 
                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',                      { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
Line 270  sub handler { Line 260  sub handler {
                       header => [{col1 => 'User affiliation',                        header => [{col1 => 'User affiliation',
                                   col2 => 'Available tools',                                    col2 => 'Available tools',
                                   col3 => 'Quotas, MB; (Authoring requires role)',}],                                    col3 => 'Quotas, MB; (Authoring requires role)',}],
                       print => \&print_quotas,  
                       modify => \&modify_quotas,  
                     },                      },
         'autoenroll' =>          'autoenroll' =>
                    { text => 'Auto-enrollment settings',                     { text => 'Auto-enrollment settings',
                      help => 'Domain_Configuration_Auto_Enrollment',                       help => 'Domain_Configuration_Auto_Enrollment',
                      header => [{col1 => 'Configuration setting',                       header => [{col1 => 'Configuration setting',
                                  col2 => 'Value(s)'}],                                   col2 => 'Value(s)'}],
                      print => \&print_autoenroll,  
                      modify => \&modify_autoenroll,  
                    },                     },
         'autoupdate' =>           'autoupdate' => 
                    { text => 'Auto-update settings',                     { text => 'Auto-update settings',
Line 289  sub handler { Line 275  sub handler {
                                 {col1 => 'Setting',                                  {col1 => 'Setting',
                                  col2 => 'Affiliation'},                                   col2 => 'Affiliation'},
                                 {col1 => 'User population',                                  {col1 => 'User population',
                                  col2 => 'Updatable user data'}],                                   col2 => 'Updateable user data'}],
                      print => \&print_autoupdate,  
                      modify => \&modify_autoupdate,  
                   },                    },
         'autocreate' =>           'autocreate' => 
                   { text => 'Auto-course creation settings',                    { text => 'Auto-course creation settings',
                      help => 'Domain_Configuration_Auto_Creation',                       help => 'Domain_Configuration_Auto_Creation',
                      header => [{col1 => 'Configuration Setting',                       header => [{col1 => 'Configuration Setting',
                                  col2 => 'Value',}],                                   col2 => 'Value',}],
                      print => \&print_autocreate,  
                      modify => \&modify_autocreate,  
                   },                    },
         'directorysrch' =>           'directorysrch' => 
                   { text => 'Institutional directory searches',                    { text => 'Institutional directory searches',
                     help => 'Domain_Configuration_InstDirectory_Search',                      help => 'Domain_Configuration_InstDirectory_Search',
                     header => [{col1 => 'Setting',                      header => [{col1 => 'Setting',
                                 col2 => 'Value',}],                                  col2 => 'Value',}],
                     print => \&print_directorysrch,  
                     modify => \&modify_directorysrch,  
                   },                    },
         'contacts' =>          'contacts' =>
                   { text => 'Contact Information',                    { text => 'Contact Information',
                     help => 'Domain_Configuration_Contact_Info',                      help => 'Domain_Configuration_Contact_Info',
                     header => [{col1 => 'Setting',                      header => [{col1 => 'Setting',
                                 col2 => 'Value',}],                                  col2 => 'Value',}],
                     print => \&print_contacts,  
                     modify => \&modify_contacts,  
                   },                    },
   
         'usercreation' =>           'usercreation' => 
                   { text => 'User creation',                    { text => 'User creation',
                     help => 'Domain_Configuration_User_Creation',                      help => 'Domain_Configuration_User_Creation',
Line 326  sub handler { Line 305  sub handler {
                                 col2 => 'Usernames which may be created',},                                  col2 => 'Usernames which may be created',},
                                {col1 => 'Context',                                 {col1 => 'Context',
                                 col2 => 'Assignable authentication types'}],                                  col2 => 'Assignable authentication types'}],
                     print => \&print_usercreation,  
                     modify => \&modify_usercreation,  
                   },  
         'selfcreation' =>   
                   { text => 'Users self-creating accounts',  
                     help => 'Domain_Configuration_Self_Creation',   
                     header => [{col1 => 'Self-creation with institutional username',  
                                 col2 => 'Enabled?'},  
                                {col1 => 'Institutional user type (login/SSO self-creation)',  
                                 col2 => 'Information user can enter'},  
                                {col1 => 'Self-creation with e-mail as username',  
                                 col2 => 'Settings'}],  
                     print => \&print_selfcreation,  
                     modify => \&modify_selfcreation,  
                   },                    },
         'usermodification' =>          'usermodification' =>
                   { text => 'User modification',                    { text => 'User modification',
                     help => 'Domain_Configuration_User_Modification',                      help => 'Domain_Configuration_User_Modification',
                     header => [{col1 => 'Target user has role',                      header => [{col1 => 'Target user has role',
                                 col2 => 'User information updatable in author context'},                                  col2 => 'User information updateable in author context'},
                                {col1 => 'Target user has role',                                 {col1 => 'Target user has role',
                                 col2 => 'User information updatable in course context'}],                                  col2 => 'User information updateable in course context'},
                     print => \&print_usermodification,                                 {col1 => "Status of user",
                     modify => \&modify_usermodification,                                  col2 => 'Information settable when self-creating account (if directory data blank)'}],
                   },                    },
         'scantron' =>          'scantron' =>
                   { text => 'Bubblesheet format file',                    { text => 'Bubblesheet format file',
Line 357  sub handler { Line 322  sub handler {
                     header => [ {col1 => 'Item',                      header => [ {col1 => 'Item',
                                  col2 => '',                                   col2 => '',
                               }],                                }],
                     print => \&print_scantron,  
                     modify => \&modify_scantron,  
                   },                    },
         'requestcourses' =>           'requestcourses' => 
                  {text => 'Request creation of courses',                   {text => 'Request creation of courses',
Line 368  sub handler { Line 331  sub handler {
                              {col1 => 'Setting',                               {col1 => 'Setting',
                               col2 => 'Value'},                                col2 => 'Value'},
                              {col1 => 'Available textbooks',                               {col1 => 'Available textbooks',
                               col2 => ''},                                col2 => ''}],
                              {col1 => 'Validation (not official courses)',  
                               col2 => 'Value'},],  
                   print => \&print_quotas,  
                   modify => \&modify_quotas,  
                  },                   },
         'requestauthor' =>          'requestauthor' =>
                  {text => 'Request Authoring Space',                   {text => 'Request authoring space',
                   help => 'Domain_Configuration_Request_Author',                    help => 'Domain_Configuration_Request_Author',
                   header => [{col1 => 'User affiliation',                    header => [{col1 => 'User affiliation',
                               col2 => 'Availability/Processing of requests',},                                col2 => 'Availability/Processing of requests',},
                              {col1 => 'Setting',                               {col1 => 'Setting',
                               col2 => 'Value'}],                                col2 => 'Value'}],
                   print => \&print_quotas,  
                   modify => \&modify_quotas,  
                  },                   },
         'coursecategories' =>          'coursecategories' =>
                   { text => 'Cataloging of courses/communities',                    { text => 'Cataloging of courses/communities',
                     help => 'Domain_Configuration_Cataloging_Courses',                      help => 'Domain_Configuration_Cataloging_Courses',
                     header => [{col1 => 'Catalog type/availability',                      header => [{col1 => 'Category settings',
                                 col2 => '',},  
                                {col1 => 'Category settings for standard catalog',  
                                 col2 => '',},                                  col2 => '',},
                                {col1 => 'Categories',                                 {col1 => 'Categories',
                                 col2 => '',                                  col2 => '',
                                }],                                 }],
                     print => \&print_coursecategories,  
                     modify => \&modify_coursecategories,  
                   },                    },
         'serverstatuses' =>          'serverstatuses' =>
                  {text   => 'Access to server status pages',                   {text   => 'Access to server status pages',
Line 404  sub handler { Line 357  sub handler {
                               col2 => 'Other named users',                                col2 => 'Other named users',
                               col3 => 'Specific IPs',                                col3 => 'Specific IPs',
                             }],                              }],
                   print => \&print_serverstatuses,                   },
                   modify => \&modify_serverstatuses,          'helpsettings' =>
                    {text   => 'Help page settings',
                     help   => 'Domain_Configuration_Help_Settings',
                     header => [{col1 => 'Help Settings (logged-in users)',
                                 col2 => 'Value'}],
                  },                   },
         'coursedefaults' =>           'coursedefaults' => 
                  {text => 'Course/Community defaults',                   {text => 'Course/Community defaults',
Line 414  sub handler { Line 371  sub handler {
                               col2 => 'Value',},                                col2 => 'Value',},
                              {col1 => 'Defaults which can be overridden for each course by a DC',                               {col1 => 'Defaults which can be overridden for each course by a DC',
                               col2 => 'Value',},],                                col2 => 'Value',},],
                   print => \&print_coursedefaults,  
                   modify => \&modify_coursedefaults,  
                  },                   },
         'selfenrollment' =>           'privacy' => 
                  {text   => 'Self-enrollment in Course/Community',                   {text   => 'User Privacy',
                   help   => 'Domain_Configuration_Selfenrollment',                    help   => 'Domain_Configuration_User_Privacy',
                   header => [{col1 => 'Configuration Rights',                    header => [{col1 => 'Setting',
                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},                                col2 => 'Value',}],
                              {col1 => 'Defaults',  
                               col2 => 'Value'},  
                              {col1 => 'Self-enrollment validation (optional)',  
                               col2 => 'Value'},],  
                   print => \&print_selfenrollment,  
                   modify => \&modify_selfenrollment,  
                  },                   },
         'usersessions' =>          'usersessions' =>
                  {text  => 'User session hosting/offloading',                   {text  => 'User session hosting/offloading',
Line 438  sub handler { Line 387  sub handler {
                               col2 => 'Rules'},                                col2 => 'Rules'},
                              {col1 => "Hosting domain's own users elsewhere",                               {col1 => "Hosting domain's own users elsewhere",
                               col2 => 'Rules'}],                                col2 => 'Rules'}],
                   print => \&print_usersessions,  
                   modify => \&modify_usersessions,  
                  },                   },
          'loadbalancing' =>           'loadbalancing' =>
                  {text  => 'Dedicated Load Balancer(s)',                   {text  => 'Dedicated Load Balancer(s)',
Line 449  sub handler { Line 396  sub handler {
                               col3 => 'User affiliation',                                col3 => 'User affiliation',
                               col4 => 'Overrides'},                                col4 => 'Overrides'},
                             ],                              ],
                   print => \&print_loadbalancing,  
                   modify => \&modify_loadbalancing,  
                  },                   },
     );      );
     if (keys(%servers) > 1) {      if (keys(%servers) > 1) {
Line 462  sub handler { Line 407  sub handler {
                                         col2 => ''},                                          col2 => ''},
                                        {col1 => 'Log-in Help',                                         {col1 => 'Log-in Help',
                                         col2 => 'Value'}],                                          col2 => 'Value'}],
                             print => \&print_login,  
                             modify => \&modify_login,  
                            };                             };
     }      }
   
Line 477  sub handler { Line 420  sub handler {
     if ($phase eq 'process') {      if ($phase eq 'process') {
         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,          my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                                                               \%prefs,\%domconfig,$confname,\@roles);                                                                \%prefs,\%domconfig,$confname,\@roles);
         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {          if (ref($result) eq 'HASH') {
             $r->rflush();              $r->rflush();
             &devalidate_remote_domconfs($dom,$result);              &devalidate_remote_domconfs($dom,$result);
         }          }
     } elsif ($phase eq 'display') {      } elsif ($phase eq 'display') {
         my $js = &recaptcha_js().          my $js = &recaptcha_js().
                  &toggle_display_js();                   &credits_js();
         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {          if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
             my ($othertitle,$usertypes,$types) =              my ($othertitle,$usertypes,$types) =
                 &Apache::loncommon::sorted_inst_types($dom);                  &Apache::loncommon::sorted_inst_types($dom);
Line 595  sub process_changes { Line 538  sub process_changes {
         $output = &modify_directorysrch($dom,%domconfig);          $output = &modify_directorysrch($dom,%domconfig);
     } elsif ($action eq 'usercreation') {      } elsif ($action eq 'usercreation') {
         $output = &modify_usercreation($dom,%domconfig);          $output = &modify_usercreation($dom,%domconfig);
     } elsif ($action eq 'selfcreation') {  
         $output = &modify_selfcreation($dom,%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 606  sub process_changes { Line 547  sub process_changes {
     } elsif ($action eq 'scantron') {      } elsif ($action eq 'scantron') {
         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);          $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
     } elsif ($action eq 'coursecategories') {      } elsif ($action eq 'coursecategories') {
         $output = &modify_coursecategories($dom,$lastactref,%domconfig);          $output = &modify_coursecategories($dom,%domconfig);
     } elsif ($action eq 'serverstatuses') {      } elsif ($action eq 'serverstatuses') {
         $output = &modify_serverstatuses($dom,%domconfig);          $output = &modify_serverstatuses($dom,%domconfig);
     } elsif ($action eq 'requestcourses') {      } elsif ($action eq 'requestcourses') {
         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);          $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
     } elsif ($action eq 'requestauthor') {      } elsif ($action eq 'requestauthor') {
         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);          $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
       } elsif ($action eq 'helpsettings') {
           $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
     } elsif ($action eq 'coursedefaults') {      } elsif ($action eq 'coursedefaults') {
         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);          $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
     } elsif ($action eq 'selfenrollment') {  
         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)  
     } elsif ($action eq 'usersessions') {      } elsif ($action eq 'usersessions') {
         $output = &modify_usersessions($dom,$lastactref,%domconfig);          $output = &modify_usersessions($dom,$lastactref,%domconfig);
     } elsif ($action eq 'loadbalancing') {      } elsif ($action eq 'loadbalancing') {
Line 631  sub print_config_box { Line 572  sub print_config_box {
     my $output;      my $output;
     if ($action eq 'coursecategories') {      if ($action eq 'coursecategories') {
         $output = &coursecategories_javascript($settings);          $output = &coursecategories_javascript($settings);
     } elsif ($action eq 'defaults') {  
         $output = &defaults_javascript($settings);   
     }      }
     $output .=      $output .= 
          '<table class="LC_nested_outer">           '<table class="LC_nested_outer">
           <tr>            <tr>
            <th align="left" valign="middle"><span class="LC_nobreak">'.             <th align="left" valign="middle"><span class="LC_nobreak">'.
Line 649  sub print_config_box { Line 588  sub print_config_box {
     if ($numheaders > 1) {      if ($numheaders > 1) {
         my $colspan = '';          my $colspan = '';
         my $rightcolspan = '';          my $rightcolspan = '';
         if (($action eq 'rolecolors') || ($action eq 'defaults') ||          if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
             (($action eq 'login') && ($numheaders < 3))) {              (($action eq 'login') && ($numheaders < 3))) {
             $colspan = ' colspan="2"';              $colspan = ' colspan="2"';
         }          }
Line 665  sub print_config_box { Line 604  sub print_config_box {
               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>                <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
              </tr>';               </tr>';
         $rowtotal ++;          $rowtotal ++;
         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||          if ($action eq 'autoupdate') {
             ($action eq 'usermodification') || ($action eq 'defaults') ||              $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
             ($action eq 'selfenrollment') || ($action eq 'usersessions')) {          } elsif ($action eq 'usercreation') {
             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);              $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
           } elsif ($action eq 'usermodification') {
               $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'coursecategories') {          } elsif ($action eq 'coursecategories') {
             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);              $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
         } elsif ($action eq 'login') {          } elsif ($action eq 'login') {
             if ($numheaders == 3) {              if ($numheaders == 3) {
                 $colspan = ' colspan="2"';                  $colspan = ' colspan="2"';
Line 678  sub print_config_box { Line 619  sub print_config_box {
             } else {              } else {
                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);                  $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
             }              }
         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {          } elsif ($action eq 'requestcourses') {
               $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
           } elsif ($action eq 'requestauthor') {
             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);              $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
           } elsif ($action eq 'usersessions') {
               $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
         } elsif ($action eq 'rolecolors') {          } elsif ($action eq 'rolecolors') {
             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);              $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
           } elsif ($action eq 'coursedefaults') {
               $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
         }          }
         $output .= '          $output .= '
            </table>             </table>
Line 691  sub print_config_box { Line 638  sub print_config_box {
            <td>             <td>
             <table class="LC_nested">              <table class="LC_nested">
              <tr class="LC_info_row">               <tr class="LC_info_row">
               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>                <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
           $output .= '
               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>                <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
              </tr>';               </tr>';
             $rowtotal ++;              $rowtotal ++;
         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||          if ($action eq 'autoupdate') {
             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||              $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
             ($action eq 'usersessions') || ($action eq 'coursecategories')) {  
             if ($action eq 'coursecategories') {  
                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);  
                 $colspan = ' colspan="2"';  
             } else {  
                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);  
             }  
             $output .= '  
            </table>             </table>
           </td>            </td>
          </tr>           </tr>
Line 713  sub print_config_box { Line 653  sub print_config_box {
             <table class="LC_nested">              <table class="LC_nested">
              <tr class="LC_info_row">               <tr class="LC_info_row">
               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>                <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>                <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
              </tr>'."\n";              &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
             if ($action eq 'coursecategories') {              $rowtotal ++;
                 $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);          } elsif ($action eq 'usercreation') {
             } else {              $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
                 $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);             </table>
             }            </td>
            </tr>
            <tr>
              <td>
               <table class="LC_nested">
                <tr class="LC_info_row">
                 <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                 <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
               &print_usercreation('bottom',$dom,$settings,\$rowtotal);
               $rowtotal ++;
           } elsif ($action eq 'usermodification') {
               $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
              </table>
             </td>
            </tr>
            <tr>
              <td>
               <table class="LC_nested">
                <tr class="LC_info_row">
                 <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                 <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
                          &print_usermodification('bottom',$dom,$settings,\$rowtotal);
             $rowtotal ++;              $rowtotal ++;
         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||          } elsif ($action eq 'coursecategories') {
                   ($action eq 'defaults')) {              $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);  
         } elsif ($action eq 'login') {          } elsif ($action eq 'login') {
             if ($numheaders == 3) {              if ($numheaders == 3) {
                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'                  $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
Line 753  sub print_config_box { Line 713  sub print_config_box {
              <tr class="LC_info_row">               <tr class="LC_info_row">
               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>                <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.                <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
                        &print_textbookcourses($dom,$settings,\$rowtotal).'                         &print_textbookcourses($dom,$settings,\$rowtotal);
             </table>          } elsif ($action eq 'requestauthor') {
            </td>              $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
           </tr>          } elsif ($action eq 'usersessions') {
           <tr>              $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
              </table>
             </td>
            </tr>
            <tr>
            <td>             <td>
             <table class="LC_nested">              <table class="LC_nested">
              <tr class="LC_info_row">               <tr class="LC_info_row">
               <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[3]->{'col1'}).'</td>                <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
               <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>                <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
              </tr>'.                         &print_usersessions('bottom',$dom,$settings,\$rowtotal);
             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);              $rowtotal ++;
         } elsif ($action eq 'requestauthor') {          } elsif ($action eq 'coursedefaults') {
             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);              $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'rolecolors') {          } elsif ($action eq 'rolecolors') {
             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'              $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
            </table>             </table>
Line 845  sub print_config_box { Line 809  sub print_config_box {
         $rowtotal ++;          $rowtotal ++;
         if ($action eq 'quotas') {          if ($action eq 'quotas') {
             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);              $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||          } elsif ($action eq 'autoenroll') {
                  ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {              $output .= &print_autoenroll($dom,$settings,\$rowtotal);
             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);          } elsif ($action eq 'autocreate') {
               $output .= &print_autocreate($dom,$settings,\$rowtotal);
           } elsif ($action eq 'directorysrch') {
               $output .= &print_directorysrch($dom,$settings,\$rowtotal);
           } elsif ($action eq 'contacts') {
               $output .= &print_contacts($dom,$settings,\$rowtotal);
           } elsif ($action eq 'defaults') {
               $output .= &print_defaults($dom,$settings,\$rowtotal);
         } elsif ($action eq 'scantron') {          } elsif ($action eq 'scantron') {
             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);              $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
           } elsif ($action eq 'serverstatuses') {
               $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
         } elsif ($action eq 'helpsettings') {          } elsif ($action eq 'helpsettings') {
             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);              $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
           } elsif ($action eq 'loadbalancing') {
               $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
         }          }
     }      }
     $output .= '      $output .= '
Line 1482  sub display_color_options { Line 1457  sub display_color_options {
     $datatable .= '<td class="LC_right_item">'.      $datatable .= '<td class="LC_right_item">'.
                   '<table border="0"><tr>';                    '<table border="0"><tr>';
     foreach my $item (@{$links}) {      foreach my $item (@{$links}) {
  my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};   my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
         $datatable .= '<td align="center">'.$choices->{$item}."\n";          $datatable .= '<td align="center">'.$choices->{$item}."\n";
         if ($designs->{'links'}{$item}) {          if ($designs->{'links'}{$item}) {
             $datatable.='&nbsp;';              $datatable.='&nbsp;';
Line 2017  sub print_requestmail { Line 1992  sub print_requestmail {
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
         if (ref($settings->{'notify'}) eq 'HASH') {          if (ref($settings->{'notify'}) eq 'HASH') {
             if ($settings->{'notify'}{'approval'} ne '') {              if ($settings->{'notify'}{'approval'} ne '') {
                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
             }              }
         }          }
     }      }
     my $numinrow = 2;      my $numinrow = 2;
     my $css_class;      my $css_class = 'class="LC_odd_row"';
     $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');  
     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');
     } elsif ($action eq 'requestauthor') {  
         $text = &mt('Receive notification of Authoring Space requests requiring approval');  
     } else {      } else {
        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');          $text = &mt('Receive notification of authoring space requests requiring approval')
     }      }
     $datatable = '<tr'.$css_class.'>'.      $datatable = '<tr '.$css_class.'>'.
                  ' <td>'.$text.'</td>'.                   ' <td>'.$text.'</td>'.
                  ' <td class="LC_left_item">';                   ' <td class="LC_left_item">';
     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',      my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
                                                  $action.'notifyapproval',%currapp);                                                   'reqapprovalnotify',%currapp);
     if ($numdc > 0) {      if ($numdc > 0) {
         $datatable .= $table;          $datatable .= $table;
     } else {      } else {
Line 2050  sub print_requestmail { Line 2022  sub print_requestmail {
 sub print_studentcode {  sub print_studentcode {
     my ($settings,$rowtotal) = @_;      my ($settings,$rowtotal) = @_;
     my $rownum = 0;       my $rownum = 0; 
     my ($output,%current);      my %choices;
     my @crstypes = ('official','unofficial','community','textbook');      $choices{'uniquecode'} = &mt('Generate unique six character code as course identifier?');
     if (ref($settings->{'uniquecode'}) eq 'HASH') {      my @toggles = ('uniquecode');
         foreach my $type (@crstypes) {      my %defaultchecked = ('uniquecode'  => 'off');
             $current{$type} = $settings->{'uniquecode'}{$type};      (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
         }                                                 \%choices,$rownum);
     }      $$rowtotal += $rownum;
     $output .= '<tr>'.      return $reports;
                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.  
                '<td class="LC_left_item">';  
     foreach my $type (@crstypes) {  
         my $check = ' ';  
         if ($current{$type}) {  
             $check = ' checked="checked" ';  
         }  
         $output .= '<span class="LC_nobreak"><label>'.  
                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.  
                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';  
     }  
     $output .= '</td></tr>';  
     $$rowtotal ++;  
     return $output;  
 }  }
   
 sub print_textbookcourses {  sub print_textbookcourses {
Line 2095  sub print_textbookcourses { Line 2053  sub print_textbookcourses {
     }      }
     my $confname = $dom.'-domainconfig';      my $confname = $dom.'-domainconfig';
     my $switchserver = &check_switchserver($dom,$confname);      my $switchserver = &check_switchserver($dom,$confname);
     $maxnum = scalar(keys(%ordered));      my $maxnum = scalar(keys(%ordered));
     my $datatable = &textbookcourses_javascript(\%ordered);      my $datatable = &textbookcourses_javascript(\%ordered);
     if (keys(%ordered)) {      if (keys(%ordered)) {
         my @items = sort { $a <=> $b } keys(%ordered);          my @items = sort { $a <=> $b } keys(%ordered);
Line 2214  $jstext Line 2172  $jstext
     var newpos = 'addbook_pos';      var newpos = 'addbook_pos';
     var current = new Array;      var current = new Array;
     var maxh = 1 + $num;      var maxh = 1 + $num;
       var current = new Array;
     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;      var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
     if (item == newpos) {      if (item == newpos) {
         changedVal = newitemVal;          changedVal = newitemVal;
Line 2792  sub print_coursedefaults { Line 2751  sub print_coursedefaults {
                 '<td class="LC_right_item"><span class="LC_nobreak">'.                  '<td class="LC_right_item"><span class="LC_nobreak">'.
                 '<input type="text" name="anonsurvey_threshold"'.                  '<input type="text" name="anonsurvey_threshold"'.
                 ' value="'.$currdefresponder.'" size="5" /></span>'.                  ' value="'.$currdefresponder.'" size="5" /></span>'.
                 '</td></tr>'."\n";                  '</td></tr>'."\n".
         $itemcount ++;                  '<tr><td><span class="LC_nobreak">'.
         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';                  $choices{'uploadquota'}.
         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.                  '</span></td>'.
                       $choices{'uploadquota'}.                  '<td align="right" class="LC_right_item">'.
                       '</span></td>'.                  '<table><tr>';
                       '<td align="right" class="LC_right_item">'.  
                       '<table><tr>';  
         foreach my $type (@types) {          foreach my $type (@types) {
             $datatable .= '<td align="center">'.&mt($type).'<br />'.              $datatable .= '<td align="center">'.&mt($type).'<br />'.
                            '<input type="text" name="uploadquota_'.$type.'"'.                             '<input type="text" name="uploadquota_'.$type.'"'.
                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';                             ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
         }          }
         $datatable .= '</tr></table></td></tr>'."\n";          $datatable .= '</tr></table></td></tr>'."\n";
         $itemcount ++;          $itemcount += 2;
         my $onclick = "toggleDisplay(this.form,'credits');";          my $onclick = 'toggleCredits(this.form);';
         my $display = 'none';          my $display = 'none';
         if ($currusecredits) {          if ($currusecredits) {
             $display = 'block';              $display = 'block';
Line 2837  sub print_coursedefaults { Line 2794  sub print_coursedefaults {
             &radiobutton_prefs($current,\@toggles,\%defaultchecked,              &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                                \%choices,$itemcount,$onclick,$additional);                                 \%choices,$itemcount,$onclick,$additional);
         $datatable .= $table;          $datatable .= $table;
         $itemcount ++;  
     }  
     $$rowtotal += $itemcount;  
     return $datatable;  
 }  
   
 sub print_selfenrollment {  
     my ($position,$dom,$settings,$rowtotal) = @_;  
     my ($css_class,$datatable);  
     my $itemcount = 1;  
     my @types = ('official','unofficial','community','textbook');  
     if (($position eq 'top') || ($position eq 'middle')) {  
         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();  
         my %descs = &Apache::lonuserutils::selfenroll_default_descs();  
         my @rows;  
         my $key;  
         if ($position eq 'top') {  
             $key = 'admin';   
             if (ref($rowsref) eq 'ARRAY') {  
                 @rows = @{$rowsref};  
             }  
         } elsif ($position eq 'middle') {  
             $key = 'default';  
             @rows = ('types','registered','approval','limit');  
         }  
         foreach my $row (@rows) {  
             if (defined($titlesref->{$row})) {  
                 $itemcount ++;  
                 $css_class = $itemcount%2?' class="LC_odd_row"':'';  
                 $datatable .= '<tr'.$css_class.'>'.  
                               '<td>'.$titlesref->{$row}.'</td>'.  
                               '<td class="LC_left_item">'.  
                               '<table><tr>';  
                 my (%current,%currentcap);  
                 if (ref($settings) eq 'HASH') {  
                     if (ref($settings->{$key}) eq 'HASH') {  
                         foreach my $type (@types) {  
                             if (ref($settings->{$key}->{$type}) eq 'HASH') {  
                                 $current{$type} = $settings->{$key}->{$type}->{$row};  
                             }  
                             if (($row eq 'limit') && ($key eq 'default')) {  
                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {  
                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};  
                                 }  
                             }  
                         }  
                     }  
                 }  
                 my %roles = (  
                              '0' => &Apache::lonnet::plaintext('dc'),  
                             );   
               
                 foreach my $type (@types) {  
                     unless (($row eq 'registered') && ($key eq 'default')) {  
                         $datatable .= '<th>'.&mt($type).'</th>';  
                     }  
                 }  
                 unless (($row eq 'registered') && ($key eq 'default')) {  
                     $datatable .= '</tr><tr>';  
                 }  
                 foreach my $type (@types) {  
                     if ($type eq 'community') {  
                         $roles{'1'} = &mt('Community personnel');  
                     } else {  
                         $roles{'1'} = &mt('Course personnel');  
                     }  
                     $datatable .= '<td style="vertical-align: top">';  
                     if ($position eq 'top') {  
                         my %checked;  
                         if ($current{$type} eq '0') {  
                             $checked{'0'} = ' checked="checked"';  
                         } else {  
                             $checked{'1'} = ' checked="checked"';  
                         }  
                         foreach my $role ('1','0') {  
                             $datatable .= '<span class="LC_nobreak"><label>'.  
                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.  
                                           'value="'.$role.'"'.$checked{$role}.' />'.  
                                           $roles{$role}.'</label></span> ';  
                         }  
                     } else {  
                         if ($row eq 'types') {  
                             my %checked;  
                             if ($current{$type} =~ /^(all|dom)$/) {  
                                 $checked{$1} = ' checked="checked"';  
                             } else {  
                                 $checked{''} = ' checked="checked"';  
                             }  
                             foreach my $val ('','dom','all') {  
                                 $datatable .= '<span class="LC_nobreak"><label>'.  
                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.  
                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';  
                             }  
                         } elsif ($row eq 'registered') {  
                             my %checked;  
                             if ($current{$type} eq '1') {  
                                 $checked{'1'} = ' checked="checked"';  
                             } else {  
                                 $checked{'0'} = ' checked="checked"';  
                             }  
                             foreach my $val ('0','1') {  
                                 $datatable .= '<span class="LC_nobreak"><label>'.  
                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.  
                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';  
                             }  
                         } elsif ($row eq 'approval') {  
                             my %checked;  
                             if ($current{$type} =~ /^([12])$/) {  
                                 $checked{$1} = ' checked="checked"';  
                             } else {  
                                 $checked{'0'} = ' checked="checked"';  
                             }  
                             for my $val (0..2) {  
                                 $datatable .= '<span class="LC_nobreak"><label>'.  
                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.  
                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';  
                             }  
                         } elsif ($row eq 'limit') {  
                             my %checked;  
                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {  
                                 $checked{$1} = ' checked="checked"';  
                             } else {  
                                 $checked{'none'} = ' checked="checked"';  
                             }  
                             my $cap;  
                             if ($currentcap{$type} =~ /^\d+$/) {  
                                 $cap = $currentcap{$type};  
                             }  
                             foreach my $val ('none','allstudents','selfenrolled') {  
                                 $datatable .= '<span class="LC_nobreak"><label>'.  
                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.  
                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';  
                             }  
                             $datatable .= '<br />'.  
                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').  
                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.  
                                           '</span>';   
                         }  
                     }  
                     $datatable .= '</td>';  
                 }  
                 $datatable .= '</tr>';  
             }  
             $datatable .= '</table></td></tr>';  
         }  
     } elsif ($position eq 'bottom') {  
         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);  
     }      }
     $$rowtotal += $itemcount;      $$rowtotal += $itemcount;
     return $datatable;      return $datatable;
 }  }
   
 sub print_validation_rows {  
     my ($caller,$dom,$settings,$rowtotal) = @_;  
     my ($itemsref,$namesref,$fieldsref);  
     if ($caller eq 'selfenroll') {   
         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();  
     } elsif ($caller eq 'requestcourses') {  
         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();  
     }  
     my %currvalidation;  
     if (ref($settings) eq 'HASH') {  
         if (ref($settings->{'validation'}) eq 'HASH') {  
             %currvalidation = %{$settings->{'validation'}};  
         }  
     }  
     my $datatable;  
     my $itemcount = 0;  
     foreach my $item (@{$itemsref}) {  
         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';  
         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.  
                       $namesref->{$item}.  
                       '</span></td>'.  
                       '<td class="LC_left_item">';  
         if (($item eq 'url') || ($item eq 'button')) {  
             $datatable .= '<span class="LC_nobreak">'.  
                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.  
                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';  
         } elsif ($item eq 'fields') {  
             my @currfields;  
             if (ref($currvalidation{$item}) eq 'ARRAY') {  
                 @currfields = @{$currvalidation{$item}};  
             }  
             foreach my $field (@{$fieldsref}) {  
                 my $check = '';  
                 if (grep(/^\Q$field\E$/,@currfields)) {  
                     $check = ' checked="checked"';  
                 }  
                 $datatable .= '<span class="LC_nobreak"><label>'.  
                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.  
                               ' value="'.$field.'"'.$check.' />'.$field.  
                               '</label></span> ';  
             }  
         } elsif ($item eq 'markup') {  
             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.  
                            $currvalidation{$item}.  
                               '</textarea>';  
         }  
         $datatable .= '</td></tr>'."\n";  
         if (ref($rowtotal)) {  
             $itemcount ++;  
         }  
     }  
     if ($caller eq 'requestcourses') {  
         my %currhash;  
         if (ref($settings->{'validation'}) eq 'HASH') {  
             if ($settings->{'validation'}{'dc'} ne '') {  
                 $currhash{$settings->{'validation'}{'dc'}} = 1;  
             }  
         }  
         my $numinrow = 2;  
         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',  
                                                        'validationdc',%currhash);  
         if ($numdc > 1) {  
             $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.  
                           &mt('Course creation processed as: (choose Dom. Coord.)').  
                           '</td><td class="LC_left_item">'.$dctable.'</td></tr>';  
         } else {  
             $datatable .= $dctable.'</td></tr>';  
         }  
         $itemcount ++;  
     }  
     if (ref($rowtotal)) {  
         $$rowtotal += $itemcount;  
     }  
     return $datatable;  
 }  
   
 sub print_usersessions {  sub print_usersessions {
     my ($position,$dom,$settings,$rowtotal) = @_;      my ($position,$dom,$settings,$rowtotal) = @_;
     my ($css_class,$datatable,%checked,%choices);      my ($css_class,$datatable,%checked,%choices);
Line 3903  sub print_usercreation { Line 3637  sub print_usercreation {
                 $rowcount ++;                  $rowcount ++;
             }              }
         }          }
           my ($emailrules,$emailruleorder) = 
               &Apache::lonnet::inst_userrules($dom,'email');
           if (ref($emailrules) eq 'HASH') {
               if (keys(%{$emailrules}) > 0) {
                   $datatable .= &user_formats_row('email',$settings,$emailrules,
                                                   $emailruleorder,$numinrow,$rowcount);
                   $$rowtotal ++;
                   $rowcount ++;
               }
           }
         if ($rowcount == 0) {          if ($rowcount == 0) {
             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';                $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
             $$rowtotal ++;              $$rowtotal ++;
             $rowcount ++;              $rowcount ++;
         }          }
     } elsif ($position eq 'middle') {      } elsif ($position eq 'middle') {
         my @creators = ('author','course','requestcrs');          my @creators = ('author','course','requestcrs','selfcreate');
         my ($rules,$ruleorder) =          my ($rules,$ruleorder) =
             &Apache::lonnet::inst_userrules($dom,'username');              &Apache::lonnet::inst_userrules($dom,'username');
         my %lt = &usercreation_types();          my %lt = &usercreation_types();
         my %checked;          my %checked;
           my @selfcreate; 
         if (ref($settings) eq 'HASH') {          if (ref($settings) eq 'HASH') {
             if (ref($settings->{'cancreate'}) eq 'HASH') {              if (ref($settings->{'cancreate'}) eq 'HASH') {
                 foreach my $item (@creators) {                  foreach my $item (@creators) {
                     $checked{$item} = $settings->{'cancreate'}{$item};                      $checked{$item} = $settings->{'cancreate'}{$item};
                 }                  }
                   if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
                       @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
                   } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
                       if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                           @selfcreate = ('email','login','sso');
                       } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
                           @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
                       }
                   }
             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {              } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                 foreach my $item (@creators) {                  foreach my $item (@creators) {
                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {                      if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
Line 3930  sub print_usercreation { Line 3684  sub print_usercreation {
         my $rownum = 0;          my $rownum = 0;
         foreach my $item (@creators) {          foreach my $item (@creators) {
             $rownum ++;              $rownum ++;
             if ($checked{$item} eq '') {              if ($item ne 'selfcreate') {  
                 $checked{$item} = 'any';                  if ($checked{$item} eq '') {
                       $checked{$item} = 'any';
                   }
             }              }
             my $css_class;              my $css_class;
             if ($rownum%2) {              if ($rownum%2) {
Line 3942  sub print_usercreation { Line 3698  sub print_usercreation {
             $datatable .= '<tr'.$css_class.'>'.              $datatable .= '<tr'.$css_class.'>'.
                          '<td><span class="LC_nobreak">'.$lt{$item}.                           '<td><span class="LC_nobreak">'.$lt{$item}.
                          '</span></td><td align="right">';                           '</span></td><td align="right">';
             my @options = ('any');              my @options;
             if (ref($rules) eq 'HASH') {              if ($item eq 'selfcreate') {
                 if (keys(%{$rules}) > 0) {                  push(@options,('email','login','sso'));
                     push(@options,('official','unofficial'));              } else {
                   @options = ('any');
                   if (ref($rules) eq 'HASH') {
                       if (keys(%{$rules}) > 0) {
                           push(@options,('official','unofficial'));
                       }
                 }                  }
                   push(@options,'none');
             }              }
             push(@options,'none');  
             foreach my $option (@options) {              foreach my $option (@options) {
                 my $type = 'radio';                  my $type = 'radio';
                 my $check = ' ';                  my $check = ' ';
                 if ($checked{$item} eq $option) {                  if ($item eq 'selfcreate') {
                     $check = ' checked="checked" ';                      $type = 'checkbox';
                       if (grep(/^\Q$option\E$/,@selfcreate)) {
                           $check = ' checked="checked" ';
                       }
                   } else {
                       if ($checked{$item} eq $option) {
                           $check = ' checked="checked" ';
                       }
                 }                   } 
                 $datatable .= '<span class="LC_nobreak"><label>'.                  $datatable .= '<span class="LC_nobreak"><label>'.
                               '<input type="'.$type.'" name="can_createuser_'.                                '<input type="'.$type.'" name="can_createuser_'.
Line 3962  sub print_usercreation { Line 3730  sub print_usercreation {
             }              }
             $datatable .= '</td></tr>';              $datatable .= '</td></tr>';
         }          }
           my ($othertitle,$usertypes,$types) =
               &Apache::loncommon::sorted_inst_types($dom);
           my $createsettings;
           if (ref($settings) eq 'HASH') {
               $createsettings = $settings->{cancreate};
           }
           if (ref($usertypes) eq 'HASH') {
               if (keys(%{$usertypes}) > 0) {
                   $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                                                $dom,$numinrow,$othertitle,
                                                'statustocreate');
                   $$rowtotal ++;
                   $rownum ++;
               }
           }
           $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
     } else {      } else {
         my @contexts = ('author','course','domain');          my @contexts = ('author','course','domain');
         my @authtypes = ('int','krb4','krb5','loc');          my @authtypes = ('int','krb4','krb5','loc');
Line 4013  sub print_usercreation { Line 3797  sub print_usercreation {
     return $datatable;      return $datatable;
 }  }
   
 sub print_selfcreation {  
     my ($position,$dom,$settings,$rowtotal) = @_;  
     my (@selfcreate,$createsettings,$processing,$datatable);  
     if (ref($settings) eq 'HASH') {  
         if (ref($settings->{'cancreate'}) eq 'HASH') {  
             $createsettings = $settings->{'cancreate'};  
             if (ref($createsettings) eq 'HASH') {  
                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {  
                     @selfcreate = @{$createsettings->{'selfcreate'}};  
                 } elsif ($createsettings->{'selfcreate'} ne '') {  
                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {  
                         @selfcreate = ('email','login','sso');  
                     } elsif ($createsettings->{'selfcreate'} ne 'none') {  
                         @selfcreate = ($createsettings->{'selfcreate'});  
                     }  
                 }  
                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {  
                     $processing = $createsettings->{'selfcreateprocessing'};  
                 }  
             }  
         }  
     }  
     my %radiohash;  
     my $numinrow = 4;  
     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;  
     if ($position eq 'top') {  
         my %choices = &Apache::lonlocal::texthash (  
                                                       cancreate_login      => 'Institutional Login',  
                                                       cancreate_sso        => 'Institutional Single Sign On',  
                                                   );  
         my @toggles = sort(keys(%choices));  
         my %defaultchecked = (  
                                'cancreate_login' => 'off',  
                                'cancreate_sso'   => 'off',  
                              );  
         my ($onclick,$itemcount);  
         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,  
                                                      \%choices,$itemcount,$onclick);  
         $$rowtotal += $itemcount;  
           
         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);  
   
         if (ref($usertypes) eq 'HASH') {  
             if (keys(%{$usertypes}) > 0) {  
                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,  
                                              $dom,$numinrow,$othertitle,  
                                              'statustocreate',$$rowtotal);  
                 $$rowtotal ++;  
             }  
         }  
     } elsif ($position eq 'middle') {  
         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);  
         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);  
         $usertypes->{'default'} = $othertitle;  
         if (ref($types) eq 'ARRAY') {  
             push(@{$types},'default');  
             $usertypes->{'default'} = $othertitle;  
             foreach my $status (@{$types}) {  
                 $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},  
                                                        $numinrow,$$rowtotal,$usertypes);  
             $$rowtotal ++;  
             }  
         }  
     } else {  
         my %choices = &Apache::lonlocal::texthash (  
                                                       cancreate_email => 'E-mail address as username',  
                                                   );  
         my @toggles = sort(keys(%choices));  
         my %defaultchecked = (  
                                'cancreate_email' => 'off',  
                              );  
         my $itemcount = 0;  
         my $display = 'none';  
         if (grep(/^\Qemail\E$/,@selfcreate)) {  
             $display = 'block';  
         }  
         my $onclick = "toggleDisplay(this.form,'emailoptions');";  
         my $additional = '<div id="emailoptions" style="display: '.$display.'">';  
         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);  
         my $usertypes = {};  
         my $order = [];  
         if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {  
             $usertypes = $domdefaults{'inststatustypes'};  
             $order = $domdefaults{'inststatusguest'};  
         }  
         if (ref($order) eq 'ARRAY') {  
             push(@{$order},'default');  
             if (@{$order} > 1) {  
                 $usertypes->{'default'} = &mt('Other users');  
                 $additional .= '<table><tr>';  
                 foreach my $status (@{$order}) {  
                     $additional .= '<th>'.$usertypes->{$status}.'</th>';  
                 }  
                 $additional .= '</tr><tr>';  
                 foreach my $status (@{$order}) {  
                     $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';  
                 }  
                 $additional .= '</tr></table>';  
             } else {  
                 $usertypes->{'default'} = &mt('All users');  
                 $additional .= &email_as_username($rowtotal,$processing);  
             }  
         }  
         $additional .= '</div>'."\n";  
   
         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,  
                                                      \%choices,$itemcount,$onclick,$additional);  
         $$rowtotal += $itemcount;  
         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);  
         $$rowtotal ++;  
         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();  
         $numinrow = 1;  
         if (ref($order) eq 'ARRAY') {  
             foreach my $status (@{$order}) {  
                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,  
                                                        $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);  
                 $$rowtotal ++;  
             }  
         }  
         my ($emailrules,$emailruleorder) =  
             &Apache::lonnet::inst_userrules($dom,'email');  
         if (ref($emailrules) eq 'HASH') {  
             if (keys(%{$emailrules}) > 0) {  
                 $datatable .= &user_formats_row('email',$settings,$emailrules,  
                                                 $emailruleorder,$numinrow,$$rowtotal);  
                 $$rowtotal ++;  
             }  
         }  
         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);  
     }  
     return $datatable;  
 }  
   
 sub email_as_username {  
     my ($rowtotal,$processing,$type) = @_;  
     my %choices =  
         &Apache::lonlocal::texthash (  
                                       automatic => 'Automatic approval',  
                                       approval  => 'Queued for approval',  
                                     );  
     my $output;  
     foreach my $option ('automatic','approval') {  
         my $checked;  
         if (ref($processing) eq 'HASH') {  
             if ($type eq '') {     
                 if (!exists($processing->{'default'})) {  
                     if ($option eq 'automatic') {  
                         $checked = ' checked="checked"';  
                     }  
                 } else {  
                     if ($processing->{'default'} eq $option) {  
                         $checked = ' checked="checked"';  
                     }  
                 }  
             } else {  
                 if (!exists($processing->{$type})) {  
                     if ($option eq 'automatic') {  
                         $checked = ' checked="checked"';  
                     }  
                 } else {  
                     if ($processing->{$type} eq $option) {  
                         $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 $output;  
 }  
   
 sub captcha_choice {  sub captcha_choice {
     my ($context,$settings,$itemcount) = @_;      my ($context,$settings,$itemcount) = @_;
     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);      my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
     my %lt = &captcha_phrases();      my %lt = &captcha_phrases();
     $keyentry = 'hidden';      $keyentry = 'hidden';
     if ($context eq 'cancreate') {      if ($context eq 'cancreate') {
         $rowname = &mt('CAPTCHA validation');          $rowname = &mt('CAPTCHA validation (e-mail as username)');
     } elsif ($context eq 'login') {      } elsif ($context eq 'login') {
         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');          $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
     }      }
Line 4319  sub usercreation_types { Line 3917  sub usercreation_types {
                     author     => 'When adding a co-author',                      author     => 'When adding a co-author',
                     course     => 'When adding a user to a course',                      course     => 'When adding a user to a course',
                     requestcrs => 'When requesting a course',                      requestcrs => 'When requesting a course',
                       selfcreate => 'User creates own account', 
                     any        => 'Any',                      any        => 'Any',
                     official   => 'Institutional only ',                      official   => 'Institutional only ',
                     unofficial => 'Non-institutional only',                      unofficial => 'Non-institutional only',
                       email      => 'E-mail address',
                       login      => 'Institutional Login',
                       sso        => 'SSO', 
                     none       => 'None',                      none       => 'None',
     );      );
     return %lt;      return %lt;
 }  }
   
 sub selfcreation_types {  
     my %lt = &Apache::lonlocal::texthash (  
                     selfcreate => 'User creates own account',  
                     any        => 'Any',  
                     official   => 'Institutional only ',  
                     unofficial => 'Non-institutional only',  
                     email      => 'E-mail address',  
                     login      => 'Institutional Login',  
                     sso        => 'SSO',  
              );  
 }  
   
 sub authtype_names {  sub authtype_names {
     my %lt = &Apache::lonlocal::texthash(      my %lt = &Apache::lonlocal::texthash(
                       int    => 'Internal',                        int    => 'Internal',
Line 4371  sub print_usermodification { Line 3961  sub print_usermodification {
             $$rowtotal ++;              $$rowtotal ++;
             $rowcount ++;              $rowcount ++;
         }          }
     } elsif ($position eq 'bottom') {      } elsif ($position eq 'middle') {
         $context = 'course';          $context = 'course';
         $rowcount = 0;          $rowcount = 0;
         foreach my $role ('st','ep','ta','in','cr') {          foreach my $role ('st','ep','ta','in','cr') {
Line 4380  sub print_usermodification { Line 3970  sub print_usermodification {
             $$rowtotal ++;              $$rowtotal ++;
             $rowcount ++;              $rowcount ++;
         }          }
       } elsif ($position eq 'bottom') {
           $context = 'selfcreate';
           my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
           $usertypes->{'default'} = $othertitle;
           if (ref($types) eq 'ARRAY') {
               push(@{$types},'default');
               $usertypes->{'default'} = $othertitle;
               foreach my $status (@{$types}) {
                   $datatable .= &modifiable_userdata_row($context,$status,$settings,
                                                          $numinrow,$rowcount,$usertypes);
                   $$rowtotal ++;
                   $rowcount ++;
               }
           }
     }      }
     return $datatable;      return $datatable;
 }  }
   
 sub print_defaults {  sub print_defaults {
     my ($position,$dom,$settings,$rowtotal) = @_;      my ($dom,$settings,$rowtotal) = @_;
       my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                    'datelocale_def','portal_def');
       my %defaults;
       if (ref($settings) eq 'HASH') {
           %defaults = %{$settings};
       } else {
           my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
           foreach my $item (@items) {
               $defaults{$item} = $domdefaults{$item};
           }
       }
       my $titles = &defaults_titles($dom);
     my $rownum = 0;      my $rownum = 0;
     my ($datatable,$css_class);      my ($datatable,$css_class);
     if ($position eq 'top') {      foreach my $item (@items) {
         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',          if ($rownum%2) {
                      'datelocale_def','portal_def');              $css_class = '';
         my %defaults;  
         if (ref($settings) eq 'HASH') {  
             %defaults = %{$settings};  
         } else {          } else {
             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);              $css_class = ' class="LC_odd_row" ';
             foreach my $item (@items) {  
                 $defaults{$item} = $domdefaults{$item};  
             }  
         }          }
         my $titles = &defaults_titles($dom);          $datatable .= '<tr'.$css_class.'>'.
         foreach my $item (@items) {                    '<td><span class="LC_nobreak">'.$titles->{$item}.
             if ($rownum%2) {                    '</span></td><td class="LC_right_item">';
                 $css_class = '';          if ($item eq 'auth_def') {
             } else {              my @authtypes = ('internal','krb4','krb5','localauth');
                 $css_class = ' class="LC_odd_row" ';              my %shortauth = (
             }                               internal => 'int',
             $datatable .= '<tr'.$css_class.'>'.                               krb4 => 'krb4',
                           '<td><span class="LC_nobreak">'.$titles->{$item}.                               krb5 => 'krb5',
                           '</span></td><td class="LC_right_item" colspan="3">';                               localauth  => 'loc'
             if ($item eq 'auth_def') {                             );
                 my @authtypes = ('internal','krb4','krb5','localauth');              my %authnames = &authtype_names();
                 my %shortauth = (              foreach my $auth (@authtypes) {
                                  internal => 'int',                  my $checked = ' ';
                                  krb4 => 'krb4',                  if ($defaults{$item} eq $auth) {
                                  krb5 => 'krb5',                      $checked = ' checked="checked" ';
                                  localauth  => 'loc'                  }
                                 );                  $datatable .= '<label><input type="radio" name="'.$item.
                 my %authnames = &authtype_names();                                '" value="'.$auth.'"'.$checked.'/>'.
                 foreach my $auth (@authtypes) {                                $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                     my $checked = ' ';  
                     if ($defaults{$item} eq $auth) {  
                         $checked = ' checked="checked" ';  
                     }  
                     $datatable .= '<label><input type="radio" name="'.$item.  
                                   '" value="'.$auth.'"'.$checked.'/>'.  
                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';  
                 }  
             } elsif ($item eq 'timezone_def') {  
                 my $includeempty = 1;  
                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);  
             } elsif ($item eq 'datelocale_def') {  
                 my $includeempty = 1;  
                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);  
             } elsif ($item eq 'lang_def') {  
                 my %langchoices = &get_languages_hash();  
                 $langchoices{''} = 'No language preference';  
                 %langchoices = &Apache::lonlocal::texthash(%langchoices);  
                 $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,  
                                                               \%langchoices);  
             } else {  
                 my $size;  
                 if ($item eq 'portal_def') {  
                     $size = ' size="25"';  
                 }  
                 $datatable .= '<input type="text" name="'.$item.'" value="'.  
                               $defaults{$item}.'"'.$size.' />';  
             }              }
             $datatable .= '</td></tr>';          } elsif ($item eq 'timezone_def') {
             $rownum ++;              my $includeempty = 1;
         }              $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
     } else {          } elsif ($item eq 'datelocale_def') {
         my (%defaults);              my $includeempty = 1;
         if (ref($settings) eq 'HASH') {              $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&          } elsif ($item eq 'lang_def') {
                 (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {              my %langchoices = &get_languages_hash();
                 my $maxnum = @{$settings->{'inststatusorder'}};              $langchoices{''} = 'No language preference';
                 for (my $i=0; $i<$maxnum; $i++) {              %langchoices = &Apache::lonlocal::texthash(%langchoices);
                     $css_class = $rownum%2?' class="LC_odd_row"':'';              $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
                     my $item = $settings->{'inststatusorder'}->[$i];                                                            \%langchoices);
                     my $title = $settings->{'inststatustypes'}->{$item};          } else {
                     my $guestok;              my $size;
                     if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {              if ($item eq 'portal_def') {
                         $guestok = 1;                  $size = ' size="25"';
                     }  
                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';  
                     $datatable .= '<tr'.$css_class.'>'.  
                                   '<td><span class="LC_nobreak">'.  
                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';  
                     for (my $k=0; $k<=$maxnum; $k++) {  
                         my $vpos = $k+1;  
                         my $selstr;  
                         if ($k == $i) {  
                             $selstr = ' selected="selected" ';  
                         }  
                         $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;'.  
                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.  
                                   &mt('delete').'</span></td>'.  
                                   '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').  
                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.  
                                   '</span></td>'.  
                                   '<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"':'';  
                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';  
                 $datatable .= '<tr '.$css_class.'>'.  
                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';  
                 for (my $k=0; $k<=$maxnum; $k++) {  
                     my $vpos = $k+1;  
                     my $selstr;  
                     if ($k == $maxnum) {  
                         $selstr = ' selected="selected" ';  
                     }  
                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';  
                 }  
                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').  
                               '<input type="text" size="10" name="addinststatus" value="" /></span>'.  
                               '&nbsp;'.&mt('(new)').  
                               '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.  
                               &mt('Name displayed:').  
                               '<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";  
                 $rownum ++;  
             }              }
               $datatable .= '<input type="text" name="'.$item.'" value="'.
                             $defaults{$item}.'"'.$size.' />';
         }          }
           $datatable .= '</td></tr>';
           $rownum ++;
     }      }
     $$rowtotal += $rownum;      $$rowtotal += $rownum;
     return $datatable;      return $datatable;
Line 4738  sub print_coursecategories { Line 4269  sub print_coursecategories {
     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;      my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
     my $datatable;      my $datatable;
     if ($position eq 'top') {      if ($position eq 'top') {
         my (%checked);  
         my @catitems = ('unauth','auth');  
         my @cattypes = ('std','domonly','codesrch','none');  
         $checked{'unauth'} = 'std';  
         $checked{'auth'} = 'std';  
         if (ref($settings) eq 'HASH') {  
             foreach my $type (@cattypes) {  
                 if ($type eq $settings->{'unauth'}) {  
                     $checked{'unauth'} = $type;  
                 }  
                 if ($type eq $settings->{'auth'}) {  
                     $checked{'auth'} = $type;  
                 }  
             }  
         }  
         my %lt = &Apache::lonlocal::texthash (  
                                                unauth   => 'Catalog type for unauthenticated users',  
                                                auth     => 'Catalog type for authenticated users',  
                                                none     => 'No catalog',  
                                                std      => 'Standard catalog',  
                                                domonly  => 'Domain-only catalog',  
                                                codesrch => "Code search form",  
                                              );  
        my $itemcount = 0;  
        foreach my $item (@catitems) {  
            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';  
            $datatable .= '<tr '.$css_class.'>'.  
                          '<td>'.$lt{$item}.'</td>'.  
                          '<td class="LC_right_item"><span class="LC_nobreak">';  
            foreach my $type (@cattypes) {  
                my $ischecked;  
                if ($checked{$item} eq $type) {  
                    $ischecked=' checked="checked"';  
                }  
                $datatable .= '<label>'.  
                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.  
                              ' />'.$lt{$type}.'</label>&nbsp;';  
            }  
            $datatable .= '</td></tr>';  
            $itemcount ++;  
         }  
         $$rowtotal += $itemcount;  
     } elsif ($position eq 'middle') {  
         my $toggle_cats_crs = ' ';          my $toggle_cats_crs = ' ';
         my $toggle_cats_dom = ' checked="checked" ';          my $toggle_cats_dom = ' checked="checked" ';
         my $can_cat_crs = ' ';          my $can_cat_crs = ' ';
Line 4987  sub print_coursecategories { Line 4475  sub print_coursecategories {
                 $datatable .= &initialize_categories($itemcount);                  $datatable .= &initialize_categories($itemcount);
             }              }
         } else {          } else {
             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'              $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
                           .&initialize_categories($itemcount);                            .&initialize_categories($itemcount);
         }          }
         $$rowtotal += $itemcount;          $$rowtotal += $itemcount;
Line 5044  sub print_serverstatuses { Line 4532  sub print_serverstatuses {
 sub serverstatus_pages {  sub serverstatus_pages {
     return ('userstatus','lonstatus','loncron','server-status','codeversions',      return ('userstatus','lonstatus','loncron','server-status','codeversions',
             'checksums','clusterstatus','metadata_keywords','metadata_harvest',              'checksums','clusterstatus','metadata_keywords','metadata_harvest',
             'takeoffline','takeonline','showenv','toggledebug','ping','domconf',              'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
             'uniquecodes','diskusage');  
 }  
   
 sub defaults_javascript {  
     my ($settings) = @_;  
     my ($output,$jstext);   
     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {  
         my $maxnum = scalar(@{$settings->{'inststatusorder'}});  
         if ($maxnum eq '') {  
             $maxnum = 0;  
         }  
         $maxnum ++;  
         $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';    
         return <<"ENDSCRIPT";  
 <script type="text/javascript">  
 // <![CDATA[  
 function reorderTypes(form,caller) {  
     var changedVal;  
 $jstext   
     var newpos = 'addinststatus_pos';  
     var current = new Array;  
     var maxh = $maxnum;  
     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;  
     var oldVal;  
     if (caller == newpos) {  
         changedVal = newitemVal;  
     } else {  
         var curritem = 'inststatus_pos_'+caller;  
         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;  
         current[newitemVal] = newpos;  
     }  
     for (var i=0; i<inststatuses.length; i++) {  
         if (inststatuses[i] != caller) {  
             var elementName = 'inststatus_pos_'+inststatuses[i];  
             if (form.elements[elementName]) {  
                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;  
                 current[currVal] = elementName;  
             }  
         }  
     }  
     for (var j=0; j<maxh; j++) {  
         if (current[j] == undefined) {  
             oldVal = j;  
         }  
     }  
     if (oldVal < changedVal) {  
         for (var k=oldVal+1; k<=changedVal ; k++) {  
            var elementName = current[k];  
            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;  
         }  
     } else {  
         for (var k=changedVal; k<oldVal; k++) {  
             var elementName = current[k];  
             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;  
         }  
     }  
     return;  
 }  
   
 // ]]>  
 </script>  
   
 ENDSCRIPT  
     }  
 }  }
   
 sub coursecategories_javascript {  sub coursecategories_javascript {
Line 5133  sub coursecategories_javascript { Line 4557  sub coursecategories_javascript {
         $jstext  = '    var categories = Array(1);'."\n".          $jstext  = '    var categories = Array(1);'."\n".
                    '    categories[0] = Array("instcode_pos");'."\n";                      '    categories[0] = Array("instcode_pos");'."\n"; 
     }      }
     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');      my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');      my $communities_reserved = &mt('The name: "communities" is a reserved category');
     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');       my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
     $output = <<"ENDSCRIPT";      $output = <<"ENDSCRIPT";
 <script type="text/javascript">  <script type="text/javascript">
 // <![CDATA[  // <![CDATA[
Line 5143  function reorderCats(form,parent,item,id Line 4567  function reorderCats(form,parent,item,id
     var changedVal;      var changedVal;
 $jstext  $jstext
     var newpos = 'addcategory_pos';      var newpos = 'addcategory_pos';
       var current = new Array;
     if (parent == '') {      if (parent == '') {
         var has_instcode = 0;          var has_instcode = 0;
         var maxtop = categories[idx].length;          var maxtop = categories[idx].length;
Line 5338  sub build_category_rows { Line 4763  sub build_category_rows {
 }  }
   
 sub modifiable_userdata_row {  sub modifiable_userdata_row {
     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;      my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
     my ($role,$rolename,$statustype);      my $rolename;
     $role = $item;      if ($context eq 'selfcreate') {
     if ($context eq 'cancreate') {  
         if ($item =~ /^emailusername_(.+)$/) {  
             $statustype = $1;  
             $role = 'emailusername';  
             if (ref($usertypes) eq 'HASH') {  
                 if ($usertypes->{$statustype}) {  
                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});  
                 } else {  
                     $rolename = &mt('Data provided by user');  
                 }  
             }  
         }  
     } elsif ($context eq 'selfcreate') {  
         if (ref($usertypes) eq 'HASH') {          if (ref($usertypes) eq 'HASH') {
             $rolename = $usertypes->{$role};              $rolename = $usertypes->{$role};
         } else {          } else {
Line 5366  sub modifiable_userdata_row { Line 4778  sub modifiable_userdata_row {
             $rolename = &Apache::lonnet::plaintext($role);              $rolename = &Apache::lonnet::plaintext($role);
         }          }
     }      }
     my (@fields,%fieldtitles);      my @fields = ('lastname','firstname','middlename','generation',
     if (ref($fieldsref) eq 'ARRAY') {                    'permanentemail','id');
         @fields = @{$fieldsref};      my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
     } else {  
         @fields = ('lastname','firstname','middlename','generation',  
                    'permanentemail','id');  
     }  
     if ((ref($titlesref) eq 'HASH')) {  
         %fieldtitles = %{$titlesref};  
     } else {  
         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();  
     }  
     my $output;      my $output;
     my $css_class = $rowcount%2?' class="LC_odd_row"':'';      my $css_class = $rowcount%2?' class="LC_odd_row"':'';
     $output = '<tr '.$css_class.'>'.      $output = '<tr '.$css_class.'>'.
Line 5388  sub modifiable_userdata_row { Line 4791  sub modifiable_userdata_row {
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
         if (ref($settings->{$context}) eq 'HASH') {          if (ref($settings->{$context}) eq 'HASH') {
             if (ref($settings->{$context}->{$role}) eq 'HASH') {              if (ref($settings->{$context}->{$role}) eq 'HASH') {
                 my $hashref = $settings->{$context}->{$role};                  foreach my $field (@fields) {
                 if ($role eq 'emailusername') {                      if ($settings->{$context}->{$role}->{$field}) {
                     if ($statustype) {                          $checks{$field} = ' checked="checked" ';
                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {  
                             $hashref = $settings->{$context}->{$role}->{$statustype};  
                             if (ref($hashref) eq 'HASH') {   
                                 foreach my $field (@fields) {  
                                     if ($hashref->{$field}) {  
                                         $checks{$field} = $hashref->{$field};  
                                     }  
                                 }  
                             }  
                         }  
                     }  
                 } else {  
                     if (ref($hashref) eq 'HASH') {  
                         foreach my $field (@fields) {  
                             if ($hashref->{$field}) {  
                                 $checks{$field} = ' checked="checked" ';  
                             }  
                         }  
                     }                      }
                 }                  }
             }              }
         }          }
     }      }
        
     for (my $i=0; $i<@fields; $i++) {      for (my $i=0; $i<@fields; $i++) {
         my $rem = $i%($numinrow);          my $rem = $i%($numinrow);
         if ($rem == 0) {          if ($rem == 0) {
Line 5424  sub modifiable_userdata_row { Line 4808  sub modifiable_userdata_row {
             $output .= '<tr>';              $output .= '<tr>';
         }          }
         my $check = ' ';          my $check = ' ';
         unless ($role eq 'emailusername') {          if (exists($checks{$fields[$i]})) {
             if (exists($checks{$fields[$i]})) {              $check = $checks{$fields[$i]}
                 $check = $checks{$fields[$i]}          } else {
             } else {              if ($role eq 'st') {
                 if ($role eq 'st') {                  if (ref($settings) ne 'HASH') {
                     if (ref($settings) ne 'HASH') {                      $check = ' checked="checked" '; 
                         $check = ' checked="checked" ';   
                     }  
                 }                  }
             }              }
         }          }
         $output .= '<td class="LC_left_item">'.          $output .= '<td class="LC_left_item">'.
                    '<span class="LC_nobreak">';                     '<span class="LC_nobreak"><label>'.
         if ($role eq 'emailusername') {                     '<input type="checkbox" name="canmodify_'.$role.'" '.
             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {                     'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                 $checks{$fields[$i]} = 'omit';                     '</label></span></td>';
             }  
             foreach my $option ('required','optional','omit') {  
                 my $checked='';  
                 if ($checks{$fields[$i]} eq $option) {  
                     $checked='checked="checked" ';  
                 }  
                 $output .= '<label>'.  
                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.  
                            &mt($option).'</label>'.('&nbsp;' x2);  
             }  
             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';  
         } else {  
             $output .= '<label>'.  
                        '<input type="checkbox" name="canmodify_'.$role.'" '.  
                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.  
                        '</label>';  
         }  
         $output .= '</span></td>';  
         $rem = @fields%($numinrow);          $rem = @fields%($numinrow);
     }      }
     my $colsleft = $numinrow - $rem;      my $colsleft = $numinrow - $rem;
Line 5472  sub modifiable_userdata_row { Line 4836  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) = @_;
     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)',
Line 5486  sub insttypes_row { Line 4850  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 $output =  '<tr class="LC_odd_row">'.
     if ($rownum ne '') {                     '<td>'.$lt{$context}.$showdom.
         $css_class = ($rownum%2? ' class="LC_odd_row"':'');                    '</td><td class="'.$class.'" colspan="2"><table>';
     }  
     my $output = '<tr'.$css_class.'>'.  
                  '<td>'.$lt{$context}.$showdom.  
                  '</td><td class="'.$class.'" colspan="2"><table>';  
     my $rem;      my $rem;
     if (ref($types) eq 'ARRAY') {      if (ref($types) eq 'ARRAY') {
         for (my $i=0; $i<@{$types}; $i++) {          for (my $i=0; $i<@{$types}; $i++) {
Line 6058  sub modify_colors { Line 5418  sub modify_colors {
         }          }
         if ($role eq 'login') {          if ($role eq 'login') {
             foreach my $item (@logintext) {              foreach my $item (@logintext) {
                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});                  unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'logintext'}{$item}) {
                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {  
                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};  
                 }  
                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {  
                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};                      $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                 }                  }
             }              }
         } else {          } else {
             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});              unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {  
                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};  
             }  
             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {  
                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};                  $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
             }              }
         }          }
         foreach my $item (@bgs) {          foreach my $item (@bgs) {
             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});              unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {  
                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};  
             }  
             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {  
                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};                  $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
             }              }
         }          }
         foreach my $item (@links) {          foreach my $item (@links) {
             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});              unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'links'}{$item}) {
             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {  
                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};  
             }  
             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {  
                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};                  $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
             }              }
         }          }
Line 6711  sub modify_quotas { Line 6055  sub modify_quotas {
     my ($r,$dom,$action,$lastactref,%domconfig) = @_;      my ($r,$dom,$action,$lastactref,%domconfig) = @_;
     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,      my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,          %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,          $author_ok,$switchserver,$errors);
         $validationfieldsref);  
     if ($action eq 'quotas') {      if ($action eq 'quotas') {
         $context = 'tools';           $context = 'tools'; 
     } else {      } else {
Line 6728  sub modify_quotas { Line 6071  sub modify_quotas {
         $confname = $dom.'-domainconfig';          $confname = $dom.'-domainconfig';
         my $servadm = $r->dir_config('lonAdmEMail');          my $servadm = $r->dir_config('lonAdmEMail');
         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);          ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
         ($validationitemsref,$validationnamesref,$validationfieldsref) =   
             &Apache::loncoursequeueadmin::requestcourses_validation_types();  
     } elsif ($context eq 'requestauthor') {      } elsif ($context eq 'requestauthor') {
         @usertools = ('author');          @usertools = ('author');
         %titles = &authorrequest_titles();          %titles = &authorrequest_titles();
Line 6765  sub modify_quotas { Line 6106  sub modify_quotas {
         }          }
     }      }
     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {      if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');          my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
         @approvalnotify = sort(@approvalnotify);          @approvalnotify = sort(@approvalnotify);
         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);          $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
         my @crstypes = ('official','unofficial','community','textbook');          if ($env{'form.uniquecode'}) {
         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');              $confhash{'uniquecode'} = 1;
         foreach my $type (@hasuniquecode) {          } else {
             if (grep(/^\Q$type\E$/,@crstypes)) {              $confhash{'uniquecode'} = '';
                 $confhash{'uniquecode'}{$type} = 1;  
             }  
         }          }
         my ($newbook,@allpos);          my ($newbook,@allpos);
         if ($context eq 'requestcourses') {          if ($context eq 'requestcourses') {
Line 6797  sub modify_quotas { Line 6136  sub modify_quotas {
                                '</span></li>';                                 '</span></li>';
                 }                  }
             }              }
   
         }          }
         if (ref($domconfig{$action}) eq 'HASH') {          if (ref($domconfig{$action}) eq 'HASH') {
             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {              if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
Line 6809  sub modify_quotas { Line 6147  sub modify_quotas {
                     $changes{'notify'}{'approval'} = 1;                      $changes{'notify'}{'approval'} = 1;
                 }                  }
             }              }
             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {              if ($domconfig{$action}{'uniquecode'}) {
                 if (ref($confhash{'uniquecode'}) eq 'HASH') {                  unless ($confhash{'uniquecode'}) {
                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {                      $changes{'uniquecode'} = 1;
                         unless ($confhash{'uniquecode'}{$crstype}) {                  }
                             $changes{'uniquecode'} = 1;              } else {
                         }                  if ($confhash{'uniquecode'}) {
                     }                      $changes{'uniquecode'} = 1;
                     unless ($changes{'uniquecode'}) {                  }
                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {  
                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {  
                                 $changes{'uniquecode'} = 1;  
                             }  
                         }  
                     }  
                } else {  
                    $changes{'uniquecode'} = 1;  
                }  
             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {  
                 $changes{'uniquecode'} = 1;  
             }              }
             if ($context eq 'requestcourses') {              if ($context eq 'requestcourses') {
                 if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {                  if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
Line 6889  sub modify_quotas { Line 6216  sub modify_quotas {
             if ($confhash{'notify'}{'approval'}) {              if ($confhash{'notify'}{'approval'}) {
                 $changes{'notify'}{'approval'} = 1;                  $changes{'notify'}{'approval'} = 1;
             }              }
             if (ref($confhash{'uniquecode'} eq 'HASH')) {              if ($confhash{'uniquecode'}) {
                 $changes{'uniquecode'} = 1;                  $changes{'uniquecode'} = 1;
             }              }
         }          }
Line 6904  sub modify_quotas { Line 6231  sub modify_quotas {
                 }                  }
                 if ($env{'form.addbook_image.filename'} ne '') {                  if ($env{'form.addbook_image.filename'} ne '') {
                     my ($cdom,$cnum) = split(/_/,$newbook);                      my ($cdom,$cnum) = split(/_/,$newbook);
                     my ($imageurl,$error) =                      my ($imageurl,$error) = 
                         &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,                          &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
                                                 $switchserver,$author_ok);                                                  $switchserver,$author_ok);
                     if ($imageurl) {                      if ($imageurl) {
Line 6934  sub modify_quotas { Line 6261  sub modify_quotas {
                     }                      }
                 }                  }
             }              }
             if (ref($validationitemsref) eq 'ARRAY') {  
                 foreach my $item (@{$validationitemsref}) {  
                     if ($item eq 'fields') {  
                         my @changed;  
                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);  
                         if (@{$confhash{'validation'}{$item}} > 0) {  
                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});  
                         }  
                         if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {  
                             if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {  
                                 @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},  
                                                                               $domconfig{'requestcourses'}{'validation'}{$item});  
                             } else {  
                                 @changed = @{$confhash{'validation'}{$item}};  
                             }  
                         } else {  
                             @changed = @{$confhash{'validation'}{$item}};  
                         }  
                         if (@changed) {  
                             if ($confhash{'validation'}{$item}) {  
                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});  
                             } else {  
                                 $changes{'validation'}{$item} = &mt('None');  
                             }  
                         }  
                     } else {  
                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};  
                         if ($item eq 'markup') {  
                             if ($env{'form.requestcourses_validation_'.$item}) {  
                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;  
                             }  
                         }  
                         if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {  
                             if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {  
                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};  
                             }  
                         } else {  
                             if ($confhash{'validation'}{$item} ne '') {  
                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};  
                             }  
                         }  
                     }  
                 }  
             }  
             if ($env{'form.validationdc'}) {  
                 my $newval = $env{'form.validationdc'};  
                 my %domcoords = &get_active_dcs($dom);  
                 if (exists($domcoords{$newval})) {  
                     $confhash{'validation'}{'dc'} = $newval;  
                 }  
             }  
             if (ref($confhash{'validation'}) eq 'HASH') {  
                 if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {  
                     if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {  
                         unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {  
                             if ($confhash{'validation'}{'dc'} eq '') {  
                                 $changes{'validation'}{'dc'} = &mt('None');  
                             } else {  
                                 $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};  
                             }  
                         }  
                     } elsif ($confhash{'validation'}{'dc'} ne '') {  
                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};  
                     }  
                 } elsif ($confhash{'validation'}{'dc'} ne '') {  
                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};  
                 }  
             } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {  
                 if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {  
                     $changes{'validation'}{'dc'} = &mt('None');  
                 }  
             }  
         }          }
     } else {      } else {
         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};          $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
Line 7182  sub modify_quotas { Line 6437  sub modify_quotas {
                     $resulttext .= '</ul></li>';                      $resulttext .= '</ul></li>';
                 }                  }
                 if (ref($changes{'authorquota'}) eq 'HASH') {                  if (ref($changes{'authorquota'}) eq 'HASH') {
                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';                      $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
                     foreach my $type (@{$types},'default') {                      foreach my $type (@{$types},'default') {
                         if (defined($changes{'authorquota'}{$type})) {                          if (defined($changes{'authorquota'}{$type})) {
                             my $typetitle = $usertypes->{$type};                              my $typetitle = $usertypes->{$type};
Line 7289  sub modify_quotas { Line 6544  sub modify_quotas {
             if ($action eq 'requestcourses') {              if ($action eq 'requestcourses') {
                 my @offon = ('off','on');                  my @offon = ('off','on');
                 if ($changes{'uniquecode'}) {                  if ($changes{'uniquecode'}) {
                     if (ref($confhash{'uniquecode'}) eq 'HASH') {                      $resulttext .= '<li>'.
                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));                                     &mt('Generation of six character code as course identifier for distribution to students set to '.
                         $resulttext .= '<li>'.                                         $offon[$env{'form.uniquecode'}]).
                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').                                     '</li>';
                                        '</li>';  
                     } else {  
                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').  
                                        '</li>';  
                     }  
                 }                  }
                 if (ref($changes{'textbooks'}) eq 'HASH') {                  if (ref($changes{'textbooks'}) eq 'HASH') {
                     $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';                      $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
Line 7321  sub modify_quotas { Line 6571  sub modify_quotas {
                     }                      }
                     $resulttext .= '</ul></li>';                      $resulttext .= '</ul></li>';
                 }                  }
                 if (ref($changes{'validation'}) eq 'HASH') {  
                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {  
                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';  
                         foreach my $item (@{$validationitemsref}) {  
                             if (exists($changes{'validation'}{$item})) {  
                                 if ($item eq 'markup') {  
                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},  
                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';  
                                 } else {  
                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},  
                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';  
                                 }  
                             }  
                         }  
                         if (exists($changes{'validation'}{'dc'})) {  
                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',  
                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';  
                         }  
                     }  
                 }  
             }              }
             $resulttext .= '</ul>';              $resulttext .= '</ul>';
             if (keys(%newenv)) {              if (keys(%newenv)) {
Line 8085  sub modify_contacts { Line 7315  sub modify_contacts {
   
 sub modify_usercreation {  sub modify_usercreation {
     my ($dom,%domconfig) = @_;      my ($dom,%domconfig) = @_;
     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);      my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
     my $warningmsg;      my $warningmsg;
     if (ref($domconfig{'usercreation'}) eq 'HASH') {      if (ref($domconfig{'usercreation'}) eq 'HASH') {
         foreach my $key (keys(%{$domconfig{'usercreation'}})) {          foreach my $key (keys(%{$domconfig{'usercreation'}})) {
             if ($key eq 'cancreate') {              $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {  
                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {  
                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||  
                             ($item eq 'captcha') || ($item eq 'recaptchakeys')) {  
                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};  
                         } else {  
                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};  
                         }  
                     }  
                 }  
             } elsif ($key eq 'email_rule') {  
                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};  
             } else {  
                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};  
             }  
         }          }
     }      }
     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');      my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');      my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
     my @contexts = ('author','course','requestcrs');      my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
       my @contexts = ('author','course','requestcrs','selfcreate');
     foreach my $item(@contexts) {      foreach my $item(@contexts) {
         $cancreate{$item} = $env{'form.can_createuser_'.$item};          if ($item eq 'selfcreate') {
               @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
               my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
               if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
                   if (ref($cancreate{$item}) eq 'ARRAY') { 
                       if (grep(/^login$/,@{$cancreate{$item}})) {
                           $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.').' '.&mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');   
                       }
                   }
               }
           } else {
               $cancreate{$item} = $env{'form.can_createuser_'.$item};
           }
     }      }
       my ($othertitle,$usertypes,$types) = 
           &Apache::loncommon::sorted_inst_types($dom);
       if (ref($types) eq 'ARRAY') {
           if (@{$types} > 0) {
               @{$cancreate{'statustocreate'}} = 
                   &Apache::loncommon::get_env_multiple('form.statustocreate');
           } else {
               @{$cancreate{'statustocreate'}} = ();
           }
           push(@contexts,'statustocreate');
       }
       &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {      if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
         foreach my $item (@contexts) {          foreach my $item (@contexts) {
             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {              if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
                 push(@{$changes{'cancreate'}},$item);                  if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                       foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                           if (ref($cancreate{$item}) eq 'ARRAY') {
                               if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                                   if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                       push(@{$changes{'cancreate'}},$item);
                                   }
                               }
                           }
                       }
                   } else {
                       if ($curr_usercreation{'cancreate'}{$item} eq '') {
                           if (@{$cancreate{$item}} > 0) {
                               if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                   push(@{$changes{'cancreate'}},$item);
                               }
                           }
                       } else {
                           if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
                               if (@{$cancreate{$item}} < 3) {
                                   if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                       push(@{$changes{'cancreate'}},$item);
                                   }
                               }
                           } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
                               if (@{$cancreate{$item}} > 0) {
                                   if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                       push(@{$changes{'cancreate'}},$item);
                                   }
                               }
                           } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
                               if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                   push(@{$changes{'cancreate'}},$item);
                               }
                           }
                       }
                   }
                   if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                       foreach my $type (@{$cancreate{$item}}) {
                           if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                               if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                                   if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                       push(@{$changes{'cancreate'}},$item);
                                   }
                               }
                           } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
                                    ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
                               if ($curr_usercreation{'cancreate'}{$item} ne $type) {
                                   if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                       push(@{$changes{'cancreate'}},$item);
                                   }
                               }
                           }
                       }
                   }
               } else {
                   if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                       push(@{$changes{'cancreate'}},$item);
                   }
             }              }
         }          }
     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {      } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
Line 8167  sub modify_usercreation { Line 7465  sub modify_usercreation {
         push(@{$changes{'id_rule'}},@id_rule);          push(@{$changes{'id_rule'}},@id_rule);
     }      }
   
       if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
           foreach my $type (@{$curr_usercreation{'email_rule'}}) {
               if (!grep(/^\Q$type\E$/,@email_rule)) {
                   push(@{$changes{'email_rule'}},$type);
               }
           }
           foreach my $type (@email_rule) {
               if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   push(@{$changes{'email_rule'}},$type);
               }
           }
       } else {
           push(@{$changes{'email_rule'}},@email_rule);
       }
   
     my @authen_contexts = ('author','course','domain');      my @authen_contexts = ('author','course','domain');
     my @authtypes = ('int','krb4','krb5','loc');      my @authtypes = ('int','krb4','krb5','loc');
     my %authhash;      my %authhash;
Line 8197  sub modify_usercreation { Line 7510  sub modify_usercreation {
         }          }
     }      }
   
     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};   
     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};  
     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};  
     $save_usercreate{'id_rule'} = \@id_rule;  
     $save_usercreate{'username_rule'} = \@username_rule,  
     $save_usercreate{'authtypes'} = \%authhash;  
   
     my %usercreation_hash =  (      my %usercreation_hash =  (
         usercreation     => \%save_usercreate,              usercreation => {
     );                                cancreate     => \%cancreate,
                                 username_rule => \@username_rule,
                                 id_rule       => \@id_rule,
                                 email_rule    => \@email_rule,
                                 authtypes     => \%authhash,
                               }
               );
   
     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,      my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                                              $dom);                                               $dom);
   
     if ($putresult eq 'ok') {  
         if (keys(%changes) > 0) {  
             $resulttext = &mt('Changes made:').'<ul>';  
             if (ref($changes{'cancreate'}) eq 'ARRAY') {  
                 my %lt = &usercreation_types();  
                 foreach my $type (@{$changes{'cancreate'}}) {  
                     my $chgtext = $lt{$type}.', ';  
                     if ($cancreate{$type} eq 'none') {  
                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');  
                     } elsif ($cancreate{$type} eq 'any') {  
                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');  
                     } elsif ($cancreate{$type} eq 'official') {  
                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');  
                     } elsif ($cancreate{$type} eq 'unofficial') {  
                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');  
                     }  
                     $resulttext .= '<li>'.$chgtext.'</li>';  
                 }  
             }  
             if (ref($changes{'username_rule'}) eq 'ARRAY') {  
                 my ($rules,$ruleorder) =   
                     &Apache::lonnet::inst_userrules($dom,'username');  
                 my $chgtext = '<ul>';  
                 foreach my $type (@username_rule) {  
                     if (ref($rules->{$type}) eq 'HASH') {  
                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';  
                     }  
                 }  
                 $chgtext .= '</ul>';  
                 if (@username_rule > 0) {  
                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';       
                 } else {  
                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';   
                 }  
             }  
             if (ref($changes{'id_rule'}) eq 'ARRAY') {  
                 my ($idrules,$idruleorder) =   
                     &Apache::lonnet::inst_userrules($dom,'id');  
                 my $chgtext = '<ul>';  
                 foreach my $type (@id_rule) {  
                     if (ref($idrules->{$type}) eq 'HASH') {  
                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';  
                     }  
                 }  
                 $chgtext .= '</ul>';  
                 if (@id_rule > 0) {  
                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';  
                 } else {  
                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';  
                 }  
             }  
             my %authname = &authtype_names();  
             my %context_title = &context_names();  
             if (ref($changes{'authtypes'}) eq 'ARRAY') {  
                 my $chgtext = '<ul>';  
                 foreach my $type (@{$changes{'authtypes'}}) {  
                     my @allowed;  
                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');  
                     foreach my $auth (@authtypes) {  
                         if ($authhash{$type}{$auth}) {  
                             push(@allowed,$authname{$auth});  
                         }  
                     }  
                     if (@allowed > 0) {  
                         $chgtext .= join(', ',@allowed).'</li>';  
                     } else {  
                         $chgtext .= &mt('none').'</li>';  
                     }  
                 }  
                 $chgtext .= '</ul>';  
                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;  
                 $resulttext .= '</li>';  
             }  
             $resulttext .= '</ul>';  
         } else {  
             $resulttext = &mt('No changes made to user creation settings');  
         }  
     } else {  
         $resulttext = '<span class="LC_error">'.  
             &mt('An error occurred: [_1]',$putresult).'</span>';  
     }  
     if ($warningmsg ne '') {  
         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';  
     }  
     return $resulttext;  
 }  
   
 sub modify_selfcreation {  
     my ($dom,%domconfig) = @_;  
     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);  
     my (%save_usercreate,%save_usermodify);  
     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);  
     if (ref($types) eq 'ARRAY') {  
         $usertypes->{'default'} = $othertitle;  
         push(@{$types},'default');  
     }  
 #  
 # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.  
 #  
     if (ref($domconfig{'usercreation'}) eq 'HASH') {  
         foreach my $key (keys(%{$domconfig{'usercreation'}})) {  
             if ($key eq 'cancreate') {  
                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {  
                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {  
                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||  
                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||   
                             ($item eq 'emailusername') || ($item eq 'notify') ||  
                             ($item eq 'selfcreateprocessing')) {  
                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};  
                         } else {  
                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};  
                         }  
                     }  
                 }  
             } elsif ($key eq 'email_rule') {  
                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};  
             } else {  
                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};  
             }  
         }  
     }  
 #  
 # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.  
 #  
     if (ref($domconfig{'usermodification'}) eq 'HASH') {  
         foreach my $key (keys(%{$domconfig{'usermodification'}})) {  
             if ($key eq 'selfcreate') {  
                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};  
             } else {  
                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};  
             }  
         }  
     }  
   
     my @contexts = ('selfcreate');  
     @{$cancreate{'selfcreate'}} = ();  
     %{$cancreate{'emailusername'}} = ();  
     @{$cancreate{'statustocreate'}} = ();  
     %{$cancreate{'selfcreateprocessing'}} = ();  
     my %selfcreatetypes = (      my %selfcreatetypes = (
                              sso   => 'users authenticated by institutional single sign on',                               sso   => 'users authenticated by institutional single sign on',
                              login => 'users authenticated by institutional log-in',                               login => 'users authenticated by institutional log-in',
                              email => 'users who provide a valid e-mail address for use as username',                               email => 'users who provide a valid e-mail address for use as the username',
                           );                            );
 #  
 # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts  
 # is permitted.  
 #  
   
     my @statuses;  
     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') {  
         if ($item eq 'email') {  
             if ($env{'form.cancreate_email'}) {  
                 push(@{$cancreate{'selfcreate'}},'email');  
                 push(@contexts,'selfcreateprocessing');  
                 foreach my $type (@statuses) {  
                     if ($type eq 'default') {  
                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};  
                     } else {   
                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};  
                     }  
                 }  
             }  
         } else {  
             if ($env{'form.cancreate_'.$item}) {  
                 push(@{$cancreate{'selfcreate'}},$item);  
             }  
         }  
     }  
     my (@email_rule,%userinfo,%savecaptcha);  
     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();  
 #  
 # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data  
 # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.  
 #  
   
     if ($env{'form.cancreate_email'} eq 'email') {  
         push(@contexts,'emailusername');  
         if (ref($types) eq 'ARRAY') {  
             foreach my $type (@{$types}) {  
                 if (ref($infofields) eq 'ARRAY') {  
                     foreach my $field (@{$infofields}) {  
                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {  
                             $cancreate{'emailusername'}{$type}{$field} = $1;  
                         }  
                     }  
                 }  
             }  
         }  
 #  
 # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of  
 # queued requests for self-creation of account using e-mail address as username  
 #  
   
         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');  
         @approvalnotify = sort(@approvalnotify);  
         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);  
         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {  
             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {  
                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {  
                     push(@{$changes{'cancreate'}},'notify');  
                 }  
             } else {  
                 if ($cancreate{'notify'}{'approval'}) {  
                     push(@{$changes{'cancreate'}},'notify');  
                 }  
             }  
         } elsif ($cancreate{'notify'}{'approval'}) {  
             push(@{$changes{'cancreate'}},'notify');  
         }  
   
 #  
 # Retrieve rules (if any) governing types of e-mail address which may be used as a username  
 #  
         @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');  
         &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  
 # institutional log-in.  
 #  
     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {  
         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);  
         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||   
                ($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.').' '.  
                           &mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');  
         }  
     }  
     my @fields = ('lastname','firstname','middlename','generation',  
                   'permanentemail','id');  
     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();  
 #  
 # Where usernames may created for institutional log-in and/or institutional single sign on:  
 # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who  
 # may self-create accounts   
 # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields  
 # which the user may supply, if institutional data is unavailable.  
 #  
     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {  
         if (ref($types) eq 'ARRAY') {  
             if (@{$types} > 1) {  
                 @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');  
                 push(@contexts,'statustocreate');  
             } else {  
                 undef($cancreate{'statustocreate'});  
             }   
             foreach my $type (@{$types}) {  
                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);  
                 foreach my $field (@fields) {  
                     if (grep(/^\Q$field\E$/,@modifiable)) {  
                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;  
                     } else {  
                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;  
                     }  
                 }  
             }  
             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {  
                 foreach my $type (@{$types}) {  
                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {  
                         foreach my $field (@fields) {  
                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne  
                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {  
                                 push(@{$changes{'selfcreate'}},$type);  
                                 last;  
                             }  
                         }  
                     }  
                 }  
             } else {  
                 foreach my $type (@{$types}) {  
                     push(@{$changes{'selfcreate'}},$type);  
                 }  
             }  
         }  
     }  
     foreach my $item (@contexts) {  
         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {  
             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {  
                 if (ref($cancreate{$item}) eq 'ARRAY') {  
                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {  
                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                             push(@{$changes{'cancreate'}},$item);  
                         }  
                     }  
                 }  
             }  
             if (ref($cancreate{$item}) eq 'ARRAY') {  
                 foreach my $type (@{$cancreate{$item}}) {  
                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {  
                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                             push(@{$changes{'cancreate'}},$item);  
                         }  
                     }  
                 }  
             }  
         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {  
             if (ref($cancreate{$item}) eq 'HASH') {  
                 foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {  
                     if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {  
                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {  
                             unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {  
                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                                     push(@{$changes{'cancreate'}},$item);  
                                 }  
                             }  
                         }  
                     } elsif ($item eq 'selfcreateprocessing') {  
                         if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {  
                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                                 push(@{$changes{'cancreate'}},$item);  
                             }  
                         }  
                     } else {  
                         if (!$cancreate{$item}{$curr}) {  
                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                                 push(@{$changes{'cancreate'}},$item);  
                             }  
                         }  
                     }  
                 }  
                 foreach my $field (keys(%{$cancreate{$item}})) {  
                     if (ref($cancreate{$item}{$field}) eq 'HASH') {  
                         foreach my $inner (keys(%{$cancreate{$item}{$field}})) {  
                             if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {  
                                 unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {  
                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                                         push(@{$changes{'cancreate'}},$item);  
                                     }  
                                 }  
                             } else {  
                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                                     push(@{$changes{'cancreate'}},$item);  
                                 }  
                             }  
                         }  
                     } elsif ($item eq 'selfcreateprocessing') {  
                         if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {  
                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                                 push(@{$changes{'cancreate'}},$item);  
                             }  
                         }  
                     } else {  
                         if (!$curr_usercreation{'cancreate'}{$item}{$field}) {  
                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                                 push(@{$changes{'cancreate'}},$item);  
                             }  
                         }  
                     }  
                 }  
             }  
         } elsif ($curr_usercreation{'cancreate'}{$item}) {  
             if (ref($cancreate{$item}) eq 'ARRAY') {  
                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {  
                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                         push(@{$changes{'cancreate'}},$item);  
                     }  
                 }  
             } elsif (ref($cancreate{$item}) eq 'HASH') {  
                 if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {  
                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                         push(@{$changes{'cancreate'}},$item);  
                     }  
                 }  
             }  
         } elsif ($item eq 'emailusername') {  
             if (ref($cancreate{$item}) eq 'HASH') {  
                 foreach my $type (keys(%{$cancreate{$item}})) {  
                     if (ref($cancreate{$item}{$type}) eq 'HASH') {  
                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {  
                             if ($cancreate{$item}{$type}{$field}) {  
                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {  
                                     push(@{$changes{'cancreate'}},$item);  
                                 }  
                                 last;  
                             }  
                         }  
                     }  
                 }  
             }  
         }  
     }  
 #  
 # Populate %save_usercreate hash with updates to self-creation configuration.  
 #  
     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};  
     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};  
     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};  
     if (ref($cancreate{'notify'}) eq 'HASH') {  
         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};  
     }  
     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {  
         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};  
     }  
     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {  
         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};  
     }  
     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};  
     $save_usercreate{'emailrule'} = \@email_rule;  
   
     my %userconfig_hash = (  
             usercreation     => \%save_usercreate,  
             usermodification => \%save_usermodify,  
     );  
     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,  
                                              $dom);  
 #  
 # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext  
 #  
     if ($putresult eq 'ok') {      if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {          if (keys(%changes) > 0) {
             $resulttext = &mt('Changes made:').'<ul>';              $resulttext = &mt('Changes made:').'<ul>';
             if (ref($changes{'cancreate'}) eq 'ARRAY') {              if (ref($changes{'cancreate'}) eq 'ARRAY') {
                 my %lt = &selfcreation_types();                  my %lt = &usercreation_types();
                 foreach my $type (@{$changes{'cancreate'}}) {                  foreach my $type (@{$changes{'cancreate'}}) {
                     my $chgtext;                      my $chgtext;
                       unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
                           $chgtext = $lt{$type}.', ';
                       }
                     if ($type eq 'selfcreate') {                      if ($type eq 'selfcreate') {
                         if (@{$cancreate{$type}} == 0) {                          if (@{$cancreate{$type}} == 0) {
                             $chgtext .= &mt('Self creation of a new user account is not permitted.');                              $chgtext .= &mt('creation of a new user account is not permitted.');
                         } else {                          } else {
                             $chgtext .= &mt('Self-creation of a new account is permitted for:').                              $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
                                         '<ul>';  
                             foreach my $case (@{$cancreate{$type}}) {                              foreach my $case (@{$cancreate{$type}}) {
                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';                                  $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                             }                              }
Line 8666  sub modify_selfcreation { Line 7551  sub modify_selfcreation {
                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {                                  if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {                                      if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                                         if (@{$cancreate{'statustocreate'}} == 0) {                                          if (@{$cancreate{'statustocreate'}} == 0) {
                                             $chgtext .= '<br />'.                                              $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                                                         '<span class="LC_warning">'.  
                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").  
                                                         '</span>';  
                                         }                                          }
                                     }                                      }
                                 }                                  }
Line 8680  sub modify_selfcreation { Line 7562  sub modify_selfcreation {
                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {                              (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                             if (@{$cancreate{'selfcreate'}} > 0) {                              if (@{$cancreate{'selfcreate'}} > 0) {
                                 if (@{$cancreate{'statustocreate'}} == 0) {                                  if (@{$cancreate{'statustocreate'}} == 0) {
   
                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");                                      $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {                                      if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
                                         $chgtext .= '<br />'.                                          $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                                                     '<span class="LC_warning">'.                                      } 
                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").  
                                                     '</span>';  
                                     }  
                                 } elsif (ref($usertypes) eq 'HASH') {                                  } elsif (ref($usertypes) eq 'HASH') {
                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {                                      if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');                                          $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
Line 8703  sub modify_selfcreation { Line 7583  sub modify_selfcreation {
                                     }                                      }
                                     $chgtext .= '</ul>';                                      $chgtext .= '</ul>';
                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {                                      if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
                                         $chgtext .= '<br /><span class="LC_warning">'.                                          $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').  
                                                     '</span>';  
                                     }                                      }
                                 }                                  }
                             } else {                              } else {
Line 8716  sub modify_selfcreation { Line 7594  sub modify_selfcreation {
                                 }                                  }
                             }                              }
                         }                          }
                     } elsif ($type eq 'selfcreateprocessing') {  
                         my %choices = &Apache::lonlocal::texthash (  
                                                                     automatic => 'Automatic approval',  
                                                                     approval  => 'Queued for approval',  
                                                                   );  
                         if (@statuses > 1) {  
                             $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').   
                                         '<ul>';  
                            foreach my $type (@statuses) {  
                                if ($type eq 'default') {  
                                    $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';  
                                } else {  
                                    $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';  
                                }  
                            }  
                            $chgtext .= '</ul>';  
                         } else {  
                            $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',  
                                          $choices{$cancreate{'selfcreateprocessing'}{'default'}});  
                         }  
                     } elsif ($type eq 'captcha') {                      } elsif ($type eq 'captcha') {
                         if ($savecaptcha{$type} eq 'notused') {                          if ($cancreate{$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.');
                         } else {                          } else {
                             my %captchas = &captcha_phrases();                              my %captchas = &captcha_phrases();
                             if ($captchas{$savecaptcha{$type}}) {                              if ($captchas{$cancreate{$type}}) {
                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");                                  $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
                             } else {                              } else {
                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');                                  $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
                             }                              }
                         }                          }
                     } elsif ($type eq 'recaptchakeys') {                      } elsif ($type eq 'recaptchakeys') {
                         my ($privkey,$pubkey);                          my ($privkey,$pubkey);
                         if (ref($savecaptcha{$type}) eq 'HASH') {                          if (ref($cancreate{$type}) eq 'HASH') {
                             $pubkey = $savecaptcha{$type}{'public'};                              $pubkey = $cancreate{$type}{'public'};
                             $privkey = $savecaptcha{$type}{'private'};                              $privkey = $cancreate{$type}{'private'};
                         }                          }
                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';                          $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                         if (!$pubkey) {                          if (!$pubkey) {
Line 8765  sub modify_selfcreation { Line 7623  sub modify_selfcreation {
                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';                              $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                         }                          }
                         $chgtext .= '</ul>';                          $chgtext .= '</ul>';
                     } elsif ($type eq 'emailusername') {                      } else {
                         if (ref($cancreate{'emailusername'}) eq 'HASH') {                          if ($cancreate{$type} eq 'none') {
                             if (ref($types) eq 'ARRAY') {                              $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                                 foreach my $type (@{$types}) {                          } elsif ($cancreate{$type} eq 'any') {
                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {                              $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {                          } elsif ($cancreate{$type} eq 'official') {
                                             $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).                              $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                                                     '<ul>';                          } elsif ($cancreate{$type} eq 'unofficial') {
                                             foreach my $field (@{$infofields}) {                              $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                                                 if ($cancreate{'emailusername'}{$type}{$field}) {  
                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';  
                                                 }  
                                             }  
                                         }  
                                         $chgtext .= '</ul>';  
                                     } else {  
                                         $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',$usertypes->{$type}).'<br />';  
                                     }  
                                 }  
                             }  
                         }  
                     } elsif ($type eq 'notify') {  
                         $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');  
                         if (ref($changes{'cancreate'}) eq 'ARRAY') {  
                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {  
                                 if ($cancreate{'notify'}{'approval'}) {  
                                     $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};  
                                 }  
                             }  
                         }                          }
                     }                      }
                     if ($chgtext) {                      $resulttext .= '<li>'.$chgtext.'</li>';
                         $resulttext .= '<li>'.$chgtext.'</li>';                  }
               }
               if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   my ($rules,$ruleorder) = 
                       &Apache::lonnet::inst_userrules($dom,'username');
                   my $chgtext = '<ul>';
                   foreach my $type (@username_rule) {
                       if (ref($rules->{$type}) eq 'HASH') {
                           $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                       }
                   }
                   $chgtext .= '</ul>';
                   if (@username_rule > 0) {
                       $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   } else {
                       $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   }
               }
               if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   my ($idrules,$idruleorder) = 
                       &Apache::lonnet::inst_userrules($dom,'id');
                   my $chgtext = '<ul>';
                   foreach my $type (@id_rule) {
                       if (ref($idrules->{$type}) eq 'HASH') {
                           $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                     }                      }
                 }                  }
                   $chgtext .= '</ul>';
                   if (@id_rule > 0) {
                       $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   } else {
                       $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   }
             }              }
             if (ref($changes{'email_rule'}) eq 'ARRAY') {              if (ref($changes{'email_rule'}) eq 'ARRAY') {
                 my ($emailrules,$emailruleorder) =                  my ($emailrules,$emailruleorder) =
Line 8812  sub modify_selfcreation { Line 7680  sub modify_selfcreation {
                 }                  }
                 $chgtext .= '</ul>';                  $chgtext .= '</ul>';
                 if (@email_rule > 0) {                  if (@email_rule > 0) {
                     $resulttext .= '<li>'.                      $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
                                    &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').  
                                        $chgtext.  
                                    '</li>';  
                 } else {                  } else {
                     $resulttext .= '<li>'.                      $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
                                    &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').  
                                    '</li>';  
                 }                  }
             }              }
             if (ref($changes{'selfcreate'}) eq 'ARRAY') {  
                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';              my %authname = &authtype_names();
                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();              my %context_title = &context_names();
                 foreach my $type (@{$changes{'selfcreate'}}) {              if (ref($changes{'authtypes'}) eq 'ARRAY') {
                     my $typename = $type;                  my $chgtext = '<ul>';
                     if (ref($usertypes) eq 'HASH') {                  foreach my $type (@{$changes{'authtypes'}}) {
                         if ($usertypes->{$type} ne '') {                      my @allowed;
                             $typename = $usertypes->{$type};                      $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                         }                      foreach my $auth (@authtypes) {
                     }                          if ($authhash{$type}{$auth}) {
                     my @modifiable;                              push(@allowed,$authname{$auth});
                     $resulttext .= '<li>'.  
                                     &mt('Self-creation of account by users with status: [_1]',  
                                         '<span class="LC_cusr_emph">'.$typename.'</span>').  
                                     ' - '.&mt('modifiable fields (if institutional data blank): ');  
                     foreach my $field (@fields) {  
                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {  
                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');  
                         }                          }
                     }                      }
                     if (@modifiable > 0) {                      if (@allowed > 0) {
                         $resulttext .= join(', ',@modifiable);                          $chgtext .= join(', ',@allowed).'</li>';
                     } else {                      } else {
                         $resulttext .= &mt('none');                          $chgtext .= &mt('none').'</li>';
                     }                      }
                     $resulttext .= '</li>';  
                 }                  }
                 $resulttext .= '</ul></li>';                  $chgtext .= '</ul>';
                   $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   $resulttext .= '</li>';
             }              }
             $resulttext .= '</ul>';              $resulttext .= '</ul>';
         } else {          } else {
             $resulttext = &mt('No changes made to self-creation settings');              $resulttext = &mt('No changes made to user creation settings');
         }          }
     } else {      } else {
         $resulttext = '<span class="LC_error">'.          $resulttext = '<span class="LC_error">'.
Line 8920  sub process_captcha { Line 7777  sub process_captcha {
   
 sub modify_usermodification {  sub modify_usermodification {
     my ($dom,%domconfig) = @_;      my ($dom,%domconfig) = @_;
     my ($resulttext,%curr_usermodification,%changes,%modifyhash);      my ($resulttext,%curr_usermodification,%changes);
     if (ref($domconfig{'usermodification'}) eq 'HASH') {      if (ref($domconfig{'usermodification'}) eq 'HASH') {
         foreach my $key (keys(%{$domconfig{'usermodification'}})) {          foreach my $key (keys(%{$domconfig{'usermodification'}})) {
             if ($key eq 'selfcreate') {              $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};  
             } else {    
                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};  
             }  
         }          }
     }      }
     my @contexts = ('author','course');      my @contexts = ('author','course','selfcreate');
     my %context_title = (      my %context_title = (
                            author => 'In author context',                             author => 'In author context',
                            course => 'In course context',                             course => 'In course context',
                              selfcreate => 'When self creating account', 
                         );                          );
     my @fields = ('lastname','firstname','middlename','generation',      my @fields = ('lastname','firstname','middlename','generation',
                   'permanentemail','id');                    'permanentemail','id');
Line 8941  sub modify_usermodification { Line 7795  sub modify_usermodification {
                   author => ['ca','aa'],                    author => ['ca','aa'],
                   course => ['st','ep','ta','in','cr'],                    course => ['st','ep','ta','in','cr'],
                 );                  );
       my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
       if (ref($types) eq 'ARRAY') {
           push(@{$types},'default');
           $usertypes->{'default'} = $othertitle;
       }
       $roles{'selfcreate'} = $types;  
     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();      my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
       my %modifyhash;
     foreach my $context (@contexts) {      foreach my $context (@contexts) {
         foreach my $role (@{$roles{$context}}) {          foreach my $role (@{$roles{$context}}) {
             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);              my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
Line 8987  sub modify_usermodification { Line 7848  sub modify_usermodification {
                     if (ref($changes{$context}) eq 'ARRAY') {                      if (ref($changes{$context}) eq 'ARRAY') {
                         foreach my $role (@{$changes{$context}}) {                          foreach my $role (@{$changes{$context}}) {
                             my $rolename;                              my $rolename;
                             if ($role eq 'cr') {                              if ($context eq 'selfcreate') {
                                 $rolename = &mt('Custom');                                  $rolename = $role;
                                   if (ref($usertypes) eq 'HASH') {
                                       if ($usertypes->{$role} ne '') {
                                           $rolename = $usertypes->{$role};
                                       }
                                   }
                             } else {                              } else {
                                 $rolename = &Apache::lonnet::plaintext($role);                                  if ($role eq 'cr') {
                                       $rolename = &mt('Custom');
                                   } else {
                                       $rolename = &Apache::lonnet::plaintext($role);
                                   }
                             }                              }
                             my @modifiable;                              my @modifiable;
                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');                              if ($context eq 'selfcreate') {
                                   $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
                               } else {
                                   $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                               }
                             foreach my $field (@fields) {                              foreach my $field (@fields) {
                                 if ($modifyhash{$context}{$role}{$field}) {                                  if ($modifyhash{$context}{$role}{$field}) {
                                     push(@modifiable,$fieldtitles{$field});                                      push(@modifiable,$fieldtitles{$field});
Line 9079  sub modify_defaults { Line 7953  sub modify_defaults {
                          defaults => \%newvalues,                           defaults => \%newvalues,
                         );                          );
     my $title = &defaults_titles();      my $title = &defaults_titles();
   
     my $currinststatus;  
     if (ref($domconfig{'inststatus'}) eq 'HASH') {  
         $currinststatus = $domconfig{'inststatus'};  
     } else {  
         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);  
         $currinststatus = {  
                              inststatustypes => $usertypes,  
                              inststatusorder => $types,  
                              inststatusguest => [],  
                           };  
     }  
     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');  
     my @allpos;  
     my %guests;  
     my %alltypes;  
     my ($currtitles,$currguests,$currorder);  
     if (ref($currinststatus) eq 'HASH') {  
         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {  
             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {  
                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {  
                     if ($currinststatus->{inststatustypes}->{$type} ne '') {  
                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';  
                     }  
                 }  
                 unless (grep(/^\Q$type\E$/,@todelete)) {   
                     my $position = $env{'form.inststatus_pos_'.$type};  
                     $position =~ s/\D+//g;  
                     $allpos[$position] = $type;  
                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};  
                     $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'}});  
             $currtitles =~ s/,$//;  
         }  
     }  
     if ($env{'form.addinststatus'}) {  
         my $newtype = $env{'form.addinststatus'};  
         $newtype =~ s/\W//g;  
         unless (exists($alltypes{$newtype})) {  
             if ($env{'form.addinststatus_guest'}) {  
                 $guests{$newtype} = 1;  
             }  
             $alltypes{$newtype} = $env{'form.addinststatus_title'};  
             $alltypes{$newtype} =~ s/`//g;   
             my $position = $env{'form.addinststatus_pos'};  
             $position =~ s/\D+//g;  
             if ($position ne '') {  
                 $allpos[$position] = $newtype;  
             }  
         }  
     }  
     my (@orderedstatus,@orderedguests);  
     foreach my $type (@allpos) {  
         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {  
             push(@orderedstatus,$type);  
             if ($guests{$type}) {  
                 push(@orderedguests,$type);  
             }  
         }  
     }  
     foreach my $type (keys(%alltypes)) {  
         unless (grep(/^\Q$type\E$/,@orderedstatus)) {  
             delete($alltypes{$type});  
         }  
     }  
     $defaults_hash{'inststatus'} = {  
                                      inststatustypes => \%alltypes,  
                                      inststatusorder => \@orderedstatus,  
                                      inststatusguest => \@orderedguests,  
                                    };  
     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {  
         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {  
             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};  
         }  
     }  
     if ($currorder ne join(',',@orderedstatus)) {  
         $changes{'inststatus'}{'inststatusorder'} = 1;  
     }  
     if ($currguests ne join(',',@orderedguests)) {  
         $changes{'inststatus'}{'inststatusguest'} = 1;  
     }  
     my $newtitles;  
     foreach my $item (@orderedstatus) {  
         $newtitles .= $alltypes{$item}.',';  
     }  
     $newtitles =~ s/,$//;  
     if ($currtitles ne $newtitles) {  
         $changes{'inststatus'}{'inststatustypes'} = 1;  
     }  
     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,      my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                                              $dom);                                               $dom);
     if ($putresult eq 'ok') {      if ($putresult eq 'ok') {
Line 9184  sub modify_defaults { Line 7961  sub modify_defaults {
             my $version = &Apache::lonnet::get_server_loncaparev($dom);              my $version = &Apache::lonnet::get_server_loncaparev($dom);
             my $mailmsgtext = "Changes made to domain settings in a LON-CAPA installation - domain: $dom (running version: $version) - dns_domain.tab needs to be updated with the following changes, to support legacy 2.4, 2.5 and 2.6 versions of LON-CAPA.\n\n";              my $mailmsgtext = "Changes made to domain settings in a LON-CAPA installation - domain: $dom (running version: $version) - dns_domain.tab needs to be updated with the following changes, to support legacy 2.4, 2.5 and 2.6 versions of LON-CAPA.\n\n";
             foreach my $item (sort(keys(%changes))) {              foreach my $item (sort(keys(%changes))) {
                 if ($item eq 'inststatus') {                  my $value = $env{'form.'.$item};
                     if (ref($changes{'inststatus'}) eq 'HASH') {                  if ($value eq '') {
                         if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {                      $value = &mt('none');
                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';                  } elsif ($item eq 'auth_def') {
                             foreach my $type (@orderedstatus) {                       my %authnames = &authtype_names();
                                 $resulttext .= $alltypes{$type}.', ';                      my %shortauth = (
                             }                               internal => 'int',
                             $resulttext =~ s/, $//;                               krb4 => 'krb4',
                             $resulttext .= '</li>';                               krb5 => 'krb5',
                         }                               localauth  => 'loc',
                         if ($changes{'inststatus'}{'inststatusguest'}) {                      );
                             $resulttext .= '<li>';                       $value = $authnames{$shortauth{$value}};
                             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 {  
                     my $value = $env{'form.'.$item};  
                     if ($value eq '') {  
                         $value = &mt('none');  
                     } elsif ($item eq 'auth_def') {  
                         my %authnames = &authtype_names();  
                         my %shortauth = (  
                                           internal   => 'int',  
                                           krb4       => 'krb4',  
                                           krb5       => 'krb5',  
                                           localauth  => 'loc',  
                         );  
                         $value = $authnames{$shortauth{$value}};  
                     }  
                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';  
                     $mailmsgtext .= "$title->{$item} set to $value\n";    
                 }                  }
                   $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   $mailmsgtext .= "$title->{$item} set to $value\n";  
             }              }
             $resulttext .= '</ul>';              $resulttext .= '</ul>';
             $mailmsgtext .= "\n";              $mailmsgtext .= "\n";
Line 9346  sub modify_scantron { Line 8097  sub modify_scantron {
 }  }
   
 sub modify_coursecategories {  sub modify_coursecategories {
     my ($dom,$lastactref,%domconfig) = @_;      my ($dom,%domconfig) = @_;
     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,      my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
         $cathash);          $cathash);
     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');      my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
     my @catitems = ('unauth','auth');  
     my @cattypes = ('std','domonly','codesrch','none');  
     if (ref($domconfig{'coursecategories'}) eq 'HASH') {      if (ref($domconfig{'coursecategories'}) eq 'HASH') {
         $cathash = $domconfig{'coursecategories'}{'cats'};          $cathash = $domconfig{'coursecategories'}{'cats'};
         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {          if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
Line 9370  sub modify_coursecategories { Line 8119  sub modify_coursecategories {
             $changes{'categorizecomm'} = 1;              $changes{'categorizecomm'} = 1;
             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};              $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
         }          }
         foreach my $item (@catitems) {  
             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {  
                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {  
                     $changes{$item} = 1;  
                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};  
                 }  
             }  
         }  
     } else {      } else {
         $changes{'togglecats'} = 1;          $changes{'togglecats'} = 1;
         $changes{'categorize'} = 1;          $changes{'categorize'} = 1;
Line 9389  sub modify_coursecategories { Line 8130  sub modify_coursecategories {
                                              togglecatscomm => $env{'form.togglecatscomm'},                                               togglecatscomm => $env{'form.togglecatscomm'},
                                              categorizecomm => $env{'form.categorizecomm'},                                               categorizecomm => $env{'form.categorizecomm'},
                                          };                                           };
         foreach my $item (@catitems) {  
             if ($env{'form.coursecat_'.$item} ne 'std') {  
                 $changes{$item} = 1;  
             }  
             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {  
                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};  
             }  
         }  
     }      }
     if (ref($cathash) eq 'HASH') {      if (ref($cathash) eq 'HASH') {
         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {          if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
Line 9519  sub modify_coursecategories { Line 8252  sub modify_coursecategories {
                          dom  => 'set in Domain ("Modify Course/Community")',                           dom  => 'set in Domain ("Modify Course/Community")',
                          crs  => 'set in Course ("Course Configuration")',                           crs  => 'set in Course ("Course Configuration")',
                          comm => 'set in Community ("Community Configuration")',                           comm => 'set in Community ("Community Configuration")',
                          none     => 'No catalog',  
                          std      => 'Standard catalog',  
                          domonly  => 'Domain-only catalog',  
                          codesrch => 'Code search form',  
                         );                          );
             $resulttext = &mt('Changes made:').'<ul>';              $resulttext = &mt('Changes made:').'<ul>';
             if ($changes{'togglecats'}) {              if ($changes{'togglecats'}) {
Line 9537  sub modify_coursecategories { Line 8266  sub modify_coursecategories {
             if ($changes{'categorizecomm'}) {              if ($changes{'categorizecomm'}) {
                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';                  $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
             }              }
             if ($changes{'unauth'}) {  
                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';  
             }  
             if ($changes{'auth'}) {  
                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';  
             }  
             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {              if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                 my $cathash;                  my $cathash;
                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {                  if (ref($domconfig{'coursecategories'}) eq 'HASH') {
Line 9587  sub modify_coursecategories { Line 8310  sub modify_coursecategories {
                 }                  }
             }              }
             $resulttext .= '</ul>';              $resulttext .= '</ul>';
             if ($changes{'unauth'} || $changes{'auth'}) {  
                 &Apache::loncommon::devalidate_domconfig_cache($dom);  
                 if (ref($lastactref) eq 'HASH') {  
                     $lastactref->{'domainconfig'} = 1;  
                 }  
             }  
         } else {          } else {
             $resulttext = '<span class="LC_error">'.              $resulttext = '<span class="LC_error">'.
                           &mt('An error occurred: [_1]',$putresult).'</span>';                            &mt('An error occurred: [_1]',$putresult).'</span>';
Line 9855  sub modify_coursedefaults { Line 8572  sub modify_coursedefaults {
                 }                  }
             }              }
         }          }
   
         my $officialcreds = $env{'form.official_credits'};          my $officialcreds = $env{'form.official_credits'};
         $officialcreds =~ s/[^\d.]+//g;          $officialcreds =~ s/[^\d.]+//g;
         my $unofficialcreds = $env{'form.unofficial_credits'};          my $unofficialcreds = $env{'form.unofficial_credits'};
Line 9883  sub modify_coursedefaults { Line 8599  sub modify_coursedefaults {
     if ($putresult eq 'ok') {      if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {          if (keys(%changes) > 0) {
             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);              my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
             if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||               if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
                 ($changes{'uploadquota'})) {   
                 if ($changes{'canuse_pdfforms'}) {                  if ($changes{'canuse_pdfforms'}) {
                     $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};                      $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
                 }                  }
Line 9964  sub modify_coursedefaults { Line 8679  sub modify_coursedefaults {
     return $resulttext;      return $resulttext;
 }  }
   
 sub modify_selfenrollment {  
     my ($dom,$lastactref,%domconfig) = @_;  
     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);  
     my @types = ('official','unofficial','community','textbook');  
     my %titles = &tool_titles();  
     my %descs = &Apache::lonuserutils::selfenroll_default_descs();  
     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();  
     $ordered{'default'} = ['types','registered','approval','limit'];  
   
     my (%roles,%shown,%toplevel);  
     $roles{'0'} = &Apache::lonnet::plaintext('dc');  
   
     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {  
         if ($domconfig{'selfenrollment'} eq '') {  
             $domconfig{'selfenrollment'} = {};  
         }  
     }  
     %toplevel = (  
                   admin      => 'Configuration Rights',  
                   default    => 'Default settings',  
                   validation => 'Validation of self-enrollment requests',  
                 );  
     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();  
   
     if (ref($ordered{'admin'}) eq 'ARRAY') {  
         foreach my $item (@{$ordered{'admin'}}) {  
             foreach my $type (@types) {  
                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {  
                     $selfenrollhash{'admin'}{$type}{$item} = 1;  
                 } else {  
                     $selfenrollhash{'admin'}{$type}{$item} = 0;  
                 }  
                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {  
                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {  
                         if ($selfenrollhash{'admin'}{$type}{$item} ne  
                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {  
                             push(@{$changes{'admin'}{$type}},$item);  
                         }  
                     } else {  
                         if (!$selfenrollhash{'admin'}{$type}{$item}) {  
                             push(@{$changes{'admin'}{$type}},$item);  
                         }  
                     }  
                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {  
                     push(@{$changes{'admin'}{$type}},$item);  
                 }  
             }  
         }  
     }  
   
     foreach my $item (@{$ordered{'default'}}) {  
         foreach my $type (@types) {  
             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};  
             if ($item eq 'types') {  
                 unless (($value eq 'all') || ($value eq 'dom')) {  
                     $value = '';  
                 }  
             } elsif ($item eq 'registered') {  
                 unless ($value eq '1') {  
                     $value = 0;  
                 }  
             } elsif ($item eq 'approval') {  
                 unless ($value =~ /^[012]$/) {  
                     $value = 0;  
                 }  
             } else {  
                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {  
                     $value = 'none';  
                 }  
             }  
             $selfenrollhash{'default'}{$type}{$item} = $value;  
             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {  
                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {  
                     if ($selfenrollhash{'default'}{$type}{$item} ne  
                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {  
                          push(@{$changes{'default'}{$type}},$item);  
                     }  
                 } else {  
                     push(@{$changes{'default'}{$type}},$item);  
                 }  
             } else {  
                 push(@{$changes{'default'}{$type}},$item);  
             }  
             if ($item eq 'limit') {  
                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {  
                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;  
                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {  
                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};  
                     }  
                 } else {  
                     $selfenrollhash{'default'}{$type}{'cap'} = '';  
                 }  
                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {  
                     if ($selfenrollhash{'default'}{$type}{'cap'} ne  
                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {  
                          push(@{$changes{'default'}{$type}},'cap');  
                     }  
                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {  
                     push(@{$changes{'default'}{$type}},'cap');  
                 }  
             }  
         }  
     }  
   
     foreach my $item (@{$itemsref}) {  
         if ($item eq 'fields') {  
             my @changed;  
             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);  
             if (@{$selfenrollhash{'validation'}{$item}} > 0) {  
                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});  
             }  
             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {  
                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {  
                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},  
                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});  
                 } else {  
                     @changed = @{$selfenrollhash{'validation'}{$item}};  
                 }  
             } else {  
                 @changed = @{$selfenrollhash{'validation'}{$item}};  
             }  
             if (@changed) {  
                 if ($selfenrollhash{'validation'}{$item}) {   
                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});  
                 } else {  
                     $changes{'validation'}{$item} = &mt('None');  
                 }  
             }  
         } else {  
             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};  
             if ($item eq 'markup') {  
                if ($env{'form.selfenroll_validation_'.$item}) {  
                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;  
                }  
             }  
             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {  
                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {  
                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};  
                 }  
             }  
         }  
     }  
   
     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},  
                                              $dom);  
     if ($putresult eq 'ok') {  
         if (keys(%changes) > 0) {  
             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);  
             $resulttext = &mt('Changes made:').'<ul>';  
             foreach my $key ('admin','default','validation') {  
                 if (ref($changes{$key}) eq 'HASH') {  
                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';  
                     if ($key eq 'validation') {  
                         foreach my $item (@{$itemsref}) {  
                             if (exists($changes{$key}{$item})) {  
                                 if ($item eq 'markup') {  
                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},  
                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';  
                                 } else {    
                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},  
                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';  
                                 }  
                             }  
                         }  
                     } else {  
                         foreach my $type (@types) {  
                             if ($type eq 'community') {  
                                 $roles{'1'} = &mt('Community personnel');  
                             } else {  
                                 $roles{'1'} = &mt('Course personnel');  
                             }  
                             if (ref($changes{$key}{$type}) eq 'ARRAY') {  
                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {  
                                     if ($key eq 'admin') {  
                                         my @mgrdc = ();  
                                         if (ref($ordered{$key}) eq 'ARRAY') {  
                                             foreach my $item (@{$ordered{'admin'}}) {  
                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {   
                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {  
                                                         push(@mgrdc,$item);  
                                                     }  
                                                 }  
                                             }  
                                             if (@mgrdc) {  
                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);  
                                             } else {  
                                                 delete($domdefaults{$type.'selfenrolladmdc'});  
                                             }  
                                         }  
                                     } else {  
                                         if (ref($ordered{$key}) eq 'ARRAY') {  
                                             foreach my $item (@{$ordered{$key}}) {  
                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {  
                                                     $domdefaults{$type.'selfenroll'.$item} =  
                                                         $selfenrollhash{$key}{$type}{$item};  
                                                 }  
                                             }  
                                         }  
                                     }  
                                 }  
                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';  
                                 foreach my $item (@{$ordered{$key}}) {  
                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {  
                                         $resulttext .= '<li>';  
                                         if ($key eq 'admin') {  
                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},  
                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');  
                                         } else {  
                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},  
                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');  
                                         }  
                                         $resulttext .= '</li>';  
                                     }  
                                 }  
                                 $resulttext .= '</ul></li>';  
                             }  
                         }  
                         $resulttext .= '</ul></li>';   
                     }  
                 }  
                 if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {  
                     my $cachetime = 24*60*60;  
                     &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);  
                     if (ref($lastactref) eq 'HASH') {  
                         $lastactref->{'domdefaults'} = 1;  
                     }  
                 }  
             }  
             $resulttext .= '</ul>';  
         } else {  
             $resulttext = &mt('No changes made to self-enrollment settings');  
         }  
     } else {  
         $resulttext = '<span class="LC_error">'.  
             &mt('An error occurred: [_1]',$putresult).'</span>';  
     }  
     return $resulttext;  
 }  
   
 sub modify_usersessions {  sub modify_usersessions {
     my ($dom,$lastactref,%domconfig) = @_;      my ($dom,$lastactref,%domconfig) = @_;
     my @hostingtypes = ('version','excludedomain','includedomain');      my @hostingtypes = ('version','excludedomain','includedomain');
Line 10735  sub get_active_dcs { Line 9211  sub get_active_dcs {
   
 sub active_dc_picker {  sub active_dc_picker {
     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;      my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
     my %domcoords = &get_active_dcs($dom);      my %domcoords = &get_active_dcs($dom); 
     my @domcoord = keys(%domcoords);      my @domcoord = keys(%domcoords);
     if (keys(%currhash)) {      if (keys(%currhash)) {
         foreach my $dc (keys(%currhash)) {          foreach my $dc (keys(%currhash)) {
Line 10789  sub active_dc_picker { Line 9265  sub active_dc_picker {
                       '<input type="'.$inputtype.'" name="'.$name.'"'.                        '<input type="'.$inputtype.'" name="'.$name.'"'.
                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;                        ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
             if ($user ne $dcname.':'.$dcdom) {              if ($user ne $dcname.':'.$dcdom) {
                 $table .=  ' ('.$dcname.':'.$dcdom.')';                  $table .=  ' ('.$dcname.':'.$dcdom.')'.
                              '</label></span></td>';
             }              }
             $table .= '</label></span></td>';  
         }          }
         $table .= '</tr></table>';          $table .= '</tr></table>';
     } elsif ($numdcs == 1) {      } elsif ($numdcs == 1) {
         my ($dcname,$dcdom) = split(':',$domcoord[0]);  
         my $user = &Apache::loncommon::plainname($dcname,$dcdom);  
         if ($inputtype eq 'radio') {          if ($inputtype eq 'radio') {
             $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;              $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
             if ($user ne $dcname.':'.$dcdom) {  
                 $table .=  ' ('.$dcname.':'.$dcdom.')';  
             }  
         } else {          } else {
             my $check;              my $check;
             if (exists($currhash{$domcoord[0]})) {              if (exists($currhash{$domcoord[0]})) {
                 $check = ' checked="checked"';                  $check = ' checked="checked"';
             }              }
             $table .= '<span class="LC_nobreak"><label>'.              $table .= '<input type="checkbox" name="'.$name.'" '.
                       '<input type="checkbox" name="'.$name.'" '.                        'value="'.$domcoord[0].'"'.$check.' />';
                       'value="'.$domcoord[0].'"'.$check.' />'.$user;  
             if ($user ne $dcname.':'.$dcdom) {  
                 $table .=  ' ('.$dcname.':'.$dcdom.')';  
             }  
             $table .= '</label></span>';  
             $rows ++;              $rows ++;
         }          }
     }      }
Line 11344  END Line 9810  END
   
 }  }
   
 sub toggle_display_js {  sub credits_js {
     return <<"END";      return <<"END";
   
 <script type="text/javascript">  <script type="text/javascript">
 // <![CDATA[  // <![CDATA[
   
 function toggleDisplay(domForm,caller) {  function toggleCredits(domForm) {
     if (document.getElementById(caller)) {      if (document.getElementById('credits')) {
         var divitem = document.getElementById(caller);          creditsitem = document.getElementById('credits');
         var optionsElement = domForm.coursecredits;          var creditsLength = domForm.coursecredits.length;
         if (caller == 'emailoptions') {          if (creditsLength) {
             optionsElement = domForm.cancreate_email;   
         }  
         if (optionsElement.length) {  
             var currval;              var currval;
             for (var i=0; i<optionsElement.length; i++) {              for (var i=0; i<creditsLength; i++) {
                 if (optionsElement[i].checked) {                  if (domForm.coursecredits[i].checked) {
                    currval = optionsElement[i].value;                     currval = domForm.coursecredits[i].value;
                 }                  }
             }              }
             if (currval == 1) {              if (currval == 1) {
                 divitem.style.display = 'block';                  creditsitem.style.display = 'block';
             } else {              } else {
                 divitem.style.display = 'none';                  creditsitem.style.display = 'none';
             }              }
         }          }
     }      }

Removed from v.1.160.6.43  
changed lines
  Added in v.1.217


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