--- loncom/interface/loncreatecourse.pm 2005/03/03 21:24:24 1.77 +++ loncom/interface/loncreatecourse.pm 2006/05/11 01:16:44 1.87 @@ -1,7 +1,7 @@ # The LearningOnline Network # Create a course # -# $Id: loncreatecourse.pm,v 1.77 2005/03/03 21:24:24 raeburn Exp $ +# $Id: loncreatecourse.pm,v 1.87 2006/05/11 01:16:44 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -86,11 +86,10 @@ sub readfile { # ============================================================ Write a userfile sub writefile { - (my $courseid, my $which,$ENV{'form.output'})=@_; + (my $courseid, my $which,$env{'form.output'})=@_; my %crsdata=&Apache::lonnet::coursedescription($courseid); return &Apache::lonnet::finishuserfileupload( $crsdata{'num'},$crsdata{'domain'}, - $crsdata{'home'}, 'output',$which); } @@ -160,6 +159,14 @@ sub copyresourcedb { my %newdata=(); undef %newdata; 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 $delta=0; if ($startdate) { @@ -194,7 +201,13 @@ sub copyresourcedb { $thiskey=~s/^$origcrsid/$newcrsid/; $newdata{$thiskey}=$data{$_}; 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 @@ -215,11 +228,17 @@ sub copyuserfiles { sub copydbfiles { my ($origcrsid,$newcrsid)=@_; + + my ($origcrs_discussion) = ($origcrsid=~m|^/(.*)|); + $origcrs_discussion=~s|/|_|g; foreach (&crsdirlist($origcrsid)) { if ($_=~/\.db$/) { unless - ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata)/) { + ($_=~/^(nohist\_|discussiontimes|classlist|versionupdate|resourcedata|\Q$origcrs_discussion\E|slots|slot_reservations|(grading|review)queue|CODEs)/) { ©db($origcrsid,$newcrsid,$_); + my $histfile=$_; + $histfile=~s/\.db$/\.hist/; + ©file($origcrsid,$newcrsid,$histfile); } } } @@ -238,7 +257,7 @@ sub copycoursefiles { sub print_course_creation_page { 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 $course_home = '\n"; my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain'); - my $bodytag=&Apache::loncommon::bodytag('Create a New Course'); my $helplink=&Apache::loncommon::help_open_topic('Create_Course',&mt('Help on Creating Courses')); my $cloneform=&Apache::loncommon::select_dom_form - ($ENV{'request.role.domain'},'clonedomain'). + ($env{'request.role.domain'},'clonedomain'). &Apache::loncommon::selectcourse_link ('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 $endtime = time+(6*30*24*60*60); # 6 months from now, approx my $enroll_table = &Apache::londropadd::date_setting_table($starttime,$endtime,'create_enrolldates'); @@ -332,11 +350,8 @@ sub print_course_creation_page { 'rshm' => 'Resource Space Home', 'opco' => "Open Course" ); - my $html=&Apache::lonxml::xmlbegin(); - $r->print(< - $coursebrowserjs -The LearningOnline Network with CAPA - -$bodytag +END + + my $start_page = + &Apache::loncommon::start_page('Create a New Course',$js); + my $end_page = + &Apache::loncommon::end_page(); + + $r->print(<

$lt{'cinf'}

@@ -563,8 +584,7 @@ $lt{'ndcl'}

