Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
ajax_view_record_details.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  */
22  function handle(&$params){
24 
25  $query =& $app->getQuery();
26  $record =& $app->getRecord();
27 
28  if ( !$record ) return PEAR::raiseError("No record could be found that matches the query.", DATAFACE_E_ERROR);
29  if ( PEAR::isError($record) ) return $record;
30 
31  $context = array('record'=>&$record);
32 
33  $t =& $record->_table;
34  $fields = array();
35  foreach ( $t->fields(false,true) as $field){
36  if ( $record->checkPermission('view', array('field'=>$field['name']))){
37  $fields[$field['name']] = $field;
38  }
39  }
40  $numfields = count($fields);
41  $pts = 0;
42  $ppf = array();
43  foreach (array_keys($fields) as $field){
44  if ( $t->isText($field) ){
45  $pts+=5;
46  $ppf[$field] = $pts;
47  } else {
48  $pts++;
49  $ppf[$field] = $pts;
50  }
51  }
52 
53  $firstField = null;
54  $threshold = floatval(floatval($pts)/floatval(2));
55  foreach ( array_keys($fields) as $field){
56  if ( $ppf[$field] >= $threshold ){
57  $firstField = $field;
58  break;
59  }
60  }
61 
62  $context['first_field_second_col'] = $firstField;
63  $context['table'] =& $t;
64  $context['fields'] =& $fields;
65  header('Content-type: text/html; charset='.$app->_conf['oe']);
66  df_display($context, 'Dataface_AjaxRecordDetails.html');
67 
68  }
69 
70 }
71 ?>