function salesforce_install in Salesforce Suite 5
File
- ./
salesforce.install, line 3
Code
function salesforce_install() {
if (!module_exists('profile')) {
form_set_error('status_salesforce', t('salesforce.module requires profile.module'));
}
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$users_table = db_query("CREATE TABLE {salesforce_users} (\n uid int(11) NOT NULL default '0',\n lead_id tinytext NOT NULL,\n contact_id tinytext NOT NULL,\n opp_id tinytext NOT NULL,\n account_id tinytext NOT NULL,\n created timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n PRIMARY KEY (uid)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8");
if (!db_error()) {
drupal_set_message(t('salesforce.module - users table installed successfully'));
}
else {
drupal_set_message(t('salesforce.module - users table did not install'), 'error');
}
$log_table = db_query("CREATE TABLE {salesforce_log} (\n sid int(11) NOT NULL auto_increment,\n type varchar(255) NOT NULL default '',\n type_id int(11) NOT NULL default '0',\n message tinytext NOT NULL,\n timestamp timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n status int(11) NOT NULL default '0',\n data text NOT NULL,\n PRIMARY KEY (sid),\n KEY type (type,type_id)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
if (!db_error()) {
drupal_set_message(t('salesforce.module - logs table installed successfully'));
}
else {
drupal_set_message(t('salesforce.module - logs table did not install'), 'error');
}
break;
}
// add required fields in profile.module for salesforce api
$fields = array();
$fields[] = array(
'title' => 'First Name',
'name' => 'first_name',
'category' => 'Personal Information',
'page' => 'first_name',
'type' => 'textfield',
'weight' => 0,
'required' => 1,
'register' => 1,
'visibility' => 2,
'autocomplete' => 0,
);
$fields[] = array(
'title' => 'Last Name',
'name' => 'last_name',
'category' => 'Personal Information',
'page' => 'last_name',
'type' => 'textfield',
'weight' => 1,
'required' => 1,
'register' => 1,
'visibility' => 2,
'autocomplete' => 0,
);
$fields[] = array(
'title' => 'Company',
'name' => 'company',
'category' => 'Personal Information',
'page' => 'company',
'type' => 'textfield',
'weight' => 2,
'required' => 1,
'register' => 1,
'visibility' => 2,
'autocomplete' => 0,
);
$fields[] = array(
'title' => 'Phone',
'name' => 'phone',
'category' => 'Personal Information',
'type' => 'textfield',
'weight' => 3,
'required' => 0,
'register' => 1,
'visibility' => 2,
'autocomplete' => 0,
);
$fields[] = array(
'title' => 'Fax',
'name' => 'fax',
'category' => 'Personal Information',
'type' => 'textfield',
'weight' => 4,
'required' => 0,
'register' => 1,
'visibility' => 2,
'autocomplete' => 0,
);
foreach ($fields as $field) {
$result = db_result(db_query("SELECT fid FROM {profile_fields} WHERE name = '%s'", $field['name']));
if (!$result) {
profile_field_form_submit('salesforce_install', $field);
}
}
}