diff --git a/htdocs/admin/agenda_extrafields.php b/htdocs/admin/agenda_extrafields.php new file mode 100644 index 00000000000..4e1518d97aa --- /dev/null +++ b/htdocs/admin/agenda_extrafields.php @@ -0,0 +1,161 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2012 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 2 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/admin/agenda_extrafields.php + * \ingroup agenda + * \brief Page to setup extra fields of agenda + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + + +if (!$user->admin) + accessforbidden(); + +$langs->load("admin"); +$langs->load("other"); + +$extrafields = new ExtraFields($db); +$form = new Form($db); + +// List of supported format +$tmptype2label=getStaticMember(get_class($extrafields),'type2label'); +$type2label=array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val); + +$action=GETPOST('action', 'alpha'); +$attrname=GETPOST('attrname', 'alpha'); +$elementtype='actioncomm'; + +if (!$user->admin) accessforbidden(); + + +/* + * Actions + */ + +require DOL_DOCUMENT_ROOT.'/core/admin_extrafields.inc.php'; + + + +/* + * View + */ + + +llxHeader(); + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans("AgendaSetup"),$linkback,'setup'); +print "
\n"; + +print "
\n"; + +$head=agenda_prepare_head(); + +dol_fiche_head($head, 'attributes', $langs->trans("Agenda")); + + +print $langs->trans("DefineHereComplementaryAttributes",$textobject).'
'."\n"; +print '
'; + +dol_htmloutput_errors($mesg); + +// Load attribute_label +$extrafields->fetch_name_optionals_label($elementtype); + +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 ""; + // $i++; +} + +print "
'.$langs->trans("Label").''.$langs->trans("AttributeCode").''.$langs->trans("Type").''.$langs->trans("Size").''.$langs->trans("Unique").''.$langs->trans("Required").' 
".$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(); +?> \ No newline at end of file diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index a79650fa893..489c9d2409d 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -209,6 +209,25 @@ class ActionComm extends CommonObject { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."actioncomm","id"); + // Actions on extra fields (by external module or standard code) + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + $hookmanager->initHooks(array('actioncommdao')); + $parameters=array('actcomm'=>$this->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + else if ($reshook < 0) $error++; + if (! $notrigger) { // Appel des triggers @@ -343,7 +362,19 @@ class ActionComm extends CommonObject $sql.= " WHERE id=".$this->id; dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql)) + $res=$this->db->query($sql); + if ($res < 0) { + $this->error=$this->db->lasterror(); + $error++; + } + + // Removed extrafields + if (! $error) { + $result=$this->deleteExtraFields($this); + if ($result < 0) $error++; + } + + if (!$error) { if (! $notrigger) { @@ -437,6 +468,26 @@ class ActionComm extends CommonObject dol_syslog(get_class($this)."::update sql=".$sql); if ($this->db->query($sql)) { + + // Actions on extra fields (by external module or standard code) + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + $hookmanager->initHooks(array('actioncommdao')); + $parameters=array('actcomm'=>$this->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + else if ($reshook < 0) $error++; + if (! $notrigger) { // Appel des triggers diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php index 5b5ebee90ee..a574664f677 100644 --- a/htdocs/comm/action/fiche.php +++ b/htdocs/comm/action/fiche.php @@ -35,6 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $langs->load("companies"); $langs->load("commercial"); @@ -60,6 +61,8 @@ $mesg=''; $cactioncomm = new CActionComm($db); $actioncomm = new ActionComm($db); $contact = new Contact($db); +$extrafields = new ExtraFields($db); + //var_dump($_POST); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array @@ -202,6 +205,15 @@ if ($action == 'add_action') $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")).'
'; } + // Get extra fields + foreach($_POST as $key => $value) + { + if (preg_match("/^options_/",$key)) + { + $actioncomm->array_options[$key]=GETPOST($key); + } + } + if (! $error) { $db->begin(); @@ -332,6 +344,15 @@ if ($action == 'update') } $actioncomm->userdone = $userdone; + // Get extra fields + foreach($_POST as $key => $value) + { + if (preg_match("/^options_/",$key)) + { + $actioncomm->array_options[$key]=GETPOST($key); + } + } + if (! $error) { $db->begin(); @@ -375,6 +396,8 @@ llxHeader('',$langs->trans("Agenda"),$help_url); $form = new Form($db); $htmlactions = new FormActions($db); +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label('actioncomm'); if ($action == 'create') { @@ -579,11 +602,30 @@ if ($action == 'create') print ''; // Other attributes - $parameters=array(); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$actioncomm,$action); // Note that $action and $object may have been modified by hook + print ' '; + print ''; + + // Other attributes + $parameters=array(); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$actioncomm,$action); // Note that $action and $object may have been modified by hook print ''; + if (empty($reshook) && ! empty($extrafields->attribute_label)) + { + print '

