--- loncom/interface/loncreateuser.pm 2012/08/21 15:43:27 1.365 +++ loncom/interface/loncreateuser.pm 2014/02/19 17:12:52 1.394 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.365 2012/08/21 15:43:27 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.394 2014/02/19 17:12:52 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -111,77 +111,51 @@ sub initialize_authen_forms { sub auth_abbrev { my %abv_auth = ( - krb5 => 'krb', - krb4 => 'krb', - internal => 'int', - localuth => 'loc', - unix => 'fsys', + krb5 => 'krb', + krb4 => 'krb', + internal => 'int', + localauth => 'loc', + unix => 'fsys', ); return %abv_auth; } # ==================================================== -sub portfolio_quota { +sub user_quotas { my ($ccuname,$ccdomain) = @_; my %lt = &Apache::lonlocal::texthash( 'usrt' => "User Tools", - 'disk' => "Disk space allocated to user's portfolio files", - 'cuqu' => "Current quota", 'cust' => "Custom quota", - 'defa' => "Default", 'chqu' => "Change quota", ); - 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"> // <![CDATA[ -function quota_changes(caller) { +function quota_changes(caller,context) { + var customoff = document.getElementById('custom_'+context+'quota_off'); + var customon = document.getElementById('custom_'+context+'quota_on'); + var number = document.getElementById(context+'quota'); if (caller == "custom") { - if (document.cu.customquota[0].checked) { - document.cu.portfolioquota.value = ""; + if (customoff) { + if (customoff.checked) { + number.value = ""; + } } } if (caller == "quota") { - document.cu.customquota[1].checked = true; + if (customon) { + customon.checked = true; + } } + return; } // ]]> </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 $longinsttype; + my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain); my $output = $quota_javascript."\n". '<h3>'.$lt{'usrt'}.'</h3>'."\n". &Apache::loncommon::start_data_table(); @@ -189,29 +163,72 @@ END_SCRIPT if (&Apache::lonnet::allowed('mut',$ccdomain)) { $output .= &build_tools_display($ccuname,$ccdomain,'tools'); } - if (&Apache::lonnet::allowed('mpq',$ccdomain)) { - $output .= '<tr class="LC_info_row">'."\n". - ' <td>'.$lt{'disk'}.'</td>'."\n". - ' </tr>'."\n". - &Apache::loncommon::start_data_table_row()."\n". - ' <td>'.$lt{'cuqu'}.': '. - $currquota.' Mb. '. - $defaultinfo.'</td>'."\n". - &Apache::loncommon::end_data_table_row()."\n". - &Apache::loncommon::start_data_table_row()."\n". - ' <td><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="'. - $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '. - '/> Mb</span></td>'."\n". - &Apache::loncommon::end_data_table_row()."\n"; - } + + my %titles = &Apache::lonlocal::texthash ( + portfolio => "Disk space allocated to user's portfolio files", + author => "Disk space allocated to user's Authoring Space (if role assigned)", + ); + foreach my $name ('portfolio','author') { + my ($currquota,$quotatype,$inststatus,$defquota) = + &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name); + if ($longinsttype eq '') { + if ($inststatus ne '') { + if ($usertypes->{$inststatus} ne '') { + $longinsttype = $usertypes->{$inststatus}; + } + } + } + my ($showquota,$custom_on,$custom_off,$defaultinfo); + $custom_on = ' '; + $custom_off = ' checked="checked" '; + 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); + } + } + + if (&Apache::lonnet::allowed('mpq',$ccdomain)) { + $output .= '<tr class="LC_info_row">'."\n". + ' <td>'.$titles{$name}.'</td>'."\n". + ' </tr>'."\n". + &Apache::loncommon::start_data_table_row()."\n". + ' <td><span class="LC_nobreak">'. + &mt('Current quota: [_1] MB',$currquota).'</span> '. + $defaultinfo.'</td>'."\n". + &Apache::loncommon::end_data_table_row()."\n". + &Apache::loncommon::start_data_table_row()."\n". + ' <td><span class="LC_nobreak">'.$lt{'chqu'}. + ': <label>'. + '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '. + 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'. + ' /><span class="LC_nobreak">'. + &mt('Default ([_1] MB)',$defquota).'</span></label> '. + ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '. + 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'. + ' />'.$lt{'cust'}.':</label> '. + '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '. + 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'. + ' /> '.&mt('MB').'</span></td>'."\n". + &Apache::loncommon::end_data_table_row()."\n"; + } + } $output .= &Apache::loncommon::end_data_table(); return $output; } @@ -223,7 +240,7 @@ sub build_tools_display { my %lt = &Apache::lonlocal::texthash ( 'blog' => "Personal User Blog", 'aboutme' => "Personal Information Page", - 'webdav' => "WebDAV access to authoring spaces (if SSL and author/co-author)", + 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)", 'portfolio' => "Personal User Portfolio", 'avai' => "Available", 'cusa' => "availability", @@ -233,13 +250,14 @@ sub build_tools_display { 'official' => 'Can request creation of official courses', 'unofficial' => 'Can request creation of unofficial courses', 'community' => 'Can request creation of communities', + 'textbook' => 'Can request creation of textbook courses', 'requestauthor' => 'Can request author space', ); if ($context eq 'requestcourses') { %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname, 'requestcourses.official','requestcourses.unofficial', - 'requestcourses.community'); - @usertools = ('official','unofficial','community'); + 'requestcourses.community','requestcourses.textbook'); + @usertools = ('official','unofficial','community','textbook'); @options =('norequest','approval','autolimit','validate'); %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain); %reqtitles = &courserequest_titles(); @@ -428,12 +446,13 @@ sub coursereq_externaluser { 'official' => 'Can request creation of official courses', 'unofficial' => 'Can request creation of unofficial courses', 'community' => 'Can request creation of communities', + 'textbook' => 'Can request creation of textbook courses', ); %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname, 'reqcrsotherdom.official','reqcrsotherdom.unofficial', - 'reqcrsotherdom.community'); - @usertools = ('official','unofficial','community'); + 'reqcrsotherdom.community','reqcrsotherdom.textbook'); + @usertools = ('official','unofficial','community','textbook'); @options = ('approval','validate','autolimit'); %validations = &Apache::lonnet::auto_courserequest_checks($cdom); my $optregex = join('|',@options); @@ -513,6 +532,7 @@ sub courserequest_titles { official => 'Official', unofficial => 'Unofficial', community => 'Communities', + textbook => 'Textbook', norequest => 'Not allowed', approval => 'Approval by Dom. Coord.', validate => 'With validation', @@ -550,6 +570,15 @@ sub requestauthor_display { return %titles; } +sub requestchange_display { + my %titles = &Apache::lonlocal::texthash ( + approval => "availability set to 'on' (approval required)", + automatic => "availability set to 'on' (automatic approval)", + norequest => "availability set to 'off'", + ); + return %titles; +} + sub curr_requestauthor { my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_; return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH')); @@ -970,7 +999,7 @@ ENDSCRIPT $r->print('</h3>'); } } - $r->print('<form name="usersrchform" method="post">'. + $r->print('<form name="usersrchform" method="post" action="">'. &Apache::loncommon::start_data_table()."\n". &Apache::loncommon::start_data_table_header_row()."\n". ' <th> </th>'."\n"); @@ -1042,7 +1071,8 @@ sub print_user_query_page { } sub print_user_modification_page { - my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,$brcrum) = @_; + my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype, + $brcrum,$showcredits) = @_; if (($ccuname eq '') || ($ccdomain eq '')) { my $usermsg = &mt('No username and/or domain provided.'); $env{'form.phase'} = ''; @@ -1133,7 +1163,7 @@ sub print_user_modification_page { my $groupslist = &Apache::lonuserutils::get_groupslist(); - my $js = &validation_javascript($context,$ccdomain,$pjump_def, + my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype, $groupslist,$newuser,$formname,\%loaditem); my %breadcrumb_text = &singleuser_breadcrumb($crstype); my $helpitem = 'Course_Change_Privileges'; @@ -1176,10 +1206,13 @@ sub print_user_modification_page { <input type="hidden" name="pres_type" value="" /> <input type="hidden" name="pres_marker" value="" /> ENDFORMINFO - my (%inccourses,$roledom); + my (%inccourses,$roledom,$defaultcredits); if ($context eq 'course') { $inccourses{$env{'request.course.id'}}=1; $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + if ($showcredits) { + $defaultcredits = &Apache::lonuserutils::get_defaultcredits(); + } } elsif ($context eq 'author') { $roledom = $env{'request.role.domain'}; } elsif ($context eq 'domain') { @@ -1196,22 +1229,20 @@ ENDFORMINFO } } } + my $title = ''; if ($newuser) { my ($portfolioform,$domroleform); if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) || (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) { # Current user has quota or user tools modification privileges - $portfolioform = '<br />'.&portfolio_quota($ccuname,$ccdomain); + $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain); } - if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) { + if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) && + ($ccdomain eq $env{'request.role.domain'})) { $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain); } &initialize_authen_forms($ccdomain,$formname); my %lt=&Apache::lonlocal::texthash( - 'cnu' => 'Create New User', - 'ast' => 'as a student', - 'ame' => 'as a member', - 'ind' => 'in domain', 'lg' => 'Login Data', 'hs' => "Home Server", ); @@ -1225,20 +1256,24 @@ $loginscript // ]]> </script> <input type='hidden' name='makeuser' value='1' /> -<h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain ENDTITLE if ($env{'form.action'} eq 'singlestudent') { if ($crstype eq 'Community') { - $r->print(' ('.$lt{'ame'}.')'); + $title = &mt('Create New User [_1] in domain [_2] as a member', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } else { - $r->print(' ('.$lt{'ast'}.')'); + $title = &mt('Create New User [_1] in domain [_2] as a student', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } + } else { + $title = &mt('Create New User [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } - $r->print('</h2>'."\n".'<div class="LC_left_float">'); - my $personal_table = - &personal_data_display($ccuname,$ccdomain,$newuser,$context, - $inst_results{$ccuname.':'.$ccdomain}); - $r->print($personal_table); + $r->print('<h2>'.$title.'</h2>'."\n"); + $r->print('<div class="LC_left_float">'); + $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context, + $inst_results{$ccuname.':'.$ccdomain})); + # Option to disable student/employee ID conflict checking not offerred for new users. my ($home_server_pick,$numlib) = &Apache::loncommon::home_server_form_item($ccdomain,'hserver', 'default','hide'); @@ -1319,39 +1354,28 @@ ENDAUTH $r->print($portfolioform.$domroleform); if ($env{'form.action'} eq 'singlestudent') { $r->print(&date_sections_select($context,$newuser,$formname, - $permission)); + $permission,$crstype,$ccuname, + $ccdomain,$showcredits)); } $r->print('</div><div class="LC_clear_float_footer"></div>'); } else { # user already exists - my %lt=&Apache::lonlocal::texthash( - 'cup' => "Modify existing user: ", - 'ens' => "Enroll one student: ", - 'enm' => "Enroll one member: ", - 'id' => "in domain", - ); - $r->print(<<ENDCHANGEUSER); -$start_page -$forminfo -<h2> -ENDCHANGEUSER + $r->print($start_page.$forminfo); if ($env{'form.action'} eq 'singlestudent') { if ($crstype eq 'Community') { - $r->print($lt{'enm'}); + $title = &mt('Enroll one member: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } else { - $r->print($lt{'ens'}); + $title = &mt('Enroll one student: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } } else { - $r->print($lt{'cup'}); - } - $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'. - "\n".'<div class="LC_left_float">'); - my ($personal_table,$showforceid) = - &personal_data_display($ccuname,$ccdomain,$newuser,$context, - $inst_results{$ccuname.':'.$ccdomain}); - $r->print($personal_table); - if ($showforceid) { - $r->print('<table>'.&Apache::lonuserutils::forceid_change($context).'</table>'); + $title = &mt('Modify existing user: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } + $r->print('<h2>'.$title.'</h2>'."\n"); + $r->print('<div class="LC_left_float">'); + $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context, + $inst_results{$ccuname.':'.$ccdomain})); if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) { $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'. &Apache::loncommon::start_data_table()); @@ -1369,23 +1393,21 @@ ENDCHANGEUSER my ($isadv,$isauthor) = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain); if ((!$isauthor) && - (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) { + (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) + && ($env{'request.role.domain'} eq $ccdomain)) { $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain); } $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname); if ((&Apache::lonnet::allowed('mpq',$ccdomain)) || (&Apache::lonnet::allowed('mut',$ccdomain))) { # Current user has quota modification privileges - $user_text{'quota'} = &portfolio_quota($ccuname,$ccdomain); + $user_text{'quota'} = &user_quotas($ccuname,$ccdomain); } if (!&Apache::lonnet::allowed('mpq',$ccdomain)) { if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) { - # Get the user's portfolio information - my %portq = &Apache::lonnet::get('environment',['portfolioquota'], - $ccdomain,$ccuname); my %lt=&Apache::lonlocal::texthash( - 'dska' => "Disk space allocated to user's portfolio files", - 'youd' => "You do not have privileges to modify the portfolio quota for this user.", + 'dska' => "Disk quotas for user's portfolio and Authoring Space", + 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.", 'ichr' => "If a change is required, contact a domain coordinator for the domain", ); $user_text{'quota'} = <<ENDNOPORTPRIV; @@ -1421,8 +1443,17 @@ ENDNOTOOLSPRIV unless ($gotdiv) { $r->print('<div class="LC_left_float">'); } - $r->print(&date_sections_select($context,$newuser,$formname)); - } + my $credits; + if ($showcredits) { + $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits); + if ($credits eq '') { + $credits = $defaultcredits; + } + } + $r->print(&date_sections_select($context,$newuser,$formname, + $permission,$crstype,$ccuname, + $ccdomain,$showcredits)); + } if ($gotdiv) { $r->print('</div><div class="LC_clear_float_footer"></div>'); } @@ -1440,7 +1471,8 @@ ENDNOTOOLSPRIV } $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n"); } else { - $r->print('<h3>'.&mt('Add Roles').'</h3>'); + $r->print('<div class="LC_left_float">'. + '<fieldset><legend>'.&mt('Add Roles').'</legend>'); my $addrolesdisplay = 0; if ($context eq 'domain' || $context eq 'author') { $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain); @@ -1450,28 +1482,33 @@ ENDNOTOOLSPRIV if (!$addrolesdisplay) { $addrolesdisplay = $add_domainroles; } - $r->print(&course_level_dc($env{'request.role.domain'},'Course')); - $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n"); + $r->print(&course_level_dc($env{'request.role.domain'},$showcredits)); + $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'. + '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n"); } elsif ($context eq 'author') { if ($addrolesdisplay) { - $r->print('<br /><input type="button" value="'.&mt('Save').'"'); + $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'. + '<br /><input type="button" value="'.&mt('Save').'"'); if ($newuser) { $r->print(' onclick="auth_check()" \>'."\n"); } else { $r->print('onclick="this.form.submit()" \>'."\n"); } } else { - $r->print('<br /><a href="javascript:backPage(document.cu)">'. + $r->print('</fieldset></div>'. + '<div class="LC_clear_float_footer"></div>'. + '<br /><a href="javascript:backPage(document.cu)">'. &mt('Back to previous page').'</a>'); } } else { - $r->print(&course_level_table(%inccourses)); - $r->print('<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n"); + $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits)); + $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'. + '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n"); } } $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain'])); $r->print('<input type="hidden" name="currstate" value="" />'); - $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form>'); + $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />'); return; } @@ -1495,22 +1532,32 @@ sub singleuser_breadcrumb { } sub date_sections_select { - my ($context,$newuser,$formname,$permission) = @_; + my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain, + $showcredits) = @_; + my $credits; + if ($showcredits) { + my $defaultcredits = &Apache::lonuserutils::get_defaultcredits(); + $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits); + if ($credits eq '') { + $credits = $defaultcredits; + } + } my $cid = $env{'request.course.id'}; my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid); my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n". &Apache::lonuserutils::date_setting_table(undef,undef,$context, undef,$formname,$permission); my $rowtitle = 'Section'; - my $secbox = '<h3>'.&mt('Section').'</h3>'."\n". + my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n". &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle, - $permission); + $permission,$context,'',$crstype, + $showcredits,$credits); my $output = $date_table.$secbox; return $output; } sub validation_javascript { - my ($context,$ccdomain,$pjump_def,$groupslist,$newuser,$formname, + my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname, $loaditem) = @_; my $dc_setcourse_code = ''; my $nondc_setsection_code = ''; @@ -1527,7 +1574,8 @@ sub validation_javascript { if ($context eq 'course') { $nondc_setsection_code = &Apache::lonuserutils::setsections_javascript($formname,$groupslist, - undef,$checkauth); + undef,$checkauth, + $crstype); } if ($checkauth) { $nondc_setsection_code .= @@ -1547,7 +1595,8 @@ sub validation_javascript { } sub display_existing_roles { - my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype) = @_; + my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype, + $showcredits) = @_; my $now=time; my %lt=&Apache::lonlocal::texthash( 'rer' => "Existing Roles", @@ -1556,6 +1605,7 @@ sub display_existing_roles { 'ren' => "Re-Enable", 'rol' => "Role", 'ext' => "Extent", + 'crd' => "Credits", 'sta' => "Start", 'end' => "End", ); @@ -1618,6 +1668,7 @@ sub display_existing_roles { my $delallowed=0; my $sortkey=$role_code; my $class='Unknown'; + my $credits=''; if ($area =~ m{^/($match_domain)/($match_courseid)} ) { $class='Course'; my ($coursedom,$coursedir) = ($1,$2); @@ -1646,6 +1697,15 @@ sub display_existing_roles { } $sortkey.="\0$coursedir"; $inccourses->{$cid}=1; + if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) { + my $defaultcredits = $coursedata{'internal.defaultcredits'}; + $credits = + &get_user_credits($ccuname,$ccdomain,$defaultcredits, + $coursedom,$coursedir); + if ($credits eq '') { + $credits = $defaultcredits; + } + } if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) || (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) { $allowed=1; @@ -1672,7 +1732,7 @@ sub display_existing_roles { } } if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) { - $carea.='<br />Section: '.$3; + $carea.='<br />'.&mt('Section: [_1]',$3); $sortkey.="\0$3"; if (!$allowed) { if ($env{'request.course.sec'} eq $3) { @@ -1702,7 +1762,7 @@ sub display_existing_roles { } } if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') { - $class='Construction Space'; + $class='Authoring Space'; } elsif ($role_code eq 'su') { $class='System'; } else { @@ -1744,7 +1804,13 @@ sub display_existing_roles { } my $plaintext=''; if (!$croletitle) { - $plaintext=&Apache::lonnet::plaintext($role_code,$class) + $plaintext=&Apache::lonnet::plaintext($role_code,$class); + if (($showcredits) && ($credits ne '')) { + $plaintext .= '<br/ ><span class="LC_nobreak">'. + '<span class="LC_fontsize_small">'. + &mt('Credits: [_1]',$credits). + '</span></span>'; + } } else { $plaintext= &mt('Customrole [_1][_2]defined by [_3]', @@ -1767,7 +1833,7 @@ sub display_existing_roles { my $rolesdisplay = 0; my %output = (); - foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') { + foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') { $output{$type} = ''; foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) { if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) { @@ -1793,25 +1859,25 @@ sub display_existing_roles { $contextrole = &mt('Existing Roles in this Course'); } } elsif ($env{'request.role'} =~ /^au\./) { - $contextrole = &mt('Existing Co-Author Roles in your Construction Space'); + $contextrole = &mt('Existing Co-Author Roles in your Authoring Space'); } else { $contextrole = &mt('Existing Roles in this Domain'); } - $r->print(' -<h3>'.$lt{'rer'}.'</h3>'. -'<div>'.$contextrole.'</div>'. + $r->print('<div class="LC_left_float">'. +'<fieldset><legend>'.$contextrole.'</legend>'. &Apache::loncommon::start_data_table("LC_createuser"). &Apache::loncommon::start_data_table_header_row(). '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}. '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}. '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'. &Apache::loncommon::end_data_table_header_row()); - foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') { + foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') { if ($output{$type}) { $r->print($output{$type}."\n"); } } - $r->print(&Apache::loncommon::end_data_table()); + $r->print(&Apache::loncommon::end_data_table(). + '</fieldset></div>'); } return; } @@ -1830,7 +1896,7 @@ sub new_coauthor_roles { my $cuname=$env{'user.name'}; my $cudom=$env{'request.role.domain'}; my %lt=&Apache::lonlocal::texthash( - 'cs' => "Construction Space", + 'cs' => "Authoring Space", 'act' => "Activate", 'rol' => "Role", 'ext' => "Extent", @@ -1881,7 +1947,7 @@ sub new_coauthor_roles { '</span>'); } elsif (($env{'user.name'} eq $ccuname) && ($env{'user.domain'} eq $ccdomain)) { - $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted')); + $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Authoring Space is not permitted')); } } return $addrolesdisplay;; @@ -2097,13 +2163,37 @@ sub modify_login_block { } sub personal_data_display { - my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_; - my ($output,$showforceid,%userenv,%canmodify,%canmodify_status); + my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray, + $now,$captchaform,$emailusername) = @_; + my ($output,%userenv,%canmodify,%canmodify_status); my @userinfo = ('firstname','middlename','lastname','generation', 'permanentemail','id'); my $rowcount = 0; my $editable = 0; - %canmodify_status = + my %textboxsize = ( + firstname => '15', + middlename => '15', + lastname => '15', + generation => '5', + permanentemail => '25', + id => '15', + ); + + my %lt=&Apache::lonlocal::texthash( + 'pd' => "Personal Data", + 'firstname' => "First Name", + 'middlename' => "Middle Name", + 'lastname' => "Last Name", + 'generation' => "Generation", + 'permanentemail' => "Permanent e-mail address", + 'id' => "Student/Employee ID", + 'lg' => "Login Data", + 'inststatus' => "Affiliation", + 'email' => 'E-mail address', + 'valid' => 'Validation', + ); + + %canmodify_status = &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain, ['inststatus'],$rolesarray); if (!$newuser) { @@ -2115,31 +2205,53 @@ sub personal_data_display { &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain, \@userinfo,$rolesarray); } elsif ($context eq 'selfcreate') { - %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo, - $inst_results,$rolesarray); + if ($newuser eq 'email') { + if (ref($emailusername) eq 'HASH') { + my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info(); + @userinfo = (); + if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) { + foreach my $field (@{$infofields}) { + if ($emailusername->{$field}) { + push(@userinfo,$field); + $canmodify{$field} = 1; + unless ($textboxsize{$field}) { + $textboxsize{$field} = 25; + } + unless ($lt{$field}) { + $lt{$field} = $infotitles->{$field}; + } + } + } + } + } + } else { + %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo, + $inst_results,$rolesarray); + } } - my %lt=&Apache::lonlocal::texthash( - 'pd' => "Personal Data", - 'firstname' => "First Name", - 'middlename' => "Middle Name", - 'lastname' => "Last Name", - 'generation' => "Generation", - 'permanentemail' => "Permanent e-mail address", - 'id' => "Student/Employee ID", - 'lg' => "Login Data", - 'inststatus' => "Affiliation", - ); - my %textboxsize = ( - firstname => '15', - middlename => '15', - lastname => '15', - generation => '5', - permanentemail => '25', - id => '15', - ); + my $genhelp=&Apache::loncommon::help_open_topic('Generation'); $output = '<h3>'.$lt{'pd'}.'</h3>'. &Apache::lonhtmlcommon::start_pick_box(); + if (($context eq 'selfcreate') && ($newuser eq 'email')) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'email'},undef, + 'LC_oddrow_value')."\n". + '<input type="text" name="uname" size="25" value="" autocomplete="off" />'; + $rowcount ++; + $output .= &Apache::lonhtmlcommon::row_closure(1); + my $upassone = '<input type="password" name="upass'.$now.'" size="10" autocomplete="off" />'; + my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="10" autocomplete="off" />'; + $output .= &Apache::lonhtmlcommon::row_title(&mt('Password'), + 'LC_pick_box_title', + 'LC_oddrow_value')."\n". + $upassone."\n". + &Apache::lonhtmlcommon::row_closure(1)."\n". + &Apache::lonhtmlcommon::row_title(&mt('Confirm password'), + 'LC_pick_box_title', + 'LC_oddrow_value')."\n". + $upasstwo. + &Apache::lonhtmlcommon::row_closure()."\n"; + } foreach my $item (@userinfo) { my $rowtitle = $lt{$item}; my $hiderow = 0; @@ -2153,8 +2265,8 @@ sub personal_data_display { $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item}; } else { if ($context eq 'selfcreate') { - if ($canmodify{$item}) { - $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />'; + if ($canmodify{$item}) { + $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />'; $editable ++; } else { $hiderow = 1; @@ -2169,7 +2281,11 @@ sub personal_data_display { $row .= $ccuname; } else { if ($canmodify{$item}) { - $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />'; + if ($newuser eq 'email') { + $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />'; + } else { + $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />'; + } $editable ++; } else { $hiderow = 1; @@ -2182,12 +2298,12 @@ sub personal_data_display { } else { if ($canmodify{$item}) { $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />'; + if (($item eq 'id') && (!$newuser)) { + $row .= '<br />'.&Apache::lonuserutils::forceid_change($context); + } } else { $row .= $userenv{$item}; } - if ($item eq 'id') { - $showforceid = $canmodify{$item}; - } } $row .= &Apache::lonhtmlcommon::row_closure(1); if (!$hiderow) { @@ -2222,7 +2338,7 @@ sub personal_data_display { } } if (!$hiderow) { - my $row = &Apache::lonhtmlcommon::row_title(&mt('Affliations'),undef,'LC_oddrow_value')."\n". + my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n". $shown.&Apache::lonhtmlcommon::row_closure(1); if ($context eq 'selfcreate') { $rowcount ++; @@ -2232,12 +2348,26 @@ sub personal_data_display { } } } + if (($context eq 'selfcreate') && ($newuser eq 'email')) { + if ($captchaform) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}, + 'LC_pick_box_title')."\n". + $captchaform."\n".'<br /><br />'. + &Apache::lonhtmlcommon::row_closure(1); + $rowcount ++; + } + my $submit_text = &mt('Create account'); + $output .= &Apache::lonhtmlcommon::row_title()."\n". + '<br /><input type="submit" name="createaccount" value="'. + $submit_text.'" />'. + &Apache::lonhtmlcommon::row_closure(1); + } $output .= &Apache::lonhtmlcommon::end_pick_box(); if (wantarray) { if ($context eq 'selfcreate') { return($output,$rowcount,$editable); } else { - return ($output,$showforceid); + return $output; } } else { return $output; @@ -2314,7 +2444,7 @@ sub get_inststatuses { # ================================================================= Phase Three sub update_user_data { - my ($r,$context,$crstype,$brcrum) = @_; + my ($r,$context,$crstype,$brcrum,$showcredits) = @_; my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'}, $env{'form.ccdomain'}); # Error messages @@ -2402,9 +2532,12 @@ sub update_user_data { if (! exists($env{'form.makeuser'})) { # Modifying an existing user, so check the validity of the name if ($uhome eq 'no_host') { - $r->print($error.&mt('Unable to determine home server for '). - $env{'form.ccuname'}.&mt(' in domain '). - $env{'form.ccdomain'}.'.'); + $r->print( + $error + .'<p class="LC_error">' + .&mt('Unable to determine home server for [_1] in domain [_2].', + '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"') + .'</p>'); return; } } @@ -2432,18 +2565,19 @@ sub update_user_data { # If they are creating a new user but have not specified login # information this will be caught below. } else { - $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink); - return; + $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink); + return; } $r->print('<h3>'.&mt('User [_1] in domain [_2]', - $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>'); - $r->print('<p class="LC_info">'.&mt('Please be patient').'</p>'); + $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'}, + $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>'); + my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2); my (%alerts,%rulematch,%inst_results,%curr_rules); my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id'); my @usertools = ('aboutme','blog','webdav','portfolio'); - my @requestcourses = ('official','unofficial','community'); + my @requestcourses = ('official','unofficial','community','textbook'); my @requestauthor = ('requestauthor'); my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'}); @@ -2499,6 +2633,7 @@ sub update_user_data { } } } + &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state); # Call modifyuser my $result = &Apache::lonnet::modifyuser ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'}, @@ -2512,14 +2647,18 @@ sub update_user_data { my (%changeHash,%newcustom,%changed,%changedinfo); if ($uhome ne 'no_host') { if ($context eq 'domain') { - if ($env{'form.customquota'} == 1) { - if ($env{'form.portfolioquota'} eq '') { - $newcustom{'quota'} = 0; - } else { - $newcustom{'quota'} = $env{'form.portfolioquota'}; - $newcustom{'quota'} =~ s/[^\d\.]//g; + foreach my $name ('portfolio','author') { + if ($env{'form.custom_'.$name.'quota'} == 1) { + if ($env{'form.'.$name.'quota'} eq '') { + $newcustom{$name.'quota'} = 0; + } else { + $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'}; + $newcustom{$name.'quota'} =~ s/[^\d\.]//g; + } + if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) { + $changed{$name.'quota'} = 1; + } } - $changed{'quota'} = "a_admin($newcustom{'quota'},\%changeHash); } foreach my $item (@usertools) { if ($env{'form.custom'.$item} == 1) { @@ -2533,7 +2672,8 @@ sub update_user_data { $newcustom{$item} = $env{'form.crsreq_'.$item}; if ($env{'form.crsreq_'.$item} eq 'autolimit') { $newcustom{$item} .= '='; - unless ($env{'form.crsreq_'.$item.'_limit'} =~ /\D/) { + $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g; + if ($env{'form.crsreq_'.$item.'_limit'}) { $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'}; } } @@ -2588,24 +2728,28 @@ sub update_user_data { $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end); } } - $r->rflush(); # Finish display of header before time consuming actions start - + &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state); ## - my (@userroles,%userupdate,$cnum,$cdom,%namechanged); + my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged); if ($context eq 'course') { - ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity(); + ($cnum,$cdom) = + &Apache::lonuserutils::get_course_identity(); $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum); + if ($showcredits) { + $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum); + } } if (! $env{'form.makeuser'} ) { # Check for need to change my %userenv = &Apache::lonnet::get ('environment',['firstname','middlename','lastname','generation', - 'id','permanentemail','portfolioquota','inststatus','tools.aboutme', - 'tools.blog','tools.webdav','tools.portfolio', + 'id','permanentemail','portfolioquota','authorquota','inststatus', + 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio', 'requestcourses.official','requestcourses.unofficial', - 'requestcourses.community','reqcrsotherdom.official', - 'reqcrsotherdom.unofficial','reqcrsotherdom.community', + 'requestcourses.community','requestcourses.textbook', + 'reqcrsotherdom.official','reqcrsotherdom.unofficial', + 'reqcrsotherdom.community','reqcrsotherdom.textbook', 'requestauthor'], $env{'form.ccdomain'},$env{'form.ccuname'}); my ($tmp) = keys(%userenv); @@ -2728,10 +2872,10 @@ sub update_user_data { } } } - my ($quotachanged,$oldportfolioquota,$newportfolioquota,$oldinststatus, - $newinststatus,$oldisdefault,$newisdefault,%oldsettings, + my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota, + $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings, %oldsettingstext,%newsettings,%newsettingstext,@disporder, - $olddefquota,$oldsettingstatus,$newdefquota,$newsettingstatus); + %oldsettingstatus,%newsettingstatus); @disporder = ('inststatus'); if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) { push(@disporder,'requestcourses','requestauthor'); @@ -2740,9 +2884,11 @@ sub update_user_data { } push(@disporder,('quota','tools')); $oldinststatus = $userenv{'inststatus'}; - ($olddefquota,$oldsettingstatus) = - &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus); - ($newdefquota,$newsettingstatus) = ($olddefquota,$oldsettingstatus); + foreach my $name ('portfolio','author') { + ($olddefquota{$name},$oldsettingstatus{$name}) = + &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name); + ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name}); + } my %canshow; if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) { $canshow{'quota'} = 1; @@ -2781,8 +2927,10 @@ sub update_user_data { $changeHash{'inststatus'} = $newinststatus; if ($newinststatus ne $oldinststatus) { $changed{'inststatus'} = $newinststatus; - ($newdefquota,$newsettingstatus) = - &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus); + foreach my $name ('portfolio','author') { + ($newdefquota{$name},$newsettingstatus{$name}) = + &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name); + } } if (ref($usertypes) eq 'HASH') { $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses)); @@ -2796,61 +2944,78 @@ sub update_user_data { $newsettings{'inststatus'} = $othertitle; if ($newinststatus ne $oldinststatus) { $changed{'inststatus'} = $changeHash{'inststatus'}; - ($newdefquota,$newsettingstatus) = - &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus); + foreach my $name ('portfolio','author') { + ($newdefquota{$name},$newsettingstatus{$name}) = + &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name); + } } } } elsif ($context ne 'selfcreate') { $canshow{'inststatus'} = 1; $newsettings{'inststatus'} = $oldsettings{'inststatus'}; } - $changeHash{'portfolioquota'} = $userenv{'portfolioquota'}; + foreach my $name ('portfolio','author') { + $changeHash{$name.'quota'} = $userenv{$name.'quota'}; + } if ($context eq 'domain') { - if ($userenv{'portfolioquota'} ne '') { - $oldportfolioquota = $userenv{'portfolioquota'}; - if ($env{'form.customquota'} == 1) { - if ($env{'form.portfolioquota'} eq '') { - $newportfolioquota = 0; + foreach my $name ('portfolio','author') { + if ($userenv{$name.'quota'} ne '') { + $oldquota{$name} = $userenv{$name.'quota'}; + if ($env{'form.custom_'.$name.'quota'} == 1) { + if ($env{'form.'.$name.'quota'} eq '') { + $newquota{$name} = 0; + } else { + $newquota{$name} = $env{'form.'.$name.'quota'}; + $newquota{$name} =~ s/[^\d\.]//g; + } + if ($newquota{$name} != $oldquota{$name}) { + if ("a_admin($newquota{$name},\%changeHash,$name)) { + $changed{$name.'quota'} = 1; + } + } } else { - $newportfolioquota = $env{'form.portfolioquota'}; - $newportfolioquota =~ s/[^\d\.]//g; - } - if ($newportfolioquota != $oldportfolioquota) { - $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash); + if ("a_admin('',\%changeHash,$name)) { + $changed{$name.'quota'} = 1; + $newquota{$name} = $newdefquota{$name}; + $newisdefault{$name} = 1; + } } } else { - $changed{'quota'} = "a_admin('',\%changeHash); - $newportfolioquota = $newdefquota; - $newisdefault = 1; - } - } else { - $oldisdefault = 1; - $oldportfolioquota = $olddefquota; - if ($env{'form.customquota'} == 1) { - if ($env{'form.portfolioquota'} eq '') { - $newportfolioquota = 0; + $oldisdefault{$name} = 1; + $oldquota{$name} = $olddefquota{$name}; + if ($env{'form.custom_'.$name.'quota'} == 1) { + if ($env{'form.'.$name.'quota'} eq '') { + $newquota{$name} = 0; + } else { + $newquota{$name} = $env{'form.'.$name.'quota'}; + $newquota{$name} =~ s/[^\d\.]//g; + } + if ("a_admin($newquota{$name},\%changeHash,$name)) { + $changed{$name.'quota'} = 1; + } } else { - $newportfolioquota = $env{'form.portfolioquota'}; - $newportfolioquota =~ s/[^\d\.]//g; + $newquota{$name} = $newdefquota{$name}; + $newisdefault{$name} = 1; } - $changed{'quota'} = "a_admin($newportfolioquota,\%changeHash); + } + if ($oldisdefault{$name}) { + $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name}); + } else { + $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name}); + } + if ($newisdefault{$name}) { + $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name}); } else { - $newportfolioquota = $newdefquota; - $newisdefault = 1; + $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name}); } } - if ($oldisdefault) { - $oldsettingstext{'quota'} = &get_defaultquota_text($oldsettingstatus); - } - if ($newisdefault) { - $newsettingstext{'quota'} = &get_defaultquota_text($newsettingstatus); - } &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv, \%changeHash,\%changed,\%newsettings,\%newsettingstext); if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) { &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext, \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext); - &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,\%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext); + &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext, + \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext); } else { &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext, \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext); @@ -2861,8 +3026,10 @@ sub update_user_data { $namechanged{$item} = 1; } } - $oldsettings{'quota'} = $oldportfolioquota.' Mb'; - $newsettings{'quota'} = $newportfolioquota.' Mb'; + foreach my $name ('portfolio','author') { + $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name}); + $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name}); + } if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) { my ($chgresult,$namechgresult); if (keys(%changed) > 0) { @@ -2902,7 +3069,8 @@ sub update_user_data { $changeHash{'tools.'.$key}; } else { $newenvhash{'environment.availabletools.'.$key} = - &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'}, $key,'reload','tools'); + &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'}, + $key,'reload','tools'); } } } @@ -2959,9 +3127,12 @@ sub update_user_data { &Apache::lonnet::appenv(\%newenvhash); } } else { # error occurred - $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '. - $env{'form.ccuname'}.' '.&mt('in domain').' '. - $env{'form.ccdomain'}.'</span><br />'); + $r->print( + '<p class="LC_error">' + .&mt('Unable to successfully change environment for [_1] in domain [_2].', + '"'.$env{'form.ccuname'}.'"', + '"'.$env{'form.ccdomain'}.'"') + .'</p>'); } } else { # End of if ($env ... ) logic # They did not want to change the users name, quota, tool availability, @@ -3005,17 +3176,20 @@ sub update_user_data { .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules) .'</span>'); } + &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); if ($env{'form.action'} eq 'singlestudent') { - &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype); - $r->print('<p><a href="javascript:backPage(document.userupdate)">'); - if ($crstype eq 'Community') { - $r->print(&mt('Enroll Another Member')); - } else { - $r->print(&mt('Enroll Another Student')); - } - $r->print('</a></p>'); + &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context, + $crstype,$showcredits,$defaultcredits); + my $linktext = ($crstype eq 'Community' ? + &mt('Enroll Another Member') : &mt('Enroll Another Student')); + $r->print( + &Apache::lonhtmlcommon::actionbox([ + '<a href="javascript:backPage(document.userupdate)">' + .($crstype eq 'Community' ? + &mt('Enroll Another Member') : &mt('Enroll Another Student')) + .'</a>'])); } else { - my @rolechanges = &update_roles($r,$context); + my @rolechanges = &update_roles($r,$context,$showcredits); if (keys(%namechanged) > 0) { if ($context eq 'course') { if (@userroles > 0) { @@ -3036,10 +3210,9 @@ sub update_user_data { if ($env{'form.popup'}) { $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>'); } else { - $r->print('<p><a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">' - .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>' - .(' 'x5).'<a href="javascript:backPage(document.userupdate)">' - .&mt('Create/Modify Another User').'</a></p>'); + $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">' + .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>', + '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>'])); } } } @@ -3060,7 +3233,7 @@ sub display_userinfo { ref($newsetting) eq 'HASH' && ref($newsettingtext) eq 'HASH'); my %lt=&Apache::lonlocal::texthash( - 'ui' => 'User Information (unchanged)', + 'ui' => 'User Information', 'uic' => 'User Information Changed', 'firstname' => 'First Name', 'middlename' => 'Middle Name', @@ -3068,7 +3241,8 @@ sub display_userinfo { 'generation' => 'Generation', 'id' => 'Student/Employee ID', 'permanentemail' => 'Permanent e-mail address', - 'quota' => 'Disk space allocated to portfolio files', + 'portfolioquota' => 'Disk space allocated to portfolio files', + 'authorquota' => 'Disk space allocated to Authoring Space', 'blog' => 'Blog Availability', 'webdav' => 'WebDAV Availability', 'aboutme' => 'Personal Information Page Availability', @@ -3076,104 +3250,105 @@ sub display_userinfo { 'official' => 'Can Request Official Courses', 'unofficial' => 'Can Request Unofficial Courses', 'community' => 'Can Request Communities', + 'textbook' => 'Can Request Textbook Courses', 'requestauthor' => 'Can Request Author Role', 'inststatus' => "Affiliation", 'prvs' => 'Previous Value:', 'chto' => 'Changed To:' ); - my $title = $lt{'ui'}; - if ($changed) { - $title = $lt{'uic'}; - } - $r->print('<h4>'.$title.'</h4>'. - &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row()); if ($changed) { + $r->print('<h3>'.$lt{'uic'}.'</h3>'. + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row()); $r->print("<th> </th>\n"); - } - my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id'); - foreach my $item (@userinfo) { - $r->print("<th>$lt{$item}</th>\n"); - } - foreach my $entry (@{$order}) { - if ($canshow->{$entry}) { - if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) { - foreach my $item (@{$requestcourses}) { - $r->print("<th>$lt{$item}</th>\n"); - } - } elsif ($entry eq 'tools') { - foreach my $item (@{$usertools}) { - $r->print("<th>$lt{$item}</th>\n"); - } - } else { - $r->print("<th>$lt{$entry}</th>\n"); - } - } - } - $r->print(&Apache::loncommon::end_data_table_header_row(). - &Apache::loncommon::start_data_table_row()); - if ($changed) { - $r->print('<td><b>'.$lt{'prvs'}.'</b></td>'."\n"); - } - foreach my $item (@userinfo) { - $r->print('<td>'.$userenv->{$item}.' </td>'."\n"); - } - foreach my $entry (@{$order}) { - if ($canshow->{$entry}) { - if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) { - foreach my $item (@{$requestcourses}) { - $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n"); - } - } elsif ($entry eq 'tools') { - foreach my $item (@{$usertools}) { - $r->print("<td>$oldsetting->{$item} $oldsettingtext->{$item}</td>\n"); - } - } else { - $r->print("<td>$oldsetting->{$entry} $oldsettingtext->{$entry} </td>\n"); - } - } - } - $r->print(&Apache::loncommon::end_data_table_row()); - if ($changed) { - $r->print(&Apache::loncommon::start_data_table_row(). - '<td><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></td>'."\n"); + $r->print('<th><b>'.$lt{'prvs'}.'</b></th>'); + $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>'); + $r->print(&Apache::loncommon::end_data_table_header_row()); + my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id'); + foreach my $item (@userinfo) { my $value = $env{'form.c'.$item}; - if ($namechangedhash->{$item}) { - $value = '<span class="LC_cusr_emph">'.$value.'</span>'; + #show changes only: + unless ($value eq $userenv->{$item}){ + $r->print(&Apache::loncommon::start_data_table_row()); + $r->print("<td>$lt{$item}</td>\n"); + $r->print("<td>".$userenv->{$item}."</td>\n"); + $r->print("<td>$value </td>\n"); + $r->print(&Apache::loncommon::end_data_table_row()); } - $r->print("<td>$value </td>\n"); } foreach my $entry (@{$order}) { if ($canshow->{$entry}) { - if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom')) { - foreach my $item (@{$requestcourses}) { - my $value = $newsetting->{$item}.' '.$newsettingtext->{$item}; - if ($changedhash->{$item}) { - $value = '<span class="LC_cusr_emph">'.$value.'</span>'; + if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) { + my @items; + if ($entry eq 'requestauthor') { + @items = ($entry); + } else { + @items = @{$requestcourses}; + } + foreach my $item (@items) { + if (($newsetting->{$item} ne $oldsetting->{$item}) || + ($newsettingtext->{$item} ne $oldsettingtext->{$item})) { + $r->print(&Apache::loncommon::start_data_table_row()."\n"); + $r->print("<td>$lt{$item}</td>\n"); + $r->print("<td>".$oldsetting->{$item}); + if ($oldsettingtext->{$item}) { + if ($oldsetting->{$item}) { + $r->print(' -- '); + } + $r->print($oldsettingtext->{$item}); + } + $r->print("</td>\n"); + $r->print("<td>".$newsetting->{$item}); + if ($newsettingtext->{$item}) { + if ($newsetting->{$item}) { + $r->print(' -- '); + } + $r->print($newsettingtext->{$item}); + } + $r->print("</td>\n"); + $r->print(&Apache::loncommon::end_data_table_row()."\n"); } - $r->print("<td>$value </td>\n"); } } elsif ($entry eq 'tools') { foreach my $item (@{$usertools}) { - my $value = $newsetting->{$item}.' '.$newsettingtext->{$item}; - if ($changedhash->{$item}) { - $value = '<span class="LC_cusr_emph">'.$value.'</span>'; + if ($newsetting->{$item} ne $oldsetting->{$item}) { + $r->print(&Apache::loncommon::start_data_table_row()."\n"); + $r->print("<td>$lt{$item}</td>\n"); + $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n"); + $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n"); + $r->print(&Apache::loncommon::end_data_table_row()."\n"); + } + } + } elsif ($entry eq 'quota') { + if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') && + (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) { + foreach my $name ('portfolio','author') { + if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) { + $r->print(&Apache::loncommon::start_data_table_row()."\n"); + $r->print("<td>$lt{$name.$entry}</td>\n"); + $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n"); + $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n"); + $r->print(&Apache::loncommon::end_data_table_row()."\n"); + } } - $r->print("<td>$value </td>\n"); } } else { - my $value = $newsetting->{$entry}.' '.$newsettingtext->{$entry}; - if ($changedhash->{$entry}) { - $value = '<span class="LC_cusr_emph">'.$value.'</span>'; + if ($newsetting->{$entry} ne $oldsetting->{$entry}) { + $r->print(&Apache::loncommon::start_data_table_row()."\n"); + $r->print("<td>$lt{$entry}</td>\n"); + $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n"); + $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n"); + $r->print(&Apache::loncommon::end_data_table_row()."\n"); } - $r->print("<td>$value </td>\n"); } } } - $r->print(&Apache::loncommon::end_data_table_row()); + $r->print(&Apache::loncommon::end_data_table().'<br />'); + } else { + $r->print('<h3>'.$lt{'ui'}.'</h3>'. + '<p>'.&mt('No changes made to user information').'</p>'); } - $r->print(&Apache::loncommon::end_data_table().'<br />'); return; } @@ -3186,20 +3361,20 @@ sub tool_changes { (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) { return; } + my %reqdisplay = &requestchange_display(); if ($context eq 'reqcrsotherdom') { my @options = ('approval','validate','autolimit'); my $optregex = join('|',@options); - my %reqdisplay = &courserequest_display(); my $cdom = $env{'request.role.domain'}; foreach my $tool (@{$usertools}) { - $oldaccesstext->{$tool} = &mt('No'); + $oldaccesstext->{$tool} = &mt("availability set to 'off'"); $newaccesstext->{$tool} = $oldaccesstext->{$tool}; $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool}; - my $newop; + my ($newop,$limit); if ($env{'form.'.$context.'_'.$tool}) { $newop = $env{'form.'.$context.'_'.$tool}; if ($newop eq 'autolimit') { - my $limit = $env{'form.'.$context.'_'.$tool.'_limit'}; + $limit = $env{'form.'.$context.'_'.$tool.'_limit'}; $limit =~ s/\D+//g; $newop .= '='.$limit; } @@ -3209,7 +3384,15 @@ sub tool_changes { $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop, $changeHash,$context); if ($changed->{$tool}) { - $newaccesstext->{$tool} = &mt('Yes'); + if ($newop =~ /^autolimit/) { + if ($limit) { + $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit); + } else { + $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)'); + } + } else { + $newaccesstext->{$tool} = $reqdisplay{$newop}; + } } else { $newaccesstext->{$tool} = $oldaccesstext->{$tool}; } @@ -3220,8 +3403,17 @@ sub tool_changes { my $changedoms; foreach my $req (@curr) { if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) { - $oldaccesstext->{$tool} = &mt('Yes'); my $oldop = $1; + if ($oldop =~ /^autolimit=(\d*)/) { + my $limit = $1; + if ($limit) { + $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit); + } else { + $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)'); + } + } else { + $oldaccesstext->{$tool} = $reqdisplay{$oldop}; + } if ($oldop ne $newop) { $changedoms = 1; foreach my $item (@curr) { @@ -3255,15 +3447,15 @@ sub tool_changes { my $limit = $env{'form.'.$context.'_'.$tool.'_limit'}; $limit =~ s/\D+//g; if ($limit) { - $newaccesstext->{$tool} = &mt('Yes, up to limit of [quant,_1,request] per user.',$limit); + $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit); } else { - $newaccesstext->{$tool} = &mt('Yes, processed automatically'); + $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)'); } } else { $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}}; } } else { - $newaccesstext->{$tool} = &mt('No'); + $newaccesstext->{$tool} = &mt("availability set to 'off'"); } } } @@ -3272,12 +3464,14 @@ sub tool_changes { return; } foreach my $tool (@{$usertools}) { - my ($newval,$envkey); + my ($newval,$limit,$envkey); $envkey = $context.'.'.$tool; if ($context eq 'requestcourses') { $newval = $env{'form.crsreq_'.$tool}; if ($newval eq 'autolimit') { - $newval .= '='.$env{'form.crsreq_'.$tool.'_limit'}; + $limit = $env{'form.crsreq_'.$tool.'_limit'}; + $limit =~ s/\D+//g; + $newval .= '='.$limit; } } elsif ($context eq 'requestauthor') { $newval = $env{'form.'.$context}; @@ -3287,10 +3481,25 @@ sub tool_changes { } if ($userenv->{$envkey} ne '') { $oldaccess->{$tool} = &mt('custom'); - if ($userenv->{$envkey}) { - $oldaccesstext->{$tool} = &mt("availability set to 'on'"); + if (($context eq 'requestcourses') || ($context eq 'requestauthor')) { + if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) { + my $currlimit = $1; + if ($currlimit eq '') { + $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)'); + } else { + $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit); + } + } elsif ($userenv->{$envkey}) { + $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}}; + } else { + $oldaccesstext->{$tool} = &mt("availability set to 'off'"); + } } else { - $oldaccesstext->{$tool} = &mt("availability set to 'off'"); + if ($userenv->{$envkey}) { + $oldaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $oldaccesstext->{$tool} = &mt("availability set to 'off'"); + } } $changeHash->{$envkey} = $userenv->{$envkey}; if ($env{'form.custom'.$tool} == 1) { @@ -3299,17 +3508,45 @@ sub tool_changes { $context); if ($changed->{$tool}) { $newaccess->{$tool} = &mt('custom'); - if ($newval) { - $newaccesstext->{$tool} = &mt("availability set to 'on'"); + if (($context eq 'requestcourses') || ($context eq 'requestauthor')) { + if ($newval =~ /^autolimit/) { + if ($limit) { + $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit); + } else { + $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)'); + } + } elsif ($newval) { + $newaccesstext->{$tool} = $reqdisplay{$newval}; + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } } else { - $newaccesstext->{$tool} = &mt("availability set to 'off'"); + if ($newval) { + $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'"); + if (($context eq 'requestcourses') || ($context eq 'requestauthor')) { + if ($newval =~ /^autolimit/) { + if ($limit) { + $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit); + } else { + $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)'); + } + } elsif ($newval) { + $newaccesstext->{$tool} = $reqdisplay{$newval}; + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } } else { - $newaccesstext->{$tool} = &mt("availability set to 'off'"); + if ($userenv->{$context.'.'.$tool}) { + $newaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } } } } else { @@ -3322,10 +3559,24 @@ sub tool_changes { $newaccess->{$tool} = &mt('default'); } else { $newaccess->{$tool} = $oldaccess->{$tool}; - if ($userenv->{$context.'.'.$tool}) { - $newaccesstext->{$tool} = &mt("availability set to 'on'"); + if (($context eq 'requestcourses') || ($context eq 'requestauthor')) { + if ($newval =~ /^autolimit/) { + if ($limit) { + $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit); + } else { + $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)'); + } + } elsif ($newval) { + $newaccesstext->{$tool} = $reqdisplay{$newval}; + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } } else { - $newaccesstext->{$tool} = &mt("availability set to 'off'"); + if ($userenv->{$context.'.'.$tool}) { + $newaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } } } } @@ -3336,10 +3587,24 @@ sub tool_changes { $context); if ($changed->{$tool}) { $newaccess->{$tool} = &mt('custom'); - if ($newval) { - $newaccesstext->{$tool} = &mt("availability set to 'on'"); + if (($context eq 'requestcourses') || ($context eq 'requestauthor')) { + if ($newval =~ /^autolimit/) { + if ($limit) { + $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit); + } else { + $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)'); + } + } elsif ($newval) { + $newaccesstext->{$tool} = $reqdisplay{$newval}; + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } } else { - $newaccesstext->{$tool} = &mt("availability set to 'off'"); + if ($newval) { + $newaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } } } else { $newaccess->{$tool} = $oldaccess->{$tool}; @@ -3353,7 +3618,7 @@ sub tool_changes { } sub update_roles { - my ($r,$context) = @_; + my ($r,$context,$showcredits) = @_; my $now=time; my @rolechanges; my %disallowed; @@ -3370,14 +3635,20 @@ sub update_roles { &Apache::lonnet::revokerole($env{'form.ccdomain'}, $env{'form.ccuname'}, $scope,$role,'','',$context); - $r->print(&mt('Revoking [_1] in [_2]: [_3]', - $role,$scope,'<b>'.$result.'</b>').'<br />'); + $r->print(&Apache::lonhtmlcommon::confirm_success( + &mt('Revoking [_1] in [_2]', + &Apache::lonnet::plaintext($role), + &Apache::loncommon::show_role_extent($scope,$context,$role)), + $result ne "ok").'<br />'); + if ($result ne "ok") { + $r->print(&mt('Error: [_1]',$result).'<br />'); + } if ($role eq 'st') { my $result = &Apache::lonuserutils::classlist_drop($scope, $env{'form.ccuname'},$env{'form.ccdomain'}, $now); - $r->print($result); + $r->print(&Apache::lonhtmlcommon::confirm_success($result)); } if (!grep(/^\Q$role\E$/,@rolechanges)) { push(@rolechanges,$role); @@ -3385,11 +3656,15 @@ sub update_roles { } if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) { # Revoke custom role - $r->print(&mt('Revoking custom role:'). - ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'. - &Apache::lonnet::revokecustomrole($env{'form.ccdomain'}, - $env{'form.ccuname'},$1,$2,$3,$4,'','',$context). - '</b><br />'); + my $result = &Apache::lonnet::revokecustomrole( + $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context); + $r->print(&Apache::lonhtmlcommon::confirm_success( + &mt('Revoking custom role [_1] by [_2] in [_3]', + $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')), + $result ne 'ok').'<br />'); + if ($result ne "ok") { + $r->print(&mt('Error: [_1]',$result).'<br />'); + } if (!grep(/^cr$/,@rolechanges)) { push(@rolechanges,'cr'); } @@ -3403,14 +3678,21 @@ sub update_roles { $env{'form.ccuname'}, $scope,$role,$now,0,1,'', $context); - $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope, - '<b>'.$result.'</b>').'<br />'); + $r->print(&Apache::lonhtmlcommon::confirm_success( + &mt('Deleting [_1] in [_2]', + &Apache::lonnet::plaintext($role), + &Apache::loncommon::show_role_extent($scope,$context,$role)), + $result ne 'ok').'<br />'); + if ($result ne "ok") { + $r->print(&mt('Error: [_1]',$result).'<br />'); + } + if ($role eq 'st') { my $result = &Apache::lonuserutils::classlist_drop($scope, $env{'form.ccuname'},$env{'form.ccdomain'}, $now); - $r->print($result); + $r->print(&Apache::lonhtmlcommon::confirm_success($result)); } if (!grep(/^\Q$role\E$/,@rolechanges)) { push(@rolechanges,$role); @@ -3419,11 +3701,17 @@ sub update_roles { if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) { my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4); # Delete custom role - $r->print(&mt('Deleting custom role [_1] by [_2] in [_3]', - $rolename,$rnam.':'.$rdom,$url).': <b>'. - &Apache::lonnet::assigncustomrole($env{'form.ccdomain'}, - $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now, - 0,1,$context).'</b><br />'); + my $result = + &Apache::lonnet::assigncustomrole($env{'form.ccdomain'}, + $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now, + 0,1,$context); + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]', + $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')), + $result ne "ok").'<br />'); + if ($result ne "ok") { + $r->print(&mt('Error: [_1]',$result).'<br />'); + } + if (!grep(/^cr$/,@rolechanges)) { push(@rolechanges,'cr'); } @@ -3439,27 +3727,38 @@ sub update_roles { my $output; if ($role eq 'st') { if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) { - my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3); + my ($cdom,$cnum,$csec) = ($1,$2,$3); + my $credits; + if ($showcredits) { + my $defaultcredits = + &Apache::lonuserutils::get_defaultcredits($cdom,$cnum); + $credits = &get_user_credits($defaultcredits,$cdom,$cnum); + } + my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits); if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) { if ($result eq 'refused' && $logmsg) { $output = $logmsg; } else { - $output = "Error: $result\n"; + $output = &mt('Error: [_1]',$result)."\n"; } } else { - $output = &mt('Assigning').' '.$role.' in '.$url. - &mt('starting').' '.localtime($now). - ': <br />'.$logmsg.'<br />'. - &mt('Add to classlist').': <b>ok</b><br />'; + $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]', + &Apache::lonnet::plaintext($role), + &Apache::loncommon::show_role_extent($url,$context,'st'), + &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />'; } } } else { my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'}, $env{'form.ccuname'},$url,$role,0,$now,'','', $context); - $output = &mt('Re-enabling [_1] in [_2]: [_3]', - $role,$url,'<b>'.$result.'</b>').'<br />'; - } + $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]', + &Apache::lonnet::plaintext($role), + &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />'; + if ($result ne "ok") { + $output .= &mt('Error: [_1]',$result).'<br />'; + } + } $r->print($output); if (!grep(/^\Q$role\E$/,@rolechanges)) { push(@rolechanges,$role); @@ -3471,8 +3770,13 @@ sub update_roles { my $result = &Apache::lonnet::assigncustomrole( $env{'form.ccdomain'}, $env{'form.ccuname'}, $url,$rdom,$rnam,$rolename,0,$now,undef,$context); - $r->print(&mt('Re-enabling custom role [_1] by [_2] in [_3]: [_4]', - $rolename,$rnam.':'.$rdom,$url,'<b>'.$result.'</b>').'<br />'); + $r->print(&Apache::lonhtmlcommon::confirm_success( + &mt('Re-enabling custom role [_1] by [_2] in [_3]', + $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')), + $result ne "ok").'<br />'); + if ($result ne "ok") { + $r->print(&mt('Error: [_1]',$result).'<br />'); + } if (!grep(/^cr$/,@rolechanges)) { push(@rolechanges,'cr'); } @@ -3529,8 +3833,20 @@ sub update_roles { # split multiple sections my %sections = (); my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three); + my $credits; + if ($three eq 'st') { + if ($showcredits) { + my $defaultcredits = + &Apache::lonuserutils::get_defaultcredits($one,$two); + $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three}; + $credits =~ s/[^\d\.]//g; + if ($credits eq $defaultcredits) { + undef($credits); + } + } + } if ($num_sections == 0) { - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context)); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits)); } else { my %curr_groups = &Apache::longroup::coursegroups($one,$two); @@ -3544,13 +3860,13 @@ sub update_roles { next; } my $securl = $url.'/'.$sec; - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context)); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits)); } else { $emptysec = 1; } } if ($emptysec) { - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context)); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits)); } } if (!grep(/^\Q$three\E$/,@rolechanges)) { @@ -3612,13 +3928,36 @@ sub update_roles { # Flush the course logs so reverse user roles immediately updated $r->register_cleanup(\&Apache::lonnet::flushcourselogs); if (@rolechanges == 0) { - $r->print(&mt('No roles to modify')); + $r->print('<p>'.&mt('No roles to modify').'</p>'); } return @rolechanges; } +sub get_user_credits { + my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_; + if ($cdom eq '' || $cnum eq '') { + return unless ($env{'request.course.id'}); + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + } + my $credits; + my %currhash = + &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum); + if (keys(%currhash) > 0) { + my @items = split(/:/,$currhash{$uname.':'.$udom}); + my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3; + $credits = $items[$crdidx]; + $credits =~ s/[^\d\.]//g; + } + if ($credits eq $defaultcredits) { + undef($credits); + } + return $credits; +} + sub enroll_single_student { - my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype) = @_; + my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype, + $showcredits,$defaultcredits) = @_; $r->print('<h3>'); if ($crstype eq 'Community') { $r->print(&mt('Enrolling Member')); @@ -3630,6 +3969,17 @@ sub enroll_single_student { # Remove non alphanumeric values from section $env{'form.sections'}=~s/\W//g; + my $credits; + if (($showcredits) && ($env{'form.credits'} ne '')) { + $credits = $env{'form.credits'}; + $credits =~ s/[^\d\.]//g; + if ($credits ne '') { + if ($credits eq $defaultcredits) { + undef($credits); + } + } + } + # Clean out any old student roles the user has in this class. &Apache::lonuserutils::modifystudent($env{'form.ccdomain'}, $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome); @@ -3639,9 +3989,10 @@ sub enroll_single_student { $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'}, $env{'form.cmiddlename'},$env{'form.clastname'}, $env{'form.generation'},$env{'form.sections'},$enddate, - $startdate,'manual',undef,$env{'request.course.id'},'',$context); + $startdate,'manual',undef,$env{'request.course.id'},'',$context, + $credits); if ($enroll_result =~ /^ok/) { - $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'})); + $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>')); if ($env{'form.sections'} ne '') { $r->print(' '.&mt('in section [_1]',$env{'form.sections'})); } @@ -3658,11 +4009,11 @@ sub enroll_single_student { } $r->print('.<br />'.$showstart.'; '.$showend); if ($startdate <= $now && !$newuser) { - $r->print('<p> '); + $r->print('<p class="LC_info">'); if ($crstype eq 'Community') { - $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role will be available when the member next logs in.')); + $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.')); } else { - $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.')); + $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.')); } $r->print('</p>'); } @@ -3676,14 +4027,14 @@ sub get_defaultquota_text { my ($settingstatus) = @_; my $defquotatext; if ($settingstatus eq '') { - $defquotatext = &mt('(default)'); + $defquotatext = &mt('default'); } else { my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'}); if ($usertypes->{$settingstatus} eq '') { - $defquotatext = &mt('(default)'); + $defquotatext = &mt('default'); } else { - $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus}); + $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus}); } } return $defquotatext; @@ -3692,7 +4043,7 @@ sub get_defaultquota_text { sub update_result_form { my ($uhome) = @_; my $outcome = - '<form name="userupdate" method="post" />'."\n"; + '<form name="userupdate" method="post" action="">'."\n"; foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') { $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n"; } @@ -3708,20 +4059,20 @@ sub update_result_form { $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n"; } $outcome .= '<input type="hidden" name="phase" value="" />'."\n". - '<input type ="hidden" name="currstate" value="" />'."\n". - '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n". + '<input type="hidden" name="currstate" value="" />'."\n". + '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n". '</form>'; return $outcome; } sub quota_admin { - my ($setquota,$changeHash) = @_; + my ($setquota,$changeHash,$name) = @_; my $quotachanged; if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) { # Current user has quota modification privileges if (ref($changeHash) eq 'HASH') { $quotachanged = 1; - $changeHash->{'portfolioquota'} = $setquota; + $changeHash->{$name.'quota'} = $setquota; } } return $quotachanged; @@ -3828,6 +4179,7 @@ sub custom_role_editor { my $dompriv=''; my $coursepriv=''; my $body_top; + my $newrole; my ($rdummy,$roledef)= &Apache::lonnet::get('roles',["rolesdef_$rolename"]); # ------------------------------------------------------- Does this role exist? @@ -3840,6 +4192,7 @@ sub custom_role_editor { $syspriv =~ s/bre\&S//; } } else { + $newrole = 1; $body_top .= &mt('New Role').' "'; $roledef=''; } @@ -3966,7 +4319,7 @@ sub custom_role_editor { $r->print('<br clear="all" />'); $r->print(<<ENDCCF); -<form name="form1" method="post"> +<form name="form1" method="post" action=""> <input type="hidden" name="phase" value="set_custom_roles" /> <input type="hidden" name="rolename" value="$rolename" /> ENDCCF @@ -4109,6 +4462,7 @@ sub set_custom_role { bread_crumbs_component => 'User Management'}; $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args)); + my $newrole; my ($rdummy,$roledef)= &Apache::lonnet::get('roles',["rolesdef_$rolename"]); @@ -4119,6 +4473,7 @@ sub set_custom_role { } else { $r->print(&mt('New Role').' "'); $roledef=''; + $newrole = 1; } $r->print($rolename.'"</h3>'); # ------------------------------------------------------- What can be assigned? @@ -4149,21 +4504,44 @@ sub set_custom_role { $sysrole.=':'.$item; } } - $r->print('<br />Defining Role: '. - &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole)); + # Assign role; Compile and show result + my $errmsg; + my $result = + &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole); + if ($result ne 'ok') { + $errmsg = ': '.$result; + } + my $message = + &Apache::lonhtmlcommon::confirm_success( + &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1)); if ($env{'request.course.id'}) { my $url='/'.$env{'request.course.id'}; $url=~s/\_/\//g; - $r->print('<br />'.&mt('Assigning Role to Self').': '. - &Apache::lonnet::assigncustomrole($env{'user.domain'}, - $env{'user.name'}, - $url, - $env{'user.domain'}, - $env{'user.name'}, - $rolename,undef,undef,undef,$context)); - } - $r->print('<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">'.&mt('Create or edit another custom role').'</a></p><form name="customresult" method="post">'); - $r->print(&Apache::lonhtmlcommon::echo_form_input([]).'</form>'); + $result = + &Apache::lonnet::assigncustomrole( + $env{'user.domain'},$env{'user.name'}, + $url, + $env{'user.domain'},$env{'user.name'}, + $rolename,undef,undef,undef,$context); + if ($result ne 'ok') { + $errmsg = ': '.$result; + } + $message .= + '<br />' + .&Apache::lonhtmlcommon::confirm_success( + &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1)); + } + $r->print( + &Apache::loncommon::confirmwrapper($message) + .'<br />' + .&Apache::lonhtmlcommon::actionbox([ + '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">' + .&mt('Create or edit another custom role') + .'</a>']) + .'<form name="customresult" method="post" action="">' + .&Apache::lonhtmlcommon::echo_form_input([]) + .'</form>' + ); } # ================================================================ Main Handler @@ -4183,14 +4561,15 @@ sub handler { } else { $context = 'domain'; } + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['action','state','callingform','roletype','showrole','bulkaction','popup','phase', - 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']); + 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']); &Apache::lonhtmlcommon::clear_breadcrumbs(); my $args; my $brcrum = []; my $bread_crumbs_component = 'User Management'; - if ($env{'form.action'} ne 'dateselect') { + if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) { $brcrum = [{href=>"/adm/createuser", text=>"User Management", help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'} @@ -4214,6 +4593,16 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; + my $showcredits; + if ((($context eq 'course') && ($crstype eq 'Course')) || + ($context eq 'domain')) { + my %domdefaults = + &Apache::lonnet::get_domain_defaults($env{'request.role.domain'}); + if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) { + $showcredits = 1; + } + } + # Main switch on form.action and form.state, as appropriate if (! exists($env{'form.action'})) { $args = {bread_crumbs => $brcrum, @@ -4236,11 +4625,12 @@ sub handler { if (! exists($env{'form.state'})) { &Apache::lonuserutils::print_first_users_upload_form($r,$context); } elsif ($env{'form.state'} eq 'got_file') { - &Apache::lonuserutils::print_upload_manager_form($r,$context, - $permission,$crstype); + &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission, + $crstype,$showcredits); } elsif ($env{'form.state'} eq 'enrolling') { if ($env{'form.datatoken'}) { - &Apache::lonuserutils::upfile_drop_add($r,$context,$permission); + &Apache::lonuserutils::upfile_drop_add($r,$context,$permission, + $showcredits); } } else { &Apache::lonuserutils::print_first_users_upload_form($r,$context); @@ -4259,15 +4649,21 @@ sub handler { if ($env{'form.phase'} eq 'createnewuser') { my $response; if ($env{'form.srchterm'} !~ /^$match_username$/) { - my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @'); + my $response = + '<span class="LC_warning">' + .&mt('You must specify a valid username. Only the following are allowed:' + .' letters numbers - . @') + .'</span>'; $env{'form.phase'} = ''; - &print_username_entry_form($r,$context,$response,$srch,undef,$crstype,$brcrum); + &print_username_entry_form($r,$context,$response,$srch,undef, + $crstype,$brcrum,$showcredits); } else { my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'}); my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'}); &print_user_modification_page($r,$ccuname,$ccdomain, $srch,$response,$context, - $permission,$crstype,$brcrum); + $permission,$crstype,$brcrum, + $showcredits); } } elsif ($env{'form.phase'} eq 'get_user_info') { my ($currstate,$response,$forcenewuser,$results) = @@ -4312,7 +4708,7 @@ sub handler { $brcrum); } } elsif ($env{'form.phase'} eq 'update_user_data') { - &update_user_data($r,$context,$crstype,$brcrum); + &update_user_data($r,$context,$crstype,$brcrum,$showcredits); } else { &print_username_entry_form($r,$context,undef,$srch,undef,$crstype, $brcrum); @@ -4328,7 +4724,7 @@ sub handler { (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) { push(@{$brcrum}, {href => '/adm/createuser?action=processauthorreq', - text => 'Authoring space requests', + text => 'Authoring Space requests', help => 'Domain_Role_Approvals'}); $bread_crumbs_component = 'Authoring requests'; if ($env{'form.state'} eq 'done') { @@ -4340,7 +4736,8 @@ sub handler { } $args = { bread_crumbs => $brcrum, bread_crumbs_component => $bread_crumbs_component}; - $r->print(&header(undef,$args)); + my $js = &usernamerequest_javascript(); + $r->print(&header(&add_script($js),$args)); if (!exists($env{'form.state'})) { $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor', $env{'request.role.domain'})); @@ -4349,6 +4746,103 @@ sub handler { $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor', $env{'request.role.domain'})); } + } elsif (($env{'form.action'} eq 'processusernamereq') && + ($permission->{'cusr'}) && + (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) { + push(@{$brcrum}, + {href => '/adm/createuser?action=processusernamereq', + text => 'LON-CAPA account requests', + help => 'Domain_Username_Approvals'}); + $bread_crumbs_component = 'Account requests'; + if ($env{'form.state'} eq 'done') { + push(@{$brcrum}, + {href => '/adm/createuser?action=usernamereqqueue', + text => 'Result', + help => 'Domain_Username_Approvals'}); + $bread_crumbs_component = 'LON-CAPA account request result'; + } + $args = { bread_crumbs => $brcrum, + bread_crumbs_component => $bread_crumbs_component}; + my $js = &usernamerequest_javascript(); + $r->print(&header(&add_script($js),$args)); + if (!exists($env{'form.state'})) { + $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername', + $env{'request.role.domain'})); + } elsif ($env{'form.state'} eq 'done') { + $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n"); + $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername', + $env{'request.role.domain'})); + } + } elsif (($env{'form.action'} eq 'displayuserreq') && + ($permission->{'cusr'})) { + my $dom = $env{'form.domain'}; + my $uname = $env{'form.username'}; + my $warning; + if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) { + if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) { + if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) { + my $uhome = &Apache::lonnet::homeserver($uname,$dom); + if ($uhome eq 'no_host') { + my $queue = $env{'form.queue'}; + my $reqkey = &escape($uname).'_'.$queue; + my $namespace = 'usernamequeue'; + my $domconfig = &Apache::lonnet::get_domainconfiguser($dom); + my %queued = + &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig); + unless ($queued{$reqkey}) { + $warning = &mt('No information was found for this LON-CAPA account request.'); + } + } else { + $warning = &mt('A LON-CAPA account already exists for the requested username and domain.'); + } + } else { + $warning = &mt('LON-CAPA account request status check is for an invalid username.'); + } + } else { + $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.'); + } + } else { + $warning = &mt('LON-CAPA account request status check is for an invalid domain.'); + } + my $args = { only_body => 1 }; + $r->print(&header(undef,$args). + '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>'); + if ($warning ne '') { + $r->print('<div class="LC_warning">'.$warning.'</div>'); + } else { + my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info(); + my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom); + my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom); + if (ref($domconfig{'usercreation'}) eq 'HASH') { + if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') { + if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') { + my $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}})); + my %info = + &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser); + if (ref($info{$uname}) eq 'HASH') { + if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) { + $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box()); + my $num; + foreach my $field (@{$infofields}) { + next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$field}); + next unless ($infotitles->{$field}); + $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}). + $info{$uname}{$field}); + $num ++; + if ($count == $num) { + $r->print(&Apache::lonhtmlcommon::row_closure(1)); + } else { + $r->print(&Apache::lonhtmlcommon::row_closure()); + } + } + $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>'); + } + } + } + } + } + $r->print(&close_popup_form()); + } } elsif (($env{'form.action'} eq 'listusers') && ($permission->{'view'} || $permission->{'cusr'})) { if ($env{'form.phase'} eq 'bulkchange') { @@ -4415,7 +4909,8 @@ sub handler { $r->print(&header(&add_script($jscript),$args)); } &Apache::lonuserutils::print_userlist($r,undef,$permission,$context, - $formname,$totcodes,$codetitles,$idlist,$idlist_titles); + $formname,$totcodes,$codetitles,$idlist,$idlist_titles, + $showcredits); } } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) { my $brtext; @@ -4446,8 +4941,8 @@ sub handler { } elsif ($env{'form.action'} eq 'dateselect') { if ($permission->{'cusr'}) { $r->print(&header(undef,{'no_nav_bar' => 1}). - &Apache::lonuserutils::date_section_selector($context, - $permission,$crstype)); + &Apache::lonuserutils::date_section_selector($context,$permission, + $crstype,$showcredits)); } else { $r->print(&header(undef,{'no_nav_bar' => 1}). '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'); @@ -4547,8 +5042,39 @@ sub add_script { .'</script>'."\n"; } +sub usernamerequest_javascript { + my $js = <<ENDJS; + +function openusernamereqdisplay(dom,uname,queue) { + var url = '/adm/createuser?action=displayuserreq'; + url += '&domain='+dom+'&username='+uname+'&queue='+queue; + var title = 'Account_Request_Browser'; + var options = 'scrollbars=1,resizable=1,menubar=0'; + options += ',width=700,height=600'; + var stdeditbrowser = open(url,title,options,'1'); + stdeditbrowser.focus(); + return; +} + +ENDJS +} + +sub close_popup_form { + my $close= &mt('Close Window'); + return << "END"; +<p><form name="displayreq" action="" method="post"> +<input type="button" name="closeme" value="$close" onclick="javascript:self.close();" /> +</form></p> +END +} + sub verify_user_display { my ($context) = @_; + my %lt = &Apache::lonlocal::texthash ( + course => 'course(s): description, section(s), status', + community => 'community(s): description, section(s), status', + author => 'author', + ); my $photos; if (($context eq 'course') && $env{'request.course.id'}) { $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}; @@ -4572,16 +5098,25 @@ function updateCols(caller) { var context = '$context'; var photos = '$photos'; if (caller == 'Status') { - if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') { - document.getElementById('showcolstatus').checked = true; - document.getElementById('showcolstatus').disabled = ''; - document.getElementById('showcolstart').checked = true; - document.getElementById('showcolend').checked = true; - } else { + if ((context == 'domain') && + ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') || + (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) { document.getElementById('showcolstatus').checked = false; document.getElementById('showcolstatus').disabled = 'disabled'; document.getElementById('showcolstart').checked = false; document.getElementById('showcolend').checked = false; + } else { + if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') { + document.getElementById('showcolstatus').checked = true; + document.getElementById('showcolstatus').disabled = ''; + document.getElementById('showcolstart').checked = true; + document.getElementById('showcolend').checked = true; + } else { + document.getElementById('showcolstatus').checked = false; + document.getElementById('showcolstatus').disabled = 'disabled'; + document.getElementById('showcolstart').checked = false; + document.getElementById('showcolend').checked = false; + } } } if (caller == 'output') { @@ -4599,13 +5134,74 @@ function updateCols(caller) { } } if (caller == 'showrole') { - if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') { + if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') || + (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) { document.getElementById('showcolrole').checked = true; document.getElementById('showcolrole').disabled = ''; } else { document.getElementById('showcolrole').checked = false; document.getElementById('showcolrole').disabled = 'disabled'; } + if (context == 'domain') { + var quotausageshow = 0; + if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') || + (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) { + document.getElementById('showcolstatus').checked = false; + document.getElementById('showcolstatus').disabled = 'disabled'; + document.getElementById('showcolstart').checked = false; + document.getElementById('showcolend').checked = false; + } else { + if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') { + document.getElementById('showcolstatus').checked = true; + document.getElementById('showcolstatus').disabled = ''; + document.getElementById('showcolstart').checked = true; + document.getElementById('showcolend').checked = true; + } + } + if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') { + document.getElementById('showcolextent').disabled = 'disabled'; + document.getElementById('showcolextent').checked = 'false'; + document.getElementById('showextent').style.display='none'; + document.getElementById('showcoltextextent').innerHTML = ''; + if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') || + (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) { + if (document.getElementById('showcolauthorusage')) { + document.getElementById('showcolauthorusage').disabled = ''; + } + if (document.getElementById('showcolauthorquota')) { + document.getElementById('showcolauthorquota').disabled = ''; + } + quotausageshow = 1; + } + } else { + document.getElementById('showextent').style.display='block'; + document.getElementById('showextent').style.textAlign='left'; + document.getElementById('showextent').style.textFace='normal'; + if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') { + document.getElementById('showcolextent').disabled = ''; + document.getElementById('showcolextent').checked = 'true'; + document.getElementById('showcoltextextent').innerHTML="$lt{'author'}"; + } else { + document.getElementById('showcolextent').disabled = ''; + document.getElementById('showcolextent').checked = 'true'; + if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') { + document.getElementById('showcoltextextent').innerHTML="$lt{'community'}"; + } else { + document.getElementById('showcoltextextent').innerHTML="$lt{'course'}"; + } + } + } + if (quotausageshow == 0) { + if (document.getElementById('showcolauthorusage')) { + document.getElementById('showcolauthorusage').checked = false; + document.getElementById('showcolauthorusage').disabled = 'disabled'; + } + if (document.getElementById('showcolauthorquota')) { + document.getElementById('showcolauthorquota').checked = false; + document.getElementById('showcolauthorquota').disabled = 'disabled'; + } + } + } } return; } @@ -4725,6 +5321,14 @@ sub print_main_menu { linktitle => 'Approve or reject author role requests', }, { + linktext => 'LON-CAPA Account Requests', + icon => 'list-add.png', + #help => 'Domain_Username_Approvals', + url => '/adm/createuser?action=processusernamereq', + permission => $permission->{'cusr'}, + linktitle => 'Approve or reject LON-CAPA account requests', + }, + { linktext => 'Change Log', icon => 'document-properties.png', #help => 'Course_User_Logs', @@ -4849,6 +5453,7 @@ sub print_main_menu { ); } } elsif ($context eq 'author') { + push(@{ $menu[2]->{items} }, #Category: Administration { linktext => 'Change Log', icon => 'document-properties.png', @@ -4857,6 +5462,7 @@ sub print_main_menu { permission => $permission->{'cusr'}, linktitle => 'View change log.', }, + ); } return Apache::lonhtmlcommon::generate_menu(@menu); # { text => 'View Log-in History', @@ -5843,7 +6449,7 @@ sub role_display_filter { &mt('Context:').'</b><br /><select name="chgcontext">'; my @posscontexts; if ($context eq 'course') { - @posscontexts = ('any','auto','updatenow','createcourse','course','domain','selfenroll','requestcourses'); + @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses'); } elsif ($context eq 'domain') { @posscontexts = ('any','domain','requestauthor','domconfig','server'); } else { @@ -5855,7 +6461,7 @@ sub role_display_filter { $selstr = ' selected="selected"'; } if ($context eq 'course') { - if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) { + if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) { next if (!&Apache::lonnet::auto_run($cnum,$cdom)); } } @@ -5891,7 +6497,7 @@ sub rolechg_contexts { if ($context eq 'course') { %lt = &Apache::lonlocal::texthash ( any => 'Any', - auto => 'Automated enrollment', + automated => 'Automated Enrollment', updatenow => 'Roster Update', createcourse => 'Course Creation', course => 'User Management in course', @@ -6416,7 +7022,8 @@ function backPage(formname,prevphase,pre } sub course_level_table { - my (%inccourses) = @_; + my ($inccourses,$showcredits,$defaultcredits) = @_; + return unless (ref($inccourses) eq 'HASH'); my $table = ''; # Custom Roles? @@ -6431,11 +7038,12 @@ sub course_level_table { 'rol' => "Role", 'ext' => "Extent", 'grs' => "Section", + 'crd' => "Credits", 'sta' => "Start", 'end' => "End" ); - foreach my $protectedcourse (sort(keys(%inccourses))) { + foreach my $protectedcourse (sort(keys(%{$inccourses}))) { my $thiscourse=$protectedcourse; $thiscourse=~s:_:/:g; my %coursedata=&Apache::lonnet::coursedescription($thiscourse); @@ -6457,12 +7065,14 @@ sub course_level_table { if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) || ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) { $table .= &course_level_row($protectedcourse,$role,$area,$domain, - $plrole,\%sections_count,\%lt); + $plrole,\%sections_count,\%lt, + $defaultcredits,$crstype); } elsif ($env{'request.course.sec'} ne '') { if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'. $env{'request.course.sec'})) { $table .= &course_level_row($protectedcourse,$role,$area,$domain, - $plrole,\%sections_count,\%lt); + $plrole,\%sections_count,\%lt, + $defaultcredits,$crstype); } } } @@ -6484,8 +7094,10 @@ sub course_level_table { $result .= &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). -'<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th> -<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'. +'<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n". +'<th>'.$lt{'ext'}.'</th><th>'.$lt{'crd'}.'</th>'."\n". +'<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n". +'<th>'.$lt{'end'}.'</th>'. &Apache::loncommon::end_data_table_header_row(). $table. &Apache::loncommon::end_data_table(); @@ -6493,12 +7105,21 @@ $table. } sub course_level_row { - my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_; + my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count, + $lt,$defaultcredits,$crstype) = @_; + my $creditem; my $row = &Apache::loncommon::start_data_table_row(). ' <td><input type="checkbox" name="act_'. $protectedcourse.'_'.$role.'" /></td>'."\n". ' <td>'.$plrole.'</td>'."\n". ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n"; + if (($role eq 'st') && ($crstype eq 'Course')) { + $row .= + '<td><input type="text" name="credits_'.$protectedcourse.'_'. + $role.'" size="3" value="'.$defaultcredits.'" /></td>'; + } else { + $row .= '<td> </td>'; + } if (($role eq 'cc') || ($role eq 'co')) { $row .= '<td> </td>'; } elsif ($env{'request.course.sec'} ne '') { @@ -6524,7 +7145,7 @@ sub course_level_row { '</tr></table></td>'."\n"; } else { $row .= '<td><input type="text" size="10" '. - 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n"; + 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n"; } } $row .= <<ENDTIMEENTRY; @@ -6540,7 +7161,7 @@ ENDTIMEENTRY } sub course_level_dc { - my ($dcdom) = @_; + my ($dcdom,$showcredits) = @_; my %customroles=&Apache::lonuserutils::my_custom_roles(); my @roles = &Apache::lonuserutils::roles_by_context('course'); my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'. @@ -6548,7 +7169,11 @@ sub course_level_dc { '<input type="hidden" name="dccourse" value="" />'; my $courseform=&Apache::loncommon::selectcourse_link ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype'); - my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser'); + my $credit_elem; + if ($showcredits) { + $credit_elem = 'credits'; + } + my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem); my %lt=&Apache::lonlocal::texthash( 'rol' => "Role", 'grs' => "Section", @@ -6558,39 +7183,46 @@ sub course_level_dc { 'end' => "End", 'ssd' => "Set Start Date", 'sed' => "Set End Date", - 'scc' => "Course/Community" + 'scc' => "Course/Community", + 'crd' => "Credits", ); my $header = '<h4>'.&mt('Course/Community Level').'</h4>'. &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). - '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'. + '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n". + '<th>'.$lt{'grs'}.'</th><th>'.$lt{'crd'}.'</th>'."\n". + '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n". &Apache::loncommon::end_data_table_header_row(); my $otheritems = &Apache::loncommon::start_data_table_row()."\n". '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'. $courseform.(' ' x4).'</span></td>'."\n". - '<td valign><br /><select name="role">'."\n"; + '<td valign="top"><br /><select name="role">'."\n"; foreach my $role (@roles) { my $plrole=&Apache::lonnet::plaintext($role); - $otheritems .= ' <option value="'.$role.'">'.$plrole; + $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>'; } if ( keys %customroles > 0) { foreach my $cust (sort keys %customroles) { my $custrole='cr_cr_'.$env{'user.domain'}. '_'.$env{'user.name'}.'_'.$cust; - $otheritems .= ' <option value="'.$custrole.'">'.$cust; + $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>'; } } $otheritems .= '</select></td><td>'. '<table border="0" cellspacing="0" cellpadding="0">'. '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'. - ' <option value=""><--'.&mt('Pick course first').'</select></td>'. + ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'. '<td> </td>'. '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'. '<input type="text" name="newsec" value="" />'. '<input type="hidden" name="section" value="" />'. '<input type="hidden" name="groups" value="" />'. '<input type="hidden" name="crstype" value="" /></td>'. - '</tr></table></td>'; + '</tr></table></td>'."\n"; + if ($showcredits) { + $otheritems .= '<td><br />'."\n". + '<input type="text" size="3" name="credits" value="" />'."\n"; + } $otheritems .= <<ENDTIMEENTRY; <td><br /><input type="hidden" name="start" value='' /> <a href= @@ -6933,7 +7565,7 @@ sub update_selfenroll_config { my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum); if (ref($visactions) eq 'HASH') { if (!$visible) { - $r->print('<br />'.$visactions->{'miss'}.'<br />'.$visactions->{'yous'}. + $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}. '<br />'); if (ref($vismsgs) eq 'ARRAY') { $r->print('<br />'.$visactions->{'take'}.'<ul>');