コード例 #1
0
ファイル: email.php プロジェクト: bgreiner/orsee
function email__send_reply_email($email)
{
    global $settings, $settings__server_url, $expadmindata;
    // checks
    $continue = true;
    $email_regex = '/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i';
    if (isset($_REQUEST['replytype']) && in_array(trim($_REQUEST['replytype']), array('replyall', 'reply'))) {
        $reply_type = trim($_REQUEST['replytype']);
    } else {
        $reply_type = "reply";
    }
    if (!isset($_REQUEST['send_to']) || !$_REQUEST['send_to']) {
        $continue = false;
        message(lang('error_email__to_address_not_given_or_wrong_format'));
    }
    if ($continue) {
        $to_adds = explode(",", $_REQUEST['send_to']);
        foreach ($to_adds as $k => $to_add) {
            $to_adds[$k] = trim($to_add);
            if (!preg_match($email_regex, trim($to_add))) {
                $continue = false;
            }
            if (!$continue) {
                message(lang('error_email__to_address_not_given_or_wrong_format'));
            }
        }
    }
    if ($reply_type == 'reply') {
        $cc_field = 'send_cc_reply';
    } else {
        $cc_field = 'send_cc_replyall';
    }
    if (isset($_REQUEST[$cc_field]) && $_REQUEST[$cc_field]) {
        $cc_adds = explode(",", $_REQUEST[$cc_field]);
    } else {
        $cc_adds = array();
    }
    foreach ($cc_adds as $k => $cc_add) {
        $cc_adds[$k] = trim($cc_add);
        if (!preg_match($email_regex, trim($cc_add))) {
            $continue = false;
        }
        if (!$continue) {
            message(lang('error_email__cc_address_wrong_format'));
        }
    }
    if (isset($_REQUEST['send_subject'])) {
        $subject = $_REQUEST['send_subject'];
    } else {
        $subject = "";
    }
    if (!$subject) {
        $continue = false;
        message(lang('error_email__subject_is_empty'));
    }
    if (isset($_REQUEST['send_body'])) {
        $body = $_REQUEST['send_body'];
    } else {
        $body = "";
    }
    if (!$body) {
        $continue = false;
        message(lang('error_email__message_body_is_empty'));
    }
    if ($continue) {
        $s['message_id'] = '<' . sha1(microtime()) . '@' . $settings__server_url . '>';
        $s['message_type'] = 'reply';
        $s['admin_id'] = $expadmindata['admin_id'];
        $s['timestamp'] = time();
        $s['from_address'] = $settings['support_mail'];
        $s['to_address'] = implode(",", $to_adds);
        $s['cc_address'] = implode(",", $cc_adds);
        $s['subject'] = $subject;
        $s['body'] = $body;
        $s['mailbox'] = $email['mailbox'];
        $s['experiment_id'] = $email['experiment_id'];
        $s['session_id'] = $email['session_id'];
        $s['participant_id'] = $email['participant_id'];
        $s['assigned_to'] = $email['assigned_to'];
        $s['thread_id'] = $email['thread_id'];
        $s['thread_time'] = time();
        $s['flag_read'] = $email['flag_read'];
        $s['flag_assigned_to_read'] = $email['flag_assigned_to_read'];
        $s['flag_processed'] = $email['flag_processed'];
        $s['flag_deleted'] = $email['flag_deleted'];
        // send message
        $headers = "From: " . $s['from_address'] . "\r\n";
        if ($s['cc_address']) {
            $headers = $headers . "Cc: " . $s['cc_address'] . "\r\n";
        }
        $done = experimentmail__mail($s['to_address'], $s['subject'], $s['body'], $headers);
        // save to database
        $done = orsee_db_save_array($s, "emails", $s['message_id'], "message_id");
        // update thread time
        $done = email__update_thread_time($s['thread_id'], $s['thread_time']);
        $redir = 'admin/emails_view.php?message_id=' . urlencode($email['message_id']);
        if (isset($_REQUEST['hide_header']) && $_REQUEST['hide_header']) {
            $redir .= '&hide_header=true';
        }
        return $redir;
    } else {
        return false;
    }
}
コード例 #2
0
ファイル: experimentmail.php プロジェクト: danorama/orsee
function experimentmail__send_participant_statistics()
{
    global $lang, $settings;
    $now = time();
    $from = $settings['support_mail'];
    $headers = "From: " . $from . "\r\n";
    // remember the current language for later reset
    $old_lang = lang('lang');
    // preload details with current language
    $maillang = $old_lang;
    $statistics = stats__get_textstats_for_email();
    $subject = load_language_symbol('subject_pool_statistics', $maillang) . ' ' . ortime__format($now, 'hide_time:true');
    // get experimenters who want to receive the statistics
    $query = "SELECT *\n            FROM " . table('admin') . "\n            WHERE get_statistics_mail='y'\n            AND disabled='n'\n            ORDER BY language";
    $result = or_query($query);
    $i = 0;
    $rec_count = pdo_num_rows($result);
    while ($admin = pdo_fetch_assoc($result)) {
        if ($admin['language'] != $maillang) {
            $maillang = $admin['language'];
            $lang = load_language($maillang);
            $statistics = stats__get_textstats_for_email();
            $subject = load_language_symbol('subject_pool_statistics', $maillang) . ' ' . ortime__format($now, 'hide_time:true', $maillang);
        }
        $mailtext = load_mail("admin_participant_statistics_mailtext", $maillang) . "\n\n" . $statistics . "\n" . experimentmail__get_admin_footer($maillang, $admin) . "\n";
        $message = process_mail_template($mailtext, $admin);
        $done = experimentmail__mail($admin['email'], $subject, $message, $headers);
        if ($done) {
            $i++;
        }
    }
    // reset language
    if ($maillang != $old_lang) {
        $lang = load_language($old_lang);
    }
    return "statistics sent to " . $i . " out of " . $rec_count . " administrators\n";
}