<?php

/**
 * kabuu dx pickup
 */
require_once "/var/www/tool/kabuu/kabu_db_def.php";
require_once "dx_def_kabu.php";
date_default_timezone_set('Asia/Tokyo');
ini_set('display_errors', "On");
// /kabuu/dx.php?name=7897&type=chart

// メニュー
$get_name = isset($_GET['type']) ? $_GET['type'] : '';
// muneのカテゴリ→name
// codeも入ってる
$nowid = isset($_GET['name']) ? $_GET['name'] : '';

// 検索
$code = isset($_GET['code']) ? $_GET['code'] : 0;
// ednet
$docid = isset($_GET['docid']) ? $_GET['docid'] : 0;
$doctype = isset($_GET['doctype']) ? $_GET['doctype'] : 0;
// 空売り機関
$karacrop = isset($_GET['karacrop']) ? $_GET['karacrop'] : 0;

// https://bttb.jp/kabu/?type=chart&name=2769
// chartの場合
if ($get_name == "chart") {
  $get_name = "";
  $code = $nowid;
}


// javasript対策をする必要がある
// 検索と個別銘柄の表示
if ($code != "0") {
  $arr = [];
  $arr[] = $code;
  $arr[] = "%{$code}%";
  $arr[] = "%{$code}%";
  $sql = "SELECT * FROM `kabu` WHERE id = ? or (`name` LIKE ? or `name_public` LIKE ?)";

  // $sql = "  select * from kabu where id = ?";
  $err_check = pdo_db($sql, $arr);
  if (empty($err_check)) {
    // ヒットしない
    $code = htmlspecialchars($code);
    echo "検索対象外になります。\n";

    $arr = [];
    $arr[] = "%{$code}%";
    $arr[] = "%{$code}%";
    $sql = "SELECT * FROM `kabu` WHERE (`name` LIKE ? or `name_public` LIKE ?)";
    $err_check = pdo_db($sql, $arr);
    if (!empty($err_check)) {
      foreach ($err_check as $row) {
        echo "{$code}は、{$row['id']}：{$row['name']}がヒットします\n";
      }
    }
    exit;
  } else {
    $code = $err_check[0]['id'];
  }
}

// 初期メニュー
if ($get_name == "" && $nowid == "") {
  $get_name = "TDnet";
  $nowid = "tdnet";
}


$chart_json = "";
$chart_json2 = "";

/**
 * ★ここから処理１
 */
if ($code != 0) {
  // 検索と個別銘柄chartのsqlを設定
  // この場合に、nameにcodeが入ってくる

  $menus['chart'][$code]['title'] = "{$code}";
  $menus['chart'][$code]['overview'] = "{$code}";
  $menus['chart'][$code]['sql'] = <<<EOL
  select 
  intdate,
  p_st,
  p_max,
  p_min,
  p_ed,
  dd,
  pdiff as diff,
  per_bp,
  per_pp,
  per_bd,
  upv,
p5days,
p10days,
p20days,

  per_pp_1,
  per_pp_5,
  per_pp_20,
  per_tmax,
  per_tmin
  from kabu_day 
  where kabu_id = '{$code}' and intdate >= {$intdate30} 
  order by intdate
EOL;
  $menus['chart'][$code]['sql_list'] = <<<EOL
select 
intdate,
p_st,
p_max,
p_min,
p_ed,
dd,
pdiff as diff,
per_bp,
per_pp,
per_bd,
upv,
p5days,
p10days,
p20days,

per_pp_1,
per_pp_5,
per_pp_20,
per_tmax,
per_tmin
from kabu_day 
where kabu_id = '{$code}' and intdate >= {$intdate30} 
order by intdate desc
EOL;
  // 現在地のメニューを示す
  $nowid = $code;
}


/**
 * メニュー作成
 */
$ul = "";
$icon = [];
$icon['TDnet'] = "fa-regular fa-newspaper";
$icon['EDINET'] = "fa-regular fa-folder-open";
$icon['short'] = "fa-regular fa-thumbs-down";
// $icon['new'] = "fa-regular fa-envelope-open";
$icon['watch'] = "fa-solid fa-battery-full";

$icon['logic'] = "fa-solid fa-signal";
$icon['pickup'] = "fa-solid fa-check";
$icon['Verify'] = "fa-regular fa-chart-bar";
$icon['銘柄'] = "fa-solid fa-users";
$icon['管理'] = "fa-regular fa-envelope-open";
$icon['chart'] = "fa-regular fa-envelope-open";
// https://fontawesome.com/search?p=12&o=r&m=free

foreach ($menus as $type => $m1) {
  // open
  if ($type == $get_name) {
    $ul .= "<li class=\"nav-item menu-is-opening menu-open\">";
  } else {
    $ul .= "<li class=\"nav-item\">";
  }

  if (!empty($icon[$type])) {
    $ul .= "<a href=\"#\" class=\"nav-link\"><i class=\"nav-icon fas {$icon[$type]}\"></i><p>{$type}<i class=\"right fas fa-angle-left\"></i></p></a>\n";
  }

  $ul .= "<ul class=\"nav nav-treeview\">\n";
  foreach ($m1 as $name => $m) {
    $ul .= "<li class=\"nav-item\">";
    $ul .= "<a class=\"nav-link\" href=\"dx.php?type={$type}&name={$name}\"><i class=\"nav-icon far fa-circle text-danger\"></i><p class=\"text\">{$m['title']}</p></a></li>\n";
  }
  $ul .= "</ul>\n";
  $ul .= "</li>\n";
}

// htmlのpage title
if (!empty($get_name) && !empty($menus[$get_name][$nowid]['title'])) {
  $htmtitle = "{$get_name}--{$menus[$get_name][$nowid]['title']}";
} else {
  $htmtitle = "{$get_name}";
}



/***************************************************
 * ★メニュー別に処理がある
 * edinet
 * Heatmap
 * 空売り機関
 * 通常list
 * 個別銘柄chart
 * h3タイトル
 * title
 */

$Sector33 = [];

