[LON-CAPA-cvs] cvs: loncom / loncapa_apache.conf lond /interface loncommon.pm lonhelpmenu.pm lonhtmlcommon.pm lonsupportreq.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Sat, 03 Jul 2004 18:49:43 -0000


This is a MIME encoded message

--raeburn1088880583
Content-Type: text/plain

raeburn		Sat Jul  3 14:49:43 2004 EDT

  Added files:                 
    /loncom/interface	lonsupportreq.pm lonhelpmenu.pm 

  Modified files:              
    /loncom	lond loncapa_apache.conf 
    /loncom/interface	lonhtmlcommon.pm loncommon.pm 
  Log:
  Integration of help icons in breadcrumb trail into a single icon. Click on icon to open new window with gateway to help options within frameset (or within main window if pop-ups blocked).  Help options include inline topic help, support request form, FAQ-o-matic, and bug reporting (all contextualized).  Option to collect form parameter information from page displaying help icon currently disabled.
  
  Some work required:
  lonsupportreq.pm - replace call to Mail::Send with more sophisticated CPAN module (e.g., Mail::Sender that allows specification of from: address and attachments.
  
  
  
--raeburn1088880583
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20040703144943.txt"

Index: loncom/lond
diff -u loncom/lond:1.204 loncom/lond:1.205
--- loncom/lond:1.204	Tue Jun 29 11:31:32 2004
+++ loncom/lond	Sat Jul  3 14:49:42 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.204 2004/06/29 15:31:32 albertel Exp $
+# $Id: lond,v 1.205 2004/07/03 18:49:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -56,7 +56,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.204 $'; #' stupid emacs
+my $VERSION='$Revision: 1.205 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid;
 my $currentdomainid;
@@ -3214,6 +3214,32 @@
                     } else {
                         print $client "refused\n";
                     }
