/**
  * Get the leads for the contacts table based on $GET_['contact_type'] or $_GET['s'] (search)
  *
  * @return  array           associative array of all contacts
  */
 function get_contacts()
 {
     /*** 
            == FILTER ARGS ==
            - filter_action (visited)      = visited a specific page url (filter_action) 
            - filter_action (submitted)    = submitted a form on specific page url (filter_action) 
            - filter_content               = content for filter_action
            - filter_form                  = selector id/class
            - num_pageviews                = visited at least #n pages
            - s                            = search query on lead_email/lead_source
        */
     global $wpdb;
     $mysql_search_filter = '';
     $mysql_contact_type_filter = '';
     $mysql_action_filter = '';
     $filter_action_set = FALSE;
     // search filter
     if (isset($_GET['s'])) {
         $escaped_query = '';
         if ($wp_version >= 4) {
             $escaped_query = $wpdb->esc_like($_GET['s']);
         } else {
             $escaped_query = like_escape($_GET['s']);
         }
         $search_query = $_GET['s'];
         $mysql_search_filter = $wpdb->prepare(" AND ( l.lead_email LIKE '%%%s%%' OR l.lead_source LIKE '%%%s%%' ) ", $escaped_query, $escaped_query);
     }
     $filtered_contacts = array();
     // contact type filter
     if (isset($_GET['contact_type'])) {
         // Query for the tag_id, then find all hashkeys with that tag ID tied to them. Use those hashkeys to modify the query
         $q = $wpdb->prepare("\n                SELECT \n                    DISTINCT ltr.contact_hashkey as lead_hashkey \n                FROM \n                    {$wpdb->li_tag_relationships} ltr, {$wpdb->li_tags} lt \n                WHERE \n                    lt.tag_id = ltr.tag_id AND \n                    ltr.tag_relationship_deleted = 0 AND  \n                    lt.tag_slug = %s GROUP BY ltr.contact_hashkey", $_GET['contact_type']);
         $filtered_contacts = $wpdb->get_results($q, 'ARRAY_A');
         $num_contacts = count($filtered_contacts);
     }
     if (isset($_GET['filter_action']) && $_GET['filter_action'] == 'visited') {
         if (isset($_GET['filter_content']) && $_GET['filter_content'] != 'any page') {
             $q = $wpdb->prepare("SELECT lead_hashkey FROM {$wpdb->li_pageviews} WHERE pageview_title LIKE '%%%s%%' GROUP BY lead_hashkey", htmlspecialchars(urldecode($_GET['filter_content'])));
             $filtered_contacts = leadout_merge_filtered_contacts($wpdb->get_results($q, 'ARRAY_A'), $filtered_contacts);
             $filter_action_set = TRUE;
         }
     }
     // filter for a form submitted on a specific page
     if (isset($_GET['filter_action']) && $_GET['filter_action'] == 'submitted') {
         $filter_form = '';
         if (isset($_GET['filter_form']) && $_GET['filter_form'] && $_GET['filter_form'] != 'any form') {
             $filter_form = str_replace(array('#', '.'), '', htmlspecialchars(urldecode($_GET['filter_form'])));
             $filter_form_query = $wpdb->prepare(" AND ( form_selector_id LIKE '%%%s%%' OR form_selector_classes LIKE '%%%s%%' )", $filter_form, $filter_form);
         }
         $q = $wpdb->prepare("SELECT lead_hashkey FROM {$wpdb->li_submissions} WHERE form_page_title LIKE '%%%s%%' ", $_GET['filter_content'] != 'any page' ? htmlspecialchars(urldecode($_GET['filter_content'])) : '');
         $q .= $filter_form_query ? $filter_form_query : '';
         $q .= " GROUP BY lead_hashkey";
         $filtered_contacts = leadout_merge_filtered_contacts($wpdb->get_results($q, 'ARRAY_A'), $filtered_contacts);
         $filter_action_set = TRUE;
     }
     $filtered_hashkeys = leadout_explode_filtered_contacts($filtered_contacts);
     $mysql_action_filter = '';
     if ($filter_action_set) {
         // If a filter action is set and there are no contacts, do a blank
         $mysql_action_filter = " AND l.hashkey IN ( " . ($filtered_hashkeys ? $filtered_hashkeys : "''") . " ) ";
     } else {
         $mysql_action_filter = $filtered_hashkeys ? " AND l.hashkey IN ( " . $filtered_hashkeys . " ) " : '';
     }
     // If a filter action isn't set, use the filtered hashkeys if they exist, else, don't include the statement
     // There's a filter and leads are in it
     if (isset($_GET['contact_type']) && ($num_contacts || !$_GET['contact_type']) || !isset($_GET['contact_type'])) {
         $q = $wpdb->prepare("\n                SELECT \n                    l.lead_id AS lead_id, \n                    LOWER(DATE_SUB(l.lead_date, INTERVAL %d HOUR)) AS lead_date, l.lead_ip, l.lead_source, l.lead_email, l.hashkey, l.lead_first_name, l.lead_last_name,\n                    COUNT(DISTINCT s.form_id) AS lead_form_submissions,\n                    COUNT(DISTINCT p.pageview_id) AS lead_pageviews,\n                    LOWER(DATE_SUB(MAX(p.pageview_date), INTERVAL %d HOUR)) AS last_visit,\n                    ( SELECT COUNT(DISTINCT pageview_id) FROM {$wpdb->li_pageviews} WHERE lead_hashkey = l.hashkey AND pageview_session_start = 1 AND pageview_deleted = 0 ) AS visits,\n                    ( SELECT MIN(pageview_source) AS pageview_source FROM {$wpdb->li_pageviews} WHERE lead_hashkey = l.hashkey AND pageview_session_start = 1 AND pageview_deleted = 0 ) AS pageview_source \n                FROM \n                    {$wpdb->li_leads} l\n                LEFT JOIN {$wpdb->li_submissions} s ON l.hashkey = s.lead_hashkey\n                LEFT JOIN {$wpdb->li_pageviews} p ON l.hashkey = p.lead_hashkey \n                WHERE l.lead_email != '' AND l.lead_deleted = 0 AND l.hashkey != '' ", $wpdb->db_hour_offset, $wpdb->db_hour_offset);
         $q .= $mysql_contact_type_filter;
         $q .= $mysql_search_filter ? $mysql_search_filter : "";
         $q .= $mysql_action_filter ? $mysql_action_filter : "";
         $q .= " GROUP BY l.hashkey";
         $leads = $wpdb->get_results($q);
     } else {
         $leads = array();
     }
     $all_leads = array();
     $contact_count = 0;
     if (count($leads)) {
         foreach ($leads as $key => $lead) {
             // filter for number of page views and skipping lead if it doesn't meet the minimum
             if (isset($_GET['filter_action']) && $_GET['filter_action'] == 'num_pageviews') {
                 if ($lead->lead_pageviews < $_GET['filter_content']) {
                     continue;
                 }
             }
             $url = leadout_strip_params_from_url($lead->lead_source);
             $redirect_url = '';
             if (isset($_GET['contact_type']) || isset($_GET['filter_action']) || isset($_GET['filter_form']) || isset($_GET['filter_content']) || isset($_GET['num_pageviews']) || isset($_GET['s']) || isset($_GET['paged'])) {
                 $redirect_url = urlencode(leadout_get_current_url());
             }
             $lead_array = array('ID' => $lead->lead_id, 'hashkey' => $lead->hashkey, 'email' => sprintf('<a href="?page=%s&action=%s&lead=%s%s">' . "<img class='pull-left leadout-contact-avatar leadout-dynamic-avatar_" . substr($lead->lead_id, -1) . "' src='https://api.hubapi.com/socialintel/v1/avatars?email=" . $lead->lead_email . "' width='35' height='35' style='margin-top: 2px;'/> " . '</a>', $_REQUEST['page'], 'view', $lead->lead_id, $redirect_url ? '&redirect_to=' . $redirect_url : '') . sprintf('<a href="?page=%s&action=%s&lead=%s%s">%s' . $lead->lead_email . '</a>', $_REQUEST['page'], 'view', $lead->lead_id, $redirect_url ? '&redirect_to=' . $redirect_url : '', strlen($lead->lead_first_name) || strlen($lead->lead_last_name) ? '<b>' . $lead->lead_first_name . ' ' . $lead->lead_last_name . '</b><br>' : ''), 'visits' => !isset($lead->visits) ? 1 : $lead->visits, 'submissions' => $lead->lead_form_submissions, 'pageviews' => $lead->lead_pageviews, 'date' => date('Y-m-d g:ia', strtotime($lead->lead_date)), 'source' => $lead->pageview_source ? "<a title='Visit page' href='" . $lead->pageview_source . "' target='_blank'>" . leadout_strip_params_from_url($lead->pageview_source) . "</a>" : 'Direct', 'last_visit' => date('Y-m-d g:ia', strtotime($lead->last_visit)), 'source' => $lead->lead_source ? "<a title='Visit page' href='" . $lead->lead_source . "' target='_blank'>" . leadout_strip_params_from_url($lead->lead_source) . "</a>" : 'Direct');
             array_push($all_leads, $lead_array);
             $contact_count++;
         }
     }
     $this->total_filtered = count($all_leads);
     return $all_leads;
 }
