source: tags/2.1.5/services/versions.php @ 815

Last change on this file since 815 was 377, checked in by quinn, 14 years ago

Releasing trunk as stable version 2.1.5

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