Index: /trunk/admin/admin_blocks.php
===================================================================
--- /trunk/admin/admin_blocks.php	(revision 151)
+++ /trunk/admin/admin_blocks.php	(revision 151)
@@ -0,0 +1,17 @@
+<?php 
+
+include_once('./../../../include/cp_header.php');
+
+global $xoopsModule;
+$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
+$module_dir = $mydirname;
+//$module_dir = $xoopsModule->getInfo('dirname');
+
+if (file_exists(XOOPS_ROOT_PATH . '/modules/altsys/admin/index.php')){
+	header("Location: ".XOOPS_URL."/modules/altsys/admin/index.php?mode=admin&lib=altsys&page=myblocksadmin&dirname=$module_dir");	
+} else if (file_exists(XOOPS_ROOT_PATH . '/modules/legacy/admin/index.php')){
+	header("Location: ".XOOPS_URL."/modules/legacy/admin/index.php?action=BlockList");	
+} else {
+	header("Location: ".XOOPS_URL."/modules/system/admin.php?fct=blocksadmin&selmod=".$xoopsModule->getVar("mid"));
+}
+?>
Index: /trunk/admin/block_check.php
===================================================================
--- /trunk/admin/block_check.php	(revision 151)
+++ /trunk/admin/block_check.php	(revision 151)
@@ -0,0 +1,94 @@
+<?php 
+// $Id: xoops_version.php,v 1.8 2005/06/03 01:35:02 phppp Exp $
+//  ------------------------------------------------------------------------ //
+//                XOOPS - PHP Content Management System                      //
+//                    Copyright (c) 2000 XOOPS.org                           //
+//                       <http://www.xoops.org/>                             //
+//  ------------------------------------------------------------------------ //
+//  This program is free software; you can redistribute it and/or modify     //
+//  it under the terms of the GNU General Public License as published by     //
+//  the Free Software Foundation; either version 2 of the License, or        //
+//  (at your option) any later version.                                      //
+//                                                                           //
+//  You may not change or alter any portion of this comment or credits       //
+//  of supporting developers from this source code or any supporting         //
+//  source code which is considered copyrighted (c) material of the          //
+//  original comment or credit authors.                                      //
+//                                                                           //
+//  This program is distributed in the hope that it will be useful,          //
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
+//  GNU General Public License for more details.                             //
+//                                                                           //
+//  You should have received a copy of the GNU General Public License        //
+//  along with this program; if not, write to the Free Software              //
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
+//  ------------------------------------------------------------------------ //
+// Author: phppp (D.J.)                                                      //
+// URL: http://xoopsforge.com, http://xoops.org.cn                           //
+// ------------------------------------------------------------------------- //
+//include_once 'cp_functions.php';
+$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
+include_once('./../../../include/cp_header.php');
+xoops_cp_header();
+include_once(dirname(__FILE__) . '/../class/check_blocks_class.php');
+
+//BLOCK CHECK
+echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . 'Check ' . $mydirname . ' block table' . "</legend>";
+echo "<div style='padding: 8px;'>";
+
+$xoops_block_check =& xoops_block_check::getInstance();
+
+if ( !$xoops_block_check->is_admin() )
+{
+	include XOOPS_ROOT_PATH.'/footer.php';
+	exit();
+}
+
+switch ( $xoops_block_check->get_op() ) 
+{
+case "remove_block":
+	echo $xoops_block_check->remove_block();
+	break;
+
+default:
+	if ($xoops_block_check->check_blocks($mydirname)){
+			echo $xoops_block_check->get_message();
+			echo "<br /><br />";
+			echo _AM_XP_BLOCK_OK ;
+	} else {
+
+			echo $xoops_block_check->get_message();
+			echo "<br /><br />\n";
+			echo _AM_XP_BLOCK_NG."<br />\n";
+			echo _AM_XP_BLOCK_REPAIR_HOWTO."<br />\n"; 
+			echo '<form method="POST">'."\n";
+			echo _AM_XP_BLOCK_REPAIR_STEP1 .' : '."\n"; 
+			echo '<input type="submit" name="mid:'.$xoops_block_check->module_id.'" value="' . _AM_XP_BLOCK_REMOVE . ': '.$xoops_block_check->module_name.'" />'."<br />\n";
+			echo '&emsp;&emsp;&emsp;&emsp;&nbsp;';
+			echo _AM_XP_BLOCK_REMOVE_NOTE;
+			echo "</form>\n";
+			echo "<br />\n";
+			echo _AM_XP_BLOCK_REPAIR_STEP2 . ' : ' . _AM_XP_BLOCK_UPDATE . "<br />\n";
+			echo '&emsp;&emsp;&emsp;&emsp;&nbsp;';
+			echo '<a href="'.$xoops_block_check->update_link.'">' .$xoops_block_check->module_name . ' ' . _AM_XP_TO_MODELE_UPDATE .'</a>';
+			echo "<br />\n";
+			echo "<br />\n";
+			
+			echo _AM_XP_BLOCK_REPAIR_STEP3 . ' : ' . _AM_XP_BLOCK_ADMIN_SETTING . "<br />\n";
+			echo '&emsp;&emsp;&emsp;&emsp;&nbsp;';
+			echo '<a href="admin_blocks.php">' .$xoops_block_check->module_name . ' ' . _AM_XP_BLOCK_TO_SETTING .'</a>';
+			echo "<br />\n";
+	}
+	break;
+
+}
+
+//if ( $xoops_block_check->get_xoops_version() == '2.1' ) {
+//	$xoopsTpl->assign( 'xoops_contents', $cont );
+//} else {
+//}
+echo "</fieldset>";
+xoops_cp_footer();
+	
+?>
Index: /trunk/admin/menu.php
===================================================================
--- /trunk/admin/menu.php	(revision 150)
+++ /trunk/admin/menu.php	(revision 151)
@@ -46,3 +46,9 @@
 $adminmenu[$i++]['link'] = "admin/index.php";
 
