229 lines
7.5 KiB
PHP
Executable File
229 lines
7.5 KiB
PHP
Executable File
<?php
|
||
// require_once 'Framework/Controleur.php';
|
||
require_once 'Framework/Controleurtraitementimage.php';
|
||
require_once 'Modele/Menuvueutilisateur.php';
|
||
require_once 'Modele/Beneficiaire.php';
|
||
require_once 'Modele/Police.php';
|
||
require_once 'Modele/Garantieadherent.php';
|
||
|
||
use Intervention\Image\ImageManager;
|
||
|
||
// class ControleurFichebeneficiaire extends Controleur
|
||
class ControleurReeditioncarte extends Controleurtraitementimage
|
||
{
|
||
private $menuvue;
|
||
private $beneficiaire;
|
||
private $police;
|
||
private $garantieadherent;
|
||
|
||
public function __construct() {
|
||
$this->menuvue = new Menuvueutilisateur();
|
||
$this->menuvue->getMenuVue('Reeditioncarte');
|
||
|
||
$this->beneficiaire = new Beneficiaire();
|
||
$this->police = new Police();
|
||
$this->garantieadherent = new Garantieadherent();
|
||
|
||
$_SESSION['modeDevis'] = "0";
|
||
}
|
||
|
||
public function index()
|
||
{
|
||
|
||
$codeSociete = $this->requete->getSession()->getAttribut('codeSociete');
|
||
$id = $this->requete->getParametre("id");
|
||
$idBeneficiaire = $id;
|
||
|
||
$this->beneficiaire->getContexteBeneficiaireId($id);
|
||
$idPolice = $_SESSION['idPolice_C'];
|
||
$this->police->getContextePoliceId($idPolice);
|
||
$this->beneficiaire->getContexteBeneficiaireId($idBeneficiaire);
|
||
|
||
$police = $this->police->getPoliceId($idPolice);
|
||
|
||
$nomGarant = $this->police->getNomGarant($police['codeGcAssureur']);
|
||
|
||
$_SESSION['nomGcAssureur_C'] = $nomGarant;
|
||
|
||
$idAdherent = $_SESSION['idAdherent_C'];
|
||
$numeroBeneficiaire = $_SESSION['numeroBeneficiaire_C'];
|
||
|
||
$garantieadherents = $this->garantieadherent->getGarantieBeneficiaire($idBeneficiaire);
|
||
|
||
$message = "";
|
||
$nouveau_fichier = "Rien";
|
||
|
||
|
||
if(!empty($_POST))
|
||
{
|
||
define('TARGET', $_SESSION['dossierSociete'].'/Photos/'); // Repertoire cible
|
||
define('MAX_SIZE', 100000); // Taille max en octets du fichier
|
||
define('WIDTH_MAX', 800); // Largeur max de l'image en pixels
|
||
define('HEIGHT_MAX', 800); // Hauteur max de l'image en pixels
|
||
|
||
$tabExt = array('jpg','png','jpeg'); // Extensions autorisees
|
||
$infosImg = array();
|
||
|
||
$extension = '';
|
||
$nomImage = '';
|
||
|
||
if( !is_dir(TARGET) )
|
||
{
|
||
if( !mkdir(TARGET, 0755) )
|
||
{
|
||
$message = 'Erreur : le r<>pertoire cible ne peut-<2D>tre cr<63><72> ! V<>rifiez que vous diposiez des droits suffisants pour le faire ou cr<63>ez le manuellement !';
|
||
}
|
||
}
|
||
|
||
|
||
//var_dump($_FILES);
|
||
//exit();
|
||
|
||
|
||
if( !empty($_FILES['fichier_image_a_uploader']['name']) )
|
||
{
|
||
if(!empty($_FILES['fichier_image_a_uploader']['tmp_name']))
|
||
{
|
||
$extension = pathinfo($_FILES['fichier_image_a_uploader']['name'], PATHINFO_EXTENSION);
|
||
|
||
if(in_array(strtolower($extension),$tabExt))
|
||
{
|
||
$infosImg = getimagesize($_FILES['fichier_image_a_uploader']['tmp_name']);
|
||
|
||
// On verifie le type de l'image
|
||
if($infosImg[2] >= 1 && $infosImg[2] <= 14)
|
||
{
|
||
// On verifie les dimensions et taille de l'image
|
||
if(($infosImg[0] <= WIDTH_MAX) && ($infosImg[1] <= HEIGHT_MAX) && (filesize($_FILES['fichier_image_a_uploader']['tmp_name']) <= MAX_SIZE))
|
||
{
|
||
// Parcours du tableau d'erreurs
|
||
if(isset($_FILES['fichier_image_a_uploader']['error'])
|
||
&& UPLOAD_ERR_OK === $_FILES['fichier_image_a_uploader']['error'])
|
||
{
|
||
// On renomme le fichier temporaire
|
||
//$rand = rand(1,1000000);
|
||
//$nomImageTemp = $_SESSION['numeroBeneficiaire_C']."_".$rand.'.'. $extension;
|
||
$nomImageTemp = $_SESSION['numeroBeneficiaire_C'].'.'.$extension;
|
||
|
||
|
||
// Si c'est OK, on teste l'upload
|
||
if(move_uploaded_file($_FILES['fichier_image_a_uploader']['tmp_name'], TARGET.$nomImageTemp))
|
||
{
|
||
// On va r<>duire la taille de l'image
|
||
// On renomme le fichier
|
||
//$rand = rand(1,1000000);
|
||
//$nomImage = $_SESSION['numeroBeneficiaire_C']."_".$rand.'.jpg';
|
||
$nomImage = $_SESSION['numeroBeneficiaire_C'].'.jpg';
|
||
|
||
$manager = new ImageManager(array('driver' => 'imagick'));
|
||
// $image = $manager->make(realpath(TARGET.$nomImageTemp))->resize(100, 100);
|
||
$image = $manager->make(realpath(TARGET.$nomImageTemp));
|
||
|
||
$width = $_SESSION['largeurPhoto'];
|
||
if($infosImg[0]<$width)
|
||
{
|
||
$width=$infosImg[0];
|
||
}
|
||
$image->resize($width, null, function ($constraint)
|
||
{
|
||
$constraint->aspectRatio();
|
||
});
|
||
$image->save(TARGET.$nomImage);
|
||
|
||
$nouveau_fichier = $nomImage;
|
||
$message = 'Chargement r<>ussi !';
|
||
$this->beneficiaire->changerPhoto($id, $nomImage);
|
||
$_SESSION['lienPhoto_C'] = $nomImage;
|
||
|
||
// $message = TARGET.$nomImageTemp;
|
||
unlink(TARGET.$nomImageTemp);
|
||
}
|
||
else
|
||
{
|
||
// Sinon on affiche une erreur systeme
|
||
$message = 'Probl<62>me lors du chargement !';
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$message = 'Une erreur interne a emp<6D>ch<63> le chargement';
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// Sinon erreur sur les dimensions et taille de l'image
|
||
$message = 'Erreur dans les dimensions du fichier !';
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// Sinon erreur sur le type de l'image
|
||
$message = 'Le fichier <20> charger n\'est pas une image !';
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// Sinon on affiche une erreur pour l'extension
|
||
$message = 'L\'extension du fichier est incorrecte !';
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// Sinon on affiche une erreur pour l'extension
|
||
$message = 'Revoir votre fichier image!';
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// Sinon on affiche une erreur pour le champ vide
|
||
$message = 'Veuillez s<>lectionner un fichier SVP !';
|
||
}
|
||
// fin upload
|
||
}
|
||
// dans tous les cas, on lance la page <Fichebeneficiaire> !!!
|
||
// On charge maintenant les infos du b<>neficiaire
|
||
|
||
$beneficiaire = $this->beneficiaire->getBeneficiaireId($id);
|
||
|
||
$_SESSION['idBeneficiaire_C'] = $id;
|
||
|
||
$police = $this->beneficiaire->getSituationPolice($idBeneficiaire);
|
||
|
||
$college = $this->beneficiaire->getSituationCollege($idBeneficiaire);
|
||
|
||
|
||
|
||
$_SESSION['dateEffetCouvert'] = $beneficiaire['dateEffetCouvert'];
|
||
|
||
|
||
$chemin = $this->menuvue->getChemin('Reeditioncarte');
|
||
|
||
$this->genererVue(array('beneficiaire' => $beneficiaire, 'message' => $message, 'nouveau_fichier' => $nouveau_fichier,
|
||
'garantieadherents' => $garantieadherents, 'police' => $police, 'college' => $college, 'chemin' => $chemin));
|
||
|
||
|
||
//$this->genererVue();
|
||
}
|
||
|
||
public function permutation() {
|
||
|
||
$numeroBeneficiaire = $this->requete->getParametre("numeroBeneficiaire_C");
|
||
|
||
$user = $_SESSION['login'];
|
||
|
||
$_SESSION['idBeneficiaire_C'] = $id;
|
||
|
||
$police = $this->beneficiaire->getSituationPolice($idBeneficiaire);
|
||
|
||
$college = $this->beneficiaire->getSituationCollege($idBeneficiaire);
|
||
|
||
$_SESSION['dateEffetCouvert'] = $beneficiaire['dateEffetCouvert'];
|
||
|
||
$nouveaunumerobeneficiaire = $this->beneficiaire->getnouveaunumerobeneficiaire($numeroBeneficiaire,$user);
|
||
|
||
//highlight_string("<?php\n\$datas =\n" . var_export($numeroBeneficiaire , true) . ";\n>");
|
||
//die();
|
||
$this->genererVue(array('beneficiaire' => $beneficiaire,'nouveaunumerobeneficiaire' => $nouveaunumerobeneficiaire, 'message' => $message, 'nouveau_fichier' => $nouveau_fichier,
|
||
'garantieadherents' => $garantieadherents, 'police' => $police, 'college' => $college));
|
||
}
|
||
} |