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

raeburn raeburn at source.lon-capa.org
Sun Mar 30 21:09:20 EDT 2014


raeburn		Mon Mar 31 01:09:20 2014 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm domainprefs.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Move &selfenroll_validation_types(), &selfenroll_default_descs(),
    &get_selfenroll_titles() from domainprefs.pm to lonuserutils.pm
    to facilitate re-use.
  - Add self-enrollment related defaults to cached domain defaults:
    (a) Self-enrollment settings controlled by DC, by default:
       - <type>selfenrolladmdc (where <type> is: course type (official,
         unofficial, community or textbook).
    (b) Self-enrollment default values:
       - <type>selfenroll<setting> where type is course type, and <setting>
         is default self-enrollment setting: types, registered, approval,
         limit, or cap.
  - New routine in lonuserutils.pm -- &selfenrollment_administration()
    provides array refs for self-enrollment items (a) managed by course
    personnel; (b) managed by DC. 
  
  
-------------- next part --------------
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.164 loncom/interface/lonuserutils.pm:1.165
--- loncom/interface/lonuserutils.pm:1.164	Fri Feb 28 19:20:06 2014
+++ loncom/interface/lonuserutils.pm	Mon Mar 31 01:09:11 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.164 2014/02/28 19:20:06 bisitz Exp $
+# $Id: lonuserutils.pm,v 1.165 2014/03/31 01:09:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5351,7 +5351,7 @@
         }
         $rolecode = "var match = str.split('_');
                 var role = match[3];\n";
-    } elsif ($formname eq 'enrollstudent') {
+    } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
         $checkincluded = 'formname.name == "'.$formname.'"';
         if ($checkauth) {
             $finish = "var authcheck = auth_check();\n".
@@ -5701,6 +5701,22 @@
         if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
             $permission{'grp_manage'} = 1;
         }
+        if ($permission{'cusr'}) {
+            my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+            my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+            my %coursehash = (
+                'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
+                'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
+                'internal.coursecode'      => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
+                'internal.textbook'        =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
+            );
+            my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
+            if (ref($managed_by_cc) eq 'ARRAY') {
+                if (@{$managed_by_cc}) {
+                    $permission{'selfenrolladmin'} = 1;
+                }
+            }
+        }
     } elsif ($context eq 'author') {
         $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
         $permission{'view'} = $permission{'cusr'};
@@ -6031,5 +6047,126 @@
     return;
 }
 
+sub get_selfenroll_titles {
+    my @row = ('types','registered','enroll_dates','access_dates','section',
+               'approval','limit');
+    my %lt = &Apache::lonlocal::texthash (
+                types        => 'Users allowed to self-enroll',
+                registered   => 'Registration status (official courses)' ,
+                enroll_dates => 'Dates self-enrollment available',
+                access_dates => 'Access dates for self-enrolling users',
+                section      => "Self-enrolling users' section",
+                approval     => 'Processing of requests',
+                limit        => 'Enrollment limit',
+             );
+    return (\@row,\%lt);
+}
+
+sub selfenroll_default_descs {
+    my %desc = (
+                 types => {
+                            dom => &mt('Course domain'),
+                            all => &mt('Any domain'),
+                            ''  => &mt('None'),
+                          },
+                 limit => {
+                            none         => &mt('No limit'),
+                            allstudents  => &mt('Limit by total students'),
+                            selfenrolled => &mt('Limit by total self-enrolled'),
+                          },
+                 approval => {
+                                '0' => &mt('Processed automatically'),
+                                '1' => &mt('Queued for approval'),
+                                '2' => &mt('Queued, pending validation'),
+                             },
+                 registered => {
+                                 0 => 'No registration required',
+                                 1 => 'Registered students only',
+                               },
+               );
+    return %desc;
+}
+
+sub selfenroll_validation_types {
+    my @items = ('url','fields','button','markup');
+    my %names =  &Apache::lonlocal::texthash (
+            url      => 'Web address of validation server/script',
+            fields   => 'Form fields to send to validator',
+            button   => 'Text for validation button',
+            markup   => 'Validation description (HTML)',
+    );
+    my @fields = ('username','domain','uniquecode','course','token','coursetype');
+    return (\@items,\%names,\@fields);
+}
+
+sub get_extended_type {
+    my ($cdom,$cnum,$crstype,$current) = @_;
+    my $type = 'unofficial';
+    my %settings;
+    if (ref($current) eq 'HASH') {
+        %settings = %{$current};
+    } else {
+        %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
+    }
+    if ($crstype eq 'Community') {
+        $type = 'community';
+    } elsif ($settings{'internal.coursecode'}) {
+        $type = 'official';
+    } elsif ($settings{'internal.textbook'}) {
+        $type = 'textbook';
+    }
+    return $type;
+}
+
+sub selfenrollment_administration {
+    my ($cdom,$cnum,$crstype,$coursehash) = @_;
+    my %settings;
+    if (ref($coursehash) eq 'HASH') {
+        %settings = %{$coursehash};
+    } else {
+        %settings = &Apache::lonnet::get('environment',
+                        ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
+                         'internal.coursecode','internal.textbook'],$cdom,$cnum);
+    }
+    my ($possconfigs) = &get_selfenroll_titles(); 
+    my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
+    my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
+
+    my (@in_course, at in_domain); 
+    if ($settings{'internal.selfenrollmgrcc'} ne '') {
+        @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'}); 
+        my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
+        unless (@diffs) {
+            return (\@in_course,\@in_domain);
+        }
+    }
+    if ($settings{'internal.selfenrollmgrdc'} ne '') {
+        my @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
+        my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
+        unless (@diffs) {
+            return (\@in_course,\@in_domain);
+        }
+    }
+    my @combined = @in_course;
+    push(@combined, at in_domain);
+    my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs); 
+    unless (@diffs) {
+        return (\@in_course,\@in_domain);
+    }
+    if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
+        push(@in_course, at diffs);
+    } else {
+        my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
+        foreach my $item (@diffs) {
+            if (grep(/^\Q$item\E$/, at defaultdc)) {
+                push(@in_domain,$item);
+            } else {
+                push(@in_course,$item);
+            }
+        }
+    }
+    return (\@in_course,\@in_domain);
+}
+
 1;
 
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.231 loncom/interface/domainprefs.pm:1.232
--- loncom/interface/domainprefs.pm:1.231	Sat Mar 29 20:35:21 2014
+++ loncom/interface/domainprefs.pm	Mon Mar 31 01:09:11 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.231 2014/03/29 20:35:21 raeburn Exp $
+# $Id: domainprefs.pm,v 1.232 2014/03/31 01:09:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -164,6 +164,7 @@
 use Apache::lonlocal;
 use Apache::lonmsg();
 use Apache::lonconfigsettings;
