웹마스터 팁

/*----------------------------------------------------------------------------*/
//  Class Name : TreeView                                                      /
//  Date  : 2002. 6. 24                                                        /
//  Coder : 이용회                                                             /
//  Homepage : http://www.sjbiz.net (개인 홈페이지는 아직 없음.)               /
//  eMail : lyh4612@hanmail.net                                                /
//  하고 싶은 말 : 우헤헤... 2일동안 고생해서 만들었어요 ^^;                   /
//                 머 수정해서 쓰시는건 상관 없는데 고칠점 있음 알려주세영 ^^  /
//                 그리고 수정하시면 저도 좀 보내주시구영..^^                  /
//                                                                             /
// 트리 알고리즘을 몰라서 고생했는데 결국 생각나는대로 만들었어염 ㅋㅋ ㅡ.,ㅡ; /
//                                                                             /
//                      그럼 즐프~~~~~ ^______________^                        /
/*----------------------------------------------------------------------------*/

class TreeView{
        var $tHead; //자바스크립트 저장
        var $tStyle; //스타일 저장

        var $title; //트리뷰 제목
        var $posX; //트리뷰 X위치
        var $posY; //트리뷰 Y위치
        var $width; //트리뷰 넓이
        var $borderColor; //트리뷰 보더선색
        var $titleFontColor; //트리뷰 타이틀 글자색
        var $titleBGColor; //트리뷰 타이틀 배경색
        var $BGColor; //트리뷰 내용 배경색
        var $uLine; //밑줄 여부

        var $toggleImg=array(
                "img/add.gif",
                "img/sub.gif",
                "img/blank.gif"); //+, - 이미지 저장

        var $NODE=array(array(
                "key",
                "str",
                "anc",
                "pKey",
                "Child Node Count",
                "Node Deep",
                "Script Folder open"));

        var $loadStr; //트리뷰 내용 담는 변수

        function TreeView($title="::: TreeView :::", $x="30", $y="30", $width="150", $bc="639EE7", $tfc="ffffff", $tbg="", $bg="ffffff", $uLine=false){
                $this->title=$title;
                $this->posX=$x;
                $this->posY=$y;
                $this->width=$width;
                $this->uLine=$uLine;
                $this->borderColor=$bc;
                $this->titleFontColor=$tfc;
                $this->titleBGColor=$tbg;
                $this->BGColor=$bg;
        }

        function setToggleImg($img){ //+, - 이미지 설정
                $tmp=split("[|]",$img);

                if(sizeof($tmp)!=3) return false;
                else $this->toggleImg=$tmp;
                return true;
        }

        function setTitle($title){ //제목 설정
                $this->title=$title;
        }

        function setPos($x, $y){ //위치 설정
                $this->posX=$x;
                $this->posY=$y;
        }

        function setWidth($width){ //크기 설정
                $this->width=$width;
        }

        function setBGColor($bc){ //트리뷰 보더색 설정
                $this->borderColor=$bc;
        }

        function setTFColor($tfc){ //트리뷰 글자색 설정
                $this->titleFontColor=$tfc;
        }

        function setTBGColor($tbg){ //타이틀 배경색 설정
                $this->titleBGColor=$tbg;
        }

        function setTBGColor($bg){ //트리뷰 배경색
                $this->BGColor=$bg;
        }

        function setUnderLine($bool=true){ //밑줄 설정
                $this->uLine=$bool;
        }

