79 |
$obj = $this->db->fetch_object($result); |
$obj = $this->db->fetch_object($result); |
80 |
return $obj->nb; |
return $obj->nb; |
81 |
} |
} |
82 |
else { |
else |
83 |
|
{ |
84 |
return -1; |
return -1; |
85 |
} |
} |
86 |
} |
} |
87 |
|
|
88 |
/** |
/** |
89 |
|
* \brief Affiche formulaire de filtre qui apparait dans page de selection |
90 |
|
* des destinataires de mailings |
91 |
|
* \return string Retourne zone select |
92 |
|
*/ |
93 |
|
function formFilter() |
94 |
|
{ |
95 |
|
return ' '; |
96 |
|
} |
97 |
|
|
98 |
|
/** |
99 |
* \brief Met a jour nombre de destinataires |
* \brief Met a jour nombre de destinataires |
100 |
* \param mailing_id Id du mailing concerné |
* \param mailing_id Id du mailing concerné |
101 |
* \return int < 0 si erreur, nb destinataires si ok |
* \return int < 0 si erreur, nb destinataires si ok |
152 |
$obj = $this->db->fetch_object($result); |
$obj = $this->db->fetch_object($result); |
153 |
if ($old <> $obj->email) |
if ($old <> $obj->email) |
154 |
{ |
{ |
155 |
$cibles[$j] = array($obj->email,$obj->fk_contact,$obj->name,$obj->firstname); |
$cibles[$j] = array($obj->email,$obj->fk_contact,$obj->name,$obj->firstname,$this->url($obj->id)); |
156 |
$old = $obj->email; |
$old = $obj->email; |
157 |
$j++; |
$j++; |
158 |
} |
} |
167 |
return -1; |
return -1; |
168 |
} |
} |
169 |
|
|
170 |
|
$this->db->begin(); |
171 |
|
|
172 |
// Insère destinataires de cibles dans table |
// Insère destinataires de cibles dans table |
173 |
$j = 0; |
$j = 0; |
174 |
$num = sizeof($cibles); |
$num = sizeof($cibles); |
177 |
$sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles"; |
$sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles"; |
178 |
$sql .= " (fk_mailing, "; |
$sql .= " (fk_mailing, "; |
179 |
if ($cibles[$i][1]) $sql .= "fk_contact, "; |
if ($cibles[$i][1]) $sql .= "fk_contact, "; |
180 |
$sql .= "nom, prenom, email)"; |
$sql .= "nom, prenom, email, url)"; |
181 |
$sql .= " VALUES (".$mailing_id.","; |
$sql .= " VALUES (".$mailing_id.","; |
182 |
if ($cibles[$i][1]) $sql .= $cibles[$i][1] .","; |
if ($cibles[$i][1]) $sql .= $cibles[$i][1] .","; |
183 |
$sql .= "'".$cibles[$i][2] ."',"; |
$sql .= "'".addslashes($cibles[$i][2])."',"; |
184 |
$sql .= "'".$cibles[$i][3] ."',"; |
$sql .= "'".addslashes($cibles[$i][3])."',"; |
185 |
$sql .= "'".$cibles[$i][0] ."')"; |
$sql .= "'".addslashes($cibles[$i][0])."',"; |
186 |
|
$sql .= "'".addslashes($cibles[$i][4])."')"; |
187 |
|
|
188 |
$result=$this->db->query($sql); |
$result=$this->db->query($sql); |
189 |
if ($result) |
if ($result) |
190 |
{ |
{ |
192 |
} |
} |
193 |
else |
else |
194 |
{ |
{ |
195 |
if ($this->db->errno() != DB_ERROR_RECORD_ALREADY_EXISTS) |
if ($this->db->errno() != 'DB_ERROR_RECORD_ALREADY_EXISTS') |
196 |
{ |
{ |
197 |
// Si erreur autre que doublon |
// Si erreur autre que doublon |
198 |
dolibarr_syslog($this->db->error()); |
dolibarr_syslog($this->db->error()); |
199 |
|
$this->error=$this->db->error(); |
200 |
|
$this->db->rollback(); |
201 |
return -1; |
return -1; |
202 |
} |
} |
203 |
} |
} |
207 |
|
|
208 |
$this->update_nb($mailing_id); |
$this->update_nb($mailing_id); |
209 |
|
|
210 |
|
$this->db->commit(); |
211 |
return $j; |
return $j; |
212 |
} |
} |
213 |
|
|