Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Utilisation de vue pour la création d'employé (#827)
Browse files Browse the repository at this point in the history
* First touch

* w/ view

* Soldes

* Groupes

* typo edition

* Verrouillage correct

* Import from ldap

* formating

* formating 2

* patch de securité
  • Loading branch information
prytoegrian authored Aug 20, 2019
1 parent dfdbc17 commit 02930ef
Show file tree
Hide file tree
Showing 7 changed files with 526 additions and 148 deletions.
2 changes: 1 addition & 1 deletion App/Libraries/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public function getHowToConnectUser()

public function isUsersExportFromLdap()
{
return $this->getGroupeAuthentificationValeur('export_users_from_ldap');
return 'ldap' === $this->getHowToConnectUser() && $this->getGroupeAuthentificationValeur('export_users_from_ldap');
}

/**
Expand Down
157 changes: 17 additions & 140 deletions App/ProtoControllers/HautResponsable/Utilisateur.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,63 +465,29 @@ private static function postFormUtilisateur(array $post, array &$errors, &$notic
return $return;
}

if (!empty($post['_METHOD'])) {
switch ($post['_METHOD']) {
case 'DELETE':
$return = static::deleteUtilisateur($post['login'], $errors);
if ($return) {
$notice = "deleted";
log_action(0, '', $post['login'], 'utilisateur ' . $post['login'] . ' supprimé');
}
return $return;
case 'PUT':
if (!empty($_GET['login'])) {
$return = static::putUtilisateur($post, $errors);
}
if ($return) {
$notice = "modified";
log_action(0, '', $post['login'], 'utilisateur ' . $post['login'] . ' modifié');
}
return $return;
}
} else {
$return = static::insertUtilisateur($post, $errors);
switch ($post['_METHOD']) {
case 'DELETE':
$return = static::deleteUtilisateur($post['login'], $errors);
if ($return) {
$notice = "inserted";
log_action(0, '', $post['login'], 'utilisateur ' . $post['login'] . ' ajouté');
$notice = "deleted";
log_action(0, '', $post['login'], 'utilisateur ' . $post['login'] . ' supprimé');
}
return $return;
return $return;
case 'PUT':
if (!empty($_GET['login'])) {
$return = static::putUtilisateur($post, $errors);
}
if ($return) {
$notice = "modified";
log_action(0, '', $post['login'], 'utilisateur ' . $post['login'] . ' modifié');
}
return $return;
default:
throw new \LogicException('Unknown _METHOD');
}
}

/**
* Controle la conformité du formulaire de création
*
* @param array $data
* @param array $errors
* @param \includes\SQL $sql
* @param \App\Libraries\Configuration $config
*
* @return boolean
*/
private static function isFormInsertValide($data, &$errors, \includes\SQL $sql, \App\Libraries\Configuration $config)
{
$return = true;
$users = \App\ProtoControllers\Utilisateur::getListId(false);
if (in_array($data['login'], $users)) {
$errors[] = _('Cet identifiant existe déja.');
$return = false;
}

if ($config->getHowToConnectUser() == 'dbconges') {
if ($data['pwd1'] == '' || strcmp($data['pwd1'], $data['pwd2'])!=0 ) {
$errors[] = _('Saisie du mot de passe incorrect');
$return = false;
}
}

return $return && static::isFormValide($data, $errors, $sql, $config);
}

