Annotation of loncom/interface/lonsupportreq.pm, revision 1.79.2.1

1.24      albertel    1: #
1.79.2.1! raeburn     2: # $Id: lonsupportreq.pm,v 1.79 2015/06/09 21:22:57 damieng 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;
1.5       raeburn    30: use MIME::Types;
                     31: use MIME::Lite;
1.27      raeburn    32: use CGI::Cookie();
1.1       raeburn    33: use Apache::Constants qw(:common);
1.2       albertel   34: use Apache::loncommon();
1.43      raeburn    35: use Apache::lonhtmlcommon;
1.24      albertel   36: use Apache::lonnet;
1.1       raeburn    37: use Apache::lonlocal;
1.34      albertel   38: use Apache::lonacc();
1.68      raeburn    39: use Apache::lonauth();
1.38      raeburn    40: use Apache::courseclassifier;
1.60      raeburn    41: use LONCAPA qw(:DEFAULT :match);
1.70      raeburn    42: use HTML::Entities;
1.1       raeburn    43: 
                     44: sub handler {
1.2       albertel   45:     my ($r) = @_;
                     46:     &Apache::loncommon::content_type($r,'text/html');
1.1       raeburn    47:     $r->send_http_header;
                     48: 
                     49:     if ($r->header_only) {
                     50:         return OK;
                     51:     }
1.42      albertel   52:     if ($r->uri eq '/adm/helpdesk') {
                     53: 	&Apache::lonlocal::get_language_handle($r);
                     54:     }
                     55: 
1.12      raeburn    56:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']);
                     57:     if ($r->uri eq '/adm/helpdesk') {
1.34      albertel   58:         &Apache::lonacc::get_posted_cgi($r);
1.12      raeburn    59:     }
1.70      raeburn    60:     my $function;
                     61:     if ($env{'form.function'}) {
                     62:         if (($env{'form.function'} eq 'norole')  ||
                     63:             ($env{'form.function'} eq 'student') ||
                     64:             ($env{'form.function'} eq 'admin')   ||
                     65:             ($env{'form.function'} eq 'author')) {
                     66:             $function = $env{'form.function'};
                     67:         }
                     68:     }
1.60      raeburn    69:     my $origurl = $env{'form.origurl'};
1.70      raeburn    70:     $origurl =~ s{^https?://}{};
                     71:     $origurl =~ s/(`)//g;
                     72:     $origurl =~ s/\$/\(\$\)/g;
1.44      raeburn    73:     my $command = $env{'form.command'};
1.12      raeburn    74: 
1.44      raeburn    75:     if ($command eq 'process') {
1.1       raeburn    76:         &print_request_receipt($r,$origurl,$function);
                     77:     } else {
                     78:         &print_request_form($r,$origurl,$function);
                     79:     }
                     80:     return OK;
                     81: }
                     82:     
                     83: sub print_request_form {
                     84:     my ($r,$origurl,$function) = @_;
1.61      raeburn    85:     my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,
                     86:         $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server,
1.79.2.1! raeburn    87:         $formname,$public,$homeserver,$knownuser,$captcha_form,$captcha_error,
        !            88:         $captcha,$recaptcha_version);
1.44      raeburn    89:     $function = &Apache::loncommon::get_users_function() if (!$function);
1.10      raeburn    90:     $ccode = '';
1.25      albertel   91:     $os = $env{'browser.os'};
                     92:     $browser = $env{'browser.type'};
                     93:     $bversion = $env{'browser.version'};
                     94:     $uhost = $env{'request.host'};
1.60      raeburn    95:     if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
                     96:         $public = 1;
                     97:     } else {
1.67      raeburn    98:         if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
                     99:             $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
                    100:                                                       $env{'user.domain'});
                    101:             if ($homeserver eq 'no_host') {
                    102:                 undef($homeserver); 
                    103:             } else {
                    104:                 $uname = $env{'user.name'};
                    105:                 $udom = $env{'user.domain'};
                    106:             }
                    107:         }
                    108:     }
1.79.2.1! raeburn   109:     if (($env{'user.name'} =~ /^$match_username$/) &&
        !           110:         ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
        !           111:         $knownuser = 1;
        !           112:     } else {
        !           113:         my $lonhost = $r->dir_config('lonHostID');
        !           114:         ($captcha_form,$captcha_error,$captcha,$recaptcha_version) =
        !           115:             &Apache::loncommon::captcha_display('login',$lonhost);
        !           116:     }
1.67      raeburn   117:     if ($homeserver) {
                    118:         $uhome = $env{'user.home'};
                    119:         $urole = $env{'request.role'};
                    120:         $usec = $env{'request.course.sec'};
                    121:         $cid = $env{'request.course.id'};
1.56      raeburn   122:     }
1.29      raeburn   123:     $formname = 'logproblem';
1.40      raeburn   124:     my $machine = &Apache::lonnet::absolute_url();
1.70      raeburn   125:     my $sourceurl = $machine.$origurl;
1.74      raeburn   126:     $server = $machine.&Apache::loncommon::cleanup_html($origurl);
1.70      raeburn   127:     $server =~ s/\?.*$//;
1.79      damieng   128:     my %js_lt = &Apache::lonlocal::texthash (
1.40      raeburn   129:                   email => 'The e-mail address you entered',
                    130:                   notv => 'is not a valid e-mail address',
                    131:                   rsub => 'You must include a subject',
                    132:                   rdes => 'You must include a description',
1.79      damieng   133:     );
                    134:     my %html_lt = &Apache::lonlocal::texthash (
1.40      raeburn   135:                   name => 'Name',
                    136:                   subm => 'Submit Request',
1.46      raeburn   137:                   emad => 'Your e-mail address',
                    138:                   emac => 'Cc', 
1.40      raeburn   139:                   unme => 'username',
                    140:                   doma => 'domain',
1.44      raeburn   141:                   entu => 'Enter the username you use to log-in to LON-CAPA',
                    142:                   chdo => 'Choose your LON-CAPA domain',
                    143:                   entr => 'Enter the username you use to log-in to LON-CAPA, and your domain.',
1.40      raeburn   144:                   urlp => 'URL of page',
                    145:                   phon => 'Phone',
                    146:                   crsd => 'Course Details',
                    147:                   enin => 'Enter institutional course code',
                    148:                   pick => 'Pick',
                    149:                   enct => 'Enter course title',
                    150:                   secn => 'Section Number',
                    151:                   sele => 'Select',
                    152:                   titl => 'Title',
                    153:                   lsec => 'LON-CAPA sec',
                    154:                   subj => 'Subject',
                    155:                   detd => 'Detailed Description',
                    156:                   opfi => 'Optional file upload',
1.44      raeburn   157:                   uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (128 KB max.)',
1.40      raeburn   158:                   fini => 'Finish',
                    159:                   clfm => 'Clear Form',
                    160:     );
1.79      damieng   161:     &js_escape(\%js_lt);
                    162:     &html_escape(\%html_lt);
1.40      raeburn   163:     my $scripttag = (<<"END");
1.5       raeburn   164: function validate() {
1.13      raeburn   165:     if (validmail(document.logproblem.email) == false) {
1.79      damieng   166:         alert("$js_lt{'email'}: "+document.logproblem.email.value+" $js_lt{'notv'}.");
1.40      raeburn   167:         return;
                    168:     }
                    169:     if (document.logproblem.subject.value == '') {
1.79      damieng   170:         alert("$js_lt{'rsub'}.");
1.40      raeburn   171:         return;
                    172:     }
                    173:     if (document.logproblem.description.value == '') {
1.79      damieng   174:         alert("$js_lt{'rdes'}.");
1.13      raeburn   175:         return;
1.5       raeburn   176:     }
                    177:     document.logproblem.submit();
                    178: }
1.13      raeburn   179: 
1.40      raeburn   180: END
1.43      raeburn   181:     $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
1.44      raeburn   182:     if ($cid) {
                    183:         $cdom = $env{'course.'.$cid.'.domain'};
                    184:         $cnum = $env{'course.'.$cid.'.num'};
1.1       raeburn   185:     }
                    186:     if ($cdom && $cnum) {
                    187:         my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
                    188:         $ctitle = $csettings{'description'};
                    189:         $ccode = $csettings{'internal.coursecode'};
                    190:         $sectionlist = $csettings{'internal.sectionnums'};
                    191:     }
1.44      raeburn   192: 
1.67      raeburn   193:     if ($homeserver) {
                    194:         if ($env{'environment.permanentemail'}) {
                    195:             $email = $env{'environment.permanentemail'};
                    196:         } elsif ($env{'environment.critnotification'}) {
                    197:             $email = $env{'environment.critnotification'};
                    198:         } elsif ($env{'environment.notification'}) {
                    199:             $email = $env{'environment.notification'};
                    200:         }
                    201:         if ($env{'environment.lastname'}) {
                    202:             $lastname = $env{'environment.lastname'};
                    203:         }
                    204:         if ($env{'environment.firstname'}) {
                    205:             $firstname = $env{'environment.firstname'};
                    206:         }
1.1       raeburn   207:     }
1.40      raeburn   208:     my @sections = split(/,/,$sectionlist);
                    209:     my %groupid;
                    210:     foreach my $section (@sections) {
                    211:         my ($sec,$grp) = split(/:/,$section);
1.1       raeburn   212:         $groupid{$sec} = $grp;
                    213:     }
1.60      raeburn   214:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom',
                    215:                                                  'useremail','useraccount']);
                    216:     if ($env{'form.origurl'} eq '/adm/createaccount') {
                    217:         if ($email eq '') {
                    218:             if ($env{'form.useremail'} =~ /^[^\@]+\@[^\@]+$/) {
                    219:                 $email = &HTML::Entities::encode($env{'form.useremail'},'"<>&');
                    220:             }
                    221:         }
                    222:         if ($uname eq '') {
                    223:             if ($env{'form.useraccount'} =~ /^$match_username$/) {
                    224:                 $uname = &HTML::Entities::encode($env{'form.useraccount'},'"<>&');
                    225:             }
                    226:         }
                    227:     }
1.45      raeburn   228:     my $codedom = &get_domain();
1.21      raeburn   229:     my $details_title;
                    230:     if ($codedom) {
                    231:         $details_title = '<br />('.$codedom.')';
                    232:     }
1.40      raeburn   233:     my %coursecodes;
                    234:     my %codes;
                    235:     my @codetitles;
                    236:     my %cat_titles;
                    237:     my %cat_order;
                    238:     my %idlist;
                    239:     my %idnums;
                    240:     my %idlist_titles;
1.1       raeburn   241:     my $caller = 'global';
                    242:     my $totcodes = 0;
                    243:     my $format_reply;
1.6       raeburn   244:     my $jscript = '';
1.22      raeburn   245:     my $loaditems = qq|
                    246: function initialize_codes() {
                    247:     return;
                    248: }
                    249:     |;
1.1       raeburn   250:     if ($cnum) {
                    251:         $coursecodes{$cnum} = $ccode;
                    252:         if ($ccode eq '') {
1.38      raeburn   253:             $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
1.1       raeburn   254:         } else {
                    255:             $coursecodes{$cnum} = $ccode;
                    256:             $caller = $cnum;
                    257:             $totcodes ++;
                    258:         }
                    259:     } else { 
1.38      raeburn   260:         $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
1.1       raeburn   261:     }
                    262:     if ($totcodes > 0) {
1.6       raeburn   263:         if ($ccode eq '') {
1.22      raeburn   264:             $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
                    265:             if ($format_reply eq 'ok') {
                    266:                 my $numtypes = @codetitles;
1.38      raeburn   267:                 &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
                    268:                 my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
                    269:                 my $longtitles_str = join('","',@{$longtitles});
                    270:                 my $allidlist = $idlist{$codetitles[0]};
                    271:                 $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
                    272:                 $jscript .= $scripttext;
                    273:                 $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
1.22      raeburn   274:                 $loaditems = '';
                    275:             }
1.6       raeburn   276:         }
1.1       raeburn   277:     }
1.30      albertel  278: 	
1.67      raeburn   279:     my $js = <<"ENDJS";
                    280: <script type="text/javascript">
                    281: // <![CDATA[
                    282: $scripttag
                    283: $jscript
                    284: $loaditems
                    285: // ]]>
                    286: </script>
                    287: ENDJS
1.79.2.1! raeburn   288:     if ($recaptcha_version >=2) {
        !           289:         $js.= "\n".'<script src="https://www.google.com/recaptcha/api.js"></script>'."\n";
        !           290:     }
1.67      raeburn   291:     my %add_entries = (
                    292:                        style    => "margin-top:0px;margin-bottom:0px;",
                    293:                        onload   => "initialize_codes();",
                    294:                       );
1.33      albertel  295: 
1.44      raeburn   296:     
                    297:     $r->print(&Apache::loncommon::start_page('Support Request',$js,
1.31      albertel  298: 				       { 'function'    => $function,
1.33      albertel  299: 					 'add_entries' => \%add_entries,
1.44      raeburn   300: 					 'only_body'   => 1,}));
1.15      raeburn   301:     if ($r->uri eq '/adm/helpdesk') {
1.14      raeburn   302:         &print_header($r,$origurl);
                    303:     }
1.50      raeburn   304:     my @css = ('LC_evenrow_value','LC_oddrow_value');
                    305:     my $num = 1;
                    306:     my $i = $num%2;
1.67      raeburn   307:     my $formtype;
                    308:     if ($homeserver) {
                    309:         $formtype = ' enctype="multipart/form-data"';
                    310:     }
                    311:     $r->print('<form method="post" action="" name="logproblem"'.$formtype.'>'."\n");
1.44      raeburn   312:     my $output = &Apache::lonhtmlcommon::start_pick_box().
1.78      bisitz    313:                  &Apache::lonhtmlcommon::row_headline().
                    314:                  '<span class="LC_info">'.
                    315:                  &mt('(All fields marked with * are required.)').
                    316:                  '</span>'.
                    317:                  &Apache::lonhtmlcommon::row_closure().
1.79      damieng   318:                  &Apache::lonhtmlcommon::row_title($html_lt{'name'},undef,$css[$num])."\n";
1.1       raeburn   319:     my $fullname = '';
                    320:     if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
                    321:         $fullname = "$firstname $lastname"; 
1.67      raeburn   322:         $output .= $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
1.1       raeburn   323:     } else {
                    324:         if (defined($firstname) && $firstname ne '') {
                    325:             $fullname = $firstname;
                    326:         } elsif (defined($lastname) && $lastname ne '') {
1.44      raeburn   327:             $fullname = " $lastname";
1.1       raeburn   328:         }
1.67      raeburn   329:         $output .= '<input type="text" size="20" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
1.1       raeburn   330:     }
1.79      damieng   331:     $output .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="'.$html_lt{'subm'}.'" onclick="validate()" />&nbsp;'.
1.50      raeburn   332:                 &Apache::lonhtmlcommon::row_closure()."\n";
                    333:     $num ++;
                    334:     $i = $num%2;
1.78      bisitz    335:     $output .= &Apache::lonhtmlcommon::row_title(
                    336:                    '<span title="'.&mt('required').'">'.
1.79      damieng   337:                    $html_lt{'emad'}.' <span class="LC_info">*</span></span>'
1.78      bisitz    338:                   ,undef,$css[$i]).
1.50      raeburn   339:                '<input type="text" size="20" name="email" value="'.
                    340:                &HTML::Entities::encode($email,'"<>&').'" /><br />'."\n".
                    341:                &Apache::lonhtmlcommon::row_closure();
                    342:     $num ++;
                    343:     $i = $num%2;
1.79.2.1! raeburn   344:     if ($knownuser) {
1.67      raeburn   345:         if ($homeserver) { 
1.79      damieng   346:             $output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]).
1.67      raeburn   347:                        '<input type="text" size="50" name="cc" value="" /><br />'."\n".
                    348:                        &Apache::lonhtmlcommon::row_closure();
                    349:             $num ++;
                    350:             $i = $num%2;
                    351:         }
1.50      raeburn   352:     }
1.79      damieng   353:     $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]);
1.44      raeburn   354:     my $udom_input = '<input type="hidden" name="udom" value="'.
1.67      raeburn   355:                      &HTML::Entities::encode($udom,'"<>&').'" />'."\n";
1.44      raeburn   356:     my $uname_input = '<input type="hidden" name="uname" value="'.
1.67      raeburn   357:                       &HTML::Entities::encode($uname,'"<>&').'" />'."\n"; 
1.79.2.1! raeburn   358:     if ($knownuser) {
1.79      damieng   359:         $output .= '<i>'.$html_lt{'unme'}.'</i>:&nbsp;'.$uname.'&nbsp;&nbsp;<i>'.$html_lt{'doma'}.'</i>:&nbsp;'.$udom.$udom_input.$uname_input;
1.1       raeburn   360:     } else {
                    361:         my $udomform = '';
                    362:         my $unameform = '';
1.60      raeburn   363:         if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
1.79      damieng   364:             $output .= $html_lt{'entu'};
1.60      raeburn   365:         } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { 
1.79      damieng   366:             $output .= $html_lt{'chdo'};
1.44      raeburn   367:         } else {
1.79      damieng   368:             $output .= $html_lt{'entr'};
1.44      raeburn   369:         }
1.67      raeburn   370:         $output .= '<br />'."\n";
1.60      raeburn   371:         if (!$public) {
                    372:             if ($env{'user.domain'} =~ /^$match_domain$/) {
1.79      damieng   373:                 $udomform = '<i>'.$html_lt{'doma'}.'</i>:&nbsp;'.$udom.$udom_input;
1.60      raeburn   374:             } elsif ($env{'user.name'} =~ /^$match_username$/) {
1.79      damieng   375:                 $unameform = '<i>'.$html_lt{'unme'}.'</i>:&nbsp;'.$uname.'&nbsp;&nbsp;'.$uname_input;
1.60      raeburn   376:             }
1.1       raeburn   377:         }
                    378:         if ($udomform eq '') {
1.79      damieng   379:             $udomform = '<i>'.$html_lt{'doma'}.'</i>:&nbsp;';
1.67      raeburn   380:             $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom')."\n";
1.1       raeburn   381:         }
                    382:         if ($unameform eq '') {
1.79      damieng   383:             $unameform= '<i>'.$html_lt{'unme'}.'</i>:&nbsp;<input type="text" size="20" name="uname" value="'.$uname.'" />&nbsp;&nbsp;';
1.1       raeburn   384:         }
1.44      raeburn   385:         $output .= $unameform.$udomform;
1.1       raeburn   386:     }
1.50      raeburn   387:     $output .= &Apache::lonhtmlcommon::row_closure();
                    388:     $num ++;
                    389:     $i = $num%2;
1.79      damieng   390:     $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]).
1.70      raeburn   391:                $server."\n".'<input type="hidden" name="sourceurl" value="'.
                    392:                &HTML::Entities::encode($sourceurl,'"<>&').'" />'."\n".
1.44      raeburn   393:                &Apache::lonhtmlcommon::row_closure().
1.79      damieng   394:                &Apache::lonhtmlcommon::row_title("$html_lt{'phon'}",undef,'LC_evenrow_value').
1.67      raeburn   395:                '<input type="text" size="15" name="phone" /><br />'."\n".
1.50      raeburn   396:                &Apache::lonhtmlcommon::row_closure();
                    397:     $num ++;
                    398:     $i = $num%2; 
1.79      damieng   399:     $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'crsd'}$details_title",undef,$css[$i]);
1.46      raeburn   400:     if ($cnum) {
1.10      raeburn   401:         if ($coursecodes{$cnum}) {
1.40      raeburn   402:             foreach my $item (@codetitles) {
1.44      raeburn   403:                 $output .= '<i>'.$item.'</i>:&nbsp;'.$codes{$cnum}{$item}.';&nbsp;';
1.10      raeburn   404:             }
1.67      raeburn   405:             $output .= '&nbsp;<input type="hidden" name="coursecode" value="'.&HTML::Entities::encode($coursecodes{$cnum},'"<>&').'" />'."\n";
1.10      raeburn   406:         } else {
1.79      damieng   407:             $output .= $html_lt{'enin'}.':&nbsp;
1.67      raeburn   408:                   <input type="text" name="coursecode" size="15" value="" />'."\n";
1.1       raeburn   409:         }
                    410:     } else {
1.10      raeburn   411:         if ($totcodes > 0) {
                    412:             my $numtitles = @codetitles;
                    413:             if ($numtitles == 0) {
1.79      damieng   414:                 $output .= $html_lt{'enin'}.':&nbsp;
1.67      raeburn   415:                   <input type="text" name="coursecode" size="15" value="" />'."\n";
1.10      raeburn   416:             } else {
1.57      raeburn   417:                 my @standardnames = &Apache::loncommon::get_standard_codeitems();
1.10      raeburn   418:                 my $lasttitle = $numtitles;
                    419:                 if ($numtitles > 4) {
                    420:                     $lasttitle = 4;
                    421:                 } 
1.44      raeburn   422:                 $output .= '<table><tr><td>'.$codetitles[0].'<br />'."\n".
1.57      raeburn   423:                       '<select name="'.$standardnames[0].'" onchange="courseSet('."'$codetitles[0]'".')">'."\n".
1.79      damieng   424:                       ' <option value="-1">'.$html_lt{'sele'}."</option>\n";
1.10      raeburn   425:                 my @items = ();
1.20      raeburn   426:                 my @longitems = ();
1.10      raeburn   427:                 if ($idlist{$codetitles[0]} =~ /","/) {
1.40      raeburn   428:                     @items = split(/","/,$idlist{$codetitles[0]});
1.10      raeburn   429:                 } else {
                    430:                     $items[0] = $idlist{$codetitles[0]};
                    431:                 }
1.20      raeburn   432:                 if (defined($idlist_titles{$codetitles[0]})) {
                    433:                     if ($idlist_titles{$codetitles[0]} =~ /","/) {
1.40      raeburn   434:                         @longitems = split(/","/,$idlist_titles{$codetitles[0]});
1.20      raeburn   435:                     } else {
                    436:                         $longitems[0] = $idlist_titles{$codetitles[0]};
                    437:                     }
1.22      raeburn   438:                     for (my $i=0; $i<@longitems; $i++) {
                    439:                         if ($longitems[$i] eq '') {
                    440:                             $longitems[$i] = $items[$i];
                    441:                         }
                    442:                     }
1.20      raeburn   443:                 } else {
                    444:                     @longitems = @items;
                    445:                 }
                    446:                 for (my $i=0; $i<@items; $i++) {
1.44      raeburn   447:                     $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>'."\n";
1.10      raeburn   448:                 }
1.44      raeburn   449:                 $output .= '</select></td>';
1.10      raeburn   450:                 for (my $i=1; $i<$numtitles; $i++) {
1.44      raeburn   451:                     $output .= '<td>'.$codetitles[$i].'<br />'."\n".
1.57      raeburn   452:                      '<select name="'.$standardnames[$i].'" onchange="courseSet('."'$codetitles[$i]'".')">'."\n".
1.79      damieng   453:                      '<option value="-1">&lt;-'.$html_lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
1.10      raeburn   454:                      '</select>'."\n".
1.44      raeburn   455:                      '</td>'."\n";
1.10      raeburn   456:                 }
1.44      raeburn   457:                 $output .= '</tr></table>';
1.10      raeburn   458:                 if ($numtitles > 4) {
1.44      raeburn   459:                     $output .= '<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
1.57      raeburn   460:                           '<select name="'.$standardnames[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
1.79      damieng   461:                           '<option value="-1">&lt;-'.$html_lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
1.44      raeburn   462:                           '</select>'."\n";
1.10      raeburn   463:                 }
                    464:             }
                    465:         } else {
1.79      damieng   466:             $output .= $html_lt{'enin'}.':&nbsp;
1.67      raeburn   467:                   <input type="text" name="coursecode" size="15" value="" />'."\n";
1.10      raeburn   468:         }
1.1       raeburn   469:     }
                    470:     if ($ctitle) {
1.79      damieng   471:         $output .= '<br /><i>'.$html_lt{'titl'}.'</i>:&nbsp;'.$ctitle.
1.44      raeburn   472:                    '<input type="hidden" name="title" value="'.
                    473:                    &HTML::Entities::encode($ctitle,'"<>&').'" />'."\n";
1.1       raeburn   474:     } else {
1.79      damieng   475:         $output .= '<br />'.$html_lt{'enct'}.':&nbsp;
1.44      raeburn   476:                  <input type="text" name="title" size="25" value="" />'."\n";
1.1       raeburn   477:     }
1.50      raeburn   478:     $output .= &Apache::lonhtmlcommon::row_closure();
                    479:     $num ++;
                    480:     $i = $num%2;
1.79      damieng   481:     $output .= &Apache::lonhtmlcommon::row_title($html_lt{'secn'},undef,$css[$i]);
1.1       raeburn   482:     if ($sectionlist) {
1.44      raeburn   483:         $output .= "<select name=\"section\"\n>".
1.79      damieng   484:                    "  <option value=\"\" selected=\"selected\">$html_lt{'sele'}</option>\n";
1.40      raeburn   485:         foreach my $id (sort(keys(%groupid))) {
                    486:             if ($id eq $groupid{$id} || $groupid{$id} eq '') {
1.44      raeburn   487:                 $output .= "  <option value=".
                    488:                            &HTML::Entities::encode($id,'"<>&').
                    489:                            " >$id</option>\n";
1.1       raeburn   490:             } else {
1.44      raeburn   491:                 $output .= "  <option value=".
                    492:                            &HTML::Entities::encode($id,'"<>&').
1.79      damieng   493:                            " >$id - ($html_lt{'lsec'}: $groupid{$id})</option>\n";
1.1       raeburn   494:             }
                    495:         }
1.44      raeburn   496:         $output .= "</select>";
1.1       raeburn   497:     } else {
1.67      raeburn   498:         $output .= '<input type="text" name="section" size="10" />'."\n";
1.1       raeburn   499:     }
1.50      raeburn   500:     $output .= &Apache::lonhtmlcommon::row_closure();
                    501:     $num ++;
                    502:     $i = $num%2; 
1.78      bisitz    503:     $output .= &Apache::lonhtmlcommon::row_title(
                    504:                    '<span title="'.&mt('required').'">'.
1.79      damieng   505:                    $html_lt{'subj'}.' <span class="LC_info">*</span></span>'
1.78      bisitz    506:                   ,undef,'LC_oddrow_value').
                    507:                '<input type="text" size="40" name="subject" />'."\n".
1.44      raeburn   508:                &Apache::lonhtmlcommon::row_closure().
1.78      bisitz    509:                &Apache::lonhtmlcommon::row_title(
                    510:                    '<span title="'.&mt('required').'">'.
1.79      damieng   511:                    $html_lt{'detd'}.' <span class="LC_info">*</span></span>'
1.78      bisitz    512:                   ,undef,'LC_evenrow_value').
                    513:                '<textarea rows="10" cols="45" name="description" style="word-wrap:normal;">'.
1.67      raeburn   514:                '</textarea>'."\n".
1.44      raeburn   515:                &Apache::lonhtmlcommon::row_closure();
1.50      raeburn   516:     $num ++;
                    517:     $i = $num%2; 
1.79.2.1! raeburn   518:     if ($knownuser) {
1.67      raeburn   519:         if ($homeserver) {
1.79      damieng   520:             $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i]).
1.67      raeburn   521:                        ' <input type="file" name="screenshot" size="20" /><br />'.
1.79      damieng   522:                        "\n".$html_lt{'uplf'}."\n".
1.67      raeburn   523:                        &Apache::lonhtmlcommon::row_closure();
                    524:             $num ++;
                    525:             $i = $num%2;
                    526:         }
1.69      raeburn   527:     } else {
1.79.2.1! raeburn   528:         if ($captcha_form) {
1.78      bisitz    529:             $output .= &Apache::lonhtmlcommon::row_title(
                    530:                            '<span title="'.&mt('required').'">'.
                    531:                            &mt('Validation').
                    532:                            ' <span class="LC_info">*</span></span>'
                    533:                       ,undef,$css[$i]).
1.79.2.1! raeburn   534:                        $captcha_form."\n".
1.69      raeburn   535:                        &Apache::lonhtmlcommon::row_closure();
                    536:             $num ++;
                    537:             $i = $num%2;
                    538:         }
1.5       raeburn   539:     }
1.79      damieng   540:     $output .= &Apache::lonhtmlcommon::row_title($html_lt{'fini'},undef,$css[$i]);
1.44      raeburn   541:     $output .= <<END;
1.1       raeburn   542:              <table border="0" cellpadding="8" cellspacing="0">
                    543:               <tr>
                    544:                <td>
1.44      raeburn   545:                 <input type="hidden" name="command" value="process" />
1.79      damieng   546:                 <input type="button" value="$html_lt{'subm'}" onclick="validate()" /> &nbsp;
1.1       raeburn   547:                </td>
                    548:                <td>&nbsp;</td>
                    549:                <td>
1.79      damieng   550:                 <input type="reset" value="$html_lt{'clfm'}" />
1.1       raeburn   551:                </td>
                    552:               </tr>
                    553:              </table>
1.44      raeburn   554: END
                    555:     $output .= &Apache::lonhtmlcommon::row_closure(1);
                    556:     $output .= &Apache::lonhtmlcommon::end_pick_box();
                    557:     $r->print(<<END);
                    558: $output
1.14      raeburn   559: </form>
1.44      raeburn   560: <br />
1.1       raeburn   561: END
1.30      albertel  562:     $r->print(&Apache::loncommon::end_page());
1.5       raeburn   563:     return;
1.1       raeburn   564: }
                    565: 
                    566: sub print_request_receipt {
                    567:     my ($r,$url,$function) = @_;
1.69      raeburn   568:     my $public;
                    569:     if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
                    570:         $public = 1;
                    571:     }
                    572:     unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
                    573:         my $lonhost = $r->dir_config('lonHostID');
                    574:         my ($captcha_chk,$captcha_error) = 
                    575:             &Apache::loncommon::captcha_response('login',$lonhost);
                    576:         if ($captcha_chk != 1) {
                    577:             $r->print(&Apache::loncommon::start_page('Support request failed',undef,
                    578:                                        {'function'    => $function,
                    579:                                         'add_entries' => {
                    580:                                             topmargin    => "0",
                    581:                                             marginheight => "0",
                    582:                                         },
                    583:                                         'only_body'   => 1,}));
                    584:             if ($r->uri eq '/adm/helpdesk') {
                    585:                 &print_header($r,$url,'process');
                    586:             }
1.75      bisitz    587:             $r->print(
                    588:                 '<h2>'.&mt('Support request failed').'</h2>'.
                    589:                       &Apache::lonhtmlcommon::confirm_success(
                    590:                         &mt('Validation of the code you entered failed.'),1).
                    591:                 '<br /><br />'.
                    592:                 &Apache::lonhtmlcommon::actionbox([
                    593:                     &mt('[_1]Go back[_2] and try again',
                    594:                         '<a href="javascript:history.go(-1)">','</a>')]).
1.69      raeburn   595:                       &Apache::loncommon::end_page());
                    596:             return;
                    597:         }
                    598:     }
1.26      raeburn   599:     my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');
                    600:     my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
1.5       raeburn   601:     my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
1.27      raeburn   602:     my @cookievars = ('lonID');
1.5       raeburn   603: 
                    604:     my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
1.45      raeburn   605:     my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
                    606:     my $defdom = &get_domain();
                    607:     my $to = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
                    608:                                                       $defdom,$origmail);
1.5       raeburn   609:     my $from = $admin;
1.56      raeburn   610:     my $bcc;
                    611:     my %domconfig =
                    612:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                    613:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                    614:         if (exists($domconfig{'contacts'}{'helpdeskmail'})) {
                    615:             if (ref($domconfig{'contacts'}{'helpdeskmail'}) eq 'HASH') {
                    616:                 my $bccmail = $domconfig{'contacts'}{'helpdeskmail'}{'bcc'};
                    617:                 if ($bccmail ne '') {
                    618:                     my @bccs = split(/,/,$bccmail);
                    619:                     my @ok_bccs;
                    620:                     foreach my $bcc (@bccs) {
                    621:                         $bcc =~ s/^\s+//g;
                    622:                         $bcc =~ s/\s+$//g;
                    623:                         if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
                    624:                             if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
                    625:                                 push(@ok_bccs,$bcc);
                    626:                             }
                    627:                         }
                    628:                     }
                    629:                     if (@ok_bccs > 0) {
                    630:                         $bcc = join(', ',@ok_bccs);
                    631:                     }
                    632:                 }
                    633:             }
                    634:         }
                    635:     }
1.1       raeburn   636:     my $reporttime = &Apache::lonlocal::locallocaltime(time);
1.14      raeburn   637:     my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot');
1.20      raeburn   638: 
1.1       raeburn   639:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
1.25      albertel  640:     my $coursecode = $env{'form.coursecode'};
1.19      raeburn   641:     if ($coursecode eq '') {
1.57      raeburn   642:         my $totcodes = 0;
                    643:         my %coursecodes;
                    644:         $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$defdom,$totcodes);
                    645:         my @standardnames = &Apache::loncommon::get_standard_codeitems();
                    646:         if ($totcodes > 0) {
1.64      raeburn   647:             my $noregexps = 1;
                    648:             $coursecode = 
                    649:                 &Apache::courseclassifier::instcode_from_selectors($defdom,$noregexps);
1.57      raeburn   650:         } 
                    651:         if ($coursecode eq '') {
                    652:             foreach my $item (@standardnames) {
                    653:                 if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) {
                    654:                     $coursecode .= $env{'form.'.$item};
                    655:                 }
                    656:             }
1.19      raeburn   657:         }
                    658:     }
1.40      raeburn   659:     my %lt = &Apache::lonlocal::texthash (
1.44      raeburn   660:                  username    => 'Name',
1.52      schafran  661:                  email       => 'E-mail',
1.46      raeburn   662:                  cc          => 'Cc',
1.44      raeburn   663:                  user        => 'Username/domain',
                    664:                  phone       => 'Phone',
                    665:                  crsi        => 'Course Information',
                    666:                  subject     => 'Subject',
                    667:                  description => 'Description',
                    668:                  sourceurl   => 'URL',
                    669:                  date        => 'Date/Time',
                    670:                  secn        => 'Section',
                    671:                  warn        => 'Warning: Problem with support e-mail address',
                    672:                  your        => 'Your support request contained the following information',
                    673:                  sect        => 'section',
                    674:                  info        => 'Information supplied',
                    675:                  adin        => 'Additional information recorded',
1.40      raeburn   676:     );
1.46      raeburn   677: 
1.72      raeburn   678:     my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist,$homeserver);
                    679:     unless ($public) {
1.67      raeburn   680:         if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
                    681:             $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
                    682:                                                       $env{'user.domain'});
                    683:         }
                    684:     }
                    685: 
                    686:     if (($homeserver) && (defined($env{'form.cc'}))) {
1.46      raeburn   687:         my @ccs;
                    688:         if ($env{'form.cc'} =~ /,/) {
                    689:             @ccs = split(/,/,$env{'form.cc'});
                    690:         } else {
                    691:             $env{'form.cc'} =~ s/^\s+//;
                    692:             $env{'form.cc'} =~ s/\s+$//;
                    693:             @ccs = $env{'form.cc'};
                    694:         }
                    695:         foreach my $cc (@ccs) {
                    696:             $cc =~ s/^\s+//g;
                    697:             $cc =~ s/\s+$//g;
                    698:             if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
                    699:                 if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
                    700:                     push(@ok_ccs,$cc);
                    701:                 }
1.57      raeburn   702:             } elsif ($cc ne '') {
1.46      raeburn   703:                 if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
                    704:                     push(@bad_ccs,$cc);
                    705:                 }
                    706:             }
                    707:         }
                    708:         if (@ok_ccs > 0) {
                    709:            $okcclist = join(', ',@ok_ccs); 
                    710:         } 
                    711:         if (@bad_ccs == 1) {
1.71      raeburn   712:             if ($bad_ccs[0] ne '') {
1.74      raeburn   713:                 $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').&Apache::loncommon::cleanup_html($bad_ccs[0]);
1.71      raeburn   714:             }
1.46      raeburn   715:         } elsif (@bad_ccs > 1) {
1.74      raeburn   716:             $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: '). &Apache::loncommon::cleanup_html(join(', ',@bad_ccs));
1.46      raeburn   717:         }
                    718:     }
1.44      raeburn   719:     $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
1.57      raeburn   720:     $env{'form.crsi'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'};
1.44      raeburn   721:     my $supportmsg = <<END;
                    722: $lt{'username'}: $env{'form.username'}
1.40      raeburn   723: $lt{'email'}: $env{'form.email'}
1.46      raeburn   724: $lt{'cc'}: $okcclist
1.44      raeburn   725: $lt{'user'}: $env{'form.user'}
                    726: $lt{'phone'}: $env{'form.phone'}
1.57      raeburn   727: $lt{'crsi'}: $env{'form.crsi'}
1.44      raeburn   728: $lt{'subject'}: $env{'form.subject'}
                    729: $lt{'description'}: $env{'form.description'}
                    730: $lt{'sourceurl'}: $env{'form.sourceurl'}
1.40      raeburn   731: $lt{'date'}: $reporttime
1.1       raeburn   732: 
1.44      raeburn   733: END
                    734:     my $displaymsg;
1.46      raeburn   735:     foreach my $item ('username','email','cc','user','phone','crsi','subject','description','sourceurl') {
1.44      raeburn   736:         if ($env{'form.'.$item} ne '') {
                    737:             if ($item eq 'description') {
                    738:                 my $descrip = $env{'form.description'};
1.74      raeburn   739:                 $descrip =  &Apache::loncommon::cleanup_html($descrip);
1.54      raeburn   740:                 $descrip =~ s|[\n\r\f]|<br />|g;
1.44      raeburn   741:                 $displaymsg .= 
                    742:                     '<span class="LC_helpform_receipt_cat">'.
                    743:                     "$lt{$item}</span>: $descrip<br />\n";
                    744:             } elsif ($item eq 'sourceurl') {
                    745:                 my $showurl = $env{'form.sourceurl'};
                    746:                 $showurl =~ s/\?.*$//;
1.74      raeburn   747:                 $showurl =  &Apache::loncommon::cleanup_html($showurl);
1.44      raeburn   748:                 $displaymsg .= 
                    749:                     '<span class="LC_helpform_receipt_cat">'.
                    750:                     "$lt{$item}</span>: $showurl<br />\n";
1.46      raeburn   751:             } elsif ($item eq 'cc') {
1.71      raeburn   752:                 if ($okcclist) {
1.74      raeburn   753:                     my $showcclist = &Apache::loncommon::cleanup_html($okcclist);
1.71      raeburn   754:                     $displaymsg .=
                    755:                         '<span class="LC_helpform_receipt_cat">'.
                    756:                         "$lt{$item}</span>: $showcclist<br />\n";
                    757:                 }
1.44      raeburn   758:             } else {
1.54      raeburn   759:                 my $showitem = $env{'form.'.$item};
1.74      raeburn   760:                 $showitem = &Apache::loncommon::cleanup_html($showitem);
1.44      raeburn   761:                 $displaymsg .= 
                    762:                     '<span class="LC_helpform_receipt_cat">'.
1.54      raeburn   763:                     "$lt{$item}</span>: $showitem<br />\n";
1.44      raeburn   764:             }
                    765:         }
                    766:     }
                    767:     $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
                    768:                    $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
1.32      albertel  769: 
                    770:     my $start_page = 
                    771: 	&Apache::loncommon::start_page('Support request recorded',undef,
1.33      albertel  772: 				       {'function'    => $function,
                    773: 					'add_entries' => {
                    774: 					    topmargin    => "0",
                    775: 					    marginheight => "0",
                    776: 					},
                    777: 					'only_body'   => 1,});
1.32      albertel  778: 
1.14      raeburn   779:     $r->print(<<"END");
1.32      albertel  780: $start_page
1.73      bisitz    781: <form name="logproblem" action="">
1.44      raeburn   782: <input type="hidden" name="command" value="result" />
1.16      raeburn   783: </form>
1.1       raeburn   784: END
1.14      raeburn   785:     if ($r->uri eq '/adm/helpdesk') {
                    786:         &print_header($r,$url,'process');
                    787:     }
1.45      raeburn   788:     my $bad_email = 0;
                    789:     if ($to =~ /,/) {
                    790:         my @ok_email; 
                    791:         foreach my $email (split(/,/,$to)) {
                    792:             if ($email =~ m/^[^\@]+\@[^\@]+$/) {
1.46      raeburn   793:                 if (!grep(/^\Q$email\E$/,@ok_email)) {
                    794:                     push(@ok_email,$email);
                    795:                 }
1.45      raeburn   796:             }
                    797:         }
                    798:         if (@ok_email > 0) {
                    799:             $to = join(',',@ok_email);
                    800:         } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
                    801:             $to = $admin;
                    802:         } else {
                    803:             $bad_email = 1;
                    804:         }
                    805:     } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
                    806:         if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
                    807:             $to = $admin;
1.9       raeburn   808:         } else {
1.45      raeburn   809:             $bad_email = 1;
                    810:         }
                    811:     }
1.66      bisitz    812: 
                    813:     my $message;
                    814:     if (!$bad_email) {
                    815:         $message = &Apache::lonhtmlcommon::confirm_success(
                    816:             &mt('A support request has been sent to [_1]','<tt>'.$to.'</tt>'));
                    817:     } else {
                    818:         $message = &Apache::lonhtmlcommon::confirm_success(
                    819:             $lt{'warn'}.'<br />'
                    820:            .&mt('As the e-mail address provided for this LON-CAPA server ([_1]) does not appear to be a valid e-mail address, your support request has [_2]not[_3] been sent to the LON-CAPA support staff or administrator at your institution.','<tt>'.$to.'</tt>','<b>','</b>')
                    821:            .' '.&mt('Instead a copy has been sent to the LON-CAPA support team at Michigan State University.'),1); 
                    822:         $to = 'helpdesk@lon-capa.org';
1.1       raeburn   823:     }
1.66      bisitz    824:     $r->print(&Apache::loncommon::confirmwrapper($message));
                    825: 
1.25      albertel  826:     if (defined($env{'form.email'})) {
1.46      raeburn   827:         $env{'form.email'} =~ s/^\s+//;
                    828:         $env{'form.email'} =~ s/\s+$//;
1.25      albertel  829:         if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
                    830:             $from = $env{'form.email'};
1.5       raeburn   831:         }
                    832:     }
                    833: 
1.46      raeburn   834:     if (defined($env{'form.cc'})) {
                    835:         if ($badccmsg) {
                    836:             $displaymsg .= $badccmsg;
                    837:         }
                    838:     }
                    839: 
1.25      albertel  840:     my $subject = $env{'form.subject'};
1.44      raeburn   841:     $subject =~ s/(`)/'/g;
                    842:     $subject =~ s/\$/\(\$\)/g;
                    843:     $supportmsg =~ s/(`)/'/g;
                    844:     $supportmsg =~ s/\$/\(\$\)/g;
                    845:     $displaymsg =~ s/(`)/'/g;
                    846:     $displaymsg =~ s/\$/\(\$\)/g;
1.5       raeburn   847:     my $fname;
                    848: 
                    849:     my $attachmentpath = '';
                    850:     my $attachmentsize = '';
1.72      raeburn   851:     if ((defined($env{'user.name'})) && (!$public)) {
1.67      raeburn   852:         if ($homeserver && $env{'form.screenshot.filename'}) {
1.25      albertel  853:             $attachmentsize = length($env{'form.screenshot'});
1.5       raeburn   854:             if ($attachmentsize > 131072) {
1.78      bisitz    855:                 $displaymsg .= '<br /><span class="LC_warning">'.
                    856:                                &mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.',$attachmentsize).'</span>';
1.5       raeburn   857:             } else {
                    858:                 $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
                    859:             }
                    860:         }
                    861:     }
                    862: 
1.40      raeburn   863:     my %cookies;
1.27      raeburn   864:     my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
1.39      albertel  865:     if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
1.27      raeburn   866:         $cookies{'lonID'} = $1;
                    867:     }
                    868: 
1.5       raeburn   869:     if ($attachmentpath =~ m-/([^/]+)$-) {
                    870:         $fname = $1;
1.51      bisitz    871:         $displaymsg .= '<br />'
                    872:                       .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].'
1.66      bisitz    873:                           ,'<span class="LC_filename">'.$fname.'</span>'
1.51      bisitz    874:                           ,$attachmentsize
                    875:                           ,$env{'user.name'}.':'.$env{'user.domain'}
                    876:                        );
