|
|
Модератор форума: Dimitro, LightInDarkness |
Форум » Web раздел » Web форум » Помощь по коду |
Помощь по коду |
В общем есть код
Код <?php error_reporting(0); set_time_limit(5); header('Content-type: text/html; charset=utf-8'); include('config.php'); ?> <style> .statistic { color:#EEE; background:#333; font-size:14px; line-height:1.5; border:1px solid #111; font-family:"Lucida Grande", Arial, Helvetica, sans-serif; } .statistic img { border:none; } .statistic .header td { background:url(statistic_img/header-bg.gif); border-bottom:1px solid #333; font-weight: bold; padding:2px; height:35px; color:#CCC; } .statistic .row td { background:url(statistic_img/row-bg.gif); border-bottom:1px solid #333; font-weight:bold; padding:2px; height:35px; color:#CCC; position:relative; } .statistic .row2 { background:url(statistic_img/row2.png); padding:3px 6px 3px 6px; border-radius:3px; -moz-border-radius:3px; -webkit-border-radius:3px; color:#000; } .statistic .stuff { background:#333333; border:1px solid #000; color:#FFF; padding:5px; text-align:left; font-weight:normal; position:absolute; z-index:1000; min-width:160px; font-size:13px; } </style> <script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> <script type="text/javascript" language="javascript"> var UPDATE_TIMESEC = <?php echo intval($auto_update_sec); ?>; function ChangeOnline(online) { if(typeof(online) != "number" || isNaN(online)) online = 0; var o = $('.statistic #online').html()*1; if(isNaN(o)) o = 0; $('.statistic #online').html(o+online); } var uptimes = new Array; function SetUptime(uptime,id) { var up = uptime; var sec = uptime%60; uptime = Math.ceil(uptime/60); var min = uptime%60; uptime = Math.ceil(uptime/60); var hour = uptime%24; uptime = Math.ceil(uptime/24); hour += uptime*24; var s_sec = sec, s_min = min, s_hour = hour; if(sec < 10) s_sec = "0"+sec; if(min < 10) s_min = "0"+min; if(hour < 10) s_hour = "0"+hour; $('#uptime-'+id).html(s_hour+':'+s_min+':'+s_sec); if(typeof(uptimes[id]) != "undefined") clearInterval(uptimes[id]); uptimes[id] = setInterval(function(){ sec++; if(sec >= 60) { min++; sec = 0; } if(min >= 60) { hour++; min = 0; } var s_sec = sec, s_min = min, s_hour = hour; if(sec < 10) s_sec = "0"+sec; if(min < 10) s_min = "0"+min; if(hour < 10) s_hour = "0"+hour; $('#uptime-'+id).html(s_hour+':'+s_min+':'+s_sec); },1000); } function GeneralUpdate(num) { var num_s = 0; for(var i = 0; i < num; i++) { $.ajax({ type: "get", url: "script.php", data: "id="+i, cache: false, dataType: "json", timeout: 2000, success: function(data) { if(data[0] == false) html += '<td colspan="10">'+data[1]+'</td>'; else { var html = '<td>'+data[1].type+'</td>'; html += '<td><span class="row2">'+data[1].name+'</span></td>'; html += '<td>'+data[1].version+'</td>'; html += '<td><span class="row2">'+data[1].rates+'</span></td>'; html += '<td><img src="statistic_img/server-status-'+data[1].status+'.png" alt="status"></td>'; html += '<td><font id="alliance" style="color:blue">'+data[1].alliance+'</font> / <font id="horde" style="color:red">'+data[1].horde+'</font></td>'; html += '<td id="online-'+num_s+'">'+data[1].online+'</td>'; html += '<td>'+data[1].maxplayers+'</td>'; html += '<td>'+data[1].stuff.length+' <a href="javascript:;" onmouseover="$(\'#stuff-'+num_s+'\').show();" onmouseout="$(\'#stuff-'+num_s+'\').hide();"><img src="statistic_img/void(0).png" alt="stuff"></a><br><div class="stuff" style="display:none" id="stuff-'+num_s+'">'; if(data[1].stuff.length == 0) html += 'Администрации в сети нет'; else { for(var i2 = 0; i2 < data[1].stuff.length; i2++) { html += data[1].stuff[i2].name+' ('+data[1].stuff[i2].str+')<br>'; } } html += '</div></td>'; html += '<td id="uptime-'+num_s+'">00:00:00</td>'; ChangeOnline($('#online-'+num_s).html()*-1); ChangeOnline(data[1].online); } $('#server-'+num_s).html(html); if(data[0] != false) SetUptime(data[1].uptime,num_s); num_s++; }, }); } } $(document).ready(function(){ var num = <?php echo sizeof($realm_config); ?>; var num_s = 0; for(var i = 0; i < num; i++) { $.ajax({ type: "get", url: "script.php", data: "id="+i, cache: false, dataType: "json", timeout: 2000, success: function(data) { var html = '<tr align="center" class="row" id="server-'+num_s+'" data="stat">'; if(data[0] == false) html += '<td colspan="10">'+data[1]+'</td>'; else { html += '<td>'+data[1].type+'</td>'; html += '<td><span class="row2">'+data[1].name+'</span></td>'; html += '<td>'+data[1].version+'</td>'; html += '<td><span class="row2">'+data[1].rates+'</span></td>'; html += '<td><img src="statistic_img/server-status-'+data[1].status+'.png" alt="status"></td>'; html += '<td><font id="alliance" style="color:blue">'+data[1].alliance+'</font> / <font id="horde" style="color:red">'+data[1].horde+'</font></td>'; html += '<td id="online-'+num_s+'">'+data[1].online+'</td>'; html += '<td>'+data[1].maxplayers+'</td>'; html += '<td>'+data[1].stuff.length+' <a href="javascript:;" onmouseover="$(\'#stuff-'+num_s+'\').show();" onmouseout="$(\'#stuff-'+num_s+'\').hide();"><img src="statistic_img/void(0).png" alt="stuff"></a><br><div class="stuff" style="display:none" id="stuff-'+num_s+'">'; if(data[1].stuff.length == 0) html += 'Администрации в сети нет'; else { for(var i2 = 0; i2 < data[1].stuff.length; i2++) { html += data[1].stuff[i2].name+' ('+data[1].stuff[i2].str+')<br>'; } } html += '</div></td>'; html += '<td id="uptime-'+num_s+'">00:00:00</td>'; ChangeOnline(data[1].online); } html += '</tr>'; $('#statistic').append(html); if(data[0] != false) SetUptime(data[1].uptime,num_s); num_s++; }, }); } if(UPDATE_TIMESEC != 0) setInterval(function(){GeneralUpdate(num);},UPDATE_TIMESEC*1000); }); </script> <table width="800" border="0" cellpadding="0" cellspacing="0" class="statistic" id="statistic"> <tr align="center" class="header"> <td width="5%">Тип</td> <td width="10%">Сервер</td> <td width="10%">Версия</td> <td width="9%">Рейты</td> <td width="9%">Состояние</td> <td width="11%">A / O</td> <td width="9%">Всего</td> <td width="7%">Max</td> <td width="18%">Администрация</td> <td width="9%">Аптайм</td> </tr> </table> <table width="800" border="0" cellpadding="0" cellspacing="0" class="statistic" style="background:#111"><tr><td align="right"><div style="padding-right:100px"><b>Всего:</b> <span id="online">0</span></div></td></tr></table> В самом файле script.php стандартный запрос аптайма, в javascript ничего не соображаю. Проблема в том что аптайм считается не понятно как, сразу после перезапуска некоторое время показывает что то вроде 0-1:4-1:3-5, потом примерно на 24 часа больше, кто то может помочь? |
| |||
| |||