/**
* Controle la conformité du formulaire de mise à jour
Expand Down Expand Up @@ -704,95 +670,6 @@ public static function isDeletable($user, \includes\SQL $sql)
return 0 >= (int) $query->fetch_array()[0];
}

/**
* Création d'un nouvel utilisateur
*
* @param array $data
* @param array $errors
* @return boolean
*/
private static function insertUtilisateur($data, &$errors)
{
$sql = \includes\SQL::singleton();
$config = new \App\Libraries\Configuration($sql);
if (!static::isFormInsertValide($data, $errors, $sql, $config)) {
return false;
}

$sql->getPdoObj()->begin_transaction();
$insertInfos = static::insertInfosUtilisateur($data, $sql);
$insertSoldes = static::insertSoldeUtilisateur($data, $sql);
$insertGroupes = true;
if (!empty($data['groupesId'])) {
$insertGroupes = static::insertGroupesUtilisateur($data, $sql);
}
if ($insertInfos && $insertSoldes && $insertGroupes) {
return $sql->getPdoObj()->commit();
}

$sql->getPdoObj()->rollback();
return false;
}

private static function insertInfosUtilisateur($data, \includes\SQL $sql)
{
$req = "INSERT INTO conges_users SET
u_login='" . $data['login'] . "',
u_nom='" . $data['nom'] . "',
u_prenom='" . $data['prenom'] . "',
u_is_resp='" . $data['isResp'] . "',
u_is_admin='" . $data['isAdmin'] . "',
planning_id = 0,
u_is_hr='" . $data['isHR'] . "',
u_passwd='" . $data['pwd1'] . "',
u_quotite=" . $data['quotite'] . ",
u_email = '" . $data['email'] . "',
u_heure_solde=" . \App\Helpers\Formatter::hour2Time($data['soldeHeure']) . ",
date_inscription = '" . date('Y-m-d H:i') . "';";

return $sql->query($req);
}

private static function insertSoldeUtilisateur($data, \includes\SQL $sql)
{
$config = new \App\Libraries\Configuration($sql);
$typeAbsencesConges = \App\ProtoControllers\Conge::getTypesAbsences($sql, 'conges');

foreach ($typeAbsencesConges as $typeId => $info) {
$valuesStd[] = "('" . $data['login'] . "' ,"
. $typeId . ", "
. $data['joursAn'][$typeId] . ", "
. $data['soldes'][$typeId] . ", "
. $data['reliquats'][$typeId] . ")" ;
}
$req = "INSERT INTO conges_solde_user (su_login, su_abs_id, su_nb_an, su_solde, su_reliquat) VALUES " . implode(",", $valuesStd);
$returnStd = $sql->query($req);
$returnExc = 1;
if ($config->isCongesExceptionnelsActive()) {
$typeAbsencesExceptionnels = \App\ProtoControllers\Conge::getTypesAbsences($sql, 'conges_exceptionnels');
foreach ($typeAbsencesExceptionnels as $typeId => $info) {
$valuesExc[] = "('" . $data['login'] . "' ,"
. $typeId . ", 0, "
. $data['soldes'][$typeId] . ", 0)" ;

}
$req = "INSERT INTO conges_solde_user (su_login, su_abs_id, su_nb_an, su_solde, su_reliquat) VALUES " . implode(",", $valuesExc);
$returnExc = $sql->query($req);
}

return $returnStd && $returnExc;
}

private static function insertGroupesUtilisateur($data, \includes\SQL $sql)
{
foreach ($data['groupesId'] as $gid) {
$values[] = "(" . $gid . ", '" . $data['login'] . "')" ;
}
$req = "INSERT INTO conges_groupe_users (gu_gid, gu_login) VALUES " . implode(",", $values);

return $sql->query($req);
}

/**
* Mise à jour d'un utilisateur
*
Expand Down
1 change: 0 additions & 1 deletion App/Views/Groupe/Edition.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@
employes : {},
responsables : {},
responsablesGroupe : <?= json_encode($responsablesGroupe) ?>,

infosGroupe : <?= json_encode($infosGroupe) ?>,
dataForm : <?= json_encode($data) ?>,
axios : instance
Expand Down
165 changes: 165 additions & 0 deletions App/Views/HautResponsable/Employe/Ajout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php declare(strict_types = 1);
/**
* $message
* $soldeHeureId
* $readOnly
* $optLdap
* $formValue
* $config
* $typeAbsencesConges
* $typeAbsencesExceptionnels
* $groupes
*/
?>

