Fix: Tons of bugs with extrafields feature.

This commit is contained in:
Laurent Destailleur 2013-11-05 13:11:36 +01:00
parent e5daee86b8
commit 190dabc3f7
12 changed files with 288 additions and 393 deletions

View File

@ -1159,22 +1159,17 @@ else if ($action == 'update_extras')
{ {
// Fill array 'array_options' with data from update form // Fill array 'array_options' with data from update form
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
if($ret < 0) $error++;
if($ret < 0) { if (! $error)
$error++; {
$action = 'edit_extras';
}
if(!$error) {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !! // FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('propaldao')); $hookmanager->initHooks(array('propaldao'));
$parameters=array('id'=>$object->id); $parameters=array('id'=>$object->id);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook)) if (empty($reshook))
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{ {
$result=$object->insertExtraFields(); $result=$object->insertExtraFields();
if ($result < 0) if ($result < 0)
@ -1182,9 +1177,10 @@ else if ($action == 'update_extras')
$error++; $error++;
} }
} }
}
else if ($reshook < 0) $error++; else if ($reshook < 0) $error++;
} }
if ($error) $action = 'edit_extras';
} }
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer) if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer)
@ -1893,20 +1889,12 @@ else
print '</tr>'; print '</tr>';
} }
// Other attributes // Other attributes (TODO Move this into an include)
$res=$object->fetch_optionals($object->id,$extralabels); $res=$object->fetch_optionals($object->id,$extralabels);
$parameters=array('colspan' => ' colspan="3"'); $parameters=array('colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label)) if (empty($reshook) && ! empty($extrafields->attribute_label))
{ {
if ($action == 'edit_extras')
{
print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
}
foreach($extrafields->attribute_label as $key=>$label) foreach($extrafields->attribute_label as $key=>$label)
{ {
if ($action == 'edit_extras') { if ($action == 'edit_extras') {
@ -1929,35 +1917,28 @@ else
$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]); $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->propal->creer) if ($action == 'edit_extras' && $user->rights->propal->creer && GETPOST('attribute') == $key)
{ {
print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="attribute" value="'.$key.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print $extrafields->showInputField($key,$value); print $extrafields->showInputField($key,$value);
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
} }
else else
{ {
print $extrafields->showOutputField($key,$value); print $extrafields->showOutputField($key,$value);
if ($object->statut == 0 && $user->rights->propal->creer) print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras&attribute='.$key.'">'.img_picto('','edit').' '.$langs->trans('Modify').'</a>';
} }
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
} }
if(count($extrafields->attribute_label) > 0) {
if ($action == 'edit_extras' && $user->rights->propal->creer)
{
print '<tr><td></td><td colspan="5">';
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
print '</td></tr>';
}
else {
if ($object->statut == 0 && $user->rights->propal->creer)
{
print '<tr><td></td><td><a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras">'.img_picto('','edit').' '.$langs->trans('Modify').'</a></td></tr>';
}
}
}
} }
// Amount HT // Amount HT

View File

