function checknextperiod($task) { global $_G; $allowapply = false; $nextapplytime = ''; if ($task['periodtype'] == 0) { $allowapply = TIMESTAMP - $task['dateline'] >= $task['period'] * 3600 ? 2 : -6; $nextapplytime = tasktimeformat($task['period'] * 3600 - TIMESTAMP + $task['dateline']); } elseif ($task['periodtype'] == 1) { $todaytimestamp = TIMESTAMP - (TIMESTAMP + $_G['setting']['timeoffset'] * 3600) % 86400; $allowapply = $task['dateline'] < $todaytimestamp - ($task['period'] - 1) * 86400 ? 2 : -6; $nextapplytime = $task['dateline'] - ($task['dateline'] + $_G['setting']['timeoffset'] * 3600) % 86400 + $task['period'] * 86400; $nextapplytime = dgmdate($nextapplytime); } elseif ($task['periodtype'] == 2 && $task['period'] > 0 && $task['period'] <= 7) { $task['period'] = $task['period'] != 7 ? $task['period'] : 0; $todayweek = dgmdate(TIMESTAMP, 'w'); $weektimestamp = TIMESTAMP - ($todayweek - $task['period']) * 86400; $weekstart = $weektimestamp - ($weektimestamp + $_G['setting']['timeoffset'] * 3600) % 86400; $weekfirstday = $weekstart - $task['period'] * 86400; if ($task['dateline'] && ($task['dateline'] > $weekstart || $task['dateline'] > $weekfirstday)) { $allowapply = -6; if ($task['dateline'] > $weekfirstday) { $weekstart += 604800; } $nextapplytime = dgmdate($weekstart); } else { $allowapply = 2; } } elseif ($task['periodtype'] == 3 && $task['period'] > 0) { list($year, $month) = explode('/', dgmdate(TIMESTAMP, 'Y/n')); $monthstart = mktime(0, 0, 0, $month, $task['period'], $year); $monthfirstday = mktime(0, 0, 0, $month, 1, $year); if ($task['dateline'] && ($task['dateline'] > $monthstart || $task['dateline'] > $monthfirstday)) { $allowapply = -6; if ($task['dateline'] > $monthfirstday) { $monthstart = mktime(0, 0, 0, $month + 1, $task['period'], $year); } $nextapplytime = dgmdate($monthstart); } else { $allowapply = 2; } } return array($allowapply, $nextapplytime); }
task_sufprocess(); $db->query("UPDATE {$tablepre}mytasks SET status='1', csc='100', dateline='{$timestamp}' WHERE uid='{$discuz_uid}' AND taskid='{$id}'"); $db->query("UPDATE {$tablepre}tasks SET achievers=achievers+1 WHERE taskid='{$id}'", 'UNBUFFERED'); if (!$db->result_first("SELECT COUNT(*) FROM {$tablepre}mytasks WHERE uid='{$discuz_uid}' AND status='0'")) { $db->query("UPDATE {$tablepre}members SET prompt=prompt^2 WHERE uid='{$discuz_uid}' AND prompt=prompt|2", 'UNBUFFERED'); } if ($inajax) { taskmessage('100', $task['reward'] ? 'task_reward_' . $task['reward'] : 'task_completed'); } else { showmessage('task_completed', 'task.php?item=done'); } } elseif ($result === FALSE) { $db->query("UPDATE {$tablepre}mytasks SET status='-1' WHERE uid='{$discuz_uid}' AND taskid='{$id}'", 'UNBUFFERED'); $inajax ? taskmessage('-1', 'task_failed') : showmessage('task_failed', 'task.php?item=failed'); } else { $result['t'] = tasktimeformat($result['remaintime']); if ($result['csc']) { $db->query("UPDATE {$tablepre}mytasks SET csc='{$result['csc']}\t{$timestamp}' WHERE uid='{$discuz_uid}' AND taskid='{$id}'", 'UNBUFFERED'); $msg = $result['t'] ? 'task_doing_rt' : 'task_doing'; $inajax ? taskmessage($result['csc'], $msg) : showmessage($msg, "task.php?action=view&id={$id}"); } else { $msg = $result['t'] ? 'task_waiting_rt' : 'task_waiting'; $inajax ? taskmessage('0', $msg) : showmessage($msg, "task.php?action=view&id={$id}"); } } } elseif ($action == 'giveup' && $id && !empty($formhash)) { if ($formhash != FORMHASH) { showmessage('undefined_action', NULL, 'HALTED'); } elseif (!($task = $db->fetch_first("SELECT t.taskid, mt.status FROM {$tablepre}tasks t LEFT JOIN {$tablepre}mytasks mt ON mt.taskid=t.taskid AND mt.uid='{$discuz_uid}' WHERE t.taskid='{$id}' AND t.available='2'"))) { showmessage('task_nonexistence', NULL, 'HALTED'); } elseif ($task['status'] != '0') {