--- loncom/interface/lonpickcourse.pm 2007/12/30 23:22:41 1.68
+++ loncom/interface/lonpickcourse.pm 2011/09/01 02:32:50 1.103
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.68 2007/12/30 23:22:41 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.103 2011/09/01 02:32:50 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,7 +35,8 @@ use Apache::loncoursedata;
use Apache::lonnet;
use Apache::lonlocal;
use Apache::longroup;
-use LONCAPA;
+use Apache::courseclassifier;
+use LONCAPA qw(:DEFAULT :match);
sub handler {
my $r = shift;
@@ -49,23 +50,22 @@ sub handler {
&Apache::loncommon::get_unprocessed_cgi
($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
'cdomelement','cnameelement','roleelement',
- 'multiple','type','setroles']);
+ 'multiple','type','setroles','fixeddom','cloner']);
+ my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement,
+ $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom);
- my ($type,$title,$jscript,$multelement,$multiple,$roleelement,
- $lastaction,$autosubmit,$submitopener);
-
- # Get course type - Course or Non-standard Course.
+ # Get course type - Course or Community.
$type = $env{'form.type'};
if (!defined($env{'form.type'})) {
$type = 'Course';
}
- $title = &mt('Selecting a [_1]',$type);
+ $title = 'Selecting a '.$type;
# Setup for multiple course selections, if flag for multiples set.
$multiple = $env{'form.multiple'};
if ($multiple) {
($jscript,$multelement) = &multiples_tag();
- $title = &mt('Selecting [_1](s)',lc($type));
+ $title = 'Selecting '.$type.'(s)';
}
# if called when a DC is selecting a course
@@ -75,6 +75,20 @@ sub handler {
$submitopener = &processpick();
$autosubmit = 'process_pick("'.$roledom.'")';
}
+ if ($env{'form.typeelement'} ne '') {
+ $typeelement = '';
+ }
+
+ # if called when a DC is creating a course for another user.
+ if ($env{'form.form'} eq 'ccrs') {
+ ($cloneruname,$clonerudom) = ($env{'form.cloner'} =~ /^($match_username):($match_domain)$/);
+ }
+
+ # if called when requesting a course
+ if ($env{'form.form'} eq 'requestcrs') {
+ $cloneruname = $env{'user.name'};
+ $clonerudom = $env{'user.domain'};
+ }
my $onlyown = 0;
# if called to assign course-based portfolio access control
@@ -83,11 +97,18 @@ sub handler {
}
my %loaditem;
+ if (($env{'form.type'} eq 'Course') && ($env{'form.numtitles'})) {
+ if (($env{'form.official'} eq 'on') && ($env{'form.state'} eq 'listing')) {
+ $loaditem{'onload'} = 'setElements(document.filterpicker); ';
+ }
+ }
+
if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) &&
($env{'form.pickedcourse'})) {
- $loaditem{'onload'} ="setSections()";
+ $loaditem{'onload'} .= 'setRoles();setSections();';
}
- $r->print(&Apache::loncommon::start_page($title,undef,
+ my $js = &js_changer();
+ $r->print(&Apache::loncommon::start_page($title,$js,
{'add_entries' => \%loaditem,
'no_nav_bar' => 1, }));
@@ -108,37 +129,100 @@ sub handler {
}
# print javascript functions for choosing a course
- if ($env{'form.gosearch'} || $onlyown) {
+ if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
+ $onlyown) {
$r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
}
- $r->print('');
+ $r->print('');
$r->print($submitopener);
# ------------------------------------------ Display of filters to limit search
my $filter = {};
my $action = '/adm/pickcourse';
+ my ($numtitles,$showroles,$nohost,@codetitles);
if (!$onlyown) {
- my $filterlist = ['domainfilter','descriptfilter',
- 'instcodefilter','ownerfilter',
- 'ownerdomfilter'];
+ my $filterlist = ['domainfilter'];
+ # created filter for DCs only
+ if ($env{'user.adv'} && $env{'form.domainfilter'} &&
+ exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})
+ && $env{'form.form'} ne 'portform') {
+ my $loncaparev = &Apache::lonnet::get_server_loncaparev($env{'form.domainfilter'});
+ if ($loncaparev ne 'unknown_cmd') {
+ push(@{$filterlist},'createdfilter');
+ }
+ }
+ push(@{$filterlist},('descriptfilter','instcodefilter'));
+ if ($env{'form.form'} eq 'rules') {
+ push(@{$filterlist},'personfilter');
+ if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {
+ if (&Apache::lonnet::homeserver($env{'form.personfilter'},
+ $env{'form.persondomfilter'}) eq 'no_host') {
+ $nohost = 1;
+ } else {
+ $showroles = 1;
+ }
+ }
+ } else {
+ push(@{$filterlist},'ownerfilter');
+ }
# course ID filter for DCs only
if ($env{'user.adv'} && $env{'form.domainfilter'} &&
exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
push(@{$filterlist},'coursefilter');
}
+ if ($cloneruname ne '' && $clonerudom ne '') {
+ push(@{$filterlist},'cloneableonly');
+ }
+
$r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
- $filter,$action));
+ $filter,$action,\$numtitles,undef,$cloneruname,
+ $clonerudom,$typeelement,\@codetitles));
}
# ---------------------------------------------------------------- Get the data
- if ($env{'form.gosearch'} || $onlyown) {
- my %courses = &search_courses($r,$type,$onlyown,$filter);
- &display_matched_courses($r,$type,$multiple,$action,%courses);
+ if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
+ $onlyown) {
+ my $domcloner;
+ if ($env{'form.form'} eq 'ccrs') {
+ if (($env{'request.role.domain'} eq $env{'form.domainfilter'}) &&
+ (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
+ $domcloner = 1;
+ }
+ }
+ my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles,
+ $cloneruname,$clonerudom,$domcloner,\@codetitles);
+ if ($nohost) {
+ $r->print (''.
+ &mt('User does not exist - username: [_1], domain: [_2].',
+ ''.$filter->{'personfilter'}.'',
+ ''.$filter->{'persondomfilter'}.'').'');
+ } else {
+ &display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,
+ $clonerudom,%courses);
+ }
}
$r->print(&Apache::loncommon::end_page());
return OK;
}
+sub js_changer {
+ return <<"ENDJS";
+
+
+ENDJS
+
+}
+
sub processpick {
my $openerform = 'rolechoice';
if ($env{'form.form'} eq 'studentform') {
@@ -155,7 +239,12 @@ ENDONE
$process_pick .= <<"ENDTWO";
if (pickedDomain == dom) {
if (pickedCourse != '') {
- var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
+ var ccrole = "cc";
+ var pickedType = "$env{'form.type'}";
+ if (pickedType == "Community") {
+ ccrole = "co";
+ }
+ var courseTarget = ccrole+"./"+pickedDomain+"/"+pickedCourse
opener.document.title='Role selected. Please stand by.';
opener.status='Role selected. Please stand by.';
opener.document.rolechoice.newrole.value=courseTarget
@@ -187,7 +276,12 @@ sub create_user_javascript {
my $output;
#javascript for reporting sections and groups then closing
if ($env{'form.pickedcourse'}) {
- my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
+ my %coursedescription =
+ &Apache::lonnet::coursedescription($env{'form.pickedcourse'},
+ {'one_time' => '1'});
+ my $cdom = $coursedescription{'domain'};
+ my $cnum = $coursedescription{'num'};
+ my $crstype = $coursedescription{'type'};
my $sec_element = 'currsec';
my $grplist_element = 'groups';
my ($sections,$groups) =
@@ -201,7 +295,10 @@ sub create_user_javascript {
function setSections() {
opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
window.opener.setSect('$seclist');
- self.close()
+ self.close();
+}
+function setRoles() {
+ window.opener.setRole('$crstype');
}
|;
@@ -211,7 +308,7 @@ function setSections() {
}
sub display_matched_courses {
- my ($r,$type,$multiple,$action,%courses) = @_;
+ my ($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses) = @_;
if ($env{'form.form'} eq 'portform') {
$action = '/adm/portfolio';
}
@@ -219,27 +316,40 @@ sub display_matched_courses {
$r->print('
\n");
return;
}
-
sub multiples_tag {
my $jscript = &Apache::loncommon::check_uncheck_jscript();
my $multelement = '';
@@ -338,25 +543,45 @@ sub multiples_tag {
sub build_filters {
my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
- $caller) = @_;
- my $list;
- my $formname;
+ $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,$codetitlesref) = @_;
+ my ($list,$formname,$fixeddom,$codedom,$jscript);
+ $codedom = $env{'request.role.domain'};
if (defined($env{'form.form'})) {
- $formname = $env{'form.form'};
+ $formname = $env{'form.form'};
} else {
- $formname = $caller;
+ $formname = $caller;
}
- my ($domainselectform,$sincefilterform,$ownerdomselectform,
- $instcodeform,$typeselectform);
+ my $onchange = 'javascript:updateFilters(this)';
+ my ($domainselectform,$sincefilterform,$createdfilterform,
+ $ownerdomselectform,$persondomselectform,$instcodeform,
+ $typeselectform,$instcodetitle);
foreach my $item (@{$filterlist}) {
$filter->{$item} = $env{'form.'.$item};
if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
- if ($item eq 'domainfilter' || $item eq 'ownerdomfilter') {
+ if ($item eq 'domainfilter') {
$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});
+ $filter->{'ownerdomfilter'} =
+ &LONCAPA::clean_domain($env{'form.ownerdomfilter'});
+ $ownerdomselectform =
+ &Apache::loncommon::select_dom_form($filter->{'ownerdomfilter'},
+ 'ownerdomfilter',1);
+ } elsif ($item eq 'personfilter') {
+ $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
+ if ($env{'form.persondomfilter'} eq '') {
+ unless ($env{'form.gosearch'}) {
+ $filter->{'persondomfilter'} = $env{'request.role.domain'};
+ }
+ } else {
+ $filter->{'persondomfilter'} =
+ &LONCAPA::clean_domain($env{'form.persondomfilter'});
+ }
+ $persondomselectform =
+ &Apache::loncommon::select_dom_form($filter->{'persondomfilter'},
+ 'persondomfilter',1);
} else {
$filter->{$item} =~ s/\W//g;
}
@@ -373,55 +598,105 @@ sub build_filters {
$filter->{$item} ||= $env{'request.role.domain'};
$allow_blank=0;
}
- $domainselectform =
- &Apache::loncommon::select_dom_form($filter->{$item},
- 'domainfilter',
- $allow_blank);
- } elsif ($item eq 'ownerdomfilter') {
- $ownerdomselectform =
- &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1);
+ if ($env{'form.fixeddom'}) {
+ $domainselectform = ''.
+ &Apache::lonnet::domain($env{'request.role.domain'},
+ 'description');
+ $codedom = $env{'request.role.domain'};
+ } else {
+ $domainselectform =
+ &Apache::loncommon::select_dom_form($filter->{$item},
+ 'domainfilter',
+ $allow_blank,'',$onchange);
+ $codedom = $filter->{'domainfilter'};
+ }
} else {
$list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
}
}
# last course activity filter and selection
- $filter->{'sincefilter'} = $env{'form.sincefilter'};
- $filter->{'sincefilter'} =~ s/[^\d-]//g;
- if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
- $sincefilterform=&Apache::loncommon::select_form($filter->{'sincefilter'},
- 'sincefilter',('-1'=>'',
- '86400' => 'today',
- '604800' => 'last week',
- '2592000' => 'last month',
- '7776000' => 'last three months',
- '15552000' => 'last six months',
- '31104000' => 'last year',
- 'select_form_order' =>
- ['-1','86400','604800','2592000','7776000',
- '15552000','31104000']));
-
- my %lt = (
- 'cac' => &mt('[_1] Activity',$type),
- 'cde' => &mt('[_1] Description',$type),
- 'cdo' => &mt('[_1] Domain',$type),
- 'cin' => &mt('Course Institutional Code'),
- 'cow' => &mt("[_1] Owner's Username",$type),
- 'cod' => &mt("[_1] Owner's Domain", $type),
- 'cog' => &mt('Course Type')
+ $sincefilterform = &timebased_select_form('sincefilter',$filter);
+
+ # course created filter and selection
+ if (exists($filter->{'createdfilter'})) {
+ $createdfilterform = &timebased_select_form('createdfilter',$filter);
+ }
+
+ my %lt = &Apache::lonlocal::texthash(
+ 'cac' => "$type Activity",
+ 'ccr' => "$type Created",
+ 'cde' => "$type Title",
+ 'cdo' => "$type Domain",
+ 'ins' => 'Institutional Code',
+ 'inc' => 'Institutional Categorization',
+ 'cow' => "$type Owner/Co-owner",
+ 'cop' => "$type Personnel Includes",
+ 'cog' => 'Type',
);
- $typeselectform = '";
+
my $output = qq|
'."\n".'
'."\n";
+ return $jscript.$warning.$output;
+}
+
+sub timebased_select_form {
+ my ($item,$filter) = @_;
+ if (ref($filter) eq 'HASH') {
+ $filter->{$item} = $env{'form.'.$item};
+ $filter->{$item} =~ s/[^\d-]//g;
+ if (!$filter->{$item}) { $filter->{$item}=-1; }
+ return &Apache::loncommon::select_form(
+ $filter->{$item},
+ $item,
+ { '-1' => '',
+ '86400' => &mt('today'),
+ '604800' => &mt('last week'),
+ '2592000' => &mt('last month'),
+ '7776000' => &mt('last three months'),
+ '15552000' => &mt('last six months'),
+ '31104000' => &mt('last year'),
+ 'select_form_order' =>
+ ['-1','86400','604800','2592000','7776000',
+ '15552000','31104000']});
+ }
+}
+
+sub get_coordinator_cloneable {
+ my ($cloneruname,$clonerudom,$type) = @_;
+ if (($cloneruname!~/\w/) || ($clonerudom!~/\w/)) {
+ my $warning = ''.&mt('Intended course owner not specified').
+ '
';
+ return ('',$warning);
+ } elsif (&Apache::lonnet::homeserver($cloneruname,$clonerudom) eq 'no_host') {
+ my $warning = ''.&mt('Intended course owner does not exist').
+ '
';
+ return ('',$warning);
+ } else {
+ my ($cc_clone,$ccrole);
+ if ($type eq 'Community') {
+ $ccrole = 'co';
+ } elsif ($type eq 'Course') {
+ $ccrole = 'cc';
+ }
+ my %ccroles = &Apache::lonnet::get_my_roles($cloneruname,$clonerudom,
+ 'userroles',['active'], [$ccrole]);
+ foreach my $key (sort(keys(%ccroles))) {
+ my ($cnum,$cdom,$role) = split(':',$key);
+ $cc_clone .= $cdom.':'.$cnum.'&';
+ }
+ $cc_clone =~ s/\&$//;
+ return ($cc_clone);
}
- $output .= qq|
-
-
-
-|;
- return $output;
+}
+
+sub instcode_selectors {
+ my ($codedom,$formname,$officialjs,$codetitles) = @_;
+ my ($output,%cat_titles,%cat_order,%cat_items);
+ my ($jscript,$totcodes,$numtitles,$lasttitle) =
+ &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
+ \%cat_items,$codetitles,\%cat_titles,\%cat_order,$officialjs);
+ if ($numtitles > 0) {
+ my $official = ' checked="checked" ';
+ my $unofficial = '';
+ if ($env{'form.official'} eq 'off') {
+ $unofficial = $official;
+ $official = '';
+ }
+ $output .= ''.&mt('Official course:').' '.(' 'x3).'
'.
+ &Apache::courseclassifier::build_instcode_selectors($numtitles,
+ $lasttitle,\%cat_items,$codetitles,\%cat_titles,\%cat_order)."\n".
+ ''."\n".
+ ''."\n";
+
+ }
+ return ($output,$jscript,$numtitles);
}
sub search_courses {
- my ($r,$type,$onlyown,$filter) = @_;
- my %courses;
+ my ($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
+ my (%courses,%showcourses,$cloner,$ccrole);
+ if ($type eq 'Community') {
+ $ccrole = 'co';
+ } else {
+ $ccrole = 'cc';
+ }
if (!$onlyown) {
- $r->print(&mt('Searching').' ...
');
+ $r->print(&mt('Searching ...').'
');
$r->rflush();
if (($filter->{'ownerfilter'} ne '') ||
($filter->{'ownerdomfilter'} ne '')) {
$filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
$filter->{'ownerdomfilter'};
}
- foreach my $item ('descriptfilter','instcodefilter','coursefilter',
- 'combownerfilter') {
+ foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
if (!$filter->{$item}) {
$filter->{$item}='.';
}
}
- if ($type eq '') { $type = '.'; }
+ my $now = time;
my $timefilter =
- ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
+ ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
+ my ($createdbefore,$createdafter);
+ if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
+ $createdbefore = $now;
+ $createdafter = $now-$filter->{'createdfilter'};
+ }
+ my ($instcodefilter,$regexpok);
+ if ($numtitles) {
+ if ($env{'form.official'} eq 'on') {
+ $instcodefilter =
+ &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles,$codetitles);
+ $regexpok = 1;
+ } elsif ($env{'form.official'} eq 'off') {
+ $instcodefilter = &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles,$codetitles);
+ unless ($instcodefilter eq '') {
+ $regexpok = -1;
+ }
+ }
+ } else {
+ $instcodefilter = $filter->{'instcodefilter'};
+ }
+ if ($instcodefilter eq '') { $instcodefilter = '.'; }
+ if ($type eq '') { $type = '.'; }
+
+ if (($clonerudom ne '') && ($cloneruname ne '')) {
+ $cloner = $cloneruname.':'.$clonerudom;
+ }
%courses =
&Apache::lonnet::courseiddump($filter->{'domainfilter'},
$filter->{'descriptfilter'},
$timefilter,
- $filter->{'instcodefilter'},
+ $instcodefilter,
$filter->{'combownerfilter'},
$filter->{'coursefilter'},
- undef,undef,$type);
+ undef,undef,$type,$regexpok,undef,undef,
+ undef,undef,$cloner,$env{'form.cc_clone'},
+ $filter->{'cloneableonly'},
+ $createdbefore,$createdafter,undef,
+ $domcloner);
+ if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
+ my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
+ $filter->{'persondomfilter'},
+ 'userroles',undef,
+ [$ccrole,'in','ad','ep','ta','cr'],
+ $filter->{'domainfilter'});
+ foreach my $role (keys(%rolehash)) {
+ my ($cnum,$cdom,$courserole) = split(':',$role);
+ my $cid = $cdom.'_'.$cnum;
+ if (exists($courses{$cid})) {
+ if (ref($courses{$cid}) eq 'HASH') {
+ if (ref($courses{$cid}{roles}) eq 'ARRAY') {
+ if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
+ push (@{$courses{$cid}{roles}},$courserole);
+ }
+ } else {
+ $courses{$cid}{roles} = [$courserole];
+ }
+ $showcourses{$cid} = $courses{$cid};
+ }
+ }
+ }
+ %courses = %showcourses;
+ }
} else {
$r->print('
');
my %coursehash = &Apache::loncommon::findallcourses();
@@ -522,12 +980,18 @@ sub search_courses {
}
sub course_chooser {
- my ($multiple,$cdom,$cnum,$cleandesc) = @_;
+ my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_;
my $output;
if ($multiple) {
$output = '