query($sql);
$temparray = $adb->fetch_array($result);
$fileContent = $temparray['data'];
$filename=$temparray['filename'];
$filesize=$temparray['filesize'];
$wordtemplatedownloadpath =$root_directory ."/test/wordtemplatedownload/";
if($mergeFileName == "")
{
die("Select Mail Merge Template");
}
$handle = fopen($wordtemplatedownloadpath .$temparray['filename'],"wb");
//chmod("/home/rajeshkannan/test/".$fileContent,0755);
fwrite($handle,base64_decode($fileContent),$filesize);
fclose($handle);
//for mass merge
$mass_merge = $_REQUEST['idlist'];
if($mass_merge != "")
{
$mass_merge = explode(";",$mass_merge);
for($i=0;$i < count($mass_merge) - 1;$i++)
{
$query = "SELECT * FROM account inner join accountbillads on accountbillads.accountaddressid=account.accountid inner join accountshipads on accountshipads.accountaddressid=account.accountid and account.accountid = '".$mass_merge[$i]."'";
$result = $adb->query($query);
$y=$adb->num_fields($result);
$columnValues = $adb->fetch_array($result);
for ($x=0; $x<$y; $x++)
{
$columnValString[$x] = $columnValues[$x];
}
//for custom fields
$sql2 = "select accountscf.* from accountscf inner join account on account.accountid = accountscf.accountid where account.accountid = '".$mass_merge[$i]."'";
$result2 = $adb->query($sql2);
$numRows2 = $adb->num_fields($result2);
$custom_field_values = $adb->fetch_array($result2);
for ($z=1; $z<$numRows2; $z++)
{
$custom_values_str[$z] = $custom_field_values[$z];
}
//end custom fields
$merged_columnValString = array_merge($columnValString,$custom_values_str);
$mass_columnString = implode(",",$merged_columnValString);
$mass_columnValString = $mass_columnValString.$mass_columnString;
if($i < count($mass_merge) - 2)
{
$mass_columnValString = $mass_columnValString."###";
}
}
$columnValString = $mass_columnValString;
}
//end for mass merge
$query = "SELECT * FROM account inner join accountbillads on accountbillads.accountaddressid=account.accountid inner join accountshipads on accountshipads.accountaddressid=account.accountid and account.accountid = '".$_REQUEST['record'] ."'";
//$query = "SELECT * FROM account where accountid = '".$_REQUEST['record'] ."'";
//$result = mysql_query($query);
$result = $adb->query($query);
//$y=mysql_num_fields($result);
$y=$adb->num_fields($result);
for ($x=0; $x<$y; $x++)
{
//$columnNames[$x] = "ACCOUNT_".strtoupper(mysql_field_name($result, $x));
$fld = $adb->field_name($result, $x);
$columnNames[$x] = "ACCOUNT_".strtoupper($fld->name);
}
//condition added for mass merge
if($mass_merge == "")
{
$columnValues = $adb->fetch_array($result);
for ($x=0; $x<$y; $x++)
{
$columnValString[$x] = $columnValues[$x];
}
//$columnValString = implode(",",$columnValString);
//<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>
$sql2 = "select accountscf.* from accountscf inner join account on account.accountid = accountscf.accountid where account.accountid = '".$_REQUEST['record'] ."'";
$result2 = $adb->query($sql2);
$numRows2 = $adb->num_fields($result2);
$custom_field_values = $adb->fetch_array($result2);
for ($i=1; $i<$numRows2; $i++)
{
$custom_values_str[$i] = str_replace(","," ",$custom_field_values[$i]);
}
//<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>
$columnValString = array_merge($columnValString,$custom_values_str);
$columnValString = implode(",",$columnValString);
}
//end condition added for mass merge
//start custom fields names
$sql1 = "select fieldlabel from field where generatedtype=2 and tabid=6";
$result = $adb->query($sql1);
$numRows = $adb->num_rows($result);
for($i=0; $i < $numRows;$i++)
{
$custom_fields[$i] = "ACCOUNT_".strtoupper(str_replace(" ","",$adb->query_result($result,$i,"fieldlabel")));
}
$column_string = array_merge($columnNames,$custom_fields);
//end custom fields names
$columnString = implode(",",$column_string);
//$columnValString = implode(",",$columnValString);
echo"";
?>