$xml = simplexml_load_file('works_list.xml');
$cat = htmlspecialchars(strip_tags($_GET['category']));
$id = htmlspecialchars(strip_tags($_GET['id']));
if($id == ""){
$mode = "index";
foreach ($xml->category as $category) {
if($cat == convert($category{"dir"})){
$history_here = convert($category{"name"});
}
}
} else {
$mode = "list";
foreach ($xml->category as $category) {
if($cat == convert($category{"dir"})){
$history_parent = convert($category{"name"});
foreach ($category->product as $product) {
if($id == convert($product{"id"})){
$history_here = convert($product{"name"});
}
}
}
}
}
?>
if($mode == "index"){ ?>
foreach ($xml->category as $category) {
if($cat == convert($category{"dir"})){
$item = $category;
$item = (array)$item;
$product_arr = (array)$item{'product'};
$tmp = array();
foreach ($product_arr as $v) $tmp[] = $v['year'];
array_multisort($tmp, SORT_DESC, SORT_NUMERIC, $product_arr);
foreach ($product_arr as $product) {
$product_name = convert($product{"name"});
$product_id = convert($product{"id"});
$product_year = convert($product{"year"});
$product_imgnum = convert($product{"num"});
if($product_imgnum > 3){
$imgnum = 3;
} else {
$imgnum = $product_imgnum;
}
print <<
{$product_name}
{$product_year}年
end_of_xml;
for($i = 0; $i < $imgnum; $i++){
$number = sprintf('%02d', $i + 1);
print("
\n");
}
print <<
end_of_xml;
}
}
}
?>
} else if($mode == "list") { ?>
foreach ($xml->category as $category) {
if($cat == convert($category{"dir"})){
foreach ($category->product as $product) {
if($id == convert($product{"id"})){
$product_name = convert($product{"name"});
$product_id = convert($product{"id"});
$product_year = convert($product{"year"});
print <<
{$product_name}
{$product_year}年
end_of_xml;
for($i = 0; $i < $product{"num"}; $i++){
$number = sprintf('%02d', $i + 1);
print("
\n");
}
print <<