Skip to content

Commit

Permalink
Merge pull request #751 from jfefe/extrasep
Browse files Browse the repository at this point in the history
New type of extrafield : separator
  • Loading branch information
eldy committed Mar 16, 2013
2 parents ca0d3be + 9a57431 commit 2da3fb6
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 109 deletions.
51 changes: 33 additions & 18 deletions htdocs/comm/propal.php
Expand Up @@ -1360,11 +1360,20 @@
foreach($extrafields->attribute_label as $key=>$label)
{
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
print $extrafields->showInputField($key,$value);
print '</td></tr>'."\n";

// Show separator only
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
print $extrafields->showInputField($key,$value);
print '</td></tr>'."\n";
}
}
}

Expand Down Expand Up @@ -1854,19 +1863,25 @@
foreach($extrafields->attribute_label as $key=>$label)
{
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
if ($action == 'edit_extras' && $user->rights->propal->creer)
{
print $extrafields->showInputField($key,$value);
}
else
{
print $extrafields->showOutputField($key,$value);
}

print '</td></tr>'."\n";
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
if ($action == 'edit_extras' && $user->rights->propal->creer)
{
print $extrafields->showInputField($key,$value);
}
else
{
print $extrafields->showOutputField($key,$value);
}
print '</td></tr>'."\n";
}
}

if(count($extrafields->attribute_label) > 0) {
Expand Down
44 changes: 29 additions & 15 deletions htdocs/compta/facture.php
Expand Up @@ -2101,11 +2101,19 @@
foreach($extrafields->attribute_label as $key=>$label)
{
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
print $extrafields->showInputField($key,$value);
print '</td></tr>'."\n";
// Show separator only
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
print $extrafields->showInputField($key,$value);
print '</td></tr>'."\n";
}
}
}

Expand Down Expand Up @@ -3090,24 +3098,30 @@
foreach($extrafields->attribute_label as $key=>$label)
{
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="5">';
if ($action == 'edit_extras' && $user->rights->propal->creer)
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showInputField($key,$value);
print $extrafields->showSeparator($key);
}
else
{
print $extrafields->showOutputField($key,$value);
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="5">';
if ($action == 'edit_extras' && $user->rights->facture->creer)
{
print $extrafields->showInputField($key,$value);
}
else
{
print $extrafields->showOutputField($key,$value);
}
print '</td></tr>'."\n";
}

print '</td></tr>'."\n";
}

if(count($extrafields->attribute_label) > 0) {

if ($action == 'edit_extras' && $user->rights->propal->creer)
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').'">';
Expand All @@ -3116,7 +3130,7 @@

}
else {
if ($object->statut == 0 && $user->rights->propal->creer)
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>';
}
Expand Down
47 changes: 34 additions & 13 deletions htdocs/contact/fiche.php
Expand Up @@ -521,11 +521,18 @@
foreach($extrafields->attribute_label as $key=>$label)
{
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($object->array_options["options_".$key])?$object->array_options["options_".$key]:''));
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
print $extrafields->showInputField($key,$value);
print '</td></tr>'."\n";
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
print $extrafields->showInputField($key,$value);
print '</td></tr>'."\n";
}
}
}

Expand Down Expand Up @@ -736,11 +743,18 @@
foreach($extrafields->attribute_label as $key=>$label)
{
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
print $extrafields->showInputField($key,$value);
print "</td></tr>\n";
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
print $extrafields->showInputField($key,$value);
print "</td></tr>\n";
}
}
}

Expand Down Expand Up @@ -948,9 +962,16 @@
foreach($extrafields->attribute_label as $key=>$label)
{
$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">';
print $extrafields->showOutputField($key,$value);
print "</td></tr>\n";
if ($extrafields->attribute_type[$key] == 'separate')
{
print $extrafields->showSeparator($key);
}
else
{
print '<tr><td>'.$label.'</td><td colspan="3">';
print $extrafields->showOutputField($key,$value);
print "</td></tr>\n";
}
}
}

Expand Down
24 changes: 15 additions & 9 deletions htdocs/core/class/commonobject.class.php
Expand Up @@ -2138,21 +2138,27 @@ function insertExtraFields()
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."_extrafields (fk_object";
foreach($this->array_options as $key => $value)
{
$attributeKey = substr($key,8); // Remove 'options_' prefix
// Add field of attribut
$sql.=",".substr($key,8); // Remove 'options_' prefix
if ($extrafields->attribute_type[$attributeKey] != 'separate') // Only for other type of separate
$sql.=",".$attributeKey;
}
$sql .= ") VALUES (".$this->id;
foreach($this->array_options as $key => $value)
{
$attributeKey = substr($key,8); // Remove 'options_' prefix
// Add field o fattribut
if ($this->array_options[$key] != '')
{
$sql.=",'".$this->array_options[$key]."'";
}
else
{
$sql.=",null";
}
if($extrafields->attribute_type[$attributeKey] != 'separate') // Only for other type of separate)
{
if ($this->array_options[$key] != '')
{
$sql.=",'".$this->array_options[$key]."'";
}
else
{
$sql.=",null";
}
}
}
$sql.=")";

