Menu="UNRAID-OS"
Title="System Drivers"
Icon="icon-packages"
Tag="server"
---
<?PHP
/* Copyright 2005-2023, Lime Technology
 * Copyright 2012-2023, Bergware International.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 */
?>
<script src="/webGui/javascript/jquery.tablesorter.widgets.js"></script>

<script>
function showDrivers(options, init = false) {
  option = options;
  if (init) {
  $('#driversearch').prop('disabled', true);
  $('#select').prop('disabled', true);
  $('#rebuild').prop('disabled', true);
  $.post('/webGui/include/SysDrivers.php',{table:'t1load',option:"all"},function(data){
    clearTimeout(timers.refresh);
    $("#t1").trigger("destroy");
    $('#t1').html(data.html);
    $('#t1').tablesorter({
      sortList: [[0,0]],
      sortAppend: [[0,0]],
      widgets: ['stickyHeaders','filter','zebra'],
      widgetOptions: {
        // on black and white, offset is height of #menu
        // on azure and gray, offset is height of #header
        stickyHeaders_offset: ($('#menu').height() < 50) ? $('#menu').height() : $('#header').height(),
        filter_columnFilters: false,
        zebra: ["normal-row","alt-row"]
      }
    });
    $('div.spinner.fixed').hide('slow');
    $('#driversearch').prop('disabled', false);
    $('#select').prop('disabled', false);
    $('#rebuild').prop('disabled', data.init);
  },"json");
  } else {
    filter = [];
    filterDrivers();
  }
}

function filterDrivers() {
  var totalColumns = $('#t1')[0].config.columns;
  var filter = [];
  filter[2] = ($('#select').val() === "inuse") ? "System|Inuse|Custom|Disabled|'Kernel - Inuse'" : "";
  filter[totalColumns] = $('#driversearch').val(); // this searches all columns
  $('#t1').trigger('search', [filter]);
}

function showDriversupdate() {
  $('#rebuild').prop('disabled', true);
  $('#t1').html("");
  $('#driversearch').prop('disabled', true);
  $('#select').prop('disabled', true);
  $('div.spinner.fixed').show('slow');
  $.post('/webGui/include/SysDrivers.php',{table:'t1create',option:"all"},function(data){
    $('#rebuild').prop('disabled', false);
    showDrivers("all",true);
    $('div.spinner.fixed').hide('slow');
  });
}

function textedit(module) {
  var i=module;
  $('#text'+module).prop('disabled', false);
  $('#save'+module).attr('hidden', false);
  $('#text'+module).attr('hidden', false);
}

function removecfg(module) {
  swal({title:"_(Proceed)_?",text:"_(Remove custom modprobe.d configuration?)_: "+module,type:'warning',html:true,showCancelButton:true,confirmButtonText:"_(Proceed)_",cancelButtonText:"_(Cancel)_"},function(p){if (p) textsave(module, true); else return false;});
}

function textsave(module,remove = false) {
  var i=module;
  $('#text'+module).prop('disabled', true);
  $('#save'+module).attr('hidden', true);
  var x = (remove) ? "" : document.getElementById("text" + module).value;
  $.post('/webGui/include/SysDrivers.php',{table:'update',module:module,conf:x},function(data){
    if (data) {
      formHasUnsavedChanges=false;
      $('#text'+module).val(data.modprobe);
      $('#status'+module).html(data.state);
      if (data.state == "Custom") {
        $('#bin'+module).show();
      } else {
        $('#bin'+module).hide();
      }
      if (data.modprobe == "")  $('#text'+module).attr('hidden', true); else $('#text'+module).attr('rows', 3);
      if (data.supportpage == true) {
        if (data.support == true) {
          document.getElementById("link" + module).innerHTML = "<a href='" + data.supporturl + "'target='_blank'><i title='"+"_(Support page)_"+"' class='fa fa-phone-square'></i></a>";
        }
      }
    }
    $('#t1').trigger("updateCell",[document.getElementById('text'+module), false, null]);
    $('#t1').trigger("updateCell",[document.getElementById('status'+module), false, null]);
    var message = "_(System Drivers)_: _(A reboot is required to apply changes)_";
    addRebootNotice(message);
  },"json");
}

$('.tabs').append("<span class='status'><span class='lite label'>_(Select View)_:</span><select id='select' onchange='showDrivers(this.value)'><option value='all' >All Drivers</option><option value='inuse' selected >Inuse Drivers</option></select>");
showDrivers("all",true);
</script>

:sysdrivers_intro_help:

<form autocomplete="off" onsubmit="return false;">
  <span><input class="t1 search" id="driversearch" type="search" placeholder="Search..." onchange="filterDrivers();"></span>
</form>
<form id="sysdrivers" class="js-confirm-leave" onsubmit="return false">
  <div class="TableContainer">
    <table id='t1' class="unraid t1 tablesorter">
      <tr>
        <td><div class="spinner"></div></td>
      </tr>
    </table>
  </div>
</form>
<br>
<div>
  <input type="button" value="_(Done)_" onclick="done()">
  <input type="button" id="rebuild" value="_(Rebuild Modules)_" onclick="showDriversupdate()">
</div>