+use Apache::lonuserutils();
 use LONCAPA qw(:DEFAULT :match);
 use LONCAPA::Enrollment;
 use LONCAPA::lonauthcgi();
@@ -2839,8 +2840,8 @@
     my $itemcount = 1;
     my @types = ('official','unofficial','community','textbook');
     if (($position eq 'top') || ($position eq 'middle')) {
-        my ($rowsref,$titlesref) = &get_selfenroll_titles();
-        my %descs = &selfenroll_default_descs();
+        my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
+        my %descs = &Apache::lonuserutils::selfenroll_default_descs();
         my @rows;
         my $key;
         if ($position eq 'top') {
@@ -3018,58 +3019,6 @@
     return $datatable;
 }
 
-sub get_selfenroll_titles {
-    my @row = ('types','registered','enroll_dates','access_dates','section',
-               'approval','limit');
-    my %lt = &Apache::lonlocal::texthash (
-                types        => 'Users allowed to self-enroll',
-                registered   => 'Registration status (official courses)' ,
-                enroll_dates => 'Dates self-enrollment available',
-                access_dates => 'Access dates for self-enrolling users',
-                section      => 'Self-enrolling users section',
-                approval     => 'Processing of requests',
-                limit        => 'Enrollment limit',
-             );
-    return (\@row,\%lt);
-}
-
-sub selfenroll_default_descs {
-    my %desc = (
-                 types => {
-                            dom => &mt('Course domain'),
-                            all => &mt('Any domain'),
-                            ''  => &mt('None'),
-                          },
-                 limit => {
-                            none         => &mt('No limit'),
-                            allstudents  => &mt('Limit by total students'),
-                            selfenrolled => &mt('Limit by total self-enrolled'),
-                          },
-                 approval => {
-                                '0' => &mt('Processed automatically'),
-                                '1' => &mt('Queued for approval'),
-                                '2' => &mt('Queued, pending validation'),
-                             },
-                 registered => {
-                                 0 => 'No registration required',
-                                 1 => 'Registered students only',
-                               },
-               );
-    return %desc;
-}
-
-sub selfenroll_validation_types {
-    my @items = ('url','fields','button','markup');
-    my %names =  &Apache::lonlocal::texthash (
-            url      => 'Web address of validation server/script',
-            fields   => 'Form fields to send to validator',
-            button   => 'Text for validation button',
-            markup   => 'Validation description (HTML)',
-    );
-    my @fields = ('username','domain','uniquecode','course','token');
-    return (\@items,\%names,\@fields);
-}  
-
 sub print_usersessions {
     my ($position,$dom,$settings,$rowtotal) = @_;
     my ($css_class,$datatable,%checked,%choices);
@@ -9410,8 +9359,8 @@
     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
     my @types = ('official','unofficial','community','textbook');
     my %titles = &tool_titles();
-    my %descs = &selfenroll_default_descs();
-    ($ordered{'admin'},my $titlesref) = &get_selfenroll_titles();
+    my %descs = &Apache::lonuserutils::selfenroll_default_descs();
+    ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
     $ordered{'default'} = ['types','registered','approval','limit'];
 
     my (%roles,%shown,%toplevel);
@@ -9577,6 +9526,34 @@
                                 $roles{'1'} = &mt('Course personnel');
                             }
                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
+                                if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
+                                    if ($key eq 'admin') {
+                                        my @mgrdc = ();
+                                        if (ref($ordered{$key}) eq 'ARRAY') {
+                                            foreach my $item (@{$ordered{'admin'}}) {
+                                                if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
+                                                    if ($selfenrollhash{$key}{$type}{$item} eq '0') {
+                                                        push(@mgrdc,$item);
+                                                    }
+                                                }
+                                            }
+                                            if (@mgrdc) {
+                                                $domdefaults{$type.'selfenrolladmdc'} = join(',', at mgrdc);
+                                            } else {
+                                                delete($domdefaults{$type.'selfenrolladmdc'});
+                                            }
+                                        }
+                                    } else {
+                                        if (ref($ordered{$key}) eq 'ARRAY') {
+                                            foreach my $item (@{$ordered{$key}}) {
+                                                if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
+                                                    $domdefaults{$type.'selfenroll'.$item} =
+                                                        $selfenrollhash{$key}{$type}{$item};
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                                 foreach my $item (@{$ordered{$key}}) {
                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
@@ -9597,6 +9574,13 @@
                         $resulttext .= '</ul></li>'; 
                     }
                 }
+                if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
+                    my $cachetime = 24*60*60;
+                    &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+                    if (ref($lastactref) eq 'HASH') {
+                        $lastactref->{'domdefaults'} = 1;
+                    }
+                }
             }
             $resulttext .= '</ul>';
         } else {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1253 loncom/lonnet/perl/lonnet.pm:1.1254
--- loncom/lonnet/perl/lonnet.pm:1.1253	Tue Mar 25 09:41:08 2014
+++ loncom/lonnet/perl/lonnet.pm	Mon Mar 31 01:09:20 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1253 2014/03/25 09:41:08 raeburn Exp $
+# $Id: lonnet.pm,v 1.1254 2014/03/31 01:09:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2012,7 +2012,8 @@
          &Apache::lonnet::get_dom('configuration',['defaults','quotas',
                                   'requestcourses','inststatus',
                                   'coursedefaults','usersessions',
-                                  'requestauthor'],$domain);
+                                  'requestauthor','selfenrollment'],$domain);
+    my @coursetypes = ('official','unofficial','community','textbook');
     if (ref($domconfig{'defaults'}) eq 'HASH') {
         $domdefaults{'lang_def'} = $domconfig{'defaults'}{'lang_def'}; 
         $domdefaults{'auth_def'} = $domconfig{'defaults'}{'auth_def'};
@@ -2056,16 +2057,15 @@
     }
     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
         $domdefaults{'canuse_pdfforms'} = $domconfig{'coursedefaults'}{'canuse_pdfforms'};
