--- ../phpMyEdit.class.-current-1.166.php	Fri Mar 25 10:25:43 2005
+++ buttons-v7-166.php	Tue Mar 29 23:24:54 2005
@@ -167,6 +167,15 @@
 			'P' => 'copy',
 			'D' => 'delete'
 			);
+	var $default_buttons = array(
+			'L' => array('<<','<','add','view','change','copy','delete','>','>>','goto','goto_combo'),
+			'F' => array('<<','<','add','view','change','copy','delete','>','>>','goto','goto_combo'),
+			'A' => array('save','more','cancel'),
+			'C' => array('save','more','cancel'),
+			'P' => array('save', 'cancel'),
+			'D' => array('save','cancel'),
+			'V' => array('change','cancel')
+			);
 	// }}}
 
 	/*
@@ -190,8 +199,8 @@
 	function nav_buttons()       { return stristr($this->navigation, 'B'); }
 	function nav_text_links()    { return stristr($this->navigation, 'T'); }
 	function nav_graphic_links() { return stristr($this->navigation, 'G'); }
-	function nav_up()            { return stristr($this->navigation, 'U'); }
-	function nav_down()          { return stristr($this->navigation, 'D'); }
+	function nav_up()            { return (stristr($this->navigation, 'U') && !($this->buttons[$this->page_type]['up'] === false)); }
+	function nav_down()          { return (stristr($this->navigation, 'D') && !($this->buttons[$this->page_type]['down'] === false)); }
 
 	/*
 	 * functions for indicating whether operations are enabled
@@ -218,10 +227,10 @@
 	function list_operation()   { /* covers also filtering page */ return ! $this->change_operation()
 										&& ! $this->add_operation()    && ! $this->copy_operation()
 										&& ! $this->delete_operation() && ! $this->view_operation(); }
-	function next_operation()	{ return $this->navop == $this->labels['Next']; }
-	function prev_operation()	{ return $this->navop == $this->labels['Prev']; }
-	function first_operation()	{ return $this->navop == $this->labels['First']; }
-	function last_operation()	{ return $this->navop == $this->labels['Last']; }
+	function next_operation()	{ return ($this->navop == $this->labels['Next']) || ($this->navop == '>'); }
+	function prev_operation()	{ return ($this->navop == $this->labels['Prev']) || ($this->navop == '<'); }
+	function first_operation()	{ return ($this->navop == $this->labels['First']) || ($this->navop == '<<'); }
+	function last_operation()	{ return ($this->navop == $this->labels['Last']) || ($this->navop == '>>'); }
 	function goto_operation()	{ return $this->navop == $this->labels['Go to']; }
 	function clear_operation()	{ return $this->sw == $this->labels['Clear'];  }
 
@@ -1331,8 +1340,9 @@
 	 * @param	css_class_name	CSS class name
 	 * @param	js_validation	if add JavaScript validation subroutine to button
 	 * @param	disabled		if mark the button as disabled
+	 * @param	js		any extra text in tags
 	 */
-	function htmlSubmit($name, $label, $css_class_name, $js_validation = true, $disabled = false) /* {{{ */
+	function htmlSubmit($name, $label, $css_class_name, $js_validation = true, $disabled = false, $js = NULL) /* {{{ */
 	{
 		// Note that <input disabled> isn't valid HTML, but most browsers support it
 		$markdisabled = $disabled ? ' disabled' : '';
@@ -1342,7 +1352,9 @@
 		if ($js_validation) {
 			$ret .= '" onClick="return '.$this->js['prefix'].'form_control(this.form);';
 		}
-		$ret .= '" />';
+		$ret .='"';
+		if(isset($js)) $ret .= ' '.$js;
+		$ret .= '>';
 		return $ret;
 	} /* }}} */
 
@@ -1667,68 +1679,36 @@
 	/*
 	 * Display buttons at top and bottom of page
 	 */
