<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
require_once('config.php');
$GLOBALS['installing'] = true;
require_once('include/entryPoint.php');
$GLOBALS['log'] = LoggerManager :: getLogger('SugarCRM');

$db = DBManagerFactory::getInstance();

$query = mysql_query("	select id 
						from cont__centro_llamadas
						where cont__opciones_respuestas_id_c = '41dcbc2e-8af7-6a7e-7eed-55eeebb32f18'");

$res = array();
$res2 = array();

while($arr = mysql_fetch_array($query)){
	$res[] = '"'.$arr["id"].'"';
}

$res = implode(",", $res);
$query = mysql_query("	select cont__centro_llamadas_contactscontacts_ida, cont__centro_llamadas_contactscont__centro_llamadas_idb
						from cont__centro_llamadas_contacts_c
						where cont__centro_llamadas_contactscont__centro_llamadas_idb IN(".$res.")
					");
$res = array();
$res2 = array();
while($arr = mysql_fetch_array($query)){
	$res[] = '"'.$arr["cont__centro_llamadas_contactscontacts_ida"].'"';
	$res2[] = '"'.$arr["cont__centro_llamadas_contactscont__centro_llamadas_idb"].'"';
}

$i=0;
$res = implode(",", $res);
$res2 = implode(",", $res2);
$query = mysql_query("delete from cont__centro_llamadas_contacts_c where cont__centro_llamadas_contactscontacts_ida IN (".$res.")") or die(mysql_error() . "query 1");
$query = mysql_query("delete from contacts where id IN (".$res.")") or die(mysql_error() . "query 2");
$query = mysql_query("delete from contacts_cstm where id_c IN (".$res.")") or die(mysql_error() . "query 3");
$query = mysql_query("delete from cont__centro_llamadas where id IN (".$res2.")") or die(mysql_error() . "query 4");
$query = mysql_query("delete from stu_tiendas_contacts_c where stu_tiendas_contactscontacts_idb IN (".$res.")") or die(mysql_error() . "query 1");
$query = mysql_query("delete from email_addr_bean_rel where bean_id IN (".$res.")") or die(mysql_error() . "query 5");

$query = mysql_query("delete from email_addresses where id not in (select email_address_id from email_addr_bean_rel)") or die(mysql_error() . "query 7");


?>