--- loncom/interface/lonuserutils.pm 2007/12/21 12:41:25 1.17 +++ loncom/interface/lonuserutils.pm 2008/08/20 21:28:14 1.62 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.17 2007/12/21 12:41:25 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.62 2008/08/20 21:28:14 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,7 +42,7 @@ use LONCAPA qw(:DEFAULT :match); ############################################################### # Drop student from all sections of a course, except optional $csec sub modifystudent { - my ($udom,$unam,$courseid,$csec,$desiredhost)=@_; + my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_; # if $csec is undefined, drop the student from all the courses matching # this one. If $csec is defined, drop them from all other sections of # this course and add them to section $csec @@ -68,14 +68,15 @@ sub modifystudent { my $reply=&Apache::lonnet::modifystudent # dom name id mode pass f m l g ($udom,$unam,'', '', '',undef,undef,undef,undef, - $section,time,undef,undef,$desiredhost); + $section,time,undef,undef,$desiredhost,'','manual', + '',$courseid,'',$context); $result .= $reply.':'; } } } } if ($result eq '') { - $result = 'Unable to find section for this student'; + $result = &mt('Unable to find section for this student'); } else { $result =~ s/(ok:)+/ok/g; } @@ -126,8 +127,10 @@ sub modifyuserrole { $email,$role,$start,$end); if ($userresult eq 'ok') { if ($role ne '') { + $role =~ s/_/\//g; $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope, - $role,$end,$start); + $role,$end,$start,'', + '',$context); } } return ($userresult,$authresult,$roleresult,$idresult); @@ -145,7 +148,7 @@ sub propagate_id_change { one_time => 1, ); foreach my $item (keys(%roleshash)) { - my ($cnum,$cdom,$role) = split(/:/,$item); + my ($cnum,$cdom,$role) = split(/:/,$item,-1); my ($start,$end) = split(/:/,$roleshash{$item}); if (&Apache::lonnet::is_course($cdom,$cnum)) { my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user); @@ -265,7 +268,7 @@ sub hidden_input { } sub print_upload_manager_header { - my ($r,$datatoken,$distotal,$krbdefdom,$context)=@_; + my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission)=@_; my $javascript; # if (! exists($env{'form.upfile_associate'})) { @@ -295,9 +298,14 @@ sub print_upload_manager_header { $password_choice = 'int'; } # + my $groupslist; + if ($context eq 'course') { + $groupslist = &get_groupslist(); + } my $javascript_validations = - &javascript_validations('auth',$krbdefdom,$password_choice,undef, - $env{'request.role.domain'}); + &javascript_validations('upload',$krbdefdom,$password_choice,undef, + $env{'request.role.domain'},$context, + $groupslist); my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':''); $r->print(&mt('Total number of records found in file: [_1].',$distotal). "
\n"); @@ -311,8 +319,8 @@ sub print_upload_manager_header { &hidden_input('fileupload',$env{'form.fileupload'}). &hidden_input('upfiletype',$env{'form.upfiletype'}). &hidden_input('upfile_associate',$env{'form.upfile_associate'})); - $r->print('
print('
'); $r->print(''); @@ -324,27 +332,47 @@ sub print_upload_manager_header { ############################################################### ############################################################### sub javascript_validations { - my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain)=@_; - my $authheader; - if ($mode eq 'auth') { - my %param = ( formname => 'studentform', - kerb_def_dom => $krbdefdom, - curr_authtype => $curr_authtype); - $authheader = &Apache::loncommon::authform_header(%param); - } elsif ($mode eq 'createcourse') { - my %param = ( formname => 'ccrs', - kerb_def_dom => $krbdefdom, - curr_authtype => $curr_authtype ); - $authheader = &Apache::loncommon::authform_header(%param); - } elsif ($mode eq 'modifycourse') { - my %param = ( formname => 'cmod', + my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain, + $context,$groupslist)=@_; + my %param = ( kerb_def_dom => $krbdefdom, - mode => 'modifycourse', curr_authtype => $curr_authtype, - curr_autharg => $curr_authfield ); - $authheader = &Apache::loncommon::authform_header(%param); + ); + if ($mode eq 'upload') { + $param{'formname'} = 'studentform'; + } elsif ($mode eq 'createcourse') { + $param{'formname'} = 'ccrs'; + } elsif ($mode eq 'modifycourse') { + $param{'formname'} = 'cmod'; + $param{'mode'} = 'modifycourse', + $param{'curr_autharg'} = $curr_authfield; } + my ($setsection_call,$setsections_js); + my $finish = " vf.submit();\n"; + if ($mode eq 'upload') { + if (($context eq 'course') || ($context eq 'domain')) { + if ($context eq 'course') { + if ($env{'request.course.sec'} eq '') { + $setsection_call = 'setSections(document.'.$param{'formname'}.');'; + $setsections_js = + &setsections_javascript($param{'formname'},$groupslist, + $mode); + } else { + $setsection_call = "'ok'"; + } + } elsif ($context eq 'domain') { + $setsection_call = 'setCourse()'; + $setsections_js = &dc_setcourse_js($param{'formname'},$mode,$context); + } + $finish = " var checkSec = $setsection_call\n". + " if (checkSec == 'ok') {\n". + " vf.submit();\n". + " }\n"; + } + } + my $authheader = &Apache::loncommon::authform_header(%param); + my %alert = &Apache::lonlocal::texthash (username => 'You need to specify the username field.', authen => 'You must choose an authentication type.', @@ -355,12 +383,13 @@ sub javascript_validations { section => 'The optional section field was not specified.', email => 'The optional email address field was not specified.', role => 'The optional role field was not specified.', + domain => 'The optional domain field was not specified.', continue => 'Continue adding users?', ); + my $function_name = <<"END"; +$setsections_js -# my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition(); - my $function_name =(< $formname, + my %param = ( formname => $form, kerb_def_dom => $krbdefdom, kerb_def_auth => $krbdef ); @@ -677,14 +711,14 @@ sub print_upload_manager_footer { my $krbform = &Apache::loncommon::authform_kerberos(%param); my $intform = &Apache::loncommon::authform_internal(%param); my $locform = &Apache::loncommon::authform_local(%param); - my $date_table = &date_setting_table(undef,undef,$context); - + my $date_table = &date_setting_table(undef,undef,$context,undef, + $formname,$permission); my $Str = "\n".'
'; $Str .= &hidden_input('nfields',$i); $Str .= &hidden_input('keyfields',$keyfields); $Str .= "

".&mt('Login Type')."

\n"; if ($context eq 'domain') { - $Str .= '

'.&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'). @@ -702,6 +736,8 @@ sub print_upload_manager_footer { } else { $Str .= $home_server_pick; } + $Str .= '