-	function display_list_table_buttons($total_recs, $position) /* {{{ */
+	function display_list_table_buttons($position) /* {{{ */
 	{
+		if (($but_str = $this->display_buttons($position)) === null)
+			return;
+		if($position == 'down') echo '<hr class="'.$this->getCSSclass('hr', 'down').'">'."\n";
 		echo '<table class="',$this->getCSSclass('navigation', $position),'">',"\n";
 		echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n";
 		echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n";
-		$listall      = $this->inc <= 0; // Are we doing a listall?
-		$disabledprev = !($this->fm > 0 && !$listall);
-		$disablednext = !($this->fm + $this->inc < $total_recs && ! $listall);
-		$disabledgoto = !($listall || ($disablednext && $disabledprev)) ? '' : ' disabled';
-		if (!$listall) {
-			$current_page = intval($this->fm / $this->inc) + 1;
-			$total_pages  = max(1, ceil($total_recs / abs($this->inc)));
-		}
-		if (!$listall) {
-			echo $this->htmlSubmit('navop', 'First', $this->getCSSclass('first', $position), false, $disabledprev), '&nbsp;';
-			echo $this->htmlSubmit('navop', 'Prev', $this->getCSSclass('prev', $position), false, $disabledprev), '&nbsp;';
-		}
-		if ($this->add_enabled()) {
-			echo $this->htmlSubmit('operation', 'Add', $this->getCSSclass('add', $position), false, false), '&nbsp;';
-		}
-		if ($this->nav_buttons()) {
-			if ($this->view_enabled()) {
-				echo $this->htmlSubmit('operation', 'View', $this->getCSSclass('view', $position), false, !$total_recs), '&nbsp;';
-			}
-			if ($this->change_enabled()) {
-				echo $this->htmlSubmit('operation', 'Change', $this->getCSSclass('change', $position), false, !$total_recs), '&nbsp;';
-			}
-			if ($this->copy_enabled()) {
-				echo $this->htmlSubmit('operation', 'Copy', $this->getCSSclass('copy', $position), false, !$total_recs), '&nbsp;';
-			}
-			if ($this->delete_enabled()) {
-				echo $this->htmlSubmit('operation', 'Delete', $this->getCSSclass('delete', $position), false, !$total_recs), '&nbsp;';
-			}
-		}
-		if (!$listall) { //nav buttons are not displayed if explicit listall
-			echo $this->htmlSubmit('navop', 'Next', $this->getCSSclass('next', $position), false, $disablednext), '&nbsp;';
-			echo $this->htmlSubmit('navop', 'Last', $this->getCSSclass('last', $position), false, $disablednext), '&nbsp;';
-			echo $this->htmlSubmit('navop', 'Go to', $this->getCSSclass('goto', $position), false,
-				($listall || ($disablednext && $disabledprev)));
-			echo '<select',$disabledgoto,' class="',$this->getCSSclass('goto', $position);
-			echo '" name="',$this->cgi['prefix']['sys'].ltrim($disabledgoto).'navfm',$position,'" onChange="return this.form.submit();">',"\n";
-			for ($i = 0; $i < $total_pages; $i++) {
-				echo '<option',($this->fm == $this->inc * $i) ? ' selected' : '';
-				echo ' value="',$this->inc * $i,'">',$i + 1,'</option>',"\n";
-			}
-			echo '</select>';
-		}
-		echo '</td>',"\n";
+		echo $but_str,'</td>',"\n";
 		// Message is now written here
 		if (strlen(@$this->message) > 0) {
 			echo '<td class="',$this->getCSSclass('message', $position),'">',$this->message,'</td>',"\n";
 		}
-		// Display page and records statistics
-		echo '<td class="',$this->getCSSclass('stats', $position),'">',"\n";
-		if ($listall) {
-			echo $this->labels['Page'],':&nbsp;1&nbsp;',$this->labels['of'],'&nbsp;1';
-		} else {
-			echo $this->labels['Page'],':&nbsp;',$current_page;
-			echo '&nbsp;',$this->labels['of'],'&nbsp;',$total_pages;
-		}
-		echo '&nbsp; ',$this->labels['Records'],':&nbsp;',$total_recs;
-		echo '</td></tr></table>',"\n";
+		if($this->display['num_pages'] || $this->display['num_records'])
+			echo '<td class="',$this->getCSSclass('stats', $position),'">',"\n";
+		if($this->display['num_pages']) {
+			if ($listall) {
+				echo $this->labels['Page'],':&nbsp;1&nbsp;',$this->labels['of'],'&nbsp;1';
+			} else {
+	 			$current_page = intval($this->fm / $this->inc) + 1;
+				$total_pages  = max(1, ceil($this->total_recs / abs($this->inc)));
+				echo $this->labels['Page'],':&nbsp;',$current_page;
+				echo '&nbsp;',$this->labels['of'],'&nbsp;',$total_pages;
+			}
+			}
+		if($this->display['num_records'])
+			echo '&nbsp; ',$this->labels['Records'],':&nbsp;',$this->total_recs;
+		if($this->display['num_pages'] || $this->display['num_records']) echo '</td>';
+		echo '</tr></table>',"\n";
+		if($position == 'up') echo '<hr class="'.$this->getCSSclass('hr', 'up').'">'."\n";
 	} /* }}} */
 
 	/*
@@ -1736,37 +1716,139 @@
 	 */
 	function display_record_buttons($position) /* {{{ */
 	{
+		if (($but_str = $this->display_buttons($position)) === null)
+			return;
+		if ($position == 'down') {
+			if ($this->tabs_enabled()) $this->display_tab_labels('down');
+			echo '<hr class="',$this->getCSSclass('hr', 'down'),'">',"\n";
+		}
 		echo '<table class="',$this->getCSSclass('navigation', $position),'">',"\n";
 		echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n";
 		echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n";
-		if ($this->change_operation()) {
-			echo $this->htmlSubmit('savechange', 'Save', $this->getCSSclass('save', $position), true), '&nbsp;';
-			echo $this->htmlSubmit('morechange', 'Apply', $this->getCSSclass('more', $position), true), '&nbsp;';
-			echo $this->htmlSubmit('cancelchange', 'Cancel', $this->getCSSclass('cancel', $position), false);
-		} elseif ($this->add_operation()) {
-			echo $this->htmlSubmit('saveadd', 'Save', $this->getCSSclass('save', $position), true), '&nbsp;';
-			echo $this->htmlSubmit('moreadd', 'More', $this->getCSSclass('more', $position), true), '&nbsp;';
-			echo $this->htmlSubmit('canceladd', 'Cancel', $this->getCSSclass('cancel', $position), false);
-		} elseif ($this->copy_operation()) {
-			echo $this->htmlSubmit('savecopy', 'Save', $this->getCSSclass('save', $position), true), '&nbsp;';
-			echo $this->htmlSubmit('cancelcopy', 'Cancel', $this->getCSSclass('cancel', $position), false);
-		} elseif ($this->delete_operation()) {
-			echo $this->htmlSubmit('savedelete', 'Delete', $this->getCSSclass('save', $position), false), '&nbsp;';
-			echo $this->htmlSubmit('canceldelete', 'Cancel', $this->getCSSclass('cancel', $position), false);
-		} elseif ($this->view_operation()) {
-			if ($this->change_enabled()) {
-				echo $this->htmlSubmit('operation', 'Change', $this->getCSSclass('save', $position), false), '&nbsp;';
-			}
-			echo $this->htmlSubmit('cancelview', 'Cancel', $this->getCSSclass('cancel', $position), false);
-		}
+		echo $but_str,'</td>',"\n";
 		// Message is now written here
 		echo '</td>',"\n";
 		if (strlen(@$this->message) > 0) {
 			echo '<td class="',$this->getCSSclass('message', $position),'">',$this->message,'</td>',"\n";
 		}
+		if ($position == 'up') {
+			if ($this->tabs_enabled()) $this->display_tab_labels('up');
+			echo '<hr class="',$this->getCSSclass('hr', 'up'),'">',"\n";
+		}
 		echo '</tr></table>',"\n";
 	} /* }}} */
 
