Diff for /loncom/interface/loncreatecourse.pm between versions 1.76 and 1.85

version 1.76, 2005/02/17 08:29:42 version 1.85, 2006/01/16 23:11:50
Line 86  sub readfile { Line 86  sub readfile {
 # ============================================================ Write a userfile  # ============================================================ Write a userfile
   
 sub writefile {  sub writefile {
     (my $courseid, my $which,$ENV{'form.output'})=@_;      (my $courseid, my $which,$env{'form.output'})=@_;
     my %crsdata=&Apache::lonnet::coursedescription($courseid);      my %crsdata=&Apache::lonnet::coursedescription($courseid);
     return &Apache::lonnet::finishuserfileupload(      return &Apache::lonnet::finishuserfileupload(
   $crsdata{'num'},$crsdata{'domain'},    $crsdata{'num'},$crsdata{'domain'},
   $crsdata{'home'},  
   'output',$which);    'output',$which);
 }  }
   
Line 160  sub copyresourcedb { Line 159  sub copyresourcedb {
     my %newdata=();      my %newdata=();
     undef %newdata;      undef %newdata;
     my $startdate=$data{$origcrsid.'.0.opendate'};      my $startdate=$data{$origcrsid.'.0.opendate'};
       if (!$startdate) {
    # now global start date for assements try the enrollment start
    my %start=&Apache::lonnet::get('environment',
      ['default_enrollment_start_date'],
      $origcrsdata{'domain'},$origcrsdata{'num'});
   
    $startdate = $start{'default_enrollment_start_date'};
       }
     my $today=time;      my $today=time;
     my $delta=0;      my $delta=0;
     if ($startdate) {      if ($startdate) {
Line 194  sub copyresourcedb { Line 201  sub copyresourcedb {
  $thiskey=~s/^$origcrsid/$newcrsid/;   $thiskey=~s/^$origcrsid/$newcrsid/;
  $newdata{$thiskey}=$data{$_};   $newdata{$thiskey}=$data{$_};
  if ($data{$_.'.type'}=~/^date_(start|end)$/) {   if ($data{$_.'.type'}=~/^date_(start|end)$/) {
     $newdata{$thiskey}=$newdata{$thiskey}+$delta;      if ($delta > 0) {
    $newdata{$thiskey}=$newdata{$thiskey}+$delta;
       } else {
    # no delta, it's unlikely we want the old dates and times
    delete($newdata{$thiskey});
    delete($newdata{$thiskey.'.type'});
       }
  }   }
     }      }
     return &Apache::lonnet::put      return &Apache::lonnet::put
Line 215  sub copyuserfiles { Line 228  sub copyuserfiles {
   
 sub copydbfiles {  sub copydbfiles {
     my ($origcrsid,$newcrsid)=@_;      my ($origcrsid,$newcrsid)=@_;
   
       my ($origcrs_discussion) = ($origcrsid=~m|^/(.*)|);
       $origcrs_discussion=~s|/|_|g;
     foreach (&crsdirlist($origcrsid)) {      foreach (&crsdirlist($origcrsid)) {
  if ($_=~/\.db$/) {   if ($_=~/\.db$/) {
     unless       unless 
              ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata)/) {               ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata|\Q$origcrs_discussion\E|slots|slot_reservations|(grading|review)queue|CODEs)/) {
  &copydb($origcrsid,$newcrsid,$_);   &copydb($origcrsid,$newcrsid,$_);
    my $histfile=$_;
    $histfile=~s/\.db$/\.hist/;
    &copyfile($origcrsid,$newcrsid,$histfile);
      }       }
  }   }
     }      }
Line 238  sub copycoursefiles { Line 257  sub copycoursefiles {
   
 sub print_course_creation_page {  sub print_course_creation_page {
     my $r=shift;      my $r=shift;
     my $defdom=$ENV{'request.role.domain'};      my $defdom=$env{'request.role.domain'};
     my %host_servers = &Apache::loncommon::get_library_servers($defdom);      my %host_servers = &Apache::loncommon::get_library_servers($defdom);
     my $course_home = '<select name="course_home" size="1">'."\n";      my $course_home = '<select name="course_home" size="1">'."\n";
     foreach my $server (sort(keys(%host_servers))) {      foreach my $server (sort(keys(%host_servers))) {
Line 253  sub print_course_creation_page { Line 272  sub print_course_creation_page {
     my $bodytag=&Apache::loncommon::bodytag('Create a New Course');      my $bodytag=&Apache::loncommon::bodytag('Create a New Course');
     my $helplink=&Apache::loncommon::help_open_topic('Create_Course',&mt('Help on Creating Courses'));      my $helplink=&Apache::loncommon::help_open_topic('Create_Course',&mt('Help on Creating Courses'));
     my $cloneform=&Apache::loncommon::select_dom_form      my $cloneform=&Apache::loncommon::select_dom_form
  ($ENV{'request.role.domain'},'clonedomain').   ($env{'request.role.domain'},'clonedomain').
      &Apache::loncommon::selectcourse_link       &Apache::loncommon::selectcourse_link
      ('ccrs','clonecourse','clonedomain');       ('ccrs','clonecourse','clonedomain');
     my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($ENV{'request.role.domain'});      my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
     my $starttime = time;      my $starttime = time;
     my $endtime = time+(6*30*24*60*60); # 6 months from now, approx      my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
     my $enroll_table = &Apache::londropadd::date_setting_table($starttime,$endtime,'create_enrolldates');      my $enroll_table = &Apache::londropadd::date_setting_table($starttime,$endtime,'create_enrolldates');
Line 327  sub print_course_creation_page { Line 346  sub print_course_creation_page {
                     'pcda' => "Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process",                      'pcda' => "Please choose the default authentication method to be used by new users added to this LON-CAPA domain by the automated enrollment process",
                     'nech' => "Notification of enrollment changes",                      'nech' => "Notification of enrollment changes",
                     'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?",                      'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
                       'ndcl' => "Notification to domain coordinator via LON-CAPA message when enrollment changes occur during the automated update?",
                     'irsp' => "Include retrieval of student photographs?",                      'irsp' => "Include retrieval of student photographs?",
     'rshm' => 'Resource Space Home',      'rshm' => 'Resource Space Home',
                     'opco' => "Open Course"                      'opco' => "Open Course"
Line 524  $locform Line 544  $locform
 <b>$lt{'nech'}</b><br />  <b>$lt{'nech'}</b><br />
 $lt{'nccl'}<br/>  $lt{'nccl'}<br/>
 <label>  <label>
     <input type="radio" name="notify" value="1" />$lt{'yes'}      <input type="radio" name="notify_owner" value="1" />$lt{'yes'}
 </label>   </label> 
 <label>  <label>
     <input type="radio" name="notify" value="0" checked="true" />$lt{'no'}      <input type="radio" name="notify_owner" value="0" checked="true" />$lt{'no'}
   </label>
   <br />
   $lt{'ndcl'}<br/>
   <label>
       <input type="radio" name="notify_dc" value="1" />$lt{'yes'}
   </label>
   <label>
       <input type="radio" name="notify_dc" value="0" checked="true" />$lt{'no'}
 </label>  </label>
 </p><p>  </p><p>
 <b>$lt{'irsp'}</b>  <b>$lt{'irsp'}</b>
Line 548  $lt{'nccl'}<br/> Line 576  $lt{'nccl'}<br/>
 <label>  <label>
     <b>$lt{'dmn'}:</b> $domform      <b>$lt{'dmn'}:</b> $domform
 </label>  </label>
 </p><p>  
 <label>  
     <b>$lt{'ierc'}:</b>  
     <input type="checkbox" name="expireown" checked />  
 </label>  
 </p>  </p>
 <p>  <p>
 <input type="hidden" name="phase" value="two" />  <input type="hidden" name="phase" value="two" />
Line 568  ENDDOCUMENT Line 591  ENDDOCUMENT
   
 sub create_course {  sub create_course {
     my $r=shift;      my $r=shift;
     my $ccuname=$ENV{'form.ccuname'};      my $ccuname=$env{'form.ccuname'};
     my $ccdomain=$ENV{'form.ccdomain'};      my $ccdomain=$env{'form.ccdomain'};
     $ccuname=~s/\W//g;      $ccuname=~s/\W//g;
     $ccdomain=~s/\W//g;      $ccdomain=~s/\W//g;
   
Line 581  sub create_course { Line 604  sub create_course {
     my $autharg;      my $autharg;
     my $authtype;      my $authtype;
   
     if ($ENV{'form.login'} eq 'krb') {      if ($env{'form.login'} eq 'krb') {
         $authtype = 'krb';          $authtype = 'krb';
         $authtype .=$ENV{'form.krbver'};          $authtype .=$env{'form.krbver'};
         $autharg = $ENV{'form.krbarg'};          $autharg = $env{'form.krbarg'};
     } elsif ($ENV{'form.login'} eq 'int') {      } elsif ($env{'form.login'} eq 'int') {
         $authtype ='internal';          $authtype ='internal';
         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {          if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
             $autharg = $ENV{'form.intarg'};              $autharg = $env{'form.intarg'};
         }          }
     } elsif ($ENV{'form.login'} eq 'loc') {      } elsif ($env{'form.login'} eq 'loc') {
         $authtype = 'localauth';          $authtype = 'localauth';
         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {          if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
             $autharg = $ENV{'form.locarg'};              $autharg = $env{'form.locarg'};
         }          }
     }      }
   
Line 611  ENDENHEAD Line 634  ENDENHEAD
     my $args = {      my $args = {
                ccuname => $ccuname,                 ccuname => $ccuname,
                ccdomain => $ccdomain,                 ccdomain => $ccdomain,
                cdescr => $ENV{'form.title'},                 cdescr => $env{'form.title'},
                curl => $ENV{'form.topmap'},                 curl => $env{'form.topmap'},
                course_domain => $ENV{'request.role.domain'},                 course_domain => $env{'request.role.domain'},
                course_home =>  $ENV{'form.course_home'},                 course_home =>  $env{'form.course_home'},
                nonstandard => $ENV{'form.nonstandard'},                 nonstandard => $env{'form.nonstandard'},
                crscode => $ENV{'form.crscode'},                 crscode => $env{'form.crscode'},
                clonecourse => $ENV{'form.clonecourse'},                 clonecourse => $env{'form.clonecourse'},
                clonedomain => $ENV{'form.clonedomain'},                 clonedomain => $env{'form.clonedomain'},
                crsid => $ENV{'form.crsid'},                 crsid => $env{'form.crsid'},
                curruser => $ENV{'user.name'},                 curruser => $env{'user.name'},
                crssections => $ENV{'form.crssections'},                 crssections => $env{'form.crssections'},
                crsxlist => $ENV{'form.crsxlist'},                 crsxlist => $env{'form.crsxlist'},
                autoadds => $ENV{'form.autoadds'},                 autoadds => $env{'form.autoadds'},
                autodrops => $ENV{'form.autodrops'},                 autodrops => $env{'form.autodrops'},
                notify => $ENV{'form.notify'},                 notify_owner => $env{'form.notify_owner'},
                no_end_date => $ENV{'form.no_end_date'},                 notify_dc => $env{'form.notify_dc'},
                showphotos => $ENV{'form.showphotos'},                 no_end_date => $env{'form.no_end_date'},
                  showphotos => $env{'form.showphotos'},
                authtype => $authtype,                 authtype => $authtype,
                autharg => $autharg,                 autharg => $autharg,
                enrollstart => $enrollstart,                 enrollstart => $enrollstart,
                enrollend => $enrollend,                 enrollend => $enrollend,
                startaccess => $startaccess,                 startaccess => $startaccess,
                endaccess => $endaccess,                 endaccess => $endaccess,
                setpolicy => $ENV{'form.setpolicy'},                 setpolicy => $env{'form.setpolicy'},
                setcontent => $ENV{'form.setcontent'},                 setcontent => $env{'form.setcontent'},
                reshome => $ENV{'form.reshome'},                 reshome => $env{'form.reshome'},
                setkeys => $ENV{'form.setkeys'},                 setkeys => $env{'form.setkeys'},
                keyauth => $ENV{'form.keyauth'},                 keyauth => $env{'form.keyauth'},
                disresdis => $ENV{'form.disresdis'},                 disresdis => $env{'form.disresdis'},
                disablechat => $ENV{'form.disablechat'},                 disablechat => $env{'form.disablechat'},
                openall => $ENV{'form.openall'},                 openall => $env{'form.openall'},
                firstres => $ENV{'form.firstres'}                 firstres => $env{'form.firstres'}
                };                 };
   
     #      #
Line 664  ENDENHEAD Line 688  ENDENHEAD
     }      }
     # Check the proposed home server for the course      # Check the proposed home server for the course
     my %host_servers = &Apache::loncommon::get_library_servers      my %host_servers = &Apache::loncommon::get_library_servers
         ($ENV{'request.role.domain'});          ($env{'request.role.domain'});
     if (! exists($host_servers{$ENV{'form.course_home'}})) {      if (! exists($host_servers{$env{'form.course_home'}})) {
         $r->print(&mt('Invalid home server for course').': '.          $r->print(&mt('Invalid home server for course').': '.
                   $ENV{'form.course_home'}.'</body></html>');                    $env{'form.course_home'}.'</body></html>');
         return;          return;
     }      }
     my ($courseid,$crsudom,$crsunum);      my ($courseid,$crsudom,$crsunum);
     $r->print(&construct_course($args,\$logmsg,\$courseid,\$crsudom,\$crsunum));      $r->print(&construct_course($args,\$logmsg,\$courseid,\$crsudom,\$crsunum,$env{'user.domain'},$env{'user.name'}));
   
 #  #
 # Make current user course adminstrator  # Make the requested user a course coordinator
 #  
     my $end=undef;  
     my $addition='';  
     if ($ENV{'form.expireown'}) { $end=time+5; $addition='expired'; }  
     $r->print(&mt('Assigning').' '.$addition.' '.&mt('role of course coordinator to self').': '.  
     &Apache::lonnet::assignrole(  
      $ENV{'user.domain'},$ENV{'user.name'},$courseid,'cc',$end).'<br>');  
 #  
 # Make additional user course administrator  
 #  #
    if (($ccdomain) && ($ccuname)) {     if (($ccdomain) && ($ccuname)) {
     $r->print(&mt('Assigning role of course coordinator to').' '.      $r->print(&mt('Assigning role of course coordinator to').' '.
                $ccuname.' at '.$ccdomain.': '.                 $ccuname.' at '.$ccdomain.': '.
     &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');      &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'<p>');
    }     }
     if ($ENV{'form.setkeys'}) {      if ($env{'form.setkeys'}) {
         $r->print(          $r->print(
  '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');   '<p><a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a></p>');
     }      }
Line 700  ENDENHEAD Line 715  ENDENHEAD
 }  }
   
 sub construct_course {  sub construct_course {
     my ($args,$logmsg,$courseid,$crsudom,$crsunum) = @_;      my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname) = @_;
     my $outcome;      my $outcome;
   
 #  #
Line 786  sub construct_course { Line 801  sub construct_course {
             foreach my $item (@sections) {              foreach my $item (@sections) {
                 my ($sec,$gp) = split/:/,$item;                  my ($sec,$gp) = split/:/,$item;
                 my $class = $args->{'crscode'}.$sec;                  my $class = $args->{'crscode'}.$sec;
                 my $addcheck = &Apache::lonnet::auto_new_course($crsunum,$crsudom,$class,$cenv{'internal.courseowner'});                  my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                 $cenv{'internal.sectionnums'} .= $item.',';                  $cenv{'internal.sectionnums'} .= $item.',';
                 unless ($addcheck eq 'ok') {                  unless ($addcheck eq 'ok') {
                     push @badclasses, $class;                      push @badclasses, $class;
Line 824  sub construct_course { Line 839  sub construct_course {
     if ($args->{'autodrops'}) {      if ($args->{'autodrops'}) {
         $cenv{'internal.autodrops'}=$args->{'autodrops'};          $cenv{'internal.autodrops'}=$args->{'autodrops'};
     }      }
     if ($args->{'notify'}) {  # check for notification of enrollment changes
       if ($args->{'ccuname'}) {      my @notified = ();
         $cenv{'internal.notifylist'} = $args->{'ccuname'}.'@'.$args->{'ccdomain'};      if ($args->{'notify_owner'}) {
       }          if ($args->{'ccuname'} ne '') {
               push(@notified,$args->{'ccuname'}.'@'.$args->{'ccdomain'});
           }
       }
       if ($args->{'notify_dc'}) {
           if ($uname ne '') { 
               push(@notified,$uname.'@'.$udom);
           }
       }
       if (@notified > 0) {
           my $notifylist;
           if (@notified > 1) {
               $notifylist = join(',',@notified);
           } else {
               $notifylist = $notified[0];
           }
           $cenv{'internal.notifylist'} = $notifylist;
     }      }
     if (@badclasses > 0) {      if (@badclasses > 0) {
         my %lt=&Apache::lonlocal::texthash(          my %lt=&Apache::lonlocal::texthash(
Line 958  sub handler { Line 989  sub handler {
        return OK;         return OK;
     }      }
   
     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {      if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
        &Apache::loncommon::content_type($r,'text/html');         &Apache::loncommon::content_type($r,'text/html');
        $r->send_http_header;         $r->send_http_header;
   
        if ($ENV{'form.phase'} eq 'two') {         if ($env{'form.phase'} eq 'two') {
            &create_course($r);             &create_course($r);
        } else {         } else {
    &print_course_creation_page($r);     &print_course_creation_page($r);
        }         }
    } else {     } else {
       $ENV{'user.error.msg'}=        $env{'user.error.msg'}=
         "/adm/createcourse:ccc:0:0:Cannot create courses";          "/adm/createcourse:ccc:0:0:Cannot create courses";
       return HTTP_NOT_ACCEPTABLE;         return HTTP_NOT_ACCEPTABLE; 
    }     }

Removed from v.1.76  
changed lines
  Added in v.1.85


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