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

raeburn raeburn@source.lon-capa.org
Mon, 04 May 2009 13:24:12 -0000


This is a MIME encoded message

--raeburn1241443452
Content-Type: text/plain

raeburn		Mon May  4 13:24:12 2009 EDT

  Modified files:              
    /loncom/interface	lonpickcourse.pm 
  Log:
  - Owner username textbox and domain selectbox now in a single row.
  - When "Select Course" is called by Scantron Operator, "Course owner/co-owner" row is replaced with "Course personnel includes: " row.
    - Can be used to search for courses where specified username:domain has active no-student role.
  
  
--raeburn1241443452
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090504132412.txt"

Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.78 loncom/interface/lonpickcourse.pm:1.79
--- loncom/interface/lonpickcourse.pm:1.78	Fri May  1 01:38:20 2009
+++ loncom/interface/lonpickcourse.pm	Mon May  4 13:24:12 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a course
 #
-# $Id: lonpickcourse.pm,v 1.78 2009/05/01 01:38:20 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.79 2009/05/04 13:24:12 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -116,17 +116,30 @@
     if ($env{'form.gosearch'} || $onlyown) {
         $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
     }
-    $r->print('<script type="text/javascript">'.$jscript.'</script>');
+    $r->print('<script type="text/javascript" language="Javascript">'.$jscript.
+              '</script>');
     $r->print($submitopener);
 
 # ------------------------------------------ Display of filters to limit search
     my $filter = {};
     my $action = '/adm/pickcourse';
-    my $numtitles;
+    my ($numtitles,$showroles,$nohost);
     if (!$onlyown) {
         my $filterlist = ['domainfilter','descriptfilter',
-                          'instcodefilter','ownerfilter',
-                          'ownerdomfilter'];
+                          'instcodefilter'];
+        if ($env{'form.form'} eq 'rules') {
+            push(@{$filterlist},'personfilter');
+            if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {
+                if (&Apache::lonnet::homeserver($env{'form.personfilter'},
+                                                 $env{'form.persondomfilter'}) eq 'no_host') {
+                    $nohost = 1;
+                } else {
+                    $showroles = 1;
+                } 
+            }
+        } else {
+            push(@{$filterlist},'ownerfilter');
+        }
         # course ID filter for DCs only
         if ($env{'user.adv'} && $env{'form.domainfilter'} &&
             exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
@@ -139,7 +152,14 @@
 # ---------------------------------------------------------------- Get the data
     if ($env{'form.gosearch'} || $onlyown) {
         my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles);
-        &display_matched_courses($r,$type,$multiple,$action,%courses);
+        if ($nohost) {
+            $r->print ('<span class="LC_warning">'.
+                       &mt('User does not exist - username: [_1], domain: [_2].',
+                           '<b>'.$filter->{'personfilter'}.'</b>',
+                           '<b>'.$filter->{'persondomfilter'}.'</b>').'</span>');
+        } else {
+            &display_matched_courses($r,$type,$multiple,$action,$showroles,%courses);
+        }
     }
     $r->print(&Apache::loncommon::end_page());
     return OK;
@@ -217,7 +237,7 @@
 }
 
 sub display_matched_courses {
-    my ($r,$type,$multiple,$action,%courses) = @_;
+    my ($r,$type,$multiple,$action,$showroles,%courses) = @_;
     if ($env{'form.form'} eq 'portform') {
         $action = '/adm/portfolio';
     }
@@ -281,6 +301,11 @@
                  .'<th>'.&mt('Owner/Co-owner(s)').'</th>'
                  .'<th>'.&mt('Type').'</th>'
                  );
+        if ($showroles) {
+            $r->print('<th>'.&mt("Role(s) for [_1]",
+                &Apache::loncommon::plainname($env{'form.personfilter'},
+                                              $env{'form.persondomfilter'},'firstname')).'</th>');
+        }
         $r->print(&Apache::loncommon::end_data_table_header_row());
     }
     foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
@@ -327,6 +352,23 @@
                 $r->print('&nbsp;');
             }
             $r->print('</td>');
+            if ($showroles) {
+                $r->print('<td>');
+                my $rolestr;
+                if (ref($courses{$course}{'roles'}) eq 'ARRAY') {
+                    my @roles = sort(@{$courses{$course}{'roles'}});
+                    foreach my $role (@roles) {
+                        if ($role =~ /^cr/) {
+                            my (undef,$crdom,$crname,$crtitle) = split('/',$role);
+                            $rolestr .= $crtitle.', ';
+                        } else {
+                            $rolestr .= &Apache::lonnet::plaintext($role,$ttype).', ';
+                        }
+                    }
+                    $rolestr =~ s/\, $//;
+                }
+                $r->print($rolestr.'</td>');
+            }
             if ($multiple) { $r->print("</label>\n"); }
             $r->print(&Apache::loncommon::end_data_table_row());
             # $r->print("<br />\n");
@@ -388,17 +430,35 @@
     if (defined($env{'form.form'})) {
          $formname = $env{'form.form'};
     }
