<?php
namespace Claromentis\Projects\Service;

$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"] ?: array()) + array("_73b0f28355cd627156a477c4fec19" . "ba3" => base64_decode("UHJvamVjdCBBZG1pbmlzdHJh" . "dG9y"), "_169c0f4a8ccce7f86e49bb8134" . "622037" => base64_decode("RGlzY3" . "Vzc2lv" . "bnM="), "_8dabb06" . "efc95df4" . "cff7c4af" . "e91857b5" . "3" => base64_decode("bmF" . "tZQ" . "=="), "_f2d41627f09270f0dbd" . "21d27e02868d7" => base64_decode("cmVzZX" . "Q="), "_3846809e0d6756ae55b70780e4cc" . "f3d6" => base64_decode("a2V" . "5"), "_cfdcfa36f9fa57f955a92" . "e7f041e06e3" => base64_decode("ZXh0" . "ZW5z" . "aW9u"), "_df934f3d" . "867cddf9e" . "8d4d8ed35" . "c7ade5" => base64_decode("L14oXGQrK" . "VxzLw=="), "_d155d43a39de93f858123c" . "6b6ce31d8a" => base64_decode("cHJlZ19tYXRja" . "A=="), "_8ab6ddf42088608c501fcded8" . "995e76c" => base64_decode("IA" . "=="), "_5e30c4717ced36cff9e9" . "3e19a5c576cc" => base64_decode("aXNfc3" . "RyaW5n"), "_31767d7" . "ad58e706" . "dbf47b7a" . "51a0fe6c" . "4" => base64_decode("Y291b" . "nQ="), "_bad6dfc21" . "09d66c91fc" . "231a44711c" . "072" => base64_decode("L" . "g" . "=" . "="), "_4d707fab93bebb00bbe69e8159697c" . "90" => base64_decode(""), "_6366a8a" . "3e681231" . "26045ee9" . "d37dafbe" . "e" => base64_decode("cmVmZXJlbmN" . "l"), "_7f628626dd1d55c71b1fc0" . "932ffd1d2c" => base64_decode("aXNfYX" . "JyYXk="), "_4938602dda9917904c6191e" . "386d4d4ac" => base64_decode("ZG1zX2ZvbGRlcl9" . "pZA=="), "_aa0553266235d1e7c4" . "3a6e8869464820" => base64_decode("REFUQV9" . "ESVI="), "_e5f5224fdfbd68" . "740d4476fe30995" . "02e" => base64_decode("RmFpbGVkIHRvIERlbGV0ZSBUYXNrcyBGaWxlcywgYXJnd" . "W1lbnQgbXVzdCBiZSBhbiBhcnJheSBvZiBUYXNrcyBvbm" . "x5"));
use Claromentis\Comments\Model\Attachment;
use Claromentis\Core\Acl\PermOClass;
use Claromentis\Core\CDN\CDNException;
use Claromentis\Core\CDN\CDNSystemException;
use Claromentis\Core\CDN\FileExistsException;
use Claromentis\Core\CDN\NotFoundException;
use Claromentis\Core\Repository\Exception\UnknownPropertyException;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Documents\Manipulator;
use Claromentis\Documents\Microsoft\DocsOneDriveDocumentLink;
use Claromentis\Projects\Model\Project;
use Claromentis\Projects\Model\Task;
use Claromentis\Projects\ProjectsRepository;
use Claromentis\Projects\Repository\ProjectRepository;
use Claromentis\Projects\Repository\TaskRepository;
use Claromentis\Projects\Exceptions\FolderException;
use Claromentis\Projects\Exceptions\ProjectFolderException;
use Claromentis\Projects\Exceptions\ProjectsFolderException;
use Claromentis\Projects\Exceptions\TaskFolderException;
use Claromentis\Projects\Exceptions\TasksFolderException;
use Claromentis\Projects\Factories\DocumentsFactory;
use Claromentis\Projects\Factories\UnifiedPermissionsFactory;
use Claromentis\Projects\Repository\TeamRepository;
use DocsGoogleDocumentLink;
use ERMSBrowser;
use ERMSDataLink;
use ERMSDocument;
use ERMSFolder;
use ERMSMarker;
use InvalidArgumentException;
use NotificationManager;
use UnifiedPermissions;
use UserRole;
class FilesService
{
    const ADHOC_TASKS_FOLDER_NAME = 'AdHoc Tasks';
    const DISCUSSIONS_FOLDER_NAME = 'Discussions';
    const TASKS_FOLDER_NAME = 'Tasks';
    
    
    
    
    private $documents_factory;
    
    
    
    
    private $erms_browser;
    
    
    protected $project_repository;
    
    
    
    
    private $projects_repository;
    
    
    protected $task_repository;
    
    
    
    
    private $team_repository;
    
    
    
    
    private $unified_permissions_factory;
    public function __construct(ProjectRepository $_ebfb7629e898d0545f54221697853ab7, TaskRepository $_820fc78883234881f40fdd3e476961cc, TeamRepository $_a3fff46786fd3e38296d0325efc151ea, ProjectsRepository $_d23d6c1a259ee9fc229dbabdafae5a1b, ERMSBrowser $_cce6f43a19d507ba4f145abdabfaed33, DocumentsFactory $_8651d75398d306d77eb492255f230a9c, UnifiedPermissionsFactory $_3f8d85989e68a307f97ccb2fdc1a01ff)
    {
        $this->project_repository = $_ebfb7629e898d0545f54221697853ab7;
        $this->task_repository = $_820fc78883234881f40fdd3e476961cc;
        $this->team_repository = $_a3fff46786fd3e38296d0325efc151ea;
        $this->projects_repository = $_d23d6c1a259ee9fc229dbabdafae5a1b;
        $this->erms_browser = $_cce6f43a19d507ba4f145abdabfaed33;
        $this->documents_factory = $_8651d75398d306d77eb492255f230a9c;
        $this->unified_permissions_factory = $_3f8d85989e68a307f97ccb2fdc1a01ff;
    }
    
    
    
    
    
    
    
    
    
