diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index 1e467331d90..4ca8b75af31 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -54,16 +54,17 @@ if (! $sortorder) $sortorder="ASC"; $id=GETPOST('id', 'int'); $rowid=GETPOST('rowid', 'int'); $action=GETPOST('action', 'aZ09'); -$search_lastname=GETPOST("search_lastname"); -$search_firstname=GETPOST("search_firstname"); -$search_email=GETPOST("search_email"); -$search_other=GETPOST("search_other"); -$search_dest_status=GETPOST('search_dest_status'); +$search_lastname=GETPOST("search_lastname", 'alphanohtml'); +$search_firstname=GETPOST("search_firstname", 'alphanohtml'); +$search_email=GETPOST("search_email", 'alphanohtml'); +$search_other=GETPOST("search_other", 'alphanohtml'); +$search_dest_status=GETPOST('search_dest_status', 'alphanohtml'); // Search modules dirs $modulesdir = dolGetModulesDirs('/mailings'); $object = new Mailing($db); +$result=$object->fetch($id); /* @@ -112,7 +113,7 @@ if ($action == 'add') } } -if (GETPOST('clearlist')) +if (GETPOST('clearlist', 'int')) { // Loading Class $obj = new MailingTargets($db); @@ -123,6 +124,50 @@ if (GETPOST('clearlist')) */ } +if (GETPOST('exportcsv', 'int')) +{ + $completefilename = 'targets_emailing'.$object->id.'_'.dol_print_date(dol_now(), 'dayhourlog').'csv'; + header('Content-Type: text/csv'); + header('Content-Disposition: attachment;filename=' . $completefilename); + + // List of selected targets + $sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.tms,"; + $sql .= " mc.source_url, mc.source_id, mc.source_type, mc.error_text"; + $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; + $sql .= " WHERE mc.fk_mailing=".$object->id; + $sql .= $db->order($sortfield, $sortorder); + + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $sep = ','; + + while ($obj = $db->fetch_object($resql)) + { + print $obj->rowid . $sep; + print $obj->lastname . $sep; + print $obj->firstname . $sep; + print $obj->email . $sep; + print $obj->other . $sep; + print $obj->date_envoi . $sep; + print $obj->tms . $sep; + print $obj->source_url . $sep; + print $obj->source_id . $sep; + print $obj->source_type . $sep; + print $obj->error_text . $sep; + print "\n"; + } + + exit; + } + else + { + dol_print_error($db); + } + exit; +} + if ($action == 'delete') { // Ici, rowid indique le destinataire et id le mailing @@ -437,10 +482,11 @@ if ($object->fetch($id) >= 0) $param = "&id=".$object->id; //if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); - if ($search_lastname) $param.= "&search_lastname=".urlencode($search_lastname); - if ($search_firstname) $param.= "&search_firstname=".urlencode($search_firstname); - if ($search_email) $param.= "&search_email=".urlencode($search_email); - if ($search_other) $param.= "&search_other=".urlencode($search_other); + if ($search_lastname) $param.= "&search_lastname=".urlencode($search_lastname); + if ($search_firstname) $param.= "&search_firstname=".urlencode($search_firstname); + if ($search_email) $param.= "&search_email=".urlencode($search_email); + if ($search_other) $param.= "&search_other=".urlencode($search_other); + if ($page) $param.= "&page=".urlencode($page); print '
'; @@ -466,9 +513,6 @@ if ($object->fetch($id) >= 0) print ''; print ''; - - if ($page) $param.= "&page=".$page; - print '