$finishSending = mktime($messagedata['finishsending']['hour'], $messagedata['finishsending']['minute'], 0, $messagedata['finishsending']['month'], $messagedata['finishsending']['day'], $messagedata['finishsending']['year']); $embargoTime = mktime($messagedata['embargo']['hour'], $messagedata['embargo']['minute'], 0, $messagedata['embargo']['month'], $messagedata['embargo']['day'], $messagedata['embargo']['year']); if ($finishSending < $embargoTime) { print Warn(s('This campaign is scheduled to stop sending before the embargo time. No mails will be sent.')); print PageLinkButton('send&id=' . $messagedata['id'] . '&tab=Scheduling', s('Review Scheduling')); } ## reset any queued messages, as the selection may have changed if (defined('MESSAGEQUEUE_PREPARE') && MESSAGEQUEUE_PREPARE) { $query = sprintf('delete from ' . $tables['usermessage'] . ' where messageid = %d and status = "todo"', $messagedata['id']); } print '<h3>' . $GLOBALS['I18N']->get('Campaign queued') . '</h3>'; foreach ($GLOBALS['plugins'] as $pluginname => $plugin) { $plugin->messageQueued($id); } if (getConfig('pqchoice') == 'phplistdotcom') { print activateRemoteQueue(); } elseif (MANUALLY_PROCESS_QUEUE) { print '<p>' . PageLinkButton('processqueue', $GLOBALS['I18N']->get('processqueue')) . '</p>'; } else { print '<p>' . PageLinkButton('messages&tab=active', $GLOBALS['I18N']->get('view progress')) . '</p>'; } } $done = 1; return; } elseif ($send || $sendtest) { $errormessage = ''; if ($messagedata['subject'] != stripslashes($messagedata['subject'])) { $errormessage = $GLOBALS['I18N']->get('Sorry, you used invalid characters in the Subject field.'); } elseif (!empty($_POST['fromfield']) && $messagedata['fromfield'] != $_POST['fromfield']) { $errormessage = $GLOBALS['I18N']->get('Sorry, you used invalid characters in the From field.'); } elseif (empty($messagedata['fromfield'])) {
function repeatMessage($msgid) { # if (!USE_REPETITION && !USE_rss) return; $data = loadMessageData($msgid); ## do not repeat when it has already been done if ($data['repeatinterval'] == 0 || !empty($data['repeatedid'])) { return; } # calculate the future embargo, a multiple of repeatinterval minutes after the current embargo $msgdata = Sql_Fetch_Array_Query(sprintf('SELECT *, embargo + INTERVAL (FLOOR(TIMESTAMPDIFF(MINUTE, embargo, GREATEST(embargo, NOW())) / repeatinterval) + 1) * repeatinterval MINUTE AS newembargo FROM %s WHERE id = %d AND now() < repeatuntil', $GLOBALS['tables']['message'], $msgid)); if (!$msgdata) { logEvent("Message {$msgid} not repeated due to reaching the repeatuntil date"); return; } # check whether the new embargo is not on an exclusion if (isset($GLOBALS['repeat_exclude']) && is_array($GLOBALS['repeat_exclude'])) { $loopcnt = 0; while (excludedDateForRepetition($msgdata['newembargo'])) { if (++$loopcnt > 15) { logEvent("Unable to find new embargo date too many exclusions? for message {$msgid}"); return; } $result = Sql_Fetch_Array_Query(sprintf("SELECT '%s' + INTERVAL repeatinterval MINUTE AS newembargo\n FROM %s\n WHERE id = %d", $msgdata['newembargo'], $GLOBALS['tables']['message'], $msgid)); $msgdata['newembargo'] = $result['newembargo']; } } # copy the new message Sql_Query(sprintf(' insert into %s (entered) values(now())', $GLOBALS['tables']['message'])); $newid = Sql_Insert_id(); require dirname(__FILE__) . '/structure.php'; if (!is_array($DBstruct['message'])) { logEvent("Error including structure when trying to duplicate message {$msgid}"); return; } foreach ($DBstruct['message'] as $column => $rec) { if ($column != 'id' && $column != 'entered' && $column != 'sendstart') { Sql_Query(sprintf('update %s set %s = "%s" where id = %d', $GLOBALS['tables']['message'], $column, addslashes($msgdata[$column]), $newid)); } } $req = Sql_Query(sprintf("SELECT *\n FROM %s\n WHERE id = %d AND name NOT IN ('id')", $GLOBALS['tables']['messagedata'], $msgid)); while ($row = Sql_Fetch_Array($req)) { setMessageData($newid, $row['name'], $row['data']); } Sql_Query(sprintf('update %s set embargo = "%s",status = "submitted",sent = "" where id = %d', $GLOBALS['tables']['message'], $msgdata['newembargo'], $newid)); list($e['year'], $e['month'], $e['day'], $e['hour'], $e['minute'], $e['second']) = sscanf($msgdata['newembargo'], '%04d-%02d-%02d %02d:%02d:%02d'); unset($e['second']); setMessageData($newid, 'embargo', $e); foreach (array('processed', 'astext', 'ashtml', 'astextandhtml', 'aspdf', 'astextandpdf', 'viewed', 'bouncecount') as $item) { Sql_Query(sprintf('update %s set %s = 0 where id = %d', $GLOBALS['tables']['message'], $item, $newid)); } # lists $req = Sql_Query(sprintf('select listid from %s where messageid = %d', $GLOBALS['tables']['listmessage'], $msgid)); while ($row = Sql_Fetch_Row($req)) { Sql_Query(sprintf('insert into %s (messageid,listid,entered) values(%d,%d,now())', $GLOBALS['tables']['listmessage'], $newid, $row[0])); } # attachments $req = Sql_Query(sprintf('select * from %s,%s where %s.messageid = %d and %s.attachmentid = %s.id', $GLOBALS['tables']['message_attachment'], $GLOBALS['tables']['attachment'], $GLOBALS['tables']['message_attachment'], $msgid, $GLOBALS['tables']['message_attachment'], $GLOBALS['tables']['attachment'])); while ($row = Sql_Fetch_Array($req)) { if (is_file($row['remotefile'])) { # if the "remote file" is actually local, we want to refresh the attachment, so we set # filename to nothing $row['filename'] = ''; } Sql_Query(sprintf('insert into %s (filename,remotefile,mimetype,description,size) values("%s","%s","%s","%s",%d)', $GLOBALS['tables']['attachment'], addslashes($row['filename']), addslashes($row['remotefile']), addslashes($row['mimetype']), addslashes($row['description']), $row['size'])); $attid = Sql_Insert_id(); Sql_Query(sprintf('insert into %s (messageid,attachmentid) values(%d,%d)', $GLOBALS['tables']['message_attachment'], $newid, $attid)); } logEvent("Message {$msgid} was successfully rescheduled as message {$newid}"); ## remember we duplicated, in order to avoid doing it again (eg when requeuing) setMessageData($msgid, 'repeatedid', $newid); if (getConfig('pqchoice') == 'phplistdotcom') { activateRemoteQueue(); } }
$result = Sql_query(sprintf('delete from %s where messageid = %d', $tables['usermessage'], $resend)); } if ($suc6) { $action_result .= '... ' . $GLOBALS['I18N']->get('Done'); foreach ($GLOBALS['plugins'] as $pluginname => $plugin) { $plugin->messageReQueued($resend); } Sql_Query(sprintf('delete from %s where id = %d and (name = "start_notified" or name = "end_notified")', $tables['messagedata'], $resend)); $messagedata = loadMessageData($resend); $finishSending = mktime($messagedata['finishsending']['hour'], $messagedata['finishsending']['minute'], 0, $messagedata['finishsending']['month'], $messagedata['finishsending']['day'], $messagedata['finishsending']['year']); if ($finishSending < time()) { $action_result .= '<br />' . s('This campaign is scheduled to stop sending in the past. No mails will be sent.'); $action_result .= '<br />' . PageLinkButton('send&id=' . $messagedata['id'] . '&tab=Scheduling', s('Review Scheduling')); } if (getConfig('pqchoice') == 'phplistdotcom') { $action_result .= activateRemoteQueue(); } } else { $action_result .= '... ' . $GLOBALS['I18N']->get('failed'); } $action_result .= '<br />'; } if (isset($_GET['suspend'])) { verifyCsrfGetToken(); $suspend = sprintf('%d', $_GET['suspend']); $action_result .= $GLOBALS['I18N']->get('Suspending') . " {$suspend} .."; $result = Sql_query(sprintf('update %s set status = "suspended" where id = %d and (status = "inprocess" or status = "submitted") %s', $tables['message'], $suspend, $ownerselect_and)); $suc6 = Sql_Affected_Rows(); if ($suc6) { $action_result .= '... ' . $GLOBALS['I18N']->get('Done'); } else {
if (!empty($_POST['apikey'])) { if (!verifyToken()) { print Error($GLOBALS['I18N']->get('No Access')); return; } $streamContext = stream_context_create(array('http' => array('timeout' => 10))); $check = @file_get_contents(PQAPI_URL . '&cmd=verifykey&key=' . trim($_POST['apikey']), false, $streamContext); $check = trim($check); if (!empty($check) && strpos($check, 'KEYPASS') !== false) { SaveConfig('PQAPIkey', trim(str_replace('"', '', strip_tags($_POST['apikey']))), 0); SaveConfig('pqchoice', 'phplistdotcom', 0); ## if we have active campaigns, start them now $_SESSION['action_result'] = s('Remote queue processing settings were saved successfully'); $count = Sql_Fetch_Row_Query(sprintf("select count(*) from %s where status not in ('draft', 'sent', 'prepared', 'suspended') and embargo <= now()", $tables['message'])); if ($count[0] > 0) { $_SESSION['action_result'] .= '<br/>' . activateRemoteQueue(); } Redirect('messages&tab=active'); } else { if (!empty($http_response_header[0]) && strpos($http_response_header[0], '200 OK') !== false) { $_SESSION['action_result'] = s('Error, the API key is incorrect'); } else { $_SESSION['action_result'] = s('Error, unable to connect to the phpList.com server for checking. Please verify that your webserver is able to connect to https://pqapi.phplist.com') . '<br/><a href="./?page=processqueue&pqchoice=local" class="button">' . s('Use local processing instead') . '</a>'; } Redirect('hostedprocessqueuesetup'); } } $existingKey = getConfig('PQAPIkey'); print '<h2>' . s('Process the queue using the service from phpList.com') . '</h2>'; if ($fopenAllowed) { print '<p>' . s('This is only possible if your phpList installation is not behind a firewall') . '</p>';