1.5       raeburn   877:         $supportmsg .= "\n";
1.40      raeburn   878:         foreach my $var (@cookievars) {
                    879:             $supportmsg .= "$var: $cookies{$var}\n";
1.27      raeburn   880:         }
1.40      raeburn   881:         foreach my $var(@ENVvars) {
                    882:             $supportmsg .= "$var: $ENV{$var}\n";
1.26      raeburn   883:         }
1.40      raeburn   884:         foreach my $var (@envvars) {
                    885:             $supportmsg .= "$var: $env{$var}\n";
1.5       raeburn   886:         }
                    887:     }
                    888:  
                    889:     my $msg = MIME::Lite->new(
                    890:                  From    => $from,
                    891:                  To      => $to,
                    892:                  Subject => $subject,
                    893:                  Type    =>'TEXT',
                    894:                  Data    => $supportmsg,
                    895:                  );
1.67      raeburn   896:     if ($homeserver) {
                    897:         if (@ok_ccs > 0) {
                    898:             my $cc_string = join(', ',@ok_ccs);
                    899:             $msg->add("Cc" => $cc_string);
                    900:         }
1.46      raeburn   901:     }
1.56      raeburn   902:     if ($bcc ne '') {
                    903:         $msg->add("Bcc" => $bcc);
                    904:     }