-    my ($domainselectform,$sincefilterform,$ownerdomselectform,
+    my ($domainselectform,$sincefilterform,$ownerdomselectform,$persondomselectform,
         $instcodeform,$typeselectform,$instcodetitle);
     foreach my $item (@{$filterlist}) {
         $filter->{$item} = $env{'form.'.$item};
         if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
-	    if ($item eq 'domainfilter' || $item eq 'ownerdomfilter') {
+	    if ($item eq 'domainfilter') {
 		$filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
 	    } elsif ($item eq 'coursefilter') {
 		$filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
 	    } elsif ($item eq 'ownerfilter') {
 		$filter->{$item} = &LONCAPA::clean_username($filter->{$item});
+                $filter->{'ownerdomfilter'} = 
+                    &LONCAPA::clean_domain($env{'form.ownerdomfilter'});
+                $ownerdomselectform =
+                    &Apache::loncommon::select_dom_form($filter->{'ownerdomfilter'},
+                                                        'ownerdomfilter',1);
+            } elsif ($item eq 'personfilter') {
+                $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
+                if ($env{'form.persondomfilter'} eq '') {
+                    unless ($env{'form.gosearch'}) {
+                        $filter->{'persondomfilter'} = $env{'request.role.domain'};
+                    }
+                } else {
+                    $filter->{'persondomfilter'} =
+                        &LONCAPA::clean_domain($env{'form.persondomfilter'});
+                }
+                $persondomselectform =
+                    &Apache::loncommon::select_dom_form($filter->{'persondomfilter'},
+                                                        'persondomfilter',1);
 	    } else {
 		$filter->{$item} =~ s/\W//g;
 	    }
@@ -421,16 +481,13 @@
                                     &Apache::lonnet::domain($env{'request.role.domain'},
                                                             'description');
                 $codedom = $env{'request.role.domain'};
-            } else {    
+            } else {
                 $domainselectform =
 		    &Apache::loncommon::select_dom_form($filter->{$item},
 		    				        'domainfilter',
 						        $allow_blank);
                 $codedom = $filter->{'domainfilter'};
             }
-        } elsif ($item eq 'ownerdomfilter') {
-            $ownerdomselectform =
-     &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1);
         } else {
             $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
         }
@@ -458,8 +515,8 @@
               'cdo' => &mt("$type Domain"),
               'ins' => &mt('Institutional Code'),
               'inc' => &mt('Institutional Categorization'),
-              'cow' => &mt("$type Owner's Username"),
-              'cod' => &mt("$type Owner's Domain"),
+              'cow' => &mt("$type Owner/Co-owner"),
+              'cop' => &mt("$type Personnel Includes"),
               'cog' => &mt('Course Type')
              );
 
@@ -540,13 +597,20 @@
                   .&Apache::lonhtmlcommon::row_closure();
     }
     if (exists($filter->{'ownerfilter'})) {
-        $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'})
-                  .'<input type="text" name="ownerfilter" size="20" value="'
-                  .$list->{'ownerfilter'}.'" />'
-                  .&Apache::lonhtmlcommon::row_closure()
-                  .&Apache::lonhtmlcommon::row_title($lt{'cod'})
-                  .$ownerdomselectform
-                  .&Apache::lonhtmlcommon::row_closure();
+        $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
+                   '<table><tr><td>'.&mt('Username').'<br />'.
+                   '<input type="text" name="ownerfilter" size="20" value="'.
+                   $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
+                   $ownerdomselectform.'</td></tr></table>'.
+                   &Apache::lonhtmlcommon::row_closure();
+    }
+    if (exists($filter->{'personfilter'})) {
+        $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
+                   '<table><tr><td>'.&mt('Username').'<br />'.
+                   '<input type="text" name="personfilter" size="20" value="'.
+                   $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
+                   $persondomselectform.'</td></tr></table>'.
+                   &Apache::lonhtmlcommon::row_closure();
     }
     if (exists($filter->{'coursefilter'})) {
         $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
@@ -584,7 +648,7 @@
 
 sub search_courses {
     my ($r,$type,$onlyown,$filter,$numtitles) = @_;
-    my %courses;
+    my (%courses,%showcourses);
     if (!$onlyown) {
         $r->print(&mt('Searching ...').'<br />&nbsp;<br />');
         $r->rflush();
@@ -619,6 +683,30 @@
                                           $filter->{'combownerfilter'},
                                           $filter->{'coursefilter'},
                                           undef,undef,$type,$regexpok);
+        if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
+            my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
+                                                         $filter->{'persondomfilter'},
+                                                         'userroles',undef,
+                                                         ['cc','in','ad','ep','ta','cr'],
+                                                         $filter->{'domainfilter'});
+            foreach my $role (keys(%rolehash)) {
+                my ($cnum,$cdom,$courserole) = split(':',$role);
+                my $cid = $cdom.'_'.$cnum;
+                if (exists($courses{$cid})) {
+                    if (ref($courses{$cid}) eq 'HASH') {
+                        if (ref($courses{$cid}{roles}) eq 'ARRAY') {
+                            if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) { 
+                                push (@{$courses{$cid}{roles}},$courserole);
+                            }
+                        } else {
+                            $courses{$cid}{roles} = [$courserole];
+                        }
+                        $showcourses{$cid} = $courses{$cid};
+                    }
+                }
+            }
+            %courses = %showcourses;
+        }
     } else {
         $r->print('<br />');
         my %coursehash = &Apache::loncommon::findallcourses(); 
@@ -830,9 +918,9 @@
 
 =item *
 X<display_matched_courses()>
-B<display_matched_courses($r,$type,$multiple,$action,%courses)>:
+B<display_matched_courses($r,$type,$multiple,$action,$showroles,%courses)>:
 
-Input: 5 - request object, course type, multiple (0 or 1), form action; hash of courses.
+Input: 7 - request object, course type, multiple (0 or 1), form action, whether to show roles (for course personnel filter), hash of courses.
 
 Output: 0
 

--raeburn1241443452--