0

I am needing to create a date calculator for horse pregnancy. Sounds odd, but this is the requirement. This is a veterinarian and the form already exists on hardcoded php site, but I have no access to files that perform this functionality.

Is there a way to use drupal webform (maybe in combination with webform calculator module) to accomplish this or is hard coding the only option? If so, any direction in this would be greatly appreciated

The basics of the functionality are this:

Choose a breeding conception date : This will be date field

Enter estimated gestation period in days : This will be integer field

Below are week progressions into the gestation:

Week 2 (2 weeks to 18 days) : Actual date will be populated on submit

First ultrasound or palpation to detect pregnancy

Week 4 - 1st Month : Actual date will be populated on submit

Second ultrasound or palpation to detect heart beat

Week 12 - 3rd Month : Actual date will be populated on submit

Give all vaccinations recommended for your area

Week 20 - 5th Month : Actual date will be populated on submit

First Equine Rhinopneumonitis Vaccination

Week 28 - 7th Month : Actual date will be populated on submit

Second Equine Rhinopneumonitis Vaccination

Week 36 - 9th Month : Actual date will be populated on submit

Third Equine Rhinopneumonitis Vaccination

Week 44 - 11th Month : Actual date will be populated on submit

Give all vaccinations recommended for your area so that mare produces antibodies in colostrum.

Due Date : Actual date will be populated on submit

reset | Submit

Here is the live example I'm trying to recreate in Drupal http://www.timbercreekveterinaryhospital.com/foalcalc.php

