Categories | Question details Back To List | ||
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'?>\n'); fwrite($fp, '<tree id='0'>\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'] . ''>'); if ( count($t['subtree']) ) { fwrite($fp, '\n'); createXmlFile($filePath, $t['subtree'], $fp); fwrite($fp, str_repeat(' ', $t['level']) . '</item>\n'); } else { fwrite($fp, '</item>\n'); } } if( $callCount == 1 ) { fwrite($fp, '</tree>\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'?>\n'); fwrite($fp, '<rows parent='0'>\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>\n'); } } if( $callCount == 1 ) { fwrite($fp, '</rows>\n'); |