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_m_googlemapsWidgetContainer.php 4770 2012-03-19 12:15:19Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
18 class admin_m_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 = 240; // デフォルトの幅
27 const DEFAULT_HEIGHT = 320; // デフォルトの高さ
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 $zoom = $request->trimValueOf('item_zoom'); // ズームレベル
103 $showMarker = ($request->trimValueOf('item_show_marker') == 'on') ? 1 : 0; // マーカーを表示するかどうか
104 $alt = $request->trimValueOf('item_alt'); // 代替テキスト
106 $this->configId = $request->trimValueOf('item_id'); // 定義ID
107 if (empty($this->configId)) $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
109 $replaceNew = false; // データを再取得するかどうか
110 if (empty($act)){// 初期起動時
112 $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
113 $replaceNew = true; // データ再取得
114 } else if ($act == 'add'){// 新規追加
116 $this->checkInput($name, '名前');
117 $this->checkNumeric($width, '幅');
118 $this->checkNumeric($height, '高さ');
119 $this->checkNumber($lat, '緯度');
120 $this->checkNumber($lng, '経度');
121 $this->checkNumber($zoom, 'ズームレベル');
122 if ($showMarker){ // マーカーを表示するかどうか
123 $this->checkNumber($markerLat, 'マーカー緯度');
124 $this->checkNumber($markerLng, 'マーカー経度');
126 $this->checkNumber($markerLat, 'マーカー緯度', true);
127 $this->checkNumber($markerLng, 'マーカー経度', true);
131 for ($i = 0; $i < count($this->paramObj); $i++){
132 $targetObj = $this->paramObj[$i]->object;
133 if ($name == $targetObj->name){ // 定義名
134 $this->setUserErrorMsg('名前が重複しています');
140 if ($this->getMsgCount() == 0){
142 $newObj = new stdClass;
143 $newObj->name = $name; // 表示名
144 $newObj->width = $width; // 幅
145 $newObj->height = $height; // 高さ
146 $newObj->lat = $lat; // 緯度
147 $newObj->lng = $lng; // 経度
148 $newObj->markerLat = $markerLat; // マーカー緯度
149 $newObj->markerLng = $markerLng; // マーカー経度
151 $newObj->zoom = $zoom; // ズームレベル
152 $newObj->showMarker = $showMarker; // マーカーを表示するかどうか
153 $newObj->alt = $alt; // 代替テキスト
155 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
158 $this->setGuidanceMsg('データを追加しました');
160 $this->configId = $defConfigId; // 定義定義IDを更新
161 $replaceNew = true; // データ再取得
163 $this->setAppErrorMsg('データ追加に失敗しました');
166 } else if ($act == 'update'){ // 設定更新のとき
168 $this->checkNumeric($width, '幅');
169 $this->checkNumeric($height, '高さ');
170 $this->checkNumber($lat, '緯度');
171 $this->checkNumber($lng, '経度');
172 $this->checkNumber($zoom, 'ズームレベル');
173 if ($showMarker){ // マーカーを表示するかどうか
174 $this->checkNumber($markerLat, 'マーカー緯度');
175 $this->checkNumber($markerLng, 'マーカー経度');
177 $this->checkNumber($markerLat, 'マーカー緯度', true);
178 $this->checkNumber($markerLng, 'マーカー経度', true);
181 if ($this->getMsgCount() == 0){ // エラーのないとき
183 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
186 $targetObj->width = $width; // ヘッダの幅
187 $targetObj->height = $height; // ヘッダの高さ
188 $targetObj->lat = $lat; // 緯度
189 $targetObj->lng = $lng; // 経度
190 $targetObj->markerLat = $markerLat; // マーカー緯度
191 $targetObj->markerLng = $markerLng; // マーカー経度
192 $targetObj->zoom = $zoom; // ズームレベル
193 $targetObj->showMarker = $showMarker; // マーカーを表示するかどうか
194 $targetObj->alt = $alt; // 代替テキスト
198 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
201 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
203 $replaceNew = true; // データ再取得
205 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
208 } else if ($act == 'select'){ // 定義IDを変更
209 $replaceNew = true; // データ再取得
213 $this->createItemMenu();
216 if (empty($this->configId)){ // 新規登録の場合
217 $this->tmpl->setAttribute('item_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
218 if ($replaceNew){ // データ再取得時
219 $name = $this->createDefaultName(); // デフォルト登録項目名
220 $width = self::DEFAULT_WIDTH; // 幅
221 $height = self::DEFAULT_HEIGHT; // 高さ
222 $lat = self::DEFAULT_POS_LAT; // 緯度
223 $lng = self::DEFAULT_POS_LNG; // 経度
224 $markerLat = self::DEFAULT_POS_LAT; // マーカー緯度
225 $markerLng = self::DEFAULT_POS_LNG; // マーカー経度
226 $zoom = self::DEFAULT_ZOOM; // ズームレベル
227 $showMarker = 0; // マーカーを表示するかどうか
233 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
235 $name = $targetObj->name;// 名前
236 $width = $targetObj->width; // 幅
237 $height = $targetObj->height; // 高さ
238 $lat = $targetObj->lat; // 緯度
239 $lng = $targetObj->lng; // 経度
240 $markerLat = $targetObj->markerLat; // マーカー緯度
241 $markerLng = $targetObj->markerLng; // マーカー経度
242 $zoom = $targetObj->zoom; // ズームレベル
243 $showMarker = $targetObj->showMarker; // マーカーを表示するかどうか
244 $alt = $targetObj->alt; // 代替テキスト
247 $this->serialNo = $this->configId;
249 // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
250 if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
254 if (is_numeric($lat) && is_numeric($lng) && is_numeric($zoom)) $this->tmpl->setAttribute('show_script', 'visibility', 'visible');// 緯度経度が入力されている場合
257 $this->tmpl->addVar("item_name_visible", "name", $name); // 名前
258 $this->tmpl->addVar("_widget", "width", $width);
259 $this->tmpl->addVar("_widget", "height", $height);
260 $this->tmpl->addVar("_widget", "lat", $lat); // 緯度
261 $this->tmpl->addVar("_widget", "lng", $lng); // 経度
262 $this->tmpl->addVar("_widget", "zoom", $zoom); // ズームレベル
263 $this->tmpl->addVar("_widget", "marker_lat", $markerLat); // マーカー緯度
264 $this->tmpl->addVar("_widget", "marker_lng", $markerLng); // マーカー経度
265 $this->tmpl->addVar("_widget", "alt", $alt); // 代替テキスト
266 $this->tmpl->addVar("show_script", "lat", $lat); // 緯度
267 $this->tmpl->addVar("show_script", "lng", $lng); // 経度
268 $this->tmpl->addVar("show_script", "zoom", $zoom); // ズームレベル
269 $this->tmpl->addVar("show_marker", "marker_lat", $markerLat); // マーカー緯度
270 $this->tmpl->addVar("show_marker", "marker_lng", $markerLng); // マーカー経度
273 if ($showMarker){ // マーカーを表示するかどうか
274 $checked = 'checked';
276 // 緯度経度が入力されている場合はスクリプトを表示
277 if (is_numeric($markerLat) && is_numeric($markerLng)) $this->tmpl->setAttribute('show_marker', 'visibility', 'visible');// マーカーを表示
279 $this->tmpl->addVar("_widget", "show_marker_checked", $checked); // マーカーを表示するかどうか
281 $this->tmpl->addVar("_widget", "coding_url", self::CODING_URL); // 緯度経度取得用URL
283 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
286 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
287 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
289 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
291 // ページ定義IDとページ定義のレコードシリアル番号を更新
292 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
299 function createItemMenu()
301 for ($i = 0; $i < count($this->paramObj); $i++){
302 $id = $this->paramObj[$i]->id;// 定義ID
303 $targetObj = $this->paramObj[$i]->object;
304 $name = $targetObj->name;// 定義名
307 if (empty($id)) continue;// 定義ID=0は一覧表示しない
309 if ($this->configId == $id) $selected = 'selected';
311 'name' => $name, // 名前
312 'value' => $id, // 定義ID
313 'selected' => $selected // 選択中の項目かどうか
315 $this->tmpl->addVars('title_list', $row);
316 $this->tmpl->parseTemplate('title_list', 'a');
322 * @return string デフォルト名
324 function createDefaultName()
326 $name = self::DEFAULT_NAME_HEAD;
327 for ($j = 1; $j < 100; $j++){
328 $name = self::DEFAULT_NAME_HEAD . $j;
330 for ($i = 0; $i < count($this->paramObj); $i++){
331 $targetObj = $this->paramObj[$i]->object;
332 if ($name == $targetObj->name){ // 定義名
337 if ($i == count($this->paramObj)) break;
344 * @param RequestManager $request HTTPリクエスト処理クラス
347 function createList($request)
349 // ページ定義IDとページ定義のレコードシリアル番号を取得
350 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
352 $userId = $this->gEnv->getCurrentUserId();
353 $langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
354 $act = $request->trimValueOf('act');
356 if ($act == 'delete'){ // メニュー項目の削除
357 $listedItem = explode(',', $request->trimValueOf('seriallist'));
359 for ($i = 0; $i < count($listedItem); $i++){
361 $itemName = 'item' . $i . '_selected';
362 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
364 if ($itemValue){ // チェック項目
365 $delItems[] = $listedItem[$i];
368 if (count($delItems) > 0){
369 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
370 if ($ret){ // データ削除成功のとき
371 $this->setGuidanceMsg('データを削除しました');
373 $this->setAppErrorMsg('データ削除に失敗しました');
379 $this->createItemList();
381 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
383 // ページ定義IDとページ定義のレコードシリアル番号を更新
384 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
391 function createItemList()
394 for ($i = 0; $i < count($this->paramObj); $i++){
395 $id = $this->paramObj[$i]->id;// 定義ID
396 $targetObj = $this->paramObj[$i]->object;
397 $name = $targetObj->name;// 定義名
399 if (empty($id)) continue;// 定義ID=0は一覧表示しない
403 $defCount = $this->_db->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
405 $operationDisagled = '';
406 if ($defCount > 0) $operationDisagled = 'disabled';
408 // 値が設定されていないときはデフォルト値を設定
409 $markerLat = $targetObj->markerLat;
410 if ($markerLat == '') $markerLat = 0; // マーカー緯度
411 $markerLng = $targetObj->markerLng;
412 if ($markerLng == '') $markerLng = 0; // マーカー経度
416 'ope_disabled' => $operationDisagled, // 選択可能かどうか
417 'name' => $this->convertToDispString($name), // 名前
418 'width' => $targetObj->width, // 動画幅
419 'height' => $targetObj->height, // 動画高さ
420 'lat' => $targetObj->lat, // 緯度
421 'lng' => $targetObj->lng, // 経度
422 'marker_lat' => $markerLat, // マーカー緯度
423 'marker_lng' => $markerLng, // マーカー経度
424 'zoom' => $targetObj->zoom, // ズームレベル
425 'marker' => $targetObj->showMarker, // マーカーを表示するかどうか
426 'def_count' => $defCount // 使用数
428 $this->tmpl->addVars('itemlist', $row);
429 $this->tmpl->parseTemplate('itemlist', 'a');
432 $this->serialArray[] = $id;
437 * JavascriptファイルをHTMLヘッダ部に設定
439 * JavascriptファイルをHTMLのheadタグ内に追加出力する。
440 * _assign()よりも後に実行される。
442 * @param RequestManager $request HTTPリクエスト処理クラス
443 * @param object $param 任意使用パラメータ。
444 * @return string Javascriptファイル。出力しない場合は空文字列を設定。
446 function _addScriptFileToHead($request, &$param)
448 $scriptUrl = $this->getUrl('http://maps.google.com/maps/api/js?sensor=false');