input('SERVICENAME'); $action = $request->input('ACTION'); $serverKeyClient = $request->input('SERVERKEYCLIENT'); // if ($serviceName !== 'SMARTUPDATE' || $action !== 'HISTORY_PATCH') { // return response()->json(['error' => 'Invalid request'], 400); // } if ($action === 'HISTORY_PATCH') { $this->historyPatch($serverKeyClient); } else if ($action === 'LIST_PATCH') { $this->listPatch($request); } } public function historyPatch($serverKeyClient) { $serverId = DB::table('conf_server_license') ->where('SNKEY', $serverKeyClient) ->value('ID'); if (!$serverId) { return response()->json(['error' => 'Invalid SERVERKEYCLIENT'], 404); } $patchHistory = $this->queryToSimpleTable(" SELECT TaskFinish as 'Update Date', TaskRunner as 'Update By', PDATE as 'Patch Date', PATCHNAME as 'Title', PLEVEL as 'Level', PDESC as 'Description' FROM conf_server_pendding AS t0 INNER JOIN conf_smartupdate AS t1 ON t0.PatchID = t1.PID WHERE ServerId = '$serverId' AND TaskStatus = 999 AND PAPPROVEDATE < NOW() AND PAPPROVEDATE <> '0000-00-00 00:00:00' AND TaskDate < NOW() AND TaskDate <> '0000-00-00 00:00:00' "); return $patchHistory; } public function listPatch($request) { $serverKeyClient = $request->input('SERVERKEYCLIENT'); $clientVersion = $request->input('CLIENTVERSION'); // ดึง Server ID จากฐานข้อมูล $serverId = $this->getServerId($serverKeyClient); if (!$serverId) { return response()->json(['error' => 'Invalid SERVERKEYCLIENT'], 404); } $pendingUpdates = ConfServerPendding::select( 't1.PDATE as PatchDate', 't1.PATCHNAME as Title', 't1.PLEVEL as Level', 't1.PDESC as Description', DB::raw("IF('{$clientVersion}' <= t1.major_version, 'Update', 'Version incompatible') AS Action") ) ->from('conf_server_pendding as t0') ->join('conf_smartupdate as t1', 't0.PatchID', '=', 't1.PID') ->where('t0.ServerId', $serverId) ->where('t0.TaskStatus', '<', 999) ->where('t1.PAPPROVEDATE', '<', now()) ->where('t1.PAPPROVEDATE', '<>', '0000-00-00 00:00:00') ->where('t0.TaskDate', '<', now()) ->where('t0.TaskDate', '<>', '0000-00-00 00:00:00') ->orderBy('t0.PatchID', 'ASC') ->get(); $cannotUpdateAll = false; foreach ($pendingUpdates as $index => $update) { if ($index > 0 && $update->Action == 'Update') { $update->Action = 'Require previous update'; } if ($update->Action == 'Version incompatible') { $cannotUpdateAll = true; } } DB::table('log_history')->insert([ 'HDATE' => now(), 'HSID' => $serverId, 'HACTION' => 'LIST_PATCH', ]); ConfServerPendding::where('ServerID', $serverId) ->where('TaskStatus', '<', 999) ->where('TaskDate', '<', now()) ->update(['TaskStatus' => 1]); echo view('smartupdate.patch_update', [ 'serverKeyClient' => $serverKeyClient, 'pendingUpdates' => $pendingUpdates, 'clientVersion' => $clientVersion, 'cannotUpdateAll' => $cannotUpdateAll, ]); } public function queryToSimpleTable($query, $numberSortOpt = "YES", $columnSortOpt = "YES", $colorPack = ['#DDDDDD', '#F2F2F2', '#FFFFFF', '#F2F2FF'], $noCodeIfEmpty = "NO") { $result = DB::select($query); if (empty($result)) { return $noCodeIfEmpty === "YES" ? '' : '
No data found.
'; } $columns = array_keys((array) $result[0]); $tabID = 'table' . rand() + 50; $res = $columnSortOpt === "YES" ? "" : ""; $res .= "" . ($column) . " | "; } $res .= "
" . ($row->$column) . " | "; } $res .= "