Expand Down
40 changes: 31 additions & 9 deletions htdocs/core/class/extrafields.class.php
Expand Up @@ -63,7 +63,8 @@ class ExtraFields
'price'=>'ExtrafieldPrice',
'phone'=>'ExtrafieldPhone',
'mail'=>'ExtrafieldMail',
'select' => 'ExtrafieldSelect'
'select' => 'ExtrafieldSelect',
'separate' => 'ExtrafieldSeparator'
);

/**
Expand Down Expand Up @@ -102,11 +103,13 @@ function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $uni
if (empty($attrname)) return -1;
if (empty($label)) return -1;


// Create field into database
$result=$this->create($attrname,$type,$size,$elementtype, $unique, $required, $default_value,$param);
// Create field into database except for separator type which is not stored in database
if ($type != 'separate')
{
$result=$this->create($attrname,$type,$size,$elementtype, $unique, $required, $default_value,$param);
}
$err1=$this->errno;
if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS')
if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate')
{
// Add declaration of field into table
$result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype, $unique, $required, $param);
Expand Down Expand Up @@ -354,7 +357,6 @@ private function delete_label($attrname, $elementtype='member')
function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos,$param='')
{
$table=$elementtype.'_extrafields';

// Special case for not normalized table names
if ($elementtype == 'member') $table='adherent_extrafields';
elseif ($elementtype == 'company') $table='societe_extrafields';
Expand Down Expand Up @@ -382,8 +384,12 @@ function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=
$lengthdb=$length;
}
$field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL'));
$result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc);
if ($result > 0)

if ($type != 'separate') // No table update when separate type
{
$result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc);
}
if ($result > 0 || $type == 'separate')
{
if ($label)
{
Expand Down Expand Up @@ -546,8 +552,13 @@ function fetch_name_optionals_label($elementtype='member',$forceload=false)
{
while ($tab = $this->db->fetch_object($resql))
{

// we can add this attribute to adherent object
$array_name_label[$tab->name]=$tab->label;
if ($tab->type != 'separate')
{
$array_name_label[$tab->name]=$tab->label;
}

$this->attribute_type[$tab->name]=$tab->type;
$this->attribute_label[$tab->name]=$tab->label;
$this->attribute_size[$tab->name]=$tab->size;
Expand Down Expand Up @@ -730,5 +741,16 @@ function showOutputField($key,$value,$moreparam='')
return $out;
}

/**
* Return HTML string to print separator extrafield
*
* @param string $key Key of attribute
* @return string
*/
function showSeparator($key)
{
$out = '<tr class="liste_titre"><td colspan="4"><strong>'.$this->attribute_label[$key].'</strong></td></tr>';
return $out;
}
}
?>
22 changes: 15 additions & 7 deletions htdocs/core/tpl/admin_extrafields_add.tpl.php
Expand Up @@ -25,11 +25,18 @@ function init_typeoffields(type)
var size = jQuery("#size");
var unique = jQuery("#unique");
var required = jQuery("#required");
var default_value = jQuery("#default_value");
<?php
if(!GETPOST('type') == "select")
if(GETPOST('type') != "select")
{
print 'jQuery("#value_choice").hide();';
}

if (GETPOST('type') == "separate")
{
print "jQuery('#size, #unique, #required, #default_value').val('').attr('disabled','disabled');";
print 'jQuery("#value_choice").hide();';
}
?>

if (type == 'date') { size.val('').attr('disabled','disabled'); unique.removeAttr('disabled','disabled'); jQuery("#value_choice").hide(); }
Expand All @@ -41,6 +48,7 @@ function init_typeoffields(type)
else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").hide();}
else if (type == 'price') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").hide();}
else if (type == 'select') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();}
else if (type == 'separate') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); required.val('').attr('disabled','disabled'); default_value.val('').attr('disabled','disabled'); jQuery("#value_choice").hide();}
else size.val('').attr('disabled','disabled');
}
init_typeoffields('');
Expand All @@ -55,16 +63,16 @@ function init_typeoffields(type)
<input type="hidden" name="action" value="add">

