Diff for /loncom/automation/batchcreatecourse.pm between versions 1.40.2.3.2.1 and 1.41

version 1.40.2.3.2.1, 2020/07/20 01:02:00 version 1.41, 2016/04/02 04:30:47
Line 80  use strict; Line 80  use strict;
 # <clonedom>msu</clonedom>  # <clonedom>msu</clonedom>
 # <datemode>shift</datemode>  # <datemode>shift</datemode>
 # <dateshift>365</dateshift>  # <dateshift>365</dateshift>
 # <tinyurls>create</tinyurls>  
 # <showphotos></showphotos>  # <showphotos></showphotos>
 # <setpolicy>1</setpolicy>  # <setpolicy>1</setpolicy>
 # <setcontent>1</setcontent>  # <setcontent>1</setcontent>
 # <setcomment>1</setcomment>  
 # <setkeys>0</setkeys>  # <setkeys>0</setkeys>
 # <keyauth>keyadmin:msu</keyauth>  # <keyauth>keyadmin:msu</keyauth>
 # <disresdis>1</disresdis>  # <disresdis>1</disresdis>
 # <disablechat>1</disablechat>  # <disablechat>1</disablechat>
 # <openall></openall>  # <openall></openall>
 # <openallfrom></openallfrom>  
 # <notify_dc>1</notify_dc>  # <notify_dc>1</notify_dc>
 # <notify_owner>1</notify_owner>  # <notify_owner>1</notify_owner>
 # <owner>  # <owner>
Line 155  use strict; Line 152  use strict;
 #  #
 # Many of these are binary options (corresponding to either checkboxes or  # Many of these are binary options (corresponding to either checkboxes or
 # radio buttons in the interactive CCRS page).  Examples include:  # radio buttons in the interactive CCRS page).  Examples include:
 # setpolicy, setcontent, setcomment, setkeys, disableresdis, disablechat, openall,  # setpolicy, setcontent, setkeys, disableresdis, disablechat, openall,
 # uniquecode  # uniquecode
 #  #
 # A value of 1 between opening and closing tags is equivalent to a   # A value of 1 between opening and closing tags is equivalent to a 
Line 166  use strict; Line 163  use strict;
 # firstres can be nav, syl, or blank for "Navigate Contents", Syllabus, or  # firstres can be nav, syl, or blank for "Navigate Contents", Syllabus, or
 # no entry respectively.  # no entry respectively.
 #   # 
 # crstype can be Course or Community  # crstype can be Course, Community or Placement
 #  #
 # crsquota is the total disk space permitted for course group portfolio files  # crsquota is the total disk space permitted for course group portfolio files
 # in all course groups.  # in all course groups.
