--- loncom/interface/loncreateuser.pm 2007/03/03 01:33:21 1.146 +++ loncom/interface/loncreateuser.pm 2007/06/07 22:34:56 1.151 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.146 2007/03/03 01:33:21 albertel Exp $ +# $Id: loncreateuser.pm,v 1.151 2007/06/07 22:34:56 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -122,11 +122,72 @@ sub portfolio_quota { my ($ccuname,$ccdomain) = @_; my %lt = &Apache::lonlocal::texthash( 'disk' => "Disk space allocated to user's portfolio files", + 'cuqu' => "Current quota", + 'cust' => "Custom quota", + 'defa' => "Default", + 'chqu' => "Change quota", ); - my $output = '<h3>'.$lt{'disk'}.'</h3>'. + my ($currquota,$quotatype,$inststatus,$defquota) = + &Apache::loncommon::get_user_quota($ccuname,$ccdomain); + my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain); + my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo); + if ($inststatus ne '') { + if ($usertypes->{$inststatus} ne '') { + $longinsttype = $usertypes->{$inststatus}; + } + } + $custom_on = ' '; + $custom_off = ' checked="checked" '; + my $quota_javascript = <<"END_SCRIPT"; +<script type="text/javascript"> +function quota_changes(caller) { + if (caller == "custom") { + if (document.cu.customquota[0].checked) { + document.cu.portfolioquota.value = ""; + } + } + if (caller == "quota") { + document.cu.customquota[1].checked = true; + } +} +</script> +END_SCRIPT + if ($quotatype eq 'custom') { + $custom_on = $custom_off; + $custom_off = ' '; + $showquota = $currquota; + if ($longinsttype eq '') { + $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); + } + } else { + if ($longinsttype eq '') { + $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); + } + } + my $output = $quota_javascript. + '<h3>'.$lt{'disk'}.'</h3>'. + $lt{'cuqu'}.': '.$currquota.' Mb. '. + $defaultinfo.'<br /><span class="LC_nobreak">'.$lt{'chqu'}. + ': <label>'. + '<input type="radio" name="customquota" value="0" '. + $custom_off.' onchange="javascript:quota_changes('."'custom'".')" + />'.$lt{'defa'}.' ('.$defquota.' Mb).</label> '. + ' <label><input type="radio" name="customquota" value="1" '. + $custom_on.' onchange="javascript:quota_changes('."'custom'".')" />'. + $lt{'cust'}.':</label> '. '<input type="text" name="portfolioquota" size ="5" value="'. - &Apache::loncommon::get_user_quota($ccuname,$ccdomain). - '" /> Mb'; + $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '. + '/> Mb'; return $output; } @@ -234,7 +295,7 @@ sub print_user_modification_page { ); $loginscript = &Apache::loncommon::authform_header(%param); $authformkrb = &Apache::loncommon::authform_kerberos(%param); - + $ccuname =&LONCAPA::clean_username($ccuname); $ccdomain=&LONCAPA::clean_domain($ccdomain); my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition(); @@ -690,7 +751,7 @@ END $row.=' '; } my $plaintext=''; - unless ($croletitle) { + if (!$croletitle) { $plaintext=&Apache::lonnet::plaintext($role_code,$class) } else { $plaintext= @@ -1064,8 +1125,8 @@ ENDNEWUSERHEAD if (lc($desiredhost) eq 'default') { $desiredhost = undef; } else { - my %home_servers = &Apache::loncommon::get_library_servers - ($env{'form.ccdomain'}); + my %home_servers = + &Apache::lonnet::get_servers($env{'form.ccdomain'},'library'); if (! exists($home_servers{$desiredhost})) { $r->print($error.&mt('Invalid home server specified')); return; @@ -1082,7 +1143,7 @@ ENDNEWUSERHEAD my $home = &Apache::lonnet::homeserver($env{'form.ccuname'}, $env{'form.ccdomain'}); $r->print('<br />'.&mt('Home server').': '.$home.' '. - $Apache::lonnet::libserv{$home}); + &Apache::lonnet::hostname($home)); } elsif (($env{'form.login'} ne 'nochange') && ($env{'form.login'} ne '' )) { # Modify user privileges @@ -1115,7 +1176,8 @@ ENDMODIFYUSERHEAD # Check for need to change my %userenv = &Apache::lonnet::get ('environment',['firstname','middlename','lastname','generation', - 'portfolioquota'],$env{'form.ccdomain'},$env{'form.ccuname'}); + 'portfolioquota','inststatus'],$env{'form.ccdomain'}, + $env{'form.ccuname'}); my ($tmp) = keys(%userenv); if ($tmp =~ /^(con_lost|error)/i) { %userenv = (); @@ -1125,22 +1187,55 @@ ENDMODIFYUSERHEAD # Strip leading and trailing whitespace $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g; } - my ($quotachanged,$namechanged,$oldportfolioquota); + my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota, + $inststatus,$isdefault,$defquotatext); + my ($defquota,$settingstatus) = + &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus); my %changeHash; - if (exists($userenv{'portfolioquota'})) { + if ($userenv{'portfolioquota'} ne '') { $oldportfolioquota = $userenv{'portfolioquota'}; - if (exists($env{'form.portfolioquota'})) { - if ($env{'form.portfolioquota'} ne $userenv{'portfolioquota'}) { - if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) { - # Current user has quota modification privileges - $quotachanged = 1; - $changeHash{'portfolioquota'} = $env{'form.portfolioquota'}; - } + if ($env{'form.customquota'} == 1) { + if ($env{'form.portfolioquota'} eq '') { + $newportfolioquota = 0; + } else { + $newportfolioquota = $env{'form.portfolioquota'}; + $newportfolioquota =~ s/[^\d\.]//g; } + if ($newportfolioquota != $userenv{'portfolioquota'}) { + $quotachanged = "a_admin($newportfolioquota,\%changeHash); + } + } else { + $quotachanged = "a_admin('',\%changeHash); + $newportfolioquota = $defquota; + $isdefault = 1; } } else { - $oldportfolioquota = - &Apache::loncommon::default_quota($env{'form.ccdomain'}); + $oldportfolioquota = $defquota; + if ($env{'form.customquota'} == 1) { + if ($env{'form.portfolioquota'} eq '') { + $newportfolioquota = 0; + } else { + $newportfolioquota = $env{'form.portfolioquota'}; + $newportfolioquota =~ s/[^\d\.]//g; + } + $quotachanged = "a_admin($newportfolioquota,\%changeHash); + } else { + $newportfolioquota = $defquota; + $isdefault = 1; + } + } + if ($isdefault) { + if ($settingstatus eq '') { + $defquotatext = &mt('(default)'); + } else { + my ($usertypes,$order) = + &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'}); + if ($usertypes->{$settingstatus} eq '') { + $defquotatext = &mt('(default)'); + } else { + $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus}); + } + } } if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) && ($env{'form.cfirstname'} ne $userenv{'firstname'} || @@ -1184,16 +1279,24 @@ ENDMODIFYUSERHEAD <td>$userenv{'middlename'} </td> <td>$userenv{'lastname'} </td> <td>$userenv{'generation'} </td> - <td>$oldportfolioquota</td> + <td>$oldportfolioquota Mb</td> </tr> <tr><td>$lt{'chto'}</td> <td>$env{'form.cfirstname'} </td> <td>$env{'form.cmiddlename'} </td> <td>$env{'form.clastname'} </td> <td>$env{'form.cgeneration'} </td> - <td>$env{'form.portfolioquota'} Mb</td></tr> + <td>$newportfolioquota Mb $defquotatext </td></tr> </table> END + if (($env{'form.ccdomain'} eq $env{'user.domain'}) && + ($env{'form.ccuname'} eq $env{'user.name'})) { + my %newenvhash; + foreach my $key (keys(%changeHash)) { + $newenvhash{'environment.'.$key} = $changeHash{$key}; + } + &Apache::lonnet::appenv(%newenvhash); + } } else { # error occurred $r->print("<h2>".&mt('Unable to successfully change environment for')." ". $env{'form.ccuname'}." ".&mt('in domain')." ". @@ -1220,8 +1323,10 @@ END <h4>$lt{'gen'}: $userenv{'generation'}</h4> END if ($putresult eq 'ok') { - if ($oldportfolioquota ne $env{'form.portfolioquota'}) { - $r->print('<h4>'.$lt{'disk'}.': '.$env{'form.portfolioquota'}.' Mb</h4>'); + if ($oldportfolioquota != $newportfolioquota) { + $r->print('<h4>'.$lt{'disk'}.': '.$newportfolioquota.' Mb '. + $defquotatext.'</h4>'); + &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'}); } } } @@ -1446,6 +1551,17 @@ END $r->print(&Apache::loncommon::end_page()); } +sub quota_admin { + my ($setquota,$changeHash) = @_; + my $quotachanged; + if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) { + # Current user has quota modification privileges + $quotachanged = 1; + $changeHash->{'portfolioquota'} = $setquota; + } + return $quotachanged; +} + sub build_roles { my ($sectionstr,$sections,$role) = @_; my $num_sections = 0; @@ -1458,7 +1574,7 @@ sub build_roles { } else { foreach my $sec (@secnums) { $sec =~ ~s/\W//g; - unless ($sec eq "") { + if (!($sec eq "")) { if (exists($$sections{$sec})) { $$sections{$sec} ++; } else { @@ -1491,15 +1607,23 @@ sub custom_role_editor { $rolename=~s/[^A-Za-z0-9]//gs; - unless ($rolename) { + if (!$rolename) { &print_username_entry_form($r); return; } - - $r->print(&Apache::loncommon::start_page('Custom Role Editor')); + my $head_script = <<END_SCRIPT; + <script type="text/javascript"> + function setchecks() { + document.form1.bre_c.checked = false; + } + </script> +END_SCRIPT + + $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script)); my $syspriv=''; my $dompriv=''; my $coursepriv=''; + my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]); my ($rdummy,$roledef)= &Apache::lonnet::get('roles',["rolesdef_$rolename"]); # ------------------------------------------------------- Does this role exist? @@ -1517,9 +1641,15 @@ sub custom_role_editor { my %full=(); my %courselevel=(); my %courselevelcurrent=(); + my @roles = ("st:c","st:d"); + #foreach my $item (@roles) { + # &Apache::lonnet::logthis(" roles for $item: ".$Apache::lonnet::pr{$item}); + #} + foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) { + my ($priv,$restrict)=split(/\&/,$item); - unless ($restrict) { $restrict='F'; } + if (!$restrict) { $restrict='F'; } $courselevel{$priv}=$restrict; if ($coursepriv=~/\:$priv/) { $courselevelcurrent{$priv}=1; @@ -1530,7 +1660,7 @@ sub custom_role_editor { my %domainlevelcurrent=(); foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) { my ($priv,$restrict)=split(/\&/,$item); - unless ($restrict) { $restrict='F'; } + if (!$restrict) { $restrict='F'; } $domainlevel{$priv}=$restrict; if ($dompriv=~/\:$priv/) { $domainlevelcurrent{$priv}=1; @@ -1541,7 +1671,7 @@ sub custom_role_editor { my %systemlevelcurrent=(); foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) { my ($priv,$restrict)=split(/\&/,$item); - unless ($restrict) { $restrict='F'; } + if (!$restrict) { $restrict='F'; } $systemlevel{$priv}=$restrict; if ($syspriv=~/\:$priv/) { $systemlevelcurrent{$priv}=1; @@ -1552,10 +1682,10 @@ sub custom_role_editor { 'prv' => "Privilege", 'crl' => "Course Level", 'dml' => "Domain Level", - 'ssl' => "System Level" - ); + 'ssl' => "System Level"); + $r->print('<form action=""><input type="button" onClick="setchecks()" value="Click" /></form>'); $r->print(<<ENDCCF); -<form method="post"> +<form name=form1 method="post"> <input type="hidden" name="phase" value="set_custom_roles" /> <input type="hidden" name="rolename" value="$rolename" /> ENDCCF @@ -1568,13 +1698,13 @@ ENDCCF my $privtext = &Apache::lonnet::plaintext($priv); $r->print(&Apache::loncommon::start_data_table_row(). '<td>'.$privtext.'</td><td>'. - ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.':c" '. + ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '. ($courselevelcurrent{$priv}?'checked="1"':'').' />':' '). '</td><td>'. - ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.':d" '. + ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '. ($domainlevelcurrent{$priv}?'checked="1"':'').' />':' '). '</td><td>'. - ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.':s" '. + ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '. ($systemlevelcurrent{$priv}?'checked="1"':'').' />':' '). '</td>'. &Apache::loncommon::end_data_table_row()); @@ -1592,7 +1722,7 @@ sub set_custom_role { $rolename=~s/[^A-Za-z0-9]//gs; - unless ($rolename) { + if (!$rolename) { &print_username_entry_form($r); return; } @@ -1616,24 +1746,24 @@ sub set_custom_role { foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) { my ($priv,$restrict)=split(/\&/,$item); - unless ($restrict) { $restrict=''; } - if ($env{'form.'.$priv.':c'}) { + if (!$restrict) { $restrict=''; } + if ($env{'form.'.$priv.'_c'}) { $courole.=':'.$item; } } foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) { my ($priv,$restrict)=split(/\&/,$item); - unless ($restrict) { $restrict=''; } - if ($env{'form.'.$priv.':d'}) { + if (!$restrict) { $restrict=''; } + if ($env{'form.'.$priv.'_d'}) { $domrole.=':'.$item; } } foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) { my ($priv,$restrict)=split(/\&/,$item); - unless ($restrict) { $restrict=''; } - if ($env{'form.'.$priv.':s'}) { + if (!$restrict) { $restrict=''; } + if ($env{'form.'.$priv.'_s'}) { $sysrole.=':'.$item; } } @@ -1672,7 +1802,7 @@ sub handler { (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - unless ($env{'form.phase'}) { + if (!$env{'form.phase'}) { &print_username_entry_form($r); } if ($env{'form.phase'} eq 'get_user_info') {