{* Smarty *}

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

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

function UsersEdit(){
  var VarCountSelectedRows = $("#GridUsers").jqGrid('getGridParam','selarrrow').length;
  if(0 == VarCountSelectedRows){
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectRecord}{literal}");
  }
  else if(1 == VarCountSelectedRows){
    var VarId = $("#GridUsers").jqGrid('getGridParam','selrow');
    $.ajax({
      async: false,
      timeout: 3000,
      type: 'GET',
      url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/UsersEdit.ajax.php{literal}",
      data: {
        "users_id": VarId
      },
      success: function(answ){
        DialogStandartOpen('UsersEditFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessRecordEdit}{literal}");
      }
    });
  }
  else{
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectOnlyOneRecord}{literal}");
  }
}

function UsersDel(){
  var VarId = $("#GridUsers").jqGrid('getGridParam','selarrrow');
  var VarCountSelectedRows = VarId.length;
  if(0 == VarCountSelectedRows){
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectRecord}{literal}");
  }
  else if(1 <= VarCountSelectedRows){
    $(function() {
      CreateDivForMessage("DialogConfirmMessage");
      $("#DialogConfirmMessageText").html("{/literal}{$MS_SP->Sp_LangMessage.message.MessAreYouSureDelete}{literal}");
      $("#DialogConfirmMessage").dialog({
        title: "{/literal}{$MS_SP->Sp_LangMessage.label.GridDelete}{literal}",
        resizable: false,
        height:180,
        modal: true,
        buttons: {
          "{/literal}{$MS_SP->Sp_LangMessage.label.GridDeleteYes}{literal}": function() {
            $.ajax({
              async: false,
              timeout: 3000,
              type: "GET",
              url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/UsersDel.ajax.php{literal}",
              data: {
                users_id: VarId
              },
              success: function(answ){
                if("undefined" == typeof(answ["error"])){
                  $("#GridUsers").trigger("reloadGrid");
                  DialogStandartMessageOpen('message', answ["message"]);
                }
                else{
                  DialogStandartMessageOpen('error', answ["error"]);
                }
              }
            });
            $(this).dialog("close");
          },
          "{/literal}{$MS_SP->Sp_LangMessage.label.GridDeleteNo}{literal}": function() {
            $(this).dialog("close");
          }
        }
      });
    });
  }
  else{
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.error.ErrUnknownError}{literal}");
  }
}

function UsersRole(com,grid){
var VarCountSelectedRows = $("#GridUsers").jqGrid('getGridParam','selarrrow').length;
  if(0 == VarCountSelectedRows){
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectRecord}{literal}");
  }
  else if(1 == VarCountSelectedRows){
    var VarId = $("#GridUsers").jqGrid('getGridParam','selrow');
    $.ajax({
      async: false,
      timeout: 3000,
      type: 'GET',
      url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/UsersServicesEdit.ajax.php{literal}",
      data: {
        users_id: VarId
      },
      success: function(answ){
        DialogStandartOpen('UsersEditFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessUsersRoleAdd}{literal}");
      }
    });
  }
  else{
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.error.ErrUnknownError}{literal}");
  }
}

