<?php
if ( ! defined('CSCMSPATH')) exit('No direct script access allowed');

class Sfq_Index_module extends CI_Module {

	function __construct(){
		    parent::__construct();
        	$this->load->helper('url');
	        $this->load->database();
            $this->load->library('session'); //加载session
	        $this->load->model('CsdjDB'); //加载数据操作模型
            $this->load->model('CsdjSkins'); //加载全局标签模型 
			require_once PLUGINDIR.'sfq/conxiu.php'; 
	        $dir = $this->uri->segment(2);
            $sql="SELECT CS_SID FROM ".CS_SqlPrefix."plugins where cs_dir='".$dir."'";
	        $row=$this->CsdjDB->get_all($sql);
	        if($row){
                      if($row[0]->CS_SID==1){
                             $this->CsdjAdmin->Admin_Url('<font color=red>该插件尚未开启！</font>',"javascript:history.back();");
                      }
            }else{
                      $this->CsdjAdmin->Admin_Url('<font color=red>该插件尚未安装！</font>',"javascript:history.back();");
            }
	}
			
			public function index()
	{
	       $this->User_Login();
			$id = $this->session->userdata('cs_id');
			$name = $this->session->userdata('cs_name');
			$i=1;
			$row=$this->db->query("SELECT CS_Logo,CS_Qianm,CS_Nichen,CS_Name,CS_Cion,CS_Vip,CS_Hits,CS_Qdts,CS_Qdtime,CS_Qda,CS_Qdb,CS_Qdc,CS_Qdd,CS_Qde,CS_Qdf,CS_Leiji,CS_Qdsjian,CS_Qdtian FROM ".CS_SqlPrefix."user where cs_id='".$this->session->userdata('cs_id')."'")->row();
			
			$sql="SELECT CS_Name,CS_Content,CS_Qdtime,CS_Cion FROM ".CS_SqlPrefix."qd where cs_sid=0 order by CS_QdTime desc limit 15";
			$rows=$this->db->query($sql);
			if($rows){
			foreach($rows->result() as $rows){
			$rowa=$this->db->query("SELECT CS_Logo,CS_Qianm,CS_Nichen,CS_Name,CS_Cion,CS_Hits,CS_Qdts,CS_Name FROM ".CS_SqlPrefix."user where cs_name='".$rows->CS_Name."'")->row();
			
			
			$list.='<li><font color="#CCCC00">'.$i.'.</font>会员：<font color="#FFCC00">'.$rowa->CS_Nichen.'</font><a>  +'.$rows->CS_Cion.'金币</a></li>';
			$i=$i+1;
			}
			}
			if($row->CS_Logo!=''){
			$touxiangnannv='<img src="/attachment/logo/'.$row->CS_Logo.'" class="logo" />';
			}else{
			$touxiangnannv='<img src="/attachment/nan_nopic.jpg" class="logo" />';
			}
			
			if($this->datetime($row->CS_Qdsjian)>86400){
			$qdk='<input type="submit" name="Submit" value="开始签到" class="baocun" />';
			}else{
			$qdk='<a pid="tmp10" class="baocun" />已签到</a><pre class="brush: jscript;" id="tmp10" style=" display:none;">$.Prompt("今天已经签到了!");</pre>';
			}
			if($row->CS_Qda!=5&&$row->CS_Leiji>=5){
			$qda='<a href="/index.php/m/sfq/qiandao/qda">领取</a>';
			}else{
			if($row->CS_Leiji<5){
			$qda='<a class="b" pid="tmp2">领取</a>
	<pre class="brush: jscript;" id="tmp2" style=" display:none;">$.Prompt("你好，累计天数不够!");</pre>';
	}
	if($row->CS_Qda==5){
			$qda='<a class="a" pid="tmp2">已领取</a>
	<pre class="brush: jscript;" id="tmp2" style=" display:none;">$.Prompt("你好，您已经领取过了!");</pre>';
	}
			}
			if($row->CS_Qdb!=7&&$row->CS_Leiji>=7){
			$qdb='<a href="/index.php/m/sfq/qiandao/qdb">领取</a>';
			}else{
			if($row->CS_Leiji<7){
			$qdb='<a class="b" pid="tmp1">领取</a>
	<pre class="brush: jscript;" id="tmp1" style=" display:none;">$.Prompt("你好，累计天数不够!");</pre>';
	}
	if($row->CS_Qdb==7){
			$qdb='<a class="a" pid="tmp1">已领取</a>
	<pre class="brush: jscript;" id="tmp1" style=" display:none;">$.Prompt("你好，您已经领取过了!");</pre>';
	}
			}
			if($row->CS_Qdc!=15&&$row->CS_Leiji>=15){
			$qdc='<a href="/index.php/m/sfq/qiandao/qdc">领取</a>';
			}else{
			if($row->CS_Leiji<15){
			$qdc='<a class="b" pid="tmp3">领取</a>
	<pre class="brush: jscript;" id="tmp3" style=" display:none;">$.Prompt("你好，累计天数不够!");</pre>';
	}
	if($row->CS_Qdc==15){
			$qdc='<a class="a" pid="tmp3">已领取</a>
	<pre class="brush: jscript;" id="tmp3" style=" display:none;">$.Prompt("你好，您已经领取过了!");</pre>';
	}
			}
			if($row->CS_Qdd!=30&&$row->CS_Leiji==30){
			$qdd='<a href="/index.php/m/sfq/qiandao/qdd">领取</a>';
			}else{
			if($row->CS_Leiji<30){
			$qdd='<a class="b" pid="tmp4">领取</a>
	<pre class="brush: jscript;" id="tmp4" style=" display:none;">$.Prompt("你好，累计天数不够!");</pre>';
	}
	if($row->CS_Qdd==30){
			$qdd='<a class="a" pid="tmp4">已领取</a>
	<pre class="brush: jscript;" id="tmp4" style=" display:none;">$.Prompt("你好，您已经领取过了!");</pre>';
	}
			}
$t = time();
$t = strtotime("+1 days", $t);
$time= date("Y-m-d H:i:m", $t);
$jinbi=jinbi+1;
			
			
			echo'<!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=gb2312" />
<title>天天签到-爱青檬音乐网</title>

<link rel="stylesheet" type="text/css" href="/plugins/sfq/statics/css/jquery.prompt.css">
<link href="/plugins/sfq/statics/css/style.css" type="text/css" rel="stylesheet" />
<script src="/plugins/sfq/statics/js/jquery.1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/plugins/sfq/statics/js/jquery.prompt.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("a[pid]").click(function(){
		var pid = $(this).attr("pid");
		eval($("#"+pid).html());
	});
});
</script>
</head>

