25 public function __construct($table_name, $id_name, $pid_name)
27 $this->db =& Database::getInstance();
28 $this->table = $table_name;
30 $this->pid = $pid_name;
32 public function XoopsTree($table_name, $id_name, $pid_name)
34 return $this->__construct($table_name, $id_name, $pid_name);
39 public function getFirstChild($sel_id, $order=
'')
42 $sql =
'SELECT * FROM ' . $this->table .
' WHERE ' . $this->pid .
'=' . $sel_id .
'';
44 $sql .=
" ORDER BY $order";
46 $result = $this->db->query($sql);
47 $count = $this->db->getRowsNum($result);
51 while ($myrow=$this->db->fetchArray($result)) {
58 public function getFirstChildId($sel_id)
61 $result = $this->db->query(
'SELECT ' . $this->
id .
' FROM ' . $this->table .
' WHERE ' . $this->pid .
'=' . $sel_id .
'');
62 $count = $this->db->getRowsNum($result);
66 while (list($id) = $this->db->fetchRow($result)) {
73 public function getAllChildId($sel_id, $order=
'', $idarray = [])
75 $sql =
'SELECT ' . $this->
id .
' FROM ' . $this->table .
' WHERE ' . $this->pid .
'=' . $sel_id .
'';
77 $sql .=
" ORDER BY $order";
79 $result=$this->db->query($sql);
80 $count = $this->db->getRowsNum($result);
84 while (list($r_id) = $this->db->fetchRow($result)) {
86 $idarray = $this->getAllChildId($r_id, $order, $idarray);
92 public function getAllParentId($sel_id, $order=
'', $idarray = [])
94 $sql =
'SELECT ' . $this->pid .
' FROM ' . $this->table .
' WHERE ' . $this->
id .
'=' . $sel_id .
'';
96 $sql .=
" ORDER BY $order";
98 $result=$this->db->query($sql);
99 [$r_id] = $this->db->fetchRow($result);
104 $idarray = $this->getAllParentId($r_id, $order, $idarray);
110 public function getPathFromId($sel_id, $title, $path=
'')
112 $result = $this->db->query(
'SELECT ' . $this->pid .
', ' . $title .
' FROM ' . $this->table .
' WHERE ' . $this->
id .
"=$sel_id");
113 if (0 == $this->db->getRowsNum($result)) {
116 [$parentid, $name] = $this->db->fetchRow($result);
118 $name = $myts->makeTboxData4Show($name);
119 $path =
'/' . $name . $path .
'';
120 if (0 == $parentid) {
123 $path = $this->getPathFromId($parentid, $title, $path);
130 public function makeMySelBox($title, $order=
'', $preset_id=0, $none=0, $sel_name=
'', $onchange=
'')
132 if (
'' == $sel_name) {
133 $sel_name = $this->id;
136 echo
"<select name='".$sel_name.
"'";
137 if (
'' !== $onchange) {
138 echo
" onchange='".$onchange.
"'";
141 $sql =
'SELECT ' . $this->
id .
', ' . $title .
' FROM ' . $this->table .
' WHERE ' . $this->pid .
'=0';
143 $sql .=
" ORDER BY $order";
145 $result = $this->db->query($sql);
147 echo
"<option value='0'>----</option>\n";
149 while (list($catid, $name) = $this->db->fetchRow($result)) {
151 if ($catid == $preset_id) {
152 $sel =
" selected='selected'";
154 echo
"<option value='$catid'$sel>$name</option>\n";
156 $arr = $this->getChildTreeArray($catid, $order);
157 foreach ($arr as $option) {
158 $option[
'prefix'] = str_replace(
'.',
'--', $option[
'prefix']);
159 $catpath = $option[
'prefix'] .
' ' . $myts->makeTboxData4Show($option[$title]);
160 if ($option[$this->
id] == $preset_id) {
161 $sel =
" selected='selected'";
163 echo
"<option value='".$option[$this->id].
"'$sel>$catpath</option>\n";
171 public function getNicePathFromId($sel_id, $title, $funcURL, $path=
'')
173 $sql =
'SELECT ' . $this->pid .
', ' . $title .
' FROM ' . $this->table .
' WHERE ' . $this->
id .
"=$sel_id";
174 $result = $this->db->query($sql);
175 if (0 == $this->db->getRowsNum($result)) {
178 list($parentid, $name) = $this->db->fetchRow($result);
180 $name = $myts->makeTboxData4Show($name);
181 $path =
"<a href='".$funcURL .
'&' . $this->
id .
'=' . $sel_id .
"'>" . $name .
'</a> : ' . $path .
'';
182 if (0 == $parentid) {
185 $path = $this->getNicePathFromId($parentid, $title, $funcURL, $path);
191 public function getIdPathFromId($sel_id, $path=
'')
193 $result = $this->db->query(
'SELECT ' . $this->pid .
' FROM ' . $this->table .
' WHERE ' . $this->
id .
"=$sel_id");
194 if (0 == $this->db->getRowsNum($result)) {
197 [$parentid] = $this->db->fetchRow($result);
198 $path =
'/' . $sel_id . $path .
'';
199 if (0 == $parentid) {
202 $path = $this->getIdPathFromId($parentid, $path);
206 public function getAllChild($sel_id=0, $order=
'', $parray = [])
208 $sql =
'SELECT * FROM ' . $this->table .
' WHERE ' . $this->pid .
'=' . $sel_id .
'';
210 $sql .=
" ORDER BY $order";
212 $result = $this->db->query($sql);
213 $count = $this->db->getRowsNum($result);
217 while ($row = $this->db->fetchArray($result)) {
219 $parray=$this->getAllChild($row[$this->
id], $order, $parray);
224 public function getChildTreeArray($sel_id=0, $order=
'', $parray = [], $r_prefix=
'')
226 $sql =
'SELECT * FROM ' . $this->table .
' WHERE ' . $this->pid .
'=' . $sel_id .
'';
228 $sql .=
" ORDER BY $order";
230 $result = $this->db->query($sql);
231 $count = $this->db->getRowsNum($result);
235 while ($row = $this->db->fetchArray($result)) {
236 $row[
'prefix'] = $r_prefix .
'.';
238 $parray = $this->getChildTreeArray($row[$this->
id], $order, $parray, $row[
'prefix']);