3
* AssignHostingPage.class.php
5
* This file contains the definition for the AssignHostingPage class
8
* @author John Diamond <jdiamond@solid-state.org>
9
* @copyright John Diamond <jdiamond@solid-state.org>
10
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
13
// Include the parent class
14
require BASE_PATH . "include/SolidStatePage.class.php";
19
* Assign a hosting service purchase to an account.
22
* @author John Diamond <jdiamond@solid-state.org>
24
class AssignHostingPage extends SolidStatePage
29
* Actions handled by this page:
30
* assign_hosting (form)
32
* @param string $action_name Action
34
function action( $action_name )
36
switch( $action_name )
38
case "assign_hosting":
39
if( isset( $this->post['continue'] ) )
41
// Add service to account
42
$this->assign_service();
44
elseif( isset( $this->post['cancel'] ) )
49
elseif( isset( $this->post['service'] ) )
51
$this->updatePrices( $this->post['service'] );
56
// No matching action - refer to base class
57
parent::action( $action_name );
64
* Create a HostingServicePurchaseDBO and add it to the database
66
function assign_service()
68
// If this HostingService requires a unique IP, make sure the user selected one
69
if( $this->post['service']->getUniqueIP() == "Required" &&
70
!isset( $this->post['ipaddress'] ) )
72
throw new FieldMissingException( "ipaddress" );
75
// If this HostingService requires a domain, make sure the user selected one
76
if( $this->post['service']->isDomainRequired() &&
77
!isset( $this->post['domainname'] ) )
79
throw new FieldMissingException( "domainname" );
82
// Create new HostingServicePurchase DBO
83
$serverID = isset( $this->post['server'] ) ? $this->post['server']->getID() : null;
85
$purchase_dbo = new HostingServicePurchaseDBO();
86
$purchase_dbo->setAccountID( $this->get['account']->getID() );
87
$purchase_dbo->setPurchasable( $this->post['service'] );
88
$purchase_dbo->setTerm( isset( $this->post['term'] ) ?
89
$this->post['term']->getTermLength() : null );
90
$purchase_dbo->setServerID( $serverID );
91
$purchase_dbo->setDate( DBConnection::format_datetime( $this->post['date'] ) );
92
$purchase_dbo->setDomainName( $this->post['domainname'] );
93
$purchase_dbo->setNote( $this->post['note'] );
96
add_HostingServicePurchaseDBO( $purchase_dbo );
98
// If an IP address was selected, assign that IP address to this purchase
99
if( isset( $this->post['ipaddress'] ) )
101
if( $this->post['ipaddress']->getServerID() != $serverID )
104
delete_HostingServicePurchaseDBO( $purchase_dbo );
105
throw new SWUserException( "[IP_MISMATCH]" );
108
// Update IP Address record
109
$this->post['ipaddress']->setPurchaseID( $purchase_dbo->getID() );
110
try{ update_IPAddressDBO( $this->post['ipaddress'] ); }
111
catch( DBException $e )
114
delete_HostingServicePurchaseDBO( $purchase_dbo );
115
throw new SWUserException( "[DB_IP_UPDATE_FAILED]" );
120
$this->setMessage( array( "type" => "[HOSTING_ASSIGNED]" ) );
121
$this->goto( "accounts_view_account",
123
"action=services&account=" . $this->get['account']->getID() );
127
* Initialize Assign Hosting Page
134
$this->setURLField( "account", $this->get['account']->getID() );
136
// Store service DBO in session
137
$this->session['account_dbo'] =& $this->get['account'];
139
try { $services = load_array_HostingServiceDBO(); }
140
catch( DBNoRowsFoundException $e )
142
throw new SWUserException( "[THERE_ARE_NO_HOSTING_SERVICES]" );
145
if( !isset( $this->post['service'] ) )
147
$this->updatePrices( array_shift( $services ) );
154
* @param HostingServiceDBO The hosting service to show prices for
156
protected function updatePrices( HostingServiceDBO $serviceDBO )
158
// Update the service terms box
159
$widget = $this->forms['assign_hosting']->getField( "term" )->getWidget();
160
$widget->setPurchasable( $serviceDBO );
162
// Indicate if this hosting service requires a domainname
163
$this->smarty->assign( "domainIsRequired", $serviceDBO->isDomainRequired() );
b'\\ No newline at end of file'