if ($get_name == "EDINET" && !empty($docid)) {
  /**
   * edinet　$docid
   */
  $arr = [];
  $arr[] = $docid;

  $sql = "select * from edinet where docID = ?";
  $result_doc = pdo_db($sql, $arr);
  if (empty($result_doc)) {
    $h3 = "【EDINET:{$docid}】該当なし";
    $htmtitle = $h3;
  } else {
    $title = $result_doc[0]['docDescription'];
    $doctype = $result_doc[0]['docTypeCode'];

    $h3 = "【EDINET:{$docid}】{$title}";
    $htmtitle = $h3;
    // ココでhtmlのtableを作る（typeにより表示内容や処理内容を変える）
    $htmltable = make_edinet($docid, $doctype);
  }
} elseif ($get_name == "watch" && strpos($nowid, "Heatmap") !== false) {
  /**
   * Heatmap
   */
  if ($menus[$get_name][$nowid]['title'] == "Heatmap") {
    $h3 = "日本株ヒートマップ{$intdate}";
  } else {
    $h3 = $menus[$get_name][$nowid]['overview'];
  }


  $result = pdo_db($menus[$get_name][$nowid]['sql']);

  foreach ($result as $row) {
    $Sector33[$row['Sector33CodeName']][] = $row;
  }

  foreach ($Sector33 as $key33 => $rows) {
    $div = "<span class=\"sector33\">{$key33}</span>";
    $div  .= "<div class=\"d-flex flex-wrap\">";
    foreach ($rows as $row) {
      $div .= def_heatmap($row);
    }
    $div .= "</div>";
    $Sector33[$key33]['html'] = $div;
  }
} elseif ($get_name == "short" && !empty($karacrop)) {
  /**
   * 空売り機関の検索で、karacoopのみ
   * 0.5以下になったら報告義務がなくなるから、そのまま収束している可能性あり、再度0.5以上になると再表示
   * 消滅の報告は原則ない
   */
  $arr = [];
  $arr[] = $karacrop;

  $c = [];
  $c2 = [];
  $c3 = [];
  $c4 = [];
  // その都度、sqlを生成する
  $sql = "select strdate,kara.kabu_id,k.name,zandaka,
  REPLACE(kara.per1, '%', '') as per1,
  kara.p_st,
  kara.p_max,
  kara.p_min,
  kara.p_ed,
  kara.dd,
CASE 
    WHEN CAST(kara.per1 AS DECIMAL(10,2)) - CAST(kara.per2 AS DECIMAL(10,2)) > 0 THEN '▲' 
    ELSE '▼' END AS '',
  TRUNCATE(kara.per1 - kara.per2,2) as per
  from kara_data kara 
  inner join kabu k on k.id = kara.kabu_id
  where `karacrop` LIKE ? and kara.strdate >= '2024-03-01' 
  ORDER BY `kabu_id`,`strdate`";
  $result = pdo_db($sql, $arr);
  $htmltable = table_make($result);
  $h3 = "【空売り機関直近取引】{$karacrop}";
  // html title
  $htmtitle = $h3;
} elseif (!empty($get_name) && $code == 0) {
  /**
   * 通常list
   */
  $result = pdo_db($menus[$get_name][$nowid]['sql']);
  // DBのhtmlテーブル化（ヘッダー、リンクや色の設定）
  if (!empty($result)) {
    $htmltable = table_make($result);
    $cnttmp = count($result);
  } else {
    $cnttmp = 0;
  }
  // タイトル
  $h3 = "【{$menus[$get_name][$nowid]['title']}】{$menus[$get_name][$nowid]['overview']}-->{$cnttmp}";
  $doc = $menus[$get_name][$nowid]['doc'];
} elseif ($code != 0) {
  /**
   * 個別銘柄chart表示
   */

  $arr = [];
  $arr[] = $code;

  // 対象銘柄かどうか
  $sql = "  select * from kabu where id = ?";
  $result = pdo_db($sql, $arr);
  if (empty($result)) {
    // ヒットしない $nowidはcodeが入ってる
    $htmtitle = "{$nowid}は対象外になります。";
    $h3 = "{$menus['chart'][$nowid]['title']}--本サイトでは対象外銘柄になります。";
  } else {

    $name = $result[0]['name'];
    $corp = $result[0]['corp2'];
    $Sector33CodeName = $result[0]['Sector33CodeName'];
    $NetSales = $result[0]['NetSales'];
    $Profit = $result[0]['Profit'];
    $TotalAssets = $result[0]['TotalAssets'];
    $jika = (int)(($result[0]['p_ed'] * $result[0]['NumberOfStock']) / 1000);



    // html title
    $htmtitle = "{$nowid}--{$name}";

    // 機関空売り
    $sql = "select 
    strdate,
    karacrop,
    zandaka,
    REPLACE(per1, '%', '') as per1,
    CASE 
    WHEN CAST(per1 AS DECIMAL(10,2)) - CAST(per2 AS DECIMAL(10,2)) > 0 THEN '▲' 
    ELSE '▼' END AS '',
    zandaka - befzandaka as zandaka_diff,
    p_st,
    p_max,
    p_min,
    p_ed,
    dd
    from kara_data where kabu_id = ? and strdate > '2024-03-01' order by strdate desc";
    $result_kara = pdo_db($sql, $arr);

    // 信用
    $sql = "  select thedate,short_all,long_all,short_n,long_n,short_s,long_s from kabu_margin where kabu_id =  ? order by thedate desc";
    $result_margin = pdo_db($sql, $arr);

    // tdnet
    $sql = "SELECT strdate,strtime,cropname,title,pdf_url
FROM tdnet where code = ?
order by strdate desc";
    $result_tdnet = pdo_db($sql, $arr);

    //edinet
    $sql = "SELECT docID,docTypeCode,submitDateTime,NameOfIssuer,filerName,docDescription 
FROM edinet where SecurityCodeOfIssuer = ? order by submitDateTime desc";
    $result_edinet = pdo_db($sql, $arr);


    /**
     * チャート(履歴処理)
     */

    $charts = [];
    $ddw = 1;
    $result = pdo_db($menus['chart'][$nowid]['sql']);


    $htmltable = table_make($result);

    $dd = 0;
    $pdd = 0;
    foreach ($result as $id => $row) {
      if ($dd < $row['dd']) {
        $dd = $row['dd'];
      }
      $pdd = $row['p_ed'];
    }

    $ddw = strlen($dd) - strlen($pdd) + 1;
    // echo "{$dd}--{$pdd}--{$ddw}";
    $wari = str_pad(1, $ddw, 0, STR_PAD_RIGHT);



    foreach ($result as $id => $row) {
      $yy =  str_replace("2025", "", $row['intdate']);
      $dd = $row['dd'] / $wari;

      $c[] = "['{$yy}',{$row['p_min']},{$row['p_st']},{$row['p_ed']},{$row['p_max']}]";
      $c2[] = "['{$yy}',{$row['p_min']},{$row['p_st']},{$row['p_ed']},{$row['p_max']},{$dd}]";
      $c3[] = "['{$yy}',{$row['p_min']},{$row['p_max']},{$dd}]";
      // $c4[] = "['{$yy}',{$row['bp']},{$row['pp']},{$row['pp_1']},{$row['tmax']},{$row['tmin']}]";
    }

    // タイトル
    $link = "--<a class=\"\" href=\"https://finance.yahoo.co.jp/quote/{$nowid}.T\"  target=\"_blank\">Yahoo</a>";

    $h3 = "{$menus['chart'][$nowid]['title']}--{$name}-【{$Sector33CodeName}】{$corp}";

    $h3sub = "売上高:{$NetSales}-当期純利益:{$Profit}-総資産:{$TotalAssets}-時価:{$jika}--{$link}";


    $result = pdo_db($menus['chart'][$nowid]['sql_list']);

    //html作成 
    $tdnettable = table_make($result_tdnet);
    $edinettable = table_make($result_edinet);


    $karatable = table_make($result_kara);
    $margintable = table_make($result_margin);

    // 先頭なし/ローソク足
    $ccc = implode(",", $c);
    $chart_json = "[{$ccc}]";

    // 先頭タイトル
    $ccc = implode(",", $c2);
    $chart_json2 = "[ ['本数', '安値', '初値', '終値', '高値', '出来高'],{$ccc}]";

    $c3a = implode(",", $c3);
    $chart_json2 = "[ ['本数','安値', '高値', '出来高'],{$c3a}]";
  }
} else {
  echo "{$get_name}--{$code}";
}