$(function BuildGrid(){
  $("#GridUsers").jqGrid('jqGridImport',{imptype:"jsonstring", impstring:window.localStorage.getItem("{/literal}{$smarty.session.SessionAuth.id}-GridUsers{literal}")});
  $("#GridUsers").jqGrid({
    caption:{/literal}'{$MS_SP->Sp_LangMessage.GridsCaptions.Users}'{literal},
    datatype: "json",
    url:"{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/UsersList.ajax.php{literal}",
    colNames:[{/literal}
      '{$MS_SP->Sp_LangMessage.GridsColNames.status}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.users_fio}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.structureorganization_title}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.users_jobtitle}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.users_numofice}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.tel}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.telint}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.telcell}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.email}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.note}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.login}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.password}'{literal}
    ],
    colModel:[
      {name:'users_status', index:'users_status', width:55, search: false},
      {name:'users_fio', index:'users_fio', width:200},
      {name:'structureorganization_title', index:'structureorganization_title', width:200},
      {name:'users_jobtitle', index:'users_jobtitle', width:125},
      {name:'users_numofice', index:'users_numofice', width:70},
      {name:'users_tel', index:'users_tel', width:70},
      {name:'users_telint', index:'users_telint', width:70},
      {name:'users_telcell', index:'users_telcell', width:80},
      {name:'users_email', index:'users_email', width:180},
      {name:'users_note', index:'users_note', width:150, hidden:true},
      {name:'users_name', index:'users_name', width:80, hidden:true},
      {name:'users_passclean', index:'users_passclean', width:80, hidden:true}
    ],
    multiselect: true,
    multiboxonly:true,
    rowNum:100,
    rowList:[10,25,100,500],
    pager: '#GridUsersPager',
    sortname: 'users_fio',
    sortorder: "asc",
    viewrecords: true,
    toolbar: [true,"top"],
    shrinkToFit:false, 
    gridview: true,
    autowidth: true,
    height: 290
  });
  $("#GridUsers").toolbarButtonAdd("#t_GridUsers",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Print}{literal}",position:"first",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Print}{literal}", buttonicon :'ui-icon-print', cursor: "pointer", onClickButton:function(){GridPrintReport('GridUsers');}});
  $("#GridUsers").toolbarButtonAdd("#t_GridUsers",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Add}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Add}{literal}", buttonicon :'ui-icon-plus', cursor: "pointer", onClickButton:UsersAdd });
  $("#GridUsers").toolbarButtonAdd("#t_GridUsers",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Edit}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Edit}{literal}", buttonicon :'ui-icon-pencil', cursor: "pointer", onClickButton:UsersEdit });
{/literal}
  {if isset($smarty.session.SessionAuth.SvtAdmin.reg) && 1 eq $smarty.session.SessionAuth.SvtAdmin.reg}
{literal}
  $("#GridUsers").toolbarButtonAdd("#t_GridUsers",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Del}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Del}{literal}", buttonicon :'ui-icon-trash', cursor: "pointer", onClickButton:UsersDel });
  $("#GridUsers").toolbarButtonAdd("#t_GridUsers",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Roles}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Roles}{literal}", buttonicon :'ui-icon-person', cursor: "pointer", onClickButton:UsersRole });
{/literal}
  {/if}
  {if isset($VarUsersSelect) && 1 eq $VarUsersSelect}
{literal}
    $("#GridUsers").toolbarButtonAdd("#t_GridUsers",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Select}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Select}{literal}", buttonicon :'ui-icon-check', cursor: "pointer", onClickButton:UsersSelect });
{/literal}
  {/if}
{literal}
  $("#GridUsers").jqGrid('navGrid','#GridUsersPager', {edit:false,add:false,del:false,refresh:false});
  $("#GridUsers").jqGrid("navButtonAdd","#GridUsersPager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Refresh}{literal}",
    buttonicon :'ui-icon-refresh',
    onClickButton : function (){
      $("#GridUsers").trigger("reloadGrid");
    }
  });
  $("#GridUsers").jqGrid("navButtonAdd","#GridUsersPager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.ColumnChooser}{literal}",
    buttonicon :'ui-icon-transfer-e-w',
    onClickButton : function (){
      $("#GridUsers").jqGrid('columnChooser');
    }
  });
  $("#GridUsers").navButtonAdd("#GridUsersPager",{ 
    caption: "", 
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.SaveSettings}{literal}", 
    buttonicon :'ui-icon-disk',
    onClickButton: function () {
      if (typeof window.localStorage !== 'undefined') {
        delete $("#GridUsers").jqGrid('getGridParam' ,'postData' )['filters'];
        window.localStorage.setItem("{/literal}{$smarty.session.SessionAuth.id}-GridUsers{literal}",$("#GridUsers").jqGrid('jqGridExport',{exptype:'jsonstring'}));
        DialogStandartMessageOpen('message', "{/literal}{$MS_SP->Sp_LangMessage.message.MessSettingsSaved}{literal}");
      }
      else{          
        DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.error.ErrNoLocalStorage}{literal}");
      }
    }
  });
  $("#GridUsers").navButtonAdd("#GridUsersPager",{ 
    caption: "", 
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.ResetSettings}{literal}", 
    buttonicon :'ui-icon-closethick',
    onClickButton: function () {
      CreateDivForMessage("DialogConfirmMessage");
      $("#DialogConfirmMessageText").html('{/literal}{$MS_SP->Sp_LangMessage.message.MessResetSettConfirm}{literal}');
      $("#DialogConfirmMessage").dialog({
        title: "{/literal}{$MS_SP->Sp_LangMessage.DialogTitles.ResetSettings}{literal}",
        resizable: false,
        height:180,
        modal: true,
        buttons: {
          "{/literal}{$MS_SP->Sp_LangMessage.label.GridDeleteYes}{literal}": function() {
            window.localStorage.removeItem("{/literal}{$smarty.session.SessionAuth.id}-GridUsers{literal}");
            $(this).dialog('close');
            $("#GridUsers").jqGrid('GridUnload');
            BuildGrid();
            DialogStandartMessageOpen('message', "{/literal}{$MS_SP->Sp_LangMessage.message.MessResetSettSuccess}{literal}");
          },
          "{/literal}{$MS_SP->Sp_LangMessage.label.GridDeleteNo}{literal}": function() {
            $(this).dialog('close');
          }
        }
      });
    }
  });
  $("#GridUsers").jqGrid('filterToolbar',{stringResult: true, searchOnEnter : true, defaultSearch:"cnof"});
  UpdateJqGrid("GridUsers","GridUsersWrapper");
});
//]]>
</script>
{/literal}

<div id="GridUsersWrapper" class="ui-widget-content ui-corner-all">
  <table id="GridUsers"><tr><td></td></tr></table>
  <div id="GridUsersPager"></div>
  <div id="t_toolbar1"></div>
</div>