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

$sql = "SELECT * FROM opitions where id=1";
$result = mysql_query ($sql) or die ("Query failed");
$p_cats=mysql_fetch_array($result);
$nuuuuumftwa = $p_cats['addfatawaincp'];

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

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

<table class='xtable' width="100%" id="Au5toNumber1">
     <tr>
      <td width="100%" colspan="2" class='xtx' align="center"><?php echo $LANGAUGE_CP[245]; ?></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[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  fatawa_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 fatawa_cat order by id desc");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo "";
}else{

echo "<table class='xtable' width='100%' id='Au00toNumber15'>
  <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 = "fatawa_cp.php?action=actxcat&id=$p[id]&act=0";
$te = $LANGAUGE_CP[72];
}else{
$im = "images/off.gif";
$li = "fatawa_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='fatawa_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='fatawa_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;
}

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


}ELSEIF ($action=="edit"){
$id = intval($_GET['id']);
$query = mysql_query("SELECT * FROM fatawa_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='fatawa_cp.php?action=editok'>
<input type='hidden' name='id' value='$p[id]' />

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

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

<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[156]."</td>
<td width='80%' class='xtd'><input name='name_cat' size='60' value='".$p['name_cat']."' /></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='20%' class='xtr'>".$LANGAUGE_CP[92]."</td>
<td width='80%' class='xtd'><textarea name='description' rows='3' cols='60'>".$p['description']."</textarea>
</td>
</tr>

<tr>
<td width='20%' 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'>";
echo "<option value='0'>".$LANGAUGE_CP[96]."</option>";
$sql = mysql_query ("SELECT * FROM fatawa_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']);

$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($name)){
echo $LANGAUGE_CP[159];
}else{
$query = mysql_query("UPDATE fatawa_cat SET name_cat='$name', order_cat='$order_cat', sub='$sub', description='$xm1', keywords='$xm2' where id='$id'");
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=fatawa_cp.php?action=add' />";
}


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


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











}ELSEIF ($action=="addtext"){
$queryx = mysql_query("SELECT * FROM fatawa_cat");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo '<a href="fatawa_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;
}
?>
<table class='xtable' width='100%' id='AutoNumber15'>
     <tr>
      <td width="100%" colspan="2" class='xtx' align="center"><?php echo $LANGAUGE_CP[246]; ?></td>
    </tr>

     <tr>
      <td width="100%" colspan="2" class='xtr' align="center">
<form name="vbform" method="GET" action="">
<input name="action" type="hidden" value="addtext" />
<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 fatawa_cat order by id desc");
while($cat = mysql_fetch_array($query))
{
if(isset($_GET['xcat']) AND $_GET['xcat'] == $cat['id']){
echo "<OPTION value='".$cat['id']."' selected='selected'>".$cat['name_cat']."</OPTION>";
}else{
echo "<OPTION value='".$cat['id']."'>".$cat['name_cat']."</OPTION>";
}

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



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

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

    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[248]; ?></td>
      <td width="80%" class='xtd'><textarea name='name[]' rows='5' cols='80'></textarea></td>
    </tr>

    <tr>
      <td width="100%" class='xtd' colspan="2" align="center">
<?php echo $LANGAUGE_CP[249]; ?>
<script type='text/javascript'>edToolbar('mytxtarea<?php echo $i; ?>'); </script>
<textarea name='answer[]' id='mytxtarea<?php echo $i; ?>' rows='15' cols='120'></textarea><br /><br />

      </td>
    </tr>

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

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

    <tr>
      <td width="20%" class='xtr'><?php echo $LANGAUGE_CP[236]; ?></td>
      <td width="80%" class='xtd'><input dir="ltr" size="80" name='url[]' /></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 fatawa_cat order by id desc");
while($cat = mysql_fetch_array($query))
{
if(isset($_GET['xcat']) AND $_GET['xcat'] == $cat['id']){
echo "<OPTION value='".$cat['id']."' selected='selected'>".$cat['name_cat']."</OPTION>";
}else{
echo "<OPTION value='".$cat['id']."'>".$cat['name_cat']."</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 = "";
}

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

$queryx = mysql_query("SELECT * FROM fatawa order by id desc LIMIT $startpoint,$perpage");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo "";
}else{
$i = 0;
echo "<form name='xxx' action='fatawa_cp.php?action=op' method='post'>
<div id='fatawa'>
<table class='xtable' width='100%' id='AutoN4umber15'>
<tr>
<td width='100%' colspan='6' class='xtt' align='center'>".$LANGAUGE_CP[97]."</td>
</tr>
<tr>
      <td width='2%' align='center' class='xtr'>#</td>
      <td width='70%' align='center' class='xtr'>".$LANGAUGE_CP[252]."</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']);

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

if($p['title']==""){
$rrr = $p['name'];
}else{
$rrr = $p['title'];
}

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

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

$queryxc = mysql_query("SELECT * FROM fatawa_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 = "fatawa_cp.php?action=actx&id=$p[id]&act=0";
$te = $LANGAUGE_CP[72];
}else{
$im = "images/off.gif";
$li = "fatawa_cp.php?action=actx&id=$p[id]&act=1";
$te = $LANGAUGE_CP[73];
}

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='70%' class='xtd'><label title='".$LANGAUGE_CP[237]." : ".$pc['name_cat']."' for='sound".$p['id']."'>» ".$rrr."</label></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='fatawa_cp.php?action=edittext&id=$p[id]'><img border='0' src='images/edit.gif' alt='".$rrr."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='fatawa_cp.php?action=deletetext&id=$p[id]'><img border='0' src='images/delete.gif' alt='".$rrr."' /></a></td>
    </tr>";
}
echo "<tr>
<td colspan='6' 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='fatawa_cp.php?action=addtext&s=1#fatawa'>".$LANGAUGE_CP[109]."</a> - <a href='fatawa_cp.php?action=addtext&s=0#fatawa'>".$LANGAUGE_CP[110]."</a></td>
</tr>
</table></div></form>";

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

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

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

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

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

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

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

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

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

if(!empty($name) OR !empty($answer)){
$query =  mysql_query ("INSERT INTO fatawa (name,answer,sound,active,cat,date,url,name_mfti,title) VALUES ('$name','$answer','$sound','1','$cat','".time()."','$url','$name_mfti','$title')") or die ("error");
echo "<p>$nnnnn ....... ".$LANGAUGE_CP[111]."</p>";
}
}

echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=fatawa_cp.php?action=addtext#fatawa' />";

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

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

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

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

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

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

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

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

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

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

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

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

<tr>
      <td width='100%' class='xtd' colspan='2' align='center'>
".$LANGAUGE_CP[249]."
<script type='text/javascript'>edToolbar('mytxtarea'); </script>
<textarea name='answer' id='mytxtarea' rows='15' cols='120'>".$p['answer']."</textarea><br /><br />

      </td>
    </tr>

<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[251]."</td>
<td width='80%' class='xtd'><input name='name_mfti' size='80' value='".$p['name_mfti']."'></td>
</tr>
<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[250]."</td>
<td width='80%' class='xtd'><input dir='ltr' name='sound' size='80' value='".$p['sound']."' /></td>
</tr>
<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[236]."</td>
<td width='80%' class='xtd'><input dir='ltr' name='url' size='80' value='".$p['url']."' /></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 fatawa_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' /> <input type='submit' value=' ".$LANGAUGE_CP[154]." ' name='re' /></td>
</tr>

</table>
</form>";

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

$id    = intval($_POST['id']);
$name        = addslashes($_POST['name']);
$title       = addslashes($_POST['title']);
$answer      = addslashes($_POST['answer']);
$sound       = addslashes($_POST['sound']);
$name_mfti   = addslashes($_POST['name_mfti']);
$url         = addslashes($_POST['url']);
$cat         = $_POST['cat'];

if (empty($name)){
echo $LANGAUGE_CP[253];
}elseif (empty($answer)){
echo $LANGAUGE_CP[254];
}else{
$query =  mysql_query("UPDATE fatawa SET name='$name', answer='$answer', sound='$sound', name_mfti='$name_mfti', url='$url', cat='$cat',title='$title' where id='$id'");
echo $LANGAUGE_CP[34];
if(isset($_POST['re'])){
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=fatawa_cp.php?action=edittext&id=$id' />";
}else{
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=fatawa_cp.php?action=addtext#fatawa' />";
}
}

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

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

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


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

if(isset($_POST['activ'])){
if(count($_POST['del']) > 0){
$del_id = join(',',$_POST['del']);
$sql = mysql_query("UPDATE fatawa SET active='1' WHERE id IN($del_id)");
print $LANGAUGE_CP[62];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=fatawa_cp.php?action=addtext#fatawa' />";
}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 fatawa where id IN($del_id) order by id desc");

echo "<form name='vbform' method='POST' action='fatawa_cp.php?action=editall'>
<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'] = stripslashes($p['name']);
$p['name'] = htmlspecialchars($p['name']);

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

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

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

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

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

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

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

<tr>
<td width='100%' class='xtd' colspan='2' align='center'>
".$LANGAUGE_CP[249]."
<script type='text/javascript'>edToolbar('mytxtarea".$ii."'); </script>
<textarea name='answer[]' id='mytxtarea".$ii."' rows='15' cols='120'>".$p['answer']."</textarea><br /><br />
</td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[251]."</td>
<td width='70%' class='xtd'><input name='name_mfti[]' size='80' value='".$p['name_mfti']."'></td>
</tr>
<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[250]."</td>
<td width='70%' class='xtd'><input dir='ltr' name='sound[]' size='80' value='".$p['sound']."' /></td>
</tr>
<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[236]."</td>
<td width='70%' class='xtd'><input dir='ltr' name='url[]' size='80' value='".$p['url']."' /></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 fatawa_cat") 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[18]." ' name='B1' /></td>
</tr>

</table>
</form>";

}else{
echo $LANGAUGE_CP[255];
}

}

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

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

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

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

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

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

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

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

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

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

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

