#!/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';
    require('lol_common.inc');

    $vl = new vendor();

    $query = "SELECT * FROM vendor WHERE active <> 3";

    $vendorList = $vl->db->getAll($query);

    $total = count($vendorList);
    
    $i = 0;
    $import = new vendor();
    $contact = new contact();

    foreach($vendorList as $v) {
        if(!($i++ % 20)) { print(CRLF . "Migrating {$i} of {$total}: "); }

        $import->clear();
        $import->id = $v['id'];
        $import->website = $v['website'];
        $import->logo = $v['logo'];
        $import->company_name = $v['comp_name'];
        $import->vendor_type_id = $v['vendor_type_id'];
        $import->xlist = $v['xlist'];
        $import->profile = $v['profile'];
        $import->input_date = $v['sign_up'];
        $import->edit_date = $v['date_edited'];
        $import->sentpass = $v['sentpass'];
        $import->info_request = $v['request'];
        $import->active = 1;

        if($v['active'] == 0 || $v['active'] == 3) {
            $import->active = 0;
            $import->status = 0;
        } else if($v['hot'] == 0) {
            $import->status = 2;
        } else if($v['hot'] == 1) {
            $import->status = 16;
        } else if($v['hot'] == 2) {
            $import->status = 4;
        } else if($v['hot'] == 3) {
            $import->status = 8;
        }

        $import->commit(TRUE);

        $contact->clear();
        $contact->ref_type = 'ven';
        $contact->ref_id = $v['id'];
        $contact->code = 'primary';
        $contact->first_name = $v['first_name'];
        $contact->last_name = $v['last_name'];
        $contact->address1 = $v['address'];
        $contact->address2 = $v['address2'];
        $contact->city = $v['city'];
        $contact->state = $v['state'];
        $contact->postal_code = $v['zip'];
        $contact->phone_area_code = $v['area_code'];
        $contact->phone_number = $v['phone'];
        $contact->fax_area_code = $v['area_fax'];
        $contact->fax_number = $v['fax'];
        $contact->email = $v['email'];
        $contact->input_date = $v['sign_up'];
        $contact->edit_date = $v['date_edited'];
        $contact->country = $v['country'];
        $contact->commit();

        $contact->clear();
        $contact->ref_type = 'ven';
        $contact->ref_id = $v['id'];
        $contact->code = 'company';
        $contact->address1 = $v['address'];
        $contact->address2 = $v['address2'];
        $contact->city = $v['city'];
        $contact->state = $v['state'];
        $contact->postal_code = $v['zip'];
        $contact->phone_area_code = $v['area_code'];
        $contact->phone_number = $v['phone'];
        $contact->fax_area_code = $v['area_fax'];
        $contact->fax_number = $v['fax'];
        $contact->input_date = $v['sign_up'];
        $contact->edit_date = $v['date_edited'];
        $contact->country = $v['country'];
        $contact->email = $v['email'];
        $contact->commit();

        echo(' * ');
    }
    print(CRLF);
?>
