diff --git a/.idea/hesabixCore.iml b/.idea/hesabixCore.iml index 020c040..3d10d12 100644 --- a/.idea/hesabixCore.iml +++ b/.idea/hesabixCore.iml @@ -3,6 +3,7 @@ + diff --git a/hesabixArchive/140250100017055461-3-65620760609ee.jpg b/hesabixArchive/140250100017055461-3-65620760609ee.jpg new file mode 100644 index 0000000..d7a5d61 Binary files /dev/null and b/hesabixArchive/140250100017055461-3-65620760609ee.jpg differ diff --git a/hesabixArchive/Screenshot-from-2023-10-20-03-46-15-6562f36b96b78.png b/hesabixArchive/Screenshot-from-2023-10-20-03-46-15-6562f36b96b78.png new file mode 100644 index 0000000..cd7eea5 Binary files /dev/null and b/hesabixArchive/Screenshot-from-2023-10-20-03-46-15-6562f36b96b78.png differ diff --git a/hesabixArchive/Screenshot-from-2023-11-02-10-32-45-6562f39a1f474.png b/hesabixArchive/Screenshot-from-2023-11-02-10-32-45-6562f39a1f474.png new file mode 100644 index 0000000..ff24ab6 Binary files /dev/null and b/hesabixArchive/Screenshot-from-2023-11-02-10-32-45-6562f39a1f474.png differ diff --git a/hesabixArchive/Screenshot-from-2023-11-10-04-37-45-6562f3f481d22.png b/hesabixArchive/Screenshot-from-2023-11-10-04-37-45-6562f3f481d22.png new file mode 100644 index 0000000..d45e61d Binary files /dev/null and b/hesabixArchive/Screenshot-from-2023-11-10-04-37-45-6562f3f481d22.png differ diff --git a/hesabixCore/composer.json b/hesabixCore/composer.json index 02f9e90..5835c2b 100644 --- a/hesabixCore/composer.json +++ b/hesabixCore/composer.json @@ -51,7 +51,8 @@ "symfonycasts/verify-email-bundle": "^1.13", "tecnickcom/tcpdf": "^6.6", "twig/extra-bundle": "^2.12|^3.0", - "twig/twig": "^2.12|^3.0" + "twig/twig": "^2.12|^3.0", + "ext-fileinfo": "*" }, "config": { "allow-plugins": { diff --git a/hesabixCore/src/Controller/ArchiveController.php b/hesabixCore/src/Controller/ArchiveController.php index 7792956..72b2af6 100644 --- a/hesabixCore/src/Controller/ArchiveController.php +++ b/hesabixCore/src/Controller/ArchiveController.php @@ -14,6 +14,7 @@ use App\Service\twigFunctions; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\FileType; +use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\File\Exception\FileException; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -40,7 +41,8 @@ class ArchiveController extends AbstractController $usedSize += $file->getFileSize(); return [ 'size' => $totalSize * 1024, - 'remain'=>$usedSize + 'remain'=>($totalSize * 1024) - $usedSize, + 'used'=>$usedSize ]; } #[Route('/api/archive/info', name: 'app_archive_info')] @@ -268,9 +270,99 @@ class ArchiveController extends AbstractController $acc = $access->hasRole('archiveUpload'); if (!$acc) throw $this->createAccessDeniedException(); + foreach ($request->get('added_media') as $item){ + if (file_exists(__DIR__ . '/../../../hesabixArchive/temp/'.$item) ){ + $file = new ArchiveFile(); + $file->setBid($acc['bid']); + $file->setDateSubmit(time()); + $file->setSubmitter($this->getUser()); + $file->setPublic(false); + $file->setFilename($item); + $file->setDes($request->get('des')); + $file->setCat($request->get('cat')); + //set file type + $mimFile = mime_content_type(__DIR__ . '/../../../hesabixArchive/temp/'.$item); + $file->setFileType($mimFile); + $file->setFileSize(ceil(filesize(__DIR__ . '/../../../hesabixArchive/temp/'.$item)/(1024*1024))); + rename(__DIR__ . '/../../../hesabixArchive/temp/'.$item,__DIR__ . '/../../../hesabixArchive/'.$item); + $file->setRelatedDocType($request->get('doctype')); + $file->setRelatedDocCode($request->get('docid')); + + $entityManager->persist($file); + $entityManager->flush(); + } + + } return $this->json([ - 'ok'=>$request->get('doctype') + 'ok'=>'ok' ]); } + + #[Route('/api/archive/files/list', name: 'app_archive_file_list')] + public function app_archive_file_list(Jdate $jdate,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + { + $acc = $access->hasRole('archiveView'); + if(!$acc) + throw $this->createAccessDeniedException(); + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + $files = $entityManager->getRepository(ArchiveFile::class)->findBy([ + 'bid'=>$acc['bid'], + 'relatedDocType'=>$params['type'], + 'relatedDocCode'=>$params['id'] + ]); + echo $request->get('type'); + $resp = []; + foreach ($files as $file){ + $temp = []; + $temp['id']=$file->getId(); + $temp['filename']=$file->getFilename(); + $temp['fileType']=$file->getFileType(); + $temp['submitter']=$file->getSubmitter()->getFullName(); + $temp['dateSubmit']=$jdate->jdate('Y/n/d H:i',$file->getDateSubmit()); + $temp['filePublicls']=$file->isPublic(); + $temp['cat']=$file->getCat(); + $temp['filesize']=$file->getFileSize(); + $resp[] = $temp; + } + return $this->json($resp); + } + + #[Route('/api/archive/file/get/{id}', name: 'app_archive_file_get')] + public function app_archive_file_get(string $id,Jdate $jdate,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): BinaryFileResponse + { + $acc = $access->hasRole('archiveView'); + if(!$acc) + throw $this->createAccessDeniedException(); + $file = $entityManager->getRepository(ArchiveFile::class)->find($id); + if(! $file) + throw $this->createNotFoundException(); + if($acc['bid']->getId() != $file->getBid()->getId()) + throw $this->createAccessDeniedException(); + $fileAdr = __DIR__ . '/../../../hesabixArchive/'. $file->getFilename(); + $response = new BinaryFileResponse($fileAdr); + return $response; + + } + #[Route('/api/archive/file/remove/{id}', name: 'app_archive_file_remove')] + public function app_archive_file_remove(string $id,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('archiveDelete'); + if(!$acc) + throw $this->createAccessDeniedException(); + $file = $entityManager->getRepository(ArchiveFile::class)->find($id); + if(! $file) + throw $this->createNotFoundException(); + if($acc['bid']->getId() != $file->getBid()->getId()) + throw $this->createAccessDeniedException(); + $fileAdr = __DIR__ . '/../../../hesabixArchive/'. $file->getFilename(); + unlink($fileAdr); + $entityManager->remove($file); + $entityManager->flush(); + $log->insert('آرشیو','فایل با نام ' . $file->getFilename() . ' حذف شد.',$this->getUser(),$acc['bid']); + return $this->json(['result'=>1]); + } } diff --git a/hesabixCore/src/Controller/BusinessController.php b/hesabixCore/src/Controller/BusinessController.php index d4d35b3..c781103 100644 --- a/hesabixCore/src/Controller/BusinessController.php +++ b/hesabixCore/src/Controller/BusinessController.php @@ -389,6 +389,7 @@ class BusinessController extends AbstractController 'archiveUpload'=>true, 'archiveMod'=>true, 'archiveDelete'=>true, + 'archiveView'=>true, 'active'=> $perm->getUser()->isActive(), 'shareholder'=>true, ]; @@ -423,6 +424,7 @@ class BusinessController extends AbstractController 'archiveUpload'=>$perm->isArchiveUpload(), 'archiveMod'=>$perm->isArchiveMod(), 'archiveDelete'=>$perm->isArchiveDelete(), + 'archiveView'=>$perm->isArchiveView(), 'active'=> $perm->getUser()->isActive(), 'shareholder'=> $perm->isShareholder(), ]; @@ -485,6 +487,7 @@ class BusinessController extends AbstractController $perm->setArchiveMod($params['archiveMod']); $perm->setArchiveDelete($params['archiveDelete']); $perm->setArchiveUpload($params['archiveUpload']); + $perm->setArchiveView($params['archiveView']); $perm->setShareholder($params['shareholder']); $entityManager->persist($perm); $entityManager->flush(); diff --git a/hesabixCore/src/Entity/Permission.php b/hesabixCore/src/Entity/Permission.php index 8317115..4e4a94f 100644 --- a/hesabixCore/src/Entity/Permission.php +++ b/hesabixCore/src/Entity/Permission.php @@ -99,6 +99,9 @@ class Permission #[ORM\Column(nullable: true)] private ?bool $shareholder = null; + #[ORM\Column(nullable: true)] + private ?bool $archiveView = null; + public function getId(): ?int { return $this->id; @@ -439,4 +442,16 @@ class Permission return $this; } + + public function isArchiveView(): ?bool + { + return $this->archiveView; + } + + public function setArchiveView(?bool $archiveView): static + { + $this->archiveView = $archiveView; + + return $this; + } }