diff --git a/hwe/css/diplomacy.css b/hwe/css/diplomacy.css index e69de29b..f6ff84bc 100644 --- a/hwe/css/diplomacy.css +++ b/hwe/css/diplomacy.css @@ -0,0 +1,58 @@ +#newLetter { + width:1000px; + margin: 10px auto; +} + +#newLetter th{ + width:16ch; +} + +#newLetter textarea{ + width:100%; + min-height:6em; + color:white; + background-color:transparent; + border:none; +} + +.letterFrame{ + width:1000px; + margin: 10px auto; +} + +.letterFrame th{ + width:16ch; +} + +.letterHeader{ + position: relative; + font-size:200%; +} + +.letterDate{ + position: absolute; + right:1ch; + bottom:0.2em; + font-size:50%; + +} + +.letterBrief, .letterDetail{ + text-align: left; +} + +.letterSignerPlate{ + text-align:center; +} + +.letterSrc, .letterDest{ + display:inline-block; + margin: 0 10px; + border: 1px solid gray; + width:110px; + text-align:center; +} + +.signerNation, .signerName{ + border-top: 1px solid gray; +} diff --git a/hwe/j_diplomacy_respond_letter.php b/hwe/j_diplomacy_respond_letter.php index b2fd78ba..f7e3a283 100644 --- a/hwe/j_diplomacy_respond_letter.php +++ b/hwe/j_diplomacy_respond_letter.php @@ -64,6 +64,12 @@ if($isAgree){ 'aux'=>Json::encode($aux) ], 'no=%i', $letterNo); //TODO: 외교 서신에 대한 메시지를 양국에 발송해야함 + + if($letter['prev_no'] !== null){ + $db->update('ng_diplomacy', [ + 'state'=>'replaced', + ], 'no=%i', $letter['prev_no']); + } } else{ $aux['reason'] = [ @@ -74,7 +80,7 @@ else{ $db->update('ng_diplomacy', [ 'state'=>'cancelled', 'aux'=>Json::encode($aux) - ]); + ], 'no=%i', $letterNo); //TODO: 외교 서신에 대한 메시지를 양국에 발송해야함 } diff --git a/hwe/j_diplomacy_send_letter.php b/hwe/j_diplomacy_send_letter.php index cd54e376..9c229334 100644 --- a/hwe/j_diplomacy_send_letter.php +++ b/hwe/j_diplomacy_send_letter.php @@ -65,18 +65,10 @@ if ($permission < 4) { $srcNationNo = $me['nation']; -$nations = $db->query('SELECT nation, name, color FROM nation WHERE nation IN (%i, %i)', $srcNationNo, $destNationNo); -if(count($nations) != 2){ - Json::die([ - 'result'=>false, - 'reason'=>'올바르지 않은 국가입니다.' - ]); -} - if($prevNo !== null){ //state는 체크하지 않는걸로 하자. 파기한 것을 재 송신하는 경우도 있을 수 있음. $prevLetter = $db->queryFirstRow( - 'SELECT no, state, aux FROM ng_diplomacy WHERE no = %i AND src_nation_id IN (%i, %i) AND dest_nation_id IN (%i, %i)', + 'SELECT no, src_nation_id, dest_nation_id, state, aux FROM ng_diplomacy WHERE no = %i AND src_nation_id IN (%i, %i) AND dest_nation_id IN (%i, %i)', $prevNo, $srcNationNo, $destNationNo, $srcNationNo, $destNationNo @@ -89,6 +81,24 @@ if($prevNo !== null){ ]); } + //새로 나온 문서가 있는지 확인하자 + $newerLetter = $db->queryFirstField( + 'SELECT count(no) FROM ng_diplomacy WHERE prev_no = %i AND state != \'cancelled\'', $prevNo + ); + if($newerLetter){ + Json::die([ + 'result'=>false, + 'reason'=>'해당 문서에 대한 새로운 문서가 이미 있습니다.' + ]); + } + + if($prevLetter['src_nation_id'] != $srcNationNo){ + $destNationNo = $prevLetter['src_nation_id']; + } + else{ + $destNationNo = $prevLetter['dest_nation_id']; + } + if($prevLetter['state'] == 'proposed'){ $prevAux = Json::decode($prevLetter['aux']); $prevAux['reason'] = [ @@ -97,12 +107,20 @@ if($prevNo !== null){ 'reason'=>'new_letter' ]; $db->update('ng_diplomacy', [ - 'state'=>'cancelled', + 'state'=>'replaced', 'aux'=>Json::encode($prevAux) ], 'no=%i', $prevNo); } } +$nations = $db->query('SELECT nation, name, color FROM nation WHERE nation IN (%i, %i)', $srcNationNo, $destNationNo); +if(count($nations) != 2){ + Json::die([ + 'result'=>false, + 'reason'=>'올바르지 않은 국가입니다.' + ]); +} + if($nations[0]['nation'] == $me['nation']){ //index 순서에 따라 또 모름. $srcNation = $nations[0]; diff --git a/hwe/j_msg_get_recent.php b/hwe/j_msg_get_recent.php index 9b127b4e..1f60d3aa 100644 --- a/hwe/j_msg_get_recent.php +++ b/hwe/j_msg_get_recent.php @@ -101,7 +101,7 @@ $result['diplomacy']= array_map(function(Message $msg)use (&$nextSequence, &$min $lastType = 'diplomacy'; } $values = $msg->toArray(); - if($permission < 3){ + if($msg->dest->nationID != 0 && $permission < 3){ $values['text'] = '(외교 문서입니다)';//TODO: 외교서신이라 읽을 수 없음을 보여줘야함 } return $values; diff --git a/hwe/js/diplomacy.js b/hwe/js/diplomacy.js index d4e2edbb..f2d1c544 100644 --- a/hwe/js/diplomacy.js +++ b/hwe/js/diplomacy.js @@ -135,6 +135,10 @@ function loadLetters(){ $(function(){ +$('textarea.autosize').on('keydown keyup', function(){ + $(this).height(1).height( $(this).prop('scrollHeight')+12 ); +}) + $('#submitLetter').click(submitLetter); $('.respondAgree').click(function(){ return repondLetter(true); @@ -143,10 +147,11 @@ $('.respondDisagree').click(function(){ return repondLetter(false); }); +/* loadLetters() .then(drawLetters, errUnknown) .fail(function(reason){ alert(reason); -}); +});*/ }); \ No newline at end of file diff --git a/hwe/sql/schema.sql b/hwe/sql/schema.sql index a4ec9dbe..f233627e 100644 --- a/hwe/sql/schema.sql +++ b/hwe/sql/schema.sql @@ -565,7 +565,7 @@ CREATE TABLE `ng_diplomacy` ( `src_nation_id` INT(11) NOT NULL, `dest_nation_id` INT(11) NOT NULL, `prev_no` INT(11) NULL DEFAULT NULL, - `state` ENUM('proposed','activated','cancelled') NOT NULL DEFAULT 'proposed', + `state` ENUM('proposed','activated','cancelled','replaced') NOT NULL DEFAULT 'proposed', `text_brief` TEXT NOT NULL, `text_detail` TEXT NOT NULL, `date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, diff --git a/hwe/t_diplomacy.php b/hwe/t_diplomacy.php index d62b5d8c..9f811cf0 100644 --- a/hwe/t_diplomacy.php +++ b/hwe/t_diplomacy.php @@ -50,21 +50,61 @@ var permissionLevel = =$permission?>; // =WebUtil::printJS('../e_lib/bootstrap.bundle.min.js')?> =WebUtil::printJS('js/common.js')?> -=WebUtil::printJS('js/board.js')?> +=WebUtil::printJS('js/diplomacy.js')?>
- -