1.65      raeburn   905:     $msg->attr("content-type"         => "text/plain");
                    906:     $msg->attr("content-type.charset" => "UTF-8");
1.5       raeburn   907: 
1.67      raeburn   908:     if ($homeserver && $attachmentpath) {
1.5       raeburn   909:         my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
                    910:         $msg->attach(Type     => $type,
                    911:                      Path     => $attachmentpath,
                    912:                      Filename => $fname
                    913:                      );
                    914: 
                    915:     } else {
                    916:         my $envdata = '';
1.40      raeburn   917:         foreach my $var (@cookievars) {
                    918:             $envdata .= "$var: $cookies{$var}\n";
1.27      raeburn   919:         }
1.40      raeburn   920:         foreach my $var (@ENVvars) {
                    921:             $envdata .= "$var: $ENV{$var}\n";
1.26      raeburn   922:         }
1.40      raeburn   923:         foreach my $var (@envvars) {
                    924:             $envdata .= "$var: $env{$var}\n";
1.5       raeburn   925:         }
1.40      raeburn   926:         foreach my $var (@loncvars) {
                    927:             $envdata .= "$var: $env{$var}\n";
1.5       raeburn   928:         }
                    929:         $msg->attach(Type => 'TEXT',
                    930:                      Data => $envdata);
                    931:     }
                    932: 
                    933: ### Send it:
                    934:     $msg->send('sendmail');
                    935: 
