/** * Displays user activity stream for display. * * @since 0.1 */ static function get_user_activity_stream($args = '', $passed_result = false) { global $wpdb, $wp_crm, $current_user; $args = wp_parse_args($args, array('per_page' => get_user_option('crm_page_wp_crm_add_new_per_page') ? (int) get_user_option('crm_page_wp_crm_add_new_per_page') : 10, 'more_per_page' => false, 'filter_types' => false)); if (empty($args['per_page'])) { $args['per_page'] = get_user_option('crm_page_wp_crm_add_new_per_page') ? (int) get_user_option('crm_page_wp_crm_add_new_per_page') : 10; $args['more_per_page'] = $args['per_page']; } if (empty($args['user_id'])) { return; } if (!empty($args['filter_types']) && is_array($args['filter_types'])) { foreach ($args['filter_types'] as $row) { update_user_option($current_user->ID, "crm_ui_crm_user_activity_{$row['attribute']}" . ($row['other'] ? '[' . $row['other'] . ']' : ''), $row['hidden']); } } $params = array('object_id' => $args['user_id'], 'filter_types' => $args['filter_types'], 'import_count' => ''); $all_messages = WP_CRM_F::get_events($params); if (!empty($passed_result)) { $result = $passed_result; } else { $params['import_count'] = $args['per_page']; $result = WP_CRM_F::get_events($params); } $result = stripslashes_deep($result); ob_start(); foreach ($result as $entry) { $entry_classes[] = $entry->attribute; $entry_classes[] = $entry->object_type; $entry_classes[] = $entry->action; $entry_classes = apply_filters('wp_crm_entry_classes', $entry_classes, $entry); $entry_type = apply_filters('wp_crm_entry_type_label', $entry->attribute, $entry); $left_by = $wpdb->get_var("SELECT display_name FROM {$wpdb->users} WHERE ID = '{$entry->user_id}'"); $entry_text = apply_filters('wp_crm_activity_single_content', nl2br($entry->text), array('entry' => $entry, 'args' => $args)); //** If detailed activity is tracked, certain fields are machine-populated. */ if (!empty($wp_crm['configuration']['track_detailed_user_activity']) && $wp_crm['configuration']['track_detailed_user_activity'] == 'true' && empty($entry_text)) { switch (true) { case $entry->attribute == 'detailed_log' && $entry->action == 'login': $entry_text = sprintf(__('Logged in from IP %1s, %2s ago.', 'wpp'), $entry->value, human_time_diff(strtotime($entry->time))); break; } } if (empty($entry_text)) { continue; } ?> <tr class="wp_crm_activity_single <?php echo @implode(' ', array_unique($entry_classes)); ?> "> <td> <div class="left clearfix"> <ul class='message_meta'> <li class='timestamp'> <span class='time'><?php echo date(get_option('time_format'), strtotime($entry->time)); ?> </span> <span class='date'><?php echo date(get_option('date_format'), strtotime($entry->time)); ?> </span>: </li> <?php if ($entry_type) { ?> <li class="entry_type"><?php echo $entry_type; ?> </li><?php } ?> <?php if ($left_by) { ?> <li class="by_user">by <?php echo $left_by; ?> </li><?php } ?> <li class="wp_crm_log_actions"> <span verify_action="true" instant_hide="true" class="wp_crm_message_quick_action wp_crm_subtle_link" object_id="<?php echo $entry->id; ?> " wp_crm_action="delete_log_entry"><?php _e('Delete', 'wp_crm'); ?> </span> </li> </ul> </div> <div class="right clearfix"> <p class="wp_crm_entry_content"><?php echo $entry_text; ?> </p> </div> </td> </tr><?php } $new_per_page = ($args['per_page'] ? $args['per_page'] : 0) + (get_user_option('crm_page_wp_crm_add_new_per_page') ? get_user_option('crm_page_wp_crm_add_new_per_page') : 10); $rest = count($all_messages) - count($result); $output = array('tbody' => ob_get_clean(), 'per_page' => $new_per_page, 'current_count' => count($result), 'total_count' => count($all_messages), 'more_per_page' => $rest >= $args['more_per_page'] ? $args['more_per_page'] : $rest); return json_encode($output); }
/** * Contact history and messages for a user * * * @todo Fix delete link to be handled internally and not depend on built-in user management * @since 0.01 * */ static function user_activity_history($object) { $user_id = WP_CRM_F::get_first_value(!empty($object['ID']) ? $object['ID'] : array()); $all_messages = array(); $limited_messages = array(); $rest_messages = 0; $per_page = 10; //** If not to check user id it may cause fatal error */ if ($user_id) { $all_messages = WP_CRM_F::get_events('import_count=&object_id=' . $user_id); $per_page = get_user_option('crm_page_wp_crm_add_new_per_page') ? get_user_option('crm_page_wp_crm_add_new_per_page') : 10; $params = array('object_id' => $user_id, 'import_count' => $per_page, 'hide_empty' => true); $limited_messages = WP_CRM_F::get_events($params); $rest_messages = count($all_messages) - count($limited_messages); } if (current_user_can('WP-CRM: Add User Messages')) { ?> <div class="wp_crm_activity_top"> <input class="wp_crm_toggle_message_entry" type="button" value="<?php _e('Add Message', 'wp_crm'); ?> " /> <?php do_action('wp_crm_user_activity_history_top', $object); ?> <img class="loading" src="<?php echo WP_CRM_URL; ?> /css/images/ajax-loader-arrows.gif" height="16" width="16" style="margin: 0pt auto; display:none" alt="<?php _e("loading", 'wp_crm'); ?> "/> </div> <?php } ?> <div class="wp_crm_new_message hidden"> <textarea id="wp_crm_message_content"></textarea> <div class="wp_crm_new_message_options_line"> <div class="alignleft"> <div class="wp_crm_show_message_options"><?php _e('Show Options', 'wp_crm'); ?> </div> <div class="wp_crm_message_options hidden"> <?php _e('Date:', 'wp_crm'); ?> <input class="datepicker" /> </div> </div> <div class="alignright"> <label for="wp_crm_message_type"><?php _e('Message type', 'wp_crm'); ?> </label> <select id="wp_crm_message_type" class='wp_crm_dropdown'> <?php foreach ((array) apply_filters('crm_add_message_types', array('general_message' => array('title' => 'General Message'), 'phone_call' => array('title' => 'Phone Call'), 'meeting' => array('title' => 'Meeting'))) as $type => $options) { ?> <option value="<?php echo $type; ?> " title="Select type of message"><?php echo $options['title']; ?> </option> <?php } ?> </select> <input type="button" id="wp_crm_add_message" value="<?php _e('Submit', 'wp_crm'); ?> "/> </div> </div> </div> <table id="wp_crm_user_activity_stream" cellpadding="0" cellspacing="0"> <thead></thead> <tbody> <?php if (!empty($user_id) && is_numeric($user_id)) { $stream = json_decode(WP_CRM_F::get_user_activity_stream("user_id={$user_id}", $limited_messages)); echo $stream->tbody; } ?> </tbody> </table> <div class="wp_crm_stream_status wp_crm_load_more_stream" limited_messages="<?php echo count($limited_messages); ?> " all_messages="<?php echo count($all_messages); ?> " per_page="<?php echo !empty($stream->per_page) ? $stream->per_page : $per_page; ?> " <?php if (empty($rest_messages)) { ?> style="display:none;" <?php } ?> > <span class="wp_crm_counts"><?php printf(__('Showing <span class="current_count">%1s</span> messages of <span class="total_count">%2s</span>. Load <span class="more_count">%3s</span> more.', 'wp_crm'), count($limited_messages), count($all_messages), $rest_messages >= $per_page ? $per_page : $rest_messages); ?> <img class="loading" src="<?php echo WP_CRM_URL; ?> /css/images/ajax-loader-arrows.gif" height="16" width="16" style="margin: 0pt auto; display:none" alt="<?php _e("loading", 'wp_crm'); ?> "/></span> </div> <?php }
/** * Contact history and messages for a user * * * @todo Fix delete link to be handled internally and not depend on built-in user management * @since 0.01 * */ function user_activity_history($object) { global $wpdb; $user_id = WP_CRM_F::get_first_value($object['ID']); $all_messages = WP_CRM_F::get_events('import_count=&object_id=' . $user_id); $limited_messages = WP_CRM_F::get_events('object_id=' . $user_id); $per_page = 10; if (current_user_can('WP-CRM: Add User Messages')) { ?> <div class="wp_crm_activity_top"> <input class='wp_crm_toggle_message_entry button' type='button' value='<?php _e('Add Message'); ?> ' /> <?php do_action('wp_crm_user_activity_history_top', $object); ?> </div> <?php } ?> <div class="wp_crm_new_message hidden"> <textarea id='wp_crm_message_content'></textarea> <div class="wp_crm_new_message_options_line"> <div class="alignleft"> <div class="wp_crm_show_message_options"><?php _e('Show Options', 'wp_crm'); ?> </div> <div class="wp_crm_message_options hidden"> <?php _e('Date:', 'wp_crm'); ?> <input class="datepicker" /> </div> </div> <div class="alignright"><input type='button' id='wp_crm_add_message' value='<?php _e('Add Message', 'wp_crm'); ?> '/></div> </div> </div> <table id="wp_crm_user_activity_stream" cellpadding="0" cellspacing="0"> <thead></thead> <tbody> <?php if ($user_id) { WP_CRM_F::get_user_activity_stream("user_id={$user_id} ", $limited_messages); } ?> </tbody> </table> <div class="wp_crm_stream_status wp_crm_load_more_stream" limited_messages="<?php echo count($limited_messages); ?> " all_messages="<?php echo count($all_messages); ?> " per_page="<?php echo $per_page; ?> "> <?php /* if($limited_messages < $all_messages) { ?> <span class="wp_crm_counts"><?php printf(__('Showing <span class="current_count">%1s</span> messages of <span class="total_count">%2s</span>. Load <span class="more_count">%3s</span> more.', 'wp_crm'),count($limited_messages), count($all_messages), $per_page); ?><span> <?php } */ ?> </div> <?php }
/** * Displays user activity stream for display. * * @since 0.1 */ function get_user_activity_stream($args = '', $passed_result = false) { global $wpdb, $current_user; $defaults = array(); $args = wp_parse_args($args, $defaults); if (empty($args['user_id'])) { return; } if (isset($messages)) { $result = $passed_result; } if (!$result) { $result = WP_CRM_F::get_events(array('object_id' => $args['user_id'], 'attribute' => array('contact_form_message', 'note'))); } if (!$result) { return; } $result = stripslashes_deep($result); foreach ($result as $entry) { //echo "<pre>";print_r($entry);echo "<pre>"; $entry_classes[] = $entry->attribute; $entry_classes[] = $entry->object_type; $entry_classes[] = $entry->action; $entry_classes = apply_filters('wp_crm_entry_classes', $entry_classes, $entry); $entry_type = apply_filters('wp_crm_entry_type_label', $entry->attribute, $entry); $left_by = $wpdb->get_var("SELECT display_name FROM {$wpdb->users} WHERE ID = '{$entry->user_id}'"); if (empty($left_by)) { // $left_by = __('System', 'wp_crm'); } ?> <tr class="wp_crm_activity_single <?php echo @implode(' ', $entry_classes); ?> "> <td class="left"> <ul class='message_meta'> <li class='timestamp'> <span class='time'><?php echo date(get_option('time_format'), strtotime($entry->time)); ?> </span> <span class='date'><?php echo date(get_option('date_format'), strtotime($entry->time)); ?> </span> </li> <?php if ($entry_type) { ?> <li class="entry_type"><?php echo $entry_type; ?> </li><?php } ?> <?php if ($left_by) { ?> <li class="by_user">by <?php echo $left_by; ?> </li><?php } ?> <li class="wp_crm_log_actions"> <span verify_action="true" instant_hide="true" class="wp_crm_message_quick_action wp_crm_subtle_link" object_id="<?php echo $entry->id; ?> " wp_crm_action="delete_log_entry"><?php _e('Delete'); ?> </span> </li> </ul> </td> <td class="right"> <p class="wp_crm_entry_content"><?php echo apply_filters('wp_crm_activity_single_content', nl2br($entry->text), array('entry' => $entry, 'args' => $args)); ?> </p> </td> </tr> <?php } }