To activate such functionality you need to include dhtmlxscheduler_serialize.js
<script src='codebase/ext/dhtmlxscheduler_serialize.js'></script>
You may use the toXML method to serialize scheduler data to xml string:
var xml = scheduler.toXML(); //xm string
It is also possible to get scheduler events in JSON format. Use toJSON in this case:
var json_string = scheduler.toJSON(); //json string
Warning - method returns json string, not object. If you need an object - use getEvents method
Serialization to iCal string requires toICal method. The next command and both methods, that are described above, can be used at any moment of time.
var ical_string = scheduler.toICal();
Also, there is an external script for iCal import-export operations
The following technique is not applicable for the iCal format.
By default export will include only standard attributes(properties)
If you need to include some custom attributes, you can redefine data_attributes method, in simplest case it will look as
scheduler.data_attributes = function(){ return [ ["id"],["text"],["date_start"],["date_end"], ["custom_attribute"] ]; };
Basically, the method defines the list of attirubute names.
But you can define the formatting function, which describes how attribute data needs being processed before serialization.
It can be useful for dates those need converting before to be placed in XML
scheduler.data_attributes = function(){ return [ ["id"], ["text"], ["start_date",scheduler.templates.xml_format], ["end_date",scheduler.templates.xml_format]]; }
Below technique is not applicable for the iCal format.
If you are using “recurring” extension, you need to define extra attributes, which are used by recurring events
scheduler.data_attributes = function(){ var empty = function(a){ return a||""; } return [["id"], ["text"], ["start_date",scheduler.templates.xml_format], ["end_date",scheduler.templates.xml_format], ["rec_type",empty], ["event_length",empty], ["event_pid",empty]]; }
Serialization allows to implement the simple routine of data saving, which doesn't require DB - data will be stored in XML file.
(1) Firstly, you need to include serialization extension
<script src='codebase/ext/dhtmlxscheduler_serialize.js'></script>
(2) The next step - place hidden form for data saving
<form id="xml_form" action="xml_writer.php" method="post" target="hidden_frame" accept-charset="utf-8"> <input type="hidden" name="data" value="" id="data"> </form>
(3) Then you need to place “Save” button on the page
<input type="button" name="save" value="save" onclick="save()" style="right:300px; width:80px; position:absolute; top:1px;">
function save(){ var form = document.getElementById("xml_form"); form.elements.data.value = scheduler.toXML(); form.submit(); }
(4) on server side, you just need to write the data in an existent file. xml_writer.php could be as follows:
<?php file_put_contents("./data.xml",$_POST["data"]); ?>
the empty data.xml is:
<data></data>
That is all, now scheduler can be loaded from data.xml, pressing “save” button will serialize the current state of the scheduler to xml and save back to the file.
So on next loading the scheduler will load events those have been saved previously.
In the scheduler package you can find ready samples:
If, during data saving, you encounter unwanted data escaping (\” in the saved data) - be sure that “magic_quotes” is disabled in php configuration.