[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm lonuserutils.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Fri, 21 Dec 2007 20:34:26 -0000
This is a MIME encoded message
--raeburn1198269266
Content-Type: text/plain
raeburn Fri Dec 21 15:34:26 2007 EDT
Modified files:
/loncom/interface lonuserutils.pm loncreateuser.pm
Log:
loncreateuser.pm
- include $permission as 3rd arg in calls to lonuserutils::print_upload_manager_form()
and lonuserutils::upfile_drop_add().
- set $env{'form.phase'} to '', so "Create new user" textbox re-displays via breadcrumb link, if username entered in "Create new user" textbox contained prohibited characters.
- include $permission as 7th arg in calls to &print_user_modification_page().
- Add $context (course, author, or domain) as first arg in &user_search_result().
- Additional breadcrumb link for "Results" after completing bulkaction of listed users
- Wording change for links on CUSR main menu (Manage -> Modify for single users).
- &build_search_response() takes $context (course, author, or domain) as first arg
- check whether user can create new accounts if search found no match. Either display creation instructions or message with link to helpdesk if creation prohibited.
- generation of interface for activating a role for a single user moved to &course_level_row() for both standard and custom roles.
- users with section-specific 'cst' priv (e.g., in a custom-role) can create student roles in user's section.
lonuserutils.pm
- $permission arg for print_upload_manager_form() and upfile_drop_add().
- section box in pop-up window generated to allow selection of ne section when
making bulk change to users selected from filtered list generated by §ion_picker().
--raeburn1198269266
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071221153426.txt"
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.20 loncom/interface/lonuserutils.pm:1.21
--- loncom/interface/lonuserutils.pm:1.20 Fri Dec 21 12:27:57 2007
+++ loncom/interface/lonuserutils.pm Fri Dec 21 15:34:26 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.20 2007/12/21 17:27:57 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.21 2007/12/21 20:34:26 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -771,7 +771,7 @@
###############################################################
###############################################################
sub print_upload_manager_form {
- my ($r,$context) = @_;
+ my ($r,$context,$permission) = @_;
my $firstLine;
my $datatoken;
if (!$env{'form.datatoken'}) {
@@ -2423,7 +2423,7 @@
}
sub date_section_selector {
- my ($context) = @_;
+ my ($context,$permission) = @_;
my $callingform = $env{'form.callingform'};
my $formname = 'dateselect';
my $groupslist = &get_groupslist();
@@ -2502,7 +2502,8 @@
$starttime = time;
}
$date_items = &date_setting_table($starttime,undef,$context,
- $env{'form.bulkaction'});
+ $env{'form.bulkaction'},$formname,
+ $permission);
}
$output .= '<h3>'.$headertext.'</h3>'.
'<form name="'.$formname.'" method="post">'."\n".
@@ -2536,17 +2537,8 @@
$info = '<input type="hidden" name="retainsec" value="0" />';
}
my $sections_select .= &course_sections(\%sections_count,$env{'form.showrole'});
- my $secbox = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
- &Apache::lonhtmlcommon::row_title(&mt('New section to assign'),'LC_oddrow_value')."\n".
- '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
- '<td align="center">'.&mt('Existing sections')."\n".
- '<br />'.$sections_select.'</td><td align="center">'.
- &mt('New section').'<br />'."\n".
- '<input type="text" name="newsec" size="15" />'."\n".
- '<input type="hidden" name="sections" value="" />'."\n".
- '</td></tr></table>'."\n".
- &Apache::lonhtmlcommon::row_closure(1)."\n".
- &Apache::lonhtmlcommon::end_pick_box().'</p>';
+ my $rowtitle = &mt('New section to assign');
+ my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context);
$output .= $info.$secbox;
}
$output .= '<p>'.
@@ -2883,7 +2875,7 @@
# ================================================= Drop/Add from uploaded file
sub upfile_drop_add {
- my ($r,$context) = @_;
+ my ($r,$context,$permission) = @_;
&Apache::loncommon::load_tmp_file($r);
my @userdata=&Apache::loncommon::upfile_record_sep();
if($env{'form.noFirstLine'}){shift(@userdata);}
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.220 loncom/interface/loncreateuser.pm:1.221
--- loncom/interface/loncreateuser.pm:1.220 Fri Dec 21 13:16:39 2007
+++ loncom/interface/loncreateuser.pm Fri Dec 21 15:34:26 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.220 2007/12/21 18:16:39 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.221 2007/12/21 20:34:26 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2730,10 +2730,11 @@
if (! exists($env{'form.state'})) {
&Apache::lonuserutils::print_first_users_upload_form($r,$context);
} elsif ($env{'form.state'} eq 'got_file') {
- &Apache::lonuserutils::print_upload_manager_form($r,$context);
+ &Apache::lonuserutils::print_upload_manager_form($r,$context,
+ $permission);
} elsif ($env{'form.state'} eq 'enrolling') {
if ($env{'form.datatoken'}) {
- &Apache::lonuserutils::upfile_drop_add($r,$context);
+ &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
}
} else {
&Apache::lonuserutils::print_first_users_upload_form($r,$context);
@@ -2755,16 +2756,18 @@
my $response;
if ($env{'form.srchterm'} !~ /^$match_username$/) {
my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
+ $env{'form.phase'} = '';
&print_username_entry_form($r,$context,$response,$srch);
} else {
my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
&print_user_modification_page($r,$ccuname,$ccdomain,
- $srch,$response,$context);
+ $srch,$response,$context,
+ $permission);
}
} elsif ($env{'form.phase'} eq 'get_user_info') {
my ($currstate,$response,$forcenewuser,$results) =
- &user_search_result($srch);
+ &user_search_result($context,$srch);
if ($env{'form.currstate'} eq 'modify') {
$currstate = $env{'form.currstate'};
}
@@ -2793,7 +2796,8 @@
$response = '';
}
&print_user_modification_page($r,$ccuname,$ccdomain,
- $srch,$response,$context);
+ $srch,$response,$context,
+ $permission);
} elsif ($currstate eq 'query') {
&print_user_query_page($r,'createuser');
} else {
@@ -2804,7 +2808,7 @@
my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
&print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
- $context);
+ $context,$permission);
}
} elsif ($env{'form.phase'} eq 'update_user_data') {
&update_user_data($r,$context);
@@ -2821,15 +2825,22 @@
($permission->{'view'} || $permission->{'cusr'})) {
if ($env{'form.phase'} eq 'bulkchange') {
&Apache::lonhtmlcommon::add_breadcrumb
- ({href=>'backPage(document.studentform)',
- text=>"List Users"});
+ ({href=>'/adm/createuser?action=listusers',
+ text=>"List Users"},
+ {href=>"/adm/createuser",
+ text=>"Result"});
my $setting = $env{'form.roletype'};
my $choice = $env{'form.bulkaction'};
$r->print(&header());
- $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users",
'User_Management_List'));
if ($permission->{'cusr'}) {
&Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
+ $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
+ $r->print(&Apache::loncommon::end_page());
+ } else {
+ $r->print(&mt('You are not authorized to make bulk changes to user roles'));
+ $r->print(&Apache::loncommon::end_page());
}
} else {
&Apache::lonhtmlcommon::add_breadcrumb
@@ -2882,7 +2893,8 @@
} elsif ($env{'form.action'} eq 'dateselect') {
if ($permission->{'cusr'}) {
$r->print(&header(undef,undef,{'no_nav_bar' => 1}).
- &Apache::lonuserutils::date_section_selector($context).
+ &Apache::lonuserutils::date_section_selector($context,
+ $permission).
&Apache::loncommon::end_page());
} else {
$r->print(&header().
@@ -2936,17 +2948,17 @@
my %links = (
domain => {
upload => 'Upload a File of Users',
- singleuser => 'Add/Manage a Single User',
+ singleuser => 'Add/Modify a Single User',
listusers => 'Manage Multiple Users',
},
author => {
upload => 'Upload a File of Co-authors',
- singleuser => 'Add/Manage a Single Co-author',
+ singleuser => 'Add/Modify a Single Co-author',
listusers => 'Display Co-authors and Manage Multiple Users',
},
course => {
upload => 'Upload a File of Course Users',
- singleuser => 'Add/Manage a Single Course User',
+ singleuser => 'Add/Modify a Single Course User',
listusers => 'Display Class Lists and Manage Multiple Users',
},
);
@@ -3040,7 +3052,7 @@
#-------------------------------------------------- functions for &phase_two
sub user_search_result {
- my ($srch) = @_;
+ my ($context,$srch) = @_;
my %allhomes;
my %inst_matches;
my %srch_results;
@@ -3109,14 +3121,14 @@
my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
if ($uhome eq 'no_host') {
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} else {
$currstate = 'modify';
}
} else {
%srch_results = &Apache::lonnet::usersearch($srch);
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
}
} else {
my $courseusers = &get_courseusers();
@@ -3125,7 +3137,7 @@
$currstate = 'modify';
} else {
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
}
} else {
foreach my $user (keys(%$courseusers)) {
@@ -3152,7 +3164,7 @@
}
}
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
}
}
}
@@ -3162,7 +3174,7 @@
($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
if ($dirsrchres eq 'ok') {
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} else {
my $showdom = &display_domain_info($srch->{'srchdomain'});
$response = '<span class="LC_warning">'.
@@ -3176,7 +3188,7 @@
if ($srch->{'srchin'} eq 'dom') {
%srch_results = &Apache::lonnet::usersearch($srch);
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} elsif ($srch->{'srchin'} eq 'crs') {
my $courseusers = &get_courseusers();
foreach my $user (keys(%$courseusers)) {
@@ -3228,14 +3240,14 @@
}
}
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} elsif ($srch->{'srchin'} eq 'alc') {
$currstate = 'query';
} elsif ($srch->{'srchin'} eq 'instd') {
($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
if ($dirsrchres eq 'ok') {
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} else {
my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = '<span class="LC_warning">'.
&mt('Institutional directory search is not available in domain: [_1]',$showdom).
@@ -3341,7 +3353,7 @@
}
sub build_search_response {
- my ($srch,%srch_results) = @_;
+ my ($context,$srch,%srch_results) = @_;
my ($currstate,$response,$forcenewuser);
my %names = (
'uname' => 'username',
@@ -3400,8 +3412,15 @@
}
}
if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
- my $showdom = &display_domain_info($env{'request.role.domain'});
+ my $cancreate =
+ &Apache::lonuserutils::can_create_user($env{'request.role.domain'},$context);
+ if ($cancreate) {
+ my $showdom = &display_domain_info($env{'request.role.domain'});
$response .= '<br /><br />'.&mt("<b>To add a new user</b> (you can only create new users in your current role's domain - <span class=\"LC_cusr_emph\">[_1]</span>):",$env{'request.role.domain'}).'<ul><li>'.&mt("Set 'Domain/institution to search' to: <span class=\"LC_cusr_emph\">[_1]</span>",$showdom).'<li>'.&mt("Set 'Search criteria' to: <span class=\"LC_cusr_emph\">'username is ...... in selected LON-CAPA domain'").'</span></li><li>'.&mt('Provide the proposed username').'</li><li>'.&mt('Search').'</li></ul><br />';
+ } else {
+ my $helplink = ' href="javascript:helpMenu('."'display'".')"';
+ $response .= '<br /><br />'.&mt("You are not authorized to create new users in your current role's domain - <span class=\"LC_cusr_emph\">[_1]</span>.",$env{'request.role.domain'}).'<br />'.&mt('Contact the <a[_1]>helpdesk</a> if you need to create a new user.',$helplink).'<br /><br />';
+ }
}
}
}
@@ -3503,83 +3522,24 @@
}
my @roles = &Apache::lonuserutils::roles_by_context('course');
foreach my $role (@roles) {
+ my $plrole=&Apache::lonnet::plaintext($role);
if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
- my $plrole=&Apache::lonnet::plaintext($role);
- $table .= &Apache::loncommon::start_data_table_row().
-'<td><input type="checkbox" name="act_'.$protectedcourse.'_'.$role.'" /></td>
-<td>'.$plrole.'</td>
-<td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
- if ($role ne 'cc') {
- if (%sections_count) {
- my $currsec =
- &Apache::lonuserutils::course_sections(\%sections_count,
- $protectedcourse.'_'.$role);
- $table .=
- '<td><table class="LC_createuser">'.
- '<tr class="LC_section_row">
- <td valign="top">'.$lt{'exs'}.'<br />'.
- $currsec.'</td>'.
- '<td> </td>'.
- '<td valign="top"> '.$lt{'new'}.'<br />'.
- '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.'" value="" />'.
- '<input type="hidden" '.
- 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'.
- '</tr></table></td>';
- } else {
- $table .= '<td><input type="text" size="10" '.
- 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>';
- }
- } else {
- $table .= '<td> </td>';
+ $table .= &course_level_row($protectedcourse,$role,$area,$domain,
+ $plrole,\%sections_count,\%lt);
+ } elsif ($env{'request.course.sec'} ne '') {
+ if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
+ $env{'request.course.sec'})) {
+ $table .= &course_level_row($protectedcourse,$role,$area,$domain,
+ $plrole,\%sections_count,\%lt);
}
- $table .= <<ENDTIMEENTRY;
-<td><input type="hidden" name="start_$protectedcourse\_$role" value='' />
-<a href=
-"javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt{'ssd'}</a></td>
-<td><input type="hidden" name="end_$protectedcourse\_$role" value='' />
-<a href=
-"javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt{'sed'}</a></td>
-ENDTIMEENTRY
- $table.= &Apache::loncommon::end_data_table_row();
}
}
- foreach my $cust (sort keys %customroles) {
- if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
- my $plrole=$cust;
- my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.
- '_'.$env{'user.name'}.'_'.$plrole;
- $table .= &Apache::loncommon::start_data_table_row().
-'<td><input type="checkbox" name="act_'.$customrole.'" /></td>
-<td>'.$plrole.'</td>
-<td>'.$area.'</td>'."\n";
- if (%sections_count) {
- my $currsec =
- &Apache::lonuserutils::course_sections(\%sections_count,
- $customrole);
- $table.=
- '<td><table class="LC_createuser">'.
- '<tr class="LC_section_row"><td valign="top">'.
- $lt{'exs'}.'<br />'.$currsec.'</td>'.
- '<td> </td>'.
- '<td valign="top"> '.$lt{'new'}.'<br />'.
- '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.
- '<input type="hidden" '.
- 'name="sec_'.$customrole.'" /></td>'.
- '</tr></table></td>';
- } else {
- $table .= '<td><input type="text" size="10" '.
- 'name="sec_'.$customrole.'" /></td>';
- }
- $table .= <<ENDENTRY;
-<td><input type="hidden" name="start_$customrole" value='' />
-<a href=
-"javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>
-<td><input type="hidden" name="end_$customrole" value='' />
-<a href=
-"javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td>
-ENDENTRY
- $table .= &Apache::loncommon::end_data_table_row();
- }
+ if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
+ foreach my $cust (sort keys %customroles) {
+ my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
+ $table .= &course_level_row($protectedcourse,$role,$area,$domain,
+ $cust,\%sections_count,\%lt);
+ }
}
}
return '' if ($table eq ''); # return nothing if there is nothing
@@ -3599,6 +3559,52 @@
return $result;
}
+sub course_level_row {
+ my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
+ my $table = &Apache::loncommon::start_data_table_row().
+ ' <td><input type="checkbox" name="act_'.
+ $protectedcourse.'_'.$role.'" /></td>'."\n".
+ ' <td>'.$plrole.'</td>'."\n".
+ '<td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
+ if ($role eq 'cc') {
+ $table .= '<td> </td>';
+ } elsif ($env{'request.course.sec'} ne '') {
+ $table .= ' <td><input type="hidden" value="'.
+ $env{'request.course.sec'}.'" '.
+ 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
+ $env{'request.course.sec'}.'</td>';
+ } else {
+ if (ref($sections_count) eq 'HASH') {
+ my $currsec =
+ &Apache::lonuserutils::course_sections($sections_count,
+ $protectedcourse.'_'.$role);
+ $table .= '<td><table class="LC_createuser">'.
+ '<tr class="LC_section_row">
+ <td valign="top">'.$lt->{'exs'}.'<br />'.
+ $currsec.'</td>
+ <td> </td>
+ <td valign="top"> '.$lt->{'new'}.'<br />'.
+ '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
+ '" value="" />'.
+ '<input type="hidden" '.
+ 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
+ '</tr></table></td>';
+ } else {
+ $table .= '<td><input type="text" size="10" '.
+ 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>';
+ }
+ }
+ $table .= <<ENDTIMEENTRY;
+<td><input type="hidden" name="start_$protectedcourse\_$role" value='' />
+<a href=
+"javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'ssd'}</a></td>
+<td><input type="hidden" name="end_$protectedcourse\_$role" value='' />
+<a href=
+"javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
+ENDTIMEENTRY
+ $table.= &Apache::loncommon::end_data_table_row();
+}
+
sub course_level_dc {
my ($dcdom) = @_;
my %customroles=&Apache::lonuserutils::my_custom_roles();
@@ -3645,6 +3651,7 @@
'<td> </td>'.
'<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
'<input type="text" name="newsec" value="" />'.
+ '<input type="hidden" name="sections" value="" />'.
'<input type="hidden" name="groups" value="" /></td>'.
'</tr></table></td>';
$otheritems .= <<ENDTIMEENTRY;
--raeburn1198269266--