7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2009 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: m_contactus_customWidgetContainer.php 2363 2009-09-26 14:45:44Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseMobileWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/contactus_customDb.php');
19 class m_contactus_customWidgetContainer extends BaseMobileWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $fieldInfoArray = array(); // お問い合わせ項目情報
23 private $valueArray; // 項目入力値
24 const DEFAULT_CONFIG_ID = 0;
25 const CONTACTUS_FORM = 'contact_us'; // お問い合わせフォーム
26 const DEFAULT_SEND_MESSAGE = 1; // メール送信機能を使用するかどうか(デフォルト使用)
27 const DEFAULT_TITLE_NAME = 'お問い合わせ'; // デフォルトのタイトル名
28 const DEFAULT_STR_REQUIRED = '<span style="color:#ff0000"><font color="#ff0000">*必須</font></span>'; // 「必須」表示用テキスト
29 const FIELD_HEAD = 'item'; // フィールド名の先頭文字列
34 function __construct()
37 parent::__construct();
40 $this->db = new contactus_customDb();
45 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
46 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
48 * @param RequestManager $request HTTPリクエスト処理クラス
49 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
50 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
52 function _setTemplate($request, &$param)
54 return 'index.tmpl.html';
59 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
61 * @param RequestManager $request HTTPリクエスト処理クラス
62 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
65 function _assign($request, &$param)
68 $configId = $this->gEnv->getCurrentWidgetConfigId();
69 if (empty($configId)) $configId = self::DEFAULT_CONFIG_ID;
72 $targetObj = $this->getWidgetParamObjByConfigId($configId);
73 if (empty($targetObj)) return; // 定義データが取得できないときは終了
76 $inputEnabled = true; // 入力の許可状態
77 $now = date("Y/m/d H:i:s"); // 現在日時
78 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
79 $sendMessage = self::DEFAULT_SEND_MESSAGE; // メール送信機能を使用するかどうか
80 $showTitle = 0; // タイトルを表示するかどうか
81 $titleName = self::DEFAULT_TITLE_NAME; // タイトル名
82 $titleBgColor = ''; // タイトルバックグランドカラー
83 $explanation = ''; // 説明
85 //$sendMessage = $targetObj->sendMessage; // メール送信機能を使用するかどうか
86 $emailReceiver = $targetObj->emailReceiver; // メール受信者
87 $emailSubject = $targetObj->emailSubject; // メール件名
88 $showTitle = $targetObj->showTitle; // タイトルを表示するかどうか
89 if (!empty($targetObj->titleName)) $titleName = $targetObj->titleName; // タイトル名
90 $titleBgColor = $targetObj->titleBgColor; // タイトルバックグランドカラー
91 $explanation = $targetObj->explanation; // 説明
92 $name = $targetObj->name;// 名前
93 if (!empty($targetObj->fieldInfo)) $this->fieldInfoArray = $targetObj->fieldInfo; // お問い合わせフィールド情報
96 $this->valueArray = array();
97 $fieldCount = count($this->fieldInfoArray);
98 for ($i = 0; $i < $fieldCount; $i++){
99 $itemName = self::FIELD_HEAD . ($i + 1);
100 $itemValue = $request->mobileTrimValueOf($itemName);
101 $this->valueArray[] = $itemValue;
103 $act = $request->trimValueOf('act');
105 if ($act == 'send'){ // お問い合わせメール送信
106 $postTicket = $request->trimValueOf('ticket'); // POST確認用
107 if (!empty($postTicket) && $postTicket == $request->getSessionValue(M3_SESSION_POST_TICKET)){ // 正常なPOST値のとき
109 for ($i = 0; $i < $fieldCount; $i++){
110 $infoObj = $this->fieldInfoArray[$i];
111 $title = $infoObj->title;// タイトル名
112 $type = $infoObj->type; // 項目タイプ
113 $required = $infoObj->required; // 必須入力
114 if (!empty($required) && empty($this->valueArray[$i])) $this->setUserErrorMsg('「' . $title . '」は必須入力項目です');
118 if ($this->getMsgCount() == 0){
119 $this->setGuidanceMsg('送信完了しました');
125 for ($i = 0; $i < $fieldCount; $i++){
126 $infoObj = $this->fieldInfoArray[$i];
127 $title = $infoObj->title;// タイトル名
128 $type = $infoObj->type; // 項目タイプ
130 $mailBody .= $title . "\n";
131 if (!empty($this->valueArray[$i])){
132 if (is_array($this->valueArray[$i])){ // 配列データのとき
133 for ($j = 0; $j < count($this->valueArray[$i]); $j++){
134 $mailBody .= $this->valueArray[$i][$j] . "\n";
137 $mailBody .= $this->valueArray[$i] . "\n";
144 $fromAddress = $this->gEnv->getSiteEmail(); // 送信元はサイト情報のEメールアドレス
145 $toAddress = $this->gEnv->getSiteEmail(); // デフォルトのサイト向けEメールアドレス
146 if (!empty($emailReceiver)) $toAddress = $emailReceiver; // 受信メールアドレスが設定されている場合
149 if (empty($toAddress)){
150 $this->gOpeLog->writeError(__METHOD__, 'メール送信に失敗しました。基本情報のEメールアドレスが設定されていません。', 1100, 'body=[' . $mailBody . ']');
152 $mailParam = array();
153 $mailParam['BODY'] = $mailBody;
154 $email = ''; // 返信先は空にする(暫定)
155 $ret = $this->gInstance->getMailManager()->sendFormMail(2/*手動送信*/, $this->gEnv->getCurrentWidgetId(), $toAddress, $fromAddress, $email, $emailSubject, self::CONTACTUS_FORM, $mailParam);
159 $inputEnabled = false; // 入力の許可状態
161 //$this->tmpl->addVar("_widget", "message", '送信しました');// 送信ボタンラベル
163 $this->tmpl->addVar("show_send_button", "send_button_label", '送信する');// 送信ボタンラベル
164 $this->tmpl->setAttribute('show_send_button', 'visibility', 'visible');
169 $postTicket = md5(time() . $this->gAccess->getAccessLogSerialNo());
170 $request->setSessionValue(M3_SESSION_POST_TICKET, $postTicket); // セッションに保存
171 $this->tmpl->addVar("_widget", "ticket", $postTicket); // 画面に書き出し
173 // メール送信不可の場合はボタンを使用不可にする
175 $this->tmpl->addVar("show_send_button", "send_button_label", '送信する');// 送信ボタンラベル
177 $this->tmpl->addVar("show_send_button", "send_button_label", '送信停止中');// 送信ボタンラベル
178 //$this->tmpl->addVar("_widget", "send_button_disabled", 'disabled');// 送信ボタン
180 $this->tmpl->setAttribute('show_send_button', 'visibility', 'visible');
184 //$this->gPage->setHeadSubTitle(self::DEFAULT_TITLE_NAME);
185 $this->gPage->setHeadSubTitle($this->gEnv->getCurrentWidgetHeadTitle()); // 共通設定画面の「タイトル」値を使用する
188 $this->tmpl->addVar('_widget', 'url', $this->gEnv->createCurrentPageUrlForMobile()); // Post用URL
189 $this->tmpl->addVar('_widget', 'act', 'send');
193 $titleClassStr = 'align="center" style="text-align:center;';
194 if (!empty($titleBgColor)) $titleClassStr .= 'background-color:' . $titleBgColor . ';';// タイトルバックグランドカラー
195 $titleClassStr .= '"';
196 $this->tmpl->addVar("show_title", "class", $titleClassStr);
197 $this->tmpl->setAttribute('show_title', 'visibility', 'visible');
198 $this->tmpl->addVar("show_title", "title_name", $this->convertToDispString($titleName));// タイトル名
201 if (!empty($explanation)){
202 $this->tmpl->setAttribute('show_explanation', 'visibility', 'visible');
203 $this->tmpl->addVar("show_explanation", "explanation", $explanation);// 説明
206 $fieldCount = $this->createFieldList($inputEnabled);
207 if ($fieldCount == 0) $this->tmpl->setAttribute('field_list', 'visibility', 'hidden');
209 $this->tmpl->addVar("_widget", "field_count", $fieldCount);// お問い合わせ項目数
214 * @param bool $enabled 項目の入力許可状態
215 * @return int フィールド項目数
217 function createFieldList($enabled)
219 $fieldCount = count($this->fieldInfoArray);
220 for ($i = 0; $i < $fieldCount; $i++){
221 $infoObj = $this->fieldInfoArray[$i];
222 $title = $infoObj->title;// タイトル名
223 $desc = $infoObj->desc; // 説明
224 $type = $infoObj->type; // 項目タイプ
225 $def = $infoObj->def; // 項目定義
227 if (!empty($infoObj->required)) $required = ' ' . self::DEFAULT_STR_REQUIRED;// 必須表示
230 $fieldName = self::FIELD_HEAD . ($i + 1);
231 $inputValue = $this->valueArray[$i]; // 入力値
234 case 'text': // テキストボックス
238 $defArray = explode(';', $def);
239 for ($j = 0; $j < count($defArray); $j++){
240 list($key, $value) = explode('=', $defArray[$j]);
242 $value = trim($value);
243 if (strcasecmp($key, 'size') == 0){
244 $size = intval($value);
248 if ($size > 0) $param[] = 'size="' . $size . '"';
249 if (!empty($inputValue)){
250 $param[] = 'value="' . $inputValue . '"';
252 if (!$enabled) $param[] = 'disabled'; // 使用不可
253 if (count($param) > 0) $paramStr = ' ' . implode($param, ' ');
254 $inputTag = '<input type="text" name="' . $fieldName . '"' . $paramStr . ' /><br />' . M3_NL;
256 case 'textarea': // テキストエリア
261 $defArray = explode(';', $def);
262 for ($j = 0; $j < count($defArray); $j++){
263 list($key, $value) = explode('=', $defArray[$j]);
265 $value = trim($value);
266 if (strcasecmp($key, 'rows') == 0){
267 $row = intval($value);
268 } else if (strcasecmp($key, 'cols') == 0){
269 $col = intval($value);
272 if ($row > 0) $param[] = 'rows="' . $row . '"';
273 if ($col > 0) $param[] = 'cols="' . $col . '"';
274 if (!$enabled) $param[] = 'disabled'; // 使用不可
275 if (count($param) > 0) $paramStr = ' ' . implode($param, ' ');
276 $inputTag = '<textarea name="' . $fieldName . '"' . $paramStr . '>' . $this->convertToDispString($inputValue) . '</textarea><br />' . M3_NL;
278 case 'select': // セレクトメニュー
281 if (!$enabled) $param[] = 'disabled'; // 使用不可
282 if (count($param) > 0) $paramStr = ' ' . implode($param, ' ');
283 $inputTag = '<select name="' . $fieldName . '"'. $paramStr . '>' . M3_NL;
284 $inputTag .= '<option value=""> </option>' . M3_NL;
285 $defArray = explode(';', $def);
286 for ($j = 0; $j < count($defArray); $j++){
289 list($key, $value) = explode('=', $defArray[$j]);
291 $value = trim($value);
292 if (empty($value)) $value = $key;
294 if (!empty($inputValue) && strcmp($inputValue, $value) == 0) $param[] = 'selected';
295 if (count($param) > 0) $paramStr = ' ' . implode($param, ' ');
296 $inputTag .= '<option value="' . $this->convertToDispString($value) . '"' . $paramStr . '>' . $this->convertToDispString($key) . '</option>' . M3_NL;
299 $inputTag .= '</select><br />' . M3_NL;
301 case 'checkbox': // チェックボックス
302 case 'radio': // ラジオボタン
304 $defArray = explode(';', $def);
305 for ($j = 0; $j < count($defArray); $j++){
308 list($key, $value) = explode('=', $defArray[$j]);
310 $value = trim($value);
311 if (empty($value)) $value = $key;
312 if (!empty($key) && !empty($value)){
313 for ($k = 0; $k < count($inputValue); $k++){
314 if (!empty($inputValue[$k]) && strcmp($inputValue[$k], $value) == 0) $param[] = 'checked';
316 if (!$enabled) $param[] = 'disabled'; // 使用不可
317 if (count($param) > 0) $paramStr = ' ' . implode($param, ' ');
318 $inputTag .= '<input type="' . $type . '" name="' . $fieldName . '" value="' . $this->convertToDispString($value) . '"' . $paramStr . ' />' . $this->convertToDispString($key) . '<br />' . M3_NL;
326 if (!empty($title) || !empty($required)) $titleBr = '<br />';
328 if (!empty($desc)) $descBr = '<br />';
330 if (!empty($inputTag)) $inputBr = '<br />';
333 'title' => $this->convertToDispString($title), // タイトル名
334 'desc' => $this->convertToDispString($desc), // 説明
335 'title_br' => $titleBr, // タイトル名改行
336 'desc_br' => $descBr, // 説明改行
337 'input_br' => $inputBr, // 入力フィールド改行
338 'required' => $required, // 必須表示
339 'input' => $inputTag // 入力フィールド
341 $this->tmpl->addVars('field_list', $row);
342 $this->tmpl->parseTemplate('field_list', 'a');