Diff for /loncom/interface/domainprefs.pm between versions 1.13 and 1.21

version 1.13, 2007/05/02 01:33:48 version 1.21, 2007/06/07 23:19:42
Line 133  sub handler { Line 133  sub handler {
         my %helphash;             my %helphash;   
         my $numprefs = @prefs;          my $numprefs = @prefs;
         &print_header($r,$phase);          &print_header($r,$phase);
           if (keys(%domconfig) == 0) {
               my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
               my $perlvarref = &LONCAPA::Configuration::read_conf('loncapa.conf');
               my $hostid = $perlvarref->{'lonHostID'};
               if ($hostid ne $primarylibserv) {
                   my %designhash = &Apache::loncommon::get_domainconf($dom);
                   my @loginimages = ('img','logo','domlogo');
                   my $custom_img_count = 0;
                   foreach my $img (@loginimages) {
                       if ($designhash{$dom.'.login.'.$img} ne '') {
                           $custom_img_count ++;
                       }
                   }
                   foreach my $role (@roles) {
                       if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                           $custom_img_count ++;
                       }
                   }
                   if ($custom_img_count > 0) {
                       my $switch_server = &check_switchserver($dom,$confname);
                       $r->print(&mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.&mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.&mt("Thereafter, you will be able to update settings from this screen when logged in to any server in the LON-CAPA network (with a DC role selected in the domain), although you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />'.$switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
                       return OK;
                   }
               }
           }
         $r->print('<table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');          $r->print('<table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
         foreach my $item (@prefs) {          foreach my $item (@prefs) {
             if ($item->{'action'} eq 'login') {              if ($item->{'action'} eq 'login') {
Line 522  sub display_color_options { Line 547  sub display_color_options {
                   '</span></td></tr>';                    '</span></td></tr>';
     my $switchserver = &check_switchserver($dom,$confname);      my $switchserver = &check_switchserver($dom,$confname);
     foreach my $img (@{$images}) {      foreach my $img (@{$images}) {
         $itemcount ++;   $itemcount ++;
         $css_class = $itemcount%2?' class="LC_odd_row"':'';          $css_class = $itemcount%2?' class="LC_odd_row"':'';
         $datatable .= '<tr'.$css_class.'>'.          $datatable .= '<tr'.$css_class.'>'.
                       '<td>'.$choices->{$img}.'</td>';                        '<td>'.$choices->{$img}.'</td>';
         my $imgfile;          my ($imgfile, $img_import);
         if ($designs->{$img} ne '') {          if ($designs->{$img} ne '') {
             $imgfile = $designs->{$img};              $imgfile = $designs->{$img};
       $img_import = ($imgfile =~ m{^/adm/});
         } else {          } else {
             $imgfile = $defaults->{$img};              $imgfile = $defaults->{$img};
         }          }
Line 550  sub display_color_options { Line 576  sub display_color_options {
                     $showfile = '';                      $showfile = '';
                 }                  }
             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {              } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
                   $showfile = $imgfile;
                 my $imgdir = $1;                  my $imgdir = $1;
                 my $filename = $2;                  my $filename = $2;
                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {                  if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
Line 559  sub display_color_options { Line 586  sub display_color_options {
                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;                      my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
                     if (!-e $output) {                      if (!-e $output) {
                         my ($width,$height) = &thumb_dimensions();                          my ($width,$height) = &thumb_dimensions();
                         my $size = $width.'x'.$height;                          my ($fullwidth,$fullheight) = &check_dimensions($input);
                         system("convert -sample $size $input $output");                          if ($fullwidth ne '' && $fullheight ne '') {
                               if ($fullwidth > $width && $fullheight > $height) { 
                                   my $size = $width.'x'.$height;
                                   system("convert -sample $size $input $output");
                                   $showfile = '/'.$imgdir.'/tn-'.$filename;
                               }
                           }
                     }                      }
                     $showfile = '/'.$imgdir.'/tn-'.$filename;  
                 }                  }
             }               }
             if ($showfile) {              if ($showfile) {
                 $showfile = &Apache::loncommon::lonhttpdurl($showfile);                  $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                 $fullsize =  &Apache::loncommon::lonhttpdurl($imgfile);                  $fullsize =  &Apache::loncommon::lonhttpdurl($imgfile);
Line 572  sub display_color_options { Line 604  sub display_color_options {
                 if (!$is_custom->{$img}) {                  if (!$is_custom->{$img}) {
                     $datatable .= &mt('Default in use:').'<br />';                      $datatable .= &mt('Default in use:').'<br />';
                 }                  }
    if ($img_import) {
       $datatable.= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
    }
                 $datatable.= '<a href="'.$fullsize.'" target="_blank"><img src="'.                  $datatable.= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                              $showfile.'" alt="'.$alt_text->{$img}.                               $showfile.'" alt="'.$alt_text->{$img}.
                              '" border="0" /></a></td>';                               '" border="0" /></a></td>';
Line 733  sub print_quotas { Line 768  sub print_quotas {
     $datatable .= '<tr'.$css_class.'>'.      $datatable .= '<tr'.$css_class.'>'.
                   '<td>'.&mt($othertitle).'</td>'.                    '<td>'.&mt($othertitle).'</td>'.
                   '<td class="LC_right_item"><span class="LC_nobreak">'.                    '<td class="LC_right_item"><span class="LC_nobreak">'.
                   '<input type="text" name="default" value="'.                    '<input type="text" name="defaultquota" value="'.
                   $defaultquota.'" size="5" /> Mb</span></td></tr>';                    $defaultquota.'" size="5" /> Mb</span></td></tr>';
     return $datatable;      return $datatable;
 }  }
   
 sub print_autoenroll {  sub print_autoenroll {
     my ($dom,$settings) = @_;      my ($dom,$settings) = @_;
     my $defdom = $dom;  
     my $autorun = &Apache::lonnet::auto_run(undef,$dom),      my $autorun = &Apache::lonnet::auto_run(undef,$dom),
     my ($runon,$runoff);      my ($defdom,$runon,$runoff);
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
         if (exists($settings->{'run'})) {          if (exists($settings->{'run'})) {
             if ($settings->{'run'} eq '0') {              if ($settings->{'run'} eq '0') {
Line 764  sub print_autoenroll { Line 798  sub print_autoenroll {
         if (exists($settings->{'sender_domain'})) {          if (exists($settings->{'sender_domain'})) {
             $defdom = $settings->{'sender_domain'};              $defdom = $settings->{'sender_domain'};
         }          }
       } else {
           if ($autorun) {
               $runon = ' checked="checked" ';
               $runoff = ' ';
           } else {
               $runoff = ' checked="checked" ';
               $runon = ' ';
           }
     }      }
     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);      my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
     my $datatable='<tr class="LC_odd_row">'.      my $datatable='<tr class="LC_odd_row">'.
Line 772  sub print_autoenroll { Line 814  sub print_autoenroll {
                   '<input type="radio" name="autoenroll_run"'.                    '<input type="radio" name="autoenroll_run"'.
                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.                    $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   '<label><input type="radio" name="autoenroll_run"'.                    '<label><input type="radio" name="autoenroll_run"'.
                   $runoff.'value="0" />'.&mt('No').'</label></span></td>'.                    $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   '</tr><tr>'.                    '</tr><tr>'.
                   '<td>'.&mt('Notification messages - sender').                    '<td>'.&mt('Notification messages - sender').
                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.                    '</td><td class="LC_right_item"><span class="LC_nobreak">'.
Line 836  sub print_autoupdate { Line 878  sub print_autoupdate {
         if (keys(%{$usertypes}) > 0) {          if (keys(%{$usertypes}) > 0) {
             $othertitle = &mt('Other users');              $othertitle = &mt('Other users');
         }          }
         my @fields = ('lastname','firstname','middlename','gen','email','id');          my @fields = ('lastname','firstname','middlename','gen',
                         'permanentemail','id');
         my %fieldtitles = &Apache::lonlocal::texthash (          my %fieldtitles = &Apache::lonlocal::texthash (
                             id => 'Student/Employee ID',                              id => 'Student/Employee ID',
                             email => 'E-mail address',                              permanentemail => 'E-mail address',
                             lastname => 'Last Name',                              lastname => 'Last Name',
                             firstname => 'First Name',                              firstname => 'First Name',
                             middlename => 'Middle Name',                              middlename => 'Middle Name',
Line 1039  sub modify_colors { Line 1082  sub modify_colors {
         }          }
         my ($width,$height) = &thumb_dimensions();          my ($width,$height) = &thumb_dimensions();
         foreach my $img (@images) {          foreach my $img (@images) {
       if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
    && !defined($domconfig->{$role}{$img})
    && !$env{'form.'.$role.'_del_'.$img}
    && $env{'form.'.$role.'_import_'.$img}) {
    # import the old configured image from the .tab setting
    # if they haven't provided a new one 
    $domconfig->{$role}{$img} = 
       $env{'form.'.$role.'_import_'.$img};
       }
             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {              if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
                 my $error;                  my $error;
                 if ($configuserok eq 'ok') {                  if ($configuserok eq 'ok') {
Line 1078  sub modify_colors { Line 1130  sub modify_colors {
                                             $dom,$confname,$img,$width,$height);                                              $dom,$confname,$img,$width,$height);
                                 if ($result eq 'ok') {                                  if ($result eq 'ok') {
                                     $confhash->{$role}{$img} = $logourl;                                      $confhash->{$role}{$img} = $logourl;
       $changes{$role}{'images'}{$img} = 1;
                                 }                                  }
                             }                              }
                         }                          }
Line 1229  sub thumb_dimensions { Line 1282  sub thumb_dimensions {
     return ('200','50');      return ('200','50');
 }  }
   
   sub check_dimensions {
       my ($inputfile) = @_;
       my ($fullwidth,$fullheight);
       if ($inputfile =~ m|^[/\w.\-]+$|) {
           if (open(PIPE,"identify $inputfile 2>&1 |")) {
               my $imageinfo = <PIPE>;
               if (!close(PIPE)) {
                   &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
               }
               chomp($imageinfo);
               my ($fullsize) = 
                   ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
               if ($fullsize) {
                   ($fullwidth,$fullheight) = split(/x/,$fullsize);
               }
           }
       }
       return ($fullwidth,$fullheight);
   }
   
 sub check_configuser {  sub check_configuser {
     my ($uhome,$dom,$confname,$servadm) = @_;      my ($uhome,$dom,$confname,$servadm) = @_;
     my ($configuserok,%currroles);      my ($configuserok,%currroles);
Line 1361  $env{'user.name'}.':'.$env{'user.domain' Line 1434  $env{'user.name'}.':'.$env{'user.domain'
             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {              if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                 my $inputfile = $filepath.'/'.$file;                  my $inputfile = $filepath.'/'.$file;
                 my $outfile = $filepath.'/'.'tn-'.$file;                  my $outfile = $filepath.'/'.'tn-'.$file;
                 my $thumbsize = $thumbwidth.'x'.$thumbheight;                  my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                 system("convert -sample $thumbsize $inputfile $outfile");                  if ($fullwidth ne '' && $fullheight ne '') { 
                 chmod(0660, $filepath.'/tn-'.$file);                      if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                 if (-e $outfile) {                          my $thumbsize = $thumbwidth.'x'.$thumbheight;
                     my $copyfile=$targetdir.'/tn-'.$file;                          system("convert -sample $thumbsize $inputfile $outfile");
                     if (copy($outfile,$copyfile)) {                          chmod(0660, $filepath.'/tn-'.$file);
                         print $logfile "\nCopied source to ".$copyfile."\n";                          if (-e $outfile) {
                         &write_metadata($dom,$confname,$formname,$targetdir,                              my $copyfile=$targetdir.'/tn-'.$file;
                                         'tn-'.$file,$logfile);                              if (copy($outfile,$copyfile)) {
                     } else {                                  print $logfile "\nCopied source to ".$copyfile."\n";
                         print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";                                  &write_metadata($dom,$confname,$formname,
                                                   $targetdir,'tn-'.$file,$logfile);
                               } else {
                                   print $logfile "\nUnable to write ".$copyfile.
                                                  ':'.$!."\n";
                               }
                           }
                     }                      }
                 }                  }
             }              }
Line 1483  sub modify_quotas { Line 1562  sub modify_quotas {
             $formhash{$1} = $env{$key};              $formhash{$1} = $env{$key};
         }          }
     }      }
       $formhash{'default'} = $env{'form.defaultquota'};
     if (ref($domconfig{'quotas'}) eq 'HASH') {      if (ref($domconfig{'quotas'}) eq 'HASH') {
         foreach my $key (keys(%{$domconfig{'quotas'}})) {          foreach my $key (keys(%{$domconfig{'quotas'}})) {
             if (exists($formhash{$key})) {              if (exists($formhash{$key})) {
Line 1536  sub modify_autoenroll { Line 1616  sub modify_autoenroll {
     my %title = ( run => 'Auto-enrollment active',      my %title = ( run => 'Auto-enrollment active',
                   sender => 'Sender for notification messages');                    sender => 'Sender for notification messages');
     my @offon = ('off','on');      my @offon = ('off','on');
       my $sender_uname = $env{'form.sender_uname'};
       my $sender_domain = $env{'form.sender_domain'};
       if ($sender_domain eq '') {
           $sender_uname = '';
       } elsif ($sender_uname eq '') {
           $sender_domain = '';
       }
     my %autoenrollhash =  (      my %autoenrollhash =  (
                        autoenroll => { run => $env{'form.autoenroll_run'},                         autoenroll => { run => $env{'form.autoenroll_run'},
                                        sender_uname => $env{'form.sender_uname'},                                         sender_uname => $sender_uname,
                                        sender_domain => $env{'form.sender_domain'},                                         sender_domain => $sender_domain,
   
                                 }                                  }
                      );                       );
Line 1555  sub modify_autoenroll { Line 1642  sub modify_autoenroll {
                 $changes{'run'} = 1;                  $changes{'run'} = 1;
             }              }
         }          }
         if (exists($currautoenroll{sender_uname})) {          if ($currautoenroll{'sender_uname'} ne $sender_uname) {
             if ($currautoenroll{'sender_uname'} ne $env{'form.sender_uname'}) {  
                 $changes{'sender'} = 1;  
             }  
         } else {  
             $changes{'sender'} = 1;              $changes{'sender'} = 1;
         }          }
         if (exists($currautoenroll{sender_domain})) {          if ($currautoenroll{'sender_domain'} ne $sender_domain) {
             if ($currautoenroll{'sender_domain'} ne $env{'form.sender_domain'}) {  
                 $changes{'sender'} = 1;  
             }  
         } else {  
             $changes{'sender'} = 1;              $changes{'sender'} = 1;
         }          }
         if (keys(%changes) > 0) {          if (keys(%changes) > 0) {
Line 1575  sub modify_autoenroll { Line 1654  sub modify_autoenroll {
                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';                  $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
             }              }
             if ($changes{'sender'}) {              if ($changes{'sender'}) {
                 $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$env{'form.sender_uname'}.':'.$env{'form.sender_domain'}).'</li>';                  if ($sender_uname eq '' || $sender_domain eq '') {
                       $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   } else {
                       $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   }
             }              }
             $resulttext .= '</ul>';              $resulttext .= '</ul>';
         } else {          } else {
Line 1604  sub modify_autoupdate { Line 1687  sub modify_autoupdate {
     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);      my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
     my %fieldtitles = &Apache::lonlocal::texthash (      my %fieldtitles = &Apache::lonlocal::texthash (
                         id => 'Student/Employee ID',                          id => 'Student/Employee ID',
                         email => 'E-mail address',                          permanentemail => 'E-mail address',
                         lastname => 'Last Name',                          lastname => 'Last Name',
                         firstname => 'First Name',                          firstname => 'First Name',
                         middlename => 'Middle Name',                          middlename => 'Middle Name',

Removed from v.1.13  
changed lines
  Added in v.1.21


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