+$adminmenu[$i]['title'] = _MI_MENU_BLOCK_ADMIN ;
+$adminmenu[$i++]['link'] = "admin/admin_blocks.php";
+
+$adminmenu[$i]['title'] = _MI_MENU_BLOCK_CHECK ;
+$adminmenu[$i++]['link'] = "admin/block_check.php";
+
 ?>
Index: /trunk/class/check_blocks_class.php
===================================================================
--- /trunk/class/check_blocks_class.php	(revision 151)
+++ /trunk/class/check_blocks_class.php	(revision 151)
@@ -0,0 +1,388 @@
+<?php
+
+//================================================================
+// check block table
+// 2007-10-10 K.OHWADA
+//================================================================
+
+//---------------------------------------------------------
+// this program works in XOOPS 2.0.16aJP, XOOPS Cube 2.1.2, XOOPS 2.0.17
+//
+// NOTE
+// xoops 2.0.16 JP  : class/xoopsblock.php and kernel/block.php are different
+// xoops cube 2.1.2 : class/xoopsblock.php and kernel/block.php are the same
+// xoops 2.0.17     : no token class
+//---------------------------------------------------------
+
+include_once dirname( __FILE__ ).'/../../../mainfile.php';
+include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
+
+//=========================================================
+// class xoops_block_check
+//=========================================================
+class xoops_block_check
+{
+	var $_TOKEN_NAME = 'block';
+	var $module_id        = 0;
+	var $_msg_array  = array();
+	var $_error_flag = false;
+	var $_xoops_version = '2.0';
+	var $_use_token     = false;
+	var $_blocks_check_array = array();
+	var $_all_ok_flag = true;
+	var $_module_dir = '';
+	var $module_name = '';
+	var $module_dirname = '';
+	var $remove_submit_form;
+	var $update_link;
+//---------------------------------------------------------
+// constructor
+//---------------------------------------------------------
+function xoops_block_check()
+{
+	$this->_detect_xoops_version();
+}
+
+function &getInstance()
+{
+	static $instance;
+	if (!isset($instance)) 
+	{
+		$instance = new xoops_block_check();
+	}
+	return $instance;
+}
+
+//--------------------------------------------------------
+// public
+//--------------------------------------------------------
+function get_message()
+{
+	return $this->_get_msg();
+}
+
+function get_op()
+{
+	$op  = '';
+	$mid = 0;
+	foreach ( $_POST as $k => $v )
+	{
+		if ( preg_match( "/^mid:/", $k ) )
+		{
+			$op  = 'remove_block';
+			$mid = intval( str_replace("mid:", "", $k) );
+			break;
+		}
+	}
+	$this->module_id = $mid;
+	return $op;
+}
+
+function check_blocks($module_dir)
+{
+	$this->_all_ok_flag = true;
+	$this->_module_dir = $module_dir;
+	$this->module_dirname = $module_dir;
+
+	if ( $this->_use_token )
+	{
+		$text = $this->_create_token();
+	}
+
+	$objs =& $this->_get_module_objects();
+	$obj = $objs[0];
+	if (!empty($obj)){
+		$this->module_id = $obj->getVar('mid', 'n');
+		$url = $this->_build_url_module_update( $this->module_dirname );
+		$this->update_link = $this->_build_url_module_update( $this->module_dirname );
+		$this->remove_submit_form .= '<input type="submit" name="mid:'.$this->module_id.'" value="Remove Block: '.$this->module_name.'" />'."\n";
+
+		return $this->_check_block_by_module( $obj );
+
+	} else {
+		$this->_err( 'Modules Not Found' );
+		return false;
+	}
+}
+
+function remove_block()
+{
+	$text = "<h1>Remove xoops block table</h1>\n";
+
+
+/*
+	if( $this->_use_token && !$this->_validate_token() ) 
+	{
+		$text .= '<h3 style="color:#ff0000">Token Error</h3>'."\n";
+		$text .= '<a href="block_check.php">Check Bloks</a>';
+		return $text;
+	}
+*/
+	$module_obj =& $this->_get_module_object_bymodule_id( $this->module_id );
+	if( !is_object($module_obj) ) 
+	{
+		$text .= '<h3 style="color:#ff0000">"No Module: mid='. $this->module_id ."</h3>\n";
+		$text .= "<br />\n";
+		$text .= '<a href="check_blocks.php">Check Bloks</a>';
+		return $text;
+	}
+
+	$ret = $this->_remove_block_bymodule_id( $this->module_id );
+	if ( $ret ) {
+		$text .= '<h4 style="color:#0000ff">Success</h4>'."\n";
+	} else {
+		$text .= '<h4 style="color:#ff0000">Failed</h4>'."\n";
+	}
+
+	$url = $this->_build_url_module_update( $module_obj->getVar('dirname', 'n') );
+	$text .= '<a href="'.$url.'">GO to Module Update: '.$module_obj->getVar('name', 's')."</a><br /><br />\n";
+//	$text .= '<a href="check_blocks.php">Check xoops block table</a><br />'."\n";
+
+	return $text;
+}
+
+//--------------------------------------------------------
+// private
+//--------------------------------------------------------
+function _check_block_by_module( &$module_obj )
+{
+	$this->_msg_array = array();
+
+	$mid      =  $module_obj->getVar('mid', 'n');
+	$mod_name =  $module_obj->getVar('name', 's');
+	$dirname  =  $module_obj->getVar('dirname', 'n');
+	$infos    =& $module_obj->getInfo('blocks');
+
+	$this->module_name = $mod_name ;
+	$this->module_dirname = $dirname ;
+	
+
+	if ( !is_array($infos) || !count($infos) )
+	{
+		$this->_msg( 'No block' );
+		return $this->_get_msg();
+	}
+
+
+	$block_objs =& $this->_get_block_object_orber_num_bymodule_id( $mid );
+
+	foreach ( $infos as $num => $info )
+	{
+		if ( !isset( $block_objs[ $num ] ) )
+		{
+			$this->_err( htmlspecialchars( $info['name'] ).': not exist in block table' );
+			$this->_all_ok_flag = false;
+
+			continue;
+		}
+
+		$this->_check_block_by_obj( $info, $block_objs[ $num ] );
+	}
+
+	if ($this->_all_ok_flag){
+	} else {		
+	}
+
+	return $this->_all_ok_flag;
+}
+
+function _check_block_by_obj( &$info, &$block_obj )
+{
+	$this->_error_flag = false;
+
+	$name = htmlspecialchars( $info['name'] );
+
+	if ( isset($info['file']) && ( $info['file'] != $block_obj->getVar('func_file', 'n') ) )
+	{
+		$this->_err( $name.': file unmatch' );
+	}
+
+	if ( isset($info['show_func']) && ( $info['show_func'] != $block_obj->getVar('show_func', 'n') ) )
+	{
+		$this->_err( $name.': show_func unmatch' );
+	}
+
+	if ( isset($info['edit_func']) && ( $info['edit_func'] != $block_obj->getVar('edit_func', 'n') ) )
+	{
+		$this->_err( $name.': edit_func unmatch' );
+	}
+
+	if ( isset($info['template']) && ( $info['template'] != $block_obj->getVar('template', 'n') ) )
+	{
+		$this->_err( $name.': template unmatch' );
+	}
+
+	if ( isset($info['options']) )
+	{
+		$option_arr_1 = explode( '|', $info['options'] );
+		$option_arr_2 = explode( '|', $block_obj->getVar('options', 'n') );
+
+		if ( count($option_arr_1) != count($option_arr_2) )
+		{
+			$this->_err( $name.': options count unmatch' );
+		}
+	}
+
+	if ( !$this->_error_flag )
+	{
+		$this->_msg( $name.': OK' );
+	} else {
+		$this->_all_ok_flag = false;
+	}
+
+}
+
+function _remove_block_bymodule_id( $mid )
+{
+	$error = false;
+	$objs =& $this->_get_block_object_bymodule_id( $mid );
+	foreach ( $objs as $obj )
+	{
+		$ret = $this->_delete_block( $obj );
+		if ( !$ret )
+		{	$error = true;	}
+	}
+	if ( $error )
+	{	return false;	}
+	return true;
+}
+
+function _msg( $msg )
+{
+	$this->_msg_array[] = '&emsp;' .$msg;
+}
+
+function _err( $msg )
+{
+	$this->_msg_array[] = '&emsp;' . $this->_highlight( $msg );
+	$this->_error_flag  = true;
+}
+
+function _get_msg()
+{
+	$msg = implode( "<br />\n", $this->_msg_array );
+	return $msg;
+}
+
+
+function _highlight( $msg )
+{
+	$text = null;
+	if ( $msg )
+	{
+		$text = '<span style="color: #ff0000;">'.$msg.'</span>';
+	}
+	return $text;
+}
+
+function _build_url_module_update( $dirname )
+{
+	if ( $this->_xoops_version == '2.1' ) {
+		$url = XOOPS_URL.'/modules/legacy/admin/index.php?action=ModuleUpdate&dirname='.$dirname;
+	} else {
+		$url = XOOPS_URL.'/modules/system/admin.php?fct=modulesadmin&op=update&module='.$dirname;
+	}
+	return $url;
+}
+
+//--------------------------------------------------------
+// user handler
+//--------------------------------------------------------
+function is_admin()
+{
+	global $xoopsUser;
+	if ( is_object($xoopsUser) && $xoopsUser->isAdmin() )
+	{	return true;	}
+	return false;
+}
+
+//--------------------------------------------------------
+// module handler
+//--------------------------------------------------------
+function &_get_module_objects()
+{
+	$criteria = new CriteriaCompo();
+	$criteria->add( new Criteria('isactive', '1', '=') );
+	$criteria->add( new Criteria('dirname', $this->_module_dir, '=') );
+
+	$module_handler =& xoops_gethandler('module');
+	$objs           =& $module_handler->getObjects( $criteria );
+	return $objs;
+}
+
+function &_get_module_object_bymodule_id( $mid )
+{
+	$module_handler =& xoops_gethandler('module');
+	$obj            =& $module_handler->get( $mid );
+	return $obj;
+}
+
+//--------------------------------------------------------
+// block handler
+//--------------------------------------------------------
+function &_get_block_object_orber_num_bymodule_id( $mid )
+{
+	$arr  = array();
+	$objs =& $this->_get_block_object_bymodule_id( $mid );
+	foreach ( $objs as $obj )
+	{
+		$arr[ $obj->getVar('func_num', 'n') ] = $obj;
+	}
+	return $arr;
+}
+
+function &_get_block_object_bymodule_id( $mid, $asobject=true )
+{
+	$objs =& xoopsBlock::getByModule( $mid, $asobject );
+	return $objs;
+}
+
+function _delete_block( &$obj )
+{
+// NOT use xoops_gethandler in xoops 2.0.16jp
+	return $obj->delete();
+}
+
+//--------------------------------------------------------
+// token handler
+//--------------------------------------------------------
+function _create_token()
+{
+	$token_handler =& xoops_gethandler('SingleToken');
+	$obj =& $token_handler->quickCreate( $this->_TOKEN_NAME );
+	return $obj->getHtml();
+}
+
+function _validate_token()
+{
+	$token_handler =& xoops_gethandler('SingleToken');
+	return $token_handler->quickValidate( $this->_TOKEN_NAME );
+}
+
+//--------------------------------------------------------
+// xoops version
+//--------------------------------------------------------
+function get_xoops_version()
+{
+	return $this->_xoops_version;
+}
+
+function _detect_xoops_version()
+{
+// very easy way
+	if ( preg_match("/XOOPS[\s+]Cube.*[\s+]2\.1/i", XOOPS_VERSION) )
+	{
+		$this->_xoops_version = '2.1';
+	}
+
+// xoops 2.0.17 has no token class
+	if ( file_exists( XOOPS_ROOT_PATH.'/class/token.php' ) ) 
+	{
+		$this->_use_token = true;
+	}
+}
+
+// --- class end ---
+}
+
+?>
Index: /trunk/include/onupdate.php
===================================================================
--- /trunk/include/onupdate.php	(revision 150)
+++ /trunk/include/onupdate.php	(revision 151)
@@ -136,8 +136,14 @@
 		$msgs[] = "$group_role table of XPressME was made.";
 	}
