예제 #1
0
function amr_generate_csv($ulist, $strip_endings, $strip_html = false, $suffix, $wrapper, $delimiter, $nextrow, $tofile = false)
{
    /* get the whole cached file - write to file? but security / privacy ? */
    /* how big */
    $c = new adb_cache();
    $rptid = $c->reportid($ulist);
    $total = $c->get_cache_totallines($rptid);
    $lines = $c->get_cache_report_lines($rptid, 1, $total + 1);
    /* we want the heading line (line1), but not the internal nameslines (line 0) , plus all the data lines, so neeed total + 1 */
    if (isset($lines) and is_array($lines)) {
        $t = count($lines);
    } else {
        $t = 0;
    }
    $csv = '';
    if ($t > 0) {
        if ($strip_endings) {
            foreach ($lines as $k => $line) {
                $csv .= apply_filters('amr_users_csv_line', $line['csvcontent']) . $nextrow;
            }
        } else {
            foreach ($lines as $k => $line) {
                $csv .= $line['csvcontent'] . $nextrow;
            }
        }
        $csv = str_replace('","', $wrapper . $delimiter . $wrapper, $csv);
        /* we already have in std csv - allow for other formats */
        $csv = str_replace($nextrow . '"', $nextrow . $wrapper, $csv);
        $csv = str_replace('"' . $nextrow, $wrapper . $nextrow, $csv);
        if ($csv[0] == '"') {
            $csv[0] = $wrapper;
        }
    }
    if (amr_debug()) {
        echo '<br />In Debug only: Csv setup: Report: ' . $ulist . ' ' . $c->reportname($ulist) . ' ' . sprintf(__('%s lines found, 1 heading line, the rest data.', 'amr-users'), $t);
        $bytes = mb_strlen($csv);
        echo ' Size = ' . amru_convert_mem($bytes) . '<br />';
    }
    if ($tofile) {
        $csvfile = amr_users_to_csv($ulist, $csv, $suffix);
        $csvurl = amr_users_get_csv_link($ulist);
        //return ($csvurl);
        $html = '<br />' . __('Public user list csv file: ', 'amr-users') . '<br />' . $csvurl;
    } else {
        echo '<p>' . sprintf(__('List %s, %s lines, plus heading line'), $ulist, $t) . '</p>';
        $html = amr_csv_form($csv, $suffix);
    }
    return $html;
}
예제 #2
0
function alist_one_widget($type = 'user', $i = 1, $do_headings = false, $do_csv = false, $max = 10)
{
    /* a widget version of alist one*/
    /* Get the fields to use for the chosen list type */
    global $aopt;
    global $amain;
    $c = new adb_cache();
    $rptid = $c->reportid($i, $type);
    $line = $c->get_cache_report_lines($rptid, '0', '2');
    /* get the internal heading names  for internal plugin use only */
    /* get the user defined heading names */
    if (!defined('str_getcsv')) {
        $icols = amr_str_getcsv($line[0]['csvcontent'], ',', '"', '\\');
    } else {
        $icols = str_getcsv($line[0]['csvcontent'], ',', '"', '\\');
    }
    //		if (!defined('str_getcsv')) $cols = amr_str_getcsv( $line[1]['csvcontent'], '","','"','\\');
    //		else $cols = str_getcsv( $line[1]['csvcontent'], ',','"','\\');
    foreach ($icols as $ic => $cv) {
        /* use the icols as our controlling array, so that we have the internal field names */
        $v = $cols[$ic];
        $html .= '<th>' . $v . '</th>';
    }
    $hhtml = '<thead><tr>' . $html . '</tr></thead>';
    /* setup the html for the table headings */
    $fhtml = '<tfoot><tr>' . $html . '</tr>' . '</tfoot>';
    /* setup the html for the table headings */
    $html = '';
    $totalitems = $c->get_cache_totallines($rptid);
    $lines = $c->get_cache_report_lines($rptid, $start + 1, $max);
    if (!($lines > 0)) {
        amr_flag_error($c->get_error('numoflists'));
        return false;
    }
    foreach ($lines as $il => $l) {
        $id = $lineitems[0];
        /*  *** pop the first one - this should always be the id */
        $user = amr_get_userdata($id);
        unset($linehtml);
        foreach ($icols as $ic => $c) {
            /* use the icols as our controlling array, so that we have the internal field names */
            $v = $lineitems[$ic];
            $linehtml .= '<td>' . amr_format_user_cell($c, $v, $user) . '</td>';
        }
        $html .= PHP_EOL . '<tr>' . $linehtml . '</tr>';
    }
    $html = '<table>' . $hhtml . $fhtml . '<tbody>' . $html . '</tbody></table>';
    return $html;
}