Beispiel #1
0
 private function _send_by_mail(org_openpsa_invoices_invoice_dba $invoice)
 {
     $customerCard = org_openpsa_widgets_contact::get($invoice->customerContact);
     $contactDetails = $customerCard->contact_details;
     $invoice_label = $invoice->get_label();
     $invoice_date = date($this->_l10n_midcom->get('short date'), $invoice->date);
     // generate pdf, only if not existing yet
     $pdf_files = org_openpsa_helpers::get_attachment_urls($invoice, "pdf_file");
     if (count($pdf_files) == 0) {
         org_openpsa_invoices_handler_pdf::render_and_attach_pdf($invoice);
     }
     $mail = new org_openpsa_mail();
     // define replacements for subject / body
     $mail->parameters = array("INVOICE_LABEL" => $invoice_label, "INVOICE_DATE" => $invoice_date, "FIRSTNAME" => $contactDetails["firstname"], "LASTNAME" => $contactDetails["lastname"]);
     $mail->to = $contactDetails["email"];
     $mail->from = $this->_config->get('invoice_mail_from_address');
     $mail->subject = $this->_config->get('invoice_mail_title');
     $mail->body = $this->_config->get('invoice_mail_body');
     // attach pdf to mail
     if ($mail->can_attach()) {
         $pdf_files = org_openpsa_helpers::get_attachment_urls($invoice, "pdf_file");
         if (count($pdf_files) > 0) {
             foreach ($pdf_files as $guid => $url) {
                 $att = array();
                 $att['name'] = basename($url) . ".pdf";
                 $att['mimetype'] = "application/pdf";
                 $fp = fopen($url, "r");
                 if (!$fp) {
                     //Failed to open attachment for reading, skip the file
                     continue;
                 }
                 $att['content'] = '';
                 while (!feof($fp)) {
                     $att['content'] .= fread($fp, 4096);
                 }
                 fclose($fp);
                 debug_add("adding attachment '{$att['name']}' to attachments array of invoice mail");
                 $mail->attachments[] = $att;
                 unset($att);
             }
         }
     }
     if (!$mail->send()) {
         $this->_request_data['message']['message'] = sprintf($this->_l10n->get('unable to deliver mail: %s'), $mail->get_error_message());
         return false;
     } else {
         $invoice->set_parameter($this->_component, 'sent_by_mail', time());
         return $this->_mark_as_sent($invoice);
     }
 }
Beispiel #2
0
 private function _decode_email()
 {
     //Make sure we have the components we use and the Mail_mimeDecode package
     if (!class_exists('org_openpsa_mail_decoder')) {
         throw new midcom_error('library org.openpsa.mail could not be loaded.');
     }
     if (!class_exists('Mail_mimeDecode')) {
         throw new midcom_error('Cannot decode attachments, aborting.');
     }
     //Make sure the message_source is POSTed
     if (!array_key_exists('message_source', $_POST) || empty($_POST['message_source'])) {
         throw new midcom_error('_POST[\'message_source\'] not present or empty.');
     }
     $this->_decoder = new org_openpsa_mail_decoder();
     $this->_decoder->mime_decode($_POST['message_source']);
 }
Beispiel #3
0
 private function _send_form($values)
 {
     $mail = new org_openpsa_mail();
     if (!empty($values['subject'])) {
         $mail->subject = $values['subject'];
     } else {
         if (!empty($this->subject)) {
             $mail->subject = $this->subject;
         } else {
             $mail->subject = $this->_config->get('formmailer_subject');
         }
     }
     if (!empty($this->from)) {
         $mail->from = $this->from;
     } else {
         $mail->from = $this->_config->get('formmailer_from');
     }
     if (!empty($this->to)) {
         $mail->to = $this->to;
     } else {
         $mail->to = $this->_config->get('formmailer_to');
     }
     if (!empty($this->body)) {
         $mail->body = $this->body;
     } else {
         $mail->body = $this->_config->get('formmailer_body');
     }
     $parameters = array();
     foreach ($values as $field => $value) {
         $parameters[strtoupper($field)] = $value;
     }
     $mail->parameters = $parameters;
     if ($mail->send()) {
         echo $this->_l10n->get('form successfully sent');
     } else {
         echo $this->_l10n->get('error sending form');
     }
 }
