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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Mon, 19 May 2008 17:10:20 -0000


This is a MIME encoded message

--raeburn1211217020
Content-Type: text/plain

raeburn		Mon May 19 13:10:20 2008 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm 
  Log:
  - &show_user_lists() can take an extra argument - $formname (defaults to 'studentform').
  - 'pickauthor' is a valid mode for show_user_lists()
    - used to generate a display of authors in a domain for selection of an ad hoc role by a DC. 
  
  
--raeburn1211217020
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080519131020.txt"

Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.54 loncom/interface/lonuserutils.pm:1.55
--- loncom/interface/lonuserutils.pm:1.54	Mon May 12 13:52:08 2008
+++ loncom/interface/lonuserutils.pm	Mon May 19 13:10:19 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.54 2008/05/12 17:52:08 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.55 2008/05/19 17:10:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1863,7 +1863,10 @@
 }
 
 sub show_users_list {
-    my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist)=@_;
+    my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname)=@_;
+    if ($formname eq '') {
+        $formname = 'studentform';
+    }
     #
     # Variables for excel output
     my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
@@ -1878,6 +1881,9 @@
     } else {
         push(@sortable,'extent');
     }
+    if ($mode eq 'pickauthor') {
+        @sortable = ('username','fullname','email','status');
+    }
     if (!grep(/^\Q$sortby\E$/,@sortable)) {
         $sortby = 'username';
     }
@@ -1918,7 +1924,7 @@
 END
         }
     }
-    if ($mode ne 'autoenroll') {
+    if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
         my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
         my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
         my $singconfirm = &mt(' for a single user?');
@@ -1960,8 +1966,8 @@
         alert("$alert");
     } 
     else {
-        var message = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].text;
-        var choice = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].value;
+        var message = document.$formname.bulkaction[document.$formname.bulkaction.selectedIndex].text;
+        var choice = document.$formname.bulkaction[document.$formname.bulkaction.selectedIndex].value;
         if (numchecked == 1) { 
             message += singconf;
         } 
@@ -1970,14 +1976,14 @@
         }
         if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
             var datemsg = '';
