<?php

require 'browserhawk.php';

// browserinfo.php
// Created by cyScape, Inc.
//
// Permission to use and modify the contents of this script for your own
// purposes is hereby granted provided you have a licensed or active 
// evaluation copy of BrowserHawk on the machine this script is used on.
//
// Copyright (c) 2000-2006 cyScape, Inc.  All rights reserved.
//
// The purpose of this script is to automatically collect details about a
// visitor's browser to assist with the troubleshooting of browser 
// compatibility issues reported.  By default this script collects 
// information on browser type and version, installed plug-ins, disabled 
// cookies/JavaScript/applets, screen size, color depth, and much more.
//
// NOTE: THIS SCRIPT IS AN EXAMPLE TO HELP YOU GET UP AND RUNNING QUICKLY WITH
// A BROWSER TROUBLESHOOTING PAGE.  HOWEVER THERE ARE MANY REFINEMENTS YOU 
// SHOULD CONSIDER BEFORE USING IT ON A PRODUCTION WEB SITE, SUCH AS FORM
// VALIDATION, BETTER ERROR HANDLING, AND PAGE LAYOUT TO MATCH THE LOOK AND
// FEEL OF YOUR SITE.

// ------------------- USER CONFIGURATION BEGIN -------------------
// 
// PLEASE READ THROUGH THIS SECTION AND SET VARIABLES AS APPROPRIATE FOR YOUR
// DESIRED USAGE.
// 
// STEP 1
// ------
// Note we specifically don't test for acrobat since it can cause IE to load 
// the Acrobat splash screen.  This is a minor side effect if you need to know 
// whether Acrobat is installed.  However we don't test for it by default for 
// this reason.  If you wish to test for Acrobat change the following variable
// to True
$testAcrobat = false;

// STEP 2
// ------
// By default we test the user's connection speed.  If you are not interested
// in this however you should change the variable below to False
$testConnectionSpeed = true;

// STEP 3
// ------
// In addition to the main properties we display to the end user and email back
// to us, it may be helpful for you to have a full dump of all the browser
// property settings.  By default we collect this additional information, and 
// although it is not shown to the end user it is transmitted back to us when
// the user submits the troubleshooting form.  If you are not interested in 
// this extra information, set the following variable to false
$collectAllDetails = true;

// STEP 4
// ------
// Go to the EMAIL CONFIGURATION SECTION located in the ProcessResults 
// function found in this file to set up your email options so the browser
// settings can be emailed back to you.
// 
// ------------------- USER CONFIGURATION END  -------------------


