From b369b08452bf3342572ceb79b6424be7df0b2805 Mon Sep 17 00:00:00 2001
From: Damien Burel <damien.burel@maarch.org>
Date: Tue, 21 Feb 2017 10:56:23 +0100
Subject: [PATCH] FEAT #5232 Ajout de la base Rest pour slim framework

---
 core/class/class_portal.php                 |   2 +-
 modules/visa/Controllers/VisaController.php | 110 ++++++++++++++++++++
 2 files changed, 111 insertions(+), 1 deletion(-)
 create mode 100644 modules/visa/Controllers/VisaController.php

diff --git a/core/class/class_portal.php b/core/class/class_portal.php
index 585dfbc6daf..b5ba153bc82 100644
--- a/core/class/class_portal.php
+++ b/core/class/class_portal.php
@@ -62,7 +62,7 @@ class portal extends functions
             . DIRECTORY_SEPARATOR . 'maarch_entreprise'
             . DIRECTORY_SEPARATOR . 'tmp'. DIRECTORY_SEPARATOR;
         $_SESSION['config']['defaultpage'] = $corePath . 'index.php';
-        $_SESSION['config']['coreurl'] = Url::coreurl();
+        $_SESSION['config']['coreurl'] = str_replace('rest/', '', Url::coreurl());
         $i=0;
         foreach($xmlconfig->BUSINESSAPPS as $BUSINESSAPPS) {
             $_SESSION['businessapps'][$i] = array("appid" => (string) $BUSINESSAPPS->appid, "comment" => (string) $BUSINESSAPPS->comment);
diff --git a/modules/visa/Controllers/VisaController.php b/modules/visa/Controllers/VisaController.php
new file mode 100644
index 00000000000..a872530cfb6
--- /dev/null
+++ b/modules/visa/Controllers/VisaController.php
@@ -0,0 +1,110 @@
+<?php
+
+namespace Visa\Controllers;
+
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+
+require_once 'modules/basket/class/class_modules_tools.php';
+require_once 'apps/maarch_entreprise/Models/ResModel.php';
+
+
+class VisaController {
+
+	public function getSignatureBook(RequestInterface $request, ResponseInterface $response, $aArgs) {
+
+
+		$resId = $aArgs['resId'];
+
+		$basket = new \basket();
+		$actions = $basket->get_actions_from_current_basket($resId, 'letterbox_coll', 'PAGE_USE', false);
+
+		$actionsData = [];
+		$actionsData[] = ['value' => '', 'label' => _CHOOSE_ACTION];
+		foreach($actions as $value) {
+			$actionsData[] = ['value' => $value['VALUE'], 'label' => $value['LABEL']];
+		}
+
+		$attachments = \ResModel::getAvailableLinkedAttachmentsNotIn([
+			'resIdMaster' => $resId,
+			'notIn' 	  => ['incoming_mail_attachment'],
+			'select' 	  => ['res_id', 'res_id_version', 'title', 'identifier', 'attachment_type', 'status', 'typist', 'path', 'filename']
+		]);
+
+		foreach ($attachments as $key => $value) {
+			if ($value['attachment_type'] == 'converted_pdf') {
+				continue;
+			}
+
+			$collId = '';
+			$realId = 0;
+			if ($value['res_id'] == 0) {
+				$collId = 'version_attachments_coll';
+				$realId = $value['res_id_version'];
+			} elseif ($value['res_id_version'] == 0) {
+				$collId = 'attachments_coll';
+				$realId = $value['res_id'];
+			}
+
+			$viewerId = $realId;
+			$pathToFind = $value['path'] . str_replace(strrchr($value['filename'], '.'), '.pdf', $value['filename']);
+			foreach ($attachments as $tmpKey => $tmpValue) {
+				if ($tmpValue['attachment_type'] == 'converted_pdf' && ($tmpValue['path'] . $tmpValue['filename'] == $pathToFind)) {
+					$viewerId = $tmpValue['res_id'];
+					unset($attachments[$tmpKey]);
+				}
+			}
+
+			$attachments[$key]['thumbnailLink'] = "index.php?page=doc_thumb&module=thumbnails&res_id={$realId}&coll_id={$collId}&display=true&advanced=true";
+			$attachments[$key]['viewerLink'] = "index.php?display=true&module=visa&page=view_pdf_attachement&res_id_master={$resId}&id={$viewerId}";
+
+			unset($attachments[$key]['res_id']);
+			unset($attachments[$key]['res_id_version']);
+			unset($attachments[$key]['path']);
+			unset($attachments[$key]['filename']);
+		}
+
+
+		$incomingMail = \ResModel::get([
+			'resId' => $resId,
+			'select'    => ['subject']
+		]);
+
+		$incomingMailAttachments = \ResModel::getAvailableLinkedAttachmentsIn([
+			'resIdMaster' => $resId,
+			'in' 	      => ['incoming_mail_attachment'],
+			'select' 	  => ['res_id', 'title']
+		]);
+
+		$documents = [
+			[
+				'title'         => $incomingMail[0]['subject'],
+				'truncateTitle' => ((strlen($incomingMail[0]['subject']) > 10) ? (substr($incomingMail[0]['subject'], 0, 10) . '...') : $incomingMail[0]['subject']),
+				'viewerLink'    => "index.php?display=true&dir=indexing_searching&page=view_resource_controler&visu&id={$resId}&collid=letterbox_coll",
+				'thumbnailLink' => "index.php?page=doc_thumb&module=thumbnails&res_id={$resId}&coll_id=letterbox_coll&display=true&advanced=true"
+			]
+		];
+		foreach ($incomingMailAttachments as $value) {
+			$documents[] = [
+				'title'         => $value['title'],
+				'truncateTitle' => ((strlen($value['title']) > 10) ? (substr($value['title'], 0, 10) . '...') : $value['title']),
+				'viewerLink'    => "index.php?display=true&module=visa&page=view_pdf_attachement&res_id_master={$resId}&id={$value['res_id']}",
+				'thumbnailLink' => "index.php?page=doc_thumb&module=thumbnails&res_id={$value['res_id']}&coll_id=attachments_coll&display=true&advanced=true"
+			];
+		}
+
+
+		$datas = [];
+		$datas['actions'] = $actionsData;
+		$datas['attachments'] = $attachments;
+		$datas['documents'] = $documents;
+		$datas['rightSelectedThumbnail'] = 0;
+		$datas['leftSelectedThumbnail'] = 0;
+		$datas['rightViewerLink'] = $attachments[0]['viewerLink'];
+		$datas['leftViewerLink'] = $documents[0]['viewerLink'];
+		$datas['linkNotes'] = 'index.php?display=true&module=notes&page=notes&identifier=' .$resId. '&origin=document&coll_id=letterbox_coll&load&size=medium';
+		$datas['headerTab'] = 1;
+
+		return $response->withJson($datas);
+	}
+}
\ No newline at end of file
-- 
GitLab