Файл: region_clean/elections/admin.php
Строк: 336
<?php
#######################################
## Mod By KoT (borispol) [76-75-072] ##
#######################################
require_once "../start.php";
require_once "../sid.php";
header('Cache-Control: no-store, no-cache, must-revalidate');
if ($ver == "wml") header ("Content-type:text/vnd.wap.wml; charset=utf-8");
else header("Content-Type:text/html; charset=UTF-8");
require_once "../inc.php";
$link = connect_db();
list($row, $id, $ps, $fsize1, $fsize2) = check_login($link);
require_once "../version.php";
if ($ver == "wml") {
echo $xml;
echo $dtd;
echo "<wml>
<card id="index" title="Выборы чата | Админка">
<p align="center">";
} else {
echo "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"";
echo ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">";
echo "<html xmlns="http://www.w3.org/1999/xhtml">
<head><link rel="stylesheet" type="text/css" href="../css/$css.css"/>
<title>Выборы чата | Админка</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body>
<div align="center">";
}
$config_bookpost = 5;
$day = date("d.m.y");
$timer = date("H:i");
$idsd = $_SESSION['id'];
echo '<b>Управление выборами</b><br/><br/>';
if ($action == "") {
$filex = file("adminlist.dat");
$countx = count($filex);
$switchx = 0;
$wordx = "$idsd";
for ($ix = 0; $ix < $countx; $ix++) {
if (trim($filex[$ix]) == $wordx) { $switchx=1; } }
if ($switchx == 1)
{
echo '<a href="admin.php?'.$ses.'&ref='.$ref.'">Обновить</a> | ';
echo '<a href="admin.php?action=add&'.$ses.'&ref='.$ref.'">Новые выборы</a><br/>';
echo $divide;
$file = file("../dataelections/list.lst");
$total = count($file);
if (empty($_GET['start'])) $start = 0;
else $start = intval($_GET['start']);
if ($total < $start + $config_bookpost) { $end = $total; }
else { $end = $start + $config_bookpost; }
for ($fm = $start; $fm < $end; $fm++) {
$file = file("../dataelections/list.lst");
$file = array_reverse($file);
$dt = explode("|",$file[$fm]);
$num = $total-$fm-1;
if ($fm >= 0) {
echo 'Название: <b>'.$dt[1].'</b><br/>Создан: <b>'.$dt[2].' / '. $dt[3].'</b><br/>Условия: '.$dt[0].'<br/>';
echo 'Автор: <b>'. $dt[5].'</b><br/>';
if ($dt[4] == 0) { $types = "Закрыто"; }
if ($dt[4] == 1) { $types = "Открыто"; }
echo 'Голосование: <b>'.$types.'</b><br/>
<a href="admin.php?action=edit&rd='.$num.'&'.$ses.'&ref='.$ref.'">[Edit]</a>
<a href="admin.php?action=del&rd='.$num.'&'.$ses.'&ref='.$ref.'">[DEL]</a>
<br/><br/>';
}
}
if ($total < 1) { echo '<br/><b>Выборов еще нет!</b><br/>'; }
echo $divide;
if ($start != 0) { echo '<a href="admin.php?start='.($start - $config_bookpost).'&'.$ses.'&ref='.$ref.'"><-Назад </a> '; }else { echo '<-Назад '; }
echo '|';
if ($total > $start + $config_bookpost) {
echo ' <a href="admin.php?start='.($start + $config_bookpost).'&'.$ses.'&ref='.$ref.'">Далее-></a>';
} else {
echo' Далее->'; }
$ba=ceil($total/$config_bookpost);
$ba2=$ba*$config_bookpost-$config_bookpost;
echo '<br/>Страницы:';
$asd2=$start+($config_bookpost*4);
if ($asd < $total and $asd > 0) {
echo ' <a href="admin.php?start=0&'.$ses.'&ref='.$ref.'">1</a> ... ';
}
for($i=$asd; $i < $asd2;)
{
if ($i < $total and $i >= 0) {
$ii=floor(1+$i/$config_bookpost);
if ($start == $i) {
echo ' <b>('.$ii.')</b>';
} else {
echo ' <a href="admin.php?start='.$i.'&'.$ses.'&ref='.$ref.'">'.$ii.'</a>';
}
}
$i=$i+$config_bookpost;}
if ($asd2 < $total) {
echo ' ... <a href="admin.php?start='.$ba2.'&'.$ses.'&ref='.$ref.'">'.$ba.'</a>';
}
echo '<br/><br/>Всего голосований : <b>'.(int)$total.'</b><br/>';
if ($total > 1) {
echo '<br/><a href="admin.php?action=prodel&'.$ses.'&ref='.$ref.'">Удалить все выборы!</a><br/>'; }
}
else { echo 'Ты не Админ выборов!<br/><br/>'; }
}
//---------------------------------------- РЕДАКТИРОВАНИЕ -------------------------------------------//
if ($action == "edit") {
$filex = file("adminlist.dat");
$countx = count($filex);
$switchx = 0;
$wordx = "$idsd";
for ($ix = 0; $ix < $countx; $ix++) {
if (trim($filex[$ix]) == $wordx) { $switchx=1; } }
if ($switchx == 1)
{
$rd = intval($_GET['rd']);
$lines = file("../dataelections/list.lst");
if (isset($rd)) {
$dt = explode("|", $lines[$rd]);
echo 'Редактирование голосования: <b>'.$dt[1].'</b>';
if ($ver != "wml") {
echo '<form action="admin.php?rd='.$rd.'&action=addedit&start='.$start.'&'.$ses.'&ref='.$ref.'" method="POST">
Имя: <br/><input type="text" name="name" value="'.$dt[1].'"><br/>
Дата: <br/><input type="text" name="day" value="'.$dt[2].'"><br/>
Время: <br/><input type="text" name="timer" value="'.$dt[3].'"><br/>
Условие:<br/>
<textarea cols="30" rows="3" name="msg">'.$dt[0].'</textarea><br/>
Сразу голосовать? <select name="votes"><option value="0">Нет</option>
<option value="1">Да</option></select><br/>
<input type="hidden" name="user" value="'.$dt[5].'">
<input type="hidden" name="uid" value="'.$dt[6].'">
<br/><input type="submit" class="ibutton" value="Изменить"></form>';
} else {
echo '<br/>--------------------<br/>
Имя: <br/><input type="text" name="name" value="'.$dt[1].'"/><br/>
Дата: <br/><input type="text" name="day" value="'.$dt[2].'"/><br/>
Время: <br/><input type="text" name="timer" value="'.$dt[3].'"/><br/>
Условие:<br/>
<input name="msg" value="'.$dt[0].'"/><br/>
<anchor>Изменить
<go href="admin.php?rd='.$rd.'&action=addedit&start='.$start.'&'.$ses.'&ref='.$ref.'" method="post">
<postfield name="day" value="$(day)"/>
<postfield name="timer" value="$(timer)"/>
<postfield name="msg" value="$(msg)"/>
<postfield name="name" value="$(name)"/>
<postfield name="type" value="'.$dt[4].'"/>
<postfield name="user" value="'.$dt[5].'"/>
<postfield name="uid" value="'.$dt[6].'"/>
</go></anchor><br/>--------------------<br/>';
}
} else { echo 'Произошла ошибка, не выбрана строка'; }
}
else { echo 'Ты не Админ выборов!<br/><br/>'; }
}
//---------------------------------------- ИЗМЕНЕНИЕ СООБЩЕНИЯ -------------------------------------------//
if ($action == "addedit") {
$filex = file("adminlist.dat");
$countx = count($filex);
$switchx = 0;
$wordx = "$idsd";
for ($ix = 0; $ix < $countx; $ix++) {
if (trim($filex[$ix]) == $wordx) { $switchx=1; } }
if ($switchx == 1)
{
$name = htmlspecialchars(check($name));
$msg = htmlspecialchars(check($msg));
$day = check($day);
$timer = check($timer);
$type = intval($type);
$uid = intval($uid);
$user = htmlspecialchars(check($user));
$text = $msg.'|'.$name.'|'.$day.'|'.$timer.'|'.$votes.'|'.$user.'|'.$uid.'|';
$text = preg_replace("|[rn]+|si","",$text);
if (isset($rd)) {
$file = file("../dataelections/list.lst");
$fp = fopen("../dataelections/list.lst","a+");
flock ($fp,LOCK_EX);
ftruncate ($fp,0);
for ($i = 0; $i < sizeof($file); $i++) {
if ($rd != $i) { fputs($fp,$file[$i]);
} else {
fputs($fp,"$textrn"); } }
fflush ($fp);
flock ($fp,LOCK_UN);
fclose($fp);
}
echo 'Голосование изменено!<br/><br/>';
}
else { echo 'Ты не Админ выборов!<br/><br/>'; }
}
//---------------------------------------- УДАЛЕНИЕ СООБЩЕНИЯ -------------------------------------------//
if ($action == "del") {
$filex = file("adminlist.dat");
$countx = count($filex);
$switchx = 0;
$wordx = "$idsd";
for ($ix = 0; $ix < $countx; $ix++) {
if (trim($filex[$ix]) == $wordx) { $switchx=1; } }
if ($switchx == 1)
{
if (isset($rd)) {
$file = file("../dataelections/list.lst");
$fp = fopen("../dataelections/list.lst","w");
flock ($fp,LOCK_EX);
for ($i = 0; $i< sizeof($file); $i++) {
if ($i == $rd) { unset($file[$i]); } }
fputs($fp, implode("",$file));
flock ($fp,LOCK_UN);
fclose($fp);
}
echo 'Голосование удалено!<br/><br/>';
}
else { echo 'Ты не Админ выборов!<br/><br/>'; }
}
//---------------------------------------- ПОДТВЕРЖДЕНИЕ ОЧИСТКИ -------------------------------------------//
if ($action == "prodel") {
echo '<br/>Удалить все выборы?<br/>';
echo '<b><a href="admin.php?action=alldel&'.$ses.'&ref='.$ref.'">Да!</a></b><br/>';
echo '<br/><a href="admin.php?'.$ses.'&ref='.$ref.'">Вернуться</a><br/>';
}
//---------------------------------------- ОЧИСТКА ГОСТЕВОЙ -------------------------------------------//
if ($action == "alldel") {
$filex = file("adminlist.dat");
$countx = count($filex);
$switchx = 0;
$wordx = "$idsd";
for ($ix = 0; $ix < $countx; $ix++) {
if (trim($filex[$ix]) == $wordx) { $switchx=1; } }
if ($switchx == 1)
{
$file = file("../dataelections/list.lst");
$fp = fopen("../dataelections/list.lst","a+");
flock ($fp,LOCK_EX);
ftruncate ($fp,0);
fflush ($fp);
flock ($fp,LOCK_UN);
fclose($fp);
echo 'Все выборы удалены!<br/><br/>';
}
else { echo 'Ты не Админ выборов!<br/><br/>'; }
}
if ($action == "add") {
$filex = file("adminlist.dat");
$countx = count($filex);
$switchx = 0;
$wordx = "$idsd";
for ($ix = 0; $ix < $countx; $ix++) {
if (trim($filex[$ix]) == $wordx) { $switchx=1; } }
if ($switchx == 1)
{
if ($ver != "wml") {
echo '<form action="admin.php?action=addn&'.$ses.'&ref='.$ref.'" method="post">
<b>Название:</b> <br/><input type="text" name="name"/><br/>
<b>Суть:</b><br/>
<textarea cols="25" rows="3" name="msg"></textarea><br/>
<b>Голосование разрешено сразу?</b><br/><b>Да</b> <input name="trans" type="checkbox" value="y" /><br/>
<br/><input type="submit" class="ibutton" value="OK!" /></form>';
} else {
echo 'Название:<br/>
<input name="name"/><br/>
Условие:<br/>
<input name="msg"/><br/>
Сразу голосовать? <select name="trans"><option value="0">Нет</option>
<option value="y">Да</option></select><br/>
<anchor>Создать!
<go href="admin.php?action=addn&'.$ses.'&ref='.$ref.'" method="post">
<postfield name="msg" value="$(msg)"/>
<postfield name="name" value="$(name)"/>
<postfield name="trans" value="$(trans)"/>
</go></anchor><br/>--------------------<br/>';
}
}
else { echo 'Ты не Админ голосований!<br/><br/>'; }
}
if ($action == "addn") {
$filex = file("adminlist.dat");
$countx = count($filex);
$switchx = 0;
$wordx = "$idsd";
for ($ix = 0; $ix < $countx; $ix++) {
if (trim($filex[$ix]) == $wordx) { $switchx=1; } }
if ($switchx == 1)
{
$dates = date("d.m.y");
$times = date("H:i");
$time = time();
$name = $_POST['name'];
$msg = $_POST['msg'];
$id = $row['id'];
$name = htmlspecialchars(check($name));
$msg = htmlspecialchars(check($msg));
if (empty($msg)) {
echo 'Введи описание выборов!!!
<br/><br/><a href="admin.php?'.$ses.'&ref='.$ref.'">К выборам</a><br/>
<a href="../apanel.php?'.$ses.'&ref='.$ref.'">В админку</a><br/>
<a href="../enter.php?'.$ses.'&ref='.$ref.'">В прихожую</a><br/>';
exit;
}
if (empty($name)) {
echo 'Введи название выборов!!!
<br/><br/><a href="admin.php?'.$ses.'&ref='.$ref.'">К выборам</a><br/>
<a href="../apanel.php?'.$ses.'&ref='.$ref.'">В админку</a><br/>
<a href="../enter.php?'.$ses.'&ref='.$ref.'">В прихожую</a><br/>';
exit;
}
if ($trans == "y") { $type = 1; }
if ($trans != "y") { $type = 0; }
$rand = rand(10000000,99999999);
$r = mysql_query ("select id,user from users where id='$id';");
$arr = mysql_fetch_array($r);
$login = $arr['user'];
$usid = $arr['id'];
$text = $msg.'|'.$name.'|'.$dates.'|'.$times.'|'.$type.'|'.$login.'|'.$rand.'|';
$text = preg_replace ("|[rn]+|si","",$text);
$fp = fopen("../dataelections/list.lst","a+");
flock ($fp,LOCK_EX);
fputs($fp,"$textrn");
flock ($fp,LOCK_UN);
fclose($fp);
echo 'Выборы созданы!<br/><br/>';
}
else { echo 'Ты не Админ выборов!<br/><br/>'; }
}
if ($action == "addadmin") {
$id = $row['id'];
$r = mysql_query ("select id,user,level from users where id='$id';");
$arr = mysql_fetch_array($r);
$login = $arr['user'];
$usid = $arr['id'];
$lev = $arr['level'];
if ($lev > 7) {
if ($ver != "wml") {
echo '<form action="admin.php?action=addadminok&'.$ses.'&ref='.$ref.'" method="post">
<b>ID Юзера:</b> <br/><input type="text" name="uid"/><br/>
<br/><input type="submit" class="ibutton" value="Назначить!" /></form>';
} else {
echo 'ID Юзера:<br/>
<input name="uid"/><br/>
<anchor>Создать!
<go href="admin.php?action=addadminok&'.$ses.'&ref='.$ref.'" method="post">
<postfield name="uid" value="$(uid)"/>
</go></anchor><br/>--------------------<br/>';
}
}
}
if ($action == "addadminok") {
$id = $row['id'];
$r = mysql_query ("select id,user,level from users where id='$id';");
$arr = mysql_fetch_array($r);
$login = $arr['user'];
$usid = $arr['id'];
$lev = $arr['level'];
$uid = $_POST['uid'];
$uid = intval($uid);
if (empty($uid)) {
echo 'Введи ID юзера!!!
<br/><br/><a href="admin.php?'.$ses.'&ref='.$ref.'">К выборам</a><br/>
<a href="../apanel.php?'.$ses.'&ref='.$ref.'">В админку</a><br/>
<a href="../enter.php?'.$ses.'&ref='.$ref.'">В прихожую</a><br/>';
exit;
}
if ($lev > 7) {
$filex = file("adminlist.dat");
$countx = count($filex);
$switchx = 0;
$wordx = "$uid";
for ($ix = 0; $ix < $countx; $ix++) {
if (trim($filex[$ix]) == $wordx) { $switchx=1; } }
if ($switchx == 1)
{
echo 'Данный юзер уже добавлен в список админов!<br/>';
}
else
{
$tex = "$uid";
$fp = fopen("adminlist.dat","a+");
flock
($fp,LOCK_EX);
fputs($fp,"$texrn");
fflush ($fp);
flock ($fp,LOCK_UN);
fclose($fp);
@chmod("$fp", 0777);
@chmod("adminlist.dat", 0777);
echo 'Теперь пользователь с ID ' . $uid . ' сможет полностью администрировать выборы!<br/>';
}
}
}
if ($action == "readlist") {
$id = $row['id'];
$r = mysql_query ("select id,user,level from users where id='$id';");
$arr = mysql_fetch_array($r);
$login = $arr['user'];
$usid = $arr['id'];
$lev = $arr['level'];
if ($lev > 7) {
echo '<br/>Список админов выборов:<br/>';
$file = file("adminlist.dat");
$total = count($file);
if (empty($_GET['start'])) $start = 0;
else $start = intval($_GET['start']);
if ($total < $start + $config_bookpost) { $end = $total; }
else { $end = $start + $config_bookpost; }
for ($fm = $start; $fm < $end; $fm++) {
$file = file("adminlist.dat");
$file = array_reverse($file);
$dt = explode("|",$file[$fm]);
$num = $total-$fm-1;
if ($fm >= 0) {
$r = mysql_query ("select id,user from users where id='$dt[0]';");
$arr = mysql_fetch_array($r);
$login = $arr['user'];
$usid = $arr['id'];
$lev = $arr['level'];
echo '<br/>';
echo "<b><a href='../info.php?$ses&nk=$usid&ref=$ref'> $login </a></b>";
echo '<a href="admin.php?action=deluser&rd='.$num.'&start='.$start.'&uz='.$dt[0].'&nm='.$dt[0].'&'.$ses.'&ref='.$ref.'">[Удалить]</a><br/>';
}
}
if ($total < 1) { echo '<br/>Админов пока нет!<br/>'; }
echo $divide;
if ($start != 0) { echo '<a href="admin.php?action=readlist&start='.($start - $config_bookpost).'&'.$ses.'&ref='.$ref.'"><-Назад </a> ';
} else {
echo'<-Назад ';
}
echo '|';
if ($total > $start + $config_bookpost) {
echo ' <a href="admin.php?action=readlist&start='.($start + $config_bookpost).'&'.$ses.'&ref='.$ref.'">Далее-></a>';
} else {
echo' Далее->';
}
$ba=ceil($total/$config_bookpost);
$ba2=$ba*$config_bookpost-$config_bookpost;
echo '<br/>Страницы:';
$asd=$start-($config_bookpost*3);
$asd2=$start+($config_bookpost*4);
if ($asd < $total and $asd > 0) {
echo ' <a href="admin.php?action=readlist&start=0&'.$ses.'&ref='.$ref.'">1</a> ... ';
}
for($i=$asd; $i < $asd2;)
{
if ($i < $total and $i >= 0) {
$ii=floor(1+$i/$config_bookpost);
if ($start == $i) {
echo ' <b>'.$ii.'</b>';
}
else
{
echo ' <a href="admin.php?action=readlist&start='.$i.'&'.$ses.'&ref='.$ref.'">'.$ii.'</a>';
}
}
$i=$i+$config_bookpost;
}
if ($asd2 < $total) {
echo ' ... <a href="admin.php?action=readlist&start='.$ba2.'&'.$ses.'&ref='.$ref.'">'.$ba.'</a>';
}
echo '<br/><br/>Всего админов: '.$total.'<br/>';
echo '<br/><a href="admin.php?action=addadmin&'.$ses.'&ref='.$ref.'">Добавить админа</a><br/>';
}
}
///////////////////////////// Удаление юзера из списка читателей \\\\\\\\\\\\\\\\\\\\
if ($action == "deluser") {
$id = $row['id'];
$r = mysql_query ("select id,user,level from users where id='$id';");
$arr = mysql_fetch_array($r);
$login = $arr['user'];
$usid = $arr['id'];
$lev = $arr['level'];
if ($lev > 7) {
if (isset($rd)) {
$file = file("adminlist.dat");
$fp = fopen("adminlist.dat","w");
flock ($fp,LOCK_EX);
for ($i = 0; $i< sizeof($file); $i++) {
if ($i == $rd) { unset($file[$i]); } }
fputs($fp, implode("",$file));
flock ($fp,LOCK_UN);
fclose($fp);
}
echo 'Теперь пользователь не может администрировать выборы!<br/>';
}
}
echo '<div class = "d1"><a href="admin.php?'.$ses.'&ref='.$ref.'">К выборам</a><br/>
<a href="admin.php?action=readlist&'.$ses.'&ref='.$ref.'">Список админов</a><br/>
<a href="../apanel.php?'.$ses.'&ref='.$ref.'">В админку</a><br/>
<a href="../enter.php?'.$ses.'&ref='.$ref.'">В прихожую</a></div>';
include_once '../foot.php';
mysql_close($link);
ob_end_flush();
exit;
?>