@ -1179,20 +1179,17 @@ else if ($action == 'update_extras')
{ {
// Fill array 'array_options' with data from update form // Fill array 'array_options' with data from update form
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
if($ret < 0) $error++;
if($ret < 0) if (! $error)
$error++; {
if(!$error) {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !! // FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('orderdao')); $hookmanager->initHooks(array('orderdao'));
$parameters=array('id'=>$object->id); $parameters=array('id'=>$object->id);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook)) if (empty($reshook))
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{ {
$result=$object->insertExtraFields(); $result=$object->insertExtraFields();
if ($result < 0) if ($result < 0)
@ -1200,14 +1197,10 @@ else if ($action == 'update_extras')
$error++; $error++;
} }
} }
}
else if ($reshook < 0) $error++; else if ($reshook < 0) $error++;
} }
else
{
$action = 'edit_extras';
}
if ($error) $action = 'edit_extras';
} }
/* /*
@ -2208,20 +2201,12 @@ else
print '</tr>'; print '</tr>';
} }
// Other attributes // Other attributes (TODO Move this into an include)
$res=$object->fetch_optionals($object->id,$extralabels); $res=$object->fetch_optionals($object->id,$extralabels);
$parameters=array('colspan' => ' colspan="3"'); $parameters=array('colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label)) if (empty($reshook) && ! empty($extrafields->attribute_label))
{ {
if ($action == 'edit_extras')
{
print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
}
foreach($extrafields->attribute_label as $key=>$label) foreach($extrafields->attribute_label as $key=>$label)
{ {
if ($action == 'edit_extras') { if ($action == 'edit_extras') {
@ -2244,35 +2229,27 @@ else
$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]); $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) if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key)
{ {
print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="attribute" value="'.$key.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print $extrafields->showInputField($key,$value); print $extrafields->showInputField($key,$value);
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
} }
else else
{ {
print $extrafields->showOutputField($key,$value); print $extrafields->showOutputField($key,$value);
if ($object->statut == 0 && $user->rights->commande->creer) print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras&attribute='.$key.'">'.img_picto('','edit').' '.$langs->trans('Modify').'</a>';
} }
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
} }
if(count($extrafields->attribute_label) > 0) {
if ($action == 'edit_extras' && $user->rights->commande->creer)
{
print '<tr><td></td><td colspan="5">';
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
print '</td></tr>';
}
else {
if ($object->statut == 0 && $user->rights->commande->creer)
{
print '<tr><td></td><td><a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras">'.img_picto('','edit').' '.$langs->trans('Modify').'</a></td></tr>';
}
}
}
} }
$rowspan=4; $rowspan=4;

View File

@ -1926,19 +1926,17 @@ if ($action == 'update_extras')
{ {
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
if($ret < 0) if ($ret < 0) $error++;
$error++;
if(!$error) { if (! $error)
{
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !! // FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('invoicedao')); $hookmanager->initHooks(array('invoicedao'));
$parameters=array('id'=>$object->id); $parameters=array('id'=>$object->id);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook)) if (empty($reshook))
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{ {
$result=$object->insertExtraFields(); $result=$object->insertExtraFields();
if ($result < 0) if ($result < 0)
@ -1946,14 +1944,10 @@ if ($action == 'update_extras')
$error++; $error++;
} }
} }
}
else if ($reshook < 0) $error++; else if ($reshook < 0) $error++;
} }
else
{
$action = 'edit_extras';
}
if ($error) $action = 'edit_extras';
} }
@ -3413,21 +3407,13 @@ else if ($id > 0 || ! empty($ref))
print '</tr>'; print '</tr>';
} }
// Other attributes // Other attributes (TODO Move this into an include)
$res=$object->fetch_optionals($object->id,$extralabels); $res=$object->fetch_optionals($object->id,$extralabels);
$parameters=array('colspan' => ' colspan="2"'); $parameters=array('colspan' => ' colspan="2"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label)) if (empty($reshook) && ! empty($extrafields->attribute_label))
{ {
if ($action == 'edit_extras')
{
print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
}
foreach($extrafields->attribute_label as $key=>$label) foreach($extrafields->attribute_label as $key=>$label)
{ {
if ($action == 'edit_extras') { if ($action == 'edit_extras') {
@ -3450,35 +3436,27 @@ else if ($id > 0 || ! empty($ref))
$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]); $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->facture->creer) if ($action == 'edit_extras' && $user->rights->facture->creer && GETPOST('attribute') == $key)
{ {
print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="attribute" value="'.$key.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print $extrafields->showInputField($key,$value); print $extrafields->showInputField($key,$value);
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
} }
else else
{ {
print $extrafields->showOutputField($key,$value); print $extrafields->showOutputField($key,$value);
if ($object->statut == 0 && $user->rights->facture->creer) print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras&attribute='.$key.'">'.img_picto('','edit').' '.$langs->trans('Modify').'</a>';
} }
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
} }
if(count($extrafields->attribute_label) > 0) {
if ($action == 'edit_extras' && $user->rights->facture->creer)
{
print '<tr><td></td><td colspan="5">';
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
print '</td></tr>';
}
else {
if ($object->statut == 0 && $user->rights->facture->creer)
{
print '<tr><td></td><td><a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras">'.img_picto('','edit').' '.$langs->trans('Modify').'</a></td></tr>';
}
}
}
} }
print '</table><br>'; print '</table><br>';

View File

@ -146,6 +146,8 @@ if ($action == 'create')
/* ************************************************************************** */ /* ************************************************************************** */
if ($action == 'edit' && ! empty($attrname)) if ($action == 'edit' && ! empty($attrname))
{ {
$langs->load("members");
print "<br>"; print "<br>";
print_titre($langs->trans("FieldEdition", $attrname)); print_titre($langs->trans("FieldEdition", $attrname));

View File

@ -2142,10 +2142,12 @@ abstract class CommonObject
*/ */
function insertExtraFields() function insertExtraFields()
{ {
global $langs; global $conf,$langs;
$error=0; $error=0;
if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used
if (! empty($this->array_options)) if (! empty($this->array_options))
{ {
// Check parameters // Check parameters

View File

@ -688,21 +688,20 @@ class ExtraFields
{ {
$param_list=array_keys($param['options']); $param_list=array_keys($param['options']);
$InfoFieldList = explode(":", $param_list[0]); $InfoFieldList = explode(":", $param_list[0]);
// 0 : tableName
// 1 : label field name
// 2 : key fields name (if differ of rowid)
// 3 : key field parent (for dependent lists)
// 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
$keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid');
// 0 1 : tableName if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3]))
// 1 2 : label field name Nom du champ contenant le libelle {
// 2 3 : key fields name (if differ of rowid)
// 3 4 : key field parent (for dependent lists)
// 4 5 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
$keyList='rowid';
if (count($InfoFieldList)>=3) {
list($parentName, $parentField) = explode('|', $InfoFieldList[3]); list($parentName, $parentField) = explode('|', $InfoFieldList[3]);
$keyList.= ', '.$parentField; $keyList.= ', '.$parentField;
} }
if (count($InfoFieldList)>=4 && !empty($InfoFieldList[4])) { if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4]))
{
if (strpos($InfoFieldList[4], 'extra')!==false) { if (strpos($InfoFieldList[4], 'extra')!==false) {
$keyList='main.'.$InfoFieldList[2].' as rowid'; $keyList='main.'.$InfoFieldList[2].' as rowid';
} else { } else {
@ -710,32 +709,31 @@ class ExtraFields
} }
} }
$fields_label = explode('|',$InfoFieldList[1]); $fields_label = explode('|',$InfoFieldList[1]);
if(is_array($fields_label)) { if (is_array($fields_label))
$keyList .=', '; {
$keyList .= implode(', ', $fields_label);
}
$fields_label = explode('|',$InfoFieldList[1]);
if(is_array($fields_label)) {
$keyList .=', '; $keyList .=', ';
$keyList .= implode(', ', $fields_label); $keyList .= implode(', ', $fields_label);
} }
$sqlwhere='';
$sql = 'SELECT '.$keyList; $sql = 'SELECT '.$keyList;
$sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0];
if (!empty($InfoFieldList[4])) { if (!empty($InfoFieldList[4]))
{
//We have to join on extrafield table //We have to join on extrafield table
if (strpos($InfoFieldList[4], 'extra')!==false) { if (strpos($InfoFieldList[4], 'extra')!==false)
{
$sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra';
$sql.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; $sqlwhere.= ' AND extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4];
}else { }
$sql.= ' WHERE '.$InfoFieldList[4]; else
{
$sqlwhere.= ' AND '.$InfoFieldList[4];
} }
} }
//$sql.= ' WHERE entity = '.$conf->entity; if (in_array($InfoFieldList[0],array('tablewithentity'))) $sqlwhere.= ' AND entity = '.$conf->entity; // Some tables may have field, some other not. For the moment we disable it.
$sql.=preg_replace('/^ AND /','',$sqlwhere);
//print $sql; //print $sql;
dol_syslog(get_class($this).'::showInputField type=sellist sql='.$sql); dol_syslog(get_class($this).'::showInputField type=sellist sql='.$sql);
@ -807,6 +805,9 @@ class ExtraFields
} }
$this->db->free($resql); $this->db->free($resql);
} }
else {
print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>';
}
} }
$out.='</select>'; $out.='</select>';
} }
@ -1005,13 +1006,14 @@ class ExtraFields
} }
/** /**
* Fill array_options array for object by extrafields value (using for data send by forms) * Fill array_options property of object by extrafields value (using for data sent by forms)
* *
* @param array $extralabels $array of extrafields * @param array $extralabels $array of extrafields
* @param object &$object object * @param object &$object Object
* @param string $onlykey Only following key is filled
* @return int 1 if array_options set / 0 if no value * @return int 1 if array_options set / 0 if no value
*/ */
function setOptionalsFromPost($extralabels,&$object) function setOptionalsFromPost($extralabels,&$object,$onlykey='')
{ {
global $_POST, $langs; global $_POST, $langs;
$nofillrequired='';// For error when required field left blank $nofillrequired='';// For error when required field left blank
@ -1022,6 +1024,8 @@ class ExtraFields
// Get extra fields // Get extra fields
foreach ($extralabels as $key => $value) foreach ($extralabels as $key => $value)
{ {
if (! empty($onlykey) && $key != $onlykey) continue;
$key_type = $this->attribute_type[$key]; $key_type = $this->attribute_type[$key];
if($this->attribute_required[$key] && !GETPOST("options_$key",2)) if($this->attribute_required[$key] && !GETPOST("options_$key",2))
{ {

View File

@ -3680,7 +3680,7 @@ class Form
if ($typehour=='select') if ($typehour=='select')
{ {
print '<select class="flat" name="'.$prefix.'hour"'.($disabled?' disabled="disabled"':'').'>'; print '<select class="flat" name="'.$prefix.'hour"'.($disabled?' disabled="disabled"':'').'>';
for ($hour = 0; $hour < 24; $hour++) for ($hour = 0; $hour < 25; $hour++) // For a duration, we allow 24 hours
{ {
print '<option value="'.$hour.'"'; print '<option value="'.$hour.'"';
if ($hourSelected == $hour) if ($hourSelected == $hour)

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
@ -79,6 +79,15 @@ $object = new Fichinter($db);
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
// Load object
if ($id > 0 || ! empty($ref))
{
$ret=$object->fetch($id, $ref);
if ($ret > 0) $ret=$object->fetch_thirdparty();
if ($ret < 0) dol_print_error('',$object->error);
}
/* /*
* Actions * Actions
@ -86,9 +95,6 @@ $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->ficheinter->creer) if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->ficheinter->creer)
{ {
$object->fetch($id);
$object->fetch_thirdparty();
$result = $object->setValid($user); $result = $object->setValid($user);
if ($result >= 0) if ($result >= 0)
{ {
@ -114,9 +120,6 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->fichein
else if ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->ficheinter->creer) else if ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->ficheinter->creer)
{ {
$object->fetch($id);
$object->fetch_thirdparty();
$result = $object->setDraft($user); $result = $object->setDraft($user);
if ($result >= 0) if ($result >= 0)
{ {
@ -309,8 +312,6 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
else if ($action == 'update' && $user->rights->ficheinter->creer) else if ($action == 'update' && $user->rights->ficheinter->creer)
{ {
$object->fetch($id);
$object->socid = $socid; $object->socid = $socid;
$object->fk_project = GETPOST('projectid','int'); $object->fk_project = GETPOST('projectid','int');
$object->fk_contrat = GETPOST('contratid','int'); $object->fk_contrat = GETPOST('contratid','int');
@ -329,8 +330,6 @@ else if ($action == 'update' && $user->rights->ficheinter->creer)
*/ */
else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou en post else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou en post
{ {
$object->fetch($id);
$object->fetch_thirdparty();
$object->fetch_lines(); $object->fetch_lines();
// Save last template used to generate document // Save last template used to generate document
@ -356,8 +355,6 @@ else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou
// Remove file in doc form // Remove file in doc form
else if ($action == 'remove_file') else if ($action == 'remove_file')
{
if ($object->fetch($id))
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -370,12 +367,10 @@ else if ($action == 'remove_file')
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
} }
}
// Set into a project // Set into a project
else if ($action == 'classin' && $user->rights->ficheinter->creer) else if ($action == 'classin' && $user->rights->ficheinter->creer)
{ {
$object->fetch($id);
$result=$object->setProject(GETPOST('projectid','int')); $result=$object->setProject(GETPOST('projectid','int'));
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
@ -383,15 +378,12 @@ else if ($action == 'classin' && $user->rights->ficheinter->creer)
// Set into a contract // Set into a contract
else if ($action == 'setcontrat' && $user->rights->contrat->creer) else if ($action == 'setcontrat' && $user->rights->contrat->creer)
{ {
$object->fetch($id);
$result=$object->set_contrat($user,GETPOST('contratid','int')); $result=$object->set_contrat($user,GETPOST('contratid','int'));
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer) else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer)
{ {
$object->fetch($id);
$object->fetch_thirdparty();
$result=$object->delete($user); $result=$object->delete($user);
if ($result<0) { if ($result<0) {
setEventMessage($object->error,'errors'); setEventMessage($object->error,'errors');
@ -403,19 +395,16 @@ else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fich
else if ($action == 'setdescription' && $user->rights->ficheinter->creer) else if ($action == 'setdescription' && $user->rights->ficheinter->creer)
{ {
$object->fetch($id);
$result=$object->set_description($user,GETPOST('description')); $result=$object->set_description($user,GETPOST('description'));
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
else if ($action == 'setnote_public' && $user->rights->ficheinter->creer) else if ($action == 'setnote_public' && $user->rights->ficheinter->creer)
{ {
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public'); $result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public');
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
else if ($action == 'setnote_private' && $user->rights->ficheinter->creer) else if ($action == 'setnote_private' && $user->rights->ficheinter->creer)
{ {
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES), '_private'); $result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES), '_private');
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
@ -433,13 +422,15 @@ else if ($action == "addline" && $user->rights->ficheinter->creer)
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Duration")).'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Duration")).'</div>';
$error++; $error++;
} }
if (GETPOST('durationhour','int') >= 24 && GETPOST('durationmin','int') > 0)
{
$mesg='<div class="error">'.$langs->trans("ErrorValueTooHigh").'</div>';
$error++;
}
if (! $error) if (! $error)
{ {
$db->begin(); $db->begin();
$ret=$object->fetch($id);
$object->fetch_thirdparty();
$desc=GETPOST('np_desc'); $desc=GETPOST('np_desc');
$date_intervention = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int')); $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')); $duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int'));
@ -482,7 +473,6 @@ else if ($action == "addline" && $user->rights->ficheinter->creer)
// Classify Billed // Classify Billed
else if ($action == 'classifybilled' && $user->rights->ficheinter->creer) else if ($action == 'classifybilled' && $user->rights->ficheinter->creer)
{ {
$object->fetch($id);
$result=$object->setBilled(); $result=$object->setBilled();
if ($result > 0) if ($result > 0)
{ {
@ -582,8 +572,6 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->
else if ($action == 'up' && $user->rights->ficheinter->creer) else if ($action == 'up' && $user->rights->ficheinter->creer)
{ {
$object->fetch($id);
$object->fetch_thirdparty();
$object->line_up(GETPOST('line_id','int')); $object->line_up(GETPOST('line_id','int'));
// Define output language // Define output language
@ -603,8 +591,6 @@ else if ($action == 'up' && $user->rights->ficheinter->creer)
else if ($action == 'down' && $user->rights->ficheinter->creer) else if ($action == 'down' && $user->rights->ficheinter->creer)
{ {
$object->fetch($id);
$object->fetch_thirdparty();
$object->line_down(GETPOST('line_id','int')); $object->line_down(GETPOST('line_id','int'));
// Define output language // Define output language
@ -661,10 +647,6 @@ if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MA
{ {
$langs->load('mails'); $langs->load('mails');
if ($object->fetch($id) > 0)
{
$object->fetch_thirdparty();
if (GETPOST('sendto','alpha')) if (GETPOST('sendto','alpha'))
{ {
// Le destinataire a ete fourni via le champ libre // Le destinataire a ete fourni via le champ libre
@ -788,32 +770,25 @@ if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MA
$mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>'; $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
dol_syslog('Recipient email is empty'); dol_syslog('Recipient email is empty');
} }
}
else
{
$langs->load("other");
$mesg='<div class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Intervention")).'</div>';
dol_syslog('Impossible de lire les donnees de l\'intervention. Le fichier intervention n\'a peut-etre pas ete genere.');
}
$action='presend'; $action='presend';
} }
else if ($action == 'update_extras') else if ($action == 'update_extras')
{ {
$object->fetch($id);
// Fill array 'array_options' with data from update form // Fill array 'array_options' with data from update form
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
if ($ret < 0) $error++;
if (! $error)
{
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !! // FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('interventiondao')); $hookmanager->initHooks(array('interventiondao'));
$parameters=array('id'=>$object->id); $parameters=array('id'=>$object->id);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook)) if (empty($reshook))
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{ {
$result=$object->insertExtraFields(); $result=$object->insertExtraFields();
if ($result < 0) if ($result < 0)
@ -821,16 +796,16 @@ else if ($action == 'update_extras')
$error++; $error++;
} }
} }
}
else if ($reshook < 0) $error++; else if ($reshook < 0) $error++;
} }
if ($error) $action = 'edit_extras';
}
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer) if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer)
{ {
if ($action == 'addcontact') if ($action == 'addcontact')
{ {
$result = $object->fetch($id);
if ($result > 0 && $id > 0) if ($result > 0 && $id > 0)
{ {
$contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int')); $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
@ -858,21 +833,13 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheint
// bascule du statut d'un contact // bascule du statut d'un contact
else if ($action == 'swapstatut') else if ($action == 'swapstatut')
{
if ($object->fetch($id))
{ {
$result=$object->swapContactStatus(GETPOST('ligne','int')); $result=$object->swapContactStatus(GETPOST('ligne','int'));
} }
else
{
dol_print_error($db);
}
}
// Efface un contact // Efface un contact
else if ($action == 'deletecontact') else if ($action == 'deletecontact')
{ {
$object->fetch($id);
$result = $object->delete_contact(GETPOST('lineid','int')); $result = $object->delete_contact(GETPOST('lineid','int'));
if ($result >= 0) if ($result >= 0)
@ -1285,19 +1252,11 @@ else if ($id > 0 || ! empty($ref))
// Statut // Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>'; print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
// Other attributes // Other attributes (TODO Move this into an include)
$parameters=array('colspan' => ' colspan="3"'); $parameters=array('colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label)) if (empty($reshook) && ! empty($extrafields->attribute_label))
{ {
if ($action == 'edit_extras')
{
print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formfichinter">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
}
foreach($extrafields->attribute_label as $key=>$label) foreach($extrafields->attribute_label as $key=>$label)
{ {
if ($action == 'edit_extras') { if ($action == 'edit_extras') {
@ -1319,35 +1278,27 @@ else if ($id > 0 || ! empty($ref))
{ {
$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]); $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->ficheinter->creer) if ($action == 'edit_extras' && $user->rights->ficheinter->creer && GETPOST('attribute') == $key)
{ {
print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formfichinter">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="attribute" value="'.$key.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print $extrafields->showInputField($key,$value); print $extrafields->showInputField($key,$value);
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
} }
else else
{ {
print $extrafields->showOutputField($key,$value); print $extrafields->showOutputField($key,$value);
if ($object->statut == 0 && $user->rights->ficheinter->creer) print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras&attribute='.$key.'">'.img_picto('','edit').' '.$langs->trans('Modify').'</a>';
} }
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
} }
if(count($extrafields->attribute_label) > 0) {
if ($action == 'edit_extras' && $user->rights->ficheinter->creer)
{
print '<tr><td></td><td colspan="3">';
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
print '</td></tr>';
}
else {
if ($object->statut == 0 && $user->rights->ficheinter->creer)
{
print '<tr><td></td><td><a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras">'.img_picto('','edit').' '.$langs->trans('Modify').'</a></td></tr>';
}
}
}
} }
print "</table><br>"; print "</table><br>";

View File

@ -1005,6 +1005,7 @@ BrowserIsKO=You are using the web browser %s. This browser is known to be a bad
XDebugInstalled=XDebug est chargé. XDebugInstalled=XDebug est chargé.
XCacheInstalled=XCache is loaded. XCacheInstalled=XCache is loaded.
AddRefInList=Display customer/supplier ref into list (select list or combobox) and most of hyperlink AddRefInList=Display customer/supplier ref into list (select list or combobox) and most of hyperlink
FieldEdition=Edition of field %s
##### Module password generation ##### Module password generation
PasswordGenerationStandard=Return a password generated according to internal Dolibarr algorithm: 8 characters containing shared numbers and characters in lowercase. PasswordGenerationStandard=Return a password generated according to internal Dolibarr algorithm: 8 characters containing shared numbers and characters in lowercase.
PasswordGenerationNone=Do not suggest any generated password. Password must be type in manually. PasswordGenerationNone=Do not suggest any generated password. Password must be type in manually.

View File

@ -118,7 +118,6 @@ LastMembers=Last %s members
LastMembersModified=Last %s modified members LastMembersModified=Last %s modified members
LastSubscriptionsModified=Last %s modified subscriptions LastSubscriptionsModified=Last %s modified subscriptions
AttributeName=Attribute name AttributeName=Attribute name
FieldEdition=Edition of field %s
String=String String=String
Text=Text Text=Text
Int=Int Int=Int

View File

@ -1017,6 +1017,7 @@ EncryptedPasswordInDatabase=Permettre le chiffrement des mots de passe dans la b
DisableForgetPasswordLinkOnLogonPage=Ne pas afficher le lien "Mot de passe oublié" sur la page de connexion DisableForgetPasswordLinkOnLogonPage=Ne pas afficher le lien "Mot de passe oublié" sur la page de connexion
UsersSetup=Configuration du module utilisateurs UsersSetup=Configuration du module utilisateurs
UserMailRequired=Email requis pour créer un nouvel utilisateur UserMailRequired=Email requis pour créer un nouvel utilisateur
FieldEdition=Édition du champ %s
##### Company setup ##### ##### Company setup #####
CompanySetup=Configuration du module Tiers CompanySetup=Configuration du module Tiers
CompanyCodeChecker=Modèle de génération et contrôle des codes tiers (clients/fournisseurs) CompanyCodeChecker=Modèle de génération et contrôle des codes tiers (clients/fournisseurs)

View File

@ -118,7 +118,6 @@ LastMembers=Les %s derniers adhérents
LastMembersModified=Les %s derniers adhérents modifiés LastMembersModified=Les %s derniers adhérents modifiés
LastSubscriptionsModified=Les %s dernières adhésions modifiées LastSubscriptionsModified=Les %s dernières adhésions modifiées
AttributeName=Nom de l'attribut AttributeName=Nom de l'attribut
FieldEdition=Édition du champ %s
String=Chaîne String=Chaîne
Text=Texte long Text=Texte long
Int=Numérique Int=Numérique