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