source: trunk/services/versions.php @ 457

Last change on this file since 457 was 457, checked in by anonymous, 10 years ago

Removed use of requireAccessClearance(). Adjusted sequence of sslOn() and requireLogin(). Added ACL::requireAllow() method. Added arguments to SortOrder::set(). Changed behavior of Validator::validateStrDate(). Added use of Validator::validateStrDate() to module maker templates.

File size: 5.3 KB
Line 
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-2012 Strangecode, LLC
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$app->sslOn();
30$auth->requireLogin();
31
32require_once 'codebase/lib/Version.inc.php';
33require_once 'codebase/lib/Lock.inc.php';
34
35/******************************************************************************
36 * CODE CONFIG
37 *****************************************************************************/
38
39// Since we're using the singleton pattern we can instantiate a Version object earlier with custom parameters.
40$version =& Version::getInstance($auth);
41
42// Query arguments to retain their values between page requests.
43$app->carryQuery('record_table');
44$app->carryQuery('record_key');
45$app->carryQuery('record_val');
46$app->carryQuery('version_title');
47
48// Titles and navigation header.
49$nav->add(_("Versions"), null);
50
51/********************************************************************
52* MAIN
53********************************************************************/
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
61if ('' == $version_id && ('' == $record_table || '' == $record_key || '' == $record_val)) {
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();
65}
66
67if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) {
68    // We remember which page we came from so we can go back there.
69    $app->setBoomerangURL($_SERVER['HTTP_REFERER'], 'versions');
70}
71
72// What action to take.
73switch (getFormData('op')) {
74
75case _("Cancel") :
76    $app->dieBoomerangURL('versions', false);
77    break;
78
79case 'view' :
80    $data = $version->getData($version_id);
81    $versionrecord = $version->getVerson($version_id);
82    $nav->add(sprintf(_("View <em>%s</em> version %s (%s)"), $versionrecord['version_title'], $version_id, $versionrecord['version_datetime']));
83    $main_template = 'versions_view.ihtml';
84    break;
85
86case '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)) {
91        $app->raiseMsg(sprintf(_("Version <em>%s</em> is identical to the current record"), $version_id), MSG_NOTICE, __FILE__, __LINE__);
92    }
93    $nav->add(sprintf(_("Difference between version %s (%s) and current record."), $version_id, $versionrecord['version_datetime']));
94    $main_template = 'versions_diff.ihtml';
95    break;
96
97case 'restore' :
98    if (!isset($lock) || !is_a($lock, 'Lock')) {
99        $lock =& Lock::getInstance($auth);
100    }
101    $lock->select($record_table, $record_key, $record_val);
102    if ($lock->isLocked() && !$lock->isMine()) {
103        $lock->dieErrorPage();
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']);
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__);
110        $app->dieBoomerangURL('versions', array('break_list_cache'=>'true', false));
111    } else {
112        $app->raiseMsg(_("Version restoration failed."), MSG_ERR, __FILE__, __LINE__);
113        $app->dieURL($_SERVER['PHP_SELF']);
114    }
115    break;
116
117default :
118    $versions = $version->getList($record_table, $record_key, $record_val);
119    if (is_array($versions) && !empty($versions)) {
120        $_POST['version_title'] = $versions[0]['version_title'];
121        $nav->add(sprintf(_("%s versions of record <em>%s</em>"), sizeof($versions), $versions[0]['version_title']));
122        $main_template = 'versions_list.ihtml';
123    } else {
124        $app->raiseMsg(sprintf(_("No saved versions available for this record"), null), MSG_NOTICE, __FILE__, __LINE__);
125        $app->dieBoomerangURL('versions');
126    }
127}
128
129
130/******************************************************************************
131 * TEMPLATE INITIALIZATION
132 *****************************************************************************/
133
134include 'header.ihtml';
135include 'codebase/services/templates/' . $main_template;
136include 'footer.ihtml';
137
138?>
Note: See TracBrowser for help on using the repository browser.