<h4>Documents Module — Debug Audit & Fixes</h4><ul><li><strong>Fixed:</strong> Enabled error_reporting(E_ALL) in insert_update.php — was commented out.</li><li><strong>Fixed:</strong> Potential fatal error in list_documents_data.php line 45 — <code>in_array($current_role, json_decode($val['roles']))</code> crashes when <code>roles</code> is null (json_decode returns null, in_array requires array). Added safe decode with <code>?? '[]'</code> fallback, is_array guard, and null coalescing on <code>$current_role</code> and <code>is_role_secured</code>.</li><li><strong>Fixed:</strong> 14 undefined variable warnings in insert_update.php — optional POST fields ($siteidkey_fk, $domainid_fk, $CategoryName, $CategoryID, $ItemName, $DocumentItemID, etc.) not initialized after extract(). Added null coalescing defaults.</li><li><strong>Fixed:</strong> Null access in deleteDocument — <code>$deleventdata['ItemLink']</code> could be null if record not found. Added null guard before file_exists/unlink.</li><li><strong>Fixed:</strong> Undefined variable $r in document.controller.php constructor (line 59) — was checking <code>$r['_token']</code> instead of <code>$_REQUEST['_token']</code>. Also added isset() check on <code>$_REQUEST['_token']</code> to prevent undefined key warning.</li></ul><p><strong>Audit Results:</strong> Page loads fully (15,040 lines, 0 PHP errors). All 6 endpoints tested (getDocumentTable, getCategTable, getCategoryOption, getDataDocument, getDataCateg, deleteDocument validation) — 0 errors. All PHP files pass syntax check. No broken onerror patterns.</p><p><strong>Files:</strong> platform/module/DocumentManager/inc/insert_update.php, platform/module/DocumentManager/page/list_documents_data.php, controller/documents/document.controller.php</p>