27 include_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';
77 $langs->load(
"commercial");
80 $statssql[0] =
"SELECT '".$this->db->escape($langs->trans(
"NbOfCompaniesContacts")).
"' as label,";
81 $statssql[0] .=
" count(distinct(c.email)) as nb";
82 $statssql[0] .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
83 $statssql[0] .=
" WHERE c.entity IN (".getEntity(
'contact').
")";
84 $statssql[0] .=
" AND c.email <> ''";
85 $statssql[0] .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = c.email) = 0";
86 $statssql[0] .=
" AND c.statut = 1";
102 $sql =
"SELECT count(distinct(c.email)) as nb";
103 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
104 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc";
105 $sql .=
" WHERE c.entity IN (".getEntity(
'contact').
")";
106 $sql .=
" AND c.email <> ''";
107 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = c.email) = 0";
109 $sql .=
" AND c.statut = 1";
112 return parent::getNbOfRecipients($sql);
126 $langs->loadLangs(array(
"commercial",
"companies",
"suppliers",
"categories"));
131 $sql =
"SELECT sp.poste, count(distinct(sp.email)) AS nb";
132 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
133 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
134 $sql .=
" AND sp.email <> ''";
135 $sql .=
" AND sp.statut = 1";
136 $sql .=
" AND (sp.poste IS NOT NULL AND sp.poste <> '')";
137 $sql .=
" GROUP BY sp.poste";
138 $sql .=
" ORDER BY sp.poste";
141 $s .=
'<select id="filter_jobposition_contact" name="filter_jobposition" class="flat" placeholder="'.dol_escape_htmltag($langs->trans(
"PostOrFunction")).
'">';
142 $s .=
'<option value="-1">'.$langs->trans(
"PostOrFunction").
'</option>';
148 $obj = $this->
db->fetch_object(
$resql);
149 $s .=
'<option value="'.dol_escape_htmltag($obj->poste).
'">'.
dol_escape_htmltag($obj->poste).
' ('.$obj->nb.
')</option>';
153 $s .=
'<option disabled="disabled" value="">'.$langs->trans(
"None").
'</option>';
163 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
165 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
166 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
167 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_contact as cs";
168 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
169 $sql .=
" AND sp.email <> ''";
170 $sql .=
" AND sp.statut = 1";
171 $sql .=
" AND cs.fk_categorie = c.rowid";
172 $sql .=
" AND cs.fk_socpeople = sp.rowid";
173 $sql .=
" GROUP BY c.label";
174 $sql .=
" ORDER BY c.label";
177 $s .=
'<select id="filter_category_contact" name="filter_category" class="flat">';
178 $s .=
'<option value="-1">'.$langs->trans(
"ContactCategoriesShort").
'</option>';
184 $obj = $this->
db->fetch_object(
$resql);
185 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
189 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactWithCategoryFound").
'</option>';
199 $s .=
'<select id="filter_contact" name="filter" class="flat">';
200 $sql =
"SELECT code, label";
201 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
202 $sql .=
" WHERE active > 0";
203 $sql .=
" ORDER BY label";
208 $s .=
'<option value="-1">'.$langs->trans(
"NatureOfThirdParty").
'</option>';
210 $s .=
'<option value="-1">'.$langs->trans(
"ContactsAllShort").
'</option>';
212 $s .=
'<option value="prospects">'.$langs->trans(
"ThirdPartyProspects").
'</option>';
216 $obj = $this->
db->fetch_object(
$resql);
217 $level = $langs->trans($obj->code);
218 if ($level == $obj->code) {
219 $level = $langs->trans($obj->label);
221 $s .=
'<option value="prospectslevel'.$obj->code.
'">'.$langs->trans(
"ThirdPartyProspects").
' ('.$langs->trans(
"ProspectLevelShort").
'='.$level.
')</option>';
227 $s .=
'<option value="customers">'.$langs->trans(
"ThirdPartyCustomers").
'</option>';
229 $s .=
'<option value="suppliers">'.$langs->trans(
"ThirdPartySuppliers").
'</option>';
236 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
238 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
239 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
240 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_societe as cs";
241 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
242 $sql .=
" AND sp.email <> ''";
243 $sql .=
" AND sp.statut = 1";
244 $sql .=
" AND cs.fk_categorie = c.rowid";
245 $sql .=
" AND cs.fk_soc = sp.fk_soc";
246 $sql .=
" GROUP BY c.label";
247 $sql .=
" ORDER BY c.label";
250 $s .=
'<select id="filter_category_customer_contact" name="filter_category_customer" class="flat maxwidth200">';
251 $s .=
'<option value="-1">'.$langs->trans(
"CustomersProspectsCategoriesShort").
'</option>';
257 $obj = $this->
db->fetch_object(
$resql);
258 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
262 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactLinkedToThirdpartieWithCategoryFound").
'</option>';
273 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
275 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
276 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
277 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
278 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
279 $sql .=
" AND sp.email <> ''";
280 $sql .=
" AND sp.statut = 1";
281 $sql .=
" AND cs.fk_categorie = c.rowid";
282 $sql .=
" AND cs.fk_soc = sp.fk_soc";
283 $sql .=
" GROUP BY c.label";
284 $sql .=
" ORDER BY c.label";
287 $s .=
'<select id="filter_category_supplier_contact" name="filter_category_supplier" class="flat maxwidth200">';
288 $s .=
'<option value="-1">'.$langs->trans(
"SuppliersCategoriesShort").
'</option>';
294 $obj = $this->
db->fetch_object(
$resql);
295 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
299 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactLinkedToThirdpartieWithCategoryFound").
'</option>';
309 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
311 $s .=
'<span class="opacitymedium">'.$langs->trans(
"DefaultLang").
':</span> ';
312 $s .= $formadmin->select_language($langs->getDefaultLang(1),
'filter_lang', 0, 0, 1, 0, 0,
'', 0, 0, 0,
null, 1);
326 return '<a href="'.DOL_URL_ROOT.
'/contact/card.php?id='.$id.
'">'.
img_object(
'',
"contact").
'</a>';
340 global $conf, $langs;
342 $filter =
GETPOST(
'filter',
'alpha');
343 $filter_jobposition =
GETPOST(
'filter_jobposition',
'alpha');
344 $filter_category =
GETPOST(
'filter_category',
'alpha');
345 $filter_category_customer =
GETPOST(
'filter_category_customer',
'alpha');
346 $filter_category_supplier =
GETPOST(
'filter_category_supplier',
'alpha');
347 $filter_lang =
GETPOST(
'filter_lang',
'alpha');
352 $prospectlevel = array();
353 $sql =
"SELECT code, label";
354 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
355 $sql .=
" WHERE active > 0";
356 $sql .=
" ORDER BY label";
362 $obj = $this->
db->fetch_object(
$resql);
363 $prospectlevel[$obj->code] = $obj->label;
371 $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,";
372 $sql .=
" s.nom as companyname";
373 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
374 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = sp.fk_soc";
375 if ($filter_category !=
'all' && $filter_category !=
'-1') {
376 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c";
377 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_contact as cs";
379 if ($filter_category_customer !=
'all' && $filter_category_customer !=
'-1') {
380 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c2";
381 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_societe as c2s";
383 if ($filter_category_supplier !=
'all' && $filter_category_supplier !=
'-1') {
384 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c3";
385 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_fournisseur as c3s";
387 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
388 $sql .=
" AND sp.email <> ''";
390 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = sp.email) = 0";
392 $sql .=
" AND sp.statut = 1";
393 $sql .=
" AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
396 if ($filter_category !=
'all' && $filter_category !=
'-1') {
397 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid";
398 $sql .=
" AND c.label = '".$this->db->escape($filter_category).
"'";
400 if ($filter_category_customer !=
'all' && $filter_category_customer !=
'-1') {
401 $sql .=
" AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc";
402 $sql .=
" AND c2.label = '".$this->db->escape($filter_category_customer).
"'";
404 if ($filter_category_supplier !=
'all' && $filter_category_supplier !=
'-1') {
405 $sql .=
" AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc";
406 $sql .=
" AND c3.label = '".$this->db->escape($filter_category_supplier).
"'";
410 if (!empty($filter_lang)) {
411 $sql .=
" AND sp.default_lang LIKE '".$this->db->escape($filter_lang).
"%'";
418 if ($key ==
'prospects') {
419 $sql .=
" AND s.client = 2";
421 foreach ($prospectlevel as $codelevel => $valuelevel) {
422 if ($key ==
'prospectslevel'.$codelevel) {
423 $sql .=
" AND s.fk_prospectlevel = '".$this->db->escape($codelevel).
"'";
426 if ($key ==
'customers') {
427 $sql .=
" AND s.client = 1";
429 if ($key ==
'suppliers') {
430 $sql .=
" AND s.fournisseur = 1";
434 $key = $filter_jobposition;
435 if (!empty($key) && $key !=
'all' && $key !=
'-1') {
436 $sql .=
" AND sp.poste = '".$this->db->escape($key).
"'";
439 $sql .=
" ORDER BY sp.email";
442 $result = $this->
db->query($sql);
444 $num = $this->
db->num_rows($result);
448 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
452 $obj = $this->
db->fetch_object($result);
453 if ($old <> $obj->email) {
455 'email' => $obj->email,
456 'fk_contact' => $obj->fk_contact,
457 'lastname' => $obj->lastname,
458 'firstname' => $obj->firstname,
460 ($langs->transnoentities(
"ThirdParty").
'='.$obj->companyname).
';'.
461 ($langs->transnoentities(
"UserTitle").
'='.($obj->civility_id ? $langs->transnoentities(
"Civility".$obj->civility_id) :
'')).
';'.
462 ($langs->transnoentities(
"JobPosition").
'='.$obj->jobposition),
463 'source_url' => $this->url($obj->id),
464 'source_id' => $obj->id,
465 'source_type' =>
'contact'
475 $this->error = $this->
db->error();
479 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.
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_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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)
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.
$conf db
API class for accounts.