/**
  * Add Price
  */
 protected function addPrice()
 {
     if ($this->post['type'] == "Onetime" && $this->post['termlength'] != 0) {
         throw new SWUserException("[TERMLENGTH_FOR_ONETIME_MUST_BE_ZERO]");
     }
     if ($this->post['type'] == "Recurring" && $this->post['termlength'] == 0) {
         throw new SWUserException("[TERMLENGTH_FOR_RECURRING_MUST_NOT_BE_ZERO]");
     }
     $priceDBO = new DomainServicePriceDBO();
     $priceDBO->setTLD($this->get['dservice']->getTLD());
     $priceDBO->setType($this->post['type']);
     $priceDBO->setTermLength($this->post['termlength']);
     $priceDBO->setPrice($this->post['price']);
     $priceDBO->setTaxable($this->post['taxable']);
     try {
         $this->get['dservice']->addPrice($priceDBO);
         add_DomainServicePriceDBO($priceDBO);
         $this->setMessage(array("type" => "[PRICE_ADDED]"));
     } catch (DuplicatePriceException $e) {
         update_DomainServicePriceDBO($priceDBO);
         $this->setMessage(array("type" => "[PRICE_UPDATED]"));
     }
     $this->reload("&sstab=pricing");
 }
/**
 * Load multiple DomainServicePriceDBO's from database
 *
 * @param string $filter A WHERE clause
 * @param string $sortby Field name to sort results by
 * @param string $sortdir Direction to sort in (ASEC or DESC)
 * @param int $limit Limit the number of results
 * @param int $start Record number to start the results at
 * @return array Array of DomainServiceDBO's
 */
function load_array_DomainServicePriceDBO($filter = null, $sortby = null, $sortdir = null, $limit = null, $start = null)
{
    $DB = DBConnection::getDBConnection();
    // Build query
    $sql = $DB->build_select_sql("domainserviceprice", "*", $filter, $sortby, $sortdir, $limit, $start);
    // Run query
    if (!($result = @mysql_query($sql, $DB->handle()))) {
        // Query error
        throw new DBException(mysql_error($DB->handle()));
    }
    if (mysql_num_rows($result) == 0) {
        // No services found
        throw new DBNoRowsFoundException();
    }
    // Build an array of DomainServicePriceDBOs from the result set
    $price_dbo_array = array();
    while ($data = mysql_fetch_array($result)) {
        // Create and initialize a new DomainServiceDBO with the data from the DB
        $dbo = new DomainServicePriceDBO();
        $dbo->load($data);
        // Add DomainServiceDBO to array
        $price_dbo_array[] = $dbo;
    }
    return $price_dbo_array;
}
Ejemplo n.º 3
0
/**
 * Delete DomainServiceDBO from database
 *
 * @param DomainServiceDBO &$dbo DomainServiceDBO to delete
 * @return boolean True on success
 */
function delete_DomainServiceDBO(&$dbo)
{
    $DB = DBConnection::getDBConnection();
    // Verify that no purchases exist
    try {
        $tld = $dbo->getTLD();
        load_array_DomainServicePurchaseDBO("tld = '" . $dbo->getTLD() . "'");
        // Can not delete domain service if any purchases exist
        throw new DBException("[PURCHASES_EXIST]");
    } catch (DBNoRowsFoundException $e) {
    }
    // Build SQL
    $sql = $DB->build_delete_sql("domainservice", "tld = " . $DB->quote_smart($dbo->getTLD()));
    // Run query
    if (!mysql_query($sql, $DB->handle())) {
        throw new DBException(mysql_error($DB->handle()));
    }
    // Delete all prices belonging to the deleted domain service.
    $domainPrices = new DomainServicePriceDBO();
    $domainPrices->setTLD($tld);
    deleteAll_DomainServicePriceDBO($domainPrices);
}