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

raeburn raeburn@source.lon-capa.org
Tue, 03 Nov 2009 14:32:44 -0000


This is a MIME encoded message

--raeburn1257258764
Content-Type: text/plain

raeburn		Tue Nov  3 14:32:44 2009 EDT

  Modified files:              
    /loncom/interface	lonpickcourse.pm 
  Log:
  - Accommodate Communities
    - Course Type is fixed if course picker is called when selecting a course or community to clone (course creation or course request) as clone must be of same type as target.
    - Coordinator role in Community is "co".
    - javascript: setRoles() used to set role names for both DC assigning a course role to a user, and DC uploading a file of users and assigning a default role to them.
    - display of matches from search excludes institutional code column if search is for Communities.  
  
  
--raeburn1257258764
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20091103143244.txt"

Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.88 loncom/interface/lonpickcourse.pm:1.89
--- loncom/interface/lonpickcourse.pm:1.88	Sat Oct 31 14:27:48 2009
+++ loncom/interface/lonpickcourse.pm	Tue Nov  3 14:32:44 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a course
 #
-# $Id: lonpickcourse.pm,v 1.88 2009/10/31 14:27:48 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.89 2009/11/03 14:32:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -102,10 +102,7 @@
 
     if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) && 
         ($env{'form.pickedcourse'})) {
-        if ($env{'form.form'} eq 'cu') {
-            $loaditem{'onload'} .= 'setRoles();';
-        }
-        $loaditem{'onload'} .= 'setSections();';
+        $loaditem{'onload'} .= 'setRoles();setSections();';
     }
     my $js = &js_changer();
     $r->print(&Apache::loncommon::start_page($title,$js,
@@ -300,7 +297,11 @@
     $r->print('<form name="courselist" method="post" action="'.$action.'">');
     if ($env{'form.form'} eq 'modifycourse') {
         if ($numcourses > 0) {
-            my $cctitle = &Apache::lonnet::plaintext('cc',$type);
+            my $ccrole = 'cc';
+            if ($type eq 'Community') {
+                $ccrole = 'co';
+            }
+            my $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
             my $dctitle = &Apache::lonnet::plaintext('dc');
             my $ccrolechk = ' checked="checked" ';
             my $menuchk = ' ';
@@ -313,12 +314,21 @@
                .'<legend>'.&mt('Action').'</legend>'
                .'<div class="LC_nobreak"><label>'
                .'<input type="radio" name="phase" value="ccrole"'.$ccrolechk.'/>'
-               .'&nbsp;'.&mt('Enter the course with the role of [_1].',$cctitle)
-               .'</label></div>'
+               .'&nbsp;');
+            if ($type eq 'Community') {
+                $r->print(&mt('Enter the community with the role of [_1].',$cctitle));
+            } else {
+                $r->print(&mt('Enter the course with the role of [_1].',$cctitle));
+            }
+            $r->print('</label></div>'
                .'<div class="LC_nobreak"><label>'
-               .'<input type="radio" name="phase" value="menu"'.$menuchk.'/>&nbsp;'
-               .&mt('View or modify course settings which only a [_1] may modify.',$dctitle)
-               .'</label></div>'
+               .'<input type="radio" name="phase" value="menu"'.$menuchk.'/>&nbsp;');
+            if ($type eq 'Community') {
+                $r->print(&mt('View or modify community settings which only a [_1] may modify.',$dctitle));
+            } else {
+                $r->print(&mt('View or modify course settings which only a [_1] may modify.',$dctitle));
+            }
+            $r->print('</label></div>'
                .'</fieldset>'
                .'<br />'
             );
@@ -349,13 +359,17 @@
     if (%courses) {
         $r->print(&Apache::loncommon::start_data_table());
         $r->print(&Apache::loncommon::start_data_table_header_row());
+        my $titlehdr = &mt('Course Title');
+        if ($type eq 'Community') {
+            $titlehdr = &mt('Community Title');
+        }
         $r->print('<th>'.&mt('Select').'</th>'
-                 .'<th>'.&mt('Course Title').'</th>'
-                 .'<th>'.&mt('Domain').'</th>'
-                 .'<th>'.&mt('Course Code').'</th>'
-                 .'<th>'.&mt('Owner/Co-owner(s)').'</th>'
-                 .'<th>'.&mt('Type').'</th>'
-                 );
+                 .'<th>'.$titlehdr.'</th>'
+                 .'<th>'.&mt('Domain').'</th>');
+        unless ($type eq 'Community') {
+            $r->print('<th>'.&mt('Course Code').'</th>');
+        }
+        $r->print('<th>'.&mt('Owner/Co-owner(s)').'</th>');
         if ($showroles) {
             $r->print('<th>'.&mt("Role(s) for [_1]",
                 &Apache::loncommon::plainname($env{'form.personfilter'},
@@ -407,21 +421,16 @@
             $r->print(&Apache::lonnet::domain($cdom,'description')?
                       $cdom.' ('.&Apache::lonnet::domain($cdom,'description').')':$cdom);
             $r->print('</td>');
-            $r->print('<td>');
-            if ($instcode ne '') {
-                $r->print(&unescape($instcode));
-            } else {
-                $r->print('&nbsp;');
+            unless ($type eq 'Community') { 
+                $r->print('<td>');
+                if ($instcode ne '') {
+                    $r->print(&unescape($instcode));
+                } else {
+                    $r->print('&nbsp;');
+                }
+                $r->print('</td>');
             }
-            $r->print('</td>');
             $r->print('<td>'.$ownerstr.'</td>');
-            $r->print('<td>');
-            if ($ttype ne '') {
-                $r->print(&mt(&unescape($ttype)));
-            } else {
-                $r->print('&nbsp;');
-            }
-            $r->print('</td>');
             if ($showroles) {
                 $r->print('<td>');
                 my $rolestr;
@@ -432,7 +441,7 @@
                             my (undef,$crdom,$crname,$crtitle) = split('/',$role);
                             $rolestr .= $crtitle.', ';
                         } else {
-                            $rolestr .= &Apache::lonnet::plaintext($role,$ttype).', ';
+                            $rolestr .= &Apache::lonnet::plaintext($role,$type).', ';
                         }
                     }
                     $rolestr =~ s/\, $//;
@@ -595,11 +604,24 @@
               'cog' => &mt('Type')
              );
 
-    $typeselectform =  '<select name="type" size="1"';
-    if ($onchange) {
-        $typeselectform .= 'onchange="'.$onchange.'"';
+    if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
+        my $typeval = 'Course';
+        if ($type eq 'Community') {
+            $typeval = 'Community';
+        }
+        $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
+    } else {
+        $typeselectform =  '<select name="type" size="1"';
+        if ($onchange) {
+            $typeselectform .= 'onchange="'.$onchange.'"';
+        }
+        $typeselectform .= '>'."\n";
+        foreach my $posstype ('Course','Community') {
+            $typeselectform.='<option value="'.$posstype.'"'.
+                ($posstype eq $type ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
+        }
+        $typeselectform.="</select>";
     }
-    $typeselectform .= '>'."\n";
     
     my ($cloneableonlyform,$cloneabletitle);
     if (exists($filter->{'cloneableonly'})) {
@@ -643,11 +665,6 @@
         }
     }
 
-    foreach my $posstype ('Course','Community') {
-        $typeselectform.='<option value="'.$posstype.'"'.
-            ($posstype eq $type ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
-    }
-    $typeselectform.="</select>";
     my $output = qq|
 <form method="post" name="filterpicker" action="$action">
 <input type="hidden" name="form" value="$formname" />
@@ -688,9 +705,13 @@
                   .&Apache::lonhtmlcommon::row_closure();
     } 
     if ($typeselectform) {
-        $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
-                  .$typeselectform
-                  .&Apache::lonhtmlcommon::row_closure();
+        if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
+            $output .= $typeselectform;
+        } else {
+            $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
+                      .$typeselectform
+                      .&Apache::lonhtmlcommon::row_closure();
+        }
     }
     if ($instcodeform) {
         $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
@@ -738,11 +759,17 @@
             $warning = '<div class="LC_error">'.&mt('Intended course owner does not exist').
                        '</div>';
         } else {
+            my $ccrole;
+            if ($type eq 'Community') {
+                $ccrole = 'co';
+            } elsif ($type eq 'Course') {
+                $ccrole = 'cc';
+            }
             if ($env{'form.form'} eq 'ccrs') {
                 $output .= '<input type="hidden" name="cloner" value="'.$env{'form.cloner'}.'" />'."\n";
             }
             my %ccroles = &Apache::lonnet::get_my_roles($cloneruname,$clonerudom,
-                                                        'userroles',['active'], ['cc']);
+                                                        'userroles',['active'], [$ccrole]);
             foreach my $key (sort(keys(%ccroles))) {
                 my ($cnum,$cdom,$role) = split(':',$key);
                 $cc_clone .= $cdom.':'.$cnum.'&';
@@ -788,7 +815,12 @@
 
 sub search_courses {
     my ($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom) = @_;
-    my (%courses,%showcourses,$cloner);
+    my (%courses,%showcourses,$cloner,$ccrole);
+    if ($type eq 'Community') {
+        $ccrole = 'co';
+    } else {
+        $ccrole = 'cc';
+    }
     if (!$onlyown) {
         $r->print(&mt('Searching ...').'<br />&nbsp;<br />');
         $r->rflush();
@@ -839,7 +871,7 @@
             my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
                                                          $filter->{'persondomfilter'},
                                                          'userroles',undef,
-                                                         ['cc','in','ad','ep','ta','cr'],
+                                                         [$ccrole,'in','ad','ep','ta','cr'],
                                                          $filter->{'domainfilter'});
             foreach my $role (keys(%rolehash)) {
                 my ($cnum,$cdom,$courserole) = split(':',$role);

--raeburn1257258764--