Line 190  use strict; Line 187  use strict;
 #                   uname - username of DC who is requesting course creation  #                   uname - username of DC who is requesting course creation
 #                   udom - domain of DC who is requesting course creation  #                   udom - domain of DC who is requesting course creation
 #    #  
 # outputs (six)  -  output - text recording user roles added etc.  # outputs (four)  -  output - text recording user roles added etc.
 #                   logmsg - text to be logged  #                    logmsg - text to be logged
 #                   cloneinfo - text output from cloning  #                    keysmsg - text containing link(s) to manage keys page(s) 
 #                   keysmsg - text containing link(s) to manage keys page(s)   #                    codehash - reference to hash containing courseID => unique code
 #                   codehash - reference to hash containing courseID => unique code  #                               where unique code is a 6 character code, to distribute
 #                              where unique code is a 6 character code, to distribute  #                               to students as a shortcut to the course.
 #                              to students as a shortcut to the course.  
 #                   instcodes - references to hash of an array, where keys are  
 #                               institutional codes and values are an array of  
 #                               courseIDs of courses with that code.  
 #############################################################  #############################################################
   
 sub create_courses {  sub create_courses {
Line 217  sub create_courses { Line 210  sub create_courses {
             $longroles{'Community'}{$1} = $3;              $longroles{'Community'}{$1} = $3;
         }          }
     }      }
     my ($logmsg,$cloneinfo,$keysmsg,$newusermsg,$addresult,$user_lh,      my ($logmsg,$keysmsg,$newusermsg,$addresult,%codehash);
         %codehash,%instcodes);  
     my %enrollcount = ();      my %enrollcount = ();
     my $newcoursedir = LONCAPA::tempdir().'/addcourse/'.$dom.'/'.$context;      my $newcoursedir = LONCAPA::tempdir().'/addcourse/'.$dom.'/'.$context;
     if ($context eq 'auto') {      if ($context eq 'auto') {
         $user_lh = &Apache::loncommon::user_lang($uname,$udom);  
         $newcoursedir .= '/pending';          $newcoursedir .= '/pending';
     } else {      } else {
         if ($uname && $udom) {          if ($uname && $udom) {
Line 234  sub create_courses { Line 225  sub create_courses {
     if (@{$requests} > 0) {      if (@{$requests} > 0) {
         foreach my $request (@{$requests}) {          foreach my $request (@{$requests}) {
             my %details = ();              my %details = ();
             my $clonemsg = [];   
             if (-e $newcoursedir.'/'.$request) {              if (-e $newcoursedir.'/'.$request) {
                 &parse_coursereqs($newcoursedir.'/'.$request, \%details);                  &parse_coursereqs($newcoursedir.'/'.$request, \%details);
                 foreach my $num (sort(keys(%details))) {                  foreach my $num (sort(keys(%details))) {
                     my $reqdetails = $details{$num};                      my $reqdetails = $details{$num};
                     my $code;                      my $code;
                     my $courseid =                      my $courseid = 
                         &build_course($dom,$num,$context,$reqdetails,\%longroles,\$logmsg,                          &build_course($dom,$num,$context,$reqdetails,\%longroles,\$logmsg,\$newusermsg,
                                       $clonemsg,\$newusermsg,\$addresult,\%enrollcount,                                        \$addresult,\%enrollcount,\$output,\$keysmsg,undef,undef,undef,undef,\$code);
                                       \$output,\$keysmsg,undef,undef,undef,undef,\$code);  
                     if ($courseid =~m{^/$match_domain/$match_courseid}) {                      if ($courseid =~m{^/$match_domain/$match_courseid}) {
                         $$courseids{$courseid} = $details{$num}{'class'};                          $$courseids{$courseid} = $details{$num}{'class'};
                         if ($code) {                          if ($code) {
                             $codehash{$courseid} = $code;                              $codehash{$courseid} = $code;
                         }                          }
                         if ($details{$num}{'coursecode'} ne '') {  
                             push(@{$instcodes{$details{$num}{'coursecode'}}},$courseid);  
                         }  
                     }  
                     if (@{$clonemsg}) {  
                         if ($context eq 'web') {  
                             $cloneinfo .= '<p class="LC_info">';  
                         }  
                         foreach my $item (@{$clonemsg}) {  
                             if (ref($item) eq 'HASH') {  
                                 if ($context eq 'auto') {  
                                     $cloneinfo .= &mt_user($user_lh,$item->{mt},  
                                                            @{$item->{args}});  
                                 } else {  
                                     $cloneinfo .= &mt($item->{mt},@{$item->{args}});  
                                 }  
                             }  
                             if ($context eq 'web') {  
                                 $cloneinfo .= '<br />';  
                             }  
                             $cloneinfo .= "\n";  
                         }  
                         if ($context eq 'web') {  
                             $cloneinfo .= '</p>';  
                         }  
                     }                      }
                 }                  }
             }              }
         }          }
     }      }
     return ($output,$logmsg,$cloneinfo,$keysmsg,\%codehash,\%instcodes);      return ($output,$logmsg,$keysmsg,\%codehash);
 }  }
   
 #############################################################  #############################################################
Line 302  sub parse_coursereqs { Line 266  sub parse_coursereqs {
     my $xlist = 0;      my $xlist = 0;
     my $userkey = '';      my $userkey = '';
     my $role = '';      my $role = '';
     my @items = ('title','optional_id','coursecode','defaultcredits','coursehome','reshome','nonstandard','adds','drops','topmap','firstres','clonecrs','clonedom','datemode','dateshift','tinyurls','showphotos','setpolicy','setcontent','setcomment','setkeys','keyauth','disresdis','disablechat','openall','notify_owner','notify_dc','crstype','crsquota','uniquecode');      my @items = ('title','optional_id','coursecode','defaultcredits','coursehome','reshome','nonstandard','adds','drops','topmap','firstres','clonecrs','clonedom','datemode','dateshift','showphotos','setpolicy','setcontent','setkeys','keyauth','disresdis','disablechat','openall','notify_owner','notify_dc','crstype','crsquota','uniquecode');
     my @possroles = qw(st ad ep ta in cc co);      my @possroles = qw(st ad ep ta in cc co);
     my @dateitems = ('enrollstart','enrollend','accessstart','accessend','openallfrom');      my @dateitems = ('enrollstart','enrollend','accessstart','accessend');
     my @useritems = ('autharg','authtype','firstname','generation','lastname','middlename','studentID');      my @useritems = ('autharg','authtype','firstname','generation','lastname','middlename','studentID');
     my $p = HTML::Parser->new      my $p = HTML::Parser->new
     (      (
Line 428  sub parse_coursereqs { Line 392  sub parse_coursereqs {
 #   ref to hash of course creation information  #   ref to hash of course creation information
 #   ref to hash of role descriptions  #   ref to hash of role descriptions
 #   ref to scalar used to accumulate log messages  #   ref to scalar used to accumulate log messages
 #   ref to array used to accumulate messages about cloning  
 #   ref to scalar used to accumulate messages sent to new users  #   ref to scalar used to accumulate messages sent to new users
 #   ref to scalar used to accumulate results of new user additions  #   ref to scalar used to accumulate results of new user additions
 #   ref to hash of enrollment counts for different roles  #   ref to hash of enrollment counts for different roles
Line 440  sub parse_coursereqs { Line 403  sub parse_coursereqs {
 #       course requests submitted via course request form.  #       course requests submitted via course request form.
 #   optional category  #   optional category
 #   optional ref to scalar for six character unique identifier  #   optional ref to scalar for six character unique identifier
 #   caller context (e.g., auto)  
 #   user language handle, if caller context is 'auto'  
 #  #
 # outputs  # outputs
 #   LON-CAPA courseID for new (created) course  #   LON-CAPA courseID for new (created) course
Line 449  sub parse_coursereqs { Line 410  sub parse_coursereqs {
 #########################################################  #########################################################
   
 sub build_course {  sub build_course {
     my ($cdom,$num,$context,$details,$longroles,$logmsg,$clonemsg,$newusermsg,      my ($cdom,$num,$context,$details,$longroles,$logmsg,$newusermsg,$addresult,
         $addresult,$enrollcount,$output,$keysmsg,$udom,$uname,$cnum,$category,          $enrollcount,$output,$keysmsg,$udom,$uname,$cnum,$category,$coderef) = @_;
         $coderef,$callercontext,$user_lh) = @_;  
     return unless (ref($details) eq 'HASH');      return unless (ref($details) eq 'HASH');
     my $owner_uname = $details->{'owner'};      my $owner_uname = $details->{'owner'};
     my $owner_domain = $details->{'domain'};      my $owner_domain = $details->{'domain'};
Line 468  sub build_course { Line 428  sub build_course {
             $rolenames = $longroles->{'Community'};              $rolenames = $longroles->{'Community'};
         }          }
     } else {      } else {
         $crstype = 'Course';          if ($details->{'crstype'} eq 'Placement') {
               $crstype = $details->{'crstype'};
           } else {
               $crstype = 'Course';
           }
         $ccrole = 'cc';          $ccrole = 'cc';
         if (ref($longroles) eq 'HASH') {          if (ref($longroles) eq 'HASH') {
             $rolenames = $longroles->{'Course'};              $rolenames = $longroles->{'Course'};
Line 491  sub build_course { Line 455  sub build_course {
     if ($firstres eq '') {      if ($firstres eq '') {
         if ($crstype eq 'Community') {          if ($crstype eq 'Community') {
             $firstres = 'nav';              $firstres = 'nav';
           } elsif ($crstype eq 'Placement') {
               $firstres = 'blank'; 
         } else {          } else {
             $firstres = 'syl';              $firstres = 'syl';
         }          }
Line 539  sub build_course { Line 505  sub build_course {
             $details->{'datemode'} = 'shift';              $details->{'datemode'} = 'shift';
             $details->{'dateshift'} = 365;              $details->{'dateshift'} = 365;
         }          }
         if ($details->{'tinyurls'} !~ /^(delete|transfer|create)$/) {  
             $details->{'tinyurls'} = 'create';  
         }  
         my $courseargs = {          my $courseargs = {
                ccuname => $details->{'owner'},                 ccuname => $details->{'owner'},
                ccdomain => $details->{'domain'},                 ccdomain => $details->{'domain'},
Line 559  sub build_course { Line 522  sub build_course {
                clonedomain => $details->{'clonedom'},                 clonedomain => $details->{'clonedom'},
                datemode => $details->{'datemode'},                 datemode => $details->{'datemode'},
                dateshift => $details->{'dateshift'},                 dateshift => $details->{'dateshift'},
                tinyurls => $details->{'tinyurls'},  
                crsid => $details->{'optional_id'},                 crsid => $details->{'optional_id'},
                curruser => $details->{'owner'},                 curruser => $details->{'owner'},
                crssections => $sectionstr,                 crssections => $sectionstr,
Line 578  sub build_course { Line 540  sub build_course {
                endaccess => $details->{'accessend'},                 endaccess => $details->{'accessend'},
                setpolicy => $details->{'setpolicy'},                 setpolicy => $details->{'setpolicy'},
                setcontent => $details->{'setcontent'},                 setcontent => $details->{'setcontent'},
                setcomment => $details->{'setcomment'},  
                reshome => $reshome,                 reshome => $reshome,
                setkeys => $details->{'setkeys'},                 setkeys => $details->{'setkeys'},
                keyauth => $details->{'keyauth'},                 keyauth => $details->{'keyauth'},
                disresdis => $details->{'disresdis'},                 disresdis => $details->{'disresdis'},
                disablechat => $details->{'disablechat'},                 disablechat => $details->{'disablechat'},
                openall => $details->{'openall'},                 openall => $details->{'openall'},
                openallfrom => $details->{'openallfrom'},  
                firstres => $firstres                 firstres => $firstres
                };                 };
         if ($details->{'textbook'}) {          if ($details->{'textbook'}) {
Line 596  sub build_course { Line 556  sub build_course {
             $$logmsg .= &mt('Invalid home server for course').': '.$details->{'coursehome'};              $$logmsg .= &mt('Invalid home server for course').': '.$details->{'coursehome'};
             return;              return;
         }          }
         my ($success,$msg,$cloneinfo) =          my ($success, $msg) = 
             &Apache::loncommon::construct_course($courseargs,$logmsg,\$courseid,\$crsudom,\$crsunum,              &Apache::loncommon::construct_course($courseargs,$logmsg,\$courseid,\$crsudom,\$crsunum,
                                                  $udom,$uname,$context,$cnum,$category,$coderef,                                                   $udom,$uname,$context,$cnum,$category,$coderef);
                                                  $callercontext,$user_lh);  
  $$logmsg .= $msg;   $$logmsg .= $msg;
         if ((ref($clonemsg) eq 'ARRAY') && (ref($cloneinfo) eq 'ARRAY')) {  
              push(@{$clonemsg},@{$cloneinfo});  
         }  
         if (!$success) {          if (!$success) {
             return;              return;
         }          }

Removed from v.1.40.2.3.2.1  
changed lines
  Added in v.1.41


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