~katiekitty/+junk/solidstate

« back to all changes in this revision

Viewing changes to solidstate/trunk/manager/pages/.svn/text-base/AssignHostingPage.class.php.svn-base

  • Committer: root
  • Date: 2010-01-13 07:44:31 UTC
  • Revision ID: root@ds3-vamp.cs-monitor.cz.cc-20100113074431-kt8ceoeznpjg22x7
Reviving the project

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * AssignHostingPage.class.php
 
4
 *
 
5
 * This file contains the definition for the AssignHostingPage class
 
6
 *
 
7
 * @package Pages
 
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
 
11
 */
 
12
 
 
13
// Include the parent class
 
14
require BASE_PATH . "include/SolidStatePage.class.php";
 
15
 
 
16
/**
 
17
 * AssignHostingPage
 
18
 *
 
19
 * Assign a hosting service purchase to an account.
 
20
 *
 
21
 * @package Pages
 
22
 * @author John Diamond <jdiamond@solid-state.org>
 
23
 */
 
24
class AssignHostingPage extends SolidStatePage
 
25
{
 
26
  /**
 
27
   * Action
 
28
   *
 
29
   * Actions handled by this page:
 
30
   *   assign_hosting (form)
 
31
   *
 
32
   * @param string $action_name Action
 
33
   */
 
34
  function action( $action_name )
 
35
  {
 
36
    switch( $action_name )
 
37
      {
 
38
      case "assign_hosting":
 
39
        if( isset( $this->post['continue'] ) )
 
40
          {
 
41
            // Add service to account
 
42
            $this->assign_service();
 
43
          }
 
44
        elseif( isset( $this->post['cancel'] ) )
 
45
          {
 
46
            // Cancel
 
47
            $this->goback();
 
48
          }
 
49
        elseif( isset( $this->post['service'] ) )
 
50
          {
 
51
            $this->updatePrices( $this->post['service'] );
 
52
          }
 
53
        break;
 
54
 
 
55
      default:
 
56
        // No matching action - refer to base class
 
57
        parent::action( $action_name );
 
58
      }
 
59
  }
 
60
 
 
61
  /**
 
62
   * Assign Service
 
63
   *
 
64
   * Create a HostingServicePurchaseDBO and add it to the database
 
65
   */
 
66
  function assign_service()
 
67
  {
 
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'] ) )
 
71
      {
 
72
        throw new FieldMissingException( "ipaddress" );
 
73
      }
 
74
 
 
75
    // If this HostingService requires a domain, make sure the user selected one
 
76
    if( $this->post['service']->isDomainRequired() && 
 
77
        !isset( $this->post['domainname'] ) )
 
78
      {
 
79
        throw new FieldMissingException( "domainname" );
 
80
      }
 
81
 
 
82
    // Create new HostingServicePurchase DBO
 
83
    $serverID = isset( $this->post['server'] ) ? $this->post['server']->getID() : null;
 
84
 
 
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'] );
 
94
 
 
95
    // Save purchase
 
96
    add_HostingServicePurchaseDBO( $purchase_dbo );
 
97
 
 
98
    // If an IP address was selected, assign that IP address to this purchase
 
99
    if( isset( $this->post['ipaddress'] ) )
 
100
      {
 
101
        if( $this->post['ipaddress']->getServerID() != $serverID )
 
102
          {
 
103
            // Roll-back
 
104
            delete_HostingServicePurchaseDBO( $purchase_dbo );
 
105
            throw new SWUserException( "[IP_MISMATCH]" );
 
106
          }
 
107
 
 
108
        // Update IP Address record
 
109
        $this->post['ipaddress']->setPurchaseID( $purchase_dbo->getID() );
 
110
        try{ update_IPAddressDBO( $this->post['ipaddress'] ); }
 
111
        catch( DBException $e )
 
112
          {
 
113
            // Roll-back
 
114
            delete_HostingServicePurchaseDBO( $purchase_dbo );
 
115
            throw new SWUserException( "[DB_IP_UPDATE_FAILED]" );
 
116
          }
 
117
      }
 
118
    
 
119
    // Success
 
120
    $this->setMessage( array( "type" => "[HOSTING_ASSIGNED]" ) );
 
121
    $this->goto( "accounts_view_account",
 
122
                 null,
 
123
                 "action=services&account=" . $this->get['account']->getID() );
 
124
  }
 
125
 
 
126
  /**
 
127
   * Initialize Assign Hosting Page
 
128
   */
 
129
  function init()
 
130
  {
 
131
    parent::init();
 
132
 
 
133
    // Set URL Fields
 
134
    $this->setURLField( "account", $this->get['account']->getID() );
 
135
 
 
136
    // Store service DBO in session
 
137
    $this->session['account_dbo'] =& $this->get['account'];
 
138
 
 
139
    try { $services = load_array_HostingServiceDBO(); }
 
140
    catch( DBNoRowsFoundException $e )
 
141
      {
 
142
        throw new SWUserException( "[THERE_ARE_NO_HOSTING_SERVICES]" );
 
143
      }
 
144
 
 
145
    if( !isset( $this->post['service'] ) )
 
146
      {
 
147
        $this->updatePrices( array_shift( $services ) );
 
148
      }
 
149
  }
 
150
 
 
151
  /**
 
152
   * Update Prices Box
 
153
   *
 
154
   * @param HostingServiceDBO The hosting service to show prices for
 
155
   */
 
156
  protected function updatePrices( HostingServiceDBO $serviceDBO )
 
157
  {
 
158
    // Update the service terms box
 
159
    $widget = $this->forms['assign_hosting']->getField( "term" )->getWidget();
 
160
    $widget->setPurchasable( $serviceDBO );
 
161
 
 
162
    // Indicate if this hosting service requires a domainname
 
163
    $this->smarty->assign( "domainIsRequired", $serviceDBO->isDomainRequired() );
 
164
  }
 
165
}
 
 
b'\\ No newline at end of file'