<?

//////////////////////////////////기본환경설정/////////////////////
$cart_config[level]  =  2; //관리자 접속등급

//////////////////////////////////기본환경설정/////////////////////


//주문관리 테이블
$cart_order = "g4_cart_order";

//제품관리 테이블
//$bo_table = "shopping"; 
$se_table = "shopping"; 
$m_table = "g4_write_".$se_table;

//상품 분류 테이블
$cart_table[cart_category] = "g4_cart_category";

//카운트 테이블
$g4_cart_count  = "g4_cart_count";

//질문답변 테이블
$g4_cart_qna  = "g4_cart_qna";

//배송비
$trance_price = 4500;

//skin_path
$cart_basic_url = "$g4[path]/skin/cart/basic";


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

    $result_array = array();

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

        if (is_dir($dirname.$file)) $result_array[] = $file;
    }
    closedir($handle);
    sort($result_array);

    return $result_array;
}




//변수는 적당한곳에 옮기세요
function sum_price($m_cart,$m_table)
{

    global $g4;
  // 장바구니에 들어있는 모든 책에 대한 가격의 총합 계산
  $price = 0;


  if(is_array($m_cart))
  {

    foreach($m_cart as $isbn => $qty)
    {  

      $result = sql_fetch("select * from $m_table where wr_id=$isbn");
      if ($result)
      {

        $item_price = $result[wr_1]; // 가격 설정
        $price +=$item_price*$qty;
      }
    }
  }


  return $price;
  
  
  
}

function sum_qt($cart)
{
  // 장바구니에 있는 책이 총 몇 권인지를 계산
  $items = 0;

  
  if(is_array($cart))
  {
    foreach($cart as $isbn => $qty)
    {  
      $items += $qty;
    }
  }
  return $items;
}





function sub_cate_name($cart_table,$cart_id, $order)
{
    global $g4;
//http://www.108bul.com/s_shop/?sv_state=
$cart_skin_url    = "{$g4[path]}/skin/cart/basic";
$shop_home        = "{$g4[bbs_path]}/board.php?bo_table=shopping";

$url_home         = "{$g4[bbs_path]}/board.php?bo_table=shopping";

//경로
    $sub_cate_name  = "";
	$sub_cate_name .= "<img src=\"$cart_skin_url/img/now_url.gif\" >";
	$sub_cate_name .=  "&nbsp;<b>현재위치</b>&nbsp;:&nbsp;&nbsp;";
	$sub_cate_name .=  "<a href='{$shop_home}' $style>";
	$sub_cate_name .=  "HOME";
	$sub_cate_name .=  "</a>";
if($cart_id){
   //분류값 검사
   $cart_sql   = " select wr_reply,wr_subject,ne_1,wr_num from $cart_table where ne_1 = '$cart_id' ";
   $cart_row   = sql_fetch($cart_sql);

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

    if($sub_reply == '1'){ //하위분류이면 대분류를 불러옴
	//$cart_row[wr_num]  // 최상위분류
	  $top_sql   = " select wr_subject,ne_1 from $cart_table where wr_num = '$cart_row[wr_num]' and wr_reply = '' ";
	  $top_row   = sql_fetch($top_sql);
       

	   //최상단 경로
	  $top_url   = $shop_home;
	  $top_url  .= "&cart_id=".$top_row[ne_1];


      $sub_cate_name .= "&nbsp;>&nbsp;";
      $sub_cate_name .= "<a href='{$top_url}' $style >";
      $sub_cate_name .= $top_row[wr_subject];
      $sub_cate_name .= "</a>";
      $sub_cate_name .= "&nbsp;>&nbsp;";
      $sub_cate_name .= $cart_row[wr_subject];
	}
	elseif($sub_reply == '2'){



	  //최상위분류
	  $top_sql   = " select wr_subject,ne_1 from $cart_table where wr_num = '$cart_row[wr_num]' and wr_reply = '' ";
	  $top_row   = sql_fetch($top_sql);

	   //최상단 경로
	  $top_url   = $shop_home;
	  $top_url  .= "&cart_id=".$top_row[ne_1];

	  //1단계분류
	  $sub_val   = substr($cart_row[wr_reply],0,1);
	  $sub_sql   = " select wr_subject,ne_1 from $cart_table where wr_num = '$cart_row[wr_num]' and wr_reply = '$sub_val' ";
	  $sub_row   = sql_fetch($sub_sql);

	  $sub_url   = $shop_home;
	  $sub_url  .= "&cart_id=".$sub_row[ne_1];
       

      $sub_cate_name .= "&nbsp;>&nbsp;";
      $sub_cate_name .= "<a href='{$top_url}' $style >";
      $sub_cate_name .= $top_row[wr_subject];
      $sub_cate_name .= "</a>";

      $sub_cate_name .= "&nbsp;>&nbsp;";
      $sub_cate_name .= "<a href='{$sub_url}' $style >";
      $sub_cate_name .= $sub_row[wr_subject];
      $sub_cate_name .= "</a>";

      $sub_cate_name .= "&nbsp;>&nbsp;";
      $sub_cate_name .= $cart_row[wr_subject];

	}
	else{ // 대분류
      $sub_cate_name .= "&nbsp;>&nbsp;";
      $sub_cate_name .= $cart_row[wr_subject];
	}

}
elseif($order){
	switch($order){

		case 'my_order':
			$order = '주문대기';
			break;

		case 'order':
			$order = '결재하기';
			break;

		case 'category':
			$order = '분류관리';
			break;

		case 'order_creat':
			$order = '입점신청';
			break;

	}
      $sub_cate_name .= "&nbsp;>&nbsp;";
      $sub_cate_name .= $order;
}


    return $sub_cate_name;
}

