/** * 离线同步TODO * * 客户端用 * @ignore */ public function todo_sync() { // 首先判断text是否存在 // 然后根据tid 判断是更新还是添加操作 // $content = z(t(v('text'))); if (!not_empty($content)) { return self::send_error(LR_API_ARGS_ERROR, __('INPUT_CHECK_BAD_ARGS', 'TEXT')); } $tid = intval(v('tid')); if ($tid < 0) { if (intval(v('is_delete')) == 1) { // 在本地添加后又在本地删除了 return self::send_result(array('msg' => __('API_MESSAGE_TODO_ALREADY_DELETE_LOCALLY'))); } // add return $this->todo_add(); } else { // 鉴权 $sql = "SELECT * FROM `todo_user` WHERE `tid` = '" . intval($tid) . "' AND `uid` = '" . intval($_SESSION['uid']) . "' LIMIT 1"; if (!($data = get_line($sql))) { return self::send_error(LR_API_FORBIDDEN, __('API_MESSAGE_CANNOT_UPDATE_OTHERS_TODO')); } // 判断最后更新时间 // // 服务器的最后操作时间 $data['last_action_at'] // 本地todo的最后操作时间 // $client_last_action_at = z(t(v('last_action_at'))); if (not_empty($data['last_action_at']) && not_empty($client_last_action_at)) { if (not_empty(v('client_now'))) { $offset = time() - strtotime(v('client_now')); } else { $offset = 0; } // 客户端时间校正 // 你不能穿越时空 if (strtotime(v('last_action_at')) > strtotime(v('client_now'))) { $offset = 0; } if (strtotime($client_last_action_at) - strtotime($data['last_action_at']) + $offset <= 0) { return self::send_result(array('msg' => __('API_MESSAGE_TODO_ALREADY_HAD_OTHER_ACTION'))); } } // update if (intval(v('is_delete')) == 1) { // remove $_REQUEST['tid'] = $tid; return $this->todo_remove(); } else { // update // 先更新todo表 $sql = "UPDATE `todo` SET `content` = '" . s($content) . "' WHERE `id` = '" . intval($tid) . "' LIMIT 1"; run_sql($sql); $sql = "UPDATE `todo_user` SET \n\t\t\t\t`is_star` = '" . intval(v('is_star')) . "', \n\t\t\t\t`is_public` = '" . intval(v('is_public')) . "', \n\t\t\t\t`status` = '" . intval(v('status')) . "',\n\t\t\t\t`last_action_at` = NOW() WHERE `tid` = '" . intval($tid) . "' AND `uid` = '" . intval($_SESSION['uid']) . "' LIMIT 1"; run_sql($sql); return self::send_result(get_todo_info_by_id($tid, true)); } } }
function api_checklist_add() { $content = z(t(v('text'))); if (!not_empty($content)) { return apiController::send_error(LR_API_ARGS_ERROR, 'TEXT CAN\'T EMPTY'); } $tid = intval(v('tid')); if (intval($tid) < 1) { return apiController::send_error(LR_API_ARGS_ERROR, 'TID NOT EXISTS'); } // check user $tinfo = get_todo_info_by_id($tid); if (intval($tinfo['details']['is_public']) == 0 && uid() != $tinfo['owner_uid']) { return apiController::send_error(LR_API_FORBIDDEN, 'ONLY PUBLIC TODO CAN ADD CHECKLIST BY OTHERS'); } $sql = "INSERT INTO `checklist` ( `tid` , `title` , `content` , `timeline` , `uid` ) VALUES ( '" . intval($tid) . "' , '" . s($content) . "' , '" . s($content) . "' , NOW() , '" . intval(uid()) . "' ) "; run_sql($sql); if (db_errno() != 0) { return apiController::send_error(LR_API_DB_ERROR, 'DATABASE ERROR ' . mysql_error()); } else { return apiController::send_result(get_line("SELECT * FROM `checklist` WHERE `id` = '" . intval(last_id()) . "' LIMIT 1", db())); } }