if(!empty($name) OR !empty($answer)){
echo "<p>$nnnnn . . . ".$LANGAUGE_CP[111]."</p>";
$query =  mysql_query("UPDATE fatawa SET name='$name', title='$title', answer='$answer', sound='$sound', cat='$cat', url='$url' ,active='$active' where id='$id'");
}

}
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=fatawa_cp.php?action=addtext#fatawa' />";

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

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

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

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

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

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

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

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

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

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

if($p_cats['folderfatawa'] == ""){
$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['folderfatawa']){
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='k7' rows='3' cols='70'>".$p_cats['k7']."</textarea><br /><br />
".$LANGAUGE_CP[124]."
<textarea name='d7' rows='3' cols='70'>".$p_cats['d7']."</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"){
$fatawa_catsloop      = $_POST['fatawa_catsloop'];
$fatawa_loop          = $_POST['fatawa_loop'];
$folderfatawa = $_POST['folderfatawa'];
$limitmenu_fatawa = $_POST['limitmenu_fatawa'];
$k7 = addslashes($_POST['k7']);
$d7 = addslashes($_POST['d7']);

$query1 =  mysql_query("UPDATE opitions SET
fatawa_catsloop='$fatawa_catsloop',
fatawa_loop='$fatawa_loop',folderfatawa='$folderfatawa',limitmenu_fatawa='$limitmenu_fatawa',k7='$k7',d7='$d7' where id='1'");
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=fatawa_cp.php?action=setting' />";
}
echo $f;
?>