{* Smarty *}

{literal}
<script type="text/javascript">
//<![CDATA[
function showResponseFormUsersPrefAdd(responseText){
  if(typeof(responseText['error'])=='undefined'){
    //alert(responseText['message']);
    $("#flexUsersPref").flexReload();
    //$("#UsersPrefAdd").dialog("close");
    DialogStandartMessageOpen("message", responseText['message']);
  }
  else{
    DialogStandartMessageOpen("error", responseText['error']);
  }
}

$(function() {
  var options = {
    success: showResponseFormUsersPrefAdd,
    timeout: 3000
  };
  $("#FormUsersPrefAdd").validate({
    submitHandler: function(form) {
      $(form).ajaxSubmit(options);
    },
//    rules : {
//      group_id : {required : true},
//      structureorganization_id : {required : true},
//      userspref_name : {required : true},
//      userspref_password : {required : true},
//      userspref_password2 : {
//        equalTo: "#userspref_password"
//      },
//      userspref_fio : {required : true},
//      userspref_email : {email: true}
//    },
    errorPlacement: function(error, element) {
      var er = element.attr("name");
      error.appendTo($("label[for='" + er + "']").next() );
    }
  });
});
//]]>
</script>
{/literal}

<form action="{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/UsersPrefSave.ajax.php" method="post" name="FormUsersPrefAdd" id="FormUsersPrefAdd">
  <input id="users_id" name="users_id" type="hidden" value="{$ArrUsers.users_id}" />
  {foreach $MS_SP->SP_UsersPref as $val}
    {if $val@first}
    <table>
    {/if}
      <tr>
        <td><label for="users_id">{$val.userspref_name} <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
        <td>
          {if true === isset($ArrUiName) && 0 < count($ArrUiName)}
            {foreach $ArrUiName as $valUiName}
              {if $valUiName@first}
              <select id="UsersPrefId{$val.userspref_id}" name="UsersPrefId{$val.userspref_id}">
              {/if}
              <option value="{$valUiName->name}"{if $val.usersprefvalue_setvalue eq $valUiName->name} selected {/if}>{$valUiName->name}</option>
              {if $valUiName@last}
              </select>
              {/if}
            {/foreach}
          {/if}
        </td>
      </tr>
    {if $val@last}
      <tr>
        <td colspan="2">
          <span class="ui-state-error"> * </span>поля обязательные для заполнения
        </td>
      </tr>
      <tr>
        <td colspan="2" class="MsFormSubmit"><input class="AltButtons" name="FormSubmit" value="сохранить" type="submit" /></td>
      </tr>
    </table>
    {/if}
  {/foreach}
</form>