+#---------------------  read and retrieve institutional code format (for support form).
+                } elsif ($userinput =~/^autoinstcodeformat:/) {
+                    if (isClient) {
+                        my $reply;
+                        my($cmd,$cdom,$course) = split(/:/,$userinput);
+                        my @pairs = split/\&/,$course;
+                        my %instcodes = ();
+                        my %codes = ();
+                        my @codetitles = ();
+                        my %cat_titles = ();
+                        my %cat_order = ();
+                        foreach (@pairs) {
+                            my ($key,$value) = split/=/,$_;
+                            $instcodes{&unescape($key)} = &unescape($value);
+                        }
+                        my $formatreply = &localenroll::instcode_format($cdom,\%instcodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
+                        if ($formatreply eq 'ok') {
+                            my $codes_str = &hash2str(%codes);
+                            my $codetitles_str = &array2str(@codetitles);
+                            my $cat_titles_str = &hash2str(%cat_titles);
+                            my $cat_order_str = &hash2str(%cat_order);
+                            print $client $codes_str.':'.$codetitles_str.':'.$cat_titles_str.':'.$cat_order_str."\n";
+                        }
+                    } else {
+                        print $client "refused\n";
+                    }
 # ------------------------------------------------------------- unknown command
 
 		} else {
@@ -3621,6 +3647,73 @@
     return $userloadpercent;
 }
 
+# Routines for serializing arrays and hashes (copies from lonnet)
+
+sub array2str {
+  my (@array) = @_;
+  my $result=&arrayref2str(\@array);
+  $result=~s/^__ARRAY_REF__//;
+  $result=~s/__END_ARRAY_REF__$//;
+  return $result;
+}
+                                                                                 
+sub arrayref2str {
+  my ($arrayref) = @_;
+  my $result='__ARRAY_REF__';
+  foreach my $elem (@$arrayref) {
+    if(ref($elem) eq 'ARRAY') {
+      $result.=&arrayref2str($elem).'&';
+    } elsif(ref($elem) eq 'HASH') {
+      $result.=&hashref2str($elem).'&';
+    } elsif(ref($elem)) {
+      #print("Got a ref of ".(ref($elem))." skipping.");
+    } else {
+      $result.=&escape($elem).'&';
+    }
+  }
+  $result=~s/\&$//;
+  $result .= '__END_ARRAY_REF__';
+  return $result;
+}
+                                                                                 
+sub hash2str {
+  my (%hash) = @_;
+  my $result=&hashref2str(\%hash);
+  $result=~s/^__HASH_REF__//;
+  $result=~s/__END_HASH_REF__$//;
+  return $result;
+}
+                                                                                 
+sub hashref2str {
+  my ($hashref)=@_;
+  my $result='__HASH_REF__';
+  foreach (sort(keys(%$hashref))) {
+    if (ref($_) eq 'ARRAY') {
+      $result.=&arrayref2str($_).'=';
+    } elsif (ref($_) eq 'HASH') {
+      $result.=&hashref2str($_).'=';
+    } elsif (ref($_)) {
+      $result.='=';
+      #print("Got a ref of ".(ref($_))." skipping.");
+    } else {
+        if ($_) {$result.=&escape($_).'=';} else { last; }
+    }
+
+    if(ref($hashref->{$_}) eq 'ARRAY') {
+      $result.=&arrayref2str($hashref->{$_}).'&';
+    } elsif(ref($hashref->{$_}) eq 'HASH') {
+      $result.=&hashref2str($hashref->{$_}).'&';
+    } elsif(ref($hashref->{$_})) {
+       $result.='&';
+      #print("Got a ref of ".(ref($hashref->{$_}))." skipping.");
+    } else {
+      $result.=&escape($hashref->{$_}).'&';
+    }
+  }
+  $result=~s/\&$//;
+  $result .= '__END_HASH_REF__';
+  return $result;
+}
 
 # ----------------------------------- POD (plain old documentation, CPAN style)
 
Index: loncom/loncapa_apache.conf
diff -u loncom/loncapa_apache.conf:1.89 loncom/loncapa_apache.conf:1.90
--- loncom/loncapa_apache.conf:1.89	Wed Jun 30 06:17:19 2004
+++ loncom/loncapa_apache.conf	Sat Jul  3 14:49:42 2004
@@ -1,7 +1,7 @@
 ##
 ## loncapa_apache.conf -- Apache HTTP LON-CAPA configuration file
 ##
-## $Id: loncapa_apache.conf,v 1.89 2004/06/30 10:17:19 foxr Exp $
+## $Id: loncapa_apache.conf,v 1.90 2004/07/03 18:49:42 raeburn Exp $
 ##
 
 #
@@ -772,6 +772,18 @@
 PerlHandler Apache::lonhelp
 </LocationMatch>
 
+<LocationMatch "^/adm/helpmenu">
+PerlAccessHandler       Apache::lonacc
+SetHandler perl-script
+PerlHandler Apache::lonhelpmenu
+</LocationMatch>
+
+<LocationMatch "^/adm/support">
+PerlAccessHandler       Apache::lonacc
+SetHandler perl-script
+PerlHandler Apache::lonsupportreq
+</LocationMatch>
+
 # ------------------------------------------------- Backdoor Adm Tests/Programs
 
 <Location /cgi-bin/loncron.pl>
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.78 loncom/interface/lonhtmlcommon.pm:1.79
--- loncom/interface/lonhtmlcommon.pm:1.78	Thu Jun 17 14:22:13 2004
+++ loncom/interface/lonhtmlcommon.pm	Sat Jul  3 14:49:42 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.78 2004/06/17 18:22:13 www Exp $
+# $Id: lonhtmlcommon.pm,v 1.79 2004/07/03 18:49:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1060,12 +1060,13 @@
         my $icons = '';
         $faq = $last->{'faq'} if (exists($last->{'faq'}));
         $bug = $last->{'bug'} if (exists($last->{'bug'}));
-        if ($faq ne '') {
-            $icons .= &Apache::loncommon::help_open_faq($faq);
-        }
-        if ($bug ne '') {
-            $icons .= &Apache::loncommon::help_open_bug($bug);
-        }
+#        if ($faq ne '') {
+#            $icons .= &Apache::loncommon::help_open_faq($faq);
+#        }
+#        if ($bug ne '') {
+#            $icons .= &Apache::loncommon::help_open_bug($bug);
+#        }
+        $icons .= &Apache::loncommon::help_open_menu($color,$component,$component_help,$function,$faq,$bug);
         if ($icons ne '') {
             $Str .= $icons.'&nbsp;';
         }
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.192 loncom/interface/loncommon.pm:1.193
--- loncom/interface/loncommon.pm:1.192	Thu Jun 10 22:21:45 2004
+++ loncom/interface/loncommon.pm	Sat Jul  3 14:49:42 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.192 2004/06/11 02:21:45 taceyjo1 Exp $
+# $Id: loncommon.pm,v 1.193 2004/07/03 18:49:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -637,6 +637,73 @@
 	.'</td></tr></table>';
 }
 
