OSDN Git Service

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