<?
		$uid = isset($uid)?intval($uid):0;
		$iserror = 0;
		if($bid == "")unset($bid);
		if($cid == "")unset($cid);

		switch($act){
				case "add":
						$act = "add";
						break;
				case "delet":
						$act = "delet";
						break;
				default:
						$act = "show";
						break;
		}
		
		if($act == "show"){
				/*每页数量*/
				$pagelistsize = 10;
				if($uid != 0){
						$isuid = $db->query_object("select uid,experience from ".JIEQI_DB_PREFIX."_system_users where uid = ".$uid);
						if(!$isuid){
    						$iserror = 1;
								$pagecontent = "<b>提醒：</b><br/>";
								$pagecontent .= "不存在的用户书架！<br/>";
								$tourl = "";
						}
    		}else{
    				$listuser -> checklogin($_SESSION["member"]->uid);
    		}
    		if($iserror == 0){
    				/*获取书签总数*/
						if($uid != 0){
								$totalbookmark = $db->query_num("select userid from ".JIEQI_DB_PREFIX."_article_bookcase where userid = ".$uid);
						}else{
								$totalbookmark = $db->query_num("select userid from ".JIEQI_DB_PREFIX."_article_bookcase where userid = ".$_SESSION["member"]->uid);
						}
						/*分页参数*/
						$totalpage=ceil($totalbookmark/$pagelistsize);
						global $page;
						if($page>$totalpage or $page<1)$page=1;
						$sqlstart = ($page-1)*$pagelistsize;
						
						/*获取书签数据*/
						if($uid != 0){
								$maxbookmarks =  ($jieqiRight['article']['maxbookmarks']['honors'][$listuser->getmemberlevel($isuid->experience,"level")]=="") ? ($jieqiConfigs['article']['maxbookmarks']) : $jieqiRight['article']['maxbookmarks']['honors'][$listuser->getmemberlevel($isuid->experience,"level")];
								$smartyObj->assign("bookmarklist",$db->query_array("select * from ".JIEQI_DB_PREFIX."_article_bookcase where userid = ".$uid." order by joindate desc limit ".$sqlstart.",".$pagelistsize));
						}else{
								$maxbookmarks =  ($jieqiRight['article']['maxbookmarks']['honors'][$listuser->getmemberlevel($_SESSION["member"]->experience,"level")]=="") ? ($jieqiConfigs['article']['maxbookmarks']) : $jieqiRight['article']['maxbookmarks']['honors'][$listuser->getmemberlevel($_SESSION["member"]->experience,"level")];
								$smartyObj->assign("bookmarklist",$db->query_array("select * from ".JIEQI_DB_PREFIX."_article_bookcase where userid = ".$_SESSION["member"]->uid." order by joindate desc limit ".$sqlstart.",".$pagelistsize));
						}
				} 
		}elseif($act == "add"){
				$listuser -> checklogin($_SESSION["member"]->uid);
				$iserror = 2;
				if($iserror == 2){
						if(!isset($bid)){
								$iserror = 1;
						}else{
								if(isset($cid)){
										$sqli = "and chapterid = {$cid} ";
								}else{
										$sqli = "";	
								}
								$sql = "select articlename,chaptername,chapterorder from ".JIEQI_DB_PREFIX."_article_chapter where articleid = {$bid} {$sqli}order by chapterid asc limit 0,1";
								$chapterdata = $db->query_object($sql);
								if($chapterdata){
										$articlename = $chapterdata->articlename;
										if(isset($cid)){
												$chaptername = $chapterdata->chaptername;
										}    
								}else{
										$iserror = 1;
								}
						}
						if($iserror == 1){
								$url = array();
								$tourl = URL_book_index($url);
								$pagecontent = "<b>提醒：</b><br/>";
								$pagecontent .= "添加失败，书籍信息错误！<br/>";
								$pagecontent .= ">><a href=\"{$tourl}\">返回上一页面</a><br/>";
						}
				}
				
				if($iserror == 2){
						$totalbookmark = $db->query_num("select caseid from ".JIEQI_DB_PREFIX."_article_bookcase where userid = ".$_SESSION["member"]->uid);
						$maxbookmarks =  ($jieqiRight['article']['maxbookmarks']['honors'][$listuser->getmemberlevel($_SESSION["member"]->experience,"level")]=="") ? ($jieqiConfigs['article']['maxbookmarks']) : $jieqiRight['article']['maxbookmarks']['honors'][$listuser->getmemberlevel($_SESSION["member"]->experience,"level")];
						if($totalbookmark >= $maxbookmarks){
								if(isset($cid)){
										$url = array(
												"bid" => $bid,
												"cid" => $cid,
												"page" => $page,
										);
										$tourl = URL_book_chapter($url);
								}else{
										$url = array(
												"bid" => $bid,
												"act" => "",
										);
										$tourl = URL_book_cover($url);
								}
								$iserror = 1;
								$pagecontent = "<b>提醒：</b><br/>";
								$pagecontent .= "添加失败，您的书签已经满了！请删除部分后添加！<br/>";
								$pagecontent .= ">><a href=\"{$tourl}\">返回上一页面</a><br/>";
						}
						
						
				}
				
				if($iserror == 2){
						if(isset($cid)){
								$isin = $db->query_num("select caseid from ".JIEQI_DB_PREFIX."_article_bookcase where articleid = {$bid} and chapterid = {$cid} and userid = ".$_SESSION["member"]->uid);
						}else{
								$isin = $db->query_num("select caseid from ".JIEQI_DB_PREFIX."_article_bookcase where articleid = {$bid} and userid = ".$_SESSION["member"]->uid);
						}
						if($isin){
								if(isset($cid)){
										$url = array(
												"bid" => $bid,
												"cid" => $cid,
												"page" => $page,
										);
										$tourl = URL_book_chapter($url);
								}else{
										$url = array(
												"bid" => $bid,
												"act" => "",
										);
										$tourl = URL_book_cover($url);
								}
								$iserror = 1;
								$pagecontent = "<b>提醒：</b><br/>";
								if(isset($cid)){
										$pagecontent .= "添加失败，您已经收藏过这个章节了！<br/>";
								}else{
										$pagecontent .= "添加失败，您已经收藏过这本书了！<br/>";
								}
								$pagecontent .= ">><a href=\"{$tourl}\">返回上一页面</a><br/>";
						}
				
				}
				
				if($iserror == 2){
						if(isset($cid)){
								$url = array(
										"bid" => $bid,
										"cid" => $cid,
										"page" => $page,
								);
								$tourl = URL_book_chapter($url);
						}else{
								$url = array(
										"bid" => $bid,
										"act" => "",
								);
								$tourl = URL_book_cover($url);
						}
						$db->query("DELETE FROM ".JIEQI_DB_PREFIX."_article_bookcase WHERE userid = ".$_SESSION["member"]->uid." and articleid = ".$bid);	
						if(isset($cid)){
								$db->query("INSERT INTO ".JIEQI_DB_PREFIX."_article_bookcase(articleid,articlename,classid,userid,username,chapterid,chaptername,chapterorder,joindate,lastvisit,flag) VALUE({$bid},'{$chapterdata->articlename}',0,".$_SESSION["member"]->uid.",'".$_SESSION["member"]->uname."',{$cid},'{$chapterdata->chaptername}','{$chapterdata->chapterorder}','".time()."','".time()."',0)");
						}else{
								$db->query("INSERT INTO ".JIEQI_DB_PREFIX."_article_bookcase(articleid,articlename,classid,userid,username,joindate,lastvisit,flag) VALUE({$bid},'{$chapterdata->articlename}',0,".$_SESSION["member"]->uid.",'".$_SESSION["member"]->uname."','".time()."','".time()."',0)");
						}
						$pagecontent = "<b>提醒：</b><br/>";
						$pagecontent .= "书签添加成功！正在返回继续阅读！<br/>";
						$url = array(
								"id" => "",
								"bid" => "",
								"cid" => "",
								"page" => "",
								"act" => "",
								"uid" => "",
						);
						$pagecontent .= "您也可以<a href=\"".URL_user_bookmark($url)."\">管理书签</a><br/>";
						$pagecontent .= ">><a href=\"{$tourl}\">返回上一页面</a><br/>";
				}
		}elseif($act == "delet"){
				$listuser -> checklogin($_SESSION["member"]->uid);
				$iserror = 2;
				if(!isset($id)){
						$iserror = 1;
						$url = array(
								"id" => "",
								"bid" => "",
								"cid" => "",
								"page" => "",
								"act" => "",
								"uid" => "",
						);
						$tourl = URL_user_bookmark($url);
						$pagecontent = "<b>提醒：</b><br/>";
						$pagecontent .= "删除失败，不存在的书签！<br/>";
						$pagecontent .= ">><a href=\"{$tourl}\">返回上一页面</a><br/>";
				}
    		
				if($iserror == 2){
						$isin = $db->query_object("select caseid from ".JIEQI_DB_PREFIX."_article_bookcase where userid=".$_SESSION["member"]->uid." and caseid=".$id);
						if(!$isin){
								$iserror = 1;
								$url = array(
										"id" => "",
										"bid" => "",
										"cid" => "",
										"page" => "",
										"act" => "",
										"uid" => "",
								);
								$tourl = URL_user_bookmark($url);
								$pagecontent = "<b>提醒：</b><br/>";
								$pagecontent .= "删除失败，您的书架中不存在该书签！<br/>";
								$pagecontent .= ">><a href=\"{$tourl}\">返回上一页面</a><br/>";
						}
				}
				if($iserror == 2){
						$url = array(
								"id" => "",
								"bid" => "",
								"cid" => "",
								"page" => "",
								"act" => "",
								"uid" => "",
						);
						$tourl = URL_user_bookmark($url);
						$db->query("DELETE FROM ".JIEQI_DB_PREFIX."_article_bookcase WHERE userid = ".$_SESSION["member"]->uid." and caseid = ".$id);	
						$pagecontent = "<b>提醒：</b><br/>";
						$pagecontent .= "书签删除成功！正在返回书架！<br/>";
						$pagecontent .= ">><a href=\"{$tourl}\">返回上一页面</a><br/>";
				}
		}
		/*套用模版*/
		if($iserror == 0 and $act == "show"){
				@$smartydate = array("pagetitle" => "书架",
													"typename" => $typename,
													"type" => $type,
													"page" => $page,
													"pagelistsize" => $pagelistsize,
													"totalpage" => $totalpage,
													"uid" => $uid,
													"totalbookmark" => $totalbookmark,
													"maxbookmarks" => $maxbookmarks,
													"data" => array("uid"=>$uid),
													);
				$tplpath = "user/bookmark.tpl";
		}else{
				@$smartydate = array("pagetitle" => "书架-提醒",
													"pagecontent" => $pagecontent,
													"torul" => $tourl,
													"redirecturl" => $tourl,
													);
				$tplpath = "public.tpl";
		}
?>