Beispiel #4
0
 /**
  * The handler for the index article.
  *
  * @param mixed $handler_id the array key from the request array
  * @param array $args the arguments given to the handler
  * @param Array &$data The local request data.
  * @return boolean Indicating success.
  */
 function _handler_manageRequest($handler_id, $args, &$data)
 {
     $_MIDCOM->auth->require_admin_user();
     $this->_request_data['name'] = "fi.kilonkipinat.accountregistration";
     $this->_update_breadcrumb_line($handler_id);
     $title = $this->_l10n_midcom->get('fi.kilonkipinat.accountregistration');
     $_MIDCOM->set_pagetitle(":: {$title}");
     $prefix = $this->_request_data['prefix'];
     $request = new fi_kilonkipinat_accountregistration_accountrequest_dba(trim($args[0]));
     if (!isset($request) || !isset($request->guid) || $request->guid == '' || $request->guid != $args[0]) {
         debug_push_class(__CLASS__, __FUNCTION__);
         debug_pop();
         $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, 'Failed to load request, cannot continue. Last Midgard error was: ' . midcom_application::get_error_string());
         // This will exit.
     }
     $this->_request_data['request'] = $request;
     if (isset($_POST) && isset($_POST['username'])) {
         if (isset($_POST['isduplicate']) && $_POST['isduplicate'] == '1') {
             $request->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_INVALID;
             $request->update();
             $message['title'] = $this->_l10n_midcom->get("Poistettu");
             $message['content'] = $this->_l10n_midcom->get("Kyseinen hakemus on merkattu duplikaatiksi, ts poistettu.");
         } else {
             if (isset($_POST['merge_user_guid']) && $_POST['merge_user_guid'] != '') {
                 $person = new fi_kilonkipinat_account_person_dba(trim($_POST['merge_user_guid']));
             } else {
                 $qb = fi_kilonkipinat_account_person_dba::new_query_builder();
                 $qb->add_constraint('username', '=', trim($_POST['username']));
                 $results = $qb->execute();
                 if (count($results) > 0) {
                     $message['title'] = $this->_l10n_midcom->get("error");
                     $message['content'] = $this->_l10n_midcom->get("Kyseinen tyyppi on jo olemassa");
                 } else {
                     $person = new fi_kilonkipinat_account_person_dba();
                     $person->username = trim($_POST['username']);
                     $person->create();
                 }
             }
             if (isset($person)) {
                 $person->firstname = $request->firstname;
                 $person->lastname = $request->lastname;
                 $person->email = $request->email;
                 $password = fi_kilonkipinat_accountregistration_viewer::generatePassword($this->_config->get('password_length'));
                 // Enforce crypt mode
                 $salt = chr(rand(64, 126)) . chr(rand(64, 126));
                 $crypt_password = crypt($password, $salt);
                 $person->password = $crypt_password;
                 $person->update();
                 if (isset($_POST['add_to_groups']) && count($_POST['add_to_groups']) > 0) {
                     foreach ($_POST['add_to_groups'] as $group_guid) {
                         $group = new midcom_db_group($group_guid);
                         if (isset($group) && isset($group->guid) && $group->guid == $group_guid) {
                             $membership = new midcom_db_member();
                             $membership->uid = $person->id;
                             $membership->gid = $group->id;
                             $membership->create();
                         }
                     }
                 }
                 $person->set_privilege('midgard:owner', "user:{$person->guid}");
                 $request->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_RESOLVED;
                 $request->personGuid = $person->guid;
                 $request->update();
                 $subject = 'Tunnuksesi kilonkipinat.fi-sivustolle';
                 $body = sprintf('Hei %s', $person->firstname);
                 $body .= "\n\n";
                 $body .= sprintf('käyttäjätunnus: %s', $person->username);
                 $body .= "\n\n";
                 $body .= sprintf('salasana: %s', $password);
                 $mail = new org_openpsa_mail();
                 $mail->from = $this->_config->get('mail_sender_title') . ' <' . $this->_config->get('mail_sender_address') . '>';
                 $mail->to = $person->firstname . ' ' . $person->lastname . ' <' . $person->email . '>';
                 $mail->body = $body;
                 $mail->subject = $subject;
                 $message = array();
                 if ($mail->send('mail')) {
                     $message['title'] = $this->_l10n_midcom->get("Onnistui");
                     $message['content'] = '';
                 } else {
                     $message['title'] = $this->_l10n_midcom->get("error");
                     $message['content'] = $this->_l10n_midcom->get("Oops, something went wrong.");
                 }
             }
         }
         $this->_request_data['message'] = $message;
     }
     return true;
 }