<table summary="listofattributes" class="border centpercent">
<!-- Type -->
<tr><td class="fieldrequired"><?php echo $langs->trans("Type"); ?></td><td class="valeur">
<?php print $form->selectarray('type',$type2label,GETPOST('type')); ?>
</td></tr>
<!-- Position -->
<tr><td class="fieldrequired"><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo GETPOST('pos'); ?>"></td></tr>
<!-- Label -->
<tr><td class="fieldrequired"><?php echo $langs->trans("Label"); ?></td><td class="valeur"><input type="text" name="label" size="40" value="<?php echo GETPOST('label'); ?>"></td></tr>
<!-- Code -->
<tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?> (<?php echo $langs->trans("AlphaNumOnlyCharsAndNoSpace"); ?>)</td><td class="valeur"><input type="text" name="attrname" size="10" value="<?php echo GETPOST('attrname'); ?>"></td></tr>
<!-- Type -->
<tr><td class="fieldrequired"><?php echo $langs->trans("Type"); ?></td><td class="valeur">
<?php print $form->selectarray('type',$type2label,GETPOST('type')); ?>
</td></tr>
<tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?> (<?php echo $langs->trans("AlphaNumOnlyCharsAndNoSpace"); ?>)</td><td class="valeur"><input type="text" name="attrname" id="attrname" size="10" value="<?php echo GETPOST('attrname'); ?>"></td></tr>
<!-- Value (for select list / radio) -->
<tr id="value_choice">
<td>
Expand All @@ -75,7 +83,7 @@ function init_typeoffields(type)
</td>
</tr>
<!-- Default Value -->
<tr><td><?php echo $langs->trans("DefaultValue"); ?></td><td class="valeur"><input id="default_value" type="text" name=""default_value"" size="5" value="<?php echo (GETPOST('"default_value"')?GETPOST('"default_value"'):''); ?>"></td></tr>
<tr><td><?php echo $langs->trans("DefaultValue"); ?></td><td class="valeur"><input id="default_value" type="text" name="default_value" size="5" value="<?php echo (GETPOST('"default_value"')?GETPOST('"default_value"'):''); ?>"></td></tr>
<!-- Size -->
<tr><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td class="valeur"><input id="size" type="text" name="size" size="5" value="<?php echo (GETPOST('size')?GETPOST('size'):''); ?>"></td></tr>
<!-- Unique -->
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/fr_FR/admin.lang
Expand Up @@ -354,6 +354,7 @@ ExtrafieldPhone = Téléphone
ExtrafieldPrice = Prix
ExtrafieldMail = Email
ExtrafieldSelect = Liste de sélection
ExtrafieldSeparator = Séparateur de champ
LibraryToBuildPDF=Bibliothèque utilisée pour la génération des PDF
WarningUsingFPDF=Attention: Votre fichier <b>conf.php</b> contient la directive <b>dolibarr_pdf_force_fpdf=1</b>. Cela signifie que vous utilisez la librairie FPDF pour générer vos fichiers PDF. Cette librairie est ancienne et ne couvre pas de nombreuses fonctionnalitée (Unicode, transparence des images, langues cyrillic, arabes ou asiatiques...), aussi vous pouvez rencontrez des problèmes durant la génération des PDF.<br>Pour résoudre cela et avoir un support complet de PDF, vous pouvez télécharger la <a href="http://www.tcpdf.org/" target="_blank">librairie TCPDF</a> puis commenter ou supprimer la ligne <b>$dolibarr_pdf_force_fpdf=1</b>, et ajouter à la place <b>$dolibarr_lib_TCPDF_PATH='chemin_vers_TCPDF'</b>
LocalTaxDesc=Certains pays appliquent 2 voir 3 taux sur chaque ligne de facture. Si c'est le cas, choisissez le type du deuxième et troisième taux et sa valeur. Les types possibles sont:<br>1 : taxe locale sur les produits et services hors tva (la tva n'est pas appliquée sur la taxe locale)<br>2 : taxe locale sur les produits et services avant tva (la tva est appliquée sur le montant + la taxe locale)<br>3 : taxe locale uniquement sur les produits hors tva (la tva n'est pas appliquée sur la taxe locale)<br>4 : taxe locale uniquement sur les produits avant tva (la tva est appliquée sur le montant + la taxe locale)<br>5 : taxe locale uniquement sur les services hors tva (la tva n'est pas appliquée sur la taxe locale)<br>6 : taxe locale uniquement sur les service avant tva (la tva est appliquée sur le montant + la taxe locale)
Expand Down

0 comments on commit 2da3fb6

Please sign in to comment.