rendered paste body<?phprequire_once(EGW_INCLUDE_ROOT.'/dupecheck/inc/class.sodupecheck.inc.php');require_once(EGW_INCLUDE_ROOT.'/dupecheck/inc/approximate-search.php');class bodupecheck extends sodupecheck{ var $public_functions = array( 'getMatches' => True, ); function bodupecheck() { $_SERVER['toleranceIndex']=0.49; $this->sodupecheck(); //call constructor of sodupecheck } function dupeCheck() { $entries = $this->getAllEntries(); foreach($entries as $k=>$v) { $entries[$k]=strtolower($v);//make case insensitive } $keys = array_keys($entries); $values = array_values($entries); $comparewith=$values; $comparewithkeys=$keys; $i=0; while(!empty($values[$i])) { $rawmatches = array(); $value=$values[$i]; $key=$keys[$i]; $tolerance=round((strlen($value))*$_SERVER['toleranceIndex'],0);//round to int $newmatches = array(); $newmatches = $this->rawSearch($value,$key,$comparewith,$comparewithkeys,$tolerance); array_splice($comparewith, 0,1);//remove current element array_splice($comparewithkeys, 0,1); $rawmatches = array_merge($rawmatches,$newmatches); $this->fineSearch($rawmatches); $i++; } } function rawSearch($searchstr,$currentkey,$comparewith,$comparewithkeys,$tolerance) { $j=1; $matches = array(); $search = new Approximate_Search( $searchstr, $tolerance ); if ( $search->too_short_err ) { $error = "Unable to search - use longer pattern "."or reduce error tolerance."; } for($i=1; $i<count($comparewith);$i++) { $found = $search->search( $comparewith[$i] ); if(!empty($found)) { if(empty($matches))array_push($matches,$currentkey); $matches[$j] = $comparewithkeys[$i]; $j++; } } return $matches; } function fineSearch($rawmatches) { static $nmbr=0; if(!empty($rawmatches)) { $comparetoEntry=$this->readEntry($rawmatches[0]); $compareto_n_given = $comparetoEntry["n_given"]; $compareto_n_family = $comparetoEntry["n_family"]; $nmbrofmatches = count($rawmatches)-1; $matches=$rawmatches; for($i=0;$i<$nmbrofmatches;$i++) { $comparewithEntry=$this->readEntry($rawmatches[$i+1]); $comparewith_n_given = $comparewithEntry["n_given"]; $comparewith_n_family = $comparewithEntry["n_family"]; $tolerance1=round((strlen($comparewith_n_given))*$_SERVER['toleranceIndex'],0); $tolerance2=round((strlen($comparewith_n_family))*$_SERVER['toleranceIndex'],0); do { $search = new Approximate_Search($comparewith_n_given,$tolerance1); $found = $search->search($compareto_n_given); $tolerance1--; }while(!empty($found)); do { $search = new Approximate_Search($comparewith_n_family,$tolerance2); $found = $search->search($compareto_n_family); $tolerance2--; }while(!empty($found)); $probability=(strlen($comparewith_n_family)+strlen($comparewith_n_given)-(($tolerance1+2)*0.7+($tolerance2+2)*0.3))/(strlen($comparewith_n_family)+strlen($comparewith_n_given)); $probability=round($probability,2); if ($comparewithEntry["owner"]==$comparetoEntry["owner"]) { $mergable=1; }else $mergable=0; $nmbr++; $match = array("nmbr"=>$nmbr,"entry" => $comparetoEntry,"match" => $comparewithEntry,"probability"=>$probability,"mergable"=>$mergable); if(empty($_SERVER['matches']))$_SERVER['matches']=array("invisible"); array_push($_SERVER['matches'],$match); } } } function getMatches() { return $_SERVER['matches']; } function merge($content) { //$this->dupecheck();//quickfix, check again, load matches again into global print_r($_SERVER['matches']);//this array is empty, why? its a global that wasn't empty earlier... $fields=array("n_prefix","n_given","n_middle","n_family","n_suffix","n_fn","bday","org_name","org_unit","title","role","assistent","room","adr_one_street","adr_one_street2","adr_one_locality","adr_one_region","adr_one_SERVERalcode","adr_one_countryname","adr_two_street","adr_two_street2","adr_two_locality","adr_two_region","adr_two_SERVERalcode","adr_two_countryname","tel_work","tel_cell","tel_fax","tel_assistent","tel_car","tel_pager","tel_home","tel_fax_home","tel_cell_private","tel_other","email","email_home","url","url_home","note","pubkey"); $id=1; while(empty($content['entry']['deal'][$id]))$id++; $entry=$_SERVER['matches'][$id]['entry']; $match=$_SERVER['matches'][$id]['match']; for ($i=0;$i<count($fields);$i++) { if(empty($entry[$fields[$i]]))$entry[$fields[$i]]=$match[$fields[$i]]; if($entry[$fields[$i]]==$match[$fields[$i]])$match[$fields[$i]]=""; } $content['entry']=$entry; //echo "id=".$id.$_SERVER['matches']['entry']['n_family']; //$content['entry']['n_family']="Van Woensel"; //$content['entry']['email']=$matches[$id]['entry']['email']; $content['match']=$match; /*$content['match']['n_family']=$matches[$id]['match']['n_family'];*/ return $content; }}