public function sendEmail() { global $lC_Database, $lC_Language; $max_execution_time = 0.8 * (int) ini_get('max_execution_time'); $time_start = explode(' ', PAGE_PARSE_START_TIME); if (isset($_POST['chosen'])) { $chosen = $_POST['chosen']; } elseif (isset($_GET['chosen'])) { $chosen = $_GET['chosen']; } elseif (isset($_POST['global'])) { $global = $_POST['global']; } elseif (isset($_GET['global'])) { $global = $_GET['global']; } $chosen_get_string = ''; if (isset($chosen) && !empty($chosen)) { foreach ($chosen as $id) { $chosen_get_string .= 'chosen[]=' . $id . '&'; } } $audience = array(); $Qcustomers = $lC_Database->query('select customers_id, customers_firstname, customers_lastname, customers_email_address from :table_customers where global_product_notifications = 1'); $Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS); $Qcustomers->execute(); while ($Qcustomers->next()) { if (!isset($audience[$Qcustomers->valueInt('customers_id')])) { $audience[$Qcustomers->valueInt('customers_id')] = array('firstname' => $Qcustomers->value('customers_firstname'), 'lastname' => $Qcustomers->value('customers_lastname'), 'email_address' => $Qcustomers->value('customers_email_address')); } } $Qcustomers = $lC_Database->query('select distinct pn.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address from :table_products_notifications pn, :table_customers c left join :table_newsletters_log nl on (c.customers_email_address = nl.email_address and nl.newsletters_id = :newsletters_id) where pn.customers_id = c.customers_id and nl.email_address is null'); $Qcustomers->bindTable(':table_products_notifications', TABLE_PRODUCTS_NOTIFICATIONS); $Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS); $Qcustomers->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG); $Qcustomers->bindInt(':newsletters_id', $this->_newsletter_id); if (isset($chosen) && !empty($chosen)) { $Qcustomers->appendQuery('and pn.products_id in (:products_id)'); $Qcustomers->bindRaw(':products_id', implode(', ', $chosen)); } $Qcustomers->execute(); while ($Qcustomers->next()) { if (!isset($audience[$Qcustomers->valueInt('customers_id')])) { $audience[$Qcustomers->valueInt('customers_id')] = array('firstname' => $Qcustomers->value('customers_firstname'), 'lastname' => $Qcustomers->value('customers_lastname'), 'email_address' => $Qcustomers->value('customers_email_address')); } } if (sizeof($audience) > 0) { $lC_Mail = new lC_Mail(null, null, null, EMAIL_FROM, $this->_newsletter_title); $lC_Mail->setBodyPlain($this->_newsletter_content); foreach ($audience as $key => $value) { $lC_Mail->clearTo(); $lC_Mail->addTo($value['firstname'] . ' ' . $value['lastname'], $value['email_address']); $lC_Mail->send(); $Qlog = $lC_Database->query('insert into :table_newsletters_log (newsletters_id, email_address, date_sent) values (:newsletters_id, :email_address, now())'); $Qlog->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG); $Qlog->bindInt(':newsletters_id', $this->_newsletter_id); $Qlog->bindValue(':email_address', $value['email_address']); $Qlog->execute(); $time_end = explode(' ', microtime()); $timer_total = number_format($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0]), 3); if ($timer_total > $max_execution_time) { echo '<p><font color="#38BB68"><b>' . $lC_Language->get('sending_refreshing_page') . '</b></font></p>' . '<form name="execute" action="' . lc_href_link_admin(FILENAME_DEFAULT, $lC_Template->getModule() . '&page=' . $_GET['page'] . '&nID=' . $this->_newsletter_id . '&action=send&' . (isset($global) && $global == 'true' ? 'global=true' : $chosen_get_string)) . '" method="post">' . '<p>' . lc_draw_hidden_field('subaction', 'execute') . '</p>' . '</form>' . '<script language="javascript">' . 'var counter = 3;' . 'public function counter() {' . ' count--;' . ' if (count > 0) {' . ' Id = window.setTimeout("counter()", 1000);' . ' } else {' . ' document.execute.submit();' . ' }' . '}' . '</script>'; exit; } } } $Qupdate = $lC_Database->query('update :table_newsletters set date_sent = now(), status = 1 where newsletters_id = :newsletters_id'); $Qupdate->bindTable(':table_newsletters', TABLE_NEWSLETTERS); $Qupdate->bindInt(':newsletters_id', $this->_newsletter_id); $Qupdate->execute(); }
public function sendEmail() { global $lC_Database, $lC_Language; $max_execution_time = 0.8 * (int) ini_get('max_execution_time'); $time_start = explode(' ', PAGE_PARSE_START_TIME); $audience = array(); $customer = ''; if (isset($_POST['customer']) && !empty($_POST['customer'])) { $customer = $_POST['customer']; } elseif (isset($_GET['customer']) && !empty($_GET['customer'])) { $customer = $_GET['customer']; } if (!empty($customer)) { $Qcustomers = $lC_Database->query('select customers_id, customers_firstname, customers_lastname, customers_email_address from :table_customers c left join :table_newsletters_log nl on (c.customers_email_address = nl.email_address and nl.newsletters_id = :newsletters_id) where nl.email_address is null'); $Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS); $Qcustomers->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG); $Qcustomers->bindInt(':newsletters_id', $this->_newsletter_id); if (is_numeric($customer)) { $Qcustomers->appendQuery('and c.customers_id = :customers_id'); $Qcustomers->bindInt(':customers_id', $customer); } $Qcustomers->execute(); while ($Qcustomers->next()) { if (!isset($audience[$Qcustomers->valueInt('customers_id')])) { $audience[$Qcustomers->valueInt('customers_id')] = array('firstname' => $Qcustomers->value('customers_firstname'), 'lastname' => $Qcustomers->value('customers_lastname'), 'email_address' => $Qcustomers->value('customers_email_address')); } } $Qcustomers->freeResult(); if (sizeof($audience) > 0) { $lC_Mail = new lC_Mail(null, null, null, EMAIL_FROM, $this->_newsletter_title); $lC_Mail->setBodyPlain($this->_newsletter_content); foreach ($audience as $key => $value) { $lC_Mail->clearTo(); $lC_Mail->addTo($value['firstname'] . ' ' . $value['lastname'], $value['email_address']); $lC_Mail->send(); $Qlog = $lC_Database->query('insert into :table_newsletters_log (newsletters_id, email_address, date_sent) values (:newsletters_id, :email_address, now())'); $Qlog->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG); $Qlog->bindInt(':newsletters_id', $this->_newsletter_id); $Qlog->bindValue(':email_address', $value['email_address']); $Qlog->execute(); $time_end = explode(' ', microtime()); $timer_total = number_format($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0]), 3); if ($timer_total > $max_execution_time) { echo '<p><font color="#38BB68"><b>' . $lC_Language->get('sending_refreshing_page') . '</b></font></p>' . '<META HTTP-EQUIV="refresh" content="2; URL=' . lc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $this->_newsletter_id . '&action=nmSendConfirm&customer=' . $customer) . '">'; exit; } } } $Qupdate = $lC_Database->query('update :table_newsletters set date_sent = now(), status = 1 where newsletters_id = :newsletters_id'); $Qupdate->bindTable(':table_newsletters', TABLE_NEWSLETTERS); $Qupdate->bindInt(':newsletters_id', $this->_newsletter_id); $Qupdate->execute(); } }
public function sendEmail() { global $lC_Database, $lC_Language, $lC_Template; $max_execution_time = 0.8 * (int) ini_get('max_execution_time'); $time_start = explode(' ', PAGE_PARSE_START_TIME); $Qrecipients = $lC_Database->query('select c.customers_firstname, c.customers_lastname, c.customers_email_address from :table_customers c left join :table_newsletters_log nl on (c.customers_email_address = nl.email_address and nl.newsletters_id = :newsletters_id) where c.customers_newsletter = 1 and nl.email_address is null'); $Qrecipients->bindTable(':table_customers', TABLE_CUSTOMERS); $Qrecipients->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG); $Qrecipients->bindInt(':newsletters_id', $this->_newsletter_id); $Qrecipients->execute(); if ($Qrecipients->numberOfRows() > 0) { $lC_Mail = new lC_Mail(null, null, null, EMAIL_FROM, $this->_newsletter_title); $lC_Mail->setBodyPlain($this->_newsletter_content); while ($Qrecipients->next()) { $lC_Mail->clearTo(); $lC_Mail->addTo($Qrecipients->value('customers_firstname') . ' ' . $Qrecipients->value('customers_lastname'), $Qrecipients->value('customers_email_address')); $lC_Mail->send(); $Qlog = $lC_Database->query('insert into :table_newsletters_log (newsletters_id, email_address, date_sent) values (:newsletters_id, :email_address, now())'); $Qlog->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG); $Qlog->bindInt(':newsletters_id', $this->_newsletter_id); $Qlog->bindValue(':email_address', $Qrecipients->value('customers_email_address')); $Qlog->execute(); $time_end = explode(' ', microtime()); $timer_total = number_format($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0]), 3); if ($timer_total > $max_execution_time) { echo '<p><font color="#38BB68"><b>' . $lC_Language->get('sending_refreshing_page') . '</b></font></p>' . '<form name="execute" action="' . lc_href_link_admin(FILENAME_DEFAULT, $lC_Template->getModule() . '&page=' . $_GET['page'] . '&nID=' . $this->_newsletter_id . '&action=send') . '" method="post">' . '<p>' . lc_draw_hidden_field('subaction', 'execute') . '</p>' . '</form>' . '<script language="javascript">' . 'var counter = 3;' . 'function counter() {' . ' count--;' . ' if (count > 0) {' . ' Id = window.setTimeout("counter()", 1000);' . ' } else {' . ' document.execute.submit();' . ' }' . '}' . '</script>'; exit; } } $Qrecipients->freeResult(); } $Qupdate = $lC_Database->query('update :table_newsletters set date_sent = now(), status = 1 where newsletters_id = :newsletters_id'); $Qupdate->bindTable(':table_newsletters', TABLE_NEWSLETTERS); $Qupdate->bindInt(':newsletters_id', $this->_newsletter_id); $Qupdate->execute(); }