/*
place this portion of file instead of display_list_table_buttons() and display_record_buttons()

in list_table and display_record functions remove all ifs and call required function.

in list_table make total_recs global
*/

	/*
	 * Display buttons at top and bottom of page
	 */
	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";
		echo $buttons;
		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";
		echo $buttons;
		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($name == 'cancel') {
			return $this->htmlSubmit('cancel'.$this->page_types[$this->page_type], 'Cancel', $this->getCSSclass('cancel', $up), false,0)."\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,2)."\n"; // total_recs
			}
		if(in_array($name, array('save','more'))) {
			if($this->page_type == 'D' && $name == 'save' ) $value = 'Delete';
			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), true, false, 0)."\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, 1)."\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, 1)."\n";
			}
		if($name == 'drop_down') {
			$disabledgoto = !($listall || ($disablednext && $disabledprev)) ? '' : ' disabled';
			if($disablegoto == 'disabled' && $this->display['disabled'] ==0 ) 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)), 1)."\n";
				}
		if($name == 'td_stats' || $name == 'stats') {
			if($name == 'td_stats') $ret = '<td class="'.$this->getCSSclass('stats', $position).'">'."\n";
			if ($this->inc <= 0) {
				$ret .= $this->labels['Page'].':&nbsp;1&nbsp;'.$this->labels['of'].'&nbsp;1';
			} else {
				$current_page = intval($this->fm / $this->inc) + 1;
				$ret .= $this->labels['Page'].':&nbsp;'.$current_page;
				$ret .= '&nbsp;'.$this->labels['of'].'&nbsp;'.$total_pages;
				}
			$ret .= '&nbsp; '.$this->labels['Records'].':&nbsp;'.$total_recs."\n";
			if($name == 'td_stats') $ret .= '</td>'."\n";
			return $ret;
			}
		if($name == 'td_message' || $name == 'message') {
			if (strlen(@$this->message) > 0) {
				if($name == 'td_message') $ret = '<td class="'.$this->getCSSclass('message', $position).'">';
				$ret .= $this->message;
				if($name == 'td_message') $ret .= '</td>'."\n";
				}
			return $ret;
			}
		return $name."\n";
	} /* }}} */

	function display_buttons($up) /* {{{ */
	{
		$page = $this->page_types[$this->page_type];
		if(is_array($this->display['buttons'][$page][$up]))
			$buttons = $this->display['buttons'][$page][$up];
		else { $nav = 'nav_'.$up;
			if($this->$nav()) {
				$def_buttons = array (
					'L' => array ('first','prev','add','view','change','copy','delete','next','last','goto','drop_down', '</td>', 'td_message', 'td_stats'),
					'F' => array ('first','prev','add','view','change','copy','delete','next','last','goto','drop_down', '</td>', 'td_message', 'td_stats'),
					'A' => array ('save','more','cancel', '</td>', 'td_message'),
					'C' => array ('save','more','cancel', '</td>', 'td_message'),
					'P' => array ('save', 'cancel', '</td>', 'td_message'),
					'D' => array ('save','cancel', '</td>', 'td_message'),
					'V' => array ('change','cancel', '</td>', 'td_message')
					);
				$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;
	} /* }}} */