/**
 * ednetのsqlとhtmlの作成
 */
function make_edinet($docid, $doctype)
{
  // table_makeの前処理
  $sql = "";
  $arr = [];
  $arr[] = $docid;
  if ($doctype == 350 || $doctype == 360) {
    $sql = "select docTypeCode,item2x,item0x,item8 from edinet_body 
    where docID = ? and flag = 1
    order by item2x,item0x";
  } elseif ($doctype > 100 && $doctype < 180) {
    // FS cateidとsortが必要になる
    $sql = "select 	docTypeCode,cate_id,cate_sort as sss,item1,item8 from edinet_body 
    where docID = ? and flag = 1 
    order by cate_id,cate_sort";
  } else {
    $sql = "select 	item1,item8
    from edinet_body 
    where docID = ? and flag = 1
    order by id";
  }
  
  $sql = "select  `id`, `docID`, `docTypeCode`, `cate_id`,`item0`, `item1`, `item8`  from edinet_body where docID = ? order by id";
  $result = pdo_db($sql, $arr);

  $html = table_make($result);
  

  // // table_make処理
  // if ($doctype == 350 || $doctype == 360) {
  //   // 大量報告書
  //   // item2xとitem0xを利用している、item0ではない
  //   $tmp = [];
  //   foreach ($result as $row) {
  //     $tmp[$row['item2x']][$row['item0x']] = $row['item8'];
  //   }
  //   $html = table_make_350($tmp);
  // } elseif ($doctype == 120 || $doctype == 140) {
  //   // FSは、値をcate_idでグループ配列化して、そのカテゴリごとにtableを表示
  //   $tmp = [];
  //   foreach ($result as $row) {
  //     $tmp[$row['cate_id']][$row['item1']] = $row['item8'];
  //   }
  //   $html = table_make_120($tmp);
  // } else {
  //   // 臨時報告書、自己株買い付け
  //   // $html = table_make($result);
  //   $html = table_make_edinet($result);
  // }

  return $html;
}