// On a GET request, we generate the form;
// on a POST request, we handle the form.
if ($_SERVER['REQUEST_METHOD'] == "GET") {

  // To avoid an ugly exception, we check that the system executing this
  // example has an Enterprise Edition license as required for this test.
  // Note: This is NOT needed in your pages, only for this sample.
  if (strpos($BrowserHawk->getVersion(), "Ent") === false) {
    echo "Enterprise License Required.  ";
    echo "You are using " . $BrowserHawk->getVersion() . ".  ";
    echo "See <a href='http://www.cyscape.com/order/'>http://www.cyscape.com/order/</a> for upgrade information.";
    return;
  }

// Let's get the extended properties including enabled/disabled
// javascript/cookie/applet settings, screen size, plugins, color depth, and
// more.  Note that there are several optional parameters for this method - 
// see the BrowserHawk documentation for important details including how to 
// make this checking look seamless with your site if you change the background
// color.
//
// For starters, tell BH to execute all its tests (all plugins, connection
// speed, disabled cookies, etc).  Note however that BH detects of 100 
// properties, and checking them all can take several seconds.  Therefore we 
// recommend that you edit this script and make the changes to test only for
// the properties which most interest you.
//
// If you remove any properties from the test you should also call
// $options->removeProperty() to tell BH not to execute the tests you wish to
// remove.  Otherwise you will be removing the tests from your output but 
// still incurring the cost of the testing time.

  $options->setProperties("all");

// Speed detection is purposesly not included by the 'all' keyword because
// the test can take up to 8 seconds or so for people with slow modems - and 
// 'all' of the tests can take several seconds to execute already...  So if 
// we've specifically been told to check for speed, let's add that in

  if ($testConnectionSpeed) {
    $options->addProperty("ConnectionSpeed");
  }

// Acrobat detection is by default included in the 'all' keyword, but it can
// cause a pop-up window to appear during testing, so remove it unless the 
// user truly wants it.

  if (!$testAcrobat) {
    $options->removeProperties("Plugin_Acrobat,Plugin_AcrobatVerEx");
  }

// Run the extended test.  Note we return immediately if we get a null.  A
// null indicates the JavaScript testing code has been sent to the client and
// will come back to us on the following request.

  $einfo = bhextended($options);

// If we get here, we have test data.  Fetch some of it for display in our
// form.  For some values, we translate() the answers into human-friendly
// format.

  $browType = $info->getBrowser();
  $browBuild = $einfo->translate("BrowserBuild");
  $browVersion = $info->getFullversion();
  $browPlatform = $info->getPlatform();

  $browActiveXEnabled = $einfo->translate("ActiveXEnabled");
  $browVBScriptEnabled = $einfo->translate("VBScriptEnabled");

  $browJavaVersion = $einfo->translate("JavaVersion");
  $browJavaVendor = $einfo->translate("JavaVendor");

  $browJavaScriptCapable = $info->getJavaScript() ? "True" : "False";
  $browJavaScriptEnabled = $einfo->translate("JavaScriptEnabled");

  $browScreenSize = $einfo->translate("ScreenSize");
  $browBrowserSize = $einfo->translate("BrowserSize");

  $browCookiesCapable = $info->getCookies() ? "True" : "False";
  $browCookiesEnabled = $einfo->translate("Cookies");

  $browAppletsCapable = $info->getJavaApplets() ? "True" : "False";
  $browAppletsEnabled = $einfo->translate("JavaApplets");

  $browPluginFlash = $einfo->translate("Plugin_Flash");
  $browPluginShockwave = $einfo->translate("Plugin_Director");
  $browPluginMediaPlayer = $einfo->translate("Plugin_MediaPlayer");
  $browPluginRealPlayer = $einfo->translate("Plugin_RealPlayer");
  $browPluginQuickTime = $einfo->translate("Plugin_QuickTime");

  $browConnectionSpeed = $einfo->translate("ConnectionSpeed");
  $browConnectionType = $einfo->translate("ConnectionType");

  $browColorDepth = $einfo->translate("ColorDepth");
  $browDateTime = $einfo->translate("BrowserDateTime");
  $browTimeZoneDiff = $einfo->translate("Timezonediff");

  $browPluginAcrobat = "Not tested by default";
  if ($testAcrobat) {
    $browPluginAcrobat = $einfo->translate("Plugin_Acrobat");
  }

  $allDetails = "Not configured to collect additional details";
  if ($collectAllDetails) {
    $allDetails = $info->toString() . $einfo->toString();
  }
?>

<HTML><HEAD><TITLE>Browser troubleshooting tool</TITLE></HEAD>
<BODY>
<BLOCKQUOTE>
The purpose of this page is to collect information from you that
will assist us in troubleshooting the problem you are having.
Details about your browser have been collected for you automatically 
and are displayed in the table below.  
Please answer the following questions and press the "Report Issue" button.
A support representative will contact you shortly.
<P>

<form method="POST" action="<?php echo $_SERVER['SCRIPT_NAME'] ?>">
  <table width=450>
  <tr><td align=right>Name:</td>
      <td><input type="text" name="name" size="30"></td></tr>
  <tr><td align=right>Email:</td>
      <td><input type="email" name="email" size="30"></td></tr>
  <tr><td align=right>Description<br>of problem:</td>
      <td><textarea rows="3" name="desc" cols="40"></textarea></td></tr>
  <tr><td>&nbsp;</td>
      <td align=left><input type="submit" value="Report Issue" name="B1"></td></tr>
  </table>
  <input type="hidden"
   name="browTypeAndVer" value="<?php echo $browType ?> <?php echo $browVersion ?>">
  <input type="hidden"
   name="browBuild" value="<?php echo $browBuild ?>">
  <input type="hidden"
   name="browPlatform" value="<?php echo $browPlatform ?>">
  <input type="hidden"
   name="browCookiesCapable" value="<?php echo $browCookiesCapable ?>">
  <input type="hidden"
   name="browCookiesEnabled" value="<?php echo $browCookiesEnabled ?>">
  <input type="hidden"
   name="browJavaScriptCapable" value="<?php echo $browJavaScriptCapable ?>">
  <input type="hidden"
   name="browJavaScriptEnabled" value="<?php echo $browJavaScriptEnabled ?>">
  <input type="hidden"
   name="browActiveXEnabled" value="<?php echo $browActiveXEnabled ?>">
  <input type="hidden"
   name="browVBScriptEnabled" value="<?php echo $browVBScriptEnabled ?>">
  <input type="hidden"
   name="browAppletsCapable" value="<?php echo $browAppletsCapable ?>">
  <input type="hidden"
   name="browAppletsEnabled" value="<?php echo $browAppletsEnabled ?>">
  <input type="hidden"
   name="browJavaVersion" value="<?php echo $browJavaVersion ?>">
  <input type="hidden"
   name="browJavaVendor" value="<?php echo $browJavaVendor ?>">
  <input type="hidden"
   name="browScreenSize" value="<?php echo $browScreenSize ?>">
  <input type="hidden"
   name="browBrowserSize" value="<?php echo $browBrowserSize ?>">
  <input type="hidden"
   name="browConnectionType" value="<?php echo $browConnectionType ?>">
  <input type="hidden"
   name="browConnectionSpeed" value="<?php echo $browConnectionSpeed ?>">
  <input type="hidden"
   name="browColorDepth" value="<?php echo $browColorDepth ?>">
  <input type="hidden"
   name="browPluginFlash" value="<?php echo $browPluginFlash ?>">
  <input type="hidden"
   name="browPluginShockwave" value="<?php echo $browPluginShockwave ?>">
  <input type="hidden"
   name="browPluginMediaPlayer" value="<?php echo $browPluginMediaPlayer ?>">
  <input type="hidden"
   name="browPluginRealPlayer" value="<?php echo $browPluginRealPlayer ?>">
  <input type="hidden"
   name="browPluginAcrobat" value="<?php echo $browPluginAcrobat ?>">
  <input type="hidden"
   name="browPluginQuickTime" value="<?php echo $browPluginQuickTime ?>">
  <input type="hidden"
   name="browAllDetails" value="<?php echo $allDetails ?>">
  <input type="hidden"
   name="browDateTime" value="<?php echo $browDateTime ?>">
  <input type="hidden"
   name="browTimeZoneDiff" value="<?php echo $browTimeZoneDiff ?>">
</form>

<?php
    $qs = $_SERVER['QUERY_STRING'];
    if ($qs != null && $qs != "") {
?>
    <b>Important</b>: If you change any browser settings you must
    <a href="<?php echo $_SERVER['SCRIPT_NAME'] ?>"><b>click here</b></a><br>
    to refresh this data instead of hitting your Reload button.<p>
<?php
    }
?>

<font size=-1>User agent: <?php echo $_SERVER['HTTP_USER_AGENT'] ?> </font><P>

<?php
    $c1 = "";
    $c2 = "";
    if ($info->getTableBGColor()) {
      $c1 = " bgcolor=\"#FFFFFF\"";
      $c2 = " bgcolor=\"#F0F0F0\"";
    }
?>

<TABLE width=500 bgcolor="#CCCCCC" BORDER=1 cellpadding=5 cellspacing=2>
<TR<?php echo $c1 ?>><TD WIDTH=175>Browser type and version</TD> <TD><?php echo $browType ?> <?php echo $browVersion ?></TD></TR>
<TR<?php echo $c2 ?>><TD>Browser build</TD> <TD><?php echo $browBuild ?></TD></TR>
<TR<?php echo $c1 ?>><TD>Platform</TD> <TD><?php echo $browPlatform ?></TD></TR>
<TR<?php echo $c2 ?>><TD>Cookies supported</TD> <TD><?php echo $browCookiesCapable ?></TD></TR>
<TR<?php echo $c1 ?>><TD>Cookies enabled</TD> <TD><?php echo $browCookiesEnabled ?></TD></TR>
<TR<?php echo $c2 ?>><TD>JavaScript supported</TD> <TD><?php echo $browJavaScriptCapable ?></TD></TR>
<TR<?php echo $c1 ?>><TD>JavaScript enabled</TD> <TD><?php echo $browJavaScriptEnabled ?></TD></TR>
<TR<?php echo $c2 ?>><TD>ActiveX enabled</TD> <TD><?php echo $browActiveXEnabled ?></TD></TR>
<TR<?php echo $c1 ?>><TD>VBScript enabled</TD> <TD><?php echo $browVBScriptEnabled ?></TD></TR>
<TR<?php echo $c2 ?>><TD>Java applets supported</TD> <TD><?php echo $browAppletsCapable ?></TD></TR>
<TR<?php echo $c1 ?>><TD>Java applets enabled</TD> <TD><?php echo $browAppletsEnabled ?></TD></TR>
<TR<?php echo $c2 ?>><TD>Java Version</TD> <TD><?php echo $browJavaVersion ?></TD></TR>
<TR<?php echo $c1 ?>><TD>Java Vendor</TD> <TD><?php echo $browJavaVendor ?></TD></TR>
<TR<?php echo $c2 ?>><TD>Screen size</TD> <TD><?php echo $browScreenSize ?></TD></TR>
<TR<?php echo $c1 ?>><TD>Browser size</TD> <TD><?php echo $browBrowserSize ?></TD></TR>
<TR<?php echo $c2 ?>><TD>Connection type</TD> <TD><?php echo $browConnectionType ?></TD></TR>
<TR<?php echo $c1 ?>><TD>Connection speed</TD> <TD><?php echo $browConnectionSpeed ?></TD></TR>
<TR<?php echo $c2 ?>><TD>Color depth</TD> <TD><?php echo $browColorDepth ?></TD></TR>
<TR<?php echo $c1 ?>><TD>Flash</TD> <TD><?php echo $browPluginFlash ?></TD></TR>
<TR<?php echo $c2 ?>><TD>Shockwave</TD><TD><?php echo $browPluginShockwave ?></TD></TR>
<TR<?php echo $c1 ?>><TD>MediaPlayer</TD> <TD><?php echo $browPluginMediaPlayer ?></TD></TR>
<TR<?php echo $c2 ?>><TD>RealPlayer</TD><TD><?php echo $browPluginRealPlayer ?></TD></TR>
<TR<?php echo $c1 ?>><TD>Acrobat</TD> <TD><?php echo $browPluginAcrobat ?></TD></TR>
<TR<?php echo $c2 ?>><TD>QuickTime</TD> <TD><?php echo $browPluginQuickTime ?></TD></TR>
<TR<?php echo $c1 ?>><TD>Browser time</TD> <TD><?php echo $browDateTime ?></TD></TR>
<TR<?php echo $c2 ?>><TD>Time zone diff</TD> <TD><?php echo $browTimeZoneDiff ?></TD></TR>
</TABLE><P>
Note: BrowserHawk can detect over 100 properties.  This list represents 
just a sample of the properties available. You can easily modify this script
to include other properties.
</BLOCKQUOTE>

<P>
<HR>
<P>

<b><a href="browserinfo.php">Retry this test</a></b><P>
<b><a href="index.html">Return to list of other PHP samples</a></b><P>
<b><a href="http://www.cyscape.com/order/">BrowserHawk Pricing and Ordering</a></b><P>
<b><a href="http://www.cyscape.com/">cyScape home page</a></b><P>
</font>
</blockquote>
</BODY>
</HTML>

<?php
  } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
