Xataface HTML Reports Module 0.2
HTML Reports Module for Xataface
|
00001 <?php 00002 /* 00003 * Xataface HTML Reports Module 00004 * Copyright (C) 2011 Steve Hannah <steve@weblite.ca> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public 00017 * License along with this library; if not, write to the 00018 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 */ 00084 class actions_htmlreports_schemabrowser_preview_row { 00085 function handle($params){ 00086 00087 $app = Dataface_Application::getInstance(); 00088 try { 00089 $record = $app->getRecord(); 00090 00091 if ( !$record ){ 00092 throw new Exception("No record found.", 404); 00093 00094 } 00095 00096 if (!$record->checkPermission('view') or !$record->checkPermission('export_json') ){ 00097 throw new Exception("You don't have permission to perform this function.", 400); 00098 } 00099 00100 $out = array(); 00101 $table = $record->table(); 00102 foreach ($table->fields(false, true) as $fld){ 00103 $out['{$'.$fld['name'].'}'] = $record->htmlValue($fld['name']); 00104 } 00105 00106 foreach ($table->delegateFields() as $fld){ 00107 $out['{$'.$fld['name'].'}'] = $record->htmlValue($fld['name']); 00108 } 00109 00110 foreach ($table->relationships() as $rname=>$r){ 00111 foreach ($r->fields(true) as $fullField){ 00112 $fld = $r->getField($fullField); 00113 $fldPath = $rname.'.'.$fld['name']; 00114 //echo $fldPath; 00115 $out['{$'.$fldPath.'}'] = $record->htmlValue($fldPath); 00116 } 00117 } 00118 00119 $this->out(array( 00120 'code'=>200, 00121 'values'=>$out 00122 )); 00123 exit; 00124 00125 00126 } catch (Exception $ex){ 00127 $this->out(array( 00128 'code'=>$ex->getCode(), 00129 'message'=>$ex->getMessage() 00130 )); 00131 exit; 00132 00133 } 00134 00135 00136 00137 00138 00139 } 00140 00141 function out($params){ 00142 header('Content-type:text/json; charset="'.Dataface_Application::getInstance()->_conf['oe'].'"'); 00143 echo json_encode($params); 00144 } 00145 }