+sub help_open_menu {
+    my ($color,$topic,$component_help,$function,$faq,$bug,$stayOnPage,$width,$height,$text) = @_;
+    $text = "" if (not defined $text);
+    $stayOnPage = 0 if (not defined $stayOnPage);
+    if ($ENV{'browser.interface'} eq 'textual' ||
+        $ENV{'environment.remote'} eq 'off' ) {
+        $stayOnPage=1;
+    }
+    $width = 620 if (not defined $width);
+    $height = 600 if (not defined $height);
+    my $link='';
+    my $title = &mt('Choose your help');
+    my $origurl = $ENV{'REQUEST_URI'};
+    my $timestamp = time;
+    my %formhash = ();
+    if ($ENV{'request.course.fn'}) {
+        open(FILE,">$ENV{'request.course.fn'}.formdata");
+        &get_unprocessed_cgi($ENV{'QUERY_STRING'},undef);
+        foreach (keys %ENV) {
+            if ($_ =~ m/^form\.(.+)$/) {
+                if (ref($ENV{$_}) eq 'ARRAY') {
+                    my $valstr = join(",",@{$ENV{$_}});
+                    print FILE "$1 = $valstr\n";
+                } else {
+                    print FILE "$1 = $ENV{$_}\n";
+                }
+            }
+        }
+        close(FILE);
+    }
+    foreach (\$color,\$function,\$topic,\$component_help,\$faq,\$bug,\$origurl) {
+        $$_ = &Apache::lonnet::escape($$_);
+    }
+
+    if (!$stayOnPage)
+    {
+         $link = "javascript:helpMenu('open')";
+    }
+    else
+    {
+        $link = "javascript:helpMenu('display')";
+    }
+    my $banner_link = "/adm/helpmenu?page=banner&color=$color&function=$function&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp";
+    my $details_link = "/adm/helpmenu?page=body&color=$color&function=$function&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp";
+    my $template .= <<"ENDTEMPLATE";
+ <script>
+function helpMenu(caller) {
+    if (caller == 'open') {
+        newWindow =  window.open("","helpmenu","HEIGHT=$height,WIDTH=$width,resize=yes,scrollbars=yes" )
+        caller = newWindow.document
+    } else {
+        caller = this.document
+    }
+    caller.write("<html><head><title>LON-CAPA Help Menu</title><meta http-equiv='pragma' content='no-cache'></head>")
+    caller.write("<frameset rows='105,*' border='0'><frame name='bannerframe'  src='$banner_link'><frame name='bodyframe' src='$details_link'></frameset>")
+    caller.write("</html>")
+    caller.close()
+    if (caller == newWindow.document) {
+        caller.focus()
+    }
+}
+ </script>
+ <a href="$link" title="$title"><image src="/adm/lonMisc/smallFAQ.gif" border="0" alt="(Help Menu)" /></a>
+ENDTEMPLATE
+    return $template;
+}
+
 sub help_open_bug {
     my ($topic, $text, $stayOnPage, $width, $height) = @_;
     unless ($ENV{'user.adv'}) { return ''; }

Index: loncom/interface/lonsupportreq.pm
+++ loncom/interface/lonsupportreq.pm
package Apache::lonsupportreq;

use strict;
use lib qw(/home/httpd/lib/perl);
use Apache::Constants qw(:common);
use Apache::loncommon;
use Apache::lonnet;
use localenroll;
use Apache::lonlocal;

use Mail::Send;
# use MIME::Lite;
# use MIME::Types;

sub handler {
    my $r = shift;
    $r->content_type('text/html');
    $r->send_http_header;

    if ($r->header_only) {
        return OK;
    }

    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','origurl','function']);
    my $action = $ENV{'form.action'};
    my $function = $ENV{'form.function'};
    my $origurl = &Apache::lonnet::unescape($ENV{'form.origurl'});
    if ($action eq 'process') {
        &print_request_receipt($r,$origurl,$function);
    } else {
        &print_request_form($r,$origurl,$function);
    }
    return OK;
}
    
sub print_request_form {
    my ($r,$origurl,$function) = @_;
    my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,$cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server);
    my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0",marginheight="0"',1);
    my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
    $os = $ENV{'browser.os'};
    $browser = $ENV{'browser.type'};
    $bversion = $ENV{'browser.version'};
    $uhost = $ENV{'request.host'};
    $uname = $ENV{'user.name'};
    $udom = $ENV{'user.domain'};
    $uhome = $ENV{'user.home'};
    $urole = $ENV{'request.role'};
    $usec = $ENV{'request.course.sec'};
    $cid = $ENV{'request.course.id'};
    $server = $ENV{'SERVER_NAME'};
    my $scripttag;
    if ($cid =~ m/_/) {
        ($cdom,$cnum) = split/_/,$cid;
    }
    if ($cdom && $cnum) {
        my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
        $ctitle = $csettings{'description'};
        $ccode = $csettings{'internal.coursecode'};
        $sectionlist = $csettings{'internal.sectionnums'};
    }
    if ($ENV{'environment.critnotification'}) {
        $email = $ENV{'environment.critnotification'};
    }
    if (!$email && $ENV{'environment.notification'}) {
        $email = $ENV{'environment.notification'};
    }
    if ($ENV{'environment.lastname'}) {
        $lastname = $ENV{'environment.lastname'};
    }
    if ($ENV{'environment.firstname'}) {
        $firstname = $ENV{'environment.firstname'};
    }
    my @sections = split/,/,$sectionlist;
    my %groupid = ();
    foreach (@sections) {
        my ($sec,$grp) = split/:/,$_;
        $groupid{$sec} = $grp;
    }
    $r->print(<<END);
<html>
 <head>
  <title>LON-CAPA support request</title>
END
    my $defdom = $Apache::lonnet::perlvar{'lonDefDomain'};
    my $codedom = $defdom;
    my %coursecodes = ();
    my %codes = ();
    my @codetitles = ();
    my %cat_titles = ();
    my %cat_order = ();
    my $caller = 'global';
    my $totcodes = 0;
    my $format_reply;
    
    if ($cdom) {
        $codedom = $cdom;
    }
    if ($cnum) {
        $coursecodes{$cnum} = $ccode;
        if ($ccode eq '') {
            $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
        } else {
            $coursecodes{$cnum} = $ccode;
            $caller = $cnum;
            $totcodes ++;
        }
    } else { 
        $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
    }
    if ($totcodes > 0) {
        $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
    }
    $r->print(<<END);
<html>
<head>
 <title>LON-CAPA support request</title>
$scripttag
</head>
$bodytag
 <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
  <tr>
   <td>
    <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
     <tr>
      <td>
       <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
        <tr>
         <td>
	  <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
           <form method="post" name="logproblem" onSubmit="return validate()">
           <tr>
            <td width="140" bgcolor="$tablecolor">
             <table width="140" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td align="right"><b>Name:</b>
               </td>
              </tr>
             </table>
            </td>
            <td width="100%" valign="top">
             <table width="100%" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td>
END
    my $fullname = '';
    if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
        $fullname = "$firstname $lastname"; 
        $r->print("$fullname<input type=\"hidden\" name=\"username\" value=\"$fullname\" />");
    } else {
        if (defined($firstname) && $firstname ne '') {
            $fullname = $firstname;
        } elsif (defined($lastname) && $lastname ne '') {
            $fullname= " $lastname";
        }
        $r->print('<input type="text" size="20" name="username" value="'.$fullname.'" /><br />');
    }
    $r->print(<<END);
               </td>
              </tr>
             </table>
            </td>
           </tr>
           <tr>
            <td width="100%" colspan="2" bgcolor="#000000">
             <img src="/adm/lonMisc/blackdot.jpg" /><br />
            </td>
           </tr>
           <tr>
            <td width="140" bgcolor="$tablecolor">
             <table width="140" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td align="right"><b>E-mail address:</b>
               </td>
              </tr>
             </table>
            </td>
            <td width="100%" valign="top">
             <table width="100%" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td>
                <input type="text" size="20" name="email" value="$email" /><br />
               </td>
              </tr>
             </table>
            </td>
           </tr>
           <tr>
            <td width="100%" colspan="2" bgcolor="#000000">
             <img src="/adm/lonMisc/blackdot.jpg" /><br />
            </td>
           </tr>
           <tr>
            <td width="140" bgcolor="$tablecolor">
             <table width="140" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td align="right"><b>username/domain:</b>
               </td>
              </tr>
             </table>
            </td>
            <td width="100%" valign="top">
             <table width="100%" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td>
