Merge pull request #790 from jfefe/extrafields
Work on task #784 : display calendar into data type extrafields
This commit is contained in:
commit
3c248ce1fe
@ -81,6 +81,9 @@ $result = restrictedArea($user, 'propal', $id);
|
|||||||
$object = new Propal($db);
|
$object = new Propal($db);
|
||||||
$extrafields = new ExtraFields($db);
|
$extrafields = new ExtraFields($db);
|
||||||
|
|
||||||
|
// fetch optionals attributes and labels
|
||||||
|
$extralabels=$extrafields->fetch_name_optionals_label('propal');
|
||||||
|
|
||||||
// Load object
|
// Load object
|
||||||
if ($id > 0 || ! empty($ref))
|
if ($id > 0 || ! empty($ref))
|
||||||
{
|
{
|
||||||
@ -338,15 +341,9 @@ else if ($action == 'add' && $user->rights->propal->creer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get extra fields
|
// Fill array 'array_options' with data from add form
|
||||||
foreach($_POST as $key => $value)
|
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||||
{
|
|
||||||
if (preg_match("/^options_/",$key))
|
|
||||||
{
|
|
||||||
$object->array_options[$key]=GETPOST($key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$id = $object->create($user);
|
$id = $object->create($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1107,14 +1104,10 @@ else if ($action == 'down' && $user->rights->propal->creer)
|
|||||||
}
|
}
|
||||||
else if ($action == 'update_extras')
|
else if ($action == 'update_extras')
|
||||||
{
|
{
|
||||||
// Get extra fields
|
// Fill array 'array_options' with data from update form
|
||||||
foreach($_POST as $key => $value)
|
$extralabels=$extrafields->fetch_name_optionals_label('propal');
|
||||||
{
|
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||||
if (preg_match("/^options_/",$key))
|
|
||||||
{
|
|
||||||
$object->array_options[$key]=$_POST[$key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 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'));
|
||||||
@ -1208,9 +1201,6 @@ $formfile = new FormFile($db);
|
|||||||
$formpropal = new FormPropal($db);
|
$formpropal = new FormPropal($db);
|
||||||
$companystatic=new Societe($db);
|
$companystatic=new Societe($db);
|
||||||
|
|
||||||
// fetch optionals attributes and labels
|
|
||||||
$extralabels=$extrafields->fetch_name_optionals_label('propal');
|
|
||||||
|
|
||||||
$now=dol_now();
|
$now=dol_now();
|
||||||
|
|
||||||
// Add new proposal
|
// Add new proposal
|
||||||
@ -1872,6 +1862,13 @@ else
|
|||||||
print '<tr><td';
|
print '<tr><td';
|
||||||
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
|
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
|
||||||
print '>'.$label.'</td><td colspan="3">';
|
print '>'.$label.'</td><td colspan="3">';
|
||||||
|
|
||||||
|
// 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"]):$object->array_options['options_'.$key];
|
||||||
|
}
|
||||||
|
|
||||||
if ($action == 'edit_extras' && $user->rights->propal->creer)
|
if ($action == 'edit_extras' && $user->rights->propal->creer)
|
||||||
{
|
{
|
||||||
print $extrafields->showInputField($key,$value);
|
print $extrafields->showInputField($key,$value);
|
||||||
|
|||||||
@ -1738,14 +1738,10 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture-
|
|||||||
|
|
||||||
if ($action == 'update_extras')
|
if ($action == 'update_extras')
|
||||||
{
|
{
|
||||||
// Get extra fields
|
// Fill array 'array_options' with data from add form
|
||||||
foreach($_POST as $key => $value)
|
$extralabels=$extrafields->fetch_name_optionals_label('facture');
|
||||||
{
|
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||||
if (preg_match("/^options_/",$key))
|
|
||||||
{
|
|
||||||
$object->array_options[$key]=$_POST[$key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 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'));
|
||||||
@ -3125,7 +3121,6 @@ else if ($id > 0 || ! empty($ref))
|
|||||||
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach($extrafields->attribute_label as $key=>$label)
|
foreach($extrafields->attribute_label as $key=>$label)
|
||||||
{
|
{
|
||||||
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
|
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
|
||||||
@ -3138,6 +3133,12 @@ else if ($id > 0 || ! empty($ref))
|
|||||||
print '<tr><td';
|
print '<tr><td';
|
||||||
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
|
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
|
||||||
print '>'.$label.'</td><td colspan="5">';
|
print '>'.$label.'</td><td colspan="5">';
|
||||||
|
// 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"]):$object->array_options['options_'.$key];
|
||||||
|
}
|
||||||
|
|
||||||
if ($action == 'edit_extras' && $user->rights->facture->creer)
|
if ($action == 'edit_extras' && $user->rights->facture->creer)
|
||||||
{
|
{
|
||||||
print $extrafields->showInputField($key,$value);
|
print $extrafields->showInputField($key,$value);
|
||||||
|
|||||||
@ -2132,15 +2132,19 @@ abstract class CommonObject
|
|||||||
case 'price':
|
case 'price':
|
||||||
$this->array_options[$key] = price2num($this->array_options[$key]);
|
$this->array_options[$key] = price2num($this->array_options[$key]);
|
||||||
break;
|
break;
|
||||||
|
case 'date':
|
||||||
|
$this->array_options[$key] = dol_print_date($this->array_options[$key],'dayrfc');
|
||||||
|
break;
|
||||||
|
case 'datetime':
|
||||||
|
$this->array_options[$key] = dol_print_date($this->array_options[$key],'dayhourrfc');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id;
|
$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);
|
dol_syslog(get_class($this)."::insertExtraFields delete sql=".$sql_del);
|
||||||
$this->db->query($sql_del);
|
$this->db->query($sql_del);
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."_extrafields (fk_object";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."_extrafields (fk_object";
|
||||||
foreach($this->array_options as $key => $value)
|
foreach($this->array_options as $key => $value)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -582,7 +582,7 @@ class ExtraFields
|
|||||||
* Return HTML string to put an input field into a page
|
* Return HTML string to put an input field into a page
|
||||||
*
|
*
|
||||||
* @param string $key Key of attribute
|
* @param string $key Key of attribute
|
||||||
* @param string $value Value to show
|
* @param string $value Value to show (for date type it must be in timestamp format)
|
||||||
* @param string $moreparam To add more parametes on html input tag
|
* @param string $moreparam To add more parametes on html input tag
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -619,7 +619,13 @@ class ExtraFields
|
|||||||
{
|
{
|
||||||
$tmp=explode(',',$size);
|
$tmp=explode(',',$size);
|
||||||
$newsize=$tmp[0];
|
$newsize=$tmp[0];
|
||||||
$out='<input type="text" name="options_'.$key.'" size="'.$showsize.'" maxlength="'.$newsize.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
|
if(!class_exists('Form'))
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
||||||
|
$formstat = new Form($db);
|
||||||
|
|
||||||
|
$showtime = in_array($type,array('datetime')) ? 1 : 0;
|
||||||
|
$out = $formstat->select_date($value, 'options_'.$key, $showtime, $showtime, $required, '', 1, 1, 0, 0, 1);
|
||||||
|
//$out='<input type="text" name="options_'.$key.'" size="'.$showsize.'" maxlength="'.$newsize.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
|
||||||
}
|
}
|
||||||
elseif (in_array($type,array('int','double')))
|
elseif (in_array($type,array('int','double')))
|
||||||
{
|
{
|
||||||
@ -670,9 +676,10 @@ class ExtraFields
|
|||||||
}
|
}
|
||||||
$out.='</select>';
|
$out.='</select>';
|
||||||
}
|
}
|
||||||
// Add comments
|
/* Add comments
|
||||||
if ($type == 'date') $out.=' (YYYY-MM-DD)';
|
if ($type == 'date') $out.=' (YYYY-MM-DD)';
|
||||||
elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)';
|
elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)';
|
||||||
|
*/
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -698,10 +705,12 @@ class ExtraFields
|
|||||||
if ($type == 'date')
|
if ($type == 'date')
|
||||||
{
|
{
|
||||||
$showsize=10;
|
$showsize=10;
|
||||||
|
$value=dol_print_date($value,'day');
|
||||||
}
|
}
|
||||||
elseif ($type == 'datetime')
|
elseif ($type == 'datetime')
|
||||||
{
|
{
|
||||||
$showsize=19;
|
$showsize=19;
|
||||||
|
$value=dol_print_date($value,'dayhour');
|
||||||
}
|
}
|
||||||
elseif ($type == 'int')
|
elseif ($type == 'int')
|
||||||
{
|
{
|
||||||
@ -752,5 +761,42 @@ class ExtraFields
|
|||||||
$out = '<tr class="liste_titre"><td colspan="4"><strong>'.$this->attribute_label[$key].'</strong></td></tr>';
|
$out = '<tr class="liste_titre"><td colspan="4"><strong>'.$this->attribute_label[$key].'</strong></td></tr>';
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill array_options array for object by extrafields value (using for data send by forms)
|
||||||
|
*
|
||||||
|
* @param array $extralabels $array of extrafields
|
||||||
|
* @param object $object object
|
||||||
|
* @return int 1 if array_options set / 0 if no value
|
||||||
|
*/
|
||||||
|
function setOptionalsFromPost($extralabels,&$object)
|
||||||
|
{
|
||||||
|
global $_POST;
|
||||||
|
|
||||||
|
if (is_array($extralabels))
|
||||||
|
{
|
||||||
|
// Get extra fields
|
||||||
|
foreach ($extralabels as $key => $value)
|
||||||
|
{
|
||||||
|
$key_type = $this->attribute_type[$key];
|
||||||
|
|
||||||
|
if (in_array($key_type,array('date','datetime')))
|
||||||
|
{
|
||||||
|
// Clean parameters
|
||||||
|
$value_key=dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$value_key=GETPOST("options_".$key);
|
||||||
|
}
|
||||||
|
$object->array_options["options_".$key]=$value_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -55,6 +55,9 @@ if ($user->societe_id) $socid=$user->societe_id;
|
|||||||
$object = new Societe($db);
|
$object = new Societe($db);
|
||||||
$extrafields = new ExtraFields($db);
|
$extrafields = new ExtraFields($db);
|
||||||
|
|
||||||
|
// fetch optionals attributes and labels
|
||||||
|
$extralabels=$extrafields->fetch_name_optionals_label('company');
|
||||||
|
|
||||||
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
|
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
|
||||||
$object->getCanvas($socid);
|
$object->getCanvas($socid);
|
||||||
$canvas = $object->canvas?$object->canvas:GETPOST("canvas");
|
$canvas = $object->canvas?$object->canvas:GETPOST("canvas");
|
||||||
@ -166,15 +169,9 @@ if (empty($reshook))
|
|||||||
$object->commercial_id = GETPOST('commercial_id');
|
$object->commercial_id = GETPOST('commercial_id');
|
||||||
$object->default_lang = GETPOST('default_lang');
|
$object->default_lang = GETPOST('default_lang');
|
||||||
|
|
||||||
// Get extra fields
|
// Fill array 'array_options' with data from add form
|
||||||
foreach($_POST as $key => $value)
|
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||||
{
|
|
||||||
if (preg_match("/^options_/",$key))
|
|
||||||
{
|
|
||||||
$object->array_options[$key]=GETPOST($key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GETPOST('deletephoto')) $object->logo = '';
|
if (GETPOST('deletephoto')) $object->logo = '';
|
||||||
else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
|
else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
|
||||||
|
|
||||||
@ -508,9 +505,6 @@ if (empty($reshook))
|
|||||||
* View
|
* View
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// fetch optionals attributes and labels
|
|
||||||
$extralabels=$extrafields->fetch_name_optionals_label('company');
|
|
||||||
|
|
||||||
$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
|
$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
|
||||||
llxHeader('',$langs->trans("ThirdParty"),$help_url);
|
llxHeader('',$langs->trans("ThirdParty"),$help_url);
|
||||||
|
|
||||||
@ -1000,6 +994,13 @@ else
|
|||||||
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
|
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
|
||||||
print '>'.$label.'</td>';
|
print '>'.$label.'</td>';
|
||||||
print '<td colspan="'.$colspan.'">';
|
print '<td colspan="'.$colspan.'">';
|
||||||
|
|
||||||
|
// Convert date into timestamp format
|
||||||
|
if (in_array($extrafields->attribute_type[$key],array('date','datetime')))
|
||||||
|
{
|
||||||
|
$value = dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]);
|
||||||
|
}
|
||||||
|
|
||||||
print $extrafields->showInputField($key,$value);
|
print $extrafields->showInputField($key,$value);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user