'.&mt('Default domain').'

'."\n". + &Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1); $Str .= '

'.&mt('Starting and Ending Dates'). "

\n"; $Str .= "

\n".$date_table."

\n"; @@ -711,40 +747,39 @@ sub print_upload_manager_footer { } 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.'

'.&mt('Course Level').'
'.$cb_script.$coursepick; - } elsif ($context eq 'author') { - $Str .= $options; + $Str .= '
'; + if (($context eq 'domain') || ($context eq 'author')) { + my ($options,$cb_script,$coursepick) = &default_role_selector($context,1); + if ($context eq 'domain') { + $Str .= ''.&mt('Domain Level').'
'.$options.'

'.&mt('Course Level').'
'.$cb_script.$coursepick; + } elsif ($context eq 'author') { + $Str .= $options; + } } else { - $Str .= '
'.&mt('role').': '. - $options.' '. - ''.&mt('section').': 
'; - } - if ($context eq 'course') { - $Str .= "

".&mt('Full Update')."

\n". - '

\n"; + my ($cnum,$cdom) = &get_course_identity(); + my $rowtitle = &mt('section'); + my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle, + $permission,$context,'upload'); + $Str .= $secbox."

".&mt('Full Update')."

\n". + '


'.&mt('Students selected from this list can be dropped.').'

'."\n"; } if ($context eq 'course' || $context eq 'domain') { $Str .= &forceid_change($context); } $Str .= '
'; $r->print($Str); @@ -754,24 +789,25 @@ sub print_upload_manager_footer { sub forceid_change { my ($context) = @_; my $output = - "

".&mt('ID/Student Number')."

\n". + "

".&mt('Student/Employee ID')."

