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-2011 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_photo_mainAuthorWidgetContainer.php 4383 2011-10-07 06:25:53Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_photo_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/photo_mainDb.php');
18 require_once($gEnvManager->getIncludePath() . '/common/userInfo.php'); // ユーザ情報クラス
20 class admin_photo_mainAuthorWidgetContainer extends admin_photo_mainBaseWidgetContainer
22 private $serialNo; // シリアルNo
23 private $serialArray = array(); // 表示されているコンテンツシリアル番号
24 const DEFAULT_LIST_COUNT = 30; // 最大リスト表示数
25 const DEFAULT_PASSWORD = '********'; // 設定済みを示すパスワード
26 const ACTIVE_ICON_FILE = '/images/system/active.png'; // 公開中アイコン
27 const INACTIVE_ICON_FILE = '/images/system/inactive.png'; // 非公開アイコン
32 function __construct()
35 parent::__construct();
40 * ヘルプの設定を行う場合はヘルプIDを返す。
41 * ヘルプデータの読み込むディレクトリは「自ウィジェットディレクトリ/include/help」に固定。
43 * @param RequestManager $request HTTPリクエスト処理クラス
44 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
45 * @return string ヘルプID。ヘルプデータはファイル名「help_[ヘルプID].php」で作成。ヘルプを使用しない場合は空文字列「''」を返す。
47 function _setHelp($request, &$param)
54 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
55 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
57 * @param RequestManager $request HTTPリクエスト処理クラス
58 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
59 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
61 function _setTemplate($request, &$param)
63 $task = $request->trimValueOf('task');
64 if ($task == 'author_detail'){ // 詳細画面
65 return 'admin_author_detail.tmpl.html';
67 return 'admin_author.tmpl.html';
73 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
75 * @param RequestManager $request HTTPリクエスト処理クラス
76 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
79 function _assign($request, &$param)
81 $localeText = array();
82 $task = $request->trimValueOf('task');
84 if ($task == 'author_detail'){ // 詳細画面
85 $this->createDetail($request);
88 $localeText['msg_add'] = $this->_('Add new user?'); // 新規ユーザを追加しますか?
89 $localeText['msg_update'] = $this->_('Update user configuration?'); // ユーザ情報を更新しますか?
90 $localeText['msg_delete'] = $this->_('Delete user?'); // ユーザを削除しますか?
91 $localeText['msg_no_name'] = $this->_('No name entered.'); // 名前が入力されていません
92 $localeText['msg_no_account'] = $this->_('No login account entered.'); // ログインアカウントが入力されていません
93 $localeText['msg_no_password'] = $this->_('No password entered.'); // パスワードが入力されていません
94 $localeText['label_author_detail'] = $this->_('Image Manager Detail'); // 画像管理者詳細
95 $localeText['label_name'] = $this->_('Name'); // 名前
96 $localeText['label_account'] = $this->_('Login Account'); // ログインアカウント
97 $localeText['label_password'] = $this->_('Password'); // パスワード
98 $localeText['label_login_enable'] = $this->_('Login Enable'); // ログイン可
99 $localeText['label_go_back'] = $this->_('Go back'); // 戻る
100 $localeText['label_delete'] = $this->_('Delete'); // 削除
101 $localeText['label_update'] = $this->_('Update'); // 更新
102 $localeText['label_add'] = $this->_('Add'); // 新規追加
104 $this->createList($request);
107 $localeText['msg_select_item'] = $this->_('Select item to edit.'); // 編集する項目を選択してください
108 $localeText['msg_select_del_item'] = $this->_('Select item to delete.'); // 削除する項目を選択してください
109 $localeText['msg_delete_item'] = $this->_('Delete selected item?');// 選択項目を削除しますか?
110 $localeText['label_author'] = $this->_('Image Manager List'); // 画像管理者詳細一覧
111 $localeText['label_check'] = $this->_('Select'); // 選択
112 $localeText['label_name'] = $this->_('Name'); // 名前
113 $localeText['label_account'] = $this->_('Login Account'); // ログインアカウント
114 $localeText['label_image_count'] = $this->_('Image Count'); // 画像数
115 $localeText['label_published_image_count'] = $this->_('Published Image Count'); // 公開数
116 $localeText['label_login_count'] = $this->_('Login Count'); // ログイン回数
117 //$localeText['label_update_dt'] = $this->_('Update Date'); // 更新日
118 $localeText['label_regist_dt'] = $this->_('Registered Date'); // 登録日
119 $localeText['label_new'] = $this->_('New'); // 新規
120 $localeText['label_edit'] = $this->_('Edit'); // 編集
121 $localeText['label_delete'] = $this->_('Delete'); // 削除
122 $localeText['label_range'] = $this->_('Range:'); // 範囲:
124 $this->setLocaleText($localeText);
129 * @param RequestManager $request HTTPリクエスト処理クラス
132 function createList($request)
134 $act = $request->trimValueOf('act');
136 if ($act == 'delete'){ // メニュー項目の削除
137 $listedItem = explode(',', $request->trimValueOf('seriallist'));
139 for ($i = 0; $i < count($listedItem); $i++){
141 $itemName = 'item' . $i . '_selected';
142 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
144 if ($itemValue){ // チェック項目
145 $delItems[] = $listedItem[$i];
148 if (count($delItems) > 0){
149 $ret = self::$_mainDb->delUserBySerial($delItems);
150 if ($ret){ // データ削除成功のとき
151 $this->setGuidanceMsg($this->_('Item deleted.')); // データを削除しました
153 $this->setAppErrorMsg($this->_('Failed in deleting item.')); // データ削除に失敗しました
158 $viewCount = self::DEFAULT_LIST_COUNT; // 表示項目数
159 $pageNo = $request->trimValueOf('page'); // ページ番号
160 if (empty($pageNo)) $pageNo = 1;
163 $totalCount = self::$_mainDb->getAllUserListCount(photo_mainCommonDef::USER_OPTION);
166 $pageCount = (int)(($totalCount -1) / $viewCount) + 1; // 総ページ数
167 if ($pageNo < 1) $pageNo = 1;
168 if ($pageNo > $pageCount) $pageNo = $pageCount;
169 $this->firstNo = ($pageNo -1) * $viewCount + 1; // 先頭番号
170 $startNo = ($pageNo -1) * $viewCount +1; // 先頭の行番号
171 $endNo = $pageNo * $viewCount > $totalCount ? $totalCount : $pageNo * $viewCount;// 最後の行番号
175 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
176 for ($i = 1; $i <= $pageCount; $i++){
178 $link = ' ' . $i;
180 $link = ' <a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
185 $this->tmpl->addVar("_widget", "page_link", $pageLink);
186 $this->tmpl->addVar("_widget", "total_count", sprintf($this->_('%d Total'), $totalCount));
187 $this->tmpl->addVar("_widget", "page", $pageNo); // ページ番号
188 $this->tmpl->addVar("search_range", "start_no", $startNo);
189 $this->tmpl->addVar("search_range", "end_no", $endNo);
190 if ($totalCount > 0) $this->tmpl->setAttribute('search_range', 'visibility', 'visible');// 検出範囲を表示
193 self::$_mainDb->getAllUserList(photo_mainCommonDef::USER_OPTION, $viewCount, $pageNo, array($this, 'userListLoop'));
194 if (count($this->serialArray) > 0){
195 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
198 $this->tmpl->setAttribute('authorlist', 'visibility', 'hidden');
204 * @param RequestManager $request HTTPリクエスト処理クラス
207 function createDetail($request)
209 $act = $request->trimValueOf('act');
210 $this->serialNo = intval($request->trimValueOf('serial')); // 選択項目のシリアル番号
211 $name = $request->trimValueOf('item_name');
212 $account = $request->trimValueOf('item_account');
213 $password = $request->trimValueOf('password');
214 $canLogin = ($request->trimValueOf('item_canlogin') == 'on') ? 1 : 0; // ログインできるかどうか
216 $isAdmin = false; // 管理権限ありかどうか
217 $limitedMenu = false; // ユーザタイプメニューの項目を制限するかどうか
218 $reloadData = false; // データの再読み込み
219 if ($act == 'update'){ // 行更新のとき
221 $this->checkInput($name, $this->_('Name')); // 名前
222 $this->checkInput($account, $this->_('Login Account')); // アカウント
226 $ret = self::$_mainDb->getUserBySerial($this->serialNo, $row);
228 if ($row['lu_account'] != $account && $this->_db->isExistsAccount($account)) $this->setMsg(self::MSG_USER_ERR, $this->_('Login account is duplicated.')); // アカウントが重複しています
230 $this->setMsg(self::MSG_APP_ERR, $this->_('Failed in getting data.')); // データ取得に失敗しました
234 if ($this->getMsgCount() == 0){
236 $ret = $this->_db->updateLoginUser($this->serialNo, $name, $account, $password, UserInfo::USER_TYPE_MANAGER/*システム運用者*/, $canLogin, $startDt, $endDt, $newSerial);
237 if ($ret){ // データ追加成功のとき
238 $this->setMsg(self::MSG_GUIDANCE, $this->_('Item updated.')); // データを更新しました
239 $this->serialNo = $newSerial;
240 $reloadData = true; // データの再読み込み
242 $this->setMsg(self::MSG_APP_ERR, $this->_('Failed in deleting item.')); // データ更新に失敗しました
245 } else if ($act == 'add'){ // 新規追加のとき
247 $this->checkInput($name, $this->_('Name')); // 名前
248 $this->checkInput($account, $this->_('Login Account')); // アカウント
251 if ($this->_db->isExistsAccount($account)) $this->setMsg(self::MSG_USER_ERR, $this->_('Login account is duplicated.')); // アカウントが重複しています
254 if ($this->getMsgCount() == 0){
255 $ret = $this->_db->addNewLoginUser($name, $account, $password, UserInfo::USER_TYPE_MANAGER/*システム運用者*/, $canLogin, null/*有効期間開始*/, null/*有効期間終了*/, $newSerial,
256 $this->gEnv->getCurrentWidgetId()/*制限ウィジェット*/, photo_mainCommonDef::USER_OPTION);
257 if ($ret){ // データ追加成功のとき
258 $this->setMsg(self::MSG_GUIDANCE, $this->_('Item added.')); // データを追加しました
259 $this->serialNo = $newSerial;
260 $reloadData = true; // データの再読み込み
262 $this->setMsg(self::MSG_APP_ERR, $this->_('Failed in adding item.')); // データ追加に失敗しました
265 } else if ($act == 'delete'){ // 削除のとき
266 $ret = self::$_mainDb->delUserBySerial(array($this->serialNo));
267 if ($ret){ // データ削除成功のとき
268 $this->setMsg(self::MSG_GUIDANCE, $this->_('Item deleted.')); // データを削除しました
270 $this->setMsg(self::MSG_APP_ERR, $this->_('Failed in deleting item.')); // データ削除に失敗しました
274 $canLogin = 1; // ログインできるかどうか
275 $reloadData = true; // データの再読み込み
277 if ($reloadData){ // データの再読み込み
279 $ret = self::$_mainDb->getUserBySerial($this->serialNo, $row);
281 $name = $row['lu_name'];
282 $account = $row['lu_account'];
284 $canLogin = $row['lu_enable_login']; // ログインできるかどうか
285 $loginUserId = $row['lu_id']; // ユーザID
290 $this->tmpl->addVar("_widget", "serial", $this->serialNo);
291 $this->tmpl->addVar("_widget", "name", $this->convertToDispString($name));
292 $this->tmpl->addVar("_widget", "account", $this->convertToDispString($account));
294 if ($canLogin) $canLoginCheck = 'checked';
295 $this->tmpl->addVar("_widget", "can_login", $canLoginCheck);
296 $this->tmpl->addVar("_widget", "userid", $loginUserId);// ユーザID
298 if (empty($this->serialNo)){ // ユーザIDが空のときは新規とする
299 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 新規登録ボタン表示
301 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 更新ボタン表示
302 $this->tmpl->addVar("_widget", "password", self::DEFAULT_PASSWORD);// 入力済みを示すパスワードの設定
306 $this->tmpl->addVar("_widget", "script_url", $this->getUrl($this->gEnv->getScriptsUrl()));
309 * ユーザリスト、取得したデータをテンプレートに設定する
311 * @param int $index 行番号(0~)
312 * @param array $fetchedRow フェッチ取得した行
313 * @param object $param 未使用
314 * @return bool true=処理続行の場合、false=処理終了の場合
316 function userListLoop($index, $fetchedRow, $param)
319 $loginCount = $fetchedRow['ll_login_count'];
320 if (empty($loginCount)) $loginCount = '0';
323 self::$_mainDb->getPhotoCount($fetchedRow['lu_id'], $allCount, $visbleCount);
326 'index' => $index, // 行番号
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 'image_count' => $this->convertToDispString($allCount), // 画像数
332 'visible_count' => $this->convertToDispString($visbleCount), // 公開画像数
333 'regist_dt' => $this->convertToDispDateTime($fetchedRow['lu_regist_dt']), // 登録日時
334 'login_count' => $this->convertToDispString($loginCount), // ログイン回数
335 'selected' => $selected // 項目選択用ラジオボタン
337 $this->tmpl->addVars('authorlist', $row);
338 $this->tmpl->parseTemplate('authorlist', 'a');
341 $this->serialArray[] = $fetchedRow['lu_serial'];