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

raeburn raeburn@source.lon-capa.org
Mon, 08 Mar 2010 22:31:27 -0000


This is a MIME encoded message

--raeburn1268087487
Content-Type: text/plain

raeburn		Mon Mar  8 22:31:27 2010 EDT

  Modified files:              
    /loncom/interface	lonmodifycourse.pm 
  Log:
  - Co-owners.
    - New routine: &update_coowners() will adjust co-owners new owner used to
      be a co-owner. 
      - If this is an official course, and auto-assignment of co-owners is 
        enabled, co-owner status will be updated for any active CCs
        who are validated as official course personnel.
  
  
--raeburn1268087487
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100308223127.txt"

Index: loncom/interface/lonmodifycourse.pm
diff -u loncom/interface/lonmodifycourse.pm:1.49 loncom/interface/lonmodifycourse.pm:1.50
--- loncom/interface/lonmodifycourse.pm:1.49	Mon Nov 23 21:45:18 2009
+++ loncom/interface/lonmodifycourse.pm	Mon Mar  8 22:31:27 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # handler for DC-only modifiable course settings
 #
-# $Id: lonmodifycourse.pm,v 1.49 2009/11/23 21:45:18 raeburn Exp $
+# $Id: lonmodifycourse.pm,v 1.50 2010/03/08 22:31:27 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -49,7 +49,8 @@
 
 sub autoenroll_keys {
     my $internals = ['coursecode','courseowner','authtype','autharg','autoadds','autodrops',
-                         'autostart','autoend','sectionnums','crosslistings'];
+                         'autostart','autoend','sectionnums','crosslistings',
+                         'co-owners'];
     my $accessdates = ['default_enrollment_start_date','default_enrollment_end_date'];
     return ($internals,$accessdates);
 }
@@ -106,7 +107,7 @@
                 } else {
                     $enrollvar{$type} = &Apache::lonlocal::locallocaltime($settings{$item});
                 }
-            } elsif ($type eq "sectionnums") {
+            } elsif (($type eq 'sectionnums') || ($type eq 'co-owners')) {
                 $enrollvar{$type} = $settings{$item};
                 $enrollvar{$type} =~ s/,/, /g;
             } elsif ($type eq "authtype"
@@ -335,7 +336,7 @@
                        "<td><b>$longtype{$item}</b></td>\n".
                        "<td>$enrollvar{$item}</td>\n";
         if (grep(/^\Q$item\E$/,@modifiable_params)) {
-            $disp_table .= '<td align="right">'.&mt('Yes').'</td>'."\n"; 
+            $disp_table .= '<td align="right">'.&mt('Yes').'</td>'."\n";
         } else {
             $disp_table .= '<td align="right">'.&mt('No').'</td>'."\n";
         }
@@ -635,7 +636,8 @@
 sub modify_course {
     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
     my %longtype = &course_settings_descrip($type);
-    my @items = ('internal.courseowner','description');
+    my @items = ('internal.courseowner','description','internal.co-owners',
+                 'internal.pendingco-owners');
     unless ($type eq 'Community') {
         push(@items,('internal.coursecode','internal.authtype','internal.autharg',
                      'internal.sectionnums','internal.crosslistings'));
@@ -711,7 +713,7 @@
         } 
     }
 
-    if ($changed{'owner'} || $changed{'code'}) { 
+    if ($changed{'owner'} || $changed{'code'}) {
         my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,
                                                     undef,undef,'.');
         if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
@@ -723,6 +725,9 @@
             }
             my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
             my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
+            if ($putres eq 'ok') {
+                &update_coowners($cdom,$cnum,$chome,\%settings,\%newattr);
+            }
         }
     }
     foreach my $param (@modifiable_params) {
@@ -861,6 +866,139 @@
     return;
 }
 