<h1><?= _('Nouvel Utilisateur') ?></h1>
<?= $message ?>

<form id="manageUser" action="" method="post" accept-charset="UTF-8"
enctype="application/x-www-form-urlencoded" class="form-group">
<table class="table table-hover table-responsive table-striped table-condensed">
<thead>
<tr>
<th><?= _('Identifiant') ?></th>
<th><?= _('Nom') ?></th>
<th><?= _('Prénom') ?></th>
<th><?= _('Quotité') ?></th>
<?php if ($config->isHeuresAutorise()) : ?>
<th><?= _('solde d\'heure') ?></th>
<?php endif; ?>
<th><?= _('Responsable?') ?></th>
<th><?= _('Administrateur?') ?></th>
<th><?= _('Haut responsable?') ?></th>
<th><?= _('activé?') ?></th>
<?php if (!$config->isUsersExportFromLdap()) : ?>
<th><?= _('Email') ?></th>
<?php endif; ?>
<?php if ($config->getHowToConnectUser() == "dbconges") : ?>
<th><?= _('mot de passe') ?></th>
<th><?= _('ressaisir mot de passe') ?></th>
<?php endif ?>
</tr>
</thead>
<tbody>
<tr class="update-line">
<td><input class="form-control" type="text" name="new_login" size="10" maxlength="99" value="<?= $formValue['login'] ?>" <?= $readOnly ?> required></td>
<td>
<input class="form-control" type="text" id="new_nom" name="new_nom" size="10" maxlength="30" value="<?= $formValue['nom'] ?>" <?= $optLdap ?> required>
<ul class="suggestions" id="suggestions"></ul>
</td>
<td><input class="form-control" type="text" name="new_prenom" size="10" maxlength="30" value="<?= $formValue['prenom'] ?>" <?= $readOnly ?> required></td>
<td><input class="form-control" type="text" name="new_quotite" size="3" maxlength="3" value="<?= $formValue['quotite'] ?>" required></td>
<?php if ($config->isHeuresAutorise()) : ?>
<td>
<input class="form-control" type="text" name="new_solde_heure" id="<?= $soldeHeureId ?>" size="6" maxlength="6" value="<?= $formValue['soldeHeure'] ?>">
</td>
<?php endif; ?>
<td>
<select class="form-control" name="new_is_resp">
<option value="N" <?= 'N' === $formValue['isResp'] ? 'selected' : ''?>>N</option>
<option value="Y" <?= 'Y' === $formValue['isResp'] ? 'selected' : ''?>>Y</option>
</select>
</td>
<td>
<select class="form-control" name="new_is_admin">
<option value="N" <?= 'N' === $formValue['isAdmin'] ? 'selected' : ''?>>N</option>
<option value="Y" <?= 'Y' === $formValue['isAdmin'] ? 'selected' : ''?>>Y</option>
</select>
</td>
<td>
<select class="form-control" name="new_is_hr">
<option value="N" <?= 'N' === $formValue['isHR'] ? 'selected' : ''?>>N</option>
<option value="Y" <?= 'Y' === $formValue['isHR'] ? 'selected' : ''?>>Y</option>
</select>
</td>
<td>
<select class="form-control" name="new_is_active">
<option value="Y" <?= 'Y' === $formValue['isActive'] ? 'selected' : '' ?>>Y</option>
<option value="N" <?= 'N' === $formValue['isActive'] ? 'selected' : '' ?>>N</option>
</select>
</td>
<?php if (!$config->isUsersExportFromLdap()) : ?>
<td><input class="form-control" type="text" name="new_email" size="10" maxlength="99" value="<?= $formValue['email'] ?>"></td>
<?php endif ;?>
<?php if ("dbconges" === $config->getHowToConnectUser()) : ?>
<td><input class="form-control" type="password" name="new_password1" size="10" maxlength="15" value="" autocomplete="off"></td>
<td><input class="form-control" type="password" name="new_password2" size="10" maxlength="15" value="" autocomplete="off"></td>
<?php endif ;?>
</tr>
</tbody>
<script type="text/javascript">
generateTimePicker("<?= $soldeHeureId ?>");
</script>
</table>
<br><hr>