Beispiel #5
0
 /**
  * The handler for the index article.
  *
  * @param mixed $handler_id the array key from the request array
  * @param array $args the arguments given to the handler
  * @param Array &$data The local request data.
  * @return boolean Indicating success.
  */
 function _handler_approveReset($handler_id, $args, &$data)
 {
     $message = array();
     $reset_request = new fi_kilonkipinat_accountregistration_resetrequest_dba(trim($args[0]));
     if (isset($reset_request) && isset($reset_request->guid) && $reset_request->guid == trim($args[0]) && $reset_request->status == FI_KILONKIPINAT_ACCOUNTREGISTRATION_PASSWORDRESETREQUEST_STATUS_NEW) {
         $_MIDCOM->auth->request_sudo('fi.kilonkipinat.accountregistration');
         $person = new midcom_db_person($reset_request->person);
         if (isset($person) && isset($person->guid) && $person->guid != '' && $person->id == $reset_request->person) {
             $password = fi_kilonkipinat_accountregistration_viewer::generatePassword($this->_config->get('password_length'));
             // Enforce crypt mode
             $salt = chr(rand(64, 126)) . chr(rand(64, 126));
             $crypt_password = crypt($password, $salt);
             $person->password = $crypt_password;
             if ($person->update()) {
                 $reset_request->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_PASSWORDRESETREQUEST_STATUS_RESOLVED;
                 $reset_request->update();
                 $message['title'] = "Onnistui";
                 $message['content'] = "Tarkista sähköpostisi";
                 $subject = sprintf('Uusi salasananne', $_SERVER['SERVER_NAME']);
                 $body = sprintf('Hei %s', $person->firstname);
                 $body .= "\n\n";
                 $body .= sprintf('Uusi salasanne on %s', $password);
                 $mail = new org_openpsa_mail();
                 $mail->from = $this->_config->get('mail_sender_title') . ' <' . $this->_config->get('mail_sender_address') . '>';
                 $mail->to = $person->firstname . ' ' . $person->lastname . ' <' . $person->email . '>';
                 $mail->body = $body;
                 $mail->subject = $subject;
                 if ($mail->send('mail')) {
                     $message['title'] = "Onnistui";
                     $message['content'] = "Tarkista sähköpostisi.";
                 } else {
                     $message['title'] = "Virhe";
                     $message['content'] = "Oho, jotain meni pieleen";
                 }
             }
         }
         $_MIDCOM->auth->drop_sudo('fi.kilonkipinat.accountregistration');
     } else {
         $message['title'] = "Virhe";
         $message['content'] = "Ei löytynyt pyyn";
     }
     $this->_request_data['message'] = $message;
     return true;
 }
Beispiel #6
0
 /**
  * Internal helper for processing the batch change of passwords
  */
 private function _process_batch_change()
 {
     // Set the mail commo parts
     $mail = new org_openpsa_mail();
     $mail->from = $this->_config->get('message_sender');
     $mail->encoding = 'UTF-8';
     // Success switch
     $success = true;
     // Get the context prefix
     $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
     // Change every user or continue to next on failure - failures will show UI messages
     foreach ($_POST['midcom_admin_user'] as $id) {
         try {
             $person = new midcom_db_person($id);
         } catch (midcom_error $e) {
             midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('failed to get the user with id %s'), $id), 'error');
             $success = false;
             continue;
         }
         // This shortcut is used in case of errors
         $person_edit_url = "<a href=\"{$prefix}__mfa/asgard_midcom.admin.user/edit/{$person->guid}\">{$person->name}</a>";
         // Cannot send the email if address is not specified
         if (!$person->email) {
             midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('no email address defined for %s'), $person_edit_url), 'error');
             continue;
         }
         // Recipient
         $mail->to = $person->email;
         // Store the old password
         $person->set_parameter('midcom.admin.user', 'old_password', $person->password);
         // Get a new password
         $password = midcom_admin_user_plugin::generate_password(8);
         $mail->body = $_POST['body'];
         $mail->subject = $_POST['subject'];
         $mail->parameters = array('PASSWORD' => $password, 'FROM' => $this->_config->get('message_sender'), 'LONGDATE' => strftime('%c'), 'SHORTDATE' => strftime('%x'), 'TIME' => strftime('%X'), 'PERSON' => $person);
         // Send the message
         if ($mail->send()) {
             // Set the password
             $person->password = "******";
             if (!$person->update()) {
                 midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('failed to update the password for %s'), $person_edit_url));
                 $success = false;
             }
         } else {
             throw new midcom_error("Failed to send the mail, SMTP returned error " . $mail->get_error_message());
         }
     }
     // Show UI message on success
     if ($success) {
         midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), $this->_l10n->get('passwords updated and mail sent'));
     }
 }
Beispiel #7
0
</p>
<table>
    <tr>
        <td background="<?php 
    echo MIDCOM_STATIC_URL;
    ?>
