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