/** * Get the email class to send a message. Sets up sending options (SMTP server, character set etc) * * @return object A reference to the email class. */ function GetEmailClass() { require_once ISC_BASE_PATH . "/lib/email.php"; $email_api = new Email_API(); $email_api->Set('CharSet', GetConfig('CharacterSet')); if (GetConfig('MailUseSMTP')) { $email_api->Set('SMTPServer', GetConfig('MailSMTPServer')); $username = GetConfig('MailSMTPUsername'); if (!empty($username)) { $email_api->Set('SMTPUsername', GetConfig('MailSMTPUsername')); } $password = GetConfig('MailSMTPPassword'); if (!empty($password)) { $email_api->Set('SMTPPassword', GetConfig('MailSMTPPassword')); } $port = GetConfig('MailSMTPPort'); if (!empty($port)) { $email_api->Set('SMTPPort', GetConfig('MailSMTPPort')); } } return $email_api; }
/** * ForgetEmail * Forgets the email settings ready for another send. * * @return Void Doesn't return anything. */ function ForgetEmail() { $this->ids_checked = false; $this->placeholders_changed = false; $this->checked_links = false; $this->listids = Array(); $this->statid = 0; $this->forcechecks = false; $this->tracklinks = false; $this->trackopens = false; $this->_FoundLinks = array( 'h' => array(), 't' => array(), 'm' => array() ); $this->_convertedlinks = array(); $this->disableunsubscribe = false; $this->SentBy = false; parent::ForgetEmail(); }
private function _handleSubmitAction() { // don't escape $template_dir = SENDSTUDIO_BASE_DIRECTORY . '/addons/surveys/templates'; $this->_template = GetTemplateSystem($template_dir); $this->_template->DefaultHtmlEscape = false; $formId = (int) IEM::requestGetGET('formId'); $postWidgets = IEM::requestGetPOST('widget'); // If there are files, take the values and place them in the $postWidgets array so they can // get validated and entered into the response values in the same manner. Uploads will be // handled separately. if (isset($_FILES['widget'])) { foreach ($_FILES['widget']['name'] as $widgetId => $widget) { foreach ($widget as $fields) { foreach ($fields as $fieldId => $field) { $postWidgets[$widgetId]['field'][$fieldId]['value'] = 'file_' . $field['value']; } } } } // If the form and widgets weren't posted in the format we require then redirect back if (!$formId) { $this->redirectToReferer(); } $surveyApi = $this->getApi(); $surveyApi->Load($formId); $surveyData = $surveyApi->GetData(); $errors = 0; $widgets = $surveyApi->getWidgets($formId); $widgetErrors = array(); /**** START OF ERROR VALIDATION ****/ // compile a list of widget ids so we can check the posted widgets against a list of // valid widget ids foreach ($widgets as $widgetKey => $widget) { if (!isset($widgetErrors[$widget['id']])) { $widgetErrors[$widget['id']] = array(); } // validate required fields if ($widget['is_required']) { // the widget is assumed blank until one of it's fields is found not blank $isBlank = true; $isOther = false; // make sure the required widget was even posted if (isset($postWidgets[$widget['id']])) { foreach ($postWidgets[$widget['id']]['field'] as $field) { if (isset($field['value'])) { $values = (array) $field['value']; foreach ($values as $value) { // get the value of an "other" field if it is one, otherwise just grab // the normal value if ($value == '__other__') { $isOther = true; $value = $field['other']; } // make sure the value isn't blank if ($this->_validateIsBlank($value) !== true) { $isBlank = false; } } } } } // if the widget is blank, flag an error if ($isBlank) { if ($isOther) { $error = GetLang('Addon_Surveys_ErrorRequiredOther'); } else { $error = GetLang('Addon_Surveys_ErrorRequired'); } $widgetErrors[$widget['id']][] = $error; $errors++; } if ($widget['type'] == 'file') { foreach ($postWidgets[$widget['id']]['field'] as $fieldid) { if (isset($fieldid['value'])) {$uploaded_file = $fieldid['value'];break;} } if (empty($uploaded_file) || $uploaded_file == "file_") { $error = GetLang('Addon_Surveys_ErrorRequired'); $widgetErrors[$widget['id']][] = $error; $errors++; } } } // validate file types if ($widget['type'] == 'file') { if (!empty($widget['allowed_file_types'])) { $typeArr = preg_split('/\s*,\s*/', strtolower($widget['allowed_file_types'])); $invalidType = false; // foreach of the passed fields (most likely 1) check and see if they are valid file types foreach ($postWidgets[$widget['id']]['field'] as $field) { $parts = explode('.', $field['value']); $ext = strtolower(end($parts)); // only if the field has a value we will test its file type if (trim($field['value']) != '' && !in_array($ext, $typeArr)) { $invalidType = true; } } // if the a file is not a valid file type, then the whole widget fails validation if ($invalidType) { $lastFileType = '<em>.' . array_pop($typeArr) . '</em>'; $firstFileTypes = '<em>.' . implode('</em>, <em>.', $typeArr) . '</em>'; $widgetErrors[$widget['id']][] = sprintf(GetLang('Addon_Surveys_ErrorInvalidFileType'), $lastFileType, $firstFileTypes); $errors++; } } } if (isset($postWidgets[$widget['id']])) { // add a value to the values array so it can be passed to the email feedback template @$widgets[$widgetKey]['values'] = $postWidgets[$widget['id']]['field']; } } // if there were errors, redirect back and display the errors if ($errors) { // set a global error message to alert the user to the specific errors IEM::sessionSet('survey.addon.' . $formId . '.errorMessage', $surveyData['error_message']); // set the widget errors so we can retrieve them for the user IEM::sessionSet('survey.addon.' . $formId . '.widgetErrors', $widgetErrors); $this->redirectToReferer(); } /**** END OF ERROR VALIDATION ****/ // isntantiate a new response object $response = $this->getSpecificApi('responses'); // associate the response to a particular form $response->surveys_id = $formId; // if the response was saved, then associate values to the response if ($response->Save()) { // foreach of the posted widgets, check to see if it belongs in this form and save it if it does foreach ($postWidgets as $postWidgetId => $postWidget) { // iterate through each field and enter it in the feedback foreach ($postWidget['field'] as $field) { // make sure it has a value first if (isset($field['value'])) { // since multiple values can be given, we treat them as an array $values = (array) $field['value']; foreach ($values as $value) { $responseValue = $this->getSpecificApi('responsesvalue'); // foreign key for the response id $responseValue->surveys_response_id = $response->GetId(); // set the widget id foreign key; widgets can have multiple field values and // should be treated as such $responseValue->surveys_widgets_id = $postWidgetId; // set the value of the feedback; this should be a single value since widgets // can have multiple feed back values if ($value == '__other__') { $responseValue->value = $field['other']; $responseValue->is_othervalue = 1; } else { // if file value exist we need to save the md5 name of the file in the database $responseValue->file_value = ""; if (substr($value, 0, 5) == "file_") { $value = str_replace("file_", "", $value); $responseValue->file_value = md5($value); } $responseValue->value = $value; $responseValue->is_othervalue = 0; } // save it $responseValue->Save(); } } } } // send an email if desired /** * Prepare for sending the email.. */ $widget_api = $this->getSpecificApi('widgets'); if ($surveyData['email_feedback']) { foreach ($widgets as &$widget) { $widget_api->populateFormData($widget); // set the values (normally 1, unless it's a list of checkboxes) $widget['values'] = $widget_api->getResponseValues($response->id); // get the other value $other = $widget_api->getOtherField(); // add the full url to the file if ($widget['type'] == 'file') { $attachment_url = "admin/index.php?Page=Addons&Addon=surveys&Action=DownloadAttach&ajax=1&formId=" . $formId . "&responseId=" . $response->id . "&value=" . base64_encode($widget['values'][0]['value']); $attachment_tag = SENDSTUDIO_APPLICATION_URL . "/" . $attachment_url; // . "'>" . $widget['values'][0]['value']; $widget['values'][0]['value'] = $attachment_tag; } if ($other) { // the other value will be the last one $otherValueIndex = count($widget['values']) - 1; $widget['values'][$otherValueIndex]['value'] = $other['other_label_text'] . ' ' . $widget['values'][$otherValueIndex]['value']; } } $viewUri = SENDSTUDIO_APPLICATION_URL . '/admin/index.php?Page=Addons&Addon=surveys&Action=viewresponses&surveyId=' . $surveyApi->id . '&responseId=' . $response->id; $editUri = SENDSTUDIO_APPLICATION_URL . '/admin/index.php?Page=Addons&Addon=surveys&Action=editresponse&surveyId=' . $surveyApi->id . '&responseId=' . $response->id; $this->_template->Assign('form', $surveyApi->GetData()); $this->_template->Assign('widgets', $widgets); $this->_template->Assign('emailBodyStart', sprintf(GetLang('Addon_Surveys_emailBodyStart'), $surveyApi->Get('name'))); $this->_template->Assign('emailViewLink', sprintf(GetLang('Addon_Surveys_emailViewLink'), $viewUri)); $this->_template->Assign('emailEditLink', sprintf(GetLang('Addon_Surveys_emailEditLink'), $editUri)); // parse the email template for its content $emailTemplate = $this->_template->ParseTemplate('email', true); require_once(IEM_PATH . '/ext/interspire_email/email.php'); $emailapi = new Email_API(); $emailapi->SetSmtp(SENDSTUDIO_SMTP_SERVER, SENDSTUDIO_SMTP_USERNAME, @base64_decode(SENDSTUDIO_SMTP_PASSWORD), SENDSTUDIO_SMTP_PORT); //if ($this->smtpserver) { // $emailapi->SetSmtp($this->smtpserver, $this->smtpusername, $this->smtppassword, $this->smtpport); //} $emailapi->ClearRecipients(); $emailapi->ForgetEmail(); $emailapi->Set('forcechecks', false); $to = ($surveyApi->Get('email')); $emailapi->AddRecipient($to); $emailapi->Set('FromAddress', (defined('SENDSTUDIO_EMAIL_ADDRESS') ? SENDSTUDIO_EMAIL_ADDRESS : $userobject->emailaddress)); $emailapi->Set('BounceAddress', SENDSTUDIO_EMAIL_ADDRESS); $emailapi->Set('CharSet', SENDSTUDIO_CHARSET); $subject = sprintf(GetLang('Addon_Surveys_emailSubject'), $surveyApi->Get('name')); $emailapi->Set('Subject', $subject); //email body $emailapi->AddBody('text', $emailTemplate); $status = $emailapi->Send(); if ($status['success'] != 1) { trigger_error(__CLASS__ . '::' . __METHOD__ . ' -- Was not able to send email: ' . serialize($status['failed']), E_USER_NOTICE); return false; } } // perform file uploading if (isset($_FILES['widget']['name'])) { $files = $_FILES['widget']['name']; foreach ($files as $widgetId => $widget) { foreach ($widget as $widgetKey => $fields) { foreach ($fields as $fieldId => $field) { // gather file information $name = $_FILES['widget']['name'][$widgetId]['field'][$fieldId]['value']; $type = $_FILES['widget']['type'][$widgetId]['field'][$fieldId]['value']; $tmpName = $_FILES['widget']['tmp_name'][$widgetId]['field'][$fieldId]['value']; $error = $_FILES['widget']['error'][$widgetId]['field'][$fieldId]['value']; $size = $_FILES['widget']['size'][$widgetId]['field'][$fieldId]['value']; // if the upload was successful to the temporary folder, move it if ($error == UPLOAD_ERR_OK) { $tempdir = TEMP_DIRECTORY; $upBaseDir = $tempdir . DIRECTORY_SEPARATOR . 'surveys'; $upSurveyDir = $upBaseDir . DIRECTORY_SEPARATOR . $formId; $upDir = $upSurveyDir . DIRECTORY_SEPARATOR . $response->GetId(); // if the base upload directory doesn't exist create it if (!is_dir($upBaseDir)) { mkdir($upBaseDir, 0755); } if (!is_dir($upSurveyDir)) { mkdir($upSurveyDir, 0755); } // if the upload directory doesn't exist create it if (!is_dir($upDir)) { mkdir($upDir, 0755); } // upload the file move_uploaded_file($tmpName, $upDir . DIRECTORY_SEPARATOR . $name); } } } } } } // if we are redirecting to a url, redirect them switch ($surveyData['after_submit']) { case 'show_uri': header('Location: ' . $surveyApi->show_uri); exit; break; case 'show_message': IEM::sessionSet('survey.addon.' . $formId . '.successMessage', $surveyApi->show_message); default: // redirect back $this->redirectToReferer(); } }
function SendAdminNotificationEmail($email_subject, $email_contents) { require_once(IEM_PATH . '/ext/interspire_email/email.php'); $emailapi = new Email_API(); $emailapi->SetSmtp(SENDSTUDIO_SMTP_SERVER, SENDSTUDIO_SMTP_USERNAME, @base64_decode(SENDSTUDIO_SMTP_PASSWORD), SENDSTUDIO_SMTP_PORT); if ($this->smtpserver) { $emailapi->SetSmtp($this->smtpserver, $this->smtpusername, $this->smtppassword, $this->smtpport); } $emailapi->ClearRecipients(); $emailapi->ForgetEmail(); $emailapi->Set('forcechecks', false); $notifyadmin_emails = explode(',', $this->adminnotify_email); foreach ($notifyadmin_emails as $notifyadmin_emails_key => $email) { $emailapi->AddRecipient(trim($email), '', 't'); } $emailapi->Set('FromName', false); $emailapi->Set('FromAddress', (defined('SENDSTUDIO_EMAIL_ADDRESS') ? SENDSTUDIO_EMAIL_ADDRESS : $userobject->emailaddress)); $emailapi->Set('BounceAddress', SENDSTUDIO_EMAIL_ADDRESS); $emailapi->Set('CharSet', SENDSTUDIO_CHARSET); $emailapi->Set('Subject', $email_subject); $emailapi->AddBody('text', $email_contents); $status = $emailapi->Send(); if ($status['success'] != 1) { trigger_error(__CLASS__ . '::' . __METHOD__ . ' -- Was not able to send email: ' . serialize($status['fail']), E_USER_NOTICE); return false; } return true; }
/** * NotifyAdmin * Notifies the administrator when a user has exceeded their quota * * @param Int $userid The userid the notification is for * @param Int $size_difference The number of emails the user has exceeded their limit by * @param Int $queuetime The time the queue was created at * @param String $langvar The langvar to use to describe which limit has been exceeded. This langvar is returned by the CheckUserStats/ReCheckuserStats functions. * @param Boolean $stopped_send Specify true if the send has been halted, false if the send is continuing * * @see Stats_API::ReCheckUserStats * @see Stats_API::CheckUserStats * * @return Void Returns nothing */ function NotifyAdmin($userid, $size_difference, $queuetime, $langvar, $stopped_send=false) { $user = GetUser($userid); $user_queuetime = AdjustTime($queuetime, false, GetLang('UserDateFormat')); require_once(IEM_PATH . '/ext/interspire_email/email.php'); $email_api = new Email_API(); $email_api->Set('Subject', GetLang('User_OverQuota_Subject')); $username = $user->Get('username'); if ($user->fullname) { $username = $user->fullname; $email_api->Set('FromName', $user->fullname); } else { $email_api->Set('FromName', GetLang('SendingSystem')); } if ($user->emailaddress) { $email_api->Set('FromAddress', $user->emailaddress); } else { $email_api->Set('FromAddress', GetLang('SendingSystem_From')); } $over_size = number_format($size_difference, 0, GetLang('NumberFormat_Dec'), GetLang('NumberFormat_Thousands')); $extra_mail = ''; if ($stopped_send) { $extra_mail = GetLang('User_OverQuota_StoppedSend'); } $message = sprintf(GetLang('User_OverQuota_Email'), $username, $user->Get('emailaddress'), $user_queuetime, GetLang('User_'.$langvar), $over_size, $extra_mail); $email_api->Set('Multipart', false); $email_api->AddBody('text', $message); $email_api->ClearAttachments(); $email_api->ClearRecipients(); $email_api->AddRecipient(SENDSTUDIO_EMAIL_ADDRESS, '', 't'); $email_api->Send(); $email_api->ForgetEmail(); // now send the user notification. $email_api->Set('Subject', GetLang('User_OverQuota_Subject')); $email_api->Set('FromName', ''); $email_api->Set('FromAddress', SENDSTUDIO_EMAIL_ADDRESS); $message = sprintf(GetLang('User_OverQuota_ToUser_Email'), $user_queuetime, GetLang('User_'.$langvar), $over_size, $extra_mail); $email_api->Set('Multipart', false); $email_api->AddBody('text', $message); $email_api->ClearAttachments(); $email_api->ClearRecipients(); $email_api->AddRecipient($user->emailaddress, '', 't'); $email_api->Send(); $email_api->ForgetEmail(); }
require_once(SENDSTUDIO_LANGUAGE_DIRECTORY . '/default/frontend.php'); /** * we don't need to include the api/lists.php file * because the AddToList function in the subscribers api does it already * because it checks the list exists before anything else. */ $lists_api = new Lists_API(); $lists_api->Load($function_params['mailinglist']); $listowneremail = $lists_api->Get('owneremail'); $listownername = $lists_api->Get('ownername'); require_once(IEM_PATH . '/ext/interspire_email/email.php'); $emailapi = new Email_API(); $emailapi->SetSMTP(SENDSTUDIO_SMTP_SERVER, SENDSTUDIO_SMTP_USERNAME, @base64_decode(SENDSTUDIO_SMTP_PASSWORD), SENDSTUDIO_SMTP_PORT); $emailapi->Set('CharSet', SENDSTUDIO_CHARSET); $emailapi->Set('Subject', GetLang('SubscriberNotification_Subject')); $emailapi->Set('FromName', false); $emailapi->Set('FromAddress', $listowneremail); $emailapi->Set('ReplyTo', $function_params['emailaddress']); $emailapi->Set('BounceAddress', SENDSTUDIO_EMAIL_ADDRESS); $emailapi->Set('Subject', sprintf(GetLang('SubscriberNotification_Subject_Lists'), $lists_api->name)); $body = ''; $body .= sprintf(GetLang('SubscriberNotification_Field'), GetLang('EmailAddress'), $function_params['emailaddress']);
/** * Evaluate credit warning conditions * * This method will evaluate credit warnings for a particular user. * It will dispatch warning emails accrodingly. * * @param record_Users|integer $user User record object or user ID * @return boolean Returns TRUE if successful, FALSE otherwise * * @todo fixed credits does not have warnings yet */ public static function creditEvaluateWarnings($user) { $userobject = null; $warnings = null; $this_month = mktime(0, 0, 0, date('n'), 1, date('Y')); $credit_left = null; // ----- PRE if ($user instanceof record_Users) { $userobject = $user; } else { $userobject = self::getRecordByID($user); } if (empty($userobject)) { trigger_error(__CLASS__ . '::' . __METHOD__ . ' -- User is not specified', E_USER_NOTICE); return false; } // ----- // Credit warnings are not enabled if (!SENDSTUDIO_CREDIT_WARNINGS) { return true; } require_once IEM_PUBLIC_PATH . '/functions/api/settings.php'; $tempSettingsAPI = new Settings_API(); $warnings = $tempSettingsAPI->GetCreditWarningsSettings(); // Does not hany any warnings setup? Well... we can't continue then. if (empty($warnings)) { return true; } $credit_left = self::creditAvailableTotal($userobject); //unlimited credit if ($credit_left === true) { return true; } $whichlevel = self::creditWhichWarning($userobject, $credit_left, $warnings); // If $whichlevel contains FALSE, that means there was something wrong // when trying to figure out which warning level it should send out. if ($whichlevel === false) { return true; } $userGroup = API_USERGROUPS::getRecordById($userobject->groupid); if (!isset($userGroup['limit_emailspermonth'])) { return false; } $userobject_permonth = (int) $userGroup['limit_emailspermonth']; $fixed = self::creditAvailableFixed($userobject); $monthly = self::creditAvailableThisMonth($userobject); if ($fixed === true) { $userobject_permonth = $monthly; } elseif ($monthly === true) { $userobject_permonth = $fixed; } if (!empty($whichlevel)) { $tempNames = explode(' ', $userobject->fullname); $tempLastName = array_pop($tempNames); $tempFirstName = implode(' ', $tempNames); $available_custom_fields_key = array('%%user_fullname%%', '%%user_firstname%%', '%%user_lastname%%', '%%credit_total%%', '%%credit_remains%%', '%%credit_remains_precentage%%', '%%credit_used%%', '%%credit_used_percentage%%'); $available_custom_fields_value = array($userobject->fullname, $tempFirstName, $tempLastName, $userobject_permonth, intval($userobject_permonth * ($credit_left / 100)), intval($credit_left), intval($userobject_permonth * ((100 - $credit_left) / 100)), intval(100 - $credit_left)); $email_contents = str_replace($available_custom_fields_key, $available_custom_fields_value, $whichlevel['emailcontents']); $email_subject = str_replace($available_custom_fields_key, $available_custom_fields_value, $whichlevel['emailsubject']); // ----- We found which warnings it is that we want to send out require_once IEM_PATH . '/ext/interspire_email/email.php'; $emailapi = new Email_API(); $emailapi->SetSmtp(SENDSTUDIO_SMTP_SERVER, SENDSTUDIO_SMTP_USERNAME, @base64_decode(SENDSTUDIO_SMTP_PASSWORD), SENDSTUDIO_SMTP_PORT); if ($userobject->smtpserver) { $emailapi->SetSmtp($userobject->smtpserver, $userobject->smtpusername, $userobject->smtppassword, $userobject->smtpport); } $emailapi->ClearRecipients(); $emailapi->ForgetEmail(); $emailapi->Set('forcechecks', false); $emailapi->AddRecipient($userobject->emailaddress, $userobject->fullname, 't'); $emailapi->Set('FromName', false); $emailapi->Set('FromAddress', defined('SENDSTUDIO_EMAIL_ADDRESS') ? SENDSTUDIO_EMAIL_ADDRESS : $userobject->emailaddress); $emailapi->Set('BounceAddress', SENDSTUDIO_EMAIL_ADDRESS); $emailapi->Set('CharSet', SENDSTUDIO_CHARSET); $emailapi->Set('Subject', $email_subject); $emailapi->AddBody('text', $email_contents); $status = $emailapi->Send(); if ($status['success'] != 1) { trigger_error(__CLASS__ . '::' . __METHOD__ . ' -- Was not able to send email: ' . serialize($status['failed']), E_USER_NOTICE); return false; } // ----- // ----- Update user record $db = IEM::getDatabase(); $status = $db->Query("UPDATE [|PREFIX|]users SET credit_warning_time = {$this_month}, credit_warning_percentage = {$whichlevel['creditlevel']} WHERE userid = {$userobject->userid}"); // Update user object in session // FIXME, we really need to make a special getter/setter for this $current_user = IEM::getCurrentUser(); if ($current_user && $current_user->userid == $userobject->userid) { $current_user->credit_warning_time = $this_month; $current_user->credit_warning_percentage = $whichlevel['creditlevel']; } // ----- } return true; }