-            if ((document.studentform.startdate_month.value == '') && 
-                (document.studentform.startdate_day.value  == '') &&
-                (document.studentform.startdate_year.value == '')) {
+            if ((document.$formname.startdate_month.value == '') && 
+                (document.$formname.startdate_day.value  == '') &&
+                (document.$formname.startdate_year.value == '')) {
                 datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
             }
-            if ((document.studentform.enddate_month.value == '') &&
-                (document.studentform.enddate_day.value  == '') &&
-                (document.studentform.enddate_year.value == '')) {
+            if ((document.$formname.enddate_month.value == '') &&
+                (document.$formname.enddate_day.value  == '') &&
+                (document.$formname.enddate_year.value == '')) {
                 datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
             }
             if (datemsg != '') {
@@ -1985,9 +1991,9 @@
             }
         }
         if (choice == 'chgsec') {
-            var rolefilter = document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value;
-            var retained =  document.studentform.retainsec.value;
-            var secshow = document.studentform.newsecs.value;
+            var rolefilter = document.$formname.showrole.options[document.$formname.showrole.selectedIndex].value;
+            var retained =  document.$formname.retainsec.value;
+            var secshow = document.$formname.newsecs.value;
             if (secshow == '') {
                 if (rolefilter == 'st' || retained == 0 || retained == "") {
                     message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n"; 
@@ -2003,36 +2009,36 @@
             }
         }
         if (confirm(message)) {
-            document.studentform.phase.value = 'bulkchange';
-            document.studentform.submit();
+            document.$formname.phase.value = 'bulkchange';
+            document.$formname.submit();
         }
     }
 }
 
 function username_display_launch(username,domain) {
     var target;
-    for (var i=0; i<document.studentform.usernamelink.length; i++) {
-        if (document.studentform.usernamelink[i].checked) {
-            target = document.studentform.usernamelink[i].value;
+    for (var i=0; i<document.$formname.usernamelink.length; i++) {
+        if (document.$formname.usernamelink[i].checked) {
+            target = document.$formname.usernamelink[i].value;
         }
     }
     if (target == 'modify') {
-        if (document.studentform.userwin.checked == true) {
+        if (document.$formname.userwin.checked == true) {
             var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&action=singleuser&srchin=dom&srchby=uname&srchtype=exact&popup=1';
             var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
             modifywin = window.open(url,'',options,1);
             modifywin.focus();
             return;
         } else {
-            document.studentform.srchterm.value=username;
-            document.studentform.srchdomain.value=domain;
-            document.studentform.phase.value='get_user_info';
-            document.studentform.action.value = 'singleuser';
-            document.studentform.submit();
+            document.$formname.srchterm.value=username;
+            document.$formname.srchdomain.value=domain;
+            document.$formname.phase.value='get_user_info';
+            document.$formname.action.value = 'singleuser';
+            document.$formname.submit();
         }
     }
     if (target == 'aboutme') {
-        if (document.studentform.userwin.checked == true) {
+        if (document.$formname.userwin.checked == true) {
             var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
             var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
             aboutmewin = window.open(url,'',options,1);
@@ -2083,28 +2089,33 @@
     } elsif ($context eq 'author') {
         $lt{'extent'} = &mt('Author'); 
     }
-    my @cols = ('username','domain','id','fullname');
-    if ($context eq 'course') {
-        push(@cols,'section');
-    }
-    if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) { 
-        push(@cols,('start','end'));
-    }
-    if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
-        push(@cols,'role');
-    }
-    if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
-                                $env{'form.roletype'} eq 'course')) {
-        push (@cols,'extent');
-    }
-    if (($statusmode eq 'Any') && 
-        (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
-        push(@cols,'status');
-    }
-    if ($context eq 'course') {
-        push(@cols,'groups');
+    my @cols;
+    if ($mode eq 'pickauthor') {
+        @cols = ('username','fullname','status','email');
+    } else {
+        @cols = ('username','domain','id','fullname');
+        if ($context eq 'course') {
+            push(@cols,'section');
+        }
+        if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) { 
+            push(@cols,('start','end'));
+        }
+        if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
+            push(@cols,'role');
+        }
+        if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
+                                    $env{'form.roletype'} eq 'course')) {
+            push (@cols,'extent');
+        }
+        if (($statusmode eq 'Any') && 
+            (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
+            push(@cols,'status');
+        }
+        if ($context eq 'course') {
+            push(@cols,'groups');
+        }
+        push(@cols,'email');
     }
-    push(@cols,'email');
 
     my $rolefilter = $env{'form.showrole'};
     if ($env{'form.showrole'} eq 'cr') {
@@ -2119,10 +2130,10 @@
         $r->print('<b>'.$results_description.'</b><br />');
     }
     my ($output,$actionselect,%canchange,%canchangesec);
-    if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') {
-        if ($mode ne 'autoenroll') {
+    if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
+        if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
             if ($permission->{'cusr'}) {
-                $actionselect = &select_actions($context,$setting,$statusmode);
+                $actionselect = &select_actions($context,$setting,$statusmode,$formname);
             }
             $r->print(<<END);
 <input type="hidden" name="srchby"  value="uname" />
@@ -2155,9 +2166,9 @@
             $output .= '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="userwin" value="1" $checkwin />'.$lt{'owin'}.'</span><br />';
             if ($actionselect) {
                 $output .= <<"END";
-$lt{'ac'}:&nbsp;$actionselect <input type="button" value="$lt{'go'}" onclick="javascript:opendatebrowser(this.form,'studentform','go')" /></p>
-<p><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.actionlist)" /> &nbsp;
-<input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.actionlist)" /><br /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action(document.studentform.actionlist)" />
+$lt{'ac'}:&nbsp;$actionselect <input type="button" value="$lt{'go'}" onclick="javascript:opendatebrowser(this.form,'$formname','go')" /></p>
+<p><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" /> &nbsp;
+<input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.$formname.actionlist)" /><br /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action(document.$formname.actionlist)" />
 END
                 my @allroles;
                 if ($env{'form.showrole'} eq 'Any') {
@@ -2205,16 +2216,20 @@
                   &Apache::loncommon::start_data_table_header_row();
         if ($mode eq 'autoenroll') {
             $output .= "
- <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>
+ <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
             ";
         } else {
-            $output .= "\n".'<th>'.&mt('Count').'</th>'."\n";
+            if ($mode eq 'pickauthor') {
+                $output .= "\n".'<th>&nbsp;</th>'."\n";
+            } else { 
+                $output .= "\n".'<th>'.&mt('Count').'</th>'."\n";
+            }
             if ($actionselect) {
                 $output .= '<th>'.&mt('Select').'</th>'."\n";
             }
         }
         foreach my $item (@cols) {
-            $output .= "<th><a href=\"javascript:document.studentform.sortby.value='$item';document.studentform.submit();\">$lt{$item}</a></th>\n";
+            $output .= "<th><a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\">$lt{$item}</a></th>\n";
         }
         my %role_types = &role_type_names();
         if ($context eq 'course' && $mode ne 'autoenroll') {
@@ -2229,8 +2244,8 @@
                     $clickerchg = 'off';
                 }
                 $output .= '    <th>'."\n".'     '.
-                    '<a href="javascript:document.studentform.displayclickers.value='.
-                      "'".$clickerchg."'".';document.studentform.submit();">'.
+                    '<a href="javascript:document.'.$formname.'.displayclickers.value='.
+                      "'".$clickerchg."'".';document.'.$formname.'.submit();">'.
                       $clicker_options{$clickerchg}.'</a>&nbsp;'.$lt{'clicker'}."\n".
                       '    </th>'."\n";
 
@@ -2245,8 +2260,8 @@
                         $photochg = 'off';
                     }
                     $output .= '    <th>'."\n".'     '.
