Annotation of loncom/interface/lonrequestcourse.pm, revision 1.26
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.26 ! raeburn 4: # $Id: lonrequestcourse.pm,v 1.25 2009/08/25 14:59:53 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: =head1 NAME
31:
32: Apache::lonrequestcourse.pm
33:
34: =head1 SYNOPSIS
35:
36: Allows users to request creation of new courses.
37:
38: This is part of the LearningOnline Network with CAPA project
39: described at http://www.lon-capa.org.
40:
41: =head1 SUBROUTINES
42:
43: =over
44:
45: =item handler()
46:
1.12 raeburn 47: =item header()
48:
49: =item form_elements()
50:
51: =item onload_action()
52:
53: =item check_can_request()
54:
55: =item course_types()
56:
57: =item print_main_menu()
58:
59: =item request_administration()
60:
61: =item print_request_form()
62:
63: =item print_enrollment_menu()
64:
65: =item inst_section_selector()
66:
67: =item date_setting_table()
68:
69: =item print_personnel_menu()
70:
71: =item print_request_status()
72:
73: =item print_request_logs()
74:
75: =item print_review()
76:
77: =item dates_from_form()
78:
79: =item courseinfo_form()
80:
81: =item clone_form()
82:
83: =item clone_text()
84:
85: =item coursecode_form()
86:
87: =item get_course_dom()
88:
89: =item display_navbuttons()
90:
91: =item print_request_outcome()
92:
93: =item get_processtype()
94:
95: =item check_autolimit()
96:
97: =item build_batchcreatehash()
98:
99: =item retrieve_settings()
100:
101: =item get_request_settings()
102:
1.1 raeburn 103: =back
104:
105: =cut
106:
107: package Apache::lonrequestcourse;
108:
109: use strict;
110: use Apache::Constants qw(:common :http);
111: use Apache::lonnet;
112: use Apache::loncommon;
113: use Apache::lonlocal;
1.8 raeburn 114: use Apache::loncoursequeueadmin;
1.4 raeburn 115: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 116:
117: sub handler {
118: my ($r) = @_;
1.20 raeburn 119: &Apache::loncommon::content_type($r,'text/html');
120: $r->send_http_header;
1.1 raeburn 121: if ($r->header_only) {
122: return OK;
123: }
124:
1.26 ! raeburn 125: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','showdom','cnum']);
1.2 raeburn 126: &Apache::lonhtmlcommon::clear_breadcrumbs();
127: my $dom = &get_course_dom();
1.1 raeburn 128: my $action = $env{'form.action'};
129: my $state = $env{'form.state'};
1.2 raeburn 130: my %stored;
131: my $jscript;
1.26 ! raeburn 132: my ($uname,$udom,$result,$warning);
! 133: if ($action eq 'display') {
! 134: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
! 135: my $namespace = 'courserequestqueue';
! 136: if ($env{'form.cnum'} ne '') {
! 137: my $cnum = $env{'form.cnum'};
! 138: my $reqkey = $cnum.'_approval';
! 139: my $namespace = 'courserequestqueue';
! 140: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
! 141: my %queued =
! 142: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
! 143: if (ref($queued{$reqkey}) eq 'HASH') {
! 144: $uname = $queued{$reqkey}{'ownername'};
! 145: $udom = $queued{$reqkey}{'ownerdom'};
! 146: if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
! 147: $result = &retrieve_settings($dom,$cnum,$udom,$uname);
! 148: } else {
! 149: $warning = &mt('Invalid username or domain for course requestor');
! 150: }
! 151: } else {
! 152: $warning = &mt('No information was found for this course request.');
! 153: }
! 154: } else {
! 155: $warning = &mt('No course request ID provided.');
! 156: }
! 157: } else {
! 158: $warning = &mt('You do not have rights to view course request information.');
! 159: }
! 160: } elsif ((defined($state)) && (defined($action))) {
1.16 raeburn 161: if (($action eq 'view') && ($state eq 'details')) {
162: if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
163: my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
1.2 raeburn 164: }
165: }
1.16 raeburn 166: my %elements = &form_elements($dom);
1.2 raeburn 167: my $elementsref = {};
168: if (ref($elements{$action}) eq 'HASH') {
169: if (ref($elements{$action}{$state}) eq 'HASH') {
170: $elementsref = $elements{$action}{$state};
171: }
172: }
1.16 raeburn 173: if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
174: $env{'form.clonedom'} = $dom;
175: }
1.2 raeburn 176: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
177: }
178:
179: if ($state eq 'personnel') {
180: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
181: }
182:
183: my $loaditems = &onload_action($action,$state);
184:
185: my %states;
1.26 ! raeburn 186: $states{'display'} = ['details'];
1.16 raeburn 187: $states{'view'} = ['pick_request','details','cancel','removal'];
1.2 raeburn 188: $states{'log'} = ['filter','display'];
189: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
1.20 raeburn 190:
1.2 raeburn 191: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
192: unless ($env{'form.state'} eq 'crstype') {
1.20 raeburn 193: unshift(@{$states{'new'}},'codepick');
1.2 raeburn 194: }
195: }
196:
197: foreach my $key (keys(%states)) {
198: if (ref($states{$key}) eq 'ARRAY') {
199: unshift (@{$states{$key}},'crstype');
200: }
201: }
202:
1.3 raeburn 203: my %trail = (
1.10 raeburn 204: crstype => 'Course Request Action',
205: codepick => 'Category',
206: courseinfo => 'Description',
1.16 raeburn 207: enrollment => 'Access Dates',
1.10 raeburn 208: personnel => 'Personnel',
209: review => 'Review',
210: process => 'Result',
211: pick_request => 'Display Summary',
1.16 raeburn 212: details => 'Request Details',
213: cancel => 'Cancel Request',
214: removal => 'Outcome',
1.3 raeburn 215: );
216:
1.16 raeburn 217: if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
218: $trail{'enrollment'} = 'Enrollment';
219: }
220:
1.2 raeburn 221: my $page = 0;
1.3 raeburn 222: my $crumb;
1.2 raeburn 223: if (defined($action)) {
224: my $done = 0;
225: my $i=0;
226: if (ref($states{$action}) eq 'ARRAY') {
227: while ($i<@{$states{$action}} && !$done) {
228: if ($states{$action}[$i] eq $state) {
229: $page = $i;
230: $done = 1;
231: }
232: $i++;
233: }
234: }
1.3 raeburn 235: for (my $i=0; $i<@{$states{$action}}; $i++) {
236: if ($state eq $states{$action}[$i]) {
237: &Apache::lonhtmlcommon::add_breadcrumb(
238: {text=>"$trail{$state}"});
239: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
240: last;
241: } else {
242: if (($state eq 'process') && ($i > 0)) {
243: &Apache::lonhtmlcommon::add_breadcrumb(
244: {href=>"javascript:backPage(document.requestcrs,'$states{$action}[0]')",
245: text=>"$trail{$states{$action}[$i]}"});
246: } else {
247: &Apache::lonhtmlcommon::add_breadcrumb(
248: {href=>"javascript:backPage(document.requestcrs,'$states{$action}[$i]')",
249: text=>"$trail{$states{$action}[$i]}"});
250: }
251: }
252: }
253: } else {
254: &Apache::lonhtmlcommon::add_breadcrumb(
255: {text=>'Pick Action'});
256: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
1.2 raeburn 257: }
258:
1.1 raeburn 259: my %can_request;
260: my $canreq = &check_can_request($dom,\%can_request);
261: if ($action eq 'new') {
262: if ($canreq) {
263: if ($state eq 'crstype') {
1.3 raeburn 264: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
265: $crumb);
1.1 raeburn 266: } else {
1.2 raeburn 267: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.3 raeburn 268: $loaditems,$crumb);
1.1 raeburn 269: }
270: } else {
1.3 raeburn 271: $r->print(&header('Course Requests').$crumb.
1.1 raeburn 272: '<div class="LC_warning">'.
273: &mt('You do not have privileges to request creation of courses.').
1.2 raeburn 274: '</div>'.&Apache::loncommon::end_page());
1.1 raeburn 275: }
276: } elsif ($action eq 'view') {
1.10 raeburn 277: if ($state eq 'crstype') {
1.26 ! raeburn 278: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
! 279: } else {
! 280: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
! 281: $loaditems,$crumb);
! 282: }
! 283: } elsif ($action eq 'display') {
! 284: if ($warning ne '') {
! 285: my $args = { only_body => 1 };
! 286: $r->print(&header('Course Requests','','',$args).$crumb.
! 287: '<h3>'.&mt('Course Request Details').'</h3>'.
! 288: '<div class="LC_warning">'.$warning.'</div>'.
! 289: &close_popup_form());
1.11 raeburn 290: } else {
1.26 ! raeburn 291: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
! 292: $loaditems,$crumb,$uname,$udom);
1.10 raeburn 293: }
1.1 raeburn 294: } elsif ($action eq 'log') {
1.3 raeburn 295: &print_request_logs($jscript,$loaditems,$crumb);
1.1 raeburn 296: } else {
1.3 raeburn 297: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
1.1 raeburn 298: }
299: return OK;
300: }
301:
1.2 raeburn 302: sub header {
1.26 ! raeburn 303: my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
1.2 raeburn 304: if ($jscript) {
1.6 raeburn 305: $jscript = '<script type="text/javascript">'."\n".
306: '// <![CDATA['."\n".
307: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
1.2 raeburn 308: }
309: if ($loaditems) {
1.26 ! raeburn 310: if (ref($args) eq 'HASH') {
! 311: my %loadhash = (
! 312: 'add_entries' => $loaditems,
! 313: );
! 314: my %arghash = (%loadhash,%{$args});
! 315: $args = \%arghash;
! 316: } else {
! 317: $args = {'add_entries' => $loaditems,};
! 318: }
1.3 raeburn 319: }
1.26 ! raeburn 320: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
1.2 raeburn 321: }
322:
323: sub form_elements {
324: my ($dom) = @_;
325: my %elements =
326: (
327: new => {
328: crstype => {
329: crstype => 'selectbox',
330: action => 'selectbox',
1.16 raeburn 331: origcnum => 'hidden',
1.2 raeburn 332: },
333: courseinfo => {
334: cdescr => 'text',
1.13 raeburn 335: clonecrs => 'text',
336: clonedom => 'selectbox',
1.2 raeburn 337: datemode => 'radio',
338: dateshift => 'text',
339: },
340: enrollment => {
1.13 raeburn 341: accessstart_month => 'selectbox',
342: accessstart_hour => 'selectbox',
343: accessend_month => 'selectbox',
344: accessend_hour => 'selectbox',
345: accessstart_day => 'text',
346: accessstart_year => 'text',
347: accessstart_minute => 'text',
348: accessstart_second => 'text',
349: accessend_day => 'text',
350: accessend_year => 'text',
351: accessend_minute => 'text',
352: accessend_second => 'text',
1.2 raeburn 353: no_end_date => 'checkbox',
354: },
355: personnel => {
356: addperson => 'checkbox',
357: },
1.13 raeburn 358: review => {
359: cnum => 'hidden',
360: },
1.2 raeburn 361: },
362: view => {
363: crstype => {
364: crstype => 'selectbox',
365: action => 'selectbox',
366: },
367: },
368: );
1.13 raeburn 369: my %servers = &Apache::lonnet::get_servers($dom,'library');
370: my $numlib = keys(%servers);
371: if ($numlib > 1) {
372: $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
373: } else {
374: $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
375: }
1.2 raeburn 376: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
377: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
378: \%cat_order,\@code_order);
379: my $numtitles = scalar(@codetitles);
380: if ($numtitles) {
381: my %extras;
382: $lastitem = pop(@codetitles);
383: $extras{'instcode_'.$lastitem} = 'text';
384: foreach my $item (@codetitles) {
385: $extras{'instcode_'.$item} = 'selectbox';
386: }
387: $elements{'new'}{'codepick'} = \%extras;
388: }
389: if (&Apache::lonnet::auto_run('',$dom)) {
390: my %extras = (
391: sectotal => 'hidden',
1.13 raeburn 392: enrollstart_month => 'selectbox',
393: enrollstart_hour => 'selectbox',
394: enrollend_month => 'selectbox',
395: enrollend_hour => 'selectbox',
396: enrollstart_day => 'text',
397: enrollstart_year => 'text',
398: enrollstart_minute => 'text',
399: enrollstart_second => 'text',
400: enrollend_day => 'text',
401: enrollend_year => 'text',
402: enrollend_minute => 'text',
403: enrollend_second => 'text',
1.2 raeburn 404: crosslisttotal => 'hidden',
405: addcrosslist => 'checkbox',
406: autoadds => 'radio',
407: autodrops => 'radio',
408: );
409: if ($env{'form.sectotal'} > 0) {
410: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
411: $extras{'sec_'.$i} = 'checkbox',
412: $extras{'secnum_'.$i} = 'text',
1.24 raeburn 413: $extras{'loncapasec_'.$i} = 'text',
1.2 raeburn 414: }
415: }
416: my $crosslisttotal = $env{'form.crosslisttotal'};
1.16 raeburn 417: if ($env{'form.addcrosslist'}) {
418: $crosslisttotal ++;
419: }
1.24 raeburn 420: if (!$crosslisttotal) {
1.2 raeburn 421: $crosslisttotal = 1;
422: }
1.24 raeburn 423: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
424: if ($numtitles) {
425: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
426: }
427: if (@codetitles > 0) {
428: foreach my $item (@codetitles) {
429: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
1.2 raeburn 430: }
431: }
1.24 raeburn 432: $extras{'crosslist_'.$i} = 'checkbox';
433: $extras{'crosslist_'.$i.'_instsec'} = 'text',
434: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
1.2 raeburn 435: }
436: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
437: %{$elements{'new'}{'enrollment'}} = %mergedhash;
438: }
439: my %people;
440: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 441: if ($env{'form.addperson'}) {
442: $persontotal ++;
443: }
444: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 445: $persontotal = 1;
446: }
447: for (my $i=0; $i<$persontotal; $i++) {
1.13 raeburn 448: $people{'person_'.$i.'_uname'} = 'text',
449: $people{'person_'.$i.'_dom'} = 'selectbox',
450: $people{'person_'.$i.'_hidedom'} = 'hidden',
451: $people{'person_'.$i.'_firstname'} = 'text',
452: $people{'person_'.$i.'_lastname'} = 'text',
453: $people{'person_'.$i.'_emailaddr'} = 'text',
454: $people{'person_'.$i.'_role'} = 'selectbox',
455: $people{'person_'.$i.'_sec'} = 'selectbox',
456: $people{'person_'.$i.'_newsec'} = 'text',
1.2 raeburn 457: }
458: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
459: %{$elements{'new'}{'personnel'}} = %personnelhash;
460: return %elements;
461: }
462:
463: sub onload_action {
464: my ($action,$state) = @_;
465: my %loaditems;
466: if (($action eq 'new') || ($action eq 'view')) {
467: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs)';
468: }
469: return \%loaditems;
470: }
471:
1.1 raeburn 472: sub check_can_request {
473: my ($dom,$can_request) = @_;
474: my $canreq = 0;
1.4 raeburn 475: my ($types,$typename) = &course_types();
1.19 raeburn 476: my @options = ('approval','validate','autolimit');
477: my $optregex = join('|',@options);
1.4 raeburn 478: if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) {
479: foreach my $type (@{$types}) {
1.1 raeburn 480: if (&Apache::lonnet::usertools_access($env{'user.name'},
481: $env{'user.domain'},
482: $type,undef,'requestcourses')) {
483: $canreq ++;
484: if ($dom eq $env{'user.domain'}) {
485: $can_request->{$type} = 1;
486: }
487: }
488: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
489: my @curr = split(',',$env{'environment.reqcrsotherdom.'.$type});
490: if (@curr > 0) {
491: $canreq ++;
492: unless ($dom eq $env{'user.domain'}) {
1.19 raeburn 493: if (grep(/^\Q$dom\E:($optregex)(=?\d*)$/,@curr)) {
1.1 raeburn 494: $can_request->{$type} = 1;
495: }
496: }
497: }
498: }
499: }
500: }
501: return $canreq;
502: }
503:
1.4 raeburn 504: sub course_types {
505: my @types = ('official','unofficial','community');
506: my %typename = (
507: official => 'Official course',
508: unofficial => 'Unofficial course',
509: community => 'Community',
510: );
511: return (\@types,\%typename);
512: }
513:
514:
1.1 raeburn 515: sub print_main_menu {
1.3 raeburn 516: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_;
1.4 raeburn 517: my ($types,$typename) = &course_types();
1.1 raeburn 518: my $onchange;
519: unless ($env{'form.interface'} eq 'textual') {
520: $onchange = 1;
521: }
522:
1.2 raeburn 523: my $nextstate_setter = "\n";
524: if (ref($states) eq 'HASH') {
525: foreach my $key (keys(%{$states})) {
526: if (ref($states->{$key}) eq 'ARRAY') {
527: $nextstate_setter .=
528: " if (actionchoice == '$key') {
529: nextstate = '".$states->{$key}[1]."';
530: }
531: ";
532: }
533: }
534: }
1.1 raeburn 535:
1.2 raeburn 536: my $js = <<"END";
1.1 raeburn 537:
1.2 raeburn 538: function nextPage(formname) {
539: var crschoice = document.requestcrs.crstype.value;
540: var actionchoice = document.requestcrs.action.value;
541: if (check_can_request(crschoice,actionchoice) == true) {
542: if ((actionchoice == 'new') && (crschoice == 'official')) {
543: nextstate = 'codepick';
544: } else {
545: $nextstate_setter
546: }
1.1 raeburn 547: formname.state.value= nextstate;
548: formname.submit();
549: }
550: return;
551: }
552:
1.2 raeburn 553: function check_can_request(crschoice,actionchoice) {
1.1 raeburn 554: var official = '';
555: var unofficial = '';
556: var community = '';
557: END
558:
559: foreach my $item (keys(%{$can_request})) {
560: $js .= "
561: $item = 1;
562: ";
563: }
564: my %lt = &Apache::lonlocal::texthash(
565: official => 'You are not permitted to request creation of an official course in this domain.',
566: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
567: community => 'You are not permitted to request creation of a community this domain.',
568: all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
569: );
570: $js .= <<END;
571: if (crschoice == 'official') {
572: if (official != 1) {
573: alert("$lt{'official'}");
574: return false;
575: }
576: } else {
577: if (crschoice == 'unofficial') {
578: if (unofficial != 1) {
579: alert("$lt{'unofficial'}");
580: return false;
581: }
582: } else {
583: if (crschoice == 'community') {
584: if (community != 1) {
585: alert("$lt{'community'}");
586: return false;
587: }
588: } else {
589: if (actionchoice == 'new') {
590: alert("$lt{'all'}");
591: return false;
592: }
593: }
594: }
595: }
596: return true;
597: }
598:
599: END
600:
1.3 raeburn 601: $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.
602: '<div>'.
1.1 raeburn 603: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
604: &Apache::lonhtmlcommon::start_pick_box().
1.8 raeburn 605: &Apache::lonhtmlcommon::row_title('Course Domain').
1.1 raeburn 606: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange));
607: if (!$onchange) {
608: $r->print(' <input type="submit" name="godom" value="'.
609: &mt('Change').'" />');
610: }
611: $r->print(&Apache::lonhtmlcommon::row_closure(1).
612: &Apache::lonhtmlcommon::end_pick_box().'</form></div>');
613:
1.2 raeburn 614: my $formname = 'requestcrs';
1.1 raeburn 615: my $nexttext = &mt('Next');
1.14 raeburn 616: $r->print(
617: '<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'.
1.1 raeburn 618: &Apache::lonhtmlcommon::start_pick_box().
619: &Apache::lonhtmlcommon::row_title('Action').'
620: <input type="hidden" name="showdom" value="'.$dom.'" />
621: <select size="1" name="action" >
1.2 raeburn 622: <option value="new">'.&mt('New request').'</option>
1.1 raeburn 623: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
624: <option value="log">'.&mt('View request history').'</option>
625: </select>'.
626: &Apache::lonhtmlcommon::row_closure().
627: &Apache::lonhtmlcommon::row_title('Course Type').'
628: <select size="1" name="crstype">
1.4 raeburn 629: <option value="any">'.&mt('All types').'</option>');
630: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
631: foreach my $type (@{$types}) {
632: my $selected = '';
633: if ($type eq 'official') {
634: $selected = ' selected="selected"';
635: }
636: $r->print('<option value="'.$type.'"'.$selected.'>'.$typename->{$type}.
637: '</option>'."\n");
638: }
639: }
640: $r->print('</select>
1.1 raeburn 641: <input type="hidden" name="state" value="crstype" />'.
642: &Apache::lonhtmlcommon::row_closure(1).
643: &Apache::lonhtmlcommon::end_pick_box().'<br />
1.2 raeburn 644: <input type="button" name="next" value="'.$nexttext.'" onclick="javascript:nextPage(document.'.$formname.')" />
1.1 raeburn 645: </form></div>');
646: $r->print(&Apache::loncommon::end_page());
647: return;
648: }
649:
650: sub request_administration {
1.26 ! raeburn 651: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,$uname,$udom) = @_;
1.2 raeburn 652: my $js;
1.16 raeburn 653: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
1.2 raeburn 654: $js = <<END;
1.1 raeburn 655:
656: function nextPage(formname,nextstate) {
657: formname.state.value= nextstate;
658: formname.submit();
659: }
1.16 raeburn 660:
661: END
662: }
663: if (($action eq 'new') || ($action eq 'view')) {
664: $js .= <<END;
665:
1.1 raeburn 666: function backPage(formname,prevstate) {
667: formname.state.value = prevstate;
668: formname.submit();
669: }
670:
671: END
1.2 raeburn 672: }
673: if ($action eq 'new') {
674: my $jsextra;
1.1 raeburn 675: unless (($state eq 'review') || ($state eq 'process')) {
1.2 raeburn 676: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
1.1 raeburn 677: }
1.3 raeburn 678: $r->print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb);
1.8 raeburn 679: &print_request_form($r,$action,$state,$page,$states,$dom);
1.2 raeburn 680: } elsif ($action eq 'view') {
1.16 raeburn 681: my $jsextra;
682: my $formname = 'requestcrs';
683: my $prev = $states->{$action}[$page-1];
684: my $next = $states->{$action}[$page+1];
685: if ($state eq 'pick_request') {
686: $next = $states->{$action}[$page+1];
687: $jsextra = &viewrequest_javascript($formname,$next);
688: } elsif ($state eq 'details') {
689: $jsextra = &viewdetails_javascript($formname);
690:
691: } elsif ($state eq 'cancel') {
692: $jsextra = &viewcancel_javascript($formname);
693: }
694: $r->print(&header('Manage course requests',$js.$jscript.$jsextra,$loaditems).
695: $crumb);
696: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
1.11 raeburn 697: if ($state eq 'pick_request') {
1.16 raeburn 698: $r->print('<h3>'.&mt('Pending course requests').'</h3><div>'."\n".$form."\n".
699: &print_request_status($dom).'</form>');
700: } elsif ($state eq 'details') {
701: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
702: my $origcnum = $env{'form.cnum'};
703: if ($origcnum eq '') {
704: $origcnum = $env{'form.origcnum'};
705: }
706: if ($env{'form.crstype'} eq 'official') {
707: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
708: \%cat_order,\@code_order);
709: }
710: $r->print('<h3>'.&mt('Course Request Details').'</h3><div>'."\n".$form."\n".
1.26 ! raeburn 711: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.16 raeburn 712: \@code_order)."\n".
713: '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
714: my @excluded = &get_excluded_elements($dom,$states,'new','review');
715: push(@excluded,'origcnum');
716: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
717: my $other = 'modify';
718: my %navtxt = &Apache::lonlocal::texthash (
719: prev => 'Back',
720: other => 'Modify Request',
721: next => 'Cancel Request',
722: );
723: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'},
724: $state,$other,$navtxt{'other'});
725: $r->print('</form>');
726: } elsif ($state eq 'cancel') {
727: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
728: $r->print('<h3>'.&mt('Cancel course request').'</h3><div>'."\n".$form."\n".
729: $output);
730: my @excluded = &get_excluded_elements($dom,$states,'view','cancel');
731: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
732: my %navtxt = &Apache::lonlocal::texthash (
733: prev => 'Back',
734: next => 'Confirm Cancellation',
735: );
736: if ($result eq 'ok') {
737: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,
738: $navtxt{'next'},$state);
739: } else {
740: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},undef,'',$state);
741: }
742: $r->print('</form>');
743: } elsif ($state eq 'removal') {
744: my $cnum = $env{'form.origcnum'};
745: my $statuskey = 'status:'.$dom.':'.$cnum;
746: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
747: $env{'user.domain'},$env{'user.name'});
748: my $currstatus = $userreqhash{$statuskey};
749: my ($result,$error);
750: if (($currstatus eq 'approval') || ($currstatus eq 'pending')) {
751: my %status = (
752: $statuskey => 'cancelled',
753: );
754: my $statusresult = &Apache::lonnet::put('courserequests',\%status);
755: if ($statusresult eq 'ok') {
756: my $delresult =
757: &Apache::lonnet::del_dom('courserequestqueue',
758: [$cnum.'_'.$currstatus],$dom);
759: if ($delresult eq 'ok') {
760: $result = 'ok';
761: } else {
762: $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
763: }
764: } else {
765: $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
766: }
767: } else {
768: $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');
769: }
770: $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
771: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
772: '<input type="hidden" name="action" value="'.$action.'" />'."\n".
773: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
774: '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
775: if ($result eq 'ok') {
776: $r->print(&mt('Your course request has been cancelled.'));
777: } else {
778: $r->print('<div class="LC_error">'.
779: &mt('The request cancellation process was not complete.').
780: '<br />'.$error.'</div>');
781: }
782: $r->print('</form>');
1.11 raeburn 783: }
1.26 ! raeburn 784: } elsif ($action eq 'display') {
! 785: my $formname = 'requestcrs';
! 786: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
! 787: if ($env{'form.crstype'} eq 'official') {
! 788: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
! 789: \%cat_order,\@code_order);
! 790: }
! 791: $r->print(&header('Course Request','','','',{ 'only_body' => 1}).
! 792: $crumb."\n".'<h3>'.&mt('Course Request Details').'</h3>'.
! 793: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
! 794: \@code_order,$uname,$udom)."\n".'</div>'.
! 795: &close_popup_form());
1.1 raeburn 796: } elsif ($action eq 'log') {
1.11 raeburn 797: $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
1.1 raeburn 798: }
1.2 raeburn 799: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 800: return;
801: }
802:
1.26 ! raeburn 803: sub close_popup_form {
! 804: my $close= &mt('Close Window');
! 805: return << "END";
! 806: <p><form name="displayreq" action="" method="post">
! 807: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
! 808: </form></p>
! 809: END
! 810: }
! 811:
1.1 raeburn 812: sub print_request_form {
1.2 raeburn 813: my ($r,$action,$state,$page,$states,$dom) = @_;
1.1 raeburn 814: my $formname = 'requestcrs';
1.2 raeburn 815: my ($next,$prev,$message,$output,$codepicker,$crstype);
816: $prev = $states->{$action}[$page-1];
817: $next = $states->{$action}[$page+1];
1.4 raeburn 818: my %navtxt = &Apache::lonlocal::texthash (
1.10 raeburn 819: prev => 'Back',
1.4 raeburn 820: next => 'Next',
821: );
1.2 raeburn 822: $crstype = $env{'form.crstype'};
1.1 raeburn 823: $r->print('<form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.2 raeburn 824: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1.1 raeburn 825: if ($crstype eq 'official') {
1.2 raeburn 826: if ($env{'form.instcode'} ne '') {
827: $instcode = $env{'form.instcode'};
828: }
829: }
830: if ($prev eq 'codepick') {
1.4 raeburn 831: if ($crstype eq 'official') {
832: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
833: \%cat_order,\@code_order);
834: }
1.2 raeburn 835: if (@code_order > 0) {
836: my $message;
837: if ($instcode eq '') {
1.1 raeburn 838: foreach my $item (@code_order) {
1.2 raeburn 839: $instcode .= $env{'form.instcode_'.$item};
1.1 raeburn 840: }
1.2 raeburn 841: $r->print('<input type="hidden" name="instcode" value="'.$instcode.'" />'."\n");
1.1 raeburn 842: }
843: if ($instcode ne '') {
1.2 raeburn 844: $code_chk = &Apache::lonnet::auto_validate_instcode('',$dom,$instcode);
1.17 raeburn 845: if ($code_chk eq 'valid') {
1.1 raeburn 846: $message = '<div class="LC_info">'.
847: &mt('The chosen course category [_1] is valid.','<b>'.
1.2 raeburn 848: $instcode.'</b>').'</div>';
1.1 raeburn 849: } else {
850: $message = '<div class="LC_warning">'.
851: &mt('No course was found matching your choice of institutional course category.');
852: if ($code_chk ne '') {
853: $message .= '<br />'.$code_chk;
854: }
855: $message .= '</div>';
856: }
1.2 raeburn 857: } else {
858: $message = '<div class="LC_warning">'.
859: &mt('No course was found matching your choice of institutional course category.');
1.1 raeburn 860: }
1.21 raeburn 861: unless ($code_chk eq 'valid') {
1.2 raeburn 862: $prev = 'crstype';
863: }
864: $r->print($message);
1.1 raeburn 865: }
1.2 raeburn 866: }
867: if ($prev eq 'crstype') {
1.4 raeburn 868: if ($crstype eq 'official') {
869: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
870: \%cat_order,\@code_order);
871: }
1.2 raeburn 872: if (@code_order > 0) {
1.1 raeburn 873: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
874: \%cat_titles,\%cat_order);
1.2 raeburn 875: if ($codepicker) {
876: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box().$codepicker.
877: &Apache::lonhtmlcommon::end_pick_box().'</div>');
878: } else {
1.20 raeburn 879: $next = $states->{$action}[$page+2];
1.15 raeburn 880: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 881: }
882: } else {
1.20 raeburn 883: if ($crstype eq 'official') {
884: $next = $states->{$action}[$page+2];
885: }
1.15 raeburn 886: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.1 raeburn 887: }
1.2 raeburn 888: } elsif ($prev eq 'codepick') {
1.20 raeburn 889: if ($env{'form.instcode'} eq '') {
890: $prev = $states->{$action}[$page-2];
891: }
1.15 raeburn 892: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 893: } elsif ($state eq 'enrollment') {
1.4 raeburn 894: if ($crstype eq 'official') {
895: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
896: \%cat_order,\@code_order);
897: }
1.2 raeburn 898: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
899: \%cat_titles,\%cat_order,\@code_order));
900: } elsif ($state eq 'personnel') {
1.8 raeburn 901: $r->print(&print_personnel_menu($dom,$formname,$crstype));
1.4 raeburn 902: } elsif ($state eq 'review') {
1.16 raeburn 903: my $cnum;
904: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
905: $cnum = $env{'form.origcnum'};
906: } else {
907: $cnum = &Apache::lonnet::generate_coursenum($dom);
908: }
1.4 raeburn 909: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
910: \%cat_order,\@code_order);
1.16 raeburn 911: $r->print('<p>'.&mt('Review the details of the course request before submission.').'</p>'.
1.26 ! raeburn 912: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order).
1.16 raeburn 913: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1.4 raeburn 914: $navtxt{'next'} = &mt('Submit course request');
1.10 raeburn 915: } elsif ($state eq 'process') {
916: if ($crstype eq 'official') {
917: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
918: \%cat_order,\@code_order);
919: }
920: my $result = &print_request_outcome($dom,\@codetitles,\@code_order);
1.13 raeburn 921: $r->print($result);
1.1 raeburn 922: }
1.16 raeburn 923: my @excluded = &get_excluded_elements($dom,$states,$action,$state);
1.24 raeburn 924: if ($state eq 'personnel') {
925: push(@excluded,'persontotal');
926: }
1.16 raeburn 927: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
928: &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'},$state);
929: return;
930: }
931:
932: sub get_excluded_elements {
933: my ($dom,$states,$action,$state) = @_;
1.2 raeburn 934: my @excluded = ('counter');
935: my %elements = &form_elements($dom);
936: if (ref($states) eq 'HASH') {
937: if (ref($states->{$action}) eq 'ARRAY') {
938: my @items = @{$states->{$action}};
939: my $numitems = scalar(@items);
940: if ($numitems) {
941: for (my $i=$numitems-1; $i>=0; $i--) {
942: if (ref($elements{$action}) eq 'HASH') {
943: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
1.16 raeburn 944: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
1.2 raeburn 945: push(@excluded,$key);
946: }
947: }
948: }
949: last if ($items[$i] eq $state);
950: }
951: }
952: }
953: }
954: if (grep(/^instcode_/,@excluded)) {
955: push(@excluded,'instcode');
1.1 raeburn 956: }
1.16 raeburn 957: return @excluded;
1.1 raeburn 958: }
959:
1.2 raeburn 960: sub print_enrollment_menu {
961: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order) =@_;
962: my ($sections,$autoenroll,$access_dates);
963: my $starttime = time;
964: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
965:
966: my %accesstitles = (
967: 'start' => 'Default start access',
1.16 raeburn 968: 'end' => 'Default end access',
1.2 raeburn 969: );
970: my %enrolltitles = (
971: 'start' => 'Start auto-enrollment',
972: 'end' => 'End auto-enrollment',
973: );
974: if ($env{'form.crstype'} eq 'official') {
975: if (&Apache::lonnet::auto_run('',$dom)) {
976: my ($section_form,$crosslist_form,$autoenroll_form);
977: $section_form = &inst_section_selector($dom,$instcode);
978: my $crosslisttotal = $env{'form.crosslisttotal'};
1.24 raeburn 979: if (!$crosslisttotal) {
1.2 raeburn 980: $crosslisttotal = 1;
981: }
982: if ($env{'form.addcrosslist'}) {
983: $crosslisttotal ++;
984: }
985: for (my $i=0; $i<$crosslisttotal; $i++) {
986: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
987: $cat_titles,$cat_order,$i);
988: }
989: if ($crosslist_form) {
990: $crosslist_form .=
991: &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
992: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
993: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
994: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
995: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1);
996: }
997: if ($section_form || $crosslist_form) {
998: $sections = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
999: $section_form.$crosslist_form.
1000: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
1001: }
1002: $autoenroll_form =
1003: &Apache::lonhtmlcommon::row_title(&mt('Add registered students automatically')).
1004: '<span class="LC_nobreak"><label>'.
1005: '<input type="radio" name="autoadds" value="1">'.
1006: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1007: '<input type="radio" name="autoadds" value="0" checked="checked">'.
1008: &mt('No').'</label></span>'.
1009: &Apache::lonhtmlcommon::row_closure().
1010: &Apache::lonhtmlcommon::row_title(&mt('Drop unregistered students automatically')).
1011: '<span class="LC_nobreak"><label>'.
1012: '<input type="radio" name="autodrops" value="1">'.
1013: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1014: '<input type="radio" name="autodrops" value="0" checked="checked">'.
1015: &mt('No').'</label></span>'.
1016: &Apache::lonhtmlcommon::row_closure().
1017: &date_setting_table($starttime,$endtime,$formname,'enroll',%enrolltitles);
1018: if ($autoenroll_form) {
1019: $autoenroll = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1020: $autoenroll_form.
1021: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
1022: }
1023: }
1024: }
1025: my $access_dates_form =
1026: &date_setting_table($starttime,$endtime,$formname,'access',%accesstitles);
1027: if ($access_dates_form) {
1028: $access_dates = '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1029: $access_dates_form.
1030: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
1031: }
1032: return $sections.$autoenroll.$access_dates;
1033: }
1034:
1.1 raeburn 1035: sub inst_section_selector {
1.2 raeburn 1036: my ($dom,$instcode) = @_;
1037: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1038: my $sectotal = scalar(@sections);
1.1 raeburn 1039: my $output;
1.2 raeburn 1040: if ($sectotal) {
1041: $output .= &Apache::lonhtmlcommon::row_title('Sections').
1042: &Apache::loncommon::start_data_table().
1043: &Apache::loncommon::start_data_table_row().
1044: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1.24 raeburn 1045: 'value="'.$sectotal.'" /></th>'.
1.2 raeburn 1046: '<th>'.&mt('Institutional Section').'</th>'.
1047: '<th>'.&mt('LON-CAPA section').'</th>'.
1048: &Apache::loncommon::end_data_table_row();
1049: for (my $i=0; $i<@sections; $i++) {
1.1 raeburn 1050: my $colflag = $i%2;
1.24 raeburn 1051: my $checked = ' checked="checked"';
1052: if ($env{'form.origcnum'}) {
1053: $checked='';
1054: }
1.1 raeburn 1055: $output .= &Apache::loncommon::start_data_table_row().
1.2 raeburn 1056: '<td><input type="checkbox" name="sec_'.$i.
1.24 raeburn 1057: '"'.$checked.' value="1" /></td>'.
1.2 raeburn 1058: '<td>'.$sections[$i].
1.1 raeburn 1059: '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2 raeburn 1060: $sections[$i].'" /></td>'.
1.1 raeburn 1061: '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2 raeburn 1062: '" value="'.$sections[$i].'" /></td>'.
1.1 raeburn 1063: &Apache::loncommon::end_data_table_row();
1064: }
1.2 raeburn 1065: $output .= &Apache::loncommon::end_data_table().
1066: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1067: }
1068: return $output;
1069: }
1070:
1.2 raeburn 1071: sub date_setting_table {
1.14 raeburn 1072: my ($starttime,$endtime,$formname,$prefix,%datetitles) = @_;
1.2 raeburn 1073: my ($perpetual,$table);
1.14 raeburn 1074: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.2 raeburn 1075: $starttime,'','','',1,'','','',1);
1.14 raeburn 1076: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.2 raeburn 1077: $endtime,'','','',1,'','','',1);
1.14 raeburn 1078: if ($prefix eq 'access') {
1.2 raeburn 1079: $perpetual = ' <span class="LC_nobreak"><label>'.
1080: '<input type="checkbox" name="no_end_date" />'.
1081: &mt('No end date').'</label></span>';
1082: }
1083: $table = &Apache::lonhtmlcommon::row_title($datetitles{'start'}).
1084: $startform.
1085: &Apache::lonhtmlcommon::row_closure().
1086: &Apache::lonhtmlcommon::row_title($datetitles{'end'}).
1087: $endform.$perpetual.
1088: &Apache::lonhtmlcommon::row_closure(1);
1089: return $table;
1090: }
1091:
1092: sub print_personnel_menu {
1.8 raeburn 1093: my ($dom,$formname,$crstype) = @_;
1.2 raeburn 1094: my $output = '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1095: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 1096: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 1097: $persontotal = 1;
1098: }
1099: if ($env{'form.addperson'}) {
1100: $persontotal ++;
1101: }
1102: my $userlinktxt = &mt('Set User');
1.13 raeburn 1103: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2 raeburn 1104:
1105: my $roleoptions;
1106: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 1107: my $type = 'Course';
1108: if ($crstype eq 'community') {
1109: $type = 'Community';
1110: }
1.2 raeburn 1111: foreach my $role (@roles) {
1.8 raeburn 1112: my $plrole=&Apache::lonnet::plaintext($role,$type);
1.2 raeburn 1113: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1114: }
1115: my %customroles=&Apache::lonuserutils::my_custom_roles();
1116: if (keys(%customroles) > 0) {
1117: foreach my $cust (sort(keys(%customroles))) {
1118: my $custrole='cr_cr_'.$env{'user.domain'}.
1119: '_'.$env{'user.name'}.'_'.$cust;
1120: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
1121: }
1122: }
1123:
1124: my @currsecs;
1125: if ($env{'form.sectotal'}) {
1126: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1127: if (defined($env{'form.loncapasec_'.$i})) {
1128: my $lcsec = $env{'form.loncapasec_'.$i};
1129: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
1130: push(@currsecs,$lcsec);
1131: }
1132: }
1133: }
1134: }
1135:
1136: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
1137: if (@currsecs) {
1138: my $existsize = scalar(@currsecs);
1139: if ($existsize > 3) {
1140: $existsize = 3;
1141: }
1142: if ($existsize > 1) {
1143: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
1144: }
1145: @currsecs = sort { $a <=> $b } (@currsecs);
1146: $existtitle = &mt('Official').': ';
1147: $existops = '<option value="">'.&mt('None').'</option>';
1148: foreach my $sec (@currsecs) {
1149: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
1150: }
1151: $seccolspan = ' colspan="2"';
1152: $newtitle = &mt('Other').': ';
1153: }
1154:
1155: for (my $i=0; $i<$persontotal; $i++) {
1156: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
1157: my $linkargstr = join("','",@linkargs);
1.7 raeburn 1158: my $userlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,$userlinktxt);
1.2 raeburn 1159: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value=""'.
1160: ' onFocus="this.blur();'.
1.7 raeburn 1161: 'openuserbrowser('."'$formname','$linkargstr','$dom'".');" />';
1.2 raeburn 1162: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1163: "'person_".$i."_hidedom'".');'.
1.7 raeburn 1164: 'openuserbrowser('."'$formname','$linkargstr','$dom'".');';
1.2 raeburn 1165: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1166: 1,$onchange).
1167: '<input type="hidden" name="person_'.$i.'_hidedom" value="'.$dom.'" />';
1168: my %form_elems;
1169: foreach my $item (@items) {
1170: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
1171: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
1172: 'value="" readonly="readonly" />';
1173: }
1174: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
1175: $roleoptions.'</select>';
1176: my $sectionselector;
1177: if (@currsecs) {
1178: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
1179: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
1180: }
1181: $sectionselector .= $newtitle.
1.14 raeburn 1182: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.2 raeburn 1183: $output .=
1184: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel').'<br />'.
1185: '<span class="LC_nobreak">'.$userlink.
1186: '</span>').
1187: '<table><tr><td align="center" valign="top">'.&mt('Username').'<br />'.$uname_form.'</td>'."\n".
1188: '<td align="center" valign="top" colspan="2">'.&mt('Domain').'<br />'.$udom_form.'</td></tr><tr>'."\n".
1.13 raeburn 1189: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
1190: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
1191: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.2 raeburn 1192: '<tr><td align="center" valign="top">'.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
1193: '<td'.$seccolspan.' align="center" valign="top">'.&mt('Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1194: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
1195: }
1196: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
1197: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
1198: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1199: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1200: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1201: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1202: return $output;
1203: }
1204:
1.1 raeburn 1205: sub print_request_status {
1.11 raeburn 1206: my ($dom) = @_;
1.14 raeburn 1207: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
1208: $env{'user.name'},'^status:'.$dom);
1209: my ($output,$formname,%queue_by_date,%typenames);
1210: if ($env{'form.crstype'} eq 'any') {
1211: %typenames = &Apache::lonlocal::texthash (
1212: official => 'Official course',
1213: unofficial => 'Unofficial course',
1214: community => 'Community',
1215: );
1216: }
1217: foreach my $key (keys(%statusinfo)) {
1218: if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) {
1219: (undef,my($cdom,$cnum)) = split(':',$key);
1220: next if ($cdom ne $dom);
1221: my $requestkey = $cdom.'_'.$cnum;
1222: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1223: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1224: $env{'user.domain'},$env{'user.name'});
1225: my $entry;
1226: my $timestamp = $history{'reqtime'};
1227: my $crstype = $history{'crstype'};
1228: my $disposition = $history{'disposition'};
1229: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1230: next unless (($env{'form.crstype'} eq 'any') ||
1231: ($env{'form.crstype'} eq $crstype));
1232: next unless (($disposition eq 'approval') ||
1233: ($disposition eq 'pending'));
1234: if (ref($history{'details'}) eq 'HASH') {
1235: $entry = $requestkey.':'.$crstype.':'.
1236: &escape($history{'details'}{'cdescr'});
1237: if ($crstype eq 'official') {
1238: $entry .= ':'.&escape($history{'details'}{'instcode'});
1239: }
1240: }
1241: if ($entry ne '') {
1242: if (exists($queue_by_date{$timestamp})) {
1243: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
1244: push(@{$queue_by_date{$timestamp}},$entry);
1245: }
1246: } else {
1247: @{$queue_by_date{$timestamp}} = ($entry);
1.10 raeburn 1248: }
1249: }
1250: }
1251: }
1252: }
1.11 raeburn 1253: $formname = 'requestcrs';
1.10 raeburn 1254: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.16 raeburn 1255: $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1256:
1.10 raeburn 1257: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1.16 raeburn 1258: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
1259: '<input type="hidden" name="showdom" value="" />'."\n".
1260: '<input type="hidden" name="cnum" value="" />'."\n";
1.10 raeburn 1261: if (@sortedtimes > 0) {
1262: $output .= &Apache::loncommon::start_data_table().
1263: &Apache::loncommon::start_data_table_header_row().
1264: '<th>'.&mt('Action').'</th>'.
1.14 raeburn 1265: '<th>'.&mt('Course Description').'</th>'.
1266: '<th>'.&mt('Domain').'</th>';
1267: if ($env{'form.crstype'} eq 'any') {
1.10 raeburn 1268: $output .= '<th>'.&mt('Type').'</th>';
1269: }
1.14 raeburn 1270: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10 raeburn 1271: $output .= '<th>'.&mt('Institutional Code').'</th>';
1272: }
1273: $output .= '<th>'.&mt('Date requested').'</th>'.
1274: &Apache::loncommon::end_data_table_header_row();
1275: my $count = 0;
1276: foreach my $item (@sortedtimes) {
1277: my $showtime = &Apache::lonlocal::locallocaltime($item);
1278: if (ref($queue_by_date{$item}) eq 'ARRAY') {
1279: foreach my $request (sort(@{$queue_by_date{$item}})) {
1280: my ($key,$type,$desc,$instcode) = split(':',$request);
1281: my ($cdom,$cnum) = split('_',$key);
1282: $output .= &Apache::loncommon::start_data_table_row().
1.16 raeburn 1283: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1.14 raeburn 1284: '<td>'.&unescape($desc).'</td>'.
1285: '<td>'.$cdom.'</td>';
1286: if ($env{'form.crstype'} eq 'any') {
1287: my $typename = $typenames{$type};
1288: if ($typename eq '') {
1289: $typename = &mt('Unknown type');
1290: }
1291: $output .= '<td>'.$typename.'</td>';
1.10 raeburn 1292: }
1.14 raeburn 1293: if (($env{'form.crstype'} eq 'any') ||
1.10 raeburn 1294: ($env{'form.crstype'} eq 'official')) {
1.14 raeburn 1295: my $showinstcode;
1296: if ($type eq 'official') {
1297: $showinstcode = &unescape($instcode);
1298: } else {
1299: $showinstcode = &mt('Not applicable');
1300: }
1301: $output .= '<td>'.$showinstcode.'</td>';
1.10 raeburn 1302: }
1303: $output .= '<td>'.$showtime.'</td>'.
1304: &Apache::loncommon::end_data_table_row();
1305: }
1306: }
1307: }
1308: $output .= &Apache::loncommon::end_data_table();
1309: } else {
1.11 raeburn 1310: $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 1311: }
1312: $output .= '
1.14 raeburn 1313: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />
1314: </form></div>';
1.10 raeburn 1315: return $output;
1.1 raeburn 1316: }
1317:
1.16 raeburn 1318: sub print_cancel_request {
1319: my ($dom,$cnum) = @_;
1320: my $requestkey = $dom.'_'.$cnum;
1321: my ($result,$output);
1322: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1323: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1324: $env{'user.domain'},$env{'user.name'});
1325: my $timestamp = $history{'reqtime'};
1326: my $crstype = $history{'crstype'};
1327: my $status = $history{'status'};
1328: if (($status eq 'cancelled') || ($status eq 'created')) {
1329: if ($status eq 'cancelled') {
1330: $output = &mt('This request has already been cancelled.');
1331: } elsif ($status eq 'created') {
1332: $output = &mt('This request has already been processed, and a course created.');
1333: }
1334: $output = &mt('No further action will be taken');
1335: } elsif (ref($history{'details'}) eq 'HASH') {
1336: my ($types,$typename) = &course_types();
1337: my $showtype = $crstype;
1338: if (defined($typename->{$crstype})) {
1339: $showtype = $typename->{$crstype};
1340: }
1341: $output = '<p>'.&Apache::loncommon::start_data_table().
1342: &Apache::loncommon::start_data_table_header_row().
1343: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
1344: '<th>'.&mt('Type').'</th>'.
1345: &Apache::loncommon::end_data_table_header_row().
1346: &Apache::loncommon::start_data_table_row().
1347: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
1348: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
1349: '<td>'.$showtype.'</td>'.
1350: &Apache::loncommon::end_data_table_row().
1351: &Apache::loncommon::end_data_table().
1352: '<br /><div class="LC_warning">'.
1353: &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
1354: $result = 'ok';
1355: } else {
1356: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
1357: }
1358: } else {
1359: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
1360: }
1361: return ($result,$output);
1362: }
1363:
1364: sub viewrequest_javascript {
1365: my ($formname,$next) = @_;
1366: return <<"ENDJS";
1367:
1368: function chooseRequest(cdom,cnum) {
1369: document.$formname.showdom.value = cdom;
1370: document.$formname.cnum.value = cnum;
1371: nextPage(document.$formname,'$next');
1372: }
1373:
1374: ENDJS
1375: }
1376:
1377: sub viewdetails_javascript {
1378: my ($formname) = @_;
1379: return << "ENDJS";
1380:
1381: function nextPage(formname,nextstate) {
1382: if (nextstate == "modify") {
1383: formname.state.value = "personnel";
1384: formname.action.value = "new";
1385: } else {
1386: formname.state.value = nextstate;
1387: }
1388: formname.submit();
1389: }
1390:
1391: function backPage(formname,prevstate) {
1392: formname.state.value = prevstate;
1393: formname.submit();
1394: }
1395:
1396: ENDJS
1397: }
1398:
1399: sub viewcancel_javascript {
1400: my $alert = &mt('Are you sure you want to cancel this request?\\n'.
1401: 'Your request will be removed.');
1402: return << "ENDJS";
1403: function nextPage(formname,nextstate) {
1404: if (confirm('$alert')) {
1405: formname.state.value = nextstate;
1406: formname.submit();
1407: }
1408: return;
1409: }
1410:
1411: ENDJS
1412: }
1413:
1.1 raeburn 1414: sub print_request_logs {
1.10 raeburn 1415: my ($jscript,$loaditems,$crumb) = @_;
1.1 raeburn 1416: return;
1417: }
1418:
1419: sub print_review {
1.26 ! raeburn 1420: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom) = @_;
1.4 raeburn 1421: my ($types,$typename) = &course_types();
1422: my ($owner,$ownername,$owneremail);
1.26 ! raeburn 1423: if ($uname eq '' || $udom eq '') {
! 1424: $uname = $env{'user.name'};
! 1425: $udom = $env{'user.domain'};
! 1426: }
! 1427: $owner = $uname.':'.$udom;
! 1428: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
! 1429: my %emails = &Apache::loncommon::getemails($uname,$udom);
1.4 raeburn 1430: foreach my $email ('permanentemail','critnotification','notification') {
1431: $owneremail = $emails{$email};
1432: last if ($owneremail ne '');
1433: }
1434: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
1435: $section_headers,$section_values,$personnel_headers,$personnel_values);
1436:
1437: $crstypename = $env{'form.crstype'};
1438: if (ref($typename) eq 'HASH') {
1439: unless ($typename->{$env{'form.crstype'}} eq '') {
1440: $crstypename = $typename->{$env{'form.crstype'}};
1441: }
1442: }
1.16 raeburn 1443: my $category = 'Course';
1444: if ($env{'form.crstype'} eq 'community') {
1445: $category = 'Community';
1446: }
1.4 raeburn 1447:
1448: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
1449: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
1450:
1.16 raeburn 1451: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
1452: '('.&Apache::lonnet::plaintext('st',$category).')';
1.4 raeburn 1453: if ($env{'form.crstype'} eq 'official') {
1454: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
1455: foreach my $title (@{$codetitles}) {
1456: if ($env{'form.instcode_'.$title} ne '') {
1457: $inst_headers .= '<th>'.$title.'</th>';
1458: my $longitem = $env{'form.instcode_'.$title};
1459: if (ref($cat_titles->{$title}) eq 'HASH') {
1460: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
1461: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
1462: }
1463: }
1464: $inst_values .= '<td>'.$longitem.'</td>';
1465: }
1466: }
1467: }
1468: if (&Apache::lonnet::auto_run('',$dom)) {
1.16 raeburn 1469: $enrollrow_title = &mt('Enrollment');
1.4 raeburn 1470: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
1471: '<th>'.&mt('Automatic Drops').'</th>'.
1472: '<th>'.&mt('Enrollment Starts').'</th>'.
1473: '<th>'.&mt('Enrollment Ends').'</th>';
1474: $section_headers = '<th>'.&mt('Sections').'</th>'.
1475: '<th>'.&mt('Crosslistings').'</th>';
1476:
1.13 raeburn 1477: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4 raeburn 1478: my @autoroster = (&mt('No'),&mt('Yes'));
1479: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
1480: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13 raeburn 1481: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
1482: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6 raeburn 1483: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
1484: &mt('Institutional section').'</th>'.
1485: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 1486: my $secinfo;
1.4 raeburn 1487: if ($env{'form.sectotal'} > 0) {
1488: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1489: if ($env{'form.sec_'.$i}) {
1.5 raeburn 1490: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4 raeburn 1491: if ($env{'form.loncapasec_'.$i} ne '') {
1.5 raeburn 1492: $secinfo .= $env{'form.loncapasec_'.$i};
1493: } else {
1494: $secinfo .= &mt('None');
1.4 raeburn 1495: }
1.5 raeburn 1496: $secinfo .= '</td></tr>';
1.4 raeburn 1497: }
1498: }
1499: }
1.6 raeburn 1500: if ($secinfo eq '') {
1501: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 1502: }
1.6 raeburn 1503: $section_values .= $secinfo.'</table></td><td>'.
1504: '<table class="LC_innerpickbox"><tr><th>'.
1505: &mt('Institutional course/section').'</th>'.
1506: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 1507: my $xlistinfo;
1.24 raeburn 1508: my $crosslisttotal = $env{'form.crosslisttotal'};
1509: if (!$crosslisttotal) {
1510: $crosslisttotal = 1;
1511: }
1512: for (my $i=0; $i<$crosslisttotal; $i++) {
1513: if ($env{'form.crosslist_'.$i}) {
1514: $xlistinfo .= '<tr><td>';
1515: if (ref($code_order) eq 'ARRAY') {
1516: if (@{$code_order} > 0) {
1517: foreach my $item (@{$code_order}) {
1518: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4 raeburn 1519: }
1520: }
1521: }
1.24 raeburn 1522: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
1523: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
1524: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
1525: } else {
1526: $xlistinfo .= &mt('None');
1527: }
1528: $xlistinfo .= '</td></tr>';
1.4 raeburn 1529: }
1530: }
1.6 raeburn 1531: if ($xlistinfo eq '') {
1532: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 1533: }
1.24 raeburn 1534: $section_values .= $xlistinfo;
1.4 raeburn 1535: }
1.24 raeburn 1536: $section_values .= '</table></td>';
1.4 raeburn 1537: }
1538:
1539: my %ctxt = &clone_text();
1540: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1.13 raeburn 1541: if (($env{'form.clonecrs'} =~ /^$match_name$/) &&
1542: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1.15 raeburn 1543: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1544: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
1545: if ($canclone) {
1546: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
1547: $env{'form.clonecrs'},('description','internal.coursecode'));
1548: if (keys(%courseenv) > 0) {
1549: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
1550: $inst_values .= '<td>'.$courseenv{'description'}.' ';
1551: my $cloneinst = $courseenv{'internal.coursecode'};
1552: if ($cloneinst ne '') {
1.18 raeburn 1553: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
1.15 raeburn 1554: } else {
1.18 raeburn 1555: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
1.15 raeburn 1556: }
1557: $inst_values .= '</td><td>';
1558: if ($env{'form.datemode'} eq 'preserve') {
1.16 raeburn 1559: $inst_values .= $ctxt{'prd'};
1.15 raeburn 1560: } elsif ($env{'form.datemode'} eq 'shift') {
1561: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
1562: } else {
1563: $inst_values .= $ctxt{'ncd'};
1564: }
1565: $inst_values .= '</td>';
1566: } else {
1567: $inst_values .= '<td>'.&mt('Unknown').'</td>';
1568: }
1569: } else {
1570: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
1571: }
1.4 raeburn 1572: } else {
1573: $inst_values .= '<td>'.&mt('None').'</td>';
1574: }
1575: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
1576: '<th>'.&mt('Access Ends').'</th>';
1.13 raeburn 1577: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1578: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
1579: if ($accessend == 0) {
1.4 raeburn 1580: $enroll_values .= '<td>'.&mt('No end date').'</td>';
1581: } else {
1.13 raeburn 1582: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4 raeburn 1583: }
1584:
1585: my $container = 'Course';
1586: if ($env{'form.crstype'} eq 'community') {
1587: $container = 'Community';
1588: }
1589:
1590: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
1591: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
1592: '</th>';
1593: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1594: '<td>'.&Apache::lonnet::plaintext('cc',$container).'</td>'.
1595: '<td>'.&mt('None').'</td></tr>';
1596: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1597: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.14 raeburn 1598: my @allsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1599: my $newsec = $env{'form.person_'.$i.'_newsec'};
1600: $newsec =~ s/^\s+//;
1601: $newsec =~s/\s+$//;
1602: my @newsecs = split(/[\s,;]+/,$newsec);
1603: foreach my $sec (@newsecs) {
1604: next if ($sec =~ /\W/);
1605: next if ($newsec eq 'none');
1606: if ($sec ne '') {
1607: unless (grep(/^\Q$sec\E$/,@allsecs)) {
1608: push(@allsecs,$sec);
1609: }
1610: }
1611: }
1.24 raeburn 1612: my $showsec;
1.14 raeburn 1613: if (@allsecs) {
1614: $showsec = join(', ',@allsecs);
1615: }
1.24 raeburn 1616: if ($showsec eq '') {
1617: $showsec = &mt('None');
1618: }
1619: if ($env{'form.person_'.$i.'_role'} eq 'cc') {
1620: $showsec = &mt('None');
1621: }
1.4 raeburn 1622: $personnel_values .=
1.13 raeburn 1623: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
1624: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 1625: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
1626: $env{'form.person_'.$i.'_dom'}.'</td>'.
1627: '<td>'.&Apache::lonnet::plaintext($env{'form.person_'.$i.'_role'},
1628: $container).'</td>'.
1.14 raeburn 1629: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 1630: }
1631: }
1.16 raeburn 1632: my $output =
1.4 raeburn 1633: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1634: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 1635: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 1636: '<th>'.&mt('Name').'</th>'.
1637: '<th>'.&mt('Username:Domain').'</th>'.
1638: '<th>'.&mt('E-mail address').'</th>'.
1639: '</tr><tr>'."\n".
1640: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
1641: '<td>'.$owneremail.'</td>'.
1642: '</tr></table>'."\n".
1643: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 1644: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 1645: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
1646: '<tr>'.$inst_values.'</tr></table>'."\n".
1647: &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 1648: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4 raeburn 1649: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
1650: '<tr>'.$enroll_values.'</tr></table>'."\n".
1651: &Apache::lonhtmlcommon::row_closure();
1652: if ($section_headers ne '') {
1653: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
1654: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
1655: '<tr>'.$section_values.'</tr></table>'."\n".
1656: &Apache::lonhtmlcommon::row_closure();
1657: }
1658: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
1659: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
1660: $personnel_values.'</table>'."\n".
1661: &Apache::lonhtmlcommon::row_closure(1).
1.26 ! raeburn 1662: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.4 raeburn 1663: return $output;
1664: }
1665:
1666: sub dates_from_form {
1667: my ($startname,$endname) = @_;
1668: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
1669: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 1670: if ($endname eq 'accessend') {
1.4 raeburn 1671: if (exists($env{'form.no_end_date'}) ) {
1672: $enddate = 0;
1673: }
1674: }
1675: return ($startdate,$enddate);
1.1 raeburn 1676: }
1677:
1678: sub courseinfo_form {
1.15 raeburn 1679: my ($dom,$formname,$crstype,$next) = @_;
1680: my $nodescr = &mt('You must provide a (brief) course description.');
1681: my $js_validate = <<"ENDJS";
1682: <script type="text/javascript">
1683: // <![CDATA['
1684:
1685: function validateForm() {
1686: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
1687: alert('$nodescr');
1688: return;
1689: }
1690: nextPage(document.$formname,'$next');
1691: }
1692: // ]]
1693: </script>
1694:
1695: ENDJS
1696:
1697: my $output .= $js_validate."\n".'<div>'.&Apache::lonhtmlcommon::start_pick_box().
1698: &Apache::lonhtmlcommon::row_title('Course Description').
1.13 raeburn 1699: '<input type="text" size="40" name="cdescr" />';
1700: my ($home_server_pick,$numlib) =
1701: &Apache::loncommon::home_server_form_item($dom,'chome',
1702: 'default','hide');
1703: if ($numlib > 1) {
1704: $output .= &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 1705: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13 raeburn 1706: }
1707: $output .= $home_server_pick.
1708: &Apache::lonhtmlcommon::row_closure(1).
1709: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
1710: '<div>'.&clone_form($dom,$formname,$crstype).'</div>'."\n";
1.1 raeburn 1711: return $output;
1712: }
1713:
1714: sub clone_form {
1715: my ($dom,$formname,$crstype) = @_;
1716: my $type = 'Course';
1717: if ($crstype eq 'community') {
1718: $type = 'Community';
1719: }
1.13 raeburn 1720: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').
1721: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1.4 raeburn 1722: my %lt = &clone_text();
1.2 raeburn 1723: my $output .=
1724: &Apache::lonhtmlcommon::start_pick_box().
1725: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.13 raeburn 1726: '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();'.
1727: 'opencrsbrowser('."'$formname','clonecrs','clonedom','','','','$type'".');" />'.
1.2 raeburn 1728: '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
1729: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
1730: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure().
1731: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
1732: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
1733: '</label><br /><label>'.
1734: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
1735: '</label><br /><label>'.
1736: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
1737: $lt{'shd'}.'</label>'.
1738: '<input type="text" size="5" name="dateshift" value="365" />'.
1739: &Apache::lonhtmlcommon::row_closure(1).
1740: &Apache::lonhtmlcommon::end_pick_box();
1.1 raeburn 1741: return $output;
1742: }
1743:
1.16 raeburn 1744: sub clone_text {
1.4 raeburn 1745: return &Apache::lonlocal::texthash(
1746: 'cid' => 'Course ID',
1747: 'dmn' => 'Domain',
1748: 'dsh' => 'Date Shift',
1749: 'ncd' => 'Do not clone date parameters',
1750: 'prd' => 'Clone date parameters as-is',
1751: 'shd' => 'Shift date parameters by number of days',
1752: );
1753: }
1754:
1.1 raeburn 1755: sub coursecode_form {
1.2 raeburn 1756: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 1757: my $output;
1.2 raeburn 1758: my %rowtitle = (
1759: instcode => 'Course Category',
1760: crosslist => 'Cross Listed Course',
1761: );
1.1 raeburn 1762: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
1763: (ref($cat_order))) {
1.2 raeburn 1764: my ($sel,$instsec,$lcsec);
1765: $sel = $context;
1766: if ($context eq 'crosslist') {
1767: $sel .= '_'.$num;
1768: $instsec = &mt('Institutional section').'<br />'.
1769: '<input type="text" size="10" name="'.$sel.'_instsec" />';
1770: $lcsec = &mt('LON-CAPA section').'<br />'.
1771: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
1772: }
1.1 raeburn 1773: if (@{$codetitles} > 0) {
1774: my $lastitem = pop(@{$codetitles});
1.2 raeburn 1775: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 1776: if (@{$codetitles} > 0) {
1.2 raeburn 1777: $output = &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1778: '<table><tr>';
1.1 raeburn 1779: if ($context eq 'crosslist') {
1.2 raeburn 1780: $output .= '<td>'.&mt('Include?').'<br />'.
1781: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 1782: }
1783: foreach my $title (@{$codetitles}) {
1784: if (ref($cat_order->{$title}) eq 'ARRAY') {
1785: if (@{$cat_order->{$title}} > 0) {
1786: $output .= '<td align="center">'.$title.'<br />'."\n".
1787: '<select name="'.$sel.'_'.$title.'">'."\n".
1788: ' <option value="" selected="selected">'.
1789: &mt('Select').'</option>'."\n";
1790: foreach my $item (@{$cat_order->{$title}}) {
1791: my $longitem = $item;
1792: if (ref($cat_titles->{$title}) eq 'HASH') {
1793: if ($cat_titles->{$title}{$item} ne '') {
1794: $longitem = $cat_titles->{$title}{$item};
1795: }
1796: }
1797: $output .= '<option value="'.$item.'">'.$longitem.
1798: '</option>'."\n";
1799: }
1800: }
1801: $output .= '</select></td>'."\n";
1802: }
1803: }
1804: if ($context eq 'crosslist') {
1805: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 1806: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
1807: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 1808: } else {
1809: $output .= '</tr></table>'.
1810: &Apache::lonhtmlcommon::row_closure().
1811: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1812: $lastinput;
1813: }
1814: } else {
1815: if ($context eq 'crosslist') {
1816: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 1817: '<table><tr>'.
1818: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
1819: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
1820: '</tr></table>';
1.1 raeburn 1821: } else {
1822: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
1823: $lastinput;
1824: }
1825: }
1.2 raeburn 1826: $output .= &Apache::lonhtmlcommon::row_closure(1);
1827: push(@$codetitles,$lastitem);
1828: } elsif ($context eq 'crosslist') {
1829: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1830: '<table><tr><td align="center">'.
1831: '<span class="LC_nobreak">'.&mt('Include?').
1832: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
1833: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
1834: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
1835: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
1836: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 1837: }
1838: }
1839: return $output;
1840: }
1841:
1842: sub get_course_dom {
1843: my $codedom = &Apache::lonnet::default_login_domain();
1.19 raeburn 1844: if ($env{'form.showdom'} ne '') {
1845: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
1846: return $env{'form.showdom'};
1847: }
1848: }
1.1 raeburn 1849: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.19 raeburn 1850: my ($types,$typename) = &course_types();
1851: if (ref($types) eq 'ARRAY') {
1852: foreach my $type (@{$types}) {
1853: if (&Apache::lonnet::usertools_access($env{'user.name'},
1854: $env{'user.domain'},$type,
1855: undef,'requestcourses')) {
1856: return $env{'user.domain'};
1857: }
1858: }
1859: my @possible_doms;
1860: foreach my $type (@{$types}) {
1861: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
1862: if ($dom_str ne '') {
1863: my @domains = split(',',$dom_str);
1864: foreach my $entry (@domains) {
1865: my ($extdom,$extopt) = split(':',$entry);
1866: if ($extdom eq $env{'request.role.domain'}) {
1867: return $extdom;
1868: }
1869: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
1870: push(@possible_doms,$extdom);
1871: }
1872: }
1873: }
1874: }
1875: if (@possible_doms) {
1876: @possible_doms = sort(@possible_doms);
1877: return $possible_doms[0];
1878: }
1879: }
1.1 raeburn 1880: $codedom = $env{'user.domain'};
1881: if ($env{'request.role.domain'} ne '') {
1882: $codedom = $env{'request.role.domain'};
1883: }
1884: }
1885: return $codedom;
1886: }
1887:
1888: sub display_navbuttons {
1.16 raeburn 1889: my ($r,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1 raeburn 1890: $r->print('<div class="LC_navbuttons">');
1891: if ($prev) {
1.16 raeburn 1892: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1893: 'onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>'.
1894: (' 'x3));
1.1 raeburn 1895: } elsif ($prevtext) {
1.16 raeburn 1896: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1897: 'onclick="javascript:history.back()"/>'.(' 'x3));
1898: }
1899: if ($state eq 'details') {
1900: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1901: 'onclick="javascript:nextPage(document.'.$formname.','."'".$other."'".
1902: ')" />');
1.1 raeburn 1903: }
1.15 raeburn 1904: if ($state eq 'courseinfo') {
1.16 raeburn 1905: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
1906: 'onclick="javascript:validateForm();" />');
1.15 raeburn 1907: } elsif ($next) {
1.1 raeburn 1908: $r->print('
1.16 raeburn 1909: <input type="button" name="next" value="'.$nexttext.'" '.
1910: 'onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1.1 raeburn 1911: }
1912: $r->print('</div>');
1913: }
1914:
1915: sub print_request_outcome {
1.10 raeburn 1916: my ($dom,$codetitles,$code_order) = @_;
1.13 raeburn 1917: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.10 raeburn 1918: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1.24 raeburn 1919: my $sectotal = $env{'form.sectotal'};
1920: my $crosslisttotal = 0;
1.10 raeburn 1921: $cnum = $env{'form.cnum'};
1.8 raeburn 1922: unless ($cnum =~ /^$match_courseid$/) {
1923: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
1924: return $output;
1925: }
1.11 raeburn 1926:
1.10 raeburn 1927: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 1928: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
1929: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
1930: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
1931: }
1932: }
1.10 raeburn 1933: $now = time;
1934: $crstype = $env{'form.crstype'};
1.17 raeburn 1935: my @instsections;
1.8 raeburn 1936: if ($crstype eq 'official') {
1937: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 1938: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 1939: }
1.10 raeburn 1940: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1941: if ($env{'form.sec_'.$i}) {
1942: if ($env{'form.secnum_'.$i} ne '') {
1.17 raeburn 1943: my $sec = $env{'form.secnum_'.$i};
1944: $sections{$i}{'inst'} = $sec;
1945: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
1946: push(@instsections,$sec);
1947: }
1.13 raeburn 1948: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.10 raeburn 1949: }
1950: }
1951: }
1952: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1953: if ($env{'form.crosslist_'.$i}) {
1954: my $xlistinfo = '';
1955: if (ref($code_order) eq 'ARRAY') {
1956: if (@{$code_order} > 0) {
1957: foreach my $item (@{$code_order}) {
1958: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1959: }
1960: }
1961: }
1.22 raeburn 1962: $crosslistings{$i}{'instcode'} = $xlistinfo;
1.24 raeburn 1963: if ($xlistinfo ne '') {
1964: $crosslisttotal ++;
1965: }
1.22 raeburn 1966: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 1967: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 1968: }
1969: }
1.14 raeburn 1970: } else {
1971: $enrollstart = '';
1972: $enrollend = '';
1.10 raeburn 1973: }
1974: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1975: my $uname = $env{'form.person_'.$i.'_uname'};
1.16 raeburn 1976: my $udom = $env{'form.person_'.$i.'_dom'};
1.10 raeburn 1977: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
1978: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 1979: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
1980: $personnel{$uname.':'.$udom} = {
1981: firstname => $env{'form.person_'.$i.'_firstname'},
1982: lastname => $env{'form.person_'.$i.'_lastname'},
1983: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
1984: };
1985: }
1986: my $role = $env{'form.person_'.$i.'_role'};
1987: unless ($role eq '') {
1.16 raeburn 1988: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13 raeburn 1989: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
1990: unless (grep(/^\Q$role\E$/,@curr_roles)) {
1991: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
1992: }
1993: } else {
1994: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
1995: }
1996: if ($role eq 'cc') {
1997: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
1998: } else {
1.14 raeburn 1999: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2000: my $newsec = $env{'form.person_'.$i.'_newsec'};
2001: $newsec =~ s/^\s+//;
2002: $newsec =~s/\s+$//;
2003: my @newsecs = split(/[\s,;]+/,$newsec);
2004: foreach my $sec (@newsecs) {
2005: next if ($sec =~ /\W/);
2006: next if ($newsec eq 'none');
2007: if ($sec ne '') {
2008: unless (grep(/^\Q$sec\E$/,@currsec)) {
2009: push(@currsec,$sec);
1.13 raeburn 2010: }
2011: }
2012: }
2013: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @currsec;
2014: }
2015: }
1.10 raeburn 2016: } else {
2017: push(@missingdom,$uname.':'.$udom);
2018: }
2019: } else {
2020: push(@baduname,$uname.':'.$udom);
2021: }
1.8 raeburn 2022: }
1.13 raeburn 2023: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 raeburn 2024: my $autodrops = 0;
2025: if ($env{'form.autodrops'}) {
2026: $autodrops = $env{'form.autodrops'};
2027: }
2028: my $autoadds = 0;
2029: if ($env{'form.autoadds'}) {
2030: $autodrops = $env{'form.autoadds'};
2031: }
2032: if ($env{'form.autoadds'}) {
2033: $autodrops = $env{'form.autoadds'};
2034: }
2035: my $instcode = '';
2036: if (exists($env{'form.instcode'})) {
2037: $instcode = $env{'form.instcode'};
2038: }
1.15 raeburn 2039: my $clonecrs = '';
2040: my $clonedom = '';
2041: if (($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
2042: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.16 raeburn 2043: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
2044: $env{'form.clonedom'});
1.15 raeburn 2045: if ($clonehome ne 'no_host') {
1.16 raeburn 2046: my $canclone =
2047: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
2048: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
1.15 raeburn 2049: if ($canclone) {
2050: $clonecrs = $env{'form.clonecrs'};
2051: $clonedom = $env{'form.clonedom'};
2052: }
2053: }
2054: }
1.8 raeburn 2055: my $details = {
1.10 raeburn 2056: owner => $env{'user.name'},
2057: domain => $env{'user.domain'},
2058: cdom => $dom,
1.11 raeburn 2059: cnum => $cnum,
1.13 raeburn 2060: coursehome => $env{'form.chome'},
2061: cdescr => $env{'form.cdescr'},
1.10 raeburn 2062: crstype => $env{'form.crstype'},
1.14 raeburn 2063: instcode => $instcode,
1.15 raeburn 2064: clonedom => $clonedom,
2065: clonecrs => $clonecrs,
1.10 raeburn 2066: datemode => $env{'form.datemode'},
1.14 raeburn 2067: dateshift => $env{'form.dateshift'},
2068: sectotal => $sectotal,
1.10 raeburn 2069: sections => \%sections,
1.14 raeburn 2070: crosslisttotal => $crosslisttotal,
1.13 raeburn 2071: crosslists => \%crosslistings,
1.14 raeburn 2072: autoadds => $autoadds,
2073: autodrops => $autodrops,
1.13 raeburn 2074: enrollstart => $enrollstart,
2075: enrollend => $enrollend,
2076: accessstart => $accessstart,
2077: accessend => $accessend,
1.10 raeburn 2078: personnel => \%personnel,
1.8 raeburn 2079: };
2080: my @inststatuses;
1.9 raeburn 2081: my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
1.8 raeburn 2082: if ($val eq '') {
2083: if ($crstype eq 'official') {
1.19 raeburn 2084: $output = &mt('You are not permitted to request creation of official courses.');
1.8 raeburn 2085: } elsif ($crstype eq 'unofficial') {
1.19 raeburn 2086: $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8 raeburn 2087: } elsif ($crstype eq 'community') {
2088: $output = &mt('You are not permitted to request creation of communities');
2089: } else {
2090: $output = &mt('Unrecognized course type: [_1]',$crstype);
2091: }
2092: } else {
1.14 raeburn 2093: my ($disposition,$message,$reqstatus);
1.8 raeburn 2094: my %reqhash = (
1.14 raeburn 2095: reqtime => $now,
1.10 raeburn 2096: crstype => $crstype,
2097: details => $details,
1.8 raeburn 2098: );
2099: my $requestkey = $dom.'_'.$cnum;
1.17 raeburn 2100: my $validationerror;
1.10 raeburn 2101: if ($val eq 'autolimit=') {
2102: $disposition = 'process';
2103: } elsif ($val =~ /^autolimit=(\d+)$/) {
2104: my $limit = $1;
1.8 raeburn 2105: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 2106: $dom,$crstype,$limit,\$message);
1.8 raeburn 2107: } elsif ($val eq 'validate') {
1.21 raeburn 2108: my ($inststatuslist,$validationchk,$validation);
1.17 raeburn 2109: if (@inststatuses > 0) {
2110: $inststatuslist = join(',',@inststatuses);
2111: }
2112: my $instseclist;
2113: if (@instsections > 0) {
2114: $instseclist = join(',',@instsections);
2115: }
1.21 raeburn 2116: $validationchk =
2117: &Apache::lonnet::auto_courserequest_validation($dom,
2118: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
2119: $inststatuslist,$instcode,$instseclist);
2120: if ($validationchk =~ /:/) {
2121: ($validation,$message) = split(':',$validationchk);
2122: } else {
2123: $validation = $validationchk;
2124: }
2125: if ($validation =~ /^error(.*)$/) {
1.17 raeburn 2126: $disposition = 'approval';
2127: $validationerror = $1;
1.23 raeburn 2128: } else {
2129: $disposition = $validation;
1.17 raeburn 2130: }
1.8 raeburn 2131: } else {
2132: $disposition = 'approval';
2133: }
1.14 raeburn 2134: $reqhash{'disposition'} = $disposition;
2135: $reqstatus = $disposition;
1.16 raeburn 2136: my ($modified,$queued);
1.8 raeburn 2137: if ($disposition eq 'rejected') {
2138: $output = &mt('Your course request was rejected.');
2139: if ($message) {
2140: $output .= '<div class="LC_warning">'.$message.'</div>';
2141: }
2142: } elsif ($disposition eq 'process') {
1.14 raeburn 2143: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
2144: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
2145: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 2146: my $type = 'Course';
2147: if ($crstype eq 'community') {
2148: $type = 'Community';
2149: }
2150: foreach my $role (@roles) {
2151: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
2152: }
1.14 raeburn 2153: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
2154: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
2155: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
2156: if ($result eq 'created') {
1.8 raeburn 2157: $disposition = 'created';
1.14 raeburn 2158: $reqstatus = 'created';
2159: $output = &mt('Your course request has been processed and the course has been created.').
2160: '<br />'.
2161: &mt('You will need to logout and log-in again to be able to select a role in the course.');
1.8 raeburn 2162: } else {
1.14 raeburn 2163: $output = '<span class="LC_error">'.
2164: &mt('An error occurred when processing your course request.').
2165: '<br />'.
2166: &mt('You may want to review the request details and submit the request again.').
2167: '</span>';
1.8 raeburn 2168: }
2169: } else {
2170: my $requestid = $cnum.'_'.$disposition;
2171: my $request = {
2172: $requestid => {
2173: timestamp => $now,
2174: crstype => $crstype,
2175: ownername => $env{'user.name'},
2176: ownerdom => $env{'user.domain'},
1.13 raeburn 2177: description => $env{'form.cdescr'},
1.8 raeburn 2178: },
2179: };
1.16 raeburn 2180: my $statuskey = 'status:'.$dom.':'.$cnum;
2181: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
2182: $env{'user.domain'},$env{'user.name'});
1.17 raeburn 2183: if ($userreqhash{$statuskey} ne '') {
1.16 raeburn 2184: $modified = 1;
1.25 raeburn 2185: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
2186: my %queuehash = &Apache::lonnet::get('courserequestqueue',
2187: [$cnum.'_approval',
2188: $cnum.'_pending'],$dom,$uname);
1.17 raeburn 2189: if (($queuehash{$cnum.'_approval'} ne '') ||
2190: ($queuehash{$cnum.'_pending'} ne '')) {
1.16 raeburn 2191: $queued = 1;
2192: }
2193: }
2194: unless ($queued) {
2195: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
2196: $dom);
2197: if ($putresult eq 'ok') {
2198: $output = &mt('Your course request has been recorded.').'<br />'.
2199: ¬ification_information($disposition,$req_notifylist,
2200: $cnum,$now);
1.8 raeburn 2201: } else {
1.16 raeburn 2202: $reqstatus = 'domainerror';
2203: $reqhash{'disposition'} = $disposition;
2204: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
2205: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8 raeburn 2206: }
2207: }
2208: }
1.14 raeburn 2209: my ($storeresult,$statusresult);
1.10 raeburn 2210: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2211: $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
2212: 'courserequests');
1.14 raeburn 2213: if ($storeresult eq 'ok') {
2214: my %status = (
2215: 'status:'.$dom.':'.$cnum => $reqstatus,
2216: );
2217: $statusresult = &Apache::lonnet::put('courserequests',\%status);
2218: }
1.10 raeburn 2219: } else {
2220: $storeresult = 'error: invalid requestkey format';
2221: }
1.8 raeburn 2222: if ($storeresult ne 'ok') {
1.13 raeburn 2223: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
2224: &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1.14 raeburn 2225: } elsif ($statusresult ne 'ok') {
2226: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'</span><br />';
2227: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
1.8 raeburn 2228: }
1.16 raeburn 2229: if ($modified && $queued && $storeresult eq 'ok') {
2230: $output .= '<p>'.&mt('Your course request has been updated').'</p>'.
2231: ¬ification_information($disposition,$req_notifylist,$cnum,$now);
2232: }
1.17 raeburn 2233: if ($validationerror ne '') {
1.19 raeburn 2234: $output .= '<span class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
1.17 raeburn 2235: }
1.16 raeburn 2236: }
2237: return $output;
2238: }
2239:
2240: sub notification_information {
2241: my ($disposition,$req_notifylist,$cnum,$now) = @_;
2242: my %emails = &Apache::loncommon::getemails();
2243: my $address;
2244: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
2245: $address = $emails{'permanentemail'};
2246: if ($address eq '') {
2247: $address = $emails{'notification'};
2248: }
2249: }
2250: my $output;
2251: if ($disposition eq 'approval') {
2252: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
2253: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
2254: if ($address ne '') {
2255: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
2256: }
2257: if ($req_notifylist) {
2258: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
2259: $env{'user.domain'});
2260: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
2261: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
2262: }
1.17 raeburn 2263: } elsif ($disposition eq 'pending') {
1.16 raeburn 2264: $output .= '<div class="LC_info">'.
2265: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
2266: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
2267: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
2268: '</div>';
1.17 raeburn 2269: } else {
2270: $output .= '<div class="LC_warning">'.
2271: &mt('Your request status is: [_1].',$disposition).
2272: '</div>'
1.8 raeburn 2273: }
2274: return $output;
2275: }
2276:
2277: sub get_processtype {
1.9 raeburn 2278: my ($dom,$crstype,$inststatuses,$domconfig) = @_;
2279: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1.8 raeburn 2280: my (%userenv,%settings,$val);
1.19 raeburn 2281: my @options = ('autolimit','validate','approval');
1.8 raeburn 2282: if ($dom eq $env{'user.domain'}) {
2283: %userenv =
2284: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
2285: 'requestcourses.'.$crstype,'inststatus');
2286: if ($userenv{'requestcourses.'.$crstype}) {
2287: $val = $userenv{'requestcourses.'.$crstype};
2288: @{$inststatuses} = ('_custom_');
2289: } else {
2290: my ($task,%alltasks);
1.9 raeburn 2291: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
2292: %settings = %{$domconfig->{'requestcourses'}};
1.8 raeburn 2293: if (ref($settings{$crstype}) eq 'HASH') {
1.23 raeburn 2294: if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
1.8 raeburn 2295: $val = $settings{$crstype}{'_LC_adv'};
2296: @{$inststatuses} = ('_LC_adv_');
2297: } else {
2298: if ($userenv{'inststatus'} ne '') {
2299: @{$inststatuses} = split(',',$userenv{'inststatus'});
2300: } else {
1.13 raeburn 2301: @{$inststatuses} = ('default');
1.8 raeburn 2302: }
2303: foreach my $status (@{$inststatuses}) {
2304: if (exists($settings{$crstype}{$status})) {
2305: my $value = $settings{$crstype}{$status};
2306: next unless ($value);
2307: unless (exists($alltasks{$value})) {
2308: if (ref($alltasks{$value}) eq 'ARRAY') {
2309: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
2310: push(@{$alltasks{$value}},$status);
2311: }
2312: } else {
2313: @{$alltasks{$value}} = ($status);
2314: }
2315: }
2316: }
2317: }
2318: my $maxlimit = 0;
1.13 raeburn 2319:
1.8 raeburn 2320: foreach my $key (sort(keys(%alltasks))) {
2321: if ($key =~ /^autolimit=(\d*)$/) {
2322: if ($1 eq '') {
2323: $val ='autolimit=';
2324: last;
2325: } elsif ($1 > $maxlimit) {
2326: $maxlimit = $1;
2327: }
2328: }
2329: }
2330: if ($maxlimit) {
2331: $val = 'autolimit='.$maxlimit;
2332: } else {
2333: foreach my $option (@options) {
2334: if ($alltasks{$option}) {
2335: $val = $option;
2336: last;
2337: }
2338: }
2339: }
2340: }
2341: }
2342: }
2343: }
2344: } else {
2345: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
2346: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
1.19 raeburn 2347: if ($userenv{'reqcrsotherdom.'.$crstype}) {
2348: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
2349: my $optregex = join('|',@options);
2350: foreach my $item (@doms) {
2351: my ($extdom,$extopt) = split(':',$item);
2352: if ($extdom eq $dom) {
2353: if ($extopt =~ /^($optregex)(=?\d*)$/) {
2354: $val = $1.$2;
2355: }
2356: last;
2357: }
1.8 raeburn 2358: }
2359: @{$inststatuses} = ('_external_');
2360: }
2361: }
2362: return $val;
2363: }
2364:
2365: sub check_autolimit {
1.10 raeburn 2366: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
2367: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
2368: 'userroles',['active','future'],['cc'],[$dom]);
2369: my ($types,$typename) = &course_types();
2370: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
2371: my %count;
2372: if (ref($types) eq 'ARRAY') {
2373: foreach my $type (@{$types}) {
2374: $count{$type} = 0;
2375: }
2376: }
2377: foreach my $key (keys(%requests)) {
2378: my ($cdom,$cnum) = split('_',$key);
2379: if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
2380: if (ref($requests{$key}) eq 'HASH') {
2381: my $type = $requests{$key}{'crstype'};
2382: if ($type =~ /^official|unofficial|community$/) {
2383: $count{$type} ++;
2384: }
2385: }
2386: }
2387: }
2388: if ($count{$crstype} < $limit) {
2389: return 'process';
2390: } else {
2391: if (ref($typename) eq 'HASH') {
2392: $$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);
2393: }
2394: return 'rejected';
2395: }
1.1 raeburn 2396: return;
2397: }
2398:
1.2 raeburn 2399: sub retrieve_settings {
1.26 ! raeburn 2400: my ($dom,$cnum,$udom,$uname) = @_;
! 2401: if ($udom eq '' || $uname eq '') {
! 2402: $udom = $env{'user.domain'};
! 2403: $uname = $env{'user.name'};
! 2404: }
! 2405: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
1.16 raeburn 2406: if ($result eq 'ok') {
1.26 ! raeburn 2407: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
1.16 raeburn 2408: $env{'form.chome'} = $reqinfo{'coursehome'};
2409: $env{'form.cdescr'} = $reqinfo{'cdescr'};
2410: $env{'form.crstype'} = $reqinfo{'crstype'};
2411: &generate_date_items($reqinfo{'accessstart'},'accessstart');
2412: &generate_date_items($reqinfo{'accessend'},'accessend');
2413: if ($reqinfo{'accessend'} == 0) {
2414: $env{'form.no_end_date'} = 1;
2415: }
2416: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
2417: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
2418: &generate_date_items($reqinfo{'enrollend'},'enrollend');
2419: }
2420: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
2421: $env{'form.clonedom'} = $reqinfo{'clonedom'};
2422: $env{'form.datemode'} = $reqinfo{'datemode'};
2423: $env{'form.dateshift'} = $reqinfo{'dateshift'};
2424: if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) {
2425: $env{'form.sectotal'} = $reqinfo{'sectotal'};
2426: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
2427: $env{'form.autoadds'} = $reqinfo{'autoadds'};
2428: $env{'form.autdrops'} = $reqinfo{'autodrops'};
2429: $env{'form.instcode'} = $reqinfo{'instcode'};
1.24 raeburn 2430: my $crscode = {
2431: $cnum => $reqinfo{'instcode'},
2432: };
2433: &extract_instcode($dom,'instcode',$crscode,$cnum);
1.16 raeburn 2434: }
2435: my @currsec;
2436: if (ref($reqinfo{'sections'}) eq 'HASH') {
2437: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
2438: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
1.24 raeburn 2439: my $sec = $reqinfo{'sections'}{$i}{'inst'};
1.16 raeburn 2440: $env{'form.secnum_'.$i} = $sec;
1.24 raeburn 2441: $env{'form.sec_'.$i} = '1';
1.16 raeburn 2442: if (!grep(/^\Q$sec\E$/,@currsec)) {
2443: push(@currsec,$sec);
2444: }
2445: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
2446: }
2447: }
2448: }
1.24 raeburn 2449: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
2450: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
2451: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
2452: $env{'form.crosslist_'.$i} = '1';
2453: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
2454: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
2455: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
2456: my $key = $cnum.$i;
2457: my $crscode = {
2458: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
2459: };
2460: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
2461: }
1.16 raeburn 2462: }
2463: }
2464: }
2465: if (ref($reqinfo{'personnel'}) eq 'HASH') {
2466: my $i = 0;
2467: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
2468: my ($uname,$udom) = split(':',$user);
2469: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
2470: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
2471: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
2472: $env{'form.person_'.$i.'_role'} = $role;
2473: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
2474: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
2475: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
2476: $env{'form.person_'.$i.'_uname'} = $uname;
2477: $env{'form.person_'.$i.'_dom'} = $udom;
2478: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
2479: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
2480: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
2481: my @newsecs;
2482: if (@usecs > 0) {
2483: foreach my $sec (@usecs) {
2484: if (grep(/^\Q$sec\E/,@currsec)) {
2485: $env{'form.person_'.$i.'_sec'} = $sec;
2486: } else {
1.20 raeburn 2487: push(@newsecs,$sec);
1.16 raeburn 2488: }
2489: }
2490: }
2491: if (@newsecs > 0) {
2492: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
2493: }
2494: }
2495: }
2496: $i ++;
2497: }
2498: }
2499: }
2500: }
2501: $env{'form.persontotal'} = $i;
2502: }
2503: }
2504: }
2505: return $result;
2506: }
2507:
2508: sub get_request_settings {
1.26 ! raeburn 2509: my ($dom,$cnum,$udom,$uname) = @_;
1.16 raeburn 2510: my $requestkey = $dom.'_'.$cnum;
2511: my ($result,%reqinfo);
2512: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1.26 ! raeburn 2513: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
1.16 raeburn 2514: my $disposition = $history{'disposition'};
2515: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
2516: if (ref($history{'details'}) eq 'HASH') {
2517: %reqinfo = %{$history{'details'}};
2518: $result = 'ok';
2519: } else {
2520: $result = 'nothash';
2521: }
2522: } else {
2523: $result = 'notqueued';
2524: }
2525: } else {
2526: $result = 'invalid';
2527: }
2528: return ($result,%reqinfo);
2529: }
1.2 raeburn 2530:
1.16 raeburn 2531: sub extract_instcode {
1.24 raeburn 2532: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
1.16 raeburn 2533: my (%codes,@codetitles,%cat_titles,%cat_order);
1.24 raeburn 2534: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
2535: \@codetitles,\%cat_titles,
2536: \%cat_order) eq 'ok') {
2537: if (ref($codes{$crskey}) eq 'HASH') {
1.16 raeburn 2538: if (@codetitles > 0) {
2539: my $sel = $element;
2540: if ($element eq 'crosslist') {
2541: $sel .= '_'.$counter;
2542: }
2543: foreach my $title (@codetitles) {
1.24 raeburn 2544: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
1.16 raeburn 2545: }
2546: }
2547: }
2548: }
2549: return;
1.2 raeburn 2550: }
2551:
1.16 raeburn 2552: sub generate_date_items {
2553: my ($currentval,$item) = @_;
2554: if ($currentval =~ /\d+/) {
2555: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
2556: &Apache::lonhtmlcommon::get_timedates($currentval);
2557: $env{'form.'.$item.'_day'} = $mday;
2558: $env{'form.'.$item.'_month'} = $month+1;
2559: $env{'form.'.$item.'_year'} = $year;
2560: }
2561: return;
1.2 raeburn 2562: }
2563:
1.1 raeburn 2564: 1;
2565:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>