mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 00:59:03 +00:00
48 lines
2.1 KiB
PHP
48 lines
2.1 KiB
PHP
<?php
|
|
|
|
require_once '../validate_api_key.php';
|
|
|
|
require_once '../require_post_method.php';
|
|
|
|
// Parse info
|
|
require_once 'document_model.php';
|
|
|
|
// Default
|
|
$insert_id = false;
|
|
|
|
// What it says - in Markdown (document_markdown), or as HTML (document_content)
|
|
$api_markdown = documentMarkdownReady() && isset($_POST['document_markdown']) ? str_replace(["\r\n", "\r"], "\n", (string) $_POST['document_markdown']) : null;
|
|
$api_content = $api_markdown === null ? (string) ($_POST['document_content'] ?? '') : '';
|
|
|
|
if (!empty($name) && ($api_markdown !== null ? trim($api_markdown) !== '' : $api_content !== '')) {
|
|
|
|
// Create document
|
|
$insert_sql = mysqli_query($mysqli,"INSERT INTO documents SET document_name = '$name', document_description = '$description', document_content = '', document_content_raw = '', document_folder_id = $folder, document_created_by = 0, document_client_id = $client_id");
|
|
|
|
// Check insert & get insert ID
|
|
if ($insert_sql) {
|
|
$insert_id = mysqli_insert_id($mysqli);
|
|
|
|
// Pasted images become files of the document's - for Markdown, the HTML is made from it
|
|
if ($api_markdown !== null) {
|
|
$api_markdown = markdownSaveImages($api_markdown, $insert_id);
|
|
$processed_html = markdownToHtml($api_markdown);
|
|
} else {
|
|
$processed_html = saveBase64Images($api_content, $_SERVER['DOCUMENT_ROOT'] . "/uploads/documents/", "uploads/documents/", $insert_id);
|
|
}
|
|
|
|
// Document update content
|
|
mysqli_query($mysqli, "UPDATE documents SET document_content = '" . mysqli_real_escape_string($mysqli, $processed_html) . "',
|
|
document_content_raw = '" . escapeSql(documentContentRaw($_POST['document_name'] ?? '', $processed_html)) . "'" . documentMarkdownSet($api_markdown) . "
|
|
WHERE document_id = $insert_id");
|
|
|
|
// Logging
|
|
logAudit("Document", "Create", "$name via API ($api_key_name)", $client_id, $insert_id);
|
|
logAudit("API", "Success", "Created document $name via API ($api_key_name)", $client_id);
|
|
}
|
|
|
|
}
|
|
|
|
// Output
|
|
require_once '../create_output.php';
|