Go to the documentation of this file.
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";
104 $sql =
"SELECT count(distinct(c.email)) as nb";
105 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
106 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc";
107 $sql .=
" WHERE c.entity IN (".getEntity(
'contact').
")";
108 $sql .=
" AND c.email <> ''";
109 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = c.email) = 0";
111 $sql .=
" AND c.statut = 1";
114 return parent::getNbOfRecipients($sql);
128 $langs->loadLangs(array(
"commercial",
"companies",
"suppliers",
"categories"));
133 $sql =
"SELECT sp.poste, count(distinct(sp.email)) AS nb";
134 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
135 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
136 $sql .=
" AND sp.email <> ''";
137 $sql .=
" AND sp.statut = 1";
138 $sql .=
" AND (sp.poste IS NOT NULL AND sp.poste <> '')";
139 $sql .=
" GROUP BY sp.poste";
140 $sql .=
" ORDER BY sp.poste";
143 $s .=
'<select id="filter_jobposition_contact" name="filter_jobposition" class="flat" placeholder="'.dol_escape_htmltag($langs->trans(
"PostOrFunction")).
'">';
144 $s .=
'<option value="-1">'.$langs->trans(
"PostOrFunction").
'</option>';
150 $obj = $this->
db->fetch_object(
$resql);
151 $s .=
'<option value="'.dol_escape_htmltag($obj->poste).
'">'.
dol_escape_htmltag($obj->poste).
' ('.$obj->nb.
')</option>';
155 $s .=
'<option disabled="disabled" value="">'.$langs->trans(
"None").
'</option>';
165 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
167 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
168 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
169 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_contact as cs";
170 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
171 $sql .=
" AND sp.email <> ''";
172 $sql .=
" AND sp.statut = 1";
173 $sql .=
" AND cs.fk_categorie = c.rowid";
174 $sql .=
" AND cs.fk_socpeople = sp.rowid";
175 $sql .=
" GROUP BY c.label";
176 $sql .=
" ORDER BY c.label";
179 $s .=
'<select id="filter_category_contact" name="filter_category" class="flat">';
180 $s .=
'<option value="-1">'.$langs->trans(
"ContactCategoriesShort").
'</option>';
186 $obj = $this->
db->fetch_object(
$resql);
187 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
191 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactWithCategoryFound").
'</option>';
201 $s .=
'<select id="filter_contact" name="filter" class="flat">';
202 $sql =
"SELECT code, label";
203 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
204 $sql .=
" WHERE active > 0";
205 $sql .=
" ORDER BY label";
210 $s .=
'<option value="-1">'.$langs->trans(
"NatureOfThirdParty").
'</option>';
212 $s .=
'<option value="-1">'.$langs->trans(
"ContactsAllShort").
'</option>';
214 $s .=
'<option value="prospects">'.$langs->trans(
"ThirdPartyProspects").
'</option>';
218 $obj = $this->
db->fetch_object(
$resql);
219 $level = $langs->trans($obj->code);
220 if ($level == $obj->code) {
221 $level = $langs->trans($obj->label);
223 $s .=
'<option value="prospectslevel'.$obj->code.
'">'.$langs->trans(
"ThirdPartyProspects").
' ('.$langs->trans(
"ProspectLevelShort").
'='.$level.
')</option>';
229 $s .=
'<option value="customers">'.$langs->trans(
"ThirdPartyCustomers").
'</option>';
231 $s .=
'<option value="suppliers">'.$langs->trans(
"ThirdPartySuppliers").
'</option>';
238 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
240 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
241 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
242 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_societe as cs";
243 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
244 $sql .=
" AND sp.email <> ''";
245 $sql .=
" AND sp.statut = 1";
246 $sql .=
" AND cs.fk_categorie = c.rowid";
247 $sql .=
" AND cs.fk_soc = sp.fk_soc";
248 $sql .=
" GROUP BY c.label";
249 $sql .=
" ORDER BY c.label";
252 $s .=
'<select id="filter_category_customer_contact" name="filter_category_customer" class="flat maxwidth200">';
253 $s .=
'<option value="-1">'.$langs->trans(
"CustomersProspectsCategoriesShort").
'</option>';
259 $obj = $this->
db->fetch_object(
$resql);
260 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
264 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactLinkedToThirdpartieWithCategoryFound").
'</option>';
275 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
277 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
278 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
279 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
280 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
281 $sql .=
" AND sp.email <> ''";
282 $sql .=
" AND sp.statut = 1";
283 $sql .=
" AND cs.fk_categorie = c.rowid";
284 $sql .=
" AND cs.fk_soc = sp.fk_soc";
285 $sql .=
" GROUP BY c.label";
286 $sql .=
" ORDER BY c.label";
289 $s .=
'<select id="filter_category_supplier_contact" name="filter_category_supplier" class="flat maxwidth200">';
290 $s .=
'<option value="-1">'.$langs->trans(
"SuppliersCategoriesShort").
'</option>';
296 $obj = $this->
db->fetch_object(
$resql);
297 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
301 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactLinkedToThirdpartieWithCategoryFound").
'</option>';
312 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
314 $s .=
'<span class="opacitymedium">'.$langs->trans(
"DefaultLang").
':</span> ';
315 $s .= $formadmin->select_language($langs->getDefaultLang(1),
'filter_lang', 0, 0, 1, 0, 0,
'', 0, 0, 0,
null, 1);
330 return '<a href="'.DOL_URL_ROOT.
'/contact/card.php?id='.$id.
'">'.
img_object(
'',
"contact").
'</a>';
344 global $conf, $langs;
346 $filter =
GETPOST(
'filter',
'alpha');
347 $filter_jobposition =
GETPOST(
'filter_jobposition',
'alpha');
348 $filter_category =
GETPOST(
'filter_category',
'alpha');
349 $filter_category_customer =
GETPOST(
'filter_category_customer',
'alpha');
350 $filter_category_supplier =
GETPOST(
'filter_category_supplier',
'alpha');
351 $filter_lang =
GETPOST(
'filter_lang',
'alpha');
356 $prospectlevel = array();
357 $sql =
"SELECT code, label";
358 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
359 $sql .=
" WHERE active > 0";
360 $sql .=
" ORDER BY label";
366 $obj = $this->
db->fetch_object(
$resql);
367 $prospectlevel[$obj->code] = $obj->label;
375 $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,";
376 $sql .=
" s.nom as companyname";
377 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
378 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = sp.fk_soc";
379 if ($filter_category !=
'all' && $filter_category !=
'-1') {
380 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c";
381 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_contact as cs";
383 if ($filter_category_customer !=
'all' && $filter_category_customer !=
'-1') {
384 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c2";
385 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_societe as c2s";
387 if ($filter_category_supplier !=
'all' && $filter_category_supplier !=
'-1') {
388 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c3";
389 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_fournisseur as c3s";
391 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
392 $sql .=
" AND sp.email <> ''";
394 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = sp.email) = 0";
396 $sql .=
" AND sp.statut = 1";
397 $sql .=
" AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
400 if ($filter_category !=
'all' && $filter_category !=
'-1') {
401 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid";
402 $sql .=
" AND c.label = '".$this->db->escape($filter_category).
"'";
404 if ($filter_category_customer !=
'all' && $filter_category_customer !=
'-1') {
405 $sql .=
" AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc";
406 $sql .=
" AND c2.label = '".$this->db->escape($filter_category_customer).
"'";
408 if ($filter_category_supplier !=
'all' && $filter_category_supplier !=
'-1') {
409 $sql .=
" AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc";
410 $sql .=
" AND c3.label = '".$this->db->escape($filter_category_supplier).
"'";
414 if (!empty($filter_lang)) {
415 $sql .=
" AND sp.default_lang LIKE '".$this->db->escape($filter_lang).
"%'";
422 if ($key ==
'prospects') {
423 $sql .=
" AND s.client = 2";
425 foreach ($prospectlevel as $codelevel => $valuelevel) {
426 if ($key ==
'prospectslevel'.$codelevel) {
427 $sql .=
" AND s.fk_prospectlevel = '".$this->db->escape($codelevel).
"'";
430 if ($key ==
'customers') {
431 $sql .=
" AND s.client = 1";
433 if ($key ==
'suppliers') {
434 $sql .=
" AND s.fournisseur = 1";
438 $key = $filter_jobposition;
439 if (!empty($key) && $key !=
'all' && $key !=
'-1') {
440 $sql .=
" AND sp.poste = '".$this->db->escape($key).
"'";
443 $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);
$conf db
API class for accounts.
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.
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='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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_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)
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.