--- loncom/interface/loncreateuser.pm 2009/01/16 10:59:48 1.274 +++ loncom/interface/loncreateuser.pm 2009/02/02 00:12:01 1.275 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.274 2009/01/16 10:59:48 bisitz Exp $ +# $Id: loncreateuser.pm,v 1.275 2009/02/02 00:12:01 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -123,18 +123,10 @@ sub portfolio_quota { my ($ccuname,$ccdomain) = @_; my %lt = &Apache::lonlocal::texthash( 'usrt' => "User Tools", - 'blog' => "Personal User Blog", - 'aboutme' => "Personal Information Page", - 'portfolio' => "Personal User Portfolio", - 'avai' => "Available", - 'cusa' => "availability", - 'chse' => "Change setting", 'disk' => "Disk space allocated to user's portfolio files", 'cuqu' => "Current quota", 'cust' => "Custom quota", 'defa' => "Default", - 'usde' => "Use default", - 'uscu' => "Use custom", 'chqu' => "Change quota", ); my ($currquota,$quotatype,$inststatus,$defquota) = @@ -190,50 +182,7 @@ END_SCRIPT &Apache::loncommon::start_data_table(); if (&Apache::lonnet::allowed('mut',$ccdomain)) { - my %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname, - 'tools.aboutme','tools.portfolio','tools.blog'); - my @usertools = ('aboutme','blog','portfolio'); - foreach my $item (@usertools) { - my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off); - $cust_off = 'checked="checked" '; - $tool_on = 'checked="checked" '; - $curr_access = &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item); - if ($userenv{'tools.'.$item} eq '') { - $custom_access = 'default'; - if (!$curr_access) { - $tool_off = 'checked="checked" '; - $tool_on = ''; - } - } else { - $custom_access = 'custom'; - $cust_on = ' checked="checked" '; - $cust_off = ''; - if ($userenv{'tools.'.$item} == 0) { - $tool_off = 'checked="checked" '; - $tool_on = ''; - } - } - $output .= ' '."\n". - ' '.$lt{$item}.''."\n". - ' '."\n". - &Apache::loncommon::start_data_table_row()."\n". - ' '.&mt('Availability determined currently from [_1] setting.',$custom_access). - '     '.$lt{'avai'}.': '. - ($curr_access?&mt('Yes'):&mt('No')).''."\n". - &Apache::loncommon::end_data_table_row()."\n". - &Apache::loncommon::start_data_table_row()."\n". - ' '.$lt{'chse'}.':    '. - '  --  '. - $lt{'cusa'}.':  '."\n". - &Apache::loncommon::end_data_table_row()."\n"; - } + $output .= &build_tools_display($ccuname,$ccdomain,'tools'); } if (&Apache::lonnet::allowed('mpq',$ccdomain)) { $output .= ''."\n". @@ -262,6 +211,76 @@ END_SCRIPT return $output; } +sub build_tools_display { + my ($ccuname,$ccdomain,$context) = @_; + my (@usertools,%userenv,$output); + my %lt = &Apache::lonlocal::texthash ( + 'blog' => "Personal User Blog", + 'aboutme' => "Personal Information Page", + 'portfolio' => "Personal User Portfolio", + 'avai' => "Available", + 'cusa' => "availability", + 'chse' => "Change setting", + 'usde' => "Use default", + 'uscu' => "Use custom", + 'official' => 'Can request creation of official courses', + 'unofficial' => 'Can request creation of unofficial courses', + ); + if ($context eq 'requestcourse') { + %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname, + 'requestcourse.official','requestcourse.unofficial'); + @usertools = ('official','unofficial'); + } else { + %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname, + 'tools.aboutme','tools.portfolio','tools.blog'); + @usertools = ('aboutme','blog','portfolio'); + } + foreach my $item (@usertools) { + my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off); + $cust_off = 'checked="checked" '; + $tool_on = 'checked="checked" '; + $curr_access = + &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef, + $context); + if ($userenv{$context.'.'.$item} eq '') { + $custom_access = 'default'; + if (!$curr_access) { + $tool_off = 'checked="checked" '; + $tool_on = ''; + } + } else { + $custom_access = 'custom'; + $cust_on = ' checked="checked" '; + $cust_off = ''; + if ($userenv{$context.'.'.$item} == 0) { + $tool_off = 'checked="checked" '; + $tool_on = ''; + } + } + $output .= ' '."\n". + ' '.$lt{$item}.''."\n". + ' '."\n". + &Apache::loncommon::start_data_table_row()."\n". + ' '.&mt('Availability determined currently from [_1] setting.',$custom_access). + '     '.$lt{'avai'}.': '. + ($curr_access?&mt('Yes'):&mt('No')).''."\n". + &Apache::loncommon::end_data_table_row()."\n". + &Apache::loncommon::start_data_table_row()."\n". + ' '.$lt{'chse'}.':    '. + '  --  '. + $lt{'cusa'}.':  '."\n". + &Apache::loncommon::end_data_table_row()."\n"; + } + return $output; +} + # =================================================================== Phase one sub print_username_entry_form { @@ -769,7 +788,7 @@ $lt{'hs'}: $home_server_pick my $authtype = $rules->{$matchedrule}{'authtype'}; if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) { $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc)); - } else { + } else { my $authparm = $rules->{$matchedrule}{'authparm'}; $authmsg = $rules->{$matchedrule}{'authmsg'}; if ($authtype =~ /^krb(4|5)$/) { @@ -847,9 +866,15 @@ ENDCHANGEUSER if ($showforceid) { $r->print(&Apache::lonuserutils::forceid_change($context)); } + if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) { + $r->print('