+sub update_coowners {
+    my ($cdom,$cnum,$chome,$settings,$newattr) = @_;
+    return unless ((ref($settings) eq 'HASH') && (ref($newattr) eq 'HASH'));
+    my %designhash = &Apache::loncommon::get_domainconf($cdom);
+    my (%cchash,$autocoowners);
+    if ($designhash{$cdom.'.autoassign.co-owners'}) {
+        $autocoowners = 1;
+        %cchash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc']);
+    }
+    if ($settings->{'internal.courseowner'} ne $newattr->{'courseowner'}) {
+        my $oldowner_to_coowner;
+        if (($newattr->{'coursecode'}) && ($autocoowners)) {
+            my $oldowner = $settings->{'internal.courseowner'};
+            if ($cchash{$oldowner.':cc'}) {
+                if ($settings->{'internal.co-owner'}) {
+                    my @current = split(',',$settings->{'internal.co-owners'});
+                    unless (grep(/^\Q$oldowner\E$/,@current)) {
+                        $oldowner_to_coowner = 1;
+                    }
+                } else {
+                    $oldowner_to_coowner = 1;
+                }
+            }
+        }
+        foreach my $type ('co-owners','pendingco-owners') {
+            if ($settings->{'internal.'.$type}) {
+                my @current = split(',',$settings->{'internal.'.$type});
+                my $newowner = $newattr->{'courseowner'};
+                my @newvalues = ();
+                if (($newowner ne '') && (grep(/^\Q$newowner\E$/,@current))) {
+                    foreach my $person (@current) {
+                        unless ($person eq $newowner) {
+                            push(@newvalues,$person);
+                        }
+                    }
+                } else {
+                    @newvalues = @current;
+                }
+                if ($oldowner_to_coowner) {
+                    push(@newvalues,$settings->{'internal.courseowner'});
+                    @newvalues = sort(@newvalues);
+                }
+                my $newownstr = join(',',@newvalues);
+                if ($newownstr ne $settings->{'internal.'.$type}) {
+                    if ($type eq 'co-owners') {
+                        my $deleted = '';
+                        unless (@newvalues) {
+                            $deleted = 1;
+                        }
+                        &Apache::lonnet::store_coowners($cdom,$cnum,$chome,
+                                                        $deleted,@newvalues);
+                    } else {
+                        my $pendingcoowners;
+                        my $cid = $cdom.'_'.$cnum;
+                        if (@newvalues) {
+                            $pendingcoowners = join(',',@newvalues);
+                            my %pendinghash = (
+                                'internal.pendingco-owners' => $pendingcoowners,
+                            );
+                            my $putresult = &put('environment',\%pendinghash,$cdom,$cnum);
+                            if ($putresult eq 'ok') {
+                                if ($env{'course.'.$cid.'.num'} eq $cnum) {
+                                    &appenv({'course.'.$cid.'.internal.pendingco-owners' => $pendingcoowners});
+                                }
+                            }
+                        } else {
+                            my $delresult = &Apache::lonnet::del('environment',['internal.pendingco-owners'],$cdom,$cnum);
+                            if ($delresult eq 'ok') {
+                                if ($env{'course.'.$cid.'.internal.pendingco-owners'}) {
+                                    &Apache::lonnet::delenv('course.'.$cid.'.internal.pendingco-owners');
+                                }
+                            }
+                        }
+                    }
+                } elsif ($oldowner_to_coowner) {
+                    &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
+                                         $settings->{'internal.courseowner'});
+
+                }
+            } elsif ($oldowner_to_coowner) {
+                &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
+                                     $settings->{'internal.courseowner'});
+            }
+        }
+    }
+    if ($settings->{'internal.coursecode'} ne $newattr->{'coursecode'}) {
+        if ($newattr->{'coursecode'} ne '') {
+            my %designhash = &Apache::loncommon::get_domainconf($cdom);
+            if ($designhash{$cdom.'.autoassign.co-owners'}) {
+                my @newcoowners = ();
+                if ($settings->{'internal.co-owners'}) {
+                    my @currcoown = split(',',$settings->{'internal.coowners'});
+                    my ($updatecoowners,$delcoowners);
+                    foreach my $person (@currcoown) {
+                        my ($result,$desc) = &Apache::lonnet::valid_instcode();
+                        if ($result eq 'valid') {
+                            push(@newcoowners,$person);
+                        }
+                    }
+                    foreach my $item (sort(keys(%cchash))) {
+                        my ($uname,$udom,$urole) = split(':',$item);
+                        unless (grep(/^\Q$uname\E:\Q$udom\E$/,@newcoowners)) {
+                            push(@newcoowners,$uname.':'.$udom);
+                        }
+                    }
+                    if (@newcoowners) {
+                        my $coowners = join(',',sort(@newcoowners));
+                        unless ($coowners eq $settings->{'internal.co-owners'}) {
+                            $updatecoowners = 1;
+                        }
+                    } else {
+                        $delcoowners = 1;
+                    }
+                    if ($updatecoowners || $delcoowners) {
+                        &Apache::lonnet::store_coowners($cdom,$cnum,$chome,
+                                                        $delcoowners,@newcoowners);
+                    }
+                } else {
+                    foreach my $item (sort(keys(%cchash))) {
+                        my ($uname,$udom,$urole) = split(':',$item);
+                        push(@newcoowners,$uname.':'.$udom);
+                    }
+                    if (@newcoowners) {
+                        &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
+                                                        @newcoowners);
+                    }
+                }
+            }
+        }
+    }
+    return;
+}
+
 sub modify_quota {
     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
     &print_header($r,$type);
@@ -1168,8 +1306,8 @@
     if ($type eq 'Community') {
          %longtype = &Apache::lonlocal::texthash(
                       'courseowner' => "Username:domain of community owner",
+                      'co-owners'   => "Username:domain of each co-owner",
          );
-
     } else {
          %longtype = &Apache::lonlocal::texthash(
                       'authtype' => 'Default authentication method',
@@ -1182,6 +1320,7 @@
                       'default_enrollment_end_date' => 'Date of last student access',
                       'coursecode' => 'Official course code',
                       'courseowner' => "Username:domain of course owner",
+                      'co-owners'   => "Username:domain of each co-owner",
                       'notifylist' => 'Course Coordinators to be notified of enrollment changes',
                       'sectionnums' => 'Course section number:LON-CAPA section',
                       'crosslistings' => 'Crosslisted class:LON-CAPA section',

--raeburn1268087487--