Diff for /loncom/interface/domainprefs.pm between versions 1.281 and 1.288

version 1.281, 2016/09/21 01:38:50 version 1.288, 2017/01/23 22:46:44
Line 19 Line 19
 #  #
 # You should have received a copy of the GNU General Public License  # You should have received a copy of the GNU General Public License
 # along with LON-CAPA; if not, write to the Free Software  # along with LON-CAPA; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   #
 # /home/httpd/html/adm/gpl.txt  # /home/httpd/html/adm/gpl.txt
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
Line 317  sub handler { Line 318  sub handler {
                     modify => \&modify_directorysrch,                      modify => \&modify_directorysrch,
                   },                    },
         'contacts' =>          'contacts' =>
                   { text => 'Contact Information',                    { text => 'E-mail addresses and helpform',
                     help => 'Domain_Configuration_Contact_Info',                      help => 'Domain_Configuration_Contact_Info',
                     header => [{col1 => 'Setting',                      header => [{col1 => 'Default e-mail addresses',
                                 col2 => 'Value',}],                                  col2 => 'Value',},
                                  {col1 => 'Recipient(s) for notifications',
                                   col2 => 'Value',},
                                  {col1 => 'Ask helpdesk form settings',
                                   col2 => 'Value',},],
                     print => \&print_contacts,                      print => \&print_contacts,
                     modify => \&modify_contacts,                      modify => \&modify_contacts,
                   },                    },
Line 417  sub handler { Line 422  sub handler {
                   modify => \&modify_serverstatuses,                    modify => \&modify_serverstatuses,
                  },                   },
         'helpsettings' =>          'helpsettings' =>
                  {text   => 'Help page settings',                   {text   => 'Support settings',
                   help   => 'Domain_Configuration_Help_Settings',                    help   => 'Domain_Configuration_Help_Settings',
                   header => [{col1 => 'Help Settings (logged-in users)',                    header => [{col1 => 'Help Page Settings (logged-in users)',
                               col2 => 'Value'}],                                col2 => 'Value'},
                                {col1 => 'Helpdesk Roles',
                                 col2 => 'Settings'},],
                   print  => \&print_helpsettings,                    print  => \&print_helpsettings,
                   modify => \&modify_helpsettings,                    modify => \&modify_helpsettings,
                  },                   },
Line 574  $javascript_validations Line 581  $javascript_validations
 $coursebrowserjs  $coursebrowserjs
 END  END
         }          }
           if (grep(/^contacts$/,@actions)) {
               $js .= &contacts_javascript();
           }
         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);          &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
     } else {      } else {
 # check if domconfig user exists for the domain.  # check if domconfig user exists for the domain.
Line 685  sub process_changes { Line 695  sub process_changes {
     } 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') {      } elsif ($action eq 'helpsettings') {
         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);          $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%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 712  sub print_config_box { Line 722  sub print_config_box {
         $output = &coursecategories_javascript($settings);          $output = &coursecategories_javascript($settings);
     } elsif ($action eq 'defaults') {      } elsif ($action eq 'defaults') {
         $output = &defaults_javascript($settings);           $output = &defaults_javascript($settings); 
       } elsif ($action eq 'helpsettings') {
           my (%privs,%levelscurrent);
           my %full=();
           my %levels=(
                        course => {},
                        domain => {},
                        system => {},
                      );
           my $context = 'domain';
           my $crstype = 'Course';
           my $formname = 'display';
           &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
           my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
           $output =
               &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full, 
                                                         \@templateroles);
     }      }
     $output .=      $output .=
          '<table class="LC_nested_outer">           '<table class="LC_nested_outer">
Line 748  sub print_config_box { Line 774  sub print_config_box {
         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 'coursedefaults') ||              ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||              ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
             ($action eq 'directorysrch') || ($action eq 'trust')) {              ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
               ($action eq 'contacts')) {
             $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);
Line 779  sub print_config_box { Line 806  sub print_config_box {
         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||          if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||              ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
             ($action eq 'usersessions') || ($action eq 'coursecategories') ||               ($action eq 'usersessions') || ($action eq 'coursecategories') || 
             ($action eq 'ssl') || ($action eq 'trust')) {              ($action eq 'ssl') || ($action eq 'trust') || ($action eq 'contacts')) {
             if ($action eq 'coursecategories') {              if ($action eq 'coursecategories') {
                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);                  $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                 $colspan = ' colspan="2"';                  $colspan = ' colspan="2"';
Line 836  sub print_config_box { Line 863  sub print_config_box {
             }              }
             $rowtotal ++;              $rowtotal ++;
         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||          } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
                  ($action eq 'defaults') || ($action eq 'directorysrch')) {                   ($action eq 'defaults') || ($action eq 'directorysrch') ||
                    ($action eq 'helpsettings')) {
             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);              $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'login') {          } elsif ($action eq 'login') {
             if ($numheaders == 4) {              if ($numheaders == 4) {
Line 994  sub print_config_box { Line 1022  sub print_config_box {
         if ($action eq 'quotas') {          if ($action eq 'quotas') {
             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);              $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||           } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
                  ($action eq 'contacts') || ($action eq 'serverstatuses') ||                    ($action eq 'serverstatuses') || ($action eq 'loadbalancing') || 
                  ($action eq 'loadbalancing') || ($action eq 'ltitools')) {                   ($action eq 'ltitools')) {
             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);              $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
         } elsif ($action eq 'scantron') {          } elsif ($action eq 'scantron') {
             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);              $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'helpsettings') {  
             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);  
         }          }
     }      }
     $output .= '      $output .= '
