'.&mt('Change authentication for existing users to these settings?').'
';
+ $Str .= '
'.&mt('Change authentication for existing users in domain "[_1]" to these settings?',$defdom).'
';
} else {
$Str .= "
\n".
- &mt('Note: this will not take effect if the user already exists').
+ &mt('Note: This will not take effect if the user already exists.').
&Apache::loncommon::help_open_topic('Auth_Options').
"
'."\n".
&mt('Pick the action to take on roles for these users:').' ';
}
- if ($context eq 'construction_space') {
+ if ($context eq 'author') {
$Str .= '
'.&mt('Default role')."
\n".
- &mt('Choose the role to assign to users without one specified in the uploaded file');
+ &mt('Choose the role to assign to users without a value specified in the uploaded file');
} elsif ($context eq 'course') {
$Str .= '
'.&mt('Default role and section')."
\n".
- &mt('Choose the role and/or section to assign to users without one specified in the uploaded file');
+ &mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file');
} else {
- $Str .= '
'.&mt('Default role and/or section')." \n".
- &mt('Role and/or section for users without one in the uploaded file.');
+ $Str .= '
'.&mt('Default role and/or section(s)')." \n".
+ &mt('Role and/or section(s) for users without values specified in the uploaded file.');
}
- $Str .= '
';
- my ($options,$cb_script,$coursepick) = &default_role_selector($context,'defaultrole',1);
- if ($context eq 'domain') {
- $Str .= ''.&mt('Domain Level').' '.$options.'
\n");
+ "\n".''.&mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.').''."\n");
+ if ($env{'form.coursepick'}) {
+ $r->print(''.&mt('Searching').' ...
';
$str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
&mt("How do I create a users list from a spreadsheet")).
" \n";
$str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
- &mt("How do I create a CSV file from a spreadsheet")).
- " \n";
+ &mt("How do I create a CSV file from a spreadsheet"));
+ $str .= "
\n";
+ $str .= "
\n";
+ $str .= ' '.
+ &mt('Ignore First Line')."
\n";
+ $str .= ''." \n";
$str .= &Apache::loncommon::end_page();
$r->print($str);
return;
@@ -2289,7 +3437,7 @@ sub print_first_users_upload_form {
# ================================================= 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);}
@@ -2304,10 +3452,14 @@ sub upfile_drop_add {
$fields{$env{'form.f'.$i}}=$keyfields[$i];
}
}
+ if ($env{'form.fullup'} ne 'yes') {
+ $r->print('
\n");
+ } else {
+ $r->print('
'.&mt('No roles added').'
');
}
if ($counts{'auth'} > 0) {
$r->print("
\n".
&mt('Authentication changed for [_1] existing users.',
$counts{'auth'})."
\n");
}
- $r->print('');
+ $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
#####################################
- # Drop students #
+ # Display list of students to drop #
#####################################
if ($env{'form.fullup'} eq 'yes') {
- $r->print('
'.&mt('Dropping Students')."
\n");
+ $r->print('
'.&mt('Students to Drop')."
\n");
# Get current classlist
- my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+ my $classlist = &Apache::loncoursedata::get_classlist();
if (! defined($classlist)) {
- $r->print(&mt('There are no students currently enrolled.').
- "\n");
- } else {
+ $r->print(''.
+ ''.
+ &mt('There are no students with current/future access to the course.').
+ ''."\n");
+ } elsif (ref($classlist) eq 'HASH') {
# Remove the students we just added from the list of students.
- foreach (@userdata) {
- my %entries=&Apache::loncommon::record_sep($_);
+ foreach my $line (@userdata) {
+ my %entries=&Apache::loncommon::record_sep($line);
unless (($entries{$fields{'username'}} eq '') ||
(!defined($entries{$fields{'username'}}))) {
delete($classlist->{$entries{$fields{'username'}}.
@@ -2603,21 +3996,64 @@ sub upfile_drop_add {
}
}
# Print out list of dropped students.
- &show_drop_list($r,$classlist,$keylist,'nosort');
+ &show_drop_list($r,$classlist,'nosort',$permission);
}
}
} # end of unless
+ if ($env{'form.fullup'} ne 'yes') {
+ $r->print('');
+ }
+}
+
+sub print_namespacing_alerts {
+ my ($domain,$alerts,$curr_rules) = @_;
+ my $output;
+ if (ref($alerts) eq 'HASH') {
+ if (keys(%{$alerts}) > 0) {
+ if (ref($alerts->{'username'}) eq 'HASH') {
+ foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
+ my $count;
+ if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
+ $count = keys(%{$alerts->{'username'}{$dom}});
+ }
+ my $domdesc = &Apache::lonnet::domain($domain,'description');
+ if (ref($curr_rules->{$dom}) eq 'HASH') {
+ $output .= &Apache::loncommon::instrule_disallow_msg(
+ 'username',$domdesc,$count,'upload');
+ }
+ $output .= &Apache::loncommon::user_rule_formats($dom,
+ $domdesc,$curr_rules->{$dom}{'username'},
+ 'username');
+ }
+ }
+ if (ref($alerts->{'id'}) eq 'HASH') {
+ foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
+ my $count;
+ if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
+ $count = keys(%{$alerts->{'id'}{$dom}});
+ }
+ my $domdesc = &Apache::lonnet::domain($domain,'description');
+ if (ref($curr_rules->{$dom}) eq 'HASH') {
+ $output .= &Apache::loncommon::instrule_disallow_msg(
+ 'id',$domdesc,$count,'upload');
+ }
+ $output .= &Apache::loncommon::user_rule_formats($dom,
+ $domdesc,$curr_rules->{$dom}{'id'},'id');
+ }
+ }
+ }
+ }
}
sub user_change_result {
- my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username,
- $userchg) = @_;
+ my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
+ $username,$userdomain,$userchg) = @_;
my $okresult = 0;
if ($userresult ne 'ok') {
if ($userresult =~ /^error:(.+)$/) {
my $error = $1;
$r->print(' '.
- &mt('[_1]: Unable to add/modify: [_2]',$username,$error));
+ &mt('[_1]: Unable to add/modify: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'user'} ++;
@@ -2627,7 +4063,7 @@ sub user_change_result {
if ($authresult =~ /^error:(.+)$/) {
my $error = $1;
$r->print(' '.
- &mt('[_1]: Unable to modify authentication: [_2]',$username,$error));
+ &mt('[_1]: Unable to modify authentication: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'auth'} ++;
@@ -2637,7 +4073,7 @@ sub user_change_result {
if ($roleresult =~ /^error:(.+)$/) {
my $error = $1;
$r->print(' '.
- &mt('[_1]: Unable to add role: [_2]',$username,$error));
+ &mt('[_1]: Unable to add role: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'role'} ++;
@@ -2645,64 +4081,311 @@ sub user_change_result {
}
if ($okresult) {
$flushc++;
- $userchg->{$username}=1;
+ $userchg->{$username.':'.$userdomain}=1;
$r->print('. ');
if ($flushc>15) {
$r->rflush;
$flushc=0;
}
}
+ if ($idresult) {
+ $r->print($idresult);
+ }
return $flushc;
}
# ========================================================= Menu Phase Two Drop
-sub print_expire_menu {
- my ($r,$context) = @_;
- $r->print("
".&mt("Expire Users' Roles")."
");
- my $cid=$env{'request.course.id'};
- my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
+sub print_drop_menu {
+ my ($r,$context,$permission) = @_;
+ $r->print('
'.&mt("Drop Students").'
'."\n".
+ ''. &Apache::loncommon::end_page());
return;
}
-
# ================================================================== Phase four
-sub expire_user_list {
- my ($r,$context) = @_;
+sub update_user_list {
+ my ($r,$context,$setting,$choice) = @_;
+ my $now = time;
my $count=0;
- my @droplist = &Apache::loncommon::get_env_multiple('form.droplist');
- foreach (@droplist) {
- my ($uname,$udom)=split(/\:/,$_);
- # drop student
- my $result = &modifystudent($udom,$uname,$env{'request.course.id'});
+ my @changelist;
+ if ($choice eq 'drop') {
+ @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
+ } else {
+ @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
+ }
+ my %result_text = ( ok => { 'revoke' => 'Revoked',
+ 'delete' => 'Deleted',
+ 'reenable' => 'Re-enabled',
+ 'activate' => 'Activated',
+ 'chgdates' => 'Changed Access Dates for',
+ 'chgsec' => 'Changed section for',
+ 'drop' => 'Dropped',
+ },
+ error => {'revoke' => 'revoking',
+ 'delete' => 'deleting',
+ 'reenable' => 're-enabling',
+ 'activate' => 'activating',
+ 'chgdates' => 'changing access dates for',
+ 'chgsec' => 'changing section for',
+ 'drop' => 'dropping',
+ },
+ );
+ my ($startdate,$enddate);
+ if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
+ ($startdate,$enddate) = &get_dates_from_form();
+ }
+ foreach my $item (@changelist) {
+ my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
+ $scopestem);
+ if ($choice eq 'drop') {
+ ($uname,$udom,$sec) = split(/:/,$item,-1);
+ $role = 'st';
+ $cid = $env{'request.course.id'};
+ $scopestem = '/'.$cid;
+ $scopestem =~s/\_/\//g;
+ if ($sec eq '') {
+ $scope = $scopestem;
+ } else {
+ $scope = $scopestem.'/'.$sec;
+ }
+ } elsif ($context eq 'course') {
+ ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
+ $cid = $env{'request.course.id'};
+ $scopestem = '/'.$cid;
+ $scopestem =~s/\_/\//g;
+ if ($sec eq '') {
+ $scope = $scopestem;
+ } else {
+ $scope = $scopestem.'/'.$sec;
+ }
+ } elsif ($context eq 'author') {
+ ($uname,$udom,$role) = split(/\:/,$item,-1);
+ $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
+ } elsif ($context eq 'domain') {
+ if ($setting eq 'domain') {
+ ($role,$uname,$udom) = split(/\:/,$item,-1);
+ $scope = '/'.$env{'request.role.domain'}.'/';
+ } elsif ($setting eq 'author') {
+ ($uname,$udom,$role,$scope) = split(/\:/,$item);
+ } elsif ($setting eq 'course') {
+ ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
+ split(/\:/,$item);
+ $scope = '/'.$cid;
+ $scope =~s/\_/\//g;
+ if ($sec ne '') {
+ $scope .= '/'.$sec;
+ }
+ }
+ }
+ my $plrole = &Apache::lonnet::plaintext($role);
+ my $start = $env{'form.'.$item.'_start'};
+ my $end = $env{'form.'.$item.'_end'};
+ if ($choice eq 'drop') {
+ # drop students
+ $end = $now;
+ $type = 'manual';
+ $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ } elsif ($choice eq 'revoke') {
+ # revoke or delete user role
+ $end = $now;
+ if ($role eq 'st') {
+ $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ } else {
+ $result =
+ &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
+ '','',$context);
+ }
+ } elsif ($choice eq 'delete') {
+ if ($role eq 'st') {
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context);
+ }
+ $result =
+ &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
+ $start,1,'',$context);
+ } else {
+ #reenable, activate, change access dates or change section
+ if ($choice ne 'chgsec') {
+ $start = $startdate;
+ $end = $enddate;
+ }
+ if ($choice eq 'reenable') {
+ if ($role eq 'st') {
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ } else {
+ $result =
+ &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
+ $now,'','',$context);
+ }
+ } elsif ($choice eq 'activate') {
+ if ($role eq 'st') {
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ } else {
+ $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
+ $now,'','',$context);
+ }
+ } elsif ($choice eq 'chgdates') {
+ if ($role eq 'st') {
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ } else {
+ $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
+ $start,'','',$context);
+ }
+ } elsif ($choice eq 'chgsec') {
+ my (@newsecs,$revresult,$nochg,@retained);
+ if ($role ne 'cc') {
+ @newsecs = split(/,/,$env{'form.newsecs'});
+ }
+ # remove existing section if not to be retained.
+ if (!$env{'form.retainsec'}) {
+ if ($sec eq '') {
+ if (@newsecs == 0) {
+ $result = &mt('No change in section assignment (none)');
+ $nochg = 1;
+ } else {
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role,
+ '','',$context);
+ }
+ } else {
+ if (@newsecs > 0) {
+ if (grep(/^\Q$sec\E$/,@newsecs)) {
+ push(@retained,$sec);
+ } else {
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role,
+ '','',$context);
+ }
+ } else {
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role,
+ '','',$context);
+ }
+ }
+ } else {
+ if ($sec eq '') {
+ $nochg = 1;
+ } else {
+ push(@retained,$sec);
+ }
+ }
+ # add new sections
+ if (@newsecs == 0) {
+ if (!$nochg) {
+ if ($role eq 'st') {
+ $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
+ } else {
+ my $newscope = $scopestem;
+ $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
+ }
+ }
+ } else {
+ foreach my $newsec (@newsecs) {
+ if (!grep(/^\Q$newsec\E$/,@retained)) {
+ if ($role eq 'st') {
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
+ } else {
+ my $newscope = $scopestem;
+ if ($newsec ne '') {
+ $newscope .= '/'.$newsec;
+ }
+ $result = &Apache::lonnet::assignrole($udom,$uname,
+ $newscope,$role,$end,$start);
+ }
+ }
+ }
+ }
+ }
+ }
+ my $extent = $scope;
+ if ($choice eq 'drop' || $context eq 'course') {
+ my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
+ if ($cdesc) {
+ $extent = $cdesc;
+ }
+ }
if ($result eq 'ok' || $result eq 'ok:') {
- $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).' ');
+ $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
+ $plrole,$extent,$uname.':'.$udom).' ');
$count++;
} else {
$r->print(
- &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
- ' ');
+ &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",
+ $plrole,$extent,$uname.':'.$udom,$result).' ');
+ }
+ }
+ $r->print(''."\n");
}
-sub section_check_js {
- my $groupslist;
- my %curr_groups = &Apache::longroup::coursegroups();
- if (%curr_groups) {
- $groupslist = join('","',sort(keys(%curr_groups)));
+sub classlist_drop {
+ my ($scope,$uname,$udom,$now) = @_;
+ my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
+ if (&Apache::lonnet::is_course($cdom,$cnum)) {
+ if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
+ my %user;
+ my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
+ return &mt('Drop from classlist: [_1]',
+ ''.$result.'').' ';
+ }
}
+}
+
+sub active_student_roles {
+ my ($cnum,$cdom,$uname,$udom) = @_;
+ my %roles =
+ &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
+ ['future','active'],['st']);
+ return exists($roles{"$cnum:$cdom:st"});
+}
+
+sub section_check_js {
+ my $groupslist= &get_groupslist();
return <<"END";
function validate(caller) {
- var groups = new Array("$groupslist");
+ var groups = new Array($groupslist);
var secname = caller.value;
if ((secname == 'all') || (secname == 'none')) {
alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
@@ -2749,5 +4432,644 @@ sub set_login {
return $response;
}
+sub course_sections {
+ my ($sections_count,$role,$current_sec) = @_;
+ my $output = '';
+ my @sections = (sort {$a <=> $b} keys %{$sections_count});
+ my $numsec = scalar(@sections);
+ my $is_selected = ' selected="selected" ';
+ if ($numsec <= 1) {
+ $output = ''."\n".
+ ' '."\n";
+ if ($current_sec eq 'none') {
+ $output .=
+ ' '."\n";
+ } else {
+ $output .=
+ ' '."\n";
+ }
+ if ($numsec == 1) {
+ if ($current_sec eq $sections[0]) {
+ $output .=
+ ' '."\n";
+ } else {
+ $output .=
+ ' '."\n";
+ }
+ }
+ } else {
+ $output = ''.&mt('Select').''."\n";
+ if ($current_sec eq 'none') {
+ $output .=
+ ' \n";
+ } else {
+ $output .=
+ ' \n";
+ }
+ } else {
+ $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
+ }
+ foreach my $sec (@sections) {
+ if ($current_sec eq $sec) {
+ $output .= '\n";
+ } else {
+ $output .= '\n";
+ }
+ }
+ }
+ $output .= '';
+ return $output;
+}
+
+sub get_groupslist {
+ my $groupslist;
+ my %curr_groups = &Apache::longroup::coursegroups();
+ if (%curr_groups) {
+ $groupslist = join('","',sort(keys(%curr_groups)));
+ $groupslist = '"'.$groupslist.'"';
+ }
+ return $groupslist;
+}
+
+sub setsections_javascript {
+ my ($formname,$groupslist,$mode,$checkauth) = @_;
+ my ($checkincluded,$finish,$rolecode,$setsection_js);
+ if ($mode eq 'upload') {
+ $checkincluded = 'formname.name == "'.$formname.'"';
+ $finish = "return 'ok';";
+ $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
+ } elsif ($formname eq 'cu') {
+ $checkincluded = 'formname.elements[i-1].checked == true';
+ if ($checkauth) {
+ $finish = "var authcheck = auth_check();\n".
+ " if (authcheck == 'ok') {\n".
+ " formname.submit();\n".
+ " }\n";
+ } else {
+ $finish = 'formname.submit()';
+ }
+ $rolecode = "var match = str.split('_');
+ var role = match[3];\n";
+ } elsif ($formname eq 'enrollstudent') {
+ $checkincluded = 'formname.name == "'.$formname.'"';
+ if ($checkauth) {
+ $finish = "var authcheck = auth_check();\n".
+ " if (authcheck == 'ok') {\n".
+ " formname.submit();\n".
+ " }\n";
+ } else {
+ $finish = 'formname.submit()';
+ }
+ $rolecode = "var match = str.split('_');
+ var role = match[1];\n";
+ } else {
+ $checkincluded = 'formname.name == "'.$formname.'"';
+ $finish = "seccheck = 'ok';";
+ $rolecode = "var match = str.split('_');
+ var role = match[1];\n";
+ $setsection_js = "var seccheck = 'alert';";
+ }
+ my %alerts = &Apache::lonlocal::texthash(
+ secd => 'Section designations do not apply to Course Coordinator roles.',
+ accr => 'A course 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.',
+ youh => 'You had selected ',
+ secs => 'sections.',
+ plmo => '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.',
+ plch => 'Please choose a different section name.',
+ mnot => 'may not be used as a section name, as it is the name of a course group.',
+ secn => 'Section names and group names must be distinct. Please choose a different section name.',
+ );
+ $setsection_js .= <<"ENDSECCODE";
+
+function setSections(formname) {
+ var re1 = /^currsec_/;
+ var groups = new Array($groupslist);
+ for (var i=0;i 0) {
+ if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
+ sections = sections + "," + formname.elements[i+1].value;
+ }
+ }
+ else {
+ sections = formname.elements[i+1].value;
+ }
+ var newsecs = formname.elements[i+1].value;
+ var numsplit;
+ if (newsecs != null && newsecs != "") {
+ numsplit = newsecs.split(/,/g);
+ numsec = numsec + numsplit.length;
+ }
+
+ if ((role == 'st') && (numsec > 1)) {
+ alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
+ return;
+ }
+ else {
+ if (numsplit != null) {
+ for (var j=0; j 0) {
+ my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
+ if (keys(%rule_check) > 0) {
+ $usertype = 'unofficial';
+ foreach my $item (keys(%rule_check)) {
+ if ($rule_check{$item}) {
+ $usertype = 'official';
+ last;
+ }
+ }
+ }
+ }
+ }
+ return $usertype;
+}
+
+sub roles_by_context {
+ my ($context,$custom) = @_;
+ my @allroles;
+ if ($context eq 'course') {
+ @allroles = ('st','ad','ta','ep','in','cc');
+ if ($custom) {
+ push(@allroles,'cr');
+ }
+ } elsif ($context eq 'author') {
+ @allroles = ('ca','aa');
+ } elsif ($context eq 'domain') {
+ @allroles = ('li','dg','sc','au','dc');
+ }
+ return @allroles;
+}
+
+sub get_permission {
+ my ($context,$roles) = @_;
+ my %permission;
+ if ($context eq 'course') {
+ my $custom = 1;
+ my @allroles = &roles_by_context($context,$custom);
+ foreach my $role (@allroles) {
+ if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
+ $permission{'cusr'} = 1;
+ last;
+ }
+ }
+ if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
+ $permission{'custom'} = 1;
+ }
+ if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
+ $permission{'view'} = 1;
+ }
+ if (!$permission{'view'}) {
+ my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
+ $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
+ if ($permission{'view'}) {
+ $permission{'view_section'} = $env{'request.course.sec'};
+ }
+ }
+ if (!$permission{'cusr'}) {
+ if ($env{'request.course.sec'} ne '') {
+ my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
+ $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
+ if ($permission{'cusr'}) {
+ $permission{'cusr_section'} = $env{'request.course.sec'};
+ }
+ }
+ }
+ if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
+ $permission{'grp_manage'} = 1;
+ }
+ } elsif ($context eq 'author') {
+ $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
+ $permission{'view'} = $permission{'cusr'};
+ } else {
+ my @allroles = &roles_by_context($context);
+ foreach my $role (@allroles) {
+ if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
+ $permission{'cusr'} = 1;
+ last;
+ }
+ }
+ if (!$permission{'cusr'}) {
+ if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
+ $permission{'cusr'} = 1;
+ }
+ }
+ if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
+ $permission{'custom'} = 1;
+ }
+ $permission{'view'} = $permission{'cusr'};
+ }
+ my $allowed = 0;
+ foreach my $perm (values(%permission)) {
+ if ($perm) { $allowed=1; last; }
+ }
+ return (\%permission,$allowed);
+}
+
+# ==================================================== Figure out author access
+
+sub authorpriv {
+ my ($auname,$audom)=@_;
+ unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
+ || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
+}
+
+sub roles_on_upload {
+ my ($context,$setting,%customroles) = @_;
+ my (@possible_roles,@permitted_roles);
+ @possible_roles = &curr_role_permissions($context,$setting,1);
+ foreach my $role (@possible_roles) {
+ if ($role eq 'cr') {
+ push(@permitted_roles,keys(%customroles));
+ } else {
+ push(@permitted_roles,$role);
+ }
+ }
+ return @permitted_roles;
+}
+
+sub get_course_identity {
+ my ($cid) = @_;
+ my ($cnum,$cdom,$cdesc);
+ if ($cid eq '') {
+ $cid = $env{'request.course.id'}
+ }
+ if ($cid ne '') {
+ $cnum = $env{'course.'.$cid.'.num'};
+ $cdom = $env{'course.'.$cid.'.domain'};
+ $cdesc = $env{'course.'.$cid.'.description'};
+ if ($cnum eq '' || $cdom eq '') {
+ my %coursehash =
+ &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
+ $cdom = $coursehash{'domain'};
+ $cnum = $coursehash{'num'};
+ $cdesc = $coursehash{'description'};
+ }
+ }
+ return ($cnum,$cdom,$cdesc);
+}
+
+sub dc_setcourse_js {
+ my ($formname,$mode,$context) = @_;
+ my ($dc_setcourse_code,$authen_check);
+ my $cctext = &Apache::lonnet::plaintext('cc');
+ my %alerts = §ioncheck_alerts();
+ my $role = 'role';
+ if ($mode eq 'upload') {
+ $role = 'courserole';
+ } else {
+ $authen_check = &verify_authen($formname,$context);
+ }
+ $dc_setcourse_code = (<<"SCRIPTTOP");
+$authen_check
+
+function setCourse() {
+ var course = document.$formname.dccourse.value;
+ if (course != "") {
+ if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
+ alert("$alerts{'curd'}");
+ return;
+ }
+ var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
+ var section="";
+ var numsections = 0;
+ var newsecs = new Array();
+ for (var i=0; i 1)) {
+ alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+ return;
+ }
+ for (var j=0; j 0)) {
+ alert("$alerts{'secd'} $cctext $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'}");
+ return;
+ }
+ else {
+ document.$formname.elements[numcourse].name = "act"+coursename;
+ var numnewsec = getIndex(document.$formname.newsec);
+ if (numnewsec != "-1") {
+ document.$formname.elements[numnewsec].name = "sec"+coursename;
+ document.$formname.elements[numnewsec].value = section;
+ }
+ var numstart = getIndex(document.$formname.start);
+ if (numstart != "-1") {
+ document.$formname.elements[numstart].name = "start"+coursename;
+ }
+ var numend = getIndex(document.$formname.end);
+ if (numend != "-1") {
+ document.$formname.elements[numend].name = "end"+coursename
+ }
+ }
+ }
+ var authcheck = auth_check();
+ if (authcheck == 'ok') {
+ document.$formname.submit();
+ }
+}
+ENDSCRIPT
+ } else {
+ $dc_setcourse_code .= "
+ document.$formname.sections.value = section;
+ }
+ return 'ok';
+}
+";
+ }
+ $dc_setcourse_code .= (<<"ENDSCRIPT");
+
+ function getIndex(caller) {
+ for (var i=0;i 0) {
+ var loginpicked = 0;
+ for (var i=0; i 'You must select a course in the current domain',
+ inea => 'In each course, each user may only have one student 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',
+ 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'
+ );
+ return %alerts;
+}
+
+sub authcheck_alerts {
+ my %alerts =
+ &Apache::lonlocal::texthash(
+ authen => 'You must choose an authentication type.',
+ krb => 'You need to specify the Kerberos domain.',
+ ipass => 'You need to specify the initial password.',
+ );
+ return %alerts;
+}
+
1;