[LON-CAPA-cvs] cvs: loncom(GCI_2) /interface lonrequestcourse.pm
raeburn
raeburn@source.lon-capa.org
Fri, 02 Oct 2009 16:15:49 -0000
This is a MIME encoded message
--raeburn1254500149
Content-Type: text/plain
raeburn Fri Oct 2 16:15:49 2009 EDT
Modified files: (Branch: GCI_2)
/loncom/interface lonrequestcourse.pm
Log:
- Customization for GCI.
- Initial Course Request page includes list of any existing Concept Test courses in gcitest domain in which user has active CC role with "Select" button to choose a role.
--raeburn1254500149
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20091002161549.txt"
Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.36.2.1 loncom/interface/lonrequestcourse.pm:1.36.2.2
--- loncom/interface/lonrequestcourse.pm:1.36.2.1 Wed Sep 23 15:58:26 2009
+++ loncom/interface/lonrequestcourse.pm Fri Oct 2 16:15:49 2009
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Request a course
#
-# $Id: lonrequestcourse.pm,v 1.36.2.1 2009/09/23 15:58:26 gci Exp $
+# $Id: lonrequestcourse.pm,v 1.36.2.2 2009/10/02 16:15:49 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -658,8 +658,31 @@
}
}
+ 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;
@@ -724,10 +747,15 @@
}
END
-
- $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.
- '<p>'.&mt('Request creation of a new course, or review your pending course requests.').'</p>'.
- '<div>'.
+ $r->print(&header('Concept Test Courses',$js.$jscript,$loaditems).$crumb);
+ my $existing = &existing_courses();
+ if ($existing) {
+ $r->print('<div class="LC_left_float">'.
+ '<h3>'.&mt('Request creation of a new course').'</h3>');
+ } else {
+ $r->print('<div><h3>'.&mt('Request creation of a new course, or review your pending course requests.').'</h3>');
+ }
+ $r->print('<p>'.
&Apache::lonhtmlcommon::start_pick_box().
&Apache::lonhtmlcommon::row_title(&mt('Course Domain')).
'<form name="domforcourse" method="post" action="/adm/requestcourse">');
@@ -749,19 +777,206 @@
'<form name="mainmenu_coursetype" method="post" action="">'."\n".
'<input type="hidden" name="crstype" value="unofficial" ></form>'."\n".
&Apache::lonhtmlcommon::row_closure(1)."\n".
- &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
- '<div><form name="'.$formname.'" method="post" action="">'."\n".
+ &Apache::lonhtmlcommon::end_pick_box().'</p>'."\n".
+ '<p><form name="'.$formname.'" method="post" action="">'."\n".
'<input type="hidden" name="state" value="crstype" />'."\n".
'<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
'<input type="hidden" name="crstype" value="" />'."\n".
'<input type="hidden" name="action" value="" />'."\n".
'<input type="button" name="next" value="'.$nexttext.
'" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
- '</form></div>');
+ '</form></p>');
+ if ($existing) {
+ $r->print('</div><div class="LC_left_float"><h3>'.&mt('Enter an existing Concept Test course').'</h3>'.$existing.'</div><div class="LC_clear_float_footer"></div>');
+ } else {
+ $r->print('</div>');
+ }
$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 = '<form name="pickrole" action="/adm/roles" method="post">'.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row();
+ my @coltitles = ('Select','Title','Owner(s)',
+ 'Default Access Dates for Students','Student Counts');
+ foreach my $item (@coltitles) {
+ $output .= '<th>';
+ if ($item eq 'Select') {
+ $output .= ' ';
+ } else {
+ $output .= &mt($item);
+ }
+ $output .= '</th>';
+ }
+ $output .= &Apache::loncommon::end_data_table_header_row();
+ my %courseinfo = &build_courseinfo_hash(\%courses);
+ my %Sortby;
+ foreach my $course (sort(keys(%courses))) {
+ my $clean_title = $courseinfo{$course}{'title'};
+ $clean_title =~ s/\W+//g;
+ if ($clean_title eq '') {
+ $clean_title = $courseinfo{$course}{'title'};
+ }
+ push(@{$Sortby{$clean_title}},$course);
+ }
+ my @sorted_courses;
+ my @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
+ foreach my $item (@sorted_courses) {
+ foreach my $course (@{$Sortby{$item}}) {
+ my ($cdom,$cnum) = split('_',$course);
+ $output.= &Apache::loncommon::start_data_table_row().
+ &courseinfo_row($courseinfo{$course},$cnum,$cdom).
+ &Apache::loncommon::end_data_table_row();
+ }
+ }
+ $output .= &Apache::loncommon::end_data_table().
+ '<input type="hidden" name="newrole" value="" />'.
+ '<input type="hidden" name="selectrole" value="" /></form>';
+ }
+ 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 .= '<i>'.&mt('From:[_1]','</i> '.$startaccess).'<br />';
+ }
+ if ($endaccess) {
+ $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$endaccess).'<br />';
+ }
+ $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 .= '<td><input type="button" name="'.$buttonname.'" value="'.&mt('Select').'" onclick="javascript:enterrole(this.form,'."'$rolecode','$buttonname'".')" ></td>'.
+ '<td>'.$info->{'title'}.' <font size="-2">'.
+ '<a href="javascript:ToSyllabus('."'$cdom','$cnum'".')">'.
+ &mt('Syllabus').'</a></font></td>'.
+ '<td>'.$info->{'ownerlastnames'}.'</td>'.
+ '<td>'.$info->{'access'}.'</td>'.
+ '<td>'.$info->{'counts'}.'</td>';
+ } else {
+ $output = '<td colspan="4">'.&mt('No information available for [_1].',
+ $cdom.'_'.$cnum).'</td>';
+ 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).'<br />';
+ foreach my $status ('Active','Future') {
+ $countslist .= '<span class="LC_nobreak">'.$status_title{$status}.': '.
+ $student_count{$status}.'</span><br />';
+ }
+ return $countslist;
+}
+
+
sub request_administration {
my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
$newinstcode,$codechk,$checkedcode,$description,$invalidcrosslist,
--raeburn1254500149--