
Панда-бир!
   
Профиль
Группа: Участник
Сообщений: 4795
Регистрация: 3.2.2003
Где: Бамбуковый лес
Репутация: 44 Всего: 73
|
Нати Вам мой скрипт: vots.php + Код | <?php error_reporting(0); #------------------------------------------------------------# # Большая просьба: # # если Вы не знакомы с языком серверных сценариев РНР # # достаточно хорошо, просьба не редактировать этот файл ( да # # пожалуй и все входящие в дистрибутив файлы ...). # #------------------------------------------------------------# // Голосование # Настройка параметров # include('config.php'); # -------------------- # # загрузка конфигурационных файлов # $style_line = @file($style_path); $index_line = @file($index_path); $config_line = @file($config_path); $badip_line = @file($badip_path); # -------------------------------- #
# загрузка главной конфигурации #
$i = 0; $c = count($config_line); while($i < $c) { $idx = explode($exp,$config_line[$i]); $config[] = $idx[0]; $config[] = $idx[1]; $config[] = $idx[2]; unset($idx); $i++;
}
$i = 0; $index_line = array_reverse($index_line); $c = count($index_line); while($i < $c) {
$idx = explode($exp,$index_line[$i]); $id = $idx[0]; $index[$id] = $idx[1]; $index_id[] = $id; unset($idx); $i++;
}
$i = 0; $c = count($badip_line); while($i < $c) {
$idx = explode($exp,$badip_line[$i]); $badip[$i][0] = $idx[0]; $badip[$i][1] = $idx[1]; unset($idx); $i++;
}
# ----------------------------- #
if(isset($GET['vid'])) {
$vid = $GET['vid'];
if(!isset($index[$vid])) { $error = "Голосования с таким id нет"; include($include_path.$inc['error']); exit(); } } if(isset($GET['act'])) { switch($GET['act']) { case "show": { $vots_line = @file($vots_path.$index[$vid]); $i = 0; $c = count($vot_line); while($i < $c) { $idx = explode($exp,$vots_line[$i]); $vots[$idx[0]] = $idx[1]; unset($idx); $i++; } include($include_path.$inc['content']); include($include_path.$inc['show_vot']); include($include_path.$inc['content_end']); break; }case "add": { include($include_path.$inc['content']); include($include_path.$inc['add_vot']); include($include_path.$inc['content_end']); break; }case "configuring": { if(empty($config[0])) { if(isset($POST['updating_of_a_configuration'])) { if(empty($POST['new_name']) and empty($POST['new_password']) and empty($POST['confirm_new_password'])) { echo "Не установлено значение Имени или пароля !"; exit(); } if($POST['confirm_new_password'] != $POST['new_password']) { echo "Пароли не совпадают !"; exit(); } $crypt_name = md5($POST['new_name']); $crypt_password = md5($POST['new_password']); $time_cookie = 100; $fop = fopen($config_path,"w"); fputs($fop,$crypt_name.$exp.$crypt_password.$exp.$time_cookie); fclose($fop); setcookie('crypt_name',$crypt_name,$time_cookie); setcookie('crypt_password',$crypt_password,$time_cookie); } else { echo "<table align=\"center\" width=\"400\"><tr align=\"center\"><td>"; echo "<form action=\"{$SELF}?{$QS}\" method=\"POST\">"; echo "Введите пожалуйста Ваше имя и пароль для конфигурирования новых пароля и имени для входа в администрирование голосованием.<p>\n"; echo "Имя: <input type=\"text\" name=\"new_name\"><br>"; echo "Пароль: <input type=\"password\" name=\"new_password\"><br>"; echo "Еще раз пароль: <input type=\"password\" name=\"confirm_new_password\"><br>"; echo "<input type=\"submit\" name=\"updating_of_a_configuration\" value=\"--- ok ---\"><p>"; echo "<p><b>Предупреждение !</b><p>"; echo "\"Пароль\" и \"Имя\" будут зашифрованы с помощью одностороннего шифрования - "; echo "<b>Сохраните</b> их, так как восстановить данные зашифрованные с помощью алгоритма MD5 в принципе невозможно !"; echo "</td></tr></table>"; exit(); } } if(isset($COOKIE['crypt_name']) and isset($COOKIE['crypt_password'])) { if($COOKIE['crypt_name'] != $config[0] and $COOKIE['crypt_password'] != $config[1]) { echo "В доступе отказано !"; exit(); } if(isset($POST['cfg'])) { switch($POST['cfg']) { case "style": { include($include_path.$inc['content']); include($include_path.$inc['modify_style']); include($include_path.$inc['content_end']);
break; } case "vot": { include($include_path.$inc['content']); include($include_path.$inc['vot']); include($include_path.$inc['content_end']);
break; } case "profile": { if(isset($POST['no_output'])) { include($include_path.$inc['profile']); } else { include($include_path.$inc['content']); include($include_path.$inc['profile']); include($include_path.$inc['content_end']); } break; } default: { include($include_path.$inc['content']); include($include_path.$inc['configuring']); include($include_path.$inc['content_end']); } } } else { include($include_path.$inc['content']); include($include_path.$inc['configuring']); include($include_path.$inc['content_end']); } } else if(isset($POST['auth'])) { $_crypt[] = md5($POST['name']); $_crypt[] = md5($POST['password']); if($config[0] == $_crypt[0] and $config[1] == $_crypt[1]) { setcookie('crypt_name',$_crypt[0],$config[2]); setcookie('crypt_password',$_crypt[1],$config[2]); echo "<center><a href=\"{$SELF}?{$QS}\">ВХОД</a>?</center>"; } else { echo "Введенные Вами данные содержат ошибки. Попробуйте снова."; } } else { include($include_path.$inc['content']); include($include_path.$inc['auth']); include($include_path.$inc['content_end']); } break; } default: { $error = "Неправильный параметер задачи"; include($include_path.$inc['error']); exit(); } } } if(!isset($GET['vid']) and !isset($GET['act'])) { if(!isset($index_line[0])) { echo "В данном представлении нет ни одного опроса; что бы их создать просьба проследовать по <a href=\"{$SELF}?act=configuring\" class=\"admin_link\">этой</a> ссылке."; } else { include($include_path.$inc['content']); echo "<b class=\"contentvots\">Архив голосований:</b><p>\n"; $i = 0; $c = count($index_id); while($i < $c) { $ii = $index_id[$i]; echo "<p><a href=\"$SELF?{$_SERVER['QUERY_STRING']}&vid=$index_id[$i]&act=add\" class=\"arhiv_vot_link\">$index[$ii]</a><br>"; echo "<a class=\"show_vot_res\" href=\"$SELF?{$_SERVER['QUERY_STRING']}&vid=$index_id[$i]&act=show\">результаты</a></p>\n"; $i++; } include($include_path.$inc['content_end']); } }
# ----------------------------- #
### end ### /************************************************************************************************# ## Просьба соблюдать авторские права ... несоблюдение авторских прав будет наказано # ## свыше ... # ## # ## Лицензия проста - изучайте, расспростроняйте, копируйте, изменяйте - но не забывайте про # ## оригинал :) # *///*********************************************************************************************# ?>
|
config.php Код | <?php # настройка параметров # error_reporting(7);
$root_dir = ""; // Полный путь к базе данных $include_path = "inc/"; // Полный путь к папке с инклудами $vots_path = "vots/"; // Полный путь к папке с голосованием
$SELF = $PHP_SELF; $GET = $HTTP_GET_VARS; $POST = $HTTP_POST_VARS; $COOKIE = $HTTP_COOKIE_VARS; $IP = $HTTP_SERVER_VARS['REMOTE_ADDR']; $QS = $HTTP_SERVER_VARS['QUERY_STRING']; $timeout = 2000; $chmod_wf = 0666;
$dat_dir = "{$root_dir}dat"; if(!is_dir($dat_dir)) { mkdir($dat_dir, 0770); } else { chmod($dat_dir, 0777); }
$config_path = "{$root_dir}dat/config.dat"; if(!file_exists($config_path)) { $of = fopen($config_path,"w"); fclose($of); chmod($config_path, $chmod_wf); }
$count_path = "{$root_dir}dat/count.dat"; if(!file_exists($count_path)) { $of = fopen($count_path,"w"); fclose($of); chmod($count_path, $chmod_wf); }
$style_path = "{$root_dir}dat/style.dat"; if(!file_exists($style_path)) { $of = fopen($style_path,"w"); fclose($of); chmod($style_path, $chmod_wf); }
$index_path = "{$root_dir}dat/index.dat"; if(!file_exists($index_path)) { $of = fopen($index_path,"w"); fclose($of); chmod($index_path, $chmod_wf); }
$badip_path = "{$root_dir}dat/badip.dat"; if(!file_exists($badip_path)) { $of = fopen($badip_path,"w"); fclose($of); chmod($badip_path, $chmod_wf); }
if(!is_dir($vots_path)) { mkdir($vots_path, 0777); } else { chmod($vots_dir, 0777); }
$exp = "]%["; // большая просьба этот пораметер не менять когда голосование уже было настроено ...
$inc['error'] = "error.inc"; $inc['content'] = "content.inc"; $inc['content_end'] = "content_end.inc"; $inc['add_vot'] = "add_vot.inc"; $inc['show_vot'] = "show_vot.inc"; $inc['configuring'] = "admin.inc"; $inc['modify_style'] = "modify_style.inc"; $inc['vot'] = "vot.inc"; $inc['add_voting'] = "add_voting.inc"; $inc['auth'] = "auth.inc"; $inc['profile'] = "profile.inc";
# конец настройки параметров # ?>
|
inc/ Код | addvot.inc
<?php if(isset($_COOKIE['lock_vot'])) { if($_COOKIE['lock_vot'] == $_GET['vid']) { header("location: ?vid={$_GET['vid']}&act=show"); } } if(!isset($POST['addvot'])) { ?> <form action="<?php echo $SELF."?{$_SERVER['QUERY_STRING']}&vid={$vid}&act=add"; ?>" method="POST"> <table> <tr> <td> <table class="trad"> <tr> <td> <b class="contentvots"><?php echo $index[$vid]; ?></b> </td> </tr> <?php $vot_line = file($vots_path.$vid); $i = 0; $c = count($vot_line); while($i < $c) { $idx = explode($exp,$vot_line[$i]); $vots[] = $idx[1]; unset($idx); $i++; } for($i = 0; $i < count($vots); $i++) { echo "<tr><td>\n"; echo "<input class=\"vot_radio\" type=\"radio\" name=\"item\" value=\"$i\"> $vots[$i]\n"; echo "</td></tr>\n"; } ?> <tr> <td> <input class="submitvots" name="addvot" type="submit" value="голосовать"><p> <a class="show_vot_res" href="<?php echo $SELF."?{$_SERVER['QUERY_STRING']}&vid=".$vid."&act=show"; ?>">результаты</a> </td> </tr> </table> </td> </tr> </table> </form> <?php } else if(isset($POST['addvot'])) { if(!isset($POST['item'])) { echo "Вы не выбрали за что голосовать ! <a href=\"javascript:history.go(-1);\" class=\"back\">back</a>"; return; } for($i = 0; $i < count($badip); $i++) { if($IP == trim($badip[$i][1]) and $vid == trim($badip[$i][0])) { echo "Вы здесь уже проголосовали !"; return; } } $vot_line = file($vots_path.$vid); $i = 0; $c = count($vot_line); $fop = fopen($vots_path.$vid,"w"); flock($fop,2); while($i < $c) { $idx = explode($exp,$vot_line[$i]); if($POST['item'] == $i) { $idx[0]++; } fputs($fop,$idx[0].$exp.$idx[1]); unset($idx); $i++; } flock($fop,3); fclose($fop); $fop = fopen($badip_path,"a+"); flock($fop,2); fputs($fop,$vid.$exp.$IP."\n"); flock($fop,3); fclose($fop); $date = date("Y"); $date = $date+10; setcookie("lock_vot", $vid, mktime(0,0,0,0,0,$date)); ?> <b>Спасибо, Ваш голос учтен.</b><br> Подождите сейчас Вас переадресует на страницу с результатами голосования. <script language="javascript"> <!-- function ReDir() { window.location.href="<?php echo $SELF."?vid=".$vid."&act=show"; ?>"; } window.setTimeout('ReDir()', <?php echo $timeout; ?>); --> </script> <?php } ?>
admin.inc
<script language="javascript"> <!-- function HiddenInputChangeValue(hInputID,val) { document.getElementById(hInputID).value = val; } --> </script> <form action="<?php echo $SELF."?".$QS; ?>" method="post"> <table class="table_admin" width="50%" align="center"> <tr align="center"> <input type="hidden" ID="hI" name="cfg" value="default"> <td><b>Администрирование AHT Voting v 1.0.1</b><br><br></td> </tr> <tr align="center"> <td><input onClick="javascript:HiddenInputChangeValue('hI','vot');" class="admin_input" type="submit" value="Добавить/Удалить/Править Голосование"></td> </tr> <tr align="center"> <td><input onClick="javascript:HiddenInputChangeValue('hI','profile');" class="admin_input" type="submit" value="Редактировать профиль"></td> </tr> <tr align="center"> <td><input onClick="javascript:HiddenInputChangeValue('hI','style');" class="admin_input" type="submit" value="Редактирование стиля"></td> </tr> </table> </form> <center><a href="<?php echo $SELF; ?>" class="arhiv">arhive vots</a></center>
auth.inc
<form action="<?php echo $SELF."?".$QS; ?>" method="post"> <table class="auth"> <tr> <td></td> <td></td> </tr> <tr> <td>Имя:</td> <td><input class="auth_input"s type="text" name="name" size=20 maxlength=20> </td> </tr> <tr> <td>Пароль:</td> <td><input class="auth_input" type="password" name="password" size=20 maxlength=20> </td> </tr> <tr> <td></td> <td><input class="auth_input" name="auth" type="submit" value="--- auth ---"> </td> </tr> </table> </form>
content.inc <html> <head> <title> hhh</title> <!-- VOTS --> <style> .l_t_vot {width: 4px; background: url(vot_bg/l_t.gif); border-width: 0} .r_t_vot {width: 4px; background: url(vot_bg/r_t.gif); border-width: 0} .c_t_vot {height: 13px; background: url(vot_bg/c_t.gif); border-width: 0} </style> </head> <body>
content_end.inc
</body> </html>
error.inc
<html> <head> <title>Error: <?php echo $error; ?></title> <meta name="Author" content="IZ@TOP"> <meta name="Generator" content="AceHTML 4 Pro"> <style> .error {border-collapse: collapse; color: #990000; font-family: Tahoma; font-size: 8pt; text-align: center} </style> </head> <body bottommargin=0 topmargin=0 leftmargin=0 rightmargin=0 marginheight=0 marginwidth=0> <table class="error" border=1 width="100%" height="100%"> <tr> <td valign="middle" align="center"> <table class="error" border=1 cellspacing=3 cellpadding=3 bordercolor=#000000 bgcolor=#ECECEC width="200" height="50"> <tr> <td><div align="center"> <font color="#000000">В ходе выполнения сценария произошла ошибка:</font><br> ----- <?php echo $error; ?> ----- </div></td> </tr> </table> </td> </tr> </table> </body> </html>
modify_style.inc
<?php if(isset($POST['automatic'])) { if(isset($POST['write'])) { $i = 0; $c = count($style_line); while($i < $c) { $idx = explode("{",$style_line[$i]); $tag[] = $idx[0]; $st[] = ereg_replace("}","",$idx[1]); unset($idx); $i++; } $i = 0; $c = count($st); while($i < $c) { $idx = explode(";",$st[$i]); $skv[$i] = $idx; unset($idx); $i++; } $i = 0; $n = 0; $exit = false; while($exit == false) { if($i == count($skv)) { $exit = true; } if($n < count($skv[$i])) { $idx = explode(":",$skv[$i][$n]); $key[$i][] = $idx[0]; $val[$i][] = $idx[1]; unset($idx); $n++; } else { $n = 0; $i++; } } $fop = fopen($style_path,"w") or $err = 1; $i = 0; $w_s = ""; $toval = $POST['toval']; while($i < count($toval)) { for($t = 0; $t < count($toval[$i]); $t++) { if($t == count($toval[$i])-1) { $end = ""; } else { $end = ";"; } $w_s .= $key[$i][$t].":".$toval[$i][$t].$end; } fputs($fop,$tag[$i]."{".$w_s."}\n") or $err = 1; unset($w_s); $i++; } fclose($fop); if(isset($err)) { echo "Произошла ошибка ! Возможные причины: невозможно открыть либо записать файл.<br>"; } else { ?> <div align="center">Изменения успешно внесены.<br> <? } ?> Подождите, сейчас Вас переадресует на страницу администрирования. <script language="javascript"> <!-- function ReDir() { window.location.href="<?php echo $SELF."?".$QS; ?>"; } window.setTimeout('ReDir()', <?php echo $timeout; ?>); --> </script></div> <? } else { $i = 0; $c = count($style_line); while($i < $c) { $idx = explode("{",$style_line[$i]); $tag[] = $idx[0]; $st[] = ereg_replace("}","",$idx[1]); unset($idx); $i++; } $i = 0; $c = count($st); while($i < $c) { $idx = explode(";",$st[$i]); $skv[$i] = $idx; unset($idx); $i++; } $i = 0; $n = 0; $exit = false; while($exit == false) { if($i == count($skv)) { $exit = true; } if($n < count($skv[$i])) { $idx = explode(":",$skv[$i][$n]); $key[$i][] = $idx[0]; $val[$i][] = $idx[1]; unset($idx); $n++; } else { $n = 0; $i++; } } echo "<table cellpadding=3 border=1 class=\"cascade\" width=\"100%\">"; echo "<tr><th colspan=2>Настройка таблицы каскадных стилей:</th></tr>"; echo "<tr><td>TAG/CLASS</td><td align=\"center\">Предустановленное значение</td></tr>"; echo "<form action=\"$SELF?$QS\" method=\"post\">"; for($i = 0; $i < count($tag); $i++) { ?> <tr class="tr_cascade"><td width="100"><b><?php echo $tag[$i]; ?></b></td><td> <?php for($t = 0; $t < count($key[$i]); $t++) { echo $key[$i][$t]; ?>: <input class="value_css" type="text" name="toval<?php echo "[{$i}][{$t}]"; ?>" size=40 maxlength=100 value="<?php echo $val[$i][$t]; ?>">;<?php } ?> </td> <? } echo "<tr><td></td><td><input type=\"hidden\" name=\"automatic\" value=\"yes\">"; echo "<tr><td></td><td><input type=\"hidden\" name=\"cfg\" value=\"style\">"; echo "<input type=\"submit\" name=\"write\" value=\"Изменить\"></td></tr>"; echo "</form>"; echo "</table>"; }
} else if(isset($POST['manually'])){ if(isset($POST['write'])) { $fop = @fopen($style_path,"w") or $err = 1; @fputs($fop,$POST['style']) or $err = 1; @fclose($fop); if(isset($err)) { echo "Произошла ошибка ! Возможные причины: невозможно открыть либо записать файл.<br>"; } else { ?> <div align="center">Изменения успешно внесены.<br> <? } ?> Подождите, сейчас Вас переадресует на страницу администрирования. <script language="javascript"> <!-- function ReDir() { window.location.href="<?php echo $SELF."?".$QS; ?>"; } window.setTimeout('ReDir()', <?php echo $timeout; ?>); --> </script></div> <? } else { ?> Редaктирование каскадных стилей вручную:<br> <form action="<?php echo $SELF.'?'.$QS; ?>" method="post"> <input type="hidden" name="cfg" value="style"> <input type="hidden" name="manually" value="yes"> <input type="hidden" name="write" value="yes"><br> <textarea name="style" cols=60 rows=10><?php for($i = 0; $i < count($style_line); $i++) { echo $style_line[$i]; } ?></textarea><br> <input type="submit" name="write" value="write"> </form> <? } } else { ?> <div align="center"> <form action="<?php echo $SELF.'?'.$QS; ?>" method="post"> <input type="hidden" name="cfg" value="style"> Редактирование стилей вручную<br> <input type="submit" name="manually" value="manually"><p> Автоматическая настройка стилей<br> <input type="submit" name="automatic" value="automatic"><p> </form> </div> <? } ?>
profile.inc
<?php if(!isset($POST['update'])) { ?> <form action="<?php echo $SELF."?".$QS; ?>" method="post"> <table align="center"> <tr> <th colspan=2><b>Изменение профиля:</b> <input type="hidden" name="cfg" value="profile"> <input type="hidden" name="no_output" value="yes"> </th> </tr> <tr><td>Новое имя:</td> <td><input type="text" name="update_name" size=20 maxlength=20> </td> </tr> <tr><td>Новый пароль:</td> <td><input type="password" name="update_password" size=20 maxlength=20> </td> </tr> <tr><td>Повторите пароль:</td> <td><input type="password" name="confirm_update_password" size=20 maxlength=20> </td> </tr> <tr><td>Запомнить меня:</td> <td> <input type="checkbox" name="member" value="yes"><br> write cookie ? </td> </tr> <tr><td></td> <td><input type="submit" name="update" value="update"> </td> </tr> </table> <table border=0 align="center"> <tr align="center"> <td> Еще раз предупреждение:<p> Не забудьте свое имя и пароль. Одностороннее шифрование данных функцией MD5 - невосстановимо ! </td> </tr> </table> </form> <? } else { if($POST['update_password'] != $POST['confirm_update_password']) { echo "Пароли несовпадают !"; exit(); } if(empty($POST['update_name']) and empty($POST['update_password'])) { echo "Нельзя использовать в качесиве значений профиля пустое значение !"; exit(); } if(!empty($POST['member'])) { $time_cookie = time()+390000*9000000; } else { $time_cookie = 100; } $crypt_name = md5($POST['update_name']); $crypt_password = md5($POST['update_password']); $fop = fopen($config_path,"w"); fputs($fop,$crypt_name.$exp.$crypt_password.$exp.$time_cookie); fclose($fop); echo "<div align=\"center\">Изменения успешно внесены в Ваш профиль.</div>"; } ?>
show_vot.inc
<table> <tr> <td> <table class="showvots"> <tr> <td> <b class="contentvots">Результаты голосования - "<?php echo $index[$vid]; ?>":<br></b> <?php $summ = 0;
$vot_line = @file($vots_path.$vid); $c = count($vot_line); for($i = 0; $i < $c; $i++) { $idx = explode($exp,$vot_line[$i]); $result[$i][] = $idx[0]; $result[$i][] = $idx[1]; $summ = $summ + $idx[0]; } for($i = 0; $i < $c; $i++) { $persent[] = $result[$i][0] * 100 / $summ; } $i = 0; $max = 10; while($i < $c) { $persent[$i] = substr($persent[$i],0,5); echo "<tr><td>\n"; echo "<b>{$result[$i][1]}</b> - <i>{$result[$i][0]}</i> чел.<br>\n"; echo "{$persent[$i]}% от всех голосов \n"; if($persent[$i] != 0) { echo "<table height=\"13\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"; class=\"persent\"><tr><td nowrap class=\"l_t_vot\"></td><td width=\"{$persent[$i]}%\" height=\"13\" class=\"c_t_vot\">"; echo "</td><td height=\"13\" nowrap class=\"r_t_vot\"</td><td width=100%><td></tr></table>\n"; } else { echo "<br> <br>"; } echo "</td></tr>\n"; $i++; } ?> </table><br> <div align="left"><a href="javascript:history.back(-1);">Назад</a></div> </td> </tr> </table>
vot.inc
<?php if(isset($POST['update'])) { if(isset($POST['add'])) { if(isset($POST['how_many'])) { if(isset($POST['question'])) { $count = count(@file($count_path)); $count++; $fop = fopen($count_path,"a+") or $err = "1:8"; fputs($fop,"[{$count}]\n") or $err = "2:9"; fclose($fop); $fop = fopen($index_path,"a+") or $err = "1:8"; fputs($fop,$count.$exp.$POST['question']."\n") or $err = "2:8"; fclose($fop); $fop = fopen($vots_path.$count,"w+") or $err = "1:14"; chmod($vots_path.$count,0660); $item = $POST['item']; for($i = 1; $i <= count($item); $i++) { fputs($fop,"0".$exp.$item[$i]."\n") or $err = "2:18"; } fclose($fop); if(isset($err)) { echo "В ходе выполнения сценария произошла ошибка : error id {$err}. Возможные прчины: неудалось открыть ('error id 1') или записать файл ('error id 2')."; exit(); } ?> Новое голосование успешно создано.<br> Подождите, сейчас Вас переадресует на страницу c новым опросом. <script language="javascript"> <!-- function ReDir() { window.location.href="<?php echo $SELF."?vid={$count}&act=add"; ?>"; } window.setTimeout('ReDir()', <?php echo $timeout; ?>); --> </script></div> <? exit(); } if($POST['how_many'] < 2) { echo "Ответов в голосовании не олжно быть меньше двух !"; exit(); } ?> <form action="<?php echo $SELF."?".$QS; ?>" method="post"> <table> <tr><th colspan=2> <input type="hidden" name="cfg" value="vot"> <input type="hidden" name="how_many" value="vot"> <input type="hidden" name="update" value="yes"> <input type="hidden" name="add" value="yes"> Новое голосование. </th></tr> <tr><td>Введите вопрос:</td><td> <input class="question" type="text" name="question" size=40 maxlength=300> </td></tr> <? for($i = 1; $i <= $POST['how_many']; $i++) { echo "<tr><td>Вариант ответа №{$i}:</td>"; echo "<td><input type=\"text\" name=\"item[{$i}]\"></td></tr/>"; } ?><tr><td></td><td> <input type="submit" name="add" value="Создать"></td></tr> </table> </form> <? } else { ?> <div align="center"><form action="<?php echo $SELF."?".$QS; ?>" method="post"> <input type="hidden" name="cfg" value="vot"> <input type="hidden" name="add" value="yes"> <input type="hidden" name="update" value="yes"> Количество ответов: <input type="text" maxlength=30 name="how_many"><br> <input type="submit" name="update" value="ok"><br> </form></div> <? } } else if(isset($POST['edit'])) { if(isset($POST['edit_only'])) { $vot_name = $POST['vot_name']; $index = $POST['index']; $id = $POST['vot_id']; $n = $POST['n']; $v = $POST['v']; $i = 0; while($i < count($n)) { $n[$i] = ereg_replace("\n","",$n[$i]); $n[$i] = ereg_replace("\r","",$n[$i]); $v[$i] = ereg_replace("\n","",$v[$i]); $v[$i] = ereg_replace("\r","",$v[$i]); $i++; }
$idx = explode($exp,$index_line[$id]); ereg_replace("\n","",$vot_name); ereg_replace("\r","",$vot_name); $idx[1] = $vot_name."\n"; $index_line[$id] = $idx[0].$exp.$idx[1]; unlink($index_path); $fop = fopen($index_path,"a+") or $err = 1; chmod($index_path,0660); for($i = 0; $i < count($index_line); $i++) { fputs($fop,$index_line[$i]) or $err = 2; } fclose($fop); unlink($vots_path.$index); $fop = fopen($vots_path.$index,"a+") or $err = 1; chmod($vots_path.$index,0660); $i = 0; while($i < count($n)) { fputs($fop,$n[$i].$exp.$v[$i]."\n") or $err = 2; $i++; } fclose($fop); if(isset($err)) { echo "В ходе выполнения сценария произошла ошибка : error id {$err}. Возможные прчины: неудалось открыть ('error id 1') или записать файл ('error id 2')."; exit(); } ?> Голосование "<b><?php echo $vot_name; ?></b>" успешно отредактировано.<br> Подождите, сейчас Вас переадресует на отредактированный опрос. <script language="javascript"> <!-- function ReDir() { window.location.href="<?php echo $SELF."?vid={$idx[0]}&act=add"; ?>"; } window.setTimeout('ReDir()', <?php echo $timeout; ?>); --> </script></div> <? } else { if(isset($POST['edit_preview'])) { $eitem = $POST['edit_item']; $vot_line = @file($vots_path.$eitem); ?> <form action="<?php echo $SELF."?".$QS; ?>" method="post"> <input type="hidden" name="edit_only" value="yes"> <input type="hidden" name="update" value="yes"> <input type="hidden" name="cfg" value="vot"> <input type="hidden" name="edit" value="yes"> <input type="hidden" name="index" value="<?php echo $eitem; ?>"> <b>Редактирование опроса:</b><p> <? for($i = 0; $i < count($index_line); $i++) { $idx = explode($exp,$index_line[$i]); if($eitem == $idx[0]) { echo "<input type=\"text\" name=\"vot_name\" style=\"width:400\" value=\"{$idx[1]}\"><p>"; echo "<input type=\"hidden\" name=\"vot_id\" value=\"{$i}\">"; } } for($i = 0; $i < count($vot_line); $i++) { $idx = explode($exp,$vot_line[$i]); ?> <input name="<?php echo "n[{$i}]"; ?>" type="text" value="<?php echo $idx[0]; ?>" style="width:20;"> <input name="<?php echo "v[{$i}]"; ?>" type="text" style="width:377;" value="<?php echo $idx[1]; ?>"><br> <? } ?><br> <input style="width:400;" type="submit" value="ok"> </form> <? } else { ?> Выбирете опрос который будете редактировать:<br> <form action="<?php echo $SELF."?".$QS; ?>" method="post"> <input type="hidden" name="edit_preview" value="yes"> <input type="hidden" name="update" value="yes"> <input type="hidden" name="cfg" value="vot"> <input type="hidden" name="edit" value="yes"> <table border=0> <? for($i = 0; $i < count($index_line); $i++) { $idx = explode($exp,$index_line[$i]); ?> <tr><td><?php echo $idx[1]; ?></td><td> <input type="radio" class="radio" name="edit_item" value="<?php echo $idx[0]; ?>"> </td></tr> <? } ?> </table><p> <input type="submit" value="edit"> </form> <? } } } else if(isset($POST['del'])) {
if(isset($POST['delete'])) {
if(empty($POST['ditem'])) { echo "Вы не выбрали голосование которое следует удалть !"; exit(); } $ditem = $POST['ditem']; $cdi = count($ditem); $update_index = $index_line; $i = 0; $t = 0; while($i < count($index_line)) { $idx = explode($exp, $index_line[$i]); if($ditem[$t] == $idx[0]) { unset($update_index[$i]); unlink($vots_path.$ditem[$t]); $t = $cdi; } if($t < $cdi) { $t++; } else { $i++; $t = 0; } } $update_index = array_reverse($update_index); unlink($index_path); $fop = fopen($index_path,"a+") or $err = 1; chmod($index_path, 0660); for($i = 0; $i < count($update_index); $i++) { fputs($fop,$update_index[$i]) or $err = 2; } fclose($fop); if(isset($err)) { echo "В ходе выполнения сценария произошла ошибка : error id {$err}. Возможные прчины: неудалось открыть ('error id 1') или записать файл ('error id 2')."; exit(); } ?> Выбранные опросы удалены.<br> Подождите, сейчас Вас переадресует на страницу c архивом голосований. <script language="javascript"> <!-- function ReDir() { window.location.href="<?php echo $SELF; ?>"; } window.setTimeout('ReDir()', <?php echo $timeout; ?>); --> </script></div> <? } else { ?> <form action="<?php echo $SELF."?".$QS; ?>" method="post"> <input type="hidden" name="update" value="yes"> <input type="hidden" name="cfg" value="vot">
|
|
|
|
Правила форума "PHP" |





|
Новичкам:
- PHP редакторы собираются и обсуждаются здесь
- Электронные книги по PHP, документацию можно найти здесь
- Интерпретатор PHP, полную документацию можно скачать на PHP.NET
Важно:
- Не брезгуйте пользоваться тегами [code=php]КОД[/code] для повышения читабельности текста/кода.
- Перед созданием новой темы воспользуйтесь поиском и загляните в FAQ
- Действия модераторов можно обсудить здесь
Внимание:
- Темы "ищу скрипт", "подскажите скрипт" и т.п. будут переноситься в форум "Web-технологии"
- Темы с именами: "Срочно", "помогите", "не знаю как делать" будут УДАЛЯТЬСЯ
Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, IZ@TOP, skyboy, SamDark, MoLeX, awers.
|
1 Пользователей читают эту тему (1 Гостей и 0 Скрытых Пользователей)
|
0 Пользователей:
|
« Предыдущая тема | PHP: Общие вопросы | Следующая тема »
|
|
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности
Powered by Invision Power Board(R) 1.3 © 2003 IPS, Inc. |
|
|