/**
  * 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 HostingServicePriceDBO();
     $priceDBO->setServiceID($this->get['hservice']->getID());
     $priceDBO->setType($this->post['type']);
     $priceDBO->setTermLength($this->post['termlength']);
     $priceDBO->setPrice($this->post['price']);
     $priceDBO->setTaxable($this->post['taxable']);
     try {
         $this->get['hservice']->addPrice($priceDBO);
         add_HostingServicePriceDBO($priceDBO);
         $this->setMessage(array("type" => "[PRICE_ADDED]"));
     } catch (DuplicatePriceException $e) {
         update_HostingServicePriceDBO($priceDBO);
         $this->setMessage(array("type" => "[PRICE_UPDATED]"));
     }
     $this->reload("&sstab=pricing");
 }
/**
 * Insert HostingServiceDBO into database
 *
 * @param HostingServiceDBO &$dbo HostingServiceDBO to add to database
 */
function add_HostingServiceDBO(&$dbo)
{
    $DB = DBConnection::getDBConnection();
    // Build SQL
    $sql = $DB->build_insert_sql("hostingservice", array("title" => $dbo->getTitle(), "description" => $dbo->getDescription(), "uniqueip" => $dbo->getUniqueIP(), "domainrequirement" => $dbo->getDomainRequirement(), "public" => $dbo->getPublic()));
    // Run query
    if (!mysql_query($sql, $DB->handle())) {
        throw new DBException(mysql_error($DB->handle()));
    }
    // Get auto-increment ID
    $id = mysql_insert_id($DB->handle());
    // Validate ID
    if ($id === false) {
        // DB error
        throw new DBException("Could not retrieve ID from previous INSERT!");
    }
    if ($id == 0) {
        // No ID?
        throw new DBException("Previous INSERT did not generate an ID");
    }
    // Store ID in DBO
    $dbo->setID($id);
    // Add all the PriceDBO's for this object
    foreach ($dbo->getPricing() as $price) {
        add_HostingServicePriceDBO($price);
    }
}