18 include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
19 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
20 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
28 public $name =
'ThirdPartyAdvancedTargeting';
30 public $desc =
"Third parties";
31 public $require_admin = 0;
33 public $require_module = array(
"none");
38 public $picto =
'company';
45 public $enabled =
'isModEnabled("societe")';
74 dol_syslog(get_class($this).
"::add_to_target_spec socid=".var_export($socid,
true).
' contactid='.var_export($contactid,
true));
78 if (($type_of_target == 1) || ($type_of_target == 3)) {
80 if (count($socid) > 0) {
81 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact";
82 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"societe_extrafields se ON se.fk_object=s.rowid";
83 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
84 $sql .=
" AND s.rowid IN (".$this->db->sanitize(implode(
',', $socid)).
")";
85 $sql .=
" ORDER BY email";
88 $result = $this->
db->query($sql);
90 $num = $this->
db->num_rows($result);
93 dol_syslog(get_class($this).
"::add_to_target_spec mailing ".$num.
" targets found", LOG_DEBUG);
96 $obj = $this->
db->fetch_object($result);
98 if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
99 if (!array_key_exists($obj->email, $cibles)) {
100 $cibles[$obj->email] = array(
101 'email' => $obj->email,
102 'fk_contact' => $obj->fk_contact,
103 'name' => $obj->name,
104 'firstname' => $obj->firstname,
106 'source_url' => $this->url($obj->id,
'thirdparty'),
107 'source_id' => $obj->id,
108 'source_type' =>
'thirdparty'
117 $this->error = $this->
db->error();
123 if (($type_of_target == 1) || ($type_of_target == 2) || ($type_of_target == 4)) {
125 if (count($socid) > 0 || count($contactid) > 0) {
126 $sql =
"SELECT socp.rowid as id, socp.email as email, socp.lastname as lastname, socp.firstname as firstname";
127 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as socp";
128 $sql .=
" WHERE socp.entity IN (".getEntity(
'contact').
")";
129 if (count($contactid) > 0) {
130 $sql .=
" AND socp.rowid IN (".$this->db->sanitize(implode(
',', $contactid)).
")";
132 if (count($socid) > 0) {
133 $sql .=
" AND socp.fk_soc IN (".$this->db->sanitize(implode(
',', $socid)).
")";
135 $sql .=
" ORDER BY email";
138 $result = $this->
db->query($sql);
140 $num = $this->
db->num_rows($result);
143 dol_syslog(get_class($this).
"::add_to_target_spec mailing ".$num.
" targets found");
146 $obj = $this->
db->fetch_object($result);
148 if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
149 if (!array_key_exists($obj->email, $cibles)) {
150 $cibles[$obj->email] = array(
151 'email' => $obj->email,
152 'fk_contact' =>$obj->id,
153 'lastname' => $obj->lastname,
154 'firstname' => $obj->firstname,
156 'source_url' => $this->url($obj->id,
'contact'),
157 'source_id' => $obj->id,
158 'source_type' =>
'contact'
167 $this->error = $this->
db->error();
174 dol_syslog(get_class($this).
"::add_to_target_spec mailing cibles=".var_export($cibles,
true), LOG_DEBUG);
176 return parent::addTargetsToDatabase($mailing_id, $cibles);
210 $sql =
"SELECT count(distinct(s.email)) as nb";
211 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
212 $sql .=
" WHERE s.email != ''";
213 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
216 return parent::getNbOfRecipients($sql);
227 global $conf, $langs;
229 $langs->load(
"companies");
232 $s .=
'<select name="filter" class="flat">';
235 $sql =
"SELECT rowid, label, type, visible";
236 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
237 $sql .=
" WHERE type in (1,2)";
239 $sql .=
" AND entity = ".$conf->entity;
240 $sql .=
" ORDER BY label";
247 if (empty($conf->categorie->enabled)) {
252 $s .=
'<option value="0"> </option>';
254 $s .=
'<option value="0">'.$langs->trans(
"ContactsAllShort").
'</option>';
259 $obj = $this->
db->fetch_object(
$resql);
262 if ($obj->type == 1) {
263 $type = $langs->trans(
"Supplier");
265 if ($obj->type == 2) {
266 $type = $langs->trans(
"Customer");
268 $s .=
'<option value="'.$obj->rowid.
'">'.
dol_trunc($obj->label, 38,
'middle');
270 $s .=
' ('.$type.
')';
291 public function url($id, $type)
293 if ($type ==
'thirdparty') {
295 $companystatic->fetch($id);
296 return $companystatic->getNomUrl(0,
'', 0, 1);
297 } elseif ($type ==
'contact') {
299 $contactstatic->fetch($id);
300 return $contactstatic->getNomUrl(0,
'', 0,
'', -1, 1);
Parent class of emailing target selectors modules.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage a list of personalised recipients for mailing feature.
url($id, $type)
Can include an URL link on each record provided by selector shown on target page.
formFilter()
This is to add a form filter to provide variant of selector If used, the HTML select must be called "...
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
add_to_target_spec($mailing_id, $socid, $type_of_target, $contactid)
This is the main function that returns the array of emails.
__construct($db)
Constructor.
getNbOfRecipients($sql='')
Return here number of distinct emails returned by your selector.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.