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

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

IF ($action=="add"){
?>
<form name="vbform" method="post" action="links_cp.php?action=insert">

<table class='xtable' width="100%" id="AutoNumber1">
     <tr>
      <td width="100%" colspan="2" class='xtx' align="center"><?php echo $LANGAUGE_CP[292]; ?></td>
    </tr>
    <tr>
      <td width="35%" class='xtr'><?php echo $LANGAUGE_CP[156]; ?></td>
      <td width="65%" class='xtd'><input size="60" name="name_cat" /></td>
    </tr>

    <tr>
      <td width="35%" class='xtr'><?php echo $LANGAUGE_CP[91]; ?></td>
      <td width="65%" class='xtd'><textarea name="keywords" rows="3" cols="60"></textarea></td>
    </tr>
    <tr>
      <td width="35%" class='xtr'><?php echo $LANGAUGE_CP[92]; ?></td>
      <td width="65%" class='xtd'><textarea name="description" rows="3" cols="60"></textarea></td>
    </tr>

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

<tr>
<td width='35%' class='xtr'><?php echo $LANGAUGE_CP[95]; ?></td>
<td width='65%' class='xtd'>
<select  size='1' name='sub'>
<OPTION value='0' selected="selected"><?php echo $LANGAUGE_CP[96]; ?></OPTION>
<?php
$sql = mysql_query ("SELECT * FROM  dlil_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 dlil_cat order by id desc");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo "";
}else{

echo "<table class='xtable' width='100%' id='AutoNum56ber15'>
<tr>
<td width='100%' colspan='5' class='xtt' align='center'>".$LANGAUGE_CP[97]."</td>
</tr>

  <tr>
      <td width='72%' align='center' class='xtr'>".$LANGAUGE_CP[158]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[293]."</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 = "links_cp.php?action=actxcat&id=$p[id]&act=0";
$te = $LANGAUGE_CP[72];
}else{
$im = "images/off.gif";
$li = "links_cp.php?action=actxcat&id=$p[id]&act=1";
$te = $LANGAUGE_CP[73];
}

$sites = mysql_num_rows(mysql_query("SELECT * FROM islam_dlil where cat='$p[id]'"));

echo "<tr>
      <td width='72%' class='xtd'>» <a href='links_cp.php?action=addt&c=$p[id]'>".$p['name_cat']."</a></td>