function latest_cart($skin_dir="", $bo_table, $rows=10, $subject_len=40,$s_subject="" , $order_by="wr_id",$cn=4 ,$s_turn=365 ,$t_end=0.0001,$if_co="" ,$if_co2="" , $w_size=90, $h_size=67  )
{
    global $g4, $is_admin;

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

    $list = array();

    $sql = " select * from $g4[board_table] where bo_table = '$bo_table'";
    $board = sql_fetch($sql);

    $tmp_write_table = $g4['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
    
    
    
    //기간별 검색 ( 검색시 원 입력을 유지시킴 )   절대 변경하시면 안됩니다.
    $start_search   =   $s_turn;   // 검색 시작일   예- 100    100일전부터
    $end_search     =   $t_end;


	 $s_day    = 24;

	 $s_time   = $s_day*$s_turn; //정수값을 1일로 환산처리.
     $s_start  = date("Y-m-d H:i:s", time()-3600 * $s_time); 

	 $t_day    = 24;
	 $t_time   = $s_day*$t_end; //정수값을 1일로 환산처리.
     $t_end  = date("Y-m-d H:i:s", time()-3600 * $t_time); 

     
	 //조건
	 $s_mct  =  "wr_is_comment = 0 ";
	 $s_mct .=  " and wr_datetime >= '$s_start'";
	 $s_mct .=  " and wr_datetime <= '$t_end'";

   //관리자 control
   if($if_co and $if_co2 ){
     $s_mct .=  " and $if_co = '$if_co2'";
     }

    $sql = " select * from $tmp_write_table where $s_mct order by $order_by desc limit 0, $rows ";
    //explain($sql);
    $result = sql_query($sql);
    for ($i=0; $row = sql_fetch_array($result); $i++) 
        $list[$i] = get_list($row, $board, $latest_skin_path, $subject_len);
    
    ob_start();
    include "$latest_skin_path/latest.skin.php";
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}

?>


<script language="javascript">
function Rink(se_07){
this.location.href=se_07;
}
</script>

