. */ ####################################### ### Update Address Book (ab_bodies) ### ####################################### if( $rundaily!="yes" ) { // no access exit(); } $out.="\n\n=== Updating Address Book copy ===\n"; if( !($ABconn=@mysql_connect(MYSQL_AB_HOST, MYSQL_AB_USER, MYSQL_AB_PASS)) ) { $out.="Failed connecting to mysql://".MYSQL_AB_USER."@".MYSQL_AB_HOST."\n"; }else { if( !(@mysql_select_db(MYSQL_AB_DB, $ABconn)) ) { $out.="Failed connecting to mysql://".MYSQL_AB_USER."@".MYSQL_AB_HOST."/".MYSQL_AB_DB."\n"; }else { $query="SELECT `bodycode`, `bodyname`, `email`, `bodystatus`, `bodycategory`, `bodycategoryorder`, `bodynameascii`, `netcomcode`, `countrycode` FROM `bodies`"; if( !($res=@mysql_query($query,$ABconn)) ) { $out.="Failed loading AB from Karl\n"; }else { // Read the AB data from Karl while( $row=mysql_fetch_array($res) ) { $AB[ $row['bodycode'] ]['bodyname']=htmlentities(stripslashes($row["bodyname"]),ENT_QUOTES); $AB[ $row['bodycode'] ]['email']=$row["email"]; $AB[ $row['bodycode'] ]['bodystatus']=$row["bodystatus"]; $AB[ $row['bodycode'] ]['bodycategory']=htmlentities(stripslashes($row["bodycategory"]),ENT_QUOTES); $AB[ $row['bodycode'] ]['bodycategoryorder']=$row["bodycategoryorder"]; $AB[ $row['bodycode'] ]['bodynameascii']=$row["bodynameascii"]; $AB[ $row['bodycode'] ]['netcomcode']=$row["netcomcode"]; $AB[ $row['bodycode'] ]['countrycode']=$row["countrycode"]; if( strlen($AB[ $row['bodycode'] ]['countrycode'])==0 ) $AB[ $row['bodycode'] ]['countrycode']="XXX"; } $query="SELECT `bodycode`, `bodyname`, `email`, `bodystatus`, `bodycategory`, `bodycategoryorder`, `bodynameascii`, `netcomcode`, `countrycode` FROM `ab_bodies`"; if( !($res=doquery($query)) ) { $out.="Failed loading current AB from localhost\n"; }else { while( $row=mysql_fetch_array($res) ) { if( !(isset( $AB[ $row['bodycode'] ] )) ) { // Entry does not exist any more in master }else { // Entry already in local copy of DB if( $AB[ $row['bodycode'] ]['bodyname']!=$row['bodyname'] OR $AB[ $row['bodycode'] ]['email']!=$row['email'] OR $AB[ $row['bodycode'] ]['bodystatus']!=$row['bodystatus'] OR $AB[ $row['bodycode'] ]['bodycategory']!=$row['bodycategory'] OR $AB[ $row['bodycode'] ]['bodycategoryorder']!=$row['bodycategoryorder'] OR $AB[ $row['bodycode'] ]['bodynameascii']!=$row['bodynameascii'] OR $AB[ $row['bodycode'] ]['netcomcode']!=$row['netcomcode'] OR $AB[ $row['bodycode'] ]['countrycode']!=$row['countrycode'] ) { // Entries differ $query="UPDATE `ab_bodies` SET `bodyname`='".addslashes($AB[ $row['bodycode'] ]['bodyname'])."', `email`='".addslashes($AB[ $row['bodycode'] ]['email'])."', `bodystatus`='".addslashes($AB[ $row['bodycode'] ]['bodystatus'])."', `bodycategory`='".addslashes($AB[ $row['bodycode'] ]['bodycategory'])."', `bodycategoryorder`=".addslashes($AB[ $row['bodycode'] ]['bodycategoryorder']).", `bodynameascii`='".addslashes($AB[ $row['bodycode'] ]['bodynameascii'])."', `netcomcode`='".addslashes($AB[ $row['bodycode'] ]['netcomcode'])."', `countrycode`='".addslashes($AB[ $row['bodycode'] ]['countrycode'])."' WHERE `bodycode`='".addslashes($row['bodycode'])."'"; if( doquery($query) ) { $out.="\nUpdated successfully ".$row['bodycode'].":\n"; }else { $out.="\nFailed updating ".$row['bodycode'].":\n"; } if( $AB[ $row['bodycode'] ]['bodyname']!=$row['bodyname'] ) $out.="BodyName: ".$row['bodyname']." ==> ".$AB[ $row['bodycode'] ]['bodyname']."\n"; if( $AB[ $row['bodycode'] ]['email']!=$row['email'] ) $out.="Email: ".$row['email']." ==> ".$AB[ $row['bodycode'] ]['email']."\n"; if( $AB[ $row['bodycode'] ]['bodystatus']!=$row['bodystatus'] ) $out.="BodyStatus: ".$row['bodystatus']." ==> ".$AB[ $row['bodycode'] ]['bodystatus']."\n"; if( $AB[ $row['bodycode'] ]['bodycategory']!=$row['bodycategory'] ) $out.="BodyCategory: ".$row['bodycategory']." ==> ".$AB[ $row['bodycode'] ]['bodycategory']."\n"; if( $AB[ $row['bodycode'] ]['bodycategoryorder']!=$row['bodycategoryorder'] ) $out.="BodyCategoryOrder: ".$row['bodycategoryorder']." ==> ".$AB[ $row['bodycode'] ]['bodycategoryorder']."\n"; if( $AB[ $row['bodycode'] ]['bodynameascii']!=$row['bodynameascii'] ) $out.="BodyNameAscii: ".$row['bodynameascii']." ==> ".$AB[ $row['bodycode'] ]['bodynameascii']."\n"; if( $AB[ $row['bodycode'] ]['netcomcode']!=$row['netcomcode'] ) $out.="NetcomCode: ".$row['netcomcode']." ==> ".$AB[ $row['bodycode'] ]['netcomcode']."\n"; if( $AB[ $row['bodycode'] ]['countrycode']!=$row['countrycode'] ) $out.="CountryCode: ".$row['countrycode']." ==> ".$AB[ $row['bodycode'] ]['countrycode']."\n"; }else { // Nothing changed, so nothing to update } unset( $AB[ $row['bodycode'] ] ); } } #/end of while // Check if there are new bodies in the master AB $bodies=array_keys($AB); for($i=0; $i