Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by ragsna on Jun 05, 2009 07:23
open dhtmlx forum
Change of xml content by using php

Hi all,
I currently have following problem:
I want to load the xml file for the grid and change some xml entries depending on user settings.
This means, I have a user identified who is loading the grid and depending on this user, for example of his last visit time, which is stored in a sql database, I want to make some entries of the grid in red color.
If another user, with another visiting time loads the grid, other entries would be colored.

I was tinking of loading the xml into a php "variable" and then make the modificiation neccessary of the "xml variable content". After that I want to handover this xml variable as input for the grid.

Is that possible or is there another more easier way to establish this kind of user depended grid view?
Tnx
--
ragsna
Answer posted by Support on Jun 05, 2009 07:28
Are you storing data of grid as static XML or building it form database ?
I first case the only way it to load and modify XML on the fly , you can use

grid.load("some.php")

where some.php
 - read xml file |
 - modify it in necessary way
 - echo modified xml

as result grid will loaded modified data. 

If you are loading data from DB  - you can just generated XML with necessary styling assigned and output it to client side in the same manner 
( by the way, you can look at connectors lib - http://dhtmlx.com/docs/products/dhtmlxConnector/index.shtml )

Answer posted by ragsna on Jun 05, 2009 08:11
Hi,
thanks for your quick reply.
I'm storing the data in a static xml file.
I will try your hint by loading it with "some.php" :)
--
ragsna

Answer posted by Support on Jun 05, 2009 08:15
Be sure to have next order of commands in PHP file

header("Content-type:text/xml"); //this line is mandatory!
echo $processed_data;
Answer posted on Jun 05, 2009 08:41
Hi again,
yes, simple loading like this

$filename = 'news.xml';
$data = file_get_contents($filename,'r');
header("Content-type:text/xml");
echo $data;

is working now.

Unfortunatly I dont see the possibility to really address direct an element, because they are all called "cell".
My xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row id="2543">
<cell><![CDATA[<img src="img/dotb.png">]]></cell>
<cell><![CDATA[<strong>KP2YL &amp; KP2HC</strong>]]></cell>
<cell>FK77</cell>
<cell><![CDATA[<font style="FONT: 10px Arial, Verdana;">2009-06-01<br>2009-06-30</font>]]></cell>
<cell>HF-50</cell>
<cell>MISC</cell>
<cell>DXP</cell>
<cell></cell>
<cell><![CDATA[<font style="FONT: 10px Arial, Verdana;">2009-05-23<br>08:59 UTC</font>]]></cell>
</row>
....

What I want to do now, is that the cell
<cell><![CDATA[<font style="FONT: 10px Arial, Verdana;">2009-05-23<br>08:59 UTC</font>]]></cell>
gets another font attribute if the date in this cell is later than a specific time.

Or do I need to use a function like "simplexml_load_file" or something like this?
Any idea?
Answer posted by Support on Jun 05, 2009 09:12
If you know, exact text of the cell you can use strreplace or preg_replace to change original value of strings to another one.
If exact text unknown - you will need to parse XML ( simpleXML or XMLDom ) and use XPath to locate and replace necessary XML element
Answer posted by ragsna on Jun 05, 2009 11:05
Finally many thanks for your great support!
I did it the way you supposed. Working fine now! :)

--
ragsna

* Thread Closed *