123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481 |
- <?php
- if (!defined('SMF'))
- die('No direct access...');
- function ManageMail()
- {
- global $context, $txt, $sourcedir;
-
- isAllowedTo('admin_forum');
- loadLanguage('Help');
- loadLanguage('ManageMail');
-
- require_once($sourcedir . '/ManageServer.php');
- $context['page_title'] = $txt['mailqueue_title'];
- $context['sub_template'] = 'show_settings';
- $subActions = array(
- 'browse' => 'BrowseMailQueue',
- 'clear' => 'ClearMailQueue',
- 'settings' => 'ModifyMailSettings',
- );
- call_integration_hook('integrate_manage_mail', array(&$subActions));
-
- $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'browse';
- $context['sub_action'] = $_REQUEST['sa'];
-
- $context[$context['admin_menu_name']]['tab_data'] = array(
- 'title' => $txt['mailqueue_title'],
- 'help' => '',
- 'description' => $txt['mailqueue_desc'],
- );
-
- $subActions[$_REQUEST['sa']]();
- }
- function BrowseMailQueue()
- {
- global $scripturl, $context, $txt, $smcFunc;
- global $sourcedir;
-
- if (isset($_REQUEST['delete']))
- {
- checkSession();
- $smcFunc['db_query']('', '
- DELETE FROM {db_prefix}mail_queue
- WHERE id_mail IN ({array_int:mail_ids})',
- array(
- 'mail_ids' => $_REQUEST['delete'],
- )
- );
- }
-
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*) AS queue_size, MIN(time_sent) AS oldest
- FROM {db_prefix}mail_queue',
- array(
- )
- );
- list ($mailQueueSize, $mailOldest) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- $context['oldest_mail'] = empty($mailOldest) ? $txt['mailqueue_oldest_not_available'] : time_since(time() - $mailOldest);
- $context['mail_queue_size'] = comma_format($mailQueueSize);
- $listOptions = array(
- 'id' => 'mail_queue',
- 'title' => $txt['mailqueue_browse'],
- 'items_per_page' => 20,
- 'base_href' => $scripturl . '?action=admin;area=mailqueue',
- 'default_sort_col' => 'age',
- 'no_items_label' => $txt['mailqueue_no_items'],
- 'get_items' => array(
- 'function' => 'list_getMailQueue',
- ),
- 'get_count' => array(
- 'function' => 'list_getMailQueueSize',
- ),
- 'columns' => array(
- 'subject' => array(
- 'header' => array(
- 'value' => $txt['mailqueue_subject'],
- ),
- 'data' => array(
- 'function' => create_function('$rowData', '
- global $smcFunc;
- return $smcFunc[\'strlen\']($rowData[\'subject\']) > 50 ? sprintf(\'%1$s...\', $smcFunc[\'htmlspecialchars\']($smcFunc[\'substr\']($rowData[\'subject\'], 0, 47))) : $smcFunc[\'htmlspecialchars\']($rowData[\'subject\']);
- '),
- 'class' => 'smalltext',
- ),
- 'sort' => array(
- 'default' => 'subject',
- 'reverse' => 'subject DESC',
- ),
- ),
- 'recipient' => array(
- 'header' => array(
- 'value' => $txt['mailqueue_recipient'],
- ),
- 'data' => array(
- 'sprintf' => array(
- 'format' => '<a href="mailto:%1$s">%1$s</a>',
- 'params' => array(
- 'recipient' => true,
- ),
- ),
- 'class' => 'smalltext',
- ),
- 'sort' => array(
- 'default' => 'recipient',
- 'reverse' => 'recipient DESC',
- ),
- ),
- 'priority' => array(
- 'header' => array(
- 'value' => $txt['mailqueue_priority'],
- ),
- 'data' => array(
- 'function' => create_function('$rowData', '
- global $txt;
- // We probably have a text label with your priority.
- $txtKey = sprintf(\'mq_mpriority_%1$s\', $rowData[\'priority\']);
- // But if not, revert to priority 0.
- return isset($txt[$txtKey]) ? $txt[$txtKey] : $txt[\'mq_mpriority_1\'];
- '),
- 'class' => 'smalltext',
- ),
- 'sort' => array(
- 'default' => 'priority',
- 'reverse' => 'priority DESC',
- ),
- ),
- 'age' => array(
- 'header' => array(
- 'value' => $txt['mailqueue_age'],
- ),
- 'data' => array(
- 'function' => create_function('$rowData', '
- return time_since(time() - $rowData[\'time_sent\']);
- '),
- 'class' => 'smalltext',
- ),
- 'sort' => array(
- 'default' => 'time_sent',
- 'reverse' => 'time_sent DESC',
- ),
- ),
- 'check' => array(
- 'header' => array(
- 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check">',
- ),
- 'data' => array(
- 'function' => create_function('$rowData', '
- return \'<input type="checkbox" name="delete[]" value="\' . $rowData[\'id_mail\'] . \'" class="input_check">\';
- '),
- 'class' => 'smalltext',
- ),
- ),
- ),
- 'form' => array(
- 'href' => $scripturl . '?action=admin;area=mailqueue',
- 'include_start' => true,
- 'include_sort' => true,
- ),
- 'additional_rows' => array(
- array(
- 'position' => 'bottom_of_list',
- 'value' => '<input type="submit" name="delete_redirects" value="' . $txt['quickmod_delete_selected'] . '" onclick="return confirm(\'' . $txt['quickmod_confirm'] . '\');" class="button_submit"><a class="button_link" href="' . $scripturl . '?action=admin;area=mailqueue;sa=clear;' . $context['session_var'] . '=' . $context['session_id'] . '" onclick="return confirm(\'' . $txt['mailqueue_clear_list_warning'] . '\');">' . $txt['mailqueue_clear_list'] . '</a> ',
- ),
- ),
- );
- require_once($sourcedir . '/Subs-List.php');
- createList($listOptions);
- loadTemplate('ManageMail');
- $context['sub_template'] = 'browse';
- }
- function list_getMailQueue($start, $items_per_page, $sort)
- {
- global $smcFunc, $txt;
- $request = $smcFunc['db_query']('', '
- SELECT
- id_mail, time_sent, recipient, priority, private, subject
- FROM {db_prefix}mail_queue
- ORDER BY {raw:sort}
- LIMIT {int:start}, {int:items_per_page}',
- array(
- 'start' => $start,
- 'sort' => $sort,
- 'items_per_page' => $items_per_page,
- )
- );
- $mails = array();
- while ($row = $smcFunc['db_fetch_assoc']($request))
- {
-
- if (!empty($row['private']))
- $row['subject'] = $txt['personal_message'];
- $mails[] = $row;
- }
- $smcFunc['db_free_result']($request);
- return $mails;
- }
- function list_getMailQueueSize()
- {
- global $smcFunc;
-
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*) AS queue_size
- FROM {db_prefix}mail_queue',
- array(
- )
- );
- list ($mailQueueSize) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- return $mailQueueSize;
- }
- function ModifyMailSettings($return_config = false)
- {
- global $txt, $scripturl, $context, $modSettings, $txtBirthdayEmails;
- loadLanguage('EmailTemplates');
- $body = $txtBirthdayEmails[(empty($modSettings['birthday_email']) ? 'happy_birthday' : $modSettings['birthday_email']) . '_body'];
- $subject = $txtBirthdayEmails[(empty($modSettings['birthday_email']) ? 'happy_birthday' : $modSettings['birthday_email']) . '_subject'];
- $emails = array();
- $processedBirthdayEmails = array();
- foreach ($txtBirthdayEmails as $key => $value)
- {
- $index = substr($key, 0, strrpos($key, '_'));
- $element = substr($key, strrpos($key, '_') + 1);
- $processedBirthdayEmails[$index][$element] = $value;
- }
- foreach ($processedBirthdayEmails as $index => $dummy)
- $emails[$index] = $index;
- $config_vars = array(
-
- array('int', 'mail_limit'),
- array('int', 'mail_quantity'),
- '',
-
- array('select', 'mail_type', array($txt['mail_type_default'], 'SMTP')),
- array('text', 'smtp_host'),
- array('text', 'smtp_port'),
- array('text', 'smtp_username'),
- array('password', 'smtp_password'),
- '',
- array('select', 'birthday_email', $emails, 'value' => array('subject' => $subject, 'body' => $body), 'javascript' => 'onchange="fetch_birthday_preview()"'),
- 'birthday_subject' => array('var_message', 'birthday_subject', 'var_message' => $processedBirthdayEmails[empty($modSettings['birthday_email']) ? 'happy_birthday' : $modSettings['birthday_email']]['subject'], 'disabled' => true, 'size' => strlen($subject) + 3),
- 'birthday_body' => array('var_message', 'birthday_body', 'var_message' => nl2br($body), 'disabled' => true, 'size' => ceil(strlen($body) / 25)),
- );
- call_integration_hook('integrate_modify_mail_settings', array(&$config_vars));
- if ($return_config)
- return $config_vars;
-
- if (isset($_GET['save']))
- {
-
- if (!empty($_POST['smtp_password'][1]))
- {
- $_POST['smtp_password'][0] = base64_encode($_POST['smtp_password'][0]);
- $_POST['smtp_password'][1] = base64_encode($_POST['smtp_password'][1]);
- }
- checkSession();
-
- unset($config_vars['birthday_subject'], $config_vars['birthday_body']);
- call_integration_hook('integrate_save_mail_settings');
- saveDBSettings($config_vars);
- redirectexit('action=admin;area=mailqueue;sa=settings');
- }
- $context['post_url'] = $scripturl . '?action=admin;area=mailqueue;save;sa=settings';
- $context['settings_title'] = $txt['mailqueue_settings'];
- prepareDBSettingContext($config_vars);
- $context['settings_insert_above'] = '
- <script><!-- // --><![CDATA[
- var bDay = {';
- $i = 0;
- foreach ($processedBirthdayEmails as $index => $email)
- {
- $is_last = ++$i == count($processedBirthdayEmails);
- $context['settings_insert_above'] .= '
- ' . $index . ': {
- subject: ' . JavaScriptEscape($email['subject']) . ',
- body: ' . JavaScriptEscape(nl2br($email['body'])) . '
- }' . (!$is_last ? ',' : '');
- }
- $context['settings_insert_above'] .= '
- };
- function fetch_birthday_preview()
- {
- var index = document.getElementById(\'birthday_email\').value;
- document.getElementById(\'birthday_subject\').innerHTML = bDay[index].subject;
- document.getElementById(\'birthday_body\').innerHTML = bDay[index].body;
- }
- // ]]></script>';
- }
- function ClearMailQueue()
- {
- global $sourcedir, $smcFunc;
- checkSession('get');
-
- require_once($sourcedir . '/ScheduledTasks.php');
-
- if (!isset($_GET['te']))
- {
-
- $request = $smcFunc['db_query']('', '
- SELECT COUNT(*) AS queue_size
- FROM {db_prefix}mail_queue',
- array(
- )
- );
- list ($_GET['te']) = $smcFunc['db_fetch_row']($request);
- $smcFunc['db_free_result']($request);
- }
- else
- $_GET['te'] = (int) $_GET['te'];
- $_GET['sent'] = isset($_GET['sent']) ? (int) $_GET['sent'] : 0;
-
- while (ReduceMailQueue(50, true, true) === true)
- {
-
- $_GET['sent'] += 50;
- pauseMailQueueClear();
- }
- return BrowseMailQueue();
- }
- function pauseMailQueueClear()
- {
- global $context, $txt, $time_start;
-
- @set_time_limit(600);
- if (function_exists('apache_reset_timeout'))
- @apache_reset_timeout();
-
- if (time() - array_sum(explode(' ', $time_start)) < 5)
- return;
- $context['continue_get_data'] = '?action=admin;area=mailqueue;sa=clear;te=' . $_GET['te'] . ';sent=' . $_GET['sent'] . ';' . $context['session_var'] . '=' . $context['session_id'];
- $context['page_title'] = $txt['not_done_title'];
- $context['continue_post_data'] = '';
- $context['continue_countdown'] = '2';
- $context['sub_template'] = 'not_done';
-
- $context['selected'] = 'browse';
-
- $context['continue_percent'] = round(($_GET['sent'] / $_GET['te']) * 100, 1);
-
- $context['continue_percent'] = min($context['continue_percent'], 100);
- obExit();
- }
- function time_since($time_diff)
- {
- global $txt;
- if ($time_diff < 0)
- $time_diff = 0;
-
- if ($time_diff > 86400)
- {
- $days = round($time_diff / 86400, 1);
- return sprintf($days == 1 ? $txt['mq_day'] : $txt['mq_days'], $time_diff / 86400);
- }
-
- elseif ($time_diff > 3600)
- {
- $hours = round($time_diff / 3600, 1);
- return sprintf($hours == 1 ? $txt['mq_hour'] : $txt['mq_hours'], $hours);
- }
-
- elseif ($time_diff > 60)
- {
- $minutes = (int) ($time_diff / 60);
- return sprintf($minutes == 1 ? $txt['mq_minute'] : $txt['mq_minutes'], $minutes);
- }
-
- else
- return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff);
- }
- ?>
|