OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / ec_category_menu / include / container / admin_ec_category_menuWidgetContainer.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-2009 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: admin_ec_category_menuWidgetContainer.php 2255 2009-08-26 14:53:39Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/ec_category_menuInfo.php');
18 require_once($gEnvManager->getCurrentWidgetDbPath() . '/ec_category_menuDb.php');
19
20 class admin_ec_category_menuWidgetContainer extends BaseAdminWidgetContainer
21 {
22         var $db;        // DB接続オブジェクト
23         const DEFAULT_IMG_FILENAME = 'menu1.png';               // デフォルトファイル名
24         const DEFAULT_LEVEL_COUNT = 3;          // デフォルト表示階層
25         const THIS_WIDGET_ID = 'ec_category_menu';              // ウィジェットID
26         const IMAGE_DIR = 'images';                             // 画像ディレクトリ名
27         const DEFAULT_MENU_TITLE = '商品カテゴリー';     // デフォルトメニュータイトル
28                         
29         /**
30          * コンストラクタ
31          */
32         function __construct()
33         {
34                 // 親クラスを呼び出す
35                 parent::__construct();
36                 
37                 // DBオブジェクト作成
38                 $this->db = new ec_category_menuDb();
39         }
40         /**
41          * テンプレートファイルを設定
42          *
43          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
44          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
45          *
46          * @param RequestManager $request               HTTPリクエスト処理クラス
47          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
48          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
49          */
50         function _setTemplate($request, &$param)
51         {       
52                 return 'admin_menu.tmpl.html';
53         }
54         /**
55          * テンプレートにデータ埋め込む
56          *
57          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
58          *
59          * @param RequestManager $request               HTTPリクエスト処理クラス
60          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
61          * @param                                                               なし
62          */
63         function _assign($request, &$param)
64         {
65                 global $gEnvManager;
66                 global $gInstanceManager;
67
68                 $userInfo               = $gEnvManager->getCurrentUserInfo();
69                 $filename = $request->trimValueOf('item_image');                // 画像ファイル名
70                 if (empty($filename)) $filename = self::DEFAULT_IMG_FILENAME;           // デフォルトファイル名       
71                 $levelCount = $request->trimValueOf('item_level_count');                // メニュー表示階層
72                 if (empty($levelCount)) $levelCount = self::DEFAULT_LEVEL_COUNT;                // デフォルト表示階層
73                 $color1 = $request->trimValueOf('item_color1');         // 文字色1
74                 $color2 = $request->trimValueOf('item_color2');         // 文字色2
75                 $color3 = $request->trimValueOf('item_color3');         // 文字色3
76                 $color4 = $request->trimValueOf('item_color4');         // 文字色4
77                 $imageMenu = ($request->trimValueOf('item_image_menu') == 'on') ? 1 : 0;        // 画像メニュー
78                 $title = $request->trimValueOf('item_title');           // メニュータイトル
79                 if (empty($title)) $title = self::DEFAULT_MENU_TITLE;                   // メニュータイトル
80                                 
81                 // 処理分岐
82                 $act = $request->trimValueOf('act');
83                 if ($act == 'select'){          // 画像選択の場合
84                 } else if ($act == 'update'){           // 項目更新の場合
85                         $menuInfo = new ec_category_menuInfo();
86                         $menuInfo->imageFilename = $filename;
87                         $menuInfo->levelCount = $levelCount;                                    // メニュー表示階層
88                         $menuInfo->fontColor1 = $color1;
89                         $menuInfo->fontColor2 = $color2;
90                         $menuInfo->fontColor3 = $color3;
91                         $menuInfo->fontColor4 = $color4;
92                         $menuInfo->useImageMenu = $imageMenu;           // 画像メニューを使用するかどうか
93                         $menuInfo->title = $title;                      // メニュータイトル
94                         
95                         // システムDBでメニュー情報を保存
96                         $ret = $gInstanceManager->getSytemDbObject()->updateWidgetParam(self::THIS_WIDGET_ID, serialize($menuInfo), $userInfo->userId);
97                         if ($ret){              // データ更新成功のとき
98                                 $this->setGuidanceMsg('データを更新しました');
99                         } else {
100                                 $this->setAppErrorMsg('データ更新に失敗しました');
101                         }
102                 } else if ($act == 'upload'){           // ファイルアップロードの場合
103                         // アップロードされたファイルか?セキュリティチェックする
104                         if (is_uploaded_file($_FILES['upfile']['tmp_name'])) {
105                                 $uploadFilename = $_FILES['upfile']['name'];            // アップロードされたファイルのファイル名取得
106                                 
107                                 // ファイルを保存するサーバディレクトリを指定
108                                 //$file = tempnam("/tmp","upload_");
109                                 //$save_dir = '/tmp/';
110                                 $imageFilePath = $gEnvManager->getCurrentWidgetRootPath() . '/' . self::IMAGE_DIR. '/' . $uploadFilename;
111                 
112                                 // アップされたテンポラリファイルを保存ディレクトリにコピー
113                                 $ret = move_uploaded_file($_FILES['upfile']['tmp_name'], $imageFilePath);
114
115                                 // ファイル削除
116                                 //unlink($imageFilePath);
117                                 if ($ret){
118                                         $msg = 'ファイルのアップロードが完了しました(ファイル名:' . $uploadFilename . ')';
119                                         $this->setGuidanceMsg($msg);
120                                 } else {
121                                         $this->setAppErrorMsg('ファイルのアップロードに失敗しました');
122                                 }
123                         }
124                 } else {
125                         // ファイル名設定値を取得
126                         $serializedParam = $gInstanceManager->getSytemDbObject()->getWidgetParam(self::THIS_WIDGET_ID);
127                         if (!empty($serializedParam)){
128                                 $menuInfo = unserialize($serializedParam);
129                                 $filename = $menuInfo->imageFilename;
130                                 if (!empty($menuInfo->imageFilename)) $filename = $menuInfo->imageFilename;
131                                 if (!empty($menuInfo->levelCount)) $levelCount = $menuInfo->levelCount;
132                                 if (!empty($menuInfo->fontColor1)) $color1 = $menuInfo->fontColor1;
133                                 if (!empty($menuInfo->fontColor2)) $color2 = $menuInfo->fontColor2;
134                                 if (!empty($menuInfo->fontColor3)) $color3 = $menuInfo->fontColor3;
135                                 if (!empty($menuInfo->fontColor4)) $color4 = $menuInfo->fontColor4;
136                                 if (!empty($menuInfo->useImageMenu)) $imageMenu = $menuInfo->useImageMenu;              // 画像メニューを使用するかどうか
137                                 if (!empty($menuInfo->title)) $title = $menuInfo->title;                        // メニュータイトル
138                         }
139                 }
140                 
141                 // メニュー画像メニューを作成
142                 // 画像ディレクトリチェック
143                 $searchPath = $gEnvManager->getCurrentWidgetRootPath() . '/' . self::IMAGE_DIR;
144                 if (is_dir($searchPath)){
145                         $dir = dir($searchPath);
146                         while (($file = $dir->read()) !== false){
147                                 $filePath = $searchPath . '/' . $file;
148                                 // ファイルかどうかチェック
149                                 if (strncmp($file, '.', 1) != 0 && $file != '..' && is_file($filePath)
150                                         && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
151                                         
152                                         $selected = '';
153                                         if ($file == $filename){
154                                                 $selected = 'selected';
155                                         }
156                                         $row = array(
157                                                 'value'    => $file,                    // ファイル名
158                                                 'name'     => $file,                    // ファイル名
159                                                 'selected' => $selected                                                                                                         // 選択中かどうか
160                                         );
161                                         $this->tmpl->addVars('image_file_list', $row);
162                                         $this->tmpl->parseTemplate('image_file_list', 'a');
163                                 }
164                         }
165                         $dir->close();
166                 }
167                 // パラメータの埋め込み
168                 $this->tmpl->addVar("_widget", "level_count", $levelCount);             // メニュー階層
169                 $this->tmpl->addVar("_widget", "filename", $filename);          // メニュー画像
170                 $this->tmpl->addVar("_widget", "color1", $color1);              // 文字色1
171                 $this->tmpl->addVar("_widget", "color2", $color2);              // 文字色2
172                 $this->tmpl->addVar("_widget", "color3", $color3);              // 文字色3
173                 $this->tmpl->addVar("_widget", "color4", $color4);              // 文字色4
174                 $imageMenuStr = '';
175                 if ($imageMenu){
176                         $imageMenuStr = 'checked';
177                 }               
178                 $this->tmpl->addVar("_widget", "image_menu", $imageMenuStr);            // 画像メニューを使用するかどうか
179                 $this->tmpl->addVar("_widget", "title", $title);                // タイトル
180                 
181                 // プレビューイメージの設定
182                 $preview = $gEnvManager->getCurrentWidgetRootUrl() . '/' . self::IMAGE_DIR . '/' . $filename;
183                 $this->tmpl->addVar("_widget", "image", $this->getUrl($preview));
184         }
185 }
186 ?>