Файл: system/inc/voting.php
Строк: 482
<?php
////батл.........
echoheader();
$urlsite = $config[home_url];
?>
<table width="300px">
<tbody>
<tr>
<td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%">
<tbody><tr>
<td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation"><?php if($_GET['action'] == "addnew") {echo "Создание нового голосования";} else {if($_GET['action'] == "edit") {echo "Редактирование голосования";} else {echo "Модуль SocialVote";}}?></div></td>
</tr>
</tbody></table>
<div class="unterline"></div>
<?php
function rus2translit($string) {
$converter = array(
'а' => 'a', 'б' => 'b', 'в' => 'v',
'г' => 'g', 'д' => 'd', 'е' => 'e',
'ё' => 'e', 'ж' => 'zh', 'з' => 'z',
'и' => 'i', 'й' => 'y', 'к' => 'k',
'л' => 'l', 'м' => 'm', 'н' => 'n',
'о' => 'o', 'п' => 'p', 'р' => 'r',
'с' => 's', 'т' => 't', 'у' => 'u',
'ф' => 'f', 'х' => 'h', 'ц' => 'c',
'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch',
'ь' => '', 'ы' => 'y', 'ъ' => '',
'э' => 'e', 'ю' => 'yu', 'я' => 'ya',
'А' => 'A', 'Б' => 'B', 'В' => 'V',
'Г' => 'G', 'Д' => 'D', 'Е' => 'E',
'Ё' => 'E', 'Ж' => 'Zh', 'З' => 'Z',
'И' => 'I', 'Й' => 'Y', 'К' => 'K',
'Л' => 'L', 'М' => 'M', 'Н' => 'N',
'О' => 'O', 'П' => 'P', 'Р' => 'R',
'С' => 'S', 'Т' => 'T', 'У' => 'U',
'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C',
'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sch',
'Ь' => '', 'Ы' => 'Y', 'Ъ' => '',
'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya',
' ' => '-',
'0' => 'zero',
'1' => 'one',
'2' => 'two',
'3' => 'three',
'4' => 'four',
'5' => 'five',
'6' => 'six',
'7' => 'seven',
'8' => 'eight',
'9' => 'nine',
);
return strtr($string, $converter);
}
function str2url($str) {
// переводим в транслит
$str = rus2translit($str);
// в нижний регистр
$str = strtolower($str);
// заменям все ненужное нам на "-"
$str = preg_replace('~[^-a-z0-9_]+~u', '-', $str);
// удаляем начальные и конечные '-'
$str = trim($str, "-");
return $str;
}
if($_GET['action'] == "addnew") {
if($_GET['type'] == "add") {
$uploaddir = ROOT_DIR . "/uploads/batl/";
move_uploaded_file($_FILES['img_one']['tmp_name'], $uploaddir.rus2translit($_FILES['img_one']['name']));
move_uploaded_file($_FILES['img_two']['tmp_name'], $uploaddir.rus2translit($_FILES['img_two']['name']));
$img_one = $urlsite."uploads/batl/".rus2translit($_FILES['img_one']['name']);
$img_two = $urlsite."uploads/batl/".rus2translit($_FILES['img_two']['name']);
$one = $_POST["one"];
$two = $_POST["two"];
$title = $_POST["title"];
$text1= $_POST["text1"];
$text2= $_POST["text2"];
$link1= $_POST["link1"];
$link2= $_POST["link2"];
$year = $_POST["year"];
$month = $_POST["month"];
$day = $_POST["day"];
$hour = $_POST["hour"];
$minute = $_POST["minute"];
$seconds = $_POST["seconds"];
$metakeys = "$one, $two";
$tpl = $_POST["tpl"];
$vk = "<br><center><div id='vk_comments'></div><script type='text/javascript'>VK.Widgets.Comments('vk_comments', {limit: 10, width: '496', attach: '*'});</script></center>";
$onet = rus2translit($one);
$twot = rus2translit($two);
$onets = substr($onet, 0, 15);
$twots = substr($twot, 0, 15);
$content = "<center>{include file='system/modules/voting/vote_start.php?nam=$name'}</center>";
if ($_POST["comments"] == "yes") {$content = $content.$vk;}
$name = "$onets-vs-$twots";
$added_time = time() + ($config['date_adjust'] * 60);
$newsdate = strtotime( $newdate );
if( ($allow_now == "yes") OR ($newsdate === - 1) OR !$newsdate) {
$thistime = $added_time;
} else {
$thistime = $newsdate;
if( ! intval( $config['no_date'] ) and $newsdate > $added_time ) $thistime = $added_time;
}
$db->query("INSERT INTO " . PREFIX . "_voting (one, two, title, alt_title, img_one, img_two, date, year, month, day, hour, minute, seconds, text1, text2, link1, link2) VALUES ("$one", "$two", "$title", "$name", "$img_one", "$img_two", "$thistime", "$year", "$month", "$day", "$hour", "$minute", "$seconds", "$text1", "$text2", "$link1", "$link2")");
$db->query("INSERT INTO " . PREFIX . "_static (name, descr, template, allow_template, tpl, metadescr, metakeys, metatitle, date) VALUES ("$name", "$title", "$content", "1", "$tpl", "$title", "$metakeys", "$title", "$thistime")");
$url = "?mod=voting";
header("Location:$url");
}
echo "
<form action="?mod=voting&action=addnew&type=add" method="post" enctype="multipart/form-data">
<table width="100%">
<tr>
<td style="padding:4px;" class="option">
<b>Название голосования:</b><br><span class="small">например: "Вконтакте против Facebook"</span>
</td><td align="middle">
<input class="edit bk" type="text" style="text-align: center;" name="title" value="" size="59">
</td>
</tr>
<tr>
<td style="padding:4px;" class="option">
<b>Варианты голосования:</b><br><span class="small">Укажите 2 варианта для голосования. Например: "Вконтакте" и "Facebook". <br>Варианты будут использоваться для генерации фразы, которая будет размещена в соц. сети. </span>
</td><td align="middle">
<input class="edit bk" type="text" style="text-align: center;" name="one" value="" size="26"> VS
<input class="edit bk" type="text" style="text-align: center;" name="two" value="" size="26">
</td>
</tr>
<tr>
<td style="padding:4px;" class="option">
<b>Описание голосования:</b><br><span class="small">Укажите описания. Например: "Вконтакте" и "Facebook". <br>Описания будут выводится на странице голосования. </span>
</td><td align="middle">
<input class="edit bk" type="text" style="text-align: center;" name="text1" value="" size="26"> VS
<input class="edit bk" type="text" style="text-align: center;" name="text2" value="" size="26">
</td>
</tr>
<tr>
<td style="padding:4px;" class="option">
<b>Ссылки:</b><br><span class="small">Если хотите, чтобы текст описаний и изображения были кликабельными укажите для них ссылки.<br>Например: сторонние сайты (сайты брендов) или внутренние страницы(новости)</span>
</td><td align="middle">
<input class="edit bk" type="text" style="text-align: center;" name="link1" value="" size="26"> VS
<input class="edit bk" type="text" style="text-align: center;" name="link2" value="" size="26">
</td>
</tr>
<tr>
<td style="padding:4px;" class="option">
<b>Изображения голосования:</b><br><span class="small">Загрузите 2 изображения соответствующие двум вариантам голосования</span>
</td><td align="middle">
<input class="edit bk" type="file" style="text-align: center;" name="img_one" value="" size="25"> VS
<input class="edit bk" type="file" style="text-align: center;" name="img_two" value="" size="25">
</td>
</tr>
<tr>
<td style="padding:4px;" class="option">
<b>Время окончания голосования:</b><br><span class="small">Укажите дату и время завершения голосования</span>
</td><td align="middle">
<input class="edit bk" style="text-align: center;" name="day" type="text" size="1" value="31" />.<input class="edit bk" style="text-align: center;" name="month" type="text" size="1" value="12" /> .<input class="edit bk" style="text-align: center;" name="year" type="text" size="4" value="2012" /> - <input class="edit bk" style="text-align: center;" name="hour" type="text" size="1" value="23" />:<input class="edit bk" style="text-align: center;" name="minute" type="text" size="1" value="59" />:<input class="edit bk" style="text-align: center;" name="seconds" type="text" size="1" value="59" />
</td>
</tr>
<tr>
<td style="padding:4px;" class="option">
<b>Шаблон страницы:</b><br><span class="small">Укажите название шаблона статической страницы, <br>либо оставьте поле пустым, если хотите использовать стандартный шаблон (static.tpl)</span>
</td><td align="middle">
<input class="edit bk" type="text" style="text-align: center;" name="tpl" value="" size="26">.tpl
</td>
</tr>
<tr>
<td style="padding:4px;" class="option">
<b>Комментарии Вконтакте:</b><br><span class="small">Выводить плагин комментариев Вконтакте под голосованием на статической странице?</span>
</td><td align="middle">
<select name="comments" size="1">
<option selected="selected" value="yes">Да</option>
<option value="no">Нет</option>
</select>
</td>
</tr>
</table>
<input class="bbcodes" type="submit" value="Создать" />
</form>
";
}
else {
if($_GET['action'] == "edit") {
if($_GET['type'] == "submit") {
$idd = $_GET['num'];
$uploaddir = ROOT_DIR . "/uploads/batl/";
$oneimg = $_FILES['img_one']['name'];
$twoimg = $_FILES['img_two']['name'];
$uploadfile = $uploaddir.$_FILES['img_one']['name'];
$uploadfile = $uploaddir.$_FILES['img_two']['name'];
move_uploaded_file($_FILES['img_one']['tmp_name'], $uploaddir.rus2translit($_FILES['img_one']['name']));
move_uploaded_file($_FILES['img_two']['tmp_name'], $uploaddir.rus2translit($_FILES['img_two']['name']));
if($oneimg == true) {
$img_one = $urlsite."uploads/batl/".rus2translit($_FILES['img_one']['name']);
} else {
$img_one = $_POST["img1"];
}
if($twoimg == true) {
$img_two = $urlsite."uploads/batl/".rus2translit($_FILES['img_two']['name']);
} else {
$img_two = $_POST["img2"];
}
$one = $_POST["one"];
$two = $_POST["two"];
$titles = $_POST["titles"];
$text1= $_POST["text1"];
$text2= $_POST["text2"];
$link1= $_POST["link1"];
$link2= $_POST["link2"];
$year = $_POST["year"];
$month = $_POST["month"];
$day = $_POST["day"];
$hour = $_POST["hour"];
$minute = $_POST["minute"];
$seconds = $_POST["seconds"];
$res = $db->query("SELECT * FROM " . PREFIX . "_voting WHERE `id`= "$idd"");
$del = $db->get_row($res);
$nams= $del['alt_title'];
$db->query( "UPDATE " . PREFIX . "_voting SET one='$one', two='$two', img_one='$img_one', img_two='$img_two', title='$titles', year='$year', month='$month', day='$day', hour='$hour', minute='$minute', seconds='$seconds', text1='$text1', text2='$text2', link1='$link1', link2='$link2' WHERE id='$idd'" );
$db->query( "UPDATE " . PREFIX . "_static SET descr='$titles' WHERE name='$nams'" );
$url = "?mod=voting";
header("Location:$url");
}
$idd = $_GET['num'];
$vote = $db->query("SELECT * FROM " . PREFIX . "_voting WHERE `id`= "$idd"");
$res = $db->get_row($vote);
$one = $res["one"];
$two = $res["two"];
$titles = $res["title"];
$text1= $res["text1"];
$text2= $res["text2"];
$link1= $res["link1"];
$link2= $res["link2"];
$img_one = $res["img_one"];
$img_two = $res["img_two"];
$year = $res["year"];
$month = $res["month"];
$day = $res["day"];
$hour = $res["hour"];
$minute = $res["minute"];
$seconds = $res["seconds"];
$tpl = $res["tpl"];
echo "
<form action="?mod=voting&action=edit&type=submit&num=$idd" method="post" enctype="multipart/form-data">
<table width="100%" border="0" bgcolor="#EFEFEF">
<tr>
<td width="33%" align="center" style="margin: 10px 4px 4px 4px"><input class="edit bk" style="text-align: center;" name="titles" value="$titles" type="text" size="50"; style="padding-left:4px" /></td>
</tr>
<tr>
<td align="center">Первый вариант:<br><input class="edit bk" style="text-align: center;" name="one" value="$one" type="text" size="20" /><br>Первое описание:<br><input class="edit bk" style="text-align: center;" name="text1" value="$text1" type="text" size="20" /></td>
<td align="center"><input class="edit bk" name="day" type="text" size="1" value="$day" />.<input class="edit bk" name="month" type="text" size="1" value="$month" />.<input class="edit bk" name="year" value="$year" type="text" size="3" /><br><input class="edit bk" name="hour" value="$hour" type="text" size="1" />:<input class="edit bk" name="minute" type="text" size="1" value="$minute" />:<input class="edit bk" name="seconds" type="text" size="1" value="$seconds" /><br><input class="edit bk" type="text" style="text-align: center;" name="tpl" value="$tpl" size="15">.tpl</td>
<td align="center">Второй вариант:<br><input class="edit bk" style="text-align: center;" name="two" value="$two" type="text" size="20" /><br>Второе описание<br><input class="edit bk" style="text-align: center;" name="text2" value="$text2" type="text" size="20" /></td>
</tr>
<tr>
<td align="center"><img src="$img_one" width="150px" height="150px" ></td>
<td align="center"><h1>VS</h1></td>
<td align="center"><img src="$img_two" width="150px" height="150px"></td>
</tr>
<tr>
<td align="center"><input class="edit bk" name="img_one" type="file" style="margin: 4px 4px 10px 4px"><input type="hidden" name="img1" value="$img_one"><br>Первая ссылка:<br><input class="edit bk" style="text-align: center;" name="link1" value="$link1" type="text" size="20" /></td>
<td align="center"><input type="submit" value="Изменить" style="margin: 4px 4px 10px 4px" /></td>
<td align="center"><input class="edit bk" name="img_two" type="file" style="margin: 4px 4px 10px 4px"><input type="hidden" name="img2" value="$img_two"><br>Вторая ссылка:<br><input class="edit bk" style="text-align: center;" name="link2" value="$link2" type="text" size="20" /></td>
</tr>
</table>
</form>
";
}
else{
$vote = $db->query("SELECT * FROM " . PREFIX . "_voting");
$i=1;
echo "
<table width="100%" id="newslist">
<tbody><tr class="thead">
<th width="50" style="padding:2px;">№</th>
<th align="center">Батл:</th>
<th width="600" align="center"><div style="text-align: center;"> Код: </div></th>
<th width="100" align="center"><div>Редактировать:</div></th>
</tr>
<tr class="tfoot"><th colspan="4"><div class="hr_line"></div></th>
</tr>
";
if($_GET['action'] == "delete") {
$idd = $_GET['num'];
$res = $db->query("SELECT * FROM " . PREFIX . "_voting WHERE `id`= "$idd"");
$del = $db->get_row($res);
$nams= $del['alt_title'];
$db->query("DELETE FROM " . PREFIX . "_voting WHERE `id` = "$idd"");
$db->query("DELETE FROM " . PREFIX . "_static WHERE `name` = "$nams"");
$url = "?mod=voting";
header("Location:$url");
}
while($voting = $db->get_row($vote))
{
$id = $voting['id'];
$one = $voting['one'];
$two = $voting['two'];
$name = $voting['alt_title'];
$title = $voting['title'];
$urls = $urlsite.$name.".html";
$content = "<tr><td class="list" style="padding:4px;">$i</td><td class="list"><a href="$urls" class="list">$title<a></td><td class="list">{include file='system/modules/voting/vote_start.php?nam=$name'}</td><td class="list"><a href="?mod=voting&action=edit&num=$id" title="Редактировать" class="list"><img src="system/inc/images/edit.png"></a> <a href="?mod=voting&action=delete&num=$id" title="Удалить"><img src="system/inc/images/delete.png"></a></td></tr>";
echo $content;
$i++;
}
echo "
<tr class="tfoot"><th colspan="4"><div class="hr_line"></div></th>
</tr></tbody></table>
";
echo "
<table width="100%">
<tr>
<td style="height:50px;"><br> <input type="button" value="Создать новое голосование" class="bbcodes" onclick="document.location='?mod=voting&action=addnew'"></td>
</tr>
</table>
";
};
}
?>
</td>
</tr>
</tbody></table>
<?php
echohtmlend();
?>