1 | <?php |
---|
2 | /** |
---|
3 | * The Strangecode Codebase - a general application development framework for PHP |
---|
4 | * For details visit the project site: <http://trac.strangecode.com/codebase/> |
---|
5 | * Copyright 2001-2009 Strangecode Internet Consultancy |
---|
6 | * |
---|
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. |
---|
13 | * |
---|
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. |
---|
18 | * |
---|
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 | /** |
---|
24 | * versions.php |
---|
25 | */ |
---|
26 | |
---|
27 | // require_once dirname(__FILE__) . '/_config.inc.php'; |
---|
28 | |
---|
29 | $auth->requireLogin(); |
---|
30 | $app->sslOn(); |
---|
31 | |
---|
32 | require_once 'codebase/lib/Version.inc.php'; |
---|
33 | require_once 'codebase/lib/Lock.inc.php'; |
---|
34 | |
---|
35 | /****************************************************************************** |
---|
36 | * CODE CONFIG |
---|
37 | *****************************************************************************/ |
---|
38 | |
---|
39 | $version = Version::getInstance($auth); |
---|
40 | |
---|
41 | // Query arguments to retain their values between page requests. |
---|
42 | $app->carryQuery('record_table'); |
---|
43 | $app->carryQuery('record_key'); |
---|
44 | $app->carryQuery('record_val'); |
---|
45 | $app->carryQuery('version_title'); |
---|
46 | |
---|
47 | // Titles and navigation header. |
---|
48 | $nav->add(_("Versions"), null); |
---|
49 | |
---|
50 | /******************************************************************** |
---|
51 | * MAIN |
---|
52 | ********************************************************************/ |
---|
53 | |
---|
54 | // Request arguments. |
---|
55 | $version_id = getFormData('version_id'); |
---|
56 | $record_table = getFormData('record_table'); |
---|
57 | $record_key = getFormData('record_key'); |
---|
58 | $record_val = getFormData('record_val'); |
---|
59 | |
---|
60 | if ('' == $version_id && ('' == $record_table || '' == $record_key || '' == $record_val)) { |
---|
61 | $app->raiseMsg(_("Record not specified for versioning."), MSG_WARNING, __FILE__, __LINE__); |
---|
62 | $app->logMsg('Record not specified for versioning.', LOG_WARNING, __FILE__, __LINE__); |
---|
63 | $app->dieBoomerangURL(); |
---|
64 | } |
---|
65 | |
---|
66 | if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) { |
---|
67 | // We remember which page we came from so we can go back there. |
---|
68 | $app->setBoomerangURL($_SERVER['HTTP_REFERER'], 'versions'); |
---|
69 | } |
---|
70 | |
---|
71 | // What action to take. |
---|
72 | switch (getFormData('op')) { |
---|
73 | |
---|
74 | case _("Cancel") : |
---|
75 | $app->dieBoomerangURL('versions', false); |
---|
76 | break; |
---|
77 | |
---|
78 | case 'view' : |
---|
79 | $data = $version->getData($version_id); |
---|
80 | $versionrecord = $version->getVerson($version_id); |
---|
81 | $nav->add(sprintf(_("View <em>%s</em> version %s (%s)"), $versionrecord['version_title'], $version_id, $versionrecord['version_datetime'])); |
---|
82 | $main_template = 'versions_view.ihtml'; |
---|
83 | break; |
---|
84 | |
---|
85 | case 'diff' : |
---|
86 | $data = $version->getData($version_id); |
---|
87 | $versionrecord = $version->getVerson($version_id); |
---|
88 | $current = $version->getCurrent($record_table, $record_key, $record_val); |
---|
89 | if (serialize($data) == serialize($current)) { |
---|
90 | $app->raiseMsg(sprintf(_("Version <em>%s</em> is identical to the current record"), $version_id), MSG_NOTICE, __FILE__, __LINE__); |
---|
91 | } |
---|
92 | $nav->add(sprintf(_("Difference between version %s (%s) and current record."), $version_id, $versionrecord['version_datetime'])); |
---|
93 | $main_template = 'versions_diff.ihtml'; |
---|
94 | break; |
---|
95 | |
---|
96 | case 'restore' : |
---|
97 | if (!isset($lock) || !is_a($lock, 'Lock')) { |
---|
98 | $lock =& Lock::getInstance($auth); |
---|
99 | } |
---|
100 | $lock->select($record_table, $record_key, $record_val); |
---|
101 | if ($lock->isLocked() && !$lock->isMine()) { |
---|
102 | $lock->dieErrorPage(); |
---|
103 | } |
---|
104 | |
---|
105 | if ($v = $version->restore($version_id)) { |
---|
106 | // Create version of this restored record as the "current" version. |
---|
107 | $version->create($record_table, $record_key, $record_val, $v['version_title']); |
---|
108 | $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__); |
---|
109 | $app->dieBoomerangURL('versions', array('break_list_cache'=>'true', false)); |
---|
110 | } else { |
---|
111 | $app->raiseMsg(_("Version restoration failed."), MSG_ERR, __FILE__, __LINE__); |
---|
112 | $app->dieURL($_SERVER['PHP_SELF']); |
---|
113 | } |
---|
114 | break; |
---|
115 | |
---|
116 | default : |
---|
117 | $versions = $version->getList($record_table, $record_key, $record_val); |
---|
118 | if (is_array($versions) && !empty($versions)) { |
---|
119 | $_POST['version_title'] = $versions[0]['version_title']; |
---|
120 | $nav->add(sprintf(_("%s versions of record <em>%s</em>"), sizeof($versions), $versions[0]['version_title'])); |
---|
121 | $main_template = 'versions_list.ihtml'; |
---|
122 | } else { |
---|
123 | $app->raiseMsg(sprintf(_("No saved versions available for this record"), null), MSG_NOTICE, __FILE__, __LINE__); |
---|
124 | $app->dieBoomerangURL('versions'); |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | |
---|
129 | /****************************************************************************** |
---|
130 | * TEMPLATE INITIALIZATION |
---|
131 | *****************************************************************************/ |
---|
132 | |
---|
133 | include 'header.ihtml'; |
---|
134 | include 'codebase/services/templates/' . $main_template; |
---|
135 | include 'footer.ihtml'; |
---|
136 | |
---|
137 | ?> |
---|