Вход Регистрация
Файл: vsime.com/polls/inc/poll_diary_new.php
Строк: 192
<?
    $title 
.= ' - Добавление опроса';
    
ex_head();

    if(!isset(
$_SESSION["poll_diary_new_$diary[id]"]))
    {
        
$_SESSION["poll_diary_new_$diary[id]"]=array();
        
$_SESSION["poll_diary_new_$diary[id]"]['text']=NULL;
        
$_SESSION["poll_diary_new_$diary[id]"]['vars']=array();
        
$_SESSION["poll_diary_new_$diary[id]"]['vars'][]=NULL;
        
$_SESSION["poll_diary_new_$diary[id]"]['vars'][]=NULL;
        
$_SESSION["poll_diary_new_$diary[id]"]['multi']=0;
        
$_SESSION["poll_diary_new_$diary[id]"]['polltime']='infin';
    }
    
$poll_new=$_SESSION["poll_diary_new_$diary[id]"];
    
// Counter of Variants
    
$count_vars=count($_SESSION["poll_diary_new_$diary[id]"]['vars']);
    
// Save New Poll
    
if(isset($_POST['submited']) && isset($_POST['poll_text']) && $_POST['mdp']==$mdp)
    {
        
$_SESSION["poll_diary_new_$diary[id]"]['text']=$_POST['poll_text'];
        if(isset(
$_POST['multi']) && $_POST['multi']==1)$_SESSION["poll_diary_new_$diary[id]"]['multi']=1;else $_SESSION["poll_diary_new_$diary[id]"]['multi']=0;
        if(
in_array($_POST['polltime'],array('infin','day','3days','week','month','3months')))$_SESSION["poll_diary_new_$diary[id]"]['polltime']=$_POST['polltime'];
        
$pros=0;
        
$_SESSION["poll_diary_new_$diary[id]"]['vars']=array();
        
$count_vars_not_null 0;
        foreach (
$_POST as $key => $value)
        {
            if (
preg_match('#^vaRiant_([0-9]*)$#',$key,$kid))
            {
                
$pros++;
                
$_SESSION["poll_diary_new_$diary[id]"]['vars'][] = $value;
                if (
strlen(trim($value)) > 0)$count_vars_not_null++;
                if(
$pros==100)break;
            }
        }
        if(
strlen($_POST['poll_text'])<$min_size_poll)$error[]='Короткое описание опроса';
        if(
strlen($_POST['poll_text'])>$max_size_poll)$error[]='Слишком длинное описание опроса';
        if(
$count_vars_not_null<2)$error[]='Вы не заполнили варианты ответов';
        if(!isset(
$error))
        {
            
$poll_text=$_POST['poll_text'];
            
$poll_timee=$_POST['polltime'];
            if(isset(
$_POST['multi']) && $_POST['multi']==1)$poll_check=1;else $poll_check=0;
            if(
$poll_timee=='day')$poll_time_add=3600*24// опрос на один день
            
elseif($poll_timee=='3days')$poll_time_add=3600*24*3// опрос на три дня
            
elseif($poll_timee=='week')$poll_time_add=3600*24*7// опрос на одну неделю
            
elseif($poll_timee=='month')$poll_time_add=3600*24*31// опрос на месяц
            
elseif($poll_timee=='3months')$poll_time_add=3600*24*31*3// опрос на три месяца
            
else $poll_time_add=3600*24*31*12*3// опрос поумолчанию (трех лет для "бесконечности" думаю хватит)
            
$poll_time=$time+$poll_time_add;
            
$var_num 0;
            foreach(
$_SESSION["poll_diary_new_$diary[id]"]['vars'] as $key => $value)
            {
                if (
strlen(trim($value)) > 0)
                {
                    
$var_num++;
                    
mysqli_query($dbi"INSERT INTO `diary_poll` (`id_diary`, `var`, `num`) VALUES ('$diary[id]', '".my_esc($value)."', '$var_num')");
                }
            }
            
mysqli_query($dbi"UPDATE `diary` SET `poll` = '1', `poll_text` = '".my_esc($poll_text)."', `poll_time` = '$poll_time', `poll_time_start` = '$time', `poll_timee` = '$poll_timee', `poll_check` = '$poll_check' WHERE `id` = '$diary[id]'");
            unset(
$_SESSION["poll_diary_new_$diary[id]"]);
            
header("Location: /diary/?act=diary&id=$diary[id]");
            exit;
        }
    }
    
// Add Variant
    
