function amr_empty_start_list($linessaved, $icols, $cols, $page, $rowsperpage, $totalitems, $caption, $search, $ulist, $c, $filtercol, $sortedbynow, $options = array()) { global $aopt, $amain, $amrusers_fieldfiltering, $amr_current_list, $amr_search_result_count, $ahtm; // the display html structure to use global $amr_refreshed_heading; $amr_current_list = $ulist; $html = $hhtml = $fhtml = ''; $filterhtml = ''; $filterhtml_separate = ''; $apply_filter_html = ''; $filter_submit_html = ''; $summary = ''; $explain_filter = ''; $adminoptions = array('show_search' => true, 'show_perpage' => true, 'show_pagination' => true, 'show_headings' => true, 'show_csv' => true, 'show_refresh' => true); if (!is_admin()) { // set public options to overrwite admin foreach ($adminoptions as $i => $opt) { if (isset($options[$i])) { $adminoptions[$i] = $options[$i]; } else { $adminoptions[$i] = ''; } } } //if (WP_DEBUG) var_dump($adminoptions); if (!empty($_REQUEST['headings']) or !empty($_REQUEST['filtering'])) { $adminoptions['show_search'] = false; $adminoptions['show_csv'] = false; $adminoptions['show_refresh'] = false; $adminoptions['show_perpage'] = false; $adminoptions['show_headings'] = false; $adminoptions['show_pagination'] = true; $amain['filter_html_type'][$amr_current_list] = 'none'; // if editingheadings, then no showingfilter } if (is_admin() or !isset($amain['html_type'][$amr_current_list])) { // must be after the check above, so will force table in admin $ahtm = amr_get_html_to_use('table'); } else { $ahtm = amr_get_html_to_use($amain['html_type'][$amr_current_list]); } if (empty($linessaved)) { $saveditems = 0; } else { $saveditems = count($linessaved); } if (is_array($caption)) { $caption = '<h3 class="caption">' . implode(', ', $caption) . '</h3>'; } // now fix the icols and cols for any special functioning-------------------------- if (isset($icols[0]) and $icols[0] == 'ID') { /* we only saved the ID so that we can access extra info on display - we don't want to always display it */ unset($icols[0]); unset($cols[0]); } $icols = array_unique($icols); // since may end up with two indices, eg if filtering and grouping by same value foreach ($icols as $i => $col) { if ($col == 'index') { // we only saved the index so that we can access extra info on display - we don't want to display it if (!isset($aopt['list'][$amr_current_list]['selected']['index'])) { unset($icols[$i]); unset($cols[$i]); } } else { if (!isset($cols[$i])) { unset($icols[$i]); } } } // end fix icols and cols if (!empty($search)) { $searchselectnow = sprintf(__('%s Users found.', 'amr-users'), $amr_search_result_count); $searchselectnow .= sprintf(__('Searching for "%s" in list', 'amr-users'), $search); } // reset count if searching if (isset($amain['sortable'])) { $sortable = $amain['sortable']; } else { $sortable = false; } if (!empty($adminoptions['show_headings'])) { //admin always has if (is_admin()) { if (!empty($amr_refreshed_heading)) { $summary = $amr_refreshed_heading; } else { $summary = $c->get_cache_summary(amr_rptid($ulist)); } } if (!empty($sortedbynow)) { $summary = str_replace('<li class="sort">', $sortedbynow, $summary); } if (!empty($searchselectnow)) { $summary = str_replace('<li class="selected">', '<li class="searched">' . $searchselectnow . '</li><li class="selected">', $summary); } if (!empty($filtercol)) { $text = implode(', ', $filtercol); $summary = str_replace('<li class="selected">', '<li class="selected">' . __('Selected users with: ', 'amr-users') . $text . '</li><li class="selected">', $summary); } } // //$sortedbynow is set if maually resorted if (!isset($amain['html_type'][$amr_current_list]) or !isset($amain['filter_html_type']) or isset($amain['filter_html_type'][$amr_current_list]) and $amain['filter_html_type'][$amr_current_list] == "intableheader") { if (function_exists('amr_show_filters')) { // for pseudo compatability if unmatched versions $filterhtml = amr_show_filters($cols, $icols, $ulist, $filtercol); // will have tr and th } } elseif (!empty($amain['filter_html_type'][$amr_current_list]) and $amain['filter_html_type'][$amr_current_list] == "above") { if (function_exists('amr_show_filters_alt')) { $filterhtml_separate = amr_show_filters_alt($cols, $icols, $ulist, $filtercol); } } if (!empty($filterhtml) or !empty($filterhtml_separate)) { $apply_filter_html = amr_show_apply_filter_button($ulist); } // footer $fhtml = $ahtm['tfoot'] . $ahtm['tr'] . '>'; if (stristr($ahtm['th'], '<th')) { // if table $fhtml .= $ahtm['th'] . ' colspan="' . count($icols) . '">' . amr_users_give_credit(); } else { $fhtml .= $ahtm['th'] . '>'; } $fhtml .= $ahtm['thc'] . $ahtm['trc'] . $ahtm['tfootc']; /* setup the html for the table headings */ if (!empty($linessaved)) { $html .= amr_display_a_page($linessaved, $icols, $cols, $ahtm); } // if (!empty($adminoptions['show_search'])) { $sformtext = alist_searchform($ulist); } else { $sformtext = ''; } // if (!empty($adminoptions['show_csv'])) { $csvtext = amr_users_get_csv_link($ulist, 'csv'); } else { $csvtext = ''; } // if (!empty($adminoptions['show_refresh'])) { $refreshtext = amr_users_get_refresh_link($ulist); } else { $refreshtext = ''; } // if (!empty($adminoptions['show_perpage'])) { $pformtext = alist_per_pageform($ulist); } else { $pformtext = ''; } if (!empty($amr_search_result_count)) { if ($rowsperpage > $amr_search_result_count) { $rowsperpage = $amr_search_result_count; } //$totalitems = $amr_search_result_count; } if (function_exists('amr_custom_navigation')) { $custom_nav = amr_custom_navigation($ulist); } else { $custom_nav = ''; } $moretext = ''; if (!empty($adminoptions['show_pagination'])) { // allows on to just show latest x $pagetext = amr_pagetext($page, $totalitems, $rowsperpage); } else { $pagetext = ''; } if (!empty($filterhtml) or !empty($hhtml)) { $hhtml = $ahtm['thead'] . $filterhtml . $hhtml . $ahtm['theadc']; } $html = amr_manage_headings_submit() . $filter_submit_html . $sformtext . $explain_filter . $filterhtml_separate . $apply_filter_html . $custom_nav . $pagetext . PHP_EOL . '<div id="userslist' . $ulist . '"><!-- user list-->' . PHP_EOL . $ahtm['table'] . $caption . $hhtml . $fhtml . PHP_EOL . $ahtm['tbody'] . $html . $ahtm['tbodyc'] . '<!-- end user list body-->' . PHP_EOL . $ahtm['tablec'] . '<!-- end user list table-->' . PHP_EOL . PHP_EOL . '</div><!-- end user list-->' . PHP_EOL . '<div class="userlistfooter">' . $pagetext . $csvtext . $refreshtext . $pformtext . '</div>'; if (is_admin()) { $html = PHP_EOL . '<div class="wrap" >' . $html . '</div>' . PHP_EOL; } $html = $summary . $html; return $html; }
function amr_build_user_data_maybe_cache($ulist = '1') { //returns the lines of data, including the headings global $amr_refreshed_heading; // seems heading not used right when we are filtering. workaround for now. /* Get the fields to use for the chosen list type */ global $aopt, $amrusers_fieldfiltering; global $amain; global $wp_post_types; global $time_start; global $cache; global $amr_current_list; $amr_current_list = $ulist; if (get_transient('amr_users_cache_' . $ulist)) { track_progress('Stop - run for ' . $ulist . ' in progress already according to transient'); return false; } //else track_progress('Set in progress flag for '.$ulist); set_transient('amr_users_cache_' . $ulist, true, 10); // 10 seconds allowed for now $network = ausers_job_prefix(); // track_progress('Getting data for network='.$network); register_shutdown_function('amr_shutdown'); set_time_limit(360); // should we make this an option.... $time_start = microtime(true); ameta_options(); $date_format = get_option('date_format'); $time_format = get_option('time_format'); add_filter('pub_priv_sql_capability', 'amr_allow_count'); // checked by the get_posts_by_author_sql if (!isset($amrusers_fieldfiltering)) { $amrusers_fieldfiltering = false; } if (function_exists('amr_check_for_realtime_filtering')) { amr_check_for_realtime_filtering($ulist); } if (empty($aopt['list'][$ulist])) { track_progress('No configuration for list ' . $ulist); return false; } $l = $aopt['list'][$ulist]; /* *get the config with any additional filtering */ $rptid = amr_rptid($ulist); if (!$amrusers_fieldfiltering) { // then do cache stuff /* now record the cache attempt */ $cache = new adb_cache(); $r = $cache->clear_cache($rptid); // If (!($r)) echo '<br />Cache does not exist or not cleared for '.$rptid; $r = $cache->record_cache_start($rptid, $amain['names'][$ulist]); // If (!($r)) echo '<br />Cache start not recorded '.$rptid; // $cache->log_cache_event(sprintf(__('Started cacheing report %s','amr-users'),$rptid)); } // end cache //track_progress('before get all users needed'); $list = amr_get_alluserdata($ulist); /* keyed by user id, and only the non excluded main fields and the ones that we asked for */ $total = count($list); //track_progress('after get all user data'.$total); $head = ''; $tablecaption = ''; if ($total > 0) { if (isset($l['selected']) and count($l['selected']) > 0) { $head .= PHP_EOL . '<div class="wrap" style ="clear: both; text-align: center; font-size:largest;"><!-- heading wrap -->' . PHP_EOL . '<strong>' . $amain['names'][$ulist] . '</strong>'; /* to look like wordpress */ $tablecaption .= '<caption> ' . $amain['names'][$ulist] . '</caption>'; $head .= '<ul class="report_explanation" style="list-style-type:none;">'; /* check for filtering */ if (isset($l['excluded']) and count($l['excluded']) > 0) { /* do headings */ $head .= '<li><em>' . __('Excluding where:', 'amr-users') . '</em> '; foreach ($l['excluded'] as $k => $ex) { if (is_array($ex)) { $head .= ' ' . agetnice($k) . '=' . implode(__(' or ', 'amr-users'), $ex) . ','; } else { $head .= ' ' . agetnice($k) . '=' . $ex . ', '; } if (empty($list)) { return; } foreach ($list as $iu => $user) { if (isset($user[$k])) { /* then we need to check the values and exclude the whole user if necessary */ if (is_array($ex)) { if (in_array($user[$k], $ex)) { unset($list[$iu]); } } else { if ($user[$k] == $ex) { unset($list[$iu]); } } } } } $head = rtrim($head, ','); $head .= '</li>'; } if (isset($l['excludeifblank']) and count($l['excludeifblank']) > 0) { $head .= '<li><em>' . __('Exclude if blank:', 'amr-users') . '</em> '; foreach ($l['excludeifblank'] as $k => $tf) { $head .= ' ' . agetnice($k) . ','; if (empty($list)) { return; } foreach ($list as $iu => $user) { /* now check each user */ if (empty($user[$k])) { /* if does not exists or empty then we need to check the values and exclude the whole user if necessary */ unset($list[$iu]); } } } $head = rtrim($head, ','); $head .= '</li>'; } //if (WP_DEBUG) track_progress('after excluding users:'.count($list)); if (isset($l['includeonlyifblank']) and count($l['includeonlyifblank']) > 0) { $head .= '<li><em>' . __('Include only if blank:', 'amr-users') . '</em> '; foreach ($l['includeonlyifblank'] as $k => $tf) { $head .= ' ' . agetnice($k) . ','; if (empty($list)) { return; } foreach ($list as $iu => $user) { /* now check each user */ if (!empty($user[$k])) { /* if does not exists or empty then we need to check the values and exclude the whole user if necessary */ unset($list[$iu]); } } } $head = rtrim($head, ','); $head .= '</li>'; } //if (WP_DEBUG) track_progress('after checking include if blank:'.count($list)); if (isset($l['included']) and count($l['included']) > 0) { $head .= '<li><em>' . __('Including where:', 'amr-users') . '</em> '; foreach ($l['included'] as $k => $in) { //if (WP_DEBUG) {echo '<br />Check include:'.$k;var_dump($in);} $inc = implode(__(' or ', 'amr-users'), $in); $head .= ' ' . agetnice($k) . '=' . $inc . ','; //if (WP_DEBUG) {echo '<br />'.$head;} if (!empty($list)) { foreach ($list as $iu => $user) { /* for each user */ if (isset($user[$k])) { /* then we need to check the values and include the user if a match */ // user[k] could be csv multiple values // inclusions an array, so need to do a like? or a $is_in = false; //if (WP_DEBUG) {echo '<br />Check user:'******','); $head .= '</li>'; } //if (WP_DEBUG) { track_progress('after checking includes '.count($list));//echo '<br />'.$head; } if (isset($l['sortby']) and count($l['sortby']) > 0) { $head .= '<li class="sort"><em>' . __(' Cache sorted by: ', 'amr-users') . '</em>'; /* class used to replace in the front end sort info */ asort($l['sortby']); // sort the sortbys first, so that $cols is in right order $cols = array(); foreach ($l['sortby'] as $sbyi => $sbyv) { if (isset($l['sortdir'][$sbyi])) { //$cols[$sbyi] = array(SORT_DESC); 20111214 $cols[$sbyi] = SORT_DESC; } else { //$cols[$sbyi] = array(SORT_ASC); 20111214 $cols[$sbyi] = SORT_ASC; } $head .= agetnice($sbyi) . ','; } //track_progress('after sortby '.$ulist); $head = rtrim($head, ','); $head .= '</li>'; //track_progress('before msort cols = '.count($cols)); if (!empty($cols)) { $list = auser_multisort($list, $cols); } //track_progress('after msort '.$ulist); } unset($cols); if (empty($list)) { $tot = 0; } else { $tot = count($list); } //track_progress('after sorting '.$tot.' users'); if ($tot === $total) { $text = sprintf(__('All %1s Users processed.', 'amr-users'), $total); } else { $text = sprintf(__('%1s Users processed from total of %2s', 'amr-users'), $tot, $total); } //$tottext = sprintf(__('%1s records in list', 'amr-users'), $tot); $head .= '<li class="selected">' . $text . '</li>'; $head .= '</ul>' . PHP_EOL . '</div><!-- heading wrap -->' . PHP_EOL; //if (WP_DEBUG) {echo '<br />'.$head;} $html = $head; if (empty($amr_refreshed_heading)) { $amr_refreshed_heading = $head; } else { $amr_refreshed_heading = $head . $amr_refreshed_heading; } $html = $head; $count = 0; //now make the fields into columns if ($tot > 0) { //if (empty($list)) echo '<br />1What happened list is empty '; if (!empty($l['grouping'][1])) { $grouping_field = $l['grouping'][1]; } $sel = $l['selected']; asort($sel); /* get the selected fields in the display order requested */ foreach ($sel as $s2 => $sv) { if ($sv > 0) { $sel2[$s2] = $sv; } } // here we can jump in and save the filter values, if we are NOT already doing a real timefilter // if do filtering , then build up filter for values now if (!$amrusers_fieldfiltering and function_exists('amr_save_filter_fieldvalues')) { $combofields = amr_get_combo_fields($ulist); if (empty($list)) { echo '<br />What happened list is empty '; } amr_save_filter_fieldvalues($ulist, $list, $combofields); } /* get the col headings ----------------------------*/ $lines[0] = amr_build_cols($sel2); // tech headings $lines[1] = amr_build_col_headings($sel2); // the headings lines foreach ($lines[1] as $jj => $kk) { if (empty($kk)) { $lines[1][$jj] = '""'; } else { $lines[1][$jj] = '"' . str_replace('"', '""', $kk) . '"'; } /* Note for csv any quote must be doubleqouoted */ } if (!$amrusers_fieldfiltering) { // then do cache stuff /* cache the col headings ----------------------------*/ //$csv = implode (",", $iline); $cache->cache_report_line($rptid, 0, $lines[0]); /* cache the internal column headings */ // $cols = amr_users_get_column_headings ($ulist, $line, $iline); //$csv = implode (",", $line); $cache->cache_report_line($rptid, 1, $lines[1]); /* cache the column headings */ //unset($cols); //unset($line);unset($iline); unset($lines); //track_progress('before cacheing list'); } $count = 1; if (!empty($list)) { foreach ($list as $j => $u) { //if (WP_DEBUG) echo '<br />Building list add: '.$j; var_dump($u);; $count = $count + 1; unset($line); if (!empty($u['ID'])) { $line[0] = $u['ID']; } else { $line[0] = ''; } foreach ($sel2 as $is => $v) { /* defines the column order */ $colno = (int) $v; if (!isset($u[$is])) { $value = ''; } else { $value = $u[$is]; } /* unfortunately for fields, this must be done here */ if (!empty($value)) { if (!empty($l['before'][$is])) { $value = html_entity_decode($l['before'][$is]) . $value; } if (!empty($l['after'][$is])) { $value = $value . html_entity_decode($l['after'][$is]); } } if (!empty($line[$colno])) { $line[$colno] .= $value; } else { $line[$colno] = $value; } } if (function_exists('ausers_build_format_column')) { // code to call extra function added as per andy.bounsall request, not yet fully tested by me foreach ($line as $colno => $value) { $line[$colno] = ausers_build_format_column($ulist, $colno, $value); } } /* ****** PROBLEM - ok now? must be at end*/ /* *** amr - can we save the grouping field value similar to the index maybe ? */ if (!empty($grouping_field) and !empty($u[$grouping_field])) { $line[99998] = $u[$grouping_field]; } // else // $line[99998] = ''; // save the index value if have it if (!empty($u['index'])) { $line[99999] = $u['index']; } else { $line[99999] = ''; } $lines[$count] = $line; unset($line); } } if (empty($lines)) { echo '<br / >Problem - no lines'; } //else if (WP_DEBUG) {echo '<br />'; var_dump($lines);} unset($list); // do not need list, we got the lines now if (!$amrusers_fieldfiltering) { // then do cache stuff $cache->cache_report_lines($rptid, 2, $lines); } } else { $html .= sprintf(__('No users found for list %s', 'amr-users'), $ulist); } } else { $html .= '<h2 style="clear:both; ">' . sprintf(__('No fields chosen for display in settings for list %s', 'amr-users'), $ulist) . '</h2>'; } } else { $html .= __('No users in database! - que pasar?', 'amr-users'); } unset($s); //track_progress('nearing end'); if (!$amrusers_fieldfiltering) { // if we are not just doing a real time filtering where we will not have full data then do cache stuff $cache->record_cache_end($rptid, $count - 1); $cache->record_cache_peakmem($rptid); $cache->record_cache_headings($rptid, $html); $time_end = microtime(true); $time = $time_end - $time_start; $cache->log_cache_event('<em>' . sprintf(__('Completed %s in %s microseconds', 'amr-users'), $rptid, number_format($time, 2)) . '</em>'); } if (!empty($amain['public'][$ulist])) { // returns url if set to go to file $csvurl = amr_generate_csv($ulist, true, false, 'csv', '"', ',', chr(13) . chr(10), true); } delete_transient('amr_users_cache_' . $ulist); // so another can run //track_progress('Release in progress flag for '.$ulist); delete_transient('amr-users-html-for-list-' . $ulist); // to force use of new one // we built up the html when filtering, but then trashed again ? if (!empty($lines)) { return $lines; } else { return false; } }