"; echo ""; echo "[".htmlspecialchars($msg)."]"; echo ""; echo "
"; break; } } if(isset($ZBX_MESSAGES)) { if($page["type"] == PAGE_TYPE_IMAGE) { foreach($ZBX_MESSAGES as $msg) { if($msg['type'] == 'error') { array_push($message, array( 'text' => $msg['message'], 'color' => array('R'=>255,'G'=>55,'B'=>55), 'font' => 2)); } else { array_push($message, array( 'text' => $msg['message'], 'color' => array('R'=>155,'G'=>155,'B'=>55), 'font' => 2)); } $width = max($width, ImageFontWidth(2) * strlen($msg['message']) + 1); $height += imagefontheight(2) + 1; } } elseif($page["type"] == PAGE_TYPE_XML) { foreach($ZBX_MESSAGES as $msg) { echo '['.$msg['type'].'] '.$msg['message']."\n"; } } else { $lst_error = new CList(null,'messages'); foreach($ZBX_MESSAGES as $msg) $lst_error->AddItem($msg['message'], $msg['type']); $lst_error->Show(false); unset($lst_error); } $ZBX_MESSAGES = null; } if($page["type"] == PAGE_TYPE_IMAGE && count($message) > 0) { $width += 2; $height += 2; $canvas = imagecreate($width, $height); ImageFilledRectangle($canvas,0,0,$width,$height, ImageColorAllocate($canvas, 255, 255, 255)); foreach($message as $id => $msg) { $message[$id]['y'] = 1 + (isset($previd) ? $message[$previd]['y'] + $message[$previd]['h'] : 0 ); $message[$id]['h'] = imagefontheight($msg['font']); ImageString( $canvas, $msg['font'], 1, $message[$id]['y'], $msg['text'], ImageColorAllocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']) ); $previd = $id; } ImageOut($canvas); ImageDestroy($canvas); } } function show_message($msg) { show_messages(TRUE,$msg,''); } function show_error_message($msg) { show_messages(FALSE,'',$msg); } function parse_period($str) { $out = NULL; $str = trim($str,';'); $periods = split(';',$str); foreach($periods as $preiod) { if(!ereg('^([1-7])-([1-7]),([0-9]{1,2}):([0-9]{1,2})-([0-9]{1,2}):([0-9]{1,2})$', $preiod, $arr)) return NULL; for($i = $arr[1]; $i <= $arr[2]; $i++) { if(!isset($out[$i])) $out[$i] = array(); array_push($out[$i], array( 'start_h' => $arr[3], 'start_m' => $arr[4], 'end_h' => $arr[5], 'end_m' => $arr[6] )); } } return $out; } function find_period_start($periods,$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']; if($per_start > $curr) { if(($next_h == -1 && $next_m == -1) || ($per_start < ($next_h*100 + $next_m))) { $next_h = $period['start_h']; $next_m = $period['start_m']; } continue; } $per_end = $period['end_h']*100+$period['end_m']; if($per_end <= $curr) continue; return $time; } if($next_h >= 0 && $next_m >= 0) { return mktime($next_h, $next_m, 0, $date['mon'], $date['mday'], $date['year']); } } for($days=1; $days < 7 ; ++$days) { $new_wday = (($wday + $days - 1)%7 + 1); if(isset($periods[$new_wday ])) { $next_h = -1; $next_m = -1; foreach($periods[$new_wday] as $period) { $per_start = $period['start_h']*100+$period['start_m']; if(($next_h == -1 && $next_m == -1) || ($per_start < ($next_h*100 + $next_m))) { $next_h = $period['start_h']; $next_m = $period['start_m']; } } if($next_h >= 0 && $next_m >= 0) { return mktime($next_h, $next_m, 0, $date['mon'], $date['mday'] + $days, $date['year']); } } } return -1; } function find_period_end($periods,$time,$max_time) { $date = getdate($time); $wday = $date['wday'] == 0 ? 7 : $date['wday']; $curr = $date['hours']*100+$date['minutes']; //SDI("find_end: ".date('r',$time)); 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; } function validate_period(&$str) { $str = trim($str,';'); $out = ""; $periods = split(';',$str); foreach($periods as $preiod) { // arr[idx] 1 2 3 4 5 6 if(!ereg('^([1-7])-([1-7]),([0-9]{1,2}):([0-9]{1,2})-([0-9]{1,2}):([0-9]{1,2})$', $preiod, $arr)) return -1; if($arr[1] > $arr[2]) // check week day return -1; if($arr[3] > 23 || $arr[3] < 0 || $arr[5] > 24 || $arr[5] < 0) // check hour return -1; if($arr[4] > 59 || $arr[4] < 0 || $arr[6] > 59 || $arr[6] < 0) // check min return -1; if(($arr[5]*100 + $arr[6]) > 2400) // check max time 24:00 return -1; if(($arr[3] * 100 + $arr[4]) >= ($arr[5] * 100 + $arr[6])) // check time period return -1; $out .= sprintf("%d-%d,%02d:%02d-%02d:%02d",$arr[1],$arr[2],$arr[3],$arr[4],$arr[5],$arr[6]).';'; } $str = $out; //parse_period($str); return 0; } function validate_float($str) { // echo "Validating float:$str| "; echo ""; echo " | "; echo "