21include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
32 public $name =
'ThirdPartiesByCategories';
37 public $desc =
"Third parties (by categories)";
42 public $require_admin = 0;
47 public $require_module = array(
"societe");
52 public $enabled =
'isModEnabled("societe")';
57 public $picto =
'company';
68 $langs->load(
"companies");
90 if (
GETPOSTISSET(
"filter_client_thirdparties") &&
GETPOST(
"filter_client_thirdparties") !=
'-1') {
91 $addFilter .=
" AND s.client=".(GETPOSTINT(
"filter_client_thirdparties"));
92 $addDescription = $langs->trans(
'ProspectCustomer').
"=";
93 if (
GETPOST(
"filter_client_thirdparties") == 0) {
94 $addDescription .= $langs->trans(
'NorProspectNorCustomer');
95 } elseif (
GETPOST(
"filter_client_thirdparties") == 1) {
96 $addDescription .= $langs->trans(
'Customer');
97 } elseif (
GETPOST(
"filter_client_thirdparties") == 2) {
98 $addDescription .= $langs->trans(
'Prospect');
99 } elseif (
GETPOST(
"filter_client_thirdparties") == 3) {
100 $addDescription .= $langs->trans(
'ProspectCustomer');
102 $addDescription .=
"Unknown status ".GETPOST(
"filter_client_thirdparties");
105 if (
GETPOSTISSET(
"filter_supplier_thirdparties") &&
GETPOST(
"filter_supplier_thirdparties") !=
'-1') {
106 $addFilter .=
" AND s.fournisseur = ".(GETPOSTINT(
"filter_supplier_thirdparties"));
107 $addDescription = $langs->trans(
'Supplier').
"=";
108 if (
GETPOST(
"filter_supplier_thirdparties") == 0) {
109 $addDescription .= $langs->trans(
'No');
110 } elseif (
GETPOST(
"filter_supplier_thirdparties") == 1) {
111 $addDescription .= $langs->trans(
'Yes');
113 $addDescription .=
"Unknown status ".GETPOST(
"filter_supplier_thirdparties");
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).
")";
148 $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";
149 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_societe as cs, ".MAIN_DB_PREFIX.
"categorie as c";
150 $sql .=
" WHERE s.email <> ''";
151 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
152 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
153 $sql .=
" AND cs.fk_soc = s.rowid";
154 $sql .=
" AND c.rowid = cs.fk_categorie";
156 $sql .=
" AND c.rowid=".(GETPOSTINT(
'filter_thirdparties'));
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'));
174 $sql .=
" ORDER BY email";
179 $result = $this->db->query($sql);
181 $num = $this->db->num_rows($result);
185 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
189 $obj = $this->db->fetch_object($result);
190 if ($old != $obj->email) {
191 $otherTxt = ($obj->label ? $langs->transnoentities(
"Category").
'='.$obj->label :
'');
192 if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
195 $otherTxt .= $addDescription;
197 'email' => $obj->email,
198 'fk_contact' => (
int) $obj->fk_contact,
199 'lastname' => $obj->name,
201 'other' => $otherTxt,
202 'source_url' => $this->url($obj->id),
203 'source_id' => (
int) $obj->id,
204 'source_type' =>
'thirdparty'
214 $this->error = $this->db->error();
218 return parent::addTargetsToDatabase($mailing_id, $cibles);
250 $sql =
"SELECT count(distinct(s.email)) as nb";
251 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
252 $sql .=
" WHERE s.email <> ''";
253 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
257 return parent::getNbOfRecipients($sql);
268 global
$conf, $langs;
270 $langs->load(
"companies");
273 $s =
'<select id="filter_thirdparties" name="filter_thirdparties" class="flat maxwidth200">';
276 $sql =
"SELECT rowid, label, type, visible";
277 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
278 $sql .=
" WHERE type in (1,2)";
280 $sql .=
" AND entity = ".((int)
$conf->entity);
281 $sql .=
" ORDER BY label";
284 $resql = $this->db->query($sql);
286 $num = $this->db->num_rows($resql);
293 $s .=
'<option value="-1">'.$langs->trans(
"Categories").
'</option>';
295 $s .=
'<option value="0">'.$langs->trans(
"ContactsAllShort").
'</option>';
300 $obj = $this->db->fetch_object($resql);
303 if ($obj->type == 1) {
304 $type = $langs->trans(
"Supplier");
306 if ($obj->type == 2) {
307 $type = $langs->trans(
"Customer");
309 $labeltoshow = $obj->label;
311 $labeltoshow .=
' <span class="opacitymedium">('.$type.
')</span>';
313 $s .=
'<option value="'.$obj->rowid.
'" data-html="'.
dol_escape_htmltag($labeltoshow).
'">';
320 dol_print_error($this->db);
326 $s .=
'<select id="filter_client_thirdparties" name="filter_client_thirdparties" class="flat minwidth100">';
327 $s .=
'<option value="-1">'.$langs->trans(
'ProspectCustomer').
'</option>';
329 $s .=
'<option value="2">'.$langs->trans(
'Prospect').
'</option>';
332 $s .=
'<option value="3">'.$langs->trans(
'ProspectCustomer').
'</option>';
335 $s .=
'<option value="1">'.$langs->trans(
'Customer').
'</option>';
337 $s .=
'<option value="0">'.$langs->trans(
'NorProspectNorCustomer').
'</option>';
343 $s .=
' <select id="filter_supplier_thirdparties" name="filter_supplier_thirdparties" class="flat minwidth100">';
344 $s .=
'<option value="-1">'.$langs->trans(
"Supplier").
'</option>';
345 $s .=
'<option value="1">'.$langs->trans(
"Yes").
'</option>';
346 $s .=
'<option value="0">'.$langs->trans(
"No").
'</option>';
351 $s .=
' <select id="filter_status_thirdparties" name="filter_status" class="flat">';
352 $s .=
'<option value="-1">'.$langs->trans(
"Status").
'</option>';
353 $s .=
'<option value="1">'.$langs->trans(
"Enabled").
'</option>';
354 $s .=
'<option value="0">'.$langs->trans(
"Disabled").
'</option>';
361 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
363 $s .= img_picto($langs->trans(
"DefaultLang"),
'language',
'class="pictofixedwidth"');
365 $s .= $formadmin->select_language(
GETPOST(
'filter_lang_thirdparties',
'aZ09'),
'filter_lang_thirdparties', 0, array(), $langs->trans(
"DefaultLang"), 0, 0,
'', 0, 0, 0, array(), 1);
380 return '<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.
$id.
'">'.img_object(
'',
"company").
'</a>';
$id
Support class for third parties, contacts, members, users or resources.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
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 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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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)