Вход Регистрация
Файл: vsime.com/polls/inc/poll_topic_edit.php
Строк: 174
<?
    $title 
.= ' - Редактирование опроса';
    
ex_head();
    if(!isset(
$_SESSION["poll_forum_edit_$topic[id]"]))
    {
        
$_SESSION["poll_forum_edit_$topic[id]"]=array();
        
$_SESSION["poll_forum_edit_$topic[id]"]['text']=$topic['poll_text'];
        
$_SESSION["poll_forum_edit_$topic[id]"]['clean']=0;
        
$_SESSION["poll_forum_edit_$topic[id]"]['default_vars'] = array();
        
$query2 mysqli_query($dbi"SELECT * FROM `forum_poll` WHERE `id_topic` = '$topic[id]' ORDER BY `num` ASC");
        while (
$post mysqli_fetch_array($query2))
        {
            
$_SESSION["poll_forum_edit_$topic[id]"]['default_vars']["$post[id]"] = $post['var'];
        }
        
$_SESSION["poll_forum_edit_$topic[id]"]['vars'] = array();
    }
    
    
$poll_edit=$_SESSION["poll_forum_edit_$topic[id]"];
    
//   - - - Counter - - -   \
    
$count_vars_default count($poll_edit['default_vars']);
    
$count_vars_new count($poll_edit['vars']);
    
$count_vars $count_vars_default $count_vars_new;

    
//  - - - Delete - - -  \

    
if(isset($_POST['delete']) && hsc(@$_POST['mdp'])==$mdp)
    {
        
mysqli_query($dbi"UPDATE `forum` SET `poll` = '0' WHERE `id` = '$topic[id]'");
        
mysqli_query($dbi"DELETE FROM `forum_poll` WHERE `id_topic` = '$topic[id]'");
        
mysqli_query($dbi"DELETE FROM `forum_pollen` WHERE `id_topic` = '$topic[id]'");
        unset(
$_SESSION["poll_forum_edit_$topic[id]"]);
        
header("Location: /forum/?act=topic&id=$topic[id]");
        exit;
    }

    
//  - - - Save - - -  \

    
if(isset($_POST['save']) && $count_vars<=&& hsc(@$_POST['mdp'])==$mdp)
    {
        
$pros=0;
        
$_SESSION["poll_forum_edit_$topic[id]"]['vars']=array();
        
$_SESSION["poll_forum_edit_$topic[id]"]['default_vars']=array();
        
$count_vars_not_null 0;
        foreach (
$_POST as $key => $value)
        {
            if (
preg_match('#^vaRiantd_([0-9]*)$#',$key,$kid))
            {
                if (
mysqli_num_rows(mysqli_query($dbi"SELECT * FROM `forum_poll` WHERE `id_topic` = '$topic[id]' AND `id` = '$kid[1]'")))
                {
                    
$pros++;
                    
$_SESSION["poll_forum_edit_$topic[id]"]['default_vars']["$kid[1]"]=$value;
                    if (
strlen(trim($value)) > 0)$count_vars_not_null++;
                }
            }
        }
        foreach (
$_POST as $key => $value)
        {
            if (
preg_match('#^vaRiant_([0-9]*)$#',$key,$kid))
            {
                
$pros++;
                
$_SESSION["poll_forum_edit_$topic[id]"]['vars'][] = $value;
                if (
strlen(trim($value)) > 0)$count_vars_not_null++;
                if(
$pros==100)break;
            }
        }
        if(
strlen2($_POST['poll_text'])<1)$error[]='Короткое описание опроса';
        if(
strlen2($_POST['poll_text'])>1000)$error[]='Слишком длинное описание опроса';
        if(
$count_vars_not_null 2)$error[]='Вы не заполнили варианты ответов';
        if(!isset(
$error))
        {
            
$array_res = array();
            foreach (
$_SESSION["poll_forum_edit_$topic[id]"]['default_vars'] as $key => $value)
            {
                if (
mysqli_result("SELECT COUNT(*) FROM `forum_poll` WHERE `id_topic` = '$topic[id]' AND `id` = '$key'"))
                {
                    if (
strlen(trim($value)) > 0)$array_res[] = $key;
                }
            }
            
$not_where implode("' AND `id` != '"$array_res);
            if (
count($not_where))mysqli_query($dbi"DELETE FROM `forum_poll` WHERE `id` != '$not_where' AND `id_topic` = '$topic[id]'");
            
$num 0;
            foreach (
$_SESSION["poll_forum_edit_$topic[id]"]['default_vars'] as $key => $value)
            {
                if (
mysqli_num_rows(mysqli_query($dbi"SELECT * FROM `forum_poll` WHERE `id_topic` = '$topic[id]' AND `id` = '$key'")))
                {
                    if (
strlen(trim($value)) > 0)
                    {
                        
$num++;
                        
mysqli_query($dbi"UPDATE `forum_poll` SET `var` = '$value', `num` = '$num' WHERE `id` = '$key' AND `id_topic` = '$topic[id]'");
                    }
                }
            }
        foreach (
$_POST as $key => $value)
        {
            if (
preg_match('#^vaRiant_([0-9]*)$#',$key,$kid))
            {
                if (
strlen(trim($value)) > 0)
                {
                    
$num++;
                    
mysqli_query($dbi"INSERT INTO `forum_poll` (`id_topic`, `var`, `num`) VALUES ('$topic[id]', '".my_esc($value)."', '$num')");
                }
            }
        }
            
mysqli_query($dbi"UPDATE `forum` SET `poll_text` = '".my_esc($_POST['poll_text'])."', `poll_last_time` = '$time', `poll_last_user` = '$user[id]' WHERE `id` = '$topic[id]'");
            if(isset(
$_POST['clean']) && $_POST['clean']==1)mysqli_query($dbi"DELETE FROM `forum_pollen` WHERE `id_topic` = '$topic[id]'");
            unset(
$_SESSION["poll_forum_edit_$topic[id]"]);
            
header("Location: /forum/?act=topic&id=$topic[id]");
            exit;
        }
    }

    