-        if (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
-            $domdefaults{'officialcredits'} = $domconfig{'coursedefaults'}{'coursecredits'}{'official'};
-            $domdefaults{'unofficialcredits'} = $domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'};
-            $domdefaults{'textbookcredits'} = $domconfig{'coursedefaults'}{'coursecredits'}{'textbook'};
-        }
-        if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
-            $domdefaults{'officialquota'} = $domconfig{'coursedefaults'}{'uploadquota'}{'official'};
-            $domdefaults{'unofficialquota'} = $domconfig{'coursedefaults'}{'uploadquota'}{'unofficial'};
-            $domdefaults{'communityquota'} = $domconfig{'coursedefaults'}{'uploadquota'}{'community'};
-            $domdefaults{'textbookquota'} = $domconfig{'coursedefaults'}{'uploadquota'}{'textbook'};
+        foreach my $type (@coursetypes) {
+            if (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
+                unless ($type eq 'community') {
+                    $domdefaults{$type.'credits'} = $domconfig{'coursedefaults'}{'coursecredits'}{$type};
+                }
+            }
+            if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
+                $domdefaults{$type.'quota'} = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
+            }
         }
     }
     if (ref($domconfig{'usersessions'}) eq 'HASH') {
@@ -2076,6 +2076,34 @@
             $domdefaults{'hostedsessions'} = $domconfig{'usersessions'}{'hosted'};
         }
     }
+    if (ref($domconfig{'selfenrollment'}) eq 'HASH') {
+        if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
+            my @settings = ('types','registered','enroll_dates','access_dates','section',
+                            'approval','limit');
+            foreach my $type (@coursetypes) {
+                if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
+                    my @mgrdc = ();
+                    foreach my $item (@settings) {
+                        if ($domconfig{'selfenrollment'}{'admin'}{$type}{$item} eq '0') {
+                            push(@mgrdc,$item);
+                        }
+                    }
+                    if (@mgrdc) {
+                        $domdefaults{$type.'selfenrolladmdc'} = join(',', at mgrdc);
+                    }
+                }
+            }
+        }
+        if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
+            foreach my $type (@coursetypes) {
+                if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
+                    foreach my $item (keys(%{$domconfig{'selfenrollment'}{'default'}{$type}})) {
+                        $domdefaults{$type.'selfenroll'.$item} = $domconfig{'selfenrollment'}{'default'}{$type}{$item};
+                    }
+                }
+            }
+        }
+    }
     &do_cache_new('domdefaults',$domain,\%domdefaults,$cachetime);
     return %domdefaults;
 }


More information about the LON-CAPA-cvs mailing list