Annotation of loncom/interface/lonrequestcourse.pm, revision 1.113
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.113 ! raeburn 4: # $Id: lonrequestcourse.pm,v 1.112 2021/08/31 17:21:24 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: =head1 NAME
31:
32: Apache::lonrequestcourse.pm
33:
34: =head1 SYNOPSIS
35:
36: Allows users to request creation of new courses.
37:
38: This is part of the LearningOnline Network with CAPA project
39: described at http://www.lon-capa.org.
40:
41: =head1 SUBROUTINES
42:
43: =over
44:
45: =item handler()
46:
1.27 raeburn 47: =item get_breadcrumbs()
48:
1.12 raeburn 49: =item header()
50:
51: =item form_elements()
52:
53: =item onload_action()
54:
55: =item print_main_menu()
56:
57: =item request_administration()
58:
1.27 raeburn 59: =item close_popup_form()
60:
61: =item get_instcode()
62:
1.12 raeburn 63: =item print_request_form()
64:
65: =item print_enrollment_menu()
66:
1.27 raeburn 67: =item show_invalid_crosslists()
68:
1.12 raeburn 69: =item inst_section_selector()
70:
71: =item date_setting_table()
72:
73: =item print_personnel_menu()
74:
75: =item print_request_status()
76:
77: =item print_request_logs()
78:
79: =item print_review()
80:
81: =item dates_from_form()
82:
83: =item courseinfo_form()
84:
85: =item clone_form()
86:
87: =item clone_text()
88:
89: =item coursecode_form()
90:
91: =item get_course_dom()
92:
93: =item display_navbuttons()
94:
95: =item print_request_outcome()
96:
97: =item check_autolimit()
98:
99: =item retrieve_settings()
100:
101: =item get_request_settings()
102:
1.27 raeburn 103: =item extract_instcode()
104:
105: =item generate_date_items()
106:
1.1 raeburn 107: =back
108:
109: =cut
110:
111: package Apache::lonrequestcourse;
112:
113: use strict;
114: use Apache::Constants qw(:common :http);
115: use Apache::lonnet;
116: use Apache::loncommon;
117: use Apache::lonlocal;
1.8 raeburn 118: use Apache::loncoursequeueadmin;
1.30 raeburn 119: use Apache::lonuserutils;
1.4 raeburn 120: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 121:
1.107 raeburn 122: my $registered_flush;
123: my $registered_instcats;
124: my $modified_dom;
125:
1.1 raeburn 126: sub handler {
127: my ($r) = @_;
1.20 raeburn 128: &Apache::loncommon::content_type($r,'text/html');
129: $r->send_http_header;
1.1 raeburn 130: if ($r->header_only) {
131: return OK;
132: }
133:
1.107 raeburn 134: $registered_flush = 0;
135: $registered_instcats = 0;
136: $modified_dom = '';
137:
1.27 raeburn 138: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.73 raeburn 139: ['action','showdom','cnum','state','crstype','queue','tabs']);
1.2 raeburn 140: &Apache::lonhtmlcommon::clear_breadcrumbs();
141: my $dom = &get_course_dom();
1.1 raeburn 142: my $action = $env{'form.action'};
143: my $state = $env{'form.state'};
1.27 raeburn 144: my (%states,%stored);
1.72 raeburn 145: my ($jscript,$uname,$udom,$result,$warning,$showcredits,$instcredits,%can_request,
146: %request_domains,@incdoms);
1.66 raeburn 147: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1.69 raeburn 148: if ($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}) {
1.66 raeburn 149: $showcredits = 1;
150: }
1.27 raeburn 151:
1.72 raeburn 152: my $canreq =
153: &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains);
154:
155: foreach my $item (keys(%request_domains)) {
156: if (ref($request_domains{$item}) eq 'ARRAY') {
157: foreach my $possdom (@{$request_domains{$item}}) {
158: unless(grep(/^\Q$possdom\E$/,@incdoms)) {
159: push(@incdoms,$possdom);
160: }
161: }
162: }
163: }
164:
165: if ($canreq) {
1.103 raeburn 166: if (($env{'form.crstype'} eq 'lti') && ($env{'request.lti.login'}) &&
167: ($env{'form.lti.reqrole'} eq 'cc') && ($env{'form.lti.reqcrs'}) &&
168: ($env{'form.lti.sourcecrs'} ne '')) {
169: if ($action eq 'process') {
170: if ($can_request{'lti'}) {
171: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
172: &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig,\%can_request,'lti');
173: } else {
174: $r->print(&header('Course Request','','','',{ 'only_body' => 1}).
175: '<div>'.
176: '<p class="LC_info">'.&mt('You do not have privileges to request creation of LTI courses.').'</p>'.
177: '</div>'.
178: &Apache::loncommon::end_page());
179: }
180: }
181: return OK;
182: }
1.73 raeburn 183: if (($env{'form.crstype'} eq 'textbook') ||
184: (scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) {
1.72 raeburn 185: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
186: if ($action eq 'log') {
1.73 raeburn 187: my $usetabs;
188: if ((scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) {
189: $usetabs = 1;
190: } elsif ($env{'form.tabs'} eq 'on') {
191: $usetabs = 1;
192: }
1.72 raeburn 193: &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
194: my $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
1.73 raeburn 195: &print_request_logs($r,$dom,undef,undef,$crumb,$usetabs);
1.72 raeburn 196: } elsif ($action eq 'process') {
1.73 raeburn 197: if ($can_request{'textbook'}) {
198: &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig,\%can_request);
199: } else {
1.85 raeburn 200: &textbook_request_disabled($r,$dom,$action,\%can_request);
1.73 raeburn 201: }
1.83 raeburn 202: } elsif ($action eq 'display') {
203: my ($uname,$udom,$result,$warning) = &domcoord_display($dom);
204: if ($warning ne '') {
205: my $args = { only_body => 1 };
206: $r->print(&header('Course/Community Requests','','' ,'',$args).
207: '<h3>'.&mt('Course/Community Request Details').'</h3>'.
208: '<div class="LC_warning">'.$warning.'</div>'.
209: &close_popup_form());
210: } else {
211: $states{'display'} = ['details'];
212: my $loaditems = &onload_action($action,$state);
213: my $page = 0;
214: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
215: $loaditems,'','','','','',$showcredits,'','',
216: $uname,$udom);
217: }
1.72 raeburn 218: } else {
1.73 raeburn 219: if ($can_request{'textbook'}) {
1.103 raeburn 220: &print_textbook_form($r,$dom,\@incdoms,\%domdefs,$domconfig{'requestcourses'},
221: \%can_request,'textbook');
1.73 raeburn 222: } else {
1.85 raeburn 223: &textbook_request_disabled($r,$dom,$action,\%can_request);
1.73 raeburn 224: }
1.72 raeburn 225: }
226: return OK;
227: }
228: }
229:
1.27 raeburn 230: $states{'display'} = ['details'];
231: $states{'view'} = ['pick_request','details','cancel','removal'];
1.48 raeburn 232: $states{'log'} = ['display'];
1.27 raeburn 233: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
234:
235: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
236: unless ($env{'form.state'} eq 'crstype') {
237: unshift(@{$states{'new'}},'codepick');
238: }
239: }
240:
1.65 raeburn 241: if (($action eq 'new') && (&Apache::loncoursequeueadmin::author_prompt())) {
242: if (ref($states{$action}) eq 'ARRAY') {
243: push(@{$states{$action}},'reqauthor');
244: }
245: }
246:
1.27 raeburn 247: foreach my $key (keys(%states)) {
248: if (ref($states{$key}) eq 'ARRAY') {
249: unshift (@{$states{$key}},'crstype');
250: }
251: }
252:
253: my @invalidcrosslist;
254: my %trail = (
1.73 raeburn 255: crstype => 'Pick Action',
1.27 raeburn 256: codepick => 'Category',
257: courseinfo => 'Description',
258: enrollment => 'Access Dates',
259: personnel => 'Personnel',
260: review => 'Review',
261: process => 'Result',
1.65 raeburn 262: reqauthor => 'Authoring Space Result',
1.27 raeburn 263: pick_request => 'Display Summary',
264: details => 'Request Details',
265: cancel => 'Cancel Request',
266: removal => 'Outcome',
1.48 raeburn 267: display => 'Request Logs',
1.27 raeburn 268: );
269:
270: if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
271: $trail{'enrollment'} = 'Enrollment';
272: }
273:
1.66 raeburn 274: my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) =
1.27 raeburn 275: &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
1.26 raeburn 276: if ($action eq 'display') {
1.83 raeburn 277: ($uname,$udom,$result,$warning) = &domcoord_display($dom);
1.26 raeburn 278: } elsif ((defined($state)) && (defined($action))) {
1.16 raeburn 279: if (($action eq 'view') && ($state eq 'details')) {
280: if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
281: my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
1.2 raeburn 282: }
1.27 raeburn 283: } elsif ($env{'form.crstype'} eq 'official') {
284: if (&Apache::lonnet::auto_run('',$dom)) {
285: if (($action eq 'new') && (($state eq 'enrollment') ||
286: ($state eq 'personnel'))) {
287: my $checkcrosslist = 0;
288: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
289: if ($env{'form.crosslist_'.$i}) {
290: $checkcrosslist ++;
291: }
292: }
293: if ($checkcrosslist) {
294: my %codechk;
295: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
296: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,
297: \%cat_titles,
298: \%cat_order,
299: \@code_order);
300: my $numtitles = scalar(@codetitles);
301: if ($numtitles) {
302: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
303: if ($env{'form.crosslist_'.$i}) {
304: my $codecheck;
305: my $crosslistcode = '';
306: foreach my $item (@code_order) {
307: $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item};
308: }
309: if ($crosslistcode ne '') {
1.36 raeburn 310: ($codechk{$i}, my $rest) =
1.27 raeburn 311: &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
312: }
313: unless ($codechk{$i} eq 'valid') {
314: $env{'form.crosslist_'.$i} = '';
315: push(@invalidcrosslist,$crosslistcode);
316: }
317: }
318: }
319: }
320: }
321: }
322: }
1.2 raeburn 323: }
1.66 raeburn 324: (my $elements,$instcredits) = &form_elements($dom,$showcredits);
1.2 raeburn 325: my $elementsref = {};
1.66 raeburn 326: if ((ref($elements) eq 'HASH') && (ref($elements->{$action}) eq 'HASH')) {
327: if (ref($elements->{$action}{$state}) eq 'HASH') {
328: $elementsref = $elements->{$action}{$state};
1.2 raeburn 329: }
330: }
1.16 raeburn 331: if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
332: $env{'form.clonedom'} = $dom;
333: }
1.30 raeburn 334: if ($state eq 'crstype') {
335: $jscript = &mainmenu_javascript();
336: } else {
337: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
1.45 raeburn 338: if ($state eq 'courseinfo') {
339: $jscript .= &cloning_javascript();
1.84 raeburn 340: } elsif ($state eq 'process') {
341: $jscript .= &processing_javascript();
1.45 raeburn 342: }
1.30 raeburn 343: }
1.2 raeburn 344: }
345:
346: if ($state eq 'personnel') {
347: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
348: }
349:
350: my $loaditems = &onload_action($action,$state);
351:
1.1 raeburn 352: if ($action eq 'new') {
353: if ($canreq) {
354: if ($state eq 'crstype') {
1.3 raeburn 355: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
1.72 raeburn 356: $crumb,\@incdoms);
1.1 raeburn 357: } else {
1.27 raeburn 358: &request_administration($r,$action,$state,$page,\%states,$dom,
359: $jscript,$loaditems,$crumb,$newinstcode,
1.36 raeburn 360: $codechk,$checkedcode,$description,
1.66 raeburn 361: $showcredits,$instcredits,\@invalidcrosslist);
1.1 raeburn 362: }
363: } else {
1.40 raeburn 364: $r->print(&header('Course/Community Requests').$crumb.
1.1 raeburn 365: '<div class="LC_warning">'.
1.40 raeburn 366: &mt('You do not have privileges to request creation of courses or communities.').
1.2 raeburn 367: '</div>'.&Apache::loncommon::end_page());
1.1 raeburn 368: }
369: } elsif ($action eq 'view') {
1.10 raeburn 370: if ($state eq 'crstype') {
1.72 raeburn 371: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\@incdoms);
1.26 raeburn 372: } else {
373: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.66 raeburn 374: $loaditems,$crumb,'','','','',$showcredits);
1.26 raeburn 375: }
376: } elsif ($action eq 'display') {
377: if ($warning ne '') {
378: my $args = { only_body => 1 };
1.49 raeburn 379: $r->print(&header('Course/Community Requests','','' ,'',$args).$crumb.
1.40 raeburn 380: '<h3>'.&mt('Course/Community Request Details').'</h3>'.
1.26 raeburn 381: '<div class="LC_warning">'.$warning.'</div>'.
382: &close_popup_form());
1.11 raeburn 383: } else {
1.26 raeburn 384: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.66 raeburn 385: $loaditems,$crumb,'','','','',$showcredits,'','',
386: $uname,$udom);
1.10 raeburn 387: }
1.1 raeburn 388: } elsif ($action eq 'log') {
1.48 raeburn 389: if ($state eq 'crstype') {
1.72 raeburn 390: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\@incdoms);
1.48 raeburn 391: } else {
392: $jscript .= <<ENDJS;
393:
394: function backPage(formname,prevstate) {
395: formname.state.value = prevstate;
396: formname.submit();
397: }
398:
399: function setPage(formname) {
400: formname.page.value = '1';
401: return;
402: }
403:
404: ENDJS
1.73 raeburn 405: &print_request_logs($r,$dom,$jscript,$loaditems,$crumb,\%can_request);
1.48 raeburn 406: }
1.1 raeburn 407: } else {
1.72 raeburn 408: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\@incdoms);
1.1 raeburn 409: }
410: return OK;
411: }
412:
1.30 raeburn 413: sub mainmenu_javascript {
414: return <<"END";
415: function setType(courseForm) {
416: for (var i=0; i<courseForm.crstype.length; i++) {
417: if (courseForm.crstype.options[i].value == "$env{'form.crstype'}") {
418: courseForm.crstype.options[i].selected = true;
419: } else {
420: courseForm.crstype.options[i].selected = false;
421: }
422: }
423: }
424:
425: function setAction(courseForm) {
426: for (var i=0; i<courseForm.action.length; i++) {
427: if (courseForm.action.options[i].value == "$env{'form.action'}") {
428: courseForm.action.options[i].selected = true;
429: } else {
430: courseForm.action.options[i].selected = false;
431: }
432: }
433: }
434: END
435: }
436:
1.45 raeburn 437: sub cloning_javascript {
438: return <<"END";
439: function setCloneDisplay(courseForm) {
440: if (courseForm.cloning.length > 1) {
441: for (var i=0; i<courseForm.cloning.length; i++) {
442: if (courseForm.cloning[i].checked) {
443: if (courseForm.cloning[i].value == 1) {
1.84 raeburn 444: document.getElementById('cloneoptions').style.display="block";
1.45 raeburn 445: }
446: }
447: }
448: }
449: }
450: END
451: }
452:
1.84 raeburn 453: sub processing_javascript {
454: return <<"END";
455: function hideProcessing() {
456: if (document.getElementById('processing')) {
457: document.getElementById('processing').style.display="none";
458: }
459: }
460:
461: END
462: }
463:
1.27 raeburn 464: sub get_breadcrumbs {
465: my ($dom,$action,$state,$states,$trail) = @_;
1.36 raeburn 466: my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description);
1.27 raeburn 467: my $page = 0;
468: if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) {
469: if (defined($action)) {
470: my $done = 0;
471: my $i=0;
472: if (ref($states->{$action}) eq 'ARRAY') {
473: while ($i<@{$states->{$action}} && !$done) {
474: if ($states->{$action}[$i] eq $$state) {
475: $page = $i;
476: $done = 1;
477: }
478: $i++;
479: }
480: }
481: if ($env{'form.crstype'} eq 'official') {
482: if ($page > 1) {
483: if ($states->{$action}[$page-1] eq 'codepick') {
484: if ($env{'form.instcode'} eq '') {
485: ($newinstcode,$numtitles) = &get_instcode($dom);
486: if ($numtitles) {
487: if ($newinstcode eq '') {
488: $$state = 'codepick';
489: $page --;
490: } else {
1.36 raeburn 491: ($codechk,$description) =
1.27 raeburn 492: &Apache::lonnet::auto_validate_instcode('',
493: $dom,$newinstcode);
494: if ($codechk ne 'valid') {
495: $$state = 'codepick';
496: $page --;
497: }
498: $checkedcode = 1;
499: }
500: }
501: }
502: }
503: }
504: }
1.85 raeburn 505: if (ref($states->{$action}) eq 'ARRAY') {
506: for (my $i=0; $i<@{$states->{$action}}; $i++) {
507: if ($$state eq $states->{$action}[$i]) {
1.27 raeburn 508: &Apache::lonhtmlcommon::add_breadcrumb(
1.85 raeburn 509: {text=>"$trail->{$$state}"});
510: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
511: last;
1.27 raeburn 512: } else {
1.85 raeburn 513: if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) {
514: &Apache::lonhtmlcommon::add_breadcrumb(
515: { href => '/adm/requestcourse',
516: text => "$trail->{$states->{$action}[$i]}",
517: }
518: );
519: } else {
520: &Apache::lonhtmlcommon::add_breadcrumb(
1.27 raeburn 521: { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')",
522: text => "$trail->{$states->{$action}[$i]}", }
1.85 raeburn 523: );
524: }
525: }
526: }
527: }
1.27 raeburn 528: } else {
529: &Apache::lonhtmlcommon::add_breadcrumb(
530: {text=>'Pick Action'});
1.40 raeburn 531: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
1.27 raeburn 532: }
533: } else {
534: &Apache::lonhtmlcommon::add_breadcrumb(
535: {text=>'Pick Action'});
1.40 raeburn 536: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
1.27 raeburn 537: }
1.36 raeburn 538: return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
1.27 raeburn 539: }
540:
1.2 raeburn 541: sub header {
1.26 raeburn 542: my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
1.2 raeburn 543: if ($jscript) {
1.6 raeburn 544: $jscript = '<script type="text/javascript">'."\n".
545: '// <![CDATA['."\n".
546: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
1.2 raeburn 547: }
548: if ($loaditems) {
1.26 raeburn 549: if (ref($args) eq 'HASH') {
550: my %loadhash = (
551: 'add_entries' => $loaditems,
552: );
553: my %arghash = (%loadhash,%{$args});
554: $args = \%arghash;
555: } else {
556: $args = {'add_entries' => $loaditems,};
557: }
1.3 raeburn 558: }
1.26 raeburn 559: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
1.2 raeburn 560: }
561:
562: sub form_elements {
1.66 raeburn 563: my ($dom,$showcredits) = @_;
564: my $instcredits;
1.2 raeburn 565: my %elements =
566: (
567: new => {
568: crstype => {
569: crstype => 'selectbox',
570: action => 'selectbox',
1.16 raeburn 571: origcnum => 'hidden',
1.2 raeburn 572: },
573: courseinfo => {
574: cdescr => 'text',
1.45 raeburn 575: cloning => 'radio',
1.13 raeburn 576: clonecrs => 'text',
577: clonedom => 'selectbox',
1.2 raeburn 578: datemode => 'radio',
579: dateshift => 'text',
1.109 raeburn 580: tinyurls => 'radio',
1.2 raeburn 581: },
582: enrollment => {
1.13 raeburn 583: accessstart_month => 'selectbox',
584: accessstart_hour => 'selectbox',
585: accessend_month => 'selectbox',
586: accessend_hour => 'selectbox',
587: accessstart_day => 'text',
588: accessstart_year => 'text',
589: accessstart_minute => 'text',
590: accessstart_second => 'text',
591: accessend_day => 'text',
592: accessend_year => 'text',
593: accessend_minute => 'text',
594: accessend_second => 'text',
1.2 raeburn 595: no_end_date => 'checkbox',
596: },
597: personnel => {
598: addperson => 'checkbox',
599: },
1.13 raeburn 600: review => {
601: cnum => 'hidden',
602: },
1.2 raeburn 603: },
604: view => {
605: crstype => {
606: crstype => 'selectbox',
607: action => 'selectbox',
608: },
609: },
610: );
1.13 raeburn 611: my %servers = &Apache::lonnet::get_servers($dom,'library');
612: my $numlib = keys(%servers);
613: if ($numlib > 1) {
614: $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
615: } else {
616: $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
617: }
1.2 raeburn 618: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
619: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
620: \%cat_order,\@code_order);
621: my $numtitles = scalar(@codetitles);
622: if ($numtitles) {
623: my %extras;
624: $lastitem = pop(@codetitles);
625: $extras{'instcode_'.$lastitem} = 'text';
626: foreach my $item (@codetitles) {
627: $extras{'instcode_'.$item} = 'selectbox';
628: }
629: $elements{'new'}{'codepick'} = \%extras;
630: }
631: if (&Apache::lonnet::auto_run('',$dom)) {
632: my %extras = (
1.13 raeburn 633: enrollstart_month => 'selectbox',
634: enrollstart_hour => 'selectbox',
635: enrollend_month => 'selectbox',
636: enrollend_hour => 'selectbox',
637: enrollstart_day => 'text',
638: enrollstart_year => 'text',
639: enrollstart_minute => 'text',
640: enrollstart_second => 'text',
641: enrollend_day => 'text',
642: enrollend_year => 'text',
643: enrollend_minute => 'text',
644: enrollend_second => 'text',
1.2 raeburn 645: addcrosslist => 'checkbox',
646: autoadds => 'radio',
647: autodrops => 'radio',
1.61 raeburn 648: );
649: my ($instcode,$titlescount) = &get_instcode($dom);
650: if ($instcode) {
651: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
652: if (@sections) {
653: $extras{'sectotal'} = 'hidden';
654: if ($env{'form.sectotal'} > 0) {
655: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
656: $extras{'sec_'.$i} = 'radio';
657: $extras{'secnum_'.$i} = 'text';
658: $extras{'loncapasec_'.$i} = 'text';
659: }
660: }
661: } else {
662: $extras{'addsection'} = 'checkbox';
663: my $sectotal = $env{'form.sectotal'};
664: if ($env{'form.addsection'}) {
665: $sectotal ++;
666: }
667: for (my $i=0; $i<$sectotal; $i++) {
668: $extras{'sec_'.$i} = 'checkbox';
669: $extras{'secnum_'.$i} = 'text',
670: $extras{'loncapasec_'.$i} = 'text',
671: }
1.2 raeburn 672: }
1.66 raeburn 673: (my $outcome,my $desc,$instcredits) =
674: &Apache::lonnet::auto_validate_instcode(undef,$dom,$instcode);
675: if ($showcredits && $instcredits eq '') {
676: $extras{'coursecredits'} = 'text';
677: }
1.69 raeburn 678: } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
1.66 raeburn 679: if ($showcredits) {
680: $extras{'coursecredits'} = 'text';
681: }
1.2 raeburn 682: }
683: my $crosslisttotal = $env{'form.crosslisttotal'};
1.16 raeburn 684: if ($env{'form.addcrosslist'}) {
685: $crosslisttotal ++;
686: }
1.24 raeburn 687: if (!$crosslisttotal) {
1.2 raeburn 688: $crosslisttotal = 1;
689: }
1.24 raeburn 690: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
691: if ($numtitles) {
692: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
693: }
694: if (@codetitles > 0) {
695: foreach my $item (@codetitles) {
696: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
1.2 raeburn 697: }
698: }
1.24 raeburn 699: $extras{'crosslist_'.$i} = 'checkbox';
700: $extras{'crosslist_'.$i.'_instsec'} = 'text',
701: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
1.2 raeburn 702: }
703: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
704: %{$elements{'new'}{'enrollment'}} = %mergedhash;
705: }
706: my %people;
707: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 708: if ($env{'form.addperson'}) {
709: $persontotal ++;
710: }
711: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 712: $persontotal = 1;
713: }
714: for (my $i=0; $i<$persontotal; $i++) {
1.13 raeburn 715: $people{'person_'.$i.'_uname'} = 'text',
716: $people{'person_'.$i.'_dom'} = 'selectbox',
717: $people{'person_'.$i.'_hidedom'} = 'hidden',
718: $people{'person_'.$i.'_firstname'} = 'text',
719: $people{'person_'.$i.'_lastname'} = 'text',
720: $people{'person_'.$i.'_emailaddr'} = 'text',
721: $people{'person_'.$i.'_role'} = 'selectbox',
722: $people{'person_'.$i.'_sec'} = 'selectbox',
723: $people{'person_'.$i.'_newsec'} = 'text',
1.2 raeburn 724: }
725: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
726: %{$elements{'new'}{'personnel'}} = %personnelhash;
1.66 raeburn 727: return (\%elements,$instcredits);;
1.2 raeburn 728: }
729:
730: sub onload_action {
731: my ($action,$state) = @_;
732: my %loaditems;
733: if (($action eq 'new') || ($action eq 'view')) {
1.30 raeburn 734: if ($state eq 'crstype') {
735: $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
736: } else {
1.45 raeburn 737: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);';
738: }
739: if ($state eq 'courseinfo') {
740: $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);';
1.30 raeburn 741: }
1.84 raeburn 742: if ($state eq 'process') {
743: $loaditems{'onload'} .= 'javascript:hideProcessing();';
744: }
1.2 raeburn 745: }
746: return \%loaditems;
747: }
748:
1.1 raeburn 749: sub print_main_menu {
1.72 raeburn 750: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$incdoms) = @_;
1.37 raeburn 751: my ($types,$typename) = &Apache::loncommon::course_types();
1.52 bisitz 752: my $onchange = 'this.form.submit()';
1.2 raeburn 753: my $nextstate_setter = "\n";
754: if (ref($states) eq 'HASH') {
755: foreach my $key (keys(%{$states})) {
756: if (ref($states->{$key}) eq 'ARRAY') {
757: $nextstate_setter .=
758: " if (actionchoice == '$key') {
759: nextstate = '".$states->{$key}[1]."';
760: }
761: ";
762: }
763: }
764: }
1.1 raeburn 765:
1.2 raeburn 766: my $js = <<"END";
1.1 raeburn 767:
1.2 raeburn 768: function nextPage(formname) {
1.27 raeburn 769: var crschoice = document.mainmenu_coursetype.crstype.value;
770: var actionchoice = document.mainmenu_action.action.value;
1.2 raeburn 771: if (check_can_request(crschoice,actionchoice) == true) {
772: if ((actionchoice == 'new') && (crschoice == 'official')) {
773: nextstate = 'codepick';
774: } else {
775: $nextstate_setter
1.27 raeburn 776: }
777: formname.crstype.value = crschoice;
778: formname.action.value = actionchoice;
1.1 raeburn 779: formname.state.value= nextstate;
780: formname.submit();
781: }
782: return;
783: }
784:
1.2 raeburn 785: function check_can_request(crschoice,actionchoice) {
1.1 raeburn 786: var official = '';
787: var unofficial = '';
1.69 raeburn 788: var community = '';
789: var textbook = '';
1.96 raeburn 790: var placement = '';
1.1 raeburn 791: END
1.39 raeburn 792: if (ref($can_request) eq 'HASH') {
793: foreach my $item (keys(%{$can_request})) {
794: $js .= "
1.1 raeburn 795: $item = 1;
796: ";
1.39 raeburn 797: }
1.1 raeburn 798: }
1.89 damieng 799: my %js_lt = &Apache::lonlocal::texthash(
1.1 raeburn 800: official => 'You are not permitted to request creation of an official course in this domain.',
801: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
1.69 raeburn 802: community => 'You are not permitted to request creation of a community in this domain.',
803: textbook => 'You are not permitted to request creation of a textbook course in this domain',
1.96 raeburn 804: placement => 'You are not permitted to request creation of a placement test in this domain',
1.67 raeburn 805: all => 'You must choose a specific course type when making a new course request.',
806: allt => '"All types" is not allowed.',
1.1 raeburn 807: );
1.89 damieng 808: &js_escape(\%js_lt);
1.1 raeburn 809: $js .= <<END;
810: if (crschoice == 'official') {
811: if (official != 1) {
1.89 damieng 812: alert("$js_lt{'official'}");
1.1 raeburn 813: return false;
814: }
815: } else {
816: if (crschoice == 'unofficial') {
817: if (unofficial != 1) {
1.89 damieng 818: alert("$js_lt{'unofficial'}");
1.1 raeburn 819: return false;
820: }
821: } else {
822: if (crschoice == 'community') {
823: if (community != 1) {
1.89 damieng 824: alert("$js_lt{'community'}");
1.1 raeburn 825: return false;
826: }
827: } else {
1.69 raeburn 828: if (crschoice == 'textbook') {
829: if (textbook != 1) {
1.89 damieng 830: alert("$js_lt{'textbook'}");
1.69 raeburn 831: return false;
832: }
833: } else {
1.96 raeburn 834: if (crschoice == 'placement') {
835: if (placement != 1) {
836: alert("$js_lt{'placement'}");
837: return false;
838: }
839: } else {
840: if (actionchoice == 'new') {
841: alert('$js_lt{'all'}'+'\\n'+'$js_lt{'allt'}');
842: return false;
843: }
1.69 raeburn 844: }
845: }
1.1 raeburn 846: }
847: }
848: }
849: return true;
850: }
851: END
1.75 raeburn 852: my ($pagetitle,$pageinfo,$domaintitle,$earlyout);
1.39 raeburn 853: if (ref($can_request) eq 'HASH') {
1.96 raeburn 854: if (($can_request->{'official'}) || ($can_request->{'unofficial'}) || ($can_request->{'textbook'}) || ($can_request->{'placement'})) {
1.39 raeburn 855: if ($can_request->{'community'}) {
856: $pagetitle = 'Course/Community Requests';
857: $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
858: $domaintitle = &mt('Course/Community Domain');
859: } else {
860: $pagetitle = 'Course Requests';
861: $pageinfo = &mt('Request creation of a new course, or review your pending course requests.');
862: $domaintitle = &mt('Course Domain');
863: }
864: } elsif ($can_request->{'community'}) {
1.40 raeburn 865: $pagetitle = 'Community Requests';
866: $pageinfo = &mt('Request creation of a new course, or review your pending requests.');
1.39 raeburn 867: $domaintitle = &mt('Community Domain');
1.75 raeburn 868: } elsif ((ref($incdoms) eq 'ARRAY') && ((@{$incdoms} > 1) ||
869: ((@{$incdoms} == 1) && ($incdoms->[0] ne $dom)))) {
1.39 raeburn 870: $pagetitle = 'Course/Community Requests';
871: $pageinfo = &mt('You do not have rights to request creation of courses in this domain; please choose a different domain.');
872: $domaintitle = &mt('Course/Community Domain');
1.75 raeburn 873: } else {
874: $pagetitle = 'Course/Community Requests';
875: $pageinfo = &mt('You do not have rights to request creation of courses or communities.');
876: $earlyout = 1;
1.39 raeburn 877: }
878: }
879: $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb.
1.75 raeburn 880: '<p>'.$pageinfo.'</p>');
881: if ($earlyout) {
882: $r->print(&Apache::loncommon::end_page());
883: return;
884: }
885: $r->print('<div>'.
1.27 raeburn 886: &Apache::lonhtmlcommon::start_pick_box().
1.39 raeburn 887: &Apache::lonhtmlcommon::row_title($domaintitle).
1.1 raeburn 888: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
1.72 raeburn 889: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms));
1.1 raeburn 890: if (!$onchange) {
891: $r->print(' <input type="submit" name="godom" value="'.
892: &mt('Change').'" />');
893: }
1.39 raeburn 894: unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) {
1.72 raeburn 895: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure(1)."\n".
1.39 raeburn 896: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
897: &Apache::loncommon::end_page());
898: return;
899: }
1.27 raeburn 900: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
1.2 raeburn 901: my $formname = 'requestcrs';
1.1 raeburn 902: my $nexttext = &mt('Next');
1.27 raeburn 903: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
904: <form name="mainmenu_action" method="post" action="">
1.1 raeburn 905: <select size="1" name="action" >
1.2 raeburn 906: <option value="new">'.&mt('New request').'</option>
1.1 raeburn 907: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
908: <option value="log">'.&mt('View request history').'</option>
1.27 raeburn 909: </select></form>'.
1.46 wenzelju 910: &Apache::lonhtmlcommon::row_closure().
1.39 raeburn 911: &Apache::lonhtmlcommon::row_title(&mt('Type')).'
1.27 raeburn 912: <form name="mainmenu_coursetype" method="post" action="">
1.39 raeburn 913: <select size="1" name="crstype">');
914: if (ref($can_request) eq 'HASH') {
915: if (keys(%{$can_request}) > 1) {
916: $r->print(' <option value="any">'.&mt('All types').'</option>');
917: }
918: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
919: foreach my $type (@{$types}) {
920: next unless($can_request->{$type});
921: my $selected = '';
922: if ($env{'form.crstype'} eq '') {
923: if ($type eq 'official') {
924: $selected = ' selected="selected"';
925: }
926: } else {
927: if ($type eq $env{'form.crstype'}) {
928: $selected = ' selected="selected"';
929: }
930: }
931: $r->print('<option value="'.$type.'"'.$selected.'>'.&mt($typename->{$type}).
932: '</option>'."\n");
1.4 raeburn 933: }
934: }
935: }
1.27 raeburn 936: $r->print('</select></form>'."\n".
937: &Apache::lonhtmlcommon::row_closure(1)."\n".
938: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
1.38 raeburn 939: '<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'."\n".
1.27 raeburn 940: '<input type="hidden" name="state" value="crstype" />'."\n".
941: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
942: '<input type="hidden" name="crstype" value="" />'."\n".
943: '<input type="hidden" name="action" value="" />'."\n".
944: '<input type="button" name="next" value="'.$nexttext.
945: '" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
946: '</form></div>');
1.1 raeburn 947: $r->print(&Apache::loncommon::end_page());
948: return;
949: }
950:
951: sub request_administration {
1.27 raeburn 952: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
1.66 raeburn 953: $newinstcode,$codechk,$checkedcode,$description,$showcredits,
954: $instcredits,$invalidcrosslist,$uname,$udom) = @_;
1.2 raeburn 955: my $js;
1.16 raeburn 956: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
1.2 raeburn 957: $js = <<END;
1.1 raeburn 958:
959: function nextPage(formname,nextstate) {
960: formname.state.value= nextstate;
961: formname.submit();
962: }
1.16 raeburn 963:
964: END
965: }
966: if (($action eq 'new') || ($action eq 'view')) {
967: $js .= <<END;
968:
1.1 raeburn 969: function backPage(formname,prevstate) {
970: formname.state.value = prevstate;
971: formname.submit();
972: }
973:
974: END
1.2 raeburn 975: }
976: if ($action eq 'new') {
977: my $jsextra;
1.54 raeburn 978: if (($state eq 'courseinfo') || ($state eq 'codepick')) {
1.87 raeburn 979: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom,'','','','','',
980: $newinstcode);
1.31 raeburn 981: } elsif ($state eq 'enrollment') {
982: if (($env{'form.crstype'} eq 'official') &&
983: (&Apache::lonnet::auto_run('',$dom))) {
984: $js .= "\n".§ion_check_javascript()."\n".&enrollment_lcsec_js();
985: }
986: } elsif ($state eq 'personnel') {
987: $js .= "\n".§ion_check_javascript()."\n".&personnel_lcsec_js();
1.1 raeburn 988: }
1.40 raeburn 989: my $title;
990: if ($env{'form.crstype'} eq 'community') {
991: $title = 'Request a community';
992: } else {
993: $title = 'Request a course';
994: }
995: $r->print(&header($title,$js.$jscript,$loaditems,$jsextra).$crumb);
1.27 raeburn 996: &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
1.66 raeburn 997: $codechk,$checkedcode,$description,$showcredits,
998: $instcredits,$invalidcrosslist);
1.2 raeburn 999: } elsif ($action eq 'view') {
1.16 raeburn 1000: my $jsextra;
1001: my $formname = 'requestcrs';
1002: my $prev = $states->{$action}[$page-1];
1003: my $next = $states->{$action}[$page+1];
1004: if ($state eq 'pick_request') {
1005: $next = $states->{$action}[$page+1];
1006: $jsextra = &viewrequest_javascript($formname,$next);
1007: } elsif ($state eq 'details') {
1008: $jsextra = &viewdetails_javascript($formname);
1009:
1010: } elsif ($state eq 'cancel') {
1011: $jsextra = &viewcancel_javascript($formname);
1012: }
1.40 raeburn 1013: my $title;
1014: if ($env{'form.crstype'} eq 'community') {
1015: $title = 'Manage community requests';
1016: } else {
1017: $title = 'Manage course requests';
1018: }
1019: $r->print(&header($title,$js.$jscript.$jsextra,$loaditems).$crumb);
1.16 raeburn 1020: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
1.11 raeburn 1021: if ($state eq 'pick_request') {
1.40 raeburn 1022: my $title;
1023: if ($env{'form.crstype'} eq 'community') {
1024: $title = &mt('Pending community requests');
1025: } elsif ($env{'form.crstype'} eq 'official') {
1026: $title = &mt('Pending requests for official courses');
1027: } elsif ($env{'form.crstype'} eq 'unofficial') {
1028: $title = &mt('Pending requests for unofficial courses');
1.69 raeburn 1029: } elsif ($env{'form.crstype'} eq 'textbook') {
1030: $title = &mt('Pending requests for textbook courses');
1.96 raeburn 1031: } elsif ($env{'form.crstype'} eq 'textbook') {
1032: $title = &mt('Pending requests for placement tests');
1.40 raeburn 1033: } else {
1034: $title = &mt('Pending course/community requests');
1035: }
1036: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.48 raeburn 1037: &print_request_status($dom,$action).'</form></div>');
1.16 raeburn 1038: } elsif ($state eq 'details') {
1039: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1040: my $origcnum = $env{'form.cnum'};
1041: if ($origcnum eq '') {
1042: $origcnum = $env{'form.origcnum'};
1043: }
1044: if ($env{'form.crstype'} eq 'official') {
1045: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1046: \%cat_order,\@code_order);
1047: }
1.40 raeburn 1048: my $title;
1049: if ($env{'form.crstype'} eq 'community') {
1050: $title = &mt('Community Request Details');
1051: } else {
1052: $title = &mt('Course Request Details');
1053: }
1054: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.26 raeburn 1055: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.66 raeburn 1056: \@code_order,'','','','',$instcredits)."\n".
1.16 raeburn 1057: '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
1.66 raeburn 1058: my @excluded = &get_excluded_elements($dom,$states,'new','review',
1059: $showcredits);
1.16 raeburn 1060: push(@excluded,'origcnum');
1061: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
1062: my $other = 'modify';
1063: my %navtxt = &Apache::lonlocal::texthash (
1064: prev => 'Back',
1065: other => 'Modify Request',
1066: next => 'Cancel Request',
1067: );
1.31 raeburn 1068: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1069: $navtxt{'next'},$state,$other,$navtxt{'other'});
1.16 raeburn 1070: $r->print('</form>');
1071: } elsif ($state eq 'cancel') {
1.40 raeburn 1072: my $title;
1073: if ($env{'form.crstype'} eq 'community') {
1074: $title = &mt('Cancel community request');
1075: } else {
1076: $title = &mt('Cancel course request');
1077: }
1.16 raeburn 1078: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
1.40 raeburn 1079: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.16 raeburn 1080: $output);
1.66 raeburn 1081: my @excluded = &get_excluded_elements($dom,$states,'view','cancel',
1082: $showcredits);
1.16 raeburn 1083: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
1084: my %navtxt = &Apache::lonlocal::texthash (
1085: prev => 'Back',
1086: next => 'Confirm Cancellation',
1087: );
1088: if ($result eq 'ok') {
1.31 raeburn 1089: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1.16 raeburn 1090: $navtxt{'next'},$state);
1091: } else {
1.31 raeburn 1092: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef,
1093: '',$state);
1.16 raeburn 1094: }
1095: $r->print('</form>');
1096: } elsif ($state eq 'removal') {
1097: my $cnum = $env{'form.origcnum'};
1098: my $statuskey = 'status:'.$dom.':'.$cnum;
1099: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
1100: $env{'user.domain'},$env{'user.name'});
1101: my $currstatus = $userreqhash{$statuskey};
1102: my ($result,$error);
1103: if (($currstatus eq 'approval') || ($currstatus eq 'pending')) {
1104: my %status = (
1105: $statuskey => 'cancelled',
1106: );
1107: my $statusresult = &Apache::lonnet::put('courserequests',\%status);
1108: if ($statusresult eq 'ok') {
1109: my $delresult =
1110: &Apache::lonnet::del_dom('courserequestqueue',
1111: [$cnum.'_'.$currstatus],$dom);
1112: if ($delresult eq 'ok') {
1113: $result = 'ok';
1114: } else {
1115: $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
1116: }
1117: } else {
1118: $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
1119: }
1120: } else {
1121: $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');
1122: }
1123: $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
1124: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
1125: '<input type="hidden" name="action" value="'.$action.'" />'."\n".
1126: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
1127: '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
1128: if ($result eq 'ok') {
1.40 raeburn 1129: if ($env{'form.crstype'} eq 'community') {
1130: $r->print(&mt('Your community request has been cancelled.'));
1131: } else {
1132: $r->print(&mt('Your course request has been cancelled.'));
1133: }
1.16 raeburn 1134: } else {
1135: $r->print('<div class="LC_error">'.
1136: &mt('The request cancellation process was not complete.').
1137: '<br />'.$error.'</div>');
1138: }
1139: $r->print('</form>');
1.11 raeburn 1140: }
1.26 raeburn 1141: } elsif ($action eq 'display') {
1142: my $formname = 'requestcrs';
1143: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1144: if ($env{'form.crstype'} eq 'official') {
1145: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1146: \%cat_order,\@code_order);
1147: }
1.40 raeburn 1148: my ($title,$header);
1149: if ($env{'form.crstype'} eq 'community') {
1150: $title = 'Community Request';
1151: $header = &mt('Community Request');
1152: } else {
1153: $title = 'Course Request';
1154: $header = &mt('Course Request');
1155: }
1156: $r->print(&header($title,'','','',{ 'only_body' => 1}).
1157: $crumb."\n".'<h3>'.$header.'</h3>'.
1.26 raeburn 1158: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.66 raeburn 1159: \@code_order,$uname,$udom,'','',$instcredits)."\n".
1160: '</div>'.
1.26 raeburn 1161: &close_popup_form());
1.1 raeburn 1162: }
1.2 raeburn 1163: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 1164: return;
1165: }
1166:
1.83 raeburn 1167: sub domcoord_display {
1168: my ($dom) = @_;
1169: my ($uname,$udom,$result,$warning);
1170: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
1171: if ($env{'form.cnum'} ne '') {
1172: my $cnum = $env{'form.cnum'};
1173: my $queue = $env{'form.queue'};
1174: my $reqkey = $cnum.'_'.$queue;
1175: my $namespace = 'courserequestqueue';
1176: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
1177: my %queued =
1178: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
1179: if (ref($queued{$reqkey}) eq 'HASH') {
1180: $uname = $queued{$reqkey}{'ownername'};
1181: $udom = $queued{$reqkey}{'ownerdom'};
1182: if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
1183: $result = &retrieve_settings($dom,$cnum,$udom,$uname);
1184: } else {
1185: if ($env{'form.crstype'} eq 'community') {
1186: $warning = &mt('Invalid username or domain for community requestor');
1187: } else {
1188: $warning = &mt('Invalid username or domain for course requestor');
1189: }
1190: }
1191: } else {
1192: if ($env{'form.crstype'} eq 'community') {
1193: $warning = &mt('No information was found for this community request.');
1194: } else {
1195: $warning = &mt('No information was found for this course request.');
1196: }
1197: }
1198: } else {
1199: $warning = &mt('No course request ID provided.');
1200: }
1201: } else {
1202: if ($env{'form.crstype'} eq 'any') {
1203: $warning = &mt('You do not have rights to view course or community request information.');
1204: } elsif ($env{'form.crstype'} eq 'community') {
1205: $warning = &mt('You do not have rights to view community request information.');
1206: } else {
1207: $warning = &mt('You do not have rights to view course request information.');
1208: }
1209: }
1210: return ($uname,$udom,$result,$warning);
1211: }
1212:
1.31 raeburn 1213: sub enrollment_lcsec_js {
1214: my %alerts = §ion_check_alerts();
1215: my $secname = $alerts{'badsec'};
1216: my $secnone = $alerts{'reserved'};
1.89 damieng 1217: &js_escape(\$secname);
1218: &js_escape(\$secnone);
1.31 raeburn 1219: my $output = '
1220: function validateEnrollSections(formname,nextstate) {
1221: var badsectotal = 0;
1222: var reservedtotal = 0;
1223: var secTest = "";
1224: ';
1225: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1226: $output .= "
1227: var selSec = 0;
1228: for (var j=0; j<document.requestcrs.sec_".$i.".length; j++) {
1229: if (document.requestcrs.sec_".$i."[j].checked) {
1230: selSec = document.requestcrs.sec_".$i."[j].value;
1231: }
1232: if (selSec == 1) {
1233: secTest = validsection(document.requestcrs.loncapasec_".$i.");
1234: if (secTest == 'badsec') {
1235: badsectotal++;
1236: }
1237: if (secTest == 'reserved') {
1238: reservedtotal++;
1239: }
1240: }
1241: }
1242: ";
1243: }
1244: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1245: $output .= "
1246: if (document.requestcrs.crosslist_".$i.".checked) {
1247: secTest = validsection(document.requestcrs.crosslist_".$i."_lcsec);
1248: if (secTest == 'badsec') {
1249: badsectotal++;
1250: }
1251: if (secTest == 'reserved') {
1252: reservedtotal++;
1253: }
1254: }
1255: ";
1256: }
1257: $output .= "
1258: if (badsectotal>0) {
1259: alert('$secname');
1260: return false;
1261: }
1262: if (reservedtotal>0) {
1263: alert('$secnone');
1264: return false;
1265: }
1266: formname.state.value= nextstate;
1267: formname.submit();
1268: return;
1269: }
1270: ";
1271: return $output;
1272: }
1273:
1274: sub personnel_lcsec_js {
1275: my %alerts = §ion_check_alerts();
1.89 damieng 1276: my $secname = $alerts{'badsec'}."\n".$alerts{'separate'};
1.31 raeburn 1277: my $secnone = $alerts{'reserved'};
1.89 damieng 1278: &js_escape(\$secname);
1279: &js_escape(\$secnone);
1.31 raeburn 1280: my $output = '
1281: function validatePersonnelSections(formname,nextstate) {
1282: var badsectotal = 0;
1283: var reservedtotal = 0;
1284: var secTest = "";
1285: ';
1286: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1287: $output .= "
1288: if (document.requestcrs.person_".$i."_uname.value != '') {
1289: secTest = validsection(document.requestcrs.person_".$i."_newsec,'1');
1290: if (secTest == 'badsec') {
1291: badsectotal++;
1292: }
1293: if (secTest == 'reserved') {
1294: reservedtotal++;
1295: }
1296: }
1297: ";
1298: }
1299: $output .= "
1300: if (badsectotal > 0) {
1301: alert('$secname');
1302: return false;
1303: } else {
1304: if (reservedtotal > 0) {
1305: alert('$secnone');
1306: return false;
1307: }
1308: }
1309: formname.state.value = nextstate;
1310: formname.submit();
1311: return;
1312: }
1313: ";
1314: return $output;
1315: }
1316:
1317: sub section_check_alerts {
1318: my %lt =
1319: &Apache::lonlocal::texthash(
1320: reserved => "You need to change one or more LON-CAPA section names - none is a reserved word in the system, and may not be used.",
1321: badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
1322: separate => 'Separate multiple sections with a comma.'
1323: );
1324: return %lt;
1325: }
1326:
1327: sub section_check_javascript {
1328: return <<"END";
1329: function validsection(field,mult) {
1330: var str = field.value;
1331: var badsec=0;
1332: var reserved=0;
1333: if (window.RegExp) {
1334: var badsecnum=0;
1335: var reservednum=0;
1336: var pattern=/[^a-zA-Z0-9]/;
1337: str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
1338: str = str.replace(/[ ]{2,}/gi," ");
1339: if (mult == '1') {
1340: var sections = new Array();
1341: sections = str.split(/\\s*[\\s,;:]\\s*/);
1342: var i;
1343: for (i=0; i<sections.length; i++) {
1344: if ((sections[i] != '') && (sections[i] != undefined) && (sections[i] != null)) {
1345: if (pattern.test(sections[i])) {
1346: badsecnum++;
1347: } else {
1348: if (sections[i] == 'none') {
1349: reservednum++;
1350: }
1351: }
1352: }
1353: }
1354: } else {
1355: if ((str != '') && (str != undefined) && (str != null)) {
1356: if (pattern.test(str)) {
1357: badsecnum++;
1358: } else {
1359: if (str == 'none') {
1360: reservednum++;
1361: }
1362: }
1363: }
1364: }
1365: if (badsecnum > 0) {
1366: return 'badsec';
1367: }
1368: if (reservednum > 0) {
1369: return 'reserved';
1370: }
1371: }
1372: return;
1373: }
1374: END
1375: }
1376:
1.26 raeburn 1377: sub close_popup_form {
1378: my $close= &mt('Close Window');
1379: return << "END";
1380: <p><form name="displayreq" action="" method="post">
1381: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
1382: </form></p>
1383: END
1384: }
1385:
1.27 raeburn 1386: sub get_instcode {
1387: my ($dom) = @_;
1388: my ($instcode,$numtitles);
1389: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1390: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1391: \%cat_order,\@code_order);
1392: $numtitles = scalar(@codetitles);
1393: if (@code_order > 0) {
1394: my $message;
1395: foreach my $item (@code_order) {
1396: $instcode .= $env{'form.instcode_'.$item};
1397: }
1398: }
1399: return ($instcode,$numtitles);
1400: }
1401:
1.1 raeburn 1402: sub print_request_form {
1.27 raeburn 1403: my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
1.66 raeburn 1404: $description,$showcredits,$instcredits,$invalidcrosslist) = @_;
1.1 raeburn 1405: my $formname = 'requestcrs';
1.2 raeburn 1406: my ($next,$prev,$message,$output,$codepicker,$crstype);
1407: $prev = $states->{$action}[$page-1];
1408: $next = $states->{$action}[$page+1];
1.4 raeburn 1409: my %navtxt = &Apache::lonlocal::texthash (
1.10 raeburn 1410: prev => 'Back',
1.4 raeburn 1411: next => 'Next',
1412: );
1.2 raeburn 1413: $crstype = $env{'form.crstype'};
1.34 raeburn 1414: $r->print('<br /><form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.30 raeburn 1415: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
1416: @disallowed);
1.1 raeburn 1417: if ($crstype eq 'official') {
1.2 raeburn 1418: if ($env{'form.instcode'} ne '') {
1419: $instcode = $env{'form.instcode'};
1.27 raeburn 1420: } elsif ($newinstcode ne '') {
1421: $instcode = $newinstcode;
1.2 raeburn 1422: }
1.27 raeburn 1423: if ($checkedcode) {
1424: if ($codechk eq 'valid') {
1425: $message = '<div class="LC_info">'.
1426: &mt('The chosen course category [_1] is valid.','<b>'.
1427: $instcode.'</b>').
1428: '<input type="hidden" name="instcode" value="'.
1429: $instcode.'" /></div>';
1.2 raeburn 1430: } else {
1431: $message = '<div class="LC_warning">'.
1.27 raeburn 1432: &mt('No course was found matching your choice of institutional course category.');
1433: if ($codechk ne '') {
1434: $message .= '<br />'.$codechk;
1435: }
1436: $message .= '</div>';
1.2 raeburn 1437: $prev = 'crstype';
1438: }
1439: $r->print($message);
1.1 raeburn 1440: }
1.2 raeburn 1441: }
1442: if ($prev eq 'crstype') {
1.4 raeburn 1443: if ($crstype eq 'official') {
1444: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1445: \%cat_order,\@code_order);
1446: }
1.2 raeburn 1447: if (@code_order > 0) {
1.1 raeburn 1448: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
1449: \%cat_titles,\%cat_order);
1.2 raeburn 1450: if ($codepicker) {
1.34 raeburn 1451: $r->print(&mt('Specify the course to be created.').
1452: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1453: $codepicker.
1.2 raeburn 1454: &Apache::lonhtmlcommon::end_pick_box().'</div>');
1455: } else {
1.20 raeburn 1456: $next = $states->{$action}[$page+2];
1.15 raeburn 1457: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 1458: }
1459: } else {
1.20 raeburn 1460: if ($crstype eq 'official') {
1461: $next = $states->{$action}[$page+2];
1462: }
1.15 raeburn 1463: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.1 raeburn 1464: }
1.2 raeburn 1465: } elsif ($prev eq 'codepick') {
1.27 raeburn 1466: if ($instcode eq '') {
1.20 raeburn 1467: $prev = $states->{$action}[$page-2];
1468: }
1.36 raeburn 1469: $r->print(&courseinfo_form($dom,$formname,$crstype,$next,$description));
1.2 raeburn 1470: } elsif ($state eq 'enrollment') {
1.4 raeburn 1471: if ($crstype eq 'official') {
1472: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1473: \%cat_order,\@code_order);
1474: }
1.2 raeburn 1475: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
1.27 raeburn 1476: \%cat_titles,\%cat_order,\@code_order,
1.66 raeburn 1477: $showcredits,$instcredits,$invalidcrosslist));
1.2 raeburn 1478: } elsif ($state eq 'personnel') {
1.27 raeburn 1479: $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
1.4 raeburn 1480: } elsif ($state eq 'review') {
1.30 raeburn 1481: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
1482: my $now = time;
1483: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1484: my $personname = $env{'form.person_'.$i.'_uname'};
1485: my $persondom = $env{'form.person_'.$i.'_dom'};
1486: if (($personname =~ /^$match_username$/) &&
1487: ($persondom =~ /^$match_domain$/)) {
1488: if (&Apache::lonnet::domain($persondom)) {
1489: my $personhome =
1490: &Apache::lonnet::homeserver($personname,$persondom);
1491: if ($personhome eq 'no_host') {
1492: if ($persondom ne $dom) {
1493: my $skipuser = 1;
1494: if ($env{'user.role.dc./'.$persondom.'/'}) {
1495: my ($start,$end) = split('.',$env{'user.role.dc./'.$persondom.'/'});
1496: if (((!$start) || ($start < $now)) &&
1497: ((!$end) || ($end > $now))) {
1498: $skipuser = 0;
1499: }
1500: }
1501: if ($skipuser) {
1502: push(@disallowed,$i);
1.60 raeburn 1503: $disallowmsg{$i} = &mt('[_1] was excluded because new users need to be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
1.30 raeburn 1504: next;
1505: }
1506: }
1.60 raeburn 1507: my $usertype = &get_usertype($persondom,$personname,\%curr_rules,\%got_rules);
1508: if (&Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype)) {
1509: my ($allowed,$msg,$authtype,$authparam) =
1.30 raeburn 1510: &check_newuser_rules($persondom,$personname,
1511: \%alerts,\%rulematch,\%inst_results,
1512: \%curr_rules,\%got_rules);
1513: if ($allowed) {
1.60 raeburn 1514: my %domdefaults = &Apache::lonnet::get_domain_defaults($persondom);
1515: if ($usertype eq 'official') {
1516: if ($authtype eq '') {
1517: $authtype = $domdefaults{'auth_def'};
1518: $authparam = $domdefaults{'auth_arg_def'};
1519: }
1520: } elsif ($usertype eq 'unofficial') {
1521: if ($authtype eq '') {
1522: $authtype = 'internal';
1523: $authparam = '';
1524: }
1525: } else {
1526: $authtype = $domdefaults{'auth_def'};
1527: $authparam = $domdefaults{'auth_arg_def'};
1528: }
1529: if (($authtype eq '') ||
1530: (($authtype =~/^krb/) && ($authparam eq ''))) {
1531: push(@disallowed,$i);
1532: $disallowmsg{$i} = &mt('[_1] was excluded because institutional information is incomplete for this new user.','<tt>'.$personname.':'.$persondom.'</tt>');
1533: next;
1534: }
1.30 raeburn 1535: if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
1536: if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
1537: $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
1538: }
1539: if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
1540: $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
1541: }
1542: if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
1543: $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
1544: }
1545: }
1546: } else {
1547: push(@disallowed,$i);
1548: $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1549: }
1550: } else {
1551: push(@disallowed,$i);
1552: $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1553: }
1554: } else {
1555: my %userenv =
1556: &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
1557: if ($env{'form.person_'.$i.'_lastname'} eq '') {
1558: $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
1559: }
1560: if ($env{'form.person_'.$i.'_firstname'} eq '') {
1561: $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
1562: }
1563: if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
1564: $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
1565: }
1566: }
1567: } elsif ($personname ne '') {
1568: push(@disallowed,$i);
1569: $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid','<tt>'.$personname.':'.$persondom.'</tt>');
1570: }
1571: } elsif ($personname ne '') {
1572: push(@disallowed,$i);
1573: $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.','<tt>'.$personname.':'.$persondom.'</tt>');
1574: }
1575: }
1.16 raeburn 1576: my $cnum;
1577: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
1578: $cnum = $env{'form.origcnum'};
1579: } else {
1.47 raeburn 1580: my $gentype = 'Course';
1581: if ($crstype eq 'community') {
1582: $gentype = 'Community';
1583: }
1584: $cnum = &Apache::lonnet::generate_coursenum($dom,$gentype);
1.16 raeburn 1585: }
1.4 raeburn 1586: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1587: \%cat_order,\@code_order);
1.40 raeburn 1588: if ($crstype eq 'community') {
1589: $r->print('<h3>'.&mt('Review community request details before submission').'</h3>');
1590: } else {
1591: $r->print('<h3>'.&mt('Review course request details before submission').'</h3>');
1592: }
1.66 raeburn 1593: $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg,$instcredits).
1.16 raeburn 1594: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1.73 raeburn 1595: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
1596: $env{'user.domain'});
1597: my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'review',$env{'user.name'},
1598: $env{'user.domain'},$fullname,$env{'form.cdescr'});
1599: if (ref($postprocess) eq 'HASH') {
1600: if ($postprocess->{'reviewweb'}) {
1601: $r->print($postprocess->{'reviewweb'});
1602: }
1603: }
1.40 raeburn 1604: if ($crstype eq 'community') {
1605: $navtxt{'next'} = &mt('Submit community request');
1606: } else {
1607: $navtxt{'next'} = &mt('Submit course request');
1608: }
1.10 raeburn 1609: } elsif ($state eq 'process') {
1610: if ($crstype eq 'official') {
1611: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1612: \%cat_order,\@code_order);
1613: }
1.78 raeburn 1614: my $lonhost = $r->dir_config('lonHostID');
1.90 raeburn 1615: my ($storeresult,$result,$customized) = &print_request_outcome($r,$lonhost,$dom,\@codetitles,
1616: \@code_order,$instcredits);
1.13 raeburn 1617: $r->print($result);
1.27 raeburn 1618: if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
1619: if ($storeresult eq 'ok') {
1.65 raeburn 1620: $r->print('<p><a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
1621: &mt('Modify this request').'</a>'.(' 'x4).
1622: '<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1623: }
1624: if (&Apache::loncoursequeueadmin::author_prompt()) {
1.90 raeburn 1625: unless ($customized) {
1626: &print_author_prompt($r,$env{'form.action'},$env{'form.cnum'},$env{'form.showdom'},
1627: $env{'form.crstype'},$storeresult);
1628: }
1.65 raeburn 1629: } elsif ($storeresult eq 'created') {
1.90 raeburn 1630: unless ($customized) {
1631: $r->print('<p><a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1632: }
1.65 raeburn 1633: }
1634: }
1635: } elsif ($state eq 'reqauthor') {
1636: my ($result,@links);
1637: if ($env{'form.requestauthor'}) {
1638: $r->print(&Apache::loncoursequeueadmin::process_reqauthor(\$result));
1639: if ($result eq 'created') {
1640: my $role = 'au';
1641: my $spec = "$role./$env{'form.showdom'}/";
1.76 bisitz 1642: push(@links,&mt('Enter your Authoring Space with role: [_1]',
1.65 raeburn 1643: '<a href="/adm/roles?selectrole=1&'.$spec.'=1">'.
1644: &Apache::lonnet::plaintext($role).'</a>'));
1.27 raeburn 1645: }
1.65 raeburn 1646: }
1647: if (($env{'form.disposition'} eq 'created') &&
1648: ($env{'form.cnum'} =~ /^$match_courseid$/) &&
1649: ($env{'form.showdom'} =~ /^$match_domain$/)) {
1650: my ($spec,$area,$role,$type);
1651: my $role = 'cc';
1652: my $spec = "$role./$env{'form.showdom'}/$env{'form.cnum'}";
1653: my $type = 'Course';
1654: if ($env{'form.crstype'} eq 'community') {
1655: $type = 'Community';
1656: }
1657: my $showrole = &Apache::lonnet::plaintext($role,$type);
1658: unshift(@links,&mt('Enter new course with role: [_1]',
1659: '<a href="/adm/roles?selectrole=1&'.$spec.'=1">'.$showrole.'</a>'));
1660: }
1661: if (@links > 1) {
1662: $r->print(&mt('New roles will be listed on your [_1]Roles[_2] page.',
1663: '<a href="/adm/roles">','</a>').' '.&mt('Choose a role:').
1664: '<ul>');
1665: foreach my $link (@links) {
1666: $r->print('<li>'.$link.'</li>');
1667: }
1668: $r->print('</ul>');
1669: } elsif (@links == 1) {
1670: $r->print('<p>'.$links[0].'</p>');
1.27 raeburn 1671: }
1.1 raeburn 1672: }
1.66 raeburn 1673: my @excluded = &get_excluded_elements($dom,$states,$action,$state,$showcredits);
1.24 raeburn 1674: if ($state eq 'personnel') {
1675: push(@excluded,'persontotal');
1676: }
1.30 raeburn 1677: if ($state eq 'review') {
1678: if (@disallowed > 0) {
1679: my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
1680: my @currsecs = ¤t_lc_sections();
1681: if (@currsecs) {
1682: push(@items,'sec');
1683: }
1684: my $count = 0;
1685: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1686: unless ($env{'form.person_'.$i.'_uname'} eq '') {
1687: if (grep(/^$i$/,@disallowed)) {
1688: foreach my $item (@items) {
1689: $env{'form.person_'.$i.'_'.$item} = '';
1690: }
1691: } else {
1692: foreach my $item (@items) {
1693: $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
1694: }
1695: }
1696: }
1697: $count ++;
1698: }
1699: $env{'form.persontotal'} = $count;
1700: }
1701: }
1.27 raeburn 1702: if ($state eq 'enrollment') {
1.61 raeburn 1703: push(@excluded,('sectotal','crosslisttotal'));
1.27 raeburn 1704: }
1.65 raeburn 1705: if (($state eq 'process') || ($state eq 'reqauthor')) {
1706: $r->print('</form>');
1707: } else {
1708: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1709: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1710: $navtxt{'next'},$state);
1711: }
1.16 raeburn 1712: return;
1713: }
1714:
1.72 raeburn 1715: sub print_author_prompt {
1716: my ($r,$action,$cnum,$showdom,$crstype,$storeresult) = @_;
1.76 bisitz 1717: $r->print('<h3>'.&mt('Access to Authoring Space').'</h3>'.
1.72 raeburn 1718: '<p>'.
1719: &mt('Although assessment items can be created directly inside a course, such items only use part of the assessment capabilities of LON-CAPA.').
1720: '<br />'.
1.76 bisitz 1721: &mt('By contrast, items created in Authoring Space, then imported into a course, can use all of the features of the assessment engine.').'</p>'.
1722: '<p>'.&mt('Request Authoring Space access now?').
1.72 raeburn 1723: '<span class="LC_nobreak"> '.
1724: '<label><input type="radio" name="requestauthor" value="1" />'.&mt('Yes').'</label>'.
1725: (' 'x2).
1726: '<label><input type="radio" name="requestauthor" value="0" checked="checked"/>'.&mt('No').'</label>'.
1727: '</span></p>'.
1728: '<input type="submit" name="newauthor" value="'.&mt('Submit authoring request').'" />'.
1729: '<input type="hidden" name="state" value="reqauthor" />'.
1730: '<input type="hidden" name="action" value="'.$action.'" />'.
1731: '<input type="hidden" name="cnum" value="'.$cnum.'" />'.
1732: '<input type="hidden" name="showdom" value="'.$showdom.'" />'.
1733: '<input type="hidden" name="crstype" value="'.$crstype.'" />'.
1734: '<input type="hidden" name="disposition" value="'.$storeresult.'" />'.
1735: '<br />');
1736: }
1737:
1.60 raeburn 1738: sub get_usertype {
1739: my ($persondom,$personname,$curr_rules,$got_rules) = @_;
1.30 raeburn 1740: my ($rules,$ruleorder) =
1741: &Apache::lonnet::inst_userrules($persondom,'username');
1742: my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
1.60 raeburn 1743: $rules,$curr_rules,$got_rules);
1744: return $usertype;
1.30 raeburn 1745: }
1746:
1747: sub check_newuser_rules {
1748: my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
1749: $got_rules) = @_;
1750: my $allowed = 1;
1751: my $newuser = 1;
1.60 raeburn 1752: my ($checkhash,$userchkmsg,$authtype,$authparam);
1.30 raeburn 1753: my $checks = { 'username' => 1 };
1754: $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
1755: &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
1756: $inst_results,$curr_rules,$got_rules);
1757: if (ref($alerts->{'username'}) eq 'HASH') {
1758: if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
1759: my $domdesc =
1760: &Apache::lonnet::domain($persondom,'description');
1761: if ($alerts->{'username'}{$persondom}{$personname}) {
1762: if (ref($curr_rules->{$persondom}) eq 'HASH') {
1763: $userchkmsg =
1764: &Apache::loncommon::instrule_disallow_msg('username',
1765: $domdesc,1).
1766: &Apache::loncommon::user_rule_formats($persondom,
1767: $domdesc,$curr_rules->{$persondom}{'username'},
1768: 'username');
1769: }
1770: $allowed = 0;
1771: }
1772: }
1773: }
1.60 raeburn 1774: if ($allowed) {
1775: if (ref($rulematch) eq 'HASH') {
1776: if (ref($rulematch->{$personname.':'.$persondom}) eq 'HASH') {
1777: my $matchedrule = $rulematch->{$personname.':'.$persondom}{'username'};
1778: my ($rules,$ruleorder) =
1779: &Apache::lonnet::inst_userrules($persondom,'username');
1780: if (ref($rules) eq 'HASH') {
1781: if (ref($rules->{$matchedrule}) eq 'HASH') {
1782: $authtype = $rules->{$matchedrule}{'authtype'};
1783: $authparam = $rules->{$matchedrule}{'authparm'};
1784: }
1785: }
1786: }
1787: }
1788: }
1789: return ($allowed,$userchkmsg,$authtype,$authparam);
1.30 raeburn 1790: }
1791:
1.16 raeburn 1792: sub get_excluded_elements {
1.66 raeburn 1793: my ($dom,$states,$action,$state,$showcredits) = @_;
1.2 raeburn 1794: my @excluded = ('counter');
1.66 raeburn 1795: my ($elements,$instcredits) = &form_elements($dom,$showcredits);
1.2 raeburn 1796: if (ref($states) eq 'HASH') {
1797: if (ref($states->{$action}) eq 'ARRAY') {
1798: my @items = @{$states->{$action}};
1799: my $numitems = scalar(@items);
1800: if ($numitems) {
1801: for (my $i=$numitems-1; $i>=0; $i--) {
1.66 raeburn 1802: if ((ref($elements) eq 'HASH') &&
1803: (ref($elements->{$action}) eq 'HASH')) {
1804: if (ref($elements->{$action}{$items[$i]}) eq 'HASH') {
1805: foreach my $key (keys(%{$elements->{$action}{$items[$i]}})) {
1.2 raeburn 1806: push(@excluded,$key);
1807: }
1808: }
1809: }
1810: last if ($items[$i] eq $state);
1811: }
1812: }
1813: }
1814: }
1815: if (grep(/^instcode_/,@excluded)) {
1816: push(@excluded,'instcode');
1.1 raeburn 1817: }
1.16 raeburn 1818: return @excluded;
1.1 raeburn 1819: }
1820:
1.2 raeburn 1821: sub print_enrollment_menu {
1.27 raeburn 1822: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
1.66 raeburn 1823: $showcredits,$instcredits,$invalidcrosslist) =@_;
1824: my ($sections,$autoenroll,$access_dates,$output,$hasauto,$hascredits,
1825: $creditsrow,$domdefcredits);
1.2 raeburn 1826: my $starttime = time;
1827: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1828:
1829: my %accesstitles = (
1830: 'start' => 'Default start access',
1.16 raeburn 1831: 'end' => 'Default end access',
1.2 raeburn 1832: );
1833: my %enrolltitles = (
1834: 'start' => 'Start auto-enrollment',
1835: 'end' => 'End auto-enrollment',
1836: );
1.66 raeburn 1837: if ($showcredits) {
1838: unless ($env{'form.crstype'} eq 'community') {
1839: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1840: $domdefcredits = $domdefs{$env{'form.crstype'}.'credits'};
1841: }
1842: }
1.2 raeburn 1843: if ($env{'form.crstype'} eq 'official') {
1844: if (&Apache::lonnet::auto_run('',$dom)) {
1.27 raeburn 1845: $output = &show_invalid_crosslists($invalidcrosslist);
1846: my ($section_form,$crosslist_form);
1.61 raeburn 1847: if ($instcode ne '') {
1848: $section_form = &inst_section_selector($dom,$instcode);
1849: if ($section_form eq '') {
1850: my $sectotal = $env{'form.sectotal'};
1851: if (!$sectotal) {
1852: $sectotal = 1;
1853: }
1854: if ($env{'form.addsection'}) {
1855: $sectotal ++;
1856: }
1857: for (my $i=0; $i<$sectotal; $i++) {
1858: $section_form .= §ions_form($dom,$instcode,$i);
1859: }
1860: if ($section_form) {
1861: $section_form .=
1862: &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1863: '<input name="sectotal" type="hidden" value="'.$sectotal.'" />'.
1864: '<input name="addsection" type="checkbox" value="'.$sectotal.'"'.
1865: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1866: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1867: }
1868: }
1869: }
1.27 raeburn 1870: if ($section_form) {
1871: $sections = &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 1872: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
1873: ' '.&mt('Sections for auto-enrollment').'</h3>'.
1.27 raeburn 1874: &Apache::lonhtmlcommon::row_closure(1).
1875: $section_form;
1876: }
1.2 raeburn 1877: my $crosslisttotal = $env{'form.crosslisttotal'};
1.24 raeburn 1878: if (!$crosslisttotal) {
1.2 raeburn 1879: $crosslisttotal = 1;
1880: }
1881: if ($env{'form.addcrosslist'}) {
1882: $crosslisttotal ++;
1883: }
1884: for (my $i=0; $i<$crosslisttotal; $i++) {
1885: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
1886: $cat_titles,$cat_order,$i);
1887: }
1888: if ($crosslist_form) {
1889: $crosslist_form .=
1.40 raeburn 1890: &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2 raeburn 1891: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
1892: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1893: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1.27 raeburn 1894: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1895: $sections .= &Apache::lonhtmlcommon::row_headline.
1.61 raeburn 1896: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Crosslist').' '.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1.27 raeburn 1897: &Apache::lonhtmlcommon::row_closure(1).
1898: $crosslist_form;
1.2 raeburn 1899: }
1.34 raeburn 1900: $hasauto = 1;
1.27 raeburn 1901: $autoenroll =
1.34 raeburn 1902: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').' '.&mt('Add registered students automatically')).
1.2 raeburn 1903: '<span class="LC_nobreak"><label>'.
1904: '<input type="radio" name="autoadds" value="1">'.
1905: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1906: '<input type="radio" name="autoadds" value="0" checked="checked">'.
1907: &mt('No').'</label></span>'.
1.27 raeburn 1908: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1909: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').' '.&mt('Drop unregistered students automatically')).
1.2 raeburn 1910: '<span class="LC_nobreak"><label>'.
1911: '<input type="radio" name="autodrops" value="1">'.
1912: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1913: '<input type="radio" name="autodrops" value="0" checked="checked">'.
1914: &mt('No').'</label></span>'.
1.27 raeburn 1915: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1916: &date_setting_table($starttime,$endtime,$formname,'enroll',
1.66 raeburn 1917: $hasauto,undef,%enrolltitles);
1918: if ($showcredits) {
1919: if ($instcredits) {
1920: $creditsrow = &mt('[quant,_1,credit]',$instcredits);
1921: } else {
1922: $creditsrow = '<span class="LC_nobreak">'.
1923: '<input type="text" size="3" name="coursecredits"'.
1924: ' value="'.$domdefcredits.'" />';
1925: }
1926: $hascredits = 1;
1927: }
1928: }
1.69 raeburn 1929: } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
1.66 raeburn 1930: if ($showcredits) {
1931: $creditsrow = '<span class="LC_nobreak">'.
1932: '<input type="text" size="3" name="coursecredits"'.
1933: ' value="'.$domdefcredits.'"/>';
1934: $hascredits = 1;
1.2 raeburn 1935: }
1936: }
1.27 raeburn 1937: my $access_dates =
1.34 raeburn 1938: &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
1.66 raeburn 1939: $hascredits,%accesstitles);
1.27 raeburn 1940: $output .= &Apache::lonhtmlcommon::start_pick_box();
1941: if ($sections) {
1942: $output .= $sections;
1943: }
1944: if ($autoenroll) {
1945: $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
1946: '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
1947: &Apache::lonhtmlcommon::row_closure(1).
1948: $autoenroll;
1949: }
1950: if ($access_dates) {
1951: my $header = &mt('Access dates for students');
1952: if ($env{'form.crstype'} eq 'community') {
1953: $header = &mt('Access dates for community members');
1954: }
1955: $output .= &Apache::lonhtmlcommon::row_headline('Access').
1956: '<h3>'.$header.'</h3>'.
1957: &Apache::lonhtmlcommon::row_closure(1).
1.66 raeburn 1958: $access_dates;
1959: }
1960: if ($creditsrow) {
1961: $output .= &Apache::lonhtmlcommon::row_headline('Credits').
1962: '<h3>'.&mt('Credits earned by students').'</h3>'.
1963: &Apache::lonhtmlcommon::row_closure(1).
1964: &Apache::lonhtmlcommon::row_title(&mt('Default credits')).
1965: $creditsrow.
1966: &Apache::lonhtmlcommon::row_closure(1);
1.2 raeburn 1967: }
1.27 raeburn 1968: return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
1969: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.2 raeburn 1970: }
1971:
1.27 raeburn 1972: sub show_invalid_crosslists {
1973: my ($invalidcrosslist) = @_;
1974: my $output;
1975: if (ref($invalidcrosslist) eq 'ARRAY') {
1976: if (@{$invalidcrosslist} > 0) {
1977: $output = '<div class="LC_warning">'.
1978: &mt('The following crosslisted courses were invalid:').'<ul>';
1979: foreach my $item (@{$invalidcrosslist}) {
1980: $output .= '<li>'.$item.'</li>';
1981: }
1982: $output .= '</ul></div><br />';
1983: }
1984: }
1985: return $output;
1986: }
1987:
1988:
1.1 raeburn 1989: sub inst_section_selector {
1.2 raeburn 1990: my ($dom,$instcode) = @_;
1991: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1992: my $sectotal = scalar(@sections);
1.1 raeburn 1993: my $output;
1.2 raeburn 1994: if ($sectotal) {
1.27 raeburn 1995: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1.2 raeburn 1996: &Apache::loncommon::start_data_table().
1997: &Apache::loncommon::start_data_table_row().
1998: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1.24 raeburn 1999: 'value="'.$sectotal.'" /></th>'.
1.2 raeburn 2000: '<th>'.&mt('Institutional Section').'</th>'.
1.34 raeburn 2001: '<th>'.&Apache::loncommon::help_open_topic('Course_Request_LCSection').
2002: ' '.&mt('LON-CAPA section').'</th>'.
1.2 raeburn 2003: &Apache::loncommon::end_data_table_row();
2004: for (my $i=0; $i<@sections; $i++) {
1.1 raeburn 2005: my $colflag = $i%2;
1.31 raeburn 2006: my $secon = ' checked="checked"';
2007: my $secoff = '';
1.24 raeburn 2008: if ($env{'form.origcnum'}) {
1.31 raeburn 2009: $secoff = $secon;
2010: $secon='';
1.24 raeburn 2011: }
1.1 raeburn 2012: $output .= &Apache::loncommon::start_data_table_row().
1.31 raeburn 2013: '<td><label><input type="radio" name="sec_'.$i.
2014: '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
2015: (' 'x2).'<label><input type="radio" name="sec_'.$i.
2016: '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
2017: '<td align="center">'.$sections[$i].
1.1 raeburn 2018: '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2 raeburn 2019: $sections[$i].'" /></td>'.
1.1 raeburn 2020: '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2 raeburn 2021: '" value="'.$sections[$i].'" /></td>'.
1.1 raeburn 2022: &Apache::loncommon::end_data_table_row();
2023: }
1.2 raeburn 2024: $output .= &Apache::loncommon::end_data_table().
2025: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 2026: }
2027: return $output;
2028: }
2029:
1.2 raeburn 2030: sub date_setting_table {
1.66 raeburn 2031: my ($starttime,$endtime,$formname,$prefix,$hasauto,$hascredits,%datetitles)=@_;
1.2 raeburn 2032: my ($perpetual,$table);
1.14 raeburn 2033: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.2 raeburn 2034: $starttime,'','','',1,'','','',1);
1.14 raeburn 2035: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.2 raeburn 2036: $endtime,'','','',1,'','','',1);
1.27 raeburn 2037: my $closure = '';
1.14 raeburn 2038: if ($prefix eq 'access') {
1.2 raeburn 2039: $perpetual = ' <span class="LC_nobreak"><label>'.
2040: '<input type="checkbox" name="no_end_date" />'.
2041: &mt('No end date').'</label></span>';
1.66 raeburn 2042: unless ($hascredits) {
2043: $closure = '1';
2044: }
1.2 raeburn 2045: }
1.34 raeburn 2046:
2047: my %help_item = (
2048: access => {
2049: start => 'Course_Request_Access_Start',
2050: end => 'Course_Request_Access_End',
2051: },
2052: enroll => {
2053: start => 'Course_Request_Enroll_Start',
2054: end => 'Course_Request_Enroll_End',
2055: },
2056: );
2057: if ($hasauto) {
2058: $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start';
2059: $help_item{'access'}{'end'} = 'Course_Request_RegAccess_End';
2060: }
2061:
2062: $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
1.46 wenzelju 2063: ' '.&mt($datetitles{'start'})).$startform.
1.27 raeburn 2064: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 2065: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
1.46 wenzelju 2066: ' '.&mt($datetitles{'end'})).$endform.$perpetual.
1.27 raeburn 2067: &Apache::lonhtmlcommon::row_closure($closure);
1.2 raeburn 2068: return $table;
2069: }
2070:
2071: sub print_personnel_menu {
1.27 raeburn 2072: my ($dom,$formname,$crstype,$invalidcrosslist) = @_;
2073: my $output;
2074: if ($crstype eq 'official') {
2075: if (&Apache::lonnet::auto_run('',$dom)) {
2076: $output .= &show_invalid_crosslists($invalidcrosslist);
2077: }
2078: }
2079: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1.2 raeburn 2080: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 2081: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 2082: $persontotal = 1;
2083: }
2084: if ($env{'form.addperson'}) {
2085: $persontotal ++;
2086: }
1.13 raeburn 2087: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2 raeburn 2088:
1.8 raeburn 2089: my $type = 'Course';
2090: if ($crstype eq 'community') {
2091: $type = 'Community';
2092: }
1.41 raeburn 2093: my $roleoptions;
2094: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.2 raeburn 2095: foreach my $role (@roles) {
1.28 raeburn 2096: my $plrole = &Apache::lonnet::plaintext($role,$type);
1.2 raeburn 2097: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
2098: }
2099: my %customroles=&Apache::lonuserutils::my_custom_roles();
2100: if (keys(%customroles) > 0) {
2101: foreach my $cust (sort(keys(%customroles))) {
1.28 raeburn 2102: my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1.2 raeburn 2103: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
2104: }
2105: }
2106:
1.30 raeburn 2107: my @currsecs = ¤t_lc_sections();
1.2 raeburn 2108:
2109: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
2110: if (@currsecs) {
2111: my $existsize = scalar(@currsecs);
2112: if ($existsize > 3) {
2113: $existsize = 3;
2114: }
2115: if ($existsize > 1) {
2116: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
2117: }
2118: @currsecs = sort { $a <=> $b } (@currsecs);
2119: $existtitle = &mt('Official').': ';
2120: $existops = '<option value="">'.&mt('None').'</option>';
2121: foreach my $sec (@currsecs) {
2122: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
2123: }
2124: $seccolspan = ' colspan="2"';
2125: $newtitle = &mt('Other').': ';
2126: }
2127:
1.27 raeburn 2128: if ($persontotal) {
1.32 raeburn 2129: my %lt = &Apache::lonlocal::texthash(
2130: community => 'Requestor is automatically assigned Coordinator role.',
2131: official => 'Requestor is automatically assigned Course Coordinator role.',
2132: );
2133: $lt{'unofficial'} = $lt{'official'};
1.96 raeburn 2134: $lt{'textbook'} = $lt{'official'};
2135: $lt{'placement'} = $lt{'official'};
1.27 raeburn 2136: $output .= &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 2137: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
1.27 raeburn 2138: }
1.99 raeburn 2139: my $cansearch = 1;
2140: my @alldoms = &Apache::lonnet::all_domains();
2141: if (@alldoms == 1) {
2142: my %domsrch = &Apache::lonnet::get_dom('configuration',
2143: ['directorysrch'],$alldoms[0]);
2144: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
2145: if ((!$domsrch{'directorysrch'}{'available'}) &&
2146: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
2147: $cansearch = 0;
2148: }
2149: }
2150: }
1.101 raeburn 2151: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$dom);
1.100 raeburn 2152: for (my $i=0; $i<$persontotal; $i++) {
1.2 raeburn 2153: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
2154: my $linkargstr = join("','",@linkargs);
1.29 raeburn 2155: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1.2 raeburn 2156: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1.29 raeburn 2157: "'person_".$i."_hidedom','person_".$i."_uname'".');';
1.2 raeburn 2158: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1.101 raeburn 2159: 1,$onchange,undef,$trusted,$untrusted).
1.29 raeburn 2160: '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1.2 raeburn 2161: my %form_elems;
2162: foreach my $item (@items) {
2163: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
2164: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
2165: 'value="" readonly="readonly" />';
2166: }
2167: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
2168: $roleoptions.'</select>';
2169: my $sectionselector;
2170: if (@currsecs) {
2171: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
2172: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
2173: }
2174: $sectionselector .= $newtitle.
1.14 raeburn 2175: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.99 raeburn 2176: my $usersrchlink;
2177: if ($cansearch) {
2178: my $usersrchlinktxt = &mt('Search for user');
2179: $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
2180: $usersrchlinktxt);
2181: } else {
2182: $usersrchlink = ' ';
2183: }
1.29 raeburn 2184: my $userchklinktxt = &mt('Check username');
2185: my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
2186: $userchklinktxt,'checkusername');
1.2 raeburn 2187: $output .=
1.29 raeburn 2188: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
2189: '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
2190: '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
2191: &mt('Username').': '.$uname_form.' '.$userchklink.'</span><br />'."\n".
2192: '<span class="LC_nobreak">'.&mt('Domain').': '.$udom_form.'</span></td>'.
2193: '</tr>'."\n".'<tr>'.
1.13 raeburn 2194: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
2195: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
2196: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.34 raeburn 2197: '<tr><td align="center" valign="top">'.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
2198: '<td'.$seccolspan.' align="center" valign="top">'.
2199: &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1.2 raeburn 2200: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
2201: }
1.40 raeburn 2202: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2 raeburn 2203: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
2204: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
2205: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
2206: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1.40 raeburn 2207: &Apache::lonhtmlcommon::end_pick_box().'</div>';
2208: if ($crstype eq 'community') {
2209: $output .= '<p>'.&mt('You may also add users later, once the community has been created, by using the "Manage community users" link, accessible from the "Main Menu".').'</p>';
2210: } else {
2211: $output .= '<p>'.&mt('You may also add users later, once the course has been created, by using the "Manage course users" link, accessible from the "Main Menu".').'</p>';
2212: }
1.2 raeburn 2213: return $output;
2214: }
2215:
1.30 raeburn 2216: sub current_lc_sections {
2217: my @currsecs;
2218: if ($env{'form.sectotal'}) {
2219: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31 raeburn 2220: if ($env{'form.sec_'.$i}) {
2221: if (defined($env{'form.loncapasec_'.$i})) {
2222: my $lcsec = $env{'form.loncapasec_'.$i};
2223: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
2224: push(@currsecs,$lcsec);
2225: }
1.30 raeburn 2226: }
2227: }
2228: }
2229: }
2230: return @currsecs;
2231: }
2232:
1.48 raeburn 2233: sub sorted_request_history {
1.49 raeburn 2234: my ($dom,$action,$curr_req) = @_;
2235: my ($after,$before,$statusfilter,$crstypefilter);
2236: if ($env{'form.status'} ne '') {
2237: $statusfilter = $env{'form.status'};
2238: }
2239: if ($env{'form.crstype'} ne '') {
2240: $crstypefilter = $env{'form.crstype'};
2241: }
2242: if (ref($curr_req) eq 'HASH') {
2243: $after = $curr_req->{'requested_after_date'},
2244: $before = $curr_req->{'requested_before_date'};
2245: $statusfilter = $curr_req->{'status'};
2246: $crstypefilter = $curr_req->{'crstype'};
2247: }
1.14 raeburn 2248: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
2249: $env{'user.name'},'^status:'.$dom);
1.48 raeburn 2250: my %queue_by_date;
1.37 raeburn 2251: my ($types,$typenames) = &Apache::loncommon::course_types();
1.14 raeburn 2252: foreach my $key (keys(%statusinfo)) {
1.48 raeburn 2253: if ($action eq 'view') {
2254: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
2255: } else {
1.49 raeburn 2256: next unless (($statusfilter eq 'any') ||
2257: ($statusfilter eq $statusinfo{$key}));
1.48 raeburn 2258: }
2259: (undef,my($cdom,$cnum)) = split(':',$key);
2260: next if ($cdom ne $dom);
2261: my $requestkey = $cdom.'_'.$cnum;
2262: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2263: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2264: $env{'user.domain'},$env{'user.name'});
2265: my $entry;
2266: my $reqtime = $history{'reqtime'};
2267: my $lastupdate = $history{'timestamp'};
2268: my $crstype = $history{'crstype'};
2269: my $disposition = $history{'disposition'};
2270: my $status = $history{'status'};
1.73 raeburn 2271: my $uniquecode = $history{'code'};
1.48 raeburn 2272: if ($action eq 'view') {
1.14 raeburn 2273: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1.48 raeburn 2274: } else {
2275: next if (($reqtime < $after) || ($reqtime > $before));
2276: }
1.49 raeburn 2277: next unless (($crstypefilter eq 'any') ||
2278: ($crstypefilter eq $crstype));
1.48 raeburn 2279: if ($action eq 'view') {
1.14 raeburn 2280: next unless (($disposition eq 'approval') ||
2281: ($disposition eq 'pending'));
1.48 raeburn 2282: }
2283: if (ref($history{'details'}) eq 'HASH') {
2284: $entry = $requestkey.':'.$crstype.':'.
2285: &escape($history{'details'}{'cdescr'});
2286: if ($action eq 'log') {
1.73 raeburn 2287: $entry .= ':'.$uniquecode.':'.$lastupdate.':';
1.48 raeburn 2288: if ($statusinfo{$key} ne '') {
2289: $entry .= $statusinfo{$key};
2290: } elsif ($status ne '') {
2291: $entry .= $status;
2292: } else {
2293: $entry .= $disposition;
1.14 raeburn 2294: }
2295: }
1.48 raeburn 2296: if ($crstype eq 'official') {
2297: $entry .= ':'.&escape($history{'details'}{'instcode'});
2298: }
2299: }
2300: if ($entry ne '') {
2301: if (exists($queue_by_date{$reqtime})) {
2302: if (ref($queue_by_date{$reqtime}) eq 'ARRAY') {
2303: push(@{$queue_by_date{$reqtime}},$entry);
1.10 raeburn 2304: }
1.48 raeburn 2305: } else {
2306: @{$queue_by_date{$reqtime}} = ($entry);
1.10 raeburn 2307: }
2308: }
2309: }
2310: }
1.48 raeburn 2311: return %queue_by_date;
2312: }
2313:
2314: sub print_request_status {
2315: my ($dom,$action) = @_;
2316: my %queue_by_date = &sorted_request_history($dom,$action);
1.10 raeburn 2317: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.48 raeburn 2318: my $formname = 'requestcrs';
2319: my ($types,$typenames) = &Apache::loncommon::course_types();
2320: my $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.16 raeburn 2321:
1.10 raeburn 2322: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1.16 raeburn 2323: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
2324: '<input type="hidden" name="showdom" value="" />'."\n".
2325: '<input type="hidden" name="cnum" value="" />'."\n";
1.10 raeburn 2326: if (@sortedtimes > 0) {
1.40 raeburn 2327: my $desctitle;
2328: if ($env{'form.crstype'} eq 'any') {
2329: $desctitle = &mt('Course/Community Description')
2330: } elsif ($env{'form.crstype'} eq 'community') {
2331: $desctitle = &mt('Community Description')
2332: } else {
2333: $desctitle = &mt('Course Description');
2334: }
1.10 raeburn 2335: $output .= &Apache::loncommon::start_data_table().
2336: &Apache::loncommon::start_data_table_header_row().
2337: '<th>'.&mt('Action').'</th>'.
1.40 raeburn 2338: '<th>'.$desctitle.'</th>'.
1.14 raeburn 2339: '<th>'.&mt('Domain').'</th>';
2340: if ($env{'form.crstype'} eq 'any') {
1.10 raeburn 2341: $output .= '<th>'.&mt('Type').'</th>';
2342: }
1.14 raeburn 2343: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10 raeburn 2344: $output .= '<th>'.&mt('Institutional Code').'</th>';
2345: }
2346: $output .= '<th>'.&mt('Date requested').'</th>'.
2347: &Apache::loncommon::end_data_table_header_row();
2348: my $count = 0;
2349: foreach my $item (@sortedtimes) {
2350: my $showtime = &Apache::lonlocal::locallocaltime($item);
2351: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2352: foreach my $request (sort(@{$queue_by_date{$item}})) {
2353: my ($key,$type,$desc,$instcode) = split(':',$request);
2354: my ($cdom,$cnum) = split('_',$key);
2355: $output .= &Apache::loncommon::start_data_table_row().
1.16 raeburn 2356: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1.14 raeburn 2357: '<td>'.&unescape($desc).'</td>'.
2358: '<td>'.$cdom.'</td>';
2359: if ($env{'form.crstype'} eq 'any') {
1.35 raeburn 2360: my $typename;
2361: if (ref($typenames) eq 'HASH') {
2362: $typename = &mt($typenames->{$type});
2363: }
1.14 raeburn 2364: if ($typename eq '') {
2365: $typename = &mt('Unknown type');
2366: }
2367: $output .= '<td>'.$typename.'</td>';
1.10 raeburn 2368: }
1.14 raeburn 2369: if (($env{'form.crstype'} eq 'any') ||
1.10 raeburn 2370: ($env{'form.crstype'} eq 'official')) {
1.14 raeburn 2371: my $showinstcode;
2372: if ($type eq 'official') {
2373: $showinstcode = &unescape($instcode);
2374: } else {
2375: $showinstcode = &mt('Not applicable');
2376: }
2377: $output .= '<td>'.$showinstcode.'</td>';
1.10 raeburn 2378: }
2379: $output .= '<td>'.$showtime.'</td>'.
2380: &Apache::loncommon::end_data_table_row();
2381: }
2382: }
2383: }
2384: $output .= &Apache::loncommon::end_data_table();
2385: } else {
1.40 raeburn 2386: if ($env{'form.crstype'} eq 'any') {
2387: $output .= '<div>'.&mt('You have no matching course or community requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'</div>';
2388: } elsif ($env{'form.crstype'} eq 'community') {
2389: $output .= '<div>'.&mt('You have no matching community requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'</div>';
2390: } else {
2391: $output .= '<div>'.&mt('You have no matching course requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'</div>';
2392: }
1.10 raeburn 2393: }
2394: $output .= '
1.30 raeburn 2395: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
1.10 raeburn 2396: return $output;
1.1 raeburn 2397: }
2398:
1.16 raeburn 2399: sub print_cancel_request {
2400: my ($dom,$cnum) = @_;
2401: my $requestkey = $dom.'_'.$cnum;
2402: my ($result,$output);
2403: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2404: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2405: $env{'user.domain'},$env{'user.name'});
2406: my $timestamp = $history{'reqtime'};
2407: my $crstype = $history{'crstype'};
2408: my $status = $history{'status'};
2409: if (($status eq 'cancelled') || ($status eq 'created')) {
2410: if ($status eq 'cancelled') {
2411: $output = &mt('This request has already been cancelled.');
2412: } elsif ($status eq 'created') {
2413: $output = &mt('This request has already been processed, and a course created.');
2414: }
2415: $output = &mt('No further action will be taken');
2416: } elsif (ref($history{'details'}) eq 'HASH') {
1.37 raeburn 2417: my ($types,$typename) = &Apache::loncommon::course_types();
1.16 raeburn 2418: my $showtype = $crstype;
2419: if (defined($typename->{$crstype})) {
2420: $showtype = $typename->{$crstype};
2421: }
2422: $output = '<p>'.&Apache::loncommon::start_data_table().
2423: &Apache::loncommon::start_data_table_header_row().
2424: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
2425: '<th>'.&mt('Type').'</th>'.
2426: &Apache::loncommon::end_data_table_header_row().
2427: &Apache::loncommon::start_data_table_row().
2428: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
2429: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
1.110 raeburn 2430: '<td>'.&mt($showtype).'</td>'.
1.16 raeburn 2431: &Apache::loncommon::end_data_table_row().
2432: &Apache::loncommon::end_data_table().
1.40 raeburn 2433: '<br /><div class="LC_warning">';
2434: if ($crstype eq 'community') {
2435: $output .= &mt('Cancelling the request will remove it from the queue of pending community requests').'</div>';
2436: } else {
2437: $output .= &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
2438: }
1.16 raeburn 2439: $result = 'ok';
2440: } else {
2441: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
2442: }
2443: } else {
2444: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
2445: }
2446: return ($result,$output);
2447: }
2448:
2449: sub viewrequest_javascript {
2450: my ($formname,$next) = @_;
2451: return <<"ENDJS";
2452:
2453: function chooseRequest(cdom,cnum) {
2454: document.$formname.showdom.value = cdom;
2455: document.$formname.cnum.value = cnum;
2456: nextPage(document.$formname,'$next');
2457: }
2458:
2459: ENDJS
2460: }
2461:
2462: sub viewdetails_javascript {
2463: my ($formname) = @_;
2464: return << "ENDJS";
2465:
2466: function nextPage(formname,nextstate) {
2467: if (nextstate == "modify") {
2468: formname.state.value = "personnel";
2469: formname.action.value = "new";
2470: } else {
2471: formname.state.value = nextstate;
2472: }
2473: formname.submit();
2474: }
2475:
2476: function backPage(formname,prevstate) {
2477: formname.state.value = prevstate;
2478: formname.submit();
2479: }
2480:
2481: ENDJS
2482: }
2483:
2484: sub viewcancel_javascript {
1.89 damieng 2485: my $alert = &mt('Are you sure you want to cancel this request?')."\n".
1.68 bisitz 2486: &mt('Your request will be removed.');
1.89 damieng 2487: &js_escape(\$alert);
1.16 raeburn 2488: return << "ENDJS";
2489: function nextPage(formname,nextstate) {
2490: if (confirm('$alert')) {
2491: formname.state.value = nextstate;
2492: formname.submit();
2493: }
2494: return;
2495: }
2496:
2497: ENDJS
2498: }
2499:
1.1 raeburn 2500: sub print_request_logs {
1.73 raeburn 2501: my ($r,$dom,$jscript,$loaditems,$crumb,$usetabs) = @_;
1.48 raeburn 2502: my $title;
2503: if ($env{'form.crstype'} eq 'community') {
2504: $title = 'Community Request Logs';
2505: } elsif ($env{'form.crstype'} eq 'any') {
2506: $title = 'Course/Community Request Logs';
2507: } else {
2508: $title = 'Course Request Logs';
2509: }
2510: $r->print(&header($title,$jscript,$loaditems).$crumb);
1.73 raeburn 2511: if ($usetabs) {
2512: &startContentScreen($r,'textbooklogs');
2513: }
1.48 raeburn 2514: my $formname = 'requestcrs';
2515: $r->print('<form action="/adm/requestcourse" method="post" name="'.$formname.'" onsubmit="javascript:setPage(this);">'."\n".
2516: '<input type="hidden" name="action" value="log" />'."\n".
2517: '<input type="hidden" name="state" value="display" />'."\n");
2518: # set defaults
2519: my $now = time();
2520: my $defstart = $now - (7*24*3600); #7 days ago
2521: my %defaults = (
2522: page => '1',
2523: show => '10',
2524: crstype => 'any',
2525: status => 'any',
2526: requested_before_date => $now,
2527: requested_after_date => $defstart,
2528: );
2529: my ($types,$typenames) = &Apache::loncommon::course_types();
2530: my $more_records = 0;
2531: my %curr;
2532: foreach my $item ('show','page','crstype','status') {
2533: $curr{$item} = $env{'form.'.$item};
2534: }
2535: $curr{'requested_after_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_after_date');
2536: $curr{'requested_before_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_before_date');
2537: foreach my $key (keys(%defaults)) {
2538: if ($curr{$key} eq '') {
2539: $curr{$key} = $defaults{$key};
2540: }
2541: }
2542: my ($statuses,$statusnames) = &reqstatus_names($curr{'crstype'});
2543: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
2544: &requestlog_display_filter($formname,\%curr));
1.49 raeburn 2545: my %queue_by_date = &sorted_request_history($dom,$env{'form.action'},\%curr);
1.48 raeburn 2546: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
2547: my $showntablehdr = 0;
2548: my $tablehdr = &Apache::loncommon::start_data_table().
2549: &Apache::loncommon::start_data_table_header_row().
2550: '<th> </th><th>'.&mt('Request Date').'</th>'.
2551: '<th>'.&mt('Description').'</th>';
2552: if ($curr{'crstype'} eq 'any') {
2553: $tablehdr .= '<th>'.&mt('Course Type').'</th>';
2554: }
2555: if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) {
2556: $tablehdr .= '<th>'.&mt('Institutional Code').'</th>';
2557: }
1.73 raeburn 2558: my $showuniquecode;
2559: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
2560: if (($curr{'status'} eq 'any') || ($curr{'status'} eq 'created')) {
2561: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
2562: if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
2563: if ($curr{'crstype'} eq 'any') {
1.96 raeburn 2564: my @types = qw(official unofficial community textbook placement);
1.73 raeburn 2565: foreach my $type (@types) {
2566: if ($domconfig{'requestcourses'}{'uniquecode'}{$type}) {
2567: $showuniquecode = 1;
2568: last;
2569: }
2570: }
2571: } elsif ($domconfig{'requestcourses'}{'uniquecode'}{$curr{'crstype'}}) {
2572: $showuniquecode = 1;
2573: }
2574: }
2575: }
2576: }
2577: if ($showuniquecode) {
2578: $tablehdr .= '<th>'.&mt('Unique Code').'</th>';
2579: }
1.48 raeburn 2580: if ($curr{'status'} eq 'any') {
2581: $tablehdr .= '<th>'.&mt('Status').'</th>';
2582: } elsif ($curr{'status'} eq 'created') {
2583: $tablehdr .= '<th>'.&mt('Creation Date').'</th>';
2584: } elsif ($curr{'status'} eq 'cancelled') {
2585: $tablehdr .= '<th>'.&mt('Cancellation Date').'</th>';
2586: } elsif ($curr{'status'} eq 'rejected') {
2587: $tablehdr .= '<th>'.&mt('Rejection Date').'</th>';
2588: }
2589: $tablehdr .= &Apache::loncommon::end_data_table_header_row();
2590: my ($minshown,$maxshown);
2591: $minshown = 1;
2592: my $count = 0;
2593: if ($curr{'show'} ne &mt('all')) {
2594: $maxshown = $curr{'page'} * $curr{'show'};
2595: if ($curr{'page'} > 1) {
2596: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
2597: }
2598: }
2599: my $norecords;
2600: if (@sortedtimes > 0) {
2601: foreach my $item (@sortedtimes) {
2602: if ($curr{'show'} ne &mt('all')) {
2603: if ($count >= $curr{'page'} * $curr{'show'}) {
2604: $more_records = 1;
2605: last;
2606: }
2607: }
2608: $count ++;
2609: next if ($count < $minshown);
2610: if (!$showntablehdr) {
2611: $r->print($tablehdr);
2612: $showntablehdr = 1;
2613: }
2614: my $showtime = &Apache::lonlocal::locallocaltime($item);
2615: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2616: foreach my $request (sort(@{$queue_by_date{$item}})) {
1.73 raeburn 2617: my ($key,$crstype,$desc,$uniquecode,$timestamp,$status,$instcode) = split(':',$request);
1.48 raeburn 2618: my ($cdom,$cnum) = split('_',$key);
2619: my $output = &Apache::loncommon::start_data_table_row().
2620: '<td>'.$count.'</td>'.
2621: '<td>'.$showtime.'</td>'.
2622: '<td>'.&unescape($desc).'</td>';
2623: if ($curr{'crstype'} eq 'any') {
2624: my $typename;
2625: if (ref($typenames) eq 'HASH') {
2626: $typename = &mt($typenames->{$crstype});
2627: }
2628: if ($typename eq '') {
2629: $typename = &mt('Unknown type');
2630: }
2631: $output .= '<td>'.$typename.'</td>';
2632: }
2633: if (($curr{'crstype'} eq 'any') ||
2634: ($curr{'crstype'} eq 'official')) {
2635: my $showinstcode;
2636: if ($crstype eq 'official') {
2637: $showinstcode = &unescape($instcode);
2638: } else {
2639: $showinstcode = &mt('Not applicable');
2640: }
2641: $output .= '<td>'.$showinstcode.'</td>';
2642: }
1.73 raeburn 2643: if ($showuniquecode) {
2644: if ($status eq 'created') {
2645: $output .= '<td>'.$uniquecode.'</td>';
2646: } else {
2647: $output .= '<td>'.&mt('Not applicable').'</td>';
2648: }
2649: }
1.48 raeburn 2650: if ($curr{'status'} eq 'any') {
2651: my $statusname = &mt('Unknown status');
2652: if (ref($statusnames) eq 'HASH') {
2653: if ($statusnames->{$status} ne '') {
2654: $statusname = $statusnames->{$status};
2655: }
2656: }
2657: if (($status eq 'created') || ($status eq 'cancelled') ||
2658: ($status eq 'rejected')) {
2659: $statusname .= ' '.&Apache::lonlocal::locallocaltime($timestamp);
2660: }
2661: $output .= '<td>'.$statusname.'</td>';
2662: } elsif (($status eq 'created') || ($status eq 'cancelled') ||
2663: ($status eq 'rejected')) {
2664: $output .= '<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>';
2665: }
2666: $output .= &Apache::loncommon::end_data_table_row();
2667: $r->print($output);
2668: }
2669: }
2670: }
2671: if ($showntablehdr) {
2672: $r->print(&Apache::loncommon::end_data_table());
2673: if (($curr{'page'} > 1) || ($more_records)) {
2674: $r->print('<table><tr>');
2675: if ($curr{'page'} > 1) {
2676: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
2677: }
2678: if ($more_records) {
2679: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
2680: }
2681: $r->print('</tr></table>');
2682: $r->print(<<"ENDSCRIPT");
2683: <script type="text/javascript">
2684: // <![CDATA[
2685: function chgPage(caller) {
2686: if (caller == 'previous') {
2687: document.$formname.page.value --;
2688: }
2689: if (caller == 'next') {
2690: document.$formname.page.value ++;
2691: }
2692: document.$formname.submit();
1.1 raeburn 2693: return;
2694: }
1.48 raeburn 2695: // ]]>
2696: </script>
2697: ENDSCRIPT
2698: }
2699: } else {
2700: $norecords = 1;
2701: }
2702: } else {
2703: $norecords = 1;
2704: }
2705: if ($norecords) {
2706: $r->print('<p class="LC_info">'.
2707: &mt('There are no records to display').
2708: '</p>');
2709: }
1.73 raeburn 2710: if ($usetabs) {
2711: $r->print('<input type="hidden" name="tabs" value="on" />');
2712: }
2713: $r->print('</form>');
2714: if ($usetabs) {
2715: &endContentScreen($r);
2716: }
2717: $r->print(&Apache::loncommon::end_page());
1.48 raeburn 2718: return;
2719: }
2720:
2721: sub reqstatus_names {
2722: my ($crstype) = @_;
2723: my @statuses = qw(created approval pending rejected cancelled);
2724: my %statusnames =
2725: &Apache::lonlocal::texthash (
1.50 raeburn 2726: created => 'Created',
1.48 raeburn 2727: approval => 'Queued pending approval',
2728: pending => 'Queued pending validation',
2729: rejected => 'Request rejected',
2730: cancelled => 'Request cancelled',
2731: );
1.96 raeburn 2732: if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook') || ($crstype eq 'placement')) {
1.48 raeburn 2733: $statusnames{'created'} = &mt('Course created');
2734: } elsif ($crstype eq 'community') {
2735: $statusnames{'created'} = &mt('Community created');
2736: }
2737: return (\@statuses,\%statusnames);
2738: }
2739:
2740: sub requestlog_display_filter {
2741: my ($formname,$curr) = @_;
2742: my $nolink = 1;
2743: my $output = '<table><tr><td valign="top">'.
2744: '<span class="LC_nobreak"><b>'.&mt('Records/page:').'</b></span><br />'.
2745: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
2746: (&mt('all'),5,10,20,50,100,1000,10000)).
2747: '</td><td> </td>';
2748: my $startform =
2749: &Apache::lonhtmlcommon::date_setter($formname,'requested_after_date',
2750: $curr->{'requested_after_date'},undef,
2751: undef,undef,undef,undef,undef,undef,$nolink);
2752: my $endform =
2753: &Apache::lonhtmlcommon::date_setter($formname,'requested_before_date',
2754: $curr->{'requested_before_date'},undef,
2755: undef,undef,undef,undef,undef,undef,$nolink);
2756: $output .= '<td valign="top"><b>'.&mt('Window during which course/community was requested:').'</b><br />'.
2757: '<table><tr><td>'.&mt('After:').
2758: '</td><td>'.$startform.'</td></tr>'.
2759: '<tr><td>'.&mt('Before:').'</td>'.
2760: '<td>'.$endform.'</td></tr></table>'.
2761: '</td>'.
2762: '<td> </td>';
2763: my ($types,$typenames) = &Apache::loncommon::course_types();
2764: if (ref($types) eq 'ARRAY') {
2765: if (@{$types} > 1) {
2766: $output .= '<td valign="top"><b>'.
2767: &mt('Course Type:').'</b><br /><select name="crstype">';
2768: my $selstr = '';
2769: if ($curr->{'crstype'} eq 'any') {
2770: $selstr = ' selected="selected"';
2771: }
2772: $output .= '<option value="any"'.$selstr.'>'.&mt('All types').'</option>'."\n";
2773: foreach my $crstype (@{$types}) {
2774: my $selstr = '';
2775: if ($curr->{'crstype'} eq $crstype) {
2776: $selstr = ' selected="selected"';
2777: }
2778: my $typename = $crstype;
2779: if (ref($typenames) eq 'HASH') {
2780: if ($typenames->{$crstype} ne '') {
2781: $typename = $typenames->{$crstype};
2782: }
2783: }
1.110 raeburn 2784: $output .= '<option value="'.$crstype.'"'.$selstr.'>'.&mt($typename).'</option>'."\n";
1.48 raeburn 2785: }
2786: $output .= '</select></td>';
2787: }
2788: }
2789: my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'});
2790: if (ref($statuses) eq 'ARRAY') {
2791: if (@{$statuses} > 1) {
2792: $output .= '<td valign="top"><b>'.
2793: &mt('Request Status:').'</b><br /><select name="status">';
2794: my $selstr = '';
2795: if ($curr->{'status'} eq 'any') {
2796: $selstr = ' selected="selected"';
2797: }
2798: $output .= '<option value="any"'.$selstr.'>'.&mt('Any status').'</option>'."\n";
2799: foreach my $status (@{$statuses}) {
2800: my $selstr = '';
2801: if ($curr->{'status'} eq $status) {
2802: $selstr = ' selected="selected"';
2803: }
2804: my $statusname = $status;
2805: if (ref($statusnames) eq 'HASH') {
2806: if ($statusnames->{$status} ne '') {
2807: $statusname = $statusnames->{$status};
2808: }
2809: }
2810: $output .= '<option value="'.$status.'"'.$selstr.'>'.$statusname.'</option>'."\n";
2811: }
2812: $output .= '</select></td>';
2813: }
2814: }
2815: $output .= '</tr></table>';
2816:
2817: # Update Display button
2818: $output .= '<p>'.
2819: '<input type="submit" value="'.&mt('Update Display').'" />'.
2820: '</p><hr />';
2821: return $output;
2822: }
1.1 raeburn 2823:
2824: sub print_review {
1.30 raeburn 2825: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
1.66 raeburn 2826: $disallowed,$disallowmsg,$instcredits) = @_;
1.37 raeburn 2827: my ($types,$typename) = &Apache::loncommon::course_types();
1.4 raeburn 2828: my ($owner,$ownername,$owneremail);
1.26 raeburn 2829: if ($uname eq '' || $udom eq '') {
2830: $uname = $env{'user.name'};
2831: $udom = $env{'user.domain'};
2832: }
2833: $owner = $uname.':'.$udom;
2834: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
2835: my %emails = &Apache::loncommon::getemails($uname,$udom);
1.4 raeburn 2836: foreach my $email ('permanentemail','critnotification','notification') {
2837: $owneremail = $emails{$email};
2838: last if ($owneremail ne '');
2839: }
2840: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
2841: $section_headers,$section_values,$personnel_headers,$personnel_values);
2842:
2843: $crstypename = $env{'form.crstype'};
2844: if (ref($typename) eq 'HASH') {
2845: unless ($typename->{$env{'form.crstype'}} eq '') {
1.35 raeburn 2846: $crstypename = &mt($typename->{$env{'form.crstype'}});
1.4 raeburn 2847: }
2848: }
1.16 raeburn 2849: my $category = 'Course';
2850: if ($env{'form.crstype'} eq 'community') {
2851: $category = 'Community';
2852: }
1.4 raeburn 2853:
2854: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
2855: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
2856:
1.16 raeburn 2857: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
2858: '('.&Apache::lonnet::plaintext('st',$category).')';
1.87 raeburn 2859: my $instcode;
1.4 raeburn 2860: if ($env{'form.crstype'} eq 'official') {
2861: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
2862: foreach my $title (@{$codetitles}) {
2863: if ($env{'form.instcode_'.$title} ne '') {
2864: $inst_headers .= '<th>'.$title.'</th>';
2865: my $longitem = $env{'form.instcode_'.$title};
2866: if (ref($cat_titles->{$title}) eq 'HASH') {
2867: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
2868: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
2869: }
2870: }
2871: $inst_values .= '<td>'.$longitem.'</td>';
2872: }
2873: }
2874: }
1.87 raeburn 2875: if (ref($code_order) eq 'ARRAY') {
2876: foreach my $item (@{$code_order}) {
2877: $instcode .= $env{'form.instcode_'.$item};
2878: }
2879: }
1.66 raeburn 2880: $inst_headers .= '<th>'.&mt('Credits').'</th>';
2881: if ($instcredits) {
2882: $inst_values .= '<td>'.$instcredits.'</td>';
2883: } else {
2884: $inst_values .= '<td>'.$env{'form.coursecredits'}.'</td>';
2885: }
1.4 raeburn 2886: if (&Apache::lonnet::auto_run('',$dom)) {
1.16 raeburn 2887: $enrollrow_title = &mt('Enrollment');
1.4 raeburn 2888: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
2889: '<th>'.&mt('Automatic Drops').'</th>'.
2890: '<th>'.&mt('Enrollment Starts').'</th>'.
2891: '<th>'.&mt('Enrollment Ends').'</th>';
2892: $section_headers = '<th>'.&mt('Sections').'</th>'.
2893: '<th>'.&mt('Crosslistings').'</th>';
2894:
1.13 raeburn 2895: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4 raeburn 2896: my @autoroster = (&mt('No'),&mt('Yes'));
2897: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
2898: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13 raeburn 2899: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
2900: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6 raeburn 2901: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
2902: &mt('Institutional section').'</th>'.
2903: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2904: my $secinfo;
1.4 raeburn 2905: if ($env{'form.sectotal'} > 0) {
2906: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2907: if ($env{'form.sec_'.$i}) {
1.5 raeburn 2908: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4 raeburn 2909: if ($env{'form.loncapasec_'.$i} ne '') {
1.5 raeburn 2910: $secinfo .= $env{'form.loncapasec_'.$i};
2911: } else {
2912: $secinfo .= &mt('None');
1.4 raeburn 2913: }
1.5 raeburn 2914: $secinfo .= '</td></tr>';
1.4 raeburn 2915: }
2916: }
2917: }
1.6 raeburn 2918: if ($secinfo eq '') {
2919: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2920: }
1.6 raeburn 2921: $section_values .= $secinfo.'</table></td><td>'.
2922: '<table class="LC_innerpickbox"><tr><th>'.
2923: &mt('Institutional course/section').'</th>'.
2924: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2925: my $xlistinfo;
1.24 raeburn 2926: my $crosslisttotal = $env{'form.crosslisttotal'};
2927: if (!$crosslisttotal) {
2928: $crosslisttotal = 1;
2929: }
2930: for (my $i=0; $i<$crosslisttotal; $i++) {
2931: if ($env{'form.crosslist_'.$i}) {
2932: $xlistinfo .= '<tr><td>';
2933: if (ref($code_order) eq 'ARRAY') {
2934: if (@{$code_order} > 0) {
2935: foreach my $item (@{$code_order}) {
2936: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4 raeburn 2937: }
2938: }
2939: }
1.24 raeburn 2940: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
2941: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
2942: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
2943: } else {
2944: $xlistinfo .= &mt('None');
2945: }
2946: $xlistinfo .= '</td></tr>';
1.4 raeburn 2947: }
2948: }
1.6 raeburn 2949: if ($xlistinfo eq '') {
2950: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2951: }
1.24 raeburn 2952: $section_values .= $xlistinfo;
1.4 raeburn 2953: }
1.24 raeburn 2954: $section_values .= '</table></td>';
1.69 raeburn 2955: } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
1.66 raeburn 2956: $inst_headers .= '<th>'.&mt('Credits').'</th>';
2957: $inst_values .= '<td>'.$env{'form.coursecredits'}.'</td>';
1.4 raeburn 2958: }
2959:
1.109 raeburn 2960: my %ctxt = &clone_text($env{'form.crstype'});
1.4 raeburn 2961: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1.45 raeburn 2962: if (($env{'form.cloning'}) &&
2963: ($env{'form.clonecrs'} =~ /^$match_name$/) &&
1.13 raeburn 2964: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1.56 raeburn 2965: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname,
2966: $udom,$env{'form.clonecrs'},$env{'form.clonedom'},
1.87 raeburn 2967: $env{'form.crstype'},$dom,$instcode);
1.15 raeburn 2968: if ($canclone) {
2969: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
2970: $env{'form.clonecrs'},('description','internal.coursecode'));
2971: if (keys(%courseenv) > 0) {
1.109 raeburn 2972: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>'.
2973: '<th>'.$ctxt{'dpl'}.'</th>';
1.15 raeburn 2974: $inst_values .= '<td>'.$courseenv{'description'}.' ';
2975: my $cloneinst = $courseenv{'internal.coursecode'};
2976: if ($cloneinst ne '') {
1.18 raeburn 2977: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
1.15 raeburn 2978: } else {
1.18 raeburn 2979: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
1.15 raeburn 2980: }
2981: $inst_values .= '</td><td>';
2982: if ($env{'form.datemode'} eq 'preserve') {
1.16 raeburn 2983: $inst_values .= $ctxt{'prd'};
1.15 raeburn 2984: } elsif ($env{'form.datemode'} eq 'shift') {
2985: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
2986: } else {
2987: $inst_values .= $ctxt{'ncd'};
2988: }
1.109 raeburn 2989: $inst_values .= '</td><td>';
2990: if ($env{'form.tinyurls'} eq 'delete') {
2991: $inst_values .= $ctxt{'nsl'};
2992: } elsif ($env{'form.tinyurls'} eq 'transfer') {
2993: $inst_values .= $ctxt{'tsl'};
2994: } else {
2995: $inst_values .= $ctxt{'csl'};
2996: }
1.15 raeburn 2997: $inst_values .= '</td>';
2998: } else {
2999: $inst_values .= '<td>'.&mt('Unknown').'</td>';
3000: }
3001: } else {
3002: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
3003: }
1.4 raeburn 3004: } else {
3005: $inst_values .= '<td>'.&mt('None').'</td>';
3006: }
3007: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
3008: '<th>'.&mt('Access Ends').'</th>';
1.13 raeburn 3009: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
3010: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
3011: if ($accessend == 0) {
1.4 raeburn 3012: $enroll_values .= '<td>'.&mt('No end date').'</td>';
3013: } else {
1.13 raeburn 3014: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4 raeburn 3015: }
3016:
3017: my $container = 'Course';
1.41 raeburn 3018: my $ccrole = 'cc';
1.4 raeburn 3019: if ($env{'form.crstype'} eq 'community') {
3020: $container = 'Community';
1.41 raeburn 3021: $ccrole = 'co';
1.4 raeburn 3022: }
3023:
3024: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
3025: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
3026: '</th>';
1.41 raeburn 3027:
1.4 raeburn 3028: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1.41 raeburn 3029: '<td>'.&Apache::lonnet::plaintext($ccrole,$container).'</td>'.
1.4 raeburn 3030: '<td>'.&mt('None').'</td></tr>';
3031: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
3032: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.30 raeburn 3033: if (ref($disallowed) eq 'ARRAY') {
3034: next if (grep(/^$i$/,@{$disallowed}));
3035: }
1.31 raeburn 3036: my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
3037: my @allsecs;
3038: foreach my $sec (@officialsecs) {
3039: next unless ($sec =~ /\w/);
3040: next if ($sec =~ /\W/);
3041: next if ($sec eq 'none');
3042: push(@allsecs,$sec);
3043: }
1.14 raeburn 3044: my $newsec = $env{'form.person_'.$i.'_newsec'};
3045: $newsec =~ s/^\s+//;
3046: $newsec =~s/\s+$//;
1.31 raeburn 3047: my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
1.14 raeburn 3048: foreach my $sec (@newsecs) {
1.31 raeburn 3049: next unless ($sec =~ /\w/);
1.14 raeburn 3050: next if ($sec =~ /\W/);
1.31 raeburn 3051: next if ($sec eq 'none');
1.14 raeburn 3052: if ($sec ne '') {
3053: unless (grep(/^\Q$sec\E$/,@allsecs)) {
3054: push(@allsecs,$sec);
3055: }
3056: }
3057: }
1.24 raeburn 3058: my $showsec;
1.14 raeburn 3059: if (@allsecs) {
3060: $showsec = join(', ',@allsecs);
3061: }
1.24 raeburn 3062: if ($showsec eq '') {
3063: $showsec = &mt('None');
3064: }
1.41 raeburn 3065: if ($env{'form.person_'.$i.'_role'} eq $ccrole) {
1.24 raeburn 3066: $showsec = &mt('None');
3067: }
1.28 raeburn 3068: my $role = $env{'form.person_'.$i.'_role'};
1.4 raeburn 3069: $personnel_values .=
1.13 raeburn 3070: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
3071: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 3072: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
3073: $env{'form.person_'.$i.'_dom'}.'</td>'.
1.28 raeburn 3074: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
1.14 raeburn 3075: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 3076: }
3077: }
1.30 raeburn 3078: my $output;
3079: if (ref($disallowed) eq 'ARRAY') {
3080: if (@{$disallowed} > 0) {
3081: if (ref($disallowmsg) eq 'HASH') {
3082: $output = '<p class="LC_warning">'.
3083: &mt('Not all requested personnel could be included.').'<ul>';
3084: foreach my $item (@{$disallowed}) {
3085: $output .= '<li>'.$disallowmsg->{$item}.'</li>';
3086: }
3087: $output .= '</ul></p>';
3088: }
3089: }
3090: }
3091: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.4 raeburn 3092: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 3093: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 3094: '<th>'.&mt('Name').'</th>'.
3095: '<th>'.&mt('Username:Domain').'</th>'.
3096: '<th>'.&mt('E-mail address').'</th>'.
3097: '</tr><tr>'."\n".
3098: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
3099: '<td>'.$owneremail.'</td>'.
3100: '</tr></table>'."\n".
3101: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 3102: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 3103: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
3104: '<tr>'.$inst_values.'</tr></table>'."\n".
3105: &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 3106: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4 raeburn 3107: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
3108: '<tr>'.$enroll_values.'</tr></table>'."\n".
3109: &Apache::lonhtmlcommon::row_closure();
3110: if ($section_headers ne '') {
3111: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
3112: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
3113: '<tr>'.$section_values.'</tr></table>'."\n".
3114: &Apache::lonhtmlcommon::row_closure();
3115: }
3116: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
3117: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
3118: $personnel_values.'</table>'."\n".
3119: &Apache::lonhtmlcommon::row_closure(1).
1.26 raeburn 3120: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.4 raeburn 3121: return $output;
3122: }
3123:
3124: sub dates_from_form {
3125: my ($startname,$endname) = @_;
3126: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
3127: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 3128: if ($endname eq 'accessend') {
1.4 raeburn 3129: if (exists($env{'form.no_end_date'}) ) {
3130: $enddate = 0;
3131: }
3132: }
3133: return ($startdate,$enddate);
1.1 raeburn 3134: }
3135:
3136: sub courseinfo_form {
1.36 raeburn 3137: my ($dom,$formname,$crstype,$next,$description) = @_;
1.89 damieng 3138: my %js_lt = &Apache::lonlocal::texthash(
1.32 raeburn 3139: official => 'You must provide a (brief) course description.',
3140: community => 'You must provide a (brief) community description.'
3141: );
1.89 damieng 3142: &js_escape(\%js_lt);
3143: $js_lt{'unofficial'} = $js_lt{'official'};
3144: $js_lt{'textbook'} = $js_lt{'official'};
1.96 raeburn 3145: $js_lt{'placement'} = $js_lt{'official'};
1.15 raeburn 3146: my $js_validate = <<"ENDJS";
3147: <script type="text/javascript">
3148: // <![CDATA['
3149:
3150: function validateForm() {
3151: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
1.89 damieng 3152: alert('$js_lt{$crstype}');
1.15 raeburn 3153: return;
3154: }
3155: nextPage(document.$formname,'$next');
3156: }
1.45 raeburn 3157:
3158: function toggleCloning() {
3159: var willclone;
3160: if (document.$formname.cloning.length > 1) {
3161: for (var i=0; i<document.$formname.cloning.length; i++) {
3162: if (document.$formname.cloning[i].checked) {
3163: willclone = document.$formname.cloning[i].value;
3164: }
3165: }
3166: }
3167: if (willclone == 1) {
3168: document.getElementById('cloneoptions').style.display="block";
3169: } else {
3170: document.getElementById('cloneoptions').style.display="none";
3171: document.$formname.clonecrs.value = '';
3172: }
3173: }
3174:
1.15 raeburn 3175: // ]]
3176: </script>
3177:
3178: ENDJS
1.27 raeburn 3179: my $title = &mt('Brief Course Description');
1.40 raeburn 3180: my $clonetitle = &mt('Clone content and settings from an existing course?');
1.27 raeburn 3181: if ($crstype eq 'community') {
3182: $title = &mt('Brief Community Description');
1.40 raeburn 3183: $clonetitle = &mt('Clone content and settings from an existing community?');
1.27 raeburn 3184: }
1.45 raeburn 3185: my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 3186: &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 3187: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'</h3>'.
1.27 raeburn 3188: &Apache::lonhtmlcommon::row_closure(1).
3189: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.36 raeburn 3190: '<input type="text" size="60" name="cdescr" value="'.$description.'" />';
1.13 raeburn 3191: my ($home_server_pick,$numlib) =
3192: &Apache::loncommon::home_server_form_item($dom,'chome',
3193: 'default','hide');
3194: if ($numlib > 1) {
3195: $output .= &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 3196: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13 raeburn 3197: }
3198: $output .= $home_server_pick.
1.27 raeburn 3199: &Apache::lonhtmlcommon::row_closure().
3200: &Apache::lonhtmlcommon::row_headline().
1.45 raeburn 3201: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.
1.46 wenzelju 3202: &Apache::lonhtmlcommon::row_closure(1).
3203: &Apache::lonhtmlcommon::row_title(&mt('Clone?')).
1.45 raeburn 3204: '<label><input type="radio" name="cloning" value="1" '.
3205: 'onclick="javascript:toggleCloning()" />'.
3206: &mt('Yes').(' 'x2).'</label><label>'.
1.49 raeburn 3207: '<input type="radio" name="cloning" value="0" checked="checked" '.
1.45 raeburn 3208: 'onclick="javascript:toggleCloning()" />'.&mt('No').'</label>'.
3209: '</h3>'.
1.13 raeburn 3210: &Apache::lonhtmlcommon::row_closure(1).
1.45 raeburn 3211: &Apache::lonhtmlcommon::row_headline().
3212: '<div id="cloneoptions" style="display: none" >'.
3213: &Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 3214: &clone_form($dom,$formname,$crstype).
1.45 raeburn 3215: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
3216: &Apache::lonhtmlcommon::end_pick_box()."\n";
1.1 raeburn 3217: return $output;
3218: }
3219:
3220: sub clone_form {
3221: my ($dom,$formname,$crstype) = @_;
3222: my $type = 'Course';
3223: if ($crstype eq 'community') {
3224: $type = 'Community';
1.98 raeburn 3225: } elsif ($crstype eq 'placement') {
3226: $type = 'Placement';
1.1 raeburn 3227: }
1.109 raeburn 3228: my %lt = &clone_text($crstype);
1.2 raeburn 3229: my $output .=
1.53 raeburn 3230: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
3231: &Apache::loncommon::select_dom_form($dom,'clonedom').'</label>'.
3232: &Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 3233: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.97 raeburn 3234: '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();opencrsbrowser('."'$formname','clonecrs','clonedom','','','','$type'".')" />'.
1.53 raeburn 3235: '</label> '.
3236: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type).
3237: &Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 3238: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
3239: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
3240: '</label><br /><label>'.
3241: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
3242: '</label><br /><label>'.
3243: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
3244: $lt{'shd'}.'</label>'.
1.112 raeburn 3245: '<input type="text" size="5" name="dateshift" value="364" />'.
1.109 raeburn 3246: &Apache::lonhtmlcommon::row_closure(1).
3247: &Apache::lonhtmlcommon::row_title($lt{'dpl'}).'<label>'.
3248: '<input type="radio" name="tinyurls" value="delete" /> '.$lt{'nsl'}.
3249: '</label><br /><label>'.
3250: '<input type="radio" name="tinyurls" value="transfer" /> '.$lt{'tsl'}.
3251: '</label><br /><label>'.
3252: '<input type="radio" name="tinyurls" value="create" checked="checked" /> '.$lt{'csl'}.
3253: '</label>'.
1.27 raeburn 3254: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 3255: return $output;
3256: }
3257:
1.16 raeburn 3258: sub clone_text {
1.109 raeburn 3259: my ($crstype) = @_;
3260: my %lt = &Apache::lonlocal::texthash(
1.4 raeburn 3261: 'cid' => 'Course ID',
3262: 'dmn' => 'Domain',
3263: 'dsh' => 'Date Shift',
3264: 'ncd' => 'Do not clone date parameters',
3265: 'prd' => 'Clone date parameters as-is',
3266: 'shd' => 'Shift date parameters by number of days',
1.109 raeburn 3267: 'dpl' => 'URL shortcuts (for deep linking)',
3268: 'nsl' => 'Do not clone URL shortcuts',
3269: 'tsl' => 'Transfer URL shortcuts from existing course to new course',
3270: 'csl' => 'Create new URL shortcuts in new course',
3271: );
3272: if ($crstype eq 'Community') {
3273: $lt{'tsl'} = &mt('Transfer URL shortcuts from existing course to new community');
3274: $lt{'csl'} = &mt('Create new URL shortcuts in new course');
3275: }
3276: return %lt;
1.4 raeburn 3277: }
3278:
1.1 raeburn 3279: sub coursecode_form {
1.2 raeburn 3280: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 3281: my $output;
1.46 wenzelju 3282: my %rowtitle = &Apache::lonlocal::texthash (
1.2 raeburn 3283: instcode => 'Course Category',
3284: crosslist => 'Cross Listed Course',
3285: );
1.34 raeburn 3286: my %helpitem = (
3287: instcode => 'Course_Request_Category',
3288: );
1.1 raeburn 3289: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
3290: (ref($cat_order))) {
1.2 raeburn 3291: my ($sel,$instsec,$lcsec);
3292: $sel = $context;
3293: if ($context eq 'crosslist') {
3294: $sel .= '_'.$num;
3295: $instsec = &mt('Institutional section').'<br />'.
3296: '<input type="text" size="10" name="'.$sel.'_instsec" />';
3297: $lcsec = &mt('LON-CAPA section').'<br />'.
3298: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
3299: }
1.1 raeburn 3300: if (@{$codetitles} > 0) {
3301: my $lastitem = pop(@{$codetitles});
1.108 raeburn 3302: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'.$lastitem.'" />';
1.1 raeburn 3303: if (@{$codetitles} > 0) {
1.61 raeburn 3304: my $helplink;
3305: if (defined($helpitem{$context})) {
3306: $helplink = &Apache::loncommon::help_open_topic($helpitem{$context}).' ';
3307: }
3308: $output = &Apache::lonhtmlcommon::row_title($helplink.$rowtitle{$context}).
1.2 raeburn 3309: '<table><tr>';
1.1 raeburn 3310: if ($context eq 'crosslist') {
1.2 raeburn 3311: $output .= '<td>'.&mt('Include?').'<br />'.
3312: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 3313: }
3314: foreach my $title (@{$codetitles}) {
3315: if (ref($cat_order->{$title}) eq 'ARRAY') {
3316: if (@{$cat_order->{$title}} > 0) {
3317: $output .= '<td align="center">'.$title.'<br />'."\n".
3318: '<select name="'.$sel.'_'.$title.'">'."\n".
3319: ' <option value="" selected="selected">'.
3320: &mt('Select').'</option>'."\n";
3321: foreach my $item (@{$cat_order->{$title}}) {
3322: my $longitem = $item;
3323: if (ref($cat_titles->{$title}) eq 'HASH') {
3324: if ($cat_titles->{$title}{$item} ne '') {
3325: $longitem = $cat_titles->{$title}{$item};
3326: }
3327: }
3328: $output .= '<option value="'.$item.'">'.$longitem.
3329: '</option>'."\n";
3330: }
3331: }
3332: $output .= '</select></td>'."\n";
3333: }
3334: }
3335: if ($context eq 'crosslist') {
3336: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 3337: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
3338: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 3339: } else {
3340: $output .= '</tr></table>'.
3341: &Apache::lonhtmlcommon::row_closure().
3342: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
3343: $lastinput;
3344: }
3345: } else {
3346: if ($context eq 'crosslist') {
3347: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 3348: '<table><tr>'.
3349: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
3350: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
3351: '</tr></table>';
1.1 raeburn 3352: } else {
3353: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
3354: $lastinput;
3355: }
3356: }
1.2 raeburn 3357: $output .= &Apache::lonhtmlcommon::row_closure(1);
3358: push(@$codetitles,$lastitem);
3359: } elsif ($context eq 'crosslist') {
3360: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
3361: '<table><tr><td align="center">'.
3362: '<span class="LC_nobreak">'.&mt('Include?').
3363: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
3364: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
3365: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
3366: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
3367: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 3368: }
3369: }
3370: return $output;
3371: }
3372:
1.61 raeburn 3373: sub sections_form {
3374: my ($dom,$instcode,$num) = @_;
3375: my $rowtitle;
3376: if ($instcode eq '') {
3377: $rowtitle = &mt('Sections');
3378: } else {
3379: $rowtitle = &mt('Sections of [_1]',$instcode);
3380: }
3381: return &Apache::lonhtmlcommon::row_title($rowtitle).
3382: '<table><tr><td align="center">'.
3383: '<span class="LC_nobreak">'.&mt('Include?').
3384: '<input type="checkbox" name="sec_'.$num.'" value="1" /></span>'.
3385: '</td><td align="center">'.&mt('Institutional section').'<br />'.
3386: '<input type="text" size="10" name="secnum_'.$num.'" />'.
3387: '</td><td align="center">'.&mt('LON-CAPA section').'<br />'.
3388: '<input type="text" size="10" name="loncapasec_'.$num.'" />'.
3389: '</td></tr></table>'.
3390: &Apache::lonhtmlcommon::row_closure(1);
3391: }
3392:
1.1 raeburn 3393: sub get_course_dom {
3394: my $codedom = &Apache::lonnet::default_login_domain();
1.19 raeburn 3395: if ($env{'form.showdom'} ne '') {
3396: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
3397: return $env{'form.showdom'};
3398: }
3399: }
1.1 raeburn 3400: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.37 raeburn 3401: my ($types,$typename) = &Apache::loncommon::course_types();
1.19 raeburn 3402: if (ref($types) eq 'ARRAY') {
3403: foreach my $type (@{$types}) {
3404: if (&Apache::lonnet::usertools_access($env{'user.name'},
3405: $env{'user.domain'},$type,
3406: undef,'requestcourses')) {
3407: return $env{'user.domain'};
3408: }
3409: }
1.106 raeburn 3410: my (@possible_doms,%willtrust);
1.19 raeburn 3411: foreach my $type (@{$types}) {
3412: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
3413: if ($dom_str ne '') {
3414: my @domains = split(',',$dom_str);
3415: foreach my $entry (@domains) {
3416: my ($extdom,$extopt) = split(':',$entry);
1.106 raeburn 3417: unless (exists($willtrust{$extdom})) {
1.100 raeburn 3418: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$env{'user.domain'},$extdom);
3419: }
3420: if ($willtrust{$extdom}) {
3421: if ($extdom eq $env{'request.role.domain'}) {
3422: return $extdom;
3423: }
3424: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
3425: push(@possible_doms,$extdom);
3426: }
1.19 raeburn 3427: }
3428: }
3429: }
3430: }
3431: if (@possible_doms) {
3432: @possible_doms = sort(@possible_doms);
3433: return $possible_doms[0];
3434: }
3435: }
1.1 raeburn 3436: $codedom = $env{'user.domain'};
3437: if ($env{'request.role.domain'} ne '') {
3438: $codedom = $env{'request.role.domain'};
3439: }
3440: }
3441: return $codedom;
3442: }
3443:
3444: sub display_navbuttons {
1.31 raeburn 3445: my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1 raeburn 3446: $r->print('<div class="LC_navbuttons">');
3447: if ($prev) {
1.16 raeburn 3448: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1.31 raeburn 3449: 'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
1.16 raeburn 3450: (' 'x3));
1.1 raeburn 3451: } elsif ($prevtext) {
1.16 raeburn 3452: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
3453: 'onclick="javascript:history.back()"/>'.(' 'x3));
3454: }
3455: if ($state eq 'details') {
3456: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1.31 raeburn 3457: 'onclick="javascript:nextPage('."document.$formname,'$other'".
1.16 raeburn 3458: ')" />');
1.1 raeburn 3459: }
1.31 raeburn 3460: my $gotnext;
1.15 raeburn 3461: if ($state eq 'courseinfo') {
1.16 raeburn 3462: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3463: 'onclick="javascript:validateForm();" />');
1.31 raeburn 3464: $gotnext = 1;
3465: } elsif ($state eq 'enrollment') {
3466: if (($env{'form.crstype'} eq 'official') &&
3467: (&Apache::lonnet::auto_run('',$dom))) {
3468: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3469: 'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
3470: $gotnext = 1;
3471: }
3472: } elsif ($state eq 'personnel') {
3473: if ($env{'form.persontotal'} > 0) {
3474: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3475: 'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
3476: $gotnext = 1;
3477: }
3478: }
3479: unless ($gotnext) {
3480: if ($next) {
3481: $r->print('
3482: <input type="button" name="next" value="'.$nexttext.'" '.
3483: 'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
3484: }
1.1 raeburn 3485: }
3486: $r->print('</div>');
3487: }
3488:
3489: sub print_request_outcome {
1.84 raeburn 3490: my ($r,$lonhost,$dom,$codetitles,$code_order,$instcredits) = @_;
1.13 raeburn 3491: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.70 raeburn 3492: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,
3493: $uniquecode);
1.24 raeburn 3494: my $sectotal = $env{'form.sectotal'};
3495: my $crosslisttotal = 0;
1.10 raeburn 3496: $cnum = $env{'form.cnum'};
1.8 raeburn 3497: unless ($cnum =~ /^$match_courseid$/) {
3498: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
3499: return $output;
3500: }
1.73 raeburn 3501: $crstype = $env{'form.crstype'};
3502: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 3503: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
3504: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
3505: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
3506: }
1.73 raeburn 3507: if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
3508: $uniquecode = $domconfig{'requestcourses'}{'uniquecode'}{$crstype};
3509: }
1.9 raeburn 3510: }
1.10 raeburn 3511: $now = time;
1.41 raeburn 3512: my $ccrole = 'cc';
3513: if ($crstype eq 'community') {
3514: $ccrole = 'co';
3515: }
1.17 raeburn 3516: my @instsections;
1.8 raeburn 3517: if ($crstype eq 'official') {
3518: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 3519: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 3520: }
1.10 raeburn 3521: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
3522: if ($env{'form.sec_'.$i}) {
3523: if ($env{'form.secnum_'.$i} ne '') {
1.17 raeburn 3524: my $sec = $env{'form.secnum_'.$i};
3525: $sections{$i}{'inst'} = $sec;
3526: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
3527: push(@instsections,$sec);
3528: }
1.13 raeburn 3529: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.58 raeburn 3530: $sections{$i}{'loncapa'} =~ s/\W//g;
3531: if ($sections{$i}{'loncapa'} eq 'none') {
3532: $sections{$i}{'loncapa'} = '';
3533: }
1.10 raeburn 3534: }
3535: }
3536: }
3537: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
3538: if ($env{'form.crosslist_'.$i}) {
3539: my $xlistinfo = '';
3540: if (ref($code_order) eq 'ARRAY') {
3541: if (@{$code_order} > 0) {
3542: foreach my $item (@{$code_order}) {
3543: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
3544: }
3545: }
3546: }
1.22 raeburn 3547: $crosslistings{$i}{'instcode'} = $xlistinfo;
1.24 raeburn 3548: if ($xlistinfo ne '') {
3549: $crosslisttotal ++;
3550: }
1.22 raeburn 3551: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 3552: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 3553: }
3554: }
1.14 raeburn 3555: } else {
3556: $enrollstart = '';
3557: $enrollend = '';
1.10 raeburn 3558: }
1.62 raeburn 3559: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg,%skipped);
1.10 raeburn 3560: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
3561: my $uname = $env{'form.person_'.$i.'_uname'};
1.16 raeburn 3562: my $udom = $env{'form.person_'.$i.'_dom'};
1.10 raeburn 3563: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
3564: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 3565: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
3566: $personnel{$uname.':'.$udom} = {
3567: firstname => $env{'form.person_'.$i.'_firstname'},
3568: lastname => $env{'form.person_'.$i.'_lastname'},
3569: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
3570: };
1.62 raeburn 3571: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
3572: my $usertype = &get_usertype($udom,$uname,\%curr_rules,\%got_rules);
3573: if (&Apache::lonuserutils::can_create_user($udom,'requestcrs',$usertype)) {
3574: my ($allowed,$msg,$authtype,$authparam) =
3575: &check_newuser_rules($udom,$uname,\%alerts,\%rulematch,
3576: \%inst_results,\%curr_rules,\%got_rules);
3577: if ($allowed) {
3578: my %domdefaults = &Apache::lonnet::get_domain_defaults($udom);
3579: if ($usertype eq 'official') {
3580: if ($authtype eq '') {
1.60 raeburn 3581: $authtype = $domdefaults{'auth_def'};
3582: $authparam = $domdefaults{'auth_arg_def'};
1.62 raeburn 3583: } else {
3584: if ($authtype eq 'loc') {
3585: $authtype = 'localauth';
3586: } elsif ($authtype eq 'int') {
3587: $authtype = 'internal';
3588: }
3589: if ($authtype !~ /^(krb4|krb5|internal|localauth)$/) {
3590: $authtype = $domdefaults{'auth_def'};
3591: $authparam = $domdefaults{'auth_arg_def'};
3592: }
3593: }
3594: } elsif ($usertype eq 'unofficial') {
3595: if ($authtype eq '') {
3596: $authtype = 'internal';
3597: $authparam = '';
1.60 raeburn 3598: }
1.62 raeburn 3599: } else {
3600: $authtype = $domdefaults{'auth_def'};
3601: $authparam = $domdefaults{'auth_arg_def'};
1.60 raeburn 3602: }
1.62 raeburn 3603: if (($authtype eq '') ||
3604: (($authtype =~/^krb(4|5)$/) && ($authparam eq '')) ||
3605: ($authtype !~ /^(krb4|krb5|internal|localauth)$/)) {
3606: $skipped{$uname.':'.$udom} = 1;
3607: next;
3608: } else {
3609: $personnel{$uname.':'.$udom}{'authtype'} = $authtype;
3610: $personnel{$uname.':'.$udom}{'autharg'} = $authparam;
1.60 raeburn 3611: }
3612: } else {
1.62 raeburn 3613: $skipped{$uname.':'.$udom} = 1;
1.60 raeburn 3614: next;
3615: }
3616: } else {
1.62 raeburn 3617: $skipped{$uname.':'.$udom} = 1;
1.60 raeburn 3618: next;
3619: }
3620: }
1.13 raeburn 3621: }
3622: my $role = $env{'form.person_'.$i.'_role'};
3623: unless ($role eq '') {
1.16 raeburn 3624: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13 raeburn 3625: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
3626: unless (grep(/^\Q$role\E$/,@curr_roles)) {
3627: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
3628: }
3629: } else {
3630: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
3631: }
1.41 raeburn 3632: if ($role eq $ccrole) {
1.13 raeburn 3633: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
3634: } else {
1.14 raeburn 3635: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1.31 raeburn 3636: my @allsecs;
3637: foreach my $sec (@currsec) {
3638: next unless ($sec =~ /\w/);
3639: next if ($sec =~ /\W/);
3640: next if ($sec eq 'none');
3641: push(@allsecs,$sec);
3642: }
1.14 raeburn 3643: my $newsec = $env{'form.person_'.$i.'_newsec'};
3644: $newsec =~ s/^\s+//;
3645: $newsec =~s/\s+$//;
3646: my @newsecs = split(/[\s,;]+/,$newsec);
3647: foreach my $sec (@newsecs) {
3648: next if ($sec =~ /\W/);
1.31 raeburn 3649: next if ($sec eq 'none');
1.14 raeburn 3650: if ($sec ne '') {
1.31 raeburn 3651: unless (grep(/^\Q$sec\E$/,@allsecs)) {
3652: push(@allsecs,$sec);
1.13 raeburn 3653: }
3654: }
3655: }
1.31 raeburn 3656: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
1.13 raeburn 3657: }
3658: }
1.10 raeburn 3659: } else {
3660: push(@missingdom,$uname.':'.$udom);
3661: }
3662: } else {
3663: push(@baduname,$uname.':'.$udom);
3664: }
1.8 raeburn 3665: }
1.62 raeburn 3666: if (keys(%skipped)) {
3667: foreach my $key (keys(%skipped)) {
3668: delete($personnel{$key});
3669: }
3670: }
1.13 raeburn 3671: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 raeburn 3672: my $autodrops = 0;
3673: if ($env{'form.autodrops'}) {
3674: $autodrops = $env{'form.autodrops'};
3675: }
3676: my $autoadds = 0;
3677: if ($env{'form.autoadds'}) {
1.57 raeburn 3678: $autoadds = $env{'form.autoadds'};
1.14 raeburn 3679: }
3680: my $instcode = '';
3681: if (exists($env{'form.instcode'})) {
3682: $instcode = $env{'form.instcode'};
3683: }
1.66 raeburn 3684: my $credits;
3685: if ($instcredits) {
3686: $credits = $instcredits;
3687: } elsif (exists($env{'form.coursecredits'})) {
3688: $credits = $env{'form.coursecredits'};
3689: }
1.15 raeburn 3690: my $clonecrs = '';
3691: my $clonedom = '';
1.45 raeburn 3692: if (($env{'form.cloning'}) &&
3693: ($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
1.15 raeburn 3694: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.16 raeburn 3695: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
3696: $env{'form.clonedom'});
1.15 raeburn 3697: if ($clonehome ne 'no_host') {
1.16 raeburn 3698: my $canclone =
3699: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.39 raeburn 3700: $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
1.87 raeburn 3701: $crstype,$dom,$instcode);
1.15 raeburn 3702: if ($canclone) {
3703: $clonecrs = $env{'form.clonecrs'};
3704: $clonedom = $env{'form.clonedom'};
3705: }
3706: }
3707: }
1.8 raeburn 3708: my $details = {
1.10 raeburn 3709: owner => $env{'user.name'},
3710: domain => $env{'user.domain'},
3711: cdom => $dom,
1.11 raeburn 3712: cnum => $cnum,
1.13 raeburn 3713: coursehome => $env{'form.chome'},
3714: cdescr => $env{'form.cdescr'},
1.10 raeburn 3715: crstype => $env{'form.crstype'},
1.14 raeburn 3716: instcode => $instcode,
1.66 raeburn 3717: defaultcredits => $credits,
1.70 raeburn 3718: uniquecode => $uniquecode,
1.15 raeburn 3719: clonedom => $clonedom,
3720: clonecrs => $clonecrs,
1.10 raeburn 3721: datemode => $env{'form.datemode'},
1.14 raeburn 3722: dateshift => $env{'form.dateshift'},
1.109 raeburn 3723: tinyurls => $env{'form.tinyurls'},
1.14 raeburn 3724: sectotal => $sectotal,
1.10 raeburn 3725: sections => \%sections,
1.14 raeburn 3726: crosslisttotal => $crosslisttotal,
1.13 raeburn 3727: crosslists => \%crosslistings,
1.14 raeburn 3728: autoadds => $autoadds,
3729: autodrops => $autodrops,
1.13 raeburn 3730: enrollstart => $enrollstart,
3731: enrollend => $enrollend,
3732: accessstart => $accessstart,
3733: accessend => $accessend,
1.10 raeburn 3734: personnel => \%personnel,
1.8 raeburn 3735: };
1.90 raeburn 3736: my ($result,$output,$customized) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,
3737: $instcode,$req_notifylist,\@instsections,\%domconfig);
3738: return ($result,$output,$customized);
1.72 raeburn 3739: }
1.96 raeburn 3740:
1.72 raeburn 3741: sub process_request {
1.84 raeburn 3742: my ($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections,
1.78 raeburn 3743: $domconfig) = @_;
1.90 raeburn 3744: my (@inststatuses,$storeresult,$creationresult,$output,$customized);
1.43 raeburn 3745: my $val =
1.64 raeburn 3746: &Apache::loncoursequeueadmin::get_processtype('course',$env{'user.name'},
3747: $env{'user.domain'},$env{'user.adv'},
1.72 raeburn 3748: $dom,$crstype,\@inststatuses,$domconfig);
1.8 raeburn 3749: if ($val eq '') {
3750: if ($crstype eq 'official') {
1.19 raeburn 3751: $output = &mt('You are not permitted to request creation of official courses.');
1.8 raeburn 3752: } elsif ($crstype eq 'unofficial') {
1.19 raeburn 3753: $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8 raeburn 3754: } elsif ($crstype eq 'community') {
3755: $output = &mt('You are not permitted to request creation of communities');
1.69 raeburn 3756: } elsif ($crstype eq 'textbook') {
3757: $output = &mt('You are not permitted to request creation of textbook courses');
1.96 raeburn 3758: } elsif ($crstype eq 'placement') {
3759: $output = &mt('You are not permitted to request creation of placement tests');
1.8 raeburn 3760: } else {
3761: $output = &mt('Unrecognized course type: [_1]',$crstype);
3762: }
1.27 raeburn 3763: $storeresult = 'notpermitted';
1.8 raeburn 3764: } else {
1.93 raeburn 3765: my ($disposition,$message,$reqstatus,$coursedesc,$accessstart,$accessend,%customvalidation);
1.8 raeburn 3766: my %reqhash = (
1.14 raeburn 3767: reqtime => $now,
1.10 raeburn 3768: crstype => $crstype,
3769: details => $details,
1.8 raeburn 3770: );
3771: my $requestkey = $dom.'_'.$cnum;
1.17 raeburn 3772: my $validationerror;
1.78 raeburn 3773: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3774: $env{'user.domain'});
3775: if (ref($details) eq 'HASH') {
3776: $coursedesc = $details->{'cdescr'};
1.93 raeburn 3777: $accessstart = $details->{'accessstart'};
3778: $accessend = $details->{'accessend'};
1.78 raeburn 3779: }
1.10 raeburn 3780: if ($val eq 'autolimit=') {
3781: $disposition = 'process';
3782: } elsif ($val =~ /^autolimit=(\d+)$/) {
3783: my $limit = $1;
1.8 raeburn 3784: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 3785: $dom,$crstype,$limit,\$message);
1.8 raeburn 3786: } elsif ($val eq 'validate') {
1.90 raeburn 3787: my ($inststatuslist,$validationchk,$validation);
1.86 raeburn 3788: if (ref($details) eq 'HASH') {
3789: if ($details->{'clonecrs'}) {
1.90 raeburn 3790: $customvalidation{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
1.86 raeburn 3791: }
3792: }
1.17 raeburn 3793: if (@inststatuses > 0) {
3794: $inststatuslist = join(',',@inststatuses);
3795: }
3796: my $instseclist;
1.72 raeburn 3797: if (ref($instsections) eq 'ARRAY') {
3798: if (@{$instsections} > 0) {
3799: $instseclist = join(',',@{$instsections});
3800: }
1.17 raeburn 3801: }
1.90 raeburn 3802: #
3803: # Retrieve any custom form information used for validation
3804: #
1.78 raeburn 3805: my $preprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'prevalidate',$env{'user.name'},
3806: $env{'user.domain'},$fullname,$coursedesc);
3807: if (ref($preprocess) eq 'HASH') {
1.90 raeburn 3808: &custom_formitems($preprocess,\%customvalidation);
1.78 raeburn 3809: }
1.21 raeburn 3810: $validationchk =
3811: &Apache::lonnet::auto_courserequest_validation($dom,
3812: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
1.90 raeburn 3813: $inststatuslist,$instcode,$instseclist,\%customvalidation);
1.21 raeburn 3814: if ($validationchk =~ /:/) {
3815: ($validation,$message) = split(':',$validationchk);
3816: } else {
3817: $validation = $validationchk;
3818: }
3819: if ($validation =~ /^error(.*)$/) {
1.17 raeburn 3820: $disposition = 'approval';
3821: $validationerror = $1;
1.23 raeburn 3822: } else {
3823: $disposition = $validation;
1.17 raeburn 3824: }
1.8 raeburn 3825: } else {
3826: $disposition = 'approval';
3827: }
1.14 raeburn 3828: $reqhash{'disposition'} = $disposition;
3829: $reqstatus = $disposition;
1.91 raeburn 3830: my ($modified,$queued,$token,%customitems);
1.73 raeburn 3831: unless ($disposition eq 'rejected') {
3832: my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$env{'user.name'},
1.90 raeburn 3833: $env{'user.domain'},$fullname,$coursedesc,undef,
3834: undef,undef,\%customvalidation);
3835: #
3836: # Retrieve any custom form information submitted with review page and include in request details.
3837: #
1.73 raeburn 3838: if (ref($inprocess) eq 'HASH') {
1.90 raeburn 3839: &custom_formitems($inprocess,\%customitems);
3840: foreach my $key (keys(%customitems)) {
3841: $reqhash{'custom'}{$key} = $customitems{$key};
1.73 raeburn 3842: }
3843: }
3844: }
1.8 raeburn 3845: if ($disposition eq 'rejected') {
1.40 raeburn 3846: if ($crstype eq 'community') {
3847: $output = &mt('Your community request was rejected.');
3848: } else {
3849: $output = &mt('Your course request was rejected.');
3850: }
1.8 raeburn 3851: if ($message) {
3852: $output .= '<div class="LC_warning">'.$message.'</div>';
3853: }
1.27 raeburn 3854: $storeresult = 'rejected';
1.8 raeburn 3855: } elsif ($disposition eq 'process') {
1.14 raeburn 3856: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1.109 raeburn 3857: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,
3858: $keysmsg,%longroles,$code);
3859: my $clonemsg = [];
1.8 raeburn 3860: my $type = 'Course';
3861: if ($crstype eq 'community') {
3862: $type = 'Community';
3863: }
1.41 raeburn 3864: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.8 raeburn 3865: foreach my $role (@roles) {
3866: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
3867: }
1.84 raeburn 3868: $r->print('<div id="processing" style="display:block;">'."\n".
3869: &mt('Your request is being processed; this page will update when processing is complete.').
3870: '</div>');
3871: $r->rflush();
1.86 raeburn 3872: if (ref($details) eq 'HASH') {
3873: if ($details->{'clonecrs'}) {
3874: $customitems{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
3875: }
3876: }
1.90 raeburn 3877: $customitems{'_LC_ownerfullname'} = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'},'first');
3878: my $owneremail;
3879: my %emails = &Apache::loncommon::getemails();
3880: foreach my $email ('permanentemail','critnotification','notification') {
3881: $owneremail = $emails{$email};
3882: last if ($owneremail ne '');
3883: }
3884: if ($owneremail ne '') {
3885: $customitems{'_LC_owneremail'} = $owneremail;
3886: }
3887: $customitems{'_LC_coursedomainname'} = &Apache::lonnet::domain($dom,'description');
1.93 raeburn 3888: $customitems{'_LC_coursedescription'} = $coursedesc;
3889: $customitems{'_LC_coursestartdate'} = $accessstart;
3890: $customitems{'_LC_courseenddate'} = $accessend;
1.73 raeburn 3891: my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
1.109 raeburn 3892: 'autocreate',$details,\$logmsg,$clonemsg,\$newusermsg,
3893: \$addresult,\$enrollcount,\$response,\$keysmsg,\%domdefs,
3894: \%longroles,\$code,\%customitems);
1.90 raeburn 3895: if (ref($postprocess) eq 'HASH') {
3896: $customized = $postprocess->{'createdcustomized'};
3897: }
1.14 raeburn 3898: if ($result eq 'created') {
1.8 raeburn 3899: $disposition = 'created';
1.14 raeburn 3900: $reqstatus = 'created';
1.28 raeburn 3901: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
3902: \%longroles);
1.40 raeburn 3903: if ($crstype eq 'community') {
3904: $output = '<p>'.&mt('Your community request has been processed and the community has been created.');
3905: } else {
3906: $output = '<p>'.&mt('Your course request has been processed and the course has been created.');
3907: }
1.73 raeburn 3908: if (($code) || ((ref($postprocess) eq 'HASH') &&
3909: (($postprocess->{'createdweb'}) || ($postprocess->{'createdmsg'})))) {
3910: $output .= ¬ification_information($disposition,$env{'user.name'}.':'.$env{'user.domain'},
1.74 raeburn 3911: $dom,$cnum,$now,$code,$postprocess);
1.73 raeburn 3912: }
1.70 raeburn 3913: if ($code) {
1.73 raeburn 3914: $reqhash{'code'} = $code;
1.70 raeburn 3915: }
1.79 raeburn 3916: if (ref($postprocess) eq 'HASH') {
3917: if (ref($postprocess->{'createdactions'}) eq 'HASH') {
1.80 raeburn 3918: if (ref($postprocess->{'createdactions'}{'environment'}) eq 'HASH') {
3919: &Apache::loncoursequeueadmin::postprocess_crsenv($dom,$cnum,
3920: $postprocess->{'createdactions'}{'environment'});
1.79 raeburn 3921: }
3922: }
3923: }
1.90 raeburn 3924: unless ($customized) {
3925: $output .= '<br />'.$role_result;
3926: }
3927: $output .= '</p>';
1.109 raeburn 3928: if ($logmsg) {
3929: $output .= '<p>'.$logmsg.'</p>';
3930: }
3931: if ((ref($clonemsg) eq 'ARRAY') && (@{$clonemsg})) {
3932: $output .= '<p class="LC_info">';
3933: my $user_lh = &Apache::loncommon::user_lang($env{'user.name'},$env{'user.domain'});
3934: foreach my $item (@{$clonemsg}) {
3935: if (ref($item) eq 'HASH') {
3936: $output .= &mt_user($user_lh,$item->{mt},
3937: @{$item->{args}}).'<br />'."\n";
3938: }
3939: }
3940: $output .= '</p>'."\n";
3941: }
1.27 raeburn 3942: $creationresult = 'created';
1.107 raeburn 3943: # Flush the course logs so reverse user roles immediately updated
3944: unless ($registered_flush) {
3945: my $handlers = $r->get_handlers('PerlCleanupHandler');
3946: $r->set_handlers('PerlCleanupHandler' => [\&Apache::lonnet::flushcourselogs,@{$handlers}]);
3947: $registered_flush=1;
3948: }
3949: if ($instcode ne '') {
3950: &Apache::lonnet::devalidate_cache_new('instcats',$dom);
3951: # Update cache of self-cataloging courses on institution's server(s).
3952: if (&Apache::lonnet::shared_institution($dom)) {
3953: unless ($registered_instcats) {
3954: my $handlers = $r->get_handlers('PerlCleanupHandler');
3955: $r->set_handlers('PerlCleanupHandler' => [\&devalidate_remote_instcats,@{$handlers}]);
3956: $registered_instcats=1;
3957: $modified_dom = $dom;
3958: }
3959: }
3960: }
1.8 raeburn 3961: } else {
1.40 raeburn 3962: $output = '<span class="LC_error">';
3963: if ($crstype eq 'community') {
3964: $output .= &mt('An error occurred when processing your community request.');
3965: } else {
3966: $output .= &mt('An error occurred when processing your course request.');
3967: }
3968: $output .= '<br />'.
3969: &mt('You may want to review the request details and submit the request again.').
1.14 raeburn 3970: '</span>';
1.27 raeburn 3971: $creationresult = 'error';
1.8 raeburn 3972: }
3973: } else {
3974: my $requestid = $cnum.'_'.$disposition;
1.73 raeburn 3975: my $request = {
1.8 raeburn 3976: $requestid => {
3977: timestamp => $now,
3978: crstype => $crstype,
3979: ownername => $env{'user.name'},
3980: ownerdom => $env{'user.domain'},
1.78 raeburn 3981: description => $env{'form.cdescr'},
3982: lonhost => $lonhost,
1.8 raeburn 3983: },
3984: };
1.49 raeburn 3985: if ($crstype eq 'official') {
3986: $request->{$requestid}->{'instcode'} = $instcode;
3987: }
1.16 raeburn 3988: my $statuskey = 'status:'.$dom.':'.$cnum;
3989: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
3990: $env{'user.domain'},$env{'user.name'});
1.17 raeburn 3991: if ($userreqhash{$statuskey} ne '') {
1.16 raeburn 3992: $modified = 1;
1.25 raeburn 3993: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
3994: my %queuehash = &Apache::lonnet::get('courserequestqueue',
3995: [$cnum.'_approval',
3996: $cnum.'_pending'],$dom,$uname);
1.17 raeburn 3997: if (($queuehash{$cnum.'_approval'} ne '') ||
3998: ($queuehash{$cnum.'_pending'} ne '')) {
1.16 raeburn 3999: $queued = 1;
1.78 raeburn 4000: if (ref($queuehash{$cnum.'_pending'}) eq 'HASH') {
4001: $token = $queuehash{$cnum.'_pending'}{'token'};
4002: }
1.16 raeburn 4003: }
4004: }
4005: unless ($queued) {
1.78 raeburn 4006: if (($disposition eq 'pending') && ($crstype ne 'official')) {
4007: my %reqinfo = (
4008: $cnum.':'.$dom => $now.':'.$env{'user.name'}.':'.$env{'user.domain'},
4009: );
4010: $token = &Apache::lonnet::tmpput(\%reqinfo,$lonhost);
4011: $request->{$requestid}->{'token'} = $token;
4012: }
1.16 raeburn 4013: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
4014: $dom);
4015: if ($putresult eq 'ok') {
1.40 raeburn 4016: if ($crstype eq 'community') {
4017: $output .= &mt('Your community request has been recorded.');
4018: } else {
4019: $output .= &mt('Your course request has been recorded.')
4020: }
1.78 raeburn 4021: unless ($disposition eq 'pending') {
4022: $output .= '<br />'.
4023: ¬ification_information($disposition,$req_notifylist,
4024: $dom,$cnum,$now);
4025: }
1.8 raeburn 4026: } else {
1.16 raeburn 4027: $reqstatus = 'domainerror';
4028: $reqhash{'disposition'} = $disposition;
4029: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
4030: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8 raeburn 4031: }
4032: }
4033: }
1.44 raeburn 4034: ($storeresult,my $updateresult) =
4035: &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
1.63 raeburn 4036: $cnum,$reqstatus,'request',$env{'user.domain'},$env{'user.name'});
1.78 raeburn 4037: if ($storeresult eq 'ok') {
4038: my $postprocess;
4039: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
4040: my $updateaction = $disposition;
4041: if ($disposition eq 'approval') {
4042: $updateaction = 'queued';
4043: }
1.73 raeburn 4044: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
4045: $env{'user.domain'});
1.78 raeburn 4046: $postprocess =
4047: &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,$updateaction,$env{'user.name'},
1.73 raeburn 4048: $env{'user.domain'},$fullname,$env{'form.cdescr'});
1.78 raeburn 4049: }
4050: if ($modified && $queued) {
4051: if ($crstype eq 'community') {
4052: $output .= '<p>'.&mt('Your community request has been updated').'</p>';
4053: } else {
4054: $output .= '<p>'.&mt('Your course request has been updated').'</p>';
4055: }
4056: if ($disposition eq 'approval') {
4057: $output .= ¬ification_information($disposition,$req_notifylist,$dom,$cnum,$now);
4058: }
4059: }
4060: if ($disposition eq 'approval') {
1.73 raeburn 4061: if ((ref($postprocess) eq 'HASH') &&
4062: ((ref($postprocess->{'queuedmsg'}) eq 'HASH') || ($postprocess->{'queuedweb'}))) {
1.77 raeburn 4063: ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
1.90 raeburn 4064: $customized = $postprocess->{'createdcustomized'};
1.73 raeburn 4065: }
1.78 raeburn 4066: } elsif ($disposition eq 'pending') {
4067: my $pendingform;
4068: if ($crstype ne 'official') {
1.111 raeburn 4069: $pendingform = &pending_validation_form($r,$dom,$cnum,$crstype,$now,$token,
1.78 raeburn 4070: $lonhost,$env{'form.cdescr'});
4071: }
4072: if ($pendingform) {
4073: $output .= $pendingform;
4074: } else {
4075: $output .= ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
4076: }
1.90 raeburn 4077: if (ref($postprocess) eq 'HASH') {
4078: $customized = $postprocess->{'createdcustomized'};
4079: }
1.73 raeburn 4080: }
1.16 raeburn 4081: }
1.17 raeburn 4082: if ($validationerror ne '') {
1.44 raeburn 4083: $output .= '<p class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
4084: }
4085: if ($updateresult) {
4086: $output .= $updateresult;
1.17 raeburn 4087: }
1.16 raeburn 4088: }
1.27 raeburn 4089: if ($creationresult ne '') {
1.90 raeburn 4090: return ($creationresult,$output,$customized);
1.27 raeburn 4091: } else {
1.90 raeburn 4092: return ($storeresult,$output,$customized);
4093: }
4094: }
4095:
1.107 raeburn 4096: sub devalidate_remote_instcats {
4097: if ($modified_dom ne '') {
4098: my %servers = &Apache::lonnet::internet_dom_servers($modified_dom);
4099: my %thismachine;
4100: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
4101: if (keys(%servers)) {
4102: foreach my $server (keys(%servers)) {
4103: next if ($thismachine{$server});
4104: &Apache::lonnet::remote_devalidate_cache($server,['instcats:'.$modified_dom]);
4105: }
4106: }
4107: $modified_dom = '';
4108: }
4109: return;
4110: }
4111:
1.90 raeburn 4112: sub custom_formitems {
4113: my ($preprocess,$customhash) = @_;
4114: return unless ((ref($preprocess) eq 'HASH') && (ref($customhash) eq 'HASH'));
4115: if (ref($preprocess->{'formitems'}) eq 'HASH') {
4116: foreach my $key (keys(%{$preprocess->{'formitems'}})) {
4117: if ($preprocess->{'formitems'}->{$key} eq 'multiple') {
4118: if (exists($env{'form.'.$key})) {
4119: my @items = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
4120: foreach my $item (@items) {
4121: $item =~ s/(`)/'/g;
4122: $item =~ s/\$/\(\$\)/g;
4123: push(@{$customhash->{$key}},$item);
4124: }
4125: }
4126: } else {
4127: if (exists($env{'form.'.$key})) {
4128: $customhash->{$key} = $env{'form.'.$key};
4129: $customhash->{$key} =~ s/(`)/'/g;
4130: $customhash->{$key} =~ s/\$/\(\$\)/g;
4131: }
4132: }
4133: }
1.27 raeburn 4134: }
1.16 raeburn 4135: }
4136:
1.28 raeburn 4137: sub update_requestors_roles {
4138: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
4139: my $now = time;
4140: my ($active,$future,$numactive,$numfuture,$output);
4141: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
4142: if (ref($details) eq 'HASH') {
4143: if (ref($details->{'personnel'}) eq 'HASH') {
1.41 raeburn 4144: my $ccrole = 'cc';
4145: if ($crstype eq 'community') {
4146: $ccrole = 'co';
4147: }
1.35 raeburn 4148: unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
4149: $details->{'personnel'}{$owner} = {
1.41 raeburn 4150: 'roles' => [$ccrole],
4151: $ccrole => { 'usec' => [] },
1.35 raeburn 4152: };
4153: }
4154: my @roles;
4155: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
4156: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
1.41 raeburn 4157: unless (grep(/^\Q$ccrole\E$/,@roles)) {
4158: push(@roles,$ccrole);
1.35 raeburn 4159: }
4160: } else {
1.41 raeburn 4161: @roles = ($ccrole);
1.35 raeburn 4162: }
4163: foreach my $role (@roles) {
1.42 raeburn 4164: my $refresh=$env{'user.refresh.time'};
4165: if ($refresh eq '') {
4166: $refresh = $env{'user.login.time'};
4167: }
4168: if ($refresh eq '') {
4169: $refresh = $now;
4170: }
4171: my $start = $refresh-1;
1.35 raeburn 4172: my $end = '0';
4173: if ($role eq 'st') {
4174: if ($details->{'accessstart'} ne '') {
4175: $start = $details->{'accessstart'};
4176: }
4177: if ($details->{'accessend'} ne '') {
4178: $end = $details->{'accessend'};
4179: }
4180: }
4181: my @usecs;
1.41 raeburn 4182: if ($role ne $ccrole) {
1.35 raeburn 4183: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
4184: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
4185: }
4186: }
4187: if ($role eq 'st') {
4188: if (@usecs > 1) {
4189: my $firstsec = $usecs[0];
4190: @usecs = ($firstsec);
4191: }
4192: }
4193: if (@usecs == 0) {
4194: push(@usecs,'');
4195: }
4196: foreach my $usec (@usecs) {
4197: my (%userroles,%newrole,%newgroups,$spec,$area);
4198: my $area = '/'.$dom.'/'.$cnum;
4199: my $spec = $role.'.'.$area;
4200: if ($usec ne '') {
4201: $spec .= '/'.$usec;
4202: $area .= '/'.$usec;
4203: }
4204: if ($role =~ /^cr\//) {
4205: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
4206: $cnum,$spec,$area);
4207: } else {
4208: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
4209: $spec,$cnum,$area);
1.28 raeburn 4210: }
1.35 raeburn 4211: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
4212: \%newgroups);
4213: $userroles{'user.role.'.$spec} = $start.'.'.$end;
4214: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
4215: if (($end == 0) || ($end > $now)) {
4216: my $showrole = $role;
1.28 raeburn 4217: if ($role =~ /^cr\//) {
1.35 raeburn 4218: $showrole = &Apache::lonnet::plaintext($role,$crstype);
4219: } elsif (ref($longroles) eq 'HASH') {
4220: if ($longroles->{$role} ne '') {
4221: $showrole = $longroles->{$role};
4222: }
1.28 raeburn 4223: }
1.35 raeburn 4224: if ($start <= $now) {
4225: $active .= '<li><a href="/adm/roles?selectrole=1&'.
4226: $spec.'=1">'.$showrole;
4227: if ($usec ne '') {
4228: $active .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 4229: }
1.35 raeburn 4230: $active .= '</a></li>';
4231: $numactive ++;
4232: } else {
4233: $future .= '<li>'.$showrole;
4234: if ($usec ne '') {
4235: $future .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 4236: }
1.35 raeburn 4237: $future .= '</li>';
4238: $numfuture ++;
1.28 raeburn 4239: }
4240: }
4241: }
4242: }
4243: }
4244: }
4245: if ($active) {
4246: if ($numactive == 1) {
1.41 raeburn 4247: if ($crstype eq 'Community') {
4248: $output = &mt('Use the following link to enter the community:');
4249: } else {
4250: $output = &mt('Use the following link to enter the course:');
4251: }
1.28 raeburn 4252: } else {
1.41 raeburn 4253: if ($crstype eq 'Community') {
4254: $output = &mt('Use the following links to your new roles to enter the community:');
4255: } else {
4256: $output = &mt('Use the following links to your new roles to enter the course:');
4257: }
1.28 raeburn 4258: }
4259: $output .= ' <ul>'.$active.'</ul><br />';
4260: }
4261: if ($future) {
1.41 raeburn 4262: if ($crstype eq 'Community') {
4263: $output .= &mt('The following community [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'<a href="/adm/roles">','</a>',&Apache::lonlocal::locallocaltime($details->{'accessstart'}))
4264: } else {
4265: $output .= &mt('The following course [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'<a href="/adm/roles">','</a>',&Apache::lonlocal::locallocaltime($details->{'accessstart'}));
4266: }
4267: $output .= ' <ul>'.$future.'</ul>';
1.28 raeburn 4268: }
4269: return $output;
4270: }
4271:
1.16 raeburn 4272: sub notification_information {
1.74 raeburn 4273: my ($disposition,$req_notifylist,$dom,$cnum,$now,$code,$postprocess) = @_;
1.16 raeburn 4274: my %emails = &Apache::loncommon::getemails();
4275: my $address;
4276: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
4277: $address = $emails{'permanentemail'};
4278: if ($address eq '') {
4279: $address = $emails{'notification'};
4280: }
4281: }
4282: my $output;
4283: if ($disposition eq 'approval') {
4284: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
4285: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
4286: if ($address ne '') {
4287: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
4288: }
4289: if ($req_notifylist) {
4290: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
1.73 raeburn 4291: $env{'user.domain'});
1.16 raeburn 4292: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
1.74 raeburn 4293: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",
4294: 'undef',$env{'form.cdescr'},$now,'coursereq',$sender);
1.16 raeburn 4295: }
1.73 raeburn 4296: if (ref($postprocess) eq 'HASH') {
4297: if (ref($postprocess->{'queuedmsg'}) eq 'ARRAY') {
4298: if (scalar(@{$postprocess->{'queuedmsg'}}) > 0) {
4299: my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
4300: my $sender = $recipient;
4301: my $addmsg = [];
4302: foreach my $item (@{$postprocess->{'queuedmsg'}}) {
4303: if (ref($item) eq 'HASH') {
4304: if ($item->{'mt'} ne '') {
4305: push(@{$addmsg},$item);
4306: }
4307: }
4308: }
4309: if (scalar(@{$addmsg}) > 0) {
1.74 raeburn 4310: &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,undef,
1.73 raeburn 4311: $env{'form.cdescr'},$now,
1.77 raeburn 4312: 'queuedcrsreq',$sender);
1.73 raeburn 4313: }
4314: }
4315: }
4316: if ($postprocess->{'queuedweb'}) {
4317: $output .= $postprocess->{'queuedweb'};
4318: }
4319: }
1.17 raeburn 4320: } elsif ($disposition eq 'pending') {
1.78 raeburn 4321: my $pending_default = '<div class="LC_info">'.
1.16 raeburn 4322: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
4323: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
4324: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
1.78 raeburn 4325: '</div>';
4326: if (ref($postprocess) eq 'HASH') {
4327: if ($postprocess->{'pendingweb'}) {
4328: $output .= $postprocess->{'pendingweb'};
4329: } else {
4330: $output .= $pending_default;
4331: }
4332: } else {
4333: $output .= $pending_default;
4334: }
1.73 raeburn 4335: } elsif ($disposition eq 'created') {
4336: if (($code) || ((ref($postprocess) eq 'HASH') &&
4337: ((ref($postprocess->{'createdmsg'}) eq 'ARRAY') || ($postprocess->{'createdweb'})))) {
4338: my $addmsg = [];
4339: my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
4340: my $sender = $recipient;
4341: if ($code) {
4342: push(@{$addmsg},{
1.74 raeburn 4343: mt => 'Students can automatically select your course: "[_1]" by entering this code: [_2]',
4344: args => [$env{'form.cdescr'},$code],
1.73 raeburn 4345: });
4346: $output .= '<p>'.
4347: &mt('Students can automatically select your course by entering this code: [_1].','<b>'.$code.'</b>').
4348: '<br />'.
4349: &mt('A message has been sent to your LON-CAPA account with this information.');
4350: if ($address ne '') {
4351: $output.= '<br />'.&mt('An e-mail has also been sent to: [_1] with this code.',$address);
4352: }
4353: $output .= '</p>';
4354: }
4355: if (ref($postprocess) eq 'HASH') {
4356: if (ref($postprocess->{'createdmsg'}) eq 'ARRAY') {
4357: foreach my $item (@{$postprocess->{'createdmsg'}}) {
4358: if (ref($item) eq 'HASH') {
4359: if ($item->{'mt'} ne '') {
4360: push(@{$addmsg},$item);
4361: }
4362: }
4363: }
4364: }
4365: if ($postprocess->{'createdweb'}) {
4366: $output .= $postprocess->{'createdweb'}
4367: }
4368: }
4369: if (scalar(@{$addmsg}) > 0) {
1.77 raeburn 4370: my $type = 'createdcrsreq';
1.73 raeburn 4371: if ($code) {
4372: $type = 'uniquecode';
4373: }
1.74 raeburn 4374: &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,$dom.'_'.$cnum,$env{'form.cdescr'},
1.73 raeburn 4375: $now,$type,$sender);
4376: }
1.70 raeburn 4377: }
1.17 raeburn 4378: } else {
4379: $output .= '<div class="LC_warning">'.
1.44 raeburn 4380: &mt('Your request status is: [_1].',$disposition).
4381: '</div>';
1.8 raeburn 4382: }
4383: return $output;
4384: }
4385:
1.78 raeburn 4386: sub pending_validation_form {
1.111 raeburn 4387: my ($r,$cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
1.78 raeburn 4388: my $output;
4389: my %postvalues = (
4390: 'owner' => $env{'user.name'}.':'.$env{'user.domain'},
4391: 'course' => $cdom.'_'.$cnum,
4392: 'coursetype' => $crstype,
4393: );
4394: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
4395:
4396: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
4397: my ($url,$buttontext,$code,@fields);
4398: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
4399: $postvalues{'description'} = $cdesc;
4400: $url = $domconfig{'requestcourses'}{'validation'}{'url'};
4401: if (ref($domconfig{'requestcourses'}{'validation'}{'fields'}) eq 'ARRAY') {
4402: @fields = @{$domconfig{'requestcourses'}{'validation'}{'fields'}};
4403: }
4404: $buttontext = $domconfig{'requestcourses'}{'validation'}{'button'};
4405: $output .= $domconfig{'requestcourses'}{'validation'}{'markup'};
4406: if (($url =~ m{^(https?\://|/)}) && (@fields > 0)) {
4407: $output .= '<form name="crsreqvalidation" action="'.$url.'" method="post">'."\n";
4408: foreach my $field (@fields) {
4409: if ($postvalues{$field}) {
4410: $output .= '<input type="hidden" name="'.$field.'" value="'.$postvalues{$field}.'" />'."\n";
4411: }
4412: }
4413: if ($buttontext eq '') {
4414: if ($crstype eq 'community') {
4415: $buttontext = &mt('Create community');
4416: } else {
4417: $buttontext = &mt('Create course');
4418: }
4419: }
1.105 raeburn 4420: my $hostname = &Apache::lonnet::hostname($lonhost);
1.78 raeburn 4421: my $protocol = $Apache::lonnet::protocol{$lonhost};
4422: $protocol = 'http' if ($protocol ne 'https');
1.111 raeburn 4423: my $alias = &Apache::lonnet::use_proxy_alias($r,$lonhost);
4424: $hostname = $alias if ($alias ne '');
1.105 raeburn 4425: my $crscreator = $protocol.'://'.$hostname.'/cgi-bin/createpending.pl';
1.78 raeburn 4426: $output .= '<input type="hidden" name="crscreator" value="'.$crscreator.'" />'."\n".
4427: '<input type="hidden" name="token" value="'.$token.'" />'."\n".
4428: '<input type="submit" name="validate" value="'.$buttontext.'" />'."\n".
4429: '</form>'."\n";
4430: }
4431: }
4432: }
4433: return $output;
4434: }
4435:
1.8 raeburn 4436: sub check_autolimit {
1.10 raeburn 4437: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
4438: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
1.41 raeburn 4439: 'userroles',['active','future'],['cc','co'],[$dom]);
1.37 raeburn 4440: my ($types,$typename) = &Apache::loncommon::course_types();
1.10 raeburn 4441: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
1.41 raeburn 4442: my $count = 0;
1.10 raeburn 4443: foreach my $key (keys(%requests)) {
4444: my ($cdom,$cnum) = split('_',$key);
1.41 raeburn 4445: if (ref($requests{$key}) eq 'HASH') {
4446: next if ($requests{$key}{'crstype'} ne $crstype);
4447: if (($crstype eq 'community') &&
4448: (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
4449: $count ++;
1.96 raeburn 4450: } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook') || ($crstype eq 'placement')) &&
1.41 raeburn 4451: (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
4452: $count ++;
1.10 raeburn 4453: }
4454: }
4455: }
1.41 raeburn 4456: if ($count < $limit) {
1.10 raeburn 4457: return 'process';
4458: } else {
4459: if (ref($typename) eq 'HASH') {
1.41 raeburn 4460: if ($crstype eq 'community') {
4461: $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
4462: '<br />'.&mt("Your limit is [_1].",$limit);
4463: } else {
4464: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
4465: '<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
4466: }
1.10 raeburn 4467: }
4468: return 'rejected';
4469: }
1.1 raeburn 4470: return;
4471: }
4472:
1.2 raeburn 4473: sub retrieve_settings {
1.26 raeburn 4474: my ($dom,$cnum,$udom,$uname) = @_;
4475: if ($udom eq '' || $uname eq '') {
4476: $udom = $env{'user.domain'};
4477: $uname = $env{'user.name'};
4478: }
4479: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
1.16 raeburn 4480: if ($result eq 'ok') {
1.26 raeburn 4481: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
1.16 raeburn 4482: $env{'form.chome'} = $reqinfo{'coursehome'};
4483: $env{'form.cdescr'} = $reqinfo{'cdescr'};
4484: $env{'form.crstype'} = $reqinfo{'crstype'};
4485: &generate_date_items($reqinfo{'accessstart'},'accessstart');
4486: &generate_date_items($reqinfo{'accessend'},'accessend');
4487: if ($reqinfo{'accessend'} == 0) {
4488: $env{'form.no_end_date'} = 1;
4489: }
4490: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
4491: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
4492: &generate_date_items($reqinfo{'enrollend'},'enrollend');
4493: }
4494: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
4495: $env{'form.clonedom'} = $reqinfo{'clonedom'};
1.55 raeburn 4496: if (($reqinfo{'clonecrs'} ne '') && ($reqinfo{'clonedom'} ne '')) {
4497: $env{'form.cloning'} = 1;
4498: }
1.16 raeburn 4499: $env{'form.datemode'} = $reqinfo{'datemode'};
4500: $env{'form.dateshift'} = $reqinfo{'dateshift'};
1.109 raeburn 4501: $env{'form.tinyurls'} = $reqinfo{'tinyurls'};
1.59 raeburn 4502: if ($reqinfo{'crstype'} eq 'official') {
4503: $env{'form.autoadds'} = $reqinfo{'autoadds'};
4504: $env{'form.autodrops'} = $reqinfo{'autodrops'};
4505: if ($reqinfo{'instcode'} ne '') {
4506: $env{'form.sectotal'} = $reqinfo{'sectotal'};
4507: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
4508: $env{'form.instcode'} = $reqinfo{'instcode'};
4509: my $crscode = {
4510: $cnum => $reqinfo{'instcode'},
4511: };
4512: &extract_instcode($dom,'instcode',$crscode,$cnum);
1.66 raeburn 4513: (undef,undef,my $instcredits) =
4514: &Apache::lonnet::auto_validate_instcode(undef,$dom,
4515: $reqinfo{'instcode'});
4516: if ($instcredits ne $reqinfo{'defaultcredits'}) {
4517: $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
4518: }
1.59 raeburn 4519: }
1.69 raeburn 4520: } elsif (($reqinfo{'crstype'} eq 'unofficial') || ($reqinfo{'crstype'} eq 'textbook')) {
1.66 raeburn 4521: $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
1.16 raeburn 4522: }
4523: my @currsec;
4524: if (ref($reqinfo{'sections'}) eq 'HASH') {
4525: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
4526: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
1.24 raeburn 4527: my $sec = $reqinfo{'sections'}{$i}{'inst'};
1.16 raeburn 4528: $env{'form.secnum_'.$i} = $sec;
1.24 raeburn 4529: $env{'form.sec_'.$i} = '1';
1.16 raeburn 4530: if (!grep(/^\Q$sec\E$/,@currsec)) {
4531: push(@currsec,$sec);
4532: }
4533: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
4534: }
4535: }
4536: }
1.24 raeburn 4537: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
4538: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
4539: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
4540: $env{'form.crosslist_'.$i} = '1';
4541: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
4542: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
4543: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
4544: my $key = $cnum.$i;
4545: my $crscode = {
4546: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
4547: };
4548: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
4549: }
1.16 raeburn 4550: }
4551: }
4552: }
4553: if (ref($reqinfo{'personnel'}) eq 'HASH') {
4554: my $i = 0;
4555: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
4556: my ($uname,$udom) = split(':',$user);
4557: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
4558: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
4559: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
4560: $env{'form.person_'.$i.'_role'} = $role;
4561: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
4562: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
4563: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
4564: $env{'form.person_'.$i.'_uname'} = $uname;
4565: $env{'form.person_'.$i.'_dom'} = $udom;
4566: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
4567: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
4568: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
4569: my @newsecs;
4570: if (@usecs > 0) {
4571: foreach my $sec (@usecs) {
4572: if (grep(/^\Q$sec\E/,@currsec)) {
4573: $env{'form.person_'.$i.'_sec'} = $sec;
4574: } else {
1.20 raeburn 4575: push(@newsecs,$sec);
1.16 raeburn 4576: }
4577: }
4578: }
4579: if (@newsecs > 0) {
4580: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
4581: }
4582: }
4583: }
4584: $i ++;
4585: }
4586: }
4587: }
4588: }
4589: $env{'form.persontotal'} = $i;
4590: }
4591: }
4592: }
4593: return $result;
4594: }
4595:
4596: sub get_request_settings {
1.26 raeburn 4597: my ($dom,$cnum,$udom,$uname) = @_;
1.16 raeburn 4598: my $requestkey = $dom.'_'.$cnum;
4599: my ($result,%reqinfo);
4600: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1.26 raeburn 4601: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
1.16 raeburn 4602: my $disposition = $history{'disposition'};
4603: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
4604: if (ref($history{'details'}) eq 'HASH') {
4605: %reqinfo = %{$history{'details'}};
4606: $result = 'ok';
4607: } else {
4608: $result = 'nothash';
4609: }
4610: } else {
4611: $result = 'notqueued';
4612: }
4613: } else {
4614: $result = 'invalid';
4615: }
4616: return ($result,%reqinfo);
4617: }
1.2 raeburn 4618:
1.16 raeburn 4619: sub extract_instcode {
1.24 raeburn 4620: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
1.16 raeburn 4621: my (%codes,@codetitles,%cat_titles,%cat_order);
1.24 raeburn 4622: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
4623: \@codetitles,\%cat_titles,
4624: \%cat_order) eq 'ok') {
4625: if (ref($codes{$crskey}) eq 'HASH') {
1.16 raeburn 4626: if (@codetitles > 0) {
4627: my $sel = $element;
4628: if ($element eq 'crosslist') {
4629: $sel .= '_'.$counter;
4630: }
4631: foreach my $title (@codetitles) {
1.24 raeburn 4632: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
1.16 raeburn 4633: }
4634: }
4635: }
4636: }
4637: return;
1.2 raeburn 4638: }
4639:
1.16 raeburn 4640: sub generate_date_items {
4641: my ($currentval,$item) = @_;
4642: if ($currentval =~ /\d+/) {
4643: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
4644: &Apache::lonhtmlcommon::get_timedates($currentval);
4645: $env{'form.'.$item.'_day'} = $mday;
4646: $env{'form.'.$item.'_month'} = $month+1;
4647: $env{'form.'.$item.'_year'} = $year;
4648: }
4649: return;
1.2 raeburn 4650: }
4651:
1.72 raeburn 4652: sub print_textbook_form {
1.103 raeburn 4653: my ($r,$dom,$incdoms,$domdefs,$settings,$can_request,$crstype,$formhash) = @_;
1.81 raeburn 4654: my (%prefab,%ordered,%numprefab);
1.103 raeburn 4655: if ($crstype eq '') {
4656: $crstype = 'textbook';
4657: }
1.72 raeburn 4658: #
1.81 raeburn 4659: # Retrieve list of prefabricated courses (textbook courses and templates) cloneable by user
1.72 raeburn 4660: #
1.81 raeburn 4661: foreach my $type ('textbooks','templates') {
4662: $numprefab{$type} = 0;
4663: if (ref($settings) eq 'HASH') {
4664: $prefab{$type} = $settings->{$type};
4665: if (ref($prefab{$type}) eq 'HASH') {
4666: foreach my $item (keys(%{$prefab{$type}})) {
1.72 raeburn 4667: my ($clonedom,$clonecrs) = split(/_/,$item);
1.81 raeburn 4668: if (ref($prefab{$type}{$item}) eq 'HASH') {
4669: if (&Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.87 raeburn 4670: $env{'user.domain'},$clonecrs,$clonedom,$crstype,$dom)) {
1.81 raeburn 4671:
4672: my $num = $prefab{$type}{$item}{'order'};
4673: $ordered{$type}{$num} = $item;
4674: $numprefab{$type} ++;
4675: }
1.72 raeburn 4676: }
4677: }
4678: }
4679: }
4680: }
4681:
4682: #
4683: # Check if domain has multiple library servers
4684: #
4685: my ($home_server_pick,$numlib) =
4686: &Apache::loncommon::home_server_form_item($dom,'chome',
4687: 'default','hide');
4688: if ($numlib > 1) {
4689: $home_server_pick = &mt('Home Server for Course').': '.$home_server_pick.'<br />';
4690: }
4691:
4692: #
1.90 raeburn 4693: # Retrieve information about courses owned by user, or in which user has an active
4694: # Course Coordinator role
1.72 raeburn 4695: #
4696: my $numcurrent;
4697: my %cloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.',$env{'user.name'}.':'.$env{'user.domain'},
1.90 raeburn 4698: '.',undef,undef,'Course');
1.72 raeburn 4699: my %ccroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
1.90 raeburn 4700: ['active'],['cc']);
4701:
4702: my $cc_clone = '';
1.72 raeburn 4703: foreach my $role (keys(%ccroles)) {
4704: my ($cnum,$cdom,$rest) = split(/:/,$role,3);
1.90 raeburn 4705: $cc_clone .= $cdom.':'.$cnum.'&';
1.72 raeburn 4706: unless (exists($cloneable{$cdom.'_'.$cnum})) {
4707: my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{'one_time' => 1});
1.95 raeburn 4708: $cloneable{$cdom.'_'.$cnum} = {
4709: context => $courseinfo{'internal.creationcontext'},
4710: created => $courseinfo{'internal.created'},
4711: creator => $courseinfo{'internal.creator'},
4712: description => $courseinfo{'description'},
4713: inst_code => $courseinfo{'coursecode'},
4714: owner => $courseinfo{'internal.courseowner'},
4715: releaserequired => $courseinfo{'internal.releaserequired'},
4716: type => $courseinfo{'type'},
1.102 raeburn 4717: };
1.72 raeburn 4718: }
4719: }
4720:
4721: my $numcurrent = scalar(keys(%cloneable));
4722:
1.90 raeburn 4723: #
4724: # Retrieve information about courses from user's domain which user can clone, but which not owned
4725: # or cloneable based on Course Coordinator role.
4726: #
4727: my ($numdomcourses,%domcloneable);
4728: my %allcloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',undef,undef,'Course',
4729: undef,undef,undef,undef,undef,
4730: $env{'user.name'}.':'.$env{'user.domain'},
4731: $cc_clone,1);
4732: foreach my $cid (keys(%allcloneable)) {
4733: unless (exists($cloneable{$cid})) {
4734: $domcloneable{$cid} = $allcloneable{$cid};
4735: }
4736: }
4737: $numdomcourses = scalar(keys(%domcloneable));
4738:
4739: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
4740: $env{'user.domain'});
4741:
4742: #
4743: # Retrieve any custom form information prior to rendering page
4744: #
4745:
4746: my $initprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'initializereview',$env{'user.name'},
4747: $env{'user.domain'},$fullname);
4748: my %custominit;
4749: if (ref($initprocess) eq 'HASH') {
4750: &custom_formitems($initprocess,\%custominit);
4751: }
4752:
4753: #
4754: # Retrieve any custom onload actions or javascript used for page before rendering
4755: #
4756:
4757: my ($customonload,$customjs,$customvalidationjs);
4758: my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'prereview',$env{'user.name'},
4759: $env{'user.domain'},$fullname,undef,undef,
4760: undef,undef,\%custominit);
4761: if (ref($inprocess) eq 'HASH') {
4762: $customonload = $inprocess->{'onload'};
4763: $customjs = $inprocess->{'javascript'};
4764: $customvalidationjs = $inprocess->{'validationjs'};
4765: }
4766:
4767: my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'review',
4768: $env{'user.name'},
4769: $env{'user.domain'},$fullname,undef,undef,
4770: undef,undef,\%custominit);
4771:
4772: my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent,$numdomcourses,$customvalidationjs);
4773: $jscript .= $customjs;
1.103 raeburn 4774: my (%loaditems,$args);
1.90 raeburn 4775: $loaditems{'onload'} = 'javascript:uncheckAllRadio();'.$customonload;
1.103 raeburn 4776: if ($crstype eq 'lti') {
4777: $args = { 'only_body' => 1};
4778: }
4779: $r->print(&header('Course Request',$jscript,\%loaditems,undef,$args));
1.72 raeburn 4780:
1.73 raeburn 4781: if (ref($can_request) eq 'HASH') {
1.103 raeburn 4782: unless (((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) ||
4783: ($crstype eq 'lti')) {
1.73 raeburn 4784: &Apache::lonhtmlcommon::add_breadcrumb(
4785: { href => '/adm/requestcourse',
4786: text => 'Pick action',
4787: });
4788: }
4789: }
1.103 raeburn 4790: unless ($crstype eq 'lti') {
4791: &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
4792: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
1.72 raeburn 4793:
1.103 raeburn 4794: &startContentScreen($r,'textbookrequests');
1.72 raeburn 4795: #
4796: # Show domain selector form, if required.
4797: #
1.103 raeburn 4798: if (@{$incdoms} > 1) {
4799: my $onchange = 'this.form.submit()';
4800: $r->print('<form name="domforcourse" method="post" action="/adm/requestcourse">'.
4801: '<div><fieldset><legend>'.&mt('Domain').'</legend>'.
4802: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms).
4803: '</fieldset></form>');
4804: }
1.72 raeburn 4805: }
4806:
4807: #
4808: # Course request form
4809: #
4810:
4811: #
4812: # Course Title
4813: #
4814: $r->print('<form name="requestcourse" method="post" action="/adm/requestcourse" onsubmit="return validTextbookReq();">'.
4815: '<div>'.
4816: '<fieldset>'.
4817: '<legend>'.&mt('Course Information').'</legend>'.
4818: '<span class="LC_nobreak">'.&mt('Title').': '.
4819: '<input type="text" size="60" name="cdescr" value="" /></span><br />'.
4820: $home_server_pick.'<br /></fieldset>'.
4821: '</div>');
4822:
4823: #
4824: # Content source selection, if more than one available
4825: #
1.90 raeburn 4826: if (keys(%cloneable) || keys(%ordered) || keys(%domcloneable)) {
1.72 raeburn 4827: $r->print('<div>'.
4828: '<fieldset><legend>'.&mt('Course Content').'</legend>');
4829: if (keys(%ordered)) {
1.81 raeburn 4830: if (ref($ordered{'textbooks'}) eq 'HASH') {
4831: $r->print('<span class="LC_nobreak"><label>'.
4832: '<input type="radio" name="cloning" value="textbook" onclick="javascript:cloneChoice();" />'.
4833: &mt('Load textbook content').'</span>'.(' 'x2).' ');
4834: }
4835: if (ref($ordered{'templates'}) eq 'HASH') {
4836: $r->print('<span class="LC_nobreak"><label>'.
4837: '<input type="radio" name="cloning" value="template" onclick="javascript:cloneChoice();" />'.
1.83 raeburn 4838: &mt('Load pre-existing template').'</span>'.(' 'x2).' ');
1.81 raeburn 4839: }
1.72 raeburn 4840: }
4841: if (keys(%cloneable)) {
4842: $r->print('<span class="LC_nobreak"><label>'.
4843: '<input type="radio" name="cloning" value="existing" onclick="javascript:cloneChoice();" />'.
4844: &mt('Copy one of your courses').'</label></span>'.(' 'x2).' ');
4845: }
1.90 raeburn 4846: if (keys(%domcloneable)) {
4847: $r->print('<span class="LC_nobreak"><label>'.
4848: '<input type="radio" name="cloning" value="colleague" onclick="javascript:cloneChoice();" />'.
4849: &mt("Copy a colleague's course").'</label></span>'.(' 'x2).' ');
4850: }
1.72 raeburn 4851: $r->print('<span class="LC_nobreak"><label>'.
4852: '<input type="radio" name="cloning" value="none" checked="checked" onclick="javascript:cloneChoice();" />'.
4853: &mt('Empty course shell').'</label></span>');
4854: } else {
4855: $r->print('<input type="hidden" name="cloning" value="none" />');
4856: }
4857:
4858: #
4859: # Table of cloneable textbook courses
4860: #
4861: if (keys(%ordered)) {
1.81 raeburn 4862: foreach my $type ('textbooks','templates') {
4863: my $divid = 'showtextbook';
4864: my $radioid = 'book';
4865: if ($type eq 'templates') {
4866: $divid = 'showtemplate';
4867: $radioid = 'template';
4868: }
4869: if (ref($ordered{$type}) eq 'HASH') {
4870: $r->print('<div id="'.$divid.'" style="display:none">'.
4871: &Apache::loncommon::start_data_table().
4872: &Apache::loncommon::start_data_table_header_row().
4873: '<th>'.&mt('Title').'</th>');
4874: if ($type eq 'textbooks') {
4875: $r->print('<th>'.&mt('Author(s)').'</th>');
4876: }
4877: $r->print('<th>'.&mt('Subject').'</th>');
4878: if ($type eq 'textbooks') {
1.82 raeburn 4879: $r->print('<th>'.&mt('Publisher').'</th>'.
4880: '<th>'.&mt('Book').'</th>');
1.81 raeburn 4881: }
4882: $r->print(&Apache::loncommon::end_data_table_header_row());
4883: my @items = sort { $a <=> $b } keys(%{$ordered{$type}});
4884: foreach my $num (@items) {
4885: my $item = $ordered{$type}{$num};
4886: my $cleantitle=&HTML::Entities::encode($prefab{$type}{$item}{'title'},'<>&"');
4887: $cleantitle=~s/'/\\'/g;
4888: $cleantitle =~ s/^\s+//;
4889: $r->print(&Apache::loncommon::start_data_table_row().
4890: '<td><label><input type="radio" name="'.$radioid.'" value="'.$item.'" />'.
4891: $cleantitle.'</label></td>');
4892: if ($type eq 'textbooks') {
4893: $r->print('<td>'.$prefab{$type}{$item}{'author'}.'</td>');
4894: }
4895: $r->print('<td>'.$prefab{$type}{$item}{'subject'}.'</td>');
4896: if ($type eq 'textbooks') {
1.82 raeburn 4897: $r->print('<td>'.$prefab{$type}{$item}{'publisher'}.'</td>'.
4898: '<td><img border="0" src="'.$prefab{$type}{$item}{'image'}.
1.81 raeburn 4899: '" alt="'.$cleantitle.'" /></td>');
4900: }
4901: $r->print(&Apache::loncommon::end_data_table_row());
4902: }
4903: $r->print(&Apache::loncommon::end_data_table().
4904: '</div>');
4905: }
1.72 raeburn 4906: }
4907: }
4908:
4909: #
4910: # Table of user's current courses (owner and/or course coordinator)
4911: #
1.109 raeburn 4912: my %lt = &clone_text('Course');
1.72 raeburn 4913: if (keys(%cloneable)) {
4914: $r->print('<div id="showexisting" style="display:none">'.
1.90 raeburn 4915: &clone_selection_table($dom,'owned',\%cloneable).
1.109 raeburn 4916: '<fieldset style="display:inline-block"><legend>'.$lt{'dsh'}.'</legend><label>'.
4917: '<input type="radio" name="owndatemode" value="delete" /> '.$lt{'ncd'}.
1.90 raeburn 4918: '</label><br /><label>'.
1.93 raeburn 4919: '<input type="radio" name="owndatemode" value="preserve" /> '.$lt{'prd'}.
1.90 raeburn 4920: '</label><br /><label>'.
1.93 raeburn 4921: '<input type="radio" name="owndatemode" value="shift" checked="checked" /> '.
1.90 raeburn 4922: $lt{'shd'}.'</label>'.
1.112 raeburn 4923: '<input type="text" size="5" name="owndateshift" value="364" />'.
1.109 raeburn 4924: '</fieldset><fieldset style="display:inline-block">'.
4925: '<legend>'.$lt{'dpl'}.'</legend><label>'.
4926: '<input type="radio" name="owntinyurls" value="delete" />'.$lt{'nsl'}.
4927: '</label><br /><label>'.
4928: '<input type="radio" name="owntinyurls" value="transfer" />'.$lt{'tsl'}.
4929: '</label><br /><label>'.
4930: '<input type="radio" name="owntinyurls" value="create" checked="checked" />'.$lt{'csl'}.
4931: '</label></fieldset>'.
1.90 raeburn 4932: '</div>');
4933: }
4934: #
4935: # Table of other cloneable courses from user's domain (exclude own courses)
4936: #
4937: if (keys(%domcloneable)) {
4938: $r->print('<div id="showcolleague" style="display:none">'.
4939: &clone_selection_table($dom,'colleague',\%domcloneable).
1.109 raeburn 4940: '<fieldset style="display:inline-block"><legend>'.$lt{'dsh'}.'</legend><label>'.
4941: '<input type="radio" name="colldatemode" value="delete" /> '.$lt{'ncd'}.
1.90 raeburn 4942: '</label><br /><label>'.
1.93 raeburn 4943: '<input type="radio" name="colldatemode" value="preserve" /> '.$lt{'prd'}.
1.90 raeburn 4944: '</label><br /><label>'.
1.93 raeburn 4945: '<input type="radio" name="colldatemode" value="shift" checked="checked" /> '.
1.90 raeburn 4946: $lt{'shd'}.'</label>'.
1.112 raeburn 4947: '<input type="text" size="5" name="colldateshift" value="364" />'.
1.109 raeburn 4948: '</fieldset><fieldset style="display:inline-block">'.
4949: '<legend>'.$lt{'dpl'}.'</legend><label>'.
4950: '<input type="radio" name="colltinyurls" value="delete" />'.$lt{'nsl'}.
4951: '</label><br /><label>'.
4952: '<input type="radio" name="colltinyurls" value="create" checked="checked" />'.$lt{'csl'}.
4953: '</label></fieldset>'.
1.90 raeburn 4954: '</div>');
1.72 raeburn 4955: }
1.90 raeburn 4956:
1.72 raeburn 4957: #
4958: # End of content selector
4959: #
1.90 raeburn 4960: if (keys(%cloneable) || keys(%domcloneable) || keys(%ordered)) {
1.72 raeburn 4961: $r->print('</fieldset></div>');
4962: }
4963:
4964: my %accesstitles = (
4965: 'start' => 'Default start access',
4966: 'end' => 'Default end access',
4967: );
4968: my %help_item = (
4969: start => 'Course_Request_Access_Start',
4970: end => 'Course_Request_Access_End',
4971: );
4972: my $starttime = time;
4973: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
4974: my $startform = &Apache::lonhtmlcommon::date_setter('requestcourse','accessstart',
4975: $starttime,'','','',1,'','','',1);
4976: my $endform = &Apache::lonhtmlcommon::date_setter('requestcourse','accessend',
4977: $endtime,'','','',1,'','','',1);
4978: #
4979: # Set default start and end dates for student access
4980: #
4981: $r->print('<div>'.
4982: '<fieldset><legend>'.&mt('Student Access Dates').'</legend>'.
4983: &Apache::loncommon::help_open_topic($help_item{'start'}).
4984: ' '.&mt($accesstitles{'start'}).$startform.'<br />'.
4985: &Apache::loncommon::help_open_topic($help_item{'end'}).
4986: ' '.&mt($accesstitles{'end'}).$endform.'<br /></div>');
4987:
4988: #
1.73 raeburn 4989: # Display any custom fields for this course type
4990: #
4991: if (ref($postprocess) eq 'HASH') {
4992: if ($postprocess->{'reviewweb'}) {
4993: $r->print($postprocess->{'reviewweb'});
4994: }
4995: }
4996:
4997: #
1.72 raeburn 4998: # Submit button
4999: #
1.103 raeburn 5000: $r->print('<input type="hidden" name="crstype" value="'.$crstype.'" />'.
1.73 raeburn 5001: '<input type="hidden" name="action" value="process" />'.
1.72 raeburn 5002: '<input type="submit" value="'.&mt('Create course').'" />');
5003:
5004: #
5005: # End request form
5006: #
1.103 raeburn 5007:
5008: if (($crstype eq 'lti') && (ref($formhash) eq 'HASH')) {
5009: foreach my $item (keys(%{$formhash})) {
5010: $r->print('<input type="hidden" name="'.$item.'" value="'.$formhash->{$item}.'" />'."\n");
5011: }
5012: }
5013:
1.73 raeburn 5014: $r->print('</form>');
1.103 raeburn 5015: unless ($crstype eq 'lti') {
5016: &endContentScreen($r);
5017: }
1.73 raeburn 5018: $r->print(&Apache::loncommon::end_page());
1.72 raeburn 5019: return;
5020: }
5021:
1.90 raeburn 5022: sub clone_selection_table {
5023: my ($dom,$name,$cloneableref) = @_;
5024: return unless ((ref($cloneableref) eq 'HASH') && (($name eq 'owned') || ($name eq 'colleague')));
5025: my %allownernames;
5026: my %sortbytitle;
5027: my $output;
5028: foreach my $cid (sort(keys(%{$cloneableref}))) {
5029: if (ref($cloneableref->{$cid}) eq 'HASH') {
5030: my $cdesc = $cloneableref->{$cid}{'description'};
5031: $cdesc =~ s/`/'/g;
5032: if ($cdesc ne '') {
5033: push(@{$sortbytitle{$cdesc}},$cid);
5034: }
5035: }
5036: }
5037: foreach my $title (sort(keys(%sortbytitle))) {
5038: if (ref($sortbytitle{$title}) eq 'ARRAY') {
5039: foreach my $cid (sort(@{$sortbytitle{$title}})) {
5040: my $cleantitle=&HTML::Entities::encode($title,'<>&"');
5041: $cleantitle=~s/'/\\'/g;
5042: $cleantitle =~ s/^\s+//;
1.95 raeburn 5043: my ($namestr,@owners,%ownernames);
5044: if ($cloneableref->{$cid}{'owner'} ne '') {
5045: push(@owners,$cloneableref->{$cid}{'owner'});
1.94 raeburn 5046: }
1.95 raeburn 5047: if ($cloneableref->{$cid}{'co-owners'} ne '') {
5048: foreach my $item (split(/,/,$cloneableref->{$cid}{'co-owners'})) {
1.94 raeburn 5049: if (($item ne '') && (!grep(/^\Q$item\E$/,@owners))) {
5050: push(@owners,$item);
5051: }
1.90 raeburn 5052: }
5053: }
5054: foreach my $owner (@owners) {
5055: my ($ownername,$ownerdom);
5056: if ($owner =~ /:/) {
5057: ($ownername,$ownerdom) = split(/:/,$owner);
5058: } else {
5059: $ownername = $owner;
5060: if ($owner ne '') {
5061: $ownerdom = $dom;
5062: }
5063: }
5064: if ($ownername ne '' && $ownerdom ne '') {
5065: if (exists($allownernames{$ownername.':'.$ownerdom})) {
5066: $ownernames{$ownername.':'.$ownerdom} = $allownernames{$ownername.':'.$ownerdom};
5067: } else {
5068: my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
5069: $ownernames{$ownername.':'.$ownerdom} = \%namehash;
5070: $allownernames{$ownername.':'.$ownerdom} = $ownernames{$ownername.':'.$ownerdom};
5071: }
5072: }
5073: }
5074: my @lastnames;
5075: foreach my $owner (keys(%ownernames)) {
5076: if (ref($ownernames{$owner}) eq 'HASH') {
5077: push(@lastnames,$ownernames{$owner}{'lastname'});
5078: }
5079: }
5080: if (@lastnames) {
5081: $namestr = join(', ',sort(@lastnames));
5082: }
5083: $output .= &Apache::loncommon::start_data_table_row().
5084: '<td><label><input type="radio" name="'.$name.'" value="'.$cid.'" />'.
5085: ' '.$cleantitle.'</label></td>'.
5086: '<td>'.$namestr.'</td>'.
5087: &Apache::loncommon::end_data_table_row();
5088: }
5089: }
5090: }
5091: if ($output) {
5092: return &Apache::loncommon::start_data_table().
5093: &Apache::loncommon::start_data_table_header_row().
5094: '<th>'.&mt('Title').'</th>'.
5095: '<th>'.&mt('Owner/co-owner(s)').'</th>'.
5096: &Apache::loncommon::end_data_table_header_row().
5097: $output.
5098: &Apache::loncommon::end_data_table();
5099: }
5100: return;
5101: }
5102:
1.72 raeburn 5103: sub process_textbook_request {
1.103 raeburn 5104: my ($r,$dom,$action,$domdefs,$domconfig,$can_request,$crstype) = @_;
1.72 raeburn 5105: my ($uniquecode,$req_notifylist);
1.103 raeburn 5106: if ($crstype eq '') {
5107: $crstype = 'textbook';
5108: }
1.72 raeburn 5109: if (ref($domconfig) eq 'HASH') {
5110: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
5111: if (ref($domconfig->{'requestcourses'}{'notify'}) eq 'HASH') {
5112: $req_notifylist = $domconfig->{'requestcourses'}{'notify'}{'approval'};
5113: }
5114: if (ref($domconfig->{'requestcourses'}{'uniquecode'}) eq 'HASH') {
5115: $uniquecode = $domconfig->{'requestcourses'}{'uniquecode'}{$crstype};
5116: }
5117: }
5118: }
5119: my $now = time;
5120: my $reqtype = $env{'form.cloning'};
5121: my (@inststatuses,$storeresult,$creationresult);
5122: my $cnum = &Apache::lonnet::generate_coursenum($dom,'Course');
5123: my ($clonefrom,$clonedom,$clonecrs);
5124: if ($reqtype eq 'textbook') {
5125: $clonefrom = $env{'form.book'};
1.81 raeburn 5126: } elsif ($reqtype eq 'template') {
5127: $clonefrom = $env{'form.template'};
1.72 raeburn 5128: } elsif ($reqtype eq 'existing') {
5129: $clonefrom = $env{'form.owned'};
1.90 raeburn 5130: } elsif ($reqtype eq 'colleague') {
5131: $clonefrom = $env{'form.colleague'};
1.72 raeburn 5132: }
5133: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
5134: if ($clonefrom) {
5135: ($clonedom,$clonecrs) = split(/_/,$clonefrom);
5136: if (&Apache::lonnet::homeserver($clonecrs,$clonedom) ne 'no_host') {
5137: my $canclone =
5138: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.87 raeburn 5139: $env{'user.domain'},$clonecrs,$clonedom,$crstype,$dom);
1.72 raeburn 5140: unless ($canclone) {
5141: undef($clonecrs);
5142: undef($clonedom);
5143: }
5144: } else {
5145: undef($clonecrs);
5146: undef($clonedom);
5147: }
5148: }
1.84 raeburn 5149: my $js = &processing_javascript();
1.103 raeburn 5150: my ($loaditems,$args);
5151: $loaditems = {
5152: onload => 'javascript:hideProcessing();',
5153: };
5154: if ($crstype eq 'lti') {
5155: $args = { 'only_body' => 1};
5156: }
5157: $r->print(&header('Course Creation',$js,$loaditems,undef,$args));
5158:
5159: unless ($crstype eq 'lti') {
5160: if (ref($can_request) eq 'HASH') {
5161: unless ((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) {
5162: &Apache::lonhtmlcommon::add_breadcrumb(
5163: { href => '/adm/requestcourse',
5164: text => 'Pick action',
5165: });
5166: }
1.73 raeburn 5167: }
1.103 raeburn 5168: &Apache::lonhtmlcommon::add_breadcrumb(
5169: { href => '/adm/requestcourse',
5170: text => "Create Course",
5171: }
5172: );
5173: &Apache::lonhtmlcommon::add_breadcrumb({text=>'Request Processed'});
5174: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
5175: &startContentScreen($r,'textbookrequests');
1.73 raeburn 5176: }
1.72 raeburn 5177:
5178: my $details = {
5179: owner => $env{'user.name'},
5180: domain => $env{'user.domain'},
5181: cdom => $dom,
5182: cnum => $cnum,
5183: coursehome => $env{'form.chome'},
5184: cdescr => $env{'form.cdescr'},
5185: crstype => $crstype,
5186: uniquecode => $uniquecode,
5187: clonedom => $clonedom,
5188: clonecrs => $clonecrs,
5189: accessstart => $accessstart,
5190: accessend => $accessend,
5191: personnel => {},
5192: };
1.93 raeburn 5193: if (($clonecrs ne '') && ($clonedom ne '')) {
5194: if ($reqtype eq 'existing') {
5195: $details->{datemode} = $env{'form.owndatemode'};
5196: if ($details->{datemode} eq 'shift') {
5197: $details->{dateshift} = $env{'form.owndateshift'};
5198: } else {
5199: $details->{dateshift} = '';
5200: }
1.109 raeburn 5201: $details->{tinyurls} = $env{'form.owntinyurls'};
1.93 raeburn 5202: } elsif ($reqtype eq 'colleague') {
5203: $details->{datemode} = $env{'form.colldatemode'};
5204: if ($details->{datemode} eq 'shift') {
5205: $details->{dateshift} = $env{'form.colldateshift'};
5206: } else {
5207: $details->{dateshift} = '';
5208: }
1.109 raeburn 5209: $details->{tinyurls} = $env{'form.colltinyurls'};
1.104 raeburn 5210: } elsif (($reqtype eq 'textbook') || ($reqtype eq 'template')) {
5211: $details->{datemode} = 'delete';
5212: $details->{dateshift} = '';
1.109 raeburn 5213: $details->{tinyurls} = '';
1.93 raeburn 5214: }
5215: if ($details->{dateshift} ne '') {
5216: $details->{dateshift} =~ s/[^\d\.]+//g;
5217: }
5218: } else {
5219: $details->{datemode} = '';
5220: $details->{dateshift} = '';
1.109 raeburn 5221: $details->{tinyurls} = '';
1.72 raeburn 5222: }
1.78 raeburn 5223: my $lonhost = $r->dir_config('lonHostID');
1.84 raeburn 5224: $r->rflush();
1.90 raeburn 5225: my ($result,$output,$customized) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,
5226: '',$req_notifylist,[],$domconfig);
1.72 raeburn 5227: $r->print($output);
1.103 raeburn 5228: if ($crstype eq 'lti') {
1.113 ! raeburn 5229: my $storecrs;
! 5230: if ($env{'request.lti.login'}) {
! 5231: my %lti = &Apache::lonnet::get_domain_lti($dom,'provider');
! 5232: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
! 5233: $storecrs = $lti{$env{'request.lti.login'}}{'storecrs'};
! 5234: }
! 5235: }
! 5236: if ($storecrs) {
! 5237: my %consumers = &Apache::lonnet::get_dom('lticonsumers',[$env{'form.sourcecrs'}],$dom);
! 5238: if (($env{'form.lti.sourcecrs'} ne '') && ($consumers{$env{'form.lti.sourcecrs'}} eq '') && ($cnum ne '')) {
! 5239: &Apache::lonnet::put_dom('lticonsumers',{ $env{'form.lti.sourcecrs'} => $cnum },$dom);
! 5240: }
1.103 raeburn 5241: }
5242: } elsif (&Apache::loncoursequeueadmin::author_prompt()) {
1.90 raeburn 5243: unless ($customized) {
5244: &print_author_prompt($r,$action,$cnum,$dom,$crstype,$result);
5245: }
1.72 raeburn 5246: } elsif ($result eq 'created') {
1.90 raeburn 5247: unless ($customized) {
5248: $r->print('<p><a href="/adm/requestcourse">'.&mt('Create another course').'</a></p>');
5249: }
1.72 raeburn 5250: }
1.103 raeburn 5251: unless ($crstype eq 'lti') {
5252: &endContentScreen($r);
5253: }
1.72 raeburn 5254: $r->print(&Apache::loncommon::end_page());
5255: }
5256:
5257: sub textbook_request_javascript {
1.90 raeburn 5258: my ($numprefab,$numcurrent,$numcolleague,$customvalidationjs) = @_;
1.81 raeburn 5259: return unless (ref($numprefab) eq 'HASH');
1.90 raeburn 5260: return if (!$numprefab->{'textbooks'} && !$numprefab->{'templates'} && !$numcurrent && !$numcolleague);
1.89 damieng 5261: my %js_lt = &Apache::lonlocal::texthash(
1.90 raeburn 5262: choose => 'Please select a content option.',
5263: textbook => 'Please select a textbook, or choose a different option.',
5264: template => 'Please select a template, or choose a different option.',
5265: existing => 'Please select one of your existing courses to copy, or choose a different option.',
5266: colleague => "Please select a colleague's course to copy, or choose a different option.",
5267: title => 'Please enter a course title.',
1.72 raeburn 5268: );
1.89 damieng 5269: &js_escape(\%js_lt);
1.72 raeburn 5270: return <<"ENDSCRIPT";
5271: function cloneChoice() {
5272: if (document.requestcourse.cloning) {
5273: var radioLength = document.requestcourse.cloning.length;
5274: if (radioLength == undefined) {
5275: var val = document.requestcourse.cloning.value;
1.90 raeburn 5276: if ((val == 'textbook') || (val == 'template') || (val == 'existing') || (val == 'colleague')) {
1.72 raeburn 5277: var elem = document.getElementById('show'+val);
5278: if (document.requestcourse.cloning.checked) {
5279: elem.style.display = 'block';
5280: } else {
5281: uncheckRadio(val);
5282: elem.style.display = 'none';
5283: }
5284: }
5285: } else {
5286: for (var i=0; i<radioLength; i++) {
5287: var val = document.requestcourse.cloning[i].value;
1.90 raeburn 5288: if ((val == 'textbook') || (val == 'template') || (val == 'existing') || (val == 'colleague')) {
1.72 raeburn 5289: var elem = document.getElementById('show'+val);
5290: if (document.requestcourse.cloning[i].checked) {
5291: elem.style.display = 'block';
5292: } else {
5293: if (val == 'textbook') {
5294: uncheckRadio('book');
5295: }
1.81 raeburn 5296: if (val == 'template') {
5297: uncheckRadio('template');
5298: }
1.72 raeburn 5299: if (val == 'existing') {
5300: uncheckRadio('owned');
5301: }
1.90 raeburn 5302: if (val == 'colleague') {
5303: uncheckRadio('colleague');
5304: }
1.72 raeburn 5305: elem.style.display = 'none';
5306: }
5307: }
5308: }
5309: }
5310: }
5311: return;
5312: }
5313:
5314: function uncheckRadio(radioGroupName) {
5315: var group = document.getElementsByName(radioGroupName);
5316: var radioLength = group.length;
5317: if (radioLength == undefined) {
5318: group.checked = false;
5319: } else {
5320: for (var i=0; i<radioLength; i++) {
5321: group[i].checked = false;
5322: }
5323: }
5324: return;
5325: }
5326:
5327: function uncheckAllRadio() {
5328: uncheckRadio('cloning');
1.81 raeburn 5329: var numbook = $numprefab->{'textbooks'};
5330: var numtemplate = $numprefab->{'templates'};
1.72 raeburn 5331: var numcurrent = $numcurrent;
1.90 raeburn 5332: var numcolleague = $numcolleague;
1.72 raeburn 5333: if (numbook > 0) {
5334: uncheckRadio('textbook');
5335: }
1.88 raeburn 5336: if (numtemplate > 0) {
1.81 raeburn 5337: uncheckRadio('template');
1.88 raeburn 5338: }
1.72 raeburn 5339: if (numcurrent > 0) {
5340: uncheckRadio('existing');
5341: }
1.90 raeburn 5342: if (numcolleague > 0) {
5343: uncheckRadio('colleague');
5344: }
1.72 raeburn 5345: return;
5346: }
5347:
5348: function validTextbookReq() {
5349: if (document.requestcourse.cloning) {
5350: var cloneChoice = 0;
5351: var radioLength = document.requestcourse.cloning.length;
5352: if (radioLength == undefined) {
5353: if (document.requestcourse.cloning.checked == false) {
1.89 damieng 5354: alert("$js_lt{'choose'}");
1.72 raeburn 5355: return false;
5356: } else {
5357: cloneChoice = document.requestcourse.cloning.value;
5358: }
5359: } else {
5360: for (var i=0; i<radioLength; i++) {
5361: if (document.requestcourse.cloning[i].checked) {
5362: cloneChoice = document.requestcourse.cloning[i].value;
5363: break;
5364: }
5365: }
5366: if (cloneChoice == 0) {
1.89 damieng 5367: alert("$js_lt{'choose'}");
1.72 raeburn 5368: return false;
5369: }
5370: }
5371: var group;
1.90 raeburn 5372: if ((cloneChoice == 'textbook') || (cloneChoice == 'template') || (cloneChoice == 'existing') || (cloneChoice == 'colleague')) {
1.72 raeburn 5373: var group;
5374: if (cloneChoice == 'textbook') {
5375: group = document.getElementsByName('book');
5376: } else {
1.81 raeburn 5377: if (cloneChoice == 'template') {
5378: group = document.getElementsByName('template');
5379: } else {
1.90 raeburn 5380: if (cloneChoice == 'existing') {
5381: group = document.getElementsByName('owned');
5382: } else {
5383: group = document.getElementsByName('colleague');
5384: }
1.81 raeburn 5385: }
1.72 raeburn 5386: }
5387: var groupLength = group.length;
5388: var chosen = 0;
5389: if (groupLength == undefined) {
5390: if (group.checked) {
5391: chosen = 1;
5392: }
5393: } else {
5394: for (var j=0; j<groupLength; j++) {
5395: if (group[j].checked) {
5396: chosen = 1;
5397: break;
5398: }
5399: }
5400: }
5401: if (chosen == 0) {
5402: if (cloneChoice == 'textbook') {
1.89 damieng 5403: alert("$js_lt{'textbook'}");
1.72 raeburn 5404: } else {
1.81 raeburn 5405: if (cloneChoice == 'template') {
1.89 damieng 5406: alert("$js_lt{'template'}");
1.81 raeburn 5407: } else {
1.90 raeburn 5408: if (cloneChoice == 'existing') {
5409: alert("$js_lt{'existing'}");
5410: } else {
1.92 raeburn 5411: alert("$js_lt{'colleague'}");
1.90 raeburn 5412: }
1.81 raeburn 5413: }
1.72 raeburn 5414: }
5415: return false;
5416: }
5417: }
5418: }
5419: if (document.requestcourse.cdescr.value == '') {
1.89 damieng 5420: alert("$js_lt{'title'}");
1.72 raeburn 5421: return false;
5422: }
1.90 raeburn 5423: $customvalidationjs
1.72 raeburn 5424: return true;
5425: }
5426:
5427: ENDSCRIPT
5428:
5429: }
1.73 raeburn 5430:
1.85 raeburn 5431: sub textbook_request_disabled {
5432: my ($r,$dom,$action,$can_request) = @_;
5433: if (ref($can_request) eq 'HASH') {
5434: if ($action eq 'process') {
5435: unless ((scalar(keys(%{$can_request})) == 1)) {
5436: &Apache::lonhtmlcommon::add_breadcrumb(
5437: { href => '/adm/requestcourse',
5438: text => 'Pick action',
5439: });
5440: }
5441: }
5442: }
5443: $r->print(&header('Course Request'));
5444: &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
5445: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests').
5446: '<div>'.
5447: '<p class="LC_info">'.&mt('You do not have privileges to request creation of textbook courses.').'</p>');
5448: if (ref($can_request) eq 'HASH') {
5449: if (scalar(keys(%{$can_request})) > 1) {
5450: $r->print('<a href="/adm/requestcourse">'.&mt('Go back').'</a>');
5451: }
5452: }
5453: $r->print('</div>'.
5454: &Apache::loncommon::end_page());
5455: return;
5456: }
5457:
1.73 raeburn 5458: sub startContentScreen {
5459: my ($r,$mode)=@_;
5460: $r->print("\n".'<ul class="LC_TabContentBigger" id="textbookreq">'."\n");
5461: $r->print('<li'.(($mode eq 'textbookrequests')?' class="active"':'').'><a href="/adm/requestcourse"><b> '.&mt('Request a Course').' </b></a></li>'."\n");
5462: $r->print('<li'.(($mode eq 'textbooklogs')?' class="active"':'').'><a href="/adm/requestcourse?action=log&crstype=textbook&tabs=on"><b> '.&mt('Course Request History').' </b></a></li>'."\n");
5463: $r->print("\n".'</ul>'."\n");
5464: $r->print('<div class="LC_Box" style="clear:both;margin:0;"><div id="mainbox" style="margin:0 0;padding:0 0;"><div class="LC_ContentBox" id="maincontentbox" style="display: block;">');
5465: }
5466:
5467: sub endContentScreen {
5468: my ($r)=@_;
5469: $r->print('</div></div></div>');
5470: }
1.72 raeburn 5471:
1.1 raeburn 5472: 1;
5473:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>