function handle(&$params) { $app =& Dataface_Application::getInstance(); if (!@$_GET['history__id']) { return PEAR::raiseError('No history id supplied', DATAFACE_E_ERROR); } $historyid = $_GET['history__id']; $query =& $app->getQuery(); $table = $query['-table']; import('Dataface/HistoryTool.php'); $ht = new Dataface_HistoryTool(); if (@$_GET['-show_changes']) { $record = $ht->getDiffs($table, $historyid); } else { $record = $ht->getRecordById($table, $historyid); } if (!$record) { return PEAR::raiseError("No history record for table {$table} with history id {$historyid} could be found", DATAFACE_E_ERROR); } if (PEAR::isError($record)) { return $record; } $context = array('history_record' => &$record); $context['table_record'] = new Dataface_Record($table, $record->vals()); $t =& Dataface_Table::loadTable($table); $numfields = count($t->fields()); $pts = 0; $ppf = array(); foreach ($t->fields() as $field) { if ($t->isText($field['name'])) { $pts += 5; $ppf[$field['name']] = $pts; } else { $pts++; $ppf[$field['name']] = $pts; } } $firstField = null; $threshold = floatval(floatval($pts) / floatval(2)); foreach ($t->fields() as $field) { if ($ppf[$field['name']] >= $threshold) { $firstField = $field['name']; break; } } $context['first_field_second_col'] = $firstField; $context['changes'] = @$_GET['-show_changes']; $context['table'] =& $t; df_display($context, 'Dataface_HistoryRecordDetails.html'); }
function test_diff() { $this->test_log_record(); $profile =& df_get_record('Profiles', array('id' => 10)); $profile->setValue('description', "Head of this household\nAnd more\nHe is also a great fisherman"); $profile->save(); $ht = new Dataface_HistoryTool(); $ht->logRecord($profile); $diff = $ht->getDiffs('Profiles', 1, 2); $this->assertEquals("Head of <del>the</del><ins>this</ins> household<ins>\nAnd more\nHe is also a great fisherman</ins>\n", $diff->val('description')); $this->assertEquals('', $diff->val('title')); $this->assertEquals('<del>1</del><ins>2</ins> ', $diff->val('history__id')); //print_r($diff->strvals()); $profile->setValue('description', "Head of my household\nAnd more\nHe is also a greater fisherman"); $profile->save(); $ht->logRecord($profile); $diff = $ht->getDiffs('Profiles', 2, 3); $this->assertEquals('Head of <del>this</del><ins>my</ins> household And more He is also a <del>great</del><ins>greater</ins> fisherman ', $diff->val('description')); $diff = $ht->getDiffs('Profiles', 2); $this->assertEquals('Head of <del>this</del><ins>my</ins> household And more He is also a <del>great</del><ins>greater</ins> fisherman ', $diff->val('description')); //print_r($diff->strvals()); //print_r($diff->strvals()); //$res =xf_db_query("select * from `Profiles__history`"); //while ( $row = xf_db_fetch_assoc($res)){ // print_r($row); //} }
function handle(&$params) { $app =& Dataface_Application::getInstance(); if (!@$_GET['history__id']) { return PEAR::raiseError('No history id supplied', DATAFACE_E_ERROR); } $historyid = $_GET['history__id']; $query =& $app->getQuery(); $table = $query['-table']; $r = $app->getRecord(); import('Dataface/HistoryTool.php'); $ht = new Dataface_HistoryTool(); if (@$_GET['-fromcurrent']) { $record = $ht->getDiffs($table, $historyid); $record->escapeOutput = false; } else { if (@$_GET['-show_changes']) { $thisVersion = $ht->getRecordById($table, $historyid); if (PEAR::isError($thisVersion)) { return $thisVersion; } else { if (!$thisVersion) { return PEAR::raiseError('No history record found', DATAFACE_E_ERROR); } } $mdate = $thisVersion->strval("history__modified"); //echo "mdate: ".$mdate; $prevDate = date('Y-m-d H:i:s', strtotime('-1 second', strtotime($mdate))); //echo " prevdate: ".$prevDate.' '; $prevVersionId = $ht->getPreviousVersion($r, $prevDate, $thisVersion->val('history__language'), null, true); //echo "Prev: $prevVersionId"; if (!$prevVersionId) { $record = new Dataface_Record($table . '__history', array()); } else { $record = $ht->getDiffs($table, $prevVersionId, $historyid); } $record->escapeOutput = false; } else { $record = $ht->getRecordById($table, $historyid); } } if (!$record) { return PEAR::raiseError("No history record for table {$table} with history id {$historyid} could be found", DATAFACE_E_ERROR); } if (PEAR::isError($record)) { return $record; } $record->secureDisplay = false; $context = array('history_record' => &$record); $context['source_record'] = $app->getRecord(); $t =& Dataface_Table::loadTable($table); $numfields = count($t->fields()); $pts = 0; $ppf = array(); $fields = $t->fields(); $tmp = array(); foreach ($fields as $k => $f) { if ($r->checkPermission('view', array('field' => $k))) { $tmp[$k] = $fields[$k]; } } $fields = $tmp; $context['fields'] = $fields; foreach ($fields as $field) { if ($t->isText($field['name'])) { $pts += 5; $ppf[$field['name']] = $pts; } else { $pts++; $ppf[$field['name']] = $pts; } } $firstField = null; $threshold = floatval(floatval($pts) / floatval(2)); foreach ($fields as $field) { if ($ppf[$field['name']] >= $threshold) { $firstField = $field['name']; break; } } $context['first_field_second_col'] = $firstField; $context['changes'] = @$_GET['-show_changes']; $context['table'] =& $t; df_display($context, 'Dataface_HistoryRecordDetails.html'); }