?>

<?php
// Our results processing follows.  It consists of formatting an email message
// to contain the results and then sending it to a support representative for
// follow up.  You of course can easily modify this to write the information
// to a file or database as well.

// ---- EMAIL CONFIGURATION SECTION -----
// By default this script is programmed to email the test results back to you
// (or your support group) using the com.oreilly.servlet.MailMessage component.
// See http://www.servlets.com/cos/ for the component.
// 
// Before submitting the form written out by this script please be sure to
// install this email component or if you prefer you can easily modify this
// script to use whatever email component you like - just update the 
// code found lower in the source accordingly.  
// 
// Set this to the address where you want the script to email the browser test
// results to

  $emailToAddr = "someone@somewhere.com";

  // Set this to the address of your SMTP server
  $emailSmtpServer = "smtp.somewhere.com";

  // After you have edited the above two variables change the emailConfigured
  // variable below to true
  $emailConfigured = false;

// ---- END EMAIL CONFIGURATION SECTION -----

  $results = "The following submission was made on ";
  $results .= date("F j, Y, g:i a");
  $results .= ":\r\n";

  $results .= "                  Name: ${_POST['name']} \r\n";
  $results .= "                 Email: ${_POST['email']} \r\n";

  $results .= "   Problem description: \r\n${_POST['desc']} \r\n";

  $results .= "            User agent: ${_SERVER['HTTP_USER_AGENT']} \r\n";

  $results .= "               Browser: ${_POST['browTypeAndVer']} \r\n";
  $results .= "         Browser build: ${_POST['browBuild']} \r\n";
  $results .= "              Platform: ${_POST['browPlatform']} \r\n";

  $results .= "     Cookies supported: ${_POST['browCookiesCapable']} \r\n";
  $results .= "       Cookies enabled: ${_POST['browCookiesEnabled']} \r\n";

  $results .= "  JavaScript supported: ${_POST['browJavaScriptCapable']} \r\n";
  $results .= "    JavaScript enabled: ${_POST['browJavaScriptEnabled']} \r\n";

  $results .= "          Java version: ${_POST['browJavaVersion']} \r\n";
  $results .= "           Java vendor: ${_POST['browJavaVendor']} \r\n";

  $results .= "       ActiveX enabled: ${_POST['browActiveXEnabled']} \r\n";
  $results .= "      VBScript enabled: ${_POST['browVBScriptEnabled']} \r\n";

  $results .= "     Applets supported: ${_POST['browAppletsCapable']} \r\n";
  $results .= "       Applets enabled: ${_POST['browAppletsEnabled']} \r\n";

  $results .= "           Screen size: ${_POST['browScreenSize']} \r\n";
  $results .= "          Browser size: ${_POST['browBrowserSize']} \r\n";
  $results .= "           Color depth: ${_POST['browColorDepth']} \r\n";

  $results .= "      Connection speed: ${_POST['browConnectionSpeed']} \r\n";
  $results .= "       Connection type: ${_POST['browConnectionType']} \r\n";

  $results .= "                 Flash: ${_POST['browPluginFlash']} \r\n";
  $results .= "             Shockwave: ${_POST['browPluginShockwave']} \r\n";
  $results .= "           MediaPlayer: ${_POST['browPluginMediaPlayer']} \r\n";
  $results .= "            RealPlayer: ${_POST['browPluginRealPlayer']} \r\n";
  $results .= "               Acrobat: ${_POST['browPluginAcrobat']} \r\n";
  $results .= "             QuickTime: ${_POST['browPluginQuickTime']} \r\n";

  $results .= "          Browser time: ${_POST['browDateTime']} \r\n";
  $results .= "        Time zone diff: ${_POST['browTimeZoneDiff']} \r\n"; 
  $results .= "\r\n";
  $results .= "Dump of all property settings: \r\n";
  $results .= $_POST['browAllDetails'];


  if ($emailConfigured) {
    $to = $emailToAddr;
    $subject = "Browser troubleshooting information for ${_POST['name']}";
    $message = $results;
    $headers = "From: ${_POST['name']} <${_POST['email']}>";

    $emailSent = mail($to, $subject, $message, $headers);
  }

  if (!$emailConfigured) {
?>

<H3>Information NOT sent</H3>
No mail was sent.  This page is not yet configured to send email.

<?php
  } else if ($emailConfigured && !$emailSent) {
?>

<H3>Information NOT sent</H3>
No mail was sent.  This is a server issue.

<?php
  } else {
?>

<blockquote>
<H3>Information sent</H3>
Your submission has been successfully sent.  Thank you for reporting this
issue.  A support representative will get back to you shortly.
<p>
DEBUG: Here's the message that was sent:
<pre>
<?php echo $message ?>
</pre>
</blockquote>

<?php
  } // end the else
?>

</body></html>

<?php
  }
?>
