Hi all

i'm try to import contacts and link with another modules (Channel, Fabricantes), same to Contacts-Accounts. but no working when i add the new functions in modules/Import/ImportContact.php.
is there any configuration missing in my CRM? Where? What ?
Thanks for you cooperation

ImportContact.php

var $special_functions = array(
"get_names_from_full_name"
,"add_created_modified_dates"
,"add_create_assigned_user_name"
,"add_create_account"
,"add_create_channel"
,"add_create_fabricante"

,"add_salutation"
,"add_lead_source"
,"add_birthdate"
,"add_do_not_call"
,"add_email_opt_out"
,"add_primary_address_streets"
,"add_alt_address_streets"
);

//------------------------------------------------- CREATE CHANNEL
function add_create_channel()
{
// global is defined in UsersLastImport.php
global $imported_ids;
global $current_user;

if ( (! isset($this->channel_name) || $this->channel_name == '') &&
(! isset($this->channel_id) || $this->channel_id == '') )
{
return;
}

$arr = array();

// check if it already exists
$focus = new Channel();

$query = '';

// if user is defining the account id to be associated with this contact..
if ( isset($this->channel_id) && $this->channel_id != '')
{
$this->channel_id = convert_id($this->channel_id);
$query = "select * from {$focus->table_name} WHERE id='". PearDatabase::quote($this->channel_id)."'";
}
// else user is defining the account name to be associated with this contact..
else
{
$query = "select * from {$focus->table_name} WHERE name='". PearDatabase::quote($this->channel_name)."'";
}

$GLOBALS['log']->info($query);

$result = $this->db->query($query)
or sugar_die("Error selecting sugarbean: ");

while ($row = $this->db->fetchByAssoc($result, -1, false)) {
if (isset($row['id']) && $row['id'] != -1)
{
// if it exists but was deleted, just remove it entirely
if ( isset($row['deleted']) && $row['deleted'] == 1)
{
$query2 = "delete from {$focus->table_name} WHERE id='". PearDatabase::quote($row['id'])."'";

$GLOBALS['log']->info($query2);

$result2 = $this->db->query($query2)
or sugar_die("Error deleting existing sugarbean: ");

}
else
{
$focus->id = $row['id'];
}
}
}

// if we didnt find the account, so create it
if (! isset($focus->id) || $focus->id == '')
{
$focus->name = $this->channel_name;
if ( isset($this->assigned_user_id))
{
$focus->assigned_user_id = $this->assigned_user_id;
$focus->modified_user_id = $this->assigned_user_id;
}
else
{
$focus->assigned_user_id = $current_user->id;
$focus->modified_user_id = $current_user->id;
}

if ( isset($this->modified_date))
{
$focus->modified_date = $this->modified_date;
}
// if we are providing the account id:
if ( isset($this->channel_id) &&
$this->channel_id != '')
{
$focus->new_with_id = true;
$focus->id = $this->channel_id;
}

$focus->save();
// avoid duplicate mappings:
if (! isset( $imported_ids[$focus->id]) )
{
// save the new account as a users_last_import
$last_import = new UsersLastImport();
$last_import->assigned_user_id = $current_user->id;
$last_import->bean_type = "Channel";
$last_import->bean_id = $focus->id;
$last_import->save();
$imported_ids[$focus->id] = 1;
}
}

// now just link the account
$this->channel_id = $focus->id;

}

//------------------------------------------------

