index.ctp 10.4 KB
<div class="materiels index">
<?php echo '<h2><i class="icon-list"></i> Liste des matériels ('.$nbMateriels.')</h2>'; ?>

<div class="actions" style="width: 100%; float: none; padding: 0 0; ">
<?php 
echo '<p>';
echo $this->Html->link ( '<i class="icon-plus"></i> Nouveau Matériel',
		[
				'action' => 'add'
		], [
				'title' => 'Ajouter un matériel',
				'escape' => false
		]);
echo '</p>';

if(in_array($role, ['Administration', 'Administration Plus', 'Super Administrateur'])) {
echo '<p>';
echo "Afficher les matériels : ";
echo '</br>';
echo '</br>';
$b_all = $b_cre = $b_val = $b_toarc = $b_arc = '';
$SELECTED = '<i class="icon-ok"></i>';
if (isset ( $STATUS )) {
	if ($STATUS == 'CREATED')
		$b_cre = $SELECTED;
		else if ($STATUS == 'VALIDATED')
			$b_val = $SELECTED;
			else if ($STATUS == 'TOBEARCHIVED')
				$b_toarc = $SELECTED;
				else if ($STATUS == 'ARCHIVED')
					$b_arc = $SELECTED;
} else
	$b_all = $SELECTED;

	// Affichage des boutons en haut de la page
	echo $this->Html->link ( $b_all . ' Tous', [
			'action' => 'index'
	], [
			'title' => 'Tous',
			'style' => 'margin-right: 5px',
			'escape' => false
	] );
	echo $this->Html->link ( $b_cre . ' A valider', [
			'action' => 'index',
			'CREATED'
	], [
			'title' => 'Liste des matériels créés',
			'style' => 'margin-right: 5px',
			'escape' => false
	] );
	echo $this->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 $this->Html->link ( $b_toarc . ' A sortir', [
			'action' => 'index',
			'TOBEARCHIVED'
	], [
			'title' => 'A sortir de l\'inventaire',
			'style' => 'margin-right: 5px',
			'escape' => false
	]);
	echo $this->Html->link ( $b_arc . ' Archivés', [
			'action' => 'index',
			'ARCHIVED'
	], [
			'title' => 'A sortir de l\'inventaire',
			'style' => 'margin-right: 5px',
			'escape' => false
	]);
	echo '</p>';

		// ACTIONS : buttons "Tout selectionner", "Tout decocher"
		// - show only with "A valider" and "A sortir"
		if (isset ( $STATUS ) && $nbMateriels != 0) {
			echo $this->Html->link ( '<i class="icon-check"></i> Tout cocher', '#all', [
					'onclick' => 'selectAll()',
					'title' => 'Sélectionner tous les matériels',
					'style' => ': 400px; margin-right: 50px',
					'escape' => false
			]);
			echo $this->Html->link ( '<i class="icon-check-empty"></i> Tout décocher', '#none', [
					'onclick' => 'selectNone()',
					'title' => 'Sélectionner aucun matériel',
					'style' => 'margin-right: 50px',
					'escape' => false
			]);
		}
	}
?>
</div>

