diff --git a/hwe/j_diplomacy_destroy_letter.php b/hwe/j_diplomacy_destroy_letter.php new file mode 100644 index 00000000..2f9f4529 --- /dev/null +++ b/hwe/j_diplomacy_destroy_letter.php @@ -0,0 +1,134 @@ +setReadOnly(); +$userID = Session::getUserID(); + +$db = DB::db(); + +$letterNo = Util::getReq('letterNo', 'int'); + +increaseRefresh("외교부", 1); + +$me = $db->queryFirstRow('SELECT no, name, nation, level, permission, con, turntime, belong, penalty, picture, imgsvr FROM general WHERE owner=%i', $userID); + +$con = checkLimit($me['con']); +if ($con >= 2) { + Json::die([ + 'result'=>false, + 'reason'=>'접속 제한입니다.' + ]); +} + +if($letterNo === null){ + Json::die([ + 'result'=>false, + 'reason'=>'올바르지 않은 입력입니다.' + ]); +} + + +$permission = checkSecretPermission($me); +if ($permission < 4) { + Json::die([ + 'result'=>false, + 'reason'=>'권한이 부족합니다. 수뇌부가 아닙니다.' + ]); +} + +$letter = $db->queryFirstRow('SELECT * FROM ng_diplomacy WHERE no=%i AND (src_nation_id = %i OR dest_nation_id = %i) AND state = \'activated\'', $letterNo, $me['nation'], $me['nation']); +if(!$letter){ + Json::die([ + 'result'=>false, + 'reason'=>'서신이 없습니다.' + ]); +} + + +$aux = Json::decode($letter['aux']); + + +$stateOpt = $aux['state_opt']??null; + +if(($stateOpt == 'try_destroy_src' && $letter['src_nation_id'] == $me['nation'])|| +($stateOpt == 'try_destroy_dest' && $letter['dest_nation_id'] == $me['nation'])){ + Json::die([ + 'result'=>false, + 'reason'=>'이미 파기 신청을 했습니다.' + ]); +} + +$srcNation = getNationStaticInfo($letter['src_nation_id']); +$destNation = getNationStaticInfo($letter['dest_nation_id']); +$me['icon'] = GetImageURL($me['imgsvr'], $me['picture']); + + +if($letter['src_nation_id'] == $me['nation']){ + $src = new MessageTarget($me['no'], $me['name'], $srcNation['nation'], $srcNation['name'], $srcNation['color'], $me['icon']); + $dest = new MessageTarget(0, '', $destNation['nation'], $destNation['name'], $destNation['color']); +} +else{ + $src = new MessageTarget($me['no'], $me['name'], $destNation['nation'], $destNation['name'], $destNation['color'], $me['icon']); + $dest = new MessageTarget(0, '', $srcNation['nation'], $srcNation['name'], $srcNation['color']); +} + + +$now = new \DateTime(); +$unlimited = new \DateTime('9999-12-31'); + +if(in_array($stateOpt, ['try_destroy_src', 'try_destroy_dest'])){ + $deleteLetterNo = $letterNo; + $db->update('ng_diplomacy', [ + 'state'=>'cancelled', + 'aux'=>Json::encode($aux) + ], 'no=%i', $letterNo); + while(true){ + $deleteLetter = $db->queryFirstRow('SELECT prev_no, aux FROM ng_diplomacy WHERE no = %i AND state = \'replaced\'', $currentLetterNo); + if(!$deleteLetter){ + break; + } + $deleteAux = Json::decode($deleteLetter['aux']); + $deleteLetterNo = $deleteLetter['prev_no']; + $deleteAux['reason'] = [ + 'who'=>$me['no'], + 'action'=>'destroy', + 'reason'=>'파기' + ]; + } + $msgText = "외교 서신 #{$letterNo}를 파기했습니다."; + $lastState = 'cancelled'; +} +else{ + if ($letter['src_nation_id'] == $me['nation']) { + $aux['state_opt'] = 'try_destroy_src'; + } + else{ + $aux['state_opt'] = 'try_destroy_dest'; + } + $db->update('ng_diplomacy', [ + 'aux'=>Json::encode($aux) + ], 'no=%i', $letterNo); + + $msgText = "외교 서신 #{$letterNo}를 파기 요청합니다."; + $lastState = 'activated'; +} + +$msg = new Message( + Message::MSGTYPE_DIPLOMACY, + $src, + $dest, + $msgText, + $now, + $unlimited, + ['invalid' => true] +); +$msgID = $msg->send(); + +Json::die([ + 'result'=>true, + 'reason'=>'success', + 'state'=>$lastState +]); \ No newline at end of file diff --git a/hwe/j_diplomacy_get_letter.php b/hwe/j_diplomacy_get_letter.php index 6486ec9c..e47bc957 100644 --- a/hwe/j_diplomacy_get_letter.php +++ b/hwe/j_diplomacy_get_letter.php @@ -59,6 +59,7 @@ foreach( 'dest'=>$letter['dest'], 'prev_no'=>$letter['prev_no'], 'state'=>$letter['state'], + 'state_opt'=>($letter['aux']['state_opt']??null), 'brief'=>$letter['text_brief'], 'detail'=>$letter['text_detail'], 'date'=>$letter['date'] diff --git a/hwe/js/diplomacy.js b/hwe/js/diplomacy.js index 9399459a..b9e3ec19 100644 --- a/hwe/js/diplomacy.js +++ b/hwe/js/diplomacy.js @@ -65,12 +65,10 @@ function repondLetter(letterNo, isAgree, reason){ } }).then(function(data){ if(!data){ - $text.val(text); alert() return quickReject('응답을 실패했습니다.'); } if(!data.result){ - $text.val(text); return quickReject('응답을 실패했습니다. : '+data.reason); } @@ -101,16 +99,86 @@ function rollbackLetter(letterNo){ } }).then(function(data){ if(!data){ - $text.val(text); alert() return quickReject('회수를 실패했습니다.'); } if(!data.result){ - $text.val(text); return quickReject('회수를 실패했습니다. : '+data.reason); } - alert('회수했습니다.'); + alert('회수 했습니다.'); + + location.reload(); + return false; + + }, errUnknown) + .fail(function(reason){ + alert(reason); + }); + + return false; +} + +function destoryLetter(letterNo){ + $.post({ + url:'j_diplomacy_destory_letter.php', + dataType:'json', + data:{ + letterNo:letterNo, + } + }).then(function(data){ + if(!data){ + alert() + return quickReject('파기를 실패했습니다.'); + } + if(!data.result){ + return quickReject('파기를 실패했습니다. : '+data.reason); + } + + if(data.state == 'activated'){ + alert('파기를 요청 했습니다.'); + } + else{ + alert('파기 되었습니다.'); + } + + location.reload(); + return false; + + }, errUnknown) + .fail(function(reason){ + alert(reason); + }); + + return false; +} + +function destroyLetter(letterNo){ + var actionName = '회수를 '; + var target = 'j_diplomacy_rollback_letter.php'; + if(!isRollback){ + actionName = '파기 요청을 ' + target = 'j_diplomacy_destroy_letter.php'; + } + $.post({ + url:target, + dataType:'json', + data:{ + letterNo:letterNo, + } + }).then(function(data){ + if(!data){ + alert() + return quickReject(actionName+'실패했습니다.'); + } + if(!data.result){ + return quickReject(actionName+'실패했습니다. : '+data.reason); + } + + if(isRollback){ + + } + alert(actionName+'했습니다.'); location.reload(); return false; @@ -170,7 +238,16 @@ function drawLetter(idx, letterObj){ 'cancelled':'거부됨', 'replaced':'대체됨', }; + + var stateOptionText = { + 'try_destroy_src':'송신측의 파기 요청', + 'try_destroy_dest':'수신측의 파기 요청', + } $letter.find('.letterStatus').text(stateText[letterObj.state]); + + if(letterObj.state_opt !== null){ + $letter.find('.letterStatusOpt').text('('+stateOptionText[letterObj.state_opt]+')'); + } if(letterObj.prev_no !== null){ var $showPrev = $('#{0}'.format(letterObj.prev_no)); $showPrev.click(function(){ @@ -216,9 +293,26 @@ function drawLetter(idx, letterObj){ if(!confirm('회수하시겠습니까?')){ return false; } - return rollbackLetter(letterObj.no, false); + return rollbackLetter(letterObj.no); }); - } + } + + if(letterObj.state == 'activated'){ + var $btnDestroy = $letter.find('.btnDestroy'); + if((letterObj.src.nationID==myNationID && letterObj.state_opt == 'try_destroy_src') || + (letterObj.dest.nationID==myNationID && letterObj.state_opt == 'try_destroy_dest')){ + $btnDestroy.show().prop('disabled', true); + } + else{ + $btnDestroy.show().click(function(){ + if(!confirm('본 문서를 파기하겠습니까? (상호 동의 필요)')){ + return false; + } + return destroyLetter(letterObj.no); + }) + + } + } $letter.find('.btnRenew').click(function(){ @@ -320,6 +414,7 @@ function drawLetters(lettersObj){ if(permissionLevel == 4){ initNewLetterForm(lettersObj); + $('.letterActionPlate').show(); } $('.letterObj').detach();//첫 버전이니까 일괄 삭제 일괄 로드 diff --git a/hwe/t_diplomacy.php b/hwe/t_diplomacy.php index 58fa7c31..3091cf4b 100644 --- a/hwe/t_diplomacy.php +++ b/hwe/t_diplomacy.php @@ -89,7 +89,7 @@ var permissionLevel = ; // 문서 번호 이전 문서 - 상태 + 상태 내용(국가 내 공개)
내용(외교권자 전용)
@@ -105,10 +105,11 @@ var permissionLevel = ; //
 
- 동작 + 동작 +