version 1.129, 2004/03/31 15:46:26 |
version 1.130, 2004/04/04 21:02:57 |
|
|
* http://platon.sk/projects/phpMyEdit/ |
* http://platon.sk/projects/phpMyEdit/ |
*/ |
*/ |
|
|
/* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.128 2004/03/31 15:35:40 nepto Exp $ */ |
/* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.129 2004/03/31 15:46:26 nepto Exp $ */ |
|
|
/* This is a generic table editing program. The table and fields to be |
/* This is a generic table editing program. The table and fields to be |
edited are defined in the calling program. |
edited are defined in the calling program. |
|
|
|
|
function form_begin() /* {{{ */ |
function form_begin() /* {{{ */ |
{ |
{ |
/* |
|
Need a lot of work in here |
|
using something like: |
|
$fdd['fieldname']['validate']['js_regex']='/something/'; |
|
$fdd['fieldname']['validate']['php_regex']='something'; |
|
*/ |
|
$page_name = htmlspecialchars($this->page_name); |
$page_name = htmlspecialchars($this->page_name); |
|
|
if ($this->add_operation() || $this->change_operation() || $this->copy_operation() |
if ($this->add_operation() || $this->change_operation() || $this->copy_operation() |
|| $this->view_operation() || $this->delete_operation()) { |
|| $this->view_operation() || $this->delete_operation()) { |
$field_to_tab = ''; |
$field_to_tab = ''; |
Line 757 function phpMyEdit_show_tab(tab_name) |
|
Line 750 function phpMyEdit_show_tab(tab_name) |
|
} |
} |
|
|
if ($this->add_operation() || $this->change_operation() || $this->copy_operation()) { |
if ($this->add_operation() || $this->change_operation() || $this->copy_operation()) { |
$required_ar = array(); |
$first_required = true; |
for ($k = 0; $k < $this->num_fds; $k++) { |
for ($k = 0; $k < $this->num_fds; $k++) { |
if ($this->displayed[$k] && $this->fdd[$k]['required'] |
if ($this->displayed[$k] && ! $this->readonly($k) && ! $this->hidden($k) |
&& ! $this->readonly($k) && ! $this->hidden($k)) { |
&& ($this->fdd[$k]['required'] || isset($this->fdd[$k]['js']['regexp']))) { |
$required_ar[] = $k; |
if ($first_required) { |
if (isset($this->fdd[$k]['regex']['js'])) { |
$first_required = false; |
/* TODO: Use a javascript regex to validate it */ |
echo '<script type="text/javascript"><!--',"\n"; |
} |
echo ' |
} |
|
} |
|
|
|
if (count($required_ar) > 0) { |
|
echo '<script type="text/javascript"><!--',"\n"; |
|
echo ' |
|
function phpMyEdit_trim(str) |
function phpMyEdit_trim(str) |
{ |
{ |
while (str.substring(0, 1) == " " |
while (str.substring(0, 1) == " " |
Line 790 function phpMyEdit_trim(str) |
|
Line 777 function phpMyEdit_trim(str) |
|
|
|
function phpMyEdit_form_control(theForm) |
function phpMyEdit_form_control(theForm) |
{',"\n"; |
{',"\n"; |
foreach ($required_ar as $field_num) { |
} |
if ($this->col_has_values($field_num)) { |
if ($this->col_has_values($k)) { |
$condition = 'theForm.%s.selectedIndex == -1'; |
$condition = 'theForm.'.$this->fds[$k].'.selectedIndex == -1'; |
$multiple = $this->col_has_multiple_select($field_num); |
$multiple = $this->col_has_multiple_select($k); |
} else { |
} else { |
$condition = 'phpMyEdit_trim(theForm.%s.value) == ""'; |
$condition = ''; |
$multiple = false; |
$multiple = false; |
|
if ($this->fdd[$k]['required']) { |
|
$condition = 'phpMyEdit_trim(theForm.'.$this->fds[$k].'.value) == ""'; |
|
} |
|
if (isset($this->fdd[$k]['js']['regexp'])) { |
|
$condition .= (strlen($condition) > 0 ? ' || ' : ''); |
|
$condition .= sprintf('!(%s.test(phpMyEdit_trim(theForm.%s.value)))', |
|
$this->fdd[$k]['js']['regexp'], $this->fds[$k]); |
|
} |
} |
} |
|
|
/* Multiple selects have their name like ``name[]''. |
/* Multiple selects have their name like ``name[]''. |
Line 809 function phpMyEdit_form_control(theForm) |
|
Line 804 function phpMyEdit_form_control(theForm) |
|
echo ' |
echo ' |
multiple_select = null; |
multiple_select = null; |
for (i = 0; i < theForm.length; i++) { |
for (i = 0; i < theForm.length; i++) { |
if (theForm.elements[i].name == "',$this->fds[$field_num],'[]") { |
if (theForm.elements[i].name == "',$this->fds[$k],'[]") { |
multiple_select = theForm.elements[i]; |
multiple_select = theForm.elements[i]; |
break; |
break; |
} |
} |
} |
} |
if (multiple_select != null && multiple_select.selectedIndex == -1) { |
if (multiple_select != null && multiple_select.selectedIndex == -1) {'; |
alert("',$this->labels['Please enter'],' ',$this->fdd[$field_num]['name'],'.");'; |
|
if ($this->tabs_enabled()) { |
|
echo ' |
|
phpMyEdit_show_tab("phpMyEdit_tab"+phpMyEdit_field_to_tab['.$field_num.']);'; |
|
} |
|
echo ' |
|
return false; |
|
}',"\n"; |
|
} else { |
} else { |
echo ' |
echo ' |
if (',sprintf($condition, $this->fds[$field_num]),') { |
if (',$condition,') {'; |
alert("',$this->labels['Please enter'],' ',$this->fdd[$field_num]['name'],'.");'; |
} |
if ($this->tabs_enabled()) { |
echo ' |
echo ' |
alert("',$this->labels['Please enter'],' ',$this->fdd[$k]['name'],'.'; |
phpMyEdit_show_tab("phpMyEdit_tab"+phpMyEdit_field_to_tab['.$field_num.']);'; |
echo isset($this->fdd[$k]['js']['hint']) ? '\n'.$this->fdd[$k]['js']['hint'] : ''; |
} |
echo '");'; |
|
if ($this->tabs_enabled()) { |
echo ' |
echo ' |
theForm.',$this->fds[$field_num],'.focus(); |
phpMyEdit_show_tab("phpMyEdit_tab"+phpMyEdit_field_to_tab['.$k.']);'; |
|
} |
|
echo ' |
|
theForm.',$this->fds[$k],'.focus(); |
return false; |
return false; |
}',"\n"; |
}',"\n"; |
} |
|
} |
} |
|
} |
|
if (! $first_required) { |
echo ' |
echo ' |
return true; |
return true; |
}',"\n\n"; |
}',"\n\n"; |