<body>

<div class="quanbu">

<div class="shang">
<div class="xinxi">
<div class="touxiang"><a href="/index.php/user/space">
'.$touxiangnannv.'</a>
<div class="name"><font color="#AEDA2C">用户名:</font>'.$row->CS_Nichen.'<br><font color="#AEDA2C">持有金币:</font>'.$row->CS_Cion.'<font color="#AEDA2C">金</font><br><font color="#AEDA2C">共签到:</font>'.$row->CS_Qdtian.'<font color="#AEDA2C">天</font><br><font color="#AEDA2C">本轮已签：</font>'.$row->CS_Leiji.'<font color="#AEDA2C">天</font></div>
</div>
<div class="jianjie"><font color="#AEDA2C">个人签名:</font>'.$row->CS_Qianm.'</div>
</div>
<div class="qiandaoba">
<form id="form111" name="form111" method="post"  action="/index.php/m/sfq/qiandao">
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bk1">
      <tr>
        <td height="95" align="center" valign="bottom">  <table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="80" height="30" align="center"><img src="/plugins/sfq/statics/images/1.jpg" width="23" height="22" /></td>
            <td width="80" align="center"><img src="/plugins/sfq/statics/images/2.jpg" width="23" height="22" /></td>
            <td width="80" align="center"><img src="/plugins/sfq/statics/images/3.jpg" width="23" height="22" /></td>
            <td width="80" align="center"><img src="/plugins/sfq/statics/images/4.jpg" width="23" height="22" /></td>
            <td width="80" align="center"><img src="/plugins/sfq/statics/images/5.jpg" width="23" height="22" /></td>
            <td width="80" align="center"><img src="/plugins/sfq/statics/images/6.jpg" width="23" height="22" /></td>
            <td width="80" align="center"><img src="/plugins/sfq/statics/images/7.jpg" width="23" height="22" /></td>
          </tr>
          <tr>
            <td height="30" align="center">高兴</td>
            <td align="center">愤怒</td>
            <td align="center">忧虑</td>
            <td align="center">普通</td>
            <td align="center">难过</td>
            <td align="center">恐慌</td>
            <td align="center">惊奇</td>
          </tr>
		  <tr>
            <td align="center"><label>
              <input type="radio" name="qdao" value="我很高兴" checked/>
            </label></td>
            <td align="center"><input type="radio" name="qdao" value="我很愤怒" /></td>
            <td align="center"><input type="radio" name="qdao" value="我好忧虑" /></td>
            <td align="center"><input type="radio" name="qdao" value="很囧、很囧" /></td>
            <td align="center"><input type="radio" name="qdao" value="亲，我好难过" /></td>
            <td align="center"><input type="radio" name="qdao" value="啊~~~什么东西" /></td>
            <td align="center"><input type="radio" name="qdao" value="哇~~~" /></td>
          </tr>
        </table>  </td>
      </tr>
      <tr>
        <td height="50" align="center"><label>
          '.$qdk.'
        </label></td>
      </tr>
    </table></form>
	
	</div>
