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