//  - - - Add vaRiant - - -  \

    
if(isset($_POST['add_vaRiant']) && $count_vars<=&& hsc(@$_POST['mdp'])==$mdp)
    {

        
$_SESSION["poll_forum_edit_$topic[id]"]['text']=$_POST['poll_text'];
        if(isset(
$_POST['clean']) && $_POST['clean']==1)$_SESSION["poll_forum_edit_$topic[id]"]['clean']=1;else $_SESSION["poll_forum_edit_$topic[id]"]['clean']=0;
        
$_SESSION["poll_forum_edit_$topic[id]"]['default_vars'] = array();
        foreach (
$_POST as $key => $value)
        {
            if (
preg_match('#^vaRiantd_([0-9]*)$#',$key,$kid))
            {
                if (
mysqli_num_rows(mysqli_query($dbi"SELECT * FROM `forum_poll` WHERE `id_topic` = '$topic[id]' AND `id` = '$kid[1]'")))
                {
                    
$_SESSION["poll_forum_edit_$topic[id]"]['default_vars']["$kid[1]"]=$value;
                }
            }
        }
        
$_SESSION["poll_forum_edit_$topic[id]"]['vars'] = array();
        
$pros=0;
        foreach (
$_POST as $key => $value)
        {
            if (
preg_match('#^vaRiant_([0-9]*)$#',$key,$kid))
            {
                
$pros++;
                
$_SESSION["poll_forum_edit_$topic[id]"]['vars'][]=$value;
                if(
$pros==100)break;
            }
        }
        
$_SESSION["poll_forum_edit_$topic[id]"]['vars'][]=NULL;
    }

    
//   - - - Delete Variant - - -   \

    
if(isset($_POST['delete_vaRiant']) && $count_vars>&& hsc(@$_POST['mdp'])==$mdp)
    {
        
$_SESSION["poll_forum_edit_$topic[id]"]['text']=$_POST['poll_text'];
        if(isset(
$_POST['clean']) && $_POST['clean']==1)$_SESSION["poll_forum_edit_$topic[id]"]['clean']=1;else $_SESSION["poll_forum_edit_$topic[id]"]['clean']=0;
        if (
$count_vars_new == 0)
        {
            
$_SESSION["poll_forum_edit_$topic[id]"]['default_vars'] = array();
            
$pros=0;
            foreach (
$_POST as $key => $value)
            {
                if (
preg_match('#^vaRiantd_([0-9]*)$#',$key,$kid))
                {
                    if (
mysqli_num_rows(mysqli_query($dbi"SELECT * FROM `forum_poll` WHERE `id_topic` = '$topic[id]' AND `id` = '$kid[1]'")))
                    {
                        
$pros++;
                        if(
$pros != $count_vars_default)$_SESSION["poll_forum_edit_$topic[id]"]['default_vars']["$kid[1]"]=$value;
                    }
                }
            }
        } else {
            foreach (
$_POST as $key => $value)
            {
                if (
preg_match('#^vaRiantd_([0-9]*)$#',$key,$kid))
                {
                    if (
mysqli_num_rows(mysqli_query($dbi"SELECT * FROM `forum_poll` WHERE `id_topic` = '$topic[id]' AND `id` = '$kid[1]'")))
                    {
                        
$_SESSION["poll_forum_edit_$topic[id]"]['default_vars']["$kid[1]"]=$value;
                    }
                }
            }
            
$_SESSION["poll_forum_edit_$topic[id]"]['vars']=array();
            
$pros=0;
            foreach (
$_POST as $key => $value)
            {
                if (
preg_match('#^vaRiant_([0-9]*)$#',$key,$kid))
                {
                    
$pros++;
                    if(
$pros != $count_vars_new)$_SESSION["poll_forum_edit_$topic[id]"]['vars'][] = $value;
                }
            }
        }
    }

    