/org.openpsa.core/default/rorschach-opaque.gif">
            <p>Table cell with background image.</p>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum odio. Praesent est odio, aliquet vitae, hendrerit at, porttitor vitae, tellus. Morbi scelerisque dolor. Maecenas nunc. Morbi pretium posuere neque. Nullam cursus laoreet magna. Nam sed tellus et purus rhoncus lacinia. Aenean nonummy tempus eros. Mauris ut nisl. Suspendisse est mauris, porta a, pharetra ut, euismod ac, elit. Fusce id diam sit amet lorem vulputate iaculis. Suspendisse gravida quam sed nulla aliquam vulputate. Donec convallis, diam vitae congue semper, velit lectus rutrum justo, nec imperdiet pede eros sit amet ante.</p>
            <p>Phasellus eget tellus. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam gravida, orci eu lobortis semper, ipsum sem sagittis est, vel imperdiet metus turpis nec enim. Sed justo turpis, pretium a, cursus eget, bibendum eu, tortor. Sed sed est. Quisque gravida justo in lorem. Nullam in lacus id metus scelerisque faucibus. Nam tempor, lorem sed venenatis tempor, ligula purus euismod enim, vitae porttitor dui justo non ipsum. Aenean eros libero, varius quis, sodales eu, consequat aliquet, pede. Ut faucibus vulputate ligula. Curabitur dui. Nullam lacus ipsum, lacinia eu, hendrerit a, tincidunt quis, mi. Nullam dapibus, lacus quis euismod ultrices, lectus nisi vulputate nisl, quis molestie nulla metus feugiat risus. Vivamus sit amet diam. Vestibulum eget risus sit amet nulla vulputate porta. Duis quis massa. In id leo eu metus imperdiet blandit. Nulla ipsum. Nam luctus, leo a interdum blandit, tortor elit posuere ligula, quis molestie nisl nibh hendrerit tellus. Donec in lectus nec est blandit scelerisque.</p>
            <p>Donec varius tempus nulla. Integer diam eros, euismod vel, rhoncus sed, vulputate at, eros. Proin tincidunt. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Morbi a odio. Suspendisse rhoncus lacus id libero. Proin libero. Cras ornare felis quis eros. Sed quis lectus. Integer sed arcu. In ullamcorper metus vel nunc. Vivamus ut lectus. Vivamus at orci. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce sit amet pede a nisl tristique egestas. Donec eu pede. Morbi nisl. Fusce pede dolor, aliquam ac, bibendum in, semper quis, sem. </p>
        </td>
    </tr>
</table>

<em>Test person</em></textarea><br/>
            <input type="submit" value="Send" />
        </p>
    </form>
<?php 
} else {
    $mail = new org_openpsa_mail($_POST['backend']);
    $mail->to = $_POST['to'];
    $mail->from = $_POST['from'];
    $mail->subject = $_POST['subject'];
    $mail->html_body = $_POST['html_body'];
    $mail->embed_images();
    $ret = $mail->send();
    echo "mail->send returned {$ret}<br>\n";
}
echo "</p>\n";
Beispiel #8
0
 private function _send_email($httpcode, $msg)
 {
     if (!isset($GLOBALS['midcom_config']['error_actions'][$httpcode]['email']) || empty($GLOBALS['midcom_config']['error_actions'][$httpcode]['email'])) {
         // No recipient specified, skip
         return;
     }
     if (!midcom::get('componentloader')->is_installed('org.openpsa.mail')) {
         debug_add("Email sending library org.openpsa.mail, used for error notifications is not installed", MIDCOM_LOG_WARN);
         return;
     }
     $mail = new org_openpsa_mail();
     $mail->to = $GLOBALS['midcom_config']['error_actions'][$httpcode]['email'];
     $mail->from = "\"MidCOM error notifier\" <webmaster@{$_SERVER['SERVER_NAME']}>";
     $mail->subject = "[{$_SERVER['SERVER_NAME']}] {$msg}";
     $mail->body = "{$_SERVER['SERVER_NAME']}:\n{$msg}";
     $stacktrace = $this->get_function_stack();
     $mail->body .= "\n" . implode("\n", $stacktrace);
     if (!$mail->send()) {
         debug_add("failed to send error notification email to {$mail->to}, reason: " . $mail->get_error_message(), MIDCOM_LOG_WARN);
     }
 }
