--- loncom/interface/lonuserutils.pm 2007/12/21 14:05:40 1.18 +++ loncom/interface/lonuserutils.pm 2007/12/21 20:34:26 1.21 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.18 2007/12/21 14:05:40 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 forceid_change { ############################################################### ############################################################### sub print_upload_manager_form { - my ($r,$context) = @_; + my ($r,$context,$permission) = @_; my $firstLine; my $datatoken; if (!$env{'form.datatoken'}) { @@ -2423,7 +2423,7 @@ ENDTWO } 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 @@ END $starttime = time; } $date_items = &date_setting_table($starttime,undef,$context, - $env{'form.bulkaction'}); + $env{'form.bulkaction'},$formname, + $permission); } $output .= '

'.$headertext.'

'. '
'."\n". @@ -2536,17 +2537,8 @@ END $info = ''; } my $sections_select .= &course_sections(\%sections_count,$env{'form.showrole'}); - my $secbox = '

'.&Apache::lonhtmlcommon::start_pick_box()."\n". - &Apache::lonhtmlcommon::row_title(&mt('New section to assign'),'LC_oddrow_value')."\n". - ''."\n". - '
'.&mt('Existing sections')."\n". - '
'.$sections_select.'
'. - &mt('New section').'
'."\n". - ''."\n". - ''."\n". - '
'."\n". - &Apache::lonhtmlcommon::row_closure(1)."\n". - &Apache::lonhtmlcommon::end_pick_box().'

'; + my $rowtitle = &mt('New section to assign'); + my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context); $output .= $info.$secbox; } $output .= '

'. @@ -2883,7 +2875,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);} @@ -3810,6 +3802,61 @@ sub can_create_user { 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; @@ -3940,6 +3987,143 @@ sub get_course_identity { 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 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 + } + } + } + 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 '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;