--- loncom/interface/lonrequestcourse.pm 2010/01/02 18:11:46 1.41.2.3 +++ loncom/interface/lonrequestcourse.pm 2010/11/08 21:16:24 1.41.2.7 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.41.2.3 2010/01/02 18:11:46 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.41.2.7 2010/11/08 21:16:24 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -285,6 +285,9 @@ sub handler { $jscript = &mainmenu_javascript(); } else { $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored); + if ($state eq 'courseinfo') { + $jscript .= &cloning_javascript(); + } } } @@ -292,7 +295,7 @@ sub handler { $jscript .= "\n".&Apache::loncommon::userbrowser_javascript(); } - my $loaditems = &onload_action($action,$state); + my $loaditems = &onload_action($action,$state,$dom); my (%can_request,%request_domains); my $canreq = @@ -364,6 +367,22 @@ function setAction(courseForm) { END } +sub cloning_javascript { + return <<"END"; +function setCloneDisplay(courseForm) { + if (courseForm.cloning.length > 1) { + for (var i=0; i<courseForm.cloning.length; i++) { + if (courseForm.cloning[i].checked) { + if (courseForm.cloning[i].value == 1) { + document.getElementById('cloneoptions').style.display="block";; + } + } + } + } +} +END +} + sub get_breadcrumbs { my ($dom,$action,$state,$states,$trail) = @_; my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description); @@ -480,6 +499,7 @@ sub form_elements { }, courseinfo => { cdescr => 'text', + cloning => 'radio', clonecrs => 'text', clonedom => 'selectbox', datemode => 'radio', @@ -518,8 +538,13 @@ sub form_elements { if ($dom eq 'gcitest') { %{$elements{'new'}{'courseinfo'}} = ( cdescr => 'text', - concepttest => 'radio', + concepttest => 'radio', ); + if (&show_cloneable()) { + $elements{'new'}{'courseinfo'}{'clonecrs'} = 'selectbox'; + $elements{'new'}{'courseinfo'}{'clonedom'} = 'hidden'; + $elements{'new'}{'courseinfo'}{'cloneroster'} = 'checkbox'; + } } my $numlib = keys(%servers); if ($numlib > 1) { @@ -625,7 +650,12 @@ sub onload_action { if ($state eq 'crstype') { $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)'; } else { - $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs)'; + $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);'; + } + if ($state eq 'courseinfo') { + if (&show_cloneable()) { + $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);'; + } } if (($state eq 'process') && ($env{'form.concepttest'} eq 'editmyown')) { $loaditems{'onload'} = 'javascript:setInitialVisibility()'; @@ -755,8 +785,9 @@ END '<li>'.&mt('Creation of a course "container" and setting of access dates').'</li>'. '<li>'.&mt('Assembly of a valid test from Concept Inventory questions').'</li>'. '<li>'.&mt('Enrollment of students').'</li>'. - '</ol></p><p>'.&mt('When assembling a test you may either:'). - '<br />'.&mt('(a) have a valid test built automatically by the WebCenter, or').'<br />'.&mt('(b) select the questions to include by combining questions chosen from eleven bins with four mandatory questions.').'</p><p>'.&mt('The most efficient way to enroll students is to upload a text file containing usernames and passwords.').'<br />'.&mt("Students' full e-mail addresses should be used as their usernames to ensure uniqueness.").'</p><div>'. + '</ol></p><p>'.&mt('When assembling a test you may:'). + '<br />'.&mt('(a) have a valid test built automatically by the WebCenter, or').'<br />'.&mt('(b) select the questions to include by combining questions chosen from eleven bins with four mandatory questions, or'). + '<br />'.&mt('(c) copy one of your existing tests (including optional copying of the student roster)').'</p><p>'.&mt('The most efficient way to enroll students is to upload a text file containing usernames and passwords.').'<br />'.&mt("Students' full e-mail addresses should be used as their usernames to ensure uniqueness.").'</p><div>'. '<form name="'.$formname.'" method="post" action="/adm/requestcourse">'."\n". '<input type="hidden" name="state" value="courseinfo" />'."\n". '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n". @@ -2250,11 +2281,16 @@ sub print_review { $concepttest = 'Auto-generated'; } elsif ($env{'form.concepttest'} eq 'editmyown') { $concepttest = 'Manually selected'; + } elsif ($env{'form.concepttest'} eq 'cloning') { + $concepttest = 'Copied from existing test'; } - $inst_values .= '<td>'.$concepttest.'</td>'; - } else { - $inst_headers .= '<th>'.&mt('Clone From').'</th>'; - if (($env{'form.clonecrs'} =~ /^$match_name$/) && + $inst_values .= '<td>'.$concepttest.(' 'x2).'</td>'; + } + if (&show_cloneable()) { + $inst_headers .= '<th>'.&mt('Copy From').'</th>'; + if ((($env{'form.cloning'}) || + (($dom eq 'gcitest') && ($env{'form.concepttest'} eq 'cloning'))) && + ($env{'form.clonecrs'} =~ /^$match_name$/) && ($env{'form.clonedom'} =~ /^$match_domain$/)) { my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'}, $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'}, @@ -2263,21 +2299,35 @@ sub print_review { my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'}, $env{'form.clonecrs'},('description','internal.coursecode')); if (keys(%courseenv) > 0) { - $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>'; + if ($dom eq 'gcitest') { + $inst_headers .= '<th>'.$ctxt{'ros'}.'</th>'; + } else { + $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>'; + } $inst_values .= '<td>'.$courseenv{'description'}.' '; my $cloneinst = $courseenv{'internal.coursecode'}; if ($cloneinst ne '') { $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'}; } else { - $inst_values .= &mt('from').' '.$env{'form.clonedom'}; + unless ($dom eq 'gcitest') { + $inst_values .= &mt('from').' '.$env{'form.clonedom'}; + } } - $inst_values .= '</td><td>'; - if ($env{'form.datemode'} eq 'preserve') { - $inst_values .= $ctxt{'prd'}; - } elsif ($env{'form.datemode'} eq 'shift') { - $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'}); + $inst_values .= (' 'x2).'</td><td>'; + if ($dom eq 'gcitest') { + if ($env{'form.cloneroster'}) { + $inst_values .= &mt('Yes'); + } else { + $inst_values .= &mt('No'); + } } else { - $inst_values .= $ctxt{'ncd'}; + if ($env{'form.datemode'} eq 'preserve') { + $inst_values .= $ctxt{'prd'}; + } elsif ($env{'form.datemode'} eq 'shift') { + $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'}); + } else { + $inst_values .= $ctxt{'ncd'}; + } } $inst_values .= '</td>'; } else { @@ -2437,6 +2487,24 @@ function validateForm() { } nextPage(document.$formname,'$next'); } + +function toggleCloning() { + var willclone; + if (document.$formname.cloning.length > 1) { + for (var i=0; i<document.$formname.cloning.length; i++) { + if (document.$formname.cloning[i].checked) { + willclone = document.$formname.cloning[i].value; + } + } + } + if (willclone == 1) { + document.getElementById('cloneoptions').style.display="block"; + } else { + document.getElementById('cloneoptions').style.display="none"; + document.$formname.clonecrs.value = ''; + } +} + // ]] </script> @@ -2447,20 +2515,26 @@ ENDJS $title = &mt('Concept Test Course Information'); $desctitle = &mt('Concept Test Title'); } - my $clonetitle = &mt('Clone content and settings from an existing course?'); + my $clonetitle = &mt('Copy content and settings from an existing course?'); if ($crstype eq 'community') { $title = &mt('Brief Community Description'); - $clonetitle = &mt('Clone content and settings from an existing community?'); + $clonetitle = &mt('Copy content and settings from an existing community?'); } - my $output .= $js_validate."\n".'<div>'.&Apache::lonhtmlcommon::start_pick_box(). + my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box(). &Apache::lonhtmlcommon::row_headline(). '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'</h3>'. &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::row_title($desctitle). '<input type="text" size="60" name="cdescr" value="'.$description.'" />'; + my $showclone; + if ($dom eq 'gcitest') { + $showclone = &show_cloneable(); + } else { + $showclone = 1; + } if ($dom eq 'gcitest') { $output .= &Apache::lonhtmlcommon::row_closure(1). - &concepttest_form(); + &concepttest_form($showclone); } my ($home_server_pick,$numlib) = &Apache::loncommon::home_server_form_item($dom,'chome', @@ -2471,31 +2545,82 @@ ENDJS } $output .= $home_server_pick. &Apache::lonhtmlcommon::row_closure(); + if ($showclone && $dom ne 'gcitest') { + $output .= &Apache::lonhtmlcommon::row_headline(). + '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle. + '<label><input type="radio" name="cloning" value="1" '. + 'onclick="javascript:toggleCloning()" />'. + &mt('Yes').(' 'x2).'</label><label>'. + '<input type="radio" name="cloning" value="0" checked="checked"'. + 'onclick="javascript:toggleCloning()" />'.&mt('No').'</label>'. + '</h3>'. + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_headline(). + '<div id="cloneoptions" style="display: none" >'. + &Apache::lonhtmlcommon::start_pick_box(). + &clone_form($dom,$formname,$crstype). + &Apache::lonhtmlcommon::end_pick_box().'</div>'; + } if ($dom eq 'gcitest') { my ($instcode,@codetitles,%cat_titles,%cat_order,@code_order); my $invalidcrosslist = []; $output .= &print_enrollment_menu($formname,$instcode,$dom, \@codetitles,\%cat_titles,\%cat_order, \@code_order,$invalidcrosslist); - } else { - $output .= - &Apache::lonhtmlcommon::row_headline(). - '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.'</h3>'. - &Apache::lonhtmlcommon::row_closure(1). - &clone_form($dom,$formname,$crstype); } - $output .= &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n"; + $output .= &Apache::lonhtmlcommon::end_pick_box()."\n"; return $output; } sub concepttest_form { - return &Apache::lonhtmlcommon::row_title(&mt('Questions included in Concept Test')). - '<input type="radio" name="concepttest" value="defchosen" /> '. - &mt('Automatically selected by WebCenter'). - '</label><br /><label>'. - '<input type="radio" name="concepttest" value="editmyown" checked="checked" /> '. - &mt('Chosen by you from Concept Inventory'). - '</label><br /><label>'; + my ($showclone) = @_; + my $output = &Apache::lonhtmlcommon::row_title(&mt('Questions included in Concept Test')). + '<label>'. + '<input type="radio" name="concepttest" value="editmyown" checked="checked" /> '. + &mt('Chosen by you from Concept Inventory'). + '</label><br />'. + '<label>'. + '<input type="radio" name="concepttest" value="defchosen" /> '. + &mt('Automatically selected by WebCenter'). + '</label>'; + if ($showclone) { + $output .= '<br /><span class="LC_nobreak"><label>'. + '<input type="radio" name="concepttest" value="cloning" /> '. + &mt('Copied from existing Test: '). + '</label>'.&select_oldtest().(' ' x2). + '<input type="hidden" name="clonedom" value="gcitest" />'. + '<label><input type="checkbox" value="1" name="cloneroster" />'. + &mt('Copy roster').'</label>'; + } + return $output; +} + +sub select_oldtest { + my $output = '<select name="clonecrs"><option value="" selected="selected">'. + '</option>'; + my %courses = &Apache::loncommon::existing_gcitest_courses('cc'); + my %Sortby; + foreach my $course (sort(keys(%courses))) { + next unless (ref($courses{$course}) eq 'HASH'); + my $clean_title = $courses{$course}{'description'}; + $clean_title =~ s/\W+//g; + if ($clean_title eq '') { + $clean_title = $courses{$course}{'description'}; + } + push(@{$Sortby{$clean_title}},$course); + } + my @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby)); + foreach my $item (@sorted_courses) { + foreach my $course (@{$Sortby{$item}}) { + my ($cdom,$cnum) = split('_',$course); + if (($cdom eq 'gcitest') && (ref($courses{$course}) eq 'HASH')) { + my $cdesc = $courses{$course}{'description'}; + $output .= '<option value="'.$cnum.'">'.$cdesc.'</option>'; + } + } + } + $output .= '</select>'; + return $output; } sub clone_form { @@ -2531,8 +2656,9 @@ sub clone_text { 'dmn' => 'Domain', 'dsh' => 'Date Shift', 'ncd' => 'Do not clone date parameters', - 'prd' => 'Clone date parameters as-is', + 'prd' => 'Copy date parameters as-is', 'shd' => 'Shift date parameters by number of days', + 'ros' => 'Copy Roster', ); } @@ -2756,6 +2882,10 @@ sub print_request_outcome { push(@instsections,$sec); } $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i}; + $sections{$i}{'loncapa'} =~ s/\W//g; + if ($sections{$i}{'loncapa'} eq 'none') { + $sections{$i}{'loncapa'} = ''; + } } } } @@ -2855,11 +2985,16 @@ sub print_request_outcome { } my $clonecrs = ''; my $clonedom = ''; - if (($env{'form.clonecrs'} =~ /^($match_courseid)$/) && + if ((($env{'form.cloning'}) || + (($dom eq 'gcitest') && ($env{'form.concepttest'} eq 'cloning'))) && + ($env{'form.clonecrs'} =~ /^($match_courseid)$/) && ($env{'form.clonedom'} =~ /^($match_domain)$/)) { + if ($dom eq 'gcitest') { + $env{'form.clonedom'} = 'gcitest'; + } my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'}, $env{'form.clonedom'}); - if ($clonehome ne 'no_host') { + if ($clonehome ne 'no_host') { my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'}, $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'}, @@ -2901,8 +3036,17 @@ sub print_request_outcome { } else { $details->{'firstres'} = 'blank'; } - $details->{'clonedom'} = 'gci'; - $details->{'clonecrs'} = '8v226795a882b4bcagcil1'; + if ($env{'form.concepttest'} eq 'cloning') { + if (($clonecrs) && ($clonedom eq 'gcitest')) { + $details->{'cloneroster'} = $env{'form.cloneroster'}; + } else { + $details->{'clonedom'} = 'gci'; + $details->{'clonecrs'} = '8v226795a882b4bcagcil1'; + } + } else { + $details->{'clonedom'} = 'gci'; + $details->{'clonecrs'} = '8v226795a882b4bcagcil1'; + } $details->{'datemode'} = 'delete'; } my (@inststatuses,$storeresult,$creationresult); @@ -3003,7 +3147,43 @@ sub print_request_outcome { my %parmresult = &store_crsparms($dom,$cnum,$now,$accessstart,$accessend); &Apache::londocsgci::setdefaults(); - if ($env{'form.concepttest'} eq 'defchosen') { + my %crsenvhash = ( + suppress_tries => 'yes', + ); + my $putresult = &Apache::lonnet::put('environment',\%crsenvhash,$dom,$cnum); + if ($env{'form.concepttest'} eq 'cloning') { + &Apache::lonuserstate::readmap($dom.'/'.$cnum); + if (($clonecrs) && ($clonedom eq 'gcitest')) { + my $cloneid = $clonedom.'/'.$clonecrs; + my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1}); + my $oldcdesc = $clonedesc{'description'}; + $output .= '<br />'.&mt('A concept test has been copied from your existing test: [_1].','<b>'.$oldcdesc.'</b>').'</p>'; + if ($env{'form.cloneroster'}) { + $output .= '<br />'.&mt('You requested copying of the old student roster to the new course.'); + if ($logmsg =~ /\Q\0\E/) { + my @logging = split("\0",$logmsg); + if (@logging) { + $output .= '<p>'.$logging[-1].'</p>'; + } + } + $output .= '<ul>'. + '<li>'.&mt('Access starts:').' '. + &Apache::lonlocal::locallocaltime($accessstart).'</li>'. + '<li>'.&mt('Access ends:').' '.&Apache::lonlocal::locallocaltime($accessend).'</li>'. + '</ul><br />'. + '<a href="/adm/menu">'.&mt('Manage Test').'</a>'; + $r->print($output); + $output = ''; + } else { + &roster_upload_form($r,$output); + $output = ''; + } + } else { + $output .= '</p>'; + &roster_upload_form($r,$output); + $output = ''; + } + } elsif ($env{'form.concepttest'} eq 'defchosen') { $output .= '<br />'; my $error = &Apache::londocsgci::store($caller,$dom,$cnum); if ($error) { @@ -3014,17 +3194,11 @@ sub print_request_outcome { &Apache::lonuserstate::readmap($dom.'/'.$cnum); $output .= &mt('A concept test has also been generated.'); } - $output .= '</p>'. - '<p>'.&mt('If you have a text file available containing student e-mail addresses and initial passwords, you may upload it now.').'<br />'. - &mt('You may also enroll students at a later date by visiting the [_1]"Menu"[_2] page and choosing: [_1]"Manage Enrollment"[_2].','<i>','</i>').'</p>'. - '</form><form name="studentform" method="post" enctype="multipart/form-data" '. - ' action="/adm/createuser">'."\n"; - $r->print($output); - &Apache::lonuserutils::print_first_users_upload_form($r,'course'); - $r->print('</form>'); + $output .= '</p>'; + &roster_upload_form($r,$output); $output = ''; } else { - $output .= '</form><br />'.&mt('The next step is to chose which questions are to be included in the Concept Test.').'</p>'; + $output .= '</p></form><br />'.&mt('The next step is to chose which questions are to be included in the Concept Test.').'</p>'; $r->print($output); &Apache::londocsgci::editor($r,'requestcrs',$dom,$cnum); $output = ''; @@ -3318,7 +3492,7 @@ sub store_crsparms { type => 'date_end', }, problemstatus => { - value => 'no_feedback_ever', + value => 'no', type => 'string_problemstatus', }, maxtries => { @@ -3344,6 +3518,16 @@ sub store_crsparms { return %parmresult; } +sub roster_upload_form { + my ($r,$output) = @_; + $r->print('<p>'.&mt('If you have a text file available containing student e-mail addresses and initial passwords, you may upload it now.').'<br />'. + &mt('You may also enroll students at a later date by visiting the [_1]"Menu"[_2] page and choosing: [_1]"Manage Enrollment"[_2].','<i>','</i>').'</p>'. + '</form><form name="studentform" method="post" enctype="multipart/form-data" '. + ' action="/adm/createuser">'."\n"); + &Apache::lonuserutils::print_first_users_upload_form($r,'course'); + $r->print('</form>'); +} + sub notification_information { my ($disposition,$req_notifylist,$cnum,$now) = @_; my %emails = &Apache::loncommon::getemails(); @@ -3671,5 +3855,16 @@ sub generate_date_items { return; } +sub show_cloneable { + my $showclone; + if (&Apache::loncommon::needs_gci_custom()) { + my %courses = &Apache::loncommon::existing_gcitest_courses('cc'); + my $numcourses = scalar(keys(%courses)); + return $numcourses; + } else { + return 1; + } +} + 1;