27include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
35 public $name =
'ContactCompanies';
37 public $desc =
'Contacts of thirdparties (prospects, customers, suppliers...)';
38 public $require_module = array(
"societe");
39 public $require_admin = 0;
41 public $enabled =
'isModEnabled("societe")';
46 public $picto =
'contact';
72 $langs->load(
"commercial");
75 $statssql[0] =
"SELECT '".$this->db->escape($langs->trans(
"NbOfCompaniesContacts")).
"' as label,";
76 $statssql[0] .=
" count(distinct(c.email)) as nb";
77 $statssql[0] .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
78 $statssql[0] .=
" WHERE c.entity IN (".getEntity(
'contact').
")";
79 $statssql[0] .=
" AND c.email <> ''";
80 $statssql[0] .=
" AND c.statut = 1";
98 $sql =
"SELECT count(distinct(c.email)) as nb";
99 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
100 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc";
101 $sql .=
" WHERE c.entity IN (".getEntity(
'contact').
")";
102 $sql .=
" AND c.email <> ''";
103 if (empty($this->evenunsubscribe)) {
104 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = c.email and mu.entity = ".((int) $conf->entity).
")";
107 $sql .=
" AND c.statut = 1";
110 return parent::getNbOfRecipients($sql);
124 $langs->loadLangs(array(
"commercial",
"companies",
"suppliers",
"categories"));
129 $sql =
"SELECT sp.poste, count(distinct(sp.email)) AS nb";
130 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
131 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
132 $sql .=
" AND sp.email <> ''";
133 $sql .=
" AND sp.statut = 1";
134 $sql .=
" AND (sp.poste IS NOT NULL AND sp.poste <> '')";
135 $sql .=
" GROUP BY sp.poste";
136 $sql .=
" ORDER BY sp.poste";
137 $resql = $this->db->query($sql);
139 $s .=
'<select id="filter_jobposition_contact" name="filter_jobposition" class="flat maxwidth200" placeholder="'.dol_escape_htmltag($langs->trans(
"PostOrFunction")).
'">';
140 $s .=
'<option value="-1">'.$langs->trans(
"PostOrFunction").
'</option>';
142 $num = $this->db->num_rows($resql);
146 $obj = $this->db->fetch_object($resql);
147 $s .=
'<option value="'.dol_escape_htmltag($obj->poste).
'">'.
dol_escape_htmltag($obj->poste).
' ('.$obj->nb.
')</option>';
151 $s .=
'<option disabled="disabled" value="">'.$langs->trans(
"None").
'</option>';
161 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
163 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
164 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
165 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_contact as cs";
166 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
167 $sql .=
" AND sp.email <> ''";
168 $sql .=
" AND sp.statut = 1";
169 $sql .=
" AND cs.fk_categorie = c.rowid";
170 $sql .=
" AND cs.fk_socpeople = sp.rowid";
171 $sql .=
" GROUP BY c.label";
172 $sql .=
" ORDER BY c.label";
173 $resql = $this->db->query($sql);
175 $s .=
'<select id="filter_category_contact" name="filter_category" class="flat maxwidth200">';
176 $s .=
'<option value="-1">'.$langs->trans(
"ContactCategoriesShort").
'</option>';
178 $num = $this->db->num_rows($resql);
182 $obj = $this->db->fetch_object($resql);
183 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
187 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactWithCategoryFound").
'</option>';
197 $s .=
'<select id="filter_contact" name="filter" class="flat maxwidth200">';
198 $sql =
"SELECT code, label";
199 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
200 $sql .=
" WHERE active > 0";
201 $sql .=
" ORDER BY label";
202 $resql = $this->db->query($sql);
204 $num = $this->db->num_rows($resql);
206 $s .=
'<option value="-1">'.$langs->trans(
"NatureOfThirdParty").
'</option>';
208 $s .=
'<option value="-1">'.$langs->trans(
"ContactsAllShort").
'</option>';
210 $s .=
'<option value="prospects">'.$langs->trans(
"ThirdPartyProspects").
'</option>';
214 $obj = $this->db->fetch_object($resql);
215 $level = $langs->trans($obj->code);
216 if ($level == $obj->code) {
217 $level = $langs->trans($obj->label);
219 $labeltoshow = $langs->trans(
"ThirdPartyProspects").
' <span class="opacitymedium">('.$langs->trans(
"ProspectLevelShort").
'='.$level.
')</span>';
220 $s .=
'<option value="prospectslevel'.$obj->code.
'" data-html="'.
dol_escape_htmltag($labeltoshow).
'">'.$labeltoshow.
'</option>';
226 $s .=
'<option value="customers">'.$langs->trans(
"ThirdPartyCustomers").
'</option>';
228 $s .=
'<option value="suppliers">'.$langs->trans(
"ThirdPartySuppliers").
'</option>';
235 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
237 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
238 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
239 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_societe as cs";
240 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
241 $sql .=
" AND sp.email <> ''";
242 $sql .=
" AND sp.statut = 1";
243 $sql .=
" AND cs.fk_categorie = c.rowid";
244 $sql .=
" AND cs.fk_soc = sp.fk_soc";
245 $sql .=
" GROUP BY c.label";
246 $sql .=
" ORDER BY c.label";
247 $resql = $this->db->query($sql);
249 $s .=
'<select id="filter_category_customer_contact" name="filter_category_customer" class="flat maxwidth200">';
250 $s .=
'<option value="-1">'.$langs->trans(
"CustomersProspectsCategoriesShort").
'</option>';
252 $num = $this->db->num_rows($resql);
256 $obj = $this->db->fetch_object($resql);
257 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
261 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactLinkedToThirdpartieWithCategoryFound").
'</option>';
272 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
274 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
275 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
276 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
277 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
278 $sql .=
" AND sp.email <> ''";
279 $sql .=
" AND sp.statut = 1";
280 $sql .=
" AND cs.fk_categorie = c.rowid";
281 $sql .=
" AND cs.fk_soc = sp.fk_soc";
282 $sql .=
" GROUP BY c.label";
283 $sql .=
" ORDER BY c.label";
284 $resql = $this->db->query($sql);
286 $s .=
'<select id="filter_category_supplier_contact" name="filter_category_supplier" class="flat maxwidth200">';
287 $s .=
'<option value="-1">'.$langs->trans(
"SuppliersCategoriesShort").
'</option>';
289 $num = $this->db->num_rows($resql);
293 $obj = $this->db->fetch_object($resql);
294 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
298 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactLinkedToThirdpartieWithCategoryFound").
'</option>';
309 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
311 $s .=
img_picto($langs->trans(
"DefaultLang"),
'language',
'class="pictofixedwidth"');
312 $s .= $formadmin->select_language(
GETPOST(
'filter_lang',
'aZ09'),
'filter_lang', 0,
null, $langs->trans(
"DefaultLang"), 0, 0,
'', 0, 0, 0,
null, 1);
327 return '<a href="'.DOL_URL_ROOT.
'/contact/card.php?id='.$id.
'">'.
img_object(
'',
"contact").
'</a>';
341 global $conf, $langs;
343 $filter =
GETPOST(
'filter',
'alpha');
344 $filter_jobposition =
GETPOST(
'filter_jobposition',
'alpha');
345 $filter_category =
GETPOST(
'filter_category',
'alpha');
346 $filter_category_customer =
GETPOST(
'filter_category_customer',
'alpha');
347 $filter_category_supplier =
GETPOST(
'filter_category_supplier',
'alpha');
348 $filter_lang =
GETPOST(
'filter_lang',
'alpha');
353 $prospectlevel = array();
354 $sql =
"SELECT code, label";
355 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
356 $sql .=
" WHERE active > 0";
357 $sql .=
" ORDER BY label";
358 $resql = $this->db->query($sql);
360 $num = $this->db->num_rows($resql);
363 $obj = $this->db->fetch_object($resql);
364 $prospectlevel[$obj->code] = $obj->label;
372 $sql =
"SELECT sp.rowid as id, sp.email as email, sp.rowid as fk_contact, sp.lastname, sp.firstname, sp.civility as civility_id, sp.poste as jobposition,";
373 $sql .=
" s.nom as companyname";
374 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
375 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = sp.fk_soc";
376 if ($filter_category !=
'all' && $filter_category !=
'-1') {
377 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c";
378 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_contact as cs";
380 if ($filter_category_customer !=
'all' && $filter_category_customer !=
'-1') {
381 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c2";
382 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_societe as c2s";
384 if ($filter_category_supplier !=
'all' && $filter_category_supplier !=
'-1') {
385 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c3";
386 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_fournisseur as c3s";
388 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
389 $sql .=
" AND sp.email <> ''";
391 if (empty($this->evenunsubscribe)) {
392 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = sp.email and mu.entity = ".((int) $conf->entity).
")";
395 $sql .=
" AND sp.statut = 1";
396 $sql .=
" AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
399 if ($filter_category !=
'all' && $filter_category !=
'-1') {
400 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid";
401 $sql .=
" AND c.label = '".$this->db->escape($filter_category).
"'";
403 if ($filter_category_customer !=
'all' && $filter_category_customer !=
'-1') {
404 $sql .=
" AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc";
405 $sql .=
" AND c2.label = '".$this->db->escape($filter_category_customer).
"'";
407 if ($filter_category_supplier !=
'all' && $filter_category_supplier !=
'-1') {
408 $sql .=
" AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc";
409 $sql .=
" AND c3.label = '".$this->db->escape($filter_category_supplier).
"'";
413 if (!empty($filter_lang) && $filter_lang !=
'-1') {
414 $sql .=
" AND sp.default_lang LIKE '".$this->db->escape($filter_lang).
"%'";
421 if ($key ==
'prospects') {
422 $sql .=
" AND s.client = 2";
424 foreach ($prospectlevel as $codelevel => $valuelevel) {
425 if ($key ==
'prospectslevel'.$codelevel) {
426 $sql .=
" AND s.fk_prospectlevel = '".$this->db->escape($codelevel).
"'";
429 if ($key ==
'customers') {
430 $sql .=
" AND s.client = 1";
432 if ($key ==
'suppliers') {
433 $sql .=
" AND s.fournisseur = 1";
437 $key = $filter_jobposition;
438 if (!empty($key) && $key !=
'all' && $key !=
'-1') {
439 $sql .=
" AND sp.poste = '".$this->db->escape($key).
"'";
442 $sql .=
" ORDER BY sp.email";
446 $result = $this->db->query($sql);
448 $num = $this->db->num_rows($result);
452 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
456 $obj = $this->db->fetch_object($result);
457 if ($old != $obj->email) {
459 'email' => $obj->email,
460 'fk_contact' => $obj->fk_contact,
461 'lastname' => $obj->lastname,
462 'firstname' => $obj->firstname,
464 ($langs->transnoentities(
"ThirdParty").
'='.$obj->companyname).
';'.
465 ($langs->transnoentities(
"UserTitle").
'='.($obj->civility_id ? $langs->transnoentities(
"Civility".$obj->civility_id) :
'')).
';'.
466 ($langs->transnoentities(
"PostOrFunction").
'='.$obj->jobposition),
467 'source_url' => $this->
url($obj->id),
468 'source_id' => $obj->id,
469 'source_type' =>
'contact'
479 $this->error = $this->db->error();
483 return parent::addTargetsToDatabase($mailing_id, $cibles);
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.
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 a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...