[LON-CAPA-cvs] cvs: loncom(version_2_9_X) /interface loncommon.pm

raeburn raeburn@source.lon-capa.org
Tue, 19 Jan 2010 16:10:11 -0000


This is a MIME encoded message

--raeburn1263917411
Content-Type: text/plain

raeburn		Tue Jan 19 16:10:11 2010 EDT

  Modified files:              (Branch: version_2_9_X)
    /loncom/interface	loncommon.pm 
  Log:
  - Backport 1.906, 1.907, 1.908, 1.909. 1.931, 1.932.
  
  
--raeburn1263917411
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100119161011.txt"

Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.692.4.21 loncom/interface/loncommon.pm:1.692.4.22
--- loncom/interface/loncommon.pm:1.692.4.21	Tue Jan 19 06:01:09 2010
+++ loncom/interface/loncommon.pm	Tue Jan 19 16:10:11 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.692.4.21 2010/01/19 06:01:09 raeburn Exp $
+# $Id: loncommon.pm,v 1.692.4.22 2010/01/19 16:10:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -481,8 +481,11 @@
 }
 
 sub coursebrowser_javascript {
-    my ($domainfilter,$sec_element,$formname,$role_element)=@_;
-    my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Community - for which you wish to add/modify a user role.');
+    my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
+    my $wintitle = 'Course_Browser';
+    if ($crstype eq 'Community') {
+        $wintitle = 'Community_Browser';
+    }
     my $id_functions = &javascript_index_functions();
     my $output = '
 <script type="text/javascript" language="JavaScript">
@@ -490,7 +493,7 @@
     var stdeditbrowser;'."\n";
 
     $output .= <<"ENDSTDBRW";
-    function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
+    function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
         var url = '/adm/pickcourse?';
         var formid = getFormIdByName(formname);
         var domainfilter = getDomainFromSelectbox(formname,udom);
@@ -515,6 +518,12 @@
                 }
             }     
         }
+        if (type != null && type != '') {
+            url += '&type='+type;
+        }
+        if (type_elem != null && type_elem != '') {
+            url += '&typeelement='+type_elem;
+        }
         if (formname == 'ccrs') {
             var ownername = document.forms[formid].ccuname.value;
             var ownerdom =  document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
@@ -523,19 +532,7 @@
         if (multflag !=null && multflag != '') {
             url += '&multiple='+multflag;
         }
-        if (crstype == 'Course/Community') {
-            if (formname == 'cu') {
-                crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
-                if (crstype == "") {
-                    alert("$crs_or_grp_alert");
-                    return;
-                }
-            }
-        }
-        if (crstype !=null && crstype != '') {
-            url += '&type='+crstype;
-        }
-        var title = 'Course_Browser';
+        var title = '$wintitle';
         var options = 'scrollbars=1,resizable=1,menubar=0';
         options += ',width=700,height=600';
         stdeditbrowser = open(url,title,options,'1');
@@ -756,16 +753,21 @@
 }
 
 sub selectcourse_link {
-   my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
+   my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
+       $typeelement) = @_;
+   my $type = $selecttype;
    my $linktext = &mt('Select Course');
    if ($selecttype eq 'Community') {
        $linktext = &mt('Select Community');
+   } elsif ($selecttype eq 'Course/Community') {
+       $linktext = &mt('Select Course/Community');
+       $type = '';
    }
    return '<span class="LC_nobreak">'
          ."<a href='"
          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
          .'","'.$udomele.'","'.$desc.'","'.$extra_element
-         .'","'.$multflag.'","'.$selecttype.'");'
+         .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
          ."'>".$linktext.'</a>'
          .'</span>';
 }
@@ -1164,7 +1166,7 @@
     my $helptopic='Student_Intro';
     if ($env{'request.role'}=~/^(ca|au)/) {
 	$helptopic='Authoring_Intro';
-    } elsif ($env{'request.role'}=~/^cc/) {
+    } elsif ($env{'request.role'}=~/^(cc|co)/) {
 	$helptopic='Course_Coordination_Intro';
     } elsif ($env{'request.role'}=~/^dc/) {
         $helptopic='Domain_Coordination_Intro';
@@ -3728,6 +3730,7 @@
         if (!%roles) {
             %roles = (
                        cc => 1,
+                       co => 1,
                        in => 1,
                        ep => 1,
                        ta => 1,
@@ -6363,7 +6366,7 @@
 ###############################################
 sub get_users_function {
     my $function = 'student';
-    if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
+    if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/
         $function='coordinator';
     }
     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
@@ -6433,7 +6436,7 @@
     my $active_chk = 'none';
     my $now = time;
     if (@uroles > 0) {
-        if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
+        if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
         } else {
             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
@@ -9382,34 +9385,55 @@
     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
     my $clonemsg;
     my $can_clone = 0;
-
+    my $lctype = lc($args->{'type'});
+    if ($lctype ne 'community') {
+        $lctype = 'course';
+    }
     if ($clonehome eq 'no_host') {
-        $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});     
+        if ($args->{'type'} eq 'Community') {
+            $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
+        } else {
+            $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
+        }
     } else {
 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
-        if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && 
+        if ($args->{'type'} eq 'Community') {
+            if ($clonedesc{'type'} ne 'Community') {
+                 $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
+                return ($can_clone, $clonemsg, $cloneid, $clonehome);
+            }
+        }
+        if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
             (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
- 	    $can_clone = 1;
-	} else {
-	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
-						 $args->{'clonedomain'},$args->{'clonecourse'});
-	    my @cloners = split(/,/,$clonehash{'cloners'});
+            $can_clone = 1;
+        } else {
+            my %clonehash = &Apache::lonnet::get('environment',['cloners'],
+                                                 $args->{'clonedomain'},$args->{'clonecourse'});
+            my @cloners = split(/,/,$clonehash{'cloners'});
             if (grep(/^\*$/,@cloners)) {
                 $can_clone = 1;
             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                 $can_clone = 1;
             } else {
-	        my %roleshash =
-		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
-					 $args->{'ccdomain'},
-                                         'userroles',['active'],['cc'],
-					 [$args->{'clonedomain'}]);
-	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
-		    $can_clone = 1;
-	        } else {
-                    $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
-	        }
-	    }
+                my $ccrole = 'cc';
+                if ($args->{'type'} eq 'Community') {
+                    $ccrole = 'co';
+                }
+                my %roleshash =
+                    &Apache::lonnet::get_my_roles($args->{'ccuname'},
+                                         $args->{'ccdomain'},
+                                         'userroles',['active'],[$ccrole],
+                                         [$args->{'clonedomain'}]);
+                if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
+                    $can_clone = 1;
+                } else {
+                    if ($args->{'type'} eq 'Community') {
+                        $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
+                    } else {
+                        $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
+                    }
+                }
+            }
         }
     }
     return ($can_clone, $clonemsg, $cloneid, $clonehome);

--raeburn1263917411--