    public function GetFolder(int $_0ea4e32b57963ac0cb3057e03e9aef64) : ERMSFolder
    {
        $_a4b4fe29a876bd36f8024f56a625bf4c = $this->erms_browser->GetERMSFolder($_0ea4e32b57963ac0cb3057e03e9aef64, false);
        if (!$_a4b4fe29a876bd36f8024f56a625bf4c instanceof ERMSFolder) {
            throw FolderException::NotFound($_0ea4e32b57963ac0cb3057e03e9aef64);
        }
        return $_a4b4fe29a876bd36f8024f56a625bf4c;
    }
    
    
    
    
    
    
    
    
    public function GetProjectsRootFolder() : ERMSFolder
    {
        $_0ea4e32b57963ac0cb3057e03e9aef64 = $this->projects_repository->GetProjectsRootFolderId();
        try {
            return $this->GetFolder($_0ea4e32b57963ac0cb3057e03e9aef64);
        } catch (FolderException $_c35473364fa7a050299058f332ec29c1) {
            throw ProjectsFolderException::Missing($_0ea4e32b57963ac0cb3057e03e9aef64, $_c35473364fa7a050299058f332ec29c1);
        }
    }
    
    
    
    
    
    
    
    
    
    public function GetProjectFolder(Project $project) : ERMSFolder
    {
        $_4eba7123fcddc4f01c504628a68f3142 = $project->GetFolderId();
        if (!isset($_4eba7123fcddc4f01c504628a68f3142) || (int) $_4eba7123fcddc4f01c504628a68f3142 === 0) {
            throw ProjectFolderException::Undefined();
        }
        try {
            return $this->GetFolder((int) $_4eba7123fcddc4f01c504628a68f3142);
        } catch (FolderException $_c35473364fa7a050299058f332ec29c1) {
            throw ProjectFolderException::Missing($_4eba7123fcddc4f01c504628a68f3142, $_c35473364fa7a050299058f332ec29c1);
        }
    }
    
    
    
    
    
    
    
    
    public function GetProjectTasksFolder(ERMSFolder $_3b4d198687ee5a112b0379b490d1564c) : ERMSFolder
    {
        $_98121e94e148d73a15700996ba4d7a53 = $_3b4d198687ee5a112b0379b490d1564c->GetChildren();
        if ($_98121e94e148d73a15700996ba4d7a53) {
            foreach ($_98121e94e148d73a15700996ba4d7a53 as $_1bd6e5a007d5639e67837f0567493081) {
                if ($_1bd6e5a007d5639e67837f0567493081->GetTitle() === self::TASKS_FOLDER_NAME) {
                    return $_1bd6e5a007d5639e67837f0567493081;
                }
            }
        }
        throw TasksFolderException::NotFound(self::TASKS_FOLDER_NAME);
    }
    
    
    
    
    
    
    
    
    
    public function GetTaskFolder(Task $_696b535739055ed7d827709916d07dea) : ERMSFolder
    {
        $_4eba7123fcddc4f01c504628a68f3142 = $_696b535739055ed7d827709916d07dea->GetFolderId();
        if (!isset($_4eba7123fcddc4f01c504628a68f3142) || (int) $_4eba7123fcddc4f01c504628a68f3142 === 0) {
            throw TaskFolderException::Undefined();
        }
        try {
            return $this->GetFolder((int) $_4eba7123fcddc4f01c504628a68f3142);
        } catch (FolderException $_c35473364fa7a050299058f332ec29c1) {
            throw TaskFolderException::Missing($_4eba7123fcddc4f01c504628a68f3142);
        }
    }
    
    
    
    
    
    
    
