#!/usr/bin/php
<?php
    define('CRLF',"\r\n");
    ini_set('include_path',ini_get('include_path') . ":/data/sites/www.landscapeonline.com/includes");

    $requiredClasses[] = 'base/vendor_listing.php';
    $requiredClasses[] = 'base/xlist_class.php';

    require('lol_common.inc');
    
    $xl = new xlist();
    $query = "SELECT id, type_biz, status FROM subscribe WHERE active=1 AND list='yes'";

    $slist = $xl->db->getAll($query);

    if(DB::isError($slist)) {
        printf("Error getting vendor list: "  . $slist->getMessage() . CRLF);
        return(FALSE);
    }

    $query = "SELECT * from type_biz";
    $bType = $xl->db->getAll($query);

    if(DB::isError($bType)) {
        printf("Error getting vendor list: "  . $bType->getMessage() . CRLF);
        return(FALSE);
    }

    $vXl = array();
    foreach($slist as $id => $obj) {
        foreach(explode(',',$obj['type_biz']) as $x) {
            $vXl[] = $x;
        }
    }


    $zzz = array_count_values($vXl);

    //print_r($zzz);
    foreach($bType as $o) {
        switch($o['idParent']) {
            case 0:
                $l = 'LASN';
                break;
            case 1:
                $l = 'LCN';
                break;
            case 2:
                $l = 'LSMP';
                break;
        }
        print(trim($o['name']) . " [{$l}]: {$zzz[$o['id']]}" . CRLF);
    }

    /*

    printf("Total Vendors: " . count($vlist) . CRLF);

    $parents = $xl->fetchXlistParentArray();
    foreach($parents as $p) {
        print("{$p['id']}: {$p['name']}" . CRLF);
        $children = $xl->fetchXlistChildrenArray($p['id']);
        $pCount = 0;
        foreach($children as $c) {
            if(!array_key_exists($c['id'], $zzz)) {
                $zzz[$c['id']] = 0;
            } else {
            }
            $pCount += $zzz[$c['id']];
            print("\t{$c['sub_number']}:: {$c['name']}: {$zzz[$c['id']]}" . CRLF);
        }
        print(CRLF . "*** Total for {$p['name']}: {$pCount} ***" . CRLF . CRLF);
    }
    */
?>
