Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
RecordBrowser_lookup_single.php
Go to the documentation of this file.
1 <?php
2 /*-------------------------------------------------------------------------------
3  * Xataface Web Application Framework
4  * Copyright (C) 2005-2009 Web Lite Solutions Corp (shannah@sfu.ca)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *-------------------------------------------------------------------------------
20  */
49  function handle(&$params){
50  session_write_close();
51  header('Connection: close');
53 
54  $query =& $app->getQuery();
55  $table = $query['-table'];
56  $ids = $query['-id'];
57  $rec = null;
58  if ( !is_array($ids) ) $ids = array($ids);
59  $out = array();
60  foreach ($ids as $id){
61  if ( preg_match('/^'.preg_quote($table,'/').'\?/', $id) ){
62  // This is a record id
63  $rec = df_get_record_by_id($id);
64 
65  } else if ( strpos($id, '=') !== false ){
66  parse_str($id, $q);
67  $rec = df_get_record($table, $q);
68  } else {
69  $keys = array_keys(Dataface_Table::loadTable($table)->keys());
70  $q = array($keys[0] =>'='. $id);
71  $rec = df_get_record($table, $q);
72 
73  }
74 
75  if ( $rec ){
76  header('Content-type: text/html; charset='.$app->_conf['oe']);
77  if ( $rec->checkPermission('view') ){
78  switch (strval(@$query['-text'])){
79  case '':
80  case '__title__':
81 
82  $out[] = $rec->getTitle();
83  break;
84  case '__json__':
85  //header('Content-type: text/json; charset='.$app->_conf['oe']);
86  $out[] = array_merge($rec->strvals(), array('__id__'=>$rec->getId()));
87  break;
88  default:
89  $out[] = $rec->display($query['-text']);
90  break;
91  }
92  } else {
93  return Dataface_Error::permissionDenied('You require view permission to access this record');
94  }
95 
96  }
97  }
98 
99  if ( count($out) == 0 ) $out[] = "";
100 
101  if ( count($out) < 2 and !is_array($query['-id']) and @$query['-return-type'] != 'array' ){
102  if ( @$query['-text'] == '__json__' ){
103  header("Content-type: application/json; charset=".$app->_conf['oe']);
104  echo json_encode($out[0]);
105  } else {
106  echo $out[0];
107  }
108  } else {
109  header("Content-type: application/json; charset=".$app->_conf['oe']);
110  echo json_encode($out);
111  }
112  exit;
113  }
114 }