<?php
$env = "";
if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'boasearch' ) {
    $env = "dev";
}

if ((!isset($_REQUEST['recordType']) || empty($_REQUEST['recordType'])) &&
    (!isset($_REQUEST['license']) || empty($_REQUEST['license']))    ) {
    echo '';
    exit;
}
$license = htmlspecialchars(stripslashes(trim($_REQUEST['license'])));
$recordType = strtolower(htmlspecialchars(stripslashes(trim($_REQUEST['recordType']))));

if ($license == '') exit;

require_once '../lib/Licensees.php';
$ldb = new Licensees($env);


include 'print_header.php';
?>
    <div class="ui-dialog-content ui-widget-content print">
<div id="detail-data" class="print">

<?php
if ($recordType == "firm") {
    $firmData = $ldb->fetchFirmLicensee($license);

    //$firmLicensees = $ldb->fetchFirmIndividuals($license);
    $firmLicensees = $ldb->fetchFirmIndividualsByFirmName($firmData[0]['name']);

    $firm = new stdClass();
    if (isset($firmData) && is_array($firmData)) {
        $firm->data = $firmData[0];
        $firm->licensees = $firmLicensees;
    }

    $licenseeData = print_firm($firm);
} else {
    $licenseeData = print_individual($ldb->fetchIndividualLicensee($license));
}
?>
</div>
</div>
<?php
//echo $licenseeData;

include 'print_footer.php';

function print_individual($licensee) {
    if (isset($licensee) && is_array($licensee)) {
        $l = $licensee[0];
        ?>
        <table><thead><tr><th colspan="2">Individual Information</th></tr></thead><tbody>
         <tr><td>License Number</td><td> <?php print $l['license_no'] ?></td></tr>
         <tr><td>Status</td><td> <?php print $l['status'] ?></td></tr>
         <tr><td>Type</td><td> <?php print $l['type'] ?></td></tr>
         <tr><td>Name</td><td> <?php print $l['full_name'] ?></td></tr>
         <tr><td>Address</td><td> <?php print doAddress($l) ?></td></tr>
         <tr><td>Date License Granted</td><td> <?php print $l['date_licensed'] ?></td></tr>
         <tr><td>Expires</td><td> <?php print $l['date_expires'] ?></td></tr>
         <tr><td>Firm Name</td><td> <?php print $l['firm_name'] ?></td></tr>
         <tr><td>Muni</td><td> <?php print $l['muni'] ?></td></tr>
         <tr><td>CPE Carryover Hours</td><td> <?php print $l['cpe_carryover'] ?></td></tr>
         <tr><td>Disciplinary</td><td> <?php print $l['complaints'] ?></td></tr>
         </tbody></table>
        <?php
    }

}


function print_firm($firm) {
    $f = $firm->data;
    $ls = $firm->licensees;
    ?>
    <div id="firm-left"><table><thead><tr><th colspan="2">Firm Information</th></tr></thead><tbody>
    <tr><td>Firm Number</td><td><?php print $f['license_no']; ?></td></tr>
    <tr><td>Name</td><td><?php print $f['name']; ?></td></tr>
    <tr><td>Address</td><td><?php print doAddress($f) ?></td></tr>
    <tr><td>Status</td><td><?php print $f['status']; ?></td></tr>
    <tr><td>Type</td><td><?php print $f['type']; ?></td></tr>
    <tr><td>Date License Granted</td><td><?php print $f['date_granted']; ?></td></tr>
    <tr><td>Expires</td><td><?php print $f['date_expires']; ?></td></tr>
    <tr><td>Managing Partner</td><td><?php print $f['owner']; ?></td></tr>
    <tr><td>Disciplinary</td><td><?php print $f['complaints']; ?></td></tr>
    </tbody></table>
    <?php doComplaints($f['complaints']); ?>
    </div>
    <?php 
    if (is_array($ls) && count($ls) > 0) {
    ?>
    <div id="firm-right"><table id="licensees-list">
        <thead>
        <tr>
            <th>Licensees</th>
            <th>Expires</th>
            <th>Status</th>
        </thead><tbody>
        <?php

        foreach ($ls as $l) {
            ?>

            <tr class="row-data">
                <td><?php print $l['full_name2']; ?></td>
                <td><?php print $l['date_expires']; ?></td>
                <td><?php print $l['status']; ?></td>
                <td><?php print $l['license_no']; ?></td>
            </tr>
            <?php
        }
        ?>
        </tbody></table></div>

        <?php
    }
    ?>
    <?php

}

function doAddress($data) {
    $address = "";
    $address .= $data['address'];

    if (!empty($data['address1'])) $address .= $data['address1'];
    if (!empty($data['address2'])) $address .= $data['address2'];

    if ($data['city'] === '' || $data['state'] === '') {
        $address .= "<br />" . $data['city']  . " " . $data['state'] . " " . $data['zip'];
    } else {
        $address .= "<br />" . $data['city']  . ", " . $data['state'] . " " . $data['zip'];
    }

    return $address;
}
function doComplaints($complaints) {
    if (strtolower($complaints) === "yes" ) {
    ?>
            <div id="complaints"> A 'Yes' answer in the disciplinary column indicates that the
            Oregon Board of Accountancy's record of the CPA, PA or registered firm includes a final outcome
            of one or more disciplinary actions.  More detail on disciplinary actions is available on the
            front page of the Board’s web site through the continually updated Disciplinary Action Report,
            posted in alphabetical and chronological order.  Discipline is reported as 'yes' when the outcome
            is a final resolution of the matter.  This means that if the Board has proposed disciplinary action,
             but the matter is not yet resolved either through a legal process or settlement agreement, it
            will not be flagged with a 'Yes' in the disciplinary column. If you need additional information
            on a disciplinary action beyond what is reported on the Board's web site,
            please contact Joel Parks at 503-378-2262 or by e-mail at joel.parks@oregon.gov
            </div>
    <?php
    }
}




