20include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
28 public $name =
'ThirdPartiesByCategories';
30 public $desc =
"Third parties (by categories)";
31 public $require_admin = 0;
33 public $require_module = array(
"societe");
35 public $enabled =
'isModEnabled("societe")';
40 public $picto =
'company';
51 $langs->load(
"companies");
73 if (GETPOSTISSET(
"filter_client_thirdparties") &&
GETPOST(
"filter_client_thirdparties") !=
'-1') {
74 $addFilter .=
" AND s.client=".(GETPOSTINT(
"filter_client_thirdparties"));
75 $addDescription = $langs->trans(
'ProspectCustomer').
"=";
76 if (
GETPOST(
"filter_client_thirdparties") == 0) {
77 $addDescription .= $langs->trans(
'NorProspectNorCustomer');
78 } elseif (
GETPOST(
"filter_client_thirdparties") == 1) {
79 $addDescription .= $langs->trans(
'Customer');
80 } elseif (
GETPOST(
"filter_client_thirdparties") == 2) {
81 $addDescription .= $langs->trans(
'Prospect');
82 } elseif (
GETPOST(
"filter_client_thirdparties") == 3) {
83 $addDescription .= $langs->trans(
'ProspectCustomer');
85 $addDescription .=
"Unknown status ".GETPOST(
"filter_client_thirdparties");
88 if (GETPOSTISSET(
"filter_supplier_thirdparties") &&
GETPOST(
"filter_supplier_thirdparties") !=
'-1') {
89 $addFilter .=
" AND s.fournisseur = ".(GETPOSTINT(
"filter_supplier_thirdparties"));
90 $addDescription = $langs->trans(
'Supplier').
"=";
91 if (
GETPOST(
"filter_supplier_thirdparties") == 0) {
92 $addDescription .= $langs->trans(
'No');
93 } elseif (
GETPOST(
"filter_supplier_thirdparties") == 1) {
94 $addDescription .= $langs->trans(
'Yes');
96 $addDescription .=
"Unknown status ".GETPOST(
"filter_supplier_thirdparties");
99 if (GETPOSTISSET(
"filter_status")) {
100 if (strlen($addDescription) > 0) {
101 $addDescription .=
";";
103 $addDescription .= $langs->trans(
"Status").
"=";
104 if (
GETPOST(
"filter_status") ==
'1') {
105 $addFilter .=
" AND s.status=1";
106 $addDescription .= $langs->trans(
"Enabled");
107 } elseif (
GETPOST(
"filter_status") ==
'0') {
108 $addFilter .=
" AND s.status=0";
109 $addDescription .= $langs->trans(
"Disabled");
112 if (GETPOSTISSET(
"filter_status")) {
113 if (strlen($addDescription) > 0) {
114 $addDescription .=
";";
116 $addDescription .= $langs->trans(
"Status").
"=";
117 if (
GETPOST(
"filter_status") ==
'1') {
118 $addFilter .=
" AND s.status=1";
119 $addDescription .= $langs->trans(
"Enabled");
120 } elseif (
GETPOST(
"filter_status") ==
'0') {
121 $addFilter .=
" AND s.status=0";
122 $addDescription .= $langs->trans(
"Disabled");
125 if (
GETPOST(
'default_lang',
'alpha') &&
GETPOST(
'default_lang',
'alpha') !=
'-1') {
126 $addFilter .=
" AND s.default_lang LIKE '".$this->db->escape(
GETPOST(
'default_lang',
'alpha')).
"%'";
127 $addDescription = $langs->trans(
'DefaultLang').
"=";
129 if (
GETPOST(
'filter_lang_thirdparties',
'alpha') &&
GETPOST(
'filter_lang_thirdparties',
'alpha') !=
'-1') {
130 $addFilter .=
" AND s.default_lang LIKE '".$this->db->escape(
GETPOST(
'filter_lang_thirdparties',
'alpha')).
"%'";
131 $addDescription = $langs->trans(
'DefaultLang').
"=";
135 if (!
GETPOST(
'filter_thirdparties') ||
GETPOST(
'filter_thirdparties') ==
'-1') {
136 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, null as label";
137 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
138 $sql .=
" WHERE s.email <> ''";
139 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
140 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
141 if (empty($this->evenunsubscribe)) {
142 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = s.email) = 0";
146 $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";
147 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_societe as cs, ".MAIN_DB_PREFIX.
"categorie as c";
148 $sql .=
" WHERE s.email <> ''";
149 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
150 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
151 $sql .=
" AND cs.fk_soc = s.rowid";
152 $sql .=
" AND c.rowid = cs.fk_categorie";
154 $sql .=
" AND c.rowid=".(GETPOSTINT(
'filter_thirdparties'));
156 if (empty($this->evenunsubscribe)) {
157 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = s.email) = 0";
161 $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";
162 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs, ".MAIN_DB_PREFIX.
"categorie as c";
163 $sql .=
" WHERE s.email <> ''";
164 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
165 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
166 $sql .=
" AND cs.fk_soc = s.rowid";
167 $sql .=
" AND c.rowid = cs.fk_categorie";
169 $sql .=
" AND c.rowid=".(GETPOSTINT(
'filter_thirdparties'));
171 if (empty($this->evenunsubscribe)) {
172 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = s.email) = 0";
176 $sql .=
" ORDER BY email";
181 $result = $this->db->query($sql);
183 $num = $this->db->num_rows($result);
187 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
191 $obj = $this->db->fetch_object($result);
192 if ($old != $obj->email) {
193 $otherTxt = ($obj->label ? $langs->transnoentities(
"Category").
'='.$obj->label :
'');
194 if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
197 $otherTxt .= $addDescription;
199 'email' => $obj->email,
200 'fk_contact' => $obj->fk_contact,
201 'lastname' => $obj->name,
203 'other' => $otherTxt,
204 'source_url' => $this->url($obj->id),
205 'source_id' => $obj->id,
206 'source_type' =>
'thirdparty'
216 $this->error = $this->db->error();
220 return parent::addTargetsToDatabase($mailing_id, $cibles);
254 $sql =
"SELECT count(distinct(s.email)) as nb";
255 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
256 $sql .=
" WHERE s.email <> ''";
257 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
258 if (empty($this->evenunsubscribe)) {
259 $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).
")";
263 return parent::getNbOfRecipients($sql);
274 global $conf, $langs;
276 $langs->load(
"companies");
279 $s =
'<select id="filter_thirdparties" name="filter_thirdparties" class="flat maxwidth200">';
282 $sql =
"SELECT rowid, label, type, visible";
283 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
284 $sql .=
" WHERE type in (1,2)";
286 $sql .=
" AND entity = ".$conf->entity;
287 $sql .=
" ORDER BY label";
290 $resql = $this->db->query($sql);
292 $num = $this->db->num_rows($resql);
294 if (!isModEnabled(
"category")) {
299 $s .=
'<option value="-1">'.$langs->trans(
"Categories").
'</option>';
301 $s .=
'<option value="0">'.$langs->trans(
"ContactsAllShort").
'</option>';
306 $obj = $this->db->fetch_object($resql);
309 if ($obj->type == 1) {
310 $type = $langs->trans(
"Supplier");
312 if ($obj->type == 2) {
313 $type = $langs->trans(
"Customer");
315 $labeltoshow = $obj->label;
317 $labeltoshow .=
' <span class="opacitymedium">('.$type.
')</span>';
319 $s .=
'<option value="'.$obj->rowid.
'" data-html="'.
dol_escape_htmltag($labeltoshow).
'">';
332 $s .=
'<select id="filter_client_thirdparties" name="filter_client_thirdparties" class="flat minwidth100">';
333 $s .=
'<option value="-1">'.$langs->trans(
'ProspectCustomer').
'</option>';
335 $s .=
'<option value="2">'.$langs->trans(
'Prospect').
'</option>';
338 $s .=
'<option value="3">'.$langs->trans(
'ProspectCustomer').
'</option>';
341 $s .=
'<option value="1">'.$langs->trans(
'Customer').
'</option>';
343 $s .=
'<option value="0">'.$langs->trans(
'NorProspectNorCustomer').
'</option>';
349 $s .=
' <select id="filter_supplier_thirdparties" name="filter_supplier_thirdparties" class="flat minwidth100">';
350 $s .=
'<option value="-1">'.$langs->trans(
"Supplier").
'</option>';
351 $s .=
'<option value="1">'.$langs->trans(
"Yes").
'</option>';
352 $s .=
'<option value="0">'.$langs->trans(
"No").
'</option>';
357 $s .=
' <select id="filter_status_thirdparties" name="filter_status" class="flat">';
358 $s .=
'<option value="-1">'.$langs->trans(
"Status").
'</option>';
359 $s .=
'<option value="1">'.$langs->trans(
"Enabled").
'</option>';
360 $s .=
'<option value="0">'.$langs->trans(
"Disabled").
'</option>';
367 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
369 $s .=
img_picto($langs->trans(
"DefaultLang"),
'language',
'class="pictofixedwidth"');
371 $s .= $formadmin->select_language(
GETPOST(
'filter_lang_thirdparties',
'aZ09'),
'filter_lang_thirdparties', 0,
null, $langs->trans(
"DefaultLang"), 0, 0,
'', 0, 0, 0,
null, 1);
386 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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a 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...