bigguy333
Newbie
Karma: 0
Posts: 1
|
 |
« on: February 13, 2012, 01:19:18 PM » |
|
Where did the topic on this go?
I am no PHP Coder, so this code will be messy and someone else could probably make it 100x better.
Starting again... I would like to see a way to make is so you could automatically move a repeated schedule around a blackout. for instance, all Sundays and Saturdays are blacked out, and I would like to book every 6th day. also I'll throw a holiday in the mix. here is an example:
Feb 13(monday) - Booked Feb 21(tuesday) - holiday (would normally be booked here because it's 6 work days after feb 13 but it's a holiday) Feb 22(wednesday) - Booked.
I do have a solution for version 1 of PHPSchedule it, but I have no idea how to put it into 2.0
here is my modification code (updated Feb 14th, fixed errors in code):
in reserve.php starting on line 176 I put:
list($last_m, $last_d, $last_y) = explode('/', $_POST['repeat_until']); //send lastdate to add_res $lastdate = mktime(0,0,0,$last_m, $last_d, $last_y); //send lastdate to add_res $res->add_res($users_to_invite, $resources_to_add, $lastdate, $_POST['scheduleid']); //send lastdate and scheduleid to add_res
in ResDB.class.php on line 66 I inserted:
// Check where the blackout dates are (except the weekends). function check_blackout($schedid) { $j = 0; $tmp = array(); $values = array(1,$schedid); $query = 'SELECT * FROM ' . $this->get_table(TBL_RESERVATIONS) . ' WHERE is_blackout=?' . ' AND scheduleid=?'; $result = $this->db->query($query, $values); // Check if error $this->check_for_error($result); while ($rs = $result->fetchRow()) { if (date('D',$rs['start_date']) != "Sat" || date('D',$rs['start_date']) != "Sun"){ $tmp[$j] = $rs['start_date']; $j++; } } return ($tmp); }
and in Reservation.class.php I changed line 178 to: function add_res($users_to_invite = array(), $resources_to_add = array(), $lastdate, $schedid)
and added on line 190:
$tmp123 = array(); $j1 = count($repeat); $x1 = 0;
$tmp123 = $this->db->check_blackout($schedid); for ($j = 0; $j < $j1; $j++) { // Jump the weekend if this week is the week after the last. if(date('W',$repeat[$j] + 86400) != date('W',$repeat[$j - 1]) AND $x1 != $j or date('D', $repeat[$j]) == "Sun" or date('D', $repeat[$j]) == "Sat") { for ($i = $j; $i < count($repeat); $i++){ if ($repeat[0] + 86400 == $repeat[1] and date('D', $repeat[$i]) == "Sun"){ // if repeat schedule is everyday don't jump 2 days $repeat[$i] = $repeat[$i] + 86400; }else{ $repeat[$i] = $repeat[$i] + 172800; } } $x1 = $j; $j = $j - 1; } do { $x = 0; // Move schedule around blackout days. $i3 = count($tmp123); for ($i = 0; $i < count($tmp123); $i++) { for ($i2 = $repeat[$j - 1]; $i2 < $repeat[$j] + 86400; $i2 = $i2 + 86400){ if ($i2 == $tmp123[$i]) { for ($i1 = $j; $i1 < count($repeat); $i1++){ $repeat[$i1] = $repeat[$i1] + 86400; } unset($tmp123[$i]); $tmp123 = array_values($tmp123); $i2 = $i2 - 86400; $j = $j - 1; } } } }while($x > 0); // Remove any dates that end up going past lastdate. if ($repeat[$j] > $lastdate and count($repeat) > 1){ unset($repeat[$j]); $repeat = array_values($repeat); $j = $j - 1; } }
|