\n". "

\n".'
'."\n". - &mt('(only do if you know what you are doing.)')."

\n"; + &mt('Disable Student/Employee ID Safeguard and force change of conflicting IDs'). + '
'."\n". + &mt('(only do if you know what you are doing.)')."\n"; if ($context eq 'domain') { - $output .= '

'."\n"; + &mt('Update Student/Employee ID in courses in which user is active/future student,[_1](if forcing change).','
'). + ''."\n"; } + $output .= '

'; return $output; } ############################################################### ############################################################### sub print_upload_manager_form { - my ($r,$context) = @_; + my ($r,$context,$permission) = @_; my $firstLine; my $datatoken; if (!$env{'form.datatoken'}) { @@ -801,6 +837,7 @@ sub print_upload_manager_form { 'ipwd_choice' => 'scalar', 'email_choice' => 'scalar', 'role_choice' => 'scalar', + 'domain_choice' => 'scalar', }; my $defdom = $env{'request.role.domain'}; if ($context eq 'course') { @@ -815,7 +852,8 @@ sub print_upload_manager_form { my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($defdom); # - &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context); + &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context, + $permission); my $i; my $keyfields; if ($total>=0) { @@ -826,11 +864,12 @@ sub print_upload_manager_form { ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}], ['lname',&mt('Last Name'), $env{'form.lname_choice'}], ['gen', &mt('Generation'), $env{'form.gen_choice'}], - ['id', &mt('ID/Student Number'),$env{'form.id_choice'}], + ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}], ['sec', &mt('Section'), $env{'form.sec_choice'}], ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}], ['email',&mt('E-mail Address'), $env{'form.email_choice'}], - ['role',&mt('Role'), $env{'form.role_choice'}]); + ['role',&mt('Role'), $env{'form.role_choice'}], + ['domain',&mt('Domain'), $env{'form.domain_choice'}]); if ($env{'form.upfile_associate'} eq 'reverse') { &Apache::loncommon::csv_print_samples($r,\@records); $i=&Apache::loncommon::csv_print_select_table($r,\@records, @@ -849,11 +888,14 @@ sub print_upload_manager_form { } $r->print(''); &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear, - $context); + $context,$permission); } sub setup_date_selectors { - my ($starttime,$endtime,$mode,$nolink) = @_; + my ($starttime,$endtime,$mode,$nolink,$formname) = @_; + if ($formname eq '') { + $formname = 'studentform'; + } if (! defined($starttime)) { $starttime = time; unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') { @@ -876,11 +918,11 @@ sub setup_date_selectors { } my $startdateform = - &Apache::lonhtmlcommon::date_setter('studentform','startdate',$starttime, + &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime, undef,undef,undef,undef,undef,undef,undef,$nolink); my $enddateform = - &Apache::lonhtmlcommon::date_setter('studentform','enddate',$endtime, + &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime, undef,undef,undef,undef,undef,undef,undef,$nolink); if ($mode eq 'create_enrolldates') { @@ -904,8 +946,15 @@ sub setup_date_selectors { sub get_dates_from_form { - my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate'); - my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate'); + my ($startname,$endname) = @_; + if ($startname eq '') { + $startname = 'startdate'; + } + if ($endname eq '') { + $endname = 'enddate'; + } + my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname); + my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname); if ($env{'form.no_end_date'}) { $enddate = 0; } @@ -913,24 +962,27 @@ sub get_dates_from_form { } sub date_setting_table { - my ($starttime,$endtime,$mode,$bulkaction) = @_; + my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission) = @_; my $nolink; if ($bulkaction) { $nolink = 1; } my ($startform,$endform) = - &setup_date_selectors($starttime,$endtime,$mode,$nolink); + &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname); my $dateDefault; if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') { $dateDefault = ' '; } elsif ($mode ne 'author' && $mode ne 'domain') { if (($bulkaction eq 'reenable') || ($bulkaction eq 'activate') || - ($bulkaction eq 'chgdates')) { - $dateDefault = ''. - ''; + ($bulkaction eq 'chgdates') || + ($env{'form.action'} eq 'upload')) { + if ($env{'request.course.sec'} eq '') { + $dateDefault = ''. + ''; + } } } my $perpetual = '