END
    my $udom_input = '<input type="hidden" name="udom" value="'.$udom.'" />';
    my $uname_input = '<input type="hidden" name="uname" value="'.$uname.'" />'; 
    if (defined($uname) && defined($udom)) {
        $r->print('<i>username</i>:&nbsp;'.$uname.'&nbsp;&nbsp;<i>domain</i>:&nbsp;'.$udom.$udom_input.$uname_input);
    } else {
        my $udomform = '';
        my $unameform = '';
        if (defined($udom)) {
            $udomform = '<i>domain</i>:&nbsp;'.$udom.$udom_input;
        } elsif (defined($uname)) {
            $unameform = '<i>username</i>:&nbsp;'.$uname.'&nbsp;&nbsp;'.$uname_input;
        }
        if ($udomform eq '') {
            $udomform = '<i>domain</i>:&nbsp;';
            $udomform .= &Apache::loncommon::select_dom_form('','udom');
        }
        if ($unameform eq '') {
            $unameform= '<i>username</i>:&nbsp;<input type="text" size="20" name="loncname" value="'.$uname.'" />&nbsp;&nbsp;';
        }
        $r->print($unameform.$udomform.'<br />Enter the username you use to log-in to your LON-CAPA system, and choose your domain.');
    }
    $r->print(<<END);
               </td>
              </tr>
             </table>
            </td>
           </tr>
           <tr>
            <td width="100%" colspan="2" bgcolor="#000000">
             <img src="/adm/lonMisc/blackdot.jpg" /><br />
            </td>
           </tr>
           <tr>
            <td width="140" bgcolor="$tablecolor">
             <table width="140" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td align="right"><b>URL of page:</b>
               </td>
              </tr>
             </table>
            </td>
            <td width="100%" valign="top">
             <table width="100%" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td>
                $server$origurl<input type="hidden" name="origurl" value="$server$origurl" />
               </td>
              </tr>
             </table>
            </td>
           </tr>
           <tr>
            <td width="100%" colspan="2" bgcolor="#000000">
             <img src="/adm/lonMisc/blackdot.jpg" /><br />
            </td>
           </tr>
           <tr>
            <td width="140" bgcolor="$tablecolor">
             <table width="140" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td align="right"><b>Phone #:</b>
               </td>
              </tr>
             </table>
            </td>
            <td width="100%" valign="top">
             <table width="100%" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td>
                <input type="text" size="15" name="phone"><br>
               </td>
              </tr>
             </table>
            </td>
           </tr>
           <tr>
            <td width="100%" colspan="2" bgcolor="#000000">
             <img src="/adm/lonMisc/blackdot.jpg" /><br />
            </td>
           </tr>
           <tr>
            <td width="140" bgcolor="$tablecolor">
             <table width="140" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td align="right"><b>Course Details:</b>
               </td>
              </tr>
             </table>
            </td>
            <td width="100%" valign="top">
             <table border="0" cellpadding="3" cellspacing="3">
              <tr>
               <td>