<?php if ($nbMateriels != 0) { ?>

<?= $this->Form->create('materiels', ['url' => '/materiels/execActions']) ?>
	
	<?php if(isset($STATUS)) {
		echo $this->Form->hidden ( 'what', ['value' => $STATUS]);
	}
	?>
	
    <table cellpadding="0" cellspacing="0">
        <thead>
            <tr>
                <?php if (isset($STATUS)) { echo '<th></th>'; }?>
                <th><?= $this->Paginator->sort('designation','Désignation') ?></th>
                <th><?= $this->Paginator->sort('numero_laboratoire', 'N° interne (labo)') ?></th>
                <th><?= $this->Paginator->sort('categorie_id', 'Catégorie') ?></th>
                <th><?= $this->Paginator->sort('organisme_id', 'Org.') ?></th>
                <th><?= $this->Paginator->sort('numero_inventaire_organisme', 'N° Invent. Org.') ?></th>
                <th><?= $this->Paginator->sort('nom_responsable', 'Responsable') ?></th>
                <th><?= $this->Paginator->sort('status', 'Statut') ?></th>
                <th><?= $this->Paginator->sort('date_acquisition', 'Date Achat') ?></th>
                <th><?= $this->Paginator->sort('etiquette', 'Et') ?></th>
                <th class="actions"><?= __('') ?></th>
                <th class="actions"><?= __('') ?></th>
                <th class="actions"><?= __('') ?></th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($materiels as $materiel): ?>
            <tr>
            	<?php if (isset($STATUS)) {
            	 echo '<td class="smallText">'.$this->Form->checkbox($materiel->id, ['style' => 'margin: 3px','id' => $materiel->id]).'</td>' ;
 				}
 				?>
 				<td class="smallText"><?= $materiel->has('designation') ? $this->Html->link($materiel->designation, ['controller' => 'Materiels', 'action' => 'view', $materiel->id]) : '' ?></td>
                <td class="smallText"><?= h($materiel->numero_laboratoire) ?></td>
                <td class="smallText"><?= $materiel->has('category') ? h($materiel->category->nom) : '' ?></td>
                <td class="smallText"><?= $materiel->has('organisme') ? h($materiel->organisme->nom) : '' ?></td>
                <td class="smallText"><?= h($materiel->numero_inventaire_organisme) ?></td>
                <td class="smallText"><?= h($materiel->nom_responsable) ?></td>
                <?php 
                if (h($materiel->status) == 'CREATED') {
                	$statut = 'C';
                }
                if (h($materiel->status) == 'VALIDATED') {
                	$statut = 'V';
                }
                if (h($materiel->status) == 'TOBEARCHIVED') {
                	$statut = 'TBA';
                }
                if (h($materiel->status) == 'ARCHIVED') {
                	$statut = 'A';
                }
                ?>
                <td class="smallText"><?= $statut ?></td>
                <td class="smallText"><?= h($materiel->date_acquisition) ?></td>
                <td class="smallText"><?php if (h($materiel->etiquette) == '1') { echo 'Y'; } else { echo 'N'; } ?></td>

                <td class="actions" style="padding: 6px 0;">
                <?php if (in_array($materiel->status, ['CREATED', 'VALIDATED'])): 
                	  if(($role == 'Utilisateur' && (in_array($username, [$materiel->nom_createur, $materiel->nom_responsable]))) || (in_array($role, ['Responsable', 'Administration', 'Administration Plus', 'Super Administrateur']))) {
				?>
                    <?= $this->Html->link(__('<i class="icon-pencil"></i>'), ['action' => 'edit', $materiel->id], ['title' => 'Editer', 'style' => 'margin: 0 2px', 'escape' => false ]) ?>
                <?php } endif; ?>
                </td>
                
                <td class="actions" style="padding: 6px 0;">
                    <?php 
                    if(in_array($role, ['Responsable', 'Administration', 'Administration Plus', 'Super Administrateur'])) {
                    	
                    if(h($materiel->status) == 'CREATED') {
                    	echo $this->Html->link('<i class="icon-ok-sign"></i>',
                    			['action' => 'statusValidated', $materiel->id],
                    			['title' => 'Valider', 'style' => 'margin: 0 2px', 'escape' => false,
                    			'confirm' => 'Êtes-vous sur de vouloir validé '.$materiel->designation.' ?']);
                    } 
                    else if (h($materiel->status) == 'VALIDATED' && h($materiel->nom_responsable) == $username) {
                    	echo $this->Html->link('<i class="icon-inbox"></i>',
                    			['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 (h($materiel->status) == 'TOBEARCHIVED' && $role != 'Responsable'){
                    	echo $this->Html->link('<i class="icon-inbox"></i>',
                    			['action' => 'statusArchived', $materiel->id],
                    			['title' => 'Sortir de l\'inventaire', 'style' => 'margin: 0 2px', 'escape' => false,
                    			'confirm' => 'Êtes-vous sur de vouloir archivé '.$materiel->designation.' ?']);
                    }
                    
                    }
                   
                    ?>
                </td>
                <td class="actions" style="padding: 6px 0;">
                   <?php 
                   if (h($materiel->status) == 'CREATED') {
                   	if($role != 'Utilisateur' || in_array($username, [$materiel->nom_createur, $materiel->nom_responsable])) {
                   		echo $this->Html->link(__('<i class="icon-trash"></i>'), ['action' => 'delete', $materiel->id], ['title' => 'Supprimer', 'style' => 'margin: 0 2px', 'escape' => false, 'confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $materiel->designation)]);
                    }
                   }
                   ?>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    
    <?php 
		if (isset ( $STATUS )) {
			switch ($STATUS) {
				case 'CREATED' :
					$action = 'Valider les';
					break;
				case 'VALIDATED' :
					$action = "Demander l'archivage des";
					break;
				case 'TOBEARCHIVED' :
					$action = "Sortir les";
					break;
			}

			if ($STATUS != 'ARCHIVED') {
				echo $this->Form->submit ( $action . ' matériels cochés', [
							'name' => 'updateSelectedStatus',
							'id' => 'updateSelectedStatus',
							'style' => 'margin: 0px' 
				]);
				echo "<br /><br />" ;
			}
				echo $this->Form->submit ( 'Exporter la liste des matériels cochés', [
					'name' => 'export',
					'id' => 'export',
					'style' => 'margin: 0px;' 
				]);
			echo "<br /><br />" ;
		}
		
		
		if(in_array($role, ['Responsable', 'Administration', 'Administration Plus', 'Super Administrateur'])):
		echo $this->Form->submit('Exporter la liste complete (toutes les pages)', [
				'name' => 'exportAll',
				'id' => 'exportAll',
				'style' => 'margin: 0px;' 
		]);
		endif;
    ?>
		
    <div class="paging" style="color: black;">
      		<?= $this->Paginator->counter(['format' => 'Page {{page}} sur {{pages}}']) ?>
    		<?= $this->Paginator->first('<< ' . __(''), ['class' => 'prev']) ?>
            <?= $this->Paginator->prev('< ' . __(''), ['class' => 'prev disabled']) ?>
            <?= $this->Paginator->numbers(['separator' => '']) ?>
            <?= $this->Paginator->next(__('') . ' >', ['class' => 'next disabled']) ?>
            <?= $this->Paginator->last(__('') . ' >>', ['class' => 'next']) ?>
    </div>
    <?= $this->Form->end()?>
    <?php 
	} else { echo 'Aucun matériel'; }
    ?>
</div>


    	<div class="actions">
			<?php echo $this->element('menu') ?>
			<?php echo $this->element('menu_index', 
			[ 'pluralHumanName' => 'Matériels',
			'singularHumanName' => 'Matériel' ]) ?>
		</div>