<?php require_once("../../classes/DBConnection.php"); $DB = new DBConnection();

$t1_name		 	= trim($_POST['t1_name']);
$id_from			= (int) trim($_POST['id_from']);
$id_to				= (int) trim($_POST['id_to']);

//range clause
$rangeclause = "";
if($id_from>0){
	if($id_to>0){
		$rangeclause = "where id>='{$id_from}' and id<='{$id_to}' ";
	}else{
		$rangeclause = "where id>='{$id_from}' ";
	}
}

if($t1_name != ""){
	$no = 0;
	echo "<br />RSTATUS Placement Started";
	$res = $DB->execute("select * from `{$t1_name}` {$rangeclause}order by id ASC");

	if(!is_null($res)){
		$res = $res[0];
		while($W = $DB->nextRow($res)){
			$id = $W['id']; $oldduty = $W['o_duty']; $newduty = $W['n_duty']; $tolerance = 10; $no++;
			//reset
			$dotag = false; $tag = "";

			if(abs($oldduty - $newduty)>$tolerance){
				$dotag = true;
				if($oldduty>$newduty) $tag = "over";
				else $tag = "under";
			}

			if(!$dotag) $tag = 'norm';
			if($DB->simpleQuery("update `{$t1_name}` set _rstatus='{$tag}' where id='{$id}'")){
				echo "<br />{$tag} at #{$id}";
			}else{
				echo "<br />Failed at #{$id}";
			}
		}
		echo "<br />ENDED<hr />";
	}
}
?>