-	
+	if ( xpress_block_check($mydirname)) {
+		$msgs[] = '<span style="color:#ff0000;">Block Check OK</span>';
+	} else {
+		$msgs[] = "Block Check NG.  You need Repar Block on This Mobule 'Block Check' Menu";
+	}
+
 	// make templates
 	include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ;
 	$t_mess = xpress_templates_make($mid,$mydirname);
+	
 	$msgs = array_merge($msgs,$t_mess);
 	
@@ -206,3 +212,30 @@
 endif;
 
+if( ! function_exists( 'xpress_block_check' ) ) :
+function xpress_block_check($mydirname){
+	include_once(dirname(dirname(__FILE__)) . '/class/check_blocks_class.php');
+
+	$xoops_block_check =& xoops_block_check::getInstance();
+
+	if ( !$xoops_block_check->is_admin() )
+	{
+		$cont = 'Block Check Pass';
+		return cont;
+	}
+
+	switch ( $xoops_block_check->get_op() ) 
+	{
+		case "remove_block":
+			$cont = $xoops_block_check->remove_block();
+			break;
+
+		default:
+			$cont = $xoops_block_check->check_blocks($mydirname);
+			break;
+	}
+	return $cont;
+}
+endif;
+
+
 ?>
Index: /trunk/language/ja_utf8/admin.php
===================================================================
--- /trunk/language/ja_utf8/admin.php	(revision 150)
+++ /trunk/language/ja_utf8/admin.php	(revision 151)
@@ -8,4 +8,19 @@
 	define("_AM_XPRESS_ARTICLES","記事数");
 	define("_AM_XPRESS_AUTHORS","投稿者数");
