--- phpMyEdit.class.-current-1.130.php	Tue Apr  6 13:11:32 2004
+++ phpMyEdit.class.-buttons-v2-1.130.php	Sun Apr 18 23:44:40 2004
@@ -210,10 +210,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'];  }
 
@@ -1288,10 +1288,11 @@
 	 * @param	js_validation	if add JavaScript validation subroutine to button
 	 * @param	disabled		if mark the button as disabled
 	 */
-	function htmlSubmit($name, $label, $css_class_name, $js_validation = true, $disabled = false) /* {{{ */
+	function htmlSubmit($name, $label, $css_class_name, $js_validation = true, $disabled = false, $order_disabled = 0) /* {{{ */
 	{
+		if($disabled && $order_disabled <= -1) return;
 		// Note that <input disabled> isn't valid HTML, but most browsers support it
-		$markdisabled = $disabled ? ' disabled' : '';
+		$markdisabled = ($disabled && ($order_disabled != 1)) ? ' disabled' : '';
 		$ret = '<input'.$markdisabled.' type="submit" class="'.$css_class_name
 			.'" name="'.ltrim($markdisabled).$name
 			.'" value="'.(isset($this->labels[$label]) ? $this->labels[$label] : $label);
@@ -1585,53 +1586,15 @@
 	/*
 	 * Display buttons at top and bottom of page
 	 */
-	function display_list_table_buttons($total_recs, $position) /* {{{ */
+	 function display_list_table_buttons($position) /* {{{ */
 	{
+		$buttons = $this->display_buttons($position);
+		if ($buttons == 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="',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 $buttons;
 		echo '</td>',"\n";
 		// Message is now written here
 		if (strlen(@$this->message) > 0) {
@@ -1642,49 +1605,148 @@
 		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($total_recs / abs($this->inc)));
 			echo $this->labels['Page'],':&nbsp;',$current_page;
 			echo '&nbsp;',$this->labels['of'],'&nbsp;',$total_pages;
 		}
-		echo '&nbsp; ',$this->labels['Records'],':&nbsp;',$total_recs;
+		echo '&nbsp; ',$this->labels['Records'],':&nbsp;',$this->total_recs;
 		echo '</td></tr></table>',"\n";
+		//echo '</tr></table>',"\n";
+		if($position == 'up') echo '<hr class="'.$this->getCSSclass('hr', 'up').'">'."\n";
 	} /* }}} */
 
 	/*
 	 * Display buttons at top and bottom of page
 	 */
+
 	function display_record_buttons($position) /* {{{ */
 	{
+		$buttons = $this->display_buttons($position);
+		if($posision == '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('saveadd', 'Save', $this->getCSSclass('save', $position), true), '&nbsp;';
-			echo $this->htmlSubmit('canceladd', 'Cancel', $this->getCSSclass('cancel', $position), false);
-		} elseif ($this->delete_operation()) {
-			echo $this->htmlSubmit('savedelete', 'Delete', $this->getCSSclass('save', $position), true), '&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), true), '&nbsp;';
-			}
-			echo $this->htmlSubmit('cancelview', 'Cancel', $this->getCSSclass('cancel', $position), false);
-		}
-		// Message is now written here
+		echo $buttons;
 		echo '</td>',"\n";
 		if (strlen(@$this->message) > 0) {
 			echo '<td class="',$this->getCSSclass('message', $position),'">',$this->message,'</td>',"\n";
 		}
 		echo '</tr></table>',"\n";
+		if($posision == 'up') {
+			if ($this->tabs_enabled()) $this->display_tab_labels('up');
+			echo '<hr class="',$this->getCSSclass('hr', 'up'),'">',"\n";
+			if ($this->tabs_enabled()) echo '<div id="phpMyEdit_tab0">',"\n";
+			}
 	} /* }}} */
 
