cli) { return true; } return parent::getAuth(); } function get($flhead_id) { if (empty($flhead_id)) { print_r(json_decode( file_get_contents('http://localhost/dragon/hk.php/Roo/flhead?_columns=flhead_id,flhead_name'))); $this->jerr("pick an available report"); } $this->transObj = DB_DataObject::Factory('gltrans'); $this->transObj->query('BEGIN'); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError')); // sandobx or live??? $url = 'http://localhost/dragon/hk.php/Roo/Flhead?flhead_id='.$flhead_id.'&_to_json=1'; $res = json_decode(file_get_contents($url),true); if(count($res['data']) < 1) { $this->jerr('no data found'); } //$res['data']['flhead_name'] = 'TESTING'; $flhead = DB_DataObject::factory('flhead'); if($flhead->get('flhead_name' , $res['data']['flhead_name'])){ $this->jerr('flhead already exists'); } $flhead->setFrom($res['data']); $flhead->insert(); if(!$flhead->pid()){ $this->jerr('error occur on insert flhead'); } if(!count($res['data']['groups'])){ $this->jerr('no groups found'); } $grp = $res['data']['groups']; $this->walkgrp($grp, $flhead->pid()); if(count($res['data']['col'])){ $this->walkcol($res['data']['col'], $flhead->pid()); } $this->transObj->query('COMMIT'); exit; } function walkgrp($grp, $hid, $pargrp = '-1') { foreach($grp as $g){ $g['flgrp_flhead_id'] = $hid; if($g['flgrp_flgrp_id'] > 0){ // get and parent $g['flgrp_flgrp_id'] = $pargrp; } $flgrp = DB_DataObject::factory('flgrp'); $flgrp->setFrom($g); $flgrp->insert(); if(!$flgrp->pid()){ $this->jerr('error occur on insert group : ' . $g['flgrp_name']); } if(count($g['items'])){ $this->walkitem($g['items'], $hid, $flgrp->pid()); } if(count($g['groups'])){ $this->walkgrp($g['groups'], $hid, $flgrp->pid()); } } } function walkitem($item, $hid, $gid) { foreach($item as $i){ $i['flitem_flhead_id'] = $hid; $i['flitem_flgrp_id'] = $gid; $flitem = DB_DataObject::factory('flitem'); $flitem->setFrom($i); $flitem->insert(); } } function walkcol($col, $hid) { foreach($col as $c){ if(!count($c['report'])){ $this->jerr('Missing report details'); } $report = DB_DataObject::factory('report'); if(!$report->get('report_name', $c['report']['report_name'])){ $report->setFrom($c['report']); $report->insert(); } if(!$report->pid()){ $this->jerr('error occur on insert report : ' . $c['report']['report_name']); } $c['flcol_flhead_id'] = $hid; $c['flcol_report_id'] = $report->pid(); $flcol = DB_DataObject::factory('flcol'); $flcol->setFrom($c); $flcol->insert(); } } }