<!--      <td width='7%' align='center' class='xtd'><a href='links_cp.php?action=addt&c=$p[id]'>$sites</a></td>-->
      <td width='7%' align='center' class='xtd'>$sites</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='links_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='links_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"){

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

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

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

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

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

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

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


}ELSEIF ($action=="edit"){
$id = intval($_GET['id']);
$query = mysql_query("SELECT * FROM dlil_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']);

echo "<form name='vbform' method='POST' action='links_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_cat' size='60' value='".$p['name_cat']."' /></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='cat'>";
echo "<option value='0'>".$LANGAUGE_CP[96]."</option>";
$sql = mysql_query ("SELECT * FROM dlil_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[18]." ' name='B1' /></td>
</tr>

</table>
</form>";

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

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

$order_cat = intval($_POST['order_cat']);
$cat = intval($_POST['cat']);

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

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

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

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

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

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

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

}ELSEIF ($action=="addt"){
$queryx = mysql_query("SELECT * FROM dlil_cat");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo '<a href="links_cp.php?action=add">'.$LANGAUGE_CP[629].'</a>';
}else{

if(isset($_GET['num']) AND $_GET['num'] != 0){
$number = intval($_GET['num']);
$xcatss = intval($_GET['xcat']);
}else{
$number = 1;
}
if(!isset($_GET["activesite"])){
?>
<table class='xtable' width='100%' id='AutoNumber15'>
     <tr>
      <td width="100%" colspan="2" class='xtx' align="center"><?php echo $LANGAUGE_CP[294]; ?></td>
    </tr>

     <tr>
      <td width="100%" colspan="2" class='xtr' align="center">
<form name="vbform" method="GET" action="">
<input name="action" type="hidden" value="addt" />
<div align="center"><?php echo $LANGAUGE_CP[101]; ?> <input name="num" type="text" size="10" value="<?php echo $number; ?>" /> <?php echo $LANGAUGE_CP[102]; ?> <select size="1" name="xcat">
<?php
$query = mysql_query("SELECT * FROM dlil_cat order by id ASC, sub desc");
while($cat = mysql_fetch_array($query))
{
if($cat['sub'] == 0){
$rrr = "&nbsp;".$cat['name_cat']."";
}else{
$rrr = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$cat['name_cat']."";
}

if(isset($_GET['xcat']) AND $_GET['xcat'] == $cat['id']){
echo "<OPTION value='".$cat['id']."' selected='selected'>".$rrr."</OPTION>";
}else{
echo "<OPTION value='".$cat['id']."'>".$rrr."</OPTION>";
}

}
?>
</select> <input type="submit" value=" <?php echo $LANGAUGE_CP[12]; ?> " class='addsubmit'></div>
</form>
      </td>
    </tr>



<form name="vbform" method="post" action="links_cp.php?action=insertt">
<?php
$ii = 0;
for($i=0;$i<$number;$i++){
$ii++;
?>

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

    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[296]; ?></td>
      <td width="80%" class='xtd'><input dir="ltr" size="80" name='url_site[]' /></td>
    </tr>

    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[92]; ?></td>
      <td width="80%" class='xtd'><textarea name='text_site[]' rows='3' cols='80'></textarea></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='80'></textarea></td>
    </tr>

    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[297]; ?></td>
      <td width="80%" class='xtd'><select size='1' name='lang[]'>
<option value='0' selected='selected'><?php echo $LANGAUGE_CP[298]; ?></option>
<option value='1'><?php echo $LANGAUGE_CP[299]; ?></option>
</select></td>
    </tr>

    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[95]; ?></td>
      <td width="80%" class='xtd'>
<select size="1" name="cat[]">
<?php
$query = mysql_query("SELECT * FROM dlil_cat order by  id ASC, sub desc");
while($cat = mysql_fetch_array($query))
{
if($cat['sub'] == 0){
$rrr = "&nbsp;".$cat['name_cat']."";
}else{
$rrr = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$cat['name_cat']."";
}
if(isset($_GET['xcat']) AND $_GET['xcat'] == $cat['id']){
echo "<OPTION value='".$cat['id']."' selected='selected'>".$rrr."</OPTION>";
}else{
echo "<OPTION value='".$cat['id']."'>".$rrr."</OPTION>";
}

}
?>
</select>
      </td>
    </tr>

<?php
if($ii != $number){
echo '<tr>
<td width="100%" colspan="2" class="xtr" align="center">- - - - - - - -</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 = "";
}

if(isset($_GET["c"]) AND intval($_GET["c"]) != 0){
$cc = "AND cat='".intval($_GET["c"])."'";
$cp = "&c=".intval($_GET["c"]);
if(isset($_GET["activesite"]) AND intval($_GET["activesite"]) != 0){
$ct = "<br /><a href='links_cp.php?action=addt&activesite=1'>".$LANGAUGE_CP[300]."</a>";
}else{
$ct = "<br /><a href='links_cp.php?action=addt'>".$LANGAUGE_CP[301]."</a>";
}
}else{
$cc = "";
$cp = "";
$ct = "";
}

if(isset($_GET["activesite"]) AND intval($_GET["activesite"]) != 0){
$aaa = 0;
$inp = 1;
$ass = "&activesite=".intval($_GET["activesite"]);
}else{
$aaa = 1;
$inp = 0;
$ass = "";
}

if(!isset($_GET['num']) AND !isset($_GET['xcat'])){
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$page = ($page == 0 ? 1 : $page);
$perpage = 30;
$startpoint = ($page * $perpage) - $perpage;

$queryx = mysql_query("SELECT * FROM islam_dlil where active='".$aaa."' ".$cc." order by id desc LIMIT $startpoint,$perpage");
$xx = mysql_num_rows($queryx);
if($xx == 0){
if(isset($_GET["activesite"]) AND intval($_GET["activesite"]) != 0){
echo $LANGAUGE_CP[302];
}else{
echo "";
}
}else{

$i = 0;
echo "<form name='xxx' action='links_cp.php?action=op' method='post'>
<input name='actt' type='hidden' value='".$inp."' />
<div id='links'>
<table class='xtable' width='100%' id='AutoNu4mber15'>
<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[303]."</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_site'] = stripslashes($p['name_site']);
$p['name_site'] = htmlspecialchars($p['name_site']);

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

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

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

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

echo "<tr>
      <td align='center' width='2%' class='xtd'><input id='sound".$p['id']."' ".$hh." type='checkbox' name='del[$i]' value='".$p['id']."' /></td>
      <td width='40%' class='xtd'><label title='".$p['url_site']."' for='sound".$p['id']."'>» <a href='".$p['url_site']."' target='_blank'>".$p['name_site']."</a></label></td>
      <td width='30%' class='xtd' align='center'><a href='links_cp.php?action=addt&c=".$p['cat']."".$ass."'>".$pc['name_cat']."</a></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 ".$rrr."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='links_cp.php?action=editt&id=$p[id]&page=$page".$cp."".$ass."'><img border='0' src='images/edit.gif' alt='".$p['name_site']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='links_cp.php?action=deletet&id=$p[id]&page=$page".$cp."".$ass."'><img border='0' src='images/delete.gif' alt='".$p['name_site']."' /></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 class='addsubmit' name='edit' type='submit' value=' ".$LANGAUGE_CP[26]." ' /> <input name='delete' class='addsubmit' type='submit' id='delete' value=' ".$LANGAUGE_CP[27]." ' /><br />
<a href='links_cp.php?action=addt&s=1&page=$page".$cp."".$ass."#links'>".$LANGAUGE_CP[109]."</a> - <a href='links_cp.php?action=addt&s=0&page=$page".$cp."".$ass."#links'>".$LANGAUGE_CP[110]."</a>".$ct."</td>
</tr>
</table></div></form>";

$pagesnum = @ceil(mysql_num_rows(mysql_query("SELECT id FROM islam_dlil where active='".$aaa."' ".$cc."")) / $perpage);
if($pagesnum > 1){
echo "<p align='center'>";
for ($i=1; $i<=$pagesnum; $i++) {
if ($i != $page) {
$z = "[<a href='links_cp.php?action=addt&page=$i".$cp."".$ass."#links'>$i</a>] ";
} else {
$z = "[<u>$i</u>]";
}
echo "$z";
}
echo "</p>";
}
}
}
}

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

$number = count($_POST['name_site']);

for($i=0;$i<$number;$i++){
$name = $_POST['name_site'][$i];
$name = addslashes($name);
$name = trim($name);

$text_site = $_POST['text_site'][$i];
$text_site = addslashes($text_site);
$text_site = trim($text_site);

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

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

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

$url = $_POST['url_site'][$i];
$url = addslashes($url);
$url = trim($url);

$lang = $_POST['lang'][$i];
$cat = $_POST['cat'][$i];
$d = time();

$ddddd = stripslashes($name);
$nnnnn = htmlspecialchars($ddddd);

if(!empty($name) OR !empty($url)){
$query =  mysql_query ("INSERT INTO islam_dlil (name_site,url_trteeb,text_site,active,cat,date,url_site,lang,keywords) VALUES ('$name','1','$xm1','1','$cat','".time()."','$url','$lang','$xm2')") or die ("error");
echo "<p>$nnnnn ....... ".$LANGAUGE_CP[111]."</p>";
}
}

echo "<META HTTP-EQUIV='refresh' CONTENT='3; URL=links_cp.php?action=addt#links' />";

}ELSEIF ($action=="actx"){
$id = intval($_GET['id']);
$act = intval($_GET['act']);

if(isset($_GET["activesite"]) AND intval($_GET["activesite"]) != 0){
$ass = "&activesite=1";
}else{
$ass = "";
}

if(isset($_GET['c']) AND intval($_GET['c']) != 0){
$cc = "&c=".intval($_GET['c']);
}else{
$cc = "";
}

if(isset($_GET['page']) AND intval($_GET['page']) != 0){
$pp = "&page=".intval($_GET['page']);
}else{
$pp = "";
}

if ($act == 0){
$query =  mysql_query("UPDATE islam_dlil SET active='$act' where id='$id'");
echo $LANGAUGE_CP[61];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=links_cp.php?action=addt".$cc."".$pp."".$ass."#links' />";
}elseif($act == 1){
$query =  mysql_query("UPDATE islam_dlil SET active='$act' where id='$id'");
echo $LANGAUGE_CP[62];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=links_cp.php?action=addt".$cc."".$pp."".$ass."#links' />";
}else{
echo $LANGAUGE_CP[63];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=links_cp.php?action=addt".$cc."".$pp."".$ass."#links' />";
}

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

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

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

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

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

if(isset($_GET["activesite"]) AND intval($_GET["activesite"]) != 0){
$ass = 1;
}else{
$ass = 0;
}

echo "<form name='vbform' method='POST' action='links_cp.php?action=edittok'>
<input type='hidden' name='id' value='$p[id]' />
<input type='hidden' name='cc' value='".intval($_GET['c'])."' />
<input type='hidden' name='pp' value='".intval($_GET['page'])."' />
<input type='hidden' name='as' value='".$ass."' />

<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[295]."</td>
<td width='80%' class='xtd'><input name='name_site' size='80' value='".$p['name_site']."' /></td>
</tr>

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

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

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

<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[297]."</td>
<td width='80%' class='xtd'>";

if($p['lang']==1){
echo "<select size='1' name='lang'>
  <option value='1' selected='selected'>".$LANGAUGE_CP[299]."</option>
  <option value='0'>".$LANGAUGE_CP[298]."</option>
</select>";
}else{
echo "<select size='1' name='lang'>
  <option value='1'>".$LANGAUGE_CP[299]."</option>
  <option value='0' selected='selected'>".$LANGAUGE_CP[298]."</option>
</select>";
}

echo "</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 dlil_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=="edittok"){

if(isset($_POST['cc']) AND intval($_POST['cc']) != 0){
$ccx = "&c=".intval($_POST['cc']);
}else{
$ccx = "";
}

if(isset($_POST['pp']) AND intval($_POST['pp']) != 0){
$ppx = "&page=".intval($_POST['pp']);
}else{
$ppx = "";
}

if(isset($_POST["as"]) AND intval($_POST["as"]) != 0){
$ass = "&activesite=1";
}else{
$ass = "";
}

$id    = intval($_POST['id']);
$name_site     = addslashes($_POST['name_site']);
$url_site    = addslashes($_POST['url_site']);
$text_site      = addslashes($_POST['text_site']);
$keywords = addslashes($_POST['keywords']);
$lang        = addslashes($_POST['lang']);
$cat            = $_POST['cat'];

if($text_site==""){
$xm1 = $name_site;
}else{
$xm1 = $text_site;
}

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

if (empty($name_site)){
echo $LANGAUGE_CP[304];
}elseif (empty($url_site)){
echo $LANGAUGE_CP[305];
}else{
$query =  mysql_query("UPDATE islam_dlil SET name_site='$name_site', keywords='$xm2', text_site='$xm1', url_site='$url_site', cat='$cat', lang='$lang' where id='$id'");
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=links_cp.php?action=addt".$ccx."".$ppx."".$ass."#links' />";
}

}ELSEIF ($action=="deletet"){
$id = intval($_GET['id']);
if(isset($_GET['c']) AND intval($_GET['c']) != 0){
$cc = "&c=".intval($_GET['c']);
}else{
$cc = "";
}

if(isset($_GET['page']) AND intval($_GET['page']) != 0){
$pp = "&page=".intval($_GET['page']);
}else{
$pp = "";
}

if(isset($_GET["activesite"]) AND intval($_GET["activesite"]) != 0){
$ass = "&activesite=1";
}else{
$ass = "";
}

$query =  mysql_query("DELETE FROM islam_dlil WHERE id='$id'");
echo $LANGAUGE_CP[35];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=links_cp.php?action=addt".$cc."".$pp."".$ass."#links' />";



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

if(isset($_POST['actt']) AND $_POST['actt']==1){
$activesite = "&activesite=1";
$dirnumbers = 1;
}else{
$activesite = "";
$dirnumbers = 0;
}

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


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

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

if(isset($_POST['edit'])){

if(count($_POST['del']) > 0){
$c = count($_POST['del']);

$del_id = join(',',$_POST['del']);
$queryx = mysql_query("SELECT * FROM islam_dlil where id IN($del_id) order by id desc");

echo "<form name='vbform' method='POST' action='links_cp.php?action=editall'>
<input name='activesite' type='hidden' value='$dirnumbers' />
<table class='xtable' width='100%' id='AutoNumber15555'>

<tr>
<td width='100%' colspan='2' class='xtt' align='center'>".$LANGAUGE_CP[32]."</td>
</tr>";
$ii = 0;
while($p = mysql_fetch_array($queryx))
{
++$ii;

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

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

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

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

echo "<input type='hidden' name='id[]' value='".$p['id']."' />
<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[295]."</td>
<td width='70%' class='xtd'><input name='name_site[]' size='80' value='".$p['name_site']."' /></td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[296]."</td>
<td width='70%' class='xtd'><input dir='ltr' name='url_site[]' size='80' value='".$p['url_site']."' /></td>
</tr>

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

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

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[297]."</td>
<td width='70%' class='xtd'>";

if($p['lang']==1){
echo "<select size='1' name='lang[]'>
  <option value='1' selected='selected'>".$LANGAUGE_CP[299]."</option>
  <option value='0'>".$LANGAUGE_CP[298]."</option>
</select>";
}else{
echo "<select size='1' name='lang'>
  <option value='1'>".$LANGAUGE_CP[299]."</option>
  <option value='0' selected='selected'>".$LANGAUGE_CP[298]."</option>
</select>";
}

echo "</td>
</tr>

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

$sql = mysql_query ("SELECT * FROM dlil_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='30%' class='xtr'>".$LANGAUGE_CP[117]."</td>
<td width='70%' class='xtd'>
<select size='1' name='active[]'>";
if($p['active'] == 1){
echo "<option value='1' selected='selected'>".$LANGAUGE_CP[108]."</option>";
echo "<option value='0'>".$LANGAUGE_CP[107]."</option>";
}else{
echo "<option value='1'>".$LANGAUGE_CP[108]."</option>";
echo "<option value='0' selected='selected'>".$LANGAUGE_CP[107]."</option>";
}
echo "</select>
</td>
</tr>";

if($ii != $c){
echo "<tr>
<td width='100%' colspan='2' align='center' class='xtr'>- - - - - - - -</td>
</tr>";
}

}

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

</table>
</form>";

}else{
echo $LANGAUGE_CP[255];
}

}

}ELSEIF ($action=="editall"){
if(isset($_POST['activesite']) AND $_POST['activesite']==1){
$activesite = "&activesite=1";
}else{
$activesite = "";
}

$number = count($_POST['id']);

for($i=0;$i<$number;$i++){
$id = $_POST['id'][$i];
$id = intval($id);

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

$text_site = $_POST['text_site'][$i];
$text_site = addslashes($text_site);
$text_site = trim($text_site);

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

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

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

$url = $_POST['url_site'][$i];
$url = addslashes($url);
$url = trim($url);

$lang = $_POST['lang'][$i];
$active = $_POST['active'][$i];
$cat = $_POST['cat'][$i];

$ddddd = stripslashes($name);
$nnnnn = htmlspecialchars($ddddd);

if(!empty($name) OR !empty($url)){
echo "<p>$nnnnn . . . ".$LANGAUGE_CP[111]."</p>";
$query =  mysql_query("UPDATE islam_dlil SET name_site='$name', text_site='$xm1', keywords='$xm2', url_site='$url', cat='$cat', lang='$lang' ,active='$active' where id='$id'");
}

}
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=links_cp.php?action=addt".$activesite."#links' />";

}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['d4'] = stripslashes($p_cats['d4']);
$p_cats['d4'] = htmlspecialchars($p_cats['d4']);

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

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

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

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

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

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

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

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

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

if($p_cats['folderlinks'] == ""){
$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['folderlinks']){
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='k4' rows='3' cols='70'>".$p_cats['k4']."</textarea><br /><br />
".$LANGAUGE_CP[124]."
<textarea name='d4' rows='3' cols='70'>".$p_cats['d4']."</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"){
$aldleel_catsloop     = $_POST['aldleel_catsloop'];
$aldleel_sitesloop    = $_POST['aldleel_sitesloop'];
$folderlinks = $_POST['folderlinks'];
$limitmenu_links = $_POST['limitmenu_links'];

$k4 = addslashes($_POST['k4']);
$d4 = addslashes($_POST['d4']);

$query1 =  mysql_query("UPDATE opitions SET
aldleel_catsloop='$aldleel_catsloop',
aldleel_sitesloop='$aldleel_sitesloop',folderlinks='$folderlinks',limitmenu_links='$limitmenu_links',k4='$k4',d4='$d4' where id='1'");
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=links_cp.php?action=setting' />";
}
echo $f;
?>