*/
$displayStatusButtons = function($SELECTED_STATUS, $nbMateriels, $html) {
?>
';
echo "Afficher les matériels : ";
echo '';
echo '';
$b_all = $b_cre = $b_val = $b_toarc = $b_arc = '';
$SELECTED = '';
//if (isset($SELECTED_STATUS)) {
if ($SELECTED_STATUS) {
if ($SELECTED_STATUS == 'CREATED')
$b_cre = $SELECTED;
else if ($SELECTED_STATUS == 'VALIDATED')
$b_val = $SELECTED;
else if ($SELECTED_STATUS == 'TOBEARCHIVED')
$b_toarc = $SELECTED;
else if ($SELECTED_STATUS == 'ARCHIVED')
$b_arc = $SELECTED;
} else $b_all = $SELECTED;
// Affichage des boutons en haut de la page
//echo $this->Html->link($b_all . ' Tous', [
echo $html->link($b_all . ' Tous', [
'action' => 'index'
], [
'title' => 'Tous',
'style' => 'margin-right: 5px',
'escape' => false
]);
echo $html->link($b_cre . ' A valider', [
'action' => 'index',
'CREATED'
], [
'title' => 'Liste des matériels créés',
'style' => 'margin-right: 5px',
'escape' => false
]);
echo $html->link($b_val . ' Validés', [
'action' => 'index',
'VALIDATED'
], [
'title' => 'Liste des materiels que l\'on peut archiver',
'style' => 'margin-right: 5px',
'escape' => false
]);
echo $html->link($b_toarc . ' A sortir', [
'action' => 'index',
'TOBEARCHIVED'
], [
'title' => 'A sortir de l\'inventaire',
'style' => 'margin-right: 5px',
'escape' => false
]);
echo $html->link($b_arc . ' Archivés', [
'action' => 'index',
'ARCHIVED'
], [
'title' => 'A sortir de l\'inventaire',
'style' => 'margin-right: 0px',
'escape' => false
]);
echo '';
// ACTIONS : buttons "Tout selectionner", "Tout decocher"
// - show only with "A valider" and "A sortir"
if ($SELECTED_STATUS && $nbMateriels>0) {
echo $html->link(' Tout cocher', '#all', [
'onclick' => 'selectAll()',
'title' => 'Sélectionner tout les matériels',
'style' => ': 400px; margin-right: 50px',
'escape' => false
]);
echo $html->link(' Tout décocher', '#none', [
'onclick' => 'selectNone()',
'title' => 'Sélectionner aucun matériel',
'style' => 'margin-right: 50px',
'escape' => false
]);
}
echo "
";
}; // displayStatusButtons()
$displayNbLinesSelector = function($form, $request) {
echo '';
//echo $this->Form->create('materiels', [
echo $form->create('materiels', [
//'url' => '/materiels/execActions?page=' . $this->request->getQuery('page')
'url' => '/materiels/execActions?page=' . $request->getQuery('page')
]);
// echo $this->Form->create('materiels', ['url' => '/materiels/execActions?page=index']);
//echo $this->Form->control('aff_par_defaut', [
echo $form->control('aff_par_defaut', [
'label' => 'Afficher',
'options' => [
'20' => 20,
'30' => 30,
'50' => 50,
'100' => 100,
'150' => 150,
'200' => 200
]
]);
echo '
';
}; // displayNbLinesSelector()
$displayActionButtonsForSelectedOrAllElements = function($form, $SELECTED_STATUS, $USER_IS_RESPONSABLE, $USER_IS_ADMIN_OR_MORE, $USER_IS_SUPERADMIN) {
//if (isset($SELECTED_STATUS)) {
if ($SELECTED_STATUS) {
switch ($SELECTED_STATUS) {
case 'CREATED':
$action = 'Valider les';
break;
case 'VALIDATED':
$action = "Demander l'archivage des";
break;
case 'TOBEARCHIVED':
$action = "Sortir les";
break;
}
if ($SELECTED_STATUS != 'ARCHIVED') {
//if (! ($role == 'Super Administrateur' && $SELECTED_STATUS == 'TOBEARCHIVED')) {
if (! ($USER_IS_SUPERADMIN && $SELECTED_STATUS=='TOBEARCHIVED') ) {
//echo $this->Form->submit($action . ' matériels cochés', [
// 'name' => 'updateSelectedStatus',
// 'id' => 'updateSelectedStatus',
// 'style' => 'margin: 0px'
//]);
//echo $this->Form->button($action . ' matériels cochés', [ 'class'=>'btn btn-outline-success', 'type'=>'submit', 'name' => 'updateSelectedStatus', 'id' => 'updateSelectedStatus', 'style' => 'margin: 0px']);
echo $form->button($action . ' matériels cochés', [ 'class'=>'btn btn-outline-success', 'type'=>'submit', 'name' => 'updateSelectedStatus', 'id' => 'updateSelectedStatus', 'style' => 'margin: 0px']);
echo "
";
}
}
//echo $this->Form->submit('Exporter la liste des matériels cochés', [
// 'name' => 'export',
// 'id' => 'export',
// 'style' => 'margin: 0px;'
//]);
echo $form->button('Exporter la liste des matériels cochés', ['class'=>'btn btn-outline-success', 'type'=>'submit', 'name' => 'export', 'id' => 'export', 'style' => 'margin: 0px;' ]);
echo "
";
}
if ($USER_IS_ADMIN_OR_MORE || $USER_IS_RESPONSABLE)
//echo $this->Form->submit('Exporter la liste complete', [
// 'name' => 'exportAll',
// 'id' => 'exportAll',
// 'style' => 'margin: 0px;'
//]);
echo $form->button('Exporter la liste complete', ['class'=>'btn btn-outline-success', 'type'=>'submit', 'name' => 'exportAll', 'id' => 'exportAll', 'style' => 'margin: 0px;']);
};
/*
* Couleurs en fonction du statut du matos
*
*/
$displayColorLegend = function() {
// CREATED => bleu
// VALIDATED => vert
// TBA => orange
// ARCHIVED => rouge
echo "Couleur : bleu=créé ; vert=validé ; orange=à sortir ; rouge=archivé (couleur date rouge = fin garantie)
";
};
$displayActionButtonsForMateriel = function($materiel, $username, $USER_IS_RESPONSABLE, $USER_IS_ADMIN_OR_MORE, $USER_IS_SUPERADMIN, $controller, $html) {
// TODO: Dans l'idéal, ces variables doivent etre définies par le controleur et passées à la vue
// (sous forme d'un tableau contenant ces droits pour CHAQUE materiel)
// Car la vue doit être la moins "intelligente" possible, la plus simple possible
$IS_CREATED = ($materiel->status == 'CREATED');
$IS_VALIDATED = ($materiel->status == 'VALIDATED');
$IS_TOBEARCHIVED = ($materiel->status == 'TOBEARCHIVED');
$IS_ARCHIVED = ($materiel->status == 'ARCHIVED');
/*
* Couleurs en fonction du statut du matos
*
*/
// CREATED => bleu
if ($IS_CREATED) $color = 'blue';
// VALIDATED => vert
if ($IS_VALIDATED) $color = 'green';
// TBA => orange
if ($IS_TOBEARCHIVED) $color = 'orange';
// ARCHIVED => rouge
if ($IS_ARCHIVED) $color = 'red';
$color = "style='color: $color'";
$USER_IS_CREATOR_OR_OWNER = in_array($username, [$materiel->nom_createur, $materiel->nom_responsable]);
$USER_IS_SAME_GROUP_AS_MATERIEL = (
( isset($priviledgedUser->groupes_metier_id) && $priviledgedUser->groupes_metier_id!=$idGmNa && $materiel->groupes_metier_id==$priviledgedUser->groupes_metier_id )
||
( isset($priviledgedUser->groupes_thematique_id) && $priviledgedUser->groupes_thematique_id!=$idGtNa && $materiel->groupes_thematique_id==$priviledgedUser->groupes_thematique_id )
);
$USER_IS_RESPONSABLE_AND_SAME_GROUP_AS_MATERIEL = $USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP_AS_MATERIEL;
$CONTEXT1 = $USER_IS_ADMIN_OR_MORE || $USER_IS_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP_AS_MATERIEL;
// Détermination des autorisations pour tous les boutons "éditer", "supprimer", "valider", ...
$id = $materiel->id;
$CAN_EDIT = $controller->isAuthorizedAction('edit', $id);
//$CAN_EDIT = $IS_CREATED && ($USER_IS_ADMIN_OR_MORE || $USER_IS_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP_AS_MATERIEL);
//$CAN_EDIT = $IS_CREATED && ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP_AS_MATERIEL || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER);
$CAN_DELETE = $controller->isAuthorizedAction('delete', $id);
//$CAN_DELETE = $CAN_EDIT;
/*
$CAN_VALIDATE_OR_INVALIDATE = $USER_IS_ADMIN_OR_MORE || ( ($materiel->materiel_administratif == 0) && $USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP_AS_MATERIEL );
$CAN_VALIDATE = $IS_CREATED && $CAN_VALIDATE_OR_INVALIDATE;
$CAN_INVALIDATE = !$IS_CREATED && $CAN_VALIDATE_OR_INVALIDATE;
$CAN_TBA = $IS_VALIDATED && ($USER_IS_ADMIN_OR_MORE || $USER_IS_CREATOR_OR_OWNER || ($USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP_AS_MATERIEL));
$CAN_ARCHIVE = $IS_TOBEARCHIVED && $CAN_VALIDATE_OR_INVALIDATE;
*/
$CAN_INVALIDATE = $controller->isAuthorizedAction('statusCreated', $id);
$CAN_VALIDATE = $controller->isAuthorizedAction('statusValidated', $id);
$CAN_TBA = $controller->isAuthorizedAction('statusTobearchived', $id);
$CAN_ARCHIVE = $controller->isAuthorizedAction('statusArchived', $id);
echo '';
// 1) EDIT icon
/*
if (
in_array($materiel->status, [
'CREATED',
// (EP 17/5/19) ben non, on peut pas si c'est validé !!!
//'VALIDATED'
])
&&
(
$USER_IS_ADMIN_OR_MORE
||
$USER_IS_CREATOR_OR_OWNER
||
($USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP_AS_MATERIEL)
)
)
*/
if ($CAN_EDIT) echo $html->link(__(''), ['action' => 'edit', $materiel->id], ['title' => 'Editer', 'style' => 'margin: 0 2px', 'escape' => false ]);
// 2) VALIDER/TBA/ARCHIVER icon
/*
if (
$USER_IS_ADMIN
||
($USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP_AS_MATERIEL)
) {
*/
//if ($materiel->status=='CREATED' && !$USER_IS_RESPONSABLE) {
if ($CAN_VALIDATE)
echo $html->link('', [
'action' => 'statusValidated',
$materiel->id
],
[
'title' => 'Valider',
'style' => 'margin: 0 2px',
'escape' => false,
'confirm' => 'Êtes-vous sur de vouloir valider ' . $materiel->designation . ' ?'
]
);
//else if (h($materiel->status) == 'VALIDATED') {
if ($CAN_TBA)
echo $html->link('', [
'action' => 'statusTobearchived',
$materiel->id
],
[
'title' => 'Demander la sortie de l\'inventaire',
'style' => 'margin: 0 2px',
'escape' => false,
'confirm' => 'Êtes-vous sur de vouloir faire une demande d\'archive ' . $materiel->designation . ' ?'
]
);
//else if ($materiel->status=='TOBEARCHIVED' && !$USER_IS_RESPONSABLE)
if ($CAN_ARCHIVE)
echo $html->link('', [
'action' => 'statusArchived',
$materiel->id
],
[
'title' => 'Sortir de l\'inventaire',
'style' => 'margin: 0 2px',
'escape' => false,
'confirm' => 'Êtes-vous sur de vouloir archiver ' . $materiel->designation . ' ?'
]
);
// 3) DELETE icon
/*
if (h($materiel->status) == 'CREATED') {
if (
$USER_IS_ADMIN_OR_MORE
||
$USER_IS_CREATOR_OR_OWNER
||
($USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP_AS_MATERIEL)
)
*/
if ($CAN_DELETE)
echo $html->link(__(''), [
'action' => 'delete',
$materiel->id
],
[
'title' => 'Supprimer',
'style' => 'margin: 0 2px',
'escape' => false,
'confirm' => __('Êtes-vous sur de vouloir supprimer {0} ?', $materiel->designation)
]
);
echo " | ";
return $color;
}; // displayActionButtonsForMateriel
?>
Liste des matériels ('.$nbMateriels.')'; ?>
';
echo $this->Html->link(' Nouveau Matériel', [
'action' => 'add'
], [
'title' => 'Ajouter un matériel',
'escape' => false
]);
echo '';*/
if ($USER_IS_ADMIN_OR_MORE) $displayStatusButtons($SELECTED_STATUS, $nbMateriels, $this->Html);
//
//
$displayNbLinesSelector($this->Form, $this->request);
//
if ($nbMateriels == 0)
echo 'Aucun matériel';
else {
// $form2 = $this->Form;
// /echo $this->Form->create('materiels', ['url' => '/materiels/execActions']);
if ($SELECTED_STATUS) echo $this->Form->hidden('what', [
'value' => $SELECTED_STATUS
]);
?>
'; }?>
= __('') ?> |
= $this->Paginator->sort('designation','Désignation') ?> |
= $this->Paginator->sort('numero_laboratoire', 'N° interne (labo)') ?> |
= $this->paginator->sort('hors_service', ' ') ?> |
= $this->Paginator->sort('categorie_id', 'Catégorie') ?> |
= $this->Paginator->sort('organisme_id', 'Org.') ?> |
= $this->Paginator->sort('numero_inventaire_organisme', 'N° Invent. Org.') ?> |
= $this->Paginator->sort('nom_responsable', 'Nom de l\'utilisateur') ?> |
= $this->Paginator->sort('status', 'Statut') ?> |
= $this->Paginator->sort('date_acquisition', 'Date Achat') ?> |
= "".$this->Paginator->sort('etiquette', 'Et')." | " ?>
".$this->Paginator->sort('metrologie', 'Metro')."" ?>
year-$time->month-$time->day"); // On extrait la date pour la vérification de fin de garantie
//$today = $today->format('Ydm'); // On formatte la date initialement en 31-12-2000 (par exemple) en un format qui pourra etre comparé : 20001231
$today = $today->format('Ymd'); // On formatte la date initialement en 31-12-2000 (par exemple) en un format qui pourra etre comparé : 20001231
// BOUCLE SUR CHAQUE MATERIEL, ligne par ligne
//$mc = new MaterielsController();
foreach ($materiels as $materiel) :
// Date fin garantie ?
$date_color = '';
if ($materiel->date_fin_garantie !== NULL) {
//debug("today $today");
$timeFin = new time($materiel->date_fin_garantie);
$dateFin = new date("$timeFin->year-$timeFin->month-$timeFin->day");
//$dateFin = $dateFin->format('Ydm');
$dateFin = $dateFin->format('Ymd');
//debug("datefin $dateFin");
if ($today>=$dateFin) $date_color = 'style="color: #FF0000"';
//debug("couleur $date_color");
}
?>
;">
// (1) COLONNE SELECTION (checkbox)
if ($SELECTED_STATUS) {
echo '' . $this->Form->checkbox($materiel->id, [
'style' => 'margin: 3px',
'id' => $materiel->id
]) . ' | ';
}
//
$color = $displayActionButtonsForMateriel($materiel, $username, $USER_IS_RESPONSABLE, $USER_IS_ADMIN_OR_MORE, $USER_IS_SUPERADMIN, $controller, $this->Html);
?>
= $materiel->has('designation') ? $this->Html->link($materiel->designation, ['controller' => 'Materiels', 'action' => 'view', $materiel->id],[$color]) : '' ?> |
= h($materiel->numero_laboratoire) ?> |
= ($materiel->hors_service) ? 'HS' : '' ?> |
= $materiel->has('category') ? h($materiel->category->nom) : '' ?> |
= $materiel->has('organisme') ? h($materiel->organisme->nom) : '' ?> |
= h($materiel->numero_inventaire_organisme) ?> |
= h($materiel->nom_responsable) ?> |
status)) {
case 'CREATED':
$statut = 'C';
break;
case 'VALIDATED':
$statut = 'V';
break;
case 'TOBEARCHIVED':
$statut = 'TBA';
break;
case 'ARCHIVED':
$statut = 'A';
break;
default:
$statut = '';
break;
}
?>
>= $statut ?> |
>= h($materiel->date_acquisition) ?> |
= h($materiel->etiquette)=='1' ? 'Y':'N' ?> |
'. (h($materiel->metrologie)=='1' ? 'Y':'N').'';
?>
Form, $SELECTED_STATUS, $USER_IS_RESPONSABLE, $USER_IS_ADMIN_OR_MORE, $USER_IS_SUPERADMIN);
echo $this->element('pagination_with_first_and_last');
$this->Form->end();
} // (nbMateriels>0)
?>