END
    if ($coursecodes{$cnum}) {
        foreach (@codetitles) {
            $r->print('<i>'.$_.'</i>:&nbsp;'.$codes{$cnum}{$_});
        }
        $r->print('.&nbsp;<input type="hidden" name="coursecode" value="'.$coursecodes{$cnum}.'" />');
    } else {
        $r->print('Enter institutional course code:&nbsp;
                  <input type="text" name="coursecode" size="15" value="" />');
    }
    if ($ctitle) {
        $r->print('<br /><i>Title</i>:&nbsp;'.$ctitle.'<input type="hidden" name="title" value="'.$ctitle.'" />');
    } else {
        $r->print('<br />Enter course title:&nbsp;
                 <input type="text" name="title" size="15" value="" />');
    }
    $r->print(<<END);
               </td>
              </tr>
             </table>
            </td>
           </tr>
           <tr>
            <td width="100%" colspan="2" bgcolor="#000000">
             <img src="/adm/lonMisc/blackdot.jpg" /><br />
            </td>
           </tr>
           <tr>
            <td width="140" bgcolor="$tablecolor">
             <table width="140" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td align="right"><b>Section Number: </b>
               </td>
              </tr>
             </table>
            </td>
            <td width="100%" valign="top">
             <table width="100%" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td>
END
    if ($sectionlist) {
        $r->print("<select name=\"section\">");
        foreach (sort keys %groupid) {
            if ($_ eq $groupid{$_} || $groupid{$_} eq '') {
                $r->print("<option value=\"$_\" />$_");
            } else {
                $r->print("<option value=\"$_\" />$_ - (LON-CAPA sec: $groupid{$_}");
            }
        }
        $r->print("</select>");
    } else {
        $r->print("<input type=\"text\" name=\"section\" size=\"10\"/>");
    }
    $r->print(<<END);
               </td>
              </tr>
             </table>
            </td>
           </tr>
           <tr>
            <td width="100%" colspan="2" bgcolor="#000000">
             <img src="/adm/lonMisc/blackdot.jpg" /><br />
            </td>
           </tr>
           <tr>
            <td width="140" bgcolor="$tablecolor">
             <table width="140" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td align="right"><b>Subject</b>
               </td>
              </tr>
             </table>
            </td>
            <td width="100%" valign="top">
             <table width="100%" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td>
                <input type="text" size="40" name="subject">
               </td>
              </tr>
             </table>
            </td>
           </tr>
           <tr>
            <td width="100%" colspan="2" bgcolor="#000000">
             <img src="/adm/lonMisc/blackdot.jpg" /><br />
            </td>
           </tr>
           <tr>
            <td width="140" bgcolor="$tablecolor">
             <table width="140" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td align="right"><b>Detailed description:</b>
               </td>
              </tr>
             </table>
            </td>
            <td width="100%" valign="top">
             <table width="100%" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td>
                <textarea rows="10" cols="45" name="description" wrap="virtual"></textarea>
               </td>
              </tr>
             </table>
            </td>
           </tr>
           <tr>
	    <td width="100%" colspan="2" bgcolor="#000000">
             <img src="/adm/lonMisc/blackdot.jpg" /><br />
	    </td>
	   </tr>
           <tr>
            <td width="140" bgcolor="$tablecolor">
             <table width="140" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td align="right"><b>Finish:</b>
               </td>
              </tr>
             </table>
            </td>
            <td width="100%" valign="top">
             <table border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td>
                <input type="hidden" name="action" value="process" />
                <input type="submit" value="Submit Request Form" /> &nbsp;
               </td>
               <td>&nbsp;</td>
               <td>
                <input type="reset" value="Clear Form">
               </td>
              </tr>
             </table>
            </td>
           </tr>
          </table>
         </td>
        </tr>
       </table>
      </td>
     </tr>
    </table>
   </td>
  </tr>
 </table>
END


# What do we know about this user?
#    foreach (sort keys %ENV) {
#        if ($_ =~ m/^browser/) {
#            $r->print("key is $_, value is $ENV{$_}");
#        } elsif ($_ =~ m/^environment/) {
#            $r->print("key is $_, value is $ENV{$_}");
#        } elsif ($_ =~ m/^request/) {
#            $r->print("key is $_, value is $ENV{$_}");
#        } elsif ($_ =~ m/^user\.(domain|home|name)/) {
#            $r->print("key is $_, value is $ENV{$_}");
#        } elsif ($_ =~ /^[A-Z]/) {
#            $r->print("key is $_, value is $ENV{$_}");
#        }
#    }
    return
}

sub print_request_receipt {
    my ($r,$url,$function) = @_;
    my @envvars = ('lonID','HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME','browser.os','browser.type','browser.version','user.home','request.role');
    my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);
    my $to =  $Apache::lonnet::perlvar{'lonSupportEMail'};
    my $reporttime = &Apache::lonlocal::locallocaltime(time);
    my $fontcolor = &Apache::loncommon::designparm($function.'.font');
    my $vlinkcolor = &Apache::loncommon::designparm($function.'.vlink');
    my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
    my @formvars = ('username','email','uname','udom','origurl','phone','section','coursecode','title','subject','description');
    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);

