Esempio n. 1
0
    /**
     * Creates view a contact's deteails + timeline history
     *
     * @param   int
     */
    function leadout_render_contact_detail($lead_id)
    {
        $li_contact = new LI_Contact();
        $li_contact->set_hashkey_by_id($lead_id);
        $li_contact->get_contact_history();
        $lead_name = $li_contact->history->lead->lead_first_name || $li_contact->history->lead->lead_last_name ? $li_contact->history->lead->lead_first_name . ' ' . $li_contact->history->lead->lead_last_name : '';
        $lead_email = $li_contact->history->lead->lead_email;
        $lead_source = isset($li_contact->history->lead->lead_source) ? leadout_strip_params_from_url($li_contact->history->lead->lead_source) : '';
        ?>

        <?php 
        if (isset($_POST['edit_tags'])) {
            $updated_tags = array();
            foreach ($_POST as $name => $value) {
                if (strstr($name, 'tag_slug_')) {
                    array_push($updated_tags, $value);
                }
            }
            $li_contact->update_contact_tags($lead_id, $updated_tags);
            $li_contact->history->tags = $li_contact->get_contact_tags($li_contact->hashkey);
        }
        echo '<div class="contact-top-navigation">';
        if ($li_contact->history->lead->lead_deleted) {
            $li_contact->display_error_message_for_merged_contact($li_contact->history->lead->lead_email);
        }
        if (isset($_GET['stats_dashboard'])) {
            echo '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=leadout_stats">&larr; Stat Dashboard</a>';
        } else {
            if (isset($_GET['redirect_to'])) {
                if (strstr($_GET['redirect_to'], 'contact_type')) {
                    $url_parts = parse_url(urldecode($_GET['redirect_to']));
                    parse_str($url_parts['query'], $url_vars);
                    if (isset($url_vars['contact_type']) && $url_vars['contact_type']) {
                        echo '<a href="' . $_GET['redirect_to'] . '">&larr; All ' . ucwords($url_vars['contact_type']) . '</a>';
                    } else {
                        echo '<a href="' . $_GET['redirect_to'] . '">&larr; All Contacts</a>';
                    }
                } else {
                    echo '<a href="' . $_GET['redirect_to'] . '">&larr; All Contacts</a>';
                }
            } else {
                echo '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=leadout_contacts">&larr; All Contacts</a>';
            }
        }
        echo '</div>';
        // contact-top-navigation
        echo '<div class="contact-deatils-column">';
        echo '<div class="leadout-meta-section">';
        echo '<div class="leadout-postbox__content">';
        echo '<img class="contact-header-avatar leadout-dynamic-avatar_' . substr($lead_id, -1) . '" height="65px" width="65px" src="https://api.hubapi.com/socialintel/v1/avatars?email=' . $lead_email . '"/>';
        echo '<div class="contact-header-info">';
        echo '<h2 class="contact-name">' . ($lead_name ? $lead_name : $lead_email) . '</h2>';
        echo '</div>';
        echo '</div>';
        echo '</div>';
        // leadout-meta-section
        if (!$li_contact->history->lead->lead_deleted) {
            echo '<div class="leadout-meta-section">';
            echo '<h4 class="leain-meta-header">Tags - <a class="thickbox contact-edit-tags" ' . ($li_contact->history->lead->lead_deleted ? 'style="display: none;"' : '') . ' href="#TB_inline?width=400&height=400&inlineId=edit-contact-tags">edit</a></h4>';
            echo '<div class="leadout-postbox__content">';
            foreach ($li_contact->history->tags as $tag) {
                if ($tag->tag_set) {
                    echo '<a class="contact-tag" href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=leadout_contacts&contact_type=' . $tag->tag_slug . '">' . $tag->tag_text . '</a>';
                }
            }
            ?>

                        <?php 
            add_thickbox();
            ?>
                        <div id="edit-contact-tags" style="display:none;">
                            <h2>Edit Tags - <?php 
            echo $li_contact->history->lead->lead_email;
            ?>
</h2>
                            <form id="edit_tags" action="" method="POST">

                                <?php 
            foreach ($li_contact->history->tags as $tag) {
                echo '<p>';
                echo '<label for="tag_slug_' . $tag->tag_slug . '">';
                echo '<input name="tag_slug_' . $tag->tag_slug . '" type="checkbox" id="tag_slug_' . $tag->tag_slug . '" value="' . $tag->tag_id . '" ' . ($tag->tag_set ? ' checked' : '') . '>' . $tag->tag_text . '</label>';
                echo '</p>';
            }
            ?>

                                <input type="hidden" name="edit_tags" value="1"/>
                                <p class="submit">
                                    <input type="submit" name="submit" id="submit" class="button button-primary" value="Save Tags">
                                </p>
                            </form>
                        </div>

                        <?php 
            echo '</div>';
            // leadout-postbox__content
            echo '</div>';
            // leadout-meta-section
            echo '<div class="leadout-meta-section">';
            echo '<h4 class="leain-meta-header">Tracking Info</h4>';
            echo '<div class="leadout-postbox__content">';
            echo '<table class="leadout-meta-table"><tbody>';
            if ($li_contact->history->lead->lead_first_name) {
                echo '<tr>';
                echo '<th>Name</th>';
                echo '<td>' . $li_contact->history->lead->lead_first_name . ' ' . $li_contact->history->lead->lead_last_name . '</td>';
                echo '</tr>';
            }
            echo '<tr>';
            echo '<th>Email</th>';
            echo '<td> <a href="mailto:' . $lead_email . '">' . $lead_email . '</a></td>';
            echo '</tr>';
            echo '<tr>';
            echo '<th>Original source</th>';
            echo '<td>' . ($li_contact->history->lead->lead_source ? '<a href="' . $li_contact->history->lead->lead_source . '">' . $lead_source . '</a>' : 'Direct') . '</td>';
            echo '</tr>';
            echo '<tr>';
            echo '<th>First visit</th>';
            echo '<td>' . self::date_format_contact_stat($li_contact->history->lead->first_visit) . '</td>';
            echo '</tr>';
            echo '<tr>';
            echo '<th>Pageviews</th>';
            echo '<td>' . $li_contact->history->lead->total_pageviews . '</td>';
            echo '</tr>';
            echo '<tr>';
            echo '<th>Form submissions</th>';
            echo '<td>' . $li_contact->history->lead->total_submissions . '</td>';
            echo '</tr>';
            echo '</tbody></table>';
            echo '</div>';
            // leadout-postbox__content
            echo '</div>';
            // leadout-meta-section
        }
        echo '</div>';
        // contact-deatils-column
        echo '<div class="contact-timeline-column" ' . ($li_contact->history->lead->lead_deleted ? 'style="display: none;"' : '') . '>';
        echo '<div class="col-wrap contact-history">';
        echo '<ul class="sessions">';
        $sessions = $li_contact->history->sessions;
        foreach ($sessions as &$session) {
            $first_event = end($session['events']);
            $first_event_date = $first_event['event_date'];
            $session_date = date('F j, Y, g:ia', strtotime($first_event['event_date']));
            $session_start_time = date('g:ia', strtotime($first_event['event_date']));
            $last_event = array_values($session['events']);
            $session_end_time = date('g:ia', strtotime($last_event[0]['event_date']));
            echo '<li class="session">';
            echo '<h3 class="session-date">' . $session_date . ($session_start_time != $session_end_time ? ' - ' . $session_end_time : '') . '</h3>';
            echo '<ul class="events">';
            //$events = array_reverse($session['events']);
            $events = $session['events'];
            foreach ($events as &$event) {
                if ($event['event_type'] == 'pageview') {
                    $pageview = $event['activities'][0];
                    echo '<li class="event pageview">';
                    echo '<div class="event-time">' . date('g:ia', strtotime($pageview['event_date'])) . '</div>';
                    echo '<div class="event-content">';
                    echo '<p class="event-title">' . $pageview['pageview_title'] . '</p>';
                    echo '<a class="event-detail pageview-url" target="_blank" href="' . $pageview['pageview_url'] . '">' . leadout_strip_params_from_url($pageview['pageview_url']) . '</a>';
                    echo '</div>';
                    echo '</li>';
                    if ($pageview['event_date'] == $first_event['event_date']) {
                        echo '<li class="event source">';
                        echo '<div class="event-time">' . date('g:ia', strtotime($pageview['event_date'])) . '</div>';
                        echo '<div class="event-content">';
                        echo '<p class="event-title">Traffic Source: ' . ($pageview['pageview_source'] ? '<a href="' . $pageview['pageview_source'] . '">' . leadout_strip_params_from_url($pageview['pageview_source']) : 'Direct') . '</a></p>';
                        $url_parts = parse_url($pageview['pageview_source']);
                        if (isset($url_parts['query'])) {
                            if ($url_parts['query']) {
                                parse_str($url_parts['query'], $url_vars);
                                if (count($url_vars)) {
                                    echo '<ul class="event-detail fields">';
                                    foreach ($url_vars as $key => $value) {
                                        if (!$value) {
                                            continue;
                                        }
                                        echo '<li class="field">';
                                        echo '<label class="field-label">' . $key . ':</label>';
                                        echo '<p class="field-value">' . nl2br($value) . '</p>';
                                        echo '</li>';
                                    }
                                    echo '</ul>';
                                }
                            }
                        }
                        echo '</div>';
                        echo '</li>';
                    }
                } else {
                    if ($event['event_type'] == 'form') {
                        $submission = $event['activities'][0];
                        $form_fields = json_decode($submission['form_fields']);
                        $num_form_fieds = count($form_fields);
                        $tag_text = '<a class="contact-tag" href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=leadout_contacts&contact_type=' . $tag->tag_slug . '">' . $tag->tag_text . '</a>';
                        echo '<li class="event form-submission">';
                        echo '<div class="event-time">' . date('g:ia', strtotime($submission['event_date'])) . '</div>';
                        echo '<div class="event-content">';
                        echo '<p class="event-title">';
                        echo 'Filled out ' . $event['form_name'] . ' on page <a href="' . $submission['form_page_url'] . '">' . $submission['form_page_title'] . '</a>';
                        if (count($event['form_tags'])) {
                            echo ' and tagged as ';
                            for ($i = 0; $i < count($event['form_tags']); $i++) {
                                echo '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=leadout_contacts&contact_type=' . $event['form_tags'][$i]['tag_slug'] . '">' . $event['form_tags'][$i]['tag_text'] . '</a> ';
                            }
                        }
                        echo '</p>';
                        echo '<ul class="event-detail fields">';
                        if (count($form_fields)) {
                            foreach ($form_fields as $field) {
                                echo '<li class="field">';
                                echo '<label class="field-label">' . $field->label . ':</label>';
                                echo '<p class="field-value">' . nl2br($field->value) . '</p>';
                                echo '</li>';
                            }
                        }
                        echo '</ul>';
                        echo '</div>';
                        echo '</li>';
                    }
                }
            }
            echo '</ul>';
            echo '</li>';
        }
        echo '</ul>';
        echo '</div>';
        echo '</div>';
        //contact-timeline-column
    }