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-2012 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_s_googlemapsWidgetContainer.php 4767 2012-03-19 08:59:10Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
18 class admin_s_googlemapsWidgetContainer extends BaseAdminWidgetContainer
20 private $serialNo; // 選択中の項目のシリアル番号
21 private $serialArray = array(); // 表示中のシリアル番号
23 private $configId; // 定義ID
24 private $paramObj; // パラメータ保存用オブジェクト
25 const DEFAULT_NAME_HEAD = '名称未設定'; // デフォルトの設定名
26 const DEFAULT_WIDTH = 320; // デフォルトの幅
27 const DEFAULT_HEIGHT = 480; // デフォルトの高さ
28 const CODING_URL = 'http://www.geocoding.jp/'; // 緯度経度取得用URL
29 const DEFAULT_POS_LAT = '35.594757'; // デフォルト緯度
30 const DEFAULT_POS_LNG = '139.620739'; // デフォルト経度
31 const DEFAULT_ZOOM = 13; // デフォルトのズームレベル
36 function __construct()
39 parent::__construct();
44 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
45 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
47 * @param RequestManager $request HTTPリクエスト処理クラス
48 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
49 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
51 function _setTemplate($request, &$param)
53 $task = $request->trimValueOf('task');
54 if ($task == 'list'){ // 一覧画面
55 return 'admin_list.tmpl.html';
57 return 'admin.tmpl.html';
63 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
65 * @param RequestManager $request HTTPリクエスト処理クラス
66 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
69 function _assign($request, &$param)
71 $task = $request->trimValueOf('task');
72 if ($task == 'list'){ // 一覧画面
73 return $this->createList($request);
75 return $this->createDetail($request);
81 * @param RequestManager $request HTTPリクエスト処理クラス
84 function createDetail($request)
86 // ページ定義IDとページ定義のレコードシリアル番号を取得
87 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
89 $userId = $this->gEnv->getCurrentUserId();
90 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
91 $act = $request->trimValueOf('act');
92 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
95 $name = $request->trimValueOf('item_name'); // ヘッダタイトル
96 $width = $request->trimValueOf('item_width'); // ヘッダの幅
97 $height = $request->trimValueOf('item_height'); // ヘッダの高さ
98 $lat = $request->trimValueOf('item_lat'); // 緯度
99 $lng = $request->trimValueOf('item_lng'); // 経度
100 $markerLat = $request->trimValueOf('item_marker_lat'); // マーカー緯度
101 $markerLng = $request->trimValueOf('item_marker_lng'); // マーカー経度
102 $infoLat = $request->trimValueOf('item_info_lat'); // 吹き出し緯度
103 $infoLng = $request->trimValueOf('item_info_lng'); // 吹き出し経度
104 $zoom = $request->trimValueOf('item_zoom'); // ズームレベル
105 $infoContent = $request->valueOf('item_info_content'); // 吹き出し内容
106 $infoContent = str_replace(array("\r", "\n", "\t"), '', $infoContent); // 改行、タブ削除
107 $showMarker = ($request->trimValueOf('item_show_marker') == 'on') ? 1 : 0; // マーカーを表示するかどうか
108 $showPosControl = ($request->trimValueOf('item_pos_control') == 'on') ? 1 : 0; // 位置コントローラを表示するかどうか
109 $showTypeControl = ($request->trimValueOf('item_type_control') == 'on') ? 1 : 0; // 地図タイプコントローラを表示するかどうか
110 $showInfo = ($request->trimValueOf('item_show_info') == 'on') ? 1 : 0; // 吹き出しを表示するかどうか
112 $this->configId = $request->trimValueOf('item_id'); // 定義ID
113 if (empty($this->configId)) $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
115 $replaceNew = false; // データを再取得するかどうか
116 if (empty($act)){// 初期起動時
118 $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
119 $replaceNew = true; // データ再取得
120 } else if ($act == 'add'){// 新規追加
122 $this->checkInput($name, '名前');
123 $this->checkNumeric($width, '幅');
124 $this->checkNumeric($height, '高さ');
125 $this->checkNumber($lat, '緯度');
126 $this->checkNumber($lng, '経度');
127 $this->checkNumber($zoom, 'ズームレベル');
128 if ($showMarker){ // マーカーを表示するかどうか
129 $this->checkNumber($markerLat, 'マーカー緯度');
130 $this->checkNumber($markerLng, 'マーカー経度');
132 $this->checkNumber($markerLat, 'マーカー緯度', true);
133 $this->checkNumber($markerLng, 'マーカー経度', true);
135 if ($showInfo){ // 吹き出しを表示するかどうか
136 $this->checkNumber($infoLat, '吹き出し緯度');
137 $this->checkNumber($infoLng, '吹き出し経度');
139 $this->checkNumber($infoLat, '吹き出し緯度', true);
140 $this->checkNumber($infoLng, '吹き出し経度', true);
144 for ($i = 0; $i < count($this->paramObj); $i++){
145 $targetObj = $this->paramObj[$i]->object;
146 if ($name == $targetObj->name){ // 定義名
147 $this->setUserErrorMsg('名前が重複しています');
153 if ($this->getMsgCount() == 0){
155 $newObj = new stdClass;
156 $newObj->name = $name; // 表示名
157 $newObj->width = $width; // 幅
158 $newObj->height = $height; // 高さ
159 $newObj->lat = $lat; // 緯度
160 $newObj->lng = $lng; // 経度
161 $newObj->markerLat = $markerLat; // マーカー緯度
162 $newObj->markerLng = $markerLng; // マーカー経度
163 $newObj->infoLat = $infoLat; // 吹き出し緯度
164 $newObj->infoLng = $infoLng; // 吹き出し経度
166 $newObj->zoom = $zoom; // ズームレベル
167 $newObj->infoContent = $infoContent; // 吹き出し内容
168 $newObj->showMarker = $showMarker; // マーカーを表示するかどうか
169 $newObj->showPosControl = $showPosControl; // 位置コントローラを表示するかどうか
170 $newObj->showTypeControl = $showTypeControl; // 地図タイプコントローラを表示するかどうか
171 $newObj->showInfo = $showInfo; // 吹き出しを表示するかどうか
173 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
176 $this->setGuidanceMsg('データを追加しました');
178 $this->configId = $defConfigId; // 定義定義IDを更新
179 $replaceNew = true; // データ再取得
181 $this->setAppErrorMsg('データ追加に失敗しました');
184 } else if ($act == 'update'){ // 設定更新のとき
186 $this->checkNumeric($width, '幅');
187 $this->checkNumeric($height, '高さ');
188 $this->checkNumber($lat, '緯度');
189 $this->checkNumber($lng, '経度');
190 $this->checkNumber($zoom, 'ズームレベル');
191 if ($showMarker){ // マーカーを表示するかどうか
192 $this->checkNumber($markerLat, 'マーカー緯度');
193 $this->checkNumber($markerLng, 'マーカー経度');
195 $this->checkNumber($markerLat, 'マーカー緯度', true);
196 $this->checkNumber($markerLng, 'マーカー経度', true);
198 if ($showInfo){ // 吹き出しを表示するかどうか
199 $this->checkNumber($infoLat, '吹き出し緯度');
200 $this->checkNumber($infoLng, '吹き出し経度');
202 $this->checkNumber($infoLat, '吹き出し緯度', true);
203 $this->checkNumber($infoLng, '吹き出し経度', true);
206 if ($this->getMsgCount() == 0){ // エラーのないとき
208 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
211 $targetObj->width = $width; // ヘッダの幅
212 $targetObj->height = $height; // ヘッダの高さ
213 $targetObj->lat = $lat; // 緯度
214 $targetObj->lng = $lng; // 経度
215 $targetObj->markerLat = $markerLat; // マーカー緯度
216 $targetObj->markerLng = $markerLng; // マーカー経度
217 $targetObj->infoLat = $infoLat; // 吹き出し緯度
218 $targetObj->infoLng = $infoLng; // 吹き出し経度
219 $targetObj->zoom = $zoom; // ズームレベル
220 $targetObj->infoContent = $infoContent; // 吹き出し内容
221 $targetObj->showMarker = $showMarker; // マーカーを表示するかどうか
222 $targetObj->showPosControl = $showPosControl; // 位置コントローラを表示するかどうか
223 $targetObj->showTypeControl = $showTypeControl; // 地図タイプコントローラを表示するかどうか
224 $targetObj->showInfo = $showInfo; // 吹き出しを表示するかどうか
228 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
231 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
233 $replaceNew = true; // データ再取得
235 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
238 } else if ($act == 'select'){ // 定義IDを変更
239 $replaceNew = true; // データ再取得
243 $this->createItemMenu();
246 if (empty($this->configId)){ // 新規登録の場合
247 $this->tmpl->setAttribute('item_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
248 if ($replaceNew){ // データ再取得時
249 $name = $this->createDefaultName(); // デフォルト登録項目名
250 $width = self::DEFAULT_WIDTH; // 幅
251 $height = self::DEFAULT_HEIGHT; // 高さ
252 $lat = self::DEFAULT_POS_LAT; // 緯度
253 $lng = self::DEFAULT_POS_LNG; // 経度
254 $markerLat = self::DEFAULT_POS_LAT; // マーカー緯度
255 $markerLng = self::DEFAULT_POS_LNG; // マーカー経度
256 $infoLat = self::DEFAULT_POS_LAT; // 吹き出し緯度
257 $infoLng = self::DEFAULT_POS_LNG; // 吹き出し経度
258 $zoom = self::DEFAULT_ZOOM; // ズームレベル
259 $infoContent = ''; // 吹き出し内容
260 $showMarker = 0; // マーカーを表示するかどうか
261 $showPosControl = 1; // 位置コントローラを表示するかどうか
262 $showTypeControl = 1; // 地図タイプコントローラを表示するかどうか
263 $showInfo = 0; // 吹き出しを表示するかどうか
268 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
270 $name = $targetObj->name;// 名前
271 $width = $targetObj->width; // 幅
272 $height = $targetObj->height; // 高さ
273 $lat = $targetObj->lat; // 緯度
274 $lng = $targetObj->lng; // 経度
275 $markerLat = $targetObj->markerLat; // マーカー緯度
276 $markerLng = $targetObj->markerLng; // マーカー経度
277 $infoLat = $targetObj->infoLat; // 吹き出し緯度
278 $infoLng = $targetObj->infoLng; // 吹き出し経度
279 $zoom = $targetObj->zoom; // ズームレベル
280 $infoContent = $targetObj->infoContent; // 吹き出し内容
281 $showMarker = $targetObj->showMarker; // マーカーを表示するかどうか
282 $showPosControl = $targetObj->showPosControl; // 位置コントローラを表示するかどうか
283 $showTypeControl = $targetObj->showTypeControl; // 地図タイプコントローラを表示するかどうか
284 $showInfo = $targetObj->showInfo; // 吹き出しを表示するかどうか
287 $this->serialNo = $this->configId;
289 // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
290 if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
294 if (is_numeric($lat) && is_numeric($lng) && is_numeric($zoom)) $this->tmpl->setAttribute('show_script', 'visibility', 'visible');// 緯度経度が入力されている場合
297 $this->tmpl->addVar("item_name_visible", "name", $name); // 名前
298 $this->tmpl->addVar("_widget", "width", $width);
299 $this->tmpl->addVar("_widget", "height", $height);
300 $this->tmpl->addVar("_widget", "lat", $lat); // 緯度
301 $this->tmpl->addVar("_widget", "lng", $lng); // 経度
302 $this->tmpl->addVar("_widget", "zoom", $zoom); // ズームレベル
303 $this->tmpl->addVar("_widget", "info_content", $this->convertToDispString($infoContent)); // 吹き出し内容
304 $this->tmpl->addVar("_widget", "marker_lat", $markerLat); // マーカー緯度
305 $this->tmpl->addVar("_widget", "marker_lng", $markerLng); // マーカー経度
306 $this->tmpl->addVar("_widget", "info_lat", $infoLat); // 吹き出し緯度
307 $this->tmpl->addVar("_widget", "info_lng", $infoLng); // 吹き出し経度
308 $this->tmpl->addVar("show_script", "lat", $lat); // 緯度
309 $this->tmpl->addVar("show_script", "lng", $lng); // 経度
310 $this->tmpl->addVar("show_script", "zoom", $zoom); // ズームレベル
311 $this->tmpl->addVar("show_marker", "marker_lat", $markerLat); // マーカー緯度
312 $this->tmpl->addVar("show_marker", "marker_lng", $markerLng); // マーカー経度
313 $this->tmpl->addVar("show_info", "info_lat", $infoLat); // 吹き出し緯度
314 $this->tmpl->addVar("show_info", "info_lng", $infoLng); // 吹き出し経度
315 $this->tmpl->addVar("show_info", "info_content", addslashes($infoContent)); // 吹き出し内容
318 if ($showMarker){ // マーカーを表示するかどうか
319 $checked = 'checked';
321 // 緯度経度が入力されている場合はスクリプトを表示
322 if (is_numeric($markerLat) && is_numeric($markerLng)) $this->tmpl->setAttribute('show_marker', 'visibility', 'visible');// マーカーを表示
324 $this->tmpl->addVar("_widget", "show_marker_checked", $checked); // マーカーを表示するかどうか
326 if ($showPosControl){ // 位置コントローラを表示するかどうか
327 $checked = 'checked';
328 $this->tmpl->setAttribute('show_pos_control', 'visibility', 'hidden');// 位置コントローラを表示
330 $this->tmpl->addVar("_widget", "pos_checked", $checked); // 位置コントローラを表示するかどうか
332 if ($showTypeControl){ // 地図タイプコントローラを表示するかどうか
333 $checked = 'checked';
334 $this->tmpl->setAttribute('show_type_control', 'visibility', 'hidden');// 地図タイプコントローラを表示
336 $this->tmpl->addVar("_widget", "type_checked", $checked); // 地図タイプコントローラを表示するかどうか
338 if ($showInfo){ // 吹き出しを表示するかどうか
339 $checked = 'checked';
341 // 緯度経度が入力されている場合はスクリプトを表示
342 if (is_numeric($infoLat) && is_numeric($infoLng)) $this->tmpl->setAttribute('show_info', 'visibility', 'visible');// 吹き出しを表示
344 $this->tmpl->addVar("_widget", "show_info_checked", $checked); // 吹き出しを表示するかどうか
345 $this->tmpl->addVar("_widget", "coding_url", self::CODING_URL); // 緯度経度取得用URL
347 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
350 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
351 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
353 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
355 // ページ定義IDとページ定義のレコードシリアル番号を更新
356 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
363 function createItemMenu()
365 for ($i = 0; $i < count($this->paramObj); $i++){
366 $id = $this->paramObj[$i]->id;// 定義ID
367 $targetObj = $this->paramObj[$i]->object;
368 $name = $targetObj->name;// 定義名
371 if (empty($id)) continue;// 定義ID=0は一覧表示しない
373 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('データ削除に失敗しました');
443 $this->createItemList();
445 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
447 // ページ定義IDとページ定義のレコードシリアル番号を更新
448 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
455 function createItemList()
458 for ($i = 0; $i < count($this->paramObj); $i++){
459 $id = $this->paramObj[$i]->id;// 定義ID
460 $targetObj = $this->paramObj[$i]->object;
461 $name = $targetObj->name;// 定義名
463 if (empty($id)) continue;// 定義ID=0は一覧表示しない
467 $defCount = $this->_db->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
469 $operationDisagled = '';
470 if ($defCount > 0) $operationDisagled = 'disabled';
472 // 値が設定されていないときはデフォルト値を設定
473 $markerLat = $targetObj->markerLat;
474 if ($markerLat == '') $markerLat = 0; // マーカー緯度
475 $markerLng = $targetObj->markerLng;
476 if ($markerLng == '') $markerLng = 0; // マーカー経度
477 $infoLat = $targetObj->infoLat;
478 if ($infoLat == '') $infoLat = 0; // 吹き出し緯度
479 $infoLng = $targetObj->infoLng;
480 if ($infoLng == '') $infoLng = 0; // 吹き出し経度
484 'ope_disabled' => $operationDisagled, // 選択可能かどうか
485 'name' => $this->convertToDispString($name), // 名前
486 'width' => $targetObj->width, // 動画幅
487 'height' => $targetObj->height, // 動画高さ
488 'lat' => $targetObj->lat, // 緯度
489 'lng' => $targetObj->lng, // 経度
490 'marker_lat' => $markerLat, // マーカー緯度
491 'marker_lng' => $markerLng, // マーカー経度
492 'info_lat' => $infoLat, // 吹き出し緯度
493 'info_lng' => $infoLng, // 吹き出し経度
494 'zoom' => $targetObj->zoom, // ズームレベル
495 'info_content' => $this->convertToDispString($targetObj->infoContent), // 吹き出し内容
496 'marker' => $targetObj->showMarker, // マーカーを表示するかどうか
497 'info' => $targetObj->showInfo, // 吹き出しを表示するかどうか
498 'pos_control' => $targetObj->showPosControl, // 位置コントローラを表示するかどうか
499 'type_control' => $targetObj->showTypeControl, // 地図タイプコントローラを表示するかどうか
500 'def_count' => $defCount // 使用数
502 $this->tmpl->addVars('itemlist', $row);
503 $this->tmpl->parseTemplate('itemlist', 'a');
506 $this->serialArray[] = $id;
511 * JavascriptファイルをHTMLヘッダ部に設定
513 * JavascriptファイルをHTMLのheadタグ内に追加出力する。
514 * _assign()よりも後に実行される。
516 * @param RequestManager $request HTTPリクエスト処理クラス
517 * @param object $param 任意使用パラメータ。
518 * @return string Javascriptファイル。出力しない場合は空文字列を設定。
520 function _addScriptFileToHead($request, &$param)
522 $scriptUrl = $this->getUrl('http://maps.google.com/maps/api/js?sensor=false');