#    if ($ENV{'request.course.fn'}) {
#        my $formdatafile = $ENV{'request.course.fn'}.'.formdata';
#        if (-e $formdatafile) {
#            open(FILE,"<$formdatafile");
#            my @buffer =<FILE>;
#            close(FILE);
#            foreach (@buffer) {
#                print STDERR $_;
#            } 
#        }
#    }

    my $supportmsg = qq|
Name: $ENV{'form.username'}
Email: $ENV{'form.email'}
Username/domain: $ENV{'form.uname'} - $ENV{'form.udom'}
Tel: $ENV{'form.phone'}
Course Information: $ENV{'form.title'} - $ENV{'form.coursecode'} - section: $ENV{'form.section'}
Subject: $ENV{'form.subject'}
Description: $ENV{'form.description'}
URL: $ENV{'form.origurl'}
Date/Time: $reporttime

    |;
    if ($to =~ m/^[^\@]+\@[^\@]+$/) {
        $r->print(<<END);
<html>
<head>
 <title>LON-CAPA support request recorded</title>
</head>
$bodytag
 <h3>A support request has been sent to $to</h3>
END
    } else { 
        $to = 'helpdesk@lon-capa.org';
        $r->print(<<END);
<html>
<head>
 <title>LON-CAPA support request recorded</title>
</head>
$bodytag
 <h3>Warning: Problem with support e-mail address</h3>
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 not been sent to the LON-CAPA support staff at your institution. Instead a copy has been sent to the LON-CAPA support team at Michigan State University. 
END
    }
    my $msg = new Mail::Send;
    $msg->to($to);
#    if (defined($ENV{'form.email'})) {
#        if ($ENV{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
#            $msg->from($ENV{'form.email'});
#        }
#    }
    $msg->subject('[LON-CAPA] - support request');
    if (my $fh = $msg->open()) {
        print $fh $supportmsg;
        $fh->close;
    }
    $r->print(<<END);
 <b>Your support request contained the following information</b>:<br /><br />
 <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
  <tr>
   <td>
    <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
     <tr>
      <td>
       <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
        <tr>
         <td>
          <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
           <tr>
            <td width="140" bgcolor="$tablecolor">
             <table width="140" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td align="right"><b>Information supplied</b>
               </td>
              </tr>
             </table>
            </td>
            <td width="100%" valign="top">
             <table width="100%" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td>