//------------------------------------------------- CREATE FABRICANTE
function add_create_fabricante()
{
// global is defined in UsersLastImport.php
global $imported_ids;
global $current_user;

if ( (! isset($this->manufacturer_name) || $this->manufacturer_name == '') &&
(! isset($this->manufacturer_id) || $this->manufacturer_id == '') )
{
return;
}

$arr = array();

// check if it already exists
$focus = new ModFabricantes();

$query = '';

// if user is defining the account id to be associated with this contact..
if ( isset($this->manufacturer_id) && $this->manufacturer_id != '')
{
$this->manufacturer_id = convert_id($this->manufacturer_id);
$query = "select * from {$focus->table_name} WHERE id='". PearDatabase::quote($this->manufacturer_id)."'";
}
// else user is defining the account name to be associated with this contact..
else
{
$query = "select * from {$focus->table_name} WHERE name='". PearDatabase::quote($this->manufacturer_name)."'";
}

$GLOBALS['log']->info($query);

$result = $this->db->query($query)
or sugar_die("Error selecting sugarbean: ");

while ($row = $this->db->fetchByAssoc($result, -1, false)) {
if (isset($row['id']) && $row['id'] != -1)
{
// if it exists but was deleted, just remove it entirely
if ( isset($row['deleted']) && $row['deleted'] == 1)
{
$query2 = "delete from {$focus->table_name} WHERE id='". PearDatabase::quote($row['id'])."'";

$GLOBALS['log']->info($query2);

$result2 = $this->db->query($query2)
or sugar_die("Error deleting existing sugarbean: ");

}
else
{
$focus->id = $row['id'];
}
}
}

// if we didnt find the account, so create it
if (! isset($focus->id) || $focus->id == '')
{
$focus->name = $this->manufacturer_name;
if ( isset($this->assigned_user_id))
{
$focus->assigned_user_id = $this->assigned_user_id;
$focus->modified_user_id = $this->assigned_user_id;
}
else
{
$focus->assigned_user_id = $current_user->id;
$focus->modified_user_id = $current_user->id;
}

if ( isset($this->modified_date))
{
$focus->modified_date = $this->modified_date;
}
// if we are providing the account id:
if ( isset($this->manufacturer_id) &&
$this->manufacturer_id != '')
{
$focus->new_with_id = true;
$focus->id = $this->manufacturer_id;
}

$focus->save();
// avoid duplicate mappings:
if (! isset( $imported_ids[$focus->id]) )
{
// save the new account as a users_last_import
$last_import = new UsersLastImport();
$last_import->assigned_user_id = $current_user->id;
$last_import->bean_type = "ModFabricantes";
$last_import->bean_id = $focus->id;
$last_import->save();
$imported_ids[$focus->id] = 1;
}
}

// now just link the account
$this->manufacturer_id = $focus->id;

}

//------------------------------------------------
vardefs.php

'accounts' =>
array (
'name' => 'accounts',
'type' => 'link',
'relationship' => 'accounts_contacts',
'link_type' => 'one',
'source' => 'non-db',
'vname' => 'LBL_ACCOUNT',
),
'channels' =>
array (
'name' => 'channels',
'type' => 'link',
'relationship' => 'channels_contacts',
'link_type' => 'one',
'source' => 'non-db',
'vname' => 'LBL_CHANNEL',
),
'manufacturers' =>
array (
'name' => 'manufacturers',
'type' => 'link',
'relationship' => 'manufacturers_contacts',
'link_type' => 'one',
'source' => 'non-db',
'vname' => 'LBL_MANUFACTURER',
),

'channels_contacts' => array('lhs_module'=> 'Contacts', 'lhs_table'=> 'contacts', 'lhs_key' => 'id',
'rhs_module'=> 'Channel', 'rhs_table'=> 'channel', 'rhs_key' => 'id',
'relationship_type'=>'many-to-many',
'join_table'=> 'channels_contacts', 'join_key_lhs'=>'contact_id', 'join_key_rhs'=>'channel_id'),

'manufacturers_contacts' => array('lhs_module'=> 'Contacts', 'lhs_table'=> 'contacts', 'lhs_key' => 'id',
'rhs_module'=> 'ModFabricantes', 'rhs_table'=> 'Fabricantes', 'rhs_key' => 'id',
'relationship_type'=>'many-to-many',
'join_table'=> 'manufacturers_contacts', 'join_key_lhs'=>'contact_id', 'join_key_rhs'=>'manufacturer_id'),