Viewing File server/base/schedule.inc.php of 1.17.7a
|
1: <?php // schedule.inc.php 2: /* ------------------------------------------------------------- 3: This file is part of FreeNATS 4: 5: FreeNATS is (C) Copyright 2008 PurplePixie Systems 6: 7: FreeNATS is free software: you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation, either version 3 of the License, or 10: (at your option) any later version. 11: 12: FreeNATS is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with FreeNATS. If not, see www.gnu.org/licenses 19: 20: For more information see www.purplepixie.org/freenats 21: -------------------------------------------------------------- */ 22: 23: // Determines Schedule Information for node 24: 25: // Period Array Format: 26: // 'dayofweek' - Mon/Tue or BLANK 27: // 'dayofmonth' - 1-31 or 0 28: // 'monthofyear' - 1-12 or 0 29: // 'year' - XXXX or 0 30: // 'starthour' - 0 to 23 31: // 'finishhour' - 0 to 23 32: // 'startmin' - 0 to 59 33: // 'finishmin' - 0 to 59 34: 35: function is_x_in_period($timex,$period) 36: { 37: $year=date("Y",$timex); 38: $month=date("m",$timex); 39: $day=date("d",$timex); 40: $hour=date("H",$timex); 41: $min=date("i",$timex); 42: $dayofweek=date("D",$timex); 43: 44: // check each non-period piece of info 45: if ($period['dayofweek']!="") 46: if ($period['dayofweek'] != $dayofweek) return false; 47: 48: if ($period['monthofyear']>0) 49: if ($period['monthofyear'] != $month) return false; 50: 51: if ($period['year']>0) 52: if ($period['year'] != $year) return false; 53: 54: if ($period['dayofmonth']>0) 55: if ($period['dayofmonth'] != $day) return false; 56: 57: // check against start/finish times 58: 59: if ($period['starthour'] > $hour) return false; // not yet the hour 60: if ( ($period['starthour']==$hour)&&($period['startmin']>$min) ) return false; // hour but not yet the minute 61: 62: if ($period['finishhour'] < $hour) return false; // past the finish hour 63: if ( ($period['finishhour']==$hour)&&($period['finishmin']<$min) ) return false; // finish hour equal but mins past 64: 65: // all non-range either match or universal - after or equal to start and equal or before finish so... 66: return true; 67: } 68: 69: function run_x_in_schedule($timex,$scheduleid) // note this is not is_x_in_schedule as we want to take into account default action! 70: { 71: global $NATS; 72: if ($scheduleid==0) return true; // always run schedule 73: if ($scheduleid<0) return false; // never run schedule 74: $q="SELECT defaultaction FROM fnschedule WHERE scheduleid=".ss($scheduleid)." LIMIT 0,1"; 75: $r=$NATS->DB->Query($q); 76: if ($NATS->DB->Num_Rows($r)<=0) return true; // illegal schedule id so YES run 77: $srow=$NATS->DB->Fetch_Array($r); 78: if ($srow['defaultaction']==0) $default=false; 79: else $default=true; 80: $NATS->DB->Free($r); 81: 82: $q="SELECT * FROM fnscheditem WHERE scheduleid=".ss($scheduleid); 83: $match=false; 84: 85: $r=$NATS->DB->Query($q); 86: while ( ($row=$NATS->DB->Fetch_Array($r))&&(!$match) ) 87: { 88: $match=is_x_in_period($timex,$row); 89: } 90: $NATS->DB->Free($r); 91: 92: if ($match) // found in the schedule list so do the reverse of default 93: { 94: if ($default) return false; 95: else return true; 96: } 97: else // not found in schedule 98: return $default; // so use the default 99: } 100: 101: ?>