Implement extrafields : calendar on date type and new separator type

This commit is contained in:
jfefe 2013-03-30 16:58:49 +01:00
parent 95d8ee8b41
commit bd4e62a5e7

View File

@ -56,6 +56,9 @@ if (! empty($user->societe_id)) $socid=$user->societe_id;
$object = new Product($db); $object = new Product($db);
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
// fetch optionals attributes and labels
$extralabels=$extrafields->fetch_name_optionals_label('product');
if ($id > 0 || ! empty($ref)) if ($id > 0 || ! empty($ref))
{ {
$object = new Product($db); $object = new Product($db);
@ -212,14 +215,8 @@ if (empty($reshook))
} }
} }
// 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]=$_POST[$key];
}
}
$id = $object->create($user); $id = $object->create($user);
@ -272,14 +269,8 @@ if (empty($reshook))
$object->finished = GETPOST('finished'); $object->finished = GETPOST('finished');
$object->hidden = GETPOST('hidden')=='yes'?1:0; $object->hidden = GETPOST('hidden')=='yes'?1:0;
// 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]=$_POST[$key];
}
}
if ($object->check()) if ($object->check())
{ {
@ -632,9 +623,6 @@ if (GETPOST("cancel") == $langs->trans("Cancel"))
* View * View
*/ */
// fetch optionals attributes and labels
$extralabels=$extrafields->fetch_name_optionals_label('product');
$helpurl=''; $helpurl='';
if (GETPOST("type") == '0') $helpurl='EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; if (GETPOST("type") == '0') $helpurl='EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
if (GETPOST("type") == '1') $helpurl='EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; if (GETPOST("type") == '1') $helpurl='EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
@ -794,7 +782,20 @@ else
{ {
foreach($extrafields->attribute_label as $key=>$label) foreach($extrafields->attribute_label as $key=>$label)
{ {
$value=(GETPOST('options_'.$key)?GETPOST('options_'.$key):$object->array_options["options_".$key]); $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
// Show separator only
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
// 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];
}
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">';
@ -802,6 +803,7 @@ else
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
} }
}
// Note (private, no output on invoices, propales...) // Note (private, no output on invoices, propales...)
print '<tr><td valign="top">'.$langs->trans("NoteNotVisibleOnBill").'</td><td>'; print '<tr><td valign="top">'.$langs->trans("NoteNotVisibleOnBill").'</td><td>';
@ -1002,6 +1004,19 @@ else
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]);
// Show separator only
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
// 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];
}
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">';
@ -1009,6 +1024,7 @@ else
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
} }
}
// Note // Note
print '<tr><td valign="top">'.$langs->trans("NoteNotVisibleOnBill").'</td><td colspan="2">'; print '<tr><td valign="top">'.$langs->trans("NoteNotVisibleOnBill").'</td><td colspan="2">';
@ -1233,12 +1249,25 @@ else
{ {
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]);
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
// 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];
}
print '<tr><td>'.$label.'</td><td colspan="3">'; print '<tr><td>'.$label.'</td><td colspan="3">';
print $extrafields->showOutputField($key,$value); print $extrafields->showOutputField($key,$value);
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
} }
}
// Note // Note
print '<tr><td valign="top">'.$langs->trans("Note").'</td><td colspan="'.(2+(($showphoto||$showbarcode)?1:0)).'">'.(dol_textishtml($object->note)?$object->note:dol_nl2br($object->note,1,true)).'</td></tr>'; print '<tr><td valign="top">'.$langs->trans("Note").'</td><td colspan="'.(2+(($showphoto||$showbarcode)?1:0)).'">'.(dol_textishtml($object->note)?$object->note:dol_nl2br($object->note,1,true)).'</td></tr>';