Skip to content

Commit

Permalink
Fix: use hooks for extrafields
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Aug 9, 2011
1 parent 673556b commit a384105
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 18 deletions.
62 changes: 60 additions & 2 deletions htdocs/core/class/commonobject.class.php
Expand Up @@ -21,7 +21,7 @@
* \file htdocs/core/class/commonobject.class.php
* \ingroup core
* \brief File of parent class of all other business classes (invoices, contracts, proposals, orders, ...)
* \version $Id: commonobject.class.php,v 1.148 2011/07/31 23:45:14 eldy Exp $
* \version $Id: commonobject.class.php,v 1.149 2011/08/09 09:13:09 hregis Exp $
*/


Expand Down Expand Up @@ -1987,7 +1987,65 @@ function printOriginLine($line,$var)
include(DOL_DOCUMENT_ROOT.'/core/tpl/originproductline.tpl.php');
}


/**
*
*/
function showInputFields($object,$post='',$socid=0)
{
global $conf;

require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");

$extrafields = new ExtraFields($this->db);

$elementtype = $object->element;
if ($object->element = 'societe') $elementtype = 'company';

$extralabels=$extrafields->fetch_name_optionals_label($elementtype);

if ($socid)
{
$res=$object->fetch_optionals($socid,$extralabels);
if ($res < 0) { dol_print_error($db); exit; }
}

foreach($extrafields->attribute_label as $key=>$label)
{
$value=(isset($post["options_$key"])?$post["options_$key"]:($socid?$object->array_options["options_$key"]:''));
print "<tr><td>".$label.'</td><td colspan="3">';
print $extrafields->showInputField($key,$value);
print '</td></tr>'."\n";
}
}

/**
*
*/
function showOutputFields($object,$socid)
{
global $conf;

require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");

$extrafields = new ExtraFields($this->db);

$elementtype = $object->element;
if ($object->element = 'societe') $elementtype = 'company';

$extralabels=$extrafields->fetch_name_optionals_label($elementtype);

$res=$object->fetch_optionals($socid,$extralabels);
if ($res < 0) { dol_print_error($db); exit; }

foreach($extrafields->attribute_label as $key=>$label)
{
$value=$object->array_options["options_$key"];
print "<tr><td>".$label.'</td><td colspan="3">';
print $extrafields->showOutputField($key,$value);
print "</td></tr>\n";
}
}

/**
* Add/Update extra fields
* TODO Use also type of field to do manage date fields
Expand Down
7 changes: 3 additions & 4 deletions htdocs/includes/modules/modSociete.class.php
Expand Up @@ -22,7 +22,7 @@
/**
* \defgroup societe Module societe
* \brief Module to manage third parties (customers, prospects)
* \version $Id: modSociete.class.php,v 1.119 2011/07/31 23:28:10 eldy Exp $
* \version $Id: modSociete.class.php,v 1.120 2011/08/09 09:13:09 hregis Exp $
*/

/**
Expand Down Expand Up @@ -106,15 +106,14 @@ function modSociete($DB)
$this->const[$r][4] = 0;
$r++;

/* Disabled (no hook by default). A module that wants to hook thirdparty or contact actions must add its own constant MAIN_MODULE_MYMODULE_HOOKS=thirdpartycard:contactcard)
$this->const[$r][0] = "MAIN_MODULE_SOCIETE_HOOKS";
$this->const[$r][1] = "chaine";
$this->const[$r][2] = "thirdpartycard:contactcard";
$this->const[$r][2] = "extrafields";
$this->const[$r][3] = "";
$this->const[$r][4] = 0;
$this->const[$r][4] = 'current';
$this->const[$r][4] = 1;
$r++; */
$r++;

// Boxes
$this->boxes = array();
Expand Down
37 changes: 37 additions & 0 deletions htdocs/societe/class/actions_societe.class.php
@@ -0,0 +1,37 @@
<?php
/* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* \file htdocs/societe/class/actions_societe.class.php
* \ingroup societe
* \brief File for third party class
* \version $Id: actions_societe.class.php,v 1.1 2011/08/09 09:13:08 hregis Exp $
*/
require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");


/**
* \class ActionsSociete
* \brief Class to manage third parties objects (customers, suppliers, prospects...)
*/
class ActionsSociete extends Societe
{

}


?>
84 changes: 72 additions & 12 deletions htdocs/societe/soc.php
Expand Up @@ -25,7 +25,7 @@
* \file htdocs/societe/soc.php
* \ingroup societe
* \brief Third party card page
* \version $Id: soc.php,v 1.126 2011/08/01 00:38:49 eldy Exp $
* \version $Id: soc.php,v 1.127 2011/08/09 09:13:09 hregis Exp $
*/

