213 lines
6.4 KiB
PHP
213 lines
6.4 KiB
PHP
<?php
|
|
require_once 'Framework/Controleur.php';
|
|
require_once 'Modele/Menuvueutilisateur.php';
|
|
require_once 'Modele/Police.php';
|
|
require_once 'Modele/Quittance.php';
|
|
require_once 'Modele/Ged.php';
|
|
|
|
class ControleurFichepolice extends Controleur {
|
|
private $police;
|
|
private $quittance;
|
|
private $etat;
|
|
private $ged;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->menuvue = new Menuvueutilisateur();
|
|
$this->menuvue->getMenuVue("Fichepolice");
|
|
|
|
$this->police = new Police();
|
|
$this->quittance = new Quittance();
|
|
$this->ged = new Ged();
|
|
|
|
$_SESSION['modeDevis'] = "0";
|
|
}
|
|
|
|
public function index($msgErreur=null)
|
|
{
|
|
$idPolice = $_SESSION['idPoliceAjax'];
|
|
|
|
$message = "";
|
|
|
|
$nouveau_fichier = "Rien";
|
|
|
|
// Extensions autorisees
|
|
$tabExt = array("avi", "bmp", "doc", "docx", "gif", "jpeg", "jpg", "jpe", "mkv", "mp3", "mp4", "pdf", "png", "pps", "xls", "xlsx", "wav");
|
|
|
|
// Mapping couleurs + icônes par type
|
|
$extStyles = [
|
|
"pdf" => ["color" => "danger", "icon" => "fas fa-file-pdf", "cat" => "Documents"],
|
|
"doc" => ["color" => "primary", "icon" => "fas fa-file-word", "cat" => "Documents"],
|
|
"docx" => ["color" => "primary", "icon" => "fas fa-file-word", "cat" => "Documents"],
|
|
"xls" => ["color" => "success", "icon" => "fas fa-file-excel", "cat" => "Documents"],
|
|
"xlsx" => ["color" => "success", "icon" => "fas fa-file-excel", "cat" => "Documents"],
|
|
"pps" => ["color" => "secondary","icon" => "fas fa-file-powerpoint","cat" => "Documents"],
|
|
|
|
"png" => ["color" => "info", "icon" => "fas fa-file-image", "cat" => "Images"],
|
|
"jpg" => ["color" => "info", "icon" => "fas fa-file-image", "cat" => "Images"],
|
|
"jpeg" => ["color" => "info", "icon" => "fas fa-file-image", "cat" => "Images"],
|
|
"jpe" => ["color" => "info", "icon" => "fas fa-file-image", "cat" => "Images"],
|
|
"gif" => ["color" => "warning", "icon" => "fas fa-file-image", "cat" => "Images"],
|
|
"bmp" => ["color" => "secondary","icon" => "fas fa-file-image", "cat" => "Images"],
|
|
|
|
"avi" => ["color" => "dark", "icon" => "fas fa-file-video", "cat" => "Vidéos"],
|
|
"mkv" => ["color" => "dark", "icon" => "fas fa-file-video", "cat" => "Vidéos"],
|
|
"mp4" => ["color" => "dark", "icon" => "fas fa-file-video", "cat" => "Vidéos"],
|
|
|
|
"mp3" => ["color" => "secondary","icon" => "fas fa-file-audio", "cat" => "Audio"],
|
|
"wav" => ["color" => "secondary","icon" => "fas fa-file-audio", "cat" => "Audio"],
|
|
];
|
|
|
|
if(!empty($_POST))
|
|
{
|
|
define('TARGET', $_SESSION['cheminGed']); // Repertoire cible
|
|
define('MAX_SIZE', 10000000); // Taille max en octets du fichier
|
|
|
|
// Variables
|
|
$extension = '';
|
|
|
|
if( !is_dir(TARGET) )
|
|
{
|
|
if( !mkdir(TARGET, 0755) )
|
|
{
|
|
$message = 'Erreur : le répertoire cible ne peut-être créé ! Vérifiez que vous diposiez des droits suffisants pour le faire ou créez le manuellement !';
|
|
}
|
|
}
|
|
|
|
// On verifie si le champ est rempli
|
|
if( !empty($_FILES['fichier_upload']['name']) )
|
|
{
|
|
// Recuperation de l'extension du fichier
|
|
|
|
$extension = pathinfo($_FILES['fichier_upload']['name'], PATHINFO_EXTENSION);
|
|
|
|
// On verifie l'extension du fichier
|
|
if(in_array(strtolower($extension), $tabExt))
|
|
{
|
|
$message = $_FILES['fichier_upload']['size'];
|
|
|
|
// On verifie les dimensions et taille du fichier
|
|
if($_FILES['fichier_upload']['size'] <= MAX_SIZE)
|
|
{
|
|
$taille = $_FILES['fichier_upload']['size'];
|
|
|
|
// Parcours du tableau d'erreurs
|
|
if(isset($_FILES['fichier_upload']['error']) && UPLOAD_ERR_OK === $_FILES['fichier_upload']['error'])
|
|
{
|
|
// On renomme le fichier
|
|
$nomOrigine = $_FILES['fichier_upload']['name'];
|
|
$nouveau_fichier = dateJourSql()."_".uniqid().".".$extension;
|
|
|
|
// Si c'est OK, on teste l'upload
|
|
if(move_uploaded_file($_FILES['fichier_upload']['tmp_name'], TARGET.$nouveau_fichier))
|
|
{
|
|
$message = 'Chargé avec succès / Uploaded successfully';
|
|
|
|
// on va envoyer dans la base de données
|
|
$this->ged->enregistrergedfichepolice($idPolice, $nomOrigine, $nouveau_fichier, $taille);
|
|
$this->rediriger("Fichepolice");
|
|
}
|
|
else
|
|
{
|
|
// Sinon on affiche une erreur systeme
|
|
$message = 'Problème lors du chargement !';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$message = 'Une erreur interne a empêché le chargement';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$message .= $_FILES['fichier_upload']['size']." Erreur dans les dimensions du fichier !";
|
|
// $message = 'Erreur dans les dimensions du fichier !';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Sinon on affiche une erreur pour l'extension
|
|
$message = 'Extension du fichier est incorrecte !';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Sinon on affiche une erreur pour le champ vide
|
|
$message = 'Veuillez sélectionner un fichier SVP! / Please select a file!';
|
|
}
|
|
|
|
// fin upload
|
|
}
|
|
|
|
$msgErreur = $message;
|
|
|
|
|
|
unset($_FILES['fichier_upload']);
|
|
|
|
|
|
$this->police->getContextePoliceId($idPolice);
|
|
|
|
$police = $this->police->getPoliceId($idPolice);
|
|
|
|
$totalquittance = $this->quittance->getTotalQuittance($idPolice);
|
|
|
|
$nb_non_facturees = $this->police->fn_primes_non_facturees_police($idPolice);
|
|
|
|
$geds = $this->ged->getgedfichepolice($idPolice);
|
|
|
|
$this->genererVue
|
|
(
|
|
array
|
|
(
|
|
'police' => $police,
|
|
'totalquittance' => $totalquittance,
|
|
'nb_non_facturees' => $nb_non_facturees,
|
|
'geds' => $geds,
|
|
'msgErreur' => $msgErreur,
|
|
'tabExt' => $tabExt,
|
|
'extStyles' => $extStyles
|
|
)
|
|
);
|
|
}
|
|
|
|
public function supprimer()
|
|
{
|
|
$id = $_SESSION['idPoliceAjax'];
|
|
|
|
if($this->police->supprimer($id))
|
|
{
|
|
$this->rediriger("Ficheclient");
|
|
}
|
|
else
|
|
{
|
|
$this->rediriger("Fichepolice");
|
|
}
|
|
}
|
|
|
|
public function imprimerquittance() {
|
|
$IdQuittance = $this->requete->getParametre("id");
|
|
require_once 'Societes/'.$_SESSION['codeSociete'].'/Etats/Etquittance.php';
|
|
$this->etat = new Etquittance();
|
|
$this->etat->imprimer($IdQuittance);
|
|
}
|
|
|
|
public function activergc()
|
|
{
|
|
$id = $_SESSION['idPoliceAjax'];
|
|
|
|
$this->police->activergc($id);
|
|
|
|
$this->rediriger("Gcpolices");
|
|
}
|
|
|
|
|
|
public function desactivergc()
|
|
{
|
|
$idPolice = $this->requete->getParametre("id");
|
|
|
|
$this->police->desactivergc($idPolice);
|
|
|
|
$this->rediriger("Gcpolices");
|
|
}
|
|
|
|
} |