<?php
include('header.php');
if($xg12 != 1){
echo $h;
echo $LANGAUGE_CP[626];
echo $f;
exit;
}
echo $h;

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

IF ($action=="add"){
?>

<form name="vbform" method="post" action="story_cp.php?action=insert" enctype="multipart/form-data">

<table class='xtable' width="100%" id="AutoNumb00er1">
     <tr>
      <td width="100%" colspan="2" class='xtx' align="center"><?php echo $LANGAUGE_CP[497]; ?></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[156]; ?></td>
      <td width="80%" class='xtd'><input size="70" name="name_cat" /></td>
    </tr>
 <!--
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[88]; ?></td>
      <td width="80%" class='xtd'><input dir="ltr" size="30" name="im" /> <?php echo $LANGAUGE_CP[89]; ?><br />
<input dir="ltr" size="30" name="image" type="file" /> <?php echo $LANGAUGE_CP[90]; ?></td>
    </tr>
    -->
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[91]; ?></td>
      <td width="80%" class='xtd'><textarea name="keywords" rows="3" cols="70"></textarea></td>
    </tr>
    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[92]; ?></td>
      <td width="80%" class='xtd'><textarea name="description" rows="3" cols="70"></textarea></td>
    </tr>

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

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

     <tr>
      <td width="100%" colspan="2" 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 story_cat order by id desc");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo "";
}else{

echo "<table class='xtable' width='100%' id='AutoN00umber15'>
  <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_cat'] = stripslashes($p['name_cat']);
$p['name_cat'] = htmlspecialchars($p['name_cat']);

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

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

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

$name      = addslashes($_POST['name_cat']);
$order_cat = addslashes($_POST['order_cat']);
$sub       = addslashes($_POST['sub']);

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

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

if($description==""){
$xm1 = $name;
}else{
$xm1 = $description;
}

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

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

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

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

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

$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']);

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

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

<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_cat' size='60' value='".$p['name_cat']."' /></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='30%' class='xtr'>".$LANGAUGE_CP[95]."</td>
<td width='70%' class='xtd'>
<select size='1' name='sub'>";
echo "<option value='0'>".$LANGAUGE_CP[96]."</option>";
$sql = mysql_query ("SELECT * FROM story_cat where sub=0 AND id != '$id'") or die ("error");
while($sub = mysql_fetch_array($sql))
{
if($sub['id'] ==  $p['sub']){
echo "<option value='$sub[id]' selected='selected'>$sub[name_cat]</option>";
}else{
echo "<option value='$sub[id]'>$sub[name_cat]</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']);
$name      = addslashes($_POST['name_cat']);
$order_cat = addslashes($_POST['order_cat']);
$sub       = addslashes($_POST['sub']);

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

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

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

if($description==""){
$xm1 = $name;
}else{
$xm1 = $description;
}

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

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

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

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

}ELSEIF ($action=="addtext"){
?>
<form name="vbform" method="post" action="story_cp.php?action=inserttext">

<table class='xtable' width='100%' id='AutoNumb4er15'>
     <tr>
      <td width="100%" colspan="2" class='xtx' align="center"><?php echo $LANGAUGE_CP[498]; ?></td>
    </tr>

<?php
echo "<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[499]."</td>
<td width='80%' class='xtd'><input size='70'  name='name' /></td>
</tr>

<tr>
      <td width='20%' class='xtr'>".$LANGAUGE_CP[91]."</td>
      <td width='80%' class='xtd'><textarea name='keywords' rows='3' cols='70'></textarea></td>
    </tr>
    <tr>
      <td width='20%' class='xtr'>".$LANGAUGE_CP[92]."</td>
      <td width='80%' class='xtd'><textarea name='description' rows='3' cols='70'></textarea></td>
    </tr>

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

<tr>
<td width='100%' class='xtd' colspan='2' align='center'>
".$LANGAUGE_CP[500]."<textarea id='textarea1' rows='15' name='text' cols='100'></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  story_cat order by id desc");
while($cat=mysql_fetch_array($sql))
{
echo "<OPTION value='".$cat['id']."'>".$cat['name_cat']."</OPTION>";
}
echo "</select>";
echo "</td>
</tr>";
?>

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

</table>
</form>

<?php
if($_GET["s"] == 1){
$hh = "checked='checked'";
}elseif($_GET["s"] == 0){
$hh = "";
}else{
$hh = "";
}

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

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

$i = 0;
echo "<form name='xxx' action='story_cp.php?action=op' method='post'>
<div id='story'>
<table class='xtable' width='100%' id='AutoNumbe4r15'>
<tr>
<td width='100%' colspan='7' class='xtt' align='center'>".$LANGAUGE_CP[97]."</td>
</tr>
<tr>
      <td width='2%' align='center' class='xtr'>#</td>
      <td width='40%' align='center' class='xtr'>".$LANGAUGE_CP[501]."</td>
      <td width='30%' align='center' class='xtr'>".$LANGAUGE_CP[237]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[106]."</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))
{
$i++;
$p['name'] = stripslashes($p['name']);
$p['name'] = htmlspecialchars($p['name']);

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

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

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

echo "<tr>
      <td align='center' width='2%' class='xtd'><input id='st".$p['id']."' ".$hh." type='checkbox' name='del[$i]' value='".$p['id']."' /></td>
      <td width='40%' class='xtd'><label for='st".$p['id']."'>» ".$p['name']."</label></td>
      <td width='30%' class='xtd' align='center'>".$pc['name_cat']."</td>
      <td width='7%' class='xtd' align='center'>".$p['vis']."</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='story_cp.php?action=edittext&id=$p[id]'><img border='0' src='images/edit.gif' alt='".$p['name']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='story_cp.php?action=deletetext&id=$p[id]'><img border='0' src='images/delete.gif' alt='".$p['name']."' /></a></td>
    </tr>";
}
echo "<tr>
<td colspan='7' align='center' class='xtr'><input name='activ' class='addsubmit' type='submit' value=' ".$LANGAUGE_CP[108]." ' /> <input class='addsubmit' name='noact' type='submit' value=' ".$LANGAUGE_CP[107]." ' /> <input name='delete' class='addsubmit' type='submit' id='delete' value=' ".$LANGAUGE_CP[27]." ' /><br />
<a href='story_cp.php?action=addtext&s=1&page=$page#story'>".$LANGAUGE_CP[109]."</a> - <a href='story_cp.php?action=addtext&s=0&page=$page#story'>".$LANGAUGE_CP[110]."</a></td>
</tr>
</table></div></form>";

$pagesnum = @ceil(mysql_num_rows(mysql_query("SELECT id FROM story")) / $perpage);
if($pagesnum > 1){
echo "<p align='center'>";
for ($i=1; $i<=$pagesnum; $i++) {
if ($i != $page) {
$z = "[<a href='story_cp.php?action=addtext&page=$i'>$i</a>] ";
} else {
$z = "[<u>$i</u>]";
}
echo "$z";
}
echo "</p>";
}
}
}ELSEIF ($action=="inserttext"){

$name = addslashes($_POST['name']);
$text = addslashes($_POST['text']);
$url = addslashes($_POST['url']);
$cat = addslashes($_POST['cat']);

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

if($description==""){
$xm1 = $name;
}else{
$xm1 = $description;
}

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

$d = time();

if($name == ""){
echo $LANGAUGE_CP[502];
}elseif($text == ""){
echo $LANGAUGE_CP[503];
}else{
$query = mysql_query ("INSERT INTO story (name,text,url,cat,date,description,keywords,active) VALUES ('".$name."','".$text."','".$url."','".$cat."','$d','$xm1','$xm2','1')");
echo $LANGAUGE_CP[21];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=story_cp.php?action=addtext#story' />";
}



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

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

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

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

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

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

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

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

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

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

<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[91]."</td>
<td width='80%' 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='20%' class='xtr'>".$LANGAUGE_CP[236]."</td>
<td width='80%' class='xtd'><input dir='ltr' name='url' size='60' value='".$p['url']."' /></td>
</tr>

<tr>
<td width='100%' class='xtd' colspan='2' align='center'>".$LANGAUGE_CP[500]."<textarea id='textarea1' rows='15' name='text' cols='100'>".$p['text']."</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 story_cat order by id") or die ("error");
while($sub = mysql_fetch_array($sql))
{
if($sub['id'] ==  $p['cat']){
echo "<option value='$sub[id]' selected='selected'>$sub[name_cat]</option>";
}else{
echo "<option value='$sub[id]'>$sub[name_cat]</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=="edittextok"){

$id    = intval($_POST['id']);
$name = addslashes($_POST['name']);
$text = addslashes($_POST['text']);
$url = addslashes($_POST['url']);
$cat = addslashes($_POST['cat']);

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

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

if($description==""){
$xm1 = $name;
}else{
$xm1 = $description;
}

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

if (empty($name)){
echo $LANGAUGE_CP[502];
}elseif (empty($text)){
echo $LANGAUGE_CP[503];
}else{
$query =  mysql_query("UPDATE story SET name='$name', text='$text', url='$url', cat='$cat', description='$xm1', keywords='$xm2' where id='$id'");
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=story_cp.php?action=addtext#story' />";
}

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

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

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

if(isset($_POST['delete'])){
if(count($_POST['del']) > 0){
$del_id = join(',',$_POST['del']);
$sql = mysql_query("DELETE FROM story WHERE id IN($del_id)");
print $LANGAUGE_CP[35];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=story_cp.php?action=addtext#story' />";
}else{
echo $LANGAUGE_CP[255];
}
}


if(isset($_POST['noact'])){
if(count($_POST['del']) > 0){
$del_id = join(',',$_POST['del']);
$sql = mysql_query("UPDATE story SET active='0' WHERE id IN($del_id)");
print $LANGAUGE_CP[61];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=story_cp.php?action=addtext#story' />";
}else{
echo $LANGAUGE_CP[255];
}
}

if(isset($_POST['activ'])){
if(count($_POST['del']) > 0){
$del_id = join(',',$_POST['del']);
$sql = mysql_query("UPDATE story SET active='1' WHERE id IN($del_id)");
print $LANGAUGE_CP[62];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=story_cp.php?action=addtext#story' />";
}else{
echo $LANGAUGE_CP[255];
}
}

}
echo $f;
?>