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-2016 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_mainUserBaseWidgetContainer.php');
18 class admin_mainLoginhistoryWidgetContainer extends admin_mainUserBaseWidgetContainer
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/'; // ブラウザアイコンディレクトリ
30 function __construct()
33 parent::__construct();
36 $this->loginStatusArray = array( array( 'name' => $this->_('Login'), 'value' => '0'), // ログイン
37 array( 'name' => $this->_('Logout'), 'value' => '1'), // ログアウト
38 array( 'name' => $this->_('Error'), 'value' => '2')); // エラー
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
60 'MC' => '', // ncsa mosaic
62 'OW' => 'omniweb.png', // omniweb
63 'HJ' => '', // hotjava
64 'BX' => '', // browsex
65 'AV' => '', // amigavoyager
66 'AW' => '', // amiga-aweb
67 'IB' => '', // ibrowse
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
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(韓国)
89 'DC' => 'docomo.gif', // ドコモ
90 'AU' => 'au.gif', // au
91 'SB' => 'softbank.gif', // ソフトバンク
97 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
98 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
100 * @param RequestManager $request HTTPリクエスト処理クラス
101 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
102 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
104 function _setTemplate($request, &$param)
106 return 'loginhistory.tmpl.html';
111 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
113 * @param RequestManager $request HTTPリクエスト処理クラス
114 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
117 function _assign($request, &$param)
119 $localeText = array();
120 $task = $request->trimValueOf('task');
122 if ($task == self::TASK_LOGINHISTORY){ // ログイン履歴
123 $this->createList($request);
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'); // ブラウザ
135 $this->setLocaleText($localeText);
140 * @param RequestManager $request HTTPリクエスト処理クラス
143 function createList($request)
146 $this->setKeepForeTaskForBackUrl(); // 遷移前のタスクを戻りURLとして維持する
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'); // ページ
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'); // ページ番号
164 // $ret = $this->_mainDb->getUserByAccount($account, $row);
165 // if ($ret) $userName = $row['lu_name'];
166 $ret = $this->_mainDb->getUserById($userId, $row);
168 $account = $row['lu_account']; // ユーザアカウント
169 $userName = $row['lu_name'];
173 $this->createLoginStatusMenu();
176 switch ($this->loginStatus){
179 $messageCode = array(2300, 2302); // ログイン、自動ログイン
189 $searchOption = 'account=' . $account;
192 $totalCount = $this->_mainDb->getOpeLogCountByMessageCode($messageCode, $searchOption);
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;// 最後の行番号
203 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
204 for ($i = 1; $i <= $pageCount; $i++){
205 if ($i > self::MAX_PAGE_COUNT) break; // 最大ページ数以上のときは終了
207 $link = ' ' . $i;
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 = ' <a href="' . $this->convertUrlToHtmlEntity($linkUrl) . '">' . $i . '</a>';
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');// 検出範囲を表示
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);
230 $this->_mainDb->getOpeLogListByMessageCode($messageCode, $searchOption, $viewCount, $pageNo, array($this, 'logListLoop'));
231 if (count($this->serialArray) <= 0) $this->tmpl->setAttribute('loglist', 'visibility', 'hidden'); // 履歴がないときは一覧を表示しない
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)); // アカウント
243 function createLoginStatusMenu()
245 for ($i = 0; $i < count($this->loginStatusArray); $i++){
246 $value = $this->loginStatusArray[$i]['value'];
247 $name = $this->loginStatusArray[$i]['name'];
250 if ($value == $this->loginStatus) $selected = 'selected';
253 'value' => $value, // ページID
254 'name' => $name, // ページ名
255 'selected' => $selected // 選択中かどうか
257 $this->tmpl->addVars('login_status_list', $row);
258 $this->tmpl->parseTemplate('login_status_list', 'a');
262 * 運用ログ一覧取得したデータをテンプレートに設定する
264 * @param int $index 行番号(0~)
265 * @param array $fetchedRow フェッチ取得した行
266 * @param object $param 未使用
267 * @return bool true=処理続行の場合、false=処理終了の場合
269 function logListLoop($index, $fetchedRow, $param)
271 $serial = $fetchedRow['ol_serial'];
272 $agent = $fetchedRow['al_user_agent'];
275 if ($fetchedRow['ol_checked']){
276 $msgChecked = 'checked';
279 if (!empty($fetchedRow['ol_access_log_serial'])) $accessLog = $this->convertToDispString($fetchedRow['ol_access_log_serial']);
283 if ($this->loginStatus == 0){ // ログインの場合
284 switch ($fetchedRow['ol_message_code']){
294 $ip = $fetchedRow['al_ip'];
295 $ipStr = $this->convertToDispString($ip);
296 if ($ip == $this->clientIp){ // クライアントのIPアドレスと同じときはグリーンで表示
297 $ipStr = '<font color="green">' . $ipStr . '</font>';
300 // ブラウザ、プラットフォームの情報を取得
301 /* $browserCode = $this->gInstance->getAnalyzeManager()->getBrowserType($fetchedRow['al_user_agent'], $version);
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 . '" />';
311 $browserTypeInfo = $this->gInstance->getAnalyzeManager()->getBrowserType($agent);
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 . '" />';
323 $messageUrl = '?task=opelog_detail&serial=' . $serial;
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']) // 出力日時
336 $this->tmpl->addVars('loglist', $row);
337 $this->tmpl->parseTemplate('loglist', 'a');
340 $this->serialArray[] = $serial;