Annotation of loncom/interface/lonsupportreq.pm, revision 1.25
1.24 albertel 1: #
1.25 ! albertel 2: # $Id: lonsupportreq.pm,v 1.24 2005/04/07 03:58:02 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) = @_;
640: 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 641: my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
642:
1.1 raeburn 643: my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);
1.5 raeburn 644: my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
1.1 raeburn 645: my $to = $Apache::lonnet::perlvar{'lonSupportEMail'};
1.5 raeburn 646: my $from = $admin;
1.1 raeburn 647: my $reporttime = &Apache::lonlocal::locallocaltime(time);
648: my $fontcolor = &Apache::loncommon::designparm($function.'.font');
649: my $vlinkcolor = &Apache::loncommon::designparm($function.'.vlink');
650: my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
1.14 raeburn 651: my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot');
1.20 raeburn 652:
1.1 raeburn 653: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
1.25 ! albertel 654: my $coursecode = $env{'form.coursecode'};
1.19 raeburn 655: if ($coursecode eq '') {
1.25 ! albertel 656: if (defined($env{'form.Year'})) {
! 657: $coursecode .= $env{'form.Year'};
1.19 raeburn 658: }
1.25 ! albertel 659: if (defined($env{'form.Semester'})) {
! 660: $coursecode .= $env{'form.Semester'};
1.19 raeburn 661: }
1.25 ! albertel 662: if (defined($env{'form.Department'})) {
! 663: $coursecode .= $env{'form.Department'};
1.19 raeburn 664: }
1.25 ! albertel 665: if (defined($env{'form.Number'})) {
! 666: $coursecode .= $env{'form.Number'};
1.19 raeburn 667: }
668: }
1.1 raeburn 669: my $supportmsg = qq|
1.25 ! albertel 670: Name: $env{'form.username'}
! 671: Email: $env{'form.email'}
! 672: Username/domain: $env{'form.uname'} - $env{'form.udom'}
! 673: Tel: $env{'form.phone'}
! 674: Course Information: $env{'form.title'} - $coursecode - section: $env{'form.section'}
! 675: Subject: $env{'form.subject'}
! 676: Description: $env{'form.description'}
! 677: URL: $env{'form.sourceurl'}
1.1 raeburn 678: Date/Time: $reporttime
679:
680: |;
1.25 ! albertel 681: my $descrip = $env{'form.description'};
1.5 raeburn 682: $descrip =~ s#\n#<br />#g;
683: my $displaymsg = qq|
1.25 ! albertel 684: <font color="$fontcolor">Name:</font><font color="$vlinkcolor"> $env{'form.username'}</font><br />
! 685: <font color="$fontcolor">Email: </font><font color="$vlinkcolor">$env{'form.email'}</font><br />
! 686: <font color="$fontcolor">Username/domain: </font><font color="$vlinkcolor">$env{'form.uname'} - $env{'form.udom'}</font><br />
! 687: <font color="$fontcolor">Tel: </font><font color="$vlinkcolor">$env{'form.phone'}</font><br />
! 688: <font color="$fontcolor">Course Information: </font><font color="$vlinkcolor">$env{'form.title'} - $coursecode - section: $env{'form.section'}</font><br />
! 689: <font color="$fontcolor">Subject: </font><font color="$vlinkcolor">$env{'form.subject'}</font><br />
1.5 raeburn 690: <font color="$fontcolor">Description: </font><font color="$vlinkcolor">$descrip</font><br />
1.25 ! albertel 691: <font color="$fontcolor">URL: </font><font color="$vlinkcolor">$env{'form.sourceurl'}</font><br />
1.5 raeburn 692: <font color="$fontcolor">Date/Time: </font><font color="$vlinkcolor">$reporttime</font><br />
693: |;
1.23 albertel 694: my $html=&Apache::lonxml::xmlbegin();
1.14 raeburn 695: $r->print(<<"END");
1.23 albertel 696: $html
1.1 raeburn 697: <head>
698: <title>LON-CAPA support request recorded</title>
699: </head>
700: $bodytag
1.16 raeburn 701: <form name="logproblem">
1.18 raeburn 702: <input type="hidden" name="action" value="result" />
1.16 raeburn 703: </form>
1.1 raeburn 704: END
1.14 raeburn 705: if ($r->uri eq '/adm/helpdesk') {
706: &print_header($r,$url,'process');
707: }
708: if ($to =~ m/^[^\@]+\@[^\@]+$/) {
709: $r->print("<h3>A support request has been sent to $to</h3>");
1.9 raeburn 710: } else {
711: $to = $admin;
712: if ($to =~ m/^[^\@]+\@[^\@]+$/) {
1.14 raeburn 713: $r->print("<h3>A support request has been sent to $to</h3>");
1.9 raeburn 714: END
715: } else {
716: $r->print(<<END);
1.1 raeburn 717: <h3>Warning: Problem with support e-mail address</h3>
1.9 raeburn 718: 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 719: END
1.9 raeburn 720: $to = 'helpdesk@lon-capa.org';
721: }
1.1 raeburn 722: }
1.25 ! albertel 723: if (defined($env{'form.email'})) {
! 724: if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
! 725: $from = $env{'form.email'};
1.5 raeburn 726: }
727: }
728:
1.25 ! albertel 729: my $subject = $env{'form.subject'};
1.5 raeburn 730: $subject =~ s#(`)#'#g;
731: $subject =~ s#\$#\(\$\)#g;
732: $supportmsg =~ s#(`)#'#g;
733: $supportmsg =~ s#\$#\(\$\)#g;
734: $displaymsg =~ s#(`)#'#g;
735: $displaymsg =~ s#\$#\(\$\)#g;
736: my $fname;
737:
738: my $attachmentpath = '';
739: my $attachmentsize = '';
1.25 ! albertel 740: if (defined($env{'user.name'})) {
! 741: if ($env{'form.screenshot.filename'}) {
! 742: $attachmentsize = length($env{'form.screenshot'});
1.5 raeburn 743: if ($attachmentsize > 131072) {
744: $displaymsg .= "<br />The uploaded screenshot file ($attachmentsize bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.";
745: } else {
746: $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
747: }
748: }
749: }
750:
751: if ($attachmentpath =~ m-/([^/]+)$-) {
752: $fname = $1;
1.25 ! albertel 753: $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 754: $supportmsg .= "\n";
755: foreach (@envvars) {
1.25 ! albertel 756: $supportmsg .= "$_: $env{$_}\n";
1.5 raeburn 757: }
758: }
759:
760: my $msg = MIME::Lite->new(
761: From => $from,
762: To => $to,
763: Subject => $subject,
764: Type =>'TEXT',
765: Data => $supportmsg,
766: );
767:
768: if ($attachmentpath) {
769: my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
770: $msg->attach(Type => $type,
771: Path => $attachmentpath,
772: Filename => $fname
773: );
774:
775: } else {
776: my $envdata = '';
777: foreach (@envvars) {
1.25 ! albertel 778: $envdata .= "$_: $env{$_}\n";
1.5 raeburn 779: }
780: foreach (@loncvars) {
1.25 ! albertel 781: $envdata .= "$_: $env{$_}\n";
1.5 raeburn 782: }
783: $msg->attach(Type => 'TEXT',
784: Data => $envdata);
785: }
786:
787: ### Send it:
1.25 ! albertel 788: # ->send can cause an sh launch which can pass all of %env along
1.4 albertel 789: # which can be to large for /bin/sh's little mind
1.5 raeburn 790: $msg->send('sendmail');
791:
792: if ($attachmentpath =~ m#$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+#) {
793: unlink($attachmentpath);
794: }
795: $r->print(qq|
1.1 raeburn 796: <b>Your support request contained the following information</b>:<br /><br />
797: <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
798: <tr>
799: <td>
800: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
801: <tr>
802: <td>
803: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
804: <tr>
805: <td>
806: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
807: <tr>
808: <td width="140" bgcolor="$tablecolor">
809: <table width="140" border="0" cellpadding="8" cellspacing="0">
810: <tr>
811: <td align="right"><b>Information supplied</b>
812: </td>
813: </tr>
814: </table>
815: </td>
816: <td width="100%" valign="top">
817: <table width="100%" border="0" cellpadding="8" cellspacing="0">
818: <tr>
1.5 raeburn 819: <td>$displaymsg</td>
1.1 raeburn 820: </tr>
821: </table>
822: </td>
823: </tr>
824: <tr>
1.5 raeburn 825: <td width="100%" colspan="2" bgcolor="#000000">
826: <img src="/adm/lonMisc/blackdot.gif" /><br />
827: </td>
828: </tr>
829: <tr>
830: <td width="140" bgcolor="$tablecolor">
831: <table width="140" border="0" cellpadding="8" cellspacing="0">
1.1 raeburn 832: <tr>
833: <td align="right"><b>Additional information recorded</b>
834: </td>
835: </tr>
836: </table>
837: </td>
838: <td width="100%" valign="top">
839: <table width="100%" border="0" cellpadding="8" cellspacing="0">
840: <tr>
841: <td>
1.5 raeburn 842: |);
1.1 raeburn 843: foreach (@envvars) {
1.25 ! albertel 844: unless($env{$_} eq '') {
! 845: $r->print("$_: <font color='$vlinkcolor'>$env{$_}</font>, ");
1.5 raeburn 846: }
1.1 raeburn 847: }
848: $r->print("
849: </td>
850: </tr>
851: </table>
852: </td>
853: </tr>
854: </table>
855: </td>
856: </tr>
857: </table>
858: </td>
859: </tr>
860: </table>
861: </td>
862: </tr>
863: </table>
1.14 raeburn 864: </body>
865: </html>
1.1 raeburn 866: ");
867: }
868:
1.14 raeburn 869: sub print_header {
870: my ($r,$origurl,$action) = @_;
871: my $location=&Apache::loncommon::lonhttpdurl("/adm");
872: my $tablecolor = '#EEEE99';
873: my ($component_url);
874: my $helpdesk_link = '<a href="javascript:validate()">';
875: if ($action eq 'process') {
876: $helpdesk_link = '<a href="/adm/helpdesk">';
877: }
878: my %lt = &Apache::lonlocal::texthash (
879: login => 'Log-in help',
880: ask => 'Ask helpdesk',
881: getst => 'Getting started guide',
882: back => 'Back to last location'
1.21 raeburn 883: );
884: my ($getstartlink,$getstarttext);
885: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
886: $getstartlink = qq|<td align="center"> <b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
887: $getstarttext = ' '.&mt('and the "Getting started" guide').' ';
888: }
1.14 raeburn 889: $r->print(<<END);
890: <table width="620" border="0" cellspacing="0" cellpadding="0" height="55"> <tr height="50"> <td width='5'> </td>
891: <td>
892: <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>
893: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
894: <tr>
895: <td>
896: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
897: <tr>
898: <td>
899: <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
900: <tr>
901: <td>
902: <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
903: <tr bgcolor="$tablecolor">
904: <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 905: <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 906: <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>
907: </tr>
908: </table>
909: </td>
910: </tr>
911: </table>
912: </td>
913: </tr>
914: </table>
915: </td>
916: </tr>
917: </table>
918: </fieldset>
919: </td>
920: <td width='5'> </td>
921: </tr>
922: <tr height='5'>
923: <td colspan='3' height='5'> </td>
924: </tr>
925: END
926: unless ($action eq 'process') {
927: $r->print('
928: <tr>
929: <td colspan="3">'.&mt('
1.21 raeburn 930: 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 931: </td>
932: </tr>');
933: }
934: $r->print('
935: </table>');
936: return;
937: }
938:
1.1 raeburn 939: sub retrieve_instcodes {
940: my ($coursecodes,$codedom,$totcodes) = @_;
1.11 raeburn 941: my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.');
1.1 raeburn 942: foreach my $course (keys %courses) {
1.11 raeburn 943: if ($courses{$course} =~ m/^[^:]*:([^:]+)/) {
1.1 raeburn 944: $$coursecodes{$course} = &Apache::lonnet::unescape($1);
945: $totcodes ++;
946: }
947: }
948: return $totcodes;
949: }
950:
1.6 raeburn 951: sub build_code_selections {
952: my ($codes,$codetitles,$cat_titles,$cat_order,$idlist,$idnums,$idlist_titles) = @_;
953: my %idarrays = ();
954: for (my $i=1; $i<@{$codetitles}; $i++) {
955: %{$idarrays{$$codetitles[$i]}} = ();
956: }
957: foreach my $cid (sort keys %{$codes}) {
958: &recurse_list($cid,$codetitles,$codes,0,\%idarrays);
959: }
960: for (my $num=0; $num<@{$codetitles}; $num++) {
961: if ($num == 0) {
962: my @contents = ();
963: my @contents_titles = ();
964: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[0]}},\@contents);
965: if (defined($$cat_titles{$$codetitles[0]})) {
966: foreach (@contents) {
967: push @contents_titles, $$cat_titles{$$codetitles[0]}{$_};
968: }
969: }
970: $$idlist{$$codetitles[0]} = join('","',@contents);
971: $$idnums{$$codetitles[0]} = scalar(@contents);
972: if (defined($$cat_titles{$$codetitles[0]})) {
973: $$idlist_titles{$$codetitles[0]} = join('","',@contents_titles);
974: }
975: } elsif ($num == 1) {
976: %{$$idlist{$$codetitles[1]}} = ();
977: %{$$idlist_titles{$$codetitles[1]}} = ();
978: foreach my $key_a (keys %{$idarrays{$$codetitles[1]}}) {
979: my @sorted_a = ();
980: my @sorted_a_titles = ();
981: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[1]}{$key_a}},\@sorted_a);
982: if (defined($$cat_titles{$$codetitles[1]})) {
983: foreach (@sorted_a) {
984: push @sorted_a_titles, $$cat_titles{$$codetitles[1]}{$_};
985: }
986: }
987: $$idlist{$$codetitles[1]}{$key_a} = join('","',@sorted_a);
988: $$idnums{$$codetitles[1]}{$key_a} = scalar(@sorted_a);
989: if (defined($$cat_titles{$$codetitles[1]})) {
990: $$idlist_titles{$$codetitles[1]}{$key_a} = join('","',@sorted_a_titles);
991: }
992: }
993: } elsif ($num == 2) {
994: %{$$idlist{$$codetitles[2]}} = ();
995: %{$$idlist_titles{$$codetitles[2]}} = ();
996: foreach my $key_a (keys %{$idarrays{$$codetitles[2]}}) {
997: %{$$idlist{$$codetitles[2]}{$key_a}} = ();
998: %{$$idlist_titles{$$codetitles[2]}{$key_a}} = ();
999: foreach my $key_b (keys %{$idarrays{$$codetitles[2]}{$key_a}}) {
1000: my @sorted_b = ();
1001: my @sorted_b_titles = ();
1002: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[2]}{$key_a}{$key_b}},\@sorted_b);
1.19 raeburn 1003: if (defined($$cat_titles{$$codetitles[2]})) {
1.6 raeburn 1004: foreach (@sorted_b) {
1.19 raeburn 1005: push @sorted_b_titles, $$cat_titles{$$codetitles[2]}{$_};
1.6 raeburn 1006: }
1007: }
1008: $$idlist{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b);
1009: $$idnums{$$codetitles[2]}{$key_a}{$key_b} = scalar(@sorted_b);
1010: if (defined($$cat_titles{$$codetitles[2]})) {
1011: $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b_titles);
1012: }
1013: }
1014: }
1015: } elsif ($num == 3) {
1016: %{$$idlist{$$codetitles[3]}} = ();
1017: foreach my $key_a (keys %{$idarrays{$$codetitles[3]}}) {
1018: %{$$idlist{$$codetitles[3]}{$key_a}} = ();
1019: foreach my $key_b (keys %{$idarrays{$$codetitles[3]}{$key_a}}) {
1020: %{$$idlist{$$codetitles[3]}{$key_a}{$key_b}} = ();
1021: foreach my $key_c (keys %{$idarrays{$$codetitles[3]}{$key_a}{$key_b}}) {
1022: my @sorted_c = ();
1.20 raeburn 1023: my @sorted_c_titles = ();
1.6 raeburn 1024: &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[3]}{$key_a}{$key_b}{$key_c}},\@sorted_c);
1.20 raeburn 1025: if (defined($$cat_titles{$$codetitles[3]})) {
1026: foreach (@sorted_c) {
1027: push @sorted_c_titles, $$cat_titles{$$codetitles[3]}{$_};
1028: }
1029: }
1.6 raeburn 1030: $$idlist{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c);
1031: $$idnums{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = scalar(@sorted_c);
1.20 raeburn 1032: if (defined($$cat_titles{$$codetitles[3]})) {
1033: $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_c_titles);
1034: }
1.6 raeburn 1035: }
1036: }
1037: }
1038: } elsif ($num == 4) {
1039: %{$$idlist{$$codetitles[4]}} = ();
1040: foreach my $key_a (keys %{$idarrays{$$codetitles[4]}}) {
1041: %{$$idlist{$$codetitles[4]}{$key_a}} = ();
1042: foreach my $key_b (keys %{$idarrays{$$codetitles[4]}{$key_a}}) {
1043: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}} = ();
1044: foreach my $key_c (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}}) {
1045: %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}} = ();
1046: foreach my $key_d (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}}) {
1047: my @sorted_d = ();
1.20 raeburn 1048: my @sorted_d_titles = ();
1.6 raeburn 1049: &sort_cats($num,$cat_order,$codetitles,$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d},\@sorted_d);
1.20 raeburn 1050: if (defined($$cat_titles{$$codetitles[4]})) {
1051: foreach (@sorted_d) {
1052: push @sorted_d_titles, $$cat_titles{$$codetitles[4]}{$_};
1053: }
1054: }
1.6 raeburn 1055: $$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d);
1056: $$idnums{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = scalar(@sorted_d);
1057: }
1058: }
1059: }
1060: }
1061: }
1062: }
1063: }
1064:
1065: sub sort_cats {
1066: my ($num,$cat_order,$codetitles,$idsarrayref,$sorted) = @_;
1067: my @unsorted = @{$idsarrayref};
1068: if (defined($$cat_order{$$codetitles[$num]})) {
1069: foreach (@{$$cat_order{$$codetitles[$num]}}) {
1070: if (grep/^$_$/,@unsorted) {
1071: push @{$sorted}, $_;
1072: }
1073: }
1074: } else {
1075: @{$sorted} = sort (@unsorted);
1076: }
1077: }
1078:
1079:
1080: sub recurse_list {
1081: my ($cid,$codetitles,$codes,$num,$idarrays) = @_;
1082: if ($num == 0) {
1083: if (!grep/^$$codes{$cid}{$$codetitles[0]}$/,@{$$idarrays{$$codetitles[0]}}) {
1084: push @{$$idarrays{$$codetitles[0]}}, $$codes{$cid}{$$codetitles[0]};
1085: }
1086: } elsif ($num == 1) {
1087: if (defined($$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}})) {
1088: if (!grep/^$$codes{$cid}{$$codetitles[1]}$/,@{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}) {
1089: push @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}, $$codes{$cid}{$$codetitles[1]};
1090: }
1091: } else {
1092: @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}} = ("$$codes{$cid}{$$codetitles[1]}");
1093: }
1094: } elsif ($num == 2) {
1095: if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}})) {
1096: if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
1097: if (!grep/^$$codes{$cid}{$$codetitles[2]}$/,@{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}) {
1098: push @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}, $$codes{$cid}{$$codetitles[2]};
1099: }
1100: } else {
1101: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
1102: }
1103: } else {
1104: %{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}} = ();
1105: @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
1106: }
1107: } elsif ($num == 3) {
1108: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}})) {
1109: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
1110: if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
1111: if (!grep/^$$codes{$cid}{$$codetitles[3]}$/,@{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}) {
1112: push @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}, $$codes{$cid}{$$codetitles[3]};
1113: }
1114: } else {
1115: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1116: }
1117: } else {
1118: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1119: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1120: }
1121: } else {
1122: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}} = ();
1123: %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1124: @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1125: }
1126: } elsif ($num == 4) {
1127: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}})) {
1128: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
1129: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
1130: if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}})) {
1131: 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]}}}) {
1132: push @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}}, $$codes{$cid}{$$codetitles[4]};
1133: }
1134: } else {
1135: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1136: }
1137: } else {
1138: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
1139: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1140: }
1141: } else {
1142: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1143: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
1144: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
1145: }
1146: } else {
1147: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}} = ();
1148: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
1149: %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
1150: @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[3]}");
1151: }
1152: }
1153: $num ++;
1154: if ($num <@{$codetitles}) {
1155: &recurse_list($cid,$codetitles,$codes,$num,$idarrays);
1156: }
1157: }
1158:
1159: sub javascript_code_selections {
1.20 raeburn 1160: my ($numcats,$cat_titles,$script_tag,$idlist,$idnums,$idlist_titles,$codetitles) = @_;
1.10 raeburn 1161: my $numtitles = @{$codetitles};
1.20 raeburn 1162: my @seltitles = ();
1.10 raeburn 1163: for (my $j=0; $j<$numtitles; $j++) {
1164: $seltitles[$j] = 'id'.$$codetitles[$j];
1165: }
1166: my $seltitle_str = join('","',@seltitles);
1.20 raeburn 1167: my @longtitles = ();
1168: for (my $i=0; $i<$numtitles; $i++) {
1169: if (defined($$cat_titles{$$codetitles[$i]})) {
1170: $longtitles[$i] = 1;
1171: } else {
1172: $longtitles[$i] = 0;
1173: }
1174: }
1175: my $longtitles_str = join('","',@longtitles);
1.6 raeburn 1176: $$script_tag .= <<END;
1177: function courseSet(caller) {
1.10 raeburn 1178: var ids = new Array ("$seltitle_str");
1179: var formitems = new Array ($numtitles);
1.20 raeburn 1180: var longtitles = new Array ("$longtitles_str");
1.15 raeburn 1181: var idyr = document.logproblem.Year.selectedIndex
1182: var idsem = document.logproblem.Semester.selectedIndex
1183: var iddept = document.logproblem.Department.selectedIndex
1184: var idclass = document.logproblem.Number.selectedIndex
1.6 raeburn 1185: var idyears = new Array("$$idlist{$$codetitles[0]}");
1186: END
1.20 raeburn 1187: if ($longtitles[0]) {
1188: $$script_tag .=
1189: qq| var idyearslongs = new Array("$$idlist_titles{$$codetitles[0]}")\n|;
1190: }
1191: $$script_tag .=
1192: " var idsems = new Array ($$idnums{$$codetitles[0]})\n";
1193: if ($longtitles[1]) {
1194: $$script_tag .=
1195: " var idsemslongs = new Array ($$idnums{$$codetitles[0]})\n";
1196: }
1197: $$script_tag .=
1198: " var idcodes = new Array ($$idnums{$$codetitles[0]})\n";
1199: if ($longtitles[2]) {
1200: $$script_tag .=
1201: " var idcodeslongs = new Array ($$idnums{$$codetitles[0]})\n";
1202: }
1203: $$script_tag .=
1204: " var idcourses = new Array ($$idnums{$$codetitles[0]})\n";
1205: if ($longtitles[3]) {
1206: $$script_tag .=
1207: " var idcourseslongs = new Array ($$idnums{$$codetitles[0]})\n";
1208: }
1209: my @sort_a = split/","/,$$idlist{$$codetitles[0]};
1.6 raeburn 1210: for (my $j=0; $j<@sort_a; $j++) {
1211: $$script_tag .= qq| idsems[$j] = new Array("$$idlist{$$codetitles[1]}{$sort_a[$j]}")\n|;
1.20 raeburn 1212: if ($longtitles[1]) {
1213: $$script_tag .= qq| idsemslongs[$j] = new Array("$$idlist_titles{$$codetitles[1]}{$sort_a[$j]}")\n|;
1214: }
1.6 raeburn 1215: $$script_tag .= qq| idcodes[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1.20 raeburn 1216: if ($longtitles[2]) {
1217: $$script_tag .= qq| idcodeslongs[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1218: }
1.6 raeburn 1219: $$script_tag .= qq| idcourses[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1.20 raeburn 1220: if ($longtitles[3]) {
1221: $$script_tag .= qq| idcourseslongs[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
1222: }
1.6 raeburn 1223: my @sort_b = split/","/,$$idlist{$$codetitles[1]}{$sort_a[$j]};
1224: for (my $k=0; $k<@sort_b; $k++) {
1225: my $idcode_entry = $$idlist{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
1226: $$script_tag .= qq| idcodes[$j][$k] = new Array("$idcode_entry")\n|;
1.20 raeburn 1227: if ($longtitles[2]) {
1228: my $idcodelong_entry = $$idlist_titles{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
1229: $$script_tag .= qq| idcodeslongs[$j][$k] = new Array("$idcodelong_entry")\n|;
1230: }
1.6 raeburn 1231: $$script_tag .= qq| idcourses[$j][$k] = new Array($$idnums{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
1.20 raeburn 1232: if ($longtitles[3]) {
1233: $$script_tag .= qq| idcourseslongs[$j][$k] = new Array($$idnums{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
1234: }
1.6 raeburn 1235: my @sort_c = split/","/,$$idlist{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
1236: for (my $l=0; $l<@sort_c; $l++) {
1237: my $idcourse_entry = $$idlist{$$codetitles[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
1238: $$script_tag .= qq| idcourses[$j][$k][$l] = new Array("$idcourse_entry")\n|;
1.20 raeburn 1239: if ($longtitles[3]) {
1240: my $idcourselong_entry = $$idlist_titles{$$codetitles[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
1241: $$script_tag .= qq| idcourseslongs[$j][$k][$l] = new Array("$idcourselong_entry")\n|;
1242: }
1.6 raeburn 1243: }
1244: }
1245: }
1246: $$script_tag .= (<<END_OF_BLOCK);
1.22 raeburn 1247: var display = new Array($numtitles)
1248: if (caller == "") {
1249: document.logproblem.Year.length = 0
1250: document.logproblem.Year.options[0] = new Option("Select","-1",true,true)
1251: display[0] = new Array(idyears.length)
1252: for (var i=0; i<idyears.length; i++) {
1253: display[0][i] = idyears[i]
1254: if (longtitles[0] == 1) {
1255: if (idyearslongs[i] != "") {
1256: display[0][i] = idyearslongs[i]
1257: }
1258: }
1259: document.logproblem.Year.options[i+1] = new Option(display[0][i],idyears[i],false,false)
1260: }
1261: document.logproblem.Year.selectedIndex = 0;
1262: }
1.19 raeburn 1263: if (caller == "$$codetitles[0]") {
1.15 raeburn 1264: document.logproblem.Department.length = 0
1265: document.logproblem.Number.length = 0
1.19 raeburn 1266: document.logproblem.Department.options[0] = new Option("<-Pick $$codetitles[1]","-1",true,true)
1267: document.logproblem.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
1.6 raeburn 1268: if (idyr == 0) {
1.15 raeburn 1269: document.logproblem.Semester.length = 0
1.19 raeburn 1270: document.logproblem.Semester.options[0] = new Option("<-Pick $$codetitles[0]","-1",true,true)
1.6 raeburn 1271: }
1272: else {
1.15 raeburn 1273: document.logproblem.Semester.length = 0
1274: document.logproblem.Semester.options[0] = new Option("Select","-1",true,true)
1.22 raeburn 1275: display[1] = new Array(idsems[idyr-1].length)
1.6 raeburn 1276: for (var i=0; i<idsems[idyr-1].length; i++) {
1.22 raeburn 1277: display[1][i] = idsems[idyr-1][i]
1.20 raeburn 1278: if (longtitles[1] == 1) {
1.22 raeburn 1279: if (idsemslongs[idyr-1][i] != "") {
1280: display[1][i] = idsemslongs[idyr-1][i]
1281: }
1.20 raeburn 1282: }
1.22 raeburn 1283: document.logproblem.Semester.options[i+1] = new Option(display[1][i],idsems[idyr-1][i],false,false)
1.6 raeburn 1284: }
1285: }
1.15 raeburn 1286: document.logproblem.Semester.selectedIndex = 0;
1.6 raeburn 1287: }
1.19 raeburn 1288: if (caller == "$$codetitles[1]") {
1.15 raeburn 1289: document.logproblem.Department.length = 0
1290: document.logproblem.Number.length = 0
1.19 raeburn 1291: document.logproblem.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
1.6 raeburn 1292: if (idsem == 0) {
1.19 raeburn 1293: document.logproblem.Department.options[0] = new Option("<-Pick $$codetitles[1]","-1",true,true)
1.6 raeburn 1294: }
1295: else {
1.15 raeburn 1296: document.logproblem.Department.options[0] = new Option("Select","-1",true,true)
1.22 raeburn 1297: display[2] = new Array(idcodes[idyr-1][idsem-1].length)
1.6 raeburn 1298: for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) {
1.22 raeburn 1299: display[2][i] = idcodes[idyr-1][idsem-1][i]
1.20 raeburn 1300: if (longtitles[2] == 1) {
1.22 raeburn 1301: if (idcodeslongs[idyr-1][idsem-1][i] != "") {
1302: display[2][i] = idcodeslongs[idyr-1][idsem-1][i]
1303: }
1.20 raeburn 1304: }
1.22 raeburn 1305: document.logproblem.Department.options[i+1] = new Option(display[2][i],idcodes[idyr-1][idsem-1][i],false,false)
1.6 raeburn 1306: }
1307: }
1.15 raeburn 1308: document.logproblem.Department.selectedIndex = 0
1.6 raeburn 1309: }
1.19 raeburn 1310: if (caller == "$$codetitles[2]") {
1.15 raeburn 1311: document.logproblem.Number.length = 0
1.6 raeburn 1312: if (iddept == 0) {
1.19 raeburn 1313: document.logproblem.Number.options[0] = new Option("<-Pick $$codetitles[2]","-1",true,true)
1.6 raeburn 1314: }
1315: else {
1.15 raeburn 1316: document.logproblem.Number.options[0] = new Option("Select","-1",true,true)
1.22 raeburn 1317: display[3] = new Array (idcourses[idyr-1][idsem-1][iddept-1].length)
1.6 raeburn 1318: for (var i=0; i<idcourses[idyr-1][idsem-1][iddept-1].length; i++) {
1.22 raeburn 1319: display[3][i] = idcourses[idyr-1][idsem-1][iddept-1][i]
1.20 raeburn 1320: if (longtitles[3] == 1) {
1.22 raeburn 1321: if (idcourseslongs[idyr-1][idsem-1][iddept-1][i] != "") {
1322: display[3][i] = idcourseslongs[idyr-1][idsem-1][iddept-1][i]
1323: }
1.20 raeburn 1324: }
1.22 raeburn 1325: document.logproblem.Number.options[i+1] = new Option(display[3][i],idcourses[idyr-1][idsem-1][iddept-1][i],false,false)
1.6 raeburn 1326: }
1327: }
1.15 raeburn 1328: document.logproblem.Number.selectedIndex = 0
1.6 raeburn 1329: }
1330: }
1.22 raeburn 1331:
1332: function initialize_codes() {
1333: courseSet();
1334: return;
1335: }
1.6 raeburn 1336: END_OF_BLOCK
1337: }
1338:
1.1 raeburn 1339: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>