- - +$end_page ENDDOCUMENT } @@ -572,8 +592,8 @@ ENDDOCUMENT sub create_course { my $r=shift; - my $ccuname=$ENV{'form.ccuname'}; - my $ccdomain=$ENV{'form.ccdomain'}; + my $ccuname=$env{'form.ccuname'}; + my $ccdomain=$env{'form.ccdomain'}; $ccuname=~s/\W//g; $ccdomain=~s/\W//g; @@ -585,69 +605,62 @@ sub create_course { my $autharg; my $authtype; - if ($ENV{'form.login'} eq 'krb') { + if ($env{'form.login'} eq 'krb') { $authtype = 'krb'; - $authtype .=$ENV{'form.krbver'}; - $autharg = $ENV{'form.krbarg'}; - } elsif ($ENV{'form.login'} eq 'int') { + $authtype .=$env{'form.krbver'}; + $autharg = $env{'form.krbarg'}; + } elsif ($env{'form.login'} eq 'int') { $authtype ='internal'; - if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) { - $autharg = $ENV{'form.intarg'}; + if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) { + $autharg = $env{'form.intarg'}; } - } elsif ($ENV{'form.login'} eq 'loc') { + } elsif ($env{'form.login'} eq 'loc') { $authtype = 'localauth'; - if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) { - $autharg = $ENV{'form.locarg'}; + if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) { + $autharg = $env{'form.locarg'}; } } my $logmsg; - my $html=&Apache::lonxml::xmlbegin(); - my $bodytag=&Apache::loncommon::bodytag('Create a New Course'); - $r->print(< -The LearningOnline Network with CAPA - -$bodytag -ENDENHEAD + my $start_page=&Apache::loncommon::start_page('Create a New Course'); + $r->print($start_page); my $args = { ccuname => $ccuname, ccdomain => $ccdomain, - cdescr => $ENV{'form.title'}, - curl => $ENV{'form.topmap'}, - course_domain => $ENV{'request.role.domain'}, - course_home => $ENV{'form.course_home'}, - nonstandard => $ENV{'form.nonstandard'}, - crscode => $ENV{'form.crscode'}, - clonecourse => $ENV{'form.clonecourse'}, - clonedomain => $ENV{'form.clonedomain'}, - crsid => $ENV{'form.crsid'}, - curruser => $ENV{'user.name'}, - crssections => $ENV{'form.crssections'}, - crsxlist => $ENV{'form.crsxlist'}, - autoadds => $ENV{'form.autoadds'}, - autodrops => $ENV{'form.autodrops'}, - notify_owner => $ENV{'form.notify_owner'}, - notify_dc => $ENV{'form.notify_dc'}, - no_end_date => $ENV{'form.no_end_date'}, - showphotos => $ENV{'form.showphotos'}, + cdescr => $env{'form.title'}, + curl => $env{'form.topmap'}, + course_domain => $env{'request.role.domain'}, + course_home => $env{'form.course_home'}, + nonstandard => $env{'form.nonstandard'}, + crscode => $env{'form.crscode'}, + clonecourse => $env{'form.clonecourse'}, + clonedomain => $env{'form.clonedomain'}, + crsid => $env{'form.crsid'}, + curruser => $env{'user.name'}, + crssections => $env{'form.crssections'}, + crsxlist => $env{'form.crsxlist'}, + autoadds => $env{'form.autoadds'}, + autodrops => $env{'form.autodrops'}, + notify_owner => $env{'form.notify_owner'}, + notify_dc => $env{'form.notify_dc'}, + no_end_date => $env{'form.no_end_date'}, + showphotos => $env{'form.showphotos'}, authtype => $authtype, autharg => $autharg, enrollstart => $enrollstart, enrollend => $enrollend, startaccess => $startaccess, endaccess => $endaccess, - setpolicy => $ENV{'form.setpolicy'}, - setcontent => $ENV{'form.setcontent'}, - reshome => $ENV{'form.reshome'}, - setkeys => $ENV{'form.setkeys'}, - keyauth => $ENV{'form.keyauth'}, - disresdis => $ENV{'form.disresdis'}, - disablechat => $ENV{'form.disablechat'}, - openall => $ENV{'form.openall'}, - firstres => $ENV{'form.firstres'} + setpolicy => $env{'form.setpolicy'}, + setcontent => $env{'form.setcontent'}, + reshome => $env{'form.reshome'}, + setkeys => $env{'form.setkeys'}, + keyauth => $env{'form.keyauth'}, + disresdis => $env{'form.disresdis'}, + disablechat => $env{'form.disablechat'}, + openall => $env{'form.openall'}, + firstres => $env{'form.firstres'} }; # @@ -664,19 +677,19 @@ ENDENHEAD - '); + '.&Apache::loncommon::end_page()); return; } # Check the proposed home server for the course my %host_servers = &Apache::loncommon::get_library_servers - ($ENV{'request.role.domain'}); - if (! exists($host_servers{$ENV{'form.course_home'}})) { + ($env{'request.role.domain'}); + if (! exists($host_servers{$env{'form.course_home'}})) { $r->print(&mt('Invalid home server for course').': '. - $ENV{'form.course_home'}.''); + $env{'form.course_home'}.&Apache::loncommon::end_page()); return; } my ($courseid,$crsudom,$crsunum); - $r->print(&construct_course($args,\$logmsg,\$courseid,\$crsudom,\$crsunum,$ENV{'user.domain'},$ENV{'user.name'})); + $r->print(&construct_course($args,\$logmsg,\$courseid,\$crsudom,\$crsunum,$env{'user.domain'},$env{'user.name'})); # # Make the requested user a course coordinator @@ -686,13 +699,16 @@ ENDENHEAD $ccuname.' at '.$ccdomain.': '. &Apache::lonnet::assignrole($ccdomain,$ccuname,$courseid,'cc').'

'); } - if ($ENV{'form.setkeys'}) { + if ($env{'form.setkeys'}) { $r->print( '

'.&mt('Manage Access Keys').'

'); } # Flush the course logs so reverse user roles immediately updated &Apache::lonnet::flushcourselogs(); - $r->print('

'.&mt('Roles will be active at next login').'.

'); + $r->print('

'.&mt('Roles will be active at next login').'.

'. + '

'. + &mt('Create Another Course').'

'. + &Apache::loncommon::end_page()); } sub construct_course { @@ -782,7 +798,7 @@ sub construct_course { foreach my $item (@sections) { my ($sec,$gp) = split/:/,$item; 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.','; unless ($addcheck eq 'ok') { push @badclasses, $class; @@ -970,17 +986,17 @@ sub handler { 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'); $r->send_http_header; - if ($ENV{'form.phase'} eq 'two') { + if ($env{'form.phase'} eq 'two') { &create_course($r); } else { &print_course_creation_page($r); } } else { - $ENV{'user.error.msg'}= + $env{'user.error.msg'}= "/adm/createcourse:ccc:0:0:Cannot create courses"; return HTTP_NOT_ACCEPTABLE; }