+	function display_buttons($position) /* {{{ */
+	{
+		$nav_fnc = 'nav_'.$position;
+		if(! $this->$nav_fnc())
+			return;
+		$buttons = (is_array($this->buttons[$this->page_type][$position]))
+			? $this->buttons[$this->page_type][$position]
+			: $buttons = $this->default_buttons[$this->page_type];
+		foreach ($buttons as $name) {
+			$ret .= $this->display_button($name, $position)."\n";
+		}
+		return $ret;
+	} /* }}} */
+
+	function display_button($name, $position = 'up') /* {{{ */
+	{
+		if (is_array($name)) {
+			if (isset($name['code'])) return $name['code'];
+			return $this->htmlSubmit($name['name'], $name['value'], $name['css'], $name['disabled'], $name['js']);
+		}
+		$disabled = 1; // show disabled by default
+		if ($name[0] == '+') { $name = substr($name, 1); $disabled =  0; } // always show disabled as enabled
+		if ($name[0] == '-') { $name = substr($name, 1); $disabled = -1; } // don't show disabled
+		if ($name == 'cancel') {
+			return $this->htmlSubmit('cancel'.$this->page_types[$this->page_type], 'Cancel',
+					$this->getCSSclass('cancel', $position), false);
+		}
+		if (in_array($name, array('add','view','change','copy','delete'))) {
+			$enabled_fnc = $name.'_enabled';
+			$enabled     = $this->$enabled_fnc();
+			if ($name != 'add' && ! $this->total_recs && strstr('LF', $this->page_type))
+				$enabled = false;
+			return $this->htmlSubmit('operation', ucfirst($name),
+					$this->getCSSclass($name, $position), false, $enabled ? 0 : $disabled);
+		}
+		if ($name == 'savedelete') {
+			$enabled     = $this->delete_enabled();
+			$js = 'onClick="return confirm(\''.$this->labels['Delete'].' ?\');"';
+			return $this->htmlSubmit('savedelete', 'Delete',
+					$this->getCSSclass('save', $position), false, $enabled ? 0 : $disabled, $js);
+		}
+		if (in_array($name, array('save','more'))) {
+			$validation = true; // if js validation
+			if     ($this->page_type == 'D' && $name == 'save' ) { $value = 'Delete'; $validation = false; }
+			elseif ($this->page_type == 'C' && $name == 'more' ) { $value = 'Apply'; }
+			else $value = ucfirst($name);
+			return $this->htmlSubmit($name.$this->page_types[$this->page_type], $value,
+					$this->getCSSclass($name, $position), $validation);
+		}
+		$listall      = $this->inc <= 0; // Are we doing a listall?
+		$disabledprev = !($this->fm > 0 && !$listall);
+		$disabledfirst = $disabledprev;
+		$disablednext = !($this->fm + $this->inc < $this->total_recs && ! $listall);
+		$disabledlast = $disablednext;
+		$total_pages  = max(1, ceil($this->total_recs / abs($this->inc)));
+		$current_page = ceil($this->fm / abs($this->inc)); // must + 1
+		// some statistics first
+		if ($name == 'total_pages') return $total_pages;
+		if ($name == 'current_page') return ($current_page+1);
+		if ($name == 'total_recs') return ($this->total_recs);
+		// now some goto buttons/dropdowns/inputs...
+		if ($name == 'goto_text') {
+			$ret = '<input type="text" class="'.$this->getCSSclass('gotopn', $position).'"';
+			$ret .= ' name="navpn'.$position.'" value="'.($current_page+1).'"';
+			$ret .= ' size="'.(strlen($total_pages)+1).'" maxlength="'.(strlen($total_pages)+1).'"';
+			// TODO some js here.... on enter submit, on click erase ?...
+			$ret .='>';
+			return $ret;
+		}
+		if ($name == 'goto_combo') {
+			$disabledgoto = !($listall || ($disablednext && $disabledprev)) ? '' : ' disabled';
+			if ($disablegoto != '' && $disabled < 0) return;
+			$ret = '<select'.$disabledgoto.' class="'.$this->getCSSclass('goto', $position);
+			$ret .= '" name="'.ltrim($disabledgoto).'navfm'.$position.'" onChange="return this.form.submit();">'."\n";
+			for ($i = 0; $i < $total_pages; $i++) {
+				$ret .= "\t".'<option';
+				$ret .= ($current_page == $i) ? ' selected' : '';
+				$ret .= ' value="'.$this->inc * $i.'">'.($i + 1).'</option>'."\n";
+			}
+			$ret .= '</select>';
+			return $ret;
+		}
+		if ($name == 'goto') {
+			return $this->htmlSubmit('navop', 'Go to', $this->getCSSclass('goto', $position),
+					false, ($listall || ($disablednext && $disabledprev)) ? $disabled : 0);
+		}
+		if (in_array($name, array('first','prev','next','last','<<','<','>','>>'))) {
+			$disabled_var = 'disabled'.$name;
+			if (strlen($name) <= 2) {
+				$nav_values = array('<<' => 'first', '<' => 'prev', '>' => 'next', '>>' => 'last');
+				$disabled_var = 'disabled'.$nav_values[$name];
+			}
+			return $this->htmlSubmit('navop', ucfirst($name),
+					$this->getCSSclass($name, $position), false, $$disabled_var ? $disabled : 0);
+		}
+		if(isset($this->labels[$name])) return $this->labels[$name];
+		return $name;
+	} /* }}} */
+
+	function number_of_recs() /* {{{ */
+	{
+		$count_parts = array(
+				'type'   => 'select',
+				'select' => 'count(*)',
+				'from'   => $this->get_SQL_join_clause(),
+				'where'  => $this->get_SQL_where_from_query_opts());
+		$res = $this->myquery($this->get_SQL_query($count_parts), __LINE__);
+		$row = @mysql_fetch_array($res, MYSQL_NUM);
+		$this->total_recs = $row[0];
+	} /* }}} */
+
 	/*
 	 * Table Page Listing
 	 */
