69 dol_syslog(get_class($this).
"::add_to_target_spec socid=".var_export($socid,
true).
' contactid='.var_export($contactid,
true));
73 if (($type_of_target == 1) || ($type_of_target == 3)) {
75 if (count($socid) > 0) {
76 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact";
77 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"societe_extrafields se ON se.fk_object=s.rowid";
78 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
79 $sql .=
" AND s.rowid IN (".$this->db->sanitize(implode(
',', $socid)).
")";
80 if (empty($this->evenunsubscribe)) {
81 $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).
")";
83 $sql .=
" ORDER BY email";
86 $result = $this->db->query($sql);
88 $num = $this->db->num_rows($result);
91 dol_syslog(get_class($this).
"::add_to_target_spec mailing ".$num.
" targets found", LOG_DEBUG);
94 $obj = $this->db->fetch_object($result);
96 if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
97 if (!array_key_exists($obj->email, $cibles)) {
98 $cibles[$obj->email] = array(
99 'email' => $obj->email,
100 'fk_contact' => $obj->fk_contact,
101 'name' => $obj->name,
102 'firstname' => $obj->firstname,
104 'source_url' => $this->url($obj->id,
'thirdparty'),
105 'source_id' => $obj->id,
106 'source_type' =>
'thirdparty'
115 $this->error = $this->db->error();
121 if (($type_of_target == 1) || ($type_of_target == 2) || ($type_of_target == 4)) {
123 if (count($socid) > 0 || count($contactid) > 0) {
124 $sql =
"SELECT socp.rowid as id, socp.email as email, socp.lastname as lastname, socp.firstname as firstname";
125 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as socp";
126 $sql .=
" WHERE socp.entity IN (".getEntity(
'contact').
")";
127 if (count($contactid) > 0) {
128 $sql .=
" AND socp.rowid IN (".$this->db->sanitize(implode(
',', $contactid)).
")";
130 if (count($socid) > 0) {
131 $sql .=
" AND socp.fk_soc IN (".$this->db->sanitize(implode(
',', $socid)).
")";
133 if (empty($this->evenunsubscribe)) {
134 $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).
")";
136 $sql .=
" ORDER BY email";
139 $result = $this->db->query($sql);
141 $num = $this->db->num_rows($result);
144 dol_syslog(get_class($this).
"::add_to_target_spec mailing ".$num.
" targets found");
147 $obj = $this->db->fetch_object($result);
149 if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
150 if (!array_key_exists($obj->email, $cibles)) {
151 $cibles[$obj->email] = array(
152 'email' => $obj->email,
153 'fk_contact' =>$obj->id,
154 'lastname' => $obj->lastname,
155 'firstname' => $obj->firstname,
157 'source_url' => $this->url($obj->id,
'contact'),
158 'source_id' => $obj->id,
159 'source_type' =>
'contact'
168 $this->error = $this->db->error();
175 dol_syslog(get_class($this).
"::add_to_target_spec mailing cibles=".var_export($cibles,
true), LOG_DEBUG);
177 return parent::addTargetsToDatabase($mailing_id, $cibles);
295 public function url($id, $type)
297 if ($type ==
'thirdparty') {
298 $companystatic =
new Societe($this->db);
299 $companystatic->fetch($id);
300 return $companystatic->getNomUrl(0,
'', 0, 1);
301 } elseif ($type ==
'contact') {
302 $contactstatic =
new Contact($this->db);
303 $contactstatic->fetch($id);
304 return $contactstatic->getNomUrl(0,
'', 0,
'', -1, 1);