--- phpMyEdit.class-v1.167.php	2005-04-16 15:36:23.000000000 +1000
+++ phpMyEdit.class-v1.167.mm4.php	2005-04-19 08:39:48.000000000 +1000
@@ -149,6 +149,8 @@
 	var $navigation;	// navigation style
 	var $tabs;			// TAB names
 	var $timer = null;	// phpMyEdit_timer object
+        var $childs; // subforms
+        var $parent; // if not null, parent PME instance
 
 	// Predefined variables
 	var $comp_ops  = array('<'=>'<','<='=>'<=','='=>'=','>='=>'>=','>'=>'>');
@@ -168,8 +170,8 @@
 			'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'),
+			'L' => array('first','prev','add','view','change','copy','delete','next','last','goto','goto_combo'), // note: >,>>,<,<< did not work with stylesheet
+			'F' => array('first','prev','add','view','change','copy','delete','next','last','goto','goto_combo'), // note: >,>>,<,<< did not work with stylesheet
 			'A' => array('save','more','cancel'),
 			'C' => array('save','more','cancel'),
 			'P' => array('save', 'cancel'),
@@ -214,6 +216,7 @@
 	function copy_enabled()   { return stristr($this->options, 'P') && $this->add_enabled(); }
 	function tabs_enabled()   { return $this->display['tabs'] && count($this->tabs) > 0; }
 	function hidden($k)       { return stristr($this->fdd[$k]['input'],'H'); }
+        function fileupload($k)   { return stristr($this->fdd[$k]['input'],'F'); }
 	function password($k)     { return stristr($this->fdd[$k]['input'],'W'); }
 	function readonly($k)     { return stristr($this->fdd[$k]['input'],'R') || $this->virtual($k);     }
 	function virtual($k)      { return stristr($this->fdd[$k]['input'],'V') && $this->col_has_sql($k); }
@@ -770,6 +773,7 @@
 	document.getElementById(tab_name).style.display = "block";
 	'.$this->js['prefix'].'cur_tab = tab_name;
 	document.'.$this->cgi['prefix']['sys'].'form.'.$this->cgi['prefix']['sys'].'cur_tab.value = tab_name;
+       document.'.(!$this->display['form'] && isset($this->parent->cgi['prefix']['sys']) ? $this->parent->cgi['prefix']['sys'] : $this->cgi['prefix']['sys']).'form.'.$this->cgi['prefix']['sys'].'cur_tab.value = tab_name;
 }',"\n\n";
 				echo '// --></script>', "\n";
 			}
@@ -888,6 +892,7 @@
 
 		if ($this->display['form']) {
 			echo '<form class="',$this->getCSSclass('form'),'" method="POST"';
+                        echo ' enctype="multipart/form-data" ';
 			echo ' action="',$page_name,'" name="'.$this->cgi['prefix']['sys'].'form">',"\n";
 		}
 		return true;
@@ -979,11 +984,15 @@
 				$size   && $size_ml_props .= ' size="'.$size.'"';
 				$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
 				echo '<input class="',$css_class_name,'" ';
-				echo ($this->password($k) ? 'type="password"' : 'type="text"');
+				echo ($this->password($k) ? 'type="password"' : 'type="'.($this->fileupload($k) ? 'file' : 'text').'" ');
 				echo ($this->readonly($k) ? ' disabled' : '');
-				echo ' name="',$this->cgi['prefix']['data'].$this->fds[$k],'"';
+				echo ' name="',$this->cgi['prefix']['data'].$this->fds[$k],''.($this->fileupload($k) ? 'IMG' : '').'"';
+				if ($this->fileupload($k)) { 
+                                  echo ' onChange="extract(this.form.'.$this->cgi['prefix']['data'].$this->fds[$k].'IMG.value,this.form.'.$this->cgi['prefix']['data'].$this->fds[$k].')"';}
 				echo $size_ml_props,' value="';
 				echo htmlspecialchars($this->fdd[$k]['default']),'">';
+				if ($this->fileupload($k)) { 
+                                      echo '<input type="hidden" name="'.$this->cgi['prefix']['data'].$this->fds[$k].'" id="'.$this->fds[$k].'" value="">'; }
 			}
 			echo '</td>',"\n";
 			if ($this->guidance) {
@@ -1100,16 +1109,25 @@
 				echo ' wrap="virtual"';
 			}
 			echo '>',htmlspecialchars($row["qf$k"]),'</textarea>',"\n";
+                } elseif (isset($this->fdd[$k]['child'])) {
+                        $this->childs[$this->fds[$k]]->execute();
 		} else {
 			$size_ml_props = '';
 			$maxlen = intval($this->fdd[$k]['maxlen']);
 			$size   = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60); 
+                        if ($this->fileupload($k)) { $size = 15; }
 			$size   && $size_ml_props .= ' size="'.$size.'"';
 			$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
-			echo '<input class="',$css_class_name,'" type="text" ';
+			echo '<input class="',$css_class_name,'" type="'.($this->fileupload($k) ? 'file' : 'text').'" ';
 			echo ($this->readonly($k) ? 'disabled ' : '');
