|
| 1 | +<?php |
| 2 | +/** |
| 3 | +* LoadAvg - Server Monitoring & Analytics |
| 4 | +* http://www.loadavg.com |
| 5 | +* |
| 6 | +* Subheader - used to add date selector to pages |
| 7 | +* |
| 8 | +* @link https://github.com/loadavg/loadavg |
| 9 | +* @author Karsten Becker |
| 10 | +* @copyright 2014 Sputnik7 |
| 11 | +* |
| 12 | +* This file is licensed under the Affero General Public License version 3 or |
| 13 | +* later. |
| 14 | +*/ |
| 15 | +?> |
| 16 | + |
| 17 | + |
| 18 | +<script type="text/javascript"> |
| 19 | + //used to display browser time |
| 20 | + |
| 21 | + //get the offset for the client timezone |
| 22 | + var currentTime = new Date(); |
| 23 | + |
| 24 | + //why doest this pull getItemTime from common.js ? |
| 25 | + //var browserTime = getItemTime(currentTime); |
| 26 | + |
| 27 | + var hours = currentTime.getHours(); |
| 28 | + var minutes = currentTime.getMinutes(); |
| 29 | + var ampm = ""; |
| 30 | + |
| 31 | + if (minutes < 10) |
| 32 | + minutes = "0" + minutes; |
| 33 | + |
| 34 | + if(hours > 12) { hours = hours - 12; ampm = "pm"; } |
| 35 | + else ampm = "am"; |
| 36 | + |
| 37 | + var browserTime = hours + ":" + minutes + " " + ampm; |
| 38 | + |
| 39 | + //get the timezone offset |
| 40 | + var tz_offset = currentTime.getTimezoneOffset()/60; |
| 41 | + |
| 42 | +</script> |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +<table class="well lh70 lh70-style" width="100%" border="0" cellspacing="1" cellpadding="3"> |
| 47 | + <tr> |
| 48 | + <td width="30%"> |
| 49 | + |
| 50 | + <?php |
| 51 | + |
| 52 | + echo '<strong>Server</strong> ' . LoadAvg::$_settings->general['settings']['title'] . "<br>"; |
| 53 | + |
| 54 | + //figure out the time first |
| 55 | + $chartTimezoneMode = LoadAvg::$_settings->general['settings']['timezonemode']; |
| 56 | + |
| 57 | + if ($chartTimezoneMode == "UTC") { |
| 58 | + $gmtimenow = time() - (int)substr(date('O'),0,3)*60*60; |
| 59 | + $theTime = date("h:i a", $gmtimenow) . " UTC"; |
| 60 | + } |
| 61 | + else if ($chartTimezoneMode == "Browser" || $chartTimezoneMode == "Override" ) { |
| 62 | + $theTime = '<script type="text/javascript">document.write(browserTime);</script>'; |
| 63 | + } |
| 64 | + |
| 65 | + |
| 66 | + //Now let them know what data they are seeing |
| 67 | + |
| 68 | + if ( ( isset($_GET['minDate']) && !empty($_GET['minDate']) ) && |
| 69 | + ( isset($_GET['maxDate']) && !empty($_GET['maxDate']) ) ) |
| 70 | + { |
| 71 | + echo '<strong>Viewing</strong> ' . date("l, M. j", strtotime($_GET['minDate'])); |
| 72 | + echo ' <strong>to</strong> ' . date("M. j", strtotime($_GET['maxDate'])); |
| 73 | + } |
| 74 | + else if ( (isset($_GET['logdate'])) && !empty($_GET['logdate']) ) |
| 75 | + { |
| 76 | + echo '<strong>Viewing </strong> ' . date("l, M. j", strtotime($_GET['logdate'])); |
| 77 | + //echo date("l, M. j", strtotime($_GET['logdate'])); |
| 78 | + } |
| 79 | + else |
| 80 | + { |
| 81 | + //echo '<strong>Viewing </strong>' . date("l, M. j "); |
| 82 | + echo date("l, M. j ") . " | " . $theTime; |
| 83 | + } |
| 84 | + |
| 85 | + ?> |
| 86 | + |
| 87 | + </td> |
| 88 | + |
| 89 | + <td width="70%" align="right"> |
| 90 | + |
| 91 | + <script type="text/javascript"> |
| 92 | + // a dirty hack for our form/drop down menu as we need to hack the url for plugins |
| 93 | + //as plugins have a ? in the url and a form submit overwrites the ? with the base url |
| 94 | + function myfunction() { |
| 95 | + |
| 96 | + //first we get the url |
| 97 | + //var url = window.location.href; |
| 98 | + var url = document.URL; |
| 99 | + var lastPart = url.substr(url.lastIndexOf('/') + 1); |
| 100 | + |
| 101 | + |
| 102 | + //this means that page is in the url so we are on a page |
| 103 | + //if we are on a page we need to add the plugin name back to the url here |
| 104 | + if ( lastPart.indexOf("page=") > -1 ) { |
| 105 | + |
| 106 | + console.log('Page is in url!'); |
| 107 | + |
| 108 | + //get the modules |
| 109 | + var loadModules = []; |
| 110 | + loadModules = <?php print(json_encode(LoadPlugins::$_plugins)); ?>; |
| 111 | + console.log('loadModules', loadModules); |
| 112 | + |
| 113 | + |
| 114 | + for ( key in loadModules) { |
| 115 | + |
| 116 | + if ( lastPart.indexOf(key) > -1 ) { |
| 117 | + |
| 118 | + //we need to insert page if we are on a plugin here!!! |
| 119 | + var myin = document.createElement("input"); |
| 120 | + myin.type='hidden'; |
| 121 | + myin.name='page'; |
| 122 | + myin.value=key; |
| 123 | + |
| 124 | + //this would append at the end... |
| 125 | + //document.getElementById('form_id').appendChild(myin); |
| 126 | + //we insert at begining for eg index.php?page=alerts... |
| 127 | + document.getElementById('form_id').insertBefore(myin,document.getElementById('form_id').firstChild); |
| 128 | + break; |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + //alert(url); |
| 134 | + |
| 135 | + document.getElementById("form_id").action = "index.php"; // Setting form action to "success.php" page |
| 136 | + document.getElementById("form_id").submit(); // Submitting form |
| 137 | + |
| 138 | + } |
| 139 | + </script> |
| 140 | + |
| 141 | + <form id = "form_id" onsubmit="this.action=get_action();" method="get" class="margin-none form-horizontal"> |
| 142 | + |
| 143 | + <!-- Periods --> |
| 144 | + <div class="control-group margin-none"> |
| 145 | + |
| 146 | + <?php |
| 147 | + if ( isset($showCalendar) && ($showCalendar==true) ) |
| 148 | + { |
| 149 | + ?> |
| 150 | + |
| 151 | + <label class="control-label"><b>Period:</b></label> |
| 152 | + <div class="controls"> |
| 153 | + |
| 154 | + <input type="hidden" id="minDateValue" value="<?php echo date("Y-m-d", strtotime("-". LoadAvg::$_settings->general['settings']['daystokeep'] ." days 00:00:00")); ?>"> |
| 155 | + <input type="hidden" id="maxDateValue" value="<?php echo date("Y-m-d"); ?>"> |
| 156 | + |
| 157 | + <input type="text" id="minDate" name="minDate" value="<?php echo (isset($_GET['minDate']) && !empty($_GET['minDate'])) ? $_GET['minDate'] : ''; ?>" placeholder="Period from" style="width: 70px;height: 18px;"> |
| 158 | + - |
| 159 | + <input type="text" id="maxDate" name="maxDate" value="<?php echo (isset($_GET['minDate']) && !empty($_GET['maxDate'])) ? $_GET['maxDate'] : ''; ?>" placeholder="Period to" style="width: 70px;height: 18px;"> |
| 160 | + <?php |
| 161 | + } |
| 162 | + ?> |
| 163 | + |
| 164 | + <b class="innerL">Log file:</b> |
| 165 | + <select name="logdate" id="logdate" style="width: 110px;height: 28px;"> |
| 166 | + <?php |
| 167 | + |
| 168 | + $dates = LoadAvg::getDates(); |
| 169 | + |
| 170 | + $date_counter = 1; |
| 171 | + |
| 172 | + $totalDates = (int)count($dates); |
| 173 | + |
| 174 | + foreach ( $dates as $date ) { |
| 175 | + |
| 176 | + if ( ($date_counter != $totalDates) ) |
| 177 | + |
| 178 | + { |
| 179 | + ?><option<?php echo ((isset($_GET['logdate']) && !empty($_GET['logdate']) && $_GET['logdate'] == $date) || (!isset($_GET['logdate']) && $date == date('Y-m-d'))) ? ' selected="selected"' : ''; ?> value="<?php echo $date; ?>"><?php echo $date; ?></option><?php |
| 180 | + } |
| 181 | + else |
| 182 | + { |
| 183 | + //last date is todays date add for easy access |
| 184 | + ?><option<?php echo ((isset($_GET['logdate']) && !empty($_GET['logdate']) && $_GET['logdate'] == $date) || (!isset($_GET['logdate']) && $date == date('Y-m-d'))) ? ' selected="selected"' : ''; ?> value="<?php echo $date; ?>"><?php echo 'Today'; ?></option><?php |
| 185 | + } |
| 186 | + |
| 187 | + $date_counter++; |
| 188 | + } |
| 189 | + |
| 190 | + ?> |
| 191 | + |
| 192 | + <input type="hidden" id="page" value="Alert"> |
| 193 | + |
| 194 | + </select> |
| 195 | + <input onclick="myfunction()" type="button" value="View" class="btn btn-primary" /> |
| 196 | + </div> |
| 197 | + </div> |
| 198 | + <!-- End of Periods --> |
| 199 | + </form> |
| 200 | + |
| 201 | + </td> |
| 202 | + |
| 203 | + </tr> |
| 204 | +</table> |
| 205 | + |
| 206 | + |
0 commit comments