[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm

raeburn raeburn at source.lon-capa.org
Sat Aug 25 17:48:12 EDT 2012


raeburn		Sat Aug 25 21:48:12 2012 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
  Log:
  - Domain configuration for help pages.
     - Code re-use (radiobutton_prefs) in &print_helpsettings().
     - Overhaul coding style in &modify_helpsettings().
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.165 loncom/interface/domainprefs.pm:1.166
--- loncom/interface/domainprefs.pm:1.165	Sat Aug 25 04:34:44 2012
+++ loncom/interface/domainprefs.pm	Sat Aug 25 21:48:12 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.165 2012/08/25 04:34:44 raeburn Exp $
+# $Id: domainprefs.pm,v 1.166 2012/08/25 21:48:12 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -353,10 +353,10 @@
         'helpsettings' =>
                  {text   => 'Help page settings',
                   help   => 'Domain_Configuration_Help_Settings',
-                  header => [{col1 => 'Authenticated Help Settings',
-                              col2 => ''},
-                             {col1 => 'Unauthenticated Help Settings',
-                              col2 => ''}],
+                  header => [{col1 => 'Help Settings (logged-in users)',
+                              col2 => 'Value'},
+                             {col1 => 'Help Settings (before log-in)',
+                              col2 => 'Value'}],
                  },
         'coursedefaults' => 
                  {text => 'Course/Community defaults',
@@ -533,7 +533,7 @@
     if ($numheaders > 1) {
         my $colspan = '';
         my $rightcolspan = '';
-        if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
+        if (($action eq 'rolecolors') || ($action eq 'coursecategories')) {
             $colspan = ' colspan="2"';
         }
         if ($action eq 'usersessions') {
@@ -2263,103 +2263,70 @@
 }
 
 sub print_helpsettings {
+    my ($position,$dom,$confname,$settings,$rowtotal) = @_;
+    my ($css_class,$datatable,$itemcount);
+    my $switchserver = &check_switchserver($dom,$confname);
+    $itemcount = 1;
+    if ($position eq 'top') {
+        my (%checkedon,%checkedoff,%choices,%defaultchecked, at toggles,$align);
+        $choices{'submitbugs'} = &mt('Display link to: [_1]?',
+                                     &Apache::loncommon::modal_link('http://bugs.loncapa.org',
+                                     &mt('LON-CAPA bug tracker'),600,500));
+        %defaultchecked = ('submitbugs' => 'on');
+        @toggles = ('submitbugs',);
+        $align = 'LC_left_item';
 
-	my ($position,$dom,$confname,$settings,$rowtotal) = @_;
-	my ($css_class,$datatable);
-	
-	my $switchserver = &check_switchserver($dom,$confname);
-	
-	my $itemcount = 1;
-	
-	if ($position eq 'top') {
-		
-		my (%checkedon,%checkedoff,%choices,%defaultchecked, at toggles);
-		
-		%choices =
-			&Apache::lonlocal::texthash (
-				submitbugs => 'Display "Submit a bug" link?',
-		);
-		
-		%defaultchecked = ('submitbugs' => 'on');
-		
-		@toggles = ('submitbugs',);
-		
-		foreach my $item (@toggles) {
-			if ($defaultchecked{$item} eq 'on') { 
-				$checkedon{$item} = ' checked="checked" ';
-				$checkedoff{$item} = ' ';
-			} elsif ($defaultchecked{$item} eq 'off') {
-				$checkedoff{$item} = ' checked="checked" ';
-				$checkedon{$item} = ' ';
-			}
-		}
-		
-		if (ref($settings) eq 'HASH') {
-			foreach my $item (@toggles) {
-				if ($settings->{$item} eq '1') {
-					$checkedon{$item} =  ' checked="checked" ';
-					$checkedoff{$item} = ' ';
-				} elsif ($settings->{$item} eq '0') {
-					$checkedoff{$item} =  ' checked="checked" ';
-					$checkedon{$item} = ' ';
-				}
-			}
-		 }
-		
-		 foreach my $item (@toggles) {
-			$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
-			$datatable .=  
-				'<tr'.$css_class.'>
-				<td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
-				<td><span class="LC_nobreak"> </span></td>
-				<td class="LC_right_item"><span class="LC_nobreak">
-				<label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label> 
-				<label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
-				'</span></td>'.
-				'</tr>';
-			$itemcount ++;
-		 }
-     
-     } else {
-     
-     	$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
-     	
-     	$datatable .= '<tr'.$css_class.'>';
-     	
-     	if (ref($settings) eq 'HASH') {
-			if ($settings->{'loginhelpurl'} ne '') {
-				my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
-				$datatable .= '<td width="33%"><span class="LC_left_item"><label><a href="'.$settings->{'loginhelpurl'}.'" target="_blank">'.&mt('Custom Login Page Help File In Use').'</a></label></span></td>';
-				$datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
-			} else {
-				$datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
-				$datatable .= '<td width="33%"><span class="LC_right_item"> </span></td>';
-			}
-		} else {
-			$datatable .= '<td><span class="LC_left_item"> </span></td>';
-			$datatable .= '<td><span class="LC_right_item"> </span></td>';
-		}
-    	
-     	$datatable .= '<td width="33%"><span class="LC_right_item">';
-     	if ($switchserver) {
-            $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+        ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
+                                                     \%choices,$itemcount);
+    } else {
+        $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
+        $datatable .= '<tr'.$css_class.'>';
+        my $url = '/adm/loginproblems.html'; 
+        my $type = 'default';
+        my %lt = &Apache::lonlocal::texthash (
+                     del     => 'Delete?',
+                     rep     => 'Replace:',
+                     upl     => 'Upload:',
+                     default => 'Default',
+                     custom  => 'Custom', 
+                                             ); 
+        if (ref($settings) eq 'HASH') {
+            if (ref($settings->{'loginhelpurl'}) eq 'HASH') {
+
+            } elsif ($settings->{'loginhelpurl'} ne '') {
+                $type = 'custom';
+                $url = $settings->{'loginhelpurl'}.'?inhibitmenu=yes';
+            }
+        }
+        $datatable .= '<td class="LC_left_item"><span class="LC_nobreak">'.
+                      &mt('Log-in help page currently in use: [_1]',
+                          &Apache::loncommon::modal_link($url,$lt{$type},600,500)).
+                      '</span></td>'."\n".
+                      '<td class="LC_left_item">';
+        if ($type eq 'custom') {
+            $datatable .= '<span class="LC_nobreak"><label>'.
+                          '<input type="checkbox" name="loginhelpurl_del" value="1" />'.$lt{'del'}. 
+                          '</label> '.$lt{'rep'}.'</span>';
         } else {
-        	$datatable .= &mt('Upload Custom Login Page Help File:');
-            $datatable .='<input type="file" name="loginhelpurl" />';
+            $datatable .= $lt{'upl'};
         }
-        $datatable .= '</span></td></tr>';
-        
-     }
-     return $datatable;
+        $datatable .='<br />';
+        if ($switchserver) {
+            $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+        } else {
+            $datatable .= '<input type="file" name="loginhelpurl" />';
+        } 
+        $datatable .= '</td></tr>';
+    }
+    return $datatable;
 }
 
-
 sub radiobutton_prefs {
     my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                    (ref($choices) eq 'HASH'));
 
-    my (%checkedon,%checkedoff,$datatable,$css_class);
+    my (%checkedon,%checkedoff,$datatable,$css_class,$cell_colspan);
 
     foreach my $item (@{$toggles}) {
         if ($defaultchecked->{$item} eq 'on') {
@@ -7440,80 +7407,75 @@
 
 sub modify_helpsettings {
     my ($r,$dom,$confname,%domconfig) = @_;
- 	my ($resulttext,$errors,%changes,%helphash);
- 	
- 	my $customhelpfile  = $env{'form.loginhelpurl.filename'};
-    my $defaulthelpfile = 'defaulthelp.html';
- 	my $servadm = $r->dir_config('lonAdmEMail');
-    my ($configuserok,$author_ok,$switchserver) = 
-        &config_check($dom,$confname,$servadm);
- 	
- 	my %defaultchecked = ('submitbugs'	=> 'on');
- 	my @offon = ('off','on');
-    my %title = ( submitbugs     => 'Display link for users to submit a bug', 
-    			  loginhelpurl  => 'Unauthenticated login help page set to custom file');
-    			  
+    my ($resulttext,$errors,%changes,%helphash);
+    my $customhelpfile = $env{'form.loginhelpurl.filename'};
+    my $defaulthelpfile = '/adm/loginproblems.html';
+    my $defaulttext = &mt('Default in use');
+    my $servadm = $r->dir_config('lonAdmEMail');
+    my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
+    my %defaultchecked = ('submitbugs' => 'on');
+    my @offon = ('off','on');
+    my %title = (
+                    submitbugs    => 'Display link for users to submit a bug', 
+                    loginhelpurl  => 'Unauthenticated login help page set to custom file'
+                );
     my @toggles = ('submitbugs');
-
     $helphash{'helpsettings'} = {};
-    
     if (ref($domconfig{'helpsettings'}) ne 'HASH') {
         if ($domconfig{'helpsettings'} eq '') {
             $domconfig{'helpsettings'} = {};
         }
     }
-    
     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
-    	
         foreach my $item (@toggles) {
-        	
-			if ($defaultchecked{$item} eq 'on') { 
-				if (($domconfig{'helpsettings'}{$item} eq '') &&
-					 ($env{'form.'.$item} eq '0')) {
-					$changes{$item} = 1;
-				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
-					$changes{$item} = 1;
-				}
-			} elsif ($defaultchecked{$item} eq 'off') {
-				if (($domconfig{'helpsettings'}{$item} eq '') &&
-					 ($env{'form.'.$item} eq '1')) {
-					$changes{$item} = 1;
-				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
-					$changes{$item} = 1;
-				}
-			}
-			$helphash{'helpsettings'}{$item} = $env{'form.'.$item};
-		}
-		
-		if ($customhelpfile ne '') {
-			my $error;
-			if ($configuserok eq 'ok') {
-				if ($switchserver) {
-					$error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
-				} else {
-					if ($author_ok eq 'ok') {
-						my ($result,$loginhelpurl) =
-							&publishlogo($r,'upload','loginhelpurl',$dom,
-										 $confname,'help','','',$customhelpfile);
-						if ($result eq 'ok') {
-							$helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
-							$changes{'loginhelpurl'} = 1;
-						} else {
-							$error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
-						}
-					} else {
-						$error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$customhelpfile,$confname,$dom,$author_ok);
-					}
-				}
-			} else {
-				$error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok);
-			}
-			if ($error) {
-				&Apache::lonnet::logthis($error);
-				$errors .= '<li><span class="LC_error">'.$error.'</span></li>';
-			}
-		}
-		
+            if ($defaultchecked{$item} eq 'on') { 
+                if ($domconfig{'helpsettings'}{$item} eq '') {
+                    if ($env{'form.'.$item} eq '0') {
+                        $changes{$item} = 1;
+                    }
+                } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
+                    $changes{$item} = 1;
+                }
+            } elsif ($defaultchecked{$item} eq 'off') {
+                if ($domconfig{'helpsettings'}{$item} eq '') {
+                    if ($env{'form.'.$item} eq '1') {
+                        $changes{$item} = 1;
+                    }
+                } elsif ($domconfig{'helpsettings'}{$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};
+            }
+        }
+        if ($customhelpfile ne '') {
+            my $error;
+            if ($configuserok eq 'ok') {
+                if ($switchserver) {
+                    $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
+                } else {
+                    if ($author_ok eq 'ok') {
+                        my ($result,$loginhelpurl) = &publishlogo($r,'upload','loginhelpurl',$dom,
+                                                                  $confname,'help','','',$customhelpfile);
+                        if ($result eq 'ok') {
+                            $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
+                            $changes{'loginhelpurl'} = 1;
+                        } else {
+                            $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
+                        }
+                    } else {
+                        $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$customhelpfile,$confname,$dom,$author_ok);
+                    }
+                }
+            } else {
+                $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok);
+            }
+            if ($error) {
+                &Apache::lonnet::logthis($error);
+                $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
+            }
+        }
         if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
             if ($env{'form.loginhelpurl_del'}) {
                 $helphash{'helpsettings'}{'loginhelpurl'} = '';
@@ -7521,38 +7483,42 @@
             }
         }
     }
