recover($code); } //DB_DataObject::debugLevel(1); $b = DB_DataObject::factory('builder'); if (!empty($_REQUEST['id'])) { if (!$b->get($_REQUEST['id'])) { die("Invalid URL"); } } if (!empty($code)) { if (!$b->get('module', $code)) { die("Invalid URL"); } } if (!$b->id) { die("Invalid URL"); } $json = json_decode($b->json); //echo '
';print_r($b->json);exit;
        $out  = $this->toJSFile($json, $b->json);
     
        if (!empty($code)) {
            header('Content-type: application/javascript');
            echo $out;
            exit;
        }
        
        echo "
";
        //print_r($json);
        echo htmlspecialchars($out);
        
       
        
        exit; 
        
    }
    
    
    function recover($code)
    {
        if (!$this->getAuthUser()) {
            $this->jerr("invalid");
        }
        // fixme!!!!
        
        $fn = $this->rootDir .'/Pman/' . $code.'.js';
        
        list($app, $mod) = explode('/', $code);
        
        if (!file_exists($fn)) {
            $this->jerr("file does not exist.:" . $fn);
        }
        $data = file_get_contents($fn);
        preg_match("#/*\n--SOURCE--\n([^\*]+)#m", $data,$matches);
       // echo "
";print_R($matches);
        $base = $matches[1];
        $str = bzdecompress( base64_decode($base));
        $js = json_decode($str);
        //echo "
";print_R($str);
         $b = DB_DataObject::factory('builder');
        $b->app = $app;
        $b->module = $mod;
        $b->btype = 'FORM';
        $b->name= $js->name;
        if (!$b->find(true)) {
            $b->insert();
        }
        echo "
" . htmlspecialchars( print_r($b, true));
        $b->json = $str;
        $b->update();
        $this->jok("DONE");
        exit;
        
        
        
        
    }
    
    
    function mungePropsObj($obj)
    {
        if (isset($obj->items)) {
            $items = array();
            
            // look for *prop...
            
            foreach($obj->items as $o) {
                if (!empty($o->{'*prop'})) {
                    $pn = $o->{'*prop'};
                    unset($o->{'*prop'});
                    $this->mungePropsObj($o);
                    
                   
                    
                    $obj->$pn = $o;
                    if (isset($o->xtype) &&  $o->xtype == 'Array') {
                        if (empty($o->items)) {
                            unset($obj->$pn);
                            continue;
                        }
                        $obj->$pn = $o->items;
                    }
                    
                    
                    continue;
                }
                
                // otherwise is a standard item..
                $this->mungePropsObj($o);
                
                 //if ($o->xtype == 'GridField') {
                 //       continue;
                 //   }
                $items[] = $o;
            }
            
            $obj->items = $items;
            if (empty($items)) {
                unset($obj->items);
            }
        }
        if (!empty($obj->xtype) && ($obj->xtype[0] == '*')) {
            unset($obj->xtype);
        }
        
        
    }
    
    function jsHead()
    {
        return array(
            "//