
<button class="cabinet-button mb-2" type="button" data-toggle="modal" data-target="#modalAddServer">Добавить сервер</button>
<button class="cabinet-button mb-2" type="button" data-toggle="modal" data-target="#modalAddCategory">Добавить категорию</button>
<button class="cabinet-button mb-2" type="button" data-toggle="modal" data-target="#modalAddBlock">Добавить блок</button>
<button class="cabinet-button mb-2" type="button" data-toggle="modal" data-target="#modalAddPrivilage">Добавить привилегию</button>

<div class="modal fade" id="modalAddBlock" tabindex="-1" role="dialog" aria-labelledby="modalAddBlockTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalAddBlockTitle">Добавление блока</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form id="add_product">
          <div class="form-group mb-1">
            <label for="old_pass">Название блока</label>
            <input type="text" class="form-control" name="add_block_name" id="add_block_name" placeholder="Название" required>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Выберите сервер</label>
            <select name="add_block_server" id="add_block_server" class="form-control">
              <option value="0">Все сервера</option>
              {foreach $server_list as $value}
              <option value="{$value.id}">{$value.name}</option>
              {/foreach}
            </select>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Выберите категории</label>
            <div class="category_list">
              {foreach $category_list as $value}
              <input type="checkbox" name="category-{$value.id}" id="category-{$value.id}"><label for="category-{$value.id}" class="category_list-item">{$value.name}</label>
              {/foreach}
            </div>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">id блока</label>
            <input type="text" class="form-control" name="add_block_id" id="add_block_id" placeholder="ID:DATA" required>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Ссылка на иконку</label>
            <input type="text" class="form-control" name="add_block_icon" id="add_block_icon" placeholder="https://link.png" required>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Цена блока за шт</label>
            <input type="text" class="form-control" name="add_block_price" id="add_block_price" placeholder="Цена" required>
          </div>
          <div class="form-group mt-3">
            <button class="cabinet-button" type="button" onclick="add_block();">Добавить блок</button>
          </div>
        </form>
        <script>
          function add_block() {
         var form_data = $('#add_product').serialize();
         $.ajax({
          type: "POST",
          url: "/cabinet/engine/handlers/handler.php",
          data: "operation=addproduct&" + form_data,
          success: function(data) {
            var message = JSON.parse(data);
            if (message.type == "success") {
              notif_success(message.text);
              $('#add_product')[0].reset();
              $('.label-active').removeClass('label-active');
            }else {
              notif_error(message.text);
            }
          }
        });
       }
       </script>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="modalAddServer" tabindex="-1" role="dialog" aria-labelledby="modalAddServerTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalAddServerTitle">Добавление сервера</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form id="add_server">
          <div class="form-group mb-1">
            <label for="old_pass">Название сервера</label>
            <input type="text" class="form-control" name="add_server_name" id="add_server_name" placeholder="Уникальное имя" required>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Описание сервера</label>
            <input type="text" class="form-control" name="add_server_desc" id="add_server_desc" placeholder="Краткое описание" required>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Host-базы с правами</label>
            <input type="text" class="form-control" name="add_server_dbhost" id="add_server_dbhost" placeholder="По умолчанию localhost" required>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Имя базы данных</label>
            <input type="text" class="form-control" name="add_server_dbname" id="add_server_dbname" placeholder="Имя базы с таблицей прав" required>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Пользователь базы данных</label>
            <input type="text" class="form-control" name="add_server_dblogin" id="add_server_dblogin" placeholder="Логин от базы даных" required>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Пароль пользователя</label>
            <input type="text" class="form-control" name="add_server_dbpass" id="add_server_dbpass" placeholder="Пароль от базы даных" required>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Подключённый плагин с правами</label>
            <select class="form-control" name="add_server_plugin" id="add_server_plugin">
              <option value="pex">PermissionEX</option>
              <option value="lp">LuckPerms</option>
            </select>
          </div>
          <div class="form-group mt-3">
            <button class="cabinet-button" type="button" onclick="add_server();">Добавить сервер</button>
          </div>
        </form>
        <script>
          function add_server() {
         var form_data = $('#add_server').serialize();
         $.ajax({
          type: "POST",
          url: "/cabinet/engine/handlers/handler.php",
          data: "operation=addserver&" + form_data,
          success: function(data) {
            var message = JSON.parse(data);
            if (message.type == "success") {
              notif_success(message.text);
              $('#add_server')[0].reset();
              $('.label-active').removeClass('label-active');
            }else {
              notif_error(message.text);
            }
          }
        });
       }
       </script>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="modalAddCategory" tabindex="-1" role="dialog" aria-labelledby="modalAddCategoryTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalAddCategoryTitle">Добавление категории</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form id="add_category">
          <div class="form-group mb-1">
            <label for="old_pass">Название категории</label>
            <input type="text" class="form-control" name="add_category_name" id="add_category_name" placeholder="Название" required>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Выберите сервер</label>
            <div class="category_list">
              {foreach $server_list as $value}
              <input type="checkbox" name="server-{$value.id}" id="server-{$value.id}"><label for="server-{$value.id}" class="category_list-item">{$value.name}</label>
              {/foreach}
              <input type="checkbox" name="server-0" id="server-0"><label for="server-0" class="category_list-item">Все сервера</label>
            </div>
          </div>
          <div class="form-group mt-3">
            <button class="cabinet-button" type="button" onclick="add_category();">Добавить категорию</button>
          </div>
        </form>
        <script>
          function add_category() {
            var form_data = $('#add_category').serialize();
            $.ajax({
              type: "POST",
              url: "/cabinet/engine/handlers/handler.php",
              data: "operation=addcategory&" + form_data,
              success: function(data) {
                var message = JSON.parse(data);
                if (message.type == "success") {
                  notif_success(message.text);
                  $('#add_category')[0].reset();
                  $('.label-active').removeClass('label-active');
                } else {
                  notif_error(message.text);
                }
              }
            });
          }
        </script>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="modalAddPrivilage" tabindex="-1" role="dialog" aria-labelledby="modalAddPrivilageTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalAddPrivilageTitle">Добавление привилегии</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form id="add_privilage">
          <div class="form-group mb-1">
            <label for="old_pass">Название</label>
            <input type="text" class="form-control" name="add_privilage_name" id="add_privilage_name" placeholder="Как в конфиге плагина" required>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Стоимость</label>
            <input type="number" class="form-control" name="add_privilage_price" id="add_privilage_price" placeholder="Стоимость в месяц" required>
          </div>
          <div class="form-group mb-1">
            <label for="old_pass">Выберите сервер</label>
            <div class="category_list">
              {foreach $server_list as $value}
              <input type="checkbox" name="privilage-server-{$value.id}" id="privilage-server-{$value.id}"><label for="privilage-server-{$value.id}" class="category_list-item">{$value.name}</label>
              {/foreach}
            </div>
          </div>
          <div class="form-group mt-3">
            <button class="cabinet-button" type="button" onclick="add_privilage();">Добавить привилегию</button>
          </div>
        </form>
        <script>
          function add_privilage() {
            var form_data = $('#add_privilage').serialize();
            $.ajax({
              type: "POST",
              url: "/cabinet/engine/handlers/handler.php",
              data: "operation=addprivilage&" + form_data,
              success: function(data) {
                var message = JSON.parse(data);
                if (message.type == "success") {
                  notif_success(message.text);
                  $('#add_privilage')[0].reset();
                  $('.label-active').removeClass('label-active');
                } else {
                  notif_error(message.text);
                }
              }
            });
          }
        </script>
      </div>
    </div>
  </div>
</div>
