<?PHP
/* Copyright 2012, Bergware International & Speeding Ant.
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 */
 
  $sleep_cmd='';
  if ( isset($sf_ini['sleep']) && $sf_ini['sleep']['s3'] == 1 ) {
    $sleep_cmd = $sf_ini['sleep']['script']
                .( !empty($sf_ini['sleep']['forceGb'])    ? " "   .$sf_ini['sleep']['forceGb']   : "" )
                .( !empty($sf_ini['sleep']['dhcpRenew'])  ? " "   .$sf_ini['sleep']['dhcpRenew'] : "" )
                .( !empty($sf_ini['sleep']['setWol'])     ? " -w ".$sf_ini['sleep']['setWol']    : "" )
                .( !empty($sf_ini['sleep']['preRun'])     ? " -b /usr/local/bin/preRun"          : "" )
                .( !empty($sf_ini['sleep']['postRun'])    ? " -p /usr/local/bin/postRun"         : "" )
                ." -S &";
  }
?>
<script>
$(document).ready(function() {
  $('#sleep').click(function() {
    $(this).val('Sleeping...').attr('disabled',false);
    $.ajax( {
      url: "<?=$sf?>/scripts/run.php",
      data: ({
        cmd: 'sleep',
        sleep_cmd: '<?=rawurlencode($sleep_cmd)?>'
      }),
      success: function(data) { window.location.reload(true); }
    });
  });
});

function activateSleep() {
  document.getElementById('sleep').disabled = !document.getElementById('confirm').checked;
}
</script>

<table class="array_status">
<tr>
<td></td>
<td><input type="button" id="sleep" value="Sleep"<?=$confirm['sleep']?' disabled':''?> onclick="disableInput();"></td>
<td><strong>Sleep</strong> will immediately Sleep Server.<br>
<?if ($confirm['sleep']):?>
<input type="checkbox" id="confirm" value="OFF" onClick="activateSleep()"> <small>Yes I want to do this</small>
<?endif;?>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td>Make sure your server supports S3 sleep.<br><br>
Check this <a href="http://lime-technology.com/wiki/index.php?title=Setup_Sleep_(S3)_and_Wake_on_Lan_(WOL)" target="_blank">wiki entry</a> for more information.
</td>
</tr>
</table>