+	function display_button($name, $up='up') /* {{{ */
+	{
+		if(is_array($name)) {
+			if($name['code'] != '') return $name['code']."\n";
+			if($name['name'] == '' ) return NULL;
+			return htmlSubmit($name['name'], $name['value'], $name['css'], $name['disabled']);
+			}
+		$order = 0; // show disabled by default
+		if($name[0] == '+') { $name = substr($name, 1); $order = 1;} // always show disabled
+		if($name[0] == '-') { $name = substr($name, 1); $order = -1;} // don't show disabled
+		if($name == 'cancel') {
+			return $this->htmlSubmit('cancel'.$this->page_types[$this->page_type], 'Cancel', $this->getCSSclass('cancel', $up), false,0,1)."\n";
+			}
+		$total_recs = $this->total_recs;
+		if(in_array($name, array('add','view','change','copy','delete'))) {
+			$enabled = $name.'_enabled';
+			$dis = !($this->$enabled()); if($name != 'add' && !$total_recs) $dis = true;
+			return $this->htmlSubmit('operation', ucfirst($name), $this->getCSSclass($name, $up), false, $dis,$order)."\n"; // total_recs
+			}
+		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, $up), $validation, false, $order)."\n";
+			}
+		$listall      = $this->inc <= 0; // Are we doing a listall?
+		$disabledprev = !($this->fm > 0 && !$listall);
+		$disabledfirst = $disabledprev;
+		$disablednext = !($this->fm + $this->inc < $total_recs && ! $listall);
+		$disabledlast = $disablednext;
+		$total_pages  = max(1, ceil($total_recs / abs($this->inc)));
+		if(in_array($name, array('first','prev','next','last'))) {
+			$dis = 'disabled'.$name;
+			return $this->htmlSubmit('navop', ucfirst($name), $this->getCSSclass($name, $up), false, $$dis, $order)."\n";
+			}
+		if(in_array($name, array('<<','<','>','>>'))) {
+			$nav_values = array ( '<<' => 'first', '<' => 'prev', '>' => 'next', '>>' => 'last');
+			$dis = 'disabled'.$nav_values[$name];
+			return $this->htmlSubmit('navop', $name, $this->getCSSclass($name, $up), false, $$dis, $order)."\n";
+			}
+		if($name == 'drop_down') {
+			$disabledgoto = !($listall || ($disablednext && $disabledprev)) ? '' : ' disabled';
+			if($disablegoto == 'disabled' && $order <= -1 ) return;
+			$ret = '<select'.$disabledgoto.' class="'.$this->getCSSclass('goto', $up);
+			$ret .= '" name="'.ltrim($disabledgoto).'navfm'.$up.'" onChange="return this.form.submit();">'."\n";
+			for ($i = 0; $i < $total_pages; $i++) {
+				$ret .= "\t".'<option';
+				$ret .= ($this->fm == $this->inc * $i) ? ' selected' : '';
+				$ret .= ' value="'.$this->inc * $i.'">'.($i + 1).'</option>'."\n";
+				}
+			$ret .= '</select>'."\n";
+			return $ret;
+			}
+		if($name == 'goto') {
+			return $this->htmlSubmit('navop', 'Go to', $this->getCSSclass('goto', $up), false,
+				($listall || ($disablednext && $disabledprev)), $order)."\n";
+				}
+		return $name."\n";
+	} /* }}} */
+
+	function display_buttons($up) /* {{{ */
+	{
+		$page = $this->page_type;
+		if(is_array($this->display['buttons']))
+			foreach ($this->display['buttons'] as $key => $value) {
+				if(strstr($key, $page) && is_array($this->display['buttons'][$key][$up])) {
+					$buttons = $this->display['buttons'][$key][$up];
+					continue;
+					}
+			}
+		if(!is_array($buttons)) {
+			$nav = 'nav_'.$up;
+			if($this->$nav()) {
+				$def_buttons = array (
+					'L' => array ('first','prev','add','view','change','copy','delete','next','last','goto','drop_down'),
+					'F' => array ('first','prev','add','view','change','copy','delete','next','last','goto','drop_down'),
+					'A' => array ('save','more','cancel'),
+					'C' => array ('save','more','cancel'),
+					'P' => array ('save', 'cancel'),
+					'D' => array ('save','cancel'),
+					'V' => array ('change','cancel')
+					);
+				$buttons = $def_buttons[$this->page_type];
+				}
+				else return NULL; // nothing should be displayed in this part
+			}
+		foreach($buttons as $name) $ret .= $this->display_button($name, $up);
+		return $ret;
+	} /* }}} */
+
+	function number_of_recs() /* {{{ */
+	{
+		// Setup query to get num_rows. (sparky)
+		$count_parts = array(
+				'type'   => 'select',
+				'select' => 'count(*)',
+				'from'   => $this->create_join_clause(),
+				'where'  => $this->make_where_from_query_opts());
+		$res = $this->myquery($this->query_make($count_parts), __LINE__);
+		$row = @mysql_fetch_array($res, MYSQL_NUM);
+		$total_recs = $row[0];
+		$this->total_recs = $total_recs;
+	} /* }}} */
 	/*
 	 * Table Page Listing
 	 */
@@ -1746,22 +1808,12 @@
 		echo '<input type="hidden" name="fl" value="',$this->fl,'">',"\n";
 		// 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->create_join_clause(),
-				'where'  => $this->make_where_from_query_opts());
-		$res = $this->myquery($this->query_make($count_parts), __LINE__);
-		$row = @mysql_fetch_array($res, MYSQL_NUM);
-		$total_recs = $row[0];
+		$this->number_of_recs();
 		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->fm = (int)(($this->total_recs - 1)/$this->inc)*$this->inc;
 		}
+		$this->display_list_table_buttons('up');
+
 		if ($this->cgi['persist'] != '') {
 			echo $this->get_origvars_html($this->cgi['persist']);
 		}
@@ -2191,10 +2243,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();
 	} /* }}} */
 
@@ -2236,13 +2285,8 @@
 		echo '<input type="hidden" name="rec" value="',($this->copy_operation()?'':$this->rec),'">',"\n";
 		echo '<input type="hidden" name="fm" value="',$this->fm,'">',"\n";
 		echo '<input type="hidden" name="fl" value="',$this->fl,'">',"\n";
-		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="phpMyEdit_tab0">',"\n";
 		}
@@ -2254,13 +2298,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();
 	} /* }}} */
 
@@ -2879,6 +2919,7 @@
 		if (! $this->nav_up() && ! $this->nav_down()) {
 			$this->navigation .= 'D'; // down position is default
 		}
+		$this->display['buttons'] = $opts['display']['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'));
