OSDN Git Service

3a4080bf8cf2c20b9d6fbf3516cde44ba97e46f1
[magic3/magic3.git] / widgets / default_content / include / container / admin_default_contentContentWidgetContainer.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-2018 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id$
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getWidgetContainerPath('default_content') . '/admin_default_contentBaseWidgetContainer.php');
17 require_once($gEnvManager->getLibPath()                 . '/qqFileUploader/fileuploader.php');
18 require_once($gEnvManager->getCommonPath() . '/valueCheck.php');
19
20 class admin_default_contentContentWidgetContainer extends admin_default_contentBaseWidgetContainer
21 {
22         private $serialNo;              // 選択中の項目のシリアル番号
23         private $serialArray = array();         // 表示されているコンテンツシリアル番号
24         private $selectedItem = array();        // 選択中の項目
25         private $attachFileInfoArray;           // 添付ファイルの情報
26         private $fieldValueArray;               // ユーザ定義フィールド入力値
27         private $completed;                     // データ登録完了かどうか
28         private $isExistsContent;               // コンテンツ項目が存在するかどうか
29         private $isMultiLang;                   // 多言語対応画面かどうか
30         private $isOpenOptionArea;              // 拡張エリアを開くかどうか
31         private $pluginIdArray = array();               // jQueryプラグインのID
32         private $selectedPlugin = array();                      // 選択しているjQueryプラグイン
33         private $addLib = array();              // 追加スクリプトライブラリ
34         private $templateId;    // テンプレートID
35         private $subTemplateId; // サブテンプレートID
36         private $subTemplateInfo;               // サブテンプレート情報
37         private $isExistsSubTemplate;           // サブテンプレートが存在するかどうか
38         const ICON_SIZE = 32;           // アイコンのサイズ
39         const PANEL_BUTTON_SIZE = 32;   // 拡張エリア制御ボタンサイズ
40         const INC_INDEX = 1;            // メニュー項目表示順の増加分
41         const ADMIN_WIDGET_ID = 'admin_main';           // 管理ウィジェットのウィジェットID
42         const CALENDAR_ICON_FILE = '/images/system/calendar.png';               // カレンダーアイコン
43         const ACTIVE_ICON_FILE = '/images/system/active32.png';                 // 公開中アイコン
44         const INACTIVE_ICON_FILE = '/images/system/inactive32.png';             // 非公開アイコン
45         const ADD_TO_MENU_ICON_FILE = '/images/system/addtomenu32.png';         // メニューに追加用アイコン
46         const PREVIEW_ICON_FILE = '/images/system/window32.png';                // プレビュー用アイコン
47         const OPEN_PANEL_ICON_FILE = '/images/system/plus32.png';               // 拡張エリア表示用アイコン
48         const CLOSE_PANEL_ICON_FILE = '/images/system/minus32.png';             // 拡張エリア非表示用アイコン
49         const DELETE_ICON_FILE = '/images/system/delete32.png';         // 行削除用アイコン
50         const LANG_ICON_PATH = '/images/system/flag/';          // 言語アイコンパス
51         const MSG_UPDATE_CONTENT = 'コンテンツを更新しました';                      // コンテンツ更新メッセージ
52         const DEFAULT_SEARCH_KEY = '1';                 // デフォルトの検索キー(更新日時)
53         const DEFAULT_SEARCH_ORDER = '1';                       // デフォルトの検索ソート順(降順)
54         const DEFAULT_LIST_COUNT = 20;                  // 最大リスト表示数
55         const LINK_PAGE_COUNT           = 20;                   // リンクページ数
56         const DEFAULT_PASSWORD = '********';    // 設定済みを示すパスワード
57         const LOG_MSG_ADD_CONTENT = '汎用コンテンツ(%s)を追加しました。タイトル: %s';
58         const LOG_MSG_UPDATE_CONTENT = '汎用コンテンツ(%s)を更新しました。タイトル: %s';
59         const LOG_MSG_DEL_CONTENT = '汎用コンテンツ(%s)を削除しました。タイトル: %s';
60         const FIELD_HEAD = 'item_';                     // フィールド名の先頭文字列
61         const LIB_ITEM_HEAD = 'item_lib_';                      // 選択ライブラリの項目名ヘッダ
62         const LIB_CODEMIRROR_JAVASCRIPT = 'codemirror.javascript';              // CodeMirror Javascript
63         const TAG_ID_ACTIVE_TERM = 'activeterm_button';         // 公開期間エリア表示用ボタンタグ
64         const TOOLTIP_ACTIVE_TERM = '公開期間を設定';            // 公開期間エリア表示用ボタンツールチップ
65         const CHANGE_URL_TAG_ID = 'changeurl';                  // URL変更ボタンタグID
66         
67         /**
68          * コンストラクタ
69          */
70         function __construct()
71         {
72                 // 親クラスを呼び出す
73                 parent::__construct();
74                 
75                 $this->isMultiLang = $this->gEnv->isMultiLanguageSite();                        // 多言語対応画面かどうか
76         }
77         /**
78          * テンプレートファイルを設定
79          *
80          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
81          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
82          *
83          * @param RequestManager $request               HTTPリクエスト処理クラス
84          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
85          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
86          */
87         function _setTemplate($request, &$param)
88         {
89                 $filename = '';
90                 $task = $request->trimValueOf('task');
91                 switch ($task){
92                         case self::TASK_CONTENT:                // コンテンツ管理
93                         default:
94                                 $filename = 'admin.tmpl.html';
95                                 break;
96                         case self::TASK_CONTENT_DETAIL:         // 詳細画面
97                                 $filename = 'admin_detail.tmpl.html';
98                                 break;
99                 }
100                 return $filename;
101         }
102         /**
103          * テンプレートにデータ埋め込む
104          *
105          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
106          *
107          * @param RequestManager $request               HTTPリクエスト処理クラス
108          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
109          * @return                                                              なし
110          */
111         function _assign($request, &$param)
112         {
113                 $task = $request->trimValueOf('task');
114                 switch ($task){
115                         case self::TASK_CONTENT:                // コンテンツ管理
116                         default:
117                                 $this->createList($request);
118                                 break;
119                         case self::TASK_CONTENT_DETAIL:         // 詳細画面
120                                 $this->createDetail($request);
121                                 break;
122                 }
123         }
124         /**
125          * コンテンツ一覧画面作成
126          *
127          * @param RequestManager $request               HTTPリクエスト処理クラス
128          * @param                                                               なし
129          */
130         function createList($request)
131         {
132                 // ユーザ情報、表示言語
133                 $userId = $this->gEnv->getCurrentUserId();
134                 $this->langId = $this->gEnv->getDefaultLanguage();
135                 
136                 // 一覧表示数
137                 $maxListCount = self::DEFAULT_LIST_COUNT;
138                 
139                 // ##### 検索条件 #####
140                 $pageNo = $request->trimIntValueOf(M3_REQUEST_PARAM_PAGE_NO, '1');                              // ページ番号
141                 $searchKeyword = $request->trimValueOf('search_keyword');                       // 検索キーワード
142                 $searchKey = $request->trimValueOf('search_key');                       // 検索ソートキー
143                 if ($searchKey == '') $searchKey = self::DEFAULT_SEARCH_KEY;
144                 $searchOrder = $request->trimValueOf('search_order');                   // 検索ソート順
145                 if ($searchOrder == '') $searchOrder = self::DEFAULT_SEARCH_ORDER;
146
147                 $act = $request->trimValueOf('act');
148                 if ($act == 'delete'){          // 項目削除の場合
149                         $listedItem = explode(',', $request->trimValueOf('seriallist'));
150                         $delItems = array();
151                         for ($i = 0; $i < count($listedItem); $i++){
152                                 // 項目がチェックされているかを取得
153                                 $itemName = 'item' . $i . '_selected';
154                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
155                                 
156                                 if ($itemValue){                // チェック項目
157                                         $delItems[] = $listedItem[$i];
158                                 }
159                         }
160                         if (count($delItems) > 0){
161                                 // 削除するコンテンツの情報を取得
162                                 $delContentInfo = array();
163                                 for ($i = 0; $i < count($delItems); $i++){
164                                         $ret = self::$_mainDb->getContentBySerial($delItems[$i], $row);
165                                         if ($ret){
166                                                 $newInfoObj = new stdClass;
167                                                 $newInfoObj->contentId = $row['cn_id'];         // コンテンツID
168                                                 $newInfoObj->name = $row['cn_name'];            // コンテンツ名前
169                                                 $newInfoObj->thumb = $row['cn_thumb_filename'];         // サムネール
170                                                 $delContentInfo[] = $newInfoObj;
171                                         }
172                                 }
173                                 
174                                 // 多言語対応状態に関わらずコンテンツIDで削除
175                                 //if ($this->isMultiLang){              // 多言語対応のとき
176                                         $ret = self::$_mainDb->delContentItemById($delItems);
177                                 //} else {
178                                 //      $ret = self::$_mainDb->delContentItem($delItems);
179                                 //}
180                                 
181                                 if ($ret){
182                                         for ($i = 0; $i < count($delContentInfo); $i++){
183                                                 $infoObj = $delContentInfo[$i];
184                                                 
185                                                 // サムネールを削除
186                                                 if (!empty($infoObj->thumb)){
187                                                         $oldFiles = explode(';', $infoObj->thumb);
188                                                         $this->gInstance->getImageManager()->delSystemDefaultThumb(M3_VIEW_TYPE_CONTENT, default_contentCommonDef::$_deviceType, $oldFiles);
189                                                 }
190                                                 
191                                                 // 添付ファイルをコンテンツIDで削除
192                                                 $ret = $this->gInstance->getFileManager()->delAttachFileInfoByContentId(default_contentCommonDef::$_viewContentType,
193                                                                                                                                                                                                 $infoObj->contentId, default_contentCommonDef::getAttachFileDir());
194                                                 if (!$ret) break;
195                                         }
196                                 }
197
198                                 if ($ret){              // データ削除成功のとき
199                                         // ##### アクセスキー情報を削除 #####
200                                         for ($i = 0; $i < count($delContentInfo); $i++){
201                                                 $infoObj = $delContentInfo[$i];
202                                                 $this->gAccess->unegistAllSessionAccessKey($infoObj->contentId);                // 一旦すべて削除
203                                         }
204                                         
205                                         $this->setGuidanceMsg('データを削除しました');
206                                         
207                                         // キャッシュデータのクリア
208                                         for ($i = 0; $i < count($delItems); $i++){
209                                                 $this->clearCacheBySerial($delItems[$i]);
210                                         }
211                                         
212                                         // 運用ログを残す
213                                         for ($i = 0; $i < count($delContentInfo); $i++){
214                                                 $infoObj = $delContentInfo[$i];
215                                                 $contentAttr = default_contentCommonDef::$_deviceTypeName;
216                                                 //$this->gOpeLog->writeUserInfo(__METHOD__, sprintf(self::LOG_MSG_DEL_CONTENT, $contentAttr, $infoObj->name), 2100, 'ID=' . $infoObj->contentId);
217                                                 $eventParam = array(    M3_EVENT_HOOK_PARAM_CONTENT_TYPE        => M3_VIEW_TYPE_CONTENT,
218                                                                                                 M3_EVENT_HOOK_PARAM_CONTENT_ID          => $infoObj->contentId,
219                                                                                                 M3_EVENT_HOOK_PARAM_UPDATE_DT           => date("Y/m/d H:i:s"));
220                                                 $this->writeUserInfoEvent(__METHOD__, sprintf(self::LOG_MSG_DEL_CONTENT, $contentAttr, $infoObj->name), 2402, 'ID=' . $infoObj->contentId, $eventParam);
221                                         }
222                                 } else {
223                                         $this->setAppErrorMsg('データ削除に失敗しました');
224                                 }
225                         }
226                 } else if ($act == 'search'){           // 検索のとき
227                         $pageNo = 1;            // ページ番号初期化
228                 } else if ($act == 'selpage'){                  // ページ選択
229                 }
230                 // コンテンツ総数を取得
231                 $totalCount = self::$_mainDb->getContentCount(default_contentCommonDef::$_contentType, $this->langId, $searchKeyword, $searchKey, $searchOrder);
232                 
233                 // ページング計算
234                 $this->calcPageLink($pageNo, $totalCount, $maxListCount);
235
236                 // ページングリンク作成
237                 $currentBaseUrl = '';           // POST用のリンク作成
238                 $pageLink = $this->createPageLink($pageNo, self::LINK_PAGE_COUNT, $currentBaseUrl, 'selpage($1);return false;');
239                 
240                 // 一覧の表示タイプを設定
241                 if ($this->isMultiLang){                // 多言語対応の場合
242                         $this->tmpl->setAttribute('show_multilang', 'visibility', 'visible');
243                 } else {
244                         $this->tmpl->setAttribute('show_singlelang', 'visibility', 'visible');
245                 }
246                 
247                 // コンテンツリストを取得
248                 self::$_mainDb->searchContent(default_contentCommonDef::$_contentType, $this->langId, $maxListCount, $pageNo, $searchKeyword, $searchKey, $searchOrder, array($this, 'itemListLoop'));
249                 if (!$this->isExistsContent) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');// コンテンツ項目がないときは、一覧を表示しない
250                 
251                 // 画面にデータを埋め込む
252                 // 検索条件
253                 if (empty($searchKey)){                 // コンテンツIDをキーにする場合
254                         $this->tmpl->addVar('_widget', 'search_content_id_checked', 'checked');
255                 } else {
256                         $this->tmpl->addVar('_widget', 'search_update_dt_checked', 'checked');
257                 }
258                 if (empty($searchOrder)){                       // 昇順にソートするとき
259                         $this->tmpl->addVar('_widget', 'search_asc_checked', 'checked');
260                 } else {
261                         $this->tmpl->addVar('_widget', 'search_desc_checked', 'checked');
262                 }
263                 
264                 // 検索条件
265                 $this->tmpl->addVar("_widget", "page", $pageNo);        // ページ番号
266                 $this->tmpl->addVar("_widget", "page_link", $pageLink);
267                 $this->tmpl->addVar("_widget", "total_count", $totalCount);
268                 $this->tmpl->addVar("_widget", "search_keyword", $searchKeyword);       // 検索キーワード
269                                 
270                 // その他
271                 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
272                 $this->tmpl->addVar("_widget", "target_widget", $this->gEnv->getCurrentWidgetId());// メニュー選択ウィンドウ表示用
273                 $this->tmpl->addVar("_widget", "device_type", default_contentCommonDef::$_deviceType);          // デバイスタイプ
274         }
275         /**
276          * コンテンツ詳細画面作成
277          *
278          * @param RequestManager $request               HTTPリクエスト処理クラス
279          * @param                                                               なし
280          */
281         function createDetail($request)
282         {
283                 // ユーザ情報、表示言語
284                 $this->langId = $this->gEnv->getDefaultLanguage();
285                 
286                 // ウィンドウ表示状態
287                 $openby = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);
288                 
289                 // 言語を取得
290                 if ($this->isMultiLang){                // 多言語対応の場合
291                         $langId = $request->trimValueOf('item_lang');                           // 現在メニューで選択中の言語
292                         if (!empty($langId)) $this->langId = $langId;
293                 }
294                 // コンテンツレイアウトを取得
295                 $contentLayout = self::$_configArray[default_contentCommonDef::$CF_LAYOUT_VIEW_DETAIL];
296                 $fieldInfoArray = default_contentCommonDef::parseUserMacro($contentLayout);
297
298                 // jQueryプラグインのIDを取得
299                 $useJQuery = self::$_configArray[default_contentCommonDef::$CF_USE_JQUERY];             // jQueryスクリプト作成するかどうか
300                 if ($useJQuery){                // jQueryスクリプト作成機能を使用する場合
301                         $this->pluginIdArray = $this->gPage->getScriptLibId(2/*jQueryプラグインのみ*/);
302                         
303                         $pluginCount = count($this->pluginIdArray);
304                         for ($i = 0; $i < $pluginCount; $i++){
305                                 $itemPluginId = str_replace('.', '_', $this->pluginIdArray[$i]);
306                                 $itemName = self::LIB_ITEM_HEAD . $itemPluginId;
307                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
308                                 if ($itemValue) $this->selectedPlugin[] = $this->pluginIdArray[$i];
309                         }
310                 }
311                 $useContentTemplate = self::$_configArray[default_contentCommonDef::$CF_USE_CONTENT_TEMPLATE];// コンテンツ単位のテンプレート設定を行うかどうか
312                 
313                 // 入力値を取得
314                 $act = $request->trimValueOf('act');
315                 $this->serialNo = $request->trimValueOf('serial');              // 選択項目のシリアル番号
316                 $contentId = $request->trimValueOf('contentid');                // コンテンツID
317                 $name = $request->trimValueOf('item_name');
318                 $html = $request->valueOf('item_html');         // HTMLタグを可能とする
319                 $desc = $request->trimValueOf('item_desc');             // 簡易説明
320                 $key = $request->trimValueOf('item_key');               // 外部参照用キー
321                 $visible = ($request->trimValueOf('item_visible') == 'on') ? 1 : 0;             // チェックボックス
322                 $limited = ($request->trimValueOf('item_limited') == 'on') ? 1 : 0;             // チェックボックス
323 //              $default = ($request->trimValueOf('item_default') == 'on') ? 1 : 0;             // チェックボックス
324                 $searchTarget = $request->trimCheckedValueOf('item_search_target');             // 検索対象かどうか
325                 $metaTitle = $request->trimValueOf('item_meta_title');          // ページタイトル名
326                 $metaDesc = $request->trimValueOf('item_meta_desc');                    // ページ要約
327                 $metaKeyword = $request->trimValueOf('item_meta_keyword');      // ページキーワード
328                 $headOthers = $request->valueOf('item_head_others');    // ヘッダ部その他
329                 $password = $request->trimValueOf('password');
330                 $relatedContent = $request->trimValueOf('item_related_content');        // 関連コンテンツ
331                 $jQueryScript = $request->valueOf('item_jquery_script');        // jQueryスクリプト
332                 $this->templateId       = $request->trimValueOf('templateid');  // テンプレートID
333                 $this->subTemplateId = $request->trimValueOf('subtemplateid');  // サブテンプレートID
334                 $accessKey = $request->trimValueOf('item_access_key');          // アクセスキー
335                 $accessUrl = $request->trimValueOf('item_access_url');          // アクセスキー取得用URL
336                 $accessUrl = str_replace($this->gEnv->getRootUrl(), M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $accessUrl);// マクロ変換
337                 
338                 $start_date = $request->trimValueOf('item_start_date');         // 公開期間開始日付
339                 if (!empty($start_date)) $start_date = $this->convertToProperDate($start_date);
340                 $start_time = $request->trimValueOf('item_start_time');         // 公開期間開始時間
341                 if (empty($start_date)){
342                         $start_time = '';                                       // 日付が空のときは時刻も空に設定する
343                 } else {
344                         if (empty($start_time)) $start_time = '00:00';          // 日付が入っているときは時間にデフォルト値を設定
345                 }
346                 if (!empty($start_time)) $start_time = $this->convertToProperTime($start_time, 1/*時分フォーマット*/);
347                 
348                 $end_date = $request->trimValueOf('item_end_date');             // 公開期間終了日付
349                 if (!empty($end_date)) $end_date = $this->convertToProperDate($end_date);
350                 $end_time = $request->trimValueOf('item_end_time');             // 公開期間終了時間
351                 if (empty($end_date)){
352                         $end_time = '';                                 // 日付が空のときは時刻も空に設定する
353                 } else {
354                         if (empty($end_time)) $end_time = '00:00';              // 日付が入っているときは時間にデフォルト値を設定
355                 }
356                 if (!empty($end_time)) $end_time = $this->convertToProperTime($end_time, 1/*時分フォーマット*/);
357                 
358                 // ユーザ定義フィールド入力値取得
359                 $this->fieldValueArray = array();               // ユーザ定義フィールド入力値
360                 $fieldKeys = array_keys($fieldInfoArray);
361                 for ($i = 0; $i < count($fieldKeys); $i++){
362                         $fieldKey = $fieldKeys[$i];
363                         $itemName = self::FIELD_HEAD . $fieldKey;
364                         $itemValue = $this->cleanMacroValue($request->trimValueOf($itemName));
365                         if (!empty($itemValue)) $this->fieldValueArray[$fieldKey] = $itemValue;
366                 }
367                 
368                 // 添付ファイルリスト取得
369                 $attachFileCount = $request->trimValueOf('attachfilecount');            // 添付ファイル数
370                 $fileTitles     = $request->trimValueOf('item_filetitle');              // 添付ファイルタイトル
371                 $filenames      = $request->trimValueOf('item_filename');               // 添付ファイルファイル名
372                 $fileIds        = $request->trimValueOf('item_fileid');         // 添付ファイルファイルID
373                 $this->attachFileInfoArray = array();
374                 for ($i = 0; $i < $attachFileCount; $i++){
375                         $newInfoObj = new stdClass;
376                         $newInfoObj->title              = $fileTitles[$i];
377                         $newInfoObj->filename   = $filenames[$i];
378                         $newInfoObj->fileId             = $fileIds[$i];
379                         $this->attachFileInfoArray[] = $newInfoObj;
380                 }
381
382                 $reloadData = false;            // データの再読み込み
383                 $hasPassword = false;           // パスワードが設定されているかどうか
384                 $historyIndex = -1;     // 履歴番号(旧データの場合のみ有効)
385                 if ($act == 'new'){
386                         $this->serialNo = 0;
387                         $reloadData = true;             // データの再読み込み
388                 } else if ($act == 'add'){              // 項目追加の場合。多言語対応の場合はデフォルト言語が最初に追加される。
389                         // 入力チェック
390                         $this->checkInput($name, '名前');
391
392                         // 期間範囲のチェック
393                         if (!empty($start_date) && !empty($end_date)){
394                                 if (strtotime($start_date . ' ' . $start_time) >= strtotime($end_date . ' ' . $end_time)) $this->setUserErrorMsg('公開期間が不正です');
395                         }
396                         
397                         // 関連コンテンツのチェック
398                         if (!empty($relatedContent)){
399                                 $contentIdArray = explode(',', $relatedContent);
400                                 if (!ValueCheck::isNumeric($contentIdArray)) $this->setUserErrorMsg('関連コンテンツにエラー値があります');// すべて数値であるかチェック
401                         }
402                         
403                         // アクセスキーのチェック
404                         $this->checkSingleByte($accessKey, 'アクセスキー', true);
405                         
406                         // エラーなしの場合は、データを登録
407                         if ($this->getMsgCount() == 0){
408                                 // 保存データ作成
409                                 if (empty($start_date)){
410                                         $startDt = $this->gEnv->getInitValueOfTimestamp();
411                                 } else {
412                                         $startDt = $start_date . ' ' . $start_time;
413                                 }
414                                 if (empty($end_date)){
415                                         $endDt = $this->gEnv->getInitValueOfTimestamp();
416                                 } else {
417                                         $endDt = $end_date . ' ' . $end_time;
418                                 }
419
420                                 // サムネール画像を取得
421                                 $thumbFilename = '';
422                                 if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){         // // 多言語対応の場合はデフォルト言語が選択されている場合のみ処理を行う
423                                         // 次のコンテンツIDを取得
424                                         $nextContentId = self::$_mainDb->getNextContentId(default_contentCommonDef::$_contentType);
425                                 
426                                         $thumbPath = $this->gInstance->getImageManager()->getFirstImagePath($html);
427                                         if (!empty($thumbPath)){
428                                                 $ret = $this->gInstance->getImageManager()->createSystemDefaultThumb(M3_VIEW_TYPE_CONTENT, default_contentCommonDef::$_deviceType, $nextContentId, $thumbPath, $destFilename);
429                                                 if ($ret) $thumbFilename = implode(';', $destFilename);
430                                         }
431                                 }
432                                 
433                                 // 追加パラメータ
434                                 $otherParams =  array(  'cn_thumb_filename'             => $thumbFilename,              // サムネールファイル名
435                                                                                 'cn_related_content'    => $relatedContent,             // 関連コンテンツ
436                                                                                 'cn_option_fields'              => $this->serializeArray($this->fieldValueArray),               // ユーザ定義フィールド値
437                                                                                 'cn_script'                             => $jQueryScript,       // jQueryスクリプト
438                                                                                 'cn_script_lib'                 => implode(',', $this->selectedPlugin),// jQueryプラグイン
439                                                                                 'cn_template_id'                => $this->templateId,           // テンプレートID
440                                                                                 'cn_sub_template_id'    => $this->subTemplateId,        // サブテンプレートID
441                                                                                 'cn_attach_access_key'  => $accessKey,          // アクセスキー
442                                                                                 'cn_attach_access_url'  => $accessUrl,          // アクセスキー取得用URL
443                                                                                 'cn_search_target'              => $searchTarget        // 検索対象かどうか
444                                                                 );
445                                 
446                                 if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){         // 多言語でデフォルト言語、または単一言語のとき
447                                         $ret = self::$_mainDb->addContentItem(default_contentCommonDef::$_contentType, $nextContentId * (-1)/*次のコンテンツIDのチェック*/,
448                                                                                                                 $this->langId, $name, $desc, $html, $visible, 0/*未使用(デフォルトかどうか)*/, $limited, $key, $password, 
449                                                                                                                 $metaTitle, $metaDesc, $metaKeyword, $headOthers, $startDt, $endDt, $newSerial, $otherParams);
450                                 } else {
451                                         $ret = self::$_mainDb->addContentItem(default_contentCommonDef::$_contentType, $contentId, 
452                                                                                                                 $this->langId, $name, $desc, $html, $visible, 0/*未使用(デフォルトかどうか)*/, $limited, $key, $password, 
453                                                                                                                 $metaTitle, $metaDesc, $metaKeyword, $headOthers, $startDt, $endDt, $newSerial, $otherParams);
454                                 }
455                                 // ##### 添付ファイル情報を更新 #####
456                                 if ($ret){
457                                         $ret = self::$_mainDb->getContentBySerial($newSerial, $row);
458                                         if ($ret){
459                                                 $contentId = $row['cn_id'];             // コンテンツID
460                                                 $name = $row['cn_name'];                // コンテンツ名前
461                                                 $updateDt = $row['cn_create_dt'];               // コンテンツ作成日時
462                                                 $attachFileDir = default_contentCommonDef::getAttachFileDir();
463                                         
464                                                 $ret = $this->gInstance->getFileManager()->updateAttachFileInfo(default_contentCommonDef::$_viewContentType, $contentId, 0, $newSerial,
465                                                                                                                                                                                                                                                         $this->attachFileInfoArray, $attachFileDir);
466                                         }
467                                 }
468
469                                 if ($ret){
470                                         // ##### アクセスキー情報を登録 #####
471                                         $this->gAccess->unegistAllSessionAccessKey($contentId);         // 一旦すべて削除
472                                         if (!empty($accessKey)) $this->gAccess->registSessionAccessKey($accessKey, $contentId, 0/*参照*/);
473                                         
474                                         $this->setGuidanceMsg('データを追加しました');
475                                         
476                                         // シリアル番号更新
477                                         $this->serialNo = $newSerial;
478                                         $reloadData = true;             // データの再読み込み
479                                         
480                                         // 親ウィンドウを更新
481                                         $this->gPage->updateParentWindow($this->serialNo);
482                                         
483                                         // コンテンツ更新情報をサーバへ登録
484                                         $ret = $this->registContentInfoBySerial($this->serialNo, true/*新規*/);
485                                         if ($ret) $this->setGuidanceMsg('更新情報をサーバへアップしました');
486                                         
487                                         // 運用ログを残す
488                                         $contentAttr = default_contentCommonDef::$_deviceTypeName;
489                                         if ($this->isMultiLang) $contentAttr .= $this->getLangName($this->langId);              // 多言語対応の場合
490                                         //$this->gOpeLog->writeUserInfo(__METHOD__, sprintf(self::LOG_MSG_ADD_CONTENT, $contentAttr, $name), 2100, 'ID=' . $contentId);
491                                         $eventParam = array(    M3_EVENT_HOOK_PARAM_CONTENT_TYPE        => M3_VIEW_TYPE_CONTENT,
492                                                                                         M3_EVENT_HOOK_PARAM_CONTENT_ID          => $contentId,
493                                                                                         M3_EVENT_HOOK_PARAM_UPDATE_DT           => $updateDt);
494                                         $this->writeUserInfoEvent(__METHOD__, sprintf(self::LOG_MSG_ADD_CONTENT, $contentAttr, $name), 2400, 'ID=' . $contentId, $eventParam);
495                                 } else {
496                                         $this->setAppErrorMsg('データ追加に失敗しました');
497                                 }
498                         }
499                 } else if ($act == 'update'){           // 項目更新の場合
500                         // 入力チェック
501                         $this->checkInput($name, '名前');
502                         
503                         // 期間範囲のチェック
504                         if (!empty($start_date) && !empty($end_date)){
505                                 if (strtotime($start_date . ' ' . $start_time) >= strtotime($end_date . ' ' . $end_time)) $this->setUserErrorMsg('公開期間が不正です');
506                         }
507                         
508                         // 関連コンテンツのチェック
509                         if (!empty($relatedContent)){
510                                 $contentIdArray = explode(',', $relatedContent);
511                                 if (!ValueCheck::isNumeric($contentIdArray)) $this->setUserErrorMsg('関連コンテンツにエラー値があります');// すべて数値であるかチェック
512                         }
513                         
514                         // アクセスキーのチェック
515                         $this->checkSingleByte($accessKey, 'アクセスキー', true);
516                         
517                         // エラーなしの場合は、データを更新
518                         if ($this->getMsgCount() == 0){
519                                 // 保存データ作成
520                                 if (empty($start_date)){
521                                         $startDt = $this->gEnv->getInitValueOfTimestamp();
522                                 } else {
523                                         $startDt = $start_date . ' ' . $start_time;
524                                 }
525                                 if (empty($end_date)){
526                                         $endDt = $this->gEnv->getInitValueOfTimestamp();
527                                 } else {
528                                         $endDt = $end_date . ' ' . $end_time;
529                                 }
530                                 
531                                 // サムネール画像を取得
532                                 $thumbFilename = '';
533                                 if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){         // // 多言語対応の場合はデフォルト言語が選択されている場合のみ処理を行う
534                                         $thumbPath = $this->gInstance->getImageManager()->getFirstImagePath($html);
535                                         if (!empty($thumbPath)){
536                                                 $ret = $this->gInstance->getImageManager()->createSystemDefaultThumb(M3_VIEW_TYPE_CONTENT, default_contentCommonDef::$_deviceType, $contentId, $thumbPath, $destFilename);
537                                                 if ($ret) $thumbFilename = implode(';', $destFilename);
538                                         }
539                                 }
540
541                                 // 追加パラメータ
542                                 $otherParams =  array(  'cn_thumb_filename'             => $thumbFilename,              // サムネールファイル名
543                                                                                 'cn_related_content'    => $relatedContent,             // 関連コンテンツ
544                                                                                 'cn_option_fields'              => $this->serializeArray($this->fieldValueArray),       // ユーザ定義フィールド値
545                                                                                 'cn_script'                             => $jQueryScript,       // jQueryスクリプト
546                                                                                 'cn_script_lib'                 => implode(',', $this->selectedPlugin),                 // jQueryプラグイン
547                                                                                 'cn_template_id'                => $this->templateId,           // テンプレートID
548                                                                                 'cn_sub_template_id'    => $this->subTemplateId,        // サブテンプレートID
549                                                                                 'cn_attach_access_key'  => $accessKey,          // アクセスキー
550                                                                                 'cn_attach_access_url'  => $accessUrl,          // アクセスキー取得用URL
551                                                                                 'cn_search_target'              => $searchTarget        // 検索対象かどうか
552                                                                 );
553                                                                                 
554                                 // 履歴からのデータ取得の場合はシリアル番号を最新に変更
555                                 $mode = $request->trimValueOf('mode');                  // データ更新モード
556                                 if ($mode == 'history'){                // 履歴データ表示モード
557                                         // 最新のシリアル番号を取得
558                                         $ret = self::$_mainDb->getContentByContentId(default_contentCommonDef::$_contentType, $contentId, $this->langId, $row);
559                                         if ($ret) $this->serialNo = $row['cn_serial'];          // コンテンツシリアル番号
560                                         
561                                         // ### 履歴データを再取得すべき? ###
562                                 }
563                                 
564                                 $ret = self::$_mainDb->updateContentItem($this->serialNo, $name, $desc, $html, $visible, 0/*未使用(デフォルトかどうか)*/, $limited, $key, $password, 
565                                                                                                                         $metaTitle, $metaDesc, $metaKeyword, $headOthers, $startDt, $endDt, $newSerial, $oldRecord, $otherParams);
566                                 if ($ret){
567                                         // コンテンツに画像がなくなった場合は、サムネールを削除
568                                         if (empty($thumbFilename) && !empty($oldRecord['cn_thumb_filename'])){
569                                                 $oldFiles = explode(';', $oldRecord['cn_thumb_filename']);
570                                                 $this->gInstance->getImageManager()->delSystemDefaultThumb(M3_VIEW_TYPE_CONTENT, default_contentCommonDef::$_deviceType, $oldFiles);
571                                         }
572                                 
573                                         // ##### 添付ファイル情報を更新 #####
574                                         $ret = self::$_mainDb->getContentBySerial($newSerial, $row);
575                                         if ($ret){
576                                                 $contentId = $row['cn_id'];             // コンテンツID
577                                                 $name = $row['cn_name'];                // コンテンツ名前
578                                                 $updateDt = $row['cn_create_dt'];               // コンテンツ作成日時
579                                                 $attachFileDir = default_contentCommonDef::getAttachFileDir();
580                                         
581                                                 $ret = $this->gInstance->getFileManager()->updateAttachFileInfo(default_contentCommonDef::$_viewContentType, $contentId, $this->serialNo, $newSerial,
582                                                                                                                                                                                                                                                         $this->attachFileInfoArray, $attachFileDir);
583                                         }
584                                 }
585                                 
586                                 if ($ret){
587                                         // ##### アクセスキー情報を登録 #####
588                                         $this->gAccess->unegistAllSessionAccessKey($contentId);         // 一旦すべて削除
589                                         if (!empty($accessKey)) $this->gAccess->registSessionAccessKey($accessKey, $contentId, 0/*参照*/);
590                                         
591                                         $this->setGuidanceMsg('データを更新しました');
592                                         
593                                         // シリアル番号更新
594                                         $this->serialNo = $newSerial;
595                                         $reloadData = true;             // データの再読み込み
596                                         
597                                         // キャッシュデータのクリア
598                                         $this->clearCacheBySerial($this->serialNo);
599                                         
600                                         // 親ウィンドウを更新
601                                         $this->gPage->updateParentWindow($this->serialNo);
602                                         
603                                         // コンテンツ更新情報をサーバへ登録
604                                         $ret = $this->registContentInfoBySerial($this->serialNo);
605                                         if ($ret) $this->setGuidanceMsg('更新情報をサーバへアップしました');
606                                         
607                                         // 運用ログを残す
608                                         $contentAttr = default_contentCommonDef::$_deviceTypeName;
609                                         if ($this->isMultiLang) $contentAttr .= $this->getLangName($this->langId);              // 多言語対応の場合
610                                         //$this->gOpeLog->writeUserInfo(__METHOD__, sprintf(self::LOG_MSG_UPDATE_CONTENT, $contentAttr, $name), 2100, 'ID=' . $contentId);
611                                         $eventParam = array(    M3_EVENT_HOOK_PARAM_CONTENT_TYPE        => M3_VIEW_TYPE_CONTENT,
612                                                                                         M3_EVENT_HOOK_PARAM_CONTENT_ID          => $contentId,
613                                                                                         M3_EVENT_HOOK_PARAM_UPDATE_DT           => $updateDt);
614                                         $this->writeUserInfoEvent(__METHOD__, sprintf(self::LOG_MSG_UPDATE_CONTENT, $contentAttr, $name), 2401, 'ID=' . $contentId, $eventParam);
615                                 } else {
616                                         $this->setAppErrorMsg('データ更新に失敗しました');
617                                 }
618                         }                               
619                 } else if ($act == 'delete'){           // 項目削除の場合
620                         if (empty($this->serialNo)){
621                                 $this->setUserErrorMsg('削除項目が選択されていません');
622                         }
623                         // エラーなしの場合は、データを削除
624                         if ($this->getMsgCount() == 0){
625                                 // 削除するコンテンツの情報を取得
626                                 $ret = self::$_mainDb->getContentBySerial($this->serialNo, $row);
627                                 if ($ret){
628                                         $contentId = $row['cn_id'];             // コンテンツID
629                                         $name = $row['cn_name'];                // コンテンツ名前
630                                 }
631
632                                 $delByContentId = true;         // コンテンツをコンテンツIDで削除するかどうか
633                                 if ($this->isMultiLang){                // 多言語対応のとき
634                                         if ($this->langId == $this->gEnv->getDefaultLanguage()){                // デフォルト言語のときは全削除
635                                                 $ret = self::$_mainDb->delContentItemById(array($this->serialNo));
636                                         } else {
637                                                 $ret = self::$_mainDb->delContentItem(array($this->serialNo));
638                                                 $delByContentId = false;                // コンテンツをコンテンツIDで削除するかどうか
639                                         }
640                                 } else {
641                                         // 多言語対応状態に関わらずコンテンツIDで削除
642                                         $ret = self::$_mainDb->delContentItemById(array($this->serialNo));
643                                 }
644                         
645                                 if ($ret){
646                                         if ($delByContentId){           // コンテンツIDで削除のとき
647                                                 // サムネールを削除
648                                                 if (!empty($row['cn_thumb_filename'])){
649                                                         $oldFiles = explode(';', $row['cn_thumb_filename']);
650                                                         $this->gInstance->getImageManager()->delSystemDefaultThumb(M3_VIEW_TYPE_CONTENT, default_contentCommonDef::$_deviceType, $oldFiles);
651                                                 }
652                                                 
653                                                 // 添付ファイルを削除
654                                                 $ret = $this->gInstance->getFileManager()->delAttachFileInfoByContentId(default_contentCommonDef::$_viewContentType,
655                                                                                                                                                                                                 $contentId, default_contentCommonDef::getAttachFileDir());
656                                         } else {
657                                                 // 添付ファイルを削除
658                                                 $ret = $this->gInstance->getFileManager()->delAttachFileInfo(default_contentCommonDef::$_viewContentType,
659                                                                                                                                                                                 $this->serialNo, default_contentCommonDef::getAttachFileDir());
660                                         }
661                                 }
662                                 
663                                 if ($ret){              // データ削除成功のとき
664                                         // ##### アクセスキー情報を削除 #####
665                                         $this->gAccess->unegistAllSessionAccessKey($contentId);         // 一旦すべて削除
666                                         
667                                         $this->setGuidanceMsg('データを削除しました');
668                                         $reloadData = true;             // データの再読み込み
669                                         
670                                         // キャッシュデータのクリア
671                                         $this->clearCacheBySerial($this->serialNo);
672                                         
673                                         // 親ウィンドウを更新
674                                         $this->gPage->updateParentWindow();
675                                         
676                                         // 運用ログを残す
677                                         $contentAttr = default_contentCommonDef::$_deviceTypeName;
678                                         if ($this->isMultiLang && $this->langId != $this->gEnv->getDefaultLanguage()) $contentAttr .= $this->getLangName($this->langId);                // 多言語対応の場合
679                                         //$this->gOpeLog->writeUserInfo(__METHOD__, sprintf(self::LOG_MSG_DEL_CONTENT, $contentAttr, $name), 2100, 'ID=' . $contentId);
680                                         $eventParam = array(    M3_EVENT_HOOK_PARAM_CONTENT_TYPE        => M3_VIEW_TYPE_CONTENT,
681                                                                                 //      M3_EVENT_HOOK_PARAM_CONTENT_ID          => $infoObj->contentId,
682                                                                                         M3_EVENT_HOOK_PARAM_CONTENT_ID          => $contentId,
683                                                                                         M3_EVENT_HOOK_PARAM_UPDATE_DT           => date("Y/m/d H:i:s"));
684                                         $this->writeUserInfoEvent(__METHOD__, sprintf(self::LOG_MSG_DEL_CONTENT, $contentAttr, $name), 2402, 'ID=' . $contentId, $eventParam);
685                                 } else {
686                                         $this->setAppErrorMsg('データ削除に失敗しました');
687                                 }
688                         }
689                 } else if ($act == 'get_history'){              // 履歴データの取得のとき
690                         $reloadData = true;             // データの再読み込み
691                 } else if ($act == 'selectlang'){               // 言語選択
692                         // 多言語対応の場合の処理
693                         //$contentId = $request->trimValueOf('contentid');              // コンテンツID
694                         
695                         // コンテンツを取得
696                         $ret = self::$_mainDb->getContentByContentId(default_contentCommonDef::$_contentType, $contentId, $this->langId, $row);
697                         if ($ret){
698                                 $this->serialNo = $row['cn_serial'];            // コンテンツシリアル番号
699                                 $reloadData = true;             // データの再読み込み
700                         } else {
701                                 $this->serialNo = 0;
702                         }
703                 } else if ($act == 'uploadfile'){               // 添付ファイルアップロード
704                         $uploader = new qqFileUploader(array());
705                         $resultObj = $uploader->handleUpload(default_contentCommonDef::getAttachFileDir());
706                         
707                         if ($resultObj['success']){
708                                 $fileInfo = $resultObj['file'];
709                                 $ret = $this->gInstance->getFileManager()->addAttachFileInfo(default_contentCommonDef::$_viewContentType, $fileInfo['fileid'], $fileInfo['path'], $fileInfo['filename']);
710                                 if (!$ret){                     // エラーの場合はファイルを添付ファイルを削除
711                                         unlink($fileInfo['path']);
712                                         $resultObj = array('error' => 'Could not create file information.');
713                                 }
714                         }
715                         // ##### 添付ファイルアップロード結果を返す #####
716                         // ページ作成処理中断
717                         $this->gPage->abortPage();
718                         
719                         // 添付ファイルの登録データを返す
720                         if (function_exists('json_encode')){
721                                 $destStr = json_encode($resultObj);
722                         } else {
723                                 $destStr = $this->gInstance->getAjaxManager()->createJsonString($resultObj);
724                         }
725                         //$destStr = htmlspecialchars($destStr, ENT_NOQUOTES);// 「&」が「&amp;」に変換されるので使用しない
726                         //header('Content-type: application/json; charset=utf-8');
727                         header('Content-Type: text/html; charset=UTF-8');               // JSONタイプを指定するとIE8で動作しないのでHTMLタイプを指定
728                         echo $destStr;
729                         
730                         // システム強制終了
731                         $this->gPage->exitSystem();
732                 } else if ($act == 'getmenu'){          // メニュー定義取得
733                         // ##### ウィジェット出力処理中断 ######
734                         $this->gPage->abortWidget();
735                         
736                         $menuList = $this->getParsedTemplateData('default_menulist.tmpl.html', array($this, 'makeMenuList'), $contentId);// メニュー定義一覧
737                         $this->gInstance->getAjaxManager()->addDataToBody($menuList);
738                         return;
739                 } else if ($act == 'getsubtemplate'){           // サブテンプレート取得
740                         // ##### ウィジェット出力処理中断 ######
741                         $this->gPage->abortWidget();
742                         
743                         // デフォルトのサブテンプレートを取得
744                         $this->subTemplateId = $this->getDefaultSubTemplateId($this->templateId);
745                         
746 //                      $subTemplateMenu = $this->getParsedTemplateData('sub_template_menu.tmpl.html', array($this, 'makeSubTemplateMenu'), $this->templateId);// サブテンプレートメニュー取得
747                         $subTemplateMenu = $this->getParsedTemplateData('sub_template_menu.tmpl.html', array($this, 'createSubTemplateMenu'), $this->templateId);// サブテンプレートメニュー取得
748                         if (!$this->isExistsSubTemplate) $subTemplateMenu = '';         // サブテンプレートが存在しない場合は空で返す
749                         $this->gInstance->getAjaxManager()->addDataToBody($subTemplateMenu);
750                         return;
751                 } else if ($act == 'addtomenu'){                        // メニューに項目を追加
752                         $serialList = $request->trimValueOf('seriallist');
753                         if (!empty($serialList)){
754                                 $listedItem = explode(',', $serialList);
755                                 for ($i = 0; $i < count($listedItem); $i++){
756                                         // 項目がチェックされているかを取得
757                                         $itemName = 'item' . $i . '_selected';
758                                         $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
759                                         if ($itemValue) $this->selectedItem[] = $listedItem[$i];// チェック項目
760                                 }
761                         }
762                 
763                         // URLの作成
764                         switch (default_contentCommonDef::$_deviceType){                // デバイスごとの処理
765                                 case 0:         // PC
766                                 default:
767                                         $url = M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/' . $this->gEnv->getDefaultPageId() . '.php?contentid=' . $contentId;
768                                         break;
769                                 case 1:         // 携帯
770                                         $url = M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/' . M3_DIR_NAME_MOBILE . '/' . $this->gEnv->getDefaultPageId() . '.php?contentid=' . $contentId;
771                                         break;
772                                 case 2:         // スマートフォン
773                                         $url = M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/' . M3_DIR_NAME_SMARTPHONE . '/' . $this->gEnv->getDefaultPageId() . '.php?contentid=' . $contentId;
774                                         break;
775                         }
776
777                         // コンテンツ名を取得
778                         $menutItemName = '';
779                         $ret = self::$_mainDb->getContentByContentId(default_contentCommonDef::$_contentType, $contentId, $this->langId, $row);
780                         if ($ret) $menutItemName = $row['cn_name'];             // 名前は取得値を設定
781
782                         // メニュー項目追加
783                         for ($i = 0; $i < count($this->selectedItem); $i++){
784                                 $ret = self::$_mainDb->addMenuItem($this->selectedItem[$i], $menutItemName, $url);
785                                 if (!$ret) break;
786                         }
787                         if ($ret){
788                                 $this->gInstance->getAjaxManager()->addData('status', 'OK');
789                                 $this->gInstance->getAjaxManager()->addData('message', '<div class="alert alert-success">メニューにリンクを追加しました</div>');
790                         } else {
791                                 $this->gInstance->getAjaxManager()->addData('status', 'NG');
792                                 $this->gInstance->getAjaxManager()->addData('message', '<div class="alert alert-error">メニューのリンク追加に失敗しました</div>');
793                         }
794                         return;
795                 } else {
796                         // ##### コンテンツIDが設定されているとき(他ウィジェットからの表示)は、データを取得 #####
797                         if (empty($contentId)){
798                                 if (empty($this->serialNo)){            // 新規項目追加のとき
799                                         $visible = 1;           // 非公開で登録されてしまうので、初期状態は表示に設定
800                                 } else {
801                                         $reloadData = true;             // データの再読み込み
802                                 }
803                         } else {
804                                 // 多言語対応の場合は、言語を取得
805                                 if ($this->isMultiLang){                // 多言語対応の場合
806                                         $langId = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_LANG);               // lang値を取得
807                                         if (!empty($langId)) $this->langId = $langId;
808                                 }
809                 
810                                 // コンテンツを取得
811                                 $ret = self::$_mainDb->getContentByContentId(default_contentCommonDef::$_contentType, $contentId, $this->langId, $row);
812                                 if ($ret){
813                                         $this->serialNo = $row['cn_serial'];            // コンテンツシリアル番号
814                                         $reloadData = true;             // データの再読み込み
815                                 } else {
816                                         $visible = 1;           // 非公開で登録されてしまうので、初期状態は表示に設定
817                                         $this->serialNo = 0;
818                                 }
819                         }
820                         // ##### 初期表示時は仮登録の添付ファイルを削除 #####
821                         $this->gInstance->getFileManager()->cleanAttachFileInfo(default_contentCommonDef::$_viewContentType, default_contentCommonDef::getAttachFileDir());
822                 }
823                 if ($reloadData){               // データの再読み込み
824                         $ret = self::$_mainDb->getContentBySerial($this->serialNo, $row);
825                         if ($ret){
826                                 $contentId = $row['cn_id'];             // コンテンツID
827                                 $name = $row['cn_name'];                // コンテンツ名前
828                                 $html = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->getUrl($this->gEnv->getRootUrl()), $row['cn_html']);                              // HTML
829                                 $desc = $row['cn_description'];         // 簡易説明
830                                 $key = $row['cn_key'];                                  // 外部参照用キー
831                                 $update_user = $row['lu_name'];// 更新者
832                                 $update_dt = $row['cn_create_dt'];
833                         
834                                 // 項目表示、デフォルト値チェックボックス
835                                 $visible = $row['cn_visible'];
836                                 $default = '0';                 // 未使用(デフォルトかどうか)
837                                 $limited = $row['cn_user_limited'];             // ユーザ制限
838                                 $searchTarget = $row['cn_search_target'];               // 検索対象かどうか
839                                 $metaTitle = $row['cn_meta_title'];             // ページタイトル名(METAタグ)
840                                 $metaDesc = $row['cn_meta_description'];                // ページ要約(METAタグ)
841                                 $metaKeyword = $row['cn_meta_keywords'];                // ページキーワード(METAタグ)
842                                 $headOthers = $row['cn_head_others'];   // ヘッダ部その他
843                                 $start_date = $this->convertToDispDate($row['cn_active_start_dt']);     // 公開期間開始日
844                                 $start_time = $this->convertToDispTime($row['cn_active_start_dt'], 1/*時分*/);        // 公開期間開始時間
845                                 $end_date = $this->convertToDispDate($row['cn_active_end_dt']); // 公開期間終了日
846                                 $end_time = $this->convertToDispTime($row['cn_active_end_dt'], 1/*時分*/);    // 公開期間終了時間
847                                 $relatedContent = $row['cn_related_content'];           // 関連コンテンツ
848                                 $jQueryScript = $row['cn_script'];      // jQueryスクリプト
849                                 if (!empty($row['cn_script_lib'])) $this->selectedPlugin = explode(',', $row['cn_script_lib']);         // jQueryプラグイン
850                                 $this->templateId       = $row['cn_template_id'];       // テンプレートID
851                                 $this->subTemplateId = $row['cn_sub_template_id'];      // サブテンプレートID
852                                 $accessKey = $row['cn_attach_access_key'];              // アクセスキー
853                                 $accessUrl = $row['cn_attach_access_url'];              // アクセスキー取得用URL
854                                 
855                                 // パスワード
856                                 if (!empty($row['cn_password'])) $hasPassword = true;           // パスワードが設定されている
857                                 
858                                 // 履歴番号
859                                 if ($row['cn_deleted']) $historyIndex = $row['cn_history_index'];// 旧データの場合のみ有効
860                                 
861                                 // ユーザ定義フィールド
862                                 $this->fieldValueArray = $this->unserializeArray($row['cn_option_fields']);
863
864                                 // ##### 添付ファイル情報を取得 #####
865                                 // 多言語対応の場合はデフォルト言語が選択されている場合のみ処理を行う
866                                 if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){
867                                         $ret = $this->gInstance->getFileManager()->getAttachFileInfo(default_contentCommonDef::$_viewContentType, $this->serialNo, $rows);
868                                         if ($ret){
869                                                 $this->attachFileInfoArray = array();
870                                                 for ($i = 0; $i < count($rows); $i++){
871                                                         $attachFileRow = $rows[$i];
872                                                         $newInfoObj = new stdClass;
873                                                         $newInfoObj->title              = $attachFileRow['af_title'];
874                                                         $newInfoObj->filename   = $attachFileRow['af_filename'];
875                                                         $newInfoObj->fileId             = $attachFileRow['af_file_id'];
876                                                         $this->attachFileInfoArray[] = $newInfoObj;
877                                                 }
878                                         }
879                                 }
880                                 
881                                 // 拡張エリアの状態を設定
882                                 if ($hasPassword || !empty($headOthers) || !empty($limited) || !empty($key) || !empty($relatedContent) || count($this->attachFileInfoArray) > 0) $this->isOpenOptionArea = true;
883                         } else {
884                                 $this->serialNo = 0;
885                                 
886                                 $contentId = '0';               // コンテンツID
887                                 $name = '';             // コンテンツ名前
888                                 $html = '';                             // HTML
889                                 $desc = '';             // 簡易説明
890                                 $key = '';                                      // 外部参照用キー
891                                 $update_user = '';// 更新者
892                                 $update_dt = '';
893                         
894                                 // 項目表示、デフォルト値チェックボックス
895                                 $visible = '1';
896                                 $default = '0';         // 未使用(デフォルトかどうか)
897                                 $limited = '0';         // ユーザ制限
898                                 $searchTarget = '1';            // 検索対象かどうか
899                                 $metaTitle = '';                // ページタイトル名(METAタグ)
900                                 $metaDesc = '';         // ページ要約(METAタグ)
901                                 $metaKeyword = '';              // ページキーワード(METAタグ)
902                                 $headOthers = '';       // ヘッダ部その他
903                                 $start_date = '';       // 公開期間開始日
904                                 $start_time = '';       // 公開期間開始時間
905                                 $end_date = ''; // 公開期間終了日
906                                 $end_time = ''; // 公開期間終了時間
907                                 $relatedContent = '';           // 関連コンテンツ
908                                 $jQueryScript = '';     // jQueryスクリプト
909                                 $this->selectedPlugin = array();                // jQueryプラグイン
910                                 $this->templateId       = '';   // テンプレートID
911                                 $this->subTemplateId = '';      // サブテンプレートID
912                                 $accessKey = '';                // アクセスキー
913                                 $accessUrl = '';                // アクセスキー取得用URL
914                                 
915                                 // パスワード
916                                 $hasPassword = false;           // パスワードが設定されている
917                                 
918                                 // 履歴番号
919                                 $historyIndex = -1;
920                                 
921                                 // ユーザ定義フィールド
922                                 $this->fieldValueArray = array();
923
924                                 // 添付ファイル情報
925                                 $this->attachFileInfoArray = array();
926                                 
927                                 // 拡張エリアの状態を設定
928                                 $this->isOpenOptionArea = false;
929                         }
930                 }
931                 // 一覧の表示タイプを設定
932                 if ($this->isMultiLang){                // 多言語対応の場合
933                         $this->tmpl->setAttribute('show_multilang', 'visibility', 'visible');
934                         $this->tmpl->addVar("show_multilang", "sel_item_name", $name);          // 名前
935                         
936                         if (empty($contentId)){         // 新規追加の場合
937                                 $defaultLangName = $this->gEnv->getDefaultLanguageNameByCurrentLanguage();              // デフォルト言語の現在の表示名を取得
938                                 $this->tmpl->addVar("default_lang", "default_lang", $defaultLangName);
939                                 $this->tmpl->setAttribute('default_lang', 'visibility', 'visible');
940                         } else {                // コンテンツが選択されているとき
941                                 // 言語選択メニュー作成
942                                 self::$_mainDb->getAvailableLang(array($this, 'langLoop'));
943                                 $this->tmpl->setAttribute('select_lang', 'visibility', 'visible');
944                                 
945                                 // デフォルト言語のみ入力可能フィールド
946                                 if ($this->langId != $this->gEnv->getDefaultLanguage()){
947                                         $this->tmpl->addVar("_widget", "password_disabled", "disabled");// パスワード
948                                         $this->tmpl->addVar("_widget", "key_disabled", "disabled");             // 外部参照用キー
949                                         $this->tmpl->addVar("_widget", "related_content_disabled", "disabled");// 関連コンテンツ
950                                 }
951                         }
952                         
953                         // 言語イメージ
954                         $langImage = $this->createLangImage($contentId);
955                         $this->tmpl->addVar("show_multilang", "lang", $langImage);
956                 } else {
957                         $this->tmpl->setAttribute('show_singlelang', 'visibility', 'visible');
958                         $this->tmpl->addVar("show_singlelang", "sel_item_name", $name);         // 名前
959                 }
960                 
961                 // 公開期間エリア表示ボタン
962                 $activeTermButton = $this->gDesign->createTermButton(''/*同画面*/, self::TOOLTIP_ACTIVE_TERM, self::TAG_ID_ACTIVE_TERM);
963                 $this->tmpl->addVar("_widget", "active_term_button", $activeTermButton);
964                 $this->tmpl->addVar("_widget", "tagid_active_term", self::TAG_ID_ACTIVE_TERM);
965                 if (!empty($start_date) || !empty($start_time) || !empty($end_date) || !empty($end_time)){
966                         $this->tmpl->addVar('_widget', 'show_active_term_area', 'true');                // 公開期間エリアの初期の表示状態
967                 } else {
968                         $this->tmpl->addVar('_widget', 'show_active_term_area', 'false');               // 公開期間エリアの初期の表示状態
969                 }
970                 
971                 // ユーザ定義フィールドを作成
972                 $this->createUserFields($fieldInfoArray);
973                 
974                 // 添付ファイル一覧作成
975                 $this->createAttachFileList();
976                 if (count($this->attachFileInfoArray) == 0) $this->tmpl->setAttribute('attach_file_list', 'visibility', 'hidden');// 添付ファイル一覧を表示
977                 
978                 // アップロード実行用URL
979                 $uploadUrl = $this->gEnv->getDefaultAdminUrl() . '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_CONFIG_WIDGET; // ウィジェット設定画面
980                 $uploadUrl .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $this->gEnv->getCurrentWidgetId();       // ウィジェットID
981                 $uploadUrl .= '&' . M3_REQUEST_PARAM_OPERATION_TASK . '=' . 'content_detail';
982                 $uploadUrl .= '&' . M3_REQUEST_PARAM_OPERATION_ACT . '=' . 'uploadfile';
983 //              $uploadUrl .= '&path=' . $this->adaptWindowsPath($path);                                        // アップロードディレクトリ
984                 $this->tmpl->addVar("_widget", "upload_url", $this->getUrl($uploadUrl));
985                 
986                 // アクセスキー取得用URLを実URLに変換
987                 $accessUrl = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->gEnv->getRootUrl(), $accessUrl);             // マクロ展開
988                 
989                 // jQueryスクリプト、プラグイン一覧作成
990                 if ($useJQuery){
991                         // デフォルト言語のみ入力可能
992                         if ($this->langId == $this->gEnv->getDefaultLanguage()){
993                                 $this->tmpl->setAttribute('show_jquery', 'visibility', 'visible');
994                                 $this->createpluginIdList();
995                         }
996                         // ライブラリ追加
997                         $this->addLib[] = self::LIB_CODEMIRROR_JAVASCRIPT;              // CodeMirror Javascript
998                 }
999                 // コンテンツ単位のテンプレート設定を行うかどうか
1000                 if ($useContentTemplate){
1001                         // デフォルト言語のみ入力可能
1002                         if ($this->langId == $this->gEnv->getDefaultLanguage()){
1003                                 $this->tmpl->setAttribute('show_template', 'visibility', 'visible');
1004                                 
1005                                 // テンプレート選択メニュー作成
1006                                 self::$_mainDb->getAllTemplateList(default_contentCommonDef::$_deviceType, array($this, 'templateIdLoop'));
1007                                 
1008                                 // サブテンプレート選択メニュー作成
1009                                 $this->createSubTemplateMenu($this->tmpl, $this->templateId);
1010                                 
1011                                 // サブテンプレートが設定されている場合は拡張エリアを開く
1012                                 if (!empty($this->templateId)) $this->isOpenOptionArea = true;
1013                         }
1014                 }
1015                 
1016                 // ### 入力値を再設定 ###
1017                 $this->tmpl->addVar("_widget", "sel_item_html", $this->convertToDispString($html));             // HTML
1018                 $this->tmpl->addVar("_widget", "desc", $this->convertToDispString($desc));              // 簡易説明
1019                 $this->tmpl->addVar("_widget", "sel_item_key", $this->convertToDispString($key));               // 外部参照用キー
1020                 $this->tmpl->addVar("_widget", "meta_title", $this->convertToDispString($metaTitle));           // ページタイトル名(METAタグ)
1021                 $this->tmpl->addVar("_widget", "meta_desc", $this->convertToDispString($metaDesc));             // ページ要約(METAタグ)
1022                 $this->tmpl->addVar("_widget", "meta_keyword", $this->convertToDispString($metaKeyword));               // ページキーワード(METAタグ)
1023                 $this->tmpl->addVar("_widget", "head_others", $this->convertToDispString($headOthers));         // ヘッダ部その他
1024                 $this->tmpl->addVar("_widget", "update_user", $this->convertToDispString($update_user));        // 更新者
1025                 $this->tmpl->addVar("_widget", "update_dt", $this->convertToDispDateTime($update_dt));  // 更新日時
1026                 $this->tmpl->addVar("_widget", "start_date", $start_date);      // 公開期間開始日
1027                 $this->tmpl->addVar("_widget", "start_time", $start_time);      // 公開期間開始時間
1028                 $this->tmpl->addVar("_widget", "end_date", $end_date);  // 公開期間終了日
1029                 $this->tmpl->addVar("_widget", "end_time", $end_time);  // 公開期間終了時間
1030                 if ($hasPassword) $this->tmpl->addVar("_widget", "password", self::DEFAULT_PASSWORD);// 入力済みを示すパスワードの設定
1031                 $this->tmpl->addVar("_widget", "related_content", $this->convertToDispString($relatedContent)); // 関連コンテンツ
1032                 $this->tmpl->addVar("show_jquery", "jquery_script", $this->convertToDispString($jQueryScript)); // jQueryスクリプト
1033                 $this->tmpl->addVar('_widget', 'access_key', $this->convertToDispString($accessKey));           // アクセスキー
1034                 $this->tmpl->addVar('_widget', 'access_url', $this->convertToDispString($accessUrl));           // アクセスキー取得用URL
1035                                 
1036                 // 項目表示、項目利用可否チェックボックス
1037 /*              $visibleStr = '';
1038                 if ($visible) $visibleStr = 'checked';
1039                 $this->tmpl->addVar("_widget", "sel_item_visible", $visibleStr);
1040 //              $defaultStr = '';
1041 //              if ($default) $defaultStr = 'checked';
1042 //              $this->tmpl->addVar("_widget", "sel_item_default", $defaultStr);
1043                 $limitedStr = '';
1044                 if ($limited) $limitedStr = 'checked';
1045                 $this->tmpl->addVar("_widget", "sel_item_limited", $limitedStr);
1046 */
1047                 $this->tmpl->addVar("_widget", "sel_item_visible", $this->convertToCheckedString($visible));            // コンテンツ公開
1048                 $this->tmpl->addVar("_widget", "sel_item_limited", $this->convertToCheckedString($limited));            // ユーザ制限
1049                 $this->tmpl->addVar("_widget", "search_target_checked", $this->convertToCheckedString($searchTarget));          // 検索対象かどうか
1050         
1051                 $this->tmpl->addVar("_widget", "serial", $this->serialNo);              // 選択中のシリアル番号
1052                 $this->tmpl->addVar("_widget", "target_widget", $this->gEnv->getCurrentWidgetId());// メニュー選択ウィンドウ表示用
1053                 $this->tmpl->addVar("_widget", "device_type", default_contentCommonDef::$_deviceType);          // デバイスタイプ
1054                 $this->tmpl->addVar('_widget', 'tag_start', M3_TAG_START . M3_TAG_MACRO_ITEM_KEY);              // 置換タグ(前)
1055                 $this->tmpl->addVar('_widget', 'tag_end', M3_TAG_END);          // 置換タグ(後)
1056                 
1057                 // パスの設定
1058                 $this->tmpl->addVar('_widget', 'admin_url', $this->getUrl($this->gEnv->getDefaultAdminUrl()));// 管理者URL
1059
1060                 // プレビュー用URL
1061                 switch (default_contentCommonDef::$_deviceType){                // デバイスごとの処理
1062                         case 0:         // PC
1063                         default:
1064                                 $previewUrl = $this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentId;
1065                                 break;
1066                         case 1:         // 携帯
1067                                 $previewUrl = $this->gEnv->getDefaultMobileUrl() . '?' . M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentId;
1068                                 break;
1069                         case 2:         // スマートフォン
1070                                 $previewUrl = $this->gEnv->getDefaultSmartphoneUrl() . '?' . M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentId;
1071                                 break;
1072                 }
1073                 if ($historyIndex >= 0) $previewUrl .= '&' . M3_REQUEST_PARAM_HISTORY . '=' . $historyIndex;
1074                 $previewUrl .= '&' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_PREVIEW;
1075                 if ($this->isMultiLang) $previewUrl .= '&' . M3_REQUEST_PARAM_OPERATION_LANG . '=' . $this->langId;             // 多言語対応の場合は言語IDを付加
1076                 $this->tmpl->addVar('_widget', 'preview_url', $previewUrl);// プレビュー用URL(フロント画面)
1077                 
1078                 $this->tmpl->addVar('_widget', 'custom_value_task', 'usercustom');              // ユーザ定義値参照用
1079                 $this->tmpl->addVar('_widget', 'admin_widget_id', self::ADMIN_WIDGET_ID);// ユーザ定義値参照用(管理ウィジェットのウィジェットID)
1080                 $this->tmpl->addVar('_widget', 'calendar_img', $this->getUrl($this->gEnv->getRootUrl() . self::CALENDAR_ICON_FILE));    // カレンダーアイコン
1081                 
1082                 $iconUrl = $this->gEnv->getRootUrl() . self::DELETE_ICON_FILE;                  // 行削除アイコン
1083                 $iconTitle = '削除';
1084                 $iconTag = '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::ICON_SIZE . '" height="' . self::ICON_SIZE . '" rel="m3help" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
1085                 $this->tmpl->addVar('_widget', 'delete_icon', $iconTag);
1086
1087                 // CKEditor用のCSSファイルを読み込む
1088                 $this->loadCKEditorCssFiles($previewUrl);
1089
1090                 // リンクボタン作成
1091                 $buttonTag = $this->gDesign->createEditButton(''/*同画面*/, 'URL作成', self::CHANGE_URL_TAG_ID);
1092                 $this->tmpl->addVar("_widget", "change_url_button", $buttonTag);
1093                 $this->tmpl->addVar("_widget", "tagid_change_url", self::CHANGE_URL_TAG_ID);            // URL変更タグ
1094                 
1095                 // 拡張エリア制御
1096                 if ($this->isOpenOptionArea){
1097                         $this->tmpl->addVar('_widget', 'option_area_open', 'true');
1098                 } else {
1099                         $this->tmpl->addVar('_widget', 'option_area_open', 'false');
1100                 }
1101                 $iconUrl = $this->gEnv->getRootUrl() . self::OPEN_PANEL_ICON_FILE;              // 拡張エリア表示用アイコン
1102                 $iconTitle = 'オプションを表示';
1103                 $openButton = '<a id="button_open" href="javascript:void(0);" class="btn btn-sm btn-warning" role="button" rel="m3help" data-container="body" title="' . $iconTitle . '"><i class="glyphicon glyphicon-plus"></i></a>';
1104                 //$openButton = '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::PANEL_BUTTON_SIZE . '" height="' . self::PANEL_BUTTON_SIZE . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
1105                 $this->tmpl->addVar('_widget', 'open_button', $openButton);
1106                 $iconUrl = $this->gEnv->getRootUrl() . self::CLOSE_PANEL_ICON_FILE;             // 拡張エリア非表示用アイコン
1107                 $iconTitle = 'オプションを非表示';
1108                 $closeButton = '<a id="button_close" href="javascript:void(0);" class="btn btn-sm btn-warning" role="button" rel="m3help" data-container="body" title="' . $iconTitle . '"><i class="glyphicon glyphicon-minus"></i></a>';
1109                 //$closeButton = '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::PANEL_BUTTON_SIZE . '" height="' . self::PANEL_BUTTON_SIZE . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
1110                 $this->tmpl->addVar('_widget', 'close_button', $closeButton);
1111         
1112                 // ボタンの表示制御
1113                 if (empty($this->serialNo)){            // 新規追加項目を選択しているとき
1114                         if ($this->isMultiLang){                // 多言語対応の場合
1115                                 if (empty($contentId)){
1116                                         $this->tmpl->addVar("_widget", "sel_item_id", '');                      // コンテンツID
1117                                         $this->tmpl->addVar("_widget", "item_id", '新規');                    // コンテンツID
1118                                         
1119                                         $this->tmpl->addVar('cancel_button', 'new_btn_disabled', 'disabled');   // 「新規」ボタン使用不可
1120                                 } else {
1121                                         $this->tmpl->addVar("_widget", "sel_item_id", $contentId);                      // コンテンツID
1122                                         $this->tmpl->addVar("_widget", "item_id", $contentId);                  // コンテンツID
1123                                 }
1124                         } else {
1125                                 $this->tmpl->addVar("_widget", "sel_item_id", '');                      // コンテンツID
1126                                 $this->tmpl->addVar("_widget", "item_id", '新規');                    // コンテンツID
1127                                 
1128                                 $this->tmpl->addVar('cancel_button', 'new_btn_disabled', 'disabled');   // 「新規」ボタン使用不可
1129                         }
1130                         $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
1131                         $this->tmpl->addVar('_widget', 'preview_btn_disabled', 'disabled');// プレビューボタン使用不可
1132                         $this->tmpl->addVar('_widget', 'history_btn_disabled', 'disabled');// 履歴ボタン使用不可
1133                 } else {
1134                         // 履歴番号
1135                         $itemId = $contentId;                   // コンテンツID
1136                         if ($historyIndex >= 0) $itemId .= '(' . ($historyIndex +1) . ')';
1137
1138                         $this->tmpl->addVar("_widget", "sel_item_id", $contentId);                      // コンテンツID
1139                         $this->tmpl->addVar("_widget", "item_id", $itemId);                     // コンテンツID
1140                         
1141                         if ($historyIndex >= 0){                // 履歴データの場合
1142                                 $this->tmpl->setAttribute('update_history_button', 'visibility', 'visible');            // 「履歴データで更新」ボタン
1143                         } else {
1144                                 $this->tmpl->setAttribute('del_button', 'visibility', 'visible');// 「更新」「削除」ボタン
1145                         }
1146                 }
1147                 // 「戻る」ボタンの表示
1148                 if ($openby == 'simple' || $openby == 'tabs') $this->tmpl->setAttribute('cancel_button', 'visibility', 'hidden');               // 詳細画面のみの表示またはタブ表示のときは戻るボタンを隠す
1149         }
1150         /**
1151          * JavascriptライブラリをHTMLヘッダ部に設定
1152          *
1153          * JavascriptライブラリをHTMLのheadタグ内に追加出力する。
1154          * _assign()よりも後に実行される。
1155          *
1156          * @param RequestManager $request               HTTPリクエスト処理クラス
1157          * @param object         $param                 任意使用パラメータ。
1158          * @return string,array                                 Javascriptライブラリ。出力しない場合は空文字列を設定。
1159          */
1160         function _addScriptLibToHead($request, &$param)
1161         {
1162                 return $this->addLib;
1163         }
1164         /**
1165          * 取得したデータをテンプレートに設定する
1166          *
1167          * @param int $index                    行番号(0~)
1168          * @param array $fetchedRow             フェッチ取得した行
1169          * @param object $param                 未使用
1170          * @return bool                                 true=処理続行の場合、false=処理終了の場合
1171          */
1172         function itemListLoop($index, $fetchedRow, $param)
1173         {
1174                 $serial = $this->convertToDispString($fetchedRow['cn_serial']);
1175                 $contentId = $fetchedRow['cn_id'];              // コンテンツID
1176
1177                 // ユーザ制限
1178                 $limited = '';
1179                 if ($fetchedRow['cn_user_limited']) $limited = 'checked';
1180                 
1181                 // 対応言語を取得
1182                 $lang = '';
1183                 if ($this->isMultiLang){                // 多言語対応の場合
1184                         $lang = $this->createLangImage($contentId);
1185                 }
1186                 // 参照数
1187                 $updateViewCount = $this->gInstance->getAnalyzeManager()->getTotalContentViewCount(default_contentCommonDef::$_viewContentType, $serial);       // 更新後からの参照数
1188                 $totalViewCount = $this->gInstance->getAnalyzeManager()->getTotalContentViewCount(default_contentCommonDef::$_viewContentType, 0, $contentId);  // 新規作成からの参照数
1189                 $viewCountStr = $updateViewCount;
1190                 if ($totalViewCount > $updateViewCount) $viewCountStr .= '(' . $totalViewCount . ')';           // 新規作成からの参照数がない旧仕様に対応
1191                 
1192                 // 公開状況の設定
1193                 $now = date("Y/m/d H:i:s");     // 現在日時
1194                 $startDt = $fetchedRow['cn_active_start_dt'];
1195                 $endDt = $fetchedRow['cn_active_end_dt'];
1196                 
1197                 $isActive = false;              // 公開状態
1198                 if ($fetchedRow['cn_visible']) $isActive = $this->isActive($startDt, $endDt, $now);// 表示可能
1199                 
1200                 if ($isActive){         // コンテンツが公開状態のとき
1201                         $iconUrl = $this->gEnv->getRootUrl() . self::ACTIVE_ICON_FILE;                  // 公開中アイコン
1202                         $iconTitle = '公開中';
1203                 } else {
1204                         $iconUrl = $this->gEnv->getRootUrl() . self::INACTIVE_ICON_FILE;                // 非公開アイコン
1205                         $iconTitle = '非公開';
1206                 }
1207                 $statusImg = '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::ICON_SIZE . '" height="' . self::ICON_SIZE . '" rel="m3help" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
1208                 
1209                 // 操作用ボタン
1210                 $addToMenuImg = $this->getUrl($this->gEnv->getRootUrl() . self::ADD_TO_MENU_ICON_FILE);         // メニューに追加用アイコン
1211                 $addToMenuStr = 'メニューに追加';
1212                 $statusUrl = $this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentId;// 現在の表示画面用URL
1213                 
1214                 // プレビュー用URL
1215                 switch (default_contentCommonDef::$_deviceType){                // デバイスごとの処理
1216                         case 0:         // PC
1217                         default:
1218                                 $previewUrl = $this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentId;
1219                                 break;
1220                         case 1:         // 携帯
1221                                 $previewUrl = $this->gEnv->getDefaultMobileUrl() . '?' . M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentId;
1222                                 break;
1223                         case 2:         // スマートフォン
1224                                 $previewUrl = $this->gEnv->getDefaultSmartphoneUrl() . '?' . M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentId;
1225                                 break;
1226                 }
1227                 $previewUrl .= '&' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_PREVIEW;// プレビュー用URL
1228 //              if ($this->isMultiLang) $previewUrl .= '&' . M3_REQUEST_PARAM_OPERATION_LANG . '=' . $this->langId;             // 多言語対応の場合は言語IDを付加
1229                 $previewImg = $this->getUrl($this->gEnv->getRootUrl() . self::PREVIEW_ICON_FILE);
1230                 $previewStr = 'プレビュー';
1231                 
1232                 $row = array(
1233                         'index' => $index,                                                                                                      // 項目番号
1234                         'serial' => $serial,                    // シリアル番号
1235                         'id' => $this->convertToDispString($contentId),                 // ID
1236                         'name' => $this->convertToDispString($fetchedRow['cn_name']),           // 名前
1237                         'lang' => $lang,                                                                                                        // 対応言語
1238                         //'view_count' => $totalViewCount,                                                                      // 参照数
1239                         'view_count' => $this->convertToDispString($viewCountStr),                      // 参照数
1240                         'status' => $statusImg,                                                                                         // 公開状況
1241                         'update_user' => $this->convertToDispString($fetchedRow['lu_name']),    // 更新者
1242                         'update_dt' => $this->convertToDispDateTime($fetchedRow['cn_create_dt'], 0/*ロングフォーマット*/, 10/*時分*/),               // 更新日時
1243                         'limited' => $limited,                                                                                  // ユーザ制限
1244                         'add_to_menu_img' => $addToMenuImg,                                                                                     // メニューに追加用の画像
1245                         'add_to_menu_str' => $addToMenuStr,                                                                                     // メニューに追加用の文字列
1246                         'status_url' => $statusUrl,                                                                                     // 現在の表示画面用URL
1247                         'preview_url' => $previewUrl,                                                                                   // プレビュー用のURL
1248                         'preview_img' => $previewImg,                                                                                   // プレビュー用の画像
1249                         'preview_str' => $previewStr                                                                    // プレビュー文字列
1250                 );
1251                 if ($this->isMultiLang){                // 多言語対応のとき
1252                         $this->tmpl->addVars('itemlist2', $row);
1253                         $this->tmpl->parseTemplate('itemlist2', 'a');
1254                 } else {
1255                         $this->tmpl->addVars('itemlist', $row);
1256                         $this->tmpl->parseTemplate('itemlist', 'a');
1257                 }
1258                 
1259                 // 表示中のコンテンツIDを保存
1260                 $this->serialArray[] = $fetchedRow['cn_serial'];
1261                 
1262                 $this->isExistsContent = true;          // コンテンツ項目が存在するかどうか
1263                 return true;
1264         }
1265         /**
1266          * 取得した言語をテンプレートに設定する
1267          *
1268          * @param int $index                    行番号(0~)
1269          * @param array $fetchedRow             フェッチ取得した行
1270          * @param object $param                 未使用
1271          * @return bool                                 true=処理続行の場合、false=処理終了の場合
1272          */
1273         function langLoop($index, $fetchedRow, $param)
1274         {
1275                 $selected = '';
1276                 if ($fetchedRow['ln_id'] == $this->langId){
1277                         $selected = 'selected';
1278                 }
1279                 if ($this->gEnv->getCurrentLanguage() == 'ja'){         // 日本語表示の場合
1280                         $name = $this->convertToDispString($fetchedRow['ln_name']);
1281                 } else {
1282                         $name = $this->convertToDispString($fetchedRow['ln_name_en']);
1283                 }
1284
1285                 $row = array(
1286                         'value'    => $this->convertToDispString($fetchedRow['ln_id']),                 // 言語ID
1287                         'name'     => $name,                    // 言語名
1288                         'selected' => $selected                                                                                                         // 選択中かどうか
1289                 );
1290                 $this->tmpl->addVars('lang_list', $row);
1291                 $this->tmpl->parseTemplate('lang_list', 'a');
1292                 return true;
1293         }
1294         /**
1295          * 取得したデータをテンプレートに設定する
1296          *
1297          * @param int $index                    行番号(0~)
1298          * @param array $fetchedRow             フェッチ取得した行
1299          * @param object $param                 未使用
1300          * @return bool                                 true=処理続行の場合、false=処理終了の場合
1301          */
1302         function menuIdListLoop($index, $fetchedRow, $tmpl)
1303         {
1304                 $id = $fetchedRow['mn_id'];
1305                 
1306                 $checkStr = '';
1307                 if (in_array($id, $this->selectedItem)) $checkStr = 'checked ';
1308                 if ($this->completed) $checkStr .= 'disabled ';                 // 追加完了のとき
1309                 
1310                 $row = array(
1311                         'index' => $index,                                                                                                      // 項目番号
1312                         'serial' => $this->convertToDispString($id),                    // シリアル番号
1313                         'id' => $this->convertToDispString($id),                        // ID
1314                         'name' => $this->convertToDispString($fetchedRow['mn_name']),           // 名前
1315                         'check' => $checkStr            // チェック状態
1316                 );
1317                 $tmpl->addVars('itemlist', $row);
1318                 $tmpl->parseTemplate('itemlist', 'a');
1319                 
1320                 // 表示中項目IDを保存
1321                 $this->serialArray[] = $id;
1322                 $this->isExistsContent = true;          // コンテンツ項目が存在するかどうか
1323                 return true;
1324         }
1325         /**
1326          * キャッシュデータをクリア
1327          *
1328          * @param int $serial           削除対象のコンテンツシリアル番号
1329          * @return                                      なし
1330          */
1331         function clearCacheBySerial($serial)
1332         {
1333                 $ret = self::$_mainDb->getContentBySerial($serial, $row);               // コンテンツID取得
1334                 if ($ret){
1335                         $contentId = $row['cn_id'];             // コンテンツID
1336                         $urlParam = array();
1337                         $urlParam[] = M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentId;           // コンテンツID
1338                         $urlParam[] = M3_REQUEST_PARAM_CONTENT_ID_SHORT . '=' . $contentId;             // コンテンツID略式
1339                         $this->clearCache($urlParam);
1340                 }
1341         }
1342         /**
1343          * 期間から公開可能かチェック
1344          *
1345          * @param timestamp     $startDt                公開開始日時
1346          * @param timestamp     $endDt                  公開終了日時
1347          * @param timestamp     $now                    基準日時
1348          * @return bool                                         true=公開可能、false=公開不可
1349          */
1350         function isActive($startDt, $endDt, $now)
1351         {
1352                 $isActive = false;              // 公開状態
1353
1354                 if ($startDt == $this->gEnv->getInitValueOfTimestamp() && $endDt == $this->gEnv->getInitValueOfTimestamp()){
1355                         $isActive = true;               // 公開状態
1356                 } else if ($startDt == $this->gEnv->getInitValueOfTimestamp()){
1357                         if (strtotime($now) < strtotime($endDt)) $isActive = true;              // 公開状態
1358                 } else if ($endDt == $this->gEnv->getInitValueOfTimestamp()){
1359                         if (strtotime($now) >= strtotime($startDt)) $isActive = true;           // 公開状態
1360                 } else {
1361                         if (strtotime($startDt) <= strtotime($now) && strtotime($now) < strtotime($endDt)) $isActive = true;            // 公開状態
1362                 }
1363                 return $isActive;
1364         }
1365         /**
1366          * コンテンツ更新情報をサーバへ登録
1367          *
1368          * @param int $serial           コンテンツシリアル番号
1369          * @param bool $isNew           新規または更新
1370          * @return                                      なし
1371          */
1372         function registContentInfoBySerial($serial, $isNew=false)
1373         {
1374                 $ret = self::$_mainDb->getContentBySerial($serial, $row);               // コンテンツID取得
1375                 if ($ret){
1376                         $contentId = $row['cn_id'];             // コンテンツID
1377                         $contentTitle = $row['cn_name'];                // コンテンツタイトル
1378                         $contentLink = $url = $this->gEnv->getDefaultUrl() . '?contentid=' . $contentId;                // コンテンツリンク先
1379                         $contentDt = $row['cn_create_dt'];              // コンテンツ更新日時
1380                         
1381                         $ret = $this->gInstance->getConnectManager()->registUpdateInfo(''/*汎用コンテンツ*/, ''/*送信先はデフォルトURL*/, ''/*デフォルトウィジェットに送信*/, 
1382                                                                 $this->gEnv->getCurrentWidgetId(), self::MSG_UPDATE_CONTENT, $contentTitle, $contentLink, $contentDt);
1383                 }
1384                 return $ret;
1385         }
1386         /**
1387          * 言語アイコンを作成
1388          *
1389          * @param int $contentId        コンテンツID
1390          * @return atring                       言語アイコンタグ
1391          */
1392         function createLangImage($contentId)
1393         {
1394                 $imageTag = '';
1395                 $ret = self::$_mainDb->getLangByContentId(default_contentCommonDef::$_contentType, $contentId, $rows);
1396                 if ($ret){
1397                         $count = count($rows);
1398                         for ($i = 0; $i < $count; $i++){
1399                                 if ($this->gEnv->getCurrentLanguage() == 'ja'){ // 日本語の場合
1400                                         $langName = $rows[$i]['ln_name'];
1401                                 } else {
1402                                         $langName = $rows[$i]['ln_name_en'];
1403                                 }
1404                                 // 言語アイコン
1405                                 $iconTitle = $langName;
1406                                 $iconUrl = $this->gEnv->getRootUrl() . self::LANG_ICON_PATH . $rows[$i]['ln_image_filename'];           // 画像ファイル
1407                                 $iconTag = '<img src="' . $this->getUrl($iconUrl) . '" rel="m3help" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
1408                                 $imageTag .= $iconTag;
1409                         }
1410                 }
1411                 return $imageTag;
1412         }
1413         /**
1414          * 言語表示名を取得
1415          *
1416          * @param string $langId        言語ID
1417          * @return atring                       表示名
1418          */
1419         function getLangName($langId)
1420         {
1421                 $ret = self::$_mainDb->getLang($langId, $row);
1422                 if ($this->gEnv->getCurrentLanguage() == 'ja'){         // 日本語表示の場合
1423                         $name = $this->convertToDispString($row['ln_name']);
1424                 } else {
1425                         $name = $this->convertToDispString($row['ln_name_en']);
1426                 }
1427                 return $name;
1428         }
1429         /**
1430          * 添付ファイル一覧を作成
1431          *
1432          * @return なし                                               
1433          */
1434         function createAttachFileList()
1435         {
1436                 // アイコンタグ作成
1437                 $iconUrl = $this->gEnv->getRootUrl() . self::DELETE_ICON_FILE;                  // 行削除アイコン
1438                 $iconTitle = '削除';
1439                 $iconTag = '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::ICON_SIZE . '" height="' . self::ICON_SIZE . '" rel="m3help" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
1440                 
1441                 $fileCount = count($this->attachFileInfoArray);
1442                 for ($i = 0; $i < $fileCount; $i++){
1443                         $infoObj = $this->attachFileInfoArray[$i];
1444                         $title = $infoObj->title;               // タイトル
1445                         $filename = $infoObj->filename;         // ファイル名
1446                         $fileId = $infoObj->fileId;             // ファイルID
1447                         
1448                         $row = array(
1449                                 'title' => $this->convertToDispString($title),
1450                                 'filename' => $this->convertToDispString($filename),
1451                                 'file_id' => $this->convertToDispString($fileId),
1452                                 'delete_icon' => $iconTag
1453                         );
1454                         $this->tmpl->addVars('attach_file_list', $row);
1455                         $this->tmpl->parseTemplate('attach_file_list', 'a');
1456                 }
1457         }
1458         /**
1459          * ユーザ定義フィールドを作成
1460          *
1461          * @param array $fields                 フィールドID
1462          * @return bool                                 true=成功、false=失敗
1463          */
1464         function createUserFields($fields)
1465         {
1466                 if (count($fields) == 0) return true;
1467                 
1468                 $this->tmpl->setAttribute('user_fields', 'visibility', 'visible');
1469                 $keys = array_keys($fields);
1470                 $fieldCount = count($keys);
1471                 for ($i = 0; $i < $fieldCount; $i++){
1472                         if ($i == 0) $this->tmpl->addVar('user_fields', 'type', 'first');               // 最初の行の場合
1473                         
1474                         // 入力値を取得
1475                         $key = $keys[$i];
1476                         $value = $this->fieldValueArray[$key];
1477                         if (!isset($value)) $value = '';
1478                         
1479                         $row = array(
1480                                 'row_count'     => $fieldCount,
1481                                 'field_id'      => $this->convertToDispString($key),
1482                                 'value'         => $this->convertToDispString($value)
1483                         );
1484                         $this->tmpl->addVars('user_fields', $row);
1485                         $this->tmpl->parseTemplate('user_fields', 'a');
1486                 }
1487                 return true;
1488         }
1489         /**
1490          * jQueryプラグイン一覧作成
1491          *
1492          * @return なし
1493          */
1494         function createpluginIdList()
1495         {
1496                 for ($i = 0; $i < count($this->pluginIdArray); $i++){
1497                         $itemPluginId = str_replace('.', '_', $this->pluginIdArray[$i]);
1498                         $id = $this->pluginIdArray[$i];
1499                         $name = $id;
1500                         
1501                         // ライブラリ情報取得
1502                         $libInfo = $this->gPage->getScriptLibInfo($id);
1503                         if (!empty($libInfo)){
1504                                 $url = $libInfo['url'];
1505                                 if (!empty($url)) $name = '<a href="' . $this->convertUrlToHtmlEntity($url) . '" target="_blank">' . $name . '</a>';
1506                         }
1507                         
1508                         $checked = '';
1509                         if (in_array($id, $this->selectedPlugin)) $checked = 'checked';
1510
1511                         $row = array(
1512                                 'id'    => $itemPluginId,                       // 値
1513                                 'name'     => $name,                    // 名前
1514                                 'id_checked' => $checked                        // 選択中かどうか
1515                         );
1516                         $this->tmpl->addVars('plugin_list', $row);
1517                         $this->tmpl->parseTemplate('plugin_list', 'a');
1518                 }
1519         }
1520         /**
1521          * テンプレート一覧を作成
1522          *
1523          * @param int $index                    行番号(0~)
1524          * @param array $fetchedRow             フェッチ取得した行
1525          * @param object $param                 未使用
1526          * @return bool                                 true=処理続行の場合、false=処理終了の場合
1527          */
1528         function templateIdLoop($index, $fetchedRow, $param)
1529         {
1530                 $selected = '';
1531                 if ($fetchedRow['tm_id'] == $this->templateId) $selected = 'selected';
1532
1533                 $row = array(
1534                         'value'    => $this->convertToDispString($fetchedRow['tm_id']),                 // テンプレートID
1535                         'name'     => $this->convertToDispString($fetchedRow['tm_name']),                       // テンプレート名名
1536                         'selected' => $selected                                                                                                         // 選択中かどうか
1537                 );
1538                 $this->tmpl->addVars('template_list', $row);
1539                 $this->tmpl->parseTemplate('template_list', 'a');
1540                 return true;
1541         }
1542         /**
1543          * サブテンプレートメニュー作成
1544          *
1545          * @param object  $tmpl                 テンプレートオブジェクト
1546          * @param string  $templateId   テンプレートID
1547          * @return                                              なし
1548          */
1549         function createSubTemplateMenu($tmpl, $templateId)
1550         {
1551                 if (empty($templateId)) return;
1552                 
1553                 // テンプレート情報取得
1554                 $ret = self::$_mainDb->getTemplate($templateId, $row);
1555                 if (!$ret) return;
1556                 
1557                 $generator      = $row['tm_generator'];
1558                 $version        = $row['tm_version'];           // テンプレートバージョン
1559                 if ($generator != M3_TEMPLATE_GENERATOR_THEMLER) return;                // Themler
1560                 
1561                 // テンプレート選択メニューを表示
1562                 $tmpl->setAttribute('select_subtemplate', 'visibility', 'visible');
1563                 
1564                 $subTemplateInfoFile = $this->gEnv->getTemplatesPath() . '/' . $templateId . '/templates/list.php';
1565                 if (is_readable($subTemplateInfoFile)){
1566                         // サブテンプレート情報ファイル読み込み
1567                         require_once($subTemplateInfoFile);
1568                         
1569                         // $templatesInfoにサブテンプレートの情報が設定されているので取得
1570                         if (!isset($this->subTemplateInfo)) $this->subTemplateInfo = array();
1571                         if (!empty($templatesInfo)) $this->subTemplateInfo = $templatesInfo;
1572                         
1573                         foreach ($this->subTemplateInfo as $key => $templateInfo){
1574                                 $subTemplateId = $templateInfo['fileName'];
1575                                 $type = $templateInfo['kind'];
1576                                 if (empty($subTemplateId)) continue;
1577                                 if ($type == 'error404') continue;              // エラーメッセージ表示用の404タイプのサブテンプレートは表示しない
1578                                 
1579                                 $selected = '';
1580                                 if ($subTemplateId == $this->subTemplateId) $selected = 'selected';             // サブテンプレートID
1581                                 
1582                                 $row = array(
1583                                         'value'    => $this->convertToDispString($subTemplateId),
1584                                         'name'     => $this->convertToDispString($templateInfo['defaultTemplateCaption'] . '(' . $templateInfo['fileName'] . ')'),
1585                                         'selected' => $selected                                                                                                         // 選択中かどうか
1586                                 );
1587                                 $tmpl->addVars('subtemplate_list', $row);
1588                                 $tmpl->parseTemplate('subtemplate_list', 'a');
1589                                 
1590                                 $this->isExistsSubTemplate = true;              // サブテンプレートが存在するかどうか
1591                         }
1592                 }
1593         }
1594         /**
1595          * メニュー定義一覧データ作成処理コールバック
1596          *
1597          * @param object        $tmpl                   テンプレートオブジェクト
1598          * @param object        $param                  任意パラメータ(コンテンツID)
1599          * @param                                                       なし
1600          */
1601         function makeMenuList($tmpl, $param)
1602         {
1603                 // メニューID選択メニュー作成
1604                 self::$_mainDb->getMenuIdList(default_contentCommonDef::$_deviceType, array($this, 'menuIdListLoop'), $tmpl);
1605                 if (!$this->isExistsContent) $tmpl->setAttribute('itemlist', 'visibility', 'hidden');// 一覧項目がないときは、一覧を表示しない
1606
1607                 $tmpl->addVar("_tmpl", "content_id", $param);// コンテンツID
1608                 $tmpl->addVar("_tmpl", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
1609         }
1610         /**
1611          * デフォルトのサブテンプレートIDを取得
1612          *
1613          * @param string  $templateId   テンプレートID
1614          * @return string                               サブテンプレートID
1615          */
1616         function getDefaultSubTemplateId($templateId)
1617         {
1618                 $subTemplateId = '';
1619                 
1620                 $ret = self::$_mainDb->getTemplate($templateId, $row);
1621                 if (!$ret) return $subTemplateId;
1622                 
1623                 $generator      = $row['tm_generator'];
1624                 $version        = $row['tm_version'];           // テンプレートバージョン
1625                 switch ($generator){
1626                 case M3_TEMPLATE_GENERATOR_THEMLER:             // Themler
1627                         // デフォルトのサブテンプレートIDを取得
1628                         $subTemplateInfoFile = $this->gEnv->getTemplatesPath() . '/' . $templateId . '/templates/list.php';
1629                         if (is_readable($subTemplateInfoFile)){
1630                                 // サブテンプレート情報ファイル読み込み
1631                                 require_once($subTemplateInfoFile);
1632                                 
1633                                 // $templatesInfoにサブテンプレートの情報が設定されているので取得
1634                                 if (!isset($this->subTemplateInfo)) $this->subTemplateInfo = array();
1635                                 if (!empty($templatesInfo)) $this->subTemplateInfo = $templatesInfo;
1636
1637                                 foreach ($this->subTemplateInfo as $key => $templateInfo){
1638                                         $id = $templateInfo['fileName'];
1639                                         $type = $templateInfo['kind'];
1640                                         if (empty($id)) continue;
1641                                         
1642                                         if ($type == 'default'){
1643                                                 $subTemplateId = $id;
1644                                                 break;
1645                                         }
1646                                 }
1647                         }
1648                         break;
1649                 }
1650                 return $subTemplateId;
1651         }
1652 }
1653 ?>