<table class="table table-hover table-responsive table-striped table-condensed">
<thead>
<tr>
<th colspan=3><h4><?= _('Soldes') ?> </h4></th>
</tr>
<tr>
<th></th>
<th><?= _('admin_new_users_nb_par_an') ?></th>
<th><?= _('divers_solde') ?></th>
<th><?= _('Reliquat') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($typeAbsencesConges as $typeId => $infoType) :?>
<tr>
<?php
$joursAn = $formValue['joursAn'][$typeId] ?? 0;
$solde = $formValue['soldes'][$typeId] ?? 0;
$reliquat = $formValue['reliquat'][$typeId] ?? 0;
?>
<td><?= $infoType['libelle'] ?></td>
<td><input class="form-control" type="text" name="tab_new_jours_an[<?= $typeId ?>]" size="5" maxlength="5" value="<?= $joursAn ?>"></td>
<td><input class="form-control" type="text" name="tab_new_solde[<?= $typeId ?>]" size="5" maxlength="5" value="<?= $solde ?>"></td>
<td><input class="form-control" type="text" name="tab_new_reliquat[<?= $typeId ?>]" size="5" maxlength="5" value="<?= $reliquat ?>"></td>
</tr>
<?php endforeach ;?>
<?php foreach ($typeAbsencesExceptionnels as $typeId => $infoType) : ?>
<tr>
<?php
$solde = $formValue['soldes'][$typeId] ?? 0;
?>
<td><?= $infoType['libelle'] ?></td>
<td><input type="hidden" name="tab_new_jours_an[<?= $typeId ?>]" size="5" maxlength="5" value="0"></td>
<td><input class="form-control" type="text" name="tab_new_solde[<?= $typeId ?>]" size="5" maxlength="5" value="<?= $solde ?>"></td>
<td><input type="hidden" name="tab_new_reliquat[<?= $typeId ?> ]" size="5" maxlength="5" value="0"></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<br>
<br><hr>
<table class="table table-hover table-responsive table-striped table-condensed">
<thead>
<tr>
<th colspan=3><h4><?= _('Groupes') ?></h4></th>
</tr>
<tr>
<th>&nbsp;</th>
<th>&nbsp;<?= _('Nom') ?></th>
<th>&nbsp;<?= _('Description') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($groupes as $groupeId => $groupeInfos) : ?>
<tr>
<td>
<?php
$checked = in_array($groupeId, $formValue['groupesId']) ? 'checked' : '';
?>
<input type="checkbox" name="checkbox_user_groups[<?= $groupeId ?>]" value="<?= $groupeId ?>" <?= $checked ?>>
</td>
<td>&nbsp;<?= $groupeInfos['g_groupename'] ?>&nbsp</td>
<td>&nbsp;<?= $groupeInfos['g_comment'] ?>&nbsp;</td>
</tr>
<?php endforeach ;?>
<tbody>
</table>
<hr>
<input class="btn btn-success" type="submit" value="<?= _('form_submit') ?>">
</form>
2 changes: 1 addition & 1 deletion edition/Fonctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ public static function editPDFModule()
// renvoit un tableau vide si pas de'edition pour le user
private static function recup_editions_user($login)
{
$tab_ed =a [];
$tab_ed = [];

$sql2 = "SELECT ep_id, ep_date, ep_num_for_user ";
$sql2=$sql2."FROM conges_edition_papier WHERE ep_login = '$login' ";
Expand Down
Loading

0 comments on commit 02930ef

Please sign in to comment.