19include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
27 public $name =
'ThirdPartiesByCategories';
29 public $desc =
"Third parties (by categories)";
30 public $require_admin = 0;
32 public $require_module = array(
"societe");
34 public $enabled =
'isModEnabled("societe")';
39 public $picto =
'company';
50 $langs->load(
"companies");
72 if (GETPOSTISSET(
"filter_client_thirdparties") &&
GETPOST(
"filter_client_thirdparties") !=
'-1') {
73 $addFilter .=
" AND s.client=".((int)
GETPOST(
"filter_client_thirdparties",
'int'));
74 $addDescription = $langs->trans(
'ProspectCustomer').
"=";
75 if (
GETPOST(
"filter_client_thirdparties") == 0) {
76 $addDescription .= $langs->trans(
'NorProspectNorCustomer');
77 } elseif (
GETPOST(
"filter_client_thirdparties") == 1) {
78 $addDescription .= $langs->trans(
'Customer');
79 } elseif (
GETPOST(
"filter_client_thirdparties") == 2) {
80 $addDescription .= $langs->trans(
'Prospect');
81 } elseif (
GETPOST(
"filter_client_thirdparties") == 3) {
82 $addDescription .= $langs->trans(
'ProspectCustomer');
84 $addDescription .=
"Unknown status ".GETPOST(
"filter_client_thirdparties");
87 if (GETPOSTISSET(
"filter_supplier_thirdparties") &&
GETPOST(
"filter_supplier_thirdparties") !=
'-1') {
88 $addFilter .=
" AND s.fournisseur = ".((int)
GETPOST(
"filter_supplier_thirdparties",
'int'));
89 $addDescription = $langs->trans(
'Supplier').
"=";
90 if (
GETPOST(
"filter_supplier_thirdparties") == 0) {
91 $addDescription .= $langs->trans(
'No');
92 } elseif (
GETPOST(
"filter_supplier_thirdparties") == 1) {
93 $addDescription .= $langs->trans(
'Yes');
95 $addDescription .=
"Unknown status ".GETPOST(
"filter_supplier_thirdparties");
98 if (GETPOSTISSET(
"filter_status")) {
99 if (strlen($addDescription) > 0) {
100 $addDescription .=
";";
102 $addDescription .= $langs->trans(
"Status").
"=";
103 if (
GETPOST(
"filter_status") ==
'1') {
104 $addFilter .=
" AND s.status=1";
105 $addDescription .= $langs->trans(
"Enabled");
106 } elseif (
GETPOST(
"filter_status") ==
'0') {
107 $addFilter .=
" AND s.status=0";
108 $addDescription .= $langs->trans(
"Disabled");
111 if (GETPOSTISSET(
"filter_status")) {
112 if (strlen($addDescription) > 0) {
113 $addDescription .=
";";
115 $addDescription .= $langs->trans(
"Status").
"=";
116 if (
GETPOST(
"filter_status") ==
'1') {
117 $addFilter .=
" AND s.status=1";
118 $addDescription .= $langs->trans(
"Enabled");
119 } elseif (
GETPOST(
"filter_status") ==
'0') {
120 $addFilter .=
" AND s.status=0";
121 $addDescription .= $langs->trans(
"Disabled");
124 if (
GETPOST(
'default_lang',
'alpha') &&
GETPOST(
'default_lang',
'alpha') !=
'-1') {
125 $addFilter .=
" AND s.default_lang LIKE '".$this->db->escape(
GETPOST(
'default_lang',
'alpha')).
"%'";
126 $addDescription = $langs->trans(
'DefaultLang').
"=";
128 if (
GETPOST(
'filter_lang_thirdparties',
'alpha') &&
GETPOST(
'filter_lang_thirdparties',
'alpha') !=
'-1') {
129 $addFilter .=
" AND s.default_lang LIKE '".$this->db->escape(
GETPOST(
'filter_lang_thirdparties',
'alpha')).
"%'";
130 $addDescription = $langs->trans(
'DefaultLang').
"=";
134 if (!
GETPOST(
'filter_thirdparties') ||
GETPOST(
'filter_thirdparties') ==
'-1') {
135 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, null as label";
136 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
137 $sql .=
" WHERE s.email <> ''";
138 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
139 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
140 if (empty($this->evenunsubscribe)) {
141 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = s.email) = 0";
145 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label";
146 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_societe as cs, ".MAIN_DB_PREFIX.
"categorie as c";
147 $sql .=
" WHERE s.email <> ''";
148 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
149 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
150 $sql .=
" AND cs.fk_soc = s.rowid";
151 $sql .=
" AND c.rowid = cs.fk_categorie";
152 if (
GETPOST(
'filter_thirdparties',
'int') > 0) {
153 $sql .=
" AND c.rowid=".((int)
GETPOST(
'filter_thirdparties',
'int'));
155 if (empty($this->evenunsubscribe)) {
156 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = s.email) = 0";
160 $sql .=
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label";
161 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs, ".MAIN_DB_PREFIX.
"categorie as c";
162 $sql .=
" WHERE s.email <> ''";
163 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
164 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
165 $sql .=
" AND cs.fk_soc = s.rowid";
166 $sql .=
" AND c.rowid = cs.fk_categorie";
167 if (
GETPOST(
'filter_thirdparties',
'int') > 0) {
168 $sql .=
" AND c.rowid=".((int)
GETPOST(
'filter_thirdparties',
'int'));
170 if (empty($this->evenunsubscribe)) {
171 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = s.email) = 0";
175 $sql .=
" ORDER BY email";
180 $result = $this->db->query($sql);
182 $num = $this->db->num_rows($result);
186 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
190 $obj = $this->db->fetch_object($result);
191 if ($old != $obj->email) {
192 $otherTxt = ($obj->label ? $langs->transnoentities(
"Category").
'='.$obj->label :
'');
193 if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
196 $otherTxt .= $addDescription;
198 'email' => $obj->email,
199 'fk_contact' => $obj->fk_contact,
200 'lastname' => $obj->name,
202 'other' => $otherTxt,
203 'source_url' => $this->url($obj->id),
204 'source_id' => $obj->id,
205 'source_type' =>
'thirdparty'
215 $this->error = $this->db->error();
219 return parent::addTargetsToDatabase($mailing_id, $cibles);
253 $sql =
"SELECT count(distinct(s.email)) as nb";
254 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
255 $sql .=
" WHERE s.email <> ''";
256 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
257 if (empty($this->evenunsubscribe)) {
258 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).
")";
262 return parent::getNbOfRecipients($sql);
273 global $conf, $langs;
275 $langs->load(
"companies");
278 $s =
'<select id="filter_thirdparties" name="filter_thirdparties" class="flat maxwidth200">';
281 $sql =
"SELECT rowid, label, type, visible";
282 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
283 $sql .=
" WHERE type in (1,2)";
285 $sql .=
" AND entity = ".$conf->entity;
286 $sql .=
" ORDER BY label";
289 $resql = $this->db->query($sql);
291 $num = $this->db->num_rows($resql);
293 if (!isModEnabled(
"categorie")) {
298 $s .=
'<option value="-1">'.$langs->trans(
"Categories").
'</option>';
300 $s .=
'<option value="0">'.$langs->trans(
"ContactsAllShort").
'</option>';
305 $obj = $this->db->fetch_object($resql);
308 if ($obj->type == 1) {
309 $type = $langs->trans(
"Supplier");
311 if ($obj->type == 2) {
312 $type = $langs->trans(
"Customer");
314 $labeltoshow = $obj->label;
316 $labeltoshow .=
' <span class="opacitymedium">('.$type.
')</span>';
318 $s .=
'<option value="'.$obj->rowid.
'" data-html="'.
dol_escape_htmltag($labeltoshow).
'">';
331 $s .=
'<select id="filter_client_thirdparties" name="filter_client_thirdparties" class="flat minwidth100">';
332 $s .=
'<option value="-1">'.$langs->trans(
'ProspectCustomer').
'</option>';
334 $s .=
'<option value="2">'.$langs->trans(
'Prospect').
'</option>';
337 $s .=
'<option value="3">'.$langs->trans(
'ProspectCustomer').
'</option>';
340 $s .=
'<option value="1">'.$langs->trans(
'Customer').
'</option>';
342 $s .=
'<option value="0">'.$langs->trans(
'NorProspectNorCustomer').
'</option>';
348 $s .=
' <select id="filter_supplier_thirdparties" name="filter_supplier_thirdparties" class="flat minwidth100">';
349 $s .=
'<option value="-1">'.$langs->trans(
"Supplier").
'</option>';
350 $s .=
'<option value="1">'.$langs->trans(
"Yes").
'</option>';
351 $s .=
'<option value="0">'.$langs->trans(
"No").
'</option>';
356 $s .=
' <select id="filter_status_thirdparties" name="filter_status" class="flat">';
357 $s .=
'<option value="-1">'.$langs->trans(
"Status").
'</option>';
358 $s .=
'<option value="1">'.$langs->trans(
"Enabled").
'</option>';
359 $s .=
'<option value="0">'.$langs->trans(
"Disabled").
'</option>';
366 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
368 $s .=
img_picto($langs->trans(
"DefaultLang"),
'language',
'class="pictofixedwidth"');
370 $s .= $formadmin->select_language(
GETPOST(
'filter_lang_thirdparties',
'aZ09'),
'filter_lang_thirdparties', 0,
null, $langs->trans(
"DefaultLang"), 0, 0,
'', 0, 0, 0,
null, 1);
385 return '<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$id.
'">'.
img_object(
'',
"company").
'</a>';
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Parent class of emailing target selectors modules.
Class to manage a list of personalised recipients for mailing feature.
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
url($id)
Can include an URL link on each record provided by selector shown on target page.
__construct($db)
Constructor.
add_to_target($mailing_id)
This is the main function that returns the array of emails.
formFilter()
This is to add a form filter to provide variant of selector If used, the HTML select must be called "...
getNbOfRecipients($sql='')
Return here number of distinct emails returned by your selector.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...