[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'; |
---|
[497] | 34 | require_once 'codebase/lib/HTML.inc.php'; |
---|
[1] | 35 | |
---|
| 36 | /****************************************************************************** |
---|
| 37 | * CODE CONFIG |
---|
| 38 | *****************************************************************************/ |
---|
| 39 | |
---|
[396] | 40 | // Since we're using the singleton pattern we can instantiate a Version object earlier with custom parameters. |
---|
[457] | 41 | $version =& Version::getInstance($auth); |
---|
[497] | 42 | $version->setParam(array( |
---|
| 43 | // If true, makes an exact comparison of saved vs. live table schemas. If false, just checks that the saved columns are available. |
---|
| 44 | 'db_schema_strict' => false, |
---|
| 45 | )); |
---|
[1] | 46 | |
---|
[20] | 47 | // Query arguments to retain their values between page requests. |
---|
[136] | 48 | $app->carryQuery('record_table'); |
---|
| 49 | $app->carryQuery('record_key'); |
---|
| 50 | $app->carryQuery('record_val'); |
---|
| 51 | $app->carryQuery('version_title'); |
---|
[1] | 52 | |
---|
| 53 | // Titles and navigation header. |
---|
[202] | 54 | $nav->add(_("Versions"), null); |
---|
[535] | 55 | $nav->set('id', 'versions'); |
---|
[1] | 56 | |
---|
[143] | 57 | /******************************************************************** |
---|
| 58 | * MAIN |
---|
| 59 | ********************************************************************/ |
---|
[1] | 60 | |
---|
| 61 | // Request arguments. |
---|
| 62 | $version_id = getFormData('version_id'); |
---|
| 63 | $record_table = getFormData('record_table'); |
---|
| 64 | $record_key = getFormData('record_key'); |
---|
| 65 | $record_val = getFormData('record_val'); |
---|
| 66 | |
---|
| 67 | if ('' == $version_id && ('' == $record_table || '' == $record_key || '' == $record_val)) { |
---|
[136] | 68 | $app->raiseMsg(_("Record not specified for versioning."), MSG_WARNING, __FILE__, __LINE__); |
---|
| 69 | $app->logMsg('Record not specified for versioning.', LOG_WARNING, __FILE__, __LINE__); |
---|
| 70 | $app->dieBoomerangURL(); |
---|
[1] | 71 | } |
---|
| 72 | |
---|
[20] | 73 | if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) { |
---|
[1] | 74 | // We remember which page we came from so we can go back there. |
---|
[136] | 75 | $app->setBoomerangURL($_SERVER['HTTP_REFERER'], 'versions'); |
---|
[1] | 76 | } |
---|
| 77 | |
---|
| 78 | // What action to take. |
---|
| 79 | switch (getFormData('op')) { |
---|
| 80 | |
---|
[502] | 81 | case 'cancel' : |
---|
[535] | 82 | if ($app->validBoomerangURL('versions')) { |
---|
[502] | 83 | // Display boomerang page. |
---|
[535] | 84 | $app->dieBoomerangURL('versions'); |
---|
[502] | 85 | } |
---|
| 86 | // Display default page. |
---|
| 87 | $app->dieURL(false, false); |
---|
[1] | 88 | break; |
---|
| 89 | |
---|
| 90 | case 'view' : |
---|
| 91 | $data = $version->getData($version_id); |
---|
| 92 | $versionrecord = $version->getVerson($version_id); |
---|
[497] | 93 | $nav->add(sprintf(_("%s <small>Version %s (%s)</small>"), $versionrecord['version_title'], $version_id, date(sprintf('%s %s', $app->getParam('date_format'), $app->getParam('time_format')), strtotime($versionrecord['version_datetime'])))); |
---|
[1] | 94 | $main_template = 'versions_view.ihtml'; |
---|
| 95 | break; |
---|
| 96 | |
---|
| 97 | case 'diff' : |
---|
| 98 | $data = $version->getData($version_id); |
---|
| 99 | $versionrecord = $version->getVerson($version_id); |
---|
| 100 | $current = $version->getCurrent($record_table, $record_key, $record_val); |
---|
| 101 | if (serialize($data) == serialize($current)) { |
---|
[497] | 102 | $app->raiseMsg(sprintf(_("Version %s is identical to the current record"), $version_id), MSG_NOTICE, __FILE__, __LINE__); |
---|
[1] | 103 | } |
---|
[497] | 104 | $nav->add(sprintf(_("%s <small>Version %s (%s)</small>"), $versionrecord['version_title'], $version_id, date(sprintf('%s %s', $app->getParam('date_format'), $app->getParam('time_format')), strtotime($versionrecord['version_datetime'])))); |
---|
[1] | 105 | $main_template = 'versions_diff.ihtml'; |
---|
| 106 | break; |
---|
| 107 | |
---|
| 108 | case 'restore' : |
---|
[137] | 109 | if (!isset($lock) || !is_a($lock, 'Lock')) { |
---|
| 110 | $lock =& Lock::getInstance($auth); |
---|
[22] | 111 | } |
---|
[1] | 112 | $lock->select($record_table, $record_key, $record_val); |
---|
| 113 | if ($lock->isLocked() && !$lock->isMine()) { |
---|
| 114 | $lock->dieErrorPage(); |
---|
[21] | 115 | } |
---|
| 116 | |
---|
| 117 | if ($v = $version->restore($version_id)) { |
---|
| 118 | // Create version of this restored record as the "current" version. |
---|
| 119 | $version->create($record_table, $record_key, $record_val, $v['version_title']); |
---|
[141] | 120 | $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] | 121 | $app->dieBoomerangURL('versions', array('break_list_cache'=>'true', false)); |
---|
[1] | 122 | } else { |
---|
[136] | 123 | $app->raiseMsg(_("Version restoration failed."), MSG_ERR, __FILE__, __LINE__); |
---|
| 124 | $app->dieURL($_SERVER['PHP_SELF']); |
---|
[1] | 125 | } |
---|
| 126 | break; |
---|
| 127 | |
---|
| 128 | default : |
---|
| 129 | $versions = $version->getList($record_table, $record_key, $record_val); |
---|
| 130 | if (is_array($versions) && !empty($versions)) { |
---|
[255] | 131 | $_POST['version_title'] = $versions[0]['version_title']; |
---|
[497] | 132 | $nav->add(sprintf(_("%s versions of <em>%s</em>"), sizeof($versions), $versions[0]['version_title'])); |
---|
[1] | 133 | $main_template = 'versions_list.ihtml'; |
---|
| 134 | } else { |
---|
[497] | 135 | $app->raiseMsg(sprintf(_("No saved versions available"), null), MSG_NOTICE, __FILE__, __LINE__); |
---|
[136] | 136 | $app->dieBoomerangURL('versions'); |
---|
[1] | 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | /****************************************************************************** |
---|
| 142 | * TEMPLATE INITIALIZATION |
---|
| 143 | *****************************************************************************/ |
---|
[42] | 144 | |
---|
[1] | 145 | include 'header.ihtml'; |
---|
| 146 | include 'codebase/services/templates/' . $main_template; |
---|
| 147 | include 'footer.ihtml'; |
---|
| 148 | |
---|