Annotation of loncom/interface/lonrequestcourse.pm, revision 1.36.2.2
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.36.2.2! raeburn 4: # $Id: lonrequestcourse.pm,v 1.36.2.1 2009/09/23 15:58:26 gci 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 check_can_request()
56:
57: =item course_types()
58:
59: =item print_main_menu()
60:
61: =item request_administration()
62:
1.27 raeburn 63: =item close_popup_form()
64:
65: =item get_instcode()
66:
1.12 raeburn 67: =item print_request_form()
68:
69: =item print_enrollment_menu()
70:
1.27 raeburn 71: =item show_invalid_crosslists()
72:
1.12 raeburn 73: =item inst_section_selector()
74:
75: =item date_setting_table()
76:
77: =item print_personnel_menu()
78:
79: =item print_request_status()
80:
81: =item print_request_logs()
82:
83: =item print_review()
84:
85: =item dates_from_form()
86:
87: =item courseinfo_form()
88:
89: =item clone_form()
90:
91: =item clone_text()
92:
93: =item coursecode_form()
94:
95: =item get_course_dom()
96:
97: =item display_navbuttons()
98:
99: =item print_request_outcome()
100:
101: =item get_processtype()
102:
103: =item check_autolimit()
104:
105: =item retrieve_settings()
106:
107: =item get_request_settings()
108:
1.27 raeburn 109: =item extract_instcode()
110:
111: =item generate_date_items()
112:
1.1 raeburn 113: =back
114:
115: =cut
116:
117: package Apache::lonrequestcourse;
118:
119: use strict;
120: use Apache::Constants qw(:common :http);
121: use Apache::lonnet;
122: use Apache::loncommon;
123: use Apache::lonlocal;
1.8 raeburn 124: use Apache::loncoursequeueadmin;
1.30 raeburn 125: use Apache::lonuserutils;
1.4 raeburn 126: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 127:
128: sub handler {
129: my ($r) = @_;
1.20 raeburn 130: &Apache::loncommon::content_type($r,'text/html');
131: $r->send_http_header;
1.1 raeburn 132: if ($r->header_only) {
133: return OK;
134: }
135:
1.27 raeburn 136: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
137: ['action','showdom','cnum','state']);
1.2 raeburn 138: &Apache::lonhtmlcommon::clear_breadcrumbs();
139: my $dom = &get_course_dom();
1.1 raeburn 140: my $action = $env{'form.action'};
141: my $state = $env{'form.state'};
1.27 raeburn 142: my (%states,%stored);
143: my ($jscript,$uname,$udom,$result,$warning);
144:
145: $states{'display'} = ['details'];
146: $states{'view'} = ['pick_request','details','cancel','removal'];
147: $states{'log'} = ['filter','display'];
148: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
149:
150: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
151: unless ($env{'form.state'} eq 'crstype') {
152: unshift(@{$states{'new'}},'codepick');
153: }
154: }
155:
156: foreach my $key (keys(%states)) {
157: if (ref($states{$key}) eq 'ARRAY') {
158: unshift (@{$states{$key}},'crstype');
159: }
160: }
161:
162: my @invalidcrosslist;
163: my %trail = (
164: crstype => 'Course Request Action',
165: codepick => 'Category',
166: courseinfo => 'Description',
167: enrollment => 'Access Dates',
168: personnel => 'Personnel',
169: review => 'Review',
170: process => 'Result',
171: pick_request => 'Display Summary',
172: details => 'Request Details',
173: cancel => 'Cancel Request',
174: removal => 'Outcome',
175: );
176:
177: if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
178: $trail{'enrollment'} = 'Enrollment';
179: }
180:
1.36 raeburn 181: my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) =
1.27 raeburn 182: &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
1.26 raeburn 183: if ($action eq 'display') {
184: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
185: my $namespace = 'courserequestqueue';
186: if ($env{'form.cnum'} ne '') {
187: my $cnum = $env{'form.cnum'};
188: my $reqkey = $cnum.'_approval';
189: my $namespace = 'courserequestqueue';
190: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
191: my %queued =
192: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
193: if (ref($queued{$reqkey}) eq 'HASH') {
194: $uname = $queued{$reqkey}{'ownername'};
195: $udom = $queued{$reqkey}{'ownerdom'};
196: if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
197: $result = &retrieve_settings($dom,$cnum,$udom,$uname);
198: } else {
199: $warning = &mt('Invalid username or domain for course requestor');
200: }
201: } else {
202: $warning = &mt('No information was found for this course request.');
203: }
204: } else {
205: $warning = &mt('No course request ID provided.');
206: }
207: } else {
208: $warning = &mt('You do not have rights to view course request information.');
209: }
210: } elsif ((defined($state)) && (defined($action))) {
1.16 raeburn 211: if (($action eq 'view') && ($state eq 'details')) {
212: if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
213: my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
1.2 raeburn 214: }
1.27 raeburn 215: } elsif ($env{'form.crstype'} eq 'official') {
216: if (&Apache::lonnet::auto_run('',$dom)) {
217: if (($action eq 'new') && (($state eq 'enrollment') ||
218: ($state eq 'personnel'))) {
219: my $checkcrosslist = 0;
220: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
221: if ($env{'form.crosslist_'.$i}) {
222: $checkcrosslist ++;
223: }
224: }
225: if ($checkcrosslist) {
226: my %codechk;
227: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
228: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,
229: \%cat_titles,
230: \%cat_order,
231: \@code_order);
232: my $numtitles = scalar(@codetitles);
233: if ($numtitles) {
234: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
235: if ($env{'form.crosslist_'.$i}) {
236: my $codecheck;
237: my $crosslistcode = '';
238: foreach my $item (@code_order) {
239: $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item};
240: }
1.36.2.1 gci 241: if ($crosslistcode ne '') {
242: ($codechk{$i}, my $rest) =
1.27 raeburn 243: &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
244: }
245: unless ($codechk{$i} eq 'valid') {
246: $env{'form.crosslist_'.$i} = '';
247: push(@invalidcrosslist,$crosslistcode);
248: }
249: }
250: }
251: }
252: }
253: }
254: }
1.2 raeburn 255: }
1.16 raeburn 256: my %elements = &form_elements($dom);
1.2 raeburn 257: my $elementsref = {};
258: if (ref($elements{$action}) eq 'HASH') {
259: if (ref($elements{$action}{$state}) eq 'HASH') {
260: $elementsref = $elements{$action}{$state};
261: }
262: }
1.16 raeburn 263: if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
264: $env{'form.clonedom'} = $dom;
265: }
1.30 raeburn 266: if ($state eq 'crstype') {
267: $jscript = &mainmenu_javascript();
268: } else {
269: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
270: }
1.2 raeburn 271: }
272:
273: if ($state eq 'personnel') {
274: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
275: }
276:
277: my $loaditems = &onload_action($action,$state);
278:
1.1 raeburn 279: my %can_request;
280: my $canreq = &check_can_request($dom,\%can_request);
281: if ($action eq 'new') {
282: if ($canreq) {
283: if ($state eq 'crstype') {
1.3 raeburn 284: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
285: $crumb);
1.1 raeburn 286: } else {
1.27 raeburn 287: &request_administration($r,$action,$state,$page,\%states,$dom,
288: $jscript,$loaditems,$crumb,$newinstcode,
1.36 raeburn 289: $codechk,$checkedcode,$description,
290: \@invalidcrosslist);
1.1 raeburn 291: }
292: } else {
1.3 raeburn 293: $r->print(&header('Course Requests').$crumb.
1.1 raeburn 294: '<div class="LC_warning">'.
295: &mt('You do not have privileges to request creation of courses.').
1.2 raeburn 296: '</div>'.&Apache::loncommon::end_page());
1.1 raeburn 297: }
298: } elsif ($action eq 'view') {
1.10 raeburn 299: if ($state eq 'crstype') {
1.30 raeburn 300: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb);
1.26 raeburn 301: } else {
302: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
303: $loaditems,$crumb);
304: }
305: } elsif ($action eq 'display') {
306: if ($warning ne '') {
307: my $args = { only_body => 1 };
308: $r->print(&header('Course Requests','','',$args).$crumb.
309: '<h3>'.&mt('Course Request Details').'</h3>'.
310: '<div class="LC_warning">'.$warning.'</div>'.
311: &close_popup_form());
1.11 raeburn 312: } else {
1.26 raeburn 313: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.36 raeburn 314: $loaditems,$crumb,'','','','','',$uname,$udom);
1.10 raeburn 315: }
1.1 raeburn 316: } elsif ($action eq 'log') {
1.3 raeburn 317: &print_request_logs($jscript,$loaditems,$crumb);
1.1 raeburn 318: } else {
1.3 raeburn 319: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
1.1 raeburn 320: }
321: return OK;
322: }
323:
1.30 raeburn 324: sub mainmenu_javascript {
325: return <<"END";
326: function setType(courseForm) {
327: for (var i=0; i<courseForm.crstype.length; i++) {
328: if (courseForm.crstype.options[i].value == "$env{'form.crstype'}") {
329: courseForm.crstype.options[i].selected = true;
330: } else {
331: courseForm.crstype.options[i].selected = false;
332: }
333: }
334: }
335:
336: function setAction(courseForm) {
337: for (var i=0; i<courseForm.action.length; i++) {
338: if (courseForm.action.options[i].value == "$env{'form.action'}") {
339: courseForm.action.options[i].selected = true;
340: } else {
341: courseForm.action.options[i].selected = false;
342: }
343: }
344: }
345: END
346: }
347:
1.27 raeburn 348: sub get_breadcrumbs {
349: my ($dom,$action,$state,$states,$trail) = @_;
1.36 raeburn 350: my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description);
1.27 raeburn 351: my $page = 0;
352: if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) {
353: if (defined($action)) {
354: my $done = 0;
355: my $i=0;
356: if (ref($states->{$action}) eq 'ARRAY') {
357: while ($i<@{$states->{$action}} && !$done) {
358: if ($states->{$action}[$i] eq $$state) {
359: $page = $i;
360: $done = 1;
361: }
362: $i++;
363: }
364: }
365: if ($env{'form.crstype'} eq 'official') {
366: if ($page > 1) {
367: if ($states->{$action}[$page-1] eq 'codepick') {
368: if ($env{'form.instcode'} eq '') {
369: ($newinstcode,$numtitles) = &get_instcode($dom);
370: if ($numtitles) {
371: if ($newinstcode eq '') {
372: $$state = 'codepick';
373: $page --;
374: } else {
1.36 raeburn 375: ($codechk,$description) =
1.27 raeburn 376: &Apache::lonnet::auto_validate_instcode('',
377: $dom,$newinstcode);
378: if ($codechk ne 'valid') {
379: $$state = 'codepick';
380: $page --;
381: }
382: $checkedcode = 1;
383: }
384: }
385: }
386: }
387: }
388: }
389: for (my $i=0; $i<@{$states->{$action}}; $i++) {
390: if ($$state eq $states->{$action}[$i]) {
391: &Apache::lonhtmlcommon::add_breadcrumb(
392: {text=>"$trail->{$$state}"});
393: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
394: last;
395: } else {
396: if (($$state eq 'process') || ($$state eq 'removal')) {
397: &Apache::lonhtmlcommon::add_breadcrumb(
398: { href => '/adm/requestcourse',
399: text => "$trail->{$states->{$action}[$i]}",
400: }
401: );
402: } else {
403: &Apache::lonhtmlcommon::add_breadcrumb(
404: { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')",
405: text => "$trail->{$states->{$action}[$i]}", }
406: );
407: }
408: }
409: }
410: } else {
411: &Apache::lonhtmlcommon::add_breadcrumb(
412: {text=>'Pick Action'});
413: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
414: }
415: } else {
416: &Apache::lonhtmlcommon::add_breadcrumb(
417: {text=>'Pick Action'});
418: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
419: }
1.36 raeburn 420: return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
1.27 raeburn 421: }
422:
1.2 raeburn 423: sub header {
1.26 raeburn 424: my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
1.2 raeburn 425: if ($jscript) {
1.6 raeburn 426: $jscript = '<script type="text/javascript">'."\n".
427: '// <![CDATA['."\n".
428: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
1.2 raeburn 429: }
430: if ($loaditems) {
1.26 raeburn 431: if (ref($args) eq 'HASH') {
432: my %loadhash = (
433: 'add_entries' => $loaditems,
434: );
435: my %arghash = (%loadhash,%{$args});
436: $args = \%arghash;
437: } else {
438: $args = {'add_entries' => $loaditems,};
439: }
1.3 raeburn 440: }
1.26 raeburn 441: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
1.2 raeburn 442: }
443:
444: sub form_elements {
445: my ($dom) = @_;
446: my %elements =
447: (
448: new => {
449: crstype => {
450: crstype => 'selectbox',
451: action => 'selectbox',
1.16 raeburn 452: origcnum => 'hidden',
1.2 raeburn 453: },
454: courseinfo => {
455: cdescr => 'text',
1.13 raeburn 456: clonecrs => 'text',
457: clonedom => 'selectbox',
1.2 raeburn 458: datemode => 'radio',
459: dateshift => 'text',
460: },
461: enrollment => {
1.13 raeburn 462: accessstart_month => 'selectbox',
463: accessstart_hour => 'selectbox',
464: accessend_month => 'selectbox',
465: accessend_hour => 'selectbox',
466: accessstart_day => 'text',
467: accessstart_year => 'text',
468: accessstart_minute => 'text',
469: accessstart_second => 'text',
470: accessend_day => 'text',
471: accessend_year => 'text',
472: accessend_minute => 'text',
473: accessend_second => 'text',
1.2 raeburn 474: no_end_date => 'checkbox',
475: },
476: personnel => {
477: addperson => 'checkbox',
478: },
1.13 raeburn 479: review => {
480: cnum => 'hidden',
481: },
1.2 raeburn 482: },
483: view => {
484: crstype => {
485: crstype => 'selectbox',
486: action => 'selectbox',
487: },
488: },
489: );
1.13 raeburn 490: my %servers = &Apache::lonnet::get_servers($dom,'library');
491: my $numlib = keys(%servers);
492: if ($numlib > 1) {
493: $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
494: } else {
495: $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
496: }
1.2 raeburn 497: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
498: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
499: \%cat_order,\@code_order);
500: my $numtitles = scalar(@codetitles);
501: if ($numtitles) {
502: my %extras;
503: $lastitem = pop(@codetitles);
504: $extras{'instcode_'.$lastitem} = 'text';
505: foreach my $item (@codetitles) {
506: $extras{'instcode_'.$item} = 'selectbox';
507: }
508: $elements{'new'}{'codepick'} = \%extras;
509: }
510: if (&Apache::lonnet::auto_run('',$dom)) {
511: my %extras = (
512: sectotal => 'hidden',
1.13 raeburn 513: enrollstart_month => 'selectbox',
514: enrollstart_hour => 'selectbox',
515: enrollend_month => 'selectbox',
516: enrollend_hour => 'selectbox',
517: enrollstart_day => 'text',
518: enrollstart_year => 'text',
519: enrollstart_minute => 'text',
520: enrollstart_second => 'text',
521: enrollend_day => 'text',
522: enrollend_year => 'text',
523: enrollend_minute => 'text',
524: enrollend_second => 'text',
1.2 raeburn 525: addcrosslist => 'checkbox',
526: autoadds => 'radio',
527: autodrops => 'radio',
528: );
529: if ($env{'form.sectotal'} > 0) {
530: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31 raeburn 531: $extras{'sec_'.$i} = 'radio';
532: $extras{'secnum_'.$i} = 'text';
533: $extras{'loncapasec_'.$i} = 'text';
1.2 raeburn 534: }
535: }
536: my $crosslisttotal = $env{'form.crosslisttotal'};
1.16 raeburn 537: if ($env{'form.addcrosslist'}) {
538: $crosslisttotal ++;
539: }
1.24 raeburn 540: if (!$crosslisttotal) {
1.2 raeburn 541: $crosslisttotal = 1;
542: }
1.27 raeburn 543:
1.24 raeburn 544: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
545: if ($numtitles) {
546: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
547: }
548: if (@codetitles > 0) {
549: foreach my $item (@codetitles) {
550: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
1.2 raeburn 551: }
552: }
1.24 raeburn 553: $extras{'crosslist_'.$i} = 'checkbox';
554: $extras{'crosslist_'.$i.'_instsec'} = 'text',
555: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
1.2 raeburn 556: }
557: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
558: %{$elements{'new'}{'enrollment'}} = %mergedhash;
559: }
560: my %people;
561: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 562: if ($env{'form.addperson'}) {
563: $persontotal ++;
564: }
565: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 566: $persontotal = 1;
567: }
568: for (my $i=0; $i<$persontotal; $i++) {
1.13 raeburn 569: $people{'person_'.$i.'_uname'} = 'text',
570: $people{'person_'.$i.'_dom'} = 'selectbox',
571: $people{'person_'.$i.'_hidedom'} = 'hidden',
572: $people{'person_'.$i.'_firstname'} = 'text',
573: $people{'person_'.$i.'_lastname'} = 'text',
574: $people{'person_'.$i.'_emailaddr'} = 'text',
575: $people{'person_'.$i.'_role'} = 'selectbox',
576: $people{'person_'.$i.'_sec'} = 'selectbox',
577: $people{'person_'.$i.'_newsec'} = 'text',
1.2 raeburn 578: }
579: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
580: %{$elements{'new'}{'personnel'}} = %personnelhash;
581: return %elements;
582: }
583:
584: sub onload_action {
585: my ($action,$state) = @_;
586: my %loaditems;
587: if (($action eq 'new') || ($action eq 'view')) {
1.30 raeburn 588: if ($state eq 'crstype') {
589: $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
590: } else {
591: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs)';
592: }
1.2 raeburn 593: }
594: return \%loaditems;
595: }
596:
1.1 raeburn 597: sub check_can_request {
598: my ($dom,$can_request) = @_;
599: my $canreq = 0;
1.4 raeburn 600: my ($types,$typename) = &course_types();
1.19 raeburn 601: my @options = ('approval','validate','autolimit');
602: my $optregex = join('|',@options);
1.4 raeburn 603: if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) {
604: foreach my $type (@{$types}) {
1.1 raeburn 605: if (&Apache::lonnet::usertools_access($env{'user.name'},
606: $env{'user.domain'},
607: $type,undef,'requestcourses')) {
608: $canreq ++;
609: if ($dom eq $env{'user.domain'}) {
610: $can_request->{$type} = 1;
611: }
612: }
613: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
614: my @curr = split(',',$env{'environment.reqcrsotherdom.'.$type});
615: if (@curr > 0) {
616: $canreq ++;
617: unless ($dom eq $env{'user.domain'}) {
1.19 raeburn 618: if (grep(/^\Q$dom\E:($optregex)(=?\d*)$/,@curr)) {
1.1 raeburn 619: $can_request->{$type} = 1;
620: }
621: }
622: }
623: }
624: }
625: }
626: return $canreq;
627: }
628:
1.4 raeburn 629: sub course_types {
1.36.2.1 gci 630: my @types = ('unofficial');
1.4 raeburn 631: my %typename = (
632: official => 'Official course',
633: unofficial => 'Unofficial course',
634: community => 'Community',
1.35 raeburn 635: );
1.4 raeburn 636: return (\@types,\%typename);
637: }
638:
639:
1.1 raeburn 640: sub print_main_menu {
1.3 raeburn 641: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_;
1.4 raeburn 642: my ($types,$typename) = &course_types();
1.1 raeburn 643: my $onchange;
644: unless ($env{'form.interface'} eq 'textual') {
645: $onchange = 1;
646: }
647:
1.2 raeburn 648: my $nextstate_setter = "\n";
649: if (ref($states) eq 'HASH') {
650: foreach my $key (keys(%{$states})) {
651: if (ref($states->{$key}) eq 'ARRAY') {
652: $nextstate_setter .=
653: " if (actionchoice == '$key') {
654: nextstate = '".$states->{$key}[1]."';
655: }
656: ";
657: }
658: }
659: }
1.1 raeburn 660:
1.36.2.2! raeburn 661: my $standby=&mt('Course selected. Please stand by.');
1.2 raeburn 662: my $js = <<"END";
1.1 raeburn 663:
1.36.2.2! raeburn 664: function enterrole (thisform,rolecode,buttonname) {
! 665: document.title='$standby';
! 666: window.status='$standby';
! 667: thisform.newrole.value=rolecode;
! 668: thisform.selectrole.value='1';
! 669: thisform.submit();
! 670: }
! 671:
! 672: function ToSyllabus(cdom,cnum) {
! 673: if (cdom == '' || cdom == null) {
! 674: return;
! 675: }
! 676: if (cnum == '' || cnum == null) {
! 677: return;
! 678: }
! 679: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
! 680: var url = "/public/"+cdom+"/"+cnum+"/syllabus";
! 681: syllwin = window.open(url,'',options,1);
! 682: syllwin.focus();
! 683: return;
! 684: }
! 685:
1.2 raeburn 686: function nextPage(formname) {
1.27 raeburn 687: var crschoice = document.mainmenu_coursetype.crstype.value;
688: var actionchoice = document.mainmenu_action.action.value;
1.2 raeburn 689: if (check_can_request(crschoice,actionchoice) == true) {
690: if ((actionchoice == 'new') && (crschoice == 'official')) {
691: nextstate = 'codepick';
692: } else {
693: $nextstate_setter
1.27 raeburn 694: }
695: formname.crstype.value = crschoice;
696: formname.action.value = actionchoice;
1.1 raeburn 697: formname.state.value= nextstate;
698: formname.submit();
699: }
700: return;
701: }
702:
1.2 raeburn 703: function check_can_request(crschoice,actionchoice) {
1.1 raeburn 704: var official = '';
705: var unofficial = '';
706: var community = '';
707: END
708:
709: foreach my $item (keys(%{$can_request})) {
710: $js .= "
711: $item = 1;
712: ";
713: }
714: my %lt = &Apache::lonlocal::texthash(
715: official => 'You are not permitted to request creation of an official course in this domain.',
716: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
717: community => 'You are not permitted to request creation of a community this domain.',
718: all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
719: );
720: $js .= <<END;
721: if (crschoice == 'official') {
722: if (official != 1) {
723: alert("$lt{'official'}");
724: return false;
725: }
726: } else {
727: if (crschoice == 'unofficial') {
728: if (unofficial != 1) {
729: alert("$lt{'unofficial'}");
730: return false;
731: }
732: } else {
733: if (crschoice == 'community') {
734: if (community != 1) {
735: alert("$lt{'community'}");
736: return false;
737: }
738: } else {
739: if (actionchoice == 'new') {
740: alert("$lt{'all'}");
741: return false;
742: }
743: }
744: }
745: }
746: return true;
747: }
748:
749: END
1.36.2.2! raeburn 750: $r->print(&header('Concept Test Courses',$js.$jscript,$loaditems).$crumb);
! 751: my $existing = &existing_courses();
! 752: if ($existing) {
! 753: $r->print('<div class="LC_left_float">'.
! 754: '<h3>'.&mt('Request creation of a new course').'</h3>');
! 755: } else {
! 756: $r->print('<div><h3>'.&mt('Request creation of a new course, or review your pending course requests.').'</h3>');
! 757: }
! 758: $r->print('<p>'.
1.27 raeburn 759: &Apache::lonhtmlcommon::start_pick_box().
760: &Apache::lonhtmlcommon::row_title(&mt('Course Domain')).
1.36.2.1 gci 761: '<form name="domforcourse" method="post" action="/adm/requestcourse">');
762: $r->print('GCI Web Center Concept Test Delivery (gcitest)'."\n".
763: '<input type="hidden" value="gcitest" name="showdom" />');
1.27 raeburn 764: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
1.1 raeburn 765:
1.2 raeburn 766: my $formname = 'requestcrs';
1.1 raeburn 767: my $nexttext = &mt('Next');
1.27 raeburn 768: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
769: <form name="mainmenu_action" method="post" action="">
1.1 raeburn 770: <select size="1" name="action" >
1.2 raeburn 771: <option value="new">'.&mt('New request').'</option>
1.1 raeburn 772: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
1.27 raeburn 773: </select></form>'.
774: &Apache::lonhtmlcommon::row_closure(1).
1.36.2.1 gci 775: &Apache::lonhtmlcommon::row_title(&mt('Course Type')).
776: &mt($typename->{'unofficial'})."\n".
777: '<form name="mainmenu_coursetype" method="post" action="">'."\n".
778: '<input type="hidden" name="crstype" value="unofficial" ></form>'."\n".
1.27 raeburn 779: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.36.2.2! raeburn 780: &Apache::lonhtmlcommon::end_pick_box().'</p>'."\n".
! 781: '<p><form name="'.$formname.'" method="post" action="">'."\n".
1.27 raeburn 782: '<input type="hidden" name="state" value="crstype" />'."\n".
783: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
784: '<input type="hidden" name="crstype" value="" />'."\n".
785: '<input type="hidden" name="action" value="" />'."\n".
786: '<input type="button" name="next" value="'.$nexttext.
787: '" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
1.36.2.2! raeburn 788: '</form></p>');
! 789: if ($existing) {
! 790: $r->print('</div><div class="LC_left_float"><h3>'.&mt('Enter an existing Concept Test course').'</h3>'.$existing.'</div><div class="LC_clear_float_footer"></div>');
! 791: } else {
! 792: $r->print('</div>');
! 793: }
1.1 raeburn 794: $r->print(&Apache::loncommon::end_page());
795: return;
796: }
797:
1.36.2.2! raeburn 798: sub existing_courses {
! 799: my $output;
! 800: my %roleshash = &Apache::lonnet::get_my_roles(undef,undef,'userroles',undef,
! 801: ['cc'],['gcitest']);
! 802: my %courses;
! 803: if (keys(%roleshash) > 0) {
! 804: foreach my $key (keys(%roleshash)) {
! 805: my ($cnum,$cdom,$role) = split(':',$key);
! 806: my ($tstart,$tend) = split(':',$roleshash{$key});
! 807: my %coursehash = &Apache::lonnet::coursedescription($cdom.'/'.$cnum);
! 808: $courses{$cdom.'_'.$cnum}{'description'} = $coursehash{'description'};
! 809: $courses{$cdom.'_'.$cnum}{'owner'} = $coursehash{'internal.courseowner'};
! 810: if (defined($coursehash{'default_enrollment_start_date'}) ) {
! 811: $courses{$cdom.'_'.$cnum}{'startaccess'} =
! 812: &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
! 813: }
! 814: if (defined($coursehash{'default_enrollment_end_date'}) ) {
! 815: $courses{$cdom.'_'.$cnum}{'endaccess'} =
! 816: &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
! 817: if ($coursehash{'default_enrollment_end_date'} == 0) {
! 818: $courses{$cdom.'_'.$cnum}{'endaccess'} = &mt('No ending date');
! 819: }
! 820: }
! 821: }
! 822: $output = '<form name="pickrole" action="/adm/roles" method="post">'.
! 823: &Apache::loncommon::start_data_table().
! 824: &Apache::loncommon::start_data_table_header_row();
! 825: my @coltitles = ('Select','Title','Owner(s)',
! 826: 'Default Access Dates for Students','Student Counts');
! 827: foreach my $item (@coltitles) {
! 828: $output .= '<th>';
! 829: if ($item eq 'Select') {
! 830: $output .= ' ';
! 831: } else {
! 832: $output .= &mt($item);
! 833: }
! 834: $output .= '</th>';
! 835: }
! 836: $output .= &Apache::loncommon::end_data_table_header_row();
! 837: my %courseinfo = &build_courseinfo_hash(\%courses);
! 838: my %Sortby;
! 839: foreach my $course (sort(keys(%courses))) {
! 840: my $clean_title = $courseinfo{$course}{'title'};
! 841: $clean_title =~ s/\W+//g;
! 842: if ($clean_title eq '') {
! 843: $clean_title = $courseinfo{$course}{'title'};
! 844: }
! 845: push(@{$Sortby{$clean_title}},$course);
! 846: }
! 847: my @sorted_courses;
! 848: my @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
! 849: foreach my $item (@sorted_courses) {
! 850: foreach my $course (@{$Sortby{$item}}) {
! 851: my ($cdom,$cnum) = split('_',$course);
! 852: $output.= &Apache::loncommon::start_data_table_row().
! 853: &courseinfo_row($courseinfo{$course},$cnum,$cdom).
! 854: &Apache::loncommon::end_data_table_row();
! 855: }
! 856: }
! 857: $output .= &Apache::loncommon::end_data_table().
! 858: '<input type="hidden" name="newrole" value="" />'.
! 859: '<input type="hidden" name="selectrole" value="" /></form>';
! 860: }
! 861: return $output;
! 862: }
! 863:
! 864: sub build_courseinfo_hash {
! 865: my ($courses) = @_;
! 866: my %courseinfo;
! 867: foreach my $course (keys(%{$courses})) {
! 868: my ($cdom,$cnum) = split('_',$course);
! 869: my $descr;
! 870: if (ref($courses->{$course}) eq 'HASH') {
! 871: $descr = $courses->{$course}{'description'};
! 872: }
! 873: my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
! 874: $cleandesc=~s/'/\\'/g;
! 875: $cleandesc =~ s/^\s+//;
! 876: my ($cdom,$cnum)=split(/\_/,$course);
! 877: my ($singleowner,@owners,%ownernames);
! 878: if (ref($courses->{$course}) eq 'HASH') {
! 879: $singleowner = $courses->{$course}{'owner'};
! 880: push(@owners,$singleowner);
! 881: if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') {
! 882: foreach my $item (@{$courses->{$course}{'co-owners'}}) {
! 883: push(@owners,$item);
! 884: }
! 885: }
! 886: }
! 887: foreach my $owner (@owners) {
! 888: my ($ownername,$ownerdom);
! 889: if ($owner =~ /:/) {
! 890: ($ownername,$ownerdom) = split(/:/,$owner);
! 891: } else {
! 892: $ownername = $owner;
! 893: if ($owner ne '') {
! 894: $ownerdom = $cdom;
! 895: }
! 896: }
! 897: if ($ownername ne '' && $ownerdom ne '') {
! 898: my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
! 899: $ownernames{$ownername.':'.$ownerdom} = \%namehash;
! 900: }
! 901: }
! 902: $courseinfo{$course}{'cdom'} = $cdom;
! 903: $courseinfo{$course}{'cnum'} = $cnum;
! 904: my @lastnames;
! 905: foreach my $owner (keys(%ownernames)) {
! 906: if (ref($ownernames{$owner}) eq 'HASH') {
! 907: push(@lastnames,$ownernames{$owner}{'lastname'});
! 908: }
! 909: }
! 910: $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames));
! 911: $courseinfo{$course}{'title'} = $cleandesc;
! 912: $courseinfo{$course}{'owner'} = $singleowner;
! 913: my @classids;
! 914: $courseinfo{$course}{'counts'} = &count_students($cdom,$cnum,0);
! 915: my $startaccess = $courses->{$course}{'startaccess'};
! 916: my $endaccess = $courses->{$course}{'endaccess'};
! 917: my $accessdates;
! 918: if ($startaccess) {
! 919: $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$startaccess).'<br />';
! 920: }
! 921: if ($endaccess) {
! 922: $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$endaccess).'<br />';
! 923: }
! 924: $courseinfo{$course}{'access'} = $accessdates;
! 925: }
! 926: return %courseinfo;
! 927: }
! 928:
! 929: sub courseinfo_row {
! 930: my ($info,$cnum,$cdom) = @_;
! 931: my $output;
! 932: if (ref($info) eq 'HASH') {
! 933: my $rolecode = 'cc./'.$cdom.'/'.$cnum;
! 934: my $buttonname = $rolecode;
! 935: $buttonname=~s/\W//g;
! 936: $output .= '<td><input type="button" name="'.$buttonname.'" value="'.&mt('Select').'" onclick="javascript:enterrole(this.form,'."'$rolecode','$buttonname'".')" ></td>'.
! 937: '<td>'.$info->{'title'}.' <font size="-2">'.
! 938: '<a href="javascript:ToSyllabus('."'$cdom','$cnum'".')">'.
! 939: &mt('Syllabus').'</a></font></td>'.
! 940: '<td>'.$info->{'ownerlastnames'}.'</td>'.
! 941: '<td>'.$info->{'access'}.'</td>'.
! 942: '<td>'.$info->{'counts'}.'</td>';
! 943: } else {
! 944: $output = '<td colspan="4">'.&mt('No information available for [_1].',
! 945: $cdom.'_'.$cnum).'</td>';
! 946: return $output;
! 947: }
! 948: return $output;
! 949: }
! 950:
! 951: sub count_students {
! 952: my ($cdom,$cnum,$numsec) = @_;
! 953: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
! 954: my %student_count = (
! 955: Active => 0,
! 956: Future => 0,
! 957: Expired => 0,
! 958: );
! 959: my %idx;
! 960: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
! 961: my %status_title = &Apache::lonlocal::texthash(
! 962: Expired => 'Previous access',
! 963: Active => 'Current access',
! 964: Future => 'Future access',
! 965: );
! 966:
! 967: while (my ($student,$data) = each(%$classlist)) {
! 968: $student_count{$data->[$idx{'status'}]} ++;
! 969: }
! 970:
! 971: my $countslist = &mt('[quant,_1,section:,sections:,No sections]',$numsec).'<br />';
! 972: foreach my $status ('Active','Future') {
! 973: $countslist .= '<span class="LC_nobreak">'.$status_title{$status}.': '.
! 974: $student_count{$status}.'</span><br />';
! 975: }
! 976: return $countslist;
! 977: }
! 978:
! 979:
1.1 raeburn 980: sub request_administration {
1.27 raeburn 981: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
1.36 raeburn 982: $newinstcode,$codechk,$checkedcode,$description,$invalidcrosslist,
983: $uname,$udom) = @_;
1.2 raeburn 984: my $js;
1.16 raeburn 985: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
1.2 raeburn 986: $js = <<END;
1.1 raeburn 987:
988: function nextPage(formname,nextstate) {
989: formname.state.value= nextstate;
990: formname.submit();
991: }
1.16 raeburn 992:
993: END
994: }
995: if (($action eq 'new') || ($action eq 'view')) {
996: $js .= <<END;
997:
1.1 raeburn 998: function backPage(formname,prevstate) {
999: formname.state.value = prevstate;
1000: formname.submit();
1001: }
1002:
1003: END
1.2 raeburn 1004: }
1005: if ($action eq 'new') {
1006: my $jsextra;
1.31 raeburn 1007: if ($state eq 'courseinfo') {
1.2 raeburn 1008: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
1.31 raeburn 1009: } elsif ($state eq 'enrollment') {
1010: if (($env{'form.crstype'} eq 'official') &&
1011: (&Apache::lonnet::auto_run('',$dom))) {
1012: $js .= "\n".§ion_check_javascript()."\n".&enrollment_lcsec_js();
1013: }
1014: } elsif ($state eq 'personnel') {
1015: $js .= "\n".§ion_check_javascript()."\n".&personnel_lcsec_js();
1.1 raeburn 1016: }
1.3 raeburn 1017: $r->print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb);
1.27 raeburn 1018: &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
1.36 raeburn 1019: $codechk,$checkedcode,$description,$invalidcrosslist);
1.2 raeburn 1020: } elsif ($action eq 'view') {
1.16 raeburn 1021: my $jsextra;
1022: my $formname = 'requestcrs';
1023: my $prev = $states->{$action}[$page-1];
1024: my $next = $states->{$action}[$page+1];
1025: if ($state eq 'pick_request') {
1026: $next = $states->{$action}[$page+1];
1027: $jsextra = &viewrequest_javascript($formname,$next);
1028: } elsif ($state eq 'details') {
1029: $jsextra = &viewdetails_javascript($formname);
1030:
1031: } elsif ($state eq 'cancel') {
1032: $jsextra = &viewcancel_javascript($formname);
1033: }
1034: $r->print(&header('Manage course requests',$js.$jscript.$jsextra,$loaditems).
1035: $crumb);
1036: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
1.11 raeburn 1037: if ($state eq 'pick_request') {
1.16 raeburn 1038: $r->print('<h3>'.&mt('Pending course requests').'</h3><div>'."\n".$form."\n".
1.30 raeburn 1039: &print_request_status($dom).'</form></div>');
1.16 raeburn 1040: } elsif ($state eq 'details') {
1041: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1042: my $origcnum = $env{'form.cnum'};
1043: if ($origcnum eq '') {
1044: $origcnum = $env{'form.origcnum'};
1045: }
1046: if ($env{'form.crstype'} eq 'official') {
1047: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1048: \%cat_order,\@code_order);
1049: }
1050: $r->print('<h3>'.&mt('Course Request Details').'</h3><div>'."\n".$form."\n".
1.26 raeburn 1051: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.16 raeburn 1052: \@code_order)."\n".
1053: '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
1054: my @excluded = &get_excluded_elements($dom,$states,'new','review');
1055: push(@excluded,'origcnum');
1056: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
1057: my $other = 'modify';
1058: my %navtxt = &Apache::lonlocal::texthash (
1059: prev => 'Back',
1060: other => 'Modify Request',
1061: next => 'Cancel Request',
1062: );
1.31 raeburn 1063: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1064: $navtxt{'next'},$state,$other,$navtxt{'other'});
1.16 raeburn 1065: $r->print('</form>');
1066: } elsif ($state eq 'cancel') {
1067: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
1068: $r->print('<h3>'.&mt('Cancel course request').'</h3><div>'."\n".$form."\n".
1069: $output);
1070: my @excluded = &get_excluded_elements($dom,$states,'view','cancel');
1071: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
1072: my %navtxt = &Apache::lonlocal::texthash (
1073: prev => 'Back',
1074: next => 'Confirm Cancellation',
1075: );
1076: if ($result eq 'ok') {
1.31 raeburn 1077: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1.16 raeburn 1078: $navtxt{'next'},$state);
1079: } else {
1.31 raeburn 1080: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef,
1081: '',$state);
1.16 raeburn 1082: }
1083: $r->print('</form>');
1084: } elsif ($state eq 'removal') {
1085: my $cnum = $env{'form.origcnum'};
1086: my $statuskey = 'status:'.$dom.':'.$cnum;
1087: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
1088: $env{'user.domain'},$env{'user.name'});
1089: my $currstatus = $userreqhash{$statuskey};
1090: my ($result,$error);
1091: if (($currstatus eq 'approval') || ($currstatus eq 'pending')) {
1092: my %status = (
1093: $statuskey => 'cancelled',
1094: );
1095: my $statusresult = &Apache::lonnet::put('courserequests',\%status);
1096: if ($statusresult eq 'ok') {
1097: my $delresult =
1098: &Apache::lonnet::del_dom('courserequestqueue',
1099: [$cnum.'_'.$currstatus],$dom);
1100: if ($delresult eq 'ok') {
1101: $result = 'ok';
1102: } else {
1103: $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
1104: }
1105: } else {
1106: $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
1107: }
1108: } else {
1109: $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');
1110: }
1111: $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
1112: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
1113: '<input type="hidden" name="action" value="'.$action.'" />'."\n".
1114: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
1115: '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
1116: if ($result eq 'ok') {
1117: $r->print(&mt('Your course request has been cancelled.'));
1118: } else {
1119: $r->print('<div class="LC_error">'.
1120: &mt('The request cancellation process was not complete.').
1121: '<br />'.$error.'</div>');
1122: }
1123: $r->print('</form>');
1.11 raeburn 1124: }
1.26 raeburn 1125: } elsif ($action eq 'display') {
1126: my $formname = 'requestcrs';
1127: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1128: if ($env{'form.crstype'} eq 'official') {
1129: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1130: \%cat_order,\@code_order);
1131: }
1132: $r->print(&header('Course Request','','','',{ 'only_body' => 1}).
1133: $crumb."\n".'<h3>'.&mt('Course Request Details').'</h3>'.
1134: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1135: \@code_order,$uname,$udom)."\n".'</div>'.
1136: &close_popup_form());
1.1 raeburn 1137: } elsif ($action eq 'log') {
1.11 raeburn 1138: $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
1.1 raeburn 1139: }
1.2 raeburn 1140: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 1141: return;
1142: }
1143:
1.31 raeburn 1144: sub enrollment_lcsec_js {
1145: my %alerts = §ion_check_alerts();
1146: my $secname = $alerts{'badsec'};
1147: my $secnone = $alerts{'reserved'};
1148: my $output = '
1149: function validateEnrollSections(formname,nextstate) {
1150: var badsectotal = 0;
1151: var reservedtotal = 0;
1152: var secTest = "";
1153: ';
1154: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1155: $output .= "
1156: var selSec = 0;
1157: for (var j=0; j<document.requestcrs.sec_".$i.".length; j++) {
1158: if (document.requestcrs.sec_".$i."[j].checked) {
1159: selSec = document.requestcrs.sec_".$i."[j].value;
1160: }
1161: if (selSec == 1) {
1162: secTest = validsection(document.requestcrs.loncapasec_".$i.");
1163: if (secTest == 'badsec') {
1164: badsectotal++;
1165: }
1166: if (secTest == 'reserved') {
1167: reservedtotal++;
1168: }
1169: }
1170: }
1171: ";
1172: }
1173: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1174: $output .= "
1175: if (document.requestcrs.crosslist_".$i.".checked) {
1176: secTest = validsection(document.requestcrs.crosslist_".$i."_lcsec);
1177: if (secTest == 'badsec') {
1178: badsectotal++;
1179: }
1180: if (secTest == 'reserved') {
1181: reservedtotal++;
1182: }
1183: }
1184: ";
1185: }
1186: $output .= "
1187: if (badsectotal>0) {
1188: alert('$secname');
1189: return false;
1190: }
1191: if (reservedtotal>0) {
1192: alert('$secnone');
1193: return false;
1194: }
1195: formname.state.value= nextstate;
1196: formname.submit();
1197: return;
1198: }
1199: ";
1200: return $output;
1201: }
1202:
1203: sub personnel_lcsec_js {
1204: my %alerts = §ion_check_alerts();
1205: my $secname = $alerts{'badsec'}.'\\n'.$alerts{'separate'};
1206: my $secnone = $alerts{'reserved'};
1207: my $output = '
1208: function validatePersonnelSections(formname,nextstate) {
1209: var badsectotal = 0;
1210: var reservedtotal = 0;
1211: var secTest = "";
1212: ';
1213: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1214: $output .= "
1215: if (document.requestcrs.person_".$i."_uname.value != '') {
1216: secTest = validsection(document.requestcrs.person_".$i."_newsec,'1');
1217: if (secTest == 'badsec') {
1218: badsectotal++;
1219: }
1220: if (secTest == 'reserved') {
1221: reservedtotal++;
1222: }
1223: }
1224: ";
1225: }
1226: $output .= "
1227: if (badsectotal > 0) {
1228: alert('$secname');
1229: return false;
1230: } else {
1231: if (reservedtotal > 0) {
1232: alert('$secnone');
1233: return false;
1234: }
1235: }
1236: formname.state.value = nextstate;
1237: formname.submit();
1238: return;
1239: }
1240: ";
1241: return $output;
1242: }
1243:
1244: sub section_check_alerts {
1245: my %lt =
1246: &Apache::lonlocal::texthash(
1247: 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.",
1248: badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
1249: separate => 'Separate multiple sections with a comma.'
1250: );
1251: return %lt;
1252: }
1253:
1254: sub section_check_javascript {
1255: return <<"END";
1256: function validsection(field,mult) {
1257: var str = field.value;
1258: var badsec=0;
1259: var reserved=0;
1260: if (window.RegExp) {
1261: var badsecnum=0;
1262: var reservednum=0;
1263: var pattern=/[^a-zA-Z0-9]/;
1264: str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
1265: str = str.replace(/[ ]{2,}/gi," ");
1266: if (mult == '1') {
1267: var sections = new Array();
1268: sections = str.split(/\\s*[\\s,;:]\\s*/);
1269: var i;
1270: for (i=0; i<sections.length; i++) {
1271: if ((sections[i] != '') && (sections[i] != undefined) && (sections[i] != null)) {
1272: if (pattern.test(sections[i])) {
1273: badsecnum++;
1274: } else {
1275: if (sections[i] == 'none') {
1276: reservednum++;
1277: }
1278: }
1279: }
1280: }
1281: } else {
1282: if ((str != '') && (str != undefined) && (str != null)) {
1283: if (pattern.test(str)) {
1284: badsecnum++;
1285: } else {
1286: if (str == 'none') {
1287: reservednum++;
1288: }
1289: }
1290: }
1291: }
1292: if (badsecnum > 0) {
1293: return 'badsec';
1294: }
1295: if (reservednum > 0) {
1296: return 'reserved';
1297: }
1298: }
1299: return;
1300: }
1301: END
1302: }
1303:
1.26 raeburn 1304: sub close_popup_form {
1305: my $close= &mt('Close Window');
1306: return << "END";
1307: <p><form name="displayreq" action="" method="post">
1308: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
1309: </form></p>
1310: END
1311: }
1312:
1.27 raeburn 1313: sub get_instcode {
1314: my ($dom) = @_;
1315: my ($instcode,$numtitles);
1316: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1317: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1318: \%cat_order,\@code_order);
1319: $numtitles = scalar(@codetitles);
1320: if (@code_order > 0) {
1321: my $message;
1322: foreach my $item (@code_order) {
1323: $instcode .= $env{'form.instcode_'.$item};
1324: }
1325: }
1326: return ($instcode,$numtitles);
1327: }
1328:
1.1 raeburn 1329: sub print_request_form {
1.27 raeburn 1330: my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
1.36 raeburn 1331: $description,$invalidcrosslist) = @_;
1.1 raeburn 1332: my $formname = 'requestcrs';
1.2 raeburn 1333: my ($next,$prev,$message,$output,$codepicker,$crstype);
1334: $prev = $states->{$action}[$page-1];
1335: $next = $states->{$action}[$page+1];
1.4 raeburn 1336: my %navtxt = &Apache::lonlocal::texthash (
1.10 raeburn 1337: prev => 'Back',
1.4 raeburn 1338: next => 'Next',
1339: );
1.2 raeburn 1340: $crstype = $env{'form.crstype'};
1.34 raeburn 1341: $r->print('<br /><form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.30 raeburn 1342: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
1343: @disallowed);
1.1 raeburn 1344: if ($crstype eq 'official') {
1.2 raeburn 1345: if ($env{'form.instcode'} ne '') {
1346: $instcode = $env{'form.instcode'};
1.27 raeburn 1347: } elsif ($newinstcode ne '') {
1348: $instcode = $newinstcode;
1.2 raeburn 1349: }
1.27 raeburn 1350: if ($checkedcode) {
1351: if ($codechk eq 'valid') {
1352: $message = '<div class="LC_info">'.
1353: &mt('The chosen course category [_1] is valid.','<b>'.
1354: $instcode.'</b>').
1355: '<input type="hidden" name="instcode" value="'.
1356: $instcode.'" /></div>';
1.2 raeburn 1357: } else {
1358: $message = '<div class="LC_warning">'.
1.27 raeburn 1359: &mt('No course was found matching your choice of institutional course category.');
1360: if ($codechk ne '') {
1361: $message .= '<br />'.$codechk;
1362: }
1363: $message .= '</div>';
1.2 raeburn 1364: $prev = 'crstype';
1365: }
1366: $r->print($message);
1.1 raeburn 1367: }
1.2 raeburn 1368: }
1369: if ($prev eq 'crstype') {
1.4 raeburn 1370: if ($crstype eq 'official') {
1371: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1372: \%cat_order,\@code_order);
1373: }
1.2 raeburn 1374: if (@code_order > 0) {
1.1 raeburn 1375: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
1376: \%cat_titles,\%cat_order);
1.2 raeburn 1377: if ($codepicker) {
1.34 raeburn 1378: $r->print(&mt('Specify the course to be created.').
1379: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1380: $codepicker.
1.2 raeburn 1381: &Apache::lonhtmlcommon::end_pick_box().'</div>');
1382: } else {
1.20 raeburn 1383: $next = $states->{$action}[$page+2];
1.15 raeburn 1384: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 1385: }
1386: } else {
1.20 raeburn 1387: if ($crstype eq 'official') {
1388: $next = $states->{$action}[$page+2];
1389: }
1.15 raeburn 1390: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.1 raeburn 1391: }
1.2 raeburn 1392: } elsif ($prev eq 'codepick') {
1.27 raeburn 1393: if ($instcode eq '') {
1.20 raeburn 1394: $prev = $states->{$action}[$page-2];
1395: }
1.36 raeburn 1396: $r->print(&courseinfo_form($dom,$formname,$crstype,$next,$description));
1.2 raeburn 1397: } elsif ($state eq 'enrollment') {
1.4 raeburn 1398: if ($crstype eq 'official') {
1399: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1400: \%cat_order,\@code_order);
1401: }
1.2 raeburn 1402: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
1.27 raeburn 1403: \%cat_titles,\%cat_order,\@code_order,
1404: $invalidcrosslist));
1.2 raeburn 1405: } elsif ($state eq 'personnel') {
1.27 raeburn 1406: $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
1.4 raeburn 1407: } elsif ($state eq 'review') {
1.30 raeburn 1408: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
1409: my $now = time;
1410: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1411: my $personname = $env{'form.person_'.$i.'_uname'};
1412: my $persondom = $env{'form.person_'.$i.'_dom'};
1413: if (($personname =~ /^$match_username$/) &&
1414: ($persondom =~ /^$match_domain$/)) {
1415: if (&Apache::lonnet::domain($persondom)) {
1416: my $personhome =
1417: &Apache::lonnet::homeserver($personname,$persondom);
1418: if ($personhome eq 'no_host') {
1419: if ($persondom ne $dom) {
1420: my $skipuser = 1;
1421: if ($env{'user.role.dc./'.$persondom.'/'}) {
1422: my ($start,$end) = split('.',$env{'user.role.dc./'.$persondom.'/'});
1423: if (((!$start) || ($start < $now)) &&
1424: ((!$end) || ($end > $now))) {
1425: $skipuser = 0;
1426: }
1427: }
1428: if ($skipuser) {
1429: push(@disallowed,$i);
1430: $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
1431: next;
1432: }
1433: }
1434: if (&get_cancreate_status($persondom,$personname,$dom)) {
1435: my ($allowed,$msg) =
1436: &check_newuser_rules($persondom,$personname,
1437: \%alerts,\%rulematch,\%inst_results,
1438: \%curr_rules,\%got_rules);
1439: if ($allowed) {
1440: if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
1441: if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
1442: $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
1443: }
1444: if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
1445: $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
1446: }
1447: if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
1448: $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
1449: }
1450: }
1451: } else {
1452: push(@disallowed,$i);
1453: $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1454: }
1455: } else {
1456: push(@disallowed,$i);
1457: $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1458: }
1459: } else {
1460: my %userenv =
1461: &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
1462: if ($env{'form.person_'.$i.'_lastname'} eq '') {
1463: $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
1464: }
1465: if ($env{'form.person_'.$i.'_firstname'} eq '') {
1466: $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
1467: }
1468: if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
1469: $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
1470: }
1471: }
1472: } elsif ($personname ne '') {
1473: push(@disallowed,$i);
1474: $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid','<tt>'.$personname.':'.$persondom.'</tt>');
1475: }
1476: } elsif ($personname ne '') {
1477: push(@disallowed,$i);
1478: $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.','<tt>'.$personname.':'.$persondom.'</tt>');
1479: }
1480: }
1.16 raeburn 1481: my $cnum;
1482: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
1483: $cnum = $env{'form.origcnum'};
1484: } else {
1485: $cnum = &Apache::lonnet::generate_coursenum($dom);
1486: }
1.4 raeburn 1487: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1488: \%cat_order,\@code_order);
1.27 raeburn 1489: $r->print('<h3>'.&mt('Review course request details before submission').'</h3>'.
1.30 raeburn 1490: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg).
1.16 raeburn 1491: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1.4 raeburn 1492: $navtxt{'next'} = &mt('Submit course request');
1.10 raeburn 1493: } elsif ($state eq 'process') {
1494: if ($crstype eq 'official') {
1495: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1496: \%cat_order,\@code_order);
1497: }
1.27 raeburn 1498: my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles,
1499: \@code_order);
1.13 raeburn 1500: $r->print($result);
1.27 raeburn 1501: if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
1502: $r->print('<p>');
1503: if ($storeresult eq 'ok') {
1504: $r->print('<a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
1505: &mt('Modify this request').'</a>'.(' 'x4));
1506: }
1507: $r->print('<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1508: return;
1509: }
1.1 raeburn 1510: }
1.16 raeburn 1511: my @excluded = &get_excluded_elements($dom,$states,$action,$state);
1.24 raeburn 1512: if ($state eq 'personnel') {
1513: push(@excluded,'persontotal');
1514: }
1.30 raeburn 1515: if ($state eq 'review') {
1516: if (@disallowed > 0) {
1517: my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
1518: my @currsecs = ¤t_lc_sections();
1519: if (@currsecs) {
1520: push(@items,'sec');
1521: }
1522: my $count = 0;
1523: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1524: unless ($env{'form.person_'.$i.'_uname'} eq '') {
1525: if (grep(/^$i$/,@disallowed)) {
1526: foreach my $item (@items) {
1527: $env{'form.person_'.$i.'_'.$item} = '';
1528: }
1529: } else {
1530: foreach my $item (@items) {
1531: $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
1532: }
1533: }
1534: }
1535: $count ++;
1536: }
1537: $env{'form.persontotal'} = $count;
1538:
1539: }
1540: }
1.27 raeburn 1541: if ($state eq 'enrollment') {
1542: push(@excluded,'crosslisttotal');
1543: }
1.16 raeburn 1544: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1.31 raeburn 1545: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1546: $navtxt{'next'},$state);
1.16 raeburn 1547: return;
1548: }
1549:
1.30 raeburn 1550: sub get_cancreate_status {
1551: my ($persondom,$personname,$dom) = @_;
1552: my ($rules,$ruleorder) =
1553: &Apache::lonnet::inst_userrules($persondom,'username');
1554: my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
1555: $rules);
1556: return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype);
1557: }
1558:
1559: sub check_newuser_rules {
1560: my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
1561: $got_rules) = @_;
1562: my $allowed = 1;
1563: my $newuser = 1;
1564: my ($checkhash,$userchkmsg);
1565: my $checks = { 'username' => 1 };
1566: $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
1567: &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
1568: $inst_results,$curr_rules,$got_rules);
1569: if (ref($alerts->{'username'}) eq 'HASH') {
1570: if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
1571: my $domdesc =
1572: &Apache::lonnet::domain($persondom,'description');
1573: if ($alerts->{'username'}{$persondom}{$personname}) {
1574: if (ref($curr_rules->{$persondom}) eq 'HASH') {
1575: $userchkmsg =
1576: &Apache::loncommon::instrule_disallow_msg('username',
1577: $domdesc,1).
1578: &Apache::loncommon::user_rule_formats($persondom,
1579: $domdesc,$curr_rules->{$persondom}{'username'},
1580: 'username');
1581: }
1582: $allowed = 0;
1583: }
1584: }
1585: }
1586: return ($allowed,$userchkmsg);
1587: }
1588:
1.16 raeburn 1589: sub get_excluded_elements {
1590: my ($dom,$states,$action,$state) = @_;
1.2 raeburn 1591: my @excluded = ('counter');
1592: my %elements = &form_elements($dom);
1593: if (ref($states) eq 'HASH') {
1594: if (ref($states->{$action}) eq 'ARRAY') {
1595: my @items = @{$states->{$action}};
1596: my $numitems = scalar(@items);
1597: if ($numitems) {
1598: for (my $i=$numitems-1; $i>=0; $i--) {
1599: if (ref($elements{$action}) eq 'HASH') {
1600: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
1.16 raeburn 1601: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
1.2 raeburn 1602: push(@excluded,$key);
1603: }
1604: }
1605: }
1606: last if ($items[$i] eq $state);
1607: }
1608: }
1609: }
1610: }
1611: if (grep(/^instcode_/,@excluded)) {
1612: push(@excluded,'instcode');
1.1 raeburn 1613: }
1.16 raeburn 1614: return @excluded;
1.1 raeburn 1615: }
1616:
1.2 raeburn 1617: sub print_enrollment_menu {
1.27 raeburn 1618: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
1619: $invalidcrosslist) =@_;
1.34 raeburn 1620: my ($sections,$autoenroll,$access_dates,$output,$hasauto);
1.2 raeburn 1621: my $starttime = time;
1622: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1623:
1624: my %accesstitles = (
1625: 'start' => 'Default start access',
1.16 raeburn 1626: 'end' => 'Default end access',
1.2 raeburn 1627: );
1628: my %enrolltitles = (
1629: 'start' => 'Start auto-enrollment',
1630: 'end' => 'End auto-enrollment',
1631: );
1632: if ($env{'form.crstype'} eq 'official') {
1633: if (&Apache::lonnet::auto_run('',$dom)) {
1.27 raeburn 1634: $output = &show_invalid_crosslists($invalidcrosslist);
1635: my ($section_form,$crosslist_form);
1.2 raeburn 1636: $section_form = &inst_section_selector($dom,$instcode);
1.27 raeburn 1637: if ($section_form) {
1638: $sections = &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 1639: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
1640: ' '.&mt('Sections for auto-enrollment').'</h3>'.
1.27 raeburn 1641: &Apache::lonhtmlcommon::row_closure(1).
1642: $section_form;
1643: }
1.2 raeburn 1644: my $crosslisttotal = $env{'form.crosslisttotal'};
1.24 raeburn 1645: if (!$crosslisttotal) {
1.2 raeburn 1646: $crosslisttotal = 1;
1647: }
1648: if ($env{'form.addcrosslist'}) {
1649: $crosslisttotal ++;
1650: }
1651: for (my $i=0; $i<$crosslisttotal; $i++) {
1652: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
1653: $cat_titles,$cat_order,$i);
1654: }
1655: if ($crosslist_form) {
1656: $crosslist_form .=
1657: &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
1658: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
1659: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1660: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1.27 raeburn 1661: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1662: $sections .= &Apache::lonhtmlcommon::row_headline.
1663: '<h3>'.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1664: &Apache::lonhtmlcommon::row_closure(1).
1665: $crosslist_form;
1.2 raeburn 1666: }
1.34 raeburn 1667: $hasauto = 1;
1.27 raeburn 1668: $autoenroll =
1.34 raeburn 1669: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').' '.&mt('Add registered students automatically')).
1.2 raeburn 1670: '<span class="LC_nobreak"><label>'.
1671: '<input type="radio" name="autoadds" value="1">'.
1672: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1673: '<input type="radio" name="autoadds" value="0" checked="checked">'.
1674: &mt('No').'</label></span>'.
1.27 raeburn 1675: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1676: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').' '.&mt('Drop unregistered students automatically')).
1.2 raeburn 1677: '<span class="LC_nobreak"><label>'.
1678: '<input type="radio" name="autodrops" value="1">'.
1679: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1680: '<input type="radio" name="autodrops" value="0" checked="checked">'.
1681: &mt('No').'</label></span>'.
1.27 raeburn 1682: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1683: &date_setting_table($starttime,$endtime,$formname,'enroll',
1684: $hasauto,%enrolltitles);
1.2 raeburn 1685: }
1686: }
1.27 raeburn 1687: my $access_dates =
1.34 raeburn 1688: &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
1689: %accesstitles);
1.27 raeburn 1690: $output .= &Apache::lonhtmlcommon::start_pick_box();
1691: if ($sections) {
1692: $output .= $sections;
1693: }
1694: if ($autoenroll) {
1695: $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
1696: '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
1697: &Apache::lonhtmlcommon::row_closure(1).
1698: $autoenroll;
1699: }
1700: if ($access_dates) {
1701: my $header = &mt('Access dates for students');
1702: if ($env{'form.crstype'} eq 'community') {
1703: $header = &mt('Access dates for community members');
1704: }
1705: $output .= &Apache::lonhtmlcommon::row_headline('Access').
1706: '<h3>'.$header.'</h3>'.
1707: &Apache::lonhtmlcommon::row_closure(1).
1708: $access_dates
1.2 raeburn 1709: }
1.27 raeburn 1710: return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
1711: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.2 raeburn 1712: }
1713:
1.27 raeburn 1714: sub show_invalid_crosslists {
1715: my ($invalidcrosslist) = @_;
1716: my $output;
1717: if (ref($invalidcrosslist) eq 'ARRAY') {
1718: if (@{$invalidcrosslist} > 0) {
1719: $output = '<div class="LC_warning">'.
1720: &mt('The following crosslisted courses were invalid:').'<ul>';
1721: foreach my $item (@{$invalidcrosslist}) {
1722: $output .= '<li>'.$item.'</li>';
1723: }
1724: $output .= '</ul></div><br />';
1725: }
1726: }
1727: return $output;
1728: }
1729:
1730:
1.1 raeburn 1731: sub inst_section_selector {
1.2 raeburn 1732: my ($dom,$instcode) = @_;
1733: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1734: my $sectotal = scalar(@sections);
1.1 raeburn 1735: my $output;
1.2 raeburn 1736: if ($sectotal) {
1.27 raeburn 1737: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1.2 raeburn 1738: &Apache::loncommon::start_data_table().
1739: &Apache::loncommon::start_data_table_row().
1740: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1.24 raeburn 1741: 'value="'.$sectotal.'" /></th>'.
1.2 raeburn 1742: '<th>'.&mt('Institutional Section').'</th>'.
1.34 raeburn 1743: '<th>'.&Apache::loncommon::help_open_topic('Course_Request_LCSection').
1744: ' '.&mt('LON-CAPA section').'</th>'.
1.2 raeburn 1745: &Apache::loncommon::end_data_table_row();
1746: for (my $i=0; $i<@sections; $i++) {
1.1 raeburn 1747: my $colflag = $i%2;
1.31 raeburn 1748: my $secon = ' checked="checked"';
1749: my $secoff = '';
1.24 raeburn 1750: if ($env{'form.origcnum'}) {
1.31 raeburn 1751: $secoff = $secon;
1752: $secon='';
1.24 raeburn 1753: }
1.1 raeburn 1754: $output .= &Apache::loncommon::start_data_table_row().
1.31 raeburn 1755: '<td><label><input type="radio" name="sec_'.$i.
1756: '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
1757: (' 'x2).'<label><input type="radio" name="sec_'.$i.
1758: '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
1759: '<td align="center">'.$sections[$i].
1.1 raeburn 1760: '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2 raeburn 1761: $sections[$i].'" /></td>'.
1.1 raeburn 1762: '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2 raeburn 1763: '" value="'.$sections[$i].'" /></td>'.
1.1 raeburn 1764: &Apache::loncommon::end_data_table_row();
1765: }
1.2 raeburn 1766: $output .= &Apache::loncommon::end_data_table().
1767: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1768: }
1769: return $output;
1770: }
1771:
1.2 raeburn 1772: sub date_setting_table {
1.34 raeburn 1773: my ($starttime,$endtime,$formname,$prefix,$hasauto,%datetitles) = @_;
1.2 raeburn 1774: my ($perpetual,$table);
1.14 raeburn 1775: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.2 raeburn 1776: $starttime,'','','',1,'','','',1);
1.14 raeburn 1777: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.2 raeburn 1778: $endtime,'','','',1,'','','',1);
1.27 raeburn 1779: my $closure = '';
1.14 raeburn 1780: if ($prefix eq 'access') {
1.2 raeburn 1781: $perpetual = ' <span class="LC_nobreak"><label>'.
1782: '<input type="checkbox" name="no_end_date" />'.
1783: &mt('No end date').'</label></span>';
1.27 raeburn 1784: $closure = '1';
1.2 raeburn 1785: }
1.34 raeburn 1786:
1787: my %help_item = (
1788: access => {
1789: start => 'Course_Request_Access_Start',
1790: end => 'Course_Request_Access_End',
1791: },
1792: enroll => {
1793: start => 'Course_Request_Enroll_Start',
1794: end => 'Course_Request_Enroll_End',
1795: },
1796: );
1797: if ($hasauto) {
1798: $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start';
1799: $help_item{'access'}{'end'} = 'Course_Request_RegAccess_End';
1800: }
1801:
1802: $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
1803: ' '.$datetitles{'start'}).$startform.
1.27 raeburn 1804: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1805: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
1806: ' '.$datetitles{'end'}).$endform.$perpetual.
1.27 raeburn 1807: &Apache::lonhtmlcommon::row_closure($closure);
1.2 raeburn 1808: return $table;
1809: }
1810:
1811: sub print_personnel_menu {
1.27 raeburn 1812: my ($dom,$formname,$crstype,$invalidcrosslist) = @_;
1813: my $output;
1814: if ($crstype eq 'official') {
1815: if (&Apache::lonnet::auto_run('',$dom)) {
1816: $output .= &show_invalid_crosslists($invalidcrosslist);
1817: }
1818: }
1819: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1.2 raeburn 1820: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 1821: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 1822: $persontotal = 1;
1823: }
1824: if ($env{'form.addperson'}) {
1825: $persontotal ++;
1826: }
1.13 raeburn 1827: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2 raeburn 1828:
1829: my $roleoptions;
1830: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 1831: my $type = 'Course';
1832: if ($crstype eq 'community') {
1833: $type = 'Community';
1834: }
1.2 raeburn 1835: foreach my $role (@roles) {
1.28 raeburn 1836: my $plrole = &Apache::lonnet::plaintext($role,$type);
1.2 raeburn 1837: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1838: }
1839: my %customroles=&Apache::lonuserutils::my_custom_roles();
1840: if (keys(%customroles) > 0) {
1841: foreach my $cust (sort(keys(%customroles))) {
1.28 raeburn 1842: my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1.2 raeburn 1843: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
1844: }
1845: }
1846:
1.30 raeburn 1847: my @currsecs = ¤t_lc_sections();
1.2 raeburn 1848:
1849: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
1850: if (@currsecs) {
1851: my $existsize = scalar(@currsecs);
1852: if ($existsize > 3) {
1853: $existsize = 3;
1854: }
1855: if ($existsize > 1) {
1856: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
1857: }
1858: @currsecs = sort { $a <=> $b } (@currsecs);
1859: $existtitle = &mt('Official').': ';
1860: $existops = '<option value="">'.&mt('None').'</option>';
1861: foreach my $sec (@currsecs) {
1862: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
1863: }
1864: $seccolspan = ' colspan="2"';
1865: $newtitle = &mt('Other').': ';
1866: }
1867:
1.27 raeburn 1868: if ($persontotal) {
1.32 raeburn 1869: my %lt = &Apache::lonlocal::texthash(
1870: community => 'Requestor is automatically assigned Coordinator role.',
1871: official => 'Requestor is automatically assigned Course Coordinator role.',
1872: );
1873: $lt{'unofficial'} = $lt{'official'};
1.27 raeburn 1874: $output .= &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 1875: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
1.27 raeburn 1876: }
1.2 raeburn 1877: for (my $i=0; $i<$persontotal; $i++) {
1878: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
1879: my $linkargstr = join("','",@linkargs);
1.29 raeburn 1880: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1.2 raeburn 1881: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1.29 raeburn 1882: "'person_".$i."_hidedom','person_".$i."_uname'".');';
1.2 raeburn 1883: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1884: 1,$onchange).
1.29 raeburn 1885: '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1.2 raeburn 1886: my %form_elems;
1887: foreach my $item (@items) {
1888: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
1889: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
1890: 'value="" readonly="readonly" />';
1891: }
1892: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
1893: $roleoptions.'</select>';
1894: my $sectionselector;
1895: if (@currsecs) {
1896: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
1897: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
1898: }
1899: $sectionselector .= $newtitle.
1.14 raeburn 1900: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.29 raeburn 1901: my $usersrchlinktxt = &mt('Search for user');
1902: my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1903: $usersrchlinktxt);
1904: my $userchklinktxt = &mt('Check username');
1905: my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1906: $userchklinktxt,'checkusername');
1.2 raeburn 1907: $output .=
1.29 raeburn 1908: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
1909: '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
1910: '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
1911: &mt('Username').': '.$uname_form.' '.$userchklink.'</span><br />'."\n".
1912: '<span class="LC_nobreak">'.&mt('Domain').': '.$udom_form.'</span></td>'.
1913: '</tr>'."\n".'<tr>'.
1.13 raeburn 1914: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
1915: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
1916: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.34 raeburn 1917: '<tr><td align="center" valign="top">'.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
1918: '<td'.$seccolspan.' align="center" valign="top">'.
1919: &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1.2 raeburn 1920: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
1921: }
1922: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
1923: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
1924: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1925: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1926: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1927: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
1928: '<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>';
1.2 raeburn 1929: return $output;
1930: }
1931:
1.30 raeburn 1932: sub current_lc_sections {
1933: my @currsecs;
1934: if ($env{'form.sectotal'}) {
1935: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31 raeburn 1936: if ($env{'form.sec_'.$i}) {
1937: if (defined($env{'form.loncapasec_'.$i})) {
1938: my $lcsec = $env{'form.loncapasec_'.$i};
1939: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
1940: push(@currsecs,$lcsec);
1941: }
1.30 raeburn 1942: }
1943: }
1944: }
1945: }
1946: return @currsecs;
1947: }
1948:
1.1 raeburn 1949: sub print_request_status {
1.11 raeburn 1950: my ($dom) = @_;
1.14 raeburn 1951: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
1952: $env{'user.name'},'^status:'.$dom);
1.35 raeburn 1953: my ($output,$formname,%queue_by_date);
1954: my ($types,$typenames) = &course_types();
1.14 raeburn 1955: foreach my $key (keys(%statusinfo)) {
1956: if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) {
1957: (undef,my($cdom,$cnum)) = split(':',$key);
1958: next if ($cdom ne $dom);
1959: my $requestkey = $cdom.'_'.$cnum;
1960: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1961: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1962: $env{'user.domain'},$env{'user.name'});
1963: my $entry;
1964: my $timestamp = $history{'reqtime'};
1965: my $crstype = $history{'crstype'};
1966: my $disposition = $history{'disposition'};
1967: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1968: next unless (($env{'form.crstype'} eq 'any') ||
1969: ($env{'form.crstype'} eq $crstype));
1970: next unless (($disposition eq 'approval') ||
1971: ($disposition eq 'pending'));
1972: if (ref($history{'details'}) eq 'HASH') {
1973: $entry = $requestkey.':'.$crstype.':'.
1974: &escape($history{'details'}{'cdescr'});
1975: if ($crstype eq 'official') {
1976: $entry .= ':'.&escape($history{'details'}{'instcode'});
1977: }
1978: }
1979: if ($entry ne '') {
1980: if (exists($queue_by_date{$timestamp})) {
1981: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
1982: push(@{$queue_by_date{$timestamp}},$entry);
1983: }
1984: } else {
1985: @{$queue_by_date{$timestamp}} = ($entry);
1.10 raeburn 1986: }
1987: }
1988: }
1989: }
1990: }
1.11 raeburn 1991: $formname = 'requestcrs';
1.10 raeburn 1992: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.16 raeburn 1993: $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1994:
1.10 raeburn 1995: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1.16 raeburn 1996: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
1997: '<input type="hidden" name="showdom" value="" />'."\n".
1998: '<input type="hidden" name="cnum" value="" />'."\n";
1.10 raeburn 1999: if (@sortedtimes > 0) {
2000: $output .= &Apache::loncommon::start_data_table().
2001: &Apache::loncommon::start_data_table_header_row().
2002: '<th>'.&mt('Action').'</th>'.
1.14 raeburn 2003: '<th>'.&mt('Course Description').'</th>'.
2004: '<th>'.&mt('Domain').'</th>';
2005: if ($env{'form.crstype'} eq 'any') {
1.10 raeburn 2006: $output .= '<th>'.&mt('Type').'</th>';
2007: }
1.14 raeburn 2008: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10 raeburn 2009: $output .= '<th>'.&mt('Institutional Code').'</th>';
2010: }
2011: $output .= '<th>'.&mt('Date requested').'</th>'.
2012: &Apache::loncommon::end_data_table_header_row();
2013: my $count = 0;
2014: foreach my $item (@sortedtimes) {
2015: my $showtime = &Apache::lonlocal::locallocaltime($item);
2016: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2017: foreach my $request (sort(@{$queue_by_date{$item}})) {
2018: my ($key,$type,$desc,$instcode) = split(':',$request);
2019: my ($cdom,$cnum) = split('_',$key);
2020: $output .= &Apache::loncommon::start_data_table_row().
1.16 raeburn 2021: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1.14 raeburn 2022: '<td>'.&unescape($desc).'</td>'.
2023: '<td>'.$cdom.'</td>';
2024: if ($env{'form.crstype'} eq 'any') {
1.35 raeburn 2025: my $typename;
2026: if (ref($typenames) eq 'HASH') {
2027: $typename = &mt($typenames->{$type});
2028: }
1.14 raeburn 2029: if ($typename eq '') {
2030: $typename = &mt('Unknown type');
2031: }
2032: $output .= '<td>'.$typename.'</td>';
1.10 raeburn 2033: }
1.14 raeburn 2034: if (($env{'form.crstype'} eq 'any') ||
1.10 raeburn 2035: ($env{'form.crstype'} eq 'official')) {
1.14 raeburn 2036: my $showinstcode;
2037: if ($type eq 'official') {
2038: $showinstcode = &unescape($instcode);
2039: } else {
2040: $showinstcode = &mt('Not applicable');
2041: }
2042: $output .= '<td>'.$showinstcode.'</td>';
1.10 raeburn 2043: }
2044: $output .= '<td>'.$showtime.'</td>'.
2045: &Apache::loncommon::end_data_table_row();
2046: }
2047: }
2048: }
2049: $output .= &Apache::loncommon::end_data_table();
2050: } else {
1.11 raeburn 2051: $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>';
1.10 raeburn 2052: }
2053: $output .= '
1.30 raeburn 2054: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
1.10 raeburn 2055: return $output;
1.1 raeburn 2056: }
2057:
1.16 raeburn 2058: sub print_cancel_request {
2059: my ($dom,$cnum) = @_;
2060: my $requestkey = $dom.'_'.$cnum;
2061: my ($result,$output);
2062: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2063: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2064: $env{'user.domain'},$env{'user.name'});
2065: my $timestamp = $history{'reqtime'};
2066: my $crstype = $history{'crstype'};
2067: my $status = $history{'status'};
2068: if (($status eq 'cancelled') || ($status eq 'created')) {
2069: if ($status eq 'cancelled') {
2070: $output = &mt('This request has already been cancelled.');
2071: } elsif ($status eq 'created') {
2072: $output = &mt('This request has already been processed, and a course created.');
2073: }
2074: $output = &mt('No further action will be taken');
2075: } elsif (ref($history{'details'}) eq 'HASH') {
2076: my ($types,$typename) = &course_types();
2077: my $showtype = $crstype;
2078: if (defined($typename->{$crstype})) {
2079: $showtype = $typename->{$crstype};
2080: }
2081: $output = '<p>'.&Apache::loncommon::start_data_table().
2082: &Apache::loncommon::start_data_table_header_row().
2083: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
2084: '<th>'.&mt('Type').'</th>'.
2085: &Apache::loncommon::end_data_table_header_row().
2086: &Apache::loncommon::start_data_table_row().
2087: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
2088: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
2089: '<td>'.$showtype.'</td>'.
2090: &Apache::loncommon::end_data_table_row().
2091: &Apache::loncommon::end_data_table().
2092: '<br /><div class="LC_warning">'.
2093: &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
2094: $result = 'ok';
2095: } else {
2096: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
2097: }
2098: } else {
2099: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
2100: }
2101: return ($result,$output);
2102: }
2103:
2104: sub viewrequest_javascript {
2105: my ($formname,$next) = @_;
2106: return <<"ENDJS";
2107:
2108: function chooseRequest(cdom,cnum) {
2109: document.$formname.showdom.value = cdom;
2110: document.$formname.cnum.value = cnum;
2111: nextPage(document.$formname,'$next');
2112: }
2113:
2114: ENDJS
2115: }
2116:
2117: sub viewdetails_javascript {
2118: my ($formname) = @_;
2119: return << "ENDJS";
2120:
2121: function nextPage(formname,nextstate) {
2122: if (nextstate == "modify") {
2123: formname.state.value = "personnel";
2124: formname.action.value = "new";
2125: } else {
2126: formname.state.value = nextstate;
2127: }
2128: formname.submit();
2129: }
2130:
2131: function backPage(formname,prevstate) {
2132: formname.state.value = prevstate;
2133: formname.submit();
2134: }
2135:
2136: ENDJS
2137: }
2138:
2139: sub viewcancel_javascript {
2140: my $alert = &mt('Are you sure you want to cancel this request?\\n'.
2141: 'Your request will be removed.');
2142: return << "ENDJS";
2143: function nextPage(formname,nextstate) {
2144: if (confirm('$alert')) {
2145: formname.state.value = nextstate;
2146: formname.submit();
2147: }
2148: return;
2149: }
2150:
2151: ENDJS
2152: }
2153:
1.1 raeburn 2154: sub print_request_logs {
1.10 raeburn 2155: my ($jscript,$loaditems,$crumb) = @_;
1.1 raeburn 2156: return;
2157: }
2158:
2159: sub print_review {
1.30 raeburn 2160: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
2161: $disallowed,$disallowmsg) = @_;
1.4 raeburn 2162: my ($types,$typename) = &course_types();
2163: my ($owner,$ownername,$owneremail);
1.26 raeburn 2164: if ($uname eq '' || $udom eq '') {
2165: $uname = $env{'user.name'};
2166: $udom = $env{'user.domain'};
2167: }
2168: $owner = $uname.':'.$udom;
2169: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
2170: my %emails = &Apache::loncommon::getemails($uname,$udom);
1.4 raeburn 2171: foreach my $email ('permanentemail','critnotification','notification') {
2172: $owneremail = $emails{$email};
2173: last if ($owneremail ne '');
2174: }
2175: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
2176: $section_headers,$section_values,$personnel_headers,$personnel_values);
2177:
2178: $crstypename = $env{'form.crstype'};
2179: if (ref($typename) eq 'HASH') {
2180: unless ($typename->{$env{'form.crstype'}} eq '') {
1.35 raeburn 2181: $crstypename = &mt($typename->{$env{'form.crstype'}});
1.4 raeburn 2182: }
2183: }
1.16 raeburn 2184: my $category = 'Course';
2185: if ($env{'form.crstype'} eq 'community') {
2186: $category = 'Community';
2187: }
1.4 raeburn 2188:
2189: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
2190: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
2191:
1.16 raeburn 2192: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
2193: '('.&Apache::lonnet::plaintext('st',$category).')';
1.4 raeburn 2194: if ($env{'form.crstype'} eq 'official') {
2195: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
2196: foreach my $title (@{$codetitles}) {
2197: if ($env{'form.instcode_'.$title} ne '') {
2198: $inst_headers .= '<th>'.$title.'</th>';
2199: my $longitem = $env{'form.instcode_'.$title};
2200: if (ref($cat_titles->{$title}) eq 'HASH') {
2201: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
2202: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
2203: }
2204: }
2205: $inst_values .= '<td>'.$longitem.'</td>';
2206: }
2207: }
2208: }
2209: if (&Apache::lonnet::auto_run('',$dom)) {
1.16 raeburn 2210: $enrollrow_title = &mt('Enrollment');
1.4 raeburn 2211: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
2212: '<th>'.&mt('Automatic Drops').'</th>'.
2213: '<th>'.&mt('Enrollment Starts').'</th>'.
2214: '<th>'.&mt('Enrollment Ends').'</th>';
2215: $section_headers = '<th>'.&mt('Sections').'</th>'.
2216: '<th>'.&mt('Crosslistings').'</th>';
2217:
1.13 raeburn 2218: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4 raeburn 2219: my @autoroster = (&mt('No'),&mt('Yes'));
2220: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
2221: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13 raeburn 2222: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
2223: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6 raeburn 2224: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
2225: &mt('Institutional section').'</th>'.
2226: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2227: my $secinfo;
1.4 raeburn 2228: if ($env{'form.sectotal'} > 0) {
2229: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2230: if ($env{'form.sec_'.$i}) {
1.5 raeburn 2231: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4 raeburn 2232: if ($env{'form.loncapasec_'.$i} ne '') {
1.5 raeburn 2233: $secinfo .= $env{'form.loncapasec_'.$i};
2234: } else {
2235: $secinfo .= &mt('None');
1.4 raeburn 2236: }
1.5 raeburn 2237: $secinfo .= '</td></tr>';
1.4 raeburn 2238: }
2239: }
2240: }
1.6 raeburn 2241: if ($secinfo eq '') {
2242: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2243: }
1.6 raeburn 2244: $section_values .= $secinfo.'</table></td><td>'.
2245: '<table class="LC_innerpickbox"><tr><th>'.
2246: &mt('Institutional course/section').'</th>'.
2247: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2248: my $xlistinfo;
1.24 raeburn 2249: my $crosslisttotal = $env{'form.crosslisttotal'};
2250: if (!$crosslisttotal) {
2251: $crosslisttotal = 1;
2252: }
2253: for (my $i=0; $i<$crosslisttotal; $i++) {
2254: if ($env{'form.crosslist_'.$i}) {
2255: $xlistinfo .= '<tr><td>';
2256: if (ref($code_order) eq 'ARRAY') {
2257: if (@{$code_order} > 0) {
2258: foreach my $item (@{$code_order}) {
2259: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4 raeburn 2260: }
2261: }
2262: }
1.24 raeburn 2263: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
2264: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
2265: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
2266: } else {
2267: $xlistinfo .= &mt('None');
2268: }
2269: $xlistinfo .= '</td></tr>';
1.4 raeburn 2270: }
2271: }
1.6 raeburn 2272: if ($xlistinfo eq '') {
2273: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2274: }
1.24 raeburn 2275: $section_values .= $xlistinfo;
1.4 raeburn 2276: }
1.24 raeburn 2277: $section_values .= '</table></td>';
1.4 raeburn 2278: }
2279:
2280: my %ctxt = &clone_text();
2281: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1.13 raeburn 2282: if (($env{'form.clonecrs'} =~ /^$match_name$/) &&
2283: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1.15 raeburn 2284: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
2285: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
2286: if ($canclone) {
2287: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
2288: $env{'form.clonecrs'},('description','internal.coursecode'));
2289: if (keys(%courseenv) > 0) {
2290: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
2291: $inst_values .= '<td>'.$courseenv{'description'}.' ';
2292: my $cloneinst = $courseenv{'internal.coursecode'};
2293: if ($cloneinst ne '') {
1.18 raeburn 2294: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
1.15 raeburn 2295: } else {
1.18 raeburn 2296: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
1.15 raeburn 2297: }
2298: $inst_values .= '</td><td>';
2299: if ($env{'form.datemode'} eq 'preserve') {
1.16 raeburn 2300: $inst_values .= $ctxt{'prd'};
1.15 raeburn 2301: } elsif ($env{'form.datemode'} eq 'shift') {
2302: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
2303: } else {
2304: $inst_values .= $ctxt{'ncd'};
2305: }
2306: $inst_values .= '</td>';
2307: } else {
2308: $inst_values .= '<td>'.&mt('Unknown').'</td>';
2309: }
2310: } else {
2311: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
2312: }
1.4 raeburn 2313: } else {
2314: $inst_values .= '<td>'.&mt('None').'</td>';
2315: }
2316: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
2317: '<th>'.&mt('Access Ends').'</th>';
1.13 raeburn 2318: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
2319: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
2320: if ($accessend == 0) {
1.4 raeburn 2321: $enroll_values .= '<td>'.&mt('No end date').'</td>';
2322: } else {
1.13 raeburn 2323: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4 raeburn 2324: }
2325:
2326: my $container = 'Course';
2327: if ($env{'form.crstype'} eq 'community') {
2328: $container = 'Community';
2329: }
2330:
2331: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
2332: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
2333: '</th>';
2334: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
2335: '<td>'.&Apache::lonnet::plaintext('cc',$container).'</td>'.
2336: '<td>'.&mt('None').'</td></tr>';
2337: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2338: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.30 raeburn 2339: if (ref($disallowed) eq 'ARRAY') {
2340: next if (grep(/^$i$/,@{$disallowed}));
2341: }
1.31 raeburn 2342: my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2343: my @allsecs;
2344: foreach my $sec (@officialsecs) {
2345: next unless ($sec =~ /\w/);
2346: next if ($sec =~ /\W/);
2347: next if ($sec eq 'none');
2348: push(@allsecs,$sec);
2349: }
1.14 raeburn 2350: my $newsec = $env{'form.person_'.$i.'_newsec'};
2351: $newsec =~ s/^\s+//;
2352: $newsec =~s/\s+$//;
1.31 raeburn 2353: my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
1.14 raeburn 2354: foreach my $sec (@newsecs) {
1.31 raeburn 2355: next unless ($sec =~ /\w/);
1.14 raeburn 2356: next if ($sec =~ /\W/);
1.31 raeburn 2357: next if ($sec eq 'none');
1.14 raeburn 2358: if ($sec ne '') {
2359: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2360: push(@allsecs,$sec);
2361: }
2362: }
2363: }
1.24 raeburn 2364: my $showsec;
1.14 raeburn 2365: if (@allsecs) {
2366: $showsec = join(', ',@allsecs);
2367: }
1.24 raeburn 2368: if ($showsec eq '') {
2369: $showsec = &mt('None');
2370: }
2371: if ($env{'form.person_'.$i.'_role'} eq 'cc') {
2372: $showsec = &mt('None');
2373: }
1.28 raeburn 2374: my $role = $env{'form.person_'.$i.'_role'};
1.4 raeburn 2375: $personnel_values .=
1.13 raeburn 2376: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
2377: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 2378: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
2379: $env{'form.person_'.$i.'_dom'}.'</td>'.
1.28 raeburn 2380: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
1.14 raeburn 2381: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 2382: }
2383: }
1.30 raeburn 2384: my $output;
2385: if (ref($disallowed) eq 'ARRAY') {
2386: if (@{$disallowed} > 0) {
2387: if (ref($disallowmsg) eq 'HASH') {
2388: $output = '<p class="LC_warning">'.
2389: &mt('Not all requested personnel could be included.').'<ul>';
2390: foreach my $item (@{$disallowed}) {
2391: $output .= '<li>'.$disallowmsg->{$item}.'</li>';
2392: }
2393: $output .= '</ul></p>';
2394: }
2395: }
2396: }
2397: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.4 raeburn 2398: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 2399: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 2400: '<th>'.&mt('Name').'</th>'.
2401: '<th>'.&mt('Username:Domain').'</th>'.
2402: '<th>'.&mt('E-mail address').'</th>'.
2403: '</tr><tr>'."\n".
2404: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
2405: '<td>'.$owneremail.'</td>'.
2406: '</tr></table>'."\n".
2407: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 2408: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 2409: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
2410: '<tr>'.$inst_values.'</tr></table>'."\n".
2411: &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2412: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4 raeburn 2413: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
2414: '<tr>'.$enroll_values.'</tr></table>'."\n".
2415: &Apache::lonhtmlcommon::row_closure();
2416: if ($section_headers ne '') {
2417: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
2418: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
2419: '<tr>'.$section_values.'</tr></table>'."\n".
2420: &Apache::lonhtmlcommon::row_closure();
2421: }
2422: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
2423: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
2424: $personnel_values.'</table>'."\n".
2425: &Apache::lonhtmlcommon::row_closure(1).
1.26 raeburn 2426: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.4 raeburn 2427: return $output;
2428: }
2429:
2430: sub dates_from_form {
2431: my ($startname,$endname) = @_;
2432: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
2433: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 2434: if ($endname eq 'accessend') {
1.4 raeburn 2435: if (exists($env{'form.no_end_date'}) ) {
2436: $enddate = 0;
2437: }
2438: }
2439: return ($startdate,$enddate);
1.1 raeburn 2440: }
2441:
2442: sub courseinfo_form {
1.36 raeburn 2443: my ($dom,$formname,$crstype,$next,$description) = @_;
1.32 raeburn 2444: my %lt = &Apache::lonlocal::texthash(
2445: official => 'You must provide a (brief) course description.',
2446: community => 'You must provide a (brief) community description.'
2447: );
2448: $lt{'unofficial'} = $lt{'official'};
1.15 raeburn 2449: my $js_validate = <<"ENDJS";
2450: <script type="text/javascript">
2451: // <![CDATA['
2452:
2453: function validateForm() {
2454: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
1.32 raeburn 2455: alert('$lt{$crstype}');
1.15 raeburn 2456: return;
2457: }
2458: nextPage(document.$formname,'$next');
2459: }
2460: // ]]
2461: </script>
2462:
2463: ENDJS
1.27 raeburn 2464: my $title = &mt('Brief Course Description');
2465: if ($crstype eq 'community') {
2466: $title = &mt('Brief Community Description');
2467: }
1.15 raeburn 2468: my $output .= $js_validate."\n".'<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 2469: &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 2470: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'</h3>'.
1.27 raeburn 2471: &Apache::lonhtmlcommon::row_closure(1).
2472: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.36 raeburn 2473: '<input type="text" size="60" name="cdescr" value="'.$description.'" />';
1.13 raeburn 2474: my ($home_server_pick,$numlib) =
2475: &Apache::loncommon::home_server_form_item($dom,'chome',
2476: 'default','hide');
2477: if ($numlib > 1) {
2478: $output .= &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2479: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13 raeburn 2480: }
2481: $output .= $home_server_pick.
1.27 raeburn 2482: &Apache::lonhtmlcommon::row_closure().
2483: &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 2484: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.&mt('Clone content and settings from an existing course?').'</h3>'.
1.13 raeburn 2485: &Apache::lonhtmlcommon::row_closure(1).
1.27 raeburn 2486: &clone_form($dom,$formname,$crstype).
2487: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
1.1 raeburn 2488: return $output;
2489: }
2490:
2491: sub clone_form {
2492: my ($dom,$formname,$crstype) = @_;
2493: my $type = 'Course';
2494: if ($crstype eq 'community') {
2495: $type = 'Community';
2496: }
1.35 raeburn 2497: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').' '.
1.13 raeburn 2498: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1.4 raeburn 2499: my %lt = &clone_text();
1.2 raeburn 2500: my $output .=
2501: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.29 raeburn 2502: '<input type="text" size="25" name="clonecrs" value="" />'.
1.35 raeburn 2503: '</label>'.&Apache::lonhtmlcommon::row_closure(1).
2504: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
1.27 raeburn 2505: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 2506: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
2507: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
2508: '</label><br /><label>'.
2509: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
2510: '</label><br /><label>'.
2511: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
2512: $lt{'shd'}.'</label>'.
2513: '<input type="text" size="5" name="dateshift" value="365" />'.
1.27 raeburn 2514: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2515: return $output;
2516: }
2517:
1.16 raeburn 2518: sub clone_text {
1.4 raeburn 2519: return &Apache::lonlocal::texthash(
2520: 'cid' => 'Course ID',
2521: 'dmn' => 'Domain',
2522: 'dsh' => 'Date Shift',
2523: 'ncd' => 'Do not clone date parameters',
2524: 'prd' => 'Clone date parameters as-is',
2525: 'shd' => 'Shift date parameters by number of days',
2526: );
2527: }
2528:
1.1 raeburn 2529: sub coursecode_form {
1.2 raeburn 2530: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 2531: my $output;
1.2 raeburn 2532: my %rowtitle = (
2533: instcode => 'Course Category',
2534: crosslist => 'Cross Listed Course',
2535: );
1.34 raeburn 2536: my %helpitem = (
2537: instcode => 'Course_Request_Category',
2538: crosslist => 'Course_Request_Crosslist',
2539: );
1.1 raeburn 2540: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
2541: (ref($cat_order))) {
1.2 raeburn 2542: my ($sel,$instsec,$lcsec);
2543: $sel = $context;
2544: if ($context eq 'crosslist') {
2545: $sel .= '_'.$num;
2546: $instsec = &mt('Institutional section').'<br />'.
2547: '<input type="text" size="10" name="'.$sel.'_instsec" />';
2548: $lcsec = &mt('LON-CAPA section').'<br />'.
2549: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
2550: }
1.1 raeburn 2551: if (@{$codetitles} > 0) {
2552: my $lastitem = pop(@{$codetitles});
1.2 raeburn 2553: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 2554: if (@{$codetitles} > 0) {
1.34 raeburn 2555: $output = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($helpitem{$context}).' '.$rowtitle{$context}).
1.2 raeburn 2556: '<table><tr>';
1.1 raeburn 2557: if ($context eq 'crosslist') {
1.2 raeburn 2558: $output .= '<td>'.&mt('Include?').'<br />'.
2559: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 2560: }
2561: foreach my $title (@{$codetitles}) {
2562: if (ref($cat_order->{$title}) eq 'ARRAY') {
2563: if (@{$cat_order->{$title}} > 0) {
2564: $output .= '<td align="center">'.$title.'<br />'."\n".
2565: '<select name="'.$sel.'_'.$title.'">'."\n".
2566: ' <option value="" selected="selected">'.
2567: &mt('Select').'</option>'."\n";
2568: foreach my $item (@{$cat_order->{$title}}) {
2569: my $longitem = $item;
2570: if (ref($cat_titles->{$title}) eq 'HASH') {
2571: if ($cat_titles->{$title}{$item} ne '') {
2572: $longitem = $cat_titles->{$title}{$item};
2573: }
2574: }
2575: $output .= '<option value="'.$item.'">'.$longitem.
2576: '</option>'."\n";
2577: }
2578: }
2579: $output .= '</select></td>'."\n";
2580: }
2581: }
2582: if ($context eq 'crosslist') {
2583: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 2584: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
2585: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 2586: } else {
2587: $output .= '</tr></table>'.
2588: &Apache::lonhtmlcommon::row_closure().
2589: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2590: $lastinput;
2591: }
2592: } else {
2593: if ($context eq 'crosslist') {
2594: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 2595: '<table><tr>'.
2596: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
2597: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
2598: '</tr></table>';
1.1 raeburn 2599: } else {
2600: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2601: $lastinput;
2602: }
2603: }
1.2 raeburn 2604: $output .= &Apache::lonhtmlcommon::row_closure(1);
2605: push(@$codetitles,$lastitem);
2606: } elsif ($context eq 'crosslist') {
2607: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
2608: '<table><tr><td align="center">'.
2609: '<span class="LC_nobreak">'.&mt('Include?').
2610: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
2611: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
2612: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
2613: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
2614: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2615: }
2616: }
2617: return $output;
2618: }
2619:
2620: sub get_course_dom {
2621: my $codedom = &Apache::lonnet::default_login_domain();
1.19 raeburn 2622: if ($env{'form.showdom'} ne '') {
2623: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
2624: return $env{'form.showdom'};
2625: }
2626: }
1.1 raeburn 2627: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.19 raeburn 2628: my ($types,$typename) = &course_types();
2629: if (ref($types) eq 'ARRAY') {
2630: foreach my $type (@{$types}) {
2631: if (&Apache::lonnet::usertools_access($env{'user.name'},
2632: $env{'user.domain'},$type,
2633: undef,'requestcourses')) {
2634: return $env{'user.domain'};
2635: }
2636: }
2637: my @possible_doms;
2638: foreach my $type (@{$types}) {
2639: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
2640: if ($dom_str ne '') {
2641: my @domains = split(',',$dom_str);
2642: foreach my $entry (@domains) {
2643: my ($extdom,$extopt) = split(':',$entry);
2644: if ($extdom eq $env{'request.role.domain'}) {
2645: return $extdom;
2646: }
2647: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
2648: push(@possible_doms,$extdom);
2649: }
2650: }
2651: }
2652: }
2653: if (@possible_doms) {
2654: @possible_doms = sort(@possible_doms);
2655: return $possible_doms[0];
2656: }
2657: }
1.1 raeburn 2658: $codedom = $env{'user.domain'};
2659: if ($env{'request.role.domain'} ne '') {
2660: $codedom = $env{'request.role.domain'};
2661: }
2662: }
2663: return $codedom;
2664: }
2665:
2666: sub display_navbuttons {
1.31 raeburn 2667: my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1 raeburn 2668: $r->print('<div class="LC_navbuttons">');
2669: if ($prev) {
1.16 raeburn 2670: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1.31 raeburn 2671: 'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
1.16 raeburn 2672: (' 'x3));
1.1 raeburn 2673: } elsif ($prevtext) {
1.16 raeburn 2674: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
2675: 'onclick="javascript:history.back()"/>'.(' 'x3));
2676: }
2677: if ($state eq 'details') {
2678: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1.31 raeburn 2679: 'onclick="javascript:nextPage('."document.$formname,'$other'".
1.16 raeburn 2680: ')" />');
1.1 raeburn 2681: }
1.31 raeburn 2682: my $gotnext;
1.15 raeburn 2683: if ($state eq 'courseinfo') {
1.16 raeburn 2684: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2685: 'onclick="javascript:validateForm();" />');
1.31 raeburn 2686: $gotnext = 1;
2687: } elsif ($state eq 'enrollment') {
2688: if (($env{'form.crstype'} eq 'official') &&
2689: (&Apache::lonnet::auto_run('',$dom))) {
2690: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2691: 'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
2692: $gotnext = 1;
2693: }
2694: } elsif ($state eq 'personnel') {
2695: if ($env{'form.persontotal'} > 0) {
2696: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2697: 'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
2698: $gotnext = 1;
2699: }
2700: }
2701: unless ($gotnext) {
2702: if ($next) {
2703: $r->print('
2704: <input type="button" name="next" value="'.$nexttext.'" '.
2705: 'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
2706: }
1.1 raeburn 2707: }
2708: $r->print('</div>');
2709: }
2710:
2711: sub print_request_outcome {
1.10 raeburn 2712: my ($dom,$codetitles,$code_order) = @_;
1.13 raeburn 2713: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.10 raeburn 2714: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1.24 raeburn 2715: my $sectotal = $env{'form.sectotal'};
2716: my $crosslisttotal = 0;
1.10 raeburn 2717: $cnum = $env{'form.cnum'};
1.8 raeburn 2718: unless ($cnum =~ /^$match_courseid$/) {
2719: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
2720: return $output;
2721: }
1.11 raeburn 2722:
1.10 raeburn 2723: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 2724: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
2725: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
2726: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
2727: }
2728: }
1.10 raeburn 2729: $now = time;
2730: $crstype = $env{'form.crstype'};
1.17 raeburn 2731: my @instsections;
1.8 raeburn 2732: if ($crstype eq 'official') {
2733: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 2734: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 2735: }
1.10 raeburn 2736: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2737: if ($env{'form.sec_'.$i}) {
2738: if ($env{'form.secnum_'.$i} ne '') {
1.17 raeburn 2739: my $sec = $env{'form.secnum_'.$i};
2740: $sections{$i}{'inst'} = $sec;
2741: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
2742: push(@instsections,$sec);
2743: }
1.13 raeburn 2744: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.10 raeburn 2745: }
2746: }
2747: }
2748: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
2749: if ($env{'form.crosslist_'.$i}) {
2750: my $xlistinfo = '';
2751: if (ref($code_order) eq 'ARRAY') {
2752: if (@{$code_order} > 0) {
2753: foreach my $item (@{$code_order}) {
2754: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
2755: }
2756: }
2757: }
1.22 raeburn 2758: $crosslistings{$i}{'instcode'} = $xlistinfo;
1.24 raeburn 2759: if ($xlistinfo ne '') {
2760: $crosslisttotal ++;
2761: }
1.22 raeburn 2762: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 2763: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 2764: }
2765: }
1.14 raeburn 2766: } else {
2767: $enrollstart = '';
2768: $enrollend = '';
1.10 raeburn 2769: }
2770: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2771: my $uname = $env{'form.person_'.$i.'_uname'};
1.16 raeburn 2772: my $udom = $env{'form.person_'.$i.'_dom'};
1.10 raeburn 2773: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
2774: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 2775: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
2776: $personnel{$uname.':'.$udom} = {
2777: firstname => $env{'form.person_'.$i.'_firstname'},
2778: lastname => $env{'form.person_'.$i.'_lastname'},
2779: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
2780: };
2781: }
2782: my $role = $env{'form.person_'.$i.'_role'};
2783: unless ($role eq '') {
1.16 raeburn 2784: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13 raeburn 2785: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
2786: unless (grep(/^\Q$role\E$/,@curr_roles)) {
2787: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
2788: }
2789: } else {
2790: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
2791: }
2792: if ($role eq 'cc') {
2793: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
2794: } else {
1.14 raeburn 2795: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1.31 raeburn 2796: my @allsecs;
2797: foreach my $sec (@currsec) {
2798: next unless ($sec =~ /\w/);
2799: next if ($sec =~ /\W/);
2800: next if ($sec eq 'none');
2801: push(@allsecs,$sec);
2802: }
1.14 raeburn 2803: my $newsec = $env{'form.person_'.$i.'_newsec'};
2804: $newsec =~ s/^\s+//;
2805: $newsec =~s/\s+$//;
2806: my @newsecs = split(/[\s,;]+/,$newsec);
2807: foreach my $sec (@newsecs) {
2808: next if ($sec =~ /\W/);
1.31 raeburn 2809: next if ($sec eq 'none');
1.14 raeburn 2810: if ($sec ne '') {
1.31 raeburn 2811: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2812: push(@allsecs,$sec);
1.13 raeburn 2813: }
2814: }
2815: }
1.31 raeburn 2816: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
1.13 raeburn 2817: }
2818: }
1.10 raeburn 2819: } else {
2820: push(@missingdom,$uname.':'.$udom);
2821: }
2822: } else {
2823: push(@baduname,$uname.':'.$udom);
2824: }
1.8 raeburn 2825: }
1.13 raeburn 2826: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 raeburn 2827: my $autodrops = 0;
2828: if ($env{'form.autodrops'}) {
2829: $autodrops = $env{'form.autodrops'};
2830: }
2831: my $autoadds = 0;
2832: if ($env{'form.autoadds'}) {
2833: $autodrops = $env{'form.autoadds'};
2834: }
2835: if ($env{'form.autoadds'}) {
2836: $autodrops = $env{'form.autoadds'};
2837: }
2838: my $instcode = '';
2839: if (exists($env{'form.instcode'})) {
2840: $instcode = $env{'form.instcode'};
2841: }
1.15 raeburn 2842: my $clonecrs = '';
2843: my $clonedom = '';
2844: if (($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
2845: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.16 raeburn 2846: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
2847: $env{'form.clonedom'});
1.15 raeburn 2848: if ($clonehome ne 'no_host') {
1.16 raeburn 2849: my $canclone =
2850: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
2851: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
1.15 raeburn 2852: if ($canclone) {
2853: $clonecrs = $env{'form.clonecrs'};
2854: $clonedom = $env{'form.clonedom'};
2855: }
2856: }
2857: }
1.8 raeburn 2858: my $details = {
1.10 raeburn 2859: owner => $env{'user.name'},
2860: domain => $env{'user.domain'},
2861: cdom => $dom,
1.11 raeburn 2862: cnum => $cnum,
1.13 raeburn 2863: coursehome => $env{'form.chome'},
2864: cdescr => $env{'form.cdescr'},
1.10 raeburn 2865: crstype => $env{'form.crstype'},
1.14 raeburn 2866: instcode => $instcode,
1.15 raeburn 2867: clonedom => $clonedom,
2868: clonecrs => $clonecrs,
1.10 raeburn 2869: datemode => $env{'form.datemode'},
1.14 raeburn 2870: dateshift => $env{'form.dateshift'},
2871: sectotal => $sectotal,
1.10 raeburn 2872: sections => \%sections,
1.14 raeburn 2873: crosslisttotal => $crosslisttotal,
1.13 raeburn 2874: crosslists => \%crosslistings,
1.14 raeburn 2875: autoadds => $autoadds,
2876: autodrops => $autodrops,
1.13 raeburn 2877: enrollstart => $enrollstart,
2878: enrollend => $enrollend,
2879: accessstart => $accessstart,
2880: accessend => $accessend,
1.10 raeburn 2881: personnel => \%personnel,
1.8 raeburn 2882: };
1.27 raeburn 2883: my (@inststatuses,$storeresult,$creationresult);
1.9 raeburn 2884: my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
1.8 raeburn 2885: if ($val eq '') {
2886: if ($crstype eq 'official') {
1.19 raeburn 2887: $output = &mt('You are not permitted to request creation of official courses.');
1.8 raeburn 2888: } elsif ($crstype eq 'unofficial') {
1.19 raeburn 2889: $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8 raeburn 2890: } elsif ($crstype eq 'community') {
2891: $output = &mt('You are not permitted to request creation of communities');
2892: } else {
2893: $output = &mt('Unrecognized course type: [_1]',$crstype);
2894: }
1.27 raeburn 2895: $storeresult = 'notpermitted';
1.8 raeburn 2896: } else {
1.14 raeburn 2897: my ($disposition,$message,$reqstatus);
1.8 raeburn 2898: my %reqhash = (
1.14 raeburn 2899: reqtime => $now,
1.10 raeburn 2900: crstype => $crstype,
2901: details => $details,
1.8 raeburn 2902: );
2903: my $requestkey = $dom.'_'.$cnum;
1.17 raeburn 2904: my $validationerror;
1.10 raeburn 2905: if ($val eq 'autolimit=') {
2906: $disposition = 'process';
2907: } elsif ($val =~ /^autolimit=(\d+)$/) {
2908: my $limit = $1;
1.8 raeburn 2909: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 2910: $dom,$crstype,$limit,\$message);
1.8 raeburn 2911: } elsif ($val eq 'validate') {
1.21 raeburn 2912: my ($inststatuslist,$validationchk,$validation);
1.17 raeburn 2913: if (@inststatuses > 0) {
2914: $inststatuslist = join(',',@inststatuses);
2915: }
2916: my $instseclist;
2917: if (@instsections > 0) {
2918: $instseclist = join(',',@instsections);
2919: }
1.21 raeburn 2920: $validationchk =
2921: &Apache::lonnet::auto_courserequest_validation($dom,
2922: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
2923: $inststatuslist,$instcode,$instseclist);
2924: if ($validationchk =~ /:/) {
2925: ($validation,$message) = split(':',$validationchk);
2926: } else {
2927: $validation = $validationchk;
2928: }
2929: if ($validation =~ /^error(.*)$/) {
1.17 raeburn 2930: $disposition = 'approval';
2931: $validationerror = $1;
1.23 raeburn 2932: } else {
2933: $disposition = $validation;
1.17 raeburn 2934: }
1.8 raeburn 2935: } else {
2936: $disposition = 'approval';
2937: }
1.14 raeburn 2938: $reqhash{'disposition'} = $disposition;
2939: $reqstatus = $disposition;
1.16 raeburn 2940: my ($modified,$queued);
1.8 raeburn 2941: if ($disposition eq 'rejected') {
2942: $output = &mt('Your course request was rejected.');
2943: if ($message) {
2944: $output .= '<div class="LC_warning">'.$message.'</div>';
2945: }
1.27 raeburn 2946: $storeresult = 'rejected';
1.8 raeburn 2947: } elsif ($disposition eq 'process') {
1.14 raeburn 2948: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
2949: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
2950: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 2951: my $type = 'Course';
2952: if ($crstype eq 'community') {
2953: $type = 'Community';
2954: }
2955: foreach my $role (@roles) {
2956: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
2957: }
1.14 raeburn 2958: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
2959: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
2960: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
2961: if ($result eq 'created') {
1.8 raeburn 2962: $disposition = 'created';
1.14 raeburn 2963: $reqstatus = 'created';
1.28 raeburn 2964: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
2965: \%longroles);
2966: $output = '<p>'.&mt('Your course request has been processed and the course has been created.').
2967: '<br />'.$role_result.'</p>';
1.27 raeburn 2968: $creationresult = 'created';
1.8 raeburn 2969: } else {
1.14 raeburn 2970: $output = '<span class="LC_error">'.
2971: &mt('An error occurred when processing your course request.').
2972: '<br />'.
2973: &mt('You may want to review the request details and submit the request again.').
2974: '</span>';
1.27 raeburn 2975: $creationresult = 'error';
1.8 raeburn 2976: }
2977: } else {
2978: my $requestid = $cnum.'_'.$disposition;
2979: my $request = {
2980: $requestid => {
2981: timestamp => $now,
2982: crstype => $crstype,
2983: ownername => $env{'user.name'},
2984: ownerdom => $env{'user.domain'},
1.13 raeburn 2985: description => $env{'form.cdescr'},
1.8 raeburn 2986: },
2987: };
1.16 raeburn 2988: my $statuskey = 'status:'.$dom.':'.$cnum;
2989: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
2990: $env{'user.domain'},$env{'user.name'});
1.17 raeburn 2991: if ($userreqhash{$statuskey} ne '') {
1.16 raeburn 2992: $modified = 1;
1.25 raeburn 2993: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
2994: my %queuehash = &Apache::lonnet::get('courserequestqueue',
2995: [$cnum.'_approval',
2996: $cnum.'_pending'],$dom,$uname);
1.17 raeburn 2997: if (($queuehash{$cnum.'_approval'} ne '') ||
2998: ($queuehash{$cnum.'_pending'} ne '')) {
1.16 raeburn 2999: $queued = 1;
3000: }
3001: }
3002: unless ($queued) {
3003: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
3004: $dom);
3005: if ($putresult eq 'ok') {
3006: $output = &mt('Your course request has been recorded.').'<br />'.
3007: ¬ification_information($disposition,$req_notifylist,
3008: $cnum,$now);
1.8 raeburn 3009: } else {
1.16 raeburn 3010: $reqstatus = 'domainerror';
3011: $reqhash{'disposition'} = $disposition;
3012: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
3013: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8 raeburn 3014: }
3015: }
3016: }
1.27 raeburn 3017: my ($statusresult);
1.10 raeburn 3018: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
3019: $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
3020: 'courserequests');
1.14 raeburn 3021: if ($storeresult eq 'ok') {
3022: my %status = (
3023: 'status:'.$dom.':'.$cnum => $reqstatus,
3024: );
1.27 raeburn 3025: $statusresult = &Apache::lonnet::put('courserequests',\%status);
1.14 raeburn 3026: }
1.10 raeburn 3027: } else {
3028: $storeresult = 'error: invalid requestkey format';
3029: }
1.8 raeburn 3030: if ($storeresult ne 'ok') {
1.13 raeburn 3031: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
3032: &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1.14 raeburn 3033: } elsif ($statusresult ne 'ok') {
1.28 raeburn 3034: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'</span><br />';
1.14 raeburn 3035: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
1.8 raeburn 3036: }
1.16 raeburn 3037: if ($modified && $queued && $storeresult eq 'ok') {
3038: $output .= '<p>'.&mt('Your course request has been updated').'</p>'.
3039: ¬ification_information($disposition,$req_notifylist,$cnum,$now);
3040: }
1.17 raeburn 3041: if ($validationerror ne '') {
1.19 raeburn 3042: $output .= '<span class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
1.17 raeburn 3043: }
1.16 raeburn 3044: }
1.27 raeburn 3045: if ($creationresult ne '') {
3046: return ($creationresult,$output);
3047: } else {
3048: return ($storeresult,$output);
3049: }
1.16 raeburn 3050: }
3051:
1.28 raeburn 3052: sub update_requestors_roles {
3053: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
3054: my $now = time;
3055: my ($active,$future,$numactive,$numfuture,$output);
3056: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
3057: if (ref($details) eq 'HASH') {
3058: if (ref($details->{'personnel'}) eq 'HASH') {
1.35 raeburn 3059: unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
3060: $details->{'personnel'}{$owner} = {
3061: 'roles' => ['cc'],
3062: 'cc' => { 'usec' => [] },
3063: };
3064: }
3065: my @roles;
3066: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
3067: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
3068: unless (grep(/^cc$/,@roles)) {
3069: push(@roles,'cc');
3070: }
3071: } else {
3072: @roles = ('cc');
3073: }
3074: foreach my $role (@roles) {
3075: my $start = $now;
3076: my $end = '0';
3077: if ($role eq 'st') {
3078: if ($details->{'accessstart'} ne '') {
3079: $start = $details->{'accessstart'};
3080: }
3081: if ($details->{'accessend'} ne '') {
3082: $end = $details->{'accessend'};
3083: }
3084: }
3085: my @usecs;
3086: if ($role ne 'cc') {
3087: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
3088: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
3089: }
3090: }
3091: if ($role eq 'st') {
3092: if (@usecs > 1) {
3093: my $firstsec = $usecs[0];
3094: @usecs = ($firstsec);
3095: }
3096: }
3097: if (@usecs == 0) {
3098: push(@usecs,'');
3099: }
3100: foreach my $usec (@usecs) {
3101: my (%userroles,%newrole,%newgroups,$spec,$area);
3102: my $area = '/'.$dom.'/'.$cnum;
3103: my $spec = $role.'.'.$area;
3104: if ($usec ne '') {
3105: $spec .= '/'.$usec;
3106: $area .= '/'.$usec;
3107: }
3108: if ($role =~ /^cr\//) {
3109: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
3110: $cnum,$spec,$area);
3111: } else {
3112: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
3113: $spec,$cnum,$area);
1.28 raeburn 3114: }
1.35 raeburn 3115: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
3116: \%newgroups);
3117: $userroles{'user.role.'.$spec} = $start.'.'.$end;
3118: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
3119: if (($end == 0) || ($end > $now)) {
3120: my $showrole = $role;
1.28 raeburn 3121: if ($role =~ /^cr\//) {
1.35 raeburn 3122: $showrole = &Apache::lonnet::plaintext($role,$crstype);
3123: } elsif (ref($longroles) eq 'HASH') {
3124: if ($longroles->{$role} ne '') {
3125: $showrole = $longroles->{$role};
3126: }
1.28 raeburn 3127: }
1.35 raeburn 3128: if ($start <= $now) {
3129: $active .= '<li><a href="/adm/roles?selectrole=1&'.
3130: $spec.'=1">'.$showrole;
3131: if ($usec ne '') {
3132: $active .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 3133: }
1.35 raeburn 3134: $active .= '</a></li>';
3135: $numactive ++;
3136: } else {
3137: $future .= '<li>'.$showrole;
3138: if ($usec ne '') {
3139: $future .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 3140: }
1.35 raeburn 3141: $future .= '</li>';
3142: $numfuture ++;
1.28 raeburn 3143: }
3144: }
3145: }
3146: }
3147: }
3148: }
3149: if ($active) {
3150: if ($numactive == 1) {
3151: $output = &mt('Use the following link to enter the course:');
3152: } else {
3153: $output = &mt('Use the following links to your new roles to enter the course:');
3154: }
3155: $output .= ' <ul>'.$active.'</ul><br />';
3156: }
3157: if ($future) {
3158: $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'})).
3159: ' <ul>'.$future.'</ul>';
3160: }
3161: return $output;
3162: }
3163:
1.16 raeburn 3164: sub notification_information {
3165: my ($disposition,$req_notifylist,$cnum,$now) = @_;
3166: my %emails = &Apache::loncommon::getemails();
3167: my $address;
3168: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
3169: $address = $emails{'permanentemail'};
3170: if ($address eq '') {
3171: $address = $emails{'notification'};
3172: }
3173: }
3174: my $output;
3175: if ($disposition eq 'approval') {
3176: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
3177: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
3178: if ($address ne '') {
3179: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
3180: }
3181: if ($req_notifylist) {
3182: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3183: $env{'user.domain'});
3184: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
3185: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
3186: }
1.17 raeburn 3187: } elsif ($disposition eq 'pending') {
1.16 raeburn 3188: $output .= '<div class="LC_info">'.
3189: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
3190: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
3191: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
3192: '</div>';
1.17 raeburn 3193: } else {
3194: $output .= '<div class="LC_warning">'.
3195: &mt('Your request status is: [_1].',$disposition).
3196: '</div>'
1.8 raeburn 3197: }
3198: return $output;
3199: }
3200:
3201: sub get_processtype {
1.9 raeburn 3202: my ($dom,$crstype,$inststatuses,$domconfig) = @_;
3203: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1.8 raeburn 3204: my (%userenv,%settings,$val);
1.19 raeburn 3205: my @options = ('autolimit','validate','approval');
1.8 raeburn 3206: if ($dom eq $env{'user.domain'}) {
3207: %userenv =
3208: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
3209: 'requestcourses.'.$crstype,'inststatus');
3210: if ($userenv{'requestcourses.'.$crstype}) {
3211: $val = $userenv{'requestcourses.'.$crstype};
3212: @{$inststatuses} = ('_custom_');
3213: } else {
3214: my ($task,%alltasks);
1.9 raeburn 3215: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
3216: %settings = %{$domconfig->{'requestcourses'}};
1.8 raeburn 3217: if (ref($settings{$crstype}) eq 'HASH') {
1.23 raeburn 3218: if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
1.8 raeburn 3219: $val = $settings{$crstype}{'_LC_adv'};
3220: @{$inststatuses} = ('_LC_adv_');
3221: } else {
3222: if ($userenv{'inststatus'} ne '') {
3223: @{$inststatuses} = split(',',$userenv{'inststatus'});
3224: } else {
1.13 raeburn 3225: @{$inststatuses} = ('default');
1.8 raeburn 3226: }
3227: foreach my $status (@{$inststatuses}) {
3228: if (exists($settings{$crstype}{$status})) {
3229: my $value = $settings{$crstype}{$status};
3230: next unless ($value);
3231: unless (exists($alltasks{$value})) {
3232: if (ref($alltasks{$value}) eq 'ARRAY') {
3233: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
3234: push(@{$alltasks{$value}},$status);
3235: }
3236: } else {
3237: @{$alltasks{$value}} = ($status);
3238: }
3239: }
3240: }
3241: }
3242: my $maxlimit = 0;
1.13 raeburn 3243:
1.8 raeburn 3244: foreach my $key (sort(keys(%alltasks))) {
3245: if ($key =~ /^autolimit=(\d*)$/) {
3246: if ($1 eq '') {
3247: $val ='autolimit=';
3248: last;
3249: } elsif ($1 > $maxlimit) {
3250: $maxlimit = $1;
3251: }
3252: }
3253: }
3254: if ($maxlimit) {
3255: $val = 'autolimit='.$maxlimit;
3256: } else {
3257: foreach my $option (@options) {
3258: if ($alltasks{$option}) {
3259: $val = $option;
3260: last;
3261: }
3262: }
3263: }
3264: }
3265: }
3266: }
3267: }
3268: } else {
3269: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
3270: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
1.19 raeburn 3271: if ($userenv{'reqcrsotherdom.'.$crstype}) {
3272: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
3273: my $optregex = join('|',@options);
3274: foreach my $item (@doms) {
3275: my ($extdom,$extopt) = split(':',$item);
3276: if ($extdom eq $dom) {
3277: if ($extopt =~ /^($optregex)(=?\d*)$/) {
3278: $val = $1.$2;
3279: }
3280: last;
3281: }
1.8 raeburn 3282: }
3283: @{$inststatuses} = ('_external_');
3284: }
3285: }
3286: return $val;
3287: }
3288:
3289: sub check_autolimit {
1.10 raeburn 3290: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
3291: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
3292: 'userroles',['active','future'],['cc'],[$dom]);
3293: my ($types,$typename) = &course_types();
3294: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
3295: my %count;
3296: if (ref($types) eq 'ARRAY') {
3297: foreach my $type (@{$types}) {
3298: $count{$type} = 0;
3299: }
3300: }
3301: foreach my $key (keys(%requests)) {
3302: my ($cdom,$cnum) = split('_',$key);
3303: if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
3304: if (ref($requests{$key}) eq 'HASH') {
3305: my $type = $requests{$key}{'crstype'};
3306: if ($type =~ /^official|unofficial|community$/) {
3307: $count{$type} ++;
3308: }
3309: }
3310: }
3311: }
3312: if ($count{$crstype} < $limit) {
3313: return 'process';
3314: } else {
3315: if (ref($typename) eq 'HASH') {
3316: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').'<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
3317: }
3318: return 'rejected';
3319: }
1.1 raeburn 3320: return;
3321: }
3322:
1.2 raeburn 3323: sub retrieve_settings {
1.26 raeburn 3324: my ($dom,$cnum,$udom,$uname) = @_;
3325: if ($udom eq '' || $uname eq '') {
3326: $udom = $env{'user.domain'};
3327: $uname = $env{'user.name'};
3328: }
3329: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
1.16 raeburn 3330: if ($result eq 'ok') {
1.26 raeburn 3331: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
1.16 raeburn 3332: $env{'form.chome'} = $reqinfo{'coursehome'};
3333: $env{'form.cdescr'} = $reqinfo{'cdescr'};
3334: $env{'form.crstype'} = $reqinfo{'crstype'};
3335: &generate_date_items($reqinfo{'accessstart'},'accessstart');
3336: &generate_date_items($reqinfo{'accessend'},'accessend');
3337: if ($reqinfo{'accessend'} == 0) {
3338: $env{'form.no_end_date'} = 1;
3339: }
3340: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
3341: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
3342: &generate_date_items($reqinfo{'enrollend'},'enrollend');
3343: }
3344: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
3345: $env{'form.clonedom'} = $reqinfo{'clonedom'};
3346: $env{'form.datemode'} = $reqinfo{'datemode'};
3347: $env{'form.dateshift'} = $reqinfo{'dateshift'};
3348: if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) {
3349: $env{'form.sectotal'} = $reqinfo{'sectotal'};
3350: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
3351: $env{'form.autoadds'} = $reqinfo{'autoadds'};
3352: $env{'form.autdrops'} = $reqinfo{'autodrops'};
3353: $env{'form.instcode'} = $reqinfo{'instcode'};
1.24 raeburn 3354: my $crscode = {
3355: $cnum => $reqinfo{'instcode'},
3356: };
3357: &extract_instcode($dom,'instcode',$crscode,$cnum);
1.16 raeburn 3358: }
3359: my @currsec;
3360: if (ref($reqinfo{'sections'}) eq 'HASH') {
3361: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
3362: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
1.24 raeburn 3363: my $sec = $reqinfo{'sections'}{$i}{'inst'};
1.16 raeburn 3364: $env{'form.secnum_'.$i} = $sec;
1.24 raeburn 3365: $env{'form.sec_'.$i} = '1';
1.16 raeburn 3366: if (!grep(/^\Q$sec\E$/,@currsec)) {
3367: push(@currsec,$sec);
3368: }
3369: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
3370: }
3371: }
3372: }
1.24 raeburn 3373: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
3374: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
3375: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
3376: $env{'form.crosslist_'.$i} = '1';
3377: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
3378: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
3379: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
3380: my $key = $cnum.$i;
3381: my $crscode = {
3382: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
3383: };
3384: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
3385: }
1.16 raeburn 3386: }
3387: }
3388: }
3389: if (ref($reqinfo{'personnel'}) eq 'HASH') {
3390: my $i = 0;
3391: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
3392: my ($uname,$udom) = split(':',$user);
3393: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
3394: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
3395: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
3396: $env{'form.person_'.$i.'_role'} = $role;
3397: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
3398: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
3399: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
3400: $env{'form.person_'.$i.'_uname'} = $uname;
3401: $env{'form.person_'.$i.'_dom'} = $udom;
3402: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
3403: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
3404: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
3405: my @newsecs;
3406: if (@usecs > 0) {
3407: foreach my $sec (@usecs) {
3408: if (grep(/^\Q$sec\E/,@currsec)) {
3409: $env{'form.person_'.$i.'_sec'} = $sec;
3410: } else {
1.20 raeburn 3411: push(@newsecs,$sec);
1.16 raeburn 3412: }
3413: }
3414: }
3415: if (@newsecs > 0) {
3416: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
3417: }
3418: }
3419: }
3420: $i ++;
3421: }
3422: }
3423: }
3424: }
3425: $env{'form.persontotal'} = $i;
3426: }
3427: }
3428: }
3429: return $result;
3430: }
3431:
3432: sub get_request_settings {
1.26 raeburn 3433: my ($dom,$cnum,$udom,$uname) = @_;
1.16 raeburn 3434: my $requestkey = $dom.'_'.$cnum;
3435: my ($result,%reqinfo);
3436: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1.26 raeburn 3437: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
1.16 raeburn 3438: my $disposition = $history{'disposition'};
3439: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
3440: if (ref($history{'details'}) eq 'HASH') {
3441: %reqinfo = %{$history{'details'}};
3442: $result = 'ok';
3443: } else {
3444: $result = 'nothash';
3445: }
3446: } else {
3447: $result = 'notqueued';
3448: }
3449: } else {
3450: $result = 'invalid';
3451: }
3452: return ($result,%reqinfo);
3453: }
1.2 raeburn 3454:
1.16 raeburn 3455: sub extract_instcode {
1.24 raeburn 3456: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
1.16 raeburn 3457: my (%codes,@codetitles,%cat_titles,%cat_order);
1.24 raeburn 3458: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
3459: \@codetitles,\%cat_titles,
3460: \%cat_order) eq 'ok') {
3461: if (ref($codes{$crskey}) eq 'HASH') {
1.16 raeburn 3462: if (@codetitles > 0) {
3463: my $sel = $element;
3464: if ($element eq 'crosslist') {
3465: $sel .= '_'.$counter;
3466: }
3467: foreach my $title (@codetitles) {
1.24 raeburn 3468: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
1.16 raeburn 3469: }
3470: }
3471: }
3472: }
3473: return;
1.2 raeburn 3474: }
3475:
1.16 raeburn 3476: sub generate_date_items {
3477: my ($currentval,$item) = @_;
3478: if ($currentval =~ /\d+/) {
3479: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
3480: &Apache::lonhtmlcommon::get_timedates($currentval);
3481: $env{'form.'.$item.'_day'} = $mday;
3482: $env{'form.'.$item.'_month'} = $month+1;
3483: $env{'form.'.$item.'_year'} = $year;
3484: }
3485: return;
1.2 raeburn 3486: }
3487:
1.1 raeburn 3488: 1;
3489:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>