39 public $element =
'advtargetemailing';
44 public $table_element =
'advtargetemailing';
74 public $fk_user_author;
94 public $select_target_type = array();
99 public $type_statuscommprospect = array();
100 public $thirdparty_lines;
101 public $contact_lines;
112 $langs->load(
'customers');
116 $this->select_target_type = array(
117 '2' => $langs->trans(
'Contacts'),
118 '1' => $langs->trans(
'Contacts').
'+'.$langs->trans(
'ThirdParty'),
119 '3' => $langs->trans(
'ThirdParty'),
120 '4' => $langs->trans(
'ContactsWithThirdpartyFilter')
122 $this->type_statuscommprospect = array(
123 -1 => $langs->trans(
"StatusProspect-1"),
124 0 => $langs->trans(
"StatusProspect0"),
125 1 => $langs->trans(
"StatusProspect1"),
126 2 => $langs->trans(
"StatusProspect2"),
127 3 => $langs->trans(
"StatusProspect3")
138 public function create($user, $notrigger = 0)
140 global $conf, $langs;
144 if (isset($this->fk_element)) {
145 $this->fk_element = (int) $this->fk_element;
147 if (isset($this->type_element)) {
148 $this->type_element = trim($this->type_element);
151 if (isset($this->
name)) {
154 if (isset($this->filtervalue)) {
155 $this->filtervalue = trim($this->filtervalue);
162 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"advtargetemailing(";
165 $sql .=
"fk_element,";
166 $sql .=
"type_element,";
167 $sql .=
"filtervalue,";
168 $sql .=
"fk_user_author,";
170 $sql .=
"fk_user_mod";
171 $sql .=
") VALUES (";
172 $sql .=
" ".(!isset($this->
name) ?
'NULL' :
"'".$this->db->escape($this->
name).
"'").
",";
173 $sql .=
" ".$conf->entity.
",";
174 $sql .=
" ".(!isset($this->fk_element) ?
'NULL' :
"'".$this->db->escape($this->fk_element).
"'").
",";
175 $sql .=
" ".(!isset($this->type_element) ?
'NULL' :
"'".$this->db->escape($this->type_element).
"'").
",";
176 $sql .=
" ".(!isset($this->filtervalue) ?
'NULL' :
"'".$this->db->escape($this->filtervalue).
"'").
",";
177 $sql .=
" ".$user->id.
",";
178 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
179 $sql .=
" ".$user->id;
184 dol_syslog(get_class($this).
"::create sql=".$sql, LOG_DEBUG);
187 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
191 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"advtargetemailing");
196 foreach ($this->errors as $errmsg) {
197 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
198 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
200 $this->
db->rollback();
221 $sql .=
" t.entity,";
222 $sql .=
" t.fk_element,";
223 $sql .=
" t.type_element,";
224 $sql .=
" t.filtervalue,";
225 $sql .=
" t.fk_user_author,";
227 $sql .=
" t.fk_user_mod,";
230 $sql .=
" FROM ".MAIN_DB_PREFIX.
"advtargetemailing as t";
231 $sql .=
" WHERE t.rowid = ".$id;
233 dol_syslog(get_class($this).
"::fetch sql=".$sql, LOG_DEBUG);
237 $obj = $this->
db->fetch_object(
$resql);
239 $this->
id = $obj->rowid;
241 $this->
name = $obj->name;
242 $this->entity = $obj->entity;
243 $this->fk_element = $obj->fk_element;
244 $this->type_element = $obj->type_element;
245 $this->filtervalue = $obj->filtervalue;
246 $this->fk_user_author = $obj->fk_user_author;
247 $this->datec = $this->
db->jdate($obj->datec);
248 $this->fk_user_mod = $obj->fk_user_mod;
249 $this->tms = $this->
db->jdate($obj->tms);
255 $this->error =
"Error ".$this->db->lasterror();
256 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
276 $sql .=
" t.entity,";
277 $sql .=
" t.fk_element,";
278 $sql .=
" t.type_element,";
279 $sql .=
" t.filtervalue,";
280 $sql .=
" t.fk_user_author,";
282 $sql .=
" t.fk_user_mod,";
285 $sql .=
" FROM ".MAIN_DB_PREFIX.
"advtargetemailing as t";
287 $sql .=
" WHERE t.fk_element = ".$id.
" AND type_element='mailing'";
289 $sql .=
" WHERE t.fk_element = ".$this->fk_element.
" AND type_element='mailing'";
292 dol_syslog(get_class($this).
"::fetch sql=".$sql, LOG_DEBUG);
296 $obj = $this->
db->fetch_object(
$resql);
298 $this->
id = $obj->rowid;
300 $this->
name = $obj->name;
301 $this->entity = $obj->entity;
302 $this->fk_element = $obj->fk_element;
303 $this->type_element = $obj->type_element;
304 $this->filtervalue = $obj->filtervalue;
305 $this->fk_user_author = $obj->fk_user_author;
306 $this->datec = $this->
db->jdate($obj->datec);
307 $this->fk_user_mod = $obj->fk_user_mod;
308 $this->tms = $this->
db->jdate($obj->tms);
314 $this->error =
"Error ".$this->db->lasterror();
315 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
339 $sql .=
" t.entity,";
340 $sql .=
" t.fk_element,";
341 $sql .=
" t.type_element,";
342 $sql .=
" t.filtervalue,";
343 $sql .=
" t.fk_user_author,";
345 $sql .=
" t.fk_user_mod,";
348 $sql .=
" FROM ".MAIN_DB_PREFIX.
"advtargetemailing as t";
350 $sql .=
" WHERE t.fk_element = ".$id.
" AND type_element='$type_element'";
352 $sql .=
" WHERE t.fk_element = ".$this->fk_element.
" AND type_element='$type_element'";
355 dol_syslog(get_class($this).
"::fetch sql=".$sql, LOG_DEBUG);
359 $obj = $this->
db->fetch_object(
$resql);
361 $this->
id = $obj->rowid;
363 $this->
name = $obj->name;
364 $this->entity = $obj->entity;
365 $this->fk_element = $obj->fk_element;
366 $this->type_element = $obj->type_element;
367 $this->filtervalue = $obj->filtervalue;
368 $this->fk_user_author = $obj->fk_user_author;
369 $this->datec = $this->
db->jdate($obj->datec);
370 $this->fk_user_mod = $obj->fk_user_mod;
371 $this->tms = $this->
db->jdate($obj->tms);
377 $this->error =
"Error ".$this->db->lasterror();
378 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
390 public function update($user, $notrigger = 0)
392 global $conf, $langs;
396 if (isset($this->fk_element)) {
397 $this->fk_element = (int) $this->fk_element;
399 if (isset($this->type_element)) {
400 $this->type_element = trim($this->type_element);
402 if (isset($this->
name)) {
405 if (isset($this->filtervalue)) {
406 $this->filtervalue = trim($this->filtervalue);
413 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"advtargetemailing SET";
415 $sql .=
" name=".(isset($this->
name) ?
"'".$this->db->escape($this->
name).
"'" :
"''").
",";
416 $sql .=
" entity=".$conf->entity.
",";
417 $sql .=
" fk_element=".(isset($this->fk_element) ? $this->fk_element :
"null").
",";
418 $sql .=
" type_element=".(isset($this->type_element) ?
"'".$this->db->escape($this->type_element).
"'" :
"null").
",";
419 $sql .=
" filtervalue=".(isset($this->filtervalue) ?
"'".$this->db->escape($this->filtervalue).
"'" :
"null").
",";
420 $sql .=
" fk_user_mod=".$user->id;
422 $sql .=
" WHERE rowid=".$this->id;
425 dol_syslog(get_class($this).
"::update sql=".$sql, LOG_DEBUG);
429 $this->errors[] =
"Error ".$this->db->lasterror();
434 foreach ($this->errors as $errmsg) {
435 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
436 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
438 $this->
db->rollback();
453 public function delete($user, $notrigger = 0)
455 global $conf, $langs;
461 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"advtargetemailing";
462 $sql .=
" WHERE rowid=".$this->id;
464 dol_syslog(get_class($this).
"::delete sql=".$sql);
467 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
473 foreach ($this->errors as $errmsg) {
474 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
475 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
477 $this->
db->rollback();
495 global $langs, $conf;
497 if (!empty($arrayquery)) {
499 $this->filtervalue = json_encode($arrayquery);
503 if (!empty($this->
id)) {
523 global $langs, $conf, $extrafields;
527 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as t";
528 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"societe_extrafields as te ON te.fk_object=t.rowid ";
532 $sqlwhere[] =
't.entity IN ('.getEntity(
'societe').
')';
534 if (count($arrayquery) > 0) {
535 if (array_key_exists(
'cust_saleman', $arrayquery)) {
536 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as saleman ON saleman.fk_soc=t.rowid ";
538 if (array_key_exists(
'cust_categ', $arrayquery)) {
539 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as custcateg ON custcateg.fk_soc=t.rowid ";
542 if (!empty($arrayquery[
'cust_name'])) {
543 $sqlwhere[] = $this->
transformToSQL(
't.nom', $arrayquery[
'cust_name']);
545 if (!empty($arrayquery[
'cust_code'])) {
546 $sqlwhere[] = $this->
transformToSQL(
't.code_client', $arrayquery[
'cust_code']);
548 if (!empty($arrayquery[
'cust_adress'])) {
549 $sqlwhere[] = $this->
transformToSQL(
't.address', $arrayquery[
'cust_adress']);
551 if (!empty($arrayquery[
'cust_zip'])) {
552 $sqlwhere[] = $this->
transformToSQL(
't.zip', $arrayquery[
'cust_zip']);
554 if (!empty($arrayquery[
'cust_city'])) {
555 $sqlwhere[] = $this->
transformToSQL(
't.town', $arrayquery[
'cust_city']);
557 if (!empty($arrayquery[
'cust_mothercompany'])) {
558 $str = $this->
transformToSQL(
'nom', $arrayquery[
'cust_mothercompany']);
559 $sqlwhere[] =
" (t.parent IN (SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe WHERE (".$str.
")))";
561 if (!empty($arrayquery[
'cust_status']) && count($arrayquery[
'cust_status']) > 0) {
562 $sqlwhere[] =
" (t.status IN (".implode(
',', $arrayquery[
'cust_status']).
"))";
564 if (!empty($arrayquery[
'cust_typecust']) && count($arrayquery[
'cust_typecust']) > 0) {
565 $sqlwhere[] =
" (t.client IN (".implode(
',', $arrayquery[
'cust_typecust']).
"))";
567 if (!empty($arrayquery[
'cust_comm_status']) && count($arrayquery[
'cust_comm_status'] > 0)) {
568 $sqlwhere[] =
" (t.fk_stcomm IN (".implode(
',', $arrayquery[
'cust_comm_status']).
"))";
570 if (!empty($arrayquery[
'cust_prospect_status']) && count($arrayquery[
'cust_prospect_status']) > 0) {
571 $sqlwhere[] =
" (t.fk_prospectlevel IN ('".implode(
"','", $arrayquery[
'cust_prospect_status']).
"'))";
573 if (!empty($arrayquery[
'cust_typeent']) && count($arrayquery[
'cust_typeent']) > 0) {
574 $sqlwhere[] =
" (t.fk_typent IN (".implode(
',', $arrayquery[
'cust_typeent']).
"))";
576 if (!empty($arrayquery[
'cust_saleman']) && count($arrayquery[
'cust_saleman']) > 0) {
577 $sqlwhere[] =
" (saleman.fk_user IN (".implode(
',', $arrayquery[
'cust_saleman']).
"))";
579 if (!empty($arrayquery[
'cust_country']) && count($arrayquery[
'cust_country']) > 0) {
580 $sqlwhere[] =
" (t.fk_pays IN (".implode(
',', $arrayquery[
'cust_country']).
"))";
582 if (!empty($arrayquery[
'cust_effectif_id']) && count($arrayquery[
'cust_effectif_id']) > 0) {
583 $sqlwhere[] =
" (t.fk_effectif IN (".implode(
',', $arrayquery[
'cust_effectif_id']).
"))";
585 if (!empty($arrayquery[
'cust_categ']) && count($arrayquery[
'cust_categ']) > 0) {
586 $sqlwhere[] =
" (custcateg.fk_categorie IN (".implode(
',', $arrayquery[
'cust_categ']).
"))";
588 if (!empty($arrayquery[
'cust_language']) && count($arrayquery[
'cust_language']) > 0) {
589 $sqlwhere[] =
" (t.default_lang IN ('".implode(
"','", $arrayquery[
'cust_language']).
"'))";
593 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
595 $elementtype = $socstatic->table_element;
597 $extrafields->fetch_name_optionals_label($elementtype);
599 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $val) {
600 if (($extrafields->attributes[$elementtype][
'type'][$key] ==
'varchar') ||
601 ($extrafields->attributes[$elementtype][
'type'][$key] ==
'text')) {
602 if (!empty($arrayquery[
'options_'.$key])) {
603 $sqlwhere[] =
" (te.".$key.
" LIKE '".$this->
db->escape($arrayquery[
'options_'.$key]).
"')";
605 } elseif (($extrafields->attributes[$elementtype][
'type'][$key] ==
'int') ||
606 ($extrafields->attributes[$elementtype][
'type'][$key] ==
'double')) {
607 if (!empty($arrayquery[
'options_'.$key.
'_max'])) {
608 $sqlwhere[] =
" (te.".$key.
" >= ".$arrayquery[
'options_'.$key.
'_max'].
" AND te.".$key.
" <= ".$arrayquery[
'options_'.$key.
'_min'].
")";
610 } elseif (($extrafields->attributes[$elementtype][
'type'][$key] ==
'date') ||
611 ($extrafields->attributes[$elementtype][
'type'][$key] ==
'datetime')) {
612 if (!empty($arrayquery[
'options_'.$key.
'_end_dt'])) {
613 $sqlwhere[] =
" (te.".$key.
" >= '".$this->
db->idate($arrayquery[
'options_'.$key.
'_st_dt']).
"' AND te.".$key.
" <= '".$this->
db->idate($arrayquery[
'options_'.$key.
'_end_dt']).
"')";
615 } elseif ($extrafields->attributes[$elementtype][
'type'][$key] ==
'boolean') {
616 if ($arrayquery[
'options_'.$key] !=
'') {
617 $sqlwhere[] =
" (te.".$key.
" = ".$arrayquery[
'options_'.$key].
")";
620 if (is_array($arrayquery[
'options_'.$key])) {
621 $sqlwhere[] =
" (te.".$key.
" IN ('".implode(
"','", $arrayquery[
'options_'.$key]).
"'))";
622 } elseif (!empty($arrayquery[
'options_'.$key])) {
623 $sqlwhere[] =
" (te.".$key.
" LIKE '".$this->
db->escape($arrayquery[
'options_'.$key]).
"')";
629 if (count($sqlwhere) > 0) {
630 $sql .=
" WHERE ".implode(
" AND ", $sqlwhere);
635 dol_syslog(get_class($this).
"::query_thirdparty sql=".$sql, LOG_DEBUG);
638 $this->thirdparty_lines = array();
644 $obj = $this->
db->fetch_object(
$resql);
646 $this->thirdparty_lines[$i] = $obj->rowid;
655 $this->error =
"Error ".$this->db->lasterror();
656 dol_syslog(get_class($this).
"::query_thirdparty ".$this->error, LOG_ERR);
672 global $langs, $conf;
676 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as t";
677 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"socpeople_extrafields as te ON te.fk_object=t.rowid ";
679 if (!empty($withThirdpartyFilter)) {
680 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"societe as ts ON ts.rowid=t.fk_soc";
681 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"societe_extrafields as tse ON tse.fk_object=ts.rowid ";
686 $sqlwhere[] =
't.entity IN ('.getEntity(
'socpeople').
')';
688 if (count($arrayquery) > 0) {
689 if (array_key_exists(
'contact_categ', $arrayquery)) {
690 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_contact as contactcateg ON contactcateg.fk_socpeople=t.rowid ";
693 if (!empty($arrayquery[
'contact_lastname'])) {
694 $sqlwhere[] = $this->
transformToSQL(
't.lastname', $arrayquery[
'contact_lastname']);
696 if (!empty($arrayquery[
'contact_firstname'])) {
697 $sqlwhere[] = $this->
transformToSQL(
't.firstname', $arrayquery[
'contact_firstname']);
699 if (!empty($arrayquery[
'contact_country']) && count($arrayquery[
'contact_country'])) {
700 $sqlwhere[] =
" (t.fk_pays IN (".$this->db->sanitize($this->
db->escape(implode(
',', $arrayquery[
'contact_country']))).
"))";
702 if (!empty($arrayquery[
'contact_status']) && count($arrayquery[
'contact_status']) > 0) {
703 $sqlwhere[] =
" (t.statut IN (".$this->db->sanitize($this->
db->escape(implode(
',', $arrayquery[
'contact_status']))).
"))";
705 if (!empty($arrayquery[
'contact_civility']) && count($arrayquery[
'contact_civility']) > 0) {
706 $sqlwhere[] =
" (t.civility IN ('".$this->db->sanitize($this->
db->escape(implode(
"','", $arrayquery[
'contact_civility']))).
"'))";
708 if ($arrayquery[
'contact_no_email'] !=
'') {
710 if (!empty($arrayquery[
'contact_no_email'])) {
711 $tmpwhere .=
"(t.email IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE t.entity IN (".
getEntity(
'mailing').
") AND email = '".$this->
db->escape($arrayquery[
'contact_no_email']).
"'))";
713 $tmpwhere .=
"(t.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE t.entity IN (".
getEntity(
'mailing').
") AND email = '".$this->
db->escape($arrayquery[
'contact_no_email']).
"'))";
715 $sqlwhere[] = $tmpwhere;
717 if ($arrayquery[
'contact_update_st_dt'] !=
'') {
718 $sqlwhere[] =
" (t.tms >= '".$this->db->idate($arrayquery[
'contact_update_st_dt']).
"' AND t.tms <= '".$this->
db->idate($arrayquery[
'contact_update_end_dt']).
"')";
720 if ($arrayquery[
'contact_create_st_dt'] !=
'') {
721 $sqlwhere[] =
" (t.datec >= '".$this->db->idate($arrayquery[
'contact_create_st_dt']).
"' AND t.datec <= '".$this->
db->idate($arrayquery[
'contact_create_end_dt']).
"')";
723 if (!empty($arrayquery[
'contact_categ']) && count($arrayquery[
'contact_categ']) > 0) {
724 $sqlwhere[] =
" (contactcateg.fk_categorie IN (".$this->db->escape(implode(
",", $arrayquery[
'contact_categ'])).
"))";
728 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
730 $elementtype = $contactstatic->table_element;
735 $extrafields->fetch_name_optionals_label($elementtype);
737 $extrafields->fetch_name_optionals_label($elementtype);
739 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $val) {
740 if (($extrafields->attributes[$elementtype][
'type'][$key] ==
'varchar') ||
741 ($extrafields->attributes[$elementtype][
'type'][$key] ==
'text')) {
742 if (!empty($arrayquery[
'options_'.$key.
'_cnct'])) {
743 $sqlwhere[] =
" (te.".$key.
" LIKE '".$this->
db->escape($arrayquery[
'options_'.$key.
'_cnct']).
"')";
745 } elseif (($extrafields->attributes[$elementtype][
'type'][$key] ==
'int') ||
746 ($extrafields->attributes[$elementtype][
'type'][$key] ==
'double')) {
747 if (!empty($arrayquery[
'options_'.$key.
'_max_cnct'])) {
748 $sqlwhere[] =
" (te.".$key.
" >= ".$arrayquery[
'options_'.$key.
'_max_cnct'].
" AND te.".$key.
" <= ".$arrayquery[
'options_'.$key.
'_min_cnct'].
")";
750 } elseif (($extrafields->attributes[$elementtype][
'type'][$key] ==
'date') ||
751 ($extrafields->attributes[$elementtype][
'type'][$key] ==
'datetime')) {
752 if (!empty($arrayquery[
'options_'.$key.
'_end_dt_cnct'])) {
753 $sqlwhere[] =
" (te.".$key.
" >= '".$this->
db->idate($arrayquery[
'options_'.$key.
'_st_dt_cnct']).
"' AND te.".$key.
" <= '".$this->
db->idate($arrayquery[
'options_'.$key.
'_end_dt_cnct']).
"')";
755 } elseif ($extrafields->attributes[$elementtype][
'type'][$key] ==
'boolean') {
756 if ($arrayquery[
'options_'.$key.
'_cnct'] !=
'') {
757 if ($arrayquery[
'options_'.$key.
'_cnct'] == 0) {
758 $sqlwhere[] =
" (te.".$key.
" = ".$arrayquery[
'options_'.$key.
'_cnct'].
" OR ((te.".$key.
" IS NULL) AND (te.fk_object IS NOT NULL)))";
760 $sqlwhere[] =
" (te.".$key.
" = ".$arrayquery[
'options_'.$key.
'_cnct'].
")";
764 if (is_array($arrayquery[
'options_'.$key.
'_cnct'])) {
765 $sqlwhere[] =
" (te.".$key.
" IN ('".implode(
"','", $arrayquery[
'options_'.$key.
'_cnct']).
"'))";
766 } elseif (!empty($arrayquery[
'options_'.$key.
'_cnct'])) {
767 $sqlwhere[] =
" (te.".$key.
" LIKE '".$this->
db->escape($arrayquery[
'options_'.$key.
'_cnct']).
"')";
772 if (!empty($withThirdpartyFilter)) {
773 if (array_key_exists(
'cust_saleman', $arrayquery)) {
774 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as saleman ON saleman.fk_soc=ts.rowid ";
776 if (array_key_exists(
'cust_categ', $arrayquery)) {
777 $sql .=
" LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"categorie_societe as custcateg ON custcateg.fk_soc=ts.rowid ";
780 if (!empty($arrayquery[
'cust_name'])) {
781 $sqlwhere[] = $this->
transformToSQL(
'ts.nom', $arrayquery[
'cust_name']);
783 if (!empty($arrayquery[
'cust_code'])) {
784 $sqlwhere[] = $this->
transformToSQL(
'ts.code_client', $arrayquery[
'cust_code']);
786 if (!empty($arrayquery[
'cust_adress'])) {
787 $sqlwhere[] = $this->
transformToSQL(
'ts.address', $arrayquery[
'cust_adress']);
789 if (!empty($arrayquery[
'cust_zip'])) {
790 $sqlwhere[] = $this->
transformToSQL(
'ts.zip', $arrayquery[
'cust_zip']);
792 if (!empty($arrayquery[
'cust_city'])) {
793 $sqlwhere[] = $this->
transformToSQL(
'ts.town', $arrayquery[
'cust_city']);
795 if (!empty($arrayquery[
'cust_mothercompany'])) {
796 $str = $this->
transformToSQL(
'nom', $arrayquery[
'cust_mothercompany']);
797 $sqlwhere[] =
" (ts.parent IN (SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe WHERE (".$str.
")))";
799 if (!empty($arrayquery[
'cust_status']) && count($arrayquery[
'cust_status']) > 0) {
800 $sqlwhere[] =
" (ts.status IN (".implode(
',', $arrayquery[
'cust_status']).
"))";
802 if (!empty($arrayquery[
'cust_typecust']) && count($arrayquery[
'cust_typecust']) > 0) {
803 $sqlwhere[] =
" (ts.client IN (".implode(
',', $arrayquery[
'cust_typecust']).
"))";
805 if (!empty($arrayquery[
'cust_comm_status']) && count($arrayquery[
'cust_comm_status'] > 0)) {
806 $sqlwhere[] =
" (ts.fk_stcomm IN (".implode(
',', $arrayquery[
'cust_comm_status']).
"))";
808 if (!empty($arrayquery[
'cust_prospect_status']) && count($arrayquery[
'cust_prospect_status']) > 0) {
809 $sqlwhere[] =
" (ts.fk_prospectlevel IN ('".implode(
"','", $arrayquery[
'cust_prospect_status']).
"'))";
811 if (!empty($arrayquery[
'cust_typeent']) && count($arrayquery[
'cust_typeent']) > 0) {
812 $sqlwhere[] =
" (ts.fk_typent IN (".implode(
',', $arrayquery[
'cust_typeent']).
"))";
814 if (!empty($arrayquery[
'cust_saleman']) && count($arrayquery[
'cust_saleman']) > 0) {
815 $sqlwhere[] =
" (saleman.fk_user IN (".implode(
',', $arrayquery[
'cust_saleman']).
"))";
817 if (!empty($arrayquery[
'cust_country']) && count($arrayquery[
'cust_country']) > 0) {
818 $sqlwhere[] =
" (ts.fk_pays IN (".implode(
',', $arrayquery[
'cust_country']).
"))";
820 if (!empty($arrayquery[
'cust_effectif_id']) && count($arrayquery[
'cust_effectif_id']) > 0) {
821 $sqlwhere[] =
" (ts.fk_effectif IN (".implode(
',', $arrayquery[
'cust_effectif_id']).
"))";
823 if (!empty($arrayquery[
'cust_categ']) && count($arrayquery[
'cust_categ']) > 0) {
824 $sqlwhere[] =
" (custcateg.fk_categorie IN (".implode(
',', $arrayquery[
'cust_categ']).
"))";
826 if (!empty($arrayquery[
'cust_language']) && count($arrayquery[
'cust_language']) > 0) {
827 $sqlwhere[] =
" (ts.default_lang IN ('".implode(
"','", $arrayquery[
'cust_language']).
"'))";
831 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
833 $elementtype = $socstatic->table_element;
839 $extrafields->fetch_name_optionals_label($elementtype);
841 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $val) {
842 if (($extrafields->attributes[$elementtype][
'type'][$key] ==
'varchar') ||
843 ($extrafields->attributes[$elementtype][
'type'][$key] ==
'text')) {
844 if (!empty($arrayquery[
'options_'.$key])) {
845 $sqlwhere[] =
" (tse.".$key.
" LIKE '".$this->
db->escape($arrayquery[
'options_'.$key]).
"')";
847 } elseif (($extrafields->attributes[$elementtype][
'type'][$key] ==
'int') ||
848 ($extrafields->attributes[$elementtype][
'type'][$key] ==
'double')) {
849 if (!empty($arrayquery[
'options_'.$key.
'_max'])) {
850 $sqlwhere[] =
" (tse.".$key.
" >= ".$arrayquery[
'options_'.$key.
'_max'].
" AND tse.".$key.
" <= ".$arrayquery[
'options_'.$key.
'_min'].
")";
852 } elseif (($extrafields->attributes[$elementtype][
'type'][$key] ==
'date') ||
853 ($extrafields->attributes[$elementtype][
'type'][$key] ==
'datetime')) {
854 if (!empty($arrayquery[
'options_'.$key.
'_end_dt'])) {
855 $sqlwhere[] =
" (tse.".$key.
" >= '".$this->
db->idate($arrayquery[
'options_'.$key.
'_st_dt']).
"' AND tse.".$key.
" <= '".$this->
db->idate($arrayquery[
'options_'.$key.
'_end_dt']).
"')";
857 } elseif ($extrafields->attributes[$elementtype][
'type'][$key] ==
'boolean') {
858 if ($arrayquery[
'options_'.$key] !=
'') {
859 $sqlwhere[] =
" (tse.".$key.
" = ".$arrayquery[
'options_'.$key].
")";
862 if (is_array($arrayquery[
'options_'.$key])) {
863 $sqlwhere[] =
" (tse.".$key.
" IN ('".implode(
"','", $arrayquery[
'options_'.$key]).
"'))";
864 } elseif (!empty($arrayquery[
'options_'.$key])) {
865 $sqlwhere[] =
" (tse.".$key.
" LIKE '".$this->
db->escape($arrayquery[
'options_'.$key]).
"')";
872 if (count($sqlwhere) > 0) {
873 $sql .=
" WHERE ".implode(
" AND ", $sqlwhere);
877 dol_syslog(get_class($this).
"::query_contact sql=".$sql, LOG_DEBUG);
880 $this->contact_lines = array();
886 $obj = $this->
db->fetch_object(
$resql);
888 $this->contact_lines[$i] = $obj->rowid;
897 $this->error =
"Error ".$this->db->lasterror();
898 dol_syslog(get_class($this).
"::query_contact ".$this->error, LOG_ERR);
915 $return_sql_criteria =
'(';
918 if (preg_match(
'/;/', $criteria)) {
919 $return_sql_not_like = array();
920 $return_sql_like = array();
922 $criteria_array = explode(
';', $criteria);
923 foreach ($criteria_array as $inter_criteria) {
924 if (preg_match(
'/!/', $inter_criteria)) {
925 $return_sql_not_like[] =
'('.$column_to_test.
' NOT LIKE \''.str_replace(
'!',
'', $inter_criteria).
'\')
';
927 $return_sql_like[] = '(
'.$column_to_test.' LIKE \
''.$inter_criteria.
'\')
';
931 if (count($return_sql_like) > 0) {
932 $return_sql_criteria .= '(
'.implode(' OR
', $return_sql_like).')
';
934 if (count($return_sql_not_like) > 0) {
935 $return_sql_criteria .= ' AND (
'.implode(' AND
', $return_sql_not_like).')
';
938 $return_sql_criteria .= $column_to_test.' LIKE \
''.$this->db->escape($criteria).
'\'';
941 $return_sql_criteria .=
')';
943 return $return_sql_criteria;
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
fetch($id)
Load object in memory from the database.
fetch_by_element($id=0, $type_element= 'mailing')
Load object in memory from the database.
query_contact($arrayquery, $withThirdpartyFilter=0)
Load object in memory from database.
dol_now($mode= 'auto')
Return date for now.
query_thirdparty($arrayquery)
Load object in memory from database.
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.
savequery($user, $arrayquery)
Save query in database to retrieve it.
fetch_by_mailing($id=0)
Load object in memory from the database.
Class to manage third parties objects (customers, suppliers, prospects...)
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
__construct($db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
transformToSQL($column_to_test, $criteria)
Parse criteria to return a SQL qury formated.
Class to manage advanced emailing target selector.
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.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
create($user, $notrigger=0)
Create object into database.
update($user, $notrigger=0)
Update object into database.