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