| <?php | |
| require_once($_SERVER['DOCUMENT_ROOT'] ."/eclipse.org-common/system/app.class.php"); | |
| require_once("/home/data/httpd/eclipse-php-classes/menu/menu.class.php"); | |
| #***************************************************************************** | |
| # | |
| # loadstats.php | |
| # | |
| # Author: M. Ward | |
| # Date: 2006-05-08 | |
| # | |
| # Description: show the load stats for the last month on the given server. | |
| # | |
| # | |
| # | |
| # | |
| # HISTORY: | |
| # | |
| #**************************************************************************** | |
| //set the default debug level nice and low | |
| define('DEBUG',0); | |
| //define('BASEPATH','/tmp/') | |
| $App = new App(); | |
| $App->preventCaching(); | |
| $Session = $App->useSession('required'); | |
| $Friend = $Session->getFriend(); | |
| if (!$Friend->getIsCommitter()){ | |
| header("HTTP/1.1 403 Forbidden"); | |
| exit; | |
| } | |
| include "../html/header.php"; | |
| //do menu stuff | |
| $Menu = new Menu("en"); | |
| $Menu->addMenuItem("Main stats page", "dailyloadstats.php", "_self"); | |
| include("../modules/menu.php"); | |
| //build a calendar | |
| //get the passed values, if they haven't been passed, then use the current values | |
| //start with the month | |
| if( isset($_REQUEST['day']) && $_REQUEST['day'] != '' && is_numeric($_REQUEST['day']) && $_REQUEST['day'] >= 0 && $_REQUEST['day'] <= 31 ){ | |
| if( $_REQUEST['day'] < 10 ) | |
| $today = "0" . $_REQUEST['day']; | |
| else | |
| $today = $_REQUEST['day']; | |
| }else{ //if whatever the passed failed the above get the current day so that we can open the files. | |
| $today = date ( 'd' ); | |
| } | |
| //check to see if someone passed in a request for a specific month | |
| if( isset($_REQUEST['month']) && $_REQUEST['month'] != '' && is_numeric($_REQUEST['month']) && $_REQUEST['month'] >= 0 && $_REQUEST['month'] <= 12 ){ | |
| $month = $_REQUEST['month']; | |
| }else{ //if whatever the passed failed the above get the current month so that we can open the files. | |
| $month = date ('n'); | |
| } | |
| //check to see if someone passed in a request for a specific year | |
| if( isset($_REQUEST['year']) && $_REQUEST['year'] != '' && is_numeric($_REQUEST['year']) && $_REQUEST['year'] >= 2007 && $_REQUEST['year'] <= 3000 ){ | |
| $year = $_REQUEST['year']; | |
| }else{ //if whatever the passed failed the above get the current year so that we can open the files. | |
| $year = date ('Y'); | |
| } | |
| //pre set the previous and next month and make sure they wrap around. | |
| $prevyear = $nextyear = $year; | |
| $prevmonth = $month-1; | |
| if ( $prevmonth <= 0 ) { | |
| $prevmonth = 12; | |
| $prevyear -= 1; | |
| } | |
| $nextmonth = $month+1; | |
| if ( $nextmonth > 12){ | |
| $nextmonth = 1; | |
| $nextyear += 1; | |
| } | |
| //get the Current month 3 letter short form | |
| $month_name = date( 'M', mktime( 0,0,0,$month,1,$year)); | |
| //get the servername | |
| $server= $_REQUEST['server']; | |
| //use showmonth to adjust the image | |
| if( isset($_REQUEST['showmonth']) && is_numeric($_REQUEST['showmonth']) && $_REQUEST['showmonth'] >= 1 ){ | |
| $html = "<img src='drawmonthstats.php?server=$server&month=$month&year=$year'></br></br></br>"; | |
| } else { | |
| $html = "<img src='drawstats.php?server=$server&year=$year&month=$month&day=$today'></br></br></br>"; | |
| } | |
| //now build the calendar(borrowed from a tutorial at zend.net) | |
| $daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa'); | |
| $firstday = mktime(0,0,0,$month,1,$year); | |
| $numberofdays = date('t',$firstday); | |
| $dateComponents = getdate($firstday); | |
| $dayOfWeek = $dateComponents['wday']; | |
| //$calendar = "<table align=center><caption> $month_name, $year</caption><tr>\n\r"; | |
| $calendar = "<table align=center><td><a href=\"showmonthstats.php?server=$server&year=$prevyear&month=$prevmonth&showmonth=1\">Prev</href></td><td colspan=5 align=center><a href=\"showmonthstats.php?server=$server&month=$month&showmonth=1\">$month_name, $year</a></td><td><a href=\"showmonthstats.php?server=$server&year=$nextyear&month=$nextmonth&showmonth=1\">Next</href></td><tr>\n\r"; | |
| foreach($daysOfWeek as $day) { | |
| $calendar .= "<th>$day</th>\n\r"; | |
| } | |
| $currentDay = 1; | |
| $calendar .= "</tr><tr>\n\r"; | |
| if ($dayOfWeek > 0) { | |
| $calendar .= "<td colspan='$dayOfWeek'> </td>\n\r"; | |
| } | |
| while ($currentDay <= $numberofdays) { | |
| if ($dayOfWeek == 7) { | |
| $dayOfWeek = 0; | |
| $calendar .= "</tr><tr>"; | |
| } | |
| $day_code = date( 'd', mktime( 0,0,0,$month,$currentDay,$year)); | |
| if( is_file($server ."/" .$year . "/" . $month_name . "/loadavgfor." . $day_code) == true) { | |
| $calendar .= "<td><a href=\"showmonthstats.php?server=$server&year=$year&month=$month&day=$currentDay\">$currentDay</a></td>\n\r"; | |
| } else { | |
| $calendar .= "<td>$currentDay</td>\n\r"; | |
| } | |
| $currentDay++; | |
| $dayOfWeek++; | |
| } | |
| if ($dayOfWeek != 7) { | |
| $remainingDays = 7 - $dayOfWeek; | |
| $calendar .= "<td colspan='$remainingDays'> </td>\n\r"; | |
| } | |
| $calendar .= "<tr><td colspan=7><a href=\"showyearlystats.php?server=$server\">Yearly Summaries</a></td></tr>\n\r"; | |
| $calendar .= "</table>\n\r"; | |
| echo $html; | |
| echo $calendar; | |
| $html = "</br></br><img src='drawyearstats.php?server=$server&year=$year'></br></br></br>"; | |
| echo $html; | |
| include "../html/footer.php"; |