doEmailTask(999999); echo "Completed Mailout ID: ".$_GET['id']; exit; } $action = $tp->toDB(varset($_GET['mode'],'makemail')); $pageMode = varset($_GET['savepage'], $action); // Sometimes we need to know what brought us here - $action gets changed $mailId = intval(varset($_GET['m'],0)); $targetId = intval(varset($_GET['t'],0)); // Create mail admin object, load all mail handlers $mailAdmin = new mailoutAdminClass($action); // This decodes parts of the query using $_GET syntax e107::setRegistry('_mailout_admin', $mailAdmin); if ($mailAdmin->loadMailHandlers() == 0) { // No mail handlers loaded echo 'No mail handlers loaded!!'; exit; } require_once(e_ADMIN.'auth.php'); $errors = array(); $subAction = ''; $midAction = ''; $fromHold = FALSE; if (isset($_POST['mailaction'])) { if (is_array($_POST['mailaction'])) { foreach ($_POST['mailaction'] as $k => $v) { if ($v) // Look for non-empty action { $mailId = $k; $action = $v; break; } } } } if (isset($_POST['targetaction'])) { if (is_array($_POST['targetaction'])) { foreach ($_POST['targetaction'] as $k => $v) { if ($v) // Look for non-empty action { $targetId = $k; $action = $v; break; } } } } //echo "Action: {$action} MailId: {$mailId} Target: {$targetId}
"; // ----------------- Actions -------------------> //TODO - replace code sections with class/functions. switch ($action) { case 'prefs' : if (getperms('0')) { if (isset($_POST['testemail'])) { // Send test email - uses standard 'single email' handler if(trim($_POST['testaddress']) == '') { $mes->addError(LAN_MAILOUT_19); $subAction = 'error'; } else { $mailheader_e107id = USERID; require_once(e_HANDLER.'mail.php'); $add = ($pref['mailer']) ? " (".strtoupper($pref['mailer']).")" : ' (PHP)'; $sendto = trim($_POST['testaddress']); if (!sendemail($sendto, LAN_MAILOUT_113." ".SITENAME.$add, LAN_MAILOUT_114,LAN_MAILOUT_189)) { $mes->addError(($pref['mailer'] == 'smtp') ? LAN_MAILOUT_67 : LAN_MAILOUT_106); } else { $mes->addSuccess(LAN_MAILOUT_81. ' ('.$sendto.')'); $admin_log->log_event('MAIL_01',$sendto,E_LOG_INFORMATIVE,''); } } } elseif (isset($_POST['updateprefs'])) { saveMailPrefs($mes); // TODO check if functional, $emessage -> $mes } } break; case 'mailcopy' : // Copy existing email and go to edit screen if (isset($_POST['mailaction'])) { $action = 'makemail'; $mailData = $mailAdmin->retrieveEmail($mailId); if ($mailData === FALSE) { $mes->addError(LAN_MAILOUT_164.':'.$mailId); break; } unset($mailData['mail_source_id']); } break; case 'mailedit' : // Edit existing mail if (isset($_POST['mailaction'])) { $action = 'makemail'; $mailData = $mailAdmin->retrieveEmail($mailId); if ($mailData === FALSE) { $mes->addError(LAN_MAILOUT_164.':'.$mailId); break; } } break; case 'makemail' : $newMail = TRUE; if (isset($_POST['save_email'])) { $subAction = 'new'; } elseif (isset($_POST['update_email'])) { $subAction = 'update'; $newMail = FALSE; } elseif (isset($_POST['send_email'])) { // Send bulk email $subAction = 'send'; } if ($subAction != '') { $mailData = $mailAdmin->parseEmailPost($newMail); $errors = $mailAdmin->checkEmailPost($mailData, $subAction == 'send'); // Full check if sending email if ($errors !== TRUE) { $subAction = 'error'; break; } $mailData['mail_selectors'] = $mailAdmin->getAllSelectors(); // Add in the selection criteria } // That's the checking over - now do something useful! switch ($subAction) { case 'send' : // This actually creates the list of recipients in the display routine $action = 'marksend'; break; case 'new' : // TODO: Check all fields created - maybe $mailData['mail_content_status'] = MAIL_STATUS_SAVED; $mailData['mail_create_app'] = 'core'; $result = $mailAdmin->saveEmail($mailData, TRUE); if (is_numeric($result)) { $mailData['mail_source_id'] = $result; $mes->addSuccess(LAN_MAILOUT_145); } else { $mes->addError(LAN_MAILOUT_146); } break; case 'update' : $mailData['mail_content_status'] = MAIL_STATUS_SAVED; $result = $mailAdmin->saveEmail($mailData, FALSE); if (is_numeric($result)) { $mailData['mail_source_id'] = $result; $mes->addSuccess(LAN_MAILOUT_147); } else { $mes->addError(LAN_MAILOUT_146); } break; } break; case 'mailhold' : $action = 'held'; if ($mailAdmin->holdEmail($mailId)) { $mes->addSuccess(str_replace('--ID--', $mailId, LAN_MAILOUT_229)); } else { $errors[] = str_replace('--ID--', $mailId, LAN_MAILOUT_230); } break; case 'mailcancel' : $action = $pageMode; // Want to return to some other page if ($mailAdmin->cancelEmail($mailId)) { $mes->addSuccess(str_replace('--ID--', $mailId, LAN_MAILOUT_220)); } else { $errors[] = str_replace('--ID--', $mailId, LAN_MAILOUT_221); } break; case 'maildelete' : break; case 'marksend' : // Actually do something with an email and list of recipients - entry from email confirm page $action = 'saved'; if (isset($_POST['email_cancel'])) // 'Cancel' in this context means 'delete' - don't want it any more { $midAction = 'midDeleteEmail'; } elseif (isset($_POST['email_hold'])) { if ($mailAdmin->activateEmail($mailId, TRUE)) { $mes->addSuccess(str_replace('--ID--', $mailId, LAN_MAILOUT_187)); } else { $errors[] = str_replace('--ID--', $mailId, LAN_MAILOUT_166); } $action = 'held'; } elseif (isset($_POST['email_send'])) { $midAction = 'midMoveToSend'; $action = 'pending'; } if(isset($_POST['email_sendnow'])) { $midAction = 'midMoveToSend'; //$action = 'pending'; } break; case 'mailsendnow' : // Send mail previously on 'held' list. Need to give opportunity to change time/date etc $action = 'marksend'; // This shows the email details for confirmation $fromHold = TRUE; $mailData['mail_source_id'] = $mailId; break; case 'maildeleteconfirm' : $action = $pageMode; // Want to return to some other page $midAction = 'midDeleteEmail'; if (!isset($_POST['mailIDConf']) || (intval($_POST['mailIDConf']) != $mailId)) { $errors[] = str_replace(array('--ID--', '--CHECK--'), array($mailId, intval($_POST['mailIDConf'])), LAN_MAILOUT_174); break; } break; case 'mailonedelete' : case 'debug' : $mes->addError('Not implemented yet'); break; case 'mailtargets' : $action = 'recipients'; // Intentional fall-through case 'recipients' : case 'saved' : // Show template emails - probably no actions case 'sent' : case 'pending' : case 'held' : case 'mailshowtemplate' : if (isset($_POST['etrigger_ecolumns'])) { $mailAdmin->mailbodySaveColumnPref($action); } break; case 'maint' : // Perform any maintenance actions required if (isset($_POST['email_dross'])) if ($mailAdmin->dbTidy()) // Admin logging done in this routine { $mes->addSuccess(LAN_MAILOUT_184); } else { $errors[] = LAN_MAILOUT_183; } break; // Send Emails Immediately using Ajax case 'mailsendimmediately' : $id = array_keys($_POST['mailaction']); sendImmediately($id[0]); break; default : $mes->addError('Code malfunction 23! ('.$action.')'); $ns->tablerender(LAN_MAILOUT_97, $mes->render()); exit; // Could be a hack attempt } // switch($action) - end of 'executive' tasks // ------------------------ Intermediate actions --------------------------- // (These have more than one route to trigger them) switch ($midAction) { case 'midDeleteEmail' : // $emessage->add($pageMode.': Would delete here: '.$mailId, E_MESSAGE_SUCCESS); // break; // Delete this $result = $mailAdmin->deleteEmail($mailId, 'all'); $admin_log->log_event('MAIL_04','ID: '.$mailId,E_LOG_INFORMATIVE,''); if (($result === FALSE) || !is_array($result)) { $errors[] = str_replace('--ID--', $mailId, LAN_MAILOUT_166); } else { if (isset($result['content'])) { if ($result['content'] === FALSE) { $errors[] = str_replace('--ID--', $mailId, LAN_MAILOUT_167); } else { $mes->addSuccess(str_replace('--ID--', $mailId, LAN_MAILOUT_167)); } } if (isset($result['recipients'])) { if ($result['recipients'] === FALSE) { $errors[] = str_replace('--ID--', $mailId, LAN_MAILOUT_169); } else { $mes->addSuccess(str_replace(array('--ID--', '--NUM--'), array($mailId, $result['recipients']), LAN_MAILOUT_170)); } } } break; case 'midMoveToSend' : $notify = isset($_POST['mail_notify_complete']) ? 3 : 2; $first = 0; $last = 0; // Set defaults for earliest and latest send times. // TODO: Save these fields if (isset($_POST['mail_earliest_time'])) { $first = e107::getDateConvert()->decodeDateTime($_POST['mail_earliest_time'], 'datetime', CORE_DATE_ORDER, FALSE); } if (isset($_POST['mail_latest_time'])) { $last = e107::getDateConvert()->decodeDateTime($_POST['mail_earliest_time'], 'datetime', CORE_DATE_ORDER, TRUE); } if ($mailAdmin->activateEmail($mailId, FALSE, $notify, $first, $last)) { $mes->addSuccess(LAN_MAILOUT_185); $admin_log->log_event('MAIL_06','ID: '.$mailId,E_LOG_INFORMATIVE,''); } else { $errors[] = str_replace('--ID--', $mailId, LAN_MAILOUT_188); } break; } if(isset($_POST['email_sendnow'])) { sendImmediately($mailId); } // --------------------- Display errors and results ------------------------ if (is_array($errors) && (count($errors) > 0)) { foreach ($errors as $e) { $mes->addError($e); } unset($errors); } if ($mes->hasMessage()) { $ns->tablerender(LAN_MAILOUT_97, $mes->render()); } // ---------------------- Display required page ---------------------------- // At this point $action determines which page display is required - one of a // fairly limited number of choices $mailAdmin->newMode($action); //echo "Action: {$action} MailId: {$mailId} Target: {$targetId}
"; switch ($action) { case 'prefs' : if (getperms('0')) { show_prefs($mailAdmin); } break; case 'maint' : if (getperms('0')) { show_maint(FALSE); } break; case 'debug' : if (getperms('0')) { show_maint(TRUE); } break; case 'saved' : // Show template emails case 'sent' : case 'pending' : case 'held' : $mailAdmin->showEmailList($action, -1, -1); break; case 'mailshowtemplate' : // Show the templated email $mailAdmin->showEmailTemplate($mailId); break; case 'maildelete' : // NOTE:: need to set previous page in form $mailAdmin->showDeleteConfirm($mailId, $pageMode); break; case 'marksend' : // Show the send confirmation page $mailAdmin->sendEmailCircular($mailData, $fromHold); break; case 'recipients' : $mailAdmin->showmailRecipients($mailId, $action); break; case 'makemail' : default : if (!isset($mailData) || !is_array($mailData)) { $mailData = array(); // Empty array just in case } $mailAdmin->show_mailform($mailData); break; } require_once(e_ADMIN.'footer.php'); /** * Real-time Immediate Mail-out. Browser may be closed and will continue. * @param integer $id (mailing id) * @return */ function sendImmediately($id) { $mes = e107::getMessage(); $text = "
Processing Mailout ID: ".$id."
"; $text .= "
 
