CREATE TABLE `bank_account` (
  `Serial` int(11) NOT NULL,
  `UUT` varchar(10) character set latin1 NOT NULL,
  `UUB` decimal(18,0) NOT NULL,
  `PieB` decimal(18,0) NOT NULL,
  `Credit` int(11) NOT NULL,
  `NowLoan` decimal(18,0) NOT NULL,
  `InquiryPassword` varchar(200) character set latin1 NOT NULL,
  `ConsumptionPassword` varchar(200) character set latin1 NOT NULL,
  `Freeze` int(11) NOT NULL,
  `MDate` datetime NOT NULL,
  `OnceMax` decimal(18,0) NOT NULL,
  `OneDayMax` decimal(18,0) NOT NULL,
  `LoanApprovalRemind` bit(1) NOT NULL,
  `ExchangeApprovalRemind` bit(1) NOT NULL,
  `AccountChangeRemind` bit(1) NOT NULL,
  `TodayConsume` decimal(18,0) NOT NULL,
  `LastConsumeTime` datetime NOT NULL,
  `Score` int(11) NOT NULL,
  `IRQ` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `bbs_forums` (
  `ID` int(11) NOT NULL,
  `Name` varchar(50) NOT NULL default '',
  `ParentID` int(11) default NULL,
  `Description` longtext,
  `Theme` varchar(50) default NULL,
  `SortOrder` int(11) default NULL,
  `Locked` bit(1) NOT NULL,
  `Hidden` bit(1) default NULL,
  `IsPublic` bit(1) NOT NULL,
  `LastTopicID` int(11) default NULL,
  `LastPosted` datetime default NULL,
  `LastAccount` varchar(50) character set latin1 default NULL,
  `LastNickName` varchar(50) character set latin1 default NULL,
  `NumTopics` int(11) default NULL,
  `NumPosts` int(11) default NULL,
  `CreateDate` datetime default NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `bbs_manage` (
  `ForumID` int(11) NOT NULL,
  `Account` varchar(50) character set utf8 NOT NULL default ''
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `bbs_personal_forums` (
  `PersonalModuleID` int(11) NOT NULL,
  `UserID` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `bbs_rank` (
  `RankID` int(11) NOT NULL,
  `Name` varchar(50) default NULL,
  `IsStart` bit(1) default NULL,
  `MixPosts` int(11) default NULL,
  `RankImage` tinytext
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `bbs_reply` (
  `ID` int(11) NOT NULL auto_increment,
  `TopicID` int(11) NOT NULL,
  `Account` varchar(50) NOT NULL default '',
  `Subject` tinytext NOT NULL,
  `Content` mediumtext NOT NULL,
  `ReplyDate` datetime NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `bbs_topic` (
  `ID` int(11) NOT NULL auto_increment,
  `Account` varchar(50) NOT NULL default '',
  `Type` int(11) NOT NULL,
  `Subject` tinytext NOT NULL,
  `Content` mediumtext NOT NULL,
  `PublishDate` datetime NOT NULL,
  `ForumID` int(11) NOT NULL,
  `PersonalForumID` int(11) NOT NULL,
  `Status` int(11) NOT NULL,
  `ReplyCount` int(11) NOT NULL,
  `ReadCount` int(11) NOT NULL,
  `LastReplyAccount` varchar(50) NOT NULL default '',
  `LastReplyDate` datetime NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `bbs_userconfig` (
  `Account` varchar(50) character set latin1 NOT NULL,
  `signature` longtext,
  `RankID` int(11) default NULL,
  `Approved` bit(1) default NULL,
  `Theme` varchar(50) default NULL,
  `NumTopics` int(11) default NULL,
  `NumReply` int(11) default NULL,
  PRIMARY KEY  (`Account`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `blog_categories` (
  `CategoryID` int(11) NOT NULL auto_increment,
  `Title` varchar(150) NOT NULL default '',
  `Active` bit(1) NOT NULL,
  `BlogID` int(11) NOT NULL,
  `CategoryType` tinyint(3) unsigned default NULL,
  `Description` longtext NOT NULL,
  `ParentID` int(11) NOT NULL default '0',
  `UpdateTime` datetime default NULL,
  PRIMARY KEY  (`CategoryID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `blog_config` (
  `BlogID` int(11) NOT NULL auto_increment,
  `Account` varchar(50) NOT NULL default '',
  `ShowPostCount` int(11) default NULL,
  `ShowCommentCount` int(11) default NULL,
  `DisabledComment` tinyint(1) unsigned default NULL,
  `PostShowMode` int(10) unsigned NOT NULL default '1',
  PRIMARY KEY  (`BlogID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `blog_content` (
  `ID` int(11) NOT NULL auto_increment,
  `BlogID` int(11) NOT NULL,
  `Author` varchar(50) default NULL,
  `Title` tinytext,
  `Text` mediumtext,
  `TitleUrl` varchar(255) default NULL,
  `SourceName` varchar(50) default NULL,
  `ParentID` int(11) default '0',
  `FeedBackCount` int(11) default NULL,
  `PostType` int(11) default NULL,
  `EnableComment` tinyint(3) unsigned NOT NULL default '0',
  `Hiding` tinyint(3) unsigned NOT NULL default '0',
  `Price` int(11) default NULL,
  `Tags` varchar(255) default NULL,
  `WebCount` int(11) NOT NULL default '0',
  `AggCount` int(11) NOT NULL default '0',
  `WebLastUpdated` datetime NOT NULL default '1900-01-01 00:00:00',
  `AggLastUpdated` datetime NOT NULL default '1900-01-01 00:00:00',
  `DateAdded` datetime NOT NULL default '1900-01-01 00:00:00',
  `DateUpdated` datetime NOT NULL default '1900-01-01 00:00:00',
  PRIMARY KEY  (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `blog_links` (
  `LinkID` int(11) NOT NULL auto_increment,
  `CategoryID` int(11) default NULL,
  `BlogID` int(11) NOT NULL,
  `PostID` int(11) default NULL,
  `NewWindow` tinyint(3) unsigned NOT NULL default '0',
  PRIMARY KEY  (`LinkID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `blog_viewcount` (
  `PostID` int(11) NOT NULL,
  `BlogID` int(11) NOT NULL,
  `WebCount` int(11) NOT NULL,
  `AggCount` int(11) NOT NULL,
  `WebLastUpdated` datetime default NULL,
  `AggLastUpdated` datetime default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `netdisk_directory` (
  `DirectoryID` int(11) NOT NULL auto_increment,
  `Account` varchar(50) NOT NULL default '',
  `Directory` tinytext NOT NULL,
  `ParentID` int(11) NOT NULL,
  `Attribute` int(11) NOT NULL,
  `Password` varchar(50) default NULL,
  `Description` longtext,
  `limits` varchar(10) NOT NULL default 'LR',
  `Created` datetime default NULL,
  `Updated` datetime default NULL,
  PRIMARY KEY  (`DirectoryID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `netdisk_domain` (
  `DomainID` int(11) NOT NULL auto_increment,
  `Account` varchar(50) NOT NULL default '',
  `Title` tinytext,
  `Advertise` tinytext,
  `RedirectURL` tinytext,
  `Type` int(11) default NULL,
  PRIMARY KEY  (`DomainID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `netdisk_filekey` (
  `ID` int(11) default NULL,
  `Account` char(10) NOT NULL default '',
  `FileID` int(11) NOT NULL,
  `Filekey` varchar(80) NOT NULL default '',
  `DownCount` int(11) NOT NULL,
  `EndTime` datetime NOT NULL,
  `AddTime` datetime default NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `netdisk_resource` (
  `FileID` int(11) NOT NULL auto_increment,
  `DirectoryID` int(11) NOT NULL,
  `Attribute` int(11) NOT NULL,
  `SourceName` varchar(250) NOT NULL default '',
  `Name` varchar(250) NOT NULL default '',
  `Description` longtext NOT NULL,
  `FileSize` int(11) NOT NULL,
  `Hits` int(11) NOT NULL,
  `Price` int(11) NOT NULL,
  `Tags` varchar(255) default NULL,
  `Created` datetime NOT NULL default '1900-01-01 00:00:00',
  `Updated` datetime NOT NULL,
  PRIMARY KEY  (`FileID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `photo_categories` (
  `id` int(11) NOT NULL auto_increment,
  `Account` varchar(50) default NULL,
  `Name` varchar(255) NOT NULL default '',
  `Password` varchar(255) default NULL,
  `Limits` char(10) default NULL,
  `Description` tinytext,
  `PhotoType` int(11) default '1',
  `MainPhotoID` int(11) NOT NULL default '-1',
  `NumPhotos` int(11) NOT NULL default '0',
  `Updated` datetime default NULL,
  `created` datetime default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `photo_data` (
  `PhotoID` int(11) NOT NULL auto_increment,
  `CategoryID` int(11) NOT NULL default '0',
  `image` varchar(255) NOT NULL default '',
  `title` varchar(255) NOT NULL default '',
  `SmallPic` varchar(255) NOT NULL default '',
  `PhotoSize` int(11) NOT NULL default '0',
  `Width` int(11) NOT NULL default '0',
  `height` int(11) NOT NULL default '0',
  `detail` tinytext,
  `IsCover` tinyint(3) NOT NULL default '0',
  `Order` int(11) NOT NULL default '0',
  `Tags` varchar(255) default '',
  `created` datetime default NULL,
  PRIMARY KEY  (`PhotoID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `tbl_admin` (
  `AdminID` int(11) NOT NULL auto_increment,
  `Username` varchar(50) NOT NULL default '',
  `Password` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`AdminID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `tbl_disallowedwords` (
  `DisallowedWord` varchar(255) NOT NULL default '',
  `Type` int(11) default NULL,
  PRIMARY KEY  (`DisallowedWord`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `tbl_entitytotag` (
  `EntityID` int(11) NOT NULL auto_increment,
  `TagID` int(11) NOT NULL,
  `TagType` int(11) NOT NULL default '0',
  PRIMARY KEY  (`EntityID`,`TagID`,`TagType`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `tbl_friends` (
  `UserID` int(11) NOT NULL,
  `FID` int(11) NOT NULL,
  `FriendType` int(11) NOT NULL,
  PRIMARY KEY  (`UserID`,`FID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `tbl_posttotag` (
  `PostID` int(11) NOT NULL,
  `TagID` int(11) NOT NULL,
  `TagType` int(11) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `tbl_sitesettings` (
  `SiteID` int(11) NOT NULL auto_increment,
  `disabledSpaces` tinyint(3) default '0',
  `Settings` longblob,
  `SpacesVersion` varchar(64) NOT NULL default '1',
  PRIMARY KEY  (`SiteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `tbl_tags` (
  `TagID` int(11) NOT NULL auto_increment,
  `TagName` varchar(50) NOT NULL default '',
  `Hits` int(11) NOT NULL default '0',
  PRIMARY KEY  (`TagID`,`TagName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `tbl_visitor` (
  `Account` varchar(50) NOT NULL default '',
  `VisitorAccount` varchar(50) default '',
  `VisitorDate` datetime default NULL,
  `IPAddress` varchar(50) default NULL,
  PRIMARY KEY  (`Account`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `user_amt` (
  `Account` varchar(50) NOT NULL default '',
  `moneyBean` decimal(19,4) NOT NULL,
  `credit` int(11) NOT NULL,
  `present` decimal(19,4) default NULL,
  `Reward` decimal(19,4) NOT NULL,
  `NowLoan` decimal(19,4) default NULL,
  `freeze` bit(1) default NULL,
  `InquiryPassword` varchar(50) default NULL,
  `ConsumptionPassword` varchar(50) default NULL,
  PRIMARY KEY  (`Account`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `user_group` (
  `GroupID` int(11) NOT NULL auto_increment,
  `GroupName` varchar(50) default NULL,
  `TotalSize` int(11) NOT NULL,
  `MonthPrice` int(11) NOT NULL,
  `DefaultGroup` int(10) unsigned NOT NULL default '0',
  `Active` int(11) NOT NULL,
  PRIMARY KEY  (`GroupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `user_links` (
  `LinkID` int(11) NOT NULL auto_increment,
  `Account` varchar(50) character set latin1 NOT NULL,
  `LinkName` tinytext NOT NULL,
  `UrlAddress` tinytext NOT NULL,
  `NewWindow` tinyint(1) NOT NULL default '1',
  `Description` varchar(255) default NULL,
  `LinkType` int(11) NOT NULL default '0',
  PRIMARY KEY  (`LinkID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `user_list` (
  `ID` int(11) NOT NULL auto_increment,
  `Account` varchar(50) NOT NULL default '',
  `ListType` int(11) NOT NULL,
  `Title` varchar(255) default '',
  `Parameter` tinytext,
  `SourceUrl` tinytext,
  `Description` longtext,
  PRIMARY KEY  (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `user_userconfig` (
  `Account` varchar(50) NOT NULL default '',
  `GroupID` int(11) default NULL,
  `GuestLimits` varchar(50) NOT NULL default 'LR',
  `Encoding` int(11) NOT NULL default '936',
  `Server` varchar(200) default NULL,
  `Title` varchar(255) default NULL,
  `AvatarImage` varchar(255) default NULL,
  `Theme` varchar(200) NOT NULL default 'msn',
  `Language` varchar(50) NOT NULL default 'zh-CN',
  `EnableBlog` int(11) NOT NULL default '1',
  `EnableDisk` int(11) NOT NULL default '1',
  `Description` longtext,
  `Layout` blob,
  `Created` datetime NOT NULL default '1900-01-01 00:00:00',
  PRIMARY KEY  (`Account`,`Created`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `users` (
  `UserID` int(11) NOT NULL auto_increment,
  `Username` varchar(50) character set utf8 collate utf8_bin default NULL,
  `Account` varchar(100) NOT NULL default '',
  `NickName` varchar(100) NOT NULL default '',
  `Email` varchar(50) NOT NULL default '',
  `Gender` int(11) default NULL,
  `Password` varchar(50) default NULL,
  `IDNumber` varchar(20) default NULL,
  `Phone` varchar(50) default NULL,
  `Answer` varchar(50) default NULL,
  `Address` varchar(200) default NULL,
  `City` varchar(50) default NULL,
  `Question` varchar(50) default NULL,
  `Birthday` datetime default NULL,
  `Active` int(11) default NULL,
  `RegIP` varchar(20) default NULL,
  `LastIP` varchar(20) default NULL,
  `DateLastLogin` datetime NOT NULL default '1900-01-01 00:00:00',
  `Created` datetime NOT NULL default '1900-01-01 00:00:00',
  PRIMARY KEY  (`UserID`,`Account`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE ALGORITHM=UNDEFINED   SQL SECURITY DEFINER VIEW `view_content` AS select sql_no_cache `c`.`ID` AS `ID`,`c`.`BlogID` AS `BlogID`,`c`.`Author` AS `Author`,`c`.`Title` AS `Title`,`c`.`Text` AS `Text`,`c`.`TitleUrl` AS `TitleUrl`,`c`.`SourceName` AS `SourceName`,`c`.`ParentID` AS `ParentID`,`c`.`FeedBackCount` AS `FeedBackCount`,`c`.`PostType` AS `PostType`,`c`.`EnableComment` AS `EnableComment`,`c`.`Hiding` AS `Hiding`,`c`.`Price` AS `Price`,`c`.`Tags` AS `Tags`,`c`.`WebCount` AS `WebCount`,`c`.`AggCount` AS `AggCount`,`c`.`WebLastUpdated` AS `WebLastUpdated`,`c`.`AggLastUpdated` AS `AggLastUpdated`,`c`.`DateAdded` AS `DateAdded`,`c`.`DateUpdated` AS `DateUpdated`,`bc`.`Account` AS `Account`,`d`.`CategoryID` AS `CategoryID` from (((`blog_content` `c` join `blog_config` `bc` on((`bc`.`BlogID` = `c`.`BlogID`))) left join `blog_links` `l` on((`c`.`ID` = `l`.`PostID`))) left join `blog_categories` `d` on((`d`.`CategoryID` = `l`.`CategoryID`)));


CREATE   PROCEDURE `blog_DelCategory`(ategoryID int)
BEGIN

DELETE FROM `blog_Categories`

WHERE `blog_Categories`.`CategoryID`= CategoryID;

DELETE FROM `blog_Links`

WHERE `blog_Links`.`CategoryID`=CategoryID;



END;

CREATE   PROCEDURE `blog_DelContent`(ID int)
BEGIN





declare ParentID int ;

declare PostType int ;

set ParentID=(SELECT  `Blog_Content`.`ParentID` FROM `Blog_Content` where `Blog_Content`.`ID`=ID);

set PostType=(SELECT  `Blog_Content`.`PostType` FROM `Blog_Content` where `Blog_Content`.`ID`=ID);



CALL blog_DelPostTag(ID);

call blog_DelTopicLink(ID);



DELETE FROM `Blog_Content`

WHERE `Blog_Content`.`ParentID`=ID;



DELETE FROM `Blog_Content`

WHERE  `Blog_Content`.`ID`=ID;



if(PostType=8) then



UPDATE `Blog_Content`

SET  `Blog_Content`.`FeedBackCount`=`Blog_Content`.`FeedBackCount`-1

WHERE `Blog_Content`.`ID`=ID;

end if;



END;

CREATE   PROCEDURE `blog_DelPostTag`(PostID int)
begin

DELETE FROM `tbl_EntityToTag` WHERE  `tbl_EntityToTag`.`TagType`=1 and  `tbl_EntityToTag`.`EntityID`=PostID;



END;

CREATE   PROCEDURE `blog_DelTopicLink`(PostID int)
BEGIN

DELETE FROM `blog_links` WHERE   `blog_links`.`PostID`=PostID;



END;

CREATE   PROCEDURE `blog_GetAllPagedFeedBack`(

in PageIndex int,

in PageSize int,

in BlogID int,

out  Count int

)
BEGIN



 SELECT 	



blog_Content.*

       ,'' as Account,0 as WebCount,0  as AggCount

FROM blog_content

where BlogID= @BlogID and PostType=8

   ORDER BY blog_content.ID desc       limit   1, 1;

      set @Count =(SELECT count(*) FROM blog_Content

WHERE  blog_Content.BlogID = @BlogID and PostType=8 ) ;

Select @Count;



END;

CREATE   PROCEDURE `blog_GetBlogCategory`(CategoryID int)
BEGIN

SELECT * FROM

`blog_Categories` where `blog_Categories`.`CategoryID`=CategoryID;



END;

CREATE   PROCEDURE `blog_GetBlogCategoryByAccout`(Account varchar(255))
begin

SELECT * FROM

`blog_Categories` bc join `Blog_Config` con on (bc.`blogID`=con.`BlogID`)

 where con.`Account`=Account order by bc.`CategoryID` desc ;



END;

CREATE   PROCEDURE `blog_GetBlogCategoryByBlogID`(blogID int)
BEGIN

SELECT * FROM `blog_Categories` where `blog_Categories`.`blogID`= blogID;



END;

CREATE   PROCEDURE `blog_GetBlogCategoryByPostID`(PostID int)
BEGIN

SELECT c.* FROM `blog_Categories` c

join `blog_Links` l

on (c.CategoryID=l.CategoryID and l.PostID=PostID);



END;

CREATE   PROCEDURE `blog_GetPostByID`(postID int)
begin

SELECT 	c.*,bc.Account	FROM  `blog_Content` c inner join blog_Config bc on (c.blogID=bc.blogID)

	WHERE

		c.`ID`=PostID;



END;

CREATE   PROCEDURE `blog_getTagTop`(BlogID int ,

Count  int )
BEGIN

if(BlogID>0) then

SELECT  tag.TagName ,Count(tag.TagID) as RefCount

FROM tbl_Tags tag join tbl_EntityToTag pt on tag.TagID=pt.TagID

join Blog_Content bc on bc.ID=pt.EntityID and pt.TagType=1 and bc.BlogID=BlogID

group by tagName order by RefCount desc limit 0,10;

else

SELECT  tag.TagName ,Count(tag.TagID) as RefCount FROM tbl_Tags tag join tbl_EntityToTag pt on tag.TagID=pt.TagID

group by tagName order by RefCount desc limit 0,10;

end if;



END;

CREATE   PROCEDURE `blog_InsertCategory`(Title varchar(255),

	Active  tinyint,

	BlogID int,

	CategoryType tinyint,

	Description longText,

	ParentID int,

OUT	CategoryID int

)
BEGIN



INSERT INTO `blog_Categories` ( `Title`, `Active`, `CategoryType`, `Description`, `BlogID`,`ParentID`,`UpdateTime` )

VALUES (Title,Active, CategoryType, Description, BlogID,ParentID,now());

set CategoryID = last_insert_id();

Select CategoryID as CategoryID;



END;

CREATE   PROCEDURE `Blog_Insert_Content`(BlogID int,

Title varchar(255),

TitleUrl varchar(255),

SourceName varchar(255),	

Text longtext,

Author varchar(50),

PostType int,

EnableComment tinyint,

Hiding  tinyint ,

Price   int,

Tags    varchar(255),

DateAdded datetime,

ParentID int,

 out ID int)
BEGIN



INSERT INTO `Blog_Content`(`BlogID`,

`Author`,

`Title`,

 `Text`,

`TitleUrl`,

`SourceName`,

`ParentID`,

`FeedBackCount`,

`PostType`,

`EnableComment`,

`Hiding`,

`Price`, 

`Tags`,

`WebCount`,

`AggCount`,

`WebLastUpdated`,

`AggLastUpdated`,

`DateAdded`, `DateUpdated`)

VALUES(BlogID,

Author,

Title,

Text,

TitleUrl,

SourceName,

ParentID,

0,

PostType,

EnableComment,Hiding,Price,

Tags,

0,

0,

now(),

now(),

DateAdded,

DateAdded);

set ID =last_insert_id();



if(PostType =8) THEN



/*declare tempID int ;

set tempID =(select `BlogID` from `Blog_Content` where `Blog_Content`.`ID`=ParentID);

Update `Blog_Content` Set `Blog_Content`.`blogID` = tempID where `Blog_Content`.`ID` = ID;*/

Update `Blog_Content` Set `Blog_Content`.`FeedBackCount` = `FeedBackCount` + 1 ,

`Blog_Content`.`WebLastUpdated`=now()

where `Blog_Content`.`ID` = ParentID;

End if;

select ID as ID;



END;

CREATE   PROCEDURE `Blog_TopicToPutCategory`(CategoryID int,

BlogID     int,

PostID     int)
BEGIN

if not exists (select * from `Blog_Links` where `Blog_Links`.`PostID`=PostID and `Blog_Links`.`CategoryID`= CategoryID) then



INSERT INTO `blog_Links`(`CategoryID`, `BlogID`, `PostID`)

VALUES(CategoryID,BlogID,PostID);

end if;



END;

CREATE   PROCEDURE `blog_UpdateCategory`(CategoryID int,

         Title varchar(255),

	 Active tinyint,

	 BlogID int,

	 CategoryType tinyint,

	 Description longtext,

	 ParentID int)
BEGIN

UPDATE `blog_Categories`

SET

`blog_Categories`.`Title`=Title,

`blog_Categories`.`Active`= Active,

`blog_Categories`.`BlogID`= BlogID, 

`blog_Categories`.`CategoryType`= CategoryType,

`blog_Categories`.`Description`= Description,

`blog_Categories`.`ParentID`= ParentID,

`blog_Categories`.`UpdateTime`=now()

WHERE `blog_Categories`.`CategoryID`= CategoryID;



END;

CREATE   PROCEDURE `Blog_UpdateContent`(ID  int,

BlogID int,

Title varchar(255),

TitleUrl varchar(255),

SourceName varchar(255),	

Text longtext,

Author varchar(50),

PostType int,

EnableComment tinyint,

Hiding  tinyint ,

Price   int,

Tags    varchar(255),

DateAdded datetime,

ParentID int)
begin

UPDATE `Blog_Content`

SET  `Blog_Content`.`BlogID`=BlogID,

`Blog_Content`.`Author`=Author,

`Blog_Content`.`Title`=Title,

`Blog_Content`.`Text`=Text, 

`Blog_Content`.`TitleUrl`=TitleUrl,

`Blog_Content`.`SourceName`=SourceName,

`Blog_Content`.`ParentID`=ParentID,

`Blog_Content`.`PostType`=PostType, 

`EnableComment`=EnableComment, 

`Blog_Content`.`Hiding`=Hiding,

`Blog_Content`.`Price`=Price,

`Blog_Content`.`Tags`=Tags,

`Blog_Content`.`DateAdded`=DateAdded

WHERE `Blog_Content`.`ID`=ID;

END;

CREATE   PROCEDURE `NetDisk_AddFileKey`(

Filekey     varchar(80) ,

Account    varchar(20) ,

FileID    int ,

DownCount  int,

EndTime      datetime

)
begin

if(not exists(select * from NetDisk_filekey where (NetDisk_filekey.Filekey=Filekey))) then



	

		insert  NetDisk_filekey(Filekey,Account,FileID,DownCount,EndTime,`AddTime`)

		values (Filekey,Account,FileID,DownCount,EndTime,now());



	

end if;

end;

CREATE   PROCEDURE `NetDisk_CreateDirectory`(

Account varchar(50),

Directory varchar(255),

ParentID int,

Attribute int,

Password  varchar(50),

Description LongText,

limits varchar(10)

)
begin

declare NewParentID int ;

set NewParentID=ParentID;

if ParentID<1  then

if  Directory<>'/'  then

set NewParentID=(SELECT DirectoryID FROM `NetDisk_Directory` where `NetDisk_Directory`.`Account`=Account and `NetDisk_Directory`.`Directory`='/');

else

set NewParentID=0;

end if;

end if;





 

 if not exists(SELECT * FROM `NetDisk_Directory` where `NetDisk_Directory`.`Account`=Account and `NetDisk_Directory`.`Directory`=Directory) then

   

 INSERT INTO NetDisk_Directory(`Account`, `Directory`, `ParentID`, `Attribute`,`Password`, `Description`,  `limits`, `Created`, `Updated`)

VALUES(Account, Directory, NewParentID,Attribute,Password ,Description,limits ,now(),now());

   end if;



end;

CREATE   PROCEDURE `NetDisk_CreateFile`(DirectoryID int,

Attribute int,

SourceName varchar(255),

Name varchar(255),

Description  longtext,

FileSize int,

Hits int,

Price int,

Tags  varchar(255),

out FileID int)
begin

INSERT INTO `NetDisk_Resource`

(`DirectoryID`, `Attribute`, `SourceName`, 

`Name`, `Description`, `FileSize`, 

`Hits`, `Price`,`Tags`, `Created`, `Updated`)

VALUES(DirectoryID,Attribute,SourceName,

Name,Description,

FileSize,Hits,Price,Tags,now(),now());

/*Select FileID =  last_insert_id();*/

select last_insert_id();

end;

CREATE   PROCEDURE `NetDisk_DelDirectory`(DirectoryID int)
begin

DELETE FROM `NetDisk_Directory`

WHERE  `NetDisk_Directory`.`DirectoryID`= DirectoryID;

end;

CREATE   PROCEDURE `NetDisk_DelFile`(FileID int)
begin

DELETE FROM `NetDisk_Resource`

WHERE `NetDisk_Resource`.`FileID`=FileID;

end;

CREATE   PROCEDURE `NetDisk_FileKeyExists`(Account        varchar(50) ,

FileID         int

)
begin

select `FileKey` from `NetDisk_filekey`  where (`NetDisk_filekey`.`Account` = Account and `NetDisk_filekey`.`FileID`=FileID)  ;

end;

CREATE   PROCEDURE `NetDisk_GetDefaultRes`(in ParentID int ,

in Directory   nvarchar(255),

in Count     int )
begin

Declare DirectoryID INT  ;

set DirectoryID=(SELECT `DirectoryID` FROM `NetDisk_Directory` where `NetDisk_Directory`.`ParentID`=ParentID and `NetDisk_Directory`.`Directory`=Directory)   ;

SELECT f.*,d.Directory,d.Password,d.Attribute as FolderAttribute,d.limits FROM `NetDisk_Resource` f join

NetDisk_Directory d on(d.`DirectoryID`=DirectoryID and  f.`DirectoryID`=d.DirectoryID)

order by f.Created desc     ;

end;

CREATE   PROCEDURE `NetDisk_GetDirectory`(DirectoryID int,

Account varchar(50)

)
begin

if(DirectoryID=0) then

begin

SELECT * FROM `NetDisk_Directory` where  `NetDisk_Directory`.`Account`=Account and Directory='/';

end;

else

begin

SELECT * FROM `NetDisk_Directory` where  `NetDisk_Directory`.`DirectoryID`=DirectoryID;

end;

end if;

end;

CREATE   PROCEDURE `NetDisk_GetFile`(FileID int)
begin

SELECT f.*,d.`Directory`,d.`Password`,d.`Attribute` as FolderAttribute,d.limits FROM `NetDisk_Resource` f 

join

`NetDisk_Directory` d on( f.`FileID`=FileID and f.DirectoryID=d.DirectoryID);



end;

CREATE   PROCEDURE `NetDisk_GetFilePath`(
FileKey  varchar(100)  
)
begin
DECLARE DownCount int;
DECLARE EndTime   DateTime;
SET DownCount=(select fk.DownCount from NetDisk_filekey fk where (fk.FileKey=FileKey));
set EndTime=(select fk.EndTime from NetDisk_filekey fk where (fk.FileKey=FileKey));
if(DownCount>0 and EndTime>now()) then
begin
UPDATE  NetDisk_filekey  SET DownCount=DownCount-1 where (NetDisk_filekey.FileKey=FileKey);

select f.SourceName,d.`Directory`,k.* from NetDisk_filekey k join NetDisk_Resource f
on (f.FileID=k.FileID and k.FileKey=FileKey) join NetDisk_Directory d
on d.DirectoryID=f.DirectoryID;
end;
else
 
DELETE FROM  NetDisk_filekey  WHERE (NetDisk_filekey.FileKey=FileKey);
 
end if;
end;

CREATE   PROCEDURE `NetDisk_GetUserDisk`(DirectoryID int )
begin

 

SELECT * FROM `NetDisk_Directory` where  `NetDisk_Directory`.`DirectoryID`=DirectoryID;

SELECT * FROM `NetDisk_Directory` where   `NetDisk_Directory`.`ParentID`=DirectoryID;

SELECT f.*,d.Directory,d.`Password`,d.Attribute as FolderAttribute,d.limits FROM 

`NetDisk_Resource` f join

`NetDisk_Directory` d on(d.`DirectoryID`=DirectoryID and  f.DirectoryID=d.DirectoryID)

order by f.Created desc;

end;

CREATE   PROCEDURE `NetDisk_GetUserDiskByName`(ParentID int ,

Directory varchar(255)

)
begin

declare DirectoryID int;

set DirectoryID=(SELECT `NetDisk_Directory`.`DirectoryID` FROM `NetDisk_Directory` where

`NetDisk_Directory`.`ParentID`=ParentID and `NetDisk_Directory`.`Directory`=Directory);

call NetDisk_GetUserDisk(DirectoryID);

end;

CREATE   PROCEDURE `NetDisk_UpdateDirectory`(DirectoryID int,

Account varchar(50),

Directory varchar(255),

ParentID int,

Attribute int,

Password  varchar(100),

Description longText,

limits varchar(20)

)
begin

Declare CurrentDirectory varchar(255) ;

Declare CurrentParentID int;



set CurrentDirectory =(select `Directory` 

FROM 

`NetDisk_Directory` where `NetDisk_Directory`.`DirectoryID`=DirectoryID);

set CurrentParentID=

(select `ParentID`

FROM

`NetDisk_Directory` where `NetDisk_Directory`.`DirectoryID`=DirectoryID);



if(CurrentDirectory<>Directory) then



UPDATE `NetDisk_Directory` 

Set `NetDisk_Directory`.`Directory`=Directory+Right(`NetDisk_Directory`.`Directory`,length(`NetDisk_Directory`.`Directory`)-length(left(`NetDisk_Directory`.`Directory`,Length(CurrentDirectory))))

WHERE `NetDisk_Directory`.`Account`=Account and left(`NetDisk_Directory`.`Directory`,length(CurrentDirectory))=CurrentDirectory;



end if;





UPDATE `NetDisk_Directory`

SET  `NetDisk_Directory`.`ParentID`=ParentID,

`NetDisk_Directory`.`Directory`=Directory,

`NetDisk_Directory`.`Attribute`=Attribute, 

`NetDisk_Directory`.`Password`=Password, 

`NetDisk_Directory`.`Description`=Description, 

`NetDisk_Directory`.`limits`=limits,  

`Updated`=now()

WHERE `NetDisk_Directory`.`DirectoryID`=DirectoryID ;



if(Directory='/') then



UPDATE `User_UserConfig`

SET  `User_UserConfig`.`GuestLimits`=limits

WHERE `User_UserConfig`.`Account`=Account;

end if;



end;

CREATE   PROCEDURE `NetDisk_UpdateFile`(

FileID      int,

DirectoryID int,

Attribute int,

SourceName varchar(255),

Name varchar(255),

Description  longtext,

FileSize int,

Hits int,

Price int,
Tags  varchar(255),
Created datetime,

Updated datetime

)
begin

UPDATE `NetDisk_Resource`

SET  `NetDisk_Resource`.`DirectoryID`=DirectoryID,

`NetDisk_Resource`.`Attribute`=Attribute, 

`NetDisk_Resource`.`SourceName`=SourceName, 

`NetDisk_Resource`.`Name`=Name, 

`NetDisk_Resource`.`Description`=Description, 

`NetDisk_Resource`.`FileSize`=FileSize, 

`NetDisk_Resource`.`Hits`=Hits,

`NetDisk_Resource`.`Price`=Price, 

`NetDisk_Resource`.`Tags`=Tags, 

`NetDisk_Resource`.`Created`=Created, 

`NetDisk_Resource`.`Updated`=Updated

WHERE `NetDisk_Resource`.`FileID`=FileID;

end;

CREATE   PROCEDURE `Photo_CreateCategory`(

Account varchar(50),

Name    varchar(255),

Password varchar(50),

Limits   char(10),

Description tinyText,

out ID int

)
begin





INSERT INTO  `Photo_Categories`

 (`Account`, 

`Name`, 

`Password`, 

`Limits`, 

`Description`, 

`PhotoType`,

`MainPhotoID`, 

`Updated`,

`created`)

VALUES(

Account , 

Name,

Password,

Limits,

Description, 

1, 

-1,

now(),

now());



select last_insert_id();

end;

CREATE   PROCEDURE `Photo_CreatePhoto`(CategoryID INT,

image varchar(255),

title varchar(255),

SmallPic varchar(255),

PhotoSize int,

Width     int,

height    int,

detail    tinytext,

IsCover   int,

PhotoOrder     int,

Tags      varchar(255),

out ID    int )
begin

declare MaxOrder  int;

declare NumPhotos  int;

declare MainPhotoID int ;

declare photoID int;

set MainPhotoID=-1;

if(PhotoOrder<1) then

begin

set NumPhotos=(select count(*)+1 FROM `Photo_Data` where `Photo_Data`.`CategoryID`=CategoryID);

set MaxOrder=(select Max(p.`Order`)+1 FROM `Photo_Data` p where p.`CategoryID`=CategoryID);



if(ISNULL(MaxOrder)) then

set MaxOrder=0;

end if;

IF(isnull(NumPhotos)) then

set NumPhotos=1;

end if;

end;

else

begin

set MaxOrder=PhotoOrder;

end;

end if;

INSERT INTO  `Photo_Data`(  

`CategoryID`, 

`image`, 

`title`, 

`SmallPic`, 

`PhotoSize`, 

`Width`, `height`,

 `detail`,

`IsCover`,

`Order`,

`Tags`,

 `created`)

VALUES(CategoryID,

image,

title ,

SmallPic,

PhotoSize,

Width,

height,detail,

IsCover,

MaxOrder,

Tags,

now());

set photoID = last_insert_id();

if exists(select * from `Photo_Categories` c where c.`ID`=CategoryID and c.`MainPhotoID`=-1 ) then

begin

update `Photo_Categories` p SET p.`NumPhotos`=NumPhotos,p.`Updated`=now(),p.`MainPhotoID`=photoID where p.`ID`=CategoryID;

end;

else 

begin

update `Photo_Categories` c SET c.`NumPhotos`=NumPhotos, c.`Updated`=now() where c.`ID`=CategoryID;

end ;

end if;

Select photoID;

end;

CREATE   PROCEDURE `Photo_GetCategories`(Account varchar(255))
begin

 

SELECT c.*,p.smallPic  FROM  `Photo_Categories` c

left join `Photo_Data` p on (c.ID=p.CategoryID and c.MainPhotoID=p.PhotoID)

where c.Account=Account;

end;

CREATE   PROCEDURE `Photo_UpdateCategory`(

ID      int,

Account varchar(50),

Name    varchar(255),

Password varchar(50),

Limits   char(10),

Description tinytext,

MainPhotoID int,

Updated     DateTime

)
begin

UPDATE `Photo_Categories` p

SET 

  p.`Account`=Account, 

  p.`Name`=Name,

 p.`Password`=Password,

 p.`Limits`=Limits,

 

 p.`Description`=Description,

 p.`MainPhotoID`=MainPhotoID, 

p.`Updated`=Updated





WHERE p.`ID`=ID;

end;

CREATE   PROCEDURE `Photo_UpdatePhoto`(

PhotoID    int,

CategoryID INT,

image varchar(255),

title varchar(255),

SmallPic varchar(255),

PhotoSize int,

Width     int,

height    int,

IsCover   int,

PhotoOrder     int,

detail    tinytext,

Tags      varchar(255)

)
begin





UPDATE  `Photo_Data` p

SET 

 p.`CategoryID`=CategoryID,

  p.`image`=image, 

  p.`title`=title, 

  p.`SmallPic`=SmallPic,

  p.`PhotoSize`=PhotoSize, 

  p.`Width`=Width,

  p.`height`=height,

  p.`detail`=detail ,

   p.`IsCover`=IsCover,

    p.`Order`=PhotoOrder ,

    p.`Tags`=Tags

WHERE p.`PhotoID`=PhotoID;

end;

CREATE   PROCEDURE `spaces_CreateDisallowedWord`(DisallowedWord varchar(255),

Type  int)
begin

if not exists(SELECT * FROM `tbl_DisallowedWords` w where w.`DisallowedWord`=DisallowedWord and w.`Type`=Type) then





INSERT INTO `tbl_DisallowedWords`(`DisallowedWord`, `Type`) 

VALUES(DisallowedWord,Type);

end if;

end;

CREATE   PROCEDURE `Spaces_CreateTag`(

Tag varchar(50),

EntityID int,

TagType  int

)
begin

declare TagID int;

 

if not exists(SELECT `TagID` FROM `tbl_Tags` where `tbl_Tags`.`TagName`=Tag) then



INSERT INTO `tbl_Tags`(`TagName`) VALUES(Tag);

set TagID = last_insert_id();



else



set TagID =(Select `tbl_Tags`.`TagID` FROM `tbl_Tags` where `tbl_Tags`.`TagName`=Tag);

end if;



if not exists (select * from `tbl_EntityToTag` where `tbl_EntityToTag`.`EntityID`=EntityID 

and  `tbl_EntityToTag`.`TagID`=TagID  and `tbl_EntityToTag`.`TagType`=TagType) then

INSERT INTO `tbl_EntityToTag`(`EntityID`, `TagID`,`TagType`)

VALUES(EntityID,TagID,TagType);

end if;

end;

CREATE   PROCEDURE `spaces_DelDisallowedWords`(Type int)
begin

if(Type>0) then

DELETE FROM  `tbl_DisallowedWords` 

WHERE `tbl_DisallowedWords`.`Type`=Type;



end if;

end;

CREATE   PROCEDURE `spaces_DelEntityTag`(EntityID int,

TagType int

)
begin



DELETE FROM `tbl_EntityToTag`   WHERE `tbl_EntityToTag`.`TagType`=TagType and `tbl_EntityToTag`.`EntityID`=EntityID;

end;

CREATE   PROCEDURE `spaces_GetDisallowedWords`(Type int)
begin

select * from `tbl_DisallowedWords` w where w.Type=Type;

end;

CREATE   PROCEDURE `spaces_getGetStatus`()
begin

select (select count(UserID) from `Users`) as UserCount ,

(select count(ID) from `Blog_Content` where PostType=1) as PostCount,

(select count(ID) from `Blog_Content` where PostType=8) as CommentCount,

(select count(DirectoryID) from `NetDisk_Directory`) as DirectoryCount,

(select count(FileID) from `NetDisk_Resource`) as FileCount,

(select sum(FileSize) from `NetDisk_Resource`) as FileSize,

(select count(ID) from `NetDisk_filekey`) as FileKeyCount,

(select count(TagID) from `tbl_Tags`) as TagCount,

(select count(TagID) from `tbl_EntityToTag`) as TagRefCount,

(select count(CategoryID) from `blog_Categories`) as BlogCategoryCount,

(select sum(WebCount) from `blog_Content`) as PostHitCount,

(select count(LinkID) from `User_Links`) as LinkCount,

(select count(ID) from `User_List`) as ListCount;

end;

CREATE   PROCEDURE `spaces_SiteSettings_Save`(

	DisabledSpaces  tinyint(3),

 	

 Settings  longblob

)
begin





	IF EXISTS (SELECT * FROM tbl_SiteSettings limit 0,1) then

		UPDATE

			tbl_SiteSettings

		SET

			tbl_SiteSettings.DisabledSpaces = DisabledSpaces ,

			tbl_SiteSettings.Settings = Settings;

		 

	ELSE

		INSERT INTO

           			tbl_SiteSettings

			(



				tbl_SiteSettings.`DisabledSpaces`,

				tbl_SiteSettings.`Settings`

			)

		VALUES

			(



			DisabledSpaces,

				Settings

			);

	end if;

END;

CREATE   PROCEDURE `test`(Account varchar(50))
begin

 if not exists(SELECT * FROM `NetDisk_Directory` where `Account`='windinwing' and `Directory`='/') then

     select 1;

     else

     select 2;

     end if;

     end;

CREATE   PROCEDURE `User_Create`(

Username varchar(50),

Account varchar(50),

Email   varchar(50),

Password varchar(50),

NickName varchar(20),

Gender  int,

City      varchar(100),

Address   varchar(200),



IDNumber  varchar(50),



Birthday  dateTime,

Question  varchar(50),

Answer    varchar(50),

RegIP     varchar(50),

GoToAddress   varchar(255) 

)
begin 

declare Title nvarchar(200);

declare blogID int;

declare DefaultGroupID int;

INSERT INTO `Users`(`Username`, `Account`, `Email`,`Password`,

`NickName`,

`Gender`, `City`, `Address`,

  `IDNumber`,

 `Birthday`,

`Question`,

`Answer`,`Active`,

`RegIP`, `LastIP`, `DateLastLogin`, 

`Created`)

VALUES(Username,Account,Email,Password,NickName,Gender,

City,Address,

IDNumber,

Birthday,

Question,Answer,1,

RegIP,RegIP,now(),now());







INSERT INTO `Blog_Config`(`Account`, `ShowPostCount`, `ShowCommentCount`)

VALUES(Account, 10,10);

set blogID=last_insert_id();



if NickName='' Then

set Title=concat(Account,'\'S Spaces');

else

set Title=concat(NickName,'\'S Spaces');

end if;

if GoToAddress<>'' then



INSERT INTO `NetDisk_Domain`( `Account`, `Title`, `Advertise`, `RedirectURL`, `Type`)

VALUES(Account,Title, 1, GoToAddress, 1);



end if;



set DefaultGroupID=(SELECT  `GroupID` FROM  `User_Group` where DefaultGroup=1 LIMIT 0,1);



INSERT INTO `User_UserConfig`(`Account`, `GroupID`,`Title`,`Description`)

VALUES(Account,DefaultGroupID,Title,'');

end;

CREATE   PROCEDURE `User_CreateLink`(

Account varchar(100),

LinkName varchar(255),

UrlAddress varchar(255),

NewWindow  bit,

LinkType   int,

Description TinyText

)
begin

INSERT INTO `User_Links`( `Account`, `LinkName`,`UrlAddress`, `NewWindow`, `LinkType`,`Description`)

VALUES(Account,LinkName, UrlAddress, NewWindow, LinkType,Description);

end;

CREATE   PROCEDURE `User_CreateList`(

Account varchar(100),

ListType int,

Title varchar(255),

Parameter TINYTEXT,

SourceUrl   TINYTEXT,

Description longText,

out ID int

)
begin

INSERT INTO `User_List`(`Account`, `ListType`, `Title`, `Parameter`, `SourceUrl`,`Description`)

VALUES(Account,ListType,Title,Parameter,SourceUrl,Description);

/*Select ID = last_insert_id();*/

select last_insert_id();

end;

CREATE   PROCEDURE `User_DelLink`(

LinkID int

)
begin

DELETE FROM `User_Links`

WHERE `User_Links`.`LinkID`=LinkID;

end;

CREATE   PROCEDURE `User_delList`(ID int)
begin



DELETE FROM `User_List`

WHERE `User_List`.`ID`=ID;

end;

CREATE   PROCEDURE `user_delUser`(Account varchar(50))
begin
Declare BlogID int ;

SET BlogID=(Select `BlogID` from Blog_Config WHERE Blog_Config.`Account`=Account) ;

delete From Tbl_EntityToTag where EntityID  
in( Select `ID` from blog_Content where blog_Content.postType=1 and blog_Content.BlogID=BlogID) and TagType=1;

delete From Tbl_EntityToTag where EntityID   
in(SELECT `PhotoID` FROM `Photo_Data` d inner join `Photo_Categories` c on (d.CategoryID=c.ID) and c.Account=Account) 
 and TagType=3;

delete From Tbl_EntityToTag where EntityID  
in(SELECT `FileID` FROM `NetDisk_Resource` r inner join `NetDisk_Directory` d on(d.DirectoryID=r.DirectoryID) and d.Account=Account)  
 and TagType=2;

DELETE FROM `blog_Links`   
WHERE `blog_Links`.BlogID=BlogID;

DELETE FROM `blog_Categories`  
WHERE `blog_Categories`.BlogID=BlogID;


delete From blog_Content where  blog_Content.BlogID=BlogID  ;

delete From NetDisk_Resource where  
DirectoryID in(SELECT `DirectoryID` FROM `NetDisk_Directory` where `NetDisk_Directory`.`Account`=Account);

delete From `NetDisk_Directory` where  
 `NetDisk_Directory`.`Account`=Account;

DELETE FROM `User_Links`  
WHERE `User_Links`.`Account`=Account;

DELETE FROM `NetDisk_filekey` 
WHERE `NetDisk_filekey`.`Account`=Account; 

DELETE FROM `User_List` 
WHERE  `User_List`.`Account`=Account;

DELETE FROM  `Users`    
WHERE `Users`.`Account`=Account; 


Delete From `User_UserConfig`  
WHERE `User_UserConfig`.`Account`=Account ;

DELETE FROM `NetDisk_Domain` 
WHERE `NetDisk_Domain`.`Account`=Account;

DELETE FROM `Photo_Data`     
where `CategoryID` in (select `ID` FROM `Photo_Categories` where `Photo_Categories`.`Account`=Account );

DELETE FROM `Photo_Categories`  
where `Photo_Categories`.`Account`=Account;

DELETE FROM `tbl_Visitor` 
where `tbl_Visitor`.`Account`=Account;

end;

CREATE   PROCEDURE `User_Get`(Username varchar(50))
begin

SELECT * FROM Users u where  u.Username= Username;

end;

CREATE   PROCEDURE `User_GetConfig`(Account varchar(50))
begin

SELECT uc.* ,ng.GroupName, u.nickName,ng.TotalSize

,bc.BlogID,bc.ShowPostCount,bc.ShowCommentCount,bc.DisabledComment, bc.PostShowMode,dir.DirectoryID as RootDirID

FROM User_UserConfig uc   join `users` u on(uc.account=u.account)

join  User_Group  ng on (uc.Account=Account and uc.GroupID=ng.GroupID)

left join  Blog_Config  bc on (bc.Account=uc.Account)

left join NetDisk_Directory dir on (dir.Account=Account and dir.ParentID=0);

end;

CREATE   PROCEDURE `User_GetLink`(Account varchar(50))
begin

SELECT * FROM User_Links

where User_Links.Account=Account;

end;

CREATE   PROCEDURE `User_GetListByAccount`(

Account varchar(100)

)
begin

SELECT * FROM `User_List` 

where `User_List`.`Account`=Account;

end;

CREATE   PROCEDURE `User_Update`(

Username varchar(50),

Account varchar(50),

Email    varchar(50),

NickName varchar(20),

Gender   int,

Password  varchar(50),

Question  varchar(50),

Answer    varchar(50),

City      varchar(100),

Address   varchar(200),

IDNumber  varchar(50),

Phone     varchar(50),

Birthday Datetime,

LastIP    varchar(50),

DateLastLogin DateTime

)
begin

UPDATE `Users` u

SET 

u.`NickName`=NickName, 

u.`Email`=Email, 

u.`Gender`=Gender,

u.`Password`=Password, 

u.`IDNumber`=IDNumber, 

u.`Phone`=Phone,

u.`Answer`=Answer, 

u.`Address`=Address,

u.`City`=City, 

u.`Question`=Question,

u.`Birthday`=Birthday,

u.`LastIP`=LastIP, 

u.`DateLastLogin`=DateLastLogin

WHERE u.`Account`=Account;

end;

CREATE   PROCEDURE `User_UpdateLink`(

LinkID int,

Account varchar(100),

LinkName varchar(255),

UrlAddress varchar(255),

NewWindow  bit,

LinkType   int,

Description TinyText

)
begin

UPDATE `User_Links` u

SET  u.`Account`=Account,u.`LinkName` =LinkName , u.`UrlAddress`=UrlAddress,

 u.`NewWindow`=NewWindow, u.`LinkType`=LinkType,

 u.`Description`=Description

WHERE u.`LinkID`=LinkID;

end;

CREATE   PROCEDURE `User_UpdateList`(

ID int,

Account varchar(50),

ListType int,

Title varchar(255),

Parameter TINYTEXT,

SourceUrl   TINYTEXT,

Description longText

)
begin

UPDATE `User_List`

SET  `User_List`.`Account`=Account, `User_List`.`ListType`=ListType, 

    `User_List`.`Title`=Title, 

    `User_List`.`Parameter`=Parameter, 

    `User_List`.`SourceUrl`=SourceUrl,

    `User_List`.`Description`=Description

WHERE `User_List`.`ID`=ID;

end;

CREATE   PROCEDURE `User_UpdateUserConfig`(

Account varchar(50),

GroupID int,

GuestLimits varchar(20),

Encoding  int,

Server    varchar(255),

Title     varchar(1000),

AvatarImage varchar(255),

Theme       varchar(50),  

Language  varchar(255),

EnableBlog  bit,

EnableDisk  bit,

Layout    varbinary (7500),

Description varchar(1000)

)
begin

UPDATE `User_UserConfig`

SET  `User_UserConfig`.`GroupID`=GroupID, 

`User_UserConfig`.`GuestLimits`=GuestLimits, 

`User_UserConfig`.`Encoding`=Encoding, 

 `User_UserConfig`.`Server`=Server, 

`User_UserConfig`.`Title`=Title, 

`User_UserConfig`.`Theme`=Theme,

`User_UserConfig`.`Language`=Language, 

`User_UserConfig`.`EnableDisk`=EnableDisk,

`User_UserConfig`.`AvatarImage`=AvatarImage,

`User_UserConfig`.`Description`=Description,

`User_UserConfig`.`Layout` =Layout 

WHERE `User_UserConfig`.`Account`=Account;

UPDATE `NetDisk_Domain`

SET   `NetDisk_Domain`.`Title`=Title

WHERE `NetDisk_Domain`.`Account`=Account;

end;

CREATE   PROCEDURE `Visitor_UpdateList`(

Account varchar(50),

VisitorAccount varchar(50),

IPAddress      varchar(30),

VisitorDate   DateTime)
BEGIN

if exists(SELECT *  FROM  tbl_Visitor where tbl_Visitor.Account=Account

and tbl_Visitor.VisitorAccount=VisitorAccount) then

begin

UPDATE  tbl_Visitor

SET  tbl_Visitor.VisitorDate=VisitorDate, tbl_Visitor.IPAddress=IPAddress

WHERE tbl_Visitor.Account=Account and tbl_Visitor.VisitorAccount=VisitorAccount;

end;

else

begin

INSERT INTO tbl_Visitor(Account, VisitorAccount, VisitorDate, IPAddress)

VALUES(Account, VisitorAccount, VisitorDate, IPAddress);

end;

end if;



END;
INSERT INTO `user_group` (`GroupID`,`GroupName`,`TotalSize`,`MonthPrice`,`DefaultGroup`,`Active`) VALUES 
 (1,'default',32,0,1,1);
