<?php
include('header.php');
echo $h;

$pfolder = "../upload/";
$folderthumbs = $pfolder."thumbs/";
$wth = 150;
$hth = 150;

$action = $_GET['action'];
if(!isset($action)) $action = "add";

IF ($action=="add"){
?>
<form name="vbform" method="post" action="news_cp.php?action=insert" enctype="multipart/form-data">
<table class='xtable' width="100%" id="AutoNumber1">
     <tr>
      <td width="100%" colspan="3" class='xtx' align="center"><?php echo $LANGAUGE_CP[320]; ?></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[156]; ?></td>
      <td width="80%" class='xtd' colspan="2"><input size="60" name="name" /></td>
    </tr>
    <!--
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[88]; ?></td>
      <td width="80%" class='xtd' colspan="2"><?php echo $LANGAUGE_CP[89]; ?> <input dir="ltr" size="30" name="im" /><br />
<?php echo $LANGAUGE_CP[90]; ?> <input dir="ltr" size="30" name="image" type="file" /></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[94]; ?></td>
      <td width="80%" class='xtd' colspan="2"><input size="10" name="order_cat" /></td>
    </tr>
-->
    <tr>
                <td rowspan="2" class='xtr'><?php echo $LANGAUGE_CP[321]; ?></td>
                <td class='xtr' align="center"><?php echo $LANGAUGE_CP[91]; ?></td>
                <td class='xtr' align="center"><?php echo $LANGAUGE_CP[92]; ?></td>
        </tr>
        <tr>
                <td class='xtd' align="center"><textarea name="keywords" rows="5" cols="45"></textarea></td>
                <td class='xtd' align="center"><textarea name="description" rows="5" cols="45"></textarea></td>
        </tr>

        <tr>
<td width='20%' class='xtr'><?php echo $LANGAUGE_CP[95]; ?></td>
<td width='80%' class='xtd' colspan="2">
<select  size='1' name='sub'>
<OPTION value='0' selected="selected"><?php echo $LANGAUGE_CP[96]; ?></OPTION>
<?php
$sql = mysql_query ("SELECT * FROM  news_cat where sub=0");
while($cat=mysql_fetch_array($sql))
{
$cat['name'] = stripslashes($cat['name']);
$cat['name'] = htmlspecialchars($cat['name']);
echo "<OPTION value='".$cat['id']."'>".$cat['name']."</OPTION>";
}
?>
</select>
</td>
</tr>

     <tr>
      <td width="100%" colspan="3" class='xtr' align="center">
      <input type="submit" value=" <?php echo $LANGAUGE_CP[18]; ?> " name="cmdAdd" /></td>
    </tr>
  </table>
</form>

<?php

$queryx = mysql_query("SELECT * FROM news_cat order by id desc");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo "";
}else{

echo "<table class='xtable' width='100%' id='Aut4oNumber15'>
  <tr>
<td width='100%' colspan='4' class='xtt' align='center'>".$LANGAUGE_CP[97]."</td>
</tr>
  <tr>
      <td width='79%' align='center' class='xtr'>".$LANGAUGE_CP[158]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[28]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[26]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[27]."</td>
    </tr>";
while($p = mysql_fetch_array($queryx))
{
$p['name'] = stripslashes($p['name']);
$p['name'] = htmlspecialchars($p['name']);

if($p['active'] == 1){
$im = "images/on.gif";
$li = "news_cp.php?action=actx&id=$p[id]&act=0";
$te = $LANGAUGE_CP[72];
}else{
$im = "images/off.gif";
$li = "news_cp.php?action=actx&id=$p[id]&act=1";
$te = $LANGAUGE_CP[73];
}

echo "<tr>
      <td width='79%' class='xtd'>» ".$p['name']."</td>
      <td width='7%' align='center' class='xtd'><a href='$li'><img border='0' src='$im' alt='$te ".$p['name']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='news_cp.php?action=edit&id=$p[id]'><img border='0' src='images/edit.gif' alt='".$p['name']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='news_cp.php?action=delete&id=$p[id]'><img border='0' src='images/delete.gif' alt='".$p['name']."' /></a></td>
</tr>";
}
echo "</table>";
}

}ELSEIF ($action=="insert"){

$title = addslashes($_POST['name']);
$title = trim($title);

$im = addslashes($_POST['im']);
if($im==""){
$ima = uploadfile("image","upload","../upload/");
}else{
$ima = $im;
}

$keywords = addslashes($_POST['keywords']);
$keywords = trim($keywords);

$description = addslashes($_POST['description']);
$description = trim($description);

$order_cat = $_POST['order_cat'];
$sub = $_POST['sub'];

if($keywords==""){
$ree = str_replace(" ",",",$title);
$kkk = $ree;
}else{
$kkk = $keywords;
}

if($description==""){
$ddd = $title;
}else{
$ddd = $description;
}

if (empty($title)){
echo $LANGAUGE_CP[159];
}else{
$query =  mysql_query ("INSERT INTO news_cat (name,order_cat,image,keywords,description,sub,active) VALUES ('$title','$order_cat','".$ima."','$kkk','$ddd','$sub','1')") or die ("error");
print $LANGAUGE_CP[21];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=news_cp.php?action=add' />";
}

}ELSEIF ($action=="actx"){
$id = intval($_GET['id']);
$act = intval($_GET['act']);
if ($act == 0){
$query =  mysql_query("UPDATE news_cat SET active='$act' where id='$id'");
echo $LANGAUGE_CP[61];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=news_cp.php?action=add' />";
}elseif($act == 1){
$query =  mysql_query("UPDATE news_cat SET active='$act' where id='$id'");
echo $LANGAUGE_CP[62];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=news_cp.php?action=add' />";
}else{
echo $LANGAUGE_CP[63];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=news_cp.php?action=add' />";
}


}ELSEIF ($action=="edit"){
$id = intval($_GET['id']);
$query = mysql_query("SELECT * FROM news_cat where id='$id'");
$p = mysql_fetch_array($query);

$p['name'] = stripslashes($p['name']);
$p['name'] = htmlspecialchars($p['name']);

$p['keywords'] = stripslashes($p['keywords']);
$p['keywords'] = htmlspecialchars($p['keywords']);

$p['description'] = stripslashes($p['description']);
$p['description'] = htmlspecialchars($p['description']);

$p['image'] = stripslashes($p['image']);
$p['image'] = htmlspecialchars($p['image']);

if($p['image']==""){
$rr = '';
}else{
$rr = '<br /><a target="_blank" href="../'.$p['image'].'"><img src="../'.$p['image'].'" width="100" height="100" alt="'.$LANGAUGE_CP[322].'" border="0" /></a>';
}

echo "<form name='vbform' method='POST' action='news_cp.php?action=editok'>
<input type='hidden' name='id' value='$p[id]' />

<table class='xtable' width='100%' id='AutoNumber15'>

<tr>
<td width='100%' colspan='2' class='xtx' align='center'>".$LANGAUGE_CP[32]."</td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[156]."</td>
<td width='70%' class='xtd'><input name='name' size='60' value='".$p['name']."' /></td>
</tr>
<!--
<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[88]."</td>
<td width='70%' class='xtd'><input dir='ltr' name='image' size='60' value='".$p['image']."' /></td>
</tr>
-->
<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[91]."</td>
<td width='70%' class='xtd'><textarea name='keywords' rows='3' cols='60'>".$p['keywords']."</textarea></td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[92]."</td>
<td width='70%' class='xtd'><textarea name='description' rows='3' cols='60'>".$p['description']."</textarea></td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[94]."</td>
<td width='70%' class='xtd'><input name='order_cat' size='10' value='".$p['order_cat']."' /></td>
</tr>

<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[95]."</td>
<td width='80%' class='xtd'>
<select size='1' name='sub'>
<option value='0'>".$LANGAUGE_CP[96]."</option>";

$sql = mysql_query ("SELECT * FROM news_cat order by id") or die ("error");
while($sub = mysql_fetch_array($sql))
{
$sub['name'] = stripslashes($sub['name']);
$sub['name'] = htmlspecialchars($sub['name']);

if($sub['id'] ==  $p['sub']){
echo "<option value='$sub[id]' selected='selected'>".$sub['name']."</option>";
}else{
echo "<option value='$sub[id]'>".$sub['name']."</option>";
}

}
echo "</select>
</td>
</tr>

<tr>
<td width='100%' colspan='2' align='center' class='xtr'><input type='submit' value=' ".$LANGAUGE_CP[33]." ' name='B1' /></td>
</tr>

</table>
</form>";

}ELSEIF ($action=="editok"){

$id    = intval($_POST['id']);
$title = addslashes($_POST['name']);
$title = trim($title);

$image = addslashes($_POST['image']);

$keywords = addslashes($_POST['keywords']);
$keywords = trim($keywords);

$description = addslashes($_POST['description']);
$description = trim($description);

$order_cat = $_POST['order_cat'];
$sub = $_POST['sub'];

if($keywords==""){
$ree = str_replace(" ",",",$title);
$kkk = $ree;
}else{
$kkk = $keywords;
}

if($description==""){
$ddd = $title;
}else{
$ddd = $description;
}

if (empty($title)){
echo $LANGAUGE_CP[159];
}else{
$query =  mysql_query("UPDATE news_cat SET name='$title',order_cat='$order_cat',keywords='$kkk',description='$ddd',image='$image',sub='$sub' where id='$id'");
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=news_cp.php?action=add' />";
}

}ELSEIF ($action=="delete"){
$id = intval($_GET['id']);
$query =  mysql_query("DELETE FROM news_cat WHERE id='$id'");
echo $LANGAUGE_CP[35];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=news_cp.php?action=add' />";

}ELSEIF ($action=="addnews"){
$queryx = mysql_query("SELECT * FROM news_cat");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo '<a href="news_cp.php?action=add">'.$LANGAUGE_CP[629].'</a>';
}else{
?>
<form name="vbform" method="post" action="news_cp.php?action=insertnews" enctype="multipart/form-data">

<table class='xtable' width='90%' id='AutoNumber15'>
     <tr>
      <td width="100%" colspan="2" class='xtx' align="center"><?php echo $LANGAUGE_CP[323];?></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[324]; ?></td>
      <td width="80%" class='xtd'><input size="60" name="sub" /></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[325]; ?></td>
      <td width="80%" class='xtd'><input size="60" name="editor" /></td>
    </tr>

    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[236]; ?></td>
      <td width="80%" class='xtd'><input size="60" name="url" /></td>
    </tr>

    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[88]; ?></td>
      <td width="80%" class='xtd'><?php echo $LANGAUGE_CP[326]; ?> <input dir='ltr' size="20" name="im" /> <?php echo $LANGAUGE_CP[327]; ?> <input dir='ltr' size="20" name="im2" /><br />
<?php echo $LANGAUGE_CP[328]; ?> <input dir='ltr' type="file" size="40" name="image" /><br />
<?php echo $LANGAUGE_CP[329]; ?>
</td>
    </tr>

    <tr>
      <td width="100%" class='xtd' colspan="2" align="center">
<?php echo $LANGAUGE_CP[330]; ?><textarea name="keywords" rows="3" cols="100"></textarea>
</td>
    </tr>

    <tr>
      <td width="100%" class='xtd' colspan="2" align="center">
<?php echo $LANGAUGE_CP[331]; ?><textarea id="textarea1" name="short" rows="8" cols="100"></textarea>
</td>
    </tr>

    <tr>
      <td width="100%" class='xtd' colspan="2" align="center">
<?php echo $LANGAUGE_CP[332]; ?><textarea id="textarea2" name="text" rows="15" cols="100"></textarea>
      </td>
    </tr>

    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[156]; ?></td>
      <td width="80%" class='xtd'>
<select size="1" name="cat">
<?php
$query = mysql_query("SELECT * FROM news_cat order by id desc");
while($cat = mysql_fetch_array($query))
{
$cat['name'] = stripslashes($cat['name']);
$cat['name'] = htmlspecialchars($cat['name']);
echo "<OPTION value='$cat[id]'>".$cat['name']."</OPTION>";
}
?>
</select>
      </td>
    </tr>
     <tr>
      <td width="100%" colspan="2" align="center" class='xtr'>
      <input type="submit" value=" <?php echo $LANGAUGE_CP[18]; ?> " name="cmdAdd" /></td>
    </tr>
  </table>

</form>

<?php
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$page = ($page == 0 ? 1 : $page);
$perpage = 20;
$startpoint = ($page * $perpage) - $perpage;

$queryx = mysql_query("SELECT id,sub,date,vis,cat,active FROM news order by id desc LIMIT $startpoint,$perpage");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo "";
}else{

echo "<table class='xtable' width='100%' id='AutoNumber15'>
<tr>
<td width='100%' colspan='8' class='xtt' align='center'>".$LANGAUGE_CP[97]."</td>
</tr>
<tr>
      <td width='33%' align='center' class='xtr'>".$LANGAUGE_CP[333]."</td>
      <td width='20%' align='center' class='xtr'>".$LANGAUGE_CP[237]."</td>
      <td width='12%' align='center' class='xtr'>".$LANGAUGE_CP[57]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[106]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[706]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[28]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[26]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[27]."</td>
    </tr>";
while($p = mysql_fetch_array($queryx))
{
$p['sub'] = stripslashes($p['sub']);
$p['sub'] = htmlspecialchars($p['sub']);

$d = date("j/n/Y",$p['date']);

$queryxc = mysql_query("SELECT * FROM news_cat where id='".$p['cat']."'");
$pc = mysql_fetch_array($queryxc);
$pc['name'] = stripslashes($pc['name']);
$pc['name'] = htmlspecialchars($pc['name']);

if($p['active'] == 1){
$im = "images/on.gif";
$li = "news_cp.php?action=actxx&id=$p[id]&act=0";
$te = $LANGAUGE_CP[72];
}else{
$im = "images/off.gif";
$li = "news_cp.php?action=actxx&id=$p[id]&act=1";
$te = $LANGAUGE_CP[73];
}

echo "<tr>
      <td width='33%' class='xtd'>» <a href='../news.php?action=view&id=".$p['id']."' target='_blank'>".$p['sub']."</a></td>
      <td width='20%' align='center' class='xtd'><a href='../news.php?action=cat&id=".$pc['id']."' target='_blank'>".$pc['name']."</a></td>
      <td width='12%' align='center' class='xtd'>".$d."</td>
      <td width='7%' align='center' class='xtd'>".$p['vis']."</td>
      <td width='7%' align='center' class='xtd'><a href='comment.php?action=add&id=$p[id]'><img border='0' src='images/comment.png' alt='".$p['sub']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='$li'><img border='0' src='$im' alt='$te ".$p['title']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='news_cp.php?action=editnews&id=$p[id]'><img border='0' src='images/edit.gif' alt='".$p['sub']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='news_cp.php?action=deletenews&id=$p[id]'><img border='0' src='images/delete.gif' alt='".$p['sub']."' /></a></td>
    </tr>";
}
echo "</table>";

$pagesnum = @ceil(mysql_num_rows(mysql_query("SELECT id FROM news")) / $perpage);
if($pagesnum > 1){
echo "<p align='center'>";
for ($i=1; $i<=$pagesnum; $i++) {
if ($i != $page) {
$z = "[<a href='news_cp.php?action=addnews&page=$i'>$i</a>] ";
} else {
$z = "[<u>$i</u>]";
}
echo "$z";
}
echo "</p>";
}
}
}
}ELSEIF ($action=="actxx"){
$id = intval($_GET['id']);
$act = intval($_GET['act']);
if ($act == 0){
$query =  mysql_query("UPDATE news SET active='$act' where id='$id'");
echo $LANGAUGE_CP[61];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=news_cp.php?action=addnews' />";
}elseif($act == 1){
$query =  mysql_query("UPDATE news SET active='$act' where id='$id'");
echo $LANGAUGE_CP[62];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=news_cp.php?action=addnews' />";
}else{
echo $LANGAUGE_CP[63];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=news_cp.php?action=addnews' />";
}

}ELSEIF ($action=="insertnews"){

$title = addslashes($_POST['sub']);
$title = trim($title);
$imx  = addslashes($_POST['im']);
$imx = trim($imx);
$im2  = addslashes($_POST['im2']);
$im2 = trim($im2);
$short  = addslashes($_POST['short']);
$short = trim($short);
$text  = addslashes($_POST['text']);
$text = trim($text);
$cat = intval($_POST['cat']);
$datex = time();
$editor  = addslashes($_POST['editor']);
$editor = trim($editor);
$url  = addslashes($_POST['url']);

$keywords  = addslashes($_POST['keywords']);
$keywords = trim($keywords);

if($keywords==""){
$m2x = str_replace(" ",",",$title);
$xm2 = $m2x;
}else{
$xm2 = $keywords;
}

$fileName = $_FILES['image']['name'];
$tmpName  = $_FILES['image']['tmp_name'];
$fileSize = $_FILES['image']['size'];
$fileType = $_FILES['image']['type'];

if (empty($title)){
echo $LANGAUGE_CP[334];
}elseif (empty($text)){
echo $LANGAUGE_CP[335];
}else{
if(!empty($fileName)){
$timex = time();
$time = date("jnY",$timex);
$ext = substr(strrchr($fileName, "."), 1);

if($ext == "gif" or $ext == "GIF" or $ext == "jpg" or $ext == "jpeg" or $ext == "png"){

$randName = md5(rand() * time());
$randName = substr($randName, 0, 5);
$filePath = $pfolder . $time . '-' . $randName . '.' . $ext;
$folderth = $folderthumbs . $time . '-' . $randName . '.' . $ext;
$pathimages = str_replace("../","",$filePath);
$pathimagest = str_replace("../","",$folderth);
$result = move_uploaded_file($tmpName, $filePath);
if($result){
$fi = $pathimages;

if($ext=="jpg" || $ext=="JPG"){
$im = imagecreatefromjpeg($filePath);
$ox = imagesx( $im );
$oy = imagesy( $im );
$nm = imagecreatetruecolor( $wth, $hth );
imagecopyresized( $nm, $im, 0, 0, 0, 0, $wth, $hth, $ox, $oy );
imagejpeg( $nm,$folderth,100);
$thhhh = $pathimagest;
}

if($ext=="gif" || $ext=="GIF"){
$im = imagecreatefromgif($filePath);
$ox = imagesx( $im );
$oy = imagesy( $im );
$nm = imagecreatetruecolor( $wth, $hth );
imagecopyresized( $nm, $im, 0, 0, 0, 0, $wth, $hth, $ox, $oy );
imagegif( $nm,$folderth,100);
$thhhh = $pathimagest;
}
/*
if($ext=="png" || $ext=="PNG"){
$im = imagecreatefrompng($filePath);
$ox = imagesx( $im );
$oy = imagesy( $im );
$nm = imagecreatetruecolor( $wth, $hth );
imagecopyresized( $nm, $im, 0, 0, 0, 0, $wth, $hth, $ox, $oy );
imagepng( $nm,$folderth,100);
$thhhh = $pathimagest;
}
*/
}else{
$fi = "";
}
}
}

if($imx==""){
$yyy = $fi;
}else{
$yyy = $imx;
}

if($im2==""){
$yyy1 = $thhhh;
}else{
$yyy1 = $im2;
}

$query =  mysql_query ("INSERT INTO news (sub,news,short,image,cat,date,editor,url,bbcodes,thumbs,keywords) VALUES ('$title','$text','$short','$yyy','$cat','$datex','$editor','$url','1','$yyy1','$xm2')") or die ("error");
echo $LANGAUGE_CP[21];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=news_cp.php?action=addnews' />";
}



}ELSEIF ($action=="editnews"){
$id = intval($_GET['id']);
$query = mysql_query("SELECT * FROM news where id='$id'");
$p = mysql_fetch_array($query);

$p['sub'] = stripslashes($p['sub']);
$p['sub'] = htmlspecialchars($p['sub']);

$p['url'] = stripslashes($p['url']);
$p['url'] = htmlspecialchars($p['url']);

$p['image'] = stripslashes($p['image']);
$p['image'] = htmlspecialchars($p['image']);

$p['news'] = stripslashes($p['news']);
$p['news'] = htmlspecialchars($p['news']);

$p['short'] = stripslashes($p['short']);
$p['short'] = htmlspecialchars($p['short']);

$p['editor'] = stripslashes($p['editor']);
$p['editor'] = htmlspecialchars($p['editor']);

$p['thumbs'] = stripslashes($p['thumbs']);
$p['thumbs'] = htmlspecialchars($p['thumbs']);

$p['keywords'] = stripslashes($p['keywords']);
$p['keywords'] = htmlspecialchars($p['keywords']);

echo "<form name='vbform' method='POST' action='news_cp.php?action=editnewsok'>
<input type='hidden' name='id' value='$p[id]' />

<table class='xtable' width='100%' id='AutoNumber15'>

<tr>
<td width='100%' colspan='2' class='xtx' align='center'>".$LANGAUGE_CP[32]."</td>
</tr>

<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[324]."</td>
<td width='80%' class='xtd'><input name='sub' size='60' value='".$p['sub']."' /></td>
</tr>

<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[324]."</td>
<td width='80%' class='xtd'><input name='editor' size='60' value='".$p['editor']."' /></td>
</tr>


<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[336]."</td>
<td width='80%' class='xtd'><input dir='ltr' name='image' size='60' value='".$p['image']."' /></td>
</tr>

<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[337]."</td>
<td width='80%' class='xtd'><input dir='ltr' name='thumbs' size='60' value='".$p['thumbs']."' /></td>
</tr>

<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[236]."</td>
<td width='80%' class='xtd'><input name='url' size='60' value='".$p['url']."'></td>
</tr>

<tr>
<td width='100%' class='xtd' colspan='2' align='center'>
".$LANGAUGE_CP[330]."<textarea name='keywords' rows='3' cols='90'>".$p['keywords']."</textarea>
</td>
</tr>


<tr>
<td width='100%' class='xtd' colspan='2' align='center'>
".$LANGAUGE_CP[331]."<textarea id='textarea1' name='short' rows='5' cols='90'>".$p['short']."</textarea>
</td>
</tr>

<tr>
<td width='100%' class='xtd' colspan='2' align='center'>
".$LANGAUGE_CP[332]."<textarea id='textarea2' name='news' rows='15' cols='60'>".$p['news']."</textarea>
</td>
</tr>

<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[95]."</td>
<td width='80%' class='xtd'>
<select size='1' name='cat'>";

$sql = mysql_query ("SELECT * FROM news_cat order by id") or die ("error");
while($sub = mysql_fetch_array($sql))
{
$sub['name'] = stripslashes($sub['name']);
$sub['name'] = htmlspecialchars($sub['name']);

if($sub['id'] ==  $p['cat']){
echo "<option value='$sub[id]' selected='selected'>".$sub['name']."</option>";
}else{
echo "<option value='$sub[id]'>".$sub['name']."</option>";
}

}
echo "</select>
</td>
</tr>

<tr>
<td width='100%' colspan='2' align='center' class='xtr'><input type='submit' value=' ".$LANGAUGE_CP[33]." ' name='B1' /> <input type='submit' value=' ".$LANGAUGE_CP[154]." ' name='re' /></td>
</tr>

</table>
</form>";

}ELSEIF ($action=="editnewsok"){

$id    = intval($_POST['id']);
$title = addslashes($_POST['sub']);
$title = trim($title);
$image  = addslashes($_POST['image']);
$image = trim($image);
$short  = addslashes($_POST['short']);
$short = trim($short);
$text  = addslashes($_POST['news']);
$text = trim($text);
$cat = intval($_POST['cat']);
$editor  = addslashes($_POST['editor']);
$editor = trim($editor);
$url  = addslashes($_POST['url']);

$thumbs  = addslashes($_POST['thumbs']);
$thumbs = trim($thumbs);

$keywords = addslashes($_POST['keywords']);
$keywords = trim($keywords);


if (empty($title)){
echo $LANGAUGE_CP[334];
}elseif (empty($text)){
echo $LANGAUGE_CP[335];

}else{
$query =  mysql_query("UPDATE news SET sub='$title', news='$text', image='$image', short='$short', cat='$cat', editor='$editor', url='$url',thumbs='$thumbs',keywords='$keywords' where id='$id'");
echo $LANGAUGE_CP[34];
if(isset($_POST['re'])){
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=news_cp.php?action=editnews&id=".$id."' />";
}else{
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=news_cp.php?action=addnews' />";
}
}

}ELSEIF ($action=="deletenews"){
$id = intval($_GET['id']);
$query =  mysql_query("DELETE FROM news WHERE id='$id'");
echo $LANGAUGE_CP[35];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=news_cp.php?action=addnews' />";

}ELSEIF ($action=="setting"){
$sql = "SELECT * FROM opitions where id=1";
$result = mysql_query ($sql) or die ("Query failed");
$p_cats = mysql_fetch_array($result);
$p_cats['d12'] = stripslashes($p_cats['d12']);
$p_cats['d12'] = htmlspecialchars($p_cats['d12']);

$p_cats['k12'] = stripslashes($p_cats['k12']);
$p_cats['k12'] = htmlspecialchars($p_cats['k12']);

$td1 = "70%";
$td2 = "30%";

echo "<form method='POST' action='news_cp.php?action=update'>

<table class='xtable' width='100%' id='AutoNumber15'>

<tr>
<td width='100%' colspan='2' class='xtt' align='center'>".$LANGAUGE_CP[338]."</td>
</tr>

<tr>
<td width='$td1' class='xtr'>".$LANGAUGE_CP[339]."</td>
<td width='$td2' class='xtd'><input name='num_news' size='3' value='$p_cats[num_news]' />";

echo " <select size='1' name='table_news'>";
if ($p_cats[table_news]=="1"){
echo "<OPTION value='1' selected='selected'>".$LANGAUGE_CP[340]."</OPTION>
<OPTION value='2'>".$LANGAUGE_CP[341]."</OPTION>
<OPTION value='3'>".$LANGAUGE_CP[342]."</OPTION>";
}elseif($p_cats[table_news]=="2"){
echo "<OPTION value='2' selected='selected'>".$LANGAUGE_CP[341]."</OPTION>
<OPTION value='1'>".$LANGAUGE_CP[340]."</OPTION>
<OPTION value='3'>".$LANGAUGE_CP[342]."</OPTION>";
}elseif($p_cats[table_news]=="3"){
echo "<OPTION value='2'>".$LANGAUGE_CP[341]."</OPTION>
<OPTION value='1'>".$LANGAUGE_CP[340]."</OPTION>
<OPTION value='3' selected='selected'>".$LANGAUGE_CP[342]."</OPTION>";
}
echo "</select>";

echo "</td>
</tr>";

echo "<tr>
<td width='$td1' class='xtr'>".$LANGAUGE_CP[343]."</td>
<td width='$td2' class='xtd'><input name='threadsloop' size='10' value='$p_cats[threadsloop]' /></td>
</tr>

<tr>
<td width='$td1' class='xtr'>".$LANGAUGE_CP[344]."</td>
<td width='$td2' class='xtd'><input name='catsloop' size='10' value='$p_cats[catsloop]' /></td>
</tr>

<tr>
<td width='$td1' class='xtr'>".$LANGAUGE_CP[345]."</td>
<td width='$td2' class='xtd'><input name='archivethreadsnumber' size='10' value='$p_cats[archivethreadsnumber]' /></td>
</tr>

<tr>
<td width='$td1' class='xtr'>".$LANGAUGE_CP[346]."</td>
<td width='$td2' class='xtd'><input name='limitmenu_news' size='10' value='$p_cats[limitmenu_news]' /></td>
</tr>

<tr>
<td width='$td1' class='xtr'>".$LANGAUGE_CP[347]."</td>
<td width='$td2' class='xtd'>";
echo " <select size='1' name='foldernews'>";

if($p_cats['foldernews'] == ""){
$result = mysql_query ("SELECT * FROM pathstyle") or die ("Query failed");
while ($p_s=mysql_fetch_array($result))
{
$p_s['name'] = stripslashes($p_s['name']);
$p_s['name'] = htmlspecialchars($p_s['name']);

$p_s['pathfolder'] = stripslashes($p_s['pathfolder']);
$p_s['pathfolder'] = htmlspecialchars($p_s['pathfolder']);

if($p_s['pathfolder'] == $p_cats['folder']){
echo "<option value='".$p_s['pathfolder']."' selected='selected'>".$p_s['name']."</option>";
}else{
echo "<option value='".$p_s['pathfolder']."'>".$p_s['name']."</option>";
}
}

}else{

$result = mysql_query ("SELECT * FROM pathstyle") or die ("Query failed");
while ($p_s=mysql_fetch_array($result))
{
$p_s['name'] = stripslashes($p_s['name']);
$p_s['name'] = htmlspecialchars($p_s['name']);

$p_s['pathfolder'] = stripslashes($p_s['pathfolder']);
$p_s['pathfolder'] = htmlspecialchars($p_s['pathfolder']);

if($p_s['pathfolder'] == $p_cats['foldernews']){
echo "<option value='".$p_s['pathfolder']."' selected='selected'>".$p_s['name']."</option>";
}else{
echo "<option value='".$p_s['pathfolder']."'>".$p_s['name']."</option>";
}
}
}


echo "</select>";

echo "</td>
</tr>

<tr>
<td width='100%' colspan='2' class='xtd' align='center'>
".$LANGAUGE_CP[123]."
<textarea name='k12' rows='3' cols='70'>".$p_cats['k12']."</textarea><br /><br />
".$LANGAUGE_CP[124]."
<textarea name='d12' rows='3' cols='70'>".$p_cats['d12']."</textarea>
</td>
</tr>

<tr>
<td width='100%' colspan='2' align='center' class='xtr'><input type='submit' value=' ".$LANGAUGE_CP[33]." ' name='B1' /></td>
</tr>

</table>

</form>";
}ELSEIF ($action=="update"){
$num_news    = $_POST['num_news'];
$table_news  = $_POST['table_news'];
$threadsloop          = $_POST['threadsloop'];
$catsloop             = $_POST['catsloop'];
$archivethreadsnumber = $_POST['archivethreadsnumber'];
$foldernews = $_POST['foldernews'];
$limitmenu_news = $_POST['limitmenu_news'];

$k12 = addslashes($_POST['k12']);
$d12 = addslashes($_POST['d12']);

$query1 =  mysql_query("UPDATE opitions SET
num_news='$num_news',
table_news='$table_news',
threadsloop='$threadsloop',
catsloop='$catsloop',
archivethreadsnumber='$archivethreadsnumber',foldernews='$foldernews',limitmenu_news='$limitmenu_news',k12='$k12',d12='$d12' where id='1'");
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=news_cp.php?action=setting' />";
}
echo $f;
?>