"; //Initiate the Function in the Background. $text .= " "; // Update the Progress in real-time. $text .= " "; $mes->addSuccess($text); e107::getRender()->tablerender("Sending...", $mes->render()); } /** * Display Progress-bar of real-time mail-out. * @return */ function sendProgress() { $sqld = e107::getDb(); $sqld->db_Select("mail_content","mail_togo_count,mail_sent_count,mail_fail_count","mail_source_id= ".intval($_GET['id']) ); $row = $sqld -> db_Fetch(); $rand = $row['mail_sent_count'] + $row['mail_fail_count']; $total = $row['mail_togo_count'] + $row['mail_sent_count'] + $row['mail_fail_count']; // $rand = rand(1,20); //$total = 20; $inc = round(($rand / $total) * 100); if($rand >= $total && $total !=0) { echo ""; echo "
Complete
"; echo "
".$rand." / ".$total."
"; return; } echo "
"; for($j=1;$j<=$inc;$j++) { echo ""; } echo " $inc %
"; echo "
".$rand." / ".$total."
"; return; } // Update Preferences. (security handled elsewhere) function saveMailPrefs(&$mes) // $emessage to $mes, working? { //$pref = e107::getPref(); $e107 = e107::getInstance(); $bounceOpts = array('none' => LAN_MAILOUT_232, 'auto' => LAN_MAILOUT_233, 'mail' => LAN_MAILOUT_234); unset($temp); if (!in_array($_POST['mailer'], array('smtp', 'sendmail', 'php'))) $_POST['mailer'] = 'php'; $temp['mailer'] = $_POST['mailer']; // Allow qmail as an option as well - works much as sendmail if ((strpos($_POST['sendmail'],'sendmail') !== FALSE) || (strpos($_POST['sendmail'],'qmail') !== FALSE)) { $temp['sendmail'] = $tp->toDB($_POST['sendmail']); } else { $temp['sendmail'] = ''; } $temp['smtp_server'] = $tp->toDB($_POST['smtp_server']); $temp['smtp_username'] = $tp->toDB($_POST['smtp_username']); $temp['smtp_password'] = $tp->toDB($_POST['smtp_password']); $smtp_opts = array(); switch (trim($_POST['smtp_options'])) { case 'smtp_ssl' : $smtp_opts[] = 'secure=SSL'; break; case 'smtp_tls' : $smtp_opts[] = 'secure=TLS'; break; case 'smtp_pop3auth' : $smtp_opts[] = 'pop3auth'; break; } if (varsettrue($_POST['smtp_keepalive'])) $smtp_opts[] = 'keepalive'; if (varsettrue($_POST['smtp_useVERP'])) $smtp_opts[] = 'useVERP'; $temp['smtp_options'] = implode(',',$smtp_opts); $temp['mail_sendstyle'] = $tp->toDB($_POST['mail_sendstyle']); $temp['mail_pause'] = intval($_POST['mail_pause']); $temp['mail_pausetime'] = intval($_POST['mail_pausetime']); $temp['mail_workpertick'] = intval($_POST['mail_workpertick']); $temp['mail_workpertick'] = min($temp['mail_workpertick'],1000); $temp['mail_bounce'] = isset($bounceOpts[$_POST['mail_bounce']]) ? $_POST['mail_bounce'] : 'none'; $temp['mail_bounce_auto'] = 0; // Make sure this is always defined switch ($temp['mail_bounce']) { case 'none' : $temp['mail_bounce_email'] = ''; break; case 'auto' : $temp['mail_bounce_email'] = $tp->toDB($_POST['mail_bounce_email2']); break; case 'mail' : $temp['mail_bounce_email'] = $tp->toDB($_POST['mail_bounce_email']); $temp['mail_bounce_auto'] = intval($_POST['mail_bounce_auto']); break; } $temp['mail_bounce_pop3'] = $tp->toDB($_POST['mail_bounce_pop3']); $temp['mail_bounce_user'] = $tp->toDB($_POST['mail_bounce_user']); $temp['mail_bounce_pass'] = $tp->toDB($_POST['mail_bounce_pass']); $temp['mail_bounce_type'] = $tp->toDB($_POST['mail_bounce_type']); $temp['mail_bounce_delete'] = intval(varset($_POST['mail_bounce_delete'], 0)); $temp['mailout_enabled'] = implode(',',varset($_POST['mail_mailer_enabled'], '')); $temp['mail_log_options'] = intval($_POST['mail_log_option']).','.intval($_POST['mail_log_email']); foreach ($temp as &$t) { if ($t === NULL) $t = ''; } $pref = e107::pref('core'); // Core Prefs Array. if (e107::getAdminLog()->logArrayDiffs($temp, $pref, 'MAIL_03')) { e107::getConfig()->updatePref($temp); e107::getConfig()->save(false); // Only save if changes - generates its own message } else { $mes->addInfo(LAN_NO_CHANGE); } } //---------------------------------------------------- // MAILER OPTIONS //---------------------------------------------------- function show_prefs($mailAdmin) { $pref = e107::getPref(); $e107 = e107::getInstance(); $frm = e107::getForm(); $mes = e107::getMessage(); $ns = e107::getRender(); e107::getCache()->CachePageMD5 = '_'; $lastload = e107::getCache()->retrieve('emailLastBounce',FALSE,TRUE,TRUE); $lastBounce = round((time() - $lastload) / 60); $lastBounceText = ($lastBounce > 1256474) ? "Never" : "".$lastBounce . " minutes ago."; $text = "
".LAN_MAILOUT_110." \n \n \n"; if (isset($pref['e_mailout_list'])) // Allow selection of email address sources { $text .= " \n"; } list($mail_log_option,$mail_log_email) = explode(',',varset($pref['mail_log_options'],'0,0')); $check = ($mail_log_email == 1) ? " checked='checked'" : ""; $text .= "\n"; $text .= "
".LAN_MAILOUT_110."
".$frm->admin_button('testemail', LAN_MAILOUT_112,'other')." 
".LAN_MAILOUT_115."
".LAN_MAILOUT_116."
"; // SMTP. --------------> $smtp_opts = explode(',',varset($pref['smtp_options'],'')); $smtpdisp = ($pref['mailer'] != 'smtp') ? "style='display:none;'" : ''; $text .= "
"; $text .= " "; $text .= ""; $checked = (in_array('useVERP',$smtp_opts) ? "checked='checked'" : ""); $text .= "
".LAN_MAILOUT_87.":  
".LAN_MAILOUT_88.": (".LAN_OPTIONAL.")  
".LAN_MAILOUT_89.": (".LAN_OPTIONAL.")  
".LAN_MAILOUT_90." \n
".LAN_MAILOUT_94."
".LAN_MAILOUT_57." "; $checked = (varsettrue($pref['smtp_keepalive']) ) ? "checked='checked'" : ''; $text .= "
".LAN_MAILOUT_95."
"; /* FIXME - posting SENDMAIL path triggers Mod-Security rules. // Sendmail. --------------> $senddisp = ($pref['mailer'] != 'sendmail') ? "style='display:none;'" : ''; $text .= "
"; $text .= "
".LAN_MAILOUT_20.":  
"; */ $text .="
".LAN_MAILOUT_222." "; $text .= $mailAdmin->sendStyleSelect(varset($pref['mail_sendstyle'], 'textonly'), 'mail_sendstyle'); $text .= "".LAN_MAILOUT_223."
".LAN_MAILOUT_25." ".LAN_MAILOUT_26." ".LAN_MAILOUT_27. " ".LAN_MAILOUT_29.".
".LAN_MAILOUT_30."
".LAN_MAILOUT_156." ".LAN_MAILOUT_157."
".LAN_MAILOUT_77." "; $mail_enable = explode(',',$pref['mailout_enabled']); foreach ($pref['e_mailout_list'] as $mailer => $v) { $check = (in_array($mailer,$mail_enable)) ? "checked='checked'" : ""; $text .= "  {$mailer}
"; } $text .= "
".LAN_MAILOUT_72." \n ".LAN_MAILOUT_76. "
".LAN_MAILOUT_31."
".LAN_MAILOUT_231.""; // bounce divs = mail_bounce_none, mail_bounce_auto, mail_bounce_mail $autoDisp = ($pref['mail_bounce'] != 'auto') ? "style='display:none;'" : ''; $autoMail = ($pref['mail_bounce'] != 'mail') ? "style='display:none;'" : ''; $bounceOpts = array('none' => LAN_MAILOUT_232, 'auto' => LAN_MAILOUT_233, 'mail' => LAN_MAILOUT_234); $text .= "\n
".LAN_MAILOUT_32."
".LAN_MAILOUT_233."".(e_DOCROOT).e107::getFolder('handlers')."bounce_handler.php"; if(!is_readable(e_HANDLER.'bounce_handler.php')) { $text .= "
".LAN_MAILOUT_161.''; } elseif(!is_executable(e_HANDLER.'bounce_handler.php')) // Seems to give wrong answers on Windoze { $text .= "
".LAN_MAILOUT_162.''; } $text .= "
".LAN_MAILOUT_235."
".LAN_MAILOUT_236."".$lastBounceText."
"; // Parameters for mail-account based bounce processing $text .= " \n "; $check = ($pref['mail_bounce_delete']==1) ? " checked='checked'" : ""; $text .= ""; $check = ($pref['mail_bounce_auto']==1) ? " checked='checked'" : ""; $text .= "
".LAN_MAILOUT_32."
".LAN_MAILOUT_33."
".LAN_MAILOUT_34."
".LAN_MAILOUT_35."
".LAN_MAILOUT_120."
".LAN_MAILOUT_36."
".LAN_MAILOUT_245." ".LAN_MAILOUT_246."
".$frm->admin_button('updateprefs',LAN_MAILOUT_28,'update')."
"; $caption = ADLAN_136.SEP.LAN_PREFS; $ns->tablerender($caption, $mes->render(). $text); } //----------------------------------------------------------- // MAINTENANCE OPTIONS //----------------------------------------------------------- function show_maint($debug = FALSE) { $mes = e107::getMessage(); $ns = e107::getRender(); $frm = e107::getForm(); $text = "
"; $text .= ""; $text .= "
".LAN_MAILOUT_182." ".$frm->admin_button('email_dross','no-value','delete', LAN_RUN)."
".LAN_MAILOUT_252."
\n
"; $ns->tablerender(ADLAN_136.SEP.ADLAN_40, $mes->render().$text); } function mailout_adminmenu() { $tp = e107::getParser(); $action = $tp->toDB(varset($_GET['mode'],'makemail')); if($action == 'mailedit') { $action = 'makemail'; } $var['post']['text'] = LAN_MAILOUT_190; $var['post']['link'] = e_SELF; $var['post']['perm'] = 'W'; $var['saved']['text'] = LAN_MAILOUT_191; // Saved emails $var['saved']['link'] = e_SELF.'?mode=saved'; $var['saved']['perm'] = 'W'; $var['pending']['text'] = LAN_MAILOUT_193; // Pending email runs $var['pending']['link'] = e_SELF.'?mode=pending'; $var['pending']['perm'] = 'W'; $var['held']['text'] = LAN_MAILOUT_194; // Held email runs $var['held']['link'] = e_SELF.'?mode=held'; $var['held']['perm'] = 'W'; $var['sent']['text'] = LAN_MAILOUT_192; // Completed email runs $var['sent']['link'] = e_SELF.'?mode=sent'; $var['sent']['perm'] = 'W'; if(getperms("0")) { $var['prefs']['text'] = LAN_PREFS; $var['prefs']['link'] = e_SELF.'?mode=prefs'; $var['prefs']['perm'] = '0'; $var['maint']['text'] = ADLAN_40; $var['maint']['link'] = e_SELF.'?mode=maint'; $var['maint']['perm'] = '0'; } show_admin_menu(LAN_MAILOUT_15, $action, $var); } function headerjs() { $text = " "; $mailAdmin = e107::getRegistry('_mailout_admin'); // $text .= $mailAdmin->_cal->load_files(); return $text; } ?>