        function setFont($style="333333|none,333333|none"){
                $sArr=array(array("color","decoration"));
                $aTmp=explode(",", $style);
                while (list(, $val)=each($aTmp)){
                        $tmp=explode("|", $val);
                        array_push($sArr, $tmp);
                }
                $this->tStyle="
<style>
.TDTview {font-size:9pt; line-height:140%; font-family:굴림, tahoma, verdana, 돋움; color:#333333;}
A:link.Treeview    {text-decoration:{$sArr[1][1]}; color:{$sArr[1][0]};}
A:visited.Treeview {text-decoration:{$sArr[1][1]}; color:{$sArr[1][0]};}
A:active.Treeview  {text-decoration:{$sArr[1][1]}; color:{$sArr[1][0]};}
A:hover.Treeview   {text-decoration:{$sArr[2][1]}; color:{$sArr[2][0]};}
A:link.Treeview_title    {text-decoration:none; color:#333333;}
A:visited.Treeview_title {text-decoration:none; color:#333333;}
A:active.Treeview_title  {text-decoration:none; color:#333333;}
A:hover.Treeview_title   {text-decoration:none; color:#333333;}
</style>";
        }

        function findKey($POS, $Key){ //NODE에서 키 검색
        //인자 : NODE에서 위치 지정, 비교값
                $r=array("");
                for ($i=1;$i<sizeof($this->NODE);$i++)
                        if($this->NODE[$i][$POS]==$Key) array_push($r, $i);
                return $r;
        }

        function findPos($key){ //NODE에서 위치 검색
        //인자 : NODE에서 위치를 찾을 Key값
                for ($i=1;$i<sizeof($this->NODE);$i++)
                        if($this->NODE[$i][0]==$key) return $i;
        }

        function scriptObjectInsert($key){ //트리뷰의 상위NODE를 검색하여 스크립트 객체 생성
        //인자 : 현재 NODE의 Key
                $pos=$this->findPos($key); //자신의 키 위치값을 알아온다.
                $CPos=$this->findKey(0, $this->NODE[$pos][3]); //상위 NODE를 찾는다.
                $this->NODE[$CPos[1]][6].="∫".$this->NODE[$pos][0];
        }

        function Add($key, $str, $anc="#", $pKey=""){ //NODE 추가
        //인자 : 키값, 텍스트, 링크, 부모키값
                for($i=1;$i<sizeof($this->NODE);$i++) //키값 중복 체크
                        if($this->NODE[$i][0]==$key){
                                echo("{$key}값이 중복되었습니다.!!");
                                return false;
                        }

                if ($pKey!="") { //부모키를 찾아 자식 NODE 카운트를 증가시킨다.
                        $tmp=$this->findKey(0, $pKey);
                        $this->NODE[$tmp[1]][4]+=1;
                        $deep=$this->NODE[$tmp[1]][5]+1;
                } else $deep=0;

                array_push($this->NODE, array($key, $str, $anc, $pKey, 0, $deep)); //NODE에 삽입
                //최상위(Root)가 아닐 경우에 상위에 자신을 등록시킨다.
                if ($pKey!=""){
                        $this->scriptObjectInsert($key);
                }
                return true;
        }

        function createScript(){ //자바스크립트 생성
                if($this->tStyle=="") $this->setFont(); //스타일 정의가 안 되어 있으면 실행한다.

                $this->tHead=$this->tStyle."
<script>
function toggleFolder (name){
        switch (name) {
        case 'off' :
                viewHidden(document.all('off'), 'off')n";

                for($i=1;$i<sizeof($this->NODE);$i++){
                        if ($this->NODE[$i][6]!=""){
                                $this->tHead.="        case '{$this->NODE[$i][0]}' :";
                                $tmp=explode("∫", $this->NODE[$i][6]);
                                for($j=1;$j<sizeof($tmp);$j++){
                                        $this->tHead.="n                viewHidden(document.all('$tmp[$j]'), '{$this->NODE[$i][0]}');";
                                }
                                $this->tHead.="n                break;n";
                        }
                }
                $this->tHead.="
        } //switch end
}

function viewHidden(oTbl, oImg){
        var imgObj=document.all('IMG_'+oImg);

        if (oTbl.style.display == ''){
                oTbl.style.display='none';
                imgObj.src='{$this->toggleImg[0]}';
        }else{
                oTbl.style.display='';
                imgObj.src='{$this->toggleImg[1]}';
        }
}
</script>";
        }

        function Refresh($debug=false){ //트리뷰 생성/출력
        //인자 : true=모든 입력 자료 출력
                if (sizeof($this->NODE)<2) return 1;
                $startTime=time(); //처리 시작 시간
                $this->createScript(); //스크립트 생성
                $pos=$this->findKey(3, ""); //루트를 찾는다.
                for($i=1;$i<sizeof($pos);$i++){
                        $this->deep=0; //자식NODE 들여쓰기를 초기화
                        if($this->NODE[$pos[$i]][4]>0){ //하위 NODE가 있으면 하위 NODE를 출력한다.
                                $this->setStr($this->NODE[$pos[$i]][0], $this->toggleImg[0], $this->NODE[$pos[$i]][1], $this->NODE[$pos[$i]][2]);
                                $this->repeat($pos[$i]);
                        } else //자식NODE가 없으면 부모 NODE만 출력한다.
                                $this->setStr($this->NODE[$pos[$i]][0], $this->toggleImg[1], $this->NODE[$pos[$i]][1], $this->NODE[$pos[$i]][2]);
                } $this->loadStr="

<div id='remote' style='+ 'position:absolute; left:0px; top:0px; display:none;'><img src='img/t_sub.gif' id='IMG_off'></div>
<div id='remote' style='position:absolute; left:{$this->posX}px; top:{$this->posY}px;'>
<table cellpadding='0' cellspacing='1' border='0' width='$this->width' bgcolor='{$this->borderColor}'>
<tr>
        <td style='padding-top:3px;' bgcolor='{$this->titleBGColor}' class='TDTview'> 
                <a href="javascript:toggleFolder('off');" onfocus='this.blur()' class='Treeview_title'>
                <font color='{$this->titleFontColor}'> $this->title</font>  </a>
                <table border='0' cellpadding='2' cellspacing='1' width='100%' bgcolor='{$this->BGColor}' id='off'>
                <tr>
                        <td class='TDTview'>
                                $this->loadStr
                        </td>
                </tr>
                </table>
        </td>
</tr>
</table>
</div>";
                echo($this->tHead.$this->loadStr);
                if ($debug) $this->nodePrint($startTime);
        }

        function repeat($pos){ //트리뷰의 하위NODE를 출력하여 준다. (재귀함수)
        //인자 : NODE 위치
                $this->deep++; //들여쓰기를 증가한다.
                $loop=$this->NODE[$pos][4] + 1; //자식 NODE 갯수(반복 횟수)
                $CPos=$this->findKey(3, $this->NODE[$pos][0]); //자식 NODE를 찾는다.
                for($i=1;$i<$loop; $i++){
                        if($this->NODE[$CPos[$i]][4]>0){ //자식NODE가 또 있으면 재귀함수를 호출..
                                $this->nodeHead($this->NODE[$CPos[$i]][0], $this->toggleImg[0], $this->NODE[$CPos[$i]][1], $this->NODE[$CPos[$i]][2], $this->NODE[$CPos[$i]][5], " style='display:none'");
                                $this->repeat($CPos[$i]);
                                $this->nodeFoot();
                        } else //자식NODE가 없으면 출력한다.
                                $this->setStr($this->NODE[$CPos[$i]][0], $this->toggleImg[2], $this->NODE[$CPos[$i]][1], $this->NODE[$CPos[$i]][2], $this->NODE[$CPos[$i]][5], " style='display:none'");
                }
        }

        function nodeHead($id, $img, $str, $anc="#", $deep=0, $style=""){ //하위 NODE 설정 (head)
        //인자 : 키값, 이미지, 텍스트, 링크, 표시여부
        //들여쓰기 설정
        for($i=0;$i<$deep;$i++) $space.="   ";

        //이미지에 링크 걸기
        if ($img==$this->toggleImg[0]) $imgAnc="onclick="toggleFolder('$id')" style='cursor:hand;'";
        else $imgAnc="";

        //밑줄 설정
        if($this->uLine) $dot=" background-image:url(img/dot.gif); background-repeat:repeat-x; background-position:bottom bottom;";
        else $dot="";

        $this->loadStr.="
                <table cellpadding='1' cellspacing='0' border='0' width='100%' id='$id'{$style}>
                <tr>
                        <td style='padding-top:2pt;$dot' class='TDTview'>  $space<img src='$img' id='IMG_$id'$imgAnc>
                                <a onfocus='this.blur()' href=$anc class='Treeview'>$str</a>
                        </td>
                </tr>
                <tr>
                        <td class='TDTview'>";
        }

        function nodeFoot(){ //하위 NODE 설정 (foot)
        $this->loadStr.="
                        </td>
                </tr>
                </table>";
        }

        function setStr($id, $img, $str, $anc="#", $deep=0, $style=""){ //Root NODE와 하위 NODE가 없을 경우의 설정
        //인자 : 키값, 이미지, 텍스트, 링크, 표시여부
        //들여쓰기 설정
        for($i=0;$i<$deep;$i++) $space.="   ";

        //이미지에 링크 걸기
        if ($img==$this->toggleImg[0]) $imgAnc="onclick="toggleFolder('+ '$id')" style='cursor:hand;'";
        else $imgAnc="";

        //밑줄 설정
        if($this->uLine) $dot=" background-image:url(img/dot.gif); background-repeat:repeat-x; background-position:bottom bottom;";
        else $dot="";

        $this->loadStr.="
                <table cellpadding='1' cellspacing='0' border='0' width='100%' id='$id'{$style}>
                <tr>
                        <td style='padding-top:2pt;$dot' class='TDTview'>  $space<img src='$img' id='IMG_$id'$imgAnc>
                                <a onfocus='this.blur()' href=$anc class='Treeview'+ '>$str</a>
                        </td>
                </tr>
                </table>";
        }

        function nodePrint($startTime){ //입력한 모든 내용을 출력
                echo("
                <table border='0' cellspacing='1' cellpadding='3'+ ' bgcolor='666666'>
                <tr>
                        <td colspan='8' align='center' bgcolor='ffffff' class='+ 'TDTview'><b>트리뷰에 입력하신 모든 내용입니다.</b></td>
                </tr>
                <tr>
                        <td align='center' bgcolor='ffffff' class='TDTview'>No</td>
                        <td align='center' bgcolor='ffffff' class='TDTview'>Key</td>
                        <td align='center' bgcolor='ffffff' class='TDTview'>String</td>
                        <td align='center' bgcolor='ffffff' class='TDTview'>링크(Anc)</td>
                        <td align='center' bgcolor='ffffff' class='TDTview'>pKey</td>
                        <td align='center' bgcolor='ffffff' class='TDTview'>Deep</td>
                        <td align='center' bgcolor='ffffff' class='TDTview'>CNode</td>
                        <td align='center' bgcolor='ffffff' class='TDTview'>Script Object Name</td>
                </tr>
                ");
                for($i=1;$i<sizeof($this->NODE);$i++){
                        if($this->NODE[$i][3]==""){
                                $pKey="Root";
                                $tdbg="bgcolor='eeeeee'";
                        }else{
                                $pKey=$this->NODE[$i][3];
                                $tdbg="bgcolor='ffffff'";
                        }
                        echo("
                <tr>
                        <td $tdbg align='right' valign='top' class='TDTview'>$i </td>
                        <td $tdbg valign='top' class='TDTview'> {$this->NODE[$i][0]} </td>
                        <td $tdbg valign='top' class='TDTview'> {$this->NODE[$i][1]} </td>
                        <td $tdbg align='center' valign='top' class='TDTview'> {$this->NODE[$i][2]} </td>
                        <td $tdbg valign='top' class='TDTview'> {$pKey} </td>
                        <td $tdbg align='right' valign='top' class='TDTview'>{$this->NODE[$i][5]} </td>
                        <td $tdbg align='right' valign='top' class='TDTview'>{$this->NODE[$i][4]} </td>
                        <td $tdbg class='TDTview'> {$this->NODE[$i][6]} </td>
                </tr>");
                } $endTime=time(); //처리 종료 시간
                $pTime=$endTime-$startTime; //처리 시간
                echo("
                <tr>
                        <td colspan='8' bgcolor='ffffff' class='TDTview'> ::: Process Time : $pTime sec.</td>
                </tr>
                </table>");
        }
}
제목 글쓴이 날짜
[추천 팁] 폴더내의 파일중에서 특정정보만 뽑아오기. [2] M2Vis 2002.07.12
[추천 팁] 파일의 최종접근시간과 파일의 수정시간을 알려주는 함수 [2] ssukai 2002.07.10
PHP 와 Flash 를 이용해 즉석복권을 만들어 보자. [2] 다솜아빠 2002.07.10
[추천 팁] 웹 브라우저가 한글인지 영문인지(다른 언어인지) 자동 인식하기... [1] 박용구 2002.07.10
[PHP]간단한 로그인페이지 만들기 [15] ZipShin 2002.07.09
php소스를 윈도우 실행파일로 만드는 컴파일러 있나요? [2] 소우리 2002.07.08
배경그림과 글자색상,배경색상을 지정해주는 php스크립트 [2] ZipShin 2002.07.07
echo를 처음사용하시는 초보들에게... [10] ZipShin 2002.07.06
HTML 태그 메일 전송하기 [2] ZipShin 2002.07.06
EMail 주소 검사하기 [6] ZipShin 2002.07.06
트리뷰를 흉내낸 클래스 입니다.^^;; 용가리 2002.06.24
위 짜가리 클래스 활용 1 (FTP 디렉토리 트리뷰) 용가리 2002.06.24
위 짜가리 클래스 활용 1 (디렉토리 트리뷰) 용가리 2002.06.24
트리뷰를 흉내낸 클래스 사용법 입니다.^^;; 용가리 2002.06.24
리스트뷰를 흉내낸 클래스 입니다.^^;; [2] 용가리 2002.06.22
위의 리스트뷰 흉내낸 클래스 활용법 입니다.^^; [1] 용가리 2002.06.22
위의 리스트뷰 흉내낸 클래스 사용법 입니다.^^; 용가리 2002.06.22
php에서 GD를 이용한 3차원 막대 그래프 입니다. [4] 용가리 2002.06.22
리눅스로 쉘 프로그래밍 할때 [1] OsE= 2002.06.19
[mysql] 하나 더 추가요. 역시 별로 쓸대 없는거... 불티나 2002.06.18