<?php
if (!defined('webid')) {
    exit();
}

if ($user_status != 'admin') {
    exit();
}

if (isset($_POST['save'])) {
    $des = $_POST['description'];
    $texto = $_POST['texto'];
    $url = $_POST['url'];
    
    mysql_query("INSERT INTO servicelink (des, texto, url) VALUES ('$des', '$texto', '$url')") or die(mysql_error());
}
if (isset($_POST['saveedit'])) {
    $id = $_GET['edit'];
    $des = $_POST['description'];
    $texto = $_POST['texto'];
    $url = $_POST['url'];
    
   mysql_query("UPDATE servicelink SET des = '$des', texto = '$texto', url = '$url' WHERE id = '$id'") or die(mysql_error());
   ?>
   <script type="text/javascript">window.location.href = "http://<?=$_SERVER['HTTP_HOST']?>/admin/?adm=15"</script>
   <?
}
if (isset($_GET['run'])) {
    $id = intval($_GET['run']); 
    $sql = mysql_fetch_array(mysql_query("SELECT modered FROM servicelink WHERE id = '$id'")) or die(mysql_error());
    if ($sql['modered'] == 0) {
        $mod = 1;
    } else {
        $mod = 0;
    }
    mysql_query("UPDATE servicelink SET modered = '$mod' WHERE id = '$id'") or die(mysql_error());
}
if (isset($_GET['edit'])) {
    $id = intval($_GET['edit']);
    $sql = mysql_fetch_array(mysql_query("SELECT des, texto, url FROM servicelink WHERE id = '$id'")) or die(mysql_error());
    $des = $sql['des'];
    $texto = $sql['texto'];
    $urlg = $sql['url'];
}

if (isset($_GET['del'])) {
    mysql_query("DELETE FROM servicelink WHERe id = '$_GET[del]'");
}
?>
<form action="" method="post">
<table width="500px" border="0" cellpadding="0" cellspacing="1" class="tab">
    <thead>
        <th colspan="2" style="background: #ebebeb; padding: 5px;" align="right">
            <?
            if (isset($_GET['edit'])) {
                ?>
                    <input type="submit" value="Сохранить" id="save" name="saveedit" />
                <?
            } else {
                ?>
                    <input type="submit" value="Сохранить" id="save" name="save" />
                <?
            }
            ?>
        </th>
    </thead>
    <tr>
        <td class="lt" width="40%">Заголовок ссылки</td>
        <td class="rt"><input type="text" name="description" size="40" value="<?=$des?>" maxlength="100" /></td>
    </tr>
    <tr>
        <td class="lt" width="40%">Краткое описание ссылки</td>
        <td class="rt"><input type="text" name="texto" size="40" value="<?=$texto?>" maxlength="100" /></td>
    </tr>
    <tr>
        <td class="lt" width="40%">URL с (http://)</td>
        <td class="rt"><input type="text" name="url" size="40" value="<?=$urlg?>" maxlength="300" /></td>
    </tr>
</table>
</form><br /><br />
<table width="500px" border="0" cellpadding="0" cellspacing="1" class="tab">
<?
$sql = mysql_query("SELECT * FROM servicelink");
while ($row = mysql_fetch_array($sql)) {
    if ($row['modered'] == 0) {
        $img = '<a href="http://'.$_SERVER['HTTP_HOST'].'/admin/?adm=15&run='.$row['id'].'"><img src="../theme/img/picadv/serf-play.png" title="Запустить" border="0" /></a>';
    } else {
        $img = '<a href="http://'.$_SERVER['HTTP_HOST'].'/admin/?adm=15&run='.$row['id'].'"><img src="../theme/img/picadv/serf-pause.png" title="Остановить" border="0" /></a>';
    }
    ?>
    <tr>
        <td width="60" align="center" class="lt"><?=$img?></td>
        <td class="rt"><div style="position: relative;"><?=$row['des']?><br /><font color="#8AADBA"><?=$row['texto']?></font><br /><font color="#C4C4C4"><?=$row['url']?></font><div style="position: absolute; top: 0; right: 0;"><a href="http://<?=$_SERVER['HTTP_HOST']?>/admin/?adm=15&edit=<?=$row['id']?>" title="Редактровать"><img src="../theme/img/edit.png" border="0" /></a> <a href="http://<?=$_SERVER['HTTP_HOST']?>/admin/?adm=15&del=<?=$row['id']?>" title="Удалить"><img src="../theme/img/ref_del.png" border="0" /></a></div><div style="position: absolute; right: 0; bottom: 0;" title="Кол-во визитов"><?=$row['visit']?></div></div></td>
    </tr>
    <?
}
?>
</table>