-=[ Mr. Bumblebee ]=-
_Indonesia_
<?php
class category
{
var $category = array() ; // array
var $use_none = "--¼±ÅÃ--" ;
var $s_value = array() ; // default select data
var $result ;
var $aresult ;
var $objOption ;
var $objChangeOption ;
var $depth = 1 ;
function push( $key , $val )
{
$this->category[$key] = $val ;
}
function loop($arr) {
if ( is_array($arr)) {
foreach ( $arr as $key=>$val ) {
if ( empty($key)) $key = '' ;
if ( !empty($this->aresult)) $this->aresult.= "," ;
$this->aresult.= "['{$key}','{$val[0]}'" ;
if ( is_array($val[1])) $this->loop($val[1]);
$this->aresult.= "]" ;
}
}
}
function script($cname) {
$this->aresult = '' ;
$this->loop($this->category);
$select = '' ;
$data = array() ;
$data[0] = "''" ;
for ( $i = 1 ; $i < $this->depth ; $i++ ) {
$select.= '<select name="' . $cname . '' . $i . '" onchange="change_data___' . $cname . '(this);" ><option value="">' . $this->use_none . '</option></select> ' ;
if (is_numeric($this->s_value[$i])) $data[$i] = $this->s_value[($i-1)];
else $data[$i] = "'" . $this->s_value[($i-1)] . "'" ;
}
// last
if (is_numeric($this->s_value[$this->depth])) $data[$this->depth] = $this->s_value[($this->depth-1)];
else $data[$this->depth] = "'" . $this->s_value[($this->depth-1)] . "'" ;
$select.= '<select name="' . $cname . '' . $this->depth . '" ' . $this->objOption . ' ><option value="">' . $this->use_none . '</option></select>' ;
// result
$this->result = $select .
'<script language="javascript">
var ' . $cname . '_depth = ' . $this->depth . ' ;
var ' . $cname . '_value = [ ' . implode ( ',' , $data ) . ' ] ;
var ' . $cname . ' = [' . $this->aresult . '] ;
function create__master___' . $cname . '(obj) {
var len = obj.length ;
var d = 1 ;
for ( var i = 0 ; i < len ; i++ ) {
document.getElementById(\'' . $cname . '\' + d).options[(i+1)] = new Option( obj[i][1] , obj[i][0] ) ;
if ( ' . $cname . '_value[d] == obj[i][0] ) {
document.getElementById(\'' . $cname . '\' + d).options[(i+1)].selected = true ;
if ( typeof obj[i][2] != \'undefined\' ) create__sub___' . $cname . '(obj[i],d+1);
}
else document.getElementById(\'' . $cname . '\' + d).options[(i+1)].selected = false ;
}
}
function create__sub___' . $cname . '(obj,d) {
var tlen = obj.length ;
for ( var i = 2 ; i < tlen ; i++ ) {
idx = i - 1 ;
document.getElementById(\'' . $cname . '\' + d).options[idx] = new Option( obj[i][1] , obj[i][0] ) ;
if ( ' . $cname . '_value[d] == obj[i][0] ) {
document.getElementById(\'' . $cname . '\' + d).options[idx].selected = true ;
if ( typeof obj[i][2] != \'undefined\' ) create__sub___' . $cname . '(obj[i],d+1);
}
}
}
function change_data___' . $cname . '(fobj) {
d = fobj.name.substring ( String(fobj.name).length , String(fobj.name).length - 1 );
// options default
for ( var i = ' . $cname . '_depth ; i > d ; i-- ) {
len = document.getElementById(\'' . $cname . '\' + i).options.length ;
for ( var j = ( len - 1 ) ; j > 0 ; j-- ) document.getElementById(\'' . $cname . '\' + i).options[j] = null ;
}
if ( document.getElementById(\'' . $cname . '1\').selectedIndex == 0 ) {
} else {
obj = ' . $cname . '[(document.getElementById(\'' . $cname . '1\').selectedIndex-1)] ;
for ( var i = 2 ; i <= d ; i++ ) {
obj = obj[(document.getElementById(\'' . $cname . '\' + i).selectedIndex+1)] ;
}
if ( typeof obj[2] != \'undefined\' ) create__sub___' . $cname . '(obj,parseInt(d)+1);
}
' . $this->objChangeOption . '
}
create__master___' . $cname . '(' . $cname . ');
</script> ' ;
}
}
/*
::¸¸µçÀÌ::
³¯Â¥ : 2009.06.25~26
ȸ»ç : emagination
»ç¶÷ : jjyp@emagination.co.kr
::ÁÖÀÇ»çÇ×::
depth ´Â ÃÖ°í ±íÀ̰ªÀ¸·Î Á¤È®ÇÏ°Ô ÀÔ·ÂÇØ¾ß ÇÕ´Ï´Ù.
category ¹è¿ µ¥ÀÌÅÍ´Â
key°ªÀº Äڵ尪(µ¥ÀÌÅÍ)
0¹øÂ° À妽º´Â º¸ÀÌ´Â °ª(ÅØ½ºÆ®)
1~ ¼ÓÇÑ ¼ºê Ä«Å×°í¸®
¹è¿µ¥ÀÌÅÍ´Â Á¤È®È÷ ÁöÄÑÁà¾ß ÇÕ´Ï´Ù.
Å×½ºÆ®´Â ¸øÇغÃÀ¸³ª ¹«Çѵµ °¡´ÉÇÒ µí?
objOption ¿¡ event¸¦ ³ÖÀ¸¸é ¾ÈµË´Ï´Ù...
::»ç¿ë¹æ¹ý::
$pcate = new category ;
$pcate->category = $product_category[$total['options']['pcode']] ;
$pcate->depth = 2 ;
$pcate->use_none = '--¼±ÅÃÇØÁÖ¼¼¿ä--' ;
$pcate->s_value[] = '' ;
$pcate->objOption = ' class="form" required ' ;
$pcate->script('category');
echo $pcate->result ;
*/
?>
Copyright © 2017 || Recoded By Mr.Bumblebee