function getValidMailing(&$list, $mailingId) { $listId = $list->id; $ready = false; do { if ($mailingId < 1) { $mailingId = xmailing::getFirstMailingId($listId); if (empty($mailingId)) { return ''; } } $mailing = xmailing::getOneMailing('', $mailingId, '', $new); if (!empty($mailing)) { if ($mailing->published == 1) { $newMailing = $mailing; $ready = true; } else { $newIssueNb = $mailing->issue_nb; $noMoreMailing = false; do { $newIssueNb++; $newMailing = xmailing::getQuickMailingIssue($listId, $newIssueNb, $total); if (empty($newMailing)) { $noMoreMailing = true; $newMailing->published = 0; } } while ($newMailing->published != 1 and $newIssueNb < $total and $noMoreMailing == false); if ($newIssueNb == $total and $newMailing->published != 1 or $noMoreMailing == true) { if ($list->follow_up > 0 and $list->list_type == '2') { $list = lists::getOneList($list->follow_up); if (!empty($list)) { if ($list->list_type == 2) { $mailingId = xmailing::getFirstMailingId($list->id); } else { $newMailing = ''; $newMailing->list_type = 1; $newMailing->list_id = $list->id; $ready = true; } } else { $newMailing = ''; $ready = true; } } else { $newMailing = ''; $ready = true; } } else { $ready = true; } } } else { $ready = true; $newMailing = ''; } } while (!$ready); return $newMailing; }