'."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ $output .= &Apache::loncommon::end_data_table();
return $output;
}
@@ -220,6 +285,7 @@ sub print_username_entry_form {
my %loaditems = (
'onload' => "javascript:setFormElements(document.$formtoset)",
);
+ my %breadcrumb_text = &singleuser_breadcrumb();
my $start_page =
&Apache::loncommon::start_page('User Management',
$jscript,{'add_entries' => \%loaditems,});
@@ -230,7 +296,7 @@ sub print_username_entry_form {
} else {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:backPage(document.crtuser)",
- text=>"Single user search",
+ text=>$breadcrumb_text{'search'},
faq=>282,bug=>'Instructor Interface',});
}
my $helpitem = 'Course_Change_Privileges';
@@ -245,21 +311,14 @@ sub print_username_entry_form {
my $choice=&Apache::loncommon::select_form('make new role','rolename',
('make new role' => 'Generate new role ...',%existingroles));
my %lt=&Apache::lonlocal::texthash(
- 'srch' => "User Search",
- or => "or",
+ 'srst' => 'Search for a user and enroll as a student',
+ 'srad' => 'Search for a user and modify/add user information or roles',
'usr' => "Username",
'dom' => "Domain",
'ecrp' => "Edit Custom Role Privileges",
'nr' => "Name of Role",
'cre' => "Custom Role Editor",
- 'mod' => "to modify user information or add/modify roles",
- 'enrl' => "to enroll one student",
);
- my $help = &Apache::loncommon::help_open_menu(undef,undef,282,'Instructor Interface');
- my $sellink=&Apache::loncommon::selectstudent_link('crtuser','srchterm','srchdomain');
- if ($sellink) {
- $sellink = "$lt{'or'} ".$sellink;
- }
$r->print($start_page."\n".$crumbs);
if ($env{'form.action'} eq 'custom') {
if (&Apache::lonnet::allowed('mcr','/')) {
@@ -274,12 +333,12 @@ $lt{'nr'}: $choice print("
-
$lt{'srch'} $sellink $actiontext
");
+
$actiontext
");
if ($env{'form.origform'} ne 'crtusername') {
$r->print("\n".$response);
}
@@ -291,7 +350,7 @@ ENDCUSTOM
sub entry_form {
my ($dom,$srch,$forcenewuser,$context,$responsemsg) = @_;
my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
- my $usertype;
+ my ($usertype,$inexact);
if (ref($srch) eq 'HASH') {
if (($srch->{'srchin'} eq 'dom') &&
($srch->{'srchby'} eq 'uname') &&
@@ -301,6 +360,8 @@ sub entry_form {
my ($rules,$ruleorder) =
&Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
$usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
+ } else {
+ $inexact = 1;
}
}
my $cancreate =
@@ -309,6 +370,11 @@ sub entry_form {
&Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
'document.crtuser',$cancreate,$usertype);
my $srchbutton = &mt('Search');
+ if ($env{'form.action'} eq 'singlestudent') {
+ $srchbutton = &mt('Search and Enroll');
+ } elsif ($cancreate && $responsemsg ne '' && $inexact) {
+ $srchbutton = &mt('Search or Add New User');
+ }
my $output = <<"ENDBLOCK";
ENDBLOCK
- if ($cancreate && $env{'form.phase'} eq '') {
+ if ($env{'form.phase'} eq '') {
my $defdom=$env{'request.role.domain'};
my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
- my $helpcrt=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
my %lt=&Apache::lonlocal::texthash(
+ 'enro' => 'Enroll one student',
+ 'admo' => 'Add/modify a single user',
+ 'crea' => 'create new user if required',
+ 'uskn' => "username is known",
'crnu' => 'Create a new user',
'usr' => 'Username',
'dom' => 'in domain',
- 'cra' => 'Create user',
+ 'enrl' => 'Enroll',
+ 'cram' => 'Create/Modify user',
);
+ my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
+ my ($title,$buttontext,$showresponse);
+ if ($env{'form.action'} eq 'singlestudent') {
+ $title = $lt{'enro'};
+ $buttontext = $lt{'enrl'};
+ } else {
+ $title = $lt{'admo'};
+ $buttontext = $lt{'cram'};
+ }
+ if ($cancreate) {
+ $title .= ' ('.$lt{'crea'}.')';
+ } else {
+ $title .= ' ('.$lt{'uskn'}.')';
+ }
+ if ($env{'form.origform'} eq 'crtusername') {
+ $showresponse = $responsemsg;
+ }
$output .= <<"ENDDOCUMENT";
+
@@ -381,7 +470,7 @@ END
# =================================================================== Phase two
sub print_user_selection_page {
- my ($r,$response,$srch,$srch_results,$operation,$srcharray,$context) = @_;
+ my ($r,$response,$srch,$srch_results,$srcharray,$context) = @_;
my @fields = ('username','domain','lastname','firstname','permanentemail');
my $sortby = $env{'form.sortby'};
@@ -416,27 +505,22 @@ ENDSCRIPT
'permanentemail' => "permanent e-mail",
);
$r->print(&Apache::loncommon::start_page('User Management',$jscript));
- if ($operation eq 'createuser') {
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.usersrchform,'','')",
- text=>"Create/modify user",
- faq=>282,bug=>'Instructor Interface',},
- {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
- text=>"Select User",
- faq=>282,bug=>'Instructor Interface',});
+
+ my %breadcrumb_text = &singleuser_breadcrumb();
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.usersrchform,'','')",
+ text=>$breadcrumb_text{'search'},
+ faq=>282,bug=>'Instructor Interface',},
+ {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
+ text=>$breadcrumb_text{'userpicked'},
+ faq=>282,bug=>'Instructor Interface',});
+ if ($env{'form.action'} eq 'singleuser') {
$r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
'Course_Change_Privileges'));
$r->print("$lt{'usrch'} ");
$r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
$r->print('
'.$lt{'usel'}.'
');
- } elsif ($operation eq 'enrollstudent') {
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.usersrchform,'','')",
- text=>"Create/modify student",
- faq=>282,bug=>'Instructor Interface',},
- {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
- text=>"Select Student",
- faq=>282,bug=>'Instructor Interface',});
+ } elsif ($env{'form.action'} eq 'singlestudent') {
$r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
'Course_Add_Student'));
$r->print($jscript."$lt{'stusrch'} ");
@@ -515,8 +599,7 @@ sub print_user_modification_page {
$formname = 'cu';
}
my %abv_auth = &auth_abbrev();
- my ($curr_authtype,%rulematch,%inst_results,$curr_kerb_ver,$newuser,
- %alerts,%curr_rules,%got_rules);
+ my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
if ($uhome eq 'no_host') {
my $usertype;
@@ -571,32 +654,10 @@ sub print_user_modification_page {
}
} else {
$newuser = 0;
- my $currentauth =
- &Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
- if ($currentauth =~ /^(krb4|krb5|unix|internal|localauth):/) {
- $curr_authtype = $abv_auth{$1};
- if ($currentauth =~ /^krb(4|5)/) {
- $curr_kerb_ver = $1;
- }
- }
}
if ($response) {
$response = ' '.$response;
}
- my $defdom=$env{'request.role.domain'};
-
- my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_kerberos_defaults($defdom);
-
- my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom,
- kerb_def_auth => $krbdef,
- curr_authtype => $curr_authtype,
- curr_kerb_ver => $curr_kerb_ver,
- domain => $ccdomain,
- );
- $loginscript = &Apache::loncommon::authform_header(%param);
- $authformkrb = &Apache::loncommon::authform_kerberos(%param);
my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
my $dc_setcourse_code = '';
@@ -607,9 +668,12 @@ sub print_user_modification_page {
my $js = &validation_javascript($context,$ccdomain,$pjump_def,
$groupslist,$newuser,$formname,\%loaditem);
+ my $args = {'add_entries' => \%loaditem};
+ if ($env{'form.popup'}) {
+ $args->{'no_nav_bar'} = 1;
+ }
my $start_page =
- &Apache::loncommon::start_page('User Management',
- $js,{'add_entries' => \%loaditem,});
+ &Apache::loncommon::start_page('User Management',$js,$args);
my %breadcrumb_text = &singleuser_breadcrumb();
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:backPage($form)",
@@ -650,11 +714,12 @@ ENDFORMINFO
}
if ($newuser) {
my $portfolioform;
- if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
- # Current user has quota modification privileges
+ if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
+ (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
+ # Current user has quota or user tools modification privileges
$portfolioform = ' '.&portfolio_quota($ccuname,$ccdomain);
}
- &initialize_authen_forms($ccdomain);
+ &initialize_authen_forms($ccdomain,$formname);
my %lt=&Apache::lonlocal::texthash(
'cnu' => 'Create New User',
'ast' => 'as a student',
@@ -704,8 +769,9 @@ $lt{'hs'}: $home_server_pick
my $authtype = $rules->{$matchedrule}{'authtype'};
if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
$r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
- } else {
+ } else {
my $authparm = $rules->{$matchedrule}{'authparm'};
+ $authmsg = $rules->{$matchedrule}{'authmsg'};
if ($authtype =~ /^krb(4|5)$/) {
my $ver = $1;
if ($authparm ne '') {
@@ -714,7 +780,6 @@ $lt{'hs'}: $home_server_pick
KERB
- $authmsg = $rules->{$matchedrule}{'authmsg'};
}
} else {
$fixedauth =
@@ -723,8 +788,16 @@ KERB
$fixedauth .=
''."\n";
} else {
- $varauth =
+ if ($authtype eq 'int') {
+ $varauth = ' '.
+&mt('[_1] Internally authenticated (with initial password [_2])','','')."';
+ } elsif ($authtype eq 'loc') {
+ $varauth = ' '.
+&mt('[_1] Local Authentication with argument [_2]','','')."\n";
+ } else {
+ $varauth =
''."\n";
+ }
}
}
}
@@ -775,37 +848,63 @@ ENDCHANGEUSER
$r->print(&Apache::lonuserutils::forceid_change($context));
}
$r->print('');
- my $user_auth_text =
- &user_authentication($ccuname,$ccdomain,$krbdefdom,\%abv_auth);
- my $user_quota_text;
- if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
+ my $user_auth_text = &user_authentication($ccuname,$ccdomain,$formname);
+ my ($user_quota_text,$user_tools_text);
+ if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
+ (&Apache::lonnet::allowed('mut',$ccdomain))) {
# Current user has quota modification privileges
$user_quota_text = &portfolio_quota($ccuname,$ccdomain);
- } elsif (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
- # Get the user's portfolio information
- my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
- $ccdomain,$ccuname);
-
- my %lt=&Apache::lonlocal::texthash(
- 'dska' => "Disk space allocated to user's portfolio files",
- 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
- 'ichr' => "If a change is required, contact a domain coordinator for the domain",
- );
- $user_quota_text = < "Disk space allocated to user's portfolio files",
+ 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
+ 'ichr' => "If a change is required, contact a domain coordinator for the domain",
+ );
+ $user_quota_text = <$lt{'dska'}
$lt{'youd'} $lt{'ichr'}: $ccdomain
ENDNOPORTPRIV
+ }
+ }
+ if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
+ if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
+ my %lt=&Apache::lonlocal::texthash(
+ 'utav' => "User Tools Availability",
+ 'yodo' => "You do not have privileges to modify Portfolio, Blog or Home Page settings for this user.",
+ 'ifch' => "If a change is required, contact a domain coordinator for the domain",
+ );
+ $user_tools_text = <$lt{'utav'}
+$lt{'yodo'} $lt{'ifch'}: $ccdomain
+ENDNOTOOLSPRIV
+ }
}
if ($user_auth_text ne '') {
$r->print('
'.$user_auth_text);
if ($user_quota_text ne '') {
$r->print($user_quota_text);
}
+ if ($user_tools_text ne '') {
+ $r->print($user_tools_text);
+ }
if ($env{'form.action'} eq 'singlestudent') {
$r->print(&date_sections_select($context,$newuser,$formname));
}
} elsif ($user_quota_text ne '') {
$r->print('
'.$user_quota_text);
+ if ($user_tools_text ne '') {
+ $r->print($user_tools_text);
+ }
+ if ($env{'form.action'} eq 'singlestudent') {
+ $r->print(&date_sections_select($context,$newuser,$formname));
+ }
+ } elsif ($user_tools_text ne '') {
+ $r->print('
'.$user_tools_text);
if ($env{'form.action'} eq 'singlestudent') {
$r->print(&date_sections_select($context,$newuser,$formname));
}
@@ -835,12 +934,12 @@ ENDNOPORTPRIV
$addrolesdisplay = $add_domainroles;
}
$r->print(&course_level_dc($env{'request.role.domain'},'Course'));
- $r->print(' '."\n");
+ $r->print(' '."\n");
} elsif ($context eq 'author') {
if ($addrolesdisplay) {
- $r->print(' print(' print(' onClick="verify_message(this.form)" \>'."\n");
+ $r->print(' onClick="auth_check()" \>'."\n");
} else {
$r->print('onClick="this.form.submit()" \>'."\n");
}
@@ -850,7 +949,7 @@ ENDNOPORTPRIV
}
} else {
$r->print(&course_level_table(%inccourses));
- $r->print(' '."\n");
+ $r->print(' '."\n");
}
}
$r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
@@ -867,7 +966,7 @@ sub singleuser_breadcrumb {
$breadcrumb_text{'userpicked'} = 'Select a user',
$breadcrumb_text{'modify'} = 'Set section/dates',
} else {
- $breadcrumb_text{'search'} = 'Create/modify user';
+ $breadcrumb_text{'search'} = 'Create/modify a user';
$breadcrumb_text{'userpicked'} = 'Select a user',
$breadcrumb_text{'modify'} = 'Set user role',
}
@@ -897,26 +996,28 @@ sub validation_javascript {
if ($context eq 'domain') {
my $dcdom = $env{'request.role.domain'};
$loaditem->{'onload'} = "document.cu.coursedesc.value='';";
- $dc_setcourse_code = &Apache::lonuserutils::dc_setcourse_js('cu','singleuser');
+ $dc_setcourse_code =
+ &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
} else {
- $nondc_setsection_code =
- &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
+ my $checkauth;
+ if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
+ $checkauth = 1;
+ }
+ if ($context eq 'course') {
+ $nondc_setsection_code =
+ &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
+ undef,$checkauth);
+ }
+ if ($checkauth) {
+ $nondc_setsection_code .=
+ &Apache::lonuserutils::verify_authen($formname,$context);
+ }
}
my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
$nondc_setsection_code,$groupslist);
-
my ($jsback,$elements) = &crumb_utilities();
- my $javascript_validations;
- if ((&Apache::lonnet::allowed('mau',$ccdomain)) || ($newuser)) {
- my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_kerberos_defaults($ccdomain);
- $javascript_validations =
- &Apache::lonuserutils::javascript_validations('createuser',$krbdefdom,undef,
- undef,$ccdomain);
- }
$js .= "\n".
- '';
+ '';
return $js;
}
@@ -967,7 +1068,7 @@ sub display_existing_roles {
if (defined($coursedata{'description'})) {
$carea=$coursedata{'description'}.
' '.&mt('Domain').': '.$coursedom.(' 'x8).
- &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
+ &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
$sortkey.="\0".$coursedata{'description'};
$class=$coursedata{'type'};
} else {
@@ -1241,22 +1342,9 @@ sub new_domain_roles {
}
sub user_authentication {
- my ($ccuname,$ccdomain,$krbdefdom,$abv_auth) = @_;
+ my ($ccuname,$ccdomain,$formname) = @_;
my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
- my ($loginscript,$outcome);
- if ($currentauth=~/^(krb)(4|5):(.*)/) {
- my $long_auth = $1.$2;
- my $curr_kerb_ver = $2;
- my $krbdefdom=$3;
- my $curr_authtype = $abv_auth->{$long_auth};
- my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom,
- domain => $ccdomain,
- curr_authtype => $curr_authtype,
- curr_kerb_ver => $curr_kerb_ver,
- );
- $loginscript = &Apache::loncommon::authform_header(%param);
- }
+ my $outcome;
# Check for a bad authentication type
if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
# bad authentication scheme
@@ -1268,7 +1356,8 @@ sub user_authentication {
'ld' => "Login Data"
);
if (&Apache::lonnet::allowed('mau',$ccdomain)) {
- &initialize_authen_forms($ccdomain);
+ &initialize_authen_forms($ccdomain,$formname);
+
my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
$outcome = <
@@ -1289,7 +1378,7 @@ $lt{'uuas'} ($currentauth). $lt{'adcs'}.
ENDBADAUTH
}
} else { # Authentication type is valid
- &initialize_authen_forms($ccdomain,$currentauth,'modifyuser');
+ &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
my ($authformcurrent,$can_modify,@authform_others) =
&modify_login_block($ccdomain,$currentauth);
if (&Apache::lonnet::allowed('mau',$ccdomain)) {
@@ -1333,6 +1422,7 @@ ENDBADAUTH
$outcome .= <$lt{'ccld'}
$lt{'yodo'} $lt{'ifch'}: $ccdomain
+
ENDNOPRIV
}
}
@@ -1407,10 +1497,12 @@ sub modify_login_block {
}
sub personal_data_display {
- my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_;
+ my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
my ($output,$showforceid,%userenv,%canmodify);
my @userinfo = ('firstname','middlename','lastname','generation',
'permanentemail','id');
+ my $rowcount = 0;
+ my $editable = 0;
if (!$newuser) {
# Get the users information
%userenv = &Apache::lonnet::get('environment',
@@ -1418,7 +1510,10 @@ sub personal_data_display {
'permanentemail','id'],$ccdomain,$ccuname);
%canmodify =
&Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
- \@userinfo);
+ \@userinfo,$rolesarray);
+ } elsif ($context eq 'selfcreate') {
+ %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
+ $inst_results,$rolesarray);
}
my %lt=&Apache::lonlocal::texthash(
'pd' => "Personal Data",
@@ -1427,7 +1522,7 @@ sub personal_data_display {
'lastname' => "Last Name",
'generation' => "Generation",
'permanentemail' => "Permanent e-mail address",
- 'id' => "ID/Student Number",
+ 'id' => "Student/Employee ID",
'lg' => "Login Data"
);
my %textboxsize = (
@@ -1443,40 +1538,97 @@ sub personal_data_display {
&Apache::lonhtmlcommon::start_pick_box();
foreach my $item (@userinfo) {
my $rowtitle = $lt{$item};
+ my $hiderow = 0;
if ($item eq 'generation') {
$rowtitle = $genhelp.$rowtitle;
}
- $output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
+ my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
if ($newuser) {
if (ref($inst_results) eq 'HASH') {
if ($inst_results->{$item} ne '') {
- $output .= ''.$inst_results->{$item};
+ $row .= ''.$inst_results->{$item};
} else {
- $output .= '';
+ if ($context eq 'selfcreate') {
+ if ($canmodify{$item}) {
+ $row .= '';
+ $editable ++;
+ } else {
+ $hiderow = 1;
+ }
+ } else {
+ $row .= '';
+ }
}
} else {
- $output .= '';
+ if ($context eq 'selfcreate') {
+ if (($item eq 'permanentemail') && ($newuser eq 'email')) {
+ $row .= $ccuname;
+ } else {
+ if ($canmodify{$item}) {
+ $row .= '';
+ $editable ++;
+ } else {
+ $hiderow = 1;
+ }
+ }
+ } else {
+ $row .= '';
+ }
}
} else {
if ($canmodify{$item}) {
- $output .= '';
+ $row .= '';
} else {
- $output .= $userenv{$item};
+ $row .= $userenv{$item};
}
if ($item eq 'id') {
$showforceid = $canmodify{$item};
}
}
- $output .= &Apache::lonhtmlcommon::row_closure(1);
+ $row .= &Apache::lonhtmlcommon::row_closure(1);
+ if (!$hiderow) {
+ $output .= $row;
+ $rowcount ++;
+ }
}
$output .= &Apache::lonhtmlcommon::end_pick_box();
if (wantarray) {
- return ($output,$showforceid);
+ if ($context eq 'selfcreate') {
+ return($output,$rowcount,$editable);
+ } else {
+ return ($output,$showforceid);
+ }
} else {
return $output;
}
}
+sub selfcreate_canmodify {
+ my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
+ if (ref($inst_results) eq 'HASH') {
+ my @inststatuses = &get_inststatuses($inst_results);
+ if (@inststatuses == 0) {
+ @inststatuses = ('default');
+ }
+ $rolesarray = \@inststatuses;
+ }
+ my %canmodify =
+ &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
+ $rolesarray);
+ return %canmodify;
+}
+
+sub get_inststatuses {
+ my ($insthashref) = @_;
+ my @inststatuses = ();
+ if (ref($insthashref) eq 'HASH') {
+ if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
+ @inststatuses = @{$insthashref->{'inststatus'}};
+ }
+ }
+ return @inststatuses;
+}
+
# ================================================================= Phase Three
sub update_user_data {
my ($r,$context) = @_;
@@ -1501,7 +1653,13 @@ sub update_user_data {
my $jscript = ''."\n";
my %breadcrumb_text = &singleuser_breadcrumb();
- $r->print(&Apache::loncommon::start_page($title,$jscript));
+ my $args;
+ if ($env{'form.popup'}) {
+ $args->{'no_nav_bar'} = 1;
+ } else {
+ $args = undef;
+ }
+ $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:backPage(document.userupdate)",
text=>$breadcrumb_text{'search'},
@@ -1533,8 +1691,8 @@ sub update_user_data {
}
if ( $env{'form.ccuname'} ne
&LONCAPA::clean_username($env{'form.ccuname'}) ) {
- $r->print($error.&mt('Invalid login name').'. '.
- &mt('Only letters, numbers, periods, dashes, @, and underscores are valid').'.'.
+ $r->print($error.&mt('Invalid login name.').' '.
+ &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
$end.$rtnlink);
return;
}
@@ -1544,8 +1702,8 @@ sub update_user_data {
}
if ( $env{'form.ccdomain'} ne
&LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
- $r->print($error.&mt ('Invalid domain name').'. '.
- &mt('Only letters, numbers, periods, dashes, and underscores are valid').'.'.
+ $r->print($error.&mt ('Invalid domain name.').' '.
+ &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
$end.$rtnlink);
return;
}
@@ -1592,6 +1750,7 @@ sub update_user_data {
$r->print('
'.&mt('User [_1] in domain [_2]',
$env{'form.ccuname'}, $env{'form.ccdomain'}).'
');
my (%alerts,%rulematch,%inst_results,%curr_rules);
+ my @usertools = ('aboutme','blog','portfolio');
if ($env{'form.makeuser'}) {
$r->print('
'.&mt('Creating new account.').'
');
# Check for the authentication mode and password
@@ -1651,6 +1810,35 @@ sub update_user_data {
$r->print(&mt('Generating user').': '.$result);
$uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
$env{'form.ccdomain'});
+ my (%changeHash,%newcustom,%changed);
+ if ($uhome ne 'no_host') {
+ if ($env{'form.customquota'} == 1) {
+ if ($env{'form.portfolioquota'} eq '') {
+ $newcustom{'quota'} = 0;
+ } else {
+ $newcustom{'quota'} = $env{'form.portfolioquota'};
+ $newcustom{'quota'} =~ s/[^\d\.]//g;
+ }
+ $changed{'quota'} = "a_admin($newcustom{'quota'},\%changeHash);
+ }
+ foreach my $item (@usertools) {
+ if ($env{'form.custom'.$item} == 1) {
+ $newcustom{$item} = $env{'form.tools_'.$item};
+ $changed{$item} = &tool_admin($item,$newcustom{$item},\%changeHash);
+ }
+ }
+ if (keys(%changed)) {
+ $changeHash{'firstname'} = $env{'form.cfirstname'};
+ $changeHash{'middlename'} = $env{'form.cmiddlename'};
+ $changeHash{'lastname'} = $env{'form.clastname'};
+ $changeHash{'generation'} = $env{'form.cgeneration'};
+ $changeHash{'id'} = $env{'form.cid'};
+ $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
+ my $chgresult =
+ &Apache::lonnet::put('environment',\%changeHash,
+ $env{'form.ccdomain'},$env{'form.ccuname'});
+ }
+ }
$r->print(' '.&mt('Home server').': '.$uhome.' '.
&Apache::lonnet::hostname($uhome));
} elsif (($env{'form.login'} ne 'nochange') &&
@@ -1682,7 +1870,8 @@ sub update_user_data {
# Check for need to change
my %userenv = &Apache::lonnet::get
('environment',['firstname','middlename','lastname','generation',
- 'id','permanentemail','portfolioquota','inststatus'],
+ 'id','permanentemail','portfolioquota','inststatus','tools.aboutme',
+ 'tools.blog','tools.portfolio'],
$env{'form.ccdomain'},$env{'form.ccuname'});
my ($tmp) = keys(%userenv);
if ($tmp =~ /^(con_lost|error)/i) {
@@ -1773,7 +1962,7 @@ sub update_user_data {
$env{'form.c'.$item} = $userenv{$item};
}
}
- # Check to see if we can change the ID/student number
+ # Check to see if we can change the Student/Employee ID
my $forceid = $env{'form.forceid'};
my $recurseid = $env{'form.recurseid'};
my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
@@ -1784,7 +1973,10 @@ sub update_user_data {
(!$forceid)) {
if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
$env{'form.cid'} = $userenv{'id'};
- $no_forceid_alert = &mt('New student/employeeID does not match existing ID for this user.').' '.&mt('Change is not permitted without checking the \'Force ID change\' checkbox on the previous page.').' '."\n";
+ $no_forceid_alert = &mt('New Student/Employee ID does not match existing ID for this user.')
+ .' '
+ .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
+ .' '."\n";
}
}
if ($env{'form.cid'} ne $userenv{'id'}) {
@@ -1804,14 +1996,17 @@ sub update_user_data {
}
my ($quotachanged,$oldportfolioquota,$newportfolioquota,
$inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
- $newdefquotatext);
+ $newdefquotatext,%oldaccess,%oldaccesstext,%newaccess,%newaccesstext);
my ($defquota,$settingstatus) =
&Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
- my $showquota;
+ my ($showquota,$showtools);
if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
$showquota = 1;
}
- my %changeHash;
+ if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
+ $showtools = 1;
+ }
+ my (%changeHash,%changed);
$changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
if ($userenv{'portfolioquota'} ne '') {
$oldportfolioquota = $userenv{'portfolioquota'};
@@ -1823,10 +2018,10 @@ sub update_user_data {
$newportfolioquota =~ s/[^\d\.]//g;
}
if ($newportfolioquota != $oldportfolioquota) {
- $quotachanged = "a_admin($newportfolioquota,\%changeHash);
+ $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
}
} else {
- $quotachanged = "a_admin('',\%changeHash);
+ $changed{'quota'} = "a_admin('',\%changeHash);
$newportfolioquota = $defquota;
$newisdefault = 1;
}
@@ -1840,7 +2035,7 @@ sub update_user_data {
$newportfolioquota = $env{'form.portfolioquota'};
$newportfolioquota =~ s/[^\d\.]//g;
}
- $quotachanged = "a_admin($newportfolioquota,\%changeHash);
+ $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash);
} else {
$newportfolioquota = $defquota;
$newisdefault = 1;
@@ -1852,6 +2047,73 @@ sub update_user_data {
if ($newisdefault) {
$newdefquotatext = &get_defaultquota_text($settingstatus);
}
+
+ foreach my $tool (@usertools) {
+ if ($userenv{'tools.'.$tool} ne '') {
+ $oldaccess{$tool} = &mt('custom');
+ if ($userenv{'tools_'.$tool}) {
+ $oldaccesstext{$tool} = &mt("availability set to 'on'");
+ } else {
+ $oldaccesstext{$tool} = &mt("availability set to 'off'");
+ }
+ $changeHash{'tools.'.$tool} = $userenv{'tools.'.$tool};
+ if ($env{'form.custom'.$tool} == 1) {
+ if ($env{'form.tools_'.$tool} ne $userenv{'tools.'.$tool}) {
+ $changed{$tool} = &tool_admin($tool,$env{'form.tools_'.$tool},
+ \%changeHash);
+ if ($changed{$tool}) {
+ $newaccess{$tool} = &mt('custom');
+ if ($env{'form.tools_'.$tool}) {
+ $newaccesstext{$tool} = &mt("availability set to 'on'");
+ } else {
+ $newaccesstext{$tool} = &mt("availability set to 'off'");
+ }
+ } else {
+ $newaccess{$tool} = $oldaccess{$tool};
+ if ($userenv{'tools.'.$tool}) {
+ $newaccesstext{$tool} = &mt("availability set to 'on'");
+ } else {
+ $newaccesstext{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ } else {
+ $newaccess{$tool} = $oldaccess{$tool};
+ $newaccesstext{$tool} = $oldaccesstext{$tool};
+ }
+ } else {
+ $changed{$tool} = &tool_admin($tool,'',\%changeHash);
+ if ($changed{$tool}) {
+ $newaccess{$tool} = &mt('default');
+ } else {
+ $newaccess{$tool} = $oldaccess{$tool};
+ if ($userenv{'tools.'.$tool}) {
+ $newaccesstext{$tool} = &mt("availability set to 'on'");
+ } else {
+ $newaccesstext{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ }
+ } else {
+ $oldaccess{$tool} = &mt('default');
+ if ($env{'form.custom'.$tool} == 1) {
+ $changed{$tool} = &tool_admin($tool,$env{'form.tools_'.$tool},
+ \%changeHash);
+ if ($changed{$tool}) {
+ $newaccess{$tool} = &mt('custom');
+ if ($env{'form.tools_'.$tool}) {
+ $newaccesstext{$tool} = &mt("availability set to 'on'");
+ } else {
+ $newaccesstext{$tool} = &mt("availability set to 'off'");
+ }
+ } else {
+ $newaccess{$tool} = $oldaccess{$tool};
+ }
+ } else {
+ $newaccess{$tool} = $oldaccess{$tool};
+ }
+ }
+ }
+
if ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
$env{'form.cmiddlename'} ne $userenv{'middlename'} ||
$env{'form.clastname'} ne $userenv{'lastname'} ||
@@ -1860,18 +2122,35 @@ sub update_user_data {
$env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
$namechanged = 1;
}
- if ($namechanged || $quotachanged) {
+ if (($namechanged) || (keys(%changed) > 0)) {
$changeHash{'firstname'} = $env{'form.cfirstname'};
$changeHash{'middlename'} = $env{'form.cmiddlename'};
$changeHash{'lastname'} = $env{'form.clastname'};
$changeHash{'generation'} = $env{'form.cgeneration'};
$changeHash{'id'} = $env{'form.cid'};
$changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
- my ($quotachgresult,$namechgresult);
- if ($quotachanged) {
- $quotachgresult =
+ my ($chgresult,$namechgresult);
+ if (keys(%changed) > 0) {
+ $chgresult =
&Apache::lonnet::put('environment',\%changeHash,
$env{'form.ccdomain'},$env{'form.ccuname'});
+ if ($chgresult eq 'ok') {
+ if (($env{'user.name'} eq $env{'form.ccuname'}) &&
+ ($env{'user.domain'} eq $env{'form.ccdomain'})) {
+ my %newenvhash;
+ foreach my $key (keys(%changed)) {
+ if ($key ne 'quota') {
+ $newenvhash{'environment.tools.'.$key} =
+ $changeHash{'tools.'.$key};
+ $newenvhash{'environment.availabletools.'.$key} =
+ $changeHash{'tools.'.$key};
+ }
+ }
+ if (keys(%newenvhash)) {
+ &Apache::lonnet::appenv(\%newenvhash);
+ }
+ }
+ }
}
if ($namechanged) {
# Make the change
@@ -1890,19 +2169,22 @@ sub update_user_data {
);
}
if (($namechanged && $namechgresult eq 'ok') ||
- ($quotachanged && $quotachgresult eq 'ok')) {
+ ((keys(%changed) > 0) && $chgresult eq 'ok')) {
# Tell the user we changed the name
my %lt=&Apache::lonlocal::texthash(
- 'uic' => "User Information Changed",
- 'frst' => "first",
- 'mddl' => "middle",
- 'lst' => "last",
- 'gen' => "generation",
- 'id' => "ID/Student number",
- 'mail' => "permanent e-mail",
- 'disk' => "disk space allocated to portfolio files",
- 'prvs' => "Previous",
- 'chto' => "Changed To"
+ 'uic' => "User Information Changed",
+ 'frst' => "First",
+ 'mddl' => "Middle",
+ 'lst' => "Last",
+ 'gen' => "Generation",
+ 'id' => "Student/Employee ID",
+ 'mail' => "Permanent E-mail",
+ 'disk' => "Disk space allocated to portfolio files",
+ 'blog' => "Blog Availability",
+ 'aboutme' => "Home Page Availability",
+ 'portfolio' => "Portfolio Availability",
+ 'prvs' => "Previous",
+ 'chto' => "Changed To"
);
$r->print('
'.$lt{'uic'}.'
'.
&Apache::loncommon::start_data_table().
@@ -1920,6 +2202,12 @@ END
$r->print("
$lt{'disk'}
\n");
}
+ if ($showtools) {
+ foreach my $item (@usertools) {
+ $r->print("
+
\n");
}
+ if ($showtools) {
+ foreach my $item (@usertools) {
+ $r->print("
+
$newaccess{$item} $newaccesstext{$item}
\n");
+ }
+ }
$r->print(&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table().' ');
if ($env{'form.cid'} ne $userenv{'id'}) {
@@ -1970,7 +2270,7 @@ END
foreach my $key (keys(%changeHash)) {
$newenvhash{'environment.'.$key} = $changeHash{$key};
}
- &Apache::lonnet::appenv(%newenvhash);
+ &Apache::lonnet::appenv(\%newenvhash);
}
} else { # error occurred
$r->print(''.&mt('Unable to successfully change environment for').' '.
@@ -1978,12 +2278,15 @@ END
$env{'form.ccdomain'}.' ');
}
} else { # End of if ($env ... ) logic
- # They did not want to change the users name or quota but we can
- # still tell them what the name and quota are
+ # They did not want to change the users name, quota or tool availability,
+ # but we can still tell them what the name and quota and availabilities are
my %lt=&Apache::lonlocal::texthash(
- 'id' => "ID/Student number",
- 'mail' => "Permanent e-mail",
- 'disk' => "Disk space allocated to user's portfolio files",
+ 'id' => "Student/Employee ID",
+ 'mail' => "Permanent e-mail",
+ 'disk' => "Disk space allocated to user's portfolio files",
+ 'blog' => "Blog Availability",
+ 'aboutme' => "Home Page Availability",
+ 'portfolio' => "Portfolio Availability",
);
$r->print(<<"END");
');
+ }
}
$r->print(&Apache::loncommon::end_page());
}
sub update_roles {
- my ($r) = @_;
+ my ($r,$context) = @_;
my $now=time;
- my $rolechanges = 0;
+ my @rolechanges;
my %disallowed;
$r->print('
'.&mt('Modifying Roles').'
');
foreach my $key (keys (%env)) {
@@ -2064,7 +2390,7 @@ sub update_roles {
my $result =
&Apache::lonnet::revokerole($env{'form.ccdomain'},
$env{'form.ccuname'},
- $scope,$role);
+ $scope,$role,'','',$context);
$r->print(&mt('Revoking [_1] in [_2]: [_3]',
$role,$scope,''.$result.'').' ');
if ($role eq 'st') {
@@ -2074,16 +2400,21 @@ sub update_roles {
$now);
$r->print($result);
}
+ if (!grep(/^\Q$role\E$/,@rolechanges)) {
+ push(@rolechanges,$role);
+ }
}
if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
# Revoke custom role
$r->print(&mt('Revoking custom role:').
' '.$4.' by '.$3.':'.$2.' in '.$1.': '.
&Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
- $env{'form.ccuname'},$1,$2,$3,$4).
+ $env{'form.ccuname'},$1,$2,$3,$4,'','',$context).
' ');
+ if (!grep(/^cr$/,@rolechanges)) {
+ push(@rolechanges,'cr');
+ }
}
- $rolechanges ++;
} elsif ($key=~/^form\.del/) {
if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
# Delete standard role
@@ -2091,7 +2422,8 @@ sub update_roles {
my $result =
&Apache::lonnet::assignrole($env{'form.ccdomain'},
$env{'form.ccuname'},
- $scope,$role,$now,0,1);
+ $scope,$role,$now,0,1,'',
+ $context);
$r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
''.$result.'').' ');
if ($role eq 'st') {
@@ -2101,6 +2433,9 @@ sub update_roles {
$now);
$r->print($result);
}
+ if (!grep(/^\Q$role\E$/,@rolechanges)) {
+ push(@rolechanges,$role);
+ }
}
if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
@@ -2109,9 +2444,11 @@ sub update_roles {
$rolename,$rnam,$rdom,$url).': '.
&Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
$env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
- 0,1).' ');
+ 0,1,$context).' ');
+ if (!grep(/^cr$/,@rolechanges)) {
+ push(@rolechanges,'cr');
+ }
}
- $rolechanges ++;
} elsif ($key=~/^form\.ren/) {
my $udom = $env{'form.ccdomain'};
my $uname = $env{'form.ccuname'};
@@ -2139,22 +2476,28 @@ sub update_roles {
}
} else {
my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
- $env{'form.ccuname'},$url,$role,0,$now);
- $output = &mt('Re-enabling [_1] in [_2]: [_3]',
- $role,$url,$result).' ';
+ $env{'form.ccuname'},$url,$role,0,$now,'','',
+ $context);
+ $output = &mt('Re-enabling [_1] in [_2]: [_3]',
+ $role,$url,''.$result.'').' ';
}
$r->print($output);
+ if (!grep(/^\Q$role\E$/,@rolechanges)) {
+ push(@rolechanges,$role);
+ }
}
# Re-enable custom role
if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
my $result = &Apache::lonnet::assigncustomrole(
$env{'form.ccdomain'}, $env{'form.ccuname'},
- $url,$rdom,$rnam,$rolename,0,$now);
- $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : [_5]',
- $rolename,$rnam,$rdom,$url,$result).' ');
+ $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
+ $r->print(&mt('Re-enabling custom role [_1] by [_2]:[_3] in [_4] : [_5]',
+ $rolename,$rnam,$rdom,$url,''.$result.'').' ');
+ if (!grep(/^cr$/,@rolechanges)) {
+ push(@rolechanges,'cr');
+ }
}
- $rolechanges ++;
} elsif ($key=~/^form\.act/) {
my $udom = $env{'form.ccdomain'};
my $uname = $env{'form.ccuname'};
@@ -2175,7 +2518,7 @@ sub update_roles {
my %sections = ();
my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
if ($num_sections == 0) {
- $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
+ $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
} else {
my %curr_groups =
&Apache::longroup::coursegroups($one,$two);
@@ -2186,9 +2529,12 @@ sub update_roles {
next;
}
my $securl = $url.'/'.$sec;
- $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
+ $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
}
}
+ if (!grep(/^cr$/,@rolechanges)) {
+ push(@rolechanges,'cr');
+ }
} elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
# Activate roles for sections with 3 id numbers
# set start, end times, and the url for the class
@@ -2205,7 +2551,7 @@ sub update_roles {
my %sections = ();
my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
if ($num_sections == 0) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
} else {
my %curr_groups =
&Apache::longroup::coursegroups($one,$two);
@@ -2219,15 +2565,18 @@ sub update_roles {
next;
}
my $securl = $url.'/'.$sec;
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
} else {
$emptysec = 1;
}
}
if ($emptysec) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
}
- }
+ }
+ if (!grep(/^\Q$three\E$/,@rolechanges)) {
+ push(@rolechanges,$three);
+ }
} elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
# Activate roles for sections with two id numbers
# set start, end times, and the url for the class
@@ -2237,26 +2586,31 @@ sub update_roles {
my $end = ( $env{'form.end_'.$1.'_'.$2} ?
$env{'form.end_'.$1.'_'.$2} :
0 );
- my $url='/'.$1.'/';
+ my $one = $1;
+ my $two = $2;
+ my $url='/'.$one.'/';
# split multiple sections
my %sections = ();
- my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
+ my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
if ($num_sections == 0) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
} else {
my $emptysec = 0;
foreach my $sec (sort {$a cmp $b} keys %sections) {
if ($sec ne '') {
my $securl = $url.'/'.$sec;
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
} else {
$emptysec = 1;
}
}
if ($emptysec) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
}
}
+ if (!grep(/^\Q$two\E$/,@rolechanges)) {
+ push(@rolechanges,$two);
+ }
} else {
$r->print('
');
}
@@ -2268,19 +2622,18 @@ sub update_roles {
}
$r->print(' '.&mt('Please go back and choose a different section name.').' ');
}
- $rolechanges ++;
}
} # End of foreach (keys(%env))
# Flush the course logs so reverse user roles immediately updated
&Apache::lonnet::flushcourselogs();
- if (!$rolechanges) {
+ if (@rolechanges == 0) {
$r->print(&mt('No roles to modify'));
}
- return $rolechanges;
+ return @rolechanges;
}
sub enroll_single_student {
- my ($r,$uhome,$amode,$genpwd,$now,$newuser) = @_;
+ my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context) = @_;
$r->print('
'.&mt('Enrolling Student').'
');
# Remove non alphanumeric values from section
@@ -2295,7 +2648,7 @@ sub enroll_single_student {
$env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
$env{'form.cmiddlename'},$env{'form.clastname'},
$env{'form.generation'},$env{'form.sections'},$enddate,
- $startdate,'manual',undef,$env{'request.course.id'});
+ $startdate,'manual',undef,$env{'request.course.id'},'',$context);
if ($enroll_result =~ /^ok/) {
$r->print(&mt('[_1] enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
if ($env{'form.sections'} ne '') {
@@ -2369,12 +2722,27 @@ sub quota_admin {
my $quotachanged;
if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
# Current user has quota modification privileges
- $quotachanged = 1;
- $changeHash->{'portfolioquota'} = $setquota;
+ if (ref($changeHash) eq 'HASH') {
+ $quotachanged = 1;
+ $changeHash->{'portfolioquota'} = $setquota;
+ }
}
return $quotachanged;
}
+sub tool_admin {
+ my ($tool,$settool,$changeHash) = @_;
+ my $toolchanged;
+ if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
+ # Current user has quota modification privileges
+ if (ref($changeHash) eq 'HASH') {
+ $toolchanged = 1;
+ $changeHash->{'tools.'.$tool} = $settool;
+ }
+ }
+ return $toolchanged;
+}
+
sub build_roles {
my ($sectionstr,$sections,$role) = @_;
my $num_sections = 0;
@@ -2484,7 +2852,7 @@ sub custom_role_editor {
my @template_roles = ("cc","in","ta","ep","st");
foreach my $role (@template_roles) {
$head_script .= &make_script_template($role);
- $button_code .= &make_button_code($role);
+ $button_code .= &make_button_code($role).' ';
}
$head_script .= "\n".$jsback."\n".''."\n";
$r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
@@ -2504,10 +2872,15 @@ sub custom_role_editor {
'crl' => "Course Level",
'dml' => "Domain Level",
'ssl' => "System Level");
- $r->print('Select a Template ');
- $r->print('');
+
+ $r->print('
'
+ .''
+ .'
'
+ );
+
$r->print(<
@@ -2567,34 +2940,35 @@ sub make_script_template {
my ($priv_item, $dummy) = split(/\&/,$priv);
$role_c{$priv_item} = 1;
}
+ my %role_d;
+ @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
+ foreach my $priv(@temp) {
+ my ($priv_item, $dummy) = split(/\&/,$priv);
+ $role_d{$priv_item} = 1;
+ }
+ my %role_s;
+ @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
+ foreach my $priv(@temp) {
+ my ($priv_item, $dummy) = split(/\&/,$priv);
+ $role_s{$priv_item} = 1;
+ }
foreach my $priv_item (keys(%full_c)) {
my ($priv, $dummy) = split(/\&/,$priv_item);
- if (exists($role_c{$priv})) {
+ if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
+ (exists($role_s{$priv}))) {
$return_script .= "document.form1.$priv"."_c.checked = true;\n";
} else {
$return_script .= "document.form1.$priv"."_c.checked = false;\n";
}
}
- my %role_d;
- @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
- foreach my $priv(@temp) {
- my ($priv_item, $dummy) = split(/\&/,$priv);
- $role_d{$priv_item} = 1;
- }
foreach my $priv_item (keys(%full_d)) {
my ($priv, $dummy) = split(/\&/,$priv_item);
- if (exists($role_d{$priv})) {
+ if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
$return_script .= "document.form1.$priv"."_d.checked = true;\n";
} else {
$return_script .= "document.form1.$priv"."_d.checked = false;\n";
}
}
- my %role_s;
- @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
- foreach my $priv(@temp) {
- my ($priv_item, $dummy) = split(/\&/,$priv);
- $role_s{$priv_item} = 1;
- }
foreach my $priv_item (keys(%full_s)) {
my ($priv, $dummy) = split(/\&/,$priv_item);
if (exists($role_s{$priv})) {
@@ -2610,12 +2984,12 @@ sub make_script_template {
sub make_button_code {
my ($role) = @_;
my $label = &Apache::lonnet::plaintext($role);
- my $button_code = '';
+ my $button_code = '';
return ($button_code);
}
# ---------------------------------------------------------- Call to definerole
sub set_custom_role {
- my ($r) = @_;
+ my ($r,$context) = @_;
my $rolename=$env{'form.rolename'};
$rolename=~s/[^A-Za-z0-9]//gs;
if (!$rolename) {
@@ -2690,7 +3064,7 @@ sub set_custom_role {
$url,
$env{'user.domain'},
$env{'user.name'},
- $rolename));
+ $rolename,undef,undef,undef,$context));
}
$r->print('
';
}
return $menu_html;
@@ -3072,6 +3485,816 @@ sub restore_prev_selections {
\%saveable_parameters);
}
+sub print_selfenroll_menu {
+ my ($r,$context,$permission) = @_;
+ my $formname = 'enrollstudent';
+ my $nolink = 1;
+ my ($row,$lt) = &get_selfenroll_titles();
+ my $groupslist = &Apache::lonuserutils::get_groupslist();
+ my $setsec_js =
+ &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
+ my %alerts = &Apache::lonlocal::texthash(
+ acto => 'Activation of self-enrollment was selected for the following domain(s)',
+ butn => 'but no user types have been checked.',
+ wilf => "Please uncheck 'activate' or check at least one type.",
+ );
+ my $selfenroll_js = <<"ENDSCRIPT";
+function update_types(caller,num) {
+ var delidx = getIndexByName('selfenroll_delete');
+ var actidx = getIndexByName('selfenroll_activate');
+ if (caller == 'selfenroll_all') {
+ var selall;
+ for (var i=0; i 0) {
+ var msg = "$alerts{'acto'}\\n";
+ var loopend = needaction.length -1;
+ if (loopend > 0) {
+ for (var m=0; m'."\n".
+ $setsec_js."\n".$selfenroll_js."\n".
+ ''."\n".
+ '
'.$lt->{'selfenroll'}.'
'."\n";
+ my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
+ if (ref($visactions) eq 'HASH') {
+ if ($visible) {
+ $output .= '
';
+ }
+ $output .= '';
+ }
+ }
+ $output .= '';
+ $r->print($output);
+ return;
+}
+
+sub visible_in_cat {
+ my ($cdom,$cnum) = @_;
+ my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
+ my ($cathash,%settable,@vismsgs,$cansetvis);
+ my %visactions = &Apache::lonlocal::texthash(
+ vis => 'Your course currently appears in the Course Catalog for this domain.',
+ gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.',
+ miss => 'Your course does not currently appear in the Course Catalog for this domain.',
+ yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
+ coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.',
+ make => 'Make any changes to self-enrollment settings below, click "Save changes", then take action to include the course in the Catalog:',
+ take => 'Take the following action to ensure the course appears in the Catalog:',
+ dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
+ dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
+ dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
+ dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
+ dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
+ dc_chgcat => 'Ask a domain coordinator to change the category assigned to the course, as the one currently assigned is no longer used in the domain',
+ dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
+ );
+ $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','"','"');
+ $visactions{'chgcat'} = &mt('Use [_1]Set course environment[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"','"');
+ $visactions{'addcat'} = &mt('Use [_1]Set course environment[_2] to assign a category to the course.','"','"');
+ if (ref($domconf{'coursecategories'}) eq 'HASH') {
+ if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
+ $settable{'togglecats'} = 1;
+ }
+ if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
+ $settable{'categorize'} = 1;
+ }
+ $cathash = $domconf{'coursecategories'}{'cats'};
+ }
+ if ($settable{'togglecats'} && $settable{'categorize'}) {
+ $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
+ } elsif ($settable{'togglecats'}) {
+ $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.');
+ } elsif ($settable{'categorize'}) {
+ $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
+ } else {
+ $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
+ }
+
+ my %currsettings =
+ &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
+ $cdom,$cnum);
+ my $visible = 0;
+ if ($currsettings{'internal.coursecode'} ne '') {
+ if (ref($domconf{'coursecategories'}) eq 'HASH') {
+ $cathash = $domconf{'coursecategories'}{'cats'};
+ if (ref($cathash) eq 'HASH') {
+ if ($cathash->{'instcode::0'} eq '') {
+ push(@vismsgs,'dc_addinst');
+ } else {
+ $visible = 1;
+ }
+ } else {
+ $visible = 1;
+ }
+ } else {
+ $visible = 1;
+ }
+ } else {
+ if (ref($cathash) eq 'HASH') {
+ if ($cathash->{'instcode::0'} ne '') {
+ push(@vismsgs,'dc_instcode');
+ }
+ } else {
+ push(@vismsgs,'dc_instcode');
+ }
+ }
+ if ($currsettings{'categories'} ne '') {
+ my $cathash;
+ if (ref($domconf{'coursecategories'}) eq 'HASH') {
+ $cathash = $domconf{'coursecategories'}{'cats'};
+ if (ref($cathash) eq 'HASH') {
+ if (keys(%{$cathash}) == 0) {
+ push(@vismsgs,'dc_catalog');
+ } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
+ push(@vismsgs,'dc_categories');
+ } else {
+ my @currcategories = split('&',$currsettings{'categories'});
+ my $matched = 0;
+ foreach my $cat (@currcategories) {
+ if ($cathash->{$cat} ne '') {
+ $visible = 1;
+ $matched = 1;
+ last;
+ }
+ }
+ if (!$matched) {
+ if ($settable{'categorize'}) {
+ push(@vismsgs,'chgcat');
+ } else {
+ push(@vismsgs,'dc_chgcat');
+ }
+ }
+ }
+ }
+ }
+ } else {
+ if (ref($cathash) eq 'HASH') {
+ if ((keys(%{$cathash}) > 1) ||
+ (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
+ if ($settable{'categorize'}) {
+ push(@vismsgs,'addcat');
+ } else {
+ push(@vismsgs,'dc_addcat');
+ }
+ }
+ }
+ }
+ if ($currsettings{'hidefromcat'} eq 'yes') {
+ $visible = 0;
+ if ($settable{'togglecats'}) {
+ unshift(@vismsgs,'unhide');
+ } else {
+ unshift(@vismsgs,'dc_unhide')
+ }
+ }
+ return ($visible,$cansetvis,\@vismsgs,\%visactions);
+}
+
+sub new_selfenroll_dom_row {
+ my ($newdom,$num) = @_;
+ my $domdesc = &Apache::lonnet::domain($newdom);
+ my $output;
+ if ($domdesc ne '') {
+ $output .= &Apache::loncommon::start_data_table_row()
+ .'
';
+ my $startform =
+ &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
+ $curr->{'rolelog_start_date'},undef,
+ undef,undef,undef,undef,undef,undef,$nolink);
+ my $endform =
+ &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
+ $curr->{'rolelog_end_date'},undef,
+ undef,undef,undef,undef,undef,undef,$nolink);
+ my %lt = &rolechg_contexts();
+ $output .= '
'.&mt('Window during which changes occurred:').'
'.&mt('After:').
+ '
'.$startform.'
'.&mt('Before:').'
'.
+ $endform.'
'.
+ '
'.&mt('Role:').' '.
+ '
'.
+ &mt('Context:').'
'.
+ ''.
+ &mt('[_1]Note:[_2] Only changes made from servers running LON-CAPA 2.6.99.0 or later are displayed.');
+ if ($version) {
+ $output .= ' '.&mt('This server is version [_3].','','',$version); }
+ $output .= ' ';
+ return $output;
+}
+
+sub rolechg_contexts {
+ my %lt = &Apache::lonlocal::texthash (
+ any => 'Any',
+ auto => 'Automated enrollment',
+ updatenow => 'Roster Update',
+ createcourse => 'Course Creation',
+ course => 'User Management in course',
+ domain => 'User Management in domain',
+ selfenroll => 'Self-enrolled',
+ );
+ return %lt;
+}
+
#-------------------------------------------------- functions for &phase_two
sub user_search_result {
my ($context,$srch) = @_;
@@ -3104,7 +4327,13 @@ sub user_search_result {
if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
($srch->{'srchin'} eq 'alc')) {
if ($srch->{'srchby'} eq 'uname') {
- if ($srch->{'srchterm'} !~ /^$match_username$/) {
+ my $unamecheck = $srch->{'srchterm'};
+ if ($srch->{'srchtype'} eq 'contains') {
+ if ($unamecheck !~ /^\w/) {
+ $unamecheck = 'a'.$unamecheck;
+ }
+ }
+ if ($unamecheck !~ /^$match_username$/) {
$response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
}
}
@@ -3313,11 +4542,15 @@ sub directorysrch_check {
my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
my @longtypes;
foreach my $item (@usertypes) {
- push (@longtypes,$insttypes->{$item});
+ if (defined($insttypes->{$item})) {
+ push (@longtypes,$insttypes->{$item});
+ } elsif ($item eq 'default') {
+ push (@longtypes,&mt('other'));
+ }
}
my $insttype_str = join(', ',@longtypes);
return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
- }
+ }
} else {
$can_search = 1;
}
@@ -3438,10 +4671,30 @@ sub build_search_response {
&Apache::lonuserutils::can_create_user($env{'request.role.domain'},$context);
if ($cancreate) {
my $showdom = &display_domain_info($env{'request.role.domain'});
- $response .= '
'.&mt("To add a new user (you can only create new users in your current role's domain - [_1]):",$env{'request.role.domain'}).'
'.&mt("Set 'Domain/institution to search' to: [_1]",$showdom).'
'.&mt("Set 'Search criteria' to: 'username is ...... in selected LON-CAPA domain'").'
'.&mt('Provide the proposed username').'
'.&mt('Search').'
';
+ $response .= '
'
+ .''.&mt('To add a new user:').''
+ .' '
+ .&mt("(You can only create new users in your current role's domain - [_1])"
+ ,''.$env{'request.role.domain'}.'')
+ .'
'
+ .&mt("Set 'Domain/institution to search' to: [_1]",''.$showdom.'')
+ .'
'
+ .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'','')
+ .'
'.&mt("You are not authorized to create new users in your current role's domain - [_1].",$env{'request.role.domain'}).' '.&mt('Contact the helpdesk if you need to create a new user.',$helplink).'
';
+ $response .= '
'
+ .&mt("You are not authorized to create new users in your current role's domain - [_1]."
+ ,''.$env{'request.role.domain'}.'')
+ .' '
+ .&mt('Contact the [_1]helpdesk[_2] if you need to create a new user.'
+ ,' '
+ ,'')
+ .'
');
+ my %newenvhash;
+ foreach my $key (keys(%changes)) {
+ $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
+ }
+ &Apache::lonnet::appenv(\%newenvhash);
+ } else {
+ $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').' '.&mt('The error was: [_1].',$putresult));
+ }
+ } else {
+ $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
+ }
+ } else {
+ $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
+ }
+ my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
+ if (ref($visactions) eq 'HASH') {
+ if (!$visible) {
+ $r->print(' '.$visactions->{'miss'}.' '.$visactions->{'yous'}.
+ ' ');
+ if (ref($vismsgs) eq 'ARRAY') {
+ $r->print(' '.$visactions->{'take'}.'
');
+ foreach my $item (@{$vismsgs}) {
+ $r->print('
'.$visactions->{$item}.'
');
+ }
+ $r->print('
');
+ }
+ $r->print($cansetvis);
+ }
+ }
+ return;
+}
+
+sub get_selfenroll_titles {
+ my @row = ('types','registered','enroll_dates','access_dates','section');
+ my %lt = &Apache::lonlocal::texthash (
+ types => 'Users allowed to self-enroll in this course',
+ registered => 'Restrict self-enrollment to students officially registered for the course',
+ enroll_dates => 'Dates self-enrollment available',
+ access_dates => 'Course access dates assigned to self-enrolling users',
+ section => 'Section assigned to self-enrolling users',
+ );
+ return (\@row,\%lt);
+}
+
#---------------------------------------------- end functions for &phase_two
#--------------------------------- functions for &phase_two and &phase_three