function bbconnect_user_data_select($args = '') { $defaults = array('id' => '', 'class' => '', 'meta_key' => '', 'value' => '', 'name' => false, 'address_unlock' => false, 's_context' => 'search', 'ppum' => bbconnect_get_user_metadata(array('group_break' => true)), 'wpr' => false, 'meta_only' => false, 'chosen' => ' chzn-select', 'multiple' => false, 'multi_meta_key' => false); // PARSE THE INCOMING ARGS $args = wp_parse_args($args, $defaults); // EXTRACT THE VARIABLES extract($args, EXTR_SKIP); // SPECIAL LOCK FOR ADDRESSES // IF AN ADDRESS IS LOCKED, ONLY THE FIRST FIELD OPTION WILL BE DISPLAYED $address_lock = false; // FOR THE SELECT, USE THE $NAME VARIABLE TO DETERMINE WETHER OR NOT THE VALUES SHOULD BE SUBMITTED. ?> <select class="<?php echo $class . $chosen; ?> "<?php if (false !== $name) { echo ' name="' . $name . '"'; } if (false !== $multiple) { echo ' multiple="multiple"'; } ?> > <option value=""><?php _e('Make a selection', 'bbconnect'); ?> </option> <optgroup label="<?php _e('Profile Fields', 'bbconnect'); ?> "> <?php $fput = array(); foreach ($ppum as $ukey => $uvalue) { // RETRIEVE THE OPTION AND EVALUATE $user_meta = get_option($uvalue); // RESTRICT TO ONLY USER TABLE FIELDS if (false != $wpr && 'wpr' != $user_meta['source']) { continue; } // RESTRICT TO ONLY USER TABLE FIELDS if (false != $meta_only && 'wpr' == $user_meta['source']) { continue; } // OTHERWISE, SET THE KEY $utkey = $user_meta['meta_key']; // IF THIS IS A GROUP, GET THE GROUP ELEMENTS AND LOG THEM if ('group' === $user_meta['options']['field_type'] || 'section' === $user_meta['options']['field_type']) { // SET THE VARS $prefix = stripslashes($user_meta['name']) . ': '; // IF THIS IS AN ADDRESS FIELD, SHOW THE FIRST FIELD // PREVENT SUCCESSIVE LIKE FIELDS FROM DISPLAYING if ('address' === $user_meta['group_type'] && false == $address_lock) { // IF WE'RE LOCKING SUCCESSIVE FIELDS, DO SO HERE if (false == $address_unlock) { $address_lock = true; $prefix = ''; // IF WE'RE LOCKED, DEFAULT TO THE FIRST ADDRESS GROUP if ('1' != strrchr($user_meta['meta_key'], '_')) { $ext = count(strrchr($user_meta['meta_key'], '_')); $add_app = substr($user_meta['meta_key'], 0, -$ext); $fid = $add_app . '1'; $user_meta = get_option('bbconnect_' . $fid); } } // IF ADDRESSES ARE LOCKED, SKIP SUCCESSIVE FIELDS } elseif ('address' === $user_meta['group_type'] && false != $address_lock) { continue; } foreach ($user_meta['options']['choices'] as $group_key => $group_value) { // RETRIEVE THE OPTION AND EVALUATE if ('section' === $user_meta['options']['field_type']) { $prefix = ''; $group_meta = get_option('bbconnect_' . $group_value); } else { $group_meta = get_option($group_value); } // IF WE'VE PASSED AN ARRAY AS A VALUE, CONVERT IT TO THE META KEY VALUE if (is_array($multi_meta_key)) { if (in_array($group_meta['meta_key'], $multi_meta_key)) { $meta_key = $group_meta['meta_key']; } } if (false != $group_meta['options']['reports']) { $fput[$group_meta['meta_key']] = '<option class="orderable" value="' . $group_meta['meta_key'] . '"' . selected($meta_key, $group_meta['meta_key']) . '>' . $prefix . stripslashes($group_meta['name']) . '</option>'; } } } else { if (false != $user_meta['options']['reports']) { $fselected = ''; // IF WE'VE PASSED AN ARRAY AS A VALUE, CONVERT IT TO THE META KEY VALUE if (is_array($multi_meta_key)) { if (in_array($utkey, $multi_meta_key)) { $meta_key = $utkey; } } if ($meta_key === $utkey) { $fselected = ' selected'; } $fput[$user_meta['meta_key']] = '<option class="orderable" value="' . $user_meta['meta_key'] . '"' . $fselected . '>' . stripslashes($user_meta['name']) . '</option>'; } } } $fput = apply_filters("bbconnect_user_data_select_f_{$s_context}", $fput); echo implode('', $fput); ?> </optgroup> <?php // ADD OPTIONS BASED ON CONTEXT if (false != $s_context) { do_action("bbconnect_user_data_select_{$s_context}", $meta_key, $wpr); } ?> </select> <?php }
function bbconnect_admin_globals() { // QUEUE WORDPRESS SCRIPTS wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('jquery-ui-draggable'); wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_script('thickbox'); // QUEUE BBCONNECT SCRIPTS wp_enqueue_script('tiptipJS'); wp_enqueue_script('chosenJS'); wp_enqueue_script('bbconnectJS'); wp_enqueue_script('bbconnectAdminJS'); // SET UP VARIABLES FOR ADMIN SCREENS $get_merge_tags = bbconnect_get_user_metadata(array('return_val' => true, 'include' => array('text'))); //$merge_tags = unserialize( urldecode( $_GET['mt'] ) ); $merge_tags = array(); foreach ($get_merge_tags as $val) { $merge_tags[$val['meta_key']] = $val['name']; } $merge_tags = apply_filters('bbconnect_merge_filter', $merge_tags); $merged_tags = urlencode(serialize($merge_tags)); // HOOK THE AJAX ENGINE FOR ADMIN ELEMENTS $admin_ajax_array = array(); $admin_ajax_array['ajaxurl'] = admin_url('admin-ajax.php'); $admin_ajax_array['bbconnect_admin_nonce'] = wp_create_nonce('bbconnect-admin-nonce'); $admin_ajax_array['ajaxload'] = plugins_url('/assets/g/loading.gif', __FILE__); $admin_ajax_array['ajaxhome'] = home_url(); $admin_ajax_array['metaKeyTaken'] = __('duplicate key!', 'bbconnect'); $admin_ajax_array['oneMoment'] = __('One Moment Please...', 'bbconnect'); $admin_ajax_array['mergeref'] = plugins_url('/assets/j/tmce/merge-ref.php?tags=' . $merged_tags, __FILE__); $admin_ajax_array['errMsg'] = sprintf(__('We found some errors -- please attend to the fields below marked with %1$s', 'bbconnect'), '<span class="halt-example"> </span>'); $admin_ajax_array['confirmDelete'] = BBCONNECT_CONFIRM_DELETE; // PASS A VALUE IF FIREFOX IS DETECTED $user_agent = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/Firefox/i', $user_agent)) { $admin_ajax_array['firefox'] = true; } // LOCALIZE THE ADMIN SCRIPT wp_localize_script('bbconnectAdminJS', 'bbconnectAdminAjax', $admin_ajax_array); // QUEUE STYLES //wp_enqueue_style( 'chosenCSS', BBCONNECT_URL . 'assets/j/chosen/chosen.css', array(), BBCONNECT_VER, false ); wp_enqueue_style('chosenCSS'); wp_enqueue_style('tiptipCSS'); }
function bbconnect_export_process() { // EXTEND EXECUTION TIME set_time_limit(3600); // SET LOCAL GLOBALS global $wpdb; $blog_prefix = $wpdb->get_blog_prefix(get_current_blog_id()); // SET A WPR TEMPORARY ARRAY $wpr_trans = array('email', 'url'); $ret_array = array(); $exp_array = array(); // BYPASS PAGINATION AND GET ALL USERS FROM THIS QUERY if (isset($_POST['_grexport']['all_users'])) { $users = explode('|', $_POST['_grexport']['all_search']); unset($_POST['_grexport']['all_search']); } else { if (isset($_POST['gredit_users'])) { $users = array_unique($_POST['gredit_users']); } else { $users = false; } } // SET UP THE DATA ARRAY foreach ($_POST['_grexport'] as $key => $val) { $exp_array[$key] = maybe_unserialize(urldecode($val)); } $exp_array['return'] = true; if (false != $users) { // IF WE WANT ALL FIELDS, DO THAT NOW, ELSE, TAKE WHAT WE'VE SEARCHED FOR if (isset($_POST['_grexport']['all_fields'])) { $headers_prep = bbconnect_get_user_metadata(); foreach ($headers_prep as $header) { $user_meta = get_option($header); if ('taxonomy' == $user_meta['options']['field_type']) { $headers[$user_meta['meta_key']] = array(); } else { if ('wpr' == $user_meta['source']) { if (in_array($user_meta['meta_key'], $wpr_trans)) { $wpr_key = 'user_' . $user_meta['meta_key']; } else { if ('role' == $user_meta['meta_key']) { $wpr_key = $blog_prefix . 'capabilities'; } else { $wpr_key = $user_meta['meta_key']; } } $headers[$wpr_key] = $user_meta['meta_key']; } else { if ('wp' == $user_meta['source'] || 'user' == $user_meta['source']) { $headers[$user_meta['meta_key']] = $user_meta['meta_key']; } else { $headers['bbconnect_' . $user_meta['meta_key']] = $user_meta['meta_key']; } } } } // REPLACE THE FIELD SELECTIONS WITH ALL FIELDS $exp_array['table_body'] = $headers; $exp_array['post_vars'] = false; unset($headers); } // IF WE HAVE ACTIONS, PROCESS THEM if (isset($_POST['gredit_actions'])) { $exp_array['action_array'] = apply_filters('bbconnect_export_action_array', $_POST['gredit_actions']); } foreach ($users as $user_id) { // ADD THE CURRENT USER IN $exp_array['user_id'] = $user_id; $cur_user = bbconnect_rows($exp_array); if (isset($cur_user['action'])) { if (isset($_POST['_grexport']['all_actions']) || isset($_POST['gredit_actions'])) { $curact_array = apply_filters('bbconnect_export_action_return', $cur_user['action']); unset($cur_user['action']); foreach ($curact_array as $akey => $aval) { $ret_array[] = $cur_user + $aval; } } else { unset($cur_user['action']); $ret_array[] = $cur_user; } } else { $ret_array[] = $cur_user; } } // APPLY A HEADER array_unshift($ret_array, array_keys($ret_array[0])); // FIX THAT DAMN MICROSOFT BUG! if ('ID' == $ret_array[0][0]) { $ret_array[0][0] = 'user_id'; } if (isset($_POST['export_title'])) { $exp_title = $_POST['export_title']; } else { $exp_title = 'export'; } $inc_file = bbconnect_export_filename(sanitize_title_with_underscores($exp_title)); $ret_file = bbconnect_export_file($inc_file, $ret_array); if (false != $ret_file) { $export_results = '<div id="progress"><a href="' . $ret_file . '">' . __('Your file', 'bbconnect') . '</a></div>'; } else { $export_results = __('I was not able to complete the export.', 'bbconnect'); } } else { $export_results = __('Please make a selection', 'bbconnect'); } $ret_arr = array('all_search' => false, 'member_search' => false, 'action_search' => false, 'user_display' => false, 'export_array' => $ret_array, 'max_num_pages' => false, 'post_vars' => false, 'users_per_page' => false, 'users_count' => false, 'export_results' => $export_results); return $ret_arr; }
function bbconnect_report_display($ret_res = array()) { // SETUP DISPLAY GLOBALS global $ret_res, $table_head, $table_body, $pagenow, $action_array; global $totalValues, $fieldInfos; // EXTRACT THE VARIABLES extract($ret_res, EXTR_SKIP); // COUNT THE ADDRESSES FOR DISPLAY global $bbconnect_address_count; $bbconnect_user_metas = bbconnect_get_user_metadata(array('group_break' => true)); $bbconnect_address_count = 0; foreach ($bbconnect_user_metas as $pmkey => $pmval) { if (false != strstr($pmval, 'address')) { $bbconnect_address_count++; } } if (is_admin()) { // IF THERE ARE ANY ERRORS, LET THE USER KNOW! if (isset($bbconnect_errors) && !empty($bbconnect_errors)) { echo '<div class="error">'; if (is_array($bbconnect_errors)) { foreach ($bbconnect_errors as $error) { if (is_wp_error($error)) { $error->get_error_message(); } else { echo $error; } } } else { echo $bbconnect_errors; } echo '</div>'; } // FIRE OFF ANY NOTIFICATIONS FOR PLUGINS do_action('bbconnect_report_notifications', $ret_res); } $report_nav = ''; $report_nav .= '<div id="report-navigation"><div class="inside">'; $report_nav .= '<span class="report-tab">'; if (is_admin()) { $report_nav .= bbconnect_pagination($ret_res); } else { $report_nav .= bbconnect_pagination($ret_res, true); } // ALLOW OTHER PLUGINS TO ADD VIEWS AND DO STUFF if (is_admin()) { $report_nav .= bbctheme_toggle_view(apply_filters('bbconnect_dir_tabs', array('list'))); } $report_nav .= '</span>'; echo $report_nav; do_action('bbconnect_report_navigation'); echo '</div></div>'; if (!isset($all_search) || empty($all_search)) { $all_search = $member_search; } // HANDLE ACTIONS HERE do_action('bbconnect_process_action_search', $action_search, $ret_res); $action_array = apply_filters('bbconnect_process_action_array', false, $ret_res); ?> <div id="report-data-array" style="display: none;"> <input name="_grexport[post_vars]" type="hidden" value="<?php echo rawurlencode(serialize($ret_res['post_vars'])); ?> " /> <input name="_grexport[table_body]" type="hidden" value="<?php echo rawurlencode(serialize($table_body)); ?> " /> <input name="_grexport[bbconnect_address_count]" type="hidden" value="<?php echo rawurlencode(serialize($bbconnect_address_count)); ?> " /> <input name="_grexport[all_search]" type="hidden" value="<?php echo implode('|', $ret_res['all_search']); ?> " /> <input name="_grexport[action_search]" type="hidden" value="<?php echo rawurlencode(serialize($action_search)); ?> " /> </div> <form id="report-data-form" action="" enctype="multipart/form-data" method="POST"> <div id="list" class="content-display" style="<?php if (!isset($_COOKIE['view']) || 'list' == $_COOKIE['view']) { echo ' display: block;'; } ?> "> <?php // DISPLAY USERS OR... if (false != $all_search && false != $member_search) { // SETUP TABLE HEADER DISPLAY if ('' != $table_head) { if (is_array($table_head)) { $t_head = ''; foreach ($table_head as $head) { // DISPLAY THE HEADER $t_head .= '<th>' . $head[1] . '</th>'; } } else { $t_head = $table_head; } } else { $t_head = ''; } if (false != $action_search) { if (is_admin()) { $t_head .= '<th><table><tr><td class="gredit-column" width="5%"><input type="checkbox" id="action-gredit" class="gredit-action"'; if (!isset($ret_res['edit'])) { $t_head .= ' disabled="disabled"'; } else { $t_head .= ' style="display: block;"'; } $t_head .= ' /><span style="padding: 0 0 0 4%;">' . __('Actions', 'bbconnect') . '</span></td></tr></table></th>'; } else { $t_head .= '<th>' . __('Actions', 'bbconnect') . '</th>'; } } // COUNT THE NUMBER OF COLUMNS $col_count = 1; $col_span = 1; if (!empty($table_body)) { $col_count = $col_count + count($table_body); $col_span = count($table_body); } if (false != $action_search) { $col_count = $col_count + 2; $act_span = true; } // CALCULATE THE COLUMN WIDTHS $tdw = 95 / $col_count; if (!isset($act_span)) { $stw = '95%'; } else { $stw = $tdw * $col_span; $atw = $tdw * 2; } ?> <table class="wp-list-table widefat" cellspacing="5"> <thead> <tr> <?php if (is_admin()) { ?> <?php } ?> <th style="min-width: 185px;text-align:left;"><?php echo apply_filters('bbconnect_reports_user_header', __('Users', 'bbconnect')); ?> </th> <?php echo $t_head; ?> </tr> </thead> <tbody> <?php // DO AN ACTION FOR OTHER TABS // YOU'LL HAVE TO CALL THE GLOBALS MANUALLY! do_action('bbconnect_prep_results_display', $ret_res); $user_rows = ''; $note_ids = array(); // FOR THE REST... PAGINATE! foreach ($member_search as $user_id) { foreach ($ret_res['post_vars'] as $post_var) { foreach ($post_var as $var_details) { if ($var_details['field'] == 'bb_work_queue' && $var_details['operator'] == 'is' && function_exists('bbconnect_workqueues_get_action_items')) { $work_queues = $var_details['query']; $args = array('author' => $user_id, 'tax_query' => array(array('taxonomy' => 'bb_note_type', 'field' => 'term_id', 'terms' => $work_queues))); $notes = bbconnect_workqueues_get_action_items($args); foreach ($notes as $note) { $note_ids[$note->ID] = $note->ID; } } } } echo bbconnect_rows(array('table_body' => $table_body, 'user_id' => $user_id, 'action_search' => $action_search, 'action_array' => $action_array, 'bbconnect_address_count' => $bbconnect_address_count, 'post_vars' => $ret_res['post_vars'], 'tdw' => $tdw)); } ?> </tbody> <tfoot> <?php if (count($totalValues) > 0) { ?> <tr> <?php if (is_admin()) { ?> <?php } ?> <th><?php echo apply_filters('bbconnect_reports_user_header', __('Total for displayed results)', 'bbconnect')); ?> </th> <?php for ($i = 1; $i <= count($table_body); $i++) { $value_display = $totalValues[$i] ? $totalValues[$i] : ''; if ($fieldInfos[$i]['options']['field_type'] == 'number' && $fieldInfos[$i]['options']['is_currency'] && $value_display != '') { $value_display = '$' . number_format($value_display, 2); } echo "<th style='text-align: right;'>" . apply_filters('bbconnect_reports_user_header', $value_display) . "</th>" . "\n"; } ?> </tr> <tr> <?php if (is_admin()) { ?> <?php } ?> <th><?php echo apply_filters('bbconnect_reports_user_header', __('Average for displayed results)', 'bbconnect')); ?> </th> <?php for ($i = 1; $i <= count($table_body); $i++) { //echo "<th>".apply_filters( 'bbconnect_reports_user_header', ($valueforavg)?__($valueforavg/$ret_res["users_count"],'bbconnect'):'' )."</th>"."\n"; $value_display = $totalValues[$i] ? number_format($totalValues[$i] / count($member_search), 2) : ''; if ($fieldInfos[$i]['options']['field_type'] == 'number' && $fieldInfos[$i]['options']['is_currency'] && $value_display != '') { $value_display = '$' . $value_display; } echo "<th style='text-align: right;'>" . apply_filters('bbconnect_reports_user_header', $value_display) . "</th>" . "\n"; } ?> </tr> <?php } ?> </tfoot> </table> <?php } else { if (isset($export_results)) { echo '<p>' . $export_results . '</p>'; } else { if (isset($errors)) { if ($errors) { echo '<p>' . $errors . '</p>'; } else { echo '<p>No records found.</p>'; } } else { echo '<p>' . __('terribly sorry. i did not find anything.', 'bbconnect') . '</p>'; } } } ?> </div> <?php if (is_admin()) { do_action('bbconnect_results_display', $ret_res); } ?> </form> <?php if (function_exists('bbconnect_report_quicklinks')) { $args = array(); if (!empty($note_ids)) { $args['note_ids'] = $note_ids; } bbconnect_report_quicklinks($member_search, $args); } else { echo '<div id="quicklinks-wrapper">You should get the quicklinks addon!</div>'; } unset($ret_res); unset($table_head); unset($table_body); unset($pagenow); unset($all_search); unset($member_search); unset($action_search); unset($action_array); unset($bbconnect_errors); unset($bbconnect_query); unset($bbconnect_user_metas); unset($bbconnect_address_count); unset($current_member); unset($currency); unset($currency_array); unset($tdw); unset($_POST); }