--- loncom/interface/lonrequestcourse.pm 2009/09/08 13:20:27 1.32
+++ loncom/interface/lonrequestcourse.pm 2009/10/24 03:56:01 1.36.2.3
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Request a course
#
-# $Id: lonrequestcourse.pm,v 1.32 2009/09/08 13:20:27 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.36.2.3 2009/10/24 03:56:01 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -52,10 +52,6 @@ described at http://www.lon-capa.org.
=item onload_action()
-=item check_can_request()
-
-=item course_types()
-
=item print_main_menu()
=item request_administration()
@@ -178,7 +174,7 @@ sub handler {
$trail{'enrollment'} = 'Enrollment';
}
- my ($page,$crumb,$newinstcode,$codechk,$checkedcode) =
+ 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))) {
@@ -238,8 +234,8 @@ sub handler {
foreach my $item (@code_order) {
$crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item};
}
- if ($crosslistcode ne '') {
- $codechk{$i} =
+ if ($crosslistcode ne '') {
+ ($codechk{$i}, my $rest) =
&Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
}
unless ($codechk{$i} eq 'valid') {
@@ -277,7 +273,7 @@ sub handler {
my $loaditems = &onload_action($action,$state);
my %can_request;
- my $canreq = &check_can_request($dom,\%can_request);
+ my $canreq = &Apache::lonnet::check_can_request($dom,\%can_request);
if ($action eq 'new') {
if ($canreq) {
if ($state eq 'crstype') {
@@ -286,7 +282,8 @@ sub handler {
} else {
&request_administration($r,$action,$state,$page,\%states,$dom,
$jscript,$loaditems,$crumb,$newinstcode,
- $codechk,$checkedcode,\@invalidcrosslist);
+ $codechk,$checkedcode,$description,
+ \@invalidcrosslist);
}
} else {
$r->print(&header('Course Requests').$crumb.
@@ -310,7 +307,7 @@ sub handler {
&close_popup_form());
} else {
&request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
- $loaditems,$crumb,'','','','',$uname,$udom);
+ $loaditems,$crumb,'','','','','',$uname,$udom);
}
} elsif ($action eq 'log') {
&print_request_logs($jscript,$loaditems,$crumb);
@@ -346,7 +343,7 @@ END
sub get_breadcrumbs {
my ($dom,$action,$state,$states,$trail) = @_;
- my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles);
+ my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description);
my $page = 0;
if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) {
if (defined($action)) {
@@ -371,7 +368,7 @@ sub get_breadcrumbs {
$$state = 'codepick';
$page --;
} else {
- $codechk =
+ ($codechk,$description) =
&Apache::lonnet::auto_validate_instcode('',
$dom,$newinstcode);
if ($codechk ne 'valid') {
@@ -416,7 +413,7 @@ sub get_breadcrumbs {
{text=>'Pick Action'});
$crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
}
- return ($page,$crumb,$newinstcode,$codechk,$checkedcode);
+ return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
}
sub header {
@@ -593,52 +590,9 @@ sub onload_action {
return \%loaditems;
}
-sub check_can_request {
- my ($dom,$can_request) = @_;
- my $canreq = 0;
- my ($types,$typename) = &course_types();
- my @options = ('approval','validate','autolimit');
- my $optregex = join('|',@options);
- if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) {
- foreach my $type (@{$types}) {
- if (&Apache::lonnet::usertools_access($env{'user.name'},
- $env{'user.domain'},
- $type,undef,'requestcourses')) {
- $canreq ++;
- if ($dom eq $env{'user.domain'}) {
- $can_request->{$type} = 1;
- }
- }
- if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
- my @curr = split(',',$env{'environment.reqcrsotherdom.'.$type});
- if (@curr > 0) {
- $canreq ++;
- unless ($dom eq $env{'user.domain'}) {
- if (grep(/^\Q$dom\E:($optregex)(=?\d*)$/,@curr)) {
- $can_request->{$type} = 1;
- }
- }
- }
- }
- }
- }
- return $canreq;
-}
-
-sub course_types {
- my @types = ('official','unofficial','community');
- my %typename = (
- official => 'Official course',
- unofficial => 'Unofficial course',
- community => 'Community',
- );
- return (\@types,\%typename);
-}
-
-
sub print_main_menu {
my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_;
- my ($types,$typename) = &course_types();
+ my ($types,$typename) = &Apache::loncommon::course_types();
my $onchange;
unless ($env{'form.interface'} eq 'textual') {
$onchange = 1;
@@ -657,8 +611,31 @@ sub print_main_menu {
}
}
+ my $standby=&mt('Course selected. Please stand by.');
my $js = <<"END";
+function enterrole (thisform,rolecode,buttonname) {
+ document.title='$standby';
+ window.status='$standby';
+ thisform.newrole.value=rolecode;
+ thisform.selectrole.value='1';
+ thisform.submit();
+}
+
+function ToSyllabus(cdom,cnum) {
+ if (cdom == '' || cdom == null) {
+ return;
+ }
+ if (cnum == '' || cnum == null) {
+ return;
+ }
+ var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
+ var url = "/public/"+cdom+"/"+cnum+"/syllabus";
+ syllwin = window.open(url,'',options,1);
+ syllwin.focus();
+ return;
+}
+
function nextPage(formname) {
var crschoice = document.mainmenu_coursetype.crstype.value;
var actionchoice = document.mainmenu_action.action.value;
@@ -723,16 +700,20 @@ END
}
END
-
- $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.'
'.
+ $r->print(&header('Concept Test Courses',$js.$jscript,$loaditems).$crumb);
+ my $existing = &existing_courses();
+ if ($existing) {
+ $r->print('
'.
+ '
'.&mt('Request creation of a new course').'
');
+ } else {
+ $r->print('
'.&mt('Request creation of a new course, or review your pending course requests.').'
');
+ }
+ $r->print('
'.
&Apache::lonhtmlcommon::start_pick_box().
&Apache::lonhtmlcommon::row_title(&mt('Course Domain')).
- '
'.&Apache::lonhtmlcommon::row_closure());
my $formname = 'requestcrs';
@@ -742,41 +723,217 @@ END
'.
&Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::row_title(&mt('Course Type')).'
-
'."\n".
+ &Apache::lonhtmlcommon::row_title(&mt('Course Type')).
+ &mt($typename->{'unofficial'})."\n".
+ '
'."\n".
&Apache::lonhtmlcommon::row_closure(1)."\n".
- &Apache::lonhtmlcommon::end_pick_box().'
'."\n".
- '
');
+ '');
+ if ($existing) {
+ $r->print('
'.&mt('Enter an existing Concept Test course').'
'.$existing.'');
+ } else {
+ $r->print('
');
+ }
$r->print(&Apache::loncommon::end_page());
return;
}
+sub existing_courses {
+ my $output;
+ my %roleshash = &Apache::lonnet::get_my_roles(undef,undef,'userroles',undef,
+ ['cc'],['gcitest']);
+ my %courses;
+ if (keys(%roleshash) > 0) {
+ foreach my $key (keys(%roleshash)) {
+ my ($cnum,$cdom,$role) = split(':',$key);
+ my ($tstart,$tend) = split(':',$roleshash{$key});
+ my %coursehash = &Apache::lonnet::coursedescription($cdom.'/'.$cnum);
+ $courses{$cdom.'_'.$cnum}{'description'} = $coursehash{'description'};
+ $courses{$cdom.'_'.$cnum}{'owner'} = $coursehash{'internal.courseowner'};
+ if (defined($coursehash{'default_enrollment_start_date'}) ) {
+ $courses{$cdom.'_'.$cnum}{'startaccess'} =
+ &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
+ }
+ if (defined($coursehash{'default_enrollment_end_date'}) ) {
+ $courses{$cdom.'_'.$cnum}{'endaccess'} =
+ &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
+ if ($coursehash{'default_enrollment_end_date'} == 0) {
+ $courses{$cdom.'_'.$cnum}{'endaccess'} = &mt('No ending date');
+ }
+ }
+ }
+ $output = '';
+ }
+ return $output;
+}
+
+sub build_courseinfo_hash {
+ my ($courses) = @_;
+ my %courseinfo;
+ foreach my $course (keys(%{$courses})) {
+ my ($cdom,$cnum) = split('_',$course);
+ my $descr;
+ if (ref($courses->{$course}) eq 'HASH') {
+ $descr = $courses->{$course}{'description'};
+ }
+ my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
+ $cleandesc=~s/'/\\'/g;
+ $cleandesc =~ s/^\s+//;
+ my ($cdom,$cnum)=split(/\_/,$course);
+ my ($singleowner,@owners,%ownernames);
+ if (ref($courses->{$course}) eq 'HASH') {
+ $singleowner = $courses->{$course}{'owner'};
+ push(@owners,$singleowner);
+ if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') {
+ foreach my $item (@{$courses->{$course}{'co-owners'}}) {
+ push(@owners,$item);
+ }
+ }
+ }
+ foreach my $owner (@owners) {
+ my ($ownername,$ownerdom);
+ if ($owner =~ /:/) {
+ ($ownername,$ownerdom) = split(/:/,$owner);
+ } else {
+ $ownername = $owner;
+ if ($owner ne '') {
+ $ownerdom = $cdom;
+ }
+ }
+ if ($ownername ne '' && $ownerdom ne '') {
+ my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
+ $ownernames{$ownername.':'.$ownerdom} = \%namehash;
+ }
+ }
+ $courseinfo{$course}{'cdom'} = $cdom;
+ $courseinfo{$course}{'cnum'} = $cnum;
+ my @lastnames;
+ foreach my $owner (keys(%ownernames)) {
+ if (ref($ownernames{$owner}) eq 'HASH') {
+ push(@lastnames,$ownernames{$owner}{'lastname'});
+ }
+ }
+ $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames));
+ $courseinfo{$course}{'title'} = $cleandesc;
+ $courseinfo{$course}{'owner'} = $singleowner;
+ my @classids;
+ $courseinfo{$course}{'counts'} = &count_students($cdom,$cnum,0);
+ my $startaccess = $courses->{$course}{'startaccess'};
+ my $endaccess = $courses->{$course}{'endaccess'};
+ my $accessdates;
+ if ($startaccess) {
+ $accessdates .= ''.&mt('From:[_1]',' '.$startaccess).'
';
+ }
+ if ($endaccess) {
+ $accessdates .= ''.&mt('To:[_1]',' '.$endaccess).'
';
+ }
+ $courseinfo{$course}{'access'} = $accessdates;
+ }
+ return %courseinfo;
+}
+
+sub courseinfo_row {
+ my ($info,$cnum,$cdom) = @_;
+ my $output;
+ if (ref($info) eq 'HASH') {
+ my $rolecode = 'cc./'.$cdom.'/'.$cnum;
+ my $buttonname = $rolecode;
+ $buttonname=~s/\W//g;
+ $output .= ' | '.
+ ''.$info->{'title'}.' '.
+ ''.
+ &mt('Syllabus').' | '.
+ ''.$info->{'ownerlastnames'}.' | '.
+ ''.$info->{'access'}.' | '.
+ ''.$info->{'counts'}.' | ';
+ } else {
+ $output = ''.&mt('No information available for [_1].',
+ $cdom.'_'.$cnum).' | ';
+ return $output;
+ }
+ return $output;
+}
+
+sub count_students {
+ my ($cdom,$cnum,$numsec) = @_;
+ my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
+ my %student_count = (
+ Active => 0,
+ Future => 0,
+ Expired => 0,
+ );
+ my %idx;
+ $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
+ my %status_title = &Apache::lonlocal::texthash(
+ Expired => 'Previous access',
+ Active => 'Current access',
+ Future => 'Future access',
+ );
+
+ while (my ($student,$data) = each(%$classlist)) {
+ $student_count{$data->[$idx{'status'}]} ++;
+ }
+
+ my $countslist = &mt('[quant,_1,section:,sections:,No sections]',$numsec).'
';
+ foreach my $status ('Active','Future') {
+ $countslist .= ''.$status_title{$status}.': '.
+ $student_count{$status}.'
';
+ }
+ return $countslist;
+}
+
+
sub request_administration {
my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
- $newinstcode,$codechk,$checkedcode,$invalidcrosslist,$uname,$udom) = @_;
+ $newinstcode,$codechk,$checkedcode,$description,$invalidcrosslist,
+ $uname,$udom) = @_;
my $js;
if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
$js = <print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb);
&print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
- $codechk,$checkedcode,$invalidcrosslist);
+ $codechk,$checkedcode,$description,$invalidcrosslist);
} elsif ($action eq 'view') {
my $jsextra;
my $formname = 'requestcrs';
@@ -1124,7 +1281,7 @@ sub get_instcode {
sub print_request_form {
my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
- $invalidcrosslist) = @_;
+ $description,$invalidcrosslist) = @_;
my $formname = 'requestcrs';
my ($next,$prev,$message,$output,$codepicker,$crstype);
$prev = $states->{$action}[$page-1];
@@ -1134,7 +1291,7 @@ sub print_request_form {
next => 'Next',
);
$crstype = $env{'form.crstype'};
- $r->print('