Index: trunk/xpressme_integration_kit/blocks/archives_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/archives_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/archives_block.php	(revision 463)
@@ -28,5 +28,5 @@
 
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$form .= "<br />";
 		$a_month = _MB_XP2_ARC_MONTH ;
@@ -62,5 +62,5 @@
 		$form .=  "</select><br/>";
 		
-		$form .= "<br />" . _MB_XP2_COUNT_ZERO_ALL . "  <input type='text' name='options[3]' value='" . $limit . "' />";
+		$form .= "<br />" . _MB_XP2_COUNT_ZERO_ALL . "  <input type='text' size='3' name='options[3]' value='" . $limit . "' />";
 		$form .= "<br />" . yes_no_radio_option('options[4]', _MB_XP2_SHOW_NUM_OF_POST , $show_post_count);
 		$form .= "<br />" . yes_no_radio_option('options[5]', _MB_XP2_SHOW_DROP_DOWN , $drop_down);
Index: trunk/xpressme_integration_kit/blocks/authors_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/authors_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/authors_block.php	(revision 463)
@@ -28,5 +28,5 @@
 			
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$form .= "<br />";
 		$form .= yes_no_radio_option('options[2]', _MB_XP2_SHOW_NUM_OF_POST , $optioncount);
Index: trunk/xpressme_integration_kit/blocks/calender_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/calender_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/calender_block.php	(revision 463)
@@ -26,5 +26,5 @@
 
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$form .= "<br />";
 		$form .= _MB_XP2_SUN_COLOR .": <input type='text' name='options[2]' value='" . $sun_color . "' /><br />\n";
Index: trunk/xpressme_integration_kit/blocks/category_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/category_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/category_block.php	(revision 463)
@@ -35,5 +35,5 @@
 
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$form .= "<br />";
 		$form .= _MB_XP2_CAT_ALL_STR . "  <input type='text' name='options[2]' value='" . $show_option_all . "' /><br />";
Index: trunk/xpressme_integration_kit/blocks/enhanced_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/enhanced_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/enhanced_block.php	(revision 463)
@@ -19,4 +19,5 @@
 		$mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
 		$this_template = empty( $options[1] ) ? 'db:'.$mydirname.'_enhanced_block.html' : trim( $options[1] );
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$include_file = empty( $options[2] ) ? '' : $options[2] ;
 		
Index: trunk/xpressme_integration_kit/blocks/meta_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/meta_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/meta_block.php	(revision 463)
@@ -31,5 +31,5 @@
 
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$form .= "<br />";
 		$form .= yes_no_radio_option('options[2]', _MB_XP2_META_WP_LINK , $wp_link) . "<br />\n";
Index: trunk/xpressme_integration_kit/blocks/page_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/page_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/page_block.php	(revision 463)
@@ -35,5 +35,5 @@
 
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$form .= "<br />";
 		$form .= _MB_XP2_PAGE_ORDERBY .": ";
Index: trunk/xpressme_integration_kit/blocks/popular_posts_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/popular_posts_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/popular_posts_block.php	(revision 463)
@@ -30,5 +30,5 @@
 
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />\n";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$form .= "<br />\n";
 		$form .= _MB_XP2_COUNT .": <input type='text' name='options[2]' value='" . $disp_count . "' /><br />\n";
Index: trunk/xpressme_integration_kit/blocks/recent_comments_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/recent_comments_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/recent_comments_block.php	(revision 463)
@@ -30,8 +30,8 @@
 		
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />\n";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$form .= "<br />";
-		$form .= _MB_XP2_COUNT .": <input type='text' name='options[2]' value='" . $disp_count . "' /><br />\n";
-		$form .= _MB_XP2_LENGTH .": <input type='text' name='options[3]' value='" . $disp_length . "' /><br />\n";
+		$form .= _MB_XP2_COUNT .": <input type='text' size='3' name='options[2]' value='" . $disp_count . "' /><br />\n";
+		$form .= _MB_XP2_LENGTH .": <input type='text' size='3' name='options[3]' value='" . $disp_length . "' /><br />\n";
 		$form .= _MB_XP2_DATE_FORMAT .": <input type='text' name='options[4]' value='" . $date_format . "' /><br />\n";
 		$form .= _MB_XP2_TIME_FORMAT .": <input type='text' name='options[5]' value='" . $time_format . "' /><br />\n";
