Example #1
0
function email__show_email($email, $open_reply = false, $open_note = false)
{
    global $color, $settings, $expadmindata;
    // load remaining email thread
    $pars = array(':thread_id' => $email['thread_id']);
    $query = "SELECT * FROM " . table('emails') . "\n            WHERE thread_id = :thread_id\n            AND message_id != thread_id\n            ORDER BY timestamp";
    $result = or_query($query, $pars);
    $replies = array();
    while ($r = pdo_fetch_assoc($result)) {
        $replies[] = $r;
    }
    // set mail thread as read when is unread
    if (!$email['flag_read'] || !$email['flag_assigned_to_read']) {
        $flags = array();
        if (!$email['flag_read']) {
            $flags['read'] = 1;
        }
        if ($settings['email_module_allow_assign_emails'] == 'y') {
            if (!$email['flag_assigned_to_read']) {
                global $expadmindata;
                $assigned_to = db_string_to_id_array($email['assigned_to']);
                if (in_array($expadmindata['admin_id'], $assigned_to)) {
                    $flags['assigned_to_read'] = 1;
                }
            }
        } else {
            if (!$email['flag_assigned_to_read']) {
                $flags['assigned_to_read'] = 1;
            }
        }
        if (count($flags) > 0) {
            email__update_flags($email['thread_id'], $flags);
        }
    }
    // guess participant if not already set
    $guess_parts = array();
    $guess_part_message = "";
    if (!$email['participant_id']) {
        $guess_parts = email__guess_participant($email);
        if (count($guess_parts) == 0) {
            $guess_part_message = lang('cannot_guess');
        } else {
            $guess_part_message = lang('guess');
            $email['participant_id'] = $guess_parts[0]['participant_id'];
            $participant = $guess_parts[0];
        }
    } else {
        $participant = orsee_db_load_array("participants", $email['participant_id'], "participant_id");
    }
    if (!isset($participant['participant_id'])) {
        $participant = array();
    }
    // guess experiment/session if not already set
    $guess_exp_sess = array();
    $guess_expsess_message = "";
    if (!$email['mailbox'] && !$email['experiment_id']) {
        $guess_exp_sess = email__guess_expsess($email);
        if (count($guess_exp_sess) == 0) {
            $guess_expsess_message = lang('cannot_guess');
        } else {
            $guess_expsess_message = lang('guess');
            $email['experiment_id'] = $guess_exp_sess[0]['experiment_id'];
            $email['session_id'] = $guess_exp_sess[0]['session_id'];
        }
    } else {
        if ($email['session_id']) {
            $session = orsee_db_load_array("sessions", $email['session_id'], "session_id");
        }
        if (isset($session['experiment_id'])) {
            $email['experiment_id'] = $session['experiment_id'];
        }
        if ($email['experiment_id']) {
            $experiment = orsee_db_load_array("experiments", $email['experiment_id'], "experiment_id");
        }
        if (!isset($session['session_id'])) {
            $session = array();
        }
    }
    if (!isset($session['session_id'])) {
        $session = array();
    }
    if (!isset($experiment['experiment_id'])) {
        $experiment = array();
    }
    $orig_to = explode(",", $email['to_address']);
    if ($email['cc_address']) {
        $orig_cc = explode(",", $email['cc_address']);
    } else {
        $orig_cc = array();
    }
    echo '<table class="or_formtable" style="background: ' . $color['options_box_background'] . '" CELLPADDING="3" CELLSPACING="3" >
        <TR class="emailtable"><TD align="right">';
    $allow_change = email__is_allowed($email, $experiment, 'change');
    $allow_reply = email__is_allowed($email, $experiment, 'reply');
    $allow_note = email__is_allowed($email, $experiment, 'note');
    $allow_delete = email__is_allowed($email, $experiment, 'delete');
    if ($allow_reply && count($orig_to) + count($orig_cc) > 1) {
        $reply_all_button = true;
    } else {
        $reply_all_button = false;
    }
    email__show_buttons($email, $reply_all_button, $allow_delete, $allow_reply, $allow_note);
    echo '</TD></TR>';
    echo '<TR class="emailtable"><TD>';
    echo '  <FORM action="' . thisdoc() . '" METHOD="POST"">
        <INPUT type="hidden" name="message_id" value="' . $email['message_id'] . '">';
    if (isset($_REQUEST['hide_header']) && $_REQUEST['hide_header']) {
        echo '<INPUT type="hidden" name="hide_header" value="true">';
    }
    echo '<TABLE  class="or_panel" style="background: ' . $color['content_background_color'] . '; width: 100%; padding: 2px;" CELLPADDING="3" CELLSPACING="0">';
    // show settings to classify this email
    echo '<TR style="background: ' . $color['panel_title_background'] . '; color: ' . $color['panel_title_textcolor'] . ';">
        <TD align=right>' . lang('mailbox_experiment_session') . ':</TD>
        <TD align=left valign=middle>';
    if ($allow_change) {
        email__expsess_select($email, $session, $experiment, $participant);
        if ($guess_expsess_message) {
            echo '<span class="small" style="border: 1px solid ' . $color['message_border'] . '; background: ' . $color['message_background'] . '; color: ' . $color['message_text'] . '"> (' . str_replace(" ", "&nbsp", $guess_expsess_message) . ')</span>';
        }
    } else {
        if ($email['experiment_id']) {
            echo $experiment['experiment_name'];
            if ($email['session_id']) {
                echo ', ' . session__build_name($related_sessions[$email['session_id']]);
            }
        } elseif ($email['mailbox']) {
            $mailboxes = email__load_mailboxes();
            echo $mailboxes[$email['mailbox']];
        } else {
            echo lang('mailbox_not_assigned');
        }
    }
    if ($email['experiment_id']) {
        echo '<BR><A HREF="experiment_show.php?experiment_id=' . urlencode($email['experiment_id']) . '" style="color: ' . $color['panel_title_textcolor'] . ';">[' . str_replace(" ", "&nbsp", lang('view_experiment')) . ']</A>';
    }
    if ($email['session_id']) {
        echo ' <A HREF="experiment_participants_show.php?experiment_id=' . urlencode($email['experiment_id']) . '&session_id=' . urlencode($email['session_id']) . '" style="color: ' . $color['panel_title_textcolor'] . ';">[' . str_replace(" ", "&nbsp", lang('view_session')) . ']</A>';
    }
    echo '  </TD>
            <TD align=center valign=middle rowspan=3>';
    echo lang('email_processed?') . '<BR>';
    if ($allow_change) {
        echo '<select id="processed_switch" name="flag_processed">';
        echo '<option value="0"';
        if (!$email['flag_processed']) {
            echo ' SELECTED';
        }
        echo '></option>';
        echo '<option value="1"';
        if ($email['flag_processed']) {
            echo ' SELECTED';
        }
        echo '></option>';
        echo '</select>';
        $out = "<script type=\"text/javascript\">\n        \$(function() {\n            \$('#processed_switch').switchy();\n            \$('#processed_switch').on('change', function(){\n                var firstOption = \$(this).children('option').first().val();\n                var lastOption = \$(this).children('option').last().val();\n                var bgColor = '#bababa';\n                if (\$(this).val() == firstOption){\n                    bgColor = '#DC143C';\n                } else if (\$(this).val() == lastOption){\n                    bgColor = '#008000';\n                }\n                \$(this).next().next().children().first().css(\"background-color\", bgColor);\n            });\n            \$('#processed_switch').trigger('change');\n        });\n        </script>";
        echo $out;
    } else {
        if ($email['flag_processed']) {
            echo lang('y');
        } else {
            echo lang('n');
        }
    }
    echo '  </TD>
            <TD align=center valign=middle rowspan=3>';
    if ($allow_change) {
        echo '<INPUT class="button small" type="submit" name="update" value="' . lang('save') . '">';
    }
    echo '  </TD>
            </TR>';
    echo '  <TR style="background: ' . $color['panel_title_background'] . '; color: ' . $color['panel_title_textcolor'] . ';">
            <TD align=right>' . lang('participant') . ':</TD>
            <TD align=left valign=middle>';
    if ($allow_change) {
        email__participant_select($email, $participant, $guess_parts);
        if ($guess_part_message) {
            echo '<span class="small" style="border: 1px solid ' . $color['message_border'] . '; background: ' . $color['message_background'] . '; color: ' . $color['message_text'] . '"> (' . str_replace(" ", "&nbsp", $guess_part_message) . ')</span>';
        }
    } else {
        if ($email['participant_id']) {
            $cols = participant__get_result_table_columns('email_participant_guesses_list');
            $items = array();
            foreach ($cols as $k => $c) {
                $items[] = $participant[$k];
            }
            echo implode(" ", $items);
        } else {
            echo lang('mailbox_not_assigned');
        }
    }
    if ($email['participant_id']) {
        echo '&nbsp;<A HREF="participants_edit.php?participant_id=' . urlencode($email['participant_id']) . '" style="color: ' . $color['panel_title_textcolor'] . ';">[' . str_replace(" ", "&nbsp", lang('view_profile')) . ']</A> ';
    }
    echo '</TD>
        </TR>';
    if ($settings['email_module_allow_assign_emails'] == 'y') {
        echo '  <TR style="background: ' . $color['panel_title_background'] . '; color: ' . $color['panel_title_textcolor'] . ';">
                <TD align=right>' . lang('assign_email_to') . ':</TD>
                <TD align=left valign=middle class="small">';
        if ($allow_change) {
            echo '<span style="color: ' . $color['body_text'] . ';">' . experiment__experimenters_select_field("assigned_to", db_string_to_id_array($email['assigned_to']), true, array('cols' => 30)) . '</span>';
        } else {
            if ($email['assigned_to']) {
                echo experiment__list_experimenters($email['assigned_to'], false, true);
            } else {
                echo '-';
            }
        }
        echo '</TD>
            </TR>';
    }
    // show headers
    email__show_headers($email);
    // show email body
    email__show_body($email);
    // attachments
    email__show_attachments($email);
    echo '
        </TABLE>
        </FORM>
        </TD></TR>
        ';
    echo '<TR><TD>';
    echo '<TABLE width=100% border=0>';
    foreach ($replies as $remail) {
        echo '<TR><TD valign="top">';
        if ($remail['message_type'] == 'reply') {
            echo icon('reply', '', ' fa-2x', ' color: #666666;', 'reply');
        } elseif ($remail['message_type'] == 'note') {
            echo icon('file-text-o', '', ' fa-2x', ' color: #666666;', 'internal note');
        } elseif ($remail['message_type'] == 'incoming') {
            echo icon('envelope-square', '', ' fa-2x', ' color: #666666;', 'incoming');
        }
        echo '</TD><TD>&nbsp;&nbsp;</TD><TD>';
        echo '<TABLE  class="or_panel" style="background: ' . $color['content_background_color'] . '; width: 100%; padding: 2px;" CELLPADDING="3" CELLSPACING="0">';
        // show headers
        email__show_headers($remail);
        // show email body
        email__show_body($remail);
        // attachments
        email__show_attachments($remail);
        echo '</TABLE>
        </TD></TR>
        ';
    }
    echo '</TABLE></TD></TR>';
    if (count($replies) > 0) {
        echo '<TR class="emailtable"><TD align="right">';
        email__show_buttons($email, $reply_all_button, false, $allow_reply, $allow_note);
        echo '</TD></TR>';
    }
    // reply field
    if ($allow_reply) {
        echo '<TR id="replyfield"><TD>';
        echo '<A name="replyform"></A>';
        show_message();
        echo '<FORM name="send_email" action="' . thisdoc() . '#replyform" method="POST">
             <INPUT type="hidden" name="message_id" value="' . $email['message_id'] . '">';
        if (isset($_REQUEST['hide_header']) && $_REQUEST['hide_header']) {
            echo '<INPUT type="hidden" name="hide_header" value="true">';
        }
        if (isset($_REQUEST['replytype']) && $_REQUEST['replytype'] == 'reply') {
            $replytype = 'reply';
        } else {
            $replytype = 'replyall';
        }
        echo '<INPUT id="replytype" type="hidden" name="replytype" value="' . $replytype . '">';
        echo '<TABLE class="or_panel" style="background: ' . $color['content_background_color'] . '; width: 100%;">';
        echo '<TR><TD colspan=2 align=right>
                <I id="close_reply" class="fa fa-times-circle-o fa-2x"></I>
                </TD></TR>';
        echo '<TR><TD align=right>' . lang('email_from') . ':</TD>
                    <TD width=90% align=left>' . $settings['support_mail'] . '</TD>
                </TR>';
        if (isset($_REQUEST['send_to'])) {
            $to = $_REQUEST['send_to'];
        } elseif (isset($email['reply_to_address']) && $email['reply_to_address']) {
            $to = $email['reply_to_address'];
        } else {
            $to = $email['from_address'];
        }
        echo '<TR>
                 <TD align=right>' . lang('email_to') . ':</TD><TD align=left>
                    <INPUT type="text" name="send_to" size=60 maxlength=255 value="' . $to . '">
                </TD>
                </TR>';
        if (isset($_REQUEST['send_cc_replyall'])) {
            $cc_replyall = $_REQUEST['send_cc_replyall'];
        } else {
            $cc_arr = array();
            if (count($orig_to) > 1) {
                foreach ($orig_to as $oto) {
                    if ($oto != $settings['support_mail'] && !in_array($oto, $cc_arr)) {
                        $cc_arr[] = $oto;
                    }
                }
            }
            foreach ($orig_cc as $occ) {
                if ($occ != $settings['support_mail'] && !in_array($occ, $cc_arr)) {
                    $cc_arr[] = $occ;
                }
            }
            $cc_replyall = implode(",", $cc_arr);
        }
        echo '<TR id="ccfield_replyall">
                 <TD align=right>' . lang('email_cc') . ':</TD><TD align=left>
                    <INPUT type="text" name="send_cc_replyall" rows=2 cols=60 value="' . $cc_replyall . '">
                </TD>
                </TR>';
        if (isset($_REQUEST['send_cc_reply'])) {
            $cc_reply = $_REQUEST['send_cc_reply'];
        } else {
            $cc_reply = '';
        }
        echo '<TR id="ccfield_reply">
                 <TD align=right>' . lang('email_cc') . ':</TD><TD align=left>
                    <INPUT type="text" name="send_cc_reply" rows=2 cols=60 value="' . $cc_reply . '">
                </TD>
                </TR>';
        if (isset($_REQUEST['send_subject'])) {
            $subject = $_REQUEST['send_subject'];
        } else {
            $subject = lang('email_subject_re:') . ' ' . $email['subject'];
        }
        echo '<TR>
                <TD align=right>' . lang('email_subject') . ':</TD>
                <TD align=left><INPUT type="text" name="send_subject" size=60 maxlength=255 value="' . $subject . '"></TD>
                </TR>';
        if (isset($_REQUEST['send_body'])) {
            $body = $_REQUEST['send_body'];
        } else {
            $body = "\n\n\n\n" . $email['from_name'] . ' <' . $email['from_address'] . '> ' . lang('email_xxx_wrote') . ':' . "\n" . email__cite_text($email['body']);
        }
        echo '<TR><TD></TD><TD>
                <textarea name="send_body" wrap="virtual" rows="20" cols="60">' . $body . '</textarea>
            </TD></TR>';
        echo '<TR><TD colspan="2" align="center"><INPUT type="submit" class="button" name="send" value="' . lang('send_email') . '"></TD></TR>';
        echo '</TABLE>';
        echo '</FORM>';
        echo '</TD></TR>';
    }
    // note field
    if ($allow_note) {
        echo '<TR id="notefield"><TD>';
        echo '<A name="noteform"></A>';
        show_message();
        echo '<FORM name="add_note" action="' . thisdoc() . '#noteform" method="POST">
             <INPUT type="hidden" name="message_id" value="' . $email['message_id'] . '">';
        if (isset($_REQUEST['hide_header']) && $_REQUEST['hide_header']) {
            echo '<INPUT type="hidden" name="hide_header" value="true">';
        }
        echo '<TABLE class="or_panel" style="background: ' . $color['content_background_color'] . '; width: 100%;">';
        echo '<TR><TD colspan="3" align=right>
                <I id="close_note" class="fa fa-times-circle-o fa-2x"></I>
                </TD></TR>';
        echo '<TR><TD valign="top" rowspan="3">';
        echo icon('file-text-o', '', ' fa-2x', ' color: #666666;', 'internal note');
        echo '</TD><TD rowspan="3">&nbsp;&nbsp;</TD>';
        echo '<TD>' . lang('email_internal_note_by') . ' ' . $expadmindata['fname'] . ' ' . $expadmindata['lname'] . '</TD>
                </TR>';
        if (isset($_REQUEST['note_body'])) {
            $body = $_REQUEST['note_body'];
        } else {
            $body = "";
        }
        echo '<TR><TD>
                <textarea name="note_body" wrap="virtual" rows="20" cols="60">' . $body . '</textarea>
            </TD></TR>';
        echo '<TR><TD align="center"><INPUT type="submit" class="button" name="addnote" value="' . lang('add') . '"></TD></TR>';
        echo '</TABLE>';
        echo '</FORM>';
        echo '</TD></TR>';
    }
    echo '</TABLE>';
    echo '  <script type="text/javascript"> ';
    if (!$open_reply) {
        echo '$("#replyfield").hide(); ';
    } else {
        if ($replytype == 'reply') {
            echo ' $("#ccfield_replyall").hide(); ';
        } else {
            echo ' $("#ccfield_reply").hide(); ';
        }
    }
    if ($allow_note && !$open_note) {
        echo '$("#notefield").hide(); ';
    }
    if ($allow_note) {
        echo '
                $(".note_button").click(function() {
                    $(".emailtable :input").attr("disabled", true);
                    $("#notefield").show();
                    $("html, body").animate({
                        scrollTop: $("#notefield").offset().top
                    }, 1000);
                });
                $("#close_note").click(function() {
                    $("#notefield").hide();
                    $(".emailtable :input").attr("disabled", false);
                });';
    }
    if ($allow_reply) {
        echo '
                $(".reply_button").click(function() {
                    $(".emailtable :input").attr("disabled", true);
                    $("#replytype").val("reply");
                    $("#ccfield_replyall").hide();
                    $("#ccfield_reply").show();
                    $("#replyfield").show();
                    $("html, body").animate({
                        scrollTop: $("#replyfield").offset().top
                    }, 1000);
                });
                $(".replyall_button").click(function() {
                    $(".emailtable :input").attr("disabled", true);
                    $("#replytype").val("replyall");
                    $("#ccfield_replyall").show();
                    $("#ccfield_reply").hide();
                    $("#replyfield").show();
                    $("html, body").animate({
                        scrollTop: $("#replyfield").offset().top
                    }, 1000);
                });
                $("#close_reply").click(function() {
                    $("#ccfield").hide();
                    $("#replyfield").hide();
                    $("#ccfield_replyall").hide();
                    $("#ccfield_reply").hide();
                    $(".emailtable :input").attr("disabled", false);
                });';
    }
    echo '
            </script>';
}
Example #2
0
                    $redirect = email__delete_undelete_email($email, 'delete');
                }
                break;
            case "undelete":
                if (email__is_allowed($email, array(), 'delete')) {
                    $redirect = email__delete_undelete_email($email, 'undelete');
                }
                break;
            case "send":
                if (email__is_allowed($email, array(), 'reply')) {
                    $open_reply = true;
                    $redirect = email__send_reply_email($email);
                }
                break;
            case "addnote":
                if (email__is_allowed($email, array(), 'note')) {
                    $open_note = true;
                    $redirect = email__add_internal_note($email);
                }
                break;
            default:
        }
        if ($redirect) {
            redirect($redirect);
        }
    }
}
if ($proceed) {
    // show email
    echo '<BR><BR><center><TABLE width="80%" border=0><TR><TD align="center">';
    email__show_email($email, $open_reply, $open_note);