Line 2927  sub print_directorysrch { Line 2953  sub print_directorysrch {
 }  }
   
 sub print_contacts {  sub print_contacts {
     my ($dom,$settings,$rowtotal) = @_;      my ($position,$dom,$settings,$rowtotal) = @_;
     my $datatable;      my $datatable;
     my @contacts = ('adminemail','supportemail');      my @contacts = ('adminemail','supportemail');
     my (%checked,%to,%otheremails,%bccemails);      my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',          $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
                     'requestsmail','updatesmail','idconflictsmail');      if ($position eq 'top') {
     foreach my $type (@mailings) {          if (ref($settings) eq 'HASH') {
         $otheremails{$type} = '';              foreach my $item (@contacts) {
     }                  if (exists($settings->{$item})) {
     $bccemails{'helpdeskmail'} = '';                      $to{$item} = $settings->{$item};
     if (ref($settings) eq 'HASH') {                  }
         foreach my $item (@contacts) {  
             if (exists($settings->{$item})) {  
                 $to{$item} = $settings->{$item};  
             }              }
         }          }
       } elsif ($position eq 'middle') {
           @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
                        'updatesmail','idconflictsmail');
         foreach my $type (@mailings) {          foreach my $type (@mailings) {
             if (exists($settings->{$type})) {              $otheremails{$type} = '';
                 if (ref($settings->{$type}) eq 'HASH') {          }
                     foreach my $item (@contacts) {      } else {
                         if ($settings->{$type}{$item}) {          @mailings = ('helpdeskmail','otherdomsmail');
                             $checked{$type}{$item} = ' checked="checked" ';          foreach my $type (@mailings) {
               $otheremails{$type} = '';
           }
           $bccemails{'helpdeskmail'} = '';
           $bccemails{'otherdomsmail'} = '';
           $includestr{'helpdeskmail'} = '';
           $includestr{'otherdomsmail'} = '';
           ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
       }
       if (ref($settings) eq 'HASH') {
           unless ($position eq 'top') {
               foreach my $type (@mailings) {
                   if (exists($settings->{$type})) {
                       if (ref($settings->{$type}) eq 'HASH') {
                           foreach my $item (@contacts) {
                               if ($settings->{$type}{$item}) {
                                   $checked{$type}{$item} = ' checked="checked" ';
                               }
                           }
                           $otheremails{$type} = $settings->{$type}{'others'};
                           if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                               $bccemails{$type} = $settings->{$type}{'bcc'};
                               if ($settings->{$type}{'include'} ne '') {
                                   ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                                   $includestr{$type} = &unescape($includestr{$type});
                               }
                         }                          }
                     }                      }
                     $otheremails{$type} = $settings->{$type}{'others'};                  } elsif ($type eq 'lonstatusmail') {
                     if ($type eq 'helpdeskmail') {                      $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                         $bccemails{$type} = $settings->{$type}{'bcc'};                  }
               }
           }
           if ($position eq 'bottom') {
               foreach my $type (@mailings) {
                   $bccemails{$type} = $settings->{$type}{'bcc'};
                   if ($settings->{$type}{'include'} ne '') {
                       ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                       $includestr{$type} = &unescape($includestr{$type});
                   }
               }
               if (ref($settings->{'helpform'}) eq 'HASH') {
                   if (ref($fields) eq 'ARRAY') {
                       foreach my $field (@{$fields}) {
                           $currfield{$field} = $settings->{'helpform'}{$field};
                       }
                   }
                   if (exists($settings->{'helpform'}{'maxsize'})) {
                       $maxsize = $settings->{'helpform'}{'maxsize'};
                   } else {
                       $maxsize = '1.0'; 
                   }
               } else {
                   if (ref($fields) eq 'ARRAY') {
                       foreach my $field (@{$fields}) {
                           $currfield{$field} = 'yes';
                     }                      }
                 }                  }
             } elsif ($type eq 'lonstatusmail') {                  $maxsize = '1.0';
                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';  
             }              }
         }          }
     } else {      } else {
         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};          if ($position eq 'top') {
         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};              $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';              $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';              $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';              $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';               $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';              $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
         $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';              $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
         $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';              $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
           } elsif ($position eq 'bottom') {
               $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
               $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
               if (ref($fields) eq 'ARRAY') {
                   foreach my $field (@{$fields}) {
                       $currfield{$field} = 'yes';
                   }
               }
               $maxsize = '1.0';
           }
     }      }
     my ($titles,$short_titles) = &contact_titles();      my ($titles,$short_titles) = &contact_titles();
     my $rownum = 0;      my $rownum = 0;
     my $css_class;      my $css_class;
     foreach my $item (@contacts) {      if ($position eq 'top') {
         $css_class = $rownum%2?' class="LC_odd_row"':'';          foreach my $item (@contacts) {
         $datatable .= '<tr'.$css_class.'>'.               $css_class = $rownum%2?' class="LC_odd_row"':'';
                   '<td><span class="LC_nobreak">'.$titles->{$item}.              $datatable .= '<tr'.$css_class.'>'. 
                   '</span></td><td class="LC_right_item">'.                            '<td><span class="LC_nobreak">'.$titles->{$item}.
                   '<input type="text" name="'.$item.'" value="'.                            '</span></td><td class="LC_right_item">'.
                   $to{$item}.'" /></td></tr>';                            '<input type="text" name="'.$item.'" value="'.
         $rownum ++;                            $to{$item}.'" /></td></tr>';
               $rownum ++;
           }
       } else {
           foreach my $type (@mailings) {
               $css_class = $rownum%2?' class="LC_odd_row"':'';
               $datatable .= '<tr'.$css_class.'>'.
                             '<td><span class="LC_nobreak">'.
                             $titles->{$type}.': </span></td>'.
                             '<td class="LC_left_item">';
               if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
               }
               $datatable .= '<span class="LC_nobreak">';
               foreach my $item (@contacts) {
                   $datatable .= '<label>'.
                                 '<input type="checkbox" name="'.$type.'"'.
                                 $checked{$type}{$item}.
                                 ' value="'.$item.'" />'.$short_titles->{$item}.
                                 '</label>&nbsp;';
               }
               $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                             '<input type="text" name="'.$type.'_others" '.
                             'value="'.$otheremails{$type}.'"  />';
               my %locchecked;
               if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   foreach my $loc ('s','b') {
                       if ($includeloc{$type} eq $loc) {
                           $locchecked{$loc} = ' checked="checked"';
                           last;
                       }
                   }
                   $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                                 '<input type="text" name="'.$type.'_bcc" '.
                                 'value="'.$bccemails{$type}.'"  /></fieldset>'.
                                 '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                                 &mt('Text automatically added to e-mail:').' '.
                                 '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
                                 '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                                 '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                                 ('&nbsp;'x2).
                                 '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                                 '</span></fieldset>';
               }
               $datatable .= '</td></tr>'."\n";
               $rownum ++;
           }
     }      }
     foreach my $type (@mailings) {      if ($position eq 'middle') {
           my %choices;
           $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
                                       &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                                       &mt('LON-CAPA core group - MSU'),600,500));
           $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
                                           &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                                           &mt('LON-CAPA core group - MSU'),600,500));
           my @toggles = ('reporterrors','reportupdates');
           my %defaultchecked = ('reporterrors'  => 'on',
                                 'reportupdates' => 'on');
           (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                                                      \%choices,$rownum);
           $datatable .= $reports;
       } elsif ($position eq 'bottom') {
         $css_class = $rownum%2?' class="LC_odd_row"':'';          $css_class = $rownum%2?' class="LC_odd_row"':'';
         $datatable .= '<tr'.$css_class.'>'.          $datatable .= '<tr'.$css_class.'>'.
                       '<td><span class="LC_nobreak">'.                        '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                       $titles->{$type}.': </span></td>'.                        &mt('(e-mail, subject, and description always shown)').
                       '<td class="LC_left_item">'.                        '</td><td class="LC_left_item">';
                       '<span class="LC_nobreak">';          if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') && 
         foreach my $item (@contacts) {              (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
             $datatable .= '<label>'.              $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                           '<input type="checkbox" name="'.$type.'"'.              foreach my $field (@{$fields}) {
                           $checked{$type}{$item}.                  $datatable .= '<tr><td>'.$fieldtitles->{$field};
                           ' value="'.$item.'" />'.$short_titles->{$item}.                  if (($field eq 'screenshot') || ($field eq 'cc')) {
                           '</label>&nbsp;';                      $datatable .= ' '.&mt('(logged-in users)');
         }                  }
         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.                  $datatable .='</td><td>';
                       '<input type="text" name="'.$type.'_others" '.                  my $clickaction;
                       'value="'.$otheremails{$type}.'"  />';                  if ($field eq 'screenshot') {
         if ($type eq 'helpdeskmail') {                      $clickaction = ' onclick="screenshotSize(this);"';
             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).                  }
                           '<input type="text" name="'.$type.'_bcc" '.                  if (ref($possoptions->{$field}) eq 'ARRAY') {
                           'value="'.$bccemails{$type}.'"  />';                      foreach my $option (@{$possoptions->{$field}}) {
                           my $checked;
                           if ($currfield{$field} eq $option) {
                               $checked = ' checked="checked"';
                           }
                           $datatable .= '<span class="LC_nobreak"><label>'.
                                         '<input type="radio" name="helpform_'.$field.'" '.
                                         'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                                         '</label></span>'.('&nbsp;'x2);
                       }
                   }
                   if ($field eq 'screenshot') {
                       my $display;
                       if ($currfield{$field} eq 'no') {
                           $display = ' style="display:none"';
                       }
                       $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
                                     '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                                     '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   }
                   $datatable .= '</td></tr>';
               }
               $datatable .= '</table>';
         }          }
         $datatable .= '</td></tr>'."\n";          $datatable .= '</td></tr>'."\n";
         $rownum ++;          $rownum ++;
     }      }
     my %choices;  
     $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',  
                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',  
                                    &mt('LON-CAPA core group - MSU'),600,500));  
     $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',  
                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',  
                                     &mt('LON-CAPA core group - MSU'),600,500));  
     my @toggles = ('reporterrors','reportupdates');  
     my %defaultchecked = ('reporterrors'  => 'on',  
                           'reportupdates' => 'on');  
     (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,  
                                                \%choices,$rownum);  
     $datatable .= $reports;  
     $$rowtotal += $rownum;      $$rowtotal += $rownum;
     return $datatable;      return $datatable;
 }  }
   
   sub contacts_javascript {
       return <<"ENDSCRIPT";
   
   <script type="text/javascript">
   // <![CDATA[
   
   function screenshotSize(field) {
       if (document.getElementById('help_screenshotsize')) {
           if (field.value == 'no') {
               document.getElementById('help_screenshotsize').style.display="none"; 
           } else {
               document.getElementById('help_screenshotsize').style.display="";
           }
       }
       return;
   }
   
   // ]]>
   </script>
   
   ENDSCRIPT
   }
   
 sub print_helpsettings {  sub print_helpsettings {
     my ($dom,$confname,$settings,$rowtotal) = @_;      my ($position,$dom,$settings,$rowtotal) = @_;
       my $confname = $dom.'-domainconfig';
       my $formname = 'display';
     my ($datatable,$itemcount);      my ($datatable,$itemcount);
     $itemcount = 1;      if ($position eq 'top') {
     my (%choices,%defaultchecked,@toggles);          $itemcount = 1;
     $choices{'submitbugs'} = &mt('Display link to: [_1]?',          my (%choices,%defaultchecked,@toggles);
                                  &Apache::loncommon::modal_link('http://bugs.loncapa.org',          $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                                  &mt('LON-CAPA bug tracker'),600,500));                                       &Apache::loncommon::modal_link('http://bugs.loncapa.org',
     %defaultchecked = ('submitbugs' => 'on');                                       &mt('LON-CAPA bug tracker'),600,500));
     @toggles = ('submitbugs',);          %defaultchecked = ('submitbugs' => 'on');
           @toggles = ('submitbugs');
     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,          ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                                                  \%choices,$itemcount);                                                       \%choices,$itemcount);
           $$rowtotal ++;
       } else {
           my $css_class;
           my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
           my (%customroles,%ordered,%current);
           if (ref($settings->{'adhoc'}) eq 'HASH') {
               %current = %{$settings->{'adhoc'}};
           }
           my $count = 0;
           foreach my $key (sort(keys(%existing))) {
               if ($key=~/^rolesdef\_(\w+)$/) {
                   my $rolename = $1;
                   my (%privs,$order);
                   ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   $customroles{$rolename} = \%privs;
                   if (ref($current{$rolename}) eq 'HASH') {
                       $order = $current{$rolename}{'order'};
                   }
                   if ($order eq '') {
                       $order = $count;
                   }
                   $ordered{$order} = $rolename;
                   $count++;
               }
           }
           my $maxnum = scalar(keys(%ordered));
           my @roles_by_num = ();
           foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
               push(@roles_by_num,$item);
           }
           my $context = 'domprefs';
           my $crstype = 'Course';
           my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
           my @accesstypes = ('all','none');
           my ($numstatustypes,@jsarray);
           if (ref($types) eq 'ARRAY') {
               if (@{$types} > 0) {
                   $numstatustypes = scalar(@{$types});
                   push(@accesstypes,'status');
                   @jsarray = ('bystatus');
               }
           }
           my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh']);
           if (keys(%domhelpdesk)) {
               push(@accesstypes,('inc','exc'));
               push(@jsarray,('notinc','notexc'));
           }
           my $hiddenstr = join("','",@jsarray);
           $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
           my $context = 'domprefs';
           my $crstype = 'Course';
           my $prefix = 'helproles_';
           my $add_class = 'LC_hidden';
           foreach my $num (@roles_by_num) {
               my $role = $ordered{$num};
               my ($desc,$access,@statuses);
               if (ref($current{$role}) eq 'HASH') {
                   $desc = $current{$role}{'desc'};
                   $access = $current{$role}{'access'};
                   if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                       @statuses = @{$current{$role}{'insttypes'}};
                   }
               }
               if ($desc eq '') {
                   $desc = $role;
               }
               my $identifier = 'custhelp'.$num;
               my %full=();
               my %levels= (
                            course => {},
                            domain => {},
                            system => {},
                           );
               my %levelscurrent=(
                                  course => {},
                                  domain => {},
                                  system => {},
                                 );
               &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
               my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
               $css_class = $itemcount%2?' class="LC_odd_row"':'';
               my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
               $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
                             '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
               for (my $k=0; $k<=$maxnum; $k++) {
                   my $vpos = $k+1;
                   my $selstr;
                   if ($k == $num) {
                       $selstr = ' selected="selected" ';
                   }
                   $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
               }
               $datatable .= '</select>'.('&nbsp;'x2).
                             '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                             '</td>'.
                             '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                             &mt('Name shown to users:').
                             '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                             '</fieldset>'.
                             &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                                                   $othertitle,$usertypes,$types,\%domhelpdesk).
                             '<fieldset>'.
                             '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
                             &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
                                                                      \%levelscurrent,$identifier,
                                                                      'LC_hidden',$prefix.$num.'_privs').
                             '</fieldset></td>';
               $itemcount ++;
           }
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           my $newcust = 'custhelp'.$count;
           my (%privs,%levelscurrent);
           my %full=();
           my %levels= (
                        course => {},
                        domain => {},
                        system => {},
                       );
           &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
           my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
           my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
           $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
                         '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                         '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
           for (my $k=0; $k<$maxnum+1; $k++) {
               my $vpos = $k+1;
               my $selstr;
               if ($k == $maxnum) {
                   $selstr = ' selected="selected" ';
               }
               $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
           }
           $datatable .= '</select>&nbsp;'."\n".
                         '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                         '</label></span></td>'.
                         '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                         '<span class="LC_nobreak">'.
                         &mt('Internal name:').
                         '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                         '</span>'.('&nbsp;'x4).
                         '<span class="LC_nobreak">'.
                         &mt('Name shown to users:').
                         '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                         '</span></fieldset>'.
                          &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                                                $usertypes,$types,\%domhelpdesk).
                         '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
                         &Apache::lonuserutils::custom_role_header($context,$crstype,
                                                                   \@templateroles,$newcust).
                         &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                                                                  \%levelscurrent,$newcust).
                         '</fieldset></td></tr>';
           $count ++;
           $$rowtotal += $count;
       }
     return $datatable;      return $datatable;
 }  }
   
   sub adhocbutton {
       my ($prefix,$num,$field,$visibility) = @_;
       my %lt = &Apache::lonlocal::texthash(
                                             show => 'Show details',
                                             hide => 'Hide details',
                                           );
       return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
              '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
              ' value="'.$lt{$visibility}.'" style="height:20px;" '.
              'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
   }
   
   sub helpsettings_javascript {
       my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
       return unless(ref($roles_by_num) eq 'ARRAY');
       my %html_js_lt = &Apache::lonlocal::texthash(
                                             show => 'Show details',
                                             hide => 'Hide details',
                                           );
       &html_escape(\%html_js_lt);
       my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
       return <<"ENDSCRIPT";
   <script type="text/javascript">
   // <![CDATA[
   
   function reorderHelpRoles(form,item) {
       var changedVal;
   $jstext
       var newpos = 'helproles_${total}_pos';
       var maxh = 1 + $total;
       var current = new Array();
       var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
       if (item == newpos) {
           changedVal = newitemVal;
       } else {
           changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
           current[newitemVal] = newpos;
       }
       for (var i=0; i<helproles.length; i++) {
           var elementName = 'helproles_'+helproles[i]+'_pos';
           if (elementName != item) {
               if (form.elements[elementName]) {
                   var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   current[currVal] = elementName;
               }
           }
       }
       var oldVal;
       for (var j=0; j<maxh; j++) {
           if (current[j] == undefined) {
               oldVal = j;
           }
       }
       if (oldVal < changedVal) {
           for (var k=oldVal+1; k<=changedVal ; k++) {
              var elementName = current[k];
              form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
           }
       } else {
           for (var k=changedVal; k<oldVal; k++) {
               var elementName = current[k];
               form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
           }
       }
       return;
   }
   
   function helpdeskAccess(num) {
       var curraccess = null;
       if (document.$formname.elements['helproles_'+num+'_access'].length) {
           for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
               if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
               }
           }
       }
       var shown = Array();
       var hidden = Array();
       if (curraccess == 'none') {
           hidden = Array('$hiddenstr');
       } else {
           if (curraccess == 'status') {
               shown = Array('bystatus');
               hidden = Array('notinc','notexc');
           } else {
               if (curraccess == 'exc') {
                   shown = Array('notexc');
                   hidden = Array('notinc','bystatus');
               }
               if (curraccess == 'inc') {
                   shown = Array('notinc');
                   hidden = Array('notexc','bystatus');
               }
               if (curraccess == 'all') {
                   hidden = Array('notinc','notexc','bystatus');
               }
           }
       }
       if (hidden.length > 0) {
           for (var i=0; i<hidden.length; i++) {
               if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
               }
           }
       }
       if (shown.length > 0) {
           for (var i=0; i<shown.length; i++) {
               if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   if (shown[i] == 'privs') {
                       document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   } else {
                       document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   }
               }
           }
       }
       return;
   }
   
   function toggleHelpdeskItem(num,field) {
       if (document.getElementById('helproles_'+num+'_'+field)) {
           if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
               document.getElementById('helproles_'+num+'_'+field).className = 
                   document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
               if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
               }
           } else {
               document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
               if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
               }
           }
       }
       return;
   }
   
   // ]]>
   </script>
   
   ENDSCRIPT
   }
   
   sub helpdeskroles_access {
       my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
           $usertypes,$types,$domhelpdesk) = @_;
       return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
       my %lt = &Apache::lonlocal::texthash(
                       'rou'    => 'Role usage',
                       'whi'    => 'Which helpdesk personnel may use this role?',
                       'all'    => 'All',
                       'none'   => 'None',
                       'status' => 'Determined based on institutional status',
                       'inc'    => 'Include all, but exclude specific personnel',
                       'exc'    => 'Exclude all, but include specific personnel',
                     );
       my %usecheck = (
                        all => ' checked="checked"',
                      );
       my %displaydiv = (
                         status => 'none',
                         inc    => 'none',
                         exc    => 'none',
                         priv   => 'block',
                        );
       my $output;
       if (ref($current) eq 'HASH') {
           if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
               if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   $usecheck{$current->{access}} = $usecheck{'all'};
                   delete($usecheck{'all'});
                   if ($current->{access} =~ /^(status|inc|exc)$/) {
                       my $access = $1;
                       $displaydiv{$access} = 'inline';
                   } elsif ($current->{access} eq 'none') {
                       $displaydiv{'priv'} = 'none';
                   }
               }
           }
       }
       $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                 '<p>'.$lt{'whi'}.'</p>';
       foreach my $access (@{$accesstypes}) {
           $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                      ' onclick="helpdeskAccess('."'$num'".');" />'.
                      $lt{$access}.'</label>';
           if ($access eq 'status') {
               $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                          &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                                                                    $othertitle,$usertypes,$types).
                          '</div>';
           } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
               $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                          &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                          '</div>';
           } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
               $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                          &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                          '</div>';
           }
           $output .= '</p>';
       }
       $output .= '</fieldset>';
       return $output;
   }
   
 sub radiobutton_prefs {  sub radiobutton_prefs {
     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,      my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
         $additional,$align) = @_;          $additional,$align) = @_;
