OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / contactus / include / container / contactusWidgetContainer.php
1 <?php
2 /**
3  * コンテナクラス
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
9  * @package    Magic3 Framework
10  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11  * @copyright  Copyright 2006-2012 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: contactusWidgetContainer.php 5455 2012-12-10 13:21:36Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() .                 '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() .   '/contactus_mainDb.php');
18
19 class contactusWidgetContainer extends BaseWidgetContainer
20 {
21         private $db;    // DB接続オブジェクト
22         private $langId;        // 表示言語
23         private $state;         // 都道府県
24         const CONTACTUS_FORM = 'contact_us';            // お問い合わせフォーム
25         const DEFAULT_SEND_MESSAGE = 1;         // メール送信機能を使用するかどうか(デフォルト使用)
26         const DEFAULT_TITLE_NAME = 'お問い合わせ';        // デフォルトのタイトル名
27         const DEFAULT_STR_REQUIRED = '<font color="red">*必須</font>';                // 「必須」表示用テキスト
28         
29         /**
30          * コンストラクタ
31          */
32         function __construct()
33         {
34                 // 親クラスを呼び出す
35                 parent::__construct();
36                 
37                 // DBオブジェクト作成
38                 $this->db = new contactus_mainDb();
39         }
40         /**
41          * テンプレートファイルを設定
42          *
43          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
44          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
45          *
46          * @param RequestManager $request               HTTPリクエスト処理クラス
47          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
48          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
49          */
50         function _setTemplate($request, &$param)
51         {
52                 return 'index.tmpl.html';
53         }
54         /**
55          * テンプレートにデータ埋め込む
56          *
57          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
58          *
59          * @param RequestManager $request               HTTPリクエスト処理クラス
60          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
61          * @param                                                               なし
62          */
63         function _assign($request, &$param)
64         {
65                 $now = date("Y/m/d H:i:s");     // 現在日時
66                 $this->langId   = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
67                 
68                 // 設定値の取得
69                 $sendMessage = self::DEFAULT_SEND_MESSAGE;                      // メール送信機能を使用するかどうか
70                 $emailReceiver = '';            // メール受信者
71                 $showTitle = 0;                         // タイトルを表示するかどうか
72                 $titleName = self::DEFAULT_TITLE_NAME;                  // タイトル名
73                 $explanation = '';                      // 説明
74                 $nameVisible            = 1;            // 名前入力フィールドの表示
75                 $nameKanaVisible        = 1;            // フリガナ入力フィールドの表示
76                 $emailVisible           = 1;            // Eメール入力フィールドの表示
77                 $companyVisible         = 0;            // 会社名入力フィールドの表示
78                 $zipcodeVisible         = 0;            // 郵便番号入力フィールドの表示
79                 $stateVisible           = 0;            // 都道府県入力フィールドの表示
80                 $addressVisible         = 0;            // 住所入力フィールドの表示
81                 $telVisible                     = 0;            // 電話番号入力フィールドの表示
82                 $bodyVisible            = 1;            // 内容入力フィールドの表示
83                 $nameRequired           = 1;            // 名前入力フィールドの必須
84                 $nameKanaRequired       = 1;            // フリガナ入力フィールドの必須
85                 $emailRequired          = 1;            // Eメール入力フィールドの必須
86                 $companyRequired        = 0;            // 会社名入力フィールドの必須
87                 $zipcodeRequired        = 0;            // 郵便番号入力フィールドの必須
88                 $stateRequired          = 0;            // 都道府県入力フィールドの必須
89                 $addressRequired        = 0;            // 住所入力フィールドの必須
90                 $telRequired            = 0;            // 電話番号入力フィールドの必須
91                 $bodyRequired           = 1;            // 内容入力フィールドの必須
92                 
93                 $paramObj = $this->getWidgetParamObj();
94                 if (!empty($paramObj)){
95                         $sendMessage = $paramObj->sendMessage;                  // メール送信機能を使用するかどうか
96                         $emailReceiver = $paramObj->emailReceiver;              // メール受信者
97                         $showTitle = $paramObj->showTitle;                              // タイトルを表示するかどうか
98                         if (!empty($paramObj->titleName)) $titleName = $paramObj->titleName;                    // タイトル名
99                         $explanation = $paramObj->explanation;                  // 説明
100                         $nameVisible            = $paramObj->nameVisible;               // 名前入力フィールドの表示
101                         $nameKanaVisible        = $paramObj->nameKanaVisible;           // フリガナ入力フィールドの表示
102                         $emailVisible           = $paramObj->emailVisible;              // Eメール入力フィールドの表示
103                         $companyVisible         = $paramObj->companyVisible;            // 会社名入力フィールドの表示
104                         $zipcodeVisible         = $paramObj->zipcodeVisible;            // 郵便番号入力フィールドの表示
105                         $stateVisible           = $paramObj->stateVisible;              // 都道府県入力フィールドの表示
106                         $addressVisible         = $paramObj->addressVisible;            // 住所入力フィールドの表示
107                         $telVisible                     = $paramObj->telVisible;                // 電話番号入力フィールドの表示
108                         $bodyVisible            = $paramObj->bodyVisible;               // 内容入力フィールドの表示
109                         $nameRequired           = $paramObj->nameRequired;              // 名前入力フィールドの必須
110                         $nameKanaRequired       = $paramObj->nameKanaRequired;          // フリガナ入力フィールドの必須
111                         $emailRequired          = $paramObj->emailRequired;             // Eメール入力フィールドの必須
112                         $companyRequired        = $paramObj->companyRequired;           // 会社名入力フィールドの必須
113                         $zipcodeRequired        = $paramObj->zipcodeRequired;           // 郵便番号入力フィールドの必須
114                         $stateRequired          = $paramObj->stateRequired;             // 都道府県入力フィールドの必須
115                         $addressRequired        = $paramObj->addressRequired;           // 住所入力フィールドの必須
116                         $telRequired            = $paramObj->telRequired;               // 電話番号入力フィールドの必須
117                         $bodyRequired           = $paramObj->bodyRequired;              // 内容入力フィールドの必須
118                 }
119                 
120                 // 入力値を取得
121                 $act = $request->trimValueOf('act');
122                 $this->state = $request->trimValueOf('item_state');             // 都道府県
123                 $name = $request->trimValueOf('item_name');             // 名前
124                 $nameKana = $request->trimValueOf('item_name_kana');            // 名前(カナ)
125                 $email = $request->trimValueOf('item_email');           // Eメール
126                 $email2 = $request->trimValueOf('item_email2');         // Eメール確認用
127                 $companyName = $request->trimValueOf('item_company_name');              // 会社名
128                 $zipcode = $request->trimValueOf('item_zipcode');               // 郵便番号
129                 $address = $request->trimValueOf('item_address');               // 住所
130                 $phone = $request->trimValueOf('item_phone');           // 電話番号
131                 $body = $request->trimValueOf('item_body');             // 問い合わせ内容
132                 if ($act == 'send'){            // お問い合わせメール送信
133                         $postTicket = $request->trimValueOf('ticket');          // POST確認用
134                         if (!empty($postTicket) && $postTicket == $request->getSessionValue(M3_SESSION_POST_TICKET)){           // 正常なPOST値のとき
135                         
136                                 // 入力状況のチェック
137                                 if ($nameVisible && $nameRequired) $this->checkInput($name, 'お名前');
138                                 if ($nameKanaVisible && $nameKanaRequired) $this->checkInput($nameKana, 'お名前(カナ)');
139                                 if ($emailVisible){
140                                         if ($this->checkMailAddress($email, 'Eメール', !$emailRequired)){
141                                                 if ($email != $email2) $this->setAppErrorMsg('Eメールアドレスに誤りがあります');
142                                         }
143                                 }
144                                 if ($companyVisible && $companyRequired) $this->checkInput($companyName, '会社名');
145                                 if ($zipcodeVisible && $zipcodeRequired) $this->checkInput($zipcode, '郵便番号');
146                                 if ($stateVisible && $stateRequired) $this->checkInput($this->state, '都道府県');
147                                 if ($addressVisible && $addressRequired) $this->checkInput($address, '住所');
148                                 if ($telVisible && $telRequired) $this->checkInput($phone, '電話番号');
149                                 if ($bodyVisible && $bodyRequired) $this->checkInput($body, 'お問い合わせ内容');
150
151                                 // エラーなしの場合はメール送信
152                                 if ($this->getMsgCount() == 0){
153                                         $this->setGuidanceMsg('送信完了しました');
154                                 
155                                         // メール送信設定のときはメールを送信
156                                         if ($sendMessage){
157                                                 // メール本文の作成
158                                                 $stateName = $this->db->getStateName('JPN', $this->langId, $this->state);
159                                                 $mailBody = '';
160                                                 if ($nameVisible)               $mailBody .= 'お名前     : ' . $name . "\n";
161                                                 if ($nameKanaVisible)   $mailBody .= 'お名前(カナ) : ' . $nameKana . "\n";
162                                                 if ($emailVisible)              $mailBody .= 'Eメールアドレス: ' . $email . "\n";
163                                                 if ($companyVisible)    $mailBody .= '会社名     : ' . $companyName . "\n";
164                                                 if ($zipcodeVisible)    $mailBody .= '郵便番号    : ' . $zipcode . "\n";
165                                                 if ($stateVisible)              $mailBody .= '都道府県    : ' . $stateName . "\n";
166                                                 if ($addressVisible)    $mailBody .= '住所      : ' . $address . "\n";
167                                                 if ($telVisible)                $mailBody .= '電話番号    : ' . $phone . "\n";
168                                                 if ($bodyVisible)               $mailBody .= 'お問い合わせ内容: ' . $body . "\n";
169                                         
170                                                 // 送信元、送信先
171                                                 $fromAddress = $this->gEnv->getSiteEmail();     // 送信元はサイト情報のEメールアドレス
172                                                 $toAddress = $this->gEnv->getSiteEmail();               // デフォルトのサイト向けEメールアドレス
173                                                 if (!empty($emailReceiver)) $toAddress = $emailReceiver;                // 受信メールアドレスが設定されている場合
174                                         
175                                                 // メールを送信
176                                                 if (empty($toAddress)){
177                                                         $this->gOpeLog->writeError(__METHOD__, 'メール送信に失敗しました。基本情報のEメールアドレスが設定されていません。', 1100, 'body=[' . $mailBody . ']');
178                                                 } else {
179                                                         $mailParam = array();
180                                                         $mailParam['BODY'] = $mailBody;
181                                                         $ret = $this->gInstance->getMailManager()->sendFormMail(2/*手動送信*/, $this->gEnv->getCurrentWidgetId(), $toAddress, $fromAddress, $email, '', self::CONTACTUS_FORM, $mailParam);
182                                                 }
183                                         }
184
185                                         $this->tmpl->addVar("show_name", "name_disabled", 'disabled');
186                                         $this->tmpl->addVar("show_name_kana", "name_kana_disabled", 'disabled');
187                                         $this->tmpl->addVar("show_email", "email_disabled", 'disabled');
188                                         $this->tmpl->addVar("show_email", "email2_disabled", 'disabled');
189                                         $this->tmpl->addVar("show_company_name", "company_name_disabled", 'disabled');
190                                         $this->tmpl->addVar("show_zipcode", "zipcode_disabled", 'disabled');
191                                         $this->tmpl->addVar("show_state", "state_disabled", 'disabled');
192                                         $this->tmpl->addVar("show_address", "address_disabled", 'disabled');
193                                         $this->tmpl->addVar("show_tel", "phone_disabled", 'disabled');
194                                         $this->tmpl->addVar("show_body", "body_disabled", 'disabled');
195                                         $this->tmpl->addVar("_widget", "send_button_disabled", 'disabled');// 送信ボタン
196                                         $request->unsetSessionValue(M3_SESSION_POST_TICKET);            // セッション値をクリア
197                                         $sendButtonLabel = '送信済み';                      // 送信ボタンラベル
198                                 } else {                // 入力エラーの場合はハッシュキーを再設定
199                                         // ハッシュキー作成
200                                         $postTicket = md5(time() . $this->gAccess->getAccessLogSerialNo());
201                                         $request->setSessionValue(M3_SESSION_POST_TICKET, $postTicket);         // セッションに保存
202                                         $this->tmpl->addVar("_widget", "ticket", $postTicket);                          // 画面に書き出し
203                                         $sendButtonLabel = '送信する';                      // 送信ボタンラベル
204                                 }
205                         } else {                // ハッシュキーが異常のとき
206                                 $request->unsetSessionValue(M3_SESSION_POST_TICKET);            // セッション値をクリア
207                                 $sendButtonLabel = '送信する';                      // 送信ボタンラベル
208                         }
209                         $this->tmpl->addVar("show_name", "name", $name);
210                         $this->tmpl->addVar("show_name_kana", "name_kana", $nameKana);
211                         $this->tmpl->addVar("show_email", "email", $email);
212                         $this->tmpl->addVar("show_email", "email2", $email2);
213                         $this->tmpl->addVar("show_company_name", "company_name", $companyName);
214                         $this->tmpl->addVar("show_zipcode", "zipcode", $zipcode);
215                         $this->tmpl->addVar("show_address", "address", $address);
216                         $this->tmpl->addVar("show_tel", "phone", $phone);
217                         $this->tmpl->addVar("show_body", "body", $body);
218                         $this->tmpl->addVar("_widget", "send_button_label", $sendButtonLabel);// 送信ボタンラベル
219                 } else {
220                         // ハッシュキー作成
221                         $postTicket = md5(time() . $this->gAccess->getAccessLogSerialNo());
222                         $request->setSessionValue(M3_SESSION_POST_TICKET, $postTicket);         // セッションに保存
223                         $this->tmpl->addVar("_widget", "ticket", $postTicket);                          // 画面に書き出し
224                         
225                         // メール送信不可の場合はボタンを使用不可にする
226                         if ($sendMessage){
227                                 $this->tmpl->addVar("_widget", "send_button_label", '送信する');// 送信ボタンラベル
228                         } else {
229                                 $this->tmpl->addVar("_widget", "send_button_label", '送信停止中');// 送信ボタンラベル
230                                 $this->tmpl->addVar("_widget", "send_button_disabled", 'disabled');// 送信ボタン
231                         }
232                 }
233                 // HTMLサブタイトルを設定
234                 $this->gPage->setHeadSubTitle(self::DEFAULT_TITLE_NAME);
235                         
236                 // タイトルの表示
237                 if ($showTitle){
238                         $headClassStr = $this->gDesign->getDefaultContentHeadClassString();                     // コンテンツタイトル用CSSクラス
239                         $this->tmpl->addVar("show_title", "class", $headClassStr);
240                         $this->tmpl->setAttribute('show_title', 'visibility', 'visible');
241                         $this->tmpl->addVar("show_title", "title_name", $titleName);// タイトル名
242                 }
243                 // 説明の表示
244                 if (!empty($explanation)){
245                         $this->tmpl->setAttribute('show_explanation', 'visibility', 'visible');
246                         $this->tmpl->addVar("show_explanation", "explanation", $explanation);// 説明
247                 }
248                 // 入力フィールドの表示制御
249                 if ($nameVisible){
250                         if ($nameRequired) $this->tmpl->addVar('show_name', 'required', self::DEFAULT_STR_REQUIRED);// 「必須」表示
251                         $this->tmpl->setAttribute('show_name', 'visibility', 'visible');// 名前入力フィールドの表示
252                 }
253                 if ($nameKanaVisible){
254                         if ($nameKanaRequired) $this->tmpl->addVar('show_name_kana', 'required', self::DEFAULT_STR_REQUIRED);// 「必須」表示
255                         $this->tmpl->setAttribute('show_name_kana', 'visibility', 'visible');// 名前カナ入力フィールドの表示
256                 }
257                 if ($emailVisible){
258                         if ($emailRequired) $this->tmpl->addVar('show_email', 'required', self::DEFAULT_STR_REQUIRED);// 「必須」表示
259                         $this->tmpl->setAttribute('show_email', 'visibility', 'visible');// Eメール入力フィールドの表示
260                 }
261                 if ($companyVisible){
262                         if ($companyRequired) $this->tmpl->addVar('show_company_name', 'required', self::DEFAULT_STR_REQUIRED);// 「必須」表示
263                         $this->tmpl->setAttribute('show_company_name', 'visibility', 'visible');// 会社名入力フィールドの表示
264                 }
265                 if ($zipcodeVisible){
266                         if ($zipcodeRequired) $this->tmpl->addVar('show_zipcode', 'required', self::DEFAULT_STR_REQUIRED);// 「必須」表示
267                         $this->tmpl->setAttribute('show_zipcode', 'visibility', 'visible');// 郵便番号入力フィールドの表示
268                 }
269                 if ($stateVisible){
270                         if ($stateRequired) $this->tmpl->addVar('show_state', 'required', self::DEFAULT_STR_REQUIRED);// 「必須」表示
271                         $this->tmpl->setAttribute('show_state', 'visibility', 'visible');//都道府県入力フィールドの表示
272                         $this->db->getAllState('JPN', $this->langId, array($this, 'stateLoop'));// 都道府県メニュー
273                 }
274                 if ($addressVisible){   // 住所入力フィールドの表示
275                         if ($addressRequired) $this->tmpl->addVar('show_address', 'required', self::DEFAULT_STR_REQUIRED);// 「必須」表示
276                         $this->tmpl->setAttribute('show_address', 'visibility', 'visible');// 住所入力フィールドの表示
277                 }                                       
278                 if ($telVisible){
279                         if ($telRequired) $this->tmpl->addVar('show_tel', 'required', self::DEFAULT_STR_REQUIRED);// 「必須」表示
280                         $this->tmpl->setAttribute('show_tel', 'visibility', 'visible');// 電話番号入力フィールドの表示
281                 }
282                 if ($bodyVisible){
283                         if ($bodyRequired) $this->tmpl->addVar('show_body', 'required', self::DEFAULT_STR_REQUIRED);// 「必須」表示
284                         $this->tmpl->setAttribute('show_body', 'visibility', 'visible');// 内容入力フィールドの表示
285                 }
286         }
287         /**
288          * 取得した都道府県をテンプレートに設定する
289          *
290          * @param int $index                    行番号(0~)
291          * @param array $fetchedRow             フェッチ取得した行
292          * @param object $param                 未使用
293          * @return bool                                 true=処理続行の場合、false=処理終了の場合
294          */
295         function stateLoop($index, $fetchedRow, $param)
296         {
297                 $selected = '';
298                 if ($fetchedRow['gz_id'] == $this->state){              // 選択中の都道府県
299                         $selected = 'selected';
300                 }
301
302                 $row = array(
303                         'value'    => $this->convertToDispString($fetchedRow['gz_id']),                 // ID
304                         'name'     => $this->convertToDispString($fetchedRow['gz_name']),                       // 表示名
305                         'selected' => $selected                                                                                                         // 選択中かどうか
306                 );
307                 $this->tmpl->addVars('state_list', $row);
308                 $this->tmpl->parseTemplate('state_list', 'a');
309                 return true;
310         }
311 }
312 ?>