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