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

raeburn raeburn at source.lon-capa.org
Wed Oct 19 09:14:06 EDT 2016


raeburn		Wed Oct 19 13:14:06 2016 EDT

  Modified files:              
    /loncom/auth	lonroles.pm 
    /loncom/interface	lonpickcourse.pm 
  Log:
  - Link(s) to course/community selector(s) for ad hoc custom roles included 
    with Domain Helpdesk role entry, for any custom helpdesk roles assigned
    to user.
  
  
-------------- next part --------------
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.316 loncom/auth/lonroles.pm:1.317
--- loncom/auth/lonroles.pm:1.316	Fri Oct 14 23:11:04 2016
+++ loncom/auth/lonroles.pm	Wed Oct 19 13:12:58 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.316 2016/10/14 23:11:04 raeburn Exp $
+# $Id: lonroles.pm,v 1.317 2016/10/19 13:12:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -255,7 +255,8 @@
 
     my $envkey;
     my %dcroles = ();
-    my $numdc = &check_fordc(\%dcroles,$update,$then);
+    my %dhroles = ();
+    my ($numdc,$numdh,$numadhoc) = &check_for_adhoc(\%dcroles,\%dhroles,$update,$then);
     my $loncaparev = $r->dir_config('lonVersion');
 
 # ================================================================== Roles Init
@@ -269,7 +270,7 @@
             $env{'form.'.$env{'form.newrole'}}=1;
 # Check if this is a Domain Helpdesk role trying to enter a course
             if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) {
-                if (&Apache::lonnet::allowed('rar',$1)) {
+                if ($dhroles{$1}) {
                     $custom_adhoc = 1;
                 }
             }
@@ -1044,7 +1045,7 @@
     }
 # ----------------------------------------------------------------------- Table
 
-    if ($numdc > 0) {
+    if (($numdc > 0) || (($numdh > 0) && ($numadhoc > 0))) {
         $r->print(&coursepick_jscript());
         $r->print(&Apache::loncommon::coursebrowser_javascript().
                   &Apache::loncommon::authorbrowser_javascript());
@@ -1077,9 +1078,12 @@
                                $roletext{'user.role.'.$role}->[1].
                                &Apache::loncommon::end_data_table_row();
                 }
-                if ($role =~ m{dc\./($match_domain)/} 
+                if ($role =~ m{^user\.role\.dc\./($match_domain)/} 
 		    && $dcroles{$1}) {
 		    $output .= &adhoc_roles_row($1,'recent');
+                } elsif ($role =~ m{^user\.role\.dh\./($match_domain)/}
+                         && ($env{'environment.adhocroles.'.$1} ne '')) {
+                    $output .= &adhoc_customroles_row($1,'recent');
                 }
 	    } elsif ($numdc > 0) {
                 unless ($role =~/^error\:/) {
@@ -1476,12 +1480,15 @@
                                            &Apache::loncommon::end_data_table_row();
                             }
                         }
-                        if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
+                        if ($sortrole->{$which} =~ m{^user\.role\.dc\./($match_domain)/}) {
                             if (ref($dcroles) eq 'HASH') {
                                 if ($dcroles->{$1}) {
                                     $output .= &adhoc_roles_row($1,'');
                                 }
                             }
+                        } elsif (($sortrole->{$which} =~ m{^user\.role\.dh\./($match_domain)/}) &&
+                                 ($env{'environment.adhocroles.'.$1} ne '')) {
+                            $output .= &adhoc_customroles_row($1,'');
                         }
                     }
                 }
@@ -1739,29 +1746,42 @@
     }
 }
 
-sub check_fordc {
-    my ($dcroles,$update,$then) = @_;
+sub check_for_adhoc {
+    my ($dcroles,$dhroles,$update,$then) = @_;
     my $numdc = 0;
+    my $numdh = 0;
+    my $numadhoc = 0;
+    my $num_custom_adhoc = 0; 
     if ($env{'user.adv'}) {
         foreach my $envkey (sort(keys(%env))) {
-            if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
-                my $dcdom = $1;
-                my $livedc = 1;
+            if ($envkey=~/^user\.role\.(dc|dh)\.\/($match_domain)\/$/) {
+                my $role = $1;
+                my $roledom = $2;
+                my $liverole = 1;
                 my ($tstart,$tend)=split(/\./,$env{$envkey});
                 my $limit = $update;
-                if ($env{'request.role'} eq 'dc./'.$dcdom.'/') {
+                if ((($role eq 'dc') && ($env{'request.role'} eq 'dc./'.$roledom.'/')) ||
+                    (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$roledom.'/'))) {
                     $limit = $then;
                 }
-                if ($tstart && $tstart>$limit) { $livedc = 0; }
-                if ($tend   && $tend  <$limit) { $livedc = 0; }
-                if ($livedc) {
-                    $$dcroles{$dcdom} = $envkey;
-                    $numdc++;
+                if ($tstart && $tstart>$limit) { $liverole = 0; }
+                if ($tend   && $tend  <$limit) { $liverole = 0; }
+                if ($liverole) {
+                    if ($role eq 'dc') {
+                        $dcroles->{$roledom} = $envkey;
+                        $numdc++;
+                    } else {
+                        $dhroles->{$roledom} = $envkey;
+                        if ($env{'environment.adhocroles.'.$roledom} ne '') {
+                            $numadhoc ++;
+                        }
+                        $numdh++;
+                    }
                 }
             }
         }
     }
-    return $numdc;
+    return ($numdc,$numdh,$numadhoc);
 }
 
 sub adhoc_course_role {
@@ -1853,15 +1873,16 @@
 }
 
 sub courselink {
-    my ($dcdom,$rowtype) = @_;
+    my ($roledom,$rowtype,$role) = @_;
     my $courseform=&Apache::loncommon::selectcourse_link
-                   ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
-                    'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
-                    $dcdom,$dcdom,undef,'Course/Community');
-    my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
-                      '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
-                      '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
-                      '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
+                   ('rolechoice','course'.$rowtype.'_'.$roledom.'_'.$role,
+                    'domain'.$rowtype.'_'.$roledom.'_'.$role,
+                    'coursedesc'.$rowtype.'_'.$roledom.'_'.$role,
+                    $roledom.':'.$role,undef,'Course/Community');
+    my $hiddenitems = '<input type="hidden" name="domain'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
+                      '<input type="hidden" name="origdom'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
+                      '<input type="hidden" name="course'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />'.
+                      '<input type="hidden" name="coursedesc'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />';
     return $courseform.$hiddenitems;
 }
 
@@ -1958,7 +1979,8 @@
                  .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
                      ,'<span class="LC_cusr_emph">','</span>',$dcdom)
                  .' ';
