-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
176: fix some problems with document upload
- missing entry in .htaccess - simplify some complexity - extracted render components - add disclaimer about supported file formats
- Loading branch information
Showing
5 changed files
with
87 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
RewriteEngine On | ||
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.webp|\.gif|\.jpeg|\.zip|\.css|\.svg|\.js|\.ttf|\.woff2|\.webmanifest)$ | ||
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.webp|\.gif|\.jpeg|\.zip|\.css|\.svg|\.js|\.ttf|\.woff2|\.webmanifest|\.pdf|\.doc|\.docx|\.xls|\.xlsx)$ | ||
RewriteRule (.*) routes.php [QSA,L] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
function renderDocument(SharedFile $shared_doc) | ||
{ | ||
$file_mime = $shared_doc->mime; | ||
|
||
$file_icon = match ($file_mime) { | ||
'pdf' => 'fas fa-file-pdf', | ||
'png', 'jpg', 'jpeg', 'gif' => 'fas fa-file-image', | ||
'doc', 'docx' => 'fas fa-file-word', | ||
'xls', 'xlsx' => 'fas fa-file-excel', | ||
'ppt', 'pptx' => 'fas fa-file-powerpoint', | ||
default => 'fas fa-file', | ||
}; | ||
?> | ||
<tr class="event-row"> | ||
<td> | ||
<i class="<?= $file_icon ?> fa-lg"></i> | ||
</td> | ||
<td> | ||
<a href="/telecharger?id=<?= $shared_doc->id ?>" hx-boost=false> | ||
<?= $shared_doc->name ?> | ||
<i class="fas fa-download"></i> | ||
</a> | ||
</td> | ||
<td> | ||
<?= $shared_doc->date->format("d/m/Y") ?> | ||
</td> | ||
<td> | ||
<a href="/documents/<?= $shared_doc->id ?>/supprimer" class="destructive"> | ||
<i class="fas fa-trash"></i> | ||
</a> | ||
</td> | ||
</tr> | ||
<?php } | ||
|
||
function renderTable($title, $docs) | ||
{ | ||
if (!$docs) | ||
return; ?> | ||
<thead> | ||
<tr> | ||
<th colspan="4"> | ||
<?= $title ?> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php foreach ($docs as $doc) { | ||
renderDocument($doc); | ||
} ?> | ||
</tbody> | ||
<?php } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,40 @@ | ||
<?php | ||
restrict_access(); | ||
|
||
$can_edit = check_auth(Access::$ADD_EVENTS); | ||
$canEdit = check_auth(Access::$ADD_EVENTS); | ||
|
||
# public files | ||
$shared_files_users = em()->getRepository(SharedFile::class)->findBy(['permission_level' => Permission::USER]); | ||
$publicDocs = SharedFile::findBy(Permission::USER); | ||
|
||
# upper authorisation files | ||
if ($can_edit) { | ||
$shared_files_coach_staff = em()->getRepository(SharedFile::class)->findBy(['permission_level' => Access::$ADD_EVENTS]); | ||
} | ||
|
||
function render_documents($shared_doc) | ||
{ | ||
$file_mime = $shared_doc->mime; | ||
|
||
switch ($file_mime) { | ||
case 'pdf': | ||
$file_icon = 'fas fa-file-pdf'; | ||
break; | ||
case 'png': | ||
case 'jpg': | ||
case 'jpeg': | ||
case 'gif': | ||
$file_icon = 'fas fa-file-image'; | ||
break; | ||
case 'doc': | ||
case 'docx': | ||
$file_icon = 'fas fa-file-word'; | ||
break; | ||
case 'xls': | ||
case 'xlsx': | ||
$file_icon = 'fas fa-file-excel'; | ||
break; | ||
case 'ppt': | ||
case 'pptx': | ||
$file_icon = 'fas fa-file-powerpoint'; | ||
break; | ||
default: | ||
$file_icon = 'fas fa-file'; | ||
break; | ||
} ?> | ||
<tr class="event-row clickable" onclick="window.location.href = '/telecharger?id=<?= $shared_doc->id ?>'"> | ||
<td> | ||
<i class="<?= $file_icon ?> fa-lg"></i> | ||
</td> | ||
<td> | ||
<?= $shared_doc->name ?> | ||
</td> | ||
<td> | ||
<?= $shared_doc->date->format("d/m/Y") ?> | ||
</td> | ||
<td><a href="/documents/<?= $shared_doc->id ?>/supprimer" class="destructive"> | ||
<i class="fas fa-trash"></i> | ||
</a></td> | ||
</tr> | ||
<?php } | ||
$adminDocs = $canEdit ? SharedFile::findBy(Access::$ADD_EVENTS) : null; | ||
|
||
include __DIR__ . "/renderDocument.php"; | ||
page("Documents partagés"); | ||
?> | ||
|
||
<?php if ($can_edit): ?> | ||
<?php if ($canEdit): ?> | ||
<nav id="page-actions"> | ||
<a href="/documents/ajouter"><i class="fas fa-plus"></i> Ajouter un document</a> | ||
</nav> | ||
<?php endif ?> | ||
|
||
<?php if (count($shared_files_users)): ?> | ||
<?php if ($can_edit): ?> | ||
<h2>Documents publics</h2> | ||
<?php endif ?> | ||
<table role="grid"> | ||
<thead class=header-responsive> | ||
<tr> | ||
<th></th> | ||
<th>Nom du fichier</th> | ||
<th>Date d'ajout</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php | ||
if (!$publicDocs && !$adminDocs): ?> | ||
|
||
<?php foreach ($shared_files_users as $shared_file) { | ||
render_documents($shared_file); | ||
} ?> | ||
<p class=center>Aucun document pour le moment 🫠</p> | ||
|
||
</tbody> | ||
</table> | ||
<?php endif ?> | ||
<?php return; | ||
endif; | ||
?> | ||
|
||
<?php if ($can_edit && count($shared_files_coach_staff)): ?> | ||
<h2>Documents admins</h2> | ||
<table role="grid"> | ||
<thead class=header-responsive> | ||
<tr> | ||
<th></th> | ||
<th>Nom du fichier</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<table role="grid"> | ||
|
||
<?php foreach ($shared_files_coach_staff as $shared_file) { | ||
render_documents($shared_file); | ||
} ?> | ||
<?php | ||
renderTable("Documents publics", $publicDocs); | ||
|
||
</tbody> | ||
</table> | ||
<?php endif ?> | ||
if ($adminDocs) | ||
renderTable("Documents privés", $adminDocs); | ||
?> | ||
|
||
<?php if (!count($shared_files_users) && (!$can_edit || !count($shared_files_coach_staff))): ?> | ||
<p class=center>Aucun document pour le moment 🫠</p> | ||
<?php endif ?> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters