Annotation of loncom/interface/lonsupportreq.pm, revision 1.20
1.1 raeburn 1: package Apache::lonsupportreq;
2:
3: use strict;
4: use lib qw(/home/httpd/lib/perl);
1.5 raeburn 5: use MIME::Types;
6: use MIME::Lite;
1.1 raeburn 7: use Apache::Constants qw(:common);
1.2 albertel 8: use Apache::loncommon();
9: use Apache::lonnet();
1.1 raeburn 10: use Apache::lonlocal;
11:
12: sub handler {
1.2 albertel 13: my ($r) = @_;
14: &Apache::loncommon::content_type($r,'text/html');
1.1 raeburn 15: $r->send_http_header;
16:
17: if ($r->header_only) {
18: return OK;
19: }
1.12 raeburn 20: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']);
21: if ($r->uri eq '/adm/helpdesk') {
22: &Apache::loncommon::get_posted_cgi($r);
23: }
1.1 raeburn 24: my $function = $ENV{'form.function'};
25: my $origurl = &Apache::lonnet::unescape($ENV{'form.origurl'});
1.12 raeburn 26: my $action = $ENV{'form.action'};
27:
1.1 raeburn 28: if ($action eq 'process') {
29: &print_request_receipt($r,$origurl,$function);
30: } else {
31: &print_request_form($r,$origurl,$function);
32: }
33: return OK;
34: }
35:
36: sub print_request_form {
37: my ($r,$origurl,$function) = @_;
38: my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,$cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server);
39: my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0",marginheight="0"',1);
40: my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
1.5 raeburn 41: if (($tablecolor eq '') || ($tablecolor eq '#FFFFFF')) {
1.14 raeburn 42: $tablecolor = '#EEEE99';
1.5 raeburn 43: }
1.10 raeburn 44: $ccode = '';
1.1 raeburn 45: $os = $ENV{'browser.os'};
46: $browser = $ENV{'browser.type'};
47: $bversion = $ENV{'browser.version'};
48: $uhost = $ENV{'request.host'};
49: $uname = $ENV{'user.name'};
50: $udom = $ENV{'user.domain'};
51: $uhome = $ENV{'user.home'};
52: $urole = $ENV{'request.role'};
53: $usec = $ENV{'request.course.sec'};
54: $cid = $ENV{'request.course.id'};
55: $server = $ENV{'SERVER_NAME'};
1.13 raeburn 56: my $scripttag = (<<'END');
1.5 raeburn 57: function validate() {
1.13 raeburn 58: if (validmail(document.logproblem.email) == false) {
59: alert("The e-mail address you entered: "+document.logproblem.email.value+" is not a valid e-mail address.");
60: return;
1.5 raeburn 61: }
62: document.logproblem.submit();
63: }
1.13 raeburn 64:
65: function validmail(field) {
66: var str = field.value;
67: if (window.RegExp) {
68: var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
69: var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
70: var reg1 = new RegExp(reg1str);
71: var reg2 = new RegExp(reg2str);
72: if (!reg1.test(str) && reg2.test(str)) {
73: return true;
74: }
75: return false;
76: }
77: else
78: {
79: if(str.indexOf("@") >= 0) {
80: return true;
81: }
82: return false;
83: }
84: }
1.5 raeburn 85: END
1.1 raeburn 86: if ($cid =~ m/_/) {
87: ($cdom,$cnum) = split/_/,$cid;
88: }
89: if ($cdom && $cnum) {
90: my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
91: $ctitle = $csettings{'description'};
92: $ccode = $csettings{'internal.coursecode'};
93: $sectionlist = $csettings{'internal.sectionnums'};
94: }
95: if ($ENV{'environment.critnotification'}) {
96: $email = $ENV{'environment.critnotification'};
97: }
98: if (!$email && $ENV{'environment.notification'}) {
99: $email = $ENV{'environment.notification'};
100: }
101: if ($ENV{'environment.lastname'}) {
102: $lastname = $ENV{'environment.lastname'};
103: }
104: if ($ENV{'environment.firstname'}) {
105: $firstname = $ENV{'environment.firstname'};
106: }
107: my @sections = split/,/,$sectionlist;
108: my %groupid = ();
109: foreach (@sections) {
110: my ($sec,$grp) = split/:/,$_;
111: $groupid{$sec} = $grp;
112: }
1.19 raeburn 113: my $codedom = $Apache::lonnet::perlvar{'lonDefDomain'};
114: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom']);
115: if (exists($ENV{'form.codedom'})) {
116: $codedom = $ENV{'form.codedom'};
117: }
1.1 raeburn 118: my %coursecodes = ();
119: my %codes = ();
120: my @codetitles = ();
121: my %cat_titles = ();
122: my %cat_order = ();
1.6 raeburn 123: my %idlist = ();
124: my %idnums = ();
125: my %idlist_titles = ();
1.1 raeburn 126: my $caller = 'global';
127: my $totcodes = 0;
128: my $format_reply;
1.6 raeburn 129: my $jscript = '';
1.20 ! raeburn 130:
1.1 raeburn 131: if ($cdom) {
132: $codedom = $cdom;
133: }
134: if ($cnum) {
135: $coursecodes{$cnum} = $ccode;
136: if ($ccode eq '') {
137: $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
138: } else {
139: $coursecodes{$cnum} = $ccode;
140: $caller = $cnum;
141: $totcodes ++;
142: }
143: } else {
144: $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
145: }
146: if ($totcodes > 0) {
147: $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
1.6 raeburn 148: if ($ccode eq '') {
149: my $numtypes = @codetitles;
150: &build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
1.20 ! raeburn 151: &javascript_code_selections($numtypes,\%cat_titles,\$jscript,\%idlist,\%idnums,\%idlist_titles,\@codetitles);
1.6 raeburn 152: }
1.1 raeburn 153: }
1.14 raeburn 154: $r->print(<<ENDHEAD);
1.1 raeburn 155: <html>
156: <head>
157: <title>LON-CAPA support request</title>
1.18 raeburn 158: <script type"text/javascript">
1.1 raeburn 159: $scripttag
1.6 raeburn 160: $jscript
161: </script>
1.1 raeburn 162: </head>
163: $bodytag
1.14 raeburn 164: ENDHEAD
1.15 raeburn 165: if ($r->uri eq '/adm/helpdesk') {
1.14 raeburn 166: &print_header($r,$origurl);
167: }
168: $r->print(<<"END");
1.15 raeburn 169: <form method="post" name="logproblem" enctype="multipart/form-data">
1.1 raeburn 170: <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
171: <tr>
172: <td>
173: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
174: <tr>
175: <td>
176: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
177: <tr>
178: <td>
179: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
180: <tr>
181: <td width="140" bgcolor="$tablecolor">
182: <table width="140" border="0" cellpadding="8" cellspacing="0">
183: <tr>
184: <td align="right"><b>Name:</b>
185: </td>
186: </tr>
187: </table>
188: </td>
189: <td width="100%" valign="top">
190: <table width="100%" border="0" cellpadding="8" cellspacing="0">
191: <tr>
192: <td>
193: END
194: my $fullname = '';
195: if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
196: $fullname = "$firstname $lastname";
197: $r->print("$fullname<input type=\"hidden\" name=\"username\" value=\"$fullname\" />");
198: } else {
199: if (defined($firstname) && $firstname ne '') {
200: $fullname = $firstname;
201: } elsif (defined($lastname) && $lastname ne '') {
202: $fullname= " $lastname";
203: }
1.17 raeburn 204: $r->print('<input type="text" size="20" name="username" value="'.$fullname.'" />');
1.1 raeburn 205: }
206: $r->print(<<END);
1.18 raeburn 207: <input type="button" value="Submit Request" onClick="validate()" />
1.1 raeburn 208: </td>
209: </tr>
210: </table>
211: </td>
212: </tr>
213: <tr>
214: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 215: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 216: </td>
217: </tr>
218: <tr>
219: <td width="140" bgcolor="$tablecolor">
220: <table width="140" border="0" cellpadding="8" cellspacing="0">
221: <tr>
222: <td align="right"><b>E-mail address:</b>
223: </td>
224: </tr>
225: </table>
226: </td>
227: <td width="100%" valign="top">
228: <table width="100%" border="0" cellpadding="8" cellspacing="0">
229: <tr>
230: <td>
231: <input type="text" size="20" name="email" value="$email" /><br />
232: </td>
233: </tr>
234: </table>
235: </td>
236: </tr>
237: <tr>
238: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 239: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 240: </td>
241: </tr>
242: <tr>
243: <td width="140" bgcolor="$tablecolor">
244: <table width="140" border="0" cellpadding="8" cellspacing="0">
245: <tr>
246: <td align="right"><b>username/domain:</b>
247: </td>
248: </tr>
249: </table>
250: </td>
251: <td width="100%" valign="top">
252: <table width="100%" border="0" cellpadding="8" cellspacing="0">
253: <tr>
254: <td>
255: END
256: my $udom_input = '<input type="hidden" name="udom" value="'.$udom.'" />';
257: my $uname_input = '<input type="hidden" name="uname" value="'.$uname.'" />';
258: if (defined($uname) && defined($udom)) {
259: $r->print('<i>username</i>: '.$uname.' <i>domain</i>: '.$udom.$udom_input.$uname_input);
260: } else {
261: my $udomform = '';
262: my $unameform = '';
263: if (defined($udom)) {
264: $udomform = '<i>domain</i>: '.$udom.$udom_input;
265: } elsif (defined($uname)) {
266: $unameform = '<i>username</i>: '.$uname.' '.$uname_input;
267: }
268: if ($udomform eq '') {
269: $udomform = '<i>domain</i>: ';
1.19 raeburn 270: $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom');
1.1 raeburn 271: }
272: if ($unameform eq '') {
1.19 raeburn 273: $unameform= '<i>username</i>: <input type="text" size="12" name="uname" value="'.$uname.'" /> ';
1.1 raeburn 274: }
275: $r->print($unameform.$udomform.'<br />Enter the username you use to log-in to your LON-CAPA system, and choose your domain.');
276: }
277: $r->print(<<END);
278: </td>
279: </tr>
280: </table>
281: </td>
282: </tr>
283: <tr>
284: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 285: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 286: </td>
287: </tr>
288: <tr>
289: <td width="140" bgcolor="$tablecolor">
290: <table width="140" border="0" cellpadding="8" cellspacing="0">
291: <tr>
292: <td align="right"><b>URL of page:</b>
293: </td>
294: </tr>
295: </table>
296: </td>
297: <td width="100%" valign="top">
298: <table width="100%" border="0" cellpadding="8" cellspacing="0">
299: <tr>
300: <td>
1.14 raeburn 301: http://$server$origurl<input type="hidden" name="sourceurl" value="http://$server$origurl" />
1.1 raeburn 302: </td>
303: </tr>
304: </table>
305: </td>
306: </tr>
307: <tr>
308: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 309: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 310: </td>
311: </tr>
312: <tr>
313: <td width="140" bgcolor="$tablecolor">
314: <table width="140" border="0" cellpadding="8" cellspacing="0">
315: <tr>
316: <td align="right"><b>Phone #:</b>
317: </td>
318: </tr>
319: </table>
320: </td>
321: <td width="100%" valign="top">
322: <table width="100%" border="0" cellpadding="8" cellspacing="0">
323: <tr>
324: <td>
325: <input type="text" size="15" name="phone"><br>
326: </td>
327: </tr>
328: </table>
329: </td>
330: </tr>
331: <tr>
332: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 333: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 334: </td>
335: </tr>
336: <tr>
337: <td width="140" bgcolor="$tablecolor">
338: <table width="140" border="0" cellpadding="8" cellspacing="0">
339: <tr>
340: <td align="right"><b>Course Details:</b>
341: </td>
342: </tr>
343: </table>
344: </td>
345: <td width="100%" valign="top">
346: <table border="0" cellpadding="3" cellspacing="3">
347: <tr>
348: <td>
349: END
1.10 raeburn 350: if ($cnum) {
351: if ($coursecodes{$cnum}) {
352: foreach (@codetitles) {
353: $r->print('<i>'.$_.'</i>: '.$codes{$cnum}{$_}.'; ');
354: }
355: $r->print(' <input type="hidden" name="coursecode" value="'.$coursecodes{$cnum}.'" />');
356: } else {
357: $r->print('Enter institutional course code:
358: <input type="text" name="coursecode" size="15" value="" />');
1.1 raeburn 359: }
360: } else {
1.10 raeburn 361: if ($totcodes > 0) {
362: my $numtitles = @codetitles;
363: if ($numtitles == 0) {
364: $r->print('Enter institutional course code:
1.1 raeburn 365: <input type="text" name="coursecode" size="15" value="" />');
1.10 raeburn 366: } else {
367: my $lasttitle = $numtitles;
368: if ($numtitles > 4) {
369: $lasttitle = 4;
370: }
371: $r->print('<table><tr><td>'.$codetitles[0].'<br />'."\n".
372: '<select name="'.$codetitles[0].'" onChange="courseSet('."'$codetitles[0]'".')">'."\n".
373: ' <option value="-1" />Select'."\n");
374: my @items = ();
1.20 ! raeburn 375: my @longitems = ();
1.10 raeburn 376: if ($idlist{$codetitles[0]} =~ /","/) {
377: @items = split/","/,$idlist{$codetitles[0]};
378: } else {
379: $items[0] = $idlist{$codetitles[0]};
380: }
1.20 ! raeburn 381: if (defined($idlist_titles{$codetitles[0]})) {
! 382: if ($idlist_titles{$codetitles[0]} =~ /","/) {
! 383: @longitems = split/","/,$idlist_titles{$codetitles[0]};
! 384: } else {
! 385: $longitems[0] = $idlist_titles{$codetitles[0]};
! 386: }
! 387: } else {
! 388: @longitems = @items;
! 389: }
! 390: for (my $i=0; $i<@items; $i++) {
! 391: $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
1.10 raeburn 392: }
393: $r->print('</select></td>');
394: for (my $i=1; $i<$numtitles; $i++) {
395: $r->print('<td>'.$codetitles[$i].'<br />'."\n".
396: '<select name="'.$codetitles[$i].'" onChange="courseSet('."'$codetitles[$i]'".')">'."\n".
397: '<option value="-1"><-Pick '.$codetitles[$i-1].'</option>'."\n".
398: '</select>'."\n".
399: '</td>'
400: );
401: }
402: $r->print('</tr></table>');
403: if ($numtitles > 4) {
404: $r->print('<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
405: '<select name="'.$codetitles[$numtitles].'" onChange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
406: '<option value="-1"><-Pick '.$codetitles[$numtitles-1].'</option>'."\n".
407: '</select>'."\n");
408: }
409: }
410: } else {
411: $r->print('Enter institutional course code:
412: <input type="text" name="coursecode" size="15" value="" />');
413: }
1.1 raeburn 414: }
415: if ($ctitle) {
416: $r->print('<br /><i>Title</i>: '.$ctitle.'<input type="hidden" name="title" value="'.$ctitle.'" />');
417: } else {
418: $r->print('<br />Enter course title:
1.10 raeburn 419: <input type="text" name="title" size="25" value="" />');
1.1 raeburn 420: }
421: $r->print(<<END);
422: </td>
423: </tr>
424: </table>
425: </td>
426: </tr>
427: <tr>
428: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 429: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 430: </td>
431: </tr>
432: <tr>
433: <td width="140" bgcolor="$tablecolor">
434: <table width="140" border="0" cellpadding="8" cellspacing="0">
435: <tr>
436: <td align="right"><b>Section Number: </b>
437: </td>
438: </tr>
439: </table>
440: </td>
441: <td width="100%" valign="top">
442: <table width="100%" border="0" cellpadding="8" cellspacing="0">
443: <tr>
444: <td>
445: END
446: if ($sectionlist) {
447: $r->print("<select name=\"section\">");
448: foreach (sort keys %groupid) {
449: if ($_ eq $groupid{$_} || $groupid{$_} eq '') {
450: $r->print("<option value=\"$_\" />$_");
451: } else {
1.5 raeburn 452: $r->print("<option value=\"$_\" />$_ - (LON-CAPA sec: $groupid{$_})");
1.1 raeburn 453: }
454: }
455: $r->print("</select>");
456: } else {
457: $r->print("<input type=\"text\" name=\"section\" size=\"10\"/>");
458: }
459: $r->print(<<END);
460: </td>
461: </tr>
462: </table>
463: </td>
464: </tr>
465: <tr>
466: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 467: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 468: </td>
469: </tr>
470: <tr>
471: <td width="140" bgcolor="$tablecolor">
472: <table width="140" border="0" cellpadding="8" cellspacing="0">
473: <tr>
474: <td align="right"><b>Subject</b>
475: </td>
476: </tr>
477: </table>
478: </td>
479: <td width="100%" valign="top">
480: <table width="100%" border="0" cellpadding="8" cellspacing="0">
481: <tr>
482: <td>
483: <input type="text" size="40" name="subject">
484: </td>
485: </tr>
486: </table>
487: </td>
488: </tr>
489: <tr>
490: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 491: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 492: </td>
493: </tr>
494: <tr>
495: <td width="140" bgcolor="$tablecolor">
496: <table width="140" border="0" cellpadding="8" cellspacing="0">
497: <tr>
498: <td align="right"><b>Detailed description:</b>
499: </td>
500: </tr>
501: </table>
502: </td>
503: <td width="100%" valign="top">
504: <table width="100%" border="0" cellpadding="8" cellspacing="0">
505: <tr>
506: <td>
507: <textarea rows="10" cols="45" name="description" wrap="virtual"></textarea>
508: </td>
509: </tr>
510: </table>
511: </td>
512: </tr>
513: <tr>
514: <td width="100%" colspan="2" bgcolor="#000000">
1.3 albertel 515: <img src="/adm/lonMisc/blackdot.gif" /><br />
1.1 raeburn 516: </td>
517: </tr>
1.5 raeburn 518: END
519: if (defined($ENV{'user.name'})) {
520: $r->print(<<END);
521: <tr>
522: <td width="140" bgcolor="$tablecolor">
523: <table width="140" border="0" cellpadding="8" cellspacing="0">
524: <tr>
525: <td align="right"><b>Optional file upload:</b>
526: </td>
527: </tr>
528: </table>
529: </td>
530: <td width="100%" valign="top">
531: <table width="100%" border="0" cellpadding="8" cellspacing="0">
532: <tr>
533: <td>
534: <input type="file" name="screenshot" size="20" /><br />Upload a file (e.g., a screenshot) relevant to your support request (128 KB max. size).
535: </td>
536: </tr>
537: </table>
538: </td>
539: </tr>
540: <tr>
541: <td width="100%" colspan="2" bgcolor="#000000">
542: <img src="/adm/lonMisc/blackdot.gif" /><br />
543: </td>
544: </tr>
545: END
546: }
547: $r->print(<<END);
1.1 raeburn 548: <tr>
549: <td width="140" bgcolor="$tablecolor">
550: <table width="140" border="0" cellpadding="8" cellspacing="0">
551: <tr>
552: <td align="right"><b>Finish:</b>
553: </td>
554: </tr>
555: </table>
556: </td>
557: <td width="100%" valign="top">
558: <table border="0" cellpadding="8" cellspacing="0">
559: <tr>
560: <td>
561: <input type="hidden" name="action" value="process" />
1.15 raeburn 562: <input type="button" value="Submit Request" onClick="validate()"/>
1.1 raeburn 563: </td>
564: <td> </td>
565: <td>
566: <input type="reset" value="Clear Form">
567: </td>
568: </tr>
569: </table>
570: </td>
571: </tr>
572: </table>
573: </td>
574: </tr>
575: </table>
576: </td>
577: </tr>
578: </table>
579: </td>
580: </tr>
581: </table>
1.14 raeburn 582: </form>
583: </body>
584: </html>
1.1 raeburn 585: END
1.5 raeburn 586: return;
1.1 raeburn 587: }
588:
589: sub print_request_receipt {
590: my ($r,$url,$function) = @_;
591: my @envvars = ('lonID','HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME','browser.os','browser.type','browser.version','user.home','request.role');
1.5 raeburn 592: my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
593:
1.1 raeburn 594: my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);
1.5 raeburn 595: my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
1.1 raeburn 596: my $to = $Apache::lonnet::perlvar{'lonSupportEMail'};
1.5 raeburn 597: my $from = $admin;
1.1 raeburn 598: my $reporttime = &Apache::lonlocal::locallocaltime(time);
599: my $fontcolor = &Apache::loncommon::designparm($function.'.font');
600: my $vlinkcolor = &Apache::loncommon::designparm($function.'.vlink');
601: my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
1.14 raeburn 602: my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot');
1.20 ! raeburn 603:
1.1 raeburn 604: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
1.19 raeburn 605: my $coursecode = $ENV{'form.coursecode'};
606: if ($coursecode eq '') {
607: if (defined($ENV{'form.Year'})) {
608: $coursecode .= $ENV{'form.Year'};
609: }
610: if (defined($ENV{'form.Semester'})) {
611: $coursecode .= $ENV{'form.Semester'};
612: }
613: if (defined($ENV{'form.Department'})) {
614: $coursecode .= $ENV{'form.Department'};
615: }
616: if (defined($ENV{'form.Number'})) {
617: $coursecode .= $ENV{'form.Number'};
618: }
619: }
1.1 raeburn 620: my $supportmsg = qq|
621: Name: $ENV{'form.username'}
622: Email: $ENV{'form.email'}
623: Username/domain: $ENV{'form.uname'} - $ENV{'form.udom'}
624: Tel: $ENV{'form.phone'}
1.19 raeburn 625: Course Information: $ENV{'form.title'} - $coursecode - section: $ENV{'form.section'}
1.1 raeburn 626: Subject: $ENV{'form.subject'}
627: Description: $ENV{'form.description'}
1.14 raeburn 628: URL: $ENV{'form.sourceurl'}
1.1 raeburn 629: Date/Time: $reporttime
630:
631: |;
1.5 raeburn 632: my $descrip = $ENV{'form.description'};
633: $descrip =~ s#\n#<br />#g;
634: my $displaymsg = qq|
635: <font color="$fontcolor">Name:</font><font color="$vlinkcolor"> $ENV{'form.username'}</font><br />
636: <font color="$fontcolor">Email: </font><font color="$vlinkcolor">$ENV{'form.email'}</font><br />
637: <font color="$fontcolor">Username/domain: </font><font color="$vlinkcolor">$ENV{'form.uname'} - $ENV{'form.udom'}</font><br />
638: <font color="$fontcolor">Tel: </font><font color="$vlinkcolor">$ENV{'form.phone'}</font><br />
1.19 raeburn 639: <font color="$fontcolor">Course Information: </font><font color="$vlinkcolor">$ENV{'form.title'} - $coursecode - section: $ENV{'form.section'}</font><br />
1.5 raeburn 640: <font color="$fontcolor">Subject: </font><font color="$vlinkcolor">$ENV{'form.subject'}</font><br />
641: <font color="$fontcolor">Description: </font><font color="$vlinkcolor">$descrip</font><br />
1.14 raeburn 642: <font color="$fontcolor">URL: </font><font color="$vlinkcolor">$ENV{'form.sourceurl'}</font><br />
1.5 raeburn 643: <font color="$fontcolor">Date/Time: </font><font color="$vlinkcolor">$reporttime</font><br />
644: |;
1.14 raeburn 645: $r->print(<<"END");
1.1 raeburn 646: <html>
647: <head>
648: <title>LON-CAPA support request recorded</title>
649: </head>
650: $bodytag
1.16 raeburn 651: <form name="logproblem">
1.18 raeburn 652: <input type="hidden" name="action" value="result" />
1.16 raeburn 653: </form>
1.1 raeburn 654: END
1.14 raeburn 655: if ($r->uri eq '/adm/helpdesk') {
656: &print_header($r,$url,'process');
657: }
658: if ($to =~ m/^[^\@]+\@[^\@]+$/) {
659: $r->print("<h3>A support request has been sent to $to</h3>");
1.9 raeburn 660: } else {
661: $to = $admin;
662: if ($to =~ m/^[^\@]+\@[^\@]+$/) {
1.14 raeburn 663: $r->print("<h3>A support request has been sent to $to</h3>");
1.9 raeburn 664: END
665: } else {
666: $r->print(<<END);
1.1 raeburn 667: <h3>Warning: Problem with support e-mail address</h3>
1.9 raeburn 668: As the e-mail address provided for this LON-CAPA server ($to) does not appear to be a valid e-mail address, your support request has <b>not</b> been sent to the LON-CAPA support staff or administrator at your institution. Instead a copy has been sent to the LON-CAPA support team at Michigan State University.
1.1 raeburn 669: END
1.9 raeburn 670: $to = 'helpdesk@lon-capa.org';
671: }
1.1 raeburn 672: }
1.5 raeburn 673: if (defined($ENV{'form.email'})) {
674: if ($ENV{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
675: $from = $ENV{'form.email'};
676: }
677: }
678:
679: my $subject = $ENV{'form.subject'};
680: $subject =~ s#(`)#'#g;
681: $subject =~ s#\$#\(\$\)#g;
682: $supportmsg =~ s#(`)#'#g;
683: $supportmsg =~ s#\$#\(\$\)#g;
684: $displaymsg =~ s#(`)#'#g;
685: $displaymsg =~ s#\$#\(\$\)#g;
686: my $fname;
687:
688: my $attachmentpath = '';
689: my $attachmentsize = '';
690: if (defined($ENV{'user.name'})) {
691: if ($ENV{'form.screenshot.filename'}) {
692: $attachmentsize = length($ENV{'form.screenshot'});
693: if ($attachmentsize > 131072) {
694: $displaymsg .= "<br />The uploaded screenshot file ($attachmentsize bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.";
695: } else {
696: $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
697: }
698: }
699: }
700:
701: if ($attachmentpath =~ m-/([^/]+)$-) {
702: $fname = $1;
703: $displaymsg .= "<br />An uploaded screenshot file - $fname ($attachmentsize bytes) was included in the request sent by $ENV{'user.name'} from LON-CAPA domain: $ENV{'user.domain'}";
704: $supportmsg .= "\n";
705: foreach (@envvars) {
706: $supportmsg .= "$_: $ENV{$_}\n";
707: }
708: }
709:
710: my $msg = MIME::Lite->new(
711: From => $from,
712: To => $to,
713: Subject => $subject,
714: Type =>'TEXT',
715: Data => $supportmsg,
716: );
717:
718: if ($attachmentpath) {
719: my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
720: $msg->attach(Type => $type,
721: Path => $attachmentpath,
722: Filename => $fname
723: );
724:
725: } else {
726: my $envdata = '';
727: foreach (@envvars) {
728: $envdata .= "$_: $ENV{$_}\n";
729: }
730: foreach (@loncvars) {
731: $envdata .= "$_: $ENV{$_}\n";
732: }
733: $msg->attach(Type => 'TEXT',
734: Data => $envdata);
735: }
736:
737: ### Send it:
738: # ->send can cause an sh launch which can pass all of %ENV along
1.4 albertel 739: # which can be to large for /bin/sh's little mind
740: my %oldENV=%ENV;
741: undef(%ENV);
1.5 raeburn 742: $msg->send('sendmail');
1.4 albertel 743: %ENV=%oldENV;
744: undef(%oldENV);
1.5 raeburn 745:
746: if ($attachmentpath =~ m#$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+#) {
747: unlink($attachmentpath);
748: }
749: $r->print(qq|
1.1 raeburn 750: <b>Your support request contained the following information</b>:<br /><br />
751: <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
752: <tr>
753: <td>
754: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
755: <tr>
756: <td>
757: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
758: <tr>
759: <td>
760: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
761: <tr>
762: <td width="140" bgcolor="$tablecolor">
763: <table width="140" border="0" cellpadding="8" cellspacing="0">
764: <tr>
765: <td align="right"><b>Information supplied</b>
766: </td>
767: </tr>
768: </table>
769: </td>
770: <td width="100%" valign="top">
771: <table width="100%" border="0" cellpadding="8" cellspacing="0">
772: <tr>
1.5 raeburn 773: <td>$displaymsg</td>
1.1 raeburn 774: </tr>
775: </table>
776: </td>
777: </tr>
778: <tr>
1.5 raeburn 779: <td width="100%" colspan="2" bgcolor="#000000">
780: <img src="/adm/lonMisc/blackdot.gif" /><br />
781: </td>
782: </tr>
783: <tr>
784: <td width="140" bgcolor="$tablecolor">
785: <table width="140" border="0" cellpadding="8" cellspacing="0">
1.1 raeburn 786: <tr>
787: <td align="right"><b>Additional information recorded</b>
788: </td>
789: </tr>
790: </table>
791: </td>
792: <td width="100%" valign="top">
793: <table width="100%" border="0" cellpadding="8" cellspacing="0">
794: <tr>
795: <td>
1.5 raeburn 796: |);
1.1 raeburn 797: foreach (@envvars) {
1.5 raeburn 798: unless($ENV{$_} eq '') {
799: $r->print("$_: <font color='$vlinkcolor'>$ENV{$_}</font>, ");
800: }
1.1 raeburn 801: }
802: $r->print("
803: </td>
804: </tr>
805: </table>
806: </td>
807: </tr>
808: </table>
809: </td>
810: </tr>
811: </table>
812: </td>
813: </tr>
814: </table>
815: </td>
816: </tr>
817: </table>
1.14 raeburn 818: </body>
819: </html>
1.1 raeburn 820: ");
821: }
822:
1.14 raeburn 823: sub print_header {
824: my ($r,$origurl,$action) = @_;
825: my $location=&Apache::loncommon::lonhttpdurl("/adm");
826: my $tablecolor = '#EEEE99';
827: my ($component_url);
828: my $helpdesk_link = '<a href="javascript:validate()">';
829: if ($action eq 'process') {
830: $helpdesk_link = '<a href="/adm/helpdesk">';
831: }
832: my %lt = &Apache::lonlocal::texthash (
833: login => 'Log-in help',
834: ask => 'Ask helpdesk',
835: getst => 'Getting started guide',
836: back => 'Back to last location'
837: );
838: $r->print(<<END);
839: <table width="620" border="0" cellspacing="0" cellpadding="0" height="55"> <tr height="50"> <td width='5'> </td>
840: <td>
841: <fieldset><legend><img src="$location/lonIcons/minilogo.gif" height='20' width='29' valign='bottom' /> <b><font size="+1">LON-CAPA help/support</font></b></legend>
842: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
843: <tr>
844: <td>
845: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
846: <tr>
847: <td>
848: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
849: <tr>
850: <td>
851: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
852: <tr bgcolor="$tablecolor">
853: <td align="center"><img src="$location/help/gif/smallHelp.gif" border="0" alt="(Login help)" valign="middle" /> <b><a href="/adm/loginproblems.html">$lt{'login'}</a></td>
854: <td align="center"> <b>$helpdesk_link<img src="$location/lonIcons/helpdesk.gif" border="0" alt="(Ask helpdesk)" valign="middle" /> $lt{'ask'}</a></b> </td>
855: <td align="center"> <b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>
856: <td align="center"> <b><a href="$origurl" target="_top"><img src="$location/lonIcons/move_up.gif" border="0" alt="(Back to last location)" valign="middle" /> $lt{'back'}</a></b> </td>
857: </tr>
858: </table>
859: </td>
860: </tr>
861: </table>
862: </td>
863: </tr>
864: </table>
865: </td>
866: </tr>
867: </table>
868: </fieldset>
869: </td>
870: <td width='5'> </td>
871: </tr>
872: <tr height='5'>
873: <td colspan='3' height='5'> </td>
874: </tr>
875: END
876: unless ($action eq 'process') {
877: $r->print('
878: <tr>
879: <td colspan="3">'.&mt('
880: Please read the "Log-in help" and "Getting started guide" if you can not log-in').'. '.&mt('If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk').'.<br /><font size="-1"><b>'.&mt('Note').':</b> '.&mt('Student questions about course content should be directed to the course instructor').'.</font><br /><br />
881: </td>
882: </tr>');
883: }
884: $r->print('
885: </table>');
886: return;
887: }
888:
1.1 raeburn 889: sub retrieve_instcodes {
890: my ($coursecodes,$codedom,$totcodes) = @_;
1.11 raeburn 891: my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.');
1.1 raeburn 892: foreach my $course (keys %courses) {
1.11 raeburn 893: if ($courses{$course} =~ m/^[^:]*:([^:]+)/) {
1.1 raeburn 894: $$coursecodes{$course} = &Apache::lonnet::unescape($1);
895: $totcodes ++;
896: }
897: }
898: return $totcodes;
899: }
900:
1.6 raeburn 901: sub build_code_selections {
902: my ($codes,$codetitles,$cat_titles,$cat_order,$idlist,$idnums,$idlist_titles) = @_;
903: my %idarrays = ();
904: for (my $i=1; $i<@{$codetitles}; $i++) {
905: %{$idarrays{$$codetitles[$i]}} = ();
906: }
907: foreach my $cid (sort keys %{$codes}) {
908: &recurse_list($cid,$codetitles,$codes,0,\%idarrays);
909: }
910: for (my $num=0; $num<@{$codetitles}; $num++) {
911: if ($num == 0) {
912: my @contents = ();
913: my @contents_titles = ();
914: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[0]}},\@contents);
915: if (defined($$cat_titles{$$codetitles[0]})) {
916: foreach (@contents) {
917: push @contents_titles, $$cat_titles{$$codetitles[0]}{$_};
918: }
919: }
920: $$idlist{$$codetitles[0]} = join('","',@contents);
921: $$idnums{$$codetitles[0]} = scalar(@contents);
922: if (defined($$cat_titles{$$codetitles[0]})) {
923: $$idlist_titles{$$codetitles[0]} = join('","',@contents_titles);
924: }
925: } elsif ($num == 1) {
926: %{$$idlist{$$codetitles[1]}} = ();
927: %{$$idlist_titles{$$codetitles[1]}} = ();
928: foreach my $key_a (keys %{$idarrays{$$codetitles[1]}}) {
929: my @sorted_a = ();
930: my @sorted_a_titles = ();
931: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[1]}{$key_a}},\@sorted_a);
932: if (defined($$cat_titles{$$codetitles[1]})) {
933: foreach (@sorted_a) {
934: push @sorted_a_titles, $$cat_titles{$$codetitles[1]}{$_};
935: }
936: }
937: $$idlist{$$codetitles[1]}{$key_a} = join('","',@sorted_a);
938: $$idnums{$$codetitles[1]}{$key_a} = scalar(@sorted_a);
939: if (defined($$cat_titles{$$codetitles[1]})) {
940: $$idlist_titles{$$codetitles[1]}{$key_a} = join('","',@sorted_a_titles);
941: }
942: }
943: } elsif ($num == 2) {
944: %{$$idlist{$$codetitles[2]}} = ();
945: %{$$idlist_titles{$$codetitles[2]}} = ();
946: foreach my $key_a (keys %{$idarrays{$$codetitles[2]}}) {
947: %{$$idlist{$$codetitles[2]}{$key_a}} = ();
948: %{$$idlist_titles{$$codetitles[2]}{$key_a}} = ();
949: foreach my $key_b (keys %{$idarrays{$$codetitles[2]}{$key_a}}) {
950: my @sorted_b = ();
951: my @sorted_b_titles = ();
952: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[2]}{$key_a}{$key_b}},\@sorted_b);
1.19 raeburn 953: if (defined($$cat_titles{$$codetitles[2]})) {
1.6 raeburn 954: foreach (@sorted_b) {
1.19 raeburn 955: push @sorted_b_titles, $$cat_titles{$$codetitles[2]}{$_};
1.6 raeburn 956: }
957: }
958: $$idlist{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b);
959: $$idnums{$$codetitles[2]}{$key_a}{$key_b} = scalar(@sorted_b);
960: if (defined($$cat_titles{$$codetitles[2]})) {
961: $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b_titles);
962: }
963: }
964: }
965: } elsif ($num == 3) {
966: %{$$idlist{$$codetitles[3]}} = ();
967: foreach my $key_a (keys %{$idarrays{$$codetitles[3]}}) {
968: %{$$idlist{$$codetitles[3]}{$key_a}} = ();
969: foreach my $key_b (keys %{$idarrays{$$codetitles[3]}{$key_a}}) {
970: %{$$idlist{$$codetitles[3]}{$key_a}{$key_b}} = ();
971: foreach my $key_c (keys %{$idarrays{$$codetitles[3]}{$key_a}{$key_b}}) {
972: my @sorted_c = ();
1.20 ! raeburn 973: my @sorted_c_titles = ();
1.6 raeburn 974: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[3]}{$key_a}{$key_b}{$key_c}},\@sorted_c);
1.20 ! raeburn 975: if (defined($$cat_titles{$$codetitles[3]})) {
! 976: foreach (@sorted_c) {
! 977: push @sorted_c_titles, $$cat_titles{$$codetitles[3]}{$_};
! 978: }
! 979: }
1.6 raeburn 980: $$idlist{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c);
981: $$idnums{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = scalar(@sorted_c);
1.20 ! raeburn 982: if (defined($$cat_titles{$$codetitles[3]})) {
! 983: $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_c_titles);
! 984: }
1.6 raeburn 985: }
986: }
987: }
988: } elsif ($num == 4) {
989: %{$$idlist{$$codetitles[4]}} = ();
990: foreach my $key_a (keys %{$idarrays{$$codetitles[4]}}) {
991: %{$$idlist{$$codetitles[4]}{$key_a}} = ();
992: foreach my $key_b (keys %{$idarrays{$$codetitles[4]}{$key_a}}) {
993: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}} = ();
994: foreach my $key_c (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}}) {
995: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}} = ();
996: foreach my $key_d (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}}) {
997: my @sorted_d = ();
1.20 ! raeburn 998: my @sorted_d_titles = ();
1.6 raeburn 999: &sort_cats($num,$cat_order,$codetitles,$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d},\@sorted_d);
1.20 ! raeburn 1000: if (defined($$cat_titles{$$codetitles[4]})) {
! 1001: foreach (@sorted_d) {
! 1002: push @sorted_d_titles, $$cat_titles{$$codetitles[4]}{$_};
! 1003: }
! 1004: }
1.6 raeburn 1005: $$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d);
1006: $$idnums{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = scalar(@sorted_d);
1007: }
1008: }
1009: }
1010: }
1011: }
1012: }
1013: }
1014:
1015: sub sort_cats {
1016: my ($num,$cat_order,$codetitles,$idsarrayref,$sorted) = @_;
1017: my @unsorted = @{$idsarrayref};
1018: if (defined($$cat_order{$$codetitles[$num]})) {
1019: foreach (@{$$cat_order{$$codetitles[$num]}}) {
1020: if (grep/^$_$/,@unsorted) {
1021: push @{$sorted}, $_;
1022: }
1023: }
1024: } else {
1025: @{$sorted} = sort (@unsorted);
1026: }
1027: }
1028:
1029:
1030: sub recurse_list {
1031: my ($cid,$codetitles,$codes,$num,$idarrays) = @_;
1032: if ($num == 0) {
1033: if (!grep/^$$codes{$cid}{$$codetitles[0]}$/,@{$$idarrays{$$codetitles[0]}}) {
1034: push @{$$idarrays{$$codetitles[0]}}, $$codes{$cid}{$$codetitles[0]};
1035: }
1036: } elsif ($num == 1) {
1037: if (defined($$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}})) {
1038: if (!grep/^$$codes{$cid}{$$codetitles[1]}$/,@{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}) {
1039: push @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}, $$codes{$cid}{$$codetitles[1]};
1040: }
1041: } else {
1042: @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}} = ("$$codes{$cid}{$$codetitles[1]}");
1043: }
1044: } elsif ($num == 2) {
1045: if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}})) {
1046: if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
1047: if (!grep/^$$codes{$cid}{$$codetitles[2]}$/,@{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}) {
1048: push @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}, $$codes{$cid}{$$codetitles[2]};
1049: }
1050: } else {
1051: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
1052: }
1053: } else {
1054: %{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}} = ();
1055: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
1056: }
1057: } elsif ($num == 3) {
1058: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}})) {
1059: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
1060: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
1061: if (!grep/^$$codes{$cid}{$$codetitles[3]}$/,@{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}) {
1062: push @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}, $$codes{$cid}{$$codetitles[3]};
1063: }
1064: } else {
1065: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1066: }
1067: } else {
1068: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1069: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1070: }
1071: } else {
1072: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}} = ();
1073: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1074: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1075: }
1076: } elsif ($num == 4) {
1077: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}})) {
1078: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
1079: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
1080: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}})) {
1081: if (!grep/^$$codes{$cid}{$$codetitles[4]}$/,@{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}}) {
1082: push @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}}, $$codes{$cid}{$$codetitles[4]};
1083: }
1084: } else {
1085: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1086: }
1087: } else {
1088: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
1089: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1090: }
1091: } else {
1092: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1093: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
1094: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1095: }
1096: } else {
1097: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}} = ();
1098: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1099: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
1100: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1101: }
1102: }
1103: $num ++;
1104: if ($num <@{$codetitles}) {
1105: &recurse_list($cid,$codetitles,$codes,$num,$idarrays);
1106: }
1107: }
1108:
1109: sub javascript_code_selections {
1.20 ! raeburn 1110: my ($numcats,$cat_titles,$script_tag,$idlist,$idnums,$idlist_titles,$codetitles) = @_;
1.10 raeburn 1111: my $numtitles = @{$codetitles};
1.20 ! raeburn 1112: my @seltitles = ();
1.10 raeburn 1113: for (my $j=0; $j<$numtitles; $j++) {
1114: $seltitles[$j] = 'id'.$$codetitles[$j];
1115: }
1116: my $seltitle_str = join('","',@seltitles);
1.20 ! raeburn 1117: my @longtitles = ();
! 1118: for (my $i=0; $i<$numtitles; $i++) {
! 1119: if (defined($$cat_titles{$$codetitles[$i]})) {
! 1120: $longtitles[$i] = 1;
! 1121: } else {
! 1122: $longtitles[$i] = 0;
! 1123: }
! 1124: }
! 1125: my $longtitles_str = join('","',@longtitles);
1.6 raeburn 1126: $$script_tag .= <<END;
1127: function courseSet(caller) {
1.10 raeburn 1128: var ids = new Array ("$seltitle_str");
1129: var formitems = new Array ($numtitles);
1.20 ! raeburn 1130: var longtitles = new Array ("$longtitles_str");
1.15 raeburn 1131: var idyr = document.logproblem.Year.selectedIndex
1132: var idsem = document.logproblem.Semester.selectedIndex
1133: var iddept = document.logproblem.Department.selectedIndex
1134: var idclass = document.logproblem.Number.selectedIndex
1.6 raeburn 1135: var idyears = new Array("$$idlist{$$codetitles[0]}");
1136: END
1.20 ! raeburn 1137: if ($longtitles[0]) {
! 1138: $$script_tag .=
! 1139: qq| var idyearslongs = new Array("$$idlist_titles{$$codetitles[0]}")\n|;
! 1140: }
! 1141: $$script_tag .=
! 1142: " var idsems = new Array ($$idnums{$$codetitles[0]})\n";
! 1143: if ($longtitles[1]) {
! 1144: $$script_tag .=
! 1145: " var idsemslongs = new Array ($$idnums{$$codetitles[0]})\n";
! 1146: }
! 1147: $$script_tag .=
! 1148: " var idcodes = new Array ($$idnums{$$codetitles[0]})\n";
! 1149: if ($longtitles[2]) {
! 1150: $$script_tag .=
! 1151: " var idcodeslongs = new Array ($$idnums{$$codetitles[0]})\n";
! 1152: }
! 1153: $$script_tag .=
! 1154: " var idcourses = new Array ($$idnums{$$codetitles[0]})\n";
! 1155: if ($longtitles[3]) {
! 1156: $$script_tag .=
! 1157: " var idcourseslongs = new Array ($$idnums{$$codetitles[0]})\n";
! 1158: }
! 1159: my @sort_a = split/","/,$$idlist{$$codetitles[0]};
1.6 raeburn 1160: for (my $j=0; $j<@sort_a; $j++) {
1161: $$script_tag .= qq| idsems[$j] = new Array("$$idlist{$$codetitles[1]}{$sort_a[$j]}")\n|;
1.20 ! raeburn 1162: if ($longtitles[1]) {
! 1163: $$script_tag .= qq| idsemslongs[$j] = new Array("$$idlist_titles{$$codetitles[1]}{$sort_a[$j]}")\n|;
! 1164: }
1.6 raeburn 1165: $$script_tag .= qq| idcodes[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1.20 ! raeburn 1166: if ($longtitles[2]) {
! 1167: $$script_tag .= qq| idcodeslongs[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
! 1168: }
1.6 raeburn 1169: $$script_tag .= qq| idcourses[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1.20 ! raeburn 1170: if ($longtitles[3]) {
! 1171: $$script_tag .= qq| idcourseslongs[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
! 1172: }
1.6 raeburn 1173: my @sort_b = split/","/,$$idlist{$$codetitles[1]}{$sort_a[$j]};
1174: for (my $k=0; $k<@sort_b; $k++) {
1175: my $idcode_entry = $$idlist{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
1176: $$script_tag .= qq| idcodes[$j][$k] = new Array("$idcode_entry")\n|;
1.20 ! raeburn 1177: if ($longtitles[2]) {
! 1178: my $idcodelong_entry = $$idlist_titles{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
! 1179: $$script_tag .= qq| idcodeslongs[$j][$k] = new Array("$idcodelong_entry")\n|;
! 1180: }
1.6 raeburn 1181: $$script_tag .= qq| idcourses[$j][$k] = new Array($$idnums{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
1.20 ! raeburn 1182: if ($longtitles[3]) {
! 1183: $$script_tag .= qq| idcourseslongs[$j][$k] = new Array($$idnums{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
! 1184: }
1.6 raeburn 1185: my @sort_c = split/","/,$$idlist{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
1186: for (my $l=0; $l<@sort_c; $l++) {
1187: my $idcourse_entry = $$idlist{$$codetitles[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
1188: $$script_tag .= qq| idcourses[$j][$k][$l] = new Array("$idcourse_entry")\n|;
1.20 ! raeburn 1189: if ($longtitles[3]) {
! 1190: my $idcourselong_entry = $$idlist_titles{$$codetitles[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
! 1191: $$script_tag .= qq| idcourseslongs[$j][$k][$l] = new Array("$idcourselong_entry")\n|;
! 1192: }
1.6 raeburn 1193: }
1194: }
1195: }
1196: $$script_tag .= (<<END_OF_BLOCK);
1.19 raeburn 1197: if (caller == "$$codetitles[0]") {
1.15 raeburn 1198: document.logproblem.Department.length = 0
1199: document.logproblem.Number.length = 0
1.19 raeburn 1200: document.logproblem.Department.options[0] = new Option("<-Pick $$codetitles[1]","-1",true,true)
1201: document.logproblem.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
1.6 raeburn 1202: if (idyr == 0) {
1.15 raeburn 1203: document.logproblem.Semester.length = 0
1.19 raeburn 1204: document.logproblem.Semester.options[0] = new Option("<-Pick $$codetitles[0]","-1",true,true)
1.6 raeburn 1205: }
1206: else {
1.15 raeburn 1207: document.logproblem.Semester.length = 0
1208: document.logproblem.Semester.options[0] = new Option("Select","-1",true,true)
1.6 raeburn 1209: for (var i=0; i<idsems[idyr-1].length; i++) {
1.20 ! raeburn 1210: if (longtitles[1] == 1) {
! 1211: document.logproblem.Semester.options[i+1] = new Option(idsemslongs[idyr-1][i],idsems[idyr-1][i],false,false)
! 1212: }
! 1213: else {
! 1214: document.logproblem.Semester.options[i+1] = new Option(idsems[idyr-1][i],idsems[idyr-1][i],false,false)
! 1215: }
1.6 raeburn 1216: }
1217: }
1.15 raeburn 1218: document.logproblem.Semester.selectedIndex = 0;
1.6 raeburn 1219: }
1.19 raeburn 1220: if (caller == "$$codetitles[1]") {
1.15 raeburn 1221: document.logproblem.Department.length = 0
1222: document.logproblem.Number.length = 0
1.19 raeburn 1223: document.logproblem.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
1.6 raeburn 1224: if (idsem == 0) {
1.19 raeburn 1225: document.logproblem.Department.options[0] = new Option("<-Pick $$codetitles[1]","-1",true,true)
1.6 raeburn 1226: }
1227: else {
1.15 raeburn 1228: document.logproblem.Department.options[0] = new Option("Select","-1",true,true)
1.6 raeburn 1229: for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) {
1.20 ! raeburn 1230: if (longtitles[2] == 1) {
! 1231: document.logproblem.Department.options[i+1] = new Option(idcodeslongs[idyr-1][idsem-1][i],idcodes[idyr-1][idsem-1][i],false,false)
! 1232: }
! 1233: else {
! 1234: document.logproblem.Department.options[i+1] = new Option(idcodes[idyr-1][idsem-1][i],idcodes[idyr-1][idsem-1][i],false,false)
! 1235: }
1.6 raeburn 1236: }
1237: }
1.15 raeburn 1238: document.logproblem.Department.selectedIndex = 0
1.6 raeburn 1239: }
1.19 raeburn 1240: if (caller == "$$codetitles[2]") {
1.15 raeburn 1241: document.logproblem.Number.length = 0
1.6 raeburn 1242: if (iddept == 0) {
1.19 raeburn 1243: document.logproblem.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
1.6 raeburn 1244: }
1245: else {
1.15 raeburn 1246: document.logproblem.Number.options[0] = new Option("Select","-1",true,true)
1.6 raeburn 1247: for (var i=0; i<idcourses[idyr-1][idsem-1][iddept-1].length; i++) {
1.20 ! raeburn 1248: if (longtitles[3] == 1) {
! 1249: document.logproblem.Number.options[i+1] = new Option(idcourseslongs[idyr-1][idsem-1][iddept-1][i],idcourses[idyr-1][idsem-1][iddept-1][i],false,false)
! 1250: }
! 1251: else {
! 1252: document.logproblem.Number.options[i+1] = new Option(idcourses[idyr-1][idsem-1][iddept-1][i],idcourses[idyr-1][idsem-1][iddept-1][i],false,false)
! 1253: }
1.6 raeburn 1254: }
1255: }
1.15 raeburn 1256: document.logproblem.Number.selectedIndex = 0
1.6 raeburn 1257: }
1258: }
1259: END_OF_BLOCK
1260: }
1261:
1.1 raeburn 1262: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>