1.44      raeburn   936:     if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
1.5       raeburn   937:         unlink($attachmentpath);
                    938:     }
1.44      raeburn   939:     $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
1.55      bisitz    940:     $r->print('<div style="width:620px;">'.
                    941:               &Apache::lonhtmlcommon::start_pick_box().
1.44      raeburn   942:               &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
                    943:               &Apache::lonhtmlcommon::row_closure().
                    944:               &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
                    945:     my $envmsg;
1.40      raeburn   946:     foreach my $var (@cookievars) {
1.44      raeburn   947:         if ($cookies{$var} ne '') {
                    948:             $envmsg.= '<span class="LC_helpform_receipt_cat">'.
                    949:                       $var.'</span>:&nbsp;'.$cookies{$var}.', ';
1.27      raeburn   950:         }
                    951:     }
1.40      raeburn   952:     foreach my $var (@ENVvars) {
1.44      raeburn   953:         if ($ENV{$var} ne '') {
                    954:             $envmsg .= '<span class="LC_helpform_receipt_cat">'.
                    955:                        $var.'</span>:&nbsp;'.$ENV{$var}.', ';
1.26      raeburn   956:         }
                    957:     }
1.40      raeburn   958:     foreach my $var (@envvars) {
1.44      raeburn   959:         if ($env{$var} ne '') { 
                    960:             $envmsg .= '<span class="LC_helpform_receipt_cat">'.
                    961:                        $var.'</span>:&nbsp;'.$env{$var}.', ';
1.5       raeburn   962:         }
1.1       raeburn   963:     }
1.44      raeburn   964:     $envmsg =~ s/, $//;
                    965:     $r->print($envmsg."\n".
                    966:               &Apache::lonhtmlcommon::row_closure(1)."\n".
1.55      bisitz    967:               &Apache::lonhtmlcommon::end_pick_box().
                    968:               "</div>\n".
1.44      raeburn   969:               &Apache::loncommon::end_page());
1.1       raeburn   970: }
                    971: 
