diff --git a/README-LABINVENT.md b/README-LABINVENT.md index 040b2bf..002ea19 100755 --- a/README-LABINVENT.md +++ b/README-LABINVENT.md @@ -50,18 +50,14 @@ Logiciel testé et validé sur les configurations suivantes : VERSION ACTUELLE -Date: 28/06/2016 -Version: 2.5.1.0 +Date: 29/06/2016 +Version: 2.5.2.0 -!!! Se placer dans database/update et exécuter le script ./db-update-2016-06-28.sh !!! +envoi mail ajout document + bugfixes + edition details doc + acl documents + pb saut de ligne champ "text -Confirmation suppression doc + organisation configuration/form + taille doc config + photo materiel + liste type document défaut + acl documents + bugfixes - -Demande (terminé) : https://projects.irap.omp.eu/issues/3905 - https://projects.irap.omp.eu/issues/3790 - https://projects.irap.omp.eu/issues/3904 - -Demande (en cours) : https://projects.irap.omp.eu/issues/3716 +Demande (terminé) : https://projects.irap.omp.eu/issues/3913 + https://projects.irap.omp.eu/issues/3716 + https://projects.irap.omp.eu/issues/3912 Version majeure en cours (2.5): https://projects.irap.omp.eu/versions/99 diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 3d714f0..8a5d2ed 100755 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -164,10 +164,7 @@ class AppController extends Controller $this->set('_serialize', true); } $this->set('username', $this->LdapAuth->user('givenname')[0].' '.$this->LdapAuth->user('sn')[0]); - - - - + $configuration = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); $this->set('configuration', $configuration); $this->request->session()->write("authType", $configuration->authentificationType_ldap); @@ -249,30 +246,33 @@ class AppController extends Controller switch ($action) { case 'add': - $actionFrench = ['Création', 'créé']; + $actionFrench = ['Création d\'un ', 'été créé']; break; case 'edit': - $actionFrench = ['Modification', 'modifié']; + $actionFrench = ['Modification d\'un ', 'été modifié']; break; case 'delete': - $actionFrench = ['Suppression', 'supprimé']; + $actionFrench = ['Suppression d\'un ', 'été supprimé']; break; case 'statusValidated': - $actionFrench = ['Validation', 'validé']; + $actionFrench = ['Validation d\'un ', 'été validé']; break; case 'statusToBeArchived': - $actionFrench = ['Demande Archivage', 'demandé pour archivage']; + $actionFrench = ['Demande Archivage d\'un ', 'été demandé pour archivage']; break; case 'statusArchived': - $actionFrench = ['Archivage', 'archivé']; + $actionFrench = ['Archivage d\'un ', 'été archivé']; + break; + case 'setLabelIsPlaced': + $actionFrench = ['Etiquette posé sur un ', 'reçu une étiquette']; break; default: - $actionFrench = [$action, $action]; + $actionFrench = [$action.' d\'un ', 'été '.$action]; break; } $doneBy = $userName." (".$userEmail.", login=".$userAuth.", profil=".$role.")."; - $subject = $actionFrench[0]." d'un " .$controller; + $subject = $actionFrench[0].$controller; if($id != null) { $entityName = TableRegistry::get($modelName)->find('all')->where(['id =' => $id])->first(); @@ -291,7 +291,7 @@ class AppController extends Controller $entityName = NULL; } - $message = $this->getArticle().$controller." ".$entityName." (id=".$id.") a été ".$actionFrench[1]." par ".$doneBy; + $message = $this->getArticle().$controller." ".$entityName." (id=".$id.") a ".$actionFrench[1]." par ".$doneBy; $this->sendEmailToManagementWith($subject, $message); diff --git a/src/Controller/DocumentsController.php b/src/Controller/DocumentsController.php index de5b3d4..8cedf24 100755 --- a/src/Controller/DocumentsController.php +++ b/src/Controller/DocumentsController.php @@ -36,10 +36,33 @@ class DocumentsController extends AppController } } - if($action == 'delete') { + if(in_array($action, ['delete', 'edit'])) { if ($this->userHasRole('Administration')) { return true; } + $u = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first(); + + $doc = $this->Documents->get((int)$this->request->params['pass'][0]); + + $id = $doc->get('materiel_id'); + if(empty($id)) { + $id = $doc->get('suivi_id'); + $suiviTable = TableRegistry::get('Suivis'); + if ($role == 'Responsable') { + return ($suiviTable->exists(['id' => $id, 'groupes_metier_id' => $u['groupes_metier_id']]) || $suiviTable->exists(['id' => $id, 'groupes_thematique_id' => $u['groupe_thematique_id']])); + } + if ($role == 'Utilisateur') { + return $suiviTable->exists(['id' => $id, 'nom_createur' => $user['givenname'][0].' '.$user['sn'][0]]); + } + } else { + $materielTable = TableRegistry::get('Materiels'); + if ($role == 'Responsable') { + return ($materielTable->exists(['id' => $id, 'groupes_metier_id' => $u['groupes_metier_id']]) || $materielTable->exists(['id' => $id, 'groupes_thematique_id' => $u['groupe_thematique_id']])); + } + if ($role == 'Utilisateur') { + return ($materielTable->exists(['id' => $id, 'nom_createur' => $user['givenname'][0].' '.$user['sn'][0]]) || $materielTable->exists(['id' => $id, 'nom_responsable' => $user['givenname'][0].' '.$user['sn'][0]])); + } + } } //Pour tout le monde @@ -101,20 +124,27 @@ class DocumentsController extends AppController public function add() { $document = $this->Documents->newEntity(); + if ($this->request->is('post')) { $document = $this->Documents->patchEntity($document, $this->request->data); + $nomType = $this->Documents->TypeDocuments->find()->where(['id =' => $document->type_document_id])->first()['nom']; + if(isset($this->passedArgs[2]) && $this->passedArgs[2] == 'photo') { $document->set('photo', 1); } - + if ($this->Documents->save($document)) { $this->Flash->success(__('Le fichier a bien été ajouté.')); + $id = $document->materiel_id; + if(!empty($id)) { + $materielTable = TableRegistry::get('Materiels'); + $materiel = $materielTable->get($id); + } + if(isset($this->passedArgs[2]) && $this->passedArgs[2] == 'photo') { - $materielTable = TableRegistry::get('Materiels'); - $materiel = $materielTable->get($document->materiel_id); - + $photoIdOld = $materiel->get('photo_id'); if(isset($photoIdOld)) { $docOld = TableRegistry::get('Documents')->get($photoIdOld); @@ -125,11 +155,16 @@ class DocumentsController extends AppController $materielTable->save($materiel); } + $userName = $this->LdapAuth->user('givenname')[0].' '.$this->LdapAuth->user('sn')[0]; + $userEmail = $this->LdapAuth->user('mail')[0]; + $id = $document->materiel_id; if(empty($id)) { $id = $document->suivi_id; + $this->sendEmailToManagementWith('[LabInvent] Ajout d\'un document', $userName.' (email = '.$userEmail.') a ajouté un document de type "'.$nomType.'" au suivi "Suivi '.$document->suivi_id.'".'); return $this->redirect(['controller' => 'suivis', 'action' => 'view', $id]); } else { + $this->sendEmailToManagementWith('[LabInvent] Ajout d\'un document', $userName.' (email = '.$userEmail.') a ajouté un document de type "'.$nomType.'" au matériel "'.$materiel->designation.'" (id = '.$materiel->id.').'); return $this->redirect(['controller' => 'materiels', 'action' => 'view', $id]); } @@ -158,6 +193,56 @@ class DocumentsController extends AppController $this->set('_serialize', ['document']); } + /** + * EDit method + * + * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. + */ + public function edit($id = null) + { + $document = $this->Documents->get($id, [ + 'contain' => [] + ]); + + if ($this->request->is(['patch', 'post', 'put'])) { + $document = $this->Documents->patchEntity($document, $this->request->data); + + if ($this->Documents->save($document)) { + $this->Flash->success(__('Le fichier a bien été edité.')); + + $id = $document->materiel_id; + if(empty($id)) { + $id = $document->suivi_id; + return $this->redirect(['controller' => 'suivis', 'action' => 'view', $id]); + } else { + return $this->redirect(['controller' => 'materiels', 'action' => 'view', $id]); + } + + } else { + $this->Flash->error(__('Le fichier n\'a pas pu être edité.')); + } + } + + $id = $document->materiel_id; + if(empty($id)) { + $id = $document->suivi_id; + $suivi = $this->Documents->Suivis->find('list', [ 'keyField' => 'id', 'valueField' => 'id'])->where(['id =' => $id]); + $this->set('suivi', $suivi); + } else { + $materiel = $this->Documents->Materiels->find('list', [ 'keyField' => 'id', 'valueField' => 'numero_laboratoire'])->where(['id =' => $id]); + $this->set('materiel', $materiel); + } + + if($document->photo) { + $this->set('photo', 1); + } + + + $typesD = $this->Documents->TypeDocuments->find('list', [ 'keyField' => 'id', 'valueField' => 'nom', 'order' => 'TypeDocuments.nom']); + + $this->set(compact('document', 'typesD')); + $this->set('_serialize', ['document']); + } /** * Delete method diff --git a/src/Controller/MaterielsController.php b/src/Controller/MaterielsController.php index 8f37a0d..ef1d046 100755 --- a/src/Controller/MaterielsController.php +++ b/src/Controller/MaterielsController.php @@ -906,16 +906,14 @@ class MaterielsController extends AppController if ($this->Materiels->save($materiel, ['checkRules' => false, 'checkExisting' => false])) { $this->Flash->success(__('L\'étiquette a bien été éditer.')); - $this->sendEmailToManagement($id); + // Envoi email seulement si etiquette posée + if ($printed) { + $this->sendEmailToManagement($id); + } } else { $this->Flash->error(__('L\'étiquette n\'a pas pu être édité.')); } - - // Envoi email seulement si etiquette posée - if ($printed) { - $this->sendEmailToManagementWith('etiquette posée', "Une étiquette a été posée sur le matériel (id=$id)"); - } return $this->redirect($this->referer()); } diff --git a/src/Model/Table/AppTable.php b/src/Model/Table/AppTable.php index 32a6535..fb74419 100644 --- a/src/Model/Table/AppTable.php +++ b/src/Model/Table/AppTable.php @@ -11,7 +11,7 @@ class AppTable extends Table // autoriser les caracteres habituels standards pour un ou plusieurs MOTs // accents + - _ / () . , \s (=space) - private $string = "a-zA-Z0-9éèàùâêôîôûç%().,\/\s\+\-_"; + private $string = "a-zA-Z0-9éèàùâêôîôûç%().,\/\s\+\-_'"; public function check_string($check) { return (bool) preg_match('/^['.$this->string.']*$/', $check); diff --git a/src/Model/Table/DocumentsTable.php b/src/Model/Table/DocumentsTable.php index 98685fb..f134117 100755 --- a/src/Model/Table/DocumentsTable.php +++ b/src/Model/Table/DocumentsTable.php @@ -61,8 +61,8 @@ class DocumentsTable extends AppTable ->allowEmpty('type_doc'); $validator - ->notEmpty('chemin_file'); - + ->allowEmpty('chemin_file'); + $validator ->notEmpty('nom'); @@ -97,30 +97,49 @@ class DocumentsTable extends AppTable $config = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); $checkSizeDoc= function($entity) { - $config = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); - $size = $entity->get('chemin_file')['size']; - if(isset($size)) { - if($size > $config->taille_max_doc) { - return false; + if(!empty($entity->get('chemin_file')['tmp_name'])) { + $config = TableRegistry::get('Configurations')->find()->where(['id =' => 1])->first(); + $size = $entity->get('chemin_file')['size']; + if(isset($size)) { + if($size > $config->taille_max_doc) { + return false; + } else { + return true; + } } else { - return true; + return false; } } else { - return false; + return true; } - }; $checkPhoto= function($entity) { - if($entity->get('photo')) { - $extension = strtolower(pathinfo($entity->get('chemin_file')['name'] , PATHINFO_EXTENSION)); - return in_array($extension, ['png', 'jpg', 'jpeg']); - } - else { - return true; - } + if(!empty($entity->get('chemin_file')['tmp_name'])) { + if($entity->get('photo')) { + $extension = strtolower(pathinfo($entity->get('chemin_file')['name'] , PATHINFO_EXTENSION)); + return in_array($extension, ['png', 'jpg', 'jpeg']); + } + else { + return true; + } + } else { + return true; + } }; + $checkEditFile= function($entity) { + if(!$entity->get('edit')) { + if(empty($entity->get('chemin_file')['tmp_name'])) { + return false; + } + else { + return true; + } + } else { + return true; + } + }; $rules->add($checkSizeDoc, [ 'errorField' => 'chemin_file', @@ -132,6 +151,10 @@ class DocumentsTable extends AppTable 'message' => 'La photo doit etre au format png, jpg (ou jpeg).' ]); + $rules->add($checkEditFile, [ + 'errorField' => 'chemin_file', + 'message' => 'Un fichier doit être présent.' + ]); return $rules; } @@ -154,10 +177,13 @@ class DocumentsTable extends AppTable **/ public function beforeSave($event, $entity, $options) { + $file = $entity->get('chemin_file'); - $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); + if(!empty($file['tmp_name'])) { + $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); + $entity->set('type_doc', $extension); + } - $entity->set('type_doc', $extension); return true; } diff --git a/src/Template/Documents/edit.ctp b/src/Template/Documents/edit.ctp new file mode 100644 index 0000000..51f333f --- /dev/null +++ b/src/Template/Documents/edit.ctp @@ -0,0 +1,46 @@ + +
+ Form->create($document, ['type' => 'file']) ?> +
+ Editer une photo'; + }else { + echo '

