OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / ec_menu / include / container / admin_ec_menuMenudefWidgetContainer.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-2013 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: admin_ec_menuMenudefWidgetContainer.php 5562 2013-01-18 03:49:58Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getCurrentWidgetContainerPath() .    '/admin_ec_menuBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/ec_menuDb.php');
18
19 class admin_ec_menuMenudefWidgetContainer extends admin_ec_menuBaseWidgetContainer
20 {
21         private $db;    // DB接続オブジェクト
22         private $userId;
23         private $langId;                // 表示言語を取得
24         private $serialNo;              // 選択中の項目のシリアル番号(メニュー項目IDを使用)
25         private $serialArray = array();                 // 表示中のシリアル番号
26         private $isExistsMenuItem;              // メニュー項目が存在するかどうか
27         private $menuId;                // 現在選択中のメニューID
28         private $menuItemType;  // メニュー項目タイプ
29         private $menuDeviceType;        // メニューの端末タイプ
30         private $itemTypeArray;         // メニュー項目の種類
31         private $isMultiLang;                   // 多言語対応画面かどうか
32         private $availableLangRows;     // 利用可能な言語
33         private $availableLangArray;    // 利用可能な言語
34         private $categoryListData;              // 商品カテゴリー
35         private $categoryArray;                 // カテゴリー設定値
36         private $catagorySelectCount;   // カテゴリー選択可能数
37         private $parentId;                              // メニュー親項目
38         private $parentIdArray = array();                       // メニュー項目パス
39         private $parentNameArray = array();                     // メニュー項目名
40         const SEARCH_WIDGET = 'ec_disp';                        // 商品表示用ウィジェット
41         const DEFAULT_MENU_ID = 'ec_menu';                      // デフォルトメニューID
42         const MAX_MENU_TREE_LEVEL = 5;                  // メニュー階層最大数
43         const FILE_ICON_FILE = '/images/system/file.png';                       // ファイルアイコン
44         const FOLDER_ICON_FILE = '/images/system/folder.png';           // フォルダアイコン
45         const ICON_SIZE = 16;           // アイコンのサイズ
46         const WIDGET_TYPE_MENU = 'menu';                // メニュー型のウィジェット(キャッシュクリア用)
47         const HEAD_CONTENT_TYPE = 'ec_menu';                    // ヘッダ用コンテンツ
48 //      const CONTENT_TYPE_PC = '';                     // 汎用コンテンツのコンテンツタイプ(PC用)
49 //      const CONTENT_TYPE_MOBILE = 'mobile';                   // 汎用コンテンツのコンテンツタイプ(携帯用)
50 //      const CONTENT_TYPE_SMARTPHONE = 'smartphone';                   // 汎用コンテンツのコンテンツタイプ(スマートフォン用)
51         const LANG_ICON_PATH = '/images/system/flag/';          // 言語アイコンパス
52         const ITEM_NAME_HEAD = 'item_name_';                            // 多言語対応名前ヘッダ
53         const PARAM_CONTENT_ID = 'pcontent';    // コンテンツIDキー
54         const PARAM_CATEGORY_ID = 'category';   // カテゴリーIDキー
55         const DEFAULT_CATEGORY_COUNT = 2;       // デフォルトの商品カテゴリー選択可能数
56         const TREE_ITEM_HEAD = 'treeitem_';             // ツリー項目IDヘッダ
57         
58         /**
59          * コンストラクタ
60          */
61         function __construct()
62         {
63                 // 親クラスを呼び出す
64                 parent::__construct();
65                 
66                 // DBオブジェクト作成
67                 $this->db = new ec_menuDb();
68
69                 // メニュー項目タイプ
70                 $this->itemTypeArray = array(   array(  'name' => $this->_('Folder'),           'value' => '1'),        // フォルダ
71                                                                                 array(  'name' => $this->_('Separator'),        'value' => '3'));       // セパレータ
72
73                 $this->userId   = $this->gEnv->getCurrentUserId();
74                 $this->langId   = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
75                 
76                 // ウィジェットパラメータ取得
77                 $paramObj = $this->getWidgetParamObj();
78                 if (!empty($paramObj)){
79                         $this->catagorySelectCount              = $paramObj->categoryCount;             // 商品カテゴリー選択可能数
80                 }
81                 if ($this->catagorySelectCount <= 0) $this->catagorySelectCount = self::DEFAULT_CATEGORY_COUNT;
82                 
83                 // ##### 多言語対応用データ作成 #####
84                 $this->isMultiLang = $this->gEnv->isMultiLanguageSite();                        // 多言語対応画面かどうか
85                 $this->availableLangRows = array();
86                 $this->availableLangArray = array();
87                 $ret = $this->db->getAvailableLang($rows);                              // 利用可能な言語を取得
88                 if ($ret){
89                         for ($i = 0; $i < count($rows); $i++){
90                                 $langId = $rows[$i]['ln_id'];
91                                 $this->availableLangArray[$langId] = $rows[$i];
92                         }
93                         $this->availableLangRows = $rows;
94                 }
95         }
96         /**
97          * テンプレートファイルを設定
98          *
99          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
100          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
101          *
102          * @param RequestManager $request               HTTPリクエスト処理クラス
103          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
104          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
105          */
106         function _setTemplate($request, &$param)
107         {
108                 $task = $request->trimValueOf('task');
109                 if ($task == 'menudef_detail'){         // 詳細画面
110                         return 'admin_menudef_detail.tmpl.html';
111                 } else {                        // 一覧画面
112                         return 'admin_menudef.tmpl.html';
113                 }
114         }
115         /**
116          * ヘルプデータを設定
117          *
118          * ヘルプの設定を行う場合はヘルプIDを返す。
119          * ヘルプデータの読み込むディレクトリは「自ウィジェットディレクトリ/include/help」に固定。
120          *
121          * @param RequestManager $request               HTTPリクエスト処理クラス
122          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
123          * @return string                                               ヘルプID。ヘルプデータはファイル名「help_[ヘルプID].php」で作成。ヘルプを使用しない場合は空文字列「''」を返す。
124          */
125         function _setHelp($request, &$param)
126         {       
127                 return 'menudef';
128         }
129         /**
130          * テンプレートにデータ埋め込む
131          *
132          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
133          *
134          * @param RequestManager $request               HTTPリクエスト処理クラス
135          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
136          * @param                                                               なし
137          */
138         function _assign($request, &$param)
139         {
140                 $localeText = array();
141                 $task = $request->trimValueOf('task');
142                 
143                 if ($task == 'menudef_detail'){         // 詳細画面
144                         $this->createDetail($request);
145                         
146                         // テキストをローカライズ
147                         $localeText['msg_add'] = $this->_('Add menu item?');            // 項目を新規追加しますか?
148                         $localeText['msg_update'] = $this->_('Update menu item?');              // 項目を更新しますか?
149                         $localeText['msg_delete'] = $this->_('Delete menu item?');              // 項目を削除しますか?
150                         $localeText['label_menu_item_detail'] = $this->_('Menu Item Detail');           // メニュー項目詳細
151                         $localeText['label_go_back'] = $this->_('Go back');             // 戻る
152                         $localeText['label_name'] = $this->_('Name');           // 名前
153                         $localeText['label_lang'] = $this->_('Language');                       // 言語
154                         $localeText['label_new'] = $this->_('New');             // 新規
155                         $localeText['label_item_type'] = $this->_('Item Type');         // 項目タイプ
156                         $localeText['label_link_type'] = $this->_('Link Type');         // 表示方法
157                         $localeText['label_link_self'] = $this->_('Open page in the same window');              // 同ウィンドウで表示
158                         $localeText['label_link_other'] = $this->_('Open page in the other window');            // 別ウィンドウで表示
159                         $localeText['label_select_link'] = $this->_('Select Link Type');                // リンク先を選択
160                         $localeText['label_unselected'] = $this->_('Unselected');       // 未選択
161                         $localeText['label_link_top'] = $this->_('Top');        // トップ
162                         $localeText['label_input'] = $this->_('Input URL');     // URL任意設定
163                         $localeText['label_page_id'] = $this->_('Page ID:');    // ページID:
164                         $localeText['label_content'] = $this->_('General Contents:');   // 汎用コンテンツ:
165                         $localeText['label_url'] = $this->_('URL');     // リンク先URL
166                         $localeText['label_item_visible'] = $this->_('Item Control');   // 表示制御
167                         $localeText['label_visible'] = $this->_('Visible');     // 公開
168                         $localeText['msg_link_to_content'] = $this->_('Cotrol visible status linked to contents.');     // リンク先のコンテンツに連動
169                         $localeText['label_desc'] = $this->_('Description');    // 説明
170                         $localeText['label_delete'] = $this->_('Delete');       // 削除
171                         $localeText['label_update'] = $this->_('Update');       // 更新
172                         $localeText['label_add'] = $this->_('Add');     // 新規追加
173                 } else {                        // 一覧画面
174                         $this->createList($request);
175                         
176                         // テキストをローカライズ
177                         $localeText['msg_select_item'] = $this->_('Select menu item to edit.');         // 編集する項目を選択してください
178                         $localeText['msg_select_del_item'] = $this->_('Select menu item to delete.');           // 削除する項目を選択してください
179                         $localeText['msg_delete_item'] = $this->_('Delete selected item?');// 選択項目を削除しますか?
180                         $localeText['label_menu_item_list'] = $this->_('Menu Item List');                                       // メニュー項目一覧
181                         $localeText['label_path'] = $this->_('Path:');                                  // 階層パス
182                         $localeText['label_new'] = $this->_('New');                                     // 新規
183                         $localeText['label_edit'] = $this->_('Edit');                           // 編集
184                         $localeText['label_delete'] = $this->_('Delete');                       // 削除
185                         $localeText['label_check'] = $this->_('Select');                        // 選択
186                         $localeText['label_name'] = $this->_('Name');                   // 名前
187                         $localeText['label_lang'] = $this->_('Language');                       // 言語
188                         $localeText['label_url'] = $this->_('URL');                     // リンク先URL
189                         $localeText['label_link_type'] = $this->_('Link Type');                 // 表示方法
190                         $localeText['label_visible'] = $this->_('Visible');                     // 公開
191                         $localeText['label_operation'] = $this->_('Operation');         // 操作
192                         $localeText['label_menu_layout'] = $this->_('Menu Layout');             // メニューレイアウト
193                         $localeText['msg_change_item_order'] = $this->_('Menu items can be sorted by mouse drag and drop.');            // マウスドラッグで項目の表示順を変更できます
194                         $localeText['label_menu_top'] = $this->_('Menu Top');                                   // メニュートップ
195                         $localeText['label_open_all'] = $this->_('Open All');                                   // すべて開く
196                         $localeText['label_close_all'] = $this->_('Close All');                         // すべて閉じる
197                 }
198                 $this->setLocaleText($localeText);
199         }
200         /**
201          * 一覧画面作成
202          *
203          * @param RequestManager $request               HTTPリクエスト処理クラス
204          * @param                                                               なし
205          */
206         function createList($request)
207         {
208                 $fixedMode = $request->trimValueOf('fixed_mode');               // メニュー定義IDが固定かどうか
209                 if ($fixedMode == ''){          // 値が設定されていないときは設定
210                         if ($request->trimValueOf('menuid') == ''){
211                                 $fixedMode = '0';
212                         } else {
213                                 $fixedMode = '1';               // 固定
214                         }
215                 }
216 //              $this->menuId = $request->trimValueOf('menuid');                // 現在選択中のメニュータイプ
217 //              if ($this->menuId == '') $this->menuId = self::DEFAULT_MENU_ID;         // デフォルト商品メニューID
218                 $this->menuId = self::DEFAULT_MENU_ID;          // デフォルト商品メニューID
219                 
220                 // メニューの端末タイプを取得
221                 $this->menuDeviceType = 0;      // メニューの端末タイプ
222                 $ret = $this->db->getMenuId($this->menuId, $row);
223                 if ($ret) $this->menuDeviceType = $row['mn_device_type'];
224                 
225                 $act = $request->trimValueOf('act');
226                 $this->parentId = $request->trimValueOf('parentid');            // 親メニューID取得
227                 if ($this->parentId == '') $this->parentId = '0';
228                 
229                 if ($act == 'delete'){          // メニュー項目の削除
230                         $listedItem = explode(',', $request->trimValueOf('seriallist'));
231                         $delItems = array();
232                         for ($i = 0; $i < count($listedItem); $i++){
233                                 // 項目がチェックされているかを取得
234                                 $itemName = 'item' . $i . '_selected';
235                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
236                                 
237                                 if ($itemValue){                // チェック項目
238                                         $delItems[] = $listedItem[$i];
239                                         
240                                         // 子カテゴリーのある項目は削除不可
241                                         $ret = $this->db->getChildMenuItems($this->menuId, $listedItem[$i], $rows);
242                                         if ($ret){
243                                                 $this->setAppErrorMsg($this->_('You are not allowed to delete menu item with child item.'));            // 子項目を持つメニュー項目は削除できません。
244                                                 break;
245                                         }
246                                 }
247                         }
248
249                         // エラーなしの場合は、データを削除
250                         if ($this->getMsgCount() == 0){
251                                 if (count($delItems) > 0){
252                                         $ret = $this->delMenuItems($delItems);
253                                         if ($ret){              // データ削除成功のとき
254                                                 $this->setGuidanceMsg($this->_('Menu item deleted.'));          // データを削除しました
255                                         } else {
256                                                 $this->setAppErrorMsg($this->_('Failed in deleting menu item.'));               // データ削除に失敗しました
257                                         }
258                                 }
259                                 $this->gCache->clearCacheByWidgetType(self::WIDGET_TYPE_MENU);          // キャッシュをクリア
260                                 $this->gPage->updateParentWindow();// 親ウィンドウを更新
261                         }
262                 } else if ($act == 'selecttree'){               // メニューツリーから選択
263                         $this->parentId = str_replace(self::TREE_ITEM_HEAD, '', $request->trimValueOf('treedest'));
264                 } else if ($act == 'updatetree'){               // メニューツリーからの更新
265                         $treeId = str_replace(self::TREE_ITEM_HEAD, '', $request->trimValueOf('treesrc'));
266                         $treeParentId = str_replace(self::TREE_ITEM_HEAD, '', $request->trimValueOf('treedest'));
267                         $treePos = $request->trimValueOf('treepos');
268                         $this->db->reorderMenuItem($this->menuId, $treeParentId, $treeId, $treePos);
269                         
270                         $this->gCache->clearCacheByWidgetType(self::WIDGET_TYPE_MENU);          // キャッシュをクリア
271                         $this->gPage->updateParentWindow();// 親ウィンドウを更新
272                 }
273                 
274                 // メニュー階層パスを取得
275                 if (!empty($this->parentId)){
276                         // 現在のメニュー項目からパスを作成
277                         $this->parentIdArray = $this->getPath($this->menuId, $this->parentId);
278                         
279                         // メニュー項目を選択
280                         $this->tmpl->setAttribute('select_tree_area', 'visibility', 'visible');
281                         $this->tmpl->addVar("select_tree_area", "select_id", self::TREE_ITEM_HEAD . $this->parentId);           // 選択中のメニュー項目
282                 }
283                 
284                 // 一覧の表示タイプを設定
285                 if ($this->isMultiLang){                // 多言語対応の場合
286                         $this->tmpl->setAttribute('show_multilang', 'visibility', 'visible');
287                 } else {
288                         $this->tmpl->setAttribute('show_singlelang', 'visibility', 'visible');
289                 }
290                 
291                 // メニューID選択メニュー作成
292                 $this->db->getMenuIdList($this->gEnv->getCurrentWidgetId(), array($this, 'menuIdListLoop'));
293                 
294                 // メニューツリー作成
295                 $treeMenu = $this->createTreeMenu($this->menuId, 0);
296                 
297                 // メニュー項目が存在しないときはメニューのプレビューを表示しない
298                 if (!$this->isExistsMenuItem) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');            // メニュー項目一覧
299                 if ($fixedMode == '1') $this->tmpl->addVar("_widget", "sel_menu_id_disabled", 'disabled');                      // メニューIDの選択可否
300                 
301                 // メニュー階層パスを作成
302                 if (empty($this->parentIdArray)){
303                         $path = '[ルート]';
304                 } else {
305                         $path = '<a href="#" onclick="selectTree(0);">[ルート]</a>';
306                 }
307                 for ($i = 0; $i < count($this->parentIdArray); $i++){
308                         $path .= '&nbsp;/&nbsp;';
309                         $path .= '<a href="#" onclick="selectTree(' . $this->parentIdArray[$i] . ');">' . $this->convertToDispString($this->parentNameArray[$i]) . '</a>';
310                 }
311                 
312                 $this->tmpl->addVar("_widget", "tree", $treeMenu);              // メニューツリー
313                 $this->tmpl->addVar("_widget", "parent_id", $this->parentId);           // メニュー項目親ID
314                 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
315                 $this->tmpl->addVar('_widget', 'admin_url', $this->getUrl($this->gEnv->getDefaultAdminUrl()));// 管理者URL
316                 $this->tmpl->addVar("_widget", "fixed_mode", $fixedMode);               // メニュー定義IDが固定かどうか
317                 $this->tmpl->addVar("_widget", "path", $path);          // メニュー階層パス
318                 
319                 // ディレクトリを設定
320                 $this->tmpl->addVar("_widget", "script_url", $this->getUrl($this->gEnv->getScriptsUrl()));
321         }
322         /**
323          * 詳細画面作成
324          *
325          * @param RequestManager $request               HTTPリクエスト処理クラス
326          * @param                                                               なし
327          */
328         function createDetail($request)
329         {
330                 $fixedMode = $request->trimValueOf('fixed_mode');               // メニュー定義IDが固定かどうか
331                 $act = $request->trimValueOf('act');
332                 $this->serialNo = $request->trimValueOf('serial');              // 選択項目のシリアル番号
333                 $value = $request->trimValueOf('item_sel_menuid');
334                 if ($value != '') $this->serialNo = $value;                     // メニュー項目が選択されている場合はシリアル番号を更新
335                 $this->menuId = $request->trimValueOf('menuid');                // 現在選択中のメニューID
336                 $parentId = $request->trimValueOf('parentid');          // 親メニューID取得
337                 if ($parentId == '') $parentId = '0';
338                 
339                 $name = $request->trimValueOf('item_name');
340                 $title = $request->valueOf('item_title');               // タイトル(HTML可)
341                 $this->menuItemType = $request->trimValueOf('item_type');
342                 if ($this->menuItemType == '') $this->menuItemType = '0';               // デフォルトの項目タイプは通常リンク
343                 $linkType = $request->trimValueOf('item_link_type');
344                 $visible = ($request->trimValueOf('item_visible') == 'on') ? 1 : 0;             // チェックボックス
345 //              $url = $request->trimValueOf('item_url');               // 決定したURL
346 //              $url = str_replace($this->gEnv->getRootUrl(), M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $url);// マクロ変換
347                 $html = $request->valueOf('item_html');         // ヘッダコンテンツ
348                 
349                 // カテゴリーを取得
350                 $this->categoryArray = array();
351                 for ($i = 0; $i < $this->catagorySelectCount; $i++){
352                         $itemName = 'item_category' . $i;
353                         $itemValue = $request->trimValueOf($itemName);
354                         if (!empty($itemValue)){                // 0以外の値を取得
355                                 $this->categoryArray[] = $itemValue;
356                         }
357                 }
358                 
359                 // 多言語入力を取得
360                 if ($this->isMultiLang){                // 多言語対応の場合
361                         $nameLangArray = array();               // 多言語対応文字列
362                         for ($i = 0; $i < count($this->availableLangRows); $i++){
363                                 $inputLangId = $this->availableLangRows[$i]['ln_id'];
364
365                                 $itemName = self::ITEM_NAME_HEAD . $inputLangId;
366                                 $itemValue = $request->trimValueOf($itemName);
367                                 if (!empty($itemValue)) $nameLangArray[$inputLangId] = $itemValue;
368                         }
369                         // デフォルト言語を追加
370                         if (!empty($name)) $nameLangArray[$this->gEnv->getDefaultLanguage()] = $name;
371                 }
372                 
373                 $this->menuDeviceType = 0;      // メニューの端末タイプ
374                 $ret = $this->db->getMenuId($this->menuId, $row);
375                 if ($ret) $this->menuDeviceType = $row['mn_device_type'];
376                 
377                 $reloadData = false;            // データの再読み込み
378                 if ($act == 'add'){// 新規追加
379                         // 入力チェック
380                         $this->checkInput($name, $this->_('Name'));             // 名前
381                         $this->checkInput($this->menuId, $this->_('Menu ID'));          // メニューID
382
383                         // エラーなしの場合は、データを登録
384                         if ($this->getMsgCount() == 0){
385                                 // ##### 格納用の名前を作成 #####
386                                 if ($this->isMultiLang){                // 多言語対応の場合
387                                         $nameLangStr = $this->serializeLangArray($nameLangArray);
388                                 } else {
389                                         $nameLangStr = $name;
390                                 }
391                                 
392                                 // トランザクションスタート
393                                 $this->db->startTransaction();
394                                 
395                                 $ret = $this->db->updateContentItem(self::HEAD_CONTENT_TYPE, 0/*新規*/, $this->langId, $name, $html, 1/*表示*/, $newContentId, $newSerial);
396                                 if ($ret){
397                                         // パラメータ作成
398                                         $param = self::PARAM_CATEGORY_ID . '=' . implode(',', $this->categoryArray) . '&' . self::PARAM_CONTENT_ID . '=' . $newContentId;
399                         
400                                         $ret = $this->db->addMenuItem($this->menuId, $parentId, $nameLangStr, $title, ''/*説明*/, 0/*項目順は自動設定*/, $this->menuItemType, $linkType, $param, $visible, $newId);
401                                 }
402                                 
403                                 // トランザクション終了
404                                 $ret = $this->db->endTransaction();
405                                 if ($ret){
406                                         $this->setGuidanceMsg($this->_('Menu item added.'));    // データを追加しました
407                                         $this->serialNo = $newId;               // メニュー項目IDを更新
408                                         $reloadData = true;             // データの再読み込み
409                                 } else {
410                                         $this->setAppErrorMsg($this->_('Failed in adding menu item.')); // データ追加に失敗しました
411                                 }
412                                 $this->gCache->clearCacheByWidgetType(self::WIDGET_TYPE_MENU);          // キャッシュをクリア
413                                 $this->gPage->updateParentWindow();// 親ウィンドウを更新
414                         }
415                 } else if ($act == 'update'){           // 項目更新の場合
416                         // 入力チェック
417                         $this->checkInput($name, $this->_('Name'));             // 名前
418
419                         // エラーなしの場合は、データを更新
420                         if ($this->getMsgCount() == 0){
421                                 // ##### 格納用の名前を作成 #####
422                                 if ($this->isMultiLang){                // 多言語対応の場合
423                                         $nameLangStr = $this->serializeLangArray($nameLangArray);
424                                 } else {
425                                         $nameLangStr = $name;
426                                 }
427                                 
428                                 // トランザクションスタート
429                                 $this->db->startTransaction();
430                                 
431                                 $ret = $this->db->getMenuItem($this->serialNo, $row);
432                                 if ($ret){
433                                         // ヘッダコンテンツIDを取得
434                                         $param = $row['md_param'];
435                                         $parsedParam = parseUrlParam($param);
436                                         $contentId = $parsedParam[self::PARAM_CONTENT_ID];
437                                         if ($contentId == '') $contentId = 0;           // コンテンツID初期化
438                                         
439                                         $ret = $this->db->updateContentItem(self::HEAD_CONTENT_TYPE, $contentId, $this->langId, $name, $html, 1/*表示*/, $newContentId, $newSerial);
440                                 }
441                                                                                 
442                                 // コンテンツを更新
443                                 if ($ret){
444                                         // パラメータ作成
445                                         $param = self::PARAM_CATEGORY_ID . '=' . implode(',', $this->categoryArray) . '&' . self::PARAM_CONTENT_ID . '=' . $newContentId;
446                                         
447                                         // メニューを更新
448                                         $ret = $this->db->updateMenuItem($this->serialNo, $nameLangStr, $title, ''/*説明*/, $this->menuItemType, $linkType, $param, $visible);
449                                 }
450                                 
451                                 // トランザクション終了
452                                 $ret = $this->db->endTransaction();
453                                 if ($ret){
454                                         $this->setGuidanceMsg($this->_('Menu item updated.'));          // データを更新しました
455                                         
456                                         $reloadData = true;             // データの再読み込み
457                                 } else {
458                                         $this->setAppErrorMsg($this->_('Failed in updating menu item.'));               // データ更新に失敗しました
459                                 }
460                                 $this->gCache->clearCacheByWidgetType(self::WIDGET_TYPE_MENU);          // キャッシュをクリア
461                                 $this->gPage->updateParentWindow();// 親ウィンドウを更新
462                         }
463                 } else if ($act == 'delete'){           // 項目削除の場合
464                         //$ret = $this->db->delMenuItems($this->serialNo);
465                         $ret = $this->delMenuItems(array($this->serialNo));
466                         if ($ret){              // データ削除成功のとき
467                                 $this->setGuidanceMsg($this->_('Menu item deleted.'));          // データを削除しました
468                         } else {
469                                 $this->setAppErrorMsg($this->_('Failed in deleting menu item.'));               // データ削除に失敗しました
470                         }
471                         $this->gCache->clearCacheByWidgetType(self::WIDGET_TYPE_MENU);          // キャッシュをクリア
472                         $this->gPage->updateParentWindow();// 親ウィンドウを更新
473                 } else if ($act == 'select'){   // ページサブIDを変更
474                 } else {
475                         $reloadData = true;             // データの再読み込み
476                 }
477                 
478                 if ($reloadData){               // データの再読み込み
479                         if (empty($this->serialNo)){            // 新規項目追加のとき
480                                 $name = '';             // 名前
481                                 $linkType = 0;  // リンクタイプ
482                                 $visible = 1;
483                         } else {
484                                 $ret = $this->db->getMenuItem($this->serialNo, $row);
485                                 if ($ret){
486                                         // 取得値を設定
487                                         $this->serialNo = $row['md_id'];                        // ID
488                                         $name = $this->getDefaultLangString($row['md_name']);           // 名前
489                                         $title = $row['md_title'];              // タイトル(HTML可)
490                                         $this->menuItemType = $row['md_type'];          // 項目タイプ
491                                         $linkType = $row['md_link_type'];       // リンクタイプ
492                                         $visible = $row['md_visible'];
493                                         $param = $row['md_param'];
494                                         
495                                         // カテゴリーIDとヘッダコンテンツIDを取得
496                                         $parsedParam = parseUrlParam($param);
497                                         $contentId = $parsedParam[self::PARAM_CONTENT_ID];
498                                         if (empty($parsedParam[self::PARAM_CATEGORY_ID])){
499                                                 $this->categoryArray = array();
500                                         } else {
501                                                 $this->categoryArray = explode(',', $parsedParam[self::PARAM_CATEGORY_ID]);
502                                         }
503                         
504                                         // コンテンツを取得
505                                         $ret = $this->db->getContentByContentId(self::HEAD_CONTENT_TYPE, $contentId, $this->langId, $row);
506                                         if ($ret){
507                                                 $html = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->getUrl($this->gEnv->getRootUrl()), $row['cn_html']);// アプリケーションルートを変換
508                                         }
509                                         
510                                         // ##### 多言語対応用データ作成 #####
511                                         if ($this->isMultiLang){                // 多言語対応の場合
512                                                 $nameLangArray = $this->unserializeLangArray($row['md_name']);
513                                         }
514                                 }
515                         }
516                 }
517                 // リンク先を実URLに変換
518                 if (count($this->categoryArray) > 0){
519                         $url = $this->gPage->getDefaultPageUrlByWidget(self::SEARCH_WIDGET, $param);
520                 } else {
521                         $url = '';
522                 }
523                 
524                 // メニュー項目タイプメニュー
525                 $this->createItemTypeMenu();
526                 
527                 // メニューID選択メニュー作成
528                 $this->db->getAllMenuItems($this->menuId, array($this, 'menuIdLoop'));
529                 
530                 // カテゴリーメニューを作成
531                 $this->db->getAllCategory($this->langId, $this->categoryListData);
532                 $this->createCategoryMenu();
533                 
534                 // 多言語用入力エリア作成
535                 if ($this->isMultiLang){                // 多言語対応の場合
536                         // デフォルト言語設定
537                         $this->tmpl->addVar("_widget", "lang", $this->createLangImage($this->gEnv->getDefaultLanguage()));
538                         
539                         // その他の入力欄作成
540                         $this->tmpl->setAttribute('input_lang', 'visibility', 'visible');
541                         $this->createInputLangText($nameLangArray);
542                 }
543                 
544                 // ### 入力値を再設定 ###
545                 $this->tmpl->addVar("_widget", "name", $this->convertToDispString($name));              // 名前
546                 $this->tmpl->addVar("_widget", "title", $this->convertToDispString($title));            // タイトル(HTML可)
547                 $this->tmpl->addVar("_widget", "url", $url);            // リンク先URL
548                 $this->tmpl->addVar("_widget", "disp_url", $this->convertToDispString($url));           // リンク先URL
549                 $this->tmpl->addVar("_widget", "html", $html);          // ヘッダコンテンツ
550                 
551                 // リンクタイプ
552                 switch ($linkType){
553                         case 0:                 // 同ウィンドウで開くリンク
554                                 $this->tmpl->addVar("_widget", "link_type_0", 'selected');
555                                 break;
556                         case 1:                 // 別ウィンドウで開くリンク
557                                 $this->tmpl->addVar("_widget", "link_type_1", 'selected');
558                                 break;
559                 }
560                 // 項目表示、項目利用可否チェックボックス
561                 $visibleStr = '';
562                 if ($visible) $visibleStr = 'checked';
563                 $this->tmpl->addVar("_widget", "sel_item_visible", $visibleStr);
564                 
565                 // 選択中のシリアル番号、IDを設定
566                 $this->tmpl->addVar("_widget", "serial", $this->serialNo);
567                 $this->tmpl->addVar("_widget", "menu_id", $this->menuId);               // メニューID
568                 $this->tmpl->addVar("_widget", "parent_id", $parentId);         // メニュー項目親ID
569                 $this->tmpl->addVar("_widget", "fixed_mode", $fixedMode);               // メニュー定義IDが固定かどうか
570                 
571                 // ボタンの表示制御
572                 if (empty($this->serialNo)){            // 新規追加項目を選択しているとき
573                         $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
574                 } else {
575                         $this->tmpl->setAttribute('del_button', 'visibility', 'visible');// 「削除」ボタン
576                         
577                         // 子項目を持つときは削除不可
578                         $ret = $this->db->getChildMenuItems($this->menuId, $this->serialNo, $rows);
579                         if ($ret) $this->tmpl->addVar('del_button', 'del_button_disabled', 'disabled');
580                 }
581         }
582         /**
583          * 取得したデータをテンプレートに設定する
584          *
585          * @param int $index                    行番号(0~)
586          * @param array $fetchedRow             フェッチ取得した行
587          * @param object $param                 未使用
588          * @return bool                                 true=処理続行の場合、false=処理終了の場合
589          */
590         function menuIdListLoop($index, $fetchedRow, $param)
591         {
592                 $value = $fetchedRow['mn_id'];
593                 $name = $value . ' - ' . $fetchedRow['mn_name'];
594                         
595                 $selected = '';
596                 if ($value == $this->menuId) $selected = 'selected';
597                 
598                 $row = array(
599                         'value'    => $this->convertToDispString($value),                       // ページID
600                         'name'     => $this->convertToDispString($name),                        // ページ名
601                         'selected' => $selected                                                                                                         // 選択中かどうか
602                 );
603                 $this->tmpl->addVars('menu_id_list', $row);
604                 $this->tmpl->parseTemplate('menu_id_list', 'a');
605                 return true;
606         }
607         /**
608          * メニュー項目タイプ選択メニュー作成
609          *
610          * @return なし
611          */
612         function createItemTypeMenu()
613         {
614                 for ($i = 0; $i < count($this->itemTypeArray); $i++){
615                         $value = $this->itemTypeArray[$i]['value'];
616                         $name = $this->itemTypeArray[$i]['name'];
617                         
618                         $selected = '';
619                         if ($value == $this->menuItemType) $selected = 'selected';
620                         
621                         $row = array(
622                                 'value'    => $value,                   // ページID
623                                 'name'     => $name,                    // ページ名
624                                 'selected' => $selected                                                                                                         // 選択中かどうか
625                         );
626                         $this->tmpl->addVars('item_type_list', $row);
627                         $this->tmpl->parseTemplate('item_type_list', 'a');
628                 }
629         }
630         /**
631          * メニューIDをテンプレートに設定する
632          *
633          * @param int $index                    行番号(0~)
634          * @param array $fetchedRow             フェッチ取得した行
635          * @param object $param                 未使用
636          * @return bool                                 true=処理続行の場合、false=処理終了の場合
637          */
638         function menuIdLoop($index, $fetchedRow, $param)
639         {
640                 $value = $this->convertToDispString($fetchedRow['md_id']);
641                 $name = $this->getDefaultLangString($fetchedRow['md_name']);
642                 
643                 $selected = '';
644                 if ($value == $this->serialNo) $selected = 'selected';
645                         
646                 $row = array(
647                         'value'    => $value,                   // メニュー項目ID
648                         'name'     => $this->convertToDispString($name),                        // メニュー項目名
649                         'selected' => $selected                                                                                                         // 選択中かどうか
650                 );
651                 $this->tmpl->addVars('menuid_list', $row);
652                 $this->tmpl->parseTemplate('menuid_list', 'a');
653                 return true;
654         }
655         /**
656          * メニューツリー作成
657          *
658          * @param string        $menuId         メニューID
659          * @param int           $parantId       親メニュー項目ID
660          * @param int           $level          階層数
661          * @return string               ツリーメニュータグ
662          */
663         function createTreeMenu($menuId, $parantId, $level = 0)
664         {
665                 static $index = 0;              // インデックス番号
666                 
667                 // メニューの階層を制限
668                 if ($level >= self::MAX_MENU_TREE_LEVEL) return '';
669                 
670                 $treeHtml = '';
671                 if ($this->db->getChildMenuItems($menuId, $parantId, $rows)){
672                         $itemCount = count($rows);
673                         for ($i = 0; $i < $itemCount; $i++){
674                                 $row = $rows[$i];
675                                 $id = $row['md_id'];
676                                 $name = $this->getDefaultLangString($row['md_name']);// デフォルト言語で名前を取得
677                         
678                                 // 対応言語を取得
679                                 $lang = '';
680                                 if ($this->isMultiLang){                // 多言語対応の場合
681                                         $lang = $this->createLangImageList($row['md_name']);
682                                 }
683                         
684                                 // ##### ツリーメニュー作成 #####
685                                 if ($row['md_type'] == 0){      // リンク項目のとき
686                                         $treeHtml .= '<li id="' . self::TREE_ITEM_HEAD . $id . '"><a href="#">' . $this->convertToDispString($name) . '</a></li>' . M3_NL;
687                                 } else if ($row['md_type'] == 1){                       // フォルダのとき
688                                         // サブメニュー作成
689                                         if (in_array($id, $this->parentIdArray)){               // メニュー階層パス上にある場合はフォルダを開く
690                                                 $itemClass = 'jstree-open';
691                                                 
692                                                 $this->parentNameArray[] = $name;
693                                         } else {
694                                                 $itemClass = 'jstree-closed';
695                                         }
696                                         $treeHtml .= '<li id="' . self::TREE_ITEM_HEAD . $id . '" rel="folder" class="' . $itemClass . '"><a href="#">' . $this->convertToDispString($name) . '</a>' . M3_NL;
697                                         $treeHtml .= '<ul>' . M3_NL;
698                                         $treeHtml .= $this->createTreeMenu($menuId, $id, $level + 1);
699                                         $treeHtml .= '</ul>' . M3_NL;
700                                         $treeHtml .= '</li>' . M3_NL;
701                                 } else if ($row['md_type'] == 2){                       // テキストのとき
702                                         $treeHtml .= '<li id="' . self::TREE_ITEM_HEAD . $id . '"><a href="#">' . $this->convertToDispString($name) . '</a></li>' . M3_NL;
703                                 } else if ($row['md_type'] == 3){                       // セパレータのとき
704                                         $treeHtml .= '<li id="' . self::TREE_ITEM_HEAD . $id . '"><a href="#">' . '-----' . '</a></li>' . M3_NL;
705                                 }
706                                 
707                                 // 選択中のメニュー項目の内容のみ表示
708                                 if ($parantId != $this->parentId) continue;
709                                 
710                                 // メニュー項目タイプアイコン
711                                 $iconUrl = '';
712                                 switch ($row['md_type']){
713                                         case 0:         // リンク
714                                                 $iconTitle = $this->_('Link');          // リンク
715                                                 $iconUrl = $this->gEnv->getRootUrl() . self::FILE_ICON_FILE;
716                                                 break;
717                                         case 1:         // フォルダ
718                                                 $iconTitle = $this->_('Folder');                // フォルダ
719                                                 $iconUrl = $this->gEnv->getRootUrl() . self::FOLDER_ICON_FILE;
720                                                 break;
721                                         case 2: // テキスト
722                                                 $iconTitle = $this->_('Text');          // テキスト
723                                                 $iconUrl = $this->gEnv->getRootUrl() . self::FILE_ICON_FILE;
724                                                 break;
725                                         case 3: // セパレータ
726                                                 $iconTitle = $this->_('Separator');             // セパレータ
727                                                 $iconUrl = $this->gEnv->getRootUrl() . self::FILE_ICON_FILE;
728                                                 break;
729                                         default:
730                                                 break;
731                                 }
732                                 $iconTag = '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::ICON_SIZE . '" height="' . self::ICON_SIZE . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
733                 
734                                 $visible = '';
735                                 if ($row['md_visible']){
736                                         $visible = 'checked';
737                                 }
738                                 // リンクタイプ
739                                 $linkString = '';
740                                 switch ($row['md_link_type']){
741                                         case 0:                 // 同ウィンドウで開くリンク
742                                                 $linkString = $this->_('Self');         // 同
743                                                 break;
744                                         case 1:                 // 別ウィンドウで開くリンク
745                                                 $linkString = $this->_('Other');        // 別
746                                                 break;
747                                 }
748                                 // 更新用シリアル番号
749                                 $serial = $id;
750                 
751                                 // リンクURLを作成
752                                 $parsedParam = parseUrlParam($row['md_param']);
753                                 if (empty($parsedParam[self::PARAM_CATEGORY_ID])){
754                                         $linkUrlStr = '';
755                                 } else {
756                                         $url = $this->gPage->getDefaultPageUrlByWidget(self::SEARCH_WIDGET, $row['md_param']);
757                                         $linkUrlStr = str_replace($this->gEnv->getRootUrl(), '...', $url);              // 表示テキスト
758                                         $linkUrlStr = '<a href="#" onclick="previewInOtherWindow(\'' . $this->getUrl($url, true) . '\');">' . $this->convertToDispString($linkUrlStr) . '</a>';
759                                 }
760                                 
761                                 $itemRow = array(
762                                         'index' => $index,                                                                                                      // 行番号
763                                         'serial' => $this->convertToDispString($serial),                        // シリアル番号
764                                         'id' => $this->convertToDispString($id),                        // ID
765                                         'name' => $this->convertToDispString($name),            // 名前
766                                         'lang'          => $lang,                       // 言語
767                                         'item_type' => $iconTag,                                                                                        // メニュー項目タイプアイコン
768                                         'link_type' => $linkString,                                                                                     // リンクタイプ
769                                         'link_str' => $linkUrlStr,                                                                                      // リンクURL
770                                         'visible' => $visible,                                                                                  // メニュー項目表示制御
771                                         'label_edit_content' => $this->_('Edit Content')                                // コンテンツを編集
772                                 );
773
774                                 if ($this->isMultiLang){                // 多言語対応のとき
775                                         $this->tmpl->addVars('itemlist2', $itemRow);
776                                         $this->tmpl->parseTemplate('itemlist2', 'a');
777                                 } else {
778                                         $this->tmpl->addVars('itemlist', $itemRow);
779                                         $this->tmpl->parseTemplate('itemlist', 'a');
780                                 }
781                         
782                                 $index++;               // インデックス番号更新
783                                 $this->isExistsMenuItem = true;         // メニュー項目が存在するかどうか
784                 
785                                 // シリアル番号を保存
786                                 $this->serialArray[] = $serial;
787                         }
788                 }
789                 return $treeHtml;
790         }
791         /**
792          * メニュー階層パス取得
793          *
794          * @param string $menuId                メニューID
795          * @param int    $parantId              親メニュー項目ID
796          * @param int    $level                 階層数
797          * @return array                                メニュー項目IDの配列
798          */
799         function getPath($menuId, $parantId, $level = 0)
800         {
801                 static $pathArray = array();
802                 
803                 // メニューの階層を制限
804                 if ($level >= self::MAX_MENU_TREE_LEVEL) return $pathArray;
805                 
806                 if (empty($parantId)) return $pathArray;                // メニューIDが0のときは終了
807                 
808                 // メニューパス追加
809                 $pathArray[] = $parantId;
810                 
811                 // メニュー項目情報を取得
812                 $ret = $this->db->getMenuItem($parantId, $row);
813                 if ($ret){
814                         // 親メニュー項目のパスを取得
815                         $this->getPath($menuId, $row['md_parent_id'], $level + 1);
816                         
817                         if ($level == 0) $pathArray = array_reverse($pathArray);                // パスを反転
818                         return $pathArray;
819                 } else {
820                         return $pathArray;
821                 }
822         }
823         /**
824          * メニュー項目削除
825          *
826          * @param array $idArray        削除するメニュー項目ID
827          * @param bool                          true=成功、false=失敗
828          */
829         function delMenuItems($idArray)
830         {
831                 // トランザクションスタート
832                 $this->db->startTransaction();
833                 
834                 for ($i = 0; $i < count($idArray); $i++){
835                         $ret = $this->db->getMenuItem($idArray[$i], $row);
836                         if ($ret){
837                                 // ヘッダコンテンツIDを取得
838                                 $param = $row['md_param'];
839                                 $parsedParam = parseUrlParam($param);
840                                 $contentId = $parsedParam[self::PARAM_CONTENT_ID];
841                                 if ($contentId == '') $contentId = 0;           // コンテンツID初期化
842                         }
843                         if ($ret) $ret = $this->db->delMenuItem($idArray[$i]);
844                         if ($ret){
845                                 if (!empty($contentId)) $ret = $this->db->delContentItem(self::HEAD_CONTENT_TYPE, $contentId, $this->langId);           // コンテンツを削除
846                         }
847                         if (!$ret){                     // エラーの場合は終了
848                                 $this->db->endTransaction();
849                                 return false;
850                         }
851                 }
852                 // トランザクション終了
853                 $ret = $this->db->endTransaction();
854                 return $ret;
855         }
856         /**
857          * 商品カテゴリーメニューを作成
858          *
859          * @return なし                                               
860          */
861         function createCategoryMenu()
862         {
863                 for ($j = 0; $j < $this->catagorySelectCount; $j++){
864                         // selectメニューの作成
865                         $this->tmpl->clearTemplate('category_list');
866                         for ($i = 0; $i < count($this->categoryListData); $i++){
867                                 $categoryId = $this->categoryListData[$i]['pc_id'];
868                                 $selected = '';
869                                 if ($j < count($this->categoryArray) && $this->categoryArray[$j] == $categoryId){
870                                         $selected = 'selected';
871                                 }
872                                 $menurow = array(
873                                         'value'         => $categoryId,                 // カテゴリーID
874                                         'name'          => $this->categoryListData[$i]['pc_name'],                      // カテゴリー名
875                                         'selected'      => $selected                                                                                                            // 選択中かどうか
876                                 );
877                                 $this->tmpl->addVars('category_list', $menurow);
878                                 $this->tmpl->parseTemplate('category_list', 'a');
879                         }
880                         $itemRow = array(               
881                                         'index'         => $j                   // 項目番号                                                                                 
882                         );
883                         $this->tmpl->addVars('category', $itemRow);
884                         $this->tmpl->parseTemplate('category', 'a');
885                 }
886         }
887         /**
888          * 言語アイコンを作成
889          *
890          * @param string $src           多言語対応文字列
891          * @return string                       言語アイコンタグ
892          */
893         function createLangImageList($src)
894         {
895                 $imageTag = '';
896                 $langArray = $this->unserializeLangArray($src);
897                 $keys = array_keys($langArray);
898                 
899                 for ($i = 0; $i < count($this->availableLangRows); $i++){
900                         $langId = $this->availableLangRows[$i]['ln_id'];
901                         if (in_array($langId, $keys)) $imageTag .= $this->createLangImage($langId);
902                 }
903                 return $imageTag;
904         }
905         /**
906          * 言語アイコンを作成
907          *
908          * @param string $id            言語ID
909          * @return string                       言語アイコンタグ
910          */
911         function createLangImage($id)
912         {
913                 $langInfo = $this->availableLangArray[$id];
914                 if (!isset($langInfo)) return '';
915                 
916                 if ($this->gEnv->getCurrentLanguage() == 'ja'){ // 日本語の場合
917                         $langName = $langInfo['ln_name'];
918                 } else {
919                         $langName = $langInfo['ln_name_en'];
920                 }
921                 // 言語アイコン
922                 $iconTitle = $langName;
923                 $iconUrl = $this->gEnv->getRootUrl() . self::LANG_ICON_PATH . $langInfo['ln_image_filename'];           // 画像ファイル
924                 $iconTag = '<img src="' . $this->getUrl($iconUrl) . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
925                 $imageTag .= $iconTag;
926                 return $imageTag;
927         }
928         /**
929          * 多言語文字列入力エリア作成
930          *
931          * @param array $nameArray      多言語対応文字列
932          * @return なし
933          */
934         function createInputLangText($nameArray)
935         {
936                 for ($i = 0; $i < count($this->availableLangRows); $i++){
937                         $langId = $this->availableLangRows[$i]['ln_id'];
938                         if ($langId == $this->gEnv->getDefaultLanguage()) continue;             // デフォルト言語は除く
939                         $langImage = $this->createLangImage($langId);
940                         
941                         $value = $nameArray[$langId];
942                         $row = array(
943                                 'id'    => $langId,                     // 言語ID
944                                 'value' => $this->convertToDispString($value),                  // 入力値
945                                 'lang'  => $langImage           // 言語画像
946                         );
947                         $this->tmpl->addVars('input_lang', $row);
948                         $this->tmpl->parseTemplate('input_lang', 'a');
949                 }
950         }
951 }
952 ?>