# The LearningOnline Network
# Request a course
#
# $Id: lonrequestcourse.pm,v 1.1 2009/07/27 22:58:24 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
###
=head1 NAME
Apache::lonrequestcourse.pm
=head1 SYNOPSIS
Allows users to request creation of new courses.
This is part of the LearningOnline Network with CAPA project
described at http://www.lon-capa.org.
=head1 SUBROUTINES
=over
=item handler()
=back
=cut
package Apache::lonrequestcourse;
use strict;
use Apache::Constants qw(:common :http);
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
use LONCAPA;
sub handler {
my ($r) = @_;
if ($r->header_only) {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK;
}
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
my $action = $env{'form.action'};
my $state = $env{'form.state'};
my $dom = &get_course_dom();
my %can_request;
my $canreq = &check_can_request($dom,\%can_request);
if ($action eq 'new') {
if ($canreq) {
if ($state eq 'crstype') {
&print_main_menu($r,\%can_request,$dom);
} else {
&request_administration($r,$action,$state,$dom);
}
} else {
$r->print(&Apache::loncommon::start_page('Course Requests').
'
'.
&mt('You do not have privileges to request creation of courses.').
'
'.
&Apache::loncommon::end_page());
}
} elsif ($action eq 'view') {
&print_request_status();
} elsif ($action eq 'log') {
&print_request_logs();
} else {
&print_main_menu($r,\%can_request,$dom);
}
return OK;
}
sub check_can_request {
my ($dom,$can_request) = @_;
my $canreq = 0;
if (ref($can_request) eq 'HASH') {
foreach my $type ('official','unofficial','community') {
if (&Apache::lonnet::usertools_access($env{'user.name'},
$env{'user.domain'},
$type,undef,'requestcourses')) {
$canreq ++;
if ($dom eq $env{'user.domain'}) {
$can_request->{$type} = 1;
}
}
if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
my @curr = split(',',$env{'environment.reqcrsotherdom.'.$type});
if (@curr > 0) {
$canreq ++;
unless ($dom eq $env{'user.domain'}) {
if (grep(/^\Q$dom\E$/,@curr)) {
$can_request->{$type} = 1;
}
}
}
}
}
}
return $canreq;
}
sub print_main_menu {
my ($r,$can_request,$dom) = @_;
my $onchange;
unless ($env{'form.interface'} eq 'textual') {
$onchange = 1;
}
&Apache::lonhtmlcommon::clear_breadcrumbs();
my $js = <
function nextPage(formname,nextstate) {
if (check_can_request() == true) {
formname.state.value= nextstate;
formname.submit();
}
return;
}
function backPage(formname,prevstate) {
formname.state.value = prevstate;
formname.submit();
}
function check_can_request() {
var official = '';
var unofficial = '';
var community = '';
END
foreach my $item (keys(%{$can_request})) {
$js .= "
$item = 1;
";
}
my %lt = &Apache::lonlocal::texthash(
official => 'You are not permitted to request creation of an official course in this domain.',
unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
community => 'You are not permitted to request creation of a community this domain.',
all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
);
$js .= <
END
my $formname = 'requestform';
$r->print(&Apache::loncommon::start_page('Course Requests',$js).
'
'.
'
');
my $formname = 'requestform';
my $next = 'codepick';
my $nexttext = &mt('Next');
$r->print('');
$r->print(&Apache::loncommon::end_page());
return;
}
sub request_administration {
my ($r,$action,$state,$dom) = @_;
if ($action eq 'new') {
my $js = <
function nextPage(formname,nextstate) {
formname.state.value= nextstate;
formname.submit();
}
function backPage(formname,prevstate) {
formname.state.value = prevstate;
formname.submit();
}
END
unless (($state eq 'review') || ($state eq 'process')) {
$js .= "\n".&Apache::loncommon::coursebrowser_javascript($dom);
}
my $start_page =
&Apache::loncommon::start_page('Request a course',$js);
$r->print($start_page);
if ($state eq 'review') {
&print_review($r,$state,$dom);
} elsif ($state eq 'process') {
&print_request_outcome($r,$state,$dom);
} else {
&print_request_form($r,$state,$dom);
}
$r->print(&Apache::loncommon::end_page());
} elsif ($action eq 'log') {
$r->print(&coursereq_log());
}
return;
}
sub print_request_form {
my ($r,$state,$dom) = @_;
my $formname = 'requestcrs';
my ($next,$prev,$message,$output,$codepicker);
my $prev = 'crstype';
$r->print('');
&display_navbuttons($r,$formname,$prev,'Previous',$next,'Next');
return;
}
sub inst_section_selector {
my ($sections,$selected) = @_;
my $output;
if (ref($sections) eq 'ARRAY') {
$output = &Apache::lonhtmlcommon::row_title('Sections').
&Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_row().
'
'.&mt('Institutional Section').'
'.
'
'.&mt('LON-CAPA section ID').'
'.
'
'.&mt('Include in course?').'
'.
&Apache::loncommon::end_data_table_row();
for (my $i=0; $i<@{$sections}; $i++) {
my $colflag = $i%2;
$output .= &Apache::loncommon::start_data_table_row().
'
'.$sections->[$i].
'
'.
'
'.
'
'.
&Apache::loncommon::end_data_table_row();
}
$output .= &Apache::loncommon::end_data_table();
}
return $output;
}
sub print_request_status {
return;
}
sub print_request_logs {
return;
}
sub print_review {
my ($r,$state,$dom) = @_;
return;
}
sub courseinfo_form {
my $output = &Apache::lonhtmlcommon::row_title('Course Description').
'';
return $output;
}
sub clone_form {
my ($dom,$formname,$crstype) = @_;
my $type = 'Course';
if ($crstype eq 'community') {
$type = 'Community';
}
my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedomain').
&Apache::loncommon::selectcourse_link($formname,'clonecourse',
'clonedomain','','','',$type);
my %lt = &Apache::lonlocal::texthash(
'cid' => 'Course ID',
'dmn' => 'Domain',
'dsh' => 'Date Shift',
'ncd' => 'Do not clone date parameters',
'prd' => 'Clone date parameters as-is',
'shd' => 'Shift date parameters by number of days',
);
my $output .= &Apache::lonhtmlcommon::start_pick_box().
&Apache::lonhtmlcommon::row_title($lt{'cid'}).
''.&Apache::lonhtmlcommon::row_closure(1).''.
$cloneform.''.&Apache::lonhtmlcommon::row_closure().
&Apache::lonhtmlcommon::row_title($lt{'dsh'}).'
'.
''.
&Apache::lonhtmlcommon::row_closure(1).
&Apache::lonhtmlcommon::end_pick_box();
return $output;
}
sub coursecode_form {
my ($dom,$context,$codetitles,$cat_titles,$cat_order,$count) = @_;
my $output;
if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
(ref($cat_order))) {
if (@{$codetitles} > 0) {
my $lastitem = pop(@{$codetitles});
my $sel = $context;
if ($context eq 'crosslist') {
$sel .= '_'.$count;
}
my $lastinput = '';
my %rowtitle = (
instcode => 'Course Category',
crosslist => 'Cross Listed Course',
);
if (@{$codetitles} > 0) {
my $sel = $context;
if ($context eq 'crosslist') {
$sel .= '_'.$count;
}
$output = &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
'
';
foreach my $title (@{$codetitles}) {
if (ref($cat_order->{$title}) eq 'ARRAY') {
if (@{$cat_order->{$title}} > 0) {
$output .= '