[1] | 1 | <?php |
---|
| 2 | /** |
---|
[362] | 3 | * The Strangecode Codebase - a general application development framework for PHP |
---|
| 4 | * For details visit the project site: <http://trac.strangecode.com/codebase/> |
---|
[396] | 5 | * Copyright 2001-2012 Strangecode, LLC |
---|
[457] | 6 | * |
---|
[362] | 7 | * This file is part of The Strangecode Codebase. |
---|
| 8 | * |
---|
| 9 | * The Strangecode Codebase is free software: you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License as published by the |
---|
| 11 | * Free Software Foundation, either version 3 of the License, or (at your option) |
---|
| 12 | * any later version. |
---|
[457] | 13 | * |
---|
[362] | 14 | * The Strangecode Codebase is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
| 17 | * details. |
---|
[457] | 18 | * |
---|
[362] | 19 | * You should have received a copy of the GNU General Public License along with |
---|
| 20 | * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | /** |
---|
[42] | 24 | * versions.php |
---|
[1] | 25 | */ |
---|
| 26 | |
---|
| 27 | // require_once dirname(__FILE__) . '/_config.inc.php'; |
---|
| 28 | |
---|
[457] | 29 | $app->sslOn(); |
---|
[1] | 30 | $auth->requireLogin(); |
---|
| 31 | |
---|
[137] | 32 | require_once 'codebase/lib/Version.inc.php'; |
---|
| 33 | require_once 'codebase/lib/Lock.inc.php'; |
---|
[1] | 34 | |
---|
| 35 | /****************************************************************************** |
---|
| 36 | * CODE CONFIG |
---|
| 37 | *****************************************************************************/ |
---|
| 38 | |
---|
[396] | 39 | // Since we're using the singleton pattern we can instantiate a Version object earlier with custom parameters. |
---|
[457] | 40 | $version =& Version::getInstance($auth); |
---|
[1] | 41 | |
---|
[20] | 42 | // Query arguments to retain their values between page requests. |
---|
[136] | 43 | $app->carryQuery('record_table'); |
---|
| 44 | $app->carryQuery('record_key'); |
---|
| 45 | $app->carryQuery('record_val'); |
---|
| 46 | $app->carryQuery('version_title'); |
---|
[1] | 47 | |
---|
| 48 | // Titles and navigation header. |
---|
[202] | 49 | $nav->add(_("Versions"), null); |
---|
[1] | 50 | |
---|
[143] | 51 | /******************************************************************** |
---|
| 52 | * MAIN |
---|
| 53 | ********************************************************************/ |
---|
[1] | 54 | |
---|
| 55 | // Request arguments. |
---|
| 56 | $version_id = getFormData('version_id'); |
---|
| 57 | $record_table = getFormData('record_table'); |
---|
| 58 | $record_key = getFormData('record_key'); |
---|
| 59 | $record_val = getFormData('record_val'); |
---|
| 60 | |
---|
| 61 | if ('' == $version_id && ('' == $record_table || '' == $record_key || '' == $record_val)) { |
---|
[136] | 62 | $app->raiseMsg(_("Record not specified for versioning."), MSG_WARNING, __FILE__, __LINE__); |
---|
| 63 | $app->logMsg('Record not specified for versioning.', LOG_WARNING, __FILE__, __LINE__); |
---|
| 64 | $app->dieBoomerangURL(); |
---|
[1] | 65 | } |
---|
| 66 | |
---|
[20] | 67 | if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) { |
---|
[1] | 68 | // We remember which page we came from so we can go back there. |
---|
[136] | 69 | $app->setBoomerangURL($_SERVER['HTTP_REFERER'], 'versions'); |
---|
[1] | 70 | } |
---|
| 71 | |
---|
| 72 | // What action to take. |
---|
| 73 | switch (getFormData('op')) { |
---|
| 74 | |
---|
| 75 | case _("Cancel") : |
---|
[136] | 76 | $app->dieBoomerangURL('versions', false); |
---|
[1] | 77 | break; |
---|
| 78 | |
---|
| 79 | case 'view' : |
---|
| 80 | $data = $version->getData($version_id); |
---|
| 81 | $versionrecord = $version->getVerson($version_id); |
---|
[202] | 82 | $nav->add(sprintf(_("View <em>%s</em> version %s (%s)"), $versionrecord['version_title'], $version_id, $versionrecord['version_datetime'])); |
---|
[1] | 83 | $main_template = 'versions_view.ihtml'; |
---|
| 84 | break; |
---|
| 85 | |
---|
| 86 | case 'diff' : |
---|
| 87 | $data = $version->getData($version_id); |
---|
| 88 | $versionrecord = $version->getVerson($version_id); |
---|
| 89 | $current = $version->getCurrent($record_table, $record_key, $record_val); |
---|
| 90 | if (serialize($data) == serialize($current)) { |
---|
[141] | 91 | $app->raiseMsg(sprintf(_("Version <em>%s</em> is identical to the current record"), $version_id), MSG_NOTICE, __FILE__, __LINE__); |
---|
[1] | 92 | } |
---|
[202] | 93 | $nav->add(sprintf(_("Difference between version %s (%s) and current record."), $version_id, $versionrecord['version_datetime'])); |
---|
[1] | 94 | $main_template = 'versions_diff.ihtml'; |
---|
| 95 | break; |
---|
| 96 | |
---|
| 97 | case 'restore' : |
---|
[137] | 98 | if (!isset($lock) || !is_a($lock, 'Lock')) { |
---|
| 99 | $lock =& Lock::getInstance($auth); |
---|
[22] | 100 | } |
---|
[1] | 101 | $lock->select($record_table, $record_key, $record_val); |
---|
| 102 | if ($lock->isLocked() && !$lock->isMine()) { |
---|
| 103 | $lock->dieErrorPage(); |
---|
[21] | 104 | } |
---|
| 105 | |
---|
| 106 | if ($v = $version->restore($version_id)) { |
---|
| 107 | // Create version of this restored record as the "current" version. |
---|
| 108 | $version->create($record_table, $record_key, $record_val, $v['version_title']); |
---|
[141] | 109 | $app->raiseMsg(sprintf(_("The record <em>%s</em> has been replaced with <em>%s</em> version <em>%s</em> from <em>%s</em>."), getFormData('version_title'), $v['version_title'], $version_id, $v['version_datetime']), MSG_SUCCESS, __FILE__, __LINE__); |
---|
[136] | 110 | $app->dieBoomerangURL('versions', array('break_list_cache'=>'true', false)); |
---|
[1] | 111 | } else { |
---|
[136] | 112 | $app->raiseMsg(_("Version restoration failed."), MSG_ERR, __FILE__, __LINE__); |
---|
| 113 | $app->dieURL($_SERVER['PHP_SELF']); |
---|
[1] | 114 | } |
---|
| 115 | break; |
---|
| 116 | |
---|
| 117 | default : |
---|
| 118 | $versions = $version->getList($record_table, $record_key, $record_val); |
---|
| 119 | if (is_array($versions) && !empty($versions)) { |
---|
[255] | 120 | $_POST['version_title'] = $versions[0]['version_title']; |
---|
[202] | 121 | $nav->add(sprintf(_("%s versions of record <em>%s</em>"), sizeof($versions), $versions[0]['version_title'])); |
---|
[1] | 122 | $main_template = 'versions_list.ihtml'; |
---|
| 123 | } else { |
---|
[136] | 124 | $app->raiseMsg(sprintf(_("No saved versions available for this record"), null), MSG_NOTICE, __FILE__, __LINE__); |
---|
| 125 | $app->dieBoomerangURL('versions'); |
---|
[1] | 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | /****************************************************************************** |
---|
| 131 | * TEMPLATE INITIALIZATION |
---|
| 132 | *****************************************************************************/ |
---|
[42] | 133 | |
---|
[1] | 134 | include 'header.ihtml'; |
---|
| 135 | include 'codebase/services/templates/' . $main_template; |
---|
| 136 | include 'footer.ihtml'; |
---|
| 137 | |
---|