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