Diff for /loncom/interface/domainprefs.pm between versions 1.160.6.44 and 1.256

version 1.160.6.44, 2014/05/05 21:40:52 version 1.256, 2015/03/03 22:06:50
Line 213  sub handler { Line 213  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','selfenrollment','inststatus'],$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','selfcreation','usermodification','scantron',
                        'requestcourses','requestauthor','coursecategories',                         'requestcourses','requestauthor','coursecategories',
                        'serverstatuses','coursedefaults','selfenrollment',                         'serverstatuses','helpsettings',
                        'usersessions');                         'coursedefaults','selfenrollment','usersessions');
     my %existing;      my %existing;
     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {      if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
         %existing = %{$domconfig{'loadbalancing'}};          %existing = %{$domconfig{'loadbalancing'}};
Line 250  sub handler { Line 250  sub handler {
                       header => [{col1 => 'Log-in Page Items',                        header => [{col1 => 'Log-in Page Items',
                                   col2 => '',},                                    col2 => '',},
                                  {col1 => 'Log-in Help',                                   {col1 => 'Log-in Help',
                                     col2 => 'Value'},
                                    {col1 => 'Custom HTML in document head',
                                   col2 => 'Value'}],                                    col2 => 'Value'}],
                       print => \&print_login,                        print => \&print_login,
                       modify => \&modify_login,                        modify => \&modify_login,
Line 369  sub handler { Line 371  sub handler {
                               col2 => 'Value'},                                col2 => 'Value'},
                              {col1 => 'Available textbooks',                               {col1 => 'Available textbooks',
                               col2 => ''},                                col2 => ''},
                                {col1 => 'Available templates',
                                 col2 => ''},
                              {col1 => 'Validation (not official courses)',                               {col1 => 'Validation (not official courses)',
                               col2 => 'Value'},],                                col2 => 'Value'},],
                   print => \&print_quotas,                    print => \&print_quotas,
Line 407  sub handler { Line 411  sub handler {
                   print => \&print_serverstatuses,                    print => \&print_serverstatuses,
                   modify => \&modify_serverstatuses,                    modify => \&modify_serverstatuses,
                  },                   },
           'helpsettings' =>
                    {text   => 'Help page settings',
                     help   => 'Domain_Configuration_Help_Settings',
                     header => [{col1 => 'Help Settings (logged-in users)',
                                 col2 => 'Value'}],
                     print  => \&print_helpsettings,
                     modify => \&modify_helpsettings,
                    },
         'coursedefaults' =>           'coursedefaults' => 
                  {text => 'Course/Community defaults',                   {text => 'Course/Community defaults',
                   help => 'Domain_Configuration_Course_Defaults',                    help => 'Domain_Configuration_Course_Defaults',
Line 429  sub handler { Line 441  sub handler {
                   print => \&print_selfenrollment,                    print => \&print_selfenrollment,
                   modify => \&modify_selfenrollment,                    modify => \&modify_selfenrollment,
                  },                   },
           'privacy' => 
                    {text   => 'User Privacy',
                     help   => 'Domain_Configuration_User_Privacy',
                     header => [{col1 => 'Setting',
                                 col2 => 'Value',}],
                     print => \&print_privacy,
                     modify => \&modify_privacy,
                    },
         'usersessions' =>          'usersessions' =>
                  {text  => 'User session hosting/offloading',                   {text  => 'User session hosting/offloading',
                   help  => 'Domain_Configuration_User_Sessions',                    help  => 'Domain_Configuration_User_Sessions',
Line 461  sub handler { Line 481  sub handler {
                                        {col1 => 'Log-in Page Items',                                         {col1 => 'Log-in Page Items',
                                         col2 => ''},                                          col2 => ''},
                                        {col1 => 'Log-in Help',                                         {col1 => 'Log-in Help',
                                           col2 => 'Value'},
                                          {col1 => 'Custom HTML in document head',
                                         col2 => 'Value'}],                                          col2 => 'Value'}],
                             print => \&print_login,                              print => \&print_login,
                             modify => \&modify_login,                              modify => \&modify_login,
Line 613  sub process_changes { Line 635  sub process_changes {
         $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') {      } elsif ($action eq 'selfenrollment') {
Line 650  sub print_config_box { Line 674  sub print_config_box {
         my $colspan = '';          my $colspan = '';
         my $rightcolspan = '';          my $rightcolspan = '';
         if (($action eq 'rolecolors') || ($action eq 'defaults') ||          if (($action eq 'rolecolors') || ($action eq 'defaults') ||
             (($action eq 'login') && ($numheaders < 3))) {              (($action eq 'login') && ($numheaders < 4))) {
             $colspan = ' colspan="2"';              $colspan = ' colspan="2"';
         }          }
         if ($action eq 'usersessions') {          if ($action eq 'usersessions') {
Line 666  sub print_config_box { Line 690  sub print_config_box {
              </tr>';               </tr>';
         $rowtotal ++;          $rowtotal ++;
         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||          if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
             ($action eq 'usermodification') || ($action eq 'defaults') ||              ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
             ($action eq 'selfenrollment') || ($action eq 'usersessions')) {              ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);              $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'coursecategories') {          } elsif ($action eq 'coursecategories') {
             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);              $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
         } elsif ($action eq 'login') {          } elsif ($action eq 'login') {
             if ($numheaders == 3) {              if ($numheaders == 4) {
                 $colspan = ' colspan="2"';                  $colspan = ' colspan="2"';
                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);                  $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
             } else {              } else {
Line 725  sub print_config_box { Line 749  sub print_config_box {
                   ($action eq 'defaults')) {                    ($action eq 'defaults')) {
             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);              $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'login') {          } elsif ($action eq 'login') {
             if ($numheaders == 3) {              if ($numheaders == 4) {
                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'                  $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
            </table>             </table>
           </td>            </td>
Line 741  sub print_config_box { Line 765  sub print_config_box {
             } else {              } else {
                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);                  $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
             }              }
               $output .= '
              </table>
             </td>
            </tr>
            <tr>
              <td>
               <table class="LC_nested">
                <tr class="LC_info_row">';
               if ($numheaders == 4) {
                   $output .= '
                 <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                 <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                </tr>';
               } else {
                   $output .= '
                 <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                 <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                </tr>';
               }
               $rowtotal ++;
               $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
         } elsif ($action eq 'requestcourses') {          } elsif ($action eq 'requestcourses') {
             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).              $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                        &print_studentcode($settings,\$rowtotal).'              $rowtotal ++;
               $output .= &print_studentcode($settings,\$rowtotal).'
            </table>             </table>
           </td>            </td>
          </tr>           </tr>
Line 753  sub print_config_box { Line 799  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).'                         &textbookcourses_javascript($settings).
                          &print_textbookcourses($dom,'textbooks',$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'}->[3]->{'col1'}).'</td>
                 <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                          &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
             </table>              </table>
            </td>             </td>
           </tr>            </tr>
Line 761  sub print_config_box { Line 818  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.' valign="top">'.&mt($item->{'header'}->[3]->{'col1'}).'</td>                <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
               <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>                <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
              </tr>'.               </tr>'.
             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);              &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'requestauthor') {          } elsif ($action eq 'requestauthor') {
             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);              $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
               $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 1148  sub print_login { Line 1206  sub print_login {
             $itemcount ++;              $itemcount ++;
         }          }
         $datatable .= &captcha_choice('login',$settings,$itemcount);          $datatable .= &captcha_choice('login',$settings,$itemcount);
       } elsif ($caller eq 'headtag') {
           my %domservers = &Apache::lonnet::get_servers($dom);
           my $choice = $choices{'headtag'};
           $css_class = ' class="LC_odd_row"';
           $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
                         '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
                         '<th>'.$choices{'current'}.'</th>'.
                         '<th>'.$choices{'action'}.'</th>'.
                         '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
           my (%currurls,%currexempt);
           if (ref($settings) eq 'HASH') {
               if (ref($settings->{'headtag'}) eq 'HASH') {
                   foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                       if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                           $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                           $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                       }
                   }
               }
           }
           my %lt = &Apache::lonlocal::texthash(
                                                  del  => 'Delete?',
                                                  rep  => 'Replace:',
                                                  upl  => 'Upload:',
                                                  curr => 'View contents',
                                                  none => 'None',
           );
           my $switchserver = &check_switchserver($dom,$confname);
           foreach my $lonhost (sort(keys(%domservers))) {
               my $exempt = &check_exempt_addresses($currexempt{$lonhost});
               $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
               if ($currurls{$lonhost}) {
                   $datatable .= '<td class="LC_right_item"><a href="'.
                                 "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                                 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                                 '">'.$lt{'curr'}.'</a></td>'.
                                 '<td><span class="LC_nobreak"><label>'.
                                 '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                                 $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
               } else {
                   $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
               }
               $datatable .='<br />';
               if ($switchserver) {
                   $datatable .= &mt('Upload to library server: [_1]',$switchserver);
               } else {
                   $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
               }
               $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
           }
           $datatable .= '</table></td></tr>';
     }      }
     return $datatable;      return $datatable;
 }  }
Line 1181  sub login_choices { Line 1290  sub login_choices {
             link          => "Link",              link          => "Link",
             alink         => "Active link",              alink         => "Active link",
             vlink         => "Visited link",              vlink         => "Visited link",
               headtag       => "Custom markup",
               action        => "Action",
               current       => "Current",
         );          );
     return %choices;      return %choices;
 }  }
Line 2043  sub print_requestmail { Line 2155  sub print_requestmail {
         $datatable .= &mt('There are no active Domain Coordinators');          $datatable .= &mt('There are no active Domain Coordinators');
     }      }
     $datatable .='</td></tr>';      $datatable .='</td></tr>';
     $$rowtotal += $rows;  
     return $datatable;      return $datatable;
 }  }
   
Line 2052  sub print_studentcode { Line 2163  sub print_studentcode {
     my $rownum = 0;       my $rownum = 0; 
     my ($output,%current);      my ($output,%current);
     my @crstypes = ('official','unofficial','community','textbook');      my @crstypes = ('official','unofficial','community','textbook');
     if (ref($settings->{'uniquecode'}) eq 'HASH') {      if (ref($settings) eq 'HASH') {
         foreach my $type (@crstypes) {          if (ref($settings->{'uniquecode'}) eq 'HASH') {
             $current{$type} = $settings->{'uniquecode'}{$type};              foreach my $type (@crstypes) {
                   $current{$type} = $settings->{'uniquecode'}{$type};
               }
         }          }
     }      }
     $output .= '<tr>'.      $output .= '<tr>'.
Line 2075  sub print_studentcode { Line 2188  sub print_studentcode {
 }  }
   
 sub print_textbookcourses {  sub print_textbookcourses {
     my ($dom,$settings,$rowtotal) = @_;      my ($dom,$type,$settings,$rowtotal) = @_;
     my $rownum = 0;      my $rownum = 0;
     my $css_class;      my $css_class;
     my $itemcount = 1;      my $itemcount = 1;
     my $maxnum = 0;      my $maxnum = 0;
     my $bookshash;      my $bookshash;
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
         $bookshash = $settings->{'textbooks'};          $bookshash = $settings->{$type};
     }      }
     my %ordered;      my %ordered;
     if (ref($bookshash) eq 'HASH') {      if (ref($bookshash) eq 'HASH') {
Line 2095  sub print_textbookcourses { Line 2208  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;
     if (keys(%ordered)) {      if (keys(%ordered)) {
         my @items = sort { $a <=> $b } keys(%ordered);          my @items = sort { $a <=> $b } keys(%ordered);
         for (my $i=0; $i<@items; $i++) {          for (my $i=0; $i<@items; $i++) {
Line 2104  sub print_textbookcourses { Line 2217  sub print_textbookcourses {
             my $key = $ordered{$items[$i]};              my $key = $ordered{$items[$i]};
             my %coursehash=&Apache::lonnet::coursedescription($key);              my %coursehash=&Apache::lonnet::coursedescription($key);
             my $coursetitle = $coursehash{'description'};              my $coursetitle = $coursehash{'description'};
             my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);              my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
             if (ref($bookshash->{$key}) eq 'HASH') {              if (ref($bookshash->{$key}) eq 'HASH') {
                 $subject = $bookshash->{$key}->{'subject'};                  $subject = $bookshash->{$key}->{'subject'};
                 $title = $bookshash->{$key}->{'title'};                  $title = $bookshash->{$key}->{'title'};
                 $author = $bookshash->{$key}->{'author'};                  if ($type eq 'textbooks') {
                 $image = $bookshash->{$key}->{'image'};                      $publisher = $bookshash->{$key}->{'publisher'};
                 if ($image ne '') {                      $author = $bookshash->{$key}->{'author'};
                     my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});                      $image = $bookshash->{$key}->{'image'};
                     my $imagethumb = "$path/tn-".$imagefile;                      if ($image ne '') {
                     $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';                          my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                           my $imagethumb = "$path/tn-".$imagefile;
                           $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                       }
                 }                  }
             }              }
             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';              my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'              $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                          .'<select name="'.$key.'"'.$chgstr.'>';                           .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
             for (my $k=0; $k<=$maxnum; $k++) {              for (my $k=0; $k<=$maxnum; $k++) {
                 my $vpos = $k+1;                  my $vpos = $k+1;
                 my $selstr;                  my $selstr;
Line 2128  sub print_textbookcourses { Line 2244  sub print_textbookcourses {
                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';                  $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
             }              }
             $datatable .= '</select>'.('&nbsp;'x2).              $datatable .= '</select>'.('&nbsp;'x2).
                 '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.                  '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
                 &mt('Delete?').'</label></span></td>'.                  &mt('Delete?').'</label></span></td>'.
                 '<td colspan="2">'.                  '<td colspan="2">'.
                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.                  '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
                 ('&nbsp;'x2).  
                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.  
                 ('&nbsp;'x2).  
                 '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.  
                 ('&nbsp;'x2).                  ('&nbsp;'x2).
                 '<span class="LC_nobreak">'.&mt('Thumbnail:');                  '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
             if ($image) {              if ($type eq 'textbooks') {
                 $datatable .= '<span class="LC_nobreak">'.                  $datatable .= ('&nbsp;'x2).
                               $imgsrc.                                '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                               '<label><input type="checkbox" name="book_image_del"'.                                ('&nbsp;'x2).
                               ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.                                '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';                                ('&nbsp;'x2).
             }                                '<span class="LC_nobreak">'.&mt('Thumbnail:');
             if ($switchserver) {                  if ($image) {
                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);                      $datatable .= '<span class="LC_nobreak">'.
             } else {                                    $imgsrc.
                 $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';                                    '<label><input type="checkbox" name="'.$type.'_image_del"'.
                                     ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                                     '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   }
                   if ($switchserver) {
                       $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   } else {
                       $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   }
             }              }
             $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.              $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.                            '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                           $coursetitle.'</span></td></tr>'."\n";                            $coursetitle.'</span></td></tr>'."\n";
             $itemcount ++;              $itemcount ++;
         }          }
     }      }
     $css_class = $itemcount%2?' class="LC_odd_row"':'';      $css_class = $itemcount%2?' class="LC_odd_row"':'';
     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';      my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".      $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".                    '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   '<select name="addbook_pos"'.$chgstr.'>';                    '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
     for (my $k=0; $k<$maxnum+1; $k++) {      for (my $k=0; $k<$maxnum+1; $k++) {
         my $vpos = $k+1;          my $vpos = $k+1;
         my $selstr;          my $selstr;
Line 2170  sub print_textbookcourses { Line 2290  sub print_textbookcourses {
         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';          $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
     }      }
     $datatable .= '</select>&nbsp;'."\n".      $datatable .= '</select>&nbsp;'."\n".
                   '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".                    '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
                   '<td colspan="2">'.                    '<td colspan="2">'.
                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".                    '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
                   ('&nbsp;'x2).  
                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".  
                   ('&nbsp;'x2).  
                   '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".  
                   ('&nbsp;'x2).                    ('&nbsp;'x2).
                   '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';                    '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
     if ($switchserver) {                    ('&nbsp;'x2);
         $datatable .= &mt('Upload to library server: [_1]',$switchserver);      if ($type eq 'textbooks') {
     } else {          $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
         $datatable .= '<input type="file" name="addbook_image" value="" />';                        ('&nbsp;'x2).
                         '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
                         ('&nbsp;'x2).
                         '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
           if ($switchserver) {
               $datatable .= &mt('Upload to library server: [_1]',$switchserver);
           } else {
               $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
           }
     }      }
     $datatable .= '</span>'."\n".      $datatable .= '</span>'."\n".
                   '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.                    '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').                    &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   '<input type="text" size="25" name="addbook_cnum" value="" />'.                    '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
                   &Apache::loncommon::selectcourse_link                    &Apache::loncommon::selectcourse_link
                       ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');                        ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
                   '</span></td>'."\n".                    '</span></td>'."\n".
                   '</tr>'."\n";                    '</tr>'."\n";
     $itemcount ++;      $itemcount ++;
Line 2197  sub print_textbookcourses { Line 2321  sub print_textbookcourses {
 }  }
   
 sub textbookcourses_javascript {  sub textbookcourses_javascript {
     my ($textbooks) = @_;      my ($settings) = @_;
     return unless(ref($textbooks) eq 'HASH');      return unless(ref($settings) eq 'HASH');
     my $num = scalar(keys(%{$textbooks}));      my (%ordered,%total,%jstext);
     my @jsarray;      foreach my $type ('textbooks','templates') {
     foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {          $total{$type} = 0;
         push(@jsarray,$textbooks->{$item});          if (ref($settings->{$type}) eq 'HASH') {
               foreach my $item (keys(%{$settings->{$type}})) {
                   if (ref($settings->{$type}->{$item}) eq 'HASH') {
                       my $num = $settings->{$type}->{$item}{'order'};
                       $ordered{$type}{$num} = $item;
                   }
               }
               $total{$type} = scalar(keys(%{$settings->{$type}}));
           }
           my @jsarray = ();
           foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
               push(@jsarray,$ordered{$type}{$item});
           }
           $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
     }      }
     my $jstext = '    var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";  
     return <<"ENDSCRIPT";      return <<"ENDSCRIPT";
 <script type="text/javascript">  <script type="text/javascript">
 // <![CDATA[  // <![CDATA[
 function reorderBooks(form,item) {  function reorderBooks(form,item,caller) {
     var changedVal;      var changedVal;
 $jstext   $jstext{'textbooks'};
     var newpos = 'addbook_pos';  $jstext{'templates'};
       var newpos;
       var maxh;
       if (caller == 'textbooks') {  
           newpos = 'textbooks_addbook_pos';
           maxh = 1 + $total{'textbooks'};
       } else {
           newpos = 'templates_addbook_pos';
           maxh = 1 + $total{'templates'};
       }
     var current = new Array;      var current = new Array;
     var maxh = 1 + $num;  
     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 2221  $jstext Line 2365  $jstext
         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;          changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
         current[newitemVal] = newpos;          current[newitemVal] = newpos;
     }      }
     for (var i=0; i<textbooks.length; i++) {      if (caller == 'textbooks') {
         var elementName = textbooks[i];          for (var i=0; i<textbooks.length; i++) {
         if (elementName != item) {              var elementName = 'textbooks_'+textbooks[i];
             if (form.elements[elementName]) {              if (elementName != item) {
                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;                  if (form.elements[elementName]) {
                 current[currVal] = elementName;                      var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                       current[currVal] = elementName;
                   }
               }
           }
       }
       if (caller == 'templates') {
           for (var i=0; i<templates.length; i++) {
               var elementName = 'templates_'+templates[i];
               if (elementName != item) {
                   if (form.elements[elementName]) {
                       var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                       current[currVal] = elementName;
                   }
             }              }
         }          }
     }      }
Line 2444  sub print_autocreate { Line 2601  sub print_autocreate {
                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';                    $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',      my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                                                    'autocreate_xmldc',%currhash);                                                     'autocreate_xmldc',%currhash);
       $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
     if ($numdc > 1) {      if ($numdc > 1) {
         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.          $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                       &mt('Course creation processed as: (choose Dom. Coord.)').                        '</td><td class="LC_left_item">';
                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';  
     } else {      } else {
         $datatable .= $dctable.'</td></tr>';          $datatable .= &mt('Course creation processed as:').
                         '</td><td class="LC_right_item">';
     }      }
       $datatable .= $dctable.'</td></tr>';
     $$rowtotal += $rows;      $$rowtotal += $rows;
     return $datatable;      return $datatable;
 }  }
Line 3042  sub print_validation_rows { Line 3201  sub print_validation_rows {
     }      }
     if ($caller eq 'requestcourses') {      if ($caller eq 'requestcourses') {
         my %currhash;          my %currhash;
         if (ref($settings->{'validation'}) eq 'HASH') {          if (ref($settings) eq 'HASH') {
             if ($settings->{'validation'}{'dc'} ne '') {              if (ref($settings->{'validation'}) eq 'HASH') {
                 $currhash{$settings->{'validation'}{'dc'}} = 1;                  if ($settings->{'validation'}{'dc'} ne '') {
                       $currhash{$settings->{'validation'}{'dc'}} = 1;
                   }
             }              }
         }          }
         my $numinrow = 2;          my $numinrow = 2;
         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',          my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                                                        'validationdc',%currhash);                                                         'validationdc',%currhash);
           my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
           $datatable .= '</td></tr><tr'.$css_class.'><td>';
         if ($numdc > 1) {          if ($numdc > 1) {
             $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.              $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
                           &mt('Course creation processed as: (choose Dom. Coord.)').  
                           '</td><td class="LC_left_item">'.$dctable.'</td></tr>';  
         } else {          } else {
             $datatable .= $dctable.'</td></tr>';              $datatable .=  &mt('Course creation processed as: ');
         }          }
           $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
         $itemcount ++;          $itemcount ++;
     }      }
     if (ref($rowtotal)) {      if (ref($rowtotal)) {
Line 3578  sub print_loadbalancing { Line 3740  sub print_loadbalancing {
                     $disabled = ' disabled="disabled"';                      $disabled = ' disabled="disabled"';
                 }                  }
                 $targettable .=                  $targettable .=
                     '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.                      '<td><span class="LC_nobreak"><label>'.
                       '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.                      $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
                     '</span></label></td>';                      '</span></label></span></td>';
                 my $rem = $i%($numinrow);                  my $rem = $i%($numinrow);
                 if ($rem == 0) {                  if ($rem == 0) {
                     if (($i > 0) && ($i < $numspares-1)) {                      if (($i > 0) && ($i < $numspares-1)) {
Line 3670  sub loadbalancing_rules { Line 3833  sub loadbalancing_rules {
             if (ref($currrules) eq 'HASH') {              if (ref($currrules) eq 'HASH') {
                 $current = $currrules->{$type};                  $current = $currrules->{$type};
             }              }
             if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {              if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {                  if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
                     $current = '';                      $current = '';
                 }                  }
Line 3722  sub loadbalance_rule_row { Line 3885  sub loadbalance_rule_row {
     my @rulenames;      my @rulenames;
     my %ruletitles = &offloadtype_text();      my %ruletitles = &offloadtype_text();
     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {      if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
         @rulenames = ('balancer','offloadedto');          @rulenames = ('balancer','offloadedto','specific');
     } else {      } else {
         @rulenames = ('default','homeserver');          @rulenames = ('default','homeserver');
         if ($type eq '_LC_external') {          if ($type eq '_LC_external') {
Line 3733  sub loadbalance_rule_row { Line 3896  sub loadbalance_rule_row {
         push(@rulenames,'none');          push(@rulenames,'none');
     }      }
     my $style = $targets_div_style;      my $style = $targets_div_style;
     if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {      if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
         $style = $homedom_div_style;          $style = $homedom_div_style;
     }      }
     my $space;      my $space;
Line 3784  sub loadbalance_rule_row { Line 3947  sub loadbalance_rule_row {
                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.                     '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.                     '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".                     $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.                     ')"'.$checked.' />&nbsp;';
                    '</label>'.$extra.'</span><br />'."\n";          if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
               $output .= $ruletitles{'particular'};
           } else {
               $output .= $ruletitles{$rulenames[$i]};
           }
           $output .= '</label>'.$extra.'</span><br />'."\n";
     }      }
     $output .= '</div></td></tr>'."\n";      $output .= '</div></td></tr>'."\n";
     return $output;      return $output;
Line 3800  sub offloadtype_text { Line 3968  sub offloadtype_text {
            'none'             => 'No offload',             'none'             => 'No offload',
            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',             'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
            'offloadedto'      => 'Session hosted on offload server, after re-authentication',             'offloadedto'      => 'Session hosted on offload server, after re-authentication',
              'particular'       => 'Session hosted (after re-auth) on server:',
     );      );
     return %ruletitles;      return %ruletitles;
 }  }
Line 4070  sub print_selfcreation { Line 4239  sub print_selfcreation {
         my $numperrow = 2;          my $numperrow = 2;
         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';          my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
         $datatable .= '<tr'.$css_class.'>'.          $datatable .= '<tr'.$css_class.'>'.
                      '<td class="LC_left_item">'.&mt('Shibboleth (SSO) Data').'</td>'.                       '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
                      '<td class="LC_left_item">'."\n".                       '<td class="LC_left_item">'."\n".
                      '<table><tr><td>'."\n";                       '<table><tr><td>'."\n";
         for (my $i=0; $i<@fields; $i++) {          for (my $i=0; $i<@fields; $i++) {
Line 4082  sub print_selfcreation { Line 4251  sub print_selfcreation {
                 $datatable .= '<tr>';                  $datatable .= '<tr>';
             }              }
             my $currval;              my $currval;
             if (ref($createsettings->{'shibenv'}) eq 'HASH') {              if (ref($createsettings) eq 'HASH') {
                 $currval = $createsettings->{'shibenv'}{$fields[$i]};                  if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                       $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   }
             }              }
             $datatable .= '<td class="LC_left_item">'.              $datatable .= '<td class="LC_left_item">'.
                           '<span class="LC_nobreak">'.                            '<span class="LC_nobreak">'.
Line 5087  sub serverstatus_pages { Line 5258  sub serverstatus_pages {
   
 sub defaults_javascript {  sub defaults_javascript {
     my ($settings) = @_;      my ($settings) = @_;
     my ($output,$jstext);       return unless (ref($settings) eq 'HASH'); 
     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {      if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
         my $maxnum = scalar(@{$settings->{'inststatusorder'}});          my $maxnum = scalar(@{$settings->{'inststatusorder'}});
         if ($maxnum eq '') {          if ($maxnum eq '') {
             $maxnum = 0;              $maxnum = 0;
         }          }
         $maxnum ++;          $maxnum ++;
         $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';            my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
         return <<"ENDSCRIPT";          return <<"ENDSCRIPT";
 <script type="text/javascript">  <script type="text/javascript">
 // <![CDATA[  // <![CDATA[
Line 5687  sub modify_login { Line 5858  sub modify_login {
     }      }
   
     my %servers = &Apache::lonnet::internet_dom_servers($dom);      my %servers = &Apache::lonnet::internet_dom_servers($dom);
       my %domservers = &Apache::lonnet::get_servers($dom);
     my @loginvia_attribs = ('serverpath','custompath','exempt');      my @loginvia_attribs = ('serverpath','custompath','exempt');
     if (keys(%servers) > 1) {      if (keys(%servers) > 1) {
         foreach my $lonhost (keys(%servers)) {          foreach my $lonhost (keys(%servers)) {
Line 5729  sub modify_login { Line 5901  sub modify_login {
                             $changes{'loginvia'}{$lonhost} = 1;                              $changes{'loginvia'}{$lonhost} = 1;
                         }                          }
                         if ($item eq 'exempt') {                          if ($item eq 'exempt') {
                             $new =~ s/^\s+//;                              $new = &check_exempt_addresses($new);
                             $new =~ s/\s+$//;  
                             my @poss_ips = split(/\s*[,:]\s*/,$new);  
                             my @okips;  
                             foreach my $ip (@poss_ips) {  
                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {  
                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {  
                                         push(@okips,$ip);   
                                     }  
                                 }  
                             }  
                             if (@okips > 0) {  
                                 $new = join(',',@okips);   
                             } else {  
                                 $new = '';   
                             }  
                         }                          }
                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;                          $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                     }                      }
Line 5840  sub modify_login { Line 5997  sub modify_login {
                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';                          $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&                          if ((grep(/^\Q$lang\E$/,@currlangs)) &&
                             (!grep(/^\Q$lang\E$/,@delurls))) {                              (!grep(/^\Q$lang\E$/,@delurls))) {
   
                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};                              $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                         }                          }
                     }                      }
Line 5856  sub modify_login { Line 6012  sub modify_login {
             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';              $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
         }          }
     }      }
   
       my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
       if (ref($domconfig{'login'}) eq 'HASH') {
           if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
               foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   if ($domservers{$lonhost}) {
                       if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                           $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
                           $currexempt{$lonhost} = $domconfig{'login'}{'headtagexempt'}{$lonhost}{'exempt'}
                       }
                   }
               }
           }
       }
       my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
       foreach my $lonhost (sort(keys(%domservers))) {
           if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
               $changes{'headtag'}{$lonhost} = 1;
           } else {
               if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
               }
               if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   push(@newhosts,$lonhost);
               } elsif ($currheadtagurls{$lonhost}) {
                   $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   if ($currexempt{$lonhost}) {
                       if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) { 
                           $changes{'headtag'}{$lonhost} = 1;
                       }
                   } elsif ($possexempt{$lonhost}) {
                       $changes{'headtag'}{$lonhost} = 1;
                   }
                   if ($possexempt{$lonhost}) {
                       $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   }
               }
           }
       }
       if (@newhosts) {
           my $error;
           my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
           if ($configuserok eq 'ok') {
               if ($switchserver) {
                   $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
               } elsif ($author_ok eq 'ok') {
                   foreach my $lonhost (@newhosts) {
                       my $formelem = 'loginheadtag_'.$lonhost;
                       (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                                                                             "login/headtag/$lonhost",'','',
                                                                             $env{'form.loginheadtag_'.$lonhost.'.filename'});
                       if ($result eq 'ok') {
                           $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                           $changes{'headtag'}{$lonhost} = 1;
                           if ($possexempt{$lonhost}) {
                               $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                           }
                       } else {
                           my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                                              $newheadtagurls{$lonhost},$result);
                           $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                           if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                               (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                               $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                           }
                       }
                   }
               } else {
                   $error = &mt("Upload of custom markup file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2].  Error was: [_3].",$confname,$dom,$author_ok);
               }
           } else {
               $error = &mt("Upload of custom markup file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2].  Error was: [_3].",$confname,$dom,$configuserok);
           }
           if ($error) {
               &Apache::lonnet::logthis($error);
               $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
           }
       }
     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});      &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
   
     my $defaulthelpfile = '/adm/loginproblems.html';      my $defaulthelpfile = '/adm/loginproblems.html';
Line 5956  sub modify_login { Line 6190  sub modify_login {
                             }                              }
                         }                          }
                     }                      }
                   } elsif ($item eq 'headtag') {
                       if (ref($changes{$item}) eq 'HASH') {
                           foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                               if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                                   $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                               } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                                   $resulttext .= '<li><a href="'.
                                                  "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                                                  'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                                                  '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                                   if ($possexempt{$lonhost}) {
                                       $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                                   } else {
                                       $resulttext .= &mt('included for any client IP');
                                   }
                                   $resulttext .= '</li>';
                               }
                           }
                       }
                 } elsif ($item eq 'captcha') {                  } elsif ($item eq 'captcha') {
                     if (ref($loginhash{'login'}) eq 'HASH') {                      if (ref($loginhash{'login'}) eq 'HASH') {
                         my $chgtxt;                          my $chgtxt;
Line 5987  sub modify_login { Line 6240  sub modify_login {
                         if (!$privkey) {                          if (!$privkey) {
                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';                              $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                         } else {                          } else {
                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';                              $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
                         }                          }
                         $chgtxt .= '</ul>';                          $chgtxt .= '</ul>';
                         $resulttext .= '<li>'.$chgtxt.'</li>';                          $resulttext .= '<li>'.$chgtxt.'</li>';
Line 6011  sub modify_login { Line 6264  sub modify_login {
     return $resulttext;      return $resulttext;
 }  }
   
   
   sub check_exempt_addresses {
       my ($iplist) = @_;
       $iplist =~ s/^\s+//;
       $iplist =~ s/\s+$//;
       my @poss_ips = split(/\s*[,:]\s*/,$iplist);
       my (@okips,$new);
       foreach my $ip (@poss_ips) {
           if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
               if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   push(@okips,$ip);
               }
           }
       }
       if (@okips > 0) {
           $new = join(',',@okips);
       } else {
           $new = '';
       }
       return $new;
   }
   
 sub color_font_choices {  sub color_font_choices {
     my %choices =      my %choices =
         &Apache::lonlocal::texthash (          &Apache::lonlocal::texthash (
Line 6812  sub modify_quotas { Line 7087  sub modify_quotas {
                 $confhash{'uniquecode'}{$type} = 1;                  $confhash{'uniquecode'}{$type} = 1;
             }              }
         }          }
         my ($newbook,@allpos);          my (%newbook,%allpos);
         if ($context eq 'requestcourses') {          if ($context eq 'requestcourses') {
             if ($env{'form.addbook'}) {              foreach my $type ('textbooks','templates') {
                 if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&                  @{$allpos{$type}} = (); 
                     ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {                  my $invalid;
                     if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},                  if ($type eq 'textbooks') {
                                                     $env{'form.addbook_cdom'}) eq 'no_host') {                      $invalid = &mt('Invalid LON-CAPA course for textbook');
                         $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').                  } else {
                                    '</span></li>';                      $invalid = &mt('Invalid LON-CAPA course for template');
                     } else {                  }
                         $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};                  if ($env{'form.'.$type.'_addbook'}) {
                         my $position = $env{'form.addbook_pos'};                      if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                         $position =~ s/\D+//g;                          ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                         if ($position ne '') {                          if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                             $allpos[$position] = $newbook;                                                          $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                               $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                           } else {
                               $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                               my $position = $env{'form.'.$type.'_addbook_pos'};
                               $position =~ s/\D+//g;
                               if ($position ne '') {
                                   $allpos{$type}[$position] = $newbook{$type};
                               }
                         }                          }
                       } else {
                           $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                     }                      }
                 } else {  
                     $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').  
                                '</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 6867  sub modify_quotas { Line 7148  sub modify_quotas {
                 $changes{'uniquecode'} = 1;                  $changes{'uniquecode'} = 1;
             }              }
             if ($context eq 'requestcourses') {              if ($context eq 'requestcourses') {
                 if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {                  foreach my $type ('textbooks','templates') {
                     my %deletions;                      if (ref($domconfig{$action}{$type}) eq 'HASH') {
                     my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');                          my %deletions;
                     if (@todelete) {                          my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                         map { $deletions{$_} = 1; } @todelete;                          if (@todelete) {
                     }                              map { $deletions{$_} = 1; } @todelete;
                     my %imgdeletions;                          }
                     my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');                          my %imgdeletions;
                     if (@todeleteimages) {                          my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                         map { $imgdeletions{$_} = 1; } @todeleteimages;                          if (@todeleteimages) {
                     }                              map { $imgdeletions{$_} = 1; } @todeleteimages;
                     my $maxnum = $env{'form.book_maxnum'};                          }
                     for (my $i=0; $i<=$maxnum; $i++) {                          my $maxnum = $env{'form.'.$type.'_maxnum'};
                         my $key = $env{'form.book_id_'.$i};                          for (my $i=0; $i<=$maxnum; $i++) {
                         if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {                              my $itemid = $env{'form.'.$type.'_id_'.$i};
                             if ($deletions{$key}) {                              my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                                 if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {                              if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                                     #FIXME need to obsolete item in RES space                                  if ($deletions{$key}) {
                                       if ($domconfig{$action}{$type}{$key}{'image'}) {
                                           #FIXME need to obsolete item in RES space
                                       }
                                       next;
                                   } else {
                                       my $newpos = $env{'form.'.$itemid};
                                       $newpos =~ s/\D+//g;
                                       foreach my $item ('subject','title','publisher','author') {
                                           next if ((($item eq 'author') || ($item eq 'publisher')) && 
                                                    ($type eq 'templates'));
                                           $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                                           if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                                               $changes{$type}{$key} = 1;
                                           }
                                       }
                                       $allpos{$type}[$newpos] = $key;
                                 }                                  }
                                 next;                                  if ($imgdeletions{$key}) {
                             } else {                                      $changes{$type}{$key} = 1;
                                 my $newpos = $env{'form.'.$key};                                      #FIXME need to obsolete item in RES space
                                 $newpos =~ s/\D+//g;                                  } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                                 foreach my $item ('subject','title','author') {                                      my ($cdom,$cnum) = split(/_/,$key);
                                     $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};                                      my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                                     if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {                                                                                    $cdom,$cnum,$type,$configuserok,
                                         $changes{'textbooks'}{$key} = 1;                                                                                    $switchserver,$author_ok);
                                       if ($imgurl) {
                                           $confhash{$type}{$key}{'image'} = $imgurl;
                                           $changes{$type}{$key} = 1; 
                                     }                                      }
                                       if ($error) {
                                           &Apache::lonnet::logthis($error);
                                           $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                                       } 
                                   } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                                       $confhash{$type}{$key}{'image'} = 
                                           $domconfig{$action}{$type}{$key}{'image'};
                                 }                                  }
                                 $allpos[$newpos] = $key;  
                             }  
                             if ($imgdeletions{$key}) {  
                                 $changes{'textbooks'}{$key} = 1;  
                                 #FIXME need to obsolete item in RES space  
                             } elsif ($env{'form.book_image_'.$i.'.filename'}) {  
                                 my ($cdom,$cnum) = split(/_/,$key);  
                                 my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,  
                                                                               $cdom,$cnum,$configuserok,  
                                                                               $switchserver,$author_ok);  
                                 if ($imgurl) {  
                                     $confhash{'textbooks'}{$key}{'image'} = $imgurl;  
                                     $changes{'textbooks'}{$key} = 1;   
                                 }  
                                 if ($error) {  
                                     &Apache::lonnet::logthis($error);  
                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';  
                                 }   
                             } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {  
                                 $confhash{'textbooks'}{$key}{'image'} =   
                                     $domconfig{$action}{'textbooks'}{$key}{'image'};  
                             }                              }
                         }                          }
                     }                      }
Line 6931  sub modify_quotas { Line 7217  sub modify_quotas {
             }              }
         }          }
         if ($context eq 'requestcourses') {          if ($context eq 'requestcourses') {
             if ($newbook) {              foreach my $type ('textbooks','templates') {
                 $changes{'textbooks'}{$newbook} = 1;                  if ($newbook{$type}) {
                 foreach my $item ('subject','title','author') {                      $changes{$type}{$newbook{$type}} = 1;
                     $env{'form.addbook_'.$item} =~ s/(`)/'/g;                      foreach my $item ('subject','title','publisher','author') {
                     if ($env{'form.addbook_'.$item}) {                          next if ((($item eq 'author') || ($item eq 'publisher')) &&
                         $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};                                   ($type eq 'template'));
                     }                          $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                 }                          if ($env{'form.'.$type.'_addbook_'.$item}) {
                 if ($env{'form.addbook_image.filename'} ne '') {                              $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                     my ($cdom,$cnum) = split(/_/,$newbook);                          }
                     my ($imageurl,$error) =                      }
                         &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,                      if ($type eq 'textbooks') {
                                                 $switchserver,$author_ok);                          if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                     if ($imageurl) {                              my ($cdom,$cnum) = split(/_/,$newbook{$type});
                         $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;                              my ($imageurl,$error) =
                     }                                  &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                     if ($error) {                                                          $configuserok,$switchserver,$author_ok);
                         &Apache::lonnet::logthis($error);                              if ($imageurl) {
                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';                                  $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                               }
                               if ($error) {
                                   &Apache::lonnet::logthis($error);
                                   $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                               }
                           }
                     }                      }
                 }                  }
             }                  if (@{$allpos{$type}} > 0) {
             if (@allpos > 0) {                      my $idx = 0;
                 my $idx = 0;                      foreach my $item (@{$allpos{$type}}) {
                 foreach my $item (@allpos) {                          if ($item ne '') {
                     if ($item ne '') {                              $confhash{$type}{$item}{'order'} = $idx;
                         $confhash{'textbooks'}{$item}{'order'} = $idx;                              if (ref($domconfig{$action}) eq 'HASH') {
                         if (ref($domconfig{$action}) eq 'HASH') {                                  if (ref($domconfig{$action}{$type}) eq 'HASH') {
                             if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {                                      if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                                 if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {                                          if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                                     if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {                                              $changes{$type}{$item} = 1;
                                         $changes{'textbooks'}{$item} = 1;                                          }
                                     }                                      }
                                 }                                  }
                             }                              }
                               $idx ++;
                         }                          }
                         $idx ++;  
                     }                      }
                 }                  }
             }              }
Line 7184  sub modify_quotas { Line 7476  sub modify_quotas {
         $domdefaults{'requestauthor'} = \%confhash;          $domdefaults{'requestauthor'} = \%confhash;
     } else {      } else {
         foreach my $key (keys(%confhash)) {          foreach my $key (keys(%confhash)) {
             unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {              unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
                 $domdefaults{$key} = $confhash{$key};                  $domdefaults{$key} = $confhash{$key};
             }              }
         }          }
Line 7336  sub modify_quotas { Line 7628  sub modify_quotas {
                                        '</li>';                                         '</li>';
                     }                      }
                 }                  }
                 if (ref($changes{'textbooks'}) eq 'HASH') {                  foreach my $type ('textbooks','templates') {
                     $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';                      if (ref($changes{$type}) eq 'HASH') {
                     foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {                          $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                         my %coursehash = &Apache::lonnet::coursedescription($key);                          foreach my $key (sort(keys(%{$changes{$type}}))) {
                         my $coursetitle = $coursehash{'description'};                              my %coursehash = &Apache::lonnet::coursedescription($key);
                         my $position = $confhash{'textbooks'}{$key}{'order'} + 1;                              my $coursetitle = $coursehash{'description'};
                         $resulttext .= '<li>';                              my $position = $confhash{$type}{$key}{'order'} + 1;
                         foreach my $item ('subject','title','author') {                              $resulttext .= '<li>';
                             my $name = $item.':';                              foreach my $item ('subject','title','publisher','author') {
                             $name =~ s/^(\w)/\U$1/;                                  next if ((($item eq 'author') || ($item eq 'publisher')) &&
                             $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';                                           ($type eq 'templates'));
                         }                                  my $name = $item.':';
                         $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';                                  $name =~ s/^(\w)/\U$1/;
                         if ($confhash{'textbooks'}{$key}{'image'}) {                                  $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                             $resulttext .= ' '.&mt('Image: [_1]',                              }
                                                '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.                              $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                                                ' alt="Textbook cover" />').'<br />';                              if ($type eq 'textbooks') {
                                   if ($confhash{$type}{$key}{'image'}) {
                                       $resulttext .= ' '.&mt('Image: [_1]',
                                                      '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                                                      ' alt="Textbook cover" />').'<br />';
                                   }
                               }
                               $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
                         }                          }
                         $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';                          $resulttext .= '</ul></li>';
                     }                      }
                     $resulttext .= '</ul></li>';  
                 }                  }
                 if (ref($changes{'validation'}) eq 'HASH') {                  if (ref($changes{'validation'}) eq 'HASH') {
                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {                      if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
Line 7404  sub modify_quotas { Line 7702  sub modify_quotas {
 }  }
   
 sub process_textbook_image {  sub process_textbook_image {
     my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;      my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
     my $filename = $env{'form.'.$caller.'.filename'};      my $filename = $env{'form.'.$caller.'.filename'};
     my ($error,$url);      my ($error,$url);
     my ($width,$height) = (50,50);      my ($width,$height) = (50,50);
Line 7415  sub process_textbook_image { Line 7713  sub process_textbook_image {
         } elsif ($author_ok eq 'ok') {          } elsif ($author_ok eq 'ok') {
             my ($result,$imageurl) =              my ($result,$imageurl) =
                 &publishlogo($r,'upload',$caller,$dom,$confname,                  &publishlogo($r,'upload',$caller,$dom,$confname,
                              "textbooks/$dom/$cnum/cover",$width,$height);                               "$type/$dom/$cnum/cover",$width,$height);
             if ($result eq 'ok') {              if ($result eq 'ok') {
                 $url = $imageurl;                  $url = $imageurl;
             } else {              } else {
Line 8432  sub modify_selfcreation { Line 8730  sub modify_selfcreation {
 # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.  # 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') {      if ($env{'form.cancreate_email'}) {
         push(@contexts,'emailusername');          push(@contexts,'emailusername');
         if (ref($types) eq 'ARRAY') {          if (ref($types) eq 'ARRAY') {
             foreach my $type (@{$types}) {              foreach my $type (@{$types}) {
Line 8850  sub modify_selfcreation { Line 9148  sub modify_selfcreation {
                                 foreach my $type (@{$types}) {                                  foreach my $type (@{$types}) {
                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {                                      if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {                                          if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
                                             $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).                                              $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
                                                     '<ul>';                                                      '<ul>';
                                             foreach my $field (@{$infofields}) {                                              foreach my $field (@{$infofields}) {
                                                 if ($cancreate{'emailusername'}{$type}{$field}) {                                                  if ($cancreate{'emailusername'}{$type}{$field}) {
                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';                                                      $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 />';
                                         }                                          }
                                         $chgtext .= '</ul>';  
                                     } else {                                      } 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 />';                                          $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 />';
                                     }                                      }
                                 }                                  }
                             }                              }
Line 8966  sub process_captcha { Line 9266  sub process_captcha {
     if ($newsettings->{'captcha'} eq 'recaptcha') {      if ($newsettings->{'captcha'} eq 'recaptcha') {
         $newpub = $env{'form.'.$container.'_recaptchapub'};          $newpub = $env{'form.'.$container.'_recaptchapub'};
         $newpriv = $env{'form.'.$container.'_recaptchapriv'};          $newpriv = $env{'form.'.$container.'_recaptchapriv'};
         $newpub =~ s/\W//g;          $newpub =~ s/[^\w\-]//g;
         $newpriv =~ s/\W//g;          $newpriv =~ s/[^\w\-]//g;
         $newsettings->{'recaptchakeys'} = {          $newsettings->{'recaptchakeys'} = {
                                              public  => $newpub,                                               public  => $newpub,
                                              private => $newpriv,                                               private => $newpriv,
Line 9667  sub modify_coursecategories { Line 9967  sub modify_coursecategories {
             }              }
             $resulttext .= '</ul>';              $resulttext .= '</ul>';
             if ($changes{'unauth'} || $changes{'auth'}) {              if ($changes{'unauth'} || $changes{'auth'}) {
                 &Apache::loncommon::devalidate_domconfig_cache($dom);                  my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   if ($changes{'auth'}) {
                       $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   }
                   if ($changes{'unauth'}) {
                       $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   }
                   my $cachetime = 24*60*60;
                   &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                 if (ref($lastactref) eq 'HASH') {                  if (ref($lastactref) eq 'HASH') {
                     $lastactref->{'domainconfig'} = 1;                      $lastactref->{'domdefaults'} = 1;
                 }                  }
             }              }
         } else {          } else {
Line 10562  sub modify_loadbalancing { Line 10870  sub modify_loadbalancing {
     my ($othertitle,$usertypes,$types) =      my ($othertitle,$usertypes,$types) =
         &Apache::loncommon::sorted_inst_types($dom);          &Apache::loncommon::sorted_inst_types($dom);
     my %servers = &Apache::lonnet::internet_dom_servers($dom);      my %servers = &Apache::lonnet::internet_dom_servers($dom);
       my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
     my @sparestypes = ('primary','default');      my @sparestypes = ('primary','default');
     my %typetitles = &sparestype_titles();      my %typetitles = &sparestype_titles();
     my $resulttext;      my $resulttext;
Line 10653  sub modify_loadbalancing { Line 10962  sub modify_loadbalancing {
                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};                      $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                 }                  }
                 if ($rule eq 'specific') {                  if ($rule eq 'specific') {
                     $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};                      my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
                       if (exists($servers{$specifiedhost})) { 
                           $rule = $specifiedhost;
                       }
                 }                  }
                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;                  $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                 if (ref($currrules{$balancer}) eq 'HASH') {                  if (ref($currrules{$balancer}) eq 'HASH') {
Line 10675  sub modify_loadbalancing { Line 10987  sub modify_loadbalancing {
                                                  \%defaultshash,$dom);                                                   \%defaultshash,$dom);
         if ($putresult eq 'ok') {          if ($putresult eq 'ok') {
             if (keys(%changes) > 0) {              if (keys(%changes) > 0) {
                   my %toupdate;
                 if (ref($changes{'delete'}) eq 'ARRAY') {                  if (ref($changes{'delete'}) eq 'ARRAY') {
                     foreach my $balancer (sort(@{$changes{'delete'}})) {                      foreach my $balancer (sort(@{$changes{'delete'}})) {
                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';                          $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
                         my $cachekey = &escape('loadbalancing').':'.&escape($dom);                          $toupdate{$balancer} = 1;
                         &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);  
                     }                      }
                 }                  }
                 if (ref($changes{'add'}) eq 'ARRAY') {                  if (ref($changes{'add'}) eq 'ARRAY') {
                     foreach my $balancer (sort(@{$changes{'add'}})) {                      foreach my $balancer (sort(@{$changes{'add'}})) {
                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);                          $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
                           $toupdate{$balancer} = 1;
                     }                      }
                 }                  }
                 if (ref($changes{'curr'}) eq 'HASH') {                  if (ref($changes{'curr'}) eq 'HASH') {
                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {                      foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
                           $toupdate{$balancer} = 1;
                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {                          if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                             if ($changes{'curr'}{$balancer}{'targets'}) {                              if ($changes{'curr'}{$balancer}{'targets'}) {
                                 my %offloadstr;                                  my %offloadstr;
Line 10725  sub modify_loadbalancing { Line 11039  sub modify_loadbalancing {
                                         if ($rule eq '') {                                          if ($rule eq '') {
                                             $balancetext =  $ruletitles{'default'};                                              $balancetext =  $ruletitles{'default'};
                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||                                          } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
                                                  ($rule eq 'balancer') || ($rule eq 'offloadedto')) {                                                   ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) { 
                                             $balancetext =  $ruletitles{$rule};                                              if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
                                                   foreach my $sparetype (@sparestypes) {
                                                       if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                                                           map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                                                       }
                                                   }
                                                   foreach my $item (@{$alltypes}) {
                                                       next if ($item =~  /^_LC_ipchange/);
                                                       my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                                                       if ($hasrule eq 'homeserver') {
                                                           map { $toupdate{$_} = 1; } (keys(%libraryservers));
                                                       } else {
                                                           unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                                                               if ($servers{$hasrule}) {
                                                                   $toupdate{$hasrule} = 1;
                                                               }
                                                           }
                                                       }
                                                   }
                                                   if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                                                       $balancetext =  $ruletitles{$rule};
                                                   } else {
                                                       my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                                                       $balancetext = $ruletitles{'particular'}.' '.$receiver;
                                                       if ($receiver) {
                                                           $toupdate{$receiver};
                                                       }
                                                   }
                                               } else {
                                                   $balancetext =  $ruletitles{$rule};
                                               }
                                         } else {                                          } else {
                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});                                              $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                                         }                                          }
Line 10735  sub modify_loadbalancing { Line 11079  sub modify_loadbalancing {
                                 }                                  }
                             }                              }
                         }                          }
                         my $cachekey = &escape('loadbalancing').':'.&escape($dom);                          if (keys(%toupdate)) {
                         &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);                              my %thismachine;
                               my $updatedhere;
                               my $cachetime = 60*60*24;
                               map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                               foreach my $lonhost (keys(%toupdate)) {
                                   if ($thismachine{$lonhost}) {
                                       unless ($updatedhere) {
                                           &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                                                                         $defaultshash{'loadbalancing'},
                                                                         $cachetime);
                                           $updatedhere = 1;
                                       }
                                   } else {
                                       my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                                       &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
                                   }
                               }
                           }
                     }                      }
                 }                  }
                 if ($resulttext ne '') {                  if ($resulttext ne '') {
Line 10877  sub active_dc_picker { Line 11238  sub active_dc_picker {
         my ($dcname,$dcdom) = split(':',$domcoord[0]);          my ($dcname,$dcdom) = split(':',$domcoord[0]);
         my $user = &Apache::loncommon::plainname($dcname,$dcdom);          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].'" />'.$user;
             if ($user ne $dcname.':'.$dcdom) {              if ($user ne $dcname.':'.$dcdom) {
                 $table .=  ' ('.$dcname.':'.$dcdom.')';                  $table .=  ' ('.$dcname.':'.$dcdom.')';
             }              }
Line 10886  sub active_dc_picker { Line 11247  sub active_dc_picker {
             if (exists($currhash{$domcoord[0]})) {              if (exists($currhash{$domcoord[0]})) {
                 $check = ' checked="checked"';                  $check = ' checked="checked"';
             }              }
             $table .= '<span class="LC_nobreak"><label>'.              $table = '<span class="LC_nobreak"><label>'.
                       '<input type="checkbox" name="'.$name.'" '.                       '<input type="checkbox" name="'.$name.'" '.
                       'value="'.$domcoord[0].'"'.$check.' />'.$user;                       'value="'.$domcoord[0].'"'.$check.' />'.$user;
             if ($user ne $dcname.':'.$dcdom) {              if ($user ne $dcname.':'.$dcdom) {
                 $table .=  ' ('.$dcname.':'.$dcdom.')';                  $table .=  ' ('.$dcname.':'.$dcdom.')';
             }              }

Removed from v.1.160.6.44  
changed lines
  Added in v.1.256


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