Go to the documentation of this file.
19 include_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");
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");
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')) {
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')) {
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).
")";
147 $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";
148 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_societe as cs, ".MAIN_DB_PREFIX.
"categorie as c";
149 $sql .=
" WHERE s.email <> ''";
150 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
151 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
152 $sql .=
" AND cs.fk_soc = s.rowid";
153 $sql .=
" AND c.rowid = cs.fk_categorie";
154 if (
GETPOST(
'filter_thirdparties',
'int') > 0) {
155 $sql .=
" AND c.rowid=".((int)
GETPOST(
'filter_thirdparties',
'int'));
159 $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";
160 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs, ".MAIN_DB_PREFIX.
"categorie as c";
161 $sql .=
" WHERE s.email <> ''";
162 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
163 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
164 $sql .=
" AND cs.fk_soc = s.rowid";
165 $sql .=
" AND c.rowid = cs.fk_categorie";
166 if (
GETPOST(
'filter_thirdparties',
'int') > 0) {
167 $sql .=
" AND c.rowid=".((int)
GETPOST(
'filter_thirdparties',
'int'));
171 $sql .=
" ORDER BY email";
176 $result = $this->
db->query($sql);
178 $num = $this->
db->num_rows($result);
182 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
186 $obj = $this->
db->fetch_object($result);
187 if ($old <> $obj->email) {
188 $otherTxt = ($obj->label ? $langs->transnoentities(
"Category").
'='.$obj->label :
'');
189 if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
192 $otherTxt .= $addDescription;
194 'email' => $obj->email,
195 'fk_contact' => $obj->fk_contact,
196 'lastname' => $obj->name,
198 'other' => $otherTxt,
199 'source_url' => $this->url($obj->id),
200 'source_id' => $obj->id,
201 'source_type' =>
'thirdparty'
211 $this->error = $this->
db->error();
215 return parent::addTargetsToDatabase($mailing_id, $cibles);
249 $sql =
"SELECT count(distinct(s.email)) as nb";
250 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
251 $sql .=
" WHERE s.email <> ''";
252 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
253 $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).
")";
255 return parent::getNbOfRecipients($sql);
266 global $conf, $langs;
268 $langs->load(
"companies");
271 $s =
'<select id="filter_thirdparties" name="filter_thirdparties" class="flat">';
274 $sql =
"SELECT rowid, label, type, visible";
275 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
276 $sql .=
" WHERE type in (1,2)";
278 $sql .=
" AND entity = ".$conf->entity;
279 $sql .=
" ORDER BY label";
286 if (empty($conf->categorie->enabled)) {
291 $s .=
'<option value="-1">'.$langs->trans(
"Categories").
'</option>';
293 $s .=
'<option value="0">'.$langs->trans(
"ContactsAllShort").
'</option>';
298 $obj = $this->
db->fetch_object(
$resql);
301 if ($obj->type == 1) {
302 $type = $langs->trans(
"Supplier");
304 if ($obj->type == 2) {
305 $type = $langs->trans(
"Customer");
307 $s .=
'<option value="'.$obj->rowid.
'">'.
dol_trunc($obj->label, 38,
'middle');
309 $s .=
' ('.$type.
')';
322 $s .=
'<select id="filter_client_thirdparties" name="filter_client_thirdparties" class="flat minwidth100">';
323 $s .=
'<option value="-1">'.$langs->trans(
'ProspectCustomer').
'</option>';
324 if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
325 $s .=
'<option value="2">'.$langs->trans(
'Prospect').
'</option>';
327 if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
328 $s .=
'<option value="3">'.$langs->trans(
'ProspectCustomer').
'</option>';
330 if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
331 $s .=
'<option value="1">'.$langs->trans(
'Customer').
'</option>';
333 $s .=
'<option value="0">'.$langs->trans(
'NorProspectNorCustomer').
'</option>';
339 $s .=
' <select id="filter_supplier_thirdparties" name="filter_supplier_thirdparties" class="flat minwidth100">';
340 $s .=
'<option value="-1">'.$langs->trans(
"Supplier").
'</option>';
341 $s .=
'<option value="1">'.$langs->trans(
"Yes").
'</option>';
342 $s .=
'<option value="0">'.$langs->trans(
"No").
'</option>';
347 $s .=
' <select id="filter_status_thirdparties" name="filter_status" class="flat">';
348 $s .=
'<option value="-1">'.$langs->trans(
"Status").
'</option>';
349 $s .=
'<option value="1">'.$langs->trans(
"Enabled").
'</option>';
350 $s .=
'<option value="0">'.$langs->trans(
"Disabled").
'</option>';
357 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
359 $s .=
'<span class="opacitymedium">'.$langs->trans(
"DefaultLang").
':</span> ';
360 $s .= $formadmin->select_language($langs->getDefaultLang(1),
'filter_lang_thirdparties', 0,
null, 1, 0, 0,
'', 0, 0, 0,
null, 1);
375 return '<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$id.
'">'.
img_object(
'',
"company").
'</a>';
formFilter()
This is to add a form filter to provide variant of selector If used, the HTML select must be called "...
$conf db
API class for accounts.
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.
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='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Parent class of emailing target selectors modules.
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
__construct($db)
Constructor.
getNbOfRecipients($sql='')
Return here number of distinct emails returned by your selector.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
add_to_target($mailing_id)
This is the main function that returns the array of emails.
url($id)
Can include an URL link on each record provided by selector shown on target page.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Class to manage a list of personalised recipients for mailing feature.