Beispiel #9
0
 /**
  * The handler for the index article.
  *
  * @param mixed $handler_id the array key from the request array
  * @param array $args the arguments given to the handler
  * @param Array &$data The local request data.
  * @return boolean Indicating success.
  */
 function _handler_index($handler_id, $args, &$data)
 {
     $this->_request_data['name'] = "fi.kilonkipinat.accountregistration";
     $this->_update_breadcrumb_line($handler_id);
     $title = $this->_l10n_midcom->get('fi.kilonkipinat.accountregistration');
     $_MIDCOM->set_pagetitle(":: {$title}");
     $prefix = $this->_request_data['prefix'];
     $this->_request_data['sort_order'] = $this->_config->get('sort_order');
     if (isset($_POST) && isset($_POST['action_type']) && ($_POST['action_type'] == 'reset_password' || $_POST['action_type'] == 'registration')) {
         $_MIDCOM->auth->request_sudo('fi.kilonkipinat.accountregistration');
         if ($_POST['action_type'] == 'reset_password') {
             if (trim($_POST['username']) == '') {
                 $error_msg = 'Täytä käyttäjätunnus-kenttä';
             } else {
                 $qb = fi_kilonkipinat_account_person_dba::new_query_builder();
                 $qb->add_constraint('username', '=', trim($_POST['username']));
                 $qb->set_limit(1);
                 $user = $qb->execute();
                 if (isset($user) && count($user) > 0) {
                     $reset_request = new fi_kilonkipinat_accountregistration_resetrequest_dba();
                     $reset_request->username = $user[0]->username;
                     $reset_request->person = $user[0]->id;
                     $reset_request->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_PASSWORDRESETREQUEST_STATUS_NEW;
                     $reset_request->create();
                     $reset_request_quid = $reset_request->guid;
                     $subject = sprintf('Salasanan vaihto palvelimella %s', $_SERVER['SERVER_NAME']);
                     $body = sprintf('Hei %s', $user[0]->firstname);
                     $body .= "\n\n";
                     $body .= sprintf($this->_l10n_midcom->get('Pyysit salasanasi resetointia palvelimella %s'), $_SERVER['SERVER_NAME']);
                     $body .= "\n\n";
                     $body .= sprintf($this->_l10n_midcom->get('Resetoidaksesi salasanasi käyttäjätunnukselle %s, klikkaa alla olevaa linkkiä'), $user[0]->username);
                     $body .= "\n\n";
                     $body .= 'http://' . $_SERVER['SERVER_NAME'] . $prefix . 'approve_reset/' . $reset_request_quid . '/';
                     $mail = new org_openpsa_mail();
                     $mail->from = $this->_config->get('mail_sender_title') . ' <' . $this->_config->get('mail_sender_address') . '>';
                     $mail->to = $user[0]->firstname . ' ' . $user[0]->lastname . ' <' . $user[0]->email . '>';
                     $mail->body = $body;
                     $mail->subject = $subject;
                     if ($mail->send('mail')) {
                         $success_msg = $this->_l10n_midcom->get("Salasanan resetointipyyntö vastaanotettu, katso sähköpostiasi.");
                     }
                 }
             }
         } elseif ($_POST['action_type'] == 'registration') {
             if ($_POST['firstname'] == '' || $_POST['lastname'] == '' || $_POST['email'] == '') {
                 $error_msg = 'Täytä kaikki pakolliset kentät';
             } else {
                 $accountrequest = new fi_kilonkipinat_accountregistration_accountrequest_dba();
                 $accountrequest->firstname = $_POST['firstname'];
                 $accountrequest->lastname = $_POST['lastname'];
                 $accountrequest->email = $_POST['email'];
                 $accountrequest->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_NEW;
                 $accountrequest->create();
                 $accountrequest_quid = $accountrequest->guid;
                 $subject = sprintf('Käyttäjätunnuksen rekisteröinti palvelimelle %s', $_SERVER['SERVER_NAME']);
                 $body = sprintf('Hei %s', $accountrequest->firstname);
                 $body .= "\n\n";
                 $body .= sprintf($this->_l10n_midcom->get('Käyttäjätunnuksen rekisteröinti palvelimelle %s.'), $_SERVER['SERVER_NAME']);
                 $body .= "\n\n";
                 $body .= $this->_l10n_midcom->get('Varmistaaksesi sähköpostisi, klikkaa alla olevaa linkkiä');
                 $body .= "\n\n";
                 $body .= 'http://' . $_SERVER['SERVER_NAME'] . $prefix . 'validate_email/' . $accountrequest_quid . '/';
                 $mail = new org_openpsa_mail();
                 $mail->from = $this->_config->get('mail_sender_title') . ' <' . $this->_config->get('mail_sender_address') . '>';
                 $mail->to = $accountrequest->firstname . ' ' . $accountrequest->lastname . ' <' . $accountrequest->email . '>';
                 $mail->body = $body;
                 $mail->subject = $subject;
                 if ($mail->send('mail')) {
                     $success_msg = 'Käyttäjätunnuksen rekisteröinti vastaanotettu, katso sähköpostisi';
                 }
             }
         }
         $_MIDCOM->auth->drop_sudo('fi.kilonkipinat.accountregistration');
     }
     $message = array();
     if (isset($success_msg) && $success_msg != '') {
         $message['title'] = 'Onnistui';
         $message['content'] = $success_msg;
         $this->_request_data['message'] = $message;
     }
     if (isset($error_msg) && $error_msg != '') {
         $message['title'] = 'Virhe';
         $message['content'] = $error_msg;
         $this->_request_data['message'] = $message;
     }
     return true;
 }
