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