@@ -1790,6 +1872,10 @@
 		if ($this->goto_operation()) {
 			$this->fm = $this->navfm;
 		}
+		$this->number_of_recs();
+		if ($this->last_operation() || $this->fm > $this->total_recs) { // if goto_text is badly set
+			$this->fm = (int)(($this->total_recs - 1)/$this->inc)*$this->inc;
+		}
 		// If sort sequence has changed, restart listing
 		$this->qfn != $this->prev_qfn && $this->fm = 0;
 		if (0) { // DEBUG
@@ -1814,23 +1900,7 @@
 		echo $this->get_origvars_html($this->get_sfn_cgi_vars());
 		echo $this->htmlHiddenSys('fl', $this->fl);
 		// Display buttons at top and/or bottom of page.
-		// Setup query to get num_rows. (sparky)
-		$total_recs  = 0;
-		$count_parts = array(
-				'type'   => 'select',
-				'select' => 'count(*)',
-				'from'   => $this->get_SQL_join_clause(),
-				'where'  => $this->get_SQL_where_from_query_opts());
-		$res = $this->myquery($this->get_SQL_query($count_parts), __LINE__);
-		$row = @mysql_fetch_array($res, MYSQL_NUM);
-		$total_recs = $row[0];
-		if ($this->last_operation()) {
-			$this->fm = (int)(($total_recs-1)/$this->inc)*$this->inc;
-		}
-		if ($this->nav_up()) {
-			$this->display_list_table_buttons($total_recs, 'up');
-			echo '<hr class="',$this->getCSSclass('hr', 'up'),'">',"\n";
-		}
+		$this->display_list_table_buttons('up');
 		if ($this->cgi['persist'] != '') {
 			echo $this->get_origvars_html($this->cgi['persist']);
 		}
@@ -2264,10 +2334,7 @@
 			echo '</tr>',"\n";
 		}
 		echo '</table>',"\n"; // end of table rows listing
