--- loncom/interface/loncreateuser.pm 2008/01/06 04:38:57 1.229 +++ loncom/interface/loncreateuser.pm 2008/03/08 03:48:41 1.237 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.229 2008/01/06 04:38:57 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.237 2008/03/08 03:48:41 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -156,21 +156,21 @@ END_SCRIPT $custom_off = ' '; $showquota = $currquota; if ($longinsttype eq '') { - $defaultinfo = &mt('For this user, the default quota would be [_1] - Mb.',$defquota); + $defaultinfo = &mt('For this user, the default quota would be [_1]' + .' Mb.',$defquota); } else { - $defaultinfo = &mt("For this user, the default quota would be [_1] - Mb, as determined by the user's institutional - affiliation ([_2]).",$defquota,$longinsttype); + $defaultinfo = &mt("For this user, the default quota would be [_1]". + " Mb, as determined by the user's institutional". + " affiliation ([_2]).",$defquota,$longinsttype); } } else { if ($longinsttype eq '') { - $defaultinfo = &mt('For this user, the default quota is [_1] - Mb.',$defquota); + $defaultinfo = &mt('For this user, the default quota is [_1]' + .' Mb.',$defquota); } else { - $defaultinfo = &mt("For this user, the default quota of [_1] - Mb, is determined by the user's institutional - affiliation ([_2]).",$defquota,$longinsttype); + $defaultinfo = &mt("For this user, the default quota of [_1]". + " Mb, is determined by the user's institutional". + " affiliation ([_2]).",$defquota,$longinsttype); } } my $output = $quota_javascript. @@ -355,7 +355,7 @@ ENDBLOCK - + @@ -603,9 +603,12 @@ sub print_user_modification_page { my $js = &validation_javascript($context,$ccdomain,$pjump_def, $groupslist,$newuser,$formname,\%loaditem); + my $args = {'add_entries' => \%loaditem}; + if ($env{'form.popup'}) { + $args->{'no_nav_bar'} = 1; + } my $start_page = - &Apache::loncommon::start_page('User Management', - $js,{'add_entries' => \%loaditem,}); + &Apache::loncommon::start_page('User Management',$js,$args); my %breadcrumb_text = &singleuser_breadcrumb(); &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:backPage($form)", @@ -1318,6 +1321,7 @@ ENDBADAUTH $outcome .= <$lt{'ccld'} $lt{'yodo'} $lt{'ifch'}: $ccdomain + ENDNOPRIV } } @@ -1486,7 +1490,13 @@ sub update_user_data { my $jscript = ''."\n"; my %breadcrumb_text = &singleuser_breadcrumb(); - $r->print(&Apache::loncommon::start_page($title,$jscript)); + my $args; + if ($env{'form.popup'}) { + $args->{'no_nav_bar'} = 1; + } else { + $args = undef; + } + $r->print(&Apache::loncommon::start_page($title,$jscript,$args)); &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:backPage(document.userupdate)", text=>$breadcrumb_text{'search'}, @@ -1636,6 +1646,27 @@ sub update_user_data { $r->print(&mt('Generating user').': '.$result); $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'}, $env{'form.ccdomain'}); + if (($uhome ne 'no_host') && ($env{'form.customquota'} == 1)) { + my (%changeHash,$newportfolioquota); + if ($env{'form.portfolioquota'} eq '') { + $newportfolioquota = 0; + } else { + $newportfolioquota = $env{'form.portfolioquota'}; + $newportfolioquota =~ s/[^\d\.]//g; + } + my $quotachanged = "a_admin($newportfolioquota,\%changeHash); + if ($quotachanged) { + $changeHash{'firstname'} = $env{'form.cfirstname'}; + $changeHash{'middlename'} = $env{'form.cmiddlename'}; + $changeHash{'lastname'} = $env{'form.clastname'}; + $changeHash{'generation'} = $env{'form.cgeneration'}; + $changeHash{'id'} = $env{'form.cid'}; + $changeHash{'permanentemail'} = $env{'form.cpermanentemail'}; + my $quotachgresult = + &Apache::lonnet::put('environment',\%changeHash, + $env{'form.ccdomain'},$env{'form.ccuname'}); + } + } $r->print('
'.&mt('Home server').': '.$uhome.' '. &Apache::lonnet::hostname($uhome)); } elsif (($env{'form.login'} ne 'nochange') && @@ -2033,8 +2064,12 @@ END } } my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'}, - $env{'form.ccdomain'}); - $r->print('

'.&mt('Modify this user: ([_1])',$userinfo).''.(' 'x5).''.&mt('Create/Modify Another User').'

'); + $env{'form.ccdomain'}); + if ($env{'form.popup'}) { + $r->print('

'.&mt('Close window').'

'); + } else { + $r->print('

'.&mt('Modify this user: ([_1])',$userinfo).''.(' 'x5).''.&mt('Create/Modify Another User').'

'); + } } $r->print(&Apache::loncommon::end_page()); } @@ -2521,7 +2556,7 @@ sub custom_role_editor { 'crl' => "Course Level", 'dml' => "Domain Level", 'ssl' => "System Level"); - $r->print('Select a Template
'); + $r->print(&mt('Select a Template').'
'); $r->print('
'); $r->print($button_code); $r->print('
'); @@ -2731,7 +2766,8 @@ sub handler { $context = 'domain'; } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['action','state','callingform','roletype','showrole','bulkaction']); + ['action','state','callingform','roletype','showrole','bulkaction','popup','phase', + 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']); &Apache::lonhtmlcommon::clear_breadcrumbs(); if ($env{'form.action'} ne 'dateselect') { &Apache::lonhtmlcommon::add_breadcrumb @@ -2934,6 +2970,25 @@ sub handler { ''.&mt('You do not have permission to modify dates or sections for users').''. &Apache::loncommon::end_page()); } + } elsif ($env{'form.action'} eq 'selfenroll') { + $r->print(&header()); + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>'/adm/createuser?action=selfenroll', + text=>"Configure Self-enrollment"}); + if (!exists($env{'form.state'})) { + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment', + 'Course_Self_Enrollment')); + + &print_selfenroll_menu($r,$context,$permission); + } elsif ($env{'form.state'} eq 'done') { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>'/adm/createuser?action=selfenroll', + text=>"Result"}); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result', + 'Course_Self_Enrollment')); + &update_selfenroll_config($r,$context); + } + $r->print(&Apache::loncommon::end_page()); } else { $r->print(&header()); $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); @@ -3042,7 +3097,12 @@ sub print_main_menu { permission => (&Apache::lonnet::auto_run($cnum,$cdom) && $permission->{'cusr'}), url => '/adm/populate', - }); + }, + { text => 'Configure User Self-enrollment', + help => 'Course_Self_Enrollment', + action => 'selfenroll', + permission => $permission->{'cusr'}, + }); } push(@courselinks, { text => 'Manage Course Groups', @@ -3056,6 +3116,10 @@ sub print_main_menu { foreach my $menu_item (@menu) { next if (! $menu_item->{'permission'}); $menu_html.='

'; + if (exists($menu_item->{'help'})) { + $menu_html.= + &Apache::loncommon::help_open_topic($menu_item->{'help'}); + } $menu_html.=''; if (exists($menu_item->{'url'})) { $menu_html.=qq{}; @@ -3064,10 +3128,6 @@ sub print_main_menu { qq{}; } $menu_html.= &mt($menu_item->{'text'}).''; - if (exists($menu_item->{'help'})) { - $menu_html.= - &Apache::loncommon::help_open_topic($menu_item->{'help'}); - } $menu_html.='

'; } return $menu_html; @@ -3084,6 +3144,126 @@ sub restore_prev_selections { \%saveable_parameters); } +sub print_selfenroll_menu { + my ($r,$context,$permission) = @_; + my $formname = 'enrollstudent'; + my $nolink = 1; + my ($row,$lt) = &get_selfenroll_titles(); + my $groupslist = &Apache::lonuserutils::get_groupslist(); + my $setsec_js = + &Apache::lonuserutils::setsections_javascript($formname,$groupslist); + my $output = ''."\n". + '

'.$lt->{'selfenroll'}.'

'."\n". + '
'."\n". + &Apache::lonhtmlcommon::start_pick_box(); + if (ref($row) eq 'ARRAY') { + foreach my $item (@{$row}) { + my $title = $item; + if (ref($lt) eq 'HASH') { + $title = $lt->{$item}; + } + $output .= + &Apache::lonhtmlcommon::row_title($title, + 'LC_selfenroll_pick_box_title','LC_oddrow_value')."\n"; + if ($item eq 'types') { + my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'}; + $output .= ''; + } elsif ($item eq 'registered') { + my ($regon,$regoff); + if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) { + $regon = ' checked="checked" '; + $regoff = ' '; + } else { + $regon = ' '; + $regoff = ' checked="checked" '; + } + $output .= '  '; + } elsif ($item eq 'enroll_dates') { + my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'}; + my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'}; + if ($starttime eq '') { + $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'}; + } + if ($endtime eq '') { + $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'}; + } + my $startform = + &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime, + undef,undef,undef,undef,undef,undef,undef,$nolink); + my $endform = + &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime, + undef,undef,undef,undef,undef,undef,undef,$nolink); + $output .= &selfenroll_date_forms($startform,$endform); + } elsif ($item eq 'access_dates') { + my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'}; + my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'}; + if ($starttime eq '') { + $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'}; + } + if ($endtime eq '') { + $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'}; + } + my $startform = + &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime, + undef,undef,undef,undef,undef,undef,undef,$nolink); + my $endform = + &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime, + undef,undef,undef,undef,undef,undef,undef,$nolink); + $output .= &selfenroll_date_forms($startform,$endform); + } elsif ($item eq 'section') { + my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'}; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'},'.num'}; + my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum); + my $newsecval; + if ($currsec ne 'none' && $currsec ne '') { + if (!defined($sections_count{$currsec})) { + $newsecval = $currsec; + } + } + my $sections_select = + &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec); + $output .= ''."\n". + ''."\n". + '
'.&mt('Existing sections')."\n". + '
'.$sections_select.'
'. + &mt('New section').'
'."\n". + ''."\n". + ''."\n". + ''."\n". + '
'."\n"; + } + $output .= &Apache::lonhtmlcommon::row_closure(1); + } + } + $output .= &Apache::lonhtmlcommon::end_pick_box(). + '
'; + $r->print($output); + return; +} + +sub selfenroll_date_forms { + my ($startform,$endform) = @_; + my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n". + &Apache::lonhtmlcommon::row_title(&mt('Starts'), + 'LC_oddrow_value')."\n". + $startform."\n". + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_title(&mt('Ends'), + 'LC_oddrow_value')."\n". + $endform."\n". + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::end_pick_box(); + return $output; +} + #-------------------------------------------------- functions for &phase_two sub user_search_result { my ($context,$srch) = @_; @@ -3690,7 +3870,7 @@ sub course_level_dc { '  '. ' '.$lt{'new'}.'
'. ''. - ''. + ''. ''. ''; $otheritems .= <print('

