<?
if (!defined('_GNUBOARD_')) exit;

// 모든 테이블에서 글 축출, 출력시간및 정렬순서
function latest_all($skin_dir="", $subject_name, $rows=10, $subject_len=40, $order_by="bn_id", $s_op ,$s_time="60", $e_time="0")
{
    global $g4;

    if ($skin_dir)
        $latest_skin_path = "$g4[path]/skin/latest_all/$skin_dir";
    else
        $latest_skin_path = "$g4[path]/skin/latest_all/basic";


      $day_s = 60*60*24*$s_time;
      $day_e = 60*60*24*$e_time;
      
      $start_t = time() - $day_s;
      $g4[time_s_ago] = date("Y-m-d H:i:s",$start_t);

      $end_t = time() - $day_e;
      $g4[time_e_ago] = date("Y-m-d H:i:s",$end_t);

      $mct         = " where bn_datetime between  '$g4[time_s_ago]' AND '$g4[time_e_ago]' ";
      $sql         = " select * from {$g4[site_count]}  $mct order by $order_by desc limit 0, $rows "; 
      $result      = sql_query($sql);
      $total_count = mysql_num_rows($result);

    
      ob_start();
      include "$latest_skin_path/latest.skin.php";
      $content = ob_get_contents();
      ob_end_clean();

      return $content;
 } 

// 모든 테이블 이미지 축출
function latest_photo($skin_dir="", $subject_name, $rows=10, $subject_len=40, $order_by="bf_datetime", $s_op ,$s_time="60", $e_time="0")
{
    global $g4;

    if ($skin_dir)
        $latest_skin_path = "$g4[path]/skin/latest_photo/$skin_dir";
    else
        $latest_skin_path = "$g4[path]/skin/latest_photo/basic";




      $day_s = 60*60*24*$s_time;
      $day_e = 60*60*24*$e_time;
      
      $start_t = time() - $day_s;
      $g4[time_s_ago] = date("Y-m-d H:i:s",$start_t);

      $end_t = time() - $day_e;
      $g4[time_e_ago] = date("Y-m-d H:i:s",$end_t);

      //이미지출력
      $mct        = " where ( bf_file LIKE '%jpg' or bf_file LIKE '%jpeg' or bf_file LIKE '%gif' or bf_file LIKE '%png' ) ";
      $mct       .= " and ( bf_datetime between  '$g4[time_s_ago]' AND '$g4[time_e_ago]' ) ";

      $sql       = " select * from $g4[board_file_table] $mct order by {$order_by} desc limit 0, $rows";
      $result       = sql_query($sql);
      $total_count  = mysql_num_rows($result);



    
      ob_start();
      include "$latest_skin_path/latest.skin.php";
      $content = ob_get_contents();
      ob_end_clean();

      return $content;
 } 


// 그릅축출방식
function sub_menu_gr($skin_dir="",$gr_id, $bo_table, $show, $subject_len=40, $options="")
{
    global $g4;

    if ($skin_dir)
        $sub_menu_skin_path = "$g4[path]/skin/sub_menu/$skin_dir";
    else
        $sub_menu_skin_path = "$g4[path]/skin/sub_menu/basic";

    $list = array();


    $site_bill  = 'g4_site_bill'; 

	if($gr_id){
    $mct          = " po_poll3 = '$gr_id' "; // 기본출력메뉴
	  $mct         .=  " and  po_cnt8 = '1'";  //2차메뉴설정 1인값
	  }
	else{
	  $mct         =  " po_cnt6 = '10'";  //1차메뉴설정 10인값
	  }

	 //정렬순서
	 if($bo_table || $gr_id){
		 $po_num_list  = "po_cnt9";
	 }
	 else{
		 $po_num_list  = "po_cnt7";
	 }

    $sql          = " select * from $site_bill where $mct order by {$po_num_list} ,po_poll1"; // gr_id 값을 추적한다. 
    $result       = sql_query($sql); 
    $total_count  = mysql_num_rows($result);
    //메뉴 상단 제목을 불러옴

    $ss_mct         =  " po_poll1 = '$gr_id' ";
    $ss_mct        .=  " and po_poll9 = 'gr_id' ";
    $ss_sql         =("select po_subject from $site_bill where $ss_mct");
    $gr_row         = sql_fetch($ss_sql);
    $gr_subject     = $gr_row[po_subject];


    ob_start();
    include "$sub_menu_skin_path/sub_menu.skin.php";
    $content = ob_get_contents();
    ob_end_clean();


    return $content;
}


