<?php
//=====================================
// LINKER Category Engine
//=====================================
// Filename : move_category.php
// Path : Manage directory
// last update : 2002/03/13
// Desc : Move Category
//=====================================
//=====================================
// File include part
//=====================================
include ("./authen.php");
include ("../function/$Sdb_type.php");
include ("../function/main_func.php");
include ("../$Slang/m_common.php");
if (!isset($move)) errmsg($l_error_nosid);
if (empty($move)) errmsg($l_error_nomove);
$db = new DB_Sql($Sdb_host,$Sdb_user,$Sdb_pass,$Sselect_db);
//=====================================
// Print form
//=====================================
if (!$switch) {
$db->query("select title,path,parent from LINKER_CAT where sid='$move'");;
$row=$db->nrecord();
$row[title] = htmlspecial(stripslashes(trim($row[title])));
$this_title = $row[title];
$this_parent = $row[parent];
$this_path = $row[path];
$db->query("select pathtxt from LINKER_CAT where sid='$this_parent'");
$row = $db->nrecord();
$p_pathtxt = str_replace($Ssepchar, $Sarrow, $row[pathtxt]);
// movable category
$db->query("select sid,title,pathtxt,path from LINKER_CAT where relate<1 and path not like '$this_path%' order by pathtxt ");
while ($row = $db->nrecord()) {
$row[pathtxt] = str_replace($Ssepchar, $Sarrow, $row[pathtxt]);
if ($this_parent == $row[sid])
$prow .= "<option value='$row[sid]' selected>$row[pathtxt]</option>\n";
else
$prow .= "<option value='$row[sid]'>$row[pathtxt]</option>\n";
}
print <<<EOF
<html>
<head>
<LINK rel='stylesheet' type='text/css' href='./linker.css'>
<meta http-equiv='Content-Type' content='text/html; charset=$Scharset'>
</head>
<body bgcolor="#E9E9E9">
<form action='move_category.php' method='post'>
<input type='hidden' name='switch' value='up'>
<input type='hidden' name='move' value='$move'>
<input type='hidden' name='oparent' value='$this_parent'>
<div align='left'>
<table border=0 cellpadding=0 cellspacing=1>
<tr>
<td colspan=2>
<table width="100%" border="1"><tr><td bgcolor="#000066" align="center">
<b><font color="white" size="2">$l_cat $l_move</font></b>
</td></tr></table>
</td> </tr>
<tr><td colspan=2> </td> </tr>
<tr>
<td bgcolor='#E0E0E0' colspan=2 height=24 align=center width=500>
<font size='2'> $l_cat_move_head </font></td>
</tr>
<tr>
<td width='150' height=23 bgcolor='#F6F6F6'><font size='2'> $l_sid</font></td>
<td bgcolor='#F6F6F6'> <font size='2'>$move</font></td>
</tr>
<tr>
<td width='150' height=23 bgcolor='#F6F6F6'><font size='2'> $l_title</font></td>
<td bgcolor='#F6F6F6'> <font size='2'>$this_title</font></td>
</tr>
<tr>
<td width='150' height=23 bgcolor='#F6F6F6'><font size='2'> $l_this_cat</font></td>
<td bgcolor='#F6F6F6'> <font size='2'>$p_pathtxt</font></td>
</tr>
<tr>
<td width='150' height=23 bgcolor='#F6F6F6'><font size='2'> $l_target_cat</font></td>
<td bgcolor='#F6F6F6'> <font size='2'><select name='parent'>$prow</select></font></td>
</tr>
<tr><td colspan=2 align=center bgcolor="#E0E0E0" height=23><input type='submit' value=' $l_move ' class=cinput>
<input type='reset' value=' $l_reset ' class=cinput></td></tr>
</table></div></form>
EOF;
exit;
}
//=====================================
// Move category part
//=====================================
if ($oparent <> $parent)
{
$db->query("select sid,path,pathtxt,parent,title from LINKER_CAT where sid = '$move'");
$row = $db->nrecord();
$slash_path = $row[path] . "/";
$slash_pathtxt = $row[pathtxt] . $Ssepchar;
// Target category info
$db->query("select sid,parent,path,pathtxt from LINKER_CAT where sid='$parent'");
$trow = $db->nrecord();
$tpparent = $trow[parent];
$slash_tpath = $trow[path] . "/" . $row[sid] . "/";
$slash_tpathtxt = $trow[pathtxt]. $Ssepchar . $row[title] . $Ssepchar;
// This category info
$this_tpath = $trow[path] . "/" . $row[sid];
$this_tpathtxt = $trow[pathtxt]. $Ssepchar . $row[title];
// Change Sub category
$db->query("update LINKER_CAT set path = REPLACE(path,'$slash_path','$slash_tpath'),
pathtxt = REPLACE(pathtxt,'$slash_pathtxt','$slash_tpathtxt') where path like '$slash_path%'");
$db->query("update LINKER_CAT set pparent = '$parent' where parent='$move'");
$db->query("update LINKER_LINK set path = REPLACE(path,'$slash_path','$slash_tpath'),
pathtxt = REPLACE(pathtxt,'$slash_pathtxt','$slash_tpathtxt') where path like '$slash_path%'");
// This Category move
$db->query("update LINKER_CAT set path = '$this_tpath',pathtxt = '$this_tpathtxt',parent='$parent',pparent='$tpparent' where sid='$move'");
$db->query("update LINKER_LINK set path = '$this_tpath',pathtxt = '$this_tpathtxt' where parent='$move'");
// Minus Category num
$db->query("update LINKER_CAT set sub_cat = sub_cat -1 where sid='$row[parent]'");
$db->query("update LINKER_CAT set sub_cat = sub_cat +1 where sid='$trow[sid]'");
}
//=====================================
// Print move result
//=====================================
print <<<EOF
<head>
<LINK rel='stylesheet' type='text/css' href='./linker.css'>
<meta http-equiv='Content-Type' content='text/html; charset=$Scharset'>
<meta http-equiv='refresh' content='2; url=./view_category.php?type=move'>
</head>
<body bgcolor="#E9E9E9">
<body bgcolor="#E9E9E9">
<table width="500" border="1"><tr><td bgcolor="#000066" align="center">
<font color="white" size="2"><b>$move $l_move_result</b></font>
</td></tr></table>
EOF;
?>