'; + foreach($extrafields->attribute_label as $key=>$label) + { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($actioncomm->array_options["options_".$key])?$actioncomm->array_options["options_".$key]:'')); + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print ' width="30%">'.$label.''."\n"; + } + print '
'; + print $extrafields->showInputField($key,$value); + print '


'; + } + print '

'; print ''; print '     '; @@ -607,6 +649,8 @@ if ($id) $act = new ActionComm($db); $result=$act->fetch($id); + $act->fetch_optionals($id,$extralabels); + if ($result < 0) { dol_print_error($db,$act->error); @@ -792,8 +836,32 @@ if ($id) $doleditor->Create(); print ''; + // Other attributes + print ' '; + print ''; + + // Other attributes + $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3'); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook + print ''; + if (empty($reshook) && ! empty($extrafields->attribute_label)) + { + print '

'; + foreach($extrafields->attribute_label as $key=>$label) + { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$act->array_options["options_".$key]); + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print ' width="30%">'.$label.''."\n"; + } + print '
'; + print $extrafields->showInputField($key,$value); + print '


'; + } + + print '

'; print '     '; print '
'; @@ -957,11 +1025,28 @@ if ($id) print dol_htmlentitiesbr($act->note); print ''; - // Other attributes - $parameters=array(); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook + print ' '; + print ''; + + // Other attributes + $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3'); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook print ''; + + //Extra field + if (empty($reshook) && ! empty($extrafields->attribute_label)) + { + print '

'; + foreach($extrafields->attribute_label as $key=>$label) + { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($act->array_options['options_'.$key])?$act->array_options['options_'.$key]:'')); + print '\n"; + } + print '
'.$label.''; + print $extrafields->showOutputField($key,$value); + print "


'; + } } print "\n"; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index eb1c4c9e435..75a5086e711 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2067,6 +2067,36 @@ abstract class CommonObject } } + /** + * Delete all extra fields values for the current object. + * + * @return void + */ + function deleteExtraFields() + { + global $langs; + + $error=0; + + $this->db->begin(); + + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id; + dol_syslog(get_class($this)."::insertExtraFields delete sql=".$sql_del); + $this->db->query($sql_del); + + if (! $resql) + { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::delete ".$this->error,LOG_ERR); + $this->db->rollback(); + return -1; + } + else + { + $this->db->commit(); + return 1; + } + } /** * Add/Update all extra fields values for the current object. diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index 1c92cdf504e..f7d4cd430e3 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -384,6 +384,15 @@ function agenda_prepare_head() $head[$h][2] = 'extsites'; $h++; + complete_head_from_modules($conf,$langs,$object,$head,$h,'agenda_admin'); + + $head[$h][0] = DOL_URL_ROOT."/admin/agenda_extrafields.php"; + $head[$h][1] = $langs->trans("ExtraFields"); + $head[$h][2] = 'attributes'; + $h++; + + complete_head_from_modules($conf,$langs,$object,$head,$h,'agenda_admin','remove'); + return $head; }