// 그릅 -> 테이블 
function menu_gr($skin_dir="", $gr_id, $bo_table, $show, $subject_len=40, $options="" , $options2="") 
{ 
global $config, $member, $g4, $urlencode, $is_admin; 

    if ($skin_dir) 
        $sub_menu_skin_path = "$g4[path]/skin/head_menu/$skin_dir"; 
    else 
        $sub_menu_skin_path = "$g4[path]/skin/head_menu/basic"; 

    $list = array(); 

    $site_bill    = 'g4_site_bill'; 
    $mct          =  "po_cnt6  = '$show'"; 
    $sql          = " select * from $site_bill where $mct order by po_cnt7 , po_poll1"; 
    $result      = sql_query($sql); 

//로고검사
$site_bill_table = "g4_site_bill";
$head_mct        = " where po_poll1 = 'skin' and po_poll2 = 'head_menu' ";
$head_sql        = "select po_poll19, po_poll10, po_poll11,  po_cnt19, po_cnt18 from $site_bill_table $head_mct";
$head_row     = sql_fetch($head_sql);


$text_font_off = $head_row[po_poll10];  //폰트색상
if(!$text_font_off)
$text_font_off = "#d3d1d1";  //폰트색상

$text_font_on  = $head_row[po_poll11];  //폰트색상
if(!$text_font_on)
$text_font_on = "#fccbcb";  //폰트색상


$text_size     = $head_row[po_cnt18];  //폰트크기
if(!$text_size)
$text_size = 12;  //폰트색상

$text_width    = $head_row[po_cnt19];  //메뉴간격
if(!$text_width)
$text_width = 10;  //폰트색상

//로고이미지
$logo_name     = $head_row[po_poll19]; //로고이름
if($head_row[po_poll19])
   $logo_img    = "<img src='$g4[path]/data/file/index/$head_row[po_poll19]' border='0'>";
else
   $logo_img    =  "<img src='$sub_menu_skin_path/img/logo.gif' border='0'>";
    
    ob_start(); 
    include "$sub_menu_skin_path/sub_menu.skin.php"; 
    $content = ob_get_contents(); 
    ob_end_clean(); 

    return $content; 
}



//return latest
function if_conf_pro($skin_dir="", $limit, $show, $subject_len=40, $gr_id)
{
    global $g4;
    $board[shop] = "g4_site_bill";
    $mct    = " po_poll9 = 'bo_table' ";
    
   if($gr_id){

	  $mct   .= "and po_point = '$skin_dir'";
	  $mct   .= "and po_poll3 = '$gr_id'";
	  
	  $order_by  = 'po_cnt3';
      }
   else{
    $mct    = " po_poll7 = '$skin_dir' ";
	  $order_by  = 'po_poll8';
     }
    $limit  = " limit $limit "; // 켈러리형의 출력 갯수
    $sql    = " select * from $board[shop] where $mct order by  $order_by , po_subject $limit ";
    $result = sql_query($sql);
    $total_count  = mysql_num_rows($result);

	if($gr_id){

    ob_start();
       for ($i=0; $row=sql_fetch_array($result); $i++) {
	     echo "<table width=100% cellpadding=0 cellspacing=0><tr><td valign=top>";
         echo latest($row['mb_ids'], $row['po_poll1'], $row['po_ips'], $row['po_cnt1'],$row['po_cnt12']);
	     echo "</td></tr>";
		 echo "<tr><td height=5></td></tr>";
		 echo "</table>";

          }
    $content = ob_get_contents();
    ob_end_clean();
	}
	else{

    ob_start();
       for ($i=0; $row=sql_fetch_array($result); $i++) {
	     echo "<table width=100% cellpadding=0 cellspacing=0><tr><td valign=top>";
         echo latest($row['po_poll6'], $row['po_poll1'], $row['po_cnt4'], $row['po_cnt2'], $row['po_cnt11']);
	     echo "</td></tr>";
		 echo "<tr><td height=5></td></tr>";
		 echo "</table>";
	   }
    $content = ob_get_contents();
    ob_end_clean();

	}



    return $content;
}



function menu_url($s_menu, $t_menu){
   global  $g4; 
         $url_path   = "";
       if($s_menu == 'gr_id'){
         $url_path   =  $g4['path'];
         $url_path  .=  "/index.php?gr_id=";
         $url_path  .=  $t_menu;
         }
       if($s_menu == 'bo_table'){
         $url_path   =  $g4['path'];
         $url_path  .=  "/bbs/board.php?bo_table=";
         $url_path  .=  $t_menu;
         }
         
         $result   =  $url_path;

    return $result; 
  
  }

