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

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

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

  <table class='xtable' width="100%" id="AutoNumber1">

     <tr>
      <td width="100%" colspan="2" class='xtt' align="center"><?php echo $LANGAUGE_CP[36]; ?></td>
    </tr>

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

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

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

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

    <tr>
      <td width="35%" class='xtr'><?php echo $LANGAUGE_CP[41]; ?></td>
      <td width="65%" class='xtd'>
<select size="1" name="cat">
<!--
  <option value="0" selected="selected"><?php echo $LANGAUGE_CP[42]; ?></option>
  <option value="1"><?php echo $LANGAUGE_CP[43]; ?></option>
-->
  <option value="2"><?php echo $LANGAUGE_CP[44]; ?></option>
  <option value="3"><?php echo $LANGAUGE_CP[45]; ?></option>
</select>
</td>
    </tr>

    <tr>
      <td width="35%" class='xtr'><?php echo $LANGAUGE_CP[46]; ?></td>
      <td width="65%" class='xtd'>
<select size="1" name="type">
  <option value="0" selected="selected"><?php echo $LANGAUGE_CP[47]; ?></option>
  <option value="1"><?php echo $LANGAUGE_CP[48]; ?></option>
  <option value="2"><?php echo $LANGAUGE_CP[49]; ?></option>
  <option value="3"><?php echo $LANGAUGE_CP[50]; ?></option>
</select>
</td>
    </tr>
<!--
    <tr>
      <td width="35%" class='xtr'><?php echo $LANGAUGE_CP[51]; ?></td>
      <td width="65%" class='xtd'>
<select size="1" name="textbox">
  <option value="1" selected="selected"><?php echo $LANGAUGE_CP[52]; ?></option>
  <option value="0"><?php echo $LANGAUGE_CP[53]; ?></option>
</select>
</td>
    </tr>
-->
    <tr>
      <td width="100%" colspan="2" class='xtd' align="center">
<?php echo $LANGAUGE_CP[54]; ?>
<textarea name="codex" rows="5" cols="100"></textarea>
      </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 ads order by adsid desc");
$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='xtx' align='center'>".$LANGAUGE_CP[55]."</td>
</tr>
  <tr>
      <td width='40%' align='center' class='xtr'>".$LANGAUGE_CP[56]."</td>
      <td width='12%' align='center' class='xtr'>".$LANGAUGE_CP[57]."</td>
      <td width='10%' align='center' class='xtr'>".$LANGAUGE_CP[58]."</td>
      <td width='10%' align='center' class='xtr'>".$LANGAUGE_CP[59]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[60]."</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']);

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

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

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

if($p['active'] == 1){
$im = "images/on.gif";
$li = "ads_cp.php?action=actx&id=$p[adsid]&act=0";
$te = "إضغط هنا للحجب";
}else{
$im = "images/off.gif";
$li = "ads_cp.php?action=actx&id=$p[adsid]&act=1";
$te = "إضغط هنا للتفعيل";
}

if($p['cat'] == 0){
$place = $LANGAUGE_CP[42];
}elseif($p['cat'] == 1){
$place = $LANGAUGE_CP[43];
}elseif($p['cat'] == 2){
$place = $LANGAUGE_CP[44];
}elseif($p['cat'] == 3){
$place = $LANGAUGE_CP[45];
}

if($p['type'] == 0){
$type = $LANGAUGE_CP[47];
}elseif($p['type'] == 1){
$type = $LANGAUGE_CP[48];
}elseif($p['type'] == 2){
$type = $LANGAUGE_CP[49];
}elseif($p['type'] == 3){
$type = $LANGAUGE_CP[50];
}

echo "<tr>
      <td width='40%' class='xtd'>» <a target='_blank' href='".$p['url']."'>".$p['name']."</a></td>
      <td width='12%' class='xtd' align='center'>".$d."</td>
      <td width='10%' class='xtd' align='center'>".$type."</td>
      <td width='10%' class='xtd' align='center'>".$place."</td>
      <td width='7%' class='xtd' align='center'>".$p['vis']."</td>
      <td width='7%' class='xtd' align='center'><a href='$li'><img border='0' src='$im' alt='$te ".$p['name_cat']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='ads_cp.php?action=edit&adsid=$p[adsid]'><img border='0' src='images/edit.gif' alt='".$p['name_cat']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='ads_cp.php?action=delete&adsid=$p[adsid]'><img border='0' src='images/delete.gif' alt='".$p['name_cat']."' /></a></td>
    </tr>";
}

echo "</table>";
}

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


}ELSEif ($act == 1){
$query =  mysql_query("UPDATE ads SET active='$act' where adsid='$id'");
echo $LANGAUGE_CP[62];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=ads_cp.php?action=add' />";
}else{
echo $LANGAUGE_CP[63];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=ads_cp.php?action=add' />";
}

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

