Merge pull request #663 from jfefe/extrafields

Work on extrafields
This commit is contained in:
Laurent Destailleur 2013-02-18 05:17:06 -08:00
commit 70ea5b0b1d
4 changed files with 87 additions and 12 deletions

View File

@ -134,7 +134,7 @@ abstract class CommonDocGenerator
$object->state=getState($object->state_code,0);
}
return array(
$array_thirdparty = array(
'company_name'=>$object->name,
'company_email'=>$object->email,
'company_phone'=>$object->phone,
@ -163,6 +163,25 @@ abstract class CommonDocGenerator
'company_idprof6'=>$object->idprof6,
'company_note'=>$object->note
);
// Retrieve extrafields
if(is_array($object->array_options) && count($object->array_options))
{
if(!class_exists('Extrafields'))
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);
$extralabels = $extrafields->fetch_name_optionals_label('company',true);
foreach($extrafields->attribute_label as $key=>$label)
{
if($extrafields->attribute_type[$key] == 'price')
{
$object->array_options['options_'.$key] = price($object->array_options['options_'.$key]).' '.$outputlangs->getCurrencySymbol($conf->currency);
}
$array_thirdparty=array_merge($array_thirdparty,array('company_options_'.$key => $object->array_options['options_'.$key]));
}
}
return $array_thirdparty;
}
/**

View File

@ -44,6 +44,10 @@ class ExtraFields
var $attribute_unique;
// Array to store if attribute is required or not
var $attribute_required;
// Array to store parameters of attribute (used in select type)
var $attribute_param;
// Int to store position of attribute
var $attribute_pos;
var $error;
var $errno;
@ -669,7 +673,7 @@ class ExtraFields
*/
function showOutputField($key,$value,$moreparam='')
{
global $conf;
global $conf,$langs;
$label=$this->attribute_label[$key];
$type=$this->attribute_type[$key];

View File

@ -139,6 +139,8 @@ class Societe extends CommonObject
var $logo;
var $logo_small;
var $logo_mini;
var $array_options;
var $oldcopy;
@ -852,6 +854,19 @@ class Societe extends CommonObject
$this->import_key = $obj->import_key;
$result = 1;
// 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('company',true);
if (count($extralabels)>0) {
$this->array_options = array();
}
foreach($extrafields->attribute_label as $key=>$label)
{
$this->array_options['options_'.$key]=$label;
}
}
else
{

View File

@ -998,14 +998,25 @@ else
$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))
{
$e=0;
foreach($extrafields->attribute_label as $key=>$label)
{
$colspan='3';
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($object->array_options["options_".$key])?$object->array_options["options_".$key]:''));
print '<tr><td';
if (($e % 2) == 0)
{
print '<tr>';
$colspan='0';
}
print '<td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
print '>'.$label.'</td>';
print '<td colspan="'.$colspan.'">';
print $extrafields->showInputField($key,$value);
print '</td></tr>'."\n";
print '</td>';
if (($e % 2) == 1) print '</tr>'."\n";
$e++;
}
}
@ -1426,23 +1437,38 @@ else
print '</td>';
print '</tr>';
}
// Other attributes
$parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
$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))
{
$old_pos=0;
$e=0;
foreach($extrafields->attribute_label as $key=>$label)
{
$colspan = '3';
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
print '<tr><td';
if (($e % 2) == 0)
{
print '<tr>'."\n";
$colspan = '0';
}
print '<td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
print '>'.$label.'</td>'."\n";
print '<td colspan="'.$colspan.'">';
print $extrafields->showInputField($key,$value);
print "</td></tr>\n";
print "</td>"."\n";
if (($e % 2) == 1 )
{
print "</tr>\n";
}
$old_pos = $extrafields->attribute_pos[$key];
$e++;
}
}
// Logo
print '<tr>';
print '<td>'.$langs->trans("Logo").'</td>';
@ -1756,12 +1782,23 @@ else
$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))
{
$e=0;
foreach($extrafields->attribute_label as $key=>$label)
{
$colspan='3';
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($object->array_options['options_'.$key])?$object->array_options['options_'.$key]:''));
print '<tr><td>'.$label.'</td><td colspan="3">';
if (($e % 2) == 0)
{
print '<tr>';
$colspan='0';
}
print '<td>'.$label.'</td>';
print '<td colspan="'.$colspan.'">';
print $extrafields->showOutputField($key,$value);
print "</td></tr>\n";
print "</td>";
if (($e % 2) == 1) print '</tr>';
$e++;
}
}