function menu_color($s_menu, $gr_id, $bo_table , $t_menu, $u_menu){
   global  $g4; 
   
		    
		  if($bo_table){
		      if($s_menu == $bo_table){
		        $color_r  = $t_menu;  
		        }
		      else{
		        $color_r  = $u_menu;  
		        }
		    }
         
         $result   =  $color_r;

    return $result; 
  
  }

// 스킨경로를 얻는다
function get_cate_dir($skin, $len='')
{
    global $g4;

    $result_array = array();

    $dirname = "$g4[path]/skin/board/$skin/";
    $handle = opendir($dirname);
	$i=0;
    while ($file = readdir($handle)) 
    {
        if($file == "."||$file == "..") continue;

        if (!(is_dir($dirname.$file))){
           if (!(preg_match("/\.(bak)$/i", $file)))
			$result_array[] = $file;
		}
	 $i++;

    }
    closedir($handle);
    sort($result_array);

    return $result_array;
}




// 분류 cart_id 의 길이 환산
function cart_strlen($cart_table, $cart_id)
{
    global $g4;

	//분류값 검사
    $cart_sql   = " select wr_reply from $cart_table where ne_1 = '$cart_id' ";
    $cart_row   = sql_fetch($cart_sql);

    $sql_search  = "";

    $reply_len = strlen($cart_row[wr_reply]);

	if($reply_len == '1'){
     $sql_search .= " wr_22 = '$cart_id' "; //
	}
	elseif($reply_len == '2'){
     $sql_search .= " wr_23 = '$cart_id' "; //
	}
	else{
     $sql_search .= " wr_21 = '$cart_id' "; //최상단메뉴인경우
	}


    return $sql_search;
}

function banner_sero($banner_sca)
{
    global $g4, $is_admin;

	$list = array();
    $g4_table         = "banner";	  
    $g4_site_table    =  "g4_site_".$g4_table;  
    $mct              = " where po_poll1 = '$banner_sca' ";
    $sql              = " select * from $g4_site_table $mct order by po_cnt4, po_id ";
    $result           = sql_query($sql);
	$total_count      = mysql_num_rows($result);


	if($total_count){
    ob_start();
		     echo "<table cellpadding=0 cellspacing=0>";
		for ($i=0; $row = sql_fetch_array($result); $i++){

             //파일 확장자 검색, 오류예방
	         $path_info       =  pathinfo($row[po_poll19]);
	         //  $path_info["extension"];

			 
			 if($path_info["extension"] == 'swf'){//플레쉬 파일일경우
		     echo "<tr><td align='center'>";
                 ?>
                <script>
                doc_write(flash_movie("<?=$g4[path]?>/data/file/banner/<?=$row[po_poll19]?>", "myfile", "<?=$row[po_cnt5]?>", "<?=$row[po_cnt6]?>", "transparent"));
                </script>
				 <?
			 echo "</td></tr>";
			 }
			 else{
		     echo "<tr><td align='center'>";
			 echo "<a href='$row[po_poll4]' target='$row[po_poll5]' >"; // 연결할 주소
             echo "<img src='$g4[path]/data/file/banner/$row[po_poll19]' title='$row[po_subject]'  border='0'>";
			 echo "</a>";
			 echo "</td></tr>";
			 }
		}
		     echo "</table>";
    $content = ob_get_contents();
    ob_end_clean();

	}
	else{
    ob_start();
	   if($is_admin){
	    $set_url = "<a href=".$g4[path]."/adm/category_list.php?url=banner>";
	    $set_url = "<a href=".$g4[path]."/adm/category_list.php?url=banner>";
		echo "<table width=100% height=100%  border=1 cellspacing=0 cellpadding=0 bordercolor=#F4F3F3 bordercolordark=white bordercolorlight=#F4F3F3>";
		echo "<tr><td height=100% align=center>[{$set_url}{$banner_sca}</a>]</td></tr>";
		echo "<tr><td height=5></td></tr>";
		echo "</table>";
	   }

    $content = ob_get_contents();
    ob_end_clean();
	}

    return $content;
}

