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