--- /cdrom/phpMyEdit.class.-current-1.141.php	Sat Apr 24 00:08:59 2004
+++ /cdrom/phpMyEdit.class.-field-1.141.php	Sun Apr 25 18:08:36 2004
@@ -660,7 +660,7 @@
 					continue;
 				}
 				$afilter = addslashes($m);
-				if ($this->fdd[$k]['select'] == 'N') { 
+				if ($this->fdd[$k]['select'] == 'N') {
 					$mc = in_array($mc, $this->comp_ops) ? $mc : '=';
 					$qo[$this->fqn($k)] = array('oper' => $mc, 'value' => "'$afilter'");
 					$this->qfn .= '&'.$l .'='.rawurlencode($m);
@@ -899,162 +899,120 @@
 	 * Display functions
 	 */
 
-	function display_add_record() /* {{{ */
+	function prepare_display() /* {{{ */
 	{
-		for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) {
-			if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) {
-				$tab++;
-				echo '</table>',"\n";
-				echo '</div>',"\n";
-				echo '<div id="phpMyEdit_tab',$tab,'">',"\n";
-				echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
-			}
-			if (! $this->displayed[$k]) {
-				continue;
+		// PRE Triggers
+		$ret = true;
+		if ($this->change_operation() && isset($this->triggers['update']['pre'])) {
+			$ret = include($this->triggers['update']['pre']);
+			// if PRE update fails, then back to view operation
+			if (! $ret) {
+				$this->operation = $this->labels['View'];
+				$ret = true;
 			}
-			if ($this->hidden($k)) {
-				echo $this->htmlHidden($this->fds[$k], $row["qf$k"]);
-				continue;
+		}
+		if (($this->add_operation() || $this->copy_operation())
+				&& isset($this->triggers['insert']['pre'])) {
+			$ret = include($this->triggers['insert']['pre']);
+		}
+		if ($this->view_operation() && isset($this->triggers['select']['pre'])) {
+			$ret = include($this->triggers['select']['pre']);
+		}
+		if ($this->delete_operation() && isset($this->triggers['delete']['pre'])) {
+			$ret = include($this->triggers['delete']['pre']);
+		}
+		// if PRE insert/view/delete fail, then back to the list
+		if ($ret == false) {
+			$this->operation = '';
+			$this->list_table();
+			return false;
+		}
+		// make values, either from database or from $opts
+		/*if(is_array($this->newvals)) {
+			// to make possible php valiedation and/or sql triggers.
+			$this->sql_row= $this->newvals;
+			return;
+		}*/
+		if(stristr('VCPD', $this->page_type)) {
+			$qparts['type']   = 'select';
+			$qparts['select'] = $this->create_column_list();
+			$qparts['from']   = $this->create_join_clause();
+			$qparts['where']  = '('.$this->fqn($this->key).'='
+				.$this->key_delim.$this->rec.$this->key_delim.')';
+
+			$res = $this->myquery($this->query_make($qparts),__LINE__);
+			if (! ($row = @mysql_fetch_array($res, MYSQL_ASSOC))) {
+				return false;
 			}
-			$css_postfix    = @$this->fdd[$k]['css']['postfix'];
-			$css_class_name = $this->getCSSclass('input', null, 'next', $css_postfix);
-			echo '<tr class="',$this->getCSSclass('row', null, true, $css_postfix),'">',"\n";
-			echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">',$this->fdd[$k]['name'],'</td>',"\n";
-			echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
-			echo $this->getColAttributes($k),">\n";
-			if ($this->col_has_values($k)) {
-				$vals       = $this->set_values($k);
-				$selected   = @$this->fdd[$k]['default'];
-				$multiple   = $this->col_has_multiple_select($k);
-				$readonly   = $this->readonly($k);
-				$strip_tags = true;
-				$escape     = true;
-				echo $this->htmlSelect($this->fds[$k], $css_class_name, $vals, $selected,
-						$multiple, $readonly, $strip_tags, $escape);
-			} elseif (isset ($this->fdd[$k]['textarea'])) {
-				echo '<textarea class="',$css_class_name,'" name="',$this->fds[$k],'"';
-				echo ($this->readonly($k) ? ' disabled' : '');
-				if (intval($this->fdd[$k]['textarea']['rows']) > 0) {
-					echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"';
-				}
-				if (intval($this->fdd[$k]['textarea']['cols']) > 0) {
-					echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"';
+			$this->pme_row = $row; // needed for cellDisplay
+			for ($k = 0; $k < $this->num_fds; $k++) {
+				$this->sql_row[$this->fds[$k]] = $this->pme_row["qf$k"];
 				}
-				if (isset($this->fdd[$k]['textarea']['wrap'])) {
-					echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"';
-				} else {
-					echo ' wrap="virtual"';
+			return true;
+		} elseif(stristr('A', $this->page_type)) {
+			for ($k = 0; $k < $this->num_fds; $k++) {
+				$this->sql_row[$this->fds[$k]] = $this->fdd[$k]['default'];
 				}
-				echo '>',htmlspecialchars($this->fdd[$k]['default']),'</textarea>',"\n";
-			} else {
-				// Simple edit box required
-				$size_ml_props = '';
-				$maxlen = intval($this->fdd[$k]['maxlen']);
-				$size   = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); 
-				$size   && $size_ml_props .= ' size="'.$size.'"';
-				$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
-				echo '<input class="',$css_class_name,'" type="text" ';
-				echo ($this->readonly($k) ? 'disabled ' : ''),' name="',$this->fds[$k],'"';
-				echo $size_ml_props,' value="';
-				echo htmlspecialchars($this->fdd[$k]['default']),'">';
-			}
-			echo '</td>',"\n";
-			if ($this->guidance) {
-				$css_class_name = $this->getCSSclass('help', null, true, $css_postfix);
-				$cell_value     = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : '&nbsp;';
-				echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n";
-			}
-			echo '</tr>',"\n";
+			return true;
+		} else {
+			return false;//unsuported
 		}
 	} /* }}} */
 
-	function display_copy_change_delete_record() /* {{{ */
+	function valueDisplay($name) /* {{{ */
 	{
-		/*
-		 * For delete or change: SQL SELECT to retrieve the selected record
-		 */
-
-		$qparts['type']   = 'select';
-		$qparts['select'] = $this->create_column_list();
-		$qparts['from']   = $this->create_join_clause();
-		$qparts['where']  = '('.$this->fqn($this->key).'='
-			.$this->key_delim.$this->rec.$this->key_delim.')';
-
-		$res = $this->myquery($this->query_make($qparts),__LINE__);
-		if (! ($row = @mysql_fetch_array($res, MYSQL_ASSOC))) {
-			return false;
-		}
-		for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) {
-			if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) {
-				$tab++;
-				echo '</table>',"\n";
-				echo '</div>',"\n";
-				echo '<div id="phpMyEdit_tab',$tab,'">',"\n";
-				echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
+		$k = $this->fdn[$name];
+		if (! $this->displayed[$k]) return;
+		$css_postfix    = @$this->fdd[$k]['css']['postfix'];
+		$css_class_name = $this->getCSSclass('value', null, true, $css_postfix);
+		if(stristr('ACP', $this->page_type)) {
+			if ($this->readonly($k) && ($this->col_has_datemask($k) || $this->col_has_URL($k))) { // what is this good for ?
+				return $this->cellDisplay($k, $this->pme_row, $css_class_name);
 			}
-			if (! $this->displayed[$k]) {
-				continue;
+			if ($this->password($k)) {
+				return $this->display_password_field($k);
 			}
-			if ($this->copy_operation() || $this->change_operation()) {
-				if ($this->hidden($k)) {
-					if ($k != $this->key_num) {
-						echo $this->htmlHidden($this->fds[$k], $row["qf$k"]);
-					}
-					continue;
-				}
-				$css_postfix = @$this->fdd[$k]['css']['postfix'];
-				echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n";
-				echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">',$this->fdd[$k]['name'],'</td>',"\n";
-				/* There are two possibilities of readonly fields handling:
-				   1. Display plain text for readonly timestamps, dates and URLs.
-				   2. Display disabled input field
-				   In all cases particular readonly field will NOT be saved. */
-				if ($this->readonly($k) && ($this->col_has_datemask($k) || $this->col_has_URL($k))) {
-					echo $this->display_delete_field($row, $k);
-				} elseif ($this->password($k)) {
-					echo $this->display_password_field($row, $k);
-				} else {
-					echo $this->display_change_field($row, $k);
-				}
-				if ($this->guidance) {
-					$css_class_name = $this->getCSSclass('help', null, true, $css_postfix);
-					$cell_value     = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : '&nbsp;';
-					echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n";
-				}
-				echo '</tr>',"\n";
-			} elseif ($this->delete_operation() || $this->view_operation()) {
-				$css_postfix = @$this->fdd[$k]['css']['postfix'];
-				echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n";
-				echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">',$this->fdd[$k]['name'],'</td>',"\n";
-				if ($this->password($k)) {
-					echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
-					echo $this->getColAttributes($k),'>',$this->labels['hidden'],'</td>',"\n";
-				} else {
-					$this->display_delete_field($row, $k);
-				}
-				if ($this->guidance) {
-					$css_class_name = $this->getCSSclass('help', null, true, $css_postfix);
-					$cell_value     = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : '&nbsp;';
-					echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n";
-				}
-				echo '</tr>',"\n";
+			if ($this->hidden($k)) {
+				return $this->htmlHidden($name, $this->sql_row[$name]);
 			}
+			return $this->display_change_field($k);
+		} elseif(stristr('LFVD', $this->page_type)) {
+			if ($this->password($k)) {
+				return $this->labels['hidden'];
+				}
+			return $this->cellDisplay($k, $this->pme_row, $css_class_name);
 		}
 	} /* }}} */
 
-	function display_change_field($row, $k) /* {{{ */
+	function helpDisplay($name) /* {{{ */
 	{
+		$k = $this->fdn[$name];
+		$cell_value     = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : '&nbsp;';
+		return $cell_value;
+	} /* }}} */
+
+	function nameDisplay($name) /* {{{ */
+	{
+		$k = $this->fdn[$name];
+		if(stristr('ACPLVD', $this->page_type)) {
+			return $this->fdd[$k]['name'];
+		} elseif(stristr('F', $this->page_type)) {
+			// TODO, related to 'custom header' feature
+		}
+	} /* }}} */
+
+	function display_change_field($k) /* {{{ */
+	{
+		$value = $this->sql_row[$this->fds[$k]];
 		$css_postfix    = @$this->fdd[$k]['css']['postfix'];
 		$css_class_name = $this->getCSSclass('input', null, true, $css_postfix);
-		echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
-		echo $this->getColAttributes($k),">\n";
 		if ($this->col_has_values($k)) {
 			$vals       = $this->set_values($k);
 			$multiple   = $this->col_has_multiple_select($k);
 			$readonly   = $this->readonly($k);
 			$strip_tags = true;
 			$escape     = true;
-			echo $this->htmlSelect($this->fds[$k], $css_class_name, $vals, $row["qf$k"],
+			echo $this->htmlSelect($this->fds[$k], $css_class_name, $vals, $value,
 					$multiple, $readonly, $strip_tags, $escape);
 		} elseif (isset($this->fdd[$k]['textarea'])) {
 			echo '<textarea class="',$css_class_name,'" name="',$this->fds[$k],'"';
@@ -1070,7 +1028,7 @@
 			} else {
 				echo ' wrap="virtual"';
 			}
-			echo '>',htmlspecialchars($row["qf$k"]),'</textarea>',"\n";
+			echo '>',htmlspecialchars($value),'</textarea>',"\n";
 		} else {
 			$size_ml_props = '';
 			$maxlen = intval($this->fdd[$k]['maxlen']);
@@ -1079,34 +1037,23 @@
 			$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
 			echo '<input class="',$css_class_name,'" type="text" ';
 			echo ($this->readonly($k) ? 'disabled ' : ''),'name="',$this->fds[$k],'" value="';
-			echo htmlspecialchars($row["qf$k"]),'" ',$size_ml_props,'>',"\n";
+			echo htmlspecialchars($value),'" ',$size_ml_props,'>',"\n";
 		}
-		echo '</td>',"\n";
 	} /* }}} */
 
-	function display_password_field($row, $k) /* {{{ */
+	function display_password_field($k) /* {{{ */
 	{
+		$value = $this->sql_row[$this->fds[$k]];
 		$css_postfix = @$this->fdd[$k]['css']['postfix'];
-		echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
-		echo $this->getColAttributes($k),">\n";
 		$size_ml_props = '';
 		$maxlen = intval($this->fdd[$k]['maxlen']);
-		$size   = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); 
+		$size   = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60);
 		$size   && $size_ml_props .= ' size="'.$size.'"';
 		$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
-		echo '<input class="',$this->getCSSclass('value', null, true, $css_postfix),'" type="password" ';
-		echo ($this->readonly($k) ? 'disabled ' : ''),'name="',$this->fds[$k],'" value="';
-		echo htmlspecialchars($row["qf$k"]),'" ',$size_ml_props,'>',"\n";
-		echo '</td>',"\n";
-	} /* }}} */
-
-	function display_delete_field($row, $k) /* {{{ */
-	{
-		$css_postfix    = @$this->fdd[$k]['css']['postfix'];
-		$css_class_name = $this->getCSSclass('value', null, true, $css_postfix);
-		echo '<td class="',$css_class_name,'"',$this->getColAttributes($k),">\n";
-		echo $this->cellDisplay($k, $row, $css_class_name);
-		echo '</td>',"\n";
+		$ret = '<input class="'.$this->getCSSclass('value', null, true, $css_postfix).'" type="password" ';
+		$ret .= ($this->readonly($k) ? 'disabled ' : '').'name="'.$this->fds[$k].'" value="';
+		$ret .= htmlspecialchars($value).'" '.$size_ml_props.'>'."\n";
+		return $ret;
 	} /* }}} */
 
 	/**
@@ -2195,32 +2142,7 @@
 
 	function display_record() /* {{{ */
 	{
-		// PRE Triggers
-		$ret = true;
-		if ($this->change_operation() && isset($this->triggers['update']['pre'])) {
-			$ret = include($this->triggers['update']['pre']);
-			// if PRE update fails, then back to view operation
-			if (! $ret) {
-				$this->operation = $this->labels['View'];
-				$ret = true;
-			}
-		}
-		if (($this->add_operation() || $this->copy_operation())
-				&& isset($this->triggers['insert']['pre'])) {
-			$ret = include($this->triggers['insert']['pre']);
-		}
-		if ($this->view_operation() && isset($this->triggers['select']['pre'])) {
-			$ret = include($this->triggers['select']['pre']);
-		}
-		if ($this->delete_operation() && isset($this->triggers['delete']['pre'])) {
-			$ret = include($this->triggers['delete']['pre']);
-		}
-		// if PRE insert/view/delete fail, then back to the list
-		if ($ret == false) {
-			$this->operation = '';
-			$this->list_table();
-			return;
-		}
+		if(!$this->prepare_display()) return false;
 		$this->form_begin();
 		if ($this->cgi['persist'] != '') {
 			echo $this->get_origvars_html($this->cgi['persist']);
@@ -2242,11 +2164,37 @@
 			echo '<div id="phpMyEdit_tab0">',"\n";
 		}
 		echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
-		if ($this->add_operation()) {
-			$this->display_add_record();
-		} else {
-			$this->display_copy_change_delete_record();
-		}
+		//$this->display_some_record();
+		for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) {
+			if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) {
+				$tab++;
+				echo '</table>',"\n";
+				echo '</div>',"\n";
+				echo '<div id="phpMyEdit_tab',$tab,'">',"\n";
+				echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
+			}
+			if (! $this->displayed[$k]) {
+				continue;
+			}
+			// line section
+			$css_postfix = @$this->fdd[$k]['css']['postfix'];
+			$name = $this->fds[$k];
+			echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n";
+			// name section
+			echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">',$this->nameDisplay($name),'</td>',"\n";
+			// value section
+			echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
+			echo $this->getColAttributes($k),">\n";
+			echo $this->valueDisplay($name);
+			echo "</td>\n";
+			// help section
+			if ($this->guidance) {
+				$css_class_name = $this->getCSSclass('help', null, true, $css_postfix);
+				echo '<td class="',$css_class_name,'">',$this->helpDisplay($name),'</td>',"\n";
+				}
+			echo '</tr>',"\n";
+			}
+		// end display_some_record
 		echo '</table>',"\n";
 		echo '</div>',"\n";
 		if ($this->nav_down()) {