Index: trunk/xpressme_integration_kit/blocks/recent_posts_content_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/recent_posts_content_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/recent_posts_content_block.php	(revision 463)
@@ -34,6 +34,6 @@
 		
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
-		$form .= _MB_XP2_COUNT .": <input type='text' name='options[2]' value='" . $disp_count . "' /><br />\n";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+		$form .= _MB_XP2_COUNT .": <input type='text' size='3' name='options[2]' value='" . $disp_count . "' /><br />\n";
 		$form .= yes_no_radio_option('options[3]', _MB_XP2_P_EXCERPT , $excerpt) . "<br />\n";
 		$form .= _MB_XP2_P_EXCERPT_SIZE .": <input type='text' name='options[4]' value='" . $excerpt_size . "' /><br />\n";
Index: trunk/xpressme_integration_kit/blocks/recent_posts_list_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/recent_posts_list_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/recent_posts_list_block.php	(revision 463)
@@ -31,9 +31,9 @@
 
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />\n";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$form .= "<br />\n";	
-		$form .= _MB_XP2_COUNT .": <input type='text' name='options[2]' value='" . $disp_count . "' /><br />\n";
-		$form .= _MB_XP2_REDNEW_DAYS .": <input type='text' name='options[3]' value='" . $disp_red . "' /><br />\n";
-		$form .= _MB_XP2_GREENNEW_DAYS .": <input type='text' name='options[4]' value='" . $disp_green . "' /><br />\n";
+		$form .= _MB_XP2_COUNT .": <input type='text' size='3' name='options[2]' value='" . $disp_count . "' /><br />\n";
+		$form .= _MB_XP2_REDNEW_DAYS .": <input type='text' size='3' name='options[3]' value='" . $disp_red . "' /><br />\n";
+		$form .= _MB_XP2_GREENNEW_DAYS .": <input type='text' size='3' name='options[4]' value='" . $disp_green . "' /><br />\n";
 		$form .= _MB_XP2_DATE_FORMAT .": <input type='text' name='options[5]' value='" . $date_format . "' /><br />\n";
 		$form .= _MB_XP2_TIME_FORMAT .": <input type='text' name='options[6]' value='" . $time_format . "' /><br />\n";
Index: trunk/xpressme_integration_kit/blocks/search_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/search_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/search_block.php	(revision 463)
@@ -25,7 +25,7 @@
 		
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$form .= "<br />";		
-		$form .= _MB_XP2_SEARCH_LENGTH .": <input type='text' name='options[2]' value='" . $disp_count . "' /><br />";
+		$form .= _MB_XP2_SEARCH_LENGTH .": <input type='text' size='3' name='options[2]' value='" . $disp_count . "' /><br />";
 //	    $form .="<br /><input type='text' size='60' name='options[2]' value='".htmlspecialchars($this_template,ENT_QUOTES)."' />";
 
Index: trunk/xpressme_integration_kit/blocks/tag_cloud_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/tag_cloud_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/tag_cloud_block.php	(revision 463)
@@ -32,5 +32,5 @@
 
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$form .= "<br />";
 		$form .= _MB_XP2_CLOUD_SMALLEST .": <input type='text' size='4' name='options[2]' value='" . $smallest . "' /><br />";
Index: trunk/xpressme_integration_kit/blocks/widget_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/widget_block.php	(revision 462)
+++ trunk/xpressme_integration_kit/blocks/widget_block.php	(revision 463)
@@ -46,5 +46,5 @@
 
 		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$form .= "<br />" . yes_no_radio_option('options[2]', _MB_XP2_WIDGET_TITLE_SHOW , $title_show);
 		$form .= "<br />";