require("../main.inc.php");
Expand All @@ -35,7 +35,7 @@
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formadmin.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");
//require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");
require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
if ($conf->adherent->enabled) require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");

Expand All @@ -52,7 +52,7 @@
$confirm = GETPOST('confirm');

$object = new Societe($db);
$extrafields = new ExtraFields($db);
//$extrafields = new ExtraFields($db);

// Security check
$socid = GETPOST("socid");
Expand All @@ -78,7 +78,7 @@
// Instantiate hooks of thirdparty module. Note that conf->hooks_modules contains array array
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
$object->callHooks('thirdpartycard');
$object->callHooks(array('thirdpartycard','extrafields'));
}


Expand Down Expand Up @@ -502,7 +502,7 @@
*/

// fetch optionals attributes and labels
$extralabels=$extrafields->fetch_name_optionals_label('company');
//$extralabels=$extrafields->fetch_name_optionals_label('company');

$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('',$langs->trans("ThirdParty"),$help_url);
Expand Down Expand Up @@ -1025,13 +1025,33 @@
}

// Other attributes
/*
foreach($extrafields->attribute_label as $key=>$label)
{
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:'');
print "<tr><td>".$label.'</td><td colspan="3">';
print $extrafields->showInputField($key,$value);
print '</td></tr>'."\n";
}
*/

// Hook for external modules
if (! empty($object->hooks))
{
foreach($object->hooks as $hook)
{
if (! empty($hook['modules']))
{
foreach($hook['modules'] as $module)
{
if (method_exists($module,'showInputFields'))
{
$module->showInputFields($object,$_POST);
}
}
}
}
}

// Ajout du logo
print '<tr>';
Expand All @@ -1057,11 +1077,11 @@

if ($socid)
{
$object = new Societe($db);
//$object = new Societe($db);
$res=$object->fetch($socid);
if ($res < 0) { dol_print_error($db,$object->error); exit; }
$res=$object->fetch_optionals($socid,$extralabels);
if ($res < 0) { dol_print_error($db); exit; }
//$res=$object->fetch_optionals($socid,$extralabels);
//if ($res < 0) { dol_print_error($db); exit; }

// Load object modCodeTiers
$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
Expand Down Expand Up @@ -1448,13 +1468,33 @@
}

// Other attributes
/*
foreach($extrafields->attribute_label as $key=>$label)
{
$value=(isset($_POST["options_$key"])?$_POST["options_$key"]:$object->array_options["options_$key"]);
print "<tr><td>".$label."</td><td colspan=\"3\">";
print $extrafields->showInputField($key,$value);
print "</td></tr>\n";
}
*/

// Hook for external modules
if (! empty($object->hooks))
{
foreach($object->hooks as $hook)
{
if (! empty($hook['modules']))
{
foreach($hook['modules'] as $module)
{
if (method_exists($module,'showInputFields'))
{
$module->showInputFields($object,$_POST,$socid);
}
}
}
}
}

// Logo
print '<tr>';
Expand Down Expand Up @@ -1491,11 +1531,11 @@
/*
* View
*/
$object = new Societe($db);
//$object = new Societe($db);
$res=$object->fetch($socid);
if ($res < 0) { dol_print_error($db,$object->error); exit; }
$res=$object->fetch_optionals($socid,$extralabels);
if ($res < 0) { dol_print_error($db); exit; }
//$res=$object->fetch_optionals($socid,$extralabels);
//if ($res < 0) { dol_print_error($db); exit; }


$head = societe_prepare_head($object);
Expand Down Expand Up @@ -1784,13 +1824,33 @@
}

// Other attributes
/*
foreach($extrafields->attribute_label as $key=>$label)
{
$value=$object->array_options["options_$key"];
print "<tr><td>".$label.'</td><td colspan="3">';
print $extrafields->showOutputField($key,$value);
print "</td></tr>\n";
}
*/

// Hook for external modules
if (! empty($object->hooks))
{
foreach($object->hooks as $hook)
{
if (! empty($hook['modules']))
{
foreach($hook['modules'] as $module)
{
if (method_exists($module,'showOutputFields'))
{
$module->showOutputFields($object,$socid);
}
}
}
}
}

// Ban
if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT))
Expand Down Expand Up @@ -1969,5 +2029,5 @@

$db->close();

llxFooter('$Date: 2011/08/01 00:38:49 $ - $Revision: 1.126 $');
llxFooter('$Date: 2011/08/09 09:13:09 $ - $Revision: 1.127 $');
?>

0 comments on commit a384105

Please sign in to comment.