</div>
<div class="xia">

<div class="zuo">
<div class="mingzi"><i></i>今天签到的会员</div>
'.$list.'

</div>
<div class="you">
<div class="mingzia"><i></i>签到额外奖励<a href="http://qzs.qq.com/snsapp/app/bee/widget/open.htm#content=天天签到-爱青檬音乐网&time='.$time.'&advance=0&url='.site_url("m/sfq").'" target="_blank"><img src="/plugins/sfq/statics/tixing.gif" style="border:0px; float:right; margin:5px 15px 0 0;"/></a></div>

<p>爱青檬音乐网提示：<br>每一天签到增加金币'.jinbi.'个，连续签到可以获得额外奖励。<font color="#ff0000">VIP会员签到可以获得'.$jinbi.'金币！</font><br>累计签到5天，获得'.wjinbi.'金币。<br>累计签到7天，获得'.qjinbi.'金币奖励。<br>累计15天签到，获得'.swtian.'天VIP+'.swjinbi.'金币奖励.<br>累计签到30天，获得'.sstian.'天VIP+'.ssjinbi.'金币。</p>
<p>累计签到以30天为一轮，以第31天为新一轮开始累计天数则为1.</p>


<div class="ling">
<li><b>签到5天</b>'.$qda.'</li>
<li><b>签到7天</b>'.$qdb.'</li>
<li><b>签到15天</b>'.$qdc.'</li>
<li><b>签到30天</b>'.$qdd.'</li>
</div>







</div>

</div>

</div>




';
			
$this->load->view('share.tpl');			
			
			
			
			
			//结束
			}
			
			
            function datetime($TimeTime){
    		$limit=time()-strtotime($TimeTime);
  		    return $limit;
	        }
       //检测登入
    function User_Login($cid=0) {
          $id   = intval($this->session->userdata('cs_id'));
          $name = $this->session->userdata('cs_name');
          $pass = $this->session->userdata('cs_pass');
          $login= TRUE;

          if($id==0||empty($name)||empty($pass)){
              if($cid==0){
                    die("<script language='javascript'>alert('请登陆后再来签到。');window.parent.location='".site_url('user/login')."';</script>");
              }else{
                    $login=FALSE; 
              }  
          }else{
		        $row=$this->db->query("SELECT CS_Pass FROM ".CS_SqlPrefix."user where cs_id='".$id."'")->row();
		        if(!$row){
                    if($cid==0){
                           die("<script language='javascript'>alert('请登陆后再来签到。');window.parent.location='".site_url('user/login')."';</script>");
                    }else{
                           $login=FALSE; 
                    }
                }else{
		        if(md5($row->CS_Pass)!=$pass){
                          if($cid==0){
                                 die("<script language='javascript'>alert('请登陆后再来签到。');window.parent.location='".site_url('user/login')."';</script>");
                          }else{
                                 $login=FALSE; 
                          }
                    }
                }
          }
          return $login;
    } 
	
	       
