<?php
if(!defined('IN_CRONLITE'))exit();

$act=isset($_GET['act'])?$_GET['act']:null;

if($islogin==1)
{
switch($act) {

case 'add':
$type=daddslashes($_GET['type']);
$jobid=daddslashes($_GET['jobid']);
$data=daddslashes($_POST['data']);

if(!$type || !$data) {
	exit('{"code":-1,"msg":"参数不能为空！"}');
}
if(in_array('wsign1',$vip_func) && $isvip==0 && $isadmin==0) {
	exit('{"code":-1,"msg":"抱歉，您还不是网站VIP会员，无法使用此功能。"}');
}
$sysid=isset($_POST['sys']) ? intval($_POST['sys']) : 1;
$start=isset($_POST['start']) ? intval($_POST['start']) : '0';
$stop=isset($_POST['stop']) ? intval($_POST['stop']) : '24';
$pl=isset($_POST['pl']) ? intval($_POST['pl']) : '0';

if($start>$stop)
{
	exit('{"code":0,"msg":"运行时间格式错误:开始时间大于结束时间"}');
}

$myrow=$DB->get_row("SELECT * FROM ".DBQZ."_signjob WHERE data='{$data}' and type='{$type}' limit 1");

if($jobid!=0 || $jobid=$myrow['jobid']) {
	if($myrow['uid']!=$uid && $isadmin==0 && $isdeputy==0)
		exit('{"code":-1,"msg":"你只能操作自己的任务哦！"}');
	$sql="update `".DBQZ."_signjob` set `data` ='{$data}',`pl`='$pl',`start`='$start',`stop`='$stop',`sysid`='$sysid' where `jobid`='$jobid'";
	if($DB->query($sql)){
		exit('{"code":1,"msg":"任务已成功修改！"}');
	}else{
		exit('{"code":0,"msg":"任务修改失败！'.$DB->error().'"}');
	}
} else {
	$sql="insert into `".DBQZ."_signjob` (`uid`,`type`,`data`,`lasttime`,`nexttime`,`pl`,`start`,`stop`,`sysid`) values ('{$uid}','{$type}','{$data}','".time()."','".time()."','{$pl}','{$start}','{$stop}','{$sysid}')";
	if($DB->query($sql)){
		exit('{"code":1,"msg":"'.$signTaskNames[$type].'任务已成功添加！"}');
	}else{
		exit('{"code":0,"msg":"任务添加失败！'.$DB->error().'"}');
	}
}


break;

case 'edit':
$type=daddslashes($_GET['type']);
$jobid=daddslashes($_GET['jobid']);
$page=daddslashes($_GET['page']);

if($jobid)
{
	$row1=$DB->get_row("SELECT * FROM ".DBQZ."_signjob where jobid='{$jobid}' limit 1");
	if($row1['uid']!=$uid && $isadmin==0 && $isdeputy==0)
		showmsg('你只能操作自己的任务哦！',3);
	$data=unserialize($row1['data']);
	$type=$row1['type'];
}else{
	$data=isset($_POST['data'])?unserialize($_POST['data']):array('quest'=>0,'siteid'=>1000);
}
?>
<div class="panel panel-primary">
	<div class="panel-heading bk-bg-primary">
		<h6><i class="fa fa-indent red"></i><span class="break"></span>添加<?php echo $signTaskNames[$type]?>任务</h6>
		<div class="panel-actions">
			<a href="#" onclick="showlist('signtask',1)" class="btn-close"><i class="fa fa-times black"></i></a>
		</div>
	</div>
<?php

switch($type) {
case 'klqd':
vipfunc_check('wsign1');
echo <<<HTML
<div class="panel-body">
<form action="#" role="form">
<p><label>网站首页URL:</label><br/>
<input type="text" class="form-control" name="url" value="{$data['url']}" onblur="formatURL(this)"/></p>
<p><div><label>siteid:</label></div>
<input type="text" class="form-control" name="siteid" value="{$data['siteid']}"/></p>
<p><div><label>SID: (<a href="index.php?mod=kelinksid" target="_blank">提取SID</a>)</label></div>
<input type="text" class="form-control" name="sid" value="{$data['sid']}"/></p>
<p><label>签到内容(5字内):</label><br/>
<input type="text" class="form-control" name="content" value="{$data['content']}"/></p>
<p><input type="button" class="btn btn-primary btn-block" id="signjob_edit" value="签到"/>
<input type="reset" class="btn btn-default btn-block" value="重填" /></p></form>
[ <a href="#" onclick="showlist('signtask',1)">返回上一页</a> ]
</div>
<div class="well">
<font color="blue">提示：<br/>网站首页URL格式如：http://kelink.com/</font>
</div>
HTML;
break;

case 'klol':
vipfunc_check('wsign1');
echo <<<HTML
<div class="panel-body">
<form action="#" role="form">
<p><label>网站首页URL:</label><br/>
<input type="text" class="form-control" name="url" value="{$data['url']}" onblur="formatURL(this)"/></p>
<p><label>siteid:</label><br/>
<input type="text" class="form-control" name="siteid" value="{$data['siteid']}"/></p>
<p><div><label>SID: (<a href="index.php?mod=kelinksid" target="_blank">提取SID</a>)</label></div>
<input type="text" class="form-control" name="sid" value="{$data['sid']}"/></p>
<p><input type="button" class="btn btn-primary btn-block" id="signjob_edit" value="签到"/>
<input type="reset" class="btn btn-default btn-block" value="重填" /></p></form>
[ <a href="#" onclick="showlist('signtask',1)">返回上一页</a> ]
</div>
<div class="well">
<font color="blue">提示：<br/>网站首页URL格式如：http://kelink.com/</font>
</div>
HTML;
break;

case 'dzsign':
vipfunc_check('wsign1');
echo <<<HTML
<div class="panel-body">
<form action="#" role="form">
<p><label>论坛首页网址:</label><br/>
<input type="text" class="form-control" name="url" value="{$data['url']}" required="required" onblur="formatURL(this)"/></p>
<p><label>用户名:</label><br/>
<input type="text" class="form-control" name="username" value="{$data['username']}" required="required"/></p>
<p><label>登录信息SID:(<a href="index.php?mod=dzcookie" target="_blank">点击获取登录信息SID</a>)</label><br/>
<input type="text" class="form-control" name="sid" value="{$data['sid']}" required="required"/></p>
<p>签到内容：论坛每日签到！</p>
<p><input type="button" class="btn btn-primary btn-block" id="signjob_edit" value="签到"/>
<input type="reset" class="btn btn-default btn-block" value="重填" /></p></form>
[ <a href="#" onclick="showlist('signtask',1)">返回上一页</a> ]
</div>
<div class="well">
<font color="blue">提示：<br/>论坛首页网址格式如：https://www.52pojie.cn/<br/>
本签到机只针对Discuz!的DSU每日打卡插件。本身没有开放签到功能的论坛无法签到。如果点击签到后提示“签到失败”也不一定是真的失败，有可能是程序未检测到签到成功的页面，实际能否签到成功以论坛显示为准。</font>
</div>
HTML;
break;

case 'dzdk':
vipfunc_check('wsign1');
echo <<<HTML
<div class="panel-body">
<form action="#" role="form">
<p><label>论坛首页网址:</label><br/>
<input type="text" class="form-control" name="url" value="{$data['url']}" required="required" onblur="formatURL(this)"/></p>
<p><label>用户名:</label><br/>
<input type="text" class="form-control" name="username" value="{$data['username']}" required="required"/></p>
<p><label>登录信息SID:(<a href="index.php?mod=dzcookie" target="_blank">点击获取登录信息SID</a>)</label><br/>
<input type="text" class="form-control" name="sid" value="{$data['sid']}" required="required"/></p>
<p><label>打卡插件类型:</label><br/>
<select class="form-control" name="method" default="{$data['method']}">
<option value="amupper">DSU打卡机</option>
<option value="ljdaka">亮剑打卡</option>
<option value="singcere">S!签到</option>
<option value="feixue">飞雪签到（福利吧论坛）</option>
<option value="misign">百变小米每日签到</option>
</select></p>
<p><input type="button" class="btn btn-primary btn-block" id="signjob_edit" value="签到"/>
<input type="reset" class="btn btn-default btn-block" value="重填" /></p></form>
[ <a href="#" onclick="showlist('signtask',1)">返回上一页</a> ]
</div>
<div class="well">
<font color="blue">提示：<br/>论坛首页网址格式如：https://www.52pojie.cn/<br/>
本签到机支持多种签到打卡插件。本身没有此类插件的论坛无法签到。如果点击签到后提示“签到失败”也不一定是真的失败，有可能是程序未检测到签到成功的页面，实际能否签到成功以论坛显示为准。</font>
</div>
<script>
var items = $("select[default]");
for (i = 0; i < items.length; i++) {
	$(items[i]).val($(items[i]).attr("default")||0);
}
</script>
HTML;
break;

case 'dztask':
vipfunc_check('wsign1');
echo <<<HTML
<div class="panel-body">
<form action="#" role="form">
<p><label>论坛首页网址:</label><br/>
<input type="text" class="form-control" name="url" value="{$data['url']}" required="required" onblur="formatURL(this)"/></p>
<p><label>用户名:</label><br/>
<input type="text" class="form-control" name="username" value="{$data['username']}" required="required"/></p>
<p><label>登录信息SID:(<a href="index.php?mod=dzcookie" target="_blank">点击获取登录信息SID</a>)</label><br/>
<input type="text" class="form-control" name="sid" value="{$data['sid']}" required="required"/></p>
<p><label>任务ID:</label><br/>
<input type="text" class="form-control" name="task" value="{$data['task']}"/></p>
<p><input type="button" class="btn btn-primary btn-block" id="signjob_edit" value="签到"/>
<input type="reset" class="btn btn-default btn-block" value="重填" /></p></form>
[ <a href="#" onclick="showlist('signtask',1)">返回上一页</a> ]
</div>
<div class="well">
<font color="blue">提示：<br/>论坛首页网址格式如：https://www.52pojie.cn/<br/>
利用本系统可以自动完成一些Discuz论坛的每日性领币任务，任务ID就是“申请任务”页面地址栏链接中“task=”后面的数字。</font>
</div>
HTML;
break;

case 'dzol':
echo <<<HTML
<div class="panel-body">
<form action="#" role="form">
<p><label>论坛首页网址:</label><br/>
<input type="text" class="form-control" name="url" value="{$data['url']}" required="required" onblur="formatURL(this)"/></p>
<p><label>用户名:</label><br/>
<input type="text" class="form-control" name="username" value="{$data['username']}" required="required"/></p>
<p><label>登录信息SID:(<a href="index.php?mod=dzcookie" target="_blank">点击获取登录信息SID</a>)</label><br/>
<input type="text" class="form-control" name="sid" value="{$data['sid']}" required="required"/></p>
<p><input type="button" class="btn btn-primary btn-block" id="signjob_edit" value="签到"/>
<input type="reset" class="btn btn-default btn-block" value="重填" /></p></form>
[ <a href="#" onclick="showlist('signtask',1)">返回上一页</a> ]
</div>
<div class="well">
<font color="blue">提示：<br/>论坛首页网址格式如：https://www.52pojie.cn/<br/>Discuz挂在线时长将会每5分钟运行一次</font>
</div>
HTML;
break;

case 'pwsign':
vipfunc_check('wsign1');
echo <<<HTML
<div class="panel-body">
<form action="#" role="form">
<p><label>论坛首页网址:</label><br/>
<input type="text" class="form-control" name="url" value="{$data['url']}" onblur="formatURL(this)"/></p>
<p><label>用户名:</label><br/>
<input type="text" class="form-control" name="username" value="{$data['username']}"/></p>
<p><label>登录信息SID:(<a href="index.php?mod=pwcookie2" target="_blank">点击获取登录信息SID</a>)</label><br/>
<input type="text" class="form-control" name="sid" value="{$data['sid']}" required="required"/></p>
<p><input type="button" class="btn btn-primary btn-block" id="signjob_edit" value="签到"/>
<input type="reset" class="btn btn-default btn-block" value="重填" /></p></form>
[ <a href="#" onclick="showlist('signtask',1)">返回上一页</a> ]
</div>
<div class="well">
<font color="blue">提示：<br/>论坛首页网址格式如：http://www.phpwind.net/<br/>
仅限PHPWind9.X系列。</font>
</div>
HTML;
break;

case 'pw2sign':
vipfunc_check('wsign1');
echo <<<HTML
<div class="panel-body">
<form action="#" role="form">
<p><label>论坛首页网址:</label><br/>
<input type="text" class="form-control" name="url" value="{$data['url']}" onblur="formatURL(this)"/></p>
<p><label>用户名:</label><br/>
<input type="text" class="form-control" name="username" value="{$data['username']}"/></p>
<p><label>登录信息SID:(<a href="index.php?mod=pwcookie" target="_blank">点击获取登录信息SID</a>)</label><br/>
<input type="text" class="form-control" name="sid" value="{$data['sid']}" required="required"/></p>
<p><label>签到插件类型:</label><br/>
<select class="form-control" name="method">
<option value='1'>每日打卡</option>
<option value='2'>每日心情签到</option>
<option value='3'>每日签到</option>
</select></p>
<p><input type="button" class="btn btn-primary btn-block" id="signjob_edit" value="签到"/>
<input type="reset" class="btn btn-default btn-block" value="重填" /></p></form>
[ <a href="#" onclick="showlist('signtask',1)">返回上一页</a> ]
</div>
<div class="well">
<font color="blue">提示：<br/>论坛首页网址格式如：http://www.phpwind.net/<br/>
仅限PHPWind8.X系列。</font>
</div>
HTML;
break;

case 'qiu':
vipfunc_check('wsign2');
echo <<<HTML
<div class="panel-body">
<form action="#" role="form">
<p><label>请输入邀请链接:</label><br/>
<input type="text" class="form-control" name="url" value="{$data['url']}"/></p>
<p><input type="button" class="btn btn-primary btn-block" id="signjob_edit" value="提交"/>
<input type="reset" class="btn btn-default btn-block" value="重填" /></p></form>
<a href="#" onclick="showlist('signtask',1)">返回上一页</a>
</div>
<div class="well">
<font color="blue">提示：
可用于刷球球大作战的棒棒糖，每天5个</font>
</div>
HTML;
break;

}
?>
<script>
function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function formatURL(obj){
	var url = trim($(obj).val());
	if(url == '' || url.indexOf(".")<0){
		return;
	}
	if (url.indexOf(" ")>=0){
		url = url.replace(/ /g,"");
	}
	if (url.toLowerCase().indexOf("http://")<0 && url.toLowerCase().indexOf("https://")<0){
		url = "http://"+url;
	}
	if (url.substring(url.length-1)!="/"){
		if(url.indexOf("?")>=0 || url.indexOf(".html")>=0 || url.indexOf(".php")>=0)
			url = url.substring(0,url.lastIndexOf("/")+1);
		else
			url = url+"/";
	}
	$(obj).val(url);
}
$(document).ready(function(){
$('#signjob_edit').click(function()
{
	$("#signjob_edit").val('loading');
	ajax.post("ajax.php?mod=signdo&type=<?php echo $type?>&jobid=<?php echo $jobid?>&page=<?php echo $page?>",$('form').serialize(),"html",function(data,status){
		$('#list').html(data);
	});
});
});
</script>
</div>
<?php

break;

}
}else{
	showmsg('登录失败，可能是密码错误或者身份失效了，请<a href="index.php?mod=login">重新登录</a>！',3);
}