後臺部分:
添加對象Vote/add、對象列表Vote/votelist、分類設置Vote/set_type
控制器:
<?php
class VoteAction extends CommonAction{
public function index(){
$this->display();
}
public function upload(){
if(!empty($_FILES)){
return $this->_upload();
}
}
//文件上傳方法(帶縮略圖)
public function _upload(){
import('ORG.Net.UploadFile');
$upload = new UploadFile();// 實例化上傳類
$upload->maxSize = 3145728 ;// 設置附件上傳大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 設置附件上傳類型
$upload->savePath = './Public/Uploads/Vote/';// 設置附件上傳目錄
$upload->thumb = true; //設置需要生成縮略圖,僅對圖像文件有效
$upload->imageClassPath = 'ORG.Util.Image';//設置引用圖片類庫包路徑
$upload->thumbPrefix = 'm_,s_'; //生成2張縮略圖
$upload->thumbMaxWidth = '400,100';//最大寬度
$upload->thumbMaxHeight = '400,100';//最大高度
$upload->saveRule = uniqid;//設置上傳文件規則
if(!$upload->upload()) {// 上傳錯誤提示錯誤信息
$this->error($upload->getErrorMsg());
}else{// 上傳成功 獲取上傳文件信息
$info = $upload->getUploadFileInfo();
return $info;
}
}
//設置分類
public function set_type(){
$act = I("get.act");
import('ORG.Util.Paged');// 導入分頁類
$count = M("Votetype")->order("orderBy DESC")->count();
$page = new Page($count,20);// 實例化分頁類 傳入總記錄數和每頁顯示的記錄數
$show = $page->show();
$data = M("Votetype")->order("orderBy DESC")->limit($page->firstRow.','.$page->listRows)->select();
$this->assign("data",$data);
$this->assign("page",$show);
if($act==""){
$act='add';
}
switch ($act) {
case 'add':
//排序
$orderby = M("Votetype")->order("orderBy DESC")->getField("orderBy");
if($orderby==""){
$orderbydata=1;
}else{
$orderbydata = (int)$orderby+1;
}
$this->assign("orderbydata",$orderbydata);
break;
case 'addsave':
$m = M("Votetype");
if($m->create()){
$m->addtime=time();
if($m->add()){
$this->success("添加成功!",U('Vote/set_type',array('act'=>'add')));
}else{
$this->error("添加失敗!");
}
}
break;
case 'edit':
$id = I("get.id");
$edit_data = M("Votetype")->where(array('id'=>$id))->find();
$this->assign("edit_data",$edit_data);
break;
case 'editsave':
$m = M("Votetype");
$editsave_id = I("post.editid");
if($m->create()){
$m->id = $editsave_id;
$m->updatetime=time();
if($m->save()){
$this->success("修改成功!",U('Vote/set_type',array('act'=>'edit','id'=>$editsave_id)));
}else{
$this->error("修改失敗!");
}
}
break;
case 'del':
$id = I("get.id");
M("Vote")->where(array('cid'=>$id))->delete();
if(M('Votetype')->where(array('id'=>$id))->delete()){
$this->success("刪除成功!",U('Vote/set_type',array('act'=>'add')));
}else{
$this->error("刪除失敗!");
}
break;
default:
# code...
break;
}
$this->display();
}
public function votelist(){
//查詢
if(IS_POST){
$searchtype = I("post.searchtype");
$keyword = I("post.keyword");
$lang = I("post.lang");
$cid = I("post.cid");
$isshow = I("post.isshow");
if($searchtype==1 && $keyword!=""){
$where['voteName']=array("like",array("%$keyword%"));
}
if($lang!=2){
$where['tp_vote.lang']=$lang;
}
if($cid!=0){
$where['cid']=$cid;
}
if($isshow!=2){
$where['tp_vote.isshow']=$isshow;
}
//綁定分類
$n = M("Votetype");
$data = $n->select();
$list = $n->field("id,typeName")->order('id DESC')->select();
$this->assign("alist",$list);
//顯示數據
$m = M("Vote");
import("ORG.Util.Paged");
$count = $m->where($where)->count();
$page = new Page($count,20);
foreach($where as $key=>$val) {
$page->parameter .="$key=".urlencode($val).'&';
}
$show = $page->show();
$data = $m->join("tp_votetype on tp_votetype.id=tp_vote.cid")->field("tp_votetype.typeName,tp_vote.*")
->order("orderby asc")
->limit($page->firstRow.','.$page->listRows)
->where($where)->select();
$this->assign("data",$data);//綁定數據
$this->assign("page",$show);//綁定分頁
//語言版本取值
$lang_data = SettingAction::getLang();
$this->assign("lang_data",$lang_data);
}else{
$searchtype = I("get.searchtype");
$keyword = I("get.keyword");
$lang = I("get.tp_Vote_lang");
$cid = I("get.cid");
$isshow = I("get.tp_Vote_isshow");
if($searchtype==1 && $keyword!=""){
$where['voteName']=array("like",array("%$keyword%"));
}
if($lang!=2 && $lang!=""){
$where['tp_Vote.lang']=$lang;
}
if($cid!=0 && $cid!=""){
$where['cid']=$cid;
}
if($isshow!=2 && $isshow!=""){
$where['tp_Vote.isshow']=$isshow;
}
//綁定分類
$n = M("Votetype");
$data = $n->select();
$list = $n->field("id,typeName")->order('id DESC')->select();
$this->assign("alist",$list);
//顯示數據
$m = M("Vote");
import("ORG.Util.Paged");
$count = $m->where($where)->count();
$page = new Page($count,20);
$show = $page->show();
$data = $m->where($where)->join("tp_votetype on tp_votetype.id=tp_vote.cid")->field("tp_votetype.typeName,tp_vote.*")->limit($page->firstRow.','.$page->listRows)
->order("orderby asc")
->select();
$this->assign("data",$data);//綁定數據
$this->assign("page",$show);//綁定分頁
//語言版本取值
$lang_data = SettingAction::getLang();
$this->assign("lang_data",$lang_data);
}
$this->display();
}
//添加
public function add(){
if(IS_POST){
$post = I("post.");
if($post['voname']==""){
$this->error("內容名稱不能爲空");
}else if($post['vocon']==""){
$this->error("詳細內容不能爲空");
}
$cid = I("post.cid","trim");
$count = M("Votetype")->where("pid=$cid")->count();
if($count>0){
$this->error("該分類不是終極分類,操作失敗");
}
$m = M("Vote");
if($m->create()){
if($_FILES){
$info = $this->upload(); //加載upload方法
$m->vophoto=$info[0][savename];
$m->vothumb1="s_".$info[0]['savename'];
$m->vothumb2="m_".$info[0]['savename'];
//加水印
$settingimg = M("Config_info")->find();
//判斷是否開啓
if($settingimg[is_watermark]==1 && $settingimg[waterpic]!=""){
import('ORG.Util.Imaged');
$image = new Imaged();
//添加水印 原圖片,水印圖片,添加後圖片名,水印透明度,定位:
/*
*0 右下角
*1 居中
*2 左上角
*3 右上角
*4 左下角
*/
//$postnum = M("Config_info")->field("position")->find();//取得位置字段
$image->water('./Public/Uploads/Vote/'.$info[0]['savename'],'./Public/Uploads/Setting/'.$settingimg[waterpic],'',80,$settingimg[position]);
}
}
$m->addtime=time();
$m->sjpacon=$_POST['sjpacon'];
if($m->add()){
if(isset($_POST[submit1])){
$this->success("添加成功",U("Vote/votelist"));
}else{
$this->success("添加成功",U('Vote/add',array('cid'=>$post[cid])));
}
}else{
$this->error("添加失敗");
}
}
}else{
//排序自增
$orderby1 = M("Vote")->order("orderby DESC")->limit(1)->find();
if($orderby1){
$orderbydata=$orderby1[orderby]+1;
}else{
$orderbydata=1;
}
$this->assign("orderbydata",$orderbydata);
//綁定分類
$m = M("Votetype");
$data = $m->select();
$list = $m->field("id,typeName")->order('id DESC')->select();
//調用Content模塊的getAllField方法 有參 5代表內容 獲得數組 20140529注 已使用ajax調用
// $zdydata = R('Content/getAllField',array("5"));
$this->assign("alist",$list);
//$this->assign("zdydata",$zdydata);
//語言版本取值
$lang_data = SettingAction::getLang();
$this->assign("lang_data",$lang_data);
}
$this->display();
}
//修改
public function edit(){
if(IS_POST){
$post = I("post.");
$files = $_FILES;
if($post['voname']==""){
$this->error("內容名稱不能爲空");
}else if($post['vocon']==""){
$this->error("詳細內容不能爲空");
}
$cid = I("post.cid","trim");
$count = M("Concate")->where("pid=$cid")->count();
if($count>0){
$this->error("該分類不是終極分類,操作失敗");
}
$m = M("Vote");
$m->create();
if(!empty($files['vophoto'])){
$info = $this->upload();
$m->vophoto=$info[0][savename];
$m->vothumb1="s_".$info[0]['savename'];
$m->vothumb2="m_".$info[0]['savename'];
}
$m->updatetime=time();
$m->sjpacon=$_POST['sjpacon'];
if($m->save()){
$this->success("修改成功",U("Vote/votelist",array('p'=>$_POST[p])));
}else{
$this->error("修改失敗");
}
}else{
//綁定分類
$n = M("Votetype");
$data = $n->select();
$list = $n->field("id,typeName")->order('id DESC')->select();
$this->assign("alist",$list);
$id = I("get.id","","trim");
$m = M("Vote");
$data = $m->where("id=$id")->find();
//調用Content模塊的editAllField方法 有參 5代表內容 獲得數組
$zdydata = R('Content/editAllField',array($data,'5'));
//語言版本取值
$lang_data = SettingAction::getLang();
$this->assign("lang_data",$lang_data);
$this->assign("data",$data);
$this->assign("zdydata",$zdydata);
}
// print_r($_FILES);
$this->display();
}
//刪除
public function delete(){
$id = I("get.id");
if($id>0){
$m = M("Vote");
if($m->where("id=$id")->delete()){
$this->success("刪除成功");
}else
{
$this->error("刪除失敗");
}
}
}
//分類ajax 驗證分類
public function ajax(){
$cid = I("get.cid");
$count = M("Votetype")->where("pid=$cid")->count();
if($count>0){
echo "0";
}else{
echo "1";
}
}
//是否顯示
public function isshow(){
$id = I("get.id","trim");
$issh = I("get.issh","trim");
$where['id']=$id;
$data['isshow']=$issh;
$m = M("Vote");
if($m->where($where)->save($data)){
$this->success("操作成功",U("Vote/votelist"));
}
}
//批量刪除
public function pldelete(){
$str = I("get.str");
$str = $str."0";//補0
$m = M("Vote");
$where['id']=array("in",$str);
if($m->where($where)->delete()){
echo "1";
}else{
echo "0";
}
}
//批量顯示
public function plshow(){
$str = I("get.str");
$str = $str."0";//補0
$m = M("Vote");
$where['id']=array("in",$str);
$data['isshow']=1;
$data['updatetime']=time();
if($m->where($where)->save($data)){
echo "1";
}else{
echo "0";
}
}
//批量隱藏
public function plhidden(){
$str = I("get.str");
$str = $str."0";//補0
$m = M("Vote");
$where['id']=array("in",$str);
$data['isshow']=0;
$data['updatetime']=time();
if($m->where($where)->save($data)){
echo "1";
}else{
echo "0";
}
}
//批量移動
public function list_class(){
if(IS_POST){
$str = I("post.str");
$str = $str."0";//補0
$m = M("Vote");
$cid = I("post.cid");
if($cid=="" || !isset($cid)){
$this->error("必須要選擇一項");
}
$count = M("Votetype")->where("pid=$cid")->count();
if($count>0){
$this->error("該分類不是終極分類,操作失敗");
}
$where['id']=array("in",$str);
$data1['cid']=$cid;
$data1['updatetime']=time();
if($m->where($where)->save($data1)){
$this->success("移動成功");
}else{
$this->error("移動失敗");
}
}else{
//綁定分類
$m = M("Votetype");
$data = $m->select();
$list = $m->field("id,typeName")->order('id DESC')->select();
$this->assign("alist",$list);
}
$this->display();
}
//批量複製
public function list_class2(){
if(IS_POST){
$str = I("post.str");
$lang = I("post.lang"); //20170323添加
$str = $str."0";//補0
$m = M("Vote");
$cid = I("post.cid");
if($cid=="" || !isset($cid)){
$this->error("必須要選擇一項");
}
$count = M("Votetype")->where("pid=$cid")->count();
if($count>0){
$this->error("該分類不是終極分類,操作失敗");
}
$arr = explode(",",$str);
$i=0;
foreach($arr as $v){
if($v!=0){
$data1 = $m->where("id=$v")->find();
$data1['cid']=$cid;
$data1['lang'] = $lang; //20170323添加
$data1['id']="";
//$data1['addtime']=time();
//$data1['updatetime']="";
if($m->add($data1)){
$i=$i+1;
}
}
}
if($i>0){
$this->success("共有".$i."個複製成功");
}else
{
$this->error("複製失敗");
}
exit;
}else{
//綁定分類
$m = M("Votetype");
$data = $m->select();
$list = $m->field("id,typeName")->order('id DESC')->select();
$this->assign("alist",$list);
//語言版本取值(這裏是20170323添加)
$lang_data = SettingAction::getLang();
$this->assign("lang_data",$lang_data);
}
$this->display();
}
}
?>
add.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加內容</title>
<script language="javascript">
var GV = {
JS_ROOT: "__PUBLIC__/Js/",
};
</script>
<load href="__PUBLIC__/Css/admin_style.css" />
<load href="__PUBLIC__/Js/artDialog/skins/default.css" />
<load href="__PUBLIC__/Js/My97DatePicker/WdatePicker.js"/>
<load href="__PUBLIC__/Js/wind.js" />
<load href="__PUBLIC__/Js/jquery.js" />
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/ueditor/ueditor.all.min.js"> </script>
<!--建議手動加在語言,避免在ie下有時因爲加載語言失敗導致編輯器加載失敗-->
<!--這裏加載的語言文件會覆蓋你在配置項目裏添加的語言類型,比如你在配置項目裏配置的是英文,這裏加載的中文,那最後就是中文-->
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
$(function(){
$(".J_ajax_submit_btn").click(function(){
var voname = $("#voname");
var editor= $("#editor");
var ue = UE.getEditor('editor');
if(voname.val()==""){
Wind.use("artDialog", function () {
art.dialog({
id: "error",
icon: "error",
fixed: true,
lock: true,
background: "#CCCCCC",
opacity: 0,
content: "內容名稱不能爲空",
cancelVal: '確定',
cancel: function(){
voname.focus();
}
});
});
return false;
}else if($("#valu").html()==0){
Wind.use("artDialog", function () {
art.dialog({
id: "error",
icon: "error",
fixed: true,
lock: true,
background: "#CCCCCC",
opacity: 0,
content: "該分類不是終極分類,不可添加!",
cancelVal: '確定',
cancel: function(){
$("#cid").focus();
}
});
});
return false;
}
else if(ue.hasContents()==false){
Wind.use("artDialog", function () {
art.dialog({
id: "error",
icon: "error",
fixed: true,
lock: true,
background: "#CCCCCC",
opacity: 0,
content: "內容詳情不能爲空",
cancelVal: '確定',
cancel: function(){
editor.focus();
}
});
});
return false;
}else{
return true;
}
})
})
</script>
<script type="text/javascript">
$(function(){
//pc編輯器
var ue = UE.getEditor('editor');
$("#btn1").click(function(){
if(ue.hasContents()){
ue1.setContent(ue.getContent());
}
})
})
</script>
<script language="javascript">
$(function(){
$(".opti1").click(function(){
if($("#tr2").length<=0){
$("#tr1").after("<tr id=\"tr2\"><th>頁面標題</th><td><input type=\"text\" name=\"yetitle\" size=\"30\" placeholder=\"頁面標題\" class=\"input\" /></td></tr><tr id=\"tr3\"><th>頁面關鍵字</th><td><textarea style=\"width:408px; height:100px;\" name=\"keywords\" placeholder=\"頁面關鍵字\"></textarea></td></tr><tr id=\"tr4\"><th>頁面描述</th><td><textarea style=\"width:408px; height:100px;\" name=\"descri\" placeholder=\"頁面描述\"></textarea></td></tr>");
}
})
$(".opti2").click(function(){
$("#tr2").remove();
$("#tr3").remove();
$("#tr4").remove();
})
})
</script>
<script language="javascript">
//日期控件顯示
function isdate(){
WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'});
}
</script>
<script language="javascript">
$(function(){
ajx();
$("#cid").change(function(){
ajx();
})
})
function ajx(){
var cid = $("#cid").val();
//ajax驗證
$.get('<{:U("Pacontent/ajax")}>',{cid:cid,rand:Math.random()},function(data){
$("#valu").html(data); //判斷是否爲終極分類
});
//ajax顯示獲取自定義字段
$.get('<{:U("Content/add_custom_ajax")}>',{module_id:5,cid:cid,rand:Math.random()},function(data){
if(data!=0){
var json = JSON.parse(data);
var json_str="";
for(var o in json){ //遍歷json對象,此操作是爲了去除json對象中的逗號
json_str +=json[o];
}
var $bf = $(".custom_before").eq(0);
var $alltr = $bf.nextAll('tr');
var $k = 0;
$alltr.each(function(e){
if ($(this).hasClass('custom_after')) {
$k =e ;
}
})
$alltr.each(function(e){
if ( e<$k ) {
$(this).remove();
}
})
$bf.after(''+json_str+''); //此處必須要加引號 注:花費了3個小時- 原來是少個引號
}
});
}
</script>
<script language="javascript">
//是否有縮略圖顯隱藏
$(function(){
var isphoto = $("input[name='isphoto']:checked").val();
$("input[name='isphoto']").click(function(){
if(this.value==0){
x = $("#ta1").detach();
}else{
$("#ta2").after(x);
}
})
})
</script>
</head>
<body class="J_scroll_fixed">
<div class="wrap J_check_wrap">
<div class="nav">
<ul class="cc">
<li><a href="javascript:void(0)">內容管理</a></li>
<li><a href="javascript:void(0)">內容添加</a></li>
</ul>
</div>
<div class="h_a">內容相關</div>
<form name="myform" action="<{:U("Vote/add")}>" method="post" class="J_ajaxForm" enctype="multipart/form-data">
<div class="table_full">
<table width="100%" class="table_form contentWrap">
<tbody>
<tr>
<th width="100">內容名稱</th>
<td><input type="text" name="voname" value="" class="input" id="voname" size="70" placeholder="內容名稱"><font color="red">*</font></td>
</tr>
<tr>
<th width="100">內容分類</th>
<td>
<select name="cid" id="cid">
<volist name="alist" id="vo">
<option value="<{$vo.id}>" <if condition="$Think.get.cid eq $vo[id]">selected</if> >
<?php
for($i=0;$i<$vo['count'];$i++){
echo " ";
}
?>
<{$vo.typeName}></option>
</volist>
</select>
<font color="red">*</font></td>
</tr>
<tr id="ta2">
<th>是否有縮略圖</th>
<td>
<input type="radio" name="isphoto" checked="checked" value="1" class="issuo" />是
<input type="radio" name="isphoto" value="0" class="issuo" />否
</td>
</tr>
<tr id="ta1">
<th>內容圖片</th>
<td>
<input type="file" name="vophoto" id="prophoto" />
</td>
</tr>
<tr>
<th width="100">語言</th>
<td>
<select name="lang">
<foreach name="lang_data" item="vo">
<option value="<{$vo.lang_val}>"><{$vo.lang_name}></option>
</foreach>
</select>
<font color="red">*</font></td>
</tr>
<tr>
<th width="100">是否顯示</th>
<td>
<select name="isshow">
<option value="1">是</option>
<option value="0">否</option>
</select>
<font color="red">*</font></td>
</tr>
<tr>
<th>內容詳細</th>
<td>
<script type="text/plain" id="editor" name="vocon" style="width:100%;height:400px;"></script>
</td>
</tr>
<tr>
<th>排序</th>
<td><input type="text" name="orderby" id="orderby" class="input" size="30" placeholder="輸入排序:" value="<{$orderbydata}>" /></td>
</tr>
<tr class="custom_before">
<td colspan="2" class="h_a">自定義字段</td>
</tr>
<tr>
<td colspan="2" class="h_a">優化相關</td>
</tr>
<tr id="tr1">
<th>優化設置</th>
<td><input type="radio" name="opti" value="1" class="opti1"/>是
<input type="radio" name="opti" value="0" class="opti2" checked="checked" />否
</td>
</tr>
</tbody></table>
</div>
<div class="btn_wrap" style="z-index:999;">
<div class="btn_wrap_pd">
<button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit" name="submit1">確定</button>
<button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit" name="submit2">保存並繼續添加</button>
<span id="valu" style="display:none;"></span>
</div>
</div>
</form>
</div>
</body>
</html>
edit.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>內容修改</title>
<load href="__PUBLIC__/Css/admin_style.css" />
<load href="__PUBLIC__/Js/artDialog/skins/default.css" />
<load href="__PUBLIC__/Js/My97DatePicker/WdatePicker.js"/>
<script language="javascript">
var GV = {
JS_ROOT: "__PUBLIC__/Js/",
};
</script>
<load href="__PUBLIC__/Js/wind.js" />
<load href="__PUBLIC__/Js/jquery.js" />
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/ueditor/ueditor.all.min.js"> </script>
<!--建議手動加在語言,避免在ie下有時因爲加載語言失敗導致編輯器加載失敗-->
<!--這裏加載的語言文件會覆蓋你在配置項目裏添加的語言類型,比如你在配置項目裏配置的是英文,這裏加載的中文,那最後就是中文-->
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
$(function(){
$(".J_ajax_submit_btn").click(function(){
var voname = $("#voname");
var editor= $("#editor");
var ue = UE.getEditor('editor');
if(voname.val()==""){
Wind.use("artDialog", function () {
art.dialog({
id: "error",
icon: "error",
fixed: true,
lock: true,
background: "#CCCCCC",
opacity: 0,
content: "內容名稱不能爲空",
cancelVal: '確定',
cancel: function(){
voname.focus();
}
});
});
return false;
}else if($("#valu").html()==0){
Wind.use("artDialog", function () {
art.dialog({
id: "error",
icon: "error",
fixed: true,
lock: true,
background: "#CCCCCC",
opacity: 0,
content: "該分類不是終極分類,不可操作!",
cancelVal: '確定',
cancel: function(){
$("#cid").focus();
}
});
});
return false;
}
else if(ue.hasContents()==false){
Wind.use("artDialog", function () {
art.dialog({
id: "error",
icon: "error",
fixed: true,
lock: true,
background: "#CCCCCC",
opacity: 0,
content: "內容詳情不能爲空",
cancelVal: '確定',
cancel: function(){
editor.focus();
}
});
});
return false;
}else{
return true;
}
})
})
</script>
<script type="text/javascript">
$(function(){
//pc編輯器
var ue = UE.getEditor('editor');
$("#btn1").click(function(){
if(ue.hasContents()){
ue1.setContent(ue.getContent());
}
})
})
</script>
<script language="javascript">
$(function(){
$(".opti1").click(function(){
if($("#tr2").length<=0){
$("#tr1").after("<tr id=\"tr2\"><th>頁面標題</th><td><input type=\"text\" name=\"yetitle\" size=\"30\" placeholder=\"頁面標題\" class=\"input\" value=\"<{$data.yetitle}>\" /></td></tr><tr id=\"tr3\"><th>頁面關鍵字</th><td><textarea style=\"width:408px; height:100px;\" name=\"keywords\" placeholder=\"頁面關鍵字\"><{$data.keywords}></textarea></td></tr><tr id=\"tr4\"><th>頁面描述</th><td><textarea style=\"width:408px; height:100px;\" name=\"descri\" placeholder=\"頁面描述\"><{$data.descri}></textarea></td></tr>");
}
})
$(".opti2").click(function(){
$("#tr2").remove();
$("#tr3").remove();
$("#tr4").remove();
})
})
</script>
<script language="javascript">
//日期控件顯示
function isdate(){
WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'});
}
</script>
<script language="javascript">
$(function(){
ajx();
$("#cid").change(function(){
ajx();
})
})
function ajx(){
var cid = $("#cid").val();//獲取分類id
var id = $("input[name='id']").val();//獲取新聞id
//ajax驗證
$.get('<{:U("Pacontent/ajax")}>',{cid:cid,rand:Math.random()},function(data){
$("#valu").html(data); //判斷是否爲終極分類
});
//ajax顯示獲取自定義字段
$.get('<{:U("Content/edit_custom_ajax")}>',{module_id:5,id:id,cid:cid,rand:Math.random()},function(data){
if(data!=0){
var json = JSON.parse(data);
var json_str="";
for(var o in json){ //遍歷json對象,此操作是爲了去除json對象中的逗號
json_str +=json[o];
}
var $bf = $(".custom_before").eq(0);
var $alltr = $bf.nextAll('tr');
var $k = 0;
$alltr.each(function(e){
if ($(this).hasClass('custom_after')) {
$k =e ;
}
})
$alltr.each(function(e){
if ( e<$k ) {
$(this).remove();
}
})
$bf.after(''+json_str+''); //此處必須要加引號 注:花費了3個小時- 原來是少個引號
}
});
}
</script>
<script language="javascript">
//重新選擇圖片
$(function(){
$("#sn1").toggle(function(){
$("#sn1").html("取消重選");
$("#tr100").after("<tr id='tr200'><th>重選圖片</th><td><input type=\"file\" name=\"vophoto\" id=\"vophoto\" /></td></tr>");
},function(){
$("#sn1").html("重新選擇");
$("#tr200").remove();
})
})
</script>
<script type="text/javascript">
//是否有縮略圖
$(function(){
var ispic = "<{$data.isphoto}>";
if(ispic==0){
x1 = $("#ta1").detach();
}
$("input[name=isphoto]").click(function(){
if(this.value==0){
x1 = $("#ta1").detach();
x2 = $("#tr100").detach();
}else{
$("#ta2").after(x1);
$("#ta2").after(x2);
}
})
})
</script>
</head>
<body class="J_scroll_fixed">
<div class="wrap J_check_wrap">
<div class="nav">
<ul class="cc">
<li><a href="javascript:void(0)">內容管理</a></li>
<li><a href="javascript:void(0)">內容修改</a></li>
</ul>
</div>
<div class="h_a">內容相關</div>
<form name="myform" action="<{:U("Vote/edit")}>" method="post" class="J_ajaxForm" enctype="multipart/form-data">
<div class="table_full">
<table width="100%" class="table_form contentWrap">
<tbody>
<tr>
<th width="100">內容名稱</th>
<td><input type="text" name="voname" value="<{$data.voname}>" class="input" id="voname" size="70" placeholder="內容名稱"><font color="red">*</font></td>
</tr>
<tr>
<th width="100">內容分類</th>
<td>
<select name="cid" id="cid">
<volist name="alist" id="vo">
<if condition="$data.cid eq $vo['id']">
<option value="<{$vo.id}>" selected="selected">
<?php
for($i=0;$i<$vo['count'];$i++){
echo " ";
}
?>
<{$vo.typeName}></option>
<else />
<option value="<{$vo.id}>">
<?php
for($i=0;$i<$vo['count'];$i++){
echo " ";
}
?>
<{$vo.typeName}></option>
</if>
</volist>
</select>
<font color="red">*</font></td>
</tr>
<tr id="ta2">
<th>是否有縮略圖</th>
<td>
<input type="radio" name="isphoto" value="1"
<if condition="$data.isphoto eq 1">checked</if>
/>是
<input type="radio" name="isphoto" value="0"
<if condition="$data.isphoto eq 0">checked</if>
/>否
</td>
</tr>
<if condition="$data.isphoto eq 1">
<tr id="tr100">
<th>產品圖片</th>
<td>
<span class="zoom-section">
<span class="zoom-small-image">
<a href='__PUBLIC__/Uploads/Vote/<{$data.vothumb2}>' class='cloud-zoom' rel="tint:'#ff0000',tintOpacity:0.5,smoothMove:5,zoomWidth:400,adjustY:-4,adjustX:10"><img src="__PUBLIC__/Uploads/Vote/<{$data.vothumb1}>" title="" alt='' /></a>
</span>
</span>
<span style=""><a id="sn1" href="javascript:void(0)">重新選擇</a></span>
</td>
</tr>
<else />
<tr id="ta1">
<th>產品圖片</th>
<td>
<input type="file" name="vophoto" id="vophoto" />
</td>
</tr>
</if>
<tr>
<th width="100">語言</th>
<td>
<select name="lang">
<foreach name="lang_data" item="vo">
<if condition="$data.lang eq $vo[lang_val]">
<option selected value="<{$vo.lang_val}>"><{$vo.lang_name}></option>
<else />
<option value="<{$vo.lang_val}>"><{$vo.lang_name}></option>
</if>
</foreach>
</select>
<font color="red">*</font></td>
</tr>
<tr>
<th width="100">是否顯示</th>
<td>
<select name="isshow">
<option value="1"
<if condition="$data.isshow eq 1">
selected
</if>
>是</option>
<option value="0"
<if condition="$data.isshow eq 0">
selected
</if>
>否</option>
</select>
<font color="red">*</font></td>
</tr>
<tr>
<th>內容詳細</th>
<td>
<textarea name="vocon" id="editor"style="width:100%;height:400px;"><{$data.vocon}></textarea>
</td>
</tr>
<tr>
<th>排序</th>
<td><input type="text" name="orderby" id="orderby" class="input" size="30" placeholder="輸入排序:" value="<{$data.orderby}>" /></td>
</tr>
<tr class="custom_before">
<td colspan="2" class="h_a">自定義字段</td>
</tr>
<tr>
<td colspan="2" class="h_a">優化相關</td>
</tr>
<tr id="tr1">
<th>優化設置</th>
<td>
<if condition="$data.opti eq 1">
<input type="radio" name="opti" value="1" class="opti1" checked="checked"/>是
<input type="radio" name="opti" value="0" class="opti2" />否
<else />
<input type="radio" name="opti" value="1" class="opti1" />是
<input type="radio" name="opti" value="0" class="opti2" checked="checked" />否
</if>
</td>
</tr>
</tbody></table>
</div>
<div class="btn_wrap" style="z-index:999;">
<div class="btn_wrap_pd">
<button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">確定</button>
<input type="hidden" name="id" value="<{$data.id}>" />
<input type="hidden" name="p" value="<{$Think.get.p}>" />
<span id="valu" style="display:none;"></span>
</div>
</div>
</form>
</div>
</body>
</html>
<script type="text/javascript">
var opti = "<{$data.opti}>";
//document.forms[0].sjeditor.value=con;
if(opti==1){
if($("#tr2").length<=0){
$("#tr1").after("<tr id=\"tr2\"><th>頁面標題</th><td><input type=\"text\" name=\"yetitle\" size=\"30\" placeholder=\"頁面標題\" class=\"input\" value=\"<{$data.yetitle}>\" /></td></tr><tr id=\"tr3\"><th>頁面關鍵字</th><td><textarea style=\"width:408px; height:100px;\" name=\"keywords\" placeholder=\"頁面關鍵字\"><{$data.keywords}></textarea></td></tr><tr id=\"tr4\"><th>頁面描述</th><td><textarea style=\"width:408px; height:100px;\" name=\"descri\" placeholder=\"頁面描述\"><{$data.descri}></textarea></td></tr>");
}
}
</script>
votelist.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>對象列表</title>
<load href="__PUBLIC__/Css/admin_style.css"/>
<load href="__PUBLIC__/Js/artDialog/skins/default.css" />
<script language="javascript">
var GV = {
JS_ROOT: "__PUBLIC__/Js/",
};
</script>
<load href="__PUBLIC__/Js/wind.js" />
<load href="__PUBLIC__/Js/jquery.js" />
<load href="__PUBLIC__/Js/ajaxpage.js" />
<script language="javascript">
$(function(){
$("#piliang").attr("disabled",true);
$("#checkall").click(function(){
if(this.checked){
$("input[name='check[]']").each(function(){this.checked=true;});
}else{
$("input[name='check[]']").each(function(){this.checked=false;});
}
if($("input:checkbox[name='check[]']:checked").length > 0){
$("#piliang").attr("disabled",false);
}else{
$("#piliang").attr("disabled",true);
}
})
$("input[name='check[]']").click(function(){
if($("input:checkbox[name='check[]']:checked").length > 0){
$("#piliang").attr("disabled",false);
}else{
$("#piliang").attr("disabled",true);
}
})
$("#piliang").change(function(){
var piliang = $("#piliang").val();
var str = go();//獲取選中的id
if(piliang==1){
//批量顯示
art.dialog({
title:"提示",
content:"確定要顯示所選項嗎?",
icon:"question",
lock:true,
ok:function(){
$.get('<{:U("Vote/plshow")}>',{str:str,ran:Math.random()},function(data){
if(data==1){
art.dialog({
title:"提示",
icon:"succeed",
content:"操作成功",
lock:true,
time:1,
fixed:true,
ok:function(){
window.location.reload();
},
close:function(){
window.location.reload();
},
});
}else{
art.dialog({
title:"提示",
icon:"error",
content:"操作失敗",
lock:true,
time:1,
fixed:true,
ok:function(){
window.location.reload();
},
close:function(){
window.location.reload();
},
});
}
});
},
cancel:true,
cancelVal:"取消",
close:function(){
document.getElementById("piliang").value=0;
}
});
}else if(piliang==2){
//批量隱藏
art.dialog({
title:"提示",
content:"確定要隱藏所選項嗎?",
icon:"question",
lock:true,
ok:function(){
$.get('<{:U("Vote/plhidden")}>',{str:str,ran:Math.random()},function(data){
if(data==1){
art.dialog({
title:"提示",
icon:"succeed",
content:"操作成功",
lock:true,
time:1,
fixed:true,
ok:function(){
window.location.reload();
},
close:function(){
window.location.reload();
},
});
}else{
art.dialog({
title:"提示",
icon:"error",
content:"操作失敗",
lock:true,
time:1,
fixed:true,
ok:function(){
window.location.reload();
},
close:function(){
window.location.reload();
},
});
}
});
},
cancel:true,
cancelVal:"取消",
close:function(){
document.getElementById("piliang").value=0;
}
});
}else if(piliang==3){
//批量移動
Wind.use("artDialog", function () {
art.dialog.open("__APP__/Vote/list_class/str/"+str, {width: 320, height: 300,title:'移動內容至',background:"#CCCCCC",opacity:0.8,lock:true,id:'abe',drag:false,resize:false,
cancel:function(){
location.href='<{:U("Vote/votelist")}>';
},
cancelVal:"關閉",
});
});
}else if(piliang==4){
//批量複製
Wind.use("artDialog", function () {
art.dialog.open("__APP__/Vote/list_class2/str/"+str, {width: 320, height: 300,title:'複製內容至',background:"#CCCCCC",opacity:0.8,lock:true,id:'abe',drag:false,resize:false,
cancel:function(){
location.href='<{:U("Vote/votelist")}>';
},
cancelVal:"關閉",
});
});
}else if(piliang==5){
//批量刪除
art.dialog({
title:"提示",
content:"確定要刪除所選項嗎?刪除後不可恢復!",
icon:"question",
lock:true,
ok:function(){
$.get('<{:U("Vote/pldelete")}>',{str:str,ran:Math.random()},function(data){
if(data==1){
art.dialog({
title:"提示",
icon:"succeed",
content:"操作成功",
lock:true,
time:1,
fixed:true,
ok:function(){
window.location.reload();
},
close:function(){
window.location.reload();
},
});
}else{
art.dialog({
title:"提示",
icon:"error",
content:"操作失敗",
lock:true,
time:1,
fixed:true,
ok:function(){
window.location.reload();
},
close:function(){
window.location.reload();
},
});
}
});
},
cancel:true,
cancelVal:"取消",
close:function(){
document.getElementById("piliang").value=0;
}
});
}else{
}
})
})
</script>
<script language="javascript">
//獲取被選中的value
function go() {
var str="";
$("input[name='check[]']:checkbox").each(function(){
if($(this).attr("checked")){
str += $(this).val()+","
}
})
return str;
}
</script>
</head>
<body class="J_scroll_fixed">
<div class="wrap J_check_wrap">
<div class="nav">
<ul class="cc">
<li><a href="javascript:void(0)">投票管理</a></li>
<li><a href="javascript:void(0)">對象列表</a></li>
</ul>
</div>
<div class="mb10">
<a href='<{:U("Vote/add")}>' class="btn" title="添加內容"><span class="add"></span>添加對象</a>
</div>
<div class="h_a">搜索</div>
<form name="form1" action="<{:U("Vote/votelist")}>" method="post" >
<div class="search_type cc mb10">
<div class="mb10"> <span class="mr20"> 搜索類型:
<select name="searchtype">
<option value="1" >標題</option>
</select>
關鍵字:
<input type="text" class="input length_2" name="keyword" size='10' value="" placeholder="關鍵字">
語言
<select name="lang">
<option value="2">全部</option>
<foreach name="lang_data" item="vo">
<option value="<{$vo.lang_val}>"><{$vo.lang_name}></option>
</foreach>
</select>
分類:
<select name="cid">
<option value="0">全部</option>
<volist name="alist" id="vo">
<option value="<{$vo.id}>">
<{$vo.typeName}>
</option>
</volist>
</select>
是否顯示:
<select name="isshow">
<option value="2">全部</option>
<option value="1">是</option>
<option value="0">否</option>
</select>
<span id="spn1"></span>
<button class="btn btn10">搜索</button>
</span> </div>
</div>
</form>
<form name="form2" action="<{:U('Vote/orderby')}>" method="post" >
<div class="table_list">
<table width="100%" cellspacing="0" >
<thead>
<tr>
<td width="70" align="center"><input type="checkbox" name="checkall" id="checkall" /></td>
<td width="69" align="left">排序</td>
<td width="230" align="left">對象名稱</td>
<td width="198" align="left">所屬分類</td>
<td width="60" align="left">語言</td>
<td width="135" align="center">是否顯示</td>
<td width="169" align="center">更新時間</td>
<td width="447" align="center">管理操作</td>
</tr>
</thead>
<tbody>
<volist name="data" id="vo">
<tr>
<td align='center'><input type="checkbox" name="check[]" value="<{$vo.id}>" /></td>
<td align="left"><input type="text" class="input orderclass" name="orderby[order][]" size="3" value="<{$vo.orderby}>" />
<input type="hidden" name="orderby[id][]" value="<{$vo.id}>"></td>
<td align='left'><{$vo.voname}></td>
<td align='left'><{$vo.typeName}></td>
<td align='left'>
<foreach name="lang_data" item="v">
<if condition="$vo.lang eq $v[lang_val]"><{$v.lang_name}></if>
</foreach>
</td>
<td align='center'>
<if condition="$vo.isshow eq 1">
<font color="green">是</font>
<else />
<font color="red">否</font>
</if>
</td>
<td align='center'>
<if condition="$vo.updatetime eq ''">
<{$vo.addtime|date="Y-m-d H:i:s",###}>
<else />
<{$vo.updatetime|date="Y-m-d H:i:s",###}>
</if>
</td>
<td width="447" align='center'><a href='<{:U("Vote/edit",array("id"=>$vo[id],"p"=>$_GET[p]))}>'>修改</a> |
<if condition="$vo.isshow eq 1">
<font color="green"><a href='<{:U("Vote/isshow",array("id"=>$vo[id],"issh"=>0))}>'>隱藏</a></font> |
<else />
<a style="color:red;" href='<{:U("Vote/isshow",array("id"=>$vo[id],"issh"=>1))}>'>顯示</a> |
</if>
<a οnclick="return ab()" class="J_ajax_del" href="<{:U('Vote/delete',array('id'=>$vo['id']) ) }>">刪除</a> </td>
</tr>
</volist>
</tbody>
</table>
<div class="p10">
<div class="btn_wrap" style="z-index:999;">
<div class="btn_wrap_pd">
<div class="pages">
<button class="btn btn_submit mr10 orderbtn" type="submit">排序</button>
批量操作<select name="piliang" id="piliang">
<option value="0"></option>
<option value="1">批量顯示</option>
<option value="2">批量隱藏</option>
<option value="3">批量移動</option>
<option value="4">批量複製</option>
<option value="5">批量刪除</option>
</select>
<span class="ajaxpage"><{$page}></span>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<script src="__PUBLIC__/Js/common.js?v"></script>
<script type="text/javascript">
</script>
</body>
</html>
set_type.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>分類設置</title>
<script language="javascript">
var GV = {
JS_ROOT: "__PUBLIC__/Js/",
};
</script>
<load href="__PUBLIC__/Css/admin_style.css" />
<load href="__PUBLIC__/Js/artDialog/skins/default.css" />
<load href="__PUBLIC__/Js/wind.js" />
<load href="__PUBLIC__/Js/jquery.js" />
<load href="__PUBLIC__/Js/ajaxpage.js" />
<load href="__PUBLIC__/Css/cloud-zoom.css" />
<load href="__PUBLIC__/Js/cloud-zoom.1.0.2.min.js" />
<load href="__PUBLIC__/Js/ueditorMN/themes/default/css/umeditor.min.css" />
<load href="__PUBLIC__/Js/ueditorMN/umeditor.config.js" />
<load href="__PUBLIC__/Js/ueditorMN/umeditor.js" />
<load href="__PUBLIC__/Js/ueditorMN/lang/zh-cn/zh-cn.js" />
<style type="text/css">
/* zoom-section */
.zoom-section{clear:both;margin-top:20px;}
*html .zoom-section{display:inline;clear:both;}
.zoom-small-image{border:4px solid #CCC;float:left;margin-bottom:0px;}
.keyword_style{
width: 300px;
height: 120px;
}
.csspage{
font-size: 12px;
}
</style>
<script type="text/javascript">
$(function(){
$(".delone").click(function(){
if(confirm("確定刪除嗎?該操作將刪除分類下的所有題目!")){
return true;
}else{
return false;
}
})
})
</script>
</head>
<body class="J_scroll_fixed">
<div class="wrap J_check_wrap">
<div class="nav">
<ul class="cc">
<li><a href="javascript:void(0)">系統設置</a></li>
<li><a href="<{:U('Setting/setlang')}>">分類設置</a></li>
</ul>
</div>
<div class="table_list">
<table width="100%" cellspacing="0">
<thead>
<tr>
<td width="30%" align="left">分類名稱</td>
<td width="20%" align="center">排序</td>
<td width="20%" align="center">是否顯示</td>
<td width="30%" align="center">操作</td>
</tr>
</thead>
<tbody>
<foreach name="data" item="vo">
<tr>
<td align="left"><{$vo.typeName}></td>
<td align="center"><{$vo.orderBy}></td>
<td align="center" >
<if condition="$vo.isShow eq 1">
<font color="green">是</font>
<else />
<font color="red">否</font>
</if>
</td>
<td align="center" ><a href="<{:U('Vote/set_type',array('id'=>$vo[id],'act'=>'edit'))}>">修改</a> | <a class="delone" href="<{:U('Vote/set_type',array('id'=>$vo[id],'act'=>'del'))}>">刪除</a></td>
</tr>
</foreach>
</tbody>
</table>
<div class="pages">
<span class="ajaxpage"> <{$page}></span>
</div>
</div>
<!--添加-->
<if condition="$Think.get.act eq '' OR $Think.get.act eq 'add'">
<div class="h_a">添加分類</div>
<form name="myform" action="<{:U("Vote/set_type",array('act'=>'addsave'))}>" method="post" class="J_ajaxForm" enctype="multipart/form-data">
<div class="table_full">
<table width="100%" class="table_form contentWrap">
<tbody>
<tr>
<th width="100">分類名稱</th>
<td>
<input type="text" class="input topicName" name="typeName" size="40" value="" placeholder="請輸入分類名稱"/>
<font color="red">*</font>
</td>
</tr>
<tr>
<th width="100">是否顯示</th>
<td>
<select name="isShow">
<option value="1">是</option>
<option value="0">否</option>
</select>
</td>
</tr>
<tr>
<th width="100">排序</th>
<td>
<input type="text" class="input" name="orderBy" value="<{$orderbydata}>" size="40" placeholder="請輸入排序" />
<font color="red">*</font>
</td>
</tr>
</tr>
</tbody></table>
</div>
<div class="btn_wrap" style="z-index:999;">
<div class="btn_wrap_pd">
<button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">保存</button>
</div>
</div>
</form>
</if>
<!--修改-->
<if condition="$Think.get.act eq 'edit'">
<div class="h_a">修改分類</div>
<form name="myform" action="<{:U("Vote/set_type",array('act'=>'editsave'))}>" method="post" class="J_ajaxForm" enctype="multipart/form-data">
<div class="table_full">
<table width="100%" class="table_form contentWrap">
<tbody>
<tr>
<th width="100">分類名稱</th>
<td>
<input type="text" class="input topicName" name="typeName" size="40" value="<{$edit_data.typeName}>" placeholder="請輸入分類名稱"/>
<font color="red">*</font>
</td>
</tr>
<tr>
<th width="100">是否顯示</th>
<td>
<select name="isShow">
<option value="1" <eq name="edit_data.isShow" value="1">selected</eq> >是</option>
<option value="0" <eq name="edit_data.isShow" value="0">selected</eq> >否</option>
</select>
</td>
</tr>
<tr>
<th width="100">排序</th>
<td>
<input type="text" class="input" name="orderBy" value="<{$edit_data.orderBy}>" size="40" placeholder="請輸入排序" />
<font color="red">*</font>
</td>
</tr>
</tr>
</tbody></table>
</div>
<div class="btn_wrap" style="z-index:999;">
<div class="btn_wrap_pd">
<button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">保存</button>
<input type="hidden" name="editid" value="<{$edit_data.id}>" />
</div>
</div>
</form>
</if>
</div>
</body>
</html>
<script type="text/javascript">
$(function(){
$(".J_ajax_submit_btn").click(function(){
if($(".lang_name").val()==""){
alert("名稱不能爲空");
$(".lang_name").focus();
return false;
}
if($(".lang_val").val()==""){
alert("值不能爲空");
$(".lang_val").focus();
return false;
}
if($(".orderby").val()==""){
alert("排序不能爲空");
$(".orderby").focus();
return false;
}
})
})
</script>
前臺部分:
控制器:
//投票
public function tovote(){
//評選步驟
$sel_steps = $this->getNews2("評選步驟",$this->lang,0,0);
$k==1;
foreach($sel_steps as $k=>$v){
$sel_steps[$k][num]=$k+1;
}
$k++;
$this->assign("sel_steps",$sel_steps);
//候選對象
$vote_data = $this->getVote("候選對象",$this->lang,0,0);
foreach($vote_data as $k=>$v){
$where['VoteID'] = $v[id];
$where['VoteIP']=get_client_ip();
$where['votedata'] = date('Y-m-d', time());
$exist = M('Votedetail')->where($where)->find();
if($exist){
$vote_data[$k][isvote]=1;
}else{
$vote_data[$k][isvote]=0;
}
}
$this->assign("vote_data",$vote_data);
$this->display();
}
//詳情頁
public function voteinfo(){
//對象取值
$id = I("get.id","","trim");
if($id>0){
$data = M("Vote")->where("id=$id")->find();
$type_name = M("Votetype")->where(array('id'=>$data[cid]))->getField("typeName");
//$data[concon]=$new_content;
}
$where['VoteID'] = $id;
$where['VoteIP']=get_client_ip();
$where['votedata'] = date('Y-m-d', time());
$exist = M('Votedetail')->where($where)->find();
if($exist){
$data[isvote]=1;
}else{
$data[isvote]=0;
}
$this->assign("data",$data);
$this->assign("type_name",$type_name);
$this->display();
}
//投票功能
public function favorites(){
$id = I("post.id"); //對象id
$gid = I("post.gid"); //頁面id
$ip = get_client_ip();
$m = M("Vote");
$vdata=$m->where("id=$id")->find();
$where['VoteID'] = $id;
$where['VoteIP']=get_client_ip();
$where['votedata'] = date('Y-m-d', time());
$exist1 = M('Votedetail')->where($where)->find();
if(!$exist1){
$where2['VoteIP']=get_client_ip();
$where2['votedata'] = date('Y-m-d', time());
$exist2 = M('Votedetail')->where($where2)->select();
$count = count($exist2);
if($count>=10){
// $this->error("抱歉!您今天已投10票,請明天再投");
$data[status] = 3;
}else{
$vote_data['VoteIP'] = $ip;
$vote_data['VoteID']=$id;
$vote_data['Nums']=1;
$vote_data['votedata']=date('Y-m-d', time());
$oinfo=M('Votedetail')->add($vote_data);
if($oinfo){
//投票量
M("Vote")->execute("update tp_vote set nums=nums+1 where id=$id");
// $this->success("投票成功",U("News/tovote"));
$data[status] = 1;
}else{
// $this->error("投票失敗");
$data[status] = 2;
}
}
$data[number] = M('Votedetail')->where($where2)->count();
}else{
// $this->error("今天您已經投過此人,請投其他人員");
$data[status] = 4;
}
$this -> ajaxReturn($data);
}
模板:
tovote.php
<div class="list w12">
<div class="recent-title">
<h3><span><b>候選</b>名單</span> Candidate list</h3>
</div>
<ul class="clearfix">
<volist name="vote_data" id="vo">
<li>
<!-- <form action="<{:U('News/favorites')}>" method="post" name="myform" enctype="multipart/form-data"> -->
<input type="hidden" name="id" id="gid" value="2" />
<input type="hidden" name="id" id="id" value="<{$vo.id}>" />
<div class="list-cont">
<div class="list-top">
<a href="<{:U('News/voteinfo',array('id'=>$vo['id']))}>">
<div class="list-img">
<img src="__PUBLIC__/Uploads/Vote/<{$vo.vophoto}>" alt="avatar"/>
</div>
<div class="list-title">
<p><{$vo.voname}><b style="color:#29bfe0;">--詳細信息</b></p>
</div>
</a>
</div>
<div class="list-down">
<span>票數:<i><{$vo.nums}></i></span>
<if condition="$vo.isvote eq 1">
<button type="submit" class="list-btn" style="background-color:#788c90;box-shadow:0 3px 2px 0 #788c90;" οnclick="showVote2(<{$vo.id}>)">投票</button>
<else/>
<button type="submit" class="list-btn" οnclick="showVote(<{$vo.id}>)">投票</button>
</if>
</div>
</div>
<!-- </form> -->
</li>
</volist>
</ul>
</div>
---------------------------------------
<script language="javascript">
function showVote(Id){
$.post("<{:U('News/favorites')}>", { "id":Id },function(data){
var number=data.number;
var lavenumb=10-number;
if(data.status==1){
alert("投票成功,您還有"+lavenumb+"次投票權!");
window.location.reload();
}else if(data.status==3){
alert("抱歉!您今天已投10票,請明天再投!");
window.location.reload();
}else if(data.status==4){
alert("今天您已經投過此人,請投其他人員!");
window.location.reload();
}else{
alert("投票失敗!");
window.location.reload();
}
} );
}
function showVote2(Id){
alert("今天您已經投過此人,請投其他人員!");
window.location.reload();
}
</script>
voteinfo.php
<!-- <form action="<{:U('News/favorites')}>" method="post" name="myform" enctype="multipart/form-data"> -->
<input type="hidden" name="id" id="gid" value="1" />
<input type="hidden" name="id" id="id" value="<{$data.id}>" />
<div class="details w12">
<div class="details-cont w845">
<div class="details-title">
<h3><{$data.voname}></h3>
<p>發佈時間:<span><{$data.addtime|date="Y-m-d",###}></span></p>
</div>
<div class="details-content">
<{$data.vocon}>
</div>
<div class="details-btn">
<div>票數:<span><{$data.nums}></span>
<button type="submit" class="detailsBtn" οnclick="javascript:history.back(-1);">返回</button
<!-- -->
</div>
</div>
</div>
</div>
<!-- </form> -->
投標分類表tp_votetype:
CREATE TABLE IF NOT EXISTS `tp_votetype` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`typeName` varchar(255) DEFAULT NULL,
`isShow` tinyint(1) DEFAULT '0',
`orderBy` int(4) DEFAULT NULL,
`addtime` varchar(20) DEFAULT NULL,
`updatetime` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
----------------------------------------
INSERT INTO `tp_votetype` (`id`, `typeName`, `isShow`, `orderBy`, `addtime`, `updatetime`) VALUES
(1, '候選名單', 1, 1, '1519970213', NULL);
投票對象表tp_vote:
CREATE TABLE IF NOT EXISTS `tp_vote` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cid` int(11) DEFAULT '0',
`voname` varchar(150) DEFAULT NULL,
`lang` tinyint(1) DEFAULT '0',
`vocon` longtext COMMENT '內容詳情',
`opti` tinyint(1) DEFAULT '0',
`yetitle` varchar(50) DEFAULT NULL COMMENT '頁面標題',
`keywords` text COMMENT '頁面關鍵字',
`descri` text COMMENT '頁面描述',
`isshow` tinyint(1) DEFAULT NULL COMMENT '是否顯示',
`orderby` int(4) DEFAULT '0' COMMENT '排序',
`addtime` varchar(30) DEFAULT NULL COMMENT '添加時間',
`updatetime` varchar(30) DEFAULT NULL COMMENT '修改時間',
`isphoto` tinyint(1) DEFAULT '0' COMMENT '是否有圖片',
`vophoto` varchar(255) DEFAULT NULL COMMENT '圖片',
`vothumb1` varchar(30) DEFAULT NULL COMMENT '縮略圖1',
`vothumb2` varchar(30) DEFAULT NULL COMMENT '縮略圖2',
`describe` text COMMENT '描述',
`nums` int(11) DEFAULT '0' COMMENT '票數',
`votedata` varchar(20) DEFAULT NULL COMMENT '評價時間',
`voteip` varchar(32) DEFAULT NULL COMMENT '評價ip',
PRIMARY KEY (`id`)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=12 ;
投票詳情表tp_votedetail:
CREATE TABLE IF NOT EXISTS `tp_votedetail` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`VoteIP` varchar(10) NOT NULL DEFAULT '0' COMMENT '30',
`VoteID` int(10) unsigned NOT NULL DEFAULT '0',
`Nums` int(11) NOT NULL DEFAULT '0',
`votedata` varchar(20) DEFAULT NULL COMMENT '評價時間',
PRIMARY KEY (`id`),
KEY `OrderID` (`VoteID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='收藏夾' AUTO_INCREMENT=11 ;