<?php
namespace Modules\API\APIInterne\Document\Controller;

use Skeleton\Controller\Controller;
use Helpers\Fichier\Fichier;

class ChargeDocumentController extends Controller
{
    
    /**
     * init
     *
     * @return \GuzzleHttp\Psr7\Response|void
     */
    public function init()
    {
        if (!isset($_SESSION['Session_Login'])) {
            return  $this->redirectLocation($this->contenaire->get('base').'index.php?APIChargedocument=1&idDoc='.$this->request->getAttribute('idDoc').'&typeDoc='.$this->request->getAttribute('typeDoc'));
        }
    }
        
    /**
     * chargeDocumentAction
     *
     * @return string|false
     */
    public function chargeDocumentAction()
    {
        $idDocument = $this->request->getAttribute('idDoc');
        $typeDocument = $this->request->getAttribute('typeDoc');
        
        if ($typeDocument == 'facture') {
            $facture = new \Entity\Model\FactEnt($this->pdo);
            $facture = $facture->find($idDocument);

            $message = Fichier::UploadClient($_SESSION['url_pj'].$facture['FIC_LAD'], "Image_Facture_".$idDocument);
            return $message;
        }
        return false;
    }
}
