requireLogin();
App::sslOn();
require_once 'codebase/lib/RecordVersion.inc.php';
require_once 'codebase/lib/RecordLock.inc.php';
/******************************************************************************
* CODE CONFIG
*****************************************************************************/
$version = RecordVersion::getInstance($GLOBALS['auth']);
// Query arguments to retain their values between page requests.
App::carryQuery('record_table');
App::carryQuery('record_key');
App::carryQuery('record_val');
App::carryQuery('version_title');
// Titles and navigation header.
$nav->addPage(_("Versions"), $_SERVER['PHP_SELF']);
/******************************************************************************
* MAIN
*****************************************************************************/
// Request arguments.
$version_id = getFormData('version_id');
$record_table = getFormData('record_table');
$record_key = getFormData('record_key');
$record_val = getFormData('record_val');
if ('' == $version_id && ('' == $record_table || '' == $record_key || '' == $record_val)) {
App::raiseMsg(_("Record not specified for versioning."), MSG_WARNING, __FILE__, __LINE__);
App::logMsg('Record not specified for versioning.', LOG_WARNING, __FILE__, __LINE__);
App::dieBoomerangURL();
}
if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) {
// We remember which page we came from so we can go back there.
App::setBoomerangURL($_SERVER['HTTP_REFERER'], 'versions');
}
// What action to take.
switch (getFormData('op')) {
case _("Cancel") :
App::dieBoomerangURL('versions', false);
break;
case 'view' :
$data = $version->getData($version_id);
$versionrecord = $version->getVerson($version_id);
$nav->addPage(sprintf(_("View %s version %s (%s)"), $versionrecord['version_title'], $version_id, $versionrecord['version_datetime']));
$main_template = 'versions_view.ihtml';
break;
case 'diff' :
$data = $version->getData($version_id);
$versionrecord = $version->getVerson($version_id);
$current = $version->getCurrent($record_table, $record_key, $record_val);
if (serialize($data) == serialize($current)) {
App::raiseMsg(sprintf(_("Version %s is identical to the current record"), $version_id), MSG_NOTICE, __FILE__, __LINE__);
}
$nav->addPage(sprintf(_("Difference between version %s (%s) and current record."), $version_id, $versionrecord['version_datetime']));
$main_template = 'versions_diff.ihtml';
break;
case 'restore' :
if (!isset($lock) || !is_a($lock, 'RecordLock')) {
$lock =& RecordLock::getInstance($auth);
}
$lock->select($record_table, $record_key, $record_val);
if ($lock->isLocked() && !$lock->isMine()) {
$lock->dieErrorPage();
}
if ($v = $version->restore($version_id)) {
// Create version of this restored record as the "current" version.
$version->create($record_table, $record_key, $record_val, $v['version_title']);
App::raiseMsg(sprintf(_("The record %s has been replaced with %s version %s from %s."), getFormData('version_title'), $v['version_title'], $version_id, $v['version_datetime']), MSG_SUCCESS, __FILE__, __LINE__);
App::dieBoomerangURL('versions', array('break_list_cache'=>'true', false));
} else {
App::raiseMsg(_("Version restoration failed."), MSG_ERR, __FILE__, __LINE__);
App::dieURL($_SERVER['PHP_SELF']);
}
break;
default :
$versions = $version->getList($record_table, $record_key, $record_val);
$_POST['version_title'] = $versions[0]['version_title'];
if (is_array($versions) && !empty($versions)) {
$nav->addPage(sprintf(_("%s versions of record %s"), sizeof($versions), $versions[0]['version_title']));
$main_template = 'versions_list.ihtml';
} else {
App::raiseMsg(sprintf(_("No saved versions available for this record"), null), MSG_NOTICE, __FILE__, __LINE__);
App::dieBoomerangURL('versions');
}
}
/******************************************************************************
* TEMPLATE INITIALIZATION
*****************************************************************************/
include 'header.ihtml';
include 'codebase/services/templates/' . $main_template;
include 'footer.ihtml';
?>