OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / photo_main / include / container / admin_photo_mainAuthorWidgetContainer.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-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
15  */
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');          // ユーザ情報クラス
19
20 class admin_photo_mainAuthorWidgetContainer extends admin_photo_mainBaseWidgetContainer
21 {
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';               // 非公開アイコン
28         
29         /**
30          * コンストラクタ
31          */
32         function __construct()
33         {
34                 // 親クラスを呼び出す
35                 parent::__construct();
36         }
37         /**
38          * ヘルプデータを設定
39          *
40          * ヘルプの設定を行う場合はヘルプIDを返す。
41          * ヘルプデータの読み込むディレクトリは「自ウィジェットディレクトリ/include/help」に固定。
42          *
43          * @param RequestManager $request               HTTPリクエスト処理クラス
44          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
45          * @return string                                               ヘルプID。ヘルプデータはファイル名「help_[ヘルプID].php」で作成。ヘルプを使用しない場合は空文字列「''」を返す。
46          */
47         function _setHelp($request, &$param)
48         {       
49                 return 'author';
50         }
51         /**
52          * テンプレートファイルを設定
53          *
54          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
55          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
56          *
57          * @param RequestManager $request               HTTPリクエスト処理クラス
58          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
59          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
60          */
61         function _setTemplate($request, &$param)
62         {
63                 $task = $request->trimValueOf('task');
64                 if ($task == 'author_detail'){          // 詳細画面
65                         return 'admin_author_detail.tmpl.html';
66                 } else {                        // 一覧画面
67                         return 'admin_author.tmpl.html';
68                 }
69         }
70         /**
71          * テンプレートにデータ埋め込む
72          *
73          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
74          *
75          * @param RequestManager $request               HTTPリクエスト処理クラス
76          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
77          * @param                                                               なし
78          */
79         function _assign($request, &$param)
80         {
81                 $localeText = array();
82                 $task = $request->trimValueOf('task');
83                 
84                 if ($task == 'author_detail'){          // 詳細画面
85                         $this->createDetail($request);
86                         
87                         // テキストをローカライズ
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');     // 新規追加
103                 } else {                        // 一覧画面
104                         $this->createList($request);
105                         
106                         // テキストをローカライズ
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:');                // 範囲:
123                 }
124                 $this->setLocaleText($localeText);
125         }
126         /**
127          * 一覧画面作成
128          *
129          * @param RequestManager $request               HTTPリクエスト処理クラス
130          * @param                                                               なし
131          */
132         function createList($request)
133         {
134                 $act = $request->trimValueOf('act');
135                 
136                 if ($act == 'delete'){          // メニュー項目の削除
137                         $listedItem = explode(',', $request->trimValueOf('seriallist'));
138                         $delItems = array();
139                         for ($i = 0; $i < count($listedItem); $i++){
140                                 // 項目がチェックされているかを取得
141                                 $itemName = 'item' . $i . '_selected';
142                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
143                                 
144                                 if ($itemValue){                // チェック項目
145                                         $delItems[] = $listedItem[$i];
146                                 }
147                         }
148                         if (count($delItems) > 0){
149                                 $ret = self::$_mainDb->delUserBySerial($delItems);
150                                 if ($ret){              // データ削除成功のとき
151                                         $this->setGuidanceMsg($this->_('Item deleted.'));               // データを削除しました
152                                 } else {
153                                         $this->setAppErrorMsg($this->_('Failed in deleting item.'));            // データ削除に失敗しました
154                                 }
155                         }
156                 }
157                 
158                 $viewCount = self::DEFAULT_LIST_COUNT;                          // 表示項目数
159                 $pageNo = $request->trimValueOf('page');                                // ページ番号
160                 if (empty($pageNo)) $pageNo = 1;
161                 
162                 // 総数を取得
163                 $totalCount = self::$_mainDb->getAllUserListCount(photo_mainCommonDef::USER_OPTION);
164
165                 // 表示するページ番号の修正
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;// 最後の行番号
172                 
173                 // ページング用リンク作成
174                 $pageLink = '';
175                 if ($pageCount > 1){    // ページが2ページ以上のときリンクを作成
176                         for ($i = 1; $i <= $pageCount; $i++){
177                                 if ($i == $pageNo){
178                                         $link = '&nbsp;' . $i;
179                                 } else {
180                                         $link = '&nbsp;<a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
181                                 }
182                                 $pageLink .= $link;
183                         }
184                 }
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');// 検出範囲を表示
191                 
192                 // ユーザリストを取得
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, ','));// 表示項目のシリアル番号を設定
196                 } else {
197                         // 項目がないときは、一覧を表示しない
198                         $this->tmpl->setAttribute('authorlist', 'visibility', 'hidden');
199                 }
200         }
201         /**
202          * 詳細画面作成
203          *
204          * @param RequestManager $request               HTTPリクエスト処理クラス
205          * @param                                                               なし
206          */
207         function createDetail($request)
208         {
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;           // ログインできるかどうか
215                 
216                 $isAdmin = false;                       // 管理権限ありかどうか
217                 $limitedMenu = false;           // ユーザタイプメニューの項目を制限するかどうか
218                 $reloadData = false;            // データの再読み込み
219                 if ($act == 'update'){          // 行更新のとき
220                         // 入力チェック
221                         $this->checkInput($name, $this->_('Name'));             // 名前
222                         $this->checkInput($account, $this->_('Login Account')); // アカウント
223                         
224                         // アカウント重複チェック
225                         // 設定データを取得
226                         $ret = self::$_mainDb->getUserBySerial($this->serialNo, $row);
227                         if ($ret){
228                                 if ($row['lu_account'] != $account && $this->_db->isExistsAccount($account)) $this->setMsg(self::MSG_USER_ERR, $this->_('Login account is duplicated.'));               // アカウントが重複しています
229                         } else {
230                                 $this->setMsg(self::MSG_APP_ERR, $this->_('Failed in getting data.'));                  // データ取得に失敗しました
231                         }
232                         
233                         // エラーなしの場合は、データを更新
234                         if ($this->getMsgCount() == 0){
235                                 
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;             // データの再読み込み
241                                 } else {
242                                         $this->setMsg(self::MSG_APP_ERR, $this->_('Failed in deleting item.'));         // データ更新に失敗しました
243                                 }
244                         }
245                 } else if ($act == 'add'){              // 新規追加のとき
246                         // 入力チェック
247                         $this->checkInput($name, $this->_('Name'));             // 名前
248                         $this->checkInput($account, $this->_('Login Account')); // アカウント
249                         
250                         // アカウント重複チェック
251                         if ($this->_db->isExistsAccount($account)) $this->setMsg(self::MSG_USER_ERR, $this->_('Login account is duplicated.')); // アカウントが重複しています
252                                                 
253                         // エラーなしの場合は、データを登録
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;             // データの再読み込み
261                                 } else {
262                                         $this->setMsg(self::MSG_APP_ERR, $this->_('Failed in adding item.'));   // データ追加に失敗しました
263                                 }
264                         }
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.'));   // データを削除しました
269                         } else {
270                                 $this->setMsg(self::MSG_APP_ERR, $this->_('Failed in deleting item.')); // データ削除に失敗しました
271                         }
272                 } else {
273                         // 初期値を設定
274                         $canLogin = 1;          // ログインできるかどうか
275                         $reloadData = true;             // データの再読み込み
276                 }
277                 if ($reloadData){               // データの再読み込み
278                         // 設定データを取得
279                         $ret = self::$_mainDb->getUserBySerial($this->serialNo, $row);
280                         if ($ret){
281                                 $name = $row['lu_name'];
282                                 $account = $row['lu_account'];
283
284                                 $canLogin = $row['lu_enable_login'];            // ログインできるかどうか
285                                 $loginUserId = $row['lu_id'];                           // ユーザID
286                         }
287                 }
288                 
289                 // 取得データを設定
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));
293                 $canLoginCheck = '';
294                 if ($canLogin) $canLoginCheck = 'checked';
295                 $this->tmpl->addVar("_widget", "can_login", $canLoginCheck);
296                 $this->tmpl->addVar("_widget", "userid", $loginUserId);// ユーザID
297                 
298                 if (empty($this->serialNo)){            // ユーザIDが空のときは新規とする
299                         $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 新規登録ボタン表示
300                 } else {
301                         $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 更新ボタン表示
302                         $this->tmpl->addVar("_widget", "password", self::DEFAULT_PASSWORD);// 入力済みを示すパスワードの設定
303                 }
304                 
305                 // ディレクトリを設定
306                 $this->tmpl->addVar("_widget", "script_url", $this->getUrl($this->gEnv->getScriptsUrl()));
307         }
308         /**
309          * ユーザリスト、取得したデータをテンプレートに設定する
310          *
311          * @param int $index                    行番号(0~)
312          * @param array $fetchedRow             フェッチ取得した行
313          * @param object $param                 未使用
314          * @return bool                                 true=処理続行の場合、false=処理終了の場合
315          */
316         function userListLoop($index, $fetchedRow, $param)
317         {
318                 // ログイン回数
319                 $loginCount = $fetchedRow['ll_login_count'];
320                 if (empty($loginCount)) $loginCount = '0';
321                 
322                 // 画像数を取得
323                 self::$_mainDb->getPhotoCount($fetchedRow['lu_id'], $allCount, $visbleCount);
324                 
325                 $row = array(
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                                                                                         // 項目選択用ラジオボタン
336                 );
337                 $this->tmpl->addVars('authorlist', $row);
338                 $this->tmpl->parseTemplate('authorlist', 'a');
339                 
340                 // 表示中のコンテンツIDを保存
341                 $this->serialArray[] = $fetchedRow['lu_serial'];
342                 return true;
343         }
344 }
345 ?>