<html>
<head>
</head>
<body>
<?php
require("./adopttools.php");
/* Our visitor has picked an adoptable they want, its id is in $_REQUEST['id']. Find that
* adoptable in adoptables.xml
*/
$adoptable=find_adoptable($_REQUEST['id']);
/* To randomly pick a variation from that adoptable, we're going have to do a little maths with
* random numbers.
*
* First we find the sum of all the 'chance' attributes for this adoptable...
*/
$sum=0;
foreach ($adoptable->variation as $variation) {
$sum=$sum + $variation['chance'];
}
/* Now we can generate a random number which goes from 0.0 to that sum. This will help us
* pick a variation.
*/
$random=lcg_value()*$sum;
$sum=0;
foreach ($adoptable->variation as $variation) {
$sum = $sum + $variation['chance'];
if ($random <= $sum) {
//Choose this variation
$v_id=$variation['id'];
break;
}
}
?>
<p><img src="http://xxx.com/simple1.php?a=<?php echo $_REQUEST['id'];?>&v=<?php echo $v_id;?>"></p>
<p>Thanks for adopting this pet! :). Here is the adoption code for your pet:</p>
<p><textarea cols="60" rows="2"><img src="http://xxx.com/simple1.php?a=<?php echo $_REQUEST['id'];?>&v=<?php echo $v_id;?>"></textarea></p>
</body>
</html>
<adoptables>
<adoptable id="1">
<variation id="1" chance="1.0">
<age image="./dogbaby.png" />
<age date="2009-10-21" image="./dogpuppyrare.png" />
<age date="2009-10-22" image="./dogadultrare.png" />
</variation>
<variation id="2" chance="5.0">
<age image="./dogbaby.png" />
<age date="2009-10-21" image="./dogpuppy.png" />
<age date="2009-10-22" image="./dogadult.png" />
</variation>
</adoptable>
<adoptable id="2">
<variation id="1" chance="1.0">
<age image="./ratbaby.png" />
<age date="2009-10-21" image="./ratadult.png" />
</variation>
</adoptable>
</adoptables>
<?php
//Load the adoptables XML file
$adoptxml=simplexml_load_file("./adoptables1.xml");
//Find the adoptable from adoptables.xml which has the right id
function find_adoptable($id) {
global $adoptxml;
//For each 'adoptable' tag which is available
foreach ($adoptxml->adoptable as $adoptable) {
//Is this adoptable's id the same as the one that the user wants to see?
if ($adoptable['id']==$id) {
//Yes, it is
return $adoptable;
}
}
return NULL; //We couldn't find an adoptable with that ID
}
//Find the variation with the given adoptable id and variation id
function find_variation($adoptid, $varid) {
$adoptable=find_adoptable($adoptid);
//For each 'variation' tag which is available
foreach ($adoptable->variation as $variation) {
//Is this variation's id the same as the one that the user wants to see?
if ($variation['id']==$varid) {
//Yes, it is
return $variation;
}
}
return NULL; //We couldn't find the variation with that ID
}
?>
<?php
//Tell the browser that we are sending it a PNG image to display
header("Content-Type: image/png");
require("./adopttools.php");
//Find the variation with the given adoptable id ('a') and variation id ('v')
$variation=find_variation($_REQUEST['a'], $_REQUEST['v']);
//Decide which of the ages we want to show for the adoptable
$pickedAge=NULL; //We'll store the age we eventually pick into the variable $pickedAge
/* Check the ages in order. The age we end up picking will be the last age
* in the file where the current date is after the 'date' attribute
*/
foreach ($variation->age as $age) {
if (!isset($age['date']) || time() > strtotime($age['date'])) {
$pickedAge=$age;
}
}
//Now that we've picked the age, display the image that that age uses
readfile($pickedAge['image']);
exit();
?>
<!-- INCLUDE overall_header.html -->
<p class="{S_CONTENT_FLOW_END}<!-- IF S_USER_LOGGED_IN --> rightside<!-- ENDIF -->"><!-- IF S_USER_LOGGED_IN -->{LAST_VISIT_DATE}<!-- ELSE -->{CURRENT_TIME}<!-- ENDIF --></p>
<!-- IF U_MCP --><p>{CURRENT_TIME} <br />[ <a href="{U_MCP}">{L_MCP}</a> ]</p><!-- ELSEIF S_USER_LOGGED_IN --><p>{CURRENT_TIME}</p><!-- ENDIF -->
<div class="panel">
<div class="inner"><span class="corners-top"><span></span></span>
<div class="content">
<html>
<head>
</head>
<body>
<p>Adopt one of my pets!</p>
<table width="400" border="0" cellspacing="0" cellpadding="4">
<tr>
<td><img src="./dogbaby.png"></td>
<td><a href="adopt.php?id=1">Adopt a dog!</a></td>
</tr>
<tr>
<td><img src="./ratbaby.png"></td>
<td><a href="adopt.php?id=2">Adopt a rat!</a></td>
</tr>
</table>
</body>
</html>
</div>
<span class="corners-bottom"><span></span></span></div>
</div>
<!-- INCLUDE overall_footer.html -->
Users browsing this forum: No registered users and 3 guests