Line 4599  sub print_loadbalancing { Line 5139  sub print_loadbalancing {
         my ($numspares,@spares) = &count_servers($lonhost,%servers);          my ($numspares,@spares) = &count_servers($lonhost,%servers);
         my @sparestypes = ('primary','default');          my @sparestypes = ('primary','default');
         my %typetitles = &sparestype_titles();          my %typetitles = &sparestype_titles();
           my %hostherechecked = (
                                     no => ' checked="checked"',
                                 );
         foreach my $sparetype (@sparestypes) {          foreach my $sparetype (@sparestypes) {
             my $targettable;              my $targettable;
             for (my $i=0; $i<$numspares; $i++) {              for (my $i=0; $i<$numspares; $i++) {
Line 4644  sub print_loadbalancing { Line 5187  sub print_loadbalancing {
                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.                  $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                                '<table><tr>'.$targettable.'</tr></table><br />';                                 '<table><tr>'.$targettable.'</tr></table><br />';
             }              }
               $hostherechecked{$sparetype} = '';
               if (ref($currtargets{$lonhost}) eq 'HASH') {
                   if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                       if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                           $hostherechecked{$sparetype} = ' checked="checked"';
                           $hostherechecked{'no'} = '';
                       }
                   }
               }
           }
           $datatable .= &mt('Hosting on balancer itself').'<br />'.
                         '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                         $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
           foreach my $sparetype (@sparestypes) {
               $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                             'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                             '</i></label><br />';
         }          }
         $datatable .= '</div></td></tr>'.          $datatable .= '</div></td></tr>'.
                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},                        &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
Line 4861  sub sparestype_titles { Line 5421  sub sparestype_titles {
   
 sub contact_titles {  sub contact_titles {
     my %titles = &Apache::lonlocal::texthash (      my %titles = &Apache::lonlocal::texthash (
                    'supportemail' => 'Support E-mail address',                     'supportemail'    => 'Support E-mail address',
                    'adminemail'   => 'Default Server Admin E-mail address',                     'adminemail'      => 'Default Server Admin E-mail address',
                    'errormail'    => 'Error reports to be e-mailed to',                     'errormail'       => 'Error reports to be e-mailed to',
                    'packagesmail' => 'Package update alerts to be e-mailed to',                     'packagesmail'    => 'Package update alerts to be e-mailed to',
                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',                     'helpdeskmail'    => "Helpdesk requests for this domain's users",
                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',                     'otherdomsmail'   => 'Helpdesk requests for other (unconfigured) domains',  
                    'requestsmail' => 'E-mail from course requests requiring approval',                     'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',                     'requestsmail'    => 'E-mail from course requests requiring approval',
                      'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',                     'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
                  );                   );
     my %short_titles = &Apache::lonlocal::texthash (      my %short_titles = &Apache::lonlocal::texthash (
Line 4878  sub contact_titles { Line 5439  sub contact_titles {
     return (\%titles,\%short_titles);      return (\%titles,\%short_titles);
 }  }
   
   sub helpform_fields {
       my %titles =  &Apache::lonlocal::texthash (
                          'username'   => 'Name',
                          'user'       => 'Username/domain',
                          'phone'      => 'Phone',
                          'cc'         => 'Cc e-mail',
                          'course'     => 'Course Details',
                          'section'    => 'Sections',
                          'screenshot' => 'File upload', 
       );
       my @fields = ('username','phone','user','course','section','cc','screenshot');
       my %possoptions = (
                           username     => ['yes','no','req'],
                           phone        => ['yes','no','req'],   
                           user         => ['yes','no'],
                           cc           => ['yes','no'], 
                           course       => ['yes','no'],
                           section      => ['yes','no'],
                           screenshot   => ['yes','no'],
                         );
       my %fieldoptions = &Apache::lonlocal::texthash (
                            'yes'  => 'Optional',
                            'req'  => 'Required',
                            'no'   => "Not shown",
       );
       return (\@fields,\%titles,\%fieldoptions,\%possoptions);
   }
   
 sub tool_titles {  sub tool_titles {
     my %titles = &Apache::lonlocal::texthash (      my %titles = &Apache::lonlocal::texthash (
                      aboutme    => 'Personal web page',                       aboutme    => 'Personal web page',
Line 8256  sub modify_quotas { Line 8845  sub modify_quotas {
             }              }
             if ($env{'form.validationdc'}) {              if ($env{'form.validationdc'}) {
                 my $newval = $env{'form.validationdc'};                  my $newval = $env{'form.validationdc'};
                 my %domcoords = &get_active_dcs($dom);                  my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
                 if (exists($domcoords{$newval})) {                  if (exists($domcoords{$newval})) {
                     $confhash{'validation'}{'dc'} = $newval;                      $confhash{'validation'}{'dc'} = $newval;
                 }                  }
Line 9513  sub modify_autocreate { Line 10102  sub modify_autocreate {
         $newvals{$item} = 0 if ($newvals{$item} eq '');          $newvals{$item} = 0 if ($newvals{$item} eq '');
     }      }
     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};      $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
     my %domcoords = &get_active_dcs($dom);      my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
     unless (exists($domcoords{$newvals{'xmldc'}})) {      unless (exists($domcoords{$newvals{'xmldc'}})) {
         $newvals{'xmldc'} = '';          $newvals{'xmldc'} = '';
     }       } 
Line 9782  sub modify_contacts { Line 10371  sub modify_contacts {
             $currsetting{$key} = $domconfig{'contacts'}{$key};              $currsetting{$key} = $domconfig{'contacts'}{$key};
         }          }
     }      }
     my (%others,%to,%bcc);      my (%others,%to,%bcc,%includestr,%includeloc);
     my @contacts = ('supportemail','adminemail');      my @contacts = ('supportemail','adminemail');
     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',      my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
                     'requestsmail','updatesmail','idconflictsmail');                      'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
     my @toggles = ('reporterrors','reportupdates');      my @toggles = ('reporterrors','reportupdates');
       my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
     foreach my $type (@mailings) {      foreach my $type (@mailings) {
         @{$newsetting{$type}} =           @{$newsetting{$type}} = 
             &Apache::loncommon::get_env_multiple('form.'.$type);              &Apache::loncommon::get_env_multiple('form.'.$type);
Line 9799  sub modify_contacts { Line 10389  sub modify_contacts {
         }            }  
         $others{$type} = $env{'form.'.$type.'_others'};          $others{$type} = $env{'form.'.$type.'_others'};
         $contacts_hash{contacts}{$type}{'others'} = $others{$type};          $contacts_hash{contacts}{$type}{'others'} = $others{$type};
         if ($type eq 'helpdeskmail') {          if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
             $bcc{$type} = $env{'form.'.$type.'_bcc'};              $bcc{$type} = $env{'form.'.$type.'_bcc'};
             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};              $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
               if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
               }
         }          }
     }      }
     foreach my $item (@contacts) {      foreach my $item (@contacts) {
Line 9813  sub modify_contacts { Line 10408  sub modify_contacts {
             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};              $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
         }          }
     }      }
       if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
           foreach my $field (@{$fields}) {
               if (ref($possoptions->{$field}) eq 'ARRAY') {
                   my $value = $env{'form.helpform_'.$field};
                   $value =~ s/^\s+|\s+$//g;
                   if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
                       $contacts_hash{contacts}{'helpform'}{$field} = $value;
                       if ($field eq 'screenshot') {
                           $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                           if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
                               $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
                           }
                       }
                   }
               }
           }
       }
     if (keys(%currsetting) > 0) {      if (keys(%currsetting) > 0) {
         foreach my $item (@contacts) {          foreach my $item (@contacts) {
             if ($to{$item} ne $currsetting{$item}) {              if ($to{$item} ne $currsetting{$item}) {
Line 9832  sub modify_contacts { Line 10444  sub modify_contacts {
             if ($others{$type} ne $currsetting{$type}{'others'}) {              if ($others{$type} ne $currsetting{$type}{'others'}) {
                 push(@{$changes{$type}},'others');                  push(@{$changes{$type}},'others');
             }              }
             if ($type eq 'helpdeskmail') {                 if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {   
                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {                  if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                     push(@{$changes{$type}},'bcc');                       push(@{$changes{$type}},'bcc'); 
                 }                  }
                   my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                       push(@{$changes{$type}},'include');
                   }
               }
           }
           if (ref($fields) eq 'ARRAY') {
               if (ref($currsetting{'helpform'}) eq 'HASH') {
                   foreach my $field (@{$fields}) {
                       if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                           push(@{$changes{'helpform'}},$field);
                       }
                       if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                           if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                               push(@{$changes{'helpform'}},'maxsize');
                           }
                       }
                   }
               } else {
                   foreach my $field (@{$fields}) {
                       if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                           push(@{$changes{'helpform'}},$field);
                       }
                       if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                           if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                               push(@{$changes{'helpform'}},'maxsize');
                           }
                       }
                   }
             }              }
         }          }
     } else {      } else {
Line 9845  sub modify_contacts { Line 10486  sub modify_contacts {
         $default{'errormail'} = 'adminemail';          $default{'errormail'} = 'adminemail';
         $default{'packagesmail'} = 'adminemail';          $default{'packagesmail'} = 'adminemail';
         $default{'helpdeskmail'} = 'supportemail';          $default{'helpdeskmail'} = 'supportemail';
           $default{'otherdomsmail'} = 'supportemail';
         $default{'lonstatusmail'} = 'adminemail';          $default{'lonstatusmail'} = 'adminemail';
         $default{'requestsmail'} = 'adminemail';          $default{'requestsmail'} = 'adminemail';
         $default{'updatesmail'} = 'adminemail';          $default{'updatesmail'} = 'adminemail';
         foreach my $item (@contacts) {          foreach my $item (@contacts) {
            if ($to{$item} ne $default{$item}) {             if ($to{$item} ne $default{$item}) {
               $changes{$item} = 1;                 $changes{$item} = 1;
            }             }
         }          }
         foreach my $type (@mailings) {          foreach my $type (@mailings) {
             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {              if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                  
                 push(@{$changes{$type}},@{$newsetting{$type}});                  push(@{$changes{$type}},@{$newsetting{$type}});
             }              }
             if ($others{$type} ne '') {              if ($others{$type} ne '') {
                 push(@{$changes{$type}},'others');                  push(@{$changes{$type}},'others');
             }              }
             if ($type eq 'helpdeskmail') {              if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                 if ($bcc{$type} ne '') {                  if ($bcc{$type} ne '') {
                     push(@{$changes{$type}},'bcc');                      push(@{$changes{$type}},'bcc');
                 }                  }
                   if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                       push(@{$changes{$type}},'include');
                   }
             }              }
         }          }
           if (ref($fields) eq 'ARRAY') {
               foreach my $field (@{$fields}) {
                   if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                       push(@{$changes{'helpform'}},$field);
                   }
                   if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                       if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                           push(@{$changes{'helpform'}},'maxsize');
                       }
                   }
               }
           }   
     }      }
     foreach my $item (@toggles) {      foreach my $item (@toggles) {
         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {          if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
Line 9896  sub modify_contacts { Line 10552  sub modify_contacts {
             }              }
             foreach my $type (@mailings) {              foreach my $type (@mailings) {
                 if (ref($changes{$type}) eq 'ARRAY') {                  if (ref($changes{$type}) eq 'ARRAY') {
                     $resulttext .= '<li>'.$titles->{$type}.': ';                      if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                           $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': '; 
                       } else {
                           $resulttext .= '<li>'.$titles->{$type}.': ';
                       }
                     my @text;                      my @text;
                     foreach my $item (@{$newsetting{$type}}) {                      foreach my $item (@{$newsetting{$type}}) {
                         push(@text,$short_titles->{$item});                          push(@text,$short_titles->{$item});
Line 9904  sub modify_contacts { Line 10564  sub modify_contacts {
                     if ($others{$type} ne '') {                      if ($others{$type} ne '') {
                         push(@text,$others{$type});                          push(@text,$others{$type});
                     }                      }
                     $resulttext .= '<span class="LC_cusr_emph">'.                      if (@text) {
                                    join(', ',@text).'</span>';                          $resulttext .= '<span class="LC_cusr_emph">'.
                     if ($type eq 'helpdeskmail') {                                         join(', ',@text).'</span>';
                       }
                       if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                         if ($bcc{$type} ne '') {                          if ($bcc{$type} ne '') {
                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';                              my $bcctext;
                               if (@text) {
                                   $bcctext = '&nbsp;'.&mt('with Bcc to'); 
                               } else {
                                   $bcctext = '(Bcc)';
                               }
                               $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                           } elsif (!@text) {
                               $resulttext .= &mt('No one');
                           }   
                           if ($includestr{$type} ne '') { 
                               if ($includeloc{$type} eq 'b') {
                                   $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                               } elsif ($includeloc{$type} eq 's') {
                                   $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                               }
                         }                          }
                       } elsif (!@text) {
                           $resulttext .= &mt('No recipients');
                     }                      }
                     $resulttext .= '</li>';                      $resulttext .= '</li>';
                 }                  }
Line 9931  sub modify_contacts { Line 10610  sub modify_contacts {
                                         &mt('LON-CAPA core group - MSU'),600,500)).                                          &mt('LON-CAPA core group - MSU'),600,500)).
                                 '</li>';                                  '</li>';
             }              }
               if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   my (@optional,@required,@unused,$maxsizechg);
                   foreach my $field (@{$changes{'helpform'}}) {
                       if ($field eq 'maxsize') {
                           $maxsizechg = 1;
                           next;
                       }
                       if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
                           push(@optional,$field);    
                       } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                           push(@unused,$field);
                       } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
                           push(@required,$field);   
                       }
                   }
                   if (@optional) {
                       $resulttext .= '<li>'.
                                      &mt('Help form fields changed to "Optional": [_1].',
                                          '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                                      '</li>';
                   }
                   if (@required) {
                       $resulttext .= '<li>'.
                                      &mt('Help form fields changed to "Required": [_1].',
                                          '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                                      '</li>';
                   }
                   if (@unused) {
                       $resulttext .= '<li>'.
                                      &mt('Help form fields changed to "Not shown": [_1].',
                                          '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                                      '</li>';
                   }
                   if ($maxsizechg) {
                       $resulttext .= '<li>'.
                                      &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                                          $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                                      '</li>';
   
                   }
               }
             $resulttext .= '</ul>';              $resulttext .= '</ul>';
         } else {          } else {
             $resulttext = &mt('No changes made to contact information');              $resulttext = &mt('No changes made to contacts and form settings');
         }          }
     } else {      } else {
         $resulttext = '<span class="LC_error">'.          $resulttext = '<span class="LC_error">'.
Line 11699  sub modify_serverstatuses { Line 12419  sub modify_serverstatuses {
 }  }
   
 sub modify_helpsettings {  sub modify_helpsettings {
     my ($r,$dom,$confname,%domconfig) = @_;      my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
     my ($resulttext,$errors,%changes,%helphash);      my ($resulttext,$errors,%changes,%helphash);
     my %defaultchecked = ('submitbugs' => 'on');      my %defaultchecked = ('submitbugs' => 'on');
     my @offon = ('off','on');      my @offon = ('off','on');
     my @toggles = ('submitbugs');      my @toggles = ('submitbugs');
       my %current = ('submitbugs' => '',
                      'adhoc'      => {},
                     );
     if (ref($domconfig{'helpsettings'}) eq 'HASH') {      if (ref($domconfig{'helpsettings'}) eq 'HASH') {
         foreach my $item (@toggles) {          %current = %{$domconfig{'helpsettings'}};
             if ($defaultchecked{$item} eq 'on') {       }
                 if ($domconfig{'helpsettings'}{$item} eq '') {      my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                     if ($env{'form.'.$item} eq '0') {      foreach my $item (@toggles) {
                         $changes{$item} = 1;          if ($defaultchecked{$item} eq 'on') { 
                     }              if ($current{$item} eq '') {
                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {                  if ($env{'form.'.$item} eq '0') {
                     $changes{$item} = 1;                      $changes{$item} = 1;
                 }                  }
             } elsif ($defaultchecked{$item} eq 'off') {              } elsif ($current{$item} ne $env{'form.'.$item}) {
                 if ($domconfig{'helpsettings'}{$item} eq '') {                  $changes{$item} = 1;
                     if ($env{'form.'.$item} eq '1') {              }
                         $changes{$item} = 1;          } elsif ($defaultchecked{$item} eq 'off') {
                     }              if ($current{$item} eq '') {
                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {                  if ($env{'form.'.$item} eq '1') {
                     $changes{$item} = 1;                      $changes{$item} = 1;
                 }                  }
               } elsif ($current{$item} ne $env{'form.'.$item}) {
                   $changes{$item} = 1;
               }
           }
           if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
               $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
           }
       }
       my $maxnum = $env{'form.helproles_maxnum'};
       my $confname = $dom.'-domainconfig';
       my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
       my (@allpos,%newsettings,%changedprivs,$newrole);
       my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
       my @accesstypes = ('all','none','status','inc','exc');
       my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh']);
       my %lt = &Apache::lonlocal::texthash(
                       s      => 'system',
                       d      => 'domain',
                       order  => 'Display order',
                       access => 'Role usage',
                       all    => 'All',
                       none   => 'None',
                       status => 'Determined based on institutional status',
                       inc    => 'Include all, but exclude specific personnel',
                       exc    => 'Exclude all, but include specific personnel',
       );
       for (my $num=0; $num<=$maxnum; $num++) {
           my ($prefix,$identifier,$rolename,%curr);
           if ($num == $maxnum) {
               next unless ($env{'form.newcusthelp'} == $maxnum);
               $identifier = 'custhelp'.$num;
               $prefix = 'helproles_'.$num;
               $rolename = $env{'form.custhelpname'.$num};
               $rolename=~s/[^A-Za-z0-9]//gs;
               next if ($rolename eq '');
               next if (exists($existing{'rolesdef_'.$rolename}));
               my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
               my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                                                        $newprivs{'c'},$confname,$dom);
               if ($result ne 'ok') {
                   $errors .= '<li><span class="LC_error">'.
                              &mt('An error occurred storing the new custom role: [_1]',
                              $result).'</span></li>';
                   next;
               } else {
                   $changedprivs{$rolename} = \%newprivs;
                   $newrole = $rolename;
               }
           } else {
               $prefix = 'helproles_'.$num;
               $rolename = $env{'form.'.$prefix};
               next if ($rolename eq '');
               next unless (exists($existing{'rolesdef_'.$rolename}));
               $identifier = 'custhelp'.$num;
               my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
               my %currprivs;
               ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) = 
                   split(/\_/,$existing{'rolesdef_'.$rolename});
               foreach my $level ('c','d','s') {
                   if ($newprivs{$level} ne $currprivs{$level}) {
                       my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                                                                $newprivs{'c'},$confname,$dom);
                       if ($result ne 'ok') {
                           $errors .= '<li><span class="LC_error">'.
                                      &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                                          $rolename,$result).'</span></li>';
                       } else {
                           $changedprivs{$rolename} = \%newprivs;
                       }
                       last;
                   }
               }
               if (ref($current{'adhoc'}) eq 'HASH') {
                   if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                       %curr = %{$current{'adhoc'}{$rolename}};
                   }
               }
           }
           my $newpos = $env{'form.'.$prefix.'_pos'};
           $newpos =~ s/\D+//g;
           $allpos[$newpos] = $rolename;
           my $newdesc = $env{'form.'.$prefix.'_desc'};
           $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
           if ($curr{'desc'}) {
               if ($curr{'desc'} ne $newdesc) {
                   $changes{'customrole'}{$rolename}{'desc'} = 1;
                   $newsettings{$rolename}{'desc'} = $newdesc;
               }
           } elsif ($newdesc ne '') {
               $changes{'customrole'}{$rolename}{'desc'} = 1;
               $newsettings{$rolename}{'desc'} = $newdesc;
           }
           my $access = $env{'form.'.$prefix.'_access'};
           if (grep(/^\Q$access\E$/,@accesstypes)) {
               $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
               if ($access eq 'status') {
                   my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   if (scalar(@statuses) == 0) {
                       $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none'; 
                   } else {
                       my (@shownstatus,$numtypes);
                       $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                       if (ref($types) eq 'ARRAY') {
                           $numtypes = scalar(@{$types});
                           foreach my $type (sort(@statuses)) {
                               if ($type eq 'default') {
                                   push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                               } elsif (grep(/^\Q$type\E$/,@{$types})) {
                                   push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                                   push(@shownstatus,$usertypes->{$type});
                               }
                           }
                       }
                       if (grep(/^default$/,@statuses)) {
                           push(@shownstatus,$othertitle);
                       }
                       if (scalar(@shownstatus) == 1+$numtypes) {
                           $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                           delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                       } else {
                           $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                           if (ref($curr{'status'}) eq 'ARRAY') {
                               my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                               if (@diffs) {
                                   $changes{'customrole'}{$rolename}{$access} = 1;
                               }
                           } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                               $changes{'customrole'}{$rolename}{$access} = 1;
                           }
                       }
                   }
               } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   my @newspecstaff;
                   $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   foreach my $person (sort(@personnel)) {
                       if ($domhelpdesk{$person}) {
                           push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                       }
                   }
                   if (ref($curr{$access}) eq 'ARRAY') {
                       my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                       if (@diffs) {
                           $changes{'customrole'}{$rolename}{$access} = 1;
                       }
                   } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                       $changes{'customrole'}{$rolename}{$access} = 1;
                   }
                   foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                       my ($uname,$udom) = split(/:/,$person);
                           push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   }
                   $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
             }              }
             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {          } else {
                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};              $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
           }
           unless ($curr{'access'} eq $access) {
               $changes{'customrole'}{$rolename}{'access'} = 1;
               $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
           }
       }
       if (@allpos > 0) {
           my $idx = 0;
           foreach my $rolename (@allpos) {
               if ($rolename ne '') {
                   $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   if (ref($current{'adhoc'}) eq 'HASH') {
                       if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                           if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                               $changes{'customrole'}{$rolename}{'order'} = 1;
                               $newsettings{$rolename}{'order'} = $idx+1; 
                           }
                       }
                   }
                   $idx ++;
             }              }
         }          }
     }      }
