<?php
$links = array ('http://yandex.ru/','http://google.com/','http://rambler.ru','http://www.mail.ru/','http://yahoo.com/',
'http://msn.com/','http://www.yellowpages.ru/', 'http://www.liveinternet.ru/', 'http://www.lenta.ru/','http://www.3.org/'
);
function MyCount()
{
global $links;
$file='count.txt';
if(!file_exists($file)){$fp = fopen($file, "w");fwrite($fp,'0');fclose($fp);}
$k=(int)file_get_contents($file);
$z=$k+1;
$countf=fopen($file,"r+");
flock($countf,2);
fputs($countf,$z);
fclose($countf);
$z=($k % count($links));
if ($z==0){$z=count($links);}else {$z=$z-1;}
return $z;
}
function MyList($k)
{
global $links;
$z= count($links)-$k;
if ($z<5) {
$links2=array_slice($links,($k),$z,true)+array_slice($links,0,(5-$z),true);
}
else
{
$links2=array_slice($links,$k,5,true);
}
return $links2;
}
function MyListToHTML($list)
{
$out='';
foreach ($list as $key => $value)
{ $key2=$key+1;
$out.='<tr><th><input id="'.$key2.'" name="'.$key.'" type=checkbox><th><label for="'.$key2.'">'.$value.'</label></tr>';
}
return $out;
}
?>
<html>
<head>
<script type="text/javascript">
var x;var y;
function t(i){return (i<10)?"0"+i:i;}
function z(){
var e = new Date();
window.status=t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+" x= "+x+", y= "+y;
setTimeout('z()',1);
}
document.onmousemove=function(){x=event.x;y=event.y;}
function s(){
var k=false;
var nodeList = document.getElementsByTagName('input');
for (var i = 0; i < nodeList.length; i++)
{
if(nodeList[i].getAttribute("type") =="checkbox")
{
if (nodeList[i].checked==true)
{
k=true;
}
}
}
if(!k){alert('Ничего не выбрано');}
return k;
}
</script></head>
<body onLoad="z()">
<?php
if(isset($_POST['submitMe']))
{
echo("Вами были выбраны следующие ссылки:<br>");
foreach ($_POST as $key => $value)
{
if ($value=='on') echo '<a href="'.$links[$key].'">'.$links[$key].'</a><br>';
}
}
else
{
?>
<form name='MyList' method="POST" action="<?=$_SERVER['PHP_SELF']?>" onsubmit="return s();">
<table border=all><col align=center><col align=left>
<?php echo MyListToHTML(Mylist(MyCount()));; ?>
<tr><th> <th><input type=submit name="submitMe" value="Oк" style="width:200px;"></tr>
</table>
</form>
<?
}
?>
</body></html>
$end
preferences:
42.51 ms | 402 KiB | 5 Q