function table_make($result)
{
  // たんなる定義
  $defkeys = [];
  $defkeys['p_st'] = ['name' => "初値", 'format' => '1'];
  $defkeys['p_max'] =  ['name' => "高値", 'format' => '1'];
  $defkeys['p_min'] =  ['name' => "安値", 'format' => '1'];
  $defkeys['p_ed'] =  ['name' => "終値", 'format' => '1'];
  $defkeys['dd'] =  ['name' => "出来高", 'format' => '1'];
  $defkeys['dp'] =  ['name' => "売買代金", 'format' => '1'];
  $defkeys['diff'] =  ['name' => "前日比", 'format' => '1'];
  $defkeys['p_st1'] =  ['name' => "翌日初値", 'format' => '1'];
  $defkeys['ed1'] =  ['name' => "翌日終値", 'format' => '1'];
  $defkeys['max20'] =  ['name' => "直近高値", 'format' => '1'];
  $defkeys['min20'] =  ['name' => "直近安値", 'format' => '1'];
  $defkeys['zandaka'] =  ['name' => "残高", 'format' => '1'];
  $defkeys['zandaka_diff'] =  ['name' => "増減", 'format' => '1'];

  $defkeys['short_all'] =  ['name' => "short", 'format' => '1'];
  $defkeys['long_all'] =  ['name' => "long", 'format' => '1'];

  $defkeys['dp1'] =  ['name' => "売買代金", 'format' => '1'];
  $defkeys['dp3'] =  ['name' => "売買代金3日平均", 'format' => '1'];
  $defkeys['dp5'] =  ['name' => "売買代金5日平均", 'format' => '1'];
  $defkeys['dp10'] =  ['name' => "売買代金10日平均", 'format' => '1'];

  $defkeys['strdate'] =  ['name' => "報告日", 'format' => '0'];
  $defkeys['karacrop'] =  ['name' => "空売り機関", 'format' => '0'];
  $defkeys['kabu_id'] =  ['name' => "コード", 'format' => '0'];
  $defkeys['name'] =  ['name' => "銘柄", 'format' => '0'];
  $defkeys['cropname'] =  ['name' => "銘柄", 'format' => '0'];
  $defkeys['title'] =  ['name' => "タイトル", 'format' => '0'];
  $defkeys['id'] =  ['name' => "コード", 'format' => '0'];
  $defkeys['corp'] =  ['name' => "特色", 'format' => '0'];
  $defkeys['ppt'] =  ['name' => "セグメント", 'format' => '0'];

  $defkeys['per_bp'] =  ['name' => "価格比", 'format' => '0'];
  $defkeys['per_pp'] =  ['name' => "終/初値", 'format' => '0'];
  $defkeys['per_bd'] =  ['name' => "出来比", 'format' => '0'];
  $defkeys['per_pp_5'] =  ['name' => "5率", 'format' => '0'];
  $defkeys['per_pp_20'] =  ['name' => "10率", 'format' => '0'];
  $defkeys['per_tmax'] =  ['name' => "MAX20", 'format' => '0'];
  $defkeys['per_tmin'] =  ['name' => "MIN20", 'format' => '0'];
  $defkeys['per1'] =  ['name' => "割合", 'format' => '0'];

  $defkeys['Sector33CodeName'] =  ['name' => "セクタ", 'format' => '0'];
  $defkeys['befdate'] =  ['name' => "前回報告日", 'format' => '0'];
  $defkeys['item1'] =  ['name' => "タイトル", 'format' => '0'];
  $defkeys['item8'] =  ['name' => "内容", 'format' => '0'];
  $defkeys['filerName'] =  ['name' => "提出者", 'format' => '0'];
  $defkeys['docDescription'] =  ['name' => "報告書", 'format' => '0'];
  $defkeys['NameOfIssuer'] =  ['name' => "企業名", 'format' => '0'];
  $defkeys['submitDateTime'] =  ['name' => "報告日時", 'format' => '0'];
  $defkeys['docTypeCode'] =  ['name' => "docType", 'format' => '0'];

  $defkeys['p5days'] =  ['name' => "5%s", 'format' => '0'];
  $defkeys['p10days'] =  ['name' => "10%s", 'format' => '0'];
  $defkeys['p20days'] =  ['name' => "20%s", 'format' => '0'];

  // 長い文字列優先でマッチ
  $defkeys['short_n'] =  ['name' => "一般信用売残", 'format' => '1'];
  $defkeys['long_n'] =  ['name' => "一般信用買残", 'format' => '1'];
  $defkeys['short_s'] =  ['name' => "制度信用売残", 'format' => '1'];
  $defkeys['long_s'] =  ['name' => "制度信用買残", 'format' => '1'];
  $defkeys['short'] =  ['name' => "売残合計", 'format' => '1'];
  $defkeys['long'] =  ['name' => "買残合計", 'format' => '1'];

  $defkeys['kabu_type'] =  ['name' => "logic", 'format' => '0'];


  $defkeys['出来高'] =  ['name' => "出来高", 'format' => '1'];
  $defkeys['信用'] =  ['name' => "信用", 'format' => '1'];
  $defkeys['売上'] =  ['name' => "売上", 'format' => '1'];
  $defkeys['営利'] =  ['name' => "営利", 'format' => '1'];
  $defkeys['当利'] =  ['name' => "当利", 'format' => '1'];
  $defkeys['1株利'] =  ['name' => "1株利", 'format' => '1'];
  $defkeys['現金'] =  ['name' => "現金", 'format' => '1'];
  $defkeys['総資産'] =  ['name' => "総資産", 'format' => '1'];
  $defkeys['純資産'] =  ['name' => "純資産", 'format' => '1'];
  $defkeys['資比率'] =  ['name' => "資比率", 'format' => '1'];
  $defkeys['1株資'] =  ['name' => "1株資", 'format' => '1'];
  $defkeys['発行株式数'] =  ['name' => "発行株式数", 'format' => '1'];
  $defkeys['自己株式'] =  ['name' => "自己株式", 'format' => '1'];


  $html = "<table class=\"table table-striped table-sm\">";


  $code2 = [];
  $cnt = 0;
  foreach ($result as $row) {
    if ($cnt == 0) {
      $html .= "<thead>\n<tr>";
      foreach ($row as $key => $v) {
        if ($key == "pdf_url") {
        } elseif ($key == "url") {
        } elseif ($key == "item8") {
          $html .= "<th width=\"800\">" . def_key($defkeys, $key) . "</th>";
        } else {
          $html .= "<th>" . def_key($defkeys, $key) . "</th>";
        }
      }
      $html .= "</tr>\n</thead>\n<tbody>";
      $cnt = 1;
    }

    if (!empty($row["kabu_id"])) {
      if (empty($code2[$row["kabu_id"]])) {
        $code2[$row["kabu_id"]] = $row["kabu_id"];
      } else {
        continue;
      }
    }
    $htmltd = "";
    $trflag = 0;
    foreach ($row as $key => $v) {
      if ($key == "id" || $key == "kabu_id") {
        // $htmltd .= "<td> <a class=\"\" href=\"https://finance.yahoo.co.jp/quote/{$v}.T/history/download\">$v</td>";
        $htmltd .= "<td> <a class=\"\" href=\"dx.php?code={$v}\" target=\"_blank\">$v</a></td>";
      } elseif ($key == "y") {
        $htmltd .= "<td> <a class=\"\" href=\"https://finance.yahoo.co.jp/quote/{$v}.T\" target=\"_blank\">Y</a></td>";
      } elseif ($key == "karacrop") {
        $htmltd .= "<td> <a class=\"\" href=\"dx.php?type=short&karacrop={$v}\" target=\"_blank\">$v</a></td>";
      } elseif ($key == "siteurl") {
        $htmltd .= "<td> <a class=\"\" href=\"{$v}\" target=\"_blank\">{$v}</a></td>";
      } elseif (strpos($key, "per") !== false) {
        // %の赤色表示
        if ($v > 100) {
          $htmltd .= "<td>" . nl2br($v) . "%</td>";
        } else {
          $htmltd .= "<td>" . nl2br($v) . "%</td>";
          // $htmltd .= "<td><span style=\"color:#ff0000;\">" . nl2br($v) . "%</span></td>";
        }
      } elseif ($key == "pdiff") {
        if ($v > 0) {
          $htmltd .= "<td><span style=\"color:#ff0000;\">" . nl2br($v) . "</span></td>";
        } else {
          $htmltd .= "<td>" . nl2br($v) . "</td>";
        }
      } elseif ($key == "tmax") {
        if ($v < 80) {
          $htmltd .= "<td><span style=\"color:#ff0000;\">" . nl2br($v) . "</span></td>";
        } else {
          $htmltd .= "<td>" . nl2br($v) . "</td>";
        }
      } elseif ($key == "tmin") {
        if ($v < 130) {
          $htmltd .= "<td><span style=\"color:#ff0000;\">" . nl2br($v) . "</span></td>";
        } else {
          $htmltd .= "<td>" . nl2br($v) . "</td>";
        }
      } elseif (!empty($key) && mb_strpos("個人,海外,証券,自己,委託,投信,信託,事業,生保,銀行", $key, 0, "UTF-8") !== false) {
        if ($v < 0) {
          $htmltd .= "<td><span style=\"color:#ff0000;\">" . nl2br($v) . "</span></td>";
        } else {
          $htmltd .= "<td>" . nl2br($v) . "</td>";
        }
      } elseif ($key == "docID") {
        // $htmltd .= "<td> <a class=\"\" href=\"dx.php?type=EDINET&docid={$v}&doctype={$row['docTypeCode']}\">{$v}</a></td>";
        $htmltd .= "<td> <a class=\"\" href=\"dx.php?type=EDINET&docid={$v}\">{$v}</a></td>";
      } elseif ($key == "title") {
        $htmltd .= "<td> <a class=\"\" href=\"{$row['pdf_url']}\">{$v}</a></td>";
      } elseif ($key == "site_title") {
        $htmltd .= "<td> <a class=\"\" href=\"{$row['url']}\">{$v}</a></td>";
      } elseif ($key == "upv") {
        $v = def_upv($v);
        $htmltd .= "<td>" . nl2br($v) . "</td>";
      } elseif ($key == "pdf_url") {
      } elseif ($key == "url") {
      } elseif ($key == "item8") {
        $v = disp_item8($v);
        $htmltd .= "<td>" . nl2br($v) . "</td>";
      } else {
        $v = def_sankaku($v);

        if (def_kanma($defkeys, $key, $v) === false) {
          $htmltd .= "<td>" . nl2br($v) . "</td>";
        } else {
          $v = def_kanma($defkeys, $key, $v);
          $htmltd .= "<td class=\"number\">" . nl2br($v) . "</td>";
        }
      }
    }
    if ($trflag == 1) {
      $html .= "<tr class=\"trflag\">" . $htmltd . "</tr>";
    } else {
      $html .= "<tr>" . $htmltd . "</tr>";
    }
  }
  $html .= "</tbody>\n</table>";
  return ($html);
}

