7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2009 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_image2WidgetContainer.php 2268 2009-08-31 03:29:18Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/image2Db.php');
19 class admin_image2WidgetContainer extends BaseAdminWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $sysDb; // DB接続オブジェクト
23 private $serialNo; // 選択中の項目のシリアル番号
24 private $serialArray = array(); // 表示中のシリアル番号
26 private $configId; // 定義ID
27 private $paramObj; // パラメータ保存用オブジェクト
28 const DEFAULT_NAME_HEAD = '名称未設定'; // デフォルトの設定名
33 function __construct()
36 parent::__construct();
39 $this->db = new image2Db();
40 $this->sysDb = $this->gInstance->getSytemDbObject();
45 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
46 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
48 * @param RequestManager $request HTTPリクエスト処理クラス
49 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
50 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
52 function _setTemplate($request, &$param)
54 $task = $request->trimValueOf('task');
55 if ($task == 'list'){ // 一覧画面
56 return 'admin_list.tmpl.html';
58 return 'admin.tmpl.html';
64 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
66 * @param RequestManager $request HTTPリクエスト処理クラス
67 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
70 function _assign($request, &$param)
72 $task = $request->trimValueOf('task');
73 if ($task == 'list'){ // 一覧画面
74 return $this->createList($request);
76 return $this->createDetail($request);
82 * @param RequestManager $request HTTPリクエスト処理クラス
85 function createDetail($request)
87 // ページ定義IDとページ定義のレコードシリアル番号を取得
88 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
90 $userId = $this->gEnv->getCurrentUserId();
91 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
92 $act = $request->trimValueOf('act');
93 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
94 $this->configId = $request->trimValueOf('item_id'); // 定義ID
95 if (empty($this->configId)) $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
98 $name = $request->trimValueOf('item_name'); // 定義名
99 $imageUrl = $request->trimValueOf('item_image_url'); // 画像へのパス
100 $linkUrl = $request->trimValueOf('item_link_url'); // リンク先
101 $align = $request->trimValueOf('item_align'); // 表示位置
102 $bgcolor = $request->trimValueOf('item_bgcolor'); // 画像バックグランドカラー
103 $width = $request->trimValueOf('item_width'); // 画像の幅
104 $height = $request->trimValueOf('item_height'); // 画像の高さ
105 $margin = $request->trimValueOf('item_margin'); // 画像マージン
106 $widthType = $request->trimValueOf('item_widthtype'); // 画像の幅単位
107 $heightType = $request->trimValueOf('item_heighttype'); // 画像の高さ単位
108 $posx = $request->trimValueOf('item_posx'); // x座標
109 $posy = $request->trimValueOf('item_posy'); // y座標
110 $posxType = $request->trimValueOf('item_posxtype'); // x座標単位
111 $posyType = $request->trimValueOf('item_posytype'); // y座標単位
112 $posType = $request->trimValueOf('item_postype'); // 座標指定方法
113 $usePos = ($request->trimValueOf('item_use_pos') == 'on') ? 1 : 0; // 座標指定を可能とするかどうか
114 $useLink = ($request->trimValueOf('item_use_link') == 'on') ? 1 : 0; // 画像にリンクを付けるかどうか
116 $replaceNew = false; // データを再取得するかどうか
117 if ($act == 'add'){// 新規追加
119 $this->checkInput($name, '名前');
120 $this->checkNumeric($width, '画像の幅', true);
121 $this->checkNumeric($height, '画像の高さ', true);
122 $this->checkNumeric($margin, '画像マージン', true);
125 for ($i = 0; $i < count($this->paramObj); $i++){
126 $targetObj = $this->paramObj[$i]->object;
127 if ($name == $targetObj->name){ // 定義名
128 $this->setUserErrorMsg('名前が重複しています');
134 if ($this->getMsgCount() == 0){
136 if (!empty($imageUrl)) $imageUrl = $this->gEnv->getMacroPath($imageUrl);
139 $newObj = new stdClass;
140 $newObj->name = $name;// 表示名
141 $newObj->imageUrl = $imageUrl; // 画像へのパス
142 $newObj->linkUrl = $linkUrl; // リンク先
143 $newObj->align = $align; // 表示位置
144 $newObj->bgcolor = $bgcolor; // 画像バックグランドカラー
145 $newObj->width = $width; // 画像の幅
146 $newObj->height = $height; // 画像の高さ
147 $newObj->margin = $margin; // 画像マージン
148 $newObj->widthType = $widthType; // 画像の幅単位
149 $newObj->heightType = $heightType; // 画像の高さ単位
150 $newObj->posx = $posx; // x座標
151 $newObj->posy = $posy; // y座標
152 $newObj->posxType = $posxType; // x座標単位
153 $newObj->posyType = $posyType; // y座標単位
154 $newObj->posType = $posType; // 座標指定方法(相対座標)
155 $newObj->usePos = $usePos; // 座標指定を可能とするかどうか
156 $newObj->useLink = $useLink; // 画像にリンクを付けるかどうか
158 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
160 $this->setGuidanceMsg('データを追加しました');
162 $this->configId = $defConfigId; // 定義定義IDを更新
163 $replaceNew = true; // データ再取得
165 $this->setAppErrorMsg('データ追加に失敗しました');
168 } else if ($act == 'update'){ // 設定更新のとき
170 $this->checkNumeric($width, '画像の幅', true);
171 $this->checkNumeric($height, '画像の高さ', true);
172 $this->checkNumeric($margin, '画像マージン', true);
174 if ($this->getMsgCount() == 0){ // エラーのないとき
176 if (!empty($imageUrl)) $imageUrl = $this->gEnv->getMacroPath($imageUrl);
179 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
182 $targetObj->imageUrl = $imageUrl; // 画像へのパス
183 $targetObj->linkUrl = $linkUrl; // リンク先
184 $targetObj->align = $align; // 表示位置
185 $targetObj->bgcolor = $bgcolor; // 画像バックグランドカラー
186 $targetObj->width = $width; // 画像の幅
187 $targetObj->height = $height; // 画像の高さ
188 $targetObj->margin = $margin; // 画像マージン
189 $targetObj->widthType = $widthType; // 画像の幅単位
190 $targetObj->heightType = $heightType; // 画像の高さ単位
191 $targetObj->posx = $posx; // x座標
192 $targetObj->posy = $posy; // y座標
193 $targetObj->posxType = $posxType; // x座標単位
194 $targetObj->posyType = $posyType; // y座標単位
195 $targetObj->posType = $posType; // 座標指定方法(相対座標)
196 $targetObj->imageType = $imageType; // 画像のタイプ(0=メニューから選択、1=直接指定)
197 $targetObj->usePos = $usePos; // 座標指定を可能とするかどうか
198 $targetObj->useLink = $useLink; // 画像にリンクを付けるかどうか
202 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
204 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
205 $replaceNew = true; // データ再取得
207 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
210 } else if ($act == 'select'){ // 定義IDを変更
211 $replaceNew = true; // データ再取得
212 } else { // 初期起動時、または上記以外の場合
214 $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
215 $replaceNew = true; // データ再取得
218 $this->createItemMenu();
221 if (empty($this->configId)){ // 新規登録の場合
222 $this->tmpl->setAttribute('item_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
223 if ($replaceNew){ // データ再取得時
224 $name = $this->createDefaultName(); // デフォルト登録項目名
225 $imageUrl = ''; // 画像へのパス
226 $linkUrl = ''; // リンク先
228 $bgcolor = ''; // 画像バックグランドカラー
230 $height = 0; // 画像の高さ
231 $margin = 0; // 画像マージン
232 $widthType = 0; // 画像の幅単位
233 $heightType = 0; // 画像の高さ単位
236 $posxType = 0; // x座標単位
237 $posyType = 0; // y座標単位
238 $posType = 'relative'; // 座標指定方法(相対座標)
239 $usePos = 0; // 座標指定を可能とするかどうか
240 $useLink = 0; // 画像にリンクを付けるかどうか
244 if ($replaceNew){// データ再取得時
245 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
247 $name = $targetObj->name;// 名前
248 $imageUrl = $targetObj->imageUrl; // 画像へのパス
249 $linkUrl = $targetObj->linkUrl; // リンク先
250 $align = $targetObj->align; // 表示位置
251 $bgcolor = $targetObj->bgcolor; // 画像バックグランドカラー
252 $width = $targetObj->width; // 画像の幅
253 $height = $targetObj->height; // 画像の高さ
254 $margin = $targetObj->margin; // 画像マージン
255 $widthType = $targetObj->widthType; // 画像の幅単位
256 $heightType = $targetObj->heightType; // 画像の高さ単位
257 $posx = $targetObj->posx; // x座標
258 $posy = $targetObj->posy; // y座標
259 $posxType = $targetObj->posxType; // x座標単位
260 $posyType = $targetObj->posyType; // y座標単位
261 $posType = $targetObj->posType; // 座標指定方法(相対座標)
262 $usePos = $targetObj->usePos; // 座標指定を可能とするかどうか
263 $useLink = $targetObj->useLink; // 画像にリンクを付けるかどうか
266 $this->serialNo = $this->configId;
268 // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
269 if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
273 if (!empty($imageUrl)){
274 $imageUrl = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->gEnv->getRootUrl(), $imageUrl);
278 if (!empty($this->configId)) $this->tmpl->addVar("_widget", "id", $this->configId); // 定義ID
279 $this->tmpl->addVar("item_name_visible", "name", $name);
280 $this->tmpl->addVar("_widget", "link_url", $this->getUrl($linkUrl));// リンク先
281 $this->tmpl->addVar("_widget", "bgcolor", $bgcolor);
282 $this->tmpl->addVar("_widget", "width", $width);
283 $this->tmpl->addVar("_widget", "height", $height);
284 $this->tmpl->addVar("_widget", "margin", $margin);
285 $this->tmpl->addVar("_widget", "posx", $posx);// x座標
286 $this->tmpl->addVar("_widget", "posy", $posy);// y座標
289 if (empty($widthType)){ // ヘッダの幅単位
290 $this->tmpl->addVar("_widget", "width0_selected", 'selected');
292 $this->tmpl->addVar("_widget", "width1_selected", 'selected');
294 if (empty($heightType)){ // ヘッダの高さ単位
295 $this->tmpl->addVar("_widget", "height0_selected", 'selected');
297 $this->tmpl->addVar("_widget", "height1_selected", 'selected');
299 if (empty($posxType)){ // x座標単位
300 $this->tmpl->addVar("_widget", "posx0_selected", 'selected');
302 $this->tmpl->addVar("_widget", "posx1_selected", 'selected');
304 if (empty($posyType)){ // y座標単位
305 $this->tmpl->addVar("_widget", "posy0_selected", 'selected');
307 $this->tmpl->addVar("_widget", "posy1_selected", 'selected');
309 if ($posType == 'relative'){ // 座標の指定方法
310 $this->tmpl->addVar("_widget", "postype0_selected", 'selected');
311 } else if ($posType == 'absolute'){
312 $this->tmpl->addVar("_widget", "postype1_selected", 'selected');
314 if ($align == ''){ // 表示位置
315 $this->tmpl->addVar("_widget", "align0_selected", 'selected');
316 } else if ($align == 'left'){
317 $this->tmpl->addVar("_widget", "align1_selected", 'selected');
318 } else if ($align == 'center'){
319 $this->tmpl->addVar("_widget", "align2_selected", 'selected');
320 } else if ($align == 'right'){
321 $this->tmpl->addVar("_widget", "align3_selected", 'selected');
323 $this->tmpl->addVar("_widget", "image_url", $imageUrl);
324 if ($usePos) $this->tmpl->addVar('_widget', 'use_pos', 'checked'); // 座標指定を可能とするかどうか
325 if ($useLink) $this->tmpl->addVar('_widget', 'use_link', 'checked'); // 画像にリンクを付けるかどうか
329 if (!empty($imageUrl)){
330 $destImg = '<img id="preview_img" src="' . $this->getUrl($imageUrl) . '"';
331 if (!empty($width) && $width > 0){
332 $destImg .= ' width="' . $width;
333 if (!empty($widthType)) $destImg .= '%';
336 if (!empty($height) && $height > 0){
337 $destImg .= ' height="' . $height;
338 if (!empty($heightType)) $destImg .= '%';
343 $this->tmpl->addVar("_widget", "image", $destImg);
345 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
348 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
349 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
351 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
354 $this->convertHelp('update_button');
357 // ページ定義IDとページ定義のレコードシリアル番号を更新
358 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
365 function createItemMenu()
367 for ($i = 0; $i < count($this->paramObj); $i++){
368 $id = $this->paramObj[$i]->id;// 定義ID
369 $targetObj = $this->paramObj[$i]->object;
370 $name = $targetObj->name;// 定義名
372 if ($this->configId == $id) $selected = 'selected';
375 'name' => $name, // 名前
376 'value' => $id, // 定義ID
377 'selected' => $selected // 選択中の項目かどうか
379 $this->tmpl->addVars('title_list', $row);
380 $this->tmpl->parseTemplate('title_list', 'a');
386 * @return string デフォルト名
388 function createDefaultName()
390 $name = self::DEFAULT_NAME_HEAD;
391 for ($j = 1; $j < 100; $j++){
392 $name = self::DEFAULT_NAME_HEAD . $j;
394 for ($i = 0; $i < count($this->paramObj); $i++){
395 $targetObj = $this->paramObj[$i]->object;
396 if ($name == $targetObj->name){ // 定義名
401 if ($i == count($this->paramObj)) break;
408 * @param RequestManager $request HTTPリクエスト処理クラス
411 function createList($request)
413 // ページ定義IDとページ定義のレコードシリアル番号を取得
414 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
416 $userId = $this->gEnv->getCurrentUserId();
417 $langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
418 $act = $request->trimValueOf('act');
420 if ($act == 'delete'){ // メニュー項目の削除
421 $listedItem = explode(',', $request->trimValueOf('seriallist'));
423 for ($i = 0; $i < count($listedItem); $i++){
425 $itemName = 'item' . $i . '_selected';
426 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
428 if ($itemValue){ // チェック項目
429 $delItems[] = $listedItem[$i];
432 if (count($delItems) > 0){
433 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
434 if ($ret){ // データ削除成功のとき
435 $this->setGuidanceMsg('データを削除しました');
437 $this->setAppErrorMsg('データ削除に失敗しました');
442 $this->createItemList();
444 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
445 $this->tmpl->addVar('_widget', 'admin_url', $this->gEnv->getDefaultAdminUrl());// 管理者URL
447 // ページ定義IDとページ定義のレコードシリアル番号を更新
448 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
455 function createItemList()
457 for ($i = 0; $i < count($this->paramObj); $i++){
458 $id = $this->paramObj[$i]->id;// 定義ID
459 $targetObj = $this->paramObj[$i]->object;
460 $name = $targetObj->name;// 定義名
461 $width = $targetObj->width; // 画像の幅
462 $height = $targetObj->height; // 画像の高さ
463 $widthType = $targetObj->widthType; // 画像の幅単位
464 $heightType = $targetObj->heightType; // 画像の高さ単位
468 $partArray = explode('/', $targetObj->imageUrl);
469 if (count($partArray) > 0) $filename = $partArray[count($partArray)-1];
474 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
476 $operationDisagled = '';
477 if ($defCount > 0) $operationDisagled = 'disabled';
482 if (!empty($width) && $width > 0){
484 if (!empty($widthType)) $imgWidth .= '%';
486 if (!empty($height) && $height > 0){
487 $imgHeight = $height;
488 if (!empty($heightType)) $imgHeight .= '%';
492 $url = $targetObj->imageUrl;
493 if (!empty($url)) $url = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->gEnv->getRootUrl(), $url);
498 'ope_disabled' => $operationDisagled, // 選択可能かどうか
499 'name' => $this->convertToDispString($name), // 名前
500 'filename' => $this->convertToDispString($filename), // ファイル名
501 'def_count' => $defCount, // 使用数
502 'width' => $imgWidth, // 画像幅
503 'height' => $imgHeight, // 画像高さ
504 'url' => $this->getUrl($url) // URL
506 $this->tmpl->addVars('itemlist', $row);
507 $this->tmpl->parseTemplate('itemlist', 'a');
510 $this->serialArray[] = $id;