public function jsqian()
	{
          $id   = intval($this->session->userdata('cs_id'));
		  $yue=date("m");
		  $ri=date("d");
		  $weekarray=array("日","一","二","三","四","五","六");
          $shijian="星期".$weekarray[date("w")];
		  echo'<style>
.sf_qiandao{ width:314px; height:80px;border-bottom:3px solid #ff9900;}
.qiandao_a{ width:300px; height:25px; color:#000000; margin-left:15px;}
.qiandao_b{ width:80px; height:50px; float:left;}
.qiandao_b a{ display:block; background:#FF9900; width:100px; height:50px; line-height:50px; color:#FFFFFF; font-size:22px; text-align:center;}
.qiandao_c{ width:65px; height:47px; border:1px solid #FF9900; line-height:50px; color:#FF9900; font-size:18px; text-align:center;float:left;margin-left:30px;}
.qiandao_d{ width:80px; height:50px; float:left;margin-left:15px;}
.qiandao_d a{display:block; width:80px; height:50px; background:#77BBFF; line-height:50px; color:#FFFFFF; font-size:18px; text-align:center;}
.qiandao_e{ width:180px;height:48px; line-height:48px; color:#FFFFFF;border:1px solid #77BBFF; background:#AAD7E8; text-align:center;font-size:16px; float:left;}
.qiandao_f{ width:100px; height:50px;  float:left;background:#FFCC00; color:#FFFFFF; text-align:center;margin-left:15px;}
.qiandao_f ul{ width:99px; height:30px; margin-top:10px;}
.qiandao_e ul{margin-top:10px;}
</style>';
		  if($id==''){
echo '
<div class="sf_qiandao">

<div class="qiandao_a">你还没登陆，请登陆后再来签到吧！</div>
<div class="qiandao_f"><ul class="qiandao_q">'.$shijian.'<br>'.$yue.'月'.$ri.'日</ul></div>
<div class="qiandao_b"><a href="javascript:void(0);" onClick="SFCMS_Qianadd()">签到</a></div><div class="qiandao_c">+'.jinbi.'金币</div>

</div>';
}else{
$row=$this->db->query("SELECT CS_Logo,CS_Qianm,CS_Nichen,CS_Name,CS_Cion,CS_Vip,CS_Hits,CS_Qdtian,CS_Qdsjian,CS_Qda,CS_Qdb,CS_Qdc,CS_Qdd,CS_Leiji FROM ".CS_SqlPrefix."user where cs_id='".$this->session->userdata('cs_id')."'")->row();
$wjinbi='<font color="#ff0000">+'.wjinbi.'</font>金币<br><a href="'.site_url('m/sfq').'" style="color:#0099FF" target="_blank">领取签到额外奖励>></a>';
$qjinbi='<font color="#ff0000">+'.qjinbi.'</font>金币<br><a href="'.site_url('m/sfq').'" style="color:#0099FF" target="_blank">领取签到额外奖励>></a>';
$swjinbi='<font color="#ff0000">+'.swjinbi.'</font>金币<br><a href="'.site_url('m/sfq').'" style="color:#0099FF" target="_blank">领取签到额外奖励>></a>';
$ssjinbi='<font color="#ff0000">+'.ssjinbi.'</font>金币<br><a href="'.site_url('m/sfq').'" style="color:#0099FF" target="_blank">领取签到额外奖励>></a>';
if($row->CS_Leiji<=5){
$a=5;
$c=$a-$row->CS_Leiji;
if($c==0){
$c='今天可以领取奖励'.$wjinbi.'';
}else{
$c='再连续签到'.$c.'天即可'.$wjinbi.'';
}
}else if($row->CS_Qda==0){
$c='马上领取签到5天奖励'.$wjinbi.'';
}else{
if($row->CS_Leiji<=7){
$a=7;
$c=$a-$row->CS_Leiji;
if($c==0){
$c='今天可以领取奖励'.$qjinbi.'';
}else{
$c='再连续签到'.$c.'天即可'.$qjinbi.'';
}
}else if($row->CS_Qdb==0){
$c='马上领取签到7天奖励'.$qjinbi.'';
}else{
if($row->CS_Leiji<=15){
$a=15;
$c=$a-$row->CS_Leiji;
if($c==0){
$c='今天可以领取奖励'.$swjinbi.'';
}else{
$c='再连续签到'.$c.'天即可'.$swjinbi.'';
}
}else if($row->CS_Qdc==0){
$c='马上领取签到15天奖励'.$swjinbi.'';
}else{
if($row->CS_Leiji<=30){
$a=30;
$c=$a-$row->CS_Leiji;
if($c==0){
$c='今天可以领取奖励'.$ssjinbi.'';
}else{
$c='再连续签到'.$c.'天即可'.$ssjinbi.'';
}
}
}
}
}
if($this->datetime($row->CS_Qdsjian)>86400){
echo '

<div class="sf_qiandao">

<div class="qiandao_a"><font color="#00CCFF">已签到:</font><font color="#FFCC00">'.$row->CS_Qdtian.'天</font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00CCFF">金币：</font><font color="#ff0000">'.$row->CS_Cion.'</font>&nbsp;&nbsp;<font color="#FFCC00">金币</font></div>
<div class="qiandao_f"><ul class="qiandao_q">'.$shijian.'<br>'.$yue.'月'.$ri.'日</ul></div>
<div class="qiandao_b"><a href="javascript:void(0);" onClick="SFCMS_Qianadd()">签到</a></div><div class="qiandao_c">+'.jinbi.'金币</div>

</div>';
}else{
echo '<div class="sf_qiandao">

<div class="qiandao_a"><font color="#00CCFF">已签到:</font><font color="#FFCC00">'.$row->CS_Qdtian.'天</font>&nbsp;&nbsp;&nbsp;<font color="#00CCFF">金币：</font><font color="#ff0000">'.$row->CS_Cion.'</font>&nbsp;&nbsp;<font color="#FFCC00">金币</font></div>
<div class="qiandao_d"><a href="javascript:void(0);" onClick="SFCMS_Qianadd()">已签到</a></div>
<div class="qiandao_e"><ul class="qiandao_q">'.$c.'</ul></div>

</div>';
}
}
        }

public function rili()
	{
	$selectedDay = date( 'd'); 
$selectedMonth = date( 'm'); 
$selectedYear = date( 'Y'); 
$yueshi= date('Y-M');
//
			$sql="SELECT CS_Name,CS_Content,CS_Qdtime,CS_Cion,CS_Y,CS_M,CS_D FROM ".CS_SqlPrefix."qd where cs_sid=0 and cs_m='".$selectedMonth."' order by CS_QdTime desc limit 15";
			$rows=$this->db->query($sql);
			if($rows){
			foreach($rows->result() as $rows){
			$rowa=$this->db->query("SELECT CS_Logo,CS_Qianm,CS_Nichen,CS_Name,CS_Cion,CS_Hits,CS_Qdts,CS_Name FROM ".CS_SqlPrefix."user where cs_name='".$rows->CS_Name."'")->row();
			
			
			$list.=''.$rows->CS_D.'';
			}
			}
//获取当月第一天是数值型星期几
$firstday = date( 'w',mktime(0,0,0,$selectedMonth,1,$selectedYear)); 
//找出本月最后一天 
$lastday = 31; 
do { 
$monthOrig = date( 'm',mktime(0,0,0,$selectedMonth,1,$selectedYear)); 
$monthTest = date( 'm',mktime(0,0,0,$selectedMonth,$lastday,$selectedYear)); 
if ($monthTest != $monthOrig) { $lastday -= 1; } 
} while ($monthTest != $monthOrig); 
//获取当月对应的英文名
$monthName = date( 'F',mktime(0,0,0,$selectedMonth,1,$selectedYear)); 
//显示日历表头
$days = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); 
$dayRow = 0; 
print( "<table bgcolor=\"#bbFFFF\">"); 
print( "<caption valign=\"center\"><b>$monthName $selectedYear</b></caption>"); 
print( "<tr>\n"); 
for($i=0; $i<=6; $i++) { 
print( "<td width=10%>$days[$i]</td>\n"); 
} 
print( "</tr>\n"); 
print( "<tr>\n"); 
//空出当月第一天前面的空位
while($dayRow < $firstday) { 
print( "<td><!-- This day in last month --></td>"); 
$dayRow += 1; 
} 
$day = 0; 

while($day < $lastday) { 
//下面的判断语句用于每显示7个时间位置转换到下一行
if(($dayRow % 7) == 0) { 
print( "</tr>\n<tr>\n"); 
} 
$adjusted_day = $day+1;
//当天的日期用红色显示
if($adjusted_day==$selectedDay){
echo "<td class='r".$adjusted_day."'><font color=#ff0000>".$adjusted_day."</font></td>";
}else{echo "<td class='r".$adjusted_day."'>".$adjusted_day."</td>";} 
$day += 1; 
$dayRow += 1; 
} 
print( "\n</tr>\n</table>"); 
echo''.$list.'';
        }


	public function admin()
	{
              header("Location: ".site_url('m/sfq/admin').""); 
        }
}
