* Copyright (c) 2002-2006 Platon Group, http://platon.sk/ * All rights reserved. * * See README file for more information about this software. * See COPYING file for license information. * * Download the latest version from * http://platon.sk/projects/phpMyEdit/ */ /* $Platon: phpMyEdit/extensions/phpMyEdit-report.class.php,v 1.11 2004/12/30 19:59:00 nepto Exp $ */ /* Extension TODO: - allow user to enable/disable particular field in reporting (maybe 'X' flag for indicating that field is forbidden is good idea) - support for ['help'] in select fields screen - make extension's option for selecting "Select fields" link or button */ require_once dirname(__FILE__).'/../phpMyEdit.class.php'; class phpMyEdit_report extends phpMyEdit { function phpMyEdit_report($opts) /* {{{ */ { $opts['options'] = 'L'; $execute = 1; isset($opts['execute']) && $execute = $opts['execute']; $opts['execute'] = 0; parent::phpMyEdit($opts); $execute && $this->execute(); } /* }}} */ function make_language_labels($language) /* {{{ */ { $ret = parent::make_language_labels($language); strlen($ret['Make report']) <= 0 && $ret['Make report'] = 'Make report'; strlen($ret['Select fields']) <= 0 && $ret['Select fields'] = 'Select fields'; strlen($ret['Records per screen']) <= 0 && $ret['Records per screen'] = 'Records per screen'; return $ret; } /* }}} */ function get_cgi_cookie_var($name, $default_value = null) /* {{{ */ { $ret = $this->get_cgi_var($name, null); if ($ret === null) { global $HTTP_COOKIE_VARS; $ret = @$HTTP_COOKIE_VARS[$name.'_'.$this->tb.'_cookie']; if (! isset($ret)) { $ret = $default_value; } } return $ret; } /* }}} */ function display_list_table_buttons($total_recs, $position) /* {{{ */ { /* This is mostly copy/paste from core class. */ $listall = $this->inc <= 0; // Are we doing a listall? echo '',"\n"; echo '',"\n"; echo '',"\n"; if (strlen(@$this->message) > 0) { echo '',"\n"; } // Display page and records statistics echo '
',"\n"; echo ' '; // Note that fm > 0 && ! $listall) ? '' : ' disabled'; echo ' '; $disabled = ($this->fm + $this->inc < $total_recs && ! $listall) ? '' : ' disabled'; echo ''; // Message is now written here echo '',$this->message,'',"\n"; if ($listall) { echo $this->labels['Page'],': 1 ',$this->labels['of'],' 1'; } else { echo $this->labels['Page'],': ',($this->fm / $this->inc) + 1; echo ' ',$this->labels['of'],' ',max(1, ceil($total_recs / abs($this->inc))); } echo '  ',$this->labels['Records'],': ',$total_recs; echo '
',"\n"; } /* }}} */ function display_report_selection_buttons($position) /* {{{ */ { echo '',"\n"; echo '',"\n"; echo '
',"\n"; echo '',"\n"; echo '
',"\n"; } /* }}} */ function get_select_fields_link() /* {{{ */ { $link = ''.$this->labels['Select fields'].''; return $link; } /* }}} */ function execute() /* {{{ */ { global $HTTP_GET_VARS; global $HTTP_POST_VARS; /* * Extracting field names */ $table_cols = array(); $all_table_cols = array(); if ($this->connect() == false) { return false; } $query_parts = array( 'type' => 'select', 'select' => '*', 'from' => $this->tb, 'limit' => '1'); $result = $this->myquery($this->get_SQL_query($query_parts), __LINE__); $all_table_cols = array_keys(@mysql_fetch_array($result, MYSQL_ASSOC)); if (count($all_table_cols) <= 0) { $this->error('database fetch error'); return false; } foreach (array_keys($this->fdd) as $field_name) { if (preg_match('/^\d*$/', $field_name)) continue; if (($idx = array_search($field_name, $all_table_cols)) !== false) $table_cols[$field_name] = mysql_field_len($result, $idx); } @mysql_free_result($result); unset($all_table_cols); /* * Preparing variables */ $fields_select = $this->get_cgi_var('fields_select'); $filter = $this->get_cgi_var('filter'); $prepare_filter = $this->get_cgi_var('prepare_filter'); $this->inc = intval($this->get_cgi_cookie_var('inc')); $force_select = true; $none_displayed = true; $expire_time = time() + (3600 * 24 * 30 * 12 * 5); // five years $headers_sent = @headers_sent(); foreach (array_merge(array('@inc'), array_keys($table_cols)) as $col) { $varname = ($col[0] == '@' ? substr($col, 1) : 'have_'.$col); if (isset($HTTP_POST_VARS[$varname]) || isset($HTTP_GET_VARS[$varname])) { $value = $HTTP_POST_VARS[$varname]; if (isset($HTTP_GET_VARS[$varname])) { $value = $HTTP_GET_VARS[$varname]; } if ($varname != 'inc' && ! empty($value)) { $force_select = false; } $headers_sent || setcookie($varname.'_'.$this->tb.'_cookie', $value, $expire_time); $this->cgi['persist'] .= '&'.urlencode($varname); $this->cgi['persist'] .= '='.urlencode($value); } else { $headers_sent || setcookie($varname.'_'.$this->tb.'_cookie', '', time() - 10000); } } $i = -1; foreach (array_keys($this->fdd) as $key) { $i++; if (preg_match('/^\d*$/', $key)) continue; $varname = 'have_'.$key; $value = @$this->get_cgi_cookie_var($varname, ''); $options = @$value ? 'LV' : ''; $this->fdd[$i]['options'] = $options; $this->fdd[$key]['options'] = $options; $this->displayed[$i] = @$value ? true : false; $value && $none_displayed = false; } /* * Redirecting when neccessary * (hackity hack with unregistering/unchecking fields) */ if ($prepare_filter && ! $headers_sent) { $this->execute_redirect(); exit; } /* * Check if field selection report screen has to be displayed */ if (isset($fields_select) || $force_select || $none_displayed) { $this->execute_report_screen($table_cols); return true; } if (0) { $this->message .= $this->get_select_fields_link(); } // parent class call return parent::execute(); } /* }}} */ function execute_redirect() /* {{{ */ { global $HTTP_SERVER_VARS; global $HTTP_GET_VARS; global $HTTP_POST_VARS; $redirect_url = 'http://'.$HTTP_SERVER_VARS['HTTP_HOST'].$HTTP_SERVER_VARS['SCRIPT_NAME']; $delim = '?'; foreach ($HTTP_POST_VARS + $HTTP_GET_VARS as $cgi_var_name => $cgi_var_value) { $cgi_var_name == 'prepare_filter' && $cgi_var_name = 'filter'; $redirect_url .= $delim; $redirect_url .= rawurlencode($cgi_var_name).'='.rawurlencode($cgi_var_value); $delim == '?' && $delim = '&'; } $redirect_url .= $this->cgi['persist']; header('Location: '.$redirect_url); exit; } /* }}} */ function execute_report_screen($table_cols) /* {{{ */ { echo '
',"\n"; if ($this->nav_up()) { $this->display_report_selection_buttons('up'); echo '
',"\n"; } echo '',"\n"; $i = 0; foreach ($table_cols as $key => $val) { $css_postfix = @$this->fdd[$key]['css']['postfix']; $css_class_name = $this->getCSSclass('input', null, true, $css_postfix); $varname = 'have_'.$key; $value = $this->get_cgi_cookie_var($varname); $checked = @$value ? ' checked' : ''; echo '',"\n"; echo '',"\n"; echo '',"\n"; echo '',"\n",'',"\n"; $i++; } echo '',"\n"; echo ''; echo '',"\n"; echo '
'; echo $this->fdd[$i]['name'],''; echo ''; echo 'getColAttributes($key),">\n"; $varname = 'qf'.$i; $value = $this->get_cgi_cookie_var($varname); if ($this->fdd[$key]['select'] == 'D' || $this->fdd[$key]['select'] == 'M') { $from_table = ! $this->col_has_values($key) || isset($this->fdd[$key]['values']['table']); $selected = $value; $value = $this->set_values($key, array('*' => '*'), null, $from_table); $multiple = $this->col_has_multiple_select($key); $multiple |= $this->fdd[$key]['select'] == 'M'; $readonly = false; $strip_tags = true; $escape = true; echo $this->htmlSelect($varname.'_id', $css_class_name, $value, $selected, $multiple, $readonly, $strip_tags, $escape); } else { echo ''; } echo '
'; echo $this->labels['Records per screen'],''; echo ''; echo '
',"\n"; if ($this->nav_down()) { echo '
',"\n"; $this->display_report_selection_buttons('down'); } echo '
'; } /* }}} */ } /* Modeline for ViM {{{ * vim:set ts=4: * vim600:fdm=marker fdl=0 fdc=0: * }}} */ ?>