Commit aaf7558a528aeeac9b244e16c1d7de426e70ac01

Authored by Thibaud Ajas
1 parent 7e8c1ba2

modifications de lisibilité mineures du code

src/Controller/AppController.php
@@ -61,34 +61,24 @@ class AppController extends Controller { @@ -61,34 +61,24 @@ class AppController extends Controller {
61 $this->loadComponent('RequestHandler'); 61 $this->loadComponent('RequestHandler');
62 $this->loadComponent('Flash'); 62 $this->loadComponent('Flash');
63 $this->loadComponent('LdapAuth', [ 63 $this->loadComponent('LdapAuth', [
64 - 'authorize' => [  
65 - 'Controller'  
66 - ],  
67 - 'loginRedirect' => [  
68 - 'controller' => 'Pages',  
69 - 'action' => 'home'  
70 - ],  
71 - 'logoutRedirect' => [  
72 - 'controller' => 'Pages',  
73 - 'action' => 'home'  
74 - ] 64 + 'authorize' => [ 'Controller'],
  65 + 'loginRedirect' => ['controller' => 'Pages', 'action' => 'home'],
  66 + 'logoutRedirect' => ['controller' => 'Pages', 'action' => 'home' ]
75 ]); 67 ]);
76 - $this->confLabinvent = TableRegistry::get('Configurations')->find()->where([  
77 - 'id =' => 1  
78 - ])->first(); 68 + // On charge la configuration
  69 + $this->confLabinvent = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first();
79 } 70 }
80 71
81 /** 72 /**
82 - *  
83 - * @param $user Give  
84 - * authorization in general 73 + * @param $user
  74 + * Give authorization in general
85 * @return boolean 75 * @return boolean
86 */ 76 */
87 public function isAuthorized($user) { 77 public function isAuthorized($user) {
88 $configuration = $this->confLabinvent; 78 $configuration = $this->confLabinvent;
89 - $role = TableRegistry::get('Users')->find()->where([  
90 - 'username' => $user[$configuration->authentificationType_ldap][0]  
91 - ])->first()['role']; 79 + $role = TableRegistry::get('Users')->find()
  80 + ->where(['username' => $user[$configuration->authentificationType_ldap][0]])
  81 + ->first()['role'];
92 82
93 $action = $this->request->params['action']; 83 $action = $this->request->params['action'];
94 84
@@ -99,15 +89,7 @@ class AppController extends Controller { @@ -99,15 +89,7 @@ class AppController extends Controller {
99 return true; 89 return true;
100 90
101 // ACL : Pour tout le monde 91 // ACL : Pour tout le monde
102 - if (in_array($action, [  
103 - 'index',  
104 - 'view',  
105 - 'add',  
106 - 'find',  
107 - 'creer',  
108 - 'getNextDate',  
109 - 'getDateGarantie'  
110 - ])) 92 + if (in_array($action, ['index', 'view', 'add', 'find', 'creer', 'getNextDate', 'getDateGarantie']))
111 return true; 93 return true;
112 94
113 // ACL : Par défaut refuser 95 // ACL : Par défaut refuser
@@ -115,108 +97,70 @@ class AppController extends Controller { @@ -115,108 +97,70 @@ class AppController extends Controller {
115 } 97 }
116 98
117 function userHasRole($roleDefine) { 99 function userHasRole($roleDefine) {
118 - $configuration = TableRegistry::get('Configurations')->find()->where([  
119 - 'id =' => 1  
120 - ])->first();  
121 - $role = TableRegistry::get('Users')->find()->where([  
122 - 'username' => $this->LdapAuth->user($configuration->authentificationType_ldap)[0]  
123 - ])->first()['role']; 100 + $configuration = $this->confLabinvent;
  101 + $role = TableRegistry::get('Users')->find()
  102 + ->where(['username' => $this->LdapAuth->user($configuration->authentificationType_ldap)[0]])
  103 + ->first()['role'];
124 104
125 $isAuthorized = false; 105 $isAuthorized = false;
126 106
127 switch ($roleDefine) { 107 switch ($roleDefine) {
128 case 'Super Administrateur' : 108 case 'Super Administrateur' :
129 - if (in_array($role, [  
130 - 'Super Administrateur'  
131 - ])) 109 + if (in_array($role, ['Super Administrateur']))
132 $isAuthorized = true; 110 $isAuthorized = true;
133 break; 111 break;
134 112
135 case 'Administration Plus' : 113 case 'Administration Plus' :
136 - if (in_array($role, [  
137 - 'Administration Plus',  
138 - 'Super Administrateur'  
139 - ])) 114 + if (in_array($role, ['Administration Plus', 'Super Administrateur']))
140 $isAuthorized = true; 115 $isAuthorized = true;
141 break; 116 break;
142 117
143 case 'Administration' : 118 case 'Administration' :
144 - if (in_array($role, [  
145 - 'Administration',  
146 - 'Administration Plus',  
147 - 'Super Administrateur'  
148 - ])) 119 + if (in_array($role, ['Administration', 'Administration Plus', 'Super Administrateur' ]))
149 $isAuthorized = true; 120 $isAuthorized = true;
150 break; 121 break;
151 case 'Responsable' : 122 case 'Responsable' :
152 - if (in_array($role, [  
153 - 'Responsable',  
154 - 'Administration',  
155 - 'Administration Plus',  
156 - 'Super Administrateur'  
157 - ])) 123 + if (in_array($role, ['Responsable', 'Administration', 'Administration Plus', 'Super Administrateur']))
158 $isAuthorized = true; 124 $isAuthorized = true;
159 break; 125 break;
160 126
161 case 'Utilisateur' : 127 case 'Utilisateur' :
162 - if (in_array($role, [  
163 - 'Utilisateur',  
164 - 'Responsable',  
165 - 'Administration',  
166 - 'Administration Plus',  
167 - 'Super Administrateur'  
168 - ])) 128 + if (in_array($role, ['Utilisateur', 'Responsable', 'Administration', 'Administration Plus', 'Super Administrateur']))
169 $isAuthorized = true; 129 $isAuthorized = true;
170 break; 130 break;
171 } 131 }
172 -  
173 return $isAuthorized; 132 return $isAuthorized;
174 } 133 }
175 134
176 /** 135 /**
177 - *  
178 * {@inheritdoc} 136 * {@inheritdoc}
179 * 137 *
180 * @see \Cake\Controller\Controller::beforeFilter() 138 * @see \Cake\Controller\Controller::beforeFilter()
181 */ 139 */
182 public function beforeFilter(Event $event) { 140 public function beforeFilter(Event $event) {
183 // !!! Ne jamais autoriser l'action 'login', sinon cela va créer des problèmes sur le fonctionnement normal de AuthComponent (cf doc) !!! 141 // !!! Ne jamais autoriser l'action 'login', sinon cela va créer des problèmes sur le fonctionnement normal de AuthComponent (cf doc) !!!
184 - $configuration = TableRegistry::get('Configurations')->find()->where([  
185 - 'id =' => 1  
186 - ])->first();  
187 -  
188 - if ($configuration->mode_install) {  
189 - $this->LdapAuth->allow([  
190 - 'display',  
191 - 'add',  
192 - 'edit',  
193 - 'installOff'  
194 - ]);  
195 - } else {  
196 - $this->LdapAuth->allow([  
197 - 'display'  
198 - ]);  
199 - } 142 + $configuration = $this->confLabinvent;
  143 +
  144 + if ($configuration->mode_install)
  145 + $this->LdapAuth->allow(['display', 'add', 'edit', 'installOff']);
  146 + else
  147 + $this->LdapAuth->allow(['display']);
200 148
201 $this->LdapAuth->config('authError', "Désolé, vous n'êtes pas autorisé à accéder à cette zone."); 149 $this->LdapAuth->config('authError', "Désolé, vous n'êtes pas autorisé à accéder à cette zone.");
202 } 150 }
203 151
204 public function afterFilter(Event $event) { 152 public function afterFilter(Event $event) {
205 - if (in_array($this->request->params['action'], [  
206 - 'edit',  
207 - 'add'  
208 - ])) { 153 + if (in_array($this->request->params['action'], ['edit', 'add']))
209 $this->request->session()->write("retourForm1", true); 154 $this->request->session()->write("retourForm1", true);
210 - } else if ($this->request->params['action'] != 'creer') { 155 + else if ($this->request->params['action'] != 'creer')
211 $this->request->session()->write("retourForm1", false); 156 $this->request->session()->write("retourForm1", false);
212 - }  
213 } 157 }
214 158
215 /** 159 /**
216 * Before render callback. 160 * Before render callback.
217 * 161 *
218 - * @param \Cake\Event\Event $event  
219 - * The beforeRender event. 162 + * @param \Cake\Event\Event
  163 + * $event The beforeRender event
220 * @return void 164 * @return void
221 */ 165 */
222 public function beforeRender(Event $event) { 166 public function beforeRender(Event $event) {
@@ -228,23 +172,18 @@ class AppController extends Controller { @@ -228,23 +172,18 @@ class AppController extends Controller {
228 $this->set('PROFILE_SUPERADMIN', self::PROFILE_SUPERADMIN); 172 $this->set('PROFILE_SUPERADMIN', self::PROFILE_SUPERADMIN);
229 $this->set('allProfiles', $this->allProfiles); 173 $this->set('allProfiles', $this->allProfiles);
230 174
231 - if (! array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), [  
232 - 'application/json',  
233 - 'application/xml'  
234 - ])) { 175 + if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml' ]))
235 $this->set('_serialize', true); 176 $this->set('_serialize', true);
236 - } 177 +
237 $this->set('username', $this->LdapAuth->user('sn')[0] . ' ' . $this->LdapAuth->user('givenname')[0]); 178 $this->set('username', $this->LdapAuth->user('sn')[0] . ' ' . $this->LdapAuth->user('givenname')[0]);
238 179
239 - $configuration = TableRegistry::get('Configurations')->find()->where([  
240 - 'id =' => 1  
241 - ])->first(); 180 + $configuration = $this->confLabinvent;
242 $this->set('configuration', $configuration); 181 $this->set('configuration', $configuration);
243 $this->request->session()->write("authType", $configuration->authentificationType_ldap); 182 $this->request->session()->write("authType", $configuration->authentificationType_ldap);
244 183
245 - $user = TableRegistry::get('Users')->find()->where([  
246 - 'username' => $this->LdapAuth->user($configuration->authentificationType_ldap)[0]  
247 - ])->first(); 184 + $user = TableRegistry::get('Users')->find()
  185 + ->where(['username' => $this->LdapAuth->user($configuration->authentificationType_ldap)[0]])
  186 + ->first();
248 187
249 $role = $user['role']; 188 $role = $user['role'];
250 if ($role == null) 189 if ($role == null)
@@ -274,12 +213,8 @@ class AppController extends Controller { @@ -274,12 +213,8 @@ class AppController extends Controller {
274 213
275 $this->set('userConnected', $user); 214 $this->set('userConnected', $user);
276 215
277 - $this->set('idGmNa', TableRegistry::get('GroupesMetiers')->find()->where([  
278 - 'nom =' => 'N/A'  
279 - ])->first()['id']);  
280 - $this->set('idGtNa', TableRegistry::get('GroupesThematiques')->find()->where([  
281 - 'nom =' => 'N/A'  
282 - ])->first()['id']); 216 + $this->set('idGmNa', TableRegistry::get('GroupesMetiers')->find()->where(['nom =' => 'N/A'])->first()['id']);
  217 + $this->set('idGtNa', TableRegistry::get('GroupesThematiques')->find()->where(['nom =' => 'N/A'])->first()['id']);
283 218
284 $displayElement = function ($nom, $valeur, $params = "") { 219 $displayElement = function ($nom, $valeur, $params = "") {
285 $balise = ($params != "") ? '<td ' . $params . '>' : '<td>'; 220 $balise = ($params != "") ? '<td ' . $params . '>' : '<td>';
@@ -291,208 +226,9 @@ class AppController extends Controller { @@ -291,208 +226,9 @@ class AppController extends Controller {
291 } 226 }
292 227
293 // "le materiel", "le suivi"... 228 // "le materiel", "le suivi"...
294 - protected function getArticle() {  
295 - return "Le ";  
296 - }  
297 -  
298 - /**  
299 - *  
300 - * @param string $subject  
301 - * @param string $message  
302 - * @param string[] $to  
303 - */  
304 - // public function sendEmailTo($subject, $message, $to = null) {  
305 -  
306 - // $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first();  
307 -  
308 - // if ($to != null && !$configuration->test) {  
309 -  
310 - // for($i = 0; $i < sizeof($to); $i++) {  
311 -  
312 - // if (filter_var($to[$i], FILTER_VALIDATE_EMAIL)) {  
313 - // $email = new Email();  
314 -  
315 - // $etiquetteFrom = explode("@", $configuration->sender_mail);  
316 -  
317 - // if($configuration->envoi_mail_management_dev) {  
318 - // $email->transport('dev')  
319 - // ->from([$configuration->sender_mail => $etiquetteFrom[0]])  
320 - // ->to($to[$i])  
321 - // ->subject("[LabInvent] ".$subject)  
322 - // ->send($message);  
323 - // } else {  
324 - // $email->transport('default')  
325 - // ->from([$configuration->sender_mail => $etiquetteFrom[0]])  
326 - // ->to($to[$i])  
327 - // ->subject("[LabInvent] ".$subject)  
328 - // ->send($message);  
329 - // }  
330 - // }  
331 -  
332 - // }  
333 - // }  
334 -  
335 - // }  
336 -  
337 - // /**  
338 - // * Envoi d'un email à la gestion (et aux devs) pour prévenir qu'un matériel a été créé ou modifié  
339 - // * (cf howto dans http://book.cakephp.org/2.0/fr/core-utility-libraries/email.html)  
340 - // * @param string $subject  
341 - // * @param string $message  
342 - // */  
343 - // public function sendEmailToManagementWith($subject, $message) {  
344 -  
345 - // $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first();  
346 -  
347 - // for($i = 1; $i < 11; $i++) {  
348 - // $t = 'emailGuest'.$i;  
349 - // $to = $configuration->$t;  
350 -  
351 - // if ($to != null && !$configuration->test) {  
352 - // if (filter_var($to, FILTER_VALIDATE_EMAIL)) {  
353 - // $email = new Email();  
354 -  
355 - // $etiquetteFrom = explode("@", $configuration->sender_mail);  
356 -  
357 - // if($configuration->envoi_mail_management_dev) {  
358 - // $email->transport('dev')  
359 - // ->from([$configuration->sender_mail => $etiquetteFrom[0]])  
360 - // ->to($to)  
361 - // ->subject("[LabInvent] ".$subject)  
362 - // ->send($message);  
363 - // } else {  
364 - // $email->transport('default')  
365 - // ->from([$configuration->sender_mail => $etiquetteFrom[0]])  
366 - // ->to($to)  
367 - // ->subject("[LabInvent] ".$subject)  
368 - // ->send($message);  
369 - // }  
370 - // }  
371 -  
372 - // }  
373 - // }  
374 -  
375 - // }  
376 -  
377 - // public function sendEmailToManagement($idObj = null) {  
378 -  
379 - // $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first();  
380 -  
381 - // $userAuth = $this->LdapAuth->user($configuration->authentificationType_ldap)[0];  
382 - // $controller = substr($this->request->params['controller'], 0, -1); // materiel  
383 - // $action = $this->request->params['action']; // add or edit or delete or ...  
384 - // $userName = $this->LdapAuth->user('sn')[0].' '.$this->LdapAuth->user('givenname')[0];  
385 - // $userEmail = $this->LdapAuth->user('mail')[0];  
386 - // $role = TableRegistry::get('Users')->find()->where(['username' => $this->LdapAuth->user($configuration->authentificationType_ldap)[0]])->first()['role'];  
387 - // if($role == null) $role = 'Utilisateur';  
388 -  
389 - // $modelName = $this->modelClass; // 'Materiels'  
390 - // $id = $idObj;  
391 -  
392 - // switch ($action) {  
393 - // case 'add':  
394 - // $actionFrench = ['Création d\'un ', 'été créé'];  
395 - // break;  
396 - // case 'edit':  
397 - // $actionFrench = ['Modification d\'un ', 'été modifié'];  
398 - // break;  
399 - // case 'delete':  
400 - // $actionFrench = ['Suppression d\'un ', 'été supprimé'];  
401 - // break;  
402 - // case 'statusValidated':  
403 - // $actionFrench = ['Validation d\'un ', 'été validé'];  
404 - // break;  
405 - // case 'statusToBeArchived':  
406 - // $actionFrench = ['Demande Archivage d\'un ', 'été demandé pour archivage'];  
407 - // break;  
408 - // case 'statusArchived':  
409 - // $actionFrench = ['Archivage d\'un ', 'été archivé'];  
410 - // break;  
411 - // case 'setLabelIsPlaced':  
412 - // $actionFrench = ['Etiquette posé sur un ', 'reçu une étiquette'];  
413 - // break;  
414 - // default:  
415 - // $actionFrench = [$action.' d\'un ', 'été '.$action];  
416 - // break;  
417 - // }  
418 - // $doneBy = $userName." (".$userEmail.", login=".$userAuth.", profil=".$role.").";  
419 -  
420 - // $subject = $actionFrench[0].$controller;  
421 -  
422 - // if($id != null) {  
423 - // $entityName = TableRegistry::get($modelName)->find('all')->where(['id =' => $id])->first();  
424 -  
425 - // if($modelName == 'Materiels') {  
426 - // $entityName = $entityName['designation'];  
427 - // }  
428 - // else if ($modelName == 'Suivis' || $modelName == 'Emprunts') {  
429 - // $entityName = $entityName['id'];  
430 - // }  
431 - // else {  
432 - // $entityName = $entityName['nom'];  
433 - // }  
434 - // }  
435 - // else {  
436 - // $entityName = NULL;  
437 - // }  
438 -  
439 - // $message = $this->getArticle().$controller." ".$entityName." (id=".$id.") a ".$actionFrench[1]." par ".$doneBy;  
440 -  
441 - // $this->sendEmailToManagementWith($subject, $message);  
442 -  
443 - // }  
444 -  
445 - // /**  
446 - // * Envoi d'un email au propriétaire pour prévenir qu'un matériel a été créé  
447 - // * @param string $subject  
448 - // * @param string $message  
449 - // */  
450 - // public function sendEmailToCreate($idObj = null) {  
451 -  
452 - // $id = $idObj;  
453 -  
454 - // $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first();  
455 - // $materiel = TableRegistry::get('Materiels')->find()->where(['id =' => $id])->first();  
456 -  
457 - // $createurName = $this->LdapAuth->user('sn')[0].' '.$this->LdapAuth->user('givenname')[0];  
458 - // $createurEmail = $this->LdapAuth->user('mail')[0];  
459 - // $toEmail = $materiel->email_responsable;  
460 -  
461 - // $role = TableRegistry::get('Users')->find()->where(['username' => $this->LdapAuth->user($configuration->authentificationType_ldap)[0]])->first()['role'];  
462 - // if($role == null) $role = 'Utilisateur';  
463 -  
464 - // $subject = 'Ajout d\'un matériel';  
465 - // $message = $createurName.' (email = '.$createurEmail.', role = '.$role.') a ajouté le matériel "'.$materiel->designation.'" ('.$materiel->numero_laboratoire.') et vous a nommé propriétaire de ce matériel.';  
466 -  
467 - // if ($toEmail != null && !$configuration->test) {  
468 - // if (filter_var($toEmail, FILTER_VALIDATE_EMAIL)) {  
469 - // $email = new Email();  
470 -  
471 - // $etiquetteFrom = explode("@", $configuration->sender_mail);  
472 -  
473 - // if($configuration->envoi_mail_management_dev) {  
474 - // $email->transport('dev')  
475 - // ->from([$configuration->sender_mail => $etiquetteFrom[0]])  
476 - // ->to($toEmail)  
477 - // ->subject("[LabInvent] ".$subject)  
478 - // ->send($message);  
479 - // } else {  
480 - // $email->transport('default')  
481 - // ->from([$configuration->sender_mail => $etiquetteFrom[0]])  
482 - // ->to($toEmail)  
483 - // ->subject("[LabInvent] ".$subject)  
484 - // ->send($message);  
485 - // }  
486 - // }  
487 -  
488 - // }  
489 -  
490 - // }  
491 - static function isLabinventDebugMode() {  
492 - return TableRegistry::get('Configurations')->find()->where([  
493 - 'id =' => 1  
494 - ])->first()->mode_debug;  
495 - } 229 + protected function getArticle() { return "Le "; }
  230 +
  231 + static function isLabinventDebugMode() { return TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first()->mode_debug; }
496 232
497 function myDebug($arg, $stop = false) { 233 function myDebug($arg, $stop = false) {
498 if ($this->isLabinventDebugMode()) { 234 if ($this->isLabinventDebugMode()) {
@@ -516,17 +252,17 @@ class AppController extends Controller { @@ -516,17 +252,17 @@ class AppController extends Controller {
516 public function sendEmail($obj, $subject = null, $msg = null) { 252 public function sendEmail($obj, $subject = null, $msg = null) {
517 /* 253 /*
518 * $_SESSION['Auth']['User'] pour retrouver TOUTES les infos de la session courante (tout est du string) : 254 * $_SESSION['Auth']['User'] pour retrouver TOUTES les infos de la session courante (tout est du string) :
519 - * nom['sn'][0]  
520 - * prenom['givenname'][0]  
521 - * mail['mail'][0]  
522 - * login['xxx'][0] /!\ Ce champ est suceptible de changer de nom, dans les tests ce champ est ['cn'][0]  
523 - * mdp['userpassword'][0] 255 + * nom $_SESSION['Auth']['User']['sn'][0]
  256 + * prenom $_SESSION['Auth']['User']['givenname'][0]
  257 + * mail $_SESSION['Auth']['User']['mail'][0]
  258 + * login $_SESSION['Auth']['User']['xxx'][0] /!\ Ce champ est suceptible de changer de nom, dans les tests ce champ est ['cn'][0]
  259 + * mdp $_SESSION['Auth']['User']['userpassword'][0]
524 */ 260 */
525 $configuration = $this->confLabinvent; 261 $configuration = $this->confLabinvent;
526 $action = $this->request->params['action']; // add or edit or delete or ... 262 $action = $this->request->params['action']; // add or edit or delete or ...
527 263
528 // Si les deux cases "Activer l'envoi des mails.." sont décochée, on se fatigue pas à exécuter la fonction 264 // Si les deux cases "Activer l'envoi des mails.." sont décochée, on se fatigue pas à exécuter la fonction
529 - if (! $configuration->envoi_mail && ! $configuration->envoi_mail_guests) 265 + if (!$configuration->envoi_mail && !$configuration->envoi_mail_guests)
530 return null; 266 return null;
531 267
532 $materiel = $obj; 268 $materiel = $obj;
@@ -580,6 +316,7 @@ class AppController extends Controller { @@ -580,6 +316,7 @@ class AppController extends Controller {
580 // Et maintenant on construit la liste de mails ... 316 // Et maintenant on construit la liste de mails ...
581 // Si l'envoi général est activé (et que l'action ne correspond pas à 'printLabelRuban'): 317 // Si l'envoi général est activé (et que l'action ne correspond pas à 'printLabelRuban'):
582 if ($configuration->envoi_mail && $action != 'printLabelRuban') { 318 if ($configuration->envoi_mail && $action != 'printLabelRuban') {
  319 +
583 // mail owner 320 // mail owner
584 $mailList[0] = $materiel->email_responsable; 321 $mailList[0] = $materiel->email_responsable;
585 322
@@ -589,10 +326,9 @@ class AppController extends Controller { @@ -589,10 +326,9 @@ class AppController extends Controller {
589 326
590 if ($materiel->groupes_metier_id != null && $materiel->groupes_metier_id != 1) 327 if ($materiel->groupes_metier_id != null && $materiel->groupes_metier_id != 1)
591 // Le ..!= 1 c'est parce que le groupe métier/thématique d'id 1 correspond au groupe N/A, soit aucun groupe 328 // Le ..!= 1 c'est parce que le groupe métier/thématique d'id 1 correspond au groupe N/A, soit aucun groupe
592 - $mailsRespMetier = TableRegistry::get('Users')->find()->select('email')->where([  
593 - 'role =' => 'Responsable',  
594 - 'groupes_metier_id =' => $materiel->groupes_metier_id  
595 - ])->toArray(); 329 + $mailsRespMetier = TableRegistry::get('Users')->find()->select('email')
  330 + ->where(['role =' => 'Responsable', 'groupes_metier_id =' => $materiel->groupes_metier_id])
  331 + ->toArray();
596 332
597 if ($mailsRespMetier != null && $mailsRespMetier != null) { 333 if ($mailsRespMetier != null && $mailsRespMetier != null) {
598 $mailResp = array_unique(array_merge($mailsRespMetier, $mailRespThematique)); 334 $mailResp = array_unique(array_merge($mailsRespMetier, $mailRespThematique));
@@ -607,11 +343,8 @@ class AppController extends Controller { @@ -607,11 +343,8 @@ class AppController extends Controller {
607 343
608 /* 344 /*
609 * if ($action != 'statusValidated' && $action != 'statusArchived') { 345 * if ($action != 'statusValidated' && $action != 'statusArchived') {
610 - * $mailsAdmin = TableRegistry::get('Users')->find()  
611 - * ->select('email')  
612 - * ->where([  
613 - * 'role =' => 'Administration'  
614 - * ]) 346 + * $mailsAdmin = TableRegistry::get('Users')->find()->select('email')
  347 + * ->where(['role =' => 'Administration'])
615 * ->toArray(); 348 * ->toArray();
616 * for ($i = 0; $i < sizeof($mailsAdmin); $i ++) { 349 * for ($i = 0; $i < sizeof($mailsAdmin); $i ++) {
617 * $mailList[sizeof($mailList)] = $mailsAdmin[$i]['email']; 350 * $mailList[sizeof($mailList)] = $mailsAdmin[$i]['email'];
@@ -639,15 +372,15 @@ class AppController extends Controller { @@ -639,15 +372,15 @@ class AppController extends Controller {
639 // 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 372 // 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
640 if ($mail != $_SESSION['Auth']['User']['mail'][0]) { 373 if ($mail != $_SESSION['Auth']['User']['mail'][0]) {
641 $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 374 $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
  375 + $role = TableRegistry::get('Users')->find()->select('role')->where(['email =' => $mail])->first()['role'];
  376 +
642 if ($action != 'statusValidated' && $materiel != null) 377 if ($action != 'statusValidated' && $materiel != null)
643 $message .= " Veuillez vérifier et compléter si besoin la fiche corespondante."; 378 $message .= " Veuillez vérifier et compléter si besoin la fiche corespondante.";
644 - $role = TableRegistry::get('Users')->find()->select('role')->where([  
645 - 'email =' => $mail  
646 - ])->first()['role'];  
647 if ($role) 379 if ($role)
648 $role = 'en tant que ' . $role; 380 $role = 'en tant que ' . $role;
649 else 381 else
650 $role = 'car vous avez demandé à le recevoir. Pour faire retirer votre mail de la liste, veuillez contacter un SuperAdmin'; 382 $role = 'car vous avez demandé à le recevoir. Pour faire retirer votre mail de la liste, veuillez contacter un SuperAdmin';
  383 +
651 $message .= "\n\n" . 'Vous recevez ce message ' . $role; 384 $message .= "\n\n" . 'Vous recevez ce message ' . $role;
652 $this->sendEmailTo("$subject", $message, $mail, $configuration); 385 $this->sendEmailTo("$subject", $message, $mail, $configuration);
653 } 386 }
@@ -657,23 +390,12 @@ class AppController extends Controller { @@ -657,23 +390,12 @@ class AppController extends Controller {
657 390
658 // Fonction d'envoi de mails 391 // Fonction d'envoi de mails
659 private function sendEmailTo($subject, $msg, $mail, $config) { 392 private function sendEmailTo($subject, $msg, $mail, $config) {
660 - if ($mail != null && ! $config->test) { 393 + if ($mail != null && !$config->test) {
661 if (filter_var($mail, FILTER_VALIDATE_EMAIL)) { 394 if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
662 $email = new Email(); 395 $email = new Email();
663 -  
664 $etiquetteFrom = explode("@", $config->sender_mail); 396 $etiquetteFrom = explode("@", $config->sender_mail);
665 -  
666 - // if($config->envoi_mail) { // <-- Si la case "Envoi des mails de management en local " est cochée  
667 - // $email->transport('dev')  
668 - // ->from([$config->sender_mail => $etiquetteFrom[0]])  
669 - // ->to($mail)  
670 - // ->subject("[LabInvent] ".$subject)  
671 - // ->send($msg);  
672 - // } else { // <-- Si la case n'est pas cochée  
673 - $email->transport('default')->from([  
674 - $config->sender_mail => $etiquetteFrom[0]  
675 - ])->to($mail)->subject("[LabInvent] " . $subject)->send($msg);  
676 - // } 397 + $email->transport('default')->from([$config->sender_mail => $etiquetteFrom[0]])
  398 + ->to($mail)->subject("[LabInvent] " . $subject)->send($msg);
677 } 399 }
678 } 400 }
679 } 401 }
src/Controller/CategoriesController.php
@@ -26,7 +26,7 @@ class CategoriesController extends AppController @@ -26,7 +26,7 @@ class CategoriesController extends AppController
26 */ 26 */
27 public function isAuthorized($user) 27 public function isAuthorized($user)
28 { 28 {
29 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 29 + $configuration = $this->confLabinvent;
30 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 30 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
31 $action = $this->request->params['action']; 31 $action = $this->request->params['action'];
32 32
src/Controller/ConfigurationsController.php
@@ -34,7 +34,7 @@ class ConfigurationsController extends AppController @@ -34,7 +34,7 @@ class ConfigurationsController extends AppController
34 */ 34 */
35 public function isAuthorized($user) 35 public function isAuthorized($user)
36 { 36 {
37 - $configuration = $this->Configurations->find()->where(['id =' => 1])->first(); 37 + $configuration = $this->confLabinvent;
38 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 38 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
39 $action = $this->request->params['action']; 39 $action = $this->request->params['action'];
40 40
@@ -81,6 +81,7 @@ class ConfigurationsController extends AppController @@ -81,6 +81,7 @@ class ConfigurationsController extends AppController
81 $configurationObj = $this->Configurations->patchEntity($configurationObj, $this->request->data); 81 $configurationObj = $this->Configurations->patchEntity($configurationObj, $this->request->data);
82 if ($this->Configurations->save($configurationObj)) { 82 if ($this->Configurations->save($configurationObj)) {
83 $this->Flash->success(__('La configuration a bien été sauvegardée.')); 83 $this->Flash->success(__('La configuration a bien été sauvegardée.'));
  84 + // On reload la configuration
84 $this->confLabinvent = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 85 $this->confLabinvent = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first();
85 if($configurationObj->get('mode_install')) { 86 if($configurationObj->get('mode_install')) {
86 return $this->redirect(['controller' => 'pages', 'action' => 'home']); 87 return $this->redirect(['controller' => 'pages', 'action' => 'home']);
src/Controller/DocumentsController.php
@@ -20,12 +20,10 @@ class DocumentsController extends AppController { @@ -20,12 +20,10 @@ class DocumentsController extends AppController {
20 * @return boolean 20 * @return boolean
21 */ 21 */
22 public function isAuthorized($user) { 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']; 23 + $configuration = $this->confLabinvent;
  24 + $role = TableRegistry::get('Users')->find()
  25 + ->where(['username' => $user[$configuration->authentificationType_ldap][0]])
  26 + ->first()['role'];
29 $action = $this->request->params['action']; 27 $action = $this->request->params['action'];
30 28
31 // Super-Admin peut accéder à chaque action 29 // Super-Admin peut accéder à chaque action
@@ -301,15 +299,9 @@ class DocumentsController extends AppController { @@ -301,15 +299,9 @@ class DocumentsController extends AppController {
301 * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. 299 * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise.
302 */ 300 */
303 public function edit($id = null) { 301 public function edit($id = null) {
304 - $document = $this->Documents->get($id, [  
305 - 'contain' => []  
306 - ]); 302 + $document = $this->Documents->get($id, ['contain' => []]);
307 303
308 - if ($this->request->is([  
309 - 'patch',  
310 - 'post',  
311 - 'put'  
312 - ])) { 304 + if ($this->request->is(['patch','post','put'])) {
313 $document = $this->Documents->patchEntity($document, $this->request->data); 305 $document = $this->Documents->patchEntity($document, $this->request->data);
314 306
315 if ($this->Documents->save($document)) { 307 if ($this->Documents->save($document)) {
@@ -318,57 +310,31 @@ class DocumentsController extends AppController { @@ -318,57 +310,31 @@ class DocumentsController extends AppController {
318 $id = $document->materiel_id; 310 $id = $document->materiel_id;
319 if (empty($id)) { 311 if (empty($id)) {
320 $id = $document->suivi_id; 312 $id = $document->suivi_id;
321 - return $this->redirect([  
322 - 'controller' => 'suivis',  
323 - 'action' => 'view',  
324 - $id  
325 - ]);  
326 - } else {  
327 - return $this->redirect([  
328 - 'controller' => 'materiels',  
329 - 'action' => 'view',  
330 - $id  
331 - ]);  
332 - }  
333 - } else { 313 + return $this->redirect(['controller' => 'suivis', 'action' => 'view', $id]);
  314 + } else
  315 + return $this->redirect(['controller' => 'materiels', 'action' => 'view', $id]);
  316 + } else
334 $this->Flash->error(__('Le fichier n\'a pas pu être edité.')); 317 $this->Flash->error(__('Le fichier n\'a pas pu être edité.'));
335 - }  
336 } 318 }
337 319
338 $id = $document->materiel_id; 320 $id = $document->materiel_id;
339 if (empty($id)) { 321 if (empty($id)) {
340 $id = $document->suivi_id; 322 $id = $document->suivi_id;
341 - $suivi = $this->Documents->Suivis->find('list', [  
342 - 'keyField' => 'id',  
343 - 'valueField' => 'id'  
344 - ])->where([  
345 - 'id =' => $id  
346 - ]); 323 + $suivi = $this->Documents->Suivis->find('list', ['keyField' => 'id', 'valueField' => 'id'])->where(['id =' => $id]);
347 $this->set('suivi', $suivi); 324 $this->set('suivi', $suivi);
348 } else { 325 } else {
349 - $materiel = $this->Documents->Materiels->find('list', [  
350 - 'keyField' => 'id',  
351 - 'valueField' => 'numero_laboratoire'  
352 - ])->where([  
353 - 'id =' => $id  
354 - ]); 326 + $materiel = $this->Documents->Materiels->find('list', ['keyField' => 'id','valueField' => 'numero_laboratoire'])
  327 + ->where(['id =' => $id]);
355 $this->set('materiel', $materiel); 328 $this->set('materiel', $materiel);
356 } 329 }
357 330
358 - if ($document->photo) { 331 + if ($document->photo)
359 $this->set('photo', 1); 332 $this->set('photo', 1);
360 - }  
361 333
362 - $typesD = $this->Documents->TypeDocuments->find('list', [  
363 - 'keyField' => 'id',  
364 - 'valueField' => 'nom',  
365 - 'order' => 'TypeDocuments.nom'  
366 - ]); 334 + $typesD = $this->Documents->TypeDocuments->find('list', ['keyField' => 'id', 'valueField' => 'nom', 'order' => 'TypeDocuments.nom']);
367 335
368 $this->set(compact('document', 'typesD')); 336 $this->set(compact('document', 'typesD'));
369 - $this->set('_serialize', [  
370 - 'document'  
371 - ]); 337 + $this->set('_serialize', ['document']);
372 } 338 }
373 339
374 /** 340 /**
@@ -380,10 +346,7 @@ class DocumentsController extends AppController { @@ -380,10 +346,7 @@ class DocumentsController extends AppController {
380 * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. 346 * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
381 */ 347 */
382 public function delete($id = null) { 348 public function delete($id = null) {
383 - $this->request->allowMethod([  
384 - 'post',  
385 - 'delete'  
386 - ]); 349 + $this->request->allowMethod(['post', 'delete']);
387 $document = $this->Documents->get($id); 350 $document = $this->Documents->get($id);
388 351
389 if ($document->photo) { 352 if ($document->photo) {
@@ -394,41 +357,27 @@ class DocumentsController extends AppController { @@ -394,41 +357,27 @@ class DocumentsController extends AppController {
394 $materielTable->save($materiel); 357 $materielTable->save($materiel);
395 } 358 }
396 359
397 - if ($this->Documents->delete($document)) { 360 + if ($this->Documents->delete($document))
398 $this->Flash->success(__('Le fichier a bien été supprimé.')); 361 $this->Flash->success(__('Le fichier a bien été supprimé.'));
399 - } else { 362 + else
400 $this->Flash->error(__('Le fichier n\'a pas pu être supprimé.')); 363 $this->Flash->error(__('Le fichier n\'a pas pu être supprimé.'));
401 - }  
402 - 364 +
403 $id = $document->materiel_id; 365 $id = $document->materiel_id;
  366 +
404 if (empty($id)) { 367 if (empty($id)) {
405 $id = $document->suivi_id; 368 $id = $document->suivi_id;
406 - return $this->redirect([  
407 - 'controller' => 'suivis',  
408 - 'action' => 'view',  
409 - $id  
410 - ]);  
411 - } else {  
412 - return $this->redirect([  
413 - 'controller' => 'materiels',  
414 - 'action' => 'view',  
415 - $id  
416 - ]);  
417 - } 369 + return $this->redirect(['controller' => 'suivis', 'action' => 'view', $id]);
  370 + } else
  371 + return $this->redirect(['controller' => 'materiels', 'action' => 'view', $id]);
418 } 372 }
419 373
420 - public function sortie($labNumber) {  
421 - $this->set('fpdf', new FPDF('P', 'mm', 'A4'));  
422 - } 374 + public function sortie($labNumber) { $this->set('fpdf', new FPDF('P', 'mm', 'A4')); }
423 375
424 public function admission($labNumber) { 376 public function admission($labNumber) {
425 $this->set('fpdf', new FPDF('P', 'mm', 'A4')); 377 $this->set('fpdf', new FPDF('P', 'mm', 'A4'));
426 // Find the concerned materiel 378 // Find the concerned materiel
427 - $materiel = TableRegistry::get('Materiels')->find('all', [  
428 - 'conditions' => [  
429 - 'numero_laboratoire' => $labNumber  
430 - ]  
431 - ])->first(); // End find 379 + $materiel = TableRegistry::get('Materiels')->find('all', ['conditions' => ['numero_laboratoire' => $labNumber]])->first();
  380 + // End find
432 381
433 // Get the administration user name 382 // Get the administration user name
434 $userName = $this->LdapAuth->user('username'); 383 $userName = $this->LdapAuth->user('username');
@@ -437,13 +386,10 @@ class DocumentsController extends AppController { @@ -437,13 +386,10 @@ class DocumentsController extends AppController {
437 $dateAcquisition = $dateAcquisition; 386 $dateAcquisition = $dateAcquisition;
438 $numeroCommande = $materiel->numero_commande; 387 $numeroCommande = $materiel->numero_commande;
439 $designation = $materiel->designation; 388 $designation = $materiel->designation;
440 - if (isset($materiel->organisme_id) && ! empty($materiel->organisme_id)) {  
441 - $organisme = TableRegistry::get('Organismes')->find('all')->where([  
442 - 'id =' => $materiel->organisme_id  
443 - ])->first()->nom;  
444 - } else { 389 + if (isset($materiel->organisme_id) && ! empty($materiel->organisme_id))
  390 + $organisme = TableRegistry::get('Organismes')->find('all')->where(['id =' => $materiel->organisme_id])->first()->nom;
  391 + else
445 $organisme = ""; 392 $organisme = "";
446 - }  
447 393
448 $fournisseur = $materiel->fournisseur; 394 $fournisseur = $materiel->fournisseur;
449 $numeroOrganisme = $materiel->numero_inventaire_organisme; 395 $numeroOrganisme = $materiel->numero_inventaire_organisme;
@@ -471,70 +417,48 @@ class DocumentsController extends AppController { @@ -471,70 +417,48 @@ class DocumentsController extends AppController {
471 public function ficheMateriel($labNumber) { 417 public function ficheMateriel($labNumber) {
472 418
473 // Find the concerned materiel 419 // Find the concerned materiel
474 - $materiel = TableRegistry::get('Materiels')->find('all', [  
475 - 'conditions' => [  
476 - 'numero_laboratoire' => $labNumber  
477 - ]  
478 - ])->first(); // End find 420 + $materiel = TableRegistry::get('Materiels')->find('all', ['conditions' => ['numero_laboratoire' => $labNumber]])->first();
  421 + // End find
479 422
480 - if (isset($materiel->sur_categorie_id)) {  
481 - $surCategorie = TableRegistry::get('SurCategories')->find()->where([  
482 - 'id =' => $materiel->sur_categorie_id  
483 - ])->first()->nom;  
484 - } else { 423 + if (isset($materiel->sur_categorie_id))
  424 + $surCategorie = TableRegistry::get('SurCategories')->find()->where(['id =' => $materiel->sur_categorie_id])->first()->nom;
  425 + else
485 $surCategorie = ' '; 426 $surCategorie = ' ';
486 - }  
487 427
488 - if (isset($materiel->categorie_id)) {  
489 - $categorie = TableRegistry::get('Categories')->find()->where([  
490 - 'id =' => $materiel->categorie_id  
491 - ])->first()->nom;  
492 - } else { 428 + if (isset($materiel->categorie_id))
  429 + $categorie = TableRegistry::get('Categories')->find()->where(['id =' => $materiel->categorie_id])->first()->nom;
  430 + else
493 $categorie = ' '; 431 $categorie = ' ';
494 - }  
495 432
496 - if (isset($materiel->sous_categorie_id)) {  
497 - $sousCategorie = TableRegistry::get('SousCategories')->find()->where([  
498 - 'id =' => $materiel->sous_categorie_id  
499 - ])->first()->nom;  
500 - } else { 433 + if (isset($materiel->sous_categorie_id))
  434 + $sousCategorie = TableRegistry::get('SousCategories')->find()
  435 + ->where(['id =' => $materiel->sous_categorie_id])
  436 + ->first()->nom;
  437 + else
501 $sousCategorie = ' '; 438 $sousCategorie = ' ';
502 - }  
503 439
504 - if (isset($materiel->groupes_thematique_id)) {  
505 - $groupesThematique = TableRegistry::get('GroupesThematiques')->find()->where([  
506 - 'id =' => $materiel->groupes_thematique_id  
507 - ])->first()->nom;  
508 - } else { 440 + if (isset($materiel->groupes_thematique_id))
  441 + $groupesThematique = TableRegistry::get('GroupesThematiques')->find()
  442 + ->where(['id =' => $materiel->groupes_thematique_id])
  443 + ->first()->nom;
  444 + else
509 $groupesThematique = ' '; 445 $groupesThematique = ' ';
510 - }  
511 446
512 - if (isset($materiel->groupes_metier_id)) {  
513 - $groupesMetier = TableRegistry::get('GroupesMetiers')->find()->where([  
514 - 'id =' => $materiel->groupes_metier_id  
515 - ])->first()->nom;  
516 - } else { 447 + if (isset($materiel->groupes_metier_id))
  448 + $groupesMetier = TableRegistry::get('GroupesMetiers')->find()->where(['id =' => $materiel->groupes_metier_id])->first()->nom;
  449 + else
517 $groupesMetier = ' '; 450 $groupesMetier = ' ';
518 - }  
519 451
520 - if (isset($materiel->organisme_id)) {  
521 - $organisme = TableRegistry::get('Organismes')->find()->where([  
522 - 'id =' => $materiel->organisme_id  
523 - ])->first()->nom;  
524 - } else { 452 + if (isset($materiel->organisme_id))
  453 + $organisme = TableRegistry::get('Organismes')->find()->where(['id =' => $materiel->organisme_id])->first()->nom;
  454 + else
525 $organisme = ' '; 455 $organisme = ' ';
526 - }  
527 456
528 - if (isset($materiel->site_id)) {  
529 - $site = TableRegistry::get('Sites')->find()->where([  
530 - 'id =' => $materiel->site_id  
531 - ])->first()->nom;  
532 - } else { 457 + if (isset($materiel->site_id))
  458 + $site = TableRegistry::get('Sites')->find()->where(['id =' => $materiel->site_id])->first()->nom;
  459 + else
533 $site = ' '; 460 $site = ' ';
534 - }  
535 - $configuration = TableRegistry::get('Configurations')->find()->where([  
536 - 'id =' => 1  
537 - ])->first(); 461 + $configuration = $this->confLabinvent;
538 $nom_groupe_thematique = $configuration->nom_groupe_thematique; 462 $nom_groupe_thematique = $configuration->nom_groupe_thematique;
539 $nom_groupe_metier = $configuration->nom_groupe_metier; 463 $nom_groupe_metier = $configuration->nom_groupe_metier;
540 464
@@ -546,35 +470,17 @@ class DocumentsController extends AppController { @@ -546,35 +470,17 @@ class DocumentsController extends AppController {
546 public function ficheMetrologique($id) { 470 public function ficheMetrologique($id) {
547 471
548 // Find the concerned suivi 472 // Find the concerned suivi
549 - $fiche = TableRegistry::get('Fichemetrologiques')->find('all', [  
550 - 'conditions' => [  
551 - 'id' => $id  
552 - ]  
553 - ])->first();  
554 - $suivi = TableRegistry::get('Suivis')->find('all', [  
555 - 'conditions' => [  
556 - 'id' => $fiche->suivi_id  
557 - ]  
558 - ])->first();  
559 - $mesures = TableRegistry::get('Mesures')->find('all', [  
560 - 'conditions' => [  
561 - 'fichemetrologique_id' => $fiche->id  
562 - ]  
563 - ]);  
564 - if (isset($suivi->unite_id)) {  
565 - $unite = TableRegistry::get('Unites')->find()->where([  
566 - 'id =' => $suivi->unite_id  
567 - ])->first()->nom;  
568 - } else { 473 + $fiche = TableRegistry::get('Fichemetrologiques')->find('all', ['conditions' => ['id' => $id]])->first();
  474 + $suivi = TableRegistry::get('Suivis')->find('all', ['conditions' => ['id' => $fiche->suivi_id]])->first();
  475 + $mesures = TableRegistry::get('Mesures')->find('all', ['conditions' => ['fichemetrologique_id' => $fiche->id]]);
  476 + if (isset($suivi->unite_id))
  477 + $unite = TableRegistry::get('Unites')->find()->where(['id =' => $suivi->unite_id])->first()->nom;
  478 + else
569 $unite = ' '; 479 $unite = ' ';
570 - }  
571 - if (isset($suivi->unite_id)) {  
572 - $symbole = TableRegistry::get('Unites')->find()->where([  
573 - 'id =' => $suivi->unite_id  
574 - ])->first()->symbole;  
575 - } else { 480 + if (isset($suivi->unite_id))
  481 + $symbole = TableRegistry::get('Unites')->find()->where(['id =' => $suivi->unite_id])->first()->symbole;
  482 + else
576 $symbole = ' '; 483 $symbole = ' ';
577 - }  
578 484
579 // set the data materiel for the document (accessible par $materiel dans le document) 485 // set the data materiel for the document (accessible par $materiel dans le document)
580 $this->set(compact('suivi', 'unite', 'fiche', 'symbole', 'mesures')); 486 $this->set(compact('suivi', 'unite', 'fiche', 'symbole', 'mesures'));
src/Controller/EmpruntsController.php
@@ -25,7 +25,7 @@ class EmpruntsController extends AppController @@ -25,7 +25,7 @@ class EmpruntsController extends AppController
25 */ 25 */
26 public function isAuthorized($user) 26 public function isAuthorized($user)
27 { 27 {
28 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 28 + $configuration = $this->confLabinvent;
29 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 29 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
30 30
31 $action = $this->request->params['action']; 31 $action = $this->request->params['action'];
src/Controller/FichemetrologiquesController.php
@@ -24,7 +24,7 @@ class FichemetrologiquesController extends AppController @@ -24,7 +24,7 @@ class FichemetrologiquesController extends AppController
24 public function isAuthorized($user) 24 public function isAuthorized($user)
25 { 25 {
26 /* 26 /*
27 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 27 + $configuration = $this->confLabinvent;
28 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 28 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
29 29
30 $action = $this->request->params['action']; 30 $action = $this->request->params['action'];
src/Controller/FormulesController.php
@@ -21,7 +21,7 @@ class FormulesController extends AppController @@ -21,7 +21,7 @@ class FormulesController extends AppController
21 */ 21 */
22 public function isAuthorized($user) 22 public function isAuthorized($user)
23 { 23 {
24 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 24 + $configuration = $this->confLabinvent;
25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
26 26
27 $action = $this->request->params['action']; 27 $action = $this->request->params['action'];
src/Controller/FournisseursController.php
@@ -21,7 +21,7 @@ class FournisseursController extends AppController @@ -21,7 +21,7 @@ class FournisseursController extends AppController
21 */ 21 */
22 public function isAuthorized($user) 22 public function isAuthorized($user)
23 { 23 {
24 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 24 + $configuration = $this->confLabinvent;
25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
26 $action = $this->request->params['action']; 26 $action = $this->request->params['action'];
27 27
src/Controller/GroupesMetiersController.php
@@ -21,7 +21,7 @@ class GroupesMetiersController extends AppController @@ -21,7 +21,7 @@ class GroupesMetiersController extends AppController
21 */ 21 */
22 public function isAuthorized($user) 22 public function isAuthorized($user)
23 { 23 {
24 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 24 + $configuration = $this->confLabinvent;
25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
26 $action = $this->request->params['action']; 26 $action = $this->request->params['action'];
27 27
src/Controller/GroupesThematiquesController.php
@@ -22,7 +22,7 @@ class GroupesThematiquesController extends AppController @@ -22,7 +22,7 @@ class GroupesThematiquesController extends AppController
22 */ 22 */
23 public function isAuthorized($user) 23 public function isAuthorized($user)
24 { 24 {
25 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 25 + $configuration = $this->confLabinvent;
26 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 26 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
27 $action = $this->request->params['action']; 27 $action = $this->request->params['action'];
28 28
src/Controller/MaterielsController.php
@@ -48,18 +48,16 @@ class MaterielsController extends AppController { @@ -48,18 +48,16 @@ class MaterielsController extends AppController {
48 } 48 }
49 49
50 /** 50 /**
51 - *  
52 - * @param $user Give  
53 - * authorization for materiels 51 + * @param $user
  52 + * Give authorization for materiels
54 * @return boolean 53 * @return boolean
55 */ 54 */
56 // (EP) TODO: ameliorer ca avec des variables globales IS_VALIDATED, IS_ADMIN, ... 55 // (EP) TODO: ameliorer ca avec des variables globales IS_VALIDATED, IS_ADMIN, ...
57 public function isAuthorized($user) { 56 public function isAuthorized($user) {
58 $configuration = $this->confLabinvent; 57 $configuration = $this->confLabinvent;
59 - // $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first();  
60 - $role = TableRegistry::get('Users')->find()->where([  
61 - 'username' => $user[$configuration->authentificationType_ldap][0]  
62 - ])->first()['role']; 58 + $role = TableRegistry::get('Users')->find()
  59 + ->where(['username' => $user[$configuration->authentificationType_ldap][0]])
  60 + ->first()['role'];
63 $this->role = $role; 61 $this->role = $role;
64 $action = $this->request->params['action']; 62 $action = $this->request->params['action'];
65 63
@@ -229,7 +227,6 @@ class MaterielsController extends AppController { @@ -229,7 +227,6 @@ class MaterielsController extends AppController {
229 // Autorisations par defaut: 227 // Autorisations par defaut:
230 default: 228 default:
231 return parent::isAuthorized($user); 229 return parent::isAuthorized($user);
232 - ;  
233 break; 230 break;
234 } // end of switch case 231 } // end of switch case
235 } 232 }
@@ -307,91 +304,57 @@ class MaterielsController extends AppController { @@ -307,91 +304,57 @@ class MaterielsController extends AppController {
307 // Par $this->request->params['pass'][0] 304 // Par $this->request->params['pass'][0]
308 $condition = ''; 305 $condition = '';
309 if (isset($this->request->params['pass'][0])) { 306 if (isset($this->request->params['pass'][0])) {
310 - $condition = [  
311 - 'Materiels.status =' => $this->request->params['pass'][0]  
312 - ]; 307 + $condition = ['Materiels.status =' => $this->request->params['pass'][0]];
313 $this->set('STATUS', $this->request->params['pass'][0]); 308 $this->set('STATUS', $this->request->params['pass'][0]);
314 } 309 }
315 310
316 $GM = $this->request->query('GM'); 311 $GM = $this->request->query('GM');
317 $GT = $this->request->query('GT'); 312 $GT = $this->request->query('GT');
318 if (isset($GM) || isset($GT)) { 313 if (isset($GM) || isset($GT)) {
319 - if (isset($GM) && $GM != TableRegistry::get('GroupesMetiers')->find()->where([  
320 - 'nom =' => 'N/A'  
321 - ])->first()['id']) { 314 + if (isset($GM) && $GM != TableRegistry::get('GroupesMetiers')->find()->where(['nom =' => 'N/A'])->first()['id'])
322 $condition = [ 315 $condition = [
323 'Materiels.groupes_metier_id =' => $GM, 316 'Materiels.groupes_metier_id =' => $GM,
324 'Materiels.status !=' => 'ARCHIVED' 317 'Materiels.status !=' => 'ARCHIVED'
325 ]; 318 ];
326 - } else if (isset($GT) && $GT != TableRegistry::get('GroupesThematiques')->find()->where([  
327 - 'nom =' => 'N/A'  
328 - ])->first()['id']) { 319 + else if (isset($GT) && $GT != TableRegistry::get('GroupesThematiques')->find()->where(['nom =' => 'N/A'])->first()['id'])
329 $condition = [ 320 $condition = [
330 'Materiels.groupes_thematique_id =' => $GT, 321 'Materiels.groupes_thematique_id =' => $GT,
331 'Materiels.status !=' => 'ARCHIVED' 322 'Materiels.status !=' => 'ARCHIVED'
332 ]; 323 ];
333 - } else {  
334 - $condition = [  
335 - 'Materiels.id =' => 0  
336 - ];  
337 - } 324 + else
  325 + $condition = ['Materiels.id =' => 0];
338 } 326 }
339 327
340 $GMV = $this->request->query('GMV'); 328 $GMV = $this->request->query('GMV');
341 $GTV = $this->request->query('GTV'); 329 $GTV = $this->request->query('GTV');
342 if (isset($GMV) || isset($GTV)) { 330 if (isset($GMV) || isset($GTV)) {
343 - if (isset($GMV) && $GMV != TableRegistry::get('GroupesMetiers')->find()->where([  
344 - 'nom =' => 'N/A'  
345 - ])->first()['id']) {  
346 - $condition = [  
347 - 'Materiels.groupes_metier_id =' => $GMV,  
348 - 'Materiels.status =' => 'CREATED',  
349 - 'Materiels.status !=' => 'ARCHIVED' 331 + if (isset($GMV) && $GMV != TableRegistry::get('GroupesMetiers')->find()->where(['nom =' => 'N/A'])->first()['id'])
  332 + $condition = ['Materiels.groupes_metier_id =' => $GMV,
  333 + 'Materiels.status =' => 'CREATED',
  334 + 'Materiels.status !=' => 'ARCHIVED'
350 ]; 335 ];
351 - } else if (isset($GTV) && $GTV != TableRegistry::get('GroupesThematiques')->find()->where([  
352 - 'nom =' => 'N/A'  
353 - ])->first()['id']) { 336 + else if (isset($GTV) && $GTV != TableRegistry::get('GroupesThematiques')->find()->where(['nom =' => 'N/A'])->first()['id'])
354 $condition = [ 337 $condition = [
355 - 'Materiels.groupes_metier_id =' => $GTV,  
356 - 'Materiels.status =' => 'CREATED',  
357 - 'Materiels.status !=' => 'ARCHIVED'  
358 - ];  
359 - } else {  
360 - $condition = [  
361 - 'Materiels.id =' => 0 338 + 'Materiels.groupes_metier_id =' => $GTV,
  339 + 'Materiels.status =' => 'CREATED',
  340 + 'Materiels.status !=' => 'ARCHIVED'
362 ]; 341 ];
363 - } 342 + else
  343 + $condition = ['Materiels.id =' => 0];
364 } 344 }
365 345
366 $MY = $this->request->query('MY'); 346 $MY = $this->request->query('MY');
367 if (isset($MY)) { 347 if (isset($MY)) {
368 - if (in_array($this->role, [  
369 - 'Utilisateur',  
370 - 'Responsable'  
371 - ])) {  
372 - $condition = [  
373 - 'Materiels.nom_responsable =' => $this->request->query('MY'),  
374 - 'Materiels.status !=' => 'ARCHIVED'  
375 - ];  
376 - } else {  
377 - $condition = [  
378 - 'Materiels.nom_responsable =' => $this->request->query('MY')  
379 - ];  
380 - } 348 + if (in_array($this->role, ['Utilisateur', 'Responsable']))
  349 + $condition = ['Materiels.nom_responsable =' => $this->request->query('MY'),'Materiels.status !=' => 'ARCHIVED'];
  350 + else
  351 + $condition = ['Materiels.nom_responsable =' => $this->request->query('MY')];
381 } 352 }
382 353
383 - if (in_array($this->role, [  
384 - 'Utilisateur',  
385 - 'Responsable'  
386 - ]) && $condition == '') {  
387 - $condition = [  
388 - 'Materiels.status !=' => 'ARCHIVED'  
389 - ];  
390 - } 354 + if (in_array($this->role, ['Utilisateur', 'Responsable']) && $condition == '')
  355 + $condition = ['Materiels.status !=' => 'ARCHIVED'];
391 356
392 - $config = TableRegistry::get('Configurations')->find()->where([  
393 - 'id =' => 1  
394 - ])->first(); 357 + $config = $this->confLabinvent;
395 $limit = $this->request->query('aff'); 358 $limit = $this->request->query('aff');
396 if (! isset($limit)) 359 if (! isset($limit))
397 $limit = $config['aff_par_defaut']; 360 $limit = $config['aff_par_defaut'];
@@ -407,23 +370,14 @@ class MaterielsController extends AppController { @@ -407,23 +370,14 @@ class MaterielsController extends AppController {
407 'Organismes', 370 'Organismes',
408 'Sites' 371 'Sites'
409 ], 372 ],
410 - 'order' => [  
411 - 'Materiels.numero_laboratoire' => 'desc'  
412 - ] 373 + 'order' => ['Materiels.numero_laboratoire' => 'desc']
413 ]; 374 ];
414 375
415 - $materiels = $this->paginate($this->Materiels->find('all', [  
416 - 'conditions' => $condition  
417 - ]));  
418 -  
419 - $this->set('nbMateriels', $this->Materiels->find('all', [  
420 - 'conditions' => $condition  
421 - ])->count()); 376 + $materiels = $this->paginate($this->Materiels->find('all', ['conditions' => $condition]));
422 377
  378 + $this->set('nbMateriels', $this->Materiels->find('all', ['conditions' => $condition])->count());
423 $this->set(compact('materiels')); 379 $this->set(compact('materiels'));
424 - $this->set('_serialize', [  
425 - 'materiels'  
426 - ]); 380 + $this->set('_serialize', ['materiels']);
427 } 381 }
428 382
429 /** 383 /**
@@ -493,11 +447,8 @@ class MaterielsController extends AppController { @@ -493,11 +447,8 @@ class MaterielsController extends AppController {
493 $this->set('typeSuivis', $typeSuivis); 447 $this->set('typeSuivis', $typeSuivis);
494 $this->set('typeDocuments', $typeDocuments); 448 $this->set('typeDocuments', $typeDocuments);
495 $this->set('fournisseurs', $fournisseurs); 449 $this->set('fournisseurs', $fournisseurs);
496 -  
497 $this->set('materiel', $materiel); 450 $this->set('materiel', $materiel);
498 - $this->set('_serialize', [  
499 - 'materiel'  
500 - ]); 451 + $this->set('_serialize', ['materiel']);
501 } 452 }
502 453
503 /** 454 /**
@@ -510,12 +461,10 @@ class MaterielsController extends AppController { @@ -510,12 +461,10 @@ class MaterielsController extends AppController {
510 $materiel = $this->Materiels->newEntity(); 461 $materiel = $this->Materiels->newEntity();
511 if ($this->request->is('post')) { 462 if ($this->request->is('post')) {
512 $materiel = $this->Materiels->patchEntity($materiel, $this->request->data); 463 $materiel = $this->Materiels->patchEntity($materiel, $this->request->data);
513 - if (in_array($_SESSION['Auth']['User']['sn'][0], TableRegistry::get('Users')->find('list', [  
514 - 'keyField' => 'id',  
515 - 'valueField' => 'nom'  
516 - ])->where([  
517 - 'role =' => 'Administration'  
518 - ])->toArray())) { 464 + if (in_array($_SESSION['Auth']['User']['sn'][0],
  465 + TableRegistry::get('Users')->find('list', ['keyField' => 'id','valueField' => 'nom'])
  466 + ->where(['role =' => 'Administration'])
  467 + ->toArray())) {
519 $gestionnaireID = TableRegistry::get('Users')->find()->where([ 468 $gestionnaireID = TableRegistry::get('Users')->find()->where([
520 'nom' => $_SESSION['Auth']['User']['sn'][0] 469 'nom' => $_SESSION['Auth']['User']['sn'][0]
521 ])->first()->id; 470 ])->first()->id;
@@ -523,25 +472,17 @@ class MaterielsController extends AppController { @@ -523,25 +472,17 @@ class MaterielsController extends AppController {
523 } 472 }
524 if ($this->Materiels->save($materiel)) { 473 if ($this->Materiels->save($materiel)) {
525 $this->Flash->success(__('Le matériel a bien été ajouté.')); 474 $this->Flash->success(__('Le matériel a bien été ajouté.'));
526 -  
527 $this->sendEmail($materiel); 475 $this->sendEmail($materiel);
528 -  
529 - return $this->redirect([  
530 - 'action' => 'view',  
531 - $materiel->id  
532 - ]);  
533 - } else { 476 + return $this->redirect(['action' => 'view', $materiel->id]);
  477 + } else
534 $this->Flash->error(__('Le matériel n\'a pas pu être ajouté.')); 478 $this->Flash->error(__('Le matériel n\'a pas pu être ajouté.'));
535 - }  
536 } 479 }
537 480
538 $surCategories = $this->Materiels->SurCategories->find('list', [ 481 $surCategories = $this->Materiels->SurCategories->find('list', [
539 'keyField' => 'id', 482 'keyField' => 'id',
540 'valueField' => 'nom', 483 'valueField' => 'nom',
541 'order' => 'SurCategories.nom', 484 'order' => 'SurCategories.nom',
542 - 'conditions' => array(  
543 - 'nom !=' => 'N/A'  
544 - ) 485 + 'conditions' => array('nom !=' => 'N/A')
545 ]); 486 ]);
546 $categories = $this->Materiels->Categories->find('list', [ 487 $categories = $this->Materiels->Categories->find('list', [
547 'keyField' => 'id', 488 'keyField' => 'id',
@@ -581,24 +522,20 @@ class MaterielsController extends AppController { @@ -581,24 +522,20 @@ class MaterielsController extends AppController {
581 $lieu_detail = $this->Materiels->find('list', [ 522 $lieu_detail = $this->Materiels->find('list', [
582 'keyField' => 'lieu_detail', 523 'keyField' => 'lieu_detail',
583 'valueField' => 'lieu_detail', 524 'valueField' => 'lieu_detail',
584 - 'conditions' => array(  
585 - 'lieu_detail !=' => ''  
586 - ), 525 + 'conditions' => array('lieu_detail !=' => ''),
587 'order' => 'lieu_detail', 526 'order' => 'lieu_detail',
588 'group' => 'lieu_detail' 527 'group' => 'lieu_detail'
589 ]); 528 ]);
590 $designation = $this->Materiels->find('list', [ 529 $designation = $this->Materiels->find('list', [
591 'keyField' => 'designation', 530 'keyField' => 'designation',
592 'valueField' => 'designation', 531 'valueField' => 'designation',
593 - 'conditions' => array(  
594 - 'designation !=' => ''  
595 - ), 532 + 'conditions' => array('designation !=' => ''),
596 'order' => 'designation', 533 'order' => 'designation',
597 'group' => 'designation' 534 'group' => 'designation'
598 ]); 535 ]);
599 - $domaineresp = TableRegistry::get('Users')->find()->select('sur_categorie_id')->where([  
600 - 'username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]  
601 - ])->first()['sur_categorie_id']; 536 + $domaineresp = TableRegistry::get('Users')->find()->select('sur_categorie_id')
  537 + ->where(['username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]])
  538 + ->first()['sur_categorie_id'];
602 if ($domaineresp == null) $domaineresp = false; 539 if ($domaineresp == null) $domaineresp = false;
603 $utilisateurconnect = TableRegistry::get('Users')->find('all')->toArray(); 540 $utilisateurconnect = TableRegistry::get('Users')->find('all')->toArray();
604 $users = TableRegistry::get('LdapConnections')->getListUsers(); 541 $users = TableRegistry::get('LdapConnections')->getListUsers();
@@ -611,9 +548,9 @@ class MaterielsController extends AppController { @@ -611,9 +548,9 @@ class MaterielsController extends AppController {
611 } 548 }
612 549
613 // Ne pas commenter la ligne suivante, on en a besoin dans add.cpt 550 // Ne pas commenter la ligne suivante, on en a besoin dans add.cpt
614 - $mail_responsable = TableRegistry::get('Users')->find()->select('email')->where([  
615 - 'username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]  
616 - ])->first()['email']; 551 + $mail_responsable = TableRegistry::get('Users')->find()->select('email')
  552 + ->where(['username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]])
  553 + ->first()['email'];
617 554
618 if (isset($this->request->params['pass'][0])) { 555 if (isset($this->request->params['pass'][0])) {
619 $cpMateriel = $this->Materiels->get($this->request->params['pass'][0]); 556 $cpMateriel = $this->Materiels->get($this->request->params['pass'][0]);
@@ -621,9 +558,7 @@ class MaterielsController extends AppController { @@ -621,9 +558,7 @@ class MaterielsController extends AppController {
621 } 558 }
622 559
623 $this->set(compact('designation', 'utilisateurconnect', 'users', 'materiel', 'surCategories', 'categories', 'sousCategories', 'groupesThematiques', 'groupesMetiers', 'organismes', 'sites', 'utilisateurs', 'mail_responsable', 'domaineresp', 'lieu_detail', 'fournisseurs')); 560 $this->set(compact('designation', 'utilisateurconnect', 'users', 'materiel', 'surCategories', 'categories', 'sousCategories', 'groupesThematiques', 'groupesMetiers', 'organismes', 'sites', 'utilisateurs', 'mail_responsable', 'domaineresp', 'lieu_detail', 'fournisseurs'));
624 - $this->set('_serialize', [  
625 - 'materiel'  
626 - ]); 561 + $this->set('_serialize', ['materiel']);
627 } 562 }
628 563
629 /** 564 /**
@@ -635,36 +570,24 @@ class MaterielsController extends AppController { @@ -635,36 +570,24 @@ class MaterielsController extends AppController {
635 * @throws \Cake\Network\Exception\NotFoundException When record not found. 570 * @throws \Cake\Network\Exception\NotFoundException When record not found.
636 */ 571 */
637 public function edit($id = null) { 572 public function edit($id = null) {
638 - $materiel = $this->Materiels->get($id, [  
639 - 'contain' => []  
640 - ]);  
641 - if ($this->request->is([  
642 - 'patch',  
643 - 'post',  
644 - 'put'  
645 - ])) { 573 + $materiel = $this->Materiels->get($id, ['contain' => []]);
  574 + if ($this->request->is(['patch', 'post', 'put'])) {
646 $materiel = $this->Materiels->patchEntity($materiel, $this->request->data); 575 $materiel = $this->Materiels->patchEntity($materiel, $this->request->data);
647 - if (in_array($_SESSION['Auth']['User']['sn'][0], TableRegistry::get('Users')->find('list', [  
648 - 'keyField' => 'id',  
649 - 'valueField' => 'nom'  
650 - ])->where([  
651 - 'role =' => 'Administration'  
652 - ])->toArray())) {  
653 - $gestionnaireID = TableRegistry::get('Users')->find()->where([  
654 - 'nom' => $_SESSION['Auth']['User']['sn'][0]  
655 - ])->first()->id; 576 + if (in_array($_SESSION['Auth']['User']['sn'][0],
  577 + TableRegistry::get('Users')->find('list', ['keyField' => 'id','valueField' => 'nom'])
  578 + ->where(['role =' => 'Administration'])
  579 + ->toArray())) {
  580 + $gestionnaireID = TableRegistry::get('Users')->find()
  581 + ->where(['nom' => $_SESSION['Auth']['User']['sn'][0]])
  582 + ->first()->id;
656 $materiel->gestionnaire_id = $gestionnaireID; 583 $materiel->gestionnaire_id = $gestionnaireID;
657 } 584 }
658 if ($this->Materiels->save($materiel)) { 585 if ($this->Materiels->save($materiel)) {
659 $this->Flash->success(__('Le matériel a bien été édité.')); 586 $this->Flash->success(__('Le matériel a bien été édité.'));
660 $this->sendEmail($materiel); 587 $this->sendEmail($materiel);
661 - return $this->redirect([  
662 - 'action' => 'view',  
663 - $id  
664 - ]);  
665 - } else { 588 + return $this->redirect(['action' => 'view',$id]);
  589 + } else
666 $this->Flash->error(__('Le matériel n\'a pas pu être édité.')); 590 $this->Flash->error(__('Le matériel n\'a pas pu être édité.'));
667 - }  
668 } 591 }
669 592
670 $surCategories = $this->Materiels->SurCategories->find('list', [ 593 $surCategories = $this->Materiels->SurCategories->find('list', [
@@ -705,18 +628,14 @@ class MaterielsController extends AppController { @@ -705,18 +628,14 @@ class MaterielsController extends AppController {
705 $designation = $this->Materiels->find('list', [ 628 $designation = $this->Materiels->find('list', [
706 'keyField' => 'designation', 629 'keyField' => 'designation',
707 'valueField' => 'designation', 630 'valueField' => 'designation',
708 - 'conditions' => array(  
709 - 'designation !=' => ''  
710 - ), 631 + 'conditions' => array('designation !=' => ''),
711 'order' => 'designation', 632 'order' => 'designation',
712 'group' => 'designation' 633 'group' => 'designation'
713 ]); 634 ]);
714 $designation_edit = $this->Materiels->find('list', [ 635 $designation_edit = $this->Materiels->find('list', [
715 'keyField' => 'id', 636 'keyField' => 'id',
716 'valueField' => 'designation', 637 'valueField' => 'designation',
717 - 'conditions' => array(  
718 - 'id =' => $materiel->id  
719 - ) 638 + 'conditions' => array('id =' => $materiel->id)
720 ]); 639 ]);
721 $designation_edit = $designation_edit->toArray(); 640 $designation_edit = $designation_edit->toArray();
722 641
@@ -724,17 +643,13 @@ class MaterielsController extends AppController { @@ -724,17 +643,13 @@ class MaterielsController extends AppController {
724 $lieu_detail = $this->Materiels->find('list', [ 643 $lieu_detail = $this->Materiels->find('list', [
725 'keyField' => 'lieu_detail', 644 'keyField' => 'lieu_detail',
726 'valueField' => 'lieu_detail', 645 'valueField' => 'lieu_detail',
727 - 'conditions' => array(  
728 - 'lieu_detail !=' => ''  
729 - ), 646 + 'conditions' => array('lieu_detail !=' => ''),
730 'order' => 'lieu_detail' 647 'order' => 'lieu_detail'
731 ]); 648 ]);
732 $lieu_detail_edit = $this->Materiels->find('list', [ 649 $lieu_detail_edit = $this->Materiels->find('list', [
733 'keyField' => 'id', 650 'keyField' => 'id',
734 'valueField' => 'lieu_detail', 651 'valueField' => 'lieu_detail',
735 - 'conditions' => array(  
736 - 'id =' => $materiel->id  
737 - ) 652 + 'conditions' => array('id =' => $materiel->id)
738 ]); 653 ]);
739 $lieu_detail_edit = $lieu_detail_edit->toArray(); 654 $lieu_detail_edit = $lieu_detail_edit->toArray();
740 655
@@ -744,15 +659,15 @@ class MaterielsController extends AppController { @@ -744,15 +659,15 @@ class MaterielsController extends AppController {
744 'valueField' => 'nom', 659 'valueField' => 'nom',
745 'order' => 'Fournisseurs.nom' 660 'order' => 'Fournisseurs.nom'
746 ]); 661 ]);
747 - $dom = TableRegistry::get('Materiels')->find()->select('sur_categorie_id')->where([  
748 - 'id =' => $materiel->id  
749 - ])->first()['sur_categorie_id'];  
750 - $domaines = TableRegistry::get('Users')->find()->select('sur_categorie_id')->where([  
751 - 'username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]  
752 - ])->first()['sur_categorie_id'];  
753 - $role = TableRegistry::get('Users')->find()->select('role')->where([  
754 - 'username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]  
755 - ])->first()['role']; 662 + $dom = TableRegistry::get('Materiels')->find()->select('sur_categorie_id')
  663 + ->where(['id =' => $materiel->id])
  664 + ->first()['sur_categorie_id'];
  665 + $domaines = TableRegistry::get('Users')->find()->select('sur_categorie_id')
  666 + ->where(['username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]])
  667 + ->first()['sur_categorie_id'];
  668 + $role = TableRegistry::get('Users')->find()->select('role')
  669 + ->where(['username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]])
  670 + ->first()['role'];
756 671
757 if ($dom == $domaines) 672 if ($dom == $domaines)
758 $domaineresp = true; 673 $domaineresp = true;
@@ -767,39 +682,32 @@ class MaterielsController extends AppController { @@ -767,39 +682,32 @@ class MaterielsController extends AppController {
767 $utilisateurs[$users[$i]] = $users[$i]; 682 $utilisateurs[$users[$i]] = $users[$i];
768 } 683 }
769 684
770 - if (! empty($materiel->get('nom_responsable'))) {  
771 - if (! in_array($materiel->get('nom_responsable'), $utilisateurs)) { 685 + if (!empty($materiel->get('nom_responsable'))) {
  686 + if (!in_array($materiel->get('nom_responsable'), $utilisateurs)) {
772 $nom_ancien_responsable = $materiel->get('nom_responsable'); 687 $nom_ancien_responsable = $materiel->get('nom_responsable');
773 $this->set(compact('nom_ancien_responsable')); 688 $this->set(compact('nom_ancien_responsable'));
774 } 689 }
775 } 690 }
776 - $mail_responsable = TableRegistry::get('Users')->find()->select('email')->where([  
777 - 'username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]  
778 - ])->first()['email']; 691 + $mail_responsable = TableRegistry::get('Users')->find()->select('email')
  692 + ->where(['username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]])
  693 + ->first()['email'];
779 694
780 // Fonction utilisée dans la vue, déclarée ici pour éviter les problèmes de tests 695 // Fonction utilisée dans la vue, déclarée ici pour éviter les problèmes de tests
781 $isReadonlyField = function ($fieldName, $myReadonlyFields) { 696 $isReadonlyField = function ($fieldName, $myReadonlyFields) {
782 - if (! empty($myReadonlyFields) && $myReadonlyFields[0] == '*') { 697 + if (!empty($myReadonlyFields) && $myReadonlyFields[0] == '*') {
783 $modifiableFields = $myReadonlyFields; 698 $modifiableFields = $myReadonlyFields;
784 array_shift($modifiableFields); 699 array_shift($modifiableFields);
785 - return ! in_array($fieldName, $modifiableFields); 700 + return !in_array($fieldName, $modifiableFields);
786 } 701 }
787 return in_array($fieldName, $myReadonlyFields); 702 return in_array($fieldName, $myReadonlyFields);
788 }; 703 };
  704 +
789 $this->set('isReadonlyField', $isReadonlyField); 705 $this->set('isReadonlyField', $isReadonlyField);
790 -  
791 $this->set('IS_CREATED', $materiel->status == 'CREATED'); 706 $this->set('IS_CREATED', $materiel->status == 'CREATED');
792 $this->set('IS_VALIDATED', $materiel->status == 'VALIDATED'); 707 $this->set('IS_VALIDATED', $materiel->status == 'VALIDATED');
793 - $this->set('IS_ARCHIVED_OR_TOBE', in_array($materiel->status, [  
794 - 'TOBEARCHIVED',  
795 - 'ARCHIVED'  
796 - ]));  
797 - 708 + $this->set('IS_ARCHIVED_OR_TOBE', in_array($materiel->status, ['TOBEARCHIVED','ARCHIVED']));
798 $this->set(compact('materiel', 'surCategories', 'categories', 'sousCategories', 'groupesThematiques', 'groupesMetiers', 'organismes', 'sites', 'utilisateurs', 'mail_responsable', 'role', 'domaineresp', 'designation_edit', 'designation', 'lieu_detail', 'lieu_detail_edit', 'fournisseurs')); 709 $this->set(compact('materiel', 'surCategories', 'categories', 'sousCategories', 'groupesThematiques', 'groupesMetiers', 'organismes', 'sites', 'utilisateurs', 'mail_responsable', 'role', 'domaineresp', 'designation_edit', 'designation', 'lieu_detail', 'lieu_detail_edit', 'fournisseurs'));
799 -  
800 - $this->set('_serialize', [  
801 - 'materiel'  
802 - ]); 710 + $this->set('_serialize', ['materiel']);
803 } 711 }
804 712
805 /** 713 /**
@@ -811,26 +719,14 @@ class MaterielsController extends AppController { @@ -811,26 +719,14 @@ class MaterielsController extends AppController {
811 * @throws \Cake\Network\Exception\NotFoundException When record not found. 719 * @throws \Cake\Network\Exception\NotFoundException When record not found.
812 */ 720 */
813 public function administrer($id = null) { 721 public function administrer($id = null) {
814 - $materiel = $this->Materiels->get($id, [  
815 - 'contain' => []  
816 - ]);  
817 - if ($this->request->is([  
818 - 'patch',  
819 - 'post',  
820 - 'put'  
821 - ])) { 722 + $materiel = $this->Materiels->get($id, ['contain' => []]);
  723 + if ($this->request->is(['patch', 'post', 'put'])) {
822 $materiel = $this->Materiels->patchEntity($materiel, $this->request->data); 724 $materiel = $this->Materiels->patchEntity($materiel, $this->request->data);
823 - if ($this->Materiels->save($materiel, [  
824 - 'checkRules' => false  
825 - ])) { 725 + if ($this->Materiels->save($materiel, ['checkRules' => false])) {
826 $this->Flash->success(__('Le matériel a bien été édité.')); 726 $this->Flash->success(__('Le matériel a bien été édité.'));
827 - return $this->redirect([  
828 - 'action' => 'view',  
829 - $id  
830 - ]);  
831 - } else { 727 + return $this->redirect(['action' => 'view', $id]);
  728 + } else
832 $this->Flash->error(__('Le matériel n\'a pas pu être édité.')); 729 $this->Flash->error(__('Le matériel n\'a pas pu être édité.'));
833 - }  
834 } 730 }
835 $surCategories = $this->Materiels->SurCategories->find('list', [ 731 $surCategories = $this->Materiels->SurCategories->find('list', [
836 'keyField' => 'id', 732 'keyField' => 'id',
@@ -874,6 +770,7 @@ class MaterielsController extends AppController { @@ -874,6 +770,7 @@ class MaterielsController extends AppController {
874 ]); 770 ]);
875 771
876 $users = TableRegistry::get('LdapConnections')->getListUsers(); 772 $users = TableRegistry::get('LdapConnections')->getListUsers();
  773 +
877 // tri des utilisateurs par nom 774 // tri des utilisateurs par nom
878 sort($users); 775 sort($users);
879 $utilisateurs = []; 776 $utilisateurs = [];
@@ -881,27 +778,22 @@ class MaterielsController extends AppController { @@ -881,27 +778,22 @@ class MaterielsController extends AppController {
881 $utilisateurs[$users[$i]] = $users[$i]; 778 $utilisateurs[$users[$i]] = $users[$i];
882 } 779 }
883 780
884 - if (! empty($materiel->get('nom_responsable'))) {  
885 - if (! in_array($materiel->get('nom_responsable'), $utilisateurs)) { 781 + if (!empty($materiel->get('nom_responsable'))) {
  782 + if (!in_array($materiel->get('nom_responsable'), $utilisateurs)) {
886 $nom_ancien_responsable = $materiel->get('nom_responsable'); 783 $nom_ancien_responsable = $materiel->get('nom_responsable');
887 $this->set(compact('nom_ancien_responsable')); 784 $this->set(compact('nom_ancien_responsable'));
888 } 785 }
889 } 786 }
890 - $mail_responsable = TableRegistry::get('Users')->find()->select('email')->where([  
891 - 'username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]  
892 - ])->first()['email']; 787 + $mail_responsable = TableRegistry::get('Users')->find()->select('email')
  788 + ->where(['username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]])
  789 + ->first()['email'];
893 790
894 $this->set('IS_CREATED', $materiel->status == 'CREATED'); 791 $this->set('IS_CREATED', $materiel->status == 'CREATED');
895 $this->set('IS_VALIDATED', $materiel->status == 'VALIDATED'); 792 $this->set('IS_VALIDATED', $materiel->status == 'VALIDATED');
896 - $this->set('IS_ARCHIVED_OR_TOBE', in_array($materiel->status, [  
897 - 'TOBEARCHIVED',  
898 - 'ARCHIVED'  
899 - ])); 793 + $this->set('IS_ARCHIVED_OR_TOBE', in_array($materiel->status, ['TOBEARCHIVED','ARCHIVED']));
900 794
901 $this->set(compact('materiel', 'surCategories', 'categories', 'sousCategories', 'groupesThematiques', 'groupesMetiers', 'organismes', 'sites', 'utilisateurs', 'mail_responsable', 'fournisseurs')); 795 $this->set(compact('materiel', 'surCategories', 'categories', 'sousCategories', 'groupesThematiques', 'groupesMetiers', 'organismes', 'sites', 'utilisateurs', 'mail_responsable', 'fournisseurs'));
902 - $this->set('_serialize', [  
903 - 'materiel'  
904 - ]); 796 + $this->set('_serialize', ['materiel']);
905 } 797 }
906 798
907 /** 799 /**
@@ -919,12 +811,9 @@ class MaterielsController extends AppController { @@ -919,12 +811,9 @@ class MaterielsController extends AppController {
919 if ($this->Materiels->delete($materiel)) { 811 if ($this->Materiels->delete($materiel)) {
920 $this->Flash->success(__('Le matériel a bien été supprimé.')); 812 $this->Flash->success(__('Le matériel a bien été supprimé.'));
921 $this->sendEmail($materiel); 813 $this->sendEmail($materiel);
922 - } else { 814 + } else
923 $this->Flash->error(__('Le matériel n\'a pas pu être supprimé.')); 815 $this->Flash->error(__('Le matériel n\'a pas pu être supprimé.'));
924 - }  
925 - return $this->redirect([  
926 - 'action' => 'index'  
927 - ]); 816 + return $this->redirect(['action' => 'index']);
928 } 817 }
929 818
930 /** 819 /**
@@ -939,9 +828,8 @@ class MaterielsController extends AppController { @@ -939,9 +828,8 @@ class MaterielsController extends AppController {
939 private function statusSetTo($newStatus, $message, $id = null, $from = 'index') { 828 private function statusSetTo($newStatus, $message, $id = null, $from = 'index') {
940 $materiel = $this->Materiels->get($id)->set('status', $newStatus); 829 $materiel = $this->Materiels->get($id)->set('status', $newStatus);
941 830
942 - if ($newStatus == 'ARCHIVED') { 831 + if ($newStatus == 'ARCHIVED')
943 $materiel->set('date_archivage', date('Y-m-d')); 832 $materiel->set('date_archivage', date('Y-m-d'));
944 - }  
945 833
946 if ($newStatus == 'VALIDATED') { 834 if ($newStatus == 'VALIDATED') {
947 $mandatoryFields = array( 835 $mandatoryFields = array(
@@ -952,50 +840,32 @@ class MaterielsController extends AppController { @@ -952,50 +840,32 @@ class MaterielsController extends AppController {
952 $materiel->date_reception, 840 $materiel->date_reception,
953 $materiel->prix_ht 841 $materiel->prix_ht
954 ); 842 );
955 - $msgError ="Pour valider un matériel, les champs suivants ne doivent pas être vides :  
956 -Nom propriétaire,  
957 -Fournisseur,  
958 -Numéro de commande,  
959 -Organisme,  
960 -Prix,  
961 -et Date de reception  
962 -"; // Ne pas oublier les espaces après chaque virgule/fin de ligne (sinon le message d'erreur est pas joli)  
963 - $allGood = true; // Oui, comme le KFC ! 843 + $msgError = "Pour valider un matériel, les champs suivants ne doivent pas être vides :
  844 + Nom propriétaire,
  845 + Fournisseur,
  846 + Numéro de commande,
  847 + Organisme,
  848 + Date de reception,
  849 + et Prix.";
  850 + // Ne pas oublier les espaces après chaque virgule/fin de ligne (sinon le message d'erreur est pas joli)
  851 +
964 foreach ($mandatoryFields as $field){ 852 foreach ($mandatoryFields as $field){
965 if (!isset($field)){ 853 if (!isset($field)){
966 - $allGood = false; 854 + $this->Flash->error($msgError);
  855 + return $this->redirect(['action' => 'edit', $id]);
967 } 856 }
968 } 857 }
969 - if ($allGood == false) {  
970 - $this->Flash->error($msgError);  
971 - return $this->redirect([  
972 - 'action' => 'edit',  
973 - $id  
974 - ]);  
975 - }  
976 - // $message = 'Le matériel "'.$materiel->get('designation').'" ('.$materiel->numero_laboratoire.') a été validé.';  
977 - // $this->sendEmailTo('Validation d\'un matériel', $message, [$materiel->get('email_responsable')]);  
978 } 858 }
979 859
980 - if ($this->Materiels->save($materiel, [  
981 - 'checkRules' => false,  
982 - 'checkExisting' => false  
983 - ])) { 860 + if ($this->Materiels->save($materiel, ['checkRules' => false, 'checkExisting' => false]))
984 $this->Flash->success(__($message)); 861 $this->Flash->success(__($message));
985 - // $this->sendEmailToManagement($id);  
986 - } else { 862 + else
987 $this->Flash->error(__('Le statut n\'a pas pu être édité.')); 863 $this->Flash->error(__('Le statut n\'a pas pu être édité.'));
988 - }  
989 864
990 if ($from == 'index') 865 if ($from == 'index')
991 - return $this->redirect([  
992 - 'action' => $from  
993 - ]); 866 + return $this->redirect([ 'action' => $from]);
994 else 867 else
995 - return $this->redirect([  
996 - 'action' => $from,  
997 - $id  
998 - ]); 868 + return $this->redirect(['action' => $from, $id]);
999 } 869 }
1000 870
1001 /** 871 /**
@@ -1006,15 +876,11 @@ et Date de reception @@ -1006,15 +876,11 @@ et Date de reception
1006 */ 876 */
1007 public function statusValidated($id = null, $from = 'index') { 877 public function statusValidated($id = null, $from = 'index') {
1008 $this->statusSetTo('VALIDATED', 'Le matériel a bien été validé', $id, $from); 878 $this->statusSetTo('VALIDATED', 'Le matériel a bien été validé', $id, $from);
1009 - if (in_array($_SESSION['Auth']['User']['sn'][0], TableRegistry::get('Users')->find('list', [  
1010 - 'keyField' => 'id',  
1011 - 'valueField' => 'nom'  
1012 - ])->where([  
1013 - 'role =' => 'Administration'  
1014 - ])->toArray())) {  
1015 - $gestionnaireID = TableRegistry::get('Users')->find()->where([  
1016 - 'nom' => $_SESSION['Auth']['User']['sn'][0]  
1017 - ])->first()->id; 879 + if (in_array($_SESSION['Auth']['User']['sn'][0], TableRegistry::get('Users')
  880 + ->find('list', ['keyField' => 'id', 'valueField' => 'nom'])
  881 + ->where(['role =' => 'Administration'])
  882 + ->toArray())) {
  883 + $gestionnaireID = TableRegistry::get('Users')->find()->where(['nom' => $_SESSION['Auth']['User']['sn'][0]])->first()->id;
1018 $materiel->gestionnaire_id = $gestionnaireID; 884 $materiel->gestionnaire_id = $gestionnaireID;
1019 } 885 }
1020 $this->sendEmail($this->Materiels->get($id)); 886 $this->sendEmail($this->Materiels->get($id));
@@ -1051,9 +917,7 @@ et Date de reception @@ -1051,9 +917,7 @@ et Date de reception
1051 private function getConditionForField($fieldName) { 917 private function getConditionForField($fieldName) {
1052 $searchFieldName = 's_' . $fieldName; 918 $searchFieldName = 's_' . $fieldName;
1053 if (isset($this->request->data[$searchFieldName]) && ($this->request->data[$searchFieldName] != '')) 919 if (isset($this->request->data[$searchFieldName]) && ($this->request->data[$searchFieldName] != ''))
1054 - return [  
1055 - "Materiels.$fieldName LIKE" => '%' . $this->request->data[$searchFieldName] . '%'  
1056 - ]; 920 + return ["Materiels.$fieldName LIKE" => '%' . $this->request->data[$searchFieldName] . '%'];
1057 return NULL; 921 return NULL;
1058 } 922 }
1059 923
@@ -1066,9 +930,7 @@ et Date de reception @@ -1066,9 +930,7 @@ et Date de reception
1066 private function getConditionForFieldNumber($fieldName) { 930 private function getConditionForFieldNumber($fieldName) {
1067 $searchFieldName = 's_' . $fieldName; 931 $searchFieldName = 's_' . $fieldName;
1068 if (isset($this->request->data[$searchFieldName]) && ($this->request->data[$searchFieldName] != '')) 932 if (isset($this->request->data[$searchFieldName]) && ($this->request->data[$searchFieldName] != ''))
1069 - return [  
1070 - "Materiels.$fieldName =" => $this->request->data[$searchFieldName]  
1071 - ]; 933 + return ["Materiels.$fieldName =" => $this->request->data[$searchFieldName]];
1072 return NULL; 934 return NULL;
1073 } 935 }
1074 936
@@ -1139,22 +1001,13 @@ et Date de reception @@ -1139,22 +1001,13 @@ et Date de reception
1139 ) 1001 )
1140 ]); 1002 ]);
1141 $categories = $this->Materiels->Categories; 1003 $categories = $this->Materiels->Categories;
1142 -  
1143 $this->set(compact('s_numero_laboratoire', 's_nomresp', 's_sur_categories', 's_categories', 's_sous_categories', 's_groupes_thematiques', 's_groupes_metiers', 's_organismes', 's_fournisseurs', 's_salles', 'categories')); 1004 $this->set(compact('s_numero_laboratoire', 's_nomresp', 's_sur_categories', 's_categories', 's_sous_categories', 's_groupes_thematiques', 's_groupes_metiers', 's_organismes', 's_fournisseurs', 's_salles', 'categories'));
1144 -  
1145 $resultTri = $this->request->session()->read("resultTri"); 1005 $resultTri = $this->request->session()->read("resultTri");
1146 1006
1147 - if (! (in_array($this->role, [  
1148 - 'Administration',  
1149 - 'Administration Plus',  
1150 - 'Super Administrateur'  
1151 - ]))) {  
1152 - $conditionNotArchived = [  
1153 - 'Materiels.status !=' => 'ARCHIVED'  
1154 - ];  
1155 - } else { 1007 + if (! (in_array($this->role, ['Administration', 'Administration Plus', 'Super Administrateur'])))
  1008 + $conditionNotArchived = ['Materiels.status !=' => 'ARCHIVED'];
  1009 + else
1156 $conditionNotArchived = ''; 1010 $conditionNotArchived = '';
1157 - }  
1158 1011
1159 // some data POSTED (au moins le champ de recherche generale) ? 1012 // some data POSTED (au moins le champ de recherche generale) ?
1160 if (isset($this->request->data['s_all']) || isset($this->request->data['s_all_2']) || isset($this->request->data['s_designation'])) { 1013 if (isset($this->request->data['s_all']) || isset($this->request->data['s_all_2']) || isset($this->request->data['s_designation'])) {
@@ -1164,10 +1017,7 @@ et Date de reception @@ -1164,10 +1017,7 @@ et Date de reception
1164 $all = $this->request->data['s_all']; 1017 $all = $this->request->data['s_all'];
1165 1018
1166 // Check for a date 1019 // Check for a date
1167 - foreach ([  
1168 - "/",  
1169 - "-"  
1170 - ] as $symb) { 1020 + foreach (["/", "-"] as $symb) {
1171 $pos1 = strpos($all, $symb); // Première occurence 1021 $pos1 = strpos($all, $symb); // Première occurence
1172 $pos2 = strrchr($all, $symb); // Dernière occurence 1022 $pos2 = strrchr($all, $symb); // Dernière occurence
1173 if ($pos1 !== false && $pos1 != $pos2) { 1023 if ($pos1 !== false && $pos1 != $pos2) {
@@ -1203,10 +1053,7 @@ et Date de reception @@ -1203,10 +1053,7 @@ et Date de reception
1203 $all = $this->request->data['s_all_2']; 1053 $all = $this->request->data['s_all_2'];
1204 1054
1205 // Check for a date 1055 // Check for a date
1206 - foreach ([  
1207 - "/",  
1208 - "-"  
1209 - ] as $symb) { 1056 + foreach (["/", "-"] as $symb) {
1210 $pos1 = strpos($all, $symb); // Première occurence 1057 $pos1 = strpos($all, $symb); // Première occurence
1211 $pos2 = strrchr($all, $symb); // Dernière occurence 1058 $pos2 = strrchr($all, $symb); // Dernière occurence
1212 if ($pos1 !== false && $pos1 != $pos2) { 1059 if ($pos1 !== false && $pos1 != $pos2) {
@@ -1320,48 +1167,29 @@ et Date de reception @@ -1320,48 +1167,29 @@ et Date de reception
1320 $matostypeRequest 1167 $matostypeRequest
1321 ]; 1168 ];
1322 1169
1323 - if ($this->request->data['s_status'] != '') {  
1324 - array_push($specificFieldsConditions, [  
1325 - 'Materiels.status =' => $this->request->data['s_status']  
1326 - ]);  
1327 - } 1170 + if ($this->request->data['s_status'] != '')
  1171 + array_push($specificFieldsConditions, ['Materiels.status =' => $this->request->data['s_status']]);
1328 } 1172 }
1329 1173
1330 // CONSTRUCTION DE LA REQUETE SQL COMPLETE = $specificFieldsConditions OR $generalFieldConditions (mais entre chaque champ, c'est un AND) 1174 // CONSTRUCTION DE LA REQUETE SQL COMPLETE = $specificFieldsConditions OR $generalFieldConditions (mais entre chaque champ, c'est un AND)
1331 // by default, no sort 1175 // by default, no sort
  1176 + if (isset($this->request->data['s_all_2']) && $this->request->data['s_all_2'] != '')
  1177 + $conditions = [$generalFieldConditions, $conditionNotArchived];
  1178 + else if (isset($this->request->data['s_all']) && $this->request->data['s_all'] != '')
  1179 + $conditions = [$generalFieldConditions, $conditionNotArchived];
  1180 + else
  1181 + $conditions = [$specificFieldsConditions, $conditionNotArchived];
1332 1182
1333 - if (isset($this->request->data['s_all_2']) && $this->request->data['s_all_2'] != '') {  
1334 - $conditions = [  
1335 - $generalFieldConditions,  
1336 - $conditionNotArchived  
1337 - ];  
1338 - } else if (isset($this->request->data['s_all']) && $this->request->data['s_all'] != '') {  
1339 - $conditions = [  
1340 - $generalFieldConditions,  
1341 - $conditionNotArchived  
1342 - ];  
1343 - } else {  
1344 - $conditions = [  
1345 - $specificFieldsConditions,  
1346 - $conditionNotArchived  
1347 - ];  
1348 - }  
1349 -  
1350 - $lastResults = $this->Materiels->find('all', [  
1351 - 'limit' => 1000,  
1352 - 'conditions' => $conditions  
1353 - ]); 1183 + $lastResults = $this->Materiels->find('all', ['limit' => 1000, 'conditions' => $conditions]);
1354 1184
1355 - $this->paginate = [  
1356 - 'limit' => 1000  
1357 - ]; 1185 + $this->paginate = ['limit' => 1000];
1358 $_results = $this->paginate($lastResults); 1186 $_results = $this->paginate($lastResults);
1359 $this->set(compact('_results')); 1187 $this->set(compact('_results'));
1360 1188
1361 // pour l'export 1189 // pour l'export
1362 $this->request->session()->write("result", $lastResults->toArray()); 1190 $this->request->session()->write("result", $lastResults->toArray());
1363 } // end if() 1191 } // end if()
1364 -else if (isset($resultTri) && strstr($this->request->here(), 'sort') != false && strstr($this->request->here(), 'direction') != false) { 1192 + else if (isset($resultTri) && strstr($this->request->here(), 'sort') != false && strstr($this->request->here(), 'direction') != false) {
1365 $findedMateriel = []; 1193 $findedMateriel = [];
1366 1194
1367 foreach ($resultTri as $r) { 1195 foreach ($resultTri as $r) {
@@ -1391,11 +1219,9 @@ else if (isset($resultTri) &amp;&amp; strstr($this-&gt;request-&gt;here(), &#39;sort&#39;) != false &amp;&amp; @@ -1391,11 +1219,9 @@ else if (isset($resultTri) &amp;&amp; strstr($this-&gt;request-&gt;here(), &#39;sort&#39;) != false &amp;&amp;
1391 * group update status + exportAll 1219 * group update status + exportAll
1392 */ 1220 */
1393 public function execActions() { 1221 public function execActions() {
1394 - if (isset($this->request->data['updateSelectedStatus'])) { 1222 + if (isset($this->request->data['updateSelectedStatus']))
1395 $this->updateSelectedStatus(); 1223 $this->updateSelectedStatus();
1396 - } else {  
1397 - $this->export();  
1398 - } 1224 + else $this->export();
1399 } 1225 }
1400 1226
1401 /** 1227 /**
@@ -1407,48 +1233,42 @@ else if (isset($resultTri) &amp;&amp; strstr($this-&gt;request-&gt;here(), &#39;sort&#39;) != false &amp;&amp; @@ -1407,48 +1233,42 @@ else if (isset($resultTri) &amp;&amp; strstr($this-&gt;request-&gt;here(), &#39;sort&#39;) != false &amp;&amp;
1407 $this->myDebug($this->request->data); 1233 $this->myDebug($this->request->data);
1408 $what = $this->request->data['what']; 1234 $what = $this->request->data['what'];
1409 $nb = 0; 1235 $nb = 0;
1410 - 1236 +
1411 if (in_array($what, $this->NOTARCHIVED)) { 1237 if (in_array($what, $this->NOTARCHIVED)) {
1412 foreach ($this->request->data as $id => $value) : 1238 foreach ($this->request->data as $id => $value) :
1413 - if ($value == 1) {  
1414 - switch ($what) {  
1415 - case 'CREATED' :  
1416 - $new = 'VALIDATED';  
1417 - break;  
1418 - case 'VALIDATED' :  
1419 - $new = 'TOBEARCHIVED';  
1420 - break;  
1421 - case 'TOBEARCHIVED' :  
1422 - $new = 'ARCHIVED';  
1423 - break;  
1424 - }  
1425 - // if mode_debug desactivate  
1426 - if (! $this->isLabinventDebugMode()) {  
1427 - $materiel = $this->Materiels->get($id);  
1428 - if (! isset($materiel->nom_responsable) || ! isset($materiel->fournisseur) || ! isset($materiel->numero_commande) || ! isset($materiel->organisme_id) || ! isset($materiel->date_reception) || ! isset($materiel->prix_ht)) {  
1429 - $this->Flash->error('le materiel ' . $materiel->designation . '-' . $materiel->numero_laboratoire . ' n\'a pas pu etre validé car un des champs nécessaires n\'est pas rempli');  
1430 - $nb --;  
1431 - } else {  
1432 - $materiel->set('status', $new);  
1433 - $this->Materiels->save($materiel, [ 1239 + if ($value == 1) {
  1240 + switch ($what) {
  1241 + case 'CREATED' : $new = 'VALIDATED'; break;
  1242 + case 'VALIDATED' : $new = 'TOBEARCHIVED'; break;
  1243 + case 'TOBEARCHIVED' : $new = 'ARCHIVED'; break;
  1244 + }
  1245 + // if mode_debug desactivate
  1246 + if (! $this->isLabinventDebugMode()) {
  1247 + $materiel = $this->Materiels->get($id);
  1248 + if (! isset($materiel->nom_responsable) || ! isset($materiel->fournisseur) || ! isset($materiel->numero_commande) || ! isset($materiel->organisme_id) || ! isset($materiel->date_reception) || ! isset($materiel->prix_ht)) {
  1249 + $this->Flash->error('le materiel ' . $materiel->designation . '-' . $materiel->numero_laboratoire . ' n\'a pas pu etre validé car un des champs nécessaires n\'est pas rempli');
  1250 + $nb --;
  1251 + } else {
  1252 + $materiel->set('status', $new);
  1253 + $this->Materiels->save($materiel, [
1434 'checkRules' => false, 1254 'checkRules' => false,
1435 'checkExisting' => false 1255 'checkExisting' => false
1436 - ]);  
1437 - } 1256 + ]);
1438 } 1257 }
1439 - $nb ++;  
1440 } 1258 }
  1259 + $nb ++;
  1260 + }
1441 endforeach 1261 endforeach
1442 ; 1262 ;
1443 if ($nb != 0) 1263 if ($nb != 0)
1444 - $this->Flash->success(__($nb . ' matériel(s) mis à jour'));  
1445 - $this->myDebug("Nb matos = " . $nb);  
1446 -  
1447 - if (! $this->isLabinventDebugMode())  
1448 - return $this->redirect([  
1449 - 'action' => 'index',  
1450 - $what  
1451 - ]); 1264 + $this->Flash->success(__($nb . ' matériel(s) mis à jour'));
  1265 + $this->myDebug("Nb matos = " . $nb);
  1266 +
  1267 + if (! $this->isLabinventDebugMode())
  1268 + return $this->redirect([
  1269 + 'action' => 'index',
  1270 + $what
  1271 + ]);
1452 } 1272 }
1453 } 1273 }
1454 } 1274 }
@@ -1579,9 +1399,7 @@ else if (isset($resultTri) &amp;&amp; strstr($this-&gt;request-&gt;here(), &#39;sort&#39;) != false &amp;&amp; @@ -1579,9 +1399,7 @@ else if (isset($resultTri) &amp;&amp; strstr($this-&gt;request-&gt;here(), &#39;sort&#39;) != false &amp;&amp;
1579 'Content-Disposition: attachment; filename="' . $filename . '"' 1399 'Content-Disposition: attachment; filename="' . $filename . '"'
1580 ]); 1400 ]);
1581 $this->response->sendHeaders(); 1401 $this->response->sendHeaders();
1582 - $configuration = TableRegistry::get('Configurations')->find()->where([  
1583 - 'id =' => 1  
1584 - ])->first(); 1402 + $configuration = $this->confLabinvent;
1585 $nomgroupemetier = $configuration->nom_groupe_metier; 1403 $nomgroupemetier = $configuration->nom_groupe_metier;
1586 $nomgroupethematique = $configuration->nom_groupe_thematique; 1404 $nomgroupethematique = $configuration->nom_groupe_thematique;
1587 1405
@@ -1801,15 +1619,13 @@ else if (isset($resultTri) &amp;&amp; strstr($this-&gt;request-&gt;here(), &#39;sort&#39;) != false &amp;&amp; @@ -1801,15 +1619,13 @@ else if (isset($resultTri) &amp;&amp; strstr($this-&gt;request-&gt;here(), &#39;sort&#39;) != false &amp;&amp;
1801 1619
1802 $filename = 'inventirap_label.label'; 1620 $filename = 'inventirap_label.label';
1803 $file = fopen('php://output', 'w'); 1621 $file = fopen('php://output', 'w');
1804 - $this->response->header([  
1805 - 'Content-type: application/xml',  
1806 - 'Content-Disposition: attachment; filename="' . $filename . '"'  
1807 - ]); 1622 + $this->response->header(['Content-type: application/xml', 'Content-Disposition: attachment; filename="' . $filename . '"']);
1808 $this->response->sendHeaders(); 1623 $this->response->sendHeaders();
1809 - 1624 +
1810 /* 1625 /*
1811 * SIMPLE LABEL FOR PRINTER DYMO LabelWriter 450 : NO LOGO 1626 * SIMPLE LABEL FOR PRINTER DYMO LabelWriter 450 : NO LOGO
1812 */ 1627 */
  1628 +
1813 /* 1629 /*
1814 * '<?xml version="1.0" encoding="utf-8"?> 1630 * '<?xml version="1.0" encoding="utf-8"?>
1815 * <DieCutLabel Version="8.0" Units="twips"> 1631 * <DieCutLabel Version="8.0" Units="twips">
@@ -2091,16 +1907,12 @@ else if (isset($resultTri) &amp;&amp; strstr($this-&gt;request-&gt;here(), &#39;sort&#39;) != false &amp;&amp; @@ -2091,16 +1907,12 @@ else if (isset($resultTri) &amp;&amp; strstr($this-&gt;request-&gt;here(), &#39;sort&#39;) != false &amp;&amp;
2091 $date_next = date_create_from_format('d-m-Y', $date); 1907 $date_next = date_create_from_format('d-m-Y', $date);
2092 1908
2093 switch ($unite) { 1909 switch ($unite) {
2094 - case "Mois" :  
2095 - date_add($date_next, date_interval_create_from_date_string($duree . ' months'));  
2096 - break;  
2097 - case "Ans" :  
2098 - date_add($date_next, date_interval_create_from_date_string($duree . ' years'));  
2099 - break; 1910 + case "Mois" : date_add($date_next, date_interval_create_from_date_string($duree . ' months')); break;
  1911 + case "Ans" : date_add($date_next, date_interval_create_from_date_string($duree . ' years')); break;
2100 } 1912 }
2101 1913
2102 $this->set('date', date_format($date_next, 'd-m-Y')); 1914 $this->set('date', date_format($date_next, 'd-m-Y'));
2103 - 1915 +
2104 $this->viewBuilder()->layout = 'ajax'; 1916 $this->viewBuilder()->layout = 'ajax';
2105 } 1917 }
2106 1918
@@ -2132,10 +1944,7 @@ else if (isset($resultTri) &amp;&amp; strstr($this-&gt;request-&gt;here(), &#39;sort&#39;) != false &amp;&amp; @@ -2132,10 +1944,7 @@ else if (isset($resultTri) &amp;&amp; strstr($this-&gt;request-&gt;here(), &#39;sort&#39;) != false &amp;&amp;
2132 $this->set('sites', $sites); 1944 $this->set('sites', $sites);
2133 $this->set('typeSuivis', $typeSuivis); 1945 $this->set('typeSuivis', $typeSuivis);
2134 $this->set('typeDocuments', $typeDocuments); 1946 $this->set('typeDocuments', $typeDocuments);
2135 -  
2136 $this->set('materiel', $materiel); 1947 $this->set('materiel', $materiel);
2137 - $this->set('_serialize', [  
2138 - 'materiel'  
2139 - ]); 1948 + $this->set('_serialize', ['materiel']);
2140 } 1949 }
2141 } 1950 }
src/Controller/OrganismesController.php
@@ -25,7 +25,7 @@ class OrganismesController extends AppController @@ -25,7 +25,7 @@ class OrganismesController extends AppController
25 */ 25 */
26 public function isAuthorized($user) 26 public function isAuthorized($user)
27 { 27 {
28 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 28 + $configuration = $this->confLabinvent;
29 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 29 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
30 $action = $this->request->params['action']; 30 $action = $this->request->params['action'];
31 31
src/Controller/PagesController.php
@@ -40,7 +40,7 @@ class PagesController extends AppController @@ -40,7 +40,7 @@ class PagesController extends AppController
40 { 40 {
41 41
42 42
43 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 43 + $configuration = $this->confLabinvent;
44 44
45 $path = func_get_args(); 45 $path = func_get_args();
46 if(!(isset($path[0]))) { 46 if(!(isset($path[0]))) {
src/Controller/SitesController.php
@@ -21,7 +21,7 @@ class SitesController extends AppController @@ -21,7 +21,7 @@ class SitesController extends AppController
21 */ 21 */
22 public function isAuthorized($user) 22 public function isAuthorized($user)
23 { 23 {
24 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 24 + $configuration = $this->confLabinvent;
25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
26 $action = $this->request->params['action']; 26 $action = $this->request->params['action'];
27 27
src/Controller/SousCategoriesController.php
@@ -24,7 +24,7 @@ class SousCategoriesController extends AppController @@ -24,7 +24,7 @@ class SousCategoriesController extends AppController
24 */ 24 */
25 public function isAuthorized($user) 25 public function isAuthorized($user)
26 { 26 {
27 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 27 + $configuration = $this->confLabinvent;
28 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 28 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
29 $action = $this->request->params['action']; 29 $action = $this->request->params['action'];
30 30
src/Controller/SuivisController.php
@@ -18,11 +18,7 @@ class SuivisController extends AppController { @@ -18,11 +18,7 @@ class SuivisController extends AppController {
18 * @return boolean 18 * @return boolean
19 */ 19 */
20 public function isAuthorized($user) { 20 public function isAuthorized($user) {
21 - $configuration = TableRegistry::get('Configurations')->find()  
22 - ->where([  
23 - 'id =' => 1  
24 - ])  
25 - ->first(); 21 + $configuration = $this->confLabinvent;
26 $role = TableRegistry::get('Users')->find() 22 $role = TableRegistry::get('Users')->find()
27 ->where([ 23 ->where([
28 'username' => $user[$configuration->authentificationType_ldap][0] 24 'username' => $user[$configuration->authentificationType_ldap][0]
src/Controller/SurCategoriesController.php
@@ -25,7 +25,7 @@ class SurCategoriesController extends AppController @@ -25,7 +25,7 @@ class SurCategoriesController extends AppController
25 */ 25 */
26 public function isAuthorized($user) 26 public function isAuthorized($user)
27 { 27 {
28 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 28 + $configuration = $this->confLabinvent;
29 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 29 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
30 $action = $this->request->params['action']; 30 $action = $this->request->params['action'];
31 31
src/Controller/TypeDocumentsController.php
@@ -21,7 +21,7 @@ class TypeDocumentsController extends AppController @@ -21,7 +21,7 @@ class TypeDocumentsController extends AppController
21 */ 21 */
22 public function isAuthorized($user) 22 public function isAuthorized($user)
23 { 23 {
24 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 24 + $configuration = $this->confLabinvent;
25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
26 $action = $this->request->params['action']; 26 $action = $this->request->params['action'];
27 27
src/Controller/TypeSuivisController.php
@@ -21,7 +21,7 @@ class TypeSuivisController extends AppController @@ -21,7 +21,7 @@ class TypeSuivisController extends AppController
21 */ 21 */
22 public function isAuthorized($user) 22 public function isAuthorized($user)
23 { 23 {
24 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 24 + $configuration = $this->confLabinvent;
25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
26 $action = $this->request->params['action']; 26 $action = $this->request->params['action'];
27 27
src/Controller/UnitesController.php
@@ -21,7 +21,7 @@ class UnitesController extends AppController @@ -21,7 +21,7 @@ class UnitesController extends AppController
21 */ 21 */
22 public function isAuthorized($user) 22 public function isAuthorized($user)
23 { 23 {
24 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 24 + $configuration = $this->confLabinvent;
25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 25 $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
26 $action = $this->request->params['action']; 26 $action = $this->request->params['action'];
27 27
src/Controller/UsersController.php
@@ -27,7 +27,7 @@ class UsersController extends AppController @@ -27,7 +27,7 @@ class UsersController extends AppController
27 */ 27 */
28 public function isAuthorized($user) 28 public function isAuthorized($user)
29 { 29 {
30 - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 30 + $configuration = $this->confLabinvent;
31 $role = $this->Users->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; 31 $role = $this->Users->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role'];
32 32
33 $action = $this->request->params['action']; 33 $action = $this->request->params['action'];
src/Model/Table/DocumentsTable.php
@@ -99,17 +99,14 @@ class DocumentsTable extends AppTable @@ -99,17 +99,14 @@ class DocumentsTable extends AppTable
99 $config = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); 99 $config = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first();
100 $size = $entity->get('chemin_file')['size']; 100 $size = $entity->get('chemin_file')['size'];
101 if(isset($size)) { 101 if(isset($size)) {
102 - if($size > $config->taille_max_doc) { 102 + if($size > $config->taille_max_doc)
103 return false; 103 return false;
104 - } else { 104 + else
105 return true; 105 return true;
106 - }  
107 - } else { 106 + } else
108 return false; 107 return false;
109 - }  
110 - } else { 108 + } else
111 return true; 109 return true;
112 - }  
113 }; 110 };
114 111
115 $checkPhoto= function($entity) { 112 $checkPhoto= function($entity) {
@@ -118,12 +115,10 @@ class DocumentsTable extends AppTable @@ -118,12 +115,10 @@ class DocumentsTable extends AppTable
118 $extension = strtolower(pathinfo($entity->get('chemin_file')['name'] , PATHINFO_EXTENSION)); 115 $extension = strtolower(pathinfo($entity->get('chemin_file')['name'] , PATHINFO_EXTENSION));
119 return in_array($extension, ['png', 'jpg', 'jpeg']); 116 return in_array($extension, ['png', 'jpg', 'jpeg']);
120 } 117 }
121 - else { 118 + else
122 return true; 119 return true;
123 - }  
124 - } else { 120 + } else
125 return true; 121 return true;
126 - }  
127 }; 122 };
128 123
129 $checkEditFile= function($entity) { 124 $checkEditFile= function($entity) {
src/Template/Materiels/index.ctp
@@ -99,26 +99,18 @@ if (isset ( $STATUS )) { @@ -99,26 +99,18 @@ if (isset ( $STATUS )) {
99 ]); 99 ]);
100 } 100 }
101 } 101 }
102 -  
103 - // Rajouté par Thibault Ajas, 20/04/2017  
104 - echo $this->Form->create(); 102 +?>
  103 +</div>
  104 +
  105 +<?php
  106 +if ($nbMateriels != 0) {
  107 + echo $this->Form->create('materiels', ['url' => '/materiels/execActions']);
105 echo $this->Form->input('aff_par_defaut', [ 108 echo $this->Form->input('aff_par_defaut', [
106 'label' => 'Afficher', 109 'label' => 'Afficher',
107 'options' => ['20'=> 20, '30'=>30, '50'=>50, '100'=>100, '150'=>150, '200'=>200], 110 'options' => ['20'=> 20, '30'=>30, '50'=>50, '100'=>100, '150'=>150, '200'=>200],
108 ]); 111 ]);
109 - $this->Form->end();  
110 - // Fin ajout 112 + if(isset($STATUS)) echo $this->Form->hidden ( 'what', ['value' => $STATUS]);
111 ?> 113 ?>
112 -</div>  
113 -  
114 -<?php if ($nbMateriels != 0) { ?>  
115 -  
116 -<?= $this->Form->create('materiels', ['url' => '/materiels/execActions']) ?>  
117 -  
118 - <?php if(isset($STATUS)) {  
119 - echo $this->Form->hidden ( 'what', ['value' => $STATUS]);  
120 - }  
121 - ?>  
122 114
123 <table style="border-collapse: separate; border-spacing: 0;"> 115 <table style="border-collapse: separate; border-spacing: 0;">
124 <thead> 116 <thead>
@@ -140,7 +132,7 @@ if (isset ( $STATUS )) { @@ -140,7 +132,7 @@ if (isset ( $STATUS )) {
140 <tbody> 132 <tbody>
141 133
142 <?php 134 <?php
143 - // Pour changer la couleur du nom du matos si la garantie est passée - Ajout par Thibault Ajas le 28/04/2017 135 + // Pour changer la couleur du nom du matos si la garantie est passée
144 $time = Time::now(); // On récupère la date et l'heure actuelles 136 $time = Time::now(); // On récupère la date et l'heure actuelles
145 $today = new date("$time->year-$time->month-$time->day"); // On extrait la date pour la vérification de fin de garantie 137 $today = new date("$time->year-$time->month-$time->day"); // On extrait la date pour la vérification de fin de garantie
146 $today = $today->format('Ydm'); // On formatte la date initialement en 31-12-2000 (par exemple) en un format qui pourra etre comparé : 20001231 138 $today = $today->format('Ydm'); // On formatte la date initialement en 31-12-2000 (par exemple) en un format qui pourra etre comparé : 20001231
@@ -154,8 +146,8 @@ if (isset ( $STATUS )) { @@ -154,8 +146,8 @@ if (isset ( $STATUS )) {
154 $dateFin = new date("$timeFin->year-$timeFin->month-$timeFin->day"); 146 $dateFin = new date("$timeFin->year-$timeFin->month-$timeFin->day");
155 $dateFin = $dateFin->format('Ydm'); 147 $dateFin = $dateFin->format('Ydm');
156 } 148 }
157 - if($materiel->date_fin_garantie !== NULL) $styleLien = ($today >= $dateFin) ? 'style="color: #FF0000"' : '' ; else $styleLien = '';  
158 - // Fin ajout - Utilisation de la variable $styleLien ligne 213 149 + if($materiel->date_fin_garantie !== NULL) $styleLien = ($today >= $dateFin) ? 'style="color: #FF0000"' : '' ;
  150 + else $styleLien = '';
159 ?> 151 ?>
160 152
161 <tr> 153 <tr>
@@ -256,45 +248,39 @@ if (isset ( $STATUS )) { @@ -256,45 +248,39 @@ if (isset ( $STATUS )) {
256 </table> 248 </table>
257 249
258 <?php 250 <?php
259 - if (isset ( $STATUS )) {  
260 - switch ($STATUS) {  
261 - case 'CREATED' :  
262 - $action = 'Valider les';  
263 - break;  
264 - case 'VALIDATED' :  
265 - $action = "Demander l'archivage des";  
266 - break;  
267 - case 'TOBEARCHIVED' :  
268 - $action = "Sortir les";  
269 - break;  
270 - }  
271 -  
272 - if ($STATUS != 'ARCHIVED') {  
273 - if(!($role == 'Super Administrateur' && $STATUS == 'TOBEARCHIVED')) {  
274 - echo $this->Form->submit ( $action . ' matériels cochés', [  
275 - 'name' => 'updateSelectedStatus',  
276 - 'id' => 'updateSelectedStatus',  
277 - 'style' => 'margin: 0px'  
278 - ]);  
279 - echo "<br /><br />" ;  
280 - }  
281 - }  
282 - echo $this->Form->submit ( 'Exporter la liste des matériels cochés', [  
283 - 'name' => 'export',  
284 - 'id' => 'export',  
285 - 'style' => 'margin: 0px;'  
286 - ]);  
287 - echo "<br /><br />" ;  
288 - }  
289 -  
290 -  
291 - if(in_array($role, ['Responsable', 'Administration', 'Administration Plus', 'Super Administrateur'])):  
292 - echo $this->Form->submit('Exporter la liste complete (toutes les pages)', [  
293 - 'name' => 'exportAll',  
294 - 'id' => 'exportAll',  
295 - 'style' => 'margin: 0px;'  
296 - ]);  
297 - endif; 251 + if (isset ( $STATUS )) {
  252 + switch ($STATUS) {
  253 + case 'CREATED' : $action = 'Valider les'; break;
  254 + case 'VALIDATED' : $action = "Demander l'archivage des"; break;
  255 + case 'TOBEARCHIVED' : $action = "Sortir les"; break;
  256 + }
  257 +
  258 + if ($STATUS != 'ARCHIVED') {
  259 + if(!($role == 'Super Administrateur' && $STATUS == 'TOBEARCHIVED')) {
  260 + echo $this->Form->submit ( $action . ' matériels cochés', [
  261 + 'name' => 'updateSelectedStatus',
  262 + 'id' => 'updateSelectedStatus',
  263 + 'style' => 'margin: 0px'
  264 + ]);
  265 + echo "<br />" ;
  266 + }
  267 + }
  268 + echo $this->Form->submit ( 'Exporter la liste des matériels cochés', [
  269 + 'name' => 'export',
  270 + 'id' => 'export',
  271 + 'style' => 'margin: 0px;'
  272 + ]);
  273 + echo "<br />" ;
  274 + }
  275 +
  276 + if(in_array($role, ['Responsable', 'Administration', 'Administration Plus', 'Super Administrateur'])):
  277 + echo $this->Form->submit('Exporter la liste complete (toutes les pages)', [
  278 + 'name' => 'exportAll',
  279 + 'id' => 'exportAll',
  280 + 'style' => 'margin: 0px;'
  281 + ]);
  282 + endif;
  283 +
298 ?> 284 ?>
299 285
300 <div class="paging" style="color: black;"> 286 <div class="paging" style="color: black;">
src/Template/Materiels/view.ctp
@@ -7,7 +7,7 @@ use Cake\ORM\TableRegistry; @@ -7,7 +7,7 @@ use Cake\ORM\TableRegistry;
7 // Set some useful global variables for this view 7 // Set some useful global variables for this view
8 8
9 // 1) Materiel settings 9 // 1) Materiel settings
10 -/* 10 +
11 const CREATED = 1; 11 const CREATED = 1;
12 const VALIDATED = 2; 12 const VALIDATED = 2;
13 const TOBEARCHIVED = 3; 13 const TOBEARCHIVED = 3;
@@ -48,7 +48,7 @@ $USER_IS_ADMINPLUS = ($profile == $PROFILE_ADMINPLUS); @@ -48,7 +48,7 @@ $USER_IS_ADMINPLUS = ($profile == $PROFILE_ADMINPLUS);
48 $USER_IS_SUPERADMIN = ($profile == $PROFILE_SUPERADMIN); 48 $USER_IS_SUPERADMIN = ($profile == $PROFILE_SUPERADMIN);
49 49
50 $USER_IS_ADMIN_OR_MORE = $profile >= $PROFILE_ADMIN; 50 $USER_IS_ADMIN_OR_MORE = $profile >= $PROFILE_ADMIN;
51 -*/ 51 +
52 52
53 $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER = $USER_IS_UTILISATEUR && in_array($username, [$materiel->nom_createur, $materiel->nom_responsable]); 53 $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER = $USER_IS_UTILISATEUR && in_array($username, [$materiel->nom_createur, $materiel->nom_responsable]);
54 54