121 lines
5.1 KiB
PHP
121 lines
5.1 KiB
PHP
<?php
|
|
ini_set('display_errors',1);
|
|
$db=$GLOBALS['db'];
|
|
function escape($value) {
|
|
$return = '';
|
|
for($i = 0; $i < strlen($value); ++$i) {
|
|
$char = $value[$i];
|
|
$ord = ord($char);
|
|
if($char !== "'" && $char !== "\"" && $char !== '\\' && $ord >= 32 && $ord <= 126)
|
|
$return .= $char;
|
|
else
|
|
$return .= '\\x' . dechex($ord);
|
|
}
|
|
return $return;
|
|
}
|
|
if($_GET['record']!=''){
|
|
// id nie jest puste? jedziemy i szukamy leadsa ...
|
|
$r=$db->query("select contactlead_id,id,date_modified,deleted from leads_contactleads where lead_id='".$_GET['record']."'");
|
|
if($r->num_rows>0){
|
|
// o jest kontakt!
|
|
while($row=$db->fetchByAssoc($r)){
|
|
// wybieranie ścierwa
|
|
$ct=$db->query("select * from contactleads where id='".$row['contactlead_id']."'");
|
|
while($row2=$db->fetchByAssoc($ct)){
|
|
$db->query("delete from contacts where id='".$row2['id']."'");
|
|
// przenoszenie ścierwa ...
|
|
$db->query("INSERT INTO `contacts` VALUES('".implode("','",array_map('escape', $row2))."')");
|
|
|
|
// echo "INSERT INTO `contacts` VALUES('".implode("','",$row2)."')";
|
|
// usuwanie starego ścierwa ...
|
|
$db->query("delete from contactleads where id='".$row2['id']."'");
|
|
// szukanie emaili...
|
|
$mail=$db->query("select * from email_addr_bean_rel where bean_id='".$row2['id']."'");
|
|
if($mail->num_rows>0){
|
|
// o jest email!
|
|
while($mu=$db->fetchByAssoc($mail)){
|
|
// podmianka relacji na kontakt
|
|
$db->query("update email_addr_bean_rel set bean_module='ContactLeads' where id='".$mu['id']."'");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// die();
|
|
// asasa$$$
|
|
$l=$db->query("select * from leads where id='".$_GET['record']."'");
|
|
$pola=array();
|
|
$wartosci=array();
|
|
while($daj=$db->fetchByAssoc($l)){
|
|
|
|
|
|
foreach ($daj as $pole=>$wartosc){
|
|
if($pole=='lead_type')$pole='account_type';
|
|
if($pole=='lead_id')continue;
|
|
$pola[]=$pole;
|
|
$wartosci[]=$wartosc;
|
|
}
|
|
$r=$db->query("select * from accounts where id='".$_GET['record']."'");
|
|
if($r->num_rows==1)$db->query("delete from accounts where id='".$_GET['record']."'");
|
|
$db->query("INSERT INTO `accounts` (".implode(",",$pola).") VALUES ('".implode("','",$wartosci)."')");
|
|
|
|
// echo "INSERT INTO `accounts` (".implode(",",$pola).") VALUES ('".implode("','",$wartosci)."')<br>";
|
|
$db->query("update leads set deleted='1' where id='".$daj['id']."'");
|
|
|
|
}
|
|
// notatki
|
|
$n1=$db->query("select * from notes where parent_id='".$_GET['record']."'");
|
|
|
|
if($n1->num_rows>0){
|
|
|
|
while($nt=$db->fetchByAssoc($n1)){
|
|
$db->query("update notes set parent_type='Accounts' where id='".$nt['id']."'");
|
|
}
|
|
}
|
|
// przenoszenie emaila
|
|
$mail=$db->query("select * from email_addr_bean_rel where bean_id='".$_GET['record']."'");
|
|
if($mail->num_rows>0){
|
|
// o jest email!
|
|
while($mu=$db->fetchByAssoc($mail)){
|
|
// podmianka relacji na kontrahenta
|
|
$db->query("update email_addr_bean_rel set bean_module='Accounts' where bean_id='".$_GET['record']."'");
|
|
}
|
|
}
|
|
$mail=$db->query("select * from ecmaccountcategories_bean where bean_id='".$_GET['record']."'");
|
|
if($mail->num_rows>0){
|
|
// o jest email!
|
|
while($mu=$db->fetchByAssoc($mail)){
|
|
// podmianka relacji na kontrahenta
|
|
$db->query("update ecmaccountcategories_bean set bean_name='Accounts' where bean_id='".$_GET['record']."'");
|
|
}
|
|
}
|
|
// relacja kontrahent kontakt
|
|
$rr=$db->query("SELECT * FROM leads_contactleads where lead_id='".$_GET['record']."'");
|
|
if($rr->num_rows>0){
|
|
// o jest email!
|
|
while($re=$db->fetchByAssoc($rr)){
|
|
$re['deleted']=0;
|
|
// podmianka relacji na kontrahenta
|
|
$db->query("delete from accounts_contacts where account_id='".$re['id']."'");
|
|
$db->query("INSERT INTO `accounts_contacts` VALUES('".implode("','",$re)."')");
|
|
|
|
$db->query("delete leads_contactleads where lead_id='".$_GET['record']."'");
|
|
}
|
|
}
|
|
// relacja adresy
|
|
$ad=$db->query("SELECT * FROM lead_addresses where lead_id='".$_GET['record']."'");
|
|
if($ad->num_rows>0){
|
|
// o jest email!
|
|
while($re=$db->fetchByAssoc($ad)){
|
|
// podmianka relacji na kontrahenta
|
|
$db->query("delete account_addresses where account_id='".$re['id']."'");
|
|
$db->query("INSERT INTO `account_addresses` VALUES('".implode("','",$re)."')");
|
|
|
|
$db->query("delete lead_addresses where lead_id='".$_GET['record']."'");
|
|
}
|
|
}
|
|
// szukanie kontaktów
|
|
|
|
header("Location: index.php?module=Accounts&action=DetailView&record=".$_GET['record']);
|
|
}
|
|
?>
|