function table_make_edinet($result)
{
  // たんなる定義
  $defkeys = [];
  $defkeys['item1'] =  ['name' => "タイトル", 'format' => '0'];
  $defkeys['item8'] =  ['name' => "内容", 'format' => '0'];

  $html = "<table class=\"table table-striped table-sm\">";

  $cnt = 0;
  foreach ($result as $row) {
    if ($cnt == 0) {
      $html .= "<thead>\n<tr>";
      foreach ($row as $key => $v) {
        if ($key == "item8") {
          $html .= "<th width=\"800\">" . def_key($defkeys, $key) . "</th>";
        } else {
          $html .= "<th>" . def_key($defkeys, $key) . "</th>";
        }
      }
      $html .= "</tr>\n</thead>\n<tbody>";
      $cnt = 1;
    }

    $htmltd = "";
    // print_r($row);
    // [item1] => 証券コード、DEI
    $berlabel = "";
    foreach ($row as $key => $v) {
      if ($key == "item8") {

        if (mb_strrpos($berlabel, "コード") !== false) {
        } else {
          $v = disp_item8($v);
        }


        $htmltd .= "<td>" . nl2br($v) . "</td>";
      } else {
        // item1の項目ラベル
        $htmltd .= "<td>" . nl2br($v) . "</td>";
        $berlabel = $v;
      }
    }
    $html .= "<tr>" . $htmltd . "</tr>";
  }
  $html .= "</tbody>\n</table>";
  return ($html);
}

/**
 * 大量報告書
 */
function table_make_350($tmp)
{

  $html = "";
  foreach ($tmp as $key => $row2) {
    if ($key == "Date") {
      // 企業名
      $SecurityCodeIssuer = $row2['SecurityCodeIssuer'];
      $NameIssuer = $row2['NameIssuer'];

      $html .= "<table class=\"table table-striped table-sm\">\n";
      $html .= "<tr><td>証券コード</td><td width=\"80%\"><a class=\"\" href=\"dx.php?code={$row2['SecurityCodeIssuer']}\" target=\"_blank\">{$row2['SecurityCodeIssuer']}</td></tr>\n";

      $html .= "<tr><td>対象企業名</td><td width=\"80%\">{$row2['NameIssuer']}</td></tr>\n";
      if (!empty($row2['TotalNumberOutstandingStocksEtc'])) {
        $html .= "<tr><td>株式総数</td><td width=\"80%\">{$row2['TotalNumberOutstandingStocksEtc']}</td></tr>\n";
      }
      $html .= "</tbody>\n</table>\n";
      $html .= "<hr>\n";
    } else {

      $html .= "<table class=\"table table-striped table-sm\">\n";
      // $html .= "<tr><td>コード</td><td width=\"70%\">{$row2['SecurityCode']}</td></tr>\n";
      if (!empty($row2['NameJapanese'])) {
        $html .= "<tr><td>報告者</td><td width=\"80%\">{$row2['NameJapanese']}({$row2['Code']})</td></tr>\n";
      }
      // if (!empty($row2['TotalNumberOutstandingStocksEtc'])) {
      //   $html .= "<tr><td>株式総数</td><td width=\"80%\">{$row2['TotalNumberOutstandingStocksEtc']}</td></tr>\n";
      // }
      if (!empty($row2['TotalNumberStocksEtcHeld'])) {
        $html .= "<tr><td>保有株総数</td><td width=\"80%\">{$row2['TotalNumberStocksEtcHeld']}</td></tr>\n";
      }
      if (!empty($row2['HoldingRatioShareCertificatesEtc'])) {

        $html .= "<tr><td>割合</td><td width=\"80%\">{$row2['HoldingRatioShareCertificatesEtc']}%</td></tr>\n";
      }
      if (!empty($row2['HoldingRatioShareCertificatesEtcPerLastReport'])) {
        $diff = $row2['HoldingRatioShareCertificatesEtc'] - $row2['HoldingRatioShareCertificatesEtcPerLastReport'];

        $html .= "<tr><td>割合直前</td><td width=\"80%\">{$row2['HoldingRatioShareCertificatesEtcPerLastReport']}% ({$diff}%)</td></tr>\n";
      }
      if (!empty($row2['PurposeHolding'])) {
        $html .= "<tr><td>目的</td><td width=\"80%\">{$row2['PurposeHolding']}</td></tr>\n";
      }
      // 追加
      if (!empty($row2['TotalAmountFundingAcquisition'])) {
        $one = floor($row2['TotalAmountFundingAcquisition'] / $row2['TotalNumberStocksEtcHeld']);
        $html .= "<tr><td>取得資金合計</td><td width=\"80%\">{$row2['TotalAmountFundingAcquisition']}（1株取得単価：{$one}円）</td></tr>\n";
      }
      if (!empty($row2['AmountOwnFund'])) {
        $html .= "<tr><td>自己資金</td><td width=\"80%\">{$row2['AmountOwnFund']}</td></tr>\n";
      }
      // if (!empty($row2['NamesEtcCreditors'])) {
      //   $html .= "<tr><td>借入先の名称等</td><td width=\"80%\">{$row2['NamesEtcCreditors']}</td></tr>\n";
      // }
      if (!empty($row2['BreakdownBorrowings'])) {
        $v = $row2['BreakdownBorrowings'];
        $v = str_replace("②【借入金の内訳】", "", $v);
        $v = str_replace("名称（支店名）", "", $v);
        $v = str_replace("業種代表者氏名所在地借入目的金額", "", $v);
        $v = str_replace("（千円）", "", $v);

        $html .= "<tr><td>借入金の内訳</td><td width=\"80%\">{$v}</td></tr>\n";
      }
      if (!empty($row2['SignificantContractsRelatedToSaidStocksEtcSuchAsCollateralAgreements'])) {
        $v = $row2['SignificantContractsRelatedToSaidStocksEtcSuchAsCollateralAgreements'];
        $v = str_replace("(4)【当該株券等に関する担保契約等重要な契約】", "", $v);
        $html .= "<tr><td>担保契約等重要な契約</td><td width=\"80%\">{$v}</td></tr>\n";
      }


      $v = "";
      if (!empty($row2['AcquisitionsDisposalsStocksEtcIssuedIssuerSaidStocksEtcDuringLastDays'])) {
        $v = $row2['AcquisitionsDisposalsStocksEtcIssuedIssuerSaidStocksEtcDuringLastDays'];
        $v = str_replace("（５）【当該株券等の発行者の発行する株券等に関する最近60日間の取得又は処分の状況】", "", $v);

        $v = str_replace("年月日株券等の種類数量割合市場内外取引の別取得又は処分の別単価", "", $v);
        $v = str_replace("年月日", "", $v);
        $v = str_replace("株券等の種類", "", $v);
        $v = str_replace("数量", "", $v);
        $v = str_replace("割合", "", $v);
        $v = str_replace("市場内外取引の別", "", $v);
        $v = str_replace("取得又は処分の別", "", $v);
        $v = str_replace("単価", "", $v);



        $v = str_replace("令和", "<br>令和", $v);
        $v = str_replace("2021年", "<br>2021年", $v);
        $v = str_replace("2022年", "<br>2022年", $v);
        $v = str_replace("2023年", "<br>2023年", $v);
        $v = str_replace("2024年", "<br>2024年", $v);
        $v = NumbersRaito($v);
      }
      $html .= "<tr><td>取得又は処分の状況</td><td width=\"80%\">{$v}</td></tr>\n";

      $html .= "</tbody>\n</table>\n";
      $html .= "<hr>\n";
    }
  }
  return ($html);
}

