Files
itflow/agent/modals/kb/kb_import_markdown.php

66 lines
3.1 KiB
PHP

<?php
/*
* Import Markdown files into the Knowledge Base - each .md file picked becomes an article written
* in Markdown, a draft for agents only, in the category picked (import_markdown_kb_articles,
* agent/post/kb.php). ?category starts it in the list's category.
*/
require_once '../../../includes/modal_header.php';
$kb_closed = kbClosedText(2);
if ($kb_closed !== '') {
exit(json_encode(['error' => $kb_closed]));
}
$kb_import_category = kbCategoryId($_GET['category'] ?? 0);
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fab fa-fw fa-markdown me-2"></i>Import Markdown Files</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<div class="modal-body">
<?php if (!kbMarkdownReady()) { ?>
<div class="alert alert-warning mb-0">Articles in Markdown arrive with the next database update - run it from Maintenance &gt; Update first.</div>
<?php } else { ?>
<div class="mb-3">
<label class="form-label">Markdown files <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-file-import"></i></span>
<input type="file" class="form-control" name="files[]" multiple required accept=".md,.markdown,.mdown,.mkd,text/markdown">
</div>
<div class="form-text">Each becomes an article written in Markdown, named by the heading it starts with or its file name - up to 50 at a time. They come in as drafts for agents only, to read through before you publish them. Pictures a file points to on your computer aren't brought in.</div>
</div>
<div>
<label class="form-label">Category</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-list-ul"></i></span>
<select class="form-select select2" name="category_id">
<option value="0">- No category -</option>
<?php foreach (categoryPicker('kb', $kb_import_category ? [$kb_import_category] : []) as $category_id => $category_row) { ?>
<?= categoryOptionHtml($category_row, intval($category_id) === $kb_import_category) ?>
<?php } ?>
</select>
<?= categoryAddButtonHtml('kb') ?>
</div>
</div>
<?php } ?>
</div>
<div class="modal-footer">
<?php if (kbMarkdownReady()) { ?>
<button type="submit" name="import_markdown_kb_articles" class="btn btn-primary fw-bold"><i class="fas fa-file-import me-2"></i>Import</button>
<?php } ?>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';