1.14      raeburn   972: sub print_header {
1.44      raeburn   973:     my ($r,$origurl,$command) = @_;
1.14      raeburn   974:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
                    975:     my ($component_url);
                    976:     my $helpdesk_link = '<a href="javascript:validate()">';
1.44      raeburn   977:     if ($command eq 'process') {
1.14      raeburn   978:         $helpdesk_link = '<a href="/adm/helpdesk">';
                    979:     }
                    980:     my %lt = &Apache::lonlocal::texthash (
1.67      raeburn   981:                                            login    => 'Log-in help',
                    982:                                            ask      => 'Ask helpdesk',
                    983:                                            getst    => 'Getting started guide',
                    984:                                            back     =>  'Back to last location',
1.47      bisitz    985:                                            headline => 'help/support',
1.67      raeburn   986:                                            stud     => 'Students',
                    987:                                            ifyo     => 'If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.',
                    988:                                            cont     => 'Contact your instructor instead.',
1.21      raeburn   989:                                          );
1.47      bisitz    990:     my ($getstartlink,$reviewtext);
1.21      raeburn   991:     if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
                    992:         $getstartlink = qq|<td align="center">&nbsp;<b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
1.47      bisitz    993:         $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
                    994:     } else {
                    995:         $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
1.21      raeburn   996:     }
1.70      raeburn   997:     my $linkback;
1.59      raeburn   998:     if ($origurl eq '') {
1.70      raeburn   999:         $linkback = 'javascript:history.go(-1)';
                   1000:     } else {
                   1001:         $linkback = &HTML::Entities::encode($origurl,'"<>&');
1.59      raeburn  1002:     }
1.68      raeburn  1003:     my $loginhelp = &Apache::lonauth::loginhelpdisplay();
                   1004:     if ($loginhelp eq '') {
                   1005:         $loginhelp = '/adm/loginproblems.html';
                   1006:     }