function banner_garo($banner_sca)
{
    global $g4, $is_admin;

	$list = array();
    $g4_table         = "banner";	  
    $g4_site_table    =  "g4_site_".$g4_table; 


    $mct              = " where po_poll1 = '$banner_sca' ";
    $sql              = " select * from $g4_site_table $mct order by po_cnt4, po_id ";
    $result           = sql_query($sql);
	$total_count      = mysql_num_rows($result);

	$banner_target    = $result[po_poll1]; // 대상프레임


	if($total_count){
    ob_start();
		     echo "<table cellpadding=0 cellspacing=0><tr>";

		for ($i=0; $row = sql_fetch_array($result); $i++){

             //파일 확장자 검색, 오류예방
	         $path_info       =  pathinfo($row[po_poll19]);
	         //  $path_info["extension"];

			 if($path_info["extension"] == 'swf'){//플레쉬 파일일경우
		     echo "<td align='center'>";             
                 ?>
                <script>
                doc_write(flash_movie("<?=$g4[path]?>/data/file/banner/<?=$row[po_poll19]?>", "myfile", "<?=$row[po_cnt5]?>", "<?=$row[po_cnt6]?>", "transparent"));
                </script>
				 <?
			 echo "</td>";
			 }
			 else{
		     echo "<td align='center'>";             
			 echo "<a href='$row[po_poll4]' target='$row[po_poll5]'>"; // 연결할 주소
             echo "<img src='$g4[path]/data/file/banner/$row[po_poll19]' title='$row[po_subject]'  border='0'>";
			 echo "</a>";
			 echo "</td>";
			 }
		}
		     echo "</tr></table>";
    $content = ob_get_contents();
    ob_end_clean();
	}
	else{
    ob_start();
	   if($is_admin){
	    $set_url = "<a href=".$g4[path]."/adm/category_list.php?url=banner>";
		echo "<table width=100%  border=1 cellspacing=0 cellpadding=0 bordercolor=#F4F3F3 bordercolordark=white bordercolorlight=#F4F3F3>";
		echo "<tr><td hegiht=20 align=center>[{$set_url}{$banner_sca}</a>]</td></tr>";
		echo "<tr><td height=5></td></tr>";
		echo "</table>";
	   }

    $content = ob_get_contents();
    ob_end_clean();
	}

    return $content;
}

function banner_rand($banner_sca)
{
    global $g4, $is_admin;

	$list = array();
    $g4_table         = "banner";	  
    $g4_site_table    =  "g4_site_".$g4_table; 


    $mct              = " where po_poll1 = '$banner_sca' ";
    $sql              = " select * from $g4_site_table $mct order by po_cnt4, po_id ";
    $result           = sql_query($sql);
	$total_count      = mysql_num_rows($result);
	$t_c              = $total_count -1;

	$banner_target    = $result[po_poll1]; // 대상프레임


	if($total_count){
    ob_start();
		     echo "<table width='100%' cellpadding=0 cellspacing=0 align='center'><tr>";
		     echo "<td align='center'>"; 

		for ($i=0; $row = sql_fetch_array($result); $i++){

             //파일 확장자 검색, 오류예방
	         $path_info       =  pathinfo($row[po_poll19]);
	         //  $path_info["extension"];

			 if($path_info["extension"] == 'swf'){//플레쉬 파일일경우

             $data[$i] = "<script>doc_write(flash_movie('$g4[path]/data/file/banner/$row[po_poll19]', 'myfile', '$row[po_cnt5]', '$row[po_cnt6]', 'transparent'));</script>";

			 }
			 else{           

			 $data[$i] = "<a href='$row[po_poll4]' target='$row[po_poll5]'><img src='$g4[path]/data/file/banner/$row[po_poll19]' title='$row[po_subject]'  border='0'></a>";

			 }
		}

            $rand         = mt_rand(0,$t_c); 
            $data_view    = "$data[$rand]";

			 echo $data_view;
			 echo "</td>";
		     echo "</tr></table>";

    $content = ob_get_contents();
    ob_end_clean();
	}
	else{
    ob_start();
	   if($is_admin){
	    $set_url = "<a href=".$g4[path]."/adm/category_list.php?url=banner>";
		echo "<table width=100%  border=1 cellspacing=0 cellpadding=0 bordercolor=#F4F3F3 bordercolordark=white bordercolorlight=#F4F3F3>";
		echo "<tr><td hegiht=20 align=center>[{$set_url}{$banner_sca}</a>]</td></tr>";
		echo "<tr><td height=5></td></tr>";
		echo "</table>";
	   }

    $content = ob_get_contents();
    ob_end_clean();
	}

    return $content;
}

// 다차원분류메뉴
function cart_menu($skin_dir="",$cart_table,$bo_table,$cart_id,$options="" , $options2="")
{
    global $g4;

    if ($skin_dir)
        $cart_menu_path = "$g4[path]/skin/cart/cart_menu/$skin_dir";
    else
        $cart_menu_path = "$g4[path]/skin/cart/cart_menu/basic";

    $list = array();

	$mct      = " wr_reply = ''";
	


    $sql      = " select * from $cart_table where  {$mct}  order by ne_8, wr_id desc ";
    $result   = sql_query($sql);



    
    ob_start();
    include "$cart_menu_path/cart_menu.skin.php";
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}


?>
