[LON-CAPA-cvs] cvs: loncom /interface coursecatalog.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sat, 08 Mar 2008 04:00:54 -0000


raeburn		Fri Mar  7 23:00:54 2008 EDT

  Modified files:              
    /loncom/interface	coursecatalog.pm 
  Log:
  Can specify course display limited to courses which permit self enrollment.
  - link provided if self-enrollment is active
  - dates self-enrollment available if start date is in the future   
  
  
Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.26 loncom/interface/coursecatalog.pm:1.27
--- loncom/interface/coursecatalog.pm:1.26	Thu Feb 14 21:30:14 2008
+++ loncom/interface/coursecatalog.pm	Fri Mar  7 23:00:53 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for displaying the course catalog interface
 #
-# $Id: coursecatalog.pm,v 1.26 2008/02/15 02:30:14 raeburn Exp $
+# $Id: coursecatalog.pm,v 1.27 2008/03/08 04:00:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -261,12 +261,18 @@
                       '</option>'."\n".'</select>'."\n".
                  '</td>'
                 );
+            my $show_selfenroll_status;
+            if ($env{'form.showselfenroll'}) {
+                $show_selfenroll_status = 'checked="checked" ';
+            }
             if (&user_is_dc($codedom)) {
                 my $showdetails_status;
                 if ($env{'form.showdetails'}) {
                     $showdetails_status = 'checked="checked" ';
-                } 
-                $r->print('<td></td><td><input type="checkbox" name="showdetails" value="1" '.$showdetails_status.'/>'.&mt('Show full details for each course (DC only)').'</td>');
+                }
+                $r->print('<td></td><td><label><input type="checkbox" name="showdetails" value="1" '.$showdetails_status.'/>'.&mt('Show full details for each course (DC only)').'</label><br /><label><input type="checkbox" name="showselfenroll" value="1" '.$show_selfenroll_status.'/>'.&mt('Only show courses which allow self-enrollment').'</label></td>');
+            } else {
+                $r->print('<td></td><td><br /><label><input type="checkbox" name="showselfenroll" value="1" '.$show_selfenroll_status.'/>'.&mt('Only show courses which allow self-enrollment').'</label></td>');
             }
             $r->print('</tr></table>');
             if ($numtitles > 4) {
@@ -414,7 +420,8 @@
         }
     }
     my %courses = &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',
-                                                undef,undef,'Course',1);
+                                                undef,undef,'Course',1,
+                                                $env{'form.showselfenroll'});
     return %courses;
 }
 
@@ -448,13 +455,16 @@
             $output = &mt('<b>Note for students:</b> If you are officially enrolled in a course but the course is not listed in your LON-CAPA courses, click the "Show more details" link for the specific course and check the default access dates and/or automated enrollment settings.<br /><br />');
         }
     }
-    $output .= &construct_data_table($knownuser,\%courses,$details);
+    my $now = time;
+    my %domconfig =
+        &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
+    $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig);
     $output .= &Apache::lonhtmlcommon::echo_form_input(['coursenum','state','catalogfilter','sortby','showdetails']);
     return $output;
 }
 
 sub construct_data_table {
-    my ($knownuser,$courses,$details,$usersections) = @_;
+    my ($knownuser,$courses,$details,$usersections,$now,$domconfig) = @_;
     my %sortname;
     if (($details eq '') || ($env{'form.showdetails'})) {
         $sortname{'Code'} = 'code';
@@ -485,9 +495,10 @@
               '<th>'.&mt('Student Counts').'</th>'.
               '<th>'.&mt('Auto-enrollment of <br />registered students').'</th>';
         } else {
-            $output .= '<th>&nbsp;</th>';
+            $output .= '<th>'.&mt('Details').'</th>';
         }
     }
+    $output .= '<th>'.&mt('Self-enroll (if permitted)').'</th>';
     &Apache::loncommon::end_data_table_header_row();
     my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$details,
                                             $usersections);
@@ -516,7 +527,8 @@
     foreach my $item (@sorted_courses) {
         foreach my $course (@{$Sortby{$item}}) {
             $output.=&Apache::loncommon::start_data_table_row(); 
-            $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details,\$count);
+            $output.=&courseinfo_row($courseinfo{$course},$knownuser,
+                                     $details,\$count,$now,$course);
             $output.=&Apache::loncommon::end_data_table_row();
         }
     }
@@ -537,12 +549,16 @@
         $cleandesc=~s/'/\\'/g;
         $cleandesc =~ s/^\s+//;
         my ($cdom,$cnum)=split(/\_/,$course);
-        my ($descr,$instcode,$singleowner,$ttype,@owners,%ownernames);
+        my ($descr,$instcode,$singleowner,$ttype,$selfenroll_types,
+            $selfenroll_start,$selfenroll_end,@owners,%ownernames);
         if (ref($courses->{$course}) eq 'HASH') {
             $descr = $courses->{$course}{'description'};
             $instcode =  $courses->{$course}{'inst_code'};
             $singleowner = $courses->{$course}{'owner'};
             $ttype =  $courses->{$course}{'type'};
+            $selfenroll_types = $courses->{$course}{'selfenroll_types'};
+            $selfenroll_start = $courses->{$course}{'selfenroll_start_date'};
+            $selfenroll_end = $courses->{$course}{'selfenroll_end_date'};
             push(@owners,$singleowner);
             if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') {
                 foreach my $item (@{$courses->{$course}{'co-owners'}}) {
@@ -577,6 +593,9 @@
         $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames));
         $courseinfo{$course}{'title'} = $cleandesc;
         $courseinfo{$course}{'owner'} = $singleowner;
+        $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types;
+        $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start;
+        $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end;
 
         my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
         my @classids;
@@ -660,7 +679,7 @@
 }
 
 sub courseinfo_row {
-    my ($info,$knownuser,$details,$countref) = @_;
+    my ($info,$knownuser,$details,$countref,$now,$course) = @_;
     my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
         $accessdates,$showsyllabus,$counts,$autoenrollment,$output);
     if (ref($info) eq 'HASH') {
@@ -703,6 +722,22 @@
             $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
         }
     }
+    my $selfenroll;
+    if ($info->{'selfenroll_types'}) {
+        my $showstart = &Apache::lonlocal::locallocaltime($info->{'selfenroll_start'});
+        my $showend = &Apache::lonlocal::locallocaltime($info->{'selfenroll_end'});
+        if (($info->{'selfenroll_end'} > 0) && ($info->{'selfenroll_end'} > $now)) {
+            if (($info->{'selfenroll_start'} > 0) && ($info->{'selfenroll_start'} > $now)) {
+                $output .= '<td>'.&mt('Starts: [_1]','<span class="LC_cusr_emph">'.$showstart.'</span>').'<br />'.&mt('Ends: [_1]','<span class="LC_cusr_emph">'.$showend.'</span>').'</td>';
+            } else { 
+                $output .= '<td><a href="/adm/selfenroll?cid='.$course.'">'.&mt('Enroll in course').'</a></td>';
+            }
+            $selfenroll = 1;
+        }
+    }
+    if (!$selfenroll) {
+        $output .= '<td>&nbsp;</td>';
+    }
     $$countref ++;
     return $output;
 }