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

$parenarray = array("open_1","close_1","open_2","close_2","open_3","close_3","open_4","close_4","open_5","close_5","open_6","close_6");

echo "<br />Finding Positions...";
$res = $DB->execute("select id, enginecode from parenlocations order by id ASC");

if(!is_null($res)){
	$res = $res[0];
	while($W = $DB->nextRow($res)){
		$id = $W['id'];
		$enginecode = $W['enginecode'];

		//NOW GO
		saveToRow($id, $enginecode);
	}
	echo "<br />ENDED<hr />";
}else{ "<span style='color:#F00'>Error in Commencement</span><br />"; }


function saveToRow($id, $enginecode){
	global $DB, $parenarray; $pt = -1; $clause = "";
	for($i=0; $i<strlen($enginecode); $i++){
		switch(substr($enginecode,$i,1)){
			case '(': case ')':
			$pt++;
			$clause .= ", {$parenarray[$pt]} = '".($i+1)."'";
			break;
		}
	}

	//save
	if(substr($clause,0,1)==',') $clause = substr($clause,1);
	if($clause!=""){
		if($DB->simpleQuery("update parenlocations set {$clause} where id = '{$id}'")){
			echo "<br />Done at #{$id}";
		}else{echo "update parenlocations set {$clause} where id = '{$id}'";
			echo "<br /><span style='color:#F00'>Error at #{$id}</span>";
		}
	}else{
		echo "<br /><span style='color:#F00'>Skipped at #{$id}</span>";
	}

	return $sav;
}
?>