}
                } catch (Exception $e) {
                    $dao->rollback_trans();
                    $smarty->assign('message', 'DBエラーで失敗しました。');
                }
                $id = $forms['id'];
            }
            $phase = 'complete';
        } else {
            $phase = 'input';
        }
    }
}
$categorydao = new Class_mp_service_category();
$sql = "select * from mp_service_category";
$categorydata = $categorydao->get_rows($sql);
if (isset($categorydata)) {
    $smarty->assign('categorydata', $categorydata);
}
if (isset($forms)) {
    $smarty->assign('forms', $forms);
}
if (isset($err_mes)) {
    $smarty->assign('err', $err_mes);
}
if (isset($service_forms)) {
    $smarty->assign('forms', $service_forms);
}
$smarty->assign('phase', $phase);
$smarty->assign('menu', $smarty->fetch('menu.html'));
$smarty->assign('footer', $smarty->fetch('footer.html'));
<?php

require_once '../system/smarty.inc';
require_once '../system/mdao/Class_mp_service_category.php';
require_once '../system/Class_ERROR.php';
require_once '../system/login.inc.php';
require_once '../system/prego_m.php';
$dao = new Class_mp_service_category();
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $phase = 'input';
    // get category data
    $sql = "select * from mp_service_category";
    $forms = $dao->get_rows($sql);
} else {
    $forms = $_POST;
    // set $forms['mutirow'] array
    if (isset($forms['category_id'])) {
        foreach ($forms['category_id'] as $k => $v) {
            $forms['mutirow'][] = array("id" => $v, "category_name" => $forms['category_name'][$k]);
        }
    }
    if ($forms['mode'] == 'input') {
        // check $forms['mutirow'] items
        $err = new Class_ERROR();
        $index = 0;
        $category_chk = $dao->get_checks();
        foreach ($forms['mutirow'] as $k => $v) {
            $err_mes['category_name'][$index] = $err->check($v['category_name'], $category_chk['category_name']);
            $index = $index + 1;
        }
        // verification check
<?php

require_once '../system/smarty.inc';
require_once '../system/mdao/Class_mp_service_category.php';
$dao = new Class_mp_service_category();
$sql = "select * from mp_service_category";
$data = $dao->get_rows($sql);
if (isset($data)) {
    $smarty->assign('data', $data);
}
$smarty->display('popup_category_select.html');
        $spec_id = $_GET['sid'];
        $sql = "select * from mp_spec_fee where spec_id = '{$spec_id}' ";
        $spec_data = $spec_fee_dao->get_rows($sql);
        $wherearr = array();
        $service_id_arr = array();
        foreach ($spec_data as $k => $v) {
            $service_each_id = $v['service_id'];
            $service_id_arr[] = "id = '{$service_each_id}' ";
        }
        $service_where = implode(' OR ', $service_id_arr);
        $wherearr[] = "( {$service_where} )";
        $service_data = $service_dao->search($wherearr);
        $category_data = array();
        $category_id_temp = array();
        foreach ($service_data as $k => $v) {
            if (!in_array($v['category_id'], $category_id_temp)) {
                $category_id_temp[] = $v['category_id'];
                $category_id = $v['category_id'];
                $category_data[] = $category_dao->get($category_id);
            }
        }
    } else {
        $service_sql = "select * from mp_service";
        $service_data = $service_dao->get_rows($service_sql);
        $category_sql = "select * from mp_service_category";
        $category_data = $category_dao->get_rows($category_sql);
    }
}
$smarty->assign('category_data', $category_data);
$smarty->assign('service_data', $service_data);
$smarty->display('popup_service_master.html');