Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
view_history_record_details.php
Go to the documentation of this file.
1 <?php
3  function handle(&$params){
5  if ( !@$_GET['history__id'] ){
6  return PEAR::raiseError('No history id supplied', DATAFACE_E_ERROR);
7  }
8  $historyid = $_GET['history__id'];
9  $query =& $app->getQuery();
10  $table = $query['-table'];
11  $r = $app->getRecord();
12 
13  import('Dataface/HistoryTool.php');
14  $ht = new Dataface_HistoryTool();
15  if ( @$_GET['-fromcurrent'] ){
16  $record = $ht->getDiffs($table, $historyid);
17  $record->escapeOutput = false;
18 
19  } else if ( @$_GET['-show_changes'] ){
20  $thisVersion = $ht->getRecordById($table, $historyid);
21  if ( PEAR::isError($thisVersion) ){
22  return $thisVersion;
23  } else if ( !$thisVersion ){
24  return PEAR::raiseError('No history record found', DATAFACE_E_ERROR);
25  }
26  $mdate = $thisVersion->strval("history__modified");
27  //echo "mdate: ".$mdate;
28  $prevDate = date('Y-m-d H:i:s', strtotime('-1 second', strtotime($mdate)));
29  //echo " prevdate: ".$prevDate.' ';
30  $prevVersionId = $ht->getPreviousVersion($r, $prevDate, $thisVersion->val('history__language'), null, true);
31  //echo "Prev: $prevVersionId";
32  if ( !$prevVersionId ){
33  $record = new Dataface_Record($table.'__history', array());
34  } else {
35  $record = $ht->getDiffs($table, $prevVersionId, $historyid);
36 
37  }
38  $record->escapeOutput = false;
39  } else {
40  $record = $ht->getRecordById($table, $historyid);
41  }
42  if ( !$record ) return PEAR::raiseError("No history record for table {$table} with history id {$historyid} could be found", DATAFACE_E_ERROR);
43  if ( PEAR::isError($record) ) return $record;
44 
45  $record->secureDisplay = false;
46  $context = array('history_record'=>&$record);
47  $context['source_record'] = $app->getRecord();
48 
49 
51  $numfields = count($t->fields());
52  $pts = 0;
53  $ppf = array();
54 
55  $fields = $t->fields();
56  $tmp = array();
57  foreach ($fields as $k=>$f){
58  if ( $r->checkPermission('view', array('field'=>$k)) ){
59  $tmp[$k] = $fields[$k];
60  }
61  }
62  $fields = $tmp;
63 
64  $context['fields'] = $fields;
65 
66  foreach ($fields as $field){
67  if ( $t->isText($field['name']) ){
68  $pts+=5;
69  $ppf[$field['name']] = $pts;
70  } else {
71  $pts++;
72  $ppf[$field['name']] = $pts;
73  }
74  }
75 
76  $firstField = null;
77  $threshold = floatval(floatval($pts)/floatval(2));
78  foreach ( $fields as $field){
79  if ( $ppf[$field['name']] >= $threshold ){
80  $firstField = $field['name'];
81  break;
82  }
83  }
84 
85  $context['first_field_second_col'] = $firstField;
86  $context['changes'] = @$_GET['-show_changes'];
87  $context['table'] =& $t;
88  df_display($context, 'Dataface_HistoryRecordDetails.html');
89 
90  }
91 
92 }
93 ?>