-    
-    
     my $putresult;
-    
     if (keys(%changes) > 0) {
-    	$putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
+        $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
     } else {
-    	$putresult = 'ok';
+        $putresult = 'ok';
     }
-                                             
     if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {
-			$resulttext = &mt('Changes made:').'<ul>';
-			foreach my $item (sort(keys(%changes))) {
-				if ($item eq 'submitbugs') {
-					$resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
-				}
-				if ($item eq 'loginhelpurl') {
-					if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
-                        $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
-                    } else {
-                        $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
-                    }
-				}
-			}
-			$resulttext .= '</ul>';
-		} else {
-			$resulttext = &mt('No changes made to help settings');
-		}
+            $resulttext = &mt('Changes made:').'<ul>';
+            foreach my $item (sort(keys(%changes))) {
+                if ($item eq 'submitbugs') {
+                    $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
+                                              &Apache::loncommon::modal_link('http://bugs.loncapa.org',
+                                              &mt('LON-CAPA bug tracker'),600,500)).'</li>';
+                }
+                if ($item eq 'loginhelpurl') {
+                    if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
+                        $resulttext .= '<li>'.&mt('custom log-in help file removed.').' '.
+                                              &Apache::loncommon::modal_link($defaulthelpfile,
+                                              $defaulttext,600,500).'</li>';
+                    } else {
+                        $resulttext .= '<li>'.&Apache::loncommon::modal_link(
+                                                  $helphash{'helpsettings'}{'loginhelpurl'}.
+                                                  '?inhibitmenu=yes',
+                                                  &mt('custom log-in help file'),600,500).
+                                       '</li>';
+                    }
+                }
+            }
+            $resulttext .= '</ul>';
+        } else {
+            $resulttext = &mt('No changes made to help settings');
+        }
     } else {
-        $resulttext = '<span class="LC_error">'.
-	    &mt('An error occurred: [_1]',$putresult).'</span>';
+        $errors .= '<li><span class="LC_error">'.&mt('An error occurred storing the settings: [_1]',
+                                                     $putresult).'</span></li>';
     }
     if ($errors) {
         $resulttext .= &mt('The following errors occurred: ').'<ul>'.


More information about the LON-CAPA-cvs mailing list