<?php

require_once 'config.php';
require_once 'confidentcaptcha/ccap_api.php';
$ccap_api = new CCAP_API($ccap_api_settings['customer_id'], $ccap_api_settings['site_id'], $ccap_api_settings['api_username'], $ccap_api_settings['api_password'], $ccap_server_url);
// Has the configuration been tested?
$cred_check = $ccap_api->check_credentials();
if ($cred_check->status != 200) {
    $credentials_good = FALSE;
} else {
    $credentials_good = FALSE === stripos($cred_check->body, "api_failed='True'");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>Confident CAPTCHA - PHP Library and Sample Code</title>
</head>
<body>
  <h1>PHP Library and Sample Code for Confident CAPTCHA</h1>

<?php 
if ($credentials_good) {
    ?>
<p>
The samples are:
</p>
<ul>
  <li><a href="check.php">check.php</a> - Check if your
    configuration is supported by Confident CAPTCHA</li>
 * The code is a bit complex, indended to be viewed from a browser rather than
 * read as code.  See 'sample_before.php' and 'sample_after.php' for a
 * practical example of how to add Confident CAPTCHA to your own forms.  Be
 * sure to also look for a plugin for your platform, which is even easier.
 */
require_once 'config.php';
require_once 'confidentcaptcha/ccap_api.php';
require_once 'confidentcaptcha/ccap_persist.php';
require_once 'confidentcaptcha/ccap_policy_factory.php';
// Get a value from an array, or NULL
function array_get($a, $key)
{
    return isset($a[$key]) ? $a[$key] : NULL;
}
// Use configured state as the working API
$ccap_api_good = new CCAP_API($ccap_api_settings['customer_id'], $ccap_api_settings['site_id'], $ccap_api_settings['api_username'], $ccap_api_settings['api_password'], $ccap_server_url);
// Has the configuration been tested?
$settings_good = array_get($_REQUEST, 'ccap_settings_good');
if (!$settings_good) {
    $cred_check = $ccap_api_good->check_credentials();
    if ($cred_check->status != 200) {
        $settings_good = FALSE;
    } else {
        $settings_good = FALSE === stripos($cred_check->body, "api_failed='True'");
    }
}
// Use a working system or a bad one?
$fail_sim = array_get($_REQUEST, 'ccap_fail_sim');
$valid_fail_sims = array('' => 'No simulated API failure.', 'bad_credentials' => 'All API calls using API credentials will fail with
        HTTP code 401 NOT AUTHORIZED, as if using bad credentials.', 'server_not_responding' => 'All API calls will fail with status 0,
        as if the CAPTCHA API server is unavailable.');