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

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

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

<form name="vbform" method="post" action="url_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[554]; ?></td>
    </tr>

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

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

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

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

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

    <tr>
      <td width="35%" class='xtr'><?php echo $LANGAUGE_CP[369]; ?></td>
      <td width="65%" class='xtd'><select size="1" name="target">
  <option value="0"><?php echo $LANGAUGE_CP[370]; ?></option>
  <option value="1"><?php echo $LANGAUGE_CP[371]; ?></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 links_my_site order by url_trteeb ASC");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo "";
}else{

echo "<form name='xxx1' action='url_cp.php?action=order' method='post'>
<table class='xtable' width='100%' id='AutoNu4mber15'>
  <tr>
<td width='100%' colspan='5' class='xtt' align='center'>".$LANGAUGE_CP[97]."</td>
</tr>
  <tr>
      <td width='70%' align='center' class='xtr'>".$LANGAUGE_CP[559]."</td>
      <td width='9%' align='center' class='xtr'>".$LANGAUGE_CP[152]."</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_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 = "url_cp.php?action=actx&id=$p[id]&act=0";
$te = $LANGAUGE_CP[72];
}else{
$im = "images/off.gif";
$li = "url_cp.php?action=actx&id=$p[id]&act=1";
$te = $LANGAUGE_CP[73];
}

echo "<input type='hidden' name='idx[]' value='".$p['id']."' />
<tr>
      <td width='70%' class='xtd'>» ".$p['name_site']."<div align='left' dir='ltr'>".$p['url_site']."</div></td>
      <td width='9%' align='center' class='xtd'><input style='text-align:center;' size='2' name='order[]' value='".$p['url_trteeb']."' /></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='url_cp.php?action=edit&id=$p[id]'><img border='0' src='images/edit.gif' alt='".$p['url_site']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='url_cp.php?action=delete&id=$p[id]'><img border='0' src='images/delete.gif' alt='".$p['url_site']."' /></a></td>
    </tr>";
}

echo "<tr>
<td colspan='7' align='center' class='xtr'><input name='activ' type='submit' id='activ' value=' ".$LANGAUGE_CP[152]." ' />
</td>
</tr>

</table></form>";
}


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

$name_site = addslashes($_POST['name_site']);
$url_site = addslashes($_POST['url_site']);
$url_trteeb = addslashes($_POST['url_trteeb']);
$urlm = addslashes($_POST['urlm']);
$target = addslashes($_POST['target']);
$classs = addslashes($_POST['class']);

if (empty($name_site)){
echo $LANGAUGE_CP[560];
}else{
$query =  mysql_query ("INSERT INTO links_my_site (name_site,url_site,url_trteeb,urlm,target,class) VALUES ('$name_site','$url_site','$url_trteeb','$urlm','$target','$classs')") or die ("error");
print $LANGAUGE_CP[21];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=url_cp.php?action=add' />";
}

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

}ELSEIF ($action=="order"){
if(isset($_POST['activ'])){

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

for($i=0;$i<$number;$i++){
$id = $_POST['idx'][$i];
$orders = $_POST['order'][$i];
$sqld = mysql_query("UPDATE links_my_site SET url_trteeb='".$orders."' WHERE id=$id");
}
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=url_cp.php' />";
}else{
echo $LANGAUGE_CP[255];
}

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

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

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

echo "<form name='vbform' method='POST' action='url_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[555]."</td>
<td width='70%' class='xtd'><input name='name_site' size='60' value='".$p['name_site']."' /></td>
</tr>

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

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

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

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

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

if($p['target']==1){
echo "<option value='1' selected='selected'>".$LANGAUGE_CP[371]."</option>
<option value='0'>".$LANGAUGE_CP[370]."</option>";
}else{
echo "<option value='1'>".$LANGAUGE_CP[371]."</option>
<option value='0' selected='selected'>".$LANGAUGE_CP[370]."</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_site = addslashes($_POST['name_site']);
$url_site = addslashes($_POST['url_site']);
$url_trteeb = addslashes($_POST['url_trteeb']);

$urlm = addslashes($_POST['urlm']);
$target = addslashes($_POST['target']);
$classs = addslashes($_POST['class']);

if (empty($name_site)){
echo $LANGAUGE_CP[560];
}else{
$query =  mysql_query("UPDATE links_my_site SET name_site='$name_site',url_site='$url_site',url_trteeb='$url_trteeb',target='$target',urlm='$urlm',class='$classs' where id='$id'");
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=url_cp.php?action=add' />";
}

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