END
    my @textmsg = split/\n/,$supportmsg;
    foreach my $line (@textmsg) {
        $line =~ s|^|<font color="$fontcolor">|;
        $line =~ s|:|:</font><font color="$vlinkcolor">|;
        $r->print("$line</font><br />");
    }
    $r->print('</td>
              </tr>
             </table>
            </td>
           </tr>
           <tr>
            <td width="130" bgcolor="'.$tablecolor.'">
             <table width="130" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td align="right"><b>Additional information recorded</b>
               </td>
              </tr>
             </table>
            </td>
            <td width="100%" valign="top">
             <table width="100%" border="0" cellpadding="8" cellspacing="0">
              <tr>
               <td>
    ');
    foreach (@envvars) {
        $r->print("$_:&nbsp;<font color='$vlinkcolor>$ENV{$_}</font>, ");
        $supportmsg .= "$_: $ENV{$_}\n";
    }
    $r->print("
               </td>
              </tr>
             </table>
            </td>
           </tr>
          </table>
         </td>
        </tr>
       </table>
      </td>
     </tr>
    </table>
   </td>
  </tr>
 </table>
    ");
}

sub retrieve_instcodes {
    my ($coursecodes,$codedom,$totcodes) = @_;
    my %courses = &Apache::lonnet::courseiddump($codedom,'.',1);
    foreach my $course (keys %courses) {
        if ($courses{$course} =~ m/^[^:]*:([^:]+)$/) {
            $$coursecodes{$course} = &Apache::lonnet::unescape($1);
            $totcodes ++;
        }
    }
    return $totcodes;
}

1;

Index: loncom/interface/lonhelpmenu.pm
+++ loncom/interface/lonhelpmenu.pm
# The LearningOnline Network with CAPA
# generate frame-based help system
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#

package Apache::lonhelpmenu;

use strict;
use lib qw(/home/httpd/lib/perl);
use Apache::Constants qw(:common);
use Apache::loncommon();

sub handler
{
    my $r = shift;
    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['page','color','function','faq','bug','topic','component_help','origurl']);
    $r->content_type('text/html');
    $r->send_http_header;

    if ($r->header_only) {
        return OK;
    }
    my $color = &Apache::lonnet::unescape($ENV{'form.color'});
    my $faq = &Apache::lonnet::unescape($ENV{'form.faq'});
    my $bug = &Apache::lonnet::unescape($ENV{'form.bug'});
    my $topic = &Apache::lonnet::unescape($ENV{'form.topic'});
    my $function = &Apache::lonnet::unescape($ENV{'form.function'});
    my $component_help = &Apache::lonnet::unescape($ENV{'form.component_help'});
    my $origurl = $ENV{'form.origurl'};
    my $component_url = $component_help;
    if ($component_url) {
        $component_url = '/adm/help/'.$component_url.'.hlp';
    }
    my $bugurl = $Apache::lonnet::perlvar{'BugzillaHost'};
    $bugurl .= 'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.$origurl;
    if ($bug) {
        $bugurl .= '&component='.$bug;
    }
    my $faqbaseurl = $Apache::lonnet::perlvar{'FAQHost'};
    my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
    if ($ENV{'form.page'} eq 'banner') {
        &display_help_banner ($r,$color,$function,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail);
    } elsif ($ENV{'form.page'} eq 'body') {
        &display_help_mainpage ($r,$color,$function,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail);
    }
    return OK;
}

