OSDN Git Service

テンプレート管理画面仕様追加。
authornaoki hirata <naoki@magic3.org>
Thu, 5 Jul 2018 07:57:43 +0000 (16:57 +0900)
committernaoki hirata <naoki@magic3.org>
Thu, 5 Jul 2018 07:57:43 +0000 (16:57 +0900)
include/container/admin_indexFrameContainer.php
include/container/baseAdminTemplateContainer.php [new file with mode: 0644]
include/container/baseFrameContainer.php
include/manager/launchManager.php
templates/bootstrap4_custom/admin/index.php [new file with mode: 0644]
templates/bootstrap4_custom/include/container/admin_bootstrap4_customTemplateContainer.php [new file with mode: 0644]
templates/bootstrap4_custom/include/template/admin.tmpl.html [new file with mode: 0644]

index 28101d3..d4b71f6 100644 (file)
@@ -50,7 +50,7 @@ class admin_indexFrameContainer extends BaseFrameContainer
                                        $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET ||             // 表示位置を表示するとき(ウィジェット付き)
                                        $cmd == M3_REQUEST_CMD_SHOW_WIDGET ||           // ウィジェットの単体表示
                                        $cmd == M3_REQUEST_CMD_DO_WIDGET ||             // ウィジェット単体実行
-//                                     $cmd == M3_REQUEST_CMD_CONFIG_WIDGET ||         // ウィジェットの設定
+                                       $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE ||               // テンプレートの設定
                                        $cmd == M3_REQUEST_CMD_GET_WIDGET_INFO ||       // ウィジェット各種情報取得(AJAX用)
                                        $cmd == M3_REQUEST_CMD_SHOW_PHPINFO){   // phpinfoの表示
                        // 管理者権限がなければ実行できない
diff --git a/include/container/baseAdminTemplateContainer.php b/include/container/baseAdminTemplateContainer.php
new file mode 100644 (file)
index 0000000..ce29498
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+/**
+ * テンプレート管理画面コンテナ作成用ベースクラス
+ *
+ * テンプレートの管理画面を作成するためのベースクラス
+ *
+ * PHP versions 5
+ *
+ * LICENSE: This source file is licensed under the terms of the GNU General Public License.
+ *
+ * @package    Magic3 Framework
+ * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
+ * @copyright  Copyright 2006-2018 Magic3 Project.
+ * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
+ * @version    SVN: $Id$
+ * @link       http://www.magic3.org
+ */
+require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
+
+class BaseAdminTemplateContainer extends BaseAdminWidgetContainer
+{
+//     const DEFAULT_WIDGET_TYPE = 'admin';            // ウィジェットタイプ
+//     const TASK_CONFIG_LIST = 'list';                        // 設定一覧
+       
+       /**
+        * コンストラクタ
+        */
+       function __construct()
+       {
+               // 親クラスを呼び出す
+               parent::__construct();
+               
+               // データ初期化
+//             $this->_widgetType = self::DEFAULT_WIDGET_TYPE;                                         // ウィジェットタイプ
+       }
+       /**
+        * 出力用の変数に値を設定する
+        * このクラスでは、共通項目を設定
+        */
+       function __assign()
+       {
+
+       }
+       /**
+        * テンプレートファイルの設定
+        * 
+        * @param bool $useSystemTemplate               システムの標準テンプレートを使用するかどうか
+        * @return                                                              なし
+        */
+       function __setTemplate($useSystemTemplate = false)
+       {
+               // テンプレートオブジェクト作成
+               $this->tmpl = new PatTemplate();
+               // ##### テンプレート読み込みディレクトリ #####
+               $dirArray = array();
+
+               // テンプレート管理画面のテンプレートディレクトリを追加
+               $templateId = $this->gRequest->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID);// テンプレートID
+               $dir = $this->gEnv->getTemplatesPath() . '/' . $templateId . '/include/template';
+               if (file_exists($dir)) $dirArray[] = $dir;
+
+               $this->tmpl->setRoot($dirArray);
+               
+               // エラーメッセージテンプレートを埋め込む
+               $this->tmpl->applyInputFilter('ErrorMessage');
+               
+               // 機能付きタグを変換
+               //$this->tmpl->applyInputFilter('FunctionTag');
+               
+               // コメントを削除
+               //$this->tmpl->applyInputFilter('StripComments');
+               
+               // フォームチェック機能を使用するか、システム管理権限がある場合は、管理画面用パラメータを埋め込む
+//             if ($this->_useFormCheck || $gEnvManager->isSystemManageUser()) $this->tmpl->applyInputFilter('PostParam');
+               $this->tmpl->applyInputFilter('PostParam');
+       }
+}
+?>
index 5dbdfe9..2877eba 100644 (file)
@@ -357,6 +357,9 @@ class BaseFrameContainer extends Core
                        $createPage = false;            // ウィジェット単体処理モードに設定
                } else if ($cmd == M3_REQUEST_CMD_CSS){         // CSS生成
                
+               } else if ($cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE){             // テンプレートの設定
+                       $createPage = false;            // ウィジェット単体処理モードに設定
+                       $this->gPage->showWidget();     // ウィジェット表示
                } else if ($this->gEnv->isServerConnector()){           // サーバ接続の場合
                        $createPage = false;            // ウィジェット単体処理モードに設定
                }
