[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm loncoursequeueadmin.pm lonrequestcourse.pm

raeburn raeburn@source.lon-capa.org
Wed, 04 Nov 2009 17:42:17 -0000


This is a MIME encoded message

--raeburn1257356537
Content-Type: text/plain

raeburn		Wed Nov  4 17:42:17 2009 EDT

  Modified files:              
    /loncom/interface	lonrequestcourse.pm loncoursequeueadmin.pm 
                     	loncommon.pm 
  Log:
  - Additional optional arg for loncommon::select_dom_form()
    - can restrict available domains to those included in the array ref arg.
  - Only display domains for which user can request courses in the domain select box
  - Only included types of course a user can request in the Type select box
  - Accommodate Communities
    - text changed depending on whether requests are possible for courses only, communitiesonly or both.
    - &loncoursequeueadmin::check_can_clone() - check user roles for active "co" role for a Community.     
  
  
--raeburn1257356537
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20091104174217.txt"

Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.38 loncom/interface/lonrequestcourse.pm:1.39
--- loncom/interface/lonrequestcourse.pm:1.38	Sun Oct 25 14:48:55 2009
+++ loncom/interface/lonrequestcourse.pm	Wed Nov  4 17:42:17 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.38 2009/10/25 14:48:55 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.39 2009/11/04 17:42:17 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -272,13 +272,14 @@
 
     my $loaditems = &onload_action($action,$state);
 
-    my %can_request;
-    my $canreq = &Apache::lonnet::check_can_request($dom,\%can_request);
+    my (%can_request,%request_domains);
+    my $canreq = 
+        &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains);
     if ($action eq 'new') {
         if ($canreq) {
             if ($state eq 'crstype') {
                 &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
-                                 $crumb);
+                                 $crumb,\%request_domains);
             } else {
                 &request_administration($r,$action,$state,$page,\%states,$dom,
                                         $jscript,$loaditems,$crumb,$newinstcode,
@@ -293,7 +294,7 @@
         }
     } elsif ($action eq 'view') {
         if ($state eq 'crstype') {
-            &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb);
+            &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\%request_domains);
         } else {
             &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
                                     $loaditems,$crumb);
@@ -312,7 +313,7 @@
     } elsif ($action eq 'log') {
         &print_request_logs($jscript,$loaditems,$crumb);
     } else {
-        &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
+        &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
     }
     return OK;
 }
@@ -591,11 +592,11 @@
 }
 
 sub print_main_menu {
-    my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_;
+    my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$request_domains) = @_;
     my ($types,$typename) = &Apache::loncommon::course_types();
     my $onchange;
     unless ($env{'form.interface'} eq 'textual') {
-        $onchange = 1;
+        $onchange = 'this.form.submit()';
     }
 
     my $nextstate_setter = "\n";
@@ -635,11 +636,12 @@
     var unofficial = '';
     var community = '';    
 END
-
-    foreach my $item (keys(%{$can_request})) {
-            $js .= " 
+    if (ref($can_request) eq 'HASH') {
+        foreach my $item (keys(%{$can_request})) {
+                $js .= " 
         $item = 1;
 ";
+        }
     }
     my %lt = &Apache::lonlocal::texthash(
         official => 'You are not permitted to request creation of an official course in this domain.',
@@ -675,22 +677,59 @@
     }
     return true;
 }
-
 END
-
-    $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.
-             '<p>'.&mt('Request creation of a new course, or review your pending course requests.').'</p>'.
+    my ($pagetitle,$pageinfo,$domaintitle);
+    if (ref($can_request) eq 'HASH') {
+        if (($can_request->{'official'}) || ($can_request->{'unofficial'})) {
+            if ($can_request->{'community'}) {
+                $pagetitle = 'Course/Community Requests';
+                $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
+                $domaintitle = &mt('Course/Community Domain');
+            } else {
+                $pagetitle = 'Course Requests';
+                $pageinfo = &mt('Request creation of a new course, or review your pending course requests.');
+                $domaintitle = &mt('Course Domain');
+            }
+        } elsif ($can_request->{'community'}) {
+            $pagetitle = 'Course/Community Requests';
+            $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
+            $domaintitle = &mt('Community Domain');
+        } else {
+            $pagetitle = 'Course/Community Requests';
+            $pageinfo = &mt('You do not have rights to request creation of courses in this domain; please choose a different domain.');
+            $domaintitle = &mt('Course/Community Domain');
+        }
+    }
+    my @incdoms;
+    if (ref($request_domains) eq 'HASH') {
+        foreach my $item (keys(%{$request_domains})) {
+            if (ref($request_domains->{$item}) eq 'ARRAY') {
+                foreach my $possdom (@{$request_domains->{$item}}) {
+                    unless(grep(/^\Q$possdom\E$/,@incdoms)) {
+                        push(@incdoms,$possdom);
+                    } 
+                } 
+            }
+        }
+    }
+    $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb.
+             '<p>'.$pageinfo.'</p>'.
              '<div>'.
               &Apache::lonhtmlcommon::start_pick_box().
-              &Apache::lonhtmlcommon::row_title(&mt('Course Domain')).
+              &Apache::lonhtmlcommon::row_title($domaintitle).
               '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
-              &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange));
+              &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,\@incdoms));
     if (!$onchange) {
         $r->print('&nbsp;<input type="submit" name="godom" value="'.
                    &mt('Change').'" />');
     }
