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

raeburn raeburn@source.lon-capa.org
Mon, 22 Feb 2010 18:39:14 -0000


This is a MIME encoded message

--raeburn1266863954
Content-Type: text/plain

raeburn		Mon Feb 22 18:39:14 2010 EDT

  Modified files:              (Branch: version_2_9_X)
    /loncom/interface	domainprefs.pm 
  Log:
  - Backport 1.110 (part), 1.125, 1.126, 1.127.
  
  
--raeburn1266863954
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100222183914.txt"

Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.102.2.8 loncom/interface/domainprefs.pm:1.102.2.9
--- loncom/interface/domainprefs.pm:1.102.2.8	Tue Jan 26 15:47:27 2010
+++ loncom/interface/domainprefs.pm	Mon Feb 22 18:39:13 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.102.2.8 2010/01/26 15:47:27 raeburn Exp $
+# $Id: domainprefs.pm,v 1.102.2.9 2010/02/22 18:39:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -199,12 +199,12 @@
     }
     my %domconfig =
       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
-                'quotas','autoenroll','autoupdate','directorysrch',
-                'usercreation','usermodification','contacts','defaults',
-                'scantron','coursecategories','serverstatuses',
-                'requestcourses','coursedefaults'],$dom);
+                'quotas','autoenroll','autoupdate','autocreate',
+                'directorysrch','usercreation','usermodification',
+                'contacts','defaults','scantron','coursecategories',
+                'serverstatuses','requestcourses','coursedefaults'],$dom);
     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
-                       'autoupdate','directorysrch','contacts',
+                       'autoupdate','autocreate','directorysrch','contacts',
                        'usercreation','usermodification','scantron',
                        'requestcourses','coursecategories','serverstatuses',
                        'coursedefaults');
@@ -254,6 +254,12 @@
                                 {col1 => 'User population',
                                  col2 => 'Updataeable user data'}],
                   },
