74 dol_syslog(get_class($this).
"::add_to_target_spec socid=".var_export($socid,
true).
' contactid='.var_export($contactid,
true));
78 if (($type_of_target == 1) || ($type_of_target == 3)) {
80 if (count($socid) > 0) {
81 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact";
82 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"societe_extrafields se ON se.fk_object=s.rowid";
83 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
84 $sql .=
" AND s.rowid IN (".$this->db->sanitize(implode(
',', $socid)).
")";
85 if (empty($this->evenunsubscribe)) {
86 $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).
")";
88 $sql .=
" ORDER BY email";
91 $result = $this->db->query($sql);
93 $num = $this->db->num_rows($result);
96 dol_syslog(get_class($this).
"::add_to_target_spec mailing ".$num.
" targets found", LOG_DEBUG);
99 $obj = $this->db->fetch_object($result);
101 if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
102 if (!array_key_exists($obj->email, $cibles)) {
103 $cibles[$obj->email] = array(
104 'email' => $obj->email,
105 'fk_contact' => $obj->fk_contact,
106 'name' => $obj->name,
107 'firstname' => $obj->firstname,
109 'source_url' => $this->url($obj->id,
'thirdparty'),
110 'source_id' => $obj->id,
111 'source_type' =>
'thirdparty'
120 $this->error = $this->db->error();
126 if (($type_of_target == 1) || ($type_of_target == 2) || ($type_of_target == 4)) {
128 if (count($socid) > 0 || count($contactid) > 0) {
129 $sql =
"SELECT socp.rowid as id, socp.email as email, socp.lastname as lastname, socp.firstname as firstname";
130 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as socp";
131 $sql .=
" WHERE socp.entity IN (".getEntity(
'contact').
")";
132 if (count($contactid) > 0) {
133 $sql .=
" AND socp.rowid IN (".$this->db->sanitize(implode(
',', $contactid)).
")";
135 if (count($socid) > 0) {
136 $sql .=
" AND socp.fk_soc IN (".$this->db->sanitize(implode(
',', $socid)).
")";
138 if (empty($this->evenunsubscribe)) {
139 $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).
")";
141 $sql .=
" ORDER BY email";
144 $result = $this->db->query($sql);
146 $num = $this->db->num_rows($result);
149 dol_syslog(get_class($this).
"::add_to_target_spec mailing ".$num.
" targets found");
152 $obj = $this->db->fetch_object($result);
154 if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
155 if (!array_key_exists($obj->email, $cibles)) {
156 $cibles[$obj->email] = array(
157 'email' => $obj->email,
158 'fk_contact' =>$obj->id,
159 'lastname' => $obj->lastname,
160 'firstname' => $obj->firstname,
162 'source_url' => $this->url($obj->id,
'contact'),
163 'source_id' => $obj->id,
164 'source_type' =>
'contact'
173 $this->error = $this->db->error();
180 dol_syslog(get_class($this).
"::add_to_target_spec mailing cibles=".var_export($cibles,
true), LOG_DEBUG);
182 return parent::addTargetsToDatabase($mailing_id, $cibles);
300 public function url($id, $type)
302 if ($type ==
'thirdparty') {
303 $companystatic =
new Societe($this->db);
304 $companystatic->fetch($id);
305 return $companystatic->getNomUrl(0,
'', 0, 1);
306 } elseif ($type ==
'contact') {
307 $contactstatic =
new Contact($this->db);
308 $contactstatic->fetch($id);
309 return $contactstatic->getNomUrl(0,
'', 0,
'', -1, 1);