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