Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by andreea on Apr 24, 2008 08:20
open dhtmlx forum
I have this function to create a xml for a tree


function createXmlFile($filePath, $tree=array(), $fp='', $resetCount=0) {
    static $callCount = 0;
    if ( $resetCount ) {
        $callCount = 0;
    }
    $callCount++;

    if( $callCount == 1 ) {
        $fp = fopen($filePath, 'w+');
        fwrite($fp, '<?xml version='1.0' encoding='utf-8'?&gt;\n');
        fwrite($fp, '<tree id='0'&gt;\n');
    }

    foreach ($tree AS $t) {
        fwrite($fp, str_repeat(' ', $t['level']) . '<item ' . ($t['checked'] ? ' checked='1' open='1'' : '') .' '.($t['value'] ? ' value=''.$t['value'].'' ' : '').'  '. ' text='' . $t['name'].' '.($t[value]?' ='.$t[value]:''). '' id='' . $t['id'] . ''  im0='' . $t['im0'] . ''  im1='' . $t['im1'] . '' im2='' . $t['im2'] . ''&gt;');
        if ( count($t['subtree']) ) {
            fwrite($fp, '\n');
            createXmlFile($filePath, $t['subtree'], $fp);
            fwrite($fp, str_repeat(' ', $t['level']) . '</item&gt;\n');
        }
        else {
            fwrite($fp, '</item&gt;\n');
        }
    }

    if( $callCount == 1 ) {
        fwrite($fp, '</tree&gt;\n');
        chmod($filePath, 0766);
        fclose($fp);
    }

    $callCount--;
}

I have to turn this function into a function  that will create a tree grid
can you help me ?
Answer posted by Support on Apr 25, 2008 04:04
...
  if( $callCount == 1 ) {
        $fp = fopen($filePath, 'w+');
        fwrite($fp, '<?xml version='1.0' encoding='utf-8'?&gt;\n');
        fwrite($fp, '<rows parent='0'&gt;\n');
    }
...
    foreach ($tree AS $t) {
        fwrite($fp, str_repeat(' ', $t['level']) . '<row' . ($t['checked'] ? ' checked='1' open='1'' : '') .' '.($t['value'] ? ' value=''.$t['value'].'' ' : '').'  '. ' id='' . $t['id'] . ''  image='' . $t['im0'] . ' >');
        fwrite($fp, str_repeat(' ', $t['level']) . '<cell>'.$t['name'].'</cell>');
        if ( count($t['subtree']) ) {
...
        else {
            fwrite($fp, '</row&gt;\n');
        }
    }

    if( $callCount == 1 ) {
        fwrite($fp, '</rows&gt;\n');