add trigger files
This commit is contained in:
parent
d811de4da2
commit
6c20fbafdf
@ -1051,7 +1051,7 @@ else
|
||||
if (!empty($object->socid)) {
|
||||
print '<tr><td>' . $langs->trans("Role") . '</td>';
|
||||
print '<td colspan="3">';
|
||||
print $form->showRoles("roles", $object, 'edit' ,$object->roles);
|
||||
print $formcompany->showRoles("roles", $object, 'edit' ,$object->roles);
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
@ -1256,7 +1256,7 @@ else
|
||||
if (!empty($object->socid)) {
|
||||
print '<tr><td class="titlefield">' . $langs->trans("Roles") . '</td>';
|
||||
print '<td colspan="3">';
|
||||
print $form->showRoles("roles", $object, 'view');
|
||||
print $formcompany->showRoles("roles", $object, 'view');
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
|
||||
@ -1525,6 +1525,49 @@ class Contact extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Contact roles for a thirdparty
|
||||
*
|
||||
* @param string $element element type
|
||||
* @return array|int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getContactRoles($element = '')
|
||||
{
|
||||
$tab=array();
|
||||
|
||||
$sql = "SELECT sc.fk_socpeople as id, sc.fk_c_type_contact";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."societe_contacts sc";
|
||||
$sql.= " WHERE sc.fk_soc =".$this->socid;
|
||||
$sql.= " AND sc.fk_c_type_contact=tc.rowid";
|
||||
$sql.= " AND tc.element='".$element."'";
|
||||
$sql.= " AND tc.active=1";
|
||||
|
||||
dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num=$this->db->num_rows($resql);
|
||||
$i=0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$tab[]=array('fk_socpeople'=>$obj->id, 'type_contact'=>$obj->fk_c_type_contact);
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $tab;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates Roles
|
||||
*
|
||||
|
||||
@ -36,6 +36,7 @@ require '../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
|
||||
|
||||
// Load translation files required by the page
|
||||
$langs->loadLangs(array("companies", "suppliers", "categories"));
|
||||
@ -264,6 +265,7 @@ if ($search_priv < 0) $search_priv='';
|
||||
|
||||
$form=new Form($db);
|
||||
$formother=new FormOther($db);
|
||||
$formcompany=new FormCompany($db);
|
||||
$contactstatic=new Contact($db);
|
||||
|
||||
$title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
|
||||
@ -518,7 +520,7 @@ if (! empty($conf->categorie->enabled))
|
||||
}
|
||||
$moreforfilter.='<div class="divsearchfield">';
|
||||
$moreforfilter.=$langs->trans('Roles'). ': ';
|
||||
$moreforfilter.=$form->showRoles("search_roles", $objecttmp, 'edit', $search_roles);
|
||||
$moreforfilter.=$formcompany->showRoles("search_roles", $objecttmp, 'edit', $search_roles);
|
||||
$moreforfilter.='</div>';
|
||||
}
|
||||
if ($moreforfilter)
|
||||
|
||||
@ -1224,9 +1224,10 @@ abstract class CommonObject
|
||||
public function listeTypeContacts($source = 'internal', $option = 0, $activeonly = 0, $code = '', $element = '')
|
||||
{
|
||||
// phpcs:enable
|
||||
global $langs;
|
||||
global $langs, $conf;
|
||||
|
||||
$tab = array();
|
||||
|
||||
$sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position, tc.element";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
|
||||
|
||||
@ -1251,27 +1252,36 @@ abstract class CommonObject
|
||||
|
||||
dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num=$this->db->num_rows($resql);
|
||||
$i=0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$libelle_element = $langs->trans('ContactDefault_'.$obj->element);
|
||||
$transkey="TypeContact_".$this->element."_".$source."_".$obj->code;
|
||||
$libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle);
|
||||
if (empty($option)) $tab[$obj->rowid]=$libelle_element.' - '.$libelle_type;
|
||||
else $tab[$obj->rowid]=$libelle_element.' - '.$libelle_type;
|
||||
$i++;
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
if ($num > 0) {
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
if (strpos($obj->element, 'project')!==false) {
|
||||
$element='projet';
|
||||
} elseif($obj->element=='contrat') {
|
||||
$element='contract';
|
||||
} elseif(strpos($obj->element, 'supplier')!==false && $obj->element!='supplier_proposal') {
|
||||
$element='fournisseur';
|
||||
} elseif(strpos($obj->element, 'supplier')!==false && $obj->element!='supplier_proposal') {
|
||||
$element='fournisseur';
|
||||
} else {
|
||||
$element=$obj->element;
|
||||
}
|
||||
if ($conf->{$element}->enabled) {
|
||||
$libelle_element = $langs->trans('ContactDefault_' . $obj->element);
|
||||
$transkey = "TypeContact_" . $this->element . "_" . $source . "_" . $obj->code;
|
||||
$libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle);
|
||||
if (empty($option))
|
||||
$tab[$obj->rowid] = $libelle_element . ' - ' . $libelle_type;
|
||||
else $tab[$obj->rowid] = $libelle_element . ' - ' . $libelle_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tab;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
//dol_print_error($this->db);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6484,47 +6484,6 @@ class Form
|
||||
return 'ErrorBadValueForParameterRenderMode'; // Should not happened
|
||||
}
|
||||
|
||||
/**
|
||||
* showContactRoles on view and edit mode
|
||||
*
|
||||
* @param string $htmlname Html component name and id
|
||||
* @param Contact $contact Contact Obejct
|
||||
* @param string $rendermode view, edit
|
||||
* @param array $selected $key=>$val $val is selected Roles for input mode
|
||||
* @return string String with contacts roles
|
||||
*/
|
||||
public function showRoles($htmlname = '', Contact $contact, $rendermode = 'view', $selected = array())
|
||||
{
|
||||
if ($rendermode === 'view') {
|
||||
$toprint = array();
|
||||
foreach ($contact->roles as $key => $val) {
|
||||
$toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa;">' . $val['label'] . '</li>';
|
||||
}
|
||||
return '<div class="select2-container-multi-dolibarr" style="width: 90%;" id="'.$htmlname.'"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
|
||||
}
|
||||
|
||||
if ($rendermode === 'edit')
|
||||
{
|
||||
$contactType=$contact->listeTypeContacts('external', '', 1);
|
||||
|
||||
if (count($selected)>0) {
|
||||
$newselected=array();
|
||||
foreach($selected as $key=>$val) {
|
||||
if (is_array($val) && array_key_exists('id', $val) && in_array($val['id'], array_keys($contactType))) {
|
||||
$newselected[]=$val['id'];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (count($newselected)>0) $selected=$newselected;
|
||||
}
|
||||
return $this->multiselectarray($htmlname, $contactType, $selected);
|
||||
}
|
||||
|
||||
return 'ErrorBadValueForParameterRenderMode'; // Should not happened
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show linked object block.
|
||||
*
|
||||
|
||||
@ -29,28 +29,11 @@
|
||||
* Class to build HTML component for third parties management
|
||||
* Only common components are here.
|
||||
*/
|
||||
class FormCompany
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
||||
|
||||
class FormCompany extends Form
|
||||
{
|
||||
/**
|
||||
* @var DoliDB Database handler.
|
||||
*/
|
||||
public $db;
|
||||
|
||||
/**
|
||||
* @var string Error code (or message)
|
||||
*/
|
||||
public $error='';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
@ -763,6 +746,45 @@ class FormCompany
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* showContactRoles on view and edit mode
|
||||
*
|
||||
* @param string $htmlname Html component name and id
|
||||
* @param Contact $contact Contact Obejct
|
||||
* @param string $rendermode view, edit
|
||||
* @param array $selected $key=>$val $val is selected Roles for input mode
|
||||
* @return string String with contacts roles
|
||||
*/
|
||||
public function showRoles($htmlname = '', Contact $contact, $rendermode = 'view', $selected = array())
|
||||
{
|
||||
if ($rendermode === 'view') {
|
||||
$toprint = array();
|
||||
foreach ($contact->roles as $key => $val) {
|
||||
$toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa;">' . $val['label'] . '</li>';
|
||||
}
|
||||
return '<div class="select2-container-multi-dolibarr" style="width: 90%;" id="'.$htmlname.'"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
|
||||
}
|
||||
|
||||
if ($rendermode === 'edit')
|
||||
{
|
||||
$contactType=$contact->listeTypeContacts('external', '', 1);
|
||||
if (count($selected)>0) {
|
||||
$newselected=array();
|
||||
foreach($selected as $key=>$val) {
|
||||
if (is_array($val) && array_key_exists('id', $val) && in_array($val['id'], array_keys($contactType))) {
|
||||
$newselected[]=$val['id'];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (count($newselected)>0) $selected=$newselected;
|
||||
}
|
||||
return $this->multiselectarray($htmlname, $contactType, $selected);
|
||||
}
|
||||
|
||||
return 'ErrorBadValueForParameterRenderMode'; // Should not happened
|
||||
}
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Return a select list with zip codes and their town
|
||||
|
||||
@ -859,6 +859,8 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
global $user,$conf,$extrafields,$hookmanager;
|
||||
global $contextpage;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
|
||||
$formcompany = new FormCompany($db);
|
||||
$form = new Form($db);
|
||||
|
||||
$optioncss = GETPOST('optioncss', 'alpha');
|
||||
@ -1017,7 +1019,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
if (in_array($key, array('lastname','name'))) print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
|
||||
elseif (in_array($key, array('statut'))) print $form->selectarray('search_status', array('-1'=>'','0'=>$contactstatic->LibStatut(0, 1),'1'=>$contactstatic->LibStatut(1, 1)), $search_status);
|
||||
elseif (in_array($key, array('role'))) {
|
||||
print $form->showRoles("search_roles", $contactstatic, 'edit', $search_roles);
|
||||
print $formcompany->showRoles("search_roles", $contactstatic, 'edit', $search_roles);
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
@ -1152,7 +1154,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
if (! empty($arrayfields['sc.role']['checked']))
|
||||
{
|
||||
print '<td>';
|
||||
print $form->showRoles("roles", $contactstatic, 'view');
|
||||
print $formcompany->showRoles("roles", $contactstatic, 'view');
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2013 Cedric GROSS <c.gross@kreiz-it.fr>
|
||||
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
|
||||
* Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
|
||||
*
|
||||
* 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 3 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/core/triggers/interface_50_modAgenda_ActionsAuto.class.php
|
||||
* \ingroup agenda
|
||||
* \brief Trigger file for agenda module
|
||||
*/
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
|
||||
|
||||
|
||||
/**
|
||||
* Class of triggered functions for agenda module
|
||||
*/
|
||||
class InterfaceContactRoles extends DolibarrTriggers
|
||||
{
|
||||
public $family = 'agenda';
|
||||
public $description = "Triggers of this module add actions in agenda according to setup made in agenda setup.";
|
||||
|
||||
/**
|
||||
* Version of the trigger
|
||||
* @var string
|
||||
*/
|
||||
public $version = self::VERSION_DOLIBARR;
|
||||
|
||||
/**
|
||||
* @var string Image of the trigger
|
||||
*/
|
||||
public $picto = 'action';
|
||||
|
||||
/**
|
||||
* Function called when a Dolibarrr business event is done.
|
||||
* All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
|
||||
*
|
||||
* Following properties may be set before calling trigger. The may be completed by this trigger to be used for writing the event into database:
|
||||
* $object->actiontypecode (translation action code: AC_OTH, ...)
|
||||
* $object->actionmsg (note, long text)
|
||||
* $object->actionmsg2 (label, short text)
|
||||
* $object->sendtoid (id of contact or array of ids)
|
||||
* $object->socid (id of thirdparty)
|
||||
* $object->fk_project
|
||||
* $object->fk_element
|
||||
* $object->elementtype
|
||||
*
|
||||
* @param string $action Event action code
|
||||
* @param Object $object Object
|
||||
* @param User $user Object user
|
||||
* @param Translate $langs Object langs
|
||||
* @param conf $conf Object conf
|
||||
* @return int <0 if KO, 0 if no triggered ran, >0 if OK
|
||||
*/
|
||||
public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
|
||||
{
|
||||
// Lors de la création d'un document, récupération des contacts et rôle associés à la société et association avec le document
|
||||
if ($action === 'PROPAL_CREATE' || $action === 'ORDER_CREATE' || $action === 'BILL_CREATE' || $action === 'ORDER_SUPPLIER_CREATE' || $action === 'BILL_SUPPLIER_CREATE'
|
||||
|| $action === 'CONTRACT_CREATE' || $action === 'FICHINTER_CREATE' || $action === 'PROJECT_CREATE' || $action === 'TICKET_CREATE' || $action === 'ACTION_CREATE') {
|
||||
|
||||
if(!empty($object->socid) && $object->socid != '-1') {
|
||||
global $db, $langs;
|
||||
|
||||
$contactdefault = new Contact($this->db);
|
||||
$contactdefault->socid=$object->socid;
|
||||
$TContact = $contactdefault->getContactRoles();
|
||||
|
||||
// Le trigger est appelé avant que le core n'ajoute lui-même des contacts (contact propale, clone), il ne faut pas les associer avant sinon bug
|
||||
$TContactAlreadyLinked = array();
|
||||
if ($object->id > 0)
|
||||
{
|
||||
$class = get_class($object);
|
||||
$cloneFrom = new $class($db);
|
||||
$r = $cloneFrom->fetch($object->id);
|
||||
|
||||
if (!empty($cloneFrom->id)) $TContactAlreadyLinked = array_merge($cloneFrom->liste_contact(-1,'external'), $cloneFrom->liste_contact(-1,'internal'));
|
||||
}
|
||||
|
||||
foreach($TContact as $i => $infos) {
|
||||
// Gestion du cas du clone
|
||||
foreach ($TContactAlreadyLinked as $contactData) {
|
||||
if($contactData['id'] == $infos['fk_socpeople'] && $contactData['fk_c_type_contact'] == $infos['type_contact']) unset($TContact[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$nb = 0;
|
||||
foreach($TContact as $infos) {
|
||||
// Gestion du cas spécifique de la création de propale avec sélection du contact, cela créé un bug si le contact est ajouté par le module contactdefault
|
||||
$res = $object->add_contact($infos['fk_socpeople'], $infos['type_contact']);
|
||||
if($res > 0) $nb++;
|
||||
}
|
||||
|
||||
if($nb > 0) {
|
||||
setEventMessage($langs->trans('ContactAddedAutomatically', $nb));
|
||||
}
|
||||
}
|
||||
|
||||
dol_syslog(
|
||||
"Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user