Thanasoft-H2F/gestion/lib/Controller/ProviderController.php
Narindra ezway e6a18fd529 Add MailRepository and enhance calendar functionalities
- Introduced MailRepository for mailbox ID retrieval.
- Updated CalendarObjectCreatedListener to handle cookies.
- Modified VCalendarHelpers to include MIME type extraction.
- Enhanced TalkService with room token retrieval logic.
- Updated ProviderController to integrate external API for sharing.
- Refactored EmailBoxController to utilize MailRepository for mailbox ID.
2025-03-20 17:11:06 +03:00

269 lines
6.8 KiB
PHP

<?php
namespace OCA\Gestion\Controller;
use Exception;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\Mail\IMailer;
use OCP\IGroupManager;
defined("TAB1") or define("TAB1", "\t");
use OCP\IURLGenerator;
use OCA\Gestion\Db\Bdd;
use OC\Files\Filesystem;
use OCP\Files\IRootFolder;
use Psr\Log\LoggerInterface;
use OCP\AppFramework\Controller;
use OCA\Gestion\Service\GestionService;
use OCP\AppFramework\Http\DataResponse;
use OCA\Gestion\Service\NavigationService;
use OCP\AppFramework\Http\TemplateResponse;
use OCA\Gestion\Service\ConfigurationService;
use OCA\Gestion\Service\Provider\ProviderService;
use OCA\Gestion\Service\Provider\Statistic\ProviderStatisticService;
date_default_timezone_set('Europe/Paris');
class ProviderController extends Controller
{
private $idNextcloud;
private $urlGenerator;
private $mailer;
private $config;
/** @var IRootStorage */
private $storage;
private $user;
private $groups = [];
/** @var \OCA\Gestion\Service\NavigationService */
private $navigationService;
private $providerService;
private $providerStatisticService;
private $logger;
//Gestion service
private $gestionService;
/**
* Constructor
*/
public function __construct(
$AppName,
IRequest $request,
$UserId,
Bdd $myDb,
IRootFolder $rootFolder,
IURLGenerator $urlGenerator,
IMailer $mailer,
Iconfig $config,
IUserSession $userSession,
IGroupManager $groupManager,
NavigationService $navigationService,
ConfigurationService $configurationService,
LoggerInterface $logger,
ProviderService $providerService,
ProviderStatisticService $providerStatisticService,
GestionService $gestionService
) {
parent::__construct($AppName, $request);
$this->idNextcloud = $UserId;
$this->myDb = $myDb;
$this->urlGenerator = $urlGenerator;
$this->mailer = $mailer;
$this->config = $config;
$this->navigationService = $navigationService;
$this->configurationService = $configurationService;
$this->logger = $logger;
$this->providerService = $providerService;
$this->providerStatisticService = $providerStatisticService;
$this->gestionService = $gestionService;
if ($userSession->isLoggedIn()) {
$this->user = $userSession->getUser();
}
if ($this->user != null) {
$groups = $groupManager->getUserGroups($this->user);
$this->groups = [];
foreach ($groups as $group) {
$this->groups[] = $group->getGID();
}
}
try {
$this->storage = $rootFolder->getUserFolder($this->idNextcloud);
} catch (\OC\User\NoUserException $e) {
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function provider()
{
return new TemplateResponse('gestion', 'provider', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->navigationService->getNavigationLink()));
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
// public function getProviders()
// {
// $providers = $this->providerService->getProvidersAsArray();
// return json_encode($providers);
// }
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getProviders() {
// $providers = $this->providerService->getProvidersAsArray();
// http://127.0.0.1:8585/ocs/v2.php/apps/files_sharing/api/v1/shares
$client = \OC::$server->getHTTPClientService()->newClient();
$token = file_get_contents('http://127.0.0.1/ocs/v2.php/core/getcsrftoken', false, stream_context_create([
'http' => [
'header' => "OCS-APIRequest: true\r\n"
]
]));
$response = $client->post('http://127.0.0.1/ocs/v2.php/apps/files_sharing/api/v1/shares', [
//not verifier ssl
'body' => [
"path" => "//Talk/narindra-dev.png",
"referenceId" => "dkzcesdsdhae",
"shareWith" => "dkzcehae",
"shareType" => 10,
'talkMetaData' => "{\"messageType\":\"\"}"
],
'headers' => [
'Cookie' =>"_ga=GA1.1.259457270.1732194936; _ga_699NE13B0K=GS1.1.1732203040.2.0.1732203040.0.0.0; nc_sameSiteCookielax=true; nc_sameSiteCookiestrict=true; nc_username=Tiavina; oc_sessionPassphrase=v7ncJ0h%2BYxrmzJViNygGkErBa9cSDs1m3mpgW4M6wZ%2BqphceZK2S7PMELp%2BlHgxQxcZuGPrpzZSwzp2SQCXADxDehB7OkwdBEr3DtG8ZzlnXZWzB%2Fbfl7xsuQYTnvmLU; oczp8j7d6k88=1b54a2ea877ffca7154bea254f70886c; nc_token=OEez5vu%2FWTz7FsafIbVDbAXA7lSdkG9U; nc_session_id=1b54a2ea877ffca7154bea254f70886c",
'OCS-APIRequest' => 'true',
'requesttoken' => $token
]
]);
var_dump($response);die;
return json_encode($providers);
}
// json_encode([
// "path" => "//Talk/logo (2).png",
// "referenceId" => "90b2ef6f74ab9f5a5cb0f240d4552798780352ffd276717f54de9f4098e4ceab",
// "shareType" => 10,
// "shareWith" => "dkzcehae",
// "talkMetaData" => "{\"messageType\":\"\"}"
// ]));
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function createDefaultProvider()
{
try {
$this->providerService->createDefaultProvider($this->idNextcloud);
return true;
} catch (Exception $e) {
return null;
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function exportProvidersStatistic(array $providerIds, $year)
{
try {
$filenames = $this->providerStatisticService->exportProvidersStatisticByYear($providerIds, $year, $this->idNextcloud);
return $filenames;
} catch (Exception $e) {
return [];
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function moveAttachmentFile()
{
$tex = "BEGIN:VCALENDAR
PRODID:-//IDN nextcloud.com//Calendar app 4.7.16//EN
CALSCALE:GREGORIAN
VERSION:2.0
BEGIN:VEVENT
CREATED:20250319T070401Z
DTSTAMP:20250319T070538Z
LAST-MODIFIED:20250319T070538Z
SEQUENCE:2
UID:dc3ebd49-74c6-490a-afd2-2b61ef47c6f3
DTSTART;TZID=Africa/Nairobi:20250319T110001
DTEND;TZID=Africa/Nairobi:20250319T120001
STATUS:CONFIRMED
SUMMARY:test 5
LOCATION:2
DESCRIPTION:SOINS
TRANSP:TRANSPARENT
ATTACH;FMTTYPE=image/png;FILENAME=/sign.png;X-NC-FILE-ID=1426;X-NC-HAS-PREV
IEW=true:/f/1426
CLIENT:1
EMBALMER:
END:VEVENT
BEGIN:VTIMEZONE
TZID:Africa/Nairobi
BEGIN:STANDARD
TZOFFSETFROM:+0300
TZOFFSETTO:+0300
TZNAME:EAT
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE
END:VCALENDAR";
$this->gestionService->moveCalendarAttachmentFile($tex, '/f');
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function sendEmailAttachment()
{
$this->storage->getFullPath("/");
$attachments = [
['file_id' => 1518, 'name' => 'Capture.JPG']
];
$to = "jonathan.goulet@nextcloud.com";
$subject = "Piece jointe";
$body = "<p>Bonjour.</p> <p>Vous trouverez en pièce jointe les fichiers votre défunt.</p>";
$message = $this->mailer->createMessage();
$message->setSubject($subject);
$message->setTo(recipients: [$to]);
foreach ($attachments as $attachment) {
$path = Filesystem::getPath($attachment['file_id']);
$content = $this->mailer->createAttachment(Filesystem::file_get_contents($path), $attachment['name'], 'image/png');
$message->attach($content);
}
$message->setHtmlBody($body);
$this->mailer->send($message);
return true;
}
}