Index: branches/version-2_5-dev/data/class/pages/admin/design/LC_Page_Admin_Design_Template.php
===================================================================
--- branches/version-2_5-dev/data/class/pages/admin/design/LC_Page_Admin_Design_Template.php (revision 19807)
+++ branches/version-2_5-dev/data/class/pages/admin/design/LC_Page_Admin_Design_Template.php (revision 19966)
@@ -53,5 +53,4 @@
$this->arrErr = array();
$this->arrForm = array();
- $this->tpl_select = TEMPLATE_NAME;
ini_set("max_execution_time", 300);
}
@@ -76,102 +75,106 @@
function action() {
// 認証可否の判定
- $objSession = new SC_Session();
- SC_Utils::sfIsSuccess($objSession);
-
- // uniqidをテンプレートへ埋め込み
- $this->uniqid = $objSession->getUniqId();
-
- $objView = new SC_AdminView();
-
- switch($this->lfGetMode()) {
+ $objSession = new SC_Session();
+ SC_Utils::sfIsSuccess($objSession);
+
+ // 端末種別IDを取得
+ if (isset($_REQUEST['device_type_id'])
+ && is_numeric($_REQUEST['device_type_id'])) {
+ $device_type_id = $_REQUEST['device_type_id'];
+ } else {
+ $device_type_id = DEVICE_TYPE_PC;
+ }
+
+ $this->tpl_select = $this->getTemplateName($device_type_id);
+
+ // uniqidをテンプレートへ埋め込み
+ $this->uniqid = $objSession->getUniqId();
+
+ $objView = new SC_AdminView();
+
+ switch($this->lfGetMode()) {
// 登録ボタン押下時
- case 'register':
- // 画面遷移の正当性チェック
- if (!SC_Utils::sfIsValidTransition($objSession)) {
- sfDispError('');
- }
- // パラメータ検証
- $objForm = $this->lfInitRegister();
- if ($objForm->checkError()) {
- SC_Utils_Ex::sfDispError('');
- }
-
- $template_code = $objForm->getValue('template_code');
- $this->tpl_select = $template_code;
-
- if($template_code == "") {
- $template_code = "default";
- }
-
- // DBへ使用するテンプレートを登録
- $this->lfRegisterTemplate($template_code);
-
- // XXX コンパイルファイルのクリア処理を行う
- $objView->_smarty->clear_compiled_tpl();
-
- // common.cssの内容を更新
- $this->lfChangeCommonCss($template_code);
+ case 'register':
+ // 画面遷移の正当性チェック
+ if (!SC_Utils::sfIsValidTransition($objSession)) {
+ sfDispError('');
+ }
+ // パラメータ検証
+ $objForm = $this->lfInitRegister();
+ if ($objForm->checkError()) {
+ SC_Utils_Ex::sfDispError('');
+ }
+
+ $template_code = $objForm->getValue('template_code');
+ $this->tpl_select = $template_code;
+
+ if($template_code == "") {
+ $template_code = $this->getTemplateName($device_type_id, true);
+ }
+
+ // DBへ使用するテンプレートを登録
+ $this->lfRegisterTemplate($template_code);
+
+ // XXX コンパイルファイルのクリア処理を行う
+ $objView->_smarty->clear_compiled_tpl();
+
+ // ブロック位置を更新
+ $this->lfChangeBloc($template_code);
+
+ // 完了メッセージ
+ $this->tpl_onload="alert('登録が完了しました。');";
+ break;
+
+ // 削除ボタン押下時
+ case 'delete':
+ // 画面遷移の正当性チェック
+ if (!SC_Utils::sfIsValidTransition($objSession)) {
+ SC_Utils::sfDispError('');
+ }
+ // パラメータ検証
+ $objForm = $this->lfInitDelete();
+ if ($objForm->checkError()) {
+ SC_Utils::sfDispError('');
+ }
- // テンプレートのコピー
- $this->lfCopyTemplate($template_code);
-
- // ブロック位置を更新
- $this->lfChangeBloc($template_code);
-
- // 完了メッセージ
- $this->tpl_onload="alert('登録が完了しました。');";
+ //現在使用中のテンプレートとデフォルトのテンプレートは削除できないようにする
+ $template_code = $objForm->getValue('template_code_temp');
+ if ($template_code == $this->getTemplateName($device_type_id)
+ || $template_code == $this->getTemplateName($device_type_id, true)) {
+ $this->tpl_onload = "alert('デフォルトテンプレートと、選択中のテンプレートは削除出来ません');";
break;
-
- // 削除ボタン押下時
- case 'delete':
- // 画面遷移の正当性チェック
- if (!SC_Utils::sfIsValidTransition($objSession)) {
- SC_Utils::sfDispError('');
- }
- // パラメータ検証
- $objForm = $this->lfInitDelete();
- if ($objForm->checkError()) {
- SC_Utils::sfDispError('');
- }
-
- //現在使用中のテンプレートとデフォルトのテンプレートは削除できないようにする
- $template_code = $objForm->getValue('template_code_temp');
- if ($template_code == TEMPLATE_NAME || $template_code == DEFAULT_TEMPLATE_NAME) {
- $this->tpl_onload = "alert('選択中のテンプレートは削除出来ません');";
- break;
- }
- $this->lfDeleteTemplate($template_code);
- break;
+ }
+ $this->lfDeleteTemplate($template_code);
+ break;
// downloadボタン押下時
- case 'download':
- // 画面遷移の正当性チェック
- if (!SC_Utils::sfIsValidTransition($objSession)) {
- SC_Utils::sfDispError('');
- }
- // パラメータ検証
- $objForm = $this->lfInitDownload();
- $template_code = $objForm->getValue('template_code_temp');
- // ユーザデータの下のファイルも保存する。
- $from_dir = USER_TEMPLATE_REALDIR . $template_code . "/";
- $to_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/";
- SC_Utils::sfMakeDir($to_dir);
- SC_Utils::sfCopyDir($from_dir, $to_dir);
- SC_Helper_FileManager::downloadArchiveFiles(SMARTY_TEMPLATES_REALDIR . $template_code);
- break;
+ case 'download':
+ // 画面遷移の正当性チェック
+ if (!SC_Utils::sfIsValidTransition($objSession)) {
+ SC_Utils::sfDispError('');
+ }
+ // パラメータ検証
+ $objForm = $this->lfInitDownload();
+ $template_code = $objForm->getValue('template_code_temp');
+ // ユーザデータの下のファイルも保存する。
+ $from_dir = USER_TEMPLATE_REALDIR . $template_code . "/";
+ $to_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/";
+ SC_Utils::sfMakeDir($to_dir);
+ SC_Utils::sfCopyDir($from_dir, $to_dir);
+ SC_Helper_FileManager::downloadArchiveFiles(SMARTY_TEMPLATES_REALDIR . $template_code);
+ break;
// プレビューボタン押下時
- case 'preview':
- break;
-
- default:
- break;
- }
-
- // defaultパラメータのセット
- $this->templates = $this->lfGetAllTemplates();
- $this->now_template = TEMPLATE_NAME;
- $this->device_type_id = $device_type_id;
+ case 'preview':
+ break;
+
+ default:
+ break;
+ }
+
+ $this->templates = $this->lfGetAllTemplates($device_type_id);
+ $this->now_template = TEMPLATE_NAME;
+ $this->device_type_id = $device_type_id;
}
@@ -225,8 +228,21 @@
* 使用するテンプレートをDBへ登録する
*/
- function lfRegisterTemplate($template_code) {
+ function lfRegisterTemplate($template_code, $device_type_id) {
$masterData = new SC_DB_MasterData_Ex();
- $data = array('TEMPLATE_NAME' => var_export($template_code, TRUE));
+ $defineName = 'TEMPLATE_NAME';
+ switch ($device_type_id) {
+ case DEVICE_TYPE_MOBILE:
+ $defineName = 'MOBILE_' . $defineName;
+ break;
+
+ case DEVICE_TYPE_SMARTPHONE:
+ $defineName = 'SMARTPHONE_' . $defineName;
+ break;
+ case DEVICE_TYPE_PC:
+ default:
+ }
+
+ $data = array($defineName => var_export($template_code, TRUE));
// DBのデータを更新
@@ -236,24 +252,4 @@
$masterData->createCache('mtb_constants', array(), true, array('id', 'remarks'));
}
-
- /**
- * common.cssの更新
- */
- function lfChangeCommonCss($template_code) {
- $css_path = USER_REALDIR . "css/common.css";
-
- // ファイル内容取得
- $css_data = file_get_contents($css_path);
-
- // ファイル内容更新
- $pt = '/(@import url\("\.\.\/packages\/.+\/css\/import\.css"\);)/';
- $rp = '@import url("../packages/'. $template_code. '/css/import.css");';
- $css = preg_replace($pt, $rp, $css_data);
-
- // ファイル更新
- $fp = fopen($css_path,"w");
- fwrite($fp, $css);
- fclose($fp);
- }
/**
@@ -262,5 +258,8 @@
function lfChangeBloc($template_code) {
$objQuery = new SC_Query();
- $filepath = USER_TEMPLATE_REALDIR. $template_code. "/sql/update_bloc.sql";
+ /*
+ * FIXME 各端末に合わせて作成する必要あり
+ * $filepath = USER_TEMPLATE_REALDIR. $template_code. "/sql/update_bloc.sql";
+ */
// ブロック位置更新SQLファイル有
@@ -299,7 +298,7 @@
}
- function lfGetAllTemplates() {
+ function lfGetAllTemplates($device_type_id) {
$objQuery = new SC_Query();
- $arrRet = $objQuery->select('*', 'dtb_templates');
+ $arrRet = $objQuery->select('*', 'dtb_templates', "device_type_id = ?", array($device_type_id));
if (empty($arrRet)) return array();
@@ -307,66 +306,4 @@
}
- /*
- * 関数名:lfCreateTemplate()
- * 引数1 :ディレクトリパス
- * 引数2 :作成ファイル名
- * 説明 :キャンペーンの初期テンプレート作成
- * 戻り値:無し
- */
- function lfCreateTemplate($dir, $file , $cart_flg) {
- umask(0);
- $objFileManager = new SC_Helper_FileManager_Ex();
-
- // 作成ファイルディレクトリ
- $create_dir = $dir . $file;
- $create_active_dir = $create_dir . "/" . CAMPAIGN_TEMPLATE_ACTIVE;
- $create_end_dir = $create_dir . "/" . CAMPAIGN_TEMPLATE_END;
- // デフォルトファイルディレクトリ
- $default_dir = TEMPLATE_REALDIR . CAMPAIGN_TEMPLATE_REALDIR;
- $default_active_dir = $default_dir . "/" . CAMPAIGN_TEMPLATE_ACTIVE;
- $default_end_dir = $default_dir . "/" . CAMPAIGN_TEMPLATE_END;
-
- $ret = $objFileManager->sfCreateFile($create_dir, 0755);
- $ret = $objFileManager->sfCreateFile($create_active_dir, 0755);
- $ret = $objFileManager->sfCreateFile($create_end_dir, 0755);
-
- // キャンペーン実行PHPをコピー
- $ret = $objFileManager->sfCreateFile(CAMPAIGN_PATH . $file);
- copy(HTML_REALDIR . CAMPAIGN_TEMPLATE_REALDIR . "index.php", CAMPAIGN_PATH . $file . "/index.php");
- copy(HTML_REALDIR . CAMPAIGN_TEMPLATE_REALDIR . "application.php", CAMPAIGN_PATH . $file . "/application.php");
- copy(HTML_REALDIR . CAMPAIGN_TEMPLATE_REALDIR . "complete.php", CAMPAIGN_PATH . $file . "/complete.php");
- copy(HTML_REALDIR . CAMPAIGN_TEMPLATE_REALDIR . "entry.php", CAMPAIGN_PATH . $file . "/entry.php");
-
- // デフォルトテンプレート作成(キャンペーン中)
- $header = $this->lfGetFileContents($default_active_dir."header.tpl");
- SC_Utils_Ex::sfWriteFile($header, $create_active_dir."header.tpl", "w");
- $contents = $this->lfGetFileContents($default_active_dir."contents.tpl");
- if(!$cart_flg) {
- $contents .= "\n" . '' . "\n";
- $contents .= $this->lfGetFileContents(CAMPAIGN_BLOC_PATH . "login.tpl");
- $contents .= ''."\n";
- $contents .= $this->lfGetFileContents(CAMPAIGN_BLOC_PATH . "entry.tpl");
- }
- SC_Utils_Ex::sfWriteFile($contents, $create_active_dir."contents.tpl", "w");
- $footer = $this->lfGetFileContents($default_active_dir."footer.tpl");
- SC_Utils_Ex::sfWriteFile($footer, $create_active_dir."footer.tpl", "w");
-
- // サイトフレーム作成
- $site_frame = $header."\n";
- $site_frame .= ''."\n";
- $site_frame .= ''."\n";
- $site_frame .= ''."\n";
- $site_frame .= $footer."\n";
- SC_Utils_Ex::sfWriteFile($site_frame, $create_active_dir."site_frame.tpl", "w");
-
- /* デフォルトテンプレート作成(キャンペーン終了) */
- $header = $this->lfGetFileContents($default_end_dir."header.tpl");
- SC_Utils_Ex::sfWriteFile($header, $create_end_dir."header.tpl", "w");
- $contents = $this->lfGetFileContents($default_end_dir."contents.tpl");
- SC_Utils_Ex::sfWriteFile($contents, $create_end_dir."contents.tpl", "w");
- $footer = $this->lfGetFileContents($default_end_dir."footer.tpl");
- SC_Utils_Ex::sfWriteFile($footer, $create_end_dir."footer.tpl", "w");
- }
-
/*
* 関数名:lfGetFileContents()
@@ -385,4 +322,23 @@
return $contents;
}
+
+ /**
+ * テンプレート名を返す.
+ */
+ function getTemplateName($device_type_id, $isDefault = false) {
+ switch ($device_type_id) {
+ case DEVICE_TYPE_MOBILE:
+ return $isDefault ? MOBILE_DEFAULT_TEMPLATE_NAME : MOBILE_TEMPLATE_NAME;
+ break;
+
+ case DEVICE_TYPE_SMARTPHONE:
+ return $isDefault ? SMARTPHONE_DEFAULT_TEMPLATE_NAME : SMARTPHONE_TEMPLATE_NAME;
+ break;
+
+ case DEVICE_TYPE_PC:
+ default:
+ }
+ return $isDefault ? DEFAULT_TEMPLATE_NAME : TEMPLATE_NAME;
+ }
}
?>