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;
44 public $picto =
'contact';
75 $langs->load(
"commercial");
78 $statssql[0] =
"SELECT '".$this->db->escape($langs->trans(
"NbOfCompaniesContacts")).
"' as label,";
79 $statssql[0] .=
" count(distinct(c.email)) as nb";
80 $statssql[0] .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
81 $statssql[0] .=
" WHERE c.entity IN (".getEntity(
'socpeople').
")";
82 $statssql[0] .=
" AND c.email != ''";
83 $statssql[0] .=
" AND c.no_email = 0";
84 $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(
'socpeople').
")";
106 $sql .=
" AND c.email != ''";
107 $sql .=
" AND c.no_email = 0";
108 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = c.email) = 0";
110 $sql .=
" AND c.statut = 1";
113 return parent::getNbOfRecipients($sql);
127 $langs->loadLangs(array(
"commercial",
"companies",
"suppliers",
"categories"));
132 $sql =
"SELECT sp.poste, count(distinct(sp.email)) AS nb";
133 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
134 $sql .=
" WHERE sp.entity IN (".getEntity(
'socpeople').
")";
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 .= $langs->trans(
"PostOrFunction").
': ';
144 $s .=
'<select name="filter_jobposition" class="flat">';
145 $s .=
'<option value="all"> </option>';
152 $obj = $this->
db->fetch_object(
$resql);
153 $s .=
'<option value="'.dol_escape_htmltag($obj->poste).
'">'.
dol_escape_htmltag($obj->poste).
' ('.$obj->nb.
')</option>';
162 $s .= $langs->trans(
"ContactCategoriesShort").
': ';
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.statut = 1";
172 $sql .=
" AND cs.fk_categorie = c.rowid";
173 $sql .=
" AND cs.fk_socpeople = sp.rowid";
174 $sql .=
" GROUP BY c.label";
175 $sql .=
" ORDER BY c.label";
178 $s .=
'<select name="filter_category" class="flat">';
179 $s .=
'<option value="all"> </option>';
188 $obj = $this->
db->fetch_object(
$resql);
189 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
193 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactWithCategoryFound").
'</option>';
201 $s .= $langs->trans(
"NatureOfThirdParty").
': ';
202 $s .=
'<select name="filter" class="flat">';
203 $sql =
"SELECT code, label";
204 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
205 $sql .=
" WHERE active > 0";
206 $sql .=
" ORDER BY label";
211 if ($num) $s .=
'<option value="all"> </option>';
212 else $s .=
'<option value="all">'.$langs->trans(
"ContactsAllShort").
'</option>';
213 $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) $level = $langs->trans($obj->label);
221 $s .=
'<option value="prospectslevel'.$obj->code.
'">'.$langs->trans(
"ThirdPartyProspects").
' ('.$langs->trans(
"ProspectLevelShort").
'='.$level.
')</option>';
225 $s .=
'<option value="customers">'.$langs->trans(
"ThirdPartyCustomers").
'</option>';
227 $s .=
'<option value="suppliers">'.$langs->trans(
"ThirdPartySuppliers").
'</option>';
233 $s .= $langs->trans(
"CustomersProspectsCategoriesShort").
': ';
234 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
236 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
237 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
238 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_societe as cs";
239 $sql .=
" WHERE 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";
249 $s .=
'<select name="filter_category_customer" class="flat">';
250 $s .=
'<option value="all"> </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>';
272 $s .= $langs->trans(
"SuppliersCategoriesShort").
': ';
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.statut = 1";
282 $sql .=
" AND cs.fk_categorie = c.rowid";
283 $sql .=
" AND cs.fk_soc = sp.fk_soc";
284 $sql .=
" GROUP BY c.label";
285 $sql .=
" ORDER BY c.label";
288 $s .=
'<select name="filter_category_supplier" class="flat">';
289 $s .=
'<option value="all"> </option>';
298 $obj = $this->
db->fetch_object(
$resql);
299 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
303 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactLinkedToThirdpartieWithCategoryFound").
'</option>';
320 return '<a href="'.DOL_URL_ROOT.
'/contact/card.php?id='.$id.
'">'.
img_object(
'',
"contact").
'</a>';
334 global $conf, $langs;
336 $filter =
GETPOST(
'filter',
'alpha');
337 $filter_jobposition =
GETPOST(
'filter_jobposition',
'alpha');
338 $filter_category =
GETPOST(
'filter_category',
'alpha');
339 $filter_category_customer =
GETPOST(
'filter_category_customer',
'alpha');
340 $filter_category_supplier =
GETPOST(
'filter_category_supplier',
'alpha');
345 $prospectlevel = array();
346 $sql =
"SELECT code, label";
347 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
348 $sql .=
" WHERE active > 0";
349 $sql .=
" ORDER BY label";
357 $obj = $this->
db->fetch_object(
$resql);
358 $prospectlevel[$obj->code] = $obj->label;
364 $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,";
365 $sql .=
" s.nom as companyname";
366 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
367 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = sp.fk_soc";
368 if ($filter_category <>
'all') $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c";
369 if ($filter_category <>
'all') $sql .=
", ".MAIN_DB_PREFIX.
"categorie_contact as cs";
370 if ($filter_category_customer <>
'all') $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c2";
371 if ($filter_category_customer <>
'all') $sql .=
", ".MAIN_DB_PREFIX.
"categorie_societe as c2s";
372 if ($filter_category_supplier <>
'all') $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c3";
373 if ($filter_category_supplier <>
'all') $sql .=
", ".MAIN_DB_PREFIX.
"categorie_fournisseur as c3s";
374 $sql .=
" WHERE sp.entity IN (".getEntity(
'socpeople').
")";
375 $sql .=
" AND sp.email <> ''";
376 $sql .=
" AND sp.no_email = 0";
377 $sql .=
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = sp.email) = 0";
379 $sql .=
" AND sp.statut = 1";
380 $sql .=
" AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".$mailing_id.
")";
382 if ($filter_category <>
'all') $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid";
383 if ($filter_category <>
'all') $sql .=
" AND c.label = '".$this->db->escape($filter_category).
"'";
384 if ($filter_category_customer <>
'all') $sql .=
" AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc";
385 if ($filter_category_customer <>
'all') $sql .=
" AND c2.label = '".$this->db->escape($filter_category_customer).
"'";
386 if ($filter_category_supplier <>
'all') $sql .=
" AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc";
387 if ($filter_category_supplier <>
'all') $sql .=
" AND c3.label = '".$this->db->escape($filter_category_supplier).
"'";
392 if ($key ==
'prospects') $sql .=
" AND s.client=2";
393 foreach ($prospectlevel as $codelevel=>$valuelevel)
if ($key ==
'prospectslevel'.$codelevel) $sql .=
" AND s.fk_prospectlevel='".$this->db->escape($codelevel).
"'";
394 if ($key ==
'customers') $sql .=
" AND s.client=1";
395 if ($key ==
'suppliers') $sql .=
" AND s.fournisseur=1";
398 $key = $filter_jobposition;
399 if (!empty($key) && $key !=
'all') $sql .=
" AND sp.poste ='".$this->db->escape($key).
"'";
400 $sql .=
" ORDER BY sp.email";
404 $result = $this->
db->query($sql);
407 $num = $this->
db->num_rows($result);
411 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
416 $obj = $this->
db->fetch_object($result);
417 if ($old <> $obj->email)
420 'email' => $obj->email,
421 'fk_contact' => $obj->fk_contact,
422 'lastname' => $obj->lastname,
423 'firstname' => $obj->firstname,
425 ($langs->transnoentities(
"ThirdParty").
'='.$obj->companyname).
';'.
426 ($langs->transnoentities(
"UserTitle").
'='.($obj->civility_id ? $langs->transnoentities(
"Civility".$obj->civility_id) :
'')).
';'.
427 ($langs->transnoentities(
"JobPosition").
'='.$obj->jobposition),
428 'source_url' => $this->
url($obj->id),
429 'source_id' => $obj->id,
430 'source_type' =>
'contact'
440 $this->error = $this->
db->error();
444 return parent::addTargetsToDatabase($mailing_id, $cibles);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
$conf db
API class for accounts.
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)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...