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