{* Smarty *}

{literal}
<script type="text/javascript">

//$(function(){
//  $("#RestoreTabs").tabs();
//});

$(function(){
  $("input[name='RestoreDbCode']").css("width","400px");
});

$(function(){
//  $("#RestoreDbForm").validate({
//    ignore: "",
//    rules: {
//      "RestoreDbCode": {
//        required: true
//      },
//      "RestoreDbFile": {
//        required: true
//      }
//    },
//    messages: {
//      Restore: "{/literal}{$MS_SP->Sp_LangMessage.message.MessRestore}{literal}"
//    },
//    errorPlacement: function(error, element) {
//      var er = element.attr("name");
//      if('Restore'==er){
////        alert(er);
//        error.appendTo($("label[for='RestoreDbFile']").next() );
//      }
//      else{
//        error.appendTo($("label[for='" + er + "']").next() );
//      }
//    }
//  });
  $("#RestorePoForm").validate({
    rules: {
      "RestorePoFile": {
        required: true,
        accept: "zip|sql"
      }
    },
    errorPlacement: function(error, element) {
      var er = element.attr("name");
      error.appendTo($("label[for='" + er + "']").next() );
    }
  });
//  $("#RestoreUserDbForm").validate({
//    rules: {
//      "RestoreUserDbFile": {
//        required: true,
//        accept: "zip|sql"
//      }
//    },
//    errorPlacement: function(error, element) {
//      var er = element.attr("name");
//      error.appendTo($("label[for='" + er + "']").next() );
//    }
//  });
//  $("#RestoreDbForm").ajaxForm({
//    beforeSend: function(){
//      $("#MessageLoading").dialog("open");
//    },
//    complete: function(){
//      $("#MessageLoading").dialog("close");
//    },
//    success: function(answ) {
//      var responseText = $.parseJSON(answ);
//      if(typeof(responseText['error'])=='undefined'){
//        DialogStandartMessageOpen("message", responseText['message']);
//      }
//      else{
//        DialogStandartMessageOpen("message", responseText['error']);
//      }
//    }
//  });
  $("#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']);
      }
    }
  });
//  $("#RestoreUserDbForm").ajaxForm({
//    beforeSend: function(){
//      $("#MessageLoading").dialog("open");
//    },
//    complete: function(){
//      $("#MessageLoading").dialog("close");
//    },
//    success: function(answ) {
//      var responseText = $.parseJSON(answ);
//      if(typeof(responseText['error'])=='undefined'){
//        DialogStandartMessageOpen("message", responseText['message']);
//      }
//      else{
//        DialogStandartMessageOpen("message", 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']);
      }
      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="RestoreTabs">
  <ul>
    <li><a href="#RestoreDbTab">{$MS_SP->Sp_LangMessage.Tabs.RestoreDb}</a></li>
    <li><a href="#RestorePoTab">{$MS_SP->Sp_LangMessage.Tabs.RestorePo}</a></li>
    <li><a href="#RestoreUserDbTab">{$MS_SP->Sp_LangMessage.Tabs.RestoreUserDb}</a></li>
  </ul>-->
<!--  <div id="RestoreDbTab">
    <h4>{$MS_SP->Sp_LangMessage.Tabs.RestoreDb}</h4>
    <form action="{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/RestoreDb.ajax.php" method="post" name="RestoreDbForm" id="RestoreDbForm" enctype="multipart/form-data">
      <table>
        <tr>
          <td><label for="RestoreDbFile">{$MS_SP->Sp_LangMessage.label.RestoreDbFile}<span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
          <td><input type="file" id="RestoreDbFile" name="RestoreDbFile" value="" /></td>
        </tr>
        {if (1 eq isset($smarty.session.SessionAuth.id) && 1 eq is_numeric($smarty.session.SessionAuth.id) && strtotime('30.09.2013') < {$smarty.now|date_format:'%d.%m.%Y'}) && 1 neq isset($VarCheckLicense)}
         <tr>
          <td><label for="RestoreDbCode">{$MS_SP->Sp_LangMessage.label.RestoreDbCode}<span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
          <td><input type="text" id="RestoreDbCode" name="RestoreDbCode" value="" /></td>
        </tr>
        {/if}
        <tr>
          <td colspan="2">
            <span class="ui-state-error"> * {$MS_SP->Sp_LangMessage.label.ReqFields}</span>
          </td>
        </tr>
        <tr>
          <td colspan="2" style="text-align: center; padding-top: 10px;">
            <input class="AltButtons" name="FormSubmitRestoreDbForm" value="{$MS_SP->Sp_LangMessage.label.Refresh}" type="submit" />
          </td>
        </tr>
      </table>
    </form>
  </div>-->
  <div id="RestorePoTab">
    <h4>{$MS_SP->Sp_LangMessage.Tabs.RestorePo}</h4>
    <h5>{if $ArrSystem.SysUpdate.system_value}{$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">Загрузить файл обновления <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
          <td>
            <input type="radio" id="RestorePoMethodCd" value="Cd" name="UrlMethod" />с компакт диска<br />
            <input type="radio" id="RestorePoMethodNet" value="Net" name="UrlMethod" />через сеть Интернет
          </td>
        </tr>
        <tr id="RestorePoMethodCdRow" style="display: none;">
          <td style="vertical-align: top;"><label for="RestorePoFile">{$MS_SP->Sp_LangMessage.label.RestoreDbFile}<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.label.Refresh*}Загрузить с компакт диска" type="submit" />
          </td>
        </tr>
        <tr id="RestorePoMethodNetRow" style="display: none;">
          <td>{*<label for="RestorePoFile">{$MS_SP->Sp_LangMessage.label.RestoreDbFile}<span class="ui-state-error">* </span>:&nbsp;</label><span></span>*}</td>
          <td id="RestorePoMethodNetResult"><input class="AltButtons" id="RestorePoMethodNetButton" name="RestorePoMethodNetButton" value="Загрузить через сеть Интернет" 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>
<!--  <div id="RestoreUserDbTab">
    <h4>{$MS_SP->Sp_LangMessage.Tabs.RestoreUserDb}</h4>
    <form action="{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/RestoreUserDb.ajax.php" method="post" name="RestoreUserDbForm" id="RestoreUserDbForm" enctype="multipart/form-data">
      <table>
        <tr>
          <td><label for="RestoreUserDbFile">{$MS_SP->Sp_LangMessage.label.RestoreUserDbFile}<span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
          <td><input type="file" id="RestoreUserDbFile" name="RestoreUserDbFile" value="" /></td>
        </tr>
        <tr>
          <td colspan="2">
            <span class="ui-state-error"> * {$MS_SP->Sp_LangMessage.label.ReqFields}</span>
          </td>
        </tr>
        <tr>
          <td colspan="2" style="text-align: center; padding-top: 10px;">
            <input class="AltButtons" name="FormSubmitRestoreUserDbForm" value="{$MS_SP->Sp_LangMessage.label.Reestablish}" type="submit" />
          </td>
        </tr>
      </table>
    </form>
  </div>-->
<!--</div>-->