I was actually able to get the site files. The only problem is when it calculates each date, it's defaulting back to year 1970 starting at Jan 1. I'm learning PHP right now, but cannot see why this date is not being loaded into $bred variable. See the code below (I know it's a lot).

<?
$gestationperiod = 340;
$tobecalc= "<span style=\"font-size:12px;font-style:italic;\">to be             calculated</span>";
$week2 = $tobecalc;
$week4 = $tobecalc;
$week12 = $tobecalc;
$week20 = $tobecalc;
$week28 = $tobecalc;
$week36 = $tobecalc;
$week44 = $tobecalc;
$duedate = $tobecalc;
$id = 0;  // for use in selectday month year include-files

if(isset($_POST['horsename'])) {
 $gestationperiod = $_POST['gestationperiod'];
 $bred = strtotime($theyear[0] . '/' . $month[0] . '/' . $day[0]);
 $week2 = date('M j, Y', ($bred + 14 * 86400));
 $week4 = date('M j, Y', ($bred + 28 * 86400));
 $week12 = date('M j, Y', ($bred + 84 * 86400));
 $week20 = date('M j, Y', ($bred + 140 * 86400));
 $week28 = date('M j, Y', ($bred + 196 * 86400));
 $week36 = date('M j, Y', ($bred + 252 * 86400));
 $week44 = date('M j, Y', ($bred + 308 * 86400));
 $duedate = date('M j, Y', ($bred + $_POST['gestationperiod'] * 86400));
}
?>


<div style="margin:12px;text-indent:22px;font-size:42px;letter-    spacing:3px;line-height:72px;">Gestation Calculator</div>
<center>
<table width="700px" cellpadding=0 cellspacing=0 border=0>
<tr><td class=v style="font-size:16px;">

This gestation calculator is for information and fun only. The dates that     are calculated are an estimate of when to expect your new arrival and should not     be interpreted as an exact foaling date.
<br><br>
This Foaling Date Estimator is based on 340 days gestation. 
<div class=v style="font-size:16px;font-style:italic;">You should average     plus or minus 10 days for actual foaling window.</div>
<br>
If you'd like to keep records for several horses, 
enter each horse's name before printing the page.
</td></tr>
</table>

<a name="calculate"></a>
<script language="javascript">
<!--
function doReset() {
 document.calcForm.horsename.value = ''
 document.calcForm.gestationperiod.value = 340
 document.calcForm.gestationperiod.focus();
 return false;
}
-->
</script>

<FORM method=post action="foalcalc.php?#calculate" name="calcForm">
<table width="700px" cellpadding=0 cellspacing=10 border=0 class=v     style="font-size:16px;">
<tr><td colspan=2>
<br><br>
<span style="font-weight:bold;">Name of Horse:&nbsp;</span><input type=text     name="horsename" value="<?=$_POST['horsename']; ?>" maxlength=55 size=60>
</td></tr>

<tr><td>
Date mare was bred:
</td>
<td align=center style="white-space:nowrap;">
<?
//Select Month
if(isset($month[$id])) $m = $month[$id];
else $m = date(n);

echo "\n<select name=month[$id] class=small>";
for ($k=1; $k<=12; $k++) {
  if ($k == $mo) $s = " SELECTED";
  elseif ($k == $m && $mo == "") $s = " SELECTED";
  else $s = "";
   if ((strlen($k)) <= 1) $k = "0$k";
 echo "\n<option value=$k$s>$k</option>";
 }
echo "\n</select>";

//Select Day
if(isset($day[$id])) $d = $day[$id];
else $d = date(j);

echo "\n<select name=\"day[$id]\" class=small>";
for ($k=1; $k<=31; $k++) {
  if ($k == $da) $s = " SELECTED";
  elseif ($k == $d && $da == "") $s = " SELECTED";
  else $s = "";
  if ((strlen($k)) <= 1) $k = "0$k";
 echo "\n<option value=$k $s>$k</option>";
 }
echo "\n</select>";

//Select Year
if(isset($theyear[$id])) $y = $theyear[$id];
else $y = date(Y);

echo "\n<select name=theyear[$id] class=small>";
for ($k=($y-1); $k<=($y+2); $k++) {
  if ($k == $yr) $s = " SELECTED";
  elseif ($k == $y && $yr == "") $s = " SELECTED";
  else $s = "";
 echo "\n<option value=$k$s>$k</option>";
 }
echo "\n</select>";

?>  
</td></tr>



<tr><td colspan=2 style="border-top:1px solid #bbbbbb;"></td></tr>



<tr><td>
<div class=v style="font-size:16px;font-weight:bold;">Enter estimated     gestation period in days:</div>
<div class=v style="font-size:14px;font-style:italic;padding-    left:32px;padding-top:8px;">(Normally calculated at 340 days.)</div>
</td>
<td align=center> 
<input type=text name=gestationperiod value="<?=$gestationperiod; ?>"     maxlength=3 size=5>
</td></tr>

<tr><td colspan=2 style="border-top:1px solid #bbbbbb;"></td></tr>

<tr><td>
<div class=v style="font-size:16px;font-weight:bold;">Week 2 (2 weeks to 18     days)</div> 
<div class=v style="font-size:14px;font-style:italic;padding-    left:32px;padding-top:8px;"><li>First ultrasound or palpation to detect     pregnancy</li></div>
</td>
<td align=center> 
<?=$week2; ?>
</td></tr>

<tr><td colspan=2 style="border-top:1px solid #bbbbbb;"></td></tr>

<tr><td>
<div class=v style="font-size:16px;font-weight:bold;">Week 4 - 1st     Month</div> 
<div class=v style="font-size:14px;font-style:italic;padding-    left:32px;padding-top:8px;"><li>Second ultrasound or palpation to detect heart     beat</li></div>
</td>
<td align=center> 
<?=$week4; ?>
</td></tr>

<tr><td colspan=2 style="border-top:1px solid #bbbbbb;"></td></tr>

<tr><td>
<div class=v style="font-size:16px;font-weight:bold;">Week 12 - 3rd     Month</div> 
<div class=v style="font-size:14px;font-style:italic;padding-    left:32px;padding-top:8px;"><li>Give all vaccinations recommended for your     area</li>
<br>
<li>Worm the mare</li></div>
</td>
<td align=center> 
<?=$week12; ?>
</td></tr>

<tr><td colspan=2 style="border-top:1px solid #bbbbbb;"></td></tr>

<tr><td>
<div class=v style="font-size:16px;font-weight:bold;">Week 20 - 5th     Month</div> 
<div class=v style="font-size:14px;font-style:italic;padding-    left:32px;padding-top:8px;"><li>First Equine Rhinopneumonitis Vaccination</li>    </div>
</td>
<td align=center> 
<?=$week20; ?>
</td></tr>

<tr><td colspan=2 style="border-top:1px solid #bbbbbb;"></td></tr>

<tr><td>
<div class=v style="font-size:16px;font-weight:bold;">Week 28 - 7th     Month</div>
<div class=v style="font-size:14px;font-style:italic;padding-    left:32px;padding-top:8px;"><li>Second Equine Rhinopneumonitis Vaccination</li>        </div>
</td>
<td align=center> 
<?=$week28; ?>
</td></tr>

<tr><td colspan=2 style="border-top:1px solid #bbbbbb;"></td></tr>

<tr><td>
<div class=v style="font-size:16px;font-weight:bold;">Week 36 - 9th Month</div>
<div class=v style="font-size:14px;font-style:italic;padding-left:32px;padding-top:8px;"><li>Third Equine Rhinopneumonitis Vaccination</li>    </div>
</td>
<td align=center> 
<?=$week36; ?>
</td></tr>

<tr><td colspan=2 style="border-top:1px solid #bbbbbb;"></td></tr>

<tr><td>
<div class=v style="font-size:16px;font-weight:bold;">Week 44 - 11th Month</div>
<div class=v style="font-size:14px;font-style:italic;padding-    left:32px;padding-top:8px;"><li>Give all vaccinations recommended for your area     so that mare produces antibodies in colostrum.</li>
<br>
<li>Worm the mare</li>
<br>
<li>Begin watching for waxing and other signs of early foaling.</li></div>
</td>
<td align=center> 
<?=$week44; ?>
</td></tr>

<tr><td colspan=2 style="border-top:1px solid #bbbbbb;"></td></tr>

<tr><td>
<div class=v style="font-size:16px;font-weight:bold;">Due Date</div>
</td>
<td align=center>
<?=$duedate; ?>
</td></tr>

<tr><td colspan=2 style="border-top:1px solid #bbbbbb;"></td></tr>

</table>


<table width="700px" cellpadding=0 cellspacing=0 border=0>
<tr><td style="padding-left:60px; padding-right:140px;font-style:italic;">
<br>
Disclaimer: It is the mare owner's responsibility to consult their vet with     regard to broodmare health care.
This Calendar is only a guideline.
<br><br>
</td></tr>
</table>
<button onclick="doReset()">Reset     Entries</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input     type=submit value="&nbsp;Calculate&nbsp;">
</FORM>
?>
  • best way I could think is to create custom ajax form to calculate the dates. check the usage here: phptherightway.com/#date_and_time – shrish Jan 20 '16 at 4:42
  • Thanks for the reply. I was actually able to get the site files that are working on the current prod site, and get those onto my dev server. THe only problem is it's not loading the date from the selected options when it calculates. Keeps defaulting to 1970. Anythng you see glaring that would cause this? Thanks in advance. – billy_comic Jan 21 '16 at 5:30
  • have you done this in custom module ? using form api ? or the custom php page? – shrish Jan 21 '16 at 5:34
  • This is just from a custom php page. I was thinking that if I can get it working just using the custom php page on my server, then I could implement the code on my drupal site using the php text format in my node. – billy_comic Jan 22 '16 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.