Code:
<?php
define('sugarEntry', TRUE);
require_once('erpconfig.php');
$hf = fopen("MANUFACT_soap.log","a");
//fwrite($hf, "\n*********************From Sugar-");
require_once('../include/nusoap/nusoap.php');
// change the URL here to point to your Sugar installation
$soapclient = new nusoapclient($soapurl,true);
$user_auth = array(
'user_auth' => array(
'user_name' => $soapuser,
'password' => md5($soappaswd),
'version' => '0.1'
),
'application_name' => 'MANUFfrm');
$result_array = $soapclient->call('login',$user_auth);
$session_id = $result_array['id'];
$user_guid = $soapclient->call('get_user_id',$session_id);
//fwrite($hf, "\n*********************Opening DB-");
$g_link = mysql_connect( $dbhost, $dbuser, $dbpasswd) or die('Could not connect to mysql server.' );
mysql_select_db($db, $g_link) or die('Could not select database.');
$qry = "SELECT manufacturers_id as manuf_id, manufacturers_name as name FROM manufacturers ORDER BY manufacturers_id";
$sqlresult = mysql_query($qry);
while ($row = mysql_fetch_assoc($sqlresult)) {
$man_id = $row['manuf_id'];
$cname = str_replace('®','',$row['name']);
$cname = str_replace(",","",$cname);
$cname = str_replace(".","",$cname);
$list_order = $row['manuf_id'];
$status = 'Active';
fwrite($hf, "\n\nManufacturer---->".$man_id."#mname.....".$cname);
//FIRST CHECK IF THE RECORD IS AVAILABLE IT IS TO UPDATE
$sman_id=NULL;
$prcat_list_params = array(
'session' => $session_id,
'module_name' => 'Leads',
'query' => 'leads_cstm.list_order_c = "' . $list_order . '"',
'offset' => 0,
'select_fields' => array('id'),
'max_results' => 1,
'deleted' => 0
);
$prcat_list_array = $soapclient->call('get_entry_list',$prcat_list_params);
$prcat_id = $prcat_list_array['entry_list'][0]['name_value_list'][0]['value'];
//fwrite($hf, "\nIF THE RECORD IS AVAILABLE IT IS TO UPDATE.....".$prcat_id);
if(isset($prcat_id)){
$set_entry_params = array(
'session' => $session_id,
'module_name' => 'Leads',
'name_value_list'=>array(
array('name'=>'id','value'=>$prcat_id),
array('name'=>'name','value'=>$cname),
array('name'=>'list_order_c','value'=>$list_order),
array('name'=>'status_c','value'=>$status),
array('name'=>'assigned_user_id', 'value'=>$user_guid)));
} else{
$set_entry_params = array(
'session' => $session_id,
'module_name' => 'Manufacturers',
'name_value_list'=>array(
array('name'=>'name','value'=>$cname),
array('name'=>'list_order_c','value'=>$list_order),
array('name'=>'status_c','value'=>$status),
array('name'=>'assigned_user_id', 'value'=>$user_guid)));
}
// fwrite($hf, "\nManufacturer now ready to set at Sugar Lead...............");
$result = $soapclient->call('set_entry',$set_entry_params);
$acctid = $result['id'];
fwrite($hf, "\nLead ID generated.....".$acctid);
fwrite($hf, "\nManuf ID error:".$soapclient->error_str);
}
// Free the resources associated with the result set
// This is done automatically at the end of the script
mysql_free_result($sqlresult);
fwrite($hf, "\n**************************Closing the file***********");
fclose($hf);
?>
Bookmarks