20 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
43 function XoopsTree($table_name, $id_name, $pid_name)
45 $GLOBALS[
'xoopsLogger']->addDeprecated(
"Class '" . __CLASS__ .
"' is deprecated, check 'XoopsObjectTree' in tree.php");
47 $this->table = $table_name;
49 $this->pid = $pid_name;
53 function getFirstChild($sel_id, $order =
"")
55 $sel_id = intval($sel_id);
57 $sql =
"SELECT * FROM " . $this->table .
" WHERE " . $this->pid .
"=" . $sel_id .
"";
59 $sql .=
" ORDER BY $order";
62 $count = $this->db->getRowsNum(
$result);
66 while ($myrow = $this->db->fetchArray(
$result)) {
67 array_push($arr, $myrow);
73 function getFirstChildId($sel_id)
75 $sel_id = intval($sel_id);
77 $result = $this->db->query(
"SELECT " . $this->
id .
" FROM " . $this->table .
" WHERE " . $this->pid .
"=" . $sel_id .
"");
78 $count = $this->db->getRowsNum(
$result);
82 while (list ($id) = $this->db->fetchRow(
$result)) {
83 array_push($idarray, $id);
89 function getAllChildId($sel_id, $order =
"", $idarray = array())
91 $sel_id = intval($sel_id);
92 $sql =
"SELECT " . $this->
id .
" FROM " . $this->table .
" WHERE " . $this->pid .
"=" . $sel_id .
"";
94 $sql .=
" ORDER BY $order";
97 $count = $this->db->getRowsNum(
$result);
101 while (list ($r_id) = $this->db->fetchRow(
$result)) {
102 array_push($idarray, $r_id);
103 $idarray = $this->getAllChildId($r_id, $order, $idarray);
109 function getAllParentId($sel_id, $order =
"", $idarray = array())
111 $sel_id = intval($sel_id);
112 $sql =
"SELECT " . $this->pid .
" FROM " . $this->table .
" WHERE " . $this->
id .
"=" . $sel_id .
"";
114 $sql .=
" ORDER BY $order";
117 list ($r_id) = $this->db->fetchRow(
$result);
121 array_push($idarray, $r_id);
122 $idarray = $this->getAllParentId($r_id, $order, $idarray);
128 function getPathFromId($sel_id, $title,
$path =
"")
130 $sel_id = intval($sel_id);
131 $result = $this->db->query(
"SELECT " . $this->pid .
", " . $title .
" FROM " . $this->table .
" WHERE " . $this->
id .
"=$sel_id");
132 if ($this->db->getRowsNum(
$result) == 0) {
135 list ($parentid, $name) = $this->db->fetchRow(
$result);
137 $name =
$myts->htmlspecialchars($name);
139 if ($parentid == 0) {
142 $path = $this->getPathFromId($parentid, $title,
$path);
149 function makeMySelBox($title, $order =
"", $preset_id = 0, $none = 0, $sel_name =
"", $onchange =
"")
151 if ($sel_name ==
"") {
152 $sel_name = $this->id;
155 echo
"<select name='" . $sel_name .
"'";
156 if ($onchange !=
"") {
157 echo
" onchange='" . $onchange .
"'";
160 $sql =
"SELECT " . $this->
id .
", " . $title .
" FROM " . $this->table .
" WHERE " . $this->pid .
"=0";
162 $sql .=
" ORDER BY $order";
166 echo
"<option value='0'>----</option>\n";
168 while (list ($catid, $name) = $this->db->fetchRow(
$result)) {
170 if ($catid == $preset_id) {
171 $sel =
" selected='selected'";
173 echo
"<option value='$catid'$sel>$name</option>\n";
175 $arr = $this->getChildTreeArray($catid, $order);
176 foreach($arr as $option) {
177 $option[
'prefix'] = str_replace(
".",
"--", $option[
'prefix']);
178 $catpath = $option[
'prefix'] .
" " .
$myts->htmlspecialchars($option[$title]);
179 if ($option[$this->
id] == $preset_id) {
180 $sel =
" selected='selected'";
182 echo
"<option value='" . $option[$this->id] .
"'$sel>$catpath</option>\n";
190 function getNicePathFromId($sel_id, $title, $funcURL,
$path =
"")
193 $sel_id = intval($sel_id);
194 $sql =
"SELECT " . $this->pid .
", " . $title .
" FROM " . $this->table .
" WHERE " . $this->
id .
"=$sel_id";
196 if ($this->db->getRowsNum(
$result) == 0) {
199 list ($parentid, $name) = $this->db->fetchRow(
$result);
201 $name =
$myts->htmlspecialchars($name);
202 $path =
"<a href='" . $funcURL .
"&" . $this->
id .
"=" . $sel_id .
"'>" . $name .
"</a>" .
$path .
"";
203 if ($parentid == 0) {
206 $path = $this->getNicePathFromId($parentid, $title, $funcURL,
$path);
212 function getIdPathFromId($sel_id,
$path =
"")
214 $sel_id = intval($sel_id);
215 $result = $this->db->query(
"SELECT " . $this->pid .
" FROM " . $this->table .
" WHERE " . $this->
id .
"=$sel_id");
216 if ($this->db->getRowsNum(
$result) == 0) {
219 list ($parentid) = $this->db->fetchRow(
$result);
221 if ($parentid == 0) {
224 $path = $this->getIdPathFromId($parentid,
$path);
236 function getAllChild($sel_id = 0, $order =
"", $parray = array())
238 $sel_id = intval($sel_id);
239 $sql =
"SELECT * FROM " . $this->table .
" WHERE " . $this->pid .
"=" . $sel_id .
"";
241 $sql .=
" ORDER BY $order";
244 $count = $this->db->getRowsNum(
$result);
248 while ($row = $this->db->fetchArray(
$result)) {
249 array_push($parray, $row);
250 $parray = $this->getAllChild($row[$this->
id], $order, $parray);
263 function getChildTreeArray($sel_id = 0, $order =
"", $parray = array(), $r_prefix =
"")
265 $sel_id = intval($sel_id);
266 $sql =
"SELECT * FROM " . $this->table .
" WHERE " . $this->pid .
"=" . $sel_id .
"";
268 $sql .=
" ORDER BY $order";
271 $count = $this->db->getRowsNum(
$result);
275 while ($row = $this->db->fetchArray(
$result)) {
276 $row[
'prefix'] = $r_prefix .
".";
277 array_push($parray, $row);
278 $parray = $this->getChildTreeArray($row[$this->
id], $order, $parray, $row[
'prefix']);