Image Caption

Monday, March 18, 2013

Soap response to php array


//Php Explode is best way to convert the soap response to PHP array

function soaptoarray($response)
{

$search  = array('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"','<soapenv:Header/','<soapenv:Body','</', '<');
$replace = array(' ',' ',' ','@end@', '*start*');
$customer=str_replace($search, $replace, $response);
$soapres =explode('*start*',$customer);

foreach($soapres as $key=>$value)
{
$res[$key]=$value;
$temp=explode('@end@',$value);
$tempval=explode('>',$temp[0]);
$tmp=explode("State",$tempval[0]);
}

$resp{$tempval[0]}=$tempval[1];

}

return $resp;
}


//Output php array similar to:


Array
(
    [ ] =>  
    [p711:getDeviceResponse xmlns:p711="http://provision.xbridge.com"] => 
    [getDeviceResult] => 
    [Status Code="0" Message="Done"/] => 
    [Device Id="B0112121" Phone="12312312331" Serial="8901410423121235279"] => 
    [DeviceStatus] => Deactivated
    [State Code="0" Name="Deactivated"/] => 
    [Network Id="1" Name="AT&T" Type="Gold"/] => 
    [Customer] => 00001238
    [Contract Description="FRED SEIFU" Id="43124" Name="FREDS121"/] => 
    [LLI] => B011218
    [APN] => gp102.mo122.net
    [ICCID] => 89022103423295536629
    [MSISDN] => 512233212
    [IMSI] => 310423343553527
    [PIN1] => 1111
    [PUK1] => 412129385
    [PIN2] => 2222
    [PUK2] => 2222
)



Thursday, February 14, 2013

Joomla mass email with attachments [Demo Code]


Step: 1 Create the form 

<form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">
 <input type="text"   name="emailid" id="emailid"  />
 <input type="text"   name="subject" id="subject"  />
 <input type="text"   name="message" id="message"  />
 <input type="file"   name="attachment" id="attachment"  />
</form>

Step: 2 Get the form value and Call the mail function

$recipient  = JRequest::getVar('emailid', '', 'post', 'string', JREQUEST_ALLOWRAW);
$subject  = JRequest::getVar('subject', '', 'post', 'string', JREQUEST_ALLOWRAW);
$body  = JRequest::getVar('message', '', 'post', 'string', JREQUEST_ALLOWRAW);
$attachment = JRequest::getVar('attachment', null, 'files', 'array');
$attachmentname=$attachment[name];
jimport( 'joomla.utilities.utility' );
JUtility::sendMail($from, $fromname, $recipient, $subject, $body, $mode=0, $cc=null, $bcc=null, $attachment, $attachmentname, $replyto=null, $replytoname=null);


Step: 3 Replace the function "addAttachment" in libraries/joomla/mail.php

function addAttachment($attachment, $name = '')
{
// If the file attachments is an aray, add each file... otherwise just add the one
if (isset ($attachment))
{
if (is_array($attachment)) {
foreach ($attachment as $file) {
parent::AddAttachment($file, $name);
}
}
else
{
parent::AddAttachment($attachment, $name);
}
}
}

Step: 4 Replace the below code in ( libraries\joomla\utilities\utility.php ) line 44

function sendMail($from, $fromname, $recipient, $subject, $body, $mode=0, $cc=null, $bcc=null, $attachment=null,$attachmentname, $replyto=null, $replytoname=null )