--- loncom/interface/lonuserutils.pm 2007/12/05 21:23:14 1.11 +++ loncom/interface/lonuserutils.pm 2008/05/30 17:18:21 1.57 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.11 2007/12/05 21:23:14 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.57 2008/05/30 17:18:21 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,12 +42,11 @@ 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 - my $cdom = $env{'course.'.$courseid.'.domain'}; - my $cnum = $env{'course.'.$courseid.'.num'}; + my ($cnum,$cdom) = &get_course_identity($courseid); my %roles = &Apache::lonnet::dump('roles',$udom,$unam); my ($tmp) = keys(%roles); # Bail out if we were unable to get the students roles @@ -69,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; } @@ -96,7 +96,7 @@ sub modifyuserrole { } } elsif ($context eq 'domain') { $scope = '/'.$env{'request.role.domain'}.'/'; - } elsif ($context eq 'construction_space') { + } elsif ($context eq 'author') { $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'}; } if ($context eq 'domain') { @@ -127,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); @@ -136,22 +138,30 @@ sub modifyuserrole { sub propagate_id_change { my ($uname,$udom,$user) = @_; - my (@types,@roles,@cdoms); + my (@types,@roles); @types = ('active','future'); @roles = ('st'); my $idresult; my %roleshash = &Apache::lonnet::get_my_roles($uname, - $udom,'userroles',\@types,\@roles,\@cdoms); + $udom,'userroles',\@types,\@roles); + my %args = ( + 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 %userupdate; - my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%userupdate); + my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user); + my %coursehash = + &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args); + my $cdesc = $coursehash{'description'}; + if ($cdesc eq '') { + $cdesc = $cdom.'_'.$cnum; + } if ($result eq 'ok') { - $idresult .= "Classlist change: $uname:$udom - class -> $cnum:$cdom\n"; + $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'
'."\n"; } else { - $idresult .= "Error - $result -during classlist update for $uname:$udom in $cnum:$cdom\n"; + $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'
'."\n"; } } } @@ -203,7 +213,7 @@ sub domain_roles_select { # domain context # # Role types - my @roletypes = ('domain','construction_space','course'); + my @roletypes = ('domain','author','course'); my %lt = &role_type_names(); # # build up the menu information to be passed to @@ -225,11 +235,11 @@ sub domain_roles_select { my @roles; if ($roletype eq 'domain') { @roles = &domain_roles(); - } elsif ($roletype eq 'construction_space') { + } elsif ($roletype eq 'author') { @roles = &construction_space_roles(); } else { - @roles = &course_roles('domain'); - unshift(@roles,'cr'); + my $custom = 1; + @roles = &course_roles('domain',undef,$custom); } my $order = ['Any',@roles]; $select_menus{$roletype}->{'order'} = $order; @@ -246,7 +256,7 @@ sub domain_roles_select { } my $result = &Apache::loncommon::linked_select_forms ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'}, - 'roletype','showrole',\%select_menus,['domain','construction_space','course']); + 'roletype','showrole',\%select_menus,['domain','author','course']); return $result; } @@ -258,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'})) { @@ -288,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"); @@ -317,26 +332,46 @@ 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.', @@ -348,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 ); @@ -670,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'). @@ -695,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"; @@ -702,32 +745,32 @@ sub print_upload_manager_footer { $Str .= '

'.&mt('Settings for assigning roles:').'

'."\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.'

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

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

\n". - '

\n"; + $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 { + 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); @@ -751,20 +794,21 @@ sub forceid_change { "

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

\n"; + &mt('(only do if you know what you are doing.)')."\n"; if ($context eq 'domain') { - $output .= '

'."\n"; + &mt('Update ID/Student Number in courses in which user is Active/Future student,
(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'}) { @@ -794,6 +838,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') { @@ -808,7 +853,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) { @@ -823,7 +869,8 @@ sub print_upload_manager_form { ['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, @@ -842,11 +889,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') { @@ -869,11 +919,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') { @@ -897,8 +947,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; } @@ -906,24 +963,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 'construction_space' && $mode ne 'domain') { + } 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 = '