Example #2
0
 /**
  * Creates each session section separated by a spacer
  *
  * @param   stdClass    LI_contact
  * @return  string      concatenated string of sessions
  */
 function build_sessions($history)
 {
     $built_sessions = "";
     $sessions = $history->sessions;
     foreach ($sessions as &$session) {
         $first_event = end($session['events']);
         $first_event_date = $first_event['activities'][0]['event_date'];
         $session_date = date('F j, Y, g:i a', strtotime($first_event_date));
         $last_event = array_values($session['events']);
         $last_event = $last_event[0];
         $last_activity = end($last_event['activities']);
         $session_end_time = date('g:i a', strtotime($last_activity['event_date']));
         $format = '<table class="row lead-timeline__date" style="border-spacing: 0;border-collapse: collapse;padding: 0px;vertical-align: top;text-align: left;width: 100%%;position: relative;display: block;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="wrapper last" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;padding-right: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="twelve columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 580px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><h4 style="color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: bold;padding: 0;margin: 0;text-align: left;line-height: 1.3;word-break: normal;font-size: 14px;">%s - %s</h4></td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td></tr></table>';
         $built_sessions .= sprintf($format, $session_date, $session_end_time);
         $events = $session['events'];
         foreach ($events as &$event) {
             if ($event['event_type'] == 'pageview') {
                 $pageview = $event['activities'][0];
                 $pageview_time = date('g:ia', strtotime($pageview['event_date']));
                 $pageview_url = $pageview['pageview_url'];
                 $pageview_title = $pageview['pageview_title'];
                 $pageview_source = $pageview['pageview_source'];
                 $format = '<table class="row lead-timeline__event pageview" style="border-spacing: 0;border-collapse: collapse;padding: 0px;vertical-align: top;text-align: left;width: 100%%;position: relative;display: block;background-color: #fff;border-top: 1px solid #dedede;border-right: 1px solid #dedede;border-left: 4px solid #28c;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="wrapper" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="two columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 80px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><p class="lead-timeline__event-time" style="margin: 0;color: #1f6696;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;">%s</p></td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td><td class="wrapper last" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;padding-right: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="ten columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 480px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><p class="lead-timeline__event-title" style="margin: 0;color: #1f6696;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;">%s</p><p class="lead-timeline__pageview-url" style="margin: 0;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;"><a href="%s" style="color: #999;text-decoration: none;">%s</a></p></td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td></tr></table>';
                 $built_sessions .= sprintf($format, $pageview_time, $pageview_title, $pageview_url, leadout_strip_params_from_url($pageview_url));
                 if ($pageview['event_date'] == $first_event_date) {
                     $format = '<table class="row lead-timeline__event traffic-source" style="margin-bottom: 20px;border-spacing: 0;border-collapse: collapse;padding: 0px;vertical-align: top;text-align: left;width: 100%%;position: relative;display: block;background-color: #fff;border-top: 1px solid #dedede;border-right: 1px solid #dedede;border-left: 4px solid #99aa1f;border-bottom: 1px solid #dedede;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="wrapper" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="two columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 80px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><p class="lead-timeline__event-time" style="margin: 0;color: #727e14;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;">%s</p></td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td><td class="wrapper last" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;padding-right: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="ten columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 480px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><p class="lead-timeline__event-title" style="margin: 0;color: #727e14;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;">Traffic Source: %s</p> %s </td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td></tr></table>';
                     $built_sessions .= sprintf($format, $pageview_time, $pageview_source ? '<a href="' . $pageview_source . '">' . leadout_strip_params_from_url($pageview_source) . '</a>' : 'Direct', $this->build_source_url_params($pageview_source));
                 }
             } else {
                 if ($event['event_type'] == 'form') {
                     $submission = $event['activities'][0];
                     $submission_Time = date('g:ia', strtotime($submission['event_date']));
                     $submission_url = $submission['form_page_url'];
                     $submission_page_title = $submission['form_page_title'];
                     $submission_form_fields = json_decode($submission['form_fields']);
                     $submission_tags = '';
                     if (count($event['form_tags'])) {
                         $submission_tags = ' and tagged as ';
                         for ($i = 0; $i < count($event['form_tags']); $i++) {
                             $submission_tags .= '<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> ';
                         }
                     }
                     $format = '<table class="row lead-timeline__event submission" style="border-spacing: 0;border-collapse: collapse;padding: 0px;vertical-align: top;text-align: left;width: 100%%;position: relative;display: block;background-color: #fff;border-top: 1px solid #dedede;border-right: 1px solid #dedede;border-left: 4px solid #f6601d;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="wrapper" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="two columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 80px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><p class="lead-timeline__event-time" style="margin: 0;color: #b34a12;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;">%s</p></td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td><td class="wrapper last" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;padding-right: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="ten columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 480px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><p class="lead-timeline__event-title" style="margin: 0;color: #b34a12;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;">Filled out ' . $event['form_name'] . ' on page <a href="%s" style="color: #2ba6cb;text-decoration: none;">%s</a>%s</p> %s </td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td></tr></table>';
                     $built_sessions .= sprintf($format, $submission_Time, $submission_url, $submission_page_title, $submission_tags, $this->build_form_fields($submission_form_fields));
                 }
             }
         }
     }
     return $built_sessions;
 }
Example #3
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
    }