[LON-CAPA-cvs] cvs: loncom(GCI_3) /interface lonrequestcourse.pm

raeburn raeburn@source.lon-capa.org
Fri, 26 Feb 2010 22:38:31 -0000


This is a MIME encoded message

--raeburn1267223911
Content-Type: text/plain

raeburn		Fri Feb 26 22:38:31 2010 EDT

  Modified files:              (Branch: GCI_3)
    /loncom/interface	lonrequestcourse.pm 
  Log:
  - Customization for GCI_3
    - Backport 1.45.
    - Users creating Concept Tests can choose to clone a concept test for
      which they are an active CC.
    - Users can also choose to copy the course roster from the cloned course.
    - Three new subroutines: 
       &show_cloneable() - returns 1 if user has CC role in existing tests.
       &select_oldtest() - select box containing courseIDs for existing tests.
       &roster_upload_form() - display of file upload of a CSV of students moved to its own subroutine to facilitate reuse.
  
  
--raeburn1267223911
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100226223831.txt"

Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.41.2.5 loncom/interface/lonrequestcourse.pm:1.41.2.6
--- loncom/interface/lonrequestcourse.pm:1.41.2.5	Thu Feb 25 05:01:25 2010
+++ loncom/interface/lonrequestcourse.pm	Fri Feb 26 22:38:31 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.41.2.5 2010/02/25 05:01:25 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.41.2.6 2010/02/26 22:38:31 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -285,6 +285,9 @@
             $jscript = &mainmenu_javascript();
         } else {
             $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
+            if ($state eq 'courseinfo') {
+                $jscript .= &cloning_javascript();
+            }
         }
     }
 
@@ -292,7 +295,7 @@
         $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 @@
 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 @@
             },
             courseinfo => {
                 cdescr           => 'text',
+                cloning          => 'radio',
                 clonecrs         => 'text',
                 clonedom         => 'selectbox',
                 datemode         => 'radio',
@@ -518,8 +538,13 @@
     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 @@
         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 @@
             '<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 @@
             $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.('&nbsp;'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 @@
                 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'}.'&nbsp;';
                     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 .= ('&nbsp;'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 @@
     }
     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 @@
         $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').'&nbsp;'.$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 @@
     }
     $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').'&nbsp;'.$clonetitle.
+                   '<label><input type="radio" name="cloning" value="1" '.
+                   'onclick="javascript:toggleCloning()" />'.
+                   &mt('Yes').('&nbsp;'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').'&nbsp;'.$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().('&nbsp;' 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 @@
                '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',
         );
 }
 
@@ -2855,11 +2981,16 @@
     }
     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 +3032,17 @@
         } 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);
@@ -3007,7 +3147,39 @@
                                        suppress_tries => 'yes',
                                      );
                     my $putresult =  &Apache::lonnet::put('environment',\%crsenvhash,$dom,$cnum);
-                    if ($env{'form.concepttest'} eq 'defchosen') {
+                    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) {
@@ -3018,17 +3190,11 @@
                             &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 = '';
@@ -3348,6 +3514,16 @@
     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();
@@ -3675,5 +3851,16 @@
     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;
 

--raeburn1267223911--