+    unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) {
+        $r->print(&Apache::lonhtmlcommon::row_closure(1)."\n".
+                  &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
+                  &Apache::loncommon::end_page());
+        return;
+    }
     $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
-
     my $formname = 'requestcrs';
     my $nexttext = &mt('Next');
     $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
@@ -701,18 +740,29 @@
  <option value="log">'.&mt('View request history').'</option>
 </select></form>'.
               &Apache::lonhtmlcommon::row_closure(1).
-              &Apache::lonhtmlcommon::row_title(&mt('Course Type')).'
+              &Apache::lonhtmlcommon::row_title(&mt('Type')).'
 <form name="mainmenu_coursetype" method="post" action="">
-<select size="1" name="crstype">
- <option value="any">'.&mt('All types').'</option>');
-    if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
-        foreach my $type (@{$types}) {
-            my $selected = '';
-            if ($type eq 'official') {
-                $selected = ' selected="selected"';
+<select size="1" name="crstype">');
+    if (ref($can_request) eq 'HASH') {
+        if (keys(%{$can_request}) > 1) {
+            $r->print(' <option value="any">'.&mt('All types').'</option>');
+        }
+        if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
+            foreach my $type (@{$types}) {
+                next unless($can_request->{$type});
+                my $selected = '';
+                if ($env{'form.crstype'} eq '') {
+                    if ($type eq 'official') {
+                        $selected = ' selected="selected"';
+                    }
+                } else {
+                    if ($type eq $env{'form.crstype'}) {
+                        $selected = ' selected="selected"';
+                    }
+                }
+                $r->print('<option value="'.$type.'"'.$selected.'>'.&mt($typename->{$type}).
+                          '</option>'."\n");
             }
-            $r->print('<option value="'.$type.'"'.$selected.'>'.&mt($typename->{$type}).
-                      '</option>'."\n");
         }
     }
     $r->print('</select></form>'."\n".
@@ -2035,7 +2085,8 @@
     if (($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'});
+                           $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
+                           $env{'form.crstype'});
         if ($canclone) {
             my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
                               $env{'form.clonecrs'},('description','internal.coursecode'));
@@ -2601,7 +2652,8 @@
         if ($clonehome ne 'no_host') {  
             my $canclone =  
                 &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
-                        $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
+                        $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
+                        $crstype);
             if ($canclone) {
                 $clonecrs = $env{'form.clonecrs'};
                 $clonedom = $env{'form.clonedom'};
Index: loncom/interface/loncoursequeueadmin.pm
diff -u loncom/interface/loncoursequeueadmin.pm:1.10 loncom/interface/loncoursequeueadmin.pm:1.11
--- loncom/interface/loncoursequeueadmin.pm:1.10	Mon Oct  5 01:54:44 2009
+++ loncom/interface/loncoursequeueadmin.pm	Wed Nov  4 17:42:17 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Utilities to administer domain course requests and course self-enroll requests 
 #
-# $Id: loncoursequeueadmin.pm,v 1.10 2009/10/05 01:54:44 raeburn Exp $
+# $Id: loncoursequeueadmin.pm,v 1.11 2009/11/04 17:42:17 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -954,11 +954,15 @@
 }
 
 sub can_clone_course {
-    my ($uname,$udom,$clonecrs,$clonedom) = @_;
+    my ($uname,$udom,$clonecrs,$clonedom,$crstype) = @_;
     my $canclone;
+    my $ccrole = 'cc';
+    if ($crstype eq 'Community') {
+        $ccrole = 'co';
+    }
     my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',['active'],
-                                                  ['cc'],[$clonedom]);
-    if (exists($roleshash{$clonecrs.':'.$clonedom.':cc'})) {
+                                                  [$ccrole],[$clonedom]);
+    if (exists($roleshash{$clonecrs.':'.$clonedom.':'.$ccrole})) {
         $canclone = 1;
     } else {
         my %courseenv = &Apache::lonnet::userenvironment($clonedom,$clonecrs,('cloners'));
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.909 loncom/interface/loncommon.pm:1.910
--- loncom/interface/loncommon.pm:1.909	Wed Nov  4 14:08:36 2009
+++ loncom/interface/loncommon.pm	Wed Nov  4 17:42:17 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.909 2009/11/04 14:08:36 raeburn Exp $
+# $Id: loncommon.pm,v 1.910 2009/11/04 17:42:17 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1942,7 +1942,7 @@
 
 =pod
 
-=item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange)
+=item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
 
 Returns a string containing a <select name='$name' size='1'> form to 
 allow a user to select the domain to preform an operation in.  
@@ -1953,17 +1953,24 @@
 
 If the $showdomdesc flag is set, the domain name is followed by the domain description.
 
-The optional $onchange argumnet specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.  
+The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
+
+The optional $incdoms is a reference to an array of domains which will be the only available options. 
 
 =cut
 
 #-------------------------------------------
 sub select_dom_form {
-    my ($defdom,$name,$includeempty,$showdomdesc,$onchange) = @_;
+    my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
     if ($onchange) {
         $onchange = ' onchange="'.$onchange.'"';
     }
-    my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
+    my @domains;
+    if (ref($incdoms) eq 'ARRAY') {
+        @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
+    } else {
+        @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
+    }
     if ($includeempty) { @domains=('',@domains); }
     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
     foreach my $dom (@domains) {

--raeburn1257356537--