<?php

	include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
	include $_SERVER['DOCUMENT_ROOT'].ADMIN_PATH.'common/auth_chk.php';

    $sql = "
            SELECT cd_dealer, cd_dealerid, nm_company, nm_name, concat(nm_hp_01, concat(nm_hp_02,nm_hp_03)) as nm_hp, ds_status, dt_insert, dt_lastlogin
            	FROM dealer_master d
            	   where ds_delind='N'
                    and ds_type = 'D0'
            ORDER BY nm_company asc";
    $r = mysql_query($sql);
    $i=1;
    $cnt = 1;
    while($col = mysql_fetch_array($r)) {
?>
<?
        $sub_sql = "select dt_insert from tender_master tm where tm.cd_dealer_p = '".$col['cd_dealer']."' order by cd_tender desc limit 1";
        $sub_r = mysql_query($sub_sql);
        $sub_col = mysql_fetch_array($sub_r);

        $d1_sql = "select cd_dealer, cd_dealerid, nm_company, nm_name, concat(nm_hp_01, concat(nm_hp_02,nm_hp_03)) as nm_hp, ds_status, dt_insert, dt_lastlogin from dealer_master dm where ds_delind='N' and ds_type = 'D1' and cd_dealer_p = '".$col['cd_dealer']."'";
        $d1_res = mysql_query($d1_sql);
        $d1_cnt = mysql_num_rows($d1_res);
?>
<table border="1">
<? if($cnt == 1) {?>
    <tr>
        <td>No</td>
        <td><?=iconv("UTF-8", "EUC-KR", "상호");?></td>
        <td><?=iconv("UTF-8", "EUC-KR", "관리자이름 및 아이디");?></td>
        <td><?=iconv("UTF-8", "EUC-KR", "연락처");?></td>
    <? for($i=0; $i < 5; $i++) {?>
        <td><?=iconv("UTF-8", "EUC-KR", "관리자이름 및 아이디");?></td>
        <td><?=iconv("UTF-8", "EUC-KR", "연락처");?></td>
    <? } ?>
        <td><?=iconv("UTF-8", "EUC-KR", "최종입찰일");?></td>
        <td><?=iconv("UTF-8", "EUC-KR", "최종로그인");?></td>
    </tr>
<? } ?>
    <tr>
        <td><?=$cnt?></td>
        <td><?=iconv("UTF-8", "EUC-KR", $col[nm_company]);?></td>
        <td><?=iconv("UTF-8", "EUC-KR", $col[nm_name]);?> <?=iconv("UTF-8", "EUC-KR", $col[cd_dealerid]);?></td>
        <td  style=mso-number-format:'\@'>'&nbsp;<?=iconv("UTF-8", "EUC-KR", $col[nm_hp]);?></td>
    <? while($d1_row = mysql_fetch_array($d1_res)) { ?>
        <td><?=iconv("UTF-8", "EUC-KR", $d1_row[nm_name]);?> <?=iconv("UTF-8", "EUC-KR", $d1_row[cd_dealerid]);?></td>
        <td style=mso-number-format:'\@'>'&nbsp;<?=iconv("UTF-8", "EUC-KR", $d1_row[nm_hp]);?></td>
    <? } ?>
    <?
        for($i=$d1_cnt;$i < 5;$i++) {
    ?>
        <td></td>
        <td></td>
    <?
        }
    ?>
        <td><?=iconv("UTF-8", "EUC-KR", $sub_col[dt_insert]);?></td>
        <td><?=iconv("UTF-8", "EUC-KR", $col[dt_lastlogin]);?></td>
    </tr>
</table>
<?
        $cnt++;
    }
?>