-			echo 'name="',$this->cgi['prefix']['data'].$this->fds[$k],'" value="';
-			echo htmlspecialchars($row["qf$k"]),'" ',$size_ml_props,'>',"\n";
+			echo 'name="',$this->cgi['prefix']['data'].$this->fds[$k],''.($this->fileupload($k) ? 'IMG' : '').'"';
+                        if ($this->fileupload($k)) { 
+                           echo ' onChange="extract(this.form.'.$this->cgi['prefix']['data'].$this->fds[$k].'IMG.value,this.form.'.$this->cgi['prefix']['data'].$this->fds[$k].')"';}
+                        echo $size_ml_props,' value="';
+			echo htmlspecialchars($row["qf$k"]) ,'">',"\n";
+			if ($this->fileupload($k)) { 
+                           echo '['.htmlspecialchars($row["qf$k"]).']';
+                           echo '<input type="hidden" name="'.$this->cgi['prefix']['data'].$this->fds[$k].'" value="'.htmlspecialchars($row["qf$k"]).'">'; }
 		}
 		echo '</td>',"\n";
 	} /* }}} */
@@ -1136,7 +1154,11 @@
 		$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);
+                if (isset($this->fdd[$k]['child'])) {
+                        $this->childs[$this->fds[$k]]->execute();
+                } else {
+                        echo $this->cellDisplay($k, $row, $css_class_name);
+                }
 		echo '</td>',"\n";
 	} /* }}} */
 
@@ -1707,8 +1729,8 @@
 		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";
+                echo '</tr></table>',"\n"; 
+		if($position == 'up')  echo '<hr class="'.$this->getCSSclass('hr', 'up').'">'."\n"; 
 	} /* }}} */
 
 	/*
@@ -1735,7 +1757,7 @@
 			if ($this->tabs_enabled()) $this->display_tab_labels('up');
 			echo '<hr class="',$this->getCSSclass('hr', 'up'),'">',"\n";
 		}
-		echo '</tr></table>',"\n";
+                else echo '</tr></table>',"\n";
 	} /* }}} */
 
 	function display_buttons($position) /* {{{ */
@@ -3128,6 +3150,49 @@
 				$this->cgi['prefix'][$type] = $this->get_default_cgi_prefix($type);
 			}
 		}
+               // Childs
+               $this->parent = null;
+               if(isset($opts['childs'])) {
+                       global $HTTP_POST_VARS, $HTTP_GET_VARS;
+                       $all_CGI = array_merge(Array(), @$HTTP_POST_VARS, @$HTTP_GET_VARS);
+                       $cgi_parent = Array();
+                       foreach($all_CGI as $key => $val) {
+                               if(preg_match('/^('.$this->cgi['prefix']['sys'].'.*)/', $key, $parts)) {
+                                       $cgi_parent[$key] = $val;
+                               }
+                       }
+                       foreach($opts['childs'] as $key => $val) {
+                               $val['display']['form'] = false; //form's tag not required for childs
+                               $val['execute'] = 0; //don't execute childs now !
+                               $child_was_clicked = false;
+                               foreach($all_CGI as $key2 => $val2) { //is last click child related
+                                       $child_was_clicked = $child_was_clicked || preg_match('/^('.$val['cgi']['prefix']['sys'].')(save|more|cancel|operation)+(add|view|change|copy|delete)?/', $key2, $parts);
+                               }
+                               foreach($all_CGI as $key2 => $val2) { //
+                                       if(preg_match('/^('.$val['cgi']['prefix']['sys'].')('.$this->cgi['prefix']['sys'].'.*)/', $key2, $parts)) {
+                                               //if last action was made on thsi child
+                                               if($child_was_clicked && $parts[2] != $this->cgi['prefix']['sys'].'cur_tab') {
+                                                       //...force to previous main action
+                                                       //shouldn't we here convert
+                                                       // - morechange=Apply to operation = Change ?
+                                                       // - operation=Add to operation=Change + correct rec ?
+                                                       $this->cgi['overwrite'][$parts[2]] = $val2;
+                                               }
+                                               //backup main sys again (old one will be overwrited by next loop)
+                                               $val['cgi']['persist'][$val['cgi']['prefix']['sys'].$parts[2]] = $val2;
+                                       }
+                               }
+                               foreach($cgi_parent as $key2 => $val2) { //keep (but protect) parents CGI var
+                                       $val['cgi']['persist'][$val['cgi']['prefix']['sys'].$key2] = $val2;
+                               }
+                               $this->childs[$key] = new phpMyEdit($val); //instanciation
+                               $this->childs[$key]->is_child = true; // it's a child
+                               $this->childs[$key]->parent = $this; //it has a parent (persisting tab required)
+                       }
+               } else {
+                       $this->childs = false;
+               }
+
 		// Sorting variables
 		$this->sfn   = $this->get_sys_cgi_var('sfn');
 		isset($this->sfn)             || $this->sfn          = array();
@@ -3214,4 +3279,3 @@
  * }}} */
 
 ?>
-