Line 11732  sub modify_helpsettings { Line 12628  sub modify_helpsettings {
     if (keys(%changes) > 0) {      if (keys(%changes) > 0) {
         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);          $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
         if ($putresult eq 'ok') {          if ($putresult eq 'ok') {
             $resulttext = &mt('Changes made:').'<ul>';              if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                       $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   }
               }
               my $cachetime = 24*60*60;
               &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
               if (ref($lastactref) eq 'HASH') {
                   $lastactref->{'domdefaults'} = 1;
               }
           } else {
               $errors .= '<li><span class="LC_error">'.
                          &mt('An error occurred storing the settings: [_1]',
                              $putresult).'</span></li>';
           }
       }
       if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
           $resulttext = &mt('Changes made:').'<ul>';
           my (%shownprivs,@levelorder);
           @levelorder = ('c','d','s');
           if ((keys(%changes)) && ($putresult eq 'ok')) {
             foreach my $item (sort(keys(%changes))) {              foreach my $item (sort(keys(%changes))) {
                 if ($item eq 'submitbugs') {                  if ($item eq 'submitbugs') {
                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',                      $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',                                                &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';                                                &mt('LON-CAPA bug tracker'),600,500)).'</li>';
                   } elsif ($item eq 'customrole') {
                       if (ref($changes{'customrole'}) eq 'HASH') {
                           my @keyorder = ('order','desc','access','status','exc','inc');
                           my %keytext = &Apache::lonlocal::texthash(
                                                                      order  => 'Order',
                                                                      desc   => 'Role description',
                                                                      access => 'Role usage',
                                                                      status => 'Allowed instituional types',
                                                                      exc    => 'Allowed personnel',
                                                                      inc    => 'Disallowed personnel',
                           );
                           foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
                               if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                                   if ($role eq $newrole) {
                                       $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                                                                 $role).'<ul>';
                                   } else {
                                       $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                                                                 $role).'<ul>';
                                   }
                                   foreach my $key (@keyorder) {
                                       if ($changes{'customrole'}{$role}{$key}) {
                                           $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                                                                     $keytext{$key},$newsettings{$role}{$key}).
                                                          '</li>';
                                       }
                                   }
                                   if (ref($changedprivs{$role}) eq 'HASH') {
                                       $shownprivs{$role} = 1;
                                       $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                                       foreach my $level (@levelorder) {
                                           foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                                               next if ($item eq '');
                                               my ($priv) = split(/\&/,$item,2);
                                               if (&Apache::lonnet::plaintext($priv)) {
                                                   $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                                                   unless ($level eq 'c') {
                                                       $resulttext .= ' ('.$lt{$level}.')';
                                                   }
                                                   $resulttext .= '</li>';
                                               }
                                           }
                                       }
                                       $resulttext .= '</ul>';
                                   }
                                   $resulttext .= '</ul></li>';
                               }
                           }
                       }
                 }                  }
             }              }
             $resulttext .= '</ul>';  
         } else {  
             $resulttext = &mt('No changes made to help settings');  
             $errors .= '<li><span class="LC_error">'.  
                        &mt('An error occurred storing the settings: [_1]',  
                            $putresult).'</span></li>';  
         }          }
           if (keys(%changedprivs)) {
               foreach my $role (sort(keys(%changedprivs))) {
                   unless ($shownprivs{$role}) {
                       $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                                                 $role).'<ul>'.
                                      '<li>'.&mt('Privileges set to :').'<ul>';
                       foreach my $level (@levelorder) {
                           foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                               next if ($item eq '');
                               my ($priv) = split(/\&/,$item,2);
                               if (&Apache::lonnet::plaintext($priv)) {
                                   $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                                   unless ($level eq 'c') {
                                       $resulttext .= ' ('.$lt{$level}.')';
                                   }
                                   $resulttext .= '</li>';
                               }
                           }
                       }
                       $resulttext .= '</ul></li></ul></li>';
                   }
               }
           }
           $resulttext .= '</ul>';
       } else {
           $resulttext = &mt('No changes made to help settings');
     }      }
     if ($errors) {      if ($errors) {
         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.          $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
                        $errors.'</ul>';                                      $errors.'</ul>';
     }      }
     return $resulttext;      return $resulttext;
 }  }