Beispiel #10
0
 /**
  * can be called by various handlers
  *
  * @param string password: leave blank for auto generated
  */
 public function create_account($person_guid, $username, $usermail, $password = "", $send_welcome_mail = false, $auto_relocate = true)
 {
     //quick validation
     if (empty($person_guid)) {
         $this->errstr = "cannot identify user: no guid given";
         return false;
     }
     if (empty($username)) {
         $this->errstr = "cannot create account: no username given";
         return false;
     }
     if ($send_welcome_mail && empty($usermail)) {
         $this->errstr = "cannot deliver welcome mail: no usermail adress given";
         return false;
     }
     // Check if we get the person
     $this->_person = new midcom_db_person($person_guid);
     $this->_person->require_do('midgard:update');
     //need to generate password?
     if (empty($password)) {
         $generated_password = true;
         $password = $this->generate_safe_password($this->_config->get("min_password_length"));
     } else {
         $generated_password = false;
     }
     $this->_account = new midcom_core_account($this->_person);
     //an account already existing?
     if ($this->_account->get_password()) {
         $this->errstr = "Creating new account for existing account is not possible";
         return false;
     }
     //try creating
     $success = $this->set_account($username, $password);
     if (!$success) {
         $this->errstr = "couldnt set account, reason: " . $this->errstr;
         return false;
     }
     //send welcome mail?
     if ($send_welcome_mail) {
         $mail = new org_openpsa_mail();
         $mail->to = $usermail;
         $mail->from = $this->_config->get('welcome_mail_from_address');
         $mail->subject = $this->_config->get('welcome_mail_title');
         $mail->body = $this->_config->get('welcome_mail_body');
         // Make replacements to body
         $mail->parameters = array("USERNAME" => $username, "PASSWORD" => $password);
         if (!$mail->send()) {
             $this->errstr = "Unable to deliver welcome mail: " . $mail->get_error_message();
             return false;
         }
     } else {
         /*
          * no welcome mail was sent:
          * if the password was auto generated show it in an ui message
          */
         if ($generated_password) {
             midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.user'), sprintf($this->_l10n->get("account_creation_success"), $username, $password), 'ok');
         }
     }
     if ($auto_relocate) {
         // Relocate to group view
         $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
         midcom::get()->relocate("{$prefix}view/{$this->_person->guid}/");
         // This will exit
     } else {
         if (!empty($this->errstr)) {
             throw new midcom_error('Could not create account: ' . $this->errstr);
         }
         return true;
     }
 }
        $midgard_users[strtolower($person->email)] = $person->name;
    }
    $persons_found = array();
    $persons_new = array();
    foreach ($moinmoin_users as $email => $user) {
        if (array_key_exists($email, $midgard_users)) {
            // This person is already in DB
            $persons_found[$email] = $midgard_users[$email];
        } else {
            // This is a new person
            $persons_new[$email] = $user;
        }
    }
    echo "<p>" . count($persons_found) . " users are already in database and " . count($persons_new) . " are new</p>\n";
    foreach ($persons_new as $email => $name) {
        $mail = new org_openpsa_mail();
        $mail->to = $email;
        $mail->from = $_POST['from'];
        $mail->subject = $_POST['subject'];
        $mail->body = $_POST['message'];
        // Make replacements to body
        $mail->parameters = array('USER' => $name);
        $ret = $mail->send();
        if (!$ret) {
            echo "<p>failed to send notification email to {$mail->to}, reason: " . $mail->get_error_message() . "</p>\n";
        } else {
            echo "<p>Sent notification to {$name} ({$email})</p>\n";
        }
    }
} else {
    ?>
Beispiel #12
0
        <p>
            Backend: <select name="backend">
                        <option value="try_default">Component default(s)</option>
                        <option value="mail_smtp">PEAR Mail/SMTP</option>
                        <option value="mail_sendmail">PEAR Mail/Sendmail</option>
                        <option value="mail">PHP mail()</option>
                     </select><br/>
            From: <input name="from" size=50 type="text" value="*****@*****.**"/><br/>
            To: <input name="to" size=50 type="text" value="*****@*****.**" /><br/>
            Subject: <input name="subject" size=50 type="text" value="Testing o.o.mail with special chars (ÄäÖöÅå€)"/><br/>
            Message:<br/>
            <textarea rows=40 cols=80 name="body">Test body with special chars (Ää Öö Åå €)

/Test person</textarea><br/>
            <input type="submit" value="Send" />
        </p>
    </form>
<?php 
} else {
    $mail = new org_openpsa_mail($_POST['backend']);
    $mail->subject = $_POST['subject'];
    $mail->body = $_POST['body'];
    $mail->to = $_POST['to'];
    $mail->from = $_POST['from'];
    $ret = $mail->send();
    echo "mail->send returned {$ret}<br>\n";
    if (!$ret) {
        echo $mail->get_error_message();
    }
}
echo "</p>\n";
Beispiel #13
0
 private function _send_email_member($member, &$subject, &$content, &$from, &$data_array)
 {
     if ($this->_check_member_deny($member, 'email')) {
         return;
     }
     if (!isset($GLOBALS['org_openpsa_directmarketing_campaign_message_send_i'])) {
         $GLOBALS['org_openpsa_directmarketing_campaign_message_send_i'] = 0;
     }
     $GLOBALS['org_openpsa_directmarketing_campaign_message_send_i']++;
     $token = $this->_create_email_token();
     $person =& org_openpsa_contacts_person_dba::get_cached($member->person);
     debug_add("Called for member #{$member->id}, (person #{$person->id}: {$person->rname})");
     //Make sure we have some backend and parameters for it defined
     if (!isset($data_array['mail_send_backend'])) {
         $data_array['mail_send_backend'] = 'try_default';
     }
     if (!isset($data_array['mail_send_backend_params'])) {
         $data_array['mail_send_backend_params'] = array();
     }
     //Check for bounce detector usage
     if (array_key_exists('bounce_detector_address', $data_array) && !empty($data_array['bounce_detector_address'])) {
         $bounce_address = str_replace('TOKEN', $token, $data_array['bounce_detector_address']);
         $mail->headers['Return-Path'] = $bounce_address;
         //Force bouncer as backend if default specified
         if (!array_key_exists('mail_send_backend', $data_array) || empty($data_array['mail_send_backend']) || $data_array['mail_send_backend'] == 'try_default') {
             $data_array['mail_send_backend'] = 'bouncer';
         }
     }
     $mail = new org_openpsa_mail($data_array['mail_send_backend'], $data_array['mail_send_backend_params']);
     $mail->to = $person->email;
     $subject = $member->personalize_message($subject, self::EMAIL_TEXT, $person);
     if ($this->test_mode) {
         $mail->subject = "[TEST] {$subject}";
     } else {
         $mail->subject = $subject;
     }
     $mail->from = $from;
     if (isset($data_array['reply-to'])) {
         $mail->headers['Reply-To'] = $data_array['reply-to'];
     }
     //Set some List-xxx headers to avoid auto-replies and in general to be a good netizen
     $mail->headers['List-Id'] = "<{$this->guid}@{$_SERVER['SERVER_NAME']}>";
     $mail->headers['List-Unsubscribe'] = '<' . $member->get_unsubscribe_url(false, $person) . '>';
     debug_add('mail->from: ' . $mail->from . ', mail->to: ' . $mail->to . ', mail->subject: ' . $mail->subject);
     switch ($this->orgOpenpsaObtype) {
         case self::EMAIL_TEXT:
             $mail->body = $member->personalize_message($content, $this->orgOpenpsaObtype, $person);
             break;
         case self::EMAIL_HTML:
             $mail->html_body = $member->personalize_message($content, $this->orgOpenpsaObtype, $person);
             if (array_key_exists('htmlemail_force_text_body', $data_array) && strlen($data_array['htmlemail_force_text_body']) > 0) {
                 $mail->body = $member->personalize_message($data_array['htmlemail_force_text_body'], $this->orgOpenpsaObtype, $person);
             }
             // Allow sensing only HTML body if requested
             if (array_key_exists('htmlemail_onlyhtml', $data_array) && !empty($data_array['htmlemail_onlyhtml'])) {
                 $mail->allow_only_html = true;
             }
             // Skip embedding if requested
             if (array_key_exists('htmlemail_donotembed', $data_array) && !empty($data_array['htmlemail_donotembed'])) {
                 // Skip embedding, do something else ??
             } else {
                 //The mail class uses a caching scheme to avoid fetching embedded objects again.
                 $mail->embed_images($this);
             }
             //Handle link detection
             if (array_key_exists('link_detector_address', $data_array) && !empty($data_array['link_detector_address'])) {
                 $link_address = str_replace('TOKEN', $token, $data_array['link_detector_address']);
                 $mail->html_body = $this->_insert_link_detector($mail->html_body, $link_address);
             }
             break;
         default:
             debug_add('Invalid message type, aborting', MIDCOM_LOG_ERROR);
             return array(false, $mail);
     }
     //Go trough DM2 types array for attachments
     reset($data_array['dm_types']);
     foreach ($data_array['dm_types'] as $field => $typedata) {
         if (empty($typedata->attachments_info)) {
             continue;
         }
         // If you don't want to add the image as an attachment to the field, add show_attachment customdata-definition to
         // schema and set it to false
         if (isset($typedata->storage->_schema->fields[$field]) && is_array($typedata->storage->_schema->fields[$field]) && isset($typedata->storage->_schema->fields[$field]['customdata']) && is_array($typedata->storage->_schema->fields[$field]['customdata']) && isset($typedata->storage->_schema->fields[$field]['customdata']['show_attachment']) && $typedata->storage->_schema->fields[$field]['customdata']['show_attachment'] === false) {
             continue;
         }
         foreach ($typedata->attachments_info as $attachment_data) {
             $att = array();
             $att['name'] = $attachment_data['filename'];
             $att['mimetype'] = $attachment_data['mimetype'];
             $fp = $attachment_data['object']->open('r');
             if (!$fp) {
                 //Failed to open attachment for reading, skip the file
                 continue;
             }
             $att['content'] = '';
             /* PONDER: Should we cache the content somehow so that we only need to read it once per request ??
                We would save some file opens at the expense of keeping the contents in memory (potentially very expensive) */
             while (!feof($fp)) {
                 $att['content'] .= fread($fp, 4096);
             }
             fclose($fp);
             debug_add("adding attachment '{$att['name']}' from field '{$field}' to attachments array");
             $mail->attachments[] = $att;
             unset($att);
         }
     }
     $status = $mail->send();
     if ($status) {
         debug_add('Mail sent to: ' . $mail->to);
         if (!$this->test_mode) {
             $member->create_receipt($this->id, org_openpsa_directmarketing_campaign_messagereceipt_dba::SENT, $token);
         }
     } else {
         $message = sprintf('FAILED to send mail to: %s, reason: %s', $mail->to, $mail->get_error_message());
         debug_add($message, MIDCOM_LOG_WARN);
         if (!$this->test_mode) {
             $params = array(array('domain' => 'org.openpsa.directmarketing', 'name' => 'send_error_message', 'value' => $message));
             $member->create_receipt($this->id, ORG_OPENPSA_MESSAGERECEIPT_FAILURE, $token, $params);
         }
         if ($this->send_output) {
             midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.directmarketing', 'org.openpsa.directmarketing'), sprintf(midcom::get('i18n')->get_string('FAILED to send mail to: %s, reason: %s', 'org.openpsa.directmarketing'), $mail->to, $mail->get_error_message()), 'error');
         }
     }
     unset($mail);
     return $status;
 }
