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';
72 dol_syslog(get_class($this).
"::add_to_target_spec socid=".var_export($socid,
true).
' contactid='.var_export($contactid,
true));
76 if (($type_of_target == 1) || ($type_of_target == 3)) {
78 if (count($socid) > 0)
80 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact";
81 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"societe_extrafields se ON se.fk_object=s.rowid";
82 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
83 $sql .=
" AND s.rowid IN (".implode(
',', $socid).
")";
84 $sql .=
" ORDER BY email";
87 $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);
97 $obj = $this->
db->fetch_object($result);
99 if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
100 if (!array_key_exists($obj->email, $cibles)) {
101 $cibles[$obj->email] = array(
102 'email' => $obj->email,
103 'fk_contact' => $obj->fk_contact,
104 'name' => $obj->name,
105 'firstname' => $obj->firstname,
107 'source_url' => $this->url($obj->id,
'thirdparty'),
108 'source_id' => $obj->id,
109 'source_type' =>
'thirdparty'
118 $this->error = $this->
db->error();
124 if (($type_of_target == 1) || ($type_of_target == 2) || ($type_of_target == 4)) {
126 if (count($socid) > 0 || count($contactid) > 0)
128 $sql =
"SELECT socp.rowid as id, socp.email as email, socp.lastname as lastname, socp.firstname as firstname";
129 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as socp";
130 $sql .=
" WHERE socp.entity IN (".getEntity(
'socpeople').
")";
131 if (count($contactid) > 0) {
132 $sql .=
" AND socp.rowid IN (".implode(
',', $contactid).
")";
134 if (count($socid) > 0) {
135 $sql .=
" AND socp.fk_soc IN (".implode(
',', $socid).
")";
137 $sql .=
" ORDER BY email";
140 $result = $this->
db->query($sql);
143 $num = $this->
db->num_rows($result);
146 dol_syslog(get_class($this).
"::add_to_target_spec mailing ".$num.
" targets found");
150 $obj = $this->
db->fetch_object($result);
152 if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
153 if (!array_key_exists($obj->email, $cibles)) {
154 $cibles[$obj->email] = array(
155 'email' => $obj->email,
156 'fk_contact' =>$obj->id,
157 'lastname' => $obj->lastname,
158 'firstname' => $obj->firstname,
160 'source_url' => $this->url($obj->id,
'contact'),
161 'source_id' => $obj->id,
162 'source_type' =>
'contact'
171 $this->error = $this->
db->error();
178 dol_syslog(get_class($this).
"::add_to_target_spec mailing cibles=".var_export($cibles,
true), LOG_DEBUG);
180 return parent::addTargetsToDatabase($mailing_id, $cibles);
214 $sql =
"SELECT count(distinct(s.email)) as nb";
215 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
216 $sql .=
" WHERE s.email != ''";
217 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
221 return parent::getNbOfRecipients($sql);
232 global $conf, $langs;
234 $langs->load(
"companies");
237 $s .=
'<select name="filter" class="flat">';
240 $sql =
"SELECT rowid, label, type, visible";
241 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
242 $sql .=
" WHERE type in (1,2)";
244 $sql .=
" AND entity = ".$conf->entity;
245 $sql .=
" ORDER BY label";
253 if (empty($conf->categorie->enabled)) $num = 0;
255 if ($num) $s .=
'<option value="0"> </option>';
256 else $s .=
'<option value="0">'.$langs->trans(
"ContactsAllShort").
'</option>';
261 $obj = $this->
db->fetch_object(
$resql);
264 if ($obj->type == 1) $type = $langs->trans(
"Supplier");
265 if ($obj->type == 2) $type = $langs->trans(
"Customer");
266 $s .=
'<option value="'.$obj->rowid.
'">'.
dol_trunc($obj->label, 38,
'middle');
267 if ($type) $s .=
' ('.$type.
')';
287 public function url($id, $type)
289 if ($type ==
'thirdparty') {
291 $companystatic->fetch($id);
292 return $companystatic->getNomUrl(0,
'', 0, 1);
293 } elseif ($type ==
'contact') {
295 $contactstatic->fetch($id);
296 return $contactstatic->getNomUrl(0,
'', 0,
'', -1, 1);
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
Class to manage a list of personalised recipients for mailing feature.
$conf db
API class for accounts.
url($id, $type)
Can include an URL link on each record provided by selector shown on target page. ...
__construct($db)
Constructor.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
add_to_target_spec($mailing_id, $socid, $type_of_target, $contactid)
This is the main function that returns the array of emails.
getNbOfRecipients($sql= '')
Return here number of distinct emails returned by your selector.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $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.
Parent class of emailing target selectors modules.
formFilter()
This is to add a form filter to provide variant of selector If used, the HTML select must be called "...