<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/cms4j" prefix="cms4j" %>
<%@ page import = "cn.com.dekn.cms.util.*,cn.com.dekn.common.util.*" %>
<%@ page import = "cn.com.dekn.cms.article.classadmin.busi.ArticleClassBean"%>
<%@ page import = "cn.com.dekn.cms.article.classadmin.vo.ArticleClassVO"%>
<%@ page import = "cn.com.dekn.cms.stat.SiteStat"%>
<%@ page import = "cn.com.dekn.cms.stat.Counter"%>
<%@ page import = "java.util.HashMap"%>
<%@ page import = "java.util.Iterator"%>
<style type="text/css">
.form-buttun {
	BORDER-RIGHT: #002D96 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #002D96 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 12px; FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#FFFFFF, EndColorStr=#9DBCEA); BORDER-LEFT: #002D96 1px solid; CURSOR: hand; COLOR: black; PADDING-TOP: 2px; BORDER-BOTTOM: #002D96 1px solid
}
</style>
<script src="../../js/ajaxrequest.js"></script>
<%
/***********************************
* TAG参数初始化
***********************************/
//要显示文章的ID
String ARTICLE_ID = ParamUtil.getStrParam(request,"ARTICLE_ID","");
//要显示文章的所属站点
String NODE_ID = ParamUtil.getStrParam(request,"NODE_ID","");
//要显示文章的总得分数
String MARK = ParamUtil.getStrParam(request,"MARK","");
//已经打过一次分的提示信息
String NOTE_INFO = ParamUtil.getStrParam(request,"NOTE_INFO","您已经对此文章打过分了！");
//要显示文章的打分次数
String MARK_NUM = ParamUtil.getStrParam(request,"MARK_NUM","0");
//要显示的文章栏目ID
String ARTICLE_CLASS_ID = ParamUtil.getStrParam(request,"ARTICLE_CLASS_ID","");

//取得内存中所有对此文章的打分总和打分的次数
SiteStat siteStat = (SiteStat)Counter.getInstance().counter(NODE_ID);
int allScore = 0;
int allMarkNum = 0;
HashMap markColl = siteStat.getArticleMarkMap();//内存中打分总数
HashMap markNumColl = siteStat.getArticleMarkNumMap();//内存中打分的次数

//取得内存中所有对此文章打分的总数
if(markColl.size()>0){
	Iterator it = markColl.keySet().iterator();
	while(it.hasNext()){
		String id = (String) it.next();
		if(ARTICLE_ID.equals(id)){
			allScore = allScore + StrUtil.getNotNullIntValue((String)markColl.get(ARTICLE_ID));
		}
	}
}

//取得内存中所有对此文章打分的总次数
if(markNumColl.size()>0){
	Iterator it = markNumColl.keySet().iterator();
	while(it.hasNext()){
		String id = (String) it.next();
		if(ARTICLE_ID.equals(id)){
			allMarkNum = allMarkNum + StrUtil.getNotNullIntValue((String)markNumColl.get(ARTICLE_ID));
		}
	}
}

//要在页面中显示的文章得分数
double point = 0;
if(!MARK_NUM.equals("0") || allMarkNum != 0){
	point = (StrUtil.getNotNullIntValue(MARK)+allScore)*10/(StrUtil.getNotNullIntValue(MARK_NUM)+allMarkNum);
}

//取得文章所属的栏目信息
ArticleClassBean classBean = new ArticleClassBean();
ArticleClassVO classVO = classBean.getClassVo(ARTICLE_CLASS_ID);
int markBound = classVO.getMARK_BOUND();
int isUseMark = classVO.getIS_USE_MARK();
//判断栏目是否启用了文章打分，如果不启用则不显示
if(isUseMark == 1){
%>


<div style="width:80%">
<ul class="unit-rating" style="width:150px;">		
<%for(int i = 1;i <= markBound;i++){%>
<li><a href="javascript:markArticle('<%=i%>')" title="<%=i%>分 " class="r<%=i%>-unit rater"><%=i%></a></li>
<%}%>
</ul>
<p style="padding-top:10px;text-indent:5em;color:#999;">当前平均分:<strong id="mark"><%=point/10.0%>分</strong>(<span id="mark_num"><%=allMarkNum%></span>人打分) 谢谢参与</p>
<div class="rateNum"><strong>1</strong><strong>2</strong><strong>3</strong><strong>4</strong><strong>5</strong></div>
</div>

<script>
	//对文章打分
	function markArticle(value){
		var articleID = "<%=ARTICLE_ID%>";
		var nodeID = "<%=NODE_ID%>";
		var noteInfo = "<%=NOTE_INFO%>";
		var allMark = "<%=MARK%>";
		var markNum = "<%=MARK_NUM%>";
		var allScore = "<%=allScore%>";
		var allMarkNum = "<%=allMarkNum%>";
		if(articleID==""||nodeID==""){
			return;
		}
		
		var ajax=new AJAXRequest();
		ajax.get("../../do?action=markArticle&id="+articleID+"&node_id="+nodeID+"&note_info="+noteInfo+"&mark="+value,function(obj){processReturnFromAjax(obj.responseText,allScore,markNum,allMark,allMarkNum,value);});
	}
	//文章打分的回调函数
	function processReturnFromAjax(responseText,m,mn,allmark,allMarkNum,value){
		if(responseText=="true"){
			var markCount = parseInt(allmark);
			document.getElementById("mark").innerHTML = parseInt((markCount + parseInt(m) + parseInt(value))*10/(parseInt(mn)+parseInt(allMarkNum) + 1))/10.0;
			document.getElementById("mark_num").innerHTML = parseInt(allMarkNum) + 1;
		}else{
			alert(responseText);
		}
	}
</script>
<%}%>