{* Smarty *}

{literal}
<script type="text/javascript">
//<![CDATA[
$(function(){
  $("#RestorePoForm").validate({
    rules: {
      "RestorePoFile": {
        required: true,
        accept: "zip"
      }
    },
    errorPlacement: function(error, element) {
      var er = element.attr("name");
      error.appendTo($("label[for='" + er + "']").next() );
    }
  });
  $("#RestorePoForm").ajaxForm({
    beforeSend: function(){
      $("#MessageLoading").dialog("open");
    },
    complete: function(){
      $("#MessageLoading").dialog("close");
    },
    success: function(responseText) {
      responseText = $.parseJSON(responseText);
      if(typeof(responseText['error'])=='undefined'){
        RestorePoMethodResult(responseText['message']);
      }
      else{
        DialogStandartMessageOpen("error", responseText['error']);
      }
    }
  });
});

$(function(){
  $('input[name=UrlMethod]').change(function() {
    if('Cd' == $(this).val()){
      $("#RestorePoMethodCdRow").css("display", '');
      $("#RestorePoMethodNetRow").css("display", 'none');
    }
    else{
      $("#RestorePoMethodCdRow").css("display", 'none');
      $("#RestorePoMethodNetRow").css("display", '');
    }
    $("#RestorePoMethodRow").css("display", 'none');
    $("#RestorePoExecRow").css("display", 'none');
  });
});

function UpdateFileGet(VarSys){
  var VarMethod = $(":radio[name=UrlMethod]:checked").val();
  $.ajax({
    async: false,
    timeout: 3000,
    type: 'POST',
    url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/UpdateFileGet.ajax.php{literal}",
    data: {
      UrlType: VarSys,
      UrlMethod: VarMethod
    },
    beforeSend: function(){
      $("#MessageLoading").dialog("open");
    },
    complete: function(){
      $("#MessageLoading").dialog("close");
    },
    success: function(answ){
      answ = $.parseJSON(answ);
      if(typeof(answ['error'])=='undefined'){
//        DialogStandartMessageOpen("message", answ['message']);
        RestorePoMethodResult(answ['message']);
      }
      else{
        DialogStandartMessageOpen("error", answ['error']);
      }
    }
  });
}

$(function(){
  $('#RestorePoMethodNetButton').click(function() {
    UpdateFileGet('Sys');
  });
});

function RestorePoMethodResult(VarAnsw){
  $("#RestorePoMethodNetRow").css("display", 'none');
  $("#RestorePoMethodCdRow").css("display", 'none');
  $('#RestorePoMethodResult').html(VarAnsw+'<input id="RestorePoMethodStatus" name="RestorePoMethodStatus" value="1" type="hidden" />');
  $('#RestorePoMethodRow').css("display", '');
  $("#RestorePoExecRow").css("display", '');
  $("#RestorePoTypeRow").css("display", 'none');
  $("#RestorePoReqFieldsRow").css("display", 'none');
}

$(function(){
  $('#RestorePoExecButton').click(function() {
    $.ajax({
      async: false,
      timeout: 3000,
      type: 'GET',
      url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/UpdateExec.ajax.php{literal}",
      data: {
        UrlType: 'Sys'
      },
      success: function(answ){
        if(typeof(answ['error'])=='undefined'){
          DialogStandartMessageOpen("message", answ['message']);
        }
        else{
          DialogStandartMessageOpen("error", answ['error']);
        }
      }
    });
  });
});
//]]>
</script>
{/literal}

<div id="RestorePoTab">
  <h4>{$MS_SP->Sp_LangMessage.Tabs.RestorePo}</h4>
  <h5>{if $ArrSystem.SysUpdate.system_value}{$MS_SP->Sp_LangMessage.label.CurrentRelease}: {$ArrSystem.SysUpdate.system_value}{/if}</h5>
  <form action="{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/UpdateFileGet.ajax.php" method="post" name="RestorePoForm" id="RestorePoForm" enctype="multipart/form-data">
    <input id="UrlType" name="UrlType" value="Sys" type="hidden" />
    <table>
      <tr id="RestorePoTypeRow">
        <td style="vertical-align: top;"><label for="RestorePoMethod">{$MS_SP->Sp_LangMessage.Form.UploadUpdateFile} <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
        <td>
          <input type="radio" id="RestorePoMethodCd" value="Cd" name="UrlMethod" />{$MS_SP->Sp_LangMessage.Form.FromCD}<br />
          <input type="radio" id="RestorePoMethodNet" value="Net" name="UrlMethod" />{$MS_SP->Sp_LangMessage.Form.FromInternet}
        </td>
      </tr>
      <tr id="RestorePoMethodCdRow" style="display: none;">
        <td style="vertical-align: top;"><label for="RestorePoFile">{$MS_SP->Sp_LangMessage.label.RestoreFile}<span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
        <td id="RestorePoMethodCdResult">
          <input type="file" id="RestorePoFile" name="RestorePoFile" value="" /><br />
          <input style="margin-top: 10px;" class="AltButtons" name="FormSubmitRestorePoForm" value="{$MS_SP->Sp_LangMessage.Form.UploadUpdateFile} {$MS_SP->Sp_LangMessage.Form.FromCD}" type="submit" />
        </td>
      </tr>
      <tr id="RestorePoMethodNetRow" style="display: none;">
        <td></td>
        <td id="RestorePoMethodNetResult"><input class="AltButtons" id="RestorePoMethodNetButton" name="RestorePoMethodNetButton" value="{$MS_SP->Sp_LangMessage.Form.UploadUpdateFile} {$MS_SP->Sp_LangMessage.Form.FromInternet}" type="button" /></td>
      </tr>
      <tr id="RestorePoMethodRow" style="display: none;">
        <td></td>
        <td id="RestorePoMethodResult"></td>
      </tr>
      <tr id="RestorePoReqFieldsRow">
        <td colspan="2">
          <span class="ui-state-error"> * {$MS_SP->Sp_LangMessage.label.ReqFields}</span>
        </td>
      </tr>
      <tr id="RestorePoExecRow" style="display: none;">
        <td></td>
        <td><input class="AltButtons" id="RestorePoExecButton" name="RestorePoExecButton" value="{$MS_SP->Sp_LangMessage.label.Refresh}" type="button" /></td>
      </tr>
    </table>
  </form>
</div>