'Invalid ID', 'docs' => array())); exit; } // Get the anlage to know the socid $anlage = new Anlage($db); if ($anlage->fetch($anlageId) <= 0) { echo json_encode(array('error' => 'Element not found', 'docs' => array())); exit; } // Get documents for this element (pdf and document types) $anlagefile = new AnlageFile($db); $files = $anlagefile->fetchAllByAnlage($anlageId); $docs = array(); foreach ($files as $file) { // Only include PDFs and documents, not images if (in_array($file->file_type, array('pdf', 'document'))) { $docs[] = array( 'id' => $file->id, 'name' => $file->filename, 'url' => $file->getUrl(), 'type' => $file->file_type, 'icon' => $file->file_type == 'pdf' ? 'fa-file-pdf-o' : 'fa-file-text-o', ); } } echo json_encode(array('docs' => $docs));