function NumbersRaito($input)
{
  // 「,数字4桁.」のパターンを「,数字3桁 1桁.」に変換
  $pattern4 = '/(\d{4})\./';
  $replacement4 = function ($matches) {
    return substr($matches[1], 0, 3) . ' -  ' . substr($matches[1], 3) . '.';
  };
  $input = preg_replace_callback($pattern4, $replacement4, $input);

  // 「,数字5桁.」のパターンを「,数字3桁 2桁.」に変換
  $pattern5 = '/(\d{5})\./';
  $replacement5 = function ($matches) {
    return substr($matches[1], 0, 3) . ' - ' . substr($matches[1], 3) . '.';
  };
  $input = preg_replace_callback($pattern5, $replacement5, $input);

  return $input;
}

/**
 * FS
 */
function table_make_120($tmp)
{

  $html = "";
  // 10	CoverPage
  if (!empty($tmp['10'])) {
    $html .= "<h3>CoverPage</h3>";
    $html .= table_make_fs($tmp['10']);
  }

  // 11	corp
  if (!empty($tmp['11'])) {
    $html .= "<h3>corp</h3>";
    $html .= table_make_fs($tmp['11']);
  }

  // 21	Employees
  if (!empty($tmp['21'])) {
    $html .= "<h3>Employees</h3>";
    $html .= table_make_fs($tmp['21']);
  }


  // 40	Investment
  if (!empty($tmp['40'])) {
    $html .= "<h3>Investment</h3>";
    $html .= table_make_fs($tmp['40']);
  }

  // 50	Shareholders
  if (!empty($tmp['50'])) {
    $html .= "<h3>Shareholders</h3>";
    $html .= table_make_fs($tmp['50']);
  }


  // 51	Shareholders2自己株式
  if (!empty($tmp['51'])) {
    $html .= "<h3>Shareholders2</h3>";
    $html .= table_make_fs($tmp['51']);
  }



  // 60	Audit　単体と連結があるNon=1
  if (!empty($tmp['60'])) {
    $html .= "<h3>Audit</h3>";
    $html .= table_make_fs($tmp['60']);
  }


  // 60	Audit　単体と連結があるNon=1
  if (!empty($tmp['61'])) {
    $html .= "<h3>Audit1</h3>";
    $html .= table_make_fs($tmp['61']);
  }


  // 100	BS資産
  if (!empty($tmp['100'])) {
    $html .= "<h3>BS資産</h3>";
    $html .= table_make_fs($tmp['100']);
  }

  // 110	BS2負債、資本
  if (!empty($tmp['110'])) {
    $html .= "<h3>BS負債、資本</h3>";
    $html .= table_make_fs($tmp['110']);
  }

  // 200	PL
  if (!empty($tmp['200'])) {
    $html .= "<h3>PL</h3>";
    $html .= table_make_fs($tmp['200']);
  }

  // 210	PL2 包括利益、不明
  // 包括利益とは、企業の純資産の増分すべてを含む利益で、当期純利益に保有資産の含み益や含み損を織り込んだものです。
  if (!empty($tmp['210'])) {
    $html .= "<h3>PL2</h3>";
    $html .= table_make_fs($tmp['210']);
  }


  // 400	BS_ALL
  if (!empty($tmp['400'])) {
    $html .= "<h3>FS_ALL</h3>";
    $html .= table_make_fs($tmp['400']);
  }


  // 300	CF1>営業活動によるキャッシュ・フロー
  if (!empty($tmp['300'])) {
    $html .= "<h3>営業活動によるキャッシュ・フロー</h3>";
    $html .= table_make_fs($tmp['300']);
  }


  // 310	CF2財務活動によるキャッシュ・フロー
  if (!empty($tmp['310'])) {
    $html .= "<h3>財務活動によるキャッシュ・フロー</h3>";
    $html .= table_make_fs($tmp['310']);
  }


  // 320	CF3投資活動によるキャッシュ・フロー
  if (!empty($tmp['320'])) {
    $html .= "<h3>投資活動によるキャッシュ・フロー</h3>";
    $html .= table_make_fs($tmp['320']);
  }


  // 500	fs_note テキストボックス、概要や注記
  if (!empty($tmp['500'])) {
    $html .= "<h3>概要や注記</h3>";
    $html .= table_make_fs($tmp['500']);
  }

  // // 510	fs2　あいまい
  // $html .= table_make_fs($tmp['510']);
  return ($html);
}


function table_make_fs($ret)
{
  // FSはカテゴリ別にtable化して、表示する

  $html = "<table class=\"table table-striped table-sm\">\n";
  foreach ($ret as $key => $v) {

    // キーの表示、整形
    $key = str_replace("（△）", "", $key);
    $key = str_replace("（△は減少）", "", $key);
    $key = str_replace("（平成26年3月28日財規等改正後）", "", $key);

    // 値の表示、整形
    $v = disp_item8($v);

    $html .= "<tr><td>{$key}</td><td width=\"60%\">{$v}</td></tr>\n";
  }
  $html .= "</table>\n";

  return $html;
}

function disp_item8($str)
{
  // edinetのitem8は、コンテキストが入っている
  // 項目ごとに、詳細に整形する必要がある→おそらくDBでやった方がいいけど、上書きだから失敗しないようにする
  // keyとvalueがあるので、その関係で、keyで分岐して、valueを整形する

  if (is_numeric($str)) {
    $str = number_format($str);
  }
  // ①、(1),個別に文字列を用意して、置換などをする
  $str = str_replace("】", "】<br>", $str);
  $str = str_replace("(注)", "<br>(注)", $str);

  $str = str_replace("第１号議案", "<br>第１号議案", $str);
  $str = str_replace("第２号議案", "<br>第２号議案", $str);
  $str = str_replace("第３号議案", "<br>第３号議案", $str);

  $str = str_replace("(2)", "<br>(2)", $str);


  return $str;
}

function def_upv($key)
{
  // ▲▼の表示
  if ($key == 0) {
    $key = "--";
  } elseif ($key > 0) {
    // #3366FF
    $key = str_repeat("▲", $key);
    $key = "<span style=\"color:#3366FF;\">{$key}</span>";
  } elseif ($key < 0) {
    $key = $key * -1;
    $key = str_repeat("▼", $key);
    $key = "<span style=\"color:#ff0000;\">{$key}</span>";
  }
  return  $key;
}

