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");
37 public $picto =
'company';
53 $langs->load(
"companies");
75 if (empty($_POST[
'filter']))
77 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, null as label";
78 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
79 $sql .=
" WHERE s.email <> ''";
80 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
81 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".$mailing_id.
")";
85 $addFilter .=
" AND s.client=".((int)
GETPOST(
"filter_client",
'int'));
86 $addDescription = $langs->trans(
'ProspectCustomer').
"=";
87 if ($_POST[
"filter_client"] == 0)
89 $addDescription .= $langs->trans(
'NorProspectNorCustomer');
90 } elseif ($_POST[
"filter_client"] == 1)
92 $addDescription .= $langs->trans(
'Customer');
93 } elseif ($_POST[
"filter_client"] == 2)
95 $addDescription .= $langs->trans(
'Prospect');
96 } elseif ($_POST[
"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 $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";
117 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_societe as cs, ".MAIN_DB_PREFIX.
"categorie as c";
118 $sql .=
" WHERE s.email <> ''";
119 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
120 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".$mailing_id.
")";
121 $sql .=
" AND cs.fk_soc = s.rowid";
122 $sql .=
" AND c.rowid = cs.fk_categorie";
123 $sql .=
" AND c.rowid=".((int)
GETPOST(
'filter',
'int'));
126 $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";
127 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs, ".MAIN_DB_PREFIX.
"categorie as c";
128 $sql .=
" WHERE s.email <> ''";
129 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
130 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".$mailing_id.
")";
131 $sql .=
" AND cs.fk_soc = s.rowid";
132 $sql .=
" AND c.rowid = cs.fk_categorie";
133 $sql .=
" AND c.rowid=".((int)
GETPOST(
'filter',
'int'));
136 $sql .=
" ORDER BY email";
139 $result = $this->
db->query($sql);
142 $num = $this->
db->num_rows($result);
146 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
151 $obj = $this->
db->fetch_object($result);
152 if ($old <> $obj->email)
154 $otherTxt = ($obj->label ? $langs->transnoentities(
"Category").
'='.$obj->label :
'');
155 if (strlen($addDescription) > 0 && strlen($otherTxt) > 0)
159 $otherTxt .= $addDescription;
161 'email' => $obj->email,
162 'fk_contact' => $obj->fk_contact,
163 'lastname' => $obj->name,
165 'other' => $otherTxt,
166 'source_url' => $this->url($obj->id),
167 'source_id' => $obj->id,
168 'source_type' =>
'thirdparty'
178 $this->error = $this->
db->error();
182 return parent::addTargetsToDatabase($mailing_id, $cibles);
216 $sql =
"SELECT count(distinct(s.email)) as nb";
217 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
218 $sql .=
" WHERE s.email != ''";
219 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
223 return parent::getNbOfRecipients($sql);
234 global $conf, $langs;
236 $langs->load(
"companies");
238 $s = $langs->trans(
"Categories").
': ';
239 $s .=
'<select name="filter" class="flat">';
242 $sql =
"SELECT rowid, label, type, visible";
243 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
244 $sql .=
" WHERE type in (1,2)";
246 $sql .=
" AND entity = ".$conf->entity;
247 $sql .=
" ORDER BY label";
255 if (empty($conf->categorie->enabled)) $num = 0;
257 if ($num) $s .=
'<option value="0"> </option>';
258 else $s .=
'<option value="0">'.$langs->trans(
"ContactsAllShort").
'</option>';
263 $obj = $this->
db->fetch_object(
$resql);
266 if ($obj->type == 1) $type = $langs->trans(
"Supplier");
267 if ($obj->type == 2) $type = $langs->trans(
"Customer");
268 $s .=
'<option value="'.$obj->rowid.
'">'.
dol_trunc($obj->label, 38,
'middle');
269 if ($type) $s .=
' ('.$type.
')';
278 $s .= $langs->trans(
'ProspectCustomer');
279 $s .=
': <select name="filter_client" class="flat">';
280 $s .=
'<option value="-1"> </option>';
281 if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
282 $s .=
'<option value="2">'.$langs->trans(
'Prospect').
'</option>';
284 if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
285 $s .=
'<option value="3">'.$langs->trans(
'ProspectCustomer').
'</option>';
287 if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
288 $s .=
'<option value="1">'.$langs->trans(
'Customer').
'</option>';
290 $s .=
'<option value="0">'.$langs->trans(
'NorProspectNorCustomer').
'</option>';
294 $s .= $langs->trans(
"Status");
295 $s .=
': <select name="filter_status" class="flat">';
296 $s .=
'<option value="-1"> </option>';
297 $s .=
'<option value="1" selected>'.$langs->trans(
"Enabled").
'</option>';
298 $s .=
'<option value="0">'.$langs->trans(
"Disabled").
'</option>';
312 return '<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$id.
'">'.
img_object(
'',
"company").
'</a>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
__construct($db)
Constructor.
Class to manage a list of personalised recipients for mailing feature.
add_to_target($mailing_id)
This is the main function that returns the array of emails.
$conf db
API class for accounts.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
formFilter()
This is to add a form filter to provide variant of selector If used, the HTML select must be called "...
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getNbOfRecipients($sql= '')
Return here number of distinct emails returned by your selector.
url($id)
Can include an URL link on each record provided by selector shown on target page. ...
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $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...
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.
Parent class of emailing target selectors modules.