Changeset 20863 for branches/version-2_11-dev/data/class/pages
- Timestamp:
- 2011/04/19 22:52:35 (13 years ago)
- bzr:base-revision:
- ohkouchi@loop-az.jp-20110419134221-1wtj14593l61zc53
- bzr:committer:
- Kentaro Ohkouchi <ohkouchi@loop-az.jp>
- bzr:file-ids:
data/Smarty/templates/admin/design/template.tpl 15732@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Ffeature-module-update%2Fdata%2FSmarty%2Ftemplates%2Fdefault%2Fadmin%2Fdesign%2Ftemplate.tpl
data/Smarty/templates/admin/design/up_down.tpl 16677@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Ffeature-module-update%2Fdata%2FSmarty%2Ftemplates%2Fdefault%2Fadmin%2Fdesign%2Fup_down.tpl
data/class/SC_UploadFile.php 18171@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Fcomu-ver2%2Fdata%2Fclass%2FSC_UploadFile.php
data/class/helper/SC_Helper_FileManager.php 16253@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Ffeature-module-update%2Fdata%2Fclass%2Fhelper%2FSC_Helper_FileManager.php
data/class/pages/admin/design/LC_Page_Admin_Design_Template.php 16430@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Ffeature-module-update%2Fdata%2Fclass%2Fpages%2Fadmin%2Fdesign%2FLC_Page_Admin_Design_Template.php
data/class/pages/admin/design/LC_Page_Admin_Design_UpDown.php 20543@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Fversion-2_5-dev%2Fdata%2Fclass%2Fpages%2Fadmin%2Fdesign%2FLC_Page_Admin_Design_UpDown.php
data/class/util/SC_Utils.php 15078@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Ffeature-module-update%2Fdata%2Fclass%2Futil%2FSC_Utils.php
html/install/sql/insert_data.sql 15078@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Ffeature-module-update%2Fhtml%2Finstall%2Fsql%2Finsert_data.sql
html/user_data/packages/default/sql/update_bloc.sql 17136@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Fcomu-ver2%2Fhtml%2Fuser_data%2Fpackages%2Fdefault%2Fsql%2Fupdate_bloc.sql- bzr:mapping-version:
- v4
- bzr:merge:
ohkouchi@loop-az.jp-20110419134938-8843gis71oelhuff- bzr:repository-uuid:
- 1e3b908f-19a9-db11-a64c-001125224ba8
- bzr:revision-id:
- ohkouchi@loop-az.jp-20110419135231-g92tpf1uskbtyyat
- bzr:revno:
- 3574
- bzr:revprop:branch-nick:
- branches/version-2_11-dev
- bzr:root:
- branches/version-2_11-dev
- bzr:text-revisions:
data/Smarty/templates/admin/design/template.tpl ohkouchi@loop-az.jp-20110419134938-8843gis71oelhuff
data/Smarty/templates/admin/design/up_down.tpl ohkouchi@loop-az.jp-20110419134938-8843gis71oelhuff
data/class/SC_UploadFile.php ohkouchi@loop-az.jp-20110419134938-8843gis71oelhuff
data/class/helper/SC_Helper_FileManager.php ohkouchi@loop-az.jp-20110419134938-8843gis71oelhuff
data/class/pages/admin/design/LC_Page_Admin_Design_Template.php ohkouchi@loop-az.jp-20110419134938-8843gis71oelhuff
data/class/pages/admin/design/LC_Page_Admin_Design_UpDown.php ohkouchi@loop-az.jp-20110419134938-8843gis71oelhuff
data/class/util/SC_Utils.php ohkouchi@loop-az.jp-20110419134938-8843gis71oelhuff
html/user_data/packages/default/sql/update_bloc.sql ohkouchi@loop-az.jp-20110419134938-8843gis71oelhuff- bzr:timestamp:
- 2011-04-19 22:52:31.440999985 +0900
- bzr:user-agent:
- bzr2.2.1+bzr-svn1.0.4
- svn:original-date:
- 2011-04-19T13:52:31.441000Z
- Location:
- branches/version-2_11-dev/data/class/pages/admin/design
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_11-dev/data/class/pages/admin/design/LC_Page_Admin_Design_Template.php
r20764 r20863 71 71 * Page のアクション. 72 72 * 73 * FIXME ロジックを見直し74 *75 73 * @return void 76 74 */ 77 75 function action() { 78 // 端末種別IDを取得 79 if (isset($_REQUEST['device_type_id']) 80 && is_numeric($_REQUEST['device_type_id'])) { 81 $device_type_id = $_REQUEST['device_type_id']; 76 $objFormParam = new SC_FormParam_Ex(); 77 $this->lfInitParam($objFormParam); 78 $objFormParam->setParam($_REQUEST); 79 $objFormParam->convParam(); 80 81 $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC); 82 $this->tpl_select = $this->getTemplateName($this->device_type_id); 83 $template_code = $objFormParam->getValue('template_code'); 84 85 switch($this->getMode()) { 86 87 // 登録ボタン押下時 88 case 'register': 89 $this->arrErr = $objFormParam->checkError(); 90 if (SC_Utils_Ex::isBlank($this->arrErr)) { 91 if ($this->doRegister($template_code, $this->device_type_id)) { 92 $this->tpl_select = $template_code; 93 $this->tpl_onload = "alert('登録が完了しました。');"; 94 } 95 } 96 break; 97 98 // 削除ボタン押下時 99 case 'delete': 100 if ($objFormParam->checkError()) { 101 SC_Utils_Ex::sfDispError(''); 102 } 103 $this->arrErr = $objFormParam->checkError(); 104 if (SC_Utils_Ex::isBlank($this->arrErr)) { 105 if ($this->doDelete($template_code, $this->device_type_id)) { 106 $this->tpl_onload = "alert('削除が完了しました。');"; 107 } 108 } 109 break; 110 111 // downloadボタン押下時 112 case 'download': 113 $this->arrErr = $objFormParam->checkError(); 114 if (SC_Utils_Ex::isBlank($this->arrErr)) { 115 if ($this->doDownload($template_code) !== false) { 116 // ブラウザに出力し, 終了する 117 exit; 118 } 119 } 120 break; 121 122 default: 123 break; 124 } 125 126 if (!$is_error) { 127 $this->templates = $this->getAllTemplates($this->device_type_id); 82 128 } else { 83 $device_type_id = DEVICE_TYPE_PC; 84 } 85 86 //サブタイトルの追加 87 $this->tpl_subtitle .= ' - ' . $this->arrDeviceType[$device_type_id]; 88 89 $this->tpl_select = $this->getTemplateName($device_type_id); 90 91 $objView = new SC_AdminView_Ex(); 92 93 switch($this->getMode()) { 94 95 // 登録ボタン押下時 96 case 'register': 97 // パラメータ検証 98 $objForm = $this->lfInitRegister(); 99 if ($objForm->checkError()) { 100 SC_Utils_Ex::sfDispError(''); 101 } 102 103 $template_code = $objForm->getValue('template_code'); 104 $this->tpl_select = $template_code; 105 106 if($template_code == "") { 107 $template_code = $this->getTemplateName($device_type_id, true); 108 } 109 110 // DBへ使用するテンプレートを登録 111 $this->lfRegisterTemplate($template_code); 112 113 // XXX コンパイルファイルのクリア処理を行う 114 $objView->_smarty->clear_compiled_tpl(); 115 116 // ブロック位置を更新 117 $this->lfChangeBloc($template_code); 118 119 // 完了メッセージ 120 $this->tpl_onload="alert('登録が完了しました。');"; 121 break; 122 123 // 削除ボタン押下時 124 case 'delete': 125 // パラメータ検証 126 $objForm = $this->lfInitDelete(); 127 if ($objForm->checkError()) { 128 SC_Utils_Ex::sfDispError(''); 129 } 130 131 //現在使用中のテンプレートとデフォルトのテンプレートは削除できないようにする 132 $template_code = $objForm->getValue('template_code_temp'); 133 if ($template_code == $this->getTemplateName($device_type_id) 134 || $template_code == $this->getTemplateName($device_type_id, true)) { 135 $this->tpl_onload = "alert('デフォルトテンプレートと、選択中のテンプレートは削除出来ません');"; 136 break; 137 } 138 $this->lfDeleteTemplate($template_code); 139 break; 140 141 // downloadボタン押下時 142 case 'download': 143 // パラメータ検証 144 $objForm = $this->lfInitDownload(); 145 $template_code = $objForm->getValue('template_code_temp'); 146 // ユーザデータの下のファイルも保存する。 147 $from_dir = USER_TEMPLATE_REALDIR . $template_code . "/"; 148 $to_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/"; 149 SC_Utils_Ex::sfMakeDir($to_dir); 150 SC_Utils_Ex::sfCopyDir($from_dir, $to_dir); 151 SC_Helper_FileManager_Ex::downloadArchiveFiles(SMARTY_TEMPLATES_REALDIR . $template_code); 152 break; 153 154 // プレビューボタン押下時 155 case 'preview': 156 break; 157 158 default: 159 break; 160 } 161 162 $this->templates = $this->lfGetAllTemplates($device_type_id); 163 $this->now_template = TEMPLATE_NAME; 164 $this->device_type_id = $device_type_id; 129 // 画面にエラー表示しないため, ログ出力 130 GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true)); 131 } 132 $this->tpl_subtitle .= ' - ' . $this->arrDeviceType[$this->device_type_id]; 165 133 } 166 134 … … 174 142 } 175 143 176 function lfInitRegister() { 177 $objForm = new SC_FormParam_Ex(); 178 $objForm->addParam( 179 'template_code', 'template_code', STEXT_LEN, '', 180 array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") 181 ); 182 $objForm->setParam($_POST); 183 184 return $objForm; 185 } 186 187 function lfInitDelete() { 188 $objForm = new SC_FormParam_Ex(); 189 $objForm->addParam( 190 'template_code_temp', 'template_code_temp', STEXT_LEN, '', 191 array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") 192 ); 193 $objForm->setParam($_POST); 194 195 return $objForm; 196 } 197 198 function lfInitDownload() { 199 $objForm = new SC_FormParam_Ex(); 200 $objForm->addParam( 201 'template_code_temp', 'template_code_temp', STEXT_LEN, '', 202 array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") 203 ); 204 $objForm->setParam($_POST); 205 206 return $objForm; 207 } 208 209 /** 210 * 使用するテンプレートをDBへ登録する 211 */ 212 function lfRegisterTemplate($template_code, $device_type_id) { 144 /** 145 * パラメータ情報の初期化 146 * 147 * @param object $objFormParam SC_FormParamインスタンス 148 * @return void 149 */ 150 function lfInitParam(&$objFormParam) { 151 $objFormParam->addParam("端末種別ID", "device_type_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); 152 $objFormParam->addParam('template_code', 'template_code', STEXT_LEN, 'a', array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")); 153 } 154 155 /** 156 * 使用するテンプレートを設定する. 157 * 158 * テンプレートをマスタデータに登録する. 159 * 160 * @param string $template_code テンプレートコード 161 * @param integer $device_type_id 端末種別ID 162 * @return void 163 */ 164 function doUpdateMasterData($template_code, $device_type_id) { 213 165 $masterData = new SC_DB_MasterData_Ex(); 214 166 … … 222 174 $defineName = 'SMARTPHONE_' . $defineName; 223 175 break; 176 224 177 case DEVICE_TYPE_PC: 225 178 default: 226 179 } 227 180 228 $data = array($defineName => var_export($template_code, TRUE));229 230 181 // DBのデータを更新 231 $masterData->updateMasterData('mtb_constants', array(), $data); 182 $arrData = array($defineName => var_export($template_code, true)); 183 $masterData->updateMasterData('mtb_constants', array(), $arrData); 232 184 233 185 // キャッシュを生成 … … 236 188 237 189 /** 238 * ブロック位置の更新 239 */ 240 function lfChangeBloc($template_code) { 241 $objQuery = new SC_Query_Ex(); 242 /* 243 * FIXME 各端末に合わせて作成する必要あり 244 * $filepath = USER_TEMPLATE_REALDIR. $template_code. "/sql/update_bloc.sql"; 245 */ 246 247 // ブロック位置更新SQLファイル有 248 if(file_exists($filepath)) { 249 if($fp = fopen($filepath, 'r')) { 250 $sql = fread($fp, filesize($filepath)); 251 fclose($fp); 252 } 190 * ブロック位置の更新. 191 * 192 * ブロック位置を更新する SQL を実行する. 193 * この SQL は, 各端末に合わせて実行する必要がある 194 * 195 * @param string $filepath SQLのファイルパス 196 * @return void 197 */ 198 function updateBloc($filepath) { 199 $sql = file_get_contents($filepath); 200 if ($sql !== false) { 253 201 // 改行、タブを1スペースに変換 254 202 $sql = preg_replace("/[\r\n\t]/", " " ,$sql); 255 203 $sql_split = explode(";", $sql); 256 foreach($sql_split as $key => $val){ 204 $objQuery =& SC_Query_Ex::getSingletonInstance(); 205 foreach($sql_split as $val){ 257 206 if (trim($val) != "") { 258 207 $objQuery->query($val); … … 263 212 264 213 /** 265 * テンプレートパッケージの削除 266 */ 267 function lfDeleteTemplate($template_code) { 268 // DB更新 269 $objQuery = new SC_Query_Ex(); 270 $objQuery->delete('dtb_templates', 'template_code = ?', array($template_code)); 271 // テンプレート削除 272 $templates_dir = SMARTY_TEMPLATES_REALDIR. $template_code. "/"; 273 SC_Utils_Ex::sfDelFile($templates_dir); 274 // コンパイル削除 275 $templates_c_dir = DATA_REALDIR. "Smarty/templates_c/". $template_code. "/"; 276 SC_Utils_Ex::sfDelFile($templates_c_dir); 277 // ユーザーデータ削除 278 $user_dir = USER_TEMPLATE_REALDIR. $template_code. "/"; 279 SC_Utils_Ex::sfDelFile($user_dir); 280 } 281 282 function lfGetAllTemplates($device_type_id) { 283 $objQuery = new SC_Query_Ex(); 284 $arrRet = $objQuery->select('*', 'dtb_templates', "device_type_id = ?", array($device_type_id)); 285 if (empty($arrRet)) return array(); 286 287 return $arrRet; 288 } 289 290 /* 291 * 関数名:lfGetFileContents() 292 * 引数1 :ファイルパス 293 * 説明 :ファイル読込 294 * 戻り値:無し 295 */ 296 function lfGetFileContents($read_file) { 297 298 if(file_exists($read_file)) { 299 $contents = file_get_contents($read_file); 214 * テンプレートパッケージの削除. 215 * 216 * @param string $template_code テンプレートコード 217 * @param integer $device_type_id 端末種別ID 218 * @return boolean 成功した場合 true; 失敗した場合 false 219 */ 220 function doDelete($template_code, $device_type_id) { 221 if ($template_code == $this->getTemplateName($device_type_id) 222 || $template_code == $this->getTemplateName($device_type_id, true)) { 223 $this->arrErr['err'] = "※ デフォルトテンプレートと、選択中のテンプレートは削除出来ません<br />"; 224 return false; 300 225 } else { 301 $contents = ""; 302 } 303 304 return $contents; 226 $objQuery =& SC_Query_Ex::getSingletonInstance(); 227 $objQuery->begin(); 228 $objQuery->delete('dtb_templates', 'template_code = ? AND device_type_id = ?', 229 array($template_code, $device_type_id)); 230 231 $error = "※ テンプレートの削除ができませんでした<br />"; 232 // テンプレート削除 233 $templates_dir = SMARTY_TEMPLATES_REALDIR . $template_code. "/"; 234 if (SC_Utils_Ex::sfDelFile($templates_dir) === false) { 235 $this->arrErr['err'] = $error; 236 $objQuery->rollback(); 237 return false; 238 } 239 // ユーザーデータ削除 240 $user_dir = USER_TEMPLATE_REALDIR. $template_code. "/"; 241 if (SC_Utils_Ex::sfDelFile($user_dir) === false) { 242 $this->arrErr['err'] = $error; 243 $objQuery->rollback(); 244 return false; 245 } 246 247 // コンパイル削除 248 $templates_c_dir = DATA_REALDIR. "Smarty/templates_c/". $template_code. "/"; 249 if (SC_Utils_Ex::sfDelFile($templates_c_dir) === false) { 250 $this->arrErr['err'] = $error; 251 $objQuery->rollback(); 252 return false; 253 } 254 $objQuery->commit(); 255 return true; 256 } 257 } 258 259 /** 260 * 登録を実行する. 261 * 262 * 失敗した場合は, エラーメッセージを出力し, false を返す. 263 * 264 * @param string $template_code テンプレートコード 265 * @param integer $device_type_id 端末種別ID 266 * @return boolean 成功した場合 true; 失敗した場合 false 267 */ 268 function doRegister($template_code, $device_type_id) { 269 270 $tpl_dir = USER_TEMPLATE_REALDIR . $template_code . '/'; 271 if (!is_dir($tpl_dir)) { 272 $this->arrErr['err'] = '※ ' . $tpl_dir . 'が見つかりません<br />'; 273 return false; 274 } 275 276 // 更新SQLファイルが存在する場合はブロック位置を更新 277 $sql_file = $tpl_dir . "sql/update_bloc.sql"; 278 if (file_exists($sql_file)) { 279 $this->updateBloc($sql_file); 280 } 281 282 $this->doUpdateMasterData($template_code, $device_type_id); 283 // コンパイルファイルのクリア処理 284 $objView = new SC_AdminView_Ex(); 285 $objView->_smarty->clear_compiled_tpl(); 286 return true; 287 } 288 289 /** 290 * ダウンロードを実行する. 291 * 292 * 指定のテンプレートをアーカイブし, ブラウザに出力する. 293 * 失敗した場合は, エラーメッセージを出力し, false を返す. 294 * 295 * @param string $template_code テンプレートコード 296 * @return boolean 成功した場合 true; 失敗した場合 false 297 */ 298 function doDownload($template_code) { 299 $from_dir = USER_TEMPLATE_REALDIR . $template_code . "/"; 300 $to_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/"; 301 if (SC_Utils_Ex::recursiveMkdir($to_dir) === false) { 302 $this->arrErr['err'] = '※ ディレクトリの作成に失敗しました<br />'; 303 return false; 304 } 305 SC_Utils_Ex::sfCopyDir($from_dir, $to_dir); 306 if (SC_Helper_FileManager_Ex::downloadArchiveFiles(SMARTY_TEMPLATES_REALDIR . $template_code, $template_code) === false) { 307 $this->arrErr['err'] = '※ アーカイブファイルの作成に失敗しました<br />'; 308 return false; 309 } 310 return true; 311 } 312 313 /** 314 * テンプレート情報を取得する. 315 * 316 * @param integer $device_type_id 端末種別ID 317 * @return array テンプレート情報の配列 318 */ 319 function getAllTemplates($device_type_id) { 320 $objQuery =& SC_Query_Ex::getSingletonInstance(); 321 return $objQuery->select('*', 'dtb_templates', "device_type_id = ?", array($device_type_id)); 305 322 } 306 323 307 324 /** 308 325 * テンプレート名を返す. 326 * 327 * @param integer $device_type_id 端末種別ID 328 * @param boolean $isDefault デフォルトテンプレート名を返す場合 true 329 * @return string テンプレート名 309 330 */ 310 331 function getTemplateName($device_type_id, $isDefault = false) { -
branches/version-2_11-dev/data/class/pages/admin/design/LC_Page_Admin_Design_UpDown.php
r20764 r20863 76 76 */ 77 77 function action() { 78 // 端末種別IDを取得 79 if (isset($_REQUEST['device_type_id']) 80 && is_numeric($_REQUEST['device_type_id'])) { 81 $device_type_id = $_REQUEST['device_type_id']; 82 } else { 83 $device_type_id = DEVICE_TYPE_PC; 84 } 85 86 //サブタイトルの追加 87 $this->tpl_subtitle .= ' - ' . $this->arrDeviceType[$device_type_id]; 78 $objFormParam = new SC_FormParam_Ex(); 79 $this->lfInitParam($objFormParam); 80 $objFormParam->setParam($_REQUEST); 81 $objFormParam->convParam(); 82 83 $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC); 88 84 89 85 switch($this->getMode()) { 90 91 // ダウンロードボタン押下時の処理 92 case 'download': 86 // アップロードボタン押下時の処理 87 case 'upload': 88 $objUpFile = $this->lfInitUploadFile($objFormParam); 89 $this->arrErr = $this->lfCheckError($objFormParam, $objUpFile); 90 if (SC_Utils_Ex::isBlank($this->arrErr)) { 91 if ($this->doUpload($objFormParam, $objUpFile)) { 92 $this->tpl_onload = "alert('テンプレートファイルをアップロードしました。');"; 93 $objFormParam->setValue('template_name', ''); 94 $objFormParam->setValue('template_code', ''); 95 } 96 } 93 97 break; 94 // アップロードボタン押下時の処理 95 case 'upload': 96 // フォームパラメータ初期化 97 $objForm = $this->lfInitUpload(); 98 // エラーチェック 99 if ($arrErr = $this->lfValidateUpload($objForm)) { 100 $this->arrErr = $arrErr; 101 $this->arrForm = $objForm->getFormParamList(); 102 break; 103 } 104 // アップロードファイル初期化 105 $objUpFile = $this->lfInitUploadFile($objForm); 106 // 一時ファイルへ保存 107 $errMsg = $objUpFile->makeTempFile('template_file', false); 108 // 書き込みエラーチェック 109 if(isset($errMsg)) { 110 $this->arrErr['template_file'] = $errMsg; 111 $this->arrForm = $objForm->getFormParamList(); 112 break; 113 } 114 $this->lfAddTemplates($objForm, $objUpFile, $device_type_id); 115 $this->tpl_onload = "alert('テンプレートファイルをアップロードしました。');"; 116 break; 117 118 // 初回表示 98 119 99 default: 120 100 break; 121 101 } 122 $this->device_type_id = $device_type_id; 102 //サブタイトルの追加 103 $this->tpl_subtitle .= ' - ' . $this->arrDeviceType[$this->device_type_id]; 104 $this->arrForm = $objFormParam->getFormParamList(); 123 105 } 124 106 … … 142 124 $objUpFile = new SC_UploadFile_Ex(TEMPLATE_TEMP_REALDIR, $pkg_dir); 143 125 $objUpFile->addFile("テンプレートファイル", 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false); 144 145 126 return $objUpFile; 146 127 } 128 147 129 /** 148 130 * SC_FormParamクラスの初期化. 149 131 * 150 * @param void 151 * @return object SC_FormParamのインスタンス 152 */ 153 function lfInitUpload() { 154 $objForm = new SC_FormParam; 155 156 $objForm->addParam("テンプレートコード", "template_code", STEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")); 157 $objForm->addParam("テンプレート名", "template_name", STEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK")); 158 $objForm->setParam($_POST); 159 160 return $objForm; 161 } 132 * @param SC_FormParam $objFormParam SC_FormParamのインスタンス 133 * @return void 134 */ 135 function lfInitParam(&$objFormParam) { 136 $objFormParam->addParam("テンプレートコード", "template_code", STEXT_LEN, 'a', array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")); 137 $objFormParam->addParam("テンプレート名", "template_name", STEXT_LEN, 'KVa', array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK")); 138 $objFormParam->addParam("端末種別ID", "device_type_id", INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); 139 } 140 162 141 /** 163 142 * uploadモードのパラメータ検証を行う. 164 143 * 165 * @param object $objForm SC_FormParamのインスタンス 144 * @param object $objFormParam SC_FormParamのインスタンス 145 * @param object $objUpFile SC_UploadFileのインスタンス 166 146 * @return array エラー情報を格納した連想配列, エラーが無ければ(多分)nullを返す 167 147 */ 168 function lfValidateUpload($objForm) { 169 $arrErr = $objForm->checkError(); 170 if (!empty($arrErr)) { 171 return $arrErr; 172 } 173 174 $arrForm = $objForm->getHashArray(); 148 function lfCheckError(&$objFormParam, &$objUpFile) { 149 $arrErr = $objFormParam->checkError(); 150 $template_code = $objFormParam->getValue('template_code'); 175 151 176 152 // 同名のフォルダが存在する場合はエラー 177 if (file_exists(USER_TEMPLATE_REALDIR . $arrForm['template_code'])) {153 if (file_exists(USER_TEMPLATE_REALDIR . $template_code)) { 178 154 $arrErr['template_code'] = "※ 同名のファイルがすでに存在します。<br/>"; 179 155 } … … 184 160 SMARTPHONE_DEFAULT_TEMPLATE_NAME, 185 161 DEFAULT_TEMPLATE_NAME); 186 if (in_array($arrForm['template_code'], $arrIgnoreCode)) {162 if (in_array($template_code, $arrIgnoreCode)) { 187 163 $arrErr['template_code'] = "※ このテンプレートコードは使用できません。<br/>"; 188 164 } 189 165 190 166 // DBにすでに登録されていないかチェック 191 $objQuery = new SC_Query_Ex();192 $ ret = $objQuery->count("dtb_templates", "template_code = ?", array($arrForm['template_code']));193 if (!empty($ret)) {167 $objQuery =& SC_Query_Ex::getSingletonInstance(); 168 $count = $objQuery->count("dtb_templates", "template_code = ?", array($template_code)); 169 if ($count > 0) { 194 170 $arrErr['template_code'] = "※ すでに登録されているテンプレートコードです。<br/>"; 195 171 } 196 172 197 // ファイルの拡張子チェック(.tar/tar.gzのみ許可) 198 $errFlag = true; 199 $array_ext = explode(".", $_FILES['template_file']['name']); 200 $ext = $array_ext[ count ( $array_ext ) - 1 ]; 201 $ext = strtolower($ext); 202 // .tarチェック 203 if ($ext == 'tar') { 204 $errFlag = false; 205 } 206 $ext = $array_ext[ count ( $array_ext ) - 2 ].".".$ext; 207 $ext = strtolower($ext); 208 // .tar.gzチェック 209 if ($ext== 'tar.gz') { 210 $errFlag = false; 211 } 212 213 if($errFlag) { 214 $arrErr['template_file'] = "※ アップロードするテンプレートファイルで許可されている形式は、tar/tar.gzです。<br />"; 215 } 216 173 /* 174 * ファイル形式チェック 175 * ファイルが壊れていることも考慮して, 展開可能かチェックする. 176 */ 177 $tar = new Archive_Tar($_FILES['template_file']['tmp_name'], true); 178 $arrArchive = $tar->listContent(); 179 if (!is_array($arrArchive)) { 180 $arrErr['template_file'] = "※ テンプレートファイルが解凍できません。許可されている形式は、tar/tar.gzです。<br />"; 181 } 182 183 $arrErr['template_file'] = $objUpFile->makeTempFile('template_file', false); 217 184 return $arrErr; 218 185 } 186 219 187 /** 220 188 * DBおよびファイルシステムにテンプレートパッケージを追加する. 221 189 * 222 * @param object $objForm SC_FormParamのインスタンス 190 * エラーが発生した場合は, エラーを出力し, false を返す. 191 * 192 * @param object $objFormParam SC_FormParamのインスタンス 223 193 * @param object $objUpFile SC_UploadFileのインスタンス 224 * @return void 225 */ 226 function lfAddTemplates($objForm, $objUpFile, $device_type_id) { 227 $template_code = $objForm->getValue('template_code'); 194 * @return boolean 成功した場合 true; 失敗した場合 false 195 */ 196 function doUpload($objFormParam, $objUpFile) { 197 $template_code = $objFormParam->getValue('template_code'); 198 $template_name = $objFormParam->getValue('template_name'); 199 $device_type_id = $objFormParam->getValue('device_type_id'); 200 228 201 $template_dir = SMARTY_TEMPLATES_REALDIR . $template_code; 229 202 $compile_dir = DATA_REALDIR . "Smarty/templates_c/" . $template_code; 203 204 $objQuery =& SC_Query_Ex::getSingletonInstance(); 205 $objQuery->begin(); 206 207 $arrValues = array('template_code' => $template_code, 208 'device_type_id' => $device_type_id, 209 'template_name' => $template_name, 210 'create_date' => 'now()', 211 'update_date' => 'now()'); 212 $objQuery->insert('dtb_templates', $arrValues); 213 214 $is_error = false; 230 215 // フォルダ作成 231 if(!file_exists($template_dir)) { 232 mkdir($template_dir); 233 } 234 if(!file_exists($compile_dir)) { 235 mkdir($compile_dir); 216 if (!file_exists($template_dir)) { 217 if (!mkdir($template_dir)) { 218 $this->arrErr['err'] = "※ テンプレートフォルダが作成できませんでした。<br/>"; 219 $objQuery->rollback(); 220 return false; 221 } 222 } 223 if (!file_exists($compile_dir)) { 224 if (!mkdir($compile_dir)) { 225 $this->arrErr['err'] = "※ Smarty コンパイルフォルダが作成できませんでした。<br/>"; 226 $objQuery->rollback(); 227 return false; 228 } 236 229 } 237 230 … … 240 233 241 234 // 解凍 242 SC_Helper_FileManager_Ex::unpackFile($template_dir . "/" . $_FILES['template_file']['name']); 235 if (!SC_Helper_FileManager_Ex::unpackFile($template_dir . "/" . $_FILES['template_file']['name'])) { 236 $this->arrErr['err'] = "※ テンプレートファイルの解凍に失敗しました。<br/>"; 237 $objQuery->rollback(); 238 return false; 239 } 243 240 // ユーザデータの下のファイルをコピーする 244 241 $from_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/"; 245 242 $to_dir = USER_REALDIR . "packages/" . $template_code . "/"; 246 SC_Utils_Ex::sfMakeDir($to_dir); 243 if (!SC_Utils_Ex::recursiveMkdir($to_dir)) { 244 $this->arrErr['err'] = "※ " . $to_dir . " の作成に失敗しました。<br/>"; 245 $objQuery->rollback(); 246 return false; 247 } 247 248 SC_Utils_Ex::sfCopyDir($from_dir, $to_dir); 248 249 249 // DBにテンプレート情報を保存 250 $this->lfRegisterTemplates($objForm->getHashArray(), $device_type_id); 251 } 252 253 /** 254 * dtb_templatesへ入力内容を登録する. 255 * 256 * @param array $arrForm POSTされたパラメータ 257 * @return void 258 */ 259 function lfRegisterTemplates($arrForm, $device_type_id) { 260 $objQuery = new SC_Query_Ex(); 261 $sqlval = $arrForm; 262 $sqlval['device_type_id'] = $device_type_id; 263 $sqlval['create_date'] = "now()"; 264 $sqlval['update_date'] = "now()"; 265 $objQuery->insert('dtb_templates', $sqlval); 250 $objQuery->commit(); 251 return true; 266 252 } 267 253 }
Note: See TracChangeset
for help on using the changeset viewer.