$name = addslashes($_POST['name']);
$image = addslashes($_POST['image']);
$url = addslashes($_POST['url']);
$cat = addslashes($_POST['cat']);
$type = addslashes($_POST['type']);
$codex = addslashes($_POST['codex']);
$textbox = addslashes($_POST['textbox']);
$orders = addslashes($_POST['orders']);

$d = time();

if (empty($name)){
echo $LANGAUGE_CP[64];
}else{
$query =  mysql_query ("INSERT INTO ads (name,image,url,cat,type,active,date,codex,textbox,orders) VALUES ('$name','$image','$url','$cat','$type','1','$d','$codex','$textbox','$orders')") or die ("إستعلام خاطيء");
print $LANGAUGE_CP[21];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=ads_cp.php?action=add' />";
}


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

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

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

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

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

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

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

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

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

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

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

if($p['cat'] == 0){
echo "<!-- <option value='0' selected='selected'>".$LANGAUGE_CP[42]."</option>
  <option value='1'>".$LANGAUGE_CP[43]."</option> -->
  <option value='2'>".$LANGAUGE_CP[44]."</option>
  <option value='3'>".$LANGAUGE_CP[45]."</option>";
}elseif($p['cat'] == 1){
echo "<!-- <option value='0'>".$LANGAUGE_CP[42]."</option>
  <option value='1' selected='selected'>".$LANGAUGE_CP[43]."</option> -->
  <option value='2'>".$LANGAUGE_CP[44]."</option>
  <option value='3'>".$LANGAUGE_CP[45]."</option>";
}elseif($p['cat'] == 2){
echo "<!-- <option value='0'>".$LANGAUGE_CP[42]."</option>
  <option value='1'>".$LANGAUGE_CP[43]."</option> -->
  <option value='2' selected='selected'>".$LANGAUGE_CP[44]."</option>
  <option value='3'>".$LANGAUGE_CP[45]."</option>";
}elseif($p['cat'] == 3){
echo "<!-- <option value='0'>".$LANGAUGE_CP[42]."</option>
  <option value='1'>".$LANGAUGE_CP[43]."</option> -->
  <option value='2'>".$LANGAUGE_CP[44]."</option>
  <option value='3' selected='selected'>".$LANGAUGE_CP[45]."</option>";
}

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

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

if($p['type'] == 0){
echo "<option value='0' selected='selected'>".$LANGAUGE_CP[47]."</option>
  <option value='1'>".$LANGAUGE_CP[48]."</option>
  <option value='2'>".$LANGAUGE_CP[49]."</option>
  <option value='3'>".$LANGAUGE_CP[50]."</option>";
}elseif($p['type'] == 1){
echo "<option value='0'>".$LANGAUGE_CP[47]."</option>
  <option value='1' selected='selected'>".$LANGAUGE_CP[48]."</option>
  <option value='2'>".$LANGAUGE_CP[49]."</option>
  <option value='3'>".$LANGAUGE_CP[50]."</option>";
}elseif($p['type'] == 2){
echo "<option value='0'>".$LANGAUGE_CP[47]."</option>
  <option value='1'>".$LANGAUGE_CP[48]."</option>
  <option value='2' selected='selected'>".$LANGAUGE_CP[49]."</option>
  <option value='3'>".$LANGAUGE_CP[50]."</option>";
}elseif($p['type'] == 3){
echo "<option value='0'>".$LANGAUGE_CP[47]."</option>
  <option value='1'>".$LANGAUGE_CP[48]."</option>
  <option value='2'>".$LANGAUGE_CP[49]."</option>
  <option value='3' selected='selected'>".$LANGAUGE_CP[50]."</option>";
}

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

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

if($p['textbox'] == 1){
echo "<option value='1' selected='selected'>".$LANGAUGE_CP[52]."</option>
  <option value='0'>".$LANGAUGE_CP[53]."</option>";
}else{
echo "<option value='1'>".$LANGAUGE_CP[52]."</option>
  <option value='0' selected='selected'>".$LANGAUGE_CP[53]."</option>";
}

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

<tr>
<td width='100%' colspan='2' align='center' class='xtd'>
".$LANGAUGE_CP[54]."
<textarea name='codex' rows='5' cols='100' dir='ltr'>".$p['codex']."</textarea>
</td>
</tr>

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

</table>
</form>";

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

$adsid    = intval($_POST['adsid']);
$name = addslashes($_POST['name']);
$image = addslashes($_POST['image']);
$url = addslashes($_POST['url']);
$cat = $_POST['cat'];
$type = $_POST['type'];
$codex = addslashes($_POST['codex']);
$textbox = addslashes($_POST['textbox']);
$orders = $_POST['orders'];

if (empty($name)){
echo $LANGAUGE_CP[64];
}else{
$query =  mysql_query("UPDATE ads SET name='$name',image='$image',url='$url',cat='$cat',type='$type',codex='$codex',textbox='$textbox',orders='$orders' where adsid='$adsid'");
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=ads_cp.php?action=add' />";
}

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