1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| <?php
$zones = array();
if(isset($_REQUEST['zone'])) {
foreach($_REQUEST['zone'] as $zone) {
$zones[] = array('top' => $zone['top'], 'left' => $zone['left'], 'width' => isset($zone['width'])?$zone['width']:0, 'height' => isset($zone['height'])?$zone['height']:0);
}
}
if (count($zones) == 0) {
$zones[] = array('top' => -1, 'left' => -1, 'width' => 0, 'height' => 0);
}
$current = count($zones) - 1;
if(isset($_REQUEST['click']) && isset($_REQUEST['x']) && isset($_REQUEST['y'])) {
if ($zones[$current]['top'] == -1) {
$zones[$current]['top'] = $_REQUEST['y'];
$zones[$current]['left'] = $_REQUEST['x'];
} else {
if ($_REQUEST['y'] < ($zones[$current]['top'] + $zones[$current]['height'] / 2)) {
$zones[$current]['height'] = $zones[$current]['height'] + $zones[$current]['top'] - $_REQUEST['y'];
$zones[$current]['top'] = $_REQUEST['y'];
} else {
$zones[$current]['height'] = $_REQUEST['y'] - $zones[$current]['top'];
}
if ($_REQUEST['x'] < ($zones[$current]['left'] + $zones[$current]['width'] / 2)) {
$zones[$current]['width'] = $zones[$current]['width'] + $zones[$current]['left'] - $_REQUEST['x'];
$zones[$current]['left'] = $_REQUEST['x'];
} else {
$zones[$current]['width'] = $_REQUEST['x'] - $zones[$current]['left'];
}
}
}
if (isset($_REQUEST['save'])) {
$current++;
$zones[] = array('top' => -1, 'left' => -1, 'width' => 0, 'height' => 0);
}
$can_save = $zones[$current]['width'] && $zones[$current]['height'];
?>
<html>
<head>
<style type="text/css">
#map {
position:relative;
}
#image {
position:absolute;
}
.zone {
position:absolute;
border:1px solid blue;
}
.zone div {
width:100%;
height:100%;
background:blue;
opacity:0.2;
filter: alpha(opacity=20);
}
.done {
border:1px solid orange;
}
.done div {
background:yellow;
}
area {
border:1px solid red;
}
</style>
</head>
<body>
<div>
<?php
if (isset($_REQUEST['generate'])) {
?> <img src="Nenuphars.jpg" usemap="#test_map" />
<map name="test_map">
<?php $nb = count($zones);
for ($i = 0 ; $i < $nb - 1 ; $i++) { //On saute la dernière qui n'est jamais inachevée
?><area href="zone_<?=$i?>.html" alt="zone <?=$i?>" title="zone <?=$i?>" shape="rect" coords="<?=$zones[$i]['left']?>,<?=$zones[$i]['top']?>,<?=$zones[$i]['left']+$zones[$i]['width']?>,<?=$zones[$i]['top']+$zones[$i]['height']?>" />
<?php
} ?>
</map><?php
} else {
?>
<form action="" method="GET">
<input type="hidden" name="click" value="1" />
<input type="submit" name="save" value="save" <?=($can_save?'':'disabled="disabled"')?> />
<input type="submit" name="generate" value="generate" />
<?php foreach($zones as $key => $value) { ?>
<input type="hidden" name="zone[<?=$key?>][top]" value="<?=$value['top']?>" />
<input type="hidden" name="zone[<?=$key?>][left]" value="<?=$value['left']?>" />
<input type="hidden" name="zone[<?=$key?>][width]" value="<?=$value['width']?>" />
<input type="hidden" name="zone[<?=$key?>][height]" value="<?=$value['height']?>" />
<?php } ?>
<div id="map">
<input id="image" type="image" src="Nenuphars.jpg" />
<?php foreach($zones as $key => $value) { ?>
<div class="zone <?php echo $key!=$current?'done':''; ?>" style="top:<?=$value['top']?>;left:<?=$value['left']?>;height:<?=$value['height']?>;width:<?=$value['width']?>;"><div></div></div>
<?php } ?>
</div>
</form>
<?php } ?>
</div>
</body>
</html> |
Partager