show_errors();
    
$poll_edit=$_SESSION["poll_forum_edit_$topic[id]"];
    
$count_vars_default count($poll_edit['default_vars']);
    
$count_vars_new count($poll_edit['vars']);
    
$count_vars $count_vars_default $count_vars_new;
    
input_bbs('textarea'1, array('fon' => 0'quote' => 0'url' => 0));
    echo 
"<form method='post' action='' class='multi'>n";
        echo 
"<div class='list'>n";
            echo 
"<input type='hidden' name='mdp' value='".$mdp."'>n";
            if(isset(
$_POST['poll_text']))$pt=$_POST['poll_text'];
            else 
$pt=$poll_edit['text'];
            echo 
"Описание (".sklon_text(1000, array('знак','знака','знаков')).")<br/>n";
            echo 
"<textarea name='poll_text' id='textarea' rows='5' cols='17' style='width: 98%'>".input_value($pt)."</textarea><br />n";
        echo 
"</div>n";
        echo 
"<div class='list'>n";
            echo 
"Варианты ответов (10 вариантов)<br />n";
            if (
$count_vars_default != 0)
            {
                foreach (
$poll_edit['default_vars'] as $key => $value)
                {
                echo 
"<div class='variant'>n";
                echo 
"<input type='text' style='width: 99%' name='vaRiantd_$key' value='".input_value($value)."'><br/>n";
                echo 
"</div>n";
                }
            }
            
$pl 0;
            if (
$count_vars_new != 0)
            {
                foreach (
$_SESSION["poll_forum_edit_$topic[id]"]['vars'] as $key => $value)
                {
                
$pl++;
                echo 
"<div class='variant'>n";
                echo 
"<input type='text' style='width: 99%' name='vaRiant_$pl' value='".input_value($value)."'><br/>n";
                echo 
"</div>n";
                }
            }
            echo 
"".($count_vars<=9?"<input style='width: ".($count_vars>2?50:100)."%; float: left; margin-bottom: 10px;' type='submit' name='add_vaRiant' value='Добавить' />":null)."".($count_vars>2?"<input style='width: ".($count_vars<=9?50:100)."%; float: left; margin-bottom: 10px;' type='submit' name='delete_vaRiant' value='Убрать' />":null)."n";
            echo 
"<div class='clear'></div>n";
        echo 
"</div>n";
        echo 
"<div class='list'>n";
            if(isset(
$_POST['clean']) && $_POST['clean']==|| $poll_edit['clean']==1)$clean=1;
            echo 
"<input type='checkbox' name='clean' id='clean_1' value='1'".(isset($clean)?" checked='checked'":null)."> <label for='clean_1'>Сбросить результаты голосования</label>n";
        echo 
"</div>n";
        echo 
"<div class='list'>n";
            echo 
"<input style='width: 50%; float: left; margin-bottom: 10px;' type='submit' name='save' value='Сохранить'>n";
            echo 
"<input style='width: 50%; float: left; margin-bottom: 10px;' type='submit' name='delete' value='Удалить'>n";
            echo 
"<div class='clear'></div>n";
        echo 
"</div>n";
    echo 
"</form>n";
    echo 
"<div class='foot'>n";
        echo 
image_back()."<a href='/forum/?act=topic&id=$topic[id]'>Назад</a>n";
    echo 
"</div>";
    
ex_foot();
?>
Онлайн: 4
Реклама