hallo iedereen,
Ik ben bezig met een script te maken wat tot bedoeling heeft om het aantal werkdagen dat iemand moet wachten te berekenen. Dus de bedoeling is:
iemand geeft een datum in (liefst heb ik dat er standaard die van vandaag staat) en deze moet dan kunnen selecteren of hij of zij standaard of premium is (60 werkdagen of 30 werkdagen wachten) en als hij/zij dan op berekenen drukt moet de datum na de 30 of 60 werkdagen eruit komen. Ik ben niet echt gevorderd op gebied van php, en heb een aantal bestaande scripts in combinatie van eigen html samengegooid en kom tot onderstaand resultaat voorlopig :P
<?php
/*
i-Bridge Systems Software Solutions
http://www.ibridge.co.uk
Copyright (c) 2006 i-Bridge Systems & www.ibridge.co.uk
for more information, products or support contact simon AT ibridge.co.uk or support AT ibridge . co . uk
*/
class clsWorkDays {
//
//Class : Hold all the functions to help when calculating dates
//Params
// :
//
var $holidays = array();
var $holiday_dates = array();
var $seconds_per_day = 86400;
var $sunday_val = "0";
var $saturday_val = "6";
function clsWorkDays( $p_type='UU' ) {
//
//Function : constructor to automaticaly set the list of holidays.
//Params
// : p_type this param can be used when adding other countrys holidays
// Returns
// : sets of holidays
//
// future dates may be found from the same place i looked
// http://www.dti.gov.uk/employment/bank-public-holidays/index.html
// or for previous try
// http://www.dti.gov.uk/employment/bank-public-holidays/bank-public-holidays/page18893.html
//
//
if ( $p_type=='US' ) {
$this->holidays[] = new Holiday("Nieuwjaarsdag", $this->get_timestamp("2008-01-01"));
$this->holidays[] = new Holiday("Martin Luther King dag", $this->get_timestamp("2008-01-21"));
$this->holidays[] = new Holiday("President dag", $this->get_timestamp("2008-02-18"));
$this->holidays[] = new Holiday("Memorial dag ", $this->get_timestamp("2008-05-26"));
$this->holidays[] = new Holiday("Independence dag", $this->get_timestamp("2008-07-04"));
$this->holidays[] = new Holiday("Labor dag", $this->get_timestamp("2008-09-01"));
$this->holidays[] = new Holiday("Dag van colombus", $this->get_timestamp("2008-10-13"));
$this->holidays[] = new Holiday("Veteranendag", $this->get_timestamp("2008-11-11"));
$this->holidays[] = new Holiday("Thanksgiving", $this->get_timestamp("2008-11-27"));
$this->holidays[] = new Holiday("Kerstmis", $this->get_timestamp("2008-12-25"));
}
//go fill array to enable fast searches
foreach ( $this->holidays as $holiday_date ) {
$this->holiday_dates[] = $holiday_date->date;
}
}
function days_diff($p_start_date, $p_end_date = NULL, $p_workdays_only = TRUE, $p_skip_holidays = TRUE){
//
//Function : Main function to calculate the number of days or work days between 2 dates. If no end date passed
// in then this can be used to identify if the day is a working day as the function will return 1 or 0
//Params
// : p_start_date This paramter is the range starting date
// : p_end_date This paramter is the range ending date (can be null)
// : p_workdays_only This paramter is set if you DO NOT want to count weekends
// : p_skip_holidays This paramter is set if you DO NOT want to count standard Bank Holidays & enforced business shutdowns
// Returns
// : number of days between the 2 dates or if no end date passed in then 1/0 if the start day is a work day
//
$end_date = $p_end_date;
if ( strlen($p_end_date)==0 ) $end_date = $p_start_date;
$end_date = strtotime($end_date);
$start_date = strtotime($p_start_date);
$nbr_work_days = 0;
for($day_val = $start_date; $day_val <= $end_date; $day_val += $this->seconds_per_day){
$pointer_day = date("w", $day_val);
if($p_workdays_only == true){
if(($pointer_day != $this->sunday_val) AND ($pointer_day != $this->saturday_val)){
if($p_skip_holidays == true){
if(!in_array($day_val, $this->holiday_dates)){
$nbr_work_days++;
}
}else{
$nbr_work_days++;
}
}
}else{
if($p_skip_holidays == true){
if(!in_array($day_val, $this->holiday_dates)){
$nbr_work_days++;
}
}else{
$nbr_work_days++;
}
}
}
return $nbr_work_days;
}
function get_timestamp($p_date){
//
//Function : internal function to convert a date from mySQL fmt to unix timestamp
//Params
// : p_date This paramter takes a date in the format yyyy-mm-dd
// Returns
// : a unix timestamp
//
$date_array = explode("-",$p_date); // split the array
$the_year = $date_array[0];
$the_month = $date_array[1];
$the_day = $date_array[2];
$the_timestamp = mktime(0,0,0,$the_month,$the_day,$the_year);
return($the_timestamp); // return it to the user
}
}
class Holiday{
//
//Class : Create and hold the list of bank holidays and enforced business shutdowns
//Params
// :
// Returns
// : array of holidays
//
public $name;
public $date;
//constructor to automaticaly define the details of each holiday as it is created.
function holiday($name, $date){
$this->name = $name; // Holiday title
$this->date = $date; // Timestamp of date
}
}
?><i>Kies de datum van cash out</i><br>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
Dag: <select name="day">
<option value="1">1</option>
<option value="2">2</option>
<option value="2">3</option>
<option value="2">4</option>
<option value="2">5</option>
<option value="2">6</option>
<option value="2">7</option>
<option value="2">8</option>
<option value="2">9</option>
<option value="2">10</option>
<option value="2">11</option>
<option value="2">12</option>
<option value="2">13</option>
<option value="2">14</option>
<option value="2">15</option>
<option value="2">16</option>
<option value="2">17</option>
<option value="2">18</option>
<option value="2">19</option>
<option value="2">20</option>
<option value="2">21</option>
<option value="2">22</option>
<option value="2">23</option>
<option value="2">24</option>
<option value="2">25</option>
<option value="2">26</option>
<option value="2">27</option>
<option value="2">28</option>
<option value="2">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select> Maand: <select name="month">
<option value="1">Januari</option>
<option value="2">Februari</option>
<option value="3">Maart</option>
<option value="4">April</option>
<option value="5">Mei</option>
<option value="6">Juni</option>
<option value="7">Juli</option>
<option value="8">Augustus</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select> Jaar: <select name="year">
<option value="08">2008</option>
<option value="09">2009</option>
<option value="10">2010</option>
<option value="11">2011</option>
</select> <br/>
<input type="hidden" name="go" value="1" /><input type="submit" name="Calculate" value="Bereken"/>
</form>
<p></p>
<?php
echo $_POST['Calculate'];
?>
al bedankt voor jullie hulp
yorick
7.213 views