[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm lonpickcourse.pm lonuserutils.pm
raeburn
raeburn at source.lon-capa.org
Thu Feb 28 23:55:35 EST 2013
raeburn Fri Mar 1 04:55:35 2013 EDT
Modified files:
/loncom/interface lonuserutils.pm loncreateuser.pm lonpickcourse.pm
Log:
- Credits earned for a course can be different for a specific student
(specify when CC or DC enrolls a single student or a CC uploads a classlist
file.
-------------- next part --------------
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.149 loncom/interface/lonuserutils.pm:1.150
--- loncom/interface/lonuserutils.pm:1.149 Tue Feb 19 17:30:35 2013
+++ loncom/interface/lonuserutils.pm Fri Mar 1 04:55:34 2013
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.149 2013/02/19 17:30:35 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.150 2013/03/01 04:55:34 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -399,6 +399,12 @@
$param{'curr_autharg'} = $curr_authfield;
}
+ my $showcredits;
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
+ if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
+ $showcredits = 1;
+ }
+
my ($setsection_call,$setsections_js);
my $finish = " vf.submit();\n";
if ($mode eq 'upload') {
@@ -408,13 +414,14 @@
$setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
$setsections_js =
&setsections_javascript($param{'formname'},$groupslist,
- $mode,'',$crstype);
+ $mode,'',$crstype,$showcredits);
} else {
$setsection_call = "'ok'";
}
} elsif ($context eq 'domain') {
$setsection_call = 'setCourse()';
- $setsections_js = &dc_setcourse_js($param{'formname'},$mode,$context);
+ $setsections_js = &dc_setcourse_js($param{'formname'},$mode,
+ $context,$showcredits);
}
$finish = " var checkSec = $setsection_call\n".
" if (checkSec == 'ok') {\n".
@@ -437,13 +444,16 @@
domain => 'The optional domain field was not specified.',
continue => 'Continue adding users?',
);
+ if ($showcredits) {
+ $alert{'credits'} = &mt('The optional credits field was not specified');
+ }
if (($mode eq 'upload') && ($context eq 'domain')) {
$alert{'inststatus'} = &mt('The optional affiliation field was not specified');
}
my $function_name = <<"END";
$setsections_js
-function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus) {
+function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits) {
END
my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
my $auth_checks;
@@ -500,6 +510,7 @@
return;
}
}
+/* regexp here to check for non \d \. in credits */
END
} else {
$auth_checks .= (<<END);
@@ -572,6 +583,16 @@
message+='$alert{'domain'}';
}
END
+ if ($showcredits) {
+ $optional_checks .= <<END;
+ if (foundcredits==0) {
+ if (message!='') {
+ message+='\\n';
+ }
+ message+='$alert{'credits'}';
+ }
+END
+ }
if (($mode eq 'upload') && ($context eq 'domain')) {
$optional_checks .= (<<END);
@@ -656,6 +677,7 @@
var foundrole=0;
var founddomain=0;
var foundinststatus=0;
+ var foundcredits=0;
var tw;
for (i=0;i<=vf.nfields.value;i++) {
tw=eval('vf.f'+i+'.selectedIndex');
@@ -668,8 +690,9 @@
if (tw==11) { foundrole=1; }
if (tw==12) { founddomain=1; }
if (tw==13) { foundinststatus=1; }
+ if (tw==14) { foundcredits=1; }
}
- verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus);
+ verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
}
//
@@ -692,6 +715,7 @@
// 11 = role
// 12 = domain
// 13 = inststatus
+// 14 = foundcredits
function flip(vf,tf) {
var nw=eval('vf.f'+tf+'.selectedIndex');
@@ -789,6 +813,7 @@
var foundrole=0;
var founddomain=0;
var foundinststatus=0;
+ var foundcredits=0;
var tw;
for (i=0;i<=vf.nfields.value;i++) {
tw=eval('vf.f'+i+'.selectedIndex');
@@ -801,8 +826,9 @@
if (i==10 && tw!=0) { foundrole=1; }
if (i==11 && tw!=0) { founddomain=1; }
if (i==12 && tw!=0) { foundinstatus=1; }
+ if (i==13 && tw!=0) { foundcredits=1; }
}
- verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus);
+ verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits);
}
function flip(vf,tf) {
@@ -834,7 +860,8 @@
###############################################################
###############################################################
sub print_upload_manager_footer {
- my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype) = @_;
+ my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype,
+ $showcredits) = @_;
my $form = 'document.studentform';
my $formname = 'studentform';
my ($krbdef,$krbdefdom) =
@@ -923,9 +950,15 @@
&mt('Default role'))
.&mt('Choose the role to assign to users without a value specified in the uploaded file.')
} elsif ($context eq 'course') {
- $Str .= &Apache::lonhtmlcommon::row_title(
+ if ($showcredits) {
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role, section and credits'))
+ .&mt('Choose the role and/or section(s) and/or credits to assign to users without values specified in the uploaded file.');
+ } else {
+ $Str .= &Apache::lonhtmlcommon::row_title(
&mt('Default role and section'))
- .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
+ .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
+ }
} else {
$Str .= &Apache::lonhtmlcommon::row_title(
&mt('Default role and/or section(s)'))
@@ -933,7 +966,8 @@
}
if (($context eq 'domain') || ($context eq 'author')) {
$Str .= '<br />';
- my ($options,$cb_script,$coursepick) = &default_role_selector($context,1);
+ my ($options,$cb_script,$coursepick) =
+ &default_role_selector($context,1,'',$showcredits);
if ($context eq 'domain') {
$Str .= '<p>'
.'<b>'.&mt('Domain Level').'</b><br />'
@@ -950,8 +984,13 @@
} else {
my ($cnum,$cdom) = &get_course_identity();
my $rowtitle = &mt('section');
- my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,
- $permission,$context,'upload',$crstype);
+ my $defaultcredits;
+ if ($showcredits) {
+ $defaultcredits = &get_defaultcredits();
+ }
+ my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,$permission,
+ $context,'upload',$crstype,$showcredits,
+ $defaultcredits);
$Str .= $secbox
.&Apache::lonhtmlcommon::row_closure();
my %lt;
@@ -997,6 +1036,43 @@
return;
}
+sub get_defaultcredits {
+ my ($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'};
+ }
+ return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/));
+ my ($defaultcredits,$domdefcredits);
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
+ if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
+ my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
+ if ($instcode) {
+ $domdefcredits = $domdefaults{'officialcredits'};
+ } else {
+ $domdefcredits = $domdefaults{'unofficialcredits'};
+ }
+ } else {
+ return;
+ }
+
+ if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
+ $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
+ } elsif (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'})) {
+ $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'};
+ } else {
+ my %crsinfo =
+ &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
+ $defaultcredits = $crsinfo{'internal.defaultcredits'};
+ }
+ if ($defaultcredits eq '') {
+ $defaultcredits = $domdefcredits;
+ }
+ return $defaultcredits;
+}
+
sub forceid_change {
my ($context) = @_;
my $output =
@@ -1018,7 +1094,7 @@
###############################################################
###############################################################
sub print_upload_manager_form {
- my ($r,$context,$permission,$crstype) = @_;
+ my ($r,$context,$permission,$crstype,$showcredits) = @_;
my $firstLine;
my $datatoken;
if (!$env{'form.datatoken'}) {
@@ -1051,7 +1127,9 @@
'domain_choice' => 'scalar',
'inststatus_choice' => 'scalar',
};
- my $defdom = $env{'request.role.domain'};
+ if ($showcredits) {
+ $col_setting_names->{'credits_choice'} = 'scalar';
+ }
if ($context eq 'course') {
&Apache::loncommon::restore_course_settings('enrollment_upload',
$col_setting_names);
@@ -1059,6 +1137,7 @@
&Apache::loncommon::restore_settings($context,'user_upload',
$col_setting_names);
}
+ my $defdom = $env{'request.role.domain'};
#
# Determine kerberos parameters as appropriate
my ($krbdef,$krbdefdom) =
@@ -1084,6 +1163,10 @@
['role',&mt('Role'), $env{'form.role_choice'}],
['domain',&mt('Domain'), $env{'form.domain_choice'}],
['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
+ if ($showcredits) {
+ push(@field,
+ ['credits',&mt('Student Credits'), $env{'form.credits_choice'}]);
+ }
if ($env{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($r,\@records);
$i=&Apache::loncommon::csv_print_select_table($r,\@records,
@@ -1101,7 +1184,7 @@
}
}
&print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
- $context,$permission,$crstype);
+ $context,$permission,$crstype,$showcredits);
}
sub setup_date_selectors {
@@ -1258,7 +1341,7 @@
}
sub default_role_selector {
- my ($context,$checkpriv,$crstype) = @_;
+ my ($context,$checkpriv,$crstype,$showcredits) = @_;
my %customroles;
my ($options,$coursepick,$cb_jscript);
if ($context ne 'author') {
@@ -1270,6 +1353,7 @@
'grs' => "Section",
'exs' => "Existing sections",
'new' => "New section",
+ 'crd' => "Credits",
);
$options = '<select name="defaultrole">'."\n".
' <option value="">'.&mt('Please select').'</option>'."\n";
@@ -1289,12 +1373,18 @@
}
my $courseform = &Apache::loncommon::selectcourse_link
('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
+ my ($credit_elem,$creditsinput);
+ if ($showcredits) {
+ $credit_elem = 'credits';
+ $creditsinput = '<td><input type="text" name="credits" value="" /></td>';
+ }
$cb_jscript =
- &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community');
+ &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community',$credit_elem);
$coursepick = &Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row().
'<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
'<th>'.$lt{'grs'}.'</th>'.
+ '<th>'.$lt{'crd'}.'</th>'.
&Apache::loncommon::end_data_table_header_row().
&Apache::loncommon::start_data_table_row()."\n".
'<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
@@ -1316,7 +1406,7 @@
'<input type="hidden" name="dccourse" value="" />'.
'<input type="hidden" name="dcdomain" value="" />'.
'<input type="hidden" name="crstype" value="" />'.
- '</td></tr></table></td>'.
+ '</td></tr></table></td>'.$creditsinput.
&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table()."\n";
}
@@ -1453,7 +1543,7 @@
sub print_userlist {
my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
- $idlist,$idlist_titles) = @_;
+ $idlist,$idlist_titles,$showcredits) = @_;
my $format = $env{'form.output'};
if (! exists($env{'form.sortby'})) {
$env{'form.sortby'} = 'username';
@@ -1529,7 +1619,7 @@
$r->print(§ion_group_filter($cnum,$cdom));
}
$r->print('</div><div class="LC_left_float">'.
- &column_checkboxes($context,$mode,$formname).
+ &column_checkboxes($context,$mode,$formname,$showcredits).
'</div>');
if ($env{'form.phase'} eq '') {
$r->print('<br clear="all" />'.
@@ -1543,7 +1633,7 @@
&list_submit_button(&mt('Update Display'))."\n");
}
- my @cols = &infocolumns($context,$mode);
+ my @cols = &infocolumns($context,$mode,$showcredits);
if (!@cols) {
$r->print('<hr clear="all" /><span class="LC_warning">'.
&mt('No user information selected for display.').'</span>'.
@@ -1730,10 +1820,12 @@
my $usercount;
if ($env{'form.action'} eq 'modifystudent') {
($usercount) = &show_users_list($r,$context,'view',$permission,
- $env{'form.Status'},\%userlist,$keylist);
+ $env{'form.Status'},\%userlist,$keylist,'',
+ $showcredits);
} else {
($usercount) = &show_users_list($r,$context,$env{'form.output'},
- $permission,$env{'form.Status'},\%userlist,$keylist);
+ $permission,$env{'form.Status'},\%userlist,
+ $keylist,'',$showcredits);
}
if (!$usercount) {
$r->print('<br /><span class="LC_info">'
@@ -1854,12 +1946,12 @@
}
sub infocolumns {
- my ($context,$mode) = @_;
+ my ($context,$mode,$showcredits) = @_;
my @cols;
if (($mode eq 'pickauthor') || ($mode eq 'autoenroll')) {
- @cols = &get_cols_array($context,$mode);
+ @cols = &get_cols_array($context,$mode,$showcredits);
} else {
- my @posscols = &get_cols_array($context,$mode);
+ my @posscols = &get_cols_array($context,$mode,$showcredits);
if ($env{'form.phase'} ne '') {
my @checkedcols = &Apache::loncommon::get_env_multiple('form.showcol');
foreach my $col (@checkedcols) {
@@ -1875,7 +1967,7 @@
}
sub get_cols_array {
- my ($context,$mode) = @_;
+ my ($context,$mode,$showcredits) = @_;
my @cols;
if ($mode eq 'pickauthor') {
@cols = ('username','fullname','status','email');
@@ -1893,6 +1985,9 @@
}
push(@cols,'email');
if (($context eq 'course') && ($mode ne 'autoenroll')) {
+ if ($showcredits) {
+ push(@cols,'credits');
+ }
push(@cols,'lastlogin','clicker');
}
if (($context eq 'course') && ($mode ne 'autoenroll') &&
@@ -1907,8 +2002,8 @@
}
sub column_checkboxes {
- my ($context,$mode,$formname) = @_;
- my @cols = &get_cols_array($context,$mode);
+ my ($context,$mode,$formname,$showcredits) = @_;
+ my @cols = &get_cols_array($context,$mode,$showcredits);
my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
my (%disabledchk,%unchecked);
if ($env{'form.phase'} eq '') {
@@ -1917,6 +2012,9 @@
$disabledchk{'role'} = 1;
$unchecked{'photo'} = 1;
$unchecked{'clicker'} = 1;
+ if ($showcredits) {
+ $unchecked{'credits'} = 1;
+ }
} elsif ($context eq 'domain') {
$unchecked{'extent'} = 1;
}
@@ -2012,6 +2110,7 @@
'end' => "end date",
'status' => "status",
'role' => "role",
+ 'credits' => "credits",
'type' => "enroll type/action",
'email' => "e-mail address",
'photo' => "photo",
@@ -2322,6 +2421,7 @@
$index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
$index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
$index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
+ $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
foreach my $key (keys(%{$index})) {
$keylist->[$index->{$key}] = $key;
}
@@ -2370,7 +2470,8 @@
}
sub show_users_list {
- my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname)=@_;
+ my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
+ $showcredits)=@_;
if ($formname eq '') {
$formname = 'studentform';
}
@@ -2385,6 +2486,9 @@
my @sortable = ('username','domain','id','fullname','start','end','email','role');
if ($context eq 'course') {
push(@sortable,('section','groups','type'));
+ if ($showcredits) {
+ push(@sortable,'credits');
+ }
} else {
push(@sortable,'extent');
}
@@ -2395,11 +2499,12 @@
$sortby = 'username';
}
my $setting = $env{'form.roletype'};
- my ($cid,$cdom,$cnum,$classgroups,$crstype);
+ my ($cid,$cdom,$cnum,$classgroups,$crstype,$defaultcredits);
if ($context eq 'course') {
$cid = $env{'request.course.id'};
$crstype = &Apache::loncommon::course_type();
($cnum,$cdom) = &get_course_identity($cid);
+ $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
($classgroups) = &Apache::loncoursedata::get_group_memberships(
$userlist,$keylist,$cdom,$cnum);
if ($mode eq 'autoenroll') {
@@ -2492,7 +2597,7 @@
$r->print(<<END);
<input type="hidden" name="sortby" value="$sortby" />
END
- my @cols = &infocolumns($context,$mode);
+ my @cols = &infocolumns($context,$mode,$showcredits);
my %coltxt = &get_column_names($context);
my %acttxt = &Apache::lonlocal::texthash(
'pr' => "Proceed",
@@ -2794,6 +2899,11 @@
'gif','thumbnail');
}
}
+ if (($role eq 'st') && ($defaultcredits)) {
+ if ($userlist->{$user}->[$index{'credits'}] eq '') {
+ $userlist->{$user}->[$index{'credits'}] = $defaultcredits;
+ }
+ }
}
}
my %emails = &Apache::loncommon::getemails($uname,$udom);
@@ -2911,7 +3021,8 @@
$checkval .= ':'.$in{'section'};
if ($role eq 'st') {
$checkval .= ':'.$in{'type'}.':'.
- $in{'lockedtype'};
+ $in{'lockedtype'}.':'.
+ $in{'credits'};
}
}
}
@@ -3159,6 +3270,7 @@
chgdates => "Change starting/ending dates",
chgsec => "Change section associated with user roles",
);
+ # FIXME Add an option to change credits for student roles.
my ($output,$options,%choices);
# FIXME Disable actions for now for roletype=course in domain context
if ($context eq 'domain' && $setting eq 'course') {
@@ -3286,11 +3398,13 @@
}
sub date_section_selector {
- my ($context,$permission,$crstype) = @_;
+ my ($context,$permission,$crstype,$showcredits) = @_;
my $callingform = $env{'form.callingform'};
my $formname = 'dateselect';
my $groupslist = &get_groupslist();
- my $sec_js = &setsections_javascript($formname,$groupslist);
+ my $sec_js =
+ &setsections_javascript($formname,$groupslist,undef,undef,$crstype,
+ $showcredits);
my $output = <<"END";
<script type="text/javascript">
// <![CDATA[
@@ -3422,7 +3536,8 @@
$info = '<input type="hidden" name="retainsec" value="0" />';
}
my $rowtitle = &mt('New section to assign');
- my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context,'',$crstype);
+ my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,
+ $permission,$context,'chgsec',$crstype);
$output .= $info.$secbox;
}
$output .= '<p>'.
@@ -3432,13 +3547,14 @@
}
sub section_picker {
- my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype) = @_;
+ my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype,
+ $showcredits,$credits) = @_;
my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
my $sections_select .= &course_sections(\%sections_count,$role);
my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
if ($mode eq 'upload') {
my ($options,$cb_script,$coursepick) =
- &default_role_selector($context,1,$crstype);
+ &default_role_selector($context,1,$crstype,$showcredits);
$secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
$options. &Apache::lonhtmlcommon::row_closure(1)."\n";
}
@@ -3456,8 +3572,17 @@
$env{'request.course.sec'}.'" />'.
$env{'request.course.sec'};
}
- $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n".
- &Apache::lonhtmlcommon::end_pick_box().'</div>';
+ $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n";
+ unless ($mode eq 'chgsec') {
+ if ($showcredits) {
+ $secbox .=
+ &Apache::lonhtmlcommon::row_title(&mt('credits (students)'),
+ 'LC_evenrow_value')."\n".
+ '<input type="text" name="credits" size="3" value="'.$credits.'" />'."\n".
+ &Apache::lonhtmlcommon::row_closure(1)."\n";
+ }
+ }
+ $secbox .= &Apache::lonhtmlcommon::end_pick_box().'</div>';
return $secbox;
}
@@ -3898,7 +4023,7 @@
# ================================================= Drop/Add from uploaded file
sub upfile_drop_add {
- my ($r,$context,$permission) = @_;
+ my ($r,$context,$permission,$showcredits) = @_;
&Apache::loncommon::load_tmp_file($r);
my @userdata=&Apache::loncommon::upfile_record_sep();
if($env{'form.noFirstLine'}){shift(@userdata);}
@@ -3919,25 +4044,17 @@
}
#
# Store the field choices away
- foreach my $field (qw/username names
- fname mname lname gen id sec ipwd email role domain/) {
+ my @storefields = qw/username names fname mname lname gen id
+ sec ipwd email role domain inststatus/;
+ if ($showcredits) {
+ push (@storefields,'credits');
+ }
+ my %fieldstype;
+ foreach my $field (@storefields) {
$env{'form.'.$field.'_choice'}=$fields{$field};
+ $fieldstype{$field.'_choice'} = 'scalar';
}
- &Apache::loncommon::store_course_settings('enrollment_upload',
- { 'username_choice' => 'scalar',
- 'names_choice' => 'scalar',
- 'fname_choice' => 'scalar',
- 'mname_choice' => 'scalar',
- 'lname_choice' => 'scalar',
- 'gen_choice' => 'scalar',
- 'id_choice' => 'scalar',
- 'sec_choice' => 'scalar',
- 'ipwd_choice' => 'scalar',
- 'email_choice' => 'scalar',
- 'role_choice' => 'scalar',
- 'domain_choice' => 'scalar',
- 'inststatus_choice' => 'scalar'});
- #
+ &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
my ($cid,$crstype,$setting);
if ($context eq 'domain') {
$setting = $env{'form.roleaction'};
@@ -4005,19 +4122,30 @@
$amode = ''; # This causes the loop below to be skipped
}
}
- my ($defaultsec,$defaultrole);
+ my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
if ($context eq 'domain') {
if ($setting eq 'domain') {
$defaultrole = $env{'form.defaultrole'};
} elsif ($setting eq 'course') {
$defaultrole = $env{'form.courserole'};
$defaultsec = $env{'form.sections'};
+ if ($showcredits) {
+ $commoncredits = $env{'form.credits'};
+ if ($crstype ne 'Community') {
+ my %coursehash=&Apache::lonnet::coursedescription($cid);
+ $defaultcredits = $coursehash{'internal.defaultcredits'};
+ }
+ }
}
} elsif ($context eq 'author') {
$defaultrole = $env{'form.defaultrole'};
} elsif ($context eq 'course') {
$defaultrole = $env{'form.defaultrole'};
$defaultsec = $env{'form.sections'};
+ if ($showcredits) {
+ $commoncredits = $env{'form.credits'};
+ $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
+ }
}
# Check to see if user information can be changed
my @userinfo = ('firstname','middlename','lastname','generation',
@@ -4277,6 +4405,21 @@
foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
$$_ =~ s/(\s+$|^\s+)//g;
}
+ my $credits;
+ if ($showcredits) {
+ if (($role eq 'st') && ($crstype ne 'Community')) {
+ $credits = $entries{$fields{'credits'}};
+ if ($credits ne '') {
+ $credits =~ s/[^\d\.]//g;
+ }
+ if ($credits eq '') {
+ $credits = $commoncredits;
+ }
+ if ($credits eq $defaultcredits) {
+ undef($credits);
+ }
+ }
+ }
# check against rules
my $checkid = 0;
my $newuser = 0;
@@ -4407,7 +4550,7 @@
$fname,$mname,$lname,$gen,$sec,$enddate,
$startdate,$env{'form.forceid'},
$desiredhost,$email,'manual','',$cid,
- '',$context,$inststatus);
+ '',$context,$inststatus,$credits);
$userresult = $roleresult;
} else {
if ($role ne '') {
@@ -4681,7 +4824,7 @@
foreach my $item (@changelist) {
my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
@sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
- $nothingtodo,$keepnosection);
+ $nothingtodo,$keepnosection,$credits);
if ($choice eq 'drop') {
($uname,$udom,$sec) = split(/:/,$item,-1);
$role = 'st';
@@ -4694,7 +4837,8 @@
$scope = $scopestem.'/'.$sec;
}
} elsif ($context eq 'course') {
- ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
+ ($uname,$udom,$role,$sec,$type,$locktype,$credits) =
+ split(/\:/,$item);
$cid = $env{'request.course.id'};
$scopestem = '/'.$cid;
$scopestem =~s/\_/\//g;
@@ -4713,7 +4857,7 @@
} elsif ($setting eq 'author') {
($uname,$udom,$role,$scope) = split(/\:/,$item);
} elsif ($setting eq 'course') {
- ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
+ ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits) =
split(/\:/,$item);
$scope = '/'.$cid;
$scope =~s/\_/\//g;
@@ -4736,7 +4880,7 @@
$end = $now;
if ($role eq 'st') {
$result =
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
} else {
$result =
&Apache::lonnet::revokerole($udom,$uname,$scope,$role,
@@ -4744,7 +4888,7 @@
}
} elsif ($choice eq 'delete') {
if ($role eq 'st') {
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context);
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits);
}
$result =
&Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
@@ -4757,7 +4901,7 @@
}
if ($choice eq 'reenable') {
if ($role eq 'st') {
- $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
} else {
$result =
&Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
@@ -4765,14 +4909,14 @@
}
} elsif ($choice eq 'activate') {
if ($role eq 'st') {
- $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
} else {
$result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
$now,'','',$context);
}
} elsif ($choice eq 'chgdates') {
if ($role eq 'st') {
- $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
} else {
$result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
$start,'','',$context);
@@ -4842,7 +4986,7 @@
} else {
if ($role eq 'st') {
$result =
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits);
} else {
my $newscope = $scopestem;
$result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
@@ -4856,7 +5000,7 @@
foreach my $newsec (@newsecs) {
if (!grep(/^\Q$newsec\E$/, at retained)) {
if ($role eq 'st') {
- $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
if (@newsecs > 1) {
my $showsingle;
if ($newsec eq '') {
@@ -5148,14 +5292,18 @@
}
sub setsections_javascript {
- my ($formname,$groupslist,$mode,$checkauth,$crstype) = @_;
+ my ($formname,$groupslist,$mode,$checkauth,$crstype,$showcredits) = @_;
my ($checkincluded,$finish,$rolecode,$setsection_js);
if ($mode eq 'upload') {
$checkincluded = 'formname.name == "'.$formname.'"';
$finish = "return 'ok';";
$rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
} elsif ($formname eq 'cu') {
- $checkincluded = 'formname.elements[i-1].checked == true';
+ if (($crstype eq 'Course') && ($showcredits)) {
+ $checkincluded = "((role == 'st') && (formname.elements[i-2].checked == true)) || ((role != 'st') && (formname.elements[i-1].checked == true))";
+ } else {
+ $checkincluded = 'formname.elements[i-1].checked == true';
+ }
if ($checkauth) {
$finish = "var authcheck = auth_check();\n".
" if (authcheck == 'ok') {\n".
@@ -5214,8 +5362,8 @@
var checkcurr = str.match(re1);
if (checkcurr != null) {
var num = i;
+ $rolecode
if ($checkincluded) {
- $rolecode
if (role == 'cc' || role == 'co') {
if (role == 'cc') {
alert("$alerts{'secd'}\\n$alerts{'accr'}");
@@ -5588,7 +5736,7 @@
}
sub dc_setcourse_js {
- my ($formname,$mode,$context) = @_;
+ my ($formname,$mode,$context,$showcredits) = @_;
my ($dc_setcourse_code,$authen_check);
my $cctext = &Apache::lonnet::plaintext('cc');
my $cotext = &Apache::lonnet::plaintext('co');
@@ -5674,7 +5822,7 @@
}
SCRIPTTOP
if ($mode ne 'upload') {
- $dc_setcourse_code .= (<<"ENDSCRIPT");
+ $dc_setcourse_code .= (<<"SCRIPTMID");
var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
var numcourse = getIndex(document.$formname.dccourse);
if (numcourse == "-1") {
@@ -5700,6 +5848,16 @@
if (numend != "-1") {
document.$formname.elements[numend].name = "end"+coursename
}
+SCRIPTMID
+ if ($showcredits) {
+ $dc_setcourse_code .= <<ENDCRED;
+ var numcredits = getIndex(document.$formname.credits);
+ if (numcredits != "-1") {
+ document.$formname.elements[numcredits].name = "credits"+coursename;
+ }
+ENDCRED
+ }
+ $dc_setcourse_code .= <<ENDSCRIPT;
}
}
var authcheck = auth_check();
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.374 loncom/interface/loncreateuser.pm:1.375
--- loncom/interface/loncreateuser.pm:1.374 Tue Feb 19 17:30:35 2013
+++ loncom/interface/loncreateuser.pm Fri Mar 1 04:55:34 2013
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.374 2013/02/19 17:30:35 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.375 2013/03/01 04:55:34 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1042,7 +1042,8 @@
}
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 +1134,7 @@
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 +1177,13 @@
<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') {
@@ -1319,7 +1323,8 @@
$r->print($portfolioform.$domroleform);
if ($env{'form.action'} eq 'singlestudent') {
$r->print(&date_sections_select($context,$newuser,$formname,
- $permission,$crstype));
+ $permission,$crstype,$ccuname,
+ $ccdomain,$showcredits));
}
$r->print('</div><div class="LC_clear_float_footer"></div>');
} else { # user already exists
@@ -1421,8 +1426,16 @@
unless ($gotdiv) {
$r->print('<div class="LC_left_float">');
}
+ 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));
+ $permission,$crstype,$ccuname,
+ $ccdomain,$showcredits));
}
if ($gotdiv) {
$r->print('</div><div class="LC_clear_float_footer"></div>');
@@ -1441,7 +1454,7 @@
}
$r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
} else {
- $r->print('<h3>'.&mt('Add Roles').'</h3>');
+ $r->print('<fieldset><legend>'.&mt('Add Roles').'</legend>');
my $addrolesdisplay = 0;
if ($context eq 'domain' || $context eq 'author') {
$addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
@@ -1451,23 +1464,23 @@
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><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><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><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><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']));
@@ -1496,22 +1509,32 @@
}
sub date_sections_select {
- my ($context,$newuser,$formname,$permission,$crstype) = @_;
+ 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,$context,'',$crstype);
+ $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 = '';
@@ -1528,7 +1551,8 @@
if ($context eq 'course') {
$nondc_setsection_code =
&Apache::lonuserutils::setsections_javascript($formname,$groupslist,
- undef,$checkauth);
+ undef,$checkauth,
+ $crstype);
}
if ($checkauth) {
$nondc_setsection_code .=
@@ -1548,7 +1572,8 @@
}
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",
@@ -1557,6 +1582,7 @@
'ren' => "Re-Enable",
'rol' => "Role",
'ext' => "Extent",
+ 'crd' => "Credits",
'sta' => "Start",
'end' => "End",
);
@@ -1619,6 +1645,7 @@
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);
@@ -1647,6 +1674,15 @@
}
$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;
@@ -1745,7 +1781,13 @@
}
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]',
@@ -1798,9 +1840,8 @@
} else {
$contextrole = &mt('Existing Roles in this Domain');
}
- $r->print('
-<h3>'.$lt{'rer'}.'</h3>'.
-'<div>'.$contextrole.'</div>'.
+ $r->print('<div>'.
+'<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'}.
@@ -1812,7 +1853,8 @@
$r->print($output{$type}."\n");
}
}
- $r->print(&Apache::loncommon::end_data_table());
+ $r->print(&Apache::loncommon::end_data_table().
+ '</fieldset></div>');
}
return;
}
@@ -2315,7 +2357,7 @@
# ================================================================= 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
@@ -2594,10 +2636,14 @@
$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
@@ -3010,7 +3056,8 @@
}
&Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
if ($env{'form.action'} eq 'singlestudent') {
- &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype);
+ &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
+ $crstype,$showcredits,$defaultcredits);
$r->print('<p><a href="javascript:backPage(document.userupdate)">');
if ($crstype eq 'Community') {
$r->print(&mt('Enroll Another Member'));
@@ -3019,7 +3066,7 @@
}
$r->print('</a></p>');
} 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) {
@@ -3327,7 +3374,7 @@
}
sub update_roles {
- my ($r,$context) = @_;
+ my ($r,$context,$showcredits) = @_;
my $now=time;
my @rolechanges;
my %disallowed;
@@ -3437,7 +3484,13 @@
if ($role eq 'st') {
if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
my ($cdom,$cnum,$csec) = ($1,$2,$3);
- my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context);
+ 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;
@@ -3536,8 +3589,20 @@
# 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);
@@ -3551,13 +3616,13 @@
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$/, at rolechanges)) {
@@ -3624,8 +3689,31 @@
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'));
@@ -3637,6 +3725,17 @@
# 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);
@@ -3646,7 +3745,8 @@
$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'}));
if ($env{'form.sections'} ne '') {
@@ -4190,6 +4290,7 @@
} 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']);
@@ -4221,6 +4322,16 @@
&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,
@@ -4243,11 +4354,12 @@
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);
@@ -4272,13 +4384,15 @@
.' 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) =
@@ -4323,7 +4437,7 @@
$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);
@@ -4426,7 +4540,8 @@
$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;
@@ -4457,8 +4572,8 @@
} 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>');
@@ -6483,7 +6598,8 @@
}
sub course_level_table {
- my (%inccourses) = @_;
+ my ($inccourses,$showcredits,$defaultcredits) = @_;
+ return unless (ref($inccourses) eq 'HASH');
my $table = '';
# Custom Roles?
@@ -6498,11 +6614,12 @@
'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);
@@ -6524,12 +6641,14 @@
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);
}
}
}
@@ -6551,8 +6670,10 @@
$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();
@@ -6560,12 +6681,21 @@
}
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 '') {
@@ -6591,7 +6721,7 @@
'</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;
@@ -6607,7 +6737,7 @@
}
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.'" />'.
@@ -6615,7 +6745,11 @@
'<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",
@@ -6625,12 +6759,15 @@
'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'".')" />'.
@@ -6657,7 +6794,11 @@
'<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=
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.105 loncom/interface/lonpickcourse.pm:1.106
--- loncom/interface/lonpickcourse.pm:1.105 Tue Feb 5 17:02:40 2013
+++ loncom/interface/lonpickcourse.pm Fri Mar 1 04:55:35 2013
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.105 2013/02/05 17:02:40 bisitz Exp $
+# $Id: lonpickcourse.pm,v 1.106 2013/03/01 04:55:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,6 +31,7 @@
use strict;
use Apache::Constants qw(:common);
use Apache::loncommon;
+use Apache::lonhtmlcommon;
use Apache::loncoursedata;
use Apache::lonnet;
use Apache::lonlocal;
@@ -105,10 +106,11 @@
if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) &&
($env{'form.pickedcourse'})) {
- $loaditem{'onload'} .= 'setRoles();setSections();';
+ $loaditem{'onload'} .= 'setDefaultCredits();setRoles();setSections();';
}
my $js = &js_changer();
- $r->print(&Apache::loncommon::start_page($title,$js,
+ $r->print(&Apache::loncommon::start_page($title,
+ &Apache::lonhtmlcommon::scripttag($js),
{'add_entries' => \%loaditem,
'no_nav_bar' => 1, }));
@@ -206,20 +208,19 @@
}
sub js_changer {
- return <<"ENDJS";
+ return <<ENDJS;
<script type="text/javascript">
-
+// <![CDATA[
function updateFilters(caller) {
if (typeof(caller) != "undefined") {
document.filterpicker.updater.value = caller.name;
}
document.filterpicker.submit();
}
-
+// ]]
</script>
ENDJS
-
}
sub processpick {
@@ -281,6 +282,13 @@
my $cdom = $coursedescription{'domain'};
my $cnum = $coursedescription{'num'};
my $crstype = $coursedescription{'type'};
+ my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
+ my ($showcredits,$credits);
+ if (($crstype ne 'Community') &&
+ ($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'})) {
+ $showcredits = 1;
+ $credits = $coursedescription{'internal.defaultcredits'};
+ }
my $sec_element = 'currsec';
my $grplist_element = 'groups';
my ($sections,$groups) =
@@ -291,6 +299,7 @@
my $groupslist = join(',',@{$groups});
$output = qq|
<script type="text/javascript">
+// <![CDATA[
function setSections() {
opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
window.opener.setSect('$seclist');
@@ -299,9 +308,18 @@
function setRoles() {
window.opener.setRole('$crstype');
}
+|;
+ if ($showcredits) {
+ $output .= qq|
+function setDefaultCredits() {
+ window.opener.setCredits('$credits');
+}
+|;
+ }
+ $output .= qq|
+// ]]>
</script>
|;
-;
}
return $output;
}
@@ -324,9 +342,10 @@
my $ccrolechk = ' ';
my $menuchk = ' checked="checked" ';
$r->print(
- '<fieldset>'
- .'<legend>'.&mt('Action').'</legend>'
- .'<div class="LC_nobreak"><label>'
+ '<div class="LC_left_float">'
+ .'<fieldset>'
+ .'<legend>'.&mt('Pick action').'</legend>'
+ .'<span class="LC_nobreak"><label>'
.'<input type="radio" name="phase" value="ccrole"'.$ccrolechk.'/>'
.' ');
if ($type eq 'Community') {
@@ -334,17 +353,17 @@
} else {
$r->print(&mt('Enter the course with the role of [_1].',$cctitle));
}
- $r->print('</label></div>'
- .'<div class="LC_nobreak"><label>'
+ $r->print('</label></span><br />'
+ .'<span class="LC_nobreak"><label>'
.'<input type="radio" name="phase" value="menu"'.$menuchk.'/> ');
if ($type eq 'Community') {
$r->print(&mt('View or modify community settings which only a [_1] may modify.',$dctitle));
} else {
$r->print(&mt('View or modify course settings which only a [_1] may modify.',$dctitle));
}
- $r->print('</label></div>'
- .'</fieldset>'
- .'<br />'
+ $r->print('</label></span>'
+ .'</fieldset></div>'
+ .'<br clear="all" />'
);
}
}
@@ -891,7 +910,7 @@
$ccrole = 'cc';
}
if (!$onlyown) {
- $r->print(&mt('Searching ...').'<br /> <br />');
+ $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
$r->rflush();
if (($filter->{'ownerfilter'} ne '') ||
($filter->{'ownerdomfilter'} ne '')) {
More information about the LON-CAPA-cvs
mailing list