Editer un document

'; + } + if(isset($materiel)) { + echo $this->Form->input('materiel_id', ['label' => 'N° materiel labo', 'options' => $materiel, 'default' => $this->passedArgs[0], 'readonly' => true]); + } + else if(isset($suivi)) { + echo $this->Form->input('suivi_id', ['label' => 'N° suivi', 'options' => $suivi, 'default' => $this->passedArgs[0], 'readonly' => true]); + } + + echo $this->Form->input('nom'); + echo $this->Form->input('type_document_id', ['label' => 'Type', 'options' => $typesD, 'default' => 1]); + echo $this->Form->input('description'); + + echo $this->Form->hidden('chemin_file', ['label' => 'Fichier ('.substr($configuration->taille_max_doc/(1024*1024), 0, 4).' Mo max)', 'type' => 'file']); + + echo $this->Form->hidden('edit', ['default' => 1]); + + if(isset($photo)) { + echo $this->Form->hidden('photo', ['default' => 1]); + } + else { + echo $this->Form->hidden('photo', ['default' => 0]); + } + + + + ?> +
+ Form->submit(__('Valider')) ?> + Form->end() ?> +
+ +
+ element('menu'); + echo $this->element('menu_form', [ 'pluralHumanName' => 'Documents' ]); + ?> +
diff --git a/src/Template/Documents/index.ctp b/src/Template/Documents/index.ctp index 46bf87f..1e2ad23 100755 --- a/src/Template/Documents/index.ctp +++ b/src/Template/Documents/index.ctp @@ -45,6 +45,8 @@ echo $this->Form->postLink(__(''), '/webroot/files/'.$document->id.'.'.$document->type_doc, ['title' => 'Télécharger', 'style' => 'margin: 0 2px', 'escape' => false ]); } ?> + Html->link(__(''), ['action' => 'edit', $document->id], ['title' => 'Editer', 'style' => 'margin: 0 2px', 'escape' => false]) ?> + Form->postLink(__(''), ['action' => 'delete', $document->id], ['title' => 'Supprimer', 'style' => 'margin: 0 2px', 'escape' => false, 'confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $document->id)]) ?> diff --git a/src/Template/Documents/view.ctp b/src/Template/Documents/view.ctp index 50ac248..ceec7c4 100755 --- a/src/Template/Documents/view.ctp +++ b/src/Template/Documents/view.ctp @@ -17,7 +17,9 @@ $displayElement(__('Nom'), h($document->nom)); $displayElement(__('Type'), $document->has('type_document') ? h($document->type_document->nom) : ''); - $displayElement(__('Description'), h($document->description)); + + echo ''.__('Description').' '.nl2br($document->description).''; + $displayElement(__('Extension fichier'), h($document->type_doc)); diff --git a/src/Template/Element/menu_view.ctp b/src/Template/Element/menu_view.ctp index 00f24cc..797ef97 100755 --- a/src/Template/Element/menu_view.ctp +++ b/src/Template/Element/menu_view.ctp @@ -1,3 +1,7 @@ + +