diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index 675e1cf0794..3ba7cbf52ca 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -26,7 +26,7 @@ * Parent class for class inheritance lines of business objects * This class is useless for the moment so no inherit are done on it */ -abstract class CommonObjectLine +abstract class CommonObjectLine extends CommonObject { /** * Call trigger based on this instance diff --git a/htdocs/core/lib/fichinter.lib.php b/htdocs/core/lib/fichinter.lib.php index 01d79cdcabe..cb30a202513 100644 --- a/htdocs/core/lib/fichinter.lib.php +++ b/htdocs/core/lib/fichinter.lib.php @@ -126,6 +126,11 @@ function fichinter_admin_prepare_head() $head[$h][2] = 'attributes'; $h++; + $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinterdet_extrafields.php'; + $head[$h][1] = $langs->trans("ExtraFields"); + $head[$h][2] = 'attributesdet'; + $h++; + complete_head_from_modules($conf,$langs,null,$head,$h,'fichinter_admin','remove'); diff --git a/htdocs/fichinter/admin/fichinterdet_extrafields.php b/htdocs/fichinter/admin/fichinterdet_extrafields.php new file mode 100644 index 00000000000..7f8b5193631 --- /dev/null +++ b/htdocs/fichinter/admin/fichinterdet_extrafields.php @@ -0,0 +1,159 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2013 Florian Henry + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/fichinter/admin/fichinter_extrafields.php + * \ingroup fichinter + * \brief Page to setup extra fields of ficheinter + */ + + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + +$langs->load("companies"); +$langs->load("admin"); +$langs->load("members"); +$langs->load('interventions'); + +$extrafields = new ExtraFields($db); +$form = new Form($db); + +// List of supported format +$tmptype2label=ExtraFields::$type2label; +$type2label=array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val); + +$action=GETPOST('action', 'alpha'); +$attrname=GETPOST('attrname', 'alpha'); +$elementtype='fichinterdet'; //Must be the $element of the class that manage extrafield + +if (!$user->admin) accessforbidden(); + + +/* + * Actions + */ + +require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; + + + +/* + * View + */ + + +llxHeader(); + +$textobject=$langs->transnoentitiesnoconv("Interventions"); + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans("InterventionsSetup"),$linkback,'setup'); + + +$head=fichinter_admin_prepare_head(); + +dol_fiche_head($head, 'attributesdet', $langs->trans("Interventions"), 0, 'intervention'); + + +print $langs->trans("DefineHereComplementaryAttributes",$textobject).'
'."\n"; +print '
'; + +// Load attribute_label +$extrafields->fetch_name_optionals_label($elementtype); + +print ""; + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +$var=True; +foreach($extrafields->attribute_type as $key => $value) +{ + $var=!$var; + print ""; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print '\n"; + print '\n"; + print '\n"; + print '\n"; + print ""; + // $i++; +} + +print "
'.$langs->trans("Position").''.$langs->trans("Label").''.$langs->trans("AttributeCode").''.$langs->trans("Type").''.$langs->trans("Size").''.$langs->trans("Unique").''.$langs->trans("Required").' 
".$extrafields->attribute_pos[$key]."".$extrafields->attribute_label[$key]."".$key."".$type2label[$extrafields->attribute_type[$key]]."'.$extrafields->attribute_size[$key]."'.yn($extrafields->attribute_unique[$key])."'.yn($extrafields->attribute_required[$key])."'.img_edit().''; + print "  ".img_delete()."
"; + +dol_fiche_end(); + + +// Buttons +if ($action != 'create' && $action != 'edit') +{ + print '
'; + print "".$langs->trans("NewAttribute").""; + print "
"; +} + + +/* ************************************************************************** */ +/* */ +/* Creation d'un champ optionnel + /* */ +/* ************************************************************************** */ + +if ($action == 'create') +{ + print "
"; + print_titre($langs->trans('NewAttribute')); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php'; +} + +/* ************************************************************************** */ +/* */ +/* Edition d'un champ optionnel */ +/* */ +/* ************************************************************************** */ +if ($action == 'edit' && ! empty($attrname)) +{ + print "
"; + print_titre($langs->trans("FieldEdition", $attrname)); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php'; +} + +llxFooter(); + +$db->close(); diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index cb4f178b840..80375648e26 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -167,6 +167,17 @@ class Fichinter extends CommonObject $resql=$this->db->query($sql); if (! $resql) $error++; } + + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + // Add linked object if (! $error && $this->origin && $this->origin_id) { @@ -855,7 +866,7 @@ class Fichinter extends CommonObject * @param int $duration Intervention duration * @return int >0 if ok, <0 if ko */ - function addline($user,$fichinterid, $desc, $date_intervention, $duration) + function addline($user,$fichinterid, $desc, $date_intervention, $duration, $array_option=0) { dol_syslog("Fichinter::Addline $fichinterid, $desc, $date_intervention, $duration"); @@ -871,14 +882,20 @@ class Fichinter extends CommonObject $line->datei = $date_intervention; $line->duration = $duration; + if (is_array($array_option) && count($array_option)>0) { + $line->array_options=$array_option; + } + $result=$line->insert($user); - if ($result > 0) + + if ($result >= 0) { + $this->db->commit(); return 1; } else - { + { $this->error=$this->db->error(); $this->db->rollback(); return -1; @@ -987,7 +1004,10 @@ class FichinterLigne extends CommonObjectLine var $duration; // Duree de l'intervention var $rang = 0; - + public $element='fichinterdet'; + public $table_element='fichinterdet'; + public $fk_element='fk_fichinter'; + /** * Constructor * @@ -1017,6 +1037,7 @@ class FichinterLigne extends CommonObjectLine { $objp = $this->db->fetch_object($result); $this->rowid = $objp->rowid; + $this->id = $objp->rowid; $this->fk_fichinter = $objp->fk_fichinter; $this->datei = $this->db->jdate($objp->datei); $this->desc = $objp->description; @@ -1082,7 +1103,21 @@ class FichinterLigne extends CommonObjectLine $resql=$this->db->query($sql); if ($resql) { + $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'fichinterdet'); + + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $this->id=$this->rowid; + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + + $result=$this->update_total(); + if ($result > 0) { $this->rang=$rangToUse; @@ -1140,6 +1175,17 @@ class FichinterLigne extends CommonObjectLine $resql=$this->db->query($sql); if ($resql) { + + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $this->id=$this->rowid; + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + $result=$this->update_total(); if ($result > 0) { diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 437002aa23c..36bf1690b3c 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -196,6 +196,13 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); } + // Extrafields + $extrafields = new ExtraFields($db); + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $array_option = $extrafields->getOptionalsFromPost($extralabels); + + $object->array_options = $array_option; + $id = $object->create($user); if ($id > 0) @@ -266,12 +273,20 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $duration = 0; } + $predef = ''; + // Extrafields + $extrafieldsline = new ExtraFields($db); + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); + $array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); + + $result = $object->addline( $user, $id, $desc, $date_intervention, - $duration + $duration, + $array_option ); if ($result < 0) @@ -298,6 +313,13 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) } else { + // Extrafields + $extrafields = new ExtraFields($db); + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $array_option = $extrafields->getOptionalsFromPost($extralabels); + + $object->array_options = $array_option; + $result = $object->create($user); if ($result > 0) { @@ -433,12 +455,19 @@ else if ($action == "addline" && $user->rights->ficheinter->creer) $date_intervention = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int')); $duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int')); + + // Extrafields + $extrafieldsline = new ExtraFields($db); + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); + $array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline); + $result=$object->addline( $user, $id, $desc, $date_intervention, - $duration + $duration, + $array_option ); // Define output language @@ -524,6 +553,13 @@ else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST( $objectline->datei = $date_inter; $objectline->desc = $desc; $objectline->duration = $duration; + + // Extrafields + $extrafieldsline = new ExtraFields($db); + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); + $array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline); + $objectline->array_options = $array_option; + $result = $objectline->update($user); if ($result < 0) { @@ -1433,6 +1469,18 @@ else if ($id > 0 || ! empty($ref)) } print ''; + + $line = new FichinterLigne($db); + $line->fetch($objp->rowid); + + $extrafieldsline = new ExtraFields($db); + $extralabelslines=$extrafieldsline->fetch_name_optionals_label($line->table_element); + + $line->fetch_optionals($line->rowid, $extralabelslines); + + print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>5)); + + } // Line in update mode @@ -1461,6 +1509,17 @@ else if ($id > 0 || ! empty($ref)) print ''; print '
'; print '' . "\n"; + + $line = new FichinterLigne($db); + $line->fetch($objp->rowid); + + $extrafieldsline = new ExtraFields($db); + $extralabelslines=$extrafieldsline->fetch_name_optionals_label($line->table_element); + $line->fetch_optionals($line->rowid, $extralabelslines); + + print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>5)); + + } $i++; @@ -1511,7 +1570,16 @@ else if ($id > 0 || ! empty($ref)) print ''; print ''; - + + //Line extrafield + + $lineadd = new FichinterLigne($db); + + $extrafieldsline = new ExtraFields($db); + $extralabelslines=$extrafieldsline->fetch_name_optionals_label($lineadd->table_element); + + print $lineadd->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>5)); + if (! $num) print ''; } diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index cbe07b2fbdf..451a46dfb03 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -992,3 +992,15 @@ ALTER TABLE llx_actioncomm ADD INDEX idx_actioncomm_fk_element (fk_element); ALTER TABLE llx_projet_task_time ADD INDEX idx_projet_task_time_task (fk_task); ALTER TABLE llx_projet_task_time ADD INDEX idx_projet_task_time_date (task_date); ALTER TABLE llx_projet_task_time ADD INDEX idx_projet_task_time_datehour (task_datehour); + + +-- add extrafield on ficheinter lines +CREATE TABLE IF NOT EXISTS `llx_fichinterdet_extrafields` ( + `rowid` int(11) NOT NULL AUTO_INCREMENT, + `tms` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `fk_object` int(11) NOT NULL, + `import_key` varchar(14) DEFAULT NULL, + PRIMARY KEY (`rowid`), + KEY `idx_ficheinter_extrafields` (`fk_object`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; +