Line 13045  sub modify_loadbalancing { Line 14031  sub modify_loadbalancing {
                         push(@offloadto,$target);                          push(@offloadto,$target);
                     }                      }
                 }                  }
                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;  
             }              }
               if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                       push(@offloadto,$balancer);
                   }
               }
               $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
         }          }
         if (ref($currtargets{$balancer}) eq 'HASH') {          if (ref($currtargets{$balancer}) eq 'HASH') {
             foreach my $sparetype (@sparestypes) {              foreach my $sparetype (@sparestypes) {
Line 13280  sub recurse_cat_deletes { Line 14271  sub recurse_cat_deletes {
     return;      return;
 }  }
   
 sub get_active_dcs {  
     my ($dom) = @_;  
     my $now = time;  
     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);  
     my %domcoords;  
     my $numdcs = 0;  
     foreach my $server (keys(%dompersonnel)) {  
         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {  
             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);  
             $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};  
         }  
     }  
     return %domcoords;  
 }  
   
 sub active_dc_picker {  sub active_dc_picker {
     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;      my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
     my %domcoords = &get_active_dcs($dom);      my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
     my @domcoord = keys(%domcoords);      my @domcoord = keys(%domcoords);
     if (keys(%currhash)) {      if (keys(%currhash)) {
         foreach my $dc (keys(%currhash)) {          foreach my $dc (keys(%currhash)) {

Removed from v.1.281  
changed lines
  Added in v.1.288


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