-    my $selectcclink = &courselink($dcdom,$rowtype);
+    my $role = 'cc';
+    my $selectcclink = &courselink($dcdom,$rowtype,$role);
     my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
     my $carole = &Apache::lonnet::plaintext('ca');
     my $selectcalink = &coauthorlink($dcdom,$rowtype);
@@ -1968,6 +1990,25 @@
     return $output;
 }
 
+sub adhoc_customroles_row {
+    my ($dhdom,$rowtype) = @_;
+    my $output = &Apache::loncommon::continue_data_table_row()
+                 .' <td colspan="5" class="LC_textsize_mobile">'
+                 .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3] --',
+                      '<span class="LC_cusr_emph">','</span>',$dhdom);
+    my @customroles = split(/,/,$env{'environment.adhocroles.'.$dhdom});
+    my $count = 0;
+    foreach my $role (@customroles) {
+        next if (($role eq '') || ($role =~ /\W/));
+        $output .= ' '.$role.': '.&courselink($dhdom,$rowtype,$role).' |';
+        $count ++;
+    }
+    if ($count) {
+        return $output;
+    }
+    return;
+}
+
 sub recent_filename {
     my $area=shift;
     return 'nohist_recent_'.&escape($area);
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.119 loncom/interface/lonpickcourse.pm:1.120
--- loncom/interface/lonpickcourse.pm:1.119	Wed Oct  5 13:59:46 2016
+++ loncom/interface/lonpickcourse.pm	Wed Oct 19 13:14:05 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a course
 #
-# $Id: lonpickcourse.pm,v 1.119 2016/10/05 13:59:46 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.120 2016/10/19 13:14:05 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -69,12 +69,12 @@
         $title = 'Selecting '.$type.'(s)';
     }
 
-    # if called when a DC is selecting a course 
-    my $roledom = $env{'form.roleelement'};
+    # if called when a DC or DH is selecting a course 
+    my ($roledom,$rolename) = split(/:/,$env{'form.roleelement'});
     if ($roledom) {
-        $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
+        $roleelement = '<input type="hidden" name="roleelement" value="'.$env{'form.roleelement'}.'" />';
         $submitopener = &processpick();
-        $autosubmit = 'process_pick("'.$roledom.'")';
+        $autosubmit = 'process_pick("'.$roledom.'","'.$rolename.'")';
     }
     if ($env{'form.typeelement'} ne '') {
         $typeelement = '<input type="hidden" name="typeelement" value="'.$env{'form.typeelement'}.'" />';
@@ -288,7 +288,7 @@
     }
     my $process_pick = <<"ENDONE";
 <script type="text/javascript">
-function process_pick(dom) {
+function process_pick(dom,rolename) {
     var pickedCourse=opener.document.$openerform.$env{'form.cnumelement'}.value;
     var pickedDomain=opener.document.$openerform.$env{'form.cdomelement'}.value;
     var okDomain = 0;
@@ -297,18 +297,30 @@
         $process_pick .= <<"ENDTWO";
     if (pickedDomain == dom) {
         if (pickedCourse != '') {
-            var ccrole = "cc";
-            var pickedType = "$env{'form.type'}";
-            if (pickedType == "Community") {
-                ccrole = "co";
-            }
-            var courseTarget = ccrole+"./"+pickedDomain+"/"+pickedCourse
-            opener.document.title='Role selected. Please stand by.';
-            opener.status='Role selected. Please stand by.';
-            opener.document.rolechoice.newrole.value=courseTarget
-            opener.document.rolechoice.submit();
+            var courseTarget; 
+            if (rolename == 'cc') {
+                var ccrole = "cc";
+                var pickedType = "$env{'form.type'}";
+                if (pickedType == "Community") {
+                    ccrole = "co";
+                }
+                courseTarget = ccrole+"./"+pickedDomain+"/"+pickedCourse;
+            } else {
+                if (!/\\W/.test(rolename)) {
+                    courseTarget = "cr/"+pickedDomain+"/"+pickedDomain+"-domainconfig/"+rolename+"./"+pickedDomain+"/"+pickedCourse;
+                }
+            }
+            if ((courseTarget != '') && (courseTarget != undefined)) { 
+                opener.document.title='Role selected. Please stand by.';
+                opener.status='Role selected. Please stand by.';
+                opener.document.rolechoice.newrole.value=courseTarget;
+                opener.document.rolechoice.submit();
+            } else {
+                alert("Invalid role selection");
+                return;
+            }
         }
-    } 
+    }
     else {
         alert("You may only use this screen to select courses in the current domain: "+dom+"\\nPlease return to the roles page window and click the 'Select Course' link for domain: "+pickedDomain+",\\n if you are a Domain Coordinator in that domain, and wish to become a Course Coordinator in a course in the domain");
     }


More information about the LON-CAPA-cvs mailing list