diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php
index 7b7f97f..e1e7ec7 100755
--- a/src/Controller/AppController.php
+++ b/src/Controller/AppController.php
@@ -32,6 +32,21 @@ use PhpParser\Node\Expr\Include_;
class AppController extends Controller {
public $confLabinvent;
+
+ const PROFILE_USER = 1;
+ const PROFILE_RESPONSABLE = 2;
+ const PROFILE_ADMIN = 3;
+ const PROFILE_ADMINPLUS = 4;
+ const PROFILE_SUPERADMIN = 5;
+
+ private $allProfiles = [
+ 'Utilisateur' => self::PROFILE_USER,
+ 'Responsable' => self::PROFILE_RESPONSABLE,
+ 'Administration' => self::PROFILE_ADMIN,
+ 'Administration Plus' => self::PROFILE_ADMINPLUS,
+ 'Super Administrateur' => self::PROFILE_SUPERADMIN
+ ];
+
/**
* Initialization hook method.
@@ -205,7 +220,15 @@ class AppController extends Controller {
* @return void
*/
public function beforeRender(Event $event) {
- if (! array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), [
+
+ $this->set('PROFILE_USER', self::PROFILE_USER);
+ $this->set('PROFILE_ADMIN', self::PROFILE_ADMIN);
+ $this->set('PROFILE_RESPONSABLE', self::PROFILE_RESPONSABLE);
+ $this->set('PROFILE_ADMINPLUS', self::PROFILE_ADMINPLUS);
+ $this->set('PROFILE_SUPERADMIN', self::PROFILE_SUPERADMIN);
+ $this->set('allProfiles', $this->allProfiles);
+
+ if (! array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), [
'application/json',
'application/xml'
])) {
@@ -227,6 +250,23 @@ class AppController extends Controller {
if ($role == null)
$role = 'Utilisateur';
$this->set('role', $role);
+
+ $profile = $this->allProfiles["$role"];
+ $this->set('profile', $profile);
+
+ $USER_IS_UTILISATEUR = ($profile == self::PROFILE_USER);
+ $USER_IS_RESPONSABLE = ($profile == self::PROFILE_RESPONSABLE);
+ $USER_IS_ADMIN = ($profile == self::PROFILE_ADMIN);
+ $USER_IS_ADMINPLUS = ($profile == self::PROFILE_ADMINPLUS);
+ $USER_IS_SUPERADMIN = ($profile == self::PROFILE_SUPERADMIN);
+ $USER_IS_ADMIN_OR_MORE = ($profile >= self::PROFILE_ADMIN);
+
+ $this->set('USER_IS_UTILISATEUR', $USER_IS_UTILISATEUR);
+ $this->set('USER_IS_RESPONSABLE', $USER_IS_RESPONSABLE);
+ $this->set('USER_IS_ADMIN', $USER_IS_ADMIN);
+ $this->set('USER_IS_ADMINPLUS', $USER_IS_ADMINPLUS);
+ $this->set('USER_IS_SUPERADMIN', $USER_IS_SUPERADMIN);
+ $this->set('USER_IS_ADMIN_OR_MORE', $USER_IS_ADMIN_OR_MORE);
$this->set('userConnected', $user);
diff --git a/src/Controller/MaterielsController.php b/src/Controller/MaterielsController.php
index e99f9d2..3687958 100755
--- a/src/Controller/MaterielsController.php
+++ b/src/Controller/MaterielsController.php
@@ -12,6 +12,18 @@ use Cake\Mailer\Email;
*/
class MaterielsController extends AppController {
+ const CREATED = 1;
+ const VALIDATED = 2;
+ const TOBEARCHIVED = 3;
+ const ARCHIVED = 4;
+
+ private $allStatus = [
+ 'CREATED' => self::CREATED,
+ 'VALIDATED' => self::VALIDATED,
+ 'TOBEARCHIVED' => self::TOBEARCHIVED,
+ 'ARCHIVED' => self::ARCHIVED,
+ ];
+
private $NOTARCHIVED = [
'CREATED',
'VALIDATED',
@@ -19,7 +31,22 @@ class MaterielsController extends AppController {
];
public $role;
-
+
+ /*
+ * EP added 13/6/17
+ * Set some useful global variables for all (Materiel) views
+ * Overload beforeRender()
+ */
+ public function beforeRender(\Cake\Event\Event $event){
+ parent::beforeRender($event);
+
+ //$this->layout = 'default';
+ $this->set('CREATED', self::CREATED);
+ $this->set('VALIDATED', self::VALIDATED);
+ $this->set('TOBEARCHIVED', self::TOBEARCHIVED);
+ $this->set('ARCHIVED', self::ARCHIVED);
+ }
+
/**
*
* @param $user Give
@@ -327,6 +354,7 @@ class MaterielsController extends AppController {
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null) {
+
$materiel = $this->Materiels->get($id, [
'contain' => [
'SurCategories',
@@ -342,7 +370,18 @@ class MaterielsController extends AppController {
'Fournisseurs'
]
]);
-
+
+ $IS_CREATED = ( $materiel->status == 'CREATED' );
+ $IS_VALIDATED = ( $materiel->status == 'VALIDATED' );
+ $IS_TOBEARCHIVED = ( $materiel->status == 'TOBEARCHIVED' );
+ $IS_ARCHIVED = ( $materiel->status == 'ARCHIVED' );
+ $status = $this->allStatus[$materiel->status];
+ $this->set('IS_CREATED', $IS_CREATED);
+ $this->set('IS_VALIDATED', $IS_VALIDATED);
+ $this->set('IS_TOBEARCHIVED', $IS_TOBEARCHIVED);
+ $this->set('IS_ARCHIVED', $IS_ARCHIVED);
+ $this->set('status', $status);
+
$sites = TableRegistry::get('Sites');
$typeSuivis = TableRegistry::get('TypeSuivis');
$typeDocuments = TableRegistry::get('TypeDocuments');
@@ -357,6 +396,7 @@ class MaterielsController extends AppController {
$this->set('typeSuivis', $typeSuivis);
$this->set('typeDocuments', $typeDocuments);
$this->set('fournisseurs', $fournisseurs);
+
$this->set('materiel', $materiel);
$this->set('_serialize', [
'materiel'
diff --git a/src/Template/Materiels/view.ctp b/src/Template/Materiels/view.ctp
index 2286a88..2f4dbf3 100755
--- a/src/Template/Materiels/view.ctp
+++ b/src/Template/Materiels/view.ctp
@@ -2,13 +2,80 @@
use Cake\I18n\Time;
use Cake\I18n\Date;
use Cake\ORM\TableRegistry;
+
+// EP
+// Set some useful global variables for this view
+
+// 1) Materiel settings
+/*
+const CREATED = 1;
+const VALIDATED = 2;
+const TOBEARCHIVED = 3;
+const ARCHIVED = 4;
+$allStatus = [
+ 'CREATED' => CREATED,
+ 'VALIDATED' => VALIDATED,
+ 'TOBEARCHIVED' => TOBEARCHIVED,
+ 'ARCHIVED' => ARCHIVED,
+];
+$IS_CREATED = ( $materiel->status == 'CREATED' );
+$IS_VALIDATED = ( $materiel->status == 'VALIDATED' );
+$IS_TOBEARCHIVED = ( $materiel->status == 'TOBEARCHIVED' );
+$IS_ARCHIVED = ( $materiel->status == 'ARCHIVED' );
+$status = $allStatus[$materiel->status];
+
+// 2) User settings
+const PROFILE_USER = 1;
+const PROFILE_RESPONSABLE = 2;
+const PROFILE_ADMIN = 3;
+const PROFILE_ADMINPLUS = 4;
+const PROFILE_SUPERADMIN = 5;
+$allProfiles = [
+ 'Utilisateur' => PROFILE_USER,
+ 'Responsable' => PROFILE_RESPONSABLE,
+ 'Administration' => PROFILE_ADMIN,
+ 'Administration Plus' => PROFILE_ADMINPLUS,
+ 'Super Administrateur' => PROFILE_SUPERADMIN
+];
+
+$profile = $allProfiles["$role"];
+echo $profile;
+
+$USER_IS_UTILISATEUR = ($profile == $PROFILE_USER);
+$USER_IS_RESPONSABLE = ($profile == $PROFILE_RESPONSABLE);
+$USER_IS_ADMIN = ($profile == $PROFILE_ADMIN);
+$USER_IS_ADMINPLUS = ($profile == $PROFILE_ADMINPLUS);
+$USER_IS_SUPERADMIN = ($profile == $PROFILE_SUPERADMIN);
+
+$USER_IS_ADMIN_OR_MORE = $profile >= $PROFILE_ADMIN;
+*/
+
+$USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER = $USER_IS_UTILISATEUR && in_array($username, [$materiel->nom_createur, $materiel->nom_responsable]);
+
+$USER_IS_RESPONSABLE_AND_SAME_GROUP =
+ $USER_IS_RESPONSABLE
+ &&
+ (
+ (
+ isset($userConnected->groupes_metier_id)
+ && $userConnected->groupes_metier_id != $idGmNa
+ && $materiel->groupes_metier_id == $userConnected->groupes_metier_id
+ )
+ ||
+ (
+ isset($userConnected->groupe_thematique_id)
+ && $userConnected->groupe_thematique_id != $idGtNa
+ && $materiel->groupes_thematique_id == $userConnected->groupe_thematique_id
+ )
+ );
?>
status) == 'ARCHIVED') echo ' ';
+ //if (h($materiel->status) == 'ARCHIVED') echo ' ';
+ if ($IS_ARCHIVED) echo ' ';
$panne = h($materiel->hors_service) ? ' (HORS SERVICE)' : '';
?>
=h($materiel->designation) . $panne?>
@@ -16,8 +83,9 @@ use Cake\ORM\TableRegistry;
=h($materiel->numero_laboratoire)?>
status) == 'ARCHIVED') echo ' (Archivé)';
- ?>
+ //if (h($materiel->status) == 'ARCHIVED') echo ' (Archivé)';
+ if ($IS_ARCHIVED) echo ' (Archivé)';
+ ?>
@@ -41,21 +109,26 @@ use Cake\ORM\TableRegistry;
+
+
+
status, ['CREATED','VALIDATED']) ) {
- if (
- in_array($role, ['Administration','Administration Plus','Super Administrateur'])
+ //if ( in_array($materiel->status, ['CREATED','VALIDATED']) ) {
+ if ( $IS_CREATED || $IS_VALIDATED ) {
+ if ( $USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP )
+ /*
+ //in_array($role, ['Administration','Administration Plus','Super Administrateur'])
||
(
- $role == 'Utilisateur'
- && in_array($username, [$materiel->nom_createur, $materiel->nom_responsable])
+ //$role == 'Utilisateur'
+ //&& in_array($username, [$materiel->nom_createur, $materiel->nom_responsable])
)
||
(
- $role == 'Responsable'
+ $role == 'Responsable'
&& (
(
isset($userConnected->groupes_metier_id)
@@ -70,7 +143,7 @@ use Cake\ORM\TableRegistry;
)
)
)
- )
+ */
echo $this->Html->link(
__(' Editer ce matériel'),
[ 'action' => 'edit', $materiel->id ],
@@ -80,7 +153,8 @@ use Cake\ORM\TableRegistry;
// TOBEARCHIVED+
else {
- if (in_array($role, ['Administration Plus','Super Administrateur'])) {
+ //if (in_array($role, ['Administration Plus','Super Administrateur'])) {
+ if ($USER_IS_ADMIN_OR_MORE) {
echo $this->Html->link(
__(' Editer ce matériel'),
['action' => 'edit', $materiel->id],
@@ -90,7 +164,8 @@ use Cake\ORM\TableRegistry;
}
// VALIDATED
- if ($materiel->status == 'VALIDATED') {
+ //if ($materiel->status == 'VALIDATED') {
+ if ($IS_VALIDATED) {
// BOUTON NOUVEAU SUIVI
echo $this->Html->link(
@@ -112,6 +187,8 @@ use Cake\ORM\TableRegistry;
}
// BOUTON "Lier un Doc"
+ if ( $USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP ) {
+ /*
if (
in_array($role, ['Administration','Administration Plus','Super Administrateur'])
||
@@ -136,6 +213,7 @@ use Cake\ORM\TableRegistry;
)
)
) {
+ */
echo $this->Html->link(' Lier un Doc.', [
'controller' => 'documents',
'action' => 'add',
@@ -178,10 +256,12 @@ use Cake\ORM\TableRegistry;
// Doc admission et sortie (admin+)
- if (in_array($role, ['Administration','Administration Plus','Super Administrateur'])) {
+ if ($USER_IS_ADMIN_OR_MORE) {
+ //if (in_array($role, ['Administration','Administration Plus','Super Administrateur'])) {
// Doc admission (admin only)
- if (($materiel->status == 'VALIDATED') || ($materiel->status == 'CREATED')) {
+ if ( $IS_CREATED || $IS_VALIDATED ) {
+ //if (($materiel->status == 'VALIDATED') || ($materiel->status == 'CREATED')) {
echo $this->Html->link(' Doc. admission', [
'controller' => 'documents',
'action' => 'admission',
@@ -194,7 +274,8 @@ use Cake\ORM\TableRegistry;
}
// Doc sortie (admin only)
- else if (($materiel->status == 'ARCHIVED') || ($materiel->status == 'TOBEARCHIVED')) {
+ else if ( $IS_ARCHIVED || $IS_TOBEARCHIVED ) {
+ //else if (($materiel->status == 'ARCHIVED') || ($materiel->status == 'TOBEARCHIVED')) {
echo $this->Html->link(' Doc. sortie', [
'controller' => 'documents',
'action' => 'sortie',
@@ -209,6 +290,8 @@ use Cake\ORM\TableRegistry;
// BOUTON changement statut
+ if ( $USER_IS_ADMIN_OR_MORE || $USER_IS_RESPONSABLE_AND_SAME_GROUP ) {
+ /*
if (
in_array($role, ['Administration','Administration Plus','Super Administrateur'])
|| (
@@ -228,9 +311,12 @@ use Cake\ORM\TableRegistry;
)
)
) {
+ */
// 2) Bouton de changement de statut : Valider, Demander archivage, ou Archiver
- switch ($materiel->status) {
- case "CREATED" :
+ //switch ($materiel->status) {
+ switch ($status) {
+ //case "CREATED" :
+ case $CREATED :
echo $this->Html->link(' Valider', [
'action' => 'statusValidated',
$materiel->id,
@@ -241,7 +327,7 @@ use Cake\ORM\TableRegistry;
'escape' => false
]);
break;
- case "VALIDATED" :
+ case $VALIDATED :
echo $this->Html->link(' Demander sortie', [
'action' => 'statusToBeArchived',
$materiel->id,
@@ -252,7 +338,7 @@ use Cake\ORM\TableRegistry;
'escape' => false
]);
break;
- case "TOBEARCHIVED" :
+ case $TOBEARCHIVED :
if ($role != 'Responsable' && $role != 'Super Administrateur') {
echo $this->Html->link(' Sortie inventaire', [
'action' => 'statusArchived',
@@ -430,8 +516,10 @@ use Cake\ORM\TableRegistry;
+
';
echo '';
echo ' Informations administratives';
@@ -451,6 +539,7 @@ use Cake\ORM\TableRegistry;
+
Suivi(s) du matériel (=count($materiel->suivis)?>)
@@ -471,6 +560,8 @@ use Cake\ORM\TableRegistry;
Html->link(__(''), ['controller' => 'Suivis','action' => 'edit',$suivis->id], ['escape' => false,'style' => 'margin:0']);
echo $this->Form->postLink(__(''), ['controller' => 'Suivis','action' => 'delete',$suivis->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $suivis->id)]);
}
@@ -518,6 +610,7 @@ use Cake\ORM\TableRegistry;
+
Emprunt(s) du matériel (=count($materiel->emprunts)?>)
@@ -534,19 +627,21 @@ use Cake\ORM\TableRegistry;
=__('Date de l\'emprunt')?> |
=__('Date de retour')?> |
|
- emprunts as $emprunts) :
+ emprunts as $emprunt) :
$type = 'Externe';
- $lieu = $emprunts['laboratoire'];
- if ($emprunts['emprunt_interne'] == 1) {
+ $lieu = $emprunt['laboratoire'];
+ if ($emprunt['emprunt_interne'] == 1) {
$type = 'Interne';
$lieu = $sites->find()->where([
- 'id =' => h($emprunts->site_id)
- ])->first()['nom'] . '-' . h($emprunts->e_lieu_detail);
+ 'id =' => h($emprunt->site_id)
+ ])->first()['nom'] . '-' . h($emprunt->e_lieu_detail);
}
?>
Html->link(__(''), ['controller' => 'Emprunts','action' => 'edit',$emprunts->id], ['escape' => false,'style' => 'margin:0']);
- echo $this->Form->postLink(__(''), ['controller' => 'Emprunts','action' => 'delete',$emprunts->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $emprunts->id)]);
+ */
+ echo $this->Html->link(__(''), ['controller' => 'Emprunts','action' => 'edit',$emprunt->id], ['escape' => false,'style' => 'margin:0']);
+ echo $this->Form->postLink(__(''), ['controller' => 'Emprunts','action' => 'delete',$emprunt->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $emprunt->id)]);
}
?>
|
- =$this->Html->link('Emprunt ' . $emprunts->id, ['controller' => 'emprunts','action' => 'view',$emprunts->id])?> |
- =h($emprunts->nom_emprunteur)?> |
+ =$this->Html->link('Emprunt ' . $emprunt->id, ['controller' => 'emprunts','action' => 'view',$emprunt->id])?> |
+ =h($emprunt->nom_emprunteur)?> |
=h($type)?> |
=h($lieu)?> |
- =h($emprunts->date_emprunt)?> |
- =h($emprunts->date_retour_emprunt)?> |
+ =h($emprunt->date_emprunt)?> |
+ =h($emprunt->date_retour_emprunt)?> |
@@ -594,6 +690,7 @@ use Cake\ORM\TableRegistry;
+
documents); ?>
@@ -631,6 +728,8 @@ use Cake\ORM\TableRegistry;
'escape' => false
]);
}
+ if ( $USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP ) {
+ /*
if (
in_array($role, ['Administration','Administration Plus','Super Administrateur'])
||
@@ -656,6 +755,7 @@ use Cake\ORM\TableRegistry;
)
)
) {
+ */
echo $this->Html->link(__(''), ['controller' => 'Documents','action' => 'edit',$documents->id], ['escape' => false,'style' => 'margin:0']);
echo $this->Form->postLink(__(''), ['controller' => 'Documents','action' => 'delete',$documents->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $documents->id)]);
}
@@ -666,7 +766,7 @@ use Cake\ORM\TableRegistry;
=$p?> |
--
libgit2 0.21.2