Commit 9e64b15e9bb42a7769dee709eb17e7e51a734aab
1 parent
5406e0d4
Exists in
master
and in
3 other branches
Resolution bug sendmail
Showing
4 changed files
with
679 additions
and
619 deletions
Show diff stats
src/Controller/AppController.php
... | ... | @@ -58,11 +58,9 @@ class AppController extends Controller { |
58 | 58 | 'action' => 'home' |
59 | 59 | ] |
60 | 60 | ]); |
61 | - $this->confLabinvent = TableRegistry::get('Configurations')->find() | |
62 | - ->where([ | |
61 | + $this->confLabinvent = TableRegistry::get('Configurations')->find()->where([ | |
63 | 62 | 'id =' => 1 |
64 | - ]) | |
65 | - ->first(); | |
63 | + ])->first(); | |
66 | 64 | } |
67 | 65 | |
68 | 66 | /** |
... | ... | @@ -73,11 +71,9 @@ class AppController extends Controller { |
73 | 71 | */ |
74 | 72 | public function isAuthorized($user) { |
75 | 73 | $configuration = $this->confLabinvent; |
76 | - $role = TableRegistry::get('Users')->find() | |
77 | - ->where([ | |
74 | + $role = TableRegistry::get('Users')->find()->where([ | |
78 | 75 | 'username' => $user[$configuration->authentificationType_ldap][0] |
79 | - ]) | |
80 | - ->first()['role']; | |
76 | + ])->first()['role']; | |
81 | 77 | |
82 | 78 | $action = $this->request->params['action']; |
83 | 79 | |
... | ... | @@ -104,28 +100,24 @@ class AppController extends Controller { |
104 | 100 | } |
105 | 101 | |
106 | 102 | function userHasRole($roleDefine) { |
107 | - $configuration = TableRegistry::get('Configurations')->find() | |
108 | - ->where([ | |
103 | + $configuration = TableRegistry::get('Configurations')->find()->where([ | |
109 | 104 | 'id =' => 1 |
110 | - ]) | |
111 | - ->first(); | |
112 | - $role = TableRegistry::get('Users')->find() | |
113 | - ->where([ | |
105 | + ])->first(); | |
106 | + $role = TableRegistry::get('Users')->find()->where([ | |
114 | 107 | 'username' => $this->LdapAuth->user($configuration->authentificationType_ldap)[0] |
115 | - ]) | |
116 | - ->first()['role']; | |
108 | + ])->first()['role']; | |
117 | 109 | |
118 | 110 | $isAuthorized = false; |
119 | 111 | |
120 | 112 | switch ($roleDefine) { |
121 | - case 'Super Administrateur': | |
113 | + case 'Super Administrateur' : | |
122 | 114 | if (in_array($role, [ |
123 | 115 | 'Super Administrateur' |
124 | 116 | ])) |
125 | 117 | $isAuthorized = true; |
126 | 118 | break; |
127 | 119 | |
128 | - case 'Administration Plus': | |
120 | + case 'Administration Plus' : | |
129 | 121 | if (in_array($role, [ |
130 | 122 | 'Administration Plus', |
131 | 123 | 'Super Administrateur' |
... | ... | @@ -133,7 +125,7 @@ class AppController extends Controller { |
133 | 125 | $isAuthorized = true; |
134 | 126 | break; |
135 | 127 | |
136 | - case 'Administration': | |
128 | + case 'Administration' : | |
137 | 129 | if (in_array($role, [ |
138 | 130 | 'Administration', |
139 | 131 | 'Administration Plus', |
... | ... | @@ -141,7 +133,7 @@ class AppController extends Controller { |
141 | 133 | ])) |
142 | 134 | $isAuthorized = true; |
143 | 135 | break; |
144 | - case 'Responsable': | |
136 | + case 'Responsable' : | |
145 | 137 | if (in_array($role, [ |
146 | 138 | 'Responsable', |
147 | 139 | 'Administration', |
... | ... | @@ -151,7 +143,7 @@ class AppController extends Controller { |
151 | 143 | $isAuthorized = true; |
152 | 144 | break; |
153 | 145 | |
154 | - case 'Utilisateur': | |
146 | + case 'Utilisateur' : | |
155 | 147 | if (in_array($role, [ |
156 | 148 | 'Utilisateur', |
157 | 149 | 'Responsable', |
... | ... | @@ -174,11 +166,9 @@ class AppController extends Controller { |
174 | 166 | */ |
175 | 167 | public function beforeFilter(Event $event) { |
176 | 168 | // !!! Ne jamais autoriser l'action 'login', sinon cela va créer des problèmes sur le fonctionnement normal de AuthComponent (cf doc) !!! |
177 | - $configuration = TableRegistry::get('Configurations')->find() | |
178 | - ->where([ | |
169 | + $configuration = TableRegistry::get('Configurations')->find()->where([ | |
179 | 170 | 'id =' => 1 |
180 | - ]) | |
181 | - ->first(); | |
171 | + ])->first(); | |
182 | 172 | |
183 | 173 | if ($configuration->mode_install) { |
184 | 174 | $this->LdapAuth->allow([ |
... | ... | @@ -223,19 +213,15 @@ class AppController extends Controller { |
223 | 213 | } |
224 | 214 | $this->set('username', $this->LdapAuth->user('sn')[0] . ' ' . $this->LdapAuth->user('givenname')[0]); |
225 | 215 | |
226 | - $configuration = TableRegistry::get('Configurations')->find() | |
227 | - ->where([ | |
216 | + $configuration = TableRegistry::get('Configurations')->find()->where([ | |
228 | 217 | 'id =' => 1 |
229 | - ]) | |
230 | - ->first(); | |
218 | + ])->first(); | |
231 | 219 | $this->set('configuration', $configuration); |
232 | 220 | $this->request->session()->write("authType", $configuration->authentificationType_ldap); |
233 | 221 | |
234 | - $user = TableRegistry::get('Users')->find() | |
235 | - ->where([ | |
222 | + $user = TableRegistry::get('Users')->find()->where([ | |
236 | 223 | 'username' => $this->LdapAuth->user($configuration->authentificationType_ldap)[0] |
237 | - ]) | |
238 | - ->first(); | |
224 | + ])->first(); | |
239 | 225 | |
240 | 226 | $role = $user['role']; |
241 | 227 | if ($role == null) |
... | ... | @@ -244,16 +230,12 @@ class AppController extends Controller { |
244 | 230 | |
245 | 231 | $this->set('userConnected', $user); |
246 | 232 | |
247 | - $this->set('idGmNa', TableRegistry::get('GroupesMetiers')->find() | |
248 | - ->where([ | |
233 | + $this->set('idGmNa', TableRegistry::get('GroupesMetiers')->find()->where([ | |
249 | 234 | 'nom =' => 'N/A' |
250 | - ]) | |
251 | - ->first()['id']); | |
252 | - $this->set('idGtNa', TableRegistry::get('GroupesThematiques')->find() | |
253 | - ->where([ | |
235 | + ])->first()['id']); | |
236 | + $this->set('idGtNa', TableRegistry::get('GroupesThematiques')->find()->where([ | |
254 | 237 | 'nom =' => 'N/A' |
255 | - ]) | |
256 | - ->first()['id']); | |
238 | + ])->first()['id']); | |
257 | 239 | |
258 | 240 | $displayElement = function ($nom, $valeur, $params = "") { |
259 | 241 | $balise = ($params != "") ? '<td ' . $params . '>' : '<td>'; |
... | ... | @@ -463,11 +445,9 @@ class AppController extends Controller { |
463 | 445 | |
464 | 446 | // } |
465 | 447 | static function isLabinventDebugMode() { |
466 | - return TableRegistry::get('Configurations')->find() | |
467 | - ->where([ | |
448 | + return TableRegistry::get('Configurations')->find()->where([ | |
468 | 449 | 'id =' => 1 |
469 | - ]) | |
470 | - ->first()->mode_debug; | |
450 | + ])->first()->mode_debug; | |
471 | 451 | } |
472 | 452 | |
473 | 453 | function myDebug($arg, $stop = false) { |
... | ... | @@ -484,8 +464,12 @@ class AppController extends Controller { |
484 | 464 | * |
485 | 465 | * @param $obj : |
486 | 466 | * Matériel concerné |
467 | + * @param $subject : | |
468 | + * Sujet du message à envoyer. Si $subject n'est pas renseigné, un sujet par défaut sera généré. | |
469 | + * @param $msg : | |
470 | + * Message à envoyer. Si $msg n'est pas renseigné, un message par défaut sera généré. | |
487 | 471 | */ |
488 | - public function sendEmail($obj) { | |
472 | + public function sendEmail($obj, $subject = null, $msg = null) { | |
489 | 473 | /* |
490 | 474 | * $_SESSION['Auth']['User'] pour retrouver TOUTES les infos de la session courante (tout est du string) : |
491 | 475 | * nom['sn'][0] |
... | ... | @@ -506,90 +490,91 @@ class AppController extends Controller { |
506 | 490 | |
507 | 491 | // On détermine le message et le sujet du mail en fonction de l'action effectuee |
508 | 492 | $acteur = $_SESSION['Auth']['User']['givenname'][0] . ' ' . $_SESSION['Auth']['User']['sn'][0]; |
509 | - $nom_materiel = $materiel->designation; | |
510 | - Switch ($action) { | |
511 | - case 'add': | |
512 | - $subject = "Ajout d'un matériel"; | |
513 | - $msg = "$acteur a ajouté le matériel $nom_materiel"; | |
514 | - break; | |
515 | - case 'edit': | |
516 | - $subject = "Modification d'un matériel"; | |
517 | - $msg = "$acteur a modifié le matériel $nom_materiel"; | |
518 | - break; | |
519 | - case 'delete': | |
520 | - $subject = "Suppression d'un matériel"; | |
521 | - $msg = "$acteur a supprimé le matériel $nom_materiel"; | |
522 | - break; | |
523 | - case 'statusValidated': | |
524 | - $subject = "Validation d'un matériel"; | |
525 | - $msg = "$acteur a validé le matériel $nom_materiel"; | |
526 | - break; | |
527 | - case 'statusToBeArchived': | |
528 | - $subject = "Demande d'archivage d'un matériel"; | |
529 | - $msg = "$acteur a demandé l'archivage du matériel $nom_materiel"; | |
530 | - break; | |
531 | - case 'statusArchived': | |
532 | - $subject = "Archivage d'un matériel"; | |
533 | - $msg = "$acteur a archivé le matériel $nom_materiel"; | |
534 | - break; | |
535 | - case 'setLabelIsPlaced': | |
536 | - $subject = "Etiquette posée sur un matériel"; | |
537 | - $msg = "Etiquette posée sur le matériel $nom_materiel"; | |
538 | - break; | |
539 | - case 'printLabelRuban': | |
540 | - $subject = "Etiquette imprimée"; | |
541 | - $msg = "L'étiquette concerant votre matériel $nom_materiel a été imprimée. Veuillez vérifier et compléter si besoin la fiche corespondante."; | |
493 | + if ($materiel != null) { | |
494 | + $nom_materiel = $materiel->designation; | |
495 | + if ($subject == null && $msg == null) { | |
496 | + Switch ($action) { | |
497 | + case 'add' : | |
498 | + $subject = "Ajout d'un matériel"; | |
499 | + $msg = "$acteur a ajouté le matériel $nom_materiel"; | |
500 | + break; | |
501 | + case 'edit' : | |
502 | + $subject = "Modification d'un matériel"; | |
503 | + $msg = "$acteur a modifié le matériel $nom_materiel"; | |
504 | + break; | |
505 | + case 'delete' : | |
506 | + $subject = "Suppression d'un matériel"; | |
507 | + $msg = "$acteur a supprimé le matériel $nom_materiel"; | |
508 | + break; | |
509 | + case 'statusValidated' : | |
510 | + $subject = "Validation d'un matériel"; | |
511 | + $msg = "$acteur a validé le matériel $nom_materiel"; | |
512 | + break; | |
513 | + case 'statusToBeArchived' : | |
514 | + $subject = "Demande d'archivage d'un matériel"; | |
515 | + $msg = "$acteur a demandé l'archivage du matériel $nom_materiel"; | |
516 | + break; | |
517 | + case 'statusArchived' : | |
518 | + $subject = "Archivage d'un matériel"; | |
519 | + $msg = "$acteur a archivé le matériel $nom_materiel"; | |
520 | + break; | |
521 | + case 'setLabelIsPlaced' : | |
522 | + $subject = "Etiquette posée sur un matériel"; | |
523 | + $msg = "Etiquette posée sur le matériel $nom_materiel"; | |
524 | + break; | |
525 | + case 'printLabelRuban' : | |
526 | + $subject = "Etiquette imprimée"; | |
527 | + $msg = "L'étiquette concerant votre matériel $nom_materiel a été imprimée. Veuillez vérifier et compléter si besoin la fiche corespondante."; | |
528 | + $mailList[0] = $materiel->email_responsable; | |
529 | + default : | |
530 | + $subject = "Action \"$action\" sur un matériel"; | |
531 | + $msg = "$acteur a effectué l'action \"$action\" sur le matériel $nom_materiel"; | |
532 | + break; | |
533 | + } | |
534 | + } | |
535 | + | |
536 | + // Et maintenant on construit la liste de mails ... | |
537 | + // Si l'envoi général est activé (et que l'action ne correspond pas à 'printLabelRuban'): | |
538 | + if ($configuration->envoi_mail && $action != 'printLabelRuban') { | |
539 | + // mail owner | |
542 | 540 | $mailList[0] = $materiel->email_responsable; |
543 | - default: | |
544 | - $subject = "Action \"$action\" sur un matériel"; | |
545 | - $msg = "$acteur a effectué l'action \"$action\" sur le matériel $nom_materiel"; | |
546 | - break; | |
547 | - } | |
548 | 541 | |
549 | - // Et maintenant on construit la liste de mails ... | |
550 | - // Si l'envoi général est activé (et que l'action ne correspond pas à 'printLabelRuban'): | |
551 | - if ($configuration->envoi_mail && $action != 'printLabelRuban') { | |
552 | - // mail owner | |
553 | - $mailList[0] = $materiel->email_responsable; | |
554 | - | |
555 | - // mail resp | |
556 | - $mailsRespMetier = null; | |
557 | - $mailsRespMetier = null; | |
558 | - | |
559 | - if ($materiel->groupes_metier_id != null && $materiel->groupes_metier_id != 1) | |
560 | - // Le ..!= 1 c'est parce que le groupe métier/thématique d'id 1 correspond au groupe N/A, soit aucun groupe | |
561 | - $mailsRespMetier = TableRegistry::get('Users')->find() | |
562 | - ->select('email') | |
563 | - ->where([ | |
564 | - 'role =' => 'Responsable', | |
565 | - 'groupes_metier_id =' => $materiel->groupes_metier_id | |
566 | - ]) | |
567 | - ->toArray(); | |
568 | - | |
569 | - if ($mailsRespMetier != null && $mailsRespMetier != null) { | |
570 | - $mailResp = array_unique(array_merge($mailsRespMetier, $mailRespThematique)); | |
571 | - for ($i = 0; $i < sizeof($mailsResp); $i ++) { | |
572 | - $mailList[sizeof($mailList)] = $mailsResp[$i]['email']; | |
542 | + // mail resp | |
543 | + $mailsRespMetier = null; | |
544 | + $mailsRespMetier = null; | |
545 | + | |
546 | + if ($materiel->groupes_metier_id != null && $materiel->groupes_metier_id != 1) | |
547 | + // Le ..!= 1 c'est parce que le groupe métier/thématique d'id 1 correspond au groupe N/A, soit aucun groupe | |
548 | + $mailsRespMetier = TableRegistry::get('Users')->find()->select('email')->where([ | |
549 | + 'role =' => 'Responsable', | |
550 | + 'groupes_metier_id =' => $materiel->groupes_metier_id | |
551 | + ])->toArray(); | |
552 | + | |
553 | + if ($mailsRespMetier != null && $mailsRespMetier != null) { | |
554 | + $mailResp = array_unique(array_merge($mailsRespMetier, $mailRespThematique)); | |
555 | + for ($i = 0; $i < sizeof($mailsResp); $i ++) { | |
556 | + $mailList[sizeof($mailList)] = $mailsResp[$i]['email']; | |
557 | + } | |
573 | 558 | } |
574 | - } | |
575 | 559 | |
576 | - // mail admin de reference (ici appele gestionnaire) -> Partie administration | |
577 | - // Cela a été mis en commentaire car de toute façon l'utilisateur va voir un administratif pour faire valider sa fiche, | |
578 | - // Pas la peine de spam l'administration de mails non plus hein ! | |
579 | - | |
580 | - /* | |
581 | - * if ($action != 'statusValidated' && $action != 'statusArchived') { | |
582 | - * $mailsAdmin = TableRegistry::get('Users')->find() | |
583 | - * ->select('email') | |
584 | - * ->where([ | |
585 | - * 'role =' => 'Administration' | |
586 | - * ]) | |
587 | - * ->toArray(); | |
588 | - * for ($i = 0; $i < sizeof($mailsAdmin); $i ++) { | |
589 | - * $mailList[sizeof($mailList)] = $mailsAdmin[$i]['email']; | |
590 | - * } | |
591 | - * } | |
592 | - */ | |
560 | + // mail admin de reference (ici appele gestionnaire) -> Partie administration | |
561 | + // Cela a été mis en commentaire car de toute façon l'utilisateur va voir un administratif pour faire valider sa fiche, | |
562 | + // Pas la peine de spam l'administration de mails non plus hein ! | |
563 | + | |
564 | + /* | |
565 | + * if ($action != 'statusValidated' && $action != 'statusArchived') { | |
566 | + * $mailsAdmin = TableRegistry::get('Users')->find() | |
567 | + * ->select('email') | |
568 | + * ->where([ | |
569 | + * 'role =' => 'Administration' | |
570 | + * ]) | |
571 | + * ->toArray(); | |
572 | + * for ($i = 0; $i < sizeof($mailsAdmin); $i ++) { | |
573 | + * $mailList[sizeof($mailList)] = $mailsAdmin[$i]['email']; | |
574 | + * } | |
575 | + * } | |
576 | + */ | |
577 | + } | |
593 | 578 | } |
594 | 579 | |
595 | 580 | // Si l'envoi à la liste spécifiée est activé (et que l'action ne correspond pas à 'printLabelRuban'): |
... | ... | @@ -610,14 +595,11 @@ class AppController extends Controller { |
610 | 595 | // On envoi des mails à toute la liste, sauf pour "l'acteur", il sait ce qu'il a fait, pas besoin de le spam non plus hein |
611 | 596 | if ($mail != $_SESSION['Auth']['User']['mail'][0]) { |
612 | 597 | $message = $msg; // Sisi, cette variable $message est utile, m'enfin vous pouvez toujours essayer de la supprimer ..... Et pensez à regarder le contenu de vos mails !!! Sinon ca fait une tumeur |
613 | - if ($action != 'statusValidated') | |
598 | + if ($action != 'statusValidated' && $materiel != null) | |
614 | 599 | $message .= " Veuillez vérifier et compléter si besoin la fiche corespondante."; |
615 | - $role = TableRegistry::get('Users')->find() | |
616 | - ->select('role') | |
617 | - ->where([ | |
600 | + $role = TableRegistry::get('Users')->find()->select('role')->where([ | |
618 | 601 | 'email =' => $mail |
619 | - ]) | |
620 | - ->first()['role']; | |
602 | + ])->first()['role']; | |
621 | 603 | if ($role) |
622 | 604 | $role = 'en tant que ' . $role; |
623 | 605 | else |
... | ... | @@ -644,13 +626,9 @@ class AppController extends Controller { |
644 | 626 | // ->subject("[LabInvent] ".$subject) |
645 | 627 | // ->send($msg); |
646 | 628 | // } else { // <-- Si la case n'est pas cochée |
647 | - $email->transport('default') | |
648 | - ->from([ | |
629 | + $email->transport('default')->from([ | |
649 | 630 | $config->sender_mail => $etiquetteFrom[0] |
650 | - ]) | |
651 | - ->to($mail) | |
652 | - ->subject("[LabInvent] " . $subject) | |
653 | - ->send($msg); | |
631 | + ])->to($mail)->subject("[LabInvent] " . $subject)->send($msg); | |
654 | 632 | // } |
655 | 633 | } |
656 | 634 | } | ... | ... |
src/Controller/DocumentsController.php
... | ... | @@ -11,125 +11,175 @@ use FPDF; |
11 | 11 | * @property \App\Model\Table\DocumentsTable $Documents |
12 | 12 | * @property \Cake\ORM\Association\BelongsTo $TypeDocuments |
13 | 13 | */ |
14 | -class DocumentsController extends AppController | |
15 | -{ | |
16 | - | |
17 | - /** | |
18 | - * @param $user | |
19 | - * | |
20 | - * Give authorization for documents | |
21 | - * | |
22 | - * @return boolean | |
23 | - */ | |
24 | - public function isAuthorized($user) | |
25 | - { | |
26 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
27 | - $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; | |
28 | - $action = $this->request->params['action']; | |
29 | - | |
30 | - // Super-Admin peut accéder à chaque action | |
31 | - if($role == 'Super Administrateur') return true; | |
32 | - | |
33 | - if (in_array($action, ['admission', 'sortie'])) { | |
34 | - if ($this->userHasRole('Administration')) { | |
35 | - return true; | |
36 | - } | |
37 | - } | |
38 | - | |
39 | - if(in_array($action, ['delete', 'edit'])) { | |
40 | - if ($this->userHasRole('Administration')) { | |
41 | - return true; | |
42 | - } | |
43 | - $u = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first(); | |
44 | - | |
45 | - $doc = $this->Documents->get((int)$this->request->params['pass'][0]); | |
46 | - | |
47 | - $id = $doc->get('materiel_id'); | |
48 | - if(empty($id)) { | |
49 | - $id = $doc->get('suivi_id'); | |
50 | - $suiviTable = TableRegistry::get('Suivis'); | |
51 | - if ($role == 'Responsable') { | |
52 | - if(isset($u['groupes_metier_id']) && $u['groupes_metier_id'] != TableRegistry::get('GroupesMetiers')->find()->where(['nom =' => 'N/A'])->first()['id']) { | |
53 | - return ($suiviTable->exists(['id' => $id, 'groupes_metier_id' => $u['groupes_metier_id']])); | |
54 | - } | |
55 | - else if (isset($u['groupe_thematique_id']) && $u['groupe_thematique_id'] != TableRegistry::get('GroupesThematiques')->find()->where(['nom =' => 'N/A'])->first()['id']) { | |
56 | - return ($suiviTable->exists(['id' => $id, 'groupes_thematique_id' => $u['groupe_thematique_id']])); | |
57 | - } | |
58 | - else { | |
59 | - return false; | |
60 | - } | |
61 | - } | |
62 | - if ($role == 'Utilisateur') { | |
63 | - return $suiviTable->exists(['id' => $id, 'nom_createur' => $user['sn'][0].' '.$user['givenname'][0]]); | |
64 | - } | |
65 | - } else { | |
66 | - $materielTable = TableRegistry::get('Materiels'); | |
67 | - if ($role == 'Responsable') { | |
68 | - if(isset($u['groupes_metier_id']) && $u['groupes_metier_id'] != TableRegistry::get('GroupesMetiers')->find()->where(['nom =' => 'N/A'])->first()['id']) { | |
69 | - return ($materielTable->exists(['id' => $id, 'groupes_metier_id' => $u['groupes_metier_id']])); | |
70 | - } | |
71 | - else if (isset($u['groupe_thematique_id']) && $u['groupe_thematique_id'] != TableRegistry::get('GroupesThematiques')->find()->where(['nom =' => 'N/A'])->first()['id']) { | |
72 | - return ($materielTable->exists(['id' => $id, 'groupes_thematique_id' => $u['groupe_thematique_id']])); | |
73 | - } | |
74 | - else { | |
75 | - return false; | |
76 | - } | |
77 | - } | |
78 | - if ($role == 'Utilisateur') { | |
79 | - return ($materielTable->exists(['id' => $id, 'nom_createur' => $user['sn'][0].' '.$user['givenname'][0]]) || $materielTable->exists(['id' => $id, 'nom_responsable' => $user['sn'][0].' '.$user['givenname'][0]])); | |
80 | - } | |
81 | - } | |
82 | - } | |
83 | - | |
84 | - //Pour tout le monde | |
85 | - if (in_array($action, ['view', 'add', 'ficheMateriel'])) return true; | |
86 | - | |
87 | - return false; | |
88 | - } | |
89 | - | |
14 | +class DocumentsController extends AppController { | |
15 | + | |
16 | + /** | |
17 | + * | |
18 | + * @param $user Give | |
19 | + * authorization for documents | |
20 | + * @return boolean | |
21 | + */ | |
22 | + public function isAuthorized($user) { | |
23 | + $configuration = TableRegistry::get('Configurations')->find()->where([ | |
24 | + 'id =' => 1 | |
25 | + ])->first(); | |
26 | + $role = TableRegistry::get('Users')->find()->where([ | |
27 | + 'username' => $user[$configuration->authentificationType_ldap][0] | |
28 | + ])->first()['role']; | |
29 | + $action = $this->request->params['action']; | |
30 | + | |
31 | + // Super-Admin peut accéder à chaque action | |
32 | + if ($role == 'Super Administrateur') | |
33 | + return true; | |
34 | + | |
35 | + if (in_array($action, [ | |
36 | + 'admission', | |
37 | + 'sortie' | |
38 | + ])) { | |
39 | + if ($this->userHasRole('Administration')) { | |
40 | + return true; | |
41 | + } | |
42 | + } | |
43 | + | |
44 | + if (in_array($action, [ | |
45 | + 'delete', | |
46 | + 'edit' | |
47 | + ])) { | |
48 | + if ($this->userHasRole('Administration')) { | |
49 | + return true; | |
50 | + } | |
51 | + $u = TableRegistry::get('Users')->find()->where([ | |
52 | + 'username' => $user[$configuration->authentificationType_ldap][0] | |
53 | + ])->first(); | |
54 | + | |
55 | + $doc = $this->Documents->get((int) $this->request->params['pass'][0]); | |
56 | + | |
57 | + $id = $doc->get('materiel_id'); | |
58 | + if (empty($id)) { | |
59 | + $id = $doc->get('suivi_id'); | |
60 | + $suiviTable = TableRegistry::get('Suivis'); | |
61 | + if ($role == 'Responsable') { | |
62 | + if (isset($u['groupes_metier_id']) && $u['groupes_metier_id'] != TableRegistry::get('GroupesMetiers')->find()->where([ | |
63 | + 'nom =' => 'N/A' | |
64 | + ])->first()['id']) { | |
65 | + return ($suiviTable->exists([ | |
66 | + 'id' => $id, | |
67 | + 'groupes_metier_id' => $u['groupes_metier_id'] | |
68 | + ])); | |
69 | + } else if (isset($u['groupe_thematique_id']) && $u['groupe_thematique_id'] != TableRegistry::get('GroupesThematiques')->find()->where([ | |
70 | + 'nom =' => 'N/A' | |
71 | + ])->first()['id']) { | |
72 | + return ($suiviTable->exists([ | |
73 | + 'id' => $id, | |
74 | + 'groupes_thematique_id' => $u['groupe_thematique_id'] | |
75 | + ])); | |
76 | + } else { | |
77 | + return false; | |
78 | + } | |
79 | + } | |
80 | + if ($role == 'Utilisateur') { | |
81 | + return $suiviTable->exists([ | |
82 | + 'id' => $id, | |
83 | + 'nom_createur' => $user['sn'][0] . ' ' . $user['givenname'][0] | |
84 | + ]); | |
85 | + } | |
86 | + } else { | |
87 | + $materielTable = TableRegistry::get('Materiels'); | |
88 | + if ($role == 'Responsable') { | |
89 | + if (isset($u['groupes_metier_id']) && $u['groupes_metier_id'] != TableRegistry::get('GroupesMetiers')->find()->where([ | |
90 | + 'nom =' => 'N/A' | |
91 | + ])->first()['id']) { | |
92 | + return ($materielTable->exists([ | |
93 | + 'id' => $id, | |
94 | + 'groupes_metier_id' => $u['groupes_metier_id'] | |
95 | + ])); | |
96 | + } else if (isset($u['groupe_thematique_id']) && $u['groupe_thematique_id'] != TableRegistry::get('GroupesThematiques')->find()->where([ | |
97 | + 'nom =' => 'N/A' | |
98 | + ])->first()['id']) { | |
99 | + return ($materielTable->exists([ | |
100 | + 'id' => $id, | |
101 | + 'groupes_thematique_id' => $u['groupe_thematique_id'] | |
102 | + ])); | |
103 | + } else { | |
104 | + return false; | |
105 | + } | |
106 | + } | |
107 | + if ($role == 'Utilisateur') { | |
108 | + return ($materielTable->exists([ | |
109 | + 'id' => $id, | |
110 | + 'nom_createur' => $user['sn'][0] . ' ' . $user['givenname'][0] | |
111 | + ]) || $materielTable->exists([ | |
112 | + 'id' => $id, | |
113 | + 'nom_responsable' => $user['sn'][0] . ' ' . $user['givenname'][0] | |
114 | + ])); | |
115 | + } | |
116 | + } | |
117 | + } | |
118 | + | |
119 | + // Pour tout le monde | |
120 | + if (in_array($action, [ | |
121 | + 'view', | |
122 | + 'add', | |
123 | + 'ficheMateriel' | |
124 | + ])) | |
125 | + return true; | |
126 | + | |
127 | + return false; | |
128 | + } | |
129 | + | |
90 | 130 | /** |
91 | 131 | * Index method |
92 | 132 | * |
93 | 133 | * @return \Cake\Network\Response|null |
94 | 134 | */ |
95 | - public function index() | |
96 | - { | |
97 | - $this->paginate = [ | |
98 | - 'contain' => ['TypeDocuments'], | |
99 | - ]; | |
135 | + public function index() { | |
136 | + $this->paginate = [ | |
137 | + 'contain' => [ | |
138 | + 'TypeDocuments' | |
139 | + ] | |
140 | + ]; | |
100 | 141 | $documents = $this->paginate($this->Documents); |
101 | 142 | |
102 | 143 | $materiel = $this->Documents->Materiels; |
103 | - | |
144 | + | |
104 | 145 | $this->set(compact('documents', 'materiel')); |
105 | - $this->set('_serialize', ['documents']); | |
146 | + $this->set('_serialize', [ | |
147 | + 'documents' | |
148 | + ]); | |
106 | 149 | } |
107 | 150 | |
108 | 151 | /** |
109 | 152 | * View method |
110 | 153 | * |
111 | - * @param string|null $id Document id. | |
154 | + * @param string|null $id | |
155 | + * Document id. | |
112 | 156 | * @return \Cake\Network\Response|null |
113 | 157 | * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. |
114 | 158 | */ |
115 | - public function view($id = null) | |
116 | - { | |
159 | + public function view($id = null) { | |
117 | 160 | $document = $this->Documents->get($id, [ |
118 | - 'contain' => ['TypeDocuments'] | |
161 | + 'contain' => [ | |
162 | + 'TypeDocuments' | |
163 | + ] | |
119 | 164 | ]); |
120 | 165 | |
121 | - $materiel = $this->Documents->Materiels->find()->where(['id =' => $document->materiel_id])->first(); | |
166 | + $materiel = $this->Documents->Materiels->find()->where([ | |
167 | + 'id =' => $document->materiel_id | |
168 | + ])->first(); | |
122 | 169 | |
123 | - if($materiel != null) { | |
124 | - $this->set('materiel', $materiel); | |
125 | - } | |
126 | - else { | |
127 | - $suivi = $this->Documents->Suivis->find()->where(['id =' => $document->suivi_id])->first(); | |
128 | - $this->set('suivi', $suivi); | |
170 | + if ($materiel != null) { | |
171 | + $this->set('materiel', $materiel); | |
172 | + } else { | |
173 | + $suivi = $this->Documents->Suivis->find()->where([ | |
174 | + 'id =' => $document->suivi_id | |
175 | + ])->first(); | |
176 | + $this->set('suivi', $suivi); | |
129 | 177 | } |
130 | - | |
178 | + | |
131 | 179 | $this->set('document', $document); |
132 | - $this->set('_serialize', ['document']); | |
180 | + $this->set('_serialize', [ | |
181 | + 'document' | |
182 | + ]); | |
133 | 183 | } |
134 | 184 | |
135 | 185 | /** |
... | ... | @@ -137,79 +187,113 @@ class DocumentsController extends AppController |
137 | 187 | * |
138 | 188 | * @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise. |
139 | 189 | */ |
140 | - public function add() | |
141 | - { | |
190 | + public function add() { | |
142 | 191 | $document = $this->Documents->newEntity(); |
143 | - | |
192 | + | |
144 | 193 | if ($this->request->is('post')) { |
145 | 194 | $document = $this->Documents->patchEntity($document, $this->request->data); |
146 | 195 | |
147 | - $nomType = $this->Documents->TypeDocuments->find()->where(['id =' => $document->type_document_id])->first()['nom']; | |
196 | + $nomType = $this->Documents->TypeDocuments->find()->where([ | |
197 | + 'id =' => $document->type_document_id | |
198 | + ])->first()['nom']; | |
148 | 199 | |
149 | - if(isset($this->passedArgs[2]) && $this->passedArgs[2] == 'photo') { | |
150 | - $document->set('photo', 1); | |
200 | + if (isset($this->request->params['pass'][2]) && $this->request->params['pass'][2] == 'photo') { | |
201 | + $document->set('photo', 1); | |
151 | 202 | } |
152 | 203 | |
153 | 204 | if ($this->Documents->save($document)) { |
154 | 205 | $this->Flash->success(__('Le fichier a bien été ajouté.')); |
155 | - | |
206 | + | |
156 | 207 | $id = $document->materiel_id; |
157 | - if(!empty($id)) { | |
158 | - $materielTable = TableRegistry::get('Materiels'); | |
159 | - $materiel = $materielTable->get($id); | |
208 | + if (! empty($id)) { | |
209 | + $materielTable = TableRegistry::get('Materiels'); | |
210 | + $materiel = $materielTable->get($id); | |
160 | 211 | } |
161 | - | |
162 | - if(isset($this->passedArgs[2]) && $this->passedArgs[2] == 'photo') { | |
163 | - | |
164 | - $photoIdOld = $materiel->get('photo_id'); | |
165 | - if(isset($photoIdOld)) { | |
166 | - $docOld = TableRegistry::get('Documents')->get($photoIdOld); | |
167 | - $this->Documents->delete($docOld); | |
168 | - } | |
169 | - | |
170 | - $materiel->set('photo_id', $document->id); | |
171 | - $materielTable->save($materiel); | |
212 | + | |
213 | + if (isset($this->request->params['pass'][2]) && $this->request->params['pass'][2] == 'photo') { | |
214 | + | |
215 | + $photoIdOld = $materiel->get('photo_id'); | |
216 | + if (isset($photoIdOld)) { | |
217 | + $docOld = TableRegistry::get('Documents')->get($photoIdOld); | |
218 | + $this->Documents->delete($docOld); | |
219 | + } | |
220 | + | |
221 | + $materiel->set('photo_id', $document->id); | |
222 | + $materielTable->save($materiel); | |
172 | 223 | } |
173 | - | |
174 | - $userName = $this->LdapAuth->user('sn')[0].' '.$this->LdapAuth->user('givenname')[0]; | |
224 | + | |
225 | + $userName = $this->LdapAuth->user('sn')[0] . ' ' . $this->LdapAuth->user('givenname')[0]; | |
175 | 226 | $userEmail = $this->LdapAuth->user('mail')[0]; |
176 | 227 | |
177 | 228 | $id = $document->materiel_id; |
178 | - if(empty($id)) { | |
179 | - $id = $document->suivi_id; | |
180 | - //$this->sendEmailToManagementWith('[LabInvent] Ajout d\'un document', $userName.' (email = '.$userEmail.') a ajouté un document de type "'.$nomType.'" au suivi "Suivi '.$document->suivi_id.'".'); | |
181 | - return $this->redirect(['controller' => 'suivis', 'action' => 'view', $id]); | |
229 | + if (empty($id)) { | |
230 | + // Ajout de doc au suivi | |
231 | + $id = $document->suivi_id; | |
232 | + // $this->sendEmailToManagementWith('[LabInvent] Ajout d\'un document', $userName.' (email = '.$userEmail.') a ajouté un document de type "'.$nomType.'" au suivi "Suivi '.$document->suivi_id.'".'); | |
233 | + $this->sendEmail(null, '[LabInvent] Ajout d\'un document', $userName . ' a ajouté un document de type "' . $nomType . '" au suivi "Suivi ' . $document->suivi_id . '".'); | |
234 | + return $this->redirect([ | |
235 | + 'controller' => 'suivis', | |
236 | + 'action' => 'view', | |
237 | + $id | |
238 | + ]); | |
182 | 239 | } else { |
183 | - //$this->sendEmailToManagementWith('[LabInvent] Ajout d\'un document', $userName.' (email = '.$userEmail.') a ajouté un document de type "'.$nomType.'" au matériel "'.$materiel->designation.'" (id = '.$materiel->id.').'); | |
184 | - return $this->redirect(['controller' => 'materiels', 'action' => 'view', $id]); | |
240 | + // Ajout de doc au matériel | |
241 | + $materiel->documents = $materiel->documents + 1; | |
242 | + // $this->sendEmailToManagementWith('[LabInvent] Ajout d\'un document', $userName.' (email = '.$userEmail.') a ajouté un document de type "'.$nomType.'" au matériel "'.$materiel->designation.'" (id = '.$materiel->id.').'); | |
243 | + $this->sendEmail(null, '[LabInvent] Ajout d\'un document', $userName . ' a ajouté un document de type "' . $nomType . '" au matériel "' . $materiel->designation . '" (id = ' . $materiel->id . ').'); | |
244 | + return $this->redirect([ | |
245 | + 'controller' => 'materiels', | |
246 | + 'action' => 'view', | |
247 | + $id | |
248 | + ]); | |
185 | 249 | } |
186 | - | |
187 | 250 | } else { |
188 | 251 | $this->Flash->error(__('Le fichier n\'a pas pu être ajouté.')); |
189 | 252 | } |
190 | 253 | } |
191 | - | |
192 | - if(isset($this->passedArgs[1]) && $this->passedArgs[1] == 'mat') { | |
193 | - $materiel = $this->Documents->Materiels->find('list', [ 'keyField' => 'id', 'valueField' => 'numero_laboratoire'])->where(['id =' => $this->request->params['pass'][0]]); | |
194 | - $this->set('materiel', $materiel); | |
195 | - } | |
196 | - else { | |
197 | - $suivi = $this->Documents->Suivis->find('list', [ 'keyField' => 'id', 'valueField' => 'id'])->where(['id =' => $this->request->params['pass'][0]]); | |
198 | - $this->set('suivi', $suivi); | |
254 | + | |
255 | + if (isset($this->request->params['pass'][1]) && $this->request->params['pass'][1] == 'mat') { | |
256 | + $materiel = $this->Documents->Materiels->find('list', [ | |
257 | + 'keyField' => 'id', | |
258 | + 'valueField' => 'numero_laboratoire' | |
259 | + ])->where([ | |
260 | + 'id =' => $this->request->params['pass'][0] | |
261 | + ]); | |
262 | + $this->set('materiel', $materiel); | |
263 | + } else { | |
264 | + $suivi = $this->Documents->Suivis->find('list', [ | |
265 | + 'keyField' => 'id', | |
266 | + 'valueField' => 'id' | |
267 | + ])->where([ | |
268 | + 'id =' => $this->request->params['pass'][0] | |
269 | + ]); | |
270 | + $this->set('suivi', $suivi); | |
199 | 271 | } |
200 | - | |
201 | - if(isset($this->passedArgs[2]) && $this->passedArgs[2] == 'photo') { | |
202 | - $this->set('photo', 1); | |
203 | - $typesD = $this->Documents->TypeDocuments->find('list', [ 'keyField' => 'id', 'valueField' => 'nom'])->where(['nom =' => 'Photo']); | |
204 | - $idType = $this->Documents->TypeDocuments->find()->where(['nom =' => 'Photo'])->first()['id']; | |
205 | - $this->set('idType', $idType); | |
272 | + | |
273 | + if (isset($this->request->params['pass'][2]) && $this->request->params['pass'][2] == 'photo') { | |
274 | + $this->set('photo', 1); | |
275 | + $typesD = $this->Documents->TypeDocuments->find('list', [ | |
276 | + 'keyField' => 'id', | |
277 | + 'valueField' => 'nom' | |
278 | + ])->where([ | |
279 | + 'nom =' => 'Photo' | |
280 | + ]); | |
281 | + $idType = $this->Documents->TypeDocuments->find()->where([ | |
282 | + 'nom =' => 'Photo' | |
283 | + ])->first()['id']; | |
284 | + $this->set('idType', $idType); | |
206 | 285 | } else { |
207 | - $typesD = $this->Documents->TypeDocuments->find('list', [ 'keyField' => 'id', 'valueField' => 'nom', 'order' => 'TypeDocuments.nom']); | |
208 | - } | |
209 | - | |
210 | - | |
286 | + $typesD = $this->Documents->TypeDocuments->find('list', [ | |
287 | + 'keyField' => 'id', | |
288 | + 'valueField' => 'nom', | |
289 | + 'order' => 'TypeDocuments.nom' | |
290 | + ]); | |
291 | + } | |
292 | + | |
211 | 293 | $this->set(compact('document', 'typesD')); |
212 | - $this->set('_serialize', ['document']); | |
294 | + $this->set('_serialize', [ | |
295 | + 'document' | |
296 | + ]); | |
213 | 297 | } |
214 | 298 | |
215 | 299 | /** |
... | ... | @@ -217,214 +301,285 @@ class DocumentsController extends AppController |
217 | 301 | * |
218 | 302 | * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. |
219 | 303 | */ |
220 | - public function edit($id = null) | |
221 | - { | |
222 | - $document = $this->Documents->get($id, [ | |
223 | - 'contain' => [] | |
224 | - ]); | |
225 | - | |
226 | - if ($this->request->is(['patch', 'post', 'put'])) { | |
227 | - $document = $this->Documents->patchEntity($document, $this->request->data); | |
228 | - | |
229 | - if ($this->Documents->save($document)) { | |
230 | - $this->Flash->success(__('Le fichier a bien été edité.')); | |
231 | - | |
232 | - $id = $document->materiel_id; | |
233 | - if(empty($id)) { | |
234 | - $id = $document->suivi_id; | |
235 | - return $this->redirect(['controller' => 'suivis', 'action' => 'view', $id]); | |
236 | - } else { | |
237 | - return $this->redirect(['controller' => 'materiels', 'action' => 'view', $id]); | |
238 | - } | |
239 | - | |
240 | - } else { | |
241 | - $this->Flash->error(__('Le fichier n\'a pas pu être edité.')); | |
242 | - } | |
243 | - } | |
244 | - | |
245 | - $id = $document->materiel_id; | |
246 | - if(empty($id)) { | |
247 | - $id = $document->suivi_id; | |
248 | - $suivi = $this->Documents->Suivis->find('list', [ 'keyField' => 'id', 'valueField' => 'id'])->where(['id =' => $id]); | |
249 | - $this->set('suivi', $suivi); | |
250 | - } else { | |
251 | - $materiel = $this->Documents->Materiels->find('list', [ 'keyField' => 'id', 'valueField' => 'numero_laboratoire'])->where(['id =' => $id]); | |
252 | - $this->set('materiel', $materiel); | |
253 | - } | |
254 | - | |
255 | - if($document->photo) { | |
256 | - $this->set('photo', 1); | |
257 | - } | |
258 | - | |
259 | - | |
260 | - $typesD = $this->Documents->TypeDocuments->find('list', [ 'keyField' => 'id', 'valueField' => 'nom', 'order' => 'TypeDocuments.nom']); | |
261 | - | |
262 | - $this->set(compact('document', 'typesD')); | |
263 | - $this->set('_serialize', ['document']); | |
304 | + public function edit($id = null) { | |
305 | + $document = $this->Documents->get($id, [ | |
306 | + 'contain' => [] | |
307 | + ]); | |
308 | + | |
309 | + if ($this->request->is([ | |
310 | + 'patch', | |
311 | + 'post', | |
312 | + 'put' | |
313 | + ])) { | |
314 | + $document = $this->Documents->patchEntity($document, $this->request->data); | |
315 | + | |
316 | + if ($this->Documents->save($document)) { | |
317 | + $this->Flash->success(__('Le fichier a bien été edité.')); | |
318 | + | |
319 | + $id = $document->materiel_id; | |
320 | + if (empty($id)) { | |
321 | + $id = $document->suivi_id; | |
322 | + return $this->redirect([ | |
323 | + 'controller' => 'suivis', | |
324 | + 'action' => 'view', | |
325 | + $id | |
326 | + ]); | |
327 | + } else { | |
328 | + return $this->redirect([ | |
329 | + 'controller' => 'materiels', | |
330 | + 'action' => 'view', | |
331 | + $id | |
332 | + ]); | |
333 | + } | |
334 | + } else { | |
335 | + $this->Flash->error(__('Le fichier n\'a pas pu être edité.')); | |
336 | + } | |
337 | + } | |
338 | + | |
339 | + $id = $document->materiel_id; | |
340 | + if (empty($id)) { | |
341 | + $id = $document->suivi_id; | |
342 | + $suivi = $this->Documents->Suivis->find('list', [ | |
343 | + 'keyField' => 'id', | |
344 | + 'valueField' => 'id' | |
345 | + ])->where([ | |
346 | + 'id =' => $id | |
347 | + ]); | |
348 | + $this->set('suivi', $suivi); | |
349 | + } else { | |
350 | + $materiel = $this->Documents->Materiels->find('list', [ | |
351 | + 'keyField' => 'id', | |
352 | + 'valueField' => 'numero_laboratoire' | |
353 | + ])->where([ | |
354 | + 'id =' => $id | |
355 | + ]); | |
356 | + $this->set('materiel', $materiel); | |
357 | + } | |
358 | + | |
359 | + if ($document->photo) { | |
360 | + $this->set('photo', 1); | |
361 | + } | |
362 | + | |
363 | + $typesD = $this->Documents->TypeDocuments->find('list', [ | |
364 | + 'keyField' => 'id', | |
365 | + 'valueField' => 'nom', | |
366 | + 'order' => 'TypeDocuments.nom' | |
367 | + ]); | |
368 | + | |
369 | + $this->set(compact('document', 'typesD')); | |
370 | + $this->set('_serialize', [ | |
371 | + 'document' | |
372 | + ]); | |
264 | 373 | } |
265 | 374 | |
266 | 375 | /** |
267 | 376 | * Delete method |
268 | 377 | * |
269 | - * @param string|null $id Document id. | |
378 | + * @param string|null $id | |
379 | + * Document id. | |
270 | 380 | * @return \Cake\Network\Response|null Redirects to index. |
271 | 381 | * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. |
272 | 382 | */ |
273 | - public function delete($id = null) | |
274 | - { | |
275 | - $this->request->allowMethod(['post', 'delete']); | |
383 | + public function delete($id = null) { | |
384 | + $this->request->allowMethod([ | |
385 | + 'post', | |
386 | + 'delete' | |
387 | + ]); | |
276 | 388 | $document = $this->Documents->get($id); |
277 | - | |
278 | - if($document->photo) { | |
279 | - $materielTable = TableRegistry::get('Materiels'); | |
280 | - $materiel = $materielTable->get($document->materiel_id); | |
281 | - | |
282 | - $materiel->set('photo_id', null); | |
283 | - $materielTable->save($materiel); | |
389 | + | |
390 | + if ($document->photo) { | |
391 | + $materielTable = TableRegistry::get('Materiels'); | |
392 | + $materiel = $materielTable->get($document->materiel_id); | |
393 | + | |
394 | + $materiel->set('photo_id', null); | |
395 | + $materielTable->save($materiel); | |
284 | 396 | } |
285 | - | |
397 | + | |
286 | 398 | if ($this->Documents->delete($document)) { |
287 | 399 | $this->Flash->success(__('Le fichier a bien été supprimé.')); |
288 | 400 | } else { |
289 | 401 | $this->Flash->error(__('Le fichier n\'a pas pu être supprimé.')); |
290 | 402 | } |
291 | - | |
403 | + | |
292 | 404 | $id = $document->materiel_id; |
293 | - if(empty($id)) { | |
294 | - $id = $document->suivi_id; | |
295 | - return $this->redirect(['controller' => 'suivis', 'action' => 'view', $id]); | |
405 | + if (empty($id)) { | |
406 | + $id = $document->suivi_id; | |
407 | + return $this->redirect([ | |
408 | + 'controller' => 'suivis', | |
409 | + 'action' => 'view', | |
410 | + $id | |
411 | + ]); | |
296 | 412 | } else { |
297 | - return $this->redirect(['controller' => 'materiels', 'action' => 'view', $id]); | |
413 | + $materiel->documents = $materiel->documents - 1; | |
414 | + return $this->redirect([ | |
415 | + 'controller' => 'materiels', | |
416 | + 'action' => 'view', | |
417 | + $id | |
418 | + ]); | |
298 | 419 | } |
299 | 420 | } |
300 | - | |
301 | - | |
302 | - public function sortie($labNumber) { | |
303 | - $this->set('fpdf', new FPDF ( 'P', 'mm', 'A4' )); | |
421 | + | |
422 | + public function sortie($labNumber) { | |
423 | + $this->set('fpdf', new FPDF('P', 'mm', 'A4')); | |
304 | 424 | } |
305 | - | |
425 | + | |
306 | 426 | public function admission($labNumber) { |
307 | - | |
308 | - $this->set ( 'fpdf', new FPDF ( 'P', 'mm', 'A4' ) ); | |
309 | - // Find the concerned materiel | |
310 | - $materiel = TableRegistry::get('Materiels')->find('all', ['conditions' => ['numero_laboratoire' => $labNumber]])->first(); // End find | |
311 | - | |
312 | - // Get the administration user name | |
313 | - $userName = $this->LdapAuth->user('username'); | |
314 | - $numeroLab = $materiel->numero_laboratoire; | |
315 | - $dateAcquisition = $materiel->date_acquisition; | |
316 | - $dateAcquisition = $dateAcquisition; | |
317 | - $numeroCommande = $materiel->numero_commande; | |
318 | - $designation = $materiel->designation; | |
319 | - if(isset($materiel->organisme_id) && !empty($materiel->organisme_id)) { | |
320 | - $organisme = TableRegistry::get('Organismes')->find('all')->where(['id =' => $materiel->organisme_id])->first()->nom; | |
321 | - } | |
322 | - else { | |
323 | - $organisme = ""; | |
324 | - } | |
325 | - | |
326 | - $fournisseur = $materiel->fournisseur; | |
327 | - $numeroOrganisme = $materiel->numero_inventaire_organisme; | |
328 | - $eotp = $materiel->eotp; | |
329 | - $prix = $materiel->prix_ht; | |
330 | - | |
331 | - // Build the data array | |
332 | - $TDoc = [ | |
333 | - 'organisme' => $organisme, | |
334 | - 'numlab' => $numeroLab, | |
335 | - 'designation' => $designation, | |
336 | - 'dateAcquis' => $dateAcquisition, | |
337 | - 'numCde' => $numeroCommande, | |
338 | - 'fournisseur' => $fournisseur, | |
339 | - 'eotp' => $eotp, | |
340 | - 'prix' => $prix, | |
341 | - 'numOrg' => $numeroOrganisme | |
342 | - ]; | |
343 | - | |
344 | - // set the data for the document (accessible par $data dans le document) | |
345 | - $this->set ( 'data', $TDoc ); | |
346 | - | |
347 | - } // End fct admission | |
348 | - | |
427 | + $this->set('fpdf', new FPDF('P', 'mm', 'A4')); | |
428 | + // Find the concerned materiel | |
429 | + $materiel = TableRegistry::get('Materiels')->find('all', [ | |
430 | + 'conditions' => [ | |
431 | + 'numero_laboratoire' => $labNumber | |
432 | + ] | |
433 | + ])->first(); // End find | |
434 | + | |
435 | + // Get the administration user name | |
436 | + $userName = $this->LdapAuth->user('username'); | |
437 | + $numeroLab = $materiel->numero_laboratoire; | |
438 | + $dateAcquisition = $materiel->date_acquisition; | |
439 | + $dateAcquisition = $dateAcquisition; | |
440 | + $numeroCommande = $materiel->numero_commande; | |
441 | + $designation = $materiel->designation; | |
442 | + if (isset($materiel->organisme_id) && ! empty($materiel->organisme_id)) { | |
443 | + $organisme = TableRegistry::get('Organismes')->find('all')->where([ | |
444 | + 'id =' => $materiel->organisme_id | |
445 | + ])->first()->nom; | |
446 | + } else { | |
447 | + $organisme = ""; | |
448 | + } | |
449 | + | |
450 | + $fournisseur = $materiel->fournisseur; | |
451 | + $numeroOrganisme = $materiel->numero_inventaire_organisme; | |
452 | + $eotp = $materiel->eotp; | |
453 | + $prix = $materiel->prix_ht; | |
454 | + | |
455 | + // Build the data array | |
456 | + $TDoc = [ | |
457 | + 'organisme' => $organisme, | |
458 | + 'numlab' => $numeroLab, | |
459 | + 'designation' => $designation, | |
460 | + 'dateAcquis' => $dateAcquisition, | |
461 | + 'numCde' => $numeroCommande, | |
462 | + 'fournisseur' => $fournisseur, | |
463 | + 'eotp' => $eotp, | |
464 | + 'prix' => $prix, | |
465 | + 'numOrg' => $numeroOrganisme | |
466 | + ]; | |
467 | + | |
468 | + // set the data for the document (accessible par $data dans le document) | |
469 | + $this->set('data', $TDoc); | |
470 | + } | |
471 | + | |
472 | + // End fct admission | |
349 | 473 | public function ficheMateriel($labNumber) { |
350 | - | |
351 | - // Find the concerned materiel | |
352 | - $materiel = TableRegistry::get('Materiels')->find('all', ['conditions' => ['numero_laboratoire' => $labNumber]])->first(); // End find | |
353 | - | |
354 | - if(isset($materiel->sur_categorie_id)) { | |
355 | - $surCategorie = TableRegistry::get('SurCategories')->find()->where(['id =' => $materiel->sur_categorie_id])->first()->nom; | |
356 | - } | |
357 | - else { | |
358 | - $surCategorie = ' '; | |
359 | - } | |
360 | - | |
361 | - if(isset($materiel->categorie_id)) { | |
362 | - $categorie = TableRegistry::get('Categories')->find()->where(['id =' => $materiel->categorie_id])->first()->nom; | |
363 | - }else { | |
364 | - $categorie = ' '; | |
365 | - } | |
366 | - | |
367 | - if(isset($materiel->sous_categorie_id)) { | |
368 | - $sousCategorie = TableRegistry::get('SousCategories')->find()->where(['id =' => $materiel->sous_categorie_id])->first()->nom; | |
369 | - }else { | |
370 | - $sousCategorie = ' '; | |
371 | - } | |
372 | - | |
373 | - if(isset($materiel->groupes_thematique_id)) { | |
374 | - $groupesThematique = TableRegistry::get('GroupesThematiques')->find()->where(['id =' => $materiel->groupes_thematique_id])->first()->nom; | |
375 | - }else { | |
376 | - $groupesThematique = ' '; | |
377 | - } | |
378 | - | |
379 | - if(isset($materiel->groupes_metier_id)) { | |
380 | - $groupesMetier = TableRegistry::get('GroupesMetiers')->find()->where(['id =' => $materiel->groupes_metier_id])->first()->nom; | |
381 | - }else { | |
382 | - $groupesMetier = ' '; | |
383 | - } | |
384 | - | |
385 | - if(isset($materiel->organisme_id)) { | |
386 | - $organisme = TableRegistry::get('Organismes')->find()->where(['id =' => $materiel->organisme_id])->first()->nom; | |
387 | - }else { | |
388 | - $organisme = ' '; | |
389 | - } | |
390 | - | |
391 | - if(isset($materiel->site_id)) { | |
392 | - $site = TableRegistry::get('Sites')->find()->where(['id =' => $materiel->site_id])->first()->nom; | |
393 | - }else { | |
394 | - $site = ' '; | |
395 | - } | |
396 | - $configuration=TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
397 | - $nom_groupe_thematique = $configuration->nom_groupe_thematique; | |
398 | - $nom_groupe_metier = $configuration->nom_groupe_metier; | |
399 | - | |
400 | - | |
401 | - // set the data materiel for the document (accessible par $materiel dans le document) | |
402 | - $this->set(compact('materiel', 'surCategorie', 'categorie', 'sousCategorie', 'groupesThematique', 'groupesMetier', 'organisme', 'site','nom_groupe_metier','nom_groupe_thematique')); | |
403 | - $this->set ( 'fpdf', new FPDF ( 'P', 'mm', 'A4' ) ); | |
404 | - } | |
405 | - | |
406 | - public function ficheMetrologique($id) { | |
407 | - | |
408 | - // Find the concerned suivi | |
409 | - $fiche = TableRegistry::get('Fichemetrologiques')->find('all', ['conditions' => ['id' => $id]])->first(); | |
410 | - $suivi = TableRegistry::get('Suivis')->find('all',['conditions' => ['id' => $fiche->suivi_id]])->first(); | |
411 | - $mesures = TableRegistry::get('Mesures')->find('all',['conditions' => ['fichemetrologique_id' => $fiche->id]]); | |
412 | - if(isset($suivi->unite_id)) { | |
413 | - $unite = TableRegistry::get('Unites')->find()->where(['id =' => $suivi->unite_id])->first()->nom; | |
414 | - } | |
415 | - else{ | |
416 | - $unite = ' '; | |
417 | - } | |
418 | - if(isset($suivi->unite_id)) { | |
419 | - $symbole = TableRegistry::get('Unites')->find()->where(['id =' => $suivi->unite_id])->first()->symbole; | |
420 | - } | |
421 | - else{ | |
422 | - $symbole = ' '; | |
423 | - } | |
424 | - | |
425 | - // set the data materiel for the document (accessible par $materiel dans le document) | |
426 | - $this->set(compact('suivi', 'unite','fiche', 'symbole','mesures')); | |
427 | - $this->set ( 'fpdf', new FPDF ( 'P', 'mm', 'A4' ) ); | |
428 | - | |
429 | - } | |
474 | + | |
475 | + // Find the concerned materiel | |
476 | + $materiel = TableRegistry::get('Materiels')->find('all', [ | |
477 | + 'conditions' => [ | |
478 | + 'numero_laboratoire' => $labNumber | |
479 | + ] | |
480 | + ])->first(); // End find | |
481 | + | |
482 | + if (isset($materiel->sur_categorie_id)) { | |
483 | + $surCategorie = TableRegistry::get('SurCategories')->find()->where([ | |
484 | + 'id =' => $materiel->sur_categorie_id | |
485 | + ])->first()->nom; | |
486 | + } else { | |
487 | + $surCategorie = ' '; | |
488 | + } | |
489 | + | |
490 | + if (isset($materiel->categorie_id)) { | |
491 | + $categorie = TableRegistry::get('Categories')->find()->where([ | |
492 | + 'id =' => $materiel->categorie_id | |
493 | + ])->first()->nom; | |
494 | + } else { | |
495 | + $categorie = ' '; | |
496 | + } | |
497 | + | |
498 | + if (isset($materiel->sous_categorie_id)) { | |
499 | + $sousCategorie = TableRegistry::get('SousCategories')->find()->where([ | |
500 | + 'id =' => $materiel->sous_categorie_id | |
501 | + ])->first()->nom; | |
502 | + } else { | |
503 | + $sousCategorie = ' '; | |
504 | + } | |
505 | + | |
506 | + if (isset($materiel->groupes_thematique_id)) { | |
507 | + $groupesThematique = TableRegistry::get('GroupesThematiques')->find()->where([ | |
508 | + 'id =' => $materiel->groupes_thematique_id | |
509 | + ])->first()->nom; | |
510 | + } else { | |
511 | + $groupesThematique = ' '; | |
512 | + } | |
513 | + | |
514 | + if (isset($materiel->groupes_metier_id)) { | |
515 | + $groupesMetier = TableRegistry::get('GroupesMetiers')->find()->where([ | |
516 | + 'id =' => $materiel->groupes_metier_id | |
517 | + ])->first()->nom; | |
518 | + } else { | |
519 | + $groupesMetier = ' '; | |
520 | + } | |
521 | + | |
522 | + if (isset($materiel->organisme_id)) { | |
523 | + $organisme = TableRegistry::get('Organismes')->find()->where([ | |
524 | + 'id =' => $materiel->organisme_id | |
525 | + ])->first()->nom; | |
526 | + } else { | |
527 | + $organisme = ' '; | |
528 | + } | |
529 | + | |
530 | + if (isset($materiel->site_id)) { | |
531 | + $site = TableRegistry::get('Sites')->find()->where([ | |
532 | + 'id =' => $materiel->site_id | |
533 | + ])->first()->nom; | |
534 | + } else { | |
535 | + $site = ' '; | |
536 | + } | |
537 | + $configuration = TableRegistry::get('Configurations')->find()->where([ | |
538 | + 'id =' => 1 | |
539 | + ])->first(); | |
540 | + $nom_groupe_thematique = $configuration->nom_groupe_thematique; | |
541 | + $nom_groupe_metier = $configuration->nom_groupe_metier; | |
542 | + | |
543 | + // set the data materiel for the document (accessible par $materiel dans le document) | |
544 | + $this->set(compact('materiel', 'surCategorie', 'categorie', 'sousCategorie', 'groupesThematique', 'groupesMetier', 'organisme', 'site', 'nom_groupe_metier', 'nom_groupe_thematique')); | |
545 | + $this->set('fpdf', new FPDF('P', 'mm', 'A4')); | |
546 | + } | |
547 | + | |
548 | + public function ficheMetrologique($id) { | |
549 | + | |
550 | + // Find the concerned suivi | |
551 | + $fiche = TableRegistry::get('Fichemetrologiques')->find('all', [ | |
552 | + 'conditions' => [ | |
553 | + 'id' => $id | |
554 | + ] | |
555 | + ])->first(); | |
556 | + $suivi = TableRegistry::get('Suivis')->find('all', [ | |
557 | + 'conditions' => [ | |
558 | + 'id' => $fiche->suivi_id | |
559 | + ] | |
560 | + ])->first(); | |
561 | + $mesures = TableRegistry::get('Mesures')->find('all', [ | |
562 | + 'conditions' => [ | |
563 | + 'fichemetrologique_id' => $fiche->id | |
564 | + ] | |
565 | + ]); | |
566 | + if (isset($suivi->unite_id)) { | |
567 | + $unite = TableRegistry::get('Unites')->find()->where([ | |
568 | + 'id =' => $suivi->unite_id | |
569 | + ])->first()->nom; | |
570 | + } else { | |
571 | + $unite = ' '; | |
572 | + } | |
573 | + if (isset($suivi->unite_id)) { | |
574 | + $symbole = TableRegistry::get('Unites')->find()->where([ | |
575 | + 'id =' => $suivi->unite_id | |
576 | + ])->first()->symbole; | |
577 | + } else { | |
578 | + $symbole = ' '; | |
579 | + } | |
580 | + | |
581 | + // set the data materiel for the document (accessible par $materiel dans le document) | |
582 | + $this->set(compact('suivi', 'unite', 'fiche', 'symbole', 'mesures')); | |
583 | + $this->set('fpdf', new FPDF('P', 'mm', 'A4')); | |
584 | + } | |
430 | 585 | } | ... | ... |
src/Controller/MaterielsController.php
... | ... | @@ -29,11 +29,9 @@ class MaterielsController extends AppController { |
29 | 29 | public function isAuthorized($user) { |
30 | 30 | $configuration = $this->confLabinvent; |
31 | 31 | // $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); |
32 | - $role = TableRegistry::get('Users')->find() | |
33 | - ->where([ | |
32 | + $role = TableRegistry::get('Users')->find()->where([ | |
34 | 33 | 'username' => $user[$configuration->authentificationType_ldap][0] |
35 | - ]) | |
36 | - ->first()['role']; | |
34 | + ])->first()['role']; | |
37 | 35 | $this->role = $role; |
38 | 36 | $action = $this->request->params['action']; |
39 | 37 | |
... | ... | @@ -140,26 +138,20 @@ class MaterielsController extends AppController { |
140 | 138 | } |
141 | 139 | |
142 | 140 | public function isRespGroup($id, $loginResponsable) { |
143 | - $u = TableRegistry::get('Users')->find() | |
144 | - ->where([ | |
141 | + $u = TableRegistry::get('Users')->find()->where([ | |
145 | 142 | 'username' => $loginResponsable |
146 | - ]) | |
147 | - ->first(); | |
143 | + ])->first(); | |
148 | 144 | |
149 | - if (isset($u['groupes_metier_id']) && $u['groupes_metier_id'] != TableRegistry::get('GroupesMetiers')->find() | |
150 | - ->where([ | |
145 | + if (isset($u['groupes_metier_id']) && $u['groupes_metier_id'] != TableRegistry::get('GroupesMetiers')->find()->where([ | |
151 | 146 | 'nom =' => 'N/A' |
152 | - ]) | |
153 | - ->first()['id']) { | |
147 | + ])->first()['id']) { | |
154 | 148 | return ($this->Materiels->exists([ |
155 | 149 | 'id' => $id, |
156 | 150 | 'groupes_metier_id' => $u['groupes_metier_id'] |
157 | 151 | ])); |
158 | - } else if (isset($u['groupe_thematique_id']) && $u['groupe_thematique_id'] != TableRegistry::get('GroupesThematiques')->find() | |
159 | - ->where([ | |
152 | + } else if (isset($u['groupe_thematique_id']) && $u['groupe_thematique_id'] != TableRegistry::get('GroupesThematiques')->find()->where([ | |
160 | 153 | 'nom =' => 'N/A' |
161 | - ]) | |
162 | - ->first()['id']) { | |
154 | + ])->first()['id']) { | |
163 | 155 | return ($this->Materiels->exists([ |
164 | 156 | 'id' => $id, |
165 | 157 | 'groupes_thematique_id' => $u['groupe_thematique_id'] |
... | ... | @@ -203,7 +195,7 @@ class MaterielsController extends AppController { |
203 | 195 | * @return \Cake\Network\Response|null |
204 | 196 | */ |
205 | 197 | public function index() { |
206 | - // Remplacement de $this->request->params['pass'][0] (deprecated) | |
198 | + // Remplacement de $this->passedArgs[0] (deprecated) | |
207 | 199 | // Par $this->request->params['pass'][0] |
208 | 200 | $condition = ''; |
209 | 201 | if (isset($this->request->params['pass'][0])) { |
... | ... | @@ -216,20 +208,16 @@ class MaterielsController extends AppController { |
216 | 208 | $GM = $this->request->query('GM'); |
217 | 209 | $GT = $this->request->query('GT'); |
218 | 210 | if (isset($GM) || isset($GT)) { |
219 | - if (isset($GM) && $GM != TableRegistry::get('GroupesMetiers')->find() | |
220 | - ->where([ | |
211 | + if (isset($GM) && $GM != TableRegistry::get('GroupesMetiers')->find()->where([ | |
221 | 212 | 'nom =' => 'N/A' |
222 | - ]) | |
223 | - ->first()['id']) { | |
213 | + ])->first()['id']) { | |
224 | 214 | $condition = [ |
225 | 215 | 'Materiels.groupes_metier_id =' => $GM, |
226 | 216 | 'Materiels.status !=' => 'ARCHIVED' |
227 | 217 | ]; |
228 | - } else if (isset($GT) && $GT != TableRegistry::get('GroupesThematiques')->find() | |
229 | - ->where([ | |
218 | + } else if (isset($GT) && $GT != TableRegistry::get('GroupesThematiques')->find()->where([ | |
230 | 219 | 'nom =' => 'N/A' |
231 | - ]) | |
232 | - ->first()['id']) { | |
220 | + ])->first()['id']) { | |
233 | 221 | $condition = [ |
234 | 222 | 'Materiels.groupes_thematique_id =' => $GT, |
235 | 223 | 'Materiels.status !=' => 'ARCHIVED' |
... | ... | @@ -244,21 +232,17 @@ class MaterielsController extends AppController { |
244 | 232 | $GMV = $this->request->query('GMV'); |
245 | 233 | $GTV = $this->request->query('GTV'); |
246 | 234 | if (isset($GMV) || isset($GTV)) { |
247 | - if (isset($GMV) && $GMV != TableRegistry::get('GroupesMetiers')->find() | |
248 | - ->where([ | |
235 | + if (isset($GMV) && $GMV != TableRegistry::get('GroupesMetiers')->find()->where([ | |
249 | 236 | 'nom =' => 'N/A' |
250 | - ]) | |
251 | - ->first()['id']) { | |
237 | + ])->first()['id']) { | |
252 | 238 | $condition = [ |
253 | 239 | 'Materiels.groupes_metier_id =' => $GMV, |
254 | 240 | 'Materiels.status =' => 'CREATED', |
255 | 241 | 'Materiels.status !=' => 'ARCHIVED' |
256 | 242 | ]; |
257 | - } else if (isset($GTV) && $GTV != TableRegistry::get('GroupesThematiques')->find() | |
258 | - ->where([ | |
243 | + } else if (isset($GTV) && $GTV != TableRegistry::get('GroupesThematiques')->find()->where([ | |
259 | 244 | 'nom =' => 'N/A' |
260 | - ]) | |
261 | - ->first()['id']) { | |
245 | + ])->first()['id']) { | |
262 | 246 | $condition = [ |
263 | 247 | 'Materiels.groupes_metier_id =' => $GTV, |
264 | 248 | 'Materiels.status =' => 'CREATED', |
... | ... | @@ -297,11 +281,9 @@ class MaterielsController extends AppController { |
297 | 281 | ]; |
298 | 282 | } |
299 | 283 | |
300 | - $config = TableRegistry::get('Configurations')->find() | |
301 | - ->where([ | |
284 | + $config = TableRegistry::get('Configurations')->find()->where([ | |
302 | 285 | 'id =' => 1 |
303 | - ]) | |
304 | - ->first(); | |
286 | + ])->first(); | |
305 | 287 | $limit = $this->request->query('aff'); |
306 | 288 | if (! isset($limit)) |
307 | 289 | $limit = $config['aff_par_defaut']; |
... | ... | @@ -328,8 +310,7 @@ class MaterielsController extends AppController { |
328 | 310 | |
329 | 311 | $this->set('nbMateriels', $this->Materiels->find('all', [ |
330 | 312 | 'conditions' => $condition |
331 | - ]) | |
332 | - ->count()); | |
313 | + ])->count()); | |
333 | 314 | |
334 | 315 | $this->set(compact('materiels')); |
335 | 316 | $this->set('_serialize', [ |
... | ... | @@ -346,6 +327,7 @@ class MaterielsController extends AppController { |
346 | 327 | * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. |
347 | 328 | */ |
348 | 329 | public function view($id = null) { |
330 | + var_dump($this); | |
349 | 331 | $materiel = $this->Materiels->get($id, [ |
350 | 332 | 'contain' => [ |
351 | 333 | 'SurCategories', |
... | ... | @@ -394,16 +376,12 @@ class MaterielsController extends AppController { |
394 | 376 | if (in_array($_SESSION['Auth']['User']['sn'][0], TableRegistry::get('Users')->find('list', [ |
395 | 377 | 'keyField' => 'id', |
396 | 378 | 'valueField' => 'nom' |
397 | - ]) | |
398 | - ->where([ | |
379 | + ])->where([ | |
399 | 380 | 'role =' => 'Administration' |
400 | - ]) | |
401 | - ->toArray())) { | |
402 | - $gestionnaireID = TableRegistry::get('Users')->find() | |
403 | - ->where([ | |
381 | + ])->toArray())) { | |
382 | + $gestionnaireID = TableRegistry::get('Users')->find()->where([ | |
404 | 383 | 'nom' => $_SESSION['Auth']['User']['sn'][0] |
405 | - ]) | |
406 | - ->first()->id; | |
384 | + ])->first()->id; | |
407 | 385 | $materiel->gestionnaire_id = $gestionnaireID; |
408 | 386 | } |
409 | 387 | if ($this->Materiels->save($materiel)) { |
... | ... | @@ -481,13 +459,9 @@ class MaterielsController extends AppController { |
481 | 459 | 'order' => 'designation', |
482 | 460 | 'group' => 'designation' |
483 | 461 | ]); |
484 | - $domaineresp = TableRegistry::get('Users')->find() | |
485 | - ->select('sur_categorie_id') | |
486 | - ->where([ | |
487 | - 'username =' => $this->LdapAuth->user($this->request->session() | |
488 | - ->read('authType'))[0] | |
489 | - ]) | |
490 | - ->first()['sur_categorie_id']; | |
462 | + $domaineresp = TableRegistry::get('Users')->find()->select('sur_categorie_id')->where([ | |
463 | + 'username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0] | |
464 | + ])->first()['sur_categorie_id']; | |
491 | 465 | $utilisateurconnect = TableRegistry::get('Users')->find('all')->toArray(); |
492 | 466 | $users = TableRegistry::get('LdapConnections')->getListUsers(); |
493 | 467 | |
... | ... | @@ -499,13 +473,9 @@ class MaterielsController extends AppController { |
499 | 473 | } |
500 | 474 | |
501 | 475 | // Ne pas commenter la ligne suivante, on en a besoin dans add.cpt |
502 | - $mail_responsable = TableRegistry::get('Users')->find() | |
503 | - ->select('email') | |
504 | - ->where([ | |
505 | - 'username =' => $this->LdapAuth->user($this->request->session() | |
506 | - ->read('authType'))[0] | |
507 | - ]) | |
508 | - ->first()['email']; | |
476 | + $mail_responsable = TableRegistry::get('Users')->find()->select('email')->where([ | |
477 | + 'username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0] | |
478 | + ])->first()['email']; | |
509 | 479 | |
510 | 480 | if (isset($this->request->params['pass'][0])) { |
511 | 481 | $cpMateriel = $this->Materiels->get($this->request->params['pass'][0]); |
... | ... | @@ -539,16 +509,12 @@ class MaterielsController extends AppController { |
539 | 509 | if (in_array($_SESSION['Auth']['User']['sn'][0], TableRegistry::get('Users')->find('list', [ |
540 | 510 | 'keyField' => 'id', |
541 | 511 | 'valueField' => 'nom' |
542 | - ]) | |
543 | - ->where([ | |
512 | + ])->where([ | |
544 | 513 | 'role =' => 'Administration' |
545 | - ]) | |
546 | - ->toArray())) { | |
547 | - $gestionnaireID = TableRegistry::get('Users')->find() | |
548 | - ->where([ | |
514 | + ])->toArray())) { | |
515 | + $gestionnaireID = TableRegistry::get('Users')->find()->where([ | |
549 | 516 | 'nom' => $_SESSION['Auth']['User']['sn'][0] |
550 | - ]) | |
551 | - ->first()->id; | |
517 | + ])->first()->id; | |
552 | 518 | $materiel->gestionnaire_id = $gestionnaireID; |
553 | 519 | } |
554 | 520 | if ($this->Materiels->save($materiel)) { |
... | ... | @@ -640,26 +606,15 @@ class MaterielsController extends AppController { |
640 | 606 | 'valueField' => 'nom', |
641 | 607 | 'order' => 'Fournisseurs.nom' |
642 | 608 | ]); |
643 | - $dom = TableRegistry::get('Materiels')->find() | |
644 | - ->select('sur_categorie_id') | |
645 | - ->where([ | |
609 | + $dom = TableRegistry::get('Materiels')->find()->select('sur_categorie_id')->where([ | |
646 | 610 | 'id =' => $materiel->id |
647 | - ]) | |
648 | - ->first()['sur_categorie_id']; | |
649 | - $domaines = TableRegistry::get('Users')->find() | |
650 | - ->select('sur_categorie_id') | |
651 | - ->where([ | |
652 | - 'username =' => $this->LdapAuth->user($this->request->session() | |
653 | - ->read('authType'))[0] | |
654 | - ]) | |
655 | - ->first()['sur_categorie_id']; | |
656 | - $role = TableRegistry::get('Users')->find() | |
657 | - ->select('role') | |
658 | - ->where([ | |
659 | - 'username =' => $this->LdapAuth->user($this->request->session() | |
660 | - ->read('authType'))[0] | |
661 | - ]) | |
662 | - ->first()['role']; | |
611 | + ])->first()['sur_categorie_id']; | |
612 | + $domaines = TableRegistry::get('Users')->find()->select('sur_categorie_id')->where([ | |
613 | + 'username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0] | |
614 | + ])->first()['sur_categorie_id']; | |
615 | + $role = TableRegistry::get('Users')->find()->select('role')->where([ | |
616 | + 'username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0] | |
617 | + ])->first()['role']; | |
663 | 618 | |
664 | 619 | if ($dom == $domaines) |
665 | 620 | $domaineresp = true; |
... | ... | @@ -680,13 +635,9 @@ class MaterielsController extends AppController { |
680 | 635 | $this->set(compact('nom_ancien_responsable')); |
681 | 636 | } |
682 | 637 | } |
683 | - $mail_responsable = TableRegistry::get('Users')->find() | |
684 | - ->select('email') | |
685 | - ->where([ | |
686 | - 'username =' => $this->LdapAuth->user($this->request->session() | |
687 | - ->read('authType'))[0] | |
688 | - ]) | |
689 | - ->first()['email']; | |
638 | + $mail_responsable = TableRegistry::get('Users')->find()->select('email')->where([ | |
639 | + 'username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0] | |
640 | + ])->first()['email']; | |
690 | 641 | |
691 | 642 | // Fonction utilisée dans la vue, déclarée ici pour éviter les problèmes de tests |
692 | 643 | $isReadonlyField = function ($fieldName, $myReadonlyFields) { |
... | ... | @@ -798,13 +749,9 @@ class MaterielsController extends AppController { |
798 | 749 | $this->set(compact('nom_ancien_responsable')); |
799 | 750 | } |
800 | 751 | } |
801 | - $mail_responsable = TableRegistry::get('Users')->find() | |
802 | - ->select('email') | |
803 | - ->where([ | |
804 | - 'username =' => $this->LdapAuth->user($this->request->session() | |
805 | - ->read('authType'))[0] | |
806 | - ]) | |
807 | - ->first()['email']; | |
752 | + $mail_responsable = TableRegistry::get('Users')->find()->select('email')->where([ | |
753 | + 'username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0] | |
754 | + ])->first()['email']; | |
808 | 755 | |
809 | 756 | $this->set('IS_CREATED', $materiel->status == 'CREATED'); |
810 | 757 | $this->set('IS_VALIDATED', $materiel->status == 'VALIDATED'); |
... | ... | @@ -902,16 +849,12 @@ class MaterielsController extends AppController { |
902 | 849 | if (in_array($_SESSION['Auth']['User']['sn'][0], TableRegistry::get('Users')->find('list', [ |
903 | 850 | 'keyField' => 'id', |
904 | 851 | 'valueField' => 'nom' |
905 | - ]) | |
906 | - ->where([ | |
852 | + ])->where([ | |
907 | 853 | 'role =' => 'Administration' |
908 | - ]) | |
909 | - ->toArray())) { | |
910 | - $gestionnaireID = TableRegistry::get('Users')->find() | |
911 | - ->where([ | |
854 | + ])->toArray())) { | |
855 | + $gestionnaireID = TableRegistry::get('Users')->find()->where([ | |
912 | 856 | 'nom' => $_SESSION['Auth']['User']['sn'][0] |
913 | - ]) | |
914 | - ->first()->id; | |
857 | + ])->first()->id; | |
915 | 858 | $materiel->gestionnaire_id = $gestionnaireID; |
916 | 859 | } |
917 | 860 | $this->sendEmail($this->Materiels->get($id)); |
... | ... | @@ -1476,11 +1419,9 @@ else if (isset($resultTri) && strstr($this->request->here(), 'sort') != false && |
1476 | 1419 | 'Content-Disposition: attachment; filename="' . $filename . '"' |
1477 | 1420 | ]); |
1478 | 1421 | $this->response->sendHeaders(); |
1479 | - $configuration = TableRegistry::get('Configurations')->find() | |
1480 | - ->where([ | |
1422 | + $configuration = TableRegistry::get('Configurations')->find()->where([ | |
1481 | 1423 | 'id =' => 1 |
1482 | - ]) | |
1483 | - ->first(); | |
1424 | + ])->first(); | |
1484 | 1425 | $nomgroupemetier = $configuration->nom_groupe_metier; |
1485 | 1426 | $nomgroupethematique = $configuration->nom_groupe_thematique; |
1486 | 1427 | ... | ... |
src/Template/Materiels/view.ctp
... | ... | @@ -21,7 +21,7 @@ use Cake\ORM\TableRegistry; |
21 | 21 | <?=h($materiel->numero_laboratoire)?> |
22 | 22 | <?php |
23 | 23 | |
24 | -if (h($materiel->status) == 'ARCHIVED') | |
24 | + if (h($materiel->status) == 'ARCHIVED') | |
25 | 25 | echo ' (Archivé)'; |
26 | 26 | ?> |
27 | 27 | </span> |
... | ... | @@ -38,8 +38,7 @@ if (h($materiel->status) == 'ARCHIVED') |
38 | 38 | // Url transformé en QrCode |
39 | 39 | $this->request->session()->write("qrUrl", $this->request->env('SERVER_NAME') . $this->request->env('REQUEST_URI')); |
40 | 40 | $this->requestAction('/QrCodes/creer/'); |
41 | - echo $this->Html->image('qrcodes/' . $this->request->session() | |
42 | - ->read("filename"), [ | |
41 | + echo $this->Html->image('qrcodes/' . $this->request->session()->read("filename"), [ | |
43 | 42 | 'alt' => 'QrCode : ' . $materiel->numero_laboratoire, |
44 | 43 | 'style' => 'float: right' |
45 | 44 | ]); |
... | ... | @@ -97,7 +96,7 @@ if (h($materiel->status) == 'ARCHIVED') |
97 | 96 | 'style' => 'margin-right: 10px', |
98 | 97 | 'escape' => false |
99 | 98 | ]); // End link |
100 | - // BOUTON NOUVEL EMPRUNT | |
99 | + // BOUTON NOUVEL EMPRUNT | |
101 | 100 | echo $this->Html->link('<i class="icon-plus"></i> Nouv. Emprunt', [ |
102 | 101 | 'controller' => 'emprunts', |
103 | 102 | 'action' => 'add', |
... | ... | @@ -410,7 +409,7 @@ if (in_array($role, [ |
410 | 409 | |
411 | 410 | <?php |
412 | 411 | |
413 | -if (! empty($materiel->suivis)) { | |
412 | + if (! empty($materiel->suivis)) { | |
414 | 413 | ?> |
415 | 414 | <table> |
416 | 415 | <tr> |
... | ... | @@ -424,7 +423,7 @@ if (! empty($materiel->suivis)) { |
424 | 423 | </tr> |
425 | 424 | <?php |
426 | 425 | |
427 | -foreach ($materiel->suivis as $suivis) : | |
426 | + foreach ($materiel->suivis as $suivis) : | |
428 | 427 | ?> |
429 | 428 | <tr> |
430 | 429 | |
... | ... | @@ -442,8 +441,7 @@ foreach ($materiel->suivis as $suivis) : |
442 | 441 | <?=$this->Html->link(__('<i class="icon-pencil"></i>'), ['controller' => 'Suivis','action' => 'edit',$suivis->id], ['escape' => false,'style' => 'margin:0'])?> |
443 | 442 | <?=$this->Form->postLink(__('<i class="icon-trash"></i>'), ['controller' => 'Suivis','action' => 'delete',$suivis->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $suivis->id)])?> |
444 | 443 | <?php |
445 | - | |
446 | -} | |
444 | + } | |
447 | 445 | ?> |
448 | 446 | </td> |
449 | 447 | <td><?=$this->Html->link('Suivi ' . $suivis->id, ['controller' => 'suivis','action' => 'view',$suivis->id])?></td> |
... | ... | @@ -454,14 +452,12 @@ foreach ($materiel->suivis as $suivis) : |
454 | 452 | <td><?=h($suivis->statut)?></td> |
455 | 453 | </tr> |
456 | 454 | <?php |
457 | - | |
458 | -endforeach | |
455 | + endforeach | |
459 | 456 | ; |
460 | 457 | ?> |
461 | 458 | </table> |
462 | 459 | <?php |
463 | - | |
464 | -} else { | |
460 | + } else { | |
465 | 461 | echo 'Aucun suivi pour ce matériel.'; |
466 | 462 | } |
467 | 463 | ?> |
... | ... | @@ -477,7 +473,7 @@ endforeach |
477 | 473 | |
478 | 474 | <?php |
479 | 475 | |
480 | -if (! empty($materiel->emprunts)) { | |
476 | + if (! empty($materiel->emprunts)) { | |
481 | 477 | ?> |
482 | 478 | <table> |
483 | 479 | <tr> |
... | ... | @@ -495,11 +491,9 @@ if (! empty($materiel->emprunts)) { |
495 | 491 | $lieu = $emprunts['laboratoire']; |
496 | 492 | if ($emprunts['emprunt_interne'] == 1) { |
497 | 493 | $type = 'Interne'; |
498 | - $lieu = $sites->find() | |
499 | - ->where([ | |
494 | + $lieu = $sites->find()->where([ | |
500 | 495 | 'id =' => h($emprunts->site_id) |
501 | - ]) | |
502 | - ->first()['nom'] . '-' . h($emprunts->e_lieu_detail); | |
496 | + ])->first()['nom'] . '-' . h($emprunts->e_lieu_detail); | |
503 | 497 | } |
504 | 498 | ?> |
505 | 499 | <tr> |
... | ... | @@ -518,8 +512,7 @@ if (! empty($materiel->emprunts)) { |
518 | 512 | <?=$this->Html->link(__('<i class="icon-pencil"></i>'), ['controller' => 'Emprunts','action' => 'edit',$emprunts->id], ['escape' => false,'style' => 'margin:0'])?> |
519 | 513 | <?=$this->Form->postLink(__('<i class="icon-trash"></i>'), ['controller' => 'Emprunts','action' => 'delete',$emprunts->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $emprunts->id)])?> |
520 | 514 | <?php |
521 | - | |
522 | -} | |
515 | + } | |
523 | 516 | ?> |
524 | 517 | </td> |
525 | 518 | <td><?=$this->Html->link('Emprunt ' . $emprunts->id, ['controller' => 'emprunts','action' => 'view',$emprunts->id])?></td> |
... | ... | @@ -531,14 +524,12 @@ if (! empty($materiel->emprunts)) { |
531 | 524 | |
532 | 525 | </tr> |
533 | 526 | <?php |
534 | - | |
535 | -endforeach | |
527 | + endforeach | |
536 | 528 | ; |
537 | 529 | ?> |
538 | 530 | </table> |
539 | 531 | <?php |
540 | - | |
541 | -} else { | |
532 | + } else { | |
542 | 533 | echo 'Aucun emprunt pour ce matériel.'; |
543 | 534 | } |
544 | 535 | ?> |
... | ... | @@ -558,7 +549,7 @@ endforeach |
558 | 549 | |
559 | 550 | <?php |
560 | 551 | |
561 | -if ($nbFic != 0) { | |
552 | + if ($nbFic != 0) { | |
562 | 553 | ?> |
563 | 554 | <table> |
564 | 555 | <tr> |
... | ... | @@ -574,11 +565,9 @@ if ($nbFic != 0) { |
574 | 565 | } else { |
575 | 566 | $p = ''; |
576 | 567 | } |
577 | - $type = $typeDocuments->find() | |
578 | - ->where([ | |
568 | + $type = $typeDocuments->find()->where([ | |
579 | 569 | 'id =' => h($documents->type_document_id) |
580 | - ]) | |
581 | - ->first()['nom']; | |
570 | + ])->first()['nom']; | |
582 | 571 | ?> |
583 | 572 | <tr> |
584 | 573 | |
... | ... | @@ -609,8 +598,7 @@ if ($nbFic != 0) { |
609 | 598 | <?=$this->Html->link(__('<i class="icon-pencil"></i>'), ['controller' => 'Documents','action' => 'edit',$documents->id], ['escape' => false,'style' => 'margin:0'])?> |
610 | 599 | <?=$this->Form->postLink(__('<i class="icon-trash"></i>'), ['controller' => 'Documents','action' => 'delete',$documents->id], ['escape' => false,'style' => 'margin:0','confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $documents->id)])?> |
611 | 600 | <?php |
612 | - | |
613 | -} | |
601 | + } | |
614 | 602 | ?> |
615 | 603 | </td> |
616 | 604 | <td><?=$this->Html->link($documents->nom, ['controller' => 'documents','action' => 'view',$documents->id])?></td> |
... | ... | @@ -619,14 +607,12 @@ if ($nbFic != 0) { |
619 | 607 | |
620 | 608 | </tr> |
621 | 609 | <?php |
622 | - | |
623 | -endforeach | |
610 | + endforeach | |
624 | 611 | ; |
625 | 612 | ?> |
626 | 613 | </table> |
627 | 614 | <?php |
628 | - | |
629 | -} else { | |
615 | + } else { | |
630 | 616 | echo 'Aucun fichier pour ce matériel.'; |
631 | 617 | } |
632 | 618 | ?> | ... | ... |