OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / m / googlemaps / include / container / admin_m_googlemapsWidgetContainer.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-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
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17
18 class admin_m_googlemapsWidgetContainer extends BaseAdminWidgetContainer
19 {
20         private $serialNo;              // 選択中の項目のシリアル番号
21         private $serialArray = array();                 // 表示中のシリアル番号
22         private $langId;
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;                        // デフォルトのズームレベル
32         
33         /**
34          * コンストラクタ
35          */
36         function __construct()
37         {
38                 // 親クラスを呼び出す
39                 parent::__construct();
40         }
41         /**
42          * テンプレートファイルを設定
43          *
44          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
45          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
46          *
47          * @param RequestManager $request               HTTPリクエスト処理クラス
48          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
49          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
50          */
51         function _setTemplate($request, &$param)
52         {
53                 $task = $request->trimValueOf('task');
54                 if ($task == 'list'){           // 一覧画面
55                         return 'admin_list.tmpl.html';
56                 } else {                        // 一覧画面
57                         return 'admin.tmpl.html';
58                 }
59         }
60         /**
61          * テンプレートにデータ埋め込む
62          *
63          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
64          *
65          * @param RequestManager $request               HTTPリクエスト処理クラス
66          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
67          * @return                                                              なし
68          */
69         function _assign($request, &$param)
70         {
71                 $task = $request->trimValueOf('task');
72                 if ($task == 'list'){           // 一覧画面
73                         return $this->createList($request);
74                 } else {                        // 詳細設定画面
75                         return $this->createDetail($request);
76                 }
77         }
78         /**
79          * 詳細画面作成
80          *
81          * @param RequestManager $request               HTTPリクエスト処理クラス
82          * @return                                                              なし
83          */
84         function createDetail($request)
85         {
86                 // ページ定義IDとページ定義のレコードシリアル番号を取得
87                 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
88                 
89                 $userId         = $this->gEnv->getCurrentUserId();
90                 $this->langId   = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
91                 $act = $request->trimValueOf('act');
92                 $this->serialNo = $request->trimValueOf('serial');              // 選択項目のシリアル番号
93
94                 // 入力値を取得
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');            // 代替テキスト
105                 
106                 $this->configId = $request->trimValueOf('item_id');             // 定義ID
107                 if (empty($this->configId)) $this->configId = $defConfigId;             // 呼び出しウィンドウから引き継いだ定義ID
108                 
109                 $replaceNew = false;            // データを再取得するかどうか
110                 if (empty($act)){// 初期起動時
111                         // デフォルト値設定
112                         $this->configId = $defConfigId;         // 呼び出しウィンドウから引き継いだ定義ID
113                         $replaceNew = true;                     // データ再取得
114                 } else if ($act == 'add'){// 新規追加
115                         // 入力チェック
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, 'マーカー経度');
125                         } else {
126                                 $this->checkNumber($markerLat, 'マーカー緯度', true);
127                                 $this->checkNumber($markerLng, 'マーカー経度', true);
128                         }
129                         
130                         // 設定名の重複チェック
131                         for ($i = 0; $i < count($this->paramObj); $i++){
132                                 $targetObj = $this->paramObj[$i]->object;
133                                 if ($name == $targetObj->name){         // 定義名
134                                         $this->setUserErrorMsg('名前が重複しています');
135                                         break;
136                                 }
137                         }
138                         
139                         // エラーなしの場合は、データを登録
140                         if ($this->getMsgCount() == 0){
141                                 // 追加オブジェクト作成
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;           // マーカー経度
150                                 
151                                 $newObj->zoom   = $zoom;                // ズームレベル
152                                 $newObj->showMarker = $showMarker;              // マーカーを表示するかどうか
153                                 $newObj->alt    = $alt;         // 代替テキスト
154                                 
155                                 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
156                                 
157                                 if ($ret){
158                                         $this->setGuidanceMsg('データを追加しました');
159                                         
160                                         $this->configId = $defConfigId;         // 定義定義IDを更新
161                                         $replaceNew = true;                     // データ再取得
162                                 } else {
163                                         $this->setAppErrorMsg('データ追加に失敗しました');
164                                 }
165                         }
166                 } else if ($act == 'update'){           // 設定更新のとき
167                         // 入力値のエラーチェック
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, 'マーカー経度');
176                         } else {
177                                 $this->checkNumber($markerLat, 'マーカー緯度', true);
178                                 $this->checkNumber($markerLng, 'マーカー経度', true);
179                         }
180                         
181                         if ($this->getMsgCount() == 0){                 // エラーのないとき
182                                 // 現在の設定値を取得
183                                 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
184                                 if ($ret){
185                                         // ウィジェットオブジェクト更新
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;         // 代替テキスト
195                                 }
196                                 
197                                 // 設定値を更新
198                                 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
199                                 
200                                 if ($ret){
201                                         $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
202                                         
203                                         $replaceNew = true;                     // データ再取得
204                                 } else {
205                                         $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
206                                 }
207                         }
208                 } else if ($act == 'select'){   // 定義IDを変更
209                         $replaceNew = true;                     // データ再取得
210                 }
211                 
212                 // 設定項目選択メニュー作成
213                 $this->createItemMenu();
214                 
215                 // 表示用データを取得
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;                // マーカーを表示するかどうか
228                                 $alt    = '';           // 代替テキスト
229                         }
230                         $this->serialNo = 0;
231                 } else {
232                         if ($replaceNew){
233                                 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
234                                 if ($ret){
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;              // 代替テキスト
245                                 }
246                         }
247                         $this->serialNo = $this->configId;
248                                 
249                         // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
250                         if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
251                 }
252                 
253                 // プレビュー表示
254                 if (is_numeric($lat) && is_numeric($lng) && is_numeric($zoom)) $this->tmpl->setAttribute('show_script', 'visibility', 'visible');// 緯度経度が入力されている場合
255                 
256                 // 画面にデータを埋め込む
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);            // マーカー経度
271                 
272                 $checked = '';
273                 if ($showMarker){                       // マーカーを表示するかどうか
274                         $checked = 'checked';
275                         
276                         // 緯度経度が入力されている場合はスクリプトを表示
277                         if (is_numeric($markerLat) && is_numeric($markerLng)) $this->tmpl->setAttribute('show_marker', 'visibility', 'visible');// マーカーを表示
278                 }
279                 $this->tmpl->addVar("_widget", "show_marker_checked", $checked);        // マーカーを表示するかどうか
280                 
281                 $this->tmpl->addVar("_widget", "coding_url",    self::CODING_URL);              // 緯度経度取得用URL
282                                 
283                 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
284                 
285                 // ボタンの表示制御
286                 if (empty($this->serialNo)){            // 新規追加項目を選択しているとき
287                         $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
288                 } else {
289                         $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
290                 }
291                 // ページ定義IDとページ定義のレコードシリアル番号を更新
292                 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
293         }
294         /**
295          * 選択用メニューを作成
296          *
297          * @return なし                                               
298          */
299         function createItemMenu()
300         {
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;// 定義名
305                         $selected = '';
306
307                         if (empty($id)) continue;// 定義ID=0は一覧表示しない
308                         
309                         if ($this->configId == $id) $selected = 'selected';
310                         $row = array(
311                                 'name' => $name,                // 名前
312                                 'value' => $id,         // 定義ID
313                                 'selected' => $selected // 選択中の項目かどうか
314                         );
315                         $this->tmpl->addVars('title_list', $row);
316                         $this->tmpl->parseTemplate('title_list', 'a');
317                 }
318         }
319         /**
320          * デフォルトの名前を取得
321          *
322          * @return string       デフォルト名                                              
323          */
324         function createDefaultName()
325         {
326                 $name = self::DEFAULT_NAME_HEAD;
327                 for ($j = 1; $j < 100; $j++){
328                         $name = self::DEFAULT_NAME_HEAD . $j;
329                         // 設定名の重複チェック
330                         for ($i = 0; $i < count($this->paramObj); $i++){
331                                 $targetObj = $this->paramObj[$i]->object;
332                                 if ($name == $targetObj->name){         // 定義名
333                                         break;
334                                 }
335                         }
336                         // 重複なしのときは終了
337                         if ($i == count($this->paramObj)) break;
338                 }
339                 return $name;
340         }
341         /**
342          * 一覧画面作成
343          *
344          * @param RequestManager $request               HTTPリクエスト処理クラス
345          * @return                                                              なし
346          */
347         function createList($request)
348         {
349                 // ページ定義IDとページ定義のレコードシリアル番号を取得
350                 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
351                 
352                 $userId         = $this->gEnv->getCurrentUserId();
353                 $langId = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
354                 $act = $request->trimValueOf('act');
355                 
356                 if ($act == 'delete'){          // メニュー項目の削除
357                         $listedItem = explode(',', $request->trimValueOf('seriallist'));
358                         $delItems = array();
359                         for ($i = 0; $i < count($listedItem); $i++){
360                                 // 項目がチェックされているかを取得
361                                 $itemName = 'item' . $i . '_selected';
362                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
363                                 
364                                 if ($itemValue){                // チェック項目
365                                         $delItems[] = $listedItem[$i];
366                                 }
367                         }
368                         if (count($delItems) > 0){
369                                 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
370                                 if ($ret){              // データ削除成功のとき
371                                         $this->setGuidanceMsg('データを削除しました');
372                                 } else {
373                                         $this->setAppErrorMsg('データ削除に失敗しました');
374                                 }
375                         }
376                 }
377                                         
378                 // 定義一覧作成
379                 $this->createItemList();
380                 
381                 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
382                 
383                 // ページ定義IDとページ定義のレコードシリアル番号を更新
384                 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
385         }
386         /**
387          * 定義一覧作成
388          *
389          * @return なし                                               
390          */
391         function createItemList()
392         {
393                 $index = 0;
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;// 定義名
398                         
399                         if (empty($id)) continue;// 定義ID=0は一覧表示しない
400                         
401                         $defCount = 0;
402                         if (!empty($id)){
403                                 $defCount = $this->_db->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
404                         }
405                         $operationDisagled = '';
406                         if ($defCount > 0) $operationDisagled = 'disabled';
407                         
408                         // 値が設定されていないときはデフォルト値を設定
409                         $markerLat = $targetObj->markerLat;
410                         if ($markerLat == '')   $markerLat      = 0;            // マーカー緯度
411                         $markerLng = $targetObj->markerLng;
412                         if ($markerLng == '')   $markerLng      = 0;            // マーカー経度
413
414                         $row = array(
415                                 'index' => $index,
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                                                        // 使用数
427                         );
428                         $this->tmpl->addVars('itemlist', $row);
429                         $this->tmpl->parseTemplate('itemlist', 'a');
430                         
431                         // シリアル番号を保存
432                         $this->serialArray[] = $id;
433                         $index++;               // 項目番号更新
434                 }
435         }
436         /**
437          * JavascriptファイルをHTMLヘッダ部に設定
438          *
439          * JavascriptファイルをHTMLのheadタグ内に追加出力する。
440          * _assign()よりも後に実行される。
441          *
442          * @param RequestManager $request               HTTPリクエスト処理クラス
443          * @param object         $param                 任意使用パラメータ。
444          * @return string                                               Javascriptファイル。出力しない場合は空文字列を設定。
445          */
446         function _addScriptFileToHead($request, &$param)
447         {
448                 $scriptUrl = $this->getUrl('http://maps.google.com/maps/api/js?sensor=false');
449                 return $scriptUrl;
450         }
451 }
452 ?>