5 require_once realpath(dirname(__FILE__).
"/auto_form.inc");
50 global $auto_form_defaults;
52 foreach($auto_form_defaults as $field => $value)
54 $this->$field = $value;
57 $this->forms = array();
67 function addForm($form, $enableValidation =
false)
69 $form->makeSubordinate();
70 $this->forms[] = $form;
71 $form->getValidationEngine()->generateScript = $enableValidation;
80 foreach($this->forms as $form)
82 $s = $form->writeScript();
83 if ($form->getValidationEngine()->generateScript)
86 $s= preg_replace(
"/\\bform\\[(['\"])([^'\"]*?)['\"]\\]/",
"form[$1{$form->id}__$2$1]", $s);
93 <script type=
"text/javascript">
94 function onCompositeFormSubmit(form)
97 foreach($this->forms as $form)
100 if (!onSubmit<?echo $form->
id?>(form))
return false;
108 $script .= ob_get_contents();
128 foreach(func_get_args() as
$preset)
130 $this->presetFields[
$preset] =
true;
141 echo
"<form id='composite_auto_form' method='{$this->method}' action='{$this->action}' enctype='multipart/form-data'";
142 echo
" onsubmit='return onCompositeFormSubmit(this);'";
145 if ($this->buttons_at_top)
150 foreach($this->forms as $form)
154 $output = ob_get_contents();
157 $output = preg_replace(
"/\\bname=(['\"])([^'\"]*?)['\"]/",
"name=$1{$form->id}__$2$1", $output);
160 <div
id=
"<?echo $form->id?>_container" class=
"<?echo $this->containerClass?>">
178 foreach($this->forms as $form)
181 $form->drawReadOnly();
182 $output = ob_get_contents();
185 $output = preg_replace(
"/\\bname=(['\"])([^'\"]*?)['\"]/",
"name=$1{$form->id}__$2$1", $output);
188 <div
id=
"<?echo $form->id?>_container" class=
"<?echo $this->containerClass?>">
197 echo
"<div style='clear:both'> </div><br/>";
209 function button($text, $url, $confirm =
null, $isScript =
false)
211 $this->buttons[] = array(
'text' => $text,
'url' => $url,
'confirm' => $confirm,
'isScript' => $isScript);
221 $submitLabel = $this->submitLabel;
222 $obj = $this->forms[0]->getData();
224 if ($submitLabel ==
"")
226 $submitLabel =
"Save ".pluralize($obj->prettifyClassName());
229 echo
"<div style='clear: both; text-align: {$this->buttonAlignment}'><br/>";
230 if ($this->useLinkSubmit)
232 echo
"<a class='{$this->buttonCSS}' name='submit' onclick='if (onSubmit{$this->id}(document.forms.{$this->id})) return document.forms.{$this->id}.submit(); else return false;'>$submitLabel</a>";
236 echo
"<input type='submit' class='{$this->buttonCSS}' value='$submitLabel'/>";
239 foreach($this->buttons as $button)
241 $url = ($button[
'isScript']) ? $button[
'url'] :
"go('{$button['url']}');";
243 if ($button[
'confirm'])
245 $link =
"if (confirm('".jsSafe($button[
'confirm']).
"')) $url; return false;";
249 $link =
"$url; return false;";
252 echo
" <input type='button' class='{$this->buttonCSS}' onclick=\"$link\" value=\"{$button['text']}\"/>";
267 foreach($this->forms as $form)
269 foreach($_POST as $name => $value)
271 if (strpos($name,
"__") ===
false)
273 unset($_POST[$name]);
277 $prefix = $form->id.
"__";
278 $len = strlen($prefix);
280 foreach($_POST as $name => $value)
282 if (!strncmp($name, $prefix, $len))
284 $_POST[substr($name, $len)] = $value;
288 foreach($_FILES as $name => $value)
290 if (strpos($name,
"__") ===
false)
292 unset($_FILES[$name]);
296 $prefix = $form->id.
"__";
297 $len = strlen($prefix);
299 foreach($_FILES as $name => $value)
301 if (!strncmp($name, $prefix, $len))
303 $_FILES[substr($name, $len)] = $value;
317 if ($this->onSaveComplete)
319 call_user_func_array($this->onSaveComplete, array($this));
356 $this->
id = $form->id;
359 $this->parent->addForm($this);
370 $this->form =
new AutoForm($this->obj,
"POST",
"", $this->
id);
373 $this->parent->addForm($this);
381 return $this->form->validator;
386 return $this->form->getData();
391 $this->form->setDataSet($params);
396 return $this->form->writeScript();
401 $this->form->drawForm();
406 $this->form->drawReadOnly();
411 $this->form->makeSubordinate();
421 $rtn = $this->form->save();
423 if($rtn ==
false && $this->allowEmpty && $this->
isEmpty())
428 $this->msg = $this->form->msg;
444 $obj =& $this->form->getData();
445 $pk = $obj->getPrimaryKey();
448 $filter = $obj->getFilter();
450 foreach(
$fields as $field => $type)
452 if ($field != $pk && !array_key_exists($field, $this->form->hidden) && !($filter && $filter->isExcluded($field)) && !array_key_exists($field, $this->parent->presetFields))
454 $value = $obj->$field;