20include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
21include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
22include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
33 public $name =
'ThirdPartyAdvancedTargeting';
38 public $desc =
"Third parties";
43 public $require_admin = 0;
48 public $require_module = array(
"none");
53 public $picto =
'company';
58 public $enabled =
'isModEnabled("societe")';
89 if (($type_of_target == 1) || ($type_of_target == 3)) {
91 if (count($socid) > 0) {
92 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact";
93 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s LEFT JOIN ".MAIN_DB_PREFIX.
"societe_extrafields se ON se.fk_object=s.rowid";
94 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
95 $sql .=
" AND s.rowid IN (".$this->db->sanitize(implode(
',', $socid)).
")";
97 $sql .=
" ORDER BY email";
100 $result = $this->db->query($sql);
102 $num = $this->db->num_rows($result);
105 dol_syslog(get_class($this).
"::add_to_target_spec mailing ".$num.
" targets found", LOG_DEBUG);
108 $obj = $this->db->fetch_object($result);
110 if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
111 if (!array_key_exists($obj->email, $cibles)) {
112 $cibles[$obj->email] = array(
113 'email' => $obj->email,
114 'fk_contact' => (
int) $obj->fk_contact,
115 'name' => $obj->name,
116 'firstname' => $obj->firstname,
118 'source_url' => $this->url($obj->id,
'thirdparty'),
119 'source_id' => (
int) $obj->id,
120 'source_type' =>
'thirdparty'
129 $this->error = $this->db->error();
135 if (($type_of_target == 1) || ($type_of_target == 2) || ($type_of_target == 4)) {
137 if (count($socid) > 0 || count($contactid) > 0) {
138 $sql =
"SELECT socp.rowid as id, socp.email as email, socp.lastname as lastname, socp.firstname as firstname";
139 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as socp";
140 $sql .=
" WHERE socp.entity IN (".getEntity(
'contact').
")";
141 if (count($contactid) > 0) {
142 $sql .=
" AND socp.rowid IN (".$this->db->sanitize(implode(
',', $contactid)).
")";
144 if (count($socid) > 0) {
145 $sql .=
" AND socp.fk_soc IN (".$this->db->sanitize(implode(
',', $socid)).
")";
148 $sql .=
" ORDER BY email";
151 $result = $this->db->query($sql);
153 $num = $this->db->num_rows($result);
156 dol_syslog(get_class($this).
"::add_to_target_spec mailing ".$num.
" targets found");
159 $obj = $this->db->fetch_object($result);
161 if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
162 if (!array_key_exists($obj->email, $cibles)) {
163 $cibles[$obj->email] = array(
164 'email' => $obj->email,
165 'fk_contact' => (
int) $obj->id,
166 'lastname' => $obj->lastname,
167 'firstname' => $obj->firstname,
169 'source_url' => $this->url($obj->id,
'contact'),
170 'source_id' => (
int) $obj->id,
171 'source_type' =>
'contact'
180 $this->error = $this->db->error();
188 return parent::addTargetsToDatabase($mailing_id, $cibles);
220 $sql =
"SELECT count(distinct(s.email)) as nb";
221 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
222 $sql .=
" WHERE s.email != ''";
223 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
227 return parent::getNbOfRecipients($sql);
238 global
$conf, $langs;
240 $langs->load(
"companies");
243 $s .=
'<select name="filter" class="flat">';
246 $sql =
"SELECT rowid, label, type, visible";
247 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
248 $sql .=
" WHERE type in (1,2)";
250 $sql .=
" AND entity = ".((int)
$conf->entity);
251 $sql .=
" ORDER BY label";
254 $resql = $this->db->query($sql);
256 $num = $this->db->num_rows($resql);
263 $s .=
'<option value="0"> </option>';
265 $s .=
'<option value="0">'.$langs->trans(
"ContactsAllShort").
'</option>';
270 $obj = $this->db->fetch_object($resql);
273 if ($obj->type == 1) {
274 $type = $langs->trans(
"Supplier");
276 if ($obj->type == 2) {
277 $type = $langs->trans(
"Customer");
279 $s .=
'<option value="'.$obj->rowid.
'">'.
dol_trunc($obj->label, 38,
'middle');
281 $s .=
' ('.$type.
')';
305 if ($type ==
'thirdparty') {
306 $companystatic =
new Societe($this->db);
307 $companystatic->fetch(
$id);
308 $s = $companystatic->getNomUrl(0,
'nolink', 32, 1, 0);
309 } elseif ($type ==
'contact') {
310 $contactstatic =
new Contact($this->db);
311 $contactstatic->fetch(
$id);
312 $s = $contactstatic->getNomUrl(0,
'nolink', 1,
'', 0, 32);
317 if (strlen($s) > 255) {
$id
Support class for third parties, contacts, members, users or resources.
Parent class of emailing target selectors modules.
getSqlToExcludeUnsubscribed($emailfield)
Return the SQL fragment that excludes email addresses which opted out of emailings for the current en...
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(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) formatLogObject($data)
Return a string serialized to be output on log with dol_syslog() An option allow to output log in one...
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...