    public function HasRootFolder()
    {
        try {
            $this->projects_repository->GetProjectsRootFolderId();
            return true;
        } catch (ProjectsFolderException $_c35473364fa7a050299058f332ec29c1) {
            return false;
        }
    }
    protected function GetAdHocTaskFolder($task_id)
    {
        $_2913564fc864fd204e1f620e687ca704 = null;
        try {
            $_4e7db93b73495d62b6fe61a190365822 = $this->GetAdHocTasksFolder();
        } catch (ProjectsFolderException $_c35473364fa7a050299058f332ec29c1) {
            $_4e7db93b73495d62b6fe61a190365822 = null;
        }
        if ($_4e7db93b73495d62b6fe61a190365822 !== null) {
            $_98121e94e148d73a15700996ba4d7a53 = $_4e7db93b73495d62b6fe61a190365822->GetChildren();
            if ($_98121e94e148d73a15700996ba4d7a53) {
                foreach ($_98121e94e148d73a15700996ba4d7a53 as $_1bd6e5a007d5639e67837f0567493081) {
                    $_b4af1f7aa1ccde1a449e9d8afe15b753 = array();
                    $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_d155d43a39de93f858123c6b6c" . "e31d8a"]($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_df934f3d867c" . "ddf9e8d4d8ed3" . "5c7ade5"], $_1bd6e5a007d5639e67837f0567493081->GetTitle(), $_b4af1f7aa1ccde1a449e9d8afe15b753);
                    if ($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_31767d7ad58e706" . "dbf47b7a51a0fe6c" . "4"]($_b4af1f7aa1ccde1a449e9d8afe15b753) > 0 && $_b4af1f7aa1ccde1a449e9d8afe15b753[1] == $task_id) {
                        $_2913564fc864fd204e1f620e687ca704 = $_1bd6e5a007d5639e67837f0567493081;
                    }
                }
            }
        }
        return $_2913564fc864fd204e1f620e687ca704;
    }
    
    
    
    
    
    
    
    
    
    
    
    public function GetAdHocTasksFolder() : ERMSFolder
    {
        $_ebe668abbbd4b68ddb467d3a8f746102 = $this->GetProjectsRootFolder();
        $_ca6064645aefaa788e080e7699f1643b = $_ebe668abbbd4b68ddb467d3a8f746102->GetChildren();
        $_5fc89a822558fa65075e0e324f273530 = null;
        if ($_ca6064645aefaa788e080e7699f1643b) {
            foreach ($_ca6064645aefaa788e080e7699f1643b as $_1bd6e5a007d5639e67837f0567493081) {
                if ($_1bd6e5a007d5639e67837f0567493081->GetTitle() === self::ADHOC_TASKS_FOLDER_NAME) {
                    $_5fc89a822558fa65075e0e324f273530 = $_1bd6e5a007d5639e67837f0567493081;
                    break;
                }
            }
        }
        if (!isset($_5fc89a822558fa65075e0e324f273530)) {
            $_5fc89a822558fa65075e0e324f273530 = $this->CreateAdHocTasksFolder($_ebe668abbbd4b68ddb467d3a8f746102->GetId());
            $this->SaveFolder($_5fc89a822558fa65075e0e324f273530);
        }
        return $_5fc89a822558fa65075e0e324f273530;
    }
    
    
    
    
    
    
    
    public function BuildProjectFolderName(Project $project) : string
    {
        $_6366a8a3e68123126045ee9d37dafbee = $project->GetReference();
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_5e30c4717ced36cff9e93e19" . "a5c576cc"]($_6366a8a3e68123126045ee9d37dafbee) && $_6366a8a3e68123126045ee9d37dafbee !== $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_4d707fab93bebb00bbe69e8159" . "697c90"]) {
            $_6366a8a3e68123126045ee9d37dafbee .= $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_8ab6ddf42088608c501fcded" . "8995e76c"];
        } else {
            $_6366a8a3e68123126045ee9d37dafbee = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_4d707fab93bebb00bbe69e81596" . "97c90"];
        }
        $_8dabb06efc95df4cff7c4afe91857b53 = $project->GetName();
        if (!$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_5e30c4717ced3" . "6cff9e93e19a5c" . "576cc"]($_8dabb06efc95df4cff7c4afe91857b53)) {
            $_8dabb06efc95df4cff7c4afe91857b53 = $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_4d707fab93bebb00bbe69e" . "8159697c90"];
        }
        return $_6366a8a3e68123126045ee9d37dafbee . $_8dabb06efc95df4cff7c4afe91857b53;
    }
    
    
    
    
    
    
    
    public function CreateAdHocTasksFolder(int $_2aaf5ccdd61bef7dc6630d23ca5e88c2) : ERMSFolder
    {
        $_4159db079a5a9d85560551496e08b41c = $this->documents_factory->CreateFolder();
        $_4159db079a5a9d85560551496e08b41c->SetTitle(self::ADHOC_TASKS_FOLDER_NAME);
        $_4159db079a5a9d85560551496e08b41c->SetParentId($_2aaf5ccdd61bef7dc6630d23ca5e88c2);
        return $_4159db079a5a9d85560551496e08b41c;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function CreateAndSaveProjectFolders(Project $project) : ERMSFolder
    {
        $_b0218dcbc9116d3d1ce519aaefab12bd = $this->GetProjectsRootFolder();
        $_3b4d198687ee5a112b0379b490d1564c = $this->CreateProjectFolder($project, $_b0218dcbc9116d3d1ce519aaefab12bd->GetId());
        $this->SaveFolder($_3b4d198687ee5a112b0379b490d1564c);
        $_816fd77be9a7f0597a5ed26e6819d395 = (int) $_3b4d198687ee5a112b0379b490d1564c->GetId();
        
        
        $this->SaveFolder($this->CreateDiscussionsFolder($_816fd77be9a7f0597a5ed26e6819d395));
        
        
        $this->SaveFolder($this->CreateProjectTasksFolder($_816fd77be9a7f0597a5ed26e6819d395));
        $project->SetProperty($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_4938602dda9917904c6191" . "e386d4d4ac"], $_816fd77be9a7f0597a5ed26e6819d395);
        $this->project_repository->SaveProject($project);
        
        
        $this->project_repository->SetAllMemberPermissions((int) $project->GetId(), $_816fd77be9a7f0597a5ed26e6819d395, $this);
        return $_3b4d198687ee5a112b0379b490d1564c;
    }
    
    
    
    
    
    
    
    
    
    public function CreateProjectFolder(Project $project, int $_2aaf5ccdd61bef7dc6630d23ca5e88c2) : ERMSFolder
    {
        $_a4b4fe29a876bd36f8024f56a625bf4c = $this->documents_factory->CreateFolder();
        $_a4b4fe29a876bd36f8024f56a625bf4c->SetTitle($this->BuildProjectFolderName($project));
        $_a4b4fe29a876bd36f8024f56a625bf4c->SetParentId($_2aaf5ccdd61bef7dc6630d23ca5e88c2);
        $_a4b4fe29a876bd36f8024f56a625bf4c->SetPermissions($this->unified_permissions_factory->Create());
        return $_a4b4fe29a876bd36f8024f56a625bf4c;
    }
    
    
    
    
    
    
    
    
    
    public function CreateTaskFolder(Task $_696b535739055ed7d827709916d07dea, ?int $_6d959381825e4735e3ab7b798283e0d7) : ERMSFolder
    {
        $_a4b4fe29a876bd36f8024f56a625bf4c = $this->documents_factory->CreateFolder();
        $_a4b4fe29a876bd36f8024f56a625bf4c->SetTitle($_696b535739055ed7d827709916d07dea->GetTitle());
        if (isset($_6d959381825e4735e3ab7b798283e0d7)) {
            $_a4b4fe29a876bd36f8024f56a625bf4c->SetParentId($_6d959381825e4735e3ab7b798283e0d7);
        }
        return $_a4b4fe29a876bd36f8024f56a625bf4c;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function CreateAndSaveTaskFolder(Task $_696b535739055ed7d827709916d07dea, ?Project $project)
    {
        if (isset($project)) {
            try {
                $_3b4d198687ee5a112b0379b490d1564c = $this->GetProjectFolder($project);
            } catch (ProjectFolderException $_c35473364fa7a050299058f332ec29c1) {
                $_3b4d198687ee5a112b0379b490d1564c = $this->CreateAndSaveProjectFolders($project);
            }
            try {
                $_8ac4ddac671413fdb7a06217dc8f400b = $this->GetProjectTasksFolder($_3b4d198687ee5a112b0379b490d1564c);
            } catch (TasksFolderException $_c35473364fa7a050299058f332ec29c1) {
                $_8ac4ddac671413fdb7a06217dc8f400b = $this->CreateProjectTasksFolder((int) $_3b4d198687ee5a112b0379b490d1564c->GetId());
                $this->SaveFolder($_8ac4ddac671413fdb7a06217dc8f400b);
            }
        } else {
            
            
            $_8ac4ddac671413fdb7a06217dc8f400b = $this->GetAdHocTasksFolder();
        }
        
        
        $_2913564fc864fd204e1f620e687ca704 = $this->CreateTaskFolder($_696b535739055ed7d827709916d07dea, (int) $_8ac4ddac671413fdb7a06217dc8f400b->GetId());
        $this->SaveFolder($_2913564fc864fd204e1f620e687ca704);
        $_c4a7b58b933816b3a2ba62c400c9b3bb = (int) $_2913564fc864fd204e1f620e687ca704->GetId();
        
        
        $_021790cbafb2cb20dc2d4800734073ea = $this->CreateDiscussionsFolder($_c4a7b58b933816b3a2ba62c400c9b3bb);
        $this->SaveFolder($_021790cbafb2cb20dc2d4800734073ea);
        $_696b535739055ed7d827709916d07dea->SetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_4938602dda9917904c" . "6191e386d4d4ac"], $_c4a7b58b933816b3a2ba62c400c9b3bb);
        $_a08bd32d59ca8b97be8ee3dba712878d = SecurityContext::CreateForUser(0);
        $this->task_repository->SaveTask($_696b535739055ed7d827709916d07dea, $_a08bd32d59ca8b97be8ee3dba712878d);
        return $_2913564fc864fd204e1f620e687ca704;
    }
    
    
    
    
    
    
    
    public function RenameFolder(ERMSFolder $_a4b4fe29a876bd36f8024f56a625bf4c, string $_8dabb06efc95df4cff7c4afe91857b53) : void
    {
        $_a4b4fe29a876bd36f8024f56a625bf4c->SetTitle($_8dabb06efc95df4cff7c4afe91857b53);
    }
    public function GetFileCount(ERMSFolder $_a4b4fe29a876bd36f8024f56a625bf4c)
    {
        $_98121e94e148d73a15700996ba4d7a53 = $_a4b4fe29a876bd36f8024f56a625bf4c->GetDocs();
        return $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_31767d7ad58e706dbf47b7a51" . "a0fe6c4"]($_98121e94e148d73a15700996ba4d7a53);
    }
    
    
    
    
    
    
    public function GetProjectFileCount(Project $project) : int
    {
        try {
            return $this->GetFileCount($this->GetProjectFolder($project));
        } catch (ProjectFolderException $_c35473364fa7a050299058f332ec29c1) {
            return 0;
        }
    }
    
    
    
    
    
    
    
    public function GetTaskFileCount(int $task_id) : int
    {
        $_696b535739055ed7d827709916d07dea = $this->task_repository->LoadTask($task_id);
        if (!isset($_696b535739055ed7d827709916d07dea)) {
            return 0;
        }
        try {
            $_a4b4fe29a876bd36f8024f56a625bf4c = $this->GetTaskFolder($_696b535739055ed7d827709916d07dea);
        } catch (TaskFolderException $_c35473364fa7a050299058f332ec29c1) {
            return 0;
        }
        return $this->GetFileCount($_a4b4fe29a876bd36f8024f56a625bf4c);
    }
    
    
    
    
    
    
    
    
    
    
    public function CopyProjectFolders(Project $_7c0f893ab0c95907c78e38e1c354b301, Project $_ea389ff409b87715c72e4ecf57917ce5, $_78b95272d6851797ceeb935677ee9f22 = true)
    {
        
        
        if ($_7c0f893ab0c95907c78e38e1c354b301->GetId() == 0) {
            return;
        }
        try {
            $_3b4d198687ee5a112b0379b490d1564c = $this->GetProjectFolder($_7c0f893ab0c95907c78e38e1c354b301);
        } catch (ProjectFolderException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            return;
        }
        $_4159db079a5a9d85560551496e08b41c = new ERMSFolder();
        try {
            $_9c1b05a1853db64a6dec69a048c06a39 = $this->projects_repository->GetProjectsRootFolderId();
        } catch (ProjectsFolderException $_c35473364fa7a050299058f332ec29c1) {
            $_9c1b05a1853db64a6dec69a048c06a39 = false;
        }
        $_4159db079a5a9d85560551496e08b41c->SetParentId($_9c1b05a1853db64a6dec69a048c06a39);
        $_6366a8a3e68123126045ee9d37dafbee = $_ea389ff409b87715c72e4ecf57917ce5->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_6366a8a3e68123126045ee9d37d" . "afbee"]);
        if ($_6366a8a3e68123126045ee9d37dafbee !== null) {
            $_6366a8a3e68123126045ee9d37dafbee .= $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_8ab6ddf420886" . "08c501fcded899" . "5e76c"];
        }
        $_4159db079a5a9d85560551496e08b41c->SetTitle($_6366a8a3e68123126045ee9d37dafbee . $_ea389ff409b87715c72e4ecf57917ce5->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_8dabb06efc95df4cff7c4afe91" . "857b53"]));
        $this->SaveFolder($_4159db079a5a9d85560551496e08b41c);
        $_4159db079a5a9d85560551496e08b41c->OverridePermissions(new UnifiedPermissions());
        $this->SaveFolder($_4159db079a5a9d85560551496e08b41c);
        
        
        $this->CopyFoldersRecursive($_3b4d198687ee5a112b0379b490d1564c, $_4159db079a5a9d85560551496e08b41c, $_78b95272d6851797ceeb935677ee9f22);
        $_ea389ff409b87715c72e4ecf57917ce5->SetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_4938602dda9917904" . "c6191e386d4d4ac"], $_4159db079a5a9d85560551496e08b41c->GetId());
        $this->project_repository->SaveProject($_ea389ff409b87715c72e4ecf57917ce5);
    }
    protected function CopyFoldersRecursive(ERMSFolder $_d0845bff5cd0ddb5ed1d7bd9db996f51, ERMSFolder $_b0eff9162b2830bd7a38fc626c309d38, $_78b95272d6851797ceeb935677ee9f22 = true)
    {
        $_27970bcf34bff9a46e42e344791c884f = new Manipulator();
        $_98121e94e148d73a15700996ba4d7a53 = $_d0845bff5cd0ddb5ed1d7bd9db996f51->GetChildren();
        if ($_98121e94e148d73a15700996ba4d7a53) {
            foreach ($_98121e94e148d73a15700996ba4d7a53 as $_1bd6e5a007d5639e67837f0567493081) {
                $_9085ac15bd7a2bc4c194149cd8d18bc4 = $_1bd6e5a007d5639e67837f0567493081->Copy();
                $_9085ac15bd7a2bc4c194149cd8d18bc4->SetParentId($_b0eff9162b2830bd7a38fc626c309d38->id);
                $_9085ac15bd7a2bc4c194149cd8d18bc4->Save();
                $this->CopyFoldersRecursive($_1bd6e5a007d5639e67837f0567493081, $_9085ac15bd7a2bc4c194149cd8d18bc4, $_78b95272d6851797ceeb935677ee9f22);
            }
        }
        if ($_78b95272d6851797ceeb935677ee9f22) {
            $_8248f758e7baf777ae70aa7fe7eb48d0 = $_d0845bff5cd0ddb5ed1d7bd9db996f51->GetDocs();
            foreach ($_8248f758e7baf777ae70aa7fe7eb48d0 as $_09f61d3133f39f8e5aff0eb6a7d185a1) {
                $_27970bcf34bff9a46e42e344791c884f->Copy($_09f61d3133f39f8e5aff0eb6a7d185a1, $_b0eff9162b2830bd7a38fc626c309d38, true);
            }
        }
    }
    
    
    
    
    
    
    
    public function DeleteProjectFiles(Project $project) : void
    {
        try {
            $_3b4d198687ee5a112b0379b490d1564c = $this->GetProjectFolder($project);
            $_4eba7123fcddc4f01c504628a68f3142 = (int) $_3b4d198687ee5a112b0379b490d1564c->GetId();
        } catch (ProjectFolderException $_c35473364fa7a050299058f332ec29c1) {
            $_4eba7123fcddc4f01c504628a68f3142 = 0;
        }
        if ($_4eba7123fcddc4f01c504628a68f3142 > 0) {
            $_a4b4fe29a876bd36f8024f56a625bf4c = new ERMSFolder();
            $_a4b4fe29a876bd36f8024f56a625bf4c->Load($_4eba7123fcddc4f01c504628a68f3142);
            if ($_a4b4fe29a876bd36f8024f56a625bf4c->IsError()) {
                return;
            }
            $_27970bcf34bff9a46e42e344791c884f = new Manipulator();
            $_27970bcf34bff9a46e42e344791c884f->Delete($_a4b4fe29a876bd36f8024f56a625bf4c, false, true, true);
        }
    }
    
    
    
    
    
    
    
    
    public function DeleteTaskFiles($task_id) : void
    {
        $_696b535739055ed7d827709916d07dea = $this->task_repository->LoadTask($task_id);
        if (!isset($_696b535739055ed7d827709916d07dea)) {
            return;
        }
        try {
            $_a4b4fe29a876bd36f8024f56a625bf4c = $this->GetTaskFolder($_696b535739055ed7d827709916d07dea);
        } catch (TaskFolderException $_c35473364fa7a050299058f332ec29c1) {
            return;
        }
        $_27970bcf34bff9a46e42e344791c884f = new Manipulator();
        $_27970bcf34bff9a46e42e344791c884f->Delete($_a4b4fe29a876bd36f8024f56a625bf4c, false, true, true);
    }
    
    
    
    
    
    
    public function DeleteTasksFiles(array $_5a41aa961f592408a9a61999dd5e8716) : void
    {
        $_27970bcf34bff9a46e42e344791c884f = $this->documents_factory->CreateManipulator();
        foreach ($_5a41aa961f592408a9a61999dd5e8716 as $_696b535739055ed7d827709916d07dea) {
            if (!$_696b535739055ed7d827709916d07dea instanceof Task) {
                throw new InvalidArgumentException($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_e5f5224fdfbd6" . "8740d4476fe309" . "9502e"]);
            }
            try {
                $_27970bcf34bff9a46e42e344791c884f->Delete($this->GetTaskFolder($_696b535739055ed7d827709916d07dea), false, true, true);
            } catch (TaskFolderException $_c35473364fa7a050299058f332ec29c1) {
                continue;
            }
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    public function CopyCommentFileToProject(Attachment $_47eed1aeea2c92efe9af919c40d41358, Project $project)
    {
        try {
            $_3b4d198687ee5a112b0379b490d1564c = $this->GetProjectFolder($project);
            $_816fd77be9a7f0597a5ed26e6819d395 = $_3b4d198687ee5a112b0379b490d1564c->GetId();
        } catch (ProjectFolderException $_c35473364fa7a050299058f332ec29c1) {
            try {
                $_3b4d198687ee5a112b0379b490d1564c = $this->CreateAndSaveProjectFolders($project);
                $_816fd77be9a7f0597a5ed26e6819d395 = $_3b4d198687ee5a112b0379b490d1564c->GetId();
            } catch (ProjectsFolderException $_c35473364fa7a050299058f332ec29c1) {
                $_816fd77be9a7f0597a5ed26e6819d395 = null;
            }
        }
        $_3b4d198687ee5a112b0379b490d1564c = new ERMSFolder();
        $_3b4d198687ee5a112b0379b490d1564c->Load($_816fd77be9a7f0597a5ed26e6819d395);
        return $this->CopyCommentFileToObject($_3b4d198687ee5a112b0379b490d1564c, $_47eed1aeea2c92efe9af919c40d41358);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function CopyCommentFileToTask(Attachment $_47eed1aeea2c92efe9af919c40d41358, Task $_696b535739055ed7d827709916d07dea, ?Project $project = null)
    {
        try {
            $_2913564fc864fd204e1f620e687ca704 = $this->GetTaskFolder($_696b535739055ed7d827709916d07dea);
        } catch (TaskFolderException $_c35473364fa7a050299058f332ec29c1) {
            $_2913564fc864fd204e1f620e687ca704 = $this->CreateAndSaveTaskFolder($_696b535739055ed7d827709916d07dea, $project);
        }
        return $this->CopyCommentFileToObject($_2913564fc864fd204e1f620e687ca704, $_47eed1aeea2c92efe9af919c40d41358);
    }
    
    
    
    
    
    
    
    protected function CopyCommentFileToObject(ERMSFolder $_8a1f378bbb56eb0ed18573de899725cf, Attachment $_47eed1aeea2c92efe9af919c40d41358)
    {
        
        
        $_98121e94e148d73a15700996ba4d7a53 = $_8a1f378bbb56eb0ed18573de899725cf->GetChildren();
        $_4eba7123fcddc4f01c504628a68f3142 = 0;
        if ($_98121e94e148d73a15700996ba4d7a53) {
            foreach ($_98121e94e148d73a15700996ba4d7a53 as $_1bd6e5a007d5639e67837f0567493081) {
                if ($_1bd6e5a007d5639e67837f0567493081->GetTitle() === $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_169c0f4a8ccce7f86" . "e49bb8134622037"]) {
                    $_4eba7123fcddc4f01c504628a68f3142 = $_1bd6e5a007d5639e67837f0567493081->GetId();
                }
            }
        }
        if ($_4eba7123fcddc4f01c504628a68f3142 > 0) {
            $_a4b4fe29a876bd36f8024f56a625bf4c = new ERMSFolder();
            $_a4b4fe29a876bd36f8024f56a625bf4c->Load($_4eba7123fcddc4f01c504628a68f3142);
        } else {
            
            
            $_a4b4fe29a876bd36f8024f56a625bf4c = new ERMSFolder();
            $_a4b4fe29a876bd36f8024f56a625bf4c->SetTitle($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_169c0f4a8ccce7f86e49b" . "b8134622037"]);
            $_a4b4fe29a876bd36f8024f56a625bf4c->SetParentId($_8a1f378bbb56eb0ed18573de899725cf->GetId());
            $this->SaveFolder($_a4b4fe29a876bd36f8024f56a625bf4c);
        }
        global $g_application;
        $_9c87d4209007e97d1edc2a78ebf624a7 = $_47eed1aeea2c92efe9af919c40d41358->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_8dabb06efc" . "95df4cff7c4" . "afe91857b53"]) . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_bad6dfc2109d66c91fc231a447" . "11c072"] . $_47eed1aeea2c92efe9af919c40d41358->GetProperty($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_cfdcfa3" . "6f9fa57f" . "955a92e7" . "f041e06e" . "3"]);
        $_fc4ffcaec4dff19ed04cc1c9229222d1 = ERMSDocument::Create(DOC_TYPE_STANDARD);
        $_fc4ffcaec4dff19ed04cc1c9229222d1->AddComponentFile($g_application->config[$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_aa0553266235d1e" . "7c43a6e886946482" . "0"]] . $_47eed1aeea2c92efe9af919c40d41358->GetPath(), $_9c87d4209007e97d1edc2a78ebf624a7, true);
        $_fc4ffcaec4dff19ed04cc1c9229222d1->SetTitle($_9c87d4209007e97d1edc2a78ebf624a7);
        $_fc4ffcaec4dff19ed04cc1c9229222d1->SetParentId($_a4b4fe29a876bd36f8024f56a625bf4c->GetId());
        $_fc4ffcaec4dff19ed04cc1c9229222d1->Save();
        return $_fc4ffcaec4dff19ed04cc1c9229222d1;
    }
    public function RemoveAllPermissions($_4eba7123fcddc4f01c504628a68f3142)
    {
        $_a18f3f2e515f9b634cee4e5fbdcdb572 = new UnifiedPermissions();
        $_a4b4fe29a876bd36f8024f56a625bf4c = new ERMSFolder();
        $_a4b4fe29a876bd36f8024f56a625bf4c->Load($_4eba7123fcddc4f01c504628a68f3142);
        $_a4b4fe29a876bd36f8024f56a625bf4c->SetPermissions($_a18f3f2e515f9b634cee4e5fbdcdb572);
    }
    public function RemoveAccess($_4eba7123fcddc4f01c504628a68f3142, $user_id)
    {
        $_a4b4fe29a876bd36f8024f56a625bf4c = new ERMSFolder();
        $_a4b4fe29a876bd36f8024f56a625bf4c->Load($_4eba7123fcddc4f01c504628a68f3142);
        $_a18f3f2e515f9b634cee4e5fbdcdb572 = $_a4b4fe29a876bd36f8024f56a625bf4c->GetPermissions();
        $_a18f3f2e515f9b634cee4e5fbdcdb572->Delete(PERM_VIEW, PERM_OCLASS_INDIVIDUAL, $user_id);
        $_a18f3f2e515f9b634cee4e5fbdcdb572->Delete(PERM_EDIT, PERM_OCLASS_INDIVIDUAL, $user_id);
        $_a18f3f2e515f9b634cee4e5fbdcdb572->Delete(PERM_DELETE, PERM_OCLASS_INDIVIDUAL, $user_id);
        $_a18f3f2e515f9b634cee4e5fbdcdb572->Delete(PERM_EDIT_META, PERM_OCLASS_INDIVIDUAL, $user_id);
        $_a18f3f2e515f9b634cee4e5fbdcdb572->Delete(PERM_EDIT_PERMS, PERM_OCLASS_INDIVIDUAL, $user_id);
        $_a18f3f2e515f9b634cee4e5fbdcdb572->Delete(PERM_OCLASS_INDIVIDUAL, PERM_OCLASS_INDIVIDUAL, $user_id);
        $_a18f3f2e515f9b634cee4e5fbdcdb572->Save();
    }
    
    
    
    
    
    public function GiveFileFullAccess($_4eba7123fcddc4f01c504628a68f3142, $_a18f3f2e515f9b634cee4e5fbdcdb572 = null)
    {
        $_a4b4fe29a876bd36f8024f56a625bf4c = new ERMSFolder();
        $_a4b4fe29a876bd36f8024f56a625bf4c->Load($_4eba7123fcddc4f01c504628a68f3142);
        $_202d3ada7a176dfb421fe6345eb67ca2 = $_a4b4fe29a876bd36f8024f56a625bf4c->GetPermissions();
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_7f628626dd1d55c71b1fc" . "0932ffd1d2c"]($_a18f3f2e515f9b634cee4e5fbdcdb572)) {
            foreach ($_a18f3f2e515f9b634cee4e5fbdcdb572 as $_a1035579feba105330d0e352e2b3d045 => $_9cee5807b5bab08d25cd4213e63cb764) {
                foreach ($_9cee5807b5bab08d25cd4213e63cb764 as $_9d5fb54f90a9d5c1116490c4db3d5bc3 => $_18f48e103c59a05cbe75b66b44ec5728) {
                    $_202d3ada7a176dfb421fe6345eb67ca2->Add(PERM_VIEW | PERM_EDIT | PERM_DELETE | PERM_EDIT_META | PERM_EDIT_PERMS, $_a1035579feba105330d0e352e2b3d045, $_9d5fb54f90a9d5c1116490c4db3d5bc3);
                }
            }
        } else {
            $_4e303ab42c2cac5d623b05e12cbd852c = UserRole::GetRolesByNames($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_73b0f28355cd627156a477c4fec19b" . "a3"]);
            if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_31767d7ad5" . "8e706dbf47b" . "7a51a0fe6c4"]($_4e303ab42c2cac5d623b05e12cbd852c) > 0) {
                $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_f2d41627f09" . "270f0dbd21d2" . "7e02868d7"]($_4e303ab42c2cac5d623b05e12cbd852c);
                $_eeb125297bce9538c511611c5c48a026 = $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_3846809e" . "0d6756ae5" . "5b70780e4" . "ccf3d6"]($_4e303ab42c2cac5d623b05e12cbd852c);
                $_202d3ada7a176dfb421fe6345eb67ca2->Add(PERM_VIEW | PERM_EDIT | PERM_DELETE | PERM_EDIT_META | PERM_EDIT_PERMS, PermOClass::ROLE, $_eeb125297bce9538c511611c5c48a026);
            }
        }
        $_202d3ada7a176dfb421fe6345eb67ca2->Save();
    }
    public function GiveFileViewAccess($_4eba7123fcddc4f01c504628a68f3142, $_a18f3f2e515f9b634cee4e5fbdcdb572)
    {
        $_a4b4fe29a876bd36f8024f56a625bf4c = new ERMSFolder();
        $_a4b4fe29a876bd36f8024f56a625bf4c->Load($_4eba7123fcddc4f01c504628a68f3142);
        $_202d3ada7a176dfb421fe6345eb67ca2 = $_a4b4fe29a876bd36f8024f56a625bf4c->GetPermissions();
        foreach ($_a18f3f2e515f9b634cee4e5fbdcdb572 as $_a1035579feba105330d0e352e2b3d045 => $_9cee5807b5bab08d25cd4213e63cb764) {
            foreach ($_9cee5807b5bab08d25cd4213e63cb764 as $_9d5fb54f90a9d5c1116490c4db3d5bc3 => $_18f48e103c59a05cbe75b66b44ec5728) {
                $_202d3ada7a176dfb421fe6345eb67ca2->Add(PERM_VIEW, $_a1035579feba105330d0e352e2b3d045, $_9d5fb54f90a9d5c1116490c4db3d5bc3);
            }
        }
        $_202d3ada7a176dfb421fe6345eb67ca2->Save();
    }
    public function GiveFileEditAccess($_4eba7123fcddc4f01c504628a68f3142, $_a18f3f2e515f9b634cee4e5fbdcdb572)
    {
        $_a4b4fe29a876bd36f8024f56a625bf4c = new ERMSFolder();
        $_a4b4fe29a876bd36f8024f56a625bf4c->Load($_4eba7123fcddc4f01c504628a68f3142);
        $_202d3ada7a176dfb421fe6345eb67ca2 = $_a4b4fe29a876bd36f8024f56a625bf4c->GetPermissions();
        foreach ($_a18f3f2e515f9b634cee4e5fbdcdb572 as $_a1035579feba105330d0e352e2b3d045 => $_9cee5807b5bab08d25cd4213e63cb764) {
            foreach ($_9cee5807b5bab08d25cd4213e63cb764 as $_9d5fb54f90a9d5c1116490c4db3d5bc3 => $_18f48e103c59a05cbe75b66b44ec5728) {
                $_202d3ada7a176dfb421fe6345eb67ca2->Add(PERM_EDIT, $_a1035579feba105330d0e352e2b3d045, $_9d5fb54f90a9d5c1116490c4db3d5bc3);
            }
        }
        $_202d3ada7a176dfb421fe6345eb67ca2->Save();
    }
    
    
    
    
    public function SendNotifications()
    {
        NotificationManager::GetInstance()->SendNotifications();
    }
    
    
    
    
    
    
    public function SaveFolder(ERMSFolder $_a4b4fe29a876bd36f8024f56a625bf4c) : void
    {
        $_a4b4fe29a876bd36f8024f56a625bf4c->Save();
    }
    
    
    
    
    
    
    
    private function CreateDiscussionsFolder(int $_6d959381825e4735e3ab7b798283e0d7) : ERMSFolder
    {
        $_912b0bf666a8af59c6e0ae1f8ae6b0d9 = $this->documents_factory->CreateFolder();
        $_912b0bf666a8af59c6e0ae1f8ae6b0d9->SetTitle(self::DISCUSSIONS_FOLDER_NAME);
        $_912b0bf666a8af59c6e0ae1f8ae6b0d9->SetParentId($_6d959381825e4735e3ab7b798283e0d7);
        return $_912b0bf666a8af59c6e0ae1f8ae6b0d9;
    }
    
    
    
    
    
    
    
    private function CreateProjectTasksFolder(int $_6d959381825e4735e3ab7b798283e0d7) : ERMSFolder
    {
        $_8ac4ddac671413fdb7a06217dc8f400b = $this->documents_factory->CreateFolder();
        $_8ac4ddac671413fdb7a06217dc8f400b->SetTitle(self::TASKS_FOLDER_NAME);
        $_8ac4ddac671413fdb7a06217dc8f400b->SetParentId($_6d959381825e4735e3ab7b798283e0d7);
        return $_8ac4ddac671413fdb7a06217dc8f400b;
    }
    
    
    
    
    
    
    
    
    
    public function IsFolderOwned(int $_4eba7123fcddc4f01c504628a68f3142) : bool
    {
        if (!$this->HasRootFolder()) {
            return false;
        }
        $_998feb498a09748ff0fed1130443f243 = $this->projects_repository->GetProjectsRootFolderId();
        if ($_4eba7123fcddc4f01c504628a68f3142 === $_998feb498a09748ff0fed1130443f243) {
            return true;
        }
        return $this->project_repository->GetProjectIdFromFolderId($_4eba7123fcddc4f01c504628a68f3142) !== null;
    }
}