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

raeburn raeburn@source.lon-capa.org
Wed, 20 Jan 2010 20:28:41 -0000


This is a MIME encoded message

--raeburn1264019321
Content-Type: text/plain

raeburn		Wed Jan 20 20:28:41 2010 EDT

  Modified files:              (Branch: version_2_9_X)
    /loncom/interface	lonuserutils.pm 
  Log:
  - Backport 1.103.
  
  
--raeburn1264019321
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100120202841.txt"

Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.97.2.5 loncom/interface/lonuserutils.pm:1.97.2.6
--- loncom/interface/lonuserutils.pm:1.97.2.5	Wed Jan 20 18:22:35 2010
+++ loncom/interface/lonuserutils.pm	Wed Jan 20 20:28:40 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.97.2.5 2010/01/20 18:22:35 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.97.2.6 2010/01/20 20:28:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -91,7 +91,7 @@
     if ($setting eq 'course' || $context eq 'course') {
         $scope = '/'.$cid;
         $scope =~ s/\_/\//g;
-        if ($role ne 'cc' && $sec ne '') {
+        if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
             $scope .='/'.$sec;
         }
     } elsif ($context eq 'domain') {
@@ -295,7 +295,7 @@
 }
 
 sub print_upload_manager_header {
-    my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission)=@_;
+    my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype)=@_;
     my $javascript;
     #
     if (! exists($env{'form.upfile_associate'})) {
@@ -332,7 +332,7 @@
     my $javascript_validations =
         &javascript_validations('upload',$krbdefdom,$password_choice,undef,
                                 $env{'request.role.domain'},$context,
-                                $groupslist);
+                                $groupslist,$crstype);
     my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
     $r->print('<p>'
              .&mt('Total number of records found in file: [_1]'
@@ -365,7 +365,7 @@
 ###############################################################
 sub javascript_validations {
     my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
-        $context,$groupslist)=@_;
+        $context,$groupslist,$crstype)=@_;
     my %param = (
                   kerb_def_dom => $krbdefdom,
                   curr_authtype => $curr_authtype,
@@ -386,10 +386,11 @@
         if (($context eq 'course') || ($context eq 'domain')) {
             if ($context eq 'course') {
                 if ($env{'request.course.sec'} eq '') {
-                    $setsection_call = 'setSections(document.'.$param{'formname'}.');';
+                    $setsection_call = 'setSections(document.'.$param{'formname'}."'$crstype'".');';
+
                     $setsections_js =
                         &setsections_javascript($param{'formname'},$groupslist,
-                                                $mode);
+                                                $mode,'',$crstype);
                 } else {
                     $setsection_call = "'ok'";
                 }
@@ -830,7 +831,7 @@
                .'&nbsp;'.&mt('Add a domain role').'</label>'
                .'&nbsp;&nbsp;&nbsp;<label>'
                .'<input type="radio" name="roleaction" value="course" />'
-               .'&nbsp;'.&mt('Add a course role').'</label>'
+               .'&nbsp;'.&mt('Add a course/community role').'</label>'
                .'</span>';
     } elsif ($context eq 'author') {
         $Str .= &Apache::lonhtmlcommon::row_title(
@@ -899,7 +900,7 @@
            .'<hr />';
     if ($context eq 'course') {
         $Str .= '<p class="LC_info">'
-               .&mt('Note: For large courses, this operation may be time consuming.')
+               .&mt('Note: This operation may be time consuming when adding several users.')
                .'</p>';
     }
     $Str .= '<p><input type="button"'
@@ -979,7 +980,7 @@
         &Apache::loncommon::get_kerberos_defaults($defdom);
     #
     &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
-                                 $permission);
+                                 $permission,$crstype);
     my $i;
     my $keyfields;
     if ($total>=0) {
@@ -1202,16 +1203,16 @@
            $options .= '  <option value="'.$role.'">'.$plrole.'</option>';
         }
         my $courseform = &Apache::loncommon::selectcourse_link
-            ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course');
+            ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
         $cb_jscript = 
-            &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform');
+            &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community');
         $coursepick = &Apache::loncommon::start_data_table().
                       &Apache::loncommon::start_data_table_header_row().
                       '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
                       '<th>'.$lt{'grs'}.'</th>'.
                       &Apache::loncommon::end_data_table_header_row().
                       &Apache::loncommon::start_data_table_row()."\n".
-                      '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
+                      '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
                       '<td><select name="courserole">'."\n".
                       &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
                       '</select></td><td>'.
@@ -1229,6 +1230,7 @@
                       $env{'request.role.domain'}.'" />'.
                       '<input type="hidden" name="dccourse" value="" />'.
                       '<input type="hidden" name="dcdomain" value="" />'.
+                      '<input type="hidden" name="crstype" value="" />'.
                       '</td></tr></table></td>'.
                       &Apache::loncommon::end_data_table_row().
                       &Apache::loncommon::end_data_table()."\n";
@@ -1711,7 +1713,7 @@
             $env{'form.'.$name{$item}} = 'all';
         }
         if ($item eq 'sec') {
-            if ($env{'form.showrole'} eq 'cc') {
+            if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
                 $env{'form.'.$name{$item}} = 'none';
             }
             my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
@@ -3097,7 +3099,7 @@
         } else {
             opener.document.$callingform.retainsec.value = formname.retainsec.value;
         }
-        setSections(formname);
+        setSections(formname,'$crstype');
         if (seccheck == 'ok') {
             opener.document.$callingform.newsecs.value = formname.sections.value;
         }
@@ -3157,7 +3159,7 @@
                  fors => 'For student roles changing the section, will result in a section switch as students may only be in one section of a course at a time.',
                  forn => 'For a role in a course that is not a student role, a user may have roles in more than one section of a course at a time.',
                  reta => "Retain each user's current section affiliations?", 
-                 dnap => '(Does not apply to student roles).', 
+                 dnap => '(Does not apply to student roles).',
             );
     my ($date_items,$headertext);
     if ($env{'form.bulkaction'} eq 'chgsec') {
@@ -3178,6 +3180,12 @@
                 $date_items;
     if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
         my ($cnum,$cdom) = &get_course_identity();
+        my $crstype = &Apache::loncommon::course_type();
+        if ($crstype eq 'Community') {
+            $lt{'fors'} = &mt('For member roles changing the section, will result in a section switch as members may only be in one section of a community at a time.');
+            $lt{'forn'} = &mt('For a role in a community that is not a member role, a user may have roles in more than one section of a community at a time.');
+            $lt{'dnap'} = &mt('(Does not apply to member roles).'); 
+        }
         my $info;
         if ($env{'form.showrole'} eq 'st') {
             $output .= '<p>'.$lt{'fors'}.'</p>'; 
@@ -3294,7 +3302,7 @@
         if ($viewablesec ne '') {
             if ($env{'form.showrole'} eq 'st') {
                 $constraint = &mt('only users in section "[_1]"',$viewablesec);
-            } elsif ($env{'form.showrole'} ne 'cc') {
+            } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
                 $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
             }
             if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
@@ -3651,9 +3659,6 @@
 
     $str .= &Apache::lonhtmlcommon::start_pick_box()
            .&Apache::lonhtmlcommon::row_title(&mt('File'))
-           .'<p class="LC_info">'."\n"
-           .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
-           .'</p>'."\n"
            .&Apache::loncommon::upfile_select_html()
            .&Apache::lonhtmlcommon::row_closure()
            .&Apache::lonhtmlcommon::row_title(
@@ -4142,7 +4147,7 @@
                                         $role = 'cr_'.$env{'user.domain'}.'_'.
                                                 $env{'user.name'}.'_'.$role;
                                     }
-                                    if ($role ne 'cc') { 
+                                    if (($role ne 'cc') && ($role ne 'co')) {
                                         if (@secs > 1) {
                                             $multiple = 1;
                                             foreach my $sec (@secs) {
@@ -4503,7 +4508,7 @@
                 }
             } elsif ($choice eq 'chgsec') {
                 my (@newsecs,$revresult,$nochg,@retained);
-                if ($role ne 'cc') {
+                if (($role ne 'cc') && ($role ne 'co')) {
                     @newsecs = split(/,/,$env{'form.newsecs'});
                 }
                 # remove existing section if not to be retained.   
@@ -4758,7 +4763,7 @@
 }
 
 sub setsections_javascript {
-    my ($formname,$groupslist,$mode,$checkauth) = @_;
+    my ($formname,$groupslist,$mode,$checkauth,$crstype) = @_;
     my ($checkincluded,$finish,$rolecode,$setsection_js);
     if ($mode eq 'upload') {
         $checkincluded = 'formname.name == "'.$formname.'"';
@@ -4797,8 +4802,11 @@
     }
     my %alerts = &Apache::lonlocal::texthash(
                     secd => 'Section designations do not apply to Course Coordinator roles.',
+                    sedn => 'Section designations do not apply to Coordinator roles.',
                     accr => 'A course coordinator role will be added with access to all sections.',
+                    acor => 'A coordinator role will be added with access to all sections',
                     inea => 'In each course, each user may only have one student role at a time.',
+                    inec => 'In each community, each user may only have one member role at a time.',
                     youh => 'You had selected ',
                     secs => 'sections.',
                     plmo => 'Please modify your selections so they include no more than one section.',
@@ -4809,7 +4817,7 @@
                  );                
     $setsection_js .= <<"ENDSECCODE";
 
-function setSections(formname) {
+function setSections(formname,crstype) {
     var re1 = /^currsec_/;
     var groups = new Array($groupslist);
     for (var i=0;i<formname.elements.length;i++) {
@@ -4818,10 +4826,13 @@
         if (checkcurr != null) {
             if ($checkincluded) {
                 $rolecode
-                if (role == 'cc') {
-                    alert("$alerts{'secd'}\\n$alerts{'accr'}");
-                }
-                else {
+                if (role == 'cc' || role == 'co') {
+                    if (role == 'cc') {
+                        alert("$alerts{'secd'}\\n$alerts{'accr'}");
+                    } else {
+                        alert("$alerts{'sedn'}\\n$alerts{'acor'}");
+                    }
+                } else {
                     var sections = '';
                     var numsec = 0;
                     var sections;
@@ -4857,7 +4868,11 @@
                     }
 
                     if ((role == 'st') && (numsec > 1)) {
-                        alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
+                        if (crstype == 'Community') {
+                            alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
+                        } else {
+                            alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
+                        }
                         return;
                     }
                     else {
@@ -5131,6 +5146,7 @@
     my ($formname,$mode,$context) = @_;
     my ($dc_setcourse_code,$authen_check);
     my $cctext = &Apache::lonnet::plaintext('cc');
+    my $cotext = &Apache::lonnet::plaintext('co');
     my %alerts = &sectioncheck_alerts();
     my $role = 'role';
     if ($mode eq 'upload') {
@@ -5177,7 +5193,11 @@
             numsections = numsections + newsecs.length;
         }
         if ((userrole == 'st') && (numsections > 1)) {
-            alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+            if (document.$formname.crstype.value == 'Community') {
+                alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+            } else {
+                alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+            }
             return;
         }
         for (var j=0; j<newsecs.length; j++) {
@@ -5189,7 +5209,11 @@
                 var groups = document.$formname.groups.value.split(/,/g);
                 for (var k=0; k<groups.length; k++) {
                     if (newsecs[j] == groups[k]) {
-                        alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
+                        if (document.$formname.crstype.value == 'Community') {
+                            alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
+                        } else {
+                            alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
+                        }
                         return;
                     }
                 }
@@ -5199,13 +5223,21 @@
             alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
             section = "";
         }
+        if ((userrole == 'co') && (numsections > 0)) {
+            alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
+            section = "";
+        }
 SCRIPTTOP
     if ($mode ne 'upload') {
         $dc_setcourse_code .= (<<"ENDSCRIPT");
         var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
         var numcourse = getIndex(document.$formname.dccourse);
         if (numcourse == "-1") {
-            alert("$alerts{'thwa'}");
+            if (document.$formname.type == 'Community') {
+                alert("$alerts{'thwc'}");
+            } else {
+                alert("$alerts{'thwa'}");
+            }
             return;
         }
         else {
@@ -5314,19 +5346,22 @@
 
 sub sectioncheck_alerts {
     my %alerts = &Apache::lonlocal::texthash(
-                    curd => 'You must select a course in the current domain',
+                    curd => 'You must select a course or community in the current domain',
                     inea => 'In each course, each user may only have one student role at a time',
+                    inco => 'In each community, each user may only have one member role at a time',
                     youh => 'You had selected',
                     sect => 'sections',
                     plsm => 'Please modify your selections so they include no more than one section',
                     mayn => 'may not be used as the name for a section, as it is a reserved word',
                     plsc => 'Please choose a different section name',
                     mayt => 'may not be used as the name for a section, as it is the name of a course group',
+                    mayc => 'may not be used as the name for a section, as it is the name of a community group',
                     secn => 'Section names and group names must be distinct',
                     secd => 'Section designations do not apply to ',
                     role => 'roles',
                     accr => 'role will be added with access to all sections',
-                    thwa => 'There was a problem with your course selection'
+                    thwa => 'There was a problem with your course selection',
+                    thwc => 'There was a problem with your community selection',
                  );
     return %alerts;
 }

--raeburn1264019321--