'.&mt('User Can Request Creation of Courses?').'

'. + &Apache::loncommon::start_data_table(). + &build_tools_display($ccuname,$ccdomain,'requestcourse'). + &Apache::loncommon::end_data_table()); + } $r->print(''); my $user_auth_text = &user_authentication($ccuname,$ccdomain,$formname); - my ($user_quota_text,$user_tools_text); + my ($user_quota_text,$user_tools_text,$user_reqcrs_text); if ((&Apache::lonnet::allowed('mpq',$ccdomain)) || (&Apache::lonnet::allowed('mut',$ccdomain))) { # Current user has quota modification privileges @@ -1747,6 +1772,7 @@ sub update_user_data { $env{'form.ccuname'}, $env{'form.ccdomain'}).''); my (%alerts,%rulematch,%inst_results,%curr_rules); my @usertools = ('aboutme','blog','portfolio'); + my @requestcourses = ('official','unofficial'); if ($env{'form.makeuser'}) { $r->print('

'.&mt('Creating new account.').'

'); # Check for the authentication mode and password @@ -1820,7 +1846,15 @@ sub update_user_data { foreach my $item (@usertools) { if ($env{'form.custom'.$item} == 1) { $newcustom{$item} = $env{'form.tools_'.$item}; - $changed{$item} = &tool_admin($item,$newcustom{$item},\%changeHash); + $changed{$item} = &tool_admin($item,$newcustom{$item}, + \%changeHash,'tools'); + } + } + if (&Apache::lonnet::allowed('ccc',$env{'request.domain'})) { + foreach my $item (@requestcourses) { + $newcustom{$item} = $env{'form.requestcourse_'.$item}; + $changed{$item} = &tool_admin($item,$newcustom{$item}, + \%changeHash,'requestcourse'); } } if (keys(%changed)) { @@ -1867,7 +1901,8 @@ sub update_user_data { my %userenv = &Apache::lonnet::get ('environment',['firstname','middlename','lastname','generation', 'id','permanentemail','portfolioquota','inststatus','tools.aboutme', - 'tools.blog','tools.portfolio'], + 'tools.blog','tools.portfolio','requestcourse.official', + 'requestcourse.unofficial'], $env{'form.ccdomain'},$env{'form.ccuname'}); my ($tmp) = keys(%userenv); if ($tmp =~ /^(con_lost|error)/i) { @@ -1995,13 +2030,16 @@ sub update_user_data { $newdefquotatext,%oldaccess,%oldaccesstext,%newaccess,%newaccesstext); my ($defquota,$settingstatus) = &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus); - my ($showquota,$showtools); + my ($showquota,$showtools,$showrequestcourses); if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) { $showquota = 1; } if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) { $showtools = 1; } + if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) { + $showrequestcourses = 1; + } my (%changeHash,%changed); $changeHash{'portfolioquota'} = $userenv{'portfolioquota'}; if ($userenv{'portfolioquota'} ne '') { @@ -2043,73 +2081,10 @@ sub update_user_data { if ($newisdefault) { $newdefquotatext = &get_defaultquota_text($settingstatus); } - - foreach my $tool (@usertools) { - if ($userenv{'tools.'.$tool} ne '') { - $oldaccess{$tool} = &mt('custom'); - if ($userenv{'tools_'.$tool}) { - $oldaccesstext{$tool} = &mt("availability set to 'on'"); - } else { - $oldaccesstext{$tool} = &mt("availability set to 'off'"); - } - $changeHash{'tools.'.$tool} = $userenv{'tools.'.$tool}; - if ($env{'form.custom'.$tool} == 1) { - if ($env{'form.tools_'.$tool} ne $userenv{'tools.'.$tool}) { - $changed{$tool} = &tool_admin($tool,$env{'form.tools_'.$tool}, - \%changeHash); - if ($changed{$tool}) { - $newaccess{$tool} = &mt('custom'); - if ($env{'form.tools_'.$tool}) { - $newaccesstext{$tool} = &mt("availability set to 'on'"); - } else { - $newaccesstext{$tool} = &mt("availability set to 'off'"); - } - } else { - $newaccess{$tool} = $oldaccess{$tool}; - if ($userenv{'tools.'.$tool}) { - $newaccesstext{$tool} = &mt("availability set to 'on'"); - } else { - $newaccesstext{$tool} = &mt("availability set to 'off'"); - } - } - } else { - $newaccess{$tool} = $oldaccess{$tool}; - $newaccesstext{$tool} = $oldaccesstext{$tool}; - } - } else { - $changed{$tool} = &tool_admin($tool,'',\%changeHash); - if ($changed{$tool}) { - $newaccess{$tool} = &mt('default'); - } else { - $newaccess{$tool} = $oldaccess{$tool}; - if ($userenv{'tools.'.$tool}) { - $newaccesstext{$tool} = &mt("availability set to 'on'"); - } else { - $newaccesstext{$tool} = &mt("availability set to 'off'"); - } - } - } - } else { - $oldaccess{$tool} = &mt('default'); - if ($env{'form.custom'.$tool} == 1) { - $changed{$tool} = &tool_admin($tool,$env{'form.tools_'.$tool}, - \%changeHash); - if ($changed{$tool}) { - $newaccess{$tool} = &mt('custom'); - if ($env{'form.tools_'.$tool}) { - $newaccesstext{$tool} = &mt("availability set to 'on'"); - } else { - $newaccesstext{$tool} = &mt("availability set to 'off'"); - } - } else { - $newaccess{$tool} = $oldaccess{$tool}; - } - } else { - $newaccess{$tool} = $oldaccess{$tool}; - } - } - } - + &tool_changes('tools',\@usertools,\%oldaccess,\%oldaccesstext,\%userenv, + \%changeHash,\%changed,\%newaccess,\%newaccesstext); + &tool_changes('requestcourse',\@requestcourses,\%oldaccess,\%oldaccesstext, + \%userenv, \%changeHash,\%changed,\%newaccess,\%newaccesstext); if ($env{'form.cfirstname'} ne $userenv{'firstname'} || $env{'form.cmiddlename'} ne $userenv{'middlename'} || $env{'form.clastname'} ne $userenv{'lastname'} || @@ -2135,7 +2110,13 @@ sub update_user_data { ($env{'user.domain'} eq $env{'form.ccdomain'})) { my %newenvhash; foreach my $key (keys(%changed)) { - if ($key ne 'quota') { + if (($key eq 'official') || ($key eq 'unofficial')) { + $newenvhash{'environment.canrequest.'.$key} = + $changeHash{'requestcourse.'.$key}; + $newenvhash{'environment.canrequest.'.$key} = + $changeHash{'requestcourse.'.$key}; + + } elsif ($key ne 'quota') { $newenvhash{'environment.tools.'.$key} = $changeHash{'tools.'.$key}; $newenvhash{'environment.availabletools.'.$key} = @@ -2168,19 +2149,21 @@ sub update_user_data { ((keys(%changed) > 0) && $chgresult eq 'ok')) { # Tell the user we changed the name my %lt=&Apache::lonlocal::texthash( - 'uic' => "User Information Changed", - 'frst' => "First", - 'mddl' => "Middle", - 'lst' => "Last", - 'gen' => "Generation", - 'id' => "Student/Employee ID", - 'mail' => "Permanent E-mail", - 'disk' => "Disk space allocated to portfolio files", - 'blog' => "Blog Availability", - 'aboutme' => "Home Page Availability", - 'portfolio' => "Portfolio Availability", - 'prvs' => "Previous", - 'chto' => "Changed To" + 'uic' => "User Information Changed", + 'frst' => "First", + 'mddl' => "Middle", + 'lst' => "Last", + 'gen' => "Generation", + 'id' => "Student/Employee ID", + 'mail' => "Permanent E-mail", + 'disk' => "Disk space allocated to portfolio files", + 'blog' => "Blog Availability", + 'aboutme' => "Home Page Availability", + 'portfolio' => "Portfolio Availability", + 'official' => "Can Request Official Courses", + 'unofficial' => "Can Request Unofficial Courses", + 'prvs' => "Previous", + 'chto' => "Changed To" ); $r->print('

