'.htmlspecialchars($target_file_path).' copy from ' . htmlspecialchars($file);
				} else {
					$msgs[] = 'ERROR: Could not copy template '.htmlspecialchars($target_file_name).' from ' . htmlspecialchars($file). '(check templates directory permision (777))';
				}					
				$tplfile =& $tplfile_handler->create() ;
				if ($rcd) {
					$mtime = intval( @filemtime( $target_file_path ) ) ;
					$tplfile->setVar( 'tpl_source' , file_get_contents( $target_file_path ) , true ) ;
				} else {
					$mtime = intval( @filemtime( $file_path ) ) ;
					$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
				}
				$tplfile->setVar( 'tpl_refid' , $mid ) ;
				$tplfile->setVar( 'tpl_tplset' , 'default' ) ;
				$tplfile->setVar( 'tpl_file' , $target_file_name ) ;
				$tplfile->setVar( 'tpl_desc' , '' , true ) ;
				$tplfile->setVar( 'tpl_module' , $mydirname ) ;
				$tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
				$tplfile->setVar( 'tpl_lastimported' , 0 ) ;
				$tplfile->setVar( 'tpl_type' , 'module' ) ;
				if( ! $tplfile_handler->insert( $tplfile ) ) {
					$msgs[] = 'ERROR: Could not insert template '.htmlspecialchars($target_file_name).' to the database.
';
				} else {
					$tplid = $tplfile->getVar( 'tpl_id' ) ;
					$msgs[] = 'Template '.htmlspecialchars($target_file_name) .' added to the database. (ID: '.$tplid.')
';
					// generate compiled file
					include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
					include_once XOOPS_ROOT_PATH.'/class/template.php' ;
					if( ! xoops_template_touch( $tplid ) ) {
						$msgs[] = 'ERROR: Failed compiling template '.htmlspecialchars($target_file_name).'.
';
					} else {
						$msgs[] = 'Template '.htmlspecialchars($target_file_name).' compiled.
';
					}
				}
			}
		}
		closedir( $handler ) ;
	}
	include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
	include_once XOOPS_ROOT_PATH.'/class/template.php' ;
	xoops_template_clear_module_cache( $mid ) ;
	return $msgs;
}
function is_template($file_name){
	if (empty($file_name)) return false;
	
	$temp_list = array(
		'recent_comments_block.html',
		'recent_posts_content_block.html',
		'recent_posts_list_block.html',
		'calender_block.html',
		'popular_posts_block.html',
		'archives_block.html',
		'authors_block.html',
		'index.html',
	);
	foreach($temp_list as $ck_file){
		if (strcmp($ck_file,$file_name) ==  0) return true;
	}
	return false;
}
?>