-                '<a href="javascript:document.studentform.displayphotos.value='.
-                      "'".$photochg."'".';document.studentform.submit();">'.
+                '<a href="javascript:document.'.$formname.'.displayphotos.value='.
+                      "'".$photochg."'".';document.'.$formname.'.submit();">'.
                       $photo_options{$photochg}.'</a>&nbsp;'.$lt{'photo'}."\n".
                       '    </th>'."\n";
                 }
@@ -2445,7 +2460,7 @@
         } else {
             $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
         }
-        if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
+        if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
             $r->print(&Apache::loncommon::start_data_table_row());
             my $checkval;
             if ($mode eq 'autoenroll') {
@@ -2467,7 +2482,9 @@
                 }
                 $r->print("<td>$cellentry</td>\n");
             } else {
-                $r->print("<td>$rowcount</td>\n");
+                if ($mode ne 'pickauthor') {  
+                    $r->print("<td>$rowcount</td>\n");
+                }
                 if ($actionselect) {
                     my $showcheckbox;
                     if ($role =~ /^cr\//) {
@@ -2501,6 +2518,8 @@
                     } else {
                         $r->print('<td>&nbsp;</td>');
                     }
+                } elsif ($mode eq 'pickauthor') {
+                        $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
                 }
             }
             foreach my $item (@cols) {
@@ -2568,7 +2587,7 @@
             $row++;
         }
     }
-    if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
+    if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
             $r->print(&Apache::loncommon::end_data_table().'<br />');
     } elsif ($mode eq 'excel') {
         $excel_workbook->close();
@@ -2611,7 +2630,7 @@
 }
 
 sub select_actions {
-    my ($context,$setting,$statusmode) = @_;
+    my ($context,$setting,$statusmode,$formname) = @_;
     my %lt = &Apache::lonlocal::texthash(
                 revoke   => "Revoke user roles",
                 delete   => "Delete user roles",
@@ -2672,7 +2691,7 @@
         }
     }
     if ($options) {
-        $output = '<select name="bulkaction" onchange="javascript:opendatebrowser(this.form,'."'studentform','change'".')" />'."\n".
+        $output = '<select name="bulkaction" onchange="javascript:opendatebrowser(this.form,'."'$formname','change'".')" />'."\n".
                   '<option value="" selected="selected">'.
                   &mt('Please select').'</option>'."\n".$options."\n".'</select>';
         if ($choices{'dates'}) {

--raeburn1211217020--