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