**** Pager INIT file starts HERE copy and save as class.init.php 406) { $session_vars = '_SESSION'; $post_vars = '_POST'; $get_vars = '_GET'; $server_vars = '_SERVER'; $cookie_vars = '_COOKIE'; $files_vars = '_FILES'; $env_vars = '_ENV'; } else { $session_vars = 'HTTP_SESSION_VARS'; $post_vars = 'HTTP_POST_VARS'; $get_vars = 'HTTP_GET_VARS'; $server_vars = 'HTTP_SERVER_VARS'; $cookie_vars = 'HTTP_COOKIE_VARS'; $files_vars = 'HTTP_POST_FILES'; $env_vars = 'HTTP_ENV_VARS'; } foreach (${$GLOBALS['server_vars']} as $index=>$value) { $GLOBALS[$index] = $value; } /* recursively strip slashes from the values of an array */ function RemoveSlashes(&$array) { if(count($array) > 0) { foreach ($array as $index=>$value) { if (is_array($array[$index])) { RemoveSlashes($array[$index]); } else { $array[$index] = stripslashes($value); } } } } // Remove slashes if PHP added them if (get_magic_quotes_gpc()) { global $REQUEST_METHOD; if ($REQUEST_METHOD == "POST") { global ${$GLOBALS['post_vars']}; RemoveSlashes(${$GLOBALS['post_vars']}); } else if ($REQUEST_METHOD == "GET") { global ${$GLOBALS['get_vars']}; RemoveSlashes(${$GLOBALS['get_vars']}); } } // set include_path // $include_path = ini_get('include_path'); // $include_path .= ereg_replace(':', $include_separator, ':.:adodb:class'); // ini_set('include_path', $include_path); // error reporting // error_reporting($error_report); // include 'config.php'; // include 'adodb.inc.php'; // include 'class.template.inc.php'; // include 'class.block.inc.php'; include 'class.pager.inc.php'; //include 'class.xls.BIFFwriter.inc.php'; //include 'class.xls.Worksheet.inc.php'; //include 'class.xls.Format.inc.php'; //include 'class.xls.OLEwriter.inc.php'; //include 'class.xls.Parser.inc.php'; //include 'class.xls.Workbook.inc.php'; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; function parsedate($str) { if (ereg('^'.$GLOBALS['date_ereg'].'$', $str, $regs)) { eval('$timestamp = '.$GLOBALS['date_eval'].';'); } return $timestamp; } ?> **** end of init **** Pager Class starts HERE copy and save as class.pager.inc.php sql = $sql; $this->id = $id; $this->db = $db; $this->label_arr = $label_arr; $this->optional_arr = $optional_arr; $this->var_arr = $var_arr; $this->eval_arr = $eval_arr; $this->header_view = $header_view; $this->search_view = $search_view; $this->excel_save = ${$GLOBALS['get_vars']}[$xls_str] ? TRUE : FALSE; $this->csv_save = $this->excel_save ? FALSE : (${$GLOBALS['get_vars']}[$csv_str] ? TRUE : FALSE); if ($this->excel_save || $this->csv_save) { $this->label_arr['add_anchor'] = FALSE; $this->label_arr['edit_anchor'] = FALSE; $this->label_arr['del_anchor'] = FALSE; $this->label_arr['print_anchor'] = FALSE; $this->header_view = FALSE; $this->search_view = FALSE; } ${$GLOBALS['session_vars']}[$key_str] = IsSet(${$GLOBALS['post_vars']}[$key_str]) ? ${$GLOBALS['post_vars']}[$key_str] : ( ${$GLOBALS['get_vars']}[$key_str] ? ${$GLOBALS['get_vars']}[$key_str] : ( ${$GLOBALS['session_vars']}[$key_str] ? ${$GLOBALS['session_vars']}[$key_str] : '' ) ); ${$GLOBALS['session_vars']}[$fdat_str] = ${$GLOBALS['post_vars']}[$fdat_str] ? ${$GLOBALS['post_vars']}[$fdat_str] : ( ${$GLOBALS['get_vars']}[$fdat_str] ? ${$GLOBALS['get_vars']}[$fdat_str] : ( ${$GLOBALS['session_vars']}[$fdat_str] ? ${$GLOBALS['session_vars']}[$fdat_str] : '' ) ); ${$GLOBALS['session_vars']}[$tdat_str] = ${$GLOBALS['post_vars']}[$tdat_str] ? ${$GLOBALS['post_vars']}[$tdat_str] : ( ${$GLOBALS['get_vars']}[$tdat_str] ? ${$GLOBALS['get_vars']}[$tdat_str] : ( ${$GLOBALS['session_vars']}[$tdat_str] ? ${$GLOBALS['session_vars']}[$tdat_str] : '' ) ); //exit; $force_clean = ${$GLOBALS['get_vars']}['force_clean'] ? ${$GLOBALS['get_vars']}['force_clean'] : 0; //if ($force_clean || ${$GLOBALS['session_vars']}[$sql_str]!=$sql || ${$GLOBALS['session_vars']}[$key_str]=='listall') { if ($force_clean || ${$GLOBALS['session_vars']}[$key_str]=='listall') { ${$GLOBALS['session_vars']}[$curr_page] = ''; ${$GLOBALS['session_vars']}[$orderby] = ''; ${$GLOBALS['session_vars']}[$orderby_type] = ''; ${$GLOBALS['session_vars']}[$key_str] = ''; ${$GLOBALS['session_vars']}[$fdat_str] = ''; ${$GLOBALS['session_vars']}[$tdat_str] = ''; ${$GLOBALS['session_vars']}[$fsel_str] = ''; ${$GLOBALS['session_vars']}[$vsel_str] = ''; ${$GLOBALS['session_vars']}[$dsel_str] = ''; ${$GLOBALS['session_vars']}[$ppag_str] = ''; ${$GLOBALS['session_vars']}[$diso_str] = 1; ${$GLOBALS['session_vars']}[$orderby_arr] = $initial_sort; // Added by PC ${$GLOBALS['session_vars']}[$curr_where_str] = ''; // Added by PC /* Reset Advanced Search Fields */ ${$GLOBALS['session_vars']}[$advs_field] = array(); // Added by PC ${$GLOBALS['session_vars']}[$advs_op] = array(); // Added by PC ${$GLOBALS['session_vars']}[$advs_val] = array(); // Added by PC ${$GLOBALS['session_vars']}[$advs_andor] = array(); // Added by PC } ${$GLOBALS['session_vars']}[$curr_page] = ${$GLOBALS['post_vars']}[$next_page] ? ${$GLOBALS['post_vars']}[$next_page] : ( ${$GLOBALS['get_vars']}[$next_page] ? ${$GLOBALS['get_vars']}[$next_page] : ( ${$GLOBALS['session_vars']}[$curr_page] ? ${$GLOBALS['session_vars']}[$curr_page] : 1 ) ); ${$GLOBALS['session_vars']}[$orderby] = ${$GLOBALS['get_vars']}[$orderby] ? ${$GLOBALS['get_vars']}[$orderby] : ( ${$GLOBALS['session_vars']}[$orderby] ? ${$GLOBALS['session_vars']}[$orderby] : '' ); ${$GLOBALS['session_vars']}[$orderby_type] = ${$GLOBALS['get_vars']}[$orderby_type] ? ${$GLOBALS['get_vars']}[$orderby_type] : ( ${$GLOBALS['session_vars']}[$orderby_type] ? ${$GLOBALS['session_vars']}[$orderby_type] : 'ASC' ); ${$GLOBALS['session_vars']}[$sql_str] = $sql; ${$GLOBALS['session_vars']}[$fsel_str] = ${$GLOBALS['post_vars']}[$fsel_str] ? ${$GLOBALS['post_vars']}[$fsel_str] : ( ${$GLOBALS['get_vars']}[$fsel_str] ? ${$GLOBALS['get_vars']}[$fsel_str] : ( ${$GLOBALS['session_vars']}[$fsel_str] ? ${$GLOBALS['session_vars']}[$fsel_str] : array() )); ${$GLOBALS['session_vars']}[$dsel_str] = (${$GLOBALS['post_vars']}[$dsel_str]!="") ? ${$GLOBALS['post_vars']}[$dsel_str] : ( ${$GLOBALS['get_vars']}[$dsel_str] ? ${$GLOBALS['get_vars']}[$dsel_str] : ( ${$GLOBALS['session_vars']}[$dsel_str] ? ${$GLOBALS['session_vars']}[$dsel_str] : array() )); ${$GLOBALS['session_vars']}[$diso_str] = isset(${$GLOBALS['get_vars']}[$diso_str]) ? ${$GLOBALS['get_vars']}[$diso_str] : ( isset(${$GLOBALS['session_vars']}[$diso_str]) ? ${$GLOBALS['session_vars']}[$diso_str] : 1 ); $this->disorder = ${$GLOBALS['session_vars']}[$diso_str]; $this->curr_page = ${$GLOBALS['session_vars']}[$curr_page]; /* Setup search flag */ $this->do_search = IsSet(${$GLOBALS['post_vars']}['search_mode']) ? ${$GLOBALS['post_vars']}['search_mode'] : ''; if (${$GLOBALS['post_vars']}[$addv_str]) { $max_vsel = 0; foreach (${$GLOBALS['session_vars']}[$this->id.'_vselect'] as $key => $value) { if ($value > $max_vsel) { $max_vsel = $value; } } for ($i=0;$idisorder) { $prev_key = ''; foreach (${$GLOBALS['session_vars']}[$this->id.'_vselect'] as $key => $value) { if ($key == ${$GLOBALS['get_vars']}[$left_str]) { ${$GLOBALS['session_vars']}[$this->id.'_vselect'][$key]--; ${$GLOBALS['session_vars']}[$this->id.'_vselect'][$prev_key]++; } $prev_key = $key; } } else if (${$GLOBALS['get_vars']}[$righ_str] && ! $this->disorder) { $prev_key = ''; foreach (${$GLOBALS['session_vars']}[$this->id.'_vselect'] as $key => $value) { if ($prev_key == ${$GLOBALS['get_vars']}[$righ_str]) { ${$GLOBALS['session_vars']}[$this->id.'_vselect'][$key]--; ${$GLOBALS['session_vars']}[$this->id.'_vselect'][$prev_key]++; } $prev_key = $key; } } /*if (${$GLOBALS['session_vars']}[$key_str]=='listall') { ${$GLOBALS['session_vars']}[$key_str] = ''; ${$GLOBALS['session_vars']}[$fsel_str] = ''; }*/ // PC Routine to build sort array if (${$GLOBALS['session_vars']}[$order_set] != 1) { ${$GLOBALS['session_vars']}[$order_set] = 1; ${$GLOBALS['session_vars']}[$orderby_arr] = $initial_sort; } if (${$GLOBALS['get_vars']}[$orderby]) { // user clicked orderby // Check for field in array $obkey = ${$GLOBALS['get_vars']}[$orderby]; ${$GLOBALS['session_vars']}[$this->id.'_orderby_arr'][$obkey] = ${$GLOBALS['get_vars']}[$orderby_type]; if (${$GLOBALS['session_vars']}[$this->id.'_orderby_arr'][$obkey] == 'none') unset (${$GLOBALS['session_vars']}[$this->id.'_orderby_arr'][$obkey]); } // print the array for debug //print_r (${$GLOBALS['session_vars']}[$this->id.'_orderby_arr']); // Build sort string $orderby_sql = ''; foreach (${$GLOBALS['session_vars']}[$this->id.'_orderby_arr'] as $key => $value) $orderby_sql .= ($orderby_sql == '') ? ' ORDER BY '.$key.' '.$value : ', '.$key.' '.$value; // End of PC Routine // $orderby_sql = ${$GLOBALS['session_vars']}[$orderby] ? ' ORDER BY ' . ${$GLOBALS['session_vars']}[$orderby] . ' ' . // ${$GLOBALS['session_vars']}[$orderby_type] : ''; $this->orderby_sql = $orderby_sql; } function render_first($anchor=true) { global $PHP_SELF; $next_page = 1; if ($anchor) { $ret = <<< EOT id}_next_page={$next_page}&{$this->label_arr['extra_param']} title="First Page">{$this->first} EOT; } else { $ret = $this->first; } return $ret; } function render_next($anchor=true) { global $PHP_SELF; $next_page = $this->rs->AbsolutePage()+1; if ($anchor) { $ret = <<< EOT id}_next_page={$next_page}&{$this->label_arr['extra_param']} title="Next Page">{$this->next} EOT; } else { $ret = $this->next; } return $ret; } function render_last($anchor=true) { global $PHP_SELF; if (!$this->db->pageExecuteCountRows) { return ''; } $next_page = $this->rs->LastPageNo(); if ($anchor) { $ret = <<< EOT id}_next_page={$next_page}&{$this->label_arr['extra_param']} title="Last Page">{$this->last} EOT; } else { $ret = $this->last; } return $ret; } function render_prev($anchor=true) { global $PHP_SELF; $next_page = $this->rs->AbsolutePage()-1; if ($anchor) { $ret = <<< EOT id}_next_page={$next_page}&{$this->label_arr['extra_param']} title="Previous Page">{$this->prev} EOT; } else { $ret = $this->prev; } return $ret; } function render_grid() { global $PHP_SELF, ${$GLOBALS['session_vars']}; $rs = $this->rs; $label_arr = $this->label_arr; $optional_arr = $this->optional_arr; $eval_arr = $this->eval_arr; // $str = ''; $str = ''; $num_col = $rs->FieldCount(); $num_col++; //for field no. $label_arr['edit_anchor'] ? $num_col++ : ''; $label_arr['del_anchor'] ? $num_col++ : ''; $max_vsel = 0; for ($i=0;$ifield_arr);$i++) { $key = $this->field_arr[$i]; if ($optional_arr[$key]) continue; if (! isset(${$GLOBALS['session_vars']}[$this->id.'_vselect'][$key])) { ${$GLOBALS['session_vars']}[$this->id.'_vselect'][$key] = ++$max_vsel; } } $max_vsel = 0; if (! $this->disorder) { if (is_array(${$GLOBALS['session_vars']}[$this->id.'_vselect']) ) { asort(${$GLOBALS['session_vars']}[$this->id.'_vselect']); foreach (${$GLOBALS['session_vars']}[$this->id.'_vselect'] as $key => $value) { if ($value > $max_vsel) { ${$GLOBALS['session_vars']}[$this->id.'_vselect'][$key] = ++$max_vsel; } } } $i=0; foreach (${$GLOBALS['session_vars']}[$this->id.'_vselect'] as $key => $value) { $field_arr[$i++] = $key; } } else { $field_arr = $this->field_arr; for ($i=0;$ifield_arr);$i++) { $key = $this->field_arr[$i]; if ($optional_arr[$key]) continue; if (${$GLOBALS['session_vars']}[$this->id.'_vselect'][$key]) { ${$GLOBALS['session_vars']}[$this->id.'_vselect'][$key] = ++$max_vsel; } } } $skey = 0; for ($i=0;$iid.'_vselect'][$key])) { // ${$GLOBALS['session_vars']}[$this->id.'_vselect'][$key] = ++$max_vsel; //} if (! ${$GLOBALS['session_vars']}[$this->id.'_vselect'][$key]) continue; $skey++; $ordimg = ""; // This section replaced by PC multi column sort // if (${$GLOBALS['session_vars']}[$this->id.'_orderby']==$key) { // if (${$GLOBALS['session_vars']}[$this->id.'_orderby_type']=='asc') $ordimg = '↑'; // else if (${$GLOBALS['session_vars']}[$this->id.'_orderby_type']=='desc') $ordimg = '↓'; // } if (${$GLOBALS['session_vars']}[$this->id.'_orderby_arr'][$key]) { if (${$GLOBALS['session_vars']}[$this->id.'_orderby_arr'][$key] == 'asc') { $ordimg = '↑'; $ordtype = 'desc'; } elseif (${$GLOBALS['session_vars']}[$this->id.'_orderby_arr'][$key] == 'desc') { $ordimg = '↓'; $ordtype = 'none'; } } else { $ordtype = 'asc'; } // $ordtype = (${$GLOBALS['session_vars']}[$this->id.'_orderby']==$key) ? ((strtolower(${$GLOBALS['session_vars']}[$this->id.'_orderby_type'])=='asc') ? 'desc' : 'asc') : 'asc'; if (! $this->disorder && $skey>1) { $pkey_str = 'id.'_left='.$key."&{$this->label_arr['extra_param']} title=\"Move View to Left\">".'<-'.""; } if (! $this->disorder && $skey<$max_vsel) { $nkey_str = 'id.'_right='.$key."&{$this->label_arr['extra_param']} title=\"Move View to Right\">".'->'.""; } $str .= "'; } // $form_del_anchor = ereg_replace('.*openIT\(\'([^\']+)\'.*', "\\1", $label_arr['del_anchor']); $form_del_anchor = $label_arr['del_anchor']; $form_del_anchor_before = ereg_replace('%s', '', $form_del_anchor); $del_func_js = ' '; $GLOBALS['count_delform']++; $delform_name = 'deleteform'.$GLOBALS['count_delform']; $form_del_anchor = ''; if ($GLOBALS['count_delform']==1) $form_del_anchor = $del_func_js; $del_func2_js = ' '; $form_del_anchor .= $del_func2_js; $form_del_anchor .= '
'; // $str = substr($str, 0, -1); $str .= $label_arr['edit_anchor'] ? '
' : ''; $str .= $label_arr['del_anchor'] ? '' : ''; $tit_str[] = $str; $date_format = $GLOBALS['date_format'] ? $GLOBALS['date_format'] : 'Y-m-d H:i:s'; $rows = $rs->getRows(); $raw_str = $str.''; for ($i=0;$icurr_page-1)*$this->rows).'|'; $str .= $i+1+(($this->curr_page-1)*$this->rows).''; //for ($j=0;$j<$rs->FieldCount();$j++) { //foreach (${$GLOBALS['session_vars']}[$this->id.'_vselect'] as $key => $value) { for ($j=0;$jFetchField($j); $key = $field_arr[$j]; /*if ($optional_arr[$key]) continue; if (! $value) continue;*/ if ($label_arr['pk'][$key]) { $pk_str .= $key.'='.urlencode($rows[$i][$key]).'&'; $pk_value = $rows[$i][$key]; } if ($optional_arr[$key]) continue; if (! ${$GLOBALS['session_vars']}[$this->id.'_vselect'][$key]) continue; $str .= ''; } // $str = substr($str, 0, -1); $pk_str = substr($pk_str, 0, -1); // $the_anchor = ereg_replace("%k", $rows[$i][$key], $label_arr['edit_anchor']); $the_anchor = ereg_replace("%k", $pk_value, $label_arr['edit_anchor']); $the_anchor = ereg_replace("%s", '&'.$pk_str, $the_anchor); $str .= $label_arr['edit_anchor'] ? '' : ''; if ($eval_arr['edit_anchor']) { eval(preg_replace('/\%s/', $pk_str, $eval_arr['edit_anchor'])); } //$str .= $label_arr['del_anchor'] ? '|'.sprintf($label_arr['del_anchor'], '&' . $pk_str) : ''; $str .= $label_arr['del_anchor'] ? '' : ''; //if (($i+1)==count($rows) && $label_arr['del_anchor']) $str .= ''; if ($eval_arr['del_anchor']) { eval(preg_replace('/\%s/', $pk_str, $eval_arr['del_anchor'])); } $arr_str[] = $str; $raw_str .= $str.''; } unset($rows); $raw_str .= '
'; $str .= 'No'.'"; $str .= <<< EOT {$pkey_str} id}_orderby={$key}&{$this->id}_orderby_type={$ordtype}&{$this->label_arr['extra_param']} title="Sort by {$fldname}">{$fldname} {$ordimg} {$nkey_str} EOT; // $str .= '|'; $str .= 'Action'.$form_del_anchor.'
'; $date_check = eregi('(date)|(time?)|(^lda$)', $key); if ($rows[$i][$key]!="") { if ($eval_arr[$key]) { $str .= ''; eval(preg_replace('/\%s/', $rows[$i][$key], $eval_arr[$key])); $str .= ''; // } else if ($date_check) { // $str .= ' '.htmlentities(date($date_format,$rows[$i][$key])).''; } else { // $str .= ' '.nl2br(htmlentities($rows[$i][$key])).''; $str .= ' '.nl2br($rows[$i][$key]).''; } } $str .= ' '.$the_anchor.'
'; //($err_msg) ? $_block->set_info($err_msg) : ''; if ($this->excel_save) { $this->view_excel(&$arr_str, &$tit_str); } else if ($this->csv_save) { $this->view_csv(&$arr_str, &$tit_str); } else { // $_outside_block = new block(); // $_block = new block(); // $label_arr['form_title'] ? $_outside_block->set_config('title', $label_arr['form_title']) : ''; // $label_arr['form_width'] ? $_outside_block->set_config('width', $label_arr['form_width']) : ''; // $_block->set_config('num_col', $num_col); // $_block->set_config('width', '100%'); // $_block->set_config('cell_extra', ' valign=top '); // $_block->set_title(&$tit_str); // $_block->parse(&$arr_str); // $_out[] = $this->header_view ? $this->render_nav_search() : ''; // $_out[] = $_block->get_str(); // $_outside_block->parse(&$_out); if ($label_arr['del_anchor']) $extra_block = ""; // return $_outside_block->get_str().$extra_block; return $this->render_nav_search().$raw_str.$extra_block; } } function unhtmlentities ($string) { $trans_tbl = get_html_translation_table (HTML_ENTITIES); $trans_tbl = array_flip ($trans_tbl); return strtr ($string, $trans_tbl); } function view_excel($arr_str, $tit_str) { include 'class.xls.BIFFwriter.inc.php'; include 'class.xls.Format.inc.php'; include 'class.xls.OLEwriter.inc.php'; include 'class.xls.Parser.inc.php'; include 'class.xls.Workbook.inc.php'; include 'class.xls.Worksheet.inc.php'; $filename = 'output.xls'; header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=$filename" ); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); header("Pragma: public"); // Creating a workbook $workbook = new Workbook("-"); // Creating the first worksheet $worksheet1 =& $workbook->addworksheet(); $formatot =& $workbook->addformat(); $formatot->text_wrap = 1; $formatot->set_size(10); $formatot2 =& $workbook->addformat(); $formatot2->set_bold(); $max_width = array(); for ($i=0;$iset_row($i,12); $tit_pie = split("\|", $tit_str[$i]); for ($j=0;$junhtmlentities(strip_tags(trim($tit_pie[$j]))); $worksheet1->write_string($i,$j,$cell,$formatot2); if (strlen($cell)>$max_width[$j]) $max_width[$j] = strlen($cell); } } $start_row = count($tit_str); for ($i=0;$iset_row($i+$start_row,12); $arr_pie = split("\|", $arr_str[$i]); for ($j=0;$junhtmlentities(strip_tags(trim($arr_pie[$j]))); $worksheet1->write_string($i+$start_row,$j,$cell,$formatot); if (strlen($cell)>$max_width[$j]) $max_width[$j] = strlen($cell); } } for ($i=0;$iset_column(1,$i,$max_width[$i]); } $workbook->close(); exit; } function view_csv($arr_str, $tit_str) { $filename = 'output.csv'; header("Content-Disposition: attachment; filename=$filename" ); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); header("Pragma: public"); for ($i=0;$iunhtmlentities(strip_tags(trim($tit_pie[$j]))); $output .= "\"".$cell."\","; } $output = substr($output, 0, -1); echo $output . "\n"; } $start_row = count($tit_str); for ($i=0;$iunhtmlentities(strip_tags(trim($arr_pie[$j]))); $output .= "\"".$cell."\","; } $output = substr($output, 0, -1); echo $output . "\n"; } exit; } function render_nav() { global $PHP_SELF, ${$GLOBALS['session_vars']}; if ($this->curr_page > 1) { $a = $this->render_first().' . '.$this->render_prev(); } else { $a = $this->render_first(false).' . '.$this->render_prev(false); } if ($this->curr_page < $this->rs->LastPageNo()) { $b = ' . '.$this->render_next().' . '.$this->render_last(); } else { $b = ' . '.$this->render_next(false).' . '.$this->render_last(false); } if (!$this->db->pageExecuteCountRows) { $f = ''; } $total = $this->rs->LastPageNo(); $f = '';// multiple size=1>'; reset(${$GLOBALS['session_vars']}[$this->id.'_dselect']); $el = each(${$GLOBALS['session_vars']}[$this->id.'_dselect']); for ($i=0;$ifield_arr);$i++) { if ($el['value']==$this->field_arr[$i]) { $sl = ' selected'; $el = each(${$GLOBALS['session_vars']}[$this->id.'_dselect']); } else { $sl = ''; } if ($this->optional_arr[$this->field_arr[$i]] || ! ereg('date', $this->field_arr[$i])) continue; $field_var = $this->var_arr[$this->field_arr[$i]] ? $this->var_arr[$this->field_arr[$i]] : $this->field_arr[$i]; $d .= ''; $view_date_search = TRUE; } reset(${$GLOBALS['session_vars']}[$this->id.'_dselect']); $d .= ''; $dat_str = 'On '.$d; if ($GLOBALS['calendar_js']) { $GLOBALS['i_need_calendar_js'] = TRUE; $fday = 'id.'_fdate'] ? ${$GLOBALS['session_vars']}[$this->id.'_fdate'] : date("Y-m-d"); $fday .= '\'> '; $tday = 'id.'_tdate'] ? ${$GLOBALS['session_vars']}[$this->id.'_tdate'] : date("Y-m-d"); $tday .= '\'> '; $fday = 'From '.$fday; $tday = 'To '.$tday; if ($view_date_search) $alldat_str = '... '.$fday.' '.$tday.' '.$dat_str.''; } $s = <<< EOT EOT; /* $s = <<< EOT
{$a} . {$b} . {$add_str}
EOT; */ return $s; } function render($rows=15) { global $ADODB_COUNTRECS, ${$GLOBALS['post_vars']}, ${$GLOBALS['session_vars']}, ${$GLOBALS['get_vars']}; ${$GLOBALS['session_vars']}[$this->id.'_per_page'] = (int)${$GLOBALS['post_vars']}[$this->id.'_per_page'] ? (int)${$GLOBALS['post_vars']}[$this->id.'_per_page'] : ((int)${$GLOBALS['get_vars']}[$this->id.'_per_page'] ? (int)${$GLOBALS['get_vars']}[$this->id.'_per_page'] : ( (int)${$GLOBALS['session_vars']}[$this->id.'_per_page'] ? (int)${$GLOBALS['session_vars']}[$this->id.'_per_page'] : $rows )); $rows = ${$GLOBALS['session_vars']}[$this->id.'_per_page']; $this->rows = $rows; $savec = $ADODB_COUNTRECS; if ($this->db->pageExecuteCountRows) { $ADODB_COUNTRECS = true; } $rs = &$this->db->PageExecute($this->sql,1,1); for ($i=0;$i<$rs->FieldCount();$i++) { $fld = $rs->FetchField($i); $field_arr[] = $fld->name; } $this->field_arr = $field_arr; $sql = $this->sql; if (eregi('SELECT .* FROM .* WHERE .*', $sql)) { // echo "in eregi
"; $where_sql = eregi_replace('SELECT .* FROM .* WHERE (.*)', '\\1', $sql); $sql = eregi_replace('(SELECT .* FROM .*) WHERE .*', '\\1', $sql); } // echo "point 1 where_sql: ".$where_sql."
"; // echo "point 1 sql: ".$sql."
"; // exit; ${$GLOBALS['session_vars']}[$this->id.'_fselect'] = ${$GLOBALS['session_vars']}[$this->id.'_fselect'] ? ${$GLOBALS['session_vars']}[$this->id.'_fselect'] : $field_arr; if ($this->do_search == 'qck') { // Set Where to Quick Search $keyword = ${$GLOBALS['session_vars']}[$this->id.'_keyword']; $key_arr = split("[,\t]+",$keyword); $where_str = ''; for ($i=0;$iid.'_fselect']);$i++) { for ($j=0;$jid.'_fselect'][$i] . ' = \'' . $regs[1] . '\''; } else if (ereg('^[A-Za-z]+$', $my_keyword)) { $where_str .= ' '.${$GLOBALS['session_vars']}[$this->id.'_fselect'][$i] . ' LIKE \'%' . $my_keyword . '%\''; } else { $where_str .= ' '.${$GLOBALS['session_vars']}[$this->id.'_fselect'][$i] . ' REGEXP \'' . $my_keyword . '\''; } $where_str .= ' OR'; } } } if ($where_str != '') $where_str = substr($where_str, 0, -2); ${$GLOBALS['session_vars']}[$this->id.'_curr_where_str'] = $where_str; } elseif ($this->do_search == 'adv') { // Set Where to Advanced Search ${$GLOBALS['session_vars']}[$this->id.'_advs_field'] = ${$GLOBALS['post_vars']}[$this->id.'_advs_field']; ${$GLOBALS['session_vars']}[$this->id.'_advs_op'] = ${$GLOBALS['post_vars']}[$this->id.'_advs_op']; ${$GLOBALS['session_vars']}[$this->id.'_advs_val'] = ${$GLOBALS['post_vars']}[$this->id.'_advs_val']; ${$GLOBALS['session_vars']}[$this->id.'_advs_andor'] = ${$GLOBALS['post_vars']}[$this->id.'_advs_andor']; $where_str = ''; // echo "initial count of advs_field is: ".count(${$GLOBALS['session_vars']}[$this->id.'_advs_field']); for ($i=0; $i < count(${$GLOBALS['session_vars']}[$this->id.'_advs_field']); $i++) { if (${$GLOBALS['session_vars']}[$this->id.'_advs_val'][$i] == '') { unset(${$GLOBALS['session_vars']}[$this->id.'_advs_field'][$i]); unset(${$GLOBALS['session_vars']}[$this->id.'_advs_op'][$i]); unset(${$GLOBALS['session_vars']}[$this->id.'_advs_val'][$i]); unset(${$GLOBALS['session_vars']}[$this->id.'_advs_andor'][$i]); } } // echo "count of advs_field is: ".count(${$GLOBALS['session_vars']}[$this->id.'_advs_field']); for ($i=0; $i < count(${$GLOBALS['session_vars']}[$this->id.'_advs_field']); $i++) { $my_keyword = addslashes(${$GLOBALS['session_vars']}[$this->id.'_advs_val'][$i]); if ($where_str != '') $where_str .= ' '.$andor.' '; // $my_keyword = (${$GLOBALS['session_vars']}[$this->id.'_advs_op'][$i] == 'LIKE') ? '%'.$my_keyword.'%' : $my_keyword; if (${$GLOBALS['session_vars']}[$this->id.'_advs_op'][$i] == 'NULL') { $where_str .= ' (('.${$GLOBALS['session_vars']}[$this->id.'_advs_field'][$i].' IS NULL) OR ('.${$GLOBALS['session_vars']}[$this->id.'_advs_field'][$i].' = \'\')) '; } else { $where_str .= ' '.${$GLOBALS['session_vars']}[$this->id.'_advs_field'][$i].' '.${$GLOBALS['session_vars']}[$this->id.'_advs_op'][$i].' '.'\'' . $my_keyword . '\' '; } $andor = ${$GLOBALS['session_vars']}[$this->id.'_advs_andor'][$i]; } ${$GLOBALS['session_vars']}[$this->id.'_curr_where_str'] = $where_str; } elseif ($this->do_search == 'add') { // Add a row in Advanced Search ${$GLOBALS['session_vars']}[$this->id.'_advs_field'] = ${$GLOBALS['post_vars']}[$this->id.'_advs_field']; ${$GLOBALS['session_vars']}[$this->id.'_advs_op'] = ${$GLOBALS['post_vars']}[$this->id.'_advs_op']; ${$GLOBALS['session_vars']}[$this->id.'_advs_val'] = ${$GLOBALS['post_vars']}[$this->id.'_advs_val']; ${$GLOBALS['session_vars']}[$this->id.'_advs_andor'] = ${$GLOBALS['post_vars']}[$this->id.'_advs_andor']; for ($i=0; $i < count(${$GLOBALS['session_vars']}[$this->id.'_advs_field']); $i++) { if (${$GLOBALS['session_vars']}[$this->id.'_advs_val'][$i] == '') { unset(${$GLOBALS['session_vars']}[$this->id.'_advs_field'][$i]); unset(${$GLOBALS['session_vars']}[$this->id.'_advs_op'][$i]); unset(${$GLOBALS['session_vars']}[$this->id.'_advs_val'][$i]); unset(${$GLOBALS['session_vars']}[$this->id.'_advs_andor'][$i]); } } } $where_str = ${$GLOBALS['session_vars']}[$this->id.'_curr_where_str']; ${$GLOBALS['session_vars']}[$this->id.'_dselect'] = ${$GLOBALS['session_vars']}[$this->id.'_dselect'] ? ${$GLOBALS['session_vars']}[$this->id.'_dselect'] : array(); $fdate = $this->parsedate(${$GLOBALS['session_vars']}[$this->id.'_fdate']); $tdate = $this->parsedate(${$GLOBALS['session_vars']}[$this->id.'_tdate']); if ($tdate) { $tdate += 86400; } if ($fdate && $tdate) { $where2_str = ''; for ($i=0;$iid.'_dselect']);$i++) { $where2_str .= ' ('; $where2_str .= ${$GLOBALS['session_vars']}[$this->id.'_dselect'][$i] . ' >= ' . $fdate; $where2_str .= ' AND '; $where2_str .= ${$GLOBALS['session_vars']}[$this->id.'_dselect'][$i] . ' < ' . $tdate; $where2_str .= ' )'; $where2_str .= ' OR'; } } if ($where_str) { if ($where_sql) { // $where_str = ' WHERE'.' ('.substr($where_str, 0, -2).') AND ('.$where_sql.')'; $where_str = ' WHERE'.' ('.$where_str.') AND ('.$where_sql.')'; } else { // $where_str = ' WHERE'.substr($where_str, 0, -2); $where_str = ' WHERE'.$where_str; } } else { if ($where_sql) { $where_str = ' WHERE'.' '.$where_sql.' '; } } if ($where2_str) { if ($where_str) { $where_str = $where_str.' AND ('.substr($where2_str, 0, -2).')'; } else { $where_str = ' WHERE'.substr($where2_str, 0, -2); } } $sql .= $where_str.$this->orderby_sql; // echo $sql.'
'.$where_sql; // exit; if ($this->cache) { $rs = &$this->db->CachePageExecute($this->cache,$sql,$rows,$this->curr_page); } else { $rs = &$this->db->PageExecute($sql,$rows,$this->curr_page); } if (! $rs) { $rs = &$this->db->PageExecute($this->sql." WHERE 0",$rows,$this->curr_page); } $ADODB_COUNTRECS = $savec; $this->rs = &$rs; if (!$rs) { $err_msg = "

Query failed: $this->sql

"; return; } $this->curr_page = $this->rs->_currentPage; ${$GLOBALS['session_vars']}[$this->id.'_curr_page'] = $this->curr_page; //if (!$rs->EOF && (!$rs->AtFirstPage() || !$rs->AtLastPage())) { // $header = $this->render_nav(); //} else { // $header = " "; //} $s = $this->render_grid(); //$footer = $this->render_page_count(); //$header = $this->render_nav_search(); $rs->close(); $this->rs = false; return $s; //$this->render_layout($header,$grid,$footer); } function render_nav_search() { global $PHP_SELF, ${$GLOBALS['session_vars']}; $nav = $this->render_nav(); // Build Advanced Search HTML $adv_display = ($this->do_search == 'add') ? 'inline' : 'none'; $tot_fields = count(${$GLOBALS['session_vars']}[$this->id.'_advs_field']); $adv = ''; for ($floop = 0; $floop < ($tot_fields + 1); $floop++) { $adv .= 'Field: '; $adv .= 'Comparision: '; $adv .= 'Value: id.'_advs_val'][$floop]).'"'; $adv .= '>'; $adv .= ''; } // Sort field listing $sort = ''; // Quick Search field select $f = ''; $b = ''; for ($i=0;$ifield_arr);$i++) { if ($this->optional_arr[$this->field_arr[$i]]) continue; if (${$GLOBALS['session_vars']}[$this->id.'_vselect'][$this->field_arr[$i]]==TRUE) { $c .= ''; } else { $b .= '