~katiekitty/+junk/solidstate

« back to all changes in this revision

Viewing changes to solidstate/branches/v0.4/manager/pages/WelcomeEmailPage.class.php

  • 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
 * WelcomeEmailPage.class.php
 
4
 *
 
5
 * This file contains the definition for the EmailInvoicePage 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 Email class
 
14
require_once BASE_PATH ."solidworks/Email.class.php";
 
15
 
 
16
// Include the parent class
 
17
require_once BASE_PATH . "solidworks/Page.class.php";
 
18
 
 
19
// Include the AccountDBO
 
20
require_once BASE_PATH . "DBO/AccountDBO.class.php";
 
21
 
 
22
/**
 
23
 * WelcomeEmailPage
 
24
 *
 
25
 * This page takes the ID of the account to send a welcome email to.  
 
26
 * The body of the welcome email is read from a configuration file and the appropriate 
 
27
 * data is filled in with the customer's data.  The user is allowed to edit 
 
28
 * the raw content of the email, the subject, and the customers email address 
 
29
 * before the email is sent.
 
30
 *
 
31
 * @package Pages
 
32
 * @author John Diamond <jdiamond@solid-state.org>
 
33
 */
 
34
class WelcomeEmailPage extends Page
 
35
{
 
36
  /**
 
37
   * Initializes the Page
 
38
   *
 
39
   * Loads the DBO for the account ID provided as a GET paramenter
 
40
   */
 
41
  function init()
 
42
  {
 
43
    $id = $_GET['id'];
 
44
 
 
45
    if( isset( $id ) )
 
46
      {
 
47
        // Retrieve this Account from the database
 
48
        $dbo = load_AccountDBO( intval( $id ) );
 
49
      }
 
50
    else
 
51
      {
 
52
        // Retrieve DBO from session
 
53
        $dbo = $this->session['account_dbo'];
 
54
      }
 
55
 
 
56
    if( !isset( $dbo ) )
 
57
      {
 
58
        // Could not find Account in the database
 
59
        $this->setError( array( "type" => "DB_ACCOUNT_NOT_FOUND",
 
60
                                "args" => array( $id ) ) );
 
61
      }
 
62
    else
 
63
      {
 
64
        // Store Account DBO in session
 
65
        $this->session['account_dbo'] = $dbo;
 
66
      }
 
67
 
 
68
    // Place values on the template
 
69
    $this->smarty->assign( "email",      $dbo->getContactEmail() );
 
70
    $this->smarty->assign( "subject",    $this->conf['welcome_subject'] );
 
71
    $this->smarty->assign( "email_body", $this->conf['welcome_email'] );
 
72
  }
 
73
 
 
74
  /**
 
75
   * Handles actions for this Page
 
76
   *
 
77
   * Actions handled by this Page:
 
78
   *   email_invoice (Form)
 
79
   */
 
80
  function action( $action_name )
 
81
  {
 
82
    switch( $action_name )
 
83
      {
 
84
 
 
85
      case "welcome_email":
 
86
 
 
87
        if( isset( $this->session['welcome_email']['continue'] ) )
 
88
          {
 
89
            $this->send_email();
 
90
          }
 
91
        elseif( isset( $this->session['welcome_email']['cancel'] ) )
 
92
          {
 
93
            $this->cancel();
 
94
          }
 
95
 
 
96
        break;
 
97
 
 
98
      default:
 
99
        
 
100
        // No matching action, refer to base class
 
101
        parent::action( $action_name );
 
102
 
 
103
      }
 
104
  }
 
105
 
 
106
  /**
 
107
   * Return the user to the view account page
 
108
   */
 
109
  function cancel()
 
110
  {
 
111
    $this->goto( "accounts_view_account",
 
112
                 null,
 
113
                 "id=" . $this->session['account_dbo']->getID() );
 
114
  }
 
115
 
 
116
  /**
 
117
   * Email the welcome message and return to the view account page
 
118
   */
 
119
  function send_email()
 
120
  {
 
121
    // Construct an Email
 
122
    $email = new Email();
 
123
    $email->setFrom( $this->conf['company']['email'],
 
124
                     $this->conf['company']['name'] );
 
125
    $email->addRecipient( $this->session['welcome_email']['email'] );
 
126
    $email->setSubject( $this->session['welcome_email']['subject'] );
 
127
    $email->setBody( $this->session['welcome_email']['email_body'] );
 
128
 
 
129
    // Send the email
 
130
    if( !$email->send() )
 
131
      {
 
132
        // Error delivering invoice
 
133
        $this->setError( array( "type" => "WELCOME_EMAIL_FAILED" ) );
 
134
        $this->goto( "accounts_view_account",
 
135
                     null,
 
136
                     "id=" . $this->session['account_dbo']->getID() );
 
137
      }
 
138
 
 
139
    // Return to view_account with a sucess message
 
140
    $this->setMessage( array( "type" => "WELCOME_SENT" ) );
 
141
    $this->goto( "accounts_view_account",
 
142
                 null,
 
143
                 "id=" . $this->session['account_dbo']->getID() );
 
144
  }
 
145
}
 
146
 
 
147
?>
 
 
b'\\ No newline at end of file'