--- loncom/interface/lonpickcourse.pm 2006/06/29 17:44:03 1.50.2.1
+++ loncom/interface/lonpickcourse.pm 2009/11/04 14:12:19 1.90
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.50.2.1 2006/06/29 17:44:03 albertel Exp $
+# $Id: lonpickcourse.pm,v 1.90 2009/11/04 14:12:19 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,8 +35,8 @@ use Apache::loncoursedata;
use Apache::lonnet;
use Apache::lonlocal;
use Apache::longroup;
-use lib '/home/httpd/lib/perl/';
-use LONCAPA;
+use Apache::courseclassifier;
+use LONCAPA qw(:DEFAULT :match);
sub handler {
my $r = shift;
@@ -46,502 +46,1184 @@ sub handler {
# ------------------------------------------------------------ Print the screen
-# Get parameters from query string
+ # Get parameters from query string
&Apache::loncommon::get_unprocessed_cgi
- ($ENV{'QUERY_STRING'},['domainfilter','descriptfilter',
- 'sincefilter','form','cnumelement',
+ ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
'cdomelement','cnameelement','roleelement',
- 'pickedcourse','instcodefilter',
- 'ownerfilter','coursefilter','multiple',
- 'type']);
-# domain filter and selection
- my $domainfilter=$env{'form.domainfilter'};
- $domainfilter=~s/\W//g;
- unless ($domainfilter) { $domainfilter=''; }
- my $domainselectform=&Apache::loncommon::select_dom_form($domainfilter,
- 'domainfilter',1);
-# description filter
- my $descriptfilter=$env{'form.descriptfilter'};
- unless ($descriptfilter) { $descriptfilter=''; }
- my $listdescript=&HTML::Entities::encode($descriptfilter,'<>&"');
-# institutional code filter
- my $instcodefilter=$env{'form.instcodefilter'};
- unless ($instcodefilter) { $instcodefilter=''; }
- my $listinstcode=&HTML::Entities::encode($instcodefilter,'<>&"');
-# course owner filter
- my $ownerfilter=$env{'form.ownerfilter'};
- unless ($ownerfilter) { $ownerfilter=''; }
- my $listowner=&HTML::Entities::encode($ownerfilter,'<>&"');
-# course ID filter for DCs only
- my ($courseidtag,$coursefilter);
- if ($env{'user.adv'} && $domainfilter && exists($env{'user.role.dc./'.
- $domainfilter.'/'})) {
- $coursefilter=$env{'form.coursefilter'};
- unless ($coursefilter) { $coursefilter=''; }
- my $listcourseid=&HTML::Entities::encode($coursefilter,'<>&"');
- $courseidtag = &mt('LON-CAPA course ID');
- $courseidtag .= qq|:
-
- |;
- }
-# last course activity filter and selection
- my $sincefilter=$env{'form.sincefilter'};
- $sincefilter=~s/[^\d-]//g;
- unless ($sincefilter) { $sincefilter=-1; }
- my $sincefilterform=&Apache::loncommon::select_form($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']));
-# if called from loncreateuser, report sections, then close
- my (%loaditem,$seclist,$groupslist,$roleslist,$rolesnameslist,
- $accesslist,$accessnameslist);
- my $sec_element = 'currsec';
- my $grplist_element = 'groups';
- my $num_sections = 0;
- my $num_groups = 0;
- my $num_roles = 0;
- my $num_access = 0;
- my ($cdom,$cnum);
- if ($env{'form.pickedcourse'}) {
- ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
- }
- my $type = $env{'form.type'};
+ 'multiple','type','setroles','fixeddom','cloner']);
+ my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement,
+ $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom);
+
+ # Get course type - Course or Community.
+ $type = $env{'form.type'};
if (!defined($env{'form.type'})) {
$type = 'Course';
}
- if ($env{'form.form'} eq 'cu' && $env{'form.pickedcourse'}) {
- $loaditem{'onload'} ="setSections()";
- ($seclist,$num_sections,$groupslist,$num_groups) =
- &build_selection_lists($cdom,$cnum,$type,undef,undef,
- $env{'form.form'});
- }
-# if called from portfolio, report roles, sections, groups and close
- my ($roles_element,$groups_element,$status_element,$setitems_function);
- if ($env{'form.form'} eq 'portform' && $env{'form.pickedcourse'}) {
- my ($row_id) = ($env{'form.cnumelement'} =~ /^crsnum_(\d+)$/);
- $roles_element = 'role_'.$row_id.'_1';
- $groups_element = 'group_'.$row_id.'_1';
- $sec_element = 'section_'.$row_id.'_1';
- $status_element = 'access_'.$row_id.'_1';
- $grplist_element = 'grplist_'.$row_id.'_1';
- $loaditem{'onload'} ="setItems()";
- ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,$num_roles,
- $rolesnameslist,$accesslist,$num_access,$accessnameslist) =
- &build_selection_lists($cdom,$cnum,$type,1,1,$env{'form.form'});
- $setitems_function = qq|
-function setItems() {
- opener.document.$env{"form.form"}.activate.checked = true;
- setRoles();
- setGroups();
- setStatus();
- setSections();
-}
+ $title = 'Selecting a '.$type;
-function setRoles() {
- var numRoles = $num_roles
- var rolesArray = new Array("$roleslist");
- var roleNamesArray = new Array("$rolesnameslist");
- opener.document.$env{"form.form"}.$roles_element.length = 0;
- if (numRoles == 0) {
- opener.document.$env{"form.form"}.$roles_element.multiple=false;
- opener.document.$env{"form.form"}.$roles_element.size=1;
- opener.document.$env{"form.form"}.$roles_element.options[0] = new Option('No existing roles','',false,false);
- } else {
- if (numRoles == 1) {
- opener.document.$env{"form.form"}.$roles_element.multiple=false;
- opener.document.$env{"form.form"}.$roles_element.size=1;
- opener.document.$env{"form.form"}.$roles_element.options[0] = new Option('Select','',true,true);
- opener.document.$env{"form.form"}.$roles_element.options[1] = new Option(roleNamesArray[0],rolesArray[0],false,false);
- } else {
- for (var i=0; i';
+ $submitopener = &processpick();
+ $autosubmit = 'process_pick("'.$roledom.'")';
+ }
+ if ($env{'form.typeelement'} ne '') {
+ $typeelement = '';
+ }
+
+ # if called when a DC is creating a course
+ 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
+ if ((($env{'form.form'} eq 'portform') && (!$env{'user.adv'}))) {
+ $onlyown = 1;
+ }
+
+ 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'} .= 'setRoles();setSections();';
+ }
+ my $js = &js_changer();
+ $r->print(&Apache::loncommon::start_page($title,$js,
+ {'add_entries' => \%loaditem,
+ 'no_nav_bar' => 1, }));
+
+ if ($env{'form.form'} eq 'portform') {
+ $lastaction = 'document.courselist.submit()';
+ } elsif ($env{'form.form'} eq 'cu' || ($env{'form.form'} eq 'studentform' &&
+ !$multiple)) {
+ $lastaction =
+ 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
+ 'document.courselist.submit();';
+ } else {
+ $lastaction = 'self.close()';
+ }
+
+ # if called to assign a role in a course to a user via CUSR
+ if ($env{'form.form'} eq 'cu' || $env{'form.form'} eq 'studentform') {
+ $r->print(&create_user_javascript($type));
+ }
+
+ # print javascript functions for choosing a course
+ if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
+ $onlyown) {
+ $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
+ }
+ $r->print('');
+ $r->print($submitopener);
+
+# ------------------------------------------ Display of filters to limit search
+ my $filter = {};
+ my $action = '/adm/pickcourse';
+ my ($numtitles,$showroles,$nohost);
+ if (!$onlyown) {
+ my $filterlist = ['domainfilter','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;
+ }
}
- opener.document.$env{"form.form"}.$roles_element.options[0].selected = false;
+ } 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,\$numtitles,undef,$cloneruname,
+ $clonerudom,$typeelement));
+ }
+
+# ---------------------------------------------------------------- Get the data
+ if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
+ $onlyown) {
+ my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles,
+ $cloneruname,$clonerudom);
+ 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;
}
-function setStatus() {
- var numStatus = $num_access;
- var statusArray = new Array("$accesslist");
- var statusNamesArray = new Array("$accessnameslist");
- opener.document.$env{"form.form"}.$status_element.multiple=true;
- opener.document.$env{"form.form"}.$status_element.size=3;
- for (var i=0; i
+
+function updateFilters(caller) {
+ if (typeof(caller) != "undefined") {
+ document.filterpicker.updater.value = caller.name;
}
+ document.filterpicker.submit();
+}
+
+
+
+ENDJS
+
}
-function setGroups() {
- var numGroups = $num_groups;
- var groupsArray = new Array("$groupslist");
- opener.document.$env{"form.form"}.$groups_element.length = 0;
- if (numGroups == 0) {
- opener.document.$env{"form.form"}.$groups_element.multiple=false;
- opener.document.$env{"form.form"}.$groups_element.size=1;
- opener.document.$env{"form.form"}.$groups_element.options[0] = new Option('No existing groups','',false,false);
+sub processpick {
+ my $openerform = 'rolechoice';
+ if ($env{'form.form'} eq 'studentform') {
+ $openerform = $env{'form.form'};
+ }
+ my $process_pick = <<"ENDONE";
+
+";
+ return $process_pick;
+}
+
+sub create_user_javascript {
+ my ($type) = @_;
+ my $output;
+ #javascript for reporting sections and groups then closing
+ if ($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) =
+ &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
+ my $num_sections = scalar(@{$sections});
+ my $seclist = join(',',@{$sections});
+ my $num_groups = scalar(@{$groups});
+ my $groupslist = join(',',@{$groups});
+ $output = qq|
+
+|;
+;
+ }
+ return $output;
+}
+
+sub display_matched_courses {
+ my ($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses) = @_;
+ if ($env{'form.form'} eq 'portform') {
+ $action = '/adm/portfolio';
+ }
+ my $numcourses = keys(%courses);
+ $r->print('\n");
+ return;
+}
- my %elements = (
- Course => {
- name => 'coursepick',
- total => 'coursetotal',
- list => 'courselist',
- },
- Group => {
- name => 'grouppick',
- total => 'grouptotal',
- list => 'grouplist',
- },
- );
+sub multiples_tag {
+ my $jscript = &Apache::loncommon::check_uncheck_jscript();
+ my $multelement = '';
+ return ($jscript,$multelement);
+}
- $r->print(<
-function gochoose(cname,cdom,cdesc,multiple,caller) {
- var openerForm = "$env{'form.form'}";
- courseCount = 0;
- var courses = '';
- if (multiple) {
- if (typeof(document.courselist.course_id.length) == 'undefined') {
- // only 1 course checkbox was created
- if (document.courselist.course_id.checked) {
- courses = courses + document.courselist.course_id.value + "&&";
- courseCount ++;
- }
- } else {
- for (var j=0; j{$item} = $env{'form.'.$item};
+ if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
+ 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 {
- opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
- }
- } else {
- for (var j=0; j{$item} =~ s/\W//g;
}
- }
- if (courseCount > 0) {
- courses = courses.substr(0,courses.length-2);
- opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
- }
- } else {
- $name_code
- opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
- var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
- if (slct.options == undefined) {
- opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
+ if (!$filter->{$item}) {
+ $filter->{$item} = '';
+ }
}
- else {
- var i;
- for (i=0;i{$item} ||= $env{'user.domain'};
+ $allow_blank=0;
+ } elsif ($formname eq 'studentform') {
+ $filter->{$item} ||= $env{'request.role.domain'};
+ $allow_blank=0;
+ }
+ 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},'<>&"');
}
}
- $autosubmit
- $lastaction
-}
-function setSections() {
- var numSections = $num_sections
- var sectionsArray = new Array("$seclist")
- opener.document.$env{"form.form"}.$sec_element.length = 0
- if (numSections == 0) {
- opener.document.$env{"form.form"}.$sec_element.multiple=false
- opener.document.$env{"form.form"}.$sec_element.size=1;
- opener.document.$env{"form.form"}.$sec_element.options[0] = new Option('No existing sections','',false,false)
- } else {
- if (numSections == 1) {
- opener.document.$env{"form.form"}.$sec_element.multiple=false;
- opener.document.$env{"form.form"}.$sec_element.size=1;
- opener.document.$env{"form.form"}.$sec_element.options[0] = new Option('Select','',true,true);
- opener.document.$env{"form.form"}.$sec_element.options[1] = new Option('No section','',false,false)
- opener.document.$env{"form.form"}.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
+ # 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("$type Activity"),
+ 'cde' => &mt("$type Title"),
+ 'cdo' => &mt("$type Domain"),
+ 'ins' => &mt('Institutional Code'),
+ 'inc' => &mt('Institutional Categorization'),
+ 'cow' => &mt("$type Owner/Co-owner"),
+ 'cop' => &mt("$type Personnel Includes"),
+ 'cog' => &mt('Type')
+ );
+
+ if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
+ my $typeval = 'Course';
+ if ($type eq 'Community') {
+ $typeval = 'Community';
+ }
+ $typeselectform = '';
+ } else {
+ $typeselectform = '";
+ }
+
+ my ($cloneableonlyform,$cloneabletitle);
+ if (exists($filter->{'cloneableonly'})) {
+ my $cloneableon = '';
+ my $cloneableoff = ' checked="checked"';
+ if ($filter->{'cloneableonly'}) {
+ $cloneableon = $cloneableoff;
+ $cloneableoff = '';
+ }
+ $cloneableonlyform = ''.(' 'x3).'';
+ if ($env{'form.form'} eq 'ccrs') {
+ $cloneabletitle = &mt('Cloneable for').' '.$cloneruname.':'.$clonerudom;
} else {
- for (var i=0; i{'instcodefilter'})) {
+ if (($env{'form.fixeddom'}) || ($formname eq 'requestcrs')
+ || ($formname eq 'modifycourse')) {
+ $officialjs = 1;
+ ($instcodeform,$jscript,$$numtitlesref) =
+ &instcode_selectors($codedom,'filterpicker',$officialjs);
+ if ($jscript) {
+ $jscript = ''."\n";
+ }
}
- opener.document.$env{"form.form"}.$sec_element.multiple=true
- if (numSections < 3) {
- opener.document.$env{"form.form"}.$sec_element.size=numSections;
+ if ($instcodeform eq '') {
+ $instcodeform =
+ '';
+ $instcodetitle = $lt{'ins'};
} else {
- opener.document.$env{"form.form"}.$sec_element.size=3;
+ $instcodetitle = $lt{'inc'};
+ }
+ if ($env{'form.fixeddom'}) {
+ $instcodetitle .= '
('.$codedom.')';
}
- opener.document.$env{"form.form"}.$sec_element.options[0].selected = false
}
}
- opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
- self.close()
-}
-$setitems_function
-
-$jscript
-
-$submitopener
-
-
-ENDSCRIPT
-# ---------------------------------------------------------------- Get the data
- if ($env{'form.gosearch'}) {
- $r->print(&mt('Searching').' ...
');
+$typeelement
+|;
+ if ($formname eq 'portform') {
+ $output .= ''."\n";
+ }
+ }
+ if ($env{'form.fixeddom'}) {
+ $output .= ''."\n";
+ }
+ $output .= "
\n".&Apache::lonhtmlcommon::start_pick_box();
+ if ($sincefilterform) {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
+ .$sincefilterform
+ .&Apache::lonhtmlcommon::row_closure();
+ }
+ if ($domainselectform) {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
+ .$domainselectform
+ .&Apache::lonhtmlcommon::row_closure();
+ }
+ if ($typeselectform) {
+ if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
+ $output .= $typeselectform;
+ } else {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
+ .$typeselectform
+ .&Apache::lonhtmlcommon::row_closure();
+ }
+ }
+ if ($instcodeform) {
+ $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
+ .$instcodeform
+ .&Apache::lonhtmlcommon::row_closure();
+ }
+ if (exists($filter->{'ownerfilter'})) {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
+ ''.
+ &Apache::lonhtmlcommon::row_closure();
+ }
+ if (exists($filter->{'personfilter'})) {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
+ ''.
+ &Apache::lonhtmlcommon::row_closure();
+ }
+ if (exists($filter->{'coursefilter'})) {
+ $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
+ .''
+ .&Apache::lonhtmlcommon::row_closure();
+ }
+ if ($cloneableonlyform) {
+ $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
+ $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
+ }
+ if (exists($filter->{'descriptfilter'})) {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
+ .''
+ .&Apache::lonhtmlcommon::row_closure(1);
+ }
+ $output .= &Apache::lonhtmlcommon::end_pick_box().'';
+ my $warning;
+ if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
+ my $cloneruhome=&Apache::lonnet::homeserver($cloneruname,$clonerudom);
+ my $cc_clone;
+ if ($cloneruhome eq 'no_host') {
+ $warning = '
'.&mt('Intended course owner does not exist').
+ '
';
+ } else {
+ my $ccrole;
+ if ($type eq 'Community') {
+ $ccrole = 'co';
+ } elsif ($type eq 'Course') {
+ $ccrole = 'cc';
+ }
+ if ($env{'form.form'} eq 'ccrs') {
+ $output .= ''."\n";
+ }
+ 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/\&$//;
+ }
+ if ($cc_clone ne '') {
+ $output .= '';
+ }
+ }
+ $output .= ''."\n".
+ '
'."\n".''."\n".'
'."\n";
+ return $jscript.$warning.$output;
+}
+
+sub instcode_selectors {
+ my ($codedom,$formname,$officialjs) = @_;
+ my ($output,@codetitles,%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,$numtitles,$cloneruname,$clonerudom) = @_;
+ my (%courses,%showcourses,$cloner,$ccrole);
+ if ($type eq 'Community') {
+ $ccrole = 'co';
+ } else {
+ $ccrole = 'cc';
+ }
+ if (!$onlyown) {
+ $r->print(&mt('Searching ...').'
');
$r->rflush();
- unless ($descriptfilter) { $descriptfilter='.'; }
- unless ($instcodefilter) { $instcodefilter='.'; }
- unless ($ownerfilter) { $ownerfilter='.'; }
- unless ($coursefilter) { $coursefilter='.'; }
- unless ($type) { $type = '.'; }
- my $timefilter=($sincefilter==-1?1:time-$sincefilter);
- my %courses=
- &Apache::lonnet::courseiddump
- ($domainfilter,$descriptfilter,$timefilter,$instcodefilter,$ownerfilter,$coursefilter,undef,undef,$type);
- $r->print('\n");
}
- $r->print(&Apache::loncommon::end_page());
- return OK;
+ return %courses;
}
sub course_chooser {
- my ($multiple,$cdom,$cnum,$cleandesc) = @_;
+ my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_;
my $output;
if ($multiple) {
$output = '