Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
RecordBrowser_data.php
Go to the documentation of this file.
1 <?php
2 /*-------------------------------------------------------------------------------
3  * Xataface Web Application Framework
4  * Copyright (C) 2005-2008 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  */
69  function handle(&$params){
71  //$out = array();
72  $query =& $app->getQuery();
73  $records = df_get_records_array($query['-table'], $query);
74  header("Content-type: text/html; charset=".$app->_conf['oe']);
75  echo '<option value="">(None)</option>'."\n";
76  foreach ($records as $record){
77 
78  // First lets get the value that we are using for this option
79  $value = null;
80  if ( @$query['-value'] == '__id__' ){
81  // Use the record id as the value
82  $value = $record->getId();
83  } else if ( @$query['-value'] ){
84  // We have an explicitly specified column to use as the key.
85  $value = $record->val($query['-value']);
86 
87  } else if ( count($record->_table->keys()) > 1 ){
88  // This record has a compound key and no value column was specified
89  // so we use the record id.
90  $value = $record->getId();
91  } else {
92  // This record has a single key column so we return its value
93  $tkeys = $record->_table->keys();
94  $tkeysKeys = array_keys($tkeys);
95  $firstKey = reset($tkeysKeys);
96  $value = $record->val($firstKey);
97 
98  }
99 
100  // Now let's get the text that we are using for this option
101  $text = null;
102  switch (strval(@$query['-text'])){
103  case '':
104  case '__title__':
105  $text = $record->getTitle();
106  break;
107  default:
108  $text = $record->display($query['-text']);
109  break;
110 
111  }
112  echo '<option value="'.htmlspecialchars($value).'">'.htmlspecialchars($text).'</option>'."\n";
113 
114  }
115  exit;
116 
117 
118  }
119 }