sub display_help_banner {
    my ($r,$color,$function,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail) = @_;
    my $bodytag = &Apache::loncommon::bodytag('',$function,'rightmargin="0" leftmargin="0" marginwidth="0" topmargin="1" marginheight="1"',1);
    my $fontcolor = &Apache::loncommon::designparm($function.'.font');
    my $alinkcolor = &Apache::loncommon::designparm($function.'.alink');
    my $vlinkcolor = &Apache::loncommon::designparm($function.'.vlink');
    my $pagecolor = &Apache::loncommon::designparm($function.'.pgbg');
    my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');

    $r->print(<<END);
<html>
<head>
<title>Help Banner</title>
<style type="text/css">
<!--
 a:link {text-decoration: none; color: $fontcolor; }
 a:visited {text-decoration: none; color: $fontcolor; }
 a:active {text-decoration: none; color: $fontcolor; }
 a:hover {text-decoration: underline; color: $vlinkcolor; }
-->
</style>
<script type="text/javascript">
function noTopic () { 
    bodyframe.document.write("<html><head><title>Topic Page</title></head>")
    bodyframe.document.write('$bodytag')
    bodyframe.document.write("The LON-CAPA help system does not currently include a specific pop-up help item for this topic. You may wish to consult the LON-CAPA <a href='/adm/help/author.manual.pdf'>Authoring Manual</a> or the <a href='/adm/help/course.manual.pdf'>Course Coordinator Manual</a>.")
    bodyframe.document.write("</body></html>")
    body.document.close()
}
</script>
</head>
$bodytag
 <table width="600" border="0" cellspacing="0" cellpadding="0" height="55">
  <tr height="50">
   <td width='5'>&nbsp;</td>
   <td>
    <fieldset><legend><img src="/adm/lonIcons/minilogo.gif" height='20' width='29' valign='bottom' />&nbsp;&nbsp;<b><font size="+1">LON-CAPA help/support</font></b></legend>
 <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
  <tr>
   <td>
    <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
     <tr>
      <td>
       <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
        <tr>
         <td>
	  <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
           <tr bgcolor="$tablecolor">
END
    if (($component_url) || ($ENV{'user.adv'})) {
        if ($component_url) {
            $r->print("
            <td align=\"center\">&nbsp;<b><a href=\"$component_url\" target=\"bodyframe\">");
        } elsif ($ENV{'user.adv'}) {
            $r->print('<td align="center">&nbsp;<b><a href="javascript:noTopic()" target="bodyframe">');
        }
        $r->print('
   <image src="/adm/help/gif/smallHelp.gif" border="0" alt="(Topic help)" valign="middle" />&nbsp;Topic help</a></b>&nbsp;</td>');
    }
    if ($requestmail) {
        $r->print('
            <td align="center">&nbsp;<b><a href="/adm/support?origurl='.$origurl.'&function='.$function.'" target="bodyframe"><image src="/adm/lonMisc/feedback.gif" border="0" alt="(Ask helpdesk)" valign="middle" />&nbsp;Ask helpdesk</a></b>&nbsp;</td>');
    }
    if ($ENV{'user.adv'}) {
        $r->print(<<END)
            <td align="center">
             &nbsp;<b><a href="$faqbaseurl/fom/cache/$faq.html" target="bodyframe"><image src="/adm/lonMisc/smallFAQ.gif" border="0" alt="(FAQ)" valign="middle" />&nbsp;FAQ</a></b>&nbsp;
            </td>
            <td align="center">&nbsp;<b><a href="$bugurl" target="bodyframe"><image src="/adm/lonMisc/smallBug.gif" border="0" alt="(Report a bug)" valign="middle" />&nbsp;Report a bug</a>&nbsp;</b></td>
END
    }
    $r->print(<<END);
            <td align="center">&nbsp;<b><a href="javascript:window.close()" target="_top"><image src="/adm/lonIcons/move_up.gif" border="0" alt="(Close window)" valign="middle" />Close</a></b>&nbsp;</td>
           </tr>
          </table>
         </td>
        </tr>
       </table>
      </td>
     </tr>
    </table>
   </td>
  </tr>
 </table>
</fieldset>
  </td>
  <td width='5'>&nbsp;</td>
 </tr>
 <tr height='5'>
  <td colspan='3' height='5'>&nbsp;</td>
 </tr>
</table>
</body>
</html>
END
}

sub display_help_mainpage {
    my ($r,$color,$function,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail) = @_;
    my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);
    $r->print(<<END);
<html>
 <head>
  <title>Help Content</title>
  <script type="text/javascript">
function noTopic() {
    bodyframe.document.write("<html><head><title>Topic Page</title></head>$bodytag")
    bodyframe.document.write("The LON-CAPA help system does not currently include a specific pop-up help item for this topic. You may wish to consult the LON-CAPA <a href='/adm/help/author.manual.pdf'>Authoring Manual</a> or the <a href='/adm/help/course.manual.pdf'>Course Coordinator Manual</a>.")
    bodyframe.document.write("</body></html>")
    body.document.close()
}
  </script>
 </head>
$bodytag
Choose an entry below to go directly to a relevant help page
END
    if ($requestmail) {
        $r->print(", or to submit a help request to the LON-CAPA support staff at you institution.");
    } else {
        $r->print(".");
    }
    if ($topic) {
        if ( ($component_url) || ($ENV{'user.adv'}) ) {
            if ($component_url) {
                $r->print("
          <ul>
           <li><a href=\"$component_url\">Visit the help page for $topic</a></li>
          </ul>
          <p>Display the page in the inline help system that covers this topic.</p>
                ");
            } elsif ($ENV{'user.adv'}) {
                $r->print("
              <ul>
               <li><td align=\"center\">&nbsp;<a href=\"javascript:noTopic()\">Inline help system for $topic</a></li></ul>
               <p>Consult the inline help system for this topic.</p>");
            }
        }
    }
    if ($requestmail) {
        $r->print("
          <ul>
           <li><a href=\"/adm/support?origurl=$origurl&function=$function\" target=\"bodyframe\">Contact the LON-CAPA support team</a></li>
          </ul>
          <p>Submit a help request to the team responsible for LON-CAPA support at this institution.</p>
          <ul>
        ");
    }
    if ($faqbaseurl && $ENV{'user.adv'}) {
        if (!defined($faq) ||$faq eq '') {
            $faq = '1';
        }
        $r->print("
           <li><a href=\"$faqbaseurl/fom/cache/$faq.html\">FAQ-O-Matic Help system</a></li>
          </ul>
          <p>The FAQ-O-Matic is a compendium of answers provided to common questions asked by users of LON-CAPA over the past couple of years.</p>
        ");
    }
    if ($bugurl && $ENV{'user.adv'}) {
        $bugurl .= '?'.$bug;
        $r->print("
          <ul>
           <li><a href=\"$bugurl\">LON-CAPA Bugzilla bug/feature request tracking
system</a></li>
          </ul>
          <p>Create an account for yourself in the LON-CAPA Bugzilla tracking system, if you wish to report bugs you have encountered in the LON-CAPA software,
or if you have suggestions for improvements in LON-CAPA.  Suggested improvements may include additional functionality, improved usability, or changes to wording used in LON-CAPA pages, including the embedded help system.</p>
        ");
    }
    $r->print(<<END);
 </body>
</html>
END
}

1;

--raeburn1088880583--