dolibarr_syslog("ws_import.inc.php::import_prospects $sql", LOG_DEBUG); $resql=$db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); if ($obj) $last = $obj->last; else { dolibarr_syslog("ws_import::aucun nouveau propect", LOG_DEBUG); $last = 0; } } else { dolibarr_syslog("ws_import::import prospects erreur ".$sql, LOG_ERR); return -1; } if ($res = get_new_prospects($siteid,$db, $user, $limit) < 0) print "Erreur traitement des prospects étape 1"."\n"; else print "fin étape 1 début étape 2"."\n"; // on fait les deux traitements systématiquement if ($res = import_prospects($siteid, $db, $user, $limit, $last)) print "traitement des prospects réussi $last $limit"." \n"; else print "Erreur traitement des prospects $last $limit"."\n"; break; default : print "commande inconnue : ".$argv[1]."\n"; $error = -1;
/** * \brief This is the main function that returns the array of emails * \param mailing_id Id of mailing. No need to use it. * \param filterarray If you used the formFilter function. Empty otherwise. * \return int <0 if error, number of emails added if ok */ function add_to_target($mailing_id,$filtersarray=array()) { $target = array(); // ----- Your code start here ----- $cibles = array(); $j = 0; $product=''; foreach($filtersarray as $key) { if ($key == '0') return "Error: You must choose a filter"; $product=$this->arrayofproducts[$key]; } $now=dol_now(); // La requete doit retourner: id, email, name $sql = " select s.rowid as id, s.email, s.nom as name, cd.rowid as cdid, cd.date_ouverture, cd.date_fin_validite, cd.fk_contrat"; $sql.= " from ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c,"; $sql.= " ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p"; $sql.= " where s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''"; $sql.= " AND cd.statut= 4 AND cd.fk_product=p.rowid AND p.ref = '".$product."'"; $sql.= " AND cd.date_fin_validite < '".$this->db->idate($now)."'"; $sql.= " ORDER BY s.email"; // Stocke destinataires dans cibles $result=$this->db->query($sql); if ($result) { $num = $this->db->num_rows($result); $i = 0; dolibarr_syslog(get_class($this)."::add_to_target ".$num." targets found"); $old = ''; while ($i < $num) { $obj = $this->db->fetch_object($result); if ($old <> $obj->email) { $cibles[$j] = array( 'email' => $obj->email, 'name' => $obj->name, 'other' => ('StartDate='.dol_print_date($this->db->jdate($obj->date_ouverture),'day')).';'. ('EndDate='.dol_print_date($this->db->jdate($obj->date_fin_validite),'day')).';'. ('Contract='.$obj->fk_contrat).';'. ('ContactLine='.$obj->cdid), 'source_url' => $this->url($obj->id), 'source_id' => $obj->id, 'source_type' => 'thirdparty' ); $old = $obj->email; $j++; } $i++; } } else { dolibarr_syslog($this->db->error()); $this->error=$this->db->error(); return -1; } // ----- Your code end here ----- return parent::add_to_target($mailing_id, $cibles); }