{* Smarty *}

{literal}
<script type="text/javascript">
//<![CDATA[
  
$(function() {
  AltButtons();
});

function SvtGet(){
  $.ajax({
    async: false,
    timeout: 3000,
    type: 'GET',
    url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/SvtGet.ajax.php{literal}",
    success: function(answ){
      DialogStandartOpen('SvtFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessSelectRecord}{literal}");
    }
  });
}

function SvtSelect(){
  var VarCountSelectedRows = $("#GridSvt").jqGrid('getGridParam','selarrrow').length;
  if(1 == VarCountSelectedRows){
    var VarId = $("#GridSvt").jqGrid('getGridParam','selrow');
    var VarText = '';
    if ($("#GridSvt").jqGrid('getRowData',VarId).svt_name.length){
      VarText = '('+ $("#GridSvt").jqGrid('getRowData',VarId).svt_name +') ';
    }
    VarText = VarText + $("#GridSvt").jqGrid('getRowData',VarId).svt_buxname;
    if(!$("#FrmAgreeSvtCheckboxes"+VarId).length){
      $("#FormAdvSvtContent").html('<div id="FrmAgreeSvtCheckboxes'+VarId+'"><input type="checkbox" id="FrmAgreeSvtCheckboxes'+VarId+'" name="FrmAgreeSvtCheckboxes[]" value="'+VarId+'" checked /> '+VarText+'&nbsp;<img style="vertical-align:middle;" title="Удалить" alt="Удалить" src="{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSmarty}/{$MS_SP->Sp_TemplateName}{literal}/css/images/delete.png" class="MsPseudoAT" onclick=\'$("#FrmAgreeSvtCheckboxes'+VarId+'").remove();\'></div>');
    }
    $("#SvtFrm").dialog("destroy");
  }
  else{
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectOnlyOneRecord}{literal}");
  }
}

//$(function() {
//  $('.DemandsDetail').flexigrid({height:'auto', width:'auto', nowrap:false});
//});

function showResponseFormDemandsEdit(responseText){
  if(typeof(responseText['error'])=='undefined'){
    DialogStandartMessageOpen("message", responseText['message']);
  }
  else{
    DialogStandartMessageOpen("error", responseText['error']);
  }
  DemandsDetailLoad();
}

$(function(){
  var options = {
    success: showResponseFormDemandsEdit,
    timeout: 3000
  };
  $("#FormDemandsEdit").validate({
    submitHandler: function(form) {
      $(form).ajaxSubmit(options);
    },
    ignore: "",
    rules : {
    },
    messages: {
    },
    errorPlacement: function(error, element) {
      var er = element.attr("name");
      error.appendTo($("label[for='" + er + "']").next() );
    }
  });
});
//]]>
</script>
{/literal}

