--- loncom/interface/lonrequestcourse.pm 2010/01/14 20:08:13 1.43 +++ loncom/interface/lonrequestcourse.pm 2013/07/22 18:06:51 1.68 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.43 2010/01/14 20:08:13 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.68 2013/07/22 18:06:51 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -128,17 +128,21 @@ sub handler { } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['action','showdom','cnum','state','crstype']); + ['action','showdom','cnum','state','crstype','queue']); &Apache::lonhtmlcommon::clear_breadcrumbs(); my $dom = &get_course_dom(); my $action = $env{'form.action'}; my $state = $env{'form.state'}; my (%states,%stored); - my ($jscript,$uname,$udom,$result,$warning); + my ($jscript,$uname,$udom,$result,$warning,$showcredits,$instcredits); + my %domdefs = &Apache::lonnet::get_domain_defaults($dom); + if ($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'}) { + $showcredits = 1; + } $states{'display'} = ['details']; $states{'view'} = ['pick_request','details','cancel','removal']; - $states{'log'} = ['filter','display']; + $states{'log'} = ['display']; $states{'new'} = ['courseinfo','enrollment','personnel','review','process']; if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) { @@ -147,6 +151,12 @@ sub handler { } } + if (($action eq 'new') && (&Apache::loncoursequeueadmin::author_prompt())) { + if (ref($states{$action}) eq 'ARRAY') { + push(@{$states{$action}},'reqauthor'); + } + } + foreach my $key (keys(%states)) { if (ref($states{$key}) eq 'ARRAY') { unshift (@{$states{$key}},'crstype'); @@ -162,24 +172,26 @@ sub handler { personnel => 'Personnel', review => 'Review', process => 'Result', + reqauthor => 'Authoring Space Result', pick_request => 'Display Summary', details => 'Request Details', cancel => 'Cancel Request', removal => 'Outcome', + display => 'Request Logs', ); if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) { $trail{'enrollment'} = 'Enrollment'; } - my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) = + my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) = &get_breadcrumbs($dom,$action,\$state,\%states,\%trail); if ($action eq 'display') { if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) { - my $namespace = 'courserequestqueue'; if ($env{'form.cnum'} ne '') { my $cnum = $env{'form.cnum'}; - my $reqkey = $cnum.'_approval'; + my $queue = $env{'form.queue'}; + my $reqkey = $cnum.'_'.$queue; my $namespace = 'courserequestqueue'; my $domconfig = &Apache::lonnet::get_domainconfiguser($dom); my %queued = @@ -261,11 +273,11 @@ sub handler { } } } - my %elements = &form_elements($dom); + (my $elements,$instcredits) = &form_elements($dom,$showcredits); my $elementsref = {}; - if (ref($elements{$action}) eq 'HASH') { - if (ref($elements{$action}{$state}) eq 'HASH') { - $elementsref = $elements{$action}{$state}; + if ((ref($elements) eq 'HASH') && (ref($elements->{$action}) eq 'HASH')) { + if (ref($elements->{$action}{$state}) eq 'HASH') { + $elementsref = $elements->{$action}{$state}; } } if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) { @@ -275,6 +287,9 @@ sub handler { $jscript = &mainmenu_javascript(); } else { $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored); + if ($state eq 'courseinfo') { + $jscript .= &cloning_javascript(); + } } } @@ -296,7 +311,7 @@ sub handler { &request_administration($r,$action,$state,$page,\%states,$dom, $jscript,$loaditems,$crumb,$newinstcode, $codechk,$checkedcode,$description, - \@invalidcrosslist); + $showcredits,$instcredits,\@invalidcrosslist); } } else { $r->print(&header('Course/Community Requests').$crumb. @@ -309,21 +324,39 @@ sub handler { &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\%request_domains); } else { &request_administration($r,$action,$state,$page,\%states,$dom,$jscript, - $loaditems,$crumb); + $loaditems,$crumb,'','','','',$showcredits); } } elsif ($action eq 'display') { if ($warning ne '') { my $args = { only_body => 1 }; - $r->print(&header('Course/Community Requests','','',$args).$crumb. + $r->print(&header('Course/Community Requests','','' ,'',$args).$crumb. '

'.&mt('Course/Community Request Details').'

'. '
'.$warning.'
'. &close_popup_form()); } else { &request_administration($r,$action,$state,$page,\%states,$dom,$jscript, - $loaditems,$crumb,'','','','','',$uname,$udom); + $loaditems,$crumb,'','','','',$showcredits,'','', + $uname,$udom); } } elsif ($action eq 'log') { - &print_request_logs($jscript,$loaditems,$crumb); + if ($state eq 'crstype') { + &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains); + } else { + $jscript .= < 1) { + for (var i=0; i '/adm/requestcourse', text => "$trail->{$states->{$action}[$i]}", @@ -451,7 +500,8 @@ sub header { } sub form_elements { - my ($dom) = @_; + my ($dom,$showcredits) = @_; + my $instcredits; my %elements = ( new => { @@ -462,6 +512,7 @@ sub form_elements { }, courseinfo => { cdescr => 'text', + cloning => 'radio', clonecrs => 'text', clonedom => 'selectbox', datemode => 'radio', @@ -518,7 +569,6 @@ sub form_elements { } if (&Apache::lonnet::auto_run('',$dom)) { my %extras = ( - sectotal => 'hidden', enrollstart_month => 'selectbox', enrollstart_hour => 'selectbox', enrollend_month => 'selectbox', @@ -534,12 +584,39 @@ sub form_elements { addcrosslist => 'checkbox', autoadds => 'radio', autodrops => 'radio', - ); - if ($env{'form.sectotal'} > 0) { - for (my $i=0; $i<$env{'form.sectotal'}; $i++) { - $extras{'sec_'.$i} = 'radio'; - $extras{'secnum_'.$i} = 'text'; - $extras{'loncapasec_'.$i} = 'text'; + ); + my ($instcode,$titlescount) = &get_instcode($dom); + if ($instcode) { + my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode); + if (@sections) { + $extras{'sectotal'} = 'hidden'; + if ($env{'form.sectotal'} > 0) { + for (my $i=0; $i<$env{'form.sectotal'}; $i++) { + $extras{'sec_'.$i} = 'radio'; + $extras{'secnum_'.$i} = 'text'; + $extras{'loncapasec_'.$i} = 'text'; + } + } + } else { + $extras{'addsection'} = 'checkbox'; + my $sectotal = $env{'form.sectotal'}; + if ($env{'form.addsection'}) { + $sectotal ++; + } + for (my $i=0; $i<$sectotal; $i++) { + $extras{'sec_'.$i} = 'checkbox'; + $extras{'secnum_'.$i} = 'text', + $extras{'loncapasec_'.$i} = 'text', + } + } + (my $outcome,my $desc,$instcredits) = + &Apache::lonnet::auto_validate_instcode(undef,$dom,$instcode); + if ($showcredits && $instcredits eq '') { + $extras{'coursecredits'} = 'text'; + } + } elsif ($env{'form.crstype'} eq 'unofficial') { + if ($showcredits) { + $extras{'coursecredits'} = 'text'; } } my $crosslisttotal = $env{'form.crosslisttotal'}; @@ -549,7 +626,6 @@ sub form_elements { if (!$crosslisttotal) { $crosslisttotal = 1; } - for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) { if ($numtitles) { $extras{'crosslist_'.$i.'_'.$lastitem} = 'text'; @@ -587,7 +663,7 @@ sub form_elements { } my %personnelhash = (%{$elements{'new'}{'personnel'}},%people); %{$elements{'new'}{'personnel'}} = %personnelhash; - return %elements; + return (\%elements,$instcredits);; } sub onload_action { @@ -597,7 +673,10 @@ sub onload_action { if ($state eq 'crstype') { $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)'; } else { - $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs)'; + $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);'; + } + if ($state eq 'courseinfo') { + $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);'; } } return \%loaditems; @@ -606,11 +685,7 @@ sub onload_action { sub print_main_menu { my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$request_domains) = @_; my ($types,$typename) = &Apache::loncommon::course_types(); - my $onchange; - unless ($env{'form.interface'} eq 'textual') { - $onchange = 'this.form.submit()'; - } - + my $onchange = 'this.form.submit()'; my $nextstate_setter = "\n"; if (ref($states) eq 'HASH') { foreach my $key (keys(%{$states})) { @@ -659,7 +734,8 @@ END official => 'You are not permitted to request creation of an official course in this domain.', unofficial => 'You are not permitted to request creation of an unofficial course in this domain.', community => 'You are not permitted to request creation of a community this domain.', - all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.', + all => 'You must choose a specific course type when making a new course request.', + allt => '"All types" is not allowed.', ); $js .= <'.&mt('View/Modify/Cancel pending requests').' '. - &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_closure(). &Apache::lonhtmlcommon::row_title(&mt('Type')).'
'."\n"); - my @excluded = &get_excluded_elements($dom,$states,'new','review'); + my @excluded = &get_excluded_elements($dom,$states,'new','review', + $showcredits); push(@excluded,'origcnum'); $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).''); my $other = 'modify'; @@ -915,7 +993,8 @@ END my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'}); $r->print('

'.$title.'

'."\n".$form."\n". $output); - my @excluded = &get_excluded_elements($dom,$states,'view','cancel'); + my @excluded = &get_excluded_elements($dom,$states,'view','cancel', + $showcredits); $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'
'); my %navtxt = &Apache::lonlocal::texthash ( prev => 'Back', @@ -992,10 +1071,9 @@ END $r->print(&header($title,'','','',{ 'only_body' => 1}). $crumb."\n".'

'.$header.'

'. &print_review($dom,\@codetitles,\%cat_titles,\%cat_order, - \@code_order,$uname,$udom)."\n".''. + \@code_order,$uname,$udom,'','',$instcredits)."\n". + ''. &close_popup_form()); - } elsif ($action eq 'log') { - $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb); } $r->print(&Apache::loncommon::end_page()); return; @@ -1188,7 +1266,7 @@ sub get_instcode { sub print_request_form { my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode, - $description,$invalidcrosslist) = @_; + $description,$showcredits,$instcredits,$invalidcrosslist) = @_; my $formname = 'requestcrs'; my ($next,$prev,$message,$output,$codepicker,$crstype); $prev = $states->{$action}[$page-1]; @@ -1261,7 +1339,7 @@ sub print_request_form { } $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles, \%cat_titles,\%cat_order,\@code_order, - $invalidcrosslist)); + $showcredits,$instcredits,$invalidcrosslist)); } elsif ($state eq 'personnel') { $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist)); } elsif ($state eq 'review') { @@ -1287,16 +1365,38 @@ sub print_request_form { } if ($skipuser) { push(@disallowed,$i); - $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain',''.$personname.':'.$persondom.''); + $disallowmsg{$i} = &mt('[_1] was excluded because new users need to be from the course domain',''.$personname.':'.$persondom.''); next; } } - if (&get_cancreate_status($persondom,$personname,$dom)) { - my ($allowed,$msg) = + my $usertype = &get_usertype($persondom,$personname,\%curr_rules,\%got_rules); + if (&Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype)) { + my ($allowed,$msg,$authtype,$authparam) = &check_newuser_rules($persondom,$personname, \%alerts,\%rulematch,\%inst_results, \%curr_rules,\%got_rules); if ($allowed) { + my %domdefaults = &Apache::lonnet::get_domain_defaults($persondom); + if ($usertype eq 'official') { + if ($authtype eq '') { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } + } elsif ($usertype eq 'unofficial') { + if ($authtype eq '') { + $authtype = 'internal'; + $authparam = ''; + } + } else { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } + if (($authtype eq '') || + (($authtype =~/^krb/) && ($authparam eq ''))) { + push(@disallowed,$i); + $disallowmsg{$i} = &mt('[_1] was excluded because institutional information is incomplete for this new user.',''.$personname.':'.$persondom.''); + next; + } if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') { if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') { $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'}; @@ -1342,7 +1442,11 @@ sub print_request_form { if ($env{'form.origcnum'} =~ /^($match_courseid)$/) { $cnum = $env{'form.origcnum'}; } else { - $cnum = &Apache::lonnet::generate_coursenum($dom); + my $gentype = 'Course'; + if ($crstype eq 'community') { + $gentype = 'Community'; + } + $cnum = &Apache::lonnet::generate_coursenum($dom,$gentype); } &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles, \%cat_order,\@code_order); @@ -1351,7 +1455,7 @@ sub print_request_form { } else { $r->print('

'.&mt('Review course request details before submission').'

'); } - $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg). + $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg,$instcredits). ''); if ($crstype eq 'community') { $navtxt{'next'} = &mt('Submit community request'); @@ -1364,19 +1468,77 @@ sub print_request_form { \%cat_order,\@code_order); } my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles, - \@code_order); + \@code_order,$instcredits); $r->print($result); if (($storeresult eq 'ok') || ($storeresult eq 'created')) { - $r->print('

'); if ($storeresult eq 'ok') { - $r->print(''. - &mt('Modify this request').''.(' 'x4)); + $r->print('

'. + &mt('Modify this request').''.(' 'x4). + ''.&mt('Make another request').'

'); + } + if (&Apache::loncoursequeueadmin::author_prompt()) { + $r->print('

'.&mt('Access to authoring space').'

'. + '

'. + &mt('Although assessment items can be created directly inside a course, such items only use part of the assessment capabilities of LON-CAPA.'). + '
'. + &mt('By contrast, items created in authoring space, then imported into a course, can use all of the features of the assessment engine.').'

'. + '

'.&mt('Request authoring space access now?'). + ' '. + ''. + (' 'x2). + ''. + '

'. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + '
'); + } elsif ($storeresult eq 'created') { + $r->print('

'.&mt('Make another request').'

'); + } + } + } elsif ($state eq 'reqauthor') { + my ($result,@links); + if ($env{'form.requestauthor'}) { + $r->print(&Apache::loncoursequeueadmin::process_reqauthor(\$result)); + if ($result eq 'created') { + my $role = 'au'; + my $spec = "$role./$env{'form.showdom'}/"; + push(@links,&mt('Enter your authoring space with role: [_1]', + ''. + &Apache::lonnet::plaintext($role).'')); + } + } + if (($env{'form.disposition'} eq 'created') && + ($env{'form.cnum'} =~ /^$match_courseid$/) && + ($env{'form.showdom'} =~ /^$match_domain$/)) { + my ($spec,$area,$role,$type); + my $role = 'cc'; + my $spec = "$role./$env{'form.showdom'}/$env{'form.cnum'}"; + my $type = 'Course'; + if ($env{'form.crstype'} eq 'community') { + $type = 'Community'; } - $r->print(''.&mt('Make another request').'

'); - return; + my $showrole = &Apache::lonnet::plaintext($role,$type); + unshift(@links,&mt('Enter new course with role: [_1]', + ''.$showrole.'')); + } + if (@links > 1) { + $r->print(&mt('New roles will be listed on your [_1]Roles[_2] page.', + '','').' '.&mt('Choose a role:'). + '
    '); + foreach my $link (@links) { + $r->print('
  • '.$link.'
  • '); + } + $r->print('
'); + } elsif (@links == 1) { + $r->print('

'.$links[0].'

'); } } - my @excluded = &get_excluded_elements($dom,$states,$action,$state); + my @excluded = &get_excluded_elements($dom,$states,$action,$state,$showcredits); if ($state eq 'personnel') { push(@excluded,'persontotal'); } @@ -1403,25 +1565,28 @@ sub print_request_form { $count ++; } $env{'form.persontotal'} = $count; - } } if ($state eq 'enrollment') { - push(@excluded,'crosslisttotal'); + push(@excluded,('sectotal','crosslisttotal')); + } + if (($state eq 'process') || ($state eq 'reqauthor')) { + $r->print('
'); + } else { + $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).''); + &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next, + $navtxt{'next'},$state); } - $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).''); - &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next, - $navtxt{'next'},$state); return; } -sub get_cancreate_status { - my ($persondom,$personname,$dom) = @_; +sub get_usertype { + my ($persondom,$personname,$curr_rules,$got_rules) = @_; my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($persondom,'username'); my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname, - $rules); - return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype); + $rules,$curr_rules,$got_rules); + return $usertype; } sub check_newuser_rules { @@ -1429,7 +1594,7 @@ sub check_newuser_rules { $got_rules) = @_; my $allowed = 1; my $newuser = 1; - my ($checkhash,$userchkmsg); + my ($checkhash,$userchkmsg,$authtype,$authparam); my $checks = { 'username' => 1 }; $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser }; &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch, @@ -1451,22 +1616,38 @@ sub check_newuser_rules { } } } - return ($allowed,$userchkmsg); + if ($allowed) { + if (ref($rulematch) eq 'HASH') { + if (ref($rulematch->{$personname.':'.$persondom}) eq 'HASH') { + my $matchedrule = $rulematch->{$personname.':'.$persondom}{'username'}; + my ($rules,$ruleorder) = + &Apache::lonnet::inst_userrules($persondom,'username'); + if (ref($rules) eq 'HASH') { + if (ref($rules->{$matchedrule}) eq 'HASH') { + $authtype = $rules->{$matchedrule}{'authtype'}; + $authparam = $rules->{$matchedrule}{'authparm'}; + } + } + } + } + } + return ($allowed,$userchkmsg,$authtype,$authparam); } sub get_excluded_elements { - my ($dom,$states,$action,$state) = @_; + my ($dom,$states,$action,$state,$showcredits) = @_; my @excluded = ('counter'); - my %elements = &form_elements($dom); + my ($elements,$instcredits) = &form_elements($dom,$showcredits); if (ref($states) eq 'HASH') { if (ref($states->{$action}) eq 'ARRAY') { my @items = @{$states->{$action}}; my $numitems = scalar(@items); if ($numitems) { for (my $i=$numitems-1; $i>=0; $i--) { - if (ref($elements{$action}) eq 'HASH') { - if (ref($elements{$action}{$items[$i]}) eq 'HASH') { - foreach my $key (keys(%{$elements{$action}{$items[$i]}})) { + if ((ref($elements) eq 'HASH') && + (ref($elements->{$action}) eq 'HASH')) { + if (ref($elements->{$action}{$items[$i]}) eq 'HASH') { + foreach my $key (keys(%{$elements->{$action}{$items[$i]}})) { push(@excluded,$key); } } @@ -1484,8 +1665,9 @@ sub get_excluded_elements { sub print_enrollment_menu { my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order, - $invalidcrosslist) =@_; - my ($sections,$autoenroll,$access_dates,$output,$hasauto); + $showcredits,$instcredits,$invalidcrosslist) =@_; + my ($sections,$autoenroll,$access_dates,$output,$hasauto,$hascredits, + $creditsrow,$domdefcredits); my $starttime = time; my $endtime = time+(6*30*24*60*60); # 6 months from now, approx @@ -1497,11 +1679,39 @@ sub print_enrollment_menu { 'start' => 'Start auto-enrollment', 'end' => 'End auto-enrollment', ); + if ($showcredits) { + unless ($env{'form.crstype'} eq 'community') { + my %domdefs = &Apache::lonnet::get_domain_defaults($dom); + $domdefcredits = $domdefs{$env{'form.crstype'}.'credits'}; + } + } if ($env{'form.crstype'} eq 'official') { if (&Apache::lonnet::auto_run('',$dom)) { $output = &show_invalid_crosslists($invalidcrosslist); my ($section_form,$crosslist_form); - $section_form = &inst_section_selector($dom,$instcode); + if ($instcode ne '') { + $section_form = &inst_section_selector($dom,$instcode); + if ($section_form eq '') { + my $sectotal = $env{'form.sectotal'}; + if (!$sectotal) { + $sectotal = 1; + } + if ($env{'form.addsection'}) { + $sectotal ++; + } + for (my $i=0; $i<$sectotal; $i++) { + $section_form .= §ions_form($dom,$instcode,$i); + } + if ($section_form) { + $section_form .= + &Apache::lonhtmlcommon::row_title(&mt('Add another')). + ''. + ''.&mt('Add?').&Apache::lonhtmlcommon::row_closure(); + } + } + } if ($section_form) { $sections = &Apache::lonhtmlcommon::row_headline(). '

'.&Apache::loncommon::help_open_topic('Course_Request_Sections'). @@ -1528,7 +1738,7 @@ sub print_enrollment_menu { ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}. "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(); $sections .= &Apache::lonhtmlcommon::row_headline. - '

'.&mt('Crosslisted courses for auto-enrollment').'

'. + '

'.&Apache::loncommon::help_open_topic('Course_Request_Crosslist').' '.&mt('Crosslisted courses for auto-enrollment').'

'. &Apache::lonhtmlcommon::row_closure(1). $crosslist_form; } @@ -1549,12 +1759,29 @@ sub print_enrollment_menu { &mt('No').''. &Apache::lonhtmlcommon::row_closure(1). &date_setting_table($starttime,$endtime,$formname,'enroll', - $hasauto,%enrolltitles); + $hasauto,undef,%enrolltitles); + if ($showcredits) { + if ($instcredits) { + $creditsrow = &mt('[quant,_1,credit]',$instcredits); + } else { + $creditsrow = ''. + ''; + } + $hascredits = 1; + } + } + } elsif ($env{'form.crstype'} eq 'unofficial') { + if ($showcredits) { + $creditsrow = ''. + ''; + $hascredits = 1; } } my $access_dates = &date_setting_table($starttime,$endtime,$formname,'access',$hasauto, - %accesstitles); + $hascredits,%accesstitles); $output .= &Apache::lonhtmlcommon::start_pick_box(); if ($sections) { $output .= $sections; @@ -1573,7 +1800,15 @@ sub print_enrollment_menu { $output .= &Apache::lonhtmlcommon::row_headline('Access'). '

'.$header.'

'. &Apache::lonhtmlcommon::row_closure(1). - $access_dates + $access_dates; + } + if ($creditsrow) { + $output .= &Apache::lonhtmlcommon::row_headline('Credits'). + '

'.&mt('Credits earned by students').'

'. + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_title(&mt('Default credits')). + $creditsrow. + &Apache::lonhtmlcommon::row_closure(1); } return '
'.&Apache::lonhtmlcommon::start_pick_box().$output. &Apache::lonhtmlcommon::end_pick_box().'
'; @@ -1638,7 +1873,7 @@ sub inst_section_selector { } sub date_setting_table { - my ($starttime,$endtime,$formname,$prefix,$hasauto,%datetitles) = @_; + my ($starttime,$endtime,$formname,$prefix,$hasauto,$hascredits,%datetitles)=@_; my ($perpetual,$table); my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start', $starttime,'','','',1,'','','',1); @@ -1649,7 +1884,9 @@ sub date_setting_table { $perpetual = ' '; - $closure = '1'; + unless ($hascredits) { + $closure = '1'; + } } my %help_item = ( @@ -1668,10 +1905,10 @@ sub date_setting_table { } $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}). - ' '.$datetitles{'start'}).$startform. + ' '.&mt($datetitles{'start'})).$startform. &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}). - ' '.$datetitles{'end'}).$endform.$perpetual. + ' '.&mt($datetitles{'end'})).$endform.$perpetual. &Apache::lonhtmlcommon::row_closure($closure); return $table; } @@ -1818,51 +2055,93 @@ sub current_lc_sections { return @currsecs; } -sub print_request_status { - my ($dom) = @_; +sub sorted_request_history { + my ($dom,$action,$curr_req) = @_; + my ($after,$before,$statusfilter,$crstypefilter); + if ($env{'form.status'} ne '') { + $statusfilter = $env{'form.status'}; + } + if ($env{'form.crstype'} ne '') { + $crstypefilter = $env{'form.crstype'}; + } + if (ref($curr_req) eq 'HASH') { + $after = $curr_req->{'requested_after_date'}, + $before = $curr_req->{'requested_before_date'}; + $statusfilter = $curr_req->{'status'}; + $crstypefilter = $curr_req->{'crstype'}; + } my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'}, $env{'user.name'},'^status:'.$dom); - my ($output,$formname,%queue_by_date); + my %queue_by_date; my ($types,$typenames) = &Apache::loncommon::course_types(); foreach my $key (keys(%statusinfo)) { - if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) { - (undef,my($cdom,$cnum)) = split(':',$key); - next if ($cdom ne $dom); - my $requestkey = $cdom.'_'.$cnum; - if ($requestkey =~ /^($match_domain)_($match_courseid)$/) { - my %history = &Apache::lonnet::restore($requestkey,'courserequests', - $env{'user.domain'},$env{'user.name'}); - my $entry; - my $timestamp = $history{'reqtime'}; - my $crstype = $history{'crstype'}; - my $disposition = $history{'disposition'}; + if ($action eq 'view') { + next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')); + } else { + next unless (($statusfilter eq 'any') || + ($statusfilter eq $statusinfo{$key})); + } + (undef,my($cdom,$cnum)) = split(':',$key); + next if ($cdom ne $dom); + my $requestkey = $cdom.'_'.$cnum; + if ($requestkey =~ /^($match_domain)_($match_courseid)$/) { + my %history = &Apache::lonnet::restore($requestkey,'courserequests', + $env{'user.domain'},$env{'user.name'}); + my $entry; + my $reqtime = $history{'reqtime'}; + my $lastupdate = $history{'timestamp'}; + my $crstype = $history{'crstype'}; + my $disposition = $history{'disposition'}; + my $status = $history{'status'}; + if ($action eq 'view') { next if ((exists($history{'status'})) && ($history{'status'} eq 'created')); - next unless (($env{'form.crstype'} eq 'any') || - ($env{'form.crstype'} eq $crstype)); + } else { + next if (($reqtime < $after) || ($reqtime > $before)); + } + next unless (($crstypefilter eq 'any') || + ($crstypefilter eq $crstype)); + if ($action eq 'view') { next unless (($disposition eq 'approval') || ($disposition eq 'pending')); - if (ref($history{'details'}) eq 'HASH') { - $entry = $requestkey.':'.$crstype.':'. - &escape($history{'details'}{'cdescr'}); - if ($crstype eq 'official') { - $entry .= ':'.&escape($history{'details'}{'instcode'}); + } + if (ref($history{'details'}) eq 'HASH') { + $entry = $requestkey.':'.$crstype.':'. + &escape($history{'details'}{'cdescr'}); + if ($action eq 'log') { + $entry .= ':'.$lastupdate.':'; + if ($statusinfo{$key} ne '') { + $entry .= $statusinfo{$key}; + } elsif ($status ne '') { + $entry .= $status; + } else { + $entry .= $disposition; } } - if ($entry ne '') { - if (exists($queue_by_date{$timestamp})) { - if (ref($queue_by_date{$timestamp}) eq 'ARRAY') { - push(@{$queue_by_date{$timestamp}},$entry); - } - } else { - @{$queue_by_date{$timestamp}} = ($entry); + if ($crstype eq 'official') { + $entry .= ':'.&escape($history{'details'}{'instcode'}); + } + } + if ($entry ne '') { + if (exists($queue_by_date{$reqtime})) { + if (ref($queue_by_date{$reqtime}) eq 'ARRAY') { + push(@{$queue_by_date{$reqtime}},$entry); } + } else { + @{$queue_by_date{$reqtime}} = ($entry); } } } } - $formname = 'requestcrs'; + return %queue_by_date; +} + +sub print_request_status { + my ($dom,$action) = @_; + my %queue_by_date = &sorted_request_history($dom,$action); my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date)); - $output = ''."\n". + my $formname = 'requestcrs'; + my ($types,$typenames) = &Apache::loncommon::course_types(); + my $output = ''."\n". ''."\n". ''."\n". @@ -2027,8 +2306,8 @@ ENDJS } sub viewcancel_javascript { - my $alert = &mt('Are you sure you want to cancel this request?\\n'. - 'Your request will be removed.'); + my $alert = &mt('Are you sure you want to cancel this request?').'\\n'. + &mt('Your request will be removed.'); return << "ENDJS"; function nextPage(formname,nextstate) { if (confirm('$alert')) { @@ -2042,13 +2321,294 @@ ENDJS } sub print_request_logs { - my ($jscript,$loaditems,$crumb) = @_; + my ($r,$dom,$jscript,$loaditems,$crumb) = @_; + my $title; + if ($env{'form.crstype'} eq 'community') { + $title = 'Community Request Logs'; + } elsif ($env{'form.crstype'} eq 'any') { + $title = 'Course/Community Request Logs'; + } else { + $title = 'Course Request Logs'; + } + $r->print(&header($title,$jscript,$loaditems).$crumb); + my $formname = 'requestcrs'; + $r->print('
'."\n". + ''."\n". + ''."\n"); + # set defaults + my $now = time(); + my $defstart = $now - (7*24*3600); #7 days ago + my %defaults = ( + page => '1', + show => '10', + crstype => 'any', + status => 'any', + requested_before_date => $now, + requested_after_date => $defstart, + ); + my ($types,$typenames) = &Apache::loncommon::course_types(); + my $more_records = 0; + my %curr; + foreach my $item ('show','page','crstype','status') { + $curr{$item} = $env{'form.'.$item}; + } + $curr{'requested_after_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_after_date'); + $curr{'requested_before_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_before_date'); + foreach my $key (keys(%defaults)) { + if ($curr{$key} eq '') { + $curr{$key} = $defaults{$key}; + } + } + my ($statuses,$statusnames) = &reqstatus_names($curr{'crstype'}); + $r->print(''. + &requestlog_display_filter($formname,\%curr)); + my %queue_by_date = &sorted_request_history($dom,$env{'form.action'},\%curr); + my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date)); + my $showntablehdr = 0; + my $tablehdr = &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ' '.&mt('Request Date').''. + ''.&mt('Description').''; + if ($curr{'crstype'} eq 'any') { + $tablehdr .= ''.&mt('Course Type').''; + } + if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) { + $tablehdr .= ''.&mt('Institutional Code').''; + } + if ($curr{'status'} eq 'any') { + $tablehdr .= ''.&mt('Status').''; + } elsif ($curr{'status'} eq 'created') { + $tablehdr .= ''.&mt('Creation Date').''; + } elsif ($curr{'status'} eq 'cancelled') { + $tablehdr .= ''.&mt('Cancellation Date').''; + } elsif ($curr{'status'} eq 'rejected') { + $tablehdr .= ''.&mt('Rejection Date').''; + } + $tablehdr .= &Apache::loncommon::end_data_table_header_row(); + my ($minshown,$maxshown); + $minshown = 1; + my $count = 0; + if ($curr{'show'} ne &mt('all')) { + $maxshown = $curr{'page'} * $curr{'show'}; + if ($curr{'page'} > 1) { + $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'}; + } + } + my $norecords; + if (@sortedtimes > 0) { + foreach my $item (@sortedtimes) { + if ($curr{'show'} ne &mt('all')) { + if ($count >= $curr{'page'} * $curr{'show'}) { + $more_records = 1; + last; + } + } + $count ++; + next if ($count < $minshown); + if (!$showntablehdr) { + $r->print($tablehdr); + $showntablehdr = 1; + } + my $showtime = &Apache::lonlocal::locallocaltime($item); + if (ref($queue_by_date{$item}) eq 'ARRAY') { + foreach my $request (sort(@{$queue_by_date{$item}})) { + my ($key,$crstype,$desc,$timestamp,$status,$instcode) = split(':',$request); + my ($cdom,$cnum) = split('_',$key); + my $output = &Apache::loncommon::start_data_table_row(). + ''.$count.''. + ''.$showtime.''. + ''.&unescape($desc).''; + if ($curr{'crstype'} eq 'any') { + my $typename; + if (ref($typenames) eq 'HASH') { + $typename = &mt($typenames->{$crstype}); + } + if ($typename eq '') { + $typename = &mt('Unknown type'); + } + $output .= ''.$typename.''; + } + if (($curr{'crstype'} eq 'any') || + ($curr{'crstype'} eq 'official')) { + my $showinstcode; + if ($crstype eq 'official') { + $showinstcode = &unescape($instcode); + } else { + $showinstcode = &mt('Not applicable'); + } + $output .= ''.$showinstcode.''; + } + if ($curr{'status'} eq 'any') { + my $statusname = &mt('Unknown status'); + if (ref($statusnames) eq 'HASH') { + if ($statusnames->{$status} ne '') { + $statusname = $statusnames->{$status}; + } + } + if (($status eq 'created') || ($status eq 'cancelled') || + ($status eq 'rejected')) { + $statusname .= ' '.&Apache::lonlocal::locallocaltime($timestamp); + } + $output .= ''.$statusname.''; + } elsif (($status eq 'created') || ($status eq 'cancelled') || + ($status eq 'rejected')) { + $output .= ''.&Apache::lonlocal::locallocaltime($timestamp).''; + } + $output .= &Apache::loncommon::end_data_table_row(); + $r->print($output); + } + } + } + if ($showntablehdr) { + $r->print(&Apache::loncommon::end_data_table()); + if (($curr{'page'} > 1) || ($more_records)) { + $r->print(''); + if ($curr{'page'} > 1) { + $r->print(''); + } + if ($more_records) { + $r->print(''); + } + $r->print('
'.&mt('Previous [_1] changes',$curr{'show'}).''.&mt('Next [_1] changes',$curr{'show'}).'
'); + $r->print(<<"ENDSCRIPT"); + +ENDSCRIPT + } + } else { + $norecords = 1; + } + } else { + $norecords = 1; + } + if ($norecords) { + $r->print('

'. + &mt('There are no records to display'). + '

'); + } + $r->print('
'. + &Apache::loncommon::end_page()); return; } +sub reqstatus_names { + my ($crstype) = @_; + my @statuses = qw(created approval pending rejected cancelled); + my %statusnames = + &Apache::lonlocal::texthash ( + created => 'Created', + approval => 'Queued pending approval', + pending => 'Queued pending validation', + rejected => 'Request rejected', + cancelled => 'Request cancelled', + ); + if (($crstype eq 'official') || ($crstype eq 'unofficial')) { + $statusnames{'created'} = &mt('Course created'); + } elsif ($crstype eq 'community') { + $statusnames{'created'} = &mt('Community created'); + } + return (\@statuses,\%statusnames); +} + +sub requestlog_display_filter { + my ($formname,$curr) = @_; + my $nolink = 1; + my $output = ''; + my $startform = + &Apache::lonhtmlcommon::date_setter($formname,'requested_after_date', + $curr->{'requested_after_date'},undef, + undef,undef,undef,undef,undef,undef,$nolink); + my $endform = + &Apache::lonhtmlcommon::date_setter($formname,'requested_before_date', + $curr->{'requested_before_date'},undef, + undef,undef,undef,undef,undef,undef,$nolink); + $output .= ''. + ''; + my ($types,$typenames) = &Apache::loncommon::course_types(); + if (ref($types) eq 'ARRAY') { + if (@{$types} > 1) { + $output .= ''; + } + } + my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'}); + if (ref($statuses) eq 'ARRAY') { + if (@{$statuses} > 1) { + $output .= ''; + } + } + $output .= '
'. + ''.&mt('Records/page:').'
'. + &Apache::lonmeta::selectbox('show',$curr->{'show'},undef, + (&mt('all'),5,10,20,50,100,1000,10000)). + '
  '.&mt('Window during which course/community was requested:').'
'. + ''. + ''. + '
'.&mt('After:'). + ''.$startform.'
'.&mt('Before:').''.$endform.'
'. + '
  '. + &mt('Course Type:').'
'. + &mt('Request Status:').'
'; + + # Update Display button + $output .= '

'. + ''. + '


'; + return $output; +} + sub print_review { my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom, - $disallowed,$disallowmsg) = @_; + $disallowed,$disallowmsg,$instcredits) = @_; my ($types,$typename) = &Apache::loncommon::course_types(); my ($owner,$ownername,$owneremail); if ($uname eq '' || $udom eq '') { @@ -2096,6 +2656,12 @@ sub print_review { } } } + $inst_headers .= ''.&mt('Credits').''; + if ($instcredits) { + $inst_values .= ''.$instcredits.''; + } else { + $inst_values .= ''.$env{'form.coursecredits'}.''; + } if (&Apache::lonnet::auto_run('',$dom)) { $enrollrow_title = &mt('Enrollment'); $enroll_headers = ''.&mt('Automatic Adds').''. @@ -2165,14 +2731,18 @@ sub print_review { $section_values .= $xlistinfo; } $section_values .= ''; + } elsif ($env{'form.crstype'} eq 'unofficial') { + $inst_headers .= ''.&mt('Credits').''; + $inst_values .= ''.$env{'form.coursecredits'}.''; } my %ctxt = &clone_text(); $inst_headers .= ''.&mt('Clone From').''; - if (($env{'form.clonecrs'} =~ /^$match_name$/) && + if (($env{'form.cloning'}) && + ($env{'form.clonecrs'} =~ /^$match_name$/) && ($env{'form.clonedom'} =~ /^$match_domain$/)) { - my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'}, - $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'}, + my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname, + $udom,$env{'form.clonecrs'},$env{'form.clonedom'}, $env{'form.crstype'}); if ($canclone) { my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'}, @@ -2351,6 +2921,24 @@ function validateForm() { } nextPage(document.$formname,'$next'); } + +function toggleCloning() { + var willclone; + if (document.$formname.cloning.length > 1) { + for (var i=0; i @@ -2361,7 +2949,7 @@ ENDJS $title = &mt('Brief Community Description'); $clonetitle = &mt('Clone content and settings from an existing community?'); } - my $output .= $js_validate."\n".'
'.&Apache::lonhtmlcommon::start_pick_box(). + my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box(). &Apache::lonhtmlcommon::row_headline(). '

'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'

'. &Apache::lonhtmlcommon::row_closure(1). @@ -2377,10 +2965,22 @@ ENDJS $output .= $home_server_pick. &Apache::lonhtmlcommon::row_closure(). &Apache::lonhtmlcommon::row_headline(). - '

'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.'

'. + '

'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle. + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_title(&mt('Clone?')). + ''. + '

'. &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_headline(). + ''."\n"; + &Apache::lonhtmlcommon::end_pick_box().'
'. + &Apache::lonhtmlcommon::end_pick_box()."\n"; return $output; } @@ -2390,15 +2990,16 @@ sub clone_form { if ($crstype eq 'community') { $type = 'Community'; } - my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').' '. - &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type); my %lt = &clone_text(); my $output .= - &Apache::lonhtmlcommon::row_title($lt{'cid'}).''.&Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::row_title($lt{'dmn'}).''.&Apache::lonhtmlcommon::row_closure(1). + &Apache::loncommon::select_dom_form($dom,'clonedom').''. + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_title($lt{'cid'}).' '. + &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type). + &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'