29include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
37 public $name =
'ContactCompanies';
39 public $desc =
'Contacts of thirdparties (prospects, customers, suppliers...)';
40 public $require_module = array(
"societe");
41 public $require_admin = 0;
46 public $enabled =
'isModEnabled("societe")';
51 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 c.statut = 1";
103 $sql =
"SELECT count(distinct(c.email)) as nb";
104 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
105 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc";
106 $sql .=
" WHERE c.entity IN (".getEntity(
'contact').
")";
107 $sql .=
" AND c.email <> ''";
108 if (empty($this->evenunsubscribe)) {
109 $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).
")";
112 $sql .=
" AND c.statut = 1";
115 return parent::getNbOfRecipients($sql);
129 $langs->loadLangs(array(
"commercial",
"companies",
"suppliers",
"categories"));
134 $sql =
"SELECT sp.poste, count(distinct(sp.email)) AS nb";
135 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
136 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
137 $sql .=
" AND sp.email <> ''";
138 $sql .=
" AND sp.statut = 1";
139 $sql .=
" AND (sp.poste IS NOT NULL AND sp.poste <> '')";
140 $sql .=
" GROUP BY sp.poste";
141 $sql .=
" ORDER BY sp.poste";
142 $resql = $this->db->query($sql);
144 $s .=
'<select id="filter_jobposition_contact" name="filter_jobposition" class="flat maxwidth200" placeholder="'.dol_escape_htmltag($langs->trans(
"PostOrFunction")).
'">';
145 $s .=
'<option value="-1">'.$langs->trans(
"PostOrFunction").
'</option>';
147 $num = $this->db->num_rows($resql);
151 $obj = $this->db->fetch_object($resql);
152 $s .=
'<option value="'.dol_escape_htmltag($obj->poste).
'">'.
dol_escape_htmltag($obj->poste).
' ('.$obj->nb.
')</option>';
156 $s .=
'<option disabled="disabled" value="">'.$langs->trans(
"None").
'</option>';
166 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
168 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
169 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
170 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_contact as cs";
171 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
172 $sql .=
" AND sp.email <> ''";
173 $sql .=
" AND sp.statut = 1";
174 $sql .=
" AND cs.fk_categorie = c.rowid";
175 $sql .=
" AND cs.fk_socpeople = sp.rowid";
176 $sql .=
" GROUP BY c.label";
177 $sql .=
" ORDER BY c.label";
178 $resql = $this->db->query($sql);
180 $s .=
'<select id="filter_category_contact" name="filter_category" class="flat maxwidth200">';
181 $s .=
'<option value="-1">'.$langs->trans(
"ContactCategoriesShort").
'</option>';
183 $num = $this->db->num_rows($resql);
187 $obj = $this->db->fetch_object($resql);
188 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
192 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactWithCategoryFound").
'</option>';
202 $s .=
'<select id="filter_contact" name="filter" class="flat maxwidth200">';
203 $sql =
"SELECT code, label";
204 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
205 $sql .=
" WHERE active > 0";
206 $sql .=
" ORDER BY label";
207 $resql = $this->db->query($sql);
209 $num = $this->db->num_rows($resql);
211 $s .=
'<option value="-1">'.$langs->trans(
"NatureOfThirdParty").
'</option>';
213 $s .=
'<option value="-1">'.$langs->trans(
"ContactsAllShort").
'</option>';
215 $s .=
'<option value="prospects">'.$langs->trans(
"ThirdPartyProspects").
'</option>';
219 $obj = $this->db->fetch_object($resql);
220 $level = $langs->trans($obj->code);
221 if ($level == $obj->code) {
222 $level = $langs->trans($obj->label);
224 $labeltoshow = $langs->trans(
"ThirdPartyProspects").
' <span class="opacitymedium">('.$langs->trans(
"ProspectLevelShort").
'='.$level.
')</span>';
225 $s .=
'<option value="prospectslevel'.$obj->code.
'" data-html="'.
dol_escape_htmltag($labeltoshow).
'">'.$labeltoshow.
'</option>';
231 $s .=
'<option value="customers">'.$langs->trans(
"ThirdPartyCustomers").
'</option>';
233 $s .=
'<option value="suppliers">'.$langs->trans(
"ThirdPartySuppliers").
'</option>';
240 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
242 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
243 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
244 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_societe as cs";
245 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
246 $sql .=
" AND sp.email <> ''";
247 $sql .=
" AND sp.statut = 1";
248 $sql .=
" AND cs.fk_categorie = c.rowid";
249 $sql .=
" AND cs.fk_soc = sp.fk_soc";
250 $sql .=
" GROUP BY c.label";
251 $sql .=
" ORDER BY c.label";
252 $resql = $this->db->query($sql);
254 $s .=
'<select id="filter_category_customer_contact" name="filter_category_customer" class="flat maxwidth200">';
255 $s .=
'<option value="-1">'.$langs->trans(
"CustomersProspectsCategoriesShort").
'</option>';
257 $num = $this->db->num_rows($resql);
261 $obj = $this->db->fetch_object($resql);
262 $s .=
'<option value="'.$obj->label.
'">'.$obj->label.
' ('.$obj->nb.
')</option>';
266 $s .=
'<option value="-1" disabled="disabled">'.$langs->trans(
"NoContactLinkedToThirdpartieWithCategoryFound").
'</option>';
277 $sql =
"SELECT c.label, count(distinct(sp.email)) AS nb";
279 $sql .=
" ".MAIN_DB_PREFIX.
"socpeople as sp,";
280 $sql .=
" ".MAIN_DB_PREFIX.
"categorie as c,";
281 $sql .=
" ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs";
282 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
283 $sql .=
" AND sp.email <> ''";
284 $sql .=
" AND sp.statut = 1";
285 $sql .=
" AND cs.fk_categorie = c.rowid";
286 $sql .=
" AND cs.fk_soc = sp.fk_soc";
287 $sql .=
" GROUP BY c.label";
288 $sql .=
" ORDER BY c.label";
289 $resql = $this->db->query($sql);
291 $s .=
'<select id="filter_category_supplier_contact" name="filter_category_supplier" class="flat maxwidth200">';
292 $s .=
'<option value="-1">'.$langs->trans(
"SuppliersCategoriesShort").
'</option>';
294 $num = $this->db->num_rows($resql);
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>';
314 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
316 $s .=
img_picto($langs->trans(
"DefaultLang"),
'language',
'class="pictofixedwidth"');
317 $s .= $formadmin->select_language(
GETPOST(
'filter_lang',
'aZ09'),
'filter_lang', 0,
null, $langs->trans(
"DefaultLang"), 0, 0,
'', 0, 0, 0,
null, 1);
332 return '<a href="'.DOL_URL_ROOT.
'/contact/card.php?id='.
$id.
'">'.
img_object(
'',
"contact").
'</a>';
346 global
$conf, $langs;
348 $filter =
GETPOST(
'filter',
'alpha');
349 $filter_jobposition =
GETPOST(
'filter_jobposition',
'alpha');
350 $filter_category =
GETPOST(
'filter_category',
'alpha');
351 $filter_category_customer =
GETPOST(
'filter_category_customer',
'alpha');
352 $filter_category_supplier =
GETPOST(
'filter_category_supplier',
'alpha');
353 $filter_lang =
GETPOST(
'filter_lang',
'alpha');
358 $prospectlevel = array();
359 $sql =
"SELECT code, label";
360 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_prospectlevel";
361 $sql .=
" WHERE active > 0";
362 $sql .=
" ORDER BY label";
363 $resql = $this->db->query($sql);
365 $num = $this->db->num_rows($resql);
368 $obj = $this->db->fetch_object($resql);
369 $prospectlevel[$obj->code] = $obj->label;
377 $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,";
378 $sql .=
" s.nom as companyname";
379 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
380 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = sp.fk_soc";
381 if ($filter_category !=
'all' && $filter_category !=
'-1') {
382 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c";
383 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_contact as cs";
385 if ($filter_category_customer !=
'all' && $filter_category_customer !=
'-1') {
386 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c2";
387 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_societe as c2s";
389 if ($filter_category_supplier !=
'all' && $filter_category_supplier !=
'-1') {
390 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c3";
391 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_fournisseur as c3s";
393 $sql .=
" WHERE sp.entity IN (".getEntity(
'contact').
")";
394 $sql .=
" AND sp.email <> ''";
396 if (empty($this->evenunsubscribe)) {
397 $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).
")";
400 $sql .=
" AND sp.statut = 1";
401 $sql .=
" AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
404 if ($filter_category !=
'all' && $filter_category !=
'-1') {
405 $sql .=
" AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid";
406 $sql .=
" AND c.label = '".$this->db->escape($filter_category).
"'";
408 if ($filter_category_customer !=
'all' && $filter_category_customer !=
'-1') {
409 $sql .=
" AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc";
410 $sql .=
" AND c2.label = '".$this->db->escape($filter_category_customer).
"'";
412 if ($filter_category_supplier !=
'all' && $filter_category_supplier !=
'-1') {
413 $sql .=
" AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc";
414 $sql .=
" AND c3.label = '".$this->db->escape($filter_category_supplier).
"'";
418 if (!empty($filter_lang) && $filter_lang !=
'-1') {
419 $sql .=
" AND sp.default_lang LIKE '".$this->db->escape($filter_lang).
"%'";
426 if ($key ==
'prospects') {
427 $sql .=
" AND s.client = 2";
429 foreach ($prospectlevel as $codelevel => $valuelevel) {
430 if ($key ==
'prospectslevel'.$codelevel) {
431 $sql .=
" AND s.fk_prospectlevel = '".$this->db->escape($codelevel).
"'";
434 if ($key ==
'customers') {
435 $sql .=
" AND s.client = 1";
437 if ($key ==
'suppliers') {
438 $sql .=
" AND s.fournisseur = 1";
442 $key = $filter_jobposition;
443 if (!empty($key) && $key !=
'all' && $key !=
'-1') {
444 $sql .=
" AND sp.poste = '".$this->db->escape($key).
"'";
447 $sql .=
" ORDER BY sp.email";
451 $result = $this->db->query($sql);
453 $num = $this->db->num_rows($result);
457 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
461 $obj = $this->db->fetch_object($result);
462 if ($old != $obj->email) {
464 'email' => $obj->email,
465 'fk_contact' => (
int) $obj->fk_contact,
466 'lastname' => $obj->lastname,
467 'firstname' => $obj->firstname,
469 ($langs->transnoentities(
"ThirdParty").
'='.$obj->companyname).
';'.
470 ($langs->transnoentities(
"UserTitle").
'='.($obj->civility_id ? $langs->transnoentities(
"Civility".$obj->civility_id) :
'')).
';'.
471 ($langs->transnoentities(
"PostOrFunction").
'='.$obj->jobposition),
472 'source_url' => $this->
url($obj->id),
473 'source_id' => (int) $obj->id,
474 'source_type' =>
'contact'
484 $this->error = $this->db->error();
488 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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...