<div class="ui-widget-content ui-corner-all" style="width: 450px;">
  <h3 class="ui-widget-header ui-corner-all">Заявка №{$ArrDemands.demands_id}</h3>
  <div style="padding-left: 7px; padding-right: 7px; padding-bottom: 7px;">
    <form action="{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/DemandsSave.ajax.php" method="post" name="FormDemandsEdit" id="FormDemandsEdit">
      <input id="demands_id" name="demands_id" type="hidden" value="{if isset($ArrDemands.demands_id)}{$ArrDemands.demands_id}{/if}" />
      <input id="demands_intdocnum" name="demands_intdocnum" type="hidden" value="{if isset($ArrDemands.demands_intdocnum)}{$ArrDemands.demands_intdocnum}{/if}" />
      <input id="demands_intdocdate" name="demands_intdocdate" type="hidden" value="{if isset($ArrDemands.demands_intdocdate)}{$ArrDemands.demands_intdocdate|date_format:"%d.%m.%Y"}{/if}" />
      <input id="FrmAgreeUsersCheckboxes" name="FrmAgreeUsersCheckboxes[]" type="hidden" value="{if isset($ArrDemands.users_id)}{$ArrDemands.users_id}{/if}" />
      <table>
        <tr>
          <td><label for="FrmAgreeSprStatusCheckboxes[]">Статус :&nbsp;</label><span></span></td>
          <td>
            {foreach $ArrSprStatus as $val}
              {if $val@first}
                <select id="FrmAgreeSprStatusCheckboxes" name="FrmAgreeSprStatusCheckboxes[]">
                  <option value="">---выберите статус---</option>
              {/if}
                  <option value="{$val.sprstatus_id}" {if isset($ArrDemands.sprstatus_id) && $ArrDemands.sprstatus_id eq $val.sprstatus_id}selected="selected"{/if}>{$val.sprstatus_name}</option>
              {if $val@last}
                </select>
              {/if}
            {/foreach}
          </td>
        </tr>
        <tr><td><label>Дата:</label></td><td>{$ArrDemands.demands_date|date_format:"%d.%m.%Y %H:%M:%S"}</td></tr>
        <tr>
          <td><label for="FrmSvtHidden">СВТ:</label><span></span>&nbsp;<img style="vertical-align: middle;" title="Выбрать СВТ" alt="Выбрать СВТ" src="/{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSmarty}/{$MS_SP->Sp_TemplateName}/css/images/application_form_magnify.png" class="MsPseudoAT" onclick='SvtGet();' /><input type="hidden" id="FrmSvtHidden" name="FrmSvtHidden" value="" /></td>
          <td id="FormAdvSvtContent">
            {if isset($ArrDemands.svt_id)}
              <div id="FrmAgreeSvtDivCheckboxes{$ArrDemands.svt_id}"><input id="FrmAgreeSvtCheckboxes{$ArrDemands.svt_id}" name="FrmAgreeSvtCheckboxes[]" value="{$ArrDemands.svt_id}" type="hidden" />{if isset($ArrDemands.svt_name)}({$ArrDemands.svt_name}) {/if}{$ArrDemands.svt_buxname}</div>
            {/if}
          </td>
        </tr>
        <tr><td><label>Подразделение:</label></td><td>{if isset($ArrDemands.structureorganization_title)}{$ArrDemands.structureorganization_title}{/if}</td></tr>
        <tr><td><label>Инв. номер:</label></td><td>{if isset($ArrDemands.svt_invnum)}{$ArrDemands.svt_invnum}{/if}</td></tr>
        <tr><td><label>Пользователь:</label></td><td>{if isset($ArrDemands.users_fio)}{$ArrDemands.users_fio}{/if}</td></tr>
        <tr><td><label>Телефон:</label></td><td>{if isset($ArrDemands.users_tel)}{$ArrDemands.users_tel}{/if}</td></tr>
        <tr><td><label>Вн. телефон:</label></td><td>{if isset($ArrDemands.users_telint)}{$ArrDemands.users_telint}{/if}</td></tr>
        <tr>
          <td><label for="FrmAgreeDemandsClassifCheckboxes[]">Классификация :&nbsp;</label><span></span></td>
          <td>
            {foreach $ArrDemandsClassif as $val}
              {if $val@first}
                <select id="FrmAgreeDemandsClassifCheckboxes" name="FrmAgreeDemandsClassifCheckboxes[]">
                  <option value="">---выберите классификацию---</option>
              {/if}
                  <option value="{$val.demandsclassif_id}" {if isset($ArrDemands.demandsclassif_id) && $ArrDemands.demandsclassif_id eq $val.demandsclassif_id}selected="selected"{/if}>{$val.demandsclassif_name}</option>
              {if $val@last}
                </select>
              {/if}
            {/foreach}
          </td>
        </tr>
        <tr>
          <td><label for="FrmAgreeMasterCheckboxes[]">Исполнитель :&nbsp;</label><span></span></td>
          <td>
            {foreach $ArrUsersMaster as $val}
              {if $val@first}
                <select id="FrmAgreeMasterCheckboxes" name="FrmAgreeMasterCheckboxes[]">
<!--                  <option value="">---выберите исполнителя---</option>-->
              {/if}
                  <option value="{$val.users_id}" {if (isset($ArrDemands.demands_masterid) && $ArrDemands.demands_masterid eq $val.users_id) || (!isset($ArrDemands.demands_masterid) && $smarty.session.SessionAuth.id eq $val.users_id)}selected="selected"{/if}>{$val.users_fio}</option>
              {if $val@last}
                </select>
              {/if}
            {/foreach}
          </td>
        </tr>
        <tr><td><label>№ служ. записки:</label></td><td>{if isset($ArrDemands.demands_intdocnum)}{$ArrDemands.demands_intdocnum}{/if}</td></tr>
        <tr><td><label>Дата служ. записки:</label></td><td>{if isset($ArrDemands.demands_intdocdate)}{$ArrDemands.demands_intdocdate|date_format:"%d.%m.%Y"}{/if}</td></tr>
        <tr>
          <td colspan="2" class="MsFormSubmit"><input style="text-align: center;" class="AltButtons" name="FormSubmit" value="сохранить" type="submit" /></td>
        </tr>
      </table>
    </form>
  </div>
</div>