protected function drawWorkPeriod() { imagefilledrectangle($this->im, $this->shiftXleft + 1, $this->shiftY, $this->sizeX + $this->shiftXleft - 2, $this->sizeY + $this->shiftY, $this->getColor($this->graphtheme['graphcolor'], 0)); if ($this->m_showWorkPeriod != 1) { return; } if ($this->period > 3 * 2678400) { return; } // > 31*24*3600 (3*month) $db_work_period = DBselect('SELECT work_period FROM config'); $work_period = DBfetch($db_work_period); if (!$work_period) { return; } $periods = parse_period($work_period['work_period']); if (!$periods) { return; } imagefilledrectangle($this->im, $this->shiftXleft + 1, $this->shiftY, $this->sizeX + $this->shiftXleft - 2, $this->sizeY + $this->shiftY, $this->getColor($this->graphtheme['noneworktimecolor'], 0)); $now = time(); if (isset($this->stime)) { $this->from_time = $this->stime; $this->to_time = $this->stime + $this->period; } else { $this->to_time = $now - 3600 * $this->from; $this->from_time = $this->to_time - $this->period; } $from = $this->from_time; $max_time = $this->to_time; $start = find_period_start($periods, $from); $end = -1; while ($start < $max_time && $start > 0) { $end = find_period_end($periods, $start, $max_time); $x1 = round(($start - $from) * $this->sizeX / $this->period) + $this->shiftXleft; $x2 = ceil(($end - $from) * $this->sizeX / $this->period) + $this->shiftXleft; //draw rectangle imagefilledrectangle($this->im, $x1, $this->shiftY, $x2 - 2, $this->sizeY + $this->shiftY, $this->getColor($this->graphtheme['graphcolor'], 0)); $start = find_period_start($periods, $end); } }
function find_period_end($periods, $time, $max_time) { $date = getdate($time); $wday = $date['wday'] == 0 ? 7 : $date['wday']; $curr = $date['hours'] * 100 + $date['minutes']; if (isset($periods[$wday])) { $next_h = -1; $next_m = -1; foreach ($periods[$wday] as $period) { $per_start = $period['start_h'] * 100 + $period['start_m']; $per_end = $period['end_h'] * 100 + $period['end_m']; if ($per_start > $curr) { continue; } if ($per_end < $curr) { continue; } if ($next_h == -1 && $next_m == -1 || $per_end > $next_h * 100 + $next_m) { $next_h = $period['end_h']; $next_m = $period['end_m']; } } if ($next_h >= 0 && $next_m >= 0) { $new_time = mktime($next_h, $next_m, 0, $date['mon'], $date['mday'], $date['year']); if ($new_time == $time) { return $time; } if ($new_time > $max_time) { return $max_time; } $next_time = find_period_end($periods, $new_time, $max_time); if ($next_time < 0) { return $new_time; } else { return $next_time; } } } return -1; }