'.$lt{'uic'}.'

'. &Apache::loncommon::start_data_table(). @@ -2194,6 +2177,12 @@ sub update_user_data { $lt{'id'} $lt{'mail'} END + if ($showrequestcourses) { + foreach my $item (@requestcourses) { + $r->print(" + $lt{$item}\n"); + } + } if ($showquota) { $r->print(" $lt{'disk'}\n"); @@ -2215,6 +2204,12 @@ END $userenv{'id'} $userenv{'permanentemail'} END + if ($showrequestcourses) { + foreach my $item (@requestcourses) { + $r->print(" + $oldaccess{$item} $oldaccesstext{$item}\n"); + } + } if ($showquota) { $r->print(" $oldportfolioquota Mb $olddefquotatext \n"); @@ -2236,6 +2231,12 @@ END $env{'form.cid'} $env{'form.cpermanentemail'} END + if ($showrequestcourses) { + foreach my $item (@requestcourses) { + $r->print(" + $newaccess{$item} $newaccesstext{$item} \n"); + } + } if ($showquota) { $r->print(" $newportfolioquota Mb $newdefquotatext \n"); @@ -2274,15 +2275,18 @@ END $env{'form.ccdomain'}.'
'); } } else { # End of if ($env ... ) logic - # They did not want to change the users name, quota or tool availability, + # They did not want to change the users name, quota, tool availability, + # or ability to request creation of courses, # but we can still tell them what the name and quota and availabilities are my %lt=&Apache::lonlocal::texthash( - 'id' => "Student/Employee ID", - 'mail' => "Permanent e-mail", - 'disk' => "Disk space allocated to user's portfolio files", - 'blog' => "Blog Availability", - 'aboutme' => "Home Page Availability", - 'portfolio' => "Portfolio Availability", + 'id' => "Student/Employee ID", + 'mail' => "Permanent e-mail", + 'disk' => "Disk space allocated to user's portfolio files", + 'blog' => "Blog Availability", + 'aboutme' => "Home Page Availability", + 'portfolio' => "Portfolio Availability", + 'official' => "Can Request Official Courses", + 'unofficial' => "Can Request Unofficial Course", ); $r->print(<<"END");

