By scarer on
I'm trying to develop a module that synchronizes Storm Organizations and CiviCRM Organizations. However, when I press the Synchronize button in the admin section for the module I get the error:
Fatal error: Cannot use string offset as an array in /var/www/html/storm/includes/form.inc on line 976
Please help!
This is the code of my module so far:
// $Id:
/* @file
* A simple module that adds a CiviCRM organization when a Storm organization is created.
* Author: Sarah Vardy
* Date: 24/02/2009
*/
/**
* Implementation of hook_help()
*/
function civicrm_storm_organizations_help($section, $args = array() )
{
switch ($section) {
case 'admin/modules#description':
return t('Adds CiviCRM organisations when a Storm organisation is created. Syncronises data between CiviCRM organizations and Storm Organizations.');
default :
return;
}
}
/**
* Implementation of hook_menu().
*/
function civicrm_storm_organizations_menu( )
{
$items[] = array();
$items['admin/settings/civicrm_storm_organizations'] = array(
'title' => t('Synchronize CiviCRM Organizations and Storm Organizations'),
'description' => t('Synchronize CiviCRM Organizations and Storm Organizations.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('civicrm_storm_organizations_synchronise_form'),
'access callback' => 'user_access',
'access arguments' => array('access settings'),
);
return $items;
}
/**
* Implementation of hook_perm().
*/
function civicrm_storm_organizations_perm() {
return array('access settings');
}
/**
* Implementation of hook_form().
* Syncronization of CiviCRM Organizations and Storm Organizations form.
*/
function civicrm_storm_organizations_synchronise_form($form, $edit_id = NULL)
{
$form[] = array();
/*$form['synchronize_all'] = array('#type' => 'checkbox',
'#title' => t('Synchronize all CiviCRM Organizations and Storm Organizations'),
); */
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Synchronize'),
);
return $form;
}
/**
* Implementation of hook_submit() for the Syncronization of CiviCRM Organizations and Storm Organizations form.
*/
function civicrm_storm_organizations_synchronise_form_submit($form)
{
//Get all Storm Organizations
$title[] = array();
$email[] = array();
$fullname[] = array();
$country[] = array();
$state[] = array();
$city[] = array();
$zip[] = array();
$address[] = array();
$count= 0;
//$exists = 0;
$get_storm_organizations = db_query("SELECT n.title, so.email, so.fullname, so.country, so.state, so.city, so.zip, so.address FROM {node} n JOIN {stormorganization} so ON n.nid = so.nid WHERE type = 'stormorganization'");
//Store all Storm Organizations
while ($node = db_fetch_object($get_storm_organizations)) {
//store titles in an array
$title[$count] = $node->title;
$email[$count] = $node->email;
//$fullname[$count] = $node->fullname;
//$country[$count] = $node->country;
//$state[$count] = $node->state;
$city[$count] = $node->city;
$zip[$count] = $node->zip;
$address[$count] = $node->address;
$count ++;
}//end while statement
//Check if Storm Organization is already stored
for ($i = 0; $i < count($title); $i ++)
{
$tmpTitle = $title[$i];
$tmpEmail = $email[$i];
//$tmpFullname = $fullname[$i];
//$tmpCountry = $country[$i];
//$tmpState = $state[$i];
$tmpCity = $city[$i];
$tmpZip = $tmpZip[$i];
$tmpAddress = $address[$i];
//add Storm Organizations to CiviCRM Organizations if not already stored
//If it is then skip
//If not then insert it
$add_contact = db_query("INSERT INTO {civicrm_contact} (contact_type, sort_name, display_name) VALUES ('Organization', $tmpEmail, $tmpEmail)");
//Get contact Id and insert other details into CiviCRM
$get_contact_id = db_query("SELECT id FROM civicrm_contact WHERE sort_name = $tmpEmail");
while ($contactId = db_fetch_object($get_contact_id))
{
$tmpContactId = $contactId->id;
}
$insert_other_contact_data = db_query("INSERT INTO {civicrm_address} (id, streetaddress, city, postal_code) VALUES ($tmpContactId, $tmpAddress, $tmpCity, $tmpZip)");
}
}
Comments
Try this:
In civicrm_storm_organizations_synchronise_form()
Replace:
With: