<?php

# --------------------------------------------------------
# Populate users_domains table for EXISTING installs
# --------------------------------------------------------

if (INSTALLED) {
    require_once dirname(__FILE__).'/../../../../modules/domains/models/DomainName.php';
    
    $query = 'select d.DomainName, rf.amount, rf.nextbilldate, rf.paymentterm, d.username, d.password, rf.customerid, d.registrar_orderid, d.register, d.domain_extra_attr from recurringfee rf, domains d where rf.billingtypeid=-2 AND rf.appliestoid=d.id';
    $result = mysql_query($query);
    while (list($domainName, $cost, $nextbilldate, $paymentterm, $username, $password, $userid, $registrarOrderId, $registerOption, $extraAttr) = mysql_fetch_array($result)) {
        $registrar = '';
        $orderid = '';
        $regInfo = explode('-', $registrarOrderId);
        if (sizeof($regInfo) == 1) {
            $orderid = $regInfo[0];
        } elseif (sizeof($regInfo) > 1) {
            $registrar = strtolower($regInfo[0]);
            $orderid = $regInfo[1];
        }
        $properties = array(
                    'm_userId'              => $userid,
                    'm_domain'              => $domainName,
                    'm_username'            => $username,
                    'm_password'            => $password,
                    'm_period'              => $paymentterm / 12,
                    'm_nextBillDate'        => $nextbilldate,
                    'm_domain_extra_attr'   => $extraAttr,
                    'm_registration_option' => $registerOption,
                    'm_registrar'           => $registrar,
                    'm_registrarOrderID'    => $orderid,
                    'm_status'              => 1,
                );
         $domain = new DomainName($properties, $this->user);
         $domain->save();
    }
}

?>