'.$lt->{'selfenroll'}.'

'."\n"); + if (ref($row) eq 'ARRAY') { + foreach my $item (@{$row}) { + if ($item eq 'enroll_dates') { + my (%currenrolldate,%newenrolldate); + foreach my $type ('start','end') { + $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'}; + $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date'); + if ($newenrolldate{$type} ne $currenrolldate{$type}) { + $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type}; + } + } + } elsif ($item eq 'access_dates') { + my (%currdate,%newdate); + foreach my $type ('start','end') { + $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'}; + $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access'); + if ($newdate{$type} ne $currdate{$type}) { + $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type}; + } + } + } else { + my $curr_val = + $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item}; + my $newval = $env{'form.selfenroll_'.$item}; + if ($item eq 'section') { + $newval = $env{'form.sections'}; + if (grep(/^\Q$newval\E$/,keys(%{$groupslist}))) { + $newval = $curr_val; + $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'
'.&mt('Group names and section names must be distinct'); + } elsif ($newval eq 'all') { + $newval = $curr_val; + $warning{$item} = &mt("Section for self-enrolled users unchanged, as 'all' is a reserved section name."); + } + if ($newval eq '') { + $newval = 'none'; + } + } + if ($newval ne $curr_val) { + $changes{'internal.selfenroll_'.$item} = $newval; + } + } + } + if (keys(%warning) > 0) { + foreach my $item (@{$row}) { + if (exists($warning{$item})) { + $r->print($warning{$item}.'
'); + } + } + } + if (keys(%changes) > 0) { + my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum); + if ($putresult eq 'ok') { + if ((exists($changes{'internal.selfenroll_types'})) || + (exists($changes{'internal.selfenroll_start_date'})) || + (exists($changes{'internal.selfenroll_end_date'}))) { + my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.', + $cnum,undef,undef,'Course'); + my $chome = &Apache::lonnet::homeserver($cnum,$cdom); + if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') { + foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') { + if (exists($changes{'internal.'.$item})) { + $crsinfo{$env{'request.course.id'}}{$item} = + $changes{'internal.'.$item}; + } + } + my $crsputresult = + &Apache::lonnet::courseidput($cdom,\%crsinfo, + $chome,'notime'); + } + } + $r->print(&mt('The following changes were made to self-enrollment settings:').''); + my %newenvhash; + foreach my $key (keys(%changes)) { + $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key}; + } + &Apache::lonnet::appenv(%newenvhash); + } else { + $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'
'.&mt('The error was: [_1].',$putresult)); + } + } else { + $r->print(&mt('No changes were needed to the existing self-enrollment settings in this course.')); + } + } else { + $r->print(&mt('No changes were needed to the existing self-enrollment settings in this course.')); + } + return; +} + +sub get_selfenroll_titles { + my @row = ('types','registered','enroll_dates','access_dates','section'); + my %lt = &Apache::lonlocal::texthash ( + selfenroll => 'Self-enrollment with a student role', + types => 'Users allowed to self-enroll in this course', + registered => 'Restrict self-enrollment to registered students?', + enroll_dates => 'Dates self-enrollment available', + access_dates => 'Access dates for self-enrolled users', + section => 'Section', + ); + return (\@row,\%lt); +} + #---------------------------------------------- end functions for &phase_two #--------------------------------- functions for &phase_two and &phase_three