29include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
37 public $name =
'ContactCompanies';
39 public $desc =
'Contacts of thirdparties (prospects, customers, suppliers...)';
44 public $require_module = array(
"societe");
49 public $require_admin = 0;
54 public $enabled =
'isModEnabled("societe")';
59 public $picto =
'contact';
85 $langs->load(
"commercial");
88 $statssql[0] =
"SELECT '".$this->db->escape($langs->trans(
"NbOfCompaniesContacts")).
"' as label,";
89 $statssql[0] .=
" count(distinct(c.email)) as nb";
90 $statssql[0] .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
91 $statssql[0] .=
" WHERE c.entity IN (".getEntity(
'contact').
")";
92 $statssql[0] .=
" AND c.email <> ''";
93 $statssql[0] .=
" AND c.statut = 1";
111 $sql =
"SELECT count(distinct(c.email)) as nb";
112 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
113 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc";
114 $sql .=
" WHERE c.entity IN (".getEntity(
'contact').
")";
115 $sql .=
" AND c.email <> ''";
116 if (empty($this->evenunsubscribe)) {
117 $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).
")";
120 $sql .=
" AND c.statut = 1";
123 return parent::getNbOfRecipients($sql);
137 $langs->loadLangs(array(
"commercial",
"companies",
"suppliers",
"categories"));
142 $sql =
"SELECT sp.poste, count(distinct(sp.email)) AS nb";
143 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
144 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
145 $sql .=
" AND sp.email <> ''";
146 $sql .=
" AND sp.statut = 1";
147 $sql .=
" AND (sp.poste IS NOT NULL AND sp.poste <> '')";
148 $sql .=
" GROUP BY sp.poste";
149 $sql .=
" ORDER BY sp.poste";
150 $resql = $this->db->query($sql);
152 $s .=
'<select id="filter_jobposition_contact" name="filter_jobposition" class="flat maxwidth200" placeholder="'.dol_escape_htmltag($langs->trans(
"PostOrFunction")).
'">';
153 $s .=
'<option value="-1">'.$langs->trans(
"PostOrFunction").
'</option>';
155 $num = $this->db->num_rows($resql);
159 $obj = $this->db->fetch_object($resql);
160 $s .=
'<option value="'.dol_escape_htmltag($obj->poste).
'">'.
dol_escape_htmltag($obj->poste).
' ('.$obj->nb.
')</option>';
164 $s .=
'<option disabled="disabled" value="">'.$langs->trans(
"None").
'</option>';
174 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
176 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
177 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
178 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_contact as cs";
179 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
180 $sql .=
" AND sp.email <> ''";
181 $sql .=
" AND sp.statut = 1";
182 $sql .=
" AND cs.fk_categorie = c.rowid";
183 $sql .=
" AND cs.fk_socpeople = sp.rowid";
184 $sql .=
" GROUP BY c.label";
185 $sql .=
" ORDER BY c.label";
186 $resql = $this->db->query($sql);
188 $s .=
'<select id="filter_category_contact" name="filter_category" class="flat maxwidth200">';
189 $s .=
'<option value="-1">'.$langs->trans(
"ContactCategoriesShort").
'</option>';
191 $num = $this->db->num_rows($resql);
195 $obj = $this->db->fetch_object($resql);
196 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
200 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactWithCategoryFound").
'</option>';
210 $s .=
'<select id="filter_contact" name="filter" class="flat maxwidth200">';
211 $sql =
"SELECT code, label";
212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
213 $sql .=
" WHERE active > 0";
214 $sql .=
" ORDER BY label";
215 $resql = $this->db->query($sql);
217 $num = $this->db->num_rows($resql);
219 $s .=
'<option value="-1">'.$langs->trans(
"NatureOfThirdParty").
'</option>';
221 $s .=
'<option value="-1">'.$langs->trans(
"ContactsAllShort").
'</option>';
223 $s .=
'<option value="prospects">'.$langs->trans(
"ThirdPartyProspects").
'</option>';
227 $obj = $this->db->fetch_object($resql);
228 $level = $langs->trans($obj->code);
229 if ($level == $obj->code) {
230 $level = $langs->trans($obj->label);
232 $labeltoshow = $langs->trans(
"ThirdPartyProspects").
' <span class="opacitymedium">('.$langs->trans(
"ProspectLevelShort").
'='.$level.
')</span>';
233 $s .=
'<option value="prospectslevel'.$obj->code.
'" data-html="'.
dol_escape_htmltag($labeltoshow).
'">'.$labeltoshow.
'</option>';
239 $s .=
'<option value="customers">'.$langs->trans(
"ThirdPartyCustomers").
'</option>';
241 $s .=
'<option value="suppliers">'.$langs->trans(
"ThirdPartySuppliers").
'</option>';
248 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
250 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
251 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
252 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_societe as cs";
253 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
254 $sql .=
" AND sp.email <> ''";
255 $sql .=
" AND sp.statut = 1";
256 $sql .=
" AND cs.fk_categorie = c.rowid";
257 $sql .=
" AND cs.fk_soc = sp.fk_soc";
258 $sql .=
" GROUP BY c.label";
259 $sql .=
" ORDER BY c.label";
260 $resql = $this->db->query($sql);
262 $s .=
'<select id="filter_category_customer_contact" name="filter_category_customer" class="flat maxwidth200">';
263 $s .=
'<option value="-1">'.$langs->trans(
"CustomersProspectsCategoriesShort").
'</option>';
265 $num = $this->db->num_rows($resql);
269 $obj = $this->db->fetch_object($resql);
270 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
274 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactLinkedToThirdpartieWithCategoryFound").
'</option>';
285 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
287 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
288 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
289 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
290 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
291 $sql .=
" AND sp.email <> ''";
292 $sql .=
" AND sp.statut = 1";
293 $sql .=
" AND cs.fk_categorie = c.rowid";
294 $sql .=
" AND cs.fk_soc = sp.fk_soc";
295 $sql .=
" GROUP BY c.label";
296 $sql .=
" ORDER BY c.label";
297 $resql = $this->db->query($sql);
299 $s .=
'<select id="filter_category_supplier_contact" name="filter_category_supplier" class="flat maxwidth200">';
300 $s .=
'<option value="-1">'.$langs->trans(
"SuppliersCategoriesShort").
'</option>';
302 $num = $this->db->num_rows($resql);
306 $obj = $this->db->fetch_object($resql);
307 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
311 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactLinkedToThirdpartieWithCategoryFound").
'</option>';
322 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
324 $s .=
img_picto($langs->trans(
"DefaultLang"),
'language',
'class="pictofixedwidth"');
325 $s .= $formadmin->select_language(
GETPOST(
'filter_lang',
'aZ09'),
'filter_lang', 0, array(), $langs->trans(
"DefaultLang"), 0, 0,
'', 0, 0, 0, array(), 1);
340 return '<a href="'.DOL_URL_ROOT.
'/contact/card.php?id='.
$id.
'">'.
img_object(
'',
"contact").
'</a>';
354 global $conf, $langs;
356 $filter =
GETPOST(
'filter',
'alpha');
357 $filter_jobposition =
GETPOST(
'filter_jobposition',
'alpha');
358 $filter_category =
GETPOST(
'filter_category',
'alpha');
359 $filter_category_customer =
GETPOST(
'filter_category_customer',
'alpha');
360 $filter_category_supplier =
GETPOST(
'filter_category_supplier',
'alpha');
361 $filter_lang =
GETPOST(
'filter_lang',
'alpha');
366 $prospectlevel = array();
367 $sql =
"SELECT code, label";
368 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
369 $sql .=
" WHERE active > 0";
370 $sql .=
" ORDER BY label";
371 $resql = $this->db->query($sql);
373 $num = $this->db->num_rows($resql);
376 $obj = $this->db->fetch_object($resql);
377 $prospectlevel[$obj->code] = $obj->label;
385 $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,";
386 $sql .=
" s.nom as companyname";
387 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
388 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = sp.fk_soc";
389 if ($filter_category !=
'all' && $filter_category !=
'-1') {
390 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c";
391 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_contact as cs";
393 if ($filter_category_customer !=
'all' && $filter_category_customer !=
'-1') {
394 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c2";
395 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_societe as c2s";
397 if ($filter_category_supplier !=
'all' && $filter_category_supplier !=
'-1') {
398 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c3";
399 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_fournisseur as c3s";
401 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
402 $sql .=
" AND sp.email <> ''";
404 if (empty($this->evenunsubscribe)) {
405 $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).
")";
408 $sql .=
" AND sp.statut = 1";
409 $sql .=
" AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
412 if ($filter_category !=
'all' && $filter_category !=
'-1') {
413 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid";
414 $sql .=
" AND c.label = '".$this->db->escape($filter_category).
"'";
416 if ($filter_category_customer !=
'all' && $filter_category_customer !=
'-1') {
417 $sql .=
" AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc";
418 $sql .=
" AND c2.label = '".$this->db->escape($filter_category_customer).
"'";
420 if ($filter_category_supplier !=
'all' && $filter_category_supplier !=
'-1') {
421 $sql .=
" AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc";
422 $sql .=
" AND c3.label = '".$this->db->escape($filter_category_supplier).
"'";
426 if (!empty($filter_lang) && $filter_lang !=
'-1') {
427 $sql .=
" AND sp.default_lang LIKE '".$this->db->escape($filter_lang).
"%'";
434 if ($key ==
'prospects') {
435 $sql .=
" AND s.client = 2";
437 foreach ($prospectlevel as $codelevel => $valuelevel) {
438 if ($key ==
'prospectslevel'.$codelevel) {
439 $sql .=
" AND s.fk_prospectlevel = '".$this->db->escape($codelevel).
"'";
442 if ($key ==
'customers') {
443 $sql .=
" AND s.client = 1";
445 if ($key ==
'suppliers') {
446 $sql .=
" AND s.fournisseur = 1";
450 $key = $filter_jobposition;
451 if (!empty($key) && $key !=
'all' && $key !=
'-1') {
452 $sql .=
" AND sp.poste = '".$this->db->escape($key).
"'";
455 $sql .=
" ORDER BY sp.email";
459 $result = $this->db->query($sql);
461 $num = $this->db->num_rows($result);
465 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
469 $obj = $this->db->fetch_object($result);
470 if ($old != $obj->email) {
472 'email' => $obj->email,
473 'fk_contact' => (
int) $obj->fk_contact,
474 'lastname' => $obj->lastname,
475 'firstname' => $obj->firstname,
477 ($langs->transnoentities(
"ThirdParty").
'='.$obj->companyname).
';'.
478 ($langs->transnoentities(
"UserTitle").
'='.($obj->civility_id ? $langs->transnoentities(
"Civility".$obj->civility_id) :
'')).
';'.
479 ($langs->transnoentities(
"PostOrFunction").
'='.$obj->jobposition),
480 'source_url' => $this->
url($obj->id),
481 'source_id' => (int) $obj->id,
482 'source_type' =>
'contact'
492 $this->error = $this->db->error();
496 return parent::addTargetsToDatabase($mailing_id, $cibles);
$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='')
Convert a html select field into an ajax combobox.
Parent class of emailing target selectors modules.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
getDolGlobalInt($key, $default=0)
Return a 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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...