-		if ($this->nav_down()) {
-			echo '<hr class="',$this->getCSSclass('hr', 'down'),'">',"\n";
-			$this->display_list_table_buttons($total_recs, 'down');
-		}
+		$this->display_list_table_buttons('down');
 		$this->form_end();
 	} /* }}} */
 
@@ -2309,13 +2376,7 @@
 		echo $this->htmlHiddenSys('rec', $this->copy_operation() ? '' : $this->rec);
 		echo $this->htmlHiddenSys('fm', $this->fm);
 		echo $this->htmlHiddenSys('fl', $this->fl);
-		if ($this->nav_up()) {
-			$this->display_record_buttons('up');
-			echo '<hr class="',$this->getCSSclass('hr', 'up'),'">',"\n";
-			if ($this->tabs_enabled()) {
-				$this->display_tab_labels('up');
-			}
-		}
+		$this->display_record_buttons('up');
 		if ($this->tabs_enabled()) {
 			echo '<div id="'.$this->dhtml['prefix'].'tab0">',"\n";
 		}
@@ -2327,13 +2388,9 @@
 		}
 		echo '</table>',"\n";
 		echo '</div>',"\n";
-		if ($this->nav_down()) {
-			if ($this->tabs_enabled()) {
-				$this->display_tab_labels('down');
-			}
-			echo '<hr class="',$this->getCSSclass('hr', 'down'),'">',"\n";
-			$this->display_record_buttons('down');
-		}
+		
+		$this->display_record_buttons('down');
+
 		$this->form_end();
 	} /* }}} */
 
