diff --git a/hwe/b_myPage.php b/hwe/b_myPage.php index 73fdd6ba..c04bf440 100644 --- a/hwe/b_myPage.php +++ b/hwe/b_myPage.php @@ -175,10 +175,16 @@ $('#die_immediately').click(function(){ - +
+ +
+ - +
+ +
+ @@ -190,7 +196,10 @@ $('#die_immediately').click(function(){ - +
+ +
+ diff --git a/hwe/func_history.php b/hwe/func_history.php index 11a3bbe3..49d9e299 100644 --- a/hwe/func_history.php +++ b/hwe/func_history.php @@ -101,12 +101,20 @@ function getAuctionLogRecent(int $count) { } //DB-based -function formatHistoryToHTML(array $history):string{ +function formatHistoryToHTML(array $history, ?string $type=null):string{ $result = []; - foreach($history as $item){ - $result[] = ConvertLog($item); + if($type){ + foreach($history as $seq=>$item){ + $result[] = "
".ConvertLog($item).'
'; + } } - return join('
', $result); + else{ + foreach($history as $seq=>$item){ + $result[] = '
'.ConvertLog($item).'
'; + } + } + + return join('', $result); } function pushGeneralActionLog(int $generalID, ?array $history, ?int $year=null, ?int $month=null) { @@ -134,10 +142,19 @@ function pushGeneralActionLog(int $generalID, ?array $history, ?int $year=null, function getGeneralActionLogRecent(int $generalID, int $count):array{ $db = DB::db(); - return $db->queryFirstColumn( - 'SELECT `text` from general_record WHERE general_id = %i AND log_type = "action" order by id desc LIMIT %i', + return Util::convertPairArrayToDict($db->queryAllLists( + 'SELECT `id`,`text` from general_record WHERE general_id = %i AND log_type = "action" order by id desc LIMIT %i', $generalID, $count - ); + )); +} + +function getGeneralActionLogMore(int $generalID, int $startSeq, int $count):array{ + $db = DB::db(); + + return Util::convertPairArrayToDict($db->queryAllLists( + 'SELECT `id`,`text` from general_record WHERE general_id = %i AND log_type = "action" AND id < %i order by id desc LIMIT %i', + $generalID, $startSeq, $count + )); } function pushBattleResultLog(int $generalID, array $history, ?int $year=null, ?int $month=null) { @@ -165,10 +182,19 @@ function pushBattleResultLog(int $generalID, array $history, ?int $year=null, ?i function getBattleResultRecent(int $generalID, int $count):array { $db = DB::db(); - return $db->queryFirstColumn( - 'SELECT `text` from general_record WHERE general_id = %i AND log_type = "battle_brief" order by id desc LIMIT %i', + return Util::convertPairArrayToDict($db->queryAllLists( + 'SELECT `id`, `text` from general_record WHERE general_id = %i AND log_type = "battle_brief" order by id desc LIMIT %i', $generalID, $count - ); + )); +} + +function getBattleResultMore(int $generalID, int $startSeq, int $count):array { + $db = DB::db(); + + return Util::convertPairArrayToDict($db->queryAllLists( + 'SELECT `id`, `text` from general_record WHERE general_id = %i AND log_type = "battle_brief" AND id < %i order by id desc LIMIT %i', + $generalID, $startSeq, $count + )); } function pushBattleDetailLog(int $generalID, array $history, ?int $year=null, ?int $month=null) { @@ -196,12 +222,20 @@ function pushBattleDetailLog(int $generalID, array $history, ?int $year=null, ?i function getBattleDetailLogRecent(int $generalID, int $count):array { $db = DB::db(); - return $db->queryFirstColumn( - 'SELECT `text` from general_record WHERE general_id = %i AND log_type = "battle" order by id desc LIMIT %i', + return Util::convertPairArrayToDict($db->queryAllLists( + 'SELECT `id`,`text` from general_record WHERE general_id = %i AND log_type = "battle" order by id desc LIMIT %i', $generalID, $count - ); + )); } +function getBattleDetailLogMore(int $generalID, int $startSeq, int $count):array { + $db = DB::db(); + + return Util::convertPairArrayToDict($db->queryAllLists( + 'SELECT `id`,`text` from general_record WHERE general_id = %i AND log_type = "battle" AND id < %i order by id desc LIMIT %i', + $generalID, $startSeq, $count + )); +} function pushGeneralHistoryLog(int $generalID, ?array $history, $year=null, $month=null) { if(!$history){ diff --git a/hwe/j_general_log_old.php b/hwe/j_general_log_old.php new file mode 100644 index 00000000..3b397b45 --- /dev/null +++ b/hwe/j_general_log_old.php @@ -0,0 +1,103 @@ +false, + 'reason'=>'요청 타입이 올바르지 않습니다.' + ]); +} + +if($generalID <= 0 || $reqTo <= 0){ + return Json::die([ + 'result'=>false, + 'reason'=>'요청 대상이 올바르지 않습니다.' + ]); +} + +$db = DB::db(); + +$me = $db->queryFirstRow('SELECT no,nation,officer_level,con,turntime,belong,permission,penalty from general where owner=%i', $userID); +$nationID = $me['nation']; + + +$con = checkLimit($me['con']); +if ($con >= 2) { + Json::die([ + 'result'=>false, + 'reason'=>'접속 제한입니다.' + ]); +} + +if($generalID !== $targetID){ + [$testGeneralNationID, $testGeneralNPCType] = $db->queryFirstList('SELECT nation,npc FROM general WHERE no = %i', $targetID); + + $permission = checkSecretPermission($me); + if($permission < 0){ + Json::die([ + 'result'=>false, + 'reason'=>'국가에 소속되어있지 않습니다.' + ]); + } + if ($permission < 1 && $testGeneralNPCType < 2) { + Json::die([ + 'result'=>false, + 'reason'=>'권한이 부족합니다. 수뇌부가 아니거나 사관년도가 부족합니다.' + ]); + } + + if($testGeneralNationID !== $nationID){ + Json::die([ + 'result'=>false, + 'reason'=>'동일한 국가의 장수가 아닙니다.' + ]); + } +} + +if($reqType == 'generalAction'){ + $result = getGeneralActionLogMore($targetID, $reqTo, 30, $lastSeq); + Json::die([ + 'result'=>true, + 'reason'=>'success', + 'sequence'=>$lastSeq, + 'log'=>array_map(function($data){return ConvertLog($data);}, $result) + ]); +} +if($reqType == 'battleResult'){ + $result = getBattleResultMore($targetID, $reqTo, 30, $lastSeq); + Json::die([ + 'result'=>true, + 'reason'=>'success', + 'sequence'=>$lastSeq, + 'log'=>array_map(function($data){return ConvertLog($data);}, $result) + ]); +} +if($reqType == 'battleDetail'){ + $result = getBattleDetailLogMore($targetID, $reqTo, 30, $lastSeq); + Json::die([ + 'result'=>true, + 'reason'=>'success', + 'sequence'=>$lastSeq, + 'log'=>array_map(function($data){return ConvertLog($data);}, $result) + ]); +} +Json::die([ + 'result'=>false, + 'reason'=>'Invalid'.$reqType, +]); \ No newline at end of file diff --git a/hwe/js/myPage.js b/hwe/js/myPage.js index fa9da893..75c6aa27 100644 --- a/hwe/js/myPage.js +++ b/hwe/js/myPage.js @@ -30,5 +30,56 @@ jQuery(function($){ } + $('.load_old_log').click(function(){ + var $thisBtn = $(this); + var logType = $thisBtn.data('log_type'); + var $last = $('.log_{0}:last'.format(logType)); + var reqTo = null; + if($last.length){ + reqTo = $last.data('seq'); + } + + $.post({ + url:'j_general_log_old.php', + dataType:'json', + data:{ + to:reqTo, + type:logType + } + }).then(function(data){ + if(!data){ + return quickReject('로그를 받아오지 못했습니다.'); + } + if(!data.result){ + return quickReject('로그를 받아오지 못했습니다. : '+data.reason); + } + + var keys = Object.keys(data.log); + if(keys.length > 1 && keys[0] < keys[1]){ + keys.reverse(); + } + + if(keys == 0){ + $thisBtn.hide(); + return; + } + + var html = []; + $.each(keys, function(_, key){ + if($('#log_{0}_{1}'.format(logType, key)).length){ + return true; + } + var item = data.log[key]; + html.push("
{2}
".format(logType, key, item)); + }); + + $('#{0}Plate'.format(logType)).append(html); + }, errUnknown) + .fail(function(reason){ + alert(reason); + location.reload(); + }); + }) + initCustomCSSForm(); }); \ No newline at end of file