diff options
Diffstat (limited to 'pages')
-rw-r--r-- | pages/process.php | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/pages/process.php b/pages/process.php new file mode 100644 index 0000000..21604de --- /dev/null +++ b/pages/process.php @@ -0,0 +1,135 @@ +<?php +//include_once('./includes/maps.php'); +//include_once('./includes/mapclass.php'); + +//Self-ajax. +if ($_REQUEST['command'] == 'updateTask') { + $taskName = 'FAKE RECALCULATION'; + $progress = $_SESSION['tmp']; + + if ($progress >= 100) $_SESSION['dotask'] = false; + + if ($_SESSION['dotask'] !== true) { + $json['percentComplete'] = $_SESSION['tmp']; + $json['taskName'] = $taskName; + $json['completed'] = true; + echo json_encode($json); + exit; + } + + $_SESSION['tmp'] = $_SESSION['tmp'] + 25; + + + $json['percentComplete'] = $_SESSION['tmp']; + $json['taskName'] = $taskName; + $json['completed'] = 'false'; + echo json_encode($json); + exit; +} + +if ($_REQUEST['command'] == 'recalculateStats') { + //Already working on a task? + if ($_SESSION['dotask'] == true) { + $json['error'] = 'Task in progress!'; + echo json_encode($json); + exit; + } + + $_SESSION['tmp'] = 0; + $_SESSION['dotask'] = true; + $json['percentComplete'] = $_SESSION['tmp']; + $json['taskName'] = 'FAKE_Recalculation of stats'; + echo json_encode($json); + exit; +} + +htmlHeader(array('stats', 'achievements'), 'Process Tasks', + 'Process Tasks', + array()); + + +?> + +<body> +<?php +topbar($Links); + +?> +<script> +//setTimeout("start();", 500); +function start() { +} + +var requestComplete = true; +processTimer(); +function processTimer() { + setTimeout("processTimer()", 3000); + if (requestComplete == false) return; + getTaskUpdate('updateTask'); +} + +function recalculate() { + if (!confirm('Are you sure?')) return; + getTaskUpdate('recalculateStats'); +} + +function getTaskUpdate(command) { + //var URLString = 'process?initiate=true&x'+JSON.stringify(testMap); + requestComplete = false; + var URLString = 'process?command='+command; + $.ajax({ + type: "GET", + url: URLString, + cache: true, + data: '', + fail: function() { alert("error"); }, + complete: function(data) { + if (data.responseText.length <= 1) { + console.log('null response'); + requestComplete = true; + return; + } + json = decryptJSON(data.responseText); + if (json.error) { + alert('ERROR: "' + json.error + '".') + requestComplete = true; + return; + } + $('#taskProgressDisp').width(json.percentComplete+'%'); + $('#taskProgressName').html(json.taskName); + // if (json.completed == true) { + // alert("TASK COMPLETE!"); + // } + requestComplete = true; + } + }); +} + + +</script> + +<div class='wrapper'> + +<h3>Task Processor</h3> + <div class='wrapper'> + <form> + <fieldset> + <legend>Load Map:</legend> + <div class='plusMinus'> + Recalculate all statistics: <input type="button" value="Recalculate!" class="forminput" onclick='recalculate()'/> + </div> + Processing: "<span id='taskProgressName'>Loading...</span>" + <div class='progressBar' style='width:600px'> + <div id='taskProgressDisp' style='width:0%;'> + </div> + </div> + + </fieldset> + + </form> + </div> +</div> + +<?php +htmlFooter(); +?>
\ No newline at end of file |