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 .=
'<span class="nowraponall">';
325 $s .=
img_picto($langs->trans(
"DefaultLang"),
'language',
'class="pictofixedwidth"');
326 $s .= $formadmin->select_language(
GETPOST(
'filter_lang',
'aZ09'),
'filter_lang', 0, array(), $langs->trans(
"DefaultLang"), 0, 0,
'', 0, 0, 0, array(), 1);
342 return '<a href="'.DOL_URL_ROOT.
'/contact/card.php?id='.
$id.
'">'.
img_object(
'',
"contact").
'</a>';
356 global
$conf, $langs;
358 $filter =
GETPOST(
'filter',
'alpha');
359 $filter_jobposition =
GETPOST(
'filter_jobposition',
'alpha');
360 $filter_category =
GETPOST(
'filter_category',
'alpha');
361 $filter_category_customer =
GETPOST(
'filter_category_customer',
'alpha');
362 $filter_category_supplier =
GETPOST(
'filter_category_supplier',
'alpha');
363 $filter_lang =
GETPOST(
'filter_lang',
'alpha');
368 $prospectlevel = array();
369 $sql =
"SELECT code, label";
370 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
371 $sql .=
" WHERE active > 0";
372 $sql .=
" ORDER BY label";
373 $resql = $this->db->query($sql);
375 $num = $this->db->num_rows($resql);
378 $obj = $this->db->fetch_object($resql);
379 $prospectlevel[$obj->code] = $obj->label;
387 $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,";
388 $sql .=
" s.nom as companyname";
389 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
390 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = sp.fk_soc";
391 if ($filter_category !=
'all' && $filter_category !=
'-1') {
392 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c";
393 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_contact as cs";
395 if ($filter_category_customer !=
'all' && $filter_category_customer !=
'-1') {
396 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c2";
397 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_societe as c2s";
399 if ($filter_category_supplier !=
'all' && $filter_category_supplier !=
'-1') {
400 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c3";
401 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_fournisseur as c3s";
403 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
404 $sql .=
" AND sp.email <> ''";
406 if (empty($this->evenunsubscribe)) {
407 $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).
")";
410 $sql .=
" AND sp.statut = 1";
411 $sql .=
" AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
414 if ($filter_category !=
'all' && $filter_category !=
'-1') {
415 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid";
416 $sql .=
" AND c.label = '".$this->db->escape($filter_category).
"'";
418 if ($filter_category_customer !=
'all' && $filter_category_customer !=
'-1') {
419 $sql .=
" AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc";
420 $sql .=
" AND c2.label = '".$this->db->escape($filter_category_customer).
"'";
422 if ($filter_category_supplier !=
'all' && $filter_category_supplier !=
'-1') {
423 $sql .=
" AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc";
424 $sql .=
" AND c3.label = '".$this->db->escape($filter_category_supplier).
"'";
428 if (!empty($filter_lang) && $filter_lang !=
'-1') {
429 $sql .=
" AND sp.default_lang LIKE '".$this->db->escape($filter_lang).
"%'";
436 if ($key ==
'prospects') {
437 $sql .=
" AND s.client = 2";
439 foreach ($prospectlevel as $codelevel => $valuelevel) {
440 if ($key ==
'prospectslevel'.$codelevel) {
441 $sql .=
" AND s.fk_prospectlevel = '".$this->db->escape($codelevel).
"'";
444 if ($key ==
'customers') {
445 $sql .=
" AND s.client = 1";
447 if ($key ==
'suppliers') {
448 $sql .=
" AND s.fournisseur = 1";
452 $key = $filter_jobposition;
453 if (!empty($key) && $key !=
'all' && $key !=
'-1') {
454 $sql .=
" AND sp.poste = '".$this->db->escape($key).
"'";
457 $sql .=
" ORDER BY sp.email";
461 $result = $this->db->query($sql);
463 $num = $this->db->num_rows($result);
467 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
471 $obj = $this->db->fetch_object($result);
472 if ($old != $obj->email) {
474 'email' => $obj->email,
475 'fk_contact' => (
int) $obj->fk_contact,
476 'lastname' => $obj->lastname,
477 'firstname' => $obj->firstname,
479 ($langs->transnoentities(
"ThirdParty").
'='.$obj->companyname).
';'.
480 ($langs->transnoentities(
"UserTitle").
'='.($obj->civility_id ? $langs->transnoentities(
"Civility".$obj->civility_id) :
'')).
';'.
481 ($langs->transnoentities(
"PostOrFunction").
'='.$obj->jobposition),
482 'source_url' => $this->
url($obj->id),
483 'source_id' => (int) $obj->id,
484 'source_type' =>
'contact'
494 $this->error = $this->db->error();
498 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...