public function syncAction()
 {
     $response = array('error' => 0, 'target_h' => array('#myAssets' => '', '#myReady' => '', '#themAssets' => '', '#themReady' => '', '#battle' => ''));
     if (Request::getUri()[0]) {
         $mid = Request::getUri()[0];
         $model = new ProfileModel();
         $match = $model->getMatchByID($mid);
         if ($match) {
             // TODO True Deposit Value
             if ($match->uid == Request::getParam('user')->id) {
                 $response['target_h']['#usum'] = 'Current deposit value: $' . $match->usum;
                 $response['target_h']['#psum'] = 'Current deposit value: $' . $match->psum;
             } else {
                 $response['target_h']['#usum'] = 'Current deposit value: $' . $match->psum;
                 $response['target_h']['#psum'] = 'Current deposit value: $' . $match->usum;
             }
             if ($match->status == 0 && $match->pid == Request::getParam('user')->id) {
                 $response['target_h']['#battle'] = '<div id="status_action">' . ' <a onclick="' . ajaxLoad(url('matchaccept'), 'match_action', 'mid:' . $match->id, 'reloadInventory|!exception') . '">' . Lang::translate("MATCH_ACCEPT") . '</a> ' . ' <a onclick="' . ajaxLoad(url('matchreject'), 'match_action', 'mid:' . $match->id, 'reloadInventory|!exception') . '">' . Lang::translate("MATCH_REJECT") . '</a></div>';
             }
             if ($match->status == 1 || $match->status == 2 && $match->blocked) {
                 if ($match->status == 1) {
                     $response['target_h']['#map_note'] = 'Go to our <a href="' . url('servers') . '" target="_blank">servers page</a> to find a server to play on';
                 } else {
                     $response['target_h']['#map_note'] = '';
                 }
                 if (Request::getParam('user')->id == $match->uid) {
                     //if userId is UID
                     $assets = $model->getMatchAssets($match->uid, $match->id);
                     $myReady = $match->uready;
                     $myWin = !$match->uwin || $match->uwin == null ? 0 : $match->uwin;
                     $oppositeAssets = $model->getMatchAssets($match->pid, $match->id);
                     $oppositeReady = $match->pready;
                     $oppositeWin = !$match->pwin || $match->pwin == null ? 0 : $match->pwin;
                 } else {
                     //else if userId is PID
                     $assets = $model->getMatchAssets($match->pid, $match->id);
                     $myReady = $match->pready;
                     $myWin = !$match->pwin || $match->pwin == null ? 0 : $match->pwin;
                     $oppositeAssets = $model->getMatchAssets($match->uid, $match->id);
                     $oppositeReady = $match->uready;
                     $oppositeWin = !$match->uwin || $match->uwin == null ? 0 : $match->uwin;
                 }
                 //current user's data
                 if ($myWin == 0) {
                     if ($myReady) {
                         if ($oppositeReady && $match->blocked) {
                             $response['target_h']['#myReady'] = Lang::translate("MATCH_READY");
                         } else {
                             $response['target_h']['#myReady'] = '<button id="readyBtn" onclick="' . ajaxLoad(url('profile', 'setReady', $match->id), 'ready', '', 'sync|reloadInventory|!exception') . ';">' . Lang::translate("MATCH_CANCEL_READY") . '</button>';
                         }
                     } else {
                         if ($assets && count($assets) > 0) {
                             $response['target_h']['#myReady'] = '<button id="readyBtn" onclick="' . ajaxLoad(url('profile', 'setReady', $match->id), 'ready', '', 'sync|reloadInventory|!exception') . ';">' . Lang::translate("MATCH_READY") . '</button>';
                         } else {
                             $response['target_h']['#myReady'] = '<button id="readyBtn" disabled>' . Lang::translate("MATCH_CANT_READY") . '</button>';
                         }
                     }
                 }
                 if ($assets && count($assets) > 0) {
                     foreach ($assets as $asset) {
                         $response['target_h']['#myAssets'] .= '<div class="assetsItem" id="my' . $asset->oldAssetId . '" ';
                         if (!$match->blocked && $myWin == 0) {
                             $response['target_h']['#myAssets'] .= 'ondblclick="removeAsset(' . $asset->oldAssetId . ');"';
                         }
                         $response['target_h']['#myAssets'] .= '><img src="http://steamcommunity-a.akamaihd.net/economy/image/' . $asset->icon_url . '" alt="icon">' . '<div class="none" id="myAssetNo' . $asset->oldAssetId . '">' . $asset->id . '</div>' . '</div>' . '<div class="assetsInfo none" id="help_my' . $asset->oldAssetId . '">' . '<div class="text">' . $asset->name . '<br/>' . "\n" . 'Price: ' . $asset->price . '<br/>' . "\n" . '' . $asset->status . '<br/>' . "\n" . '</div>' . '</div>';
                     }
                 }
                 //opposite user data
                 if ($oppositeWin == 0) {
                     if ($oppositeReady) {
                         $response['target_h']['#themReady'] = Lang::translate("MATCH_THEM_READY");
                     } else {
                         if ($oppositeAssets && count($oppositeAssets) > 0) {
                             $response['target_h']['#themReady'] = Lang::translate("MATCH_THEM_NOT_READY");
                         } else {
                             $response['target_h']['#themReady'] = Lang::translate("MATCH_THEM_NOT_READY_EMPTY");
                         }
                     }
                 }
                 if ($oppositeAssets && count($oppositeAssets) > 0) {
                     foreach ($oppositeAssets as $asset) {
                         $response['target_h']['#themAssets'] .= '<div class="assetsItem" id="them' . $asset->oldAssetId . '" >' . '<img src="http://steamcommunity-a.akamaihd.net/economy/image/' . $asset->icon_url . '" alt="icon">' . '</div>' . '<div class="assetsInfo none" id="help_them' . $asset->oldAssetId . '">' . '<div class="text">' . $asset->name . '<br/>' . "\n" . 'Price: ' . $asset->price . '<br/>' . "\n" . '' . $asset->status . '<br/>' . "\n" . '</div>' . '</div>';
                     }
                 }
                 //match battle status
                 if ($match->blocked) {
                     $count = $model->getCountMatchAssets($match->id);
                     $countRequested = $model->getCountRequestedMatchAssets($match->id);
                     if ($countRequested < $count) {
                         $response['target_h']['#battle'] = Lang::translate("MATCH_BATTLE_WAIT_FOR_REQUEST") . ' ' . $countRequested . '/' . $count;
                     } else {
                         $countReceived = $model->getCountReceivedMatchAssets($match->id);
                         if ($count > $countReceived) {
                             $response['target_h']['#battle'] = Lang::translate("MATCH_BATTLE_WAIT_FOR_RECEIVE") . ' ' . $countReceived . '/' . $count;
                         } else {
                             $response['target_h']['#battle'] = '<div>';
                             if ($myWin == 1 && $oppositeWin == 2 || $myWin == 2 && $oppositeWin == 1) {
                                 $response['target_h']['#battle'] = Lang::translate("MATCH_ENDED");
                             } else {
                                 $response['target_h']['#battle'] .= '<div>';
                                 if ($myWin > 0) {
                                     if ($myWin == 1) {
                                         $response['target_h']['#battle'] .= Lang::translate("MATCH_WIN") . '<input type="button" id="loseBttn" value="' . Lang::translate('MATCH_LOSE_CHANGE') . '" onclick="' . ajaxLoad(url('profile', 'setLose'), '', 'mid:' . $match->id, 'sync|!exception') . '"/>';
                                     }
                                     if ($myWin == 2) {
                                         $response['target_h']['#battle'] .= Lang::translate("MATCH_LOSE") . '<input type="button" id="winBttn" value="' . Lang::translate('MATCH_WIN_CHANGE') . '" onclick="' . ajaxLoad(url('profile', 'setWin'), '', 'mid:' . $match->id, 'sync|!exception') . '"/>';
                                     }
                                 } else {
                                     $response['target_h']['#battle'] .= '<input type="button" id="winBttn" value="' . Lang::translate('MATCH_SET_WIN') . '" onclick="' . ajaxLoad(url('profile', 'setWin'), '', 'mid:' . $match->id, 'sync|!exception') . '"/>';
                                     $response['target_h']['#battle'] .= '<input type="button" id="loseBttn" value="' . Lang::translate('MATCH_SET_LOSE') . '" onclick="' . ajaxLoad(url('profile', 'setLose'), '', 'mid:' . $match->id, 'sync|!exception') . '"/>';
                                 }
                                 $response['target_h']['#battle'] .= '</div>';
                                 $response['target_h']['#battle'] .= '</div>';
                                 if ($oppositeWin > 0) {
                                     if ($oppositeWin == 1) {
                                         $response['target_h']['#battle'] .= Lang::translate("MATCH_THEM_WIN");
                                     }
                                     if ($oppositeWin == 2) {
                                         $response['target_h']['#battle'] .= Lang::translate("MATCH_THEM_LOSE");
                                     }
                                 } else {
                                     $response['target_h']['#battle'] .= Lang::translate("MATCH_THEM_BATTLE_THINK");
                                 }
                                 $response['target_h']['#battle'] .= '</div>';
                             }
                             $response['target_h']['#battle'] .= '</div>';
                         }
                     }
                 }
             }
         } else {
             $response['error'] = Lang::translate("MATCH_ACCESS_DENIED");
         }
     } else {
         $response['error'] = Lang::translate("MATCH_ACCESS_DENIED");
     }
     echo json_encode($response);
     exit;
 }