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';
55 $langs->load(
"companies");
77 if (GETPOSTISSET(
"filter_client_thirdparties") &&
GETPOST(
"filter_client_thirdparties") <>
'-1') {
78 $addFilter .=
" AND s.client=".((int)
GETPOST(
"filter_client_thirdparties",
'int'));
79 $addDescription = $langs->trans(
'ProspectCustomer').
"=";
80 if (
GETPOST(
"filter_client_thirdparties") == 0) {
81 $addDescription .= $langs->trans(
'NorProspectNorCustomer');
82 } elseif (
GETPOST(
"filter_client_thirdparties") == 1) {
83 $addDescription .= $langs->trans(
'Customer');
84 } elseif (
GETPOST(
"filter_client_thirdparties") == 2) {
85 $addDescription .= $langs->trans(
'Prospect');
86 } elseif (
GETPOST(
"filter_client_thirdparties") == 3) {
87 $addDescription .= $langs->trans(
'ProspectCustomer');
89 $addDescription .=
"Unknown status ".GETPOST(
"filter_client_thirdparties");
92 if (GETPOSTISSET(
"filter_supplier_thirdparties") &&
GETPOST(
"filter_supplier_thirdparties") <>
'-1') {
93 $addFilter .=
" AND s.fournisseur = ".((int)
GETPOST(
"filter_supplier_thirdparties",
'int'));
94 $addDescription = $langs->trans(
'Supplier').
"=";
95 if (
GETPOST(
"filter_supplier_thirdparties") == 0) {
96 $addDescription .= $langs->trans(
'No');
97 } elseif (
GETPOST(
"filter_supplier_thirdparties") == 1) {
98 $addDescription .= $langs->trans(
'Yes');
100 $addDescription .=
"Unknown status ".GETPOST(
"filter_supplier_thirdparties");
103 if (GETPOSTISSET(
"filter_status")) {
104 if (strlen($addDescription) > 0) {
105 $addDescription .=
";";
107 $addDescription .= $langs->trans(
"Status").
"=";
108 if (
GETPOST(
"filter_status") ==
'1') {
109 $addFilter .=
" AND s.status=1";
110 $addDescription .= $langs->trans(
"Enabled");
111 } elseif (
GETPOST(
"filter_status") ==
'0') {
112 $addFilter .=
" AND s.status=0";
113 $addDescription .= $langs->trans(
"Disabled");
116 if (GETPOSTISSET(
"filter_status")) {
117 if (strlen($addDescription) > 0) {
118 $addDescription .=
";";
120 $addDescription .= $langs->trans(
"Status").
"=";
121 if (
GETPOST(
"filter_status") ==
'1') {
122 $addFilter .=
" AND s.status=1";
123 $addDescription .= $langs->trans(
"Enabled");
124 } elseif (
GETPOST(
"filter_status") ==
'0') {
125 $addFilter .=
" AND s.status=0";
126 $addDescription .= $langs->trans(
"Disabled");
129 if (
GETPOST(
'default_lang',
'alpha') &&
GETPOST(
'default_lang',
'alpha') !=
'-1') {
130 $addFilter .=
" AND s.default_lang LIKE '".$this->db->escape(
GETPOST(
'default_lang',
'alpha')).
"%'";
131 $addDescription = $langs->trans(
'DefaultLang').
"=";
133 if (
GETPOST(
'filter_lang_thirdparties',
'alpha') &&
GETPOST(
'filter_lang_thirdparties',
'alpha') !=
'-1') {
134 $addFilter .=
" AND s.default_lang LIKE '".$this->db->escape(
GETPOST(
'filter_lang_thirdparties',
'alpha')).
"%'";
135 $addDescription = $langs->trans(
'DefaultLang').
"=";
139 if (!
GETPOST(
'filter_thirdparties') ||
GETPOST(
'filter_thirdparties') ==
'-1') {
140 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, null as label";
141 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
142 $sql .=
" WHERE s.email <> ''";
143 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
144 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
145 if (empty($this->evenunsubscribe)) {
146 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = s.email) = 0";
150 $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";
151 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_societe as cs, ".MAIN_DB_PREFIX.
"categorie as c";
152 $sql .=
" WHERE s.email <> ''";
153 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
154 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
155 $sql .=
" AND cs.fk_soc = s.rowid";
156 $sql .=
" AND c.rowid = cs.fk_categorie";
157 if (
GETPOST(
'filter_thirdparties',
'int') > 0) {
158 $sql .=
" AND c.rowid=".((int)
GETPOST(
'filter_thirdparties',
'int'));
160 if (empty($this->evenunsubscribe)) {
161 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = s.email) = 0";
165 $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";
166 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs, ".MAIN_DB_PREFIX.
"categorie as c";
167 $sql .=
" WHERE s.email <> ''";
168 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
169 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
170 $sql .=
" AND cs.fk_soc = s.rowid";
171 $sql .=
" AND c.rowid = cs.fk_categorie";
172 if (
GETPOST(
'filter_thirdparties',
'int') > 0) {
173 $sql .=
" AND c.rowid=".((int)
GETPOST(
'filter_thirdparties',
'int'));
175 if (empty($this->evenunsubscribe)) {
176 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = s.email) = 0";
180 $sql .=
" ORDER BY email";
185 $result = $this->db->query($sql);
187 $num = $this->db->num_rows($result);
191 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
195 $obj = $this->db->fetch_object($result);
196 if ($old <> $obj->email) {
197 $otherTxt = ($obj->label ? $langs->transnoentities(
"Category").
'='.$obj->label :
'');
198 if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
201 $otherTxt .= $addDescription;
203 'email' => $obj->email,
204 'fk_contact' => $obj->fk_contact,
205 'lastname' => $obj->name,
207 'other' => $otherTxt,
208 'source_url' => $this->url($obj->id),
209 'source_id' => $obj->id,
210 'source_type' =>
'thirdparty'
220 $this->error = $this->db->error();
224 return parent::addTargetsToDatabase($mailing_id, $cibles);
258 $sql =
"SELECT count(distinct(s.email)) as nb";
259 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
260 $sql .=
" WHERE s.email <> ''";
261 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
262 if (empty($this->evenunsubscribe)) {
263 $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).
")";
267 return parent::getNbOfRecipients($sql);
278 global $conf, $langs;
280 $langs->load(
"companies");
283 $s =
'<select id="filter_thirdparties" name="filter_thirdparties" class="flat maxwidth200">';
286 $sql =
"SELECT rowid, label, type, visible";
287 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
288 $sql .=
" WHERE type in (1,2)";
290 $sql .=
" AND entity = ".$conf->entity;
291 $sql .=
" ORDER BY label";
294 $resql = $this->db->query($sql);
296 $num = $this->db->num_rows($resql);
298 if (!isModEnabled(
"categorie")) {
303 $s .=
'<option value="-1">'.$langs->trans(
"Categories").
'</option>';
305 $s .=
'<option value="0">'.$langs->trans(
"ContactsAllShort").
'</option>';
310 $obj = $this->db->fetch_object($resql);
313 if ($obj->type == 1) {
314 $type = $langs->trans(
"Supplier");
316 if ($obj->type == 2) {
317 $type = $langs->trans(
"Customer");
319 $labeltoshow = $obj->label;
321 $labeltoshow .=
' <span class="opacitymedium">('.$type.
')</span>';
323 $s .=
'<option value="'.$obj->rowid.
'" data-html="'.
dol_escape_htmltag($labeltoshow).
'">';
336 $s .=
'<select id="filter_client_thirdparties" name="filter_client_thirdparties" class="flat minwidth100">';
337 $s .=
'<option value="-1">'.$langs->trans(
'ProspectCustomer').
'</option>';
338 if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
339 $s .=
'<option value="2">'.$langs->trans(
'Prospect').
'</option>';
341 if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
342 $s .=
'<option value="3">'.$langs->trans(
'ProspectCustomer').
'</option>';
344 if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
345 $s .=
'<option value="1">'.$langs->trans(
'Customer').
'</option>';
347 $s .=
'<option value="0">'.$langs->trans(
'NorProspectNorCustomer').
'</option>';
353 $s .=
' <select id="filter_supplier_thirdparties" name="filter_supplier_thirdparties" class="flat minwidth100">';
354 $s .=
'<option value="-1">'.$langs->trans(
"Supplier").
'</option>';
355 $s .=
'<option value="1">'.$langs->trans(
"Yes").
'</option>';
356 $s .=
'<option value="0">'.$langs->trans(
"No").
'</option>';
361 $s .=
' <select id="filter_status_thirdparties" name="filter_status" class="flat">';
362 $s .=
'<option value="-1">'.$langs->trans(
"Status").
'</option>';
363 $s .=
'<option value="1">'.$langs->trans(
"Enabled").
'</option>';
364 $s .=
'<option value="0">'.$langs->trans(
"Disabled").
'</option>';
371 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
373 $s .=
img_picto($langs->trans(
"DefaultLang"),
'language',
'class="pictofixedwidth"');
375 $s .= $formadmin->select_language(
GETPOST(
'filter_lang_thirdparties',
'aZ09'),
'filter_lang_thirdparties', 0,
null, $langs->trans(
"DefaultLang"), 0, 0,
'', 0, 0, 0,
null, 1);
390 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 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.
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...