Commit aaf7558a528aeeac9b244e16c1d7de426e70ac01
1 parent
7e8c1ba2
Exists in
master
and in
3 other branches
modifications de lisibilité mineures du code
Showing
24 changed files
with
369 additions
and
954 deletions
Show diff stats
src/Controller/AppController.php
... | ... | @@ -61,34 +61,24 @@ class AppController extends Controller { |
61 | 61 | $this->loadComponent('RequestHandler'); |
62 | 62 | $this->loadComponent('Flash'); |
63 | 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 | 75 | * @return boolean |
86 | 76 | */ |
87 | 77 | public function isAuthorized($user) { |
88 | 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 | 83 | $action = $this->request->params['action']; |
94 | 84 | |
... | ... | @@ -99,15 +89,7 @@ class AppController extends Controller { |
99 | 89 | return true; |
100 | 90 | |
101 | 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 | 93 | return true; |
112 | 94 | |
113 | 95 | // ACL : Par défaut refuser |
... | ... | @@ -115,108 +97,70 @@ class AppController extends Controller { |
115 | 97 | } |
116 | 98 | |
117 | 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 | 105 | $isAuthorized = false; |
126 | 106 | |
127 | 107 | switch ($roleDefine) { |
128 | 108 | case 'Super Administrateur' : |
129 | - if (in_array($role, [ | |
130 | - 'Super Administrateur' | |
131 | - ])) | |
109 | + if (in_array($role, ['Super Administrateur'])) | |
132 | 110 | $isAuthorized = true; |
133 | 111 | break; |
134 | 112 | |
135 | 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 | 115 | $isAuthorized = true; |
141 | 116 | break; |
142 | 117 | |
143 | 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 | 120 | $isAuthorized = true; |
150 | 121 | break; |
151 | 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 | 124 | $isAuthorized = true; |
159 | 125 | break; |
160 | 126 | |
161 | 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 | 129 | $isAuthorized = true; |
170 | 130 | break; |
171 | 131 | } |
172 | - | |
173 | 132 | return $isAuthorized; |
174 | 133 | } |
175 | 134 | |
176 | 135 | /** |
177 | - * | |
178 | 136 | * {@inheritdoc} |
179 | 137 | * |
180 | 138 | * @see \Cake\Controller\Controller::beforeFilter() |
181 | 139 | */ |
182 | 140 | public function beforeFilter(Event $event) { |
183 | 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 | 149 | $this->LdapAuth->config('authError', "Désolé, vous n'êtes pas autorisé à accéder à cette zone."); |
202 | 150 | } |
203 | 151 | |
204 | 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 | 154 | $this->request->session()->write("retourForm1", true); |
210 | - } else if ($this->request->params['action'] != 'creer') { | |
155 | + else if ($this->request->params['action'] != 'creer') | |
211 | 156 | $this->request->session()->write("retourForm1", false); |
212 | - } | |
213 | 157 | } |
214 | 158 | |
215 | 159 | /** |
216 | 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 | 164 | * @return void |
221 | 165 | */ |
222 | 166 | public function beforeRender(Event $event) { |
... | ... | @@ -228,23 +172,18 @@ class AppController extends Controller { |
228 | 172 | $this->set('PROFILE_SUPERADMIN', self::PROFILE_SUPERADMIN); |
229 | 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 | 176 | $this->set('_serialize', true); |
236 | - } | |
177 | + | |
237 | 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 | 181 | $this->set('configuration', $configuration); |
243 | 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 | 188 | $role = $user['role']; |
250 | 189 | if ($role == null) |
... | ... | @@ -274,12 +213,8 @@ class AppController extends Controller { |
274 | 213 | |
275 | 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 | 219 | $displayElement = function ($nom, $valeur, $params = "") { |
285 | 220 | $balise = ($params != "") ? '<td ' . $params . '>' : '<td>'; |
... | ... | @@ -291,208 +226,9 @@ class AppController extends Controller { |
291 | 226 | } |
292 | 227 | |
293 | 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 | 233 | function myDebug($arg, $stop = false) { |
498 | 234 | if ($this->isLabinventDebugMode()) { |
... | ... | @@ -516,17 +252,17 @@ class AppController extends Controller { |
516 | 252 | public function sendEmail($obj, $subject = null, $msg = null) { |
517 | 253 | /* |
518 | 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 | 261 | $configuration = $this->confLabinvent; |
526 | 262 | $action = $this->request->params['action']; // add or edit or delete or ... |
527 | 263 | |
528 | 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 | 266 | return null; |
531 | 267 | |
532 | 268 | $materiel = $obj; |
... | ... | @@ -580,6 +316,7 @@ class AppController extends Controller { |
580 | 316 | // Et maintenant on construit la liste de mails ... |
581 | 317 | // Si l'envoi général est activé (et que l'action ne correspond pas à 'printLabelRuban'): |
582 | 318 | if ($configuration->envoi_mail && $action != 'printLabelRuban') { |
319 | + | |
583 | 320 | // mail owner |
584 | 321 | $mailList[0] = $materiel->email_responsable; |
585 | 322 | |
... | ... | @@ -589,10 +326,9 @@ class AppController extends Controller { |
589 | 326 | |
590 | 327 | if ($materiel->groupes_metier_id != null && $materiel->groupes_metier_id != 1) |
591 | 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 | 333 | if ($mailsRespMetier != null && $mailsRespMetier != null) { |
598 | 334 | $mailResp = array_unique(array_merge($mailsRespMetier, $mailRespThematique)); |
... | ... | @@ -607,11 +343,8 @@ class AppController extends Controller { |
607 | 343 | |
608 | 344 | /* |
609 | 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 | 348 | * ->toArray(); |
616 | 349 | * for ($i = 0; $i < sizeof($mailsAdmin); $i ++) { |
617 | 350 | * $mailList[sizeof($mailList)] = $mailsAdmin[$i]['email']; |
... | ... | @@ -639,15 +372,15 @@ class AppController extends Controller { |
639 | 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 | 373 | if ($mail != $_SESSION['Auth']['User']['mail'][0]) { |
641 | 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 | 377 | if ($action != 'statusValidated' && $materiel != null) |
643 | 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 | 379 | if ($role) |
648 | 380 | $role = 'en tant que ' . $role; |
649 | 381 | else |
650 | 382 | $role = 'car vous avez demandé à le recevoir. Pour faire retirer votre mail de la liste, veuillez contacter un SuperAdmin'; |
383 | + | |
651 | 384 | $message .= "\n\n" . 'Vous recevez ce message ' . $role; |
652 | 385 | $this->sendEmailTo("$subject", $message, $mail, $configuration); |
653 | 386 | } |
... | ... | @@ -657,23 +390,12 @@ class AppController extends Controller { |
657 | 390 | |
658 | 391 | // Fonction d'envoi de mails |
659 | 392 | private function sendEmailTo($subject, $msg, $mail, $config) { |
660 | - if ($mail != null && ! $config->test) { | |
393 | + if ($mail != null && !$config->test) { | |
661 | 394 | if (filter_var($mail, FILTER_VALIDATE_EMAIL)) { |
662 | 395 | $email = new Email(); |
663 | - | |
664 | 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 | 26 | */ |
27 | 27 | public function isAuthorized($user) |
28 | 28 | { |
29 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
29 | + $configuration = $this->confLabinvent; | |
30 | 30 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
31 | 31 | $action = $this->request->params['action']; |
32 | 32 | ... | ... |
src/Controller/ConfigurationsController.php
... | ... | @@ -34,7 +34,7 @@ class ConfigurationsController extends AppController |
34 | 34 | */ |
35 | 35 | public function isAuthorized($user) |
36 | 36 | { |
37 | - $configuration = $this->Configurations->find()->where(['id =' => 1])->first(); | |
37 | + $configuration = $this->confLabinvent; | |
38 | 38 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
39 | 39 | $action = $this->request->params['action']; |
40 | 40 | |
... | ... | @@ -81,6 +81,7 @@ class ConfigurationsController extends AppController |
81 | 81 | $configurationObj = $this->Configurations->patchEntity($configurationObj, $this->request->data); |
82 | 82 | if ($this->Configurations->save($configurationObj)) { |
83 | 83 | $this->Flash->success(__('La configuration a bien été sauvegardée.')); |
84 | + // On reload la configuration | |
84 | 85 | $this->confLabinvent = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); |
85 | 86 | if($configurationObj->get('mode_install')) { |
86 | 87 | return $this->redirect(['controller' => 'pages', 'action' => 'home']); | ... | ... |
src/Controller/DocumentsController.php
... | ... | @@ -20,12 +20,10 @@ class DocumentsController extends AppController { |
20 | 20 | * @return boolean |
21 | 21 | */ |
22 | 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 | 27 | $action = $this->request->params['action']; |
30 | 28 | |
31 | 29 | // Super-Admin peut accéder à chaque action |
... | ... | @@ -301,15 +299,9 @@ class DocumentsController extends AppController { |
301 | 299 | * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. |
302 | 300 | */ |
303 | 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 | 305 | $document = $this->Documents->patchEntity($document, $this->request->data); |
314 | 306 | |
315 | 307 | if ($this->Documents->save($document)) { |
... | ... | @@ -318,57 +310,31 @@ class DocumentsController extends AppController { |
318 | 310 | $id = $document->materiel_id; |
319 | 311 | if (empty($id)) { |
320 | 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 | 317 | $this->Flash->error(__('Le fichier n\'a pas pu être edité.')); |
335 | - } | |
336 | 318 | } |
337 | 319 | |
338 | 320 | $id = $document->materiel_id; |
339 | 321 | if (empty($id)) { |
340 | 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 | 324 | $this->set('suivi', $suivi); |
348 | 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 | 328 | $this->set('materiel', $materiel); |
356 | 329 | } |
357 | 330 | |
358 | - if ($document->photo) { | |
331 | + if ($document->photo) | |
359 | 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 | 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 | 346 | * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. |
381 | 347 | */ |
382 | 348 | public function delete($id = null) { |
383 | - $this->request->allowMethod([ | |
384 | - 'post', | |
385 | - 'delete' | |
386 | - ]); | |
349 | + $this->request->allowMethod(['post', 'delete']); | |
387 | 350 | $document = $this->Documents->get($id); |
388 | 351 | |
389 | 352 | if ($document->photo) { |
... | ... | @@ -394,41 +357,27 @@ class DocumentsController extends AppController { |
394 | 357 | $materielTable->save($materiel); |
395 | 358 | } |
396 | 359 | |
397 | - if ($this->Documents->delete($document)) { | |
360 | + if ($this->Documents->delete($document)) | |
398 | 361 | $this->Flash->success(__('Le fichier a bien été supprimé.')); |
399 | - } else { | |
362 | + else | |
400 | 363 | $this->Flash->error(__('Le fichier n\'a pas pu être supprimé.')); |
401 | - } | |
402 | - | |
364 | + | |
403 | 365 | $id = $document->materiel_id; |
366 | + | |
404 | 367 | if (empty($id)) { |
405 | 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 | 376 | public function admission($labNumber) { |
425 | 377 | $this->set('fpdf', new FPDF('P', 'mm', 'A4')); |
426 | 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 | 382 | // Get the administration user name |
434 | 383 | $userName = $this->LdapAuth->user('username'); |
... | ... | @@ -437,13 +386,10 @@ class DocumentsController extends AppController { |
437 | 386 | $dateAcquisition = $dateAcquisition; |
438 | 387 | $numeroCommande = $materiel->numero_commande; |
439 | 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 | 392 | $organisme = ""; |
446 | - } | |
447 | 393 | |
448 | 394 | $fournisseur = $materiel->fournisseur; |
449 | 395 | $numeroOrganisme = $materiel->numero_inventaire_organisme; |
... | ... | @@ -471,70 +417,48 @@ class DocumentsController extends AppController { |
471 | 417 | public function ficheMateriel($labNumber) { |
472 | 418 | |
473 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 460 | $site = ' '; |
534 | - } | |
535 | - $configuration = TableRegistry::get('Configurations')->find()->where([ | |
536 | - 'id =' => 1 | |
537 | - ])->first(); | |
461 | + $configuration = $this->confLabinvent; | |
538 | 462 | $nom_groupe_thematique = $configuration->nom_groupe_thematique; |
539 | 463 | $nom_groupe_metier = $configuration->nom_groupe_metier; |
540 | 464 | |
... | ... | @@ -546,35 +470,17 @@ class DocumentsController extends AppController { |
546 | 470 | public function ficheMetrologique($id) { |
547 | 471 | |
548 | 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 | 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 | 483 | $symbole = ' '; |
577 | - } | |
578 | 484 | |
579 | 485 | // set the data materiel for the document (accessible par $materiel dans le document) |
580 | 486 | $this->set(compact('suivi', 'unite', 'fiche', 'symbole', 'mesures')); | ... | ... |
src/Controller/EmpruntsController.php
... | ... | @@ -25,7 +25,7 @@ class EmpruntsController extends AppController |
25 | 25 | */ |
26 | 26 | public function isAuthorized($user) |
27 | 27 | { |
28 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
28 | + $configuration = $this->confLabinvent; | |
29 | 29 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
30 | 30 | |
31 | 31 | $action = $this->request->params['action']; | ... | ... |
src/Controller/FichemetrologiquesController.php
... | ... | @@ -24,7 +24,7 @@ class FichemetrologiquesController extends AppController |
24 | 24 | public function isAuthorized($user) |
25 | 25 | { |
26 | 26 | /* |
27 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
27 | + $configuration = $this->confLabinvent; | |
28 | 28 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
29 | 29 | |
30 | 30 | $action = $this->request->params['action']; | ... | ... |
src/Controller/FormulesController.php
... | ... | @@ -21,7 +21,7 @@ class FormulesController extends AppController |
21 | 21 | */ |
22 | 22 | public function isAuthorized($user) |
23 | 23 | { |
24 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
24 | + $configuration = $this->confLabinvent; | |
25 | 25 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
26 | 26 | |
27 | 27 | $action = $this->request->params['action']; | ... | ... |
src/Controller/FournisseursController.php
... | ... | @@ -21,7 +21,7 @@ class FournisseursController extends AppController |
21 | 21 | */ |
22 | 22 | public function isAuthorized($user) |
23 | 23 | { |
24 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
24 | + $configuration = $this->confLabinvent; | |
25 | 25 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
26 | 26 | $action = $this->request->params['action']; |
27 | 27 | ... | ... |
src/Controller/GroupesMetiersController.php
... | ... | @@ -21,7 +21,7 @@ class GroupesMetiersController extends AppController |
21 | 21 | */ |
22 | 22 | public function isAuthorized($user) |
23 | 23 | { |
24 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
24 | + $configuration = $this->confLabinvent; | |
25 | 25 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
26 | 26 | $action = $this->request->params['action']; |
27 | 27 | ... | ... |
src/Controller/GroupesThematiquesController.php
... | ... | @@ -22,7 +22,7 @@ class GroupesThematiquesController extends AppController |
22 | 22 | */ |
23 | 23 | public function isAuthorized($user) |
24 | 24 | { |
25 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
25 | + $configuration = $this->confLabinvent; | |
26 | 26 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
27 | 27 | $action = $this->request->params['action']; |
28 | 28 | ... | ... |
src/Controller/MaterielsController.php
... | ... | @@ -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 | 53 | * @return boolean |
55 | 54 | */ |
56 | 55 | // (EP) TODO: ameliorer ca avec des variables globales IS_VALIDATED, IS_ADMIN, ... |
57 | 56 | public function isAuthorized($user) { |
58 | 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 | 61 | $this->role = $role; |
64 | 62 | $action = $this->request->params['action']; |
65 | 63 | |
... | ... | @@ -229,7 +227,6 @@ class MaterielsController extends AppController { |
229 | 227 | // Autorisations par defaut: |
230 | 228 | default: |
231 | 229 | return parent::isAuthorized($user); |
232 | - ; | |
233 | 230 | break; |
234 | 231 | } // end of switch case |
235 | 232 | } |
... | ... | @@ -307,91 +304,57 @@ class MaterielsController extends AppController { |
307 | 304 | // Par $this->request->params['pass'][0] |
308 | 305 | $condition = ''; |
309 | 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 | 308 | $this->set('STATUS', $this->request->params['pass'][0]); |
314 | 309 | } |
315 | 310 | |
316 | 311 | $GM = $this->request->query('GM'); |
317 | 312 | $GT = $this->request->query('GT'); |
318 | 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 | 315 | $condition = [ |
323 | 316 | 'Materiels.groupes_metier_id =' => $GM, |
324 | 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 | 320 | $condition = [ |
330 | 321 | 'Materiels.groupes_thematique_id =' => $GT, |
331 | 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 | 328 | $GMV = $this->request->query('GMV'); |
341 | 329 | $GTV = $this->request->query('GTV'); |
342 | 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 | 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 | 346 | $MY = $this->request->query('MY'); |
367 | 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 | 358 | $limit = $this->request->query('aff'); |
396 | 359 | if (! isset($limit)) |
397 | 360 | $limit = $config['aff_par_defaut']; |
... | ... | @@ -407,23 +370,14 @@ class MaterielsController extends AppController { |
407 | 370 | 'Organismes', |
408 | 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 | 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 | 447 | $this->set('typeSuivis', $typeSuivis); |
494 | 448 | $this->set('typeDocuments', $typeDocuments); |
495 | 449 | $this->set('fournisseurs', $fournisseurs); |
496 | - | |
497 | 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 | 461 | $materiel = $this->Materiels->newEntity(); |
511 | 462 | if ($this->request->is('post')) { |
512 | 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 | 468 | $gestionnaireID = TableRegistry::get('Users')->find()->where([ |
520 | 469 | 'nom' => $_SESSION['Auth']['User']['sn'][0] |
521 | 470 | ])->first()->id; |
... | ... | @@ -523,25 +472,17 @@ class MaterielsController extends AppController { |
523 | 472 | } |
524 | 473 | if ($this->Materiels->save($materiel)) { |
525 | 474 | $this->Flash->success(__('Le matériel a bien été ajouté.')); |
526 | - | |
527 | 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 | 478 | $this->Flash->error(__('Le matériel n\'a pas pu être ajouté.')); |
535 | - } | |
536 | 479 | } |
537 | 480 | |
538 | 481 | $surCategories = $this->Materiels->SurCategories->find('list', [ |
539 | 482 | 'keyField' => 'id', |
540 | 483 | 'valueField' => 'nom', |
541 | 484 | 'order' => 'SurCategories.nom', |
542 | - 'conditions' => array( | |
543 | - 'nom !=' => 'N/A' | |
544 | - ) | |
485 | + 'conditions' => array('nom !=' => 'N/A') | |
545 | 486 | ]); |
546 | 487 | $categories = $this->Materiels->Categories->find('list', [ |
547 | 488 | 'keyField' => 'id', |
... | ... | @@ -581,24 +522,20 @@ class MaterielsController extends AppController { |
581 | 522 | $lieu_detail = $this->Materiels->find('list', [ |
582 | 523 | 'keyField' => 'lieu_detail', |
583 | 524 | 'valueField' => 'lieu_detail', |
584 | - 'conditions' => array( | |
585 | - 'lieu_detail !=' => '' | |
586 | - ), | |
525 | + 'conditions' => array('lieu_detail !=' => ''), | |
587 | 526 | 'order' => 'lieu_detail', |
588 | 527 | 'group' => 'lieu_detail' |
589 | 528 | ]); |
590 | 529 | $designation = $this->Materiels->find('list', [ |
591 | 530 | 'keyField' => 'designation', |
592 | 531 | 'valueField' => 'designation', |
593 | - 'conditions' => array( | |
594 | - 'designation !=' => '' | |
595 | - ), | |
532 | + 'conditions' => array('designation !=' => ''), | |
596 | 533 | 'order' => 'designation', |
597 | 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 | 539 | if ($domaineresp == null) $domaineresp = false; |
603 | 540 | $utilisateurconnect = TableRegistry::get('Users')->find('all')->toArray(); |
604 | 541 | $users = TableRegistry::get('LdapConnections')->getListUsers(); |
... | ... | @@ -611,9 +548,9 @@ class MaterielsController extends AppController { |
611 | 548 | } |
612 | 549 | |
613 | 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 | 555 | if (isset($this->request->params['pass'][0])) { |
619 | 556 | $cpMateriel = $this->Materiels->get($this->request->params['pass'][0]); |
... | ... | @@ -621,9 +558,7 @@ class MaterielsController extends AppController { |
621 | 558 | } |
622 | 559 | |
623 | 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 | 570 | * @throws \Cake\Network\Exception\NotFoundException When record not found. |
636 | 571 | */ |
637 | 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 | 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 | 583 | $materiel->gestionnaire_id = $gestionnaireID; |
657 | 584 | } |
658 | 585 | if ($this->Materiels->save($materiel)) { |
659 | 586 | $this->Flash->success(__('Le matériel a bien été édité.')); |
660 | 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 | 590 | $this->Flash->error(__('Le matériel n\'a pas pu être édité.')); |
667 | - } | |
668 | 591 | } |
669 | 592 | |
670 | 593 | $surCategories = $this->Materiels->SurCategories->find('list', [ |
... | ... | @@ -705,18 +628,14 @@ class MaterielsController extends AppController { |
705 | 628 | $designation = $this->Materiels->find('list', [ |
706 | 629 | 'keyField' => 'designation', |
707 | 630 | 'valueField' => 'designation', |
708 | - 'conditions' => array( | |
709 | - 'designation !=' => '' | |
710 | - ), | |
631 | + 'conditions' => array('designation !=' => ''), | |
711 | 632 | 'order' => 'designation', |
712 | 633 | 'group' => 'designation' |
713 | 634 | ]); |
714 | 635 | $designation_edit = $this->Materiels->find('list', [ |
715 | 636 | 'keyField' => 'id', |
716 | 637 | 'valueField' => 'designation', |
717 | - 'conditions' => array( | |
718 | - 'id =' => $materiel->id | |
719 | - ) | |
638 | + 'conditions' => array('id =' => $materiel->id) | |
720 | 639 | ]); |
721 | 640 | $designation_edit = $designation_edit->toArray(); |
722 | 641 | |
... | ... | @@ -724,17 +643,13 @@ class MaterielsController extends AppController { |
724 | 643 | $lieu_detail = $this->Materiels->find('list', [ |
725 | 644 | 'keyField' => 'lieu_detail', |
726 | 645 | 'valueField' => 'lieu_detail', |
727 | - 'conditions' => array( | |
728 | - 'lieu_detail !=' => '' | |
729 | - ), | |
646 | + 'conditions' => array('lieu_detail !=' => ''), | |
730 | 647 | 'order' => 'lieu_detail' |
731 | 648 | ]); |
732 | 649 | $lieu_detail_edit = $this->Materiels->find('list', [ |
733 | 650 | 'keyField' => 'id', |
734 | 651 | 'valueField' => 'lieu_detail', |
735 | - 'conditions' => array( | |
736 | - 'id =' => $materiel->id | |
737 | - ) | |
652 | + 'conditions' => array('id =' => $materiel->id) | |
738 | 653 | ]); |
739 | 654 | $lieu_detail_edit = $lieu_detail_edit->toArray(); |
740 | 655 | |
... | ... | @@ -744,15 +659,15 @@ class MaterielsController extends AppController { |
744 | 659 | 'valueField' => 'nom', |
745 | 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 | 672 | if ($dom == $domaines) |
758 | 673 | $domaineresp = true; |
... | ... | @@ -767,39 +682,32 @@ class MaterielsController extends AppController { |
767 | 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 | 687 | $nom_ancien_responsable = $materiel->get('nom_responsable'); |
773 | 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 | 695 | // Fonction utilisée dans la vue, déclarée ici pour éviter les problèmes de tests |
781 | 696 | $isReadonlyField = function ($fieldName, $myReadonlyFields) { |
782 | - if (! empty($myReadonlyFields) && $myReadonlyFields[0] == '*') { | |
697 | + if (!empty($myReadonlyFields) && $myReadonlyFields[0] == '*') { | |
783 | 698 | $modifiableFields = $myReadonlyFields; |
784 | 699 | array_shift($modifiableFields); |
785 | - return ! in_array($fieldName, $modifiableFields); | |
700 | + return !in_array($fieldName, $modifiableFields); | |
786 | 701 | } |
787 | 702 | return in_array($fieldName, $myReadonlyFields); |
788 | 703 | }; |
704 | + | |
789 | 705 | $this->set('isReadonlyField', $isReadonlyField); |
790 | - | |
791 | 706 | $this->set('IS_CREATED', $materiel->status == 'CREATED'); |
792 | 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 | 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 | 719 | * @throws \Cake\Network\Exception\NotFoundException When record not found. |
812 | 720 | */ |
813 | 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 | 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 | 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 | 729 | $this->Flash->error(__('Le matériel n\'a pas pu être édité.')); |
833 | - } | |
834 | 730 | } |
835 | 731 | $surCategories = $this->Materiels->SurCategories->find('list', [ |
836 | 732 | 'keyField' => 'id', |
... | ... | @@ -874,6 +770,7 @@ class MaterielsController extends AppController { |
874 | 770 | ]); |
875 | 771 | |
876 | 772 | $users = TableRegistry::get('LdapConnections')->getListUsers(); |
773 | + | |
877 | 774 | // tri des utilisateurs par nom |
878 | 775 | sort($users); |
879 | 776 | $utilisateurs = []; |
... | ... | @@ -881,27 +778,22 @@ class MaterielsController extends AppController { |
881 | 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 | 783 | $nom_ancien_responsable = $materiel->get('nom_responsable'); |
887 | 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 | 791 | $this->set('IS_CREATED', $materiel->status == 'CREATED'); |
895 | 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 | 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 | 811 | if ($this->Materiels->delete($materiel)) { |
920 | 812 | $this->Flash->success(__('Le matériel a bien été supprimé.')); |
921 | 813 | $this->sendEmail($materiel); |
922 | - } else { | |
814 | + } else | |
923 | 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 | 828 | private function statusSetTo($newStatus, $message, $id = null, $from = 'index') { |
940 | 829 | $materiel = $this->Materiels->get($id)->set('status', $newStatus); |
941 | 830 | |
942 | - if ($newStatus == 'ARCHIVED') { | |
831 | + if ($newStatus == 'ARCHIVED') | |
943 | 832 | $materiel->set('date_archivage', date('Y-m-d')); |
944 | - } | |
945 | 833 | |
946 | 834 | if ($newStatus == 'VALIDATED') { |
947 | 835 | $mandatoryFields = array( |
... | ... | @@ -952,50 +840,32 @@ class MaterielsController extends AppController { |
952 | 840 | $materiel->date_reception, |
953 | 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 | 852 | foreach ($mandatoryFields as $field){ |
965 | 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 | 861 | $this->Flash->success(__($message)); |
985 | - // $this->sendEmailToManagement($id); | |
986 | - } else { | |
862 | + else | |
987 | 863 | $this->Flash->error(__('Le statut n\'a pas pu être édité.')); |
988 | - } | |
989 | 864 | |
990 | 865 | if ($from == 'index') |
991 | - return $this->redirect([ | |
992 | - 'action' => $from | |
993 | - ]); | |
866 | + return $this->redirect([ 'action' => $from]); | |
994 | 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 | 876 | */ |
1007 | 877 | public function statusValidated($id = null, $from = 'index') { |
1008 | 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 | 884 | $materiel->gestionnaire_id = $gestionnaireID; |
1019 | 885 | } |
1020 | 886 | $this->sendEmail($this->Materiels->get($id)); |
... | ... | @@ -1051,9 +917,7 @@ et Date de reception |
1051 | 917 | private function getConditionForField($fieldName) { |
1052 | 918 | $searchFieldName = 's_' . $fieldName; |
1053 | 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 | 921 | return NULL; |
1058 | 922 | } |
1059 | 923 | |
... | ... | @@ -1066,9 +930,7 @@ et Date de reception |
1066 | 930 | private function getConditionForFieldNumber($fieldName) { |
1067 | 931 | $searchFieldName = 's_' . $fieldName; |
1068 | 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 | 934 | return NULL; |
1073 | 935 | } |
1074 | 936 | |
... | ... | @@ -1139,22 +1001,13 @@ et Date de reception |
1139 | 1001 | ) |
1140 | 1002 | ]); |
1141 | 1003 | $categories = $this->Materiels->Categories; |
1142 | - | |
1143 | 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 | 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 | 1010 | $conditionNotArchived = ''; |
1157 | - } | |
1158 | 1011 | |
1159 | 1012 | // some data POSTED (au moins le champ de recherche generale) ? |
1160 | 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 | 1017 | $all = $this->request->data['s_all']; |
1165 | 1018 | |
1166 | 1019 | // Check for a date |
1167 | - foreach ([ | |
1168 | - "/", | |
1169 | - "-" | |
1170 | - ] as $symb) { | |
1020 | + foreach (["/", "-"] as $symb) { | |
1171 | 1021 | $pos1 = strpos($all, $symb); // Première occurence |
1172 | 1022 | $pos2 = strrchr($all, $symb); // Dernière occurence |
1173 | 1023 | if ($pos1 !== false && $pos1 != $pos2) { |
... | ... | @@ -1203,10 +1053,7 @@ et Date de reception |
1203 | 1053 | $all = $this->request->data['s_all_2']; |
1204 | 1054 | |
1205 | 1055 | // Check for a date |
1206 | - foreach ([ | |
1207 | - "/", | |
1208 | - "-" | |
1209 | - ] as $symb) { | |
1056 | + foreach (["/", "-"] as $symb) { | |
1210 | 1057 | $pos1 = strpos($all, $symb); // Première occurence |
1211 | 1058 | $pos2 = strrchr($all, $symb); // Dernière occurence |
1212 | 1059 | if ($pos1 !== false && $pos1 != $pos2) { |
... | ... | @@ -1320,48 +1167,29 @@ et Date de reception |
1320 | 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 | 1174 | // CONSTRUCTION DE LA REQUETE SQL COMPLETE = $specificFieldsConditions OR $generalFieldConditions (mais entre chaque champ, c'est un AND) |
1331 | 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 | 1186 | $_results = $this->paginate($lastResults); |
1359 | 1187 | $this->set(compact('_results')); |
1360 | 1188 | |
1361 | 1189 | // pour l'export |
1362 | 1190 | $this->request->session()->write("result", $lastResults->toArray()); |
1363 | 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 | 1193 | $findedMateriel = []; |
1366 | 1194 | |
1367 | 1195 | foreach ($resultTri as $r) { |
... | ... | @@ -1391,11 +1219,9 @@ else if (isset($resultTri) && strstr($this->request->here(), 'sort') != false && |
1391 | 1219 | * group update status + exportAll |
1392 | 1220 | */ |
1393 | 1221 | public function execActions() { |
1394 | - if (isset($this->request->data['updateSelectedStatus'])) { | |
1222 | + if (isset($this->request->data['updateSelectedStatus'])) | |
1395 | 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) && strstr($this->request->here(), 'sort') != false && |
1407 | 1233 | $this->myDebug($this->request->data); |
1408 | 1234 | $what = $this->request->data['what']; |
1409 | 1235 | $nb = 0; |
1410 | - | |
1236 | + | |
1411 | 1237 | if (in_array($what, $this->NOTARCHIVED)) { |
1412 | 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 | 1254 | 'checkRules' => false, |
1435 | 1255 | 'checkExisting' => false |
1436 | - ]); | |
1437 | - } | |
1256 | + ]); | |
1438 | 1257 | } |
1439 | - $nb ++; | |
1440 | 1258 | } |
1259 | + $nb ++; | |
1260 | + } | |
1441 | 1261 | endforeach |
1442 | 1262 | ; |
1443 | 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) && strstr($this->request->here(), 'sort') != false && |
1579 | 1399 | 'Content-Disposition: attachment; filename="' . $filename . '"' |
1580 | 1400 | ]); |
1581 | 1401 | $this->response->sendHeaders(); |
1582 | - $configuration = TableRegistry::get('Configurations')->find()->where([ | |
1583 | - 'id =' => 1 | |
1584 | - ])->first(); | |
1402 | + $configuration = $this->confLabinvent; | |
1585 | 1403 | $nomgroupemetier = $configuration->nom_groupe_metier; |
1586 | 1404 | $nomgroupethematique = $configuration->nom_groupe_thematique; |
1587 | 1405 | |
... | ... | @@ -1801,15 +1619,13 @@ else if (isset($resultTri) && strstr($this->request->here(), 'sort') != false && |
1801 | 1619 | |
1802 | 1620 | $filename = 'inventirap_label.label'; |
1803 | 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 | 1623 | $this->response->sendHeaders(); |
1809 | - | |
1624 | + | |
1810 | 1625 | /* |
1811 | 1626 | * SIMPLE LABEL FOR PRINTER DYMO LabelWriter 450 : NO LOGO |
1812 | 1627 | */ |
1628 | + | |
1813 | 1629 | /* |
1814 | 1630 | * '<?xml version="1.0" encoding="utf-8"?> |
1815 | 1631 | * <DieCutLabel Version="8.0" Units="twips"> |
... | ... | @@ -2091,16 +1907,12 @@ else if (isset($resultTri) && strstr($this->request->here(), 'sort') != false && |
2091 | 1907 | $date_next = date_create_from_format('d-m-Y', $date); |
2092 | 1908 | |
2093 | 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 | 1914 | $this->set('date', date_format($date_next, 'd-m-Y')); |
2103 | - | |
1915 | + | |
2104 | 1916 | $this->viewBuilder()->layout = 'ajax'; |
2105 | 1917 | } |
2106 | 1918 | |
... | ... | @@ -2132,10 +1944,7 @@ else if (isset($resultTri) && strstr($this->request->here(), 'sort') != false && |
2132 | 1944 | $this->set('sites', $sites); |
2133 | 1945 | $this->set('typeSuivis', $typeSuivis); |
2134 | 1946 | $this->set('typeDocuments', $typeDocuments); |
2135 | - | |
2136 | 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 | 25 | */ |
26 | 26 | public function isAuthorized($user) |
27 | 27 | { |
28 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
28 | + $configuration = $this->confLabinvent; | |
29 | 29 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
30 | 30 | $action = $this->request->params['action']; |
31 | 31 | ... | ... |
src/Controller/PagesController.php
... | ... | @@ -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 | 45 | $path = func_get_args(); |
46 | 46 | if(!(isset($path[0]))) { | ... | ... |
src/Controller/SitesController.php
... | ... | @@ -21,7 +21,7 @@ class SitesController extends AppController |
21 | 21 | */ |
22 | 22 | public function isAuthorized($user) |
23 | 23 | { |
24 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
24 | + $configuration = $this->confLabinvent; | |
25 | 25 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
26 | 26 | $action = $this->request->params['action']; |
27 | 27 | ... | ... |
src/Controller/SousCategoriesController.php
... | ... | @@ -24,7 +24,7 @@ class SousCategoriesController extends AppController |
24 | 24 | */ |
25 | 25 | public function isAuthorized($user) |
26 | 26 | { |
27 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
27 | + $configuration = $this->confLabinvent; | |
28 | 28 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
29 | 29 | $action = $this->request->params['action']; |
30 | 30 | ... | ... |
src/Controller/SuivisController.php
... | ... | @@ -18,11 +18,7 @@ class SuivisController extends AppController { |
18 | 18 | * @return boolean |
19 | 19 | */ |
20 | 20 | public function isAuthorized($user) { |
21 | - $configuration = TableRegistry::get('Configurations')->find() | |
22 | - ->where([ | |
23 | - 'id =' => 1 | |
24 | - ]) | |
25 | - ->first(); | |
21 | + $configuration = $this->confLabinvent; | |
26 | 22 | $role = TableRegistry::get('Users')->find() |
27 | 23 | ->where([ |
28 | 24 | 'username' => $user[$configuration->authentificationType_ldap][0] | ... | ... |
src/Controller/SurCategoriesController.php
... | ... | @@ -25,7 +25,7 @@ class SurCategoriesController extends AppController |
25 | 25 | */ |
26 | 26 | public function isAuthorized($user) |
27 | 27 | { |
28 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
28 | + $configuration = $this->confLabinvent; | |
29 | 29 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
30 | 30 | $action = $this->request->params['action']; |
31 | 31 | ... | ... |
src/Controller/TypeDocumentsController.php
... | ... | @@ -21,7 +21,7 @@ class TypeDocumentsController extends AppController |
21 | 21 | */ |
22 | 22 | public function isAuthorized($user) |
23 | 23 | { |
24 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
24 | + $configuration = $this->confLabinvent; | |
25 | 25 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
26 | 26 | $action = $this->request->params['action']; |
27 | 27 | ... | ... |
src/Controller/TypeSuivisController.php
... | ... | @@ -21,7 +21,7 @@ class TypeSuivisController extends AppController |
21 | 21 | */ |
22 | 22 | public function isAuthorized($user) |
23 | 23 | { |
24 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
24 | + $configuration = $this->confLabinvent; | |
25 | 25 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
26 | 26 | $action = $this->request->params['action']; |
27 | 27 | ... | ... |
src/Controller/UnitesController.php
... | ... | @@ -21,7 +21,7 @@ class UnitesController extends AppController |
21 | 21 | */ |
22 | 22 | public function isAuthorized($user) |
23 | 23 | { |
24 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
24 | + $configuration = $this->confLabinvent; | |
25 | 25 | $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
26 | 26 | $action = $this->request->params['action']; |
27 | 27 | ... | ... |
src/Controller/UsersController.php
... | ... | @@ -27,7 +27,7 @@ class UsersController extends AppController |
27 | 27 | */ |
28 | 28 | public function isAuthorized($user) |
29 | 29 | { |
30 | - $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); | |
30 | + $configuration = $this->confLabinvent; | |
31 | 31 | $role = $this->Users->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; |
32 | 32 | |
33 | 33 | $action = $this->request->params['action']; | ... | ... |
src/Model/Table/DocumentsTable.php
... | ... | @@ -99,17 +99,14 @@ class DocumentsTable extends AppTable |
99 | 99 | $config = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); |
100 | 100 | $size = $entity->get('chemin_file')['size']; |
101 | 101 | if(isset($size)) { |
102 | - if($size > $config->taille_max_doc) { | |
102 | + if($size > $config->taille_max_doc) | |
103 | 103 | return false; |
104 | - } else { | |
104 | + else | |
105 | 105 | return true; |
106 | - } | |
107 | - } else { | |
106 | + } else | |
108 | 107 | return false; |
109 | - } | |
110 | - } else { | |
108 | + } else | |
111 | 109 | return true; |
112 | - } | |
113 | 110 | }; |
114 | 111 | |
115 | 112 | $checkPhoto= function($entity) { |
... | ... | @@ -118,12 +115,10 @@ class DocumentsTable extends AppTable |
118 | 115 | $extension = strtolower(pathinfo($entity->get('chemin_file')['name'] , PATHINFO_EXTENSION)); |
119 | 116 | return in_array($extension, ['png', 'jpg', 'jpeg']); |
120 | 117 | } |
121 | - else { | |
118 | + else | |
122 | 119 | return true; |
123 | - } | |
124 | - } else { | |
120 | + } else | |
125 | 121 | return true; |
126 | - } | |
127 | 122 | }; |
128 | 123 | |
129 | 124 | $checkEditFile= function($entity) { | ... | ... |
src/Template/Materiels/index.ctp
... | ... | @@ -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 | 108 | echo $this->Form->input('aff_par_defaut', [ |
106 | 109 | 'label' => 'Afficher', |
107 | 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 | 115 | <table style="border-collapse: separate; border-spacing: 0;"> |
124 | 116 | <thead> |
... | ... | @@ -140,7 +132,7 @@ if (isset ( $STATUS )) { |
140 | 132 | <tbody> |
141 | 133 | |
142 | 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 | 136 | $time = Time::now(); // On récupère la date et l'heure actuelles |
145 | 137 | $today = new date("$time->year-$time->month-$time->day"); // On extrait la date pour la vérification de fin de garantie |
146 | 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 | 146 | $dateFin = new date("$timeFin->year-$timeFin->month-$timeFin->day"); |
155 | 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 | 153 | <tr> |
... | ... | @@ -256,45 +248,39 @@ if (isset ( $STATUS )) { |
256 | 248 | </table> |
257 | 249 | |
258 | 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 | 286 | <div class="paging" style="color: black;"> | ... | ... |
src/Template/Materiels/view.ctp
... | ... | @@ -7,7 +7,7 @@ use Cake\ORM\TableRegistry; |
7 | 7 | // Set some useful global variables for this view |
8 | 8 | |
9 | 9 | // 1) Materiel settings |
10 | -/* | |
10 | + | |
11 | 11 | const CREATED = 1; |
12 | 12 | const VALIDATED = 2; |
13 | 13 | const TOBEARCHIVED = 3; |
... | ... | @@ -48,7 +48,7 @@ $USER_IS_ADMINPLUS = ($profile == $PROFILE_ADMINPLUS); |
48 | 48 | $USER_IS_SUPERADMIN = ($profile == $PROFILE_SUPERADMIN); |
49 | 49 | |
50 | 50 | $USER_IS_ADMIN_OR_MORE = $profile >= $PROFILE_ADMIN; |
51 | -*/ | |
51 | + | |
52 | 52 | |
53 | 53 | $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER = $USER_IS_UTILISATEUR && in_array($username, [$materiel->nom_createur, $materiel->nom_responsable]); |
54 | 54 | ... | ... |