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

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 17 Oct 2006 18:11:49 -0000


raeburn		Tue Oct 17 14:11:49 2006 EDT

  Modified files:              
    /loncom/interface	coursecatalog.pm 
  Log:
  Only display "Show more details" link and allow retrieval of access dates, student counts and auto-enrollment status if user has authenticated. For the future: &user_is_known() should also return true if user has SSO session, but no LON-CAPA session.
  
  
Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.7 loncom/interface/coursecatalog.pm:1.8
--- loncom/interface/coursecatalog.pm:1.7	Mon Oct 16 15:39:51 2006
+++ loncom/interface/coursecatalog.pm	Tue Oct 17 14:11:46 2006
@@ -42,6 +42,17 @@
     if ($r->header_only) {
         return OK;
     }
+    my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
+    my $lonid=$cookies{'lonID'};
+    my $lonidsdir=$r->dir_config('lonIDsDir');
+    my $handle;
+    if ($lonid) {
+        $handle=$lonid->value;
+        $handle=~s/\W//g;
+    }
+    if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
+        &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
+    }
     &Apache::lonacc::get_posted_cgi($r);
     &Apache::lonlocal::get_language_handle($r);
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sortby']);
@@ -50,7 +61,7 @@
     my $domdesc = $Apache::lonnet::domaindescription{$codedom};
 
     &Apache::lonhtmlcommon::clear_breadcrumbs();
-    if ($env{'form.coursenum'} ne '') {
+    if ($env{'form.coursenum'} ne '' && &user_is_known()) {
         &course_details($r,$codedom,$formname,$domdesc);
     } else {
         &course_selector($r,$codedom,$formname,$domdesc);
@@ -369,7 +380,9 @@
             $output = &mt('No courses match the criteria you selected.');
             return $output;
         }
-        $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 />');
+        if (&user_is_known()) {
+            $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 .= &Apache::loncommon::start_data_table().
                &Apache::loncommon::start_data_table_header_row();
@@ -389,13 +402,15 @@
         }
         $output .= '</th>';
     }
-    if ($env{'form.coursenum'} eq '') {
-        $output .= '<th>&nbsp;</th>';
-    } else {
-        $output .=
+    if (&user_is_known()) {
+        if ($env{'form.coursenum'} eq '') {
+            $output .= '<th>&nbsp;</th>';
+        } else {
+            $output .=
               '<th>'.&mt('Default Access Dates for Students').'</th>'.
               '<th>'.&mt('Student Counts').'</th>'.
               '<th>'.&mt('Auto-enrollment of <br />registered students').'</th>';
+        }
     }
     &Apache::loncommon::end_data_table_header_row();
     my %courseinfo = &build_courseinfo_hash(%courses);
@@ -573,13 +588,15 @@
     }
     $output .= '</font></td>'.
                '<td>'.$ownerlast.'</td>';
-    if ($env{'form.coursenum'} eq '') {
-        $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
-    } else {
-        $output .=
+    if (&user_is_known()) {
+        if ($env{'form.coursenum'} eq '') {
+            $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
+        } else { 
+            $output .=
                '<td>'.$accessdates.'</td>'. 
                '<td>'.$counts.'</td>'.
                '<td>'.$autoenrollment.'</td>';
+        }
     }
     return $output;
 }
@@ -821,4 +838,13 @@
     return $autoenrolldates;
 }
 
+sub user_is_known {
+    my $known = 0;
+    if ($env{'user.name'} ne '' && $env{'user.name'} ne 'public' 
+        && $env{'user.domain'} ne '' && $env{'user.domain'} ne 'public') {
+        $known = 1;
+    }
+    return $known;
+}
+
 1;