function def_sankaku($key)
{
  // ▲▼の表示
  if ($key == "▲") {
    $key = "<span style=\"color:#3366FF;\">{$key}</span>";
  } else if ($key == "▼") {
    $key = "<span style=\"color:#ff0000;\">{$key}</span>";
  }
  return  $key;
}

function def_key($defkeys, $key)
{
  // 日本語名に変換

  if (empty($defkeys[$key])) {
    return  $key;
  } else {
    return  $defkeys[$key]['name'];
  }
}

function def_kanma($defkeys, $key, $number)
{

  // ３桁カンマ
  if (!empty($defkeys[$key]['format']) && is_numeric($number)) {
    $number = number_format($number);
    return $number;
  } else {
    return false;
  }
}


function def_heatmap($row)
{
  // heatmap
  // 色を5色にして、高いから低いで並べるのがいいね
  $per = $row['per_bp'];
  $strlen = "";
  $div = "";

  if ($per > 106) {
    $strlen = "u2";
    $intp = $row['per_bp'] - 100;
    $aheft = "<a href=\"dx.php?code={$row['kabu_id']}\" target=\"_blank\">{$row['kabu_id']}";
    //  style=\"width:40px;\"
    $intwitdh = $intp * 10;
    $div = "<div style=\"width:{$intwitdh}px;\" class=\"green_max\">{$aheft}<br>{$row['name']}<br>{$intp}%</a></div>";
  } elseif ($per > 103) {
    $strlen = "u2";
    $intp = $row['per_bp'] - 100;
    $aheft = "<a href=\"dx.php?code={$row['kabu_id']}\" target=\"_blank\">{$row['kabu_id']}";
    $div = "<div class=\"green\">{$aheft}<br>{$row['name']}<br>{$intp}%</a></div>";
  } elseif ($per > 100) {
    $strlen = "u1";
    $div = "<div class=\"green {$strlen}\"></div>";
  } elseif ($per == 0) {
  } elseif ($per <  93) {
    $strlen = "d2";
    $intp = 100 - $row['per_bp'];
    $intwitdh = $intp * 10;
    $aheft = "<a href=\"dx.php?code={$row['kabu_id']}\" target=\"_blank\">{$row['kabu_id']}";
    $div = "<div style=\"width:{$intwitdh}px;\" class=\"red_max\">{$aheft}<br>{$row['name']}<br>-{$intp}%</a></div>";
  } elseif ($per <  98) {
    $strlen = "d2";
    $intp = 100 - $row['per_bp'];
    $aheft = "<a href=\"dx.php?code={$row['kabu_id']}\" target=\"_blank\">{$row['kabu_id']}";
    $div = "<div class=\"red\">{$aheft}<br>{$row['name']}<br>-{$intp}%</a></div>";
  } elseif ($per <  100) {
    $strlen = "d1";
    $div = "<div class=\"red {$strlen}\"></div>";
  }


  return  $div;
}


?>

<!DOCTYPE html>
<html lang="ja">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>スイングトレード株式銘柄のスクリーニング「kabuu」(<?php echo $htmtitle ?>)</title>
  <meta content="Kabuu:スイングトレード用の株式相場アグリゲーターと株式銘柄のスクリーニング" name="description">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">
  <link rel="stylesheet" href="dist/css/adminlte.min.css">
  <script src="https://www.gstatic.com/charts/loader.js"></script>
  <style>
    .content {
      height: 800px;
      overflow-y: auto;
      padding: 10px;
    }

    .card {
      position: relative;
      overflow: hidden;
      overflow-x: scroll;
    }

    .fixed {
      position: fixed;
      top: 50;
      left: 0;
    }

    .x {
      margin: 5px;
      margin-left: 20px;
    }

    td.number {
      text-align: right;
      font-variant-numeric: tabular-nums;
    }

    div.red_max {
      margin: 1px;
      border: 2px solid #FF0000;

      background: #FF0000;
      color: white;
      height: 80px;
    }

    div.red {
      margin: 1px;
      border: 2px solid #400D0D;
      background: #400D0D;
      color: white;
      height: 80px;
    }

    .red a {
      color: white;
    }

    .red_max a {
      color: white;
    }

    div.green_max {
      margin: 1px;
      border: 1px solid #00552e;
      background: #00552e;
      color: white;
      height: 80px;
    }


    div.green {
      margin: 1px;
      border: 1px solid green;
      background: green;
      color: white;
      height: 80px;
    }

    .green a {
      color: white;
    }

    .green_max a {
      color: white;
    }


    .u2 {
      width: 30px;
    }

    .u1 {
      width: 10px;
      background: green;
    }

    .d1 {
      width: 10px;
      background: #400D0D;
    }

    .d2 {
      width: 30px;
    }

    .sector33 {
      font-size: 28px;
    }
  </style>
</head>

