<?php

//classes loading begin
function classLoad($myClass)
{
    if (file_exists('../model/' . $myClass . '.php')) {
        include '../model/' . $myClass . '.php';
    } elseif (file_exists('../controller/' . $myClass . '.php')) {
        include '../controller/' . $myClass . '.php';
    }
}
spl_autoload_register("classLoad");
include '../config.php';
//classes loading end
session_start();
//post input processing
$idEmploye = $_POST['idEmploye'];
$idSalaire = $_POST['idSalaire'];
$salaireManager = new EmployeSocieteSalaireManager($pdo);
$salaireManager->delete($idSalaire);
$_SESSION['salaire-delete-success'] = "<strong>Opération valide : </strong>Salaire supprimé avec succès.";
header('Location:../employe-societe-profile.php?idEmploye=' . $idEmploye);
    }
}
spl_autoload_register("classLoad");
include 'config.php';
include 'lib/pagination.php';
//classes loading end
session_start();
if (isset($_SESSION['userMerlaTrav']) and $_SESSION['userMerlaTrav']->profil() == "admin") {
    //les sources
    $employeManager = new EmployeSocieteManager($pdo);
    $employe = "";
    $idEmploye = 0;
    if (isset($_GET['idEmploye']) and ($_GET['idEmploye'] > 0 and $_GET['idEmploye'] <= $employeManager->getLastId())) {
        $idEmploye = htmlentities($_GET['idEmploye']);
        $employe = $employeManager->getEmployesSocieteById($idEmploye);
        $salairesManager = new EmployeSocieteSalaireManager($pdo);
        $salaires = $salairesManager->getSalairesByIdEmploye($idEmploye);
        $congesManager = new EmployeSocieteCongeManager($pdo);
        $conges = $congesManager->getCongesByIdEmploye($idEmploye);
    }
    ?>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
	<meta charset="utf-8" />
	<title>ImmoERP - Management Application</title>
	<meta content="width=device-width, initial-scale=1.0" name="viewport" />
	<meta content="" name="description" />
{
    if (file_exists('../model/' . $myClass . '.php')) {
        include '../model/' . $myClass . '.php';
    } elseif (file_exists('../controller/' . $myClass . '.php')) {
        include '../controller/' . $myClass . '.php';
    }
}
spl_autoload_register("classLoad");
include '../config.php';
include '../lib/image-processing.php';
//classes loading end
session_start();
//post input processing
$idEmploye = htmlentities($_POST['idEmploye']);
if (!empty($_POST['salaire'])) {
    $idSalaire = htmlentities($_POST['idSalaire']);
    $salaire = htmlentities($_POST['salaire']);
    $prime = htmlentities($_POST['prime']);
    $dateOperation = htmlentities($_POST['dateOperation']);
    //create class
    $salaire = new EmployeSocieteSalaire(array('id' => $idSalaire, 'salaire' => $salaire, 'prime' => $prime, 'dateOperation' => $dateOperation));
    //create class manager
    $salaireManager = new EmployeSocieteSalaireManager($pdo);
    $salaireManager->update($salaire);
    $_SESSION['salaire-update-success'] = "<strong>Opération valide : </strong>Les infos du salaire sont modifiées avec succès.";
    header('Location:../employe-societe-profile.php?idEmploye=' . $idEmploye);
} else {
    $_SESSION['salaire-update-error'] = "<strong>Erreur Modification Salaire : </strong>Vous devez remplir au moins le champ 'Salaire'.";
    header('Location:../employe-societe-profile.php?idEmploye=' . $idEmploye);
    exit;
}
function classLoad($myClass)
{
    if (file_exists('../model/' . $myClass . '.php')) {
        include '../model/' . $myClass . '.php';
    } elseif (file_exists('../controller/' . $myClass . '.php')) {
        include '../controller/' . $myClass . '.php';
    }
}
spl_autoload_register("classLoad");
include '../config.php';
include '../lib/image-processing.php';
//classes loading end
session_start();
//post input processing
$idEmploye = htmlentities($_POST['idEmploye']);
if (!empty($_POST['salaire'])) {
    $salaire = htmlentities($_POST['salaire']);
    $prime = htmlentities($_POST['prime']);
    $dateOperation = htmlentities($_POST['dateOperation']);
    //create class
    $salaire = new EmployeSocieteSalaire(array('salaire' => $salaire, 'prime' => $prime, 'dateOperation' => $dateOperation, 'idEmploye' => $idEmploye));
    //create class manager
    $salaireManager = new EmployeSocieteSalaireManager($pdo);
    $salaireManager->add($salaire);
    $_SESSION['salaire-add-success'] = "<strong>Opération valide : </strong>Le salaire est ajouté avec succès.";
    header('Location:../employe-societe-profile.php?idEmploye=' . $idEmploye);
} else {
    $_SESSION['salaire-add-error'] = "<strong>Erreur Ajout Salaire : </strong>Vous devez remplir au moins le champ 'Salaire'.";
    header('Location:../employe-societe-profile.php?idEmploye=' . $idEmploye);
    exit;
}