<?php
// inner join ecmcalls_beans as e on c.id=e.ecmcall_id
/*$w=mysql_query("select c.* from cdr as c where c.calldate>='2010-08-01 00:00:00'");
while($r=mysql_fetch_array($w)){
	$ww=mysql_query("select * from ecmcalls_beans where ecmcall_id='".$r['id']."' and src='".$r['dst']."' and deleted='0'");
	if(mysql_num_rows($ww)==0 && strlen($r['dst'])>=9){
		$rrr=mysql_fetch_array(mysql_query("select name,phone_office,id from accounts where phone_office like '%".$r['dst']."%' and deleted='0'"));
		if($rrr['id']){
			echo "#src: ".$r['src']." dst: ".$r['dst']." ".$rrr['name']." ".$rrr['phone_office']."<br>";
			$dst=$r['dst'];
			if(!eregi("0048",$r['dst'])){
				$dst='0048'.$r['dst'];
				if(strlen($dst>=12))echo "update cdr set dst='".$dst."' where id='".$r['id']."'<br>"; 
			}
			if(strlen($dst>=12))echo "insert into ecmcalls_beans(id,ecmcall_id,bean_id,bean_module,src,date_modified,deleted) values('".create_guid()."','".$r['id']."','".$rrr['id']."','Accounts','".$dst."','".date("Y-m-d H:i:s")."','0');<br>";
		}
	}
}
$w=mysql_query("select c.* from cdr as c where c.calldate>='2010-08-01 00:00:00'");
while($r=mysql_fetch_array($w)){
	if(!eregi("0048",$r['dst']) && strlen($r['dst'])==9){
		echo "update cdr set dst='0048".$r['dst']."' where id='".$r['id']."';<br>";
	}
}*/
$w=mysql_query("select * from ecmcalls_beans where date_modified>='2010-08-01 00:00:00'");
while($r=mysql_fetch_array($w)){
	if(!eregi("0048",$r['src']) && strlen($r['src'])==9){
		echo "update ecmcalls_beans set src='0048".$r['src']."' where id='".$r['id']."';<br>";
	}
}
?>