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