OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / ec_login / include / container / ec_loginWidgetContainer.php
1 <?php
2 /**
3  * index.php用コンテナクラス
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: ec_loginWidgetContainer.php 5425 2012-12-05 01:57:48Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath()           . '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() .   '/ec_loginDb.php');
18
19 class ec_loginWidgetContainer extends BaseWidgetContainer
20 {
21         const DEFAULT_CART_WIDGET = 'photo_shop';               // カート内容表示用呼び出しウィジェットID
22         const MAIL_OBJ_ID = 'ecmail';                   // メール連携オブジェクト
23         const EC_LIB_ID = "eclib";              // EC共通ライブラリオブジェクトID
24         const DEFAULT_TITLE = '会員ログイン';
25         const CSS_FILE = '/style.css';          // CSSファイルのパス
26         const CF_AUTO_REGIST_MEMBER                     = 'auto_regist_member';         // 自動会員登録
27         const SHOP_WIDGET_TYPE = 'product';                     // ショップ機能ウィジェットのウィジェットタイプ
28         const WORD_KEY_ACCOUNT = 'word_account';                // 用語取得キー(アカウント)
29         
30         /**
31          * コンストラクタ
32          */
33         function __construct()
34         {
35                 // 親クラスを呼び出す
36                 parent::__construct();
37                 
38                 // DB接続オブジェクト作成
39                 $this->db = new ec_loginDb();
40                 
41                 // メール連携オブジェクト取得
42                 $this->ecMailObj = $this->gInstance->getObject(self::MAIL_OBJ_ID);
43         }
44         /**
45          * テンプレートファイルを設定
46          *
47          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
48          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
49          *
50          * @param RequestManager $request               HTTPリクエスト処理クラス
51          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
52          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
53          */
54         function _setTemplate($request, &$param)
55         {       
56                 return 'index.tmpl.html';
57         }
58         /**
59          * テンプレートにデータ埋め込む
60          *
61          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
62          *
63          * @param RequestManager $request               HTTPリクエスト処理クラス
64          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
65          * @param                                                               なし
66          */
67         function _assign($request, &$param)
68         {
69                 $act = $request->trimValueOf('act');
70                 if ($act == 'eclogin_login'){                   // 会員ログインのとき
71                         // アカウント、パスワード取得
72                         $account = $request->trimValueOf('account');
73                         $password = $request->trimValueOf('password');
74                 
75                         // ユーザ認証
76                         if ($this->gAccess->userLoginByAccount($account, $password)){
77                                 // 初回ログインのときは、仮会員を正会員にする
78                                 $userId = $this->gEnv->getCurrentUserId();
79                                 if ($userId != 0){
80                                         $ret = $this->gInstance->getObject(self::EC_LIB_ID)->makeTmpMemberToProperMember($userId);
81                                         if ($ret){
82                                                 $ret = $this->_db->makeNormalLoginUser($userId);// 一般ログインユーザに設定
83                                                 
84                                                 // ######## 会員登録のメールをイントラネット側に送信 ########
85                                                 //$this->ecMailObj->sendMemberInfoToBackoffice(0/*新規登録*/, $userId);
86                                         }
87                                 }
88                                 // 画面を全体を再表示する
89                                 $this->gPage->redirect($this->gEnv->getCurrentRequestUri());
90                                 return;
91                         } else {
92                                 // ログイン状態を削除
93                                 $this->gAccess->userLogout();
94                                 
95                                 $this->tmpl->setAttribute('login_status', 'visibility', 'visible');             // ログイン状況
96                                 $this->tmpl->addVar("login_status", "message", 'ログインに失敗しました');
97                         }
98                 } else if ($act == 'eclogin_logout'){                   // 会員ログアウトのとき
99                         $this->gAccess->userLogout();
100                         
101                         // 画面を全体を再表示する
102                         $this->gPage->redirect($this->gEnv->getCurrentRequestUri());
103                         return;
104                 }
105                 
106                 // ログイン状態を取得
107                 $userName = $this->gEnv->getCurrentUserName();
108                 if (empty($userName)){          // ユーザがログインしていないとき
109                         // ログイン入力部、ログインボタン表示
110                         $this->tmpl->setAttribute('login_field', 'visibility', 'visible');
111                         $this->tmpl->setAttribute('login_button', 'visibility', 'visible');
112                         
113                         // 自動会員登録機能を使用するかどうか
114                         $value = $this->db->getConfig(self::CF_AUTO_REGIST_MEMBER);
115                         if (!empty($value)) $this->tmpl->setAttribute('regmember_button', 'visibility', 'visible');             // 自動会員登録機能を使用する場合のみ会員登録ボタンを表示
116                         
117                         // 値埋め込み
118                         $this->tmpl->addVar("login_field", "word_account", $this->convertToDispString($this->gInstance->getMessageManager()->getWord(self::WORD_KEY_ACCOUNT)));         // 用語(アカウント)
119                 } else {                // ユーザがログイン中のとき
120                         // 会員情報を取得
121                         $ret = $this->db->getMember($this->gEnv->getCurrentUserId(), $memberRow);
122                         
123                         $this->tmpl->addVar("login_status", "user_name", 'ログイン: ' . $userName . ' 様');
124                         
125                         // 会員情報、ログアウトボタン表示
126                         $this->tmpl->setAttribute('login_status', 'visibility', 'visible');             // ログイン状況
127                         $this->tmpl->setAttribute('logout_button', 'visibility', 'visible');
128                         if ($ret) $this->tmpl->setAttribute('member_button', 'visibility', 'visible');          // 会員の場合のみ表示
129                 }
130                 $shopWidget = $this->gPage->getActiveMainWidgetIdByWidgetType(self::SHOP_WIDGET_TYPE);          // ショップ機能ウィジェット取得
131                 if (empty($shopWidget)) $shopWidget = self::DEFAULT_CART_WIDGET;
132                 
133                 // パスワード送信画面へのリンク
134                 $sendpwdUrl = $this->createCmdUrlToWidget($shopWidget, 'task=sendpwd');
135                 $this->tmpl->addVar("regmember_button", "sendpwd_url", $this->getUrl($sendpwdUrl, true));
136                 
137                 // 会員登録画面へのリンク
138                 $regMemberUrl = $this->createCmdUrlToWidget($shopWidget, 'task=regmember');
139                 $this->tmpl->addVar("regmember_button", "regmember_url", $this->getUrl($regMemberUrl, true));
140                 
141                 // パスワード変更画面へのリンク
142                 $changepwdUrl = $this->createCmdUrlToWidget($shopWidget, 'task=changepwd');
143                 $this->tmpl->addVar("member_button", "changepwd_url", $this->getUrl($changepwdUrl, true));
144                 
145                 // 会員情報画面へのリンク
146                 $memberUrl = $this->createCmdUrlToWidget($shopWidget, 'task=memberinfo');
147                 $this->tmpl->addVar("member_button", "member_url", $this->getUrl($memberUrl, true));
148                 
149                 // 購入履歴画面へのリンク
150                 $historyUrl = $this->createCmdUrlToWidget($shopWidget, 'task=purchasehistory');
151                 $this->tmpl->addVar("member_button", "purchasehistory_url", $this->getUrl($historyUrl, true));
152                 
153                 // 会員お知らせ画面へのリンク
154                 $memberNoticeUrl = $this->createCmdUrlToWidget($shopWidget, 'task=membernotice');
155                 $this->tmpl->addVar("member_button", "member_notice_url", $this->getUrl($memberNoticeUrl, true));
156         }
157         /**
158          * CSSファイルをHTMLヘッダ部に設定
159          *
160          * CSSファイルをHTMLのheadタグ内に追加出力する。
161          * _assign()よりも後に実行される。
162          *
163          * @param RequestManager $request               HTTPリクエスト処理クラス
164          * @param object         $param                 任意使用パラメータ。
165          * @return string                                               CSS文字列。出力しない場合は空文字列を設定。
166          */
167         function _addCssFileToHead($request, &$param)
168         {
169                 return $this->getUrl($this->gEnv->getCurrentWidgetCssUrl() . self::CSS_FILE);
170         }
171         /**
172          * ウィジェットのタイトルを設定
173          *
174          * @param RequestManager $request               HTTPリクエスト処理クラス
175          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
176          * @return string                                               ウィジェットのタイトル名
177          */
178         function _setTitle($request, &$param)
179         {
180                 return self::DEFAULT_TITLE;
181         }
182 }
183 ?>