if(isset($_POST['add_vaRiant']) && $count_vars<=&& $_POST['mdp']==$mdp)
    {
        
$_SESSION["poll_diary_new_$diary[id]"]['text']=$_POST['poll_text'];
        if(isset(
$_POST['multi']) && $_POST['multi']==1)$_SESSION["poll_diary_new_$diary[id]"]['multi']=1;else $_SESSION["poll_diary_new_$diary[id]"]['multi']=0;
        if(
in_array($_POST['polltime'],array('infin','day','3days','week','month','3months')))$_SESSION["poll_diary_new_$diary[id]"]['polltime']=$_POST['polltime'];
        
$_SESSION["poll_diary_new_$diary[id]"]['vars']=array();
        
$pros=0;
        foreach (
$_POST as $key => $value)
        {
            if (
str_replace('vaRiant_','x',$key)!=$key)
            {
                
$pros++;
                
$_SESSION["poll_diary_new_$diary[id]"]['vars'][]=$value;
                if(
$pros==100)break;
            }
        }
        
$_SESSION["poll_diary_new_$diary[id]"]['vars'][]=NULL;
    }
    
// Delete Variant
    
if(isset($_POST['delete_vaRiant']) && $count_vars>&& $_POST['mdp']==$mdp)
    {
        
$_SESSION["poll_diary_new_$diary[id]"]['text']=$_POST['poll_text'];
        if(
in_array($_POST['polltime'],array('infin','day','3days','week','month','3months')))$_SESSION["poll_diary_new_$diary[id]"]['polltime']=$_POST['polltime'];
        if(isset(
$_POST['multi']) && $_POST['multi']==1)$_SESSION["poll_diary_new_$diary[id]"]['multi']=1;else $_SESSION["poll_diary_new_$diary[id]"]['multi']=0;
        
$_SESSION["poll_diary_new_$diary[id]"]['vars']=array();
        
$pros=0;
        
$ncountv=count($poll_new['vars']);
        foreach (
$_POST as $key => $value)
        {
            if (
preg_match('#^vaRiant_([0-9]*)$#',$key,$kid))
            {
                
$pros++;
                if(
$pros != $ncountv)$_SESSION["poll_diary_new_$diary[id]"]['vars'][] = $value;
            }
        }
    }
    
show_errors();
    
$poll_new=$_SESSION["poll_diary_new_$diary[id]"];
    
show_errors();
    
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_new['text'];
            echo 
"Описание (".sklon_text($max_size_poll,array('знак','знака','знаков')).")</span><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";
            
$lp=0;
            foreach (
$poll_new['vars'] as $key => $value)
            {
                
$lp++;
                echo 
"<input type='text' style='width: 99%' name='vaRiant_$lp' value='".input_value($value)."'><br/>n";
            }
            echo 
"".($lp<=9?"<input style='width: ".($lp>2?50:100)."%; float: left; margin-bottom: 10px;' type='submit' name='add_vaRiant' value='Добавить' />":null)."".($lp>2?"<input style='width: ".($lp<=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";
            echo 
"Дата окончания через: n";
            echo 
"<select name='polltime'>n";
            echo 
"<option value='infin'".($poll_new['polltime']=='infin'?" selected='selected'":null).">Бессрочное</option>n";
            echo 
"<option value='day'".($poll_new['polltime']=='day'?" selected='selected'":null).">1 День</option>n";
            echo 
"<option value='3days'".($poll_new['polltime']=='3days'?" selected='selected'":null).">3 Дня</option>n";
            echo 
"<option value='week'".($poll_new['polltime']=='week'?" selected='selected'":null).">1 Неделю</option>n";
            echo 
"<option value='month'".($poll_new['polltime']=='month'?" selected='selected'":null).">1 Месяц</option>n";
            echo 
"<option value='3months'".($poll_new['polltime']=='3months'?" selected='selected'":null).">3 Месяца</option></select>n";
            echo 
"<div class='clear'></div>n";
        echo 
"</div>n";
        echo 
"<div class='list'>n";
            if(isset(
$_POST['multi']) && $_POST['multi']==|| $poll_new['multi']==1)$multi=1;
            echo 
"<input type='checkbox' name='multi' id='multi_1' value='1'".(isset($multi)?" checked='checked'":null)."> <label for='multi_1'>Выбор нескольких вариантов</label>n";
        echo 
"</div>n";
        echo 
"<div class='list'>n";
            echo 
"<input type='submit' name='submited' style='width: 99%; float: left; margin-bottom: 10px;' value='Сохранить'>n";
            echo 
"<div class='clear'></div>n";
        echo 
"</div>n";
    echo 
"</form>n";
    echo 
"<div class='foot'>n";
        echo 
image_back()." <a href='/diary/?act=diary&id=$diary[id]'>Назад</a>n";
    echo 
"</div>";
    
ex_foot();
?>
Онлайн: 0
Реклама