<?php
$is_done = false;
//// insert / copy into database table
if(isset($_POST['import'])){
	
	$result = mysql_query("SELECT * FROM scope_std where stdCompany = '261' AND stdStatus = '1' ORDER BY stdPrefix ASC, stdCode ASC");
	while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
		// check if exist already
		$resultD = mysql_query("SELECT * FROM scope_std where stdCompany = '".$companyID."' AND (`stdPrefix` = '".$row['stdPrefix']."' AND `stdCode` = '".$row['stdCode']."') AND stdStatus != '2'");
		if(mysql_num_rows($resultD) == 0){
			$sql = "INSERT INTO `scope_std` 
				   (`stdPrefix`, `stdCode`,`stdName`, `stdDateCreated`, `stdCompany`, `stdStatus`) 
					VALUES ('".$row['stdPrefix']."', '".$row['stdCode']."', '".$row['stdName']."','".$row['stdDateCreated']."', '".$companyID."', '".$row['stdStatus']."')";
			mysql_query($sql) or die("Failed to Add Data : ".mysql_error());	
		}
	}		
	$is_done = true;	
}
//// end insert / update into database table
if($is_done){
	echo '<script>window.location="03-01Scope-01Standards01.php?msg=Imported Successfully.";</script>';
}
?> 