Beispiel #14
0
 /**
  * This is a simple function which generates and sends a password reset mail.
  *
  * @param midcom_db_person $person The newly created person account.
  */
 private function _send_reset_mail($person, $password)
 {
     $from = $this->_config->get('lostpassword_reset_mail_sender');
     if (!$from) {
         $from = $person->email;
     }
     $parameters = array('PERSON' => $person, 'PASSWORD' => $password);
     $mail = new org_openpsa_mail();
     $mail->from = $from;
     $mail->to = $person->email;
     $mail->subject = $this->_config->get('lostpassword_reset_mail_subject');
     $mail->body = $this->_config->get('lostpassword_reset_mail_body');
     $mail->parameters = $parameters;
     $mail->send();
 }
Beispiel #15
0
 /**
  * Sends the 'content' version of the message as email to subscribers via org.openpsa.mail
  */
 public function send_email($message)
 {
     if (empty($this->recipient->email)) {
         return false;
     }
     $mail = new org_openpsa_mail();
     $mail->to = $this->recipient->email;
     $growl_to = $mail->to;
     if (array_key_exists('growl_to', $message)) {
         $growl_to = $message['growl_to'];
         unset($message['growl_to']);
     }
     $sender = null;
     if (array_key_exists('from', $message) && !empty($message['from'])) {
         midcom::get('auth')->request_sudo();
         $user = midcom::get('auth')->get_user($message['from']);
         $sender =& $user->get_storage();
         midcom::get('auth')->drop_sudo();
         // Avoid double dump
         unset($message['from']);
     }
     $default_sender = $this->_config->get('default_sender');
     if (!is_null($sender) && $sender->email) {
         $mail->from = '"' . $sender->name . '" <' . $sender->email . '>';
     } else {
         if (!is_null($default_sender) && !empty($default_sender)) {
             $mail->from = $default_sender;
         } else {
             $mail->from = '"OpenPSA Notifier" <noreply@' . $_SERVER['SERVER_NAME'] . '>';
         }
     }
     if (array_key_exists('title', $message)) {
         // PHP5-TODO: Must be copy by value
         $mail->subject = $message['title'];
         // Avoid double dump
         unset($message['title']);
     } else {
         $mail->subject = 'org.openpsa.notifications message (no title provided)';
     }
     if (array_key_exists('attachments', $message)) {
         // PHP5-TODO: Must be copy by value
         $mail->attachments = $message['attachments'];
         // Do not dump attachments as content
         unset($message['attachments']);
     }
     if (array_key_exists('content', $message)) {
         $mail->body = $message['content'];
     } else {
         // No explicit content defined, dump all keys
         foreach ($message as $key => $value) {
             // TODO (nice-to-have): RFC "fold" the value
             $mail->body .= "{$key}: {$value}\n";
         }
     }
     $ret = $mail->send();
     if (!$ret) {
         debug_add("failed to send notification email to {$mail->to}, reason: " . $mail->get_error_message(), MIDCOM_LOG_WARN);
     } else {
         midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.notifications', 'org.openpsa.notifications'), sprintf(midcom::get('i18n')->get_string('notification sent to %s', 'org.openpsa.notifications'), $growl_to));
     }
     return $ret;
 }
Beispiel #16
0
            // Generate a random password and activation Hash
            $password = '******';
            $length = 8;
            // Create a random password
            for ($i = 0; $i < $length; $i++) {
                $password .= chr(rand(97, 122));
            }
            $person->password = $password;
            $person->create();
            $group = new midcom_db_group();
            $group->get_by_path('/kkp_admins/editoijat');
            $member = new midcom_db_member();
            $member->uid = $person->id;
            $member->gid = $group->id;
            $member->create();
            $mail = new org_openpsa_mail();
            $mail->from = '*****@*****.**';
            $mail->subject = '[KKp-web] Tunnukset sivustolle';
            $mail->body = "Hei\n\nTunnus: " . $username;
            $mail->body .= "\nSalasana: " . str_replace('**', '', $password);
            $mail->to = $person->email;
            $mail->send();
            $status = 'Tunnukset lähetetty.';
        }
    }
    $_MIDCOM->auth->drop_sudo();
}
?>

<h1>&(view['title']:h);</h1>