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-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
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/admin_mainDb.php');
18 require_once($gEnvManager->getIncludePath() . '/common/userInfo.php'); // ユーザ情報クラス
20 class admin_mainLoginstatusWidgetContainer extends admin_mainBaseWidgetContainer
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/'; // ブラウザアイコンディレクトリ
34 function __construct()
37 parent::__construct();
40 $this->db = new admin_mainDb();
41 $this->sysDb = $this->gInstance->getSytemDbObject();
44 $this->loginStatusArray = array( array( 'name' => $this->_('Login'), 'value' => '0'), // ログイン
45 array( 'name' => $this->_('Logout'), 'value' => '1'), // ログアウト
46 array( 'name' => $this->_('Error'), 'value' => '2')); // エラー
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
68 'MC' => '', // ncsa mosaic
70 'OW' => 'omniweb.png', // omniweb
71 'HJ' => '', // hotjava
72 'BX' => '', // browsex
73 'AV' => '', // amigavoyager
74 'AW' => '', // amiga-aweb
75 'IB' => '', // ibrowse
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
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(韓国)
97 'DC' => 'docomo.gif', // ドコモ
98 'AU' => 'au.gif', // au
99 'SB' => 'softbank.gif', // ソフトバンク
105 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
106 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
108 * @param RequestManager $request HTTPリクエスト処理クラス
109 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
110 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
112 function _setTemplate($request, &$param)
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';
126 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
128 * @param RequestManager $request HTTPリクエスト処理クラス
129 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
132 function _assign($request, &$param)
134 $localeText = array();
135 $task = $request->trimValueOf('task');
137 if ($task == 'loginstatus'){ // 一覧画面
138 $this->createList($request);
139 } else if ($task == 'loginstatus_history'){ // ユーザ単位のログイン履歴
140 $this->createHistoryList($request);
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'); // ブラウザ
152 $this->setLocaleText($localeText);
157 * @param RequestManager $request HTTPリクエスト処理クラス
160 function createList($request)
162 $act = $request->trimValueOf('act');
164 $maxListCount = self::DEFAULT_LIST_COUNT; // 表示項目数
165 $pageNo = $request->trimValueOf('page'); // ページ番号
166 if (empty($pageNo)) $pageNo = 1;
169 $totalCount = $this->db->getUserLoginStatusListCount();
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; // 先頭番号
179 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
180 for ($i = 1; $i <= $pageCount; $i++){
182 $link = ' ' . $i;
184 $link = ' <a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
189 $this->tmpl->addVar("_widget", "page_link", $pageLink);
190 $this->tmpl->addVar("_widget", "total_count", $totalCount);
191 $this->tmpl->addVar("_widget", "page", $pageNo); // ページ番号
194 $this->db->getUserLoginStatusList($maxListCount, $pageNo, array($this, 'userListLoop'));
199 * @param RequestManager $request HTTPリクエスト処理クラス
202 function createHistoryList($request)
205 $this->setKeepForeTaskForBackUrl(); // 遷移前のタスクを戻りURLとして維持する
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'); // ページ
215 $viewCount = $request->trimValueOf('viewcount');// 表示項目数
216 if ($viewCount == '') $viewCount = self::DEFAULT_LIST_COUNT; // 表示項目数
217 $pageNo = $request->trimValueOf('page'); // ページ番号
218 if (empty($pageNo)) $pageNo = 1;
221 $ret = $this->db->getUserByAccount($account, $row);
222 if ($ret) $userName = $row['lu_name'];
225 $this->createLoginStatusMenu();
228 switch ($this->loginStatus){
231 $messageCode = array(2300, 2302); // ログイン、自動ログイン
241 $searchOption = 'account=' . $account;
244 $totalCount = $this->db->getOpeLogCountByMessageCode($messageCode, $searchOption);
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;// 最後の行番号
255 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
256 for ($i = 1; $i <= $pageCount; $i++){
257 if ($i > self::MAX_PAGE_COUNT) break; // 最大ページ数以上のときは終了
259 $link = ' ' . $i;
261 $linkUrl = '?task=loginstatus_history&account=' . $account . '&loginstatus=' . intval($this->loginStatus) . '&page=' . $i;
262 $link = ' <a href="' . $this->convertUrlToHtmlEntity($linkUrl) . '">' . $i . '</a>';
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');// 検出範囲を表示
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);
281 $this->db->getOpeLogListByMessageCode($messageCode, $searchOption, $viewCount, $pageNo, array($this, 'logListLoop'));
284 $this->tmpl->addVar("_widget", "name", $this->convertToDispString($userName)); // ユーザ名
285 $this->tmpl->addVar("_widget", "account", $this->convertToDispString($account)); // アカウント
288 * ユーザリスト、取得したデータをテンプレートに設定する
290 * @param int $index 行番号(0~)
291 * @param array $fetchedRow フェッチ取得した行
292 * @param object $param 未使用
293 * @return bool true=処理続行の場合、false=処理終了の場合
295 function userListLoop($index, $fetchedRow, $param)
298 switch ($fetchedRow['lu_user_type']){
299 case UserInfo::USER_TYPE_NOT_AUTHENTICATED:
300 $userType = '<font color="darkgray">' . $this->_('Not authenticated') . '</font>'; // 未承認
302 case UserInfo::USER_TYPE_TMP:
303 $userType = '<font color="black">' . $this->_('Temporary User') . '</font>'; // 仮登録
305 case UserInfo::USER_TYPE_NORMAL:
306 $userType = '<font color="green">' . $this->_('Normal User') . '</font>'; // 一般ユーザ
308 case UserInfo::USER_TYPE_AUTHOR:
309 $userType = '<font color="yellowgreen">' . $this->_('Author') . '</font>'; // 投稿ユーザ
311 case UserInfo::USER_TYPE_MANAGER:
312 $userType = '<font color="orange">' . $this->_('Site Manager') . '</font>'; // 運営者
314 case UserInfo::USER_TYPE_SYS_ADMIN:
315 $userType = '<font color="red">' . $this->_('Administrator') . '</font>'; // 管理者
318 $userType = $this->_('Out of Range'); // 該当なし
323 $count = $fetchedRow['ll_login_count'];
324 if (empty($count)) $count = '0';
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 // 項目選択用ラジオボタン
336 $this->tmpl->addVars('userlist', $row);
337 $this->tmpl->parseTemplate('userlist', 'a');
345 function createLoginStatusMenu()
347 for ($i = 0; $i < count($this->loginStatusArray); $i++){
348 $value = $this->loginStatusArray[$i]['value'];
349 $name = $this->loginStatusArray[$i]['name'];
352 if ($value == $this->loginStatus) $selected = 'selected';
355 'value' => $value, // ページID
356 'name' => $name, // ページ名
357 'selected' => $selected // 選択中かどうか
359 $this->tmpl->addVars('login_status_list', $row);
360 $this->tmpl->parseTemplate('login_status_list', 'a');
364 * 運用ログ一覧取得したデータをテンプレートに設定する
366 * @param int $index 行番号(0~)
367 * @param array $fetchedRow フェッチ取得した行
368 * @param object $param 未使用
369 * @return bool true=処理続行の場合、false=処理終了の場合
371 function logListLoop($index, $fetchedRow, $param)
373 $serial = $fetchedRow['ol_serial'];
376 if ($fetchedRow['ol_checked']){
377 $msgChecked = 'checked';
380 if (!empty($fetchedRow['ol_access_log_serial'])) $accessLog = $this->convertToDispString($fetchedRow['ol_access_log_serial']);
384 if ($this->loginStatus == 0){ // ログインの場合
385 switch ($fetchedRow['ol_message_code']){
395 $ip = $fetchedRow['al_ip'];
396 $ipStr = $this->convertToDispString($ip);
397 if ($ip == $this->clientIp){ // クライアントのIPアドレスと同じときはグリーンで表示
398 $ipStr = '<font color="green">' . $ipStr . '</font>';
401 // ブラウザ、プラットフォームの情報を取得
402 $browserCode = $this->gInstance->getAnalyzeManager()->getBrowserType($fetchedRow['al_user_agent'], $version);
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 . '" />';
414 $messageUrl = '?task=opelog_detail&serial=' . $serial;
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']) // 出力日時
427 $this->tmpl->addVars('loglist', $row);
428 $this->tmpl->parseTemplate('loglist', 'a');
431 $this->serialArray[] = $serial;