Menu="Plugins"
Title="Install Plugin"
Tag="download"
---
<?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>
  const my = {};

  function installPlugin(file) {
    if (file == null) {
      $('#plugin_file').val('');
      openPlugin(my.cmd, my.title, my.plg);
      return;
    }
    file = file.trim();
    if (!file) return console.warn('No plugin file selected');
    $.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php', {
      cmd: 'alert'
    }, function(data) {
      const forceInstall = $('#force_install').prop('checked');
      my.cmd = 'plugin install ' + file + (forceInstall ? ' force' : '');
      my.title = "_(Install Plugin)_";
      my.plg = file.replace(/^.*(\\|\/|\:)/, '').replace('.plg', '') + ':install';
      if (data == 0) {
        // no alert message - proceed with install
        setTimeout(installPlugin);
      } else {
        // show alert message and ask for confirmation
        openAlert("showchanges <?= $alerts ?>", "<?= _('Alert Message') ?>", 'installPlugin');
      }
    });
  }

  $(function() {
    $('form[name="plugin_install"]').on('submit', function(e) {
      e.preventDefault();
      installPlugin($('#plugin_file').val());
    });

    $('#plugin_tree').fileTree({
      root: '/boot/',
      top: '/boot/',
      filter:'plg',
    }, function(file) {
      $('#plugin_file').val(file);
    });
  });
</script>


<form class="max-w-20 mx-auto" name="plugin_install" method="POST" target="progressFrame">
  <p><strong>_(Enter URL of remote plugin file or local plugin file)_</strong></p>
  <div>
    <input type="text" name="file" id="plugin_file" maxlength="1024" value="">
    <label style="margin-right: 10px;" title="_(Allows you to install the same or older version of a plugin)_">
      <input type="checkbox" id="force_install" name="force_install">
      _(Force Install)_
    </label>
    <input type="submit" value="_(Install)_">
  </div>
</form>

:plugin_install_help:

<div class="max-w-20 mx-auto">
  <p><strong>_(Select local plugin file)_</strong></p>
  <div id="plugin_tree" class="textarea h-50 overflow-y-auto"></div>
</div>
