--- loncom/interface/lonpickcourse.pm 2006/06/28 16:06:06 1.50
+++ loncom/interface/lonpickcourse.pm 2017/01/03 17:47:57 1.124
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.50 2006/06/28 16:06:06 albertel Exp $
+# $Id: lonpickcourse.pm,v 1.124 2017/01/03 17:47:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,308 +31,916 @@ package Apache::lonpickcourse;
use strict;
use Apache::Constants qw(:common);
use Apache::loncommon;
+use Apache::lonhtmlcommon;
use Apache::loncoursedata;
use Apache::lonnet;
use Apache::lonlocal;
use Apache::longroup;
-use lib '/home/httpd/lib/perl/';
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
+use JSON::DWIW;
sub handler {
my $r = shift;
+ if ($env{'form.context'} eq 'adhoc') {
+ &Apache::loncommon::content_type($r,'application/json');
+ $r->send_http_header;
+ my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.cid'});
+ if ((ref($possroles) eq 'ARRAY') && (ref($description) eq 'HASH')) {
+ my $response = [];
+ if (@{$possroles}) {
+ foreach my $role (@{$possroles}) {
+ push(@{$response},
+ { name => $role,
+ desc => $description->{$role},
+ });
+ }
+ }
+ $r->print(JSON::DWIW->to_json({roles => $response}));
+ }
+ return OK;
+ }
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK if $r->header_only;
-
+
# ------------------------------------------------------------ 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',
+ 'crscode','crsdom']);
+ my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement,
+ $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom,$crscode,
+ $crsdom,$rolechooser);
+
+ # Get course type - Course, Community or Placement.
+ $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);
+ # Setup for multiple course selections, if flag for multiples set.
+ $multiple = $env{'form.multiple'};
+ if ($multiple) {
+ ($jscript,$multelement) = &multiples_tag();
+ $title = 'Selecting '.$type.'(s)';
+ }
+
+ # if called when a DC or DH is selecting a course
+ my ($roledom,$rolename) = split(/:/,$env{'form.roleelement'});
+ if ($roledom) {
+ $roleelement = '';
+ $submitopener = &processpick();
+ $autosubmit = 'process_pick("'.$roledom.'","'.$rolename.'")';
+ if ($rolename eq 'dh') {
+ my %lt = &Apache::lonlocal::texthash(
+ title => 'Ad hoc role selection',
+ preamble => 'Please choose an ad hoc role in the course.',
+ cancel => 'Click "OK" to enter the course, or "Cancel" to choose a different course.',
+ );
+
+ $rolechooser = <<"END";
+
+
$lt{'preamble'}
+
+
$lt{'cancel'}
+
+END
+ }
+ }
+ 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)$/);
+ $crscode = $env{'form.crscode'};
+ $crsdom = $env{'request.role.domain'};
+ }
+
+ # if called when requesting a course
+ if ($env{'form.form'} eq 'requestcrs') {
+ $cloneruname = $env{'user.name'};
+ $clonerudom = $env{'user.domain'};
+ $crscode = $env{'form.crscode'};
+ $crsdom = $env{'form.crsdom'};
+ }
+
+ 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'})) {
+ if ($type ne 'Community') {
+ my %coursedescription =
+ &Apache::lonnet::coursedescription($env{'form.pickedcourse'},
+ {'one_time' => '1'});
+ my $cdom = $coursedescription{'domain'};
+ my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
+ if (($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'})) {
+ $loaditem{'onload'} .= 'setDefaultCredits();';
+ }
+ }
+ $loaditem{'onload'} .= 'setRoles();setSections();';
+ }
+ if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) && (!$onlyown)) {
+ $loaditem{'onload'} .= 'hideSearching(); ';
+ }
+ my $js = &Apache::loncommon::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 {
- 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; iprint(&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,
+ $rolename,$rolechooser));
+ }
+ $r->print(&Apache::lonhtmlcommon::scripttag($jscript));
+ $r->print($submitopener);
+
+# ------------------------------------------ Display of filters to limit search
+ my $filter = {};
+ my $action = '/adm/pickcourse';
+ my ($numtitles,$showroles,$nohost,@codetitles);
+ unless ($onlyown) {
+ my $filterlist = ['domainfilter','sincefilter'];
+ # 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');
}
- opener.document.$env{"form.form"}.$roles_element.multiple=true;
- if (numRoles < 3) {
- opener.document.$env{"form.form"}.$roles_element.size=numRoles;
+ }
+ push(@{$filterlist},('descriptfilter','instcodefilter'));
+ if ($env{'form.form'} eq 'rules') {
+ push(@{$filterlist},('personfilter','persondomfilter'));
+ if ($env{'form.persondomfilter'} eq '') {
+ unless ($env{'form.gosearch'}) {
+ $filter->{'persondomfilter'} = $env{'request.role.domain'};
+ }
} else {
- opener.document.$env{"form.form"}.$roles_element.size=3;
+ $filter->{'persondomfilter'} =
+ &LONCAPA::clean_domain($env{'form.persondomfilter'});
+ }
+ 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','ownerdomfilter'));
+ }
+ # 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');
+ }
+ if ((ref($filterlist) eq 'ARRAY') && (ref($filter) eq 'HASH')) {
+ foreach my $item (@{$filterlist}) {
+ $filter->{$item} = $env{'form.'.$item};
+ }
+ }
+ if ($env{'form.form'} eq 'portform') {
+ $filter->{'domainfilter'} ||= $env{'user.domain'};
+ } elsif ($env{'form.form'} eq 'studentform') {
+ $filter->{'domainfilter'} ||= $env{'request.role.domain'};
+ }
+ my $codedom;
+ if ($env{'form.fixeddom'}) {
+ $codedom = $env{'request.role.domain'};
+ } else {
+ $codedom = $filter->{'domainfilter'};
+ }
+ my ($clonetext,$clonewarning);
+ if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
+ (my $coord_cloneable,$clonewarning) =
+ &get_coordinator_cloneable($cloneruname,$clonerudom,$type);
+ if ($env{'form.form'} eq 'ccrs') {
+ $clonetext = ''."\n";
+ }
+ if ($coord_cloneable) {
+ $clonetext .= '';
+ }
+ if ($crscode ne '') {
+ $clonetext .= '';
+ }
+ if ($crsdom ne '') {
+ $clonetext .= '';
}
- opener.document.$env{"form.form"}.$roles_element.options[0].selected = false;
}
+ $r->print(&Apache::loncommon::build_filters($filterlist,$type,$roleelement,$multelement,
+ $filter,$action,\$numtitles,undef,$cloneruname,
+ $clonerudom,$typeelement,\@codetitles,$codedom,
+ $env{'form.form'},$env{'form.fixeddom'},
+ $env{'form.prevphase'},$env{'form.cnameelement'},
+ $env{'form.cnumelement'},$env{'form.cdomelement'},
+ $env{'form.setroles'},$clonetext,$clonewarning));
}
-}
-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; iprint(''.&mt('Searching ...').'
');
+ $r->rflush();
+ my $srchdom = $filter->{'domainfilter'};
+ %courses = &Apache::loncommon::search_courses($srchdom,$type,$filter,$numtitles,
+ $cloneruname,$clonerudom,$domcloner,
+ \@codetitles,$env{'form.cc_clone'},
+ $crsdom,$crscode);
+ } else {
+ $r->print('
');
+ my %coursehash = &Apache::loncommon::findallcourses();
+ foreach my $cid (sort(keys(%coursehash))) {
+ $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
+ }
+ }
+ 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,$crsdom,$crscode,%courses);
+ }
}
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
}
-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);
- } else {
- if (numGroups == 1) {
- 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('Select','',true,true);
- opener.document.$env{"form.form"}.$groups_element.options[1] = new Option('No group','',false,false);
- opener.document.$env{"form.form"}.$groups_element.options[2] = new Option(groupsArray[0],groupsArray[0],false,false);
- } else {
- for (var i=0; i
+function process_pick(dom,rolename) {
+ var pickedCourse=opener.document.$openerform.$env{'form.cnumelement'}.value;
+ var pickedDomain=opener.document.$openerform.$env{'form.cdomelement'}.value;
+ var okDomain = 0;
+ENDONE
+ if ($openerform eq 'rolechoice') {
+ $process_pick .= <<"ENDTWO";
+ if (pickedDomain == dom) {
+ if (pickedCourse != '') {
+ var courseTarget;
+ if (rolename == 'cc') {
+ var ccrole = "cc";
+ var pickedType = "$env{'form.type'}";
+ if (pickedType == "Community") {
+ ccrole = "co";
+ }
+ courseTarget = ccrole+"./"+pickedDomain+"/"+pickedCourse;
+ } else {
+ if (!/\\W/.test(rolename)) {
+ courseTarget = "cr/"+pickedDomain+"/"+pickedDomain+"-domainconfig/"+rolename+"./"+pickedDomain+"/"+pickedCourse;
+ }
}
- opener.document.$env{"form.form"}.$groups_element.multiple=true;
- if (numGroups < 3) {
- opener.document.$env{"form.form"}.$groups_element.size=numGroups;
+ if ((courseTarget != '') && (courseTarget != undefined)) {
+ opener.document.title='Role selected. Please stand by.';
+ opener.status='Role selected. Please stand by.';
+ opener.document.rolechoice.newrole.value=courseTarget;
+ opener.document.rolechoice.submit();
} else {
- opener.document.$env{"form.form"}.$groups_element.size=3;
+ alert("Invalid role selection");
+ return;
}
- opener.document.$env{"form.form"}.$groups_element.options[0].selected = false;
}
}
+ else {
+ alert("You may only use this screen to select courses in the current domain: "+dom+"\\nPlease return to the roles page window and click the 'Select Course' link for domain: "+pickedDomain+",\\n if you are a Domain Coordinator in that domain, and wish to become a Course Coordinator in a course in the domain");
+ }
+ENDTWO
+ } else {
+ $process_pick .= <<"ENDTHREE";
+ if (pickedDomain != dom) {
+ alert("You may only use this screen to select courses in the current domain: "+dom+"\\nPlease return to the roles page window and click the 'Select Course' link for domain: "+pickedDomain+",\\n if you are a Domain Coordinator in that domain, and wish to become a Course Coordinator in a course in the domain");
+ return;
+ }
+ENDTHREE
+ }
+ $process_pick .= "
+}
+
+
+";
+ 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 %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
+ my ($showcredits,$credits);
+ if (($crstype ne 'Community') &&
+ (($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}))) {
+ $showcredits = 1;
+ $credits = $coursedescription{'internal.defaultcredits'};
+ }
+ 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|
+
|;
}
- my $jscript;
- my $typeselectform = '";
- my $title = &mt('Selecting a [_1]',$type);
-# Setup for multiple course selections, if flag for multiples set.
- my $multiple = $env{'form.multiple'};
- my $multelement;
- if ($multiple) {
- $title = &mt('Selecting [_1](s)',lc($type));
- $jscript = &Apache::loncommon::check_uncheck_jscript();
- $multelement = '';
+ return $output;
+}
+
+sub display_matched_courses {
+ my ($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,$crsdom,$crscode,%courses) = @_;
+ if ($env{'form.form'} eq 'portform') {
+ $action = '/adm/portfolio';
}
- $r->print(&Apache::loncommon::start_page($title,undef,
- {'add_entries' => \%loaditem,
- 'no_nav_bar' => 1, }));
- 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),
- 'cog' => &mt('Course or Group')
- );
-
- my ($name_code,$name_input);
- if (defined($env{'form.cnameelement'}) && $env{'form.cnameelement'} ne '') {
- $name_code = "opener.document.$env{'form.form'}.$env{'form.cnameelement'}.value=cdesc;";
- $name_input ='';
- }
- my $submitopener = '';
- my $autosubmit = '';
- my $roleelement = '';
- my $lastaction = 'self.close()';
- if ($env{'form.form'} eq 'cu') {
- $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
- 'document.courselist.submit();';
+ my $numcourses = keys(%courses);
+ $r->print('\n");
+ return;
+}
+
+sub multiples_tag {
+ my $jscript = &Apache::loncommon::check_uncheck_jscript();
+ my $multelement = '';
+ return ($jscript,$multelement);
+}
+
+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';
+ } else {
+ $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);
}
+}
+sub course_chooser {
+ my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_;
+ my $output;
+ if ($multiple) {
+ $output = ' ")
+ .appendTo("#LC_choose_adhoc");
+ }
+ \$( "#LC_get_role_0").prop("checked", true);
+ \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
+ \$( "#LC_adhocrole_chooser" ).dialog("open");
+ \$( "#LC_adhocrole_chooser" ).dialog({
+ height: 400,
+ width: 500,
+ modal: true,
+ resizable: false,
+ buttons: [
+ {
+ text: "$lt{'ok'}",
+ click: function() {
+ var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val();
+ process_pick(cdom,rolename);
+ \$("#LC_adhocrole_chooser").dialog( "close" );
+ $lastaction;
+ }
+ },
+ {
+ text: "$lt{'exit'}",
+ click: function() {
+ \$("#LC_adhocrole_chooser").dialog( "close" );
+ }
+ }
+ ],
+ });
+ \$( "#LC_adhocrole_chooser" ).find( "form" ).on( "submit", function( event ) {
+ event.preventDefault();
+ var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val()
+ process_pick(cdom,rolename);
+ \$("#LC_adhocrole_chooser").dialog( "close" );
+ $lastaction;
+ });
}
- my $description = $descr;
- push (@{$by_descrip{$description}}, $course);
- }
- if ($numcourses > 1 && $multiple) {
- $r->print('
-
');
- }
- foreach my $description (sort
- { lc($a) cmp lc($b) } (keys(%by_descrip))) {
- foreach my $course (@{$by_descrip{$description}}) {
- my $cleandesc=&HTML::Entities::encode($description,'<>&"');
- $cleandesc=~s/'/\\'/g;
- my ($cdom,$cnum)=split(/\_/,$course);
- my ($descr,$instcode,$owner,$ttype) = split/:/,$courses{$course};
- $r->print(&course_chooser($multiple,$cdom,$cnum,$cleandesc));
- $r->print($description.'('.
- ($Apache::lonnet::domaindescription{$cdom}?
- $Apache::lonnet::domaindescription{$cdom}:$cdom).")");
- unless ($instcode eq '') {
- $r->print(" - ".&unescape($instcode));
- }
- unless ($owner eq '') {
- $r->print(", owner - ".&unescape($owner));
- }
- unless ($ttype eq '') {
- $r->print('('.&Apache::lonnet::unescape($ttype).')');
- }
- if ($multiple) { $r->print("\n"); }
- $r->print("
\n");
- }
- }
- if (!%courses) {
- $r->print(&mt('None found'));
- } elsif ($multiple) {
- $r->print('');
- }
- $r->print(''."\n".
- ''."\n".
- ''."\n".
- ''."\n".
- ''."\n");
- if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
- $r->print(''."\n");
}
- $r->print("\n");
}
- $r->print(&Apache::loncommon::end_page());
- return OK;
}
-
-sub course_chooser {
- my ($multiple,$cdom,$cnum,$cleandesc) = @_;
- my $output;
- if ($multiple) {
- $output = '