--- loncom/interface/lonpickcourse.pm 2006/11/09 22:18:28 1.55
+++ loncom/interface/lonpickcourse.pm 2007/10/06 04:32:49 1.65
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.55 2006/11/09 22:18:28 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.65 2007/10/06 04:32:49 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,7 +35,6 @@ use Apache::loncoursedata;
use Apache::lonnet;
use Apache::lonlocal;
use Apache::longroup;
-use lib '/home/httpd/lib/perl/';
use LONCAPA;
sub handler {
@@ -55,7 +54,7 @@ sub handler {
my ($type,$title,$jscript,$multelement,$multiple,$roleelement,
$lastaction,$autosubmit,$submitopener);
- # Get course type - Course or Non-standard course.
+ # Get course type - Course or Non-standard Course.
$type = $env{'form.type'};
if (!defined($env{'form.type'})) {
$type = 'Course';
@@ -79,7 +78,7 @@ sub handler {
my $onlyown = 0;
# if called to assign course-based portfolio access control
- if ((($env{'form.form'} eq 'portform') && ($env{'user.adv'}))) {
+ if ((($env{'form.form'} eq 'portform') && (!$env{'user.adv'}))) {
$onlyown = 1;
}
@@ -108,13 +107,14 @@ sub handler {
# print javascript functions for choosing a course
if ($env{'form.gosearch'} || $onlyown) {
- $r->print(&gochoose_javascript($type,$autosubmit,$lastaction));
+ $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
}
$r->print('');
$r->print($submitopener);
# ------------------------------------------ Display of filters to limit search
- my (%filter,%list);
+ my $filter = {};
+ my $action = '/adm/pickcourse';
if (!$onlyown) {
my $filterlist = ['domainfilter','descriptfilter',
'instcodefilter','ownerfilter',
@@ -125,13 +125,13 @@ sub handler {
push(@{$filterlist},'coursefilter');
}
$r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
- \%filter,\%list));
+ $filter,$action));
}
# ---------------------------------------------------------------- Get the data
if ($env{'form.gosearch'} || $onlyown) {
- my %courses = &search_courses($r,$type,$onlyown,\%filter);
- &display_matched_courses($r,$type,$multiple,%courses);
+ my %courses = &search_courses($r,$type,$onlyown,$filter);
+ &display_matched_courses($r,$type,$multiple,$action,%courses);
}
$r->print(&Apache::loncommon::end_page());
return OK;
@@ -166,8 +166,7 @@ function setSections() {
}
sub display_matched_courses {
- my ($r,$type,$multiple,%courses) = @_;
- my $action = '/adm/pickcourse';
+ my ($r,$type,$multiple,$action,%courses) = @_;
if ($env{'form.form'} eq 'portform') {
$action = '/adm/portfolio';
}
@@ -176,7 +175,9 @@ sub display_matched_courses {
my $numcourses = keys(%courses);
foreach my $course (keys(%courses)) {
my $descr;
- if ($courses{$course} =~ m/^([^:]*):/i) {
+ if (ref($courses{$course}) eq 'HASH') {
+ $descr = $courses{$course}{'description'};
+ } elsif ($courses{$course} =~ m/^([^:]*):/i) {
$descr = &unescape($1);
} else {
$descr = &unescape($courses{$course});
@@ -196,18 +197,36 @@ sub display_matched_courses {
my $cleandesc=&HTML::Entities::encode($description,'<>&"');
$cleandesc=~s/'/\\'/g;
my ($cdom,$cnum)=split(/\_/,$course);
- my ($descr,$instcode,$owner,$ttype) = split/:/,$courses{$course};
+ my ($descr,$instcode,$ttype,@owners);
+ if (ref($courses{$course}) eq 'HASH') {
+ $descr = $courses{$course}{'description'};
+ $instcode = $courses{$course}{'inst_code'};
+ $ttype = $courses{$course}{'type'};
+ push(@owners,&unescape($courses{$course}{'owner'}));
+ if (ref($courses{$course}{'co-owners'}) eq 'ARRAY') {
+ foreach my $item (@{$courses{$course}{'co-owners'}}) {
+ push(@owners,&unescape($item));
+ }
+ }
+ } else {
+ my $singleowner;
+ ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course});
+ push(@owners,&unescape($singleowner));
+ }
+ my $owner = join(', ',@owners);
$r->print(&course_chooser($multiple,$cdom,$cnum,$cleandesc));
$r->print($description.'('.
- ($Apache::lonnet::domaindescription{$cdom}?
- $Apache::lonnet::domaindescription{$cdom}:$cdom).")");
- unless ($instcode eq '') {
+ (&Apache::lonnet::domain($cdom,'description')?
+ &Apache::lonnet::domain($cdom,'description'):$cdom).")");
+ if ($instcode ne '') {
$r->print(" - ".&unescape($instcode));
}
- unless ($owner eq '') {
- $r->print(", owner - ".&unescape($owner));
+ if (@owners > 1) {
+ $r->print(', '.&mt('owners').' - ',join(', ',@owners));
+ } elsif (@owners == 1) {
+ $r->print(', '.&mt('owner').' - '.$owner);
}
- unless ($ttype eq '') {
+ if ($ttype ne '') {
$r->print('('.&unescape($ttype).')');
}
if ($multiple) { $r->print("\n"); }
@@ -217,12 +236,10 @@ sub display_matched_courses {
if (!%courses) {
$r->print(&mt('None found'));
} elsif ($multiple) {
- $r->print('');
+ $r->print('');
}
$r->print(''.
"\n".''."\n".
- ''."\n".
- ''."\n".
''."\n");
if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
$r->print('');
$r->print('');
$r->print('');
+ } elsif ($env{'form.form'} eq 'modifycourse') {
+ $r->print(''."\n");
+ $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form']));
+ } else {
+ $r->print(''."\n".
+ ''."\n");
}
$r->print("\n");
return;
@@ -246,21 +271,43 @@ sub multiples_tag {
}
sub build_filters {
- my ($filterlist,$type,$roleelement,$multelement,$filter) = @_;
+ my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
+ $caller) = @_;
my $list;
+ my $formname;
+ if (defined($env{'form.form'})) {
+ $formname = $env{'form.form'};
+ } else {
+ $formname = $caller;
+ }
my ($domainselectform,$sincefilterform,$ownerdomselectform,
$instcodeform,$typeselectform);
foreach my $item (@{$filterlist}) {
$filter->{$item} = $env{'form.'.$item};
if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
- $filter->{$item} =~ s/\W//g;
+ if ($item eq 'domainfilter' || $item eq 'ownerdomfilter') {
+ $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
+ } elsif ($item eq 'coursefilter') {
+ $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
+ } elsif ($item eq 'ownerfilter') {
+ $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
+ } else {
+ $filter->{$item} =~ s/\W//g;
+ }
if (!$filter->{$item}) {
$filter->{$item} = '';
}
}
if ($item eq 'domainfilter') {
+ my $allow_blank = 1;
+ if ($formname eq 'portform') {
+ $filter->{$item} ||= $env{'user.domain'};
+ $allow_blank=0;
+ }
$domainselectform =
- &Apache::loncommon::select_dom_form($filter->{$item},'domainfilter',1);
+ &Apache::loncommon::select_dom_form($filter->{$item},
+ 'domainfilter',
+ $allow_blank);
} elsif ($item eq 'ownerdomfilter') {
$ownerdomselectform =
&Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1);
@@ -295,54 +342,73 @@ sub build_filters {
'cog' => &mt('Course Type')
);
- $typeselectform = '";
- my $name_input;
- if ($env{'form.cnameelement'} ne '') {
- $name_input ='';
- }
- my $courseidtag;
- if (exists($filter->{'coursefilter'})) {
- $courseidtag=&mt('LON-CAPA course ID').
- '
';
- }
- my $output = <<"END";
-