* Copyright 2001-2012 Strangecode, LLC * * This file is part of The Strangecode Codebase. * * The Strangecode Codebase is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your option) * any later version. * * The Strangecode Codebase is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * The Strangecode Codebase. If not, see . */ /** * versions.php */ // require_once dirname(__FILE__) . '/_config.inc.php'; $app->sslOn(); $auth->requireLogin(); require_once 'codebase/lib/Version.inc.php'; require_once 'codebase/lib/Lock.inc.php'; /****************************************************************************** * CODE CONFIG *****************************************************************************/ // Since we're using the singleton pattern we can instantiate a Version object earlier with custom parameters. $version =& Version::getInstance($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->add(_("Versions"), null); /******************************************************************** * 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->add(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->add(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, 'Lock')) { $lock =& Lock::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); if (is_array($versions) && !empty($versions)) { $_POST['version_title'] = $versions[0]['version_title']; $nav->add(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'; ?>