Xataface 2.0
Xataface Application Framework
actions/RecordBrowser_lookup_single.php
Go to the documentation of this file.
00001 <?php
00002 /*-------------------------------------------------------------------------------
00003  * Xataface Web Application Framework
00004  * Copyright (C) 2005-2009 Web Lite Solutions Corp (shannah@sfu.ca)
00005  * 
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * 
00011  * This program 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
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  *-------------------------------------------------------------------------------
00020  */
00048 class dataface_actions_RecordBrowser_lookup_single {
00049         function handle(&$params){
00050                 session_write_close();
00051                 header('Connection: close');
00052                 $app =& Dataface_Application::getInstance();
00053                 
00054                 $query =& $app->getQuery();
00055                 $table = $query['-table'];
00056                 $ids = $query['-id'];
00057                 $rec = null;
00058                 if ( !is_array($ids) ) $ids = array($ids);
00059                 $out = array();
00060                 foreach ($ids as $id){
00061                         if ( preg_match('/^'.preg_quote($table,'/').'\?/', $id) ){
00062                                 // This is a record id
00063                                 $rec = df_get_record_by_id($id);
00064                                 
00065                         } else if ( strpos($id, '=') !== false ){
00066                                 parse_str($id, $q);
00067                                 $rec = df_get_record($table, $q);
00068                         } else {
00069                                 $keys = array_keys(Dataface_Table::loadTable($table)->keys());
00070                                 $q = array($keys[0] =>'='. $id);
00071                                 $rec = df_get_record($table, $q);
00072                                 
00073                         }
00074                         
00075                         if ( $rec ){
00076                                 header('Content-type: text/html; charset='.$app->_conf['oe']);
00077                                 if ( $rec->checkPermission('view') ){
00078                                         switch (strval(@$query['-text'])){
00079                                                 case '':
00080                                                 case '__title__':
00081                                         
00082                                                         $out[] = $rec->getTitle();
00083                                                         break;
00084                                                 case '__json__':
00085                                                         //header('Content-type: text/json; charset='.$app->_conf['oe']);
00086                                                         $out[] = array_merge($rec->strvals(), array('__id__'=>$rec->getId()));
00087                                                         break;
00088                                                 default:
00089                                                         $out[] = $rec->display($query['-text']);
00090                                                         break;
00091                                         }
00092                                 } else {
00093                                         return Dataface_Error::permissionDenied('You require view permission to access this record');
00094                                 }
00095                                 
00096                         }
00097                 }
00098                 
00099                 if ( count($out) < 2 and !is_array($query['-id']) and @$query['-return-type'] != 'array' ){
00100                         if ( @$query['-text'] == '__json__' ){
00101                                 header("Content-type: text/json; charset=".$app->_conf['oe']);
00102                                 echo json_encode($out[0]);
00103                         } else {
00104                                 echo $out[0];
00105                         }
00106                 } else {
00107                         header("Content-type: text/json; charset=".$app->_conf['oe']);
00108                         echo json_encode($out);
00109                 }
00110                 exit;
00111         }
00112 }
 All Data Structures Namespaces Files Functions Variables Enumerations