I am tying to clone the geo_zones.php script and the functions related in html_output.php and general.php in functions directory in admin.
If I copy all the code and paste it in the corrected files, all works ok, but when I try to change the code to use it with my new table the code it does not work.
I have rewrotten the code one thousand and more times and still I do not see where is the error.
What I try to develope is a website to book cruises. Then, the names are in spanish, this is the translation navieras=cruise lines, clases= classes, and barcos=vessels/ships.
I have three tables. Navieras, clases, and barcos.
I am trying to re-use the geo-zones pull down dependent menus in order to show the classes of ships only of the cruise line selected.
Please can someone review it and help me.
This is the code in geo_zones.php
<script language="javascript"><!--
function resetZoneSelected(theForm) {
if (theForm.state.value != '') {
theForm.zone_id.selectedIndex = '0';
if (theForm.zone_id.options.length > 0) {
theForm.state.value = '<?php echo JS_STATE_SELECT; ?>';
}
}
}
function update_zone(theForm) {
var NumState = theForm.zone_id.options.length;
var SelectedCountry = "";
while(NumState > 0) {
NumState--;
theForm.zone_id.options[NumState] = null;
}
SelectedCountry = theForm.zone_country_id.options[theForm.zone_country_id.selectedIndex].value;
<?php echo zen_js_zone_list('SelectedCountry', 'theForm', 'zone_id'); ?>
}
//--></script>
****and then in case of new*****
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY . '<br>' . zen_draw_pull_down_menu('zone_country_id', zen_get_countries(TEXT_ALL_COUNTRIES), '', 'onChange="update_zone(this.form);"'));
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_ZONE . '<br>' . zen_draw_pull_down_menu('zone_id', zen_prepare_country_zones_pull_down()));
****and in case of edit*****
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY . '<br>' . zen_draw_pull_down_menu('zone_country_id', zen_get_countries(TEXT_ALL_COUNTRIES), $aInfo->zone_country_id, 'onChange="update_zone(this.form);"'));
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_ZONE . '<br>' . zen_draw_pull_down_menu('zone_id', zen_prepare_country_zones_pull_down($aInfo->zone_country_id), $aInfo->zone_id));
This is the function in html_output.php
// javascript to dynamically update the states/provinces list when the country is changed
// TABLES: zones
function zen_js_zone_list($country, $form, $field) {
global $db;
$countries = $db->Execute("select distinct zone_country_id
from " . TABLE_ZONES . "
order by zone_country_id");
$num_country = 1;
$output_string = '';
while (!$countries->EOF) {
if ($num_country == 1) {
$output_string .= ' if (' . $country . ' == "' . $countries->fields['zone_country_id'] . '") {' . "\n";
} else {
$output_string .= ' } else if (' . $country . ' == "' . $countries->fields['zone_country_id'] . '") {' . "\n";
}
$states = $db->Execute("select zone_name, zone_id
from " . TABLE_ZONES . "
where zone_country_id = '" . $countries->fields['zone_country_id'] . "'
order by zone_name");
$num_state = 1;
while (!$states->EOF) {
if ($num_state == '1') $output_string .= ' ' . $form . '.' . $field . '.options[0] = new Option("' . PLEASE_SELECT . '", "");' . "\n";
$output_string .= ' ' . $form . '.' . $field . '.options[' . $num_state . '] = new Option("' . $states->fields['zone_name'] . '", "' . $states->fields['zone_id'] . '");' . "\n";
$num_state++;
$states->MoveNext();
}
$num_country++;
$countries->MoveNext();
}
$output_string .= ' } else {' . "\n" .
' ' . $form . '.' . $field . '.options[0] = new Option("' . TYPE_BELOW . '", "");' . "\n" .
' }' . "\n";
return $output_string;
}
////
These are the functions from general.php
// return an array with country zones
function zen_get_country_zones($country_id) {
global $db;
$zones_array = array();
$zones = $db->Execute("select zone_id, zone_name
from " . TABLE_ZONES . "
where zone_country_id = '" . (int)$country_id . "'
order by zone_name");
while (!$zones->EOF) {
$zones_array[] = array('id' => $zones->fields['zone_id'],
'text' => $zones->fields['zone_name']);
$zones->MoveNext();
}
return $zones_array;
}
function zen_prepare_country_zones_pull_down($country_id = '') {
// preset the width of the drop-down for Netscape
$pre = '';
if ( (!zen_browser_detect('MSIE')) && (zen_browser_detect('Mozilla/4')) ) {
for ($i=0; $i<45; $i++) $pre .= ' ';
}
$zones = zen_get_country_zones($country_id);
if (sizeof($zones) > 0) {
$zones_select = array(array('id' => '', 'text' => PLEASE_SELECT));
$zones = array_merge($zones_select, $zones);
} else {
$zones = array(array('id' => '', 'text' => TYPE_BELOW));
// create dummy options for Netscape to preset the height of the drop-down
if ( (!zen_browser_detect('MSIE')) && (zen_browser_detect('Mozilla/4')) ) {
for ($i=0; $i<9; $i++) {
$zones[] = array('id' => '', 'text' => $pre);
}
}
}
return $zones;
}
////
Ok. Then, the code modified by me are this:
<script language="javascript"><!--
function resetZoneSelected(theForm) {
if (theForm.state.value != '') {
theForm.clases_id.selectedIndex = '0';
if (theForm.clases_id.options.length > 0) {
theForm.state.value = '<?php echo JS_STATE_SELECT; ?>';
}
}
}
function update_zone(theForm) {
var NumState = theForm.clases_id.options.length;
var SelectedCountry = "";
while(NumState > 0) {
NumState--;
theForm.clases_id.options[NumState] = null;
}
SelectedCountry = theForm.clases_naviera_id.options[theForm.clases_naviera_id.selectedIndex].value;
<?php echo zen_js_clasesnaviera_list('SelectedCountry', 'theForm', 'clases_id'); ?>
}
//--></script>
<script type="text/javascript">
CASE NEW
$contents[] = array('text' => '<br>' . TEXT_INFO_NAVIERA . '<br>' . zen_draw_pull_down_menu('clases_naviera_id', zen_get_navieras(TEXT_ALL_NAVIERAS), '', 'onChange="update_zone(this.form);"'));
$contents[] = array('text' => '<br>' . TEXT_INFO_CLASE_NAVIERA . '<br>' . zen_draw_pull_down_menu('clases_id', zen_prepare_clases_navieras_pull_down()));
CASE EDIT
$contents[] = array('text' => '<br>' . TEXT_INFO_NAVIERA . '<br>' . zen_draw_pull_down_menu('clases_naviera_id', zen_get_navieras(TEXT_ALL_NAVIERAS), $aInfo->clases_naviera_id, 'onChange="update_zone(this.form);"'));
$contents[] = array('text' => '<br>' . TEXT_INFO_CLASE_NAVIERA . '<br>' . zen_draw_pull_down_menu('clases_id', zen_prepare_clases_navieras_pull_down($aInfo->clases_naviera_id), $aInfo->clases_id));
in extra functions directory, I have created a new file with these modified functions
// javascript to dynamically update the states/provinces list when the country is changed
// TABLES: zones
function zen_js_mierda_list($country, $form, $field) {
global $db;
$countries = $db->Execute("select distinct clases_naviera_id
from " . TABLE_CLASES . "
order by clases_naviera_id");
$num_country = 1;
$output_string = '';
while (!$countries->EOF) {
if ($num_country == 1) {
$output_string .= ' if (' . $country . ' == "' . $countries->fields['clases_naviera_id'] . '") {' . "\n";
} else {
$output_string .= ' } else if (' . $country . ' == "' . $countries->fields['clases_naviera_id'] . '") {' . "\n";
}
$states = $db->Execute("select clases_name, clases_id
from " . TABLE_CLASES . "
where clases_naviera_id = '" . $countries->fields['clases_naviera_id'] . "'
order by clases_name");
$num_state = 1;
while (!$states->EOF) {
if ($num_state == '1') $output_string .= ' ' . $form . '.' . $field . '.options[0] = new Option("' . PLEASE_SELECT . '", "");' . "\n";
$output_string .= ' ' . $form . '.' . $field . '.options[' . $num_state . '] = new Option("' . $states->fields['clases_name'] . '", "' . $states->fields['clases_id'] . '");' . "\n";
$num_state++;
$states->MoveNext();
}
$num_country++;
$countries->MoveNext();
}
$output_string .= ' } else {' . "\n" .
' ' . $form . '.' . $field . '.options[0] = new Option("' . TYPE_BELOW . '", "");' . "\n" .
' }' . "\n";
return $output_string;
}
////
// return an array with country zones
function zen_get_mierda_zones($country_id) {
global $db;
$zones_array = array();
$zones = $db->Execute("select clases_id, clases_name
from " . TABLE_CLASES . "
where clases_naviera_id = '" . (int)$country_id . "'
order by clases_name");
while (!$zones->EOF) {
$zones_array[] = array('id' => $zones->fields['clases_id'],
'text' => $zones->fields['clases_name']);
$zones->MoveNext();
}
return $zones_array;
}
function zen_prepare_mierda_zones_pull_down($country_id = '') {
// preset the width of the drop-down for Netscape
$pre = '';
if ( (!zen_browser_detect('MSIE')) && (zen_browser_detect('Mozilla/4')) ) {
for ($i=0; $i<45; $i++) $pre .= ' ';
}
$zones = zen_get_mierda_zones($country_id);
if (sizeof($zones) > 0) {
$zones_select = array(array('id' => '', 'text' => PLEASE_SELECT));
$zones = array_merge($zones_select, $zones);
} else {
$zones = array(array('id' => '', 'text' => TYPE_BELOW));
// create dummy options for Netscape to preset the height of the drop-down
if ( (!zen_browser_detect('MSIE')) && (zen_browser_detect('Mozilla/4')) ) {
for ($i=0; $i<9; $i++) {
$zones[] = array('id' => '', 'text' => $pre);
}
}
}
return $zones;
}
////
// Retorna un menu desplegable con las navieras
function zen_get_navieras($default = '') {
global $db;
$navieras_array = array();
if ($default) {
$navieras_array[] = array('id' => '',
'text' => $default);
}
$navieras = $db->Execute("select navieras_id, navieras_short_name
from " . TABLE_NAVIERAS . "
order by navieras_short_name");
while (!$navieras->EOF) {
$navieras_array[] = array('id' => $navieras->fields['navieras_id'],
'text' => $navieras->fields['navieras_short_name']);
$navieras->MoveNext();
}
return $navieras_array;
}
Ok.
So, please if someone can help me with this I will believe in angels.
Thank you


Reply With Quote
