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