$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'} @@ -2291,6 +2295,12 @@ END $r->print('
['.$lt{'mail'}.': '. $userenv{'permanentemail'}.']'); } + if ($showrequestcourses) { + foreach my $item (@requestcourses) { + $r->print('
['.$lt{$item}.': '.$newaccess{$item}.' '. + $newaccesstext{$item}.']'."\n"); + } + } if ($showtools) { foreach my $item (@usertools) { $r->print('
['.$lt{$item}.': '.$newaccess{$item}.' '. @@ -2369,6 +2379,83 @@ END $r->print(&Apache::loncommon::end_page()); } +sub tool_changes { + my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash, + $changed,$newaccess,$newaccesstext) = @_; + if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') && + (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') && + (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') && + (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) { + return; + } + foreach my $tool (@{$usertools}) { + if ($userenv->{$context.'.'.$tool} ne '') { + $oldaccess->{$tool} = &mt('custom'); + if ($userenv->{$context.'.'.$tool}) { + $oldaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $oldaccesstext->{$tool} = &mt("availability set to 'off'"); + } + $changeHash->{$context.'.'.$tool} = $userenv->{'tools.'.$tool}; + if ($env{'form.custom'.$tool} == 1) { + if ($env{'form.'.$context.'_'.$tool} ne $userenv->{'tools.'.$tool}) { + $changed->{$tool} = &tool_admin($tool,$env{'form.'.$context.'_'.$tool}, + $changeHash,$context); + if ($changed->{$tool}) { + $newaccess->{$tool} = &mt('custom'); + if ($env{'form.'.$context.'_'.$tool}) { + $newaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } + } else { + $newaccess->{$tool} = $oldaccess->{$tool}; + if ($userenv->{$context.'.'.$tool}) { + $newaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } + } + } else { + $newaccess->{$tool} = $oldaccess->{$tool}; + $newaccesstext->{$tool} = $oldaccesstext->{$tool}; + } + } else { + $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context); + if ($changed->{$tool}) { + $newaccess->{$tool} = &mt('default'); + } else { + $newaccess->{$tool} = $oldaccess->{$tool}; + if ($userenv->{$context.'.'.$tool}) { + $newaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } + } + } + } else { + $oldaccess->{$tool} = &mt('default'); + if ($env{'form.custom'.$tool} == 1) { + $changed->{$tool} = &tool_admin($tool,$env{'form.'.$context.'_'.$tool}, + $changeHash,$context); + if ($changed->{$tool}) { + $newaccess->{$tool} = &mt('custom'); + if ($env{'form.'.$context.'_'.$tool}) { + $newaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } + } else { + $newaccess->{$tool} = $oldaccess->{$tool}; + } + } else { + $newaccess->{$tool} = $oldaccess->{$tool}; + } + } + } + return; +} + sub update_roles { my ($r,$context) = @_; my $now=time; @@ -2733,13 +2820,21 @@ sub quota_admin { } sub tool_admin { - my ($tool,$settool,$changeHash) = @_; - my $toolchanged; - if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) { + my ($tool,$settool,$changeHash,$context) = @_; + my $canchange = 0; + if ($context eq 'requestcourse') { + if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) { + $canchange = 1; + } + } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) { # Current user has quota modification privileges + $canchange = 1; + } + my $toolchanged; + if ($canchange) { if (ref($changeHash) eq 'HASH') { $toolchanged = 1; - $changeHash->{'tools.'.$tool} = $settool; + $changeHash->{$context.'.'.$tool} = $settool; } } return $toolchanged;