This topic is locked
[SOLVED]

 Export XML via Email

6/19/2017 1:59:26 PM
PHPRunner General questions
S
swanside author

Hi all.

I am looking at trying to automate my project even more. This next step would be when the data is added on the add page, if a check box which is called exported is checked, would it be possible to auto export all the data that has just been added as an xml file? and maybe emailed to a specific email address?

At present we add a job and select it and export as xml, but I would like to automate this function. Would there be a way of doing this please?

This is the sort of XML file we use.

<?xml version="1.0" encoding="UTF-8" standalone="true"?>

-<table>

-<row>

<SiteEmailAddress/>

<SitePhoneNumber/>

<FileNo>EH 1234</FileNo>

<JobNo>1000000</JobNo>

<OrderDate>2017-06-19 00:00:00</OrderDate>

<customerPK>1234</customerPK>

<locationPK>5678</locationPK>

<EngineerId>24</EngineerId>

<JobTypeId>28</JobTypeId>

<CustomerName>OLD LANE HIGH SCHOOL</CustomerName>

<OrderSiteAddress>OLD LANE HIGH SCHOOL</OrderSiteAddress>

<CustomerRef>VERBAL MARK</CustomerRef>

<JobSheet>Basic DTD</JobSheet>

<LoggedBy>BARRY JONES</LoggedBy>

<ContactEmail>barry@heatcon.com</ContactEmail>

<JobDescription>TO ATTEND SITE AS CISTERN PIPE HAS SPLIT AND LEAKING IN BASE 4 GIRLS TOILET IN ROOM RG123</JobDescription>

<PhoneNumber/>

<CustomerEmail/>

</row>

</table>
admin 6/20/2017

Of course this can be done, you just need to write the code that does this job. In AfterAdd event all new record data is stored in $values array.
Here is an article that explains how to export an array to XML file:

https://www.codexworld.com/convert-array-to-xml-in-php/
In regards to sending an email with attachment from PHPRunner:

https://xlinesoft.com/phprunner/docs/runner_mail_function.htm

S
swanside author 6/20/2017

Sergey.

As always, you are a step ahead of me. Thanks for the links and looking forward to the next version.

Cheers

Paul.



Of course this can be done, you just need to write the code that does this job. In AfterAdd event all new record data is stored in $values array.
Here is an article that explains how to export an array to XML file:

https://www.codexworld.com/convert-array-to-xml-in-php/
In regards to sending an email with attachment from PHPRunner:

https://xlinesoft.com/phprunner/docs/runner_mail_function.htm

S
swanside author 6/22/2017

Sorry Guys,

Just looking for an update. I am trying this in the add page, After record added. I just want to try it out with three lines first. After I add this code, I Click on Check syntax and it says its OK so I build my project. When I run the project, I can add the data, but I cant see any information regarding to an XML file?

Any ideas where I have gone wrong please?
Thanks

Paul.

// Check to ensure Exported checkbox is checked

if ($values['Exported']);

//Function to insert CustomerId and LocationId and CustomerRefinto an array called export

$export_array = array(

"total_exports" => 1,

"export" => array(

array(

"CustomerId" => $values['CustomerId'],

"LocationId" => $values['LocationId'],

"CustomerRef" => $values['CustomerRef']

)

)

);
//function defination to convert array to xml

function array_to_xml($array, &$xml_export_info) {

foreach($array as $key => $value) {

if(is_array($value)) {

if(!is_numeric($key)){

$subnode = $xml_export_info->addChild("$key");

array_to_xml($value, $subnode);

}else{

$subnode = $xml_export_info->addChild("item$key");

array_to_xml($value, $subnode);

}

}else {

$xml_export_info->addChild("$key",htmlspecialchars("$value"));

}

}

}
//creating object of SimpleXMLElement

$xml_export_info = new SimpleXMLElement("<?xml version=\"1.0\"?><user_info></user_info>");
//function call to convert array to xml

array_to_xml($export_array,$xml_export_info);
//saving generated xml file

$xml_file = $xml_export_info->asXML('export.xml');
//success and error message based on xml creation

if($xml_file){

echo 'XML file have been generated successfully.';

}else{

echo 'XML file generation error.';

}