@@ -565,6 +568,11 @@ class BaseFrameContainer extends Core
                                // 指定のウィジェットを実行
                                if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェット設定のとき
                                        $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/admin/' . M3_FILENAME_INDEX;             // 管理用画面
+                               } else if ($cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE){             // テンプレート設定の場合
+                                       $templateId = $request->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID);              // テンプレートIDを取得
+                                       
+                                       // テンプレート設定画面を取得
+                                       $widgetIndexFile = $this->gEnv->getTemplatesPath() . '/' . $templateId . '/admin/' . M3_FILENAME_INDEX;
                                } else {
                                        $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/' . M3_FILENAME_INDEX;
                                }
@@ -613,6 +621,7 @@ class BaseFrameContainer extends Core
                        
                        if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET ||               // ウィジェットの単体表示
                                $cmd == M3_REQUEST_CMD_CONFIG_WIDGET ||         // ウィジェット設定のとき
+                               $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE ||               // テンプレートの設定
                                ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy))){         // ウィンドウオープンタイプ指定でウィジェット単体実行のとき
                                
                                // 現在の出力内容を取得し、一旦内容をクリア
index 9f38f26..4cfc978 100644 (file)
@@ -401,6 +401,45 @@ class LaunchManager extends Core
                $this->_goDevice(2/*スマートフォン用*/, $filepath);
        }
        /**
+        * テンプレート管理画面を実行
+        *
+        * @param string $filepath              呼び出し元ファイルのフルパス。通常は「__FILE__」。OSによってパスの表現が違うので注意。
+        */
+       function goTemplate($filepath)
+       {
+               global $gEnvManager;
+               global $gRequestManager;
+
+               // 実行コマンドを取得
+               $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
+               
+               $templateId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID);// テンプレートID
+               
+               // ウィジェットの種別を設定
+               $gEnvManager->setIsSubWidget(false);                    // 通常ウィジェットで起動
+
+               // コンテナクラス名作成
+               if ($cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE){            // テンプレート設定のとき
+                       $containerClass = 'admin_' . $templateId . 'TemplateContainer';         // デフォルトで起動するコンテナクラス名「admin_ + テンプレートID + TemplateContainer」
+               }
+               
+               // コンテナクラス名修正
+               $containerClass = str_replace('/', '_', $containerClass);
+
+               // テンプレートのコンテナクラスファイルを読み込み
+               $containerPath = $this->gEnv->getTemplatesPath() . '/' . $templateId . '/include/container/' . $containerClass . '.php';
+               if (file_exists($containerPath)){
+                       require_once($containerPath);
+               } else {
+                       echo 'file not found error: ' . $containerPath;
+               }
+               // コンテナクラスを起動
+               $widgetContainer = new $containerClass();
+               $gEnvManager->setCurrentWidgetObj($widgetContainer);                            // 実行するウィジェットコンテナオブジェクトを登録
+               $widgetContainer->process($gRequestManager);
+               $gEnvManager->setCurrentWidgetObj(null);
+       }
+       /**
         * 各種デバイス用プログラムを実行
         *
         * @param int $type                             1=携帯用プログラム、2=スマートフォン用プログラム
diff --git a/templates/bootstrap4_custom/admin/index.php b/templates/bootstrap4_custom/admin/index.php
new file mode 100644 (file)
index 0000000..0ac6c7f
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+/**
+ * テンプレート管理画面呼び出し用ファイル
+ * index.php
+ *
+ * PHP versions 5
+ *
+ * LICENSE: This source file is licensed under the terms of the GNU General Public License.
+ *
+ * @package    Magic3 Framework
+ * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
+ * @copyright  Copyright 2006-2018 Magic3 Project.
+ * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
+ * @version    SVN: $Id$
+ * @link       http://www.magic3.org
+ */
+// 直接アクセスの防止
+defined('M3_SYSTEM') or die('Access error: Direct access denied.');
+
+// ウィジェット実行
+global $gLaunchManager;
+$gLaunchManager->goTemplate(__FILE__);
+?>
diff --git a/templates/bootstrap4_custom/include/container/admin_bootstrap4_customTemplateContainer.php b/templates/bootstrap4_custom/include/container/admin_bootstrap4_customTemplateContainer.php
new file mode 100644 (file)
index 0000000..0d9eb8d
--- /dev/null
@@ -0,0 +1,229 @@
+<?php
+/**
+ * コンテナクラス
+ *
+ * PHP versions 5
+ *
+ * LICENSE: This source file is licensed under the terms of the GNU General Public License.
+ *
+ * @package    Magic3 Framework
+ * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
+ * @copyright  Copyright 2006-2018 Magic3 Project.
+ * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
+ * @version    SVN: $Id$
+ * @link       http://www.magic3.org
+ */
+require_once($gEnvManager->getContainerPath() . '/baseAdminTemplateContainer.php');
+//require_once($gEnvManager->getCurrentWidgetDbPath() . '/admin_analyticsDb.php');
+
+class admin_bootstrap4_customTemplateContainer extends BaseAdminTemplateContainer
+{
+       private $db;    // DB接続オブジェクト
+       private $graphTypeArray;        // グラフタイプ
+       private $termTypeArray;         // 期間タイプ
+       private $graphType;                     // グラフ種別
+       private $path;                          // アクセスパス
+       private $termType;                              // 期間タイプ
+       const DEFAULT_ACCESS_PATH = 'index';            // デフォルトのアクセスパス(PC用アクセスポイント)
+       const ACCESS_PATH_ALL = '_all';                         // アクセスパスすべて選択
+       const DEFAULT_TERM_TYPE = '30day';              // デフォルトの期間タイプ
+       const TERM_TYPE_ALL = '_all';                           // 全データ表示選択
+       const DEFAULT_GRAPH_TYPE = 'pageview';          // デフォルトのグラフ種別
+       const DEFAULT_GRAPH_WIDTH = 800;                // グラフ幅
+       const DEFAULT_GRAPH_HEIGHT = 280;               // グラフ高さ
+       
+       /**
+        * コンストラクタ
+        */
+       function __construct()
+       {
+               // 親クラスを呼び出す
+               parent::__construct();
+               
+               // DBオブジェクト作成
+//             $this->db = new admin_analyticsDb();
+               
+               // グラフタイプ
+               $this->graphTypeArray = array(  array(  'name' => 'ページビュー', 'value' => 'pageview'),
+                                                                               array(  'name' => '訪問数',                  'value' => 'visit'),
+                                                                               array(  'name' => '訪問者数',               'value' => 'visitor'));
+                                                                               
+               // 期間タイプ
+               $this->termTypeArray = array(   array(  'name' => '10日',      'value' => '10day'),
+                                                                               array(  'name' => '30日',      'value' => '30day'),
+                                                                               array(  'name' => '3ヶ月',    'value' => '3month'),
+                                                                               array(  'name' => '6ヶ月',    'value' => '6month'),
+                                                                               array(  'name' => '1年',       'value' => '1year'),
+                                                                               array(  'name' => '2年',       'value' => '2year'),
+                                                                               array(  'name' => '3年',       'value' => '3year'),
+                                                                               array(  'name' => '5年',       'value' => '5year'),
+                                                                               array(  'name' => 'すべて',  'value' => self::TERM_TYPE_ALL));
+       }
+       /**
+        * テンプレートファイルを設定
+        *
+        * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
+        * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
+        *
+        * @param RequestManager $request               HTTPリクエスト処理クラス
+        * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
+        * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
+        */
+       function _setTemplate($request, &$param)
+       {       
+               return 'admin.tmpl.html';
+       }
+       /**
+        * テンプレートの後処理
+        *
+        * テンプレートのデータ埋め込み(_assign())の後に実行される。
+        *
+        * @param RequestManager $request               HTTPリクエスト処理クラス
+        * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
+        * @return                                                              なし
+        */
+       function _postAssign($request, &$param)
+       {
+               // メニューバー、パンくずリスト作成(簡易版)
+               $this->createBasicConfigMenubar($request);
+       }
+       /**
+        * テンプレートにデータ埋め込む
+        *
+        * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
+        *
+        * @param RequestManager $request               HTTPリクエスト処理クラス
+        * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
+        * @param                                                               なし
+        */
+       function _assign($request, &$param)
+       {
+               $act = $request->trimValueOf('act');
+               
+               // 入力値を取得
+               $this->path = $request->trimValueOf('item_path');               // アクセスパス
+               $this->termType = $request->trimValueOf('item_term');                           // 期間タイプ
+               $graphWidth = $request->trimValueOf('item_graph_width');                // グラフ幅
+               $graphHeight = $request->trimValueOf('item_graph_height');              // グラフ高さ
+               
+               $replaceNew = false;            // データを再取得するかどうか
+               if ($act == 'update'){          // 設定更新のとき
+                       // 入力チェック
+                       $this->checkNumeric($graphWidth, 'グラフ幅');
+                       $this->checkNumeric($graphHeight, 'グラフ高さ');
+                       
+                       if ($this->getMsgCount() == 0){                 // エラーのないとき
+                               $paramObj = new stdClass;
+                               $paramObj->path = $this->path;                          // アクセスパス
+                               $paramObj->termType = $this->termType;          // 期間タイプ
+                               $paramObj->graphWidth = $graphWidth;            // グラフ幅
+                               $paramObj->graphHeight = $graphHeight;          // グラフ高さ
+                               $ret = $this->updateWidgetParamObj($paramObj);
+                               if ($ret){
+                                       $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
+                                       $replaceNew = true;                     // データ再取得
+                               } else {
+                                       $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
+                               }
+                               $this->gPage->updateParentWindow();// 親ウィンドウを更新
+                       }
+               } else {                // 初期表示の場合
+                       $replaceNew = true;                     // データ再取得
+               }
+               
+               if ($replaceNew){               // データ再取得のとき
+                       $paramObj = $this->getWidgetParamObj();
+                       if (empty($paramObj)){          // 既存データなしのとき
+                               // デフォルト値設定
+                               $this->path = self::DEFAULT_ACCESS_PATH;
+                               $this->termType = self::DEFAULT_TERM_TYPE;
+                               $graphWidth = self::DEFAULT_GRAPH_WIDTH;                // グラフ幅
+                               $graphHeight = self::DEFAULT_GRAPH_HEIGHT;              // グラフ高さ
+                       } else {
+                               $this->path = $paramObj->path;                          // アクセスパス
+                               $this->termType = $paramObj->termType;          // 期間タイプ
+                               $graphWidth = $paramObj->graphWidth;            // グラフ幅
+                               $graphHeight = $paramObj->graphHeight;          // グラフ高さ
+                       }
+               }
+               
+               // アクセスポイントメニュー作成
+//             $this->createPathMenu();
+               
+               // 期間メニュー作成
+//             $this->createTermMenu();
+               
+               // 値を埋め込む
+               $this->tmpl->addVar("_widget", "graph_width", $graphWidth);// グラフ幅
+               $this->tmpl->addVar("_widget", "graph_height", $graphHeight);// グラフ高さ
+       }
+       /**
+        * アクセスパスメニュー作成
+        *
+        * @return                                                              なし
+        */
+       function createPathMenu()
+       {
+               $selected = '';
+               if ($this->path == self::ACCESS_PATH_ALL){// アクセスパスすべて選択
+                       $selected = 'selected';
+               }
+               $row = array(
+                       'value'    => self::ACCESS_PATH_ALL,                    // アクセスパス
+                       'name'     => 'すべて表示',                        // 表示文字列
+                       'selected' => $selected                                                                                                         // 選択中かどうか
+               );
+               $this->tmpl->addVars('path_list', $row);
+               $this->tmpl->parseTemplate('path_list', 'a');
+               
+               $this->db->getPageIdList(array($this, 'pageIdLoop'), 0/*ページID*/);
+       }
+       /**
+        * ページID、取得したデータをテンプレートに設定する
+        *
+        * @param int $index                    行番号(0~)
+        * @param array $fetchedRow             フェッチ取得した行
+        * @param object $param                 未使用
+        * @return bool                                 true=処理続行の場合、false=処理終了の場合
+        */
+       function pageIdLoop($index, $fetchedRow, $param)
+       {
+               $selected = '';
+               if ($fetchedRow['pg_path'] == $this->path){
+                       $selected = 'selected';
+               }
+               $name = $this->convertToDispString($fetchedRow['pg_path']) . ' - ' . $this->convertToDispString($fetchedRow['pg_name']);                        // ページ名
+               $row = array(
+                       'value'    => $this->convertToDispString($fetchedRow['pg_path']),                       // アクセスパス
+                       'name'     => $name,                    // ページ名
+                       'selected' => $selected                                                                                                         // 選択中かどうか
+               );
+               $this->tmpl->addVars('path_list', $row);
+               $this->tmpl->parseTemplate('path_list', 'a');
+               return true;
+       }
+       /**
+        * 期間タイプ選択メニュー作成
+        *
+        * @return なし
+        */
+       function createTermMenu()
+       {
+               for ($i = 0; $i < count($this->termTypeArray); $i++){
+                       $value = $this->termTypeArray[$i]['value'];
+                       $name = $this->termTypeArray[$i]['name'];
+                       
+                       $selected = '';
+                       if ($value == $this->termType) $selected = 'selected';
+                       
+                       $row = array(
+                               'value'    => $value,                   // ページID
+                               'name'     => $name,                    // ページ名
+                               'selected' => $selected                                                                                                         // 選択中かどうか
+                       );
+                       $this->tmpl->addVars('term_list', $row);
+                       $this->tmpl->parseTemplate('term_list', 'a');
+               }
+       }
+}
+?>
diff --git a/templates/bootstrap4_custom/include/template/admin.tmpl.html b/templates/bootstrap4_custom/include/template/admin.tmpl.html
new file mode 100644 (file)
index 0000000..94d99a3
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * 表示データ作成用テンプレート(patTemplate)
+ *
+ * LICENSE: This source file is licensed under the terms of the GNU General Public License.
+ *
+ * @package    Magic3 Framework
+ * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
+ * @copyright  Copyright 2006-2015 Magic3 Project.
+ * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
+ * @version    SVN: $Id$
+ * @link       http://www.magic3.org
+ */
+<patTemplate:tmpl name="_widget">
+<script type="text/javascript">
+//<![CDATA[
+function updateItem(){
+       if (!window.confirm('設定を更新しますか?')) return false;
+       document.main.act.value='update';
+       document.main.submit();
+       return true;
+}
+$(function(){
+       m3SetConfigTable('mainconfig');
+});
+//]]>
+</script>
+<div class="m3config_container">
+<!-- m3:ErrorMessage -->
+<form method="post" name="main" class="form">
+<input type="hidden" name="act" />
+<h3 class="m3config_h">基本設定</h3>
+<table id="mainconfig">
+    <tbody>
+    <tr>
+           <th>アクセスポイント</th>
+               <td>
+           <div class="m3config_item col-sm-6"><select name="item_path" class="form-control">
+            <patTemplate:tmpl name="path_list">
+            <option value="{VALUE}" {SELECTED}>{NAME}</option>
+            </patTemplate:tmpl>
+            </select></div>
+               </td>
+       </tr>
+    <tr>
+           <th>期間</th>
+               <td>
+            <div class="m3config_item col-sm-2"><select name="item_term" class="form-control">
+            <patTemplate:tmpl name="term_list">
+            <option value="{VALUE}" {SELECTED}>{NAME}</option>
+            </patTemplate:tmpl>
+            </select></div>
+               </td>
+       </tr>
+    <tr>
+           <th>グラフサイズ</th>
+           <td><div class="form-control-static m3config_item col-sm-1">幅:</div><div class="m3config_item col-sm-2"><input type="text" name="item_graph_width" class="form-control" value="{GRAPH_WIDTH}" size="4" maxlength="4" onkeypress="return m3_numericKey(event,true);" /></div><div class="form-control-static m3config_item col-sm-2">px</div>
+           <div class="form-control-static m3config_item col-sm-1">高さ:</div><div class="m3config_item col-sm-2"><input type="text" name="item_graph_height" class="form-control" value="{GRAPH_HEIGHT}" size="4" maxlength="4" onkeypress="return m3_numericKey(event,true);" /></div><div class="form-control-static m3config_item col-sm-2">px</div>
+               </td>
+       </tr>
+    </tbody>
+</table>
+<div class="well m3config_update_buttons">
+<input type="button" class="button" onclick="updateItem();" value="更新" />
+</div>
+</form>
+</div>
+</patTemplate:tmpl>