Index: trunk/xpressme_integration_kit/include/xpress_block_render.php
===================================================================
--- trunk/xpressme_integration_kit/include/xpress_block_render.php	(revision 462)
+++ trunk/xpressme_integration_kit/include/xpress_block_render.php	(revision 463)
@@ -52,4 +52,18 @@
 			}
 			return $block_id;
+	}
+
+	function get_block_mid($mydirname)
+	{
+			$xoopsDB =& Database::getInstance();
+			$modules_tbl = $xoopsDB->prefix('modules');	
+
+			$sql = "SELECT mid FROM $modules_tbl WHERE dirname = '$mydirname'";
+			$result =  $xoopsDB->query($sql, 0, 0);
+			if ($xoopsDB->getRowsNum($result)  > 0){
+				$row = $xoopsDB->fetchArray($result);
+				$mid = $row['mid'];
+			}
+			return $mid;
 	}
 
@@ -190,12 +204,43 @@
 		$option = explode('|' , $block['options']);
 		
-		if (isset($option[1]))
+		if (isset($option[1])) {
 			$templates_file = $option[1];
-		else
+		} else {
 			$templates_file = 'db:'.$mydirname. '_' . str_replace(".php", ".html", $block_function_name);
+		}
+		
 		$tpl =& new XoopsTpl() ;
+		$tpl->template_dir = $xoops_config->module_path . '/templates';
+		if (!$tpl->template_exists($templates_file)){
+			$src_file_path = $xoops_config->module_path . '/templates/' .$mydirname. '_' . str_replace(".php", ".html", $block_function_name);
+			add_xpress_tpl($mydirname,$templates_file,$src_file_path);
+		}
 		$tpl->assign( 'block' , $block ) ;
 		$ret['content'] = $tpl->fetch( $templates_file ) ;
 		return $ret ;
+	}
+	
+	function add_xpress_tpl($mydirname,$templates='',$src_file_path){
+		global $wpdb,$xoops_config , $xoops_db;
+		
+		$mid = get_block_mid($mydirname);
+
+		$temp_parm = explode(':' , $templates);
+		if (empty($temp_parm[1])) {
+			$filename=$temp_parm[0];
+			$type = 'db';
+		} else  {
+			$filename=$temp_parm[1];
+			$type = $temp_parm[0];
+		}
+		$temp_file_path = $xoops_config->module_path . '/templates/'. $filename;
+		$pattern = '^' . $mydirname . '_';
+		if (preg_match('/' . $pattern . '/' , $filename, $match)){ // file prefix check
+			if (!file_exists($temp_file_path)){		// Repetition check
+				if (file_exists($src_file_path)){	// source file check
+					$rcd = copy($src_file_path, $temp_file_path);
+				}
+			}
+		}
 	}
 	
@@ -250,4 +295,5 @@
 	{
 		global $xoops_db,$xoops_config;
+		
 		$mid = get_xpress_modid();
 		$sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid AND visible = 1";
@@ -294,6 +340,5 @@
 			return $xu_row['conf_value'];
 		}
-	}
-	
+	}	
 }	
 ?>
Index: trunk/xpressme_integration_kit/language/english/blocks.php
===================================================================
--- trunk/xpressme_integration_kit/language/english/blocks.php	(revision 462)
+++ trunk/xpressme_integration_kit/language/english/blocks.php	(revision 463)
@@ -26,4 +26,5 @@
 	define("_MB_XP2_LIST","List");
 	define("_MB_XP2_FILE_NAME","Files Name");
+	define("_MB_XP2_THISTEMPLATE","Template");
 	
 // recent comment block	
Index: trunk/xpressme_integration_kit/language/ja_utf8/blocks.php
===================================================================
--- trunk/xpressme_integration_kit/language/ja_utf8/blocks.php	(revision 462)
+++ trunk/xpressme_integration_kit/language/ja_utf8/blocks.php	(revision 463)
@@ -26,4 +26,5 @@
 	define("_MB_XP2_LIST","リスト");
 	define("_MB_XP2_FILE_NAME","ファイル名");
+	define("_MB_XP2_THISTEMPLATE","このブロックのテンプレート");
 	
 // recent comment block	
