adminFareCommonHead.phpの例

<?php
//閲覧および各種メニュー
include_once("../../../mainfile.php");
//$xoopsOption['show_rblock'] = 0;
include_once(XOOPS_ROOT_PATH."/header.php");
include_once("../class/class.fare.php");
global $xoopsDB, $xoopsUser;
$myts = & MyTextSanitizer::getInstance();
$fareObj = new Fare();
$selectedCategoryID = isset($_POST['category'])?$_POST['category']:0;
$selectedGeneralRouteID = isset($_POST['general_route_id'])?$_POST['general_route_id']:0;
$selectedRouteID = isset($_POST['route_id'])?$_POST['route_id']:0;

$categories = $fareObj->getCategories();
if($selectedCategoryID)
  $general_routes = $fareObj->getGeneralRoutesByCategoryId(intval($_POST['category']));
if($selectedGeneralRouteID!=0)
  $routes = $fareObj->getRoutesByGeneralRouteId(intval($selectedGeneralRouteID));
?>
<script language="javascript">
/* カテゴリ,路線名選択を変化させたときに自動的に送信する関数 */
function changeGenRoute() {
  if(document.editDetail.route_id) {
    var routeSel = document.editDetail.route_id;
    routeSel.options[routeSel.options.length]= new Option("","0",false,true);
  }
  document.editDetail.submit();
}
function changeCategory() {
  if(document.editDetail.general_route_id) {
    var genRouteSel = document.editDetail.general_route_id;
    genRouteSel.options[genRouteSel.options.length]= new Option("","0",false,true);
  }
  if(document.editDetail.route_id) {
    var routeSel = document.editDetail.route_id;
    routeSel.options[routeSel.options.length]= new Option("","0",false,true);
  }
  document.editDetail.submit();
}
function changeRoute() {
  document.editDetail.submit();
}
</script>
<?php
/*
  route select menu
*/
echo "<form method=\"post\" name=\"editDetail\">";
echo "<select name='category' onchange='changeCategory()'>";
foreach($categories as $val) {
  $opt = $val['id']==$selectedCategoryID? " selected ":"";
  echo "<option value='". $val['id'] . "' ${opt}>" . $val['name'] . "</option>";
}
echo "</select><br>";
if(isset($general_routes)) {
  echo "<select name='general_route_id' onchange='changeGenRoute()'>";
  foreach($general_routes as $val) {
    $opt = $val['id']==$selectedGeneralRouteID? " selected ":"";
    echo "<option value='". $val['id'] . "' ${opt}>". $val['name'] . "</option>";
  }
  echo "</select><br>";
}
if(isset($routes)) {
  echo "<select name='route_id' onchange='changeRoute()'>";
  foreach($routes as $val) {
    $opt = $val['id']==$selectedRouteID? " selected ":"";
    echo "<option value='".$val['id'] . "' ${opt}>" .$val['name'] . "</option>";
  }
  echo "</select>";
}
echo "<input type='submit' value='"._AD_BM_SUBMIT . "'/>";
echo "</form>";


if(!$selectedRouteID) {
  include_once(XOOPS_ROOT_PATH."/footer.php");
  return;
}
?>