1.67      raeburn  1007:     $r->print(<<"END");
                   1008: <table width="620" border="0" cellspacing="0" cellpadding="0" style="height: 55px;">
                   1009:  <tr>
                   1010:    <td width="5" height="50">&nbsp;</td>
                   1011:    <td height="50">
1.53      bisitz   1012:     <fieldset>
                   1013:       <legend>
1.67      raeburn  1014:         <img src="$location/lonIcons/minilogo.gif" height="20" width="29" alt="logo" style="vertical-align:bottom" />
1.53      bisitz   1015:         LON-CAPA $lt{'headline'}
                   1016:       </legend>
1.44      raeburn  1017:  <table id="LC_helpmenu_links">
                   1018:    <tr>
1.68      raeburn  1019:     <td align="center"><span class="LC_nobreak"><img src="$location/help/help.png" border="0" alt="($lt{'login'})" style="vertical-align:middle" />&nbsp;<b><a href="$loginhelp">$lt{'login'}</a></b>&nbsp;</span></td>
1.67      raeburn  1020:     <td align="center"><span class="LC_nobreak">&nbsp;<b>$helpdesk_link<img src="$location/lonIcons/helpdesk.gif" border="0" alt="($lt{'ask'})" style="vertical-align:middle" />&nbsp;$lt{'ask'}</a></b>&nbsp;</span></td>$getstartlink
1.70      raeburn  1021:     <td align="center"><span class="LC_nobreak">&nbsp;<b><a href="$linkback" target="_top"><img src="$location/lonIcons/move_up.gif" border="0" alt="($lt{'back'})" style="vertical-align:middle" />&nbsp;$lt{'back'}</a></b>&nbsp;</span></td>
1.44      raeburn  1022:    </tr>
1.14      raeburn  1023:  </table>
                   1024: </fieldset>
                   1025:   </td>
