OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / admin_main / include / container / admin_mainLoginstatusWidgetContainer.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-2013 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: admin_mainLoginstatusWidgetContainer.php 5842 2013-03-20 00:10:52Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getCurrentWidgetContainerPath() .    '/admin_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/admin_mainDb.php');
18 require_once($gEnvManager->getIncludePath() . '/common/userInfo.php');          // ユーザ情報クラス
19
20 class admin_mainLoginstatusWidgetContainer extends admin_mainBaseWidgetContainer
21 {
22         private $db;    // DB接続オブジェクト
23         private $sysDb;         // システムDBオブジェクト
24         private $loginStatusArray;              // ログイン状況選択用
25         private $loginStatus;   // ログイン状況
26         private $browserIconFile;       // ブラウザアイコンファイル名
27         const DEFAULT_LIST_COUNT = 30;                  // 最大リスト表示数
28         const MAX_PAGE_COUNT = 20;                              // 最大ページ数
29         const BROWSER_ICON_DIR = '/images/system/browser/';             // ブラウザアイコンディレクトリ
30         
31         /**
32          * コンストラクタ
33          */
34         function __construct()
35         {
36                 // 親クラスを呼び出す
37                 parent::__construct();
38                 
39                 // DB接続オブジェクト作成
40                 $this->db = new admin_mainDb();
41                 $this->sysDb = $this->gInstance->getSytemDbObject();
42                 
43                 // ログイン状況選択用
44                 $this->loginStatusArray = array(        array(  'name' => $this->_('Login'),            'value' => '0'),        // ログイン
45                                                                                         array(  'name' => $this->_('Logout'),           'value' => '1'),        // ログアウト
46                                                                                         array(  'name' => $this->_('Error'),            'value' => '2'));       // エラー
47                                                                                         
48                 // ブラウザアイコンファイル名
49                 $this->browserIconFile = array(
50                         'OP' => 'opera.png',    // opera
51                         'IE' => 'ie.png',       // microsoft internet explorer
52                         'NS' => 'netscape.png', // netscape
53                         'GA' => 'galeon.png',   // galeon
54                         'PX' => 'phoenix.png',  // phoenix
55                         'FF' => 'firefox.png',  // firefox
56                         'FB' => 'firebird.png', // mozilla firebird
57                         'SM' => 'seamonkey.png',        // seamonkey
58                         'CA' => 'camino.png',   // camino
59                         'SF' => 'safari.png',   // safari
60                         'CH' => 'chrome.gif',   // chrome
61                         'KM' => 'k-meleon.png', // k-meleon
62                         'MO' => 'mozilla.gif',  // mozilla
63                         'KO' => 'konqueror.png',        // konqueror
64                         'BB' => '',     // blackberry
65                         'IC' => 'icab.png',     // icab
66                         'LX' => '',     // lynx
67                         'LI' => '',     // links
68                         'MC' => '',     // ncsa mosaic
69                         'AM' => '',     // amaya
70                         'OW' => 'omniweb.png',  // omniweb
71                         'HJ' => '',     // hotjava
72                         'BX' => '',     // browsex
73                         'AV' => '',     // amigavoyager
74                         'AW' => '',     // amiga-aweb
75                         'IB' => '',     // ibrowse
76                         'AR' => '',     // arora
77                         'EP' => 'epiphany.png', // epiphany
78                         'FL' => 'flock.png',    // flock
79                         'SL' => 'sleipnir.gif'          ,// sleipnir
80                         'LU' => 'lunascape.gif',        // lunascape
81                         'SH' => 'shiira.gif',           // shiira
82                         'SW' => 'swift.png',    // swift
83                         'PS' => 'playstation.gif',      // playstation portable
84                         'PP' => 'playstation.gif',      // ワイプアウトピュア
85                         'NC' => 'netcaptor.gif',        // netcaptor
86                         'WT' => 'webtv.gif',    // webtv
87                         
88                         // クローラ
89                         'GB' => 'google.gif',   // Google
90                         'MS' => 'msn.gif',      // MSN
91                         'YA' => 'yahoo.gif',    // YahooSeeker
92                         'GO' => 'goo.gif',      // goo
93                         'HT' => 'hatena.gif',   // はてなアンテナ
94                         'NV' => 'naver.gif',    // Naver(韓国)
95                         
96                         // 携帯
97                         'DC' => 'docomo.gif',           // ドコモ
98                         'AU' => 'au.gif',               // au
99                         'SB' => 'softbank.gif',         // ソフトバンク
100                 );
101         }
102         /**
103          * テンプレートファイルを設定
104          *
105          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
106          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
107          *
108          * @param RequestManager $request               HTTPリクエスト処理クラス
109          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
110          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
111          */
112         function _setTemplate($request, &$param)
113         {
114                 $task = $request->trimValueOf('task');
115                 if ($task == 'loginstatus'){            // 一覧画面
116                         return 'loginstatus.tmpl.html';
117                 } else if ($task == 'loginstatus_history'){                     // ユーザ単位のログイン履歴
118                         return 'loginstatus_history.tmpl.html';
119                 } else {
120                         return '';
121                 }
122         }
123         /**
124          * テンプレートにデータ埋め込む
125          *
126          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
127          *
128          * @param RequestManager $request               HTTPリクエスト処理クラス
129          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
130          * @return                                                              なし
131          */
132         function _assign($request, &$param)
133         {
134                 $localeText = array();
135                 $task = $request->trimValueOf('task');
136                 
137                 if ($task == 'loginstatus'){    // 一覧画面
138                         $this->createList($request);
139                 } else if ($task == 'loginstatus_history'){                     // ユーザ単位のログイン履歴
140                         $this->createHistoryList($request);
141                         
142                         // テキストをローカライズ
143                         $localeText['label_loginhistory'] = $this->_('Login History');  // ログイン履歴
144                         $localeText['label_date'] = $this->_('Date');           // 日時
145                         $localeText['label_name'] = $this->_('Name:');          // 名前:
146                         $localeText['label_account'] = $this->_('Login Acount:');               // ログインアカウント:
147                         $localeText['label_access_log'] = $this->_('Access Log');       // アクセスログ
148                         $localeText['label_range'] = $this->_('Range:');                // 範囲:
149                         $localeText['label_go_back'] = $this->_('Go back');             // 戻る
150                         $localeText['label_browser'] = $this->_('Browser');             // ブラウザ
151                 }
152                 $this->setLocaleText($localeText);
153         }
154         /**
155          * 一覧画面作成
156          *
157          * @param RequestManager $request               HTTPリクエスト処理クラス
158          * @return                                                              なし
159          */
160         function createList($request)
161         {
162                 $act = $request->trimValueOf('act');
163                 
164                 $maxListCount = self::DEFAULT_LIST_COUNT;                               // 表示項目数
165                 $pageNo = $request->trimValueOf('page');                                // ページ番号
166                 if (empty($pageNo)) $pageNo = 1;
167                 
168                 // 総数を取得
169                 $totalCount = $this->db->getUserLoginStatusListCount();
170
171                 // 表示するページ番号の修正
172                 $pageCount = (int)(($totalCount -1) / $maxListCount) + 1;               // 総ページ数
173                 if ($pageNo < 1) $pageNo = 1;
174                 if ($pageNo > $pageCount) $pageNo = $pageCount;
175                 $this->firstNo = ($pageNo -1) * $maxListCount + 1;              // 先頭番号
176                 
177                 // ページング用リンク作成
178                 $pageLink = '';
179                 if ($pageCount > 1){    // ページが2ページ以上のときリンクを作成
180                         for ($i = 1; $i <= $pageCount; $i++){
181                                 if ($i == $pageNo){
182                                         $link = '&nbsp;' . $i;
183                                 } else {
184                                         $link = '&nbsp;<a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
185                                 }
186                                 $pageLink .= $link;
187                         }
188                 }
189                 $this->tmpl->addVar("_widget", "page_link", $pageLink);
190                 $this->tmpl->addVar("_widget", "total_count", $totalCount);
191                 $this->tmpl->addVar("_widget", "page", $pageNo);        // ページ番号
192                 
193                 // ログイン状況を取得
194                 $this->db->getUserLoginStatusList($maxListCount, $pageNo, array($this, 'userListLoop'));
195         }
196         /**
197          * ユーザ単位のログイン履歴一覧画面作成
198          *
199          * @param RequestManager $request               HTTPリクエスト処理クラス
200          * @return                                                              なし
201          */
202         function createHistoryList($request)
203         {
204                 // ウィンドウ制御
205                 $this->setKeepForeTaskForBackUrl();     // 遷移前のタスクを戻りURLとして維持する
206                 
207                 // パラメータの取得
208                 $this->clientIp = $this->gRequest->trimServerValueOf('REMOTE_ADDR');            // クライアントのIPアドレス
209                 $act = $request->trimValueOf('act');
210                 $this->loginStatus = $request->trimValueOf('loginstatus');              // ログイン状況
211                 $account = $request->trimValueOf('account');            // ログインアカウント
212                 $page = $request->trimValueOf('page');                  // ページ
213                 
214                 // 表示条件
215                 $viewCount = $request->trimValueOf('viewcount');// 表示項目数
216                 if ($viewCount == '') $viewCount = self::DEFAULT_LIST_COUNT;                            // 表示項目数
217                 $pageNo = $request->trimValueOf('page');                                // ページ番号
218                 if (empty($pageNo)) $pageNo = 1;
219                 
220                 // ユーザ情報取得
221                 $ret = $this->db->getUserByAccount($account, $row);
222                 if ($ret) $userName = $row['lu_name'];
223                 
224                 // ログイン状況メニュー作成
225                 $this->createLoginStatusMenu();
226                 
227                 // メッセージコード取得
228                 switch ($this->loginStatus){
229                         case '0':               // ログイン
230                         default:
231                                 $messageCode = array(2300, 2302);               // ログイン、自動ログイン
232                                 break;
233                         case '1':               // ログアウト
234                                 $messageCode = 2301;
235                                 break;
236                         case '2':               // エラー
237                                 $messageCode = 2310;
238                                 break;
239                 }
240                 // 検索オプション作成
241                 $searchOption = 'account=' . $account;
242                 
243                 // 総数を取得
244                 $totalCount = $this->db->getOpeLogCountByMessageCode($messageCode, $searchOption);
245
246                 // 表示するページ番号の修正
247                 $pageCount = (int)(($totalCount -1) / $viewCount) + 1;          // 総ページ数
248                 if ($pageNo < 1) $pageNo = 1;
249                 if ($pageNo > $pageCount) $pageNo = $pageCount;
250                 $startNo = ($pageNo -1) * $viewCount +1;                // 先頭の行番号
251                 $endNo = $pageNo * $viewCount > $totalCount ? $totalCount : $pageNo * $viewCount;// 最後の行番号
252                 
253                 // ページング用リンク作成
254                 $pageLink = '';
255                 if ($pageCount > 1){    // ページが2ページ以上のときリンクを作成
256                         for ($i = 1; $i <= $pageCount; $i++){
257                                 if ($i > self::MAX_PAGE_COUNT) break;                   // 最大ページ数以上のときは終了
258                                 if ($i == $pageNo){
259                                         $link = '&nbsp;' . $i;
260                                 } else {
261                                         $linkUrl = '?task=loginstatus_history&account=' . $account . '&loginstatus=' . intval($this->loginStatus) . '&page=' . $i;
262                                         $link = '&nbsp;<a href="' . $this->convertUrlToHtmlEntity($linkUrl) . '">' . $i . '</a>';
263                                 }
264                                 $pageLink .= $link;
265                         }
266                 }
267                 $this->tmpl->addVar("_widget", "page_link", $pageLink);
268                 $this->tmpl->addVar("_widget", "total_count", sprintf($this->_('%d Total'), $totalCount));
269                 $this->tmpl->addVar("_widget", "page", $pageNo);        // ページ番号
270                 $this->tmpl->addVar("_widget", "view_count", $viewCount);       // 最大表示項目数
271                 $this->tmpl->addVar("search_range", "start_no", $startNo);
272                 $this->tmpl->addVar("search_range", "end_no", $endNo);
273                 if ($totalCount > 0) $this->tmpl->setAttribute('search_range', 'visibility', 'visible');// 検出範囲を表示
274                 
275                 // アクセスログURL
276                 $accessLogUrl = '?task=accesslog_detail&openby=simple';
277                 if (!empty($this->server)) $accessLogUrl .= '&_server=' . $this->server;
278                 $this->tmpl->addVar("_widget", "access_log_url", $accessLogUrl);
279                 
280                 // 一覧作成
281                 $this->db->getOpeLogListByMessageCode($messageCode, $searchOption, $viewCount, $pageNo, array($this, 'logListLoop'));
282                 
283                 // 値を画面に埋め込む
284                 $this->tmpl->addVar("_widget", "name", $this->convertToDispString($userName));  // ユーザ名
285                 $this->tmpl->addVar("_widget", "account", $this->convertToDispString($account));        // アカウント
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 userListLoop($index, $fetchedRow, $param)
296         {
297                 // ユーザ種別
298                 switch ($fetchedRow['lu_user_type']){
299                         case UserInfo::USER_TYPE_NOT_AUTHENTICATED:
300                                 $userType = '<font color="darkgray">' . $this->_('Not authenticated') . '</font>';              // 未承認
301                                 break;
302                         case UserInfo::USER_TYPE_TMP:
303                                 $userType = '<font color="black">' . $this->_('Temporary User') . '</font>';            // 仮登録
304                                 break;
305                         case UserInfo::USER_TYPE_NORMAL:
306                                 $userType = '<font color="green">' . $this->_('Normal User') . '</font>';               // 一般ユーザ
307                                 break;
308                         case UserInfo::USER_TYPE_AUTHOR:
309                                 $userType = '<font color="yellowgreen">' . $this->_('Author') . '</font>';              // 投稿ユーザ
310                                 break;
311                         case UserInfo::USER_TYPE_MANAGER:
312                                 $userType = '<font color="orange">' . $this->_('Site Manager') . '</font>';             // 運営者
313                                 break;
314                         case UserInfo::USER_TYPE_SYS_ADMIN:
315                                 $userType = '<font color="red">' . $this->_('Administrator') . '</font>';               // 管理者
316                                 break;
317                         default:
318                                 $userType = $this->_('Out of Range');           // 該当なし
319                                 break;
320                 }
321                 
322                 // ログイン回数
323                 $count = $fetchedRow['ll_login_count'];
324                 if (empty($count)) $count = '0';
325                 $row = array(
326                         'no' => $index + 1,                                                                                                     // 行番号
327                         'serial' => $this->convertToDispString($fetchedRow['lu_serial']),                       // シリアル番号
328                         'id' => $this->convertToDispString($fetchedRow['lu_id']),                       // ID
329                         'name' => $this->convertToDispString($fetchedRow['lu_name']),           // 名前
330                         'account' => $this->convertToDispString($fetchedRow['lu_account']),             // アカウント
331                         'user_type' => $userType,               // ユーザ種別
332                         'count' => $count,              // ログイン回数
333                         'login_dt' => $this->convertToDispDateTime($fetchedRow['ll_last_login_dt']),    // 最終ログイン日時
334                         'selected' => $selected                                                                                         // 項目選択用ラジオボタン
335                 );
336                 $this->tmpl->addVars('userlist', $row);
337                 $this->tmpl->parseTemplate('userlist', 'a');
338                 return true;
339         }
340         /**
341          * ログイン状況選択メニュー作成
342          *
343          * @return なし
344          */
345         function createLoginStatusMenu()
346         {
347                 for ($i = 0; $i < count($this->loginStatusArray); $i++){
348                         $value = $this->loginStatusArray[$i]['value'];
349                         $name = $this->loginStatusArray[$i]['name'];
350                         
351                         $selected = '';
352                         if ($value == $this->loginStatus) $selected = 'selected';
353                         
354                         $row = array(
355                                 'value'    => $value,                   // ページID
356                                 'name'     => $name,                    // ページ名
357                                 'selected' => $selected                                                                                                         // 選択中かどうか
358                         );
359                         $this->tmpl->addVars('login_status_list', $row);
360                         $this->tmpl->parseTemplate('login_status_list', 'a');
361                 }
362         }
363         /**
364          * 運用ログ一覧取得したデータをテンプレートに設定する
365          *
366          * @param int $index                    行番号(0~)
367          * @param array $fetchedRow             フェッチ取得した行
368          * @param object $param                 未使用
369          * @return bool                                 true=処理続行の場合、false=処理終了の場合
370          */
371         function logListLoop($index, $fetchedRow, $param)
372         {
373                 $serial = $fetchedRow['ol_serial'];
374                                 
375                 $msgChecked = '';
376                 if ($fetchedRow['ol_checked']){
377                         $msgChecked = 'checked';
378                 }
379                 $accessLog = '';
380                 if (!empty($fetchedRow['ol_access_log_serial'])) $accessLog = $this->convertToDispString($fetchedRow['ol_access_log_serial']);
381                 
382                 // ログのサブ種別
383                 $logType = '';
384                 if ($this->loginStatus == 0){           // ログインの場合
385                         switch ($fetchedRow['ol_message_code']){
386                                 case 2300:                      // ログイン
387                                         break;
388                                 case 2302:                      // 自動ログイン
389                                         $logType = '自動';
390                                         break;
391                         }
392                 }
393                                 
394                 // アクセス元のクライアントIP
395                 $ip = $fetchedRow['al_ip'];
396                 $ipStr = $this->convertToDispString($ip);
397                 if ($ip == $this->clientIp){                    // クライアントのIPアドレスと同じときはグリーンで表示
398                         $ipStr = '<font color="green">' . $ipStr . '</font>';
399                 }
400                 
401                 // ブラウザ、プラットフォームの情報を取得
402                 $browserCode = $this->gInstance->getAnalyzeManager()->getBrowserType($fetchedRow['al_user_agent'], $version);
403                 $browserImg = '';
404                 if (!empty($browserCode)){
405                         $iconFile = $this->browserIconFile[$browserCode];
406                         if (!empty($iconFile)){
407                                 $iconTitle = $browserCode;
408                                 $iconUrl = $this->gEnv->getRootUrl() . self::BROWSER_ICON_DIR . $iconFile;
409                                 $browserImg = '<img src="' . $this->getUrl($iconUrl) . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
410                         }
411                 }
412                 
413                 // メッセージのリンク先
414                 $messageUrl = '?task=opelog_detail&serial=' . $serial;
415                 
416                 $row = array(
417                         'index' => $index,                                                                                                      // 行番号
418                         'serial' => $this->convertToDispString($serial),                        // シリアル番号
419                         'message' => $this->convertToDispString($fetchedRow['ol_message']),             // メッセージ
420                         'url' => $this->convertUrlToHtmlEntity($messageUrl),                    // メッセージのリンク先
421                         'type' => $this->convertToDispString($logType),         // ログのサブ種別
422                         'ip' => $ipStr,         // クライアントIP
423                         'access_log' => $accessLog,             // アクセスログ番号
424                         'browser' => $browserImg,               // ブラウザ
425                         'output_dt' => $this->convertToDispDateTime($fetchedRow['ol_dt'])       // 出力日時
426                 );
427                 $this->tmpl->addVars('loglist', $row);
428                 $this->tmpl->parseTemplate('loglist', 'a');
429                 
430                 // 表示中のコンテンツIDを保存
431                 $this->serialArray[] = $serial;
432                 return true;
433         }
434 }
435 ?>