/** * Delete AccountDBO from database * * @param AccountDBO &$dbo Account DBO to delete * @return boolean True on success */ function delete_AccountDBO(&$dbo) { $DB = DBConnection::getDBConnection(); $id = intval($dbo->getID()); // Delete any HostingSericePurchases assigned to this account try { $hosting_array = load_array_HostingServicePurchaseDBO("accountid=" . $id); foreach ($hosting_array as $hosting_dbo) { delete_HostingServicePurchaseDBO($hosting_dbo); } } catch (DBNoRowsFoundException $e) { } // Delete any DomainSericePurchases assigned to this account try { $domain_array = load_array_DomainServicePurchaseDBO("accountid=" . $id); foreach ($domain_array as $domain_dbo) { delete_DomainServicePurchaseDBO($domain_dbo); } } catch (DBNoRowsFoundException $e) { } // Delete any ProductPurchases assigned to this account try { $product_array = load_array_ProductPurchaseDBO("accountid=" . $id); foreach ($product_array as $product_dbo) { delete_ProductPurchaseDBO($product_dbo); } } catch (DBNoRowsFoundException $e) { } // Delete any Invoices assigned to this account try { $invoice_array = load_array_InvoiceDBO("accountid=" . $id); foreach ($invoice_array as $invoice_dbo) { delete_InvoiceDBO($invoice_dbo); } } catch (DBNoRowsFoundException $e) { } // Delete any Orders assigned to this account try { $orders = load_array_OrderDBO("accountid=" . $id); foreach ($orders as $orderDBO) { delete_OrderDBO($orderDBO); } } catch (DBNoRowsFoundException $e) { } // Delete the account's user delete_UserDBO($dbo->getUserDBO()); // Build SQL $sql = $DB->build_delete_sql("account", "id = " . $id); // Delete the AccountDBO if (!mysql_query($sql, $DB->handle())) { throw new DBException(mysql_error($DB->handle())); } }
/** * Assign Service * * Create a HostingServicePurchaseDBO and add it to the database */ function assign_service() { // If this HostingService requires a unique IP, make sure the user selected one if ($this->post['service']->getUniqueIP() == "Required" && !isset($this->post['ipaddress'])) { throw new FieldMissingException("ipaddress"); } // If this HostingService requires a domain, make sure the user selected one if ($this->post['service']->isDomainRequired() && !isset($this->post['domainname'])) { throw new FieldMissingException("domainname"); } // Create new HostingServicePurchase DBO $serverID = isset($this->post['server']) ? $this->post['server']->getID() : null; $purchase_dbo = new HostingServicePurchaseDBO(); $purchase_dbo->setAccountID($this->get['account']->getID()); $purchase_dbo->setPurchasable($this->post['service']); $purchase_dbo->setTerm(isset($this->post['term']) ? $this->post['term']->getTermLength() : null); $purchase_dbo->setServerID($serverID); $purchase_dbo->setDate(DBConnection::format_datetime($this->post['date'])); $purchase_dbo->setDomainName($this->post['domainname']); $purchase_dbo->setNote($this->post['note']); // Save purchase add_HostingServicePurchaseDBO($purchase_dbo); // If an IP address was selected, assign that IP address to this purchase if (isset($this->post['ipaddress'])) { if ($this->post['ipaddress']->getServerID() != $serverID) { // Roll-back delete_HostingServicePurchaseDBO($purchase_dbo); throw new SWUserException("[IP_MISMATCH]"); } // Update IP Address record $this->post['ipaddress']->setPurchaseID($purchase_dbo->getID()); try { update_IPAddressDBO($this->post['ipaddress']); } catch (DBException $e) { // Roll-back delete_HostingServicePurchaseDBO($purchase_dbo); throw new SWUserException("[DB_IP_UPDATE_FAILED]"); } } // Success $this->setMessage(array("type" => "[HOSTING_ASSIGNED]")); $this->gotoPage("accounts_view_account", null, "action=services&account=" . $this->get['account']->getID()); }
/** * Delete Hosting Service * * Remove a hosting service purchase from this account */ function deleteHosting() { // Delete the service purchases foreach ($this->post['services'] as $dbo) { delete_HostingServicePurchaseDBO($dbo); } // Success $this->setMessage(array("type" => "[HOSTING_PURCHASES_DELETED]")); $this->setURLField("action", "services"); $this->reload(); }