1.67      raeburn  1026:   <td width="5">&nbsp;</td>
1.14      raeburn  1027:  </tr>
1.67      raeburn  1028:  <tr>
                   1029:   <td colspan="3" height="5">&nbsp;</td>
1.14      raeburn  1030:  </tr>
                   1031: END
1.44      raeburn  1032:     if  ($command ne 'process') {
1.67      raeburn  1033:         my $stuwarn = &mt('Do [_1]not[_2] use this form to ask about course content.',
                   1034:                           '<b>','</b>');
                   1035:         $r->print(<<"END");
1.14      raeburn  1036:  <tr>
1.67      raeburn  1037:   <td colspan="3">$reviewtext 
1.76      bisitz   1038:   $lt{'ifyo'}
                   1039: <p class="LC_info">
                   1040: <b>$lt{'stud'}:</b> 
                   1041: $stuwarn $lt{'cont'}
                   1042: </p><br />
1.14      raeburn  1043:   </td>
1.67      raeburn  1044:  </tr>
                   1045: END
1.14      raeburn  1046:     }
                   1047:     $r->print('
                   1048: </table>');
                   1049:     return;
                   1050: }
                   1051: 
1.45      raeburn  1052: sub get_domain {
                   1053:     my $codedom;
                   1054:     if (exists($env{'form.codedom'})) {
1.70      raeburn  1055:         if (&Apache::lonnet::domain($env{'form.codedom'}) ne '') {
                   1056:             return $env{'form.codedom'};
                   1057:         }
                   1058:     }
                   1059:     if ($env{'request.course.id'}) {
1.45      raeburn  1060:         $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1061:     } elsif ($env{'request.role.domain'}) {
                   1062:         $codedom = $env{'request.role.domain'};
                   1063:     } else {
1.54      raeburn  1064:         $codedom = &Apache::lonnet::default_login_domain();
1.45      raeburn  1065:     }
                   1066:     return $codedom;
                   1067: }
                   1068: 
1.1       raeburn  1069: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>