70 dol_syslog(get_class($this).
"::add_to_target_spec socid=".var_export($socid,
true).
' contactid='.var_export($contactid,
true));
74 if (($type_of_target == 1) || ($type_of_target == 3)) {
76 if (count($socid) > 0) {
77 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact";
78 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"societe_extrafields se ON se.fk_object=s.rowid";
79 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
80 $sql .=
" AND s.rowid IN (".$this->db->sanitize(implode(
',', $socid)).
")";
81 if (empty($this->evenunsubscribe)) {
82 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).
")";
84 $sql .=
" ORDER BY email";
87 $result = $this->db->query($sql);
89 $num = $this->db->num_rows($result);
92 dol_syslog(get_class($this).
"::add_to_target_spec mailing ".$num.
" targets found", LOG_DEBUG);
95 $obj = $this->db->fetch_object($result);
97 if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
98 if (!array_key_exists($obj->email, $cibles)) {
99 $cibles[$obj->email] = array(
100 'email' => $obj->email,
101 'fk_contact' => $obj->fk_contact,
102 'name' => $obj->name,
103 'firstname' => $obj->firstname,
105 'source_url' => $this->url($obj->id,
'thirdparty'),
106 'source_id' => $obj->id,
107 'source_type' =>
'thirdparty'
116 $this->error = $this->db->error();
122 if (($type_of_target == 1) || ($type_of_target == 2) || ($type_of_target == 4)) {
124 if (count($socid) > 0 || count($contactid) > 0) {
125 $sql =
"SELECT socp.rowid as id, socp.email as email, socp.lastname as lastname, socp.firstname as firstname";
126 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as socp";
127 $sql .=
" WHERE socp.entity IN (".getEntity(
'contact').
")";
128 if (count($contactid) > 0) {
129 $sql .=
" AND socp.rowid IN (".$this->db->sanitize(implode(
',', $contactid)).
")";
131 if (count($socid) > 0) {
132 $sql .=
" AND socp.fk_soc IN (".$this->db->sanitize(implode(
',', $socid)).
")";
134 if (empty($this->evenunsubscribe)) {
135 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = socp.email and mu.entity = ".((int) $conf->entity).
")";
137 $sql .=
" ORDER BY email";
140 $result = $this->db->query($sql);
142 $num = $this->db->num_rows($result);
145 dol_syslog(get_class($this).
"::add_to_target_spec mailing ".$num.
" targets found");
148 $obj = $this->db->fetch_object($result);
150 if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
151 if (!array_key_exists($obj->email, $cibles)) {
152 $cibles[$obj->email] = array(
153 'email' => $obj->email,
154 'fk_contact' => $obj->id,
155 'lastname' => $obj->lastname,
156 'firstname' => $obj->firstname,
158 'source_url' => $this->url($obj->id,
'contact'),
159 'source_id' => $obj->id,
160 'source_type' =>
'contact'
169 $this->error = $this->db->error();
176 dol_syslog(get_class($this).
"::add_to_target_spec mailing cibles=".var_export($cibles,
true), LOG_DEBUG);
178 return parent::addTargetsToDatabase($mailing_id, $cibles);