diff --git a/README-LABINVENT.md b/README-LABINVENT.md index 84b5ff3..040b2bf 100755 --- a/README-LABINVENT.md +++ b/README-LABINVENT.md @@ -50,19 +50,18 @@ Logiciel testé et validé sur les configurations suivantes : VERSION ACTUELLE -Date: 27/06/2016 -Version: 2.5.0.0 +Date: 28/06/2016 +Version: 2.5.1.0 -!!! Se placer dans database/update et exécuter le script ./db-update-2016-06-27.sh !!! +!!! Se placer dans database/update et exécuter le script ./db-update-2016-06-28.sh !!! -Documents + Type documents + Réorganisation configuration générale (view) + Bugfixes (numero de labo, ... ) +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/3789 - https://projects.irap.omp.eu/issues/3762 - https://projects.irap.omp.eu/issues/3791 +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/3790 - https://projects.irap.omp.eu/issues/3716 +Demande (en cours) : https://projects.irap.omp.eu/issues/3716 Version majeure en cours (2.5): https://projects.irap.omp.eu/versions/99 @@ -101,6 +100,10 @@ Liste complète des évolutions: https://gitlab.irap.omp.eu/epallier/labinvent/c MODIFICATIONS STRUCTURELLES A FAIRE MANUELLEMENT APRES LA MISE A JOUR (git pull) +28/06/16 (v2.5.1.0) Se placer dans database/update et exécuter le script ./db-update-2016-06-28.sh + +27/06/16 (v2.5.0.0) Se placer dans database/update et exécuter le script ./db-update-2016-06-27.sh + 24/06/16 (v2.4.7.2) Se placer dans database/update et exécuter le script ./db-update-2016-06-24-2.sh 24/06/16 (v2.4.7.0) Se placer dans database/update et exécuter le script ./db-update-2016-06-24.sh diff --git a/database/labinvent_2.1_12-05-16.sql b/database/labinvent_2.1_12-05-16.sql index dccb249..c16d2be 100755 --- a/database/labinvent_2.1_12-05-16.sql +++ b/database/labinvent_2.1_12-05-16.sql @@ -73,11 +73,11 @@ CREATE TABLE IF NOT EXISTS `documents` ( `id` int(11) NOT NULL AUTO_INCREMENT, `type_doc` varchar(20) DEFAULT NULL, `description` text DEFAULT NULL, - `chemin` varchar(200) DEFAULT NULL, `nom` VARCHAR(100) DEFAULT NULL, `materiel_id` int(11) DEFAULT NULL, `suivi_id` int(11) DEFAULT NULL, `type_document_id` int(11) DEFAULT NULL, + `photo` tinyint(1) DEFAULT NULL, PRIMARY KEY (`id`), KEY `fk_documents_materiel_id` (`materiel_id`), KEY `fk_documents_suivi_id` (`suivi_id`), @@ -182,6 +182,7 @@ CREATE TABLE IF NOT EXISTS `materiels` ( `date_fin_garantie` date DEFAULT NULL, `duree_garantie` int(10) DEFAULT NULL, `unite_duree_garantie` varchar (30) DEFAULT NULL, + `photo_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `numero_irap` (`numero_laboratoire`), KEY `fk_administrative_materials_sub_categories1` (`sous_categorie_id`), @@ -298,7 +299,6 @@ CREATE TABLE `type_documents` ( PRIMARY KEY (`id`) ); -Insert into type_documents(id, nom) values (1, 'N/A'); -- -------------------------------------------------------- -- -- Structure de la table `users` @@ -360,6 +360,7 @@ CREATE TABLE IF NOT EXISTS `configurations` ( `prix_inventaire_administratif` int( 10 ) DEFAULT '800', `numero_labo_sans_annee` tinyint(1) DEFAULT NULL, `date_commande_facultative` tinyint(1) DEFAULT NULL, + `taille_max_doc` int (15) DEFAULT '8000000', PRIMARY KEY (`id`), UNIQUE KEY `nom_UNIQUE` (`nom`) ); @@ -430,10 +431,24 @@ ALTER TABLE `users` Insert into type_suivis(nom) values ('Réparation'); Insert into sites(id, nom) values (9, 'N/A'); +Insert into type_documents(id, nom) values (1, 'N/A'); +Insert into type_documents(nom) values ('Bon de commande'); +Insert into type_documents(nom) values ('Bon de livraison'); +Insert into type_documents(nom) values ('Photo'); +Insert into type_documents(nom) values ('Documentation technique'); +Insert into type_documents(nom) values ('Spécifications'); +Insert into type_documents(nom) values ('CR de maintenance'); +Insert into type_documents(nom) values ('CR d\'étalonnage'); +Insert into type_documents(nom) values ('Suivi de panne'); +Insert into type_documents(nom) values ('Certificat de garantie'); +Insert into type_documents(nom) values ('Certificat de conformité'); +Insert into type_documents(nom) values ('Manuel d\'utilisation'); + -- Insertion par défaut pour la table configuration Insert into `configurations`(`nom`, `mode_install`, `mode_debug`, `use_ldap`, `host_ldap`, `port_ldap`, `authentificationType_ldap`, `baseDn_ldap`, `filter_ldap`, `labName`, `labNameShort`, `labPresent`, `labUmr`, `hasPrinter`, `emailGuest1`, `emailGuest2`, `emailGuest3`) values ('default', '1', '0', '0', '', '', 'xxx', '', '', 'LABONAME', 'LABO', 'du ', '', '0', '', '', ''); + /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/database/update/db-update-2016-06-28.sh b/database/update/db-update-2016-06-28.sh new file mode 100755 index 0000000..e44920c --- /dev/null +++ b/database/update/db-update-2016-06-28.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Pour Mac OS recent (10.10, Yosemite), la syntaxe du SED est differente +# Il faut donc faire une copie de ce fichier et transformer les instructions sed a l'interieur +# Pour cela, il suffit d'executer ces 2 lignes : +# cp ce_script.sh ce_script_macosx.sh +# sed -e "s/ -i / -i '' /" -i '' ce_script_macosx.sh + +if [ ! -f ../../config/app.php ] ; then +echo "Vous devez executer ce script depuis le dossier database/update/" +exit 1 +fi + +if [ ! -d "../../webroot/img/photos" ]; then + mkdir ../../webroot/img/photos +fi + + +# Get login, pass, dbname, and hostname +username=$(grep "/\*d\*/'username'" ../../config/app.php | cut -d"'" -f4) +password=$(grep "/\*d\*/'password'" ../../config/app.php | cut -d"'" -f4) +database=$(grep "/\*d\*/'database'" ../../config/app.php | cut -d"'" -f4) +host=$(grep "/\*d\*/'host'" ../../config/app.php | cut -d"'" -f4) + + +cp -p ./script_sql/db-update-2016-06-28.sql ./script_sql/db-update-2016-06-28-build.sql + +# Execute sql update script +sed -e "s/database/$database/" -i ./script_sql/db-update-2016-06-28-build.sql +mysql --user=$username --password=$password -h $host < ./script_sql/db-update-2016-06-28-build.sql + +# Delete cakephp cache +sudo rm ../../tmp/cache/models/* +sudo rm ../../tmp/cache/persistent/* + +sudo chmod -R 777 ../../tmp +sudo chmod -R 777 ../../vendor +sudo chmod -R 777 ../../webroot diff --git a/database/update/script_sql/db-update-2016-06-28.sql b/database/update/script_sql/db-update-2016-06-28.sql new file mode 100755 index 0000000..063b560 --- /dev/null +++ b/database/update/script_sql/db-update-2016-06-28.sql @@ -0,0 +1,20 @@ +use database; + +ALTER TABLE `materiels` ADD `photo_id` int(11) DEFAULT NULL; + +ALTER TABLE `configurations` ADD `taille_max_doc` int (15) DEFAULT '8000000'; + +ALTER TABLE `documents` ADD `photo` tinyint(1) DEFAULT NULL; + +Insert into type_documents(nom) values ('Bon de commande'); +Insert into type_documents(nom) values ('Bon de livraison'); +Insert into type_documents(nom) values ('Photo'); +Insert into type_documents(nom) values ('Documentation technique'); +Insert into type_documents(nom) values ('Spécifications'); +Insert into type_documents(nom) values ('CR de maintenance'); +Insert into type_documents(nom) values ('CR d\'étalonnage'); +Insert into type_documents(nom) values ('Suivi de panne'); + +Insert into type_documents(nom) values ('Certificat de garantie'); +Insert into type_documents(nom) values ('Certificat de conformité'); +Insert into type_documents(nom) values ('Manuel d\'utilisation'); diff --git a/install/installation.sh b/install/installation.sh index 8b4700a..635c403 100755 --- a/install/installation.sh +++ b/install/installation.sh @@ -98,6 +98,9 @@ fi if [ ! -d "./webroot/img/qrcodes" ]; then mkdir ./webroot/img/qrcodes fi +if [ ! -d "./webroot/img/photos" ]; then + mkdir ./webroot/img/photos +fi if [ ! -d "./vendor/phpunit" ]; then ./composer.phar require --dev phpunit/phpunit diff --git a/src/Controller/DocumentsController.php b/src/Controller/DocumentsController.php index 096839e..de5b3d4 100755 --- a/src/Controller/DocumentsController.php +++ b/src/Controller/DocumentsController.php @@ -35,9 +35,17 @@ class DocumentsController extends AppController return true; } } + + if($action == 'delete') { + if ($this->userHasRole('Administration')) { + return true; + } + } //Pour tout le monde if (in_array($action, ['view', 'add', 'ficheMateriel'])) return true; + + return false; } /** @@ -96,9 +104,27 @@ class DocumentsController extends AppController if ($this->request->is('post')) { $document = $this->Documents->patchEntity($document, $this->request->data); + 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é.')); + 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); + $this->Documents->delete($docOld); + } + + $materiel->set('photo_id', $document->id); + $materielTable->save($materiel); + } + $id = $document->materiel_id; if(empty($id)) { $id = $document->suivi_id; @@ -120,6 +146,10 @@ class DocumentsController extends AppController $suivi = $this->Documents->Suivis->find('list', [ 'keyField' => 'id', 'valueField' => 'id'])->where(['id =' => $this->passedArgs[0]]); $this->set('suivi', $suivi); } + + if(isset($this->passedArgs[2]) && $this->passedArgs[2] == 'photo') { + $this->set('photo', 1); + } $typesD = $this->Documents->TypeDocuments->find('list', [ 'keyField' => 'id', 'valueField' => 'nom', 'order' => 'TypeDocuments.nom']); @@ -141,6 +171,14 @@ class DocumentsController extends AppController $this->request->allowMethod(['post', 'delete']); $document = $this->Documents->get($id); + if($document->photo) { + $materielTable = TableRegistry::get('Materiels'); + $materiel = $materielTable->get($document->materiel_id); + + $materiel->set('photo_id', null); + $materielTable->save($materiel); + } + if ($this->Documents->delete($document)) { $this->Flash->success(__('Le fichier a bien été supprimé.')); } else { diff --git a/src/Controller/MaterielsController.php b/src/Controller/MaterielsController.php index ff1ad35..8f37a0d 100755 --- a/src/Controller/MaterielsController.php +++ b/src/Controller/MaterielsController.php @@ -217,6 +217,11 @@ class MaterielsController extends AppController $typeSuivis = TableRegistry::get('TypeSuivis'); $typeDocuments = TableRegistry::get('TypeDocuments'); + if($materiel->photo_id != null) { + $imgMateriel = $materiel->photo_id.'.'.TableRegistry::get('Documents')->get($materiel->photo_id)->get('type_doc'); + $this->set('imgMateriel', $imgMateriel); + } + $this->set('sites', $sites); $this->set('typeSuivis', $typeSuivis); $this->set('typeDocuments', $typeDocuments); diff --git a/src/Model/Entity/Configuration.php b/src/Model/Entity/Configuration.php index cd5885a..3f6b6f2 100644 --- a/src/Model/Entity/Configuration.php +++ b/src/Model/Entity/Configuration.php @@ -39,6 +39,7 @@ use Cake\ORM\Entity; * @property bool $date_commande_facultative * @property bool $numero_labo_sans_annee * @property int $prix_inventaire_administratif + * @property int $taille_max_doc */ class Configuration extends Entity { diff --git a/src/Model/Entity/Document.php b/src/Model/Entity/Document.php index 172b966..5f294d6 100755 --- a/src/Model/Entity/Document.php +++ b/src/Model/Entity/Document.php @@ -11,6 +11,7 @@ use Cake\ORM\Entity; * @property string $chemin * @property string $description * @property string $nom + * @property bool $photo * @property int $materiel_id * @property \App\Model\Entity\Materiel $materiel * @property int $suivi_id diff --git a/src/Model/Entity/Materiel.php b/src/Model/Entity/Materiel.php index 4b19ea4..2dca35e 100755 --- a/src/Model/Entity/Materiel.php +++ b/src/Model/Entity/Materiel.php @@ -48,6 +48,7 @@ use Cake\ORM\Entity; * @property int $organisme_id * @property \App\Model\Entity\Organisme $organisme * @property int $site_id + * @property int $photo_id * @property bool $hors_service * @property \App\Model\Entity\Site $site * @property \App\Model\Entity\Document[] $documents diff --git a/src/Model/Table/AppTable.php b/src/Model/Table/AppTable.php index c60072c..32a6535 100644 --- a/src/Model/Table/AppTable.php +++ b/src/Model/Table/AppTable.php @@ -20,7 +20,7 @@ class AppTable extends Table // autoriser les caracteres spéciaux (pour une PHRASE ou paragraphe) : // check_string PLUS ces symboles ====> & * > < ? % ! : , " ' public function check_string_with_some_special_cars($check) { - return (bool) preg_match('/^['.$this->string.'?%!:,&*><\-\+\="\''.']*$/', $check); + return (bool) preg_match('/^['.$this->string.'?%!:,*><\-\+\="\''.']*$/', $check); } public function check_mail($check) { diff --git a/src/Model/Table/ConfigurationsTable.php b/src/Model/Table/ConfigurationsTable.php index f19544e..45c0f5d 100644 --- a/src/Model/Table/ConfigurationsTable.php +++ b/src/Model/Table/ConfigurationsTable.php @@ -80,7 +80,7 @@ class ConfigurationsTable extends AppTable ->notEmpty('labNameShort'); $validator - ->allowEmpty('labPresent'); + ->notEmpty('labPresent'); $validator ->allowEmpty('labUmr'); @@ -136,7 +136,10 @@ class ConfigurationsTable extends AppTable ->allowEmpty('test'); $validator - ->allowEmpty('prix_inventaire_administratif'); + ->notEmpty('prix_inventaire_administratif'); + + $validator + ->notEmpty('taille_max_doc'); $validator ->allowEmpty('date_commande_facultative'); diff --git a/src/Model/Table/DocumentsTable.php b/src/Model/Table/DocumentsTable.php index a567b4b..98685fb 100755 --- a/src/Model/Table/DocumentsTable.php +++ b/src/Model/Table/DocumentsTable.php @@ -6,6 +6,7 @@ use Cake\ORM\Query; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; +use Cake\ORM\TableRegistry; /** * Documents Model @@ -73,6 +74,9 @@ class DocumentsTable extends AppTable $validator ->allowEmpty('materiel_id'); + + $validator + ->allowEmpty('photo'); $validator ->allowEmpty('suivi_id'); @@ -90,10 +94,13 @@ class DocumentsTable extends AppTable */ public function buildRules(RulesChecker $rules) { + $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 > 1000000) { + if($size > $config->taille_max_doc) { return false; } else { return true; @@ -104,11 +111,28 @@ class DocumentsTable extends AppTable }; + $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; + } + }; + + $rules->add($checkSizeDoc, [ 'errorField' => 'chemin_file', - 'message' => 'Le fichier ne peut pas avoir une taille supérieur à 8mo.' + 'message' => 'Le fichier ne peut pas avoir une taille supérieur à '.substr($config->taille_max_doc/(1024*1024), 0, 4).' Mo.' ]); + $rules->add($checkPhoto, [ + 'errorField' => 'chemin_file', + 'message' => 'La photo doit etre au format png, jpg (ou jpeg).' + ]); + + return $rules; } @@ -144,7 +168,12 @@ class DocumentsTable extends AppTable $file = $entity->get('chemin_file'); if(!empty($file['tmp_name'])) { $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); - move_uploaded_file($file['tmp_name'], 'files'.DS.$entity->get('id').'.'.$extension); + if($entity->get('photo')) { + move_uploaded_file($file['tmp_name'], 'img'.DS.'photos'.DS.$entity->get('id').'.'.$extension); + } + else { + move_uploaded_file($file['tmp_name'], 'files'.DS.$entity->get('id').'.'.$extension); + } } } @@ -154,8 +183,12 @@ class DocumentsTable extends AppTable **/ public function afterDelete($event, $entity, $options) { $nomFichier = $entity->get('id').'.'.$entity->get('type_doc'); - unlink('files'.DS.$nomFichier); - + if($entity->get('photo')) { + unlink('img'.DS.'photos'.DS.$nomFichier); + } + else { + unlink('files'.DS.$nomFichier); + } } } diff --git a/src/Model/Table/MaterielsTable.php b/src/Model/Table/MaterielsTable.php index 9a0469e..0bbcc35 100755 --- a/src/Model/Table/MaterielsTable.php +++ b/src/Model/Table/MaterielsTable.php @@ -165,6 +165,9 @@ class MaterielsTable extends AppTable ->allowEmpty('date_archivage'); $validator + ->allowEmpty('photo_id'); + + $validator ->boolean('etiquette') ->allowEmpty('etiquette'); diff --git a/src/Template/Configurations/edit.ctp b/src/Template/Configurations/edit.ctp index 3047592..1aa5d03 100644 --- a/src/Template/Configurations/edit.ctp +++ b/src/Template/Configurations/edit.ctp @@ -5,48 +5,83 @@
= $this->Form->submit(__('Valider')) ?> diff --git a/src/Template/Configurations/view.ctp b/src/Template/Configurations/view.ctp index 09af3d5..87723e0 100644 --- a/src/Template/Configurations/view.ctp +++ b/src/Template/Configurations/view.ctp @@ -86,6 +86,7 @@ echo '