version 1.17, 2007/12/21 12:41:25
|
version 1.20, 2007/12/21 17:27:57
|
Line 3810 sub can_create_user {
|
Line 3810 sub can_create_user {
|
return $cancreate; |
return $cancreate; |
} |
} |
|
|
|
sub can_modify_userinfo { |
|
my ($context,$dom,$fields,$userroles) = @_; |
|
my %domconfig = |
|
&Apache::lonnet::get_dom('configuration',['usermodification'], |
|
$dom); |
|
my %canmodify; |
|
if (ref($fields) eq 'ARRAY') { |
|
foreach my $field (@{$fields}) { |
|
$canmodify{$field} = 0; |
|
if (&Apache::lonnet::allowed('mau',$dom)) { |
|
$canmodify{$field} = 1; |
|
} else { |
|
if (ref($domconfig{'usermodification'}) eq 'HASH') { |
|
if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') { |
|
if (ref($userroles) eq 'ARRAY') { |
|
foreach my $role (@{$userroles}) { |
|
my $testrole; |
|
if ($role =~ /^cr\//) { |
|
$testrole = 'cr'; |
|
} else { |
|
$testrole = $role; |
|
} |
|
if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') { |
|
if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) { |
|
$canmodify{$field} = 1; |
|
last; |
|
} |
|
} |
|
} |
|
} else { |
|
foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) { |
|
if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') { |
|
if ($domconfig{'usermodification'}{$context}{$key}{$field}) { |
|
$canmodify{$field} = 1; |
|
last; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} elsif ($context eq 'course') { |
|
if (ref($userroles) eq 'ARRAY') { |
|
if (grep(/^st$/,@{$userroles})) { |
|
$canmodify{$field} = 1; |
|
} |
|
} else { |
|
$canmodify{$field} = 1; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return %canmodify; |
|
} |
|
|
|
sub check_usertype { |
|
my ($dom,$uname,$rules) = @_; |
|
my $usertype; |
|
if (ref($rules) eq 'HASH') { |
|
my @user_rules = keys(%{$rules}); |
|
if (@user_rules > 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 { |
sub roles_by_context { |
my ($context,$custom) = @_; |
my ($context,$custom) = @_; |
my @allroles; |
my @allroles; |
Line 3919 sub get_course_identity {
|
Line 3995 sub get_course_identity {
|
return ($cnum,$cdom,$cdesc); |
return ($cnum,$cdom,$cdesc); |
} |
} |
|
|
|
sub dc_setcourse_js { |
|
my ($formname,$mode) = @_; |
|
my $dc_setcourse_code; |
|
my $cctext = &Apache::lonnet::plaintext('cc'); |
|
my %alerts = §ioncheck_alerts(); |
|
my $role = 'role'; |
|
if ($mode eq 'upload') { |
|
$role = 'courserole'; |
|
} |
|
$dc_setcourse_code = (<<"SCRIPTTOP"); |
|
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<document.$formname.currsec.length; i++) { |
|
if (document.$formname.currsec.options[i].selected == true ) { |
|
if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) { |
|
if (numsections == 0) { |
|
section = document.$formname.currsec.options[i].value |
|
numsections = 1; |
|
} |
|
else { |
|
section = section + "," + document.$formname.currsec.options[i].value |
|
numsections ++; |
|
} |
|
} |
|
} |
|
} |
|
if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) { |
|
if (numsections == 0) { |
|
section = document.$formname.newsec.value |
|
} |
|
else { |
|
section = section + "," + document.$formname.newsec.value |
|
} |
|
newsecs = document.$formname.newsec.value.split(/,/g); |
|
numsections = numsections + newsecs.length; |
|
} |
|
if ((userrole == 'st') && (numsections > 1)) { |
|
alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.") |
|
return; |
|
} |
|
for (var j=0; j<newsecs.length; j++) { |
|
if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) { |
|
alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}."); |
|
return; |
|
} |
|
if (document.$formname.groups.value != '') { |
|
var groups = document.$formname.groups.value.split(/,/g); |
|
for (var k=0; k<groups.length; k++) { |
|
if (newsecs[j] == groups[k]) { |
|
alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}."); |
|
return; |
|
} |
|
} |
|
} |
|
} |
|
if ((userrole == 'cc') && (numsections > 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 |
|
} |
|
} |
|
} |
|
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<document.$formname.elements.length;i++) { |
|
if (document.$formname.elements[i] == caller) { |
|
return i; |
|
} |
|
} |
|
return -1; |
|
} |
|
ENDSCRIPT |
|
} |
|
|
|
sub sectioncheck_alerts { |
|
my %alerts = &Apache::lonlocal::texthash( |
|
curd => '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; |
|
} |
|
|
|
|
1; |
1; |