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");
78 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, null as label";
79 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
80 $sql .=
" WHERE s.email <> ''";
81 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
82 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
83 if (
GETPOST(
'default_lang',
'alpha')) {
84 $sql .=
" AND s.default_lang LIKE '".$this->db->escape(
GETPOST(
'default_lang',
'alpha')).
"%'";
89 $addFilter .=
" AND s.client=".((int)
GETPOST(
"filter_client",
'int'));
90 $addDescription = $langs->trans(
'ProspectCustomer').
"=";
91 if (
GETPOST(
"filter_client") == 0) {
92 $addDescription .= $langs->trans(
'NorProspectNorCustomer');
93 } elseif (
GETPOST(
"filter_client") == 1) {
94 $addDescription .= $langs->trans(
'Customer');
95 } elseif (
GETPOST(
"filter_client") == 2) {
96 $addDescription .= $langs->trans(
'Prospect');
97 } elseif (
GETPOST(
"filter_client") == 3) {
98 $addDescription .= $langs->trans(
'ProspectCustomer');
100 $addDescription .=
"Unknown status ".GETPOST(
"filter_client");
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");
112 $addFilter .=
" AND s.status=0";
113 $addDescription .= $langs->trans(
"Disabled");
116 if (
GETPOST(
'default_lang',
'alpha')) {
117 $addFilter .=
" AND s.default_lang LIKE '".$this->db->escape(
GETPOST(
'default_lang',
'alpha')).
"%'";
118 $addDescription = $langs->trans(
'DefaultLang').
"=";
120 if (
GETPOST(
'filter_lang_thirdparties',
'alpha')) {
121 $addFilter .=
" AND s.default_lang LIKE '".$this->db->escape(
GETPOST(
'filter_lang_thirdparties',
'alpha')).
"%'";
122 $addDescription = $langs->trans(
'DefaultLang').
"=";
125 $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";
126 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_societe as cs, ".MAIN_DB_PREFIX.
"categorie as c";
127 $sql .=
" WHERE s.email <> ''";
128 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
129 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
130 $sql .=
" AND cs.fk_soc = s.rowid";
131 $sql .=
" AND c.rowid = cs.fk_categorie";
132 if (
GETPOST(
'filter',
'int') > 0) {
133 $sql .=
" AND c.rowid=".((int)
GETPOST(
'filter',
'int'));
137 $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";
138 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs, ".MAIN_DB_PREFIX.
"categorie as c";
139 $sql .=
" WHERE s.email <> ''";
140 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
141 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
142 $sql .=
" AND cs.fk_soc = s.rowid";
143 $sql .=
" AND c.rowid = cs.fk_categorie";
144 if (
GETPOST(
'filter',
'int') > 0) {
145 $sql .=
" AND c.rowid=".((int)
GETPOST(
'filter',
'int'));
149 $sql .=
" ORDER BY email";
152 $result = $this->
db->query($sql);
154 $num = $this->
db->num_rows($result);
158 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
162 $obj = $this->
db->fetch_object($result);
163 if ($old <> $obj->email) {
164 $otherTxt = ($obj->label ? $langs->transnoentities(
"Category").
'='.$obj->label :
'');
165 if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
168 $otherTxt .= $addDescription;
170 'email' => $obj->email,
171 'fk_contact' => $obj->fk_contact,
172 'lastname' => $obj->name,
174 'other' => $otherTxt,
175 'source_url' => $this->url($obj->id),
176 'source_id' => $obj->id,
177 'source_type' =>
'thirdparty'
187 $this->error = $this->
db->error();
191 return parent::addTargetsToDatabase($mailing_id, $cibles);
225 $sql =
"SELECT count(distinct(s.email)) as nb";
226 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
227 $sql .=
" WHERE s.email <> ''";
228 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
229 $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).
")";
231 return parent::getNbOfRecipients($sql);
242 global $conf, $langs;
244 $langs->load(
"companies");
246 $s =
'<select id="filter_thirdparties" name="filter" class="flat">';
249 $sql =
"SELECT rowid, label, type, visible";
250 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
251 $sql .=
" WHERE type in (1,2)";
253 $sql .=
" AND entity = ".$conf->entity;
254 $sql .=
" ORDER BY label";
261 if (empty($conf->categorie->enabled)) {
266 $s .=
'<option value="-1">'.$langs->trans(
"Categories").
'</option>';
268 $s .=
'<option value="0">'.$langs->trans(
"ContactsAllShort").
'</option>';
273 $obj = $this->
db->fetch_object(
$resql);
276 if ($obj->type == 1) {
277 $type = $langs->trans(
"Supplier");
279 if ($obj->type == 2) {
280 $type = $langs->trans(
"Customer");
282 $s .=
'<option value="'.$obj->rowid.
'">'.
dol_trunc($obj->label, 38,
'middle');
284 $s .=
' ('.$type.
')';
296 $s .=
'<select id="filter_client_thirdparties" name="filter_client_thirdparties" class="flat">';
297 $s .=
'<option value="-1">'.$langs->trans(
'ProspectCustomer').
'</option>';
298 if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
299 $s .=
'<option value="2">'.$langs->trans(
'Prospect').
'</option>';
301 if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
302 $s .=
'<option value="3">'.$langs->trans(
'ProspectCustomer').
'</option>';
304 if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
305 $s .=
'<option value="1">'.$langs->trans(
'Customer').
'</option>';
307 $s .=
'<option value="0">'.$langs->trans(
'NorProspectNorCustomer').
'</option>';
312 $s .=
' <select id="filter_status_thirdparties" name="filter_status" class="flat">';
313 $s .=
'<option value="-1">'.$langs->trans(
"Status").
'</option>';
314 $s .=
'<option value="1">'.$langs->trans(
"Enabled").
'</option>';
315 $s .=
'<option value="0">'.$langs->trans(
"Disabled").
'</option>';
321 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
323 $s .=
'<span class="opacitymedium">'.$langs->trans(
"DefaultLang").
':</span> ';
324 $s .= $formadmin->select_language($langs->getDefaultLang(1),
'filter_lang_thirdparties', 0,
null, 1, 0, 0,
'', 0, 0, 0,
null, 1);
339 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.
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_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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.