Qual: Uniformize permission code between viewimage.php and document.php