+        'autocreate' => 
+                  {  text => 'Auto-course creation settings',
+                     help => 'Domain_Configuration_Auto_Creation',
+                     header => [{col1 => 'Configuration Setting',
+                                 col2 => 'Value',}],
+                  },
         'directorysrch' => 
                   { text => 'Institutional directory searches',
                     help => 'Domain_Configuration_InstDirectory_Search',
@@ -393,6 +399,8 @@
         $output = &modify_autoenroll($dom,%domconfig);
     } elsif ($action eq 'autoupdate') {
         $output = &modify_autoupdate($dom,%domconfig);
+    } elsif ($action eq 'autocreate') {
+        $output = &modify_autocreate($dom,%domconfig);
     } elsif ($action eq 'directorysrch') {
         $output = &modify_directorysrch($dom,%domconfig);
     } elsif ($action eq 'usercreation') {
@@ -432,9 +440,11 @@
            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
           '</tr>';
     $rowtotal ++;
-    if (($action eq 'autoupdate') || ($action eq 'rolecolors') || 
-        ($action eq 'usercreation') || ($action eq 'usermodification') ||
-        ($action eq 'coursecategories') || ($action eq 'requestcourses')) {
+    my $numheaders = 1;
+    if (ref($item->{'header'}) eq 'ARRAY') {
+        $numheaders = scalar(@{$item->{'header'}});
+    }
+    if ($numheaders > 1) {
         my $colspan = '';
         if (($action eq 'rolecolors') || ($action eq 'coursecategories')) {
             $colspan = ' colspan="2"';
@@ -580,6 +590,8 @@
             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
         } elsif ($action eq 'autoenroll') {
             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
+        } elsif ($action eq 'autocreate') {
+            $output .= &print_autocreate($dom,$settings,\$rowtotal);
         } elsif ($action eq 'directorysrch') {
             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
         } elsif ($action eq 'contacts') {
@@ -1137,7 +1149,7 @@
     my ($css_class,%titles);
     if ($context eq 'requestcourses') {
         @usertools = ('official','unofficial','community');
-        @options =('norequest','approval','autolimit','validate');
+        @options =('norequest','approval','validate','autolimit');
         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
         %titles = &courserequest_titles();
     } else {
@@ -1206,16 +1218,16 @@
                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                                   '<input type="radio" name="crsreq_'.$item.
                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
-                                  $titles{$option}.'</label>&nbsp;';
+                                  $titles{$option}.'</label>';
                             if ($option eq 'autolimit') {
-                                $cell{$item} .= '<input type="text" name="crsreq_'.
+                                $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
                                                 $item.'_limit_'.$type.'" size="1" '.
                                                 'value="'.$currlimit.'" />';
                             }
+                            $cell{$item} .= '</span> ';
                             if ($option eq 'autolimit') {
                                 $cell{$item} .= $titles{'unlimited'};
                             }
-                            $cell{$item} .= '</span>&nbsp; ';
                         }
                     } else {
                         my $checked = 'checked="checked" ';
@@ -1314,11 +1326,11 @@
                                   '_default" value="'.$val.'"'.$checked.' />'.
                                   $titles{$option}.'</label>';
                 if ($option eq 'autolimit') {
-                    $defcell{$item} .= '<input type="text" name="crsreq_'.
+                    $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
                                        $item.'_limit_default" size="1" '.
                                        'value="'.$currlimit.'" />';
                 }
-                $defcell{$item} .= '</span>&nbsp; ';
+                $defcell{$item} .= '</span> ';
                 if ($option eq 'autolimit') {
                     $defcell{$item} .= $titles{'unlimited'};
                 }
@@ -1417,11 +1429,11 @@
                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                                   $titles{$option}.'</label>';
                 if ($option eq 'autolimit') {
-                    $advcell{$item} .= '<input type="text" name="crsreq_'.
+                    $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
                                        $item.'_limit__LC_adv" size="1" '.
                                        'value="'.$currlimit.'" />';
                 }
-                $advcell{$item} .= '</span>&nbsp; ';
+                $advcell{$item} .= '</span> ';
                 if ($option eq 'autolimit') {
                     $advcell{$item} .= $titles{'unlimited'};
                 }
@@ -1651,6 +1663,57 @@
     return $datatable;
 }
 
+sub print_autocreate {
+    my ($dom,$settings,$rowtotal) = @_;
+    my (%createon,%createoff);
+    my $curr_dc;
+    my @types = ('xml','req');
+    if (ref($settings) eq 'HASH') {
+        foreach my $item (@types) {
+            $createoff{$item} = ' checked="checked" ';
+            $createon{$item} = ' ';
+            if (exists($settings->{$item})) {
+                if ($settings->{$item}) {
+                    $createon{$item} = ' checked="checked" ';
+                    $createoff{$item} = ' ';
+                }
+            }
+        }
+        $curr_dc = $settings->{'xmldc'};
+    } else {
+        foreach my $item (@types) {
+            $createoff{$item} = ' checked="checked" ';
+            $createon{$item} = ' ';
+        }
+    }
+    $$rowtotal += 2;
+    my $datatable='<tr class="LC_odd_row">'.
+                  '<td>'.&mt('Create pending official courses from XML files').'</td>'.
+                  '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
+                  '<input type="radio" name="autocreate_xml"'.
+                  $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
+                  '<label><input type="radio" name="autocreate_xml"'.
+                  $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>';
+    my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
+    if ($numdc > 1) {
+        $datatable .= '</td><tr><td>'.
+                      &mt('XML files processed as: (choose Dom. Coord.)').
+                      '</td><td class="LC_left_item">'.$dctable.'</td></tr>'.
+                      '<tr class="LC_odd_row">';
+        $$rowtotal ++ ;
+    } else {
+        $datatable .= '</td></tr><tr>';
+    }
+    $datatable .= '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
+                  '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
+                  '<input type="radio" name="autocreate_req"'.
+                  $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
+                  '<label><input type="radio" name="autocreate_req"'.
+                  $createoff{'req'}.' value="0" />'.&mt('No').'</label></span></td>'.
+                  '</tr>';
+    return $datatable;
+}
+
 sub print_directorysrch {
     my ($dom,$settings,$rowtotal) = @_;
     my $srchon = ' ';
@@ -3922,7 +3985,7 @@
     }
     if ($context eq 'requestcourses') {
         @usertools = ('official','unofficial','community');
-        @options =('norequest','approval','autolimit','validate');
+        @options =('norequest','approval','validate','autolimit');
         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
         %titles = &courserequest_titles();
         $toolregexp = join('|',@usertools);
@@ -4376,6 +4439,78 @@
     return $resulttext;
 }
 
+sub modify_autocreate {
+    my ($dom,%domconfig) = @_;
+    my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
+    if (ref($domconfig{'autocreate'}) eq 'HASH') {
+        foreach my $key (keys(%{$domconfig{'autocreate'}})) {
+            $currautocreate{$key} = $domconfig{'autocreate'}{$key};
+        }
+    }
+    my %title= ( xml => 'Auto-creation of courses in XML course description files',
+                 req => 'Auto-creation of validated requests for official courses',
+                 xmldc => 'Identity of course creator of courses from XML files',
+               );
+    my @types = ('xml','req');
+    foreach my $item (@types) {
+        $newvals{$item} = $env{'form.autocreate_'.$item};
+        $newvals{$item} =~ s/\D//g;
+        $newvals{$item} = 0 if ($newvals{$item} eq '');
+    }
+    $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
+    my %domcoords = &get_active_dcs($dom);
+    unless (exists($domcoords{$newvals{'xmldc'}})) {
+        $newvals{'xmldc'} = '';
+    }
+    %autocreatehash =  (
+                        autocreate => { xml => $newvals{'xml'},
+                                        req => $newvals{'req'},
+                                      }
+                       );
+    if ($newvals{'xmldc'} ne '') {
+        $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
+    }
+    my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
+                                             $dom);
+    if ($putresult eq 'ok') {
+        my @items = @types;
+        if ($newvals{'xml'}) {
+            push(@items,'xmldc');
+        }
+        foreach my $item (@items) {
+            if (exists($currautocreate{$item})) {
+                if ($currautocreate{$item} ne $newvals{$item}) {
+                    $changes{$item} = 1;
+                }
+            } elsif ($newvals{$item}) {
+                $changes{$item} = 1;
+            }
+        }
+        if (keys(%changes) > 0) {
+            my @offon = ('off','on');
+            $resulttext = &mt('Changes made:').'<ul>';
+            foreach my $item (@types) {
+                if ($changes{$item}) {
+                    my $newtxt = $offon[$newvals{$item}];
+                    $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
+                }
+            }
+            if ($changes{'xmldc'}) {
+                my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
+                my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
+                $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
+            }
+            $resulttext .= '</ul>';
+        } else {
+            $resulttext = &mt('No changes made to auto-creation settings');
+        }
+    } else {
+        $resulttext = '<span class="LC_error">'.
+            &mt('An error occurred: [_1]',$putresult).'</span>';
+    }
+    return $resulttext;
+}
+
 sub modify_directorysrch {
     my ($dom,%domconfig) = @_;
     my ($resulttext,%changes);
@@ -5130,7 +5265,7 @@
                             }
                             my @modifiable;
                             if ($context eq 'selfcreate') {
-                                $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]  ',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
+                                $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
                             } else {
                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                             }
@@ -5796,4 +5931,74 @@
     return;
 }
 
+sub get_active_dcs {
+    my ($dom) = @_;
+    my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
+    my %domcoords;
+    my $numdcs = 0;
+    my $now = time;
+    foreach my $server (keys(%dompersonnel)) {
+        foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
+            my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
+            my ($end,$start) = split(':',$dompersonnel{$server}{$user});
+            if (($end eq '') || ($end == 0) || ($end > $now)) {
+                if ($start <= $now) {
+                    $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
+                }
+            }
+        }
+    }
+    return %domcoords;
+}
+
+sub active_dc_picker {
+    my ($dom,$curr_dc) = @_;
+    my %domcoords = &get_active_dcs($dom);
+    my @dcs = sort(keys(%domcoords));
+    my $numdcs = scalar(@dcs);
+    my $datatable;
+    my $numinrow = 2;
+    if ($numdcs > 1) {
+        $datatable = '<table>';
+        for (my $i=0; $i<@dcs; $i++) {
+            my $rem = $i%($numinrow);
+            if ($rem == 0) {
+                if ($i > 0) {
+                    $datatable .= '</tr>';
+                }
+                $datatable .= '<tr>';
+            }
+            my $check = ' ';
+            if ($curr_dc eq '') {
+                if (!$i) {
+                    $check = ' checked="checked" ';
+                }
+            } elsif ($dcs[$i] eq $curr_dc) {
+                $check = ' checked="checked" ';
+            }
+            if ($i == @dcs - 1) {
+                my $colsleft = $numinrow - $rem;
+                if ($colsleft > 1) {
+                    $datatable .= '<td colspan="'.$colsleft.'">';
+                } else {
+                    $datatable .= '<td>';
+                }
+            } else {
+                $datatable .= '<td>';
+            }
+            my ($dcname,$dcdom) = split(':',$dcs[$i]);
+            $datatable .= '<span class="LC_nobreak"><label>'.
+                          '<input type="radio" name="autocreate_xmldc"'.
+                          ' value="'.$dcs[$i].'"'.$check.'/>'.
+                          &Apache::loncommon::plainname($dcname,$dcdom).
+                          '</label></span></td>';
+        }
+        $datatable .= '</tr></table>';
+    } elsif (@dcs) {
+        $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
+                      $dcs[0].'" />';
+    }
+    return ($numdcs,$datatable);
+}
+
 1;

--raeburn1266863954--