@@ -3014,6 +3071,10 @@
 			? $opts['display']['tabs'] : true;
 		$this->display['form'] = isset($opts['display']['form'])
 			? $opts['display']['form'] : true;
+		$this->display['num_records'] = isset($opts['display']['num_records'])
+			? $opts['display']['num_records'] : true;
+		$this->display['num_pages'] = isset($opts['display']['num_pages'])
+			? $opts['display']['num_pages'] : true;
 		// Creating directory variables
 		$this->dir['root'] = dirname(realpath(__FILE__))
 			. (strlen(dirname(realpath(__FILE__))) > 0 ? '/' : '');
@@ -3043,6 +3104,7 @@
 		if (! $this->nav_up() && ! $this->nav_down()) {
 			$this->navigation .= 'D'; // down position is default
 		}
+		$this->buttons = $opts['buttons'];
 		// Language labels (must go after navigation)
 		$this->labels = $this->make_language_labels(isset($opts['language'])
 				? $opts['language'] : $this->get_server_var('HTTP_ACCEPT_LANGUAGE'));
@@ -3076,16 +3138,23 @@
 		// Form variables all around
 		$this->fl    = intval($this->get_sys_cgi_var('fl'));
 		$this->fm    = intval($this->get_sys_cgi_var('fm'));
+//		$old_page = ceil($this->fm / abs($this->inc)) + 1;
 		$this->qfn   = $this->get_sys_cgi_var('qfn');
 		$this->sw    = $this->get_sys_cgi_var('sw');
 		$this->rec   = $this->get_sys_cgi_var('rec', '');
 		$this->navop = $this->get_sys_cgi_var('navop');
-		if (($this->navfm = $this->get_sys_cgi_var('navfmup', $this->fm)) != $this->fm) {
+/*		if (($this->navfm = $this->get_sys_cgi_var('navfmup', $this->fm)) != $this->fm) {
+			$this->navop = $this->labels['Go to'];
+		} elseif (($this->navfm = $this->get_sys_cgi_var('navfmdown', $this->navfm)) != $this->fm) {
+			$this->navop = $this->labels['Go to'];
+		} elseif (($this->navfm = $this->get_sys_cgi_var('navfmdown', $this->navfm)) != $this->fm) {
 			$this->navop = $this->labels['Go to'];
-		} else if (($this->navfm = $this->get_sys_cgi_var('navfmdown', $this->navfm)) != $this->fm) {
+		} elseif ($this->get_sys_cgi_var('navpnup')>0 && ($this->navfm = (ceil($this->get_sys_cgi_var('navpnup', $old_page))-1)*$this->inc) != $this->fm) {
 			$this->navop = $this->labels['Go to'];
+		} elseif ($this->get_sys_cgi_var('navpndown')>0 && ($this->navfm = (ceil($this->get_sys_cgi_var('navpndown', $old_page))-1)*$this->inc) != $this->fm) {
+		$this->navop = $this->labels['Go to'];
 		}
-		$this->operation = $this->get_sys_cgi_var('operation');
+*/		$this->operation = $this->get_sys_cgi_var('operation');
 		$oper_prefix_len = strlen($this->cgi['prefix']['operation']);
 		if (! strncmp($this->cgi['prefix']['operation'], $this->operation, $oper_prefix_len)) {
 			$this->operation = $this->labels[substr($this->operation, $oper_prefix_len)];
