OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / ec_main / include / container / ec_mainLoginWidgetContainer.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_mainLoginWidgetContainer.php 5440 2012-12-08 09:37:39Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getCurrentWidgetContainerPath() .    '/ec_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() .   '/ec_mainMemberDb.php');
18
19 class ec_mainLoginWidgetContainer extends ec_mainBaseWidgetContainer
20 {
21         private $memberDb;
22         private $ecMailObj;     // メール連携オブジェクト
23         const MAIL_OBJ_ID = 'ecmail';
24         const EC_LIB_ID = "eclib";              // EC共通ライブラリオブジェクトID
25         const WORD_KEY_ACCOUNT = 'word_account';                // 用語取得キー(アカウント)
26         
27         /**
28          * コンストラクタ
29          */
30         function __construct()
31         {
32                 // 親クラスを呼び出す
33                 parent::__construct();
34                 
35                 // DB接続オブジェクト作成
36                 $this->memberDb = new ec_mainMemberDb();
37                 
38                 // メール連携オブジェクト取得
39                 $this->ecMailObj = $this->gInstance->getObject(self::MAIL_OBJ_ID);
40         }
41         /**
42          * テンプレートファイルを設定
43          *
44          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
45          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
46          *
47          * @param RequestManager $request               HTTPリクエスト処理クラス
48          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
49          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
50          */
51         function _setTemplate($request, &$param)
52         {       
53                 return 'login.tmpl.html';
54         }
55         /**
56          * テンプレートにデータ埋め込む
57          *
58          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
59          *
60          * @param RequestManager $request               HTTPリクエスト処理クラス
61          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
62          * @param                                                               なし
63          */
64         function _assign($request, &$param)
65         {
66                 $task = $request->trimValueOf('task');
67                 $act = $request->trimValueOf('act');
68                 $forward = $request->trimValueOf(M3_REQUEST_PARAM_FORWARD);             // 画面遷移用パラメータ
69                 $account = $request->trimValueOf('photo_account');
70                 
71                 if ($act == 'photo_login'){                     // 会員ログインのとき
72                         // アカウント、パスワード取得
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                                                 $this->_db->makeNormalLoginUser($userId);// 一般ログインユーザに設定
83                                         
84                                                 // ######## 会員登録のメールをイントラネット側に送信 ########
85                                                 $this->ecMailObj->sendMemberInfoToBackoffice(0/*新規登録*/, $userId);
86                                         }
87                                 }
88                                 if (empty($forward)){
89                                         // 会員メニューへ
90                                         $memberPage = $this->gEnv->createCurrentPageUrl() . '&task=' . self::DEFAULT_MEMBER_TASK;
91                                         $this->gPage->redirect($memberPage);
92                                 } else {
93                                         $forwardPage = $this->gEnv->createCurrentPageUrl() . '&' . $forward;
94                                         $this->gPage->redirect($forwardPage);
95                                 }
96                                 return;
97                         } else {
98                                 // ログイン状態を削除
99                                 $this->gAccess->userLogout();
100                                 
101                                 $this->tmpl->addVar("_widget", "message", 'ログインに失敗しました');
102                         }
103                 //} else if ($act == photo_shopCommonDef::EMAIL_LOGIN_ACT){                     // メールからの会員ログインのとき
104                 } else {                // 初期画面
105                         // Eメールのリンクでのログインの場合
106                         if ($task == 'emaillogin'){
107                                 // メールからのアクセスの場合は、ログイン後最初にパスワードを変更する
108                                 //$account = $request->trimValueOf('account');
109                                 $pwd = $request->trimValueOf('pwd');
110                                 $forward = 'task=changepwd';            // パスワードを変更
111                         
112                                 $this->tmpl->addVar("_widget", "photo_account", $account);
113                                 $this->tmpl->addVar("_widget", "photo_password", $pwd);
114                                 $this->tmpl->addVar("_widget", "savepwd", $pwd);
115                         }
116                 }
117                 // 画面修正
118                 if ($task == 'emaillogin'){
119                         $this->tmpl->setAttribute('field_regmember', 'visibility', 'hidden');// 会員登録への遷移を削除
120                 } else {
121                         // 非会員の購入を許可している場合は、遷移可能にする
122                         $value = $this->_getConfig(photo_shopCommonDef::CF_PERMIT_NON_MEMBER_ORDER);
123                         if (!empty($value)){
124                                 $this->tmpl->setAttribute('field_nonmember', 'visibility', 'visible');
125                                 //$this->tmpl->addVar("field_nonmember", "url_order", $this->getUrl($this->gEnv->createCurrentPageUrl() . '&task=order', true));                                // 購入画面遷移用
126                                 $this->tmpl->addVar("field_nonmember", "url_order", $this->getUrl($this->gEnv->createCurrentPageUrl() . '&' . $forward, true));                         // 購入画面遷移用
127                         }
128                 }
129                                 
130                 // パラメータを画面に埋め込む
131                 $this->tmpl->addVar("field_regmember", "url_regmember", $this->getUrl($this->gEnv->createCurrentPageUrl() . '&task=regmember', true));          // 会員登録画面遷移用
132                 $this->tmpl->addVar("_widget", "forward", $forward);            // 遷移先を維持
133                 $this->tmpl->addVar("_widget", "task", $task);
134                 $this->tmpl->addVar("_widget", "word_account", $this->convertToDispString($this->gInstance->getMessageManager()->getWord(self::WORD_KEY_ACCOUNT)));             // 用語(アカウント)
135                 $this->tmpl->addVar("field_regmember", "word_account", $this->convertToDispString($this->gInstance->getMessageManager()->getWord(self::WORD_KEY_ACCOUNT)));             // 用語(アカウント)
136         }
137 }
138 ?>