<body class="hold-transition sidebar-mini">
  <div class="wrapper">

    <!-- ---------------------------------------------------- -->
    <nav class="main-header navbar navbar-expand navbar-white navbar-light">
      <!-- Left -->
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link" data-widget="pushmenu" href="dx.php" role="button"><i class="fas fa-bars"></i></a>
        </li>
      </ul>

      <!-- Right -->
      <ul class="navbar-nav ml-auto">
        <!-- Navbar Search -->
        <li class="nav-item">
          <a class="nav-link" data-widget="navbar-search" href="dx.php" role="button">
            <i class="fas fa-search"></i>
          </a>
          <div class="navbar-search-block">
            <form class="form-inline" action="" method="get">
              <div class="input-group input-group-sm">
                <input class="form-control form-control-navbar" type="search" placeholder="コード検索" name="code" aria-label="Search">
                <div class="input-group-append">
                  <button class="btn btn-navbar" type="submit">
                    <i class="fas fa-search"></i>
                  </button>
                </div>
              </div>
            </form>
          </div>
        </li>
      </ul>
    </nav>

    <!-- ---------------------------------------------------- -->
    <aside class="main-sidebar sidebar-dark-primary elevation-4">
      <!-- Logo -->
      <a href="dx.php" class="brand-link">
        <img src="dist/img/apple-touch-icon.png" alt="Logo" class="brand-image img-circle elevation-3" style="opacity: .8">
        <span class="brand-text font-weight-light">kabuu</span>
      </a>

      <div class="sidebar">
        <nav class="mt-2 fixed">
          <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
            <?php echo $ul ?>
          </ul>
          <div class="x"><a href="dx2.php">銘柄スクリーニング機能</a></div>
          <div class="x"><a href="index.html"><i class="far fa-regular fa-envelope-open"></i>&nbsp;&nbsp;about</a></div>
        </nav>
      </div>
    </aside>

    <!-- ---------------------------------------------------- -->
    <div class="content-wrapper">

      <div class="content-header">
        <div class="container-fluid">
          <div class="row">
            <div class="col-lg-12">
              <h3 class="m-0"><?php echo $h3 ?></h3>
              <?php
              if (!empty($h3sub)) {
                echo "<p class=\"m-0\">{$h3sub}</p>";
              }
              ?>
            </div>
          </div>
        </div>
      </div>

      <!-- ---------------------------------------------------- -->
      <div class="content">
        <div class="container-fluid">
          <div class="row">
            <div class="col-lg-12">

              <?php
              if ($code != 0) {
                echo "<div id=\"chart_r\" style=\"width:100%; height:500px;\"></div>";
                echo "<div id=\"chart_o\" style=\"width: 100%; height: 500px\"></div>";
              }
              ?>

              <script>
                // 使いたいパッケージのロード、corechartパッケージを使う
                google.charts.load('current', {
                  'packages': ['corechart']
                });
                // ロード時のコールバック関数名を指定
                google.charts.setOnLoadCallback(drawChart);

                // 関数の定義
                function drawChart() {
                  // データテーブルの作成（JSON形式）
                  var data = google.visualization.arrayToDataTable(
                    <?php echo $chart_json ?>, true);

                  var options = {
                    legend: 'none',
                    bar: {
                      groupWidth: '70%'
                    }, // Remove space between bars.
                    candlestick: {
                      fallingColor: {
                        strokeWidth: 0,
                        fill: '#dcdcdc'
                      },
                      risingColor: {
                        strokeWidth: 0,
                        fill: '#FF9900'
                      } // red
                    }
                  };

                  var chart = new google.visualization.CandlestickChart(document.getElementById('chart_r'));

                  chart.draw(data, options);
                }
              </script>
              <script>
                // google.load('visualization', '1', {'packages':['corechart']});     
                google.setOnLoadCallback(drawChart2);

                // グラフの描画   
                function drawChart2() {

                  // 配列からデータの生成
                  var data = google.visualization.arrayToDataTable(
                    <?php echo $chart_json2 ?>);
                  // オプションの設定
                  var options = {
                    legend: {
                      position: 'top'
                    },
                    pointSize: 0,
                    smoothLine: true,
                    chartArea: {
                      top: 20,
                      height: "85%"
                    }

                  };

                  // 指定されたIDの要素に折れ線グラフを作成
                  var chart = new google.visualization.LineChart(document.getElementById('chart_o'));

                  // グラフの描画
                  chart.draw(data, options);
                }
              </script>

              <div class="card">
                <div class="card-body">
                  <?php
                  // ここで表示が切り替わる、上でchartがあり、下で他のlistがある
                  if (!empty($html350)) {
                    echo "{$html350['code']}--{$html350['codename']}";
                    echo "{$html350['html']}";
                  } elseif (!empty($Sector33)) {
                    echo "<div class=\"d-flex flex-wrap\">";
                    echo "<div>{$Sector33['水産・農林業']['html']}</div>\n";
                    echo "<div>{$Sector33['鉱業']['html']}</div>\n";
                    echo "<div>{$Sector33['建設業']['html']}</div>\n";
                    echo "<div>{$Sector33['食料品']['html']}</div>\n";
                    echo "<div>{$Sector33['繊維製品']['html']}</div>\n";
                    echo "<div>{$Sector33['パルプ・紙']['html']}</div>\n";
                    echo "<div>{$Sector33['化学']['html']}</div>\n";
                    echo "<div>{$Sector33['医薬品']['html']}</div>\n";
                    echo "<div>{$Sector33['石油･石炭製品']['html']}</div>\n";
                    echo "<div>{$Sector33['ゴム製品']['html']}</div>\n";
                    echo "<div>{$Sector33['ガラス･土石製品']['html']}</div>\n";
                    echo "<div>{$Sector33['鉄鋼']['html']}</div>\n";
                    echo "<div>{$Sector33['非鉄金属']['html']}</div>\n";
                    echo "<div>{$Sector33['金属製品']['html']}</div>\n";
                    echo "<div>{$Sector33['機械']['html']}</div>\n";
                    echo "<div>{$Sector33['電気機器']['html']}</div>\n";
                    echo "<div>{$Sector33['輸送用機器']['html']}</div>\n";
                    echo "<div>{$Sector33['精密機器']['html']}</div>\n";
                    echo "<div>{$Sector33['その他製品']['html']}</div>\n";
                    echo "<div>{$Sector33['電気･ガス業']['html']}</div>\n";
                    echo "<div>{$Sector33['陸運業']['html']}</div>\n";
                    echo "<div>{$Sector33['海運業']['html']}</div>\n";
                    echo "<div>{$Sector33['空運業']['html']}</div>\n";
                    echo "<div>{$Sector33['倉庫･運輸関連業']['html']}</div>\n";
                    echo "<div>{$Sector33['情報･通信業']['html']}</div>\n";
                    echo "<div>{$Sector33['卸売業']['html']}</div>\n";
                    echo "<div>{$Sector33['小売業']['html']}</div>\n";
                    echo "<div>{$Sector33['銀行業']['html']}</div>\n";
                    echo "<div>{$Sector33['証券･商品先物取引業']['html']}</div>\n";
                    echo "<div>{$Sector33['保険業']['html']}</div>\n";
                    echo "<div>{$Sector33['その他金融業']['html']}</div>\n";
                    echo "<div>{$Sector33['不動産業']['html']}</div>\n";
                    echo "<div>{$Sector33['サービス業']['html']}</div>\n";
                    // echo "<div>{$Sector33['その他']['html']}</div>\n";
                    echo "</div>\n";
                  } else {
                    if (!empty($htmltable)) {
                      echo $htmltable;
                    }
                  }
                  ?>
                </div>
              </div>
              <?php
              if (!empty($tdnettable)) {
                echo "<h3>TDnet更新情報</h3>";
                echo "<div class=\"card\">";
                echo "<div class=\"card-body\">";
                echo $tdnettable;
                echo "</div>";
                echo "</div>";
              }
              ?>
              <?php
              // www
              if (!empty($urltable)) {
                echo "<h3>信用取引情報</h3>";
                echo "<div class=\"card\">";
                echo "<div class=\"card-body\">";
                echo $margintable;
                echo "</div>";
                echo "</div>";
              }
              ?>
              <?php
              // kara
              if (!empty($karatable)) {
                echo "<h3>機関空売り情報</h3>";
                echo "<div class=\"card\">";
                echo "<div class=\"card-body\">";
                echo $karatable;
                echo "</div>";
                echo "</div>";
              }
              ?>



              <?php
              if (!empty($edinettable)) {
                echo "<h3>EDINEt更新情報</h3>";
                echo "<div class=\"card\">";
                echo "<div class=\"card-body\">";
                echo $edinettable;
                echo "</div>";
                echo "</div>";
              }
              ?>



            </div><!-- /.col -->
          </div><!-- /.row -->
        </div><!-- /.container-fluid -->
      </div><!-- /.content -->

    </div><!-- /.content-wrapper -->


  </div><!-- /.wrapper -->

  <script src="plugins/jquery/jquery.min.js"></script>
  <script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="dist/js/adminlte.min.js"></script>

</body>

</html>