From b8c293fb1687b36e4309d4e118291476ad241747 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 4 Jul 2014 14:48:27 +0200 Subject: [PATCH 1/3] $dateSelector is a paramters of formAddObjectLine, if use global it is reset to 0 because not declare in outer context but already exists in the same context. --- htdocs/core/tpl/objectline_create.tpl.php | 2 +- htdocs/core/tpl/objectline_edit.tpl.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 4255f124c1ccc..170cc1e0fc74c 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -31,7 +31,7 @@ $usemargins=0; if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1; -global $dateSelector, $forceall, $senderissupplier, $inputalsopricewithtax; +global $forceall, $senderissupplier, $inputalsopricewithtax; if (empty($dateSelector)) $dateSelector=0; if (empty($forceall)) $forceall=0; if (empty($senderissupplier)) $senderissupplier=0; diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index 54348b2d64686..95402139f7e9f 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -31,7 +31,7 @@ $usemargins=0; if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1; -global $dateSelector, $forceall, $senderissupplier, $inputalsopricewithtax; +global $forceall, $senderissupplier, $inputalsopricewithtax; if (empty($dateSelector)) $dateSelector=0; if (empty($forceall)) $forceall=0; if (empty($senderissupplier)) $senderissupplier=0; From 02574a7af2c18b9f0e9e2169ad79ed7e6fce2311 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sat, 5 Jul 2014 11:17:50 +0200 Subject: [PATCH 2/3] Fix Ajax combobox in Extrafeilds Add Extrafield on contract --- htdocs/contrat/class/contrat.class.php | 21 ++++ htdocs/contrat/fiche.php | 127 +++++++++++++++++++----- htdocs/core/class/extrafields.class.php | 4 +- htdocs/main.inc.php | 2 +- htdocs/product/class/product.class.php | 8 ++ 5 files changed, 133 insertions(+), 29 deletions(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index daf22e0af7c8f..d384eea9b914e 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -448,6 +448,14 @@ function fetch($id,$ref='') $this->extraparams = (array) json_decode($result["extraparams"], true); $this->db->free($resql); + + // Retreive all extrafield for thirdparty + // fetch optionals attributes and labels + require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); + $extrafields=new ExtraFields($this->db); + $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); + $this->fetch_optionals($this->id,$extralabels); + return $this->id; } @@ -753,6 +761,19 @@ function create($user) // Insert contacts commerciaux ('SALESREPFOLL','contrat') $result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal'); if ($result < 0) $error++; + + + if (! $error) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } if (! $error) { diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index 0bee62d4f12e1..4c842e25f5544 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -5,7 +5,7 @@ * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010-2013 Juanjo Menent * Copyright (C) 2013 Christophe Battarel - * Copyright (C) 2013 Florian Henry + * Copyright (C) 2013-2014 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 @@ -40,6 +40,7 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; } +require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; $langs->load("contracts"); $langs->load("orders"); @@ -65,6 +66,10 @@ $hookmanager->initHooks(array('contractcard')); $object = new Contrat($db); +$extrafields = new ExtraFields($db); + +// fetch optionals attributes and labels +$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $permissionnote=$user->rights->contrat->creer; // Used by the include of actions_setnotes.inc.php @@ -86,7 +91,7 @@ exit; } else { - $mesg=$object->error; + setEventMessage($object->error,'errors'); } } @@ -107,7 +112,7 @@ exit; } else { - $mesg=$object->error; + setEventMessage($object->error,'errors'); } } } @@ -176,7 +181,7 @@ if (empty($datecontrat)) { $error++; - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")).'
'; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")),'errors'); $action='create'; } @@ -228,7 +233,7 @@ $id = $object->create($user); if ($id < 0) { - $mesg='
'.$object->error.'
'; + setEventMessage($object->error,'errors'); } if ($id > 0) @@ -319,26 +324,30 @@ } else { - $mesg=$srcobject->error; + setEventMessage($srcobject->error,'errors'); $error++; } } else { - $mesg=$object->error; + setEventMessage($object->error,'errors'); $error++; } } else { - $result = $object->create($user,$langs,$conf); + + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + + $result = $object->create($user); if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { - $mesg='
'.$object->error.'
'; + setEventMessage($object->error,'errors'); } $action='create'; } @@ -389,7 +398,7 @@ $ret=$object->fetch($id); if ($ret < 0) { - dol_print_error($db,$object->error); + setEventMessage($object->error,'errors'); exit; } $ret=$object->fetch_thirdparty(); @@ -546,7 +555,7 @@ } else { - $mesg='
'.$object->error.'
'; + setEventMessage($object->error,'errors'); } } } @@ -604,13 +613,13 @@ } else { - dol_print_error($db,'Failed to update contrat_det'); + setEventMessage($objectline->error,'errors'); $db->rollback(); } } else { - dol_print_error($db); + setEventMessage($objectline->error,'errors'); } } @@ -626,7 +635,7 @@ } else { - $mesg=$object->error; + setEventMessage($object->error,'errors'); } } @@ -655,7 +664,7 @@ } else { - $mesg='
'.$object->error.'
'; + setEventMessage($object->error,'errors'); } } @@ -674,12 +683,33 @@ } else { - $mesg='
'.$object->error.'
'; + setEventMessage($object->error,'errors'); } } else { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("RefNewContract")).'
'; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("RefNewContract")),'errors'); + } +} else if ($action == 'update_extras') { + // Fill array 'array_options' with data from update form + $object->fetch($id); + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); + if ($ret < 0) + $error ++; + + if (! $error) { + + $result = $object->insertExtraFields(); + if ($result < 0) { + $error ++; + } + } else if ($reshook < 0) + $error ++; + + if ($error) { + $action = 'edit_extras'; + setEventMessage($object->error,'errors'); } } @@ -705,11 +735,11 @@ if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); - $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; + setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"),'errors'); } else { - $mesg = '
'.$object->error.'
'; + setEventMessage($object->error,'errors'); } } } @@ -723,7 +753,7 @@ } else { - dol_print_error($db); + setEventMessage($object->error,'errors'); } } @@ -739,7 +769,7 @@ exit; } else { - dol_print_error($db); + setEventMessage($object->error,'errors'); } } } @@ -765,8 +795,6 @@ { print_fiche_titre($langs->trans('AddContract')); - dol_htmloutput_errors($mesg,''); - $soc = new Societe($db); if ($socid>0) $soc->fetch($socid); @@ -902,8 +930,13 @@ } // Other attributes - $parameters=array('colspan' => ' colspan="3"'); + $parameters=array('objectsrc' => $objectsrc,'colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + + // Other attributes + if (empty($reshook) && ! empty($extrafields->attribute_label)) { + print $object->showOptionals($extrafields, 'edit'); + } print "\n"; @@ -937,8 +970,6 @@ $result=$object->fetch_thirdparty(); if ($result < 0) dol_print_error($db,$object->error); - dol_htmloutput_errors($mesg,''); - $nbofservices=count($object->lines); $author = new User($db); @@ -1065,6 +1096,50 @@ // Other attributes $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + + $res = $object->fetch_optionals($object->id, $extralabels); + if (empty($reshook) && ! empty($extrafields->attribute_label)) { + foreach ($extrafields->attribute_label as $key => $label) { + if ($action == 'edit_extras') { + $value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]); + } else { + $value = $object->array_options ["options_" . $key]; + } + if ($extrafields->attribute_type [$key] == 'separate') { + print $extrafields->showSeparator($key); + } else { + print 'attribute_required [$key])) + print ' class="fieldrequired"'; + print '>' . $label . ''; + // Convert date into timestamp format + if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) { + $value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]); + } + + if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key) { + print '
'; + print ''; + print ''; + print ''; + print ''; + + print $extrafields->showInputField($key, $value); + + print ''; + print '
'; + } else { + print $extrafields->showOutputField($key, $value); + if ($object->statut == 0 && $user->rights->commande->creer) + print '' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . ''; + } + print '' . "\n"; + } + } + } + + + print ""; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index df302f0ffad43..de8e5fc636de7 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -677,7 +677,7 @@ function showInputField($key,$value,$moreparam='',$keyprefix='') if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; - $out.= ajax_combobox('options_'.$key.$keyprefix, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); + $out.= ajax_combobox('options_'.$key.$keyprefix, array(), $conf->global->COMPANY_USE_SEARCH_TO_SELECT); } $out.=''; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index c24f9fc20360d..323f98ade045d 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1084,7 +1084,7 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs // JQuery. Must be before other includes print ''."\n"; if (constant('JS_JQUERY')) print ''."\n"; - else print ''."\n"; + else print ''."\n"; if (constant('JS_JQUERY_UI')) print ''."\n"; else print ''."\n"; print ''."\n"; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 2bdc950495e54..32d96ec60fc7e 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1392,6 +1392,14 @@ function fetch($id='',$ref='',$ref_ext='') $this->entity = $obj->entity; $this->db->free($resql); + + + // Retreive all extrafield for thirdparty + // fetch optionals attributes and labels + require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); + $extrafields=new ExtraFields($this->db); + $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); + $this->fetch_optionals($this->id,$extralabels); // multilangs From fe50d8b1ab8b34b672623c369dd0db87a9704480 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sat, 5 Jul 2014 11:19:49 +0200 Subject: [PATCH 3/3] restore min jquery --- htdocs/main.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 323f98ade045d..c24f9fc20360d 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1084,7 +1084,7 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs // JQuery. Must be before other includes print ''."\n"; if (constant('JS_JQUERY')) print ''."\n"; - else print ''."\n"; + else print ''."\n"; if (constant('JS_JQUERY_UI')) print ''."\n"; else print ''."\n"; print ''."\n";