--- loncom/interface/lonuserutils.pm 2007/12/06 04:03:36 1.12 +++ loncom/interface/lonuserutils.pm 2007/12/22 22:42:58 1.29 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.12 2007/12/06 04:03:36 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.29 2007/12/22 22:42:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,8 +46,7 @@ sub modifystudent { # 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,7 +68,8 @@ 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); $result .= $reply.':'; } } @@ -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,6 +127,7 @@ 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); } @@ -146,7 +147,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); @@ -211,7 +212,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 @@ -233,11 +234,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; @@ -254,7 +255,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; } @@ -266,7 +267,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'})) { @@ -296,9 +297,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, + $permission,$groupslist); my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':''); $r->print(&mt('Total number of records found in file: [_1].',$distotal). "
\n"); @@ -325,26 +331,51 @@ 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,$permission,$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 'createuser') { + $param{'formname'} = 'cu'; + } elsif ($mode eq 'upload') { + $param{'formname'} = 'studentform'; + } elsif ($mode eq 'singlestudent') { + $param{'formname'} = 'cu'; + } 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); + } + $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.', @@ -359,8 +390,9 @@ sub javascript_validations { continue => 'Continue adding users?', ); -# my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition(); my $function_name =(< $formname, + my %param = ( formname => $form, kerb_def_dom => $krbdefdom, kerb_def_auth => $krbdef ); @@ -678,8 +704,8 @@ 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); @@ -710,31 +736,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"; } + $output .= '

'; return $output; } ############################################################### ############################################################### sub print_upload_manager_form { - my ($r,$context) = @_; + my ($r,$context,$permission) = @_; my $firstLine; my $datatoken; if (!$env{'form.datatoken'}) { @@ -816,7 +844,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) { @@ -850,11 +879,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') { @@ -877,11 +909,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') { @@ -914,24 +946,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 = '