+
+// Block Check	
+	define("_AM_XP_BLOCK_OK","ブロックは正常です。");
+	define("_AM_XP_BLOCK_NG","異常ブロックがあります。");
+	define("_AM_XP_BLOCK_REPAIR_HOWTO","以下の手順に従ってブロックを修正してください。");
+	define("_AM_XP_BLOCK_REPAIR_STEP1","ステップ 1");
+	define("_AM_XP_BLOCK_REMOVE","ブロックを削除");
+	define("_AM_XP_BLOCK_REMOVE_NOTE","注意: モジュールのブロックがデータベースから<b>削除</b>されます。");
+	define("_AM_XP_BLOCK_REPAIR_STEP2","ステップ 2");
+	define("_AM_XP_BLOCK_UPDATE","モジュールをアップデートして、ブロックを再構築します。");
+	define("_AM_XP_TO_MODELE_UPDATE","モジュールアップデートへ");
+	define("_AM_XP_BLOCK_REPAIR_STEP3","ステップ 3");
+	define("_AM_XP_BLOCK_ADMIN_SETTING","ブロックの配置とアクセス権限を再設定します。");
+	define("_AM_XP_BLOCK_TO_SETTING","ブロック権限の設定へ");
+	
 	
 }
Index: /trunk/language/ja_utf8/modinfo.php
===================================================================
--- /trunk/language/ja_utf8/modinfo.php	(revision 150)
+++ /trunk/language/ja_utf8/modinfo.php	(revision 151)
@@ -5,4 +5,6 @@
 	// The name of this module admin menu
 	define("_MI_MENU_SYS_INFO","システム情報");
+	define("